@pisell/pisellos 0.0.449 → 0.0.451

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.
@@ -11,7 +11,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
13
  import { StrategyEngine } from "../../index";
14
- import { processVouchers as _processVouchers, recalculateVouchers as _recalculateVouchers, getApplicableProductIds, getMainProductPrice, getBundleItemPrice, getProductQuantity, getBundleItemIsOriginalPrice } from "./utils";
14
+ import { processVouchers as _processVouchers, recalculateVouchers as _recalculateVouchers, getApplicableProductIds, getMainProductPrice, getBundleItemPrice, getProductQuantity, getBundleItemIsOriginalPrice, getTaxAndFeeRoundingRemainder, getBundleItemTaxAndFeeRoundingRemainder, getProductDiscountDifference, getBundleItemDiscountDifference } from "./utils";
15
15
  import { locales } from "./locales";
16
16
  import Decimal from 'decimal.js';
17
17
  var defaultStrategyMetadataCustom = {
@@ -465,8 +465,8 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
465
465
  // 检查主商品是否适用
466
466
  var isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
467
467
  if (isMainProductApplicable) {
468
- // 计算主商品价格(包含加减价子商品)
469
- total += getMainProductPrice(product, deductTaxAndFee) * productQuantity;
468
+ // 计算主商品价格(包含加减价子商品)= 单价 * 数量 + 舍入余数 - 商品差额
469
+ total += getMainProductPrice(product, deductTaxAndFee) * productQuantity + getTaxAndFeeRoundingRemainder(product, deductTaxAndFee) - getProductDiscountDifference(product);
470
470
  count += productQuantity;
471
471
  }
472
472
 
@@ -478,9 +478,9 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
478
478
  // 检查子商品是否适用
479
479
  var isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
480
480
  if (isBundleItemApplicable) {
481
- // 计算原价子商品价格
481
+ // 计算原价子商品价格 = 总价 + 舍入余数 - 商品差额
482
482
  var bundleItemQuantity = bundleItem.num * productQuantity;
483
- total += getBundleItemPrice(bundleItem, productQuantity, deductTaxAndFee);
483
+ total += getBundleItemPrice(bundleItem, productQuantity, deductTaxAndFee) + getBundleItemTaxAndFeeRoundingRemainder(bundleItem, deductTaxAndFee) - getBundleItemDiscountDifference(bundleItem);
484
484
  count += bundleItemQuantity;
485
485
  }
486
486
  }
@@ -5,7 +5,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- import { getApplicableProductIds, getMainProductPrice, getBundleItemPrice, getProductQuantity, getBundleItemIsOriginalPrice } from "./utils";
8
+ import { getApplicableProductIds, getMainProductPrice, getBundleItemPrice, getProductQuantity, getBundleItemIsOriginalPrice, getTaxAndFeeRoundingRemainder, getBundleItemTaxAndFeeRoundingRemainder, getProductDiscountDifference, getBundleItemDiscountDifference } from "./utils";
9
9
 
10
10
  /**
11
11
  * Wallet Pass 适配器
@@ -149,8 +149,8 @@ var WalletPassAdapter = /*#__PURE__*/function () {
149
149
  // 检查主商品是否适用
150
150
  var isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
151
151
  if (isMainProductApplicable) {
152
- // 计算主商品价格(包含加减价子商品)
153
- total += getMainProductPrice(product, deductTaxAndFee) * productQuantity;
152
+ // 计算主商品价格(包含加减价子商品)= 单价 * 数量 + 舍入余数 - 商品差额
153
+ total += getMainProductPrice(product, deductTaxAndFee) * productQuantity + getTaxAndFeeRoundingRemainder(product, deductTaxAndFee) - getProductDiscountDifference(product);
154
154
  count += productQuantity;
155
155
  }
156
156
 
@@ -162,9 +162,9 @@ var WalletPassAdapter = /*#__PURE__*/function () {
162
162
  // 检查子商品是否适用
163
163
  var isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
164
164
  if (isBundleItemApplicable) {
165
- // 计算原价子商品价格
165
+ // 计算原价子商品价格 = 总价 + 舍入余数 - 商品差额
166
166
  var bundleItemQuantity = bundleItem.num * productQuantity;
167
- total += getBundleItemPrice(bundleItem, productQuantity, deductTaxAndFee);
167
+ total += getBundleItemPrice(bundleItem, productQuantity, deductTaxAndFee) + getBundleItemTaxAndFeeRoundingRemainder(bundleItem, deductTaxAndFee) - getBundleItemDiscountDifference(bundleItem);
168
168
  count += bundleItemQuantity;
169
169
  }
170
170
  }
@@ -64,6 +64,8 @@ export interface Product {
64
64
  surcharge_rounding_remainder?: number;
65
65
  tax_fee_rounding_remainder?: number;
66
66
  main_product_selling_price: number;
67
+ /** 商品折扣差额 */
68
+ product_discount_difference?: number;
67
69
  };
68
70
  is_price_include_tax: 0 | 1;
69
71
  product_bundle: {
@@ -81,6 +83,7 @@ export interface Product {
81
83
  surcharge_fee: number;
82
84
  surcharge_rounding_remainder?: number;
83
85
  tax_fee_rounding_remainder?: number;
86
+ product_discount_difference?: number;
84
87
  };
85
88
  }[];
86
89
  }
