优化
This commit is contained in:
@@ -19,6 +19,11 @@ function records(value) { return Array.isArray(value?.records) ? value.records :
|
||||
function pageOk(value) { return Array.isArray(value?.records) && Number.isFinite(Number(value?.total)) }
|
||||
function success(response) { return Boolean(response) && response.http === 200 && String(response.body?.code) === '200' }
|
||||
function sleep(milliseconds) { return new Promise((resolve) => setTimeout(resolve, milliseconds)) }
|
||||
function rotate(values, offset) {
|
||||
if (!Array.isArray(values) || values.length < 2) return Array.isArray(values) ? [...values] : []
|
||||
const shift = Math.abs(Number(offset) || 0) % values.length
|
||||
return [...values.slice(shift), ...values.slice(0, shift)]
|
||||
}
|
||||
function key(context, operation) { return `${context.marker}-${operation}`.slice(0, 128) }
|
||||
export function requestedOrderDestinationType(context) {
|
||||
const value = String(context?.context?.orderDestinationType || 'FBA').trim().toUpperCase()
|
||||
@@ -269,6 +274,33 @@ async function loadMasterData(context, merchantToken) {
|
||||
})
|
||||
pricingResult = { receiving, ...result, originFailures: [] }
|
||||
}
|
||||
} else if (fixedRoute.originWarehouseName) {
|
||||
const receiving = receivings.find((warehouse) => warehouse.warehouseName === fixedRoute.originWarehouseName)
|
||||
if (!receiving) throw new Error(`未找到固定起运仓: ${fixedRoute.originWarehouseName}`)
|
||||
const channelsResponse = await request(context, 'GET',
|
||||
`/api/merchant/v1/first-leg/pricing/channels?originWarehouseId=${encodeURIComponent(receiving.id)}`,
|
||||
undefined, merchantToken)
|
||||
const availableChannels = context.apiSuccess(MODULE, 'Client 查询固定起运仓随机渠道池', channelsResponse)
|
||||
const channels = rotate((Array.isArray(availableChannels) ? availableChannels : [])
|
||||
.filter((item) => Array.isArray(item.pricingTaxModes) && item.pricingTaxModes.length > 0),
|
||||
fixedRoute.randomIndex)
|
||||
.map((channel, index) => ({ ...channel,
|
||||
pricingTaxModes: rotate(channel.pricingTaxModes, Number(fixedRoute.randomIndex) + index) }))
|
||||
if (channels.length === 0) throw new Error('固定起运仓没有客户可选择的可计价渠道')
|
||||
if (destinationType === 'PRIVATE') {
|
||||
const channel = channels[0]
|
||||
pricingResult = { receiving, priced: { channel,
|
||||
pricingTaxMode: channel.pricingTaxModes[0], destination: null },
|
||||
response: channelsResponse, attempts: 0, failures: [], originFailures: [] }
|
||||
} else {
|
||||
const result = await findPricedOrderRoute({
|
||||
receiving, destinations: rotate(destinations, Math.floor(Number(fixedRoute.randomIndex) / 17)),
|
||||
channels,
|
||||
estimate: (body) => request(context, 'POST', '/api/merchant/v1/first-leg/pricing/estimate', body, merchantToken),
|
||||
destinationType,
|
||||
})
|
||||
pricingResult = { receiving, ...result, originFailures: [] }
|
||||
}
|
||||
} else {
|
||||
pricingResult = await findPricedOrderRouteAcrossOrigins({
|
||||
receivings, destinations,
|
||||
@@ -307,6 +339,8 @@ function buildPayload(context, profile, master, productImageFileId) {
|
||||
const packageCountPerSku = Math.max(1,
|
||||
Number(context.context?.waitSplitVariant?.packageCountPerSku
|
||||
|| context.context?.phase3LoadingIncrementalPackageCount || 1))
|
||||
const packageCounts = Array.isArray(context.context?.waitSplitVariant?.packageCounts)
|
||||
? context.context.waitSplitVariant.packageCounts : []
|
||||
const selectedBoxes = BOXES.slice(0, skuCount)
|
||||
const orderProfile = context.context?.orderProfile || {}
|
||||
const isPrivate = master.destinationType === 'PRIVATE'
|
||||
@@ -346,7 +380,7 @@ function buildPayload(context, profile, master, productImageFileId) {
|
||||
cargoes: selectedBoxes.map((box, index) => {
|
||||
const volumeCbm = box.lengthCm * box.widthCm * box.heightCm / 1_000_000
|
||||
const unitsPerPackage = 10 + index
|
||||
const packageCount = packageCountPerSku
|
||||
const packageCount = Number(packageCounts[index] || packageCountPerSku)
|
||||
return {
|
||||
skuNo: `SKU-${box.boxType}-${context.marker}`.slice(0, 64),
|
||||
cargoName: `${box.boxType} 测试产品`, cargoNameEn: `${box.boxType} test product`,
|
||||
@@ -453,6 +487,12 @@ export async function run(context) {
|
||||
context.assert(MODULE, 'Client 测试企业已审核且客户 ID 有效', profileResponse,
|
||||
Boolean(tenantId) && profile?.status === 'ACTIVE', `tenantId=${tenantId || 'missing'}, status=${profile?.status ?? 'missing'}`)
|
||||
if (!tenantId) throw new Error('Client 企业资料未返回客户 ID')
|
||||
if (context.options?.customerName) {
|
||||
context.assert(MODULE, 'Client 登录企业与指定客户名称一致', profileResponse,
|
||||
profile?.tenantName === context.options.customerName,
|
||||
`expected=${context.options.customerName}, actual=${profile?.tenantName || 'missing'}`, CONTRACT_OPTIONS)
|
||||
if (profile?.tenantName !== context.options.customerName) throw new Error('Client 登录企业不是指定客户')
|
||||
}
|
||||
|
||||
await assertDimensionConfig(context, tenantId)
|
||||
const master = await loadMasterData(context, merchantToken)
|
||||
|
||||
Reference in New Issue
Block a user