@pisell/pisellos 2.2.37 → 2.2.39
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 +15 -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/Rules/index.d.ts +8 -3
- package/dist/modules/Rules/index.js +143 -23
- 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/Checkout/index.js +3 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +13 -3
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- 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 +15 -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/Rules/index.d.ts +8 -3
- package/lib/modules/Rules/index.js +352 -187
- 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/Checkout/index.js +3 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +8 -2
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -36,8 +36,8 @@ var import_BaseModule = require("../BaseModule");
|
|
|
36
36
|
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
37
37
|
var import_utils2 = require("../Cart/utils");
|
|
38
38
|
var import_decimal = __toESM(require("decimal.js"));
|
|
39
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
40
39
|
var import_lodash_es = require("lodash-es");
|
|
40
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
41
41
|
var import_utils3 = require("../../solution/ShopDiscount/utils");
|
|
42
42
|
var import_utils4 = require("../../solution/ShopDiscount/utils");
|
|
43
43
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
@@ -51,6 +51,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
51
51
|
this.core = core;
|
|
52
52
|
this.hooks = options == null ? void 0 : options.hooks;
|
|
53
53
|
this.store = options == null ? void 0 : options.store;
|
|
54
|
+
this.window = core.getPlugin("window");
|
|
54
55
|
}
|
|
55
56
|
async setRulesList(rulesList) {
|
|
56
57
|
this.store.rulesList = rulesList;
|
|
@@ -59,6 +60,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
59
60
|
getRulesList() {
|
|
60
61
|
return this.store.rulesList;
|
|
61
62
|
}
|
|
63
|
+
getWalletPassEvaluator() {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
|
|
66
|
+
}
|
|
62
67
|
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
63
68
|
checkHolderMatch(discount, product, holders) {
|
|
64
69
|
var _a;
|
|
@@ -77,6 +82,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
77
82
|
oldDiscountList,
|
|
78
83
|
newDiscountList,
|
|
79
84
|
productList,
|
|
85
|
+
orderTotalAmount,
|
|
80
86
|
holders,
|
|
81
87
|
isFormSubject
|
|
82
88
|
}) {
|
|
@@ -98,19 +104,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
98
104
|
productList
|
|
99
105
|
};
|
|
100
106
|
}
|
|
101
|
-
const filteredOldDiscountList = oldDiscountList.filter(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
const filteredOldDiscountList = oldDiscountList.filter(
|
|
108
|
+
(discount) => !discount.isEditMode && discount.tag !== "good_pass"
|
|
109
|
+
);
|
|
110
|
+
const mergedDiscountList = (0, import_utils.uniqueById)(
|
|
111
|
+
(0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
|
|
112
|
+
"product_id"
|
|
113
|
+
);
|
|
114
|
+
const result = this.calcDiscount(
|
|
115
|
+
{
|
|
116
|
+
discountList: mergedDiscountList,
|
|
117
|
+
productList: [...productList],
|
|
118
|
+
orderTotalAmount,
|
|
119
|
+
holders,
|
|
120
|
+
isFormSubject
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
scan: true
|
|
124
|
+
}
|
|
125
|
+
);
|
|
114
126
|
let hasApplicableDiscount = false;
|
|
115
127
|
const newDiscountIds = newDiscountList.map((discount) => discount.id);
|
|
116
128
|
result.productList.forEach((product) => {
|
|
@@ -141,7 +153,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
141
153
|
discountList,
|
|
142
154
|
productList,
|
|
143
155
|
holders,
|
|
144
|
-
isFormSubject
|
|
156
|
+
isFormSubject,
|
|
157
|
+
orderTotalAmount
|
|
145
158
|
}, options) {
|
|
146
159
|
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
147
160
|
const editModeDiscount = [];
|
|
@@ -319,7 +332,50 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
319
332
|
}
|
|
320
333
|
return priceB.minus(priceA).toNumber();
|
|
321
334
|
});
|
|
335
|
+
const evaluator = this.getWalletPassEvaluator();
|
|
336
|
+
if (evaluator) {
|
|
337
|
+
addModeDiscount.forEach((discount) => {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
const discountType = discount.tag || discount.type;
|
|
340
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
341
|
+
discountType
|
|
342
|
+
)) {
|
|
343
|
+
const voucher = {
|
|
344
|
+
id: discount.id,
|
|
345
|
+
amount: Number(discount.par_value || 0),
|
|
346
|
+
balance: Number(discount.balance || 0),
|
|
347
|
+
type: discountType,
|
|
348
|
+
product_id: discount.product_id,
|
|
349
|
+
unified_available_status: 1,
|
|
350
|
+
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
351
|
+
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
352
|
+
};
|
|
353
|
+
const productsForEvaluate = sortedFlattenedList.map((item) => ({
|
|
354
|
+
product_id: item.id,
|
|
355
|
+
price: item.price || 0,
|
|
356
|
+
quantity: item.quantity || item.num || 1,
|
|
357
|
+
selling_price: item.price || 0
|
|
358
|
+
}));
|
|
359
|
+
const result = evaluator.checkVoucherAvailability({
|
|
360
|
+
orderTotalAmount,
|
|
361
|
+
products: productsForEvaluate,
|
|
362
|
+
vouchers: [voucher]
|
|
363
|
+
});
|
|
364
|
+
if (result.isAvailable) {
|
|
365
|
+
discount.config = {
|
|
366
|
+
...result.config,
|
|
367
|
+
isAvailable: true
|
|
368
|
+
};
|
|
369
|
+
} else {
|
|
370
|
+
discount.config = {
|
|
371
|
+
isAvailable: false
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
322
377
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
378
|
+
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
323
379
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
324
380
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
325
381
|
addModeDiscount.forEach((discount) => {
|
|
@@ -472,7 +528,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
472
528
|
originProduct = flatItem.originProduct;
|
|
473
529
|
}
|
|
474
530
|
addModeDiscount.forEach((discount) => {
|
|
475
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
531
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
476
532
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
477
533
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
478
534
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -485,7 +541,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
485
541
|
);
|
|
486
542
|
let timeLimit = true;
|
|
487
543
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
488
|
-
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
544
|
+
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;
|
|
489
545
|
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(
|
|
490
546
|
(discount2) => discount2.id && [
|
|
491
547
|
"good_pass",
|
|
@@ -494,8 +550,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
494
550
|
].includes(discount2.tag || discount2.type)
|
|
495
551
|
))) : !((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)));
|
|
496
552
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
497
|
-
if (isAvailableProduct && isLimitedProduct && isBundleAvailable &&
|
|
498
|
-
(
|
|
553
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_g = discount.config) == null ? void 0 : _g.isAvailable)) {
|
|
554
|
+
(_h = discountApplicability.get(discount.id)) == null ? void 0 : _h.push(product.id);
|
|
499
555
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
500
556
|
const discountType = discount.tag || discount.type;
|
|
501
557
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -505,14 +561,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
505
561
|
type: discountType,
|
|
506
562
|
tag: discountType,
|
|
507
563
|
discount: {
|
|
508
|
-
discount_card_type: (
|
|
564
|
+
discount_card_type: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_card_type,
|
|
509
565
|
fixed_amount: product.price,
|
|
510
|
-
discount_calculation_mode: (
|
|
566
|
+
discount_calculation_mode: (_j = discount == null ? void 0 : discount.metadata) == null ? void 0 : _j.discount_calculation_mode,
|
|
511
567
|
resource_id: discount.id,
|
|
512
568
|
title: discount.format_title,
|
|
513
569
|
original_amount: product.price || product.origin_total,
|
|
514
570
|
pre_value: discount.par_value,
|
|
515
|
-
product_id: originProduct.id
|
|
571
|
+
product_id: originProduct.id,
|
|
572
|
+
discount_product_id: discount.product_id
|
|
516
573
|
},
|
|
517
574
|
metadata: {
|
|
518
575
|
num
|
|
@@ -546,22 +603,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
546
603
|
};
|
|
547
604
|
originProduct = flatItem.originProduct;
|
|
548
605
|
}
|
|
549
|
-
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(
|
|
606
|
+
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(
|
|
607
|
+
(discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
|
|
608
|
+
discount.tag || discount.type
|
|
609
|
+
)
|
|
610
|
+
))) {
|
|
550
611
|
if (flatItem.type === "main") {
|
|
551
612
|
processedProductsMap.set(product._id, [originProduct]);
|
|
552
613
|
} else {
|
|
553
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
614
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
615
|
+
{
|
|
616
|
+
...flatItem,
|
|
617
|
+
processed: true
|
|
618
|
+
}
|
|
619
|
+
]);
|
|
557
620
|
}
|
|
558
621
|
return;
|
|
559
622
|
}
|
|
560
623
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
561
|
-
var _a2, _b2;
|
|
562
|
-
|
|
624
|
+
var _a2, _b2, _c2, _d2;
|
|
625
|
+
const discountType = discount.tag || discount.type;
|
|
626
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
627
|
+
discountType
|
|
628
|
+
)) {
|
|
629
|
+
if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
|
|
563
634
|
return false;
|
|
564
|
-
if ((Number(product.price) <= 0 || !product.price) && !((
|
|
635
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
|
|
565
636
|
var _a3;
|
|
566
637
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
567
638
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -569,6 +640,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
569
640
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
570
641
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
571
642
|
return false;
|
|
643
|
+
if ((discount.tag || discount.type) === "good_pass") {
|
|
644
|
+
const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
|
|
645
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
646
|
+
const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
647
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
572
652
|
const limitedData = discount.limited_relation_product_data;
|
|
573
653
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
574
654
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -587,6 +667,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
587
667
|
return false;
|
|
588
668
|
}
|
|
589
669
|
if (limitedData.type === "product_all") {
|
|
670
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
590
673
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
591
674
|
return false;
|
|
592
675
|
}
|
|
@@ -599,66 +682,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
599
682
|
}
|
|
600
683
|
return false;
|
|
601
684
|
});
|
|
602
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
685
|
+
const selectedDiscountCard = applicableDiscounts.find(
|
|
686
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
687
|
+
);
|
|
603
688
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
604
689
|
let isManualDiscount = false;
|
|
605
690
|
if (flatItem.type === "main") {
|
|
606
|
-
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
691
|
+
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
692
|
+
(item) => {
|
|
693
|
+
var _a2;
|
|
694
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
695
|
+
}
|
|
696
|
+
) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(
|
|
697
|
+
_h,
|
|
698
|
+
(item) => item.type === "product"
|
|
699
|
+
)));
|
|
610
700
|
} else {
|
|
611
701
|
const parentProduct = flatItem.parentProduct;
|
|
612
702
|
if (parentProduct) {
|
|
613
|
-
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
703
|
+
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
704
|
+
(item) => {
|
|
705
|
+
var _a2;
|
|
706
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
707
|
+
}
|
|
708
|
+
) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(
|
|
709
|
+
_k,
|
|
710
|
+
(item) => item.type === "product"
|
|
711
|
+
)));
|
|
617
712
|
}
|
|
618
713
|
}
|
|
619
714
|
if (options == null ? void 0 : options.discountId) {
|
|
620
|
-
if (flatItem.type === "main" && ((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
715
|
+
if (flatItem.type === "main" && ((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
716
|
+
(item) => {
|
|
717
|
+
var _a2;
|
|
718
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
719
|
+
}
|
|
720
|
+
))) {
|
|
624
721
|
isManualDiscount = false;
|
|
625
722
|
}
|
|
626
723
|
if (flatItem.type === "bundle") {
|
|
627
|
-
if (((_n = product.discount_list) == null ? void 0 : _n.some(
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
724
|
+
if (((_n = product.discount_list) == null ? void 0 : _n.some(
|
|
725
|
+
(item) => {
|
|
726
|
+
var _a2;
|
|
727
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
728
|
+
}
|
|
729
|
+
)) || ((_p = (_o = flatItem.parentProduct) == null ? void 0 : _o.discount_list) == null ? void 0 : _p.some(
|
|
730
|
+
(item) => {
|
|
731
|
+
var _a2;
|
|
732
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
733
|
+
}
|
|
734
|
+
))) {
|
|
634
735
|
isManualDiscount = false;
|
|
635
736
|
}
|
|
636
737
|
}
|
|
637
738
|
}
|
|
638
739
|
if (options == null ? void 0 : options.selectedList) {
|
|
639
|
-
if (flatItem.type === "main" && ((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
740
|
+
if (flatItem.type === "main" && ((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
741
|
+
(item) => {
|
|
742
|
+
var _a2;
|
|
743
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
744
|
+
(n) => {
|
|
745
|
+
var _a3;
|
|
746
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
747
|
+
}
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
))) {
|
|
646
751
|
isManualDiscount = false;
|
|
647
752
|
}
|
|
648
753
|
if (flatItem.type === "bundle") {
|
|
649
|
-
if (((_r = product.discount_list) == null ? void 0 : _r.some(
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
754
|
+
if (((_r = product.discount_list) == null ? void 0 : _r.some(
|
|
755
|
+
(item) => {
|
|
756
|
+
var _a2;
|
|
757
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
758
|
+
(n) => {
|
|
759
|
+
var _a3;
|
|
760
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
)) || ((_t = (_s = flatItem.parentProduct) == null ? void 0 : _s.discount_list) == null ? void 0 : _t.some(
|
|
765
|
+
(item) => {
|
|
766
|
+
var _a2;
|
|
767
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
768
|
+
(n) => {
|
|
769
|
+
var _a3;
|
|
770
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
))) {
|
|
662
775
|
isManualDiscount = false;
|
|
663
776
|
}
|
|
664
777
|
}
|
|
@@ -666,9 +779,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
666
779
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
667
780
|
if (flatItem.type === "main") {
|
|
668
781
|
if (product.isClient) {
|
|
669
|
-
processedProductsMap.set(
|
|
670
|
-
|
|
671
|
-
[this.hooks.setProduct(originProduct, {
|
|
782
|
+
processedProductsMap.set(product._id, [
|
|
783
|
+
this.hooks.setProduct(originProduct, {
|
|
672
784
|
...isManualDiscount ? {} : {
|
|
673
785
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
674
786
|
product: {
|
|
@@ -689,12 +801,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
689
801
|
price: product.price
|
|
690
802
|
},
|
|
691
803
|
discount_list: []
|
|
692
|
-
})
|
|
693
|
-
);
|
|
804
|
+
})
|
|
805
|
+
]);
|
|
694
806
|
} else {
|
|
695
|
-
processedProductsMap.set(
|
|
696
|
-
|
|
697
|
-
[this.hooks.setProduct(originProduct, {
|
|
807
|
+
processedProductsMap.set(product._id, [
|
|
808
|
+
this.hooks.setProduct(originProduct, {
|
|
698
809
|
...isManualDiscount ? {
|
|
699
810
|
price: product.price,
|
|
700
811
|
main_product_selling_price: product.price
|
|
@@ -705,8 +816,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
705
816
|
main_product_selling_price: product.price
|
|
706
817
|
},
|
|
707
818
|
discount_list: []
|
|
708
|
-
})
|
|
709
|
-
);
|
|
819
|
+
})
|
|
820
|
+
]);
|
|
710
821
|
}
|
|
711
822
|
} else {
|
|
712
823
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
@@ -723,20 +834,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
723
834
|
}
|
|
724
835
|
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
725
836
|
const totalQuantity = product.quantity || product.num || 1;
|
|
726
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
727
|
-
|
|
837
|
+
const availableGoodPassCount = applicableDiscounts.filter(
|
|
838
|
+
(item) => (item.tag || item.type) === "good_pass"
|
|
839
|
+
).length;
|
|
840
|
+
let maxUsageLimit = availableGoodPassCount;
|
|
841
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
842
|
+
maxUsageLimit = Math.min(
|
|
843
|
+
availableGoodPassCount,
|
|
844
|
+
selectedDiscount.config.maxUsagePerOrder
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
728
848
|
const arr = [];
|
|
729
849
|
if (flatItem.type === "main") {
|
|
730
850
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
731
|
-
arr.push(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
851
|
+
arr.push(
|
|
852
|
+
this.hooks.setProduct(originProduct, {
|
|
853
|
+
discount_list: [],
|
|
854
|
+
quantity: totalQuantity - splitCount,
|
|
855
|
+
_id: product._id.split("___")[0],
|
|
856
|
+
total: product.origin_total || product.total
|
|
857
|
+
})
|
|
858
|
+
);
|
|
736
859
|
}
|
|
737
860
|
for (let i = 0; i < splitCount; i++) {
|
|
738
861
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
739
862
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
863
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
864
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
865
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
866
|
+
}
|
|
740
867
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
741
868
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
742
869
|
if (((_u = product.discount_list) == null ? void 0 : _u.length) && product.origin_total) {
|
|
@@ -772,10 +899,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
772
899
|
title: selectedDiscount2.format_title,
|
|
773
900
|
original_amount: product.price,
|
|
774
901
|
product_id: originProduct.id,
|
|
775
|
-
percent: selectedDiscount2.par_value
|
|
902
|
+
percent: selectedDiscount2.par_value,
|
|
903
|
+
discount_product_id: selectedDiscount2.product_id
|
|
776
904
|
},
|
|
777
905
|
// 前端使用的num数量,为了计算优惠金额
|
|
778
906
|
_num: isGoodPass ? 1 : product.num,
|
|
907
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
779
908
|
metadata: {
|
|
780
909
|
num: 1,
|
|
781
910
|
// 🔥 order_level 分摊差值
|
|
@@ -793,32 +922,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
793
922
|
}, new import_decimal.default(total)).toNumber();
|
|
794
923
|
}
|
|
795
924
|
if (product.isClient) {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
925
|
+
arr.push(
|
|
926
|
+
this.hooks.setProduct(originProduct, {
|
|
927
|
+
discount_list: [discountDetail],
|
|
928
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
929
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
930
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
931
|
+
product: {
|
|
932
|
+
original_price: product.original_price
|
|
933
|
+
},
|
|
934
|
+
bundle: product.bundle,
|
|
935
|
+
options: product.options
|
|
936
|
+
}),
|
|
937
|
+
variant: originProduct._productInit.variant,
|
|
938
|
+
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
939
|
+
total
|
|
940
|
+
})
|
|
941
|
+
);
|
|
812
942
|
} else {
|
|
813
|
-
arr.push(
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
943
|
+
arr.push(
|
|
944
|
+
this.hooks.setProduct(originProduct, {
|
|
945
|
+
discount_list: [discountDetail],
|
|
946
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
|
|
947
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
948
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
949
|
+
total,
|
|
950
|
+
origin_total: productOriginTotal,
|
|
951
|
+
main_product_selling_price: targetProductTotal
|
|
952
|
+
})
|
|
953
|
+
);
|
|
822
954
|
}
|
|
823
955
|
}
|
|
824
956
|
processedProductsMap.set(product._id, arr);
|
|
@@ -830,9 +962,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
830
962
|
for (let i = 0; i < discountNum; i++) {
|
|
831
963
|
const selectedDiscount2 = applicableDiscounts[i];
|
|
832
964
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
965
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
966
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
967
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
968
|
+
}
|
|
833
969
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
970
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(
|
|
971
|
+
selectedDiscount2,
|
|
972
|
+
product.origin_total,
|
|
973
|
+
product.origin_total
|
|
974
|
+
);
|
|
975
|
+
const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
834
976
|
const discountDetail = {
|
|
835
|
-
amount:
|
|
977
|
+
amount: bundleDiscountAmount,
|
|
836
978
|
type: "good_pass",
|
|
837
979
|
discount: {
|
|
838
980
|
fixed_amount: product.origin_total,
|
|
@@ -840,14 +982,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
840
982
|
resource_id: selectedDiscount2.id,
|
|
841
983
|
title: selectedDiscount2.format_title,
|
|
842
984
|
original_amount: product.origin_total,
|
|
843
|
-
product_id: product.id
|
|
985
|
+
product_id: product.id,
|
|
986
|
+
discount_product_id: selectedDiscount2.product_id
|
|
844
987
|
},
|
|
845
988
|
metadata: {
|
|
846
989
|
// 🔥 使用拆分后的唯一 _id
|
|
847
990
|
custom_product_bundle_map_id: uniqueId,
|
|
848
991
|
num: 1
|
|
849
992
|
},
|
|
850
|
-
_num: 1
|
|
993
|
+
_num: 1,
|
|
994
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
|
|
851
995
|
};
|
|
852
996
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
853
997
|
appliedProducts.push(discountDetail);
|
|
@@ -858,9 +1002,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
858
1002
|
_id: uniqueId,
|
|
859
1003
|
num: 1,
|
|
860
1004
|
quantity: 1,
|
|
861
|
-
price:
|
|
862
|
-
//
|
|
863
|
-
total:
|
|
1005
|
+
price: discountedPrice,
|
|
1006
|
+
// 折扣后的价格
|
|
1007
|
+
total: discountedPrice,
|
|
864
1008
|
discount_list: [discountDetail],
|
|
865
1009
|
processed: true,
|
|
866
1010
|
_discountId: selectedDiscount2.id
|
|
@@ -880,6 +1024,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
880
1024
|
} else {
|
|
881
1025
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
882
1026
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
1027
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
1028
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
1029
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
1030
|
+
}
|
|
883
1031
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
884
1032
|
const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
|
|
885
1033
|
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
|
|
@@ -899,7 +1047,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
899
1047
|
);
|
|
900
1048
|
fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
901
1049
|
}
|
|
902
|
-
debugger;
|
|
903
1050
|
const uniqueId = flatItem._id;
|
|
904
1051
|
const discountDetail = {
|
|
905
1052
|
amount: fixedAmountPerItem * (product.num || 1),
|
|
@@ -912,7 +1059,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
912
1059
|
title: selectedDiscount2.format_title,
|
|
913
1060
|
original_amount: product.original_price,
|
|
914
1061
|
product_id: product.id,
|
|
915
|
-
percent: selectedDiscount2.par_value
|
|
1062
|
+
percent: selectedDiscount2.par_value,
|
|
1063
|
+
discount_product_id: selectedDiscount2.product_id
|
|
916
1064
|
},
|
|
917
1065
|
metadata: {
|
|
918
1066
|
// 🔥 使用唯一的 _id
|
|
@@ -921,6 +1069,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
921
1069
|
// 🔥 order_level 分摊差值
|
|
922
1070
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
923
1071
|
},
|
|
1072
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
924
1073
|
_num: (product.num || 1) * (((_B = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _B.num) || 1)
|
|
925
1074
|
};
|
|
926
1075
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
@@ -1010,61 +1159,67 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1010
1159
|
const mainProduct = mainProductArr[0];
|
|
1011
1160
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1012
1161
|
const newBundleWithDiscount = [];
|
|
1013
|
-
(product.bundle || []).forEach(
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
if (item.processed) {
|
|
1041
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1042
|
-
var _a;
|
|
1043
|
-
return {
|
|
1044
|
-
...discount,
|
|
1045
|
-
metadata: {
|
|
1046
|
-
...discount.metadata,
|
|
1047
|
-
num: item.num,
|
|
1048
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1049
|
-
}
|
|
1050
|
-
// num: item.num, // 使用当前的 num
|
|
1051
|
-
};
|
|
1052
|
-
});
|
|
1053
|
-
newBundleWithDiscount.push({
|
|
1054
|
-
...bundleItem,
|
|
1055
|
-
_id: item._id,
|
|
1056
|
-
product_id: bundleItem.product_id,
|
|
1057
|
-
price: item.price,
|
|
1058
|
-
num: item.num,
|
|
1059
|
-
discount_list: updatedDiscountList2
|
|
1162
|
+
(product.bundle || []).forEach(
|
|
1163
|
+
(bundleItem, bundleIndex) => {
|
|
1164
|
+
const processedItems = bundleProcessingInfo.get(
|
|
1165
|
+
bundleIndex
|
|
1166
|
+
) || [bundleItem];
|
|
1167
|
+
if (processedItems.length > 1) {
|
|
1168
|
+
processedItems.forEach((item) => {
|
|
1169
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1170
|
+
var _a;
|
|
1171
|
+
return {
|
|
1172
|
+
...discount,
|
|
1173
|
+
metadata: {
|
|
1174
|
+
...discount.metadata,
|
|
1175
|
+
num: item.num,
|
|
1176
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1177
|
+
}
|
|
1178
|
+
// num: item.num, // 使用拆分后的 num
|
|
1179
|
+
};
|
|
1180
|
+
});
|
|
1181
|
+
newBundleWithDiscount.push({
|
|
1182
|
+
...bundleItem,
|
|
1183
|
+
_id: item._id,
|
|
1184
|
+
product_id: bundleItem.product_id,
|
|
1185
|
+
price: item.price,
|
|
1186
|
+
num: item.num,
|
|
1187
|
+
discount_list: updatedDiscountList2
|
|
1188
|
+
});
|
|
1060
1189
|
});
|
|
1061
1190
|
} else {
|
|
1062
|
-
|
|
1191
|
+
const item = processedItems[0];
|
|
1192
|
+
if (item.processed) {
|
|
1193
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1194
|
+
var _a;
|
|
1195
|
+
return {
|
|
1196
|
+
...discount,
|
|
1197
|
+
metadata: {
|
|
1198
|
+
...discount.metadata,
|
|
1199
|
+
num: item.num,
|
|
1200
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1201
|
+
}
|
|
1202
|
+
// num: item.num, // 使用当前的 num
|
|
1203
|
+
};
|
|
1204
|
+
});
|
|
1205
|
+
newBundleWithDiscount.push({
|
|
1206
|
+
...bundleItem,
|
|
1207
|
+
_id: item._id,
|
|
1208
|
+
product_id: bundleItem.product_id,
|
|
1209
|
+
price: item.price,
|
|
1210
|
+
num: item.num,
|
|
1211
|
+
discount_list: updatedDiscountList2
|
|
1212
|
+
});
|
|
1213
|
+
} else {
|
|
1214
|
+
newBundleWithDiscount.push(item);
|
|
1215
|
+
}
|
|
1063
1216
|
}
|
|
1064
1217
|
}
|
|
1065
|
-
|
|
1218
|
+
);
|
|
1066
1219
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
1067
|
-
let newOriginTotalWithDiscount = Number(
|
|
1220
|
+
let newOriginTotalWithDiscount = Number(
|
|
1221
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1222
|
+
);
|
|
1068
1223
|
const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
|
|
1069
1224
|
var _a, _b;
|
|
1070
1225
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -1080,10 +1235,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1080
1235
|
}
|
|
1081
1236
|
};
|
|
1082
1237
|
});
|
|
1083
|
-
const mainDiscountList = updatedMainDiscountList.filter(
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1238
|
+
const mainDiscountList = updatedMainDiscountList.filter(
|
|
1239
|
+
(item) => {
|
|
1240
|
+
var _a;
|
|
1241
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1242
|
+
}
|
|
1243
|
+
);
|
|
1087
1244
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1088
1245
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
1089
1246
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -1119,14 +1276,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1119
1276
|
);
|
|
1120
1277
|
if (mainProductQuantity > 1) {
|
|
1121
1278
|
const newBundleOriginal = [];
|
|
1122
|
-
(product.bundle || []).forEach(
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1279
|
+
(product.bundle || []).forEach(
|
|
1280
|
+
(bundleItem, bundleIndex) => {
|
|
1281
|
+
newBundleOriginal.push({
|
|
1282
|
+
...bundleItem,
|
|
1283
|
+
discount_list: []
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
);
|
|
1128
1287
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
1129
|
-
let newOriginTotalOriginal = Number(
|
|
1288
|
+
let newOriginTotalOriginal = Number(
|
|
1289
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1290
|
+
);
|
|
1130
1291
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
1131
1292
|
var _a, _b;
|
|
1132
1293
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -1142,12 +1303,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1142
1303
|
// num: mainProductQuantity - 1,
|
|
1143
1304
|
};
|
|
1144
1305
|
});
|
|
1145
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1306
|
+
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1307
|
+
(item) => {
|
|
1308
|
+
var _a;
|
|
1309
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1310
|
+
}
|
|
1311
|
+
);
|
|
1149
1312
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
1150
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1313
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1314
|
+
mainDiscountListOriginal
|
|
1315
|
+
);
|
|
1151
1316
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
1152
1317
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
1153
1318
|
}
|