@pisell/pisellos 0.0.306 → 0.0.308

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.
@@ -1068,13 +1068,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1068
1068
  // 🔒 支付锁检查:如果订单待付金额已经为0,不允许继续添加支付项
1069
1069
  expectAmount = new Decimal(order.expect_amount);
1070
1070
  paidDepositAmount = order.payment.reduce(function (sum, payment) {
1071
- if (payment.order_payment_type === 'deposit') {
1071
+ if (payment.order_payment_type === 'deposit' && payment.status !== 'voided') {
1072
1072
  return sum.plus(new Decimal(payment.amount));
1073
1073
  }
1074
1074
  return sum;
1075
1075
  }, new Decimal(0));
1076
- expectedDepositAmount = new Decimal(order.deposit_amount || '0').sub(paidDepositAmount); // 有一种特殊情况,订单金额为 0,但是定金金额>0,且此时是定金状态的,允许添加支付项
1077
- if (!(expectAmount.lte(0) && expectedDepositAmount.lte(0))) {
1076
+ expectedDepositAmount = new Decimal(order.deposit_amount || '0').sub(paidDepositAmount); // 有一种特殊情况,订单金额为 0,但是定金金额不等于0,且此时是定金状态的,允许添加支付项
1077
+ if (!(expectAmount.lte(0) && expectedDepositAmount.eq(0))) {
1078
1078
  _context13.next = 15;
1079
1079
  break;
1080
1080
  }
@@ -677,7 +677,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
677
677
  value: (function () {
678
678
  var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
679
679
  var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
680
- var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, isNeedDeposit, created;
680
+ var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, syncedAmount, remainingExpectAmount, isNeedDeposit, created;
681
681
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
682
682
  while (1) switch (_context10.prev = _context10.next) {
683
683
  case 0:
@@ -730,7 +730,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
730
730
  return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
731
731
  });
732
732
  if (!existingOrder) {
733
- _context10.next = 40;
733
+ _context10.next = 42;
734
734
  break;
735
735
  }
736
736
  // 基于现有支付项计算新的 expect_amount
@@ -792,14 +792,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
792
792
  timestamp: Date.now()
793
793
  });
794
794
  case 38:
795
+ // 需要减去已经同步给后端的支付过的钱
796
+ syncedAmount = activePayments.reduce(function (sum, p) {
797
+ var amt = new Decimal(p.amount || '0');
798
+ var rounding = new Decimal(p.rounding_amount || '0');
799
+ return sum.plus(amt).plus(rounding);
800
+ }, new Decimal(0));
801
+ remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2);
795
802
  this.initWalletData({
796
- order_wait_pay_amount: Number(updated.expect_amount)
803
+ order_wait_pay_amount: Number(remainingExpectAmount)
797
804
  });
798
805
  return _context10.abrupt("return", updated);
799
- case 40:
806
+ case 42:
800
807
  // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
801
808
  isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 没找到现有订单时,回退为创建逻辑(用于异常兜底)
802
- _context10.next = 43;
809
+ _context10.next = 45;
803
810
  return this.payment.createPaymentOrderAsync({
804
811
  order_id: String(params.orderId),
805
812
  total_amount: amountInfo.totalAmount,
@@ -816,15 +823,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
816
823
  amount_breakdown: amountInfo
817
824
  }
818
825
  });
819
- case 43:
826
+ case 45:
820
827
  created = _context10.sent;
821
828
  this.store.currentOrder = created;
822
- _context10.next = 47;
829
+ _context10.next = 49;
823
830
  return this.updateStateAmountToRemaining();
824
- case 47:
831
+ case 49:
825
832
  this.initWalletData();
826
833
  return _context10.abrupt("return", created);
827
- case 49:
834
+ case 51:
828
835
  case "end":
829
836
  return _context10.stop();
830
837
  }
@@ -529,13 +529,13 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
529
529
  }
530
530
  const expectAmount = new import_decimal.Decimal(order.expect_amount);
531
531
  const paidDepositAmount = order.payment.reduce((sum, payment) => {
532
- if (payment.order_payment_type === "deposit") {
532
+ if (payment.order_payment_type === "deposit" && payment.status !== "voided") {
533
533
  return sum.plus(new import_decimal.Decimal(payment.amount));
534
534
  }
535
535
  return sum;
536
536
  }, new import_decimal.Decimal(0));
537
537
  const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
538
- if (expectAmount.lte(0) && expectedDepositAmount.lte(0)) {
538
+ if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
539
539
  const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
540
540
  console.warn("[PaymentModule] Payment lock triggered:", {
541
541
  orderUuid,
@@ -522,8 +522,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
522
522
  order: updated,
523
523
  timestamp: Date.now()
524
524
  });
525
+ const syncedAmount = activePayments.reduce((sum, p) => {
526
+ const amt = new import_decimal.default(p.amount || "0");
527
+ const rounding = new import_decimal.default(p.rounding_amount || "0");
528
+ return sum.plus(amt).plus(rounding);
529
+ }, new import_decimal.default(0));
530
+ const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
531
+ 2
532
+ );
525
533
  this.initWalletData({
526
- order_wait_pay_amount: Number(updated.expect_amount)
534
+ order_wait_pay_amount: Number(remainingExpectAmount)
527
535
  });
528
536
  return updated;
529
537
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.306",
4
+ "version": "0.0.308",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",