12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- use app\model\Permission;
- use app\model\Grant;
- use think\migration\Migrator;
- class AddPriceCallPermissionToSmart 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 = Permission::where(['uri'=>'smartScreen/index'])->find();
- $count = Permission::where([['pid','=',$permission->pid]])->count();
- $addnewpr = [
- 'pid' => $permission->pid,
- 'auth_name' => '报价设置',
- 'uri' => 'renovatePriceSeet/price_setting',
- 'is_menu' => 1,
- 'relation' => 'renovatePriceSeet/price_setting,renovatePriceSeet/add_renovate_package,renovatePriceSeet/add_package_item,renovatePriceSeet/edit_package,renovatePriceSeet/edit_packitem,renovatePriceSeet/package_itemlist,renovatePriceSeet/del_package,renovatePriceSeet/del_packitem',
- 'sort' => 0
- ];
- $parent = $permission->create($addnewpr);
- $grant = Grant::find(1);
- $permission = array_merge(json_decode(json_encode($grant->permission), true), [$parent->id]);
- asort($permission);
- $grant->permission = $permission;
- $grant->save();
- }
- }
|