@pisell/pisellos 2.3.127 → 2.3.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +2 -1
- package/dist/modules/Order/index.js +117 -58
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.js +6 -4
- package/dist/modules/Rules/index.js +4 -2
- package/dist/modules/Rules/types.d.ts +2 -0
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +2 -2
- package/dist/solution/BaseSales/index.js +75 -39
- package/dist/solution/BaseSales/types.d.ts +5 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
- package/dist/solution/BaseSales/utils.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +3 -2
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Order/index.d.ts +2 -1
- package/lib/modules/Order/index.js +70 -10
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.js +3 -2
- package/lib/modules/Rules/index.js +4 -2
- package/lib/modules/Rules/types.d.ts +2 -0
- package/lib/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +2 -2
- package/lib/solution/BaseSales/index.js +15 -6
- package/lib/solution/BaseSales/types.d.ts +5 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
- package/lib/solution/BaseSales/utils.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +2 -1
- package/package.json +1 -1
|
@@ -110,6 +110,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
110
110
|
}>;
|
|
111
111
|
applyDiscount(options?: {
|
|
112
112
|
reapplyBookingDiscountProductUids?: string[];
|
|
113
|
+
reapplyWeighedDiscountProductUids?: string[];
|
|
113
114
|
preferredEntitlementPassIds?: number[];
|
|
114
115
|
}): void;
|
|
115
116
|
/**
|
|
@@ -584,7 +585,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
584
585
|
generateIdempotencyToken(): string;
|
|
585
586
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
586
587
|
createOrder(params: CommitOrderParams['query']): {
|
|
587
|
-
type: "
|
|
588
|
+
type: "appointment_booking" | "virtual";
|
|
588
589
|
platform: string;
|
|
589
590
|
sales_channel: string;
|
|
590
591
|
order_sales_channel: string;
|
|
@@ -34,6 +34,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
34
34
|
import { OrderHooks } from "./types";
|
|
35
35
|
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, collectPointCardSnapshotCodeCandidates, mergePointCardSnapshotCodes as _mergePointCardSnapshotCodes, buildVirtualCurrencySnapshotFromList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
|
|
36
36
|
import { isNormalProduct } from "../Product/utils";
|
|
37
|
+
import { getWeighedProductPriceFingerprint, resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
37
38
|
import dayjs from 'dayjs';
|
|
38
39
|
import { getDiscountLifecycleReason } from "../Discount/availability";
|
|
39
40
|
import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
|
|
@@ -42,7 +43,7 @@ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentI
|
|
|
42
43
|
import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
|
|
43
44
|
import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
|
|
44
45
|
import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
|
|
45
|
-
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
|
|
46
|
+
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum, buildManualProductDiscountItem, findManualProductDiscountItem, mergeManualProductDiscountIntoList } from "./utils/manualProductDiscount";
|
|
46
47
|
import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
|
|
47
48
|
import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
|
|
48
49
|
import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
|
|
@@ -1113,6 +1114,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1113
1114
|
orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
|
|
1114
1115
|
}, {
|
|
1115
1116
|
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
1117
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids,
|
|
1116
1118
|
preferredEntitlementPassIds: options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds
|
|
1117
1119
|
});
|
|
1118
1120
|
if (result !== null && result !== void 0 && result.productList) {
|
|
@@ -5469,8 +5471,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5469
5471
|
}
|
|
5470
5472
|
}, {
|
|
5471
5473
|
key: "applyOrderProductUpdateToTempOrder",
|
|
5472
|
-
value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
5473
|
-
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$
|
|
5474
|
+
value: function applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
|
|
5475
|
+
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata2, _targetProduct$metada20, _tempOrder$products$p, _tempOrder$products$p2;
|
|
5474
5476
|
var product_id = params.product_id,
|
|
5475
5477
|
product_variant_id = params.product_variant_id,
|
|
5476
5478
|
updates = params.updates,
|
|
@@ -5536,7 +5538,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5536
5538
|
var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
|
|
5537
5539
|
var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
|
|
5538
5540
|
var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
5539
|
-
var
|
|
5541
|
+
var callerChangesWeighing = getWeighedProductPriceFingerprint(targetProduct.product_sku) !== getWeighedProductPriceFingerprint(nextProduct.product_sku);
|
|
5542
|
+
var callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
|
|
5540
5543
|
var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
5541
5544
|
var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
5542
5545
|
var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
|
|
@@ -5552,33 +5555,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5552
5555
|
};
|
|
5553
5556
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
5554
5557
|
}();
|
|
5558
|
+
var weighedSourcePrice = callerChangesWeighing ? resolveWeighedSourcePrice(nextProduct.product_sku) : undefined;
|
|
5559
|
+
var hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
|
|
5560
|
+
if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
|
|
5561
|
+
var _ref84, _targetProduct$metada3, _targetProduct$metada4, _ref85, _targetProduct$metada5, _targetProduct$metada6;
|
|
5562
|
+
var nextMainOriginal = new Decimal(weighedSourcePrice).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5563
|
+
var previousMainOriginal = new Decimal((_ref84 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref84 !== void 0 ? _ref84 : 0);
|
|
5564
|
+
var previousMainSelling = new Decimal((_ref85 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref85 !== void 0 ? _ref85 : 0);
|
|
5565
|
+
// A manual final price remains fixed; other legacy discounts keep their amount
|
|
5566
|
+
// until Rules reapplies the currently selected wallet discount below.
|
|
5567
|
+
var nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
|
|
5568
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5569
|
+
source_product_price: weighedSourcePrice,
|
|
5570
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
|
|
5571
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : Decimal.max(0, nextMainSelling).toFixed(2),
|
|
5572
|
+
price_schema_version: 2
|
|
5573
|
+
});
|
|
5574
|
+
}
|
|
5555
5575
|
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
5556
|
-
var _targetProduct$
|
|
5576
|
+
var _targetProduct$metada7, _targetProduct$metada8, _targetProduct$metada9, _targetProduct$metada10, _targetProduct$metada11;
|
|
5557
5577
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
5558
5578
|
nextProduct.original_price = targetProduct.original_price;
|
|
5559
5579
|
nextProduct.payment_price = targetProduct.payment_price;
|
|
5560
5580
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5561
|
-
source_product_price: (_targetProduct$
|
|
5562
|
-
main_product_selling_price: (_targetProduct$
|
|
5563
|
-
main_product_original_price: (_targetProduct$
|
|
5564
|
-
price_schema_version: (_targetProduct$
|
|
5581
|
+
source_product_price: (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.source_product_price,
|
|
5582
|
+
main_product_selling_price: (_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_selling_price,
|
|
5583
|
+
main_product_original_price: (_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_original_price,
|
|
5584
|
+
price_schema_version: (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.price_schema_version) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : 2
|
|
5565
5585
|
});
|
|
5566
5586
|
nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
|
|
5567
5587
|
} else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
|
|
5568
|
-
var _targetProduct$
|
|
5588
|
+
var _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
|
|
5569
5589
|
// 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
|
|
5570
5590
|
// 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
|
|
5571
|
-
var
|
|
5572
|
-
var
|
|
5573
|
-
var preservedDiscount =
|
|
5574
|
-
var
|
|
5591
|
+
var _previousMainOriginal = new Decimal(Number((_targetProduct$metada12 = targetProduct.metadata) === null || _targetProduct$metada12 === void 0 ? void 0 : _targetProduct$metada12.main_product_original_price) || 0);
|
|
5592
|
+
var _previousMainSelling = new Decimal(Number((_targetProduct$metada13 = (_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.main_product_selling_price) !== null && _targetProduct$metada13 !== void 0 ? _targetProduct$metada13 : _previousMainOriginal.toNumber()));
|
|
5593
|
+
var preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
|
|
5594
|
+
var _nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5575
5595
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5576
5596
|
source_product_price: String(updates.metadata.source_product_price),
|
|
5577
|
-
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) :
|
|
5578
|
-
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) :
|
|
5597
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
5598
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : hasResolvedWeighedPrice && isManualProductDiscountProduct(nextProduct) ? _previousMainSelling.toFixed(2) : _nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
5579
5599
|
price_schema_version: 2
|
|
5580
5600
|
});
|
|
5581
|
-
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5601
|
+
} else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5582
5602
|
// variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
|
|
5583
5603
|
// 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
|
|
5584
5604
|
// 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
|
|
@@ -5588,24 +5608,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5588
5608
|
delete nextProduct.metadata.main_product_selling_price;
|
|
5589
5609
|
delete nextProduct.metadata.main_product_original_price;
|
|
5590
5610
|
delete nextProduct.metadata.price_schema_version;
|
|
5591
|
-
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5592
|
-
var
|
|
5611
|
+
} else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5612
|
+
var _ref86, _targetProduct$metada15, _targetProduct$metada16, _ref87, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
|
|
5593
5613
|
// 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
|
|
5594
5614
|
// 但必须让 original 与 selling 一起随新的 option 金额移动。
|
|
5595
5615
|
var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
|
|
5596
5616
|
var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
|
|
5597
|
-
var
|
|
5598
|
-
var
|
|
5599
|
-
var _preservedDiscount =
|
|
5600
|
-
var previousSource = ((_targetProduct$
|
|
5601
|
-
var
|
|
5617
|
+
var _previousMainOriginal2 = new Decimal(Number((_ref86 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref86 !== void 0 ? _ref86 : 0) || 0);
|
|
5618
|
+
var _previousMainSelling2 = new Decimal(Number((_ref87 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref87 !== void 0 ? _ref87 : _previousMainOriginal2.toNumber()) || 0);
|
|
5619
|
+
var _preservedDiscount = _previousMainOriginal2.minus(_previousMainSelling2);
|
|
5620
|
+
var previousSource = ((_targetProduct$metada19 = targetProduct.metadata) === null || _targetProduct$metada19 === void 0 ? void 0 : _targetProduct$metada19.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal2.minus(previousOptionSum);
|
|
5621
|
+
var _nextMainOriginal2 = previousSource.plus(nextOptionSum);
|
|
5602
5622
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5603
5623
|
source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
|
|
5604
|
-
main_product_original_price:
|
|
5605
|
-
main_product_selling_price:
|
|
5624
|
+
main_product_original_price: _nextMainOriginal2.toDecimalPlaces(2).toFixed(2),
|
|
5625
|
+
main_product_selling_price: _nextMainOriginal2.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
5606
5626
|
price_schema_version: 2
|
|
5607
5627
|
});
|
|
5608
|
-
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5628
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
|
|
5609
5629
|
var _existedMeta = nextProduct.metadata || {};
|
|
5610
5630
|
nextProduct.metadata = _objectSpread({}, _existedMeta);
|
|
5611
5631
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -5613,11 +5633,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5613
5633
|
delete nextProduct.metadata.main_product_original_price;
|
|
5614
5634
|
delete nextProduct.metadata.price_schema_version;
|
|
5615
5635
|
}
|
|
5636
|
+
if (callerChangesLineConfiguration && resolveWeighedSourcePrice(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
|
|
5637
|
+
var _nextProduct$metadata;
|
|
5638
|
+
var originalPrice = composeLinePrice({
|
|
5639
|
+
mainPrice: nextProduct.metadata.main_product_original_price,
|
|
5640
|
+
bundle: withOriginalBundleOptionPrices(nextProduct.product_bundle),
|
|
5641
|
+
useOriginalBundle: true
|
|
5642
|
+
});
|
|
5643
|
+
var sellingPrice = composeLinePrice({
|
|
5644
|
+
mainPrice: nextProduct.metadata.main_product_selling_price,
|
|
5645
|
+
bundle: nextProduct.product_bundle
|
|
5646
|
+
});
|
|
5647
|
+
var previousManualDiscount = findManualProductDiscountItem(nextProduct.discount_list);
|
|
5648
|
+
nextProduct.original_price = originalPrice;
|
|
5649
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5650
|
+
origin: _objectSpread(_objectSpread({}, nextProduct.metadata.origin), {}, {
|
|
5651
|
+
_extend: _objectSpread(_objectSpread({}, (_nextProduct$metadata = nextProduct.metadata.origin) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata._extend), {}, {
|
|
5652
|
+
origin_total: Number(originalPrice)
|
|
5653
|
+
})
|
|
5654
|
+
})
|
|
5655
|
+
});
|
|
5656
|
+
nextProduct.discount_list = mergeManualProductDiscountIntoList(nextProduct.discount_list, buildManualProductDiscountItem({
|
|
5657
|
+
originTotal: Number(originalPrice),
|
|
5658
|
+
sellingTotal: Number(sellingPrice),
|
|
5659
|
+
quantity: nextProduct.num,
|
|
5660
|
+
message: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.message,
|
|
5661
|
+
discountway: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discountway,
|
|
5662
|
+
discount_per: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discount_per
|
|
5663
|
+
}));
|
|
5664
|
+
}
|
|
5616
5665
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
5617
5666
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
5618
5667
|
var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
|
|
5619
5668
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
|
|
5620
|
-
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$
|
|
5669
|
+
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata2 = nextProduct.metadata) === null || _nextProduct$metadata2 === void 0 ? void 0 : _nextProduct$metadata2.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada20 = targetProduct.metadata) === null || _targetProduct$metada20 === void 0 ? void 0 : _targetProduct$metada20.booking_uid);
|
|
5621
5670
|
if (!booking && preservedBookingUid) {
|
|
5622
5671
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
5623
5672
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
@@ -5625,8 +5674,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5625
5674
|
});
|
|
5626
5675
|
}
|
|
5627
5676
|
if (booking) {
|
|
5628
|
-
var _normalizedProduct$me, _targetProduct$
|
|
5629
|
-
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$
|
|
5677
|
+
var _normalizedProduct$me, _targetProduct$metada21;
|
|
5678
|
+
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada21 = targetProduct.metadata) === null || _targetProduct$metada21 === void 0 ? void 0 : _targetProduct$metada21.unique_identification_number) || unique_identification_number || createUuidV4());
|
|
5630
5679
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
5631
5680
|
unique_identification_number: productUid
|
|
5632
5681
|
});
|
|
@@ -5646,6 +5695,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5646
5695
|
});
|
|
5647
5696
|
tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
|
|
5648
5697
|
}
|
|
5698
|
+
if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
|
|
5699
|
+
var _normalizedProduct$me2;
|
|
5700
|
+
var uid = (_normalizedProduct$me2 = normalizedProduct.metadata) === null || _normalizedProduct$me2 === void 0 ? void 0 : _normalizedProduct$me2.unique_identification_number;
|
|
5701
|
+
if (uid) reapplyWeighedDiscountProductUids === null || reapplyWeighedDiscountProductUids === void 0 || reapplyWeighedDiscountProductUids.push(String(uid));
|
|
5702
|
+
}
|
|
5649
5703
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
5650
5704
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
5651
5705
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
|
|
@@ -5655,32 +5709,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5655
5709
|
key: "updateOrderProduct",
|
|
5656
5710
|
value: function () {
|
|
5657
5711
|
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
|
|
5658
|
-
var tempOrder, updatedProductUid, promotionPayload;
|
|
5712
|
+
var tempOrder, reapplyWeighedDiscountProductUids, updatedProductUid, promotionPayload;
|
|
5659
5713
|
return _regeneratorRuntime().wrap(function _callee25$(_context27) {
|
|
5660
5714
|
while (1) switch (_context27.prev = _context27.next) {
|
|
5661
5715
|
case 0:
|
|
5662
5716
|
tempOrder = this.ensureTempOrder();
|
|
5663
|
-
|
|
5664
|
-
|
|
5717
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5718
|
+
updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5719
|
+
_context27.next = 5;
|
|
5665
5720
|
return this.evaluatePromotion();
|
|
5666
|
-
case
|
|
5721
|
+
case 5:
|
|
5667
5722
|
promotionPayload = _context27.sent;
|
|
5668
5723
|
this.applyDiscount({
|
|
5724
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5669
5725
|
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
|
|
5670
5726
|
});
|
|
5671
5727
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5672
|
-
_context27.next =
|
|
5728
|
+
_context27.next = 10;
|
|
5673
5729
|
return this.recalculateSummary({
|
|
5674
5730
|
createIfMissing: true
|
|
5675
5731
|
});
|
|
5676
|
-
case
|
|
5732
|
+
case 10:
|
|
5677
5733
|
this.persistTempOrder();
|
|
5678
5734
|
this.emitPromotionApplied(promotionPayload);
|
|
5679
5735
|
this.logInfo('updateOrderProduct success', {
|
|
5680
5736
|
params: params
|
|
5681
5737
|
});
|
|
5682
5738
|
return _context27.abrupt("return", tempOrder.products);
|
|
5683
|
-
case
|
|
5739
|
+
case 14:
|
|
5684
5740
|
case "end":
|
|
5685
5741
|
return _context27.stop();
|
|
5686
5742
|
}
|
|
@@ -5696,7 +5752,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5696
5752
|
value: function () {
|
|
5697
5753
|
var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
|
|
5698
5754
|
var _this36 = this;
|
|
5699
|
-
var tempOrder, reapplyBookingDiscountProductUids;
|
|
5755
|
+
var tempOrder, reapplyWeighedDiscountProductUids, reapplyBookingDiscountProductUids;
|
|
5700
5756
|
return _regeneratorRuntime().wrap(function _callee26$(_context28) {
|
|
5701
5757
|
while (1) switch (_context28.prev = _context28.next) {
|
|
5702
5758
|
case 0:
|
|
@@ -5707,24 +5763,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5707
5763
|
}
|
|
5708
5764
|
return _context28.abrupt("return", tempOrder.products);
|
|
5709
5765
|
case 3:
|
|
5766
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5710
5767
|
reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
|
|
5711
|
-
var updatedProductUid = _this36.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
5768
|
+
var updatedProductUid = _this36.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5712
5769
|
// 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
|
|
5713
5770
|
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
5714
5771
|
acc.push(String(updatedProductUid));
|
|
5715
5772
|
}
|
|
5716
5773
|
return acc;
|
|
5717
5774
|
}, []);
|
|
5718
|
-
_context28.next =
|
|
5775
|
+
_context28.next = 7;
|
|
5719
5776
|
return this.finalizeAfterProductsMutation(tempOrder, {
|
|
5777
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5720
5778
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
5721
5779
|
});
|
|
5722
|
-
case
|
|
5780
|
+
case 7:
|
|
5723
5781
|
this.logInfo('updateOrderProduct success', {
|
|
5724
5782
|
paramsList: paramsList
|
|
5725
5783
|
});
|
|
5726
5784
|
return _context28.abrupt("return", tempOrder.products);
|
|
5727
|
-
case
|
|
5785
|
+
case 9:
|
|
5728
5786
|
case "end":
|
|
5729
5787
|
return _context28.stop();
|
|
5730
5788
|
}
|
|
@@ -5739,7 +5797,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5739
5797
|
key: "updateOrderProductQuantity",
|
|
5740
5798
|
value: function () {
|
|
5741
5799
|
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
|
|
5742
|
-
var _targetProduct$
|
|
5800
|
+
var _targetProduct$metada22;
|
|
5743
5801
|
var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, isPersistedOrderLine, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
|
|
5744
5802
|
return _regeneratorRuntime().wrap(function _callee27$(_context29) {
|
|
5745
5803
|
while (1) switch (_context29.prev = _context29.next) {
|
|
@@ -5782,7 +5840,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5782
5840
|
normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
|
|
5783
5841
|
num: getSafeProductNum(num),
|
|
5784
5842
|
metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
|
|
5785
|
-
unique_identification_number: ((_targetProduct$
|
|
5843
|
+
unique_identification_number: ((_targetProduct$metada22 = targetProduct.metadata) === null || _targetProduct$metada22 === void 0 ? void 0 : _targetProduct$metada22.unique_identification_number) || unique_identification_number
|
|
5786
5844
|
})
|
|
5787
5845
|
})));
|
|
5788
5846
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
|
|
@@ -5903,7 +5961,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5903
5961
|
case 3:
|
|
5904
5962
|
promotionPayload = _context30.sent;
|
|
5905
5963
|
this.applyDiscount({
|
|
5906
|
-
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
|
|
5964
|
+
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
5965
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
|
|
5907
5966
|
});
|
|
5908
5967
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5909
5968
|
_context30.next = 8;
|
|
@@ -6215,23 +6274,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6215
6274
|
}, {
|
|
6216
6275
|
key: "buildCurrentSubmitPayloadForLocalPrint",
|
|
6217
6276
|
value: function buildCurrentSubmitPayloadForLocalPrint(params) {
|
|
6218
|
-
var _params$cacheId, _this$otherParams5,
|
|
6277
|
+
var _params$cacheId, _this$otherParams5, _ref88, _params$businessCode, _this$otherParams6, _this$otherParams7;
|
|
6219
6278
|
var tempOrder = this.ensureTempOrder();
|
|
6220
6279
|
this.persistTempOrder();
|
|
6221
6280
|
var payload = buildSubmitPayload({
|
|
6222
6281
|
tempOrder: tempOrder,
|
|
6223
6282
|
cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
|
|
6224
6283
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
|
|
6225
|
-
businessCode: (
|
|
6284
|
+
businessCode: (_ref88 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref88 !== void 0 ? _ref88 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
|
|
6226
6285
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
6227
6286
|
type: params === null || params === void 0 ? void 0 : params.type,
|
|
6228
6287
|
summary: this.store.summary || createEmptySummary(),
|
|
6229
6288
|
enhance: function enhance(nextPayload) {
|
|
6230
|
-
var
|
|
6289
|
+
var _ref89, _tempOrder$order_numb, _ref90, _tempOrder$shop_order2, _ref91, _tempOrder$shop_full_;
|
|
6231
6290
|
return _objectSpread(_objectSpread({}, nextPayload), {}, {
|
|
6232
|
-
order_number: (
|
|
6233
|
-
shop_order_number: (
|
|
6234
|
-
shop_full_order_number: (
|
|
6291
|
+
order_number: (_ref89 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref89 !== void 0 ? _ref89 : null,
|
|
6292
|
+
shop_order_number: (_ref90 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref90 !== void 0 ? _ref90 : null,
|
|
6293
|
+
shop_full_order_number: (_ref91 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref91 !== void 0 ? _ref91 : null,
|
|
6235
6294
|
small_ticket_data_flag: 1
|
|
6236
6295
|
});
|
|
6237
6296
|
}
|
|
@@ -6395,7 +6454,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6395
6454
|
key: "runSubmitTempOrder",
|
|
6396
6455
|
value: function () {
|
|
6397
6456
|
var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
|
|
6398
|
-
var _params$cacheId3, _this$otherParams12,
|
|
6457
|
+
var _params$cacheId3, _this$otherParams12, _ref92, _ref93, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
|
|
6399
6458
|
var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
|
|
6400
6459
|
return _regeneratorRuntime().wrap(function _callee37$(_context40) {
|
|
6401
6460
|
while (1) switch (_context40.prev = _context40.next) {
|
|
@@ -6462,7 +6521,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6462
6521
|
tempOrder: tempOrder,
|
|
6463
6522
|
cacheId: effectiveCacheId,
|
|
6464
6523
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
|
|
6465
|
-
businessCode: (
|
|
6524
|
+
businessCode: (_ref92 = (_ref93 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref93 !== void 0 ? _ref93 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref92 !== void 0 ? _ref92 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
|
|
6466
6525
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
6467
6526
|
type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
|
|
6468
6527
|
summary: latestSummary,
|
|
@@ -7582,7 +7641,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7582
7641
|
_step24;
|
|
7583
7642
|
try {
|
|
7584
7643
|
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
7585
|
-
var _product$metadata14,
|
|
7644
|
+
var _product$metadata14, _ref94, _ref95, _existed$origin, _rawProduct$metadata;
|
|
7586
7645
|
var _step24$value = _slicedToArray(_step24.value, 2),
|
|
7587
7646
|
index = _step24$value[0],
|
|
7588
7647
|
product = _step24$value[1];
|
|
@@ -7590,7 +7649,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7590
7649
|
if (!uid) continue;
|
|
7591
7650
|
var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
|
|
7592
7651
|
var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
|
|
7593
|
-
var origin = (
|
|
7652
|
+
var origin = (_ref94 = (_ref95 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref95 !== void 0 ? _ref95 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref94 !== void 0 ? _ref94 : rawProduct;
|
|
7594
7653
|
var originSnapshot = cloneDeep(origin);
|
|
7595
7654
|
var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
7596
7655
|
if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
|
|
@@ -7719,10 +7778,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7719
7778
|
}, {
|
|
7720
7779
|
key: "normalizeHydratedProductOptionItem",
|
|
7721
7780
|
value: function normalizeHydratedProductOptionItem(optionItem) {
|
|
7722
|
-
var
|
|
7723
|
-
var rawNum = (
|
|
7781
|
+
var _ref96, _optionItem$num, _ref97, _optionItem$add_price;
|
|
7782
|
+
var rawNum = (_ref96 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref96 !== void 0 ? _ref96 : 1;
|
|
7724
7783
|
var parsedNum = Number(rawNum);
|
|
7725
|
-
var rawPrice = (
|
|
7784
|
+
var rawPrice = (_ref97 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref97 !== void 0 ? _ref97 : 0;
|
|
7726
7785
|
var parsedPrice = Number(rawPrice);
|
|
7727
7786
|
var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
|
|
7728
7787
|
option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
2
|
+
export declare function getWeighedProductPriceFingerprint(sku?: Record<string, any>): string;
|
|
3
|
+
/**
|
|
4
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
5
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
6
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveWeighedSourcePrice(sku?: Record<string, any>, weighing?: Record<string, any>): string | undefined;
|
|
9
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
10
|
+
export declare function withOriginalBundleOptionPrices(bundles?: Array<Record<string, any>>): {
|
|
11
|
+
option: any;
|
|
12
|
+
}[] | undefined;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import Decimal from 'decimal.js';
|
|
8
|
+
var UNIT_GRAMS = {
|
|
9
|
+
kg: '1000',
|
|
10
|
+
KILOGRAMS: '1000',
|
|
11
|
+
g: '1',
|
|
12
|
+
GRAMS: '1',
|
|
13
|
+
lb: '453.59237',
|
|
14
|
+
POUNDS: '453.59237',
|
|
15
|
+
oz: '28.349523125',
|
|
16
|
+
OUNCES: '28.349523125'
|
|
17
|
+
};
|
|
18
|
+
function nonNegative(value) {
|
|
19
|
+
if (value === null || value === undefined || value === '') return undefined;
|
|
20
|
+
try {
|
|
21
|
+
var result = new Decimal(value);
|
|
22
|
+
return result.isFinite() && result.gte(0) ? result : undefined;
|
|
23
|
+
} catch (_unused) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function numericKey(value) {
|
|
28
|
+
var _nonNegative;
|
|
29
|
+
return (_nonNegative = nonNegative(value)) === null || _nonNegative === void 0 ? void 0 : _nonNegative.toString();
|
|
30
|
+
}
|
|
31
|
+
function unitKey(value) {
|
|
32
|
+
return UNIT_GRAMS[String(value)] || (value == null ? undefined : String(value));
|
|
33
|
+
}
|
|
34
|
+
function snapshotKey(snapshot) {
|
|
35
|
+
var _snapshot$unit_value;
|
|
36
|
+
return [numericKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price), unitKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit), numericKey((_snapshot$unit_value = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value !== void 0 ? _snapshot$unit_value : 1)];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
40
|
+
export function getWeighedProductPriceFingerprint(sku) {
|
|
41
|
+
var _sku$unit_weight;
|
|
42
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1) return 'unweighed';
|
|
43
|
+
return JSON.stringify([1, numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight), unitKey(sku === null || sku === void 0 ? void 0 : sku.unit), numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price), numericKey((_sku$unit_weight = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight !== void 0 ? _sku$unit_weight : 1), snapshotKey(sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot)]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
48
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
49
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
50
|
+
*/
|
|
51
|
+
export function resolveWeighedSourcePrice(sku, weighing) {
|
|
52
|
+
var _snapshot$unit_value2, _weighing$unit_weight, _sku$unit_weight2, _measurement$unit_wei;
|
|
53
|
+
if ((sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) != null && Number(sku.open_sold_weight) !== 1) return undefined;
|
|
54
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1 && !weighing) return undefined;
|
|
55
|
+
var hasSkuMeasurement = (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== undefined && (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== null;
|
|
56
|
+
var measurement = hasSkuMeasurement ? sku : weighing;
|
|
57
|
+
var netWeight = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.net_weight);
|
|
58
|
+
if (netWeight === undefined) return undefined;
|
|
59
|
+
var snapshot = hasSkuMeasurement ? sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot : weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct;
|
|
60
|
+
var snapshotPrice = nonNegative(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price);
|
|
61
|
+
var snapshotUnits = nonNegative((_snapshot$unit_value2 = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value2 !== void 0 ? _snapshot$unit_value2 : 1);
|
|
62
|
+
var sourceGrams = UNIT_GRAMS[String(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit)];
|
|
63
|
+
var targetGrams = UNIT_GRAMS[String(measurement === null || measurement === void 0 ? void 0 : measurement.unit)];
|
|
64
|
+
if (snapshotPrice && snapshotUnits !== null && snapshotUnits !== void 0 && snapshotUnits.gt(0) && sourceGrams && targetGrams) {
|
|
65
|
+
return snapshotPrice.mul(netWeight).mul(targetGrams).div(sourceGrams).div(snapshotUnits).toFixed(2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Legacy callers may only retain the native scale's amount. Do not let an old
|
|
69
|
+
// amount overwrite a changed SKU measurement, unit price, or pricing snapshot.
|
|
70
|
+
var runtimeAmount = nonNegative(weighing === null || weighing === void 0 ? void 0 : weighing.total_amount);
|
|
71
|
+
var runtimeMatchesSku = !hasSkuMeasurement || numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.net_weight) === numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight) && unitKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit) === unitKey(sku === null || sku === void 0 ? void 0 : sku.unit) && numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit_price) === numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price) && numericKey((_weighing$unit_weight = weighing === null || weighing === void 0 ? void 0 : weighing.unit_weight) !== null && _weighing$unit_weight !== void 0 ? _weighing$unit_weight : 1) === numericKey((_sku$unit_weight2 = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight2 !== void 0 ? _sku$unit_weight2 : 1) && JSON.stringify(snapshotKey(weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct)) === JSON.stringify(snapshotKey(sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot));
|
|
72
|
+
if (runtimeAmount && runtimeMatchesSku) return runtimeAmount.toFixed(2);
|
|
73
|
+
|
|
74
|
+
// Older persisted orders have only a rounded per-scale-unit price.
|
|
75
|
+
var unitPrice = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.unit_price);
|
|
76
|
+
var unitWeight = nonNegative((_measurement$unit_wei = measurement === null || measurement === void 0 ? void 0 : measurement.unit_weight) !== null && _measurement$unit_wei !== void 0 ? _measurement$unit_wei : 1);
|
|
77
|
+
if (!unitPrice || !(unitWeight !== null && unitWeight !== void 0 && unitWeight.gt(0))) return undefined;
|
|
78
|
+
return netWeight.div(unitWeight).mul(unitPrice).toFixed(2);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
82
|
+
export function withOriginalBundleOptionPrices(bundles) {
|
|
83
|
+
return bundles === null || bundles === void 0 ? void 0 : bundles.map(function (bundle) {
|
|
84
|
+
var _bundle$option;
|
|
85
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
86
|
+
option: (_bundle$option = bundle.option) === null || _bundle$option === void 0 ? void 0 : _bundle$option.map(function (option) {
|
|
87
|
+
var _ref, _option$original_pric;
|
|
88
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
89
|
+
add_price: (_ref = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref !== void 0 ? _ref : option.price
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -25,6 +25,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
25
25
|
import dayjs from "dayjs";
|
|
26
26
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
27
27
|
import Decimal from 'decimal.js';
|
|
28
|
+
import { withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
29
|
+
import { hasManualProductDiscountFlag } from "./utils/manualProductDiscount";
|
|
28
30
|
import { getProductHolderConfig } from "../Holder/utils";
|
|
29
31
|
import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
|
|
30
32
|
import { createUuidV4 } from "./utils/orderCollectionIdentity";
|
|
@@ -897,7 +899,7 @@ export function createDefaultOrderRulesHooks(getBookings) {
|
|
|
897
899
|
};
|
|
898
900
|
},
|
|
899
901
|
setProduct: function setProduct(product, values) {
|
|
900
|
-
var _ref32, _values$quantity, _ref33, _metadataAny$source_p, _values$discount_list, _values$quantity2;
|
|
902
|
+
var _ref32, _values$quantity, _ref33, _metadataAny$source_p, _product$product_sku, _values$discount_list, _values$quantity2;
|
|
901
903
|
var nextNum = Number((_ref32 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref32 !== void 0 ? _ref32 : 1) || 1;
|
|
902
904
|
var metadataAny = product.metadata || {};
|
|
903
905
|
var existedSource = (_ref33 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref33 !== void 0 ? _ref33 : '0';
|
|
@@ -923,7 +925,7 @@ export function createDefaultOrderRulesHooks(getBookings) {
|
|
|
923
925
|
});
|
|
924
926
|
var composedOriginalPrice = composeLinePrice({
|
|
925
927
|
mainPrice: nextMainOriginalPrice,
|
|
926
|
-
bundle: nextBundle,
|
|
928
|
+
bundle: Number((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) === 1 && hasManualProductDiscountFlag(metadataAny) ? withOriginalBundleOptionPrices(nextBundle) : nextBundle,
|
|
927
929
|
useOriginalBundle: true
|
|
928
930
|
});
|
|
929
931
|
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
@@ -1627,11 +1629,11 @@ export function mapPaymentItemsToOrderPayments(paymentItems) {
|
|
|
1627
1629
|
*/
|
|
1628
1630
|
export function formatV1Product(products) {
|
|
1629
1631
|
return products.map(function (product) {
|
|
1630
|
-
var _product$
|
|
1632
|
+
var _product$product_sku2, _product$note;
|
|
1631
1633
|
return {
|
|
1632
1634
|
bundle: product.product_bundle,
|
|
1633
1635
|
key: product.product_id,
|
|
1634
|
-
option: ((_product$
|
|
1636
|
+
option: ((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) || [],
|
|
1635
1637
|
product_id: product.product_id,
|
|
1636
1638
|
product_variant_id: product.product_variant_id,
|
|
1637
1639
|
num: product.product_quantity,
|
|
@@ -387,7 +387,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
387
387
|
}) && productList.find(function (n) {
|
|
388
388
|
return !n.booking_id;
|
|
389
389
|
});
|
|
390
|
-
var
|
|
390
|
+
var reapplyWeighedDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids) || []).map(String));
|
|
391
|
+
var reapplyBookingDiscountProductUids = new Set([].concat(_toConsumableArray((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []), _toConsumableArray(reapplyWeighedDiscountProductUids)).filter(function (uid) {
|
|
391
392
|
return uid !== undefined && uid !== null && uid !== '';
|
|
392
393
|
}).map(String));
|
|
393
394
|
var getOriginProductUid = function getOriginProductUid(originProduct) {
|
|
@@ -1319,7 +1320,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1319
1320
|
}));
|
|
1320
1321
|
|
|
1321
1322
|
// 已持久化且已有钱包券/折扣卡的商品行跳过,保留后端历史折扣结果。
|
|
1322
|
-
|
|
1323
|
+
var isReweighedProduct = reapplyWeighedDiscountProductUids.has(getOriginProductUid(originProduct) || '');
|
|
1324
|
+
if (isPersistedProduct && hasExistingWalletDiscount && !isReweighedProduct) {
|
|
1323
1325
|
if (flatItem.type === 'main') {
|
|
1324
1326
|
processedProductsMap.set(product._id, [originProduct]);
|
|
1325
1327
|
}
|