@pisell/pisellos 2.3.124 → 2.3.125

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.
Files changed (93) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
  6. package/dist/modules/Customer/index.js +3 -6
  7. package/dist/modules/Customer/types.d.ts +0 -2
  8. package/dist/modules/Discount/index.d.ts +2 -2
  9. package/dist/modules/Discount/index.js +151 -37
  10. package/dist/modules/Discount/types.d.ts +5 -36
  11. package/dist/modules/Order/index.d.ts +13 -8
  12. package/dist/modules/Order/index.js +307 -432
  13. package/dist/modules/Order/types.d.ts +5 -0
  14. package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
  15. package/dist/modules/Order/utils.d.ts +11 -1
  16. package/dist/modules/Order/utils.js +127 -122
  17. package/dist/modules/Payment/types.d.ts +1 -21
  18. package/dist/modules/Payment/types.js +0 -2
  19. package/dist/modules/Payment/walletpass.d.ts +1 -1
  20. package/dist/modules/Payment/walletpass.js +47 -80
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +186 -480
  23. package/dist/modules/Rules/types.d.ts +0 -4
  24. package/dist/server/modules/order/types.d.ts +0 -2
  25. package/dist/solution/BaseSales/index.d.ts +0 -1
  26. package/dist/solution/BaseSales/index.js +59 -51
  27. package/dist/solution/BaseSales/types.d.ts +2 -2
  28. package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
  29. package/dist/solution/BookingByStep/index.d.ts +1 -1
  30. package/dist/solution/BookingTicket/index.d.ts +2 -1
  31. package/dist/solution/BookingTicket/index.js +63 -60
  32. package/dist/solution/BookingTicket/types.d.ts +1 -5
  33. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  34. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
  35. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  36. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  37. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
  38. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  39. package/dist/solution/ShopDiscount/index.js +42 -99
  40. package/dist/solution/ShopDiscount/utils.d.ts +2 -4
  41. package/dist/solution/ShopDiscount/utils.js +23 -43
  42. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  43. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  44. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  45. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  46. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
  47. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
  48. package/lib/modules/Customer/index.js +1 -5
  49. package/lib/modules/Customer/types.d.ts +0 -2
  50. package/lib/modules/Discount/index.d.ts +2 -2
  51. package/lib/modules/Discount/index.js +129 -23
  52. package/lib/modules/Discount/types.d.ts +5 -36
  53. package/lib/modules/Order/index.d.ts +13 -8
  54. package/lib/modules/Order/index.js +107 -215
  55. package/lib/modules/Order/types.d.ts +5 -0
  56. package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
  57. package/lib/modules/Order/utils.d.ts +11 -1
  58. package/lib/modules/Order/utils.js +45 -39
  59. package/lib/modules/Payment/types.d.ts +1 -21
  60. package/lib/modules/Payment/types.js +0 -1
  61. package/lib/modules/Payment/walletpass.d.ts +1 -1
  62. package/lib/modules/Payment/walletpass.js +9 -29
  63. package/lib/modules/Rules/index.d.ts +2 -2
  64. package/lib/modules/Rules/index.js +110 -357
  65. package/lib/modules/Rules/types.d.ts +0 -4
  66. package/lib/server/modules/order/types.d.ts +0 -2
  67. package/lib/solution/BaseSales/index.d.ts +0 -1
  68. package/lib/solution/BaseSales/index.js +12 -5
  69. package/lib/solution/BaseSales/types.d.ts +2 -2
  70. package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
  71. package/lib/solution/BookingByStep/index.d.ts +1 -1
  72. package/lib/solution/BookingTicket/index.d.ts +2 -1
  73. package/lib/solution/BookingTicket/index.js +33 -36
  74. package/lib/solution/BookingTicket/types.d.ts +1 -5
  75. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  76. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
  77. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  78. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  79. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
  80. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  81. package/lib/solution/ShopDiscount/index.js +9 -55
  82. package/lib/solution/ShopDiscount/utils.d.ts +2 -4
  83. package/lib/solution/ShopDiscount/utils.js +25 -42
  84. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  85. package/package.json +1 -1
  86. package/dist/modules/Discount/availability.d.ts +0 -7
  87. package/dist/modules/Discount/availability.js +0 -49
  88. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  89. package/dist/modules/Discount/entitlementPass.js +0 -147
  90. package/lib/modules/Discount/availability.d.ts +0 -7
  91. package/lib/modules/Discount/availability.js +0 -43
  92. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  93. package/lib/modules/Discount/entitlementPass.js +0 -141
