@pisell/pisellos 2.1.172 → 2.1.173

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 (202) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -1
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +26 -99
  6. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  7. package/dist/model/strategy/adapter/walletPass/evaluator.js +8 -61
  8. package/dist/model/strategy/adapter/walletPass/locales.js +3 -12
  9. package/dist/model/strategy/engine.d.ts +5 -18
  10. package/dist/model/strategy/engine.js +45 -145
  11. package/dist/model/strategy/type.d.ts +0 -17
  12. package/dist/model/strategy/type.js +0 -4
  13. package/dist/modules/Cart/types.d.ts +0 -2
  14. package/dist/modules/Cart/utils/cartProduct.js +25 -56
  15. package/dist/modules/Cart/utils/changePrice.js +16 -9
  16. package/dist/modules/Discount/index.d.ts +9 -3
  17. package/dist/modules/Discount/index.js +103 -11
  18. package/dist/modules/Discount/types.d.ts +9 -18
  19. package/dist/modules/OpenData/index.d.ts +24 -0
  20. package/dist/modules/OpenData/index.js +173 -0
  21. package/dist/modules/OpenData/types.d.ts +73 -0
  22. package/dist/modules/OpenData/types.js +1 -0
  23. package/dist/modules/OpenData/utils.d.ts +2 -0
  24. package/dist/modules/OpenData/utils.js +75 -0
  25. package/dist/modules/Order/index.d.ts +66 -1
  26. package/dist/modules/Order/index.js +906 -30
  27. package/dist/modules/Order/types.d.ts +174 -12
  28. package/dist/modules/Order/types.js +2 -0
  29. package/dist/modules/Order/utils.d.ts +118 -0
  30. package/dist/modules/Order/utils.js +586 -2
  31. package/dist/modules/Payment/index.d.ts +1 -2
  32. package/dist/modules/Payment/index.js +7 -10
  33. package/dist/modules/Payment/utils.js +0 -3
  34. package/dist/modules/Payment/walletpass.d.ts +0 -23
  35. package/dist/modules/Payment/walletpass.js +95 -191
  36. package/dist/modules/Product/utils.js +2 -2
  37. package/dist/modules/ProductList/index.d.ts +1 -1
  38. package/dist/modules/ProductList/index.js +4 -3
  39. package/dist/modules/Quotation/index.d.ts +48 -0
  40. package/dist/modules/Quotation/index.js +248 -0
  41. package/dist/modules/Quotation/types.d.ts +42 -0
  42. package/dist/modules/Quotation/types.js +1 -0
  43. package/dist/modules/Rules/index.d.ts +5 -9
  44. package/dist/modules/Rules/index.js +173 -669
  45. package/dist/modules/Rules/types.d.ts +0 -2
  46. package/dist/modules/SalesSummary/index.d.ts +63 -0
  47. package/dist/modules/SalesSummary/index.js +174 -0
  48. package/dist/modules/SalesSummary/types.d.ts +60 -0
  49. package/dist/modules/SalesSummary/types.js +1 -0
  50. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  51. package/dist/modules/SalesSummary/utils.js +480 -0
  52. package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
  53. package/dist/modules/ScanOrderLogger/index.js +174 -0
  54. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  55. package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
  56. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  57. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  58. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  59. package/dist/modules/ScanOrderLogger/types.js +1 -0
  60. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  61. package/dist/modules/Schedule/utils.d.ts +1 -1
  62. package/dist/modules/Summary/types.d.ts +0 -2
  63. package/dist/modules/Summary/utils.d.ts +3 -9
  64. package/dist/modules/Summary/utils.js +67 -57
  65. package/dist/modules/index.d.ts +4 -0
  66. package/dist/modules/index.js +5 -1
  67. package/dist/plugins/window.d.ts +0 -2
  68. package/dist/solution/BookingByStep/index.d.ts +3 -4
  69. package/dist/solution/BookingByStep/index.js +46 -43
  70. package/dist/solution/BookingByStep/types.d.ts +3 -1
  71. package/dist/solution/BookingByStep/types.js +5 -1
  72. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  73. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  74. package/dist/solution/Checkout/index.js +0 -2
  75. package/dist/solution/ScanOrder/index.d.ts +158 -0
  76. package/dist/solution/ScanOrder/index.js +3474 -0
  77. package/dist/solution/ScanOrder/types.d.ts +306 -0
  78. package/dist/solution/ScanOrder/types.js +35 -0
  79. package/dist/solution/ScanOrder/utils.d.ts +172 -0
  80. package/dist/solution/ScanOrder/utils.js +796 -0
  81. package/dist/solution/ShopDiscount/index.d.ts +3 -2
  82. package/dist/solution/ShopDiscount/index.js +60 -59
  83. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  84. package/dist/solution/ShopDiscount/types.js +1 -2
  85. package/dist/solution/ShopDiscount/utils.js +12 -26
  86. package/dist/solution/VenueBooking/index.d.ts +206 -0
  87. package/dist/solution/VenueBooking/index.js +3519 -0
  88. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  89. package/dist/solution/VenueBooking/types.d.ts +154 -0
  90. package/dist/solution/VenueBooking/types.js +21 -0
  91. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  92. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  93. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  94. package/dist/solution/VenueBooking/utils/resource.js +131 -0
  95. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  96. package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
  97. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  98. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  99. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  100. package/dist/solution/VenueBooking/utils.js +1 -0
  101. package/dist/solution/index.d.ts +2 -0
  102. package/dist/solution/index.js +3 -1
  103. package/lib/apis/picoding.d.ts +0 -0
  104. package/lib/apis/picoding.js +0 -0
  105. package/lib/index.d.ts +0 -1
  106. package/lib/index.js +1 -3
  107. package/lib/model/strategy/adapter/promotion/evaluator.js +8 -57
  108. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  109. package/lib/model/strategy/adapter/walletPass/evaluator.js +3 -34
  110. package/lib/model/strategy/adapter/walletPass/locales.js +3 -12
  111. package/lib/model/strategy/engine.d.ts +5 -18
  112. package/lib/model/strategy/engine.js +21 -85
  113. package/lib/model/strategy/type.d.ts +0 -17
  114. package/lib/modules/Cart/types.d.ts +0 -2
  115. package/lib/modules/Cart/utils/cartProduct.js +12 -39
  116. package/lib/modules/Cart/utils/changePrice.js +13 -9
  117. package/lib/modules/Discount/index.d.ts +9 -3
  118. package/lib/modules/Discount/index.js +65 -4
  119. package/lib/modules/Discount/types.d.ts +9 -18
  120. package/lib/modules/OpenData/index.d.ts +24 -0
  121. package/lib/modules/OpenData/index.js +119 -0
  122. package/lib/modules/OpenData/types.d.ts +73 -0
  123. package/lib/modules/OpenData/types.js +17 -0
  124. package/lib/modules/OpenData/utils.d.ts +2 -0
  125. package/lib/modules/OpenData/utils.js +111 -0
  126. package/lib/modules/Order/index.d.ts +66 -1
  127. package/lib/modules/Order/index.js +515 -1
  128. package/lib/modules/Order/types.d.ts +174 -12
  129. package/lib/modules/Order/utils.d.ts +118 -0
  130. package/lib/modules/Order/utils.js +483 -2
  131. package/lib/modules/Payment/index.d.ts +1 -2
  132. package/lib/modules/Payment/index.js +0 -1
  133. package/lib/modules/Payment/utils.js +0 -3
  134. package/lib/modules/Payment/walletpass.d.ts +0 -23
  135. package/lib/modules/Payment/walletpass.js +17 -94
  136. package/lib/modules/Product/utils.js +2 -2
  137. package/lib/modules/ProductList/index.d.ts +1 -1
  138. package/lib/modules/ProductList/index.js +5 -4
  139. package/lib/modules/Quotation/index.d.ts +48 -0
  140. package/lib/modules/Quotation/index.js +152 -0
  141. package/lib/modules/Quotation/types.d.ts +42 -0
  142. package/lib/modules/Quotation/types.js +17 -0
  143. package/lib/modules/Rules/index.d.ts +5 -9
  144. package/lib/modules/Rules/index.js +292 -776
  145. package/lib/modules/Rules/types.d.ts +0 -2
  146. package/lib/modules/SalesSummary/index.d.ts +63 -0
  147. package/lib/modules/SalesSummary/index.js +105 -0
  148. package/lib/modules/SalesSummary/types.d.ts +60 -0
  149. package/lib/modules/SalesSummary/types.js +17 -0
  150. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  151. package/lib/modules/SalesSummary/utils.js +420 -0
  152. package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
  153. package/lib/modules/ScanOrderLogger/index.js +147 -0
  154. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  155. package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
  156. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  157. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  158. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  159. package/lib/modules/ScanOrderLogger/types.js +17 -0
  160. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  161. package/lib/modules/Schedule/utils.d.ts +1 -1
  162. package/lib/modules/Summary/types.d.ts +0 -2
  163. package/lib/modules/Summary/utils.d.ts +3 -9
  164. package/lib/modules/Summary/utils.js +45 -34
  165. package/lib/modules/index.d.ts +4 -0
  166. package/lib/modules/index.js +9 -1
  167. package/lib/plugins/window.d.ts +0 -2
  168. package/lib/solution/BookingByStep/index.d.ts +3 -4
  169. package/lib/solution/BookingByStep/index.js +6 -4
  170. package/lib/solution/BookingByStep/types.d.ts +3 -1
  171. package/lib/solution/BookingByStep/types.js +10 -0
  172. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  173. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  174. package/lib/solution/Checkout/index.js +0 -2
  175. package/lib/solution/ScanOrder/index.d.ts +158 -0
  176. package/lib/solution/ScanOrder/index.js +2135 -0
  177. package/lib/solution/ScanOrder/types.d.ts +306 -0
  178. package/lib/solution/ScanOrder/types.js +36 -0
  179. package/lib/solution/ScanOrder/utils.d.ts +172 -0
  180. package/lib/solution/ScanOrder/utils.js +658 -0
  181. package/lib/solution/ShopDiscount/index.d.ts +3 -2
  182. package/lib/solution/ShopDiscount/index.js +19 -25
  183. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  184. package/lib/solution/ShopDiscount/utils.js +6 -10
  185. package/lib/solution/VenueBooking/index.d.ts +206 -0
  186. package/lib/solution/VenueBooking/index.js +1955 -0
  187. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  188. package/lib/solution/VenueBooking/types.d.ts +154 -0
  189. package/lib/solution/VenueBooking/types.js +44 -0
  190. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  191. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  192. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  193. package/lib/solution/VenueBooking/utils/resource.js +92 -0
  194. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  195. package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
  196. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  197. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  198. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  199. package/lib/solution/VenueBooking/utils.js +69 -0
  200. package/lib/solution/index.d.ts +2 -0
  201. package/lib/solution/index.js +5 -1
  202. package/package.json +1 -1
