@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.
Files changed (103) 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 +2 -7
  12. package/dist/modules/Order/index.js +331 -480
  13. package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
  14. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  15. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  16. package/dist/modules/Order/utils.d.ts +1 -1
  17. package/dist/modules/Order/utils.js +65 -104
  18. package/dist/modules/Payment/types.d.ts +1 -21
  19. package/dist/modules/Payment/types.js +0 -2
  20. package/dist/modules/Payment/walletpass.d.ts +1 -1
  21. package/dist/modules/Payment/walletpass.js +47 -80
  22. package/dist/modules/Rules/index.d.ts +2 -2
  23. package/dist/modules/Rules/index.js +190 -482
  24. package/dist/modules/Rules/types.d.ts +2 -4
  25. package/dist/server/modules/order/types.d.ts +0 -2
  26. package/dist/server/utils/small-ticket.js +1 -1
  27. package/dist/solution/BaseSales/index.d.ts +2 -3
  28. package/dist/solution/BaseSales/index.js +77 -44
  29. package/dist/solution/BaseSales/types.d.ts +7 -3
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
  31. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  32. package/dist/solution/BaseSales/utils.js +3 -2
  33. package/dist/solution/BookingByStep/index.d.ts +1 -1
  34. package/dist/solution/BookingTicket/index.d.ts +3 -2
  35. package/dist/solution/BookingTicket/index.js +63 -60
  36. package/dist/solution/BookingTicket/types.d.ts +1 -5
  37. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  38. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
  39. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  40. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  41. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
  42. package/dist/solution/ScanOrder/utils.js +3 -2
  43. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  44. package/dist/solution/ShopDiscount/index.js +42 -99
  45. package/dist/solution/ShopDiscount/utils.d.ts +2 -4
  46. package/dist/solution/ShopDiscount/utils.js +23 -43
  47. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  48. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  49. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  50. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  51. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
  52. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
  53. package/lib/modules/Customer/index.js +1 -5
  54. package/lib/modules/Customer/types.d.ts +0 -2
  55. package/lib/modules/Discount/index.d.ts +2 -2
  56. package/lib/modules/Discount/index.js +129 -23
  57. package/lib/modules/Discount/types.d.ts +5 -36
  58. package/lib/modules/Order/index.d.ts +2 -7
  59. package/lib/modules/Order/index.js +109 -222
  60. package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
  61. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  62. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  63. package/lib/modules/Order/utils.d.ts +1 -1
  64. package/lib/modules/Order/utils.js +6 -41
  65. package/lib/modules/Payment/types.d.ts +1 -21
  66. package/lib/modules/Payment/types.js +0 -1
  67. package/lib/modules/Payment/walletpass.d.ts +1 -1
  68. package/lib/modules/Payment/walletpass.js +9 -29
  69. package/lib/modules/Rules/index.d.ts +2 -2
  70. package/lib/modules/Rules/index.js +114 -359
  71. package/lib/modules/Rules/types.d.ts +2 -4
  72. package/lib/server/modules/order/types.d.ts +0 -2
  73. package/lib/server/utils/small-ticket.js +1 -1
  74. package/lib/solution/BaseSales/index.d.ts +2 -3
  75. package/lib/solution/BaseSales/index.js +17 -11
  76. package/lib/solution/BaseSales/types.d.ts +7 -3
  77. package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
  78. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  79. package/lib/solution/BaseSales/utils.js +2 -1
  80. package/lib/solution/BookingByStep/index.d.ts +1 -1
  81. package/lib/solution/BookingTicket/index.d.ts +3 -2
  82. package/lib/solution/BookingTicket/index.js +33 -36
  83. package/lib/solution/BookingTicket/types.d.ts +1 -5
  84. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  85. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
  86. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  87. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  88. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
  89. package/lib/solution/ScanOrder/utils.js +2 -1
  90. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  91. package/lib/solution/ShopDiscount/index.js +9 -55
  92. package/lib/solution/ShopDiscount/utils.d.ts +2 -4
  93. package/lib/solution/ShopDiscount/utils.js +25 -42
  94. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  95. package/package.json +1 -1
  96. package/dist/modules/Discount/availability.d.ts +0 -7
  97. package/dist/modules/Discount/availability.js +0 -49
  98. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  99. package/dist/modules/Discount/entitlementPass.js +0 -147
  100. package/lib/modules/Discount/availability.d.ts +0 -7
  101. package/lib/modules/Discount/availability.js +0 -43
  102. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  103. package/lib/modules/Discount/entitlementPass.js +0 -141
@@ -2,10 +2,6 @@ var _excluded = ["_original_add_price"],
2
2
  _excluded2 = ["_original_price", "_original_add_price"];
3
3
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
4
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
5
  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; }
10
6
  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; }
11
7
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
@@ -36,15 +32,13 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
36
32
  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); }
37
33
  import { BaseModule } from "../BaseModule";
38
34
  import { UnavailableReason } from "./types";
39
- import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, getDiscountTimeUnavailableReason } from "../../solution/ShopDiscount/utils";
35
+ import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
40
36
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
41
37
  import Decimal from 'decimal.js';
42
- import { cloneDeep, isBoolean } from 'lodash-es';
38
+ import { isBoolean } from 'lodash-es';
43
39
  import dayjs from 'dayjs';
44
40
  import { isOrderLevelFixedAmountDiscount } from "../../solution/ShopDiscount/utils";
45
41
  import { calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
46
- import { compareEntitlementPassPriority, getRemainingEntitlementUses, isEntitlementPass, isFullCoveragePass, resolveEntitlementQuota } from "../Discount/entitlementPass";
47
- import { getDiscountUsageBlockReason, getDiscountUsageLimitFailKey } from "../Discount/availability";
48
42
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
49
43
  _inherits(RulesModule, _BaseModule);
50
44
  var _super = _createSuper(RulesModule);
@@ -130,23 +124,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
130
124
  }
131
125
 
132
126
  /**
133
- * 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
134
- * 只适用于同一 Holder Record,是否必填不影响匹配规则。
127
+ * 特定 form Holder 卡只授权给绑定同一 Holder Record 的商品行。
128
+ * required/isNeedHolder 仅控制是否强制选择 Holder,不参与优惠资格。
135
129
  */
136
130
  }, {
137
131
  key: "checkHolderMatch",
138
- value: function checkHolderMatch(discount, product, holderSource, holders) {
139
- var _discount$holder, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _holderSource$holder_, _holderSource$metadat, _holderSource$origin, _holderSource$metadat2, _holderSource$_origin, _holderSource$_extend, _holderSource$_extend2, _holderSource$_extend3;
132
+ value: function checkHolderMatch(discount, product, holders) {
133
+ var _discount$holder;
140
134
  // 非表单类型 holder 视为匹配
141
135
  if (((_discount$holder = discount.holder) === null || _discount$holder === void 0 ? void 0 : _discount$holder.holder_type) !== 'form') return true;
142
-
143
- // getProduct 会裁剪商品字段,从原始商品读取配置,套餐子项沿用父商品。
144
- var holderConfig = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_holderSource$holder_ = holderSource === null || holderSource === void 0 ? void 0 : holderSource.holder_config) !== null && _holderSource$holder_ !== void 0 ? _holderSource$holder_ : holderSource === null || holderSource === void 0 || (_holderSource$metadat = holderSource.metadata) === null || _holderSource$metadat === void 0 ? void 0 : _holderSource$metadat.holder_config) !== null && _ref6 !== void 0 ? _ref6 : holderSource === null || holderSource === void 0 || (_holderSource$origin = holderSource.origin) === null || _holderSource$origin === void 0 ? void 0 : _holderSource$origin.holder_config) !== null && _ref5 !== void 0 ? _ref5 : holderSource === null || holderSource === void 0 || (_holderSource$metadat2 = holderSource.metadata) === null || _holderSource$metadat2 === void 0 || (_holderSource$metadat2 = _holderSource$metadat2.origin) === null || _holderSource$metadat2 === void 0 ? void 0 : _holderSource$metadat2.holder_config) !== null && _ref4 !== void 0 ? _ref4 : holderSource === null || holderSource === void 0 || (_holderSource$_origin = holderSource._origin) === null || _holderSource$_origin === void 0 ? void 0 : _holderSource$_origin.holder_config) !== null && _ref3 !== void 0 ? _ref3 : holderSource === null || holderSource === void 0 || (_holderSource$_extend = holderSource._extend) === null || _holderSource$_extend === void 0 ? void 0 : _holderSource$_extend.holder_config) !== null && _ref2 !== void 0 ? _ref2 : holderSource === null || holderSource === void 0 || (_holderSource$_extend2 = holderSource._extend) === null || _holderSource$_extend2 === void 0 || (_holderSource$_extend2 = _holderSource$_extend2.product) === null || _holderSource$_extend2 === void 0 ? void 0 : _holderSource$_extend2.holder_config) !== null && _ref !== void 0 ? _ref : holderSource === null || holderSource === void 0 || (_holderSource$_extend3 = holderSource._extend) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.product) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.metadata) === null || _holderSource$_extend3 === void 0 ? void 0 : _holderSource$_extend3.holder_config;
145
- var holderStatus = holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.status;
146
- var holderEnabled = holderStatus === true || ['enable', '1'].includes(String(holderStatus).trim().toLowerCase());
147
- if (!holderEnabled || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === undefined || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === null || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === '') {
148
- return true;
149
- }
150
136
  var discountHolderIds = this.normalizeHolderRecordIds(discount.holder.holder_id);
151
137
  if (!discountHolderIds.length) return false;
152
138
  var productHolderIds = this.normalizeHolderRecordIds(product.holder_id);
@@ -161,14 +147,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
161
147
  // 判断discountList 是否可以对当前productList生效
