// 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(productId : number, purchaseToken : string, orderSn : string) { console.log(productId, purchaseToken, orderSn); const res = await mainClient.request({ url: 'pay/googlepay/googleVerify', method: 'POST', data: { productId, purchaseToken, orderSn } }) return res } /** * 验证IAP支付 * @param data 支付数据 */ export async function verifyIAP(data : any) { const res = await mainClient.request({ url: 'Ipa/veri', method: 'POST', data }) return res } /** * 获取充值列表 * @param type 固定值 point * @param qudao 支付类型 */ export async function getBookBuyConfigList(type : string, qudao : string) { const res = await mainClient.request({ url: 'common/bookBuyConfig/getBookBuyConfigList', method: 'POST', data: { type, qudao } }) return res } /** * 获取隐私协议 * @param id 101众妙之门隐私政策 */ export async function getAgreement(id : string) { console.log(id, 'id'); const res = await mainClient.request({ url: '/sys/agreement/getAgreement', method: 'POST', data: { id } }) return res } /** * 获取活动说明 */ export async function getActivityDescription() { const res = await mainClient.request({ url: 'common/bookBuyConfig/getRechargeActivity', method: 'POST' }) return res } /** * 充值记录列表 * @param current 当前页码 * @param limit 每页数量 * @param userId 用户id * @return */ export async function getTransactionDetailsList(current : number, limit : number, userId : string) { const res = await mainClient.request({ url: 'common/transactionDetails/getTransactionDetailsList', method: 'POST', data: { current, limit, userId, } }) return res } /** * 获取订单编号 * @return */ export async function getPlaceOrder(data: object) { const res = await mainClient.request({ url: '/book/buyOrder/placeOrder', method: 'POST', data: data }) return res } /** * 获取积分数据 * @return */ export async function getPointsData(current : number, limit : number, userId : string,) { const res = await mainClient.request({ url: 'common/jfTransactionDetails/getJfTransactionDetailsList', method: 'POST', data: { current, limit, userId, } }) return res }