@pisell/pisellos 2.1.170 → 2.1.172

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 (231) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -3
  3. package/dist/model/strategy/adapter/index.d.ts +0 -4
  4. package/dist/model/strategy/adapter/index.js +1 -5
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  7. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  8. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  9. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  10. package/dist/model/strategy/engine.d.ts +18 -5
  11. package/dist/model/strategy/engine.js +145 -45
  12. package/dist/model/strategy/type.d.ts +17 -0
  13. package/dist/model/strategy/type.js +4 -0
  14. package/dist/modules/Cart/types.d.ts +2 -0
  15. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  16. package/dist/modules/Cart/utils/changePrice.js +9 -16
  17. package/dist/modules/Discount/index.d.ts +4 -13
  18. package/dist/modules/Discount/index.js +12 -124
  19. package/dist/modules/Discount/types.d.ts +18 -13
  20. package/dist/modules/Order/index.d.ts +1 -67
  21. package/dist/modules/Order/index.js +30 -918
  22. package/dist/modules/Order/types.d.ts +12 -176
  23. package/dist/modules/Order/types.js +0 -2
  24. package/dist/modules/Order/utils.d.ts +0 -118
  25. package/dist/modules/Order/utils.js +2 -586
  26. package/dist/modules/Payment/index.d.ts +2 -1
  27. package/dist/modules/Payment/index.js +10 -7
  28. package/dist/modules/Payment/utils.js +3 -0
  29. package/dist/modules/Payment/walletpass.d.ts +23 -0
  30. package/dist/modules/Payment/walletpass.js +191 -95
  31. package/dist/modules/Product/utils.js +2 -2
  32. package/dist/modules/ProductList/index.d.ts +2 -4
  33. package/dist/modules/ProductList/index.js +12 -24
  34. package/dist/modules/Rules/index.d.ts +9 -5
  35. package/dist/modules/Rules/index.js +669 -173
  36. package/dist/modules/Rules/types.d.ts +2 -0
  37. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -16
  38. package/dist/modules/Schedule/utils.d.ts +1 -1
  39. package/dist/modules/Summary/types.d.ts +2 -0
  40. package/dist/modules/Summary/utils.d.ts +9 -3
  41. package/dist/modules/Summary/utils.js +57 -67
  42. package/dist/modules/index.d.ts +0 -4
  43. package/dist/modules/index.js +1 -5
  44. package/dist/plugins/window.d.ts +2 -0
  45. package/dist/solution/BookingByStep/index.d.ts +3 -2
  46. package/dist/solution/BookingByStep/index.js +43 -46
  47. package/dist/solution/BookingByStep/types.d.ts +1 -3
  48. package/dist/solution/BookingByStep/types.js +1 -5
  49. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  50. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  51. package/dist/solution/Checkout/index.js +2 -0
  52. package/dist/solution/ShopDiscount/index.d.ts +2 -3
  53. package/dist/solution/ShopDiscount/index.js +60 -62
  54. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  55. package/dist/solution/ShopDiscount/types.js +2 -1
  56. package/dist/solution/ShopDiscount/utils.js +26 -12
  57. package/dist/solution/index.d.ts +0 -2
  58. package/dist/solution/index.js +1 -3
  59. package/lib/index.d.ts +1 -1
  60. package/lib/index.js +3 -4
  61. package/lib/model/strategy/adapter/index.d.ts +0 -4
  62. package/lib/model/strategy/adapter/index.js +2 -13
  63. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  64. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  65. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  66. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  67. package/lib/model/strategy/engine.d.ts +18 -5
  68. package/lib/model/strategy/engine.js +85 -21
  69. package/lib/model/strategy/type.d.ts +17 -0
  70. package/lib/modules/Cart/types.d.ts +2 -0
  71. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  72. package/lib/modules/Cart/utils/changePrice.js +9 -13
  73. package/lib/modules/Discount/index.d.ts +4 -13
  74. package/lib/modules/Discount/index.js +5 -76
  75. package/lib/modules/Discount/types.d.ts +18 -13
  76. package/lib/modules/Order/index.d.ts +1 -67
  77. package/lib/modules/Order/index.js +1 -525
  78. package/lib/modules/Order/types.d.ts +12 -176
  79. package/lib/modules/Order/utils.d.ts +0 -118
  80. package/lib/modules/Order/utils.js +2 -483
  81. package/lib/modules/Payment/index.d.ts +2 -1
  82. package/lib/modules/Payment/index.js +1 -0
  83. package/lib/modules/Payment/utils.js +3 -0
  84. package/lib/modules/Payment/walletpass.d.ts +23 -0
  85. package/lib/modules/Payment/walletpass.js +94 -17
  86. package/lib/modules/Product/utils.js +2 -2
  87. package/lib/modules/ProductList/index.d.ts +2 -4
  88. package/lib/modules/ProductList/index.js +39 -46
  89. package/lib/modules/Rules/index.d.ts +9 -5
  90. package/lib/modules/Rules/index.js +776 -292
  91. package/lib/modules/Rules/types.d.ts +2 -0
  92. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -13
  93. package/lib/modules/Schedule/utils.d.ts +1 -1
  94. package/lib/modules/Summary/types.d.ts +2 -0
  95. package/lib/modules/Summary/utils.d.ts +9 -3
  96. package/lib/modules/Summary/utils.js +34 -45
  97. package/lib/modules/index.d.ts +0 -4
  98. package/lib/modules/index.js +1 -9
  99. package/lib/plugins/window.d.ts +2 -0
  100. package/lib/solution/BookingByStep/index.d.ts +3 -2
  101. package/lib/solution/BookingByStep/index.js +4 -6
  102. package/lib/solution/BookingByStep/types.d.ts +1 -3
  103. package/lib/solution/BookingByStep/types.js +0 -10
  104. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  105. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  106. package/lib/solution/Checkout/index.js +2 -0
  107. package/lib/solution/ShopDiscount/index.d.ts +2 -3
  108. package/lib/solution/ShopDiscount/index.js +27 -22
  109. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  110. package/lib/solution/ShopDiscount/utils.js +10 -6
  111. package/lib/solution/index.d.ts +0 -2
  112. package/lib/solution/index.js +1 -5
  113. package/package.json +2 -2
  114. package/dist/apis/picoding.d.ts +0 -0
  115. package/dist/apis/picoding.js +0 -1
  116. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  117. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  118. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  119. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -867
  120. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  121. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  122. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  123. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  124. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -149
  125. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  126. package/dist/modules/OpenData/index.d.ts +0 -24
  127. package/dist/modules/OpenData/index.js +0 -173
  128. package/dist/modules/OpenData/types.d.ts +0 -73
  129. package/dist/modules/OpenData/types.js +0 -1
  130. package/dist/modules/OpenData/utils.d.ts +0 -2
  131. package/dist/modules/OpenData/utils.js +0 -75
  132. package/dist/modules/Quotation/index.d.ts +0 -48
  133. package/dist/modules/Quotation/index.js +0 -248
  134. package/dist/modules/Quotation/types.d.ts +0 -42
  135. package/dist/modules/Quotation/types.js +0 -1
  136. package/dist/modules/SalesSummary/index.d.ts +0 -63
  137. package/dist/modules/SalesSummary/index.js +0 -174
  138. package/dist/modules/SalesSummary/types.d.ts +0 -60
  139. package/dist/modules/SalesSummary/types.js +0 -1
  140. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  141. package/dist/modules/SalesSummary/utils.js +0 -480
  142. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  143. package/dist/modules/ScanOrderLogger/index.js +0 -174
  144. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  145. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  146. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  147. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  148. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  149. package/dist/modules/ScanOrderLogger/types.js +0 -1
  150. package/dist/solution/ScanOrder/index.d.ts +0 -158
  151. package/dist/solution/ScanOrder/index.js +0 -3474
  152. package/dist/solution/ScanOrder/types.d.ts +0 -306
  153. package/dist/solution/ScanOrder/types.js +0 -35
  154. package/dist/solution/ScanOrder/utils.d.ts +0 -172
  155. package/dist/solution/ScanOrder/utils.js +0 -796
  156. package/dist/solution/VenueBooking/index.d.ts +0 -252
  157. package/dist/solution/VenueBooking/index.js +0 -3769
  158. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  159. package/dist/solution/VenueBooking/types.d.ts +0 -156
  160. package/dist/solution/VenueBooking/types.js +0 -22
  161. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  162. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -91
  163. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  164. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  165. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  166. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -233
  167. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -71
  168. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -302
  169. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  170. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -458
  171. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  172. package/dist/solution/VenueBooking/utils.js +0 -1
  173. package/lib/apis/picoding.d.ts +0 -0
  174. package/lib/apis/picoding.js +0 -0
  175. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  176. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  177. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  178. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -666
  179. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  180. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  181. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  182. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  183. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -149
  184. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  185. package/lib/modules/OpenData/index.d.ts +0 -24
  186. package/lib/modules/OpenData/index.js +0 -119
  187. package/lib/modules/OpenData/types.d.ts +0 -73
  188. package/lib/modules/OpenData/types.js +0 -17
  189. package/lib/modules/OpenData/utils.d.ts +0 -2
  190. package/lib/modules/OpenData/utils.js +0 -111
  191. package/lib/modules/Quotation/index.d.ts +0 -48
  192. package/lib/modules/Quotation/index.js +0 -152
  193. package/lib/modules/Quotation/types.d.ts +0 -42
  194. package/lib/modules/Quotation/types.js +0 -17
  195. package/lib/modules/SalesSummary/index.d.ts +0 -63
  196. package/lib/modules/SalesSummary/index.js +0 -105
  197. package/lib/modules/SalesSummary/types.d.ts +0 -60
  198. package/lib/modules/SalesSummary/types.js +0 -17
  199. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  200. package/lib/modules/SalesSummary/utils.js +0 -420
  201. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  202. package/lib/modules/ScanOrderLogger/index.js +0 -147
  203. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  204. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  205. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  206. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  207. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  208. package/lib/modules/ScanOrderLogger/types.js +0 -17
  209. package/lib/solution/ScanOrder/index.d.ts +0 -158
  210. package/lib/solution/ScanOrder/index.js +0 -2135
  211. package/lib/solution/ScanOrder/types.d.ts +0 -306
  212. package/lib/solution/ScanOrder/types.js +0 -36
  213. package/lib/solution/ScanOrder/utils.d.ts +0 -172
  214. package/lib/solution/ScanOrder/utils.js +0 -658
  215. package/lib/solution/VenueBooking/index.d.ts +0 -252
  216. package/lib/solution/VenueBooking/index.js +0 -2204
  217. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  218. package/lib/solution/VenueBooking/types.d.ts +0 -156
  219. package/lib/solution/VenueBooking/types.js +0 -45
  220. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  221. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -105
  222. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  223. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  224. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  225. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -236
  226. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -71
  227. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -225
  228. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  229. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -343
  230. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  231. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -50,6 +50,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
