企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 代码 ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class RbacController extends Controller { /** * 角色授权提交 */ public function authorizePost() { if ($this->request->isPost()) { $roleId = $this->request->param("roleId", 0, 'intval'); if (!$roleId) { $this->error("需要授权的角色不存在!"); } if (is_array($this->request->param('menuId/a')) && count($this->request->param('menuId/a')) > 0) { //先删除后插入 Db::name("authAccess")->where(["role_id" => $roleId, 'type' => 'admin_url'])->delete(); foreach ($_POST['menuId'] as $menuId) { $menu = Db::name("adminMenu")->where(["id" => $menuId])->field("app,controller,action")->find(); if ($menu) { $app = $menu['app']; $model = $menu['controller']; $action = $menu['action']; $name = strtolower("$app/$model/$action"); Db::name("authAccess")->insert(["role_id" => $roleId, "rule_name" => $name, 'type' => 'admin_url']); } } $this->success("授权成功!"); } else { //当没有数据时,清除当前角色授权 Db::name("authAccess")->where(["role_id" => $roleId])->delete(); $this->error("没有接收到数据,执行清除授权成功!"); } } } } ```