162
148
  }, {
163
149
  key: "isDiscountListAvailable",
164
- value: function isDiscountListAvailable(_ref7) {
150
+ value: function isDiscountListAvailable(_ref) {
165
151
  var _this2 = this;
166
- var oldDiscountList = _ref7.oldDiscountList,
167
- newDiscountList = _ref7.newDiscountList,
168
- productList = _ref7.productList,
169
- orderTotalAmount = _ref7.orderTotalAmount,
170
- holders = _ref7.holders,
171
- isFormSubject = _ref7.isFormSubject;
152
+ var oldDiscountList = _ref.oldDiscountList,
153
+ newDiscountList = _ref.newDiscountList,
154
+ productList = _ref.productList,
155
+ orderTotalAmount = _ref.orderTotalAmount,
156
+ holders = _ref.holders,
157
+ isFormSubject = _ref.isFormSubject;
172
158
  // 首先检查是否有新的优惠券可应用
173
159
  if (!newDiscountList || newDiscountList.length === 0) {
174
160
  return {
@@ -191,17 +177,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
191
177
  unavailableReason: UnavailableReason.AlreadyUsed
192
178
  };
193
179
  }
194
- var scannedEntitlementPassIds = newDiscountList.filter(function (discount) {
195
- return isEntitlementPass(discount);
196
- }).map(function (discount) {
197
- return discount.id;
198
- });
199
- var scannedEntitlementPassIdSet = new Set(scannedEntitlementPassIds.map(String));
200
180
 
201
- // 客户次卡必须保留在完整列表中;同一实例以本次扫码数据更新。
202
- // 历史折扣不参与试算,商品券继续沿用仅保留扫码来源的规则。
181
+ // 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
182
+ // 保留之前扫码得到的商品券(isScan: true)
203
183
  var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
204
- return !discount.isEditMode && (!isFullCoveragePass(discount) || isEntitlementPass(discount) || discount.isScan) && !scannedEntitlementPassIdSet.has(String(discount.id));
184
+ return !discount.isEditMode && (discount.tag !== 'good_pass' || discount.isScan);
205
185
  });
206
186
  var mergedDiscountList = uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList)));
207
187
  var result = this.calcDiscount({
@@ -211,8 +191,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
211
191
  holders: holders,
212
192
  isFormSubject: isFormSubject
213
193
  }, {
214
- scan: true,
215
- preferredEntitlementPassIds: scannedEntitlementPassIds
194
+ scan: true
216
195
  });
217
196
 
218
197
  // 检查是否有产品使用了新折扣
@@ -367,15 +346,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
367
346
  }
368
347
  }, {
369
348
  key: "calcDiscount",
370
- value: function calcDiscount(_ref8, options) {
349
+ value: function calcDiscount(_ref2, options) {
371
350
  var _options$selectedList,
372
351
  _this4 = this;
373
- var discountList = _ref8.discountList,
374
- productList = _ref8.productList,
375
- holders = _ref8.holders,
376
- isFormSubject = _ref8.isFormSubject,
377
- orderTotalAmount = _ref8.orderTotalAmount;
378
- var preferredEntitlementPassIds = new Set(((options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds) || []).map(String));
352
+ var discountList = _ref2.discountList,
353
+ productList = _ref2.productList,
354
+ holders = _ref2.holders,
355
+ isFormSubject = _ref2.isFormSubject,
356
+ orderTotalAmount = _ref2.orderTotalAmount;
379
357
  var resolveIsFormSubject = function resolveIsFormSubject(product) {
380
358
  return typeof isFormSubject === 'function' ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
381
359
  };
@@ -387,7 +365,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
387
365
  }) && productList.find(function (n) {
388
366
  return !n.booking_id;
389
367
  });
390
- var reapplyBookingDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []).filter(function (uid) {
368
+ var reapplyWeighedDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids) || []).map(String));
369
+ var reapplyBookingDiscountProductUids = new Set([].concat(_toConsumableArray((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []), _toConsumableArray(reapplyWeighedDiscountProductUids)).filter(function (uid) {
391
370
  return uid !== undefined && uid !== null && uid !== '';
392
371
  }).map(String));
393
372
  var getOriginProductUid = function getOriginProductUid(originProduct) {
@@ -401,7 +380,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
401
380
  var uid = getOriginProductUid(originProduct);
402
381
  if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
403
382
  var discountType = selectedDiscount.tag || selectedDiscount.type;
404
- return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
383
+ return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
405
384
  };
406
385
  var resolveReapplyBookingDiscountPercent = function resolveReapplyBookingDiscountPercent(originProduct, selectedDiscount) {
407
386
  var _discount2;
@@ -419,12 +398,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
419
398
  if (discount.isEditMode) {
420
399
  editModeDiscount.push(discount);
421
400
  } else {
422
- // 试算不能把 config / 不可用原因写回原有选券;每次重新计算以清除旧原因。
423
- addModeDiscount.push(_objectSpread(_objectSpread({}, discount), {}, {
424
- usageLimitFailKey: getDiscountUsageLimitFailKey(discount),
425
- reason: undefined,
426
- reasonCode: getDiscountUsageBlockReason(discount)
427
- }));
401
+ addModeDiscount.push(discount);
428
402
  }
429
403
  });
430
404
 
@@ -455,7 +429,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
455
429
  }
456
430
  var canUseEditModeDiscountForReapply = function canUseEditModeDiscountForReapply(discount) {
457
431
  var discountType = discount.tag || discount.type;
458
- return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
432
+ return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
459
433
  };
460
434
 
461
435
  // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑。
@@ -487,7 +461,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
487
461
  // 2. 展开 bundle 子商品
