@pisell/pisellos 2.3.127 → 2.3.128
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
- package/dist/modules/Customer/index.js +3 -6
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +151 -37
- package/dist/modules/Discount/types.d.ts +5 -36
- package/dist/modules/Order/index.d.ts +2 -7
- package/dist/modules/Order/index.js +331 -480
- package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.d.ts +1 -1
- package/dist/modules/Order/utils.js +65 -104
- package/dist/modules/Payment/types.d.ts +1 -21
- package/dist/modules/Payment/types.js +0 -2
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +47 -80
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +190 -482
- package/dist/modules/Rules/types.d.ts +2 -4
- package/dist/server/modules/order/types.d.ts +0 -2
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +2 -3
- package/dist/solution/BaseSales/index.js +77 -44
- package/dist/solution/BaseSales/types.d.ts +7 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
- 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 +3 -2
- package/dist/solution/BookingTicket/index.js +63 -60
- package/dist/solution/BookingTicket/types.d.ts +1 -5
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
- package/dist/solution/ScanOrder/utils.js +3 -2
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +42 -99
- package/dist/solution/ShopDiscount/utils.d.ts +2 -4
- package/dist/solution/ShopDiscount/utils.js +23 -43
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
- package/lib/modules/Customer/index.js +1 -5
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +129 -23
- package/lib/modules/Discount/types.d.ts +5 -36
- package/lib/modules/Order/index.d.ts +2 -7
- package/lib/modules/Order/index.js +109 -222
- package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.d.ts +1 -1
- package/lib/modules/Order/utils.js +6 -41
- package/lib/modules/Payment/types.d.ts +1 -21
- package/lib/modules/Payment/types.js +0 -1
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +9 -29
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +114 -359
- package/lib/modules/Rules/types.d.ts +2 -4
- package/lib/server/modules/order/types.d.ts +0 -2
- package/lib/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +2 -3
- package/lib/solution/BaseSales/index.js +17 -11
- package/lib/solution/BaseSales/types.d.ts +7 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
- 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 +3 -2
- package/lib/solution/BookingTicket/index.js +33 -36
- package/lib/solution/BookingTicket/types.d.ts +1 -5
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
- package/lib/solution/ScanOrder/utils.js +2 -1
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +9 -55
- package/lib/solution/ShopDiscount/utils.d.ts +2 -4
- package/lib/solution/ShopDiscount/utils.js +25 -42
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -49
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -43
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -141
|
@@ -8,8 +8,8 @@ var _BaseModule = require("../BaseModule");
|
|
|
8
8
|
var _types = require("./types");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
var _utils2 = require("../Product/utils");
|
|
11
|
+
var _weighedProduct = require("./utils/weighedProduct");
|
|
11
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
-
var _availability = require("../Discount/availability");
|
|
13
13
|
var _osPrivatePayload = require("../../utils/os-private-payload");
|
|
14
14
|
var _salesNotes = require("./salesNotes");
|
|
15
15
|
var _paymentUtils = require("./payment-utils");
|
|
@@ -23,7 +23,6 @@ var _discountProductLineIdentity = require("./utils/discountProductLineIdentity"
|
|
|
23
23
|
var _virtualSettlement = require("./utils/virtualSettlement");
|
|
24
24
|
var _Discount = require("../Discount");
|
|
25
25
|
var _Rules = require("../Rules");
|
|
26
|
-
var _entitlementPass = require("../Discount/entitlementPass");
|
|
27
26
|
var _types2 = require("../Rules/types");
|
|
28
27
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
29
28
|
var _lodashEs = require("lodash-es");
|
|
@@ -43,27 +42,9 @@ function isSameDiscountList(left, right) {
|
|
|
43
42
|
function isManualProductDiscountProduct(product) {
|
|
44
43
|
return (0, _manualProductDiscount.hasManualProductDiscountFlag)(product?.metadata) || (product?.discount_list || []).some(item => item?.type === 'product');
|
|
45
44
|
}
|
|
46
|
-
function syncReducedEntitlementPassUsageCount(discountList, previousQuantity, nextQuantity) {
|
|
47
|
-
if (!Array.isArray(discountList)) return discountList;
|
|
48
|
-
const previousCount = (0, _utils3.getSafeProductNum)(previousQuantity);
|
|
49
|
-
const nextCount = (0, _utils3.getSafeProductNum)(nextQuantity);
|
|
50
|
-
if (nextCount >= previousCount) return discountList;
|
|
51
|
-
return discountList.map(discount => {
|
|
52
|
-
if (!(0, _entitlementPass.isEntitlementPass)(discount)) return discount;
|
|
53
|
-
const rawUsageCount = Number(discount?.metadata?.num ?? previousCount);
|
|
54
|
-
const usageCount = Number.isFinite(rawUsageCount) ? Math.max(Math.floor(rawUsageCount), 0) : previousCount;
|
|
55
|
-
return {
|
|
56
|
-
...discount,
|
|
57
|
-
metadata: {
|
|
58
|
-
...(discount?.metadata || {}),
|
|
59
|
-
num: Math.min(usageCount, nextCount)
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
45
|
const ORDER_PAYMENT_STATUS_PAID = 'paid';
|
|
65
46
|
const ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
|
|
66
|
-
const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['
|
|
47
|
+
const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
|
|
67
48
|
function isCustomerPromotionDiscount(discount) {
|
|
68
49
|
return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String(discount?.tag || discount?.type || '').toLowerCase());
|
|
69
50
|
}
|
|
@@ -93,28 +74,6 @@ function getVoucherPaymentLifecycleKey(payment) {
|
|
|
93
74
|
if (!isVoucherPaymentRecord(payment)) return null;
|
|
94
75
|
return `${String(payment.voucher_id)}::${String(payment.status || '')}`;
|
|
95
76
|
}
|
|
96
|
-
function getDiscountIdentityKey(discount) {
|
|
97
|
-
const id = discount?.id;
|
|
98
|
-
if (id === undefined || id === null || id === '') return null;
|
|
99
|
-
return String(id);
|
|
100
|
-
}
|
|
101
|
-
function mergeCommittedEntitlementWithRuntime(committed, runtime) {
|
|
102
|
-
const committedAppliedProductDetails = committed.committedAppliedProductDetails?.length ? committed.committedAppliedProductDetails : committed.appliedProductDetails || [];
|
|
103
|
-
return {
|
|
104
|
-
...committed,
|
|
105
|
-
...runtime,
|
|
106
|
-
id: runtime.id ?? committed.id,
|
|
107
|
-
tag: runtime.tag || committed.tag,
|
|
108
|
-
type: runtime.type || committed.type,
|
|
109
|
-
isEditMode: false,
|
|
110
|
-
isDisabled: runtime.isDisabled ?? false,
|
|
111
|
-
isSelected: runtime.isSelected ?? committed.isSelected,
|
|
112
|
-
isUsed: committed.isUsed || runtime.isUsed,
|
|
113
|
-
committedAppliedProductDetails: [...committedAppliedProductDetails],
|
|
114
|
-
applicableProductDetails: [...(committed.applicableProductDetails || []), ...(runtime.applicableProductDetails || [])],
|
|
115
|
-
appliedProductDetails: [...committedAppliedProductDetails, ...(runtime.appliedProductDetails || [])]
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
77
|
class OrderModule extends _BaseModule.BaseModule {
|
|
119
78
|
defaultName = 'order';
|
|
120
79
|
defaultVersion = '1.0.0';
|
|
@@ -170,7 +129,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
170
129
|
const key = Number.isFinite(id) ? id : String(resourceId);
|
|
171
130
|
const title = item?.discount?.title ?? {};
|
|
172
131
|
const amount = Number(item?.amount || 0);
|
|
173
|
-
const encoded = item?.metadata?.encoded || item?.encoded || item?.discount?.encoded || '';
|
|
174
132
|
const discountCardType = item?.discount?.discount_card_type;
|
|
175
133
|
const parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? item?.discount?.fixed_amount ?? item?.amount : item?.discount?.percent : '0';
|
|
176
134
|
const detail = {
|
|
@@ -181,21 +139,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
181
139
|
original_amount: String(item?.discount?.original_amount ?? item?.amount ?? '0'),
|
|
182
140
|
num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1,
|
|
183
141
|
metadata: item?.metadata,
|
|
184
|
-
discount:
|
|
185
|
-
...(item?.discount || {}),
|
|
186
|
-
product_id: item?.discount?.product_id ?? product?.product_id
|
|
187
|
-
},
|
|
142
|
+
discount: item?.discount,
|
|
188
143
|
_num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1
|
|
189
144
|
};
|
|
190
145
|
const existed = discountMap.get(key);
|
|
191
146
|
if (existed) {
|
|
192
|
-
if (!existed.encoded && encoded) {
|
|
193
|
-
existed.encoded = encoded;
|
|
194
|
-
existed.metadata = {
|
|
195
|
-
...existed.metadata,
|
|
196
|
-
encoded
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
147
|
existed.amount = Number(existed.amount || 0) + amount;
|
|
200
148
|
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
201
149
|
if (!isDiscountCard) {
|
|
@@ -215,11 +163,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
215
163
|
discountMap.set(key, {
|
|
216
164
|
id: key,
|
|
217
165
|
product_name: '',
|
|
218
|
-
encoded,
|
|
219
|
-
code:
|
|
220
|
-
metadata: {
|
|
221
|
-
encoded
|
|
222
|
-
},
|
|
166
|
+
encoded: '',
|
|
167
|
+
code: '',
|
|
223
168
|
tag: type,
|
|
224
169
|
product_id: item?.discount?.discount_product_id ?? product?.product_id ?? 0,
|
|
225
170
|
relation_type: '',
|
|
@@ -510,7 +455,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
510
455
|
this.store.rules = rules;
|
|
511
456
|
}
|
|
512
457
|
createDefaultRulesHooks() {
|
|
513
|
-
return (0, _utils.createDefaultOrderRulesHooks)(
|
|
458
|
+
return (0, _utils.createDefaultOrderRulesHooks)();
|
|
514
459
|
}
|
|
515
460
|
|
|
516
461
|
/**
|
|
@@ -536,8 +481,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
536
481
|
with_wallet_pass_holder: 1,
|
|
537
482
|
with_available_wallet_flag: 1,
|
|
538
483
|
with_available_wallet_pass_flag: 1,
|
|
539
|
-
with_entitlement_pass: 1,
|
|
540
|
-
filter_order_wallet_pass_usage: 0,
|
|
541
484
|
with_virtual_currency: 1,
|
|
542
485
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
543
486
|
...(orderId ? {
|
|
@@ -559,61 +502,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
559
502
|
}
|
|
560
503
|
if (discountList) {
|
|
561
504
|
const currentDiscountList = this.store.discount?.getDiscountList() || [];
|
|
562
|
-
const
|
|
505
|
+
const currentEditDiscounts = currentDiscountList.filter(discount => discount?.isEditMode);
|
|
563
506
|
const currentScanDiscounts = currentDiscountList.filter(discount => discount?.isScan);
|
|
564
|
-
const
|
|
565
|
-
const id = getDiscountIdentityKey(discount);
|
|
566
|
-
return id === null ? [] : [[id, discount]];
|
|
567
|
-
}));
|
|
568
|
-
const committedDiscountById = new Map(currentCommittedDiscounts.flatMap(discount => {
|
|
569
|
-
const id = getDiscountIdentityKey(discount);
|
|
570
|
-
return id === null ? [] : [[id, discount]];
|
|
571
|
-
}));
|
|
572
|
-
const mergedCommittedDiscountIds = new Set();
|
|
573
|
-
const refreshedScanDiscountIds = new Set();
|
|
507
|
+
const currentScanDiscountIds = new Set(currentScanDiscounts.map(discount => discount?.id));
|
|
574
508
|
const runtimeDiscountIds = new Set();
|
|
575
|
-
const runtimeDiscounts = discountList.
|
|
576
|
-
|
|
577
|
-
if (id
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const currentScanDiscount = currentScanDiscountById.get(id);
|
|
581
|
-
if (currentScanDiscount && (!(0, _entitlementPass.isEntitlementPass)(currentScanDiscount) || !(0, _entitlementPass.isEntitlementPass)(discount))) {
|
|
582
|
-
return [];
|
|
583
|
-
}
|
|
584
|
-
const committedDiscount = committedDiscountById.get(id);
|
|
585
|
-
let nextDiscount = discount;
|
|
586
|
-
if (committedDiscount && (0, _entitlementPass.isEntitlementPass)(committedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
|
|
587
|
-
mergedCommittedDiscountIds.add(id);
|
|
588
|
-
nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
|
|
589
|
-
}
|
|
590
|
-
if (currentScanDiscount) {
|
|
591
|
-
refreshedScanDiscountIds.add(id);
|
|
592
|
-
nextDiscount = {
|
|
593
|
-
...nextDiscount,
|
|
594
|
-
isScan: true,
|
|
595
|
-
isSelected: currentScanDiscount.isSelected ?? nextDiscount.isSelected,
|
|
596
|
-
isManualSelect: currentScanDiscount.isManualSelect ?? nextDiscount.isManualSelect
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
return [nextDiscount];
|
|
600
|
-
});
|
|
601
|
-
const retainedCommittedDiscounts = currentCommittedDiscounts.filter(discount => {
|
|
602
|
-
const id = getDiscountIdentityKey(discount);
|
|
603
|
-
return id === null || !mergedCommittedDiscountIds.has(id);
|
|
604
|
-
}).map(discount => discount.committedAppliedProductDetails?.length ? {
|
|
605
|
-
...discount,
|
|
606
|
-
isEditMode: true,
|
|
607
|
-
isDisabled: true,
|
|
608
|
-
isSelected: true,
|
|
609
|
-
isUsed: true,
|
|
610
|
-
appliedProductDetails: [...discount.committedAppliedProductDetails]
|
|
611
|
-
} : discount);
|
|
612
|
-
const retainedScanDiscounts = currentScanDiscounts.filter(discount => {
|
|
613
|
-
const id = getDiscountIdentityKey(discount);
|
|
614
|
-
return id === null || !refreshedScanDiscountIds.has(id);
|
|
509
|
+
const runtimeDiscounts = discountList.filter(discount => {
|
|
510
|
+
if (currentScanDiscountIds.has(discount?.id)) return false;
|
|
511
|
+
if (runtimeDiscountIds.has(discount?.id)) return false;
|
|
512
|
+
runtimeDiscountIds.add(discount?.id);
|
|
513
|
+
return true;
|
|
615
514
|
});
|
|
616
|
-
const mergedDiscountList = [...
|
|
515
|
+
const mergedDiscountList = [...currentEditDiscounts, ...currentScanDiscounts, ...runtimeDiscounts];
|
|
617
516
|
if (!isCurrentRequest()) return this.getDiscountList();
|
|
618
517
|
await this.store.discount?.setOriginalDiscountList(mergedDiscountList);
|
|
619
518
|
if (!isCurrentRequest()) return this.getDiscountList();
|
|
@@ -734,34 +633,19 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
734
633
|
isAvailable: false,
|
|
735
634
|
discountList: this.getDiscountList()
|
|
736
635
|
};
|
|
737
|
-
const
|
|
738
|
-
const evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !(0, _availability.getDiscountLifecycleReason)(discount));
|
|
739
|
-
const shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
|
|
636
|
+
const shouldRetainForLater = !isAvailable && unavailableReason === _types2.UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
|
|
740
637
|
const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
|
|
638
|
+
const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
|
|
741
639
|
let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
|
|
742
640
|
if (isAvailable && normalizedNewDiscountList) {
|
|
743
641
|
await this.store.discount?.setDiscountList(normalizedNewDiscountList);
|
|
744
|
-
|
|
745
|
-
this.applyDiscount({
|
|
746
|
-
preferredEntitlementPassIds: withScanList.filter(discount => (0, _entitlementPass.isEntitlementPass)(discount)).map(discount => discount.id)
|
|
747
|
-
});
|
|
642
|
+
this.applyDiscount();
|
|
748
643
|
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
749
644
|
resolvedDiscountList = this.getDiscountList();
|
|
750
|
-
} else if (shouldRetainForLater) {
|
|
751
|
-
//
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
retainedDiscounts.set(String(discount.id), {
|
|
755
|
-
...discount,
|
|
756
|
-
isScan: true,
|
|
757
|
-
isAvailable: false,
|
|
758
|
-
isSelected: false,
|
|
759
|
-
reasonCode: discount.reasonCode || 'product_not_applicable',
|
|
760
|
-
appliedProductDetails: [],
|
|
761
|
-
savedAmount: 0
|
|
762
|
-
});
|
|
763
|
-
});
|
|
764
|
-
await this.store.discount?.setDiscountList([...retainedDiscounts.values()]);
|
|
645
|
+
} else if (shouldRetainForLater && retainedDiscountList) {
|
|
646
|
+
// 卡券有效但当前购物车没有适用商品:先保留在 Promotion 中,
|
|
647
|
+
// 不执行 applyDiscount,避免修改商品价格或订单金额。
|
|
648
|
+
await this.store.discount?.setDiscountList(retainedDiscountList);
|
|
765
649
|
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
766
650
|
resolvedDiscountList = this.getDiscountList();
|
|
767
651
|
}
|
|
@@ -770,7 +654,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
770
654
|
isAvailable: isAvailable || false,
|
|
771
655
|
isAccepted: Boolean(isAvailable || shouldRetainForLater),
|
|
772
656
|
discountList: resolvedDiscountList,
|
|
773
|
-
scannedDiscountList:
|
|
657
|
+
scannedDiscountList: resultDiscountList,
|
|
774
658
|
unavailableReason
|
|
775
659
|
};
|
|
776
660
|
}
|
|
@@ -803,7 +687,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
803
687
|
orderTotalAmount: Number(this.store.summary?.total_amount || 0)
|
|
804
688
|
}, {
|
|
805
689
|
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
|
|
806
|
-
|
|
690
|
+
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids
|
|
807
691
|
});
|
|
808
692
|
if (result?.productList) {
|
|
809
693
|
const previousProductsByUid = (0, _utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -1759,8 +1643,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1759
1643
|
const sku = product?.product_sku || {};
|
|
1760
1644
|
const metadata = product?.metadata || {};
|
|
1761
1645
|
const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
|
|
1762
|
-
const
|
|
1763
|
-
const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
|
|
1646
|
+
const extensionType = product?.extension_type || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
|
|
1764
1647
|
return {
|
|
1765
1648
|
product_id: product?.product_id ?? null,
|
|
1766
1649
|
product_variant_id: product?.product_variant_id ?? null,
|
|
@@ -1813,8 +1696,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1813
1696
|
const sku = product?.product_sku || {};
|
|
1814
1697
|
const metadata = product?.metadata || {};
|
|
1815
1698
|
const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
|
|
1816
|
-
const
|
|
1817
|
-
const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
|
|
1699
|
+
const extensionType = product?.extension_type || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
|
|
1818
1700
|
return {
|
|
1819
1701
|
product_id: product?.product_id ?? null,
|
|
1820
1702
|
product_variant_id: product?.product_variant_id ?? null,
|
|
@@ -2829,7 +2711,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2829
2711
|
}
|
|
2830
2712
|
isCustomerBoundDiscount(discount) {
|
|
2831
2713
|
const type = discount?.type ?? discount?.tag;
|
|
2832
|
-
return type === '
|
|
2714
|
+
return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
|
|
2833
2715
|
}
|
|
2834
2716
|
shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
|
|
2835
2717
|
return Boolean(discount?.isScan || discount?.isEditMode);
|
|
@@ -3452,35 +3334,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3452
3334
|
}
|
|
3453
3335
|
normalizedIncoming.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedIncoming.discount_list);
|
|
3454
3336
|
const hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
|
|
3455
|
-
const hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
|
|
3456
|
-
const isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
|
|
3457
|
-
const isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
|
|
3458
3337
|
const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
|
|
3459
3338
|
const hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
|
|
3460
3339
|
const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
|
|
3461
3340
|
const isIncomingCustomItem = productToAdd.metadata?.origin?.isCustomItem === true || productToAdd._origin?.isCustomItem === true;
|
|
3462
|
-
const shouldForceNewLine = disableMerge || !!booking ||
|
|
3463
|
-
const matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
|
|
3341
|
+
const shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
|
|
3342
|
+
const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
|
|
3464
3343
|
if (this.hasGoodPassDiscount(item)) return false;
|
|
3465
|
-
|
|
3466
|
-
if (
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
if (isIncomingEntitlementAppend && this.isPersistedProductLine(item)) {
|
|
3470
|
-
return false;
|
|
3471
|
-
}
|
|
3472
|
-
const hasExistingProductNote = this.hasOrderProductLineNote(item);
|
|
3473
|
-
if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
|
|
3474
|
-
return false;
|
|
3475
|
-
}
|
|
3476
|
-
const hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
|
|
3477
|
-
if (isRuntimeEntitlementPass && !this.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
|
|
3478
|
-
return false;
|
|
3479
|
-
}
|
|
3480
|
-
if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
|
|
3481
|
-
return false;
|
|
3482
|
-
}
|
|
3483
|
-
if (this.isPersistedProductLine(item)) return false;
|
|
3344
|
+
if (this.hasOrderProductLineNote(item)) return false;
|
|
3345
|
+
if (isManualProductDiscountProduct(item)) return false;
|
|
3346
|
+
if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
|
|
3347
|
+
if (item.metadata?.is_edit_for_runtime) return false;
|
|
3484
3348
|
if (item.product_id !== productToAdd.product_id) return false;
|
|
3485
3349
|
if (item.product_variant_id !== productToAdd.product_variant_id) return false;
|
|
3486
3350
|
const existedFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(item), item.product_bundle);
|
|
@@ -3781,51 +3645,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3781
3645
|
});
|
|
3782
3646
|
return tempOrder.products;
|
|
3783
3647
|
}
|
|
3784
|
-
|
|
3785
|
-
const
|
|
3648
|
+
hasGoodPassDiscount(product) {
|
|
3649
|
+
const hasMainGoodPass = (product.discount_list || []).some(item => item?.type === 'good_pass' || item?.tag === 'good_pass');
|
|
3650
|
+
if (hasMainGoodPass) return true;
|
|
3651
|
+
const bundleDiscountList = [];
|
|
3786
3652
|
(product.product_bundle || []).forEach(item => {
|
|
3787
|
-
|
|
3653
|
+
bundleDiscountList.push(...(item?.discount_list || []));
|
|
3788
3654
|
});
|
|
3789
3655
|
(product?._extend?.other?.bundle || []).forEach(item => {
|
|
3790
|
-
|
|
3656
|
+
bundleDiscountList.push(...(item?.discount_list || []));
|
|
3791
3657
|
});
|
|
3792
|
-
return
|
|
3793
|
-
}
|
|
3794
|
-
hasEntitlementPassDiscount(product) {
|
|
3795
|
-
return this.getFullCoveragePassDiscounts(product).some(item => (0, _entitlementPass.isEntitlementPass)(item));
|
|
3796
|
-
}
|
|
3797
|
-
hasGoodPassDiscount(product) {
|
|
3798
|
-
return this.getFullCoveragePassDiscounts(product).some(item => !(0, _entitlementPass.isEntitlementPass)(item));
|
|
3799
|
-
}
|
|
3800
|
-
isPersistedProductLine(product) {
|
|
3801
|
-
return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || product.metadata?.is_edit_for_runtime === true;
|
|
3802
|
-
}
|
|
3803
|
-
isRuntimeEntitlementAppend(product, tempOrder) {
|
|
3804
|
-
if (this.isPersistedProductLine(product)) return false;
|
|
3805
|
-
const uid = product.metadata?.unique_identification_number ?? product.unique_identification_number;
|
|
3806
|
-
const storedOrigin = uid !== undefined && uid !== null && uid !== '' ? tempOrder._extend?.productsByUid?.[String(uid)]?.origin : undefined;
|
|
3807
|
-
return Boolean(product?._origin?.__entitlementPassRuntimeAppend === true || storedOrigin?.__entitlementPassRuntimeAppend === true);
|
|
3808
|
-
}
|
|
3809
|
-
hasSameEntitlementMergePriceConfig(incoming, existing) {
|
|
3810
|
-
const buildPriceConfig = product => {
|
|
3811
|
-
const metadata = product.metadata || {};
|
|
3812
|
-
const bundle = (product.product_bundle || []).map(item => ({
|
|
3813
|
-
bundle_id: item.bundle_id ?? item.id ?? null,
|
|
3814
|
-
bundle_product_id: item.bundle_product_id ?? item._bundle_product_id ?? item.product_id ?? null,
|
|
3815
|
-
bundle_variant_id: item.bundle_variant_id ?? item.product_variant_id ?? 0,
|
|
3816
|
-
price_type: item.price_type ?? item.custom_price_type ?? '',
|
|
3817
|
-
price_type_ext: item.price_type_ext ?? item.custom_price_type_ext ?? ''
|
|
3818
|
-
})).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
3819
|
-
return JSON.stringify({
|
|
3820
|
-
original_price: this.normalizeFingerprintMoney(product.original_price),
|
|
3821
|
-
source_product_price: this.normalizeFingerprintMoney(metadata.source_product_price),
|
|
3822
|
-
main_product_original_price: this.normalizeFingerprintMoney(metadata.main_product_original_price),
|
|
3823
|
-
price_override: this.normalizeFingerprintMoney(metadata.price_override),
|
|
3824
|
-
is_manual_discount: Boolean(metadata.is_manual_discount),
|
|
3825
|
-
bundle
|
|
3826
|
-
});
|
|
3827
|
-
};
|
|
3828
|
-
return buildPriceConfig(incoming) === buildPriceConfig(existing);
|
|
3658
|
+
return bundleDiscountList.some(item => item?.type === 'good_pass' || item?.tag === 'good_pass');
|
|
3829
3659
|
}
|
|
3830
3660
|
getBundleRuntimeIdentity(bundle) {
|
|
3831
3661
|
if (!bundle || typeof bundle !== 'object') return '';
|
|
@@ -3857,7 +3687,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3857
3687
|
};
|
|
3858
3688
|
});
|
|
3859
3689
|
}
|
|
3860
|
-
applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
3690
|
+
applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
|
|
3861
3691
|
const {
|
|
3862
3692
|
product_id,
|
|
3863
3693
|
product_variant_id,
|
|
@@ -3930,7 +3760,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3930
3760
|
const previousLineFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(targetProduct), targetProduct.product_bundle);
|
|
3931
3761
|
const nextLineFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(nextProduct), nextProduct.product_bundle);
|
|
3932
3762
|
const callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
3933
|
-
const
|
|
3763
|
+
const callerChangesWeighing = (0, _weighedProduct.getWeighedProductPriceFingerprint)(targetProduct.product_sku) !== (0, _weighedProduct.getWeighedProductPriceFingerprint)(nextProduct.product_sku);
|
|
3764
|
+
const callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
|
|
3934
3765
|
const isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
3935
3766
|
const callerChangesDiscountList = Array.isArray(updates?.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
3936
3767
|
const callerUpdatesManualPrice = updates?.metadata?.price_override !== undefined || updates?.metadata?.is_manual_discount !== undefined || updates?.metadata?.product_discount_reason !== undefined || callerChangesDiscountList;
|
|
@@ -3946,6 +3777,23 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3946
3777
|
};
|
|
3947
3778
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
3948
3779
|
})();
|
|
3780
|
+
const weighedSourcePrice = callerChangesWeighing ? (0, _weighedProduct.resolveWeighedSourcePrice)(nextProduct.product_sku) : undefined;
|
|
3781
|
+
const hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
|
|
3782
|
+
if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
|
|
3783
|
+
const nextMainOriginal = new _decimal.default(weighedSourcePrice).plus((0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(nextProduct)));
|
|
3784
|
+
const previousMainOriginal = new _decimal.default(targetProduct.metadata?.main_product_original_price ?? targetProduct.original_price ?? 0);
|
|
3785
|
+
const previousMainSelling = new _decimal.default(targetProduct.metadata?.main_product_selling_price ?? targetProduct.selling_price ?? 0);
|
|
3786
|
+
// A manual final price remains fixed; other legacy discounts keep their amount
|
|
3787
|
+
// until Rules reapplies the currently selected wallet discount below.
|
|
3788
|
+
const nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
|
|
3789
|
+
nextProduct.metadata = {
|
|
3790
|
+
...nextProduct.metadata,
|
|
3791
|
+
source_product_price: weighedSourcePrice,
|
|
3792
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
|
|
3793
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : _decimal.default.max(0, nextMainSelling).toFixed(2),
|
|
3794
|
+
price_schema_version: 2
|
|
3795
|
+
};
|
|
3796
|
+
}
|
|
3949
3797
|
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
3950
3798
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
3951
3799
|
nextProduct.original_price = targetProduct.original_price;
|
|
@@ -3962,17 +3810,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3962
3810
|
// 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
|
|
3963
3811
|
// 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
|
|
3964
3812
|
const previousMainOriginal = new _decimal.default(Number(targetProduct.metadata?.main_product_original_price) || 0);
|
|
3965
|
-
const previousMainSelling = new _decimal.default(Number(targetProduct.metadata?.main_product_selling_price
|
|
3813
|
+
const previousMainSelling = new _decimal.default(Number(targetProduct.metadata?.main_product_selling_price ?? previousMainOriginal.toNumber()));
|
|
3966
3814
|
const preservedDiscount = previousMainOriginal.minus(previousMainSelling);
|
|
3967
3815
|
const nextMainOriginal = new _decimal.default(Number(updates.metadata.source_product_price) || 0).plus((0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(nextProduct)));
|
|
3968
3816
|
nextProduct.metadata = {
|
|
3969
3817
|
...(nextProduct.metadata || {}),
|
|
3970
3818
|
source_product_price: String(updates.metadata.source_product_price),
|
|
3971
3819
|
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
3972
|
-
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3820
|
+
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),
|
|
3973
3821
|
price_schema_version: 2
|
|
3974
3822
|
};
|
|
3975
|
-
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3823
|
+
} else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3976
3824
|
// variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
|
|
3977
3825
|
// 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
|
|
3978
3826
|
// 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
|
|
@@ -3984,7 +3832,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3984
3832
|
delete nextProduct.metadata.main_product_selling_price;
|
|
3985
3833
|
delete nextProduct.metadata.main_product_original_price;
|
|
3986
3834
|
delete nextProduct.metadata.price_schema_version;
|
|
3987
|
-
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3835
|
+
} else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3988
3836
|
// 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
|
|
3989
3837
|
// 但必须让 original 与 selling 一起随新的 option 金额移动。
|
|
3990
3838
|
const previousOptionSum = (0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(targetProduct));
|
|
@@ -4001,7 +3849,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4001
3849
|
main_product_selling_price: nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
4002
3850
|
price_schema_version: 2
|
|
4003
3851
|
};
|
|
4004
|
-
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3852
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
|
|
4005
3853
|
const existedMeta = nextProduct.metadata || {};
|
|
4006
3854
|
nextProduct.metadata = {
|
|
4007
3855
|
...existedMeta
|
|
@@ -4011,10 +3859,41 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4011
3859
|
delete nextProduct.metadata.main_product_original_price;
|
|
4012
3860
|
delete nextProduct.metadata.price_schema_version;
|
|
4013
3861
|
}
|
|
3862
|
+
if (callerChangesLineConfiguration && (0, _weighedProduct.resolveWeighedSourcePrice)(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
|
|
3863
|
+
const originalPrice = (0, _utils.composeLinePrice)({
|
|
3864
|
+
mainPrice: nextProduct.metadata.main_product_original_price,
|
|
3865
|
+
bundle: (0, _weighedProduct.withOriginalBundleOptionPrices)(nextProduct.product_bundle),
|
|
3866
|
+
useOriginalBundle: true
|
|
3867
|
+
});
|
|
3868
|
+
const sellingPrice = (0, _utils.composeLinePrice)({
|
|
3869
|
+
mainPrice: nextProduct.metadata.main_product_selling_price,
|
|
3870
|
+
bundle: nextProduct.product_bundle
|
|
3871
|
+
});
|
|
3872
|
+
const previousManualDiscount = (0, _manualProductDiscount.findManualProductDiscountItem)(nextProduct.discount_list);
|
|
3873
|
+
nextProduct.original_price = originalPrice;
|
|
3874
|
+
nextProduct.metadata = {
|
|
3875
|
+
...nextProduct.metadata,
|
|
3876
|
+
origin: {
|
|
3877
|
+
...nextProduct.metadata.origin,
|
|
3878
|
+
_extend: {
|
|
3879
|
+
...nextProduct.metadata.origin?._extend,
|
|
3880
|
+
origin_total: Number(originalPrice)
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3884
|
+
nextProduct.discount_list = (0, _manualProductDiscount.mergeManualProductDiscountIntoList)(nextProduct.discount_list, (0, _manualProductDiscount.buildManualProductDiscountItem)({
|
|
3885
|
+
originTotal: Number(originalPrice),
|
|
3886
|
+
sellingTotal: Number(sellingPrice),
|
|
3887
|
+
quantity: nextProduct.num,
|
|
3888
|
+
message: previousManualDiscount?.discount.message,
|
|
3889
|
+
discountway: previousManualDiscount?.discount.discountway,
|
|
3890
|
+
discount_per: previousManualDiscount?.discount.discount_per
|
|
3891
|
+
}));
|
|
3892
|
+
}
|
|
4014
3893
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
4015
3894
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
4016
3895
|
let normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils.mergeOrderProductDisplayFields)(nextProduct, (0, _utils3.normalizeOrderProduct)(nextProduct)));
|
|
4017
|
-
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(
|
|
3896
|
+
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
|
|
4018
3897
|
const preservedBookingUid = nextProduct.booking_uid || nextProduct.metadata?.booking_uid || targetProduct.booking_uid || targetProduct.metadata?.booking_uid;
|
|
4019
3898
|
if (!booking && preservedBookingUid) {
|
|
4020
3899
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
@@ -4048,6 +3927,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4048
3927
|
};
|
|
4049
3928
|
tempOrder.bookings = [...(tempOrder.bookings || []), linked.booking];
|
|
4050
3929
|
}
|
|
3930
|
+
if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
|
|
3931
|
+
const uid = normalizedProduct.metadata?.unique_identification_number;
|
|
3932
|
+
if (uid) reapplyWeighedDiscountProductUids?.push(String(uid));
|
|
3933
|
+
}
|
|
4051
3934
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
4052
3935
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
4053
3936
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], tempOrder.products[productIndex].metadata?.unique_identification_number);
|
|
@@ -4055,9 +3938,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4055
3938
|
}
|
|
4056
3939
|
async updateOrderProduct(params) {
|
|
4057
3940
|
const tempOrder = this.ensureTempOrder();
|
|
4058
|
-
const
|
|
3941
|
+
const reapplyWeighedDiscountProductUids = [];
|
|
3942
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
4059
3943
|
const promotionPayload = await this.evaluatePromotion();
|
|
4060
3944
|
this.applyDiscount({
|
|
3945
|
+
reapplyWeighedDiscountProductUids,
|
|
4061
3946
|
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
|
|
4062
3947
|
});
|
|
4063
3948
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
@@ -4076,8 +3961,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4076
3961
|
if (!paramsList.length) {
|
|
4077
3962
|
return tempOrder.products;
|
|
4078
3963
|
}
|
|
3964
|
+
const reapplyWeighedDiscountProductUids = [];
|
|
4079
3965
|
const reapplyBookingDiscountProductUids = paramsList.reduce((acc, params) => {
|
|
4080
|
-
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3966
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
4081
3967
|
// 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
|
|
4082
3968
|
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
4083
3969
|
acc.push(String(updatedProductUid));
|
|
@@ -4085,6 +3971,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4085
3971
|
return acc;
|
|
4086
3972
|
}, []);
|
|
4087
3973
|
await this.finalizeAfterProductsMutation(tempOrder, {
|
|
3974
|
+
reapplyWeighedDiscountProductUids,
|
|
4088
3975
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
4089
3976
|
});
|
|
4090
3977
|
this.logInfo('updateOrderProduct success', {
|
|
@@ -4131,7 +4018,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4131
4018
|
throw new Error('[Order] 目标商品不存在,无法更新数量');
|
|
4132
4019
|
}
|
|
4133
4020
|
const targetProduct = tempOrder.products[productIndex];
|
|
4134
|
-
const isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
4135
4021
|
const normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils3.normalizeOrderProduct)({
|
|
4136
4022
|
...targetProduct,
|
|
4137
4023
|
num: (0, _utils3.getSafeProductNum)(num),
|
|
@@ -4140,7 +4026,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4140
4026
|
unique_identification_number: targetProduct.metadata?.unique_identification_number || unique_identification_number
|
|
4141
4027
|
}
|
|
4142
4028
|
}));
|
|
4143
|
-
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(
|
|
4029
|
+
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
|
|
4144
4030
|
const settlementSnapshot = (0, _virtualSettlement.getSelectedSettlementSnapshot)(normalizedProduct);
|
|
4145
4031
|
if (this.isMultiCurrencySettlementEnabled() && settlementSnapshot?.settlement_type === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
|
|
4146
4032
|
const currencyProductId = Number(settlementSnapshot.currency_product_id);
|
|
@@ -4217,7 +4103,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4217
4103
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
4218
4104
|
const promotionPayload = await this.evaluatePromotion();
|
|
4219
4105
|
this.applyDiscount({
|
|
4220
|
-
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids
|
|
4106
|
+
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
|
|
4107
|
+
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids
|
|
4221
4108
|
});
|
|
4222
4109
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
4223
4110
|
await this.recalculateSummary({
|
|
@@ -17,7 +17,6 @@ exports.normalizeOrderCollections = normalizeOrderCollections;
|
|
|
17
17
|
exports.repairDuplicateProductLineIdentities = repairDuplicateProductLineIdentities;
|
|
18
18
|
exports.setOrderCollectionUid = setOrderCollectionUid;
|
|
19
19
|
var _lodashEs = require("lodash-es");
|
|
20
|
-
var _entitlementPass = require("../../Discount/entitlementPass");
|
|
21
20
|
const IDENTITY_CONFIG = {
|
|
22
21
|
product: {
|
|
23
22
|
persistentIdField: 'order_detail_id',
|
|
@@ -82,22 +81,20 @@ function setOrderCollectionUid(kind, item, uid) {
|
|
|
82
81
|
delete record[uidField];
|
|
83
82
|
return record;
|
|
84
83
|
}
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
84
|
+
function getGoodPassResourceId(product) {
|
|
85
|
+
const goodPass = (product.discount_list || []).find(item => {
|
|
86
|
+
const type = item?.type || item?.tag || item?.discount?.type || item?.discount?.tag;
|
|
87
|
+
return type === 'good_pass';
|
|
88
|
+
});
|
|
89
|
+
if (!goodPass) return null;
|
|
90
|
+
const resourceId = goodPass.discount?.resource_id ?? goodPass.resource_id ?? goodPass.discount_id ?? goodPass.id;
|
|
91
|
+
return isBlankOrderCollectionIdentity(resourceId) ? null : String(resourceId);
|
|
94
92
|
}
|
|
95
93
|
function buildSplitProductUid(originalUid, product, duplicateOrdinal) {
|
|
96
94
|
const encodedOriginalUid = encodeURIComponent(originalUid);
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
return `os-split:product:${encodedOriginalUid}:${passType}:${encodeURIComponent(passIdentity.resourceId)}:${duplicateOrdinal}`;
|
|
95
|
+
const resourceId = getGoodPassResourceId(product);
|
|
96
|
+
if (resourceId) {
|
|
97
|
+
return `os-split:product:${encodedOriginalUid}:good-pass:${encodeURIComponent(resourceId)}:${duplicateOrdinal}`;
|
|
101
98
|
}
|
|
102
99
|
return `os-split:product:${encodedOriginalUid}:duplicate:${duplicateOrdinal}`;
|
|
103
100
|
}
|
|
@@ -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;
|