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