20221011023741_updata_wework_permission.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. class UpdataWeworkPermission 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. $old_per = Permission::where([['pid', '=', $parent['id']], ['auth_name', '=', '企微群发']])->findOrEmpty();
  33. if (!$old_per->isEmpty()) {
  34. $old_per->auth_name = '客户运营';
  35. $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';
  36. $old_per->save();
  37. }
  38. $ids_arr = [];
  39. $old_per1 = Permission::where([['pid', '=', $parent['id']], ['auth_name', '=', '客户群管理']])->findOrEmpty();
  40. if ($old_per1->isEmpty()){
  41. $data1 = [
  42. 'pid'=> $parent['id'],
  43. 'auth_name'=> '客户群管理',
  44. 'uri'=> 'wework/group_list',
  45. 'is_menu'=> 1,
  46. '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'
  47. ];
  48. $result1 = Permission::create($data1);
  49. $id1 = $result1->id;
  50. $ids_arr[] = intval($id1);
  51. }
  52. $old_per2 = Permission::where([['pid', '=', $parent['id']], ['auth_name', '=', '数据统计']])->findOrEmpty();
  53. if ($old_per2->isEmpty()) {
  54. $data2 = [
  55. 'pid' => $parent['id'],
  56. 'auth_name' => '数据统计',
  57. 'uri' => 'wework/user_behavior_view',
  58. 'is_menu' => 1,
  59. 'relation' => 'wework/user_behavior_view,wework/user_behavior_data,wework/group_analysis,wework/group_number,wework/employee_analysis_view,wework/employee_analysis_data'
  60. ];
  61. $result2 = Permission::create($data2);
  62. $id2 = $result2->id;
  63. $ids_arr[] = intval($id2);
  64. }
  65. $grant = \app\model\Grant::find(1);
  66. $permission = array_merge(json_decode(json_encode($grant->permission), true), $ids_arr);
  67. asort($permission);
  68. $grant->permission = array_values(array_filter(array_unique($permission)));
  69. $grant->save();
  70. }
  71. }
  72. }