@pisell/pisellos 2.3.229 → 2.3.231

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.
Files changed (37) hide show
  1. package/dist/model/strategy/adapter/promotion/adapter.js +14 -2
  2. package/dist/model/strategy/adapter/promotion/evaluator.js +23 -8
  3. package/dist/model/strategy/adapter/promotion/type.d.ts +10 -2
  4. package/dist/modules/Order/index.d.ts +1 -1
  5. package/dist/modules/Order/index.js +1371 -1234
  6. package/dist/modules/Order/types.d.ts +13 -34
  7. package/dist/modules/Order/types.js +2 -0
  8. package/dist/modules/Summary/utils.d.ts +1 -1
  9. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  10. package/dist/solution/BaseSales/utils/cartPromotion.js +252 -168
  11. package/dist/solution/BookingTicket/index.d.ts +2 -2
  12. package/dist/solution/BookingTicket/index.js +45 -21
  13. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
  14. package/dist/solution/ScanOrder/index.d.ts +1 -0
  15. package/dist/solution/ScanOrder/index.js +52 -38
  16. package/dist/solution/ScanOrder/menuAvailability.js +3 -25
  17. package/dist/solution/ScanOrder/shopTime.d.ts +6 -0
  18. package/dist/solution/ScanOrder/shopTime.js +36 -0
  19. package/lib/model/strategy/adapter/promotion/adapter.js +10 -1
  20. package/lib/model/strategy/adapter/promotion/evaluator.js +18 -6
  21. package/lib/model/strategy/adapter/promotion/type.d.ts +10 -2
  22. package/lib/modules/Order/index.d.ts +1 -1
  23. package/lib/modules/Order/index.js +103 -32
  24. package/lib/modules/Order/types.d.ts +13 -34
  25. package/lib/modules/Order/types.js +1 -0
  26. package/lib/modules/Summary/utils.d.ts +1 -1
  27. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  28. package/lib/solution/BaseSales/utils/cartPromotion.js +87 -40
  29. package/lib/solution/BookingTicket/index.d.ts +2 -2
  30. package/lib/solution/BookingTicket/index.js +28 -11
  31. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
  32. package/lib/solution/ScanOrder/index.d.ts +1 -0
  33. package/lib/solution/ScanOrder/index.js +26 -13
  34. package/lib/solution/ScanOrder/menuAvailability.js +3 -20
  35. package/lib/solution/ScanOrder/shopTime.d.ts +6 -0
  36. package/lib/solution/ScanOrder/shopTime.js +37 -0
  37. package/package.json +1 -1
