@pisell/pisellos 0.0.318 → 0.0.319

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.
@@ -1808,7 +1808,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1808
1808
  // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
1809
1809
  var paymentAmount = new Decimal(payment.amount || 0);
1810
1810
  var roundingAmount = new Decimal(payment.rounding_amount || 0);
1811
- var effectiveAmount = paymentAmount.plus(roundingAmount.abs());
1811
+ var effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
1812
1812
  return sum.plus(effectiveAmount);
1813
1813
  } catch (error) {
1814
1814
  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"));
@@ -1836,7 +1836,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1836
1836
  code: p.code,
1837
1837
  amount: p.amount,
1838
1838
  rounding_amount: p.rounding_amount || '0.00',
1839
- effective_amount: new Decimal(p.amount || 0).plus(new Decimal(p.rounding_amount || 0).abs()).toFixed(2)
1839
+ effective_amount: new Decimal(p.amount || 0).plus(new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
1840
1840
  };
1841
1841
  }),
1842
1842
  说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
@@ -740,7 +740,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
740
740
  });
741
741
  paidAmount = activePayments.reduce(function (sum, p) {
742
742
  var amt = new Decimal(p.amount || '0');
743
- var rounding = new Decimal(p.rounding_amount || '0').abs();
743
+ var rounding = new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || '0').abs();
744
744
  return sum.plus(amt).plus(rounding);
745
745
  }, new Decimal(0));
746
746
  remaining = Decimal.max(0, totalAmount.minus(paidAmount)).toFixed(2); // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
@@ -795,7 +795,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
795
795
  // 需要减去已经同步给后端的支付过的钱
796
796
  syncedAmount = activePayments.reduce(function (sum, p) {
797
797
  var amt = new Decimal(p.amount || '0');
798
- var rounding = new Decimal(p.rounding_amount || '0').abs();
798
+ var rounding = new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || '0').abs();
799
799
  return sum.plus(amt).plus(rounding);
800
800
  }, new Decimal(0));
801
801
  remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2); // 要计算一个总价的差值和一个定金的差值,如果定金的差值>0,则需要使用定金的差值,否则使用总价的差值
@@ -2777,7 +2777,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2777
2777
  // 使用 Decimal.js 计算实际支付有效金额:
2778
2778
  // 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
2779
2779
  // 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
2780
- var effectiveAmount = amount.add(roundingAmount.abs());
2780
+ var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
2781
2781
  console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code), {
2782
2782
  originalAmount: amount.toFixed(2),
2783
2783
  roundingAmount: roundingAmount.toFixed(2),
@@ -2960,7 +2960,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2960
2960
  }
2961
2961
  var amount = new Decimal(item.amount || '0');
2962
2962
  var roundingAmount = new Decimal(item.rounding_amount || '0');
2963
- return sum.add(amount.add(roundingAmount.abs()));
2963
+ return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
2964
2964
  }, new Decimal(0));
2965
2965
  if (!depositPaidAmount.gte((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount)) {
2966
2966
  _context34.next = 11;
@@ -3107,7 +3107,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3107
3107
  code: p.code,
3108
3108
  amount: p.amount,
3109
3109
  rounding_amount: p.rounding_amount,
3110
- effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(p.rounding_amount || '0'))).toFixed(2),
3110
+ effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
3111
3111
  voucher_id: p.voucher_id,
3112
3112
  status: p.status
3113
3113
  };
@@ -3875,17 +3875,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3875
3875
  key: "roundAmountAsync",
