feat: 订单详情 & 问卷调查

This commit is contained in:
2025-09-10 16:56:24 +08:00
parent 8a1a2af1e9
commit d60445b850
31 changed files with 2054 additions and 723 deletions

View File

@@ -0,0 +1,73 @@
import httpService from "./httpService";
import type { ApiResponse } from "./httpService";
export interface AnswerResItem {
question_id: number;
answer_index: number;
question_title: string;
selected_option: string;
score: number;
}
export type AnswerItem = Pick<AnswerResItem, "question_id" | "answer_index">;
export interface Answers {
answers: AnswerItem[];
test_duration: number;
}
export interface QuestionItem {
id: number;
question_title: string;
question_content: string;
options: string[];
scores: number[];
}
export interface SubmitAnswerRes {
record_id: number;
total_score: number;
ntrp_level: string;
level_description: string;
answers: AnswerResItem[];
}
// 发布球局类
class EvaluateService {
async getEvaluateQuestions(): Promise<ApiResponse<QuestionItem[]>> {
return httpService.post("/ntrp/questions", {
showLoading: true,
});
}
async submitEvaluateAnswers({
answers,
}: Answers): Promise<ApiResponse<SubmitAnswerRes>> {
return httpService.post(
"/ntrp/submit",
{ answers },
{
showLoading: true,
},
);
}
async getHistoryNtrp(): Promise<ApiResponse<any>> {
return httpService.post("/ntrp/history", {
showLoading: true,
});
}
async getNtrpDetail(record_id: number): Promise<ApiResponse<any>> {
return httpService.post(
"/ntrp/detail",
{ record_id },
{
showLoading: true,
},
);
}
}
// 导出认证服务实例
export default new EvaluateService();

View File