@@ -723,24 +723,135 @@ function convertToPromotionProduct(product, index) {
723
723
  // 主流程:processCartPromotion
724
724
  // ============================================
725
725
 
726
+ function reduceGiftQuantity(actions, strategyId, items, quantity) {
727
+ var reductions = [];
728
+ var remaining = quantity;
729
+ var _iterator9 = _createForOfIteratorHelper(_toConsumableArray(items).reverse()),
730
+ _step9;
731
+ try {
732
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
733
+ var _item$num;
734
+ var item = _step9.value;
735
+ if (remaining <= 0) break;
736
+ var uid = getOrderProductUid(item);
737
+ var currentQuantity = Number((_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : 1) || 1;
738
+ if (currentQuantity <= remaining) {
739
+ actions.toRemove.push(uid);
740
+ remaining -= currentQuantity;
741
+ } else {
742
+ reductions.push({
743
+ uid: uid,
744
+ currentQuantity: currentQuantity,
745
+ newQuantity: currentQuantity - remaining
746
+ });
747
+ remaining = 0;
748
+ }
749
+ }
750
+ } catch (err) {
751
+ _iterator9.e(err);
752
+ } finally {
753
+ _iterator9.f();
754
+ }
755
+ if (reductions.length) actions.toReduce.push({
756
+ strategyId: strategyId,
757
+ items: reductions
758
+ });
759
+ }
760
+ function calculateFixedGiftActions(gift, existing, previousQuotas, actions) {
761
+ var unmatched = new Set(existing);
762
+ var addedQuotas = [];
763
+ var _iterator10 = _createForOfIteratorHelper(gift.giftQuotas || []),
764
+ _step10;
765
+ try {
766
+ var _loop2 = function _loop2() {
767
+ var _previous$quantity;
768
+ var quota = _step10.value;
769
+ var product_id = quota.product_id,
770
+ product_variant_id = quota.product_variant_id,
771
+ quantity = quota.quantity;
772
+ var matching = existing.filter(function (item) {
773
+ return Number(item.product_id) === product_id && (product_variant_id === 0 || Number(item.product_variant_id) === product_variant_id);
774
+ });
775
+ matching.forEach(function (item) {
776
+ return unmatched.delete(item);
777
+ });
778
+ var existingCount = matching.reduce(function (count, item) {
779
+ var _item$num2;
780
+ return count + (Number((_item$num2 = item.num) !== null && _item$num2 !== void 0 ? _item$num2 : 1) || 1);
781
+ }, 0);
782
+ var previous = previousQuotas.find(function (item) {
783
+ return item.product_id === product_id && item.product_variant_id === product_variant_id;
784
+ });
785
+ // 已放弃的额度可以手动领取。自动选择只请求本次新增的部分。
786
+ var added = quantity - Math.max(existingCount, (_previous$quantity = previous === null || previous === void 0 ? void 0 : previous.quantity) !== null && _previous$quantity !== void 0 ? _previous$quantity : 0);
787
+ if (added > 0) {
788
+ addedQuotas.push({
789
+ product_id: product_id,
790
+ product_variant_id: product_variant_id,
791
+ quantity: added
792
+ });
793
+ } else if (existingCount > quantity) {
794
+ reduceGiftQuantity(actions, gift.strategyId, matching, existingCount - quantity);
795
+ }
796
+ };
797
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
798
+ _loop2();
799
+ }
800
+ } catch (err) {
801
+ _iterator10.e(err);
802
+ } finally {
803
+ _iterator10.f();
804
+ }
805
+ if (addedQuotas.length) {
806
+ actions.toAdd.push(_objectSpread(_objectSpread({}, gift), {}, {
807
+ giftCount: addedQuotas.reduce(function (count, quota) {
808
+ return count + quota.quantity;
809
+ }, 0),
810
+ giftOptions: addedQuotas.map(function (_ref13) {
811
+ var product_id = _ref13.product_id,
812
+ product_variant_id = _ref13.product_variant_id;
813
+ return {
814
+ product_id: product_id,
815
+ product_variant_id: product_variant_id
816
+ };
817
+ }),
818
+ giftQuotas: addedQuotas
819
+ }));
820
+ }
821
+ var _iterator11 = _createForOfIteratorHelper(unmatched),
822
+ _step11;
823
+ try {
824
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
825
+ var item = _step11.value;
826
+ actions.toRemove.push(getOrderProductUid(item));
827
+ }
828
+ } catch (err) {
829
+ _iterator11.e(err);
830
+ } finally {
831
+ _iterator11.f();
832
+ }
833
+ }
834
+
726
835
  /**
727
836
  * 计算赠品差异化操作(toAdd / toReduce / toRemove)。
728
837
  *
729
- * 与 legacy `calculateGiftActions` 等价;唯一差别是行键从 `_id` 改成 `metadata.unique_identification_number`。
838
+ * 任选赠品按活动总量对账,固定赠品按活动内的各款额度对账。
730
839
  */
