20230407064100_update_permission_for_chuangyi.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use app\model\Employee;
  3. use app\model\Grant;
  4. use think\migration\Migrator;
  5. use think\migration\db\Column;
  6. class UpdatePermissionForChuangyi 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. // 复制超级管理员权限
  32. $s = Grant::find(1);
  33. $pm = (array)$s->permission;
  34. $pm[] = 198;
  35. $c = [1027];
  36. foreach ($c as $root_id) {
  37. $g = Grant::create([
  38. 'name' => '超级管理员',
  39. 'permission' => $pm,
  40. 'type' => 'm',
  41. 'root_id' => $root_id
  42. ]);
  43. Employee::where(['root_id' => $root_id, 'top_one' => 1])->update([
  44. 'grant_id' => $g->id
  45. ]);
  46. }
  47. }
  48. }