123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- use app\model\Grant;
- use app\model\Permission;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddStatisticsPermission 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-engine',
- 'relation' => ''
- ]);
- $pid = $parent->id;
- $childObjs = $permission->saveAll([
- ['pid' => $pid, 'auth_name' => '客户数据统计', 'is_menu' => 1, 'uri' => 'statistics/customer'],
- ['pid' => $pid, 'auth_name' => '跟进情况统计', 'is_menu' => 1, 'uri' => 'statistics/followUp'],
- ['pid' => $pid, 'auth_name' => '房屋信息统计', 'is_menu' => 1, 'uri' => 'statistics/house'],
- ['pid' => $pid, 'auth_name' => '客户来源渠道统计', 'is_menu' => 1, 'uri' => 'statistics/source']
- ]);
- $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();
- }
- }
|