@pisell/pisellos 0.0.484 → 0.0.485
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
|
|
@@ -15,6 +15,20 @@ import { isNormalProduct } from "../../Product/utils";
|
|
|
15
15
|
import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
|
|
16
16
|
import { calcDiscountListDifference } from "../../Summary/utils";
|
|
17
17
|
|
|
18
|
+
/** 与 Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
|
|
19
|
+
var toDiscountPayload = function toDiscountPayload(discountItem) {
|
|
20
|
+
var _discountItem$discoun, _discountItem$discoun2;
|
|
21
|
+
return {
|
|
22
|
+
amount: discountItem.amount,
|
|
23
|
+
tag: discountItem.type,
|
|
24
|
+
par_value: (_discountItem$discoun = discountItem.discount) === null || _discountItem$discoun === void 0 ? void 0 : _discountItem$discoun.percent,
|
|
25
|
+
config: discountItem.config,
|
|
26
|
+
metadata: {
|
|
27
|
+
discount_card_type: discountItem === null || discountItem === void 0 || (_discountItem$discoun2 = discountItem.discount) === null || _discountItem$discoun2 === void 0 ? void 0 : _discountItem$discoun2.discount_card_type
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
33
|
* @title 处理组合商品
|
|
20
34
|
* @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
|
|
@@ -195,6 +209,7 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
|
|
|
195
209
|
* @returns 商品总价
|
|
196
210
|
*/
|
|
197
211
|
export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
212
|
+
var _options$map;
|
|
198
213
|
var product = params.product,
|
|
199
214
|
bundle = params.bundle,
|
|
200
215
|
options = params.options,
|
|
@@ -202,23 +217,29 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
202
217
|
// const num = params.num || 1;
|
|
203
218
|
var price = Number(product.price);
|
|
204
219
|
|
|
220
|
+
// option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
|
|
221
|
+
var optionRows = (_options$map = options === null || options === void 0 ? void 0 : options.map(function (currentValue) {
|
|
222
|
+
var _ref, _currentValue$price, _ref2, _currentValue$num;
|
|
223
|
+
return {
|
|
224
|
+
unit: Number((_ref = (_currentValue$price = currentValue.price) !== null && _currentValue$price !== void 0 ? _currentValue$price : currentValue.add_price) !== null && _ref !== void 0 ? _ref : 0),
|
|
225
|
+
num: Number((_ref2 = (_currentValue$num = currentValue.num) !== null && _currentValue$num !== void 0 ? _currentValue$num : currentValue.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1)
|
|
226
|
+
};
|
|
227
|
+
})) !== null && _options$map !== void 0 ? _options$map : [];
|
|
228
|
+
|
|
205
229
|
// 如果商品有折扣,则计算折扣
|
|
206
230
|
if (discounts !== null && discounts !== void 0 && discounts.length) {
|
|
207
231
|
discounts.forEach(function (currentValue) {
|
|
208
|
-
var _currentValue$
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
metadata: {
|
|
218
|
-
discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
|
|
232
|
+
var _currentValue$config;
|
|
233
|
+
var payload = toDiscountPayload(currentValue);
|
|
234
|
+
price = getDiscountAmount(payload, price, price);
|
|
235
|
+
if (currentValue !== null && currentValue !== void 0 && (_currentValue$config = currentValue.config) !== null && _currentValue$config !== void 0 && _currentValue$config.deductOptionPrice && optionRows.length) {
|
|
236
|
+
for (var i = 0; i < optionRows.length; i++) {
|
|
237
|
+
var row = optionRows[i];
|
|
238
|
+
optionRows[i] = _objectSpread(_objectSpread({}, row), {}, {
|
|
239
|
+
unit: getDiscountAmount(payload, row.unit, row.unit)
|
|
240
|
+
});
|
|
219
241
|
}
|
|
220
|
-
}
|
|
221
|
-
// }
|
|
242
|
+
}
|
|
222
243
|
});
|
|
223
244
|
}
|
|
224
245
|
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
@@ -227,10 +248,10 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
227
248
|
}, price);
|
|
228
249
|
}
|
|
229
250
|
|
|
230
|
-
// 单规格
|
|
231
|
-
if (
|
|
232
|
-
price =
|
|
233
|
-
return accumulator +
|
|
251
|
+
// 单规格 / 加购 option
|
|
252
|
+
if (optionRows.length) {
|
|
253
|
+
price = optionRows.reduce(function (accumulator, row) {
|
|
254
|
+
return accumulator + row.unit * row.num;
|
|
234
255
|
}, price);
|
|
235
256
|
}
|
|
236
257
|
return Math.max(0, price);
|
|
@@ -389,11 +410,11 @@ export var getProductDeposit = function getProductDeposit(params) {
|
|
|
389
410
|
// 判定商品是否有定金规则
|
|
390
411
|
if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
|
|
391
412
|
var total = new Decimal(0);
|
|
392
|
-
var
|
|
393
|
-
deposit_fixed =
|
|
394
|
-
deposit_percentage =
|
|
395
|
-
deposit_policy_data =
|
|
396
|
-
self_deposit_policy_ids =
|
|
413
|
+
var _ref3 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
|
|
414
|
+
deposit_fixed = _ref3.deposit_fixed,
|
|
415
|
+
deposit_percentage = _ref3.deposit_percentage,
|
|
416
|
+
deposit_policy_data = _ref3.deposit_policy_data,
|
|
417
|
+
self_deposit_policy_ids = _ref3.self_deposit_policy_ids;
|
|
397
418
|
// 所有协议数据
|
|
398
419
|
var allProtocols = deposit_policy_data || [];
|
|
399
420
|
// 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
|
|
@@ -487,9 +508,9 @@ export var handleProductDeposit = function handleProductDeposit(params) {
|
|
|
487
508
|
depositTotal: new Decimal(0)
|
|
488
509
|
};
|
|
489
510
|
}
|
|
490
|
-
var
|
|
491
|
-
deposit_fixed =
|
|
492
|
-
deposit_percentage =
|
|
511
|
+
var _ref4 = depositData || {},
|
|
512
|
+
deposit_fixed = _ref4.deposit_fixed,
|
|
513
|
+
deposit_percentage = _ref4.deposit_percentage;
|
|
493
514
|
if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
|
|
494
515
|
var depositFixed = Decimal(deposit_fixed || 0);
|
|
495
516
|
var depositPercent = Decimal(deposit_percentage || 0);
|
|
@@ -46,6 +46,18 @@ var import_decimal = __toESM(require("decimal.js"));
|
|
|
46
46
|
var import_utils = require("../../Product/utils");
|
|
47
47
|
var import_utils2 = require("../../../solution/ShopDiscount/utils");
|
|
48
48
|
var import_utils3 = require("../../Summary/utils");
|
|
49
|
+
var toDiscountPayload = (discountItem) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
return {
|
|
52
|
+
amount: discountItem.amount,
|
|
53
|
+
tag: discountItem.type,
|
|
54
|
+
par_value: (_a = discountItem.discount) == null ? void 0 : _a.percent,
|
|
55
|
+
config: discountItem.config,
|
|
56
|
+
metadata: {
|
|
57
|
+
discount_card_type: (_b = discountItem == null ? void 0 : discountItem.discount) == null ? void 0 : _b.discount_card_type
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
49
61
|
var handleVariantProduct = (product) => {
|
|
50
62
|
var _a;
|
|
51
63
|
if (product == null ? void 0 : product.product_variant_id) {
|
|
@@ -192,18 +204,24 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
192
204
|
var getProductTotalPrice = (params) => {
|
|
193
205
|
const { product, bundle, options, discounts } = params;
|
|
194
206
|
let price = Number(product.price);
|
|
207
|
+
const optionRows = (options == null ? void 0 : options.map((currentValue) => ({
|
|
208
|
+
unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
|
|
209
|
+
num: Number(currentValue.num ?? currentValue.quantity ?? 1)
|
|
210
|
+
}))) ?? [];
|
|
195
211
|
if (discounts == null ? void 0 : discounts.length) {
|
|
196
212
|
discounts.forEach((currentValue) => {
|
|
197
213
|
var _a;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
const payload = toDiscountPayload(currentValue);
|
|
215
|
+
price = (0, import_utils2.getDiscountAmount)(payload, price, price);
|
|
216
|
+
if (((_a = currentValue == null ? void 0 : currentValue.config) == null ? void 0 : _a.deductOptionPrice) && optionRows.length) {
|
|
217
|
+
for (let i = 0; i < optionRows.length; i++) {
|
|
218
|
+
const row = optionRows[i];
|
|
219
|
+
optionRows[i] = {
|
|
220
|
+
...row,
|
|
221
|
+
unit: (0, import_utils2.getDiscountAmount)(payload, row.unit, row.unit)
|
|
222
|
+
};
|
|
205
223
|
}
|
|
206
|
-
}
|
|
224
|
+
}
|
|
207
225
|
});
|
|
208
226
|
}
|
|
209
227
|
if (bundle == null ? void 0 : bundle.length) {
|
|
@@ -211,10 +229,11 @@ var getProductTotalPrice = (params) => {
|
|
|
211
229
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
212
230
|
}, price);
|
|
213
231
|
}
|
|
214
|
-
if (
|
|
215
|
-
price =
|
|
216
|
-
|
|
217
|
-
|
|
232
|
+
if (optionRows.length) {
|
|
233
|
+
price = optionRows.reduce(
|
|
234
|
+
(accumulator, row) => accumulator + row.unit * row.num,
|
|
235
|
+
price
|
|
236
|
+
);
|
|
218
237
|
}
|
|
219
238
|
return Math.max(0, price);
|
|
220
239
|
};
|