20220708174433_add_agent_power_permission.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 AddAgentPowerPermission 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 = new Permission();
  32. $parent = $permission->create([
  33. 'auth_name' => '全民经纪人',
  34. 'url' => '',
  35. 'is_menu' => 1,
  36. 'icon' => 'layui-icon layui-icon-dollar',
  37. 'relation' => ''
  38. ]);
  39. $pid = $parent->id;
  40. $childObjs = $permission->saveAll([
  41. ['pid' => $pid, 'auth_name' => '经纪人管理', 'is_menu' => 1, 'uri' => 'agents/agent_list','relation' => 'agents/agent_list,agents/integral_setting,agents/agent_customer_list,agents/agent_kehu_list,agents/operation_wiped_integral,agents/reward_integral_save,agents/up_agt_accnumb,agents/integral_nuclear,agents/agent_already_list'],
  42. ['pid' => $pid, 'auth_name' => '数据分析', 'is_menu' => 1, 'uri' => 'agents/agent_data_analysis','relation' => 'agents/agent_data_analysis'],
  43. ['pid' => $pid, 'auth_name' => '经纪人审核', 'is_menu' => 1, 'uri' => 'agents/agent_review_list','relation' => 'agents/agent_review_list']
  44. ]);
  45. $addPermission = [intval($pid)];
  46. foreach($childObjs as $child){
  47. $addPermission[] = intval($child->id);
  48. }
  49. $grant = Grant::find(1);
  50. $permission = array_merge(json_decode(json_encode($grant->permission), true), $addPermission);
  51. asort($permission);
  52. $grant->permission = $permission;
  53. $grant->save();
  54. }
  55. }