@pisell/pisellos 2.1.53 → 2.1.54
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 +496 -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 +163 -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 +155 -29
- 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 +2 -1
- package/dist/solution/Checkout/index.js +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +14 -4
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +26 -11
- 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 +420 -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 +163 -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 +373 -195
- 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 +2 -1
- package/lib/solution/Checkout/index.js +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +9 -3
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +10 -6
- package/package.json +1 -1
|
@@ -49,6 +49,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
49
49
|
this.core = core;
|
|
50
50
|
this.hooks = options == null ? void 0 : options.hooks;
|
|
51
51
|
this.store = options == null ? void 0 : options.store;
|
|
52
|
+
this.window = core.getPlugin("window");
|
|
52
53
|
}
|
|
53
54
|
async setRulesList(rulesList) {
|
|
54
55
|
this.store.rulesList = rulesList;
|
|
@@ -57,6 +58,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
57
58
|
getRulesList() {
|
|
58
59
|
return this.store.rulesList;
|
|
59
60
|
}
|
|
61
|
+
getWalletPassEvaluator() {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
|
|
64
|
+
}
|
|
60
65
|
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
61
66
|
checkHolderMatch(discount, product, holders) {
|
|
62
67
|
var _a;
|
|
@@ -75,7 +80,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
75
80
|
oldDiscountList,
|
|
76
81
|
newDiscountList,
|
|
77
82
|
productList,
|
|
78
|
-
holders
|
|
83
|
+
holders,
|
|
84
|
+
orderTotalAmount
|
|
79
85
|
}) {
|
|
80
86
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
81
87
|
return {
|
|
@@ -95,15 +101,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
95
101
|
productList
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
|
-
const filteredOldDiscountList = oldDiscountList.filter(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
const filteredOldDiscountList = oldDiscountList.filter(
|
|
105
|
+
(discount) => !discount.isEditMode && discount.tag !== "good_pass"
|
|
106
|
+
);
|
|
107
|
+
const mergedDiscountList = (0, import_utils.uniqueById)(
|
|
108
|
+
(0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
|
|
109
|
+
"product_id"
|
|
110
|
+
);
|
|
103
111
|
const result = this.calcDiscount({
|
|
104
112
|
discountList: mergedDiscountList,
|
|
105
113
|
productList: [...productList],
|
|
106
|
-
holders
|
|
114
|
+
holders,
|
|
115
|
+
orderTotalAmount
|
|
107
116
|
}, {
|
|
108
117
|
scan: true
|
|
109
118
|
});
|
|
@@ -136,7 +145,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
136
145
|
calcDiscount({
|
|
137
146
|
discountList,
|
|
138
147
|
productList,
|
|
139
|
-
holders
|
|
148
|
+
holders,
|
|
149
|
+
orderTotalAmount
|
|
140
150
|
}, options) {
|
|
141
151
|
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
142
152
|
const editModeDiscount = [];
|
|
@@ -256,7 +266,50 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
256
266
|
}
|
|
257
267
|
return priceB.minus(priceA).toNumber();
|
|
258
268
|
});
|
|
269
|
+
const evaluator = this.getWalletPassEvaluator();
|
|
270
|
+
if (evaluator) {
|
|
271
|
+
addModeDiscount.forEach((discount) => {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
const discountType = discount.tag || discount.type;
|
|
274
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
275
|
+
discountType
|
|
276
|
+
)) {
|
|
277
|
+
const voucher = {
|
|
278
|
+
id: discount.id,
|
|
279
|
+
amount: Number(discount.par_value || 0),
|
|
280
|
+
balance: Number(discount.balance || 0),
|
|
281
|
+
type: discountType,
|
|
282
|
+
product_id: discount.product_id,
|
|
283
|
+
unified_available_status: 1,
|
|
284
|
+
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
285
|
+
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
286
|
+
};
|
|
287
|
+
const productsForEvaluate = sortedFlattenedList.map((item) => ({
|
|
288
|
+
product_id: item.id,
|
|
289
|
+
price: item.price || 0,
|
|
290
|
+
quantity: item.quantity || item.num || 1,
|
|
291
|
+
selling_price: item.price || 0
|
|
292
|
+
}));
|
|
293
|
+
const result = evaluator.checkVoucherAvailability({
|
|
294
|
+
orderTotalAmount,
|
|
295
|
+
products: productsForEvaluate,
|
|
296
|
+
vouchers: [voucher]
|
|
297
|
+
});
|
|
298
|
+
if (result.isAvailable) {
|
|
299
|
+
discount.config = {
|
|
300
|
+
...result.config,
|
|
301
|
+
isAvailable: true
|
|
302
|
+
};
|
|
303
|
+
} else {
|
|
304
|
+
discount.config = {
|
|
305
|
+
isAvailable: false
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
259
311
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
312
|
+
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
260
313
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
261
314
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
262
315
|
addModeDiscount.forEach((discount) => {
|
|
@@ -285,7 +338,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
285
338
|
originProduct = flatItem.originProduct;
|
|
286
339
|
}
|
|
287
340
|
addModeDiscount.forEach((discount) => {
|
|
288
|
-
var _a, _b, _c, _d, _e, _f;
|
|
341
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
289
342
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
290
343
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
291
344
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -298,11 +351,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
298
351
|
);
|
|
299
352
|
let timeLimit = true;
|
|
300
353
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
301
|
-
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
302
|
-
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
|
|
354
|
+
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;
|
|
355
|
+
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
|
|
356
|
+
(discount2) => discount2.id && [
|
|
357
|
+
"good_pass",
|
|
358
|
+
"discount_card",
|
|
359
|
+
"product_discount_card"
|
|
360
|
+
].includes(discount2.tag || discount2.type)
|
|
361
|
+
))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
|
|
303
362
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
304
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
305
|
-
(
|
|
363
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_e = discount.config) == null ? void 0 : _e.isAvailable)) {
|
|
364
|
+
(_f = discountApplicability.get(discount.id)) == null ? void 0 : _f.push(product.id);
|
|
306
365
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
307
366
|
const discountType = discount.tag || discount.type;
|
|
308
367
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -312,13 +371,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
312
371
|
type: discountType,
|
|
313
372
|
tag: discountType,
|
|
314
373
|
discount: {
|
|
315
|
-
discount_card_type: (
|
|
374
|
+
discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
|
|
316
375
|
fixed_amount: product.price,
|
|
317
376
|
resource_id: discount.id,
|
|
318
377
|
title: discount.format_title,
|
|
319
378
|
original_amount: product.price || product.origin_total,
|
|
320
379
|
pre_value: discount.par_value,
|
|
321
|
-
product_id: originProduct.id
|
|
380
|
+
product_id: originProduct.id,
|
|
381
|
+
discount_product_id: discount.product_id
|
|
322
382
|
},
|
|
323
383
|
metadata: {
|
|
324
384
|
num
|
|
@@ -351,25 +411,39 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
351
411
|
};
|
|
352
412
|
originProduct = flatItem.originProduct;
|
|
353
413
|
}
|
|
354
|
-
if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every(
|
|
414
|
+
if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every(
|
|
415
|
+
(discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
|
|
416
|
+
discount.tag || discount.type
|
|
417
|
+
)
|
|
418
|
+
))) {
|
|
355
419
|
if (flatItem.type === "main") {
|
|
356
420
|
processedProductsMap.set(product._id, [originProduct]);
|
|
357
421
|
} else {
|
|
358
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
422
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
423
|
+
{
|
|
424
|
+
...flatItem,
|
|
425
|
+
processed: true
|
|
426
|
+
}
|
|
427
|
+
]);
|
|
362
428
|
}
|
|
363
429
|
return;
|
|
364
430
|
}
|
|
365
431
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
366
|
-
var _a2, _b2;
|
|
367
|
-
|
|
432
|
+
var _a2, _b2, _c2, _d2;
|
|
433
|
+
const discountType = discount.tag || discount.type;
|
|
434
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
435
|
+
discountType
|
|
436
|
+
)) {
|
|
437
|
+
if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
|
|
368
442
|
var _a3;
|
|
369
443
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
370
444
|
})) && (discount.tag || discount.type) === "good_pass")
|
|
371
445
|
return false;
|
|
372
|
-
if ((Number(product.price) <= 0 || !product.price) && !((
|
|
446
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
|
|
373
447
|
var _a3;
|
|
374
448
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
375
449
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -377,6 +451,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
377
451
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
378
452
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
379
453
|
return false;
|
|
454
|
+
if ((discount.tag || discount.type) === "good_pass") {
|
|
455
|
+
const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
|
|
456
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
457
|
+
const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
458
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
380
463
|
const limitedData = discount.limited_relation_product_data;
|
|
381
464
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
382
465
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -395,6 +478,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
395
478
|
return false;
|
|
396
479
|
}
|
|
397
480
|
if (limitedData.type === "product_all") {
|
|
481
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
398
484
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
399
485
|
return false;
|
|
400
486
|
}
|
|
@@ -407,66 +493,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
407
493
|
}
|
|
408
494
|
return false;
|
|
409
495
|
});
|
|
410
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
496
|
+
const selectedDiscountCard = applicableDiscounts.find(
|
|
497
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
498
|
+
);
|
|
411
499
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
412
500
|
let isManualDiscount = false;
|
|
413
501
|
if (flatItem.type === "main") {
|
|
414
|
-
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
502
|
+
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
503
|
+
(item) => {
|
|
504
|
+
var _a2;
|
|
505
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
506
|
+
}
|
|
507
|
+
) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(
|
|
508
|
+
_g,
|
|
509
|
+
(item) => item.type === "product"
|
|
510
|
+
)));
|
|
418
511
|
} else {
|
|
419
512
|
const parentProduct = flatItem.parentProduct;
|
|
420
513
|
if (parentProduct) {
|
|
421
|
-
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
514
|
+
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
515
|
+
(item) => {
|
|
516
|
+
var _a2;
|
|
517
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
518
|
+
}
|
|
519
|
+
) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(
|
|
520
|
+
_j,
|
|
521
|
+
(item) => item.type === "product"
|
|
522
|
+
)));
|
|
425
523
|
}
|
|
426
524
|
}
|
|
427
525
|
if (options == null ? void 0 : options.discountId) {
|
|
428
|
-
if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
526
|
+
if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some(
|
|
527
|
+
(item) => {
|
|
528
|
+
var _a2;
|
|
529
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
530
|
+
}
|
|
531
|
+
))) {
|
|
432
532
|
isManualDiscount = false;
|
|
433
533
|
}
|
|
434
534
|
if (flatItem.type === "bundle") {
|
|
435
|
-
if (((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
535
|
+
if (((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
536
|
+
(item) => {
|
|
537
|
+
var _a2;
|
|
538
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
539
|
+
}
|
|
540
|
+
)) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some(
|
|
541
|
+
(item) => {
|
|
542
|
+
var _a2;
|
|
543
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
544
|
+
}
|
|
545
|
+
))) {
|
|
442
546
|
isManualDiscount = false;
|
|
443
547
|
}
|
|
444
548
|
}
|
|
445
549
|
}
|
|
446
550
|
if (options == null ? void 0 : options.selectedList) {
|
|
447
|
-
if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
551
|
+
if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some(
|
|
552
|
+
(item) => {
|
|
553
|
+
var _a2;
|
|
554
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
555
|
+
(n) => {
|
|
556
|
+
var _a3;
|
|
557
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
558
|
+
}
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
))) {
|
|
454
562
|
isManualDiscount = false;
|
|
455
563
|
}
|
|
456
564
|
if (flatItem.type === "bundle") {
|
|
457
|
-
if (((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
565
|
+
if (((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
566
|
+
(item) => {
|
|
567
|
+
var _a2;
|
|
568
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
569
|
+
(n) => {
|
|
570
|
+
var _a3;
|
|
571
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
)) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some(
|
|
576
|
+
(item) => {
|
|
577
|
+
var _a2;
|
|
578
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
579
|
+
(n) => {
|
|
580
|
+
var _a3;
|
|
581
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
582
|
+
}
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
))) {
|
|
470
586
|
isManualDiscount = false;
|
|
471
587
|
}
|
|
472
588
|
}
|
|
@@ -474,9 +590,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
474
590
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
475
591
|
if (flatItem.type === "main") {
|
|
476
592
|
if (product.isClient) {
|
|
477
|
-
processedProductsMap.set(
|
|
478
|
-
|
|
479
|
-
[this.hooks.setProduct(originProduct, {
|
|
593
|
+
processedProductsMap.set(product._id, [
|
|
594
|
+
this.hooks.setProduct(originProduct, {
|
|
480
595
|
...isManualDiscount ? {} : {
|
|
481
596
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
482
597
|
product: {
|
|
@@ -497,12 +612,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
497
612
|
price: product.price
|
|
498
613
|
},
|
|
499
614
|
discount_list: []
|
|
500
|
-
})
|
|
501
|
-
);
|
|
615
|
+
})
|
|
616
|
+
]);
|
|
502
617
|
} else {
|
|
503
|
-
processedProductsMap.set(
|
|
504
|
-
|
|
505
|
-
[this.hooks.setProduct(originProduct, {
|
|
618
|
+
processedProductsMap.set(product._id, [
|
|
619
|
+
this.hooks.setProduct(originProduct, {
|
|
506
620
|
...isManualDiscount ? {
|
|
507
621
|
price: product.price,
|
|
508
622
|
main_product_selling_price: product.price
|
|
@@ -513,8 +627,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
513
627
|
main_product_selling_price: product.price
|
|
514
628
|
},
|
|
515
629
|
discount_list: []
|
|
516
|
-
})
|
|
517
|
-
);
|
|
630
|
+
})
|
|
631
|
+
]);
|
|
518
632
|
}
|
|
519
633
|
} else {
|
|
520
634
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
@@ -531,20 +645,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
531
645
|
}
|
|
532
646
|
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
533
647
|
const totalQuantity = product.quantity || product.num || 1;
|
|
534
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
535
|
-
|
|
648
|
+
const availableGoodPassCount = applicableDiscounts.filter(
|
|
649
|
+
(item) => (item.tag || item.type) === "good_pass"
|
|
650
|
+
).length;
|
|
651
|
+
let maxUsageLimit = availableGoodPassCount;
|
|
652
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
653
|
+
maxUsageLimit = Math.min(
|
|
654
|
+
availableGoodPassCount,
|
|
655
|
+
selectedDiscount.config.maxUsagePerOrder
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
536
659
|
const arr = [];
|
|
537
660
|
if (flatItem.type === "main") {
|
|
538
661
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
539
|
-
arr.push(
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
662
|
+
arr.push(
|
|
663
|
+
this.hooks.setProduct(originProduct, {
|
|
664
|
+
discount_list: [],
|
|
665
|
+
quantity: totalQuantity - splitCount,
|
|
666
|
+
_id: product._id.split("___")[0],
|
|
667
|
+
total: product.origin_total || product.total
|
|
668
|
+
})
|
|
669
|
+
);
|
|
544
670
|
}
|
|
545
671
|
for (let i = 0; i < splitCount; i++) {
|
|
546
672
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
547
673
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
674
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
675
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
676
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
677
|
+
}
|
|
548
678
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
549
679
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
550
680
|
if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
|
|
@@ -553,24 +683,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
553
683
|
if (Number(((_u = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _u.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
554
684
|
productOriginTotal = product.total;
|
|
555
685
|
}
|
|
556
|
-
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
557
|
-
|
|
686
|
+
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
687
|
+
selectedDiscount2,
|
|
688
|
+
product.price,
|
|
689
|
+
product.price
|
|
690
|
+
);
|
|
691
|
+
const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
|
|
692
|
+
const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
558
693
|
const isGoodPass = discountType === "good_pass";
|
|
559
|
-
const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
560
694
|
const discountDetail = {
|
|
561
|
-
amount,
|
|
562
|
-
type:
|
|
695
|
+
amount: actualDiscountAmount,
|
|
696
|
+
type: discountType,
|
|
563
697
|
discount: {
|
|
564
698
|
discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
|
|
565
|
-
fixed_amount:
|
|
699
|
+
fixed_amount: actualDiscountAmount,
|
|
566
700
|
resource_id: selectedDiscount2.id,
|
|
567
701
|
title: selectedDiscount2.format_title,
|
|
568
702
|
original_amount: product.price,
|
|
569
703
|
product_id: originProduct.id,
|
|
570
|
-
percent: selectedDiscount2.par_value
|
|
704
|
+
percent: selectedDiscount2.par_value,
|
|
705
|
+
discount_product_id: selectedDiscount2.product_id
|
|
571
706
|
},
|
|
572
707
|
// 前端使用的num数量,为了计算优惠金额
|
|
573
708
|
_num: isGoodPass ? 1 : product.num,
|
|
709
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
574
710
|
metadata: {
|
|
575
711
|
num: 1
|
|
576
712
|
}
|
|
@@ -586,7 +722,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
586
722
|
}, new import_decimal.default(total)).toNumber();
|
|
587
723
|
}
|
|
588
724
|
if (product.isClient) {
|
|
589
|
-
debugger;
|
|
590
725
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
591
726
|
discount_list: [discountDetail],
|
|
592
727
|
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
@@ -623,23 +758,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
623
758
|
for (let i = 0; i < discountNum; i++) {
|
|
624
759
|
const selectedDiscount2 = applicableDiscounts[i];
|
|
625
760
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
761
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
762
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
763
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
764
|
+
}
|
|
626
765
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
766
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(
|
|
767
|
+
selectedDiscount2,
|
|
768
|
+
product.origin_total,
|
|
769
|
+
product.origin_total
|
|
770
|
+
);
|
|
771
|
+
const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
627
772
|
const discountDetail = {
|
|
628
|
-
amount:
|
|
773
|
+
amount: bundleDiscountAmount,
|
|
629
774
|
type: "good_pass",
|
|
630
775
|
discount: {
|
|
631
776
|
fixed_amount: product.origin_total,
|
|
632
777
|
resource_id: selectedDiscount2.id,
|
|
633
778
|
title: selectedDiscount2.format_title,
|
|
634
779
|
original_amount: product.origin_total,
|
|
635
|
-
product_id: product.id
|
|
780
|
+
product_id: product.id,
|
|
781
|
+
discount_product_id: selectedDiscount2.product_id
|
|
636
782
|
},
|
|
637
783
|
metadata: {
|
|
638
784
|
// 🔥 使用拆分后的唯一 _id
|
|
639
785
|
custom_product_bundle_map_id: uniqueId,
|
|
640
786
|
num: 1
|
|
641
787
|
},
|
|
642
|
-
_num: 1
|
|
788
|
+
_num: 1,
|
|
789
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
|
|
643
790
|
};
|
|
644
791
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
645
792
|
appliedProducts.push(discountDetail);
|
|
@@ -650,9 +797,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
650
797
|
_id: uniqueId,
|
|
651
798
|
num: 1,
|
|
652
799
|
quantity: 1,
|
|
653
|
-
price:
|
|
654
|
-
//
|
|
655
|
-
total:
|
|
800
|
+
price: discountedPrice,
|
|
801
|
+
// 折扣后的价格
|
|
802
|
+
total: discountedPrice,
|
|
656
803
|
discount_list: [discountDetail],
|
|
657
804
|
processed: true,
|
|
658
805
|
_discountId: selectedDiscount2.id
|
|
@@ -672,30 +819,37 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
672
819
|
} else {
|
|
673
820
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
674
821
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
822
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
823
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
824
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
825
|
+
}
|
|
675
826
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
676
827
|
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
677
828
|
selectedDiscount2,
|
|
678
829
|
productOriginTotal,
|
|
679
830
|
productOriginTotal
|
|
680
831
|
);
|
|
832
|
+
const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
681
833
|
const uniqueId = flatItem._id;
|
|
682
834
|
const discountDetail = {
|
|
683
|
-
amount:
|
|
835
|
+
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
684
836
|
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
685
837
|
discount: {
|
|
686
838
|
discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
|
|
687
|
-
fixed_amount:
|
|
839
|
+
fixed_amount: bundleActualDiscountAmount,
|
|
688
840
|
resource_id: selectedDiscount2.id,
|
|
689
841
|
title: selectedDiscount2.format_title,
|
|
690
842
|
original_amount: product.original_price,
|
|
691
843
|
product_id: product.id,
|
|
692
|
-
percent: selectedDiscount2.par_value
|
|
844
|
+
percent: selectedDiscount2.par_value,
|
|
845
|
+
discount_product_id: selectedDiscount2.product_id
|
|
693
846
|
},
|
|
694
847
|
metadata: {
|
|
695
848
|
// 🔥 使用唯一的 _id
|
|
696
849
|
custom_product_bundle_map_id: uniqueId,
|
|
697
850
|
num: product.num || 1
|
|
698
851
|
},
|
|
852
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
699
853
|
_num: (product.num || 1) * (((_x = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _x.num) || 1)
|
|
700
854
|
};
|
|
701
855
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
@@ -753,7 +907,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
753
907
|
return;
|
|
754
908
|
}
|
|
755
909
|
const hasBundle = product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0;
|
|
756
|
-
debugger;
|
|
757
910
|
if (!hasBundle) {
|
|
758
911
|
result.push(...mainProductArr);
|
|
759
912
|
} else {
|
|
@@ -786,59 +939,65 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
786
939
|
const mainProduct = mainProductArr[0];
|
|
787
940
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
788
941
|
const newBundleWithDiscount = [];
|
|
789
|
-
(product.bundle || []).forEach(
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (item.processed) {
|
|
816
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
817
|
-
var _a;
|
|
818
|
-
return {
|
|
819
|
-
...discount,
|
|
820
|
-
metadata: {
|
|
821
|
-
num: item.num,
|
|
822
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
823
|
-
}
|
|
824
|
-
// num: item.num, // 使用当前的 num
|
|
825
|
-
};
|
|
826
|
-
});
|
|
827
|
-
newBundleWithDiscount.push({
|
|
828
|
-
...bundleItem,
|
|
829
|
-
_id: item._id,
|
|
830
|
-
product_id: bundleItem.product_id,
|
|
831
|
-
price: item.price,
|
|
832
|
-
num: item.num,
|
|
833
|
-
discount_list: updatedDiscountList2
|
|
942
|
+
(product.bundle || []).forEach(
|
|
943
|
+
(bundleItem, bundleIndex) => {
|
|
944
|
+
const processedItems = bundleProcessingInfo.get(
|
|
945
|
+
bundleIndex
|
|
946
|
+
) || [bundleItem];
|
|
947
|
+
if (processedItems.length > 1) {
|
|
948
|
+
processedItems.forEach((item) => {
|
|
949
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
950
|
+
var _a;
|
|
951
|
+
return {
|
|
952
|
+
...discount,
|
|
953
|
+
metadata: {
|
|
954
|
+
num: item.num,
|
|
955
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
956
|
+
}
|
|
957
|
+
// num: item.num, // 使用拆分后的 num
|
|
958
|
+
};
|
|
959
|
+
});
|
|
960
|
+
newBundleWithDiscount.push({
|
|
961
|
+
...bundleItem,
|
|
962
|
+
_id: item._id,
|
|
963
|
+
product_id: bundleItem.product_id,
|
|
964
|
+
price: item.price,
|
|
965
|
+
num: item.num,
|
|
966
|
+
discount_list: updatedDiscountList2
|
|
967
|
+
});
|
|
834
968
|
});
|
|
835
969
|
} else {
|
|
836
|
-
|
|
970
|
+
const item = processedItems[0];
|
|
971
|
+
if (item.processed) {
|
|
972
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
973
|
+
var _a;
|
|
974
|
+
return {
|
|
975
|
+
...discount,
|
|
976
|
+
metadata: {
|
|
977
|
+
num: item.num,
|
|
978
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
979
|
+
}
|
|
980
|
+
// num: item.num, // 使用当前的 num
|
|
981
|
+
};
|
|
982
|
+
});
|
|
983
|
+
newBundleWithDiscount.push({
|
|
984
|
+
...bundleItem,
|
|
985
|
+
_id: item._id,
|
|
986
|
+
product_id: bundleItem.product_id,
|
|
987
|
+
price: item.price,
|
|
988
|
+
num: item.num,
|
|
989
|
+
discount_list: updatedDiscountList2
|
|
990
|
+
});
|
|
991
|
+
} else {
|
|
992
|
+
newBundleWithDiscount.push(item);
|
|
993
|
+
}
|
|
837
994
|
}
|
|
838
995
|
}
|
|
839
|
-
|
|
996
|
+
);
|
|
840
997
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
841
|
-
let newOriginTotalWithDiscount = Number(
|
|
998
|
+
let newOriginTotalWithDiscount = Number(
|
|
999
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1000
|
+
);
|
|
842
1001
|
const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
|
|
843
1002
|
var _a, _b;
|
|
844
1003
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -853,10 +1012,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
853
1012
|
}
|
|
854
1013
|
};
|
|
855
1014
|
});
|
|
856
|
-
const mainDiscountList = updatedMainDiscountList.filter(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1015
|
+
const mainDiscountList = updatedMainDiscountList.filter(
|
|
1016
|
+
(item) => {
|
|
1017
|
+
var _a;
|
|
1018
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1019
|
+
}
|
|
1020
|
+
);
|
|
860
1021
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
861
1022
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
862
1023
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -892,14 +1053,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
892
1053
|
);
|
|
893
1054
|
if (mainProductQuantity > 1) {
|
|
894
1055
|
const newBundleOriginal = [];
|
|
895
|
-
(product.bundle || []).forEach(
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1056
|
+
(product.bundle || []).forEach(
|
|
1057
|
+
(bundleItem, bundleIndex) => {
|
|
1058
|
+
newBundleOriginal.push({
|
|
1059
|
+
...bundleItem,
|
|
1060
|
+
discount_list: []
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
);
|
|
901
1064
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
902
|
-
let newOriginTotalOriginal = Number(
|
|
1065
|
+
let newOriginTotalOriginal = Number(
|
|
1066
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1067
|
+
);
|
|
903
1068
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
904
1069
|
var _a, _b;
|
|
905
1070
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -914,12 +1079,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
914
1079
|
// num: mainProductQuantity - 1,
|
|
915
1080
|
};
|
|
916
1081
|
});
|
|
917
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1082
|
+
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1083
|
+
(item) => {
|
|
1084
|
+
var _a;
|
|
1085
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1086
|
+
}
|
|
1087
|
+
);
|
|
921
1088
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
922
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1089
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1090
|
+
mainDiscountListOriginal
|
|
1091
|
+
);
|
|
923
1092
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
924
1093
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
925
1094
|
}
|
|
@@ -954,47 +1123,56 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
954
1123
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
955
1124
|
const newBundle = [];
|
|
956
1125
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
957
|
-
product.bundle.forEach(
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1126
|
+
product.bundle.forEach(
|
|
1127
|
+
(bundleItem, bundleIndex) => {
|
|
1128
|
+
const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
|
|
1129
|
+
const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
|
|
1130
|
+
if (!processedBundleItems || processedBundleItems.length === 0) {
|
|
1131
|
+
newBundle.push(bundleItem);
|
|
1132
|
+
} else {
|
|
1133
|
+
processedBundleItems.forEach((item) => {
|
|
1134
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1135
|
+
var _a2;
|
|
1136
|
+
return {
|
|
1137
|
+
...discount,
|
|
1138
|
+
metadata: {
|
|
1139
|
+
num: item.num,
|
|
1140
|
+
custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
|
|
1141
|
+
}
|
|
1142
|
+
// num: item.num, // 使用拆分后的 num
|
|
1143
|
+
};
|
|
1144
|
+
});
|
|
1145
|
+
newBundle.push({
|
|
1146
|
+
...bundleItem,
|
|
1147
|
+
_id: item._id,
|
|
1148
|
+
product_id: bundleItem.product_id,
|
|
1149
|
+
price: item.price,
|
|
1150
|
+
num: item.num,
|
|
1151
|
+
discount_list: updatedDiscountList2
|
|
1152
|
+
});
|
|
974
1153
|
});
|
|
975
|
-
|
|
976
|
-
...bundleItem,
|
|
977
|
-
_id: item._id,
|
|
978
|
-
product_id: bundleItem.product_id,
|
|
979
|
-
price: item.price,
|
|
980
|
-
num: item.num,
|
|
981
|
-
discount_list: updatedDiscountList2
|
|
982
|
-
});
|
|
983
|
-
});
|
|
1154
|
+
}
|
|
984
1155
|
}
|
|
985
|
-
|
|
1156
|
+
);
|
|
986
1157
|
}
|
|
987
1158
|
let newTotal = Number(mainProductData.price || 0);
|
|
988
|
-
let newOriginTotal = Number(
|
|
989
|
-
|
|
1159
|
+
let newOriginTotal = Number(
|
|
1160
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1161
|
+
);
|
|
1162
|
+
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(
|
|
1163
|
+
_b,
|
|
1164
|
+
(item) => item.type === "product"
|
|
1165
|
+
)));
|
|
990
1166
|
if (isManualDiscount) {
|
|
991
1167
|
newTotal = mainProductData.total ?? newTotal;
|
|
992
1168
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
993
1169
|
} else {
|
|
994
|
-
const mainDiscountList = mainProductData.discount_list.filter(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1170
|
+
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1171
|
+
(item) => {
|
|
1172
|
+
var _a2;
|
|
1173
|
+
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
1174
|
+
}
|
|
1175
|
+
);
|
|
998
1176
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
999
1177
|
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
|
|
1000
1178
|
newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
|