20230331072811_add_permission_for_luban.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. use app\model\Employee;
  3. use app\model\Grant;
  4. use app\model\Permission;
  5. use think\migration\Migrator;
  6. use think\migration\db\Column;
  7. class AddPermissionForLuban extends Migrator
  8. {
  9. /**
  10. * Change Method.
  11. *
  12. * Write your reversible migrations using this method.
  13. *
  14. * More information on writing migrations is available here:
  15. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  16. *
  17. * The following commands can be used in this method and Phinx will
  18. * automatically reverse them when rolling back:
  19. *
  20. * createTable
  21. * renameTable
  22. * addColumn
  23. * renameColumn
  24. * addIndex
  25. * addForeignKey
  26. *
  27. * Remember to call "create()" or "update()" and NOT "save()" when working
  28. * with the Table class.
  29. */
  30. public function change()
  31. {
  32. $np = Permission::where(['uri' => 'luban/setting'])->find();
  33. if ($np == null) {
  34. $p = Permission::where([['auth_name', '=', '企业管理']])->find();
  35. $np = Permission::create([
  36. 'pid' => $p->id,
  37. 'auth_name' => '外呼设置',
  38. 'uri' => 'luban/setting',
  39. 'relation' => 'luban/setting,luban/settingSave',
  40. 'is_menu' => 1
  41. ]);
  42. }
  43. // 复制超级管理员权限
  44. $s = Grant::find(1);
  45. $pm = (array)$s->permission;
  46. $pm[] = $np->id;
  47. $c = [1023,2214]; // 标注为鲁班id
  48. foreach ($c as $root_id) {
  49. $g = Grant::create([
  50. 'name' => '超级管理员',
  51. 'permission' => $pm,
  52. 'type' => 'm',
  53. 'root_id' => $root_id
  54. ]);
  55. Employee::where(['root_id' => $root_id, 'top_one' => 1])->update([
  56. 'grant_id' => $g->id
  57. ]);
  58. }
  59. }
  60. }