14 lines
929 B
TypeScript
14 lines
929 B
TypeScript
import { apiRequest } from '@/api/http'
|
|||
|
|
interface BudgetResult { status: string; usable: boolean; amountCny: number | string; message: string; orderNo: string | null }
|
||
|
|
const base = '/merchant/v1/last-leg/order-budgets'
|
||
|
|
// 资金回执成功才继续下单;超时保留当前幂等键,允许用户再次核对。
|
||
|
|
export async function requireOrderBudget(kind: 'procurement' | 'trucking', key: string, amount: number, currency: string) {
|
||
|
|
const url = `${base}/${kind}/${encodeURIComponent(key)}`
|
||
|
|
let result = await apiRequest<BudgetResult>({ method: 'POST', url, data: { amount, currency } })
|
||
|
|
for (let attempt = 0; result.status === 'FREEZE_PENDING' && attempt < 12; attempt++) {
|
||
|
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
||
|
|
result = await apiRequest<BudgetResult>({ method: 'GET', url })
|
||
|
|
}
|
||
|
|
if (!result.usable) throw new Error(result.message || '余额及授信校验未完成,请稍后重试')
|
||
|
|
}
|