114 lines
3.0 KiB
TypeScript
114 lines
3.0 KiB
TypeScript
import { apiRequest } from '@/api/http'
|
|
|
|
export interface PageResult<T> {
|
|
records: T[]
|
|
total: number
|
|
page: number
|
|
size: number
|
|
pages: number
|
|
}
|
|
|
|
interface PageResultWire<T> extends Omit<PageResult<T>, 'total' | 'page' | 'size' | 'pages'> {
|
|
total: number | string
|
|
page: number | string
|
|
size: number | string
|
|
pages: number | string
|
|
}
|
|
|
|
function normalizePageResult<T>(result: PageResultWire<T>): PageResult<T> {
|
|
return {
|
|
...result,
|
|
total: Number(result.total),
|
|
page: Number(result.page),
|
|
size: Number(result.size),
|
|
pages: Number(result.pages),
|
|
}
|
|
}
|
|
|
|
export interface FinanceAccount {
|
|
currencyCode: 'CNY'
|
|
actualBalance: string
|
|
frozenBalance: string
|
|
availableBalance: string
|
|
creditLimit: string
|
|
creditUsed: string
|
|
creditFrozen: string
|
|
availableCredit: string
|
|
creditExpiresOn: string | null
|
|
creditActive: boolean
|
|
version: number
|
|
updatedAt: string
|
|
}
|
|
|
|
export type AccountChangeType = 'RECHARGE' | 'DEDUCTION' | 'FREEZE' | 'UNFREEZE' | 'CONSUMPTION' | 'CREDIT_LIMIT'
|
|
|
|
export interface AccountLedgerEntry {
|
|
ledgerId: string
|
|
businessNo: string
|
|
changeType: AccountChangeType
|
|
amount: string
|
|
actualBalanceAfter: string
|
|
frozenBalanceAfter: string
|
|
availableBalanceAfter: string
|
|
creditLimitAfter: string
|
|
creditUsedAfter: string
|
|
availableCreditAfter: string
|
|
creditExpiresOnAfter: string | null
|
|
sourceType: 'CLIENT_RECHARGE' | 'MANUAL_RECHARGE' | 'MANUAL_DEDUCTION' | 'CREDIT_LIMIT_ADJUSTMENT' | string
|
|
sourceNo: string
|
|
operatorName: string | null
|
|
remark: string | null
|
|
createdAt: string
|
|
}
|
|
|
|
export type RechargeStatus = 'PENDING' | 'APPROVED' | 'REJECTED'
|
|
|
|
export interface RechargeRequest {
|
|
requestId: string
|
|
requestNo: string
|
|
amount: string
|
|
voucherFileId: string
|
|
voucherFileName: string
|
|
status: RechargeStatus
|
|
version: number
|
|
submittedByName: string | null
|
|
reviewedByName: string | null
|
|
reviewRemark: string | null
|
|
createdAt: string
|
|
reviewedAt: string | null
|
|
}
|
|
|
|
export function getFinanceAccount() {
|
|
return apiRequest<FinanceAccount>({ method: 'GET', url: '/client/finance/v1/account' })
|
|
}
|
|
|
|
export async function getAccountLedger(page: number, size: number) {
|
|
const result = await apiRequest<PageResultWire<AccountLedgerEntry>>({
|
|
method: 'GET',
|
|
url: '/client/finance/v1/account/ledger',
|
|
params: { page, size },
|
|
})
|
|
return normalizePageResult(result)
|
|
}
|
|
|
|
export async function getRechargeRequests(page: number, size: number) {
|
|
const result = await apiRequest<PageResultWire<RechargeRequest>>({
|
|
method: 'GET',
|
|
url: '/client/finance/v1/recharge-requests',
|
|
params: { page, size },
|
|
})
|
|
return normalizePageResult(result)
|
|
}
|
|
|
|
export function createRechargeRequest(amount: string, file: File, idempotencyKey: string) {
|
|
const formData = new FormData()
|
|
formData.append('amount', amount)
|
|
formData.append('file', file, file.name)
|
|
return apiRequest<RechargeRequest>({
|
|
method: 'POST',
|
|
url: '/client/finance/v1/recharge-requests',
|
|
headers: { 'Idempotency-Key': idempotencyKey },
|
|
data: formData,
|
|
})
|
|
}
|