fix: allow manual FBA quote when rate is missing

This commit is contained in:
2026-09-21 10:44:14 +08:00
parent b9e5bf3fec
commit 3e8fa3c5d7
6 changed files with 67 additions and 17 deletions
+12
View File
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ApiResponseError, http } from '@/shared/api/http' import { ApiResponseError, http } from '@/shared/api/http'
import { import {
adjustPublishedInboundFee, adjustPublishedInboundFee,
createManualInboundQuote,
confirmInboundFee, confirmInboundFee,
createFeeActionIdempotencyKey, createFeeActionIdempotencyKey,
createFeeAdjustmentIdempotencyKey, createFeeAdjustmentIdempotencyKey,
@@ -69,6 +70,17 @@ describe('inbound fee API', () => {
}) })
}) })
it('creates a manual FBA quote through the dedicated fallback endpoint', async () => {
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: { ...snapshot, rateCode: 'MANUAL_QUOTE' } })
const payload = { selectedWeightKg: 62.5, selectedVolumeCbm: 0.384, unitPrice: 12.2, reason: 'FBA价格未维护' }
await expect(createManualInboundQuote('10001', '88', payload, 'fee-manual-1'))
.resolves.toMatchObject({ rateCode: 'MANUAL_QUOTE' })
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fees/manual-quote', payload, {
params: { tenantId: '10001' }, headers: { 'Idempotency-Key': 'fee-manual-1' },
})
})
it('preserves backend conflict metadata for stale-version recovery', async () => { it('preserves backend conflict metadata for stale-version recovery', async () => {
vi.mocked(http.put).mockResolvedValue({ vi.mocked(http.put).mockResolvedValue({
code: 'A0409', message: '费用已被其他操作员修改,请刷新后重试', data: null, code: 'A0409', message: '费用已被其他操作员修改,请刷新后重试', data: null,
+11 -1
View File
@@ -23,6 +23,16 @@ export async function calculateInboundFee(tenantId: string, inboundId: string, p
return unwrapApiResponse(response) return unwrapApiResponse(response)
} }
export async function createManualInboundQuote(tenantId: string, inboundId: string, payload: {
selectedWeightKg: number; selectedVolumeCbm: number; unitPrice: number; reason: string
}, idempotencyKey: string) {
const response = await http.post<unknown, ApiEnvelope<InboundFeeSnapshot>>(
`${feeBasePath(inboundId)}/manual-quote`, payload,
{ params: { tenantId }, headers: { 'Idempotency-Key': idempotencyKey } },
)
return unwrapApiResponse(response)
}
async function transitionInboundFee( async function transitionInboundFee(
tenantId: string, tenantId: string,
inboundId: string, inboundId: string,
@@ -63,7 +73,7 @@ export function createFeeAdjustmentIdempotencyKey() {
return createFeeActionIdempotencyKey('adjust') return createFeeActionIdempotencyKey('adjust')
} }
export function createFeeActionIdempotencyKey(action: 'adjust' | 'calculate' | 'confirm' | 'send') { export function createFeeActionIdempotencyKey(action: 'adjust' | 'calculate' | 'manual' | 'confirm' | 'send') {
const uuid = globalThis.crypto?.randomUUID?.() const uuid = globalThis.crypto?.randomUUID?.()
if (uuid) return `fee-${action}-${uuid}` if (uuid) return `fee-${action}-${uuid}`
return `fee-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 12)}` return `fee-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 12)}`
+3 -3
View File
@@ -13,9 +13,9 @@ export interface InboundFeeSnapshot {
chargeRuleId: string chargeRuleId: string
ruleCode: string ruleCode: string
chargeRuleVersion: number chargeRuleVersion: number
carrierRateId: string carrierRateId: string | null
rateCode: string rateCode: string
carrierRateVersion: number carrierRateVersion: number | null
customerId: string customerId: string
customerName: string customerName: string
originWarehouseId: string originWarehouseId: string
@@ -45,7 +45,7 @@ export interface InboundFeeSnapshot {
additionalAmount: number additionalAmount: number
totalAmount: number totalAmount: number
currency: string currency: string
rateEffectiveFrom: string rateEffectiveFrom: string | null
rateEffectiveTo: string | null rateEffectiveTo: string | null
calculatedAt: string calculatedAt: string
confirmedAt: string | null confirmedAt: string | null
+1
View File
@@ -8,6 +8,7 @@ export { default as InboundFeePanel } from './fee/InboundFeePanel.vue'
export { export {
adjustPublishedInboundFee, adjustPublishedInboundFee,
calculateInboundFee, calculateInboundFee,
createManualInboundQuote,
confirmInboundFee, confirmInboundFee,
createFeeAdjustmentIdempotencyKey, createFeeAdjustmentIdempotencyKey,
createFeeActionIdempotencyKey, createFeeActionIdempotencyKey,
@@ -34,6 +34,11 @@ describe('UnifiedOrdersView contract', () => {
expect(sendFeeSource).toContain('adjustPublishedInboundFee') expect(sendFeeSource).toContain('adjustPublishedInboundFee')
expect(source).toContain('价格表参考单价') expect(source).toContain('价格表参考单价')
expect(source).toContain('本次对客单价') expect(source).toContain('本次对客单价')
expect(openDialogSource).toContain("feeConfirmPriceMissing.value = true")
expect(sendFeeSource).toContain('createManualInboundQuote')
expect(source).toContain("feeConfirmPriceMissing ? '未命中'")
expect(source).toContain("feeConfirmPriceMissing ? '人工定价原因'")
expect(source).not.toContain('<dt>固定附加费</dt>')
expect(sendFeeSource).toContain("ElMessage.error(getApiErrorDetails(error, '确认费用发送失败').message)") expect(sendFeeSource).toContain("ElMessage.error(getApiErrorDetails(error, '确认费用发送失败').message)")
}) })
@@ -66,6 +66,7 @@ import {
adjustPublishedInboundFee, adjustPublishedInboundFee,
downloadWeightImage, downloadWeightImage,
calculateInboundFee, calculateInboundFee,
createManualInboundQuote,
confirmInboundFee, confirmInboundFee,
createFeeAdjustmentIdempotencyKey, createFeeAdjustmentIdempotencyKey,
createFeeActionIdempotencyKey, createFeeActionIdempotencyKey,
@@ -258,24 +259,27 @@ const feeConfirmWeight = ref<number | null>(null)
const feeConfirmVolume = ref<number | null>(null) const feeConfirmVolume = ref<number | null>(null)
const feeConfirmReferenceLoading = ref(false) const feeConfirmReferenceLoading = ref(false)
const feeConfirmReference = ref<InboundFeeSnapshot | null>(null) const feeConfirmReference = ref<InboundFeeSnapshot | null>(null)
const feeConfirmPriceMissing = ref(false)
const feeConfirmUnitPrice = ref<number | null>(null) const feeConfirmUnitPrice = ref<number | null>(null)
const feeConfirmPriceReason = ref('') const feeConfirmPriceReason = ref('')
type FeeConfirmAttempt = { type FeeConfirmAttempt = {
fingerprint: string fingerprint: string
calculateKey: string calculateKey: string
manualKey: string
adjustKey: string adjustKey: string
confirmKey: string confirmKey: string
sendKey: string sendKey: string
} }
let feeConfirmAttempt: FeeConfirmAttempt | null = null let feeConfirmAttempt: FeeConfirmAttempt | null = null
const feeConfirmPriceChanged = computed(() => { const feeConfirmPriceChanged = computed(() => {
if (feeConfirmPriceMissing.value) return true
const reference = Number(feeConfirmReference.value?.unitPrice) const reference = Number(feeConfirmReference.value?.unitPrice)
const current = Number(feeConfirmUnitPrice.value) const current = Number(feeConfirmUnitPrice.value)
return reference >= 0 && current >= 0 && Math.abs(reference - current) > 0.000001 return reference >= 0 && current >= 0 && Math.abs(reference - current) > 0.000001
}) })
const feeConfirmPriceUnit = computed(() => { const feeConfirmPriceUnit = computed(() => {
const snapshot = feeConfirmReference.value const snapshot = feeConfirmReference.value
return snapshot ? `${snapshot.currency} / ${snapshot.chargeUnit}` : '—' return snapshot ? `${snapshot.currency} / ${snapshot.chargeUnit}` : 'CNY / 计费单位'
}) })
const feeConfirmEstimatedTotal = computed(() => { const feeConfirmEstimatedTotal = computed(() => {
const snapshot = feeConfirmReference.value const snapshot = feeConfirmReference.value
@@ -1669,6 +1673,7 @@ async function openFeeConfirmDialog() {
: measuredGrossWeight > 0 ? measuredGrossWeight : measuredNetWeight > 0 ? measuredNetWeight : null : measuredGrossWeight > 0 ? measuredGrossWeight : measuredNetWeight > 0 ? measuredNetWeight : null
feeConfirmVolume.value = Number(actualTotals.volume) > 0 ? Number(actualTotals.volume) : null feeConfirmVolume.value = Number(actualTotals.volume) > 0 ? Number(actualTotals.volume) : null
feeConfirmReference.value = null feeConfirmReference.value = null
feeConfirmPriceMissing.value = false
feeConfirmUnitPrice.value = null feeConfirmUnitPrice.value = null
feeConfirmPriceReason.value = '' feeConfirmPriceReason.value = ''
feeConfirmAttempt = null feeConfirmAttempt = null
@@ -1693,8 +1698,14 @@ async function openFeeConfirmDialog() {
feeConfirmReference.value = snapshot feeConfirmReference.value = snapshot
feeConfirmUnitPrice.value = Number(snapshot.unitPrice) feeConfirmUnitPrice.value = Number(snapshot.unitPrice)
} catch (error) { } catch (error) {
ElMessage.error(getApiErrorDetails(error, '价格表参考单价加载失败,暂不能推送费用').message) const details = getApiErrorDetails(error, '价格表参考单价加载失败')
feeConfirmOpen.value = false if (details.code === 'A0404') {
feeConfirmPriceMissing.value = true
ElMessage.warning('当前FBA价格未命中,请填写本次对客单价和人工定价原因')
} else {
ElMessage.error(details.message)
feeConfirmOpen.value = false
}
} finally { } finally {
feeConfirmReferenceLoading.value = false feeConfirmReferenceLoading.value = false
} }
@@ -1715,6 +1726,7 @@ function currentFeeConfirmAttempt(
feeConfirmAttempt = { feeConfirmAttempt = {
fingerprint, fingerprint,
calculateKey: createFeeActionIdempotencyKey('calculate'), calculateKey: createFeeActionIdempotencyKey('calculate'),
manualKey: createFeeActionIdempotencyKey('manual'),
adjustKey: createFeeAdjustmentIdempotencyKey(), adjustKey: createFeeAdjustmentIdempotencyKey(),
confirmKey: createFeeActionIdempotencyKey('confirm'), confirmKey: createFeeActionIdempotencyKey('confirm'),
sendKey: createFeeActionIdempotencyKey('send'), sendKey: createFeeActionIdempotencyKey('send'),
@@ -1747,14 +1759,25 @@ async function executeConfirmAndSendFee() {
try { try {
const tenantId = String(summary.tenantId) const tenantId = String(summary.tenantId)
const inboundId = String(summary.inboundId) const inboundId = String(summary.inboundId)
let snapshot = await calculateInboundFee(tenantId, inboundId, { let snapshot: InboundFeeSnapshot
selectedWeightKg, try {
selectedVolumeCbm, snapshot = await calculateInboundFee(tenantId, inboundId, {
weightSource: 'ACTUAL', selectedWeightKg, selectedVolumeCbm, weightSource: 'ACTUAL', volumeSource: 'ACTUAL',
volumeSource: 'ACTUAL', }, attempt.calculateKey)
}, attempt.calculateKey) } catch (error) {
if (getApiErrorDetails(error, '费用试算失败').code !== 'A0404') throw error
feeConfirmPriceMissing.value = true
if (feeConfirmPriceReason.value.trim().length < 2) {
ElMessage.warning('价格未命中,请填写至少 2 个字符的人工定价原因')
return
}
snapshot = await createManualInboundQuote(tenantId, inboundId, {
selectedWeightKg, selectedVolumeCbm, unitPrice: selectedUnitPrice,
reason: feeConfirmPriceReason.value.trim(),
}, attempt.manualKey)
}
const calculatedUnitPrice = Number(snapshot.unitPrice) const calculatedUnitPrice = Number(snapshot.unitPrice)
if (Math.abs(selectedUnitPrice - calculatedUnitPrice) > 0.000001) { if (snapshot.rateCode !== 'MANUAL_QUOTE' && Math.abs(selectedUnitPrice - calculatedUnitPrice) > 0.000001) {
snapshot = await adjustPublishedInboundFee(tenantId, inboundId, { snapshot = await adjustPublishedInboundFee(tenantId, inboundId, {
expectedFeeVersion: snapshot.feeVersion, expectedFeeVersion: snapshot.feeVersion,
chargeableQuantity: Number(snapshot.chargeableQuantity), chargeableQuantity: Number(snapshot.chargeableQuantity),
@@ -2311,13 +2334,12 @@ onBeforeUnmount(() => {
<el-form-item label="渠道"><el-input :model-value="detail?.summary.channelName || detail?.summary.channelCode || '—'" disabled /></el-form-item> <el-form-item label="渠道"><el-input :model-value="detail?.summary.channelName || detail?.summary.channelCode || '—'" disabled /></el-form-item>
<el-form-item label="计费毛重"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmWeight" :min="0" :precision="3" :controls="false" class="fee-confirm-number" placeholder="请输入计费毛重" /><span class="fee-confirm-unit">kg</span></div></el-form-item> <el-form-item label="计费毛重"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmWeight" :min="0" :precision="3" :controls="false" class="fee-confirm-number" placeholder="请输入计费毛重" /><span class="fee-confirm-unit">kg</span></div></el-form-item>
<el-form-item label="计费体积"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmVolume" :min="0" :precision="6" :controls="false" class="fee-confirm-number" placeholder="请输入计费体积" /><span class="fee-confirm-unit">m³</span></div></el-form-item> <el-form-item label="计费体积"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmVolume" :min="0" :precision="6" :controls="false" class="fee-confirm-number" placeholder="请输入计费体积" /><span class="fee-confirm-unit">m³</span></div></el-form-item>
<el-form-item label="价格表参考单价"><div class="fee-confirm-number-wrap"><el-input-number :model-value="feeConfirmReference?.unitPrice == null ? undefined : Number(feeConfirmReference.unitPrice)" :precision="4" :controls="false" disabled class="fee-confirm-number" placeholder="正在读取参考单价" /><span class="fee-confirm-unit">{{ feeConfirmPriceUnit }}</span></div></el-form-item> <el-form-item label="价格表参考单价"><div class="fee-confirm-number-wrap"><el-input-number :model-value="feeConfirmPriceMissing || feeConfirmReference?.unitPrice == null ? undefined : Number(feeConfirmReference.unitPrice)" :precision="4" :controls="false" disabled class="fee-confirm-number" :placeholder="feeConfirmPriceMissing ? '未命中' : '正在读取参考单价'" /><span class="fee-confirm-unit">{{ feeConfirmPriceUnit }}</span></div></el-form-item>
<el-form-item label="本次对客单价"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmUnitPrice" :min="0" :precision="4" :controls="false" :disabled="feeConfirmReferenceLoading" class="fee-confirm-number" placeholder="请输入对客单价" /><span class="fee-confirm-unit">{{ feeConfirmPriceUnit }}</span></div></el-form-item> <el-form-item label="本次对客单价"><div class="fee-confirm-number-wrap"><el-input-number v-model="feeConfirmUnitPrice" :min="0" :precision="4" :controls="false" :disabled="feeConfirmReferenceLoading" class="fee-confirm-number" placeholder="请输入对客单价" /><span class="fee-confirm-unit">{{ feeConfirmPriceUnit }}</span></div></el-form-item>
<el-form-item v-if="feeConfirmPriceChanged" label="单价调整原因" class="fee-confirm-price-reason"><el-input v-model="feeConfirmPriceReason" type="textarea" :rows="2" maxlength="500" show-word-limit placeholder="请说明本次人工改单价的原因" /></el-form-item> <el-form-item v-if="feeConfirmPriceChanged" :label="feeConfirmPriceMissing ? '人工定价原因' : '单价调整原因'" class="fee-confirm-price-reason"><el-input v-model="feeConfirmPriceReason" type="textarea" :rows="2" maxlength="500" show-word-limit placeholder="请说明本次人工定价的原因" /></el-form-item>
</el-form> </el-form>
<dl v-if="feeConfirmReference" class="fee-confirm-price-summary"> <dl v-if="feeConfirmReference" class="fee-confirm-price-summary">
<div><dt>参考计费量</dt><dd>{{ formatNumber(Number(feeConfirmReference.chargeableQuantity), feeConfirmReference.roundingScale) }} {{ feeConfirmReference.chargeUnit }}</dd></div> <div><dt>参考计费量</dt><dd>{{ formatNumber(Number(feeConfirmReference.chargeableQuantity), feeConfirmReference.roundingScale) }} {{ feeConfirmReference.chargeUnit }}</dd></div>
<div><dt>固定附加费</dt><dd>{{ feeConfirmMoney(Number(feeConfirmReference.additionalAmount || 0), feeConfirmReference.currency) }}</dd></div>
<div><dt>按当前单价预计合计</dt><dd>{{ feeConfirmEstimatedTotal == null ? '—' : feeConfirmMoney(feeConfirmEstimatedTotal, feeConfirmReference.currency) }}</dd></div> <div><dt>按当前单价预计合计</dt><dd>{{ feeConfirmEstimatedTotal == null ? '—' : feeConfirmMoney(feeConfirmEstimatedTotal, feeConfirmReference.currency) }}</dd></div>
</dl> </dl>
<h4 class="fee-confirm-reference-title">参考数据</h4> <h4 class="fee-confirm-reference-title">参考数据</h4>