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();
}