@pisell/pisellos 2.1.28 → 2.1.29

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|)'
@@ -310,6 +310,10 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
310
310
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
311
311
  */
312
312
  private calculateRemainingAmountAsync;
313
+ /**
314
+ * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
315
+ */
316
+ private calculateRemainingTotalAmountAsync;
313
317
  /**
314
318
  * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
315
319
  */
@@ -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),
@@ -2860,60 +2860,107 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2860
2860
  return calculateRemainingAmountAsync;
2861
2861
  }()
2862
2862
  /**
2863
- * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
2863
+ * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
2864
2864
  */
2865
2865
  )
2866
2866
  }, {
2867
- key: "updateBalanceDueAmount",
2867
+ key: "calculateRemainingTotalAmountAsync",
2868
2868
  value: (function () {
2869
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2870
- var remainingAmount, currentBalanceDueAmount;
2869
+ var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2870
+ var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2871
2871
  return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2872
2872
  while (1) switch (_context33.prev = _context33.next) {
2873
2873
  case 0:
2874
- _context33.prev = 0;
2875
- _context33.next = 3;
2874
+ if (this.store.currentOrder) {
2875
+ _context33.next = 3;
2876
+ break;
2877
+ }
2878
+ this.logWarning('calculateRemainingTotalAmountAsync: 没有当前订单');
2879
+ return _context33.abrupt("return", '0.00');
2880
+ case 3:
2881
+ // 使用 Decimal.js 进行安全的金额计算
2882
+ // 始终使用订单总金额,不进行定金相关的计算
2883
+ totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2884
+ _context33.next = 6;
2885
+ return this.calculatePaidAmountAsync();
2886
+ case 6:
2887
+ paidAmountStr = _context33.sent;
2888
+ paidAmount = new Decimal(paidAmountStr);
2889
+ remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2890
+ result = Decimal.max(0, remainingAmount).toFixed(2);
2891
+ this.logInfo('calculateRemainingTotalAmountAsync: 计算=', result);
2892
+ return _context33.abrupt("return", result);
2893
+ case 12:
2894
+ case "end":
2895
+ return _context33.stop();
2896
+ }
2897
+ }, _callee33, this);
2898
+ }));
2899
+ function calculateRemainingTotalAmountAsync() {
2900
+ return _calculateRemainingTotalAmountAsync.apply(this, arguments);
2901
+ }
2902
+ return calculateRemainingTotalAmountAsync;
2903
+ }()
2904
+ /**
2905
+ * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
2906
+ */
2907
+ )
2908
+ }, {
2909
+ key: "updateBalanceDueAmount",
2910
+ value: (function () {
2911
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2912
+ var remainingAmount, remainingTotalAmount, currentBalanceDueAmount;
2913
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2914
+ while (1) switch (_context34.prev = _context34.next) {
2915
+ case 0:
2916
+ _context34.prev = 0;
2917
+ _context34.next = 3;
2876
2918
  return this.calculateRemainingAmountAsync();
2877
2919
  case 3:
2878
- remainingAmount = _context33.sent;
2920
+ remainingAmount = _context34.sent;
2921
+ _context34.next = 6;
2922
+ return this.calculateRemainingTotalAmountAsync();
2923
+ case 6:
2924
+ remainingTotalAmount = _context34.sent;
2879
2925
  currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
2880
2926
  if (!(remainingAmount !== currentBalanceDueAmount)) {
2881
- _context33.next = 12;
2927
+ _context34.next = 15;
2882
2928
  break;
2883
2929
  }
2884
2930
  this.store.balanceDueAmount = remainingAmount;
2885
2931
 
2886
2932
  // 发出 balanceDueAmount 变更事件
2887
- _context33.next = 9;
2933
+ _context34.next = 12;
2888
2934
  return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
2889
2935
  oldAmount: currentBalanceDueAmount,
2890
2936
  newAmount: remainingAmount,
2891
- timestamp: Date.now()
2937
+ timestamp: Date.now(),
2938
+ totalAmount: remainingTotalAmount
2892
2939
  });
2893
- case 9:
2940
+ case 12:
2894
2941
  this.logInfo('balanceDueAmount 已自动更新:', {
2895
2942
  oldAmount: currentBalanceDueAmount,
2896
2943
  newAmount: remainingAmount
2897
2944
  });
2898
- _context33.next = 13;
2945
+ _context34.next = 16;
2899
2946
  break;
2900
- case 12:
2947
+ case 15:
2901
2948
  this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
2902
2949
  balanceDueAmount: currentBalanceDueAmount,
2903
2950
  remainingAmount: remainingAmount
2904
2951
  });
2905
- case 13:
2906
- _context33.next = 18;
2952
+ case 16:
2953
+ _context34.next = 21;
2907
2954
  break;
2908
- case 15:
2909
- _context33.prev = 15;
2910
- _context33.t0 = _context33["catch"](0);
2911
- this.logError('更新 balanceDueAmount 失败:', _context33.t0);
2912
2955
  case 18:
2956
+ _context34.prev = 18;
2957
+ _context34.t0 = _context34["catch"](0);
2958
+ this.logError('更新 balanceDueAmount 失败:', _context34.t0);
2959
+ case 21:
2913
2960
  case "end":
2914
- return _context33.stop();
2961
+ return _context34.stop();
2915
2962
  }
2916
- }, _callee33, this, [[0, 15]]);
2963
+ }, _callee34, this, [[0, 18]]);
2917
2964
  }));
