'statistics/customer'])->find(); $r = explode(',', $p->relation); foreach ($auth as $v) { $k = array_search($v, $r); unset($r[$k]); } $p->relation = implode(',', $r); $p->save(); // 客户跟进权限添加 statistics/table statistics/new_table_data $p1 = Permission::create([ 'pid' => $p->id, 'auth_name' => '客户跟进数据统计', 'uri' => 'statistics/table', 'is_menu' => 0, 'relation' => 'statistics/table' ]); $p2 = Permission::create([ 'pid' => $p->id, 'auth_name' => '统计部报表', 'uri' => 'statistics/new_table_data', 'is_menu' => 0, 'relation' => 'statistics/new_table_data' ]); // 超级权限 $superG = Grant::find(1); $superGp = (array)$superG->permission; $superGp[] = $p1->id; $superGp[] = $p2->id; // 要添加权限的企业 $c = [941, 1847, 1977]; // 馨居尚组织跟id 菡萏怡景组织跟id 臻品软装组织跟id foreach ($c as $root_id) { // 权限所属人添加权限 $gl = Grant::where(['root_id' => $root_id])->select(); foreach ($gl as $g) { $permission = (array)$g->permission; if (!in_array($p->id, $permission)) { $permission[] = $p1->id; $permission[] = $p2->id; $g->permission = $permission; $g->save(); } } // 创建所属企业的超级管理员 $rSp = Grant::create([ 'name' => '超级管理员', 'permission' => $superGp, 'root_id' => $root_id, 'type' => 'm' ]); // 更改所属企业的超级管理员权限 Employee::where(['root_id' => $root_id, 'grant_id' => 1])->update(['grant_id' => $rSp->id]); } Db::commit(); } }