@pisell/pisellos 0.0.483 → 0.0.484
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/modules/Rules/index.js +32 -23
- package/lib/modules/Rules/index.js +16 -11
- package/package.json +1 -1
|
@@ -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; }
|
|
@@ -943,15 +944,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
943
944
|
};
|
|
944
945
|
var optionDiscountAmount = 0;
|
|
945
946
|
var discountedOptions = options.map(function (option) {
|
|
946
|
-
var _ref6, _option$num, _option$
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
var
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
947
|
+
var _ref6, _ref7, _option$_original_pri, _ref8, _option$num, _rest$price, _option$_original_pri2;
|
|
948
|
+
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
949
|
+
var rawUnit = (_ref6 = (_ref7 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref7 !== void 0 ? _ref7 : option.price) !== null && _ref6 !== void 0 ? _ref6 : option.add_price;
|
|
950
|
+
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
951
|
+
if (baseUnitNum <= 0) return option;
|
|
952
|
+
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
953
|
+
var optQty = Number((_ref8 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref8 !== void 0 ? _ref8 : 1);
|
|
954
|
+
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
955
|
+
var _original_add_price = option._original_add_price,
|
|
956
|
+
rest = _objectWithoutProperties(option, _excluded);
|
|
957
|
+
var tmpl = (_rest$price = rest.price) !== null && _rest$price !== void 0 ? _rest$price : rest.add_price;
|
|
958
|
+
var nextPrice = typeof tmpl === 'string' ? String(discountedPrice) : discountedPrice;
|
|
959
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
960
|
+
_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,
|
|
961
|
+
price: nextPrice
|
|
955
962
|
});
|
|
956
963
|
});
|
|
957
964
|
return {
|
|
@@ -962,11 +969,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
962
969
|
var restoreOptionPrices = function restoreOptionPrices(options) {
|
|
963
970
|
if (!(options !== null && options !== void 0 && options.length)) return options;
|
|
964
971
|
return options.map(function (option) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
972
|
+
var orig = option._original_price !== undefined ? option._original_price : option._original_add_price;
|
|
973
|
+
if (orig !== undefined) {
|
|
974
|
+
var _original_price = option._original_price,
|
|
975
|
+
_original_add_price = option._original_add_price,
|
|
976
|
+
rest = _objectWithoutProperties(option, _excluded2);
|
|
968
977
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
969
|
-
|
|
978
|
+
price: orig
|
|
970
979
|
});
|
|
971
980
|
}
|
|
972
981
|
return option;
|
|
@@ -975,9 +984,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
975
984
|
var getOptionTotal = function getOptionTotal(options) {
|
|
976
985
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
977
986
|
return options.reduce(function (sum, opt) {
|
|
978
|
-
var
|
|
979
|
-
var unit = Number((
|
|
980
|
-
var n = Number((
|
|
987
|
+
var _ref9, _opt$price, _ref10, _opt$num;
|
|
988
|
+
var unit = Number((_ref9 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref9 !== void 0 ? _ref9 : 0);
|
|
989
|
+
var n = Number((_ref10 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref10 !== void 0 ? _ref10 : 1);
|
|
981
990
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
982
991
|
}, 0);
|
|
983
992
|
};
|
|
@@ -1124,8 +1133,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1124
1133
|
var _product$discount_lis5, _product12, _product12$every;
|
|
1125
1134
|
// 主商品:判断自身是否手动折扣
|
|
1126
1135
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1127
|
-
var
|
|
1128
|
-
return !((
|
|
1136
|
+
var _ref11;
|
|
1137
|
+
return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
|
|
1129
1138
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
1130
1139
|
return item.type === 'product';
|
|
1131
1140
|
})));
|
|
@@ -1138,8 +1147,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1138
1147
|
if (parentProduct) {
|
|
1139
1148
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
1140
1149
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1141
|
-
var
|
|
1142
|
-
return !((
|
|
1150
|
+
var _ref12;
|
|
1151
|
+
return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
|
|
1143
1152
|
}) && (!((_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) {
|
|
1144
1153
|
return item.type === 'product';
|
|
1145
1154
|
})));
|
|
@@ -1232,8 +1241,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1232
1241
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1233
1242
|
}))]);
|
|
1234
1243
|
} else {
|
|
1235
|
-
var
|
|
1236
|
-
var total = product.inPromotion ? (
|
|
1244
|
+
var _ref13, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1245
|
+
var total = product.inPromotion ? (_ref13 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref13 !== void 0 ? _ref13 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1237
1246
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1238
1247
|
if ((product.discount_list || []).some(function (item) {
|
|
1239
1248
|
return item.type === 'promotion';
|
|
@@ -641,16 +641,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
641
641
|
return { discountedOptions: options2, optionDiscountAmount: 0 };
|
|
642
642
|
let optionDiscountAmount = 0;
|
|
643
643
|
const discountedOptions = options2.map((option) => {
|
|
644
|
-
const
|
|
645
|
-
|
|
644
|
+
const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
|
|
645
|
+
const baseUnitNum = Number(rawUnit ?? 0);
|
|
646
|
+
if (baseUnitNum <= 0)
|
|
646
647
|
return option;
|
|
647
|
-
const discountedPrice = (0, import_utils.getDiscountAmount)(discount,
|
|
648
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
|
|
648
649
|
const optQty = Number(option.num ?? option.quantity ?? 1);
|
|
649
|
-
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(
|
|
650
|
+
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
651
|
+
const { _original_add_price, ...rest } = option;
|
|
652
|
+
const tmpl = rest.price ?? rest.add_price;
|
|
653
|
+
const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
|
|
650
654
|
return {
|
|
651
|
-
...
|
|
652
|
-
|
|
653
|
-
|
|
655
|
+
...rest,
|
|
656
|
+
_original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
|
|
657
|
+
price: nextPrice
|
|
654
658
|
};
|
|
655
659
|
});
|
|
656
660
|
return { discountedOptions, optionDiscountAmount };
|
|
@@ -659,9 +663,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
659
663
|
if (!(options2 == null ? void 0 : options2.length))
|
|
660
664
|
return options2;
|
|
661
665
|
return options2.map((option) => {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
666
|
+
const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
|
|
667
|
+
if (orig !== void 0) {
|
|
668
|
+
const { _original_price, _original_add_price, ...rest } = option;
|
|
669
|
+
return { ...rest, price: orig };
|
|
665
670
|
}
|
|
666
671
|
return option;
|
|
667
672
|
});
|
|
@@ -670,7 +675,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
670
675
|
if (!(options2 == null ? void 0 : options2.length))
|
|
671
676
|
return 0;
|
|
672
677
|
return options2.reduce((sum, opt) => {
|
|
673
|
-
const unit = Number(opt.
|
|
678
|
+
const unit = Number(opt.price ?? opt.add_price ?? 0);
|
|
674
679
|
const n = Number(opt.num ?? opt.quantity ?? 1);
|
|
675
680
|
return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
|
|
676
681
|
}, 0);
|