@@ -1,8 +1,4 @@
1
- var _excluded = ["_original_add_price"],
2
- _excluded2 = ["_original_price", "_original_add_price"];
3
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- 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; }
5
- 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; }
6
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
4
  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; } } }; }
@@ -35,6 +31,7 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
35
31
  import Decimal from 'decimal.js';
36
32
  import { isBoolean } from 'lodash-es';
37
33
  import dayjs from 'dayjs';
34
+
38
35
  // 临时变量
39
36
  var flatItem;
40
37
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
@@ -47,8 +44,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
47
44
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
48
45
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
49
46
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
50
- _defineProperty(_assertThisInitialized(_this), "window", void 0);
51
- // WindowPlugin 实例
52
47
  _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
53
48
  _this.hooks = {};
54
49
  return _this;
@@ -63,8 +58,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
63
58
  this.core = core;
64
59
  this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
65
60
  this.store = options === null || options === void 0 ? void 0 : options.store;
66
- this.window = core.getPlugin('window');
67
- case 4:
61
+ case 3:
68
62
  case "end":
69
63
  return _context.stop();
70
64
  }
@@ -119,12 +113,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
119
113
  // 最终直接匹配 holder 是否相同
120
114
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
121
115
  }
122
- }, {
123
- key: "getWalletPassEvaluator",
124
- value: function getWalletPassEvaluator() {
125
- var _this$window$getWalle, _this$window;
126
- return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
127
- }
128
116
 
129
117
  // 判断discountList 是否可以对当前productList生效
130
118
  }, {
@@ -134,7 +122,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
134
122
  var oldDiscountList = _ref.oldDiscountList,
135
123
  newDiscountList = _ref.newDiscountList,
136
124
  productList = _ref.productList,
137
- orderTotalAmount = _ref.orderTotalAmount,
138
125
  holders = _ref.holders,
139
126
  isFormSubject = _ref.isFormSubject;
140
127
  // 首先检查是否有新的优惠券可应用
@@ -169,7 +156,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
169
156
  var result = this.calcDiscount({
170
157
  discountList: mergedDiscountList,
171
158
  productList: _toConsumableArray(productList),
172
- orderTotalAmount: orderTotalAmount,
173
159
  holders: holders,
174
160
  isFormSubject: isFormSubject
175
161
  }, {
@@ -303,8 +289,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
303
289
  var discountList = _ref2.discountList,
304
290
  productList = _ref2.productList,
305
291
  holders = _ref2.holders,
306
- isFormSubject = _ref2.isFormSubject,
307
- orderTotalAmount = _ref2.orderTotalAmount;
292
+ isFormSubject = _ref2.isFormSubject;
308
293
  var editModeDiscount = [];
309
294
  var addModeDiscount = [];
310
295
  discountList.forEach(function (discount) {
@@ -553,62 +538,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
553
538
  return priceB.minus(priceA).toNumber();
554
539
  });
555
540
 
556
- // 🔥 为每个折扣卡/商品券执行策略检查并附加config
557
- var evaluator = this.getWalletPassEvaluator();
558
- if (evaluator) {
559
- addModeDiscount.forEach(function (discount) {
560
- var discountType = discount.tag || discount.type;
561
- // 只对 good_pass 和 discount_card 类型执行策略检查
562
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
563
- var _discount$limited_rel, _discount$limited_rel2;
564
- // 转换 discount 为 Voucher 格式
565
- var voucher = {
566
- id: discount.id,
567
- amount: Number(discount.par_value || 0),
568
- balance: Number(discount.balance || 0),
569
- type: discountType,
570
- product_id: discount.product_id,
571
- unified_available_status: 1,
572
- available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
573
- available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
574
- };
575
-
576
- // 转换 sortedFlattenedList 为 Product 格式
577
- var productsForEvaluate = sortedFlattenedList.map(function (item) {
578
- var _item$product;
579
- return {
580
- product_id: item.id,
581
- price: item.price || 0,
582
- quantity: item.quantity || item.num || 1,
583
- selling_price: item.price || 0,
584
- product_options: item.type === 'main' ? (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.options : undefined
585
- };
586
- });
587
-
588
- // 调用策略检查
589
- var result = evaluator.checkVoucherAvailability({
590
- orderTotalAmount: orderTotalAmount,
591
- products: productsForEvaluate,
592
- vouchers: [voucher]
593
- });
594
-
595
- // 将 config 附加到 discount 对象
596
- if (result.isAvailable) {
597
- discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
598
- isAvailable: true
599
- });
600
- } else {
601
- discount.config = {
602
- isAvailable: false
603
- };
604
- }
605
- }
541
+ // 检查商品是否被排除(全品类)
542
+ var isProductIncludedByLimitedData = function isProductIncludedByLimitedData(limitedData, productId) {
543
+ var excludedIds = (limitedData === null || limitedData === void 0 ? void 0 : limitedData.exclude_product_ids) || [];
544
+ var isExcluded = (limitedData === null || limitedData === void 0 ? void 0 : limitedData.filter) === 1 && excludedIds.some(function (id) {
545
+ return String(id) === String(productId);
606
546
  });
607
- }
547
+ return !isExcluded;
548
+ };
608
549
 
609
550
  /**
610
- // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
611
- const sortedProductList = [...productList].sort((a, b) => {
551
+ // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
552
+ const sortedProductList = [...productList].sort((a, b) => {
612
553
  const aProduct = this.hooks.getProduct(a);
613
554
  const bProduct = this.hooks.getProduct(b);
614
555
  const priceA = new Decimal((aProduct.price as string) || '0');
@@ -626,22 +567,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
626
567
  // 标记已使用的优惠券
627
568
  var usedDiscounts = new Map();
628
569
 
629
- // 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
630
- var usedProductIdCounts = new Map();
631
-
632
- // 🔥 统计每张折扣卡的 applicableProductLimit 已使用次数(跨商品全局计数)
633
- var usedDiscountCardLimitCounts = new Map();
634
-
635
- // 🔥 预先将 editModeDiscount 中的折扣卡计入 applicableProductLimit 已使用次数
636
- editModeDiscount.forEach(function (discount) {
637
- var discountType = discount.tag || discount.type;
638
- if (['discount_card', 'product_discount_card'].includes(discountType)) {
639
- var _discount$metadata4;
640
- var currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
641
- usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.num) || 1));
642
- }
643
- });
644
-
645
570
  // 记录每个优惠券适用的商品ID
646
571
  var discountApplicability = new Map();
647
572
 
@@ -857,7 +782,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
857
782
  var _flatItem$parentProdu5;
858
783
  // bundle子商品:构造虚拟商品对象
859
784
  product = {
860
- startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
861
785
  _id: flatItem._id,
862
786
  id: flatItem.id,
863
787
  price: flatItem.price,
@@ -866,12 +790,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
866
790
  total: flatItem.total,
867
791
  origin_total: flatItem.origin_total,
868
792
  booking_id: flatItem.booking_id,
869
- discount_list: flatItem.discount_list || []
793
+ discount_list: flatItem.discount_list || [],
794
+ startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
870
795
  };
871
796
  originProduct = flatItem.originProduct;
872
797
  }
873
798
  addModeDiscount.forEach(function (discount) {
874
- var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
799
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
875
800
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
876
801
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
877
802
  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;
@@ -882,7 +807,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
882
807
  var timeLimit = true;
883
808
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
884
809
  // 是符合折扣的商品
885
- 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;
810
+ var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
886
811
 
887
812
  // 编辑的商品 使用了优惠券不可用
888
813
  var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
@@ -895,8 +820,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
895
820
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
896
821
 
897
822
  // 判断优惠券是否适用于该商品
898
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
899
- var _discountApplicabilit, _discount$metadata5, _discount$metadata6;
823
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
824
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
900
825
  // 记录此优惠券适用的商品
901
826
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
902
827
 
@@ -912,15 +837,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
912
837
  type: discountType,
913
838
  tag: discountType,
914
839
  discount: {
915
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_card_type,
840
+ discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
916
841
  fixed_amount: product.price,
917
- discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.discount_calculation_mode,
842
+ discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
918
843
  resource_id: discount.id,
919
844
  title: discount.format_title,
920
845
  original_amount: product.price || product.origin_total,
921
846
  pre_value: discount.par_value,
922
- product_id: originProduct.id,
923
- discount_product_id: discount.product_id
847
+ product_id: originProduct.id
924
848
  },
925
849
  metadata: {
926
850
  num: num,
@@ -936,75 +860,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
936
860
  // 🔥 用于存储扁平化商品处理结果的Map
937
861
  var processedFlatItemsMap = new Map();
938
862
 
939
- // 🔥 Option 折扣辅助函数
940
- var applyDiscountToOptions = function applyDiscountToOptions(options, discount) {
941
- if (!(options !== null && options !== void 0 && options.length)) return {
942
- discountedOptions: options,
943
- optionDiscountAmount: 0
944
- };
945
- var optionDiscountAmount = 0;
946
- var discountedOptions = options.map(function (option) {
947
- var _ref6, _ref7, _option$_original_pri, _ref8, _option$num, _rest$price, _option$_original_pri2;
948
- // 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
949
- var rawUnit = (_ref6 = (_ref7 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref7 !== void 0 ? _ref7 : option.price) !== null && _ref6 !== void 0 ? _ref6 : option.add_price;
950
- var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
951
- if (baseUnitNum <= 0) return option;
952
- var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
953
- var optQty = Number((_ref8 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref8 !== void 0 ? _ref8 : 1);
954
- optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
955
- var _original_add_price = option._original_add_price,
956
- rest = _objectWithoutProperties(option, _excluded);
957
- var tmpl = (_rest$price = rest.price) !== null && _rest$price !== void 0 ? _rest$price : rest.add_price;
958
- var nextPrice = typeof tmpl === 'string' ? String(discountedPrice) : discountedPrice;
959
- return _objectSpread(_objectSpread({}, rest), {}, {
960
- _original_price: (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : _original_add_price !== undefined ? _original_add_price : rawUnit,
961
- price: nextPrice
962
- });
963
- });
964
- return {
965
- discountedOptions: discountedOptions,
966
- optionDiscountAmount: optionDiscountAmount
967
- };
968
- };
969
- var restoreOptionPrices = function restoreOptionPrices(options) {
970
- if (!(options !== null && options !== void 0 && options.length)) return options;
971
- return options.map(function (option) {
972
- var orig = option._original_price !== undefined ? option._original_price : option._original_add_price;
973
- if (orig !== undefined) {
974
- var _original_price = option._original_price,
975
- _original_add_price = option._original_add_price,
976
- rest = _objectWithoutProperties(option, _excluded2);
977
- return _objectSpread(_objectSpread({}, rest), {}, {
978
- price: orig
979
- });
980
- }
981
- return option;
982
- });
983
- };
984
- var getOptionTotal = function getOptionTotal(options) {
985
- if (!(options !== null && options !== void 0 && options.length)) return 0;
986
- return options.reduce(function (sum, opt) {
987
- var _ref9, _opt$price, _ref10, _opt$num;
988
- var unit = Number((_ref9 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref9 !== void 0 ? _ref9 : 0);
989
- var n = Number((_ref10 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref10 !== void 0 ? _ref10 : 1);
990
- return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
991
- }, 0);
992
- };
993
-
994
863
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
995
864
  // 🔥 使用扁平化后的列表进行处理
996
865
  sortedFlattenedList.forEach(function (flatItem, index) {
997
- var _product10, _product$discount_lis2, _product11, _selectedDiscount$con;
866
+ var _product10, _product$discount_lis2, _product11;
998
867
  // 获取商品数据
999
868
  var product, originProduct;
1000
869
  if (flatItem.type === 'main') {
1001
870
  product = flatItem.product;
1002
871
  originProduct = flatItem.originProduct;
1003
872
  } else {
1004
- var _flatItem$parentProdu6, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
873
+ var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu6;
1005
874
  // bundle子商品
1006
875
  product = {
1007
- startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate,
1008
876
  _id: flatItem._id,
1009
877
  id: flatItem.id,
1010
878
  price: flatItem.price,
@@ -1014,7 +882,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1014
882
  original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
1015
883
  origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
1016
884
  booking_id: flatItem.booking_id,
1017
- discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
885
+ discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || [],
886
+ startDate: (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate
1018
887
  };
1019
888
  originProduct = flatItem.originProduct;
1020
889
  }
@@ -1036,53 +905,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1036
905
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1037
906
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
1038
907
  var _product$discount_lis3, _product$discount_lis4;
1039
- // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
1040
- var discountType = discount.tag || discount.type;
1041
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
1042
- var _discount$config2;
1043
- // 如果策略检查后没有config,说明不可用
1044
- if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
1045
- return false;
1046
- }
1047
- }
1048
-
1049
908
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
1050
909
  // 商品券时主商品价格为0不可用
1051
910
  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;
1052
911
 
1053
912
  // 折扣卡商品价格为0时不可用
1054
- if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
913
+ 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) {
1055
914
  var _n$discount;
1056
915
  return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
1057
916
  })) && (discount.tag || discount.type) !== 'good_pass') return false;
1058
917
  // 如果优惠券已被使用,则跳过
1059
918
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
1060
919
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
1061
-
1062
- // 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
1063
- if ((discount.tag || discount.type) === 'good_pass') {
1064
- var _discount$config3;
1065
- var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
1066
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1067
- var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
1068
- if (currentUsedCount >= maxUsagePerOrder) {
1069
- return false;
1070
- }
1071
- }
1072
- }
1073
-
1074
- // 🔥 检查折扣卡的 applicableProductLimit 限制:折扣卡可使用的最大次数(跨商品全局)
1075
- var discountTypeForLimit = discount.tag || discount.type;
1076
- if (['discount_card', 'product_discount_card'].includes(discountTypeForLimit)) {
1077
- var _discount$config4;
1078
- var applicableProductLimitConfig = ((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.applicableProductLimit) || 0;
1079
- if (applicableProductLimitConfig > 0) {
1080
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
1081
- if (currentUsedLimitCount >= applicableProductLimitConfig) {
1082
- return false;
1083
- }
1084
- }
1085
- }
1086
920
  var limitedData = discount.limited_relation_product_data;
1087
921
 
1088
922
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
@@ -1101,9 +935,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1101
935
 
1102
936
  // 判断优惠券是否适用于该商品
1103
937
  if (limitedData.type === 'product_all') {
1104
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
938
+ if (!isProductIncludedByLimitedData(limitedData, product.id)) {
1105
939
  return false;
1106
940
  }
941
+
1107
942
  // 检查 package_sub_item_usage_rules
1108
943
  if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
1109
944
  return false;
@@ -1133,22 +968,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1133
968
  var _product$discount_lis5, _product12, _product12$every;
1134
969
  // 主商品:判断自身是否手动折扣
1135
970
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
1136
- var _ref11;
1137
- return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
971
+ var _ref6;
972
+ return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
1138
973
  }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
1139
974
  return item.type === 'product';
1140
975
  })));
1141
- if (product.inPromotion) {
1142
- isManualDiscount = false;
1143
- }
1144
976
  } else {
1145
977
  // bundle子商品:判断父主商品是否手动折扣
1146
978
  var parentProduct = flatItem.parentProduct;
1147
979
  if (parentProduct) {
1148
980
  var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
1149
981
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1150
- var _ref12;
1151
- return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
982
+ var _ref7;
983
+ return !((_ref7 = item.discount_list || []) !== null && _ref7 !== void 0 && _ref7.length);
1152
984
  }) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
1153
985
  return item.type === 'product';
1154
986
  })));
@@ -1215,8 +1047,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1215
1047
  // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
1216
1048
  if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
1217
1049
  if (flatItem.type === 'main') {
1218
- // 主商品:保持原有逻辑,还原 option 价格
1219
- var restoredOptions = restoreOptionPrices(product.options);
1050
+ // 主商品:保持原有逻辑
1220
1051
  if (product.isClient) {
1221
1052
  processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
1222
1053
  origin_total: getProductOriginTotalPrice({
@@ -1224,7 +1055,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1224
1055
  original_price: product.original_price
1225
1056
  },
1226
1057
  bundle: product.bundle,
1227
- options: restoredOptions
1058
+ options: product.options
1228
1059
  }),
1229
1060
  variant: originProduct._productInit.variant,
1230
1061
  original_price: originProduct._productInit.original_price,
@@ -1233,16 +1064,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1233
1064
  price: product.price
1234
1065
  },
1235
1066
  bundle: product.bundle,
1236
- options: restoredOptions
1067
+ options: product.options
1237
1068
  }),
1238
1069
  price: product.price,
1239
- options: restoredOptions
1070
+ options: product.options
1240
1071
  }), {}, {
1241
1072
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
1242
1073
  }))]);
1243
1074
  } else {
1244
- var _ref13, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
1245
- var total = product.inPromotion ? (_ref13 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref13 !== void 0 ? _ref13 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1075
+ var _ref8, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
1076
+ var total = product.inPromotion ? (_ref8 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref8 !== void 0 ? _ref8 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1246
1077
  var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
1247
1078
  if ((product.discount_list || []).some(function (item) {
1248
1079
  return item.type === 'promotion';
@@ -1255,10 +1086,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1255
1086
  price: product.price
1256
1087
  } : {
1257
1088
  _id: product._id.split('___')[0] + '___' + index,
1089
+ origin_total: product.origin_total,
1258
1090
  total: total,
1091
+ original_price: product.original_price,
1259
1092
  price: product.price,
1260
- main_product_selling_price: main_product_selling_price,
1261
- options: restoredOptions
1093
+ main_product_selling_price: main_product_selling_price
1262
1094
  }), {}, {
1263
1095
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
1264
1096
  }))]);
@@ -1278,81 +1110,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1278
1110
  return;
1279
1111
  }
1280
1112
 
1281
- // 是否需要拆分(商品券需要拆分,折扣卡在 applicableProductLimit > 0 时也需要拆分)
1282
- var discountType = selectedDiscount.tag || selectedDiscount.type;
1283
- var isGoodPass = discountType === 'good_pass';
1284
- var isDiscountCard = ['discount_card', 'product_discount_card'].includes(discountType);
1285
- var applicableProductLimit = ((_selectedDiscount$con = selectedDiscount.config) === null || _selectedDiscount$con === void 0 ? void 0 : _selectedDiscount$con.applicableProductLimit) || 0;
1286
-
1287
- // 商品券始终需要拆分,折扣卡在 applicableProductLimit > 0 时需要拆分
1288
- var isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
1113
+ // 是否需要拆分(商品券需要拆分)
1114
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
1289
1115
 
1290
1116
  // 需要拆分出来的数量
1291
1117
  var totalQuantity = product.quantity || product.num || 1;
1292
1118
  var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1293
1119
  return (item.tag || item.type) === 'good_pass';
1294
1120
  }).length;
1295
-
1296
- // 🔥 计算最大使用次数限制
1297
- var maxUsageLimit;
1298
- if (isGoodPass) {
1299
- // 商品券:使用 maxUsagePerOrder 限制
1300
- maxUsageLimit = availableGoodPassCount;
1301
- if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
1302
- maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
1303
- }
1304
- } else if (isDiscountCard && applicableProductLimit > 0) {
1305
- // 折扣卡:使用 applicableProductLimit 限制(一个商品使用一次折扣卡算1次)
1306
- // 需要减去已使用次数(跨商品全局计数)
1307
- var usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
1308
- maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
1309
- } else {
1310
- // 其他情况不拆分
1311
- maxUsageLimit = 1;
1312
- }
1313
- var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
1121
+ var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
1314
1122
  var arr = [];
1315
1123
 
1316
1124
  // 🔥 主商品和bundle子商品分别处理
1317
1125
  if (flatItem.type === 'main') {
1318
1126
  // 主商品:保持原有逻辑
1319
1127
  if (splitCount < totalQuantity && isNeedSplit) {
1320
- var _product$origin_total2;
1321
- var _total = (_product$origin_total2 = product.origin_total) !== null && _product$origin_total2 !== void 0 ? _product$origin_total2 : product.total;
1322
- if ((product.discount_list || []).some(function (item) {
1323
- return item.type === 'promotion';
1324
- })) {
1325
- var _product$total2;
1326
- _total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
1327
- }
1328
1128
  arr.push(_this3.hooks.setProduct(originProduct, {
1329
1129
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1330
1130
  quantity: totalQuantity - splitCount,
1331
- _id: product._id.split('___')[0],
1332
- total: _total
1131
+ _id: product._id.split('___')[0]
1333
1132
  }));
1334
1133
  }
1335
1134
  for (var i = 0; i < splitCount; i++) {
1336
- var _originProduct, _selectedDiscount$con2, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
1337
- // 商品券:每个拆分商品使用不同的商品券(从 applicableDiscounts 按索引取)
1338
- // 折扣卡:所有拆分商品使用同一张折扣卡(selectedDiscountCard 或 applicableDiscounts[0])
1339
- var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
1135
+ var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1136
+ // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1137
+ var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1340
1138
  // 标记优惠券为已使用
1341
- usedDiscounts.set(currentSelectedDiscount.id, true);
1342
- // 🔥 更新 product_id 使用计数
1343
- if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === 'good_pass') {
1344
- var currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
1345
- usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
1346
- }
1347
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1348
- var currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
1349
- if (['discount_card', 'product_discount_card'].includes(currentDiscountTypeForCount)) {
1350
- var currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
1351
- usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
1352
- }
1139
+ usedDiscounts.set(_selectedDiscount.id, true);
1353
1140
 
1354
1141
  // 记录实际应用了优惠券的商品信息
1355
- var appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
1142
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
1356
1143
 
1357
1144
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
1358
1145
  var productOriginTotal = product.origin_total || product.total || 0;
@@ -1367,492 +1154,210 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1367
1154
 
1368
1155
  // 计算使用折扣卡/商品券以后,单个商品的总 total
1369
1156
  // 🔥 检查是否是 order_level 固定金额折扣卡
1370
- var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1371
- var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1157
+ var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
1158
+ var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
1372
1159
  var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
1373
- var isDeductOptionPrice = !!((_selectedDiscount$con2 = selectedDiscount.config) !== null && _selectedDiscount$con2 !== void 0 && _selectedDiscount$con2.deductOptionPrice);
1374
-
1375
- // 主商品折后价(不含 option);勿与 option 合计混在同一变量,否则 main_product_selling_price 错误
1376
- var mainProductSellingPrice = void 0;
1160
+ var targetProductTotal = void 0;
1377
1161
  var amount = void 0;
1378
1162
  var productDiscountDifference = void 0;
1379
- var discountedOptions = product.options;
1380
- var optionDiscountAmount = 0;
1381
1163
  if (isOrderLevel && productAllocation) {
1382
1164
  // order_level:使用预计算的分摊金额
1383
1165
  amount = productAllocation.discountAmount;
1384
1166
  productDiscountDifference = productAllocation.difference;
1385
- mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1167
+ targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1386
1168
  } else {
1387
1169
  // item_level 或其他类型:使用原有逻辑
1388
- mainProductSellingPrice = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
1389
- amount = new Decimal(product.price).minus(new Decimal(mainProductSellingPrice)).toNumber();
1170
+ targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1171
+ amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1390
1172
  }
1391
- if (isDeductOptionPrice && (_product$options = product.options) !== null && _product$options !== void 0 && _product$options.length) {
1392
- var optionResult = applyDiscountToOptions(product.options, currentSelectedDiscount);
1393
- discountedOptions = optionResult.discountedOptions;
1394
- optionDiscountAmount = optionResult.optionDiscountAmount;
1395
- }
1396
-
1397
- // total = 主商品折后 + option 行合计;开启 option 抵扣时必须用 discountedOptions,不能用未折扣的 product.options 再算一遍
1398
- var optionsForLineTotal = isDeductOptionPrice && (_product$options2 = product.options) !== null && _product$options2 !== void 0 && _product$options2.length ? discountedOptions : product.options;
1399
- var optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
1400
- var _total2 = new Decimal(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
1401
-
1402
- // discount_list.amount / fixed_amount:行级总优惠 = 主商品优惠 + option 优惠(与 total 变化一致)
1403
- var mainProductDiscountAmount = amount;
1404
- var lineDiscountAmount = new Decimal(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
1405
- var currentDiscountType = currentSelectedDiscount.tag === 'product_discount_card' ? 'discount_card' : currentSelectedDiscount.tag;
1406
- var _discountType = selectedDiscount.tag || selectedDiscount.type;
1407
- var currentIsGoodPass = currentDiscountType === 'good_pass';
1173
+ var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1174
+ var isGoodPass = discountType === 'good_pass';
1408
1175
  var discountDetail = {
1409
- amount: lineDiscountAmount,
1410
- type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _discountType,
1176
+ amount: amount,
1177
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
1411
1178
  discount: {
1412
- discount_card_type: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met = selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1413
- fixed_amount: lineDiscountAmount,
1414
- discount_calculation_mode: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met2 = selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1415
- resource_id: selectedDiscount.id,
1416
- title: selectedDiscount.format_title,
1179
+ discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1180
+ fixed_amount: amount,
1181
+ discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1182
+ resource_id: _selectedDiscount.id,
1183
+ title: _selectedDiscount.format_title,
1417
1184
  original_amount: product.price,
1418
1185
  product_id: originProduct.id,
1419
- percent: currentSelectedDiscount.par_value,
1420
- discount_product_id: currentSelectedDiscount.product_id
1186
+ percent: _selectedDiscount.par_value
1421
1187
  },
1422
- // 前端使用的num数量,为了计算优惠金额(拆分时为1)
1423
- _num: isNeedSplit ? 1 : product.num,
1424
- config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
1425
- metadata: _objectSpread(_objectSpread({
1188
+ // 前端使用的num数量,为了计算优惠金额
1189
+ _num: isGoodPass ? 1 : product.num,
1190
+ metadata: _objectSpread({
1426
1191
  num: 1,
1427
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
1192
+ discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
1428
1193
  }, productDiscountDifference !== undefined && {
1429
1194
  product_discount_difference: productDiscountDifference
1430
- }), {}, {
1431
- /** 仅主商品上的优惠金额(不含 option) */
1432
- mainProductDiscountAmount: mainProductDiscountAmount,
1433
- optionDiscountAmount: optionDiscountAmount
1434
1195
  })
1435
1196
  };
