@pisell/pisellos 2.2.72 → 2.2.73

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.
@@ -833,7 +833,10 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
833
833
  var totalAllocated = allocatedPrices.reduce(function (sum, p) {
834
834
  return sum.plus(p);
835
835
  }, new Decimal(0));
836
- var finalPricePerUnit = this.formatPrice(totalAllocated.div(promoQty));
836
+ // 取促销价和原价的最小值,避免促销反而加价
837
+ var productOriginalAmount = new Decimal(_product.price).mul(promoQty);
838
+ var actualTotal = Decimal.min(totalAllocated, productOriginalAmount);
839
+ var finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
837
840
  result.push(_objectSpread(_objectSpread({}, _product), {}, {
838
841
  quantity: promoQty,
839
842
  finalPrice: finalPricePerUnit,
@@ -843,9 +846,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
843
846
  isSplit: false,
844
847
  matchedBundleIndex: matchedBundleIndex
845
848
  }));
846
- var productOriginalAmount = new Decimal(_product.price).mul(promoQty);
847
849
  originalAmount = originalAmount.plus(productOriginalAmount);
848
- finalAmount = finalAmount.plus(totalAllocated);
850
+ finalAmount = finalAmount.plus(actualTotal);
849
851
  } else if (promoQty === 0 && remainingQty > 0) {
850
852
  // 全部不参与促销:保留原 id,finalPrice = 原价
851
853
  result.push(_objectSpread(_objectSpread({}, _product), {}, {
@@ -865,7 +867,10 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
865
867
  var _totalAllocated = allocatedPrices.reduce(function (sum, p) {
866
868
  return sum.plus(p);
867
869
  }, new Decimal(0));
868
- var _finalPricePerUnit = this.formatPrice(_totalAllocated.div(promoQty));
870
+ // 取促销价和原价的最小值,避免促销反而加价
871
+ var promoOriginalAmount = new Decimal(_product.price).mul(promoQty);
872
+ var _actualTotal = Decimal.min(_totalAllocated, promoOriginalAmount);
873
+ var _finalPricePerUnit = this.formatPrice(_actualTotal.div(promoQty));
869
874
  result.push(_objectSpread(_objectSpread({}, _product), {}, {
870
875
  id: this.generateRandomId(),
871
876
  originalId: _product.id,
@@ -877,9 +882,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
877
882
  matchedBundleIndex: matchedBundleIndex,
878
883
  isSplit: true
879
884
  }));
880
- var promoOriginalAmount = new Decimal(_product.price).mul(promoQty);
881
885
  originalAmount = originalAmount.plus(promoOriginalAmount);
882
- finalAmount = finalAmount.plus(_totalAllocated);
886
+ finalAmount = finalAmount.plus(_actualTotal);
883
887
 
884
888
  // 不参与促销的部分:保留原 id
885
889
  result.push(_objectSpread(_objectSpread({}, _product), {}, {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -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: 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.total,
1079
+ total: total,
1071
1080
  price: product.price,
1072
- main_product_selling_price: product.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: product.origin_total || product.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 total = targetProductTotal;
1208
+ var _total2 = targetProductTotal;
1192
1209
  if (product.options) {
1193
- total = product.options.reduce(function (accumulator, currentValue) {
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(total)).toNumber();
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: 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: total,
1241
+ total: _total2,
1225
1242
  origin_total: productOriginTotal,
1226
1243
  main_product_selling_price: targetProductTotal
1227
1244
  }));
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -573,7 +573,9 @@ var PromotionEvaluator = class {
573
573
  (sum, p) => sum.plus(p),
574
574
  new import_decimal.default(0)
575
575
  );
576
- const finalPricePerUnit = this.formatPrice(totalAllocated.div(promoQty));
576
+ const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
577
+ const actualTotal = import_decimal.default.min(totalAllocated, productOriginalAmount);
578
+ const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
577
579
  result.push({
578
580
  ...product,
579
581
  quantity: promoQty,
@@ -584,9 +586,8 @@ var PromotionEvaluator = class {
584
586
  isSplit: false,
585
587
  matchedBundleIndex
586
588
  });
587
- const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
588
589
  originalAmount = originalAmount.plus(productOriginalAmount);
589
- finalAmount = finalAmount.plus(totalAllocated);
590
+ finalAmount = finalAmount.plus(actualTotal);
590
591
  } else if (promoQty === 0 && remainingQty > 0) {
591
592
  result.push({
592
593
  ...product,
@@ -605,7 +606,9 @@ var PromotionEvaluator = class {
605
606
  (sum, p) => sum.plus(p),
606
607
  new import_decimal.default(0)
607
608
  );
608
- const finalPricePerUnit = this.formatPrice(totalAllocated.div(promoQty));
609
+ const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
610
+ const actualTotal = import_decimal.default.min(totalAllocated, promoOriginalAmount);
611
+ const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
609
612
  result.push({
610
613
  ...product,
611
614
  id: this.generateRandomId(),
@@ -618,9 +621,8 @@ var PromotionEvaluator = class {
618
621
  matchedBundleIndex,
619
622
  isSplit: true
620
623
  });
621
- const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
622
624
  originalAmount = originalAmount.plus(promoOriginalAmount);
623
- finalAmount = finalAmount.plus(totalAllocated);
625
+ finalAmount = finalAmount.plus(actualTotal);
624
626
  result.push({
625
627
  ...product,
626
628
  quantity: remainingQty,
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -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: product.inPromotion ? ((_u = product == null ? void 0 : product._promotion) == null ? void 0 : _u.finalPrice) ?? product.origin_total ?? product.total : product.origin_total || product.total,
826
+ total,
821
827
  price: product.price,
822
- main_product_selling_price: product.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: product.origin_total || product.total
872
+ total
863
873
  })
864
874
  );
865
875
  }
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.72",
4
+ "version": "2.2.73",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",