@pisell/pisellos 2.3.165 → 2.3.166
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.
|
@@ -269,6 +269,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
269
269
|
var productResults = this.evaluateProducts(input);
|
|
270
270
|
|
|
271
271
|
// 2. 收集所有适用的促销(去重)
|
|
272
|
+
// strategyId is metadata and is not guaranteed to be unique. Use the actual
|
|
273
|
+
// configuration as the key so one strategy cannot overwrite another strategy's
|
|
274
|
+
// label/action when their IDs happen to be the same.
|
|
272
275
|
var promotionMap = new Map();
|
|
273
276
|
var _iterator3 = _createForOfIteratorHelper(productResults),
|
|
274
277
|
_step3;
|
|
@@ -280,7 +283,7 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
280
283
|
try {
|
|
281
284
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
282
285
|
var promo = _step4.value;
|
|
283
|
-
var existing = promotionMap.get(promo.
|
|
286
|
+
var existing = promotionMap.get(promo.strategyConfig);
|
|
284
287
|
var product = productResult.product;
|
|
285
288
|
|
|
286
289
|
// 计算促销数量:如果是 bundle 子商品匹配,数量 = 主商品数量 × 子商品数量
|
|
@@ -303,7 +306,7 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
303
306
|
// 新促销
|
|
304
307
|
var productMatchedBundleIndexMap = new Map();
|
|
305
308
|
productMatchedBundleIndexMap.set(product.id, promo.matchedBundleIndex);
|
|
306
|
-
promotionMap.set(promo.
|
|
309
|
+
promotionMap.set(promo.strategyConfig, _objectSpread(_objectSpread({}, promo), {}, {
|
|
307
310
|
applicableProducts: [product],
|
|
308
311
|
totalQuantity: promoQuantity,
|
|
309
312
|
totalAmount: product.price * product.quantity,
|
|
@@ -367,7 +370,7 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
367
370
|
var cartResult = this.evaluateCart(input);
|
|
368
371
|
|
|
369
372
|
// 2. 按 action priority 排序促销组(从 strategyConfig 获取 priority)
|
|
370
|
-
var sortedGroups = this.sortPromotionGroupsByPriority(cartResult.promotionGroups
|
|
373
|
+
var sortedGroups = this.sortPromotionGroupsByPriority(cartResult.promotionGroups);
|
|
371
374
|
|
|
372
375
|
// 3. 追踪已处理的商品(避免重复处理)
|
|
373
376
|
// key: `${product_id}_${product_variant_id}`
|
|
@@ -664,30 +667,12 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
664
667
|
*/
|
|
665
668
|
}, {
|
|
666
669
|
key: "sortPromotionGroupsByPriority",
|
|
667
|
-
value: function sortPromotionGroupsByPriority(groups
|
|
668
|
-
//
|
|
669
|
-
var priorityMap = new Map();
|
|
670
|
-
var _iterator9 = _createForOfIteratorHelper(promotions),
|
|
671
|
-
_step9;
|
|
672
|
-
try {
|
|
673
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
674
|
-
var _promo$strategyConfig2, _actions$0$priority, _actions$;
|
|
675
|
-
var promo = _step9.value;
|
|
676
|
-
var actions = ((_promo$strategyConfig2 = promo.strategyConfig) === null || _promo$strategyConfig2 === void 0 ? void 0 : _promo$strategyConfig2.actions) || [];
|
|
677
|
-
var priority = (_actions$0$priority = (_actions$ = actions[0]) === null || _actions$ === void 0 ? void 0 : _actions$.priority) !== null && _actions$0$priority !== void 0 ? _actions$0$priority : 999;
|
|
678
|
-
priorityMap.set(promo.strategyId, priority);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// 按优先级排序(数值越小优先级越高)
|
|
682
|
-
} catch (err) {
|
|
683
|
-
_iterator9.e(err);
|
|
684
|
-
} finally {
|
|
685
|
-
_iterator9.f();
|
|
686
|
-
}
|
|
670
|
+
value: function sortPromotionGroupsByPriority(groups) {
|
|
671
|
+
// 按优先级排序(数值越小优先级越高)
|
|
687
672
|
return _toConsumableArray(groups).sort(function (a, b) {
|
|
688
|
-
var
|
|
689
|
-
var priorityA = (
|
|
690
|
-
var priorityB = (
|
|
673
|
+
var _a$strategyConfig$act, _a$strategyConfig, _b$strategyConfig$act, _b$strategyConfig;
|
|
674
|
+
var priorityA = (_a$strategyConfig$act = (_a$strategyConfig = a.strategyConfig) === null || _a$strategyConfig === void 0 || (_a$strategyConfig = _a$strategyConfig.actions) === null || _a$strategyConfig === void 0 || (_a$strategyConfig = _a$strategyConfig[0]) === null || _a$strategyConfig === void 0 ? void 0 : _a$strategyConfig.priority) !== null && _a$strategyConfig$act !== void 0 ? _a$strategyConfig$act : 999;
|
|
675
|
+
var priorityB = (_b$strategyConfig$act = (_b$strategyConfig = b.strategyConfig) === null || _b$strategyConfig === void 0 || (_b$strategyConfig = _b$strategyConfig.actions) === null || _b$strategyConfig === void 0 || (_b$strategyConfig = _b$strategyConfig[0]) === null || _b$strategyConfig === void 0 ? void 0 : _b$strategyConfig.priority) !== null && _b$strategyConfig$act !== void 0 ? _b$strategyConfig$act : 999;
|
|
691
676
|
return priorityA - priorityB;
|
|
692
677
|
});
|
|
693
678
|
}
|
|
@@ -720,11 +705,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
720
705
|
// 1. 展开所有商品为单件列表(排除已处理的数量)
|
|
721
706
|
// 每个单件记录来自哪个原商品(通过 product.id)
|
|
722
707
|
var unitProducts = [];
|
|
723
|
-
var
|
|
724
|
-
|
|
708
|
+
var _iterator9 = _createForOfIteratorHelper(groupProducts),
|
|
709
|
+
_step9;
|
|
725
710
|
try {
|
|
726
|
-
for (
|
|
727
|
-
var product =
|
|
711
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
712
|
+
var product = _step9.value;
|
|
728
713
|
var key = this.getProductKey(product);
|
|
729
714
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
730
715
|
var availableQty = product.quantity - processedQty;
|
|
@@ -741,9 +726,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
741
726
|
}
|
|
742
727
|
}
|
|
743
728
|
} catch (err) {
|
|
744
|
-
|
|
729
|
+
_iterator9.e(err);
|
|
745
730
|
} finally {
|
|
746
|
-
|
|
731
|
+
_iterator9.f();
|
|
747
732
|
}
|
|
748
733
|
if (unitProducts.length === 0) {
|
|
749
734
|
return {
|
|
@@ -775,25 +760,25 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
775
760
|
|
|
776
761
|
// 5. 按原商品 id 统计参与促销和不参与的数量
|
|
777
762
|
var promotionQtyByProductId = new Map();
|
|
778
|
-
var
|
|
779
|
-
|
|
763
|
+
var _iterator10 = _createForOfIteratorHelper(inPromotionUnits),
|
|
764
|
+
_step10;
|
|
780
765
|
try {
|
|
781
|
-
for (
|
|
782
|
-
var _unit =
|
|
766
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
767
|
+
var _unit = _step10.value;
|
|
783
768
|
var id = _unit.productId;
|
|
784
769
|
promotionQtyByProductId.set(id, (promotionQtyByProductId.get(id) || 0) + 1);
|
|
785
770
|
}
|
|
786
771
|
} catch (err) {
|
|
787
|
-
|
|
772
|
+
_iterator10.e(err);
|
|
788
773
|
} finally {
|
|
789
|
-
|
|
774
|
+
_iterator10.f();
|
|
790
775
|
}
|
|
791
776
|
var remainingQtyByProductId = new Map();
|
|
792
|
-
var
|
|
793
|
-
|
|
777
|
+
var _iterator11 = _createForOfIteratorHelper(notInPromotionUnits),
|
|
778
|
+
_step11;
|
|
794
779
|
try {
|
|
795
|
-
for (
|
|
796
|
-
var _unit2 =
|
|
780
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
781
|
+
var _unit2 = _step11.value;
|
|
797
782
|
var _id = _unit2.productId;
|
|
798
783
|
remainingQtyByProductId.set(_id, (remainingQtyByProductId.get(_id) || 0) + 1);
|
|
799
784
|
}
|
|
@@ -802,9 +787,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
802
787
|
// 按组内原价比例均摊
|
|
803
788
|
// 记录每个原商品的均摊价格累加(用于后续聚合)
|
|
804
789
|
} catch (err) {
|
|
805
|
-
|
|
790
|
+
_iterator11.e(err);
|
|
806
791
|
} finally {
|
|
807
|
-
|
|
792
|
+
_iterator11.f();
|
|
808
793
|
}
|
|
809
794
|
var allocatedPricesByProductId = new Map();
|
|
810
795
|
for (var g = 0; g < groupCount; g++) {
|
|
@@ -836,11 +821,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
836
821
|
}
|
|
837
822
|
|
|
838
823
|
// 7. 为每个原商品生成结果
|
|
839
|
-
var
|
|
840
|
-
|
|
824
|
+
var _iterator12 = _createForOfIteratorHelper(groupProducts),
|
|
825
|
+
_step12;
|
|
841
826
|
try {
|
|
842
|
-
for (
|
|
843
|
-
var _product =
|
|
827
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
828
|
+
var _product = _step12.value;
|
|
844
829
|
var _key = this.getProductKey(_product);
|
|
845
830
|
var _processedQty = processedQuantityMap.get(_key) || 0;
|
|
846
831
|
var _availableQty = _product.quantity - _processedQty;
|
|
@@ -928,9 +913,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
928
913
|
|
|
929
914
|
// 8. 尾差调整:确保促销商品的 finalPrice × quantity 之和精确等于 groupPrice × groupCount
|
|
930
915
|
} catch (err) {
|
|
931
|
-
|
|
916
|
+
_iterator12.e(err);
|
|
932
917
|
} finally {
|
|
933
|
-
|
|
918
|
+
_iterator12.f();
|
|
934
919
|
}
|
|
935
920
|
if (groupCount > 0) {
|
|
936
921
|
var expectedPromoTotal = new Decimal(groupPrice).mul(groupCount);
|
|
@@ -938,17 +923,17 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
938
923
|
return p.inPromotion;
|
|
939
924
|
});
|
|
940
925
|
var actualPromoTotal = new Decimal(0);
|
|
941
|
-
var
|
|
942
|
-
|
|
926
|
+
var _iterator13 = _createForOfIteratorHelper(promoItems),
|
|
927
|
+
_step13;
|
|
943
928
|
try {
|
|
944
|
-
for (
|
|
945
|
-
var _p =
|
|
929
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
930
|
+
var _p = _step13.value;
|
|
946
931
|
actualPromoTotal = actualPromoTotal.plus(new Decimal(_p.finalPrice).mul(_p.quantity));
|
|
947
932
|
}
|
|
948
933
|
} catch (err) {
|
|
949
|
-
|
|
934
|
+
_iterator13.e(err);
|
|
950
935
|
} finally {
|
|
951
|
-
|
|
936
|
+
_iterator13.f();
|
|
952
937
|
}
|
|
953
938
|
var roundingDiff = actualPromoTotal.minus(expectedPromoTotal);
|
|
954
939
|
if (!roundingDiff.eq(0)) {
|
|
@@ -979,17 +964,17 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
979
964
|
|
|
980
965
|
// 重新计算 finalAmount
|
|
981
966
|
finalAmount = new Decimal(0);
|
|
982
|
-
var
|
|
983
|
-
|
|
967
|
+
var _iterator14 = _createForOfIteratorHelper(result),
|
|
968
|
+
_step14;
|
|
984
969
|
try {
|
|
985
|
-
for (
|
|
986
|
-
var p =
|
|
970
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
971
|
+
var p = _step14.value;
|
|
987
972
|
finalAmount = finalAmount.plus(new Decimal(p.finalPrice).mul(p.quantity));
|
|
988
973
|
}
|
|
989
974
|
} catch (err) {
|
|
990
|
-
|
|
975
|
+
_iterator14.e(err);
|
|
991
976
|
} finally {
|
|
992
|
-
|
|
977
|
+
_iterator14.f();
|
|
993
978
|
}
|
|
994
979
|
}
|
|
995
980
|
}
|
|
@@ -1027,11 +1012,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1027
1012
|
// 对于 bundle 子商品匹配,促销数量 = 主商品数量 × bundle子商品数量
|
|
1028
1013
|
var totalPromoQty = 0;
|
|
1029
1014
|
var productInfoMap = new Map();
|
|
1030
|
-
var
|
|
1031
|
-
|
|
1015
|
+
var _iterator15 = _createForOfIteratorHelper(groupProducts),
|
|
1016
|
+
_step15;
|
|
1032
1017
|
try {
|
|
1033
|
-
for (
|
|
1034
|
-
var product =
|
|
1018
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
1019
|
+
var product = _step15.value;
|
|
1035
1020
|
var key = this.getProductKey(product);
|
|
1036
1021
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
1037
1022
|
var availableQty = product.quantity - processedQty;
|
|
@@ -1057,18 +1042,18 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1057
1042
|
|
|
1058
1043
|
// 2. 判断是否满足促销条件
|
|
1059
1044
|
} catch (err) {
|
|
1060
|
-
|
|
1045
|
+
_iterator15.e(err);
|
|
1061
1046
|
} finally {
|
|
1062
|
-
|
|
1047
|
+
_iterator15.f();
|
|
1063
1048
|
}
|
|
1064
1049
|
var isFulfilled = totalPromoQty >= buyQuantity;
|
|
1065
1050
|
|
|
1066
1051
|
// 3. 生成商品结果(第二次遍历)
|
|
1067
|
-
var
|
|
1068
|
-
|
|
1052
|
+
var _iterator16 = _createForOfIteratorHelper(groupProducts),
|
|
1053
|
+
_step16;
|
|
1069
1054
|
try {
|
|
1070
|
-
for (
|
|
1071
|
-
var _product2 =
|
|
1055
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
1056
|
+
var _product2 = _step16.value;
|
|
1072
1057
|
var _key2 = this.getProductKey(_product2);
|
|
1073
1058
|
var info = productInfoMap.get(_key2);
|
|
1074
1059
|
if (!info || info.availableQty <= 0) continue;
|
|
@@ -1096,9 +1081,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1096
1081
|
|
|
1097
1082
|
// 4. 计算赠品数量(使用促销数量)
|
|
1098
1083
|
} catch (err) {
|
|
1099
|
-
|
|
1084
|
+
_iterator16.e(err);
|
|
1100
1085
|
} finally {
|
|
1101
|
-
|
|
1086
|
+
_iterator16.f();
|
|
1102
1087
|
}
|
|
1103
1088
|
var giftCount = 0;
|
|
1104
1089
|
if (isFulfilled) {
|
|
@@ -1173,11 +1158,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1173
1158
|
return b.originalPrice.minus(a.originalPrice).toNumber();
|
|
1174
1159
|
}).slice(0, rewardLimit);
|
|
1175
1160
|
var selectedByProductId = new Map();
|
|
1176
|
-
var
|
|
1177
|
-
|
|
1161
|
+
var _iterator17 = _createForOfIteratorHelper(selectedUnits),
|
|
1162
|
+
_step17;
|
|
1178
1163
|
try {
|
|
1179
|
-
for (
|
|
1180
|
-
var unit =
|
|
1164
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1165
|
+
var unit = _step17.value;
|
|
1181
1166
|
var existing = selectedByProductId.get(unit.product.id);
|
|
1182
1167
|
if (existing) {
|
|
1183
1168
|
existing.quantity += 1;
|
|
@@ -1190,18 +1175,18 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1190
1175
|
}
|
|
1191
1176
|
}
|
|
1192
1177
|
} catch (err) {
|
|
1193
|
-
|
|
1178
|
+
_iterator17.e(err);
|
|
1194
1179
|
} finally {
|
|
1195
|
-
|
|
1180
|
+
_iterator17.f();
|
|
1196
1181
|
}
|
|
1197
1182
|
var result = [];
|
|
1198
1183
|
var originalAmount = new Decimal(0);
|
|
1199
1184
|
var finalAmount = new Decimal(0);
|
|
1200
|
-
var
|
|
1201
|
-
|
|
1185
|
+
var _iterator18 = _createForOfIteratorHelper(targetProducts),
|
|
1186
|
+
_step18;
|
|
1202
1187
|
try {
|
|
1203
|
-
for (
|
|
1204
|
-
var product =
|
|
1188
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
1189
|
+
var product = _step18.value;
|
|
1205
1190
|
var key = this.getProductKey(product);
|
|
1206
1191
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
1207
1192
|
var availableQty = product.quantity - processedQty;
|
|
@@ -1240,9 +1225,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1240
1225
|
processedQuantityMap.set(key, processedQty + availableQty);
|
|
1241
1226
|
}
|
|
1242
1227
|
} catch (err) {
|
|
1243
|
-
|
|
1228
|
+
_iterator18.e(err);
|
|
1244
1229
|
} finally {
|
|
1245
|
-
|
|
1230
|
+
_iterator18.f();
|
|
1246
1231
|
}
|
|
1247
1232
|
return {
|
|
1248
1233
|
products: result,
|
|
@@ -1260,11 +1245,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1260
1245
|
key: "getAvailablePromotionQuantity",
|
|
1261
1246
|
value: function getAvailablePromotionQuantity(products, processedQuantityMap, matchedBundleIndexMap) {
|
|
1262
1247
|
var total = 0;
|
|
1263
|
-
var
|
|
1264
|
-
|
|
1248
|
+
var _iterator19 = _createForOfIteratorHelper(products),
|
|
1249
|
+
_step19;
|
|
1265
1250
|
try {
|
|
1266
|
-
for (
|
|
1267
|
-
var product =
|
|
1251
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
1252
|
+
var product = _step19.value;
|
|
1268
1253
|
var key = this.getProductKey(product);
|
|
1269
1254
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
1270
1255
|
var availableQty = product.quantity - processedQty;
|
|
@@ -1278,9 +1263,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1278
1263
|
}
|
|
1279
1264
|
}
|
|
1280
1265
|
} catch (err) {
|
|
1281
|
-
|
|
1266
|
+
_iterator19.e(err);
|
|
1282
1267
|
} finally {
|
|
1283
|
-
|
|
1268
|
+
_iterator19.f();
|
|
1284
1269
|
}
|
|
1285
1270
|
return total;
|
|
1286
1271
|
}
|
|
@@ -1288,11 +1273,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1288
1273
|
key: "buildItemRewardTargetUnits",
|
|
1289
1274
|
value: function buildItemRewardTargetUnits(products, processedQuantityMap, detail) {
|
|
1290
1275
|
var units = [];
|
|
1291
|
-
var
|
|
1292
|
-
|
|
1276
|
+
var _iterator20 = _createForOfIteratorHelper(products),
|
|
1277
|
+
_step20;
|
|
1293
1278
|
try {
|
|
1294
|
-
for (
|
|
1295
|
-
var product =
|
|
1279
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
1280
|
+
var product = _step20.value;
|
|
1296
1281
|
var key = this.getProductKey(product);
|
|
1297
1282
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
1298
1283
|
var availableQty = product.quantity - processedQty;
|
|
@@ -1311,9 +1296,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1311
1296
|
}
|
|
1312
1297
|
}
|
|
1313
1298
|
} catch (err) {
|
|
1314
|
-
|
|
1299
|
+
_iterator20.e(err);
|
|
1315
1300
|
} finally {
|
|
1316
|
-
|
|
1301
|
+
_iterator20.f();
|
|
1317
1302
|
}
|
|
1318
1303
|
return units;
|
|
1319
1304
|
}
|
|
@@ -1369,11 +1354,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1369
1354
|
key: "getRemainingProducts",
|
|
1370
1355
|
value: function getRemainingProducts(allProducts, processedQuantityMap) {
|
|
1371
1356
|
var result = [];
|
|
1372
|
-
var
|
|
1373
|
-
|
|
1357
|
+
var _iterator21 = _createForOfIteratorHelper(allProducts),
|
|
1358
|
+
_step21;
|
|
1374
1359
|
try {
|
|
1375
|
-
for (
|
|
1376
|
-
var product =
|
|
1360
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
1361
|
+
var product = _step21.value;
|
|
1377
1362
|
var key = this.getProductKey(product);
|
|
1378
1363
|
var processedQty = processedQuantityMap.get(key) || 0;
|
|
1379
1364
|
var remainingQty = product.quantity - processedQty;
|
|
@@ -1388,9 +1373,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
1388
1373
|
}
|
|
1389
1374
|
}
|
|
1390
1375
|
} catch (err) {
|
|
1391
|
-
|
|
1376
|
+
_iterator21.e(err);
|
|
1392
1377
|
} finally {
|
|
1393
|
-
|
|
1378
|
+
_iterator21.f();
|
|
1394
1379
|
}
|
|
1395
1380
|
return result;
|
|
1396
1381
|
}
|
|
@@ -227,10 +227,13 @@ class PromotionEvaluator {
|
|
|
227
227
|
const productResults = this.evaluateProducts(input);
|
|
228
228
|
|
|
229
229
|
// 2. 收集所有适用的促销(去重)
|
|
230
|
+
// strategyId is metadata and is not guaranteed to be unique. Use the actual
|
|
231
|
+
// configuration as the key so one strategy cannot overwrite another strategy's
|
|
232
|
+
// label/action when their IDs happen to be the same.
|
|
230
233
|
const promotionMap = new Map();
|
|
231
234
|
for (const productResult of productResults) {
|
|
232
235
|
for (const promo of productResult.applicablePromotions) {
|
|
233
|
-
const existing = promotionMap.get(promo.
|
|
236
|
+
const existing = promotionMap.get(promo.strategyConfig);
|
|
234
237
|
const product = productResult.product;
|
|
235
238
|
|
|
236
239
|
// 计算促销数量:如果是 bundle 子商品匹配,数量 = 主商品数量 × 子商品数量
|
|
@@ -253,7 +256,7 @@ class PromotionEvaluator {
|
|
|
253
256
|
// 新促销
|
|
254
257
|
const productMatchedBundleIndexMap = new Map();
|
|
255
258
|
productMatchedBundleIndexMap.set(product.id, promo.matchedBundleIndex);
|
|
256
|
-
promotionMap.set(promo.
|
|
259
|
+
promotionMap.set(promo.strategyConfig, {
|
|
257
260
|
...promo,
|
|
258
261
|
applicableProducts: [product],
|
|
259
262
|
totalQuantity: promoQuantity,
|
|
@@ -305,7 +308,7 @@ class PromotionEvaluator {
|
|
|
305
308
|
const cartResult = this.evaluateCart(input);
|
|
306
309
|
|
|
307
310
|
// 2. 按 action priority 排序促销组(从 strategyConfig 获取 priority)
|
|
308
|
-
const sortedGroups = this.sortPromotionGroupsByPriority(cartResult.promotionGroups
|
|
311
|
+
const sortedGroups = this.sortPromotionGroupsByPriority(cartResult.promotionGroups);
|
|
309
312
|
|
|
310
313
|
// 3. 追踪已处理的商品(避免重复处理)
|
|
311
314
|
// key: `${product_id}_${product_variant_id}`
|
|
@@ -544,19 +547,11 @@ class PromotionEvaluator {
|
|
|
544
547
|
* 按优先级排序促销组
|
|
545
548
|
* 优先级从 strategyConfig.actions[0].priority 获取,数值越小优先级越高
|
|
546
549
|
*/
|
|
547
|
-
sortPromotionGroupsByPriority(groups
|
|
548
|
-
// 创建策略ID到优先级的映射
|
|
549
|
-
const priorityMap = new Map();
|
|
550
|
-
for (const promo of promotions) {
|
|
551
|
-
const actions = promo.strategyConfig?.actions || [];
|
|
552
|
-
const priority = actions[0]?.priority ?? 999;
|
|
553
|
-
priorityMap.set(promo.strategyId, priority);
|
|
554
|
-
}
|
|
555
|
-
|
|
550
|
+
sortPromotionGroupsByPriority(groups) {
|
|
556
551
|
// 按优先级排序(数值越小优先级越高)
|
|
557
552
|
return [...groups].sort((a, b) => {
|
|
558
|
-
const priorityA =
|
|
559
|
-
const priorityB =
|
|
553
|
+
const priorityA = a.strategyConfig?.actions?.[0]?.priority ?? 999;
|
|
554
|
+
const priorityB = b.strategyConfig?.actions?.[0]?.priority ?? 999;
|
|
560
555
|
return priorityA - priorityB;
|
|
561
556
|
});
|
|
562
557
|
}
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _examples.BUY_X_GET_Y_FREE_STRATEGY;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _examples.ITEM_REWARD_STRATEGY;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "PromotionAdapter", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _adapter.PromotionAdapter;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "PromotionEvaluator", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _evaluator.PromotionEvaluator;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "default", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _adapter.default;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
var _evaluator = require("./evaluator");
|
|
43
|
-
var _adapter = _interopRequireWildcard(require("./adapter"));
|
|
44
|
-
var _examples = require("./examples");
|
|
45
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1
|
+
"use strict";
|