@pisell/pisellos 2.3.165 → 2.3.167
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 +89 -104
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/ScanOrder/index.js +36 -28
- package/dist/solution/ScanOrder/types.d.ts +3 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/ScanOrder/index.js +31 -18
- package/lib/solution/ScanOrder/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -595,7 +595,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
595
595
|
generateIdempotencyToken(): string;
|
|
596
596
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
597
597
|
createOrder(params: CommitOrderParams['query']): {
|
|
598
|
-
type: "
|
|
598
|
+
type: "virtual" | "appointment_booking";
|
|
599
599
|
platform: string;
|
|
600
600
|
sales_channel: string;
|
|
601
601
|
order_sales_channel: string;
|
|
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
328
328
|
date: string;
|
|
329
329
|
status: string;
|
|
330
330
|
week: string;
|
|
331
|
-
weekNum: 0 |
|
|
331
|
+
weekNum: 0 | 5 | 1 | 2 | 4 | 3 | 6;
|
|
332
332
|
}[]>;
|
|
333
333
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
334
334
|
private getScheduleDataByIds;
|
|
@@ -347,7 +347,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
347
347
|
count: number;
|
|
348
348
|
left: number;
|
|
349
349
|
summaryCount: number;
|
|
350
|
-
status: "
|
|
350
|
+
status: "sold_out" | "lots_of_space" | "filling_up_fast";
|
|
351
351
|
}[];
|
|
352
352
|
/**
|
|
353
353
|
* 找到多个资源的公共可用时间段
|
|
@@ -2168,7 +2168,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2168
2168
|
key: "applyPrefillByItemRule",
|
|
2169
2169
|
value: function () {
|
|
2170
2170
|
var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
2171
|
-
var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator6, _step6, _prefillItem$product_, _origin2, _origin3, _origin4, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasOriginChanged;
|
|
2171
|
+
var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator6, _step6, _prefillItem$product_, _origin2, _origin3, _origin4, prefillItem, productId, productVariantId, targetQuantity, sourceItem, sourceTitle, productTitle, displayFields, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasTitleChanged, hasOriginChanged;
|
|
2172
2172
|
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
2173
2173
|
while (1) switch (_context30.prev = _context30.next) {
|
|
2174
2174
|
case 0:
|
|
@@ -2218,7 +2218,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2218
2218
|
_iterator6.s();
|
|
2219
2219
|
case 22:
|
|
2220
2220
|
if ((_step6 = _iterator6.n()).done) {
|
|
2221
|
-
_context30.next =
|
|
2221
|
+
_context30.next = 51;
|
|
2222
2222
|
break;
|
|
2223
2223
|
}
|
|
2224
2224
|
prefillItem = _step6.value;
|
|
@@ -2229,25 +2229,32 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2229
2229
|
_context30.next = 29;
|
|
2230
2230
|
break;
|
|
2231
2231
|
}
|
|
2232
|
-
return _context30.abrupt("continue",
|
|
2232
|
+
return _context30.abrupt("continue", 49);
|
|
2233
2233
|
case 29:
|
|
2234
2234
|
if (!Number.isNaN(productVariantId)) {
|
|
2235
2235
|
_context30.next = 31;
|
|
2236
2236
|
break;
|
|
2237
2237
|
}
|
|
2238
|
-
return _context30.abrupt("continue",
|
|
2238
|
+
return _context30.abrupt("continue", 49);
|
|
2239
2239
|
case 31:
|
|
2240
2240
|
sourceItem = productSourceMap.get(buildProductKey(productId, productVariantId)) || productSourceMap.get(buildProductKey(productId, 0)) || null;
|
|
2241
|
+
sourceTitle = (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.product_title) || (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name);
|
|
2242
|
+
productTitle = typeof sourceTitle === 'string' ? {
|
|
2243
|
+
auto: sourceTitle
|
|
2244
|
+
} : sourceTitle; // 标准标题在归一化后补入,供购物车展示,并由 Order 在折扣重算时保留。
|
|
2245
|
+
displayFields = productTitle ? {
|
|
2246
|
+
product_title: productTitle
|
|
2247
|
+
} : {};
|
|
2241
2248
|
productIndex = getProductIdentityIndex(tempOrder.products, {
|
|
2242
2249
|
product_id: productId,
|
|
2243
2250
|
product_variant_id: productVariantId
|
|
2244
2251
|
});
|
|
2245
2252
|
if (!(productIndex === -1)) {
|
|
2246
|
-
_context30.next =
|
|
2253
|
+
_context30.next = 41;
|
|
2247
2254
|
break;
|
|
2248
2255
|
}
|
|
2249
2256
|
sellingPrice = toPriceString((_sourceItem$price = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _sourceItem$price !== void 0 ? _sourceItem$price : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.selling_price, '0.00');
|
|
2250
|
-
tempOrder.products.push(normalizeOrderProduct(_objectSpread(_objectSpread({}, sourceItem), {}, {
|
|
2257
|
+
tempOrder.products.push(_objectSpread(_objectSpread({}, normalizeOrderProduct(_objectSpread(_objectSpread({}, sourceItem), {}, {
|
|
2251
2258
|
product_id: productId,
|
|
2252
2259
|
product_variant_id: productVariantId,
|
|
2253
2260
|
num: targetQuantity,
|
|
@@ -2261,14 +2268,14 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2261
2268
|
item_rule_prefill: true,
|
|
2262
2269
|
item_rule_id: prefillItem.ruleId
|
|
2263
2270
|
})
|
|
2264
|
-
})));
|
|
2271
|
+
}))), displayFields));
|
|
2265
2272
|
hasChanges = true;
|
|
2266
|
-
return _context30.abrupt("continue",
|
|
2267
|
-
case
|
|
2273
|
+
return _context30.abrupt("continue", 49);
|
|
2274
|
+
case 41:
|
|
2268
2275
|
targetProduct = tempOrder.products[productIndex];
|
|
2269
2276
|
existedQuantity = toNonNegativeInt(targetProduct.num);
|
|
2270
2277
|
delta = targetQuantity - existedQuantity;
|
|
2271
|
-
nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), delta > 0 ? {
|
|
2278
|
+
nextProduct = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), displayFields), delta > 0 ? {
|
|
2272
2279
|
num: getSafeProductNum(existedQuantity + delta)
|
|
2273
2280
|
} : {}), {}, {
|
|
2274
2281
|
metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
|
|
@@ -2278,52 +2285,53 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2278
2285
|
_origin: sourceItem ? _objectSpread(_objectSpread({}, targetProduct._origin || {}), sourceItem) : targetProduct._origin
|
|
2279
2286
|
});
|
|
2280
2287
|
hasQuantityChanged = delta > 0;
|
|
2288
|
+
hasTitleChanged = Boolean(productTitle && JSON.stringify(targetProduct.product_title) !== JSON.stringify(productTitle));
|
|
2281
2289
|
hasOriginChanged = Boolean(sourceItem && (!targetProduct._origin || ((_origin2 = targetProduct._origin) === null || _origin2 === void 0 ? void 0 : _origin2.name) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name) || ((_origin3 = targetProduct._origin) === null || _origin3 === void 0 ? void 0 : _origin3.title) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || ((_origin4 = targetProduct._origin) === null || _origin4 === void 0 ? void 0 : _origin4.price) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price)));
|
|
2282
|
-
if (hasQuantityChanged || hasOriginChanged) {
|
|
2290
|
+
if (hasQuantityChanged || hasTitleChanged || hasOriginChanged) {
|
|
2283
2291
|
tempOrder.products[productIndex] = nextProduct;
|
|
2284
2292
|
hasChanges = true;
|
|
2285
2293
|
}
|
|
2286
|
-
case
|
|
2294
|
+
case 49:
|
|
2287
2295
|
_context30.next = 22;
|
|
2288
2296
|
break;
|
|
2289
|
-
case
|
|
2290
|
-
_context30.next =
|
|
2297
|
+
case 51:
|
|
2298
|
+
_context30.next = 56;
|
|
2291
2299
|
break;
|
|
2292
|
-
case
|
|
2293
|
-
_context30.prev =
|
|
2300
|
+
case 53:
|
|
2301
|
+
_context30.prev = 53;
|
|
2294
2302
|
_context30.t0 = _context30["catch"](20);
|
|
2295
2303
|
_iterator6.e(_context30.t0);
|
|
2296
|
-
case
|
|
2297
|
-
_context30.prev =
|
|
2304
|
+
case 56:
|
|
2305
|
+
_context30.prev = 56;
|
|
2298
2306
|
_iterator6.f();
|
|
2299
|
-
return _context30.finish(
|
|
2300
|
-
case
|
|
2307
|
+
return _context30.finish(56);
|
|
2308
|
+
case 59:
|
|
2301
2309
|
if (!hasChanges) {
|
|
2302
|
-
_context30.next =
|
|
2310
|
+
_context30.next = 64;
|
|
2303
2311
|
break;
|
|
2304
2312
|
}
|
|
2305
2313
|
// Prefill 属于 products CRUD 的一种形式:新增后让 Rules 重算,以支持自动应用可用优惠券。
|
|
2306
2314
|
this.store.order.applyDiscount();
|
|
2307
|
-
_context30.next =
|
|
2315
|
+
_context30.next = 63;
|
|
2308
2316
|
return this.store.order.recalculateSummary({
|
|
2309
2317
|
createIfMissing: true
|
|
2310
2318
|
});
|
|
2311
|
-
case
|
|
2319
|
+
case 63:
|
|
2312
2320
|
this.store.order.persistTempOrder();
|
|
2313
|
-
case
|
|
2314
|
-
_context30.next =
|
|
2321
|
+
case 64:
|
|
2322
|
+
_context30.next = 66;
|
|
2315
2323
|
return this.refreshItemRuleQuantityLimits();
|
|
2316
|
-
case
|
|
2324
|
+
case 66:
|
|
2317
2325
|
this.itemRulePrefillApplied = true;
|
|
2318
2326
|
this.logMethodSuccess('applyPrefillByItemRule', {
|
|
2319
2327
|
prefillCount: prefillItems.length,
|
|
2320
2328
|
hasChanges: hasChanges
|
|
2321
2329
|
});
|
|
2322
|
-
case
|
|
2330
|
+
case 68:
|
|
2323
2331
|
case "end":
|
|
2324
2332
|
return _context30.stop();
|
|
2325
2333
|
}
|
|
2326
|
-
}, _callee30, this, [[20,
|
|
2334
|
+
}, _callee30, this, [[20, 53, 56, 59]]);
|
|
2327
2335
|
}));
|
|
2328
2336
|
function applyPrefillByItemRule() {
|
|
2329
2337
|
return _applyPrefillByItemRule.apply(this, arguments);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, ScheduleModule } from '../../modules';
|
|
2
2
|
import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
|
|
3
|
+
import type { OrderLocalizedText } from '../../modules/Order/types';
|
|
3
4
|
/**
|
|
4
5
|
* 扫码下单流程 hook
|
|
5
6
|
*/
|
|
@@ -43,6 +44,8 @@ export interface ScanOrderProductSku {
|
|
|
43
44
|
}
|
|
44
45
|
export interface ScanOrderOrderProduct extends ScanOrderOrderProductIdentity {
|
|
45
46
|
order_detail_id: number | null;
|
|
47
|
+
/** 与 Order 一致的商品展示名称。 */
|
|
48
|
+
product_title?: OrderLocalizedText;
|
|
46
49
|
num: number;
|
|
47
50
|
/** Product 或当前 Variant 的生产编码 */
|
|
48
51
|
production_code?: string;
|
|
@@ -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";
|
|
@@ -595,7 +595,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
595
595
|
generateIdempotencyToken(): string;
|
|
596
596
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
597
597
|
createOrder(params: CommitOrderParams['query']): {
|
|
598
|
-
type: "
|
|
598
|
+
type: "virtual" | "appointment_booking";
|
|
599
599
|
platform: string;
|
|
600
600
|
sales_channel: string;
|
|
601
601
|
order_sales_channel: string;
|
|
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
328
328
|
date: string;
|
|
329
329
|
status: string;
|
|
330
330
|
week: string;
|
|
331
|
-
weekNum: 0 |
|
|
331
|
+
weekNum: 0 | 5 | 1 | 2 | 4 | 3 | 6;
|
|
332
332
|
}[]>;
|
|
333
333
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
334
334
|
private getScheduleDataByIds;
|
|
@@ -347,7 +347,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
347
347
|
count: number;
|
|
348
348
|
left: number;
|
|
349
349
|
summaryCount: number;
|
|
350
|
-
status: "
|
|
350
|
+
status: "sold_out" | "lots_of_space" | "filling_up_fast";
|
|
351
351
|
}[];
|
|
352
352
|
/**
|
|
353
353
|
* 找到多个资源的公共可用时间段
|
|
@@ -1299,29 +1299,40 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1299
1299
|
if (!Number.isFinite(productId) || targetQuantity <= 0) continue;
|
|
1300
1300
|
if (Number.isNaN(productVariantId)) continue;
|
|
1301
1301
|
const sourceItem = productSourceMap.get((0, _utils.buildProductKey)(productId, productVariantId)) || productSourceMap.get((0, _utils.buildProductKey)(productId, 0)) || null;
|
|
1302
|
+
const sourceTitle = sourceItem?.product_title || sourceItem?.title || sourceItem?.name;
|
|
1303
|
+
const productTitle = typeof sourceTitle === 'string' ? {
|
|
1304
|
+
auto: sourceTitle
|
|
1305
|
+
} : sourceTitle;
|
|
1306
|
+
// 标准标题在归一化后补入,供购物车展示,并由 Order 在折扣重算时保留。
|
|
1307
|
+
const displayFields = productTitle ? {
|
|
1308
|
+
product_title: productTitle
|
|
1309
|
+
} : {};
|
|
1302
1310
|
const productIndex = (0, _utils.getProductIdentityIndex)(tempOrder.products, {
|
|
1303
1311
|
product_id: productId,
|
|
1304
1312
|
product_variant_id: productVariantId
|
|
1305
1313
|
});
|
|
1306
1314
|
if (productIndex === -1) {
|
|
1307
1315
|
const sellingPrice = (0, _utils.toPriceString)(sourceItem?.price ?? sourceItem?.selling_price, '0.00');
|
|
1308
|
-
tempOrder.products.push(
|
|
1309
|
-
...
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1316
|
+
tempOrder.products.push({
|
|
1317
|
+
...(0, _utils.normalizeOrderProduct)({
|
|
1318
|
+
...sourceItem,
|
|
1319
|
+
product_id: productId,
|
|
1320
|
+
product_variant_id: productVariantId,
|
|
1321
|
+
num: targetQuantity,
|
|
1322
|
+
selling_price: sellingPrice,
|
|
1323
|
+
original_price: sellingPrice,
|
|
1324
|
+
metadata: {
|
|
1325
|
+
item_rule_prefill: true,
|
|
1326
|
+
item_rule_id: prefillItem.ruleId
|
|
1327
|
+
},
|
|
1328
|
+
_origin: {
|
|
1329
|
+
...(sourceItem || {}),
|
|
1330
|
+
item_rule_prefill: true,
|
|
1331
|
+
item_rule_id: prefillItem.ruleId
|
|
1332
|
+
}
|
|
1333
|
+
}),
|
|
1334
|
+
...displayFields
|
|
1335
|
+
});
|
|
1325
1336
|
hasChanges = true;
|
|
1326
1337
|
continue;
|
|
1327
1338
|
}
|
|
@@ -1330,6 +1341,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1330
1341
|
const delta = targetQuantity - existedQuantity;
|
|
1331
1342
|
const nextProduct = {
|
|
1332
1343
|
...targetProduct,
|
|
1344
|
+
...displayFields,
|
|
1333
1345
|
...(delta > 0 ? {
|
|
1334
1346
|
num: (0, _utils.getSafeProductNum)(existedQuantity + delta)
|
|
1335
1347
|
} : {}),
|
|
@@ -1344,8 +1356,9 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1344
1356
|
} : targetProduct._origin
|
|
1345
1357
|
};
|
|
1346
1358
|
const hasQuantityChanged = delta > 0;
|
|
1359
|
+
const hasTitleChanged = Boolean(productTitle && JSON.stringify(targetProduct.product_title) !== JSON.stringify(productTitle));
|
|
1347
1360
|
const hasOriginChanged = Boolean(sourceItem && (!targetProduct._origin || targetProduct._origin?.name !== sourceItem?.name || targetProduct._origin?.title !== sourceItem?.title || targetProduct._origin?.price !== sourceItem?.price));
|
|
1348
|
-
if (hasQuantityChanged || hasOriginChanged) {
|
|
1361
|
+
if (hasQuantityChanged || hasTitleChanged || hasOriginChanged) {
|
|
1349
1362
|
tempOrder.products[productIndex] = nextProduct;
|
|
1350
1363
|
hasChanges = true;
|
|
1351
1364
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, ScheduleModule } from '../../modules';
|
|
2
2
|
import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
|
|
3
|
+
import type { OrderLocalizedText } from '../../modules/Order/types';
|
|
3
4
|
/**
|
|
4
5
|
* 扫码下单流程 hook
|
|
5
6
|
*/
|
|
@@ -43,6 +44,8 @@ export interface ScanOrderProductSku {
|
|
|
43
44
|
}
|
|
44
45
|
export interface ScanOrderOrderProduct extends ScanOrderOrderProductIdentity {
|
|
45
46
|
order_detail_id: number | null;
|
|
47
|
+
/** 与 Order 一致的商品展示名称。 */
|
|
48
|
+
product_title?: OrderLocalizedText;
|
|
46
49
|
num: number;
|
|
47
50
|
/** Product 或当前 Variant 的生产编码 */
|
|
48
51
|
production_code?: string;
|