@pisell/pisellos 2.1.92 → 2.1.93
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +3 -0
- package/dist/model/strategy/adapter/index.js +4 -0
- package/dist/model/strategy/adapter/type.d.ts +28 -0
- package/dist/model/strategy/adapter/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +497 -0
- package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/dist/model/strategy/adapter/walletPass/example.js +258 -0
- package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/dist/model/strategy/adapter/walletPass/index.js +182 -0
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +165 -0
- package/dist/model/strategy/adapter/walletPass/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
- package/dist/model/strategy/index.d.ts +94 -0
- package/dist/model/strategy/index.js +551 -0
- package/dist/model/strategy/strategy-example.d.ts +5 -0
- package/dist/model/strategy/strategy-example.js +331 -0
- package/dist/model/strategy/type.d.ts +228 -0
- package/dist/model/strategy/type.js +94 -0
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +11 -0
- package/dist/modules/Discount/types.d.ts +16 -0
- package/dist/modules/Payment/index.d.ts +2 -1
- package/dist/modules/Payment/index.js +10 -7
- package/dist/modules/Payment/utils.js +3 -0
- package/dist/modules/Payment/walletpass.d.ts +23 -0
- package/dist/modules/Payment/walletpass.js +191 -95
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +9 -5
- package/dist/modules/Rules/index.js +539 -125
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Summary/types.d.ts +2 -0
- package/dist/modules/Summary/utils.d.ts +6 -0
- package/dist/modules/Summary/utils.js +21 -0
- package/dist/plugins/window.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -7
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- package/dist/solution/ShopDiscount/types.js +2 -1
- package/dist/solution/ShopDiscount/utils.js +26 -12
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +3 -0
- package/lib/model/strategy/adapter/index.js +45 -0
- package/lib/model/strategy/adapter/type.d.ts +28 -0
- package/lib/model/strategy/adapter/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +421 -0
- package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/lib/model/strategy/adapter/walletPass/example.js +207 -0
- package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/lib/model/strategy/adapter/walletPass/index.js +142 -0
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +165 -0
- package/lib/model/strategy/adapter/walletPass/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
- package/lib/model/strategy/index.d.ts +94 -0
- package/lib/model/strategy/index.js +413 -0
- package/lib/model/strategy/strategy-example.d.ts +5 -0
- package/lib/model/strategy/strategy-example.js +318 -0
- package/lib/model/strategy/type.d.ts +228 -0
- package/lib/model/strategy/type.js +44 -0
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -0
- package/lib/modules/Discount/types.d.ts +16 -0
- package/lib/modules/Payment/index.d.ts +2 -1
- package/lib/modules/Payment/index.js +1 -0
- package/lib/modules/Payment/utils.js +3 -0
- package/lib/modules/Payment/walletpass.d.ts +23 -0
- package/lib/modules/Payment/walletpass.js +94 -17
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +9 -5
- package/lib/modules/Rules/index.js +665 -259
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Summary/types.d.ts +2 -0
- package/lib/modules/Summary/utils.d.ts +6 -0
- package/lib/modules/Summary/utils.js +15 -0
- package/lib/plugins/window.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.js +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +22 -8
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +10 -6
- package/package.json +1 -1
|
@@ -50,6 +50,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
50
50
|
this.core = core;
|
|
51
51
|
this.hooks = options == null ? void 0 : options.hooks;
|
|
52
52
|
this.store = options == null ? void 0 : options.store;
|
|
53
|
+
this.window = core.getPlugin("window");
|
|
53
54
|
}
|
|
54
55
|
async setRulesList(rulesList) {
|
|
55
56
|
this.store.rulesList = rulesList;
|
|
@@ -71,11 +72,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
71
72
|
return false;
|
|
72
73
|
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
73
74
|
}
|
|
75
|
+
getWalletPassEvaluator() {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
|
|
78
|
+
}
|
|
74
79
|
// 判断discountList 是否可以对当前productList生效
|
|
75
80
|
isDiscountListAvailable({
|
|
76
81
|
oldDiscountList,
|
|
77
82
|
newDiscountList,
|
|
78
83
|
productList,
|
|
84
|
+
orderTotalAmount,
|
|
79
85
|
holders,
|
|
80
86
|
isFormSubject
|
|
81
87
|
}) {
|
|
@@ -108,6 +114,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
108
114
|
const result = this.calcDiscount({
|
|
109
115
|
discountList: mergedDiscountList,
|
|
110
116
|
productList: [...productList],
|
|
117
|
+
orderTotalAmount,
|
|
111
118
|
holders,
|
|
112
119
|
isFormSubject
|
|
113
120
|
}, {
|
|
@@ -180,8 +187,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
180
187
|
discountList,
|
|
181
188
|
productList,
|
|
182
189
|
holders,
|
|
183
|
-
isFormSubject
|
|
190
|
+
isFormSubject,
|
|
191
|
+
orderTotalAmount
|
|
184
192
|
}, options) {
|
|
193
|
+
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
185
194
|
const editModeDiscount = [];
|
|
186
195
|
const addModeDiscount = [];
|
|
187
196
|
discountList.forEach((discount) => {
|
|
@@ -334,7 +343,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
334
343
|
return compareByExpireTime(a, b);
|
|
335
344
|
});
|
|
336
345
|
const flattenedList = flattenProductsWithBundle(productList);
|
|
337
|
-
const isEditModeAddNewProduct = flattenedList.find((n) => n.booking_id) && flattenedList.find((n) => !n.booking_id);
|
|
338
346
|
const sortedFlattenedList = flattenedList.sort((a, b) => {
|
|
339
347
|
var _a, _b;
|
|
340
348
|
const priceA = new import_decimal.default(
|
|
@@ -359,7 +367,59 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
359
367
|
}
|
|
360
368
|
return priceB.minus(priceA).toNumber();
|
|
361
369
|
});
|
|
370
|
+
const evaluator = this.getWalletPassEvaluator();
|
|
371
|
+
if (evaluator) {
|
|
372
|
+
addModeDiscount.forEach((discount) => {
|
|
373
|
+
var _a, _b;
|
|
374
|
+
const discountType = discount.tag || discount.type;
|
|
375
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
376
|
+
discountType
|
|
377
|
+
)) {
|
|
378
|
+
const voucher = {
|
|
379
|
+
id: discount.id,
|
|
380
|
+
amount: Number(discount.par_value || 0),
|
|
381
|
+
balance: Number(discount.balance || 0),
|
|
382
|
+
type: discountType,
|
|
383
|
+
product_id: discount.product_id,
|
|
384
|
+
unified_available_status: 1,
|
|
385
|
+
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
386
|
+
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
387
|
+
};
|
|
388
|
+
const productsForEvaluate = sortedFlattenedList.map((item) => ({
|
|
389
|
+
product_id: item.id,
|
|
390
|
+
price: item.price || 0,
|
|
391
|
+
quantity: item.quantity || item.num || 1,
|
|
392
|
+
selling_price: item.price || 0
|
|
393
|
+
}));
|
|
394
|
+
const result = evaluator.checkVoucherAvailability({
|
|
395
|
+
orderTotalAmount,
|
|
396
|
+
products: productsForEvaluate,
|
|
397
|
+
vouchers: [voucher]
|
|
398
|
+
});
|
|
399
|
+
if (result.isAvailable) {
|
|
400
|
+
discount.config = {
|
|
401
|
+
...result.config,
|
|
402
|
+
isAvailable: true
|
|
403
|
+
};
|
|
404
|
+
} else {
|
|
405
|
+
discount.config = {
|
|
406
|
+
isAvailable: false
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
362
412
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
413
|
+
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
414
|
+
const usedDiscountCardLimitCounts = /* @__PURE__ */ new Map();
|
|
415
|
+
editModeDiscount.forEach((discount) => {
|
|
416
|
+
var _a;
|
|
417
|
+
const discountType = discount.tag || discount.type;
|
|
418
|
+
if (["discount_card", "product_discount_card"].includes(discountType)) {
|
|
419
|
+
const currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
420
|
+
usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_a = discount.metadata) == null ? void 0 : _a.num) || 1));
|
|
421
|
+
}
|
|
422
|
+
});
|
|
363
423
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
364
424
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
365
425
|
addModeDiscount.forEach((discount) => {
|
|
@@ -513,7 +573,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
513
573
|
originProduct = flatItem.originProduct;
|
|
514
574
|
}
|
|
515
575
|
addModeDiscount.forEach((discount) => {
|
|
516
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
576
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
517
577
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
518
578
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
519
579
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -526,7 +586,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
526
586
|
);
|
|
527
587
|
let timeLimit = true;
|
|
528
588
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
529
|
-
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
589
|
+
const 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;
|
|
530
590
|
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a2 = product == null ? void 0 : product.discount_list) == null ? void 0 : _a2.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
|
|
531
591
|
(discount2) => discount2.id && [
|
|
532
592
|
"good_pass",
|
|
@@ -535,8 +595,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
535
595
|
].includes(discount2.tag || discount2.type)
|
|
536
596
|
))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
|
|
537
597
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
538
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
539
|
-
(
|
|
598
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_g = discount.config) == null ? void 0 : _g.isAvailable)) {
|
|
599
|
+
(_h = discountApplicability.get(discount.id)) == null ? void 0 : _h.push(product.id);
|
|
540
600
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
541
601
|
const discountType = discount.tag || discount.type;
|
|
542
602
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -546,14 +606,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
546
606
|
type: discountType,
|
|
547
607
|
tag: discountType,
|
|
548
608
|
discount: {
|
|
549
|
-
discount_card_type: (
|
|
609
|
+
discount_card_type: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_card_type,
|
|
550
610
|
fixed_amount: product.price,
|
|
551
|
-
discount_calculation_mode: (
|
|
611
|
+
discount_calculation_mode: (_j = discount == null ? void 0 : discount.metadata) == null ? void 0 : _j.discount_calculation_mode,
|
|
552
612
|
resource_id: discount.id,
|
|
553
613
|
title: discount.format_title,
|
|
554
614
|
original_amount: product.price || product.origin_total,
|
|
555
615
|
pre_value: discount.par_value,
|
|
556
|
-
product_id: originProduct.id
|
|
616
|
+
product_id: originProduct.id,
|
|
617
|
+
discount_product_id: discount.product_id
|
|
557
618
|
},
|
|
558
619
|
metadata: {
|
|
559
620
|
num,
|
|
@@ -567,7 +628,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
567
628
|
});
|
|
568
629
|
const processedFlatItemsMap = /* @__PURE__ */ new Map();
|
|
569
630
|
sortedFlattenedList.forEach((flatItem, index) => {
|
|
570
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
631
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
|
|
571
632
|
let product, originProduct;
|
|
572
633
|
if (flatItem.type === "main") {
|
|
573
634
|
product = flatItem.product;
|
|
@@ -588,22 +649,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
588
649
|
};
|
|
589
650
|
originProduct = flatItem.originProduct;
|
|
590
651
|
}
|
|
591
|
-
if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every(
|
|
652
|
+
if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every(
|
|
653
|
+
(discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
|
|
654
|
+
discount.tag || discount.type
|
|
655
|
+
)
|
|
656
|
+
))) {
|
|
592
657
|
if (flatItem.type === "main") {
|
|
593
658
|
processedProductsMap.set(product._id, [originProduct]);
|
|
594
659
|
} else {
|
|
595
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
660
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
661
|
+
{
|
|
662
|
+
...flatItem,
|
|
663
|
+
processed: true
|
|
664
|
+
}
|
|
665
|
+
]);
|
|
599
666
|
}
|
|
600
667
|
return;
|
|
601
668
|
}
|
|
602
669
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
603
|
-
var _a2, _b2;
|
|
604
|
-
|
|
670
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
671
|
+
const discountType2 = discount.tag || discount.type;
|
|
672
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
673
|
+
discountType2
|
|
674
|
+
)) {
|
|
675
|
+
if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
|
|
605
680
|
return false;
|
|
606
|
-
if ((Number(product.price) <= 0 || !product.price) && !((
|
|
681
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
|
|
607
682
|
var _a3;
|
|
608
683
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
609
684
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -611,7 +686,31 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
611
686
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
612
687
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
613
688
|
return false;
|
|
689
|
+
if ((discount.tag || discount.type) === "good_pass") {
|
|
690
|
+
const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
|
|
691
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
692
|
+
const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
693
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
const discountTypeForLimit = discount.tag || discount.type;
|
|
699
|
+
if (["discount_card", "product_discount_card"].includes(discountTypeForLimit)) {
|
|
700
|
+
const applicableProductLimitConfig = ((_e2 = discount.config) == null ? void 0 : _e2.applicableProductLimit) || 0;
|
|
701
|
+
if (applicableProductLimitConfig > 0) {
|
|
702
|
+
const currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
703
|
+
if (currentUsedLimitCount >= applicableProductLimitConfig) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
614
708
|
const limitedData = discount.limited_relation_product_data;
|
|
709
|
+
let timeLimit = true;
|
|
710
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
711
|
+
if (!timeLimit) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
615
714
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
616
715
|
const isHolderMatch = this.checkHolderMatch(
|
|
617
716
|
discount,
|
|
@@ -623,12 +722,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
623
722
|
);
|
|
624
723
|
if (!isHolderMatch)
|
|
625
724
|
return false;
|
|
626
|
-
let timeLimit = true;
|
|
627
|
-
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
628
|
-
if (!timeLimit) {
|
|
629
|
-
return false;
|
|
630
|
-
}
|
|
631
725
|
if (limitedData.type === "product_all") {
|
|
726
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
632
729
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
633
730
|
return false;
|
|
634
731
|
}
|
|
@@ -641,7 +738,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
641
738
|
}
|
|
642
739
|
return false;
|
|
643
740
|
});
|
|
644
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
741
|
+
const selectedDiscountCard = applicableDiscounts.find(
|
|
742
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
743
|
+
);
|
|
645
744
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
646
745
|
let isManualDiscount = false;
|
|
647
746
|
if (flatItem.type === "main") {
|
|
@@ -708,9 +807,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
708
807
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
709
808
|
if (flatItem.type === "main") {
|
|
710
809
|
if (product.isClient) {
|
|
711
|
-
processedProductsMap.set(
|
|
712
|
-
|
|
713
|
-
[this.hooks.setProduct(originProduct, {
|
|
810
|
+
processedProductsMap.set(product._id, [
|
|
811
|
+
this.hooks.setProduct(originProduct, {
|
|
714
812
|
...isManualDiscount ? {} : {
|
|
715
813
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
716
814
|
product: {
|
|
@@ -731,12 +829,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
731
829
|
price: product.price
|
|
732
830
|
},
|
|
733
831
|
discount_list: []
|
|
734
|
-
})
|
|
735
|
-
);
|
|
832
|
+
})
|
|
833
|
+
]);
|
|
736
834
|
} else {
|
|
737
|
-
processedProductsMap.set(
|
|
738
|
-
|
|
739
|
-
[this.hooks.setProduct(originProduct, {
|
|
835
|
+
processedProductsMap.set(product._id, [
|
|
836
|
+
this.hooks.setProduct(originProduct, {
|
|
740
837
|
...isManualDiscount ? {
|
|
741
838
|
price: product.price,
|
|
742
839
|
main_product_selling_price: product.price
|
|
@@ -747,48 +844,83 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
747
844
|
main_product_selling_price: product.price
|
|
748
845
|
},
|
|
749
846
|
discount_list: []
|
|
750
|
-
})
|
|
751
|
-
);
|
|
847
|
+
})
|
|
848
|
+
]);
|
|
752
849
|
}
|
|
753
850
|
} else {
|
|
754
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
851
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
852
|
+
{
|
|
853
|
+
...flatItem,
|
|
854
|
+
discount_list: [],
|
|
855
|
+
price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
|
|
856
|
+
processed: true
|
|
857
|
+
}
|
|
858
|
+
]);
|
|
760
859
|
}
|
|
761
860
|
return;
|
|
762
861
|
}
|
|
763
862
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
|
|
764
863
|
return;
|
|
765
864
|
}
|
|
766
|
-
const
|
|
865
|
+
const discountType = selectedDiscount.tag || selectedDiscount.type;
|
|
866
|
+
const isGoodPass = discountType === "good_pass";
|
|
867
|
+
const isDiscountCard = ["discount_card", "product_discount_card"].includes(discountType);
|
|
868
|
+
const applicableProductLimit = ((_u = selectedDiscount.config) == null ? void 0 : _u.applicableProductLimit) || 0;
|
|
869
|
+
const isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
|
|
767
870
|
const totalQuantity = product.quantity || product.num || 1;
|
|
768
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
769
|
-
|
|
871
|
+
const availableGoodPassCount = applicableDiscounts.filter(
|
|
872
|
+
(item) => (item.tag || item.type) === "good_pass"
|
|
873
|
+
).length;
|
|
874
|
+
let maxUsageLimit;
|
|
875
|
+
if (isGoodPass) {
|
|
876
|
+
maxUsageLimit = availableGoodPassCount;
|
|
877
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
878
|
+
maxUsageLimit = Math.min(
|
|
879
|
+
availableGoodPassCount,
|
|
880
|
+
selectedDiscount.config.maxUsagePerOrder
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
} else if (isDiscountCard && applicableProductLimit > 0) {
|
|
884
|
+
const usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
|
|
885
|
+
maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
|
|
886
|
+
} else {
|
|
887
|
+
maxUsageLimit = 1;
|
|
888
|
+
}
|
|
889
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
770
890
|
const arr = [];
|
|
771
891
|
if (flatItem.type === "main") {
|
|
772
892
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
773
|
-
arr.push(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
893
|
+
arr.push(
|
|
894
|
+
this.hooks.setProduct(originProduct, {
|
|
895
|
+
discount_list: [],
|
|
896
|
+
quantity: totalQuantity - splitCount,
|
|
897
|
+
_id: product._id.split("___")[0],
|
|
898
|
+
total: product.origin_total || product.total
|
|
899
|
+
})
|
|
900
|
+
);
|
|
778
901
|
}
|
|
779
902
|
for (let i = 0; i < splitCount; i++) {
|
|
780
|
-
const
|
|
781
|
-
usedDiscounts.set(
|
|
782
|
-
|
|
903
|
+
const currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
904
|
+
usedDiscounts.set(currentSelectedDiscount.id, true);
|
|
905
|
+
if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === "good_pass") {
|
|
906
|
+
const currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
|
|
907
|
+
usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
|
|
908
|
+
}
|
|
909
|
+
const currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
|
|
910
|
+
if (["discount_card", "product_discount_card"].includes(currentDiscountTypeForCount)) {
|
|
911
|
+
const currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
|
|
912
|
+
usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
|
|
913
|
+
}
|
|
914
|
+
const appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
|
|
783
915
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
784
|
-
if (((
|
|
916
|
+
if (((_v = product.discount_list) == null ? void 0 : _v.length) && product.origin_total) {
|
|
785
917
|
productOriginTotal = product.origin_total;
|
|
786
918
|
}
|
|
787
|
-
if (Number(((
|
|
919
|
+
if (Number(((_w = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _w.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
788
920
|
productOriginTotal = product.total;
|
|
789
921
|
}
|
|
790
|
-
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(
|
|
791
|
-
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
922
|
+
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
|
|
923
|
+
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
792
924
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
793
925
|
let targetProductTotal;
|
|
794
926
|
let amount;
|
|
@@ -798,35 +930,38 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
798
930
|
productDiscountDifference = productAllocation.difference;
|
|
799
931
|
targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
|
|
800
932
|
} else {
|
|
801
|
-
targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
933
|
+
targetProductTotal = (0, import_utils.getDiscountAmount)(currentSelectedDiscount, product.price, product.price);
|
|
802
934
|
amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
803
935
|
}
|
|
804
|
-
const
|
|
805
|
-
const
|
|
936
|
+
const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
|
|
937
|
+
const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
938
|
+
const currentIsGoodPass = currentDiscountType === "good_pass";
|
|
806
939
|
const discountDetail = {
|
|
807
|
-
amount,
|
|
808
|
-
type:
|
|
940
|
+
amount: actualDiscountAmount,
|
|
941
|
+
type: currentDiscountType,
|
|
809
942
|
discount: {
|
|
810
|
-
discount_card_type: (
|
|
811
|
-
fixed_amount:
|
|
812
|
-
discount_calculation_mode: (
|
|
813
|
-
resource_id:
|
|
814
|
-
title:
|
|
943
|
+
discount_card_type: (_x = currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.metadata) == null ? void 0 : _x.discount_card_type,
|
|
944
|
+
fixed_amount: actualDiscountAmount,
|
|
945
|
+
discount_calculation_mode: (_y = currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.metadata) == null ? void 0 : _y.discount_calculation_mode,
|
|
946
|
+
resource_id: currentSelectedDiscount.id,
|
|
947
|
+
title: currentSelectedDiscount.format_title,
|
|
815
948
|
original_amount: product.price,
|
|
816
949
|
product_id: originProduct.id,
|
|
817
|
-
percent:
|
|
950
|
+
percent: currentSelectedDiscount.par_value,
|
|
951
|
+
discount_product_id: currentSelectedDiscount.product_id
|
|
818
952
|
},
|
|
819
|
-
// 前端使用的num
|
|
820
|
-
_num:
|
|
953
|
+
// 前端使用的num数量,为了计算优惠金额(拆分时为1)
|
|
954
|
+
_num: isNeedSplit ? 1 : product.num,
|
|
955
|
+
config: currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.config,
|
|
821
956
|
metadata: {
|
|
822
957
|
num: 1,
|
|
823
|
-
discount_rule_uncheck_flag:
|
|
958
|
+
discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
824
959
|
// 🔥 order_level 分摊差值
|
|
825
960
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
826
961
|
}
|
|
827
962
|
};
|
|
828
963
|
appliedProducts.push(discountDetail);
|
|
829
|
-
appliedDiscountProducts.set(
|
|
964
|
+
appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
|
|
830
965
|
let total = targetProductTotal;
|
|
831
966
|
if (product.options) {
|
|
832
967
|
total = product.options.reduce((accumulator, currentValue) => {
|
|
@@ -836,32 +971,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
836
971
|
}, new import_decimal.default(total)).toNumber();
|
|
837
972
|
}
|
|
838
973
|
if (product.isClient) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
974
|
+
arr.push(
|
|
975
|
+
this.hooks.setProduct(originProduct, {
|
|
976
|
+
discount_list: [discountDetail],
|
|
977
|
+
price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
|
|
978
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
979
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
980
|
+
product: {
|
|
981
|
+
original_price: product.original_price
|
|
982
|
+
},
|
|
983
|
+
bundle: product.bundle,
|
|
984
|
+
options: product.options
|
|
985
|
+
}),
|
|
986
|
+
variant: originProduct._productInit.variant,
|
|
987
|
+
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
988
|
+
total: targetProductTotal
|
|
989
|
+
})
|
|
990
|
+
);
|
|
855
991
|
} else {
|
|
856
|
-
arr.push(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
992
|
+
arr.push(
|
|
993
|
+
this.hooks.setProduct(originProduct, {
|
|
994
|
+
discount_list: [discountDetail],
|
|
995
|
+
_id: product._id.split("___")[0] + "___" + currentSelectedDiscount.id + "_" + i + "_" + index,
|
|
996
|
+
price: currentIsGoodPass ? 0 : product.price,
|
|
997
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
998
|
+
total: targetProductTotal,
|
|
999
|
+
origin_total: productOriginTotal,
|
|
1000
|
+
main_product_selling_price: targetProductTotal
|
|
1001
|
+
})
|
|
1002
|
+
);
|
|
865
1003
|
}
|
|
866
1004
|
}
|
|
867
1005
|
processedProductsMap.set(product._id, arr);
|
|
@@ -871,62 +1009,298 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
871
1009
|
const discountNum = splitCount;
|
|
872
1010
|
const normalNum = totalQuantity - discountNum;
|
|
873
1011
|
for (let i = 0; i < discountNum; i++) {
|
|
874
|
-
const
|
|
875
|
-
usedDiscounts.set(
|
|
1012
|
+
const currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1013
|
+
usedDiscounts.set(currentBundleDiscount.id, true);
|
|
1014
|
+
if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
|
|
1015
|
+
const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
|
|
1016
|
+
usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
|
|
1017
|
+
}
|
|
1018
|
+
const bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1019
|
+
if (["discount_card", "product_discount_card"].includes(bundleDiscountTypeForCount)) {
|
|
1020
|
+
const currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1021
|
+
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
|
|
1022
|
+
}
|
|
876
1023
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
1024
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(
|
|
1025
|
+
currentBundleDiscount,
|
|
1026
|
+
product.origin_total,
|
|
1027
|
+
product.origin_total
|
|
1028
|
+
);
|
|
1029
|
+
const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
1030
|
+
const bundleDiscountType = currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag;
|
|
877
1031
|
const discountDetail = {
|
|
878
|
-
amount:
|
|
879
|
-
type:
|
|
1032
|
+
amount: bundleDiscountAmount,
|
|
1033
|
+
type: bundleDiscountType,
|
|
880
1034
|
discount: {
|
|
881
|
-
|
|
882
|
-
discount_calculation_mode: (
|
|
883
|
-
|
|
884
|
-
|
|
1035
|
+
discount_card_type: (_z = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _z.discount_card_type,
|
|
1036
|
+
discount_calculation_mode: (_A = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _A.discount_calculation_mode,
|
|
1037
|
+
fixed_amount: bundleDiscountAmount,
|
|
1038
|
+
resource_id: currentBundleDiscount.id,
|
|
1039
|
+
title: currentBundleDiscount.format_title,
|
|
885
1040
|
original_amount: product.origin_total,
|
|
886
|
-
product_id: product.id
|
|
1041
|
+
product_id: product.id,
|
|
1042
|
+
percent: currentBundleDiscount.par_value,
|
|
1043
|
+
discount_product_id: currentBundleDiscount.product_id
|
|
887
1044
|
},
|
|
888
1045
|
metadata: {
|
|
889
1046
|
// 🔥 使用拆分后的唯一 _id
|
|
890
1047
|
custom_product_bundle_map_id: uniqueId,
|
|
891
|
-
discount_rule_uncheck_flag:
|
|
1048
|
+
discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
892
1049
|
num: 1
|
|
893
1050
|
},
|
|
894
|
-
_num: 1
|
|
1051
|
+
_num: 1,
|
|
1052
|
+
config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config
|
|
895
1053
|
};
|
|
896
|
-
const appliedProducts = appliedDiscountProducts.get(
|
|
1054
|
+
const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
|
|
897
1055
|
appliedProducts.push(discountDetail);
|
|
898
|
-
appliedDiscountProducts.set(
|
|
1056
|
+
appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
|
|
899
1057
|
processedItems.push({
|
|
900
1058
|
...flatItem,
|
|
901
1059
|
// 🔥 使用唯一的 _id
|
|
902
1060
|
_id: uniqueId,
|
|
903
1061
|
num: 1,
|
|
904
1062
|
quantity: 1,
|
|
905
|
-
price:
|
|
906
|
-
//
|
|
907
|
-
total:
|
|
1063
|
+
price: discountedPrice,
|
|
1064
|
+
// 折扣后的价格
|
|
1065
|
+
total: discountedPrice,
|
|
908
1066
|
discount_list: [discountDetail],
|
|
909
1067
|
processed: true,
|
|
910
|
-
_discountId:
|
|
1068
|
+
_discountId: currentBundleDiscount.id
|
|
911
1069
|
});
|
|
912
1070
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1071
|
+
let remainingNum = normalNum;
|
|
1072
|
+
let continueSplitIndex = discountNum;
|
|
1073
|
+
while (remainingNum > 0) {
|
|
1074
|
+
const nextApplicableDiscounts = sortedDiscountList.filter((nextDiscount) => {
|
|
1075
|
+
var _a2, _b2, _c2, _d2;
|
|
1076
|
+
const nextDiscountType = nextDiscount.tag || nextDiscount.type;
|
|
1077
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(nextDiscountType)) {
|
|
1078
|
+
if (nextDiscount.config === void 0 || !((_a2 = nextDiscount == null ? void 0 : nextDiscount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if ((Number(product.total) <= 0 || !product.total) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find(
|
|
1083
|
+
(n) => {
|
|
1084
|
+
var _a3;
|
|
1085
|
+
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === nextDiscount.id;
|
|
1086
|
+
}
|
|
1087
|
+
)) && nextDiscountType !== "good_pass")
|
|
1088
|
+
return false;
|
|
1089
|
+
if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === "good_pass")
|
|
1090
|
+
return false;
|
|
1091
|
+
if (nextDiscountType === "good_pass") {
|
|
1092
|
+
const maxUsagePerOrder = (_c2 = nextDiscount.config) == null ? void 0 : _c2.maxUsagePerOrder;
|
|
1093
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1094
|
+
const currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
|
|
1095
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
1096
|
+
return false;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
if (["discount_card", "product_discount_card"].includes(nextDiscountType)) {
|
|
1101
|
+
const limitConfig = ((_d2 = nextDiscount.config) == null ? void 0 : _d2.applicableProductLimit) || 0;
|
|
1102
|
+
if (limitConfig > 0) {
|
|
1103
|
+
const currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
|
|
1104
|
+
if (currentUsedLimitCount >= limitConfig) {
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
const limitedData = nextDiscount.limited_relation_product_data;
|
|
1110
|
+
if (limitedData.type === "product_all") {
|
|
1111
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
return true;
|
|
1118
|
+
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1119
|
+
if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
return false;
|
|
922
1125
|
});
|
|
1126
|
+
if (nextApplicableDiscounts.length === 0) {
|
|
1127
|
+
processedItems.push({
|
|
1128
|
+
...flatItem,
|
|
1129
|
+
_id: `${flatItem._id}_split_rest`,
|
|
1130
|
+
num: remainingNum,
|
|
1131
|
+
quantity: remainingNum,
|
|
1132
|
+
discount_list: [],
|
|
1133
|
+
processed: true
|
|
1134
|
+
});
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
const nextSelectedDiscountCard = nextApplicableDiscounts.find(
|
|
1138
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
1139
|
+
);
|
|
1140
|
+
const nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1141
|
+
const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
|
|
1142
|
+
const nextIsGoodPass = nextDiscType === "good_pass";
|
|
1143
|
+
const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
|
|
1144
|
+
const nextApplicableProductLimit = ((_B = nextSelectedDiscount.config) == null ? void 0 : _B.applicableProductLimit) || 0;
|
|
1145
|
+
const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
|
|
1146
|
+
if (!nextIsNeedSplit) {
|
|
1147
|
+
const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1148
|
+
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1149
|
+
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
|
|
1150
|
+
const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1151
|
+
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1152
|
+
}
|
|
1153
|
+
const nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1154
|
+
if (["discount_card", "product_discount_card"].includes(nextNoSplitType)) {
|
|
1155
|
+
const curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1156
|
+
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curCount + remainingNum);
|
|
1157
|
+
}
|
|
1158
|
+
const nextOriginTotal = product.original_price || product.price || 0;
|
|
1159
|
+
const nextTargetTotal = (0, import_utils.getDiscountAmount)(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
|
|
1160
|
+
const nextDiscountAmount = new import_decimal.default(nextOriginTotal).minus(nextTargetTotal).toNumber();
|
|
1161
|
+
const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
|
|
1162
|
+
const nextBundleDiscType = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
|
|
1163
|
+
const nextDiscountDetail = {
|
|
1164
|
+
amount: nextDiscountAmount * remainingNum,
|
|
1165
|
+
type: nextBundleDiscType,
|
|
1166
|
+
discount: {
|
|
1167
|
+
discount_card_type: (_C = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _C.discount_card_type,
|
|
1168
|
+
fixed_amount: nextDiscountAmount,
|
|
1169
|
+
resource_id: nextBundleDiscount.id,
|
|
1170
|
+
title: nextBundleDiscount.format_title,
|
|
1171
|
+
original_amount: product.original_price,
|
|
1172
|
+
product_id: product.id,
|
|
1173
|
+
percent: nextBundleDiscount.par_value,
|
|
1174
|
+
discount_product_id: nextBundleDiscount.product_id
|
|
1175
|
+
},
|
|
1176
|
+
metadata: {
|
|
1177
|
+
custom_product_bundle_map_id: nextUniqueId,
|
|
1178
|
+
num: remainingNum
|
|
1179
|
+
},
|
|
1180
|
+
config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
|
|
1181
|
+
_num: remainingNum * (((_D = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _D.num) || 1)
|
|
1182
|
+
};
|
|
1183
|
+
const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1184
|
+
nextAppliedProducts.push(nextDiscountDetail);
|
|
1185
|
+
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1186
|
+
processedItems.push({
|
|
1187
|
+
...flatItem,
|
|
1188
|
+
_id: nextUniqueId,
|
|
1189
|
+
num: remainingNum,
|
|
1190
|
+
quantity: remainingNum,
|
|
1191
|
+
total: nextTargetTotal,
|
|
1192
|
+
price: new import_decimal.default(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
|
|
1193
|
+
discount_list: [nextDiscountDetail],
|
|
1194
|
+
processed: true
|
|
1195
|
+
});
|
|
1196
|
+
remainingNum = 0;
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
let nextMaxUsageLimit;
|
|
1200
|
+
if (nextIsGoodPass) {
|
|
1201
|
+
const nextGoodPassCount = nextApplicableDiscounts.filter(
|
|
1202
|
+
(item) => (item.tag || item.type) === "good_pass"
|
|
1203
|
+
).length;
|
|
1204
|
+
nextMaxUsageLimit = nextGoodPassCount;
|
|
1205
|
+
if ((_E = nextSelectedDiscount.config) == null ? void 0 : _E.maxUsagePerOrder) {
|
|
1206
|
+
const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
|
|
1207
|
+
nextMaxUsageLimit = Math.min(
|
|
1208
|
+
nextGoodPassCount,
|
|
1209
|
+
Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount)
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
} else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
|
|
1213
|
+
const usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
|
|
1214
|
+
nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - usedLimitCount);
|
|
1215
|
+
} else {
|
|
1216
|
+
nextMaxUsageLimit = 1;
|
|
1217
|
+
}
|
|
1218
|
+
const nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
|
|
1219
|
+
if (nextSplitCount === 0) {
|
|
1220
|
+
processedItems.push({
|
|
1221
|
+
...flatItem,
|
|
1222
|
+
_id: `${flatItem._id}_split_rest`,
|
|
1223
|
+
num: remainingNum,
|
|
1224
|
+
quantity: remainingNum,
|
|
1225
|
+
discount_list: [],
|
|
1226
|
+
processed: true
|
|
1227
|
+
});
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
for (let j = 0; j < nextSplitCount; j++) {
|
|
1231
|
+
const nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1232
|
+
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1233
|
+
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
|
|
1234
|
+
const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1235
|
+
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1236
|
+
}
|
|
1237
|
+
const nextBundleDiscTypeForCount = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1238
|
+
if (["discount_card", "product_discount_card"].includes(nextBundleDiscTypeForCount)) {
|
|
1239
|
+
const curLimitCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1240
|
+
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curLimitCount + 1);
|
|
1241
|
+
}
|
|
1242
|
+
const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
|
|
1243
|
+
const nextDiscountedPrice = (0, import_utils.getDiscountAmount)(
|
|
1244
|
+
nextBundleDiscount,
|
|
1245
|
+
product.origin_total,
|
|
1246
|
+
product.origin_total
|
|
1247
|
+
);
|
|
1248
|
+
const nextBundleDiscAmount = new import_decimal.default(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
|
|
1249
|
+
const nextBundleDiscTypeStr = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
|
|
1250
|
+
const nextDiscountDetail = {
|
|
1251
|
+
amount: nextBundleDiscAmount,
|
|
1252
|
+
type: nextBundleDiscTypeStr,
|
|
1253
|
+
discount: {
|
|
1254
|
+
discount_card_type: (_F = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _F.discount_card_type,
|
|
1255
|
+
fixed_amount: nextBundleDiscAmount,
|
|
1256
|
+
resource_id: nextBundleDiscount.id,
|
|
1257
|
+
title: nextBundleDiscount.format_title,
|
|
1258
|
+
original_amount: product.origin_total,
|
|
1259
|
+
product_id: product.id,
|
|
1260
|
+
percent: nextBundleDiscount.par_value,
|
|
1261
|
+
discount_product_id: nextBundleDiscount.product_id
|
|
1262
|
+
},
|
|
1263
|
+
metadata: {
|
|
1264
|
+
custom_product_bundle_map_id: nextUniqueId,
|
|
1265
|
+
num: 1
|
|
1266
|
+
},
|
|
1267
|
+
_num: 1,
|
|
1268
|
+
config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config
|
|
1269
|
+
};
|
|
1270
|
+
const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1271
|
+
nextAppliedProducts.push(nextDiscountDetail);
|
|
1272
|
+
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1273
|
+
processedItems.push({
|
|
1274
|
+
...flatItem,
|
|
1275
|
+
_id: nextUniqueId,
|
|
1276
|
+
num: 1,
|
|
1277
|
+
quantity: 1,
|
|
1278
|
+
price: nextDiscountedPrice,
|
|
1279
|
+
total: nextDiscountedPrice,
|
|
1280
|
+
discount_list: [nextDiscountDetail],
|
|
1281
|
+
processed: true,
|
|
1282
|
+
_discountId: nextBundleDiscount.id
|
|
1283
|
+
});
|
|
1284
|
+
continueSplitIndex++;
|
|
1285
|
+
}
|
|
1286
|
+
remainingNum -= nextSplitCount;
|
|
923
1287
|
}
|
|
924
1288
|
} else {
|
|
925
|
-
const
|
|
926
|
-
usedDiscounts.set(
|
|
1289
|
+
const currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
1290
|
+
usedDiscounts.set(currentBundleDiscount.id, true);
|
|
1291
|
+
if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
|
|
1292
|
+
const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
|
|
1293
|
+
usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
|
|
1294
|
+
}
|
|
1295
|
+
const noSplitDiscountType = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1296
|
+
if (["discount_card", "product_discount_card"].includes(noSplitDiscountType)) {
|
|
1297
|
+
const bundleQuantity = product.num || 1;
|
|
1298
|
+
const currentNoSplitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1299
|
+
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
|
|
1300
|
+
}
|
|
927
1301
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
928
|
-
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(
|
|
929
|
-
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1302
|
+
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
|
|
1303
|
+
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
930
1304
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
931
1305
|
let targetProductTotal;
|
|
932
1306
|
let fixedAmountPerItem;
|
|
@@ -937,40 +1311,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
937
1311
|
targetProductTotal = Math.max(new import_decimal.default(productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
938
1312
|
} else {
|
|
939
1313
|
targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
940
|
-
|
|
1314
|
+
currentBundleDiscount,
|
|
941
1315
|
productOriginTotal,
|
|
942
1316
|
productOriginTotal
|
|
943
1317
|
);
|
|
944
1318
|
fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
945
1319
|
}
|
|
946
|
-
|
|
1320
|
+
const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
947
1321
|
const uniqueId = flatItem._id;
|
|
948
1322
|
const discountDetail = {
|
|
949
|
-
amount:
|
|
950
|
-
type:
|
|
1323
|
+
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
1324
|
+
type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
|
|
951
1325
|
discount: {
|
|
952
|
-
discount_card_type: (
|
|
953
|
-
fixed_amount:
|
|
954
|
-
discount_calculation_mode: (
|
|
955
|
-
resource_id:
|
|
956
|
-
title:
|
|
1326
|
+
discount_card_type: (_G = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
|
|
1327
|
+
fixed_amount: bundleActualDiscountAmount,
|
|
1328
|
+
discount_calculation_mode: (_H = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _H.discount_calculation_mode,
|
|
1329
|
+
resource_id: currentBundleDiscount.id,
|
|
1330
|
+
title: currentBundleDiscount.format_title,
|
|
957
1331
|
original_amount: product.original_price,
|
|
958
1332
|
product_id: product.id,
|
|
959
|
-
percent:
|
|
1333
|
+
percent: currentBundleDiscount.par_value,
|
|
1334
|
+
discount_product_id: currentBundleDiscount.product_id
|
|
960
1335
|
},
|
|
961
1336
|
metadata: {
|
|
962
1337
|
// 🔥 使用唯一的 _id
|
|
963
1338
|
custom_product_bundle_map_id: uniqueId,
|
|
964
|
-
discount_rule_uncheck_flag:
|
|
1339
|
+
discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
965
1340
|
num: product.num || 1,
|
|
966
1341
|
// 🔥 order_level 分摊差值
|
|
967
1342
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
968
1343
|
},
|
|
969
|
-
|
|
1344
|
+
config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config,
|
|
1345
|
+
_num: (product.num || 1) * (((_I = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _I.num) || 1)
|
|
970
1346
|
};
|
|
971
|
-
const appliedProducts = appliedDiscountProducts.get(
|
|
1347
|
+
const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
|
|
972
1348
|
appliedProducts.push(discountDetail);
|
|
973
|
-
appliedDiscountProducts.set(
|
|
1349
|
+
appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
|
|
974
1350
|
processedItems.push({
|
|
975
1351
|
...flatItem,
|
|
976
1352
|
total: targetProductTotal,
|
|
@@ -1055,80 +1431,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1055
1431
|
const mainProduct = mainProductArr[0];
|
|
1056
1432
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1057
1433
|
const newBundleWithDiscount = [];
|
|
1058
|
-
(product.bundle || []).forEach(
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
product_id: bundleItem.product_id,
|
|
1078
|
-
price: item.price,
|
|
1079
|
-
num: item.num,
|
|
1080
|
-
discount_list: updatedDiscountList2
|
|
1081
|
-
});
|
|
1082
|
-
});
|
|
1083
|
-
} else {
|
|
1084
|
-
const item = processedItems[0];
|
|
1085
|
-
if (item.processed) {
|
|
1086
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1087
|
-
var _a;
|
|
1088
|
-
return {
|
|
1089
|
-
...discount,
|
|
1090
|
-
metadata: {
|
|
1091
|
-
...discount.metadata,
|
|
1092
|
-
num: item.num,
|
|
1093
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1434
|
+
(product.bundle || []).forEach(
|
|
1435
|
+
(bundleItem, bundleIndex) => {
|
|
1436
|
+
const processedItems = bundleProcessingInfo.get(
|
|
1437
|
+
bundleIndex
|
|
1438
|
+
) || [bundleItem];
|
|
1439
|
+
if (processedItems.length > 1) {
|
|
1440
|
+
processedItems.forEach((item) => {
|
|
1441
|
+
const updatedDiscountList2 = (item.discount_list || []).map(
|
|
1442
|
+
(discount) => {
|
|
1443
|
+
var _a;
|
|
1444
|
+
return {
|
|
1445
|
+
...discount,
|
|
1446
|
+
metadata: {
|
|
1447
|
+
...discount.metadata,
|
|
1448
|
+
num: item.num,
|
|
1449
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1450
|
+
}
|
|
1451
|
+
// num: item.num, // 使用拆分后的 num
|
|
1452
|
+
};
|
|
1094
1453
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1454
|
+
);
|
|
1455
|
+
newBundleWithDiscount.push({
|
|
1456
|
+
...bundleItem,
|
|
1457
|
+
_id: item._id,
|
|
1458
|
+
product_id: bundleItem.product_id,
|
|
1459
|
+
price: item.price,
|
|
1460
|
+
num: item.num,
|
|
1461
|
+
quantity: item.num,
|
|
1462
|
+
discount_list: updatedDiscountList2
|
|
1463
|
+
});
|
|
1105
1464
|
});
|
|
1106
1465
|
} else {
|
|
1107
|
-
|
|
1466
|
+
const item = processedItems[0];
|
|
1467
|
+
if (item.processed) {
|
|
1468
|
+
const updatedDiscountList2 = (item.discount_list || []).map(
|
|
1469
|
+
(discount) => {
|
|
1470
|
+
var _a;
|
|
1471
|
+
return {
|
|
1472
|
+
...discount,
|
|
1473
|
+
metadata: {
|
|
1474
|
+
...discount.metadata,
|
|
1475
|
+
num: item.num,
|
|
1476
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1477
|
+
}
|
|
1478
|
+
// num: item.num, // 使用当前的 num
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
);
|
|
1482
|
+
newBundleWithDiscount.push({
|
|
1483
|
+
...bundleItem,
|
|
1484
|
+
_id: item._id,
|
|
1485
|
+
product_id: bundleItem.product_id,
|
|
1486
|
+
price: item.price,
|
|
1487
|
+
num: item.num,
|
|
1488
|
+
quantity: item.num,
|
|
1489
|
+
discount_list: updatedDiscountList2
|
|
1490
|
+
});
|
|
1491
|
+
} else {
|
|
1492
|
+
newBundleWithDiscount.push(item);
|
|
1493
|
+
}
|
|
1108
1494
|
}
|
|
1109
1495
|
}
|
|
1110
|
-
|
|
1496
|
+
);
|
|
1111
1497
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
1112
|
-
let newOriginTotalWithDiscount = Number(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
// num: 1,
|
|
1121
|
-
metadata: {
|
|
1122
|
-
...discount.metadata,
|
|
1123
|
-
custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
|
|
1124
|
-
num: 1
|
|
1498
|
+
let newOriginTotalWithDiscount = Number(
|
|
1499
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1500
|
+
);
|
|
1501
|
+
const updatedMainDiscountList = mainProductData.discount_list.map(
|
|
1502
|
+
(discount) => {
|
|
1503
|
+
var _a, _b;
|
|
1504
|
+
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
1505
|
+
return discount;
|
|
1125
1506
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1507
|
+
return {
|
|
1508
|
+
...discount,
|
|
1509
|
+
// num: 1,
|
|
1510
|
+
metadata: {
|
|
1511
|
+
...discount.metadata,
|
|
1512
|
+
custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
|
|
1513
|
+
num: 1
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
);
|
|
1518
|
+
const mainDiscountList = updatedMainDiscountList.filter(
|
|
1519
|
+
(item) => {
|
|
1520
|
+
var _a;
|
|
1521
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1522
|
+
}
|
|
1523
|
+
);
|
|
1132
1524
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1133
1525
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
1134
1526
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -1158,20 +1550,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1158
1550
|
quantity: 1,
|
|
1159
1551
|
discount_list: updatedMainDiscountList,
|
|
1160
1552
|
bundle: newBundleWithDiscount,
|
|
1161
|
-
total:
|
|
1162
|
-
origin_total:
|
|
1553
|
+
total: newTotalWithDiscount,
|
|
1554
|
+
origin_total: newOriginTotalWithDiscount
|
|
1163
1555
|
})
|
|
1164
1556
|
);
|
|
1165
1557
|
if (mainProductQuantity > 1) {
|
|
1166
1558
|
const newBundleOriginal = [];
|
|
1167
|
-
(product.bundle || []).forEach(
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1559
|
+
(product.bundle || []).forEach(
|
|
1560
|
+
(bundleItem, bundleIndex) => {
|
|
1561
|
+
newBundleOriginal.push({
|
|
1562
|
+
...bundleItem,
|
|
1563
|
+
discount_list: []
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
);
|
|
1173
1567
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
1174
|
-
let newOriginTotalOriginal = Number(
|
|
1568
|
+
let newOriginTotalOriginal = Number(
|
|
1569
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1570
|
+
);
|
|
1175
1571
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
1176
1572
|
var _a, _b;
|
|
1177
1573
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -1187,12 +1583,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1187
1583
|
// num: mainProductQuantity - 1,
|
|
1188
1584
|
};
|
|
1189
1585
|
});
|
|
1190
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1586
|
+
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1587
|
+
(item) => {
|
|
1588
|
+
var _a;
|
|
1589
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1590
|
+
}
|
|
1591
|
+
);
|
|
1194
1592
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
1195
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1593
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1594
|
+
mainDiscountListOriginal
|
|
1595
|
+
);
|
|
1196
1596
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
1197
1597
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
1198
1598
|
}
|
|
@@ -1229,59 +1629,67 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1229
1629
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1230
1630
|
const newBundle = [];
|
|
1231
1631
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
1232
|
-
product.bundle.forEach(
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1632
|
+
product.bundle.forEach(
|
|
1633
|
+
(bundleItem, bundleIndex) => {
|
|
1634
|
+
const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
|
|
1635
|
+
const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
|
|
1636
|
+
if (!processedBundleItems || processedBundleItems.length === 0) {
|
|
1637
|
+
newBundle.push(bundleItem);
|
|
1638
|
+
} else {
|
|
1639
|
+
processedBundleItems.forEach((item) => {
|
|
1640
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1641
|
+
var _a2;
|
|
1642
|
+
return {
|
|
1643
|
+
...discount,
|
|
1644
|
+
metadata: {
|
|
1645
|
+
...discount.metadata,
|
|
1646
|
+
num: item.num,
|
|
1647
|
+
custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
|
|
1648
|
+
}
|
|
1649
|
+
// num: item.num, // 使用拆分后的 num
|
|
1650
|
+
};
|
|
1651
|
+
});
|
|
1652
|
+
newBundle.push({
|
|
1653
|
+
...bundleItem,
|
|
1654
|
+
_id: item._id,
|
|
1655
|
+
product_id: bundleItem.product_id,
|
|
1656
|
+
price: item.price,
|
|
1657
|
+
num: item.num,
|
|
1658
|
+
quantity: item.num,
|
|
1659
|
+
discount_list: updatedDiscountList2
|
|
1660
|
+
});
|
|
1250
1661
|
});
|
|
1251
|
-
|
|
1252
|
-
...bundleItem,
|
|
1253
|
-
_id: item._id,
|
|
1254
|
-
product_id: bundleItem.product_id,
|
|
1255
|
-
price: item.price,
|
|
1256
|
-
num: item.num,
|
|
1257
|
-
discount_list: updatedDiscountList2
|
|
1258
|
-
});
|
|
1259
|
-
});
|
|
1662
|
+
}
|
|
1260
1663
|
}
|
|
1261
|
-
|
|
1664
|
+
);
|
|
1262
1665
|
}
|
|
1263
1666
|
let newTotal = Number(mainProductData.price || 0);
|
|
1264
|
-
let newOriginTotal = Number(
|
|
1265
|
-
|
|
1667
|
+
let newOriginTotal = Number(
|
|
1668
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1669
|
+
);
|
|
1670
|
+
const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(
|
|
1671
|
+
_b,
|
|
1672
|
+
(item) => item.type === "product"
|
|
1673
|
+
)));
|
|
1266
1674
|
if (isManualDiscount) {
|
|
1267
1675
|
newTotal = mainProductData.total ?? newTotal;
|
|
1268
1676
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
1269
1677
|
} else {
|
|
1270
|
-
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1678
|
+
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1679
|
+
(item) => {
|
|
1680
|
+
var _a2;
|
|
1681
|
+
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
1682
|
+
}
|
|
1683
|
+
);
|
|
1274
1684
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1275
1685
|
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
|
|
1276
1686
|
newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
|
|
1277
1687
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
1278
1688
|
}
|
|
1279
1689
|
if (newBundle.length > 0) {
|
|
1280
|
-
newBundle.forEach((item) => {
|
|
1281
|
-
newTotal += Number(item.price) * Number(item.num);
|
|
1282
|
-
});
|
|
1283
1690
|
newBundle.forEach((item) => {
|
|
1284
1691
|
var _a2, _b2, _c2;
|
|
1692
|
+
newTotal += Number(item.price) * Number(item.num);
|
|
1285
1693
|
const originalPrice = ((_c2 = (_b2 = (_a2 = item.discount_list) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.discount) == null ? void 0 : _c2.original_amount) || item.price;
|
|
1286
1694
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
1287
1695
|
});
|
|
@@ -1294,8 +1702,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1294
1702
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
1295
1703
|
}, new import_decimal.default(newTotal)).toNumber();
|
|
1296
1704
|
}
|
|
1297
|
-
newTotal = new import_decimal.default(newTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
1298
|
-
newOriginTotal = new import_decimal.default(newOriginTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
1299
1705
|
result.push(
|
|
1300
1706
|
this.hooks.setProduct(mainProduct, {
|
|
1301
1707
|
...mainProductData,
|