@pisell/pisellos 2.1.63 → 2.1.64
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 +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 +152 -25
- 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 +11 -1
- 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 +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 +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 +370 -191
- 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 +6 -0
- 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;
|
|
@@ -76,6 +81,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
76
81
|
newDiscountList,
|
|
77
82
|
productList,
|
|
78
83
|
holders,
|
|
84
|
+
orderTotalAmount,
|
|
79
85
|
isFormSubject
|
|
80
86
|
}) {
|
|
81
87
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
@@ -96,15 +102,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
96
102
|
productList
|
|
97
103
|
};
|
|
98
104
|
}
|
|
99
|
-
const filteredOldDiscountList = oldDiscountList.filter(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
const filteredOldDiscountList = oldDiscountList.filter(
|
|
106
|
+
(discount) => !discount.isEditMode && discount.tag !== "good_pass"
|
|
107
|
+
);
|
|
108
|
+
const mergedDiscountList = (0, import_utils.uniqueById)(
|
|
109
|
+
(0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
|
|
110
|
+
"product_id"
|
|
111
|
+
);
|
|
104
112
|
const result = this.calcDiscount({
|
|
105
113
|
discountList: mergedDiscountList,
|
|
106
114
|
productList: [...productList],
|
|
107
115
|
holders,
|
|
116
|
+
orderTotalAmount,
|
|
108
117
|
isFormSubject
|
|
109
118
|
}, {
|
|
110
119
|
scan: true
|
|
@@ -139,6 +148,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
139
148
|
discountList,
|
|
140
149
|
productList,
|
|
141
150
|
holders,
|
|
151
|
+
orderTotalAmount,
|
|
142
152
|
isFormSubject
|
|
143
153
|
}, options) {
|
|
144
154
|
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
@@ -263,7 +273,50 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
263
273
|
}
|
|
264
274
|
return priceB.minus(priceA).toNumber();
|
|
265
275
|
});
|
|
276
|
+
const evaluator = this.getWalletPassEvaluator();
|
|
277
|
+
if (evaluator) {
|
|
278
|
+
addModeDiscount.forEach((discount) => {
|
|
279
|
+
var _a, _b;
|
|
280
|
+
const discountType = discount.tag || discount.type;
|
|
281
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
282
|
+
discountType
|
|
283
|
+
)) {
|
|
284
|
+
const voucher = {
|
|
285
|
+
id: discount.id,
|
|
286
|
+
amount: Number(discount.par_value || 0),
|
|
287
|
+
balance: Number(discount.balance || 0),
|
|
288
|
+
type: discountType,
|
|
289
|
+
product_id: discount.product_id,
|
|
290
|
+
unified_available_status: 1,
|
|
291
|
+
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
292
|
+
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
293
|
+
};
|
|
294
|
+
const productsForEvaluate = sortedFlattenedList.map((item) => ({
|
|
295
|
+
product_id: item.id,
|
|
296
|
+
price: item.price || 0,
|
|
297
|
+
quantity: item.quantity || item.num || 1,
|
|
298
|
+
selling_price: item.price || 0
|
|
299
|
+
}));
|
|
300
|
+
const result = evaluator.checkVoucherAvailability({
|
|
301
|
+
orderTotalAmount,
|
|
302
|
+
products: productsForEvaluate,
|
|
303
|
+
vouchers: [voucher]
|
|
304
|
+
});
|
|
305
|
+
if (result.isAvailable) {
|
|
306
|
+
discount.config = {
|
|
307
|
+
...result.config,
|
|
308
|
+
isAvailable: true
|
|
309
|
+
};
|
|
310
|
+
} else {
|
|
311
|
+
discount.config = {
|
|
312
|
+
isAvailable: false
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
266
318
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
319
|
+
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
267
320
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
268
321
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
269
322
|
addModeDiscount.forEach((discount) => {
|
|
@@ -294,7 +347,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
294
347
|
originProduct = flatItem.originProduct;
|
|
295
348
|
}
|
|
296
349
|
addModeDiscount.forEach((discount) => {
|
|
297
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
350
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
298
351
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
299
352
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
300
353
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -307,11 +360,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
307
360
|
);
|
|
308
361
|
let timeLimit = true;
|
|
309
362
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
310
|
-
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
311
|
-
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(
|
|
363
|
+
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;
|
|
364
|
+
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(
|
|
365
|
+
(discount2) => discount2.id && [
|
|
366
|
+
"good_pass",
|
|
367
|
+
"discount_card",
|
|
368
|
+
"product_discount_card"
|
|
369
|
+
].includes(discount2.tag || discount2.type)
|
|
370
|
+
))) : !((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));
|
|
312
371
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
313
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
314
|
-
(
|
|
372
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_e = discount.config) == null ? void 0 : _e.isAvailable)) {
|
|
373
|
+
(_f = discountApplicability.get(discount.id)) == null ? void 0 : _f.push(product.id);
|
|
315
374
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
316
375
|
const discountType = discount.tag || discount.type;
|
|
317
376
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -321,13 +380,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
321
380
|
type: discountType,
|
|
322
381
|
tag: discountType,
|
|
323
382
|
discount: {
|
|
324
|
-
discount_card_type: (
|
|
383
|
+
discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
|
|
325
384
|
fixed_amount: product.price,
|
|
326
385
|
resource_id: discount.id,
|
|
327
386
|
title: discount.format_title,
|
|
328
387
|
original_amount: product.price || product.origin_total,
|
|
329
388
|
pre_value: discount.par_value,
|
|
330
|
-
product_id: originProduct.id
|
|
389
|
+
product_id: originProduct.id,
|
|
390
|
+
discount_product_id: discount.product_id
|
|
331
391
|
},
|
|
332
392
|
metadata: {
|
|
333
393
|
num
|
|
@@ -361,22 +421,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
361
421
|
};
|
|
362
422
|
originProduct = flatItem.originProduct;
|
|
363
423
|
}
|
|
364
|
-
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(
|
|
424
|
+
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(
|
|
425
|
+
(discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
|
|
426
|
+
discount.tag || discount.type
|
|
427
|
+
)
|
|
428
|
+
))) {
|
|
365
429
|
if (flatItem.type === "main") {
|
|
366
430
|
processedProductsMap.set(product._id, [originProduct]);
|
|
367
431
|
} else {
|
|
368
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
432
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
433
|
+
{
|
|
434
|
+
...flatItem,
|
|
435
|
+
processed: true
|
|
436
|
+
}
|
|
437
|
+
]);
|
|
372
438
|
}
|
|
373
439
|
return;
|
|
374
440
|
}
|
|
375
441
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
376
|
-
var _a2, _b2;
|
|
377
|
-
|
|
442
|
+
var _a2, _b2, _c2, _d2;
|
|
443
|
+
const discountType = discount.tag || discount.type;
|
|
444
|
+
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
445
|
+
discountType
|
|
446
|
+
)) {
|
|
447
|
+
if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
|
|
378
452
|
return false;
|
|
379
|
-
if ((Number(product.price) <= 0 || !product.price) && !((
|
|
453
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
|
|
380
454
|
var _a3;
|
|
381
455
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
382
456
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -384,6 +458,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
384
458
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
385
459
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
386
460
|
return false;
|
|
461
|
+
if ((discount.tag || discount.type) === "good_pass") {
|
|
462
|
+
const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
|
|
463
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
464
|
+
const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
465
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
387
470
|
const limitedData = discount.limited_relation_product_data;
|
|
388
471
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
389
472
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -402,6 +485,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
402
485
|
return false;
|
|
403
486
|
}
|
|
404
487
|
if (limitedData.type === "product_all") {
|
|
488
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
405
491
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
406
492
|
return false;
|
|
407
493
|
}
|
|
@@ -414,66 +500,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
414
500
|
}
|
|
415
501
|
return false;
|
|
416
502
|
});
|
|
417
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
503
|
+
const selectedDiscountCard = applicableDiscounts.find(
|
|
504
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
505
|
+
);
|
|
418
506
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
419
507
|
let isManualDiscount = false;
|
|
420
508
|
if (flatItem.type === "main") {
|
|
421
|
-
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
509
|
+
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
510
|
+
(item) => {
|
|
511
|
+
var _a2;
|
|
512
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
513
|
+
}
|
|
514
|
+
) && (!((_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(
|
|
515
|
+
_h,
|
|
516
|
+
(item) => item.type === "product"
|
|
517
|
+
)));
|
|
425
518
|
} else {
|
|
426
519
|
const parentProduct = flatItem.parentProduct;
|
|
427
520
|
if (parentProduct) {
|
|
428
|
-
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
521
|
+
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
522
|
+
(item) => {
|
|
523
|
+
var _a2;
|
|
524
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
525
|
+
}
|
|
526
|
+
) && (!((_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(
|
|
527
|
+
_k,
|
|
528
|
+
(item) => item.type === "product"
|
|
529
|
+
)));
|
|
432
530
|
}
|
|
433
531
|
}
|
|
434
532
|
if (options == null ? void 0 : options.discountId) {
|
|
435
|
-
if (flatItem.type === "main" && ((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
533
|
+
if (flatItem.type === "main" && ((_m = product.discount_list) == null ? void 0 : _m.some(
|
|
534
|
+
(item) => {
|
|
535
|
+
var _a2;
|
|
536
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
537
|
+
}
|
|
538
|
+
))) {
|
|
439
539
|
isManualDiscount = false;
|
|
440
540
|
}
|
|
441
541
|
if (flatItem.type === "bundle") {
|
|
442
|
-
if (((_n = product.discount_list) == null ? void 0 : _n.some(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
542
|
+
if (((_n = product.discount_list) == null ? void 0 : _n.some(
|
|
543
|
+
(item) => {
|
|
544
|
+
var _a2;
|
|
545
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
546
|
+
}
|
|
547
|
+
)) || ((_p = (_o = flatItem.parentProduct) == null ? void 0 : _o.discount_list) == null ? void 0 : _p.some(
|
|
548
|
+
(item) => {
|
|
549
|
+
var _a2;
|
|
550
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
551
|
+
}
|
|
552
|
+
))) {
|
|
449
553
|
isManualDiscount = false;
|
|
450
554
|
}
|
|
451
555
|
}
|
|
452
556
|
}
|
|
453
557
|
if (options == null ? void 0 : options.selectedList) {
|
|
454
|
-
if (flatItem.type === "main" && ((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
558
|
+
if (flatItem.type === "main" && ((_q = product.discount_list) == null ? void 0 : _q.some(
|
|
559
|
+
(item) => {
|
|
560
|
+
var _a2;
|
|
561
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
562
|
+
(n) => {
|
|
563
|
+
var _a3;
|
|
564
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
565
|
+
}
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
))) {
|
|
461
569
|
isManualDiscount = false;
|
|
462
570
|
}
|
|
463
571
|
if (flatItem.type === "bundle") {
|
|
464
|
-
if (((_r = product.discount_list) == null ? void 0 : _r.some(
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
572
|
+
if (((_r = product.discount_list) == null ? void 0 : _r.some(
|
|
573
|
+
(item) => {
|
|
574
|
+
var _a2;
|
|
575
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
576
|
+
(n) => {
|
|
577
|
+
var _a3;
|
|
578
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
579
|
+
}
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
)) || ((_t = (_s = flatItem.parentProduct) == null ? void 0 : _s.discount_list) == null ? void 0 : _t.some(
|
|
583
|
+
(item) => {
|
|
584
|
+
var _a2;
|
|
585
|
+
return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
|
|
586
|
+
(n) => {
|
|
587
|
+
var _a3;
|
|
588
|
+
return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
))) {
|
|
477
593
|
isManualDiscount = false;
|
|
478
594
|
}
|
|
479
595
|
}
|
|
@@ -481,9 +597,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
481
597
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
482
598
|
if (flatItem.type === "main") {
|
|
483
599
|
if (product.isClient) {
|
|
484
|
-
processedProductsMap.set(
|
|
485
|
-
|
|
486
|
-
[this.hooks.setProduct(originProduct, {
|
|
600
|
+
processedProductsMap.set(product._id, [
|
|
601
|
+
this.hooks.setProduct(originProduct, {
|
|
487
602
|
...isManualDiscount ? {} : {
|
|
488
603
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
489
604
|
product: {
|
|
@@ -504,12 +619,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
504
619
|
price: product.price
|
|
505
620
|
},
|
|
506
621
|
discount_list: []
|
|
507
|
-
})
|
|
508
|
-
);
|
|
622
|
+
})
|
|
623
|
+
]);
|
|
509
624
|
} else {
|
|
510
|
-
processedProductsMap.set(
|
|
511
|
-
|
|
512
|
-
[this.hooks.setProduct(originProduct, {
|
|
625
|
+
processedProductsMap.set(product._id, [
|
|
626
|
+
this.hooks.setProduct(originProduct, {
|
|
513
627
|
...isManualDiscount ? {
|
|
514
628
|
price: product.price,
|
|
515
629
|
main_product_selling_price: product.price
|
|
@@ -520,8 +634,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
520
634
|
main_product_selling_price: product.price
|
|
521
635
|
},
|
|
522
636
|
discount_list: []
|
|
523
|
-
})
|
|
524
|
-
);
|
|
637
|
+
})
|
|
638
|
+
]);
|
|
525
639
|
}
|
|
526
640
|
} else {
|
|
527
641
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
@@ -538,20 +652,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
538
652
|
}
|
|
539
653
|
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
540
654
|
const totalQuantity = product.quantity || product.num || 1;
|
|
541
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
542
|
-
|
|
655
|
+
const availableGoodPassCount = applicableDiscounts.filter(
|
|
656
|
+
(item) => (item.tag || item.type) === "good_pass"
|
|
657
|
+
).length;
|
|
658
|
+
let maxUsageLimit = availableGoodPassCount;
|
|
659
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
660
|
+
maxUsageLimit = Math.min(
|
|
661
|
+
availableGoodPassCount,
|
|
662
|
+
selectedDiscount.config.maxUsagePerOrder
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
543
666
|
const arr = [];
|
|
544
667
|
if (flatItem.type === "main") {
|
|
545
668
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
546
|
-
arr.push(
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
669
|
+
arr.push(
|
|
670
|
+
this.hooks.setProduct(originProduct, {
|
|
671
|
+
discount_list: [],
|
|
672
|
+
quantity: totalQuantity - splitCount,
|
|
673
|
+
_id: product._id.split("___")[0],
|
|
674
|
+
total: product.origin_total || product.total
|
|
675
|
+
})
|
|
676
|
+
);
|
|
551
677
|
}
|
|
552
678
|
for (let i = 0; i < splitCount; i++) {
|
|
553
679
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
554
680
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
681
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
682
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
683
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
684
|
+
}
|
|
555
685
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
556
686
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
557
687
|
if (((_u = product.discount_list) == null ? void 0 : _u.length) && product.origin_total) {
|
|
@@ -560,24 +690,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
560
690
|
if (Number(((_v = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _v.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
561
691
|
productOriginTotal = product.total;
|
|
562
692
|
}
|
|
563
|
-
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
564
|
-
|
|
693
|
+
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
694
|
+
selectedDiscount2,
|
|
695
|
+
product.price,
|
|
696
|
+
product.price
|
|
697
|
+
);
|
|
698
|
+
const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
|
|
699
|
+
const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
565
700
|
const isGoodPass = discountType === "good_pass";
|
|
566
|
-
const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
567
701
|
const discountDetail = {
|
|
568
|
-
amount,
|
|
569
|
-
type:
|
|
702
|
+
amount: actualDiscountAmount,
|
|
703
|
+
type: discountType,
|
|
570
704
|
discount: {
|
|
571
705
|
discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
|
|
572
|
-
fixed_amount:
|
|
706
|
+
fixed_amount: actualDiscountAmount,
|
|
573
707
|
resource_id: selectedDiscount2.id,
|
|
574
708
|
title: selectedDiscount2.format_title,
|
|
575
709
|
original_amount: product.price,
|
|
576
710
|
product_id: originProduct.id,
|
|
577
|
-
percent: selectedDiscount2.par_value
|
|
711
|
+
percent: selectedDiscount2.par_value,
|
|
712
|
+
discount_product_id: selectedDiscount2.product_id
|
|
578
713
|
},
|
|
579
714
|
// 前端使用的num数量,为了计算优惠金额
|
|
580
715
|
_num: isGoodPass ? 1 : product.num,
|
|
716
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
581
717
|
metadata: {
|
|
582
718
|
num: 1
|
|
583
719
|
}
|
|
@@ -593,7 +729,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
593
729
|
}, new import_decimal.default(total)).toNumber();
|
|
594
730
|
}
|
|
595
731
|
if (product.isClient) {
|
|
596
|
-
debugger;
|
|
597
732
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
598
733
|
discount_list: [discountDetail],
|
|
599
734
|
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
@@ -630,23 +765,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
630
765
|
for (let i = 0; i < discountNum; i++) {
|
|
631
766
|
const selectedDiscount2 = applicableDiscounts[i];
|
|
632
767
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
768
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
769
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
770
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
771
|
+
}
|
|
633
772
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
773
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(
|
|
774
|
+
selectedDiscount2,
|
|
775
|
+
product.origin_total,
|
|
776
|
+
product.origin_total
|
|
777
|
+
);
|
|
778
|
+
const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
634
779
|
const discountDetail = {
|
|
635
|
-
amount:
|
|
780
|
+
amount: bundleDiscountAmount,
|
|
636
781
|
type: "good_pass",
|
|
637
782
|
discount: {
|
|
638
783
|
fixed_amount: product.origin_total,
|
|
639
784
|
resource_id: selectedDiscount2.id,
|
|
640
785
|
title: selectedDiscount2.format_title,
|
|
641
786
|
original_amount: product.origin_total,
|
|
642
|
-
product_id: product.id
|
|
787
|
+
product_id: product.id,
|
|
788
|
+
discount_product_id: selectedDiscount2.product_id
|
|
643
789
|
},
|
|
644
790
|
metadata: {
|
|
645
791
|
// 🔥 使用拆分后的唯一 _id
|
|
646
792
|
custom_product_bundle_map_id: uniqueId,
|
|
647
793
|
num: 1
|
|
648
794
|
},
|
|
649
|
-
_num: 1
|
|
795
|
+
_num: 1,
|
|
796
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
|
|
650
797
|
};
|
|
651
798
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
652
799
|
appliedProducts.push(discountDetail);
|
|
@@ -657,9 +804,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
657
804
|
_id: uniqueId,
|
|
658
805
|
num: 1,
|
|
659
806
|
quantity: 1,
|
|
660
|
-
price:
|
|
661
|
-
//
|
|
662
|
-
total:
|
|
807
|
+
price: discountedPrice,
|
|
808
|
+
// 折扣后的价格
|
|
809
|
+
total: discountedPrice,
|
|
663
810
|
discount_list: [discountDetail],
|
|
664
811
|
processed: true,
|
|
665
812
|
_discountId: selectedDiscount2.id
|
|
@@ -679,30 +826,37 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
679
826
|
} else {
|
|
680
827
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
681
828
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
829
|
+
if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
|
|
830
|
+
const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
|
|
831
|
+
usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
|
|
832
|
+
}
|
|
682
833
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
683
834
|
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
684
835
|
selectedDiscount2,
|
|
685
836
|
productOriginTotal,
|
|
686
837
|
productOriginTotal
|
|
687
838
|
);
|
|
839
|
+
const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
688
840
|
const uniqueId = flatItem._id;
|
|
689
841
|
const discountDetail = {
|
|
690
|
-
amount:
|
|
842
|
+
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
691
843
|
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
692
844
|
discount: {
|
|
693
845
|
discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
|
|
694
|
-
fixed_amount:
|
|
846
|
+
fixed_amount: bundleActualDiscountAmount,
|
|
695
847
|
resource_id: selectedDiscount2.id,
|
|
696
848
|
title: selectedDiscount2.format_title,
|
|
697
849
|
original_amount: product.original_price,
|
|
698
850
|
product_id: product.id,
|
|
699
|
-
percent: selectedDiscount2.par_value
|
|
851
|
+
percent: selectedDiscount2.par_value,
|
|
852
|
+
discount_product_id: selectedDiscount2.product_id
|
|
700
853
|
},
|
|
701
854
|
metadata: {
|
|
702
855
|
// 🔥 使用唯一的 _id
|
|
703
856
|
custom_product_bundle_map_id: uniqueId,
|
|
704
857
|
num: product.num || 1
|
|
705
858
|
},
|
|
859
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
706
860
|
_num: (product.num || 1) * (((_y = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _y.num) || 1)
|
|
707
861
|
};
|
|
708
862
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
@@ -792,59 +946,65 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
792
946
|
const mainProduct = mainProductArr[0];
|
|
793
947
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
794
948
|
const newBundleWithDiscount = [];
|
|
795
|
-
(product.bundle || []).forEach(
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
if (item.processed) {
|
|
822
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
823
|
-
var _a;
|
|
824
|
-
return {
|
|
825
|
-
...discount,
|
|
826
|
-
metadata: {
|
|
827
|
-
num: item.num,
|
|
828
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
829
|
-
}
|
|
830
|
-
// num: item.num, // 使用当前的 num
|
|
831
|
-
};
|
|
832
|
-
});
|
|
833
|
-
newBundleWithDiscount.push({
|
|
834
|
-
...bundleItem,
|
|
835
|
-
_id: item._id,
|
|
836
|
-
product_id: bundleItem.product_id,
|
|
837
|
-
price: item.price,
|
|
838
|
-
num: item.num,
|
|
839
|
-
discount_list: updatedDiscountList2
|
|
949
|
+
(product.bundle || []).forEach(
|
|
950
|
+
(bundleItem, bundleIndex) => {
|
|
951
|
+
const processedItems = bundleProcessingInfo.get(
|
|
952
|
+
bundleIndex
|
|
953
|
+
) || [bundleItem];
|
|
954
|
+
if (processedItems.length > 1) {
|
|
955
|
+
processedItems.forEach((item) => {
|
|
956
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
957
|
+
var _a;
|
|
958
|
+
return {
|
|
959
|
+
...discount,
|
|
960
|
+
metadata: {
|
|
961
|
+
num: item.num,
|
|
962
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
963
|
+
}
|
|
964
|
+
// num: item.num, // 使用拆分后的 num
|
|
965
|
+
};
|
|
966
|
+
});
|
|
967
|
+
newBundleWithDiscount.push({
|
|
968
|
+
...bundleItem,
|
|
969
|
+
_id: item._id,
|
|
970
|
+
product_id: bundleItem.product_id,
|
|
971
|
+
price: item.price,
|
|
972
|
+
num: item.num,
|
|
973
|
+
discount_list: updatedDiscountList2
|
|
974
|
+
});
|
|
840
975
|
});
|
|
841
976
|
} else {
|
|
842
|
-
|
|
977
|
+
const item = processedItems[0];
|
|
978
|
+
if (item.processed) {
|
|
979
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
980
|
+
var _a;
|
|
981
|
+
return {
|
|
982
|
+
...discount,
|
|
983
|
+
metadata: {
|
|
984
|
+
num: item.num,
|
|
985
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
986
|
+
}
|
|
987
|
+
// num: item.num, // 使用当前的 num
|
|
988
|
+
};
|
|
989
|
+
});
|
|
990
|
+
newBundleWithDiscount.push({
|
|
991
|
+
...bundleItem,
|
|
992
|
+
_id: item._id,
|
|
993
|
+
product_id: bundleItem.product_id,
|
|
994
|
+
price: item.price,
|
|
995
|
+
num: item.num,
|
|
996
|
+
discount_list: updatedDiscountList2
|
|
997
|
+
});
|
|
998
|
+
} else {
|
|
999
|
+
newBundleWithDiscount.push(item);
|
|
1000
|
+
}
|
|
843
1001
|
}
|
|
844
1002
|
}
|
|
845
|
-
|
|
1003
|
+
);
|
|
846
1004
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
847
|
-
let newOriginTotalWithDiscount = Number(
|
|
1005
|
+
let newOriginTotalWithDiscount = Number(
|
|
1006
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1007
|
+
);
|
|
848
1008
|
const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
|
|
849
1009
|
var _a, _b;
|
|
850
1010
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -859,10 +1019,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
859
1019
|
}
|
|
860
1020
|
};
|
|
861
1021
|
});
|
|
862
|
-
const mainDiscountList = updatedMainDiscountList.filter(
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1022
|
+
const mainDiscountList = updatedMainDiscountList.filter(
|
|
1023
|
+
(item) => {
|
|
1024
|
+
var _a;
|
|
1025
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
866
1028
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
867
1029
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
868
1030
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -898,14 +1060,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
898
1060
|
);
|
|
899
1061
|
if (mainProductQuantity > 1) {
|
|
900
1062
|
const newBundleOriginal = [];
|
|
901
|
-
(product.bundle || []).forEach(
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1063
|
+
(product.bundle || []).forEach(
|
|
1064
|
+
(bundleItem, bundleIndex) => {
|
|
1065
|
+
newBundleOriginal.push({
|
|
1066
|
+
...bundleItem,
|
|
1067
|
+
discount_list: []
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
);
|
|
907
1071
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
908
|
-
let newOriginTotalOriginal = Number(
|
|
1072
|
+
let newOriginTotalOriginal = Number(
|
|
1073
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1074
|
+
);
|
|
909
1075
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
910
1076
|
var _a, _b;
|
|
911
1077
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -920,12 +1086,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
920
1086
|
// num: mainProductQuantity - 1,
|
|
921
1087
|
};
|
|
922
1088
|
});
|
|
923
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1089
|
+
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1090
|
+
(item) => {
|
|
1091
|
+
var _a;
|
|
1092
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1093
|
+
}
|
|
1094
|
+
);
|
|
927
1095
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
928
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1096
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1097
|
+
mainDiscountListOriginal
|
|
1098
|
+
);
|
|
929
1099
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
930
1100
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
931
1101
|
}
|
|
@@ -960,47 +1130,56 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
960
1130
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
961
1131
|
const newBundle = [];
|
|
962
1132
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
963
|
-
product.bundle.forEach(
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1133
|
+
product.bundle.forEach(
|
|
1134
|
+
(bundleItem, bundleIndex) => {
|
|
1135
|
+
const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
|
|
1136
|
+
const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
|
|
1137
|
+
if (!processedBundleItems || processedBundleItems.length === 0) {
|
|
1138
|
+
newBundle.push(bundleItem);
|
|
1139
|
+
} else {
|
|
1140
|
+
processedBundleItems.forEach((item) => {
|
|
1141
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1142
|
+
var _a2;
|
|
1143
|
+
return {
|
|
1144
|
+
...discount,
|
|
1145
|
+
metadata: {
|
|
1146
|
+
num: item.num,
|
|
1147
|
+
custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
|
|
1148
|
+
}
|
|
1149
|
+
// num: item.num, // 使用拆分后的 num
|
|
1150
|
+
};
|
|
1151
|
+
});
|
|
1152
|
+
newBundle.push({
|
|
1153
|
+
...bundleItem,
|
|
1154
|
+
_id: item._id,
|
|
1155
|
+
product_id: bundleItem.product_id,
|
|
1156
|
+
price: item.price,
|
|
1157
|
+
num: item.num,
|
|
1158
|
+
discount_list: updatedDiscountList2
|
|
1159
|
+
});
|
|
980
1160
|
});
|
|
981
|
-
|
|
982
|
-
...bundleItem,
|
|
983
|
-
_id: item._id,
|
|
984
|
-
product_id: bundleItem.product_id,
|
|
985
|
-
price: item.price,
|
|
986
|
-
num: item.num,
|
|
987
|
-
discount_list: updatedDiscountList2
|
|
988
|
-
});
|
|
989
|
-
});
|
|
1161
|
+
}
|
|
990
1162
|
}
|
|
991
|
-
|
|
1163
|
+
);
|
|
992
1164
|
}
|
|
993
1165
|
let newTotal = Number(mainProductData.price || 0);
|
|
994
|
-
let newOriginTotal = Number(
|
|
995
|
-
|
|
1166
|
+
let newOriginTotal = Number(
|
|
1167
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1168
|
+
);
|
|
1169
|
+
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(
|
|
1170
|
+
_b,
|
|
1171
|
+
(item) => item.type === "product"
|
|
1172
|
+
)));
|
|
996
1173
|
if (isManualDiscount) {
|
|
997
1174
|
newTotal = mainProductData.total ?? newTotal;
|
|
998
1175
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
999
1176
|
} else {
|
|
1000
|
-
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1177
|
+
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1178
|
+
(item) => {
|
|
1179
|
+
var _a2;
|
|
1180
|
+
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
1181
|
+
}
|
|
1182
|
+
);
|
|
1004
1183
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1005
1184
|
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
|
|
1006
1185
|
newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
|