123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- class SplitPerToPermissionTable extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- // 拼团
- $spellgroup = \app\model\Permission::where('auth_name', '=', '装修拼团')->find();
- $spellgroup_new = [
- 'pid'=> $spellgroup['id'],
- 'auth_name'=> '装修拼团设置',
- 'uri'=> 'spellgroup/addSave',
- 'is_menu'=> 0,
- 'icon'=> null,
- 'sort'=> 50,
- 'relation'=> 'spellgroup/addSave'
- ];
- $spellgroup_old = explode(',', $spellgroup['relation']);
- foreach ($spellgroup_old as $k => $v) {
- if ($v == 'spellgroup/addSave') {
- unset($spellgroup_old[$k]);
- }
- }
- $spellgroup_old = array_values($spellgroup_old);
- $spellgroup->save(['relation'=> implode(',', $spellgroup_old)]);
- $r_spellgroup = \app\model\Permission::create($spellgroup_new);
- $new_id[] = intval($r_spellgroup->id);
- // 砸金蛋
- $golden_eggs = \app\model\Permission::where('auth_name', '=', '砸金蛋')->find();
- $golden_eggs_new = [
- 'pid'=> $golden_eggs['id'],
- 'auth_name'=> '添加金蛋',
- 'uri'=> 'turntable/golden_eggs_add',
- 'is_menu'=> 0,
- 'icon'=> null,
- 'sort'=> 50,
- 'relation'=> 'turntable/golden_eggs_add,turntable/edit_activity,turntable/up_act_sta'
- ];
- $golden_eggs_old = explode(',', $golden_eggs['relation']);
- foreach ($golden_eggs_old as $k => $v) {
- if (in_array($v, ['turntable/golden_eggs_add', 'turntable/edit_activity', 'turntable/up_act_sta'])) {
- unset($golden_eggs_old[$k]);
- }
- }
- $golden_eggs_old = array_values($golden_eggs_old);
- $golden_eggs->save(['relation'=> implode(',', $golden_eggs_old)]);
- $r_golden = \app\model\Permission::create($golden_eggs_new);
- $new_id[] = intval($r_golden->id);
- // 大转盘
- $turntable = \app\model\Permission::where('auth_name', '=', '大转盘')->find();
- $turntable_new = [
- 'pid'=> $turntable['id'],
- 'auth_name'=> '添加大转盘',
- 'uri'=> 'turntable/add_activity',
- 'is_menu'=> 0,
- 'icon'=> null,
- 'sort'=> 50,
- 'relation'=> 'turntable/add_activity,turntable/edit_activity,turntable/up_act_sta'
- ];
- $turntable_old = explode(',', $turntable['relation']);
- foreach ($turntable_old as $k => $v) {
- if (in_array($v, ['turntable/add_activity', 'turntable/edit_activity', 'turntable/up_act_sta'])) {
- unset($turntable_old[$k]);
- }
- }
- $turntable_old = array_values($turntable_old);
- $turntable->save(['relation'=> implode(',', $turntable_old)]);
- $r_turn = \app\model\Permission::create($turntable_new);
- $new_id[] = intval($r_turn->id);
- // 渠道活码
- $huoma = \app\model\Permission::where('auth_name', '=', '渠道活码')->find();
- $huoma_new1 = [
- 'pid'=> $huoma['id'],
- 'auth_name'=> '添加活码',
- 'uri'=> 'huoma/add_code',
- 'is_menu'=> 0,
- 'icon'=> null,
- 'sort'=> 50,
- 'relation'=> 'huoma/add_code,huoma/edit_code,huoma/up_status,huoma/add_qrcode'
- ];
- $huoma_new2 = [
- 'pid'=> $huoma['id'],
- 'auth_name'=> '删除活码',
- 'uri'=> 'huoma/del_code',
- 'is_menu'=> 0,
- 'icon'=> null,
- 'sort'=> 50,
- 'relation'=> 'huoma/del_code'
- ];
- $huoma_old = explode(',', $huoma['relation']);
- foreach ($huoma_old as $k => $v) {
- if (in_array($v, ['huoma/add_code', 'huoma/edit_code', 'huoma/up_status', 'huoma/add_qrcode', 'huoma/del_code'])) {
- unset($huoma_old[$k]);
- }
- }
- $huoma_old = array_values($huoma_old);
- $huoma->save(['relation'=> implode(',', $huoma_old)]);
- $r_huoma1 = \app\model\Permission::create($huoma_new1);
- $new_id[] = intval($r_huoma1->id);
- $r_huoma2 = \app\model\Permission::create($huoma_new2);
- $new_id[] = intval($r_huoma2->id);
- $grant = \app\model\Grant::find(1);
- $permission = array_merge(json_decode(json_encode($grant->permission), true), $new_id);
- asort($permission);
- $grant->permission = array_values(array_filter(array_unique($permission)));
- $grant->save();
- $grant_a = \app\model\Grant::where('name', '=', '超级管理员')->select();
- foreach ($grant_a as $k => $v) {
- $permission_a = array_merge(json_decode(json_encode($v->permission), true), $new_id);
- asort($permission_a);
- $v->permission = $permission_a;
- $v->save();
- }
- }
- }
|