@pisell/pisellos 2.1.91 → 2.1.93

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 (102) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +497 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +165 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/index.d.ts +1 -0
  30. package/dist/modules/Discount/index.js +40 -11
  31. package/dist/modules/Discount/types.d.ts +17 -0
  32. package/dist/modules/Payment/index.d.ts +2 -1
  33. package/dist/modules/Payment/index.js +10 -7
  34. package/dist/modules/Payment/utils.js +3 -0
  35. package/dist/modules/Payment/walletpass.d.ts +23 -0
  36. package/dist/modules/Payment/walletpass.js +191 -95
  37. package/dist/modules/Product/index.d.ts +1 -1
  38. package/dist/modules/Rules/index.d.ts +9 -5
  39. package/dist/modules/Rules/index.js +538 -118
  40. package/dist/modules/Rules/types.d.ts +1 -0
  41. package/dist/modules/Summary/types.d.ts +2 -0
  42. package/dist/modules/Summary/utils.d.ts +6 -0
  43. package/dist/modules/Summary/utils.js +21 -0
  44. package/dist/plugins/window.d.ts +2 -0
  45. package/dist/solution/BookingByStep/index.d.ts +2 -1
  46. package/dist/solution/Checkout/index.js +2 -0
  47. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  48. package/dist/solution/ShopDiscount/index.js +146 -92
  49. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  50. package/dist/solution/ShopDiscount/types.js +2 -1
  51. package/dist/solution/ShopDiscount/utils.js +26 -12
  52. package/lib/index.d.ts +1 -0
  53. package/lib/index.js +3 -1
  54. package/lib/model/index.d.ts +1 -0
  55. package/lib/model/index.js +23 -0
  56. package/lib/model/strategy/adapter/index.d.ts +3 -0
  57. package/lib/model/strategy/adapter/index.js +45 -0
  58. package/lib/model/strategy/adapter/type.d.ts +28 -0
  59. package/lib/model/strategy/adapter/type.js +17 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  61. package/lib/model/strategy/adapter/walletPass/evaluator.js +421 -0
  62. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  63. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  64. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  65. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  66. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  67. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  68. package/lib/model/strategy/adapter/walletPass/type.d.ts +165 -0
  69. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  70. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  71. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  72. package/lib/model/strategy/index.d.ts +94 -0
  73. package/lib/model/strategy/index.js +413 -0
  74. package/lib/model/strategy/strategy-example.d.ts +5 -0
  75. package/lib/model/strategy/strategy-example.js +318 -0
  76. package/lib/model/strategy/type.d.ts +228 -0
  77. package/lib/model/strategy/type.js +44 -0
  78. package/lib/modules/Cart/types.d.ts +2 -0
  79. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  80. package/lib/modules/Discount/index.d.ts +1 -0
  81. package/lib/modules/Discount/index.js +9 -0
  82. package/lib/modules/Discount/types.d.ts +17 -0
  83. package/lib/modules/Payment/index.d.ts +2 -1
  84. package/lib/modules/Payment/index.js +1 -0
  85. package/lib/modules/Payment/utils.js +3 -0
  86. package/lib/modules/Payment/walletpass.d.ts +23 -0
  87. package/lib/modules/Payment/walletpass.js +94 -17
  88. package/lib/modules/Product/index.d.ts +1 -1
  89. package/lib/modules/Rules/index.d.ts +9 -5
  90. package/lib/modules/Rules/index.js +669 -258
  91. package/lib/modules/Rules/types.d.ts +1 -0
  92. package/lib/modules/Summary/types.d.ts +2 -0
  93. package/lib/modules/Summary/utils.d.ts +6 -0
  94. package/lib/modules/Summary/utils.js +15 -0
  95. package/lib/plugins/window.d.ts +2 -0
  96. package/lib/solution/BookingByStep/index.d.ts +2 -1
  97. package/lib/solution/Checkout/index.js +2 -0
  98. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  99. package/lib/solution/ShopDiscount/index.js +36 -8
  100. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  101. package/lib/solution/ShopDiscount/utils.js +10 -6
  102. package/package.json +1 -1
@@ -31,7 +31,6 @@ 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
-
35
34
  // 临时变量
36
35
  var flatItem;
37
36
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
@@ -44,6 +43,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
44
43
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
45
44
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
46
45
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
46
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
47
+ // WindowPlugin 实例
47
48
  _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