1436
1197
  appliedProducts.push(discountDetail);
1437
- appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
1198
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
1199
+ var _total = targetProductTotal;
1200
+ if (product.options) {
1201
+ _total = product.options.reduce(function (accumulator, currentValue) {
1202
+ var currentPrice = new Decimal(currentValue.price || 0);
1203
+ var currentNum = new Decimal(currentValue.num || 0);
1204
+ return accumulator.add(currentPrice.mul(currentNum));
1205
+ }, new Decimal(_total)).toNumber();
1206
+ }
1438
1207
 
1439
1208
  // 记录应用了优惠券的商品
1440
1209
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
1441
1210
  if (product.isClient) {
1442
1211
  arr.push(_this3.hooks.setProduct(originProduct, {
1443
1212
  discount_list: [discountDetail],
1444
- // good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
1445
- price: currentIsGoodPass ? mainProductSellingPrice : product.price,
1213
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1446
1214
  quantity: isNeedSplit ? 1 : product.quantity,
1447
1215
  origin_total: getProductOriginTotalPrice({
1448
1216
  product: {
1449
1217
  original_price: product.original_price
1450
1218
  },
1451
1219
  bundle: product.bundle,
1452
- options: restoreOptionPrices(product.options)
1220
+ options: product.options
1453
1221
  }),
1454
1222
  variant: originProduct._productInit.variant,
1455
1223
  original_price: new Decimal(product.price || 0).toNumber(),
1456
- total: _total2,
1457
- options: discountedOptions
1224
+ total: _total
1458
1225
  }));
1459
1226
  } else {
1460
1227
  arr.push(_this3.hooks.setProduct(originProduct, {
1461
1228
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
1462
- _id: product._id.split('___')[0] + '___' + currentSelectedDiscount.id + '_' + i + '_' + index,
1463
- price: currentIsGoodPass ? 0 : product.price,
1229
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
1230
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1464
1231
  quantity: isNeedSplit ? 1 : product.quantity,
1465
- total: _total2,
1232
+ total: _total,
1466
1233
  origin_total: productOriginTotal,
1467
- main_product_selling_price: mainProductSellingPrice,
1468
- options: discountedOptions
1234
+ main_product_selling_price: targetProductTotal
1469
1235
  }));
1470
1236
  }