@@ -9,7 +9,6 @@ var _types = require("./types");
9
9
  var _utils = require("./utils");
10
10
  var _utils2 = require("../Product/utils");
11
11
  var _dayjs = _interopRequireDefault(require("dayjs"));
12
- var _availability = require("../Discount/availability");
13
12
  var _osPrivatePayload = require("../../utils/os-private-payload");
14
13
  var _salesNotes = require("./salesNotes");
15
14
  var _paymentUtils = require("./payment-utils");
@@ -23,7 +22,6 @@ var _discountProductLineIdentity = require("./utils/discountProductLineIdentity"
23
22
  var _virtualSettlement = require("./utils/virtualSettlement");
24
23
  var _Discount = require("../Discount");
25
24
  var _Rules = require("../Rules");
26
- var _entitlementPass = require("../Discount/entitlementPass");
27
25
  var _types2 = require("../Rules/types");
28
26
  var _decimal = _interopRequireDefault(require("decimal.js"));
29
27
  var _lodashEs = require("lodash-es");
@@ -43,27 +41,9 @@ function isSameDiscountList(left, right) {
43
41
  function isManualProductDiscountProduct(product) {
44
42
  return (0, _manualProductDiscount.hasManualProductDiscountFlag)(product?.metadata) || (product?.discount_list || []).some(item => item?.type === 'product');
45
43
  }
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
44
  const ORDER_PAYMENT_STATUS_PAID = 'paid';
65
45
  const ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
66
- const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['entitlement_pass', 'good_pass', 'product_discount_card', 'discount_card']);
46
+ const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
67
47
  function isCustomerPromotionDiscount(discount) {
68
48
  return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String(discount?.tag || discount?.type || '').toLowerCase());
69
49
  }