488
462
  if (product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0) {
489
463
  product.bundle.forEach(function (bundleItem, bundleIndex) {
490
- var _ref9, _bundleItem$bundle_pr;
464
+ var _ref3, _bundleItem$bundle_pr;
491
465
  flattened.push({
492
466
  type: 'bundle',
493
467
  originProduct: originProduct,
@@ -499,7 +473,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
499
473
  // 新增商品运行态通常带 _bundle_product_id;订单 hydrate 后只有
500
474
  // bundle_product_id。Change time 必须兼容两种结构,否则 bundle
501
475
  // 子项无法命中折扣卡的 limited_relation_product_data.product_ids。
502
- id: (_ref9 = (_bundleItem$bundle_pr = bundleItem.bundle_product_id) !== null && _bundleItem$bundle_pr !== void 0 ? _bundleItem$bundle_pr : bundleItem._bundle_product_id) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.product_id,
476
+ id: (_ref3 = (_bundleItem$bundle_pr = bundleItem.bundle_product_id) !== null && _bundleItem$bundle_pr !== void 0 ? _bundleItem$bundle_pr : bundleItem._bundle_product_id) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_id,
503
477
  _id: "".concat(product._id, "_bundle_").concat(bundleIndex),
504
478
  parentId: product._id,
505
479
  num: bundleItem.num || 1,
@@ -537,9 +511,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
537
511
  var isGoodPass = function isGoodPass(discount) {
538
512
  return discount.tag === 'good_pass';
539
513
  };
540
- var isEntitlement = function isEntitlement(discount) {
541
- return isEntitlementPass(discount);
542
- };
543
514
 
544
515
  // 辅助函数:判断是否是订单级折扣卡
545
516
  var isOrderLevelDiscount = function isOrderLevelDiscount(discount) {
@@ -608,14 +579,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
608
579
  }
609
580
  return 0;
610
581
  }
611
- var entitlementA = isEntitlement(a);
612
- var entitlementB = isEntitlement(b);
613
- if (entitlementA || entitlementB) {
614
- if (entitlementA && entitlementB) {
615
- return compareEntitlementPassPriority(a, b);
616
- }
617
- return entitlementA ? -1 : 1;
618
- }
619
582
 
620
583
  // 1. 先按优先级排序
621
584
  var priorityA = getPriority(a);
@@ -659,10 +622,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
659
622
 
660
623
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
661
624
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
662
- var _ref10, _a$original_price, _ref11, _b$original_price;
625
+ var _ref4, _a$original_price, _ref5, _b$original_price;
663
626
  // 子商品优先使用 original_price,主商品使用 price
664
- var priceA = new Decimal(a.type === 'bundle' ? (_ref10 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref10 !== void 0 ? _ref10 : '0' : a.price || '0');
665
- var priceB = new Decimal(b.type === 'bundle' ? (_ref11 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref11 !== void 0 ? _ref11 : '0' : b.price || '0');
627
+ var priceA = new Decimal(a.type === 'bundle' ? (_ref4 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : a.price || '0');
628
+ var priceB = new Decimal(b.type === 'bundle' ? (_ref5 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref5 !== void 0 ? _ref5 : '0' : b.price || '0');
666
629
  if (priceA.equals(priceB)) {
667
630
  // 价格相同时,主商品优先
668
631
  if (a.type !== b.type) {
@@ -686,35 +649,20 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
686
649
 
687
650
  // 🔥 为每个折扣卡/商品券执行策略检查并附加config
688
651
  var evaluator = this.getWalletPassEvaluator();
689
- addModeDiscount.forEach(function (discount) {
690
- if (discount.reasonCode) discount.config = {
691
- isAvailable: false
692
- };
693
- });
694
652
  if (evaluator) {
695
653
  addModeDiscount.forEach(function (discount) {
696
- // 即使没有匹配的动态策略,服务端状态和次数限制也不能被覆盖为可用。
697
- if (discount.reasonCode) return;
698
654
  var discountType = discount.tag || discount.type;
699
- // 对两类全额抵扣卡和折扣卡执行附加策略检查。
700
- if (['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '')) {
701
- var _discount$unified_ava, _discount$limited_rel, _discount$limited_rel2;
702
- var entitlementQuota = isEntitlementPass(discount) ? resolveEntitlementQuota(discount) : null;
703
- if (isEntitlementPass(discount) && !entitlementQuota) {
704
- discount.config = {
705
- isAvailable: false
706
- };
707
- return;
708
- }
709
-
655
+ // 只对 good_pass 和 discount_card 类型执行策略检查
656
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
657
+ var _discount$limited_rel, _discount$limited_rel2;
710
658
  // 转换 discount 为 Voucher 格式
711
659
  var voucher = {
712
660
  id: discount.id,
713
661
  amount: Number(discount.par_value || 0),
714
- balance: (entitlementQuota === null || entitlementQuota === void 0 ? void 0 : entitlementQuota.type) === 'unlimited' ? Number.MAX_SAFE_INTEGER : (entitlementQuota === null || entitlementQuota === void 0 ? void 0 : entitlementQuota.type) === 'limited' ? entitlementQuota.balance : Number(discount.balance || 0),
662
+ balance: Number(discount.balance || 0),
715
663
  type: discountType,
716
664
  product_id: discount.product_id,
717
- unified_available_status: (_discount$unified_ava = discount.unified_available_status) !== null && _discount$unified_ava !== void 0 ? _discount$unified_ava : 1,
665
+ unified_available_status: 1,
718
666
  available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
719
667
  available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
720
668
  };
@@ -747,8 +695,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
747
695
  discount.config = {
748
696
  isAvailable: false
749
697
  };
750
- discount.reason = result.reason;
751
- discount.reasonCode = result.reasonCode || 'not_meet_the_required_conditions';
752
698
  }
753
699
  }
754
700
  });
@@ -771,162 +717,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
771
717
  });
772
718
  */
773
719
 
774
- // good_pass / 折扣卡保持原有的一次性使用标记。
720
+ // 标记已使用的优惠券
775
721
  var usedDiscounts = new Map();
776
722
 
777
- // Entitlement Pass 单独记录本次重算新增分配的次数。
778
- var entitlementUsageCounts = new Map();
779
-
780
723
  // 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
781
724
  var usedProductIdCounts = new Map();
782
- var markDiscountUsed = function markDiscountUsed(discount) {
783
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
784
- if (isEntitlementPass(discount)) {
785
- entitlementUsageCounts.set(discount.id, (entitlementUsageCounts.get(discount.id) || 0) + count);
786
- return;
787
- }
788
- usedDiscounts.set(discount.id, true);
789
- };
790
- var isDiscountUsed = function isDiscountUsed(discount) {
791
- if (isEntitlementPass(discount)) {
792
- return (entitlementUsageCounts.get(discount.id) || 0) > 0;
793
- }
794
- return usedDiscounts.get(discount.id) === true;
795
- };
796
- var buildFullCoveragePassUsageGroups = function buildFullCoveragePassUsageGroups(discounts, requestedCount) {
797
- var _firstGoodPass$config;
798
- var groups = [];
799
- var pendingUsedDiscounts = new Set(Array.from(usedDiscounts.entries()).filter(function (_ref12) {
800
- var _ref13 = _slicedToArray(_ref12, 2),
801
- used = _ref13[1];
802
- return used;
803
- }).map(function (_ref14) {
804
- var _ref15 = _slicedToArray(_ref14, 1),
805
- discountId = _ref15[0];
806
- return discountId;
807
- }));
808
- var pendingEntitlementCounts = new Map(entitlementUsageCounts);
809
- var pendingProductCounts = new Map(usedProductIdCounts);
810
- var firstGoodPass = discounts.find(function (discount) {
811
- return isFullCoveragePass(discount) && !isEntitlementPass(discount);
812
- });
813
- var legacyGoodPassPerLineLimit = firstGoodPass ? Number(((_firstGoodPass$config = firstGoodPass.config) === null || _firstGoodPass$config === void 0 ? void 0 : _firstGoodPass$config.maxUsagePerOrder) || 0) : 0;
814
- var allocatedGoodPassCount = 0;
815
- var remaining = Math.max(Math.floor(requestedCount), 0);
816
- var _iterator5 = _createForOfIteratorHelper(discounts),
817
- _step5;
818
- try {
819
- var _loop = function _loop() {
820
- var _discount$config;
821
- var discount = _step5.value;
822
- if (remaining <= 0) return 0; // break
823
- if (!isFullCoveragePass(discount)) return 1; // continue
824
- var currentEntitlementCount = pendingEntitlementCounts.get(discount.id) || 0;
825
- var availableCount = isEntitlementPass(discount) ? getRemainingEntitlementUses(discount, currentEntitlementCount, remaining) : pendingUsedDiscounts.has(discount.id) ? 0 : 1;
826
- if (!isEntitlementPass(discount) && legacyGoodPassPerLineLimit > 0) {
827
- availableCount = Math.min(availableCount, Math.max(Math.floor(legacyGoodPassPerLineLimit) - allocatedGoodPassCount, 0));
828
- }
829
- var maxUsagePerOrder = Number(((_discount$config = discount.config) === null || _discount$config === void 0 ? void 0 : _discount$config.maxUsagePerOrder) || 0);
830
- if (isEntitlementPass(discount) && maxUsagePerOrder > 0) {
831
- var currentProductCount = pendingProductCounts.get(discount.product_id) || 0;
832
- availableCount = Math.min(availableCount, Math.max(Math.floor(maxUsagePerOrder) - currentProductCount, 0));
833
- }
834
- var allocatedCount = Math.min(availableCount, remaining);
835
- if (allocatedCount <= 0) return 1; // continue
836
- var existingGroup = groups.find(function (group) {
837
- return String(group.discount.id) === String(discount.id);
838
- });
839
- if (existingGroup) {
840
- existingGroup.count += allocatedCount;
841
- } else {
842
- groups.push({
843
- discount: discount,
844
- count: allocatedCount
845
- });
846
- }
847
- if (isEntitlementPass(discount)) {
848
- pendingEntitlementCounts.set(discount.id, currentEntitlementCount + allocatedCount);
849
- } else {
850
- pendingUsedDiscounts.add(discount.id);
851
- allocatedGoodPassCount += allocatedCount;
852
- }
853
- pendingProductCounts.set(discount.product_id, (pendingProductCounts.get(discount.product_id) || 0) + allocatedCount);
854
- remaining -= allocatedCount;
855
- },
856
- _ret;
857
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
858
- _ret = _loop();
859
- if (_ret === 0) break;
860
- if (_ret === 1) continue;
861
- }
862
- } catch (err) {
863
- _iterator5.e(err);
864
- } finally {
865
- _iterator5.f();
866
- }
867
- return groups;
868
- };
869
- var mergeEntitlementAppliedProductDetails = function mergeEntitlementAppliedProductDetails(details) {
870
- var mergedDetails = [];
871
- var mergedIndexByKey = new Map();
872
- var toComparableNumber = function toComparableNumber(value) {
873
- var numberValue = Number(value);
874
- return Number.isFinite(numberValue) ? String(numberValue) : String(value !== null && value !== void 0 ? value : '');
875
- };
876
- var _iterator6 = _createForOfIteratorHelper(details || []),
877
- _step6;
878
- try {
879
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
880
- var _detail$discount$reso, _detail$discount, _detail$discount$prod, _detail$discount2, _detail$metadata$cust, _detail$metadata, _detail$discount3, _ref16, _detail$metadata$num, _detail$metadata2, _ref17, _existed$metadata$num, _existed$metadata;
881
- var detail = _step6.value;
882
- if (!isEntitlementPass(detail)) {
883
- mergedDetails.push(detail);
884
- continue;
885
- }
886
- var resourceId = (_detail$discount$reso = detail === null || detail === void 0 || (_detail$discount = detail.discount) === null || _detail$discount === void 0 ? void 0 : _detail$discount.resource_id) !== null && _detail$discount$reso !== void 0 ? _detail$discount$reso : detail === null || detail === void 0 ? void 0 : detail.resource_id;
887
- if (resourceId === undefined || resourceId === null) {
888
- mergedDetails.push(detail);
889
- continue;
890
- }
891
- var key = [resourceId, (_detail$discount$prod = detail === null || detail === void 0 || (_detail$discount2 = detail.discount) === null || _detail$discount2 === void 0 ? void 0 : _detail$discount2.product_id) !== null && _detail$discount$prod !== void 0 ? _detail$discount$prod : '', (_detail$metadata$cust = detail === null || detail === void 0 || (_detail$metadata = detail.metadata) === null || _detail$metadata === void 0 ? void 0 : _detail$metadata.custom_product_bundle_map_id) !== null && _detail$metadata$cust !== void 0 ? _detail$metadata$cust : '', toComparableNumber(detail === null || detail === void 0 ? void 0 : detail.amount), toComparableNumber(detail === null || detail === void 0 || (_detail$discount3 = detail.discount) === null || _detail$discount3 === void 0 ? void 0 : _detail$discount3.fixed_amount)].join('|');
892
- var rawUsageCount = Number((_ref16 = (_detail$metadata$num = detail === null || detail === void 0 || (_detail$metadata2 = detail.metadata) === null || _detail$metadata2 === void 0 ? void 0 : _detail$metadata2.num) !== null && _detail$metadata$num !== void 0 ? _detail$metadata$num : detail === null || detail === void 0 ? void 0 : detail._num) !== null && _ref16 !== void 0 ? _ref16 : 1);
893
- var usageCount = Number.isFinite(rawUsageCount) && rawUsageCount > 0 ? rawUsageCount : 1;
894
- var mergedIndex = mergedIndexByKey.get(key);
895
- if (mergedIndex === undefined) {
896
- mergedIndexByKey.set(key, mergedDetails.length);
897
- mergedDetails.push(_objectSpread(_objectSpread({}, detail), {}, {
898
- metadata: _objectSpread(_objectSpread({}, (detail === null || detail === void 0 ? void 0 : detail.metadata) || {}), {}, {
899
- num: usageCount
900
- }),
901
- _num: usageCount
902
- }));
903
- continue;
904
- }
905
- var existed = mergedDetails[mergedIndex];
906
- var existedUsageCount = Number((_ref17 = (_existed$metadata$num = existed === null || existed === void 0 || (_existed$metadata = existed.metadata) === null || _existed$metadata === void 0 ? void 0 : _existed$metadata.num) !== null && _existed$metadata$num !== void 0 ? _existed$metadata$num : existed === null || existed === void 0 ? void 0 : existed._num) !== null && _ref17 !== void 0 ? _ref17 : 1);
907
- var totalUsageCount = existedUsageCount + usageCount;
908
- mergedDetails[mergedIndex] = _objectSpread(_objectSpread({}, existed), {}, {
909
- metadata: _objectSpread(_objectSpread({}, (existed === null || existed === void 0 ? void 0 : existed.metadata) || {}), {}, {
910
- num: totalUsageCount
911
- }),
912
- _num: totalUsageCount
913
- });
914
- }
915
- } catch (err) {
916
- _iterator6.e(err);
917
- } finally {
918
- _iterator6.f();
919
- }
920
- return mergedDetails;
921
- };
922
725
 
923
726
  // 记录每个优惠券适用的商品ID
924
727
  var discountApplicability = new Map();
925
728
 
926
729
  // 记录每个优惠券适用的商品详细信息
927
730
  var discountApplicableProducts = new Map();
928
- var discountTimeReasons = new Map();
929
- var discountHolderMismatch = new Set();
930
731
 
931
732
  // 初始化每个优惠券的适用性和可抵扣商品
932
733
  addModeDiscount.forEach(function (discount) {
@@ -946,8 +747,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
946
747
 
947
748
  // 辅助函数:检查商品是否对某个折扣卡可用
948
749
  var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
949
- var _discount$config2, _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
950
- if (((_discount$config2 = discount.config) === null || _discount$config2 === void 0 ? void 0 : _discount$config2.isAvailable) === false) return false;
750
+ var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
951
751
  var product;
952
752
  if (flatItem.type === 'main') {
953
753
  product = flatItem.product;
@@ -970,7 +770,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
970
770
 
971
771
  // 编辑的商品使用了优惠券不可用
972
772
  var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
973
- return d.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
773
+ return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
974
774
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
975
775
  return d.id;
976
776
  }));
@@ -1070,7 +870,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1070
870
  // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
1071
871
  var applicableProducts = [];
1072
872
  sortedFlattenedList.forEach(function (flatItem) {
1073
- var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref18, _flatItem$original_pr;
873
+ var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref6, _flatItem$original_pr;
1074
874
  // 🔥 检查该商品是否被其他专属折扣卡占用
1075
875
  var occupyingDiscountId = occupiedItems.get(flatItem._id);
1076
876
  if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
@@ -1098,7 +898,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1098
898
 
1099
899
  // 对于主商品:使用 price
1100
900
  // 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
1101
- var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref18 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref18 !== void 0 ? _ref18 : 0);
901
+ var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref6 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref6 !== void 0 ? _ref6 : 0);
1102
902
 
1103
903
  // 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
1104
904
  var productData = {
@@ -1155,49 +955,42 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1155
955
  }
1156
956
  var isItemRewardProductDiscount = _this4.isItemRewardProductDiscount(product);
1157
957
  addModeDiscount.forEach(function (discount) {
1158
- var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config3;
958
+ var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
1159
959
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
1160
960
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
1161
961
  var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
1162
962
  var isHolderMatch = _this4.checkHolderMatch(discount, {
1163
963
  isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
1164
964
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
1165
- }, flatItem.originProduct, holders);
1166
- var timeReason = getDiscountTimeUnavailableReason(discount, (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss'));
1167
- var timeLimit = !timeReason;
965
+ }, holders);
966
+ var timeLimit = true;
967
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
1168
968
  // 是符合折扣的商品
1169
- var isProductInScope = limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id);
1170
- var isLimitedProduct = isProductInScope && isHolderMatch;
969
+ var isLimitedProduct = (limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
1171
970
 
1172
971
  // 编辑的商品 使用了优惠券不可用
1173
972
  var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
1174
- return discount.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
973
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
1175
974
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
1176
975
  return discount.id;
1177
976
  }));
1178
977
 
1179
978
  // 套餐是否可用判断
1180
979
  var isBundleAvailable = _this4.checkPackageSubItemUsageRules(discount, flatItem);
1181
- if (isProductInScope && isBundleAvailable && !isItemRewardProductDiscount) {
1182
- var timeReasons = discountTimeReasons.get(discount.id) || [];
1183
- timeReasons.push(timeReason);
1184
- discountTimeReasons.set(discount.id, timeReasons);
1185
- if (!isHolderMatch && timeLimit) discountHolderMismatch.add(discount.id);
1186
- }
1187
980
 
1188
981
  // 判断优惠券是否适用于该商品
1189
- if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config3 = discount.config) !== null && _discount$config3 !== void 0 && _discount$config3.isAvailable && (!isEntitlementPass(discount) || getRemainingEntitlementUses(discount, 0, 1) > 0)) {
1190
- var _discountApplicabilit, _discount$metadata4, _discount$metadata5, _discount$metadata6;
982
+ if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
983
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
1191
984
  // 记录此优惠券适用的商品
1192
985
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
1193
986
 
1194
987
  // 记录可抵扣的商品详情
1195
988
  var applicableProducts = discountApplicableProducts.get(discount.id) || [];
1196
989
  var discountType = discount.tag || discount.type;
1197
- var isFullCoverage = isFullCoveragePass(discount);
990
+ var isGoodPass = discountType === 'good_pass';
1198
991
 
1199
992
  // 使用数量
1200
- var num = isFullCoverage || (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'main' ? 1 : product.num;
993
+ var num = isGoodPass || (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'main' ? 1 : product.num;
1201
994
  var productData = {
1202
995
  amount: product.price * num,
1203
996
  type: discountType,
@@ -1214,7 +1007,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1214
1007
  discount_product_id: discount.product_id
1215
1008
  },
1216
1009
  metadata: {
1217
- encoded: ((_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.encoded) || discount.encoded,
1218
1010
  num: num,
1219
1011
  discount_rule_uncheck_flag: discount === null || discount === void 0 ? void 0 : discount.discount_rule_uncheck_flag
1220
1012
  }
@@ -1236,13 +1028,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1236
1028
  };
1237
1029
  var optionDiscountAmount = 0;
1238
1030
  var discountedOptions = options.map(function (option) {
1239
- var _ref19, _ref20, _option$_original_pri, _ref21, _option$num, _rest$price, _option$_original_pri2;
1031
+ var _ref7, _ref8, _option$_original_pri, _ref9, _option$num, _rest$price, _option$_original_pri2;
1240
1032
  // 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
1241
- var rawUnit = (_ref19 = (_ref20 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref20 !== void 0 ? _ref20 : option.price) !== null && _ref19 !== void 0 ? _ref19 : option.add_price;
1033
+ var rawUnit = (_ref7 = (_ref8 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref8 !== void 0 ? _ref8 : option.price) !== null && _ref7 !== void 0 ? _ref7 : option.add_price;
1242
1034
  var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
1243
1035
  if (baseUnitNum <= 0) return option;
1244
1036
  var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
1245
- var optQty = Number((_ref21 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref21 !== void 0 ? _ref21 : 1);
1037
+ var optQty = Number((_ref9 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref9 !== void 0 ? _ref9 : 1);
1246
1038
  optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
1247
1039
  var _original_add_price = option._original_add_price,
1248
1040
  rest = _objectWithoutProperties(option, _excluded);
@@ -1276,9 +1068,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1276
1068
  var getOptionTotal = function getOptionTotal(options) {
1277
1069
  if (!(options !== null && options !== void 0 && options.length)) return 0;
1278
1070
  return options.reduce(function (sum, opt) {
1279
- var _ref22, _opt$price, _ref23, _opt$num;
1280
- var unit = Number((_ref22 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref22 !== void 0 ? _ref22 : 0);
1281
- var n = Number((_ref23 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref23 !== void 0 ? _ref23 : 1);
1071
+ var _ref10, _opt$price, _ref11, _opt$num;
1072
+ var unit = Number((_ref10 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref10 !== void 0 ? _ref10 : 0);
1073
+ var n = Number((_ref11 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref11 !== void 0 ? _ref11 : 1);
1282
1074
  return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
1283
1075
  }, 0);
1284
1076
  };
@@ -1315,11 +1107,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1315
1107
  var _discount$id, _discount$discount4;
1316
1108
  var discountIdentity = (_discount$id = discount.id) !== null && _discount$id !== void 0 ? _discount$id : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.resource_id;
1317
1109
  var discountType = discount.tag || discount.type;
1318
- return Boolean(discountIdentity && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType));
1110
+ return Boolean(discountIdentity && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType));
1319
1111
  }));
1320
1112
 
1321
1113
  // 已持久化且已有钱包券/折扣卡的商品行跳过,保留后端历史折扣结果。
1322
- if (isPersistedProduct && hasExistingWalletDiscount) {
1114
+ var isReweighedProduct = reapplyWeighedDiscountProductUids.has(getOriginProductUid(originProduct) || '');
1115
+ if (isPersistedProduct && hasExistingWalletDiscount && !isReweighedProduct) {
1323
1116
  if (flatItem.type === 'main') {
1324
1117
  processedProductsMap.set(product._id, [originProduct]);
1325
1118
  }
@@ -1333,7 +1126,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1333
1126
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
1334
1127
  var _product$discount_lis3, _product$discount_lis4;
1335
1128
  if (_this4.isItemRewardProductDiscount(product)) return false;
1336
- // 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
1129
+ // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
1337
1130
  var discountType = discount.tag || discount.type;
1338
1131
  var currentOriginUid = getOriginProductUid(originProduct);
1339
1132
  var isReapplyEditModeDiscountForProduct = discount.isEditMode && reapplyBookingDiscountProductUids.size > 0 && currentOriginUid && reapplyBookingDiscountProductUids.has(String(currentOriginUid)) && discount.isSelected === true;
@@ -1342,36 +1135,31 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1342
1135
  if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
1343
1136
  if (!discount.isSelected) return false;
1344
1137
  }
1345
- if (['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && !isReapplyEditModeDiscountForProduct) {
1346
- var _discount$config4;
1138
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType) && !isReapplyEditModeDiscountForProduct) {
1139
+ var _discount$config2;
1347
1140
  // 如果策略检查后没有config,说明不可用
1348
- if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config4 = discount.config) !== null && _discount$config4 !== void 0 && _discount$config4.isAvailable)) {
1141
+ if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
1349
1142
  return false;
1350
1143
  }
1351
1144
  }
1352
1145
 
1353
1146
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
1354
- // 全额抵扣卡在主商品价格为 0 时不可用。
1355
- if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) && isFullCoveragePass(discount)) return false;
1147
+ // 商品券时主商品价格为0不可用
1148
+ if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) && (discount.tag || discount.type) === 'good_pass') return false;
1356
1149
 
1357
1150
  // 折扣卡商品价格为0时不可用
1358
1151
  if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
1359
1152
  var _n$discount;
1360
1153
  return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
1361
- })) && !isFullCoveragePass(discount)) return false;
1362
- // good_pass 保持一张实例只使用一次。
1363
- if ((discount.tag || discount.type) === 'good_pass' && usedDiscounts.get(discount.id)) {
1364
- return false;
1365
- }
1366
- // 有限次数卡按后端实时 balance 约束本次新增分配;无限卡不看余额。
1367
- if (isEntitlementPass(discount) && getRemainingEntitlementUses(discount, entitlementUsageCounts.get(discount.id) || 0, 1) <= 0) {
1368
- return false;
1369
- }
1154
+ })) && (discount.tag || discount.type) !== 'good_pass') return false;
1155
+ // 如果优惠券已被使用,则跳过
1156
+ var targetUsedDiscounts = usedDiscounts.get(discount.id);
1157
+ if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
1370
1158
 
