@pisell/pisellos 2.1.107 → 2.1.109
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/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/dist/model/strategy/adapter/walletPass/type.d.ts +20 -2
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +10 -10
- package/dist/model/strategy/adapter/walletPass/utils.js +105 -78
- package/dist/modules/Cart/utils/cartProduct.js +46 -25
- package/dist/modules/Discount/types.d.ts +2 -0
- package/dist/modules/Rules/index.js +171 -74
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/lib/model/strategy/adapter/walletPass/type.d.ts +20 -2
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +10 -10
- package/lib/model/strategy/adapter/walletPass/utils.js +110 -46
- package/lib/modules/Cart/utils/cartProduct.js +31 -12
- package/lib/modules/Discount/types.d.ts +2 -0
- package/lib/modules/Rules/index.js +228 -141
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Product, Voucher } from './type';
|
|
2
|
+
/** 订单商品数量 */
|
|
3
|
+
export declare const getProductQuantity: (product: any) => any;
|
|
4
|
+
/**
|
|
5
|
+
* 订单商品行唯一键,用于 maxPassesPerItem 按行、按件配额(同 SPU 不同规格视为不同行)。
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveWalletPassLineKey(product: any, indexInOrder: number): string;
|
|
2
8
|
export declare const getApplicableProductIds: (voucher: Voucher) => number[] | null;
|
|
3
9
|
/**
|
|
4
10
|
* 优惠券处理函数
|
|
@@ -24,26 +30,20 @@ export declare function recalculateVouchers(allVouchers: any[], selectedVouchers
|
|
|
24
30
|
selectedWithDetails: any[];
|
|
25
31
|
};
|
|
26
32
|
/**
|
|
27
|
-
*
|
|
33
|
+
* 获取主商品价格(单价,不含舍入余数)
|
|
28
34
|
* @param product 商品
|
|
29
35
|
* @param isDeductTaxAndFee 是否抵扣税费与附加费
|
|
30
|
-
* @returns
|
|
36
|
+
* @returns 商品单价
|
|
31
37
|
*/
|
|
32
38
|
export declare const getMainProductPrice: (product: Product, isDeductTaxAndFee: boolean) => number;
|
|
33
39
|
/**
|
|
34
|
-
*
|
|
40
|
+
* 获取套餐子商品价格(不含舍入余数)
|
|
35
41
|
* @param bundleItem 套餐子商品
|
|
36
42
|
* @param parentQuantity 父商品数量
|
|
37
43
|
* @param isDeductTaxAndFee 是否抵扣税费与附加费
|
|
38
|
-
* @returns
|
|
44
|
+
* @returns 子商品总价格(不含舍入余数)
|
|
39
45
|
*/
|
|
40
46
|
export declare const getBundleItemPrice: (bundleItem: any, parentQuantity: number, isDeductTaxAndFee: boolean) => number;
|
|
41
|
-
/**
|
|
42
|
-
* 获取商品数量
|
|
43
|
-
* @param product 商品
|
|
44
|
-
* @returns 商品数量
|
|
45
|
-
*/
|
|
46
|
-
export declare const getProductQuantity: (product: any) => any;
|
|
47
47
|
export declare const getBundleItemIsOriginalPrice: (item: any) => boolean;
|
|
48
48
|
export declare const getBundleItemIsMarkupPrice: (item: any) => boolean;
|
|
49
49
|
export declare const getBundleItemIsDiscountPrice: (item: any) => boolean;
|
|
@@ -38,10 +38,72 @@ __export(utils_exports, {
|
|
|
38
38
|
getMainProductPrice: () => getMainProductPrice,
|
|
39
39
|
getProductQuantity: () => getProductQuantity,
|
|
40
40
|
processVouchers: () => processVouchers,
|
|
41
|
-
recalculateVouchers: () => recalculateVouchers
|
|
41
|
+
recalculateVouchers: () => recalculateVouchers,
|
|
42
|
+
resolveWalletPassLineKey: () => resolveWalletPassLineKey
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(utils_exports);
|
|
44
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
46
|
+
var getProductQuantity = (product) => {
|
|
47
|
+
return product.quantity || product.product_quantity || 1;
|
|
48
|
+
};
|
|
49
|
+
function resolveWalletPassLineKey(product, indexInOrder) {
|
|
50
|
+
const m = (product == null ? void 0 : product.metadata) || {};
|
|
51
|
+
const u1 = m.product_unique;
|
|
52
|
+
if (u1 != null && String(u1).length > 0)
|
|
53
|
+
return String(u1);
|
|
54
|
+
const u2 = m.unique_identification_number;
|
|
55
|
+
if (u2 != null && String(u2).length > 0)
|
|
56
|
+
return String(u2);
|
|
57
|
+
if ((product == null ? void 0 : product.id) != null && String(product.id).length > 0)
|
|
58
|
+
return `order_item:${product.id}`;
|
|
59
|
+
if ((product == null ? void 0 : product.product_unique_string) != null && String(product.product_unique_string).length > 0) {
|
|
60
|
+
return String(product.product_unique_string);
|
|
61
|
+
}
|
|
62
|
+
return `order_line_${indexInOrder}`;
|
|
63
|
+
}
|
|
64
|
+
function getExpandedOrderLineQuantity(p) {
|
|
65
|
+
if ((p == null ? void 0 : p._orderLineQuantity) != null && p._orderLineQuantity > 0)
|
|
66
|
+
return p._orderLineQuantity;
|
|
67
|
+
return getProductQuantity(p);
|
|
68
|
+
}
|
|
69
|
+
function getMaxPassSlotsForExpandedLine(maxPassesPerItem, p) {
|
|
70
|
+
if (maxPassesPerItem <= 0)
|
|
71
|
+
return Infinity;
|
|
72
|
+
return maxPassesPerItem * getExpandedOrderLineQuantity(p);
|
|
73
|
+
}
|
|
74
|
+
function computePassSlotsIncrement(deductAmount, deductQty, maxPassesPerItem, orderLineQuantity, currentUsage) {
|
|
75
|
+
if (maxPassesPerItem <= 0 || !deductAmount.greaterThan(0))
|
|
76
|
+
return 0;
|
|
77
|
+
const cap = maxPassesPerItem * orderLineQuantity;
|
|
78
|
+
const room = Math.max(0, cap - currentUsage);
|
|
79
|
+
if (room <= 0)
|
|
80
|
+
return 0;
|
|
81
|
+
const raw = Math.max(1, Math.ceil(Number(deductQty)) || 1);
|
|
82
|
+
return Math.min(raw, room);
|
|
83
|
+
}
|
|
84
|
+
function applyMaxPassUsageIncrements(usageMap, walletPassProductId, maxPassesPerItem, deductionDetails) {
|
|
85
|
+
deductionDetails.forEach((detail) => {
|
|
86
|
+
var _a;
|
|
87
|
+
const lineKey = detail.lineKey;
|
|
88
|
+
if (!lineKey || maxPassesPerItem <= 0)
|
|
89
|
+
return;
|
|
90
|
+
const orderLineQty = detail.orderLineQuantity != null && detail.orderLineQuantity > 0 ? detail.orderLineQuantity : 1;
|
|
91
|
+
const cur = ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
|
|
92
|
+
const inc = computePassSlotsIncrement(
|
|
93
|
+
new import_decimal.default(detail.deductAmount),
|
|
94
|
+
detail.deductQuantity,
|
|
95
|
+
maxPassesPerItem,
|
|
96
|
+
orderLineQty,
|
|
97
|
+
cur
|
|
98
|
+
);
|
|
99
|
+
if (inc <= 0)
|
|
100
|
+
return;
|
|
101
|
+
if (!usageMap.has(walletPassProductId))
|
|
102
|
+
usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
103
|
+
const inner = usageMap.get(walletPassProductId);
|
|
104
|
+
inner.set(lineKey, cur + inc);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
45
107
|
var getRecommendedAmount = (voucher) => {
|
|
46
108
|
console.log("voucher312", voucher);
|
|
47
109
|
const { config, recommended_usage_amount, recommended_pure_product_usage_amount } = voucher;
|
|
@@ -82,30 +144,23 @@ var getApplicableProducts = (voucher, productsData) => {
|
|
|
82
144
|
}
|
|
83
145
|
return productsData.filter((p) => applicableProductIds.includes(p.product_id));
|
|
84
146
|
};
|
|
85
|
-
var getTotalQuantityByProductId = (allProducts, productId) => {
|
|
86
|
-
return allProducts.filter((p) => p.product_id === productId).reduce((sum, p) => sum + getProductQuantity(p), 0);
|
|
87
|
-
};
|
|
88
147
|
function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
89
148
|
console.log(products, "products123");
|
|
90
149
|
const productsCopy = expandProductsWithBundleItems(products, true);
|
|
91
150
|
let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
|
|
92
|
-
const getItemPassUsage = (usageMap, walletPassProductId,
|
|
151
|
+
const getItemPassUsage = (usageMap, walletPassProductId, lineKey) => {
|
|
93
152
|
var _a;
|
|
94
|
-
return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(
|
|
153
|
+
return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
|
|
95
154
|
};
|
|
96
|
-
const
|
|
97
|
-
if (!usageMap.has(walletPassProductId)) {
|
|
98
|
-
usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
99
|
-
}
|
|
100
|
-
const innerMap = usageMap.get(walletPassProductId);
|
|
101
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
102
|
-
};
|
|
103
|
-
const filterByMaxPassesPerItem = (products2, allProducts, usageMap, walletPassProductId, maxPassesPerItem) => {
|
|
155
|
+
const filterByMaxPassesPerItem = (products2, usageMap, walletPassProductId, maxPassesPerItem) => {
|
|
104
156
|
if (maxPassesPerItem <= 0)
|
|
105
157
|
return products2;
|
|
106
|
-
return products2.filter(
|
|
107
|
-
|
|
108
|
-
|
|
158
|
+
return products2.filter((p) => {
|
|
159
|
+
const lineKey = p._walletPassLineKey;
|
|
160
|
+
if (!lineKey)
|
|
161
|
+
return true;
|
|
162
|
+
return getItemPassUsage(usageMap, walletPassProductId, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
|
|
163
|
+
});
|
|
109
164
|
};
|
|
110
165
|
const calculateAvailableMaxAmount = (voucher, productsData, itemPassUsage) => {
|
|
111
166
|
const { config } = voucher;
|
|
@@ -119,7 +174,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
119
174
|
const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
|
|
120
175
|
let applicableProducts = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0));
|
|
121
176
|
if (itemPassUsage) {
|
|
122
|
-
applicableProducts = filterByMaxPassesPerItem(applicableProducts,
|
|
177
|
+
applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsage, voucher.product_id, maxPassesPerItem);
|
|
123
178
|
}
|
|
124
179
|
if (applicableProducts.length === 0) {
|
|
125
180
|
return new import_decimal.default(0);
|
|
@@ -185,7 +240,12 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
185
240
|
if (maxPassesPerItem > 0 && itemPassUsage) {
|
|
186
241
|
const deductTaxAndFee = (config == null ? void 0 : config.deductTaxAndFee) ?? true;
|
|
187
242
|
const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
|
|
188
|
-
const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) =>
|
|
243
|
+
const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => {
|
|
244
|
+
const lineKey = p._walletPassLineKey;
|
|
245
|
+
if (!lineKey)
|
|
246
|
+
return true;
|
|
247
|
+
return getItemPassUsage(itemPassUsage, product_id, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
|
|
248
|
+
});
|
|
189
249
|
if (availableAfterPassLimit.length === 0) {
|
|
190
250
|
return { isAvailable: false, reasonCode: "max_passes_per_item_reached" };
|
|
191
251
|
}
|
|
@@ -235,7 +295,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
235
295
|
voucher,
|
|
236
296
|
productsForRecommendation
|
|
237
297
|
).filter((p) => p[amountField].greaterThan(0));
|
|
238
|
-
applicableProducts = filterByMaxPassesPerItem(applicableProducts,
|
|
298
|
+
applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsageMap, product_id, maxPassesPerItem);
|
|
239
299
|
if (applicableProducts.length === 0)
|
|
240
300
|
return false;
|
|
241
301
|
const usageAmount = typeof voucher.edit_current_amount === "number" ? voucher.edit_current_amount : getRecommendedAmount(voucher);
|
|
@@ -313,6 +373,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
313
373
|
product_id: product.product_id,
|
|
314
374
|
parent_product_id: product.parent_product_id || null,
|
|
315
375
|
is_bundle_item: product.is_bundle_item || false,
|
|
376
|
+
lineKey: product._walletPassLineKey,
|
|
377
|
+
orderLineQuantity: getExpandedOrderLineQuantity(product),
|
|
316
378
|
deductAmount: actualDeductAmount.toNumber(),
|
|
317
379
|
// 转换为数字
|
|
318
380
|
deductQuantity: actualDeductQty
|
|
@@ -338,6 +400,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
338
400
|
product_id: targetProduct.product_id,
|
|
339
401
|
parent_product_id: targetProduct.parent_product_id || null,
|
|
340
402
|
is_bundle_item: targetProduct.is_bundle_item || false,
|
|
403
|
+
lineKey: targetProduct._walletPassLineKey,
|
|
404
|
+
orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
|
|
341
405
|
deductAmount: actualDeductAmount.toNumber(),
|
|
342
406
|
deductQuantity: actualDeductQty
|
|
343
407
|
});
|
|
@@ -346,9 +410,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
346
410
|
if (totalDeducted.greaterThan(0)) {
|
|
347
411
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
348
412
|
usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
|
|
349
|
-
|
|
350
|
-
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
|
|
351
|
-
});
|
|
413
|
+
applyMaxPassUsageIncrements(itemPassUsageMap, product_id, maxPassesPerItem, deductionDetails);
|
|
352
414
|
recommendedVouchers.push({
|
|
353
415
|
...voucher,
|
|
354
416
|
actualDeduction: totalDeducted.toNumber(),
|
|
@@ -391,23 +453,19 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
391
453
|
let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
|
|
392
454
|
const selectedWithDetails = [];
|
|
393
455
|
const itemPassUsageMap = /* @__PURE__ */ new Map();
|
|
394
|
-
const
|
|
456
|
+
const getItemPassUsageRecalc = (walletPassProductId, lineKey) => {
|
|
395
457
|
var _a;
|
|
396
|
-
return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(
|
|
458
|
+
return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
|
|
397
459
|
};
|
|
398
|
-
const
|
|
399
|
-
if (!itemPassUsageMap.has(walletPassProductId)) {
|
|
400
|
-
itemPassUsageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
401
|
-
}
|
|
402
|
-
const innerMap = itemPassUsageMap.get(walletPassProductId);
|
|
403
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
404
|
-
};
|
|
405
|
-
const filterByMaxPassesPerItem = (products2, walletPassProductId, maxPassesPerItem) => {
|
|
460
|
+
const filterByMaxPassesPerItemRecalc = (products2, walletPassProductId, maxPassesPerItem) => {
|
|
406
461
|
if (maxPassesPerItem <= 0)
|
|
407
462
|
return products2;
|
|
408
|
-
return products2.filter(
|
|
409
|
-
|
|
410
|
-
|
|
463
|
+
return products2.filter((p) => {
|
|
464
|
+
const lineKey = p._walletPassLineKey;
|
|
465
|
+
if (!lineKey)
|
|
466
|
+
return true;
|
|
467
|
+
return getItemPassUsageRecalc(walletPassProductId, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
|
|
468
|
+
});
|
|
411
469
|
};
|
|
412
470
|
selectedVouchers.forEach((selectedVoucher) => {
|
|
413
471
|
const { config, id } = selectedVoucher;
|
|
@@ -418,7 +476,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
418
476
|
selectedVoucher,
|
|
419
477
|
productsForCalc
|
|
420
478
|
).filter((p) => p[amountField].greaterThan(0));
|
|
421
|
-
applicableProducts =
|
|
479
|
+
applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, selectedVoucher.product_id, maxPassesPerItem);
|
|
422
480
|
if (applicableProducts.length === 0) {
|
|
423
481
|
selectedWithDetails.push({
|
|
424
482
|
...selectedVoucher,
|
|
@@ -461,6 +519,8 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
461
519
|
product_id: product.product_id,
|
|
462
520
|
parent_product_id: product.parent_product_id || null,
|
|
463
521
|
is_bundle_item: product.is_bundle_item || false,
|
|
522
|
+
lineKey: product._walletPassLineKey,
|
|
523
|
+
orderLineQuantity: getExpandedOrderLineQuantity(product),
|
|
464
524
|
deductAmount: actualDeductAmount.toNumber(),
|
|
465
525
|
// 转换为数字
|
|
466
526
|
deductQuantity: actualDeductQty
|
|
@@ -486,15 +546,15 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
486
546
|
product_id: targetProduct.product_id,
|
|
487
547
|
parent_product_id: targetProduct.parent_product_id || null,
|
|
488
548
|
is_bundle_item: targetProduct.is_bundle_item || false,
|
|
549
|
+
lineKey: targetProduct._walletPassLineKey,
|
|
550
|
+
orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
|
|
489
551
|
deductAmount: actualDeductAmount.toNumber(),
|
|
490
552
|
deductQuantity: actualDeductQty
|
|
491
553
|
});
|
|
492
554
|
}
|
|
493
555
|
const totalDeducted = maxDeduction.minus(deductionLeft);
|
|
494
556
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
495
|
-
|
|
496
|
-
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
|
|
497
|
-
});
|
|
557
|
+
applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
|
|
498
558
|
selectedWithDetails.push({
|
|
499
559
|
...selectedVoucher,
|
|
500
560
|
actualDeduction: totalDeducted.toNumber(),
|
|
@@ -544,7 +604,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
544
604
|
voucher,
|
|
545
605
|
productsForCalc
|
|
546
606
|
).filter((p) => p[amountField].greaterThan(0));
|
|
547
|
-
applicableProducts =
|
|
607
|
+
applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, product_id, maxPassesPerItem);
|
|
548
608
|
if (applicableProducts.length === 0) {
|
|
549
609
|
isAvailable = false;
|
|
550
610
|
reasonCode = "not_meet_the_required_conditions";
|
|
@@ -649,14 +709,17 @@ var getBundleItemPrice = (bundleItem, parentQuantity, isDeductTaxAndFee) => {
|
|
|
649
709
|
};
|
|
650
710
|
var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
|
|
651
711
|
const expandedProducts = [];
|
|
652
|
-
products.forEach((product) => {
|
|
712
|
+
products.forEach((product, indexInOrder) => {
|
|
653
713
|
const productQuantity = getProductQuantity(product);
|
|
714
|
+
const parentLineKey = resolveWalletPassLineKey(product, indexInOrder);
|
|
654
715
|
const unitPriceWithTax = getMainProductPrice(product, true);
|
|
655
716
|
const unitPricePure = getMainProductPrice(product, false);
|
|
656
717
|
expandedProducts.push({
|
|
657
718
|
...product,
|
|
658
719
|
is_bundle_item: false,
|
|
659
720
|
parent_product_id: null,
|
|
721
|
+
_walletPassLineKey: parentLineKey,
|
|
722
|
+
_orderLineQuantity: productQuantity,
|
|
660
723
|
// 单价(用于按 quantity 计算抵扣)
|
|
661
724
|
unitPriceWithTax: new import_decimal.default(unitPriceWithTax),
|
|
662
725
|
unitPricePure: new import_decimal.default(unitPricePure),
|
|
@@ -671,6 +734,7 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
|
|
|
671
734
|
product.product_bundle.forEach((bundleItem) => {
|
|
672
735
|
if (getBundleItemIsOriginalPrice(bundleItem)) {
|
|
673
736
|
const bundleQuantity = bundleItem.num * productQuantity;
|
|
737
|
+
const bundleLineKey = `${parentLineKey}#bundle:${bundleItem.bundle_id}:${bundleItem.bundle_product_id}`;
|
|
674
738
|
const bundleUnitPriceWithTax = new import_decimal.default(getBundleItemPrice(bundleItem, 1, true)).dividedBy(bundleItem.num);
|
|
675
739
|
const bundleUnitPricePure = new import_decimal.default(getBundleItemPrice(bundleItem, 1, false)).dividedBy(bundleItem.num);
|
|
676
740
|
expandedProducts.push({
|
|
@@ -681,6 +745,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
|
|
|
681
745
|
parent_product_id: product.product_id,
|
|
682
746
|
quantity: bundleQuantity,
|
|
683
747
|
// 子商品数量 * 主商品数量
|
|
748
|
+
_walletPassLineKey: bundleLineKey,
|
|
749
|
+
_orderLineQuantity: bundleQuantity,
|
|
684
750
|
// 单价(用于按 quantity 计算抵扣)
|
|
685
751
|
unitPriceWithTax: bundleUnitPriceWithTax,
|
|
686
752
|
unitPricePure: bundleUnitPricePure,
|
|
@@ -697,9 +763,6 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
|
|
|
697
763
|
});
|
|
698
764
|
return expandedProducts;
|
|
699
765
|
};
|
|
700
|
-
var getProductQuantity = (product) => {
|
|
701
|
-
return product.quantity || product.product_quantity || 1;
|
|
702
|
-
};
|
|
703
766
|
var getBundleItemIsOriginalPrice = (item) => {
|
|
704
767
|
return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
|
|
705
768
|
};
|
|
@@ -723,5 +786,6 @@ var getBundleItemIsMarkupOrDiscountPrice = (item) => {
|
|
|
723
786
|
getMainProductPrice,
|
|
724
787
|
getProductQuantity,
|
|
725
788
|
processVouchers,
|
|
726
|
-
recalculateVouchers
|
|
789
|
+
recalculateVouchers,
|
|
790
|
+
resolveWalletPassLineKey
|
|
727
791
|
});
|
|
@@ -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
|
};
|
|
@@ -120,6 +120,8 @@ export interface Discount {
|
|
|
120
120
|
allowCrossProduct?: boolean;
|
|
121
121
|
/** 可用商品数量上限 */
|
|
122
122
|
applicableProductLimit?: number;
|
|
123
|
+
/** 是否抵扣单规格价格 (Option Price) */
|
|
124
|
+
deductOptionPrice?: boolean;
|
|
123
125
|
};
|
|
124
126
|
applicableProductIds?: number[];
|
|
125
127
|
applicableProductDetails: ApplicableProductDetails[];
|