20220517021536_add_customer_drop_pool_to_permission_table.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 AddCustomerDropPoolToPermissionTable 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. $permission_obj = new Permission();
  32. $pid = Permission::where('auth_name', '=','CRM客户管理')->value('id');
  33. $id = $permission_obj->insertGetId(
  34. ['pid' => $pid, 'auth_name' => '客户自动回收库', 'uri' => 'crm/drop_pool', 'is_menu' => 1, 'icon' => null, 'sort' => 50, 'relation' => 'crm/drop_pool,crm/drop_pool_setting,crm/drop_pool_setting_edit,crm/drop_pool_resdistribute,crm/undrop,crm/drop_to_pool,crm/drop_to_pool_check']
  35. );
  36. $grant = Grant::find(1);
  37. $permission = array_merge(json_decode(json_encode($grant->permission), true), [intval($id)]);
  38. asort($permission);
  39. $grant->permission = array_values(array_filter(array_unique($permission)));
  40. $grant->save();
  41. }
  42. }