20230308084000_add_crm_remove_per_to_permission_table.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 AddCrmRemovePerToPermissionTable 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 = (new Permission())->where('auth_name', '=', 'CRM客户管理')->findOrEmpty();
  32. if (!$parent->isEmpty()) {
  33. $data['pid'] = $parent['id'];
  34. $data['auth_name'] = '客户录入';
  35. $data['uri'] = 'crmRemove/importing';
  36. $data['is_menu'] = 0;
  37. $data['icon'] = null;
  38. $data['sort'] = 50;
  39. $data['relation'] = 'crmRemove/importing,crmRemove/add,crmRemove/get_result,crmRemove/importLog';
  40. $id = Permission::insertGetId($data);
  41. $grant = Grant::find(1);
  42. $permission = array_merge(json_decode(json_encode($grant->permission), true), [intval($id)]);
  43. asort($permission);
  44. $grant->permission = $permission;
  45. $grant->save();
  46. }
  47. }
  48. }