64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
// api/modules/order.ts
|
|
import { mainClient } from '@/api/clients/main'
|
|
import type { IApiResponse } from '@/api/types'
|
|
import type {
|
|
ICreateOrderParams,
|
|
IGooglePayVerifyParams,
|
|
ICreateOrderResponse
|
|
} from '@/types/order'
|
|
import type { IUserInfo } from '@/types/user'
|
|
|
|
/**
|
|
* 订单相关 API
|
|
*/
|
|
export const orderApi = {
|
|
/**
|
|
* 创建订单
|
|
* @param data 订单数据
|
|
*/
|
|
async createOrder(data: ICreateOrderParams) {
|
|
const res = await mainClient.request<IApiResponse<ICreateOrderResponse>>({
|
|
url: 'bookAbroad/order/placeOrder',
|
|
method: 'POST',
|
|
data
|
|
})
|
|
return res
|
|
},
|
|
|
|
/**
|
|
* 验证 Google Pay 支付
|
|
* @param params 支付验证参数
|
|
*/
|
|
async verifyGooglePay(params: IGooglePayVerifyParams) {
|
|
const res = await mainClient.request<IApiResponse>({
|
|
url: 'pay/googlepay/googleVerify',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res
|
|
},
|
|
|
|
/**
|
|
* 获取用户信息(包含虚拟币余额)
|
|
*/
|
|
async getUserInfo() {
|
|
const res = await mainClient.request<IApiResponse<{ user: IUserInfo }>>({
|
|
url: 'common/user/getUserInfo',
|
|
method: 'POST'
|
|
})
|
|
return res
|
|
},
|
|
|
|
/**
|
|
* 刷新用户信息
|
|
* @param userId 用户ID
|
|
*/
|
|
async refreshUserInfo(userId: number) {
|
|
const res = await mainClient.request<IApiResponse<{ user: IUserInfo }>>({
|
|
url: `book/user/info/${userId}`,
|
|
method: 'POST'
|
|
})
|
|
return res
|
|
}
|
|
}
|