1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- use app\model\Employee;
- use app\model\Grant;
- use app\model\Permission;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddPermissionForHaoxiaoyun 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()
- {
- $np = Permission::where(['uri' => 'haoxiaoyun/setting'])->find();
- if ($np == null) {
- $p = Permission::where([['auth_name', '=', '企业管理']])->find();
- $np = Permission::create([
- 'pid' => $p->id,
- 'auth_name' => '外呼设置',
- 'uri' => 'haoxiaoyun/setting',
- 'relation' => 'haoxiaoyun/setting,haoxiaoyun/settingSave,haoxiaoyun/balence',
- 'is_menu' => 1
- ]);
- }
- // 复制超级管理员权限
- $s = Grant::find(1);
- $pm = (array)$s->permission;
- $pm[] = $np->id;
- $c = [643];
- foreach ($c as $root_id) {
- $super = Grant::where(['type' => 'm', 'root_id' => $root_id])->find();
- if($super){
- $spm = (array)$super->permission;
- $spm[] = $np->id;
- $super->permission = $spm;
- $super->save();
- continue;
- }
- $g = Grant::create([
- 'name' => '超级管理员',
- 'permission' => $pm,
- 'type' => 'm',
- 'root_id' => $root_id
- ]);
- Employee::where(['root_id' => $root_id, 'top_one' => 1])->update([
- 'grant_id' => $g->id
- ]);
- }
- }
- }
|