2918
2965
  function updateBalanceDueAmount() {
2919
2966
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -2927,7 +2974,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2927
2974
  }, {
2928
2975
  key: "updateStateAmountToRemaining",
2929
2976
  value: (function () {
2930
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2977
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2931
2978
  var checkOrder,
2932
2979
  _this$store$currentOr23,
2933
2980
  _this$store$currentOr24,
@@ -2936,21 +2983,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2936
2983
  depositPaidAmount,
2937
2984
  _this$store$currentOr26,
2938
2985
  remainingAmount,
2986
+ remainingTotalAmount,
2939
2987
  currentStateAmount,
2940
- _args34 = arguments;
2941
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2942
- while (1) switch (_context34.prev = _context34.next) {
2988
+ _args35 = arguments;
2989
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2990
+ while (1) switch (_context35.prev = _context35.next) {
2943
2991
  case 0:
2944
- checkOrder = _args34.length > 0 && _args34[0] !== undefined ? _args34[0] : true;
2945
- _context34.prev = 1;
2992
+ checkOrder = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : true;
2993
+ _context35.prev = 1;
2946
2994
  if (!(((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.is_deposit) === 1)) {
2947
- _context34.next = 11;
2995
+ _context35.next = 11;
2948
2996
  break;
2949
2997
  }
2950
- _context34.next = 5;
2998
+ _context35.next = 5;
2951
2999
  return this.payment.getPaymentItemsAsync((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.uuid);
2952
3000
  case 5:
2953
- paymentItems = _context34.sent;
3001
+ paymentItems = _context35.sent;
2954
3002
  depositPaidAmount = paymentItems.filter(function (item) {
2955
3003
  return item.order_payment_type === 'deposit' && item.status !== 'voided';
2956
3004
  }).reduce(function (sum, item) {
@@ -2960,24 +3008,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2960
3008
  }
2961
3009
  var amount = new Decimal(item.amount || '0');
2962
3010
  var roundingAmount = new Decimal(item.rounding_amount || '0');
2963
- return sum.add(amount.add(roundingAmount.abs()));
3011
+ return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
2964
3012
  }, new Decimal(0));
2965
3013
  if (!depositPaidAmount.gte((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount)) {
2966
- _context34.next = 11;
3014
+ _context35.next = 11;
2967
3015
  break;
2968
3016
  }
2969
3017
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), {}, {
2970
3018
  is_deposit: 0
2971
3019
  });
2972
- _context34.next = 11;
3020
+ _context35.next = 11;
2973
3021
  return this.payment.updateOrderAsync((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.uuid, {
2974
3022
  is_deposit: 0
2975
3023
  });
2976
3024
  case 11:
2977
- _context34.next = 13;
3025
+ _context35.next = 13;
2978
3026
  return this.calculateRemainingAmountAsync();
2979
3027
  case 13:
2980
- remainingAmount = _context34.sent;
3028
+ remainingAmount = _context35.sent;
3029
+ _context35.next = 16;
3030
+ return this.calculateRemainingTotalAmountAsync();
3031
+ case 16:
3032
+ remainingTotalAmount = _context35.sent;
2981
3033
  currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
2982
3034
  if (remainingAmount !== currentStateAmount) {
2983
3035
  this.store.stateAmount = remainingAmount;
@@ -2986,7 +3038,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2986
3038
  this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
2987
3039
  oldAmount: currentStateAmount,
2988
3040
  newAmount: remainingAmount,
2989
- timestamp: Date.now()
3041
+ timestamp: Date.now(),
3042
+ totalAmount: remainingTotalAmount
2990
3043
  });
2991
3044
  this.logInfo('stateAmount 已自动更新为剩余金额:', {
2992
3045
  oldAmount: currentStateAmount,
@@ -2999,32 +3052,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2999
3052
  });
3000
3053
  }
3001
3054
  // 同步更新系统内部的 balanceDueAmount
3002
- _context34.next = 18;
3055
+ _context35.next = 21;
3003
3056
  return this.updateBalanceDueAmount();
3004
- case 18:
3057
+ case 21:
3005
3058
  if (!checkOrder) {
3006
- _context34.next = 23;
3059
+ _context35.next = 26;
3007
3060
  break;
3008
3061
  }
3009
- _context34.next = 21;
3062
+ _context35.next = 24;
3010
3063
  return this.checkOrderPaymentCompletion();
3011
- case 21:
3012
- _context34.next = 24;
3013
- break;
3014
- case 23:
3015
- this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
3016
3064
  case 24:
3017
- _context34.next = 29;
3065
+ _context35.next = 27;
3018
3066
  break;
3019
3067
  case 26:
3020
- _context34.prev = 26;
3021
- _context34.t0 = _context34["catch"](1);
3022
- this.logError('更新 stateAmount 为剩余金额失败:', _context34.t0);
3068
+ this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
3069
+ case 27:
3070
+ _context35.next = 32;
3071
+ break;
3023
3072
  case 29:
3073
+ _context35.prev = 29;
3074
+ _context35.t0 = _context35["catch"](1);
3075
+ this.logError('更新 stateAmount 为剩余金额失败:', _context35.t0);
3076
+ case 32:
3024
3077
  case "end":
3025
- return _context34.stop();
3078
+ return _context35.stop();
3026
3079
  }
3027
- }, _callee34, this, [[1, 26]]);
3080
+ }, _callee35, this, [[1, 29]]);
3028
3081
  }));
