@pisell/pisellos 0.0.303 → 0.0.305

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.
@@ -1044,7 +1044,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1044
1044
  key: "addPaymentItemAsync",
1045
1045
  value: (function () {
1046
1046
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
1047
- var _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, expectAmount, warningMessage, paymentUuid, newPaymentItem;
1047
+ var _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, expectAmount, paidDepositAmount, expectedDepositAmount, warningMessage, paymentUuid, newPaymentItem;
1048
1048
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1049
1049
  while (1) switch (_context13.prev = _context13.next) {
1050
1050
  case 0:
@@ -1066,9 +1066,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1066
1066
  throw new Error("Order not found: ".concat(orderUuid));
1067
1067
  case 7:
1068
1068
  // 🔒 支付锁检查:如果订单待付金额已经为0,不允许继续添加支付项
1069
- expectAmount = new Decimal(order.expect_amount); // const expecDepositAmount = new Decimal(order.deposit_amount);
1070
- if (!expectAmount.lte(0)) {
1071
- _context13.next = 13;
1069
+ expectAmount = new Decimal(order.expect_amount);
1070
+ paidDepositAmount = order.payment.reduce(function (sum, payment) {
1071
+ if (payment.order_payment_type === 'deposit') {
1072
+ return sum.plus(new Decimal(payment.amount));
1073
+ }
1074
+ return sum;
1075
+ }, new Decimal(0));
1076
+ expectedDepositAmount = new Decimal(order.deposit_amount || '0').sub(paidDepositAmount); // 有一种特殊情况,订单金额为 0,但是定金金额>0,且此时是定金状态的,允许添加支付项
1077
+ if (!(expectAmount.lte(0) && expectedDepositAmount.lte(0))) {
1078
+ _context13.next = 15;
1072
1079
  break;
1073
1080
  }
1074
1081
  warningMessage = "\u8BA2\u5355 ".concat(orderUuid, " \u5F85\u4ED8\u91D1\u989D\u5DF2\u4E3A0\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u65B0\u7684\u652F\u4ED8\u9879");
@@ -1085,7 +1092,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1085
1092
  paymentItem: paymentItem
1086
1093
  });
1087
1094
  throw new Error(warningMessage);
1088
- case 13:
1095
+ case 15:
1089
1096
  paymentUuid = getUniqueId('payment_');
1090
1097
  newPaymentItem = {
1091
1098
  uuid: paymentUuid,
@@ -1108,15 +1115,15 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1108
1115
  };
1109
1116
  order.payment.push(newPaymentItem);
1110
1117
  this.recalculateOrderAmount(order);
1111
- _context13.next = 19;
1112
- return this.dbManager.update('order', order);
1113
- case 19:
1114
1118
  _context13.next = 21;
1119
+ return this.dbManager.update('order', order);
1120
+ case 21:
1121
+ _context13.next = 23;
1115
1122
  return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
1116
1123
  orderUuid: orderUuid,
1117
1124
  payment: newPaymentItem
1118
1125
  });
1119
- case 21:
1126
+ case 23:
1120
1127
  this.logInfo('addPaymentItemAsync completed successfully', {
1121
1128
  orderUuid: orderUuid,
1122
1129
  paymentUuid: newPaymentItem.uuid,
@@ -1130,10 +1137,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1130
1137
  actualPaidAmount: (_newPaymentItem$metad2 = newPaymentItem.metadata) === null || _newPaymentItem$metad2 === void 0 ? void 0 : _newPaymentItem$metad2.actual_paid_amount,
1131
1138
  changeGivenAmount: (_newPaymentItem$metad3 = newPaymentItem.metadata) === null || _newPaymentItem$metad3 === void 0 ? void 0 : _newPaymentItem$metad3.change_given_amount
1132
1139
  });
1133
- _context13.next = 29;
1140
+ _context13.next = 31;
1134
1141
  break;
1135
- case 24:
1136
- _context13.prev = 24;
1142
+ case 26:
1143
+ _context13.prev = 26;
1137
1144
  _context13.t0 = _context13["catch"](1);
1138
1145
  console.error('[PaymentModule] 添加支付项失败', _context13.t0);
1139
1146
  this.logError('addPaymentItemAsync failed', _context13.t0, {
@@ -1141,11 +1148,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1141
1148
  paymentItem: paymentItem
1142
1149
  });
