@pisell/pisellos 2.2.317 → 2.2.319
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.d.ts +1 -1
- package/dist/modules/Order/index.js +27 -13
- package/dist/modules/Order/utils.js +45 -45
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Rules/index.d.ts +3 -10
- package/dist/modules/Rules/index.js +169 -87
- 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.js +41 -21
- package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- 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.d.ts +1 -1
- package/lib/modules/Order/index.js +11 -0
- package/lib/modules/Order/utils.js +1 -1
- package/lib/modules/Payment/walletpass.js +23 -1
- 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/server/modules/order/index.d.ts +6 -0
- package/lib/server/modules/order/index.js +226 -29
- package/lib/solution/BaseSales/index.js +19 -5
- package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- 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);
|
|
@@ -243,6 +244,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
243
244
|
}
|
|
244
245
|
});
|
|
245
246
|
|
|
247
|
+
// 卡可用但互斥比较选择了促销时,扫码仍应加入可选卡列表,不能被标为商品不适用。
|
|
248
|
+
if (!hasApplicableDiscount) {
|
|
249
|
+
var promotionProductIds = new Set(result.productList.filter(function (product) {
|
|
250
|
+
var _getExclusivePromotio;
|
|
251
|
+
return ((_getExclusivePromotio = getExclusivePromotion(product)) === null || _getExclusivePromotio === void 0 ? void 0 : _getExclusivePromotio.inPromotion) === true;
|
|
252
|
+
}).map(function (product) {
|
|
253
|
+
return _this2.hooks.getProduct(product).id;
|
|
254
|
+
}));
|
|
255
|
+
hasApplicableDiscount = result.discountList.some(function (discount) {
|
|
256
|
+
var _discount$applicableP;
|
|
257
|
+
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) {
|
|
258
|
+
return promotionProductIds.has(id);
|
|
259
|
+
}));
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
246
263
|
// 如果券不可用,判断不可用原因
|
|
247
264
|
var unavailableReason;
|
|
248
265
|
if (!hasApplicableDiscount) {
|
|
@@ -368,14 +385,41 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
368
385
|
}
|
|
369
386
|
}, {
|
|
370
387
|
key: "calcDiscount",
|
|
371
|
-
value: function calcDiscount(
|
|
388
|
+
value: function calcDiscount(params, options) {
|
|
389
|
+
var _this4 = this;
|
|
390
|
+
return calculatePromotionSelection(params, options, this.hooks, function (input, calculationOptions, policy) {
|
|
391
|
+
return _this4.calcDiscountCore(input, calculationOptions, policy);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}, {
|
|
395
|
+
key: "calcDiscountCore",
|
|
396
|
+
value: function calcDiscountCore(_ref2, options, promotionPolicy) {
|
|
372
397
|
var _options$selectedList,
|
|
373
|
-
|
|
398
|
+
_this5 = this;
|
|
374
399
|
var discountList = _ref2.discountList,
|
|
375
400
|
productList = _ref2.productList,
|
|
376
401
|
holders = _ref2.holders,
|
|
377
402
|
isFormSubject = _ref2.isFormSubject,
|
|
378
403
|
orderTotalAmount = _ref2.orderTotalAmount;
|
|
404
|
+
var cancelledPromotionCards = discountList.filter(function (discount) {
|
|
405
|
+
return !discount.isEditMode && isPromotionDiscountCard(discount) && discount.promotionSelection === 'promotion';
|
|
406
|
+
});
|
|
407
|
+
var cancelledPromotionProductIds = new Set(cancelledPromotionCards.flatMap(function (discount) {
|
|
408
|
+
return discount.applicableProductIds || [];
|
|
409
|
+
}));
|
|
410
|
+
var cancelledPromotionStrategyIds = new Set(cancelledPromotionCards.flatMap(function (discount) {
|
|
411
|
+
return discount.promotionSelectionStrategyIds || [];
|
|
412
|
+
}));
|
|
413
|
+
var isCardBlockedByPromotion = function isCardBlockedByPromotion(flatItem, discount) {
|
|
414
|
+
var _originProduct$metada, _originProduct$metada2;
|
|
415
|
+
if (flatItem.type !== 'main' || !isPromotionDiscountCard(discount)) return false;
|
|
416
|
+
var originProduct = flatItem.originProduct;
|
|
417
|
+
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;
|
|
418
|
+
// 取消卡后即使数量暂未凑足促销,也不能自动改用另一张卡;重新手选/最佳组合会清除该意图。
|
|
419
|
+
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;
|
|
420
|
+
var promotion = getExclusivePromotion(originProduct);
|
|
421
|
+
return Boolean(promotion && (promotionPolicy === null || promotionPolicy === void 0 ? void 0 : promotionPolicy.blockedStrategyIds.has(String(promotion.strategyId))));
|
|
422
|
+
};
|
|
379
423
|
var preferredEntitlementPassIds = new Set(((options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds) || []).map(String));
|
|
380
424
|
var resolveIsFormSubject = function resolveIsFormSubject(product) {
|
|
381
425
|
return typeof isFormSubject === 'function' ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
|
|
@@ -393,8 +437,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
393
437
|
return uid !== undefined && uid !== null && uid !== '';
|
|
394
438
|
}).map(String));
|
|
395
439
|
var getOriginProductUid = function getOriginProductUid(originProduct) {
|
|
396
|
-
var _originProduct$
|
|
397
|
-
var uid = (_originProduct$
|
|
440
|
+
var _originProduct$metada3, _originProduct$metada4;
|
|
441
|
+
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
442
|
if (uid === undefined || uid === null || uid === '') return undefined;
|
|
399
443
|
return String(uid);
|
|
400
444
|
};
|
|
@@ -470,7 +514,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
470
514
|
var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
|
|
471
515
|
var flattened = [];
|
|
472
516
|
productList.forEach(function (originProduct) {
|
|
473
|
-
var product =
|
|
517
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
474
518
|
|
|
475
519
|
// 1. 添加主商品
|
|
476
520
|
flattened.push({
|
|
@@ -950,6 +994,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
950
994
|
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
951
995
|
var _discount$config2, _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
|
|
952
996
|
if (((_discount$config2 = discount.config) === null || _discount$config2 === void 0 ? void 0 : _discount$config2.isAvailable) === false) return false;
|
|
997
|
+
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
953
998
|
var product;
|
|
954
999
|
if (flatItem.type === 'main') {
|
|
955
1000
|
product = flatItem.product;
|
|
@@ -966,7 +1011,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
966
1011
|
startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
|
|
967
1012
|
};
|
|
968
1013
|
}
|
|
969
|
-
if (
|
|
1014
|
+
if (_this5.isItemRewardProductDiscount(product)) {
|
|
970
1015
|
return false;
|
|
971
1016
|
}
|
|
972
1017
|
|
|
@@ -1012,10 +1057,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1012
1057
|
}
|
|
1013
1058
|
|
|
1014
1059
|
// 套餐规则检查
|
|
1015
|
-
var isBundleAvailable =
|
|
1060
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1016
1061
|
return isLimitedProduct && isBundleAvailable;
|
|
1017
1062
|
};
|
|
1018
1063
|
|
|
1064
|
+
// 分摊占位与实际应用共用选择优先级,数量跌出促销门槛时也保留手选意图。
|
|
1065
|
+
var findExplicitlySelectedDiscount = function findExplicitlySelectedDiscount(applicableDiscounts) {
|
|
1066
|
+
return ((options === null || options === void 0 ? void 0 : options.isSelected) === true && options.discountId !== undefined ? applicableDiscounts.find(function (discount) {
|
|
1067
|
+
return String(discount.id) === String(options.discountId) && (isFullCoveragePass(discount) || isPromotionDiscountCard(discount));
|
|
1068
|
+
}) : undefined) || ((options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) !== false ? applicableDiscounts.find(function (discount) {
|
|
1069
|
+
return discount.promotionSelection === 'card';
|
|
1070
|
+
}) : undefined);
|
|
1071
|
+
};
|
|
1072
|
+
var getAppliedWalletDiscountIds = function getAppliedWalletDiscountIds(product) {
|
|
1073
|
+
return new Set((product.discount_list || []).filter(function (item) {
|
|
1074
|
+
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));
|
|
1075
|
+
}).map(function (item) {
|
|
1076
|
+
var _ref12, _item$discount$resour, _item$discount;
|
|
1077
|
+
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;
|
|
1078
|
+
}).filter(function (id) {
|
|
1079
|
+
return id !== undefined && id !== null;
|
|
1080
|
+
}).map(String));
|
|
1081
|
+
};
|
|
1082
|
+
var findAppliedDiscountCard = function findAppliedDiscountCard(applicableDiscounts, appliedIds) {
|
|
1083
|
+
return options !== null && options !== void 0 && options.scan || (options === null || options === void 0 ? void 0 : options.preserveEntitlementSelection) === false ? undefined : applicableDiscounts.find(function (discount) {
|
|
1084
|
+
return discount.isSelected === true && isPromotionDiscountCard(discount) && appliedIds.has(String(discount.id));
|
|
1085
|
+
});
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1019
1088
|
// 收集所有被勾选的 order_level 折扣卡及其适用商品
|
|
1020
1089
|
var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1021
1090
|
return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
|
|
@@ -1043,6 +1112,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1043
1112
|
// Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
|
|
1044
1113
|
var occupiedItems = new Map();
|
|
1045
1114
|
|
|
1115
|
+
// 手选/已应用的卡先占位(包括全品类卡),其他候选卡不能抢走其分摊商品。
|
|
1116
|
+
sortedFlattenedList.forEach(function (flatItem) {
|
|
1117
|
+
var product = flatItem.type === 'main' ? flatItem.product : flatItem.bundleItem;
|
|
1118
|
+
var holderProduct = flatItem.type === 'main' ? flatItem.product : flatItem.parentProduct;
|
|
1119
|
+
var applicableCards = sortedDiscountList.filter(function (discount) {
|
|
1120
|
+
var _discount$config3;
|
|
1121
|
+
return isPromotionDiscountCard(discount) && ((_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.isAvailable) && checkItemApplicableForDiscount(flatItem, discount) && _this5.checkHolderMatch(discount, {
|
|
1122
|
+
isNeedHolder: resolveIsFormSubject(holderProduct) && !(holderProduct !== null && holderProduct !== void 0 && holderProduct.isNormalProduct),
|
|
1123
|
+
holder_id: (holderProduct === null || holderProduct === void 0 ? void 0 : holderProduct.holder_id) || product.holder_id
|
|
1124
|
+
}, flatItem.originProduct, holders);
|
|
1125
|
+
});
|
|
1126
|
+
var preferredCard = findExplicitlySelectedDiscount(applicableCards) || findAppliedDiscountCard(applicableCards, getAppliedWalletDiscountIds(product)) || applicableCards.find(function (discount) {
|
|
1127
|
+
return discount.isScan && discount.isSelected;
|
|
1128
|
+
});
|
|
1129
|
+
if (preferredCard) occupiedItems.set(flatItem._id, preferredCard.id);
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1046
1132
|
// 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
|
|
1047
1133
|
selectedOrderLevelDiscounts.forEach(function (discount) {
|
|
1048
1134
|
var limitedData = discount.limited_relation_product_data;
|
|
@@ -1072,7 +1158,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1072
1158
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
1073
1159
|
var applicableProducts = [];
|
|
1074
1160
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
1075
|
-
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price,
|
|
1161
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref13, _flatItem$original_pr;
|
|
1076
1162
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
1077
1163
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
1078
1164
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -1100,7 +1186,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1100
1186
|
|
|
1101
1187
|
// 对于主商品:使用 price
|
|
1102
1188
|
// 对于子商品:优先使用 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((
|
|
1189
|
+
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
1190
|
|
|
1105
1191
|
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
1106
1192
|
var productData = {
|
|
@@ -1132,21 +1218,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1132
1218
|
|
|
1133
1219
|
// 可用性和实际应用共用金额判断;零基础价商品可按策略抵扣收费 option。
|
|
1134
1220
|
var isDiscountCardPriceAvailable = function isDiscountCardPriceAvailable(flatItem, discount) {
|
|
1135
|
-
var _product$discount_lis2, _discount$
|
|
1221
|
+
var _product$discount_lis2, _discount$config4;
|
|
1136
1222
|
var product = flatItem.type === 'main' ? flatItem.product : flatItem.bundleItem;
|
|
1137
1223
|
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$
|
|
1224
|
+
var _item$discount2;
|
|
1225
|
+
return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === discount.id;
|
|
1140
1226
|
})) {
|
|
1141
1227
|
return true;
|
|
1142
1228
|
}
|
|
1143
|
-
if (flatItem.type !== 'main' || Number(flatItem.price) !== 0 || !['discount_card', 'product_discount_card'].includes(discount.tag || discount.type || '') || !((_discount$
|
|
1229
|
+
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
1230
|
return false;
|
|
1145
1231
|
}
|
|
1146
1232
|
return (product.options || []).reduce(function (total, option) {
|
|
1147
|
-
var
|
|
1148
|
-
var unitPrice = Number((
|
|
1149
|
-
var quantity = Number((
|
|
1233
|
+
var _ref14, _ref15, _ref16, _option$_original_pri, _ref17, _option$num;
|
|
1234
|
+
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);
|
|
1235
|
+
var quantity = Number((_ref17 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref17 !== void 0 ? _ref17 : 1);
|
|
1150
1236
|
if (!Number.isFinite(unitPrice) || !Number.isFinite(quantity) || quantity <= 0) {
|
|
1151
1237
|
return total;
|
|
1152
1238
|
}
|
|
@@ -1179,13 +1265,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1179
1265
|
};
|
|
1180
1266
|
originProduct = flatItem.originProduct;
|
|
1181
1267
|
}
|
|
1182
|
-
var isItemRewardProductDiscount =
|
|
1268
|
+
var isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1183
1269
|
addModeDiscount.forEach(function (discount) {
|
|
1184
|
-
var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$
|
|
1270
|
+
var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config5;
|
|
1185
1271
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
1186
1272
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
1187
1273
|
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 =
|
|
1274
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1189
1275
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1190
1276
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1191
1277
|
}, flatItem.originProduct, holders);
|
|
@@ -1203,7 +1289,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1203
1289
|
}));
|
|
1204
1290
|
|
|
1205
1291
|
// 套餐是否可用判断
|
|
1206
|
-
var isBundleAvailable =
|
|
1292
|
+
var isBundleAvailable = _this5.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1207
1293
|
if (isProductInScope && isBundleAvailable && !isItemRewardProductDiscount) {
|
|
1208
1294
|
var timeReasons = discountTimeReasons.get(discount.id) || [];
|
|
1209
1295
|
timeReasons.push(timeReason);
|
|
@@ -1212,10 +1298,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1212
1298
|
}
|
|
1213
1299
|
|
|
1214
1300
|
// 判断优惠券是否适用于该商品
|
|
1215
|
-
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$
|
|
1301
|
+
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
1302
|
var _discountApplicabilit, _discount$metadata4, _discount$metadata5, _discount$metadata6;
|
|
1217
1303
|
// 记录此优惠券适用的商品
|
|
1218
1304
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
1305
|
+
if (flatItem.type === 'main' && isPromotionDiscountCard(discount)) {
|
|
1306
|
+
var _promotionPolicy$onAp;
|
|
1307
|
+
promotionPolicy === null || promotionPolicy === void 0 || (_promotionPolicy$onAp = promotionPolicy.onApplicableCard) === null || _promotionPolicy$onAp === void 0 || _promotionPolicy$onAp.call(promotionPolicy, originProduct, discount);
|
|
1308
|
+
}
|
|
1219
1309
|
|
|
1220
1310
|
// 记录可抵扣的商品详情
|
|
1221
1311
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
@@ -1262,13 +1352,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1262
1352
|
};
|
|
1263
1353
|
var optionDiscountAmount = 0;
|
|
1264
1354
|
var discountedOptions = options.map(function (option) {
|
|
1265
|
-
var
|
|
1355
|
+
var _ref18, _ref19, _option$_original_pri2, _ref20, _option$num2, _rest$price, _option$_original_pri3;
|
|
1266
1356
|
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
1267
|
-
var rawUnit = (
|
|
1357
|
+
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
1358
|
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
1269
1359
|
if (baseUnitNum <= 0) return option;
|
|
1270
1360
|
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
1271
|
-
var optQty = Number((
|
|
1361
|
+
var optQty = Number((_ref20 = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : option.quantity) !== null && _ref20 !== void 0 ? _ref20 : 1);
|
|
1272
1362
|
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
1273
1363
|
var _original_add_price = option._original_add_price,
|
|
1274
1364
|
rest = _objectWithoutProperties(option, _excluded);
|
|
@@ -1302,9 +1392,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1302
1392
|
var getOptionTotal = function getOptionTotal(options) {
|
|
1303
1393
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
1304
1394
|
return options.reduce(function (sum, opt) {
|
|
1305
|
-
var
|
|
1306
|
-
var unit = Number((
|
|
1307
|
-
var n = Number((
|
|
1395
|
+
var _ref21, _opt$price, _ref22, _opt$num;
|
|
1396
|
+
var unit = Number((_ref21 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref21 !== void 0 ? _ref21 : 0);
|
|
1397
|
+
var n = Number((_ref22 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref22 !== void 0 ? _ref22 : 1);
|
|
1308
1398
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
1309
1399
|
}, 0);
|
|
1310
1400
|
};
|
|
@@ -1359,7 +1449,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1359
1449
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1360
1450
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1361
1451
|
var _product$discount_lis4;
|
|
1362
|
-
if (
|
|
1452
|
+
if (_this5.isItemRewardProductDiscount(product)) return false;
|
|
1453
|
+
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
1363
1454
|
// 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
|
|
1364
1455
|
var discountType = discount.tag || discount.type;
|
|
1365
1456
|
var currentOriginUid = getOriginProductUid(originProduct);
|
|
@@ -1370,9 +1461,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1370
1461
|
if (!discount.isSelected) return false;
|
|
1371
1462
|
}
|
|
1372
1463
|
if (['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '') && !isReapplyEditModeDiscountForProduct) {
|
|
1373
|
-
var _discount$
|
|
1464
|
+
var _discount$config6;
|
|
1374
1465
|
// 如果策略检查后没有config,说明不可用
|
|
1375
|
-
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$
|
|
1466
|
+
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config6 = discount.config) !== null && _discount$config6 !== void 0 && _discount$config6.isAvailable)) {
|
|
1376
1467
|
return false;
|
|
1377
1468
|
}
|
|
1378
1469
|
}
|
|
@@ -1394,8 +1485,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1394
1485
|
|
|
1395
1486
|
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
1396
1487
|
if (isFullCoveragePass(discount)) {
|
|
1397
|
-
var _discount$
|
|
1398
|
-
var maxUsagePerOrder = (_discount$
|
|
1488
|
+
var _discount$config7;
|
|
1489
|
+
var maxUsagePerOrder = (_discount$config7 = discount.config) === null || _discount$config7 === void 0 ? void 0 : _discount$config7.maxUsagePerOrder;
|
|
1399
1490
|
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1400
1491
|
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
1401
1492
|
if (currentUsedCount >= maxUsagePerOrder) {
|
|
@@ -1407,7 +1498,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1407
1498
|
|
|
1408
1499
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
1409
1500
|
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 =
|
|
1501
|
+
var isHolderMatch = _this5.checkHolderMatch(discount, {
|
|
1411
1502
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1412
1503
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1413
1504
|
}, flatItem.originProduct, holders);
|
|
@@ -1425,13 +1516,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1425
1516
|
return false;
|
|
1426
1517
|
}
|
|
1427
1518
|
// 检查 package_sub_item_usage_rules
|
|
1428
|
-
if (!
|
|
1519
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1429
1520
|
return false;
|
|
1430
1521
|
}
|
|
1431
1522
|
return true;
|
|
1432
1523
|
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1433
1524
|
// 检查 package_sub_item_usage_rules
|
|
1434
|
-
if (!
|
|
1525
|
+
if (!_this5.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1435
1526
|
return false;
|
|
1436
1527
|
}
|
|
1437
1528
|
return true;
|
|
@@ -1441,27 +1532,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1441
1532
|
|
|
1442
1533
|
// 识别用户本次显式选择的卡券,供次卡和折扣卡各自的优先级使用。
|
|
1443
1534
|
// 目标仍必须在当前商品的 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;
|
|
1535
|
+
var explicitlySelectedDiscount = findExplicitlySelectedDiscount(applicableDiscounts);
|
|
1448
1536
|
// 折扣卡会复用于整条商品行;商品券必须继续按单张拆分,不能复用该分支。
|
|
1449
1537
|
var explicitlySelectedDiscountCard = explicitlySelectedDiscount && !isFullCoveragePass(explicitlySelectedDiscount) ? explicitlySelectedDiscount : undefined;
|
|
1450
1538
|
|
|
1451
1539
|
// 商品数量等变化会触发无 discountId 的重算。只要当前行已应用的卡仍在
|
|
1452
1540
|
// 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
|
-
});
|
|
1541
|
+
var appliedWalletDiscountIds = getAppliedWalletDiscountIds(product);
|
|
1542
|
+
var appliedDiscountCard = findAppliedDiscountCard(applicableDiscounts, appliedWalletDiscountIds);
|
|
1465
1543
|
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
1544
|
return isEntitlementPass(discount) && discount.isSelected === true && appliedWalletDiscountIds.has(String(discount.id));
|
|
1467
1545
|
});
|
|
@@ -1499,7 +1577,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1499
1577
|
}) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
|
|
1500
1578
|
return item.type === 'product';
|
|
1501
1579
|
})));
|
|
1502
|
-
isItemRewardProductDiscount =
|
|
1580
|
+
isItemRewardProductDiscount = _this5.isItemRewardProductDiscount(product);
|
|
1503
1581
|
if (product.inPromotion && !isItemRewardProductDiscount) {
|
|
1504
1582
|
isManualDiscount = false;
|
|
1505
1583
|
}
|
|
@@ -1582,7 +1660,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1582
1660
|
// 主商品:保持原有逻辑,还原 option 价格
|
|
1583
1661
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
1584
1662
|
if (product.isClient) {
|
|
1585
|
-
processedProductsMap.set(product._id, [
|
|
1663
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1586
1664
|
origin_total: getProductOriginTotalPrice({
|
|
1587
1665
|
product: {
|
|
1588
1666
|
original_price: product.original_price
|
|
@@ -1602,7 +1680,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1602
1680
|
price: product.price,
|
|
1603
1681
|
options: restoredOptions
|
|
1604
1682
|
}), {}, {
|
|
1605
|
-
discount_list: isManualDiscount ?
|
|
1683
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1606
1684
|
}))]);
|
|
1607
1685
|
} else {
|
|
1608
1686
|
var _ref25, _product$_promotion$f, _product12, _product$origin_total;
|
|
@@ -1615,7 +1693,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1615
1693
|
total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
|
|
1616
1694
|
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
1695
|
}
|
|
1618
|
-
processedProductsMap.set(product._id, [
|
|
1696
|
+
processedProductsMap.set(product._id, [_this5.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
|
|
1619
1697
|
price: product.price,
|
|
1620
1698
|
main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
|
|
1621
1699
|
}, isItemRewardProductDiscount ? {
|
|
@@ -1627,14 +1705,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1627
1705
|
main_product_selling_price: main_product_selling_price,
|
|
1628
1706
|
options: restoredOptions
|
|
1629
1707
|
}), {}, {
|
|
1630
|
-
discount_list: isManualDiscount ?
|
|
1708
|
+
discount_list: isManualDiscount ? _this5.resolveDiscountListForManualOverride(product.discount_list) : _this5.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1631
1709
|
}))]);
|
|
1632
1710
|
}
|
|
1633
1711
|
} else {
|
|
1634
1712
|
var _flatItem$bundleItem8, _flatItem$bundleItem9, _flatItem$bundleItem$;
|
|
1635
1713
|
// bundle子商品:保存到扁平化Map
|
|
1636
1714
|
processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1637
|
-
discount_list: isManualDiscount ?
|
|
1715
|
+
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
1716
|
price: flatItem.bundleItem.price,
|
|
1639
1717
|
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
1718
|
processed: true
|
|
@@ -1707,7 +1785,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1707
1785
|
var _product$total2;
|
|
1708
1786
|
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1709
1787
|
}
|
|
1710
|
-
arr.push(
|
|
1788
|
+
arr.push(_this5.hooks.setProduct(originProduct, _objectSpread({
|
|
1711
1789
|
// 商品券只替换被拆出的 splitCount 件。余量行原本仍有效的折扣卡
|
|
1712
1790
|
// 不能随全额抵扣卡拆分一起清除;已取消或已失效的折扣不会进入此列表。
|
|
1713
1791
|
discount_list: remainderDiscountList,
|
|
@@ -1741,7 +1819,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1741
1819
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1742
1820
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
1743
1821
|
// 如果当前 product 有 discount_list,则先从 origin_total 拿
|
|
1744
|
-
if (
|
|
1822
|
+
if (_this5.filterDiscountListByType(product.discount_list, 'promotion').length && product.origin_total) {
|
|
1745
1823
|
productOriginTotal = product.origin_total;
|
|
1746
1824
|
}
|
|
1747
1825
|
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
@@ -1763,14 +1841,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1763
1841
|
var discountedOptions = product.options;
|
|
1764
1842
|
var optionDiscountAmount = 0;
|
|
1765
1843
|
var reapplyDiscountPercent = void 0;
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1844
|
+
var bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount);
|
|
1845
|
+
if (isOrderLevel && (productAllocation || bookingDiscountPercent === undefined)) {
|
|
1846
|
+
var _productAllocation$di;
|
|
1847
|
+
// 整单卡只能使用分摊结果,缺少分摊时不能回退为每件扣减整单额度。
|
|
1848
|
+
amount = (_productAllocation$di = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.discountAmount) !== null && _productAllocation$di !== void 0 ? _productAllocation$di : 0;
|
|
1849
|
+
productDiscountDifference = productAllocation === null || productAllocation === void 0 ? void 0 : productAllocation.difference;
|
|
1770
1850
|
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1771
|
-
} else if (
|
|
1851
|
+
} else if (bookingDiscountPercent !== undefined) {
|
|
1772
1852
|
// Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
|
|
1773
|
-
var percent =
|
|
1853
|
+
var percent = bookingDiscountPercent;
|
|
1774
1854
|
reapplyDiscountPercent = new Decimal(percent).toFixed(2);
|
|
1775
1855
|
mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1776
1856
|
amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
|
|
@@ -1830,7 +1910,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1830
1910
|
// 记录应用了优惠券的商品
|
|
1831
1911
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1832
1912
|
if (product.isClient) {
|
|
1833
|
-
arr.push(
|
|
1913
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1834
1914
|
discount_list: [discountDetail],
|
|
1835
1915
|
// 全额抵扣卡:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1836
1916
|
price: isFullCoverage ? mainProductSellingPrice : product.price,
|
|
@@ -1848,8 +1928,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1848
1928
|
options: discountedOptions
|
|
1849
1929
|
}));
|
|
1850
1930
|
} else {
|
|
1851
|
-
arr.push(
|
|
1852
|
-
discount_list:
|
|
1931
|
+
arr.push(_this5.hooks.setProduct(originProduct, {
|
|
1932
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1853
1933
|
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1854
1934
|
price: isFullCoverage ? 0 : product.price,
|
|
1855
1935
|
quantity: isNeedSplit ? appliedUseCount : product.quantity,
|
|
@@ -1938,7 +2018,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1938
2018
|
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1939
2019
|
num: normalNum,
|
|
1940
2020
|
quantity: normalNum,
|
|
1941
|
-
discount_list:
|
|
2021
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1942
2022
|
processed: true
|
|
1943
2023
|
}));
|
|
1944
2024
|
}
|
|
@@ -1962,15 +2042,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1962
2042
|
var fixedAmountPerItem;
|
|
1963
2043
|
var _productDiscountDifference;
|
|
1964
2044
|
var _reapplyDiscountPercent;
|
|
1965
|
-
|
|
2045
|
+
var _bookingDiscountPercent = resolveReapplyBookingDiscountPercent(originProduct, _selectedDiscount3);
|
|
2046
|
+
if (_isOrderLevel && (_productAllocation || _bookingDiscountPercent === undefined)) {
|
|
2047
|
+
var _productAllocation$di2;
|
|
1966
2048
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1967
|
-
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1968
|
-
_productDiscountDifference = _productAllocation.difference;
|
|
2049
|
+
fixedAmountPerItem = (_productAllocation$di2 = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.discountAmount) !== null && _productAllocation$di2 !== void 0 ? _productAllocation$di2 : 0;
|
|
2050
|
+
_productDiscountDifference = _productAllocation === null || _productAllocation === void 0 ? void 0 : _productAllocation.difference;
|
|
1969
2051
|
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1970
|
-
} else if (
|
|
2052
|
+
} else if (_bookingDiscountPercent !== undefined) {
|
|
1971
2053
|
// hydrate 后 par_value 可能是余额/原值(例如 3500),百分比口径以
|
|
1972
2054
|
// 后端折扣快照 discount.percent 为准,与主商品重套逻辑保持一致。
|
|
1973
|
-
var _percent =
|
|
2055
|
+
var _percent = _bookingDiscountPercent;
|
|
1974
2056
|
_reapplyDiscountPercent = new Decimal(_percent).toFixed(2);
|
|
1975
2057
|
targetProductTotal = new Decimal(_productOriginTotal).mul(new Decimal(100).minus(_percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1976
2058
|
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
@@ -2017,7 +2099,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2017
2099
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
2018
2100
|
total: targetProductTotal,
|
|
2019
2101
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
2020
|
-
discount_list:
|
|
2102
|
+
discount_list: _this5.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
2021
2103
|
processed: true
|
|
2022
2104
|
}));
|
|
2023
2105
|
}
|
|
@@ -2029,7 +2111,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2029
2111
|
var reconstructProductsWithBundle = function reconstructProductsWithBundle(processedProductsMap, processedFlatItemsMap, originalProductList) {
|
|
2030
2112
|
var result = [];
|
|
2031
2113
|
originalProductList.forEach(function (originProduct) {
|
|
2032
|
-
var product =
|
|
2114
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2033
2115
|
|
|
2034
2116
|
// 获取主商品处理结果
|
|
2035
2117
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
@@ -2038,8 +2120,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2038
2120
|
var getDefaultProduct = function getDefaultProduct() {
|
|
2039
2121
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
2040
2122
|
if (product.isClient) {
|
|
2041
|
-
return
|
|
2042
|
-
discount_list:
|
|
2123
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2124
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2043
2125
|
price: product.price,
|
|
2044
2126
|
origin_total: getProductOriginTotalPrice({
|
|
2045
2127
|
product: {
|
|
@@ -2060,8 +2142,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2060
2142
|
options: restoredOptions
|
|
2061
2143
|
});
|
|
2062
2144
|
} else {
|
|
2063
|
-
return
|
|
2064
|
-
discount_list:
|
|
2145
|
+
return _this5.hooks.setProduct(originProduct, {
|
|
2146
|
+
discount_list: _this5.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
2065
2147
|
total: product.total,
|
|
2066
2148
|
origin_total: product.origin_total,
|
|
2067
2149
|
price: product.price,
|
|
@@ -2107,10 +2189,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2107
2189
|
}
|
|
2108
2190
|
|
|
2109
2191
|
// 🔥 2. 如果有子商品应用了商品券,且主商品数量大于1,需要拆分主商品
|
|
2110
|
-
var mainProductQuantity = mainProductArr[0] ?
|
|
2192
|
+
var mainProductQuantity = mainProductArr[0] ? _this5.hooks.getProduct(mainProductArr[0]).quantity : 1;
|
|
2111
2193
|
if (hasFullCoveragePassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
|
|
2112
2194
|
var mainProduct = mainProductArr[0];
|
|
2113
|
-
var mainProductData =
|
|
2195
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2114
2196
|
|
|
2115
2197
|
// 🔥 方案:拆分成2个主商品
|
|
2116
2198
|
// 1. 一个主商品(qty=1)包含拆分后的bundle
|
|
@@ -2225,7 +2307,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2225
2307
|
}
|
|
2226
2308
|
|
|
2227
2309
|
// 添加第一个主商品:qty=1,包含拆分后的bundle
|
|
2228
|
-
result.push(
|
|
2310
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2229
2311
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_discount"),
|
|
2230
2312
|
quantity: 1,
|
|
2231
2313
|
discount_list: updatedMainDiscountList,
|
|
@@ -2297,7 +2379,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2297
2379
|
newOriginTotalOriginal = new Decimal(newOriginTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2298
2380
|
|
|
2299
2381
|
// 添加第二个主商品:qty=原quantity-1,包含原始bundle
|
|
2300
|
-
result.push(
|
|
2382
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2301
2383
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_normal"),
|
|
2302
2384
|
quantity: mainProductQuantity - 1,
|
|
2303
2385
|
discount_list: updatedMainDiscountListOriginal,
|
|
@@ -2310,7 +2392,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2310
2392
|
// 🔥 没有子商品被拆分,使用原有逻辑
|
|
2311
2393
|
mainProductArr.forEach(function (mainProduct) {
|
|
2312
2394
|
var _ref27, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
|
|
2313
|
-
var mainProductData =
|
|
2395
|
+
var mainProductData = _this5.hooks.getProduct(mainProduct);
|
|
2314
2396
|
|
|
2315
2397
|
// 重组bundle
|
|
2316
2398
|
var newBundle = [];
|
|
@@ -2397,7 +2479,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2397
2479
|
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2398
2480
|
|
|
2399
2481
|
// 生成最终的主商品
|
|
2400
|
-
result.push(
|
|
2482
|
+
result.push(_this5.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2401
2483
|
bundle: newBundle,
|
|
2402
2484
|
total: newTotal,
|
|
2403
2485
|
origin_total: newOriginTotal
|
|
@@ -2514,7 +2596,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2514
2596
|
});
|
|
2515
2597
|
};
|
|
2516
2598
|
var getProductDiscountDetails = function getProductDiscountDetails(originProduct) {
|
|
2517
|
-
var product =
|
|
2599
|
+
var product = _this5.hooks.getProduct(originProduct);
|
|
2518
2600
|
return [].concat(_toConsumableArray(product.discount_list || []), _toConsumableArray((product.bundle || []).flatMap(function (bundle) {
|
|
2519
2601
|
return bundle.discount_list || [];
|
|
2520
2602
|
})));
|