3029
3082
  function updateStateAmountToRemaining() {
3030
3083
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -3040,32 +3093,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3040
3093
  }, {
3041
3094
  key: "checkOrderPaymentCompletion",
3042
3095
  value: (function () {
3043
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
3096
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3044
3097
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
3045
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3046
- while (1) switch (_context35.prev = _context35.next) {
3098
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3099
+ while (1) switch (_context36.prev = _context36.next) {
3047
3100
  case 0:
3048
- _context35.prev = 0;
3101
+ _context36.prev = 0;
3049
3102
  if (this.store.currentOrder) {
3050
- _context35.next = 3;
3103
+ _context36.next = 3;
3051
3104
  break;
3052
3105
  }
3053
- return _context35.abrupt("return");
3106
+ return _context36.abrupt("return");
3054
3107
  case 3:
3055
- _context35.next = 5;
3108
+ _context36.next = 5;
3056
3109
  return this.calculateRemainingAmountAsync();
3057
3110
  case 5:
3058
- remainingAmount = _context35.sent;
3111
+ remainingAmount = _context36.sent;
3059
3112
  remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3060
3113
  if (!remainingValue.lte(0)) {
3061
- _context35.next = 29;
3114
+ _context36.next = 29;
3062
3115
  break;
3063
3116
  }
3064
3117
  totalAmount = this.store.currentOrder.total_amount;
3065
- _context35.next = 11;
3118
+ _context36.next = 11;
3066
3119
  return this.calculatePaidAmountAsync();
3067
3120
  case 11:
3068
- paidAmount = _context35.sent;
3121
+ paidAmount = _context36.sent;
3069
3122
  this.logInfo('检测到订单支付完成:', {
3070
3123
  orderUuid: this.store.currentOrder.uuid,
3071
3124
  orderId: this.store.currentOrder.order_id,
@@ -3076,11 +3129,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3076
3129
  });
3077
3130
 
3078
3131
  // 从 Payment 模块获取最新支付项,检查自动同步条件
3079
- _context35.next = 15;
3132
+ _context36.next = 15;
3080
3133
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3081
3134
  );
3082
3135
  case 15:
3083
- currentPayments = _context35.sent;
3136
+ currentPayments = _context36.sent;
3084
3137
  // 检查自动同步条件:
3085
3138
  // 1. 待付金额为 0 ✓ (已在上面检查)
3086
3139
  // 2. 需要有支付项
@@ -3107,21 +3160,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3107
3160
  code: p.code,
3108
3161
  amount: p.amount,
3109
3162
  rounding_amount: p.rounding_amount,
3110
- effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(p.rounding_amount || '0'))).toFixed(2),
3163
+ effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
3111
3164
  voucher_id: p.voucher_id,
3112
3165
  status: p.status
3113
3166
  };
3114
3167
  })
3115
3168
  });
3116
3169
  if (!shouldAutoSync) {
3117
- _context35.next = 26;
3170
+ _context36.next = 26;
3118
3171
  break;
3119
3172
  }
3120
3173
  this.logInfo('满足自动同步条件,开始同步订单到后端...');
3121
- _context35.next = 24;
3174
+ _context36.next = 24;
3122
3175
  return this.syncOrderToBackendWithReturn(false);
3123
3176
  case 24:
3124
- _context35.next = 27;
3177
+ _context36.next = 27;
3125
3178
  break;
3126
3179
  case 26:
3127
3180
  if (!hasPaymentItems) {
@@ -3130,7 +3183,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3130
3183
  this.logInfo('所有支付项均为代金券类型,跳过订单同步');
3131
3184
  }
3132
3185
  case 27:
3133
- _context35.next = 29;
3186
+ _context36.next = 29;
3134
3187
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3135
3188
  orderUuid: this.store.currentOrder.uuid,
3136
3189
  orderId: this.store.currentOrder.order_id,
@@ -3140,17 +3193,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3140
3193
  timestamp: Date.now()
3141
3194
  });
3142
3195
  case 29:
3143
- _context35.next = 34;
3196
+ _context36.next = 34;
3144
3197
  break;
3145
3198
  case 31:
3146
- _context35.prev = 31;
3147
- _context35.t0 = _context35["catch"](0);
3148
- this.logError('检查订单支付完成状态失败:', _context35.t0);
3199
+ _context36.prev = 31;
3200
+ _context36.t0 = _context36["catch"](0);
3201
+ this.logError('检查订单支付完成状态失败:', _context36.t0);
3149
3202
  case 34:
3150
3203
  case "end":
3151
- return _context35.stop();
3204
+ return _context36.stop();
3152
3205
  }
3153
- }, _callee35, this, [[0, 31]]);
3206
+ }, _callee36, this, [[0, 31]]);
3154
3207
  }));
