request->post('phone'); $password = $this->request->post('password', ''); if (!$phone) { $this->error('手机号不能为空'); } $auth = InspectionAuth::instance(); $result = $auth->login($phone, $password); if ($result) { $this->success('登录成功', [ 'inspector' => $auth->getInspectorInfo(), 'token' => $auth->getToken() ]); } else { $this->error($auth->getError() ?: '登录失败'); } } /** * 验货员退出登录 */ public function logout() { if ($this->auth->logout()) { $this->success('退出成功'); } else { $this->error($this->auth->getError() ?: '退出失败'); } } /** * 获取验货员信息 */ public function info() { $this->success('获取成功', $this->getInspectorInfo()); } /** * 检查登录状态 */ public function check() { if ($this->auth->isLogin()) { $this->success('已登录', [ 'inspector' => $this->getInspectorInfo(), 'token' => $this->auth->getToken() ]); } else { $this->error('未登录', null, 401); } } /** * 修改密码 */ public function changepwd() { $oldpassword = $this->request->post('oldpassword'); $newpassword = $this->request->post('newpassword'); $renewpassword = $this->request->post('renewpassword'); if (!$oldpassword) { $this->error('旧密码不能为空'); } if (!$newpassword) { $this->error('新密码不能为空'); } if ($newpassword !== $renewpassword) { $this->error('两次输入的密码不一致'); } if (strlen($newpassword) < 6) { $this->error('密码长度不能少于6位'); } $result = $this->auth->changepwd($newpassword, $oldpassword); if ($result) { $this->success('密码修改成功,请重新登录'); } else { $this->error($this->auth->getError() ?: '密码修改失败'); } } /** * 设置初始密码(验货员首次设置密码) */ public function setPassword() { $password = $this->request->post('password'); $repassword = $this->request->post('repassword'); if (!$password) { $this->error('密码不能为空'); } if ($password !== $repassword) { $this->error('两次输入的密码不一致'); } if (strlen($password) < 6) { $this->error('密码长度不能少于6位'); } // 检查是否已设置过密码 if ($this->application->password) { $this->error('密码已设置,请使用修改密码功能'); } $result = $this->auth->setPassword($password); if ($result) { $this->success('密码设置成功'); } else { $this->error($this->auth->getError() ?: '密码设置失败'); } } }