💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 控制器 ## 代码 ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class UserController extends Controller { /** * 管理员添加提交 */ public function addPost() { if ($this->request->isPost()) { if (!empty($_POST['role_id']) && is_array($_POST['role_id'])) { $role_ids = $_POST['role_id']; unset($_POST['role_id']); $result = $this->validate($this->request->param(), 'User'); if ($result !== true) { $this->error($result); } else { $_POST['user_pass'] = cmf_password($_POST['user_pass']); $result = DB::name('user')->insertGetId($_POST); if ($result !== false) { foreach ($role_ids as $role_id) { if (cmf_get_current_admin_id() != 1 && $role_id == 1) { $this->error("为了网站的安全,非网站创建者不可创建超级管理员!"); } Db::name('RoleUser')->insert(["role_id" => $role_id, "user_id" => $result]); } $this->success("添加成功!", url("user/index")); } else { $this->error("添加失败!"); } } } else { $this->error("请为此用户指定角色!"); } } } } ```