getList($this->postData()); // 获取角色列表 $roleList = (new RoleModel)->getTreeData(); return $this->renderSuccess('', compact('list', 'roleList')); } /** * 添加区域代理管理员 */ public function add() { $model = new UserModel(); $data = $this->postData(); if ($model->add($data)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 编辑管理员需要的数据 */ public function editInfo() { $model = UserModel::detail($this->getData('operations_user_id')); $model['roles'] = UserRoleModel::where('operations_user_id', '=', $model['operations_user_id']) ->column('role_id'); // 获取角色列表 $roleList = RoleModel::getList(); return $this->renderSuccess('', compact('model', 'roleList')); } /** * 编辑管理员 */ public function edit() { $data = $this->postData(); $model = UserModel::detail($data['operations_user_id']); $nameModel = new UserModel(); if ($nameModel->getUserName(['user_name' => $data['user_name']], $model['operations_user_id'])) { return $this->renderError('用户名已存在'); } if ($model->edit($data)) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 删除管理员 */ public function delete() { $model = UserModel::detail($this->postData('operations_user_id')); // 超级管理员不允许删除 if ($model['is_super'] == 1) { return $this->renderError('超级管理员不允许删除'); } if ($model->del(['operations_user_id' => $model['operations_user_id']])) { return $this->renderSuccess('删除成功'); } return $this->renderError($model->getError() ?: '删除失败'); } /** * 修改状态 */ public function status() { $model = UserModel::detail($this->postData('operations_user_id')); // 超级管理员不允许修改状态 if ($model['is_super'] == 1) { return $this->renderError('超级管理员不允许修改状态'); } $status = $this->postData('status'); // 注意:这里应该是 is_delete 字段,但状态修改可能需要其他字段 // 根据 auth 模块,这里可能使用的是启用/禁用字段 if ($model->save(['is_delete' => $status]) !== false) { return $this->renderSuccess('修改成功'); } return $this->renderError('修改失败'); } }