adminUserModel->getAdminInfoByAccount($this->request->input('account')); if (!$userInfo) throw new AdminException('账号不存在'); if ($userInfo->status == UserCode::DISABLE) throw new AdminException(UserCode::getMessage($userInfo->status),AdminCode::LOGIN_ERROR); // pass加密跟数据库做判断 $password = $this->cryptoFactory->cryptoClass('admin-password',$this->request->input('password'),$userInfo->salt)->encrypt(); if ($password != $userInfo->password) throw new AdminException('密码错误!'); $userInfo->last_login_time = date('Y-m-d H:i:s'); $userInfo->last_login_ip = SystemUtil::getClientIp(); $userInfo->save(); if (!$userInfo->save()) throw new AdminException('登录失败'); $cityId = $this->getCityById($userInfo->id); //生成 token $token = $this->cryptoFactory->cryptoClass('admin-jwt',json_encode([ 'id' => $userInfo->id, 'role' => $userInfo->role_id, 'city_id' => $cityId ]))->encrypt(); //单点登录 $this->userCache->setAdminToken($userInfo->id, $token, (int)config('system.admin_jwt_expire')); return $this->return->success('success',[ 'token' => $token, 'info' => [ 'admin_id' => $userInfo->id, 'avatar' => $userInfo->avatar, 'name' => $userInfo->chinese_name, 'role_id' => $userInfo->role_id, 'city_id' => $cityId ] ]); } }