@pisell/pisellos 2.1.93 → 2.1.94

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 (100) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/modules/Cart/types.d.ts +0 -2
  4. package/dist/modules/Cart/utils/cartProduct.js +0 -11
  5. package/dist/modules/Discount/types.d.ts +0 -16
  6. package/dist/modules/Payment/index.d.ts +1 -2
  7. package/dist/modules/Payment/index.js +7 -10
  8. package/dist/modules/Payment/utils.js +0 -3
  9. package/dist/modules/Payment/walletpass.d.ts +0 -23
  10. package/dist/modules/Payment/walletpass.js +95 -191
  11. package/dist/modules/Rules/index.d.ts +5 -9
  12. package/dist/modules/Rules/index.js +125 -539
  13. package/dist/modules/Rules/types.d.ts +0 -1
  14. package/dist/modules/Summary/types.d.ts +0 -2
  15. package/dist/modules/Summary/utils.d.ts +0 -6
  16. package/dist/modules/Summary/utils.js +0 -21
  17. package/dist/plugins/window.d.ts +0 -2
  18. package/dist/solution/BookingByStep/index.d.ts +1 -2
  19. package/dist/solution/BookingByStep/index.js +5 -1
  20. package/dist/solution/BookingTicket/index.d.ts +1 -1
  21. package/dist/solution/Checkout/index.js +0 -2
  22. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  23. package/dist/solution/ShopDiscount/index.js +7 -23
  24. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  25. package/dist/solution/ShopDiscount/types.js +1 -2
  26. package/dist/solution/ShopDiscount/utils.js +12 -26
  27. package/lib/index.d.ts +0 -1
  28. package/lib/index.js +1 -3
  29. package/lib/modules/Cart/types.d.ts +0 -2
  30. package/lib/modules/Cart/utils/cartProduct.js +0 -9
  31. package/lib/modules/Discount/types.d.ts +0 -16
  32. package/lib/modules/Payment/index.d.ts +1 -2
  33. package/lib/modules/Payment/index.js +0 -1
  34. package/lib/modules/Payment/utils.js +0 -3
  35. package/lib/modules/Payment/walletpass.d.ts +0 -23
  36. package/lib/modules/Payment/walletpass.js +17 -94
  37. package/lib/modules/Rules/index.d.ts +5 -9
  38. package/lib/modules/Rules/index.js +259 -665
  39. package/lib/modules/Rules/types.d.ts +0 -1
  40. package/lib/modules/Summary/types.d.ts +0 -2
  41. package/lib/modules/Summary/utils.d.ts +0 -6
  42. package/lib/modules/Summary/utils.js +0 -15
  43. package/lib/plugins/window.d.ts +0 -2
  44. package/lib/solution/BookingByStep/index.d.ts +1 -2
  45. package/lib/solution/BookingByStep/index.js +3 -1
  46. package/lib/solution/BookingTicket/index.d.ts +1 -1
  47. package/lib/solution/Checkout/index.js +0 -2
  48. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  49. package/lib/solution/ShopDiscount/index.js +8 -22
  50. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  51. package/lib/solution/ShopDiscount/utils.js +6 -10
  52. package/package.json +1 -1
  53. package/dist/model/index.d.ts +0 -1
  54. package/dist/model/index.js +0 -1
  55. package/dist/model/strategy/adapter/index.d.ts +0 -3
  56. package/dist/model/strategy/adapter/index.js +0 -4
  57. package/dist/model/strategy/adapter/type.d.ts +0 -28
  58. package/dist/model/strategy/adapter/type.js +0 -1
  59. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  60. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -497
  61. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  62. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  63. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  64. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  65. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  66. package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
  67. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -165
  68. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  69. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  70. package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
  71. package/dist/model/strategy/index.d.ts +0 -94
  72. package/dist/model/strategy/index.js +0 -551
  73. package/dist/model/strategy/strategy-example.d.ts +0 -5
  74. package/dist/model/strategy/strategy-example.js +0 -331
  75. package/dist/model/strategy/type.d.ts +0 -228
  76. package/dist/model/strategy/type.js +0 -94
  77. package/lib/model/index.d.ts +0 -1
  78. package/lib/model/index.js +0 -23
  79. package/lib/model/strategy/adapter/index.d.ts +0 -3
  80. package/lib/model/strategy/adapter/index.js +0 -45
  81. package/lib/model/strategy/adapter/type.d.ts +0 -28
  82. package/lib/model/strategy/adapter/type.js +0 -17
  83. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  84. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -421
  85. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  86. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  87. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  88. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  89. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  90. package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
  91. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -165
  92. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  93. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  94. package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
  95. package/lib/model/strategy/index.d.ts +0 -94
  96. package/lib/model/strategy/index.js +0 -413
  97. package/lib/model/strategy/strategy-example.d.ts +0 -5
  98. package/lib/model/strategy/strategy-example.js +0 -318
  99. package/lib/model/strategy/type.d.ts +0 -228
  100. package/lib/model/strategy/type.js +0 -44
@@ -31,6 +31,7 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
31
31
  import Decimal from 'decimal.js';
32
32
  import { isBoolean } from 'lodash-es';
33
33
  import dayjs from 'dayjs';
34
+
34
35
  // 临时变量
35
36
  var flatItem;
36
37
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
@@ -43,8 +44,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
43
44
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
44
45
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
45
46
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
46
- _defineProperty(_assertThisInitialized(_this), "window", void 0);
47
- // WindowPlugin 实例
48
47
  _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
49
48
  _this.hooks = {};
50
49
  return _this;
@@ -59,8 +58,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
59
58
  this.core = core;
60
59
  this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
61
60
  this.store = options === null || options === void 0 ? void 0 : options.store;