1143
1150
  throw _context13.t0;
1144
- case 29:
1151
+ case 31:
1145
1152
  case "end":
1146
1153
  return _context13.stop();
1147
1154
  }
1148
- }, _callee13, this, [[1, 24]]);
1155
+ }, _callee13, this, [[1, 26]]);
1149
1156
  }));
1150
1157
  function addPaymentItemAsync(_x14, _x15) {
1151
1158
  return _addPaymentItemAsync.apply(this, arguments);
@@ -128,7 +128,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
128
128
  case 0:
129
129
  startTime = Date.now();
130
130
  walletParams = this.generateWalletParams(businessData);
131
- if (!(Number((businessData === null || businessData === void 0 || (_businessData$amountI = businessData.amountInfo) === null || _businessData$amountI === void 0 ? void 0 : _businessData$amountI.totalAmount) || 0) < 0 || Number((businessData === null || businessData === void 0 || (_businessData$amountI2 = businessData.amountInfo) === null || _businessData$amountI2 === void 0 ? void 0 : _businessData$amountI2.subTotal) || 0) < 0)) {
131
+ if (!(Number((businessData === null || businessData === void 0 || (_businessData$amountI = businessData.amountInfo) === null || _businessData$amountI === void 0 ? void 0 : _businessData$amountI.totalAmount) || 0) < 0 || Number((businessData === null || businessData === void 0 || (_businessData$amountI2 = businessData.amountInfo) === null || _businessData$amountI2 === void 0 ? void 0 : _businessData$amountI2.subTotal) || 0) < 0 || [1, 0].includes(walletParams === null || walletParams === void 0 ? void 0 : walletParams.customer_id))) {
132
132
  _context.next = 4;
133
133
  break;
134
134
  }
@@ -1071,7 +1071,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1071
1071
 
1072
1072
  // 订单ID替换后更新 stateAmount
1073
1073
  _context13.next = 15;
1074
- return this.updateStateAmountToRemaining();
1074
+ return this.updateStateAmountToRemaining(false);
1075
1075
  case 15:
1076
1076
  return _context13.abrupt("return", updatedOrder);
1077
1077
  case 18:
@@ -1645,7 +1645,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1645
1645
  key: "updateOrderDepositStatusAsync",
1646
1646
  value: (function () {
1647
1647
  var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(isDeposit) {
1648
- var newDepositValue, oldDepositValue, updateParams;
1648
+ var newDepositValue, oldDepositValue, deposit_amount, updateParams;
1649
1649
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1650
1650
  while (1) switch (_context19.prev = _context19.next) {
1651
1651
  case 0:
@@ -1671,9 +1671,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1671
1671
  console.log('[Checkout] 定金状态无变化,跳过更新');
1672
1672
  return _context19.abrupt("return");
1673
1673
  case 10:
1674
+ deposit_amount = newDepositValue === 1 ? this.store.currentOrder.deposit_amount : '0.00'; // 如果原来没有 deposit_amount,则默认把待付金额置为 deposit_amount
1675
+ if (!deposit_amount) {
1676
+ deposit_amount = this.store.currentOrder.expect_amount;
1677
+ }
1678
+
1674
1679
  // 准备更新参数
1675
1680
  updateParams = {
1676
- is_deposit: newDepositValue
1681
+ is_deposit: newDepositValue,
1682
+ deposit_amount: deposit_amount
1677
1683
  }; // 如果从定金改为全款,可以清空定金金额
1678
1684
  // if (
1679
1685
  // isDeposit === 0 &&
@@ -1683,9 +1689,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1683
1689
  // this.logInfo('订单从定金改为全款,清空定金金额');
1684
1690
  // }
1685
1691
  // 调用 Payment 模块更新订单
1686
- _context19.next = 13;
1692
+ _context19.next = 15;
1687
1693
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1688
- case 13:
1694
+ case 15:
1689
1695
  // 更新本地缓存的订单对象
1690
1696
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1691
1697
 
@@ -1693,34 +1699,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1693
1699
  if (this.store.localOrderData) {
1694
1700
  this.store.localOrderData.is_deposit = newDepositValue;
1695
1701
  }
1696
- this.updateStateAmountToRemaining();
1702
+ this.updateStateAmountToRemaining(false);
1697
1703
 
1698
1704
  // 触发订单更新事件
1699
- _context19.next = 18;
1705
+ _context19.next = 20;
1700
1706
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1701
1707
  order: this.store.currentOrder,
1702
1708
  timestamp: Date.now()
1703
1709
  });
1704
- case 18:
1710
+ case 20:
1705
1711
  this.logInfo('订单定金状态更新成功:', {
1706
1712
  isDeposit: newDepositValue,
1707
1713
  depositAmount: this.store.currentOrder.deposit_amount
1708
1714
  });
1709
- _context19.next = 27;
1715
+ _context19.next = 29;
1710
1716
  break;
1711
- case 21:
1712
- _context19.prev = 21;
1717
+ case 23:
1718
+ _context19.prev = 23;
1713
1719
  _context19.t0 = _context19["catch"](0);
1714
1720
  this.logError('更新订单定金状态失败:', _context19.t0);
1715
- _context19.next = 26;
1721
+ _context19.next = 28;
1716
1722
  return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1717
- case 26:
1723
+ case 28:
1718
1724
  throw _context19.t0;
1719
- case 27:
1725
+ case 29:
1720
1726
  case "end":
1721
1727
  return _context19.stop();
1722
1728
  }
1723
- }, _callee19, this, [[0, 21]]);
1729
+ }, _callee19, this, [[0, 23]]);
1724
1730
  }));
