1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- use app\model\Employee;
- use app\model\Grant;
- use app\model\Permission;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddPermissionForLuban 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' => 'luban/setting'])->find();
- if ($np == null) {
- $p = Permission::where([['auth_name', '=', '企业管理']])->find();
- $np = Permission::create([
- 'pid' => $p->id,
- 'auth_name' => '外呼设置',
- 'uri' => 'luban/setting',
- 'relation' => 'luban/setting,luban/settingSave',
- 'is_menu' => 1
- ]);
- }
- // 复制超级管理员权限
- $s = Grant::find(1);
- $pm = (array)$s->permission;
- $pm[] = $np->id;
- $c = [1023,2214]; // 标注为鲁班id
- foreach ($c as $root_id) {
- $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
- ]);
- }
- }
- }
|