123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- use app\model\Grant;
- use app\model\Permission;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddScreenConstructionToPermissionTable 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()
- {
- $pid = Permission::where('auth_name', '=', '智慧屏设置')->value('id');
- if ($pid) {
- $data1 = [
- 'pid'=> $pid,
- 'auth_name'=> '在施工地',
- 'uri'=> 'smartScreenMore/construction',
- 'is_menu'=> 1,
- 'sort'=> 60,
- 'relation'=> 'smartScreenMore/construction,smartScreenMore/construction_add,smartScreenMore/construction_edit,smartScreenMore/construction_delete,smartScreenMore/importLog'
- ];
- $data2 = [
- 'pid'=> $pid,
- 'auth_name'=> '项目清单',
- 'uri'=> 'smartScreenMore/project',
- 'is_menu'=> 1,
- 'sort'=> 61,
- 'relation'=> 'smartScreenMore/project,smartScreenMore/project_add,smartScreenMore/project_edit,smartScreenMore/project_delete,smartScreenMore/importLog'
- ];
- $id1 = Permission::insertGetId($data1);
- $id2 = Permission::insertGetId($data2);
- $grant = Grant::find(1);
- $permission = array_merge(json_decode(json_encode($grant->permission), true), [$id1, $id2]);
- asort($permission);
- $grant->permission = $permission;
- $grant->save();
- }
- }
- }
|