50
50
  this.core = core;
51
51
  this.hooks = options == null ? void 0 : options.hooks;
52
52
  this.store = options == null ? void 0 : options.store;
53
+ this.window = core.getPlugin("window");
53
54
  }
54
55
  async setRulesList(rulesList) {
55
56
  this.store.rulesList = rulesList;
@@ -71,11 +72,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
71
72
  return false;
72
73
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
73
74
  }
75
+ getWalletPassEvaluator() {
76
+ var _a, _b;
77
+ return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
78
+ }
74
79
  // 判断discountList 是否可以对当前productList生效
75
80
  isDiscountListAvailable({
76
81
  oldDiscountList,
77
82
  newDiscountList,
78
83
  productList,
84
+ orderTotalAmount,
79
85
  holders,
80
86
  isFormSubject
81
87
  }) {
@@ -108,6 +114,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
108
114
  const result = this.calcDiscount({
109
115
  discountList: mergedDiscountList,
110
116
  productList: [...productList],
117
+ orderTotalAmount,
111
118
  holders,
112
119
  isFormSubject
113
120
  }, {
@@ -183,7 +190,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
183
190
  discountList,
184
191
  productList,
185
192
  holders,
186
- isFormSubject
193
+ isFormSubject,
194
+ orderTotalAmount
187
195
  }, options) {
188
196
  const editModeDiscount = [];
189
197
  const addModeDiscount = [];
@@ -362,12 +370,63 @@ var RulesModule = class extends import_BaseModule.BaseModule {
362
370
  }
363
371
  return priceB.minus(priceA).toNumber();
364
372
  });
365
- const isProductIncludedByLimitedData = (limitedData, productId) => {
366
- const excludedIds = (limitedData == null ? void 0 : limitedData.exclude_product_ids) || [];
367
- const isExcluded = (limitedData == null ? void 0 : limitedData.filter) === 1 && excludedIds.some((id) => String(id) === String(productId));
368
- return !isExcluded;
369
- };
373
+ const evaluator = this.getWalletPassEvaluator();
374
+ if (evaluator) {
375
+ addModeDiscount.forEach((discount) => {
376
+ var _a, _b;
377
+ const discountType = discount.tag || discount.type;
378
+ if (["good_pass", "discount_card", "product_discount_card"].includes(
379
+ discountType
380
+ )) {
381
+ const voucher = {
382
+ id: discount.id,
383
+ amount: Number(discount.par_value || 0),
384
+ balance: Number(discount.balance || 0),
385
+ type: discountType,
386
+ product_id: discount.product_id,
387
+ unified_available_status: 1,
388
+ available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
389
+ available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
390
+ };
391
+ const productsForEvaluate = sortedFlattenedList.map((item) => {
392
+ var _a2;
393
+ return {
394
+ product_id: item.id,
395
+ price: item.price || 0,
396
+ quantity: item.quantity || item.num || 1,
397
+ selling_price: item.price || 0,
398
+ product_options: item.type === "main" ? (_a2 = item.product) == null ? void 0 : _a2.options : void 0
399
+ };
400
+ });
401
+ const result = evaluator.checkVoucherAvailability({
402
+ orderTotalAmount,
403
+ products: productsForEvaluate,
404
+ vouchers: [voucher]
405
+ });
406
+ if (result.isAvailable) {
407
+ discount.config = {
408
+ ...result.config,
409
+ isAvailable: true
410
+ };
411
+ } else {
412
+ discount.config = {
413
+ isAvailable: false
414
+ };
415
+ }
416
+ }
417
+ });
418
+ }
370
419
  const usedDiscounts = /* @__PURE__ */ new Map();
420
+ const usedProductIdCounts = /* @__PURE__ */ new Map();
421
+ const usedDiscountCardLimitCounts = /* @__PURE__ */ new Map();
422
+ editModeDiscount.forEach((discount) => {
423
+ var _a;
424
+ const discountType = discount.tag || discount.type;
425
+ if (["discount_card", "product_discount_card"].includes(discountType)) {
426
+ const currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
427
+ usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_a = discount.metadata) == null ? void 0 : _a.num) || 1));
428
+ }
429
+ });
371
430
  const discountApplicability = /* @__PURE__ */ new Map();
372
431
  const discountApplicableProducts = /* @__PURE__ */ new Map();
