@pisell/pisellos 2.2.103 → 2.2.104

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.
@@ -1,9 +0,0 @@
1
- // 导出评估器
2
- export { PromotionEvaluator } from "./evaluator";
3
-
4
- // 导出适配器
5
- export { PromotionAdapter } from "./adapter";
6
- export { default } from "./adapter";
7
-
8
- // 导出策略配置示例常量
9
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -1,4 +1,5 @@
1
- var _excluded = ["_original_add_price"];
1
+ var _excluded = ["_original_add_price"],
2
+ _excluded2 = ["_original_price", "_original_add_price"];
2
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -839,15 +840,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
839
840
  };
840
841
  var optionDiscountAmount = 0;
841
842
  var discountedOptions = options.map(function (option) {
842
- var _ref5, _option$num, _option$_original_add;
843
- var addPrice = Number(option.add_price || 0);
844
- if (addPrice <= 0) return option;
845
- var discountedPrice = getDiscountAmount(discount, addPrice, addPrice);
846
- var optQty = Number((_ref5 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref5 !== void 0 ? _ref5 : 1);
847
- optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(addPrice).minus(discountedPrice).mul(optQty)).toNumber();
848
- return _objectSpread(_objectSpread({}, option), {}, {
849
- _original_add_price: (_option$_original_add = option._original_add_price) !== null && _option$_original_add !== void 0 ? _option$_original_add : option.add_price,
850
- add_price: discountedPrice
843
+ var _ref5, _ref6, _option$_original_pri, _ref7, _option$num, _rest$price, _option$_original_pri2;
844
+ // 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
845
+ var rawUnit = (_ref5 = (_ref6 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref6 !== void 0 ? _ref6 : option.price) !== null && _ref5 !== void 0 ? _ref5 : option.add_price;
846
+ var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
847
+ if (baseUnitNum <= 0) return option;
848
+ var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
849
+ var optQty = Number((_ref7 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref7 !== void 0 ? _ref7 : 1);
850
+ optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
851
+ var _original_add_price = option._original_add_price,
852
+ rest = _objectWithoutProperties(option, _excluded);
853
+ var tmpl = (_rest$price = rest.price) !== null && _rest$price !== void 0 ? _rest$price : rest.add_price;
854
+ var nextPrice = typeof tmpl === 'string' ? String(discountedPrice) : discountedPrice;
855
+ return _objectSpread(_objectSpread({}, rest), {}, {
856
+ _original_price: (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : _original_add_price !== undefined ? _original_add_price : rawUnit,
857
+ price: nextPrice
851
858
  });
852
859
  });
853
860
  return {
@@ -858,11 +865,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
858
865
  var restoreOptionPrices = function restoreOptionPrices(options) {
859
866
  if (!(options !== null && options !== void 0 && options.length)) return options;
860
867
  return options.map(function (option) {
861
- if (option._original_add_price !== undefined) {
862
- var _original_add_price = option._original_add_price,
863
- rest = _objectWithoutProperties(option, _excluded);
868
+ var orig = option._original_price !== undefined ? option._original_price : option._original_add_price;
869
+ if (orig !== undefined) {
870
+ var _original_price = option._original_price,
871
+ _original_add_price = option._original_add_price,
872
+ rest = _objectWithoutProperties(option, _excluded2);
864
873
  return _objectSpread(_objectSpread({}, rest), {}, {
865
- add_price: _original_add_price
874
+ price: orig
866
875
  });
867
876
  }
868
877
  return option;
@@ -871,9 +880,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
871
880
  var getOptionTotal = function getOptionTotal(options) {
872
881
  if (!(options !== null && options !== void 0 && options.length)) return 0;
873
882
  return options.reduce(function (sum, opt) {
874
- var _ref6, _opt$add_price, _ref7, _opt$num;
875
- var unit = Number((_ref6 = (_opt$add_price = opt.add_price) !== null && _opt$add_price !== void 0 ? _opt$add_price : opt.price) !== null && _ref6 !== void 0 ? _ref6 : 0);
876
- var n = Number((_ref7 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref7 !== void 0 ? _ref7 : 1);
883
+ var _ref8, _opt$price, _ref9, _opt$num;
884
+ var unit = Number((_ref8 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref8 !== void 0 ? _ref8 : 0);
885
+ var n = Number((_ref9 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref9 !== void 0 ? _ref9 : 1);
877
886
  return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
878
887
  }, 0);
879
888
  };
@@ -1007,8 +1016,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1007
1016
  var _product$discount_lis5, _product11, _product11$every;
1008
1017
  // 主商品:判断自身是否手动折扣
1009
1018
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
1010
- var _ref8;
1011
- return !((_ref8 = item.discount_list || []) !== null && _ref8 !== void 0 && _ref8.length);
1019
+ var _ref10;
1020
+ return !((_ref10 = item.discount_list || []) !== null && _ref10 !== void 0 && _ref10.length);
1012
1021
  }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
1013
1022
  return item.type === 'product';
1014
1023
  })));
@@ -1021,8 +1030,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1021
1030
  if (parentProduct) {
1022
1031
  var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
1023
1032
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1024
- var _ref9;
1025
- return !((_ref9 = item.discount_list || []) !== null && _ref9 !== void 0 && _ref9.length);
1033
+ var _ref11;
1034
+ return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
1026
1035
  }) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
1027
1036
  return item.type === 'product';
1028
1037
  })));
@@ -1115,8 +1124,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1115
1124
  discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
1116
1125
  }))]);