@@ -24,18 +24,44 @@ export declare function recalculateVouchers(allVouchers: any[], selectedVouchers
24
24
  selectedWithDetails: any[];
25
25
  };
26
26
  /**
27
- * 获取主商品价格
27
+ * 获取税费和附加费的舍入余数
28
28
  * @param product 商品
29
29
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
30
- * @returns 商品价格
30
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
31
+ */
32
+ export declare const getTaxAndFeeRoundingRemainder: (product: Product, isDeductTaxAndFee: boolean) => number;
33
+ /**
34
+ * 获取主商品的商品差额
35
+ * @param product 商品
36
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
37
+ */
38
+ export declare const getProductDiscountDifference: (product: Product) => number;
39
+ /**
40
+ * 获取主商品价格(单价,不含舍入余数)
41
+ * @param product 商品
42
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
43
+ * @returns 商品单价
31
44
  */
32
45
  export declare const getMainProductPrice: (product: Product, isDeductTaxAndFee: boolean) => number;
33
46
  /**
34
- * 获取套餐子商品价格
47
+ * 获取套餐子商品税费和附加费的舍入余数
48
+ * @param bundleItem 套餐子商品
49
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
50
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
51
+ */
52
+ export declare const getBundleItemTaxAndFeeRoundingRemainder: (bundleItem: any, isDeductTaxAndFee: boolean) => number;
53
+ /**
54
+ * 获取套餐子商品的商品差额
55
+ * @param bundleItem 套餐子商品
56
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
57
+ */
58
+ export declare const getBundleItemDiscountDifference: (bundleItem: any) => number;
59
+ /**
60
+ * 获取套餐子商品价格(不含舍入余数)
35
61
  * @param bundleItem 套餐子商品
36
62
  * @param parentQuantity 父商品数量
37
63
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
38
- * @returns 子商品总价格
64
+ * @returns 子商品总价格(不含舍入余数)
39
65
  */
40
66
  export declare const getBundleItemPrice: (bundleItem: any, parentQuantity: number, isDeductTaxAndFee: boolean) => number;
41
67
  /**
@@ -798,14 +798,48 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
798
798
  }
799
799
 
800
800
  /**
801
- * 获取主商品价格
801
+ * 获取税费和附加费的舍入余数
802
802
  * @param product 商品
803
803
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
804
- * @returns 商品价格
804
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
805
+ */
806
+ export var getTaxAndFeeRoundingRemainder = function getTaxAndFeeRoundingRemainder(product, isDeductTaxAndFee) {
807
+ var _product$metadata2;
808
+ if (!isDeductTaxAndFee) {
809
+ return 0;
810
+ }
811
+
812
+ // 税费舍入余数(如果价格包含税则为0)
813
+ var taxFeeRoundingRemainder = new Decimal(0);
814
+ if (product.is_price_include_tax !== 1) {
815
+ var _product$metadata;
816
+ taxFeeRoundingRemainder = new Decimal((product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.tax_fee_rounding_remainder) || 0);
817
+ }
818
+
819
+ // 附加费舍入余数
820
+ var surchargeFeeRoundingRemainder = new Decimal((product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.surcharge_rounding_remainder) || 0);
821
+ return taxFeeRoundingRemainder.add(surchargeFeeRoundingRemainder).toNumber();
822
+ };
823
+
824
+ /**
825
+ * 获取主商品的商品差额
826
+ * @param product 商品
827
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
828
+ */
829
+ export var getProductDiscountDifference = function getProductDiscountDifference(product) {
830
+ var _product$metadata3;
831
+ return new Decimal((product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.product_discount_difference) || 0).toNumber();
832
+ };
833
+
834
+ /**
835
+ * 获取主商品价格(单价,不含舍入余数)
836
+ * @param product 商品
837
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
838
+ * @returns 商品单价
805
839
  */