373
432
  addModeDiscount.forEach((discount) => {
@@ -507,6 +566,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
507
566
  originProduct = flatItem.originProduct;
508
567
  } else {
509
568
  product = {
569
+ startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
510
570
  _id: flatItem._id,
511
571
  id: flatItem.id,
512
572
  price: flatItem.price,
@@ -515,13 +575,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
515
575
  total: flatItem.total,
516
576
  origin_total: flatItem.origin_total,
517
577
  booking_id: flatItem.booking_id,
518
- discount_list: flatItem.discount_list || [],
519
- startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
578
+ discount_list: flatItem.discount_list || []
520
579
  };
521
580
  originProduct = flatItem.originProduct;
522
581
  }
523
582
  addModeDiscount.forEach((discount) => {
524
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
583
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
525
584
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
526
585
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
527
586
  const isHolderMatch = this.checkHolderMatch(
@@ -534,7 +593,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
534
593
  );
535
594
  let timeLimit = true;
536
595
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
537
- const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
596
+ const 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;
538
597
  const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a2 = product == null ? void 0 : product.discount_list) == null ? void 0 : _a2.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
539
598
  (discount2) => discount2.id && [
540
599
  "good_pass",
@@ -543,8 +602,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
543
602
  ].includes(discount2.tag || discount2.type)
544
603
  ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
545
604
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
546
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
547
- (_g = discountApplicability.get(discount.id)) == null ? void 0 : _g.push(product.id);
605
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_g = discount.config) == null ? void 0 : _g.isAvailable)) {
606
+ (_h = discountApplicability.get(discount.id)) == null ? void 0 : _h.push(product.id);
548
607
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
549
608
  const discountType = discount.tag || discount.type;
550
609
  const isGoodPass = discountType === "good_pass";
@@ -554,14 +613,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
554
613
  type: discountType,
555
614
  tag: discountType,
556
615
  discount: {
557
- discount_card_type: (_h = discount == null ? void 0 : discount.metadata) == null ? void 0 : _h.discount_card_type,
616
+ discount_card_type: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_card_type,
558
617
  fixed_amount: product.price,
559
- discount_calculation_mode: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_calculation_mode,
618
+ discount_calculation_mode: (_j = discount == null ? void 0 : discount.metadata) == null ? void 0 : _j.discount_calculation_mode,
560
619
  resource_id: discount.id,
561
620
  title: discount.format_title,
562
621
  original_amount: product.price || product.origin_total,
563
622
  pre_value: discount.par_value,
564
- product_id: originProduct.id
623
+ product_id: originProduct.id,
624
+ discount_product_id: discount.product_id
565
625
  },
566
626
  metadata: {
567
627
  num,
@@ -574,44 +634,102 @@ var RulesModule = class extends import_BaseModule.BaseModule {
574
634
  });
575
635
  });
576
636
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
637
+ const applyDiscountToOptions = (options2, discount) => {
638
+ if (!(options2 == null ? void 0 : options2.length))
639
+ return { discountedOptions: options2, optionDiscountAmount: 0 };
640
+ let optionDiscountAmount = 0;
641
+ const discountedOptions = options2.map((option) => {
642
+ const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
643
+ const baseUnitNum = Number(rawUnit ?? 0);
644
+ if (baseUnitNum <= 0)
645
+ return option;
646
+ const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
647
+ const optQty = Number(option.num ?? option.quantity ?? 1);
648
+ optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
649
+ const { _original_add_price, ...rest } = option;
650
+ const tmpl = rest.price ?? rest.add_price;
651
+ const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
652
+ return {
653
+ ...rest,
654
+ _original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
655
+ price: nextPrice
656
+ };
657
+ });
658
+ return { discountedOptions, optionDiscountAmount };
659
+ };
660
+ const restoreOptionPrices = (options2) => {
661
+ if (!(options2 == null ? void 0 : options2.length))
662
+ return options2;
663
+ return options2.map((option) => {
664
+ const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
665
+ if (orig !== void 0) {
666
+ const { _original_price, _original_add_price, ...rest } = option;
667
+ return { ...rest, price: orig };
668
+ }
669
+ return option;
670
+ });
671
+ };
672
+ const getOptionTotal = (options2) => {
673
+ if (!(options2 == null ? void 0 : options2.length))
674
+ return 0;
675
+ return options2.reduce((sum, opt) => {
676
+ const unit = Number(opt.price ?? opt.add_price ?? 0);
677
+ const n = Number(opt.num ?? opt.quantity ?? 1);
678
+ return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
679
+ }, 0);
680
+ };
577
681
  sortedFlattenedList.forEach((flatItem, index) => {
578
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
682
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
579
683
  let product, originProduct;
580
684
  if (flatItem.type === "main") {
581
685
  product = flatItem.product;
582
686
  originProduct = flatItem.originProduct;
583
687
  } else {
584
688
  product = {
689
+ startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
585
690
  _id: flatItem._id,
586
691
  id: flatItem.id,
587
692
  price: flatItem.price,
588
693
  quantity: flatItem.quantity,
589
694
  num: flatItem.num,
590
695
  total: flatItem.total,
591
- original_price: (_a = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _a.original_price,
592
- origin_total: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
696
+ original_price: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
697
+ origin_total: (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.original_price,
593
698
  booking_id: flatItem.booking_id,
594
- discount_list: ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) || [],
595
- startDate: (_d = flatItem.parentProduct) == null ? void 0 : _d.startDate
699
+ discount_list: ((_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.discount_list) || []
596
700
  };
597
701
  originProduct = flatItem.originProduct;
598
702
  }
599
- if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
703
+ if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every(
704
+ (discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
705
+ discount.tag || discount.type
706
+ )
707
+ ))) {
600
708
  if (flatItem.type === "main") {
601
709
  processedProductsMap.set(product._id, [originProduct]);
602
710
  } else {
603
- processedFlatItemsMap.set(flatItem._id, [{
604
- ...flatItem,
605
- processed: true
606
- }]);
711
+ processedFlatItemsMap.set(flatItem._id, [
712
+ {
713
+ ...flatItem,
714
+ processed: true
715
+ }
716
+ ]);
607
717
  }
608
718
  return;
609
719
  }
610
720
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
611
- var _a2, _b2;
612
- if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.length) && (discount.tag || discount.type) === "good_pass")
721
+ var _a2, _b2, _c2, _d2, _e2;
722
+ const discountType2 = discount.tag || discount.type;
723
+ if (["good_pass", "discount_card", "product_discount_card"].includes(
724
+ discountType2
725
+ )) {
726
+ if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
727
+ return false;
728
+ }
729
+ }
730
+ if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
613
731
  return false;
614
- if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
732
+ if ((Number(product.total) <= 0 || !product.total) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
615
733
  var _a3;
616
734
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
617
735
  })) && (discount.tag || discount.type) !== "good_pass")
@@ -619,6 +737,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
619
737
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
620
738
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
621
739
  return false;
740
+ if ((discount.tag || discount.type) === "good_pass") {
741
+ const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
742
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
743
+ const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
744
+ if (currentUsedCount >= maxUsagePerOrder) {
745
+ return false;
746
+ }
747
+ }
748
+ }
749
+ const discountTypeForLimit = discount.tag || discount.type;
750
+ if (["discount_card", "product_discount_card"].includes(discountTypeForLimit)) {
751
+ const applicableProductLimitConfig = ((_e2 = discount.config) == null ? void 0 : _e2.applicableProductLimit) || 0;
752
+ if (applicableProductLimitConfig > 0) {
753
+ const currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
754
+ if (currentUsedLimitCount >= applicableProductLimitConfig) {
755
+ return false;
756
+ }
757
+ }
758
+ }
622
759
  const limitedData = discount.limited_relation_product_data;
623
760
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
624
761
  const isHolderMatch = this.checkHolderMatch(
@@ -637,7 +774,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
637
774
  return false;
638
775
  }
639
776
  if (limitedData.type === "product_all") {
640
- if (!isProductIncludedByLimitedData(limitedData, product.id)) {
777
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
641
778
  return false;
642
779
  }
643
780
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
@@ -652,21 +789,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
652
789
  }
653
790
  return false;
654
791
  });
655
- const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
792
+ const selectedDiscountCard = applicableDiscounts.find(
793
+ (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
794
+ );
656
795
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
657
796
  let isManualDiscount = false;
658
797
  if (flatItem.type === "main") {
659
- isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
660
- var _a2;
661
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
662
- }) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(_h, (item) => item.type === "product")));
798
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
799
+ (item) => {
800
+ var _a2;
801
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
802
+ }
803
+ ) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(
804
+ _h,
805
+ (item) => item.type === "product"
806
+ )));
807
+ if (product.inPromotion) {
808
+ isManualDiscount = false;
809
+ }
663
810
  } else {
664
811
  const parentProduct = flatItem.parentProduct;
665
812
  if (parentProduct) {
666
- isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
667
- var _a2;
668
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
669
- }) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(_k, (item) => item.type === "product")));
813
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
814
+ (item) => {
815
+ var _a2;
816
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
817
+ }
818
+ ) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(
819
+ _k,
820
+ (item) => item.type === "product"
821
+ )));
670
822
  }
