@pisell/pisellos 2.1.84 → 2.1.85

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 (103) 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 +168 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +76 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +1043 -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/Cart/utils/changePrice.js +0 -6
  30. package/dist/modules/Discount/index.d.ts +0 -1
  31. package/dist/modules/Discount/index.js +1 -2
  32. package/dist/modules/Discount/types.d.ts +15 -0
  33. package/dist/modules/Payment/index.d.ts +2 -1
  34. package/dist/modules/Payment/index.js +10 -7
  35. package/dist/modules/Payment/utils.js +3 -0
  36. package/dist/modules/Payment/walletpass.d.ts +23 -0
  37. package/dist/modules/Payment/walletpass.js +191 -95
  38. package/dist/modules/Rules/index.d.ts +7 -2
  39. package/dist/modules/Rules/index.js +141 -19
  40. package/dist/modules/Rules/types.d.ts +1 -0
  41. package/dist/modules/Summary/index.js +5 -47
  42. package/dist/modules/Summary/types.d.ts +2 -0
  43. package/dist/modules/Summary/utils.d.ts +7 -1
  44. package/dist/modules/Summary/utils.js +27 -21
  45. package/dist/plugins/window.d.ts +2 -0
  46. package/dist/solution/BookingByStep/index.d.ts +1 -0
  47. package/dist/solution/BookingByStep/index.js +35 -84
  48. package/dist/solution/Checkout/index.js +2 -0
  49. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  50. package/dist/solution/ShopDiscount/index.js +12 -3
  51. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  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 +168 -0
  69. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  70. package/lib/model/strategy/adapter/walletPass/utils.d.ts +76 -0
  71. package/lib/model/strategy/adapter/walletPass/utils.js +704 -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/Cart/utils/changePrice.js +0 -5
  81. package/lib/modules/Discount/index.d.ts +0 -1
  82. package/lib/modules/Discount/index.js +1 -2
  83. package/lib/modules/Discount/types.d.ts +15 -0
  84. package/lib/modules/Payment/index.d.ts +2 -1
  85. package/lib/modules/Payment/index.js +1 -0
  86. package/lib/modules/Payment/utils.js +3 -0
  87. package/lib/modules/Payment/walletpass.d.ts +23 -0
  88. package/lib/modules/Payment/walletpass.js +94 -17
  89. package/lib/modules/Rules/index.d.ts +7 -2
  90. package/lib/modules/Rules/index.js +285 -149
  91. package/lib/modules/Rules/types.d.ts +1 -0
  92. package/lib/modules/Summary/index.js +9 -22
  93. package/lib/modules/Summary/types.d.ts +2 -0
  94. package/lib/modules/Summary/utils.d.ts +7 -1
  95. package/lib/modules/Summary/utils.js +25 -21
  96. package/lib/plugins/window.d.ts +2 -0
  97. package/lib/solution/BookingByStep/index.d.ts +1 -0
  98. package/lib/solution/BookingByStep/index.js +3 -34
  99. package/lib/solution/Checkout/index.js +2 -0
  100. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  101. package/lib/solution/ShopDiscount/index.js +7 -2
  102. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  103. 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
  }
@@ -95,6 +97,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
95
97
  value: function getRulesList() {
96
98
  return this.store.rulesList;
97
99
  }
100
+ }, {
101
+ key: "getWalletPassEvaluator",
102
+ value: function getWalletPassEvaluator() {
103
+ var _this$window$getWalle, _this$window;
104
+ return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
105
+ }
98
106
 
99
107
  // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
100
108
  }, {
@@ -123,6 +131,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
123
131
  newDiscountList = _ref.newDiscountList,
124
132
  productList = _ref.productList,
125
133
  holders = _ref.holders,
134
+ orderTotalAmount = _ref.orderTotalAmount,
126
135
  isFormSubject = _ref.isFormSubject;
127
136
  // 首先检查是否有新的优惠券可应用
128
137
  if (!newDiscountList || newDiscountList.length === 0) {
@@ -157,6 +166,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
157
166
  discountList: mergedDiscountList,
158
167
  productList: _toConsumableArray(productList),
159
168
  holders: holders,
169
+ orderTotalAmount: orderTotalAmount,
160
170
  isFormSubject: isFormSubject
161
171
  }, {
162
172
  scan: true
@@ -282,6 +292,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
282
292
  var discountList = _ref2.discountList,
283
293
  productList = _ref2.productList,
284
294
  holders = _ref2.holders,
295
+ orderTotalAmount = _ref2.orderTotalAmount,
285
296
  isFormSubject = _ref2.isFormSubject;
286
297
  // 识别出来是不是在编辑的界面里又新增了商品
287
298
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
@@ -529,6 +540,57 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
529
540
  return priceB.minus(priceA).toNumber();
530
541
  });
531
542
 
543
+ // 🔥 为每个折扣卡/商品券执行策略检查并附加config
544
+ var evaluator = this.getWalletPassEvaluator();
545
+ if (evaluator) {
546
+ addModeDiscount.forEach(function (discount) {
547
+ var discountType = discount.tag || discount.type;
548
+ // 只对 good_pass 和 discount_card 类型执行策略检查
549
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
550
+ var _discount$limited_rel, _discount$limited_rel2;
551
+ // 转换 discount 为 Voucher 格式
552
+ var voucher = {
553
+ id: discount.id,
554
+ amount: Number(discount.par_value || 0),
555
+ balance: Number(discount.balance || 0),
556
+ type: discountType,
557
+ product_id: discount.product_id,
558
+ unified_available_status: 1,
559
+ available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
560
+ available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
561
+ };
562
+
563
+ // 转换 sortedFlattenedList 为 Product 格式
564
+ var productsForEvaluate = sortedFlattenedList.map(function (item) {
565
+ return {
566
+ product_id: item.id,
567
+ price: item.price || 0,
568
+ quantity: item.quantity || item.num || 1,
569
+ selling_price: item.price || 0
570
+ };
571
+ });
572
+
573
+ // 调用策略检查
574
+ var result = evaluator.checkVoucherAvailability({
575
+ orderTotalAmount: orderTotalAmount,
576
+ products: productsForEvaluate,
577
+ vouchers: [voucher]
578
+ });
579
+
580
+ // 将 config 附加到 discount 对象
581
+ if (result.isAvailable) {
582
+ discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
583
+ isAvailable: true
584
+ });
585
+ } else {
586
+ discount.config = {
587
+ isAvailable: false
588
+ };
589
+ }
590
+ }
591
+ });
592
+ }
593
+
532
594
  /**
533
595
  // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
534
596
  const sortedProductList = [...productList].sort((a, b) => {
@@ -549,6 +611,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
549
611
  // 标记已使用的优惠券
550
612
  var usedDiscounts = new Map();
551
613
 
614
+ // 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
615
+ var usedProductIdCounts = new Map();
616
+
552
617
  // 记录每个优惠券适用的商品ID
553
618
  var discountApplicability = new Map();
554
619
 
@@ -778,7 +843,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
778
843
  originProduct = flatItem.originProduct;
779
844
  }
780
845
  addModeDiscount.forEach(function (discount) {
781
- var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
846
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
782
847
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
783
848
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
784
849
  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 +854,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
789
854
  var timeLimit = true;
790
855
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
791
856
  // 是符合折扣的商品
792
- var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
857
+ 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
858
 
794
859
  // 编辑的商品 使用了优惠券不可用
795
860
  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,7 +867,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
802
867
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
803
868
 
804
869
  // 判断优惠券是否适用于该商品
805
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
870
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
806
871
  var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
807
872
  // 记录此优惠券适用的商品
808
873
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -826,7 +891,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
826
891
  title: discount.format_title,
827
892
  original_amount: product.price || product.origin_total,
828
893
  pre_value: discount.par_value,
829
- product_id: originProduct.id
894
+ product_id: originProduct.id,
895
+ discount_product_id: discount.product_id
830
896
  },
831
897
  metadata: {
832
898
  num: num
@@ -886,6 +952,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
886
952
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
887
953
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
888
954
  var _product$discount_lis3, _product$discount_lis4;
955
+ // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
956
+ var discountType = discount.tag || discount.type;
957
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
958
+ var _discount$config2;
959
+ // 如果策略检查后没有config,说明不可用
960
+ if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
961
+ return false;
962
+ }
963
+ }
964
+
889
965
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
890
966
  // 商品券时主商品价格为0不可用
891
967
  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,6 +974,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
898
974
  // 如果优惠券已被使用,则跳过
899
975
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
900
976
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
977
+
978
+ // 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
979
+ if ((discount.tag || discount.type) === 'good_pass') {
980
+ var _discount$config3;
981
+ var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
982
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
983
+ var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
984
+ if (currentUsedCount >= maxUsagePerOrder) {
985
+ return false;
986
+ }
987
+ }
988
+ }
901
989
  var limitedData = discount.limited_relation_product_data;
902
990
 
903
991
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
@@ -916,6 +1004,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
916
1004
 
917
1005
  // 判断优惠券是否适用于该商品
918
1006
  if (limitedData.type === 'product_all') {
1007
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1008
+ return false;
1009
+ }
919
1010
  // 检查 package_sub_item_usage_rules
920
1011
  if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
921
1012
  return false;
@@ -1082,7 +1173,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1082
1173
  var availableGoodPassCount = applicableDiscounts.filter(function (item) {
1083
1174
  return (item.tag || item.type) === 'good_pass';
1084
1175
  }).length;
1085
- var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
1176
+
1177
+ // 🔥 如果selectedDiscount有config配置,则使用config.maxUsagePerOrder限制使用次数
1178
+ var maxUsageLimit = availableGoodPassCount;
1179
+ if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
1180
+ maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
1181
+ }
1182
+ var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
1086
1183
  var arr = [];
1087
1184
 
1088
1185
  // 🔥 主商品和bundle子商品分别处理
@@ -1092,7 +1189,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1092
1189
  arr.push(_this3.hooks.setProduct(originProduct, {
1093
1190
  discount_list: [],
1094
1191
  quantity: totalQuantity - splitCount,
1095
- _id: product._id.split('___')[0]
1192
+ _id: product._id.split('___')[0],
1193
+ total: product.origin_total || product.total
1096
1194
  }));
1097
1195
  }
1098
1196
  for (var i = 0; i < splitCount; i++) {
@@ -1101,6 +1199,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1101
1199
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1102
1200
  // 标记优惠券为已使用
1103
1201
  usedDiscounts.set(_selectedDiscount.id, true);
1202
+ // 🔥 更新 product_id 使用计数
1203
+ if ((_selectedDiscount.tag || _selectedDiscount.type) === 'good_pass') {
1204
+ var currentCount = usedProductIdCounts.get(_selectedDiscount.product_id) || 0;
1205
+ usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + 1);
1206
+ }
1104
1207
 
1105
1208
  // 记录实际应用了优惠券的商品信息
1106
1209
  var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
@@ -1134,7 +1237,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1134
1237
  targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1135
1238
  amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1136
1239
  }
1137
- var discountType = _selectedDiscount.tag || _selectedDiscount.type;
1240
+ var discountType = _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag;
1138
1241
  var isGoodPass = discountType === 'good_pass';
1139
1242
  var discountDetail = {
1140
1243
  amount: amount,
@@ -1147,10 +1250,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1147
1250
  title: _selectedDiscount.format_title,
1148
1251
  original_amount: product.price,
1149
1252
  product_id: originProduct.id,
1150
- percent: _selectedDiscount.par_value
1253
+ percent: _selectedDiscount.par_value,
1254
+ discount_product_id: _selectedDiscount.product_id
1151
1255
  },
1152
1256
  // 前端使用的num数量,为了计算优惠金额
1153
1257
  _num: isGoodPass ? 1 : product.num,
1258
+ config: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.config,
1154
1259
  metadata: _objectSpread({
1155
1260
  num: 1
1156
1261
  }, productDiscountDifference !== undefined && {
@@ -1171,7 +1276,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1171
1276
  // 记录应用了优惠券的商品
1172
1277
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
1173
1278
  if (product.isClient) {
1174
- debugger;
1175
1279
  arr.push(_this3.hooks.setProduct(originProduct, {
1176
1280
  discount_list: [discountDetail],
1177
1281
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
@@ -1213,11 +1317,20 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1213
1317
  var _selectedDiscount2$me;
1214
1318
  var _selectedDiscount2 = applicableDiscounts[_i];
1215
1319
  usedDiscounts.set(_selectedDiscount2.id, true);
1320
+ // 🔥 更新 product_id 使用计数
1321
+ if ((_selectedDiscount2.tag || _selectedDiscount2.type) === 'good_pass') {
1322
+ var _currentCount = usedProductIdCounts.get(_selectedDiscount2.product_id) || 0;
1323
+ usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + 1);
1324
+ }
1216
1325
 
1217
1326
  // 🔥 生成唯一的 _id
1218
1327
  var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
1328
+
1329
+ // 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
1330
+ var discountedPrice = getDiscountAmount(_selectedDiscount2, product.origin_total, product.origin_total);
1331
+ var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
1219
1332
  var _discountDetail = {
1220
- amount: product.origin_total,
1333
+ amount: bundleDiscountAmount,
1221
1334
  type: 'good_pass',
1222
1335
  discount: {
1223
1336
  fixed_amount: product.origin_total,
@@ -1225,14 +1338,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1225
1338
  resource_id: _selectedDiscount2.id,
1226
1339
  title: _selectedDiscount2.format_title,
1227
1340
  original_amount: product.origin_total,
1228
- product_id: product.id
1341
+ product_id: product.id,
1342
+ discount_product_id: _selectedDiscount2.product_id
1229
1343
  },
1230
1344
  metadata: {
1231
1345
  // 🔥 使用拆分后的唯一 _id
1232
1346
  custom_product_bundle_map_id: uniqueId,
1233
1347
  num: 1
1234
1348
  },
1235
- _num: 1
1349
+ _num: 1,
1350
+ config: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.config
1236
1351
  };
1237
1352
 
1238
1353
  // 记录实际应用的折扣
@@ -1244,9 +1359,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1244
1359
  _id: uniqueId,
1245
1360
  num: 1,
1246
1361
  quantity: 1,
1247
- price: 0,
1248
- // 商品券价格为0
1249
- total: 0,
1362
+ price: discountedPrice,
1363
+ // 折扣后的价格
1364
+ total: discountedPrice,
1250
1365
  discount_list: [_discountDetail],
1251
1366
  processed: true,
1252
1367
  _discountId: _selectedDiscount2.id
@@ -1269,6 +1384,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1269
1384
  // 折扣卡:不拆分数量,直接应用
1270
1385
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1271
1386
  usedDiscounts.set(_selectedDiscount3.id, true);
1387
+ // 🔥 更新 product_id 使用计数(虽然此处主要是折扣卡,但保持一致性)
1388
+ if ((_selectedDiscount3.tag || _selectedDiscount3.type) === 'good_pass') {
1389
+ var _currentCount2 = usedProductIdCounts.get(_selectedDiscount3.product_id) || 0;
1390
+ usedProductIdCounts.set(_selectedDiscount3.product_id, _currentCount2 + 1);
1391
+ }
1272
1392
  var _productOriginTotal = product.original_price || product.price || 0;
1273
1393
 
1274
1394
  // 🔥 检查是否是 order_level 固定金额折扣卡
@@ -1288,7 +1408,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1288
1408
  _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1289
1409
  fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1290
1410
  }
1291
- debugger;
1411
+
1292
1412
  // 🔥 使用当前的 _id 作为唯一标识
1293
1413
  var _uniqueId = flatItem._id;
1294
1414
  var _discountDetail2 = {
@@ -1302,7 +1422,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1302
1422
  title: _selectedDiscount3.format_title,
1303
1423
  original_amount: product.original_price,
1304
1424
  product_id: product.id,
1305
- percent: _selectedDiscount3.par_value
1425
+ percent: _selectedDiscount3.par_value,
1426
+ discount_product_id: _selectedDiscount3.product_id
1306
1427
  },
1307
1428
  metadata: _objectSpread({
1308
1429
  // 🔥 使用唯一的 _id
@@ -1311,6 +1432,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1311
1432
  }, _productDiscountDifference !== undefined && {
1312
1433
  product_discount_difference: _productDiscountDifference
1313
1434
  }),
1435
+ config: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.config,
1314
1436
  _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1315
1437
  };
1316
1438
 
@@ -31,6 +31,7 @@ export interface RulesModuleAPI {
31
31
  holders: {
32
32
  form_record_id: number;
33
33
  }[];
34
+ orderTotalAmount: number;
34
35
  isFormSubject: boolean;
35
36
  }) => DiscountResult;
36
37
  }
@@ -1,7 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
6
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
7
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -89,7 +86,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
89
86
  while (1) switch (_context2.prev = _context2.next) {
90
87
  case 0:
91
88
  _context2.next = 2;
92
- return this.request.get('/order/custom-surcharge/available/v2', {
89
+ return this.request.get('/order/custom-surcharge/available', {
93
90
  channel: 'online-store',
94
91
  is_assemble_product_data: 1,
95
92
  is_assemble_schedule_data: 1,
@@ -114,34 +111,15 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
114
111
  value: function () {
115
112
  var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(cartItems) {
116
113
  var _this$shopStore$get;
117
- var shopInfo, scheduleModule, needScheduleIds, scheduleList, scheduleById, _iterator, _step, item, summary;
114
+ var shopInfo, summary;
118
115
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
119
116
  while (1) switch (_context3.prev = _context3.next) {
120
117
  case 0:
121
118
  shopInfo = ((_this$shopStore$get = this.shopStore.get('core')) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.shop) || {};
122
- scheduleModule = this.core.getModule('appointmentBooking_schedule');
123
- needScheduleIds = this.store.surchargeList.map(function (item) {
124
- return item.available_schedule_ids;
125
- }).flat();
126
- scheduleList = scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
127
- scheduleById = {};
128
- if (Array.isArray(scheduleList)) {
129
- _iterator = _createForOfIteratorHelper(scheduleList);
130
- try {
131
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
132
- item = _step.value;
133
- scheduleById[item.id] = item;
134
- }
135
- } catch (err) {
136
- _iterator.e(err);
137
- } finally {
138
- _iterator.f();
139
- }
140
- }
141
- summary = calculatePriceDetails(shopInfo, cartItems, ScheduleModule === null || ScheduleModule === void 0 ? void 0 : ScheduleModule.isInScheduleByDate, this.store.surchargeList, scheduleById);
119
+ summary = calculatePriceDetails(shopInfo, cartItems, ScheduleModule.isInScheduleByDate, this.store.surchargeList);
142
120
  this.store.summary = summary;
143
121
  return _context3.abrupt("return", this.store.summary);
144
- case 9:
122
+ case 4:
145
123
  case "end":
146
124
  return _context3.stop();
147
125
  }
@@ -209,26 +187,6 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
209
187
  key: "getSurchargeforUtils",
210
188
  value: function getSurchargeforUtils(items) {
211
189
  // const surchargeList = this.store.surchargeList;
212
- var scheduleModule = this.core.getModule('appointmentBooking_schedule');
213
- var needScheduleIds = this.store.surchargeList.map(function (item) {
214
- return item.available_schedule_ids;
215
- }).flat();
216
- var scheduleList = scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
217
- var scheduleById = {};
218
- if (Array.isArray(scheduleList)) {
219
- var _iterator2 = _createForOfIteratorHelper(scheduleList),
220
- _step2;
221
- try {
222
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
223
- var item = _step2.value;
224
- scheduleById[item.id] = item;
225
- }
226
- } catch (err) {
227
- _iterator2.e(err);
228
- } finally {
229
- _iterator2.f();
230
- }
231
- }
232
190
  var surchargeList = getSurcharge({
233
191
  service: items,
234
192
  addons: [],
@@ -238,7 +196,7 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
238
196
  isEdit: false,
239
197
  isInScheduleByDate: ScheduleModule.isInScheduleByDate,
240
198
  surcharge_list: this.store.surchargeList,
241
- scheduleById: scheduleById
199
+ scheduleById: {}
242
200
  });
243
201
  var surchargeAmount = new Decimal(getSurchargeAmount({
244
202
  bookingDetail: null,
@@ -6,6 +6,8 @@ export interface ISummaryState {
6
6
  subtotal: string | number;
7
7
  /** 最终总价 */
8
8
  total: string | number;
9
+ /** 最终原始价格 不包含折扣卡商品券折扣 */
10
+ originTotal: string | number;
9
11
  /** 税率标题 */
10
12
  taxTitle?: string;
11
13
  /** 商品总费率 */
@@ -1,7 +1,7 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import { CartItem } from '../Cart/types';
3
3
  import { ISummaryState } from './types';
4
- export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[], scheduleById: Record<string, any>) => ISummaryState['summary'];
4
+ export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[], isInScheduleByDate: any, surchargeList: any[]) => ISummaryState['summary'];
5
5
  /**
6
6
  * 获取子商品折扣信息
7
7
  * @param item
@@ -58,6 +58,12 @@ export declare const getTax: ({ service, addons, bookingDetail, bookingId }: {
58
58
  * @returns 商品总价字符串,保留2位小数
59
59
  */
60
60
  export declare const calculateSubtotal: (items: CartItem[]) => string;
61
+ /**
62
+ * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
63
+ * @param items - 购物车商品数组
64
+ * @returns 商品总价字符串,保留2位小数
65
+ */
66
+ export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
61
67
  /**
62
68
  * @title: 单个商品的税费
63
69
  * @description:
@@ -16,10 +16,9 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
16
16
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
17
17
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
18
  import Decimal from 'decimal.js';
19
- import { isNormalProduct } from "../Product/utils";
20
- import dayjs from 'dayjs';
21
- export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) {
19
+ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList) {
22
20
  var subtotal = new Decimal(calculateSubtotal(items));
21
+ var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
23
22
  var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
24
23
  // 订单附加费列表
25
24
  var surcharge = getSurcharge({
@@ -31,7 +30,7 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
31
30
  isEdit: false,
32
31
  isInScheduleByDate: isInScheduleByDate,
33
32
  surcharge_list: surchargeList,
34
- scheduleById: scheduleById
33
+ scheduleById: {}
35
34
  });
36
35
  // 订单附加费金额
37
36
  var surchargeAmount = new Decimal(getSurchargeAmount({
@@ -58,11 +57,15 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
58
57
  originTax = _getTax.originTax;
59
58
  var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
60
59
 
60
+ // 计算总价 不包含折扣卡商品券折扣信息价格
61
+ var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
62
+
61
63
  // 计算定金
62
64
  var deposit = calculateDeposit(items);
63
65
  return {
64
66
  subtotal: subtotal.toFixed(2),
65
67
  total: total.toFixed(2),
68
+ originTotal: originTotal.toFixed(2),
66
69
  taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
67
70
  taxRate: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_rate,
68
71
  totalTaxFee: tax,
@@ -572,6 +575,22 @@ export var calculateSubtotal = function calculateSubtotal(items) {
572
575
  return subtotal.toFixed(2);
573
576
  };
574
577
 
578
+ /**
579
+ * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
580
+ * @param items - 购物车商品数组
581
+ * @returns 商品总价字符串,保留2位小数
582
+ */
583
+ export var calculateOriginSubtotal = function calculateOriginSubtotal(items) {
584
+ if (!(items !== null && items !== void 0 && items.length)) {
585
+ return '0.00';
586
+ }
587
+ var subtotal = items.reduce(function (sum, item) {
588
+ var cartItemTotalPrice = new Decimal(item.summaryOriginTotal || 0);
589
+ return sum.plus(cartItemTotalPrice);
590
+ }, new Decimal(0));
591
+ return subtotal.toFixed(2);
592
+ };
593
+
575
594
  /**
576
595
  * @title: 单个商品的税费
577
596
  * @description:
@@ -843,7 +862,6 @@ var isProductMatchSurchargeCondition = function isProductMatchSurchargeCondition
843
862
  * @returns 附加费列表(仅返回金额 > 0 的项)
844
863
  */