1471
1237
  }
1472
1238
  processedProductsMap.set(product._id, arr);
1473
1239
  } else {
1474
- // 🔥 bundle子商品:支持拆分(商品券和折扣卡在 applicableProductLimit > 0 时都需要拆分)
1240
+ // 🔥 bundle子商品:支持拆分
1475
1241
  var processedItems = [];
1476
1242
  if (isNeedSplit) {
1477
- // 需要拆分数量(商品券或折扣卡有 applicableProductLimit 限制)
1243
+ // 商品券:需要拆分数量
1478
1244
  var discountNum = splitCount;
1479
1245
  var normalNum = totalQuantity - discountNum;
1480
1246
 
1481
- // 生成有折扣的商品(每个拆分商品 num: 1)
1247
+ // 生成有折扣的商品(每张商品券对应 num: 1)
1482
1248
  for (var _i = 0; _i < discountNum; _i++) {
1483
- var _currentBundleDiscoun, _currentBundleDiscoun2;
1484
- // 商品券:每个拆分商品使用不同的商品券
1485
- // 折扣卡:所有拆分商品使用同一张折扣卡
1486
- var currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[_i] : selectedDiscountCard || applicableDiscounts[0];
1487
- usedDiscounts.set(currentBundleDiscount.id, true);
1488
- // 🔥 更新 product_id 使用计数
1489
- if ((currentBundleDiscount.tag || currentBundleDiscount.type) === 'good_pass') {
1490
- var _currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1491
- usedProductIdCounts.set(currentBundleDiscount.product_id, _currentCount + 1);
1492
- }
1493
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1494
- var bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
1495
- if (['discount_card', 'product_discount_card'].includes(bundleDiscountTypeForCount)) {
1496
- var currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1497
- usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
1498
- }
1249
+ var _selectedDiscount2$me;
1250
+ var _selectedDiscount2 = applicableDiscounts[_i];
1251
+ usedDiscounts.set(_selectedDiscount2.id, true);
1499
1252
 
1500
1253
  // 🔥 生成唯一的 _id
1501
1254
  var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
1502
-
1503
- // 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
1504
- var discountedPrice = getDiscountAmount(currentBundleDiscount, product.origin_total, product.origin_total);
1505
- var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1506
-
1507
- // 确定折扣类型
1508
- var bundleDiscountType = currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : currentBundleDiscount.tag;
1509
1255
  var _discountDetail = {
1510
- amount: bundleDiscountAmount,
1511
- type: bundleDiscountType,
1256
+ amount: product.origin_total,
1257
+ type: 'good_pass',
1512
1258
  discount: {
1513
- discount_card_type: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun = currentBundleDiscount.metadata) === null || _currentBundleDiscoun === void 0 ? void 0 : _currentBundleDiscoun.discount_card_type,
1514
- discount_calculation_mode: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun2 = currentBundleDiscount.metadata) === null || _currentBundleDiscoun2 === void 0 ? void 0 : _currentBundleDiscoun2.discount_calculation_mode,
1515
- fixed_amount: bundleDiscountAmount,
1516
- resource_id: currentBundleDiscount.id,
1517
- title: currentBundleDiscount.format_title,
1259
+ fixed_amount: product.origin_total,
1260
+ discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
1261
+ resource_id: _selectedDiscount2.id,
1262
+ title: _selectedDiscount2.format_title,
1518
1263
  original_amount: product.origin_total,
1519
- product_id: product.id,
1520
- percent: currentBundleDiscount.par_value,
1521
- discount_product_id: currentBundleDiscount.product_id
1264
+ product_id: product.id
1522
1265
  },
1523
1266
  metadata: {
1524
1267
  // 🔥 使用拆分后的唯一 _id
1525
1268
  custom_product_bundle_map_id: uniqueId,
1526
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1269
+ discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
1527
1270
  num: 1
1528
1271
  },
1529
- _num: 1,
1530
- config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
1272
+ _num: 1
1531
1273
  };
1532
1274
 
1533
1275
  // 记录实际应用的折扣
1534
- var _appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1276
+ var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
1535
1277
  _appliedProducts.push(_discountDetail);
1536
- appliedDiscountProducts.set(currentBundleDiscount.id, _appliedProducts);
1278
+ appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
1537
1279
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1538
1280
  // 🔥 使用唯一的 _id
1539
1281
  _id: uniqueId,
1540
1282
  num: 1,
1541
1283
  quantity: 1,
1542
- price: discountedPrice,
1543
- // 折扣后的价格
1544
- total: discountedPrice,
1284
+ price: 0,
1285
+ // 商品券价格为0
1286
+ total: 0,
1545
1287
  discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail]),
