@pisell/pisellos 2.2.72 → 2.2.74
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.
|
@@ -719,7 +719,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
719
719
|
unitProducts.push({
|
|
720
720
|
product: product,
|
|
721
721
|
price: product.price,
|
|
722
|
-
productId: product.id
|
|
722
|
+
productId: product.id,
|
|
723
|
+
sourceAvailableQty: availableQty
|
|
723
724
|
});
|
|
724
725
|
}
|
|
725
726
|
}
|
|
@@ -736,8 +737,13 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
736
737
|
};
|
|
737
738
|
}
|
|
738
739
|
|
|
739
|
-
// 2.
|
|
740
|
+
// 2. 排序:优先选择来源数量是 x 倍数的商品(可完整凑组不拆分),然后按价格从高到低
|
|
740
741
|
unitProducts.sort(function (a, b) {
|
|
742
|
+
// 优先级1:来源购物车项数量是 x 的倍数的排前面(这些商品可以完整凑组,避免拆分)
|
|
743
|
+
var aIsMultiple = a.sourceAvailableQty > 0 && a.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
744
|
+
var bIsMultiple = b.sourceAvailableQty > 0 && b.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
745
|
+
if (aIsMultiple !== bIsMultiple) return bIsMultiple - aIsMultiple;
|
|
746
|
+
// 优先级2:按价格从高到低(优先使用高价商品)
|
|
741
747
|
return b.price - a.price;
|
|
742
748
|
});
|
|
743
749
|
|
|
@@ -833,7 +839,10 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
833
839
|
var totalAllocated = allocatedPrices.reduce(function (sum, p) {
|
|
834
840
|
return sum.plus(p);
|
|
835
841
|
}, new Decimal(0));
|
|
836
|
-
|
|
842
|
+
// 取促销价和原价的最小值,避免促销反而加价
|
|
843
|
+
var productOriginalAmount = new Decimal(_product.price).mul(promoQty);
|
|
844
|
+
var actualTotal = Decimal.min(totalAllocated, productOriginalAmount);
|
|
845
|
+
var finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
|
|
837
846
|
result.push(_objectSpread(_objectSpread({}, _product), {}, {
|
|
838
847
|
quantity: promoQty,
|
|
839
848
|
finalPrice: finalPricePerUnit,
|
|
@@ -843,9 +852,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
843
852
|
isSplit: false,
|
|
844
853
|
matchedBundleIndex: matchedBundleIndex
|
|
845
854
|
}));
|
|
846
|
-
var productOriginalAmount = new Decimal(_product.price).mul(promoQty);
|
|
847
855
|
originalAmount = originalAmount.plus(productOriginalAmount);
|
|
848
|
-
finalAmount = finalAmount.plus(
|
|
856
|
+
finalAmount = finalAmount.plus(actualTotal);
|
|
849
857
|
} else if (promoQty === 0 && remainingQty > 0) {
|
|
850
858
|
// 全部不参与促销:保留原 id,finalPrice = 原价
|
|
851
859
|
result.push(_objectSpread(_objectSpread({}, _product), {}, {
|
|
@@ -865,7 +873,10 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
865
873
|
var _totalAllocated = allocatedPrices.reduce(function (sum, p) {
|
|
866
874
|
return sum.plus(p);
|
|
867
875
|
}, new Decimal(0));
|
|
868
|
-
|
|
876
|
+
// 取促销价和原价的最小值,避免促销反而加价
|
|
877
|
+
var promoOriginalAmount = new Decimal(_product.price).mul(promoQty);
|
|
878
|
+
var _actualTotal = Decimal.min(_totalAllocated, promoOriginalAmount);
|
|
879
|
+
var _finalPricePerUnit = this.formatPrice(_actualTotal.div(promoQty));
|
|
869
880
|
result.push(_objectSpread(_objectSpread({}, _product), {}, {
|
|
870
881
|
id: this.generateRandomId(),
|
|
871
882
|
originalId: _product.id,
|
|
@@ -877,9 +888,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
|
|
|
877
888
|
matchedBundleIndex: matchedBundleIndex,
|
|
878
889
|
isSplit: true
|
|
879
890
|
}));
|
|
880
|
-
var promoOriginalAmount = new Decimal(_product.price).mul(promoQty);
|
|
881
891
|
originalAmount = originalAmount.plus(promoOriginalAmount);
|
|
882
|
-
finalAmount = finalAmount.plus(
|
|
892
|
+
finalAmount = finalAmount.plus(_actualTotal);
|
|
883
893
|
|
|
884
894
|
// 不参与促销的部分:保留原 id
|
|
885
895
|
result.push(_objectSpread(_objectSpread({}, _product), {}, {
|
|
@@ -1061,15 +1061,24 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1061
1061
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1062
1062
|
}))]);
|
|
1063
1063
|
} else {
|
|
1064
|
-
var _ref7, _product$_promotion$f, _product12;
|
|
1064
|
+
var _ref7, _product$_promotion$f, _product12, _product$origin_total;
|
|
1065
|
+
var total = product.inPromotion ? (_ref7 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref7 !== void 0 ? _ref7 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1066
|
+
var main_product_selling_price = product.price;
|
|
1067
|
+
if ((product.discount_list || []).some(function (item) {
|
|
1068
|
+
return item.type === 'promotion';
|
|
1069
|
+
})) {
|
|
1070
|
+
var _product$total, _product$main_product;
|
|
1071
|
+
total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
|
|
1072
|
+
main_product_selling_price = (_product$main_product = product.main_product_selling_price) !== null && _product$main_product !== void 0 ? _product$main_product : main_product_selling_price;
|
|
1073
|
+
}
|
|
1065
1074
|
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
|
|
1066
1075
|
price: product.price,
|
|
1067
1076
|
main_product_selling_price: product.price
|
|
1068
1077
|
} : {
|
|
1069
1078
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1070
|
-
total:
|
|
1079
|
+
total: total,
|
|
1071
1080
|
price: product.price,
|
|
1072
|
-
main_product_selling_price:
|
|
1081
|
+
main_product_selling_price: main_product_selling_price
|
|
1073
1082
|
}), {}, {
|
|
1074
1083
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1075
1084
|
}))]);
|
|
@@ -1110,11 +1119,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1110
1119
|
if (flatItem.type === 'main') {
|
|
1111
1120
|
// 主商品:保持原有逻辑
|
|
1112
1121
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
1122
|
+
var _product$origin_total2;
|
|
1123
|
+
var _total = (_product$origin_total2 = product.origin_total) !== null && _product$origin_total2 !== void 0 ? _product$origin_total2 : product.total;
|
|
1124
|
+
if ((product.discount_list || []).some(function (item) {
|
|
1125
|
+
return item.type === 'promotion';
|
|
1126
|
+
})) {
|
|
1127
|
+
var _product$total2;
|
|
1128
|
+
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1129
|
+
}
|
|
1113
1130
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1114
1131
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1115
1132
|
quantity: totalQuantity - splitCount,
|
|
1116
1133
|
_id: product._id.split('___')[0],
|
|
1117
|
-
total:
|
|
1134
|
+
total: _total
|
|
1118
1135
|
}));
|
|
1119
1136
|
}
|
|
1120
1137
|
for (var i = 0; i < splitCount; i++) {
|
|
@@ -1188,13 +1205,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1188
1205
|
};
|
|
1189
1206
|
appliedProducts.push(discountDetail);
|
|
1190
1207
|
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
1191
|
-
var
|
|
1208
|
+
var _total2 = targetProductTotal;
|
|
1192
1209
|
if (product.options) {
|
|
1193
|
-
|
|
1210
|
+
_total2 = product.options.reduce(function (accumulator, currentValue) {
|
|
1194
1211
|
var currentPrice = new Decimal(currentValue.price || 0);
|
|
1195
1212
|
var currentNum = new Decimal(currentValue.num || 0);
|
|
1196
1213
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
1197
|
-
}, new Decimal(
|
|
1214
|
+
}, new Decimal(_total2)).toNumber();
|
|
1198
1215
|
}
|
|
1199
1216
|
|
|
1200
1217
|
// 记录应用了优惠券的商品
|
|
@@ -1213,7 +1230,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1213
1230
|
}),
|
|
1214
1231
|
variant: originProduct._productInit.variant,
|
|
1215
1232
|
original_price: new Decimal(product.price || 0).toNumber(),
|
|
1216
|
-
total:
|
|
1233
|
+
total: _total2
|
|
1217
1234
|
}));
|
|
1218
1235
|
} else {
|
|
1219
1236
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
@@ -1221,7 +1238,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1221
1238
|
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1222
1239
|
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1223
1240
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1224
|
-
total:
|
|
1241
|
+
total: _total2,
|
|
1225
1242
|
origin_total: productOriginTotal,
|
|
1226
1243
|
main_product_selling_price: targetProductTotal
|
|
1227
1244
|
}));
|
|
@@ -512,14 +512,21 @@ var PromotionEvaluator = class {
|
|
|
512
512
|
unitProducts.push({
|
|
513
513
|
product,
|
|
514
514
|
price: product.price,
|
|
515
|
-
productId: product.id
|
|
515
|
+
productId: product.id,
|
|
516
|
+
sourceAvailableQty: availableQty
|
|
516
517
|
});
|
|
517
518
|
}
|
|
518
519
|
}
|
|
519
520
|
if (unitProducts.length === 0) {
|
|
520
521
|
return { products: [], originalAmount: 0, finalAmount: 0 };
|
|
521
522
|
}
|
|
522
|
-
unitProducts.sort((a, b) =>
|
|
523
|
+
unitProducts.sort((a, b) => {
|
|
524
|
+
const aIsMultiple = a.sourceAvailableQty > 0 && a.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
525
|
+
const bIsMultiple = b.sourceAvailableQty > 0 && b.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
526
|
+
if (aIsMultiple !== bIsMultiple)
|
|
527
|
+
return bIsMultiple - aIsMultiple;
|
|
528
|
+
return b.price - a.price;
|
|
529
|
+
});
|
|
523
530
|
const totalUnits = unitProducts.length;
|
|
524
531
|
const groupCount = cumulative ? Math.floor(totalUnits / x) : totalUnits >= x ? 1 : 0;
|
|
525
532
|
const promotionUnits = groupCount * x;
|
|
@@ -573,7 +580,9 @@ var PromotionEvaluator = class {
|
|
|
573
580
|
(sum, p) => sum.plus(p),
|
|
574
581
|
new import_decimal.default(0)
|
|
575
582
|
);
|
|
576
|
-
const
|
|
583
|
+
const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
584
|
+
const actualTotal = import_decimal.default.min(totalAllocated, productOriginalAmount);
|
|
585
|
+
const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
|
|
577
586
|
result.push({
|
|
578
587
|
...product,
|
|
579
588
|
quantity: promoQty,
|
|
@@ -584,9 +593,8 @@ var PromotionEvaluator = class {
|
|
|
584
593
|
isSplit: false,
|
|
585
594
|
matchedBundleIndex
|
|
586
595
|
});
|
|
587
|
-
const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
588
596
|
originalAmount = originalAmount.plus(productOriginalAmount);
|
|
589
|
-
finalAmount = finalAmount.plus(
|
|
597
|
+
finalAmount = finalAmount.plus(actualTotal);
|
|
590
598
|
} else if (promoQty === 0 && remainingQty > 0) {
|
|
591
599
|
result.push({
|
|
592
600
|
...product,
|
|
@@ -605,7 +613,9 @@ var PromotionEvaluator = class {
|
|
|
605
613
|
(sum, p) => sum.plus(p),
|
|
606
614
|
new import_decimal.default(0)
|
|
607
615
|
);
|
|
608
|
-
const
|
|
616
|
+
const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
617
|
+
const actualTotal = import_decimal.default.min(totalAllocated, promoOriginalAmount);
|
|
618
|
+
const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
|
|
609
619
|
result.push({
|
|
610
620
|
...product,
|
|
611
621
|
id: this.generateRandomId(),
|
|
@@ -618,9 +628,8 @@ var PromotionEvaluator = class {
|
|
|
618
628
|
matchedBundleIndex,
|
|
619
629
|
isSplit: true
|
|
620
630
|
});
|
|
621
|
-
const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
622
631
|
originalAmount = originalAmount.plus(promoOriginalAmount);
|
|
623
|
-
finalAmount = finalAmount.plus(
|
|
632
|
+
finalAmount = finalAmount.plus(actualTotal);
|
|
624
633
|
result.push({
|
|
625
634
|
...product,
|
|
626
635
|
quantity: remainingQty,
|
|
@@ -810,6 +810,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
810
810
|
})
|
|
811
811
|
]);
|
|
812
812
|
} else {
|
|
813
|
+
let total = product.inPromotion ? ((_u = product == null ? void 0 : product._promotion) == null ? void 0 : _u.finalPrice) ?? product.origin_total ?? product.total : product.origin_total ?? product.total;
|
|
814
|
+
let main_product_selling_price = product.price;
|
|
815
|
+
if ((product.discount_list || []).some((item) => item.type === "promotion")) {
|
|
816
|
+
total = product.total ?? product.origin_total;
|
|
817
|
+
main_product_selling_price = product.main_product_selling_price ?? main_product_selling_price;
|
|
818
|
+
}
|
|
813
819
|
processedProductsMap.set(product._id, [
|
|
814
820
|
this.hooks.setProduct(originProduct, {
|
|
815
821
|
...isManualDiscount ? {
|
|
@@ -817,9 +823,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
817
823
|
main_product_selling_price: product.price
|
|
818
824
|
} : {
|
|
819
825
|
_id: product._id.split("___")[0] + "___" + index,
|
|
820
|
-
total
|
|
826
|
+
total,
|
|
821
827
|
price: product.price,
|
|
822
|
-
main_product_selling_price
|
|
828
|
+
main_product_selling_price
|
|
823
829
|
},
|
|
824
830
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
|
|
825
831
|
})
|
|
@@ -854,12 +860,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
854
860
|
const arr = [];
|
|
855
861
|
if (flatItem.type === "main") {
|
|
856
862
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
863
|
+
let total = product.origin_total ?? product.total;
|
|
864
|
+
if ((product.discount_list || []).some((item) => item.type === "promotion")) {
|
|
865
|
+
total = product.total ?? product.origin_total;
|
|
866
|
+
}
|
|
857
867
|
arr.push(
|
|
858
868
|
this.hooks.setProduct(originProduct, {
|
|
859
869
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
860
870
|
quantity: totalQuantity - splitCount,
|
|
861
871
|
_id: product._id.split("___")[0],
|
|
862
|
-
total
|
|
872
|
+
total
|
|
863
873
|
})
|
|
864
874
|
);
|
|
865
875
|
}
|