// api/modules/user.ts import { mainClient } from '@/api/clients/main' import type { IApiResponse } from '@/api/types' import type { IUserInfo, IVipInfo, IOrder, IVipPackage, ITransaction, IFeedbackForm, IPageData } from '@/types/user' import { SERVICE_MAP } from '@/api/config' /** * 获取用户信息 */ export async function getUserInfo() { const res = await mainClient.request>({ url: 'common/user/getUserInfo', method: 'POST' }) return res } /** * 获取VIP信息 */ export async function getVipInfo() { const res = await mainClient.request>({ url: 'bookAbroad/home/getVipInfo', method: 'POST' }) return res } /** * 获取订单列表 * @param current 当前页码 * @param limit 每页数量 */ export async function getOrderList(page: number, limit: number, orderStatus: string) { const res = await mainClient.request }>>({ url: 'common/buyOrder/commonBuyOrderList', method: 'POST', data: { page, limit, orderStatus, come: '10', userId: uni.getStorageSync('userInfo').id } }) return res } /** * 获取VIP套餐列表 */ export async function getVipPackages() { const res = await mainClient.request>({ url: 'book/sysdictdata/getData', method: 'POST', data: { dictLabel: 'googleVip' } }) return res } /** * 创建订单 * @param data 订单数据 */ export async function createOrder(data: any) { const res = await mainClient.request>({ url: 'bookAbroad/order/placeOrder', method: 'POST', data }) return res } /** * 获取交易记录列表 * @param userId 用户ID */ export async function getTransactionList(userId: number) { const res = await mainClient.request>({ url: 'common/transactionDetails/getTransactionDetailsList', method: 'POST', data: { userId } }) return res } /** * 更新用户基本信息 * @param data 用户信息 */ export async function updateUserInfo(data: Partial) { const res = await mainClient.request({ url: 'book/user/update', method: 'POST', data }) return res } /** * 更新用户邮箱 * @param id 用户ID * @param email 邮箱地址 * @param code 验证码 */ export async function updateEmail(id: number, email: string, code: string) { const res = await mainClient.request({ url: 'common/user/updateUserEmail', method: 'POST', data: { id, email, code } }) return res } /** * 更新用户密码 * @param id 用户ID * @param password 新密码 */ export async function updatePassword(id: number, password: string) { const res = await mainClient.request({ url: 'common/user/setPasswordById', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, data: { id, password } }) return res } /** * 发送邮箱验证码 * @param email 邮箱地址 */ export async function sendEmailCode(email: string) { const res = await mainClient.request({ url: 'common/user/getMailCaptcha', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, data: { email } }) return res } /** * 上传图片 * @param filePath 本地文件路径 * @returns 图片URL */ export function uploadImage(filePath: string): Promise { return new Promise((resolve, reject) => { uni.uploadFile({ url: `${SERVICE_MAP.MAIN}oss/fileoss`, filePath, name: 'file', success: (res) => { try { const data = JSON.parse(res.data) if (data.url) { resolve(data.url) } else { reject(new Error('上传失败')) } } catch (error) { reject(error) } }, fail: reject }) }) } /** * 提交问题反馈 * @param data 反馈表单数据 */ export async function submitFeedback(data: IFeedbackForm) { const res = await mainClient.request({ url: 'common/sysFeedback/addSysFeedback', method: 'POST', data }) return res } /** * 验证Google支付 * @param purchaseToken 购买令牌 * @param orderSn 订单号 * @param productId 产品ID */ export async function verifyGooglePay(purchaseToken: string, orderSn: string, productId: string) { const res = await mainClient.request({ url: 'pay/googlepay/googleVerify', method: 'POST', data: { purchaseToken, orderSn, productId } }) return res } /** * 验证IAP支付 * @param data 支付数据 */ export async function verifyIAP(data: any) { const res = await mainClient.request({ url: 'Ipa/veri', method: 'POST', data }) return res }