671
823
  }
672
824
  if (options == null ? void 0 : options.discountId) {
@@ -718,17 +870,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
718
870
  }
719
871
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
720
872
  if (flatItem.type === "main") {
873
+ const restoredOptions = restoreOptionPrices(product.options);
721
874
  if (product.isClient) {
722
- processedProductsMap.set(
723
- product._id,
724
- [this.hooks.setProduct(originProduct, {
875
+ processedProductsMap.set(product._id, [
876
+ this.hooks.setProduct(originProduct, {
725
877
  ...isManualDiscount ? {} : {
726
878
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
727
879
  product: {
728
880
  original_price: product.original_price
729
881
  },
730
882
  bundle: product.bundle,
731
- options: product.options
883
+ options: restoredOptions
732
884
  }),
733
885
  variant: originProduct._productInit.variant,
734
886
  original_price: originProduct._productInit.original_price,
@@ -737,14 +889,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
737
889
  price: product.price
738
890
  },
739
891
  bundle: product.bundle,
740
- options: product.options
892
+ options: restoredOptions
741
893
  }),
742
894
  price: product.price,
743
- options: product.options
895
+ options: restoredOptions
744
896
  },
745
897
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
746
- })]
747
- );
898
+ })
899
+ ]);
748
900
  } else {
749
901
  let total = product.inPromotion ? ((_u = product == null ? void 0 : product._promotion) == null ? void 0 : _u.finalPrice) ?? product.origin_total ?? product.total : product.origin_total ?? product.total;
750
902
  let main_product_selling_price = product.price ?? product.main_product_selling_price;
@@ -754,19 +906,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
754
906
  }
755
907
  processedProductsMap.set(
756
908
  product._id,
757
- [this.hooks.setProduct(originProduct, {
758
- ...isManualDiscount ? {
759
- price: product.price
760
- } : {
761
- _id: product._id.split("___")[0] + "___" + index,
762
- origin_total: product.origin_total,
763
- total,
764
- original_price: product.original_price,
765
- price: product.price,
766
- main_product_selling_price
767
- },
768
- discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
769
- })]
909
+ [
910
+ this.hooks.setProduct(originProduct, {
911
+ ...isManualDiscount ? {
912
+ price: product.price
913
+ } : {
914
+ _id: product._id.split("___")[0] + "___" + index,
915
+ total,
916
+ price: product.price,
917
+ main_product_selling_price,
918
+ options: restoredOptions
919
+ },
920
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
921
+ })
922
+ ]
770
923
  );
771
924
  }
772
925
  } else {
@@ -782,104 +935,166 @@ var RulesModule = class extends import_BaseModule.BaseModule {
782
935
  if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
783
936
  return;
784
937
  }
785
- const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
938
+ const discountType = selectedDiscount.tag || selectedDiscount.type;
939
+ const isGoodPass = discountType === "good_pass";
940
+ const isDiscountCard = ["discount_card", "product_discount_card"].includes(discountType);
941
+ const applicableProductLimit = ((_w = selectedDiscount.config) == null ? void 0 : _w.applicableProductLimit) || 0;
942
+ const isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
786
943
  const totalQuantity = product.quantity || product.num || 1;
787
- const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
788
- const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
944
+ const availableGoodPassCount = applicableDiscounts.filter(
945
+ (item) => (item.tag || item.type) === "good_pass"
946
+ ).length;
947
+ let maxUsageLimit;
948
+ if (isGoodPass) {
949
+ maxUsageLimit = availableGoodPassCount;
950
+ if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
951
+ maxUsageLimit = Math.min(
952
+ availableGoodPassCount,
953
+ selectedDiscount.config.maxUsagePerOrder
954
+ );
955
+ }
956
+ } else if (isDiscountCard && applicableProductLimit > 0) {
957
+ const usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
958
+ maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
959
+ } else {
960
+ maxUsageLimit = 1;
961
+ }
962
+ const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
789
963
  const arr = [];