1371
1159
  // 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
1372
- if (isFullCoveragePass(discount)) {
1373
- var _discount$config5;
1374
- var maxUsagePerOrder = (_discount$config5 = discount.config) === null || _discount$config5 === void 0 ? void 0 : _discount$config5.maxUsagePerOrder;
1160
+ if ((discount.tag || discount.type) === 'good_pass') {
1161
+ var _discount$config3;
1162
+ var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
1375
1163
  if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1376
1164
  var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
1377
1165
  if (currentUsedCount >= maxUsagePerOrder) {
@@ -1386,7 +1174,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1386
1174
  var isHolderMatch = _this4.checkHolderMatch(discount, {
1387
1175
  isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
1388
1176
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
1389
- }, flatItem.originProduct, holders);
1177
+ }, holders);
1390
1178
  // 如果 holder 不匹配,则不适用
1391
1179
  if (!isHolderMatch) return false;
1392
1180
  var timeLimit = true;
@@ -1415,50 +1203,41 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1415
1203
  return false;
1416
1204
  });
1417
1205
 
1418
- // 识别用户本次显式选择的卡券,供次卡和折扣卡各自的优先级使用。
1206
+ // 用户显式点击某张卡券时,本次选择优先于自动排序和扫码默认选择。
1419
1207
  // 目标仍必须在当前商品的 applicableDiscounts 中,因此不会绕过 Holder、时间或商品范围校验。
