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 { 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 { 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 { 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; } } }