@pisell/pisellos 2.3.170 → 2.3.172
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/inventory/index.d.ts +92 -0
- package/dist/inventory/index.js +509 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/dist/modules/Discount/index.js +1 -0
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +25 -3
- package/dist/modules/Order/index.js +1791 -1318
- package/dist/modules/Order/types.d.ts +7 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
- package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +33 -12
- package/dist/modules/Rules/index.d.ts +5 -10
- package/dist/modules/Rules/index.js +197 -107
- package/dist/modules/Rules/promotionSelection.d.ts +14 -0
- package/dist/modules/Rules/promotionSelection.js +390 -0
- package/dist/modules/Rules/types.d.ts +9 -0
- package/dist/server/modules/order/index.d.ts +6 -0
- package/dist/server/modules/order/index.js +782 -447
- package/dist/solution/BaseSales/index.d.ts +16 -1
- package/dist/solution/BaseSales/index.js +1545 -1339
- package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +200 -108
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +94 -58
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +117 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/dist/solution/UnifiedBookingSales/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.js +69 -49
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/lib/inventory/index.d.ts +92 -0
- package/lib/inventory/index.js +287 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Discount/index.js +1 -0
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +25 -3
- package/lib/modules/Order/index.js +203 -38
- package/lib/modules/Order/types.d.ts +7 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
- package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
- package/lib/modules/Payment/walletpass.js +23 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +15 -0
- package/lib/modules/Rules/index.d.ts +5 -10
- package/lib/modules/Rules/index.js +68 -22
- package/lib/modules/Rules/promotionSelection.d.ts +14 -0
- package/lib/modules/Rules/promotionSelection.js +230 -0
- package/lib/modules/Rules/types.d.ts +9 -0
- package/lib/server/modules/order/index.d.ts +6 -0
- package/lib/server/modules/order/index.js +226 -29
- package/lib/solution/BaseSales/index.d.ts +16 -1
- package/lib/solution/BaseSales/index.js +108 -14
- package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +38 -2
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +14 -2
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +71 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/lib/solution/UnifiedBookingSales/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.js +14 -3
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/package.json +1 -1
|
@@ -46,6 +46,7 @@ import { isOrderLevelFixedAmountDiscount } from "../../solution/ShopDiscount/uti
|
|
|
46
46
|
import { calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
|
|
47
47
|
import { compareEntitlementPassPriority, getRemainingEntitlementUses, isEntitlementPass, isFullCoveragePass, resolveEntitlementQuota } from "../Discount/entitlementPass";
|
|
48
48
|
import { getDiscountUsageBlockReason, getDiscountUsageLimitFailKey } from "../Discount/availability";
|
|
49
|
+
import { calculatePromotionSelection, getExclusivePromotion, isPromotionDiscountCard } from "./promotionSelection";
|
|
49
50
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
50
51
|
_inherits(RulesModule, _BaseModule);
|
|
51
52
|
var _super = _createSuper(RulesModule);
|
|
@@ -59,10 +60,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
59
60
|
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
60
61
|
// WindowPlugin 实例
|
|
61
62
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "discountScope", void 0);
|
|
62
64
|
_this.hooks = {};
|
|
63
65
|
return _this;
|
|
64
66
|
}
|
|
65
67
|
_createClass(RulesModule, [{
|
|
68
|
+
key: "setDiscountScope",
|
|
69
|
+
value: function setDiscountScope(scope) {
|
|
70
|
+
this.discountScope = scope;
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
66
73
|
key: "initialize",
|
|
67
74
|
value: function () {
|
|
68
75
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
@@ -243,6 +250,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
243
250
|
}
|
|
244
251
|
});
|
|
245
252
|
|
|
253
|
+
// 卡可用但互斥比较选择了促销时,扫码仍应加入可选卡列表,不能被标为商品不适用。
|
|
254
|
+
if (!hasApplicableDiscount) {
|
|
255
|
+
var promotionProductIds = new Set(result.productList.filter(function (product) {
|
|
256
|
+
var _getExclusivePromotio;
|
|
257
|
+
return ((_getExclusivePromotio = getExclusivePromotion(product)) === null || _getExclusivePromotio === void 0 ? void 0 : _getExclusivePromotio.inPromotion) === true;
|
|
258
|
+
}).map(function (product) {
|
|
259
|
+
return _this2.hooks.getProduct(product).id;
|
|
260
|
+
}));
|
|
261
|
+
hasApplicableDiscount = result.discountList.some(function (discount) {
|
|
262
|
+
var _discount$applicableP;
|
|
263
|
+
return newDiscountIds.includes(discount.id) && isPromotionDiscountCard(discount) && discount.isAvailable && ((_discount$applicableP = discount.applicableProductIds) === null || _discount$applicableP === void 0 ? void 0 : _discount$applicableP.some(function (id) {
|
|
264
|
+
return promotionProductIds.has(id);
|
|
265
|
+
}));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
246
269
|
// 如果券不可用,判断不可用原因
|
|
247
270
|
var unavailableReason;
|
|
248
271
|
if (!hasApplicableDiscount) {
|
|
@@ -300,7 +323,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
300
323
|
_step;
|
|
301
324
|
try {
|
|
302
325
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
303
|
-
var
|
|
326
|
+
var _discount = _step.value;
|
|
304
327
|
var bookingTimes = productList.length ? productList.map(function (item) {
|
|
305
328
|
var product = _this3.hooks.getProduct(item);
|
|
306
329
|
return ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
|
|
@@ -310,7 +333,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
310
333
|
try {
|
|
311
334
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
312
335
|
var bookingTime = _step3.value;
|
|
313
|
-
var filteredList = filterDiscountListByBookingTime([
|
|
336
|
+
var filteredList = filterDiscountListByBookingTime([_discount], bookingTime);
|
|
314
337
|
if (filteredList.length === 0) {
|
|
315
338
|
return UnavailableReason.TimeLimit;
|
|
316
339
|
}
|
|
@@ -332,8 +355,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
332
355
|
_step2;
|
|
333
356
|
try {
|
|
334
357
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
335
|
-
var
|
|
336
|
-
var limitedData =
|
|
358
|
+
var _discount2 = _step2.value;
|
|
359
|
+
var limitedData = _discount2.limited_relation_product_data;
|
|
337
360
|
var hasApplicableProduct = false;
|
|
338
361
|
var _iterator4 = _createForOfIteratorHelper(productList),
|
|
339
362
|
_step4;
|
|
@@ -341,11 +364,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
341
364
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
342
365
|
var _limitedData$product_;
|
|
343
366
|
var item = _step4.value;
|
|
344
|
-
var
|
|
367
|
+
var _product = this.hooks.getProduct(item);
|
|
345
368
|
if (limitedData.type === 'product_all') {
|
|
346
369
|
hasApplicableProduct = true;
|
|
347
370
|
break;
|
|
348
|
-
} else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(
|
|
371
|
+
} else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(_product.id)) {
|
|
349
372
|
hasApplicableProduct = true;
|
|
350
373
|
break;
|
|
351
374
|
}
|
|
@@ -368,14 +391,41 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
368
391
|
}
|
|
369
392
|
}, {
|
|
370
393
|
key: "calcDiscount",
|
|
371
|
-
value: function calcDiscount(
|
|
394
|
+
value: function calcDiscount(params, options) {
|
|
395
|
+
var _this4 = this;
|
|
396
|
+
return calculatePromotionSelection(params, options, this.hooks, function (input, calculationOptions, policy) {
|
|
397
|
+
return _this4.calcDiscountCore(input, calculationOptions, policy);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}, {
|
|
401
|
+
key: "calcDiscountCore",
|
|
402
|
+
value: function calcDiscountCore(_ref2, options, promotionPolicy) {
|
|
372
403
|
var _options$selectedList,
|
|
373
|
-
|
|
404
|
+
_this5 = this;
|
|
374
405
|
var discountList = _ref2.discountList,
|
|
375
406
|
productList = _ref2.productList,
|
|
376
407
|
holders = _ref2.holders,
|
|
377
408
|
isFormSubject = _ref2.isFormSubject,
|
|
378
409
|
orderTotalAmount = _ref2.orderTotalAmount;
|
|
410
|
+
var cancelledPromotionCards = discountList.filter(function (discount) {
|
|
411
|
+
return !discount.isEditMode && isPromotionDiscountCard(discount) && discount.promotionSelection === 'promotion';
|
|
412
|
+
});
|
|
413
|
+
var cancelledPromotionProductIds = new Set(cancelledPromotionCards.flatMap(function (discount) {
|
|
414
|
+
return discount.applicableProductIds || [];
|
|
415
|
+
}));
|
|
416
|
+
var cancelledPromotionStrategyIds = new Set(cancelledPromotionCards.flatMap(function (discount) {
|
|
417
|
+
return discount.promotionSelectionStrategyIds || [];
|
|
418
|
+
}));
|
|
419
|
+
var isCardBlockedByPromotion = function isCardBlockedByPromotion(flatItem, discount) {
|
|
420
|
+
var _originProduct$metada, _originProduct$metada2;
|
|
421
|
+
if (flatItem.type !== 'main' || !isPromotionDiscountCard(discount)) return false;
|
|
422
|
+
var originProduct = flatItem.originProduct;
|
|
423
|
+
if (originProduct !== null && originProduct !== void 0 && originProduct.order_detail_id || originProduct !== null && originProduct !== void 0 && originProduct.orderDetailId || originProduct !== null && originProduct !== void 0 && originProduct.booking_id || originProduct !== null && originProduct !== void 0 && (_originProduct$metada = originProduct.metadata) !== null && _originProduct$metada !== void 0 && _originProduct$metada.booking_id) return false;
|
|
424
|
+
// 取消卡后即使数量暂未凑足促销,也不能自动改用另一张卡;重新手选/最佳组合会清除该意图。
|
|
425
|
+
if (cancelledPromotionProductIds.has(flatItem.product.id) || cancelledPromotionStrategyIds.has(String(originProduct === null || originProduct === void 0 || (_originProduct$metada2 = originProduct.metadata) === null || _originProduct$metada2 === void 0 || (_originProduct$metada2 = _originProduct$metada2._promotion) === null || _originProduct$metada2 === void 0 ? void 0 : _originProduct$metada2.strategyId))) return true;
|
|
426
|
+
var promotion = getExclusivePromotion(originProduct);
|
|
427
|
+
return Boolean(promotion && (promotionPolicy === null || promotionPolicy === void 0 ? void 0 : promotionPolicy.blockedStrategyIds.has(String(promotion.strategyId))));
|
|
428
|
+
};
|
|
379
429
|
var preferredEntitlementPassIds = new Set(((options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds) || []).map(String));
|
|
380
430
|
var resolveIsFormSubject = function resolveIsFormSubject(product) {
|
|
381
431
|
return typeof isFormSubject === 'function' ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
|
|
@@ -393,8 +443,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
393
443
|
return uid !== undefined && uid !== null && uid !== '';
|
|
394
444
|
}).map(String));
|
|
395
445
|
var getOriginProductUid = function getOriginProductUid(originProduct) {
|
|
396
|
-
var _originProduct$
|
|
397
|
-
var uid = (_originProduct$
|
|
446
|
+
var _originProduct$metada3, _originProduct$metada4;
|
|
447
|
+
var uid = (_originProduct$metada3 = originProduct === null || originProduct === void 0 || (_originProduct$metada4 = originProduct.metadata) === null || _originProduct$metada4 === void 0 ? void 0 : _originProduct$metada4.unique_identification_number) !== null && _originProduct$metada3 !== void 0 ? _originProduct$metada3 : originProduct === null || originProduct === void 0 ? void 0 : originProduct.unique_identification_number;
|
|
398
448
|
if (uid === undefined || uid === null || uid === '') return undefined;
|
|
399
449
|
return String(uid);
|
|
400
450
|
};
|
|
@@ -406,13 +456,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
406
456
|
return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
|
|
407
457
|
};
|
|
408
458
|
var resolveReapplyBookingDiscountPercent = function resolveReapplyBookingDiscountPercent(originProduct, selectedDiscount) {
|
|
409
|
-
var
|
|
459
|
+
var _discount3;
|
|
410
460
|
if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount)) return undefined;
|
|
411
461
|
var discountType = (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.tag) || (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.type);
|
|
412
462
|
if (discountType !== 'discount_card' && discountType !== 'product_discount_card') {
|
|
413
463
|
return undefined;
|
|
414
464
|
}
|
|
415
|
-
var percent = Number((
|
|
465
|
+
var percent = Number((_discount3 = selectedDiscount.discount) === null || _discount3 === void 0 ? void 0 : _discount3.percent);
|
|
416
466
|
return Number.isFinite(percent) ? percent : undefined;
|
|
417
467
|
};
|
|
418
468
|
var editModeDiscount = [];
|
|
@@ -470,7 +520,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
470
520
|
var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
|
|
471
521
|
var flattened = [];
|
|
472
522
|
productList.forEach(function (originProduct) {
|
|
473
|
-
var product =
|
|
523
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
474
524
|
|
|
475
525
|
// 1. 添加主商品
|
|
476
526
|
flattened.push({
|
|
@@ -948,8 +998,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
948
998
|
|
|
949
999
|
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
950
1000
|
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
951
|
-
var _discount$config2,
|
|
1001
|
+
var _discount$config2, _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
|
|
1002
|
+
if (_this5.discountScope && !_this5.discountScope(flatItem.originProduct, discount)) return false;
|
|
952
1003
|
if (((_discount$config2 = discount.config) === null || _discount$config2 === void 0 ? void 0 : _discount$config2.isAvailable) === false) return false;
|
|
1004
|
+
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
953
1005
|
var product;
|
|
954
1006
|
if (flatItem.type === 'main') {
|
|
955
1007
|
product = flatItem.product;
|
|
@@ -966,12 +1018,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
966
1018
|
startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
|
|
967
1019
|
};
|
|
968
1020
|
}
|
|
969
|
-
if (
|
|
1021
|
+
if (_this5.isItemRewardProductDiscount(product)) {
|
|
970
1022
|
return false;
|
|
971
1023
|
}
|
|
972
1024
|
|
|
973
1025
|
// 编辑的商品使用了优惠券不可用
|
|
974
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
1026
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
|
|
975
1027
|
return d.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
|
|
976
1028
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
|
|
977
1029
|
return d.id;
|
|
@@ -992,7 +1044,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
992
1044
|
var limitedData = discount.limited_relation_product_data;
|
|
993
1045
|
|
|
994
1046
|
// 时间限制检查
|
|
995
|
-
var timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
1047
|
+
var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
996
1048
|
if (!timeLimit) {
|
|
997
1049
|
return false;
|
|
998
1050
|
}
|
|
@@ -1012,10 +1064,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1012
1064
|
}
|
|
1013
1065
|
|
|
1014
1066
|
// 套餐规则检查
|
|
1015
|
-
var isBundleAvailable =
|
|
1067
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1016
1068
|
return isLimitedProduct && isBundleAvailable;
|
|
1017
1069
|
};
|
|
1018
1070
|
|
|
1071
|
+
// 分摊占位与实际应用共用选择优先级,数量跌出促销门槛时也保留手选意图。
|
|
1072
|
+
var findExplicitlySelectedDiscount = function findExplicitlySelectedDiscount(applicableDiscounts) {
|
|
1073
|
+
return ((options === null || options === void 0 ? void 0 : options.isSelected) === true && options.discountId !== undefined ? applicableDiscounts.find(function (discount) {
|
|
1074
|
+
return String(discount.id) === String(options.discountId) && (isFullCoveragePass(discount) || isPromotionDiscountCard(discount));
|
|
1075
|
+
}) : undefined) || ((options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) !== false ? applicableDiscounts.find(function (discount) {
|
|
1076
|
+
return discount.promotionSelection === 'card';
|
|
1077
|
+
}) : undefined);
|
|
1078
|
+
};
|
|
1079
|
+
var getAppliedWalletDiscountIds = function getAppliedWalletDiscountIds(product) {
|
|
1080
|
+
return new Set((product.discount_list || []).filter(function (item) {
|
|
1081
|
+
return ['entitlement_pass', 'discount_card', 'product_discount_card'].includes((item === null || item === void 0 ? void 0 : item.tag) || (item === null || item === void 0 ? void 0 : item.type));
|
|
1082
|
+
}).map(function (item) {
|
|
1083
|
+
var _ref12, _item$discount$resour, _item$discount;
|
|
1084
|
+
return (_ref12 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref12 !== void 0 ? _ref12 : item === null || item === void 0 ? void 0 : item.id;
|
|
1085
|
+
}).filter(function (id) {
|
|
1086
|
+
return id !== undefined && id !== null;
|
|
1087
|
+
}).map(String));
|
|
1088
|
+
};
|
|
1089
|
+
var findAppliedDiscountCard = function findAppliedDiscountCard(applicableDiscounts, appliedIds) {
|
|
1090
|
+
return options !== null && options !== void 0 && options.scan || (options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) === false ? undefined : applicableDiscounts.find(function (discount) {
|
|
1091
|
+
return discount.isSelected === true && isPromotionDiscountCard(discount) && appliedIds.has(String(discount.id));
|
|
1092
|
+
});
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1019
1095
|
// 收集所有被勾选的 order_level 折扣卡及其适用商品
|
|
1020
1096
|
var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1021
1097
|
return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
|
|
@@ -1043,6 +1119,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1043
1119
|
// Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
|
|
1044
1120
|
var occupiedItems = new Map();
|
|
1045
1121
|
|
|
1122
|
+
// 手选/已应用的卡先占位(包括全品类卡),其他候选卡不能抢走其分摊商品。
|
|
1123
|
+
sortedFlattenedList.forEach(function (flatItem) {
|
|
1124
|
+
var product = flatItem.type === 'main' ? flatItem.product : flatItem.bundleItem;
|
|
1125
|
+
var holderProduct = flatItem.type === 'main' ? flatItem.product : flatItem.parentProduct;
|
|
1126
|
+
var applicableCards = sortedDiscountList.filter(function (discount) {
|
|
1127
|
+
var _discount$config3;
|
|
1128
|
+
return isPromotionDiscountCard(discount) && ((_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.isAvailable) && checkItemApplicableForDiscount(flatItem, discount) && _this5.checkHolderMatch(discount, {
|
|
1129
|
+
isNeedHolder: resolveIsFormSubject(holderProduct) && !(holderProduct !== null && holderProduct !== void 0 && holderProduct.isNormalProduct),
|
|
1130
|
+
holder_id: (holderProduct === null || holderProduct === void 0 ? void 0 : holderProduct.holder_id) || product.holder_id
|
|
1131
|
+
}, flatItem.originProduct, holders);
|
|
1132
|
+
});
|
|
1133
|
+
var preferredCard = findExplicitlySelectedDiscount(applicableCards) || findAppliedDiscountCard(applicableCards, getAppliedWalletDiscountIds(product)) || applicableCards.find(function (discount) {
|
|
1134
|
+
return discount.isScan && discount.isSelected;
|
|
1135
|
+
});
|
|
1136
|
+
if (preferredCard) occupiedItems.set(flatItem._id, preferredCard.id);
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1046
1139
|
// 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
|
|
1047
1140
|
selectedOrderLevelDiscounts.forEach(function (discount) {
|
|
1048
1141
|
var limitedData = discount.limited_relation_product_data;
|
|
@@ -1072,7 +1165,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1072
1165
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
1073
1166
|
var applicableProducts = [];
|
|
1074
1167
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
1075
|
-
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price,
|
|
1168
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref13, _flatItem$original_pr;
|
|
1076
1169
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
1077
1170
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
1078
1171
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -1100,7 +1193,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1100
1193
|
|
|
1101
1194
|
// 对于主商品:使用 price
|
|
1102
1195
|
// 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
|
|
1103
|
-
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((
|
|
1196
|
+
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref13 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref13 !== void 0 ? _ref13 : 0);
|
|
1104
1197
|
|
|
1105
1198
|
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
1106
1199
|
var productData = {
|
|
@@ -1132,21 +1225,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1132
1225
|
|
|
1133
1226
|
// 可用性和实际应用共用金额判断;零基础价商品可按策略抵扣收费 option。
|
|
1134
1227
|
var isDiscountCardPriceAvailable = function isDiscountCardPriceAvailable(flatItem, discount) {
|
|
1135
|
-
var _product$discount_lis2, _discount$
|
|
1228
|
+
var _product$discount_lis2, _discount$config4;
|
|
1136
1229
|
var product = flatItem.type === 'main' ? flatItem.product : flatItem.bundleItem;
|
|
1137
1230
|
if (!(Number(flatItem.price) <= 0 || !flatItem.price) || (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.some(function (item) {
|
|
1138
|
-
var _item$
|
|
1139
|
-
return ((_item$
|
|
1231
|
+
var _item$discount2;
|
|
1232
|
+
return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === discount.id;
|
|
1140
1233
|
})) {
|
|
1141
1234
|
return true;
|
|
1142
1235
|
}
|
|
1143
|
-
if (flatItem.type !== 'main' || Number(flatItem.price) !== 0 || !['discount_card', 'product_discount_card'].includes(discount.tag || discount.type || '') || !((_discount$
|
|
1236
|
+
if (flatItem.type !== 'main' || Number(flatItem.price) !== 0 || !['discount_card', 'product_discount_card'].includes(discount.tag || discount.type || '') || !((_discount$config4 = discount.config) !== null && _discount$config4 !== void 0 && _discount$config4.deductOptionPrice) || isOrderLevelFixedAmountDiscount(discount)) {
|
|
1144
1237
|
return false;
|
|
1145
1238
|
}
|
|
1146
1239
|
return (product.options || []).reduce(function (total, option) {
|
|
1147
|
-
var
|
|
1148
|
-
var unitPrice = Number((
|
|
1149
|
-
var quantity = Number((
|
|
1240
|
+
var _ref14, _ref15, _ref16, _option$_original_pri, _ref17, _option$num;
|
|
1241
|
+
var unitPrice = Number((_ref14 = (_ref15 = (_ref16 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref16 !== void 0 ? _ref16 : option.price) !== null && _ref15 !== void 0 ? _ref15 : option.add_price) !== null && _ref14 !== void 0 ? _ref14 : 0);
|
|
1242
|
+
var quantity = Number((_ref17 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref17 !== void 0 ? _ref17 : 1);
|
|
1150
1243
|
if (!Number.isFinite(unitPrice) || !Number.isFinite(quantity) || quantity <= 0) {
|
|
1151
1244
|
return total;
|
|
1152
1245
|
}
|
|
@@ -1179,31 +1272,31 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1179
1272
|
};
|
|
1180
1273
|
originProduct = flatItem.originProduct;
|
|
1181
1274
|
}
|
|
1182
|
-
var isItemRewardProductDiscount =
|
|
1275
|
+
var isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1183
1276
|
addModeDiscount.forEach(function (discount) {
|
|
1184
|
-
var
|
|
1277
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config5;
|
|
1185
1278
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
1186
1279
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
1187
1280
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
1188
|
-
var isHolderMatch =
|
|
1281
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1189
1282
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1190
1283
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1191
1284
|
}, flatItem.originProduct, holders);
|
|
1192
|
-
var timeReason = getDiscountTimeUnavailableReason(discount, (((
|
|
1285
|
+
var timeReason = getDiscountTimeUnavailableReason(discount, (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss'));
|
|
1193
1286
|
var timeLimit = !timeReason;
|
|
1194
1287
|
// 是符合折扣的商品
|
|
1195
1288
|
var isProductInScope = 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);
|
|
1196
1289
|
var isLimitedProduct = isProductInScope && isHolderMatch;
|
|
1197
1290
|
|
|
1198
1291
|
// 编辑的商品 使用了优惠券不可用
|
|
1199
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
1292
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
|
|
1200
1293
|
return discount.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
1201
1294
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
|
|
1202
1295
|
return discount.id;
|
|
1203
1296
|
}));
|
|
1204
1297
|
|
|
1205
1298
|
// 套餐是否可用判断
|
|
1206
|
-
var isBundleAvailable =
|
|
1299
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1207
1300
|
if (isProductInScope && isBundleAvailable && !isItemRewardProductDiscount) {
|
|
1208
1301
|
var timeReasons = discountTimeReasons.get(discount.id) || [];
|
|
1209
1302
|
timeReasons.push(timeReason);
|
|
@@ -1212,10 +1305,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1212
1305
|
}
|
|
1213
1306
|
|
|
1214
1307
|
// 判断优惠券是否适用于该商品
|
|
1215
|
-
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$
|
|
1308
|
+
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config5 = discount.config) !== null && _discount$config5 !== void 0 && _discount$config5.isAvailable && (isFullCoveragePass(discount) || isDiscountCardPriceAvailable(flatItem, discount)) && (!isEntitlementPass(discount) || getRemainingEntitlementUses(discount, 0, 1) > 0)) {
|
|
1216
1309
|
var _discountApplicabilit, _discount$metadata4, _discount$metadata5, _discount$metadata6;
|
|
1217
1310
|
// 记录此优惠券适用的商品
|
|
1218
1311
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
1312
|
+
if (flatItem.type === 'main' && isPromotionDiscountCard(discount)) {
|
|
1313
|
+
var _promotionPolicy$onAp;
|
|
1314
|
+
promotionPolicy === null || promotionPolicy === void 0 || (_promotionPolicy$onAp = promotionPolicy.onApplicableCard) === null || _promotionPolicy$onAp === void 0 || _promotionPolicy$onAp.call(promotionPolicy, originProduct, discount);
|
|
1315
|
+
}
|
|
1219
1316
|
|
|
1220
1317
|
// 记录可抵扣的商品详情
|
|
1221
1318
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
@@ -1262,13 +1359,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1262
1359
|
};
|
|
1263
1360
|
var optionDiscountAmount = 0;
|
|
1264
1361
|
var discountedOptions = options.map(function (option) {
|
|
1265
|
-
var
|
|
1362
|
+
var _ref18, _ref19, _option$_original_pri2, _ref20, _option$num2, _rest$price, _option$_original_pri3;
|
|
1266
1363
|
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
1267
|
-
var rawUnit = (
|
|
1364
|
+
var rawUnit = (_ref18 = (_ref19 = (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : option._original_add_price) !== null && _ref19 !== void 0 ? _ref19 : option.price) !== null && _ref18 !== void 0 ? _ref18 : option.add_price;
|
|
1268
1365
|
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
1269
1366
|
if (baseUnitNum <= 0) return option;
|
|
1270
1367
|
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
1271
|
-
var optQty = Number((
|
|
1368
|
+
var optQty = Number((_ref20 = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : option.quantity) !== null && _ref20 !== void 0 ? _ref20 : 1);
|
|
1272
1369
|
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
1273
1370
|
var _original_add_price = option._original_add_price,
|
|
1274
1371
|
rest = _objectWithoutProperties(option, _excluded);
|
|
@@ -1302,9 +1399,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1302
1399
|
var getOptionTotal = function getOptionTotal(options) {
|
|
1303
1400
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
1304
1401
|
return options.reduce(function (sum, opt) {
|
|
1305
|
-
var
|
|
1306
|
-
var unit = Number((
|
|
1307
|
-
var n = Number((
|
|
1402
|
+
var _ref21, _opt$price, _ref22, _opt$num;
|
|
1403
|
+
var unit = Number((_ref21 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref21 !== void 0 ? _ref21 : 0);
|
|
1404
|
+
var n = Number((_ref22 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref22 !== void 0 ? _ref22 : 1);
|
|
1308
1405
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
1309
1406
|
}, 0);
|
|
1310
1407
|
};
|
|
@@ -1312,7 +1409,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1312
1409
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
1313
1410
|
// 🔥 使用扁平化后的列表进行处理
|
|
1314
1411
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
1315
|
-
var
|
|
1412
|
+
var _product10, _originProduct, _originProduct2, _originProduct3, _product$discount_lis3, _product11;
|
|
1316
1413
|
// 获取商品数据
|
|
1317
1414
|
var product, originProduct;
|
|
1318
1415
|
if (flatItem.type === 'main') {
|
|
@@ -1336,8 +1433,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1336
1433
|
};
|
|
1337
1434
|
originProduct = flatItem.originProduct;
|
|
1338
1435
|
}
|
|
1339
|
-
var isPersistedProduct = ((
|
|
1340
|
-
var hasExistingWalletDiscount = ((_product$discount_lis3 = product.discount_list) === null || _product$discount_lis3 === void 0 ? void 0 : _product$discount_lis3.length) && ((
|
|
1436
|
+
var isPersistedProduct = ((_product10 = product) === null || _product10 === void 0 ? void 0 : _product10.booking_id) || ((_originProduct = originProduct) === null || _originProduct === void 0 ? void 0 : _originProduct.order_detail_id) || ((_originProduct2 = originProduct) === null || _originProduct2 === void 0 ? void 0 : _originProduct2.orderDetailId) || ((_originProduct3 = originProduct) === null || _originProduct3 === void 0 ? void 0 : _originProduct3.booking_id);
|
|
1437
|
+
var hasExistingWalletDiscount = ((_product$discount_lis3 = product.discount_list) === null || _product$discount_lis3 === void 0 ? void 0 : _product$discount_lis3.length) && ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 ? void 0 : _product11.every(function (discount) {
|
|
1341
1438
|
var _discount$id, _discount$discount4;
|
|
1342
1439
|
var discountIdentity = (_discount$id = discount.id) !== null && _discount$id !== void 0 ? _discount$id : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.resource_id;
|
|
1343
1440
|
var discountType = discount.tag || discount.type;
|
|
@@ -1359,7 +1456,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1359
1456
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1360
1457
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1361
1458
|
var _product$discount_lis4;
|
|
1362
|
-
if (
|
|
1459
|
+
if (_this5.discountScope && !_this5.discountScope(originProduct, discount)) return false;
|
|
1460
|
+
if (_this5.isItemRewardProductDiscount(product)) return false;
|
|
1461
|
+
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
1363
1462
|
// 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
|
|
1364
1463
|
var discountType = discount.tag || discount.type;
|
|
1365
1464
|
var currentOriginUid = getOriginProductUid(originProduct);
|
|
@@ -1370,9 +1469,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1370
1469
|
if (!discount.isSelected) return false;
|
|
1371
1470
|
}
|
|
1372
1471
|
if (['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && !isReapplyEditModeDiscountForProduct) {
|
|
1373
|
-
var _discount$
|
|
1472
|
+
var _discount$config6;
|
|
1374
1473
|
// 如果策略检查后没有config,说明不可用
|
|
1375
|
-
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$
|
|
1474
|
+
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config6 = discount.config) !== null && _discount$config6 !== void 0 && _discount$config6.isAvailable)) {
|
|
1376
1475
|
return false;
|
|
1377
1476
|
}
|
|
1378
1477
|
}
|
|
@@ -1394,8 +1493,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1394
1493
|
|
|
1395
1494
|
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
1396
1495
|
if (isFullCoveragePass(discount)) {
|
|
1397
|
-
var _discount$
|
|
1398
|
-
var maxUsagePerOrder = (_discount$
|
|
1496
|
+
var _discount$config7;
|
|
1497
|
+
var maxUsagePerOrder = (_discount$config7 = discount.config) === null || _discount$config7 === void 0 ? void 0 : _discount$config7.maxUsagePerOrder;
|
|
1399
1498
|
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1400
1499
|
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
1401
1500
|
if (currentUsedCount >= maxUsagePerOrder) {
|
|
@@ -1407,7 +1506,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1407
1506
|
|
|
1408
1507
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
1409
1508
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
1410
|
-
var isHolderMatch =
|
|
1509
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1411
1510
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1412
1511
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1413
1512
|
}, flatItem.originProduct, holders);
|
|
@@ -1425,13 +1524,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1425
1524
|
return false;
|
|
1426
1525
|
}
|
|
1427
1526
|
// 检查 package_sub_item_usage_rules
|
|
1428
|
-
if (!
|
|
1527
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1429
1528
|
return false;
|
|
1430
1529
|
}
|
|
1431
1530
|
return true;
|
|
1432
1531
|
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1433
1532
|
// 检查 package_sub_item_usage_rules
|
|
1434
|
-
if (!
|
|
1533
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1435
1534
|
return false;
|
|
1436
1535
|
}
|
|
1437
1536
|
return true;
|
|
@@ -1441,27 +1540,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1441
1540
|
|
|
1442
1541
|
// 识别用户本次显式选择的卡券,供次卡和折扣卡各自的优先级使用。
|
|
1443
1542
|
// 目标仍必须在当前商品的 applicableDiscounts 中,因此不会绕过 Holder、时间或商品范围校验。
|
|
1444
|
-
var explicitlySelectedDiscount = (
|
|
1445
|
-
var discountType = discount.tag || discount.type;
|
|
1446
|
-
return String(discount.id) === String(options.discountId) && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
|
|
1447
|
-
}) : undefined;
|
|
1543
|
+
var explicitlySelectedDiscount = findExplicitlySelectedDiscount(applicableDiscounts);
|
|
1448
1544
|
// 折扣卡会复用于整条商品行;商品券必须继续按单张拆分,不能复用该分支。
|
|
1449
1545
|
var explicitlySelectedDiscountCard = explicitlySelectedDiscount && !isFullCoveragePass(explicitlySelectedDiscount) ? explicitlySelectedDiscount : undefined;
|
|
1450
1546
|
|
|
1451
1547
|
// 商品数量等变化会触发无 discountId 的重算。只要当前行已应用的卡仍在
|
|
1452
1548
|
// applicableDiscounts 中,就应保留该行选择,避免被自动排序中力度更大的卡替换。
|
|
1453
|
-
var appliedWalletDiscountIds =
|
|
1454
|
-
|
|
1455
|
-
}).map(function (item) {
|
|
1456
|
-
var _ref22, _item$discount$resour, _item$discount2;
|
|
1457
|
-
return (_ref22 = (_item$discount$resour = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref22 !== void 0 ? _ref22 : item === null || item === void 0 ? void 0 : item.id;
|
|
1458
|
-
}).filter(function (id) {
|
|
1459
|
-
return id !== undefined && id !== null;
|
|
1460
|
-
}).map(String));
|
|
1461
|
-
var appliedDiscountCard = options !== null && options !== void 0 && options.scan ? undefined : applicableDiscounts.find(function (discount) {
|
|
1462
|
-
var discountType = discount.tag || discount.type;
|
|
1463
|
-
return discount.isSelected === true && ['discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && appliedWalletDiscountIds.has(String(discount.id));
|
|
1464
|
-
});
|
|
1549
|
+
var appliedWalletDiscountIds = getAppliedWalletDiscountIds(product);
|
|
1550
|
+
var appliedDiscountCard = findAppliedDiscountCard(applicableDiscounts, appliedWalletDiscountIds);
|
|
1465
1551
|
var appliedEntitlementPass = options !== null && options !== void 0 && options.scan || (options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) === false ? undefined : applicableDiscounts.find(function (discount) {
|
|
1466
1552
|
return isEntitlementPass(discount) && discount.isSelected === true && appliedWalletDiscountIds.has(String(discount.id));
|
|
1467
1553
|
});
|
|
@@ -1489,17 +1575,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1489
1575
|
var isManualDiscount = false;
|
|
1490
1576
|
var isItemRewardProductDiscount = false;
|
|
1491
1577
|
if (flatItem.type === 'main') {
|
|
1492
|
-
var _product$discount_lis5, _product$discount_lis6,
|
|
1578
|
+
var _product$discount_lis5, _product$discount_lis6, _product12, _product12$every;
|
|
1493
1579
|
// 主商品:判断自身是否手动折扣
|
|
1494
1580
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : ((_product$discount_lis5 = product.discount_list) === null || _product$discount_lis5 === void 0 ? void 0 : _product$discount_lis5.some(function (item) {
|
|
1495
1581
|
return item.type === 'product';
|
|
1496
1582
|
})) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1497
1583
|
var _ref23;
|
|
1498
1584
|
return !((_ref23 = item.discount_list || []) !== null && _ref23 !== void 0 && _ref23.length);
|
|
1499
|
-
}) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((
|
|
1585
|
+
}) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
1500
1586
|
return item.type === 'product';
|
|
1501
1587
|
})));
|
|
1502
|
-
isItemRewardProductDiscount =
|
|
1588
|
+
isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1503
1589
|
if (product.inPromotion && !isItemRewardProductDiscount) {
|
|
1504
1590
|
isManualDiscount = false;
|
|
1505
1591
|
}
|
|
@@ -1582,7 +1668,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1582
1668
|
// 主商品:保持原有逻辑,还原 option 价格
|
|
1583
1669
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
1584
1670
|
if (product.isClient) {
|
|
1585
|
-
processedProductsMap.set(product._id, [
|
|
1671
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1586
1672
|
origin_total: getProductOriginTotalPrice({
|
|
1587
1673
|
product: {
|
|
1588
1674
|
original_price: product.original_price
|
|
@@ -1602,11 +1688,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1602
1688
|
price: product.price,
|
|
1603
1689
|
options: restoredOptions
|
|
1604
1690
|
}), {}, {
|
|
1605
|
-
discount_list: isManualDiscount ?
|
|
1691
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1606
1692
|
}))]);
|
|
1607
1693
|
} else {
|
|
1608
|
-
var _ref25, _product$_promotion$f,
|
|
1609
|
-
var total = product.inPromotion ? (_ref25 = (_product$_promotion$f = (
|
|
1694
|
+
var _ref25, _product$_promotion$f, _product13, _product$origin_total;
|
|
1695
|
+
var total = product.inPromotion ? (_ref25 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref25 !== void 0 ? _ref25 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1610
1696
|
var main_product_selling_price = product.price;
|
|
1611
1697
|
if ((product.discount_list || []).some(function (item) {
|
|
1612
1698
|
return item.type === 'promotion';
|
|
@@ -1615,7 +1701,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1615
1701
|
total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
|
|
1616
1702
|
main_product_selling_price = (_product$main_product = product.main_product_selling_price) !== null && _product$main_product !== void 0 ? _product$main_product : main_product_selling_price;
|
|
1617
1703
|
}
|
|
1618
|
-
processedProductsMap.set(product._id, [
|
|
1704
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
|
|
1619
1705
|
price: product.price,
|
|
1620
1706
|
main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
|
|
1621
1707
|
}, isItemRewardProductDiscount ? {
|
|
@@ -1627,14 +1713,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1627
1713
|
main_product_selling_price: main_product_selling_price,
|
|
1628
1714
|
options: restoredOptions
|
|
1629
1715
|
}), {}, {
|
|
1630
|
-
discount_list: isManualDiscount ?
|
|
1716
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1631
1717
|
}))]);
|
|
1632
1718
|
}
|
|
1633
1719
|
} else {
|
|
1634
1720
|
var _flatItem$bundleItem8, _flatItem$bundleItem9, _flatItem$bundleItem$;
|
|
1635
1721
|
// bundle子商品:保存到扁平化Map
|
|
1636
1722
|
processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1637
|
-
discount_list: isManualDiscount ?
|
|
1723
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(((_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.discount_list) || []) : _this5.filterDiscountListByType(((_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.discount_list) || [], 'promotion'),
|
|
1638
1724
|
price: flatItem.bundleItem.price,
|
|
1639
1725
|
bundle_selling_price: (_flatItem$bundleItem$ = flatItem.bundleItem.bundle_selling_price) !== null && _flatItem$bundleItem$ !== void 0 ? _flatItem$bundleItem$ : isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
|
|
1640
1726
|
processed: true
|
|
@@ -1707,7 +1793,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1707
1793
|
var _product$total2;
|
|
1708
1794
|
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1709
1795
|
}
|
|
1710
|
-
arr.push(
|
|
1796
|
+
arr.push(_this5.hooks.setProduct(originProduct, _objectSpread({
|
|
1711
1797
|
// 商品券只替换被拆出的 splitCount 件。余量行原本仍有效的折扣卡
|
|
1712
1798
|
// 不能随全额抵扣卡拆分一起清除;已取消或已失效的折扣不会进入此列表。
|
|
1713
1799
|
discount_list: remainderDiscountList,
|
|
@@ -1741,7 +1827,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1741
1827
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1742
1828
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
1743
1829
|
// 如果当前 product 有 discount_list,则先从 origin_total 拿
|
|
1744
|
-
if (
|
|
1830
|
+
if (_this5.filterDiscountListByType(product.discount_list, 'promotion').length && product.origin_total) {
|
|
1745
1831
|
productOriginTotal = product.origin_total;
|
|
1746
1832
|
}
|
|
1747
1833
|
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
@@ -1763,14 +1849,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1763
1849
|
var discountedOptions = product.options;
|
|
1764
1850
|
var optionDiscountAmount = 0;
|
|
1765
1851
|
var reapplyDiscountPercent = void 0;
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1852
|
+
var bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount);
|
|
1853
|
+
if (isOrderLevel && (productAllocation || bookingDiscountPercent === undefined)) {
|
|
1854
|
+
var _productAllocation$di;
|
|
1855
|
+
// 整单卡只能使用分摊结果,缺少分摊时不能回退为每件扣减整单额度。
|
|
1856
|
+
amount = (_productAllocation$di = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.discountAmount) !== null && _productAllocation$di !== void 0 ? _productAllocation$di : 0;
|
|
1857
|
+
productDiscountDifference = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.difference;
|
|
1770
1858
|
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1771
|
-
} else if (
|
|
1859
|
+
} else if (bookingDiscountPercent !== undefined) {
|
|
1772
1860
|
// Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
|
|
1773
|
-
var percent =
|
|
1861
|
+
var percent = bookingDiscountPercent;
|
|
1774
1862
|
reapplyDiscountPercent = new Decimal(percent).toFixed(2);
|
|
1775
1863
|
mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1776
1864
|
amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
|
|
@@ -1830,7 +1918,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1830
1918
|
// 记录应用了优惠券的商品
|
|
1831
1919
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1832
1920
|
if (product.isClient) {
|
|
1833
|
-
arr.push(
|
|
1921
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1834
1922
|
discount_list: [discountDetail],
|
|
1835
1923
|
// 全额抵扣卡:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1836
1924
|
price: isFullCoverage ? mainProductSellingPrice : product.price,
|
|
@@ -1848,8 +1936,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1848
1936
|
options: discountedOptions
|
|
1849
1937
|
}));
|
|
1850
1938
|
} else {
|
|
1851
|
-
arr.push(
|
|
1852
|
-
discount_list:
|
|
1939
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1940
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1853
1941
|
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1854
1942
|
price: isFullCoverage ? 0 : product.price,
|
|
1855
1943
|
quantity: isNeedSplit ? appliedUseCount : product.quantity,
|
|
@@ -1938,7 +2026,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1938
2026
|
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1939
2027
|
num: normalNum,
|
|
1940
2028
|
quantity: normalNum,
|
|
1941
|
-
discount_list:
|
|
2029
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1942
2030
|
processed: true
|
|
1943
2031
|
}));
|
|
1944
2032
|
}
|
|
@@ -1962,15 +2050,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1962
2050
|
var fixedAmountPerItem;
|
|
1963
2051
|
var _productDiscountDifference;
|
|
1964
2052
|
var _reapplyDiscountPercent;
|
|
1965
|
-
|
|
2053
|
+
var _bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount3);
|
|
2054
|
+
if (_isOrderLevel && (_productAllocation || _bookingDiscountPercent === undefined)) {
|
|
2055
|
+
var _productAllocation$di2;
|
|
1966
2056
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1967
|
-
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1968
|
-
_productDiscountDifference = _productAllocation.difference;
|
|
2057
|
+
fixedAmountPerItem = (_productAllocation$di2 = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.discountAmount) !== null && _productAllocation$di2 !== void 0 ? _productAllocation$di2 : 0;
|
|
2058
|
+
_productDiscountDifference = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.difference;
|
|
1969
2059
|
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1970
|
-
} else if (
|
|
2060
|
+
} else if (_bookingDiscountPercent !== undefined) {
|
|
1971
2061
|
// hydrate 后 par_value 可能是余额/原值(例如 3500),百分比口径以
|
|
1972
2062
|
// 后端折扣快照 discount.percent 为准,与主商品重套逻辑保持一致。
|
|
1973
|
-
var _percent =
|
|
2063
|
+
var _percent = _bookingDiscountPercent;
|
|
1974
2064
|
_reapplyDiscountPercent = new Decimal(_percent).toFixed(2);
|
|
1975
2065
|
targetProductTotal = new Decimal(_productOriginTotal).mul(new Decimal(100).minus(_percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1976
2066
|
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
@@ -2017,7 +2107,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2017
2107
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
2018
2108
|
total: targetProductTotal,
|
|
2019
2109
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
2020
|
-
discount_list:
|
|
2110
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
2021
2111
|
processed: true
|
|
2022
2112
|
}));
|
|
2023
2113
|
}
|
|
@@ -2029,7 +2119,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2029
2119
|
var reconstructProductsWithBundle = function reconstructProductsWithBundle(processedProductsMap, processedFlatItemsMap, originalProductList) {
|
|
2030
2120
|
var result = [];
|
|
2031
2121
|
originalProductList.forEach(function (originProduct) {
|
|
2032
|
-
var product =
|
|
2122
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2033
2123
|
|
|
2034
2124
|
// 获取主商品处理结果
|
|
2035
2125
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
@@ -2038,8 +2128,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2038
2128
|
var getDefaultProduct = function getDefaultProduct() {
|
|
2039
2129
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
2040
2130
|
if (product.isClient) {
|
|
2041
|
-
return
|
|
2042
|
-
discount_list:
|
|
2131
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2132
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2043
2133
|
price: product.price,
|
|
2044
2134
|
origin_total: getProductOriginTotalPrice({
|
|
2045
2135
|
product: {
|
|
@@ -2060,8 +2150,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2060
2150
|
options: restoredOptions
|
|
2061
2151
|
});
|
|
2062
2152
|
} else {
|
|
2063
|
-
return
|
|
2064
|
-
discount_list:
|
|
2153
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2154
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2065
2155
|
total: product.total,
|
|
2066
2156
|
origin_total: product.origin_total,
|
|
2067
2157
|
price: product.price,
|
|
@@ -2107,10 +2197,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2107
2197
|
}
|
|
2108
2198
|
|
|
2109
2199
|
// 🔥 2. 如果有子商品应用了商品券,且主商品数量大于1,需要拆分主商品
|
|
2110
|
-
var mainProductQuantity = mainProductArr[0] ?
|
|
2200
|
+
var mainProductQuantity = mainProductArr[0] ? _this5.hooks.getProduct(mainProductArr[0]).quantity : 1;
|
|
2111
2201
|
if (hasFullCoveragePassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
|
|
2112
2202
|
var mainProduct = mainProductArr[0];
|
|
2113
|
-
var mainProductData =
|
|
2203
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2114
2204
|
|
|
2115
2205
|
// 🔥 方案:拆分成2个主商品
|
|
2116
2206
|
// 1. 一个主商品(qty=1)包含拆分后的bundle
|
|
@@ -2225,7 +2315,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2225
2315
|
}
|
|
2226
2316
|
|
|
2227
2317
|
// 添加第一个主商品:qty=1,包含拆分后的bundle
|
|
2228
|
-
result.push(
|
|
2318
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2229
2319
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_discount"),
|
|
2230
2320
|
quantity: 1,
|
|
2231
2321
|
discount_list: updatedMainDiscountList,
|
|
@@ -2297,7 +2387,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2297
2387
|
newOriginTotalOriginal = new Decimal(newOriginTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2298
2388
|
|
|
2299
2389
|
// 添加第二个主商品:qty=原quantity-1,包含原始bundle
|
|
2300
|
-
result.push(
|
|
2390
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2301
2391
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_normal"),
|
|
2302
2392
|
quantity: mainProductQuantity - 1,
|
|
2303
2393
|
discount_list: updatedMainDiscountListOriginal,
|
|
@@ -2310,7 +2400,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2310
2400
|
// 🔥 没有子商品被拆分,使用原有逻辑
|
|
2311
2401
|
mainProductArr.forEach(function (mainProduct) {
|
|
2312
2402
|
var _ref27, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
|
|
2313
|
-
var mainProductData =
|
|
2403
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2314
2404
|
|
|
2315
2405
|
// 重组bundle
|
|
2316
2406
|
var newBundle = [];
|
|
@@ -2397,7 +2487,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2397
2487
|
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2398
2488
|
|
|
2399
2489
|
// 生成最终的主商品
|
|
2400
|
-
result.push(
|
|
2490
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2401
2491
|
bundle: newBundle,
|
|
2402
2492
|
total: newTotal,
|
|
2403
2493
|
origin_total: newOriginTotal
|
|
@@ -2514,7 +2604,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2514
2604
|
});
|
|
2515
2605
|
};
|
|
2516
2606
|
var getProductDiscountDetails = function getProductDiscountDetails(originProduct) {
|
|
2517
|
-
var product =
|
|
2607
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2518
2608
|
return [].concat(_toConsumableArray(product.discount_list || []), _toConsumableArray((product.bundle || []).flatMap(function (bundle) {
|
|
2519
2609
|
return bundle.discount_list || [];
|
|
2520
2610
|
})));
|