1546
1288
  processed: true,
1547
- _discountId: currentBundleDiscount.id
1289
+ _discountId: _selectedDiscount2.id
1548
1290
  }));
1549
1291
  }
1550
1292
 
1551
- // 🔥 对拆分后的剩余商品继续匹配其他可用折扣(而不是等到下次执行才应用)
1552
- var remainingNum = normalNum;
1553
- var continueSplitIndex = discountNum;
1554
- while (remainingNum > 0) {
1555
- var _nextSelectedDiscount;
1556
- // 重新查找适用于剩余商品的可用折扣(已使用的会被自动过滤掉)
1557
- var nextApplicableDiscounts = sortedDiscountList.filter(function (nextDiscount) {
1558
- var _product$discount_lis10;
1559
- var nextDiscountType = nextDiscount.tag || nextDiscount.type;
1560
- // 检查策略可用性
1561
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1562
- var _nextDiscount$config;
1563
- if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
1564
- return false;
1565
- }
1566
- }
1567
- // 折扣卡时总价为0时不可用
1568
- if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.find(function (n) {
1569
- var _n$discount2;
1570
- return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
1571
- })) && nextDiscountType !== 'good_pass') return false;
1572
-
1573
- // 商品券已被使用则跳过
1574
- if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
1575
-
1576
- // 检查 maxUsagePerOrder 限制
1577
- if (nextDiscountType === 'good_pass') {
1578
- var _nextDiscount$config2;
1579
- var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
1580
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1581
- var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1582
- if (currentUsedCount >= maxUsagePerOrder) {
1583
- return false;
1584
- }
1585
- }
1586
- }
1587
-
1588
- // 检查折扣卡的 applicableProductLimit 限制
1589
- if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1590
- var _nextDiscount$config3;
1591
- var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
1592
- if (limitConfig > 0) {
1593
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1594
- if (currentUsedLimitCount >= limitConfig) {
1595
- return false;
1596
- }
1597
- }
1598
- }
1599
- var limitedData = nextDiscount.limited_relation_product_data;
1600
- if (limitedData.type === 'product_all') {
1601
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1602
- return false;
1603
- }
1604
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1605
- return false;
1606
- }
1607
- return true;
1608
- } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1609
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1610
- return false;
1611
- }
1612
- return true;
1613
- }
1614
- return false;
1615
- });
1616
-
1617
- // 没有更多可用折扣,剩余商品无折扣存储
1618
- if (nextApplicableDiscounts.length === 0) {
1619
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1620
- _id: "".concat(flatItem._id, "_split_rest"),
1621
- num: remainingNum,
1622
- quantity: remainingNum,
1623
- discount_list: [],
1624
- processed: true
1625
- }));
1626
- break;
1627
- }
1628
-
1629
- // 选择最优折扣
1630
- var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
1631
- return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1632
- });
1633
- var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1634
-
1635
- // 判断新折扣是否需要拆分
1636
- var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1637
- var nextIsGoodPass = nextDiscType === 'good_pass';
1638
- var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
1639
- var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
1640
- var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1641
- if (!nextIsNeedSplit) {
1642
- var _nextBundleDiscount$m, _flatItem$parentProdu9;
1643
- // 🔥 不需要拆分:直接应用折扣到所有剩余商品
1644
- var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1645
- usedDiscounts.set(nextBundleDiscount.id, true);
1646
- if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
1647
- var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1648
- usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1649
- }
1650
- var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1651
- if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
1652
- var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1653
- usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
1654
- }
1655
- var nextOriginTotal = product.original_price || product.price || 0;
1656
- var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1657
- var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
1658
- var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1659
- var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
1660
- var nextDiscountDetail = {
1661
- amount: nextDiscountAmount * remainingNum,
1662
- type: nextBundleDiscType,
1663
- discount: {
1664
- discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
1665
- fixed_amount: nextDiscountAmount,
1666
- resource_id: nextBundleDiscount.id,
1667
- title: nextBundleDiscount.format_title,
1668
- original_amount: product.original_price,
1669
- product_id: product.id,
1670
- percent: nextBundleDiscount.par_value,
1671
- discount_product_id: nextBundleDiscount.product_id
1672
- },
1673
- metadata: {
1674
- custom_product_bundle_map_id: nextUniqueId,
1675
- num: remainingNum
1676
- },
1677
- config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
1678
- _num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1679
- };
1680
- var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1681
- nextAppliedProducts.push(nextDiscountDetail);
1682
- appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1683
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1684
- _id: nextUniqueId,
1685
- num: remainingNum,
1686
- quantity: remainingNum,
1687
- total: nextTargetTotal,
1688
- price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1689
- discount_list: [nextDiscountDetail],
1690
- processed: true
1691
- }));
1692
- remainingNum = 0;
1693
- break;
1694
- }
1695
-
1696
- // 🔥 需要拆分:计算最大使用次数
1697
- var nextMaxUsageLimit = void 0;
1698
- if (nextIsGoodPass) {
1699
- var _nextSelectedDiscount2;
1700
- var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
1701
- return (item.tag || item.type) === 'good_pass';
1702
- }).length;
1703
- nextMaxUsageLimit = nextGoodPassCount;
1704
- if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
1705
- var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1706
- nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
1707
- }
1708
- } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1709
- var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1710
- nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
1711
- } else {
1712
- nextMaxUsageLimit = 1;
1713
- }
1714
- var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1715
- if (nextSplitCount === 0) {
1716
- // 已达使用上限,剩余商品无折扣存储
1717
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1718
- _id: "".concat(flatItem._id, "_split_rest"),
1719
- num: remainingNum,
1720
- quantity: remainingNum,
1721
- discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
1722
- processed: true
1723
- }));
1724
- break;
1725
- }
1726
-
1727
- // 生成有折扣的商品
1728
- for (var j = 0; j < nextSplitCount; j++) {
1729
- var _nextBundleDiscount$m2;
1730
- var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1731
- usedDiscounts.set(_nextBundleDiscount.id, true);
1732
- if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
1733
- var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
1734
- usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
1735
- }
1736
- var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
1737
- if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
1738
- var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
1739
- usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
1740
- }
1741
- var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1742
- var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
1743
- var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1744
- var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
1745
- var _nextDiscountDetail = {
1746
- amount: nextBundleDiscAmount,
1747
- type: nextBundleDiscTypeStr,
1748
- discount: {
1749
- discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
1750
- fixed_amount: nextBundleDiscAmount,
1751
- resource_id: _nextBundleDiscount.id,
1752
- title: _nextBundleDiscount.format_title,
1753
- original_amount: product.origin_total,
1754
- product_id: product.id,
1755
- percent: _nextBundleDiscount.par_value,
1756
- discount_product_id: _nextBundleDiscount.product_id
1757
- },
1758
- metadata: {
1759
- custom_product_bundle_map_id: _nextUniqueId,
1760
- num: 1
1761
- },
1762
- _num: 1,
1763
- config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
1764
- };
1765
- var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
1766
- _nextAppliedProducts.push(_nextDiscountDetail);
1767
- appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
1768
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1769
- _id: _nextUniqueId,
1770
- num: 1,
1771
- quantity: 1,
1772
- price: nextDiscountedPrice,
1773
- total: nextDiscountedPrice,
1774
- discount_list: [_nextDiscountDetail],
1775
- processed: true,
1776
- _discountId: _nextBundleDiscount.id
1777
- }));
1778
- continueSplitIndex++;
1779
- }
1780
- remainingNum -= nextSplitCount;
1293
+ // 生成无折扣的商品(剩余数量)
1294
+ if (normalNum > 0) {
1295
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1296
+ // 🔥 为剩余商品生成唯一的 _id
1297
+ _id: "".concat(flatItem._id, "_split_rest"),
1298
+ num: normalNum,
1299
+ quantity: normalNum,
1300
+ discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
1301
+ processed: true
1302
+ }));
1781
1303
  }
