@pisell/pisellos 2.2.56 → 2.2.57

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.
@@ -2013,10 +2013,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2013
2013
  // 计算有效支付金额:支付金额 + 抹零金额的绝对值
2014
2014
  // 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
2015
2015
  // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
2016
+ // 例2:amount=15,rounding_amount=0.2,有效支付 14.8
2016
2017
  var paymentAmount = new Decimal(payment.amount || 0);
2017
2018
  var roundingAmount = new Decimal(payment.rounding_amount || 0);
2018
- // 如果当前支付项有服务费,还需要减去服务费
2019
- var effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
2019
+ var effectiveAmount = paymentAmount.minus(roundingAmount);
2020
2020
  return sum.plus(effectiveAmount);
2021
2021
  } catch (error) {
2022
2022
  console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=".concat(payment.amount, ", rounding_amount=").concat(payment.rounding_amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
@@ -2044,7 +2044,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2044
2044
  code: p.code,
2045
2045
  amount: p.amount,
2046
2046
  rounding_amount: p.rounding_amount || '0.00',
2047
- effective_amount: new Decimal(p.amount || 0).plus(new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
2047
+ effective_amount: new Decimal(p.amount || 0).minus(new Decimal(p.rounding_amount || 0)).toFixed(2)
2048
2048
  };
2049
2049
  }),
2050
2050
  说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
@@ -1567,8 +1567,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1567
1567
  quantity: 1,
1568
1568
  discount_list: updatedMainDiscountList,
1569
1569
  bundle: newBundleWithDiscount,
1570
- total: newTotalWithDiscount,
1571
- origin_total: newOriginTotalWithDiscount
1570
+ total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
1571
+ origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
1572
1572
  })));
1573
1573
 
1574
1574
  // 第二个:包含原始bundle (qty=原quantity-1)
@@ -1630,6 +1630,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1630
1630
  return accumulator.add(currentPrice.mul(currentNum));
1631
1631
  }, new Decimal(newTotalOriginal)).toNumber();
1632
1632
  }
1633
+ newTotalOriginal = new Decimal(newTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1634
+ newOriginTotalOriginal = new Decimal(newOriginTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1633
1635
 
1634
1636
  // 添加第二个主商品:qty=原quantity-1,包含原始bundle
1635
1637
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
@@ -1734,6 +1736,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1734
1736
  return accumulator.add(currentPrice.mul(currentNum));
1735
1737
  }, new Decimal(newTotal)).toNumber();
1736
1738
  }
1739
+ newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1740
+ newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
1737
1741
 
1738
1742
  // 生成最终的主商品
1739
1743
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
@@ -1029,7 +1029,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1029
1029
  }
1030
1030
  const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
1031
1031
  const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
1032
- const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
1032
+ const effectiveAmount = paymentAmount.minus(roundingAmount);
1033
1033
  return sum.plus(effectiveAmount);
1034
1034
  } catch (error) {
1035
1035
  console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
@@ -1051,7 +1051,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1051
1051
  code: p.code,
1052
1052
  amount: p.amount,
1053
1053
  rounding_amount: p.rounding_amount || "0.00",
1054
- effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
1054
+ effective_amount: new import_decimal.Decimal(p.amount || 0).minus(new import_decimal.Decimal(p.rounding_amount || 0)).toFixed(2)
1055
1055
  })),
1056
1056
  说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
1057
1057
  });
@@ -1270,8 +1270,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1270
1270
  quantity: 1,
1271
1271
  discount_list: updatedMainDiscountList,
1272
1272
  bundle: newBundleWithDiscount,
1273
- total: newTotalWithDiscount,
1274
- origin_total: newOriginTotalWithDiscount
1273
+ total: new import_decimal.default(newTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber(),
1274
+ origin_total: new import_decimal.default(newOriginTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
1275
1275
  })
1276
1276
  );
1277
1277
  if (mainProductQuantity > 1) {
@@ -1329,6 +1329,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1329
1329
  return accumulator.add(currentPrice.mul(currentNum));
1330
1330
  }, new import_decimal.default(newTotalOriginal)).toNumber();
1331
1331
  }
1332
+ newTotalOriginal = new import_decimal.default(newTotalOriginal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1333
+ newOriginTotalOriginal = new import_decimal.default(newOriginTotalOriginal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1332
1334
  result.push(
1333
1335
  this.hooks.setProduct(mainProduct, {
1334
1336
  ...mainProductData,
@@ -1412,6 +1414,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1412
1414
  return accumulator.add(currentPrice.mul(currentNum));
1413
1415
  }, new import_decimal.default(newTotal)).toNumber();
1414
1416
  }
1417
+ newTotal = new import_decimal.default(newTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1418
+ newOriginTotal = new import_decimal.default(newOriginTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1415
1419
  result.push(
1416
1420
  this.hooks.setProduct(mainProduct, {
1417
1421
  ...mainProductData,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.56",
4
+ "version": "2.2.57",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",