20220927031020_add_wework_per_to_permission_table.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. class AddWeworkPerToPermissionTable 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. $parent = Permission::where('auth_name', '=', '企微管理')->findOrEmpty();
  31. if (!$parent->isEmpty()){
  32. $parent->auth_name = '企业微信';
  33. $parent->save();
  34. $old_per = Permission::where([['pid', '=', $parent['id']], ['auth_name', '=', '企微群发']])->findOrEmpty();
  35. if (!$old_per->isEmpty()) {
  36. $old_per->auth_name = '客户运营';
  37. $old_per->relation = 'wework/external_message,wework/uploadFile,wework/getUserList,wework/materialList,wework/add_external_message,wework/edit_external_message,wework/delete_external_message,wework/statistics_external_message,wework/refresh_external_message,wework/getContactCount,wework/getUserGroupChatsList,wework/external_message_remind';
  38. $old_per->save();
  39. }
  40. $data1 = [
  41. 'pid'=> $parent['id'],
  42. 'auth_name'=> '客户群管理',
  43. 'uri'=> 'wework/group_list',
  44. 'is_menu'=> 1,
  45. 'relation'=> 'wework/group_list,wework/group_view,wework/refresh_group,wework/refresh_group_one,wework/group_tag,wework/add_group_tag_group,wework/edit_group_tag_group,wework/add_group_tag,wework/edit_group_tag,wework/group_add_tag,wework/group_view_data'
  46. ];
  47. $result1 = Permission::create($data1);
  48. $id1 = $result1->id;
  49. $data2 = [
  50. 'pid'=> $parent['id'],
  51. 'auth_name'=> '数据统计',
  52. 'uri'=> 'wework/user_behavior_view',
  53. 'is_menu'=> 1,
  54. 'relation'=> 'wework/user_behavior_view,wework/user_behavior_data,wework/group_analysis,wework/group_number,wework/employee_analysis_view,wework/employee_analysis_data'
  55. ];
  56. $result2 = Permission::create($data2);
  57. $id2 = $result2->id;
  58. $grant = \app\model\Grant::find(1);
  59. $permission = array_merge(json_decode(json_encode($grant->permission), true), [intval($id1),intval($id2)]);
  60. asort($permission);
  61. $grant->permission = array_values(array_filter(array_unique($permission)));
  62. $grant->save();
  63. }
  64. }
  65. }