dedupe FBA destinations before route selection
This commit is contained in:
@@ -278,6 +278,12 @@ async function loadMasterData(context, merchantToken) {
|
||||
if (receivings.length === 0 || (destinationType !== 'PRIVATE' && destinations.length === 0)) {
|
||||
throw new Error('缺少创建测试订单所需的收货仓或目的仓')
|
||||
}
|
||||
// The warehouse page can contain repeated rows for the same business code.
|
||||
// Collapse those rows before applying a deterministic route offset; otherwise
|
||||
// a producer intended for the second FBA destination can silently reuse ABE4.
|
||||
if (destinationType !== 'PRIVATE') {
|
||||
destinations = [...new Map(destinations.map(value => [String(value.warehouseCode).trim().toUpperCase(), value])).values()]
|
||||
}
|
||||
|
||||
let pricingResult
|
||||
if (fixedRoute.originWarehouseName && (fixedRoute.channelCode || fixedRoute.channelName)) {
|
||||
@@ -308,7 +314,8 @@ async function loadMasterData(context, merchantToken) {
|
||||
.map((rate) => String(rate.destinationCode || '').trim()).filter(Boolean))
|
||||
const eligible = destinations.filter((destination) => pricedCodes.has(String(destination.warehouseCode)))
|
||||
if (eligible.length < 1) throw new Error(`固定渠道没有可计价目的仓: ${destinationType}`)
|
||||
const destination = eligible[Number(fixedRoute.destinationIndex || 0) % eligible.length]
|
||||
const distinctEligible = [...new Map(eligible.map(value => [String(value.warehouseCode).trim().toUpperCase(), value])).values()]
|
||||
const destination = distinctEligible[Number(fixedRoute.destinationIndex || 0) % distinctEligible.length]
|
||||
const result = await findPricedOrderRoute({
|
||||
receiving, destinations: [destination], channels: [selectedChannel],
|
||||
estimate: (body) => request(context, 'POST', '/api/merchant/v1/first-leg/pricing/estimate', body, merchantToken),
|
||||
@@ -336,7 +343,9 @@ async function loadMasterData(context, merchantToken) {
|
||||
response: channelsResponse, attempts: 0, failures: [], originFailures: [] }
|
||||
} else {
|
||||
const result = await findPricedOrderRoute({
|
||||
receiving, destinations: rotate(destinations, Math.floor(Number(fixedRoute.randomIndex) / 17)),
|
||||
receiving,
|
||||
destinations: rotate(destinations, Number.isFinite(Number(fixedRoute.destinationIndex))
|
||||
? Number(fixedRoute.destinationIndex) : Math.floor(Number(fixedRoute.randomIndex) / 17)),
|
||||
channels,
|
||||
estimate: (body) => request(context, 'POST', '/api/merchant/v1/first-leg/pricing/estimate', body, merchantToken),
|
||||
destinationType,
|
||||
|
||||
Reference in New Issue
Block a user