1782
1304
  } else {
1783
- var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu10;
1784
- // 不拆分:直接应用折扣
1785
- var _currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1786
- usedDiscounts.set(_currentBundleDiscount.id, true);
1787
- // 🔥 更新 product_id 使用计数
1788
- if ((_currentBundleDiscount.tag || _currentBundleDiscount.type) === 'good_pass') {
1789
- var _currentCount2 = usedProductIdCounts.get(_currentBundleDiscount.product_id) || 0;
1790
- usedProductIdCounts.set(_currentBundleDiscount.product_id, _currentCount2 + 1);
1791
- }
1792
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(不拆分时按商品数量计数)
1793
- var noSplitDiscountType = _currentBundleDiscount.tag || _currentBundleDiscount.type;
1794
- if (['discount_card', 'product_discount_card'].includes(noSplitDiscountType)) {
1795
- var bundleQuantity = product.num || 1;
1796
- var currentNoSplitCount = usedDiscountCardLimitCounts.get(_currentBundleDiscount.id) || 0;
1797
- usedDiscountCardLimitCounts.set(_currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
1798
- }
1305
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
1306
+ // 折扣卡:不拆分数量,直接应用
1307
+ var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1308
+ usedDiscounts.set(_selectedDiscount3.id, true);
1799
1309
  var _productOriginTotal = product.original_price || product.price || 0;
1800
1310
 
1801
1311
  // 🔥 检查是否是 order_level 固定金额折扣卡
1802
- var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1803
- var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1312
+ var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
1313
+ var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
1804
1314
  var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
1805
- var targetProductTotal;
1315
+ var _targetProductTotal;
1806
1316
  var fixedAmountPerItem;
1807
1317
  var _productDiscountDifference;
1808
1318
  if (_isOrderLevel && _productAllocation) {
1809
1319
  // order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
1810
1320
  fixedAmountPerItem = _productAllocation.discountAmount;
1811
1321
  _productDiscountDifference = _productAllocation.difference;
1812
- targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1322
+ _targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1813
1323
  } else {
1814
1324
  // item_level 或其他类型:使用原有逻辑
1815
- targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
1816
- fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
1325
+ _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1326
+ fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1817
1327
  }
1818
1328
 
1819
- // 计算实际折扣金额
1820
- var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
1821
-
1822
1329
  // 🔥 使用当前的 _id 作为唯一标识
1823
1330
  var _uniqueId = flatItem._id;
1824
1331
  var _discountDetail2 = {
1825
- amount: bundleActualDiscountAmount * (product.num || 1),
1826
- type: _currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _currentBundleDiscount.tag,
1332
+ amount: fixedAmountPerItem * (product.num || 1),
1333
+ type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
1827
1334
  discount: {
1828
- discount_card_type: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun3 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun3 === void 0 ? void 0 : _currentBundleDiscoun3.discount_card_type,
1829
- fixed_amount: bundleActualDiscountAmount,
1830
- discount_calculation_mode: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun4 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun4 === void 0 ? void 0 : _currentBundleDiscoun4.discount_calculation_mode,
1831
- resource_id: _currentBundleDiscount.id,
1832
- title: _currentBundleDiscount.format_title,
1335
+ discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
1336
+ fixed_amount: fixedAmountPerItem,
1337
+ discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
1338
+ resource_id: _selectedDiscount3.id,
1339
+ title: _selectedDiscount3.format_title,
1833
1340
  original_amount: product.original_price,
1834
1341
  product_id: product.id,
1835
- percent: _currentBundleDiscount.par_value,
1836
- discount_product_id: _currentBundleDiscount.product_id
1342
+ percent: _selectedDiscount3.par_value
1837
1343
  },
1838
1344
  metadata: _objectSpread({
1839
1345
  // 🔥 使用唯一的 _id
1840
1346
  custom_product_bundle_map_id: _uniqueId,
1841
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1347
+ discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
1842
1348
  num: product.num || 1
1843
1349
  }, _productDiscountDifference !== undefined && {
1844
1350
  product_discount_difference: _productDiscountDifference
1845
1351
  }),
1846
- config: _currentBundleDiscount === null || _currentBundleDiscount === void 0 ? void 0 : _currentBundleDiscount.config,
1847
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.num) || 1)
1352
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1848
1353
  };
