增加现场提货的配置
This commit is contained in:
@@ -33,36 +33,48 @@ export function saleUnitLabel(saleUnit: ProductSaleUnit | string | null | undefi
|
||||
return saleUnit === 'BOX' ? '箱' : '瓶';
|
||||
}
|
||||
|
||||
export type DeliveryFulfillmentType = 'LOCAL' | 'CROSS_CITY' | 'ON_SITE_PICKUP';
|
||||
|
||||
/** 城市履约起购(瓶当量) */
|
||||
export type MinPurchaseMins = {
|
||||
pickupMinQty: number;
|
||||
localMinQty: number;
|
||||
crossMinQty: number;
|
||||
};
|
||||
|
||||
export function minBottleQtyForDelivery(
|
||||
deliveryType: DeliveryFulfillmentType,
|
||||
mins: MinPurchaseMins,
|
||||
): number {
|
||||
if (deliveryType === 'ON_SITE_PICKUP') {
|
||||
return mins.pickupMinQty > 0 ? mins.pickupMinQty : 2;
|
||||
}
|
||||
if (deliveryType === 'LOCAL') {
|
||||
return mins.localMinQty;
|
||||
}
|
||||
return mins.crossMinQty;
|
||||
}
|
||||
|
||||
export function validateMinPurchase(
|
||||
deliveryType: 'LOCAL' | 'CROSS_CITY' | 'ON_SITE_PICKUP',
|
||||
deliveryType: DeliveryFulfillmentType,
|
||||
quantity: number,
|
||||
localMinQty: number,
|
||||
crossMinQty: number,
|
||||
mins: MinPurchaseMins,
|
||||
options?: { bottlesPerUnit?: number; saleUnit?: ProductSaleUnit },
|
||||
): { ok: boolean; message?: string } {
|
||||
const bottlesPerUnit = options?.bottlesPerUnit ?? 1;
|
||||
const saleUnit = options?.saleUnit ?? (bottlesPerUnit > 1 ? 'BOX' : 'BOTTLE');
|
||||
const bottleQty = toBottleQuantity(quantity, bottlesPerUnit);
|
||||
const unit = saleUnitLabel(saleUnit);
|
||||
|
||||
if (deliveryType === 'ON_SITE_PICKUP') {
|
||||
const minBottles = localMinQty > 0 ? localMinQty : 2;
|
||||
if (bottleQty < minBottles) {
|
||||
const minSale = toMinSaleQuantity(minBottles, bottlesPerUnit);
|
||||
return { ok: false, message: `现场提货至少购买 ${minSale}${unit}` };
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
const minBottles = deliveryType === 'LOCAL' ? localMinQty : crossMinQty;
|
||||
const minBottles = minBottleQtyForDelivery(deliveryType, mins);
|
||||
if (bottleQty < minBottles) {
|
||||
const minSale = toMinSaleQuantity(minBottles, bottlesPerUnit);
|
||||
return {
|
||||
ok: false,
|
||||
message:
|
||||
deliveryType === 'LOCAL'
|
||||
const message =
|
||||
deliveryType === 'ON_SITE_PICKUP'
|
||||
? `现场提货至少购买 ${minSale}${unit}`
|
||||
: deliveryType === 'LOCAL'
|
||||
? `同城配送至少购买 ${minSale}${unit}`
|
||||
: `跨城配送至少购买 ${minSale}${unit}`,
|
||||
};
|
||||
: `跨城配送至少购买 ${minSale}${unit}`;
|
||||
return { ok: false, message };
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user