@pisell/pisellos 0.10.78 → 0.10.79
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/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.js +27 -13
- package/dist/modules/Rules/index.d.ts +3 -10
- package/dist/modules/Rules/index.js +164 -82
- 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/solution/BaseSales/index.js +41 -21
- package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/lib/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.js +11 -0
- package/lib/modules/Rules/index.d.ts +3 -10
- package/lib/modules/Rules/index.js +62 -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/solution/BaseSales/index.js +19 -5
- package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
- 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);
|
|
@@ -249,6 +250,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
249
250
|
}
|
|
250
251
|
});
|
|
251
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
|
+
|
|
252
269
|
// 如果券不可用,判断不可用原因
|
|
253
270
|
var unavailableReason;
|
|
254
271
|
if (!hasApplicableDiscount) {
|
|
@@ -374,14 +391,41 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
374
391
|
}
|
|
375
392
|
}, {
|
|
376
393
|
key: "calcDiscount",
|
|
377
|
-
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) {
|
|
378
403
|
var _options$selectedList,
|
|
379
|
-
|
|
404
|
+
_this5 = this;
|
|
380
405
|
var discountList = _ref2.discountList,
|
|
381
406
|
productList = _ref2.productList,
|
|
382
407
|
holders = _ref2.holders,
|
|
383
408
|
isFormSubject = _ref2.isFormSubject,
|
|
384
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
|
+
};
|
|
385
429
|
var preferredEntitlementPassIds = new Set(((options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds) || []).map(String));
|
|
386
430
|
var resolveIsFormSubject = function resolveIsFormSubject(product) {
|
|
387
431
|
return typeof isFormSubject === 'function' ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
|
|
@@ -399,8 +443,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
399
443
|
return uid !== undefined && uid !== null && uid !== '';
|
|
400
444
|
}).map(String));
|
|
401
445
|
var getOriginProductUid = function getOriginProductUid(originProduct) {
|
|
402
|
-
var _originProduct$
|
|
403
|
-
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;
|
|
404
448
|
if (uid === undefined || uid === null || uid === '') return undefined;
|
|
405
449
|
return String(uid);
|
|
406
450
|
};
|
|
@@ -476,7 +520,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
476
520
|
var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
|
|
477
521
|
var flattened = [];
|
|
478
522
|
productList.forEach(function (originProduct) {
|
|
479
|
-
var product =
|
|
523
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
480
524
|
|
|
481
525
|
// 1. 添加主商品
|
|
482
526
|
flattened.push({
|
|
@@ -955,8 +999,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
955
999
|
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
956
1000
|
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
957
1001
|
var _discount$config2, _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
|
|
958
|
-
if (
|
|
1002
|
+
if (_this5.discountScope && !_this5.discountScope(flatItem.originProduct, discount)) return false;
|
|
959
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;
|
|
960
1005
|
var product;
|
|
961
1006
|
if (flatItem.type === 'main') {
|
|
962
1007
|
product = flatItem.product;
|
|
@@ -973,7 +1018,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
973
1018
|
startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
|
|
974
1019
|
};
|
|
975
1020
|
}
|
|
976
|
-
if (
|
|
1021
|
+
if (_this5.isItemRewardProductDiscount(product)) {
|
|
977
1022
|
return false;
|
|
978
1023
|
}
|
|
979
1024
|
|
|
@@ -1019,10 +1064,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1019
1064
|
}
|
|
1020
1065
|
|
|
1021
1066
|
// 套餐规则检查
|
|
1022
|
-
var isBundleAvailable =
|
|
1067
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1023
1068
|
return isLimitedProduct && isBundleAvailable;
|
|
1024
1069
|
};
|
|
1025
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
|
+
|
|
1026
1095
|
// 收集所有被勾选的 order_level 折扣卡及其适用商品
|
|
1027
1096
|
var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1028
1097
|
return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
|
|
@@ -1050,6 +1119,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1050
1119
|
// Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
|
|
1051
1120
|
var occupiedItems = new Map();
|
|
1052
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
|
+
|
|
1053
1139
|
// 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
|
|
1054
1140
|
selectedOrderLevelDiscounts.forEach(function (discount) {
|
|
1055
1141
|
var limitedData = discount.limited_relation_product_data;
|
|
@@ -1079,7 +1165,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1079
1165
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
1080
1166
|
var applicableProducts = [];
|
|
1081
1167
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
1082
|
-
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price,
|
|
1168
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref13, _flatItem$original_pr;
|
|
1083
1169
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
1084
1170
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
1085
1171
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -1107,7 +1193,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1107
1193
|
|
|
1108
1194
|
// 对于主商品:使用 price
|
|
1109
1195
|
// 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
|
|
1110
|
-
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);
|
|
1111
1197
|
|
|
1112
1198
|
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
1113
1199
|
var productData = {
|
|
@@ -1162,13 +1248,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1162
1248
|
};
|
|
1163
1249
|
originProduct = flatItem.originProduct;
|
|
1164
1250
|
}
|
|
1165
|
-
var isItemRewardProductDiscount =
|
|
1251
|
+
var isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1166
1252
|
addModeDiscount.forEach(function (discount) {
|
|
1167
|
-
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$
|
|
1253
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config4;
|
|
1168
1254
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
1169
1255
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
1170
1256
|
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;
|
|
1171
|
-
var isHolderMatch =
|
|
1257
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1172
1258
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1173
1259
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1174
1260
|
}, flatItem.originProduct, holders);
|
|
@@ -1186,7 +1272,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1186
1272
|
}));
|
|
1187
1273
|
|
|
1188
1274
|
// 套餐是否可用判断
|
|
1189
|
-
var isBundleAvailable =
|
|
1275
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1190
1276
|
if (isProductInScope && isBundleAvailable && !isItemRewardProductDiscount) {
|
|
1191
1277
|
var timeReasons = discountTimeReasons.get(discount.id) || [];
|
|
1192
1278
|
timeReasons.push(timeReason);
|
|
@@ -1195,10 +1281,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1195
1281
|
}
|
|
1196
1282
|
|
|
1197
1283
|
// 判断优惠券是否适用于该商品
|
|
1198
|
-
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$
|
|
1284
|
+
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config4 = discount.config) !== null && _discount$config4 !== void 0 && _discount$config4.isAvailable && (!isEntitlementPass(discount) || getRemainingEntitlementUses(discount, 0, 1) > 0)) {
|
|
1199
1285
|
var _discountApplicabilit, _discount$metadata4, _discount$metadata5, _discount$metadata6;
|
|
1200
1286
|
// 记录此优惠券适用的商品
|
|
1201
1287
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
1288
|
+
if (flatItem.type === 'main' && isPromotionDiscountCard(discount)) {
|
|
1289
|
+
var _promotionPolicy$onAp;
|
|
1290
|
+
promotionPolicy === null || promotionPolicy === void 0 || (_promotionPolicy$onAp = promotionPolicy.onApplicableCard) === null || _promotionPolicy$onAp === void 0 || _promotionPolicy$onAp.call(promotionPolicy, originProduct, discount);
|
|
1291
|
+
}
|
|
1202
1292
|
|
|
1203
1293
|
// 记录可抵扣的商品详情
|
|
1204
1294
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
@@ -1245,13 +1335,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1245
1335
|
};
|
|
1246
1336
|
var optionDiscountAmount = 0;
|
|
1247
1337
|
var discountedOptions = options.map(function (option) {
|
|
1248
|
-
var
|
|
1338
|
+
var _ref14, _ref15, _option$_original_pri, _ref16, _option$num, _rest$price, _option$_original_pri2;
|
|
1249
1339
|
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
1250
|
-
var rawUnit = (
|
|
1340
|
+
var rawUnit = (_ref14 = (_ref15 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref15 !== void 0 ? _ref15 : option.price) !== null && _ref14 !== void 0 ? _ref14 : option.add_price;
|
|
1251
1341
|
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
1252
1342
|
if (baseUnitNum <= 0) return option;
|
|
1253
1343
|
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
1254
|
-
var optQty = Number((
|
|
1344
|
+
var optQty = Number((_ref16 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref16 !== void 0 ? _ref16 : 1);
|
|
1255
1345
|
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
1256
1346
|
var _original_add_price = option._original_add_price,
|
|
1257
1347
|
rest = _objectWithoutProperties(option, _excluded);
|
|
@@ -1285,9 +1375,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1285
1375
|
var getOptionTotal = function getOptionTotal(options) {
|
|
1286
1376
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
1287
1377
|
return options.reduce(function (sum, opt) {
|
|
1288
|
-
var
|
|
1289
|
-
var unit = Number((
|
|
1290
|
-
var n = Number((
|
|
1378
|
+
var _ref17, _opt$price, _ref18, _opt$num;
|
|
1379
|
+
var unit = Number((_ref17 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref17 !== void 0 ? _ref17 : 0);
|
|
1380
|
+
var n = Number((_ref18 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref18 !== void 0 ? _ref18 : 1);
|
|
1291
1381
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
1292
1382
|
}, 0);
|
|
1293
1383
|
};
|
|
@@ -1342,8 +1432,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1342
1432
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1343
1433
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1344
1434
|
var _product$discount_lis3, _product$discount_lis4;
|
|
1345
|
-
if (
|
|
1346
|
-
if (
|
|
1435
|
+
if (_this5.discountScope && !_this5.discountScope(originProduct, discount)) return false;
|
|
1436
|
+
if (_this5.isItemRewardProductDiscount(product)) return false;
|
|
1437
|
+
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
1347
1438
|
// 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
|
|
1348
1439
|
var discountType = discount.tag || discount.type;
|
|
1349
1440
|
var currentOriginUid = getOriginProductUid(originProduct);
|
|
@@ -1354,9 +1445,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1354
1445
|
if (!discount.isSelected) return false;
|
|
1355
1446
|
}
|
|
1356
1447
|
if (['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && !isReapplyEditModeDiscountForProduct) {
|
|
1357
|
-
var _discount$
|
|
1448
|
+
var _discount$config5;
|
|
1358
1449
|
// 如果策略检查后没有config,说明不可用
|
|
1359
|
-
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$
|
|
1450
|
+
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config5 = discount.config) !== null && _discount$config5 !== void 0 && _discount$config5.isAvailable)) {
|
|
1360
1451
|
return false;
|
|
1361
1452
|
}
|
|
1362
1453
|
}
|
|
@@ -1381,8 +1472,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1381
1472
|
|
|
1382
1473
|
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
1383
1474
|
if (isFullCoveragePass(discount)) {
|
|
1384
|
-
var _discount$
|
|
1385
|
-
var maxUsagePerOrder = (_discount$
|
|
1475
|
+
var _discount$config6;
|
|
1476
|
+
var maxUsagePerOrder = (_discount$config6 = discount.config) === null || _discount$config6 === void 0 ? void 0 : _discount$config6.maxUsagePerOrder;
|
|
1386
1477
|
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1387
1478
|
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
1388
1479
|
if (currentUsedCount >= maxUsagePerOrder) {
|
|
@@ -1394,7 +1485,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1394
1485
|
|
|
1395
1486
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
1396
1487
|
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;
|
|
1397
|
-
var isHolderMatch =
|
|
1488
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1398
1489
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1399
1490
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1400
1491
|
}, flatItem.originProduct, holders);
|
|
@@ -1412,13 +1503,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1412
1503
|
return false;
|
|
1413
1504
|
}
|
|
1414
1505
|
// 检查 package_sub_item_usage_rules
|
|
1415
|
-
if (!
|
|
1506
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1416
1507
|
return false;
|
|
1417
1508
|
}
|
|
1418
1509
|
return true;
|
|
1419
1510
|
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1420
1511
|
// 检查 package_sub_item_usage_rules
|
|
1421
|
-
if (!
|
|
1512
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1422
1513
|
return false;
|
|
1423
1514
|
}
|
|
1424
1515
|
return true;
|
|
@@ -1428,27 +1519,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1428
1519
|
|
|
1429
1520
|
// 识别用户本次显式选择的卡券,供次卡和折扣卡各自的优先级使用。
|
|
1430
1521
|
// 目标仍必须在当前商品的 applicableDiscounts 中,因此不会绕过 Holder、时间或商品范围校验。
|
|
1431
|
-
var explicitlySelectedDiscount = (
|
|
1432
|
-
var discountType = discount.tag || discount.type;
|
|
1433
|
-
return String(discount.id) === String(options.discountId) && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
|
|
1434
|
-
}) : undefined;
|
|
1522
|
+
var explicitlySelectedDiscount = findExplicitlySelectedDiscount(applicableDiscounts);
|
|
1435
1523
|
// 折扣卡会复用于整条商品行;商品券必须继续按单张拆分,不能复用该分支。
|
|
1436
1524
|
var explicitlySelectedDiscountCard = explicitlySelectedDiscount && !isFullCoveragePass(explicitlySelectedDiscount) ? explicitlySelectedDiscount : undefined;
|
|
1437
1525
|
|
|
1438
1526
|
// 商品数量等变化会触发无 discountId 的重算。只要当前行已应用的卡仍在
|
|
1439
1527
|
// applicableDiscounts 中,就应保留该行选择,避免被自动排序中力度更大的卡替换。
|
|
1440
|
-
var appliedWalletDiscountIds =
|
|
1441
|
-
|
|
1442
|
-
}).map(function (item) {
|
|
1443
|
-
var _ref18, _item$discount$resour, _item$discount;
|
|
1444
|
-
return (_ref18 = (_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 && _ref18 !== void 0 ? _ref18 : item === null || item === void 0 ? void 0 : item.id;
|
|
1445
|
-
}).filter(function (id) {
|
|
1446
|
-
return id !== undefined && id !== null;
|
|
1447
|
-
}).map(String));
|
|
1448
|
-
var appliedDiscountCard = options !== null && options !== void 0 && options.scan ? undefined : applicableDiscounts.find(function (discount) {
|
|
1449
|
-
var discountType = discount.tag || discount.type;
|
|
1450
|
-
return discount.isSelected === true && ['discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && appliedWalletDiscountIds.has(String(discount.id));
|
|
1451
|
-
});
|
|
1528
|
+
var appliedWalletDiscountIds = getAppliedWalletDiscountIds(product);
|
|
1529
|
+
var appliedDiscountCard = findAppliedDiscountCard(applicableDiscounts, appliedWalletDiscountIds);
|
|
1452
1530
|
var appliedEntitlementPass = options !== null && options !== void 0 && options.scan || (options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) === false ? undefined : applicableDiscounts.find(function (discount) {
|
|
1453
1531
|
return isEntitlementPass(discount) && discount.isSelected === true && appliedWalletDiscountIds.has(String(discount.id));
|
|
1454
1532
|
});
|
|
@@ -1486,7 +1564,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1486
1564
|
}) && (!((_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) {
|
|
1487
1565
|
return item.type === 'product';
|
|
1488
1566
|
})));
|
|
1489
|
-
isItemRewardProductDiscount =
|
|
1567
|
+
isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1490
1568
|
if (product.inPromotion && !isItemRewardProductDiscount) {
|
|
1491
1569
|
isManualDiscount = false;
|
|
1492
1570
|
}
|
|
@@ -1569,7 +1647,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1569
1647
|
// 主商品:保持原有逻辑,还原 option 价格
|
|
1570
1648
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
1571
1649
|
if (product.isClient) {
|
|
1572
|
-
processedProductsMap.set(product._id, [
|
|
1650
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1573
1651
|
origin_total: getProductOriginTotalPrice({
|
|
1574
1652
|
product: {
|
|
1575
1653
|
original_price: product.original_price
|
|
@@ -1589,7 +1667,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1589
1667
|
price: product.price,
|
|
1590
1668
|
options: restoredOptions
|
|
1591
1669
|
}), {}, {
|
|
1592
|
-
discount_list: isManualDiscount ?
|
|
1670
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1593
1671
|
}))]);
|
|
1594
1672
|
} else {
|
|
1595
1673
|
var _ref21, _product$_promotion$f, _product13, _product$origin_total;
|
|
@@ -1602,7 +1680,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1602
1680
|
total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
|
|
1603
1681
|
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;
|
|
1604
1682
|
}
|
|
1605
|
-
processedProductsMap.set(product._id, [
|
|
1683
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
|
|
1606
1684
|
price: product.price,
|
|
1607
1685
|
main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
|
|
1608
1686
|
}, isItemRewardProductDiscount ? {
|
|
@@ -1614,14 +1692,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1614
1692
|
main_product_selling_price: main_product_selling_price,
|
|
1615
1693
|
options: restoredOptions
|
|
1616
1694
|
}), {}, {
|
|
1617
|
-
discount_list: isManualDiscount ?
|
|
1695
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1618
1696
|
}))]);
|
|
1619
1697
|
}
|
|
1620
1698
|
} else {
|
|
1621
1699
|
var _flatItem$bundleItem8, _flatItem$bundleItem9, _flatItem$bundleItem$;
|
|
1622
1700
|
// bundle子商品:保存到扁平化Map
|
|
1623
1701
|
processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1624
|
-
discount_list: isManualDiscount ?
|
|
1702
|
+
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'),
|
|
1625
1703
|
price: flatItem.bundleItem.price,
|
|
1626
1704
|
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,
|
|
1627
1705
|
processed: true
|
|
@@ -1694,7 +1772,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1694
1772
|
var _product$total2;
|
|
1695
1773
|
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1696
1774
|
}
|
|
1697
|
-
arr.push(
|
|
1775
|
+
arr.push(_this5.hooks.setProduct(originProduct, _objectSpread({
|
|
1698
1776
|
// 商品券只替换被拆出的 splitCount 件。余量行原本仍有效的折扣卡
|
|
1699
1777
|
// 不能随全额抵扣卡拆分一起清除;已取消或已失效的折扣不会进入此列表。
|
|
1700
1778
|
discount_list: remainderDiscountList,
|
|
@@ -1728,7 +1806,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1728
1806
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1729
1807
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
1730
1808
|
// 如果当前 product 有 discount_list,则先从 origin_total 拿
|
|
1731
|
-
if (
|
|
1809
|
+
if (_this5.filterDiscountListByType(product.discount_list, 'promotion').length && product.origin_total) {
|
|
1732
1810
|
productOriginTotal = product.origin_total;
|
|
1733
1811
|
}
|
|
1734
1812
|
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
@@ -1750,14 +1828,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1750
1828
|
var discountedOptions = product.options;
|
|
1751
1829
|
var optionDiscountAmount = 0;
|
|
1752
1830
|
var reapplyDiscountPercent = void 0;
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1831
|
+
var bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount);
|
|
1832
|
+
if (isOrderLevel && (productAllocation || bookingDiscountPercent === undefined)) {
|
|
1833
|
+
var _productAllocation$di;
|
|
1834
|
+
// 整单卡只能使用分摊结果,缺少分摊时不能回退为每件扣减整单额度。
|
|
1835
|
+
amount = (_productAllocation$di = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.discountAmount) !== null && _productAllocation$di !== void 0 ? _productAllocation$di : 0;
|
|
1836
|
+
productDiscountDifference = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.difference;
|
|
1757
1837
|
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1758
|
-
} else if (
|
|
1838
|
+
} else if (bookingDiscountPercent !== undefined) {
|
|
1759
1839
|
// Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
|
|
1760
|
-
var percent =
|
|
1840
|
+
var percent = bookingDiscountPercent;
|
|
1761
1841
|
reapplyDiscountPercent = new Decimal(percent).toFixed(2);
|
|
1762
1842
|
mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1763
1843
|
amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
|
|
@@ -1817,7 +1897,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1817
1897
|
// 记录应用了优惠券的商品
|
|
1818
1898
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1819
1899
|
if (product.isClient) {
|
|
1820
|
-
arr.push(
|
|
1900
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1821
1901
|
discount_list: [discountDetail],
|
|
1822
1902
|
// 全额抵扣卡:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1823
1903
|
price: isFullCoverage ? mainProductSellingPrice : product.price,
|
|
@@ -1835,8 +1915,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1835
1915
|
options: discountedOptions
|
|
1836
1916
|
}));
|
|
1837
1917
|
} else {
|
|
1838
|
-
arr.push(
|
|
1839
|
-
discount_list:
|
|
1918
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1919
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1840
1920
|
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1841
1921
|
price: isFullCoverage ? 0 : product.price,
|
|
1842
1922
|
quantity: isNeedSplit ? appliedUseCount : product.quantity,
|
|
@@ -1925,7 +2005,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1925
2005
|
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1926
2006
|
num: normalNum,
|
|
1927
2007
|
quantity: normalNum,
|
|
1928
|
-
discount_list:
|
|
2008
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1929
2009
|
processed: true
|
|
1930
2010
|
}));
|
|
1931
2011
|
}
|
|
@@ -1949,15 +2029,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1949
2029
|
var fixedAmountPerItem;
|
|
1950
2030
|
var _productDiscountDifference;
|
|
1951
2031
|
var _reapplyDiscountPercent;
|
|
1952
|
-
|
|
2032
|
+
var _bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount3);
|
|
2033
|
+
if (_isOrderLevel && (_productAllocation || _bookingDiscountPercent === undefined)) {
|
|
2034
|
+
var _productAllocation$di2;
|
|
1953
2035
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1954
|
-
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1955
|
-
_productDiscountDifference = _productAllocation.difference;
|
|
2036
|
+
fixedAmountPerItem = (_productAllocation$di2 = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.discountAmount) !== null && _productAllocation$di2 !== void 0 ? _productAllocation$di2 : 0;
|
|
2037
|
+
_productDiscountDifference = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.difference;
|
|
1956
2038
|
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1957
|
-
} else if (
|
|
2039
|
+
} else if (_bookingDiscountPercent !== undefined) {
|
|
1958
2040
|
// hydrate 后 par_value 可能是余额/原值(例如 3500),百分比口径以
|
|
1959
2041
|
// 后端折扣快照 discount.percent 为准,与主商品重套逻辑保持一致。
|
|
1960
|
-
var _percent =
|
|
2042
|
+
var _percent = _bookingDiscountPercent;
|
|
1961
2043
|
_reapplyDiscountPercent = new Decimal(_percent).toFixed(2);
|
|
1962
2044
|
targetProductTotal = new Decimal(_productOriginTotal).mul(new Decimal(100).minus(_percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1963
2045
|
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
@@ -2004,7 +2086,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2004
2086
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
2005
2087
|
total: targetProductTotal,
|
|
2006
2088
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
2007
|
-
discount_list:
|
|
2089
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
2008
2090
|
processed: true
|
|
2009
2091
|
}));
|
|
2010
2092
|
}
|
|
@@ -2016,7 +2098,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2016
2098
|
var reconstructProductsWithBundle = function reconstructProductsWithBundle(processedProductsMap, processedFlatItemsMap, originalProductList) {
|
|
2017
2099
|
var result = [];
|
|
2018
2100
|
originalProductList.forEach(function (originProduct) {
|
|
2019
|
-
var product =
|
|
2101
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2020
2102
|
|
|
2021
2103
|
// 获取主商品处理结果
|
|
2022
2104
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
@@ -2025,8 +2107,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2025
2107
|
var getDefaultProduct = function getDefaultProduct() {
|
|
2026
2108
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
2027
2109
|
if (product.isClient) {
|
|
2028
|
-
return
|
|
2029
|
-
discount_list:
|
|
2110
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2111
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2030
2112
|
price: product.price,
|
|
2031
2113
|
origin_total: getProductOriginTotalPrice({
|
|
2032
2114
|
product: {
|
|
@@ -2047,8 +2129,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2047
2129
|
options: restoredOptions
|
|
2048
2130
|
});
|
|
2049
2131
|
} else {
|
|
2050
|
-
return
|
|
2051
|
-
discount_list:
|
|
2132
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2133
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2052
2134
|
total: product.total,
|
|
2053
2135
|
origin_total: product.origin_total,
|
|
2054
2136
|
price: product.price,
|
|
@@ -2094,10 +2176,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2094
2176
|
}
|
|
2095
2177
|
|
|
2096
2178
|
// 🔥 2. 如果有子商品应用了商品券,且主商品数量大于1,需要拆分主商品
|
|
2097
|
-
var mainProductQuantity = mainProductArr[0] ?
|
|
2179
|
+
var mainProductQuantity = mainProductArr[0] ? _this5.hooks.getProduct(mainProductArr[0]).quantity : 1;
|
|
2098
2180
|
if (hasFullCoveragePassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
|
|
2099
2181
|
var mainProduct = mainProductArr[0];
|
|
2100
|
-
var mainProductData =
|
|
2182
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2101
2183
|
|
|
2102
2184
|
// 🔥 方案:拆分成2个主商品
|
|
2103
2185
|
// 1. 一个主商品(qty=1)包含拆分后的bundle
|
|
@@ -2212,7 +2294,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2212
2294
|
}
|
|
2213
2295
|
|
|
2214
2296
|
// 添加第一个主商品:qty=1,包含拆分后的bundle
|
|
2215
|
-
result.push(
|
|
2297
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2216
2298
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_discount"),
|
|
2217
2299
|
quantity: 1,
|
|
2218
2300
|
discount_list: updatedMainDiscountList,
|
|
@@ -2284,7 +2366,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2284
2366
|
newOriginTotalOriginal = new Decimal(newOriginTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2285
2367
|
|
|
2286
2368
|
// 添加第二个主商品:qty=原quantity-1,包含原始bundle
|
|
2287
|
-
result.push(
|
|
2369
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2288
2370
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_normal"),
|
|
2289
2371
|
quantity: mainProductQuantity - 1,
|
|
2290
2372
|
discount_list: updatedMainDiscountListOriginal,
|
|
@@ -2297,7 +2379,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2297
2379
|
// 🔥 没有子商品被拆分,使用原有逻辑
|
|
2298
2380
|
mainProductArr.forEach(function (mainProduct) {
|
|
2299
2381
|
var _ref23, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
|
|
2300
|
-
var mainProductData =
|
|
2382
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2301
2383
|
|
|
2302
2384
|
// 重组bundle
|
|
2303
2385
|
var newBundle = [];
|
|
@@ -2384,7 +2466,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2384
2466
|
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2385
2467
|
|
|
2386
2468
|
// 生成最终的主商品
|
|
2387
|
-
result.push(
|
|
2469
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2388
2470
|
bundle: newBundle,
|
|
2389
2471
|
total: newTotal,
|
|
2390
2472
|
origin_total: newOriginTotal
|
|
@@ -2501,7 +2583,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2501
2583
|
});
|
|
2502
2584
|
};
|
|
2503
2585
|
var getProductDiscountDetails = function getProductDiscountDetails(originProduct) {
|
|
2504
|
-
var product =
|
|
2586
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2505
2587
|
return [].concat(_toConsumableArray(product.discount_list || []), _toConsumableArray((product.bundle || []).flatMap(function (bundle) {
|
|
2506
2588
|
return bundle.discount_list || [];
|
|
2507
2589
|
})));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Discount } from '../Discount/types';
|
|
2
|
+
import type { DiscountResult, RulesCalcDiscountOptions, RulesCalcDiscountParams, RulesParamsHooks } from './types';
|
|
3
|
+
export declare function isPromotionDiscountCard(discount: any): boolean;
|
|
4
|
+
/** 只处理当前购物车的 X 件 Y 元,历史成交和其他促销继续使用原有规则。 */
|
|
5
|
+
export declare function getExclusivePromotion(product: any): any | undefined;
|
|
6
|
+
export interface PromotionSelectionPolicy {
|
|
7
|
+
blockedStrategyIds: ReadonlySet<string>;
|
|
8
|
+
onApplicableCard?: (product: any, discount: Discount) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 以完整策略参与组为单位比较两套实际报价。每次试算都从同一快照开始,
|
|
12
|
+
* 由原引擎重新做卡券校验和整单卡分摊,不能从叠加结果里事后减掉某条优惠。
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculatePromotionSelection(params: RulesCalcDiscountParams, options: RulesCalcDiscountOptions | undefined, hooks: RulesParamsHooks, calculate: (params: RulesCalcDiscountParams, options?: RulesCalcDiscountOptions, policy?: PromotionSelectionPolicy) => DiscountResult): DiscountResult;
|