67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { apiClient } from '@/shared/api/client'
|
|
|
|
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
|
import type { BalanceType, LedgerDirection, WalletStatus } from '@/shared/types/status'
|
|
import type { PaymentOrder } from '@/features/orders/api/orders'
|
|
import { yuanToCent } from '@/shared/utils/money'
|
|
|
|
export interface WalletAccount {
|
|
user_id: number
|
|
available_balance_cent: number
|
|
frozen_balance_cent: number
|
|
status: WalletStatus
|
|
}
|
|
|
|
export interface WalletLedger {
|
|
id: number
|
|
ledger_no: string
|
|
user_id: number
|
|
order_id?: number
|
|
direction: LedgerDirection
|
|
amount_cent: number
|
|
balance_after_cent: number
|
|
balance_type: BalanceType
|
|
biz_type: string
|
|
biz_no: string
|
|
remark: string
|
|
created_at: string
|
|
}
|
|
|
|
export async function fetchWalletBalance() {
|
|
const { data } = await apiClient.get<ApiResponse<WalletAccount>>('/wallet/balance')
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchWalletLedger(page = 1, pageSize = 20) {
|
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<WalletLedger>>>(
|
|
'/wallet/ledger',
|
|
{
|
|
params: { page, page_size: pageSize },
|
|
}
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function rechargeWallet(amountYuan: number) {
|
|
const amount_cent = yuanToCent(amountYuan)
|
|
const { data } = await apiClient.post<ApiResponse<WalletAccount>>('/wallet/recharge', {
|
|
amount_cent,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function startWalletRechargePayment(amountYuan: number) {
|
|
const amount_cent = yuanToCent(amountYuan)
|
|
const { data } = await apiClient.post<ApiResponse<PaymentOrder>>('/wallet/recharge/pay', {
|
|
amount_cent,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function queryWalletRechargePayment(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<PaymentOrder>>(
|
|
`/wallet/recharge/pay/${id}/query`
|
|
)
|
|
return data.data
|
|
}
|