3876
3876
  value: (function () {
3877
3877
  var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(amount) {
3878
- var _this$otherParams$ord, _this$otherParams$ord2;
3879
- var result;
3878
+ var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
3879
+ var cashManualPayment, result;
3880
3880
  return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3881
3881
  while (1) switch (_context40.prev = _context40.next) {
3882
3882
  case 0:
3883
- _context40.next = 2;
3883
+ // 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
3884
+ cashManualPayment = this.store.paymentMethods.find(function (p) {
3885
+ return p.code === 'CASHMANUAL';
3886
+ });
3887
+ if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
3888
+ _context40.next = 3;
3889
+ break;
3890
+ }
3891
+ return _context40.abrupt("return", {
3892
+ originalAmount: amount.toString(),
3893
+ roundedAmount: amount.toString(),
3894
+ roundingDifference: '0.00'
3895
+ });
3896
+ case 3:
3897
+ _context40.next = 5;
3884
3898
  return this.payment.roundAmountAsync(amount, (_this$otherParams$ord = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord === void 0 ? void 0 : _this$otherParams$ord.interval, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.type);
3885
- case 2:
3899
+ case 5:
3886
3900
  result = _context40.sent;
3887
3901
  return _context40.abrupt("return", result);
3888
- case 4:
3902
+ case 7:
3889
3903
  case "end":
3890
3904
  return _context40.stop();
3891
3905
  }
@@ -913,7 +913,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
913
913
  }
914
914
  const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
915
915
  const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
916
- const effectiveAmount = paymentAmount.plus(roundingAmount.abs());
916
+ const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
917
917
  return sum.plus(effectiveAmount);
918
918
  } catch (error) {
919
919
  console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
@@ -935,7 +935,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
935
935
  code: p.code,
936
936
  amount: p.amount,
937
937
  rounding_amount: p.rounding_amount || "0.00",
938
- effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(p.rounding_amount || 0).abs()).toFixed(2)
938
+ 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)
939
939
  })),
940
940
  说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
941
941
  });
@@ -475,7 +475,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
475
475
  );
476
476
  const paidAmount = activePayments.reduce((sum, p) => {
477
477
  const amt = new import_decimal.default(p.amount || "0");
478
- const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
478
+ const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
479
479
  return sum.plus(amt).plus(rounding);
480
480
  }, new import_decimal.default(0));
481
481
  const remaining = import_decimal.default.max(0, totalAmount.minus(paidAmount)).toFixed(
@@ -524,7 +524,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
524
524
  });
525
525
  const syncedAmount = activePayments.reduce((sum, p) => {
526
526
  const amt = new import_decimal.default(p.amount || "0");
527
- const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
527
+ const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
528
528
  return sum.plus(amt).plus(rounding);
529
529
  }, new import_decimal.default(0));
530
530
  const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
@@ -1773,7 +1773,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1773
1773
  const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
1774
1774
  const amount = new import_decimal.default(payment.amount || "0");
1775
1775
  const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
1776
- const effectiveAmount = amount.add(roundingAmount.abs());
1776
+ const effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
1777
1777
  console.log(`[Checkout] 计算支付项: ${payment.code}`, {
1778
1778
  originalAmount: amount.toFixed(2),
1779
1779
  roundingAmount: roundingAmount.toFixed(2),
@@ -1864,7 +1864,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1864
1864
  }
1865
1865
  const amount = new import_decimal.default(item.amount || "0");
1866
1866
  const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
1867
- return sum.add(amount.add(roundingAmount.abs()));
1867
+ return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
1868
1868
  }, new import_decimal.default(0));
1869
1869
  if (depositPaidAmount.gte((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount)) {
1870
1870
  this.store.currentOrder = {
@@ -1950,7 +1950,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1950
1950
  code: p.code,
1951
1951
  amount: p.amount,
1952
1952
  rounding_amount: p.rounding_amount,
1953
- effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(p.rounding_amount || "0"))).toFixed(2),
1953
+ effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
1954
1954
  voucher_id: p.voucher_id,
1955
1955
  status: p.status
1956
1956
  }))
@@ -2433,11 +2433,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2433
2433
  * @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
2434
2434
  */
2435
2435
  async roundAmountAsync(amount) {
2436
- var _a, _b;
2436
+ var _a, _b, _c;
2437
+ const cashManualPayment = this.store.paymentMethods.find((p) => p.code === "CASHMANUAL");
2438
+ if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
2439
+ return {
2440
+ originalAmount: amount.toString(),
2441
+ roundedAmount: amount.toString(),
2442
+ roundingDifference: "0.00"
2443
+ };
2444
+ }
2437
2445
  const result = await this.payment.roundAmountAsync(
2438
2446
  amount,
2439
- (_a = this.otherParams.order_rounding_setting) == null ? void 0 : _a.interval,
2440
- (_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.type
2447
+ (_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
2448
+ (_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
2441
2449
  );
2442
2450
  return result;
2443
2451
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.318",
4
+ "version": "0.0.319",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",