@pisell/pisellos 2.2.24 → 2.2.25
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.
- package/dist/modules/Summary/utils.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +129 -75
- package/lib/modules/Summary/utils.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +311 -272
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
|
21
21
|
* @return {*}
|
|
22
22
|
* @Author: xiangfeng.xue
|
|
23
23
|
*/
|
|
24
|
-
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00"
|
|
24
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|
|
25
25
|
/**
|
|
26
26
|
* @title: 计算定金
|
|
27
27
|
* @param items - 购物车商品数组
|
|
@@ -343,7 +343,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
343
343
|
};
|
|
344
344
|
setOtherData(key: string, value: any): void;
|
|
345
345
|
getOtherData(key: string): any;
|
|
346
|
-
getProductTypeById(id: number): Promise<"
|
|
346
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
347
347
|
/**
|
|
348
348
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
349
349
|
*
|
|
@@ -20,6 +20,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
20
20
|
private otherParams;
|
|
21
21
|
private logger;
|
|
22
22
|
private calculationCache;
|
|
23
|
+
private syncOrderToBackendInFlightByOrderKey;
|
|
23
24
|
order: OrderModule;
|
|
24
25
|
payment: PaymentModule;
|
|
25
26
|
constructor(name?: string, version?: string);
|
|
@@ -61,6 +61,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
61
61
|
// LoggerManager 实例
|
|
62
62
|
// 计算缓存(用于性能优化)
|
|
63
63
|
_defineProperty(_assertThisInitialized(_this), "calculationCache", {});
|
|
64
|
+
// 同步订单到后端锁(按订单维度),防止短时间内重复触发导致同一订单多次同步
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "syncOrderToBackendInFlightByOrderKey", new Map());
|
|
64
66
|
// 直接挂载的模块
|
|
65
67
|
_defineProperty(_assertThisInitialized(_this), "order", void 0);
|
|
66
68
|
_defineProperty(_assertThisInitialized(_this), "payment", void 0);
|
|
@@ -3760,7 +3762,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3760
3762
|
key: "syncOrderToBackendWithReturn",
|
|
3761
3763
|
value: (function () {
|
|
3762
3764
|
var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
|
|
3763
|
-
var _this6 = this
|
|
3765
|
+
var _this6 = this;
|
|
3766
|
+
var isManual,
|
|
3767
|
+
customPaymentItems,
|
|
3768
|
+
paymentStatus,
|
|
3769
|
+
orderLockKey,
|
|
3770
|
+
existingInFlight,
|
|
3771
|
+
resolveInFlight,
|
|
3772
|
+
rejectInFlight,
|
|
3773
|
+
inFlightPromise,
|
|
3764
3774
|
_this$store$currentOr26,
|
|
3765
3775
|
_this$store$currentOr27,
|
|
3766
3776
|
_this$store$currentCu2,
|
|
@@ -3768,10 +3778,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3768
3778
|
_this$store$localOrde,
|
|
3769
3779
|
_this$store$localOrde2,
|
|
3770
3780
|
_checkoutResponse3,
|
|
3771
|
-
_checkoutResponse4
|
|
3772
|
-
var isManual,
|
|
3773
|
-
customPaymentItems,
|
|
3774
|
-
paymentStatus,
|
|
3781
|
+
_checkoutResponse4,
|
|
3775
3782
|
currentOrderId,
|
|
3776
3783
|
isUpdateOperation,
|
|
3777
3784
|
paymentItems,
|
|
@@ -3804,6 +3811,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3804
3811
|
_iterator3,
|
|
3805
3812
|
_step3,
|
|
3806
3813
|
paymentUuid,
|
|
3814
|
+
result,
|
|
3815
|
+
currentInFlight,
|
|
3807
3816
|
_args39 = arguments;
|
|
3808
3817
|
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
3809
3818
|
while (1) switch (_context39.prev = _context39.next) {
|
|
@@ -3817,6 +3826,36 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3817
3826
|
}
|
|
3818
3827
|
throw new Error('缺少必要的订单数据,无法同步到后端');
|
|
3819
3828
|
case 5:
|
|
3829
|
+
orderLockKey = this.store.currentOrder.uuid || this.store.currentOrder.order_id;
|
|
3830
|
+
if (orderLockKey) {
|
|
3831
|
+
_context39.next = 8;
|
|
3832
|
+
break;
|
|
3833
|
+
}
|
|
3834
|
+
throw new Error('缺少订单标识,无法同步到后端');
|
|
3835
|
+
case 8:
|
|
3836
|
+
existingInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
|
|
3837
|
+
if (!existingInFlight) {
|
|
3838
|
+
_context39.next = 14;
|
|
3839
|
+
break;
|
|
3840
|
+
}
|
|
3841
|
+
this.logInfo('syncOrderToBackendWithReturn 触发锁:当前订单正在同步中,将等待当前同步结束', {
|
|
3842
|
+
orderLockKey: orderLockKey,
|
|
3843
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
3844
|
+
orderId: this.store.currentOrder.order_id,
|
|
3845
|
+
isManual: isManual,
|
|
3846
|
+
hasCustomPaymentItems: !!customPaymentItems
|
|
3847
|
+
});
|
|
3848
|
+
_context39.next = 13;
|
|
3849
|
+
return existingInFlight;
|
|
3850
|
+
case 13:
|
|
3851
|
+
return _context39.abrupt("return", _context39.sent);
|
|
3852
|
+
case 14:
|
|
3853
|
+
inFlightPromise = new Promise(function (resolve, reject) {
|
|
3854
|
+
resolveInFlight = resolve;
|
|
3855
|
+
rejectInFlight = reject;
|
|
3856
|
+
});
|
|
3857
|
+
this.syncOrderToBackendInFlightByOrderKey.set(orderLockKey, inFlightPromise);
|
|
3858
|
+
_context39.prev = 16;
|
|
3820
3859
|
this.logInfo('syncOrderToBackendWithReturn called', {
|
|
3821
3860
|
isManual: isManual
|
|
3822
3861
|
});
|
|
@@ -3833,14 +3872,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3833
3872
|
// 获取当前订单的支付项
|
|
3834
3873
|
_context39.t0 = customPaymentItems;
|
|
3835
3874
|
if (_context39.t0) {
|
|
3836
|
-
_context39.next =
|
|
3875
|
+
_context39.next = 26;
|
|
3837
3876
|
break;
|
|
3838
3877
|
}
|
|
3839
|
-
_context39.next =
|
|
3878
|
+
_context39.next = 25;
|
|
3840
3879
|
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
3841
|
-
case
|
|
3880
|
+
case 25:
|
|
3842
3881
|
_context39.t0 = _context39.sent;
|
|
3843
|
-
case
|
|
3882
|
+
case 26:
|
|
3844
3883
|
paymentItems = _context39.t0;
|
|
3845
3884
|
// 处理支付项数据,确保包含完整的 metadata
|
|
3846
3885
|
processedPaymentItems = paymentItems.map(function (item) {
|
|
@@ -3990,7 +4029,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3990
4029
|
|
|
3991
4030
|
// 发送下单接口请求开始事件
|
|
3992
4031
|
startTime = Date.now();
|
|
3993
|
-
_context39.next =
|
|
4032
|
+
_context39.next = 42;
|
|
3994
4033
|
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
|
|
3995
4034
|
orderUuid: this.store.currentOrder.uuid,
|
|
3996
4035
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3998,9 +4037,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3998
4037
|
paymentItemCount: paymentItems.length,
|
|
3999
4038
|
timestamp: startTime
|
|
4000
4039
|
});
|
|
4001
|
-
case
|
|
4040
|
+
case 42:
|
|
4002
4041
|
submitSuccess = false;
|
|
4003
|
-
_context39.prev =
|
|
4042
|
+
_context39.prev = 43;
|
|
4004
4043
|
// 记录接口调用参数
|
|
4005
4044
|
this.logInfo('Calling backend checkout API', _objectSpread({
|
|
4006
4045
|
url: '/order/checkout',
|
|
@@ -4008,24 +4047,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4008
4047
|
}, orderParams));
|
|
4009
4048
|
|
|
4010
4049
|
// 调用 Order 模块的专用 createOrderByCheckout 方法
|
|
4011
|
-
_context39.next =
|
|
4050
|
+
_context39.next = 47;
|
|
4012
4051
|
return this.order.createOrderByCheckout(orderParams);
|
|
4013
|
-
case
|
|
4052
|
+
case 47:
|
|
4014
4053
|
checkoutResponse = _context39.sent;
|
|
4015
4054
|
submitSuccess = true;
|
|
4016
4055
|
this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
|
|
4017
4056
|
this.logInfo('下单接口调用成功', checkoutResponse);
|
|
4018
|
-
_context39.next =
|
|
4057
|
+
_context39.next = 61;
|
|
4019
4058
|
break;
|
|
4020
|
-
case
|
|
4021
|
-
_context39.prev =
|
|
4022
|
-
_context39.t1 = _context39["catch"](
|
|
4059
|
+
case 53:
|
|
4060
|
+
_context39.prev = 53;
|
|
4061
|
+
_context39.t1 = _context39["catch"](43);
|
|
4023
4062
|
submitSuccess = false;
|
|
4024
4063
|
submitError = _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1);
|
|
4025
4064
|
this.logError('下单接口调用失败:', submitError);
|
|
4026
4065
|
|
|
4027
4066
|
// 发送订单同步失败事件(网络错误或请求失败)
|
|
4028
|
-
_context39.next =
|
|
4067
|
+
_context39.next = 60;
|
|
4029
4068
|
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
4030
4069
|
orderUuid: this.store.currentOrder.uuid,
|
|
4031
4070
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -4035,11 +4074,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4035
4074
|
duration: Date.now() - startTime,
|
|
4036
4075
|
timestamp: Date.now()
|
|
4037
4076
|
});
|
|
4038
|
-
case
|
|
4077
|
+
case 60:
|
|
4039
4078
|
throw _context39.t1;
|
|
4040
|
-
case
|
|
4041
|
-
_context39.prev =
|
|
4042
|
-
_context39.next =
|
|
4079
|
+
case 61:
|
|
4080
|
+
_context39.prev = 61;
|
|
4081
|
+
_context39.next = 64;
|
|
4043
4082
|
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
|
|
4044
4083
|
success: submitSuccess,
|
|
4045
4084
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -4050,18 +4089,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4050
4089
|
duration: Date.now() - startTime,
|
|
4051
4090
|
timestamp: Date.now()
|
|
4052
4091
|
});
|
|
4053
|
-
case
|
|
4054
|
-
return _context39.finish(
|
|
4055
|
-
case
|
|
4092
|
+
case 64:
|
|
4093
|
+
return _context39.finish(61);
|
|
4094
|
+
case 65:
|
|
4056
4095
|
// 检查响应状态是否为成功状态
|
|
4057
4096
|
responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
|
|
4058
4097
|
isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
|
|
4059
4098
|
if (isSuccessResponse) {
|
|
4060
|
-
_context39.next =
|
|
4099
|
+
_context39.next = 72;
|
|
4061
4100
|
break;
|
|
4062
4101
|
}
|
|
4063
4102
|
errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
|
|
4064
|
-
_context39.next =
|
|
4103
|
+
_context39.next = 71;
|
|
4065
4104
|
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
4066
4105
|
orderUuid: this.store.currentOrder.uuid,
|
|
4067
4106
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -4072,18 +4111,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4072
4111
|
duration: Date.now() - startTime,
|
|
4073
4112
|
timestamp: Date.now()
|
|
4074
4113
|
});
|
|
4075
|
-
case
|
|
4114
|
+
case 71:
|
|
4076
4115
|
throw new Error(errorMessage);
|
|
4077
|
-
case
|
|
4116
|
+
case 72:
|
|
4078
4117
|
if (!isUpdateOperation) {
|
|
4079
|
-
_context39.next =
|
|
4118
|
+
_context39.next = 76;
|
|
4080
4119
|
break;
|
|
4081
4120
|
}
|
|
4082
4121
|
// 更新操作:使用现有的订单ID
|
|
4083
4122
|
realOrderId = currentOrderId;
|
|
4084
|
-
_context39.next =
|
|
4123
|
+
_context39.next = 109;
|
|
4085
4124
|
break;
|
|
4086
|
-
case
|
|
4125
|
+
case 76:
|
|
4087
4126
|
// 创建操作:从响应中提取新的订单ID
|
|
4088
4127
|
extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
|
|
4089
4128
|
if (!extractedOrderId) {
|
|
@@ -4105,12 +4144,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4105
4144
|
oldOrderId: this.store.currentOrder.order_id,
|
|
4106
4145
|
newOrderId: realOrderId
|
|
4107
4146
|
});
|
|
4108
|
-
_context39.prev =
|
|
4147
|
+
_context39.prev = 82;
|
|
4109
4148
|
latestPaymentStatus = this.store.currentOrder.payment_status;
|
|
4110
4149
|
previousOrder = this.store.currentOrder;
|
|
4111
|
-
_context39.next =
|
|
4150
|
+
_context39.next = 87;
|
|
4112
4151
|
return this.payment.replaceOrderIdByUuidAsync(previousOrder.uuid, realOrderId);
|
|
4113
|
-
case
|
|
4152
|
+
case 87:
|
|
4114
4153
|
updatedOrder = _context39.sent;
|
|
4115
4154
|
this.logInfo('Payment模块替换订单ID结果:', {
|
|
4116
4155
|
wasSuccessful: !!updatedOrder,
|
|
@@ -4118,7 +4157,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4118
4157
|
expectedOrderId: realOrderId
|
|
4119
4158
|
});
|
|
4120
4159
|
if (!updatedOrder) {
|
|
4121
|
-
_context39.next =
|
|
4160
|
+
_context39.next = 98;
|
|
4122
4161
|
break;
|
|
4123
4162
|
}
|
|
4124
4163
|
this.logInfo('Payment模块返回的更新后订单:', {
|
|
@@ -4134,18 +4173,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4134
4173
|
|
|
4135
4174
|
// 同步更新 Payment 模块 DB,避免后续读取 DB 时又拿回旧状态
|
|
4136
4175
|
if (!latestPaymentStatus) {
|
|
4137
|
-
_context39.next =
|
|
4176
|
+
_context39.next = 95;
|
|
4138
4177
|
break;
|
|
4139
4178
|
}
|
|
4140
|
-
_context39.next =
|
|
4179
|
+
_context39.next = 95;
|
|
4141
4180
|
return this.payment.updateOrderAsync(previousOrder.uuid, {
|
|
4142
4181
|
payment_status: latestPaymentStatus
|
|
4143
4182
|
});
|
|
4144
|
-
case
|
|
4183
|
+
case 95:
|
|
4145
4184
|
this.logInfo('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
|
|
4146
|
-
_context39.next =
|
|
4185
|
+
_context39.next = 102;
|
|
4147
4186
|
break;
|
|
4148
|
-
case
|
|
4187
|
+
case 98:
|
|
4149
4188
|
this.logError('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
|
|
4150
4189
|
|
|
4151
4190
|
// 如果替换失败,手动更新订单ID
|
|
@@ -4156,62 +4195,62 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4156
4195
|
afterReplacement: this.store.currentOrder.order_id,
|
|
4157
4196
|
目标ID: realOrderId
|
|
4158
4197
|
});
|
|
4159
|
-
case
|
|
4160
|
-
_context39.next =
|
|
4198
|
+
case 102:
|
|
4199
|
+
_context39.next = 109;
|
|
4161
4200
|
break;
|
|
4162
|
-
case
|
|
4163
|
-
_context39.prev =
|
|
4164
|
-
_context39.t2 = _context39["catch"](
|
|
4201
|
+
case 104:
|
|
4202
|
+
_context39.prev = 104;
|
|
4203
|
+
_context39.t2 = _context39["catch"](82);
|
|
4165
4204
|
this.logError('调用Payment模块替换订单ID时发生错误:', _context39.t2);
|
|
4166
4205
|
|
|
4167
4206
|
// 发生错误时也进行手动替换
|
|
4168
4207
|
this.store.currentOrder.order_id = realOrderId;
|
|
4169
4208
|
this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
|
|
4170
|
-
case
|
|
4171
|
-
_context39.prev =
|
|
4209
|
+
case 109:
|
|
4210
|
+
_context39.prev = 109;
|
|
4172
4211
|
syncedPaymentUuids = processedPaymentItems.filter(function (item) {
|
|
4173
4212
|
return item.status !== 'voided';
|
|
4174
4213
|
}).map(function (item) {
|
|
4175
4214
|
return item.uuid;
|
|
4176
4215
|
}).filter(Boolean);
|
|
4177
4216
|
_iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
|
|
4178
|
-
_context39.prev =
|
|
4217
|
+
_context39.prev = 112;
|
|
4179
4218
|
_iterator3.s();
|
|
4180
|
-
case
|
|
4219
|
+
case 114:
|
|
4181
4220
|
if ((_step3 = _iterator3.n()).done) {
|
|
4182
|
-
_context39.next =
|
|
4221
|
+
_context39.next = 120;
|
|
4183
4222
|
break;
|
|
4184
4223
|
}
|
|
4185
4224
|
paymentUuid = _step3.value;
|
|
4186
|
-
_context39.next =
|
|
4225
|
+
_context39.next = 118;
|
|
4187
4226
|
return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
|
|
4188
4227
|
isSynced: true,
|
|
4189
4228
|
syncError: undefined
|
|
4190
4229
|
});
|
|
4191
|
-
case
|
|
4192
|
-
_context39.next =
|
|
4230
|
+
case 118:
|
|
4231
|
+
_context39.next = 114;
|
|
4193
4232
|
break;
|
|
4194
|
-
case
|
|
4195
|
-
_context39.next =
|
|
4233
|
+
case 120:
|
|
4234
|
+
_context39.next = 125;
|
|
4196
4235
|
break;
|
|
4197
|
-
case
|
|
4198
|
-
_context39.prev =
|
|
4199
|
-
_context39.t3 = _context39["catch"](
|
|
4236
|
+
case 122:
|
|
4237
|
+
_context39.prev = 122;
|
|
4238
|
+
_context39.t3 = _context39["catch"](112);
|
|
4200
4239
|
_iterator3.e(_context39.t3);
|
|
4201
|
-
case
|
|
4202
|
-
_context39.prev =
|
|
4240
|
+
case 125:
|
|
4241
|
+
_context39.prev = 125;
|
|
4203
4242
|
_iterator3.f();
|
|
4204
|
-
return _context39.finish(
|
|
4205
|
-
case
|
|
4206
|
-
_context39.next =
|
|
4243
|
+
return _context39.finish(125);
|
|
4244
|
+
case 128:
|
|
4245
|
+
_context39.next = 133;
|
|
4207
4246
|
break;
|
|
4208
|
-
case
|
|
4209
|
-
_context39.prev =
|
|
4210
|
-
_context39.t4 = _context39["catch"](
|
|
4247
|
+
case 130:
|
|
4248
|
+
_context39.prev = 130;
|
|
4249
|
+
_context39.t4 = _context39["catch"](109);
|
|
4211
4250
|
this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
|
|
4212
4251
|
error: _context39.t4
|
|
4213
4252
|
});
|
|
4214
|
-
case
|
|
4253
|
+
case 133:
|
|
4215
4254
|
// 标记订单已同步
|
|
4216
4255
|
this.store.isOrderSynced = true;
|
|
4217
4256
|
|
|
@@ -4219,7 +4258,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4219
4258
|
this.clearCalculationCache();
|
|
4220
4259
|
|
|
4221
4260
|
// 触发订单同步完成事件
|
|
4222
|
-
_context39.next =
|
|
4261
|
+
_context39.next = 137;
|
|
4223
4262
|
return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
|
|
4224
4263
|
orderUuid: this.store.currentOrder.uuid,
|
|
4225
4264
|
realOrderId: realOrderId,
|
|
@@ -4228,18 +4267,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4228
4267
|
isManual: isManual,
|
|
4229
4268
|
response: checkoutResponse
|
|
4230
4269
|
});
|
|
4231
|
-
case
|
|
4232
|
-
|
|
4270
|
+
case 137:
|
|
4271
|
+
// 返回同步结果
|
|
4272
|
+
result = {
|
|
4233
4273
|
success: true,
|
|
4234
4274
|
orderId: realOrderId,
|
|
4235
4275
|
orderUuid: this.store.currentOrder.uuid,
|
|
4236
4276
|
response: checkoutResponse
|
|
4237
|
-
}
|
|
4238
|
-
|
|
4277
|
+
};
|
|
4278
|
+
resolveInFlight(result);
|
|
4279
|
+
return _context39.abrupt("return", result);
|
|
4280
|
+
case 142:
|
|
4281
|
+
_context39.prev = 142;
|
|
4282
|
+
_context39.t5 = _context39["catch"](16);
|
|
4283
|
+
rejectInFlight(_context39.t5);
|
|
4284
|
+
throw _context39.t5;
|
|
4285
|
+
case 146:
|
|
4286
|
+
_context39.prev = 146;
|
|
4287
|
+
currentInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
|
|
4288
|
+
if (currentInFlight === inFlightPromise) {
|
|
4289
|
+
this.syncOrderToBackendInFlightByOrderKey.delete(orderLockKey);
|
|
4290
|
+
}
|
|
4291
|
+
return _context39.finish(146);
|
|
4292
|
+
case 150:
|
|
4239
4293
|
case "end":
|
|
4240
4294
|
return _context39.stop();
|
|
4241
4295
|
}
|
|
4242
|
-
}, _callee39, this, [[
|
|
4296
|
+
}, _callee39, this, [[16, 142, 146, 150], [43, 53, 61, 65], [82, 104], [109, 130], [112, 122, 125, 128]]);
|
|
4243
4297
|
}));
|
|
4244
4298
|
function syncOrderToBackendWithReturn() {
|
|
4245
4299
|
return _syncOrderToBackendWithReturn.apply(this, arguments);
|
|
@@ -21,7 +21,7 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
|
21
21
|
* @return {*}
|
|
22
22
|
* @Author: xiangfeng.xue
|
|
23
23
|
*/
|
|
24
|
-
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00"
|
|
24
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|
|
25
25
|
/**
|
|
26
26
|
* @title: 计算定金
|
|
27
27
|
* @param items - 购物车商品数组
|
|
@@ -343,7 +343,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
343
343
|
};
|
|
344
344
|
setOtherData(key: string, value: any): void;
|
|
345
345
|
getOtherData(key: string): any;
|
|
346
|
-
getProductTypeById(id: number): Promise<"
|
|
346
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
347
347
|
/**
|
|
348
348
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
349
349
|
*
|
|
@@ -20,6 +20,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
20
20
|
private otherParams;
|
|
21
21
|
private logger;
|
|
22
22
|
private calculationCache;
|
|
23
|
+
private syncOrderToBackendInFlightByOrderKey;
|
|
23
24
|
order: OrderModule;
|
|
24
25
|
payment: PaymentModule;
|
|
25
26
|
constructor(name?: string, version?: string);
|
|
@@ -52,6 +52,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
52
52
|
// LoggerManager 实例
|
|
53
53
|
// 计算缓存(用于性能优化)
|
|
54
54
|
this.calculationCache = {};
|
|
55
|
+
// 同步订单到后端锁(按订单维度),防止短时间内重复触发导致同一订单多次同步
|
|
56
|
+
this.syncOrderToBackendInFlightByOrderKey = /* @__PURE__ */ new Map();
|
|
55
57
|
}
|
|
56
58
|
async initialize(core, options) {
|
|
57
59
|
this.core = core;
|
|
@@ -2373,305 +2375,342 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2373
2375
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2374
2376
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2375
2377
|
}
|
|
2376
|
-
this.
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
this.logInfo(`开始同步订单到后端...`, {
|
|
2380
|
-
currentOrderId,
|
|
2381
|
-
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2382
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2383
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2384
|
-
isManual
|
|
2385
|
-
});
|
|
2386
|
-
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2387
|
-
const processedPaymentItems = paymentItems.map((item) => {
|
|
2388
|
-
var _a2, _b2;
|
|
2389
|
-
return {
|
|
2390
|
-
...item,
|
|
2391
|
-
metadata: {
|
|
2392
|
-
...item.metadata,
|
|
2393
|
-
rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
|
|
2394
|
-
shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
|
|
2395
|
-
}
|
|
2396
|
-
};
|
|
2397
|
-
});
|
|
2398
|
-
let finalDepositAmount;
|
|
2399
|
-
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
2400
|
-
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
2401
|
-
if (manualDepositValue.gt(0)) {
|
|
2402
|
-
finalDepositAmount = manualDepositAmount;
|
|
2403
|
-
this.logInfo("使用手动设置的定金金额", {
|
|
2404
|
-
manualDepositAmount,
|
|
2405
|
-
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
2406
|
-
});
|
|
2407
|
-
} else {
|
|
2408
|
-
finalDepositAmount = "0.00";
|
|
2409
|
-
this.logInfo("定金金额为0", {
|
|
2410
|
-
manualDepositAmount,
|
|
2411
|
-
reason: "手动设置和计算值均为0"
|
|
2412
|
-
});
|
|
2378
|
+
const orderLockKey = this.store.currentOrder.uuid || this.store.currentOrder.order_id;
|
|
2379
|
+
if (!orderLockKey) {
|
|
2380
|
+
throw new Error("缺少订单标识,无法同步到后端");
|
|
2413
2381
|
}
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
this.
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
const amt = new import_decimal.default(item.amount || "0");
|
|
2428
|
-
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2429
|
-
return sum.plus(amt).sub(rounding);
|
|
2430
|
-
}, new import_decimal.default(0)).toFixed(2);
|
|
2382
|
+
const existingInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
|
|
2383
|
+
if (existingInFlight) {
|
|
2384
|
+
this.logInfo(
|
|
2385
|
+
"syncOrderToBackendWithReturn 触发锁:当前订单正在同步中,将等待当前同步结束",
|
|
2386
|
+
{
|
|
2387
|
+
orderLockKey,
|
|
2388
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2389
|
+
orderId: this.store.currentOrder.order_id,
|
|
2390
|
+
isManual,
|
|
2391
|
+
hasCustomPaymentItems: !!customPaymentItems
|
|
2392
|
+
}
|
|
2393
|
+
);
|
|
2394
|
+
return await existingInFlight;
|
|
2431
2395
|
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
amount: item.amount,
|
|
2438
|
-
rounding_amount: item.rounding_amount,
|
|
2439
|
-
order_payment_type: item.order_payment_type,
|
|
2440
|
-
status: item.status
|
|
2441
|
-
})),
|
|
2442
|
-
manualDepositAmount,
|
|
2443
|
-
finalDepositAmount,
|
|
2444
|
-
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
2396
|
+
let resolveInFlight;
|
|
2397
|
+
let rejectInFlight;
|
|
2398
|
+
const inFlightPromise = new Promise((resolve, reject) => {
|
|
2399
|
+
resolveInFlight = resolve;
|
|
2400
|
+
rejectInFlight = reject;
|
|
2445
2401
|
});
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
const orderParams = {
|
|
2462
|
-
...this.store.localOrderData,
|
|
2463
|
-
payment_status: orderPaymentStatus,
|
|
2464
|
-
type: this.store.localOrderData.type,
|
|
2465
|
-
platform: this.store.localOrderData.platform,
|
|
2466
|
-
payments: processedPaymentItems,
|
|
2467
|
-
// 使用处理过的支付项数据
|
|
2468
|
-
customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
|
|
2469
|
-
// 添加客户ID
|
|
2470
|
-
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2471
|
-
// core 有
|
|
2472
|
-
tax_title: this.otherParams.tax_title,
|
|
2473
|
-
// core 没有
|
|
2474
|
-
tax_rate: this.otherParams.tax_rate,
|
|
2475
|
-
// core 有
|
|
2476
|
-
tax_country_code: this.otherParams.tax_country_code,
|
|
2477
|
-
// core 没有
|
|
2478
|
-
currency_code: this.otherParams.currency_code,
|
|
2479
|
-
currency_symbol: this.otherParams.currency_symbol,
|
|
2480
|
-
currency_format: this.otherParams.currency_format,
|
|
2481
|
-
is_deposit: (((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
2482
|
-
deposit_amount: finalDepositAmount,
|
|
2483
|
-
// 使用最终确定的定金金额(手动设置优先)
|
|
2484
|
-
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
2485
|
-
note: this.store.localOrderData.shop_note,
|
|
2486
|
-
bookings: (_e = this.store.localOrderData.bookings) == null ? void 0 : _e.map((item) => {
|
|
2402
|
+
this.syncOrderToBackendInFlightByOrderKey.set(orderLockKey, inFlightPromise);
|
|
2403
|
+
try {
|
|
2404
|
+
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2405
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
2406
|
+
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
2407
|
+
this.logInfo(`开始同步订单到后端...`, {
|
|
2408
|
+
currentOrderId,
|
|
2409
|
+
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2410
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2411
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
2412
|
+
isManual
|
|
2413
|
+
});
|
|
2414
|
+
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2415
|
+
const processedPaymentItems = paymentItems.map((item) => {
|
|
2416
|
+
var _a2, _b2;
|
|
2487
2417
|
return {
|
|
2488
2418
|
...item,
|
|
2489
|
-
|
|
2490
|
-
...item.
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2419
|
+
metadata: {
|
|
2420
|
+
...item.metadata,
|
|
2421
|
+
rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
|
|
2422
|
+
shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
|
|
2423
|
+
}
|
|
2494
2424
|
};
|
|
2495
|
-
})
|
|
2496
|
-
|
|
2497
|
-
|
|
2425
|
+
});
|
|
2426
|
+
let finalDepositAmount;
|
|
2427
|
+
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
2428
|
+
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
2429
|
+
if (manualDepositValue.gt(0)) {
|
|
2430
|
+
finalDepositAmount = manualDepositAmount;
|
|
2431
|
+
this.logInfo("使用手动设置的定金金额", {
|
|
2432
|
+
manualDepositAmount,
|
|
2433
|
+
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
2434
|
+
});
|
|
2435
|
+
} else {
|
|
2436
|
+
finalDepositAmount = "0.00";
|
|
2437
|
+
this.logInfo("定金金额为0", {
|
|
2438
|
+
manualDepositAmount,
|
|
2439
|
+
reason: "手动设置和计算值均为0"
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
|
|
2443
|
+
finalDepositAmount = "0.00";
|
|
2444
|
+
this.store.currentOrder.is_deposit = 0;
|
|
2445
|
+
}
|
|
2446
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.some((item) => item.order_payment_type === "deposit")) {
|
|
2447
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2448
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2449
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2450
|
+
return sum.plus(amt).sub(rounding);
|
|
2451
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2452
|
+
}
|
|
2453
|
+
if (this.store.currentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
|
|
2454
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2455
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2456
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2457
|
+
return sum.plus(amt).sub(rounding);
|
|
2458
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2459
|
+
}
|
|
2460
|
+
this.logInfo("定金金额确定结果", {
|
|
2461
|
+
depositPaymentItemsCount: processedPaymentItems.length,
|
|
2462
|
+
depositPaymentItems: processedPaymentItems.map((item) => ({
|
|
2463
|
+
uuid: item.uuid,
|
|
2464
|
+
code: item.code,
|
|
2465
|
+
amount: item.amount,
|
|
2466
|
+
rounding_amount: item.rounding_amount,
|
|
2467
|
+
order_payment_type: item.order_payment_type,
|
|
2468
|
+
status: item.status
|
|
2469
|
+
})),
|
|
2470
|
+
manualDepositAmount,
|
|
2471
|
+
finalDepositAmount,
|
|
2472
|
+
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
2473
|
+
});
|
|
2474
|
+
let orderPaymentStatus = paymentStatus;
|
|
2475
|
+
if (!orderPaymentStatus) {
|
|
2476
|
+
const totalPaidAmount = processedPaymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => {
|
|
2477
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2478
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2479
|
+
return sum.plus(amt).sub(rounding);
|
|
2480
|
+
}, new import_decimal.default(0));
|
|
2481
|
+
if (totalPaidAmount.gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
|
|
2482
|
+
orderPaymentStatus = "paid";
|
|
2483
|
+
} else if (totalPaidAmount.gt(0)) {
|
|
2484
|
+
orderPaymentStatus = "partially_paid";
|
|
2485
|
+
} else {
|
|
2486
|
+
orderPaymentStatus = "unpaid";
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
const orderParams = {
|
|
2490
|
+
...this.store.localOrderData,
|
|
2491
|
+
payment_status: orderPaymentStatus,
|
|
2492
|
+
type: this.store.localOrderData.type,
|
|
2493
|
+
platform: this.store.localOrderData.platform,
|
|
2494
|
+
payments: processedPaymentItems,
|
|
2495
|
+
// 使用处理过的支付项数据
|
|
2496
|
+
customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
|
|
2497
|
+
// 添加客户ID
|
|
2498
|
+
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2499
|
+
// core 有
|
|
2500
|
+
tax_title: this.otherParams.tax_title,
|
|
2501
|
+
// core 没有
|
|
2502
|
+
tax_rate: this.otherParams.tax_rate,
|
|
2503
|
+
// core 有
|
|
2504
|
+
tax_country_code: this.otherParams.tax_country_code,
|
|
2505
|
+
// core 没有
|
|
2506
|
+
currency_code: this.otherParams.currency_code,
|
|
2507
|
+
currency_symbol: this.otherParams.currency_symbol,
|
|
2508
|
+
currency_format: this.otherParams.currency_format,
|
|
2509
|
+
is_deposit: (((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
2510
|
+
deposit_amount: finalDepositAmount,
|
|
2511
|
+
// 使用最终确定的定金金额(手动设置优先)
|
|
2512
|
+
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
2513
|
+
note: this.store.localOrderData.shop_note,
|
|
2514
|
+
bookings: (_e = this.store.localOrderData.bookings) == null ? void 0 : _e.map((item) => {
|
|
2498
2515
|
return {
|
|
2499
2516
|
...item,
|
|
2500
|
-
|
|
2517
|
+
product: {
|
|
2518
|
+
...item.product,
|
|
2519
|
+
custom_deposit_data: void 0
|
|
2520
|
+
},
|
|
2501
2521
|
deposit: void 0
|
|
2502
2522
|
};
|
|
2523
|
+
}),
|
|
2524
|
+
relation_products: (_f = this.store.localOrderData.relation_products) == null ? void 0 : _f.map(
|
|
2525
|
+
(item) => {
|
|
2526
|
+
return {
|
|
2527
|
+
...item,
|
|
2528
|
+
custom_deposit_data: void 0,
|
|
2529
|
+
deposit: void 0
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
)
|
|
2533
|
+
};
|
|
2534
|
+
if (isUpdateOperation) {
|
|
2535
|
+
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2536
|
+
this.logWarning(
|
|
2537
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2538
|
+
);
|
|
2539
|
+
} else {
|
|
2540
|
+
orderParams.order_id = currentOrderId;
|
|
2503
2541
|
}
|
|
2504
|
-
)
|
|
2505
|
-
};
|
|
2506
|
-
if (isUpdateOperation) {
|
|
2507
|
-
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2508
|
-
this.logWarning(
|
|
2509
|
-
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2510
|
-
);
|
|
2511
|
-
} else {
|
|
2512
|
-
orderParams.order_id = currentOrderId;
|
|
2513
2542
|
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
|
|
2517
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2518
|
-
operation: isUpdateOperation ? "update" : "create",
|
|
2519
|
-
isManual,
|
|
2520
|
-
paymentItemCount: paymentItems.length,
|
|
2521
|
-
timestamp: startTime
|
|
2522
|
-
});
|
|
2523
|
-
let checkoutResponse;
|
|
2524
|
-
let submitSuccess = false;
|
|
2525
|
-
let submitError;
|
|
2526
|
-
try {
|
|
2527
|
-
this.logInfo("Calling backend checkout API", {
|
|
2528
|
-
url: "/order/checkout",
|
|
2529
|
-
isManual,
|
|
2530
|
-
...orderParams
|
|
2531
|
-
});
|
|
2532
|
-
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2533
|
-
submitSuccess = true;
|
|
2534
|
-
this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
|
|
2535
|
-
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2536
|
-
} catch (error) {
|
|
2537
|
-
submitSuccess = false;
|
|
2538
|
-
submitError = error instanceof Error ? error.message : String(error);
|
|
2539
|
-
this.logError("下单接口调用失败:", submitError);
|
|
2540
|
-
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
2541
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2542
|
-
operation: isUpdateOperation ? "update" : "create",
|
|
2543
|
-
isManual,
|
|
2544
|
-
error: submitError,
|
|
2545
|
-
errorType: "network_error",
|
|
2546
|
-
duration: Date.now() - startTime,
|
|
2547
|
-
timestamp: Date.now()
|
|
2548
|
-
});
|
|
2549
|
-
throw error;
|
|
2550
|
-
} finally {
|
|
2551
|
-
await this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
|
|
2552
|
-
success: submitSuccess,
|
|
2543
|
+
const startTime = Date.now();
|
|
2544
|
+
await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
|
|
2553
2545
|
orderUuid: this.store.currentOrder.uuid,
|
|
2554
2546
|
operation: isUpdateOperation ? "update" : "create",
|
|
2555
2547
|
isManual,
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
duration: Date.now() - startTime,
|
|
2559
|
-
timestamp: Date.now()
|
|
2548
|
+
paymentItemCount: paymentItems.length,
|
|
2549
|
+
timestamp: startTime
|
|
2560
2550
|
});
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2551
|
+
let checkoutResponse;
|
|
2552
|
+
let submitSuccess = false;
|
|
2553
|
+
let submitError;
|
|
2554
|
+
try {
|
|
2555
|
+
this.logInfo("Calling backend checkout API", {
|
|
2556
|
+
url: "/order/checkout",
|
|
2557
|
+
isManual,
|
|
2558
|
+
...orderParams
|
|
2559
|
+
});
|
|
2560
|
+
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2561
|
+
submitSuccess = true;
|
|
2562
|
+
this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
|
|
2563
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2564
|
+
} catch (error) {
|
|
2565
|
+
submitSuccess = false;
|
|
2566
|
+
submitError = error instanceof Error ? error.message : String(error);
|
|
2567
|
+
this.logError("下单接口调用失败:", submitError);
|
|
2568
|
+
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
2569
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2570
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
2571
|
+
isManual,
|
|
2572
|
+
error: submitError,
|
|
2573
|
+
errorType: "network_error",
|
|
2574
|
+
duration: Date.now() - startTime,
|
|
2575
|
+
timestamp: Date.now()
|
|
2576
|
+
});
|
|
2577
|
+
throw error;
|
|
2578
|
+
} finally {
|
|
2579
|
+
await this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
|
|
2580
|
+
success: submitSuccess,
|
|
2581
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2582
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
2583
|
+
isManual,
|
|
2584
|
+
orderId: submitSuccess ? ((_g = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _g.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2585
|
+
error: submitError,
|
|
2586
|
+
duration: Date.now() - startTime,
|
|
2587
|
+
timestamp: Date.now()
|
|
2588
|
+
});
|
|
2588
2589
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2590
|
+
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2591
|
+
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2592
|
+
if (!isSuccessResponse) {
|
|
2593
|
+
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
2594
|
+
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
2595
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2596
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
2597
|
+
isManual,
|
|
2598
|
+
error: errorMessage,
|
|
2599
|
+
errorType: "api_error",
|
|
2600
|
+
response: checkoutResponse,
|
|
2601
|
+
duration: Date.now() - startTime,
|
|
2602
|
+
timestamp: Date.now()
|
|
2603
|
+
});
|
|
2604
|
+
throw new Error(errorMessage);
|
|
2591
2605
|
}
|
|
2592
|
-
realOrderId
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2606
|
+
let realOrderId;
|
|
2607
|
+
if (isUpdateOperation) {
|
|
2608
|
+
realOrderId = currentOrderId;
|
|
2609
|
+
} else {
|
|
2610
|
+
let extractedOrderId = (_h = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _h.order_id;
|
|
2611
|
+
if (!extractedOrderId) {
|
|
2612
|
+
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2613
|
+
}
|
|
2614
|
+
if (extractedOrderId !== void 0 && extractedOrderId !== null) {
|
|
2615
|
+
extractedOrderId = String(extractedOrderId);
|
|
2616
|
+
}
|
|
2617
|
+
if (!extractedOrderId) {
|
|
2618
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
2619
|
+
}
|
|
2620
|
+
realOrderId = extractedOrderId;
|
|
2621
|
+
this.logInfo("准备替换订单ID:", {
|
|
2622
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2623
|
+
oldOrderId: this.store.currentOrder.order_id,
|
|
2624
|
+
newOrderId: realOrderId
|
|
2609
2625
|
});
|
|
2610
|
-
|
|
2611
|
-
this.
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2626
|
+
try {
|
|
2627
|
+
const latestPaymentStatus = this.store.currentOrder.payment_status;
|
|
2628
|
+
const previousOrder = this.store.currentOrder;
|
|
2629
|
+
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
2630
|
+
previousOrder.uuid,
|
|
2631
|
+
realOrderId
|
|
2632
|
+
);
|
|
2633
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
2634
|
+
wasSuccessful: !!updatedOrder,
|
|
2635
|
+
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2636
|
+
expectedOrderId: realOrderId
|
|
2615
2637
|
});
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2638
|
+
if (updatedOrder) {
|
|
2639
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
2640
|
+
uuid: updatedOrder.uuid,
|
|
2641
|
+
orderId: updatedOrder.order_id,
|
|
2642
|
+
totalAmount: updatedOrder.total_amount
|
|
2643
|
+
});
|
|
2644
|
+
this.store.currentOrder = {
|
|
2645
|
+
...previousOrder,
|
|
2646
|
+
...updatedOrder,
|
|
2623
2647
|
payment_status: latestPaymentStatus
|
|
2648
|
+
};
|
|
2649
|
+
if (latestPaymentStatus)
|
|
2650
|
+
await this.payment.updateOrderAsync(previousOrder.uuid, {
|
|
2651
|
+
payment_status: latestPaymentStatus
|
|
2652
|
+
});
|
|
2653
|
+
this.logInfo(
|
|
2654
|
+
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2655
|
+
this.store.currentOrder.order_id
|
|
2656
|
+
);
|
|
2657
|
+
} else {
|
|
2658
|
+
this.logError(
|
|
2659
|
+
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2660
|
+
);
|
|
2661
|
+
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2662
|
+
this.store.currentOrder.order_id = realOrderId;
|
|
2663
|
+
this.logInfo("手动设置订单ID:", {
|
|
2664
|
+
beforeReplacement: beforeManualUpdate,
|
|
2665
|
+
afterReplacement: this.store.currentOrder.order_id,
|
|
2666
|
+
目标ID: realOrderId
|
|
2624
2667
|
});
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
);
|
|
2629
|
-
} else {
|
|
2630
|
-
this.logError(
|
|
2631
|
-
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2632
|
-
);
|
|
2633
|
-
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2668
|
+
}
|
|
2669
|
+
} catch (error) {
|
|
2670
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2634
2671
|
this.store.currentOrder.order_id = realOrderId;
|
|
2635
|
-
this.logInfo("
|
|
2636
|
-
beforeReplacement: beforeManualUpdate,
|
|
2637
|
-
afterReplacement: this.store.currentOrder.order_id,
|
|
2638
|
-
目标ID: realOrderId
|
|
2639
|
-
});
|
|
2672
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2640
2673
|
}
|
|
2641
|
-
} catch (error) {
|
|
2642
|
-
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2643
|
-
this.store.currentOrder.order_id = realOrderId;
|
|
2644
|
-
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2645
2674
|
}
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2675
|
+
try {
|
|
2676
|
+
const syncedPaymentUuids = processedPaymentItems.filter((item) => item.status !== "voided").map((item) => item.uuid).filter(Boolean);
|
|
2677
|
+
for (const paymentUuid of syncedPaymentUuids) {
|
|
2678
|
+
await this.payment.updatePaymentAsync(
|
|
2679
|
+
this.store.currentOrder.uuid,
|
|
2680
|
+
paymentUuid,
|
|
2681
|
+
{ isSynced: true, syncError: void 0 }
|
|
2682
|
+
);
|
|
2683
|
+
}
|
|
2684
|
+
} catch (e) {
|
|
2685
|
+
this.logWarning("标记支付项已同步失败(不阻塞主流程)", { error: e });
|
|
2686
|
+
}
|
|
2687
|
+
this.store.isOrderSynced = true;
|
|
2688
|
+
this.clearCalculationCache();
|
|
2689
|
+
await this.core.effects.emit(`${this.name}:onOrderSynced`, {
|
|
2690
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2691
|
+
realOrderId,
|
|
2692
|
+
virtualOrderId: this.store.currentOrder.order_id,
|
|
2693
|
+
timestamp: Date.now(),
|
|
2694
|
+
isManual,
|
|
2695
|
+
response: checkoutResponse
|
|
2696
|
+
});
|
|
2697
|
+
const result = {
|
|
2698
|
+
success: true,
|
|
2699
|
+
orderId: realOrderId,
|
|
2700
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2701
|
+
response: checkoutResponse
|
|
2702
|
+
};
|
|
2703
|
+
resolveInFlight(result);
|
|
2704
|
+
return result;
|
|
2705
|
+
} catch (error) {
|
|
2706
|
+
rejectInFlight(error);
|
|
2707
|
+
throw error;
|
|
2708
|
+
} finally {
|
|
2709
|
+
const currentInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
|
|
2710
|
+
if (currentInFlight === inFlightPromise) {
|
|
2711
|
+
this.syncOrderToBackendInFlightByOrderKey.delete(orderLockKey);
|
|
2655
2712
|
}
|
|
2656
|
-
} catch (e) {
|
|
2657
|
-
this.logWarning("标记支付项已同步失败(不阻塞主流程)", { error: e });
|
|
2658
2713
|
}
|
|
2659
|
-
this.store.isOrderSynced = true;
|
|
2660
|
-
this.clearCalculationCache();
|
|
2661
|
-
await this.core.effects.emit(`${this.name}:onOrderSynced`, {
|
|
2662
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2663
|
-
realOrderId,
|
|
2664
|
-
virtualOrderId: this.store.currentOrder.order_id,
|
|
2665
|
-
timestamp: Date.now(),
|
|
2666
|
-
isManual,
|
|
2667
|
-
response: checkoutResponse
|
|
2668
|
-
});
|
|
2669
|
-
return {
|
|
2670
|
-
success: true,
|
|
2671
|
-
orderId: realOrderId,
|
|
2672
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2673
|
-
response: checkoutResponse
|
|
2674
|
-
};
|
|
2675
2714
|
}
|
|
2676
2715
|
async setOtherParams(params, { cover = false } = {}) {
|
|
2677
2716
|
if (cover) {
|