790
964
  if (flatItem.type === "main") {
791
965
  if (splitCount < totalQuantity && isNeedSplit) {
792
- arr.push(this.hooks.setProduct(originProduct, {
793
- discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
794
- quantity: totalQuantity - splitCount,
795
- _id: product._id.split("___")[0]
796
- }));
966
+ let total = product.origin_total ?? product.total;
967
+ if ((product.discount_list || []).some((item) => item.type === "promotion")) {
968
+ total = product.total ?? product.origin_total;
969
+ }
970
+ arr.push(
971
+ this.hooks.setProduct(originProduct, {
972
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
973
+ quantity: totalQuantity - splitCount,
974
+ _id: product._id.split("___")[0],
975
+ total
976
+ })
977
+ );
797
978
  }
798
979
  for (let i = 0; i < splitCount; i++) {
799
- const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
800
- usedDiscounts.set(selectedDiscount2.id, true);
801
- const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
980
+ const currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
981
+ usedDiscounts.set(currentSelectedDiscount.id, true);
982
+ if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === "good_pass") {
983
+ const currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
984
+ usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
985
+ }
986
+ const currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
987
+ if (["discount_card", "product_discount_card"].includes(currentDiscountTypeForCount)) {
988
+ const currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
989
+ usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
990
+ }
991
+ const appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
802
992
  let productOriginTotal = product.origin_total || product.total || 0;
803
993
  if (this.filterDiscountListByType(product.discount_list, "promotion").length && product.origin_total) {
804
994
  productOriginTotal = product.origin_total;
805
995
  }
806
- if (Number(((_w = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _w.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
996
+ if (Number(((_x = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _x.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
807
997
  productOriginTotal = product.total;
808
998
  }
809
- const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
810
- const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
999
+ const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
1000
+ const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
811
1001
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
812
- let targetProductTotal;
1002
+ const isDeductOptionPrice = !!((_y = selectedDiscount.config) == null ? void 0 : _y.deductOptionPrice);
1003
+ let mainProductSellingPrice;
813
1004
  let amount;
814
1005
  let productDiscountDifference;
1006
+ let discountedOptions = product.options;
1007
+ let optionDiscountAmount = 0;
815
1008
  if (isOrderLevel && productAllocation) {
816
1009
  amount = productAllocation.discountAmount;
817
1010
  productDiscountDifference = productAllocation.difference;
818
- targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
1011
+ mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
819
1012
  } else {
820
- targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
821
- amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
1013
+ mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
1014
+ currentSelectedDiscount,
1015
+ product.price,
1016
+ product.price
1017
+ );
1018
+ amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
822
1019
  }
823
- const discountType = selectedDiscount2.tag || selectedDiscount2.type;
824
- const isGoodPass = discountType === "good_pass";
1020
+ if (isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length)) {
1021
+ const optionResult = applyDiscountToOptions(
1022
+ product.options,
1023
+ currentSelectedDiscount
1024
+ );
1025
+ discountedOptions = optionResult.discountedOptions;
1026
+ optionDiscountAmount = optionResult.optionDiscountAmount;
1027
+ }
1028
+ const optionsForLineTotal = isDeductOptionPrice && ((_A = product.options) == null ? void 0 : _A.length) ? discountedOptions : product.options;
1029
+ const optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
1030
+ const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
1031
+ const mainProductDiscountAmount = amount;
1032
+ const lineDiscountAmount = new import_decimal.default(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
1033
+ const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
1034
+ const discountType2 = selectedDiscount.tag || selectedDiscount.type;
1035
+ const currentIsGoodPass = currentDiscountType === "good_pass";
825
1036
  const discountDetail = {
826
- amount,
827
- type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
1037
+ amount: lineDiscountAmount,
1038
+ type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : discountType2,
828
1039
  discount: {
829
- discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
830
- fixed_amount: amount,
831
- discount_calculation_mode: (_y = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _y.discount_calculation_mode,
832
- resource_id: selectedDiscount2.id,
833
- title: selectedDiscount2.format_title,
1040
+ discount_card_type: (_B = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _B.discount_card_type,
1041
+ fixed_amount: lineDiscountAmount,
1042
+ discount_calculation_mode: (_C = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _C.discount_calculation_mode,
1043
+ resource_id: selectedDiscount.id,
1044
+ title: selectedDiscount.format_title,
834
1045
  original_amount: product.price,
835
1046
  product_id: originProduct.id,
836
- percent: selectedDiscount2.par_value
1047
+ percent: currentSelectedDiscount.par_value,
1048
+ discount_product_id: currentSelectedDiscount.product_id
837
1049
  },
838
- // 前端使用的num数量,为了计算优惠金额
839
- _num: isGoodPass ? 1 : product.num,
1050
+ // 前端使用的num数量,为了计算优惠金额(拆分时为1)
1051
+ _num: isNeedSplit ? 1 : product.num,
1052
+ config: currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.config,
840
1053
  metadata: {
841
1054
  num: 1,
842
- discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
1055
+ discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
843
1056
  // 🔥 order_level 分摊差值
844
- ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1057
+ ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference },
1058
+ /** 仅主商品上的优惠金额(不含 option) */
1059
+ mainProductDiscountAmount,
1060
+ optionDiscountAmount
845
1061
  }
846
1062
  };
847
1063
  appliedProducts.push(discountDetail);
848
- appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
849
- let total = targetProductTotal;
850
- if (product.options) {
851
- total = product.options.reduce((accumulator, currentValue) => {
852
- const currentPrice = new import_decimal.default(currentValue.price || 0);
853
- const currentNum = new import_decimal.default(currentValue.num || 0);
854
- return accumulator.add(currentPrice.mul(currentNum));
855
- }, new import_decimal.default(total)).toNumber();
856
- }
1064
+ appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
857
1065
  if (product.isClient) {
858
- arr.push(this.hooks.setProduct(originProduct, {
859
- discount_list: [discountDetail],
860
- price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
861
- quantity: isNeedSplit ? 1 : product.quantity,
862
- origin_total: (0, import_utils2.getProductOriginTotalPrice)({
863
- product: {
864
- original_price: product.original_price
865
- },
866
- bundle: product.bundle,
867
- options: product.options
868
- }),
869
- variant: originProduct._productInit.variant,
870
- original_price: new import_decimal.default(product.price || 0).toNumber(),
871
- total
872
- }));
1066
+ arr.push(
1067
+ this.hooks.setProduct(originProduct, {
1068
+ discount_list: [discountDetail],
1069
+ // good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
1070
+ price: currentIsGoodPass ? mainProductSellingPrice : product.price,
1071
+ quantity: isNeedSplit ? 1 : product.quantity,
1072
+ origin_total: (0, import_utils2.getProductOriginTotalPrice)({
1073
+ product: {
1074
+ original_price: product.original_price
1075
+ },
1076
+ bundle: product.bundle,
1077
+ options: restoreOptionPrices(product.options)
1078
+ }),
1079
+ variant: originProduct._productInit.variant,
1080
+ original_price: new import_decimal.default(product.price || 0).toNumber(),
1081
+ total,
1082
+ options: discountedOptions
1083
+ })
1084
+ );
873
1085
  } else {
874
- arr.push(this.hooks.setProduct(originProduct, {
875
- discount_list: this.filterDiscountListByType(product.discount_list, "promotion").concat([discountDetail]),
876
- _id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
877
- price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
878
- quantity: isNeedSplit ? 1 : product.quantity,
879
- total,
880
- origin_total: productOriginTotal,
881
- main_product_selling_price: targetProductTotal
882
- }));
1086
+ arr.push(
1087
+ this.hooks.setProduct(originProduct, {
1088
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion").concat([discountDetail]),
1089
+ _id: product._id.split("___")[0] + "___" + currentSelectedDiscount.id + "_" + i + "_" + index,
1090
+ price: currentIsGoodPass ? 0 : product.price,
1091
+ quantity: isNeedSplit ? 1 : product.quantity,
1092
+ total,
1093
+ origin_total: productOriginTotal,
1094
+ main_product_selling_price: mainProductSellingPrice,
1095
+ options: discountedOptions
1096
+ })
1097
+ );
883
1098
  }
884
1099
  }
885
1100
  processedProductsMap.set(product._id, arr);
@@ -889,62 +1104,298 @@ var RulesModule = class extends import_BaseModule.BaseModule {
889
1104
  const discountNum = splitCount;
890
1105
  const normalNum = totalQuantity - discountNum;
891
1106
  for (let i = 0; i < discountNum; i++) {
892
- const selectedDiscount2 = applicableDiscounts[i];
893
- usedDiscounts.set(selectedDiscount2.id, true);
1107
+ const currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
1108
+ usedDiscounts.set(currentBundleDiscount.id, true);
1109
+ if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
1110
+ const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1111
+ usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
1112
+ }
1113
+ const bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
1114
+ if (["discount_card", "product_discount_card"].includes(bundleDiscountTypeForCount)) {
1115
+ const currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1116
+ usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
1117
+ }
894
1118
  const uniqueId = `${flatItem._id}_split_${i}`;
1119
+ const discountedPrice = (0, import_utils.getDiscountAmount)(
1120
+ currentBundleDiscount,
1121
+ product.origin_total,
1122
+ product.origin_total
1123
+ );
1124
+ const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
1125
+ const bundleDiscountType = currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag;
895
1126
  const discountDetail = {
896
- amount: product.origin_total,
897
- type: "good_pass",
1127
+ amount: bundleDiscountAmount,
1128
+ type: bundleDiscountType,
898
1129
  discount: {
899
- fixed_amount: product.origin_total,
900
- discount_calculation_mode: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_calculation_mode,
901
- resource_id: selectedDiscount2.id,
902
- title: selectedDiscount2.format_title,
1130
+ discount_card_type: (_D = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _D.discount_card_type,
1131
+ discount_calculation_mode: (_E = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _E.discount_calculation_mode,
1132
+ fixed_amount: bundleDiscountAmount,
1133
+ resource_id: currentBundleDiscount.id,
1134
+ title: currentBundleDiscount.format_title,
903
1135
  original_amount: product.origin_total,
904
- product_id: product.id
1136
+ product_id: product.id,
1137
+ percent: currentBundleDiscount.par_value,
1138
+ discount_product_id: currentBundleDiscount.product_id
905
1139
  },
906
1140
  metadata: {
907
1141
  // 🔥 使用拆分后的唯一 _id
908
1142
  custom_product_bundle_map_id: uniqueId,
909
- discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
1143
+ discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
910
1144
  num: 1
911
1145
  },
912
- _num: 1
1146
+ _num: 1,
1147
+ config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config
913
1148
  };
914
- const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1149
+ const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
915
1150
  appliedProducts.push(discountDetail);
916
- appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
1151
+ appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
917
1152
  processedItems.push({
918
1153
  ...flatItem,
919
1154
  // 🔥 使用唯一的 _id
920
1155
  _id: uniqueId,
921
1156
  num: 1,
922
1157
  quantity: 1,
923
- price: 0,
924
- // 商品券价格为0
925
- total: 0,
1158
+ price: discountedPrice,
1159
+ // 折扣后的价格
1160
+ total: discountedPrice,
926
1161
  discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion").concat([discountDetail]),
927
1162
  processed: true,
928
- _discountId: selectedDiscount2.id
1163
+ _discountId: currentBundleDiscount.id
929
1164
  });
930
1165
  }
931
- if (normalNum > 0) {
932
- processedItems.push({
933
- ...flatItem,
934
- // 🔥 为剩余商品生成唯一的 _id
935
- _id: `${flatItem._id}_split_rest`,
936
- num: normalNum,
937
- quantity: normalNum,
938
- discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion"),
939
- processed: true
1166
+ let remainingNum = normalNum;
1167
+ let continueSplitIndex = discountNum;
1168
+ while (remainingNum > 0) {
1169
+ const nextApplicableDiscounts = sortedDiscountList.filter((nextDiscount) => {
1170
+ var _a2, _b2, _c2, _d2;
1171
+ const nextDiscountType = nextDiscount.tag || nextDiscount.type;
1172
+ if (["good_pass", "discount_card", "product_discount_card"].includes(nextDiscountType)) {
1173
+ if (nextDiscount.config === void 0 || !((_a2 = nextDiscount == null ? void 0 : nextDiscount.config) == null ? void 0 : _a2.isAvailable)) {
1174
+ return false;
1175
+ }
1176
+ }
1177
+ if ((Number(product.total) <= 0 || !product.total) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find(
1178
+ (n) => {
1179
+ var _a3;
1180
+ return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === nextDiscount.id;
1181
+ }
1182
+ )) && nextDiscountType !== "good_pass")
1183
+ return false;
1184
+ if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === "good_pass")
1185
+ return false;
1186
+ if (nextDiscountType === "good_pass") {
1187
+ const maxUsagePerOrder = (_c2 = nextDiscount.config) == null ? void 0 : _c2.maxUsagePerOrder;
1188
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1189
+ const currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1190
+ if (currentUsedCount >= maxUsagePerOrder) {
1191
+ return false;
1192
+ }
1193
+ }
1194
+ }
1195
+ if (["discount_card", "product_discount_card"].includes(nextDiscountType)) {
1196
+ const limitConfig = ((_d2 = nextDiscount.config) == null ? void 0 : _d2.applicableProductLimit) || 0;
1197
+ if (limitConfig > 0) {
1198
+ const currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1199
+ if (currentUsedLimitCount >= limitConfig) {
1200
+ return false;
1201
+ }
1202
+ }
1203
+ }
1204
+ const limitedData = nextDiscount.limited_relation_product_data;
1205
+ if (limitedData.type === "product_all") {
1206
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1207
+ return false;
1208
+ }
1209
+ if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1210
+ return false;
1211
+ }
1212
+ return true;
1213
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1214
+ if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1215
+ return false;
1216
+ }
1217
+ return true;
1218
+ }
1219
+ return false;
940
1220
  });
1221
+ if (nextApplicableDiscounts.length === 0) {
1222
+ processedItems.push({
1223
+ ...flatItem,
1224
+ _id: `${flatItem._id}_split_rest`,
1225
+ num: remainingNum,
1226
+ quantity: remainingNum,
1227
+ discount_list: [],
1228
+ processed: true
1229
+ });
1230
+ break;
1231
+ }
1232
+ const nextSelectedDiscountCard = nextApplicableDiscounts.find(
1233
+ (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
1234
+ );
1235
+ const nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1236
+ const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1237
+ const nextIsGoodPass = nextDiscType === "good_pass";
1238
+ const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
1239
+ const nextApplicableProductLimit = ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.applicableProductLimit) || 0;
1240
+ const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1241
+ if (!nextIsNeedSplit) {
1242
+ const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1243
+ usedDiscounts.set(nextBundleDiscount.id, true);
1244
+ if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1245
+ const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1246
+ usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1247
+ }
1248
+ const nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1249
+ if (["discount_card", "product_discount_card"].includes(nextNoSplitType)) {
1250
+ const curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1251
+ usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curCount + remainingNum);
1252
+ }
1253
+ const nextOriginTotal = product.original_price || product.price || 0;
1254
+ const nextTargetTotal = (0, import_utils.getDiscountAmount)(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1255
+ const nextDiscountAmount = new import_decimal.default(nextOriginTotal).minus(nextTargetTotal).toNumber();
1256
+ const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1257
+ const nextBundleDiscType = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1258
+ const nextDiscountDetail = {
1259
+ amount: nextDiscountAmount * remainingNum,
1260
+ type: nextBundleDiscType,
1261
+ discount: {
1262
+ discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
1263
+ fixed_amount: nextDiscountAmount,
1264
+ resource_id: nextBundleDiscount.id,
1265
+ title: nextBundleDiscount.format_title,
1266
+ original_amount: product.original_price,
1267
+ product_id: product.id,
1268
+ percent: nextBundleDiscount.par_value,
1269
+ discount_product_id: nextBundleDiscount.product_id
1270
+ },
1271
+ metadata: {
1272
+ custom_product_bundle_map_id: nextUniqueId,
1273
+ num: remainingNum
1274
+ },
1275
+ config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
1276
+ _num: remainingNum * (((_H = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _H.num) || 1)
1277
+ };
1278
+ const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1279
+ nextAppliedProducts.push(nextDiscountDetail);
1280
+ appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1281
+ processedItems.push({
1282
+ ...flatItem,
1283
+ _id: nextUniqueId,
1284
+ num: remainingNum,
1285
+ quantity: remainingNum,
1286
+ total: nextTargetTotal,
1287
+ price: new import_decimal.default(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1288
+ discount_list: [nextDiscountDetail],
1289
+ processed: true
1290
+ });
1291
+ remainingNum = 0;
1292
+ break;
1293
+ }
1294
+ let nextMaxUsageLimit;
1295
+ if (nextIsGoodPass) {
1296
+ const nextGoodPassCount = nextApplicableDiscounts.filter(
1297
+ (item) => (item.tag || item.type) === "good_pass"
1298
+ ).length;
1299
+ nextMaxUsageLimit = nextGoodPassCount;
1300
+ if ((_I = nextSelectedDiscount.config) == null ? void 0 : _I.maxUsagePerOrder) {
1301
+ const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1302
+ nextMaxUsageLimit = Math.min(
1303
+ nextGoodPassCount,
1304
+ Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount)
1305
+ );
1306
+ }
1307
+ } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1308
+ const usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1309
+ nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - usedLimitCount);
1310
+ } else {
1311
+ nextMaxUsageLimit = 1;
1312
+ }
1313
+ const nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1314
+ if (nextSplitCount === 0) {
1315
+ processedItems.push({
1316
+ ...flatItem,
1317
+ _id: `${flatItem._id}_split_rest`,
1318
+ num: remainingNum,
1319
+ quantity: remainingNum,
1320
+ discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion"),
1321
+ processed: true
1322
+ });
1323
+ break;
1324
+ }
1325
+ for (let j = 0; j < nextSplitCount; j++) {
1326
+ const nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1327
+ usedDiscounts.set(nextBundleDiscount.id, true);
1328
+ if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1329
+ const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1330
+ usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1331
+ }
1332
+ const nextBundleDiscTypeForCount = nextBundleDiscount.tag || nextBundleDiscount.type;
1333
+ if (["discount_card", "product_discount_card"].includes(nextBundleDiscTypeForCount)) {
1334
+ const curLimitCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1335
+ usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curLimitCount + 1);
1336
+ }
1337
+ const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1338
+ const nextDiscountedPrice = (0, import_utils.getDiscountAmount)(
1339
+ nextBundleDiscount,
1340
+ product.origin_total,
1341
+ product.origin_total
1342
+ );
1343
+ const nextBundleDiscAmount = new import_decimal.default(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1344
+ const nextBundleDiscTypeStr = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1345
+ const nextDiscountDetail = {
1346
+ amount: nextBundleDiscAmount,
1347
+ type: nextBundleDiscTypeStr,
1348
+ discount: {
1349
+ discount_card_type: (_J = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _J.discount_card_type,
1350
+ fixed_amount: nextBundleDiscAmount,
1351
+ resource_id: nextBundleDiscount.id,
1352
+ title: nextBundleDiscount.format_title,
1353
+ original_amount: product.origin_total,
1354
+ product_id: product.id,
1355
+ percent: nextBundleDiscount.par_value,
1356
+ discount_product_id: nextBundleDiscount.product_id
1357
+ },
1358
+ metadata: {
1359
+ custom_product_bundle_map_id: nextUniqueId,
1360
+ num: 1
1361
+ },
1362
+ _num: 1,
1363
+ config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config
1364
+ };
1365
+ const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1366
+ nextAppliedProducts.push(nextDiscountDetail);
1367
+ appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1368
+ processedItems.push({
1369
+ ...flatItem,
1370
+ _id: nextUniqueId,
1371
+ num: 1,
1372
+ quantity: 1,
1373
+ price: nextDiscountedPrice,
1374
+ total: nextDiscountedPrice,
1375
+ discount_list: [nextDiscountDetail],
1376
+ processed: true,
1377
+ _discountId: nextBundleDiscount.id
1378
+ });
1379
+ continueSplitIndex++;
1380
+ }
1381
+ remainingNum -= nextSplitCount;
941
1382
  }
942
1383
  } else {
943
- const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
944
- usedDiscounts.set(selectedDiscount2.id, true);
1384
+ const currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1385
+ usedDiscounts.set(currentBundleDiscount.id, true);
1386
+ if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
1387
+ const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1388
+ usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
1389
+ }
1390
+ const noSplitDiscountType = currentBundleDiscount.tag || currentBundleDiscount.type;
1391
+ if (["discount_card", "product_discount_card"].includes(noSplitDiscountType)) {
1392
+ const bundleQuantity = product.num || 1;
1393
+ const currentNoSplitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1394
+ usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
1395
+ }
945
1396
  const productOriginTotal = product.original_price || product.price || 0;
946
- const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
947
- const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
1397
+ const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
1398
+ const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
948
1399
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
949
1400
  let targetProductTotal;
950
1401
  let fixedAmountPerItem;
@@ -955,39 +1406,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
955
1406
  targetProductTotal = Math.max(new import_decimal.default(productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
956
1407
  } else {
957
1408
  targetProductTotal = (0, import_utils.getDiscountAmount)(
958
- selectedDiscount2,
1409
+ currentBundleDiscount,
959
1410
  productOriginTotal,
960
1411
  productOriginTotal
961
1412
  );
962
1413
  fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
963
1414
  }
1415
+ const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
964
1416
  const uniqueId = flatItem._id;
965
1417
  const discountDetail = {
966
- amount: fixedAmountPerItem * (product.num || 1),
967
- type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
1418
+ amount: bundleActualDiscountAmount * (product.num || 1),
1419
+ type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
968
1420
  discount: {
969
- discount_card_type: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_card_type,
970
- fixed_amount: fixedAmountPerItem,
971
- discount_calculation_mode: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_calculation_mode,
972
- resource_id: selectedDiscount2.id,
973
- title: selectedDiscount2.format_title,
1421
+ discount_card_type: (_K = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _K.discount_card_type,
1422
+ fixed_amount: bundleActualDiscountAmount,
1423
+ discount_calculation_mode: (_L = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _L.discount_calculation_mode,
1424
+ resource_id: currentBundleDiscount.id,
1425
+ title: currentBundleDiscount.format_title,
974
1426
  original_amount: product.original_price,
975
1427
  product_id: product.id,
976
- percent: selectedDiscount2.par_value
1428
+ percent: currentBundleDiscount.par_value,
1429
+ discount_product_id: currentBundleDiscount.product_id
977
1430
  },
978
1431
  metadata: {
979
1432
  // 🔥 使用唯一的 _id
980
1433
  custom_product_bundle_map_id: uniqueId,
981
- discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
1434
+ discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
982
1435
  num: product.num || 1,
983
1436
  // 🔥 order_level 分摊差值
984
1437
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
985
1438
  },
986
- _num: (product.num || 1) * (((_C = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _C.num) || 1)
1439
+ config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config,
1440
+ _num: (product.num || 1) * (((_M = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _M.num) || 1)
987
1441
  };
988
- const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1442
+ const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
989
1443
  appliedProducts.push(discountDetail);
990
- appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
1444
+ appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
991
1445
  processedItems.push({
992
1446
  ...flatItem,
993
1447
  total: targetProductTotal,
@@ -1006,6 +1460,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1006
1460
  const mainProductArr = processedProductsMap2.get(product._id);
1007
1461
  if (!mainProductArr || mainProductArr.length === 0) {
1008
1462
  const getDefaultProduct = () => {
1463
+ const restoredOptions = restoreOptionPrices(product.options);
1009
1464
  if (product.isClient) {
1010
1465
  return this.hooks.setProduct(originProduct, {
1011
1466
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
@@ -1015,7 +1470,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1015
1470
  original_price: product.original_price
1016
1471
  },
1017
1472
  bundle: product.bundle,
1018
- options: product.options
1473
+ options: restoredOptions
1019
1474
  }),
1020
1475
  variant: originProduct._productInit.variant,
1021
1476
  original_price: originProduct._productInit.original_price,
@@ -1024,15 +1479,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1024
1479
  price: product.price
1025
1480
  },
1026
1481
  bundle: product.bundle,
1027
- options: product.options
1028
- })
1482
+ options: restoredOptions
1483
+ }),
1484
+ options: restoredOptions
1029
1485
  });
1030
1486
  } else {
1031
1487
  return this.hooks.setProduct(originProduct, {
1032
1488
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
1033
1489
  total: product.total,
1034
1490
  origin_total: product.origin_total,
1035
- price: product.price
1491
+ price: product.price,
1492
+ options: restoreOptionPrices(product.options)
1036
1493
  });
1037
1494
  }
1038
1495
  };
@@ -1072,80 +1529,92 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1072
1529
  const mainProduct = mainProductArr[0];
1073
1530
  const mainProductData = this.hooks.getProduct(mainProduct);
1074
1531
  const newBundleWithDiscount = [];
1075
- (product.bundle || []).forEach((bundleItem, bundleIndex) => {
1076
- const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
1077
- if (processedItems.length > 1) {
1078
- processedItems.forEach((item) => {
1079
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1080
- var _a;
1081
- return {
1082
- ...discount,
1083
- metadata: {
1084
- ...discount.metadata,
1085
- num: item.num,
1086
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1087
- }
1088
- // num: item.num, // 使用拆分后的 num
1089
- };
1090
- });
1091
- newBundleWithDiscount.push({
1092
- ...bundleItem,
1093
- _id: item._id,
1094
- product_id: bundleItem.product_id,
1095
- price: item.price,
1096
- num: item.num,
1097
- discount_list: updatedDiscountList2
1098
- });
1099
- });
1100
- } else {
1101
- const item = processedItems[0];
1102
- if (item.processed) {
1103
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1104
- var _a;
1105
- return {
1106
- ...discount,
1107
- metadata: {
1108
- ...discount.metadata,
1109
- num: item.num,
1110
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1111
- }
1112
- // num: item.num, // 使用当前的 num
1113
- };
1114
- });
1115
- newBundleWithDiscount.push({
1116
- ...bundleItem,
1117
- _id: item._id,
1118
- product_id: bundleItem.product_id,
1119
- price: item.price,
1120
- num: item.num,
1121
- discount_list: updatedDiscountList2
1532
+ (product.bundle || []).forEach(
1533
+ (bundleItem, bundleIndex) => {
1534
+ const processedItems = bundleProcessingInfo.get(
1535
+ bundleIndex
1536
+ ) || [bundleItem];
1537
+ if (processedItems.length > 1) {
1538
+ processedItems.forEach((item) => {
1539
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1540
+ var _a;
1541
+ return {
1542
+ ...discount,
1543
+ metadata: {
1544
+ ...discount.metadata,
1545
+ num: item.num,
1546
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1547
+ }
1548
+ // num: item.num, // 使用拆分后的 num
1549
+ };
1550
+ });
1551
+ newBundleWithDiscount.push({
1552
+ ...bundleItem,
1553
+ _id: item._id,
1554
+ product_id: bundleItem.product_id,
1555
+ price: item.price,
1556
+ num: item.num,
1557
+ quantity: item.num,
1558
+ discount_list: updatedDiscountList2
1559
+ });
1122
1560
  });
1123
1561
  } else {
1124
- newBundleWithDiscount.push(item);
1562
+ const item = processedItems[0];
1563
+ if (item.processed) {
1564
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1565
+ var _a;
1566
+ return {
1567
+ ...discount,
1568
+ metadata: {
1569
+ ...discount.metadata,
1570
+ num: item.num,
1571
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1572
+ }
1573
+ // num: item.num, // 使用当前的 num
1574
+ };
1575
+ });
1576
+ newBundleWithDiscount.push({
1577
+ ...bundleItem,
1578
+ _id: item._id,
1579
+ product_id: bundleItem.product_id,
1580
+ price: item.price,
1581
+ num: item.num,
1582
+ quantity: item.num,
1583
+ discount_list: updatedDiscountList2
1584
+ });
1585
+ } else {
1586
+ newBundleWithDiscount.push(item);
1587
+ }
1125
1588
  }
1126
1589
  }
1127
- });
1590
+ );
1128
1591
  let newTotalWithDiscount = Number(mainProductData.price || 0);