1725
1731
  function updateOrderDepositStatusAsync(_x18) {
1726
1732
  return _updateOrderDepositStatusAsync.apply(this, arguments);
@@ -528,7 +528,14 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
528
528
  throw new Error(`Order not found: ${orderUuid}`);
529
529
  }
530
530
  const expectAmount = new import_decimal.Decimal(order.expect_amount);
531
- if (expectAmount.lte(0)) {
531
+ const paidDepositAmount = order.payment.reduce((sum, payment) => {
532
+ if (payment.order_payment_type === "deposit") {
533
+ return sum.plus(new import_decimal.Decimal(payment.amount));
534
+ }
535
+ return sum;
536
+ }, new import_decimal.Decimal(0));
537
+ const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
538
+ if (expectAmount.lte(0) && expectedDepositAmount.lte(0)) {
532
539
  const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
533
540
  console.warn("[PaymentModule] Payment lock triggered:", {
534
541
  orderUuid,
@@ -99,7 +99,7 @@ var WalletPassPaymentImpl = class {
99
99
  var _a, _b, _c, _d, _e, _f, _g, _h;
100
100
  const startTime = Date.now();
101
101
  const walletParams = this.generateWalletParams(businessData);
102
- if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) < 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) < 0) {
102
+ if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) < 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) < 0 || [1, 0].includes(walletParams == null ? void 0 : walletParams.customer_id)) {
103
103
  return {
104
104
  walletRecommendList: [],
105
105
  userIdentificationCodes: []
@@ -693,7 +693,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
693
693
  newOrderId: updatedOrder.id
694
694
  });
695
695
  this.store.isOrderSynced = true;
696
- await this.updateStateAmountToRemaining();
696
+ await this.updateStateAmountToRemaining(false);
697
697
  }
698
698
  return updatedOrder;
699
699
  } catch (error) {
@@ -1087,8 +1087,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1087
1087
  console.log("[Checkout] 定金状态无变化,跳过更新");
1088
1088
  return;
1089
1089
  }
1090
+ let deposit_amount = newDepositValue === 1 ? this.store.currentOrder.deposit_amount : "0.00";
1091
+ if (!deposit_amount) {
1092
+ deposit_amount = this.store.currentOrder.expect_amount;
1093
+ }
1090
1094
  const updateParams = {
1091
- is_deposit: newDepositValue
1095
+ is_deposit: newDepositValue,
1096
+ deposit_amount
1092
1097
  };
1093
1098
  await this.payment.updateOrderAsync(
1094
1099
  this.store.currentOrder.uuid,
@@ -1101,7 +1106,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1101
1106
  if (this.store.localOrderData) {
1102
1107
  this.store.localOrderData.is_deposit = newDepositValue;
1103
1108
  }
1104
- this.updateStateAmountToRemaining();
1109
+ this.updateStateAmountToRemaining(false);
1105
1110
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
1106
1111
  order: this.store.currentOrder,
1107
1112
  timestamp: Date.now()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.303",
4
+ "version": "0.0.305",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",