@pisell/pisellos 2.1.104 → 2.1.105

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 +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/Customer/index.d.ts +1 -0
  6. package/dist/modules/Customer/index.js +28 -12
  7. package/dist/modules/Discount/types.d.ts +0 -16
  8. package/dist/modules/Payment/index.d.ts +1 -2
  9. package/dist/modules/Payment/index.js +7 -10
  10. package/dist/modules/Payment/utils.js +0 -3
  11. package/dist/modules/Payment/walletpass.d.ts +0 -23
  12. package/dist/modules/Payment/walletpass.js +95 -191
  13. package/dist/modules/Rules/index.d.ts +5 -9
  14. package/dist/modules/Rules/index.js +123 -538
  15. package/dist/modules/Rules/types.d.ts +0 -1
  16. package/dist/modules/Summary/types.d.ts +0 -2
  17. package/dist/modules/Summary/utils.d.ts +0 -6
  18. package/dist/modules/Summary/utils.js +0 -21
  19. package/dist/plugins/window.d.ts +0 -2
  20. package/dist/solution/BookingByStep/index.d.ts +0 -1
  21. package/dist/solution/BookingTicket/index.d.ts +1 -1
  22. package/dist/solution/Checkout/index.js +0 -2
  23. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  24. package/dist/solution/ShopDiscount/index.js +7 -23
  25. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  26. package/dist/solution/ShopDiscount/types.js +1 -2
  27. package/dist/solution/ShopDiscount/utils.js +12 -26
  28. package/lib/index.d.ts +0 -1
  29. package/lib/index.js +1 -3
  30. package/lib/modules/Cart/types.d.ts +0 -2
  31. package/lib/modules/Cart/utils/cartProduct.js +0 -9
  32. package/lib/modules/Customer/index.d.ts +1 -0
  33. package/lib/modules/Customer/index.js +21 -6
  34. package/lib/modules/Discount/types.d.ts +0 -16
  35. package/lib/modules/Payment/index.d.ts +1 -2
  36. package/lib/modules/Payment/index.js +0 -1
  37. package/lib/modules/Payment/utils.js +0 -3
  38. package/lib/modules/Payment/walletpass.d.ts +0 -23
  39. package/lib/modules/Payment/walletpass.js +17 -94
  40. package/lib/modules/Rules/index.d.ts +5 -9
  41. package/lib/modules/Rules/index.js +258 -666
  42. package/lib/modules/Rules/types.d.ts +0 -1
  43. package/lib/modules/Summary/types.d.ts +0 -2
  44. package/lib/modules/Summary/utils.d.ts +0 -6
  45. package/lib/modules/Summary/utils.js +0 -15
  46. package/lib/plugins/window.d.ts +0 -2
  47. package/lib/solution/BookingByStep/index.d.ts +0 -1
  48. package/lib/solution/BookingTicket/index.d.ts +1 -1
  49. package/lib/solution/Checkout/index.js +0 -2
  50. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  51. package/lib/solution/ShopDiscount/index.js +8 -22
  52. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  53. package/lib/solution/ShopDiscount/utils.js +6 -10
  54. package/package.json +1 -1
  55. package/dist/model/index.d.ts +0 -1
  56. package/dist/model/index.js +0 -1
  57. package/dist/model/strategy/adapter/index.d.ts +0 -3
  58. package/dist/model/strategy/adapter/index.js +0 -4
  59. package/dist/model/strategy/adapter/type.d.ts +0 -28
  60. package/dist/model/strategy/adapter/type.js +0 -1
  61. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  62. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -498
  63. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  64. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  65. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  66. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  67. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  68. package/dist/model/strategy/adapter/walletPass/locales.js +0 -26
  69. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -169
  70. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  71. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  72. package/dist/model/strategy/adapter/walletPass/utils.js +0 -1064
  73. package/dist/model/strategy/index.d.ts +0 -94
  74. package/dist/model/strategy/index.js +0 -551
  75. package/dist/model/strategy/strategy-example.d.ts +0 -5
  76. package/dist/model/strategy/strategy-example.js +0 -331
  77. package/dist/model/strategy/type.d.ts +0 -228
  78. package/dist/model/strategy/type.js +0 -94
  79. package/lib/model/index.d.ts +0 -1
  80. package/lib/model/index.js +0 -23
  81. package/lib/model/strategy/adapter/index.d.ts +0 -3
  82. package/lib/model/strategy/adapter/index.js +0 -45
  83. package/lib/model/strategy/adapter/type.d.ts +0 -28
  84. package/lib/model/strategy/adapter/type.js +0 -17
  85. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  86. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -422
  87. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  88. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  89. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  90. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  91. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  92. package/lib/model/strategy/adapter/walletPass/locales.js +0 -54
  93. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -169
  94. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  95. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  96. package/lib/model/strategy/adapter/walletPass/utils.js +0 -720
  97. package/lib/model/strategy/index.d.ts +0 -94
  98. package/lib/model/strategy/index.js +0 -413
  99. package/lib/model/strategy/strategy-example.d.ts +0 -5
  100. package/lib/model/strategy/strategy-example.js +0 -318
  101. package/lib/model/strategy/type.d.ts +0 -228
  102. 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
  }, {
@@ -299,15 +289,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
299
289
  var discountList = _ref2.discountList,
300
290
  productList = _ref2.productList,
301
291
  holders = _ref2.holders,
302
- isFormSubject = _ref2.isFormSubject,
303
- orderTotalAmount = _ref2.orderTotalAmount;
304
- // 识别出来是不是在编辑的界面里又新增了商品
305
- // 这种情况下,如果有可用的优惠券,也会自动勾选上
306
- var isEditModeAddNewProduct = productList.find(function (n) {
307
- return n.booking_id;
308
- }) && productList.find(function (n) {
309
- return !n.booking_id;
310
- });
292
+ isFormSubject = _ref2.isFormSubject;
311
293
  var editModeDiscount = [];
312
294
  var addModeDiscount = [];
313
295
  discountList.forEach(function (discount) {
@@ -521,6 +503,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
521
503
  // 🔥 扁平化商品列表(包含主商品和bundle子商品)
522
504
  var flattenedList = flattenProductsWithBundle(productList);
523
505
 
506
+ // 识别出来是不是在编辑的界面里又新增了商品
507
+ // 这种情况下,如果有可用的优惠券,也会自动勾选上
508
+ var isEditModeAddNewProduct = flattenedList.find(function (n) {
509
+ return n.booking_id;
510
+ }) && flattenedList.find(function (n) {
511
+ return !n.booking_id;
512
+ });
513
+
524
514
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
525
515
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
526
516
  var _ref3, _a$original_price, _ref4, _b$original_price;
@@ -548,57 +538,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
548
538
  return priceB.minus(priceA).toNumber();
549
539
  });
550
540
 
551
- // 🔥 为每个折扣卡/商品券执行策略检查并附加config
552
- var evaluator = this.getWalletPassEvaluator();
553
- if (evaluator) {
554
- addModeDiscount.forEach(function (discount) {
555
- var discountType = discount.tag || discount.type;
556
- // 只对 good_pass 和 discount_card 类型执行策略检查
557
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
558
- var _discount$limited_rel, _discount$limited_rel2;
559
- // 转换 discount 为 Voucher 格式
560
- var voucher = {
561
- id: discount.id,
562
- amount: Number(discount.par_value || 0),
563
- balance: Number(discount.balance || 0),
564
- type: discountType,
565
- product_id: discount.product_id,
566
- unified_available_status: 1,
567
- available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
568
- available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
569
- };
570
-
571
- // 转换 sortedFlattenedList 为 Product 格式
572
- var productsForEvaluate = sortedFlattenedList.map(function (item) {
573
- return {
574
- product_id: item.id,
575
- price: item.price || 0,
576
- quantity: item.quantity || item.num || 1,
577
- selling_price: item.price || 0
578
- };
579
- });
580
-
581
- // 调用策略检查
582
- var result = evaluator.checkVoucherAvailability({
583
- orderTotalAmount: orderTotalAmount,
584
- products: productsForEvaluate,
585
- vouchers: [voucher]
586
- });
587
-
588
- // 将 config 附加到 discount 对象
589
- if (result.isAvailable) {
590
- discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
591
- isAvailable: true
592
- });
593
- } else {
594
- discount.config = {
595
- isAvailable: false
596
- };
597
- }
598
- }
599
- });
600
- }
601
-
602
541
  /**
603
542
  // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
604
543
  const sortedProductList = [...productList].sort((a, b) => {
@@ -619,22 +558,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
619
558
  // 标记已使用的优惠券
620
559
  var usedDiscounts = new Map();
621
560
 
622
- // 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
623
- var usedProductIdCounts = new Map();
624
-
625
- // 🔥 统计每张折扣卡的 applicableProductLimit 已使用次数(跨商品全局计数)
626
- var usedDiscountCardLimitCounts = new Map();
627
-
628
- // 🔥 预先将 editModeDiscount 中的折扣卡计入 applicableProductLimit 已使用次数
629
- editModeDiscount.forEach(function (discount) {
630
- var discountType = discount.tag || discount.type;
631
- if (['discount_card', 'product_discount_card'].includes(discountType)) {
632
- var _discount$metadata4;
633
- var currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
634
- usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.num) || 1));
635
- }
636
- });
637
-
638
561
  // 记录每个优惠券适用的商品ID
639
562
  var discountApplicability = new Map();
640
563
 
@@ -864,7 +787,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
864
787
  originProduct = flatItem.originProduct;
865
788
  }
866
789
  addModeDiscount.forEach(function (discount) {
867
- var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
790
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
868
791
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
869
792
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
870
793
  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;
@@ -875,7 +798,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
875
798
  var timeLimit = true;
876
799
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
877
800
  // 是符合折扣的商品
878
- 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;
801
+ var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
879
802
 
880
803
  // 编辑的商品 使用了优惠券不可用
881
804
  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) {
@@ -888,8 +811,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
888
811
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
889
812
 
890
813
  // 判断优惠券是否适用于该商品
891
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
892
- var _discountApplicabilit, _discount$metadata5, _discount$metadata6;
814
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
815
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
893
816
  // 记录此优惠券适用的商品
894
817
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
895
818
 
@@ -905,15 +828,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
905
828
  type: discountType,
906
829
  tag: discountType,
907
830
  discount: {
908
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_card_type,
831
+ discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
909
832
  fixed_amount: product.price,
910
- discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.discount_calculation_mode,
833
+ discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
911
834
  resource_id: discount.id,
912
835
  title: discount.format_title,
913
836
  original_amount: product.price || product.origin_total,
914
837
  pre_value: discount.par_value,
915
- product_id: originProduct.id,
916
- discount_product_id: discount.product_id
838
+ product_id: originProduct.id
917
839
  },
918
840
  metadata: {
919
841
  num: num,
@@ -932,7 +854,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
932
854
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
933
855
  // 🔥 使用扁平化后的列表进行处理
934
856
  sortedFlattenedList.forEach(function (flatItem, index) {
935
- var _product10, _product$discount_lis2, _product11, _selectedDiscount$con;
857
+ var _product10, _product$discount_lis2, _product11;
936
858
  // 获取商品数据
937
859
  var product, originProduct;
938
860
  if (flatItem.type === 'main') {
@@ -974,16 +896,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
974
896
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
975
897
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
976
898
  var _product$discount_lis3, _product$discount_lis4;
977
- // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
978
- var discountType = discount.tag || discount.type;
979
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
980
- var _discount$config2;
981
- // 如果策略检查后没有config,说明不可用
982
- if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
983
- return false;
984
- }
985
- }
986
-
987
899
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
988
900
  // 商品券时主商品价格为0不可用
989
901
  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;
@@ -996,37 +908,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
996
908
  // 如果优惠券已被使用,则跳过
997
909
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
998
910
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
999
-
1000
- // 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
1001
- if ((discount.tag || discount.type) === 'good_pass') {
1002
- var _discount$config3;
1003
- var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
1004
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1005
- var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
1006
- if (currentUsedCount >= maxUsagePerOrder) {
1007
- return false;
1008
- }
1009
- }
1010
- }
1011
-
1012
- // 🔥 检查折扣卡的 applicableProductLimit 限制:折扣卡可使用的最大次数(跨商品全局)
1013
- var discountTypeForLimit = discount.tag || discount.type;
1014
- if (['discount_card', 'product_discount_card'].includes(discountTypeForLimit)) {
1015
- var _discount$config4;
1016
- var applicableProductLimitConfig = ((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.applicableProductLimit) || 0;
1017
- if (applicableProductLimitConfig > 0) {
1018
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
1019
- if (currentUsedLimitCount >= applicableProductLimitConfig) {
1020
- return false;
1021
- }
1022
- }
1023
- }
1024
911
  var limitedData = discount.limited_relation_product_data;
1025
- var timeLimit = true;
1026
- timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
1027
- if (!timeLimit) {
1028
- return false;
1029
- }
912
+
1030
913
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
1031
914
  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;
1032
915
  var isHolderMatch = _this3.checkHolderMatch(discount, {
@@ -1035,12 +918,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1035
918
  }, holders);
1036
919
  // 如果 holder 不匹配,则不适用
1037
920
  if (!isHolderMatch) return false;
921
+ var timeLimit = true;
922
+ timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
923
+ if (!timeLimit) {
924
+ return false;
925
+ }
1038
926
 
1039
927
  // 判断优惠券是否适用于该商品
1040
928
  if (limitedData.type === 'product_all') {
1041
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1042
- return false;
1043
- }
1044
929
  // 检查 package_sub_item_usage_rules
1045
930
  if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
1046
931
  return false;
@@ -1209,39 +1094,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1209
1094
  return;
1210
1095
  }
1211
1096
 
1212
- // 是否需要拆分(商品券需要拆分,折扣卡在 applicableProductLimit > 0 时也需要拆分)
1213
- var discountType = selectedDiscount.tag || selectedDiscount.type;
1214
- var isGoodPass = discountType === 'good_pass';
1215
- var isDiscountCard = ['discount_card', 'product_discount_card'].includes(discountType);
1216
- var applicableProductLimit = ((_selectedDiscount$con = selectedDiscount.config) === null || _selectedDiscount$con === void 0 ? void 0 : _selectedDiscount$con.applicableProductLimit) || 0;
1217
-
1218
- // 商品券始终需要拆分,折扣卡在 applicableProductLimit > 0 时需要拆分
1219
- var isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
1097
+ // 是否需要拆分(商品券需要拆分)
1098
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
1220
1099
 
1221
1100
  // 需要拆分出来的数量
1222
1101
  var totalQuantity = product.quantity || product.num || 1;
1223
1102
  var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1224
1103
  return (item.tag || item.type) === 'good_pass';
1225
1104
  }).length;
1226
-
1227
- // 🔥 计算最大使用次数限制
1228
- var maxUsageLimit;
1229
- if (isGoodPass) {
1230
- // 商品券:使用 maxUsagePerOrder 限制
1231
- maxUsageLimit = availableGoodPassCount;
1232
- if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
1233
- maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
1234
- }
1235
- } else if (isDiscountCard && applicableProductLimit > 0) {
1236
- // 折扣卡:使用 applicableProductLimit 限制(一个商品使用一次折扣卡算1次)
1237
- // 需要减去已使用次数(跨商品全局计数)
1238
- var usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
1239
- maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
1240
- } else {
1241
- // 其他情况不拆分
1242
- maxUsageLimit = 1;
1243
- }
1244
- var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
1105
+ var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
1245
1106
  var arr = [];
1246
1107
 
1247
1108
  // 🔥 主商品和bundle子商品分别处理
@@ -1251,31 +1112,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1251
1112
  arr.push(_this3.hooks.setProduct(originProduct, {
1252
1113
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1253
1114
  quantity: totalQuantity - splitCount,
1254
- _id: product._id.split('___')[0],
1255
- total: product.origin_total || product.total
1115
+ _id: product._id.split('___')[0]
1256
1116
  }));
1257
1117
  }
1258
1118
  for (var i = 0; i < splitCount; i++) {
1259
- var _originProduct, _currentSelectedDisco, _currentSelectedDisco2;
1260
- // 商品券:每个拆分商品使用不同的商品券(从 applicableDiscounts 按索引取)
1261
- // 折扣卡:所有拆分商品使用同一张折扣卡(selectedDiscountCard applicableDiscounts[0]
1262
- var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
1119
+ var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1120
+ // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1121
+ var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1263
1122
  // 标记优惠券为已使用
1264
- usedDiscounts.set(currentSelectedDiscount.id, true);
1265
- // 🔥 更新 product_id 使用计数
1266
- if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === 'good_pass') {
1267
- var currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
1268
- usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
1269
- }
1270
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1271
- var currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
1272
- if (['discount_card', 'product_discount_card'].includes(currentDiscountTypeForCount)) {
1273
- var currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
1274
- usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
1275
- }
1123
+ usedDiscounts.set(_selectedDiscount.id, true);
1276
1124
 
1277
1125
  // 记录实际应用了优惠券的商品信息
1278
- var appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
1126
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
1279
1127
 
1280
1128
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
1281
1129
  var productOriginTotal = product.origin_total || product.total || 0;
@@ -1290,8 +1138,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1290
1138
 
1291
1139
  // 计算使用折扣卡/商品券以后,单个商品的总 total
1292
1140
  // 🔥 检查是否是 order_level 固定金额折扣卡
1293
- var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1294
- var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1141
+ var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
1142
+ var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
1295
1143
  var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
1296
1144
  var targetProductTotal = void 0;
1297
1145
  var amount = void 0;
@@ -1303,40 +1151,35 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1303
1151
  targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1304
1152
  } else {
1305
1153
  // item_level 或其他类型:使用原有逻辑
1306
- targetProductTotal = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
1154
+ targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1307
1155
  amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1308
1156
  }
1309
- var currentDiscountType = currentSelectedDiscount.tag === 'product_discount_card' ? 'discount_card' : currentSelectedDiscount.tag;
1310
-
1311
- // 计算实际折扣金额
1312
- var actualDiscountAmount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1313
- var currentIsGoodPass = currentDiscountType === 'good_pass';
1157
+ var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1158
+ var isGoodPass = discountType === 'good_pass';
1314
1159
  var discountDetail = {
1315
- amount: actualDiscountAmount,
1316
- type: currentDiscountType,
1160
+ amount: amount,
1161
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
1317
1162
  discount: {
1318
- discount_card_type: currentSelectedDiscount === null || currentSelectedDiscount === void 0 || (_currentSelectedDisco = currentSelectedDiscount.metadata) === null || _currentSelectedDisco === void 0 ? void 0 : _currentSelectedDisco.discount_card_type,
1319
- fixed_amount: actualDiscountAmount,
1320
- discount_calculation_mode: currentSelectedDiscount === null || currentSelectedDiscount === void 0 || (_currentSelectedDisco2 = currentSelectedDiscount.metadata) === null || _currentSelectedDisco2 === void 0 ? void 0 : _currentSelectedDisco2.discount_calculation_mode,
1321
- resource_id: currentSelectedDiscount.id,
1322
- title: currentSelectedDiscount.format_title,
1163
+ discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1164
+ fixed_amount: amount,
1165
+ discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1166
+ resource_id: _selectedDiscount.id,
1167
+ title: _selectedDiscount.format_title,
1323
1168
  original_amount: product.price,
1324
1169
  product_id: originProduct.id,
1325
- percent: currentSelectedDiscount.par_value,
1326
- discount_product_id: currentSelectedDiscount.product_id
1170
+ percent: _selectedDiscount.par_value
1327
1171
  },
1328
- // 前端使用的num数量,为了计算优惠金额(拆分时为1)
1329
- _num: isNeedSplit ? 1 : product.num,
1330
- config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
1172
+ // 前端使用的num数量,为了计算优惠金额
1173
+ _num: isGoodPass ? 1 : product.num,
1331
1174
  metadata: _objectSpread({
1332
1175
  num: 1,
1333
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
1176
+ discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
1334
1177
  }, productDiscountDifference !== undefined && {
1335
1178
  product_discount_difference: productDiscountDifference
1336
1179
  })
1337
1180
  };
1338
1181
  appliedProducts.push(discountDetail);
1339
- appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
1182
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
1340
1183
  var _total = targetProductTotal;
1341
1184
  if (product.options) {
1342
1185
  _total = product.options.reduce(function (accumulator, currentValue) {
@@ -1351,7 +1194,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1351
1194
  if (product.isClient) {
1352
1195
  arr.push(_this3.hooks.setProduct(originProduct, {
1353
1196
  discount_list: [discountDetail],
1354
- price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
1197
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1355
1198
  quantity: isNeedSplit ? 1 : product.quantity,
1356
1199
  origin_total: getProductOriginTotalPrice({
1357
1200
  product: {
@@ -1362,15 +1205,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1362
1205
  }),
1363
1206
  variant: originProduct._productInit.variant,
1364
1207
  original_price: new Decimal(product.price || 0).toNumber(),
1365
- total: targetProductTotal
1208
+ total: _total
1366
1209
  }));
1367
1210
  } else {
1368
1211
  arr.push(_this3.hooks.setProduct(originProduct, {
1369
1212
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
1370
- _id: product._id.split('___')[0] + '___' + currentSelectedDiscount.id + '_' + i + '_' + index,
1371
- price: currentIsGoodPass ? 0 : product.price,
1213
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
1214
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1372
1215
  quantity: isNeedSplit ? 1 : product.quantity,
1373
- total: targetProductTotal,
1216
+ total: _total,
1374
1217
  origin_total: productOriginTotal,
1375
1218
  main_product_selling_price: targetProductTotal
1376
1219
  }));
@@ -1378,336 +1221,80 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1378
1221
  }
1379
1222
  processedProductsMap.set(product._id, arr);
1380
1223
  } else {
1381
- // 🔥 bundle子商品:支持拆分(商品券和折扣卡在 applicableProductLimit > 0 时都需要拆分)
1224
+ // 🔥 bundle子商品:支持拆分
1382
1225
  var processedItems = [];
1383
1226
  if (isNeedSplit) {
1384
- // 需要拆分数量(商品券或折扣卡有 applicableProductLimit 限制)
1227
+ // 商品券:需要拆分数量
1385
1228
  var discountNum = splitCount;
1386
1229
  var normalNum = totalQuantity - discountNum;
1387
1230
 
1388
- // 生成有折扣的商品(每个拆分商品 num: 1)
1231
+ // 生成有折扣的商品(每张商品券对应 num: 1)
1389
1232
  for (var _i = 0; _i < discountNum; _i++) {
1390
- var _currentBundleDiscoun, _currentBundleDiscoun2;
1391
- // 商品券:每个拆分商品使用不同的商品券
1392
- // 折扣卡:所有拆分商品使用同一张折扣卡
1393
- var currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[_i] : selectedDiscountCard || applicableDiscounts[0];
1394
- usedDiscounts.set(currentBundleDiscount.id, true);
1395
- // 🔥 更新 product_id 使用计数
1396
- if ((currentBundleDiscount.tag || currentBundleDiscount.type) === 'good_pass') {
1397
- var _currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1398
- usedProductIdCounts.set(currentBundleDiscount.product_id, _currentCount + 1);
1399
- }
1400
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
1401
- var bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
1402
- if (['discount_card', 'product_discount_card'].includes(bundleDiscountTypeForCount)) {
1403
- var currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1404
- usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
1405
- }
1233
+ var _selectedDiscount2$me;
1234
+ var _selectedDiscount2 = applicableDiscounts[_i];
1235
+ usedDiscounts.set(_selectedDiscount2.id, true);
1406
1236
 
1407
1237
  // 🔥 生成唯一的 _id
1408
1238
  var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
1409
-
1410
- // 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
1411
- var discountedPrice = getDiscountAmount(currentBundleDiscount, product.origin_total, product.origin_total);
1412
- var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1413
-
1414
- // 确定折扣类型
1415
- var bundleDiscountType = currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : currentBundleDiscount.tag;
1416
1239
  var _discountDetail = {
1417
- amount: bundleDiscountAmount,
1418
- type: bundleDiscountType,
1240
+ amount: product.origin_total,
1241
+ type: 'good_pass',
1419
1242
  discount: {
1420
- discount_card_type: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun = currentBundleDiscount.metadata) === null || _currentBundleDiscoun === void 0 ? void 0 : _currentBundleDiscoun.discount_card_type,
1421
- discount_calculation_mode: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun2 = currentBundleDiscount.metadata) === null || _currentBundleDiscoun2 === void 0 ? void 0 : _currentBundleDiscoun2.discount_calculation_mode,
1422
- fixed_amount: bundleDiscountAmount,
1423
- resource_id: currentBundleDiscount.id,
1424
- title: currentBundleDiscount.format_title,
1243
+ fixed_amount: product.origin_total,
1244
+ discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
1245
+ resource_id: _selectedDiscount2.id,
1246
+ title: _selectedDiscount2.format_title,
1425
1247
  original_amount: product.origin_total,
1426
- product_id: product.id,
1427
- percent: currentBundleDiscount.par_value,
1428
- discount_product_id: currentBundleDiscount.product_id
1248
+ product_id: product.id
1429
1249
  },
1430
1250
  metadata: {
1431
1251
  // 🔥 使用拆分后的唯一 _id
1432
1252
  custom_product_bundle_map_id: uniqueId,
1433
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1253
+ discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
1434
1254
  num: 1
1435
1255
  },
1436
- _num: 1,
1437
- config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
1256
+ _num: 1
1438
1257
  };
1439
1258
 
1440
1259
  // 记录实际应用的折扣
1441
- var _appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1260
+ var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
1442
1261
  _appliedProducts.push(_discountDetail);
1443
- appliedDiscountProducts.set(currentBundleDiscount.id, _appliedProducts);
1262
+ appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
1444
1263
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1445
1264
  // 🔥 使用唯一的 _id
1446
1265
  _id: uniqueId,
1447
1266
  num: 1,
1448
1267
  quantity: 1,
1449
- price: discountedPrice,
1450
- // 折扣后的价格
1451
- total: discountedPrice,
1268
+ price: 0,
1269
+ // 商品券价格为0
1270
+ total: 0,
1452
1271
  discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail]),
1453
1272
  processed: true,
1454
- _discountId: currentBundleDiscount.id
1273
+ _discountId: _selectedDiscount2.id
1455
1274
  }));
1456
1275
  }
1457
1276
 
1458
- // 🔥 对拆分后的剩余商品继续匹配其他可用折扣(而不是等到下次执行才应用)
1459
- var remainingNum = normalNum;
1460
- var continueSplitIndex = discountNum;
1461
- while (remainingNum > 0) {
1462
- var _nextSelectedDiscount;
1463
- // 重新查找适用于剩余商品的可用折扣(已使用的会被自动过滤掉)
1464
- var nextApplicableDiscounts = sortedDiscountList.filter(function (nextDiscount) {
1465
- var _product$discount_lis10;
1466
- var nextDiscountType = nextDiscount.tag || nextDiscount.type;
1467
- // 检查策略可用性
1468
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1469
- var _nextDiscount$config;
1470
- if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
1471
- return false;
1472
- }
1473
- }
1474
- // 折扣卡时总价为0时不可用
1475
- if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.find(function (n) {
1476
- var _n$discount2;
1477
- return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
1478
- })) && nextDiscountType !== 'good_pass') return false;
1479
-
1480
- // 商品券已被使用则跳过
1481
- if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
1482
-
1483
- // 检查 maxUsagePerOrder 限制
1484
- if (nextDiscountType === 'good_pass') {
1485
- var _nextDiscount$config2;
1486
- var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
1487
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1488
- var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1489
- if (currentUsedCount >= maxUsagePerOrder) {
1490
- return false;
1491
- }
1492
- }
1493
- }
1494
-
1495
- // 检查折扣卡的 applicableProductLimit 限制
1496
- if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1497
- var _nextDiscount$config3;
1498
- var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
1499
- if (limitConfig > 0) {
1500
- var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1501
- if (currentUsedLimitCount >= limitConfig) {
1502
- return false;
1503
- }
1504
- }
1505
- }
1506
- var limitedData = nextDiscount.limited_relation_product_data;
1507
- if (limitedData.type === 'product_all') {
1508
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1509
- return false;
1510
- }
1511
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1512
- return false;
1513
- }
1514
- return true;
1515
- } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1516
- if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1517
- return false;
1518
- }
1519
- return true;
1520
- }
1521
- return false;
1522
- });
1523
-
1524
- // 没有更多可用折扣,剩余商品无折扣存储
1525
- if (nextApplicableDiscounts.length === 0) {
1526
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1527
- _id: "".concat(flatItem._id, "_split_rest"),
1528
- num: remainingNum,
1529
- quantity: remainingNum,
1530
- discount_list: [],
1531
- processed: true
1532
- }));
1533
- break;
1534
- }
1535
-
1536
- // 选择最优折扣
1537
- var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
1538
- return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1539
- });
1540
- var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1541
-
1542
- // 判断新折扣是否需要拆分
1543
- var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1544
- var nextIsGoodPass = nextDiscType === 'good_pass';
1545
- var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
1546
- var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
1547
- var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1548
- if (!nextIsNeedSplit) {
1549
- var _nextBundleDiscount$m, _flatItem$parentProdu9;
1550
- // 🔥 不需要拆分:直接应用折扣到所有剩余商品
1551
- var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1552
- usedDiscounts.set(nextBundleDiscount.id, true);
1553
- if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
1554
- var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1555
- usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1556
- }
1557
- var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1558
- if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
1559
- var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1560
- usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
1561
- }
1562
- var nextOriginTotal = product.original_price || product.price || 0;
1563
- var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1564
- var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
1565
- var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1566
- var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
1567
- var nextDiscountDetail = {
1568
- amount: nextDiscountAmount * remainingNum,
1569
- type: nextBundleDiscType,
1570
- discount: {
1571
- discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
1572
- fixed_amount: nextDiscountAmount,
1573
- resource_id: nextBundleDiscount.id,
1574
- title: nextBundleDiscount.format_title,
1575
- original_amount: product.original_price,
1576
- product_id: product.id,
1577
- percent: nextBundleDiscount.par_value,
1578
- discount_product_id: nextBundleDiscount.product_id
1579
- },
1580
- metadata: {
1581
- custom_product_bundle_map_id: nextUniqueId,
1582
- num: remainingNum
1583
- },
1584
- config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
1585
- _num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1586
- };
1587
- var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1588
- nextAppliedProducts.push(nextDiscountDetail);
1589
- appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1590
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1591
- _id: nextUniqueId,
1592
- num: remainingNum,
1593
- quantity: remainingNum,
1594
- total: nextTargetTotal,
1595
- price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1596
- discount_list: [nextDiscountDetail],
1597
- processed: true
1598
- }));
1599
- remainingNum = 0;
1600
- break;
1601
- }
1602
-
1603
- // 🔥 需要拆分:计算最大使用次数
1604
- var nextMaxUsageLimit = void 0;
1605
- if (nextIsGoodPass) {
1606
- var _nextSelectedDiscount2;
1607
- var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
1608
- return (item.tag || item.type) === 'good_pass';
1609
- }).length;
1610
- nextMaxUsageLimit = nextGoodPassCount;
1611
- if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
1612
- var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1613
- nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
1614
- }
1615
- } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1616
- var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1617
- nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
1618
- } else {
1619
- nextMaxUsageLimit = 1;
1620
- }
1621
- var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1622
- if (nextSplitCount === 0) {
1623
- // 已达使用上限,剩余商品无折扣存储
1624
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1625
- _id: "".concat(flatItem._id, "_split_rest"),
1626
- num: remainingNum,
1627
- quantity: remainingNum,
1628
- discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
1629
- processed: true
1630
- }));
1631
- break;
1632
- }
1633
-
1634
- // 生成有折扣的商品
1635
- for (var j = 0; j < nextSplitCount; j++) {
1636
- var _nextBundleDiscount$m2;
1637
- var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1638
- usedDiscounts.set(_nextBundleDiscount.id, true);
1639
- if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
1640
- var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
1641
- usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
1642
- }
1643
- var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
1644
- if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
1645
- var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
1646
- usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
1647
- }
1648
- var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1649
- var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
1650
- var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1651
- var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
1652
- var _nextDiscountDetail = {
1653
- amount: nextBundleDiscAmount,
1654
- type: nextBundleDiscTypeStr,
1655
- discount: {
1656
- discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
1657
- fixed_amount: nextBundleDiscAmount,
1658
- resource_id: _nextBundleDiscount.id,
1659
- title: _nextBundleDiscount.format_title,
1660
- original_amount: product.origin_total,
1661
- product_id: product.id,
1662
- percent: _nextBundleDiscount.par_value,
1663
- discount_product_id: _nextBundleDiscount.product_id
1664
- },
1665
- metadata: {
1666
- custom_product_bundle_map_id: _nextUniqueId,
1667
- num: 1
1668
- },
1669
- _num: 1,
1670
- config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
1671
- };
1672
- var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
1673
- _nextAppliedProducts.push(_nextDiscountDetail);
1674
- appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
1675
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1676
- _id: _nextUniqueId,
1677
- num: 1,
1678
- quantity: 1,
1679
- price: nextDiscountedPrice,
1680
- total: nextDiscountedPrice,
1681
- discount_list: [_nextDiscountDetail],
1682
- processed: true,
1683
- _discountId: _nextBundleDiscount.id
1684
- }));
1685
- continueSplitIndex++;
1686
- }
1687
- remainingNum -= nextSplitCount;
1277
+ // 生成无折扣的商品(剩余数量)
1278
+ if (normalNum > 0) {
1279
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1280
+ // 🔥 为剩余商品生成唯一的 _id
1281
+ _id: "".concat(flatItem._id, "_split_rest"),
1282
+ num: normalNum,
1283
+ quantity: normalNum,
1284
+ discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
1285
+ processed: true
1286
+ }));
1688
1287
  }
1689
1288
  } else {
1690
- var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu10;
1691
- // 不拆分:直接应用折扣
1692
- var _currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1693
- usedDiscounts.set(_currentBundleDiscount.id, true);
1694
- // 🔥 更新 product_id 使用计数
1695
- if ((_currentBundleDiscount.tag || _currentBundleDiscount.type) === 'good_pass') {
1696
- var _currentCount2 = usedProductIdCounts.get(_currentBundleDiscount.product_id) || 0;
1697
- usedProductIdCounts.set(_currentBundleDiscount.product_id, _currentCount2 + 1);
1698
- }
1699
- // 🔥 更新折扣卡 applicableProductLimit 使用计数(不拆分时按商品数量计数)
1700
- var noSplitDiscountType = _currentBundleDiscount.tag || _currentBundleDiscount.type;
1701
- if (['discount_card', 'product_discount_card'].includes(noSplitDiscountType)) {
1702
- var bundleQuantity = product.num || 1;
1703
- var currentNoSplitCount = usedDiscountCardLimitCounts.get(_currentBundleDiscount.id) || 0;
1704
- usedDiscountCardLimitCounts.set(_currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
1705
- }
1289
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
1290
+ // 折扣卡:不拆分数量,直接应用
1291
+ var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1292
+ usedDiscounts.set(_selectedDiscount3.id, true);
1706
1293
  var _productOriginTotal = product.original_price || product.price || 0;
1707
1294
 
1708
1295
  // 🔥 检查是否是 order_level 固定金额折扣卡
1709
- var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
1710
- var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
1296
+ var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
1297
+ var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
1711
1298
  var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
1712
1299
  var _targetProductTotal;
1713
1300
  var fixedAmountPerItem;
@@ -1719,45 +1306,40 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1719
1306
  _targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1720
1307
  } else {
1721
1308
  // item_level 或其他类型:使用原有逻辑
1722
- _targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
1309
+ _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1723
1310
  fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1724
1311
  }
1725
1312
 
1726
- // 计算实际折扣金额
1727
- var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1728
-
1729
1313
  // 🔥 使用当前的 _id 作为唯一标识
1730
1314
  var _uniqueId = flatItem._id;
1731
1315
  var _discountDetail2 = {
1732
- amount: bundleActualDiscountAmount * (product.num || 1),
1733
- type: _currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _currentBundleDiscount.tag,
1316
+ amount: fixedAmountPerItem * (product.num || 1),
1317
+ type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
1734
1318
  discount: {
1735
- discount_card_type: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun3 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun3 === void 0 ? void 0 : _currentBundleDiscoun3.discount_card_type,
1736
- fixed_amount: bundleActualDiscountAmount,
1737
- discount_calculation_mode: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun4 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun4 === void 0 ? void 0 : _currentBundleDiscoun4.discount_calculation_mode,
1738
- resource_id: _currentBundleDiscount.id,
1739
- title: _currentBundleDiscount.format_title,
1319
+ discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
1320
+ fixed_amount: fixedAmountPerItem,
1321
+ discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
1322
+ resource_id: _selectedDiscount3.id,
1323
+ title: _selectedDiscount3.format_title,
1740
1324
  original_amount: product.original_price,
1741
1325
  product_id: product.id,
1742
- percent: _currentBundleDiscount.par_value,
1743
- discount_product_id: _currentBundleDiscount.product_id
1326
+ percent: _selectedDiscount3.par_value
1744
1327
  },
1745
1328
  metadata: _objectSpread({
1746
1329
  // 🔥 使用唯一的 _id
1747
1330
  custom_product_bundle_map_id: _uniqueId,
1748
- discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
1331
+ discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
1749
1332
  num: product.num || 1
1750
1333
  }, _productDiscountDifference !== undefined && {
1751
1334
  product_discount_difference: _productDiscountDifference
1752
1335
  }),
1753
- config: _currentBundleDiscount === null || _currentBundleDiscount === void 0 ? void 0 : _currentBundleDiscount.config,
1754
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.num) || 1)
1336
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1755
1337
  };
1756
1338
 
1757
1339
  // 记录实际应用的折扣
1758
- var _appliedProducts2 = appliedDiscountProducts.get(_currentBundleDiscount.id) || [];
1340
+ var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
1759
1341
  _appliedProducts2.push(_discountDetail2);
1760
- appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
1342
+ appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
1761
1343
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1762
1344
  total: _targetProductTotal,
1763
1345
  price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
@@ -1882,7 +1464,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1882
1464
  product_id: bundleItem.product_id,
1883
1465
  price: item.price,
1884
1466
  num: item.num,
1885
- quantity: item.num,
1886
1467
  discount_list: updatedDiscountList
1887
1468
  }));
1888
1469
  });
@@ -1906,7 +1487,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1906
1487
  product_id: bundleItem.product_id,
1907
1488
  price: item.price,
1908
1489
  num: item.num,
1909
- quantity: item.num,
1910
1490
  discount_list: _updatedDiscountList
1911
1491
  }));
1912
1492
  } else {
@@ -1921,8 +1501,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1921
1501
 
1922
1502
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1923
1503
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1924
- var _discount$metadata7, _discount$metadata8;
1925
- if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
1504
+ var _discount$metadata6, _discount$metadata7;
1505
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
1926
1506
  // bundle的discount_list保持不变
1927
1507
  return discount;
1928
1508
  }
@@ -1930,7 +1510,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1930
1510
  return _objectSpread(_objectSpread({}, discount), {}, {
1931
1511
  // num: 1,
1932
1512
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1933
- 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,
1513
+ 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,
1934
1514
  num: 1
1935
1515
  })
1936
1516
  });
@@ -1975,8 +1555,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1975
1555
  quantity: 1,
1976
1556
  discount_list: updatedMainDiscountList,
1977
1557
  bundle: newBundleWithDiscount,
1978
- total: newTotalWithDiscount,
1979
- origin_total: newOriginTotalWithDiscount
1558
+ total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
1559
+ origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
1980
1560
  })));
1981
1561
 
1982
1562
  // 第二个:包含原始bundle (qty=原quantity-1)
@@ -1995,8 +1575,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1995
1575
 
1996
1576
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1997
1577
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1998
- var _discount$metadata9, _discount$metadata10;
1999
- if (discount !== null && discount !== void 0 && (_discount$metadata9 = discount.metadata) !== null && _discount$metadata9 !== void 0 && _discount$metadata9.custom_product_bundle_map_id) {
1578
+ var _discount$metadata8, _discount$metadata9;
1579
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
2000
1580
  // bundle的discount_list保持不变
2001
1581
  return discount;
2002
1582
  }
@@ -2004,7 +1584,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2004
1584
  return _objectSpread(_objectSpread({}, discount), {}, {
2005
1585
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2006
1586
  num: mainProductQuantity - 1,
2007
- 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
1587
+ 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
2008
1588
  })
2009
1589
  // num: mainProductQuantity - 1,
2010
1590
  });
@@ -2071,11 +1651,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2071
1651
  processedBundleItems.forEach(function (item) {
2072
1652
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
2073
1653
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
2074
- var _discount$metadata11;
1654
+ var _discount$metadata10;
2075
1655
  return _objectSpread(_objectSpread({}, discount), {}, {
2076
1656
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
2077
1657
  num: item.num,
2078
- 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
1658
+ 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
2079
1659
  })
2080
1660
  // num: item.num, // 使用拆分后的 num
2081
1661
  });
@@ -2085,7 +1665,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2085
1665
  product_id: bundleItem.product_id,
2086
1666
  price: item.price,
2087
1667
  num: item.num,
2088
- quantity: item.num,
2089
1668
  discount_list: updatedDiscountList
2090
1669
  }));
2091
1670
  });
@@ -2125,8 +1704,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2125
1704
  // 累加bundle的价格(只累加一次)
2126
1705
  if (newBundle.length > 0) {
2127
1706
  newBundle.forEach(function (item) {
2128
- var _item$discount_list3;
2129
1707
  newTotal += Number(item.price) * Number(item.num);
1708
+ });
1709
+
1710
+ // 计算原始总价(不考虑折扣)
1711
+ newBundle.forEach(function (item) {
1712
+ var _item$discount_list3;
2130
1713
  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;
2131
1714
  newOriginTotal += Number(originalPrice) * Number(item.num);
2132
1715
  });
@@ -2141,6 +1724,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2141
1724
  return accumulator.add(currentPrice.mul(currentNum));
2142
1725
  }, new Decimal(newTotal)).toNumber();
2143
1726
  }
1727
+ newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1728
+ newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
2144
1729
 
2145
1730
  // 生成最终的主商品
2146
1731
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {