@pisell/pisellos 2.1.81 → 2.1.82

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 (95) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +497 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +165 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/types.d.ts +15 -0
  30. package/dist/modules/Payment/index.d.ts +2 -1
  31. package/dist/modules/Payment/index.js +10 -7
  32. package/dist/modules/Payment/utils.js +3 -0
  33. package/dist/modules/Payment/walletpass.d.ts +23 -0
  34. package/dist/modules/Payment/walletpass.js +191 -95
  35. package/dist/modules/Rules/index.d.ts +7 -2
  36. package/dist/modules/Rules/index.js +141 -19
  37. package/dist/modules/Rules/types.d.ts +1 -0
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +6 -0
  40. package/dist/modules/Summary/utils.js +21 -0
  41. package/dist/plugins/window.d.ts +2 -0
  42. package/dist/solution/BookingByStep/index.d.ts +3 -2
  43. package/dist/solution/BookingTicket/index.d.ts +1 -1
  44. package/dist/solution/Checkout/index.js +2 -0
  45. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  46. package/dist/solution/ShopDiscount/index.js +11 -1
  47. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  48. package/lib/index.d.ts +1 -0
  49. package/lib/index.js +3 -1
  50. package/lib/model/index.d.ts +1 -0
  51. package/lib/model/index.js +23 -0
  52. package/lib/model/strategy/adapter/index.d.ts +3 -0
  53. package/lib/model/strategy/adapter/index.js +45 -0
  54. package/lib/model/strategy/adapter/type.d.ts +28 -0
  55. package/lib/model/strategy/adapter/type.js +17 -0
  56. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  57. package/lib/model/strategy/adapter/walletPass/evaluator.js +421 -0
  58. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  59. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  60. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  61. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  62. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  63. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  64. package/lib/model/strategy/adapter/walletPass/type.d.ts +165 -0
  65. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  66. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  67. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  68. package/lib/model/strategy/index.d.ts +94 -0
  69. package/lib/model/strategy/index.js +413 -0
  70. package/lib/model/strategy/strategy-example.d.ts +5 -0
  71. package/lib/model/strategy/strategy-example.js +318 -0
  72. package/lib/model/strategy/type.d.ts +228 -0
  73. package/lib/model/strategy/type.js +44 -0
  74. package/lib/modules/Cart/types.d.ts +2 -0
  75. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  76. package/lib/modules/Discount/types.d.ts +15 -0
  77. package/lib/modules/Payment/index.d.ts +2 -1
  78. package/lib/modules/Payment/index.js +1 -0
  79. package/lib/modules/Payment/utils.js +3 -0
  80. package/lib/modules/Payment/walletpass.d.ts +23 -0
  81. package/lib/modules/Payment/walletpass.js +94 -17
  82. package/lib/modules/Rules/index.d.ts +7 -2
  83. package/lib/modules/Rules/index.js +285 -149
  84. package/lib/modules/Rules/types.d.ts +1 -0
  85. package/lib/modules/Summary/types.d.ts +2 -0
  86. package/lib/modules/Summary/utils.d.ts +6 -0
  87. package/lib/modules/Summary/utils.js +15 -0
  88. package/lib/plugins/window.d.ts +2 -0
  89. package/lib/solution/BookingByStep/index.d.ts +3 -2
  90. package/lib/solution/BookingTicket/index.d.ts +1 -1
  91. package/lib/solution/Checkout/index.js +2 -0
  92. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  93. package/lib/solution/ShopDiscount/index.js +6 -0
  94. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  95. 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
  }
@@ -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
  /** 商品总费率 */
@@ -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:
@@ -18,6 +18,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
18
18
  import Decimal from 'decimal.js';
19
19
  export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList) {
20
20
  var subtotal = new Decimal(calculateSubtotal(items));
21
+ var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
21
22
  var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
22
23
  // 订单附加费列表
23
24
  var surcharge = getSurcharge({
@@ -56,11 +57,15 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
56
57
  originTax = _getTax.originTax;
57
58
  var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
58
59
 
60
+ // 计算总价 不包含折扣卡商品券折扣信息价格
61
+ var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
62
+
59
63
  // 计算定金
60
64
  var deposit = calculateDeposit(items);
61
65
  return {
62
66
  subtotal: subtotal.toFixed(2),
63
67
  total: total.toFixed(2),
68
+ originTotal: originTotal.toFixed(2),
64
69
  taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
65
70
  taxRate: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_rate,
66
71
  totalTaxFee: tax,
@@ -570,6 +575,22 @@ export var calculateSubtotal = function calculateSubtotal(items) {
570
575
  return subtotal.toFixed(2);
571
576
  };
572
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
+
573
594
  /**
574
595
  * @title: 单个商品的税费
575
596
  * @description:
@@ -1,3 +1,4 @@
1
+ import { WalletPassEvaluator } from '../model';
1
2
  import { Plugin } from '../types';
2
3
  /**
3
4
  * WindowPlugin 接口定义
@@ -14,6 +15,7 @@ export interface WindowPlugin extends Plugin {
14
15
  document: Partial<Document>;
15
16
  history: History;
16
17
  interaction?: any;
18
+ getWalletPassEvaluator?: () => WalletPassEvaluator;
17
19
  }
18
20
  /**
19
21
  * 简单的 Storage 接口实现
@@ -144,6 +144,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
144
144
  getSummary(): Promise<{
145
145
  subtotal: string | number;
146
146
  total: string | number;
147
+ originTotal: string | number;
147
148
  taxTitle?: string | undefined;
148
149
  totalTaxFee?: string | number | undefined;
149
150
  isPriceIncludeTax?: 0 | 1 | undefined;
@@ -310,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
310
311
  date: string;
311
312
  status: string;
312
313
  week: string;
313
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
315
  }[]>;
315
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
316
317
  private getScheduleDataByIds;
@@ -357,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
357
358
  };
358
359
  setOtherData(key: string, value: any): void;
359
360
  getOtherData(key: string): any;
360
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
361
362
  /**
362
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
363
364
  *
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
115
115
  * 获取当前的客户搜索条件
116
116
  * @returns 当前搜索条件
117
117
  */
118
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
118
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
119
119
  /**
120
120
  * 获取客户列表状态(包含滚动加载相关状态)
121
121
  * @returns 客户状态
@@ -403,6 +403,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
403
403
  product_id: item.product_id,
404
404
  product_variant_id: item.product_variant_id,
405
405
  quantity: item.num,
406
+ is_price_include_tax: item.is_price_include_tax,
406
407
  // 商品是否含税:1;0
407
408
  is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
408
409
  // 若商品不含税,计算得到的税费,单位(元)
@@ -427,6 +428,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
427
428
  },
428
429
  product_bundle: item.product_bundle.map(function (bundle) {
429
430
  return {
431
+ is_price_include_tax: item.is_price_include_tax,
430
432
  bundle_id: bundle.bundle_id,
431
433
  bundle_product_id: bundle.bundle_product_id,
432
434
  bundle_variant_id: bundle.bundle_variant_id,
@@ -22,6 +22,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
22
22
  getCurrentBookingTime(): string | null;
23
23
  private filterDiscountListByBookingTime;
24
24
  setCustomer(customer: Customer): Promise<void>;
25
+ setOriginTotalAmount(amount: number): void;
25
26
  setHolders(holders: {
26
27
  form_record_id: number;
27
28
  }[]): void;
@@ -56,6 +56,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
56
56
  originalDiscountList: [],
57
57
  currentBookingTime: "",
58
58
  filteredDiscountList: [],
59
+ orderTotalAmount: 0,
59
60
  bookingSubject: undefined
60
61
  };
61
62
  return _this;
@@ -288,7 +289,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
288
289
  return _setCustomer.apply(this, arguments);
289
290
  }
290
291
  return setCustomer;
291
- }() // 设置holders
292
+ }()
293
+ }, {
294
+ key: "setOriginTotalAmount",
295
+ value: function setOriginTotalAmount(amount) {
296
+ this.store.orderTotalAmount = amount;
297
+ }
298
+
299
+ // 设置holders
292
300
  }, {
293
301
  key: "setHolders",
294
302
  value: function setHolders(holders) {
@@ -317,6 +325,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
317
325
  productList: productList,
318
326
  discountList: this.getDiscountList(),
319
327
  holders: this.store.holders || [],
328
+ orderTotalAmount: this.store.orderTotalAmount || 0,
320
329
  isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
321
330
  }, options) || {
322
331
  productList: productList,
@@ -458,6 +467,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
458
467
  oldDiscountList: this.getDiscountList(),
459
468
  newDiscountList: withScanList,
460
469
  holders: this.store.holders || [],
470
+ orderTotalAmount: this.store.orderTotalAmount || 0,
461
471
  isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
462
472
  }) || {
463
473
  isAvailable: false,
@@ -31,6 +31,7 @@ export interface ShopDiscountState {
31
31
  originalDiscountList: Discount[];
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
+ orderTotalAmount?: number;
34
35
  bookingSubject?: {
35
36
  type?: 'form' | 'customer';
36
37
  [key: string]: any;
package/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './types';
6
6
  export * from './modules';
7
7
  export * from './plugins';
8
8
  export * from './solution';
9
+ export * from './model';
9
10
  export { PisellOSCore } from './core';
10
11
  import PisellOSCore from './core';
11
12
  export default PisellOSCore;
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ __reExport(src_exports, require("./types"), module.exports);
38
38
  __reExport(src_exports, require("./modules"), module.exports);
39
39
  __reExport(src_exports, require("./plugins"), module.exports);
40
40
  __reExport(src_exports, require("./solution"), module.exports);
41
+ __reExport(src_exports, require("./model"), module.exports);
41
42
  var import_core = require("./core");
42
43
  var import_core2 = __toESM(require("./core"));
43
44
  var src_default = import_core2.default;
@@ -47,5 +48,6 @@ var src_default = import_core2.default;
47
48
  ...require("./types"),
48
49
  ...require("./modules"),
49
50
  ...require("./plugins"),
50
- ...require("./solution")
51
+ ...require("./solution"),
52
+ ...require("./model")
51
53
  });
@@ -0,0 +1 @@
1
+ export * from './strategy';
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/model/index.ts
17
+ var model_exports = {};
18
+ module.exports = __toCommonJS(model_exports);
19
+ __reExport(model_exports, require("./strategy"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./strategy")
23
+ });
@@ -0,0 +1,3 @@
1
+ export * from './type';
2
+ export { default as WalletPassAdapter } from './walletPass';
3
+ export { WalletPassEvaluator } from './walletPass/evaluator';