FastAdmin刪除角色的規則

1、不能刪除當前管理員所在的角色。

2、當前角色下面有管理員的,不能刪除。

3、當前角色下面有子角色的,不能刪除。

// 移除掉當前管理員所在組別
            $ids = array_diff($ids, $group_ids);

            // 循環判斷每一個組別是否可刪除
            $grouplist = $this->model->where('itemid', 'in', $ids)->select();
            $groupaccessmodel = model('AuthGroupAccess');
            foreach ($grouplist as $k => $v)
            {
                // 當前組別下有管理員
                $groupone = $groupaccessmodel->get(['group_id' => $v['itemid']]);
                if ($groupone)
                {
                    //過濾有管理員的組別
                    $ids = array_diff($ids, [$v['itemid']]);
                    continue;
                }
                // 當前組別下有子組別
                $groupone = $this->model->get(['pid' => $v['itemid']]);
                if ($groupone)
                {
                    $ids = array_diff($ids, [$v['itemid']]);
                    continue;
                }
            }
            if (!$ids)
            {
                $this->error(__('You can not delete group that contain child group and administrators'));
            }
            $count = $this->model->where('itemid', 'in', $ids)->delete();
            if ($count)
            {
                $this->success();
            }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章