3155
3208
  function checkOrderPaymentCompletion() {
3156
3209
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -3168,7 +3221,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3168
3221
  }, {
3169
3222
  key: "syncOrderToBackendWithReturn",
3170
3223
  value: (function () {
3171
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3224
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
3172
3225
  var _this4 = this,
3173
3226
  _this$store$currentOr27,
3174
3227
  _this$store$currentOr28,
@@ -3208,14 +3261,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3208
3261
  _iterator3,
3209
3262
  _step3,
3210
3263
  paymentUuid,
3211
- _args36 = arguments;
3212
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3213
- while (1) switch (_context36.prev = _context36.next) {
3264
+ _args37 = arguments;
3265
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3266
+ while (1) switch (_context37.prev = _context37.next) {
3214
3267
  case 0:
3215
- isManual = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : false;
3216
- customPaymentItems = _args36.length > 1 ? _args36[1] : undefined;
3268
+ isManual = _args37.length > 0 && _args37[0] !== undefined ? _args37[0] : false;
3269
+ customPaymentItems = _args37.length > 1 ? _args37[1] : undefined;
3217
3270
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3218
- _context36.next = 4;
3271
+ _context37.next = 4;
3219
3272
  break;
3220
3273
  }
3221
3274
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -3234,17 +3287,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3234
3287
  });
3235
3288
 
3236
3289
  // 获取当前订单的支付项
3237
- _context36.t0 = customPaymentItems;
3238
- if (_context36.t0) {
3239
- _context36.next = 13;
3290
+ _context37.t0 = customPaymentItems;
3291
+ if (_context37.t0) {
3292
+ _context37.next = 13;
3240
3293
  break;
3241
3294
  }
3242
- _context36.next = 12;
3295
+ _context37.next = 12;
3243
3296
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3244
3297
  case 12:
3245
- _context36.t0 = _context36.sent;
3298
+ _context37.t0 = _context37.sent;
3246
3299
  case 13:
3247
- paymentItems = _context36.t0;
3300
+ paymentItems = _context37.t0;
3248
3301
  // 处理支付项数据,确保包含完整的 metadata
3249
3302
  processedPaymentItems = paymentItems.map(function (item) {
3250
3303
  var _item$metadata, _item$metadata2;
@@ -3368,7 +3421,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3368
3421
 
3369
3422
  // 发送下单接口请求开始事件
3370
3423
  startTime = Date.now();
3371
- _context36.next = 27;
3424
+ _context37.next = 27;
3372
3425
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3373
3426
  orderUuid: this.store.currentOrder.uuid,
3374
3427
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3378,7 +3431,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3378
3431
  });
3379
3432
  case 27:
3380
3433
  submitSuccess = false;
3381
- _context36.prev = 28;
3434
+ _context37.prev = 28;
3382
3435
  // 记录接口调用参数
3383
3436
  this.logInfo('Calling backend checkout API', _objectSpread({
3384
3437
  url: '/order/checkout',
@@ -3386,23 +3439,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3386
3439
  }, orderParams));
3387
3440
 
3388
3441
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3389
- _context36.next = 32;
3442
+ _context37.next = 32;
3390
3443
  return this.order.createOrderByCheckout(orderParams);
3391
3444
  case 32:
3392
- checkoutResponse = _context36.sent;
3445
+ checkoutResponse = _context37.sent;
3393
3446
  submitSuccess = true;
3394
3447
  this.logInfo('下单接口调用成功', checkoutResponse);
3395
- _context36.next = 45;
3448
+ _context37.next = 45;
3396
3449
  break;
3397
3450
  case 37:
3398
- _context36.prev = 37;
3399
- _context36.t1 = _context36["catch"](28);
3451
+ _context37.prev = 37;
3452
+ _context37.t1 = _context37["catch"](28);
3400
3453
  submitSuccess = false;
3401
- submitError = _context36.t1 instanceof Error ? _context36.t1.message : String(_context36.t1);
3454
+ submitError = _context37.t1 instanceof Error ? _context37.t1.message : String(_context37.t1);
3402
3455
  this.logError('下单接口调用失败:', submitError);
3403
3456
 
3404
3457
  // 发送订单同步失败事件(网络错误或请求失败)
3405
- _context36.next = 44;
3458
+ _context37.next = 44;
3406
3459
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3407
3460
  orderUuid: this.store.currentOrder.uuid,
3408
3461
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3413,10 +3466,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3413
3466
  timestamp: Date.now()
3414
3467
  });
3415
3468
  case 44:
3416
- throw _context36.t1;
3469
+ throw _context37.t1;
3417
3470
  case 45:
3418
- _context36.prev = 45;
3419
- _context36.next = 48;
3471
+ _context37.prev = 45;
3472
+ _context37.next = 48;
3420
3473
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3421
3474
  success: submitSuccess,
3422
3475
  orderUuid: this.store.currentOrder.uuid,
@@ -3428,17 +3481,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3428
3481
  timestamp: Date.now()
3429
3482
  });
3430
3483
  case 48:
3431
- return _context36.finish(45);
3484
+ return _context37.finish(45);
3432
3485
  case 49:
3433
3486
  // 检查响应状态是否为成功状态
3434
3487
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3435
3488
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3436
3489
  if (isSuccessResponse) {
3437
- _context36.next = 56;
3490
+ _context37.next = 56;
3438
3491
  break;
3439
3492
  }
3440
3493
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3441
- _context36.next = 55;
3494
+ _context37.next = 55;
3442
3495
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3443
3496
  orderUuid: this.store.currentOrder.uuid,
3444
3497
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3453,12 +3506,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3453
3506
  throw new Error(errorMessage);
3454
3507
  case 56:
3455
3508
  if (!isUpdateOperation) {
3456
- _context36.next = 60;
3509
+ _context37.next = 60;
3457
3510
  break;
3458
3511
  }
3459
3512
  // 更新操作:使用现有的订单ID
3460
3513
  realOrderId = currentOrderId;
3461
- _context36.next = 79;
3514
+ _context37.next = 79;
3462
3515
  break;
3463
3516
  case 60:
3464
3517
  // 创建操作:从响应中提取新的订单ID
@@ -3482,11 +3535,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3482
3535
  oldOrderId: this.store.currentOrder.order_id,
3483
3536
  newOrderId: realOrderId
3484
3537
  });
3485
- _context36.prev = 66;
3486
- _context36.next = 69;
3538
+ _context37.prev = 66;
3539
+ _context37.next = 69;
3487
3540
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3488
3541
  case 69:
3489
- updatedOrder = _context36.sent;
3542
+ updatedOrder = _context37.sent;
3490
3543
  this.logInfo('Payment模块替换订单ID结果:', {
3491
3544
  wasSuccessful: !!updatedOrder,
3492
3545
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -3512,66 +3565,66 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3512
3565
  目标ID: realOrderId
3513
3566
  });
3514
3567
  }
3515
- _context36.next = 79;
3568
+ _context37.next = 79;
3516
3569
  break;
3517
3570
  case 74:
3518
- _context36.prev = 74;
3519
- _context36.t2 = _context36["catch"](66);
3520
- this.logError('调用Payment模块替换订单ID时发生错误:', _context36.t2);
3571
+ _context37.prev = 74;
3572
+ _context37.t2 = _context37["catch"](66);
3573
+ this.logError('调用Payment模块替换订单ID时发生错误:', _context37.t2);
3521
3574
 
3522
3575
  // 发生错误时也进行手动替换
3523
3576
  this.store.currentOrder.order_id = realOrderId;
3524
3577
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3525
3578
  case 79:
3526
- _context36.prev = 79;
3579
+ _context37.prev = 79;
3527
3580
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
3528
3581
  return item.status !== 'voided';
3529
3582
  }).map(function (item) {
3530
3583
  return item.uuid;
3531
3584
  }).filter(Boolean);
3532
3585
  _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
3533
- _context36.prev = 82;
3586
+ _context37.prev = 82;
3534
3587
  _iterator3.s();
3535
3588
  case 84:
