@pisell/pisellos 2.1.62 → 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/index.js +1 -1
- 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 +164 -34
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Summary/types.d.ts +2 -0
- package/dist/modules/Summary/utils.d.ts +6 -0
- package/dist/modules/Summary/utils.js +21 -0
- package/dist/plugins/window.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +2 -0
- package/dist/solution/BookingByStep/index.js +12 -1
- 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/index.js +1 -1
- 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 +381 -199
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Summary/types.d.ts +2 -0
- package/lib/modules/Summary/utils.d.ts +6 -0
- package/lib/modules/Summary/utils.js +15 -0
- package/lib/plugins/window.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +2 -0
- package/lib/solution/BookingByStep/index.js +12 -1
- 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) => {
|
|
@@ -273,6 +326,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
273
326
|
const processedProductsMap = /* @__PURE__ */ new Map();
|
|
274
327
|
const appliedDiscountProducts = /* @__PURE__ */ new Map();
|
|
275
328
|
sortedFlattenedList.forEach((flatItem) => {
|
|
329
|
+
var _a;
|
|
276
330
|
let product, originProduct;
|
|
277
331
|
if (flatItem.type === "main") {
|
|
278
332
|
product = flatItem.product;
|
|
@@ -287,12 +341,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
287
341
|
total: flatItem.total,
|
|
288
342
|
origin_total: flatItem.origin_total,
|
|
289
343
|
booking_id: flatItem.booking_id,
|
|
290
|
-
discount_list: flatItem.discount_list || []
|
|
344
|
+
discount_list: flatItem.discount_list || [],
|
|
345
|
+
startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
|
|
291
346
|
};
|
|
292
347
|
originProduct = flatItem.originProduct;
|
|
293
348
|
}
|
|
294
349
|
addModeDiscount.forEach((discount) => {
|
|
295
|
-
var
|
|
350
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
296
351
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
297
352
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
298
353
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -305,11 +360,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
305
360
|
);
|
|
306
361
|
let timeLimit = true;
|
|
307
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;
|
|
308
|
-
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
309
|
-
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((
|
|
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));
|
|
310
371
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
311
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
312
|
-
(
|
|
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);
|
|
313
374
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
314
375
|
const discountType = discount.tag || discount.type;
|
|
315
376
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -319,13 +380,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
319
380
|
type: discountType,
|
|
320
381
|
tag: discountType,
|
|
321
382
|
discount: {
|
|
322
|
-
discount_card_type: (
|
|
383
|
+
discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
|
|
323
384
|
fixed_amount: product.price,
|
|
324
385
|
resource_id: discount.id,
|
|
325
386
|
title: discount.format_title,
|
|
326
387
|
original_amount: product.price || product.origin_total,
|
|
327
388
|
pre_value: discount.par_value,
|
|
328
|
-
product_id: originProduct.id
|
|
389
|
+
product_id: originProduct.id,
|
|
390
|
+
discount_product_id: discount.product_id
|
|
329
391
|
},
|
|
330
392
|
metadata: {
|
|
331
393
|
num
|
|
@@ -338,7 +400,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
338
400
|
});
|
|
339
401
|
const processedFlatItemsMap = /* @__PURE__ */ new Map();
|
|
340
402
|
sortedFlattenedList.forEach((flatItem, index) => {
|
|
341
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
403
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
342
404
|
let product, originProduct;
|
|
343
405
|
if (flatItem.type === "main") {
|
|
344
406
|
product = flatItem.product;
|
|
@@ -354,26 +416,41 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
354
416
|
original_price: (_a = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _a.original_price,
|
|
355
417
|
origin_total: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
|
|
356
418
|
booking_id: flatItem.booking_id,
|
|
357
|
-
discount_list: ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) || []
|
|
419
|
+
discount_list: ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) || [],
|
|
420
|
+
startDate: (_d = flatItem.parentProduct) == null ? void 0 : _d.startDate
|
|
358
421
|
};
|
|
359
422
|
originProduct = flatItem.originProduct;
|
|
360
423
|
}
|
|
361
|
-
if ((product == null ? void 0 : product.booking_id) && ((
|
|
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
|
+
))) {
|
|
362
429
|
if (flatItem.type === "main") {
|
|
363
430
|
processedProductsMap.set(product._id, [originProduct]);
|
|
364
431
|
} else {
|
|
365
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
432
|
+
processedFlatItemsMap.set(flatItem._id, [
|
|
433
|
+
{
|
|
434
|
+
...flatItem,
|
|
435
|
+
processed: true
|
|
436
|
+
}
|
|
437
|
+
]);
|
|
369
438
|
}
|
|
370
439
|
return;
|
|
371
440
|
}
|
|
372
441
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
373
|
-
var _a2, _b2;
|
|
374
|
-
|
|
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")
|
|
375
452
|
return false;
|
|
376
|
-
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) => {
|
|
377
454
|
var _a3;
|
|
378
455
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
379
456
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -381,6 +458,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
381
458
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
382
459
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
383
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
|
+
}
|
|
384
470
|
const limitedData = discount.limited_relation_product_data;
|
|
385
471
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
386
472
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -399,6 +485,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
399
485
|
return false;
|
|
400
486
|
}
|
|
401
487
|
if (limitedData.type === "product_all") {
|
|
488
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
402
491
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
403
492
|
return false;
|
|
404
493
|
}
|
|
@@ -411,66 +500,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
411
500
|
}
|
|
412
501
|
return false;
|
|
413
502
|
});
|
|
414
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
503
|
+
const selectedDiscountCard = applicableDiscounts.find(
|
|
504
|
+
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
505
|
+
);
|
|
415
506
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
416
507
|
let isManualDiscount = false;
|
|
417
508
|
if (flatItem.type === "main") {
|
|
418
|
-
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
+
)));
|
|
422
518
|
} else {
|
|
423
519
|
const parentProduct = flatItem.parentProduct;
|
|
424
520
|
if (parentProduct) {
|
|
425
|
-
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
)));
|
|
429
530
|
}
|
|
430
531
|
}
|
|
431
532
|
if (options == null ? void 0 : options.discountId) {
|
|
432
|
-
if (flatItem.type === "main" && ((
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
+
))) {
|
|
436
539
|
isManualDiscount = false;
|
|
437
540
|
}
|
|
438
541
|
if (flatItem.type === "bundle") {
|
|
439
|
-
if (((
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
+
))) {
|
|
446
553
|
isManualDiscount = false;
|
|
447
554
|
}
|
|
448
555
|
}
|
|
449
556
|
}
|
|
450
557
|
if (options == null ? void 0 : options.selectedList) {
|
|
451
|
-
if (flatItem.type === "main" && ((
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
+
))) {
|
|
458
569
|
isManualDiscount = false;
|
|
459
570
|
}
|
|
460
571
|
if (flatItem.type === "bundle") {
|
|
461
|
-
if (((
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
+
))) {
|
|
474
593
|
isManualDiscount = false;
|
|
475
594
|
}
|
|
476
595
|
}
|
|
@@ -478,9 +597,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
478
597
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
479
598
|
if (flatItem.type === "main") {
|
|
480
599
|
if (product.isClient) {
|
|
481
|
-
processedProductsMap.set(
|
|
482
|
-
|
|
483
|
-
[this.hooks.setProduct(originProduct, {
|
|
600
|
+
processedProductsMap.set(product._id, [
|
|
601
|
+
this.hooks.setProduct(originProduct, {
|
|
484
602
|
...isManualDiscount ? {} : {
|
|
485
603
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
486
604
|
product: {
|
|
@@ -501,12 +619,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
501
619
|
price: product.price
|
|
502
620
|
},
|
|
503
621
|
discount_list: []
|
|
504
|
-
})
|
|
505
|
-
);
|
|
622
|
+
})
|
|
623
|
+
]);
|
|
506
624
|
} else {
|
|
507
|
-
processedProductsMap.set(
|
|
508
|
-
|
|
509
|
-
[this.hooks.setProduct(originProduct, {
|
|
625
|
+
processedProductsMap.set(product._id, [
|
|
626
|
+
this.hooks.setProduct(originProduct, {
|
|
510
627
|
...isManualDiscount ? {
|
|
511
628
|
price: product.price,
|
|
512
629
|
main_product_selling_price: product.price
|
|
@@ -517,8 +634,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
517
634
|
main_product_selling_price: product.price
|
|
518
635
|
},
|
|
519
636
|
discount_list: []
|
|
520
|
-
})
|
|
521
|
-
);
|
|
637
|
+
})
|
|
638
|
+
]);
|
|
522
639
|
}
|
|
523
640
|
} else {
|
|
524
641
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
@@ -535,46 +652,68 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
535
652
|
}
|
|
536
653
|
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
537
654
|
const totalQuantity = product.quantity || product.num || 1;
|
|
538
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
539
|
-
|
|
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;
|
|
540
666
|
const arr = [];
|
|
541
667
|
if (flatItem.type === "main") {
|
|
542
668
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
543
|
-
arr.push(
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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
|
+
);
|
|
548
677
|
}
|
|
549
678
|
for (let i = 0; i < splitCount; i++) {
|
|
550
679
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
551
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
|
+
}
|
|
552
685
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
553
686
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
554
|
-
if (((
|
|
687
|
+
if (((_u = product.discount_list) == null ? void 0 : _u.length) && product.origin_total) {
|
|
555
688
|
productOriginTotal = product.origin_total;
|
|
556
689
|
}
|
|
557
|
-
if (Number(((
|
|
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) {
|
|
558
691
|
productOriginTotal = product.total;
|
|
559
692
|
}
|
|
560
|
-
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
561
|
-
|
|
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();
|
|
562
700
|
const isGoodPass = discountType === "good_pass";
|
|
563
|
-
const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
564
701
|
const discountDetail = {
|
|
565
|
-
amount,
|
|
566
|
-
type:
|
|
702
|
+
amount: actualDiscountAmount,
|
|
703
|
+
type: discountType,
|
|
567
704
|
discount: {
|
|
568
|
-
discount_card_type: (
|
|
569
|
-
fixed_amount:
|
|
705
|
+
discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
|
|
706
|
+
fixed_amount: actualDiscountAmount,
|
|
570
707
|
resource_id: selectedDiscount2.id,
|
|
571
708
|
title: selectedDiscount2.format_title,
|
|
572
709
|
original_amount: product.price,
|
|
573
710
|
product_id: originProduct.id,
|
|
574
|
-
percent: selectedDiscount2.par_value
|
|
711
|
+
percent: selectedDiscount2.par_value,
|
|
712
|
+
discount_product_id: selectedDiscount2.product_id
|
|
575
713
|
},
|
|
576
714
|
// 前端使用的num数量,为了计算优惠金额
|
|
577
715
|
_num: isGoodPass ? 1 : product.num,
|
|
716
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
578
717
|
metadata: {
|
|
579
718
|
num: 1
|
|
580
719
|
}
|
|
@@ -590,7 +729,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
590
729
|
}, new import_decimal.default(total)).toNumber();
|
|
591
730
|
}
|
|
592
731
|
if (product.isClient) {
|
|
593
|
-
debugger;
|
|
594
732
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
595
733
|
discount_list: [discountDetail],
|
|
596
734
|
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
@@ -627,23 +765,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
627
765
|
for (let i = 0; i < discountNum; i++) {
|
|
628
766
|
const selectedDiscount2 = applicableDiscounts[i];
|
|
629
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
|
+
}
|
|
630
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();
|
|
631
779
|
const discountDetail = {
|
|
632
|
-
amount:
|
|
780
|
+
amount: bundleDiscountAmount,
|
|
633
781
|
type: "good_pass",
|
|
634
782
|
discount: {
|
|
635
783
|
fixed_amount: product.origin_total,
|
|
636
784
|
resource_id: selectedDiscount2.id,
|
|
637
785
|
title: selectedDiscount2.format_title,
|
|
638
786
|
original_amount: product.origin_total,
|
|
639
|
-
product_id: product.id
|
|
787
|
+
product_id: product.id,
|
|
788
|
+
discount_product_id: selectedDiscount2.product_id
|
|
640
789
|
},
|
|
641
790
|
metadata: {
|
|
642
791
|
// 🔥 使用拆分后的唯一 _id
|
|
643
792
|
custom_product_bundle_map_id: uniqueId,
|
|
644
793
|
num: 1
|
|
645
794
|
},
|
|
646
|
-
_num: 1
|
|
795
|
+
_num: 1,
|
|
796
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
|
|
647
797
|
};
|
|
648
798
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
649
799
|
appliedProducts.push(discountDetail);
|
|
@@ -654,9 +804,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
654
804
|
_id: uniqueId,
|
|
655
805
|
num: 1,
|
|
656
806
|
quantity: 1,
|
|
657
|
-
price:
|
|
658
|
-
//
|
|
659
|
-
total:
|
|
807
|
+
price: discountedPrice,
|
|
808
|
+
// 折扣后的价格
|
|
809
|
+
total: discountedPrice,
|
|
660
810
|
discount_list: [discountDetail],
|
|
661
811
|
processed: true,
|
|
662
812
|
_discountId: selectedDiscount2.id
|
|
@@ -676,31 +826,38 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
676
826
|
} else {
|
|
677
827
|
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
678
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
|
+
}
|
|
679
833
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
680
834
|
const targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
681
835
|
selectedDiscount2,
|
|
682
836
|
productOriginTotal,
|
|
683
837
|
productOriginTotal
|
|
684
838
|
);
|
|
839
|
+
const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
685
840
|
const uniqueId = flatItem._id;
|
|
686
841
|
const discountDetail = {
|
|
687
|
-
amount:
|
|
842
|
+
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
688
843
|
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
689
844
|
discount: {
|
|
690
|
-
discount_card_type: (
|
|
691
|
-
fixed_amount:
|
|
845
|
+
discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
|
|
846
|
+
fixed_amount: bundleActualDiscountAmount,
|
|
692
847
|
resource_id: selectedDiscount2.id,
|
|
693
848
|
title: selectedDiscount2.format_title,
|
|
694
849
|
original_amount: product.original_price,
|
|
695
850
|
product_id: product.id,
|
|
696
|
-
percent: selectedDiscount2.par_value
|
|
851
|
+
percent: selectedDiscount2.par_value,
|
|
852
|
+
discount_product_id: selectedDiscount2.product_id
|
|
697
853
|
},
|
|
698
854
|
metadata: {
|
|
699
855
|
// 🔥 使用唯一的 _id
|
|
700
856
|
custom_product_bundle_map_id: uniqueId,
|
|
701
857
|
num: product.num || 1
|
|
702
858
|
},
|
|
703
|
-
|
|
859
|
+
config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
|
|
860
|
+
_num: (product.num || 1) * (((_y = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _y.num) || 1)
|
|
704
861
|
};
|
|
705
862
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
706
863
|
appliedProducts.push(discountDetail);
|
|
@@ -789,59 +946,65 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
789
946
|
const mainProduct = mainProductArr[0];
|
|
790
947
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
791
948
|
const newBundleWithDiscount = [];
|
|
792
|
-
(product.bundle || []).forEach(
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (item.processed) {
|
|
819
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
820
|
-
var _a;
|
|
821
|
-
return {
|
|
822
|
-
...discount,
|
|
823
|
-
metadata: {
|
|
824
|
-
num: item.num,
|
|
825
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
826
|
-
}
|
|
827
|
-
// num: item.num, // 使用当前的 num
|
|
828
|
-
};
|
|
829
|
-
});
|
|
830
|
-
newBundleWithDiscount.push({
|
|
831
|
-
...bundleItem,
|
|
832
|
-
_id: item._id,
|
|
833
|
-
product_id: bundleItem.product_id,
|
|
834
|
-
price: item.price,
|
|
835
|
-
num: item.num,
|
|
836
|
-
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
|
+
});
|
|
837
975
|
});
|
|
838
976
|
} else {
|
|
839
|
-
|
|
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
|
+
}
|
|
840
1001
|
}
|
|
841
1002
|
}
|
|
842
|
-
|
|
1003
|
+
);
|
|
843
1004
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
844
|
-
let newOriginTotalWithDiscount = Number(
|
|
1005
|
+
let newOriginTotalWithDiscount = Number(
|
|
1006
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1007
|
+
);
|
|
845
1008
|
const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
|
|
846
1009
|
var _a, _b;
|
|
847
1010
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -856,10 +1019,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
856
1019
|
}
|
|
857
1020
|
};
|
|
858
1021
|
});
|
|
859
|
-
const mainDiscountList = updatedMainDiscountList.filter(
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
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
|
+
);
|
|
863
1028
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
864
1029
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
865
1030
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -895,14 +1060,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
895
1060
|
);
|
|
896
1061
|
if (mainProductQuantity > 1) {
|
|
897
1062
|
const newBundleOriginal = [];
|
|
898
|
-
(product.bundle || []).forEach(
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
1063
|
+
(product.bundle || []).forEach(
|
|
1064
|
+
(bundleItem, bundleIndex) => {
|
|
1065
|
+
newBundleOriginal.push({
|
|
1066
|
+
...bundleItem,
|
|
1067
|
+
discount_list: []
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
);
|
|
904
1071
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
905
|
-
let newOriginTotalOriginal = Number(
|
|
1072
|
+
let newOriginTotalOriginal = Number(
|
|
1073
|
+
mainProductData.original_price || mainProductData.price || 0
|
|
1074
|
+
);
|
|
906
1075
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
907
1076
|
var _a, _b;
|
|
908
1077
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -917,12 +1086,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
917
1086
|
// num: mainProductQuantity - 1,
|
|
918
1087
|
};
|
|
919
1088
|
});
|
|
920
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
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
|
+
);
|
|
924
1095
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
925
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1096
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1097
|
+
mainDiscountListOriginal
|
|
1098
|
+
);
|
|
926
1099
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
927
1100
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
928
1101
|
}
|
|
@@ -957,47 +1130,56 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
957
1130
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
958
1131
|
const newBundle = [];
|
|
959
1132
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
960
|
-
product.bundle.forEach(
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
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
|
+
});
|
|
985
1160
|
});
|
|
986
|
-
}
|
|
1161
|
+
}
|
|
987
1162
|
}
|
|
988
|
-
|
|
1163
|
+
);
|
|
989
1164
|
}
|
|
990
1165
|
let newTotal = Number(mainProductData.price || 0);
|
|
991
|
-
let newOriginTotal = Number(
|
|
992
|
-
|
|
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
|
+
)));
|
|
993
1173
|
if (isManualDiscount) {
|
|
994
1174
|
newTotal = mainProductData.total ?? newTotal;
|
|
995
1175
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
996
1176
|
} else {
|
|
997
|
-
const mainDiscountList = mainProductData.discount_list.filter(
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
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
|
+
);
|
|
1001
1183
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1002
1184
|
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
|
|
1003
1185
|
newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
|