48
49
  _this.hooks = {};
49
50
  return _this;
@@ -58,7 +59,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
58
59
  this.core = core;
59
60
  this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
60
61
  this.store = options === null || options === void 0 ? void 0 : options.store;
61
- case 3:
62
+ this.window = core.getPlugin('window');
63
+ case 4:
62
64
  case "end":
63
65
  return _context.stop();
64
66
  }
@@ -113,6 +115,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
113
115
  // 最终直接匹配 holder 是否相同
114
116
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
115
117
  }
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
+ }
116
124
 
117
125
  // 判断discountList 是否可以对当前productList生效
118
126
  }, {
@@ -122,6 +130,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
122
130
  var oldDiscountList = _ref.oldDiscountList,
123
131
  newDiscountList = _ref.newDiscountList,
124
132
  productList = _ref.productList,
133
+ orderTotalAmount = _ref.orderTotalAmount,
125
134
  holders = _ref.holders,
126
135
  isFormSubject = _ref.isFormSubject;
127
136
  // 首先检查是否有新的优惠券可应用
@@ -156,6 +165,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
156
165
  var result = this.calcDiscount({
157
166
  discountList: mergedDiscountList,
158
167
  productList: _toConsumableArray(productList),
168
+ orderTotalAmount: orderTotalAmount,
159
169
  holders: holders,
160
170
  isFormSubject: isFormSubject
161
171
  }, {
@@ -282,7 +292,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
282
292
  var discountList = _ref2.discountList,
283
293
  productList = _ref2.productList,
284
294
  holders = _ref2.holders,
285
- isFormSubject = _ref2.isFormSubject;
295
+ isFormSubject = _ref2.isFormSubject,
296
+ orderTotalAmount = _ref2.orderTotalAmount;
286
297
  // 识别出来是不是在编辑的界面里又新增了商品
287
298
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
288
299
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -340,7 +351,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
340
351
  _id: product._id,
341
352
  parentId: product._id,
342
353
  quantity: product.quantity,
343
- num: product.num
354
+ num: product.num,
355
+ booking_id: product.booking_id
344
356
  });
345
357
 
346
358
  // 2. 展开 bundle 子商品
@@ -364,7 +376,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
364
376
  origin_total: new Decimal(bundleItem.price || 0).mul(bundleItem.num || 1).toNumber(),
365
377
  original_price: bundleItem.original_price,
366
378
  // 继承主商品属性
367
- booking_id: product.booking_id,
379
+ booking_id: bundleItem.booking_id,
368
380
  discount_list: bundleItem.discount_list || []
369
381
  });
370
382
  });
@@ -529,6 +541,57 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
529
541
  return priceB.minus(priceA).toNumber();
530
542
  });