62
- this.window = core.getPlugin('window');
63
- case 4:
61
+ case 3:
64
62
  case "end":
65
63
  return _context.stop();
66
64
  }
@@ -115,12 +113,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
115
113
  // 最终直接匹配 holder 是否相同
116
114
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
117
115
  }
118
- }, {
119
- key: "getWalletPassEvaluator",
120
- value: function getWalletPassEvaluator() {
121
- var _this$window$getWalle, _this$window;
122
- return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
123
- }
124
116
 
125
117
  // 判断discountList 是否可以对当前productList生效
126
118
  }, {
@@ -130,7 +122,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
130
122
  var oldDiscountList = _ref.oldDiscountList,
131
123
  newDiscountList = _ref.newDiscountList,
132
124
  productList = _ref.productList,
133
- orderTotalAmount = _ref.orderTotalAmount,
134
125
  holders = _ref.holders,
135
126
  isFormSubject = _ref.isFormSubject;
136
127
  // 首先检查是否有新的优惠券可应用
@@ -165,7 +156,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
165
156
  var result = this.calcDiscount({
166
157
  discountList: mergedDiscountList,
167
158
  productList: _toConsumableArray(productList),
168
- orderTotalAmount: orderTotalAmount,
169
159
  holders: holders,
170
160
  isFormSubject: isFormSubject
171
161
  }, {
@@ -292,15 +282,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
292
282
  var discountList = _ref2.discountList,
293
283
  productList = _ref2.productList,
294
284
  holders = _ref2.holders,
295
- isFormSubject = _ref2.isFormSubject,
296
- orderTotalAmount = _ref2.orderTotalAmount;
297
- // 识别出来是不是在编辑的界面里又新增了商品
298
- // 这种情况下,如果有可用的优惠券,也会自动勾选上
299
- var isEditModeAddNewProduct = productList.find(function (n) {
300
- return n.booking_id;
301
- }) && productList.find(function (n) {
302
- return !n.booking_id;
303
- });
285
+ isFormSubject = _ref2.isFormSubject;
304
286
  var editModeDiscount = [];
305
287
  var addModeDiscount = [];
306
288
  discountList.forEach(function (discount) {
@@ -514,6 +496,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
514
496
  // 🔥 扁平化商品列表(包含主商品和bundle子商品)
515
497
  var flattenedList = flattenProductsWithBundle(productList);
516
498
 
499
+ // 识别出来是不是在编辑的界面里又新增了商品
500
+ // 这种情况下,如果有可用的优惠券,也会自动勾选上
501
+ var isEditModeAddNewProduct = flattenedList.find(function (n) {
502
+ return n.booking_id;
503
+ }) && flattenedList.find(function (n) {
504
+ return !n.booking_id;
505
+ });
506
+
517
507
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
518
508
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
519
509
  var _ref3, _a$original_price, _ref4, _b$original_price;
@@ -541,57 +531,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
541
531
  return priceB.minus(priceA).toNumber();
542
532
  });
543
533
 
544
- // 🔥 为每个折扣卡/商品券执行策略检查并附加config
545
- var evaluator = this.getWalletPassEvaluator();
546
- if (evaluator) {
547
- addModeDiscount.forEach(function (discount) {
548
- var discountType = discount.tag || discount.type;
549
- // 只对 good_pass 和 discount_card 类型执行策略检查
550
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
551
- var _discount$limited_rel, _discount$limited_rel2;
552
- // 转换 discount 为 Voucher 格式
553
- var voucher = {
554
- id: discount.id,
555
- amount: Number(discount.par_value || 0),
556
- balance: Number(discount.balance || 0),
557
- type: discountType,
558
- product_id: discount.product_id,
559
- unified_available_status: 1,
560
- available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
561
- available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
562
- };
563
-
564
- // 转换 sortedFlattenedList 为 Product 格式
565
- var productsForEvaluate = sortedFlattenedList.map(function (item) {
566
- return {
567
- product_id: item.id,
568
- price: item.price || 0,
569
- quantity: item.quantity || item.num || 1,
570
- selling_price: item.price || 0
571
- };
572
- });
573
-
574
- // 调用策略检查
575
- var result = evaluator.checkVoucherAvailability({
576
- orderTotalAmount: orderTotalAmount,
577
- products: productsForEvaluate,
578
- vouchers: [voucher]
579
- });
580
-
581
- // 将 config 附加到 discount 对象
582
- if (result.isAvailable) {
583
- discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
584
- isAvailable: true
585
- });
586
- } else {
587
- discount.config = {
588
- isAvailable: false
589
- };
590
- }
591
- }
592
- });
593
- }
594
-
595
534
  /**
596
535
  // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
597
536
  const sortedProductList = [...productList].sort((a, b) => {
@@ -612,22 +551,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
612
551
  // 标记已使用的优惠券
613
552
  var usedDiscounts = new Map();
614
553
 
615
- // 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
616
- var usedProductIdCounts = new Map();
617
-
618
- // 🔥 统计每张折扣卡的 applicableProductLimit 已使用次数(跨商品全局计数)
619
- var usedDiscountCardLimitCounts = new Map();
620
-
621
- // 🔥 预先将 editModeDiscount 中的折扣卡计入 applicableProductLimit 已使用次数
622
- editModeDiscount.forEach(function (discount) {
623
- var discountType = discount.tag || discount.type;
624
- if (['discount_card', 'product_discount_card'].includes(discountType)) {
625
- var _discount$metadata4;
626
- var currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
627
- usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.num) || 1));
628
- }
629
- });
630
-
631
554
  // 记录每个优惠券适用的商品ID
632
555
  var discountApplicability = new Map();
633
556
 
@@ -857,7 +780,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
857
780
  originProduct = flatItem.originProduct;
858
781
  }
859
782
  addModeDiscount.forEach(function (discount) {
860
- var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
783
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
861
784
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
862
785
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
863
786
  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;
@@ -868,7 +791,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
868
791
  var timeLimit = true;
869
792
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
870
793
  // 是符合折扣的商品
871
- 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;
794
+ var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
872
795
 
873
796
  // 编辑的商品 使用了优惠券不可用
874
797
  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) {
@@ -881,8 +804,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
881
804
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
882
805
 
883
806
  // 判断优惠券是否适用于该商品
884
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
885
- var _discountApplicabilit, _discount$metadata5, _discount$metadata6;
807
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
808
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
886
809
  // 记录此优惠券适用的商品
887
810
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
888
811
 
@@ -898,15 +821,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
898
821
  type: discountType,
899
822
  tag: discountType,
900
823
  discount: {
901
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_card_type,
824
+ discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
902
825
  fixed_amount: product.price,
903
- discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.discount_calculation_mode,
826
+ discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
904
827
  resource_id: discount.id,
905
828
  title: discount.format_title,
906
829
  original_amount: product.price || product.origin_total,
907
830
  pre_value: discount.par_value,
908
- product_id: originProduct.id,
909
- discount_product_id: discount.product_id
831
+ product_id: originProduct.id
910
832
  },
911
833
  metadata: {
912
834
  num: num,
@@ -925,7 +847,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
925
847
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
926
848
  // 🔥 使用扁平化后的列表进行处理
927
849
  sortedFlattenedList.forEach(function (flatItem, index) {
928
- var _product10, _product$discount_lis2, _product11, _selectedDiscount$con;
850
+ var _product10, _product$discount_lis2, _product11;
929
851
  // 获取商品数据
930
852
  var product, originProduct;
931
853
  if (flatItem.type === 'main') {
@@ -967,16 +889,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
967
889
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
968
890
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
969
891
  var _product$discount_lis3, _product$discount_lis4;
970
- // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
971
- var discountType = discount.tag || discount.type;
972
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
973
- var _discount$config2;
974
- // 如果策略检查后没有config,说明不可用
975
- if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
976
- return false;
977
- }
978
- }
979
-
980
892
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
981
893
  // 商品券时主商品价格为0不可用
982
894
  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;
@@ -989,37 +901,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
989
901
  // 如果优惠券已被使用,则跳过
990
902
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
991
903
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
992
-
993
- // 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
994
- if ((discount.tag || discount.type) === 'good_pass') {
995
- var _discount$config3;
996
- var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
997
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
998
- var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
999
- if (currentUsedCount >= maxUsagePerOrder) {
1000
- return false;
1001
- }
1002
- }
1003
- }
1004
-
1005
- // 🔥 检查折扣卡的 applicableProductLimit 限制:折扣卡可使用的最大次数(跨商品全局)
1006
- var discountTypeForLimit = discount.tag || discount.type;
1007
- if (['discount_card', 'product_discount_card'].includes(discountTypeForLimit)) {
1008
- var _discount$config4;
1009
- var applicableProductLimitConfig = ((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.applicableProductLimit) || 0;
1010
- if (applicableProductLimitConfig > 0) {
1011
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
1012
- if (currentUsedLimitCount >= applicableProductLimitConfig) {
1013
- return false;
1014
- }
1015
- }
1016
- }
1017
904
  var limitedData = discount.limited_relation_product_data;
1018
- var timeLimit = true;
1019
- timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
1020
- if (!timeLimit) {
1021
- return false;
1022
- }
905
+
1023
906
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
1024
907
  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;
1025
908
  var isHolderMatch = _this3.checkHolderMatch(discount, {
@@ -1028,12 +911,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1028
911
  }, holders);
1029
912
  // 如果 holder 不匹配,则不适用
1030
913
  if (!isHolderMatch) return false;
914
+ var timeLimit = true;
915
+ timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
916
+ if (!timeLimit) {
917
+ return false;
918
+ }
1031
919
 
1032
920
  // 判断优惠券是否适用于该商品
1033
921
  if (limitedData.type === 'product_all') {
1034
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1035
- return false;
1036
- }
1037
922
  // 检查 package_sub_item_usage_rules
1038
923
  if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
1039
924
  return false;
@@ -1192,39 +1077,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1192
1077
  return;
1193
1078
  }
1194
1079
 
1195
- // 是否需要拆分(商品券需要拆分,折扣卡在 applicableProductLimit > 0 时也需要拆分)
1196
- var discountType = selectedDiscount.tag || selectedDiscount.type;
1197
- var isGoodPass = discountType === 'good_pass';
1198
- var isDiscountCard = ['discount_card', 'product_discount_card'].includes(discountType);
1199
- var applicableProductLimit = ((_selectedDiscount$con = selectedDiscount.config) === null || _selectedDiscount$con === void 0 ? void 0 : _selectedDiscount$con.applicableProductLimit) || 0;
1200
-
1201
- // 商品券始终需要拆分,折扣卡在 applicableProductLimit > 0 时需要拆分
1202
- var isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
1080
+ // 是否需要拆分(商品券需要拆分)
1081
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
1203
1082
 
1204
1083
  // 需要拆分出来的数量
1205
1084
  var totalQuantity = product.quantity || product.num || 1;
1206
1085
  var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1207
1086
  return (item.tag || item.type) === 'good_pass';
1208
1087
  }).length;
1209
-
1210
- // 🔥 计算最大使用次数限制
1211
- var maxUsageLimit;
1212
- if (isGoodPass) {
1213
- // 商品券:使用 maxUsagePerOrder 限制
1214
- maxUsageLimit = availableGoodPassCount;
1215
- if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
1216
- maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
1217
- }
1218
- } else if (isDiscountCard && applicableProductLimit > 0) {
1219
- // 折扣卡:使用 applicableProductLimit 限制(一个商品使用一次折扣卡算1次)
1220
- // 需要减去已使用次数(跨商品全局计数)
1221
- var usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
1222
- maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
1223
- } else {
1224
- // 其他情况不拆分
1225
- maxUsageLimit = 1;
1226
- }
1227
- var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
1088
+ var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
1228
1089
  var arr = [];
1229
1090
 
1230
1091
  // 🔥 主商品和bundle子商品分别处理
@@ -1234,31 +1095,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1234
1095
  arr.push(_this3.hooks.setProduct(originProduct, {
1235
1096
  discount_list: [],
1236
1097
  quantity: totalQuantity - splitCount,
1237
- _id: product._id.split('___')[0],
1238
- total: product.origin_total || product.total
1098
+ _id: product._id.split('___')[0]
1239
1099
  }));
1240
1100
  }
1241
1101
  for (var i = 0; i < splitCount; i++) {
1242
- var _product$discount_lis10, _originProduct, _currentSelectedDisco, _currentSelectedDisco2;
1243
- // 商品券:每个拆分商品使用不同的商品券(从 applicableDiscounts 按索引取)
1244
- // 折扣卡:所有拆分商品使用同一张折扣卡(selectedDiscountCard applicableDiscounts[0]
1245
- var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
1102
+ var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1103
+ // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1104
+ var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1246
1105
  // 标记优惠券为已使用
1247
- usedDiscounts.set(currentSelectedDiscount.id, true);
1248
- // 🔥 更新 product_id 使用计数
1249
- if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === 'good_pass') {
1250
- var currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
1251
- usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
1252
- }
1253
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1254
- var currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
1255
- if (['discount_card', 'product_discount_card'].includes(currentDiscountTypeForCount)) {
1256
- var currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
1257
- usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
1258
- }
1106
+ usedDiscounts.set(_selectedDiscount.id, true);
1259
1107
 
1260
1108
  // 记录实际应用了优惠券的商品信息
1261
- var appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
1109
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
1262
1110
 
1263
1111
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
1264
1112
  var productOriginTotal = product.origin_total || product.total || 0;
@@ -1273,8 +1121,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1273
1121
 
1274
1122
  // 计算使用折扣卡/商品券以后,单个商品的总 total
1275
1123
  // 🔥 检查是否是 order_level 固定金额折扣卡
1276
- var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1277
- var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1124
+ var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
1125
+ var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
1278
1126
  var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
1279
1127
  var targetProductTotal = void 0;
1280
1128
  var amount = void 0;
@@ -1286,40 +1134,35 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1286
1134
  targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1287
1135
  } else {
1288
1136
  // item_level 或其他类型:使用原有逻辑
1289
- targetProductTotal = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
1137
+ targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1290
1138
  amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1291
1139
  }
1292
- var currentDiscountType = currentSelectedDiscount.tag === 'product_discount_card' ? 'discount_card' : currentSelectedDiscount.tag;
1293
-
1294
- // 计算实际折扣金额
1295
- var actualDiscountAmount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1296
- var currentIsGoodPass = currentDiscountType === 'good_pass';
1140
+ var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1141
+ var isGoodPass = discountType === 'good_pass';
1297
1142
  var discountDetail = {
1298
- amount: actualDiscountAmount,
1299
- type: currentDiscountType,
1143
+ amount: amount,
1144
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
1300
1145
  discount: {
1301
- discount_card_type: currentSelectedDiscount === null || currentSelectedDiscount === void 0 || (_currentSelectedDisco = currentSelectedDiscount.metadata) === null || _currentSelectedDisco === void 0 ? void 0 : _currentSelectedDisco.discount_card_type,
1302
- fixed_amount: actualDiscountAmount,
1303
- discount_calculation_mode: currentSelectedDiscount === null || currentSelectedDiscount === void 0 || (_currentSelectedDisco2 = currentSelectedDiscount.metadata) === null || _currentSelectedDisco2 === void 0 ? void 0 : _currentSelectedDisco2.discount_calculation_mode,
1304
- resource_id: currentSelectedDiscount.id,
1305
- title: currentSelectedDiscount.format_title,
1146
+ discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1147
+ fixed_amount: amount,
1148
+ discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1149
+ resource_id: _selectedDiscount.id,
1150
+ title: _selectedDiscount.format_title,
1306
1151
  original_amount: product.price,
1307
1152
  product_id: originProduct.id,
1308
- percent: currentSelectedDiscount.par_value,
1309
- discount_product_id: currentSelectedDiscount.product_id
1153
+ percent: _selectedDiscount.par_value
1310
1154
  },
1311
- // 前端使用的num数量,为了计算优惠金额(拆分时为1)
1312
- _num: isNeedSplit ? 1 : product.num,
1313
- config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
1155
+ // 前端使用的num数量,为了计算优惠金额
1156
+ _num: isGoodPass ? 1 : product.num,
1314
1157
  metadata: _objectSpread({
1315
1158
  num: 1,
1316
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
1159
+ discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
1317
1160
  }, productDiscountDifference !== undefined && {
1318
1161
  product_discount_difference: productDiscountDifference
1319
1162
  })
1320
1163
  };
1321
1164
  appliedProducts.push(discountDetail);
1322
- appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
1165
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
1323
1166
  var total = targetProductTotal;
1324
1167
  if (product.options) {
1325
1168
  total = product.options.reduce(function (accumulator, currentValue) {
@@ -1332,9 +1175,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1332
1175
  // 记录应用了优惠券的商品
1333
1176
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
1334
1177
  if (product.isClient) {
1178
+ debugger;
1335
1179
  arr.push(_this3.hooks.setProduct(originProduct, {
1336
1180
  discount_list: [discountDetail],
1337
- price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
1181
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1338
1182
  quantity: isNeedSplit ? 1 : product.quantity,
1339
1183
  origin_total: getProductOriginTotalPrice({
1340
1184
  product: {
@@ -1345,15 +1189,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1345
1189
  }),
1346
1190
  variant: originProduct._productInit.variant,
1347
1191
  original_price: new Decimal(product.price || 0).toNumber(),
1348
- total: targetProductTotal
1192
+ total: total
1349
1193
  }));
1350
1194
  } else {
1351
1195
  arr.push(_this3.hooks.setProduct(originProduct, {
1352
1196
  discount_list: [discountDetail],
1353
- _id: product._id.split('___')[0] + '___' + currentSelectedDiscount.id + '_' + i + '_' + index,
1354
- price: currentIsGoodPass ? 0 : product.price,
1197
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
1198
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1355
1199
  quantity: isNeedSplit ? 1 : product.quantity,
1356
- total: targetProductTotal,
1200
+ total: total,
1357
1201
  origin_total: productOriginTotal,
1358
1202
  main_product_selling_price: targetProductTotal
1359
1203
  }));
@@ -1361,336 +1205,80 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1361
1205
  }
1362
1206
  processedProductsMap.set(product._id, arr);
1363
1207
  } else {
1364
- // 🔥 bundle子商品:支持拆分(商品券和折扣卡在 applicableProductLimit > 0 时都需要拆分)
1208
+ // 🔥 bundle子商品:支持拆分
1365
1209
  var processedItems = [];
1366
1210
  if (isNeedSplit) {
1367
- // 需要拆分数量(商品券或折扣卡有 applicableProductLimit 限制)
1211
+ // 商品券:需要拆分数量
1368
1212
  var discountNum = splitCount;
1369
1213
  var normalNum = totalQuantity - discountNum;
1370
1214
 
1371
- // 生成有折扣的商品(每个拆分商品 num: 1)
1215
+ // 生成有折扣的商品(每张商品券对应 num: 1)
1372
1216
  for (var _i = 0; _i < discountNum; _i++) {
1373
- var _currentBundleDiscoun, _currentBundleDiscoun2;
1374
- // 商品券:每个拆分商品使用不同的商品券
1375
- // 折扣卡:所有拆分商品使用同一张折扣卡
1376
- var currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[_i] : selectedDiscountCard || applicableDiscounts[0];
1377
- usedDiscounts.set(currentBundleDiscount.id, true);
1378
- // 🔥 更新 product_id 使用计数
1379
- if ((currentBundleDiscount.tag || currentBundleDiscount.type) === 'good_pass') {
1380
- var _currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1381
- usedProductIdCounts.set(currentBundleDiscount.product_id, _currentCount + 1);
1382
- }
1383
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1384
- var bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
1385
- if (['discount_card', 'product_discount_card'].includes(bundleDiscountTypeForCount)) {
1386
- var currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1387
- usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
1388
- }
1217
+ var _selectedDiscount2$me;
1218
+ var _selectedDiscount2 = applicableDiscounts[_i];
1219
+ usedDiscounts.set(_selectedDiscount2.id, true);
1389
1220
 
1390
1221
  // 🔥 生成唯一的 _id
1391
1222
  var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
1392
-
1393
- // 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
1394
- var discountedPrice = getDiscountAmount(currentBundleDiscount, product.origin_total, product.origin_total);
1395
- var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1396
-
1397
- // 确定折扣类型
1398
- var bundleDiscountType = currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : currentBundleDiscount.tag;
1399
1223
  var _discountDetail = {
1400
- amount: bundleDiscountAmount,
1401
- type: bundleDiscountType,
1224
+ amount: product.origin_total,
1225
+ type: 'good_pass',
1402
1226
  discount: {
1403
- discount_card_type: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun = currentBundleDiscount.metadata) === null || _currentBundleDiscoun === void 0 ? void 0 : _currentBundleDiscoun.discount_card_type,
1404
- discount_calculation_mode: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun2 = currentBundleDiscount.metadata) === null || _currentBundleDiscoun2 === void 0 ? void 0 : _currentBundleDiscoun2.discount_calculation_mode,
1405
- fixed_amount: bundleDiscountAmount,
1406
- resource_id: currentBundleDiscount.id,
1407
- title: currentBundleDiscount.format_title,
1227
+ fixed_amount: product.origin_total,
1228
+ discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
1229
+ resource_id: _selectedDiscount2.id,
1230
+ title: _selectedDiscount2.format_title,
1408
1231
  original_amount: product.origin_total,
1409
- product_id: product.id,
1410
- percent: currentBundleDiscount.par_value,
1411
- discount_product_id: currentBundleDiscount.product_id
1232
+ product_id: product.id
1412
1233
  },
1413
1234
  metadata: {
1414
1235
  // 🔥 使用拆分后的唯一 _id
1415
1236
  custom_product_bundle_map_id: uniqueId,
1416
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1237
+ discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
1417
1238
  num: 1
1418
1239
  },
1419
- _num: 1,
1420
- config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
1240
+ _num: 1
1421
1241
  };
1422
1242
 
1423
1243
  // 记录实际应用的折扣
1424
- var _appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1244
+ var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
1425
1245
  _appliedProducts.push(_discountDetail);
1426
- appliedDiscountProducts.set(currentBundleDiscount.id, _appliedProducts);
1246
+ appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
1427
1247
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1428
1248
  // 🔥 使用唯一的 _id
1429
1249
  _id: uniqueId,
1430
1250
  num: 1,
1431
1251
  quantity: 1,
1432
- price: discountedPrice,
1433
- // 折扣后的价格
1434
- total: discountedPrice,
1252
+ price: 0,
1253
+ // 商品券价格为0
1254
+ total: 0,
1435
1255
  discount_list: [_discountDetail],
1436
1256
  processed: true,
1437
- _discountId: currentBundleDiscount.id
1257
+ _discountId: _selectedDiscount2.id
1438
1258
  }));
1439
1259
  }
1440
1260
 
1441
- // 🔥 对拆分后的剩余商品继续匹配其他可用折扣(而不是等到下次执行才应用)
1442
- var remainingNum = normalNum;
1443
- var continueSplitIndex = discountNum;
1444
- while (remainingNum > 0) {
1445
- var _nextSelectedDiscount;
1446
- // 重新查找适用于剩余商品的可用折扣(已使用的会被自动过滤掉)
1447
- var nextApplicableDiscounts = sortedDiscountList.filter(function (nextDiscount) {
1448
- var _product$discount_lis11;
1449
- var nextDiscountType = nextDiscount.tag || nextDiscount.type;
1450
- // 检查策略可用性
1451
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1452
- var _nextDiscount$config;
1453
- if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
1454
- return false;
1455
- }
1456
- }
1457
- // 折扣卡时总价为0时不可用
1458
- if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.find(function (n) {
1459
- var _n$discount2;
1460
- return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
1461
- })) && nextDiscountType !== 'good_pass') return false;
1462
-
1463
- // 商品券已被使用则跳过
1464
- if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
1465
-
1466
- // 检查 maxUsagePerOrder 限制
1467
- if (nextDiscountType === 'good_pass') {
1468
- var _nextDiscount$config2;
1469
- var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
1470
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1471
- var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1472
- if (currentUsedCount >= maxUsagePerOrder) {
1473
- return false;
1474
- }
1475
- }
1476
- }
1477
-
1478
- // 检查折扣卡的 applicableProductLimit 限制
1479
- if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1480
- var _nextDiscount$config3;
1481
- var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
1482
- if (limitConfig > 0) {
1483
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1484
- if (currentUsedLimitCount >= limitConfig) {
1485
- return false;
1486
- }
1487
- }
1488
- }
1489
- var limitedData = nextDiscount.limited_relation_product_data;
1490
- if (limitedData.type === 'product_all') {
1491
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1492
- return false;
1493
- }
1494
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1495
- return false;
1496
- }
1497
- return true;
1498
- } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1499
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1500
- return false;
1501
- }
1502
- return true;
1503
- }
1504
- return false;
1505
- });
1506
-
1507
- // 没有更多可用折扣,剩余商品无折扣存储
1508
- if (nextApplicableDiscounts.length === 0) {
1509
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1510
- _id: "".concat(flatItem._id, "_split_rest"),
1511
- num: remainingNum,
1512
- quantity: remainingNum,
1513
- discount_list: [],
1514
- processed: true
1515
- }));
1516
- break;
1517
- }
1518
-
1519
- // 选择最优折扣
1520
- var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
1521
- return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1522
- });
1523
- var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1524
-
1525
- // 判断新折扣是否需要拆分
1526
- var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1527
- var nextIsGoodPass = nextDiscType === 'good_pass';
1528
- var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
1529
- var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
1530
- var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1531
- if (!nextIsNeedSplit) {
1532
- var _nextBundleDiscount$m, _flatItem$parentProdu9;
1533
- // 🔥 不需要拆分:直接应用折扣到所有剩余商品
1534
- var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1535
- usedDiscounts.set(nextBundleDiscount.id, true);
1536
- if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
1537
- var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1538
- usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1539
- }
1540
- var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1541
- if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
1542
- var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1543
- usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
1544
- }
1545
- var nextOriginTotal = product.original_price || product.price || 0;
1546
- var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1547
- var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
1548
- var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1549
- var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
1550
- var nextDiscountDetail = {
1551
- amount: nextDiscountAmount * remainingNum,
1552
- type: nextBundleDiscType,
1553
- discount: {
1554
- discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
1555
- fixed_amount: nextDiscountAmount,
1556
- resource_id: nextBundleDiscount.id,
1557
- title: nextBundleDiscount.format_title,
1558
- original_amount: product.original_price,
1559
- product_id: product.id,
1560
- percent: nextBundleDiscount.par_value,
1561
- discount_product_id: nextBundleDiscount.product_id
1562
- },
1563
- metadata: {
1564
- custom_product_bundle_map_id: nextUniqueId,
1565
- num: remainingNum
1566
- },
1567
- config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
1568
- _num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1569
- };
1570
- var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1571
- nextAppliedProducts.push(nextDiscountDetail);
1572
- appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1573
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1574
- _id: nextUniqueId,
1575
- num: remainingNum,
1576
- quantity: remainingNum,
1577
- total: nextTargetTotal,
1578
- price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1579
- discount_list: [nextDiscountDetail],
1580
- processed: true
1581
- }));
1582
- remainingNum = 0;
1583
- break;
1584
- }
1585
-
1586
- // 🔥 需要拆分:计算最大使用次数
1587
- var nextMaxUsageLimit = void 0;
1588
- if (nextIsGoodPass) {
1589
- var _nextSelectedDiscount2;
1590
- var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
1591
- return (item.tag || item.type) === 'good_pass';
1592
- }).length;
1593
- nextMaxUsageLimit = nextGoodPassCount;
1594
- if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
1595
- var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1596
- nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
1597
- }
1598
- } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1599
- var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1600
- nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
1601
- } else {
1602
- nextMaxUsageLimit = 1;
1603
- }
1604
- var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1605
- if (nextSplitCount === 0) {
1606
- // 已达使用上限,剩余商品无折扣存储
1607
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1608
- _id: "".concat(flatItem._id, "_split_rest"),
1609
- num: remainingNum,
1610
- quantity: remainingNum,
1611
- discount_list: [],
1612
- processed: true
1613
- }));
1614
- break;
1615
- }
1616
-
1617
- // 生成有折扣的商品
1618
- for (var j = 0; j < nextSplitCount; j++) {
1619
- var _nextBundleDiscount$m2;
1620
- var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1621
- usedDiscounts.set(_nextBundleDiscount.id, true);
1622
- if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
1623
- var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
1624
- usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
1625
- }
1626
- var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
1627
- if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
1628
- var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
1629
- usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
1630
- }
1631
- var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1632
- var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
1633
- var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1634
- var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
1635
- var _nextDiscountDetail = {
1636
- amount: nextBundleDiscAmount,
1637
- type: nextBundleDiscTypeStr,
1638
- discount: {
1639
- discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
1640
- fixed_amount: nextBundleDiscAmount,
1641
- resource_id: _nextBundleDiscount.id,
1642
- title: _nextBundleDiscount.format_title,
1643
- original_amount: product.origin_total,
1644
- product_id: product.id,
1645
- percent: _nextBundleDiscount.par_value,
1646
- discount_product_id: _nextBundleDiscount.product_id
1647
- },
1648
- metadata: {
1649
- custom_product_bundle_map_id: _nextUniqueId,
1650
- num: 1
1651
- },
1652
- _num: 1,
1653
- config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
1654
- };
1655
- var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
1656
- _nextAppliedProducts.push(_nextDiscountDetail);
1657
- appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
1658
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1659
- _id: _nextUniqueId,
1660
- num: 1,
1661
- quantity: 1,
1662
- price: nextDiscountedPrice,
1663
- total: nextDiscountedPrice,
1664
- discount_list: [_nextDiscountDetail],
1665
- processed: true,
1666
- _discountId: _nextBundleDiscount.id
1667
- }));
1668
- continueSplitIndex++;
1669
- }
1670
- remainingNum -= nextSplitCount;
1261
+ // 生成无折扣的商品(剩余数量)
1262
+ if (normalNum > 0) {
1263
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1264
+ // 🔥 为剩余商品生成唯一的 _id
1265
+ _id: "".concat(flatItem._id, "_split_rest"),
1266
+ num: normalNum,
1267
+ quantity: normalNum,
1268
+ discount_list: [],
1269
+ processed: true
1270
+ }));
1671
1271
  }
1672
1272
  } else {
1673
- var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu10;
1674
- // 不拆分:直接应用折扣
1675
- var _currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1676
- usedDiscounts.set(_currentBundleDiscount.id, true);
1677
- // 🔥 更新 product_id 使用计数
1678
- if ((_currentBundleDiscount.tag || _currentBundleDiscount.type) === 'good_pass') {
1679
- var _currentCount2 = usedProductIdCounts.get(_currentBundleDiscount.product_id) || 0;
1680
- usedProductIdCounts.set(_currentBundleDiscount.product_id, _currentCount2 + 1);
1681
- }
1682
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(不拆分时按商品数量计数)
1683
- var noSplitDiscountType = _currentBundleDiscount.tag || _currentBundleDiscount.type;
1684
- if (['discount_card', 'product_discount_card'].includes(noSplitDiscountType)) {
1685
- var bundleQuantity = product.num || 1;
1686
- var currentNoSplitCount = usedDiscountCardLimitCounts.get(_currentBundleDiscount.id) || 0;
1687
- usedDiscountCardLimitCounts.set(_currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
1688
- }
1273
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
1274
+ // 折扣卡:不拆分数量,直接应用
1275
+ var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1276
+ usedDiscounts.set(_selectedDiscount3.id, true);
1689
1277
  var _productOriginTotal = product.original_price || product.price || 0;
1690
1278
 
1691
1279
  // 🔥 检查是否是 order_level 固定金额折扣卡
1692
- var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1693
- var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1280
+ var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
1281
+ var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
1694
1282
  var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
1695
1283
  var _targetProductTotal;
1696
1284
  var fixedAmountPerItem;
@@ -1702,45 +1290,40 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1702
1290
  _targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1703
1291
  } else {
1704
1292
  // item_level 或其他类型:使用原有逻辑
1705
- _targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
1293
+ _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1706
1294
  fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1707
1295
  }
1708
-
1709
- // 计算实际折扣金额
1710
- var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1711
-
1296
+ debugger;
1712
1297
  // 🔥 使用当前的 _id 作为唯一标识
1713
1298
  var _uniqueId = flatItem._id;
1714
1299
  var _discountDetail2 = {
1715
- amount: bundleActualDiscountAmount * (product.num || 1),
1716
- type: _currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _currentBundleDiscount.tag,
1300
+ amount: fixedAmountPerItem * (product.num || 1),
1301
+ type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
1717
1302
  discount: {
1718
- discount_card_type: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun3 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun3 === void 0 ? void 0 : _currentBundleDiscoun3.discount_card_type,
1719
- fixed_amount: bundleActualDiscountAmount,
1720
- discount_calculation_mode: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun4 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun4 === void 0 ? void 0 : _currentBundleDiscoun4.discount_calculation_mode,
1721
- resource_id: _currentBundleDiscount.id,
1722
- title: _currentBundleDiscount.format_title,
1303
+ discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
1304
+ fixed_amount: fixedAmountPerItem,
1305
+ discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
1306
+ resource_id: _selectedDiscount3.id,
1307
+ title: _selectedDiscount3.format_title,
1723
1308
  original_amount: product.original_price,
1724
1309
  product_id: product.id,
1725
- percent: _currentBundleDiscount.par_value,
1726
- discount_product_id: _currentBundleDiscount.product_id
1310
+ percent: _selectedDiscount3.par_value
1727
1311
  },
1728
1312
  metadata: _objectSpread({
1729
1313
  // 🔥 使用唯一的 _id
1730
1314
  custom_product_bundle_map_id: _uniqueId,
1731
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1315
+ discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
1732
1316
  num: product.num || 1
1733
1317
  }, _productDiscountDifference !== undefined && {
1734
1318
  product_discount_difference: _productDiscountDifference
1735
1319
  }),
1736
- config: _currentBundleDiscount === null || _currentBundleDiscount === void 0 ? void 0 : _currentBundleDiscount.config,
1737
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.num) || 1)
1320
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1738
1321
  };
1739
1322
 
1740
1323
  // 记录实际应用的折扣
1741
- var _appliedProducts2 = appliedDiscountProducts.get(_currentBundleDiscount.id) || [];
1324
+ var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
1742
1325
  _appliedProducts2.push(_discountDetail2);
1743
- appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
1326
+ appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
1744
1327
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1745
1328
  total: _targetProductTotal,
1746
1329
  price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
@@ -1865,7 +1448,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1865
1448
  product_id: bundleItem.product_id,
1866
1449
  price: item.price,
1867
1450
  num: item.num,
1868
- quantity: item.num,
1869
1451
  discount_list: updatedDiscountList
1870
1452
  }));
1871
1453
  });
@@ -1889,7 +1471,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1889
1471
  product_id: bundleItem.product_id,
1890
1472
  price: item.price,
1891
1473
  num: item.num,
1892
- quantity: item.num,
1893
1474
  discount_list: _updatedDiscountList
1894
1475
  }));
1895
1476
  } else {
@@ -1904,8 +1485,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1904
1485
 
1905
1486
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1906
1487
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1907
- var _discount$metadata7, _discount$metadata8;
1908
- if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
1488
+ var _discount$metadata6, _discount$metadata7;
1489
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
1909
1490
  // bundle的discount_list保持不变
1910
1491
  return discount;
1911
1492
  }
@@ -1913,7 +1494,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1913
1494
  return _objectSpread(_objectSpread({}, discount), {}, {
1914
1495
  // num: 1,
1915
1496
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1916
- 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,
1497
+ 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,
1917
1498
  num: 1
1918
1499
  })
1919
1500
  });
@@ -1958,8 +1539,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1958
1539
  quantity: 1,
1959
1540
  discount_list: updatedMainDiscountList,
1960
1541
  bundle: newBundleWithDiscount,
1961
- total: newTotalWithDiscount,
1962
- origin_total: newOriginTotalWithDiscount
1542
+ total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
1543
+ origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
1963
1544
  })));
1964
1545
 
1965
1546
  // 第二个:包含原始bundle (qty=原quantity-1)
@@ -1978,8 +1559,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1978
1559
 
1979
1560
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1980
1561
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1981
- var _discount$metadata9, _discount$metadata10;
1982
- if (discount !== null && discount !== void 0 && (_discount$metadata9 = discount.metadata) !== null && _discount$metadata9 !== void 0 && _discount$metadata9.custom_product_bundle_map_id) {
1562
+ var _discount$metadata8, _discount$metadata9;
1563
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
1983
1564
  // bundle的discount_list保持不变
1984
1565
  return discount;
1985
1566
  }
@@ -1987,7 +1568,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1987
1568
  return _objectSpread(_objectSpread({}, discount), {}, {
1988
1569
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1989
1570
  num: mainProductQuantity - 1,
1990
- 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
1571
+ 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
1991
1572
  })
1992
1573
  // num: mainProductQuantity - 1,
1993
1574
  });
@@ -2054,11 +1635,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2054
1635
  processedBundleItems.forEach(function (item) {
2055
1636
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
2056
1637
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
2057
- var _discount$metadata11;
1638
+ var _discount$metadata10;
2058
1639
  return _objectSpread(_objectSpread({}, discount), {}, {
2059
1640
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2060
1641
  num: item.num,
2061
- 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
1642
+ 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
2062
1643
  })
2063
1644
  // num: item.num, // 使用拆分后的 num
2064
1645
  });
@@ -2068,7 +1649,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2068
1649
  product_id: bundleItem.product_id,
2069
1650
  price: item.price,
2070
1651
  num: item.num,
2071
- quantity: item.num,
2072
1652
  discount_list: updatedDiscountList
2073
1653
  }));
2074
1654
  });
@@ -2108,8 +1688,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2108
1688
  // 累加bundle的价格(只累加一次)
2109
1689
  if (newBundle.length > 0) {
2110
1690
  newBundle.forEach(function (item) {
2111
- var _item$discount_list3;
2112
1691
  newTotal += Number(item.price) * Number(item.num);
1692
+ });
1693
+
1694
+ // 计算原始总价(不考虑折扣)
1695
+ newBundle.forEach(function (item) {
1696
+ var _item$discount_list3;
2113
1697
  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;
2114
1698
  newOriginTotal += Number(originalPrice) * Number(item.num);
2115
1699
  });
@@ -2124,6 +1708,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2124
1708
  return accumulator.add(currentPrice.mul(currentNum));
2125
1709
  }, new Decimal(newTotal)).toNumber();
2126
1710
  }
1711
+ newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1712
+ newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
2127
1713
 
2128
1714
  // 生成最终的主商品
2129
1715
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {