@pisell/pisellos 2.1.118 → 2.1.119

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 (106) 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 +24 -56
  5. package/dist/modules/Discount/types.d.ts +0 -18
  6. package/dist/modules/Payment/index.d.ts +1 -2
  7. package/dist/modules/Payment/index.js +7 -10
  8. package/dist/modules/Payment/utils.js +0 -3
  9. package/dist/modules/Payment/walletpass.d.ts +0 -23
  10. package/dist/modules/Payment/walletpass.js +95 -191
  11. package/dist/modules/Product/index.d.ts +1 -1
  12. package/dist/modules/Rules/index.d.ts +5 -9
  13. package/dist/modules/Rules/index.js +162 -674
  14. package/dist/modules/Rules/types.d.ts +0 -2
  15. package/dist/modules/Summary/types.d.ts +0 -2
  16. package/dist/modules/Summary/utils.d.ts +0 -6
  17. package/dist/modules/Summary/utils.js +0 -21
  18. package/dist/plugins/window.d.ts +0 -2
  19. package/dist/solution/BookingByStep/index.d.ts +0 -1
  20. package/dist/solution/BookingByStep/index.js +44 -42
  21. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  22. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  23. package/dist/solution/BookingTicket/index.d.ts +1 -1
  24. package/dist/solution/Checkout/index.js +0 -2
  25. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  26. package/dist/solution/ShopDiscount/index.js +7 -23
  27. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  28. package/dist/solution/ShopDiscount/types.js +1 -2
  29. package/dist/solution/ShopDiscount/utils.js +12 -26
  30. package/lib/index.d.ts +0 -1
  31. package/lib/index.js +1 -3
  32. package/lib/modules/Cart/types.d.ts +0 -2
  33. package/lib/modules/Cart/utils/cartProduct.js +11 -39
  34. package/lib/modules/Discount/types.d.ts +0 -18
  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/Product/index.d.ts +1 -1
  41. package/lib/modules/Rules/index.d.ts +5 -9
  42. package/lib/modules/Rules/index.js +284 -779
  43. package/lib/modules/Rules/types.d.ts +0 -2
  44. package/lib/modules/Summary/types.d.ts +0 -2
  45. package/lib/modules/Summary/utils.d.ts +0 -6
  46. package/lib/modules/Summary/utils.js +0 -15
  47. package/lib/plugins/window.d.ts +0 -2
  48. package/lib/solution/BookingByStep/index.d.ts +0 -1
  49. package/lib/solution/BookingByStep/index.js +4 -2
  50. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  51. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/index.js +0 -2
  54. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  55. package/lib/solution/ShopDiscount/index.js +8 -22
  56. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  57. package/lib/solution/ShopDiscount/utils.js +6 -10
  58. package/package.json +1 -1
  59. package/dist/model/index.d.ts +0 -1
  60. package/dist/model/index.js +0 -1
  61. package/dist/model/strategy/adapter/index.d.ts +0 -3
  62. package/dist/model/strategy/adapter/index.js +0 -4
  63. package/dist/model/strategy/adapter/type.d.ts +0 -28
  64. package/dist/model/strategy/adapter/type.js +0 -1
  65. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  66. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -499
  67. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  68. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  69. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  70. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  71. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  72. package/dist/model/strategy/adapter/walletPass/locales.js +0 -26
  73. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -187
  74. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  75. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  76. package/dist/model/strategy/adapter/walletPass/utils.js +0 -1104
  77. package/dist/model/strategy/index.d.ts +0 -94
  78. package/dist/model/strategy/index.js +0 -551
  79. package/dist/model/strategy/strategy-example.d.ts +0 -5
  80. package/dist/model/strategy/strategy-example.js +0 -331
  81. package/dist/model/strategy/type.d.ts +0 -228
  82. package/dist/model/strategy/type.js +0 -94
  83. package/lib/model/index.d.ts +0 -1
  84. package/lib/model/index.js +0 -23
  85. package/lib/model/strategy/adapter/index.d.ts +0 -3
  86. package/lib/model/strategy/adapter/index.js +0 -45
  87. package/lib/model/strategy/adapter/type.d.ts +0 -28
  88. package/lib/model/strategy/adapter/type.js +0 -17
  89. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  90. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -423
  91. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  92. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  93. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  94. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  95. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  96. package/lib/model/strategy/adapter/walletPass/locales.js +0 -54
  97. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -187
  98. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  99. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  100. package/lib/model/strategy/adapter/walletPass/utils.js +0 -791
  101. package/lib/model/strategy/index.d.ts +0 -94
  102. package/lib/model/strategy/index.js +0 -413
  103. package/lib/model/strategy/strategy-example.d.ts +0 -5
  104. package/lib/model/strategy/strategy-example.js +0 -318
  105. package/lib/model/strategy/type.d.ts +0 -228
  106. package/lib/model/strategy/type.js +0 -44
@@ -1,499 +0,0 @@
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
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- import { StrategyEngine } from "../../index";
14
- import { processVouchers as _processVouchers, recalculateVouchers as _recalculateVouchers, getApplicableProductIds, getMainProductPrice, getBundleItemPrice, getProductQuantity, getBundleItemIsOriginalPrice } from "./utils";
15
- import { locales } from "./locales";
16
- import Decimal from 'decimal.js';
17
- var defaultStrategyMetadataCustom = {
18
- maxDeductionAmount: 99999,
19
- maxUsagePerOrder: 0,
20
- allowCrossProduct: true,
21
- applicableProductLimit: 0,
22
- deductTaxAndFee: true,
23
- maxPassesPerItem: 0,
24
- deductOptionPrice: false
25
- };
26
-
27
- /**
28
- * Wallet Pass 评估器
29
- * 用于评估哪些 voucher 可以在当前订单中使用
30
- */
31
- export var WalletPassEvaluator = /*#__PURE__*/function () {
32
- function WalletPassEvaluator() {
33
- _classCallCheck(this, WalletPassEvaluator);
34
- _defineProperty(this, "engine", void 0);
35
- _defineProperty(this, "strategyConfigs", []);
36
- _defineProperty(this, "locale", 'en');
37
- this.engine = new StrategyEngine({
38
- debug: false,
39
- enableTrace: false
40
- });
41
- }
42
- _createClass(WalletPassEvaluator, [{
43
- key: "setStrategyConfigs",
44
- value: function setStrategyConfigs(strategyConfigs) {
45
- this.strategyConfigs = strategyConfigs;
46
- }
47
- }, {
48
- key: "getStrategyConfigs",
49
- value: function getStrategyConfigs() {
50
- return this.strategyConfigs;
51
- }
52
- }, {
53
- key: "setLocale",
54
- value: function setLocale(locale) {
55
- this.locale = locale;
56
- }
57
- }, {
58
- key: "getText",
59
- value: function getText(key) {
60
- var _locales$this$locale;
61
- return locales === null || locales === void 0 || (_locales$this$locale = locales[this.locale]) === null || _locales$this$locale === void 0 ? void 0 : _locales$this$locale[key];
62
- }
63
-
64
- /**
65
- * 搜索券的格式
66
- * @param input 输入
67
- * @returns 返回搜索券的格式
68
- */
69
- }, {
70
- key: "searchVoucherFormat",
71
- value: function searchVoucherFormat(input) {
72
- var results = this.evaluate(input);
73
- return results.map(function (item) {
74
- if (item.isApplicable) {
75
- var _item$strategyResult;
76
- return _objectSpread(_objectSpread({}, item.voucher), {}, {
77
- config: _objectSpread({}, item === null || item === void 0 || (_item$strategyResult = item.strategyResult) === null || _item$strategyResult === void 0 ? void 0 : _item$strategyResult.config.metadata.custom)
78
- });
79
- } else {
80
- var _item$strategyResult2;
81
- return _objectSpread(_objectSpread({}, item.voucher), {}, {
82
- config: _objectSpread({}, item === null || item === void 0 || (_item$strategyResult2 = item.strategyResult) === null || _item$strategyResult2 === void 0 ? void 0 : _item$strategyResult2.config.metadata.custom),
83
- _unified_available_status: 0,
84
- reason: item.reason,
85
- reasonCode: item.reasonCode
86
- });
87
- }
88
- });
89
- }
90
-
91
- /**
92
- * 评估可用的 vouchers
93
- */
94
- }, {
95
- key: "evaluate",
96
- value: function evaluate(input) {
97
- var orderTotalAmount = input.orderTotalAmount,
98
- products = input.products,
99
- vouchers = input.vouchers,
100
- strategyConfigs = input.strategyConfigs;
101
-
102
- // 提取订单中的商品ID
103
- var productIds = products.map(function (p) {
104
- return p.product_id;
105
- });
106
- var results = [];
107
-
108
- // 遍历每个 voucher 进行评估
109
- var _iterator = _createForOfIteratorHelper(vouchers),
110
- _step;
111
- try {
112
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
113
- var _strategy$metadata$cu, _strategy$metadata, _businessConfig$deduc;
114
- var voucher = _step.value;
115
- // 查找适用此 voucher 的策略配置
116
- var applicableStrategies = this.findApplicableStrategies(voucher, strategyConfigs || this.strategyConfigs);
117
- if (applicableStrategies.length === 0) {
118
- // 没有匹配的策略 默认可用
119
- results.push({
120
- voucher: voucher,
121
- isApplicable: true,
122
- canUseCount: 0,
123
- maxDeduction: 0,
124
- deductTaxAndFee: true,
125
- applicableProductIds: [],
126
- reason: '',
127
- reasonCode: '',
128
- strategyResult: {
129
- config: {
130
- metadata: {
131
- custom: _objectSpread({}, defaultStrategyMetadataCustom)
132
- }
133
- }
134
- }
135
- });
136
- continue;
137
- }
138
-
139
- // 对每个策略进行评估(取第一个匹配的策略)
140
- var strategy = applicableStrategies[0];
141
-
142
- // 从 voucher 中获取适用商品ID
143
- var applicableProductIds = getApplicableProductIds(voucher);
144
-
145
- // 计算适用商品的总金额和数量
146
- var _this$calculateApplic = this.calculateApplicableProducts(products, applicableProductIds, (_strategy$metadata$cu = strategy === null || strategy === void 0 || (_strategy$metadata = strategy.metadata) === null || _strategy$metadata === void 0 || (_strategy$metadata = _strategy$metadata.custom) === null || _strategy$metadata === void 0 ? void 0 : _strategy$metadata.deductTaxAndFee) !== null && _strategy$metadata$cu !== void 0 ? _strategy$metadata$cu : true),
147
- applicableTotal = _this$calculateApplic.applicableTotal,
148
- applicableCount = _this$calculateApplic.applicableCount;
149
-
150
- // 准备运行时上下文
151
- var context = {
152
- entities: {
153
- voucher: voucher,
154
- products: products,
155
- order: {
156
- orderTotalAmount: orderTotalAmount,
157
- products: products
158
- }
159
- },
160
- attributes: {
161
- orderTotalAmount: orderTotalAmount,
162
- applicableProductTotalAmount: applicableTotal,
163
- applicableProductCount: applicableCount,
164
- voucherProductId: voucher.product_id,
165
- productIds: productIds
166
- },
167
- metadata: {
168
- timestamp: Date.now()
169
- }
170
- };
171
-
172
- // 执行策略评估
173
- var evaluationResult = this.engine.evaluate(strategy, context);
174
-
175
- // 从策略配置中获取业务配置
176
- var businessConfig = strategy.metadata.custom || {};
177
- var maxDeduction = businessConfig.maxDeductionAmount || 0;
178
- var canUseCount = businessConfig.maxUsagePerOrder || 0;
179
- var deductTaxAndFee = (_businessConfig$deduc = businessConfig.deductTaxAndFee) !== null && _businessConfig$deduc !== void 0 ? _businessConfig$deduc : true;
180
- if (evaluationResult.applicable) {
181
- results.push({
182
- voucher: voucher,
183
- isApplicable: true,
184
- canUseCount: canUseCount,
185
- maxDeduction: maxDeduction,
186
- deductTaxAndFee: deductTaxAndFee,
187
- applicableProductIds: applicableProductIds || [],
188
- strategyResult: evaluationResult
189
- });
190
- } else {
191
- // 根据策略评估结果的 code 映射到 locales 中的原因
192
- var reasonCode = 'not_meet_the_required_conditions'; // 默认原因
193
-
194
- // 根据策略引擎返回的 code 映射到本地化的 reasonCode
195
- if (evaluationResult.code) {
196
- // 可以根据具体的 code 映射到不同的原因
197
- // 例如:如果是金额不足、使用次数限制等
198
- var codeMapping = {
199
- INSUFFICIENT_AMOUNT: 'not_meet_the_required_conditions',
200
- USAGE_LIMIT_EXCEEDED: 'usage_limit_reached',
201
- CHANNEL_NOT_ALLOWED: 'not_available_for_this_channel',
202
- ORDER_TYPE_NOT_ALLOWED: 'not_valid_for_this_order_type',
203
- DEDUCTION_LIMIT_EXCEEDED: 'exceeds_the_maximum_deduction_limit'
204
- };
205
- reasonCode = codeMapping[evaluationResult.code] || 'not_meet_the_required_conditions';
206
- }
207
- results.push({
208
- voucher: voucher,
209
- isApplicable: false,
210
- canUseCount: 0,
211
- maxDeduction: 0,
212
- deductTaxAndFee: false,
213
- applicableProductIds: [],
214
- reason: this.getText(reasonCode),
215
- reasonCode: reasonCode,
216
- strategyResult: evaluationResult
217
- });
218
- }
219
- }
220
- } catch (err) {
221
- _iterator.e(err);
222
- } finally {
223
- _iterator.f();
224
- }
225
- return results;
226
- }
227
-
228
- /** 检查代金券/折扣卡是否可用 并返回config */
229
- }, {
230
- key: "checkVoucherAvailability",
231
- value: function checkVoucherAvailability(input) {
232
- var _results$, _results$2;
233
- var orderTotalAmount = input.orderTotalAmount,
234
- products = input.products,
235
- vouchers = input.vouchers;
236
- var results = this.evaluate(input);
237
- var isAvailable = ((_results$ = results[0]) === null || _results$ === void 0 ? void 0 : _results$.isApplicable) || false;
238
- return {
239
- isAvailable: isAvailable,
240
- config: _objectSpread({}, (_results$2 = results[0]) === null || _results$2 === void 0 || (_results$2 = _results$2.strategyResult) === null || _results$2 === void 0 || (_results$2 = _results$2.config) === null || _results$2 === void 0 || (_results$2 = _results$2.metadata) === null || _results$2 === void 0 ? void 0 : _results$2.custom)
241
- };
242
- }
243
-
244
- /**
245
- * 获取推荐券
246
- * @param input 输入
247
- * @returns 返回推荐券列表
248
- */
249
- }, {
250
- key: "getRecommendedVouchers",
251
- value: function getRecommendedVouchers(input) {
252
- var orderTotalAmount = input.orderTotalAmount,
253
- products = input.products,
254
- vouchers = input.vouchers;
255
- // 基于后端返回的状态不可用券
256
- var noApplicableVoucher = [];
257
- // 基于后端返回的状态可用券
258
- var applicableVoucher = [];
259
- vouchers.forEach(function (voucher) {
260
- if (voucher.unified_available_status === 1) {
261
- applicableVoucher.push(voucher);
262
- } else {
263
- noApplicableVoucher.push(voucher);
264
- }
265
- });
266
- var results = this.evaluate(_objectSpread(_objectSpread({}, input), {}, {
267
- vouchers: applicableVoucher
268
- }));
269
- var newVouchers = [];
270
- results.forEach(function (item) {
271
- if (item.isApplicable) {
272
- var _item$strategyResult3;
273
- newVouchers.push(_objectSpread(_objectSpread({}, item.voucher), {}, {
274
- config: _objectSpread(_objectSpread({}, defaultStrategyMetadataCustom), (item === null || item === void 0 || (_item$strategyResult3 = item.strategyResult) === null || _item$strategyResult3 === void 0 || (_item$strategyResult3 = _item$strategyResult3.config) === null || _item$strategyResult3 === void 0 || (_item$strategyResult3 = _item$strategyResult3.metadata) === null || _item$strategyResult3 === void 0 ? void 0 : _item$strategyResult3.custom) || {})
275
- }));
276
- } else {
277
- // 不可用的券,添加原因信息
278
- noApplicableVoucher.push(_objectSpread(_objectSpread({}, item.voucher), {}, {
279
- _unified_available_status: 0,
280
- reason: item.reason,
281
- reasonCode: item.reasonCode
282
- }));
283
- }
284
- });
285
- var _this$processVouchers = this.processVouchers(newVouchers, orderTotalAmount, products),
286
- recommended = _this$processVouchers.recommended,
287
- transformList = _this$processVouchers.transformList;
288
- var recommendedAmount = recommended.reduce(function (sum, item) {
289
- return new Decimal(sum).add(item._available_max_amount || 0).toNumber();
290
- }, 0);
291
- return {
292
- // 推荐券总金额
293
- recommendedAmount: recommendedAmount,
294
- // 推荐券列表
295
- recommended: recommended,
296
- // 格式化后的可用券列表
297
- transformList: transformList,
298
- // 后端不可用券列表 和前端基于策略返回的 不可用列表 合并
299
- noApplicableVoucher: noApplicableVoucher
300
- };
301
- }
302
- }, {
303
- key: "enhanceWithReason",
304
- value: function enhanceWithReason(voucher) {
305
- if (voucher._unified_available_status === 0 && voucher.reasonCode) {
306
- return _objectSpread(_objectSpread({}, voucher), {}, {
307
- reason: this.getText(voucher.reasonCode)
308
- });
309
- }
310
- return voucher;
311
- }
312
-
313
- /**
314
- * 优惠券处理函数
315
- * @param applicableVouchers 可用的券列表
316
- * @param orderTotalAmount 订单总金额
317
- * @param products 订单商品列表
318
- * @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
319
- */
320
- }, {
321
- key: "processVouchers",
322
- value: function processVouchers(vouchers, orderTotalAmount, products) {
323
- var _this = this;
324
- var result = _processVouchers(vouchers, orderTotalAmount, products);
325
- return {
326
- recommended: result.recommended.map(function (item) {
327
- return _this.enhanceWithReason(item);
328
- }),
329
- transformList: result.transformList.map(function (item) {
330
- return _this.enhanceWithReason(item);
331
- })
332
- };
333
- }
334
-
335
- /**
336
- * 重新计算优惠券状态(基于已选券的增量计算)
337
- * @param allVouchers 所有原始券列表
338
- * @param selectedVouchers 已选中的券列表(按选中顺序)
339
- * @param orderTotalAmount 订单总金额
340
- * @param products 订单商品列表
341
- * @returns 返回更新后的所有券列表和已选券的详细抵扣信息
342
- */
343
- }, {
344
- key: "recalculateVouchers",
345
- value: function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, products) {
346
- var _this2 = this;
347
- var result = _recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, products);
348
- return {
349
- allWithUpdatedStatus: result.allWithUpdatedStatus.map(function (item) {
350
- return _this2.enhanceWithReason(item);
351
- }),
352
- selectedWithDetails: result.selectedWithDetails.map(function (item) {
353
- return _this2.enhanceWithReason(item);
354
- })
355
- };
356
- }
357
-
358
- /**
359
- * 查找适用于指定 voucher 的策略配置
360
- */
361
- }, {
362
- key: "findApplicableStrategies",
363
- value: function findApplicableStrategies(voucher, strategyConfigs) {
364
- var _this3 = this;
365
- return strategyConfigs.filter(function (config) {
366
- // 检查策略的 conditions 中是否包含匹配此 voucher 的规则
367
- return _this3.checkVoucherInStrategy(voucher.product_id, config);
368
- });
369
- }
370
-
371
- /**
372
- * 检查策略中是否包含指定的 voucher ID
373
- */
374
- }, {
375
- key: "checkVoucherInStrategy",
376
- value: function checkVoucherInStrategy(voucherProductId, config) {
377
- var rules = config.conditions.rules;
378
- var _iterator2 = _createForOfIteratorHelper(rules),
379
- _step2;
380
- try {
381
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
382
- var rule = _step2.value;
383
- // 如果是条件组,递归检查
384
- if ('operator' in rule && 'rules' in rule) {
385
- if (this.checkVoucherInConditionGroup(voucherProductId, rule)) {
386
- return true;
387
- }
388
- } else {
389
- // 检查是否是 voucherProductId 字段的规则
390
- var conditionRule = rule;
391
- if (conditionRule.field === 'voucherProductId' && conditionRule.operator === 'in' && Array.isArray(conditionRule.value)) {
392
- if (conditionRule.value.includes(voucherProductId)) {
393
- return true;
394
- }
395
- }
396
- // 支持等于判断
397
- if (conditionRule.field === 'voucherProductId' && (conditionRule.operator === '=' || conditionRule.operator === '==')) {
398
- if (conditionRule.value === voucherProductId) {
399
- return true;
400
- }
401
- }
402
- }
403
- }
404
- } catch (err) {
405
- _iterator2.e(err);
406
- } finally {
407
- _iterator2.f();
408
- }
409
- return false;
410
- }
411
-
412
- /**
413
- * 递归检查条件组中是否包含 voucher ID
414
- */
415
- }, {
416
- key: "checkVoucherInConditionGroup",
417
- value: function checkVoucherInConditionGroup(voucherProductId, group) {
418
- var _iterator3 = _createForOfIteratorHelper(group.rules),
419
- _step3;
420
- try {
421
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
422
- var rule = _step3.value;
423
- if ('operator' in rule && 'rules' in rule) {
424
- if (this.checkVoucherInConditionGroup(voucherProductId, rule)) {
425
- return true;
426
- }
427
- } else {
428
- if (rule.field === 'voucherProductId' && rule.operator === 'in' && Array.isArray(rule.value)) {
429
- if (rule.value.includes(voucherProductId)) {
430
- return true;
431
- }
432
- }
433
- if (rule.field === 'voucherProductId' && (rule.operator === '=' || rule.operator === '==')) {
434
- if (rule.value === voucherProductId) {
435
- return true;
436
- }
437
- }
438
- }
439
- }
440
- } catch (err) {
441
- _iterator3.e(err);
442
- } finally {
443
- _iterator3.f();
444
- }
445
- return false;
446
- }
447
-
448
- /**
449
- * 计算适用商品的总金额和数量
450
- */
451
- }, {
452
- key: "calculateApplicableProducts",
453
- value: function calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee) {
454
- var total = 0;
455
- var count = 0;
456
-
457
- // 如果为空数组,不适用任何商品
458
- if (applicableProductIds !== null && applicableProductIds.length === 0) {
459
- return {
460
- applicableTotal: 0,
461
- applicableCount: 0
462
- };
463
- }
464
- products.forEach(function (product) {
465
- var productQuantity = getProductQuantity(product);
466
-
467
- // 检查主商品是否适用
468
- var isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
469
- if (isMainProductApplicable) {
470
- // 计算主商品价格(包含加减价子商品)
471
- total += getMainProductPrice(product, deductTaxAndFee) * productQuantity;
472
- count += productQuantity;
473
- }
474
-
475
- // 检查原价子商品(需要单独判断适用性)
476
- if (product.product_bundle && product.product_bundle.length > 0) {
477
- product.product_bundle.forEach(function (bundleItem) {
478
- // 只处理原价子商品,加减价子商品已包含在主商品价格中
479
- if (getBundleItemIsOriginalPrice(bundleItem)) {
480
- // 检查子商品是否适用
481
- var isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
482
- if (isBundleItemApplicable) {
483
- // 计算原价子商品价格
484
- var bundleItemQuantity = bundleItem.num * productQuantity;
485
- total += getBundleItemPrice(bundleItem, productQuantity, deductTaxAndFee);
486
- count += bundleItemQuantity;
487
- }
488
- }
489
- });
490
- }
491
- });
492
- return {
493
- applicableTotal: total,
494
- applicableCount: count
495
- };
496
- }
497
- }]);
498
- return WalletPassEvaluator;
499
- }();
@@ -1,4 +0,0 @@
1
- /**
2
- * WalletPass 评估器使用示例
3
- */
4
- export {};