优化
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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 || '余额及授信校验未完成,请稍后重试')
|
||||
}
|
||||
Reference in New Issue
Block a user