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

猜你喜欢

转载自blog.csdn.net/u010261924/article/details/80024143