12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- use app\model\Grant;
- use app\model\Permission;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddAgentPowerPermission 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()
- {
- $permission = new Permission();
- $parent = $permission->create([
- 'auth_name' => '全民经纪人',
- 'url' => '',
- 'is_menu' => 1,
- 'icon' => 'layui-icon layui-icon-dollar',
- 'relation' => ''
- ]);
- $pid = $parent->id;
- $childObjs = $permission->saveAll([
- ['pid' => $pid, 'auth_name' => '经纪人管理', 'is_menu' => 1, 'uri' => 'agents/agent_list','relation' => 'agents/agent_list,agents/integral_setting,agents/agent_customer_list,agents/agent_kehu_list,agents/operation_wiped_integral,agents/reward_integral_save,agents/up_agt_accnumb,agents/integral_nuclear,agents/agent_already_list'],
- ['pid' => $pid, 'auth_name' => '数据分析', 'is_menu' => 1, 'uri' => 'agents/agent_data_analysis','relation' => 'agents/agent_data_analysis'],
- ['pid' => $pid, 'auth_name' => '经纪人审核', 'is_menu' => 1, 'uri' => 'agents/agent_review_list','relation' => 'agents/agent_review_list']
- ]);
- $addPermission = [intval($pid)];
- foreach($childObjs as $child){
- $addPermission[] = intval($child->id);
- }
-
- $grant = Grant::find(1);
- $permission = array_merge(json_decode(json_encode($grant->permission), true), $addPermission);
- asort($permission);
- $grant->permission = $permission;
- $grant->save();
- }
- }
|