731
- function calculateGiftActions(gifts, existingGifts) {
732
- var toAdd = [];
733
- var toReduce = [];
734
- var toRemove = [];
840
+ function calculateGiftActions(gifts, existingGifts, previousFixedGiftQuotas) {
841
+ var actions = {
842
+ toAdd: [],
843
+ toReduce: [],
844
+ toRemove: []
845
+ };
735
846
 
736
847
  // 按 strategyId 分组现有赠品
737
848
  var existingByStrategy = new Map();
738
- var _iterator9 = _createForOfIteratorHelper(existingGifts),
739
- _step9;
849
+ var _iterator12 = _createForOfIteratorHelper(existingGifts),
850
+ _step12;
740
851
  try {
741
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
852
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
742
853
  var _getGiftInfo, _gift$num;
743
- var gift = _step9.value;
854
+ var gift = _step12.value;
744
855
  var strategyId = (_getGiftInfo = getGiftInfo(gift)) === null || _getGiftInfo === void 0 ? void 0 : _getGiftInfo.strategyId;
745
856
  if (!strategyId) continue;
746
857
  var existing = existingByStrategy.get(strategyId);
@@ -756,34 +867,41 @@ function calculateGiftActions(gifts, existingGifts) {
756
867
  }
757
868
  }
758
869
  } catch (err) {
759
- _iterator9.e(err);
870
+ _iterator12.e(err);
760
871
  } finally {
761
- _iterator9.f();
872
+ _iterator12.f();
762
873
  }
763
874
  var processedStrategyIds = new Set();
764
- var _iterator10 = _createForOfIteratorHelper(gifts),
765
- _step10;
875
+ var _iterator13 = _createForOfIteratorHelper(gifts),
876
+ _step13;
766
877
  try {
767
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
878
+ var _loop3 = function _loop3() {
768
879
  var _existing$totalQuanti;
769
- var giftInfo = _step10.value;
770
- var _strategyId = giftInfo.strategyId,
880
+ var giftInfo = _step13.value;
881
+ var strategyId = giftInfo.strategyId,
771
882
  strategyName = giftInfo.strategyName,
772
883
  giftCount = giftInfo.giftCount,
773
884
  giftOptions = giftInfo.giftOptions,
774
885
  sourceProductIds = giftInfo.sourceProductIds;
775
- processedStrategyIds.add(_strategyId);
776
- var _existing = existingByStrategy.get(_strategyId);
777
- var existingCount = (_existing$totalQuanti = _existing === null || _existing === void 0 ? void 0 : _existing.totalQuantity) !== null && _existing$totalQuanti !== void 0 ? _existing$totalQuanti : 0;
886
+ processedStrategyIds.add(strategyId);
887
+ var existing = existingByStrategy.get(strategyId);
888
+ if (giftInfo.giftQuotas) {
889
+ var previous = previousFixedGiftQuotas.find(function (item) {
890
+ return item.strategyId === strategyId;
891
+ });
892
+ calculateFixedGiftActions(giftInfo, (existing === null || existing === void 0 ? void 0 : existing.items) || [], (previous === null || previous === void 0 ? void 0 : previous.giftQuotas) || [], actions);
893
+ return 1; // continue
894
+ }
895
+ var existingCount = (_existing$totalQuanti = existing === null || existing === void 0 ? void 0 : existing.totalQuantity) !== null && _existing$totalQuanti !== void 0 ? _existing$totalQuanti : 0;
778
896
  var diff = giftCount - existingCount;
779
897
  if (diff > 0) {
780
898
  var _getGiftInfo2, _existing$items;
781
899
  // 判断「用户手动减赠品」: 若评估器的 giftCount 没变,diff>0 说明是手动减,跳过补回
782
- var lastEvaluated = (_getGiftInfo2 = getGiftInfo(_existing === null || _existing === void 0 || (_existing$items = _existing.items) === null || _existing$items === void 0 ? void 0 : _existing$items[0])) === null || _getGiftInfo2 === void 0 ? void 0 : _getGiftInfo2.lastEvaluatedGiftCount;
900
+ var lastEvaluated = (_getGiftInfo2 = getGiftInfo(existing === null || existing === void 0 || (_existing$items = existing.items) === null || _existing$items === void 0 ? void 0 : _existing$items[0])) === null || _getGiftInfo2 === void 0 ? void 0 : _getGiftInfo2.lastEvaluatedGiftCount;
783
901
  var strategyChanged = lastEvaluated === undefined || giftCount !== lastEvaluated;
784
902
  if (strategyChanged) {
785
- toAdd.push({
786
- strategyId: _strategyId,
903
+ actions.toAdd.push({
904
+ strategyId: strategyId,
787
905
  strategyName: strategyName,
788
906
  giftCount: diff,
789
907
  giftOptions: giftOptions,
@@ -791,82 +909,46 @@ function calculateGiftActions(gifts, existingGifts) {
791
909
  });
792
910
  }
793
911
  } else if (diff < 0) {
794
- // 减赠品:后进先出
795
- var remaining = Math.abs(diff);
796
- var reduceItems = [];
797
- var removeIds = [];
798
- var reversed = _toConsumableArray((_existing === null || _existing === void 0 ? void 0 : _existing.items) || []).reverse();
799
- var _iterator12 = _createForOfIteratorHelper(reversed),
800
- _step12;
801
- try {
802
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
803
- var _giftItem$num;
804
- var giftItem = _step12.value;
805
- if (remaining <= 0) break;
806
- var uid = getOrderProductUid(giftItem);
807
- var _qty = Number((_giftItem$num = giftItem === null || giftItem === void 0 ? void 0 : giftItem.num) !== null && _giftItem$num !== void 0 ? _giftItem$num : 1) || 1;
808
- if (_qty <= remaining) {
809
- removeIds.push(uid);
810
- remaining -= _qty;
811
- } else {
812
- reduceItems.push({
813
- uid: uid,
814
- currentQuantity: _qty,
815
- newQuantity: _qty - remaining
816
- });
817
- remaining = 0;
818
- }
819
- }
820
- } catch (err) {
821
- _iterator12.e(err);
822
- } finally {
823
- _iterator12.f();
824
- }
825
- if (reduceItems.length > 0) toReduce.push({
826
- strategyId: _strategyId,
827
- items: reduceItems
828
- });
829
- toRemove.push.apply(toRemove, removeIds);
912
+ reduceGiftQuantity(actions, strategyId, (existing === null || existing === void 0 ? void 0 : existing.items) || [], -diff);
830
913
  }
914
+ };
915
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
916
+ if (_loop3()) continue;
831
917
  }
832
918
 
833
919
  // 失效策略的赠品:全部 remove
834
920
  } catch (err) {
835
- _iterator10.e(err);
921
+ _iterator13.e(err);
836
922
  } finally {
837
- _iterator10.f();
923
+ _iterator13.f();
838
924
  }
839
- var _iterator11 = _createForOfIteratorHelper(existingByStrategy),
840
- _step11;
925
+ var _iterator14 = _createForOfIteratorHelper(existingByStrategy),
926
+ _step14;
841
927
  try {
842
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
843
- var _step11$value = _slicedToArray(_step11.value, 2),
844
- _strategyId2 = _step11$value[0],
845
- _existing2 = _step11$value[1];
846
- if (processedStrategyIds.has(_strategyId2)) continue;
847
- var _iterator13 = _createForOfIteratorHelper(_existing2.items),
848
- _step13;
928
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
929
+ var _step14$value = _slicedToArray(_step14.value, 2),
930
+ _strategyId = _step14$value[0],
931
+ _existing = _step14$value[1];
932
+ if (processedStrategyIds.has(_strategyId)) continue;
933
+ var _iterator15 = _createForOfIteratorHelper(_existing.items),
934
+ _step15;
849
935
  try {
850
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
851
- var _giftItem = _step13.value;
852
- toRemove.push(getOrderProductUid(_giftItem));
936
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
937
+ var giftItem = _step15.value;
938
+ actions.toRemove.push(getOrderProductUid(giftItem));
853
939
  }
854
940
  } catch (err) {
855
- _iterator13.e(err);
941
+ _iterator15.e(err);
856
942
  } finally {
857
- _iterator13.f();
943
+ _iterator15.f();
858
944
  }
859
945
  }
860
946
  } catch (err) {
861
- _iterator11.e(err);
947
+ _iterator14.e(err);
862
948
  } finally {
863
- _iterator11.f();
949
+ _iterator14.f();
864
950
  }