@@ -1,6 +1,6 @@
import Taro from '@tarojs/taro';
import httpService, { ApiResponse } from './httpService';
import tokenManager from '../utils/tokenManager';
import Taro from "@tarojs/taro";
import httpService, { ApiResponse } from "./httpService";
import tokenManager from "../utils/tokenManager";
// 微信用户信息接口
export interface WechatUserInfo {
@@ -35,29 +35,44 @@ export interface VerifyCodeResponse {
user_info?: WechatUserInfo;
}
// 用户详细信息
export interface UserInfoType {
id: number
openid: string
unionid: string
session_key: string
nickname: string
avatar_url: string
gender: string
country: string
province: string
city: string
language: string
phone: string
is_subscribed: string
latitude: number
longitude: number
subscribe_time: string
last_login_time: string
export interface UserStats {
followers_count: number;
following_count: number;
hosted_games_count: number;
participated_games_count: number;
}
export interface UserInfoType {
subscribe_time: string;
last_login_time: string;
create_time: string;
last_modify_time: string;
id: number;
openid: string;
user_code: string | null;
unionid: string;
session_key: string;
nickname: string;
ntrp_level: string;
occupation: string | null;
avatar_url: string;
gender: string;
country: string;
province: string;
city: string;
language: string;
phone: string;
personal_profile: string | null;
is_subscribed: string; // 如果只会是 "0" | "1",也可以写成字面量联合类型
latitude: number;
longitude: number;
stats: UserStats;
}
// 微信授权登录
export const wechat_auth_login = async (phone_code?: string): Promise<LoginResponse> => {
export const wechat_auth_login = async (
phone_code?: string,
): Promise<LoginResponse> => {
try {
// 先进行微信登录获取code
const login_result = await Taro.login();
@@ -65,34 +80,34 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
if (!login_result.code) {
return {
success: false,
message: '微信登录失败'
message: "微信登录失败",
};
}
// 使用 httpService 调用微信授权接口传递手机号code
const auth_response = await httpService.post('user/wx_auth', {
const auth_response = await httpService.post("user/wx_auth", {
code: login_result.code,
phone_code: phone_code // 传递手机号加密code
phone_code: phone_code, // 传递手机号加密code
});
if (auth_response.code === 0) {
return {
success: true,
message: '微信登录成功',
token: auth_response.data?.token || '',
user_info: auth_response.data?.userInfo
message: "微信登录成功",
token: auth_response.data?.token || "",
user_info: auth_response.data?.userInfo,
};
} else {
return {
success: false,
message: auth_response.message || '微信授权失败'
message: auth_response.message || "微信授权失败",
};
}
} catch (error) {
console.error('微信授权登录失败:', error);
console.error("微信授权登录失败:", error);
return {
success: false,
message: '微信授权失败,请重试'
message: "微信授权失败,请重试",
};
}
};
@@ -101,38 +116,39 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
export interface PhoneLoginParams {
phone: string;
verification_code: string;
user_code: string
user_code: string;
}
// 手机号验证码登录
export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginResponse> => {
export const phone_auth_login = async (
params: PhoneLoginParams,
): Promise<LoginResponse> => {
try {
// 使用 httpService 调用验证验证码接口
const verify_response = await httpService.post('user/sms/verify', {
const verify_response = await httpService.post("user/sms/verify", {
phone: params.phone,
code: params.verification_code,
user_code: params.user_code
user_code: params.user_code,
});
if (verify_response.code === 0) {
return {
success: true,
message: '登录成功',
message: "登录成功",
token: verify_response.data?.token,
user_info: verify_response.data?.userInfo
user_info: verify_response.data?.userInfo,
};
} else {
return {
success: false,
message: verify_response.message || '验证码错误'
message: verify_response.message || "验证码错误",
};
}
} catch (error) {
console.error('手机号登录失败:', error);
console.error("手机号登录失败:", error);
return {
success: false,
message: error.message
message: error.message,
};
}
};
@@ -140,55 +156,57 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
// 发送短信验证码
export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
try {
const response = await httpService.post('user/sms/send', {
phone: phone
const response = await httpService.post("user/sms/send", {
phone: phone,
});
// 修复响应检查逻辑:检查 code === 0 或 success === true
if (response.code === 0 || response.success === true) {
return {
success: true,
message: '验证码发送成功'
message: "验证码发送成功",
};
} else {
return {
success: false,
message: response.message || '验证码发送失败'
message: response.message || "验证码发送失败",
};
}
} catch (error) {
console.error('发送短信失败:', error);
console.error("发送短信失败:", error);
return {
success: false,
message: error.message
message: error.message,
};
}
};
// 验证短信验证码
export const verify_sms_code = async (phone: string, code: string): Promise<VerifyCodeResponse> => {
export const verify_sms_code = async (
phone: string,
code: string,
): Promise<VerifyCodeResponse> => {
try {
const response = await httpService.post('user/sms/verify', {
const response = await httpService.post("user/sms/verify", {
phone: phone,
code: code
code: code,
});
return {
success: response.success,
message: response.message || '验证失败',
message: response.message || "验证失败",
token: response.data?.token,
user_info: response.data?.userInfo
user_info: response.data?.userInfo,
};
} catch (error) {
console.error('验证验证码失败:', error);
console.error("验证验证码失败:", error);
return {
success: false,
message: error.message
message: error.message,
};
}
};
// 保存用户登录状态
export const save_login_state = (token: string, user_info: WechatUserInfo) => {
try {
@@ -196,16 +214,15 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
const expires_at = Date.now() + 24 * 60 * 60 * 1000; // 24小时后过期
tokenManager.setToken({
accessToken: token,
expiresAt: expires_at
expiresAt: expires_at,
});
// 保存用户信息
Taro.setStorageSync('user_info', JSON.stringify(user_info));
Taro.setStorageSync('is_logged_in', true);
Taro.setStorageSync('login_time', Date.now());
Taro.setStorageSync("user_info", JSON.stringify(user_info));
Taro.setStorageSync("is_logged_in", true);
Taro.setStorageSync("login_time", Date.now());
} catch (error) {
console.error('保存登录状态失败:', error);
console.error("保存登录状态失败:", error);
}
};
@@ -216,11 +233,11 @@ export const clear_login_state = () => {
tokenManager.clearTokens();
// 清除其他登录状态
Taro.removeStorageSync('user_info');
Taro.removeStorageSync('is_logged_in');
Taro.removeStorageSync('login_time');
Taro.removeStorageSync("user_info");
Taro.removeStorageSync("is_logged_in");
Taro.removeStorageSync("login_time");
} catch (error) {
console.error('清除登录状态失败:', error);
console.error("清除登录状态失败:", error);
}
};
@@ -229,13 +246,12 @@ export const check_login_status = (): boolean => {
try {
// 使用 tokenManager 检查令牌有效性
if (!tokenManager.hasValidToken()) {
clear_login_state();
return false;
}
const is_logged_in = Taro.getStorageSync('is_logged_in');
const is_logged_in = Taro.getStorageSync("is_logged_in");
return !!is_logged_in;
} catch (error) {
return false;
@@ -264,14 +280,14 @@ export const get_token_status = () => {
is_valid,
remaining_time,
is_expired,
expires_in_minutes: Math.floor(remaining_time / (60 * 1000))
expires_in_minutes: Math.floor(remaining_time / (60 * 1000)),
};
} catch (error) {
return {
is_valid: false,
remaining_time: 0,
is_expired: true,
expires_in_minutes: 0
expires_in_minutes: 0,
};
}
};
@@ -279,9 +295,9 @@ export const get_token_status = () => {
// 获取用户信息
export const get_user_info = (): WechatUserInfo | null => {
try {
let userinfo = Taro.getStorageSync('user_info')
let userinfo = Taro.getStorageSync("user_info");
if (userinfo) {
return JSON.parse(userinfo)
return JSON.parse(userinfo);
}
return null;
} catch (error) {
@@ -304,7 +320,7 @@ export const check_wechat_login = async (): Promise<boolean> => {
try {
const check_result = await Taro.checkSession();
// Taro.checkSession 返回的是 { errMsg: string }
return check_result.errMsg === 'checkSession:ok';
return check_result.errMsg === "checkSession:ok";
} catch (error) {
return false;
}
@@ -325,18 +341,20 @@ export const refresh_login_status = async (): Promise<boolean> => {
// 检查本地存储的登录状态
return check_login_status();
} catch (error) {
console.error('刷新登录状态失败:', error);
console.error("刷新登录状态失败:", error);
return false;
}
};
// 获取用户详细信息
export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> => {
export const fetchUserProfile = async (): Promise<
ApiResponse<UserInfoType>
> => {
try {
const response = await httpService.post('user/detail');
const response = await httpService.post("user/detail");
return response;
} catch (error) {
console.error('获取用户信息失败:', error);
console.error("获取用户信息失败:", error);
throw error;
}
};
@@ -344,10 +362,10 @@ export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> =>
// 更新用户信息
export const updateUserProfile = async (payload: Partial<UserInfoType>) => {
try {
const response = await httpService.post('/user/update', payload);
const response = await httpService.post("/user/update", payload);
return response;
} catch (error) {
console.error('更新用户信息失败:', error);
console.error("更新用户信息失败:", error);
throw error;
}
};
};

View File

@@ -30,6 +30,42 @@ export interface OrderResponse {
payment_params: PayMentParams
}
export interface OrderInfo {
time: string
address: string
registrant_nickname: string
registrant_phone: string
cost: string
}
export interface RefundPolicy {
application_time: string
refund_rule: string
}
export interface GameStatus {
current_players: number
max_players: number
is_full: boolean
can_join: boolean
}
export interface GameDetails {
game_id: number
game_title: string
game_description: string
}
export interface GameOrderRes {
order_info: OrderInfo
refund_policy: RefundPolicy[]
notice: string
game_status: GameStatus
game_details: GameDetails
}
// 发布球局类
class OrderService {
// 用户登录
@@ -39,7 +75,11 @@ class OrderService {
})
}
// async getOrderInfo()
async getOrderInfo(game_id: number): Promise<ApiResponse<GameOrderRes>> {
return httpService.post('/payment/check_order', { game_id }, {
showLoading: true,
})
}
}
// 导出认证服务实例