1420
1208
  var explicitlySelectedDiscount = (options === null || options === void 0 ? void 0 : options.isSelected) === true && options.discountId !== undefined ? applicableDiscounts.find(function (discount) {
1421
1209
  var discountType = discount.tag || discount.type;
1422
- return String(discount.id) === String(options.discountId) && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
1210
+ return String(discount.id) === String(options.discountId) && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
1423
1211
  }) : undefined;
1424
1212
  // 折扣卡会复用于整条商品行;商品券必须继续按单张拆分,不能复用该分支。
1425
- var explicitlySelectedDiscountCard = explicitlySelectedDiscount && !isFullCoveragePass(explicitlySelectedDiscount) ? explicitlySelectedDiscount : undefined;
1213
+ var explicitlySelectedDiscountCard = explicitlySelectedDiscount && (explicitlySelectedDiscount.tag || explicitlySelectedDiscount.type) !== 'good_pass' ? explicitlySelectedDiscount : undefined;
1426
1214
 
1427
- // 商品数量等变化会触发无 discountId 的重算。只要当前行已应用的卡仍在
1215
+ // 商品数量等变化会触发无 discountId 的重算。只要当前行已应用的折扣卡仍在
1428
1216
  // applicableDiscounts 中,就应保留该行选择,避免被自动排序中力度更大的卡替换。
1429
- var appliedWalletDiscountIds = new Set((product.discount_list || []).filter(function (item) {
1430
- return ['entitlement_pass', 'discount_card', 'product_discount_card'].includes((item === null || item === void 0 ? void 0 : item.tag) || (item === null || item === void 0 ? void 0 : item.type));
1217
+ var appliedDiscountCardIds = new Set((product.discount_list || []).filter(function (item) {
1218
+ return ['discount_card', 'product_discount_card'].includes((item === null || item === void 0 ? void 0 : item.tag) || (item === null || item === void 0 ? void 0 : item.type));
1431
1219
  }).map(function (item) {
1432
- var _ref24, _item$discount$resour, _item$discount;
1433
- return (_ref24 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref24 !== void 0 ? _ref24 : item === null || item === void 0 ? void 0 : item.id;
1220
+ var _ref12, _item$discount$resour, _item$discount;
1221
+ return (_ref12 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref12 !== void 0 ? _ref12 : item === null || item === void 0 ? void 0 : item.id;
1434
1222
  }).filter(function (id) {
1435
1223
  return id !== undefined && id !== null;
1436
1224
  }).map(String));
1437
1225
  var appliedDiscountCard = options !== null && options !== void 0 && options.scan ? undefined : applicableDiscounts.find(function (discount) {
1438
1226
  var discountType = discount.tag || discount.type;
1439
- return discount.isSelected === true && ['discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && appliedWalletDiscountIds.has(String(discount.id));
1440
- });
1441
- var appliedEntitlementPass = options !== null && options !== void 0 && options.scan || (options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) === false ? undefined : applicableDiscounts.find(function (discount) {
1442
- return isEntitlementPass(discount) && discount.isSelected === true && appliedWalletDiscountIds.has(String(discount.id));
1227
+ return discount.isSelected === true && ['discount_card', 'product_discount_card'].includes(discountType) && appliedDiscountCardIds.has(String(discount.id));
1443
1228
  });
1444
1229
 
1445
- // 次卡内部按本次手选/扫码、当前行已应用、默认排序选择。
1230
+ // 优先级:本次显式选择 > 当前行既有选择 > 扫码选择 > 自动排序第一项。
1446
1231
  var scannedSelectedDiscountCard = applicableDiscounts.find(function (n) {
1447
- return n.isScan && n.isSelected && !isFullCoveragePass(n);
1232
+ return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1448
1233
  });
1449
1234
  var selectedDiscountCard = explicitlySelectedDiscountCard || appliedDiscountCard || scannedSelectedDiscountCard;
1450
- var selectedEntitlementPass = (explicitlySelectedDiscount && isEntitlementPass(explicitlySelectedDiscount) ? explicitlySelectedDiscount : undefined) || applicableDiscounts.find(function (discount) {
1451
- return isEntitlementPass(discount) && preferredEntitlementPassIds.has(String(discount.id));
1452
- }) || appliedEntitlementPass || applicableDiscounts.find(function (discount) {
1453
- return isEntitlementPass(discount);
1454
- });
1455
- // 手选优先;普通重算保留当前折扣卡,扫码和最优选择仍使用原有优先级。
1456
- var selectedDiscount = explicitlySelectedDiscount || ((options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) !== false && preferredEntitlementPassIds.size === 0 ? appliedDiscountCard : undefined) || selectedEntitlementPass || selectedDiscountCard || applicableDiscounts[0];
1457
- // 实际次数分配必须使用同一顺序,避免选中状态切换后仍将次数分配给默认卡。
1458
- var prioritizedApplicableDiscounts = selectedDiscount && isFullCoveragePass(selectedDiscount) ? [selectedDiscount].concat(_toConsumableArray(applicableDiscounts.filter(function (discount) {
1459
- return isFullCoveragePass(discount) && String(discount.id) !== String(selectedDiscount.id);
1235
+ var selectedDiscount = explicitlySelectedDiscount || selectedDiscountCard || applicableDiscounts[0];
1236
+ var prioritizedApplicableDiscounts = explicitlySelectedDiscount && (explicitlySelectedDiscount.tag || explicitlySelectedDiscount.type) === 'good_pass' ? [explicitlySelectedDiscount].concat(_toConsumableArray(applicableDiscounts.filter(function (discount) {
1237
+ var discountType = discount.tag || discount.type;
1238
+ return discountType === 'good_pass' && String(discount.id) !== String(explicitlySelectedDiscount.id);
1460
1239
  })), _toConsumableArray(applicableDiscounts.filter(function (discount) {
1461
- return !isFullCoveragePass(discount);
1240
+ return (discount.tag || discount.type) !== 'good_pass';
1462
1241
  }))) : applicableDiscounts;
1463
1242
 
1464
1243
  // 如果是手动折扣,则不适用优惠券
@@ -1470,8 +1249,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1470
1249
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : ((_product$discount_lis5 = product.discount_list) === null || _product$discount_lis5 === void 0 ? void 0 : _product$discount_lis5.some(function (item) {
1471
1250
  return item.type === 'product';
1472
1251
  })) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
1473
- var _ref25;
1474
- return !((_ref25 = item.discount_list || []) !== null && _ref25 !== void 0 && _ref25.length);
1252
+ var _ref13;
1253
+ return !((_ref13 = item.discount_list || []) !== null && _ref13 !== void 0 && _ref13.length);
1475
1254
  }) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
1476
1255
  return item.type === 'product';
1477
1256
  })));
@@ -1487,8 +1266,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1487
1266
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : ((_parentProduct$discou = parentProduct.discount_list) === null || _parentProduct$discou === void 0 ? void 0 : _parentProduct$discou.some(function (item) {
1488
1267
  return item.type === 'product';
1489
1268
  })) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1490
- var _ref26;
1491
- return !((_ref26 = item.discount_list || []) !== null && _ref26 !== void 0 && _ref26.length);
1269
+ var _ref14;
1270
+ return !((_ref14 = item.discount_list || []) !== null && _ref14 !== void 0 && _ref14.length);
1492
1271
  }) && (!((_parentProduct$discou2 = parentProduct.discount_list) !== null && _parentProduct$discou2 !== void 0 && _parentProduct$discou2.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou3 = parentProduct.discount_list) === null || _parentProduct$discou3 === void 0 || (_parentProduct$discou4 = _parentProduct$discou3.every) === null || _parentProduct$discou4 === void 0 ? void 0 : _parentProduct$discou4.call(_parentProduct$discou3, function (item) {
1493
1272
  return item.type === 'product';
1494
1273
  })));
@@ -1581,8 +1360,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1581
1360
  discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(product.discount_list) : _this4.filterDiscountListByType(product.discount_list, 'promotion')
1582
1361
  }))]);
1583
1362
  } else {
1584
- var _ref27, _product$_promotion$f, _product12, _product$origin_total;
1585
- var total = product.inPromotion ? (_ref27 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref27 !== void 0 ? _ref27 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1363
+ var _ref15, _product$_promotion$f, _product12, _product$origin_total;
1364
+ var total = product.inPromotion ? (_ref15 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref15 !== void 0 ? _ref15 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1586
1365
  var main_product_selling_price = product.price;
1587
1366
  if ((product.discount_list || []).some(function (item) {
1588
1367
  return item.type === 'promotion';
@@ -1623,15 +1402,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1623
1402
  return;
1624
1403
  }
1625
1404
 
1626
- // good_pass 与 Entitlement Pass 都沿用全额抵扣卡的商品行拆分机制。
1627
- var isNeedSplit = isFullCoveragePass(selectedDiscount);
1405
+ // 是否需要拆分(商品券需要拆分)
1406
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
1628
1407
 
1629
1408
  // 需要拆分出来的数量
1630
1409
  var totalQuantity = product.quantity || product.num || 1;
1631
- var fullCoveragePassUsageGroups = isNeedSplit ? buildFullCoveragePassUsageGroups(prioritizedApplicableDiscounts, totalQuantity) : [];
1632
- var splitCount = isNeedSplit ? fullCoveragePassUsageGroups.reduce(function (total, group) {
1633
- return total + group.count;
1634
- }, 0) : 1;
1410
+ var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1411
+ return (item.tag || item.type) === 'good_pass';
1412
+ }).length;
1413
+
1414
+ // 🔥 如果selectedDiscount有config配置,则使用config.maxUsagePerOrder限制使用次数
1415
+ var maxUsageLimit = availableGoodPassCount;
1416
+ if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
1417
+ maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
1418
+ }
1419
+ var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
1635
1420
  var arr = [];
1636
1421
 
1637
1422
  // 🔥 主商品和bundle子商品分别处理
@@ -1640,8 +1425,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1640
1425
  if (splitCount < totalQuantity && isNeedSplit) {
1641
1426
  var _product$origin_total2, _product$main_product2;
1642
1427
  var remainingQuantity = totalQuantity - splitCount;
1643
- var applicableNonFullCoveragePassById = new Map(applicableDiscounts.filter(function (discount) {
1644
- return !isFullCoveragePass(discount);
1428
+ var applicableNonGoodPassById = new Map(applicableDiscounts.filter(function (discount) {
1429
+ return (discount.tag || discount.type) !== 'good_pass';
1645
1430
  }).map(function (discount) {
1646
1431
  return [String(discount.id), discount];
1647
1432
  }));
@@ -1649,19 +1434,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1649
1434
  var _discount$discount$re, _discount$discount5;
1650
1435
  var discountType = discount.tag || discount.type;
1651
1436
  if (discountType === 'promotion') return true;
1652
- if (isFullCoveragePass(discount)) return false;
1437
+ if (discountType === 'good_pass') return false;
1653
1438
  var resourceId = (_discount$discount$re = (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.resource_id) !== null && _discount$discount$re !== void 0 ? _discount$discount$re : discount.id;
1654
- return resourceId !== undefined && resourceId !== null && applicableNonFullCoveragePassById.has(String(resourceId));
1439
+ return resourceId !== undefined && resourceId !== null && applicableNonGoodPassById.has(String(resourceId));
1655
1440
  }).map(function (discount) {
1656
1441
  var _discount$discount$re2, _discount$discount6;
1657
1442
  if ((discount.tag || discount.type) === 'promotion') return discount;
1658
1443
  var resourceId = (_discount$discount$re2 = (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.resource_id) !== null && _discount$discount$re2 !== void 0 ? _discount$discount$re2 : discount.id;
1659
- var matchedDiscount = applicableNonFullCoveragePassById.get(String(resourceId));
1444
+ var matchedDiscount = applicableNonGoodPassById.get(String(resourceId));
1660
1445
  if (matchedDiscount) {
1661
1446
  // 实际场景:3 件折扣卡商品中拆出 1 件改用商品券后,
1662
1447
  // 剩余 2 件仍在使用原折扣卡;必须同步登记折扣卡的使用状态,
1663
1448
  // 否则 updatedDiscountList 会把它改成未选中并清空 savedAmount。
1664
- markDiscountUsed(matchedDiscount);
1449
+ usedDiscounts.set(matchedDiscount.id, true);
1665
1450
  var appliedProducts = appliedDiscountProducts.get(matchedDiscount.id) || [];
1666
1451
  appliedProducts.push(_objectSpread(_objectSpread({}, discount), {}, {
1667
1452
  _num: remainingQuantity
@@ -1674,7 +1459,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1674
1459
  });
1675
1460
  });
1676
1461
  var hasRetainedWalletDiscount = remainderDiscountList.some(function (discount) {
1677
- return (discount.tag || discount.type) !== 'promotion' && !isFullCoveragePass(discount);
1462
+ return !['promotion', 'good_pass'].includes(discount.tag || discount.type);
1678
1463
  });
1679
1464
  var _total = (_product$origin_total2 = product.origin_total) !== null && _product$origin_total2 !== void 0 ? _product$origin_total2 : product.total;
1680
1465
  if ((product.discount_list || []).some(function (item) {
@@ -1685,7 +1470,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1685
1470
  }
1686
1471
  arr.push(_this4.hooks.setProduct(originProduct, _objectSpread({
1687
1472
  // 商品券只替换被拆出的 splitCount 件。余量行原本仍有效的折扣卡
1688
- // 不能随全额抵扣卡拆分一起清除;已取消或已失效的折扣不会进入此列表。
1473
+ // 不能随 good_pass 拆分一起清除;已取消或已失效的折扣不会进入此列表。
1689
1474
  discount_list: remainderDiscountList,
1690
1475
  quantity: remainingQuantity,
1691
1476
  _id: product._id.split('___')[0],
@@ -1694,21 +1479,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1694
1479
  main_product_selling_price: (_product$main_product2 = product.main_product_selling_price) !== null && _product$main_product2 !== void 0 ? _product$main_product2 : product.price
1695
1480
  } : {})));
1696
1481
  }
1697
- var discountUsageGroups = isNeedSplit ? fullCoveragePassUsageGroups : [{
1698
- discount: selectedDiscount,
1699
- count: 1
1700
- }];
1701
- for (var i = 0; i < discountUsageGroups.length; i++) {
1702
- var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce, _selectedDiscount$met3;
1703
- var _discountUsageGroups$ = discountUsageGroups[i],
1704
- _selectedDiscount = _discountUsageGroups$.discount,
1705
- appliedUseCount = _discountUsageGroups$.count;
1482
+ for (var i = 0; i < splitCount; i++) {
1483
+ var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce;
1484
+ var _selectedDiscount = isNeedSplit ? prioritizedApplicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[i];
1706
1485
  // 标记优惠券为已使用
1707
- markDiscountUsed(_selectedDiscount, appliedUseCount);
1486
+ usedDiscounts.set(_selectedDiscount.id, true);
1708
1487
  // 🔥 更新 product_id 使用计数
1709
- if (isFullCoveragePass(_selectedDiscount)) {
1488
+ if ((_selectedDiscount.tag || _selectedDiscount.type) === 'good_pass') {
1710
1489
  var currentCount = usedProductIdCounts.get(_selectedDiscount.product_id) || 0;
1711
- usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + appliedUseCount);
1490
+ usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + 1);
1712
1491
  }
1713
1492
 
1714
1493
  // 记录实际应用了优惠券的商品信息
@@ -1770,7 +1549,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1770
1549
  var mainProductDiscountAmount = amount;
1771
1550
  var lineDiscountAmount = new Decimal(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
1772
1551
  var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1773
- var isFullCoverage = isFullCoveragePass(_selectedDiscount);
1552
+ var isGoodPass = discountType === 'good_pass';
1774
1553
  var discountDetail = {
1775
1554
  amount: lineDiscountAmount,
1776
1555
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
@@ -1786,11 +1565,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1786
1565
  discount_product_id: _selectedDiscount.product_id
1787
1566
  },
1788
1567
  // 前端使用的num数量,为了计算优惠金额
1789
- _num: isFullCoverage ? appliedUseCount : product.num,
1568
+ _num: isGoodPass ? 1 : product.num,
1790
1569
  config: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.config,
1791
1570
  metadata: _objectSpread(_objectSpread({
1792
- encoded: ((_selectedDiscount$met3 = _selectedDiscount.metadata) === null || _selectedDiscount$met3 === void 0 ? void 0 : _selectedDiscount$met3.encoded) || _selectedDiscount.encoded,
1793
- num: isFullCoverage ? appliedUseCount : 1,
1571
+ num: 1,
1794
1572
  discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
1795
1573
  }, productDiscountDifference !== undefined && {
1796
1574
  product_discount_difference: productDiscountDifference
@@ -1808,9 +1586,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1808
1586
  if (product.isClient) {
1809
1587
  arr.push(_this4.hooks.setProduct(originProduct, {
1810
1588
  discount_list: [discountDetail],
1811
- // 全额抵扣卡:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
1812
- price: isFullCoverage ? mainProductSellingPrice : product.price,
1813
- quantity: isNeedSplit ? appliedUseCount : product.quantity,
1589
+ // good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
1590
+ price: isGoodPass ? mainProductSellingPrice : product.price,
1591
+ quantity: isNeedSplit ? 1 : product.quantity,
1814
1592
  origin_total: getProductOriginTotalPrice({
1815
1593
  product: {
1816
1594
  original_price: product.original_price
@@ -1827,8 +1605,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1827
1605
  arr.push(_this4.hooks.setProduct(originProduct, {
1828
1606
  discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
1829
1607
  _id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
1830
- price: isFullCoverage ? 0 : product.price,
1831
- quantity: isNeedSplit ? appliedUseCount : product.quantity,
1608
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1609
+ quantity: isNeedSplit ? 1 : product.quantity,
1832
1610
  total: _total2,
1833
1611
  origin_total: productOriginTotal,
1834
1612
  main_product_selling_price: mainProductSellingPrice,
@@ -1845,17 +1623,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1845
1623
  var discountNum = splitCount;
1846
1624
  var normalNum = totalQuantity - discountNum;
1847
1625
 
1848
- // 同一卡实例的本次新增使用合并为一条,metadata.num 记录实际次数。
1849
- for (var _i = 0; _i < fullCoveragePassUsageGroups.length; _i++) {
1850
- var _selectedDiscount2$me, _selectedDiscount2$me2;
1851
- var _fullCoveragePassUsag = fullCoveragePassUsageGroups[_i],
1852
- _selectedDiscount2 = _fullCoveragePassUsag.discount,
1853
- _appliedUseCount = _fullCoveragePassUsag.count;
1854
- markDiscountUsed(_selectedDiscount2, _appliedUseCount);
1626
+ // 生成有折扣的商品(每张商品券对应 num: 1)
1627
+ for (var _i = 0; _i < discountNum; _i++) {
1628
+ var _selectedDiscount2$me;
1629
+ var _selectedDiscount2 = prioritizedApplicableDiscounts[_i];
1630
+ usedDiscounts.set(_selectedDiscount2.id, true);
1855
1631
  // 🔥 更新 product_id 使用计数
1856
- if (isFullCoveragePass(_selectedDiscount2)) {
1632
+ if ((_selectedDiscount2.tag || _selectedDiscount2.type) === 'good_pass') {
1857
1633
  var _currentCount = usedProductIdCounts.get(_selectedDiscount2.product_id) || 0;
1858
- usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + _appliedUseCount);
1634
+ usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + 1);
1859
1635
  }
1860
1636
 
1861
1637
  // 🔥 生成唯一的 _id
@@ -1863,12 +1639,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1863
1639
 
1864
1640
  // 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
1865
1641
  var discountedPrice = getDiscountAmount(_selectedDiscount2, product.origin_total, product.origin_total);
1866
- var bundleDiscountAmountPerItem = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1867
- var bundleDiscountAmount = new Decimal(bundleDiscountAmountPerItem).mul(_appliedUseCount).toNumber();
1642
+ var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1868
1643
  debugger;
1869
1644
  var _discountDetail = {
1870
1645
  amount: bundleDiscountAmount,
1871
- type: _selectedDiscount2.tag || _selectedDiscount2.type,
1646
+ type: 'good_pass',
1872
1647
  discount: {
1873
1648
  fixed_amount: product.origin_total,
1874
1649
  discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
@@ -1879,13 +1654,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1879
1654
  discount_product_id: _selectedDiscount2.product_id
1880
1655
  },
1881
1656
  metadata: {
1882
- encoded: ((_selectedDiscount2$me2 = _selectedDiscount2.metadata) === null || _selectedDiscount2$me2 === void 0 ? void 0 : _selectedDiscount2$me2.encoded) || _selectedDiscount2.encoded,
1883
1657
  // 🔥 使用拆分后的唯一 _id
1884
1658
  custom_product_bundle_map_id: uniqueId,
1885
1659
  discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
1886
- num: _appliedUseCount
1660
+ num: 1
1887
1661
  },
1888
- _num: _appliedUseCount,
1662
+ _num: 1,
1889
1663
  config: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.config
1890
1664
  };
1891
1665
 
@@ -1896,11 +1670,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1896
1670
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1897
1671
  // 🔥 使用唯一的 _id
1898
1672
  _id: uniqueId,
1899
- num: _appliedUseCount,
1900
- quantity: _appliedUseCount,
1673
+ num: 1,
1674
+ quantity: 1,
1901
1675
  price: discountedPrice,
1902
1676
  // 折扣后的价格
1903
- total: new Decimal(discountedPrice).mul(_appliedUseCount).toNumber(),
1677
+ total: discountedPrice,
1904
1678
  discount_list: [_discountDetail],
1905
1679
  processed: true,
1906
1680
  _discountId: _selectedDiscount2.id
@@ -1919,12 +1693,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1919
1693
  }));
1920
1694
  }
1921
1695
  } else {
1922
- var _selectedDiscount3$me, _selectedDiscount3$me2, _reapplyDiscountPerce2, _selectedDiscount3$me3, _flatItem$parentProdu9;
1696
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _reapplyDiscountPerce2, _flatItem$parentProdu9;
1923
1697
  // 折扣卡:不拆分数量,直接应用
1924
1698
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1925
- markDiscountUsed(_selectedDiscount3);
1699
+ usedDiscounts.set(_selectedDiscount3.id, true);
1926
1700
  // 🔥 更新 product_id 使用计数(虽然此处主要是折扣卡,但保持一致性)
1927
- if (isFullCoveragePass(_selectedDiscount3)) {
1701
+ if ((_selectedDiscount3.tag || _selectedDiscount3.type) === 'good_pass') {
1928
1702
  var _currentCount2 = usedProductIdCounts.get(_selectedDiscount3.product_id) || 0;
1929
1703
  usedProductIdCounts.set(_selectedDiscount3.product_id, _currentCount2 + 1);
1930
1704
  }
@@ -1974,7 +1748,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1974
1748
  discount_product_id: _selectedDiscount3.product_id
1975
1749
  },
1976
1750
  metadata: _objectSpread({
1977
- encoded: ((_selectedDiscount3$me3 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me3 === void 0 ? void 0 : _selectedDiscount3$me3.encoded) || _selectedDiscount3.encoded,
1978
1751
  // 🔥 使用唯一的 _id
1979
1752
  custom_product_bundle_map_id: _uniqueId,
1980
1753
  discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
@@ -2055,10 +1828,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2055
1828
  // 没有bundle,直接使用主商品处理结果
2056
1829
  result.push.apply(result, _toConsumableArray(mainProductArr));
2057
1830
  } else {
2058
- // 🔥 有 bundle,需要检查子商品是否应用了全额抵扣卡
1831
+ // 🔥 有bundle,需要检查子商品是否应用了商品券
2059
1832
  // 1. 先收集所有bundle子商品的处理结果
2060
1833
  var bundleProcessingInfo = new Map();
2061
- var hasFullCoveragePassApplied = false;
1834
+ var hasGoodPassApplied = false; // 标记是否有子商品应用了商品券
1835
+
2062
1836
  if (product.bundle && Array.isArray(product.bundle)) {
2063
1837
  product.bundle.forEach(function (bundleItem, bundleIndex) {
2064
1838
  var bundleItemId = "".concat(product._id, "_bundle_").concat(bundleIndex);
@@ -2069,14 +1843,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2069
1843
  } else {
2070
1844
  // 处理过的bundle item
2071
1845
  bundleProcessingInfo.set(bundleIndex, processedBundleItems);
2072
- var hasFullCoveragePass = processedBundleItems.some(function (item) {
1846
+ // 🔥 检查是否应用了商品券(good_pass)
1847
+ var hasGoodPass = processedBundleItems.some(function (item) {
2073
1848
  var _item$discount_list;
2074
1849
  return (_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.some(function (discount) {
2075
- return isFullCoveragePass(discount);
1850
+ return discount.type === 'good_pass' || discount.tag === 'good_pass';
2076
1851
  });
2077
1852
  });
2078
- if (hasFullCoveragePass) {
2079
- hasFullCoveragePassApplied = true;
1853
+ if (hasGoodPass) {
1854
+ hasGoodPassApplied = true;
2080
1855
  }
2081
1856
  }
2082
1857
  });
@@ -2084,7 +1859,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2084
1859
 
2085
1860
  // 🔥 2. 如果有子商品应用了商品券,且主商品数量大于1,需要拆分主商品
2086
1861
  var mainProductQuantity = mainProductArr[0] ? _this4.hooks.getProduct(mainProductArr[0]).quantity : 1;
2087
- if (hasFullCoveragePassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
1862
+ if (hasGoodPassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
2088
1863
  var mainProduct = mainProductArr[0];
2089
1864
  var mainProductData = _this4.hooks.getProduct(mainProduct);
2090
1865
 
@@ -2152,8 +1927,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2152
1927
 
2153
1928
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
2154
1929
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
2155
- var _discount$metadata7, _discount$metadata8;
2156
- if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
1930
+ var _discount$metadata6, _discount$metadata7;
1931
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
2157
1932
  // bundle的discount_list保持不变
2158
1933
  return discount;
2159
1934
  }
@@ -2161,7 +1936,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2161
1936
  return _objectSpread(_objectSpread({}, discount), {}, {
2162
1937
  // num: 1,
2163
1938
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2164
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata8 = discount.metadata) === null || _discount$metadata8 === void 0 ? void 0 : _discount$metadata8.custom_product_bundle_map_id,
1939
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata7 = discount.metadata) === null || _discount$metadata7 === void 0 ? void 0 : _discount$metadata7.custom_product_bundle_map_id,
2165
1940
  num: 1
2166
1941
  })
2167
1942
  });
@@ -2226,8 +2001,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2226
2001
 
2227
2002
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
2228
2003
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
2229
- var _discount$metadata9, _discount$metadata10;
2230
- if (discount !== null && discount !== void 0 && (_discount$metadata9 = discount.metadata) !== null && _discount$metadata9 !== void 0 && _discount$metadata9.custom_product_bundle_map_id) {
2004
+ var _discount$metadata8, _discount$metadata9;
2005
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
2231
2006
  // bundle的discount_list保持不变
2232
2007
  return discount;
2233
2008
  }
@@ -2235,7 +2010,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2235
2010
  return _objectSpread(_objectSpread({}, discount), {}, {
2236
2011
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2237
2012
  num: mainProductQuantity - 1,
2238
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata10 = discount.metadata) === null || _discount$metadata10 === void 0 ? void 0 : _discount$metadata10.custom_product_bundle_map_id
2013
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata9 = discount.metadata) === null || _discount$metadata9 === void 0 ? void 0 : _discount$metadata9.custom_product_bundle_map_id
2239
2014
  })
2240
2015
  // num: mainProductQuantity - 1,
2241
2016
  });
@@ -2285,7 +2060,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2285
2060
  } else {
2286
2061
  // 🔥 没有子商品被拆分,使用原有逻辑
2287
2062
  mainProductArr.forEach(function (mainProduct) {
2288
- var _ref29, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
2063
+ var _ref17, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
2289
2064
  var mainProductData = _this4.hooks.getProduct(mainProduct);
2290
2065
 
2291
2066
  // 重组bundle
@@ -2300,16 +2075,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2300
2075
  } else {
2301
2076
  // 🔥 关键:拆分后的bundle item
2302
2077
  processedBundleItems.forEach(function (item) {
2303
- var _item$price, _ref28, _item$bundle_selling_;
2078
+ var _item$price, _ref16, _item$bundle_selling_;
2304
2079
  var nextBundlePrice = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : bundleItem.price;
2305
- var nextBundleSellingPrice = (_ref28 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref28 !== void 0 ? _ref28 : bundleItem.bundle_selling_price;
2080
+ var nextBundleSellingPrice = (_ref16 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref16 !== void 0 ? _ref16 : bundleItem.bundle_selling_price;
2306
2081
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
2307
2082
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
2308
- var _discount$metadata11;
2083
+ var _discount$metadata10;
2309
2084
  return _objectSpread(_objectSpread({}, discount), {}, {
2310
2085
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2311
2086
  num: item.num,
2312
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata11 = discount.metadata) === null || _discount$metadata11 === void 0 ? void 0 : _discount$metadata11.custom_product_bundle_map_id
2087
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata10 = discount.metadata) === null || _discount$metadata10 === void 0 ? void 0 : _discount$metadata10.custom_product_bundle_map_id
2313
2088
  })
2314
2089
  // num: item.num, // 使用拆分后的 num
2315
2090
  });
@@ -2329,7 +2104,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2329
2104
 
2330
2105
  // 主商品已经在前面的 setProduct 中应用过折扣;这里只替换 bundle,
2331
2106
  // 避免把主商品 discount_list 再扣一次。
2332
- var mainSellingPrice = (_ref29 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref29 !== void 0 ? _ref29 : 0;
2107
+ var mainSellingPrice = (_ref17 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref17 !== void 0 ? _ref17 : 0;
2333
2108
  var newTotal = Number(mainSellingPrice || 0);
2334
2109
  var newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
2335
2110
 
@@ -2398,36 +2173,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2398
2173
 
2399
2174
  // 获取此优惠券实际应用的商品详情
2400
2175
  var appliedProductDetails = appliedDiscountProducts.get(discount.id) || [];
2401
- var committedAppliedProductDetails = isEntitlementPass(discount) ? mergeEntitlementAppliedProductDetails(discount.committedAppliedProductDetails || []) : [];
2402
- var allAppliedProductDetails = isEntitlementPass(discount) ? mergeEntitlementAppliedProductDetails([].concat(_toConsumableArray(committedAppliedProductDetails), _toConsumableArray(appliedProductDetails))) : appliedProductDetails;
2403
2176
 
2404
2177
  // 根据是否有适用商品决定isAvailable
2405
2178
  var isAvailable = applicableProducts.length > 0;
2406
- var timeReasons = discountTimeReasons.get(discount.id) || [];
2407
- var timeReason = timeReasons.length ? timeReasons.every(Boolean) ? timeReasons[0] : undefined : getDiscountTimeUnavailableReason(discount, dayjs().format('YYYY-MM-DD HH:mm:ss'));
2408
- var reasonCode = isAvailable ? undefined : getDiscountUsageBlockReason(discount) || timeReason || discount.reasonCode || (discountHolderMismatch.has(discount.id) ? 'holder_not_matched' : 'product_not_applicable');
2409
- var availabilityReason = {
2410
- reasonCode: reasonCode,
2411
- reason: reasonCode && reasonCode === discount.reasonCode ? discount.reason : undefined
2412
- };
2413
2179
 
2414
2180
  // 如果此优惠券被明确设置为不选中,保持其状态,但正确设置isAvailable
2415
2181
  if (typeof discount.isSelected === 'boolean' && discount.isSelected === false && discount.isManualSelect) {
2416
- return _objectSpread(_objectSpread(_objectSpread({}, discount), availabilityReason), {}, {
2182
+ return _objectSpread(_objectSpread({}, discount), {}, {
2417
2183
  isSelected: false,
2418
2184
  isAvailable: isAvailable,
2419
2185
  // 正确设置可用性
2420
2186
  applicableProductIds: applicableProducts,
2421
2187
  // 添加可抵扣的商品详情
2422
2188
  applicableProductDetails: applicableProductDetails,
2423
- // 已提交的历史使用不可撤销;只取消本次新增分配。
2424
- appliedProductDetails: committedAppliedProductDetails
2189
+ // 添加实际抵扣的商品详情(对于未选中的优惠券,为空数组)
2190
+ appliedProductDetails: []
2425
2191
  });
2426
2192
  }
2427
- if (isDiscountUsed(discount)) {
2193
+ if (usedDiscounts.get(discount.id)) {
2428
2194
  return _objectSpread(_objectSpread({}, discount), {}, {
2429
- reason: undefined,
2430
- reasonCode: undefined,
2431
2195
  isSelected: true,
2432
2196
  isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
2433
2197
  // 标记为可用,因为它已被应用
@@ -2437,7 +2201,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2437
2201
  // 添加可抵扣的商品详情
2438
2202
  applicableProductDetails: applicableProductDetails,
2439
2203
  // 添加实际抵扣的商品详情
2440
- appliedProductDetails: allAppliedProductDetails
2204
+ appliedProductDetails: appliedProductDetails
2441
2205
  });
2442
2206
  }
2443
2207
  var isSelected = typeof discount.isSelected === 'boolean' ? discount.isSelected : undefined;
@@ -2445,10 +2209,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2445
2209
  // 如果是可用的 并且没有手动标记 则设置为选中
2446
2210
  if (isAvailable && appliedProductDetails.length && !discount.isManualSelect) {
2447
2211
  isSelected = true;
2448
- } else if (!appliedProductDetails.length && !committedAppliedProductDetails.length) {
2212
+ } else if (!appliedProductDetails.length) {
2449
2213
  isSelected = false;
2450
2214
  }
2451
- return _objectSpread(_objectSpread(_objectSpread({}, discount), availabilityReason), {}, {
2215
+ return _objectSpread(_objectSpread({}, discount), {}, {
2452
2216
  // 如果有适用的商品,标记为可用
2453
2217
  isAvailable: isAvailable,
2454
2218
  isSelected: isSelected,
@@ -2458,69 +2222,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2458
2222
  applicableProductIds: applicableProducts,
2459
2223
  // 添加可抵扣的商品详情
2460
2224
  applicableProductDetails: applicableProductDetails,
2461
- // 编辑订单的历史使用继续保留,本次没有新增使用。
2462
- appliedProductDetails: committedAppliedProductDetails
2463
- });
2464
- });
2465
-
2466
- // 整单分配完成后统一记录卡余额;历史使用已包含在服务端余额中,只扣本次新增次数。
2467
- var entitlementBalances = new Map();
2468
- addModeDiscount.forEach(function (discount) {
2469
- var quota = resolveEntitlementQuota(discount);
2470
- if (!quota) return;
2471
- entitlementBalances.set(String(discount.id), quota.type === 'unlimited' ? null : Math.max(quota.balance - (entitlementUsageCounts.get(discount.id) || 0), 0));
2472
- });
2473
- var getEntitlementBalance = function getEntitlementBalance(detail) {
2474
- var _detail$discount$reso2, _detail$discount4;
2475
- if (!isEntitlementPass(detail)) return undefined;
2476
- var resourceId = (_detail$discount$reso2 = detail === null || detail === void 0 || (_detail$discount4 = detail.discount) === null || _detail$discount4 === void 0 ? void 0 : _detail$discount4.resource_id) !== null && _detail$discount$reso2 !== void 0 ? _detail$discount$reso2 : detail === null || detail === void 0 ? void 0 : detail.resource_id;
2477
- return entitlementBalances.get(String(resourceId));
2478
- };
2479
- var needsEntitlementBalance = function needsEntitlementBalance(detail) {
2480
- var _detail$metadata3;
2481
- var balance = getEntitlementBalance(detail);
2482
- return balance !== undefined && (detail === null || detail === void 0 || (_detail$metadata3 = detail.metadata) === null || _detail$metadata3 === void 0 ? void 0 : _detail$metadata3.balance) !== balance;
2483
- };
2484
- var withEntitlementBalance = function withEntitlementBalance(detail) {
2485
- if (!needsEntitlementBalance(detail)) return detail;
2486
- return _objectSpread(_objectSpread({}, detail), {}, {
2487
- metadata: _objectSpread(_objectSpread({}, detail.metadata || {}), {}, {
2488
- balance: getEntitlementBalance(detail)
2489
- })
2225
+ // 添加实际抵扣的商品详情(对于未使用的优惠券,为空数组)
2226
+ appliedProductDetails: []
2490
2227
  });
2491
- };
2492
- var getProductDiscountDetails = function getProductDiscountDetails(originProduct) {
2493
- var product = _this4.hooks.getProduct(originProduct);
2494
- return [].concat(_toConsumableArray(product.discount_list || []), _toConsumableArray((product.bundle || []).flatMap(function (bundle) {
2495
- return bundle.discount_list || [];
2496
- })));
2497
- };
2498
- var productsWithEntitlementBalances = entitlementBalances.size ? processedProductList.map(function (product) {
2499
- if (!getProductDiscountDetails(product).some(needsEntitlementBalance)) {
2500
- return product;
2501
- }
2502
- // 历史商品及套餐可能仍引用输入快照;仅复制有变化的行,并直接更新 metadata。
2503
- // 不再次调用价格换算钩子,避免只补余额时改变商品价格。
2504
- var nextProduct = cloneDeep(product);
2505
- getProductDiscountDetails(nextProduct).forEach(function (detail) {
2506
- if (!needsEntitlementBalance(detail)) return;
2507
- detail.metadata = withEntitlementBalance(detail).metadata;
2508
- });
2509
- return nextProduct;
2510
- }) : processedProductList;
2511
- var discountsWithEntitlementBalances = [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList)).map(function (discount) {
2512
- if (!isEntitlementPass(discount) || !entitlementBalances.has(String(discount.id))) {
2513
- return discount;
2514
- }
2515
- return _objectSpread(_objectSpread({}, discount), {}, {
2516
- appliedProductDetails: (discount.appliedProductDetails || []).map(withEntitlementBalance)
2517
- }, discount.committedAppliedProductDetails ? {
2518
- committedAppliedProductDetails: discount.committedAppliedProductDetails.map(withEntitlementBalance)
2519
- } : {});
2520
2228
  });
2521
2229
  return {
2522
- productList: productsWithEntitlementBalances,
2523
- discountList: discountsWithEntitlementBalances
2230
+ productList: processedProductList,
2231
+ discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
2524
2232
  };
2525
2233
  }
2526
2234
 
@@ -2545,15 +2253,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2545
2253
  var ruleType = usageRules.type;
2546
2254
  // 套餐适用范围配置
2547
2255
  var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
2548
- var _ref30 = packageScope || {},
2549
- _ref30$type = _ref30.type,
2550
- scopeType = _ref30$type === void 0 ? 'product_all' : _ref30$type,
2551
- _ref30$exclude_bundle = _ref30.exclude_bundle_product_ids,
2552
- exclude_bundle_product_ids = _ref30$exclude_bundle === void 0 ? [] : _ref30$exclude_bundle,
2553
- _ref30$include_bundle = _ref30.include_bundle_product_ids,
2554
- include_bundle_product_ids = _ref30$include_bundle === void 0 ? [] : _ref30$include_bundle,
2555
- _ref30$filter = _ref30.filter,
2556
- filter = _ref30$filter === void 0 ? 0 : _ref30$filter;
2256
+ var _ref18 = packageScope || {},
2257
+ _ref18$type = _ref18.type,
2258
+ scopeType = _ref18$type === void 0 ? 'product_all' : _ref18$type,
2259
+ _ref18$exclude_bundle = _ref18.exclude_bundle_product_ids,
2260
+ exclude_bundle_product_ids = _ref18$exclude_bundle === void 0 ? [] : _ref18$exclude_bundle,
2261
+ _ref18$include_bundle = _ref18.include_bundle_product_ids,
2262
+ include_bundle_product_ids = _ref18$include_bundle === void 0 ? [] : _ref18$include_bundle,
2263
+ _ref18$filter = _ref18.filter,
2264
+ filter = _ref18$filter === void 0 ? 0 : _ref18$filter;
2557
2265
  var isMainProduct = flatItem.type === 'main'; // 单独购买
2558
2266
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
2559
2267
  var bundleMainProductId = (_flatItem$product = flatItem.product) === null || _flatItem$product === void 0 ? void 0 : _flatItem$product.product_id;