865
- return {
866
- toAdd: toAdd,
867
- toReduce: toReduce,
868
- toRemove: toRemove
869
- };
951
+ return actions;
870
952
  }
871
953
 
872
954
  /**
@@ -880,11 +962,11 @@ export function extractProductMatchIdentifiersFromStrategyConfig(strategyConfig)
880
962
  var _strategyConfig$condi;
881
963
  var rules = strategyConfig === null || strategyConfig === void 0 || (_strategyConfig$condi = strategyConfig.conditions) === null || _strategyConfig$condi === void 0 ? void 0 : _strategyConfig$condi.rules;
882
964
  if (!Array.isArray(rules)) return [];
883
- var _iterator14 = _createForOfIteratorHelper(rules),
884
- _step14;
965
+ var _iterator16 = _createForOfIteratorHelper(rules),
966
+ _step16;
885
967
  try {
886
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
887
- var rule = _step14.value;
968
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
969
+ var rule = _step16.value;
888
970
  if ((rule === null || rule === void 0 ? void 0 : rule.field) === 'productIdAndVariantId' && ((rule === null || rule === void 0 ? void 0 : rule.operator) === 'product_match' || (rule === null || rule === void 0 ? void 0 : rule.operator) === 'object_in') && Array.isArray(rule === null || rule === void 0 ? void 0 : rule.value)) {
889
971
  return rule.value.map(function (item) {
890
972
  return {
@@ -897,9 +979,9 @@ export function extractProductMatchIdentifiersFromStrategyConfig(strategyConfig)
897
979
  }
898
980
  }
899
981
  } catch (err) {
900
- _iterator14.e(err);
982
+ _iterator16.e(err);
901
983
  } finally {
902
- _iterator14.f();
984
+ _iterator16.f();
903
985
  }
904
986
  return [];
905
987
  }
@@ -947,14 +1029,14 @@ export function resolveStrategyEligibleProducts(matched) {
947
1029
  */
