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