20220707020901_split_per_to_permission_table.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. class SplitPerToPermissionTable extends Migrator
  5. {
  6. /**
  7. * Change Method.
  8. *
  9. * Write your reversible migrations using this method.
  10. *
  11. * More information on writing migrations is available here:
  12. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  13. *
  14. * The following commands can be used in this method and Phinx will
  15. * automatically reverse them when rolling back:
  16. *
  17. * createTable
  18. * renameTable
  19. * addColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Remember to call "create()" or "update()" and NOT "save()" when working
  25. * with the Table class.
  26. */
  27. public function change()
  28. {
  29. // 拼团
  30. $spellgroup = \app\model\Permission::where('auth_name', '=', '装修拼团')->find();
  31. $spellgroup_new = [
  32. 'pid'=> $spellgroup['id'],
  33. 'auth_name'=> '装修拼团设置',
  34. 'uri'=> 'spellgroup/addSave',
  35. 'is_menu'=> 0,
  36. 'icon'=> null,
  37. 'sort'=> 50,
  38. 'relation'=> 'spellgroup/addSave'
  39. ];
  40. $spellgroup_old = explode(',', $spellgroup['relation']);
  41. foreach ($spellgroup_old as $k => $v) {
  42. if ($v == 'spellgroup/addSave') {
  43. unset($spellgroup_old[$k]);
  44. }
  45. }
  46. $spellgroup_old = array_values($spellgroup_old);
  47. $spellgroup->save(['relation'=> implode(',', $spellgroup_old)]);
  48. $r_spellgroup = \app\model\Permission::create($spellgroup_new);
  49. $new_id[] = intval($r_spellgroup->id);
  50. // 砸金蛋
  51. $golden_eggs = \app\model\Permission::where('auth_name', '=', '砸金蛋')->find();
  52. $golden_eggs_new = [
  53. 'pid'=> $golden_eggs['id'],
  54. 'auth_name'=> '添加金蛋',
  55. 'uri'=> 'turntable/golden_eggs_add',
  56. 'is_menu'=> 0,
  57. 'icon'=> null,
  58. 'sort'=> 50,
  59. 'relation'=> 'turntable/golden_eggs_add,turntable/edit_activity,turntable/up_act_sta'
  60. ];
  61. $golden_eggs_old = explode(',', $golden_eggs['relation']);
  62. foreach ($golden_eggs_old as $k => $v) {
  63. if (in_array($v, ['turntable/golden_eggs_add', 'turntable/edit_activity', 'turntable/up_act_sta'])) {
  64. unset($golden_eggs_old[$k]);
  65. }
  66. }
  67. $golden_eggs_old = array_values($golden_eggs_old);
  68. $golden_eggs->save(['relation'=> implode(',', $golden_eggs_old)]);
  69. $r_golden = \app\model\Permission::create($golden_eggs_new);
  70. $new_id[] = intval($r_golden->id);
  71. // 大转盘
  72. $turntable = \app\model\Permission::where('auth_name', '=', '大转盘')->find();
  73. $turntable_new = [
  74. 'pid'=> $turntable['id'],
  75. 'auth_name'=> '添加大转盘',
  76. 'uri'=> 'turntable/add_activity',
  77. 'is_menu'=> 0,
  78. 'icon'=> null,
  79. 'sort'=> 50,
  80. 'relation'=> 'turntable/add_activity,turntable/edit_activity,turntable/up_act_sta'
  81. ];
  82. $turntable_old = explode(',', $turntable['relation']);
  83. foreach ($turntable_old as $k => $v) {
  84. if (in_array($v, ['turntable/add_activity', 'turntable/edit_activity', 'turntable/up_act_sta'])) {
  85. unset($turntable_old[$k]);
  86. }
  87. }
  88. $turntable_old = array_values($turntable_old);
  89. $turntable->save(['relation'=> implode(',', $turntable_old)]);
  90. $r_turn = \app\model\Permission::create($turntable_new);
  91. $new_id[] = intval($r_turn->id);
  92. // 渠道活码
  93. $huoma = \app\model\Permission::where('auth_name', '=', '渠道活码')->find();
  94. $huoma_new1 = [
  95. 'pid'=> $huoma['id'],
  96. 'auth_name'=> '添加活码',
  97. 'uri'=> 'huoma/add_code',
  98. 'is_menu'=> 0,
  99. 'icon'=> null,
  100. 'sort'=> 50,
  101. 'relation'=> 'huoma/add_code,huoma/edit_code,huoma/up_status,huoma/add_qrcode'
  102. ];
  103. $huoma_new2 = [
  104. 'pid'=> $huoma['id'],
  105. 'auth_name'=> '删除活码',
  106. 'uri'=> 'huoma/del_code',
  107. 'is_menu'=> 0,
  108. 'icon'=> null,
  109. 'sort'=> 50,
  110. 'relation'=> 'huoma/del_code'
  111. ];
  112. $huoma_old = explode(',', $huoma['relation']);
  113. foreach ($huoma_old as $k => $v) {
  114. if (in_array($v, ['huoma/add_code', 'huoma/edit_code', 'huoma/up_status', 'huoma/add_qrcode', 'huoma/del_code'])) {
  115. unset($huoma_old[$k]);
  116. }
  117. }
  118. $huoma_old = array_values($huoma_old);
  119. $huoma->save(['relation'=> implode(',', $huoma_old)]);
  120. $r_huoma1 = \app\model\Permission::create($huoma_new1);
  121. $new_id[] = intval($r_huoma1->id);
  122. $r_huoma2 = \app\model\Permission::create($huoma_new2);
  123. $new_id[] = intval($r_huoma2->id);
  124. $grant = \app\model\Grant::find(1);
  125. $permission = array_merge(json_decode(json_encode($grant->permission), true), $new_id);
  126. asort($permission);
  127. $grant->permission = array_values(array_filter(array_unique($permission)));
  128. $grant->save();
  129. $grant_a = \app\model\Grant::where('name', '=', '超级管理员')->select();
  130. foreach ($grant_a as $k => $v) {
  131. $permission_a = array_merge(json_decode(json_encode($v->permission), true), $new_id);
  132. asort($permission_a);
  133. $v->permission = $permission_a;
  134. $v->save();
  135. }
  136. }
  137. }