948
1030
  export function calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts) {
949
1031
  var unfulfilledMap = new Map();
950
- var _loop2 = function _loop2() {
951
- var _product$metadata5, _ref13, _product$_originalPro, _product$metadata6, _product$num2;
1032
+ var _loop4 = function _loop4() {
1033
+ var _product$metadata5, _ref14, _product$_originalPro, _product$metadata6, _product$num2;
952
1034
  var product = processedProducts[i];
953
1035
  var promotion = product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5._promotion;
954
1036
  if (!promotion || promotion.inPromotion !== false || promotion.excludedByDiscountCard) return 0; // continue
955
1037
  var strategyId = promotion.strategyId;
956
1038
  if (!strategyId) return 0; // continue
957
- var lookupUid = String((_ref13 = (_product$_originalPro = product === null || product === void 0 ? void 0 : product._originalProductUid) !== null && _product$_originalPro !== void 0 ? _product$_originalPro : product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number) !== null && _ref13 !== void 0 ? _ref13 : '');
1039
+ var lookupUid = String((_ref14 = (_product$_originalPro = product === null || product === void 0 ? void 0 : product._originalProductUid) !== null && _product$_originalPro !== void 0 ? _product$_originalPro : product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number) !== null && _ref14 !== void 0 ? _ref14 : '');
958
1040
  var originalIndex = mainProducts.findIndex(function (item) {
959
1041
  return getOrderProductUid(item) === lookupUid;
960
1042
  });
@@ -984,15 +1066,15 @@ export function calculateUnfulfilledPromotions(processedProducts, applicableStra
984
1066
  },
985
1067
  _ret;
986
1068
  for (var i = 0; i < processedProducts.length; i++) {
987
- _ret = _loop2();
1069
+ _ret = _loop4();
988
1070
  if (_ret === 0) continue;
989
1071
  }
990
1072
  var result = [];
991
- var _iterator15 = _createForOfIteratorHelper(unfulfilledMap.values()),
992
- _step15;
1073
+ var _iterator17 = _createForOfIteratorHelper(unfulfilledMap.values()),
1074
+ _step17;
993
1075
  try {
994
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
995
- var data = _step15.value;
1076
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
1077
+ var data = _step17.value;
996
1078
  var needQuantity = data.requiredQuantity - data.currentQuantity;
997
1079
  if (needQuantity > 0) {
998
1080
  result.push(_objectSpread(_objectSpread({}, data), {}, {
@@ -1001,9 +1083,9 @@ export function calculateUnfulfilledPromotions(processedProducts, applicableStra
1001
1083
  }
1002
1084
  }
1003
1085
  } catch (err) {
1004
- _iterator15.e(err);
1086
+ _iterator17.e(err);
1005
1087
  } finally {
1006
- _iterator15.f();
1088
+ _iterator17.f();
1007
1089
  }
1008
1090
  return result;
1009
1091
  }
@@ -1025,10 +1107,10 @@ export function appendPromotionTags(products, evaluator) {
1025
1107
 
1026
1108
  // 评估器期望的 product shape,最少字段集
1027
1109
  var evaluatorInput = products.map(function (item, index) {
1028
- var _ref14, _item$id, _item$product_variant4, _item$price, _item$quantity;
1110
+ var _ref15, _item$id, _item$product_variant4, _item$price, _item$quantity;
1029
1111
  return {
1030
1112
  id: index,
1031
- product_id: Number((_ref14 = (_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id) !== null && _ref14 !== void 0 ? _ref14 : 0) || 0,
1113
+ product_id: Number((_ref15 = (_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id) !== null && _ref15 !== void 0 ? _ref15 : 0) || 0,
1032
1114
  product_variant_id: Number((_item$product_variant4 = item === null || item === void 0 ? void 0 : item.product_variant_id) !== null && _item$product_variant4 !== void 0 ? _item$product_variant4 : 0) || 0,
1033
1115
  name: (item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.name) || '',
1034
1116
  price: Number((_item$price = item === null || item === void 0 ? void 0 : item.price) !== null && _item$price !== void 0 ? _item$price : 0) || 0,
@@ -1043,11 +1125,11 @@ export function appendPromotionTags(products, evaluator) {
1043
1125
  var data = strategies[index];
1044
1126
  var tags = [];
1045
1127
  if (data !== null && data !== void 0 && data.hasApplicableStrategy) {
1046
- var _iterator16 = _createForOfIteratorHelper(data.applicableStrategies),
1047
- _step16;
1128
+ var _iterator18 = _createForOfIteratorHelper(data.applicableStrategies),
1129
+ _step18;
1048
1130
  try {
1049
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
1050
- var strategy = _step16.value;
1131
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
1132
+ var strategy = _step18.value;
1051
1133
  if (strategy.display) {
1052
1134
  tags.push({
1053
1135
  text: strategy.display.text,
@@ -1057,18 +1139,18 @@ export function appendPromotionTags(products, evaluator) {
1057
1139
  }
1058
1140
  }
1059
1141
  } catch (err) {
1060
- _iterator16.e(err);
1142
+ _iterator18.e(err);
1061
1143
  } finally {
1062
- _iterator16.f();
1144
+ _iterator18.f();
1063
1145
  }
1064
1146
  }
1065
1147
  // 商品卡兼容两种位置:顶层 `_promotionTags` 与 `metadata._promotionTags`
1066
1148
  // ProductCard 现有实现读顶层(详见 productSelect/ProductCard/index.tsx),
1067
1149
  // 此处同时写顶层以保持视图直连;OrderProduct 行版本走 metadata(避免顶层非协议字段)。
1068
1150
  if (tags.length === 0) {
1069
- var _ref15 = item,
1070
- _promotionTags = _ref15._promotionTags,
1071
- rest = _objectWithoutProperties(_ref15, _excluded);
1151
+ var _ref16 = item,
1152
+ _promotionTags = _ref16._promotionTags,
1153
+ rest = _objectWithoutProperties(_ref16, _excluded);
1072
1154
  void _promotionTags;
1073
1155
  return rest;
1074
1156
  }
@@ -1162,18 +1244,18 @@ export function processCartPromotion(list, evaluator, options) {
1162
1244
  });
1163
1245
  if (existingGifts.length > 0) {
1164
1246
  var toRemove = [];
1165
- var _iterator17 = _createForOfIteratorHelper(existingGifts),
1166
- _step17;
1247
+ var _iterator19 = _createForOfIteratorHelper(existingGifts),
1248
+ _step19;
1167
1249
  try {
1168
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
1169
- var gift = _step17.value;
1250
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
1251
+ var gift = _step19.value;
1170
1252
  var uid = getOrderProductUid(gift);
1171
1253
  if (uid) toRemove.push(uid);
1172
1254
  }
1173
1255
  } catch (err) {
1174
- _iterator17.e(err);
1256
+ _iterator19.e(err);
1175
1257
  } finally {
1176
- _iterator17.f();
1258
+ _iterator19.f();
1177
1259
  }
1178
1260
  return {
1179
1261
  products: editProducts,
@@ -1195,16 +1277,16 @@ export function processCartPromotion(list, evaluator, options) {
1195
1277
  // 1. 转 PromotionProduct
1196
1278
  var promotionProducts = [];
1197
1279
  var originalItemMap = new Map();
1198
- var productsForStrategies = consolidatedMainProductsWithIndex.map(function (_ref16, i) {
1199
- var _item$product_id, _item$product_variant5, _item$metadata5, _item$num;
1200
- var item = _ref16.item;
1280
+ var productsForStrategies = consolidatedMainProductsWithIndex.map(function (_ref17, i) {
1281
+ var _item$product_id, _item$product_variant5, _item$metadata5, _item$num3;
1282
+ var item = _ref17.item;
1201
1283
  return {
1202
1284
  id: i,
1203
1285
  product_id: Number((_item$product_id = item === null || item === void 0 ? void 0 : item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : 0) || 0,
1204
1286
  product_variant_id: Number((_item$product_variant5 = item === null || item === void 0 ? void 0 : item.product_variant_id) !== null && _item$product_variant5 !== void 0 ? _item$product_variant5 : 0) || 0,
1205
1287
  name: (item === null || item === void 0 || (_item$metadata5 = item.metadata) === null || _item$metadata5 === void 0 ? void 0 : _item$metadata5.product_name) || (item === null || item === void 0 ? void 0 : item.title) || '',
1206
1288
  price: getOrderProductBasePrice(item),
1207
- quantity: Number((_item$num = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num !== void 0 ? _item$num : 1) || 1,
1289
+ quantity: Number((_item$num3 = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num3 !== void 0 ? _item$num3 : 1) || 1,
1208
1290
  bundle: getProductBundleForEvaluator(item),
1209
1291
  _promotionOnlyForItemReward: isBookingEditProductLine(item)
1210
1292
  };
@@ -1227,16 +1309,16 @@ export function processCartPromotion(list, evaluator, options) {
1227
1309
  channel: options === null || options === void 0 ? void 0 : options.channel
1228
1310
  });
1229
1311
  var strategyActionMap = new Map();
1230
- var _iterator18 = _createForOfIteratorHelper(applicableStrategiesResult || []),
1231
- _step18;
1312
+ var _iterator20 = _createForOfIteratorHelper(applicableStrategiesResult || []),
1313
+ _step20;
1232
1314
  try {
1233
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
1234
- var row = _step18.value;
1235
- var _iterator23 = _createForOfIteratorHelper((row === null || row === void 0 ? void 0 : row.applicableStrategies) || []),
1236
- _step23;
1315
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
1316
+ var row = _step20.value;
1317
+ var _iterator25 = _createForOfIteratorHelper((row === null || row === void 0 ? void 0 : row.applicableStrategies) || []),
1318
+ _step25;
1237
1319
  try {
1238
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
1239
- var strategy = _step23.value;
1320
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
1321
+ var strategy = _step25.value;
1240
1322
  if (!(strategy !== null && strategy !== void 0 && strategy.strategyId)) continue;
1241
1323
  strategyActionMap.set(strategy.strategyId, {
1242
1324
  actionType: strategy.actionType,
@@ -1244,17 +1326,17 @@ export function processCartPromotion(list, evaluator, options) {
1244
1326
  });
1245
1327
  }
1246
1328
  } catch (err) {
1247
- _iterator23.e(err);
1329
+ _iterator25.e(err);
1248
1330
  } finally {
1249
- _iterator23.f();
1331
+ _iterator25.f();
1250
1332
  }
1251
1333
  }
1252
1334
 
1253
1335
  // 3. 评估器
1254
1336
  } catch (err) {
1255
- _iterator18.e(err);
1337
+ _iterator20.e(err);
1256
1338
  } finally {
1257
- _iterator18.f();
1339
+ _iterator20.f();
1258
1340
  }
1259
1341
  var result = evaluator.evaluateCartWithPricing({
1260
1342
  products: promotionProducts,
@@ -1263,11 +1345,11 @@ export function processCartPromotion(list, evaluator, options) {
1263
1345
 
1264
1346
  // 4. 收集每个策略的 sourceProductIds(参与策略的主商品 uid)
1265
1347
  var strategySourceProductIds = new Map();
1266
- var _iterator19 = _createForOfIteratorHelper(result.products),
1267
- _step19;
1348
+ var _iterator21 = _createForOfIteratorHelper(result.products),
1349
+ _step21;
1268
1350
  try {
1269
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
1270
- var priced = _step19.value;
1351
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
1352
+ var priced = _step21.value;
1271
1353
  if (priced.inPromotion && priced.strategyId) {
1272
1354
  var _priced$originalId;
1273
1355
  var sourceId = (_priced$originalId = priced.originalId) !== null && _priced$originalId !== void 0 ? _priced$originalId : priced.id;
@@ -1284,9 +1366,9 @@ export function processCartPromotion(list, evaluator, options) {
1284
1366
 
1285
1367
  // 5. 扩展 gifts,加 sourceProductIds
1286
1368
  } catch (err) {
1287
- _iterator19.e(err);
1369
+ _iterator21.e(err);
1288
1370
  } finally {
1289
- _iterator19.f();
1371
+ _iterator21.f();
1290
1372
  }
1291
1373
  var extendedGifts = result.gifts.map(function (gift) {
1292
1374
  return _objectSpread(_objectSpread({}, gift), {}, {
@@ -1296,26 +1378,26 @@ export function processCartPromotion(list, evaluator, options) {
1296
1378
 
1297
1379
  // 6. PricedProduct → OrderProduct(含拆分与价格调整)
1298
1380
  var strategyGiftInfoMap = new Map();
1299
- var _iterator20 = _createForOfIteratorHelper(extendedGifts),
1300
- _step20;
1381
+ var _iterator22 = _createForOfIteratorHelper(extendedGifts),
1382
+ _step22;
1301
1383
  try {
1302
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
1303
- var _gift = _step20.value;
1384
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
1385
+ var _gift = _step22.value;
1304
1386
  strategyGiftInfoMap.set(_gift.strategyId, _gift);
1305
1387
  }
1306
1388
  } catch (err) {
1307
- _iterator20.e(err);
1389
+ _iterator22.e(err);
1308
1390
  } finally {
1309
- _iterator20.f();
1391
+ _iterator22.f();
1310
1392
  }
1311
1393
  var strategyGiftInfoOwner = new Map();
1312
1394
  var processedProducts = [];
1313
- var _iterator21 = _createForOfIteratorHelper(result.products),
1314
- _step21;
1395
+ var _iterator23 = _createForOfIteratorHelper(result.products),
1396
+ _step23;
1315
1397
  try {
1316
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
1398
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
1317
1399
  var _priced$originalId2, _priced$product_id, _originalItem$product;
1318
- var _priced = _step21.value;
1400
+ var _priced = _step23.value;
1319
1401
  var rawSourceId = (_priced$originalId2 = _priced.originalId) !== null && _priced$originalId2 !== void 0 ? _priced$originalId2 : _priced.id;
1320
1402
  var _sourceId = Number(rawSourceId);
1321
1403
  var _originalData = Number.isFinite(_sourceId) ? originalItemMap.get(_sourceId) : undefined;
@@ -1336,17 +1418,17 @@ export function processCartPromotion(list, evaluator, options) {
1336
1418
  var wasInPromotion = wasInPromotionBeforeEvaluation(originalItem) || originalItem._wasInPromotionBeforeConsolidate === true;
1337
1419
  delete metadata._promotion;
1338
1420
  if (Array.isArray(newItem.product_bundle)) {
1339
- var _iterator24 = _createForOfIteratorHelper(newItem.product_bundle),
1340
- _step24;
1421
+ var _iterator26 = _createForOfIteratorHelper(newItem.product_bundle),
1422
+ _step26;
1341
1423
  try {
1342
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
1343
- var b = _step24.value;
1424
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
1425
+ var b = _step26.value;
1344
1426
  if (b && _typeof(b) === 'object') delete b._promotion;
1345
1427
  }
1346
1428
  } catch (err) {
1347
- _iterator24.e(err);
1429
+ _iterator26.e(err);
1348
1430
  } finally {
1349
- _iterator24.f();
1431
+ _iterator26.f();
1350
1432
  }
1351
1433
  }
1352
1434
  var originalBasePrice = getOrderProductOriginalPriceForPromotion(originalItem);
@@ -1408,11 +1490,13 @@ export function processCartPromotion(list, evaluator, options) {
1408
1490
  var _gift2 = strategyGiftInfoMap.get(_priced.strategyId);
1409
1491
  if (_gift2 && Array.isArray(_gift2.giftOptions) && _gift2.giftOptions.length > 0 && !strategyGiftInfoOwner.has(_priced.strategyId)) {
1410
1492
  var _newItem$product_bund;
1411
- var giftInfoData = {
1493
+ var giftInfoData = _objectSpread({
1412
1494
  strategyName: _gift2.strategyName,
1413
1495
  giftCount: _gift2.giftCount,
1414
1496
  giftOptions: _gift2.giftOptions
1415
- };
1497
+ }, _gift2.giftQuotas && {
1498
+ giftQuotas: _gift2.giftQuotas
1499
+ });
1416
1500
  var _bundleIdx = _priced.matchedBundleIndex;
1417
1501
  if (_bundleIdx !== undefined && Array.isArray(newItem.product_bundle) && (_newItem$product_bund = newItem.product_bundle[_bundleIdx]) !== null && _newItem$product_bund !== void 0 && _newItem$product_bund._promotion) {
1418
1502
  newItem.product_bundle[_bundleIdx]._promotion.giftInfo = giftInfoData;
@@ -1432,9 +1516,9 @@ export function processCartPromotion(list, evaluator, options) {
1432
1516
 
1433
1517
  // 7. 赠品/编辑商品原样拼回;同时同步赠品的 sourceProductIds / sourceProductId
1434
1518
  } catch (err) {
1435
- _iterator21.e(err);
1519
+ _iterator23.e(err);
1436
1520
  } finally {
1437
- _iterator21.f();
1521
+ _iterator23.f();
1438
1522
  }
1439
1523
  for (var _i2 = 0, _existingGiftsWithInd = existingGiftsWithIndex; _i2 < _existingGiftsWithInd.length; _i2++) {
1440
1524
  var _getGiftInfo3;
@@ -1483,7 +1567,7 @@ export function processCartPromotion(list, evaluator, options) {
1483
1567
  processedProducts.splice.apply(processedProducts, [0, processedProducts.length].concat(_toConsumableArray(splitPromoLines)));
1484
1568
 
1485
1569
  // 9. 给「有适用策略但未参与促销」的主商品打 inPromotion:false
1486
- var _loop3 = function _loop3() {
1570
+ var _loop5 = function _loop5() {
1487
1571
  var _product$_originalPro2;
1488
1572
  var product = _processedProducts[_i4];
1489
1573
  var metadata = product.metadata || {};
@@ -1510,23 +1594,23 @@ export function processCartPromotion(list, evaluator, options) {
1510
1594
  },
1511
1595
  _ret2;
1512
1596
  for (var _i4 = 0, _processedProducts = processedProducts; _i4 < _processedProducts.length; _i4++) {
1513
- _ret2 = _loop3();
1597
+ _ret2 = _loop5();
1514
1598
  if (_ret2 === 0) continue;
1515
1599
  }
1516
1600
 
1517
1601
  // 10. 赠品操作(在更新 lastEvaluatedGiftCount 前做对比)
1518
- var giftActions = calculateGiftActions(extendedGifts, existingGifts);
1602
+ var giftActions = calculateGiftActions(extendedGifts, existingGifts, (options === null || options === void 0 ? void 0 : options.previousFixedGiftQuotas) || []);
1519
1603
 
1520
1604
  // 10.1 更新 lastEvaluatedGiftCount,便于下次评估时判别「策略已变」
1521
- var _iterator22 = _createForOfIteratorHelper(existingGifts),
1522
- _step22;
1605
+ var _iterator24 = _createForOfIteratorHelper(existingGifts),
1606
+ _step24;
1523
1607
  try {
1524
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
1608
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
1525
1609
  var _getGiftInfo4, _metadata;
1526
- var _gift3 = _step22.value;
1527
- var _strategyId3 = (_getGiftInfo4 = getGiftInfo(_gift3)) === null || _getGiftInfo4 === void 0 ? void 0 : _getGiftInfo4.strategyId;
1528
- if (!_strategyId3) continue;
1529
- var _latest = strategyGiftInfoMap.get(_strategyId3);
1610
+ var _gift3 = _step24.value;
1611
+ var _strategyId2 = (_getGiftInfo4 = getGiftInfo(_gift3)) === null || _getGiftInfo4 === void 0 ? void 0 : _getGiftInfo4.strategyId;
1612
+ if (!_strategyId2) continue;
1613
+ var _latest = strategyGiftInfoMap.get(_strategyId2);
1530
1614
  if (_latest && (_metadata = _gift3.metadata) !== null && _metadata !== void 0 && _metadata._giftInfo) {
1531
1615
  _gift3.metadata._giftInfo.lastEvaluatedGiftCount = _latest.giftCount;
1532
1616
  }
@@ -1534,9 +1618,9 @@ export function processCartPromotion(list, evaluator, options) {
1534
1618
 
1535
1619
  // 11. 未满足促销
1536
1620
  } catch (err) {
1537
- _iterator22.e(err);
1621
+ _iterator24.e(err);
1538
1622
  } finally {
1539
- _iterator22.f();
1623
+ _iterator24.f();
1540
1624
  }
1541
1625
  var unfulfilledPromotions = calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts);
1542
1626