1849
1354
 
1850
1355
  // 记录实际应用的折扣
1851
- var _appliedProducts2 = appliedDiscountProducts.get(_currentBundleDiscount.id) || [];
1356
+ var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
1852
1357
  _appliedProducts2.push(_discountDetail2);
1853
- appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
1358
+ appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
1854
1359
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1855
- total: targetProductTotal,
1360
+ total: _targetProductTotal,
1856
1361
  price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
1857
1362
  discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
1858
1363
  processed: true
@@ -1871,9 +1376,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1871
1376
  // 获取主商品处理结果
1872
1377
  var mainProductArr = processedProductsMap.get(product._id);
1873
1378
  if (!mainProductArr || mainProductArr.length === 0) {
1874
- // 如果没有处理结果,返回默认商品(还原 option 价格)
1379
+ // 如果没有处理结果,返回默认商品
1875
1380
  var getDefaultProduct = function getDefaultProduct() {
1876
- var restoredOptions = restoreOptionPrices(product.options);
1877
1381
  if (product.isClient) {
1878
1382
  return _this3.hooks.setProduct(originProduct, {
1879
1383
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
@@ -1883,7 +1387,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1883
1387
  original_price: product.original_price
1884
1388
  },
1885
1389
  bundle: product.bundle,
1886
- options: restoredOptions
1390
+ options: product.options
1887
1391
  }),
1888
1392
  variant: originProduct._productInit.variant,
1889
1393
  original_price: originProduct._productInit.original_price,
@@ -1892,17 +1396,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1892
1396
  price: product.price
1893
1397
  },
1894
1398
  bundle: product.bundle,
1895
- options: restoredOptions
1896
- }),
1897
- options: restoredOptions
1399
+ options: product.options
1400
+ })
1898
1401
  });