531
543
 
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
+
532
595
  /**
533
596
  // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
534
597
  const sortedProductList = [...productList].sort((a, b) => {
@@ -549,6 +612,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
549
612
  // 标记已使用的优惠券
550
613
  var usedDiscounts = new Map();
551
614
 
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
+
552
631
  // 记录每个优惠券适用的商品ID
553
632
  var discountApplicability = new Map();
554
633
 
@@ -778,7 +857,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
778
857
  originProduct = flatItem.originProduct;
779
858
  }
780
859
  addModeDiscount.forEach(function (discount) {
781
- var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
860
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
782
861
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
783
862
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
784
863
  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;
@@ -789,7 +868,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
789
868
  var timeLimit = true;
790
869
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
791
870
  // 是符合折扣的商品
792
- var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
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;
793
872
 
794
873
  // 编辑的商品 使用了优惠券不可用
795
874
  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) {
@@ -802,8 +881,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
802
881
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
803
882
 
804
883
  // 判断优惠券是否适用于该商品
805
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
806
- var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
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
886
  // 记录此优惠券适用的商品
808
887
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
809
888
 
@@ -819,17 +898,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
819
898
  type: discountType,
820
899
  tag: discountType,
821
900
  discount: {
822
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
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,
823
902
  fixed_amount: product.price,
824
- discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
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,
825
904
  resource_id: discount.id,
826
905
  title: discount.format_title,
827
906
  original_amount: product.price || product.origin_total,
828
907
  pre_value: discount.par_value,
829
- product_id: originProduct.id
908
+ product_id: originProduct.id,
909
+ discount_product_id: discount.product_id
830
910
  },
831
911
  metadata: {
832
- num: num
912
+ num: num,
913
+ discount_rule_uncheck_flag: discount === null || discount === void 0 ? void 0 : discount.discount_rule_uncheck_flag
833
914
  }
834
915
  };
835
916
  applicableProducts.push(productData);
@@ -844,7 +925,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
844
925
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
845
926
  // 🔥 使用扁平化后的列表进行处理
846
927
  sortedFlattenedList.forEach(function (flatItem, index) {
847
- var _product10, _product$discount_lis2, _product11;
928
+ var _product10, _product$discount_lis2, _product11, _selectedDiscount$con;
848
929
  // 获取商品数据
849
930
  var product, originProduct;
850
931
  if (flatItem.type === 'main') {
@@ -886,6 +967,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
886
967
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
887
968
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
888
969
  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
+
889
980
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
890
981
  // 商品券时主商品价格为0不可用
891
982
  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;
@@ -898,8 +989,37 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
898
989
  // 如果优惠券已被使用,则跳过
899
990
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
900
991
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
901
- var limitedData = discount.limited_relation_product_data;
902
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
+ 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
+ }
903
1023
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
904
1024
  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;
905
1025
  var isHolderMatch = _this3.checkHolderMatch(discount, {
@@ -908,14 +1028,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
908
1028
  }, holders);
909
1029
  // 如果 holder 不匹配,则不适用
910
1030
  if (!isHolderMatch) return false;
911
- var timeLimit = true;
912
- timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
913
- if (!timeLimit) {
914
- return false;
915
- }
916
1031
 
917
1032
  // 判断优惠券是否适用于该商品
918
1033
  if (limitedData.type === 'product_all') {
1034
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1035
+ return false;
1036
+ }
919
1037
  // 检查 package_sub_item_usage_rules
920
1038
  if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
921
1039
  return false;
@@ -1074,15 +1192,39 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1074
1192
  return;
1075
1193
  }
1076
1194
 
1077
- // 是否需要拆分(商品券需要拆分)
1078
- var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
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;
1079
1203
 
1080
1204
  // 需要拆分出来的数量
1081
1205
  var totalQuantity = product.quantity || product.num || 1;
1082
1206
  var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1083
1207
  return (item.tag || item.type) === 'good_pass';
1084
1208
  }).length;
1085
- var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
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;
1086
1228
  var arr = [];
1087
1229
 
1088
1230
  // 🔥 主商品和bundle子商品分别处理
@@ -1092,18 +1234,31 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1092
1234
  arr.push(_this3.hooks.setProduct(originProduct, {
1093
1235
  discount_list: [],
1094
1236
  quantity: totalQuantity - splitCount,
1095
- _id: product._id.split('___')[0]
1237
+ _id: product._id.split('___')[0],
1238
+ total: product.origin_total || product.total
1096
1239
  }));
1097
1240
  }
1098
1241
  for (var i = 0; i < splitCount; i++) {
1099
- var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1100
- // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1101
- var _selectedDiscount = selectedDiscountCard || applicableDiscounts[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
1246
  // 标记优惠券为已使用
1103
- usedDiscounts.set(_selectedDiscount.id, true);
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
+ }
1104
1259
 
1105
1260
  // 记录实际应用了优惠券的商品信息
1106
- var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
1261
+ var appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
1107
1262
 
1108
1263
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
1109
1264
  var productOriginTotal = product.origin_total || product.total || 0;
@@ -1118,8 +1273,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1118
1273
 
1119
1274
  // 计算使用折扣卡/商品券以后,单个商品的总 total
1120
1275
  // 🔥 检查是否是 order_level 固定金额折扣卡
1121
- var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
1122
- var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
1276
+ var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1277
+ var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1123
1278
  var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
1124
1279
  var targetProductTotal = void 0;
1125
1280
  var amount = void 0;
@@ -1131,34 +1286,40 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1131
1286
  targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1132
1287
  } else {
1133
1288
  // item_level 或其他类型:使用原有逻辑
1134
- targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1289
+ targetProductTotal = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
1135
1290
  amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1136
1291
  }
1137
- var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1138
- var isGoodPass = discountType === 'good_pass';
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';
1139
1297
  var discountDetail = {
1140
- amount: amount,
1141
- type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
1298
+ amount: actualDiscountAmount,
1299
+ type: currentDiscountType,
1142
1300
  discount: {
1143
- discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1144
- fixed_amount: amount,
1145
- discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1146
- resource_id: _selectedDiscount.id,
1147
- title: _selectedDiscount.format_title,
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,
1148
1306
  original_amount: product.price,
1149
1307
  product_id: originProduct.id,
1150
- percent: _selectedDiscount.par_value
1308
+ percent: currentSelectedDiscount.par_value,
1309
+ discount_product_id: currentSelectedDiscount.product_id
1151
1310
  },
1152
- // 前端使用的num数量,为了计算优惠金额
1153
- _num: isGoodPass ? 1 : product.num,
1311
+ // 前端使用的num数量,为了计算优惠金额(拆分时为1)
1312
+ _num: isNeedSplit ? 1 : product.num,
1313
+ config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
1154
1314
  metadata: _objectSpread({
1155
- num: 1
1315
+ num: 1,
1316
+ discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
1156
1317
  }, productDiscountDifference !== undefined && {
1157
1318
  product_discount_difference: productDiscountDifference
1158
1319
  })
1159
1320
  };
1160
1321
  appliedProducts.push(discountDetail);
1161
- appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
1322
+ appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
1162
1323
  var total = targetProductTotal;
1163
1324
  if (product.options) {
1164
1325
  total = product.options.reduce(function (accumulator, currentValue) {
@@ -1171,10 +1332,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1171
1332
  // 记录应用了优惠券的商品
1172
1333
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
1173
1334
  if (product.isClient) {
1174
- debugger;
1175
1335
  arr.push(_this3.hooks.setProduct(originProduct, {
1176
1336
  discount_list: [discountDetail],
1177
- price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1337
+ price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
1178
1338
  quantity: isNeedSplit ? 1 : product.quantity,
1179
1339
  origin_total: getProductOriginTotalPrice({
1180
1340
  product: {
@@ -1185,15 +1345,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1185
1345
  }),
1186
1346
  variant: originProduct._productInit.variant,
1187
1347
  original_price: new Decimal(product.price || 0).toNumber(),
1188
- total: total
1348
+ total: targetProductTotal
1189
1349
  }));
1190
1350
  } else {
1191
1351
  arr.push(_this3.hooks.setProduct(originProduct, {
1192
1352
  discount_list: [discountDetail],
1193
- _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
1194
- price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1353
+ _id: product._id.split('___')[0] + '___' + currentSelectedDiscount.id + '_' + i + '_' + index,
1354
+ price: currentIsGoodPass ? 0 : product.price,
1195
1355
  quantity: isNeedSplit ? 1 : product.quantity,
1196
- total: total,
1356
+ total: targetProductTotal,
1197
1357
  origin_total: productOriginTotal,
1198
1358
  main_product_selling_price: targetProductTotal
1199
1359
  }));
@@ -1201,79 +1361,336 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1201
1361
  }
1202
1362
  processedProductsMap.set(product._id, arr);
1203
1363
  } else {
1204
- // 🔥 bundle子商品:支持拆分
1364
+ // 🔥 bundle子商品:支持拆分(商品券和折扣卡在 applicableProductLimit > 0 时都需要拆分)
1205
1365
  var processedItems = [];
1206
1366
  if (isNeedSplit) {
1207
- // 商品券:需要拆分数量
1367
+ // 需要拆分数量(商品券或折扣卡有 applicableProductLimit 限制)
1208
1368
  var discountNum = splitCount;
1209
1369
  var normalNum = totalQuantity - discountNum;
1210
1370
 
1211
- // 生成有折扣的商品(每张商品券对应 num: 1)
1371
+ // 生成有折扣的商品(每个拆分商品 num: 1)
1212
1372
  for (var _i = 0; _i < discountNum; _i++) {
1213
- var _selectedDiscount2$me;
1214
- var _selectedDiscount2 = applicableDiscounts[_i];
1215
- usedDiscounts.set(_selectedDiscount2.id, true);
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
+ }
1216
1389
 
1217
1390
  // 🔥 生成唯一的 _id
1218
1391
  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;
1219
1399
  var _discountDetail = {
1220
- amount: product.origin_total,
1221
- type: 'good_pass',
1400
+ amount: bundleDiscountAmount,
1401
+ type: bundleDiscountType,
1222
1402
  discount: {
1223
- fixed_amount: product.origin_total,
1224
- discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
1225
- resource_id: _selectedDiscount2.id,
1226
- title: _selectedDiscount2.format_title,
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
1408
  original_amount: product.origin_total,
1228
- product_id: product.id
1409
+ product_id: product.id,
1410
+ percent: currentBundleDiscount.par_value,
1411
+ discount_product_id: currentBundleDiscount.product_id
1229
1412
  },
1230
1413
  metadata: {
1231
1414
  // 🔥 使用拆分后的唯一 _id
1232
1415
  custom_product_bundle_map_id: uniqueId,
1416
+ discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1233
1417
  num: 1
1234
1418
  },
1235
- _num: 1
1419
+ _num: 1,
1420
+ config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
1236
1421
  };
1237
1422
 
1238
1423
  // 记录实际应用的折扣
1239
- var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
1424
+ var _appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1240
1425
  _appliedProducts.push(_discountDetail);
1241
- appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
1426
+ appliedDiscountProducts.set(currentBundleDiscount.id, _appliedProducts);
1242
1427
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1243
1428
  // 🔥 使用唯一的 _id
1244
1429
  _id: uniqueId,
1245
1430
  num: 1,
1246
1431
  quantity: 1,
1247
- price: 0,
1248
- // 商品券价格为0
1249
- total: 0,
1432
+ price: discountedPrice,
1433
+ // 折扣后的价格
1434
+ total: discountedPrice,
1250
1435
  discount_list: [_discountDetail],
1251
1436
  processed: true,
1252
- _discountId: _selectedDiscount2.id
1437
+ _discountId: currentBundleDiscount.id
1253
1438
  }));
1254
1439
  }
1255
1440
 
1256
- // 生成无折扣的商品(剩余数量)
1257
- if (normalNum > 0) {
1258
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1259
- // 🔥 为剩余商品生成唯一的 _id
1260
- _id: "".concat(flatItem._id, "_split_rest"),
1261
- num: normalNum,
1262
- quantity: normalNum,
1263
- discount_list: [],
1264
- processed: true
1265
- }));
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;
1266
1671
  }
1267
1672
  } else {
1268
- var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
1269
- // 折扣卡:不拆分数量,直接应用
1270
- var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1271
- usedDiscounts.set(_selectedDiscount3.id, true);
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
+ }
1272
1689
  var _productOriginTotal = product.original_price || product.price || 0;
1273
1690
 
1274
1691
  // 🔥 检查是否是 order_level 固定金额折扣卡
1275
- var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
1276
- var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
1692
+ var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1693
+ var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1277
1694
  var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
1278
1695
  var _targetProductTotal;
1279
1696
  var fixedAmountPerItem;
@@ -1285,39 +1702,45 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1285
1702
  _targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1286
1703
  } else {
1287
1704
  // item_level 或其他类型:使用原有逻辑
1288
- _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1705
+ _targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
1289
1706
  fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1290
1707
  }
1291
- debugger;
1708
+
1709
+ // 计算实际折扣金额
1710
+ var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1711
+
1292
1712
  // 🔥 使用当前的 _id 作为唯一标识
1293
1713
  var _uniqueId = flatItem._id;
1294
1714
  var _discountDetail2 = {
1295
- amount: fixedAmountPerItem * (product.num || 1),
1296
- type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
1715
+ amount: bundleActualDiscountAmount * (product.num || 1),
1716
+ type: _currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _currentBundleDiscount.tag,
1297
1717
  discount: {
1298
- discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
1299
- fixed_amount: fixedAmountPerItem,
1300
- discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
1301
- resource_id: _selectedDiscount3.id,
1302
- title: _selectedDiscount3.format_title,
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
1723
  original_amount: product.original_price,
1304
1724
  product_id: product.id,
1305
- percent: _selectedDiscount3.par_value
1725
+ percent: _currentBundleDiscount.par_value,
1726
+ discount_product_id: _currentBundleDiscount.product_id
1306
1727
  },
1307
1728
  metadata: _objectSpread({
1308
1729
  // 🔥 使用唯一的 _id
1309
1730
  custom_product_bundle_map_id: _uniqueId,
1731
+ discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1310
1732
  num: product.num || 1
1311
1733
  }, _productDiscountDifference !== undefined && {
1312
1734
  product_discount_difference: _productDiscountDifference
1313
1735
  }),
1314
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
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)
1315
1738
  };
1316
1739
 
1317
1740
  // 记录实际应用的折扣
1318
- var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
1741
+ var _appliedProducts2 = appliedDiscountProducts.get(_currentBundleDiscount.id) || [];
1319
1742
  _appliedProducts2.push(_discountDetail2);
1320
- appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
1743
+ appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
1321
1744
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1322
1745
  total: _targetProductTotal,
1323
1746
  price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
@@ -1442,6 +1865,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1442
1865
  product_id: bundleItem.product_id,
1443
1866
  price: item.price,
1444
1867
  num: item.num,
1868
+ quantity: item.num,
1445
1869
  discount_list: updatedDiscountList
1446
1870
  }));
1447
1871
  });
@@ -1465,6 +1889,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1465
1889
  product_id: bundleItem.product_id,
1466
1890
  price: item.price,
1467
1891
  num: item.num,
1892
+ quantity: item.num,
1468
1893
  discount_list: _updatedDiscountList
1469
1894
  }));
1470
1895
  } else {
@@ -1479,8 +1904,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1479
1904
 
1480
1905
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1481
1906
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1482
- var _discount$metadata6, _discount$metadata7;
1483
- if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
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) {
1484
1909
  // bundle的discount_list保持不变
1485
1910
  return discount;
1486
1911
  }
@@ -1488,7 +1913,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1488
1913
  return _objectSpread(_objectSpread({}, discount), {}, {
1489
1914
  // num: 1,
1490
1915
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1491
- 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,
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,
1492
1917
  num: 1
1493
1918
  })
1494
1919
  });
@@ -1533,8 +1958,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1533
1958
  quantity: 1,
1534
1959
  discount_list: updatedMainDiscountList,
1535
1960
  bundle: newBundleWithDiscount,
1536
- total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
1537
- origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
1961
+ total: newTotalWithDiscount,
1962
+ origin_total: newOriginTotalWithDiscount
1538
1963
  })));
1539
1964
 
1540
1965
  // 第二个:包含原始bundle (qty=原quantity-1)
@@ -1553,8 +1978,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1553
1978
 
1554
1979
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1555
1980
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1556
- var _discount$metadata8, _discount$metadata9;
1557
- if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
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) {
1558
1983
  // bundle的discount_list保持不变
1559
1984
  return discount;
1560
1985
  }
@@ -1562,7 +1987,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1562
1987
  return _objectSpread(_objectSpread({}, discount), {}, {
1563
1988
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1564
1989
  num: mainProductQuantity - 1,
1565
- 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
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
1566
1991
  })
1567
1992
  // num: mainProductQuantity - 1,
1568
1993
  });
@@ -1629,11 +2054,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1629
2054
  processedBundleItems.forEach(function (item) {
1630
2055
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1631
2056
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1632
- var _discount$metadata10;
2057
+ var _discount$metadata11;
1633
2058
  return _objectSpread(_objectSpread({}, discount), {}, {
1634
2059
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1635
2060
  num: item.num,
1636
- 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
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
1637
2062
  })
1638
2063
  // num: item.num, // 使用拆分后的 num
1639
2064
  });
@@ -1643,6 +2068,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1643
2068
  product_id: bundleItem.product_id,
1644
2069
  price: item.price,
1645
2070
  num: item.num,
2071
+ quantity: item.num,
1646
2072
  discount_list: updatedDiscountList
1647
2073
  }));
1648
2074
  });
@@ -1681,13 +2107,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1681
2107
 
1682
2108
  // 累加bundle的价格(只累加一次)
1683
2109
  if (newBundle.length > 0) {
1684
- newBundle.forEach(function (item) {
1685
- newTotal += Number(item.price) * Number(item.num);
1686
- });
1687
-
1688
- // 计算原始总价(不考虑折扣)
1689
2110
  newBundle.forEach(function (item) {
1690
2111
  var _item$discount_list3;
2112
+ newTotal += Number(item.price) * Number(item.num);
1691
2113
  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;
1692
2114
  newOriginTotal += Number(originalPrice) * Number(item.num);
1693
2115
  });
@@ -1702,8 +2124,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1702
2124
  return accumulator.add(currentPrice.mul(currentNum));
1703
2125
  }, new Decimal(newTotal)).toNumber();
1704
2126
  }
1705
- newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1706
- newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1707
2127
 
1708
2128
  // 生成最终的主商品
1709
2129
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {