20230217142206_add_vr_manager_menu_to_permission.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\Grant;
  6. class AddVrManagerMenuToPermission 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. */
  30. public function change()
  31. {
  32. //智慧屏 数据表
  33. $menu = [
  34. 'pid' => 0,
  35. 'uri' => '',
  36. 'auth_name' => 'VR管理',
  37. 'is_menu' => 1,
  38. 'sort' => 50,
  39. 'relation' => '',
  40. 'icon'=>'layui-icon layui-icon-chart-screen'
  41. ];
  42. $pid = Permission::insertGetId($menu);
  43. $permission = new Permission();
  44. $child = $permission->saveAll([
  45. ['pid'=>$pid,'uri'=>'vrManage/floder_list','auth_name'=>'作品管理','is_menu'=>1,'sort'=>50,'relation'=>'vrManage/floder_list,vrManage/make_floder,vrManage/floder_child,vrManage/edit_floder,vrManage/del_floder,vrManage/group_check_list,vrManage/batch_mobile,vrManage/checking,vrManage/moveto_floder,vrManage/del_group,vrManage/switch'],
  46. ]);
  47. $ids = [(int)$pid];
  48. foreach ($child as $v) {
  49. $ids[] = (int)$v->id;
  50. }
  51. //先给志远装饰添加vr管理菜单
  52. $grant = Grant::find(28);
  53. $permission = array_merge(json_decode(json_encode($grant->permission), true), $ids);
  54. asort($permission);
  55. $grant->permission = $permission;
  56. $grant->save();
  57. }
  58. }