3536
3589
  if ((_step3 = _iterator3.n()).done) {
3537
- _context36.next = 90;
3590
+ _context37.next = 90;
3538
3591
  break;
3539
3592
  }
3540
3593
  paymentUuid = _step3.value;
3541
- _context36.next = 88;
3594
+ _context37.next = 88;
3542
3595
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
3543
3596
  isSynced: true,
3544
3597
  syncError: undefined
3545
3598
  });
3546
3599
  case 88:
3547
- _context36.next = 84;
3600
+ _context37.next = 84;
3548
3601
  break;
3549
3602
  case 90:
3550
- _context36.next = 95;
3603
+ _context37.next = 95;
3551
3604
  break;
3552
3605
  case 92:
3553
- _context36.prev = 92;
3554
- _context36.t3 = _context36["catch"](82);
3555
- _iterator3.e(_context36.t3);
3606
+ _context37.prev = 92;
3607
+ _context37.t3 = _context37["catch"](82);
3608
+ _iterator3.e(_context37.t3);
3556
3609
  case 95:
3557
- _context36.prev = 95;
3610
+ _context37.prev = 95;
3558
3611
  _iterator3.f();
3559
- return _context36.finish(95);
3612
+ return _context37.finish(95);
3560
3613
  case 98:
3561
- _context36.next = 103;
3614
+ _context37.next = 103;
3562
3615
  break;
3563
3616
  case 100:
3564
- _context36.prev = 100;
3565
- _context36.t4 = _context36["catch"](79);
3617
+ _context37.prev = 100;
3618
+ _context37.t4 = _context37["catch"](79);
3566
3619
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
3567
- error: _context36.t4
3620
+ error: _context37.t4
3568
3621
  });
3569
3622
  case 103:
3570
3623
  // 标记订单已同步
3571
3624
  this.store.isOrderSynced = true;
3572
3625
 
3573
3626
  // 触发订单同步完成事件
3574
- _context36.next = 106;
3627
+ _context37.next = 106;
3575
3628
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3576
3629
  orderUuid: this.store.currentOrder.uuid,
3577
3630
  realOrderId: realOrderId,
@@ -3581,7 +3634,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3581
3634
  response: checkoutResponse
3582
3635
  });
3583
3636
  case 106:
3584
- return _context36.abrupt("return", {
3637
+ return _context37.abrupt("return", {
3585
3638
  success: true,
3586
3639
  orderId: realOrderId,
3587
3640
  orderUuid: this.store.currentOrder.uuid,
@@ -3589,9 +3642,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3589
3642
  });
3590
3643
  case 107:
3591
3644
  case "end":
3592
- return _context36.stop();
3645
+ return _context37.stop();
3593
3646
  }
3594
- }, _callee36, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3647
+ }, _callee37, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3595
3648
  }));
3596
3649
  function syncOrderToBackendWithReturn() {
3597
3650
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3601,15 +3654,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3601
3654
  }, {
3602
3655
  key: "setOtherParams",
3603
3656
  value: function () {
3604
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
3657
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3605
3658
  var _ref5,
3606
3659
  _ref5$cover,
3607
3660
  cover,
3608
- _args37 = arguments;
3609
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3610
- while (1) switch (_context37.prev = _context37.next) {
3661
+ _args38 = arguments;
3662
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3663
+ while (1) switch (_context38.prev = _context38.next) {
3611
3664
  case 0:
3612
- _ref5 = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3665
+ _ref5 = _args38.length > 1 && _args38[1] !== undefined ? _args38[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3613
3666
  if (cover) {
3614
3667
  this.otherParams = params;
3615
3668
  } else {
@@ -3617,9 +3670,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3617
3670
  }
3618
3671
  case 2:
3619
3672
  case "end":
3620
- return _context37.stop();
3673
+ return _context38.stop();
3621
3674
  }
3622
- }, _callee37, this);
3675
+ }, _callee38, this);
3623
3676
  }));