806
840
  export var getMainProductPrice = function getMainProductPrice(product, isDeductTaxAndFee) {
807
- var _product$metadata, _product$metadata2, _product$metadata3, _product$metadata4, _product$metadata5;
808
- var mainProductPrice = new Decimal((product === null || product === void 0 ? void 0 : product.main_product_selling_price) || ((_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.main_product_selling_price) || 0);
841
+ var _product$metadata4, _product$metadata5, _product$metadata6;
842
+ var mainProductPrice = new Decimal((product === null || product === void 0 ? void 0 : product.main_product_selling_price) || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_selling_price) || 0);
809
843
  var _iterator6 = _createForOfIteratorHelper((product === null || product === void 0 ? void 0 : product.product_bundle) || []),
810
844
  _step6;
811
845
  try {
@@ -824,14 +858,14 @@ export var getMainProductPrice = function getMainProductPrice(product, isDeductT
824
858
  } finally {
825
859
  _iterator6.f();
826
860
  }
827
- var taxFee = new Decimal((product === null || product === void 0 ? void 0 : product.tax_fee) || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_attached_bundle_tax_fee) || 0).add((product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.tax_fee_rounding_remainder) || 0);
861
+ var taxFee = new Decimal((product === null || product === void 0 ? void 0 : product.tax_fee) || (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.main_product_attached_bundle_tax_fee) || 0);
828
862
  if (product.is_price_include_tax === 1) {
829
863
  taxFee = new Decimal(0);
830
864
  }
831
865
 
832
866
  // 税费
833
867
  // 附加费
834
- var surchargeFee = new Decimal((product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_attached_bundle_surcharge_fee) || 0).add((product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.surcharge_rounding_remainder) || 0);
868
+ var surchargeFee = new Decimal((product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.main_product_attached_bundle_surcharge_fee) || 0);
835
869
 
836
870
  // 税费附加费总额
837
871
  var taxAndFeeTotal = taxFee.add(surchargeFee);
@@ -844,11 +878,45 @@ export var getMainProductPrice = function getMainProductPrice(product, isDeductT
844
878
  };
845
879
 
846
880
  /**
847
- * 获取套餐子商品价格
881
+ * 获取套餐子商品税费和附加费的舍入余数
882
+ * @param bundleItem 套餐子商品
883
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
884
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
885
+ */
886
+ export var getBundleItemTaxAndFeeRoundingRemainder = function getBundleItemTaxAndFeeRoundingRemainder(bundleItem, isDeductTaxAndFee) {
887
+ var _bundleItem$metadata2;
888
+ if (!isDeductTaxAndFee) {
889
+ return 0;
890
+ }
891
+
892
+ // 税费舍入余数(如果价格包含税则为0)
893
+ var taxFeeRoundingRemainder = new Decimal(0);
894
+ if (bundleItem.is_price_include_tax !== 1) {
895
+ var _bundleItem$metadata;
896
+ taxFeeRoundingRemainder = new Decimal(((_bundleItem$metadata = bundleItem.metadata) === null || _bundleItem$metadata === void 0 ? void 0 : _bundleItem$metadata.tax_fee_rounding_remainder) || 0);
897
+ }
898
+
899
+ // 附加费舍入余数
900
+ var surchargeFeeRoundingRemainder = new Decimal(((_bundleItem$metadata2 = bundleItem.metadata) === null || _bundleItem$metadata2 === void 0 ? void 0 : _bundleItem$metadata2.surcharge_rounding_remainder) || 0);
901
+ return taxFeeRoundingRemainder.add(surchargeFeeRoundingRemainder).toNumber();
902
+ };
903
+
904
+ /**
905
+ * 获取套餐子商品的商品差额
906
+ * @param bundleItem 套餐子商品
907
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
908
+ */
909
+ export var getBundleItemDiscountDifference = function getBundleItemDiscountDifference(bundleItem) {
910
+ var _bundleItem$metadata3;
911
+ return new Decimal(((_bundleItem$metadata3 = bundleItem.metadata) === null || _bundleItem$metadata3 === void 0 ? void 0 : _bundleItem$metadata3.product_discount_difference) || 0).toNumber();
912
+ };
913
+
914
+ /**
915
+ * 获取套餐子商品价格(不含舍入余数)
848
916
  * @param bundleItem 套餐子商品
849
917
  * @param parentQuantity 父商品数量
850
918
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
851
- * @returns 子商品总价格
919
+ * @returns 子商品总价格(不含舍入余数)
852
920
  */
853
921
  export var getBundleItemPrice = function getBundleItemPrice(bundleItem, parentQuantity, isDeductTaxAndFee) {
854
922
  var _bundleItem$bundle_se2;
@@ -858,14 +926,14 @@ export var getBundleItemPrice = function getBundleItemPrice(bundleItem, parentQu
858
926
 
859
927
  // 根据 deductTaxAndFee 配置决定是否加上税费和附加费
860
928
  if (isDeductTaxAndFee) {
861
- var _bundleItem$tax_fee, _bundleItem$metadata$, _bundleItem$metadata;
929
+ var _bundleItem$tax_fee, _bundleItem$metadata$, _bundleItem$metadata4;
862
930
  // 税费
863
931
  var taxFee = new Decimal((_bundleItem$tax_fee = bundleItem.tax_fee) !== null && _bundleItem$tax_fee !== void 0 ? _bundleItem$tax_fee : 0).times(totalQuantity);
864
932
  if (bundleItem.is_price_include_tax === 1) {
865
933
  taxFee = new Decimal(0);
866
934
  }
867
935
  // 附加费
868
- var surchargeFee = new Decimal((_bundleItem$metadata$ = (_bundleItem$metadata = bundleItem.metadata) === null || _bundleItem$metadata === void 0 ? void 0 : _bundleItem$metadata.surcharge_fee) !== null && _bundleItem$metadata$ !== void 0 ? _bundleItem$metadata$ : 0).times(totalQuantity);
936
+ var surchargeFee = new Decimal((_bundleItem$metadata$ = (_bundleItem$metadata4 = bundleItem.metadata) === null || _bundleItem$metadata4 === void 0 ? void 0 : _bundleItem$metadata4.surcharge_fee) !== null && _bundleItem$metadata$ !== void 0 ? _bundleItem$metadata$ : 0).times(totalQuantity);
869
937
  bundleItemPrice = bundleItemPrice.add(taxFee).add(surchargeFee);
870
938
  }
871
939
  return bundleItemPrice.toNumber();
@@ -886,6 +954,11 @@ var expandProductsWithBundleItems = function expandProductsWithBundleItems(produ
886
954
  var unitPriceWithTax = getMainProductPrice(product, true);
887
955
  var unitPricePure = getMainProductPrice(product, false);
888
956
 
957
+ // 获取舍入余数(与数量无关,只加一次)
958
+ var roundingRemainderWithTax = getTaxAndFeeRoundingRemainder(product, true);
959
+ // 获取商品差额(与数量无关,计算总价时需要减去)
960
+ var discountDifference = getProductDiscountDifference(product);
961
+
889
962
  // 1. 添加主商品(同时计算含税和不含税两个金额,以及单价和剩余数量)
890
963
  expandedProducts.push(_objectSpread(_objectSpread({}, product), {}, {
891
964
  is_bundle_item: false,
@@ -895,10 +968,10 @@ var expandProductsWithBundleItems = function expandProductsWithBundleItems(produ
895
968
  unitPricePure: new Decimal(unitPricePure),
896
969
  // 剩余可抵扣数量
897
970
  remainingQuantity: productQuantity,
898
- // 含税费的剩余金额
899
- remainingAmountWithTax: new Decimal(unitPriceWithTax).times(productQuantity),
900
- // 纯商品金额(不含税费)
901
- remainingAmountPure: new Decimal(unitPricePure).times(productQuantity)
971
+ // 含税费的剩余金额(单价 * 数量 + 舍入余数 - 商品差额)
972
+ remainingAmountWithTax: new Decimal(unitPriceWithTax).times(productQuantity).add(roundingRemainderWithTax).sub(discountDifference),
973
+ // 纯商品金额(不含税费,也需要减去商品差额)
974
+ remainingAmountPure: new Decimal(unitPricePure).times(productQuantity).sub(discountDifference)
902
975
  }));
903
976
 
904
977
  // 2. 添加原价子商品(作为独立商品项)
@@ -910,6 +983,11 @@ var expandProductsWithBundleItems = function expandProductsWithBundleItems(produ
910
983
  var bundleUnitPriceWithTax = new Decimal(getBundleItemPrice(bundleItem, 1, true)).dividedBy(bundleItem.num);
911
984
  var bundleUnitPricePure = new Decimal(getBundleItemPrice(bundleItem, 1, false)).dividedBy(bundleItem.num);
912
985
 
986
+ // 获取子商品舍入余数(与数量无关,只加一次)
987
+ var bundleRoundingRemainder = getBundleItemTaxAndFeeRoundingRemainder(bundleItem, true);
988
+ // 获取子商品差额(与数量无关,计算总价时需要减去)
989
+ var bundleDiscountDifference = getBundleItemDiscountDifference(bundleItem);
990
+
913
991
  // 原价子商品作为独立商品
914
992
  expandedProducts.push(_objectSpread(_objectSpread({}, bundleItem), {}, {
915
993
  product_id: bundleItem.bundle_product_id,
@@ -923,10 +1001,10 @@ var expandProductsWithBundleItems = function expandProductsWithBundleItems(produ
923
1001
  unitPricePure: bundleUnitPricePure,
924
1002
  // 剩余可抵扣数量
925
1003
  remainingQuantity: bundleQuantity,
926
- // 含税费的剩余金额
927
- remainingAmountWithTax: new Decimal(getBundleItemPrice(bundleItem, productQuantity, true)),
928
- // 纯商品金额(不含税费)
929
- remainingAmountPure: new Decimal(getBundleItemPrice(bundleItem, productQuantity, false))
1004
+ // 含税费的剩余金额(总价 + 舍入余数 - 商品差额)
1005
+ remainingAmountWithTax: new Decimal(getBundleItemPrice(bundleItem, productQuantity, true)).add(bundleRoundingRemainder).sub(bundleDiscountDifference),
1006
+ // 纯商品金额(不含税费,也需要减去商品差额)
1007
+ remainingAmountPure: new Decimal(getBundleItemPrice(bundleItem, productQuantity, false)).sub(bundleDiscountDifference)
930
1008
  }));
931
1009
  }
932
1010
  });
@@ -738,12 +738,8 @@ var getMainProductTotal = function getMainProductTotal(item) {
738
738
  var bundleItem = _step4.value;
739
739
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
740
740
  var _ref10, _bundleItem$bundle_se2;
741
- // 子商品折扣金额
742
- var discountAmount = getDiscountAmount(bundleItem.discount_list);
743
- // 子商品价格
744
- var bundleItemPrice = new Decimal((_ref10 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
745
- // todo: 套餐子商品后不需要处理 子商品价格 - 子商品折扣金额
746
- var bundleItemTotal = bundleItemPrice.minus(discountAmount);
741
+ // IMPORTANT: 套餐子商品如果应用了 discount,bundle_selling_price和 price 其实都已经是折后价格了,不需要单独再减一次
742
+ var bundleItemTotal = new Decimal((_ref10 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
747
743
  total = total.add(bundleItemTotal);
748
744
  }
749
745
  }
@@ -392,7 +392,7 @@ var WalletPassEvaluator = class {
392
392
  const productQuantity = (0, import_utils.getProductQuantity)(product);
393
393
  const isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
394
394
  if (isMainProductApplicable) {
395
- total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity;
395
+ total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity + (0, import_utils.getTaxAndFeeRoundingRemainder)(product, deductTaxAndFee) - (0, import_utils.getProductDiscountDifference)(product);
396
396
  count += productQuantity;
397
397
  }
398
398
  if (product.product_bundle && product.product_bundle.length > 0) {
@@ -405,7 +405,7 @@ var WalletPassEvaluator = class {
405
405
  bundleItem,
406
406
  productQuantity,
407
407
  deductTaxAndFee
408
- );
408
+ ) + (0, import_utils.getBundleItemTaxAndFeeRoundingRemainder)(bundleItem, deductTaxAndFee) - (0, import_utils.getBundleItemDiscountDifference)(bundleItem);
409
409
  count += bundleItemQuantity;
410
410
  }
411
411
  }
@@ -121,7 +121,7 @@ var WalletPassAdapter = class {
121
121
  const productQuantity = (0, import_utils.getProductQuantity)(product);
122
122
  const isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
123
123
  if (isMainProductApplicable) {
124
- total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity;
124
+ total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity + (0, import_utils.getTaxAndFeeRoundingRemainder)(product, deductTaxAndFee) - (0, import_utils.getProductDiscountDifference)(product);
125
125
  count += productQuantity;
126
126
  }
127
127
  if (product.product_bundle && product.product_bundle.length > 0) {
@@ -130,7 +130,7 @@ var WalletPassAdapter = class {
130
130
  const isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
131
131
  if (isBundleItemApplicable) {
132
132
  const bundleItemQuantity = bundleItem.num * productQuantity;
133
- total += (0, import_utils.getBundleItemPrice)(bundleItem, productQuantity, deductTaxAndFee);
133
+ total += (0, import_utils.getBundleItemPrice)(bundleItem, productQuantity, deductTaxAndFee) + (0, import_utils.getBundleItemTaxAndFeeRoundingRemainder)(bundleItem, deductTaxAndFee) - (0, import_utils.getBundleItemDiscountDifference)(bundleItem);
134
134
  count += bundleItemQuantity;
135
135
  }
136
136
  }
@@ -64,6 +64,8 @@ export interface Product {
64
64
  surcharge_rounding_remainder?: number;
65
65
  tax_fee_rounding_remainder?: number;
66
66
  main_product_selling_price: number;
67
+ /** 商品折扣差额 */
68
+ product_discount_difference?: number;
67
69
  };
68
70
  is_price_include_tax: 0 | 1;
69
71
  product_bundle: {
@@ -81,6 +83,7 @@ export interface Product {
81
83
  surcharge_fee: number;
82
84
  surcharge_rounding_remainder?: number;
83
85
  tax_fee_rounding_remainder?: number;
86
+ product_discount_difference?: number;
84
87
  };
85
88
  }[];
86
89
  }
@@ -24,18 +24,44 @@ export declare function recalculateVouchers(allVouchers: any[], selectedVouchers
24
24
  selectedWithDetails: any[];
25
25
  };
26
26
  /**
27
- * 获取主商品价格
27
+ * 获取税费和附加费的舍入余数
28
28
  * @param product 商品
29
29
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
30
- * @returns 商品价格
30
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
31
+ */
32
+ export declare const getTaxAndFeeRoundingRemainder: (product: Product, isDeductTaxAndFee: boolean) => number;
33
+ /**
34
+ * 获取主商品的商品差额
35
+ * @param product 商品
36
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
37
+ */
38
+ export declare const getProductDiscountDifference: (product: Product) => number;
39
+ /**
40
+ * 获取主商品价格(单价,不含舍入余数)
41
+ * @param product 商品
42
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
43
+ * @returns 商品单价
31
44
  */
32
45
  export declare const getMainProductPrice: (product: Product, isDeductTaxAndFee: boolean) => number;
33
46
  /**
34
- * 获取套餐子商品价格
47
+ * 获取套餐子商品税费和附加费的舍入余数
48
+ * @param bundleItem 套餐子商品
49
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
50
+ * @returns 舍入余数(税费 + 附加费的舍入余数)
51
+ */
52
+ export declare const getBundleItemTaxAndFeeRoundingRemainder: (bundleItem: any, isDeductTaxAndFee: boolean) => number;
53
+ /**
54
+ * 获取套餐子商品的商品差额
55
+ * @param bundleItem 套餐子商品
56
+ * @returns 商品差额(与数量无关,计算总价时需要减去)
57
+ */
58
+ export declare const getBundleItemDiscountDifference: (bundleItem: any) => number;
59
+ /**
60
+ * 获取套餐子商品价格(不含舍入余数)
35
61
  * @param bundleItem 套餐子商品
36
62
  * @param parentQuantity 父商品数量
37
63
  * @param isDeductTaxAndFee 是否抵扣税费与附加费
38
- * @returns 子商品总价格
64
+ * @returns 子商品总价格(不含舍入余数)
39
65
  */
40
66
  export declare const getBundleItemPrice: (bundleItem: any, parentQuantity: number, isDeductTaxAndFee: boolean) => number;
41
67
  /**
@@ -30,13 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  getApplicableProductIds: () => getApplicableProductIds,
33
+ getBundleItemDiscountDifference: () => getBundleItemDiscountDifference,
33
34
  getBundleItemIsDiscountPrice: () => getBundleItemIsDiscountPrice,
34
35
  getBundleItemIsMarkupOrDiscountPrice: () => getBundleItemIsMarkupOrDiscountPrice,
35
36
  getBundleItemIsMarkupPrice: () => getBundleItemIsMarkupPrice,
36
37
  getBundleItemIsOriginalPrice: () => getBundleItemIsOriginalPrice,
37
38
  getBundleItemPrice: () => getBundleItemPrice,
39
+ getBundleItemTaxAndFeeRoundingRemainder: () => getBundleItemTaxAndFeeRoundingRemainder,
38
40
  getMainProductPrice: () => getMainProductPrice,
41
+ getProductDiscountDifference: () => getProductDiscountDifference,
39
42
  getProductQuantity: () => getProductQuantity,
43
+ getTaxAndFeeRoundingRemainder: () => getTaxAndFeeRoundingRemainder,
40
44
  processVouchers: () => processVouchers,
41
45
  recalculateVouchers: () => recalculateVouchers
42
46
  });
@@ -546,8 +550,24 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
546
550
  selectedWithDetails
547
551
  };
548
552
  }
553
+ var getTaxAndFeeRoundingRemainder = (product, isDeductTaxAndFee) => {
554
+ var _a, _b;
555
+ if (!isDeductTaxAndFee) {
556
+ return 0;
557
+ }
558
+ let taxFeeRoundingRemainder = new import_decimal.default(0);
559
+ if (product.is_price_include_tax !== 1) {
560
+ taxFeeRoundingRemainder = new import_decimal.default(((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.tax_fee_rounding_remainder) || 0);
561
+ }
562
+ const surchargeFeeRoundingRemainder = new import_decimal.default(((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.surcharge_rounding_remainder) || 0);
563
+ return taxFeeRoundingRemainder.add(surchargeFeeRoundingRemainder).toNumber();
564
+ };
565
+ var getProductDiscountDifference = (product) => {
566
+ var _a;
567
+ return new import_decimal.default(((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.product_discount_difference) || 0).toNumber();
568
+ };
549
569
  var getMainProductPrice = (product, isDeductTaxAndFee) => {
550
- var _a, _b, _c, _d, _e;
570
+ var _a, _b, _c;
551
571
  let mainProductPrice = new import_decimal.default((product == null ? void 0 : product.main_product_selling_price) || ((_a = product.metadata) == null ? void 0 : _a.main_product_selling_price) || 0);
552
572
  for (let bundleItem of (product == null ? void 0 : product.product_bundle) || []) {
553
573
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
@@ -555,17 +575,33 @@ var getMainProductPrice = (product, isDeductTaxAndFee) => {
555
575
  mainProductPrice = mainProductPrice.add(bundleItemPrice.times(bundleItem.num));
556
576
  }
557
577
  }
558
- let taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0).add(((_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c.tax_fee_rounding_remainder) || 0);
578
+ let taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0);
559
579
  if (product.is_price_include_tax === 1) {
560
580
  taxFee = new import_decimal.default(0);
561
581
  }
562
- const surchargeFee = new import_decimal.default(((_d = product == null ? void 0 : product.metadata) == null ? void 0 : _d.main_product_attached_bundle_surcharge_fee) || 0).add(((_e = product == null ? void 0 : product.metadata) == null ? void 0 : _e.surcharge_rounding_remainder) || 0);
582
+ const surchargeFee = new import_decimal.default(((_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c.main_product_attached_bundle_surcharge_fee) || 0);
563
583
  const taxAndFeeTotal = taxFee.add(surchargeFee);
564
584
  if (isDeductTaxAndFee) {
565
585
  mainProductPrice = mainProductPrice.add(taxAndFeeTotal);
566
586
  }
567
587
  return mainProductPrice.toNumber();
568
588
  };
589
+ var getBundleItemTaxAndFeeRoundingRemainder = (bundleItem, isDeductTaxAndFee) => {
590
+ var _a, _b;
591
+ if (!isDeductTaxAndFee) {
592
+ return 0;
593
+ }
594
+ let taxFeeRoundingRemainder = new import_decimal.default(0);
595
+ if (bundleItem.is_price_include_tax !== 1) {
596
+ taxFeeRoundingRemainder = new import_decimal.default(((_a = bundleItem.metadata) == null ? void 0 : _a.tax_fee_rounding_remainder) || 0);
597
+ }
598
+ const surchargeFeeRoundingRemainder = new import_decimal.default(((_b = bundleItem.metadata) == null ? void 0 : _b.surcharge_rounding_remainder) || 0);
599
+ return taxFeeRoundingRemainder.add(surchargeFeeRoundingRemainder).toNumber();
600
+ };
601
+ var getBundleItemDiscountDifference = (bundleItem) => {
602
+ var _a;
603
+ return new import_decimal.default(((_a = bundleItem.metadata) == null ? void 0 : _a.product_discount_difference) || 0).toNumber();
604
+ };
569
605
  var getBundleItemPrice = (bundleItem, parentQuantity, isDeductTaxAndFee) => {
570
606
  var _a;
571
607
  const totalQuantity = bundleItem.num * parentQuantity;
@@ -586,6 +622,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
586
622
  const productQuantity = getProductQuantity(product);
587
623
  const unitPriceWithTax = getMainProductPrice(product, true);
588
624
  const unitPricePure = getMainProductPrice(product, false);
625
+ const roundingRemainderWithTax = getTaxAndFeeRoundingRemainder(product, true);
626
+ const discountDifference = getProductDiscountDifference(product);
589
627
  expandedProducts.push({
590
628
  ...product,
591
629
  is_bundle_item: false,
@@ -595,10 +633,10 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
595
633
  unitPricePure: new import_decimal.default(unitPricePure),
596
634
  // 剩余可抵扣数量
597
635
  remainingQuantity: productQuantity,
598
- // 含税费的剩余金额
599
- remainingAmountWithTax: new import_decimal.default(unitPriceWithTax).times(productQuantity),
600
- // 纯商品金额(不含税费)
601
- remainingAmountPure: new import_decimal.default(unitPricePure).times(productQuantity)
636
+ // 含税费的剩余金额(单价 * 数量 + 舍入余数 - 商品差额)
637
+ remainingAmountWithTax: new import_decimal.default(unitPriceWithTax).times(productQuantity).add(roundingRemainderWithTax).sub(discountDifference),
638
+ // 纯商品金额(不含税费,也需要减去商品差额)
639
+ remainingAmountPure: new import_decimal.default(unitPricePure).times(productQuantity).sub(discountDifference)
602
640
  });
603
641
  if (product.product_bundle && product.product_bundle.length > 0) {
604
642
  product.product_bundle.forEach((bundleItem) => {
@@ -606,6 +644,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
606
644
  const bundleQuantity = bundleItem.num * productQuantity;
607
645
  const bundleUnitPriceWithTax = new import_decimal.default(getBundleItemPrice(bundleItem, 1, true)).dividedBy(bundleItem.num);
608
646
  const bundleUnitPricePure = new import_decimal.default(getBundleItemPrice(bundleItem, 1, false)).dividedBy(bundleItem.num);
647
+ const bundleRoundingRemainder = getBundleItemTaxAndFeeRoundingRemainder(bundleItem, true);
648
+ const bundleDiscountDifference = getBundleItemDiscountDifference(bundleItem);
609
649
  expandedProducts.push({
610
650
  ...bundleItem,
611
651
  product_id: bundleItem.bundle_product_id,
@@ -619,10 +659,10 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
619
659
  unitPricePure: bundleUnitPricePure,
620
660
  // 剩余可抵扣数量
621
661
  remainingQuantity: bundleQuantity,
622
- // 含税费的剩余金额
623
- remainingAmountWithTax: new import_decimal.default(getBundleItemPrice(bundleItem, productQuantity, true)),
624
- // 纯商品金额(不含税费)
625
- remainingAmountPure: new import_decimal.default(getBundleItemPrice(bundleItem, productQuantity, false))
662
+ // 含税费的剩余金额(总价 + 舍入余数 - 商品差额)
663
+ remainingAmountWithTax: new import_decimal.default(getBundleItemPrice(bundleItem, productQuantity, true)).add(bundleRoundingRemainder).sub(bundleDiscountDifference),
664
+ // 纯商品金额(不含税费,也需要减去商品差额)
665
+ remainingAmountPure: new import_decimal.default(getBundleItemPrice(bundleItem, productQuantity, false)).sub(bundleDiscountDifference)
626
666
  });
627
667
  }
628
668
  });
@@ -648,13 +688,17 @@ var getBundleItemIsMarkupOrDiscountPrice = (item) => {
648
688
  // Annotate the CommonJS export names for ESM import in node:
649
689
  0 && (module.exports = {
650
690
  getApplicableProductIds,
691
+ getBundleItemDiscountDifference,
651
692
  getBundleItemIsDiscountPrice,
652
693
  getBundleItemIsMarkupOrDiscountPrice,
653
694
  getBundleItemIsMarkupPrice,
654
695
  getBundleItemIsOriginalPrice,
655
696
  getBundleItemPrice,
697
+ getBundleItemTaxAndFeeRoundingRemainder,
656
698
  getMainProductPrice,
699
+ getProductDiscountDifference,
657
700
  getProductQuantity,
701
+ getTaxAndFeeRoundingRemainder,
658
702
  processVouchers,
659
703
  recalculateVouchers
660
704
  });
@@ -458,9 +458,7 @@ var getMainProductTotal = (item) => {
458
458
  }
459
459
  for (let bundleItem of (item == null ? void 0 : item.bundle) || []) {
460
460
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
461
- const discountAmount = getDiscountAmount(bundleItem.discount_list);
462
- const bundleItemPrice = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
463
- const bundleItemTotal = bundleItemPrice.minus(discountAmount);
461
+ const bundleItemTotal = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
464
462
  total = total.add(bundleItemTotal);
465
463
  }
466
464
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.449",
4
+ "version": "0.0.451",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",