1129
- let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
1130
- const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
1131
- var _a, _b;
1132
- if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
1133
- return discount;
1134
- }
1135
- return {
1136
- ...discount,
1137
- // num: 1,
1138
- metadata: {
1139
- ...discount.metadata,
1140
- custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
1141
- num: 1
1592
+ let newOriginTotalWithDiscount = Number(
1593
+ mainProductData.original_price || mainProductData.price || 0
1594
+ );
1595
+ const updatedMainDiscountList = mainProductData.discount_list.map(
1596
+ (discount) => {
1597
+ var _a, _b;
1598
+ if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
1599
+ return discount;
1142
1600
  }
1143
- };
1144
- });
1145
- const mainDiscountList = updatedMainDiscountList.filter((item) => {
1146
- var _a;
1147
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1148
- });
1601
+ return {
1602
+ ...discount,
1603
+ // num: 1,
1604
+ metadata: {
1605
+ ...discount.metadata,
1606
+ custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
1607
+ num: 1
1608
+ }
1609
+ };
1610
+ }
1611
+ );
1612
+ const mainDiscountList = updatedMainDiscountList.filter(
1613
+ (item) => {
1614
+ var _a;
1615
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1616
+ }
1617
+ );
1149
1618
  if (mainDiscountList && mainDiscountList.length > 0) {
1150
1619
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
1151
1620
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
@@ -1175,20 +1644,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1175
1644
  quantity: 1,
1176
1645
  discount_list: updatedMainDiscountList,
1177
1646
  bundle: newBundleWithDiscount,
1178
- total: new import_decimal.default(newTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber(),
1179
- origin_total: new import_decimal.default(newOriginTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
1647
+ total: newTotalWithDiscount,
1648
+ origin_total: newOriginTotalWithDiscount
1180
1649
  })
1181
1650
  );
1182
1651
  if (mainProductQuantity > 1) {
1183
1652
  const newBundleOriginal = [];
1184
- (product.bundle || []).forEach((bundleItem, bundleIndex) => {
1185
- newBundleOriginal.push({
1186
- ...bundleItem,
1187
- discount_list: []
1188
- });
1189
- });
1653
+ (product.bundle || []).forEach(
1654
+ (bundleItem, bundleIndex) => {
1655
+ newBundleOriginal.push({
1656
+ ...bundleItem,
1657
+ discount_list: []
1658
+ });
1659
+ }
1660
+ );
1190
1661
  let newTotalOriginal = Number(mainProductData.price || 0);
1191
- let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1662
+ let newOriginTotalOriginal = Number(
1663
+ mainProductData.original_price || mainProductData.price || 0
1664
+ );
1192
1665
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
1193
1666
  var _a, _b;
1194
1667
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1204,12 +1677,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1204
1677
  // num: mainProductQuantity - 1,
1205
1678
  };
1206
1679
  });
1207
- const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
1208
- var _a;
1209
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1210
- });
1680
+ const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
1681
+ (item) => {
1682
+ var _a;
1683
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1684
+ }
1685
+ );
1211
1686
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1212
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
1687
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
1688
+ mainDiscountListOriginal
1689
+ );
1213
1690
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
1214
1691
  newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
