@pisell/pisellos 2.2.108 → 2.2.109

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.
@@ -2748,7 +2748,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2748
2748
  key: "processCashPaymentItem",
2749
2749
  value: (function () {
2750
2750
  var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(paymentItem) {
2751
- var cashPayment, remainingAmountStr, remainingAmount, cashAmount, changeAmount, processedPaymentItem;
2751
+ var cashPayment, remainingAmountStr, remainingAmount, cashAmount, roundingAmount, chargeAmount, changeAmount, processedPaymentItem;
2752
2752
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2753
2753
  while (1) switch (_context28.prev = _context28.next) {
2754
2754
  case 0:
@@ -2766,41 +2766,35 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2766
2766
  case 6:
2767
2767
  remainingAmountStr = _context28.sent;
2768
2768
  remainingAmount = new Decimal(remainingAmountStr);
2769
- cashAmount = new Decimal(String(paymentItem.amount)); // 如果现金金额小于等于剩余待付金额,无需找零
2769
+ cashAmount = new Decimal(String(paymentItem.amount));
2770
+ roundingAmount = new Decimal(String(paymentItem.rounding_amount || '0')); // 如果现金金额小于等于剩余待付金额,无需找零
2770
2771
  if (!cashAmount.lte(remainingAmount)) {
2771
- _context28.next = 11;
2772
+ _context28.next = 12;
2772
2773
  break;
2773
2774
  }
2774
2775
  return _context28.abrupt("return", paymentItem);
2775
- case 11:
2776
- // 使用 Decimal.js 安全计算找零金额
2777
- changeAmount = cashAmount.sub(remainingAmount); // 如果还有 rounding_amount 的配置,要判断是否和 changeAmount 相等
2778
- if (!(Number(paymentItem.rounding_amount) > 0)) {
2779
- _context28.next = 18;
2780
- break;
2781
- }
2782
- if (!(Number(paymentItem.rounding_amount) === changeAmount.toNumber())) {
2783
- _context28.next = 17;
2776
+ case 12:
2777
+ // 超付场景使用 rounding 回算应收金额(兼容 UI 已做抹零 + 允许超付)
2778
+ chargeAmount = Decimal.max(remainingAmount.add(roundingAmount), new Decimal(0));
2779
+ if (!cashAmount.lte(chargeAmount)) {
2780
+ _context28.next = 15;
2784
2781
  break;
2785
2782
  }
2786
2783
  return _context28.abrupt("return", paymentItem);
2787
- case 17:
2788
- // 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
2789
- remainingAmount = remainingAmount.add(new Decimal(paymentItem.rounding_amount || '0'));
2790
- case 18:
2791
- // 创建包含找零信息的支付项
2784
+ case 15:
2785
+ changeAmount = cashAmount.sub(chargeAmount); // 创建包含找零信息的支付项
2792
2786
  processedPaymentItem = _objectSpread(_objectSpread({}, paymentItem), {}, {
2793
- amount: remainingAmount.toFixed(2),
2794
- // 将 amount 设置为剩余待付金额,保留2位小数
2787
+ amount: chargeAmount.toFixed(2),
2795
2788
  metadata: _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
2796
2789
  actual_paid_amount: cashAmount.toNumber(),
2797
- // 实付金额
2798
- change_given_amount: changeAmount.toNumber() // 找零金额
2790
+ change_given_amount: changeAmount.toNumber()
2799
2791
  })
2800
2792
  });
2801
2793
  this.logInfo('Cash payment with change processed', {
2802
2794
  originalAmount: cashAmount.toFixed(2),
2803
- chargedAmount: remainingAmount.toFixed(2),
2795
+ remainingAmount: remainingAmount.toFixed(2),
2796
+ roundingAmount: roundingAmount.toFixed(2),
2797
+ chargedAmount: chargeAmount.toFixed(2),
2804
2798
  changeAmount: changeAmount.toFixed(2),
2805
2799
  paymentCode: paymentItem.code,
2806
2800
  paymentType: paymentItem.type,
@@ -2808,21 +2802,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2808
2802
  decimalPrecisionCheck: {
2809
2803
  cashAmountPrecise: cashAmount.toString(),
2810
2804
  remainingAmountPrecise: remainingAmount.toString(),
2805
+ roundingAmountPrecise: roundingAmount.toString(),
2806
+ chargeAmountPrecise: chargeAmount.toString(),
2811
2807
  changeAmountPrecise: changeAmount.toString()
2812
2808
  }
2813
2809
  });
2814
2810
  return _context28.abrupt("return", processedPaymentItem);
2815
- case 23:
2816
- _context28.prev = 23;
2811
+ case 21:
2812
+ _context28.prev = 21;
2817
2813
  _context28.t0 = _context28["catch"](3);
2818
2814
  this.logError('处理现金支付项时出错:', _context28.t0);
2819
2815
  // 出错时返回原始支付项,避免中断支付流程
2820
2816
  return _context28.abrupt("return", paymentItem);
2821
- case 27:
2817
+ case 25:
2822
2818
  case "end":
2823
2819
  return _context28.stop();
2824
2820
  }
2825
- }, _callee28, this, [[3, 23]]);
2821
+ }, _callee28, this, [[3, 21]]);
2826
2822
  }));
2827
2823
  function processCashPaymentItem(_x27) {
2828
2824
  return _processCashPaymentItem.apply(this, arguments);
@@ -1835,36 +1835,34 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1835
1835
  }
1836
1836
  try {
1837
1837
  const remainingAmountStr = await this.calculateRemainingAmountAsync();
1838
- let remainingAmount = new import_decimal.default(remainingAmountStr);
1838
+ const remainingAmount = new import_decimal.default(remainingAmountStr);
1839
1839
  const cashAmount = new import_decimal.default(String(paymentItem.amount));
1840
+ const roundingAmount = new import_decimal.default(String(paymentItem.rounding_amount || "0"));
1840
1841
  if (cashAmount.lte(remainingAmount)) {
1841
1842
  return paymentItem;
1842
1843
  }
1843
- const changeAmount = cashAmount.sub(remainingAmount);
1844
- if (Number(paymentItem.rounding_amount) > 0) {
1845
- if (Number(paymentItem.rounding_amount) === changeAmount.toNumber()) {
1846
- return paymentItem;
1847
- } else {
1848
- remainingAmount = remainingAmount.add(
1849
- new import_decimal.default(paymentItem.rounding_amount || "0")
1850
- );
1851
- }
1844
+ const chargeAmount = import_decimal.default.max(
1845
+ remainingAmount.add(roundingAmount),
1846
+ new import_decimal.default(0)
1847
+ );
1848
+ if (cashAmount.lte(chargeAmount)) {
1849
+ return paymentItem;
1852
1850
  }
1851
+ const changeAmount = cashAmount.sub(chargeAmount);
1853
1852
  const processedPaymentItem = {
1854
1853
  ...paymentItem,
1855
- amount: remainingAmount.toFixed(2),
1856
- // 将 amount 设置为剩余待付金额,保留2位小数
1854
+ amount: chargeAmount.toFixed(2),
1857
1855
  metadata: {
1858
1856
  ...paymentItem.metadata,
1859
1857
  actual_paid_amount: cashAmount.toNumber(),
1860
- // 实付金额
1861
1858
  change_given_amount: changeAmount.toNumber()
1862
- // 找零金额
1863
1859
  }
1864
1860
  };
1865
1861
  this.logInfo("Cash payment with change processed", {
1866
1862
  originalAmount: cashAmount.toFixed(2),
1867
- chargedAmount: remainingAmount.toFixed(2),
1863
+ remainingAmount: remainingAmount.toFixed(2),
1864
+ roundingAmount: roundingAmount.toFixed(2),
1865
+ chargedAmount: chargeAmount.toFixed(2),
1868
1866
  changeAmount: changeAmount.toFixed(2),
1869
1867
  paymentCode: paymentItem.code,
1870
1868
  paymentType: paymentItem.type,
@@ -1872,6 +1870,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1872
1870
  decimalPrecisionCheck: {
1873
1871
  cashAmountPrecise: cashAmount.toString(),
1874
1872
  remainingAmountPrecise: remainingAmount.toString(),
1873
+ roundingAmountPrecise: roundingAmount.toString(),
1874
+ chargeAmountPrecise: chargeAmount.toString(),
1875
1875
  changeAmountPrecise: changeAmount.toString()
1876
1876
  }
1877
1877
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.108",
4
+ "version": "2.2.109",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",