1
0

20230728064033_add_screen_construction_to_permission_table.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. use app\model\Grant;
  3. use app\model\Permission;
  4. use think\migration\Migrator;
  5. use think\migration\db\Column;
  6. class AddScreenConstructionToPermissionTable extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. $pid = Permission::where('auth_name', '=', '智慧屏设置')->value('id');
  32. if ($pid) {
  33. $data1 = [
  34. 'pid'=> $pid,
  35. 'auth_name'=> '在施工地',
  36. 'uri'=> 'smartScreenMore/construction',
  37. 'is_menu'=> 1,
  38. 'sort'=> 60,
  39. 'relation'=> 'smartScreenMore/construction,smartScreenMore/construction_add,smartScreenMore/construction_edit,smartScreenMore/construction_delete,smartScreenMore/importLog'
  40. ];
  41. $data2 = [
  42. 'pid'=> $pid,
  43. 'auth_name'=> '项目清单',
  44. 'uri'=> 'smartScreenMore/project',
  45. 'is_menu'=> 1,
  46. 'sort'=> 61,
  47. 'relation'=> 'smartScreenMore/project,smartScreenMore/project_add,smartScreenMore/project_edit,smartScreenMore/project_delete,smartScreenMore/importLog'
  48. ];
  49. $id1 = Permission::insertGetId($data1);
  50. $id2 = Permission::insertGetId($data2);
  51. $grant = Grant::find(1);
  52. $permission = array_merge(json_decode(json_encode($grant->permission), true), [$id1, $id2]);
  53. asort($permission);
  54. $grant->permission = $permission;
  55. $grant->save();
  56. }
  57. }
  58. }