1215
1692
  }
@@ -1246,59 +1723,68 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1246
1723
  const mainProductData = this.hooks.getProduct(mainProduct);
1247
1724
  const newBundle = [];
1248
1725
  if (product.bundle && Array.isArray(product.bundle)) {
1249
- product.bundle.forEach((bundleItem, bundleIndex) => {
1250
- const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1251
- const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1252
- if (!processedBundleItems || processedBundleItems.length === 0) {
1253
- newBundle.push(bundleItem);
1254
- } else {
1255
- processedBundleItems.forEach((item) => {
1256
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1257
- var _a2;
1258
- return {
1259
- ...discount,
1260
- metadata: {
1261
- ...discount.metadata,
1262
- num: item.num,
1263
- custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1264
- }
1265
- // num: item.num, // 使用拆分后的 num
1266
- };
1726
+ product.bundle.forEach(
1727
+ (bundleItem, bundleIndex) => {
1728
+ const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1729
+ const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1730
+ if (!processedBundleItems || processedBundleItems.length === 0) {
1731
+ newBundle.push(bundleItem);
1732
+ } else {
1733
+ processedBundleItems.forEach((item) => {
1734
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1735
+ var _a2;
1736
+ return {
1737
+ ...discount,
1738
+ metadata: {
1739
+ ...discount.metadata,
1740
+ num: item.num,
1741
+ custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1742
+ }
1743
+ // num: item.num, // 使用拆分后的 num
1744
+ };
1745
+ });
1746
+ newBundle.push({
1747
+ ...bundleItem,
1748
+ _id: item._id,
1749
+ product_id: bundleItem.product_id,
1750
+ price: item.price,
1751
+ num: item.num,
1752
+ quantity: item.num,
1753
+ discount_list: updatedDiscountList2,
1754
+ bundle_selling_price: bundleItem.bundle_selling_price !== void 0 ? item.price : void 0
1755
+ });
1267
1756
  });
1268
- newBundle.push({
1269
- ...bundleItem,
1270
- _id: item._id,
1271
- product_id: bundleItem.product_id,
1272
- price: item.price,
1273
- num: item.num,
1274
- discount_list: updatedDiscountList2
1275
- });
1276
- });
1757
+ }
1277
1758
  }
1278
- });
1759
+ );
1279
1760
  }
1280
1761
  let newTotal = Number(mainProductData.price || 0);
1281
- let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
1282
- const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(_b, (item) => item.type === "product")));
1762
+ let newOriginTotal = Number(
1763
+ mainProductData.original_price || mainProductData.price || 0
1764
+ );
1765
+ const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(
1766
+ _b,
1767
+ (item) => item.type === "product"
1768
+ )));
1283
1769
  if (isManualDiscount) {
1284
1770
  newTotal = mainProductData.total ?? newTotal;
1285
1771
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
1286
1772
  } else {
1287
- const mainDiscountList = mainProductData.discount_list.filter((item) => {
1288
- var _a2;
1289
- return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1290
- });
1773
+ const mainDiscountList = mainProductData.discount_list.filter(
1774
+ (item) => {
1775
+ var _a2;
1776
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1777
+ }
1778
+ );
1291
1779
  if (mainDiscountList && mainDiscountList.length > 0) {
1292
1780
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
1293
1781
  newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
1294
1782
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
1295
1783
  }
1296
1784
  if (newBundle.length > 0) {
1297
- newBundle.forEach((item) => {
1298
- newTotal += Number(item.price) * Number(item.num);
1299
- });
1300
1785
  newBundle.forEach((item) => {
1301
1786
  var _a2, _b2, _c2;
1787
+ newTotal += Number(item.price) * Number(item.num);
1302
1788
  const originalPrice = ((_c2 = (_b2 = (_a2 = item.discount_list) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.discount) == null ? void 0 : _c2.original_amount) || item.price;
1303
1789
  newOriginTotal += Number(originalPrice) * Number(item.num);
1304
1790
  });
@@ -1311,8 +1797,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1311
1797
  return accumulator.add(currentPrice.mul(currentNum));
1312
1798
  }, new import_decimal.default(newTotal)).toNumber();
1313
1799
  }
1314
- newTotal = new import_decimal.default(newTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1315
- newOriginTotal = new import_decimal.default(newOriginTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1316
1800
  result.push(
1317
1801
  this.hooks.setProduct(mainProduct, {
1318
1802
  ...mainProductData,