20230320112506_save_customer_setting_permission.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use app\model\Permission;
  3. use app\model\Grant;
  4. use think\migration\Migrator;
  5. class SaveCustomerSettingPermission extends Migrator
  6. {
  7. /**
  8. * Change Method.
  9. *
  10. * Write your reversible migrations using this method.
  11. *
  12. * More information on writing migrations is available here:
  13. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  14. *
  15. * The following commands can be used in this method and Phinx will
  16. * automatically reverse them when rolling back:
  17. *
  18. * createTable
  19. * renameTable
  20. * addColumn
  21. * renameColumn
  22. * addIndex
  23. * addForeignKey
  24. *
  25. * Remember to call "create()" or "update()" and NOT "save()" when working
  26. * with the Table class.
  27. */
  28. public function change()
  29. {
  30. $permission = Permission::where(['uri'=>'customerSetting/index'])->find();
  31. $relation = explode(',', $permission->relation);
  32. $del_relation[] = 'customerSetting/report_save';
  33. $del_relation[] = 'customerSetting/report';
  34. $new_relation = array_diff($relation,$del_relation);
  35. $permission->relation = implode(',',$new_relation);
  36. $permission->save();
  37. $addnewpr = [
  38. 'pid' => $permission->id,
  39. 'auth_name' => 'PC端报备设置',
  40. 'uri' => 'customerSetting/report',
  41. 'is_menu' => 0,
  42. 'relation' => 'customerSetting/report,customerSetting/report_save'
  43. ];
  44. $parent = $permission->create($addnewpr);
  45. $grant = Grant::find(1);
  46. $permission = array_merge(json_decode(json_encode($grant->permission), true), [$parent->id]);
  47. asort($permission);
  48. $grant->permission = $permission;
  49. $grant->save();
  50. }
  51. }