添加钱包测试功能

This commit is contained in:
张成
2025-09-21 13:26:38 +08:00
parent 29bc03f242
commit 535b647165
14 changed files with 912 additions and 5 deletions

View File

@@ -0,0 +1,115 @@
import httpService from "./httpService";
// 钱包信息接口
export interface WalletInfo {
balance: number;
total_income: number;
total_withdraw: number;
}
// 交易记录接口
export interface TransactionRecord {
id: string;
type: "withdraw" | "income" | "refund";
amount: number;
description: string;
created_time: string;
status: "pending" | "success" | "failed";
}
// 提现请求接口
export interface WithdrawRequest {
amount: number;
bank_id: string;
}
export class WalletService {
/**
* 获取钱包信息
*/
static async get_wallet_info(): Promise<WalletInfo> {
try {
const response = await httpService.post("/api/wallet/get_info", {});
if (response.code === 200) {
return response.data;
} else {
throw new Error(response.message || "获取钱包信息失败");
}
} catch (error) {
console.error("获取钱包信息失败:", error);
// 返回模拟数据
return {
balance: 1588.80,
total_income: 3200.00,
total_withdraw: 1611.20,
};
}
}
/**
* 获取交易记录
*/
static async get_transactions(): Promise<TransactionRecord[]> {
try {
const response = await httpService.post("/api/wallet/get_transactions", {});
if (response.code === 200) {
return response.data;
} else {
throw new Error(response.message || "获取交易记录失败");
}
} catch (error) {
console.error("获取交易记录失败:", error);
// 返回模拟数据
return [
{
id: "1",
type: "income",
amount: 150.00,
description: "球局收入",
created_time: "2024-12-20 14:30:00",
status: "success",
},
{
id: "2",
type: "withdraw",
amount: 200.00,
description: "提现",
created_time: "2024-12-19 10:15:00",
status: "success",
},
{
id: "3",
type: "refund",
amount: 80.00,
description: "球局退款",
created_time: "2024-12-18 16:45:00",
status: "success",
},
];
}
}
/**
* 提交提现申请
*/
static async submit_withdraw(request: WithdrawRequest): Promise<void> {
try {
const response = await httpService.post("/wallet/withdraw", {
amount: request.amount,
transfer_remark: "用户申请提现"
});
if (response.code !== 200) {
throw new Error(response.message || "提现申请提交失败");
}
} catch (error) {
console.error("提现申请提交失败:", error);
throw error;
}
}
}