1117
1126
  } else {
1118
- var _ref10, _product$_promotion$f, _product12, _product$origin_total;
1119
- var total = product.inPromotion ? (_ref10 = (_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 && _ref10 !== void 0 ? _ref10 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1127
+ var _ref12, _product$_promotion$f, _product12, _product$origin_total;
1128
+ var total = product.inPromotion ? (_ref12 = (_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 && _ref12 !== void 0 ? _ref12 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1120
1129
  var main_product_selling_price = product.price;
1121
1130
  if ((product.discount_list || []).some(function (item) {
1122
1131
  return item.type === 'promotion';
@@ -593,16 +593,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
593
593
  return { discountedOptions: options2, optionDiscountAmount: 0 };
594
594
  let optionDiscountAmount = 0;
595
595
  const discountedOptions = options2.map((option) => {
596
- const addPrice = Number(option.add_price || 0);
597
- if (addPrice <= 0)
596
+ const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
597
+ const baseUnitNum = Number(rawUnit ?? 0);
598
+ if (baseUnitNum <= 0)
598
599
  return option;
599
- const discountedPrice = (0, import_utils.getDiscountAmount)(discount, addPrice, addPrice);
600
+ const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
600
601
  const optQty = Number(option.num ?? option.quantity ?? 1);
601
- optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(addPrice).minus(discountedPrice).mul(optQty)).toNumber();
602
+ optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
603
+ const { _original_add_price, ...rest } = option;
604
+ const tmpl = rest.price ?? rest.add_price;
605
+ const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
602
606
  return {
603
- ...option,
604
- _original_add_price: option._original_add_price ?? option.add_price,
605
- add_price: discountedPrice
607
+ ...rest,
608
+ _original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
609
+ price: nextPrice
606
610
  };
607
611
  });
608
612
  return { discountedOptions, optionDiscountAmount };
@@ -611,9 +615,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
611
615
  if (!(options2 == null ? void 0 : options2.length))
612
616
  return options2;
613
617
  return options2.map((option) => {
614
- if (option._original_add_price !== void 0) {
615
- const { _original_add_price, ...rest } = option;
616
- return { ...rest, add_price: _original_add_price };
618
+ const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
619
+ if (orig !== void 0) {
620
+ const { _original_price, _original_add_price, ...rest } = option;
621
+ return { ...rest, price: orig };
617
622
  }
618
623
  return option;
619
624
  });
@@ -622,7 +627,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
622
627
  if (!(options2 == null ? void 0 : options2.length))
623
628
  return 0;
624
629
  return options2.reduce((sum, opt) => {
625
- const unit = Number(opt.add_price ?? opt.price ?? 0);
630
+ const unit = Number(opt.price ?? opt.add_price ?? 0);
626
631
  const n = Number(opt.num ?? opt.quantity ?? 1);
627
632
  return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
628
633
  }, 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.103",
4
+ "version": "2.2.104",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",