feat: model mixed-SKU dropship cartons
This commit is contained in:
@@ -65,6 +65,7 @@ export function createEmptyCargoItem(id = `cargo-${Date.now()}`): FirstLegCargoI
|
||||
unitsPerPackage: 1,
|
||||
pieces: 1,
|
||||
packageCount: 1,
|
||||
packingGroupNo: '',
|
||||
grossWeightKg: 0,
|
||||
volumeCbm: 0,
|
||||
netWeightKg: 0,
|
||||
@@ -130,22 +131,48 @@ export function validateFirstLegOrderDraft(draft: FirstLegOrderDraft) {
|
||||
if (!Number.isInteger(item.pieces) || item.pieces <= 0) errors.push(`${line}件数必须为正整数`)
|
||||
if (!Number.isInteger(item.packageCount) || item.packageCount <= 0) errors.push(`${line}箱数必须为正整数`)
|
||||
if (!Number.isInteger(item.unitsPerPackage) || item.unitsPerPackage <= 0) errors.push(`${line}每箱数量必须为正整数`)
|
||||
if (Number.isInteger(item.unitsPerPackage) && item.unitsPerPackage > 0
|
||||
&& Number.isInteger(item.packageCount) && item.packageCount > 0
|
||||
&& Number.isInteger(item.pieces) && item.pieces > 0
|
||||
&& item.pieces !== item.unitsPerPackage * item.packageCount) {
|
||||
errors.push(`${line}总数量应等于每箱数量 × 箱数(${item.unitsPerPackage * item.packageCount})`)
|
||||
}
|
||||
if (item.grossWeightKg <= 0) errors.push(`${line}毛重必须大于 0`)
|
||||
if (item.volumeCbm <= 0) errors.push(`${line}体积必须大于 0`)
|
||||
if (item.woodenProduct && draft.customsInspection !== true) errors.push(`${line}为木制品,“是否商检”必须选择“是”`)
|
||||
})
|
||||
|
||||
if (draft.fulfillmentType === 'ONE_CLICK_DROPSHIP') {
|
||||
const groups = new Map<string, FirstLegCargoItem>()
|
||||
draft.items.forEach((item) => {
|
||||
const group = item.packingGroupNo.trim()
|
||||
if (!group) return
|
||||
const first = groups.get(group)
|
||||
if (!first) groups.set(group, item)
|
||||
else if (first.packageCount !== item.packageCount || first.packageType !== item.packageType
|
||||
|| first.lengthCm !== item.lengthCm || first.widthCm !== item.widthCm || first.heightCm !== item.heightCm) {
|
||||
errors.push(`混箱组合 ${group} 的箱数、包装类型和箱规必须一致`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
export function summarizeFirstLegCargo(items: FirstLegCargoItem[]) {
|
||||
const countedGroups = new Set<string>()
|
||||
return items.reduce(
|
||||
(summary, item) => ({
|
||||
(summary, item) => {
|
||||
const group = item.packingGroupNo.trim()
|
||||
const packageCount = group && countedGroups.has(group) ? 0 : item.packageCount
|
||||
if (group) countedGroups.add(group)
|
||||
return ({
|
||||
pieces: summary.pieces + item.pieces,
|
||||
packageCount: summary.packageCount + item.packageCount,
|
||||
packageCount: summary.packageCount + packageCount,
|
||||
grossWeightKg: summary.grossWeightKg + item.grossWeightKg,
|
||||
volumeCbm: summary.volumeCbm + item.volumeCbm,
|
||||
}),
|
||||
})
|
||||
},
|
||||
{ pieces: 0, packageCount: 0, grossWeightKg: 0, volumeCbm: 0 },
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user