This commit is contained in:
2026-10-30 17:59:48 +08:00
parent d6ef770e48
commit ad72ab8406
10 changed files with 209 additions and 42 deletions
+7 -10
View File
@@ -1,13 +1,10 @@
import { apiRequest } from '@/api/http'
interface BudgetResult { status: string; usable: boolean; amountCny: number | string; message: string; orderNo: string | null }
export 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 || '余额及授信校验未完成,请稍后重试')
// 创建订单时后端在同一事务记录冻结请求,客户端只在详情核对状态和重试明确失败。
export function readOrderFunding(kind: 'procurement' | 'trucking', orderNo: string) {
return apiRequest<BudgetResult>({ method: 'GET', url: base + '/' + kind + '/orders/' + encodeURIComponent(orderNo) })
}
export function retryOrderFunding(kind: 'procurement' | 'trucking', orderNo: string) {
return apiRequest<BudgetResult>({ method: 'POST', url: base + '/' + kind + '/orders/' + encodeURIComponent(orderNo) + '/retry' })
}