845
864
  export var getSurcharge = function getSurcharge(_ref11, options) {
846
- var _service$filter;
847
865
  var service = _ref11.service,
848
866
  addons = _ref11.addons,
849
867
  bookingDetail = _ref11.bookingDetail,
@@ -852,16 +870,6 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
852
870
  isInScheduleByDate = options.isInScheduleByDate,
853
871
  surcharge_list = options.surcharge_list,
854
872
  scheduleById = options.scheduleById;
855
- // 在所有商品里试着找 start_date,如果没有则用当前时间
856
- var firstAppointmentCartItem = (_service$filter = service.filter(function (n) {
857
- return !isNormalProduct(n._productOrigin);
858
- })) === null || _service$filter === void 0 ? void 0 : _service$filter[0];
859
- var startDate = '';
860
- if (firstAppointmentCartItem) {
861
- startDate = firstAppointmentCartItem.start_date + ' ' + firstAppointmentCartItem.start_time + ':00';
862
- } else {
863
- startDate = dayjs().format('YYYY-MM-DD HH:mm:ss');
864
- }
865
873
  // 编辑状态, 且未修改商品时直接从详情取出
866
874
  if (!isEdit && bookingId) {
867
875
  if (Array.isArray(bookingDetail === null || bookingDetail === void 0 ? void 0 : bookingDetail.surcharge)) {
@@ -928,7 +936,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
928
936
  // 主商品符合附加费条件
929
937
  if (isProductMatchSurchargeCondition({
930
938
  isCustomItem: item.isCustomItem,
931
- startDate: startDate,
939
+ startDate: (item === null || item === void 0 ? void 0 : item.startDate) || '',
932
940
  product_id: item.id
933
941
  }, {
934
942
  surchargeConfig: surchargeConfig,
@@ -962,7 +970,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
962
970
  // bundle商品是原价且符合附加费条件
963
971
  if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition({
964
972
  isCustomItem: false,
965
- startDate: startDate,
973
+ startDate: item.startDate,
966
974
  product_id: bundleItem._bundle_product_id
967
975
  }, {
968
976
  surchargeConfig: surchargeConfig,
@@ -994,7 +1002,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
994
1002
  var relationDetail = _step7.value;
995
1003
  if (isProductMatchSurchargeCondition({
996
1004
  isCustomItem: false,
997
- startDate: startDate,
1005
+ startDate: item.startDate,
998
1006
  product_id: relationDetail.product_id
999
1007
  }, {
1000
1008
  surchargeConfig: surchargeConfig,
@@ -1031,9 +1039,7 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
1031
1039
  try {
1032
1040
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1033
1041
  var _item = _step8.value;
1034
- if (isProductMatchSurchargeCondition(_objectSpread(_objectSpread({}, _item), {}, {
1035
- startDate: startDate
1036
- }), {
1042
+ if (isProductMatchSurchargeCondition(_item, {
1037
1043
  surchargeConfig: surchargeConfig,
1038
1044
  scheduleById: scheduleById || {},
1039
1045
  isInScheduleByDate: isInScheduleByDate