'添加管理员失败', self::ERR_EDIT => '编辑管理员失败', self::ERR_FORBIDDEN => '禁用管理员失败', self::EMPTY_ADMINID => 'id不能为空', self::EMPTY_ADMIN => '没有找到该管理员' ]; public function initialize() { parent::initialize(); $this->validate = new AdminValidate(); $this->model = new AdminModel(); } protected $errorMsg = [ self::EMPTY_ADMINID ]; /** * 显示指定的资源 * * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function read() { $inputData = $this->request->param(['admin_id']); if ($inputData['admin_id'] <= 0) { return $this->msg(self::EMPTY_ADMINID, self::ERROR[self::EMPTY_ADMINID]); } $info = $this->model->getInfo($inputData['admin_id']); if (empty($info)) { return $this->msg(self::EMPTY_ADMIN, self::ERROR[self::EMPTY_ADMIN]); } return $this->msg(200, '获取管理员信息成功', $info); } /** * 保存更新的资源 * * @return \think\Response */ public function update() { $inputData = $this->request->param(['admin_id', 'password', 'role_id', 'mobile']); $inputData['password'] = md5($inputData['password']); if (!$this->commonValidate(__FUNCTION__,$inputData)) { return $this->msg(-1,$this->validate->getError()); } if ($inputData['password'] == '') { unset($inputData['password']); } $result = $this->model->edit($inputData); if ($result) { return $this->msg(200, '编辑管理员成功'); } else { return $this->msg(504, '编辑管理员失败'); } } }