20220530081633_add_value_to_permission_table.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 AddValueToPermissionTable 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. $parent_id = (new Permission())->where('auth_name', '=', '营销工具')->value('id');
  32. $grant = Grant::where('name', '=', '超级管理员')->select();
  33. foreach ($grant as $k => $v) {
  34. $permission = array_merge(json_decode(json_encode($v->permission), true), [intval($parent_id)]);
  35. asort($permission);
  36. $v->permission = array_values(array_filter(array_unique($permission)));
  37. $v->save();
  38. }
  39. }
  40. }