3624
3677
  function setOtherParams(_x27) {
3625
3678
  return _setOtherParams.apply(this, arguments);
@@ -3638,22 +3691,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3638
3691
  }, {
3639
3692
  key: "editOrderNoteByOrderIdAsync",
3640
3693
  value: (function () {
3641
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderId, note) {
3694
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(orderId, note) {
3642
3695
  var response, previousNote, errorMessage, _errorMessage;
3643
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3644
- while (1) switch (_context38.prev = _context38.next) {
3696
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3697
+ while (1) switch (_context39.prev = _context39.next) {
3645
3698
  case 0:
3646
3699
  this.logInfo('editOrderNoteByOrderIdAsync called', {
3647
3700
  orderId: orderId,
3648
3701
  note: note,
3649
3702
  noteLength: note.length
3650
3703
  });
3651
- _context38.prev = 1;
3704
+ _context39.prev = 1;
3652
3705
  if (orderId) {
3653
- _context38.next = 4;
3706
+ _context39.next = 4;
3654
3707
  break;
3655
3708
  }
3656
- return _context38.abrupt("return", {
3709
+ return _context39.abrupt("return", {
3657
3710
  success: false,
3658
3711
  message: '订单ID不能为空',
3659
3712
  orderId: orderId
@@ -3669,12 +3722,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3669
3722
  });
3670
3723
 
3671
3724
  // 调用后端API修改订单备注
3672
- _context38.next = 7;
3725
+ _context39.next = 7;
3673
3726
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3674
3727
  note: note
3675
3728
  });
3676
3729
  case 7:
3677
- response = _context38.sent;
3730
+ response = _context39.sent;
3678
3731
  this.logInfo('订单备注编辑响应:', {
3679
3732
  orderId: orderId,
3680
3733
  status: response.status,
@@ -3684,11 +3737,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3684
3737
 
3685
3738
  // 检查响应状态
3686
3739
  if (!(response.status === true || response.status === 200)) {
3687
- _context38.next = 18;
3740
+ _context39.next = 18;
3688
3741
  break;
3689
3742
  }
3690
3743
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3691
- _context38.next = 15;
3744
+ _context39.next = 15;
3692
3745
  break;
3693
3746
  }
3694
3747
  // 获取修改前的备注用于事件
@@ -3698,7 +3751,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3698
3751
  }
3699
3752
 
3700
3753
  // 触发订单备注变更事件
3701
- _context38.next = 15;
3754
+ _context39.next = 15;
3702
3755
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3703
3756
  orderUuid: this.store.currentOrder.uuid,
3704
3757
  oldNote: previousNote,
@@ -3706,7 +3759,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3706
3759
  timestamp: Date.now()
3707
3760
  });
3708
3761
  case 15:
3709
- return _context38.abrupt("return", {
3762
+ return _context39.abrupt("return", {
3710
3763
  success: true,
3711
3764
  message: response.message || '订单备注修改成功',
3712
3765
  orderId: orderId
@@ -3715,29 +3768,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3715
3768
  // API返回失败状态
3716
3769
  errorMessage = response.message || '订单备注修改失败';
3717
3770
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3718
- return _context38.abrupt("return", {
3771
+ return _context39.abrupt("return", {
3719
3772
  success: false,
3720
3773
  message: errorMessage,
3721
3774
  orderId: orderId
3722
3775
  });
3723
3776
  case 21:
3724
- _context38.next = 28;
3777
+ _context39.next = 28;
3725
3778
  break;
3726
3779
  case 23:
3727
- _context38.prev = 23;
3728
- _context38.t0 = _context38["catch"](1);
3729
- this.logError('编辑订单备注失败:', _context38.t0);
3730
- _errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : '网络错误或服务器异常';
3731
- return _context38.abrupt("return", {
3780
+ _context39.prev = 23;
3781
+ _context39.t0 = _context39["catch"](1);
3782
+ this.logError('编辑订单备注失败:', _context39.t0);
3783
+ _errorMessage = _context39.t0 instanceof Error ? _context39.t0.message : '网络错误或服务器异常';
3784
+ return _context39.abrupt("return", {
3732
3785
  success: false,
3733
3786
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3734
3787
  orderId: orderId
3735
3788
  });
3736
3789
  case 28:
3737
3790
  case "end":
3738
- return _context38.stop();
3791
+ return _context39.stop();
3739
3792
  }
3740
- }, _callee38, this, [[1, 23]]);
3793
+ }, _callee39, this, [[1, 23]]);
3741
3794
  }));
3742
3795
  function editOrderNoteByOrderIdAsync(_x28, _x29) {
3743
3796
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
@@ -3756,11 +3809,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3756
3809
  }, {
3757
3810
  key: "sendCustomerPayLinkAsync",
3758
3811
  value: (function () {
3759
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3812
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3760
3813
  var _params$order_ids, _params$emails;
3761
3814
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
3762
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3763
- while (1) switch (_context39.prev = _context39.next) {
3815
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3816
+ while (1) switch (_context40.prev = _context40.next) {
3764
3817
  case 0:
3765
3818
  this.logInfo('sendCustomerPayLinkAsync called', {
3766
3819
  orderIds: params.order_ids,
@@ -3769,21 +3822,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3769
3822
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
3770
3823
  notifyAction: params.notify_action || 'order_payment_reminder'
3771
3824
  });
3772
- _context39.prev = 1;
3825
+ _context40.prev = 1;
3773
3826
  if (!(!params.order_ids || params.order_ids.length === 0)) {
3774
- _context39.next = 4;
3827
+ _context40.next = 4;
3775
3828
  break;
3776
3829
  }
3777
- return _context39.abrupt("return", {
3830
+ return _context40.abrupt("return", {
3778
3831
  success: false,
3779
3832
  message: '订单ID列表不能为空'
3780
3833
  });
3781
3834
  case 4:
3782
3835
  if (!(!params.emails || params.emails.length === 0)) {
3783
- _context39.next = 6;
3836
+ _context40.next = 6;
3784
3837
  break;
3785
3838
  }
3786
- return _context39.abrupt("return", {
3839
+ return _context40.abrupt("return", {
3787
3840
  success: false,
3788
3841
  message: '邮箱地址列表不能为空'
3789
3842
  });
@@ -3794,10 +3847,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3794
3847
  return !emailRegex.test(email);
3795
3848
  });
3796
3849
  if (!(invalidEmails.length > 0)) {
3797
- _context39.next = 10;
3850
+ _context40.next = 10;
3798
3851
  break;
3799
3852
  }
3800
- return _context39.abrupt("return", {
3853
+ return _context40.abrupt("return", {
3801
3854
  success: false,
3802
3855
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
3803
3856
  });
@@ -3813,10 +3866,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3813
3866
  }, requestBody));
3814
3867
 
3815
3868
  // 调用后端API发送邮件
3816
- _context39.next = 14;
3869
+ _context40.next = 14;
3817
3870
  return this.request.post('/order/batch-email', requestBody);
3818
3871
  case 14:
3819
- response = _context39.sent;
3872
+ response = _context40.sent;
3820
3873
  this.logInfo('支付链接邮件发送响应:', {
3821
3874
  status: response.status,
3822
3875
  message: response.message,
@@ -3826,10 +3879,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3826
3879
 
3827
3880
  // 检查响应状态
3828
3881
  if (!(response.status === true || response.status === 200)) {
3829
- _context39.next = 20;
3882
+ _context40.next = 20;
3830
3883
  break;
3831
3884
  }
3832
- return _context39.abrupt("return", {
3885
+ return _context40.abrupt("return", {
3833
3886
  success: true,
3834
3887
  message: response.message || '支付链接邮件发送成功'
3835
3888
  });
@@ -3837,27 +3890,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3837
3890
  // API返回失败状态
3838
3891
  errorMessage = response.message || '支付链接邮件发送失败';
3839
3892
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
3840
- return _context39.abrupt("return", {
3893
+ return _context40.abrupt("return", {
3841
3894
  success: false,
3842
3895
  message: errorMessage
3843
3896
  });
3844
3897
  case 23:
3845
- _context39.next = 30;
3898
+ _context40.next = 30;
3846
3899
  break;
3847
3900
  case 25:
3848
- _context39.prev = 25;
3849
- _context39.t0 = _context39["catch"](1);
3850
- this.logError('发送客户支付链接邮件失败:', _context39.t0);
3851
- _errorMessage2 = _context39.t0 instanceof Error ? _context39.t0.message : '网络错误或服务器异常';
3852
- return _context39.abrupt("return", {
3901
+ _context40.prev = 25;
3902
+ _context40.t0 = _context40["catch"](1);
3903
+ this.logError('发送客户支付链接邮件失败:', _context40.t0);
3904
+ _errorMessage2 = _context40.t0 instanceof Error ? _context40.t0.message : '网络错误或服务器异常';
3905
+ return _context40.abrupt("return", {
3853
3906
  success: false,
3854
3907
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
3855
3908
  });
3856
3909
  case 30:
3857
3910
  case "end":
3858
- return _context39.stop();
3911
+ return _context40.stop();
3859
3912
  }
3860
- }, _callee39, this, [[1, 25]]);
3913
+ }, _callee40, this, [[1, 25]]);
3861
3914
  }));
3862
3915
  function sendCustomerPayLinkAsync(_x30) {
3863
3916
  return _sendCustomerPayLinkAsync.apply(this, arguments);
@@ -3874,22 +3927,36 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3874
3927
  }, {
3875
3928
  key: "roundAmountAsync",
3876
3929
  value: (function () {
3877
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(amount) {
3878
- var _this$otherParams$ord, _this$otherParams$ord2;
3879
- var result;
3880
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3881
- while (1) switch (_context40.prev = _context40.next) {
3930
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(amount) {
3931
+ var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
3932
+ var cashManualPayment, result;
3933
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3934
+ while (1) switch (_context41.prev = _context41.next) {
3882
3935
  case 0:
3883
- _context40.next = 2;
3936
+ // 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
3937
+ cashManualPayment = this.store.paymentMethods.find(function (p) {
3938
+ return p.code === 'CASHMANUAL';
3939
+ });
3940
+ if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
3941
+ _context41.next = 3;
3942
+ break;
3943
+ }
3944
+ return _context41.abrupt("return", {
3945
+ originalAmount: amount.toString(),
3946
+ roundedAmount: amount.toString(),
3947
+ roundingDifference: '0.00'
3948
+ });
3949
+ case 3:
3950
+ _context41.next = 5;
3884
3951
  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:
3886
- result = _context40.sent;
3887
- return _context40.abrupt("return", result);
3888
- case 4:
3952
+ case 5:
3953
+ result = _context41.sent;
3954
+ return _context41.abrupt("return", result);
3955
+ case 7:
3889
3956
  case "end":
3890
- return _context40.stop();
3957
+ return _context41.stop();
3891
3958
  }
3892
- }, _callee40, this);
3959
+ }, _callee41, this);
3893
3960
  }));
3894
3961
  function roundAmountAsync(_x31) {
3895
3962
  return _roundAmountAsync.apply(this, arguments);
@@ -3899,10 +3966,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3899
3966
  }, {
3900
3967
  key: "destroy",
3901
3968
  value: function () {
3902
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3969
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3903
3970
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3904
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3905
- while (1) switch (_context41.prev = _context41.next) {
3971
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3972
+ while (1) switch (_context42.prev = _context42.next) {
3906
3973
  case 0:
3907
3974
  // 清理钱包模块的所有缓存数据
3908
3975
  this.payment.wallet.clearAllCache();
@@ -3911,10 +3978,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3911
3978
  this.core.effects.offByModuleDestroy(this.name);
3912
3979
 
3913
3980
  // 销毁子模块
3914
- _context41.next = 4;
3981
+ _context42.next = 4;
3915
3982
  return (_this$order = this.order) === null || _this$order === void 0 || (_this$order$destroy = _this$order.destroy) === null || _this$order$destroy === void 0 ? void 0 : _this$order$destroy.call(_this$order);
3916
3983
  case 4:
3917
- _context41.next = 6;
3984
+ _context42.next = 6;
3918
3985
  return (_this$payment = this.payment) === null || _this$payment === void 0 || (_this$payment$destroy = _this$payment.destroy) === null || _this$payment$destroy === void 0 ? void 0 : _this$payment$destroy.call(_this$payment);
3919
3986
  case 6:
3920
3987
  // 取消注册模块
@@ -3922,9 +3989,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3922
3989
  console.log('[Checkout] 已销毁');
3923
3990
  case 8:
3924
3991
  case "end":
3925
- return _context41.stop();
3992
+ return _context42.stop();
3926
3993
  }
3927
- }, _callee41, this);
3994
+ }, _callee42, this);
3928
3995
  }));
3929
3996
  function destroy() {
3930
3997
  return _destroy.apply(this, arguments);
@@ -3939,12 +4006,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3939
4006
  }, {
3940
4007
  key: "resetStoreStateAsync",
3941
4008
  value: (function () {
3942
- var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
4009
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3943
4010
  var prevOrderInfo;
3944
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3945
- while (1) switch (_context42.prev = _context42.next) {
4011
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4012
+ while (1) switch (_context43.prev = _context43.next) {
3946
4013
  case 0:
3947
- _context42.prev = 0;
4014
+ _context43.prev = 0;
3948
4015
  prevOrderInfo = this.store.currentOrder ? {
3949
4016
  uuid: this.store.currentOrder.uuid,
3950
4017
  orderId: this.store.currentOrder.order_id
@@ -3973,26 +4040,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3973
4040
 
3974
4041
  // 触发订单清理事件(如果之前有订单)
3975
4042
  if (!prevOrderInfo) {
3976
- _context42.next = 17;
4043
+ _context43.next = 17;
3977
4044
  break;
3978
4045
  }
3979
- _context42.next = 17;
4046
+ _context43.next = 17;
3980
4047
  return this.core.effects.emit(CheckoutHooks.OnOrderCleared, {
3981
4048
  previousOrder: prevOrderInfo,
3982
4049
  timestamp: Date.now()
3983
4050
  });
3984
4051
  case 17:
3985
- _context42.next = 22;
4052
+ _context43.next = 22;
3986
4053
  break;
3987
4054
  case 19:
3988
- _context42.prev = 19;
3989
- _context42.t0 = _context42["catch"](0);
3990
- console.error('[Checkout] 重置 store 状态失败:', _context42.t0);
4055
+ _context43.prev = 19;
4056
+ _context43.t0 = _context43["catch"](0);
4057
+ console.error('[Checkout] 重置 store 状态失败:', _context43.t0);
3991
4058
  case 22:
3992
4059
  case "end":
3993
- return _context42.stop();
4060
+ return _context43.stop();
3994
4061
  }
3995
- }, _callee42, this, [[0, 19]]);
4062
+ }, _callee43, this, [[0, 19]]);
3996
4063
  }));
3997
4064
  function resetStoreStateAsync() {
3998
4065
  return _resetStoreStateAsync.apply(this, arguments);
@@ -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
  });
@@ -310,6 +310,10 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
310
310
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
311
311
  */
312
312
  private calculateRemainingAmountAsync;
313
+ /**
314
+ * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
315
+ */
316
+ private calculateRemainingTotalAmountAsync;
313
317
  /**
314
318
  * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
315
319
  */
@@ -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),
@@ -1818,19 +1818,37 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1818
1818
  this.logInfo("calculateRemainingAmountAsync: 计算=", result);