1899
1402
  } else {
1900
1403
  return _this3.hooks.setProduct(originProduct, {
1901
1404
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1902
1405
  total: product.total,
1903
1406
  origin_total: product.origin_total,
1904
- price: product.price,
1905
- options: restoreOptionPrices(product.options)
1407
+ price: product.price
1906
1408
  });
1907
1409
  }
1908
1410
  };
@@ -1978,7 +1480,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1978
1480
  product_id: bundleItem.product_id,
1979
1481
  price: item.price,
1980
1482
  num: item.num,
1981
- quantity: item.num,
1982
1483
  discount_list: updatedDiscountList
1983
1484
  }));
1984
1485
  });
@@ -2002,7 +1503,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2002
1503
  product_id: bundleItem.product_id,
2003
1504
  price: item.price,
2004
1505
  num: item.num,
2005
- quantity: item.num,
2006
1506
  discount_list: _updatedDiscountList
2007
1507
  }));
2008
1508
  } else {
@@ -2017,8 +1517,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2017
1517
 
2018
1518
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
2019
1519
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
2020
- var _discount$metadata7, _discount$metadata8;
2021
- if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
1520
+ var _discount$metadata6, _discount$metadata7;
1521
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
2022
1522
  // bundle的discount_list保持不变
2023
1523
  return discount;
2024
1524
  }
@@ -2026,7 +1526,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2026
1526
  return _objectSpread(_objectSpread({}, discount), {}, {
2027
1527
  // num: 1,
2028
1528
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2029
- 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,
1529
+ 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,
2030
1530
  num: 1
2031
1531
  })
2032
1532
  });
@@ -2071,8 +1571,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2071
1571
  quantity: 1,
2072
1572
  discount_list: updatedMainDiscountList,
2073
1573
  bundle: newBundleWithDiscount,
2074
- total: newTotalWithDiscount,
2075
- origin_total: newOriginTotalWithDiscount
1574
+ total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
1575
+ origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
2076
1576
  })));
2077
1577
 
2078
1578
  // 第二个:包含原始bundle (qty=原quantity-1)
@@ -2091,8 +1591,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2091
1591
 
2092
1592
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
2093
1593
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
2094
- var _discount$metadata9, _discount$metadata10;
2095
- if (discount !== null && discount !== void 0 && (_discount$metadata9 = discount.metadata) !== null && _discount$metadata9 !== void 0 && _discount$metadata9.custom_product_bundle_map_id) {
1594
+ var _discount$metadata8, _discount$metadata9;
1595
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
2096
1596
  // bundle的discount_list保持不变
2097
1597
  return discount;
2098
1598
  }
@@ -2100,7 +1600,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2100
1600
  return _objectSpread(_objectSpread({}, discount), {}, {
2101
1601
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2102
1602
  num: mainProductQuantity - 1,
2103
- 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
1603
+ 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
2104
1604
  })
2105
1605
  // num: mainProductQuantity - 1,
2106
1606
  });
@@ -2167,11 +1667,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2167
1667
  processedBundleItems.forEach(function (item) {
2168
1668
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
2169
1669
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
2170
- var _discount$metadata11;
1670
+ var _discount$metadata10;
2171
1671
  return _objectSpread(_objectSpread({}, discount), {}, {
2172
1672
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2173
1673
  num: item.num,
2174
- 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
1674
+ 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
2175
1675
  })
2176
1676
  // num: item.num, // 使用拆分后的 num
2177
1677
  });
@@ -2181,9 +1681,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2181
1681
  product_id: bundleItem.product_id,
2182
1682
  price: item.price,
2183
1683
  num: item.num,
2184
- quantity: item.num,
2185
- discount_list: updatedDiscountList,
2186
- bundle_selling_price: bundleItem.bundle_selling_price !== undefined ? item.price : undefined
1684
+ discount_list: updatedDiscountList
2187
1685
  }));
2188
1686
  });
2189
1687
  }
@@ -2222,8 +1720,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2222
1720
  // 累加bundle的价格(只累加一次)
2223
1721
  if (newBundle.length > 0) {
2224
1722
  newBundle.forEach(function (item) {
2225
- var _item$discount_list3;
2226
1723
  newTotal += Number(item.price) * Number(item.num);
1724
+ });
1725
+
1726
+ // 计算原始总价(不考虑折扣)
1727
+ newBundle.forEach(function (item) {
1728
+ var _item$discount_list3;
2227
1729
  var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
2228
1730
  newOriginTotal += Number(originalPrice) * Number(item.num);
2229
1731
  });
@@ -2238,6 +1740,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2238
1740
  return accumulator.add(currentPrice.mul(currentNum));
2239
1741
  }, new Decimal(newTotal)).toNumber();
2240
1742
  }
1743
+ newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1744
+ newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
2241
1745
 
2242
1746
  // 生成最终的主商品
2243
1747
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
@@ -2345,14 +1849,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2345
1849
  var ruleType = usageRules.type;
2346
1850
  // 套餐适用范围配置
2347
1851
  var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
2348
- var _ref14 = packageScope || {},
2349
- scopeType = _ref14.type,
2350
- _ref14$exclude_bundle = _ref14.exclude_bundle_product_ids,
2351
- exclude_bundle_product_ids = _ref14$exclude_bundle === void 0 ? [] : _ref14$exclude_bundle,
2352
- _ref14$include_bundle = _ref14.include_bundle_product_ids,
2353
- include_bundle_product_ids = _ref14$include_bundle === void 0 ? [] : _ref14$include_bundle,
2354
- _ref14$filter = _ref14.filter,
2355
- filter = _ref14$filter === void 0 ? 0 : _ref14$filter;
1852
+ var _ref9 = packageScope || {},
1853
+ scopeType = _ref9.type,
1854
+ _ref9$exclude_bundle_ = _ref9.exclude_bundle_product_ids,
1855
+ exclude_bundle_product_ids = _ref9$exclude_bundle_ === void 0 ? [] : _ref9$exclude_bundle_,
1856
+ _ref9$include_bundle_ = _ref9.include_bundle_product_ids,
1857
+ include_bundle_product_ids = _ref9$include_bundle_ === void 0 ? [] : _ref9$include_bundle_,
1858
+ _ref9$filter = _ref9.filter,
1859
+ filter = _ref9$filter === void 0 ? 0 : _ref9$filter;
2356
1860
  var isMainProduct = flatItem.type === 'main'; // 单独购买
2357
1861
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
2358
1862
 
@@ -2367,12 +1871,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2367
1871
  return true; // 单独购买时可用
2368
1872
  }
2369
1873
  if (isBundleItem) {
2370
- var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$parentProdu11;
1874
+ var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$parentProdu10;
2371
1875
  // 套餐中购买时,判断是否为原价
2372
1876
  var priceType = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type;
2373
1877
  var priceTypeExt = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type_ext;
2374
1878
  // 主商品id
2375
- var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$parentProdu11 = flatItem.parentProduct) === null || _flatItem$parentProdu11 === void 0 ? void 0 : _flatItem$parentProdu11.id) || 0;
1879
+ var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.id) || 0;
2376
1880
  // original_price 对应:
2377
1881
  // 1. price_type: "markup" && price_type_ext: "product_price"
2378
1882
  // markup_price 对应: