@pisell/pisellos 2.1.118 → 2.1.120
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +4 -1
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -1
- package/dist/model/strategy/engine.d.ts +106 -0
- package/dist/model/strategy/engine.js +611 -0
- package/dist/model/strategy/index.d.ts +2 -93
- package/dist/model/strategy/index.js +6 -549
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +25 -56
- package/dist/modules/Discount/types.d.ts +0 -18
- package/dist/modules/OpenData/index.d.ts +23 -0
- package/dist/modules/OpenData/index.js +167 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +58 -1
- package/dist/modules/Order/index.js +780 -29
- package/dist/modules/Order/types.d.ts +144 -12
- package/dist/modules/Order/utils.d.ts +25 -0
- package/dist/modules/Order/utils.js +225 -1
- 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/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +245 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.d.ts +5 -9
- package/dist/modules/Rules/index.js +164 -673
- package/dist/modules/Rules/types.d.ts +0 -2
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +59 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +513 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
- package/dist/modules/ScanOrderLogger/index.js +161 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +3 -9
- package/dist/modules/Summary/utils.js +4 -25
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -2
- package/dist/solution/BookingByStep/index.js +44 -42
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ScanOrder/index.d.ts +90 -0
- package/dist/solution/ScanOrder/index.js +1853 -0
- package/dist/solution/ScanOrder/types.d.ts +210 -0
- package/dist/solution/ScanOrder/types.js +16 -0
- package/dist/solution/ScanOrder/utils.d.ts +93 -0
- package/dist/solution/ScanOrder/utils.js +397 -0
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +7 -23
- package/dist/solution/ShopDiscount/types.d.ts +0 -1
- package/dist/solution/ShopDiscount/types.js +1 -2
- package/dist/solution/ShopDiscount/utils.js +12 -26
- package/dist/solution/VenueBooking/index.d.ts +158 -0
- package/dist/solution/VenueBooking/index.js +2873 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +130 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/resource.js +94 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +204 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +12 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +58 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/lib/model/strategy/engine.d.ts +106 -0
- package/lib/model/strategy/engine.js +450 -0
- package/lib/model/strategy/index.d.ts +2 -93
- package/lib/model/strategy/index.js +6 -381
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +12 -39
- package/lib/modules/Discount/types.d.ts +0 -18
- package/lib/modules/OpenData/index.d.ts +23 -0
- package/lib/modules/OpenData/index.js +116 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +58 -1
- package/lib/modules/Order/index.js +423 -1
- package/lib/modules/Order/types.d.ts +144 -12
- package/lib/modules/Order/utils.d.ts +25 -0
- package/lib/modules/Order/utils.js +229 -0
- 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/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +149 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.d.ts +5 -9
- package/lib/modules/Rules/index.js +286 -778
- package/lib/modules/Rules/types.d.ts +0 -2
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +59 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +452 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
- package/lib/modules/ScanOrderLogger/index.js +135 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +3 -9
- package/lib/modules/Summary/utils.js +4 -19
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -2
- package/lib/solution/BookingByStep/index.js +4 -2
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ScanOrder/index.d.ts +90 -0
- package/lib/solution/ScanOrder/index.js +1071 -0
- package/lib/solution/ScanOrder/types.d.ts +210 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +93 -0
- package/lib/solution/ScanOrder/utils.js +359 -0
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +8 -22
- package/lib/solution/ShopDiscount/types.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +6 -10
- package/lib/solution/VenueBooking/index.d.ts +158 -0
- package/lib/solution/VenueBooking/index.js +1545 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +130 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/resource.js +80 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +209 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -50,7 +50,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
50
50
|
this.core = core;
|
|
51
51
|
this.hooks = options == null ? void 0 : options.hooks;
|
|
52
52
|
this.store = options == null ? void 0 : options.store;
|
|
53
|
-
this.window = core.getPlugin("window");
|
|
54
53
|
}
|
|
55
54
|
async setRulesList(rulesList) {
|
|
56
55
|
this.store.rulesList = rulesList;
|
|
@@ -72,16 +71,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
72
71
|
return false;
|
|
73
72
|
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
74
73
|
}
|
|
75
|
-
getWalletPassEvaluator() {
|
|
76
|
-
var _a, _b;
|
|
77
|
-
return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
|
|
78
|
-
}
|
|
79
74
|
// 判断discountList 是否可以对当前productList生效
|
|
80
75
|
isDiscountListAvailable({
|
|
81
76
|
oldDiscountList,
|
|
82
77
|
newDiscountList,
|
|
83
78
|
productList,
|
|
84
|
-
orderTotalAmount,
|
|
85
79
|
holders,
|
|
86
80
|
isFormSubject
|
|
87
81
|
}) {
|
|
@@ -114,7 +108,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
114
108
|
const result = this.calcDiscount({
|
|
115
109
|
discountList: mergedDiscountList,
|
|
116
110
|
productList: [...productList],
|
|
117
|
-
orderTotalAmount,
|
|
118
111
|
holders,
|
|
119
112
|
isFormSubject
|
|
120
113
|
}, {
|
|
@@ -190,8 +183,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
190
183
|
discountList,
|
|
191
184
|
productList,
|
|
192
185
|
holders,
|
|
193
|
-
isFormSubject
|
|
194
|
-
orderTotalAmount
|
|
186
|
+
isFormSubject
|
|
195
187
|
}, options) {
|
|
196
188
|
const editModeDiscount = [];
|
|
197
189
|
const addModeDiscount = [];
|
|
@@ -370,63 +362,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
370
362
|
}
|
|
371
363
|
return priceB.minus(priceA).toNumber();
|
|
372
364
|
});
|
|
373
|
-
const evaluator = this.getWalletPassEvaluator();
|
|
374
|
-
if (evaluator) {
|
|
375
|
-
addModeDiscount.forEach((discount) => {
|
|
376
|
-
var _a, _b;
|
|
377
|
-
const discountType = discount.tag || discount.type;
|
|
378
|
-
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
379
|
-
discountType
|
|
380
|
-
)) {
|
|
381
|
-
const voucher = {
|
|
382
|
-
id: discount.id,
|
|
383
|
-
amount: Number(discount.par_value || 0),
|
|
384
|
-
balance: Number(discount.balance || 0),
|
|
385
|
-
type: discountType,
|
|
386
|
-
product_id: discount.product_id,
|
|
387
|
-
unified_available_status: 1,
|
|
388
|
-
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
389
|
-
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
390
|
-
};
|
|
391
|
-
const productsForEvaluate = sortedFlattenedList.map((item) => {
|
|
392
|
-
var _a2;
|
|
393
|
-
return {
|
|
394
|
-
product_id: item.id,
|
|
395
|
-
price: item.price || 0,
|
|
396
|
-
quantity: item.quantity || item.num || 1,
|
|
397
|
-
selling_price: item.price || 0,
|
|
398
|
-
product_options: item.type === "main" ? (_a2 = item.product) == null ? void 0 : _a2.options : void 0
|
|
399
|
-
};
|
|
400
|
-
});
|
|
401
|
-
const result = evaluator.checkVoucherAvailability({
|
|
402
|
-
orderTotalAmount,
|
|
403
|
-
products: productsForEvaluate,
|
|
404
|
-
vouchers: [voucher]
|
|
405
|
-
});
|
|
406
|
-
if (result.isAvailable) {
|
|
407
|
-
discount.config = {
|
|
408
|
-
...result.config,
|
|
409
|
-
isAvailable: true
|
|
410
|
-
};
|
|
411
|
-
} else {
|
|
412
|
-
discount.config = {
|
|
413
|
-
isAvailable: false
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
365
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
420
|
-
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
421
|
-
const usedDiscountCardLimitCounts = /* @__PURE__ */ new Map();
|
|
422
|
-
editModeDiscount.forEach((discount) => {
|
|
423
|
-
var _a;
|
|
424
|
-
const discountType = discount.tag || discount.type;
|
|
425
|
-
if (["discount_card", "product_discount_card"].includes(discountType)) {
|
|
426
|
-
const currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
427
|
-
usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_a = discount.metadata) == null ? void 0 : _a.num) || 1));
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
366
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
431
367
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
432
368
|
addModeDiscount.forEach((discount) => {
|
|
@@ -566,7 +502,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
566
502
|
originProduct = flatItem.originProduct;
|
|
567
503
|
} else {
|
|
568
504
|
product = {
|
|
569
|
-
startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
|
|
570
505
|
_id: flatItem._id,
|
|
571
506
|
id: flatItem.id,
|
|
572
507
|
price: flatItem.price,
|
|
@@ -575,12 +510,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
575
510
|
total: flatItem.total,
|
|
576
511
|
origin_total: flatItem.origin_total,
|
|
577
512
|
booking_id: flatItem.booking_id,
|
|
578
|
-
discount_list: flatItem.discount_list || []
|
|
513
|
+
discount_list: flatItem.discount_list || [],
|
|
514
|
+
startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
|
|
579
515
|
};
|
|
580
516
|
originProduct = flatItem.originProduct;
|
|
581
517
|
}
|
|
582
518
|
addModeDiscount.forEach((discount) => {
|
|
583
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i
|
|
519
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
584
520
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
585
521
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
586
522
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -593,7 +529,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
593
529
|
);
|
|
594
530
|
let timeLimit = true;
|
|
595
531
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
596
|
-
const isLimitedProduct = (limitedData.type === "product_all"
|
|
532
|
+
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
597
533
|
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(
|
|
598
534
|
(discount2) => discount2.id && [
|
|
599
535
|
"good_pass",
|
|
@@ -602,8 +538,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
602
538
|
].includes(discount2.tag || discount2.type)
|
|
603
539
|
))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
|
|
604
540
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
605
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable
|
|
606
|
-
(
|
|
541
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
542
|
+
(_g = discountApplicability.get(discount.id)) == null ? void 0 : _g.push(product.id);
|
|
607
543
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
608
544
|
const discountType = discount.tag || discount.type;
|
|
609
545
|
const isGoodPass = discountType === "good_pass";
|
|
@@ -613,15 +549,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
613
549
|
type: discountType,
|
|
614
550
|
tag: discountType,
|
|
615
551
|
discount: {
|
|
616
|
-
discount_card_type: (
|
|
552
|
+
discount_card_type: (_h = discount == null ? void 0 : discount.metadata) == null ? void 0 : _h.discount_card_type,
|
|
617
553
|
fixed_amount: product.price,
|
|
618
|
-
discount_calculation_mode: (
|
|
554
|
+
discount_calculation_mode: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_calculation_mode,
|
|
619
555
|
resource_id: discount.id,
|
|
620
556
|
title: discount.format_title,
|
|
621
557
|
original_amount: product.price || product.origin_total,
|
|
622
558
|
pre_value: discount.par_value,
|
|
623
|
-
product_id: originProduct.id
|
|
624
|
-
discount_product_id: discount.product_id
|
|
559
|
+
product_id: originProduct.id
|
|
625
560
|
},
|
|
626
561
|
metadata: {
|
|
627
562
|
num,
|
|
@@ -634,102 +569,44 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
634
569
|
});
|
|
635
570
|
});
|
|
636
571
|
const processedFlatItemsMap = /* @__PURE__ */ new Map();
|
|
637
|
-
const applyDiscountToOptions = (options2, discount) => {
|
|
638
|
-
if (!(options2 == null ? void 0 : options2.length))
|
|
639
|
-
return { discountedOptions: options2, optionDiscountAmount: 0 };
|
|
640
|
-
let optionDiscountAmount = 0;
|
|
641
|
-
const discountedOptions = options2.map((option) => {
|
|
642
|
-
const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
|
|
643
|
-
const baseUnitNum = Number(rawUnit ?? 0);
|
|
644
|
-
if (baseUnitNum <= 0)
|
|
645
|
-
return option;
|
|
646
|
-
const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
|
|
647
|
-
const optQty = Number(option.num ?? option.quantity ?? 1);
|
|
648
|
-
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
649
|
-
const { _original_add_price, ...rest } = option;
|
|
650
|
-
const tmpl = rest.price ?? rest.add_price;
|
|
651
|
-
const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
|
|
652
|
-
return {
|
|
653
|
-
...rest,
|
|
654
|
-
_original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
|
|
655
|
-
price: nextPrice
|
|
656
|
-
};
|
|
657
|
-
});
|
|
658
|
-
return { discountedOptions, optionDiscountAmount };
|
|
659
|
-
};
|
|
660
|
-
const restoreOptionPrices = (options2) => {
|
|
661
|
-
if (!(options2 == null ? void 0 : options2.length))
|
|
662
|
-
return options2;
|
|
663
|
-
return options2.map((option) => {
|
|
664
|
-
const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
|
|
665
|
-
if (orig !== void 0) {
|
|
666
|
-
const { _original_price, _original_add_price, ...rest } = option;
|
|
667
|
-
return { ...rest, price: orig };
|
|
668
|
-
}
|
|
669
|
-
return option;
|
|
670
|
-
});
|
|
671
|
-
};
|
|
672
|
-
const getOptionTotal = (options2) => {
|
|
673
|
-
if (!(options2 == null ? void 0 : options2.length))
|
|
674
|
-
return 0;
|
|
675
|
-
return options2.reduce((sum, opt) => {
|
|
676
|
-
const unit = Number(opt.price ?? opt.add_price ?? 0);
|
|
677
|
-
const n = Number(opt.num ?? opt.quantity ?? 1);
|
|
678
|
-
return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
|
|
679
|
-
}, 0);
|
|
680
|
-
};
|
|
681
572
|
sortedFlattenedList.forEach((flatItem, index) => {
|
|
682
|
-
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, _z, _A, _B, _C
|
|
573
|
+
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, _z, _A, _B, _C;
|
|
683
574
|
let product, originProduct;
|
|
684
575
|
if (flatItem.type === "main") {
|
|
685
576
|
product = flatItem.product;
|
|
686
577
|
originProduct = flatItem.originProduct;
|
|
687
578
|
} else {
|
|
688
579
|
product = {
|
|
689
|
-
startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
|
|
690
580
|
_id: flatItem._id,
|
|
691
581
|
id: flatItem.id,
|
|
692
582
|
price: flatItem.price,
|
|
693
583
|
quantity: flatItem.quantity,
|
|
694
584
|
num: flatItem.num,
|
|
695
585
|
total: flatItem.total,
|
|
696
|
-
original_price: (
|
|
697
|
-
origin_total: (
|
|
586
|
+
original_price: (_a = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _a.original_price,
|
|
587
|
+
origin_total: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
|
|
698
588
|
booking_id: flatItem.booking_id,
|
|
699
|
-
discount_list: ((
|
|
589
|
+
discount_list: ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) || [],
|
|
590
|
+
startDate: (_d = flatItem.parentProduct) == null ? void 0 : _d.startDate
|
|
700
591
|
};
|
|
701
592
|
originProduct = flatItem.originProduct;
|
|
702
593
|
}
|
|
703
|
-
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(
|
|
704
|
-
(discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
|
|
705
|
-
discount.tag || discount.type
|
|
706
|
-
)
|
|
707
|
-
))) {
|
|
594
|
+
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((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
708
595
|
if (flatItem.type === "main") {
|
|
709
596
|
processedProductsMap.set(product._id, [originProduct]);
|
|
710
597
|
} else {
|
|
711
|
-
processedFlatItemsMap.set(flatItem._id, [
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
]);
|
|
598
|
+
processedFlatItemsMap.set(flatItem._id, [{
|
|
599
|
+
...flatItem,
|
|
600
|
+
processed: true
|
|
601
|
+
}]);
|
|
717
602
|
}
|
|
718
603
|
return;
|
|
719
604
|
}
|
|
720
605
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
721
|
-
var _a2, _b2
|
|
722
|
-
|
|
723
|
-
if (["good_pass", "discount_card", "product_discount_card"].includes(
|
|
724
|
-
discountType2
|
|
725
|
-
)) {
|
|
726
|
-
if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
|
|
727
|
-
return false;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
|
|
606
|
+
var _a2, _b2;
|
|
607
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.length) && (discount.tag || discount.type) === "good_pass")
|
|
731
608
|
return false;
|
|
732
|
-
if ((Number(product.
|
|
609
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
|
|
733
610
|
var _a3;
|
|
734
611
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
735
612
|
})) && (discount.tag || discount.type) !== "good_pass")
|
|
@@ -737,25 +614,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
737
614
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
738
615
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
739
616
|
return false;
|
|
740
|
-
if ((discount.tag || discount.type) === "good_pass") {
|
|
741
|
-
const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
|
|
742
|
-
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
743
|
-
const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
744
|
-
if (currentUsedCount >= maxUsagePerOrder) {
|
|
745
|
-
return false;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
const discountTypeForLimit = discount.tag || discount.type;
|
|
750
|
-
if (["discount_card", "product_discount_card"].includes(discountTypeForLimit)) {
|
|
751
|
-
const applicableProductLimitConfig = ((_e2 = discount.config) == null ? void 0 : _e2.applicableProductLimit) || 0;
|
|
752
|
-
if (applicableProductLimitConfig > 0) {
|
|
753
|
-
const currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
754
|
-
if (currentUsedLimitCount >= applicableProductLimitConfig) {
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
617
|
const limitedData = discount.limited_relation_product_data;
|
|
760
618
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
761
619
|
const isHolderMatch = this.checkHolderMatch(
|
|
@@ -774,9 +632,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
774
632
|
return false;
|
|
775
633
|
}
|
|
776
634
|
if (limitedData.type === "product_all") {
|
|
777
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
635
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
781
636
|
return false;
|
|
782
637
|
}
|
|
@@ -789,36 +644,21 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
789
644
|
}
|
|
790
645
|
return false;
|
|
791
646
|
});
|
|
792
|
-
const selectedDiscountCard = applicableDiscounts.find(
|
|
793
|
-
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
794
|
-
);
|
|
647
|
+
const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
|
|
795
648
|
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
796
649
|
let isManualDiscount = false;
|
|
797
650
|
if (flatItem.type === "main") {
|
|
798
|
-
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
) && (!((_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(
|
|
804
|
-
_h,
|
|
805
|
-
(item) => item.type === "product"
|
|
806
|
-
)));
|
|
807
|
-
if (product.inPromotion) {
|
|
808
|
-
isManualDiscount = false;
|
|
809
|
-
}
|
|
651
|
+
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
|
|
652
|
+
var _a2;
|
|
653
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
654
|
+
}) && (!((_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(_h, (item) => item.type === "product")));
|
|
810
655
|
} else {
|
|
811
656
|
const parentProduct = flatItem.parentProduct;
|
|
812
657
|
if (parentProduct) {
|
|
813
|
-
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
) && (!((_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(
|
|
819
|
-
_k,
|
|
820
|
-
(item) => item.type === "product"
|
|
821
|
-
)));
|
|
658
|
+
isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
|
|
659
|
+
var _a2;
|
|
660
|
+
return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
|
|
661
|
+
}) && (!((_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(_k, (item) => item.type === "product")));
|
|
822
662
|
}
|
|
823
663
|
}
|
|
824
664
|
if (options == null ? void 0 : options.discountId) {
|
|
@@ -870,17 +710,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
870
710
|
}
|
|
871
711
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
872
712
|
if (flatItem.type === "main") {
|
|
873
|
-
const restoredOptions = restoreOptionPrices(product.options);
|
|
874
713
|
if (product.isClient) {
|
|
875
|
-
processedProductsMap.set(
|
|
876
|
-
|
|
714
|
+
processedProductsMap.set(
|
|
715
|
+
product._id,
|
|
716
|
+
[this.hooks.setProduct(originProduct, {
|
|
877
717
|
...isManualDiscount ? {} : {
|
|
878
718
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
879
719
|
product: {
|
|
880
720
|
original_price: product.original_price
|
|
881
721
|
},
|
|
882
722
|
bundle: product.bundle,
|
|
883
|
-
options:
|
|
723
|
+
options: product.options
|
|
884
724
|
}),
|
|
885
725
|
variant: originProduct._productInit.variant,
|
|
886
726
|
original_price: originProduct._productInit.original_price,
|
|
@@ -889,14 +729,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
889
729
|
price: product.price
|
|
890
730
|
},
|
|
891
731
|
bundle: product.bundle,
|
|
892
|
-
options:
|
|
732
|
+
options: product.options
|
|
893
733
|
}),
|
|
894
734
|
price: product.price,
|
|
895
|
-
options:
|
|
735
|
+
options: product.options
|
|
896
736
|
},
|
|
897
737
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
|
|
898
|
-
})
|
|
899
|
-
|
|
738
|
+
})]
|
|
739
|
+
);
|
|
900
740
|
} else {
|
|
901
741
|
let total = product.inPromotion ? ((_u = product == null ? void 0 : product._promotion) == null ? void 0 : _u.finalPrice) ?? product.origin_total ?? product.total : product.origin_total ?? product.total;
|
|
902
742
|
let main_product_selling_price = product.price ?? product.main_product_selling_price;
|
|
@@ -906,20 +746,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
906
746
|
}
|
|
907
747
|
processedProductsMap.set(
|
|
908
748
|
product._id,
|
|
909
|
-
[
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
]
|
|
749
|
+
[this.hooks.setProduct(originProduct, {
|
|
750
|
+
...isManualDiscount ? {
|
|
751
|
+
price: product.price
|
|
752
|
+
} : {
|
|
753
|
+
_id: product._id.split("___")[0] + "___" + index,
|
|
754
|
+
origin_total: product.origin_total,
|
|
755
|
+
total,
|
|
756
|
+
original_price: product.original_price,
|
|
757
|
+
price: product.price,
|
|
758
|
+
main_product_selling_price
|
|
759
|
+
},
|
|
760
|
+
discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
|
|
761
|
+
})]
|
|
923
762
|
);
|
|
924
763
|
}
|
|
925
764
|
} else {
|
|
@@ -935,166 +774,104 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
935
774
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
|
|
936
775
|
return;
|
|
937
776
|
}
|
|
938
|
-
const
|
|
939
|
-
const isGoodPass = discountType === "good_pass";
|
|
940
|
-
const isDiscountCard = ["discount_card", "product_discount_card"].includes(discountType);
|
|
941
|
-
const applicableProductLimit = ((_w = selectedDiscount.config) == null ? void 0 : _w.applicableProductLimit) || 0;
|
|
942
|
-
const isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
|
|
777
|
+
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
943
778
|
const totalQuantity = product.quantity || product.num || 1;
|
|
944
|
-
const availableGoodPassCount = applicableDiscounts.filter(
|
|
945
|
-
|
|
946
|
-
).length;
|
|
947
|
-
let maxUsageLimit;
|
|
948
|
-
if (isGoodPass) {
|
|
949
|
-
maxUsageLimit = availableGoodPassCount;
|
|
950
|
-
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
951
|
-
maxUsageLimit = Math.min(
|
|
952
|
-
availableGoodPassCount,
|
|
953
|
-
selectedDiscount.config.maxUsagePerOrder
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
} else if (isDiscountCard && applicableProductLimit > 0) {
|
|
957
|
-
const usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
|
|
958
|
-
maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
|
|
959
|
-
} else {
|
|
960
|
-
maxUsageLimit = 1;
|
|
961
|
-
}
|
|
962
|
-
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
779
|
+
const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
|
|
780
|
+
const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
963
781
|
const arr = [];
|
|
964
782
|
if (flatItem.type === "main") {
|
|
965
783
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
this.hooks.setProduct(originProduct, {
|
|
972
|
-
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
973
|
-
quantity: totalQuantity - splitCount,
|
|
974
|
-
_id: product._id.split("___")[0],
|
|
975
|
-
total
|
|
976
|
-
})
|
|
977
|
-
);
|
|
784
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
785
|
+
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
786
|
+
quantity: totalQuantity - splitCount,
|
|
787
|
+
_id: product._id.split("___")[0]
|
|
788
|
+
}));
|
|
978
789
|
}
|
|
979
790
|
for (let i = 0; i < splitCount; i++) {
|
|
980
|
-
const
|
|
981
|
-
usedDiscounts.set(
|
|
982
|
-
|
|
983
|
-
const currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
|
|
984
|
-
usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
|
|
985
|
-
}
|
|
986
|
-
const currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
|
|
987
|
-
if (["discount_card", "product_discount_card"].includes(currentDiscountTypeForCount)) {
|
|
988
|
-
const currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
|
|
989
|
-
usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
|
|
990
|
-
}
|
|
991
|
-
const appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
|
|
791
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
792
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
793
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
992
794
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
993
795
|
if (this.filterDiscountListByType(product.discount_list, "promotion").length && product.origin_total) {
|
|
994
796
|
productOriginTotal = product.origin_total;
|
|
995
797
|
}
|
|
996
|
-
if (Number(((
|
|
798
|
+
if (Number(((_w = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _w.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
997
799
|
productOriginTotal = product.total;
|
|
998
800
|
}
|
|
999
|
-
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(
|
|
1000
|
-
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
801
|
+
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
|
|
802
|
+
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
|
|
1001
803
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1002
|
-
|
|
1003
|
-
let mainProductSellingPrice;
|
|
804
|
+
let targetProductTotal;
|
|
1004
805
|
let amount;
|
|
1005
806
|
let productDiscountDifference;
|
|
1006
|
-
let discountedOptions = product.options;
|
|
1007
|
-
let optionDiscountAmount = 0;
|
|
1008
807
|
if (isOrderLevel && productAllocation) {
|
|
1009
808
|
amount = productAllocation.discountAmount;
|
|
1010
809
|
productDiscountDifference = productAllocation.difference;
|
|
1011
|
-
|
|
810
|
+
targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
|
|
1012
811
|
} else {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
product.price,
|
|
1016
|
-
product.price
|
|
1017
|
-
);
|
|
1018
|
-
amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
|
|
1019
|
-
}
|
|
1020
|
-
if (isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length)) {
|
|
1021
|
-
const optionResult = applyDiscountToOptions(
|
|
1022
|
-
product.options,
|
|
1023
|
-
currentSelectedDiscount
|
|
1024
|
-
);
|
|
1025
|
-
discountedOptions = optionResult.discountedOptions;
|
|
1026
|
-
optionDiscountAmount = optionResult.optionDiscountAmount;
|
|
812
|
+
targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
|
|
813
|
+
amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
1027
814
|
}
|
|
1028
|
-
const
|
|
1029
|
-
const
|
|
1030
|
-
const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
|
|
1031
|
-
const mainProductDiscountAmount = amount;
|
|
1032
|
-
const lineDiscountAmount = new import_decimal.default(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
|
|
1033
|
-
const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
|
|
1034
|
-
const discountType2 = selectedDiscount.tag || selectedDiscount.type;
|
|
1035
|
-
const currentIsGoodPass = currentDiscountType === "good_pass";
|
|
815
|
+
const discountType = selectedDiscount2.tag || selectedDiscount2.type;
|
|
816
|
+
const isGoodPass = discountType === "good_pass";
|
|
1036
817
|
const discountDetail = {
|
|
1037
|
-
amount
|
|
1038
|
-
type:
|
|
818
|
+
amount,
|
|
819
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
|
|
1039
820
|
discount: {
|
|
1040
|
-
discount_card_type: (
|
|
1041
|
-
fixed_amount:
|
|
1042
|
-
discount_calculation_mode: (
|
|
1043
|
-
resource_id:
|
|
1044
|
-
title:
|
|
821
|
+
discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
|
|
822
|
+
fixed_amount: amount,
|
|
823
|
+
discount_calculation_mode: (_y = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _y.discount_calculation_mode,
|
|
824
|
+
resource_id: selectedDiscount2.id,
|
|
825
|
+
title: selectedDiscount2.format_title,
|
|
1045
826
|
original_amount: product.price,
|
|
1046
827
|
product_id: originProduct.id,
|
|
1047
|
-
percent:
|
|
1048
|
-
discount_product_id: currentSelectedDiscount.product_id
|
|
828
|
+
percent: selectedDiscount2.par_value
|
|
1049
829
|
},
|
|
1050
|
-
// 前端使用的num
|
|
1051
|
-
_num:
|
|
1052
|
-
config: currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.config,
|
|
830
|
+
// 前端使用的num数量,为了计算优惠金额
|
|
831
|
+
_num: isGoodPass ? 1 : product.num,
|
|
1053
832
|
metadata: {
|
|
1054
833
|
num: 1,
|
|
1055
|
-
discount_rule_uncheck_flag:
|
|
834
|
+
discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
|
|
1056
835
|
// 🔥 order_level 分摊差值
|
|
1057
|
-
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1058
|
-
/** 仅主商品上的优惠金额(不含 option) */
|
|
1059
|
-
mainProductDiscountAmount,
|
|
1060
|
-
optionDiscountAmount
|
|
836
|
+
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1061
837
|
}
|
|
1062
838
|
};
|
|
1063
839
|
appliedProducts.push(discountDetail);
|
|
1064
|
-
appliedDiscountProducts.set(
|
|
840
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
841
|
+
let total = targetProductTotal;
|
|
842
|
+
if (product.options) {
|
|
843
|
+
total = product.options.reduce((accumulator, currentValue) => {
|
|
844
|
+
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
845
|
+
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
846
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
847
|
+
}, new import_decimal.default(total)).toNumber();
|
|
848
|
+
}
|
|
1065
849
|
if (product.isClient) {
|
|
1066
|
-
arr.push(
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
total,
|
|
1082
|
-
options: discountedOptions
|
|
1083
|
-
})
|
|
1084
|
-
);
|
|
850
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
851
|
+
discount_list: [discountDetail],
|
|
852
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
853
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
854
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
855
|
+
product: {
|
|
856
|
+
original_price: product.original_price
|
|
857
|
+
},
|
|
858
|
+
bundle: product.bundle,
|
|
859
|
+
options: product.options
|
|
860
|
+
}),
|
|
861
|
+
variant: originProduct._productInit.variant,
|
|
862
|
+
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
863
|
+
total
|
|
864
|
+
}));
|
|
1085
865
|
} else {
|
|
1086
|
-
arr.push(
|
|
1087
|
-
this.
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
options: discountedOptions
|
|
1096
|
-
})
|
|
1097
|
-
);
|
|
866
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
867
|
+
discount_list: this.filterDiscountListByType(product.discount_list, "promotion").concat([discountDetail]),
|
|
868
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
|
|
869
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
870
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
871
|
+
total,
|
|
872
|
+
origin_total: productOriginTotal,
|
|
873
|
+
main_product_selling_price: targetProductTotal
|
|
874
|
+
}));
|
|
1098
875
|
}
|
|
1099
876
|
}
|
|
1100
877
|
processedProductsMap.set(product._id, arr);
|
|
@@ -1104,298 +881,62 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1104
881
|
const discountNum = splitCount;
|
|
1105
882
|
const normalNum = totalQuantity - discountNum;
|
|
1106
883
|
for (let i = 0; i < discountNum; i++) {
|
|
1107
|
-
const
|
|
1108
|
-
usedDiscounts.set(
|
|
1109
|
-
if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
|
|
1110
|
-
const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
|
|
1111
|
-
usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
|
|
1112
|
-
}
|
|
1113
|
-
const bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1114
|
-
if (["discount_card", "product_discount_card"].includes(bundleDiscountTypeForCount)) {
|
|
1115
|
-
const currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1116
|
-
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
|
|
1117
|
-
}
|
|
884
|
+
const selectedDiscount2 = applicableDiscounts[i];
|
|
885
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
1118
886
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
1119
|
-
const discountedPrice = (0, import_utils.getDiscountAmount)(
|
|
1120
|
-
currentBundleDiscount,
|
|
1121
|
-
product.origin_total,
|
|
1122
|
-
product.origin_total
|
|
1123
|
-
);
|
|
1124
|
-
const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
1125
|
-
const bundleDiscountType = currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag;
|
|
1126
887
|
const discountDetail = {
|
|
1127
|
-
amount:
|
|
1128
|
-
type:
|
|
888
|
+
amount: product.origin_total,
|
|
889
|
+
type: "good_pass",
|
|
1129
890
|
discount: {
|
|
1130
|
-
|
|
1131
|
-
discount_calculation_mode: (
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
title: currentBundleDiscount.format_title,
|
|
891
|
+
fixed_amount: product.origin_total,
|
|
892
|
+
discount_calculation_mode: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_calculation_mode,
|
|
893
|
+
resource_id: selectedDiscount2.id,
|
|
894
|
+
title: selectedDiscount2.format_title,
|
|
1135
895
|
original_amount: product.origin_total,
|
|
1136
|
-
product_id: product.id
|
|
1137
|
-
percent: currentBundleDiscount.par_value,
|
|
1138
|
-
discount_product_id: currentBundleDiscount.product_id
|
|
896
|
+
product_id: product.id
|
|
1139
897
|
},
|
|
1140
898
|
metadata: {
|
|
1141
899
|
// 🔥 使用拆分后的唯一 _id
|
|
1142
900
|
custom_product_bundle_map_id: uniqueId,
|
|
1143
|
-
discount_rule_uncheck_flag:
|
|
901
|
+
discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
|
|
1144
902
|
num: 1
|
|
1145
903
|
},
|
|
1146
|
-
_num: 1
|
|
1147
|
-
config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config
|
|
904
|
+
_num: 1
|
|
1148
905
|
};
|
|
1149
|
-
const appliedProducts = appliedDiscountProducts.get(
|
|
906
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
1150
907
|
appliedProducts.push(discountDetail);
|
|
1151
|
-
appliedDiscountProducts.set(
|
|
908
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
1152
909
|
processedItems.push({
|
|
1153
910
|
...flatItem,
|
|
1154
911
|
// 🔥 使用唯一的 _id
|
|
1155
912
|
_id: uniqueId,
|
|
1156
913
|
num: 1,
|
|
1157
914
|
quantity: 1,
|
|
1158
|
-
price:
|
|
1159
|
-
//
|
|
1160
|
-
total:
|
|
915
|
+
price: 0,
|
|
916
|
+
// 商品券价格为0
|
|
917
|
+
total: 0,
|
|
1161
918
|
discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion").concat([discountDetail]),
|
|
1162
919
|
processed: true,
|
|
1163
|
-
_discountId:
|
|
920
|
+
_discountId: selectedDiscount2.id
|
|
1164
921
|
});
|
|
1165
922
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
if ((Number(product.total) <= 0 || !product.total) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find(
|
|
1178
|
-
(n) => {
|
|
1179
|
-
var _a3;
|
|
1180
|
-
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === nextDiscount.id;
|
|
1181
|
-
}
|
|
1182
|
-
)) && nextDiscountType !== "good_pass")
|
|
1183
|
-
return false;
|
|
1184
|
-
if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === "good_pass")
|
|
1185
|
-
return false;
|
|
1186
|
-
if (nextDiscountType === "good_pass") {
|
|
1187
|
-
const maxUsagePerOrder = (_c2 = nextDiscount.config) == null ? void 0 : _c2.maxUsagePerOrder;
|
|
1188
|
-
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1189
|
-
const currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
|
|
1190
|
-
if (currentUsedCount >= maxUsagePerOrder) {
|
|
1191
|
-
return false;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
if (["discount_card", "product_discount_card"].includes(nextDiscountType)) {
|
|
1196
|
-
const limitConfig = ((_d2 = nextDiscount.config) == null ? void 0 : _d2.applicableProductLimit) || 0;
|
|
1197
|
-
if (limitConfig > 0) {
|
|
1198
|
-
const currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
|
|
1199
|
-
if (currentUsedLimitCount >= limitConfig) {
|
|
1200
|
-
return false;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
const limitedData = nextDiscount.limited_relation_product_data;
|
|
1205
|
-
if (limitedData.type === "product_all") {
|
|
1206
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1207
|
-
return false;
|
|
1208
|
-
}
|
|
1209
|
-
if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1210
|
-
return false;
|
|
1211
|
-
}
|
|
1212
|
-
return true;
|
|
1213
|
-
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1214
|
-
if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1215
|
-
return false;
|
|
1216
|
-
}
|
|
1217
|
-
return true;
|
|
1218
|
-
}
|
|
1219
|
-
return false;
|
|
923
|
+
if (normalNum > 0) {
|
|
924
|
+
processedItems.push({
|
|
925
|
+
...flatItem,
|
|
926
|
+
// 🔥 为剩余商品生成唯一的 _id
|
|
927
|
+
_id: `${flatItem._id}_split_rest`,
|
|
928
|
+
num: normalNum,
|
|
929
|
+
quantity: normalNum,
|
|
930
|
+
discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion"),
|
|
931
|
+
processed: true
|
|
1220
932
|
});
|
|
1221
|
-
if (nextApplicableDiscounts.length === 0) {
|
|
1222
|
-
processedItems.push({
|
|
1223
|
-
...flatItem,
|
|
1224
|
-
_id: `${flatItem._id}_split_rest`,
|
|
1225
|
-
num: remainingNum,
|
|
1226
|
-
quantity: remainingNum,
|
|
1227
|
-
discount_list: [],
|
|
1228
|
-
processed: true
|
|
1229
|
-
});
|
|
1230
|
-
break;
|
|
1231
|
-
}
|
|
1232
|
-
const nextSelectedDiscountCard = nextApplicableDiscounts.find(
|
|
1233
|
-
(n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
|
|
1234
|
-
);
|
|
1235
|
-
const nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1236
|
-
const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
|
|
1237
|
-
const nextIsGoodPass = nextDiscType === "good_pass";
|
|
1238
|
-
const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
|
|
1239
|
-
const nextApplicableProductLimit = ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.applicableProductLimit) || 0;
|
|
1240
|
-
const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
|
|
1241
|
-
if (!nextIsNeedSplit) {
|
|
1242
|
-
const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1243
|
-
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1244
|
-
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
|
|
1245
|
-
const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1246
|
-
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1247
|
-
}
|
|
1248
|
-
const nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1249
|
-
if (["discount_card", "product_discount_card"].includes(nextNoSplitType)) {
|
|
1250
|
-
const curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1251
|
-
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curCount + remainingNum);
|
|
1252
|
-
}
|
|
1253
|
-
const nextOriginTotal = product.original_price || product.price || 0;
|
|
1254
|
-
const nextTargetTotal = (0, import_utils.getDiscountAmount)(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
|
|
1255
|
-
const nextDiscountAmount = new import_decimal.default(nextOriginTotal).minus(nextTargetTotal).toNumber();
|
|
1256
|
-
const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
|
|
1257
|
-
const nextBundleDiscType = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
|
|
1258
|
-
const nextDiscountDetail = {
|
|
1259
|
-
amount: nextDiscountAmount * remainingNum,
|
|
1260
|
-
type: nextBundleDiscType,
|
|
1261
|
-
discount: {
|
|
1262
|
-
discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
|
|
1263
|
-
fixed_amount: nextDiscountAmount,
|
|
1264
|
-
resource_id: nextBundleDiscount.id,
|
|
1265
|
-
title: nextBundleDiscount.format_title,
|
|
1266
|
-
original_amount: product.original_price,
|
|
1267
|
-
product_id: product.id,
|
|
1268
|
-
percent: nextBundleDiscount.par_value,
|
|
1269
|
-
discount_product_id: nextBundleDiscount.product_id
|
|
1270
|
-
},
|
|
1271
|
-
metadata: {
|
|
1272
|
-
custom_product_bundle_map_id: nextUniqueId,
|
|
1273
|
-
num: remainingNum
|
|
1274
|
-
},
|
|
1275
|
-
config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
|
|
1276
|
-
_num: remainingNum * (((_H = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _H.num) || 1)
|
|
1277
|
-
};
|
|
1278
|
-
const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1279
|
-
nextAppliedProducts.push(nextDiscountDetail);
|
|
1280
|
-
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1281
|
-
processedItems.push({
|
|
1282
|
-
...flatItem,
|
|
1283
|
-
_id: nextUniqueId,
|
|
1284
|
-
num: remainingNum,
|
|
1285
|
-
quantity: remainingNum,
|
|
1286
|
-
total: nextTargetTotal,
|
|
1287
|
-
price: new import_decimal.default(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
|
|
1288
|
-
discount_list: [nextDiscountDetail],
|
|
1289
|
-
processed: true
|
|
1290
|
-
});
|
|
1291
|
-
remainingNum = 0;
|
|
1292
|
-
break;
|
|
1293
|
-
}
|
|
1294
|
-
let nextMaxUsageLimit;
|
|
1295
|
-
if (nextIsGoodPass) {
|
|
1296
|
-
const nextGoodPassCount = nextApplicableDiscounts.filter(
|
|
1297
|
-
(item) => (item.tag || item.type) === "good_pass"
|
|
1298
|
-
).length;
|
|
1299
|
-
nextMaxUsageLimit = nextGoodPassCount;
|
|
1300
|
-
if ((_I = nextSelectedDiscount.config) == null ? void 0 : _I.maxUsagePerOrder) {
|
|
1301
|
-
const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
|
|
1302
|
-
nextMaxUsageLimit = Math.min(
|
|
1303
|
-
nextGoodPassCount,
|
|
1304
|
-
Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount)
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
} else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
|
|
1308
|
-
const usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
|
|
1309
|
-
nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - usedLimitCount);
|
|
1310
|
-
} else {
|
|
1311
|
-
nextMaxUsageLimit = 1;
|
|
1312
|
-
}
|
|
1313
|
-
const nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
|
|
1314
|
-
if (nextSplitCount === 0) {
|
|
1315
|
-
processedItems.push({
|
|
1316
|
-
...flatItem,
|
|
1317
|
-
_id: `${flatItem._id}_split_rest`,
|
|
1318
|
-
num: remainingNum,
|
|
1319
|
-
quantity: remainingNum,
|
|
1320
|
-
discount_list: this.filterDiscountListByType(flatItem.discount_list, "promotion"),
|
|
1321
|
-
processed: true
|
|
1322
|
-
});
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
for (let j = 0; j < nextSplitCount; j++) {
|
|
1326
|
-
const nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1327
|
-
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1328
|
-
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
|
|
1329
|
-
const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1330
|
-
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1331
|
-
}
|
|
1332
|
-
const nextBundleDiscTypeForCount = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1333
|
-
if (["discount_card", "product_discount_card"].includes(nextBundleDiscTypeForCount)) {
|
|
1334
|
-
const curLimitCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1335
|
-
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curLimitCount + 1);
|
|
1336
|
-
}
|
|
1337
|
-
const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
|
|
1338
|
-
const nextDiscountedPrice = (0, import_utils.getDiscountAmount)(
|
|
1339
|
-
nextBundleDiscount,
|
|
1340
|
-
product.origin_total,
|
|
1341
|
-
product.origin_total
|
|
1342
|
-
);
|
|
1343
|
-
const nextBundleDiscAmount = new import_decimal.default(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
|
|
1344
|
-
const nextBundleDiscTypeStr = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
|
|
1345
|
-
const nextDiscountDetail = {
|
|
1346
|
-
amount: nextBundleDiscAmount,
|
|
1347
|
-
type: nextBundleDiscTypeStr,
|
|
1348
|
-
discount: {
|
|
1349
|
-
discount_card_type: (_J = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _J.discount_card_type,
|
|
1350
|
-
fixed_amount: nextBundleDiscAmount,
|
|
1351
|
-
resource_id: nextBundleDiscount.id,
|
|
1352
|
-
title: nextBundleDiscount.format_title,
|
|
1353
|
-
original_amount: product.origin_total,
|
|
1354
|
-
product_id: product.id,
|
|
1355
|
-
percent: nextBundleDiscount.par_value,
|
|
1356
|
-
discount_product_id: nextBundleDiscount.product_id
|
|
1357
|
-
},
|
|
1358
|
-
metadata: {
|
|
1359
|
-
custom_product_bundle_map_id: nextUniqueId,
|
|
1360
|
-
num: 1
|
|
1361
|
-
},
|
|
1362
|
-
_num: 1,
|
|
1363
|
-
config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config
|
|
1364
|
-
};
|
|
1365
|
-
const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1366
|
-
nextAppliedProducts.push(nextDiscountDetail);
|
|
1367
|
-
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1368
|
-
processedItems.push({
|
|
1369
|
-
...flatItem,
|
|
1370
|
-
_id: nextUniqueId,
|
|
1371
|
-
num: 1,
|
|
1372
|
-
quantity: 1,
|
|
1373
|
-
price: nextDiscountedPrice,
|
|
1374
|
-
total: nextDiscountedPrice,
|
|
1375
|
-
discount_list: [nextDiscountDetail],
|
|
1376
|
-
processed: true,
|
|
1377
|
-
_discountId: nextBundleDiscount.id
|
|
1378
|
-
});
|
|
1379
|
-
continueSplitIndex++;
|
|
1380
|
-
}
|
|
1381
|
-
remainingNum -= nextSplitCount;
|
|
1382
933
|
}
|
|
1383
934
|
} else {
|
|
1384
|
-
const
|
|
1385
|
-
usedDiscounts.set(
|
|
1386
|
-
if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
|
|
1387
|
-
const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
|
|
1388
|
-
usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
|
|
1389
|
-
}
|
|
1390
|
-
const noSplitDiscountType = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1391
|
-
if (["discount_card", "product_discount_card"].includes(noSplitDiscountType)) {
|
|
1392
|
-
const bundleQuantity = product.num || 1;
|
|
1393
|
-
const currentNoSplitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1394
|
-
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
|
|
1395
|
-
}
|
|
935
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
936
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
1396
937
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
1397
|
-
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(
|
|
1398
|
-
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
938
|
+
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
|
|
939
|
+
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
|
|
1399
940
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1400
941
|
let targetProductTotal;
|
|
1401
942
|
let fixedAmountPerItem;
|
|
@@ -1406,42 +947,39 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1406
947
|
targetProductTotal = Math.max(new import_decimal.default(productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1407
948
|
} else {
|
|
1408
949
|
targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
1409
|
-
|
|
950
|
+
selectedDiscount2,
|
|
1410
951
|
productOriginTotal,
|
|
1411
952
|
productOriginTotal
|
|
1412
953
|
);
|
|
1413
954
|
fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1414
955
|
}
|
|
1415
|
-
const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1416
956
|
const uniqueId = flatItem._id;
|
|
1417
957
|
const discountDetail = {
|
|
1418
|
-
amount:
|
|
1419
|
-
type:
|
|
958
|
+
amount: fixedAmountPerItem * (product.num || 1),
|
|
959
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
1420
960
|
discount: {
|
|
1421
|
-
discount_card_type: (
|
|
1422
|
-
fixed_amount:
|
|
1423
|
-
discount_calculation_mode: (
|
|
1424
|
-
resource_id:
|
|
1425
|
-
title:
|
|
961
|
+
discount_card_type: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_card_type,
|
|
962
|
+
fixed_amount: fixedAmountPerItem,
|
|
963
|
+
discount_calculation_mode: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_calculation_mode,
|
|
964
|
+
resource_id: selectedDiscount2.id,
|
|
965
|
+
title: selectedDiscount2.format_title,
|
|
1426
966
|
original_amount: product.original_price,
|
|
1427
967
|
product_id: product.id,
|
|
1428
|
-
percent:
|
|
1429
|
-
discount_product_id: currentBundleDiscount.product_id
|
|
968
|
+
percent: selectedDiscount2.par_value
|
|
1430
969
|
},
|
|
1431
970
|
metadata: {
|
|
1432
971
|
// 🔥 使用唯一的 _id
|
|
1433
972
|
custom_product_bundle_map_id: uniqueId,
|
|
1434
|
-
discount_rule_uncheck_flag:
|
|
973
|
+
discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
|
|
1435
974
|
num: product.num || 1,
|
|
1436
975
|
// 🔥 order_level 分摊差值
|
|
1437
976
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1438
977
|
},
|
|
1439
|
-
|
|
1440
|
-
_num: (product.num || 1) * (((_M = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _M.num) || 1)
|
|
978
|
+
_num: (product.num || 1) * (((_C = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _C.num) || 1)
|
|
1441
979
|
};
|
|
1442
|
-
const appliedProducts = appliedDiscountProducts.get(
|
|
980
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
1443
981
|
appliedProducts.push(discountDetail);
|
|
1444
|
-
appliedDiscountProducts.set(
|
|
982
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
1445
983
|
processedItems.push({
|
|
1446
984
|
...flatItem,
|
|
1447
985
|
total: targetProductTotal,
|
|
@@ -1460,7 +998,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1460
998
|
const mainProductArr = processedProductsMap2.get(product._id);
|
|
1461
999
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1462
1000
|
const getDefaultProduct = () => {
|
|
1463
|
-
const restoredOptions = restoreOptionPrices(product.options);
|
|
1464
1001
|
if (product.isClient) {
|
|
1465
1002
|
return this.hooks.setProduct(originProduct, {
|
|
1466
1003
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
@@ -1470,7 +1007,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1470
1007
|
original_price: product.original_price
|
|
1471
1008
|
},
|
|
1472
1009
|
bundle: product.bundle,
|
|
1473
|
-
options:
|
|
1010
|
+
options: product.options
|
|
1474
1011
|
}),
|
|
1475
1012
|
variant: originProduct._productInit.variant,
|
|
1476
1013
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1479,17 +1016,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1479
1016
|
price: product.price
|
|
1480
1017
|
},
|
|
1481
1018
|
bundle: product.bundle,
|
|
1482
|
-
options:
|
|
1483
|
-
})
|
|
1484
|
-
options: restoredOptions
|
|
1019
|
+
options: product.options
|
|
1020
|
+
})
|
|
1485
1021
|
});
|
|
1486
1022
|
} else {
|
|
1487
1023
|
return this.hooks.setProduct(originProduct, {
|
|
1488
1024
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
1489
1025
|
total: product.total,
|
|
1490
1026
|
origin_total: product.origin_total,
|
|
1491
|
-
price: product.price
|
|
1492
|
-
options: restoreOptionPrices(product.options)
|
|
1027
|
+
price: product.price
|
|
1493
1028
|
});
|
|
1494
1029
|
}
|
|
1495
1030
|
};
|
|
@@ -1529,92 +1064,80 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1529
1064
|
const mainProduct = mainProductArr[0];
|
|
1530
1065
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1531
1066
|
const newBundleWithDiscount = [];
|
|
1532
|
-
(product.bundle || []).forEach(
|
|
1533
|
-
(
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
metadata:
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1067
|
+
(product.bundle || []).forEach((bundleItem, bundleIndex) => {
|
|
1068
|
+
const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
|
|
1069
|
+
if (processedItems.length > 1) {
|
|
1070
|
+
processedItems.forEach((item) => {
|
|
1071
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1072
|
+
var _a;
|
|
1073
|
+
return {
|
|
1074
|
+
...discount,
|
|
1075
|
+
metadata: {
|
|
1076
|
+
...discount.metadata,
|
|
1077
|
+
num: item.num,
|
|
1078
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1079
|
+
}
|
|
1080
|
+
// num: item.num, // 使用拆分后的 num
|
|
1081
|
+
};
|
|
1082
|
+
});
|
|
1083
|
+
newBundleWithDiscount.push({
|
|
1084
|
+
...bundleItem,
|
|
1085
|
+
_id: item._id,
|
|
1086
|
+
product_id: bundleItem.product_id,
|
|
1087
|
+
price: item.price,
|
|
1088
|
+
num: item.num,
|
|
1089
|
+
discount_list: updatedDiscountList2
|
|
1090
|
+
});
|
|
1091
|
+
});
|
|
1092
|
+
} else {
|
|
1093
|
+
const item = processedItems[0];
|
|
1094
|
+
if (item.processed) {
|
|
1095
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1096
|
+
var _a;
|
|
1097
|
+
return {
|
|
1098
|
+
...discount,
|
|
1099
|
+
metadata: {
|
|
1100
|
+
...discount.metadata,
|
|
1101
|
+
num: item.num,
|
|
1102
|
+
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1103
|
+
}
|
|
1104
|
+
// num: item.num, // 使用当前的 num
|
|
1105
|
+
};
|
|
1106
|
+
});
|
|
1107
|
+
newBundleWithDiscount.push({
|
|
1108
|
+
...bundleItem,
|
|
1109
|
+
_id: item._id,
|
|
1110
|
+
product_id: bundleItem.product_id,
|
|
1111
|
+
price: item.price,
|
|
1112
|
+
num: item.num,
|
|
1113
|
+
discount_list: updatedDiscountList2
|
|
1560
1114
|
});
|
|
1561
1115
|
} else {
|
|
1562
|
-
|
|
1563
|
-
if (item.processed) {
|
|
1564
|
-
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1565
|
-
var _a;
|
|
1566
|
-
return {
|
|
1567
|
-
...discount,
|
|
1568
|
-
metadata: {
|
|
1569
|
-
...discount.metadata,
|
|
1570
|
-
num: item.num,
|
|
1571
|
-
custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
|
|
1572
|
-
}
|
|
1573
|
-
// num: item.num, // 使用当前的 num
|
|
1574
|
-
};
|
|
1575
|
-
});
|
|
1576
|
-
newBundleWithDiscount.push({
|
|
1577
|
-
...bundleItem,
|
|
1578
|
-
_id: item._id,
|
|
1579
|
-
product_id: bundleItem.product_id,
|
|
1580
|
-
price: item.price,
|
|
1581
|
-
num: item.num,
|
|
1582
|
-
quantity: item.num,
|
|
1583
|
-
discount_list: updatedDiscountList2
|
|
1584
|
-
});
|
|
1585
|
-
} else {
|
|
1586
|
-
newBundleWithDiscount.push(item);
|
|
1587
|
-
}
|
|
1116
|
+
newBundleWithDiscount.push(item);
|
|
1588
1117
|
}
|
|
1589
1118
|
}
|
|
1590
|
-
);
|
|
1119
|
+
});
|
|
1591
1120
|
let newTotalWithDiscount = Number(mainProductData.price || 0);
|
|
1592
|
-
let newOriginTotalWithDiscount = Number(
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
var _a, _b;
|
|
1598
|
-
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
1599
|
-
return discount;
|
|
1600
|
-
}
|
|
1601
|
-
return {
|
|
1602
|
-
...discount,
|
|
1603
|
-
// num: 1,
|
|
1604
|
-
metadata: {
|
|
1605
|
-
...discount.metadata,
|
|
1606
|
-
custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
|
|
1607
|
-
num: 1
|
|
1608
|
-
}
|
|
1609
|
-
};
|
|
1121
|
+
let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
|
|
1122
|
+
const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
|
|
1123
|
+
var _a, _b;
|
|
1124
|
+
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
1125
|
+
return discount;
|
|
1610
1126
|
}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1127
|
+
return {
|
|
1128
|
+
...discount,
|
|
1129
|
+
// num: 1,
|
|
1130
|
+
metadata: {
|
|
1131
|
+
...discount.metadata,
|
|
1132
|
+
custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
|
|
1133
|
+
num: 1
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
const mainDiscountList = updatedMainDiscountList.filter((item) => {
|
|
1138
|
+
var _a;
|
|
1139
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1140
|
+
});
|
|
1618
1141
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1619
1142
|
const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
|
|
1620
1143
|
newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
|
|
@@ -1644,24 +1167,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1644
1167
|
quantity: 1,
|
|
1645
1168
|
discount_list: updatedMainDiscountList,
|
|
1646
1169
|
bundle: newBundleWithDiscount,
|
|
1647
|
-
total: newTotalWithDiscount,
|
|
1648
|
-
origin_total: newOriginTotalWithDiscount
|
|
1170
|
+
total: new import_decimal.default(newTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber(),
|
|
1171
|
+
origin_total: new import_decimal.default(newOriginTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
|
|
1649
1172
|
})
|
|
1650
1173
|
);
|
|
1651
1174
|
if (mainProductQuantity > 1) {
|
|
1652
1175
|
const newBundleOriginal = [];
|
|
1653
|
-
(product.bundle || []).forEach(
|
|
1654
|
-
(
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
}
|
|
1660
|
-
);
|
|
1176
|
+
(product.bundle || []).forEach((bundleItem, bundleIndex) => {
|
|
1177
|
+
newBundleOriginal.push({
|
|
1178
|
+
...bundleItem,
|
|
1179
|
+
discount_list: []
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1661
1182
|
let newTotalOriginal = Number(mainProductData.price || 0);
|
|
1662
|
-
let newOriginTotalOriginal = Number(
|
|
1663
|
-
mainProductData.original_price || mainProductData.price || 0
|
|
1664
|
-
);
|
|
1183
|
+
let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
|
|
1665
1184
|
const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
|
|
1666
1185
|
var _a, _b;
|
|
1667
1186
|
if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
|
|
@@ -1677,16 +1196,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1677
1196
|
// num: mainProductQuantity - 1,
|
|
1678
1197
|
};
|
|
1679
1198
|
});
|
|
1680
|
-
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
}
|
|
1685
|
-
);
|
|
1199
|
+
const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
|
|
1200
|
+
var _a;
|
|
1201
|
+
return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
|
|
1202
|
+
});
|
|
1686
1203
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
1687
|
-
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
|
|
1688
|
-
mainDiscountListOriginal
|
|
1689
|
-
);
|
|
1204
|
+
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
|
|
1690
1205
|
newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
|
|
1691
1206
|
newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
|
|
1692
1207
|
}
|
|
@@ -1723,59 +1238,48 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1723
1238
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1724
1239
|
const newBundle = [];
|
|
1725
1240
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
1726
|
-
product.bundle.forEach(
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
metadata
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
};
|
|
1745
|
-
});
|
|
1746
|
-
newBundle.push({
|
|
1747
|
-
...bundleItem,
|
|
1748
|
-
_id: item._id,
|
|
1749
|
-
product_id: bundleItem.product_id,
|
|
1750
|
-
price: item.price,
|
|
1751
|
-
num: item.num,
|
|
1752
|
-
quantity: item.num,
|
|
1753
|
-
discount_list: updatedDiscountList2,
|
|
1754
|
-
bundle_selling_price: bundleItem.bundle_selling_price !== void 0 ? item.price : void 0
|
|
1755
|
-
});
|
|
1241
|
+
product.bundle.forEach((bundleItem, bundleIndex) => {
|
|
1242
|
+
const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
|
|
1243
|
+
const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
|
|
1244
|
+
if (!processedBundleItems || processedBundleItems.length === 0) {
|
|
1245
|
+
newBundle.push(bundleItem);
|
|
1246
|
+
} else {
|
|
1247
|
+
processedBundleItems.forEach((item) => {
|
|
1248
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1249
|
+
var _a2;
|
|
1250
|
+
return {
|
|
1251
|
+
...discount,
|
|
1252
|
+
metadata: {
|
|
1253
|
+
...discount.metadata,
|
|
1254
|
+
num: item.num,
|
|
1255
|
+
custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
|
|
1256
|
+
}
|
|
1257
|
+
// num: item.num, // 使用拆分后的 num
|
|
1258
|
+
};
|
|
1756
1259
|
});
|
|
1757
|
-
|
|
1260
|
+
newBundle.push({
|
|
1261
|
+
...bundleItem,
|
|
1262
|
+
_id: item._id,
|
|
1263
|
+
product_id: bundleItem.product_id,
|
|
1264
|
+
price: item.price,
|
|
1265
|
+
num: item.num,
|
|
1266
|
+
discount_list: updatedDiscountList2
|
|
1267
|
+
});
|
|
1268
|
+
});
|
|
1758
1269
|
}
|
|
1759
|
-
);
|
|
1270
|
+
});
|
|
1760
1271
|
}
|
|
1761
1272
|
let newTotal = Number(mainProductData.price || 0);
|
|
1762
|
-
let newOriginTotal = Number(
|
|
1763
|
-
|
|
1764
|
-
);
|
|
1765
|
-
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(
|
|
1766
|
-
_b,
|
|
1767
|
-
(item) => item.type === "product"
|
|
1768
|
-
)));
|
|
1273
|
+
let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
|
|
1274
|
+
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")));
|
|
1769
1275
|
if (isManualDiscount) {
|
|
1770
1276
|
newTotal = mainProductData.total ?? newTotal;
|
|
1771
1277
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|
|
1772
1278
|
} else {
|
|
1773
|
-
const mainDiscountList = mainProductData.discount_list.filter(
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
}
|
|
1778
|
-
);
|
|
1279
|
+
const mainDiscountList = mainProductData.discount_list.filter((item) => {
|
|
1280
|
+
var _a2;
|
|
1281
|
+
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
1282
|
+
});
|
|
1779
1283
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1780
1284
|
const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
|
|
1781
1285
|
newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
|
|
@@ -1783,8 +1287,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1783
1287
|
}
|
|
1784
1288
|
if (newBundle.length > 0) {
|
|
1785
1289
|
newBundle.forEach((item) => {
|
|
1786
|
-
var _a2, _b2, _c2;
|
|
1787
1290
|
newTotal += Number(item.price) * Number(item.num);
|
|
1291
|
+
});
|
|
1292
|
+
newBundle.forEach((item) => {
|
|
1293
|
+
var _a2, _b2, _c2;
|
|
1788
1294
|
const originalPrice = ((_c2 = (_b2 = (_a2 = item.discount_list) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.discount) == null ? void 0 : _c2.original_amount) || item.price;
|
|
1789
1295
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
1790
1296
|
});
|
|
@@ -1797,6 +1303,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1797
1303
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
1798
1304
|
}, new import_decimal.default(newTotal)).toNumber();
|
|
1799
1305
|
}
|
|
1306
|
+
newTotal = new import_decimal.default(newTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
1307
|
+
newOriginTotal = new import_decimal.default(newOriginTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
1800
1308
|
result.push(
|
|
1801
1309
|
this.hooks.setProduct(mainProduct, {
|
|
1802
1310
|
...mainProductData,
|