1819
1819
  return result;
1820
1820
  }
1821
+ /**
1822
+ * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
1823
+ */
1824
+ async calculateRemainingTotalAmountAsync() {
1825
+ if (!this.store.currentOrder) {
1826
+ this.logWarning("calculateRemainingTotalAmountAsync: 没有当前订单");
1827
+ return "0.00";
1828
+ }
1829
+ const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
1830
+ const paidAmountStr = await this.calculatePaidAmountAsync();
1831
+ const paidAmount = new import_decimal.default(paidAmountStr);
1832
+ const remainingAmount = totalAmount.sub(paidAmount);
1833
+ const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
1834
+ this.logInfo("calculateRemainingTotalAmountAsync: 计算=", result);
1835
+ return result;
1836
+ }
1821
1837
  /**
1822
1838
  * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
1823
1839
  */
1824
1840
  async updateBalanceDueAmount() {
1825
1841
  try {
1826
1842
  const remainingAmount = await this.calculateRemainingAmountAsync();
1843
+ const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
1827
1844
  const currentBalanceDueAmount = this.store.balanceDueAmount;
1828
1845
  if (remainingAmount !== currentBalanceDueAmount) {
1829
1846
  this.store.balanceDueAmount = remainingAmount;
1830
1847
  await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
1831
1848
  oldAmount: currentBalanceDueAmount,
1832
1849
  newAmount: remainingAmount,
1833
- timestamp: Date.now()
1850
+ timestamp: Date.now(),
1851
+ totalAmount: remainingTotalAmount
1834
1852
  });
1835
1853
  this.logInfo("balanceDueAmount 已自动更新:", {
1836
1854
  oldAmount: currentBalanceDueAmount,
@@ -1864,7 +1882,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1864
1882
  }
1865
1883
  const amount = new import_decimal.default(item.amount || "0");
1866
1884
  const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
1867
- return sum.add(amount.add(roundingAmount.abs()));
1885
+ return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
1868
1886
  }, new import_decimal.default(0));
