ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
>注:删除时和 `RoleUser` 关联! ## 代码 ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class RbacController extends Controller { /** * 删除角色 */ public function roleDelete() { $id = $this->request->param("id", 0, 'intval'); if ($id == 1) { $this->error("超级管理员角色不能被删除!"); } $count = Db::name('RoleUser')->where(['role_id' => $id])->count(); if ($count > 0) { $this->error("该角色已经有用户!"); } else { $status = Db::name('role')->delete($id); if (!empty($status)) { $this->success("删除成功!", url('rbac/index')); } else { $this->error("删除失败!"); } } } } ```