@@ -93,28 +73,6 @@ function getVoucherPaymentLifecycleKey(payment) {
93
73
  if (!isVoucherPaymentRecord(payment)) return null;
94
74
  return `${String(payment.voucher_id)}::${String(payment.status || '')}`;
95
75
  }
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
76
  class OrderModule extends _BaseModule.BaseModule {
119
77
  defaultName = 'order';
120
78
  defaultVersion = '1.0.0';
@@ -130,6 +88,8 @@ class OrderModule extends _BaseModule.BaseModule {
130
88
  sessionStorageRestoreRecord = null;
131
89
  /** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
132
90
  customerWalletPrepareConfigEpoch = 0;
91
+ /** Payment 可能早于 prepare/config 返回;先按实例 ID 暂存卡号等待 Snapshot。 */
92
+ pointCardSnapshotCodeCandidates = new Map();
133
93
  salesSummaryModuleName;
134
94
  rulesHooksOverride;
135
95
  moduleHooksOverride;
@@ -168,7 +128,6 @@ class OrderModule extends _BaseModule.BaseModule {
168
128
  const key = Number.isFinite(id) ? id : String(resourceId);
169
129
  const title = item?.discount?.title ?? {};
170
130
  const amount = Number(item?.amount || 0);
171
- const encoded = item?.metadata?.encoded || item?.encoded || item?.discount?.encoded || '';
172
131
  const discountCardType = item?.discount?.discount_card_type;
173
132
  const parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? item?.discount?.fixed_amount ?? item?.amount : item?.discount?.percent : '0';
174
133
  const detail = {
@@ -179,21 +138,11 @@ class OrderModule extends _BaseModule.BaseModule {
179
138
  original_amount: String(item?.discount?.original_amount ?? item?.amount ?? '0'),
180
139
  num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1,
181
140
  metadata: item?.metadata,
182
- discount: {
183
- ...(item?.discount || {}),
184
- product_id: item?.discount?.product_id ?? product?.product_id
185
- },
141
+ discount: item?.discount,
186
142
  _num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1
187
143
  };
188
144
  const existed = discountMap.get(key);
189
145
  if (existed) {
190
- if (!existed.encoded && encoded) {
191
- existed.encoded = encoded;
192
- existed.metadata = {
193
- ...existed.metadata,
194
- encoded
195
- };
196
- }
197
146
  existed.amount = Number(existed.amount || 0) + amount;
198
147
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
199
148
  if (!isDiscountCard) {
@@ -213,11 +162,8 @@ class OrderModule extends _BaseModule.BaseModule {
213
162
  discountMap.set(key, {
214
163
  id: key,
215
164
  product_name: '',
216
- encoded,
217
- code: item?.code || item?.discount?.code || '',
218
- metadata: {
219
- encoded
220
- },
165
+ encoded: '',
166
+ code: '',
221
167
  tag: type,
222
168
  product_id: item?.discount?.discount_product_id ?? product?.product_id ?? 0,
223
169
  relation_type: '',
@@ -508,7 +454,7 @@ class OrderModule extends _BaseModule.BaseModule {
508
454
  this.store.rules = rules;
509
455
  }
510
456
  createDefaultRulesHooks() {
511
- return (0, _utils.createDefaultOrderRulesHooks)(() => this.store.tempOrder?.bookings || []);
457
+ return (0, _utils.createDefaultOrderRulesHooks)();
512
458
  }
513
459
 
514
460
  /**
@@ -534,8 +480,6 @@ class OrderModule extends _BaseModule.BaseModule {
534
480
  with_wallet_pass_holder: 1,
535
481
  with_available_wallet_flag: 1,
536
482
  with_available_wallet_pass_flag: 1,
537
- with_entitlement_pass: 1,
538
- filter_order_wallet_pass_usage: 0,
539
483
  with_virtual_currency: 1,
540
484
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
541
485
  ...(orderId ? {
@@ -557,61 +501,17 @@ class OrderModule extends _BaseModule.BaseModule {
557
501
  }
558
502
  if (discountList) {
559
503
  const currentDiscountList = this.store.discount?.getDiscountList() || [];
560
- const currentCommittedDiscounts = currentDiscountList.filter(discount => discount?.isEditMode || discount?.committedAppliedProductDetails?.length);
504
+ const currentEditDiscounts = currentDiscountList.filter(discount => discount?.isEditMode);
561
505
  const currentScanDiscounts = currentDiscountList.filter(discount => discount?.isScan);
562
- const currentScanDiscountById = new Map(currentScanDiscounts.flatMap(discount => {
563
- const id = getDiscountIdentityKey(discount);
564
- return id === null ? [] : [[id, discount]];
565
- }));
566
- const committedDiscountById = new Map(currentCommittedDiscounts.flatMap(discount => {
567
- const id = getDiscountIdentityKey(discount);
568
- return id === null ? [] : [[id, discount]];
569
- }));
570
- const mergedCommittedDiscountIds = new Set();
571
- const refreshedScanDiscountIds = new Set();
506
+ const currentScanDiscountIds = new Set(currentScanDiscounts.map(discount => discount?.id));
572
507
  const runtimeDiscountIds = new Set();
573
- const runtimeDiscounts = discountList.flatMap(discount => {
574
- const id = getDiscountIdentityKey(discount);
575
- if (id === null) return [discount];
576
- if (runtimeDiscountIds.has(id)) return [];
577
- runtimeDiscountIds.add(id);
578
- const currentScanDiscount = currentScanDiscountById.get(id);
579
- if (currentScanDiscount && (!(0, _entitlementPass.isEntitlementPass)(currentScanDiscount) || !(0, _entitlementPass.isEntitlementPass)(discount))) {
580
- return [];
581
- }
582
- const committedDiscount = committedDiscountById.get(id);
583
- let nextDiscount = discount;
584
- if (committedDiscount && (0, _entitlementPass.isEntitlementPass)(committedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
585
- mergedCommittedDiscountIds.add(id);
586
- nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
587
- }
588
- if (currentScanDiscount) {
589
- refreshedScanDiscountIds.add(id);
590
- nextDiscount = {
591
- ...nextDiscount,
592
- isScan: true,
593
- isSelected: currentScanDiscount.isSelected ?? nextDiscount.isSelected,
594
- isManualSelect: currentScanDiscount.isManualSelect ?? nextDiscount.isManualSelect
595
- };
596
- }
597
- return [nextDiscount];
598
- });
599
- const retainedCommittedDiscounts = currentCommittedDiscounts.filter(discount => {
600
- const id = getDiscountIdentityKey(discount);
601
- return id === null || !mergedCommittedDiscountIds.has(id);
602
- }).map(discount => discount.committedAppliedProductDetails?.length ? {
603
- ...discount,
604
- isEditMode: true,
605
- isDisabled: true,
606
- isSelected: true,
607
- isUsed: true,
608
- appliedProductDetails: [...discount.committedAppliedProductDetails]
609
- } : discount);
610
- const retainedScanDiscounts = currentScanDiscounts.filter(discount => {
611
- const id = getDiscountIdentityKey(discount);
612
- return id === null || !refreshedScanDiscountIds.has(id);
508
+ const runtimeDiscounts = discountList.filter(discount => {
509
+ if (currentScanDiscountIds.has(discount?.id)) return false;
510
+ if (runtimeDiscountIds.has(discount?.id)) return false;
511
+ runtimeDiscountIds.add(discount?.id);
512
+ return true;
613
513
  });
614
- const mergedDiscountList = [...retainedCommittedDiscounts, ...retainedScanDiscounts, ...runtimeDiscounts];
514
+ const mergedDiscountList = [...currentEditDiscounts, ...currentScanDiscounts, ...runtimeDiscounts];
615
515
  if (!isCurrentRequest()) return this.getDiscountList();
616
516
  await this.store.discount?.setOriginalDiscountList(mergedDiscountList);
617
517
  if (!isCurrentRequest()) return this.getDiscountList();
@@ -732,34 +632,19 @@ class OrderModule extends _BaseModule.BaseModule {
732
632
  isAvailable: false,
733
633
  discountList: this.getDiscountList()
734
634
  };
735
- const scannedIds = new Set(withScanList.map(discount => String(discount.id)));
736
- const evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !(0, _availability.getDiscountLifecycleReason)(discount));
737
- const shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
635
+ const shouldRetainForLater = !isAvailable && unavailableReason === _types2.UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
738
636
  const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
637
+ const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
739
638
  let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
740
639
  if (isAvailable && normalizedNewDiscountList) {
741
640
  await this.store.discount?.setDiscountList(normalizedNewDiscountList);
742
- // 实际写回商品时沿用扫码试算的优先级,避免旧商品行的选卡覆盖本次扫码。
743
- this.applyDiscount({
744
- preferredEntitlementPassIds: withScanList.filter(discount => (0, _entitlementPass.isEntitlementPass)(discount)).map(discount => discount.id)
745
- });
641
+ this.applyDiscount();
746
642
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
747
643
  resolvedDiscountList = this.getDiscountList();
748
- } else if (shouldRetainForLater) {
749
- // 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
750
- const retainedDiscounts = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
751
- evaluatedScannedDiscounts.forEach(discount => {
752
- retainedDiscounts.set(String(discount.id), {
753
- ...discount,
754
- isScan: true,
755
- isAvailable: false,
756
- isSelected: false,
757
- reasonCode: discount.reasonCode || 'product_not_applicable',
758
- appliedProductDetails: [],
759
- savedAmount: 0
760
- });
761
- });
762
- await this.store.discount?.setDiscountList([...retainedDiscounts.values()]);
644
+ } else if (shouldRetainForLater && retainedDiscountList) {
645
+ // 卡券有效但当前购物车没有适用商品:先保留在 Promotion 中,
646
+ // 不执行 applyDiscount,避免修改商品价格或订单金额。
647
+ await this.store.discount?.setDiscountList(retainedDiscountList);
763
648
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
764
649
  resolvedDiscountList = this.getDiscountList();
765
650
  }
@@ -768,7 +653,7 @@ class OrderModule extends _BaseModule.BaseModule {
768
653
  isAvailable: isAvailable || false,
769
654
  isAccepted: Boolean(isAvailable || shouldRetainForLater),
770
655
  discountList: resolvedDiscountList,
771
- scannedDiscountList: evaluatedScannedDiscounts,
656
+ scannedDiscountList: resultDiscountList,
772
657
  unavailableReason
773
658
  };
774
659
  }
@@ -800,8 +685,7 @@ class OrderModule extends _BaseModule.BaseModule {
800
685
  isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
801
686
  orderTotalAmount: Number(this.store.summary?.total_amount || 0)
802
687
  }, {
803
- reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
804
- preferredEntitlementPassIds: options?.preferredEntitlementPassIds
688
+ reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids
805
689
  });
806
690
  if (result?.productList) {
807
691
  const previousProductsByUid = (0, _utils.indexOrderProductsByUid)(tempOrder.products);
@@ -1159,17 +1043,55 @@ class OrderModule extends _BaseModule.BaseModule {
1159
1043
  }
1160
1044
  clearCustomerWalletRuntimeState() {
1161
1045
  this.customerWalletPrepareConfigEpoch += 1;
1046
+ this.pointCardSnapshotCodeCandidates.clear();
1162
1047
  this.store.availableWalletIds = [];
1163
1048
  this.store.virtualCurrencyList = [];
1164
1049
  }
1050
+ rememberPointCardSnapshotCodeCandidates(value) {
1051
+ (0, _utils.collectPointCardSnapshotCodeCandidates)(value).forEach(({
1052
+ id,
1053
+ code
1054
+ }) => {
1055
+ if (!this.pointCardSnapshotCodeCandidates.has(id)) {
1056
+ this.pointCardSnapshotCodeCandidates.set(id, code);
1057
+ }
1058
+ });
1059
+ }
1060
+ getRememberedPointCardSnapshotCodeCandidates() {
1061
+ return [...this.pointCardSnapshotCodeCandidates].map(([id, code]) => ({
1062
+ id,
1063
+ code
1064
+ }));
1065
+ }
1066
+ getPointCardSnapshotOrderIdentityKey(identity) {
1067
+ if (identity?.externalSaleNumber) {
1068
+ return `external:${identity.externalSaleNumber}`;
1069
+ }
1070
+ if (identity?.orderId !== undefined && identity.orderId !== null) {
1071
+ return `order:${identity.orderId}`;
1072
+ }
1073
+ if (identity?.localId) return `local:${identity.localId}`;
1074
+ if (identity?.orderNumber) return `number:${identity.orderNumber}`;
1075
+ return '';
1076
+ }
1077
+ isPointCardSnapshotMergeContextCurrent(context) {
1078
+ if (!context) return true;
1079
+ if (context.customerId !== undefined && String(context.customerId ?? '') !== String(this.store.tempOrder?.customer_id ?? '')) {
1080
+ return false;
1081
+ }
1082
+ const expectedOrderKey = this.getPointCardSnapshotOrderIdentityKey(context.orderIdentity);
1083
+ return !expectedOrderKey || expectedOrderKey === this.getPointCardSnapshotOrderIdentityKey(this.getOrderIdentity());
1084
+ }
1165
1085
  writeCustomerWalletSnapshotsFromPrepareConfig(params) {
1166
1086
  const tempOrder = this.store.tempOrder;
1167
1087
  if (!tempOrder) return;
1168
1088
  if (String(tempOrder.customer_id ?? '') !== String(params.customerId)) return;
1089
+ const currentOrderMetaList = (0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list);
1169
1090
  const virtualCurrencyList = Array.isArray(params.virtualCurrencyList) ? params.virtualCurrencyList : [];
1091
+ const snapshotsWithExistingCodes = (0, _utils.mergePointCardSnapshotCodes)(params.availableWalletPassList, currentOrderMetaList?.point_cards_snapshot);
1170
1092
  tempOrder.order_meta_list = {
1171
- ...((0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list) || {}),
1172
- point_cards_snapshot: (0, _utils.buildPointCardSnapshotFromWalletPassList)(params.availableWalletPassList),
1093
+ ...(currentOrderMetaList || {}),
1094
+ point_cards_snapshot: (0, _utils.mergePointCardSnapshotCodes)(snapshotsWithExistingCodes, this.getRememberedPointCardSnapshotCodeCandidates()),
1173
1095
  virtual_currency_snapshot: (0, _utils.buildVirtualCurrencySnapshotFromList)(virtualCurrencyList)
1174
1096
  };
1175
1097
  this.store.availableWalletIds = [...params.availableWalletIds];
@@ -1177,6 +1099,31 @@ class OrderModule extends _BaseModule.BaseModule {
1177
1099
  this.persistTempOrder();
1178
1100
  this.saveDraftInBackground();
1179
1101
  }
1102
+
1103
+ /**
1104
+ * 将 Payment WalletPass 返回的实例 code 回填到当前订单 Snapshot。
1105
+ * 这里只按资产 ID 补空值,不新增卡、不覆盖 prepare/config 冻结的余额。
1106
+ */
1107
+ mergePointCardSnapshotCodes(walletPassList, context) {
1108
+ const tempOrder = this.store.tempOrder;
1109
+ const currentOrderMetaList = (0, _utils.normalizeOrderMetaList)(tempOrder?.order_meta_list);
1110
+ const currentSnapshots = currentOrderMetaList?.point_cards_snapshot || [];
1111
+ if (!tempOrder || !this.isPointCardSnapshotMergeContextCurrent(context)) {
1112
+ return currentSnapshots;
1113
+ }
1114
+ this.rememberPointCardSnapshotCodeCandidates(walletPassList);
1115
+ if (!currentSnapshots.length) return currentSnapshots;
1116
+ const nextSnapshots = (0, _utils.mergePointCardSnapshotCodes)(currentSnapshots, this.getRememberedPointCardSnapshotCodeCandidates());
1117
+ const hasChanged = nextSnapshots.some((snapshot, index) => snapshot.code !== currentSnapshots[index]?.code);
1118
+ if (!hasChanged) return currentSnapshots;
1119
+ tempOrder.order_meta_list = {
1120
+ ...(currentOrderMetaList || {}),
1121
+ point_cards_snapshot: nextSnapshots
1122
+ };
1123
+ this.persistTempOrder();
1124
+ this.saveDraftInBackground();
1125
+ return nextSnapshots;
1126
+ }
1180
1127
  createExternalSaleNumber() {
1181
1128
  const timestamp = (0, _dayjs.default)().format('YYYYMMDDHHmmssSSS');
1182
1129
  const random6 = String(Math.floor(Math.random() * 1000000)).padStart(6, '0');
@@ -1694,8 +1641,7 @@ class OrderModule extends _BaseModule.BaseModule {
1694
1641
  const sku = product?.product_sku || {};
1695
1642
  const metadata = product?.metadata || {};
1696
1643
  const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
1697
- const fullCoveragePassType = discountTypes.find(type => ['entitlement_pass', 'good_pass'].includes(type));
1698
- const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
1644
+ const extensionType = product?.extension_type || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
1699
1645
  return {
1700
1646
  product_id: product?.product_id ?? null,
1701
1647
  product_variant_id: product?.product_variant_id ?? null,
@@ -1748,8 +1694,7 @@ class OrderModule extends _BaseModule.BaseModule {
1748
1694
  const sku = product?.product_sku || {};
1749
1695
  const metadata = product?.metadata || {};
1750
1696
  const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
1751
- const fullCoveragePassType = discountTypes.find(type => ['entitlement_pass', 'good_pass'].includes(type));
1752
- const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
1697
+ const extensionType = product?.extension_type || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
1753
1698
  return {
1754
1699
  product_id: product?.product_id ?? null,
1755
1700
  product_variant_id: product?.product_variant_id ?? null,
@@ -2764,7 +2709,7 @@ class OrderModule extends _BaseModule.BaseModule {
2764
2709
  }
2765
2710
  isCustomerBoundDiscount(discount) {
2766
2711
  const type = discount?.type ?? discount?.tag;
2767
- return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
2712
+ return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
2768
2713
  }
2769
2714
  shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
2770
2715
  return Boolean(discount?.isScan || discount?.isEditMode);
@@ -3387,35 +3332,17 @@ class OrderModule extends _BaseModule.BaseModule {
3387
3332
  }
3388
3333
  normalizedIncoming.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedIncoming.discount_list);
3389
3334
  const hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
3390
- const hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
3391
- const isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
3392
- const isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
3393
3335
  const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
3394
3336
  const hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
3395
3337
  const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3396
3338
  const isIncomingCustomItem = productToAdd.metadata?.origin?.isCustomItem === true || productToAdd._origin?.isCustomItem === true;
3397
- const shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
3398
- const matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
3339
+ const shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
3340
+ const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
3399
3341
  if (this.hasGoodPassDiscount(item)) return false;
3400
- const isRuntimeEntitlementPass = this.isRuntimeEntitlementAppend(item, tempOrder);
3401
- if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
3402
- return false;
3403
- }
3404
- if (isIncomingEntitlementAppend && this.isPersistedProductLine(item)) {
3405
- return false;
3406
- }
3407
- const hasExistingProductNote = this.hasOrderProductLineNote(item);
3408
- if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
3409
- return false;
3410
- }
3411
- const hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
3412
- if (isRuntimeEntitlementPass && !this.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
3413
- return false;
3414
- }
3415
- if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
3416
- return false;
3417
- }
3418
- if (this.isPersistedProductLine(item)) return false;
3342
+ if (this.hasOrderProductLineNote(item)) return false;
3343
+ if (isManualProductDiscountProduct(item)) return false;
3344
+ if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3345
+ if (item.metadata?.is_edit_for_runtime) return false;
3419
3346
  if (item.product_id !== productToAdd.product_id) return false;
3420
3347
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
3421
3348
  const existedFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(item), item.product_bundle);
@@ -3716,51 +3643,17 @@ class OrderModule extends _BaseModule.BaseModule {
3716
3643
  });
3717
3644
  return tempOrder.products;
3718
3645
  }
3719
- getFullCoveragePassDiscounts(product) {
3720
- const discountList = [...(product.discount_list || [])];
3646
+ hasGoodPassDiscount(product) {
3647
+ const hasMainGoodPass = (product.discount_list || []).some(item => item?.type === 'good_pass' || item?.tag === 'good_pass');
3648
+ if (hasMainGoodPass) return true;
3649
+ const bundleDiscountList = [];
3721
3650
  (product.product_bundle || []).forEach(item => {
3722
- discountList.push(...(item?.discount_list || []));
3651
+ bundleDiscountList.push(...(item?.discount_list || []));
3723
3652
  });
3724
3653
  (product?._extend?.other?.bundle || []).forEach(item => {
3725
- discountList.push(...(item?.discount_list || []));
3654
+ bundleDiscountList.push(...(item?.discount_list || []));
3726
3655
  });
3727
- return discountList.filter(item => (0, _entitlementPass.isFullCoveragePass)(item));
3728
- }
3729
- hasEntitlementPassDiscount(product) {
3730
- return this.getFullCoveragePassDiscounts(product).some(item => (0, _entitlementPass.isEntitlementPass)(item));
3731
- }
3732
- hasGoodPassDiscount(product) {
3733
- return this.getFullCoveragePassDiscounts(product).some(item => !(0, _entitlementPass.isEntitlementPass)(item));
3734
- }
3735
- isPersistedProductLine(product) {
3736
- return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || product.metadata?.is_edit_for_runtime === true;
3737
- }
3738
- isRuntimeEntitlementAppend(product, tempOrder) {
3739
- if (this.isPersistedProductLine(product)) return false;
3740
- const uid = product.metadata?.unique_identification_number ?? product.unique_identification_number;
3741
- const storedOrigin = uid !== undefined && uid !== null && uid !== '' ? tempOrder._extend?.productsByUid?.[String(uid)]?.origin : undefined;
3742
- return Boolean(product?._origin?.__entitlementPassRuntimeAppend === true || storedOrigin?.__entitlementPassRuntimeAppend === true);
3743
- }
3744
- hasSameEntitlementMergePriceConfig(incoming, existing) {
3745
- const buildPriceConfig = product => {
3746
- const metadata = product.metadata || {};
3747
- const bundle = (product.product_bundle || []).map(item => ({
3748
- bundle_id: item.bundle_id ?? item.id ?? null,
3749
- bundle_product_id: item.bundle_product_id ?? item._bundle_product_id ?? item.product_id ?? null,
3750
- bundle_variant_id: item.bundle_variant_id ?? item.product_variant_id ?? 0,
3751
- price_type: item.price_type ?? item.custom_price_type ?? '',
3752
- price_type_ext: item.price_type_ext ?? item.custom_price_type_ext ?? ''
3753
- })).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
3754
- return JSON.stringify({
3755
- original_price: this.normalizeFingerprintMoney(product.original_price),
3756
- source_product_price: this.normalizeFingerprintMoney(metadata.source_product_price),
3757
- main_product_original_price: this.normalizeFingerprintMoney(metadata.main_product_original_price),
3758
- price_override: this.normalizeFingerprintMoney(metadata.price_override),
3759
- is_manual_discount: Boolean(metadata.is_manual_discount),
3760
- bundle
3761
- });
3762
- };
3763
- return buildPriceConfig(incoming) === buildPriceConfig(existing);
3656
+ return bundleDiscountList.some(item => item?.type === 'good_pass' || item?.tag === 'good_pass');
3764
3657
  }
3765
3658
  getBundleRuntimeIdentity(bundle) {
3766
3659
  if (!bundle || typeof bundle !== 'object') return '';
@@ -3949,7 +3842,7 @@ class OrderModule extends _BaseModule.BaseModule {
3949
3842
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
3950
3843
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
3951
3844
  let normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils.mergeOrderProductDisplayFields)(nextProduct, (0, _utils3.normalizeOrderProduct)(nextProduct)));
3952
- normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
3845
+ normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
3953
3846
  const preservedBookingUid = nextProduct.booking_uid || nextProduct.metadata?.booking_uid || targetProduct.booking_uid || targetProduct.metadata?.booking_uid;
3954
3847
  if (!booking && preservedBookingUid) {
3955
3848
  normalizedProduct.booking_uid = preservedBookingUid;
@@ -4066,7 +3959,6 @@ class OrderModule extends _BaseModule.BaseModule {
4066
3959
  throw new Error('[Order] 目标商品不存在,无法更新数量');
4067
3960
  }
4068
3961
  const targetProduct = tempOrder.products[productIndex];
4069
- const isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
4070
3962
  const normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils3.normalizeOrderProduct)({
4071
3963
  ...targetProduct,
4072
3964
  num: (0, _utils3.getSafeProductNum)(num),
@@ -4075,7 +3967,7 @@ class OrderModule extends _BaseModule.BaseModule {
4075
3967
  unique_identification_number: targetProduct.metadata?.unique_identification_number || unique_identification_number
4076
3968
  }
4077
3969
  }));
4078
- normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
3970
+ normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
4079
3971
  const settlementSnapshot = (0, _virtualSettlement.getSelectedSettlementSnapshot)(normalizedProduct);
4080
3972
  if (this.isMultiCurrencySettlementEnabled() && settlementSnapshot?.settlement_type === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
4081
3973
  const currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -204,6 +204,10 @@ export interface PointCardSnapshotItem {
204
204
  par_value: string;
205
205
  used_par_value: string;
206
206
  }
207
+ export interface PointCardSnapshotMergeContext {
208
+ customerId?: number | string | null;
209
+ orderIdentity?: OrderIdentitySnapshot | null;
210
+ }
207
211
  export interface VirtualCurrencySnapshotItem {
208
212
  id: number | string;
209
213
  tag: 'virtual_currency';
@@ -976,6 +980,7 @@ export interface OrderModuleAPI {
976
980
  getDiscountList: () => Discount[];
977
981
  getAvailableWalletIds: () => number[];
978
982
  getCustomerWalletPrepareConfigEpoch: () => number;
983
+ mergePointCardSnapshotCodes: (walletPassList: unknown, context?: PointCardSnapshotMergeContext) => PointCardSnapshotItem[];
979
984
  applyDiscount: () => void;
980
985
  /**
981
986
  * 注入促销评估器。
@@ -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 getFullCoveragePassIdentity(product) {
86
- const pass = (product.discount_list || []).find(item => (0, _entitlementPass.isFullCoveragePass)(item));
87
- if (!pass) return null;
88
- const resourceId = pass.discount?.resource_id ?? pass.resource_id ?? pass.discount_id ?? pass.id;
89
- if (isBlankOrderCollectionIdentity(resourceId)) return null;
90
- return {
91
- type: String(pass.type || pass.tag),
92
- resourceId: String(resourceId)
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 passIdentity = getFullCoveragePassIdentity(product);
98
- if (passIdentity) {
99
- const passType = passIdentity.type === 'good_pass' ? 'good-pass' : 'entitlement-pass';
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
  }
@@ -18,6 +18,16 @@ export interface OrderProductsDepositSummary {
18
18
  import type { WindowPlugin } from '../../plugins';
19
19
  export declare function normalizePointCardSnapshotItem(value: unknown): PointCardSnapshotItem | null;
20
20
  export declare function buildPointCardSnapshotFromWalletPassList(value: unknown): PointCardSnapshotItem[];
21
+ export declare function collectPointCardSnapshotCodeCandidates(value: unknown): Array<{
22
+ id: string;
23
+ code: string;
24
+ }>;
25
+ /**
26
+ * Payment 的 WalletPass 列表包含实例 code,而 prepare/config 通常只提供
27
+ * 卡名称和余额。按实例 ID 仅补齐 Snapshot 缺失的 code,避免后到的运行态
28
+ * 数据覆盖下单时已经冻结的卡名称和余额。
29
+ */
30
+ export declare function mergePointCardSnapshotCodes(snapshotsValue: unknown, walletPassesValue: unknown): PointCardSnapshotItem[];
21
31
  export declare function normalizeVirtualCurrencySnapshotItem(value: unknown): VirtualCurrencySnapshotItem | null;
22
32
  export declare function buildVirtualCurrencySnapshotFromList(value: unknown): VirtualCurrencySnapshotItem[];
23
33
  export declare function normalizeOrderMetaList(value: unknown): OrderMetaList | undefined;
@@ -161,7 +171,7 @@ export declare function resolveManualOverrideLineOriginalPrice(params: {
161
171
  * // => -4
162
172
  */
163
173
  export declare function resolveEffectivePerUnitDiscount(product: Record<string, any>): number;
164
- export declare function createDefaultOrderRulesHooks(getBookings?: () => OrderTempOrder['bookings']): RulesParamsHooks;
174
+ export declare function createDefaultOrderRulesHooks(): RulesParamsHooks;
165
175
  /**
166
176
  * 通过 session 类商品的开始时间结束时间生成商品的时长
167
177
  * @param {CartItem} cartItem