1869
1887
  if (depositPaidAmount.gte((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount)) {
1870
1888
  this.store.currentOrder = {
@@ -1877,13 +1895,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1877
1895
  }
1878
1896
  }
1879
1897
  const remainingAmount = await this.calculateRemainingAmountAsync();
1898
+ const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
1880
1899
  const currentStateAmount = this.store.stateAmount;
1881
1900
  if (remainingAmount !== currentStateAmount) {
1882
1901
  this.store.stateAmount = remainingAmount;
1883
1902
  this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
1884
1903
  oldAmount: currentStateAmount,
1885
1904
  newAmount: remainingAmount,
1886
- timestamp: Date.now()
1905
+ timestamp: Date.now(),
1906
+ totalAmount: remainingTotalAmount
1887
1907
  });
1888
1908
  this.logInfo("stateAmount 已自动更新为剩余金额:", {
1889
1909
  oldAmount: currentStateAmount,
@@ -1950,7 +1970,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1950
1970
  code: p.code,
1951
1971
  amount: p.amount,
1952
1972
  rounding_amount: p.rounding_amount,
1953
- effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(p.rounding_amount || "0"))).toFixed(2),
1973
+ effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
1954
1974
  voucher_id: p.voucher_id,
1955
1975
  status: p.status
1956
1976
  }))
@@ -2433,11 +2453,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2433
2453
  * @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
2434
2454
  */
2435
2455
  async roundAmountAsync(amount) {
2436
- var _a, _b;
2456
+ var _a, _b, _c;
2457
+ const cashManualPayment = this.store.paymentMethods.find((p) => p.code === "CASHMANUAL");
2458
+ if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
2459
+ return {
2460
+ originalAmount: amount.toString(),
2461
+ roundedAmount: amount.toString(),
2462
+ roundingDifference: "0.00"
2463
+ };
2464
+ }
2437
2465
  const result = await this.payment.roundAmountAsync(
2438
2466
  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
2467
+ (_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
2468
+ (_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
2441
2469
  );
2442
2470
  return result;
2443
2471
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.28",
4
+ "version": "2.1.29",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",