20220519073505_add_construction_to_permission_table.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use think\migration\Migrator;
  3. use app\model\Permission;
  4. use app\model\Grant;
  5. use think\migration\db\Column;
  6. class AddConstructionToPermissionTable 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. $permission_obj = new Permission();
  32. $parent_id = $permission_obj->where('auth_name', '=', '素材中心')->value('id');
  33. $id = $permission_obj->insertGetId(
  34. ['pid' => $parent_id, 'auth_name' => '在施工地', 'uri' => 'construction/index', 'is_menu' => 1, 'icon' => null, 'sort' => 56, 'relation' => 'construction/index,construction/add,construction/edit,construction/delete,construction/step_setting,construction/change_status,construction/update_step,construction/step_list']
  35. );
  36. $grant = Grant::where('name', '=', '超级管理员')->select();
  37. foreach ($grant as $k => $v) {
  38. $permission = array_merge(json_decode(json_encode($v->permission), true), [intval($id)]);
  39. asort($permission);
  40. $v->permission = array_values(array_filter(array_unique($permission)));
  41. $v->save();
  42. }
  43. }
  44. }