20220506032446_add_wework_permission_to_permission.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 AddWeworkPermissionToPermission 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. $table = $this->table('permission');
  32. $permission = new Permission();
  33. $parent = $permission->create(
  34. ['pid' => 0, 'auth_name' => '企微管理', 'uri' => '', 'is_menu' => 1, 'icon' => 'layui-icon layui-icon-set-sm', 'sort' => 52, 'relation' => '']
  35. );
  36. $pid = $parent->id;
  37. $permission = new Permission();
  38. $child = $permission->create(
  39. ['pid' => $pid, 'auth_name' => '企微群发', 'uri' => 'wework/external_message', 'is_menu' => 1, 'icon' => null, 'sort' => 50, 'relation' => 'wework/external_message,wework/weworkUpload,wework/getUserList,wework/add_external_message,wework/edit_external_message,wework/delete_external_message,wework/statistics_external_message']
  40. );
  41. $cid = $child->id;
  42. $grant = Grant::where('name', '=', '超级管理员')->select();
  43. foreach ($grant as $k => $v) {
  44. $permission = array_merge(json_decode(json_encode($v->permission), true), [intval($pid),intval($cid)]);
  45. asort($permission);
  46. $v->permission = $permission;
  47. $v->save();
  48. }
  49. }
  50. }