@pisell/pisellos 1.0.65 → 1.0.67
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/Date/index.js +4 -0
- package/dist/modules/Order/index.js +10 -4
- package/dist/modules/Payment/index.d.ts +1 -0
- package/dist/modules/Payment/index.js +75 -41
- package/dist/modules/Payment/walletpass.js +3 -4
- package/dist/modules/Rules/index.js +2 -0
- package/dist/modules/Schedule/index.d.ts +1 -1
- package/dist/modules/Schedule/index.js +9 -0
- package/dist/solution/BookingByStep/index.d.ts +16 -4
- package/dist/solution/BookingByStep/index.js +671 -109
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +219 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +6 -148
- package/dist/solution/Checkout/index.js +1188 -2434
- package/dist/solution/Checkout/types.d.ts +7 -220
- package/dist/solution/Checkout/types.js +1 -49
- package/dist/solution/Checkout/utils/index.d.ts +9 -5
- package/dist/solution/Checkout/utils/index.js +18 -56
- package/lib/modules/Date/index.js +3 -0
- package/lib/modules/Order/index.js +6 -0
- package/lib/modules/Payment/index.d.ts +1 -0
- package/lib/modules/Payment/index.js +35 -8
- package/lib/modules/Payment/walletpass.js +2 -2
- package/lib/modules/Rules/index.js +2 -0
- package/lib/modules/Schedule/index.d.ts +1 -1
- package/lib/modules/Schedule/index.js +9 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -4
- package/lib/solution/BookingByStep/index.js +363 -8
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +157 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +6 -148
- package/lib/solution/Checkout/index.js +337 -1115
- package/lib/solution/Checkout/types.d.ts +7 -220
- package/lib/solution/Checkout/types.js +3 -27
- package/lib/solution/Checkout/utils/index.d.ts +9 -5
- package/lib/solution/Checkout/utils/index.js +12 -53
- package/package.json +1 -1
|
@@ -65,8 +65,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
65
65
|
this.order = new import_Order.OrderModule();
|
|
66
66
|
this.payment = new import_Payment.PaymentModule();
|
|
67
67
|
this.store = {
|
|
68
|
-
status: import_types.CheckoutStatus.Initializing,
|
|
69
|
-
step: import_types.CheckoutStep.OrderConfirmation,
|
|
70
68
|
cartItems: [],
|
|
71
69
|
paymentMethods: [],
|
|
72
70
|
stateAmount: "0.00",
|
|
@@ -78,7 +76,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
78
76
|
await this.initializeSubModules(core, options);
|
|
79
77
|
await this.preloadPaymentMethods();
|
|
80
78
|
await this.cleanupExpiredOrdersAsync();
|
|
81
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
82
79
|
console.log("[Checkout] 初始化完成");
|
|
83
80
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
|
|
84
81
|
timestamp: Date.now()
|
|
@@ -92,7 +89,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
92
89
|
if (this.logger) {
|
|
93
90
|
this.logger.addLog({
|
|
94
91
|
type: "info",
|
|
95
|
-
title: `[CheckoutModule] ${title}`,
|
|
92
|
+
title: `[CheckoutModule] ${this.getCurrentOrderId()} ${title}`,
|
|
96
93
|
metadata: metadata || {}
|
|
97
94
|
});
|
|
98
95
|
}
|
|
@@ -128,11 +125,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
128
125
|
var _a, _b;
|
|
129
126
|
core.registerModule(this.order, {
|
|
130
127
|
store: ((_a = options.store) == null ? void 0 : _a.order) || {},
|
|
131
|
-
otherParams: { ...this.otherParams,
|
|
128
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
132
129
|
});
|
|
133
130
|
core.registerModule(this.payment, {
|
|
134
131
|
store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
|
|
135
|
-
otherParams: { ...this.otherParams,
|
|
132
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
136
133
|
});
|
|
137
134
|
this.setupPaymentEventListeners();
|
|
138
135
|
}
|
|
@@ -181,7 +178,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
181
178
|
platform: params.platform
|
|
182
179
|
});
|
|
183
180
|
try {
|
|
184
|
-
this.setStatus(import_types.CheckoutStatus.Initializing);
|
|
185
181
|
const validation = this.validateCheckoutParams(params);
|
|
186
182
|
if (!validation.valid) {
|
|
187
183
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -190,8 +186,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
190
186
|
);
|
|
191
187
|
}
|
|
192
188
|
this.store.cartItems = params.cartItems;
|
|
193
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
194
|
-
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
195
189
|
console.log("[Checkout] 结账流程初始化完成");
|
|
196
190
|
} catch (error) {
|
|
197
191
|
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
@@ -213,21 +207,29 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
213
207
|
product_id: item.product.product_id,
|
|
214
208
|
product_variant_id: item.product.product_variant_id,
|
|
215
209
|
quantity: item.product.num,
|
|
216
|
-
selling_price: item.product.
|
|
210
|
+
selling_price: item.product.calculated_selling_price
|
|
211
|
+
})
|
|
212
|
+
)) || [];
|
|
213
|
+
const relationProducts = ((_e = (_d = (_c = this.store.currentOrder.order_info) == null ? void 0 : _c.original_order_data) == null ? void 0 : _d.relation_products) == null ? void 0 : _e.map(
|
|
214
|
+
(item) => ({
|
|
215
|
+
product_id: item.product_id,
|
|
216
|
+
product_variant_id: item.product_variant_id,
|
|
217
|
+
quantity: item.num,
|
|
218
|
+
selling_price: item.source_product_price
|
|
217
219
|
})
|
|
218
220
|
)) || [];
|
|
219
|
-
const relationProducts = ((_e = (_d = (_c = this.store.currentOrder.order_info) == null ? void 0 : _c.original_order_data) == null ? void 0 : _d.relation_products) == null ? void 0 : _e.map((item) => ({
|
|
220
|
-
product_id: item.product_id,
|
|
221
|
-
product_variant_id: item.product_variant_id,
|
|
222
|
-
quantity: item.num,
|
|
223
|
-
selling_price: item.source_product_price
|
|
224
|
-
}))) || [];
|
|
225
221
|
return [...productList, ...relationProducts];
|
|
226
222
|
}
|
|
227
223
|
async initWalletData(params) {
|
|
228
224
|
var _a, _b, _c, _d;
|
|
225
|
+
this.logInfo("initWalletData called", {
|
|
226
|
+
params
|
|
227
|
+
});
|
|
229
228
|
const amountInfo = (_b = (_a = this.store.currentOrder) == null ? void 0 : _a.order_info) == null ? void 0 : _b.amount_breakdown;
|
|
230
229
|
if (!amountInfo) {
|
|
230
|
+
this.logInfo("initWalletData amountInfo not found", {
|
|
231
|
+
params
|
|
232
|
+
});
|
|
231
233
|
return;
|
|
232
234
|
}
|
|
233
235
|
const walletBusinessData = {
|
|
@@ -239,9 +241,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
239
241
|
products: this.getProductListByOrder(),
|
|
240
242
|
...params
|
|
241
243
|
};
|
|
244
|
+
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
245
|
+
walletBusinessData
|
|
246
|
+
});
|
|
242
247
|
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
243
248
|
walletBusinessData
|
|
244
249
|
);
|
|
250
|
+
this.logInfo("调用结束:initializeWalletDataFromBusinessAsync", {
|
|
251
|
+
walletBusinessData
|
|
252
|
+
});
|
|
253
|
+
if (!this.store.currentOrder) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
this.logInfo("initWalletData currentOrder found", {
|
|
257
|
+
currentOrder: this.store.currentOrder
|
|
258
|
+
});
|
|
245
259
|
await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
|
|
246
260
|
orderUuid: (_d = this.store.currentOrder) == null ? void 0 : _d.uuid,
|
|
247
261
|
customerId: walletBusinessData.customer_id,
|
|
@@ -273,9 +287,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
273
287
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
274
288
|
});
|
|
275
289
|
try {
|
|
276
|
-
console.time("createLocalOrderAsync");
|
|
277
290
|
await this.resetStoreStateAsync();
|
|
278
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
279
291
|
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
280
292
|
if (!validation.valid) {
|
|
281
293
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -320,20 +332,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
320
332
|
amount_breakdown: amountInfo
|
|
321
333
|
}
|
|
322
334
|
});
|
|
323
|
-
console.timeEnd("createLocalOrderAsync");
|
|
324
335
|
this.store.currentOrder = paymentOrder;
|
|
325
|
-
this.initWalletData();
|
|
326
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
327
|
-
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
328
336
|
if (params.autoPayment) {
|
|
329
|
-
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
330
337
|
}
|
|
331
338
|
this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
332
339
|
order: paymentOrder,
|
|
333
340
|
timestamp: Date.now()
|
|
334
341
|
});
|
|
335
342
|
await this.updateStateAmountToRemaining();
|
|
336
|
-
|
|
343
|
+
this.logInfo("本地订单创建成功:", {
|
|
337
344
|
localOrderId,
|
|
338
345
|
uuid: paymentOrder.uuid,
|
|
339
346
|
totalAmount: amountInfo.totalAmount,
|
|
@@ -341,12 +348,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
341
348
|
taxAmount: amountInfo.taxAmount,
|
|
342
349
|
stateAmount: this.store.stateAmount
|
|
343
350
|
});
|
|
351
|
+
this.initWalletData();
|
|
344
352
|
return paymentOrder;
|
|
345
353
|
} catch (error) {
|
|
346
354
|
await this.handleError(
|
|
347
355
|
error,
|
|
348
356
|
import_types.CheckoutErrorType.OrderCreationFailed
|
|
349
357
|
);
|
|
358
|
+
this.logError("本地订单创建失败:", error);
|
|
350
359
|
this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
|
|
351
360
|
error: this.store.lastError,
|
|
352
361
|
timestamp: Date.now()
|
|
@@ -354,206 +363,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
354
363
|
throw error;
|
|
355
364
|
}
|
|
356
365
|
}
|
|
357
|
-
/**
|
|
358
|
-
* 手动下单 (根据虚拟订单生成实际订单)
|
|
359
|
-
*
|
|
360
|
-
* 使用当前存储的本地订单数据调用 Order 模块创建真实订单
|
|
361
|
-
*/
|
|
362
|
-
async placeOrderAsync(params = {}) {
|
|
363
|
-
var _a, _b;
|
|
364
|
-
this.logInfo("placeOrderAsync called", {
|
|
365
|
-
url: params.url,
|
|
366
|
-
autoReplaceOrderId: params.autoReplaceOrderId,
|
|
367
|
-
hasLocalOrderData: !!this.store.localOrderData,
|
|
368
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
369
|
-
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
370
|
-
isOrderSynced: this.store.isOrderSynced
|
|
371
|
-
});
|
|
372
|
-
try {
|
|
373
|
-
if (!this.store.localOrderData) {
|
|
374
|
-
throw (0, import_utils.createCheckoutError)(
|
|
375
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
376
|
-
"没有找到本地订单数据,请先调用 createLocalOrderAsync 创建虚拟订单"
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
if (!this.store.currentOrder) {
|
|
380
|
-
throw (0, import_utils.createCheckoutError)(
|
|
381
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
382
|
-
"没有找到当前订单,请先创建虚拟订单"
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
console.log("[Checkout] 开始手动下单流程...");
|
|
386
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
387
|
-
const orderData = {
|
|
388
|
-
cartItems: this.store.cartItems,
|
|
389
|
-
type: this.store.localOrderData.type,
|
|
390
|
-
platform: this.store.localOrderData.platform
|
|
391
|
-
};
|
|
392
|
-
const orderResponse = await this.order.submitOrder({
|
|
393
|
-
url: params.url,
|
|
394
|
-
// 可选的自定义 URL
|
|
395
|
-
query: orderData
|
|
396
|
-
});
|
|
397
|
-
const realOrderId = ((_b = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _b.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
|
|
398
|
-
if (!realOrderId) {
|
|
399
|
-
throw (0, import_utils.createCheckoutError)(
|
|
400
|
-
import_types.CheckoutErrorType.OrderCreationFailed,
|
|
401
|
-
"订单创建成功但未返回订单ID"
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
console.log("[Checkout] 真实订单创建成功:", realOrderId);
|
|
405
|
-
if (params.autoReplaceOrderId !== false) {
|
|
406
|
-
console.log("[Checkout] 自动替换虚拟订单ID为真实订单ID...");
|
|
407
|
-
const updatedOrder = await this.replaceLocalOrderIdAsync(realOrderId);
|
|
408
|
-
if (updatedOrder) {
|
|
409
|
-
console.log("[Checkout] 订单ID替换成功:", {
|
|
410
|
-
oldId: this.store.currentOrder.order_id,
|
|
411
|
-
newId: realOrderId
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
416
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
417
|
-
order: this.store.currentOrder,
|
|
418
|
-
timestamp: Date.now()
|
|
419
|
-
});
|
|
420
|
-
this.store.isOrderSynced = true;
|
|
421
|
-
console.log("[Checkout] 手动下单流程完成");
|
|
422
|
-
return {
|
|
423
|
-
success: true,
|
|
424
|
-
orderId: realOrderId
|
|
425
|
-
};
|
|
426
|
-
} catch (error) {
|
|
427
|
-
let errorMessage = "下单失败";
|
|
428
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
429
|
-
errorMessage = error.message;
|
|
430
|
-
} else if (error instanceof Error) {
|
|
431
|
-
errorMessage = error.message;
|
|
432
|
-
}
|
|
433
|
-
console.error("[Checkout] 手动下单失败:", errorMessage);
|
|
434
|
-
await this.handleError(
|
|
435
|
-
error,
|
|
436
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
437
|
-
);
|
|
438
|
-
return {
|
|
439
|
-
success: false,
|
|
440
|
-
error: errorMessage
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* 创建订单
|
|
446
|
-
*/
|
|
447
|
-
async createOrderAsync(params) {
|
|
448
|
-
var _a;
|
|
449
|
-
try {
|
|
450
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
451
|
-
const checkResult = this.order.checkBeforeSubmitOrder({
|
|
452
|
-
cartItems: params.cartItems,
|
|
453
|
-
type: "account"
|
|
454
|
-
// 默认使用 account 类型
|
|
455
|
-
});
|
|
456
|
-
if (!checkResult) {
|
|
457
|
-
throw (0, import_utils.createCheckoutError)(
|
|
458
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
459
|
-
"购物车数据验证失败,请检查商品信息"
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
const orderResponse = await this.order.submitOrder({
|
|
463
|
-
query: {
|
|
464
|
-
cartItems: params.cartItems,
|
|
465
|
-
type: params.type || "appointment_booking",
|
|
466
|
-
platform: params.platform || "pc"
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
470
|
-
order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
|
|
471
|
-
total_amount: (0, import_utils.calculateTotalAmount)(params.cartItems),
|
|
472
|
-
order_info: orderResponse == null ? void 0 : orderResponse.data
|
|
473
|
-
});
|
|
474
|
-
this.store.currentOrder = paymentOrder;
|
|
475
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
476
|
-
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
477
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
478
|
-
order: paymentOrder,
|
|
479
|
-
timestamp: Date.now()
|
|
480
|
-
});
|
|
481
|
-
this.store.isOrderSynced = true;
|
|
482
|
-
await this.updateStateAmountToRemaining();
|
|
483
|
-
console.log("[Checkout] 订单创建成功:", paymentOrder.id);
|
|
484
|
-
return paymentOrder;
|
|
485
|
-
} catch (error) {
|
|
486
|
-
await this.handleError(
|
|
487
|
-
error,
|
|
488
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
489
|
-
);
|
|
490
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
|
|
491
|
-
error: this.store.lastError,
|
|
492
|
-
timestamp: Date.now()
|
|
493
|
-
});
|
|
494
|
-
throw error;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* 处理支付
|
|
499
|
-
*/
|
|
500
|
-
async processPaymentAsync(params) {
|
|
501
|
-
try {
|
|
502
|
-
if (!this.store.currentOrder) {
|
|
503
|
-
throw (0, import_utils.createCheckoutError)(
|
|
504
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
505
|
-
"未找到当前订单,请先创建订单"
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
this.setStatus(import_types.CheckoutStatus.ProcessingPayment);
|
|
509
|
-
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
510
|
-
const paymentMethod = this.store.paymentMethods.find(
|
|
511
|
-
(method) => method.code === params.paymentMethodCode
|
|
512
|
-
);
|
|
513
|
-
if (!paymentMethod) {
|
|
514
|
-
throw (0, import_utils.createCheckoutError)(
|
|
515
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
516
|
-
`未找到支付方式: ${params.paymentMethodCode}`
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
const paymentItem = {
|
|
520
|
-
code: paymentMethod.code,
|
|
521
|
-
name: paymentMethod.name,
|
|
522
|
-
type: paymentMethod.type,
|
|
523
|
-
amount: String(params.amount),
|
|
524
|
-
id: paymentMethod.id
|
|
525
|
-
};
|
|
526
|
-
await this.payment.addPaymentItemAsync(
|
|
527
|
-
this.store.currentOrder.uuid,
|
|
528
|
-
paymentItem
|
|
529
|
-
);
|
|
530
|
-
const result = await this.payment.submitPayAsync(
|
|
531
|
-
this.store.currentOrder.uuid
|
|
532
|
-
);
|
|
533
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
534
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
535
|
-
paymentMethodCode: params.paymentMethodCode,
|
|
536
|
-
amount: String(params.amount),
|
|
537
|
-
timestamp: Date.now()
|
|
538
|
-
});
|
|
539
|
-
if (result.status === "success") {
|
|
540
|
-
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
541
|
-
await this.updateStateAmountToRemaining();
|
|
542
|
-
await this.handlePaymentSuccess({
|
|
543
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
544
|
-
timestamp: Date.now()
|
|
545
|
-
});
|
|
546
|
-
} else {
|
|
547
|
-
throw (0, import_utils.createCheckoutError)(
|
|
548
|
-
import_types.CheckoutErrorType.PaymentFailed,
|
|
549
|
-
"支付处理失败,请重试"
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
} catch (error) {
|
|
553
|
-
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
554
|
-
throw error;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
366
|
/**
|
|
558
367
|
* 完成结账
|
|
559
368
|
*/
|
|
@@ -575,8 +384,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
575
384
|
);
|
|
576
385
|
}
|
|
577
386
|
this.payment.wallet.clearAllCache();
|
|
578
|
-
this.setStatus(import_types.CheckoutStatus.Completed);
|
|
579
|
-
this.setStep(import_types.CheckoutStep.Complete);
|
|
580
387
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
581
388
|
orderId: order.id,
|
|
582
389
|
timestamp: Date.now()
|
|
@@ -592,89 +399,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
592
399
|
return { success: false };
|
|
593
400
|
}
|
|
594
401
|
}
|
|
595
|
-
/**
|
|
596
|
-
* 取消结账
|
|
597
|
-
*/
|
|
598
|
-
async cancelCheckoutAsync() {
|
|
599
|
-
try {
|
|
600
|
-
if (this.store.currentOrder) {
|
|
601
|
-
await this.payment.deletePaymentOrderAsync(
|
|
602
|
-
this.store.currentOrder.uuid
|
|
603
|
-
);
|
|
604
|
-
this.store.currentOrder = void 0;
|
|
605
|
-
}
|
|
606
|
-
this.store.localOrderData = void 0;
|
|
607
|
-
this.store.cartSummary = void 0;
|
|
608
|
-
this.payment.wallet.clearAllCache();
|
|
609
|
-
this.store.cartItems = [];
|
|
610
|
-
this.store.stateAmount = "0.00";
|
|
611
|
-
this.store.balanceDueAmount = "0.00";
|
|
612
|
-
this.store.isOrderSynced = false;
|
|
613
|
-
this.store.currentCustomer = void 0;
|
|
614
|
-
this.setStatus(import_types.CheckoutStatus.Cancelled);
|
|
615
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
|
|
616
|
-
timestamp: Date.now()
|
|
617
|
-
});
|
|
618
|
-
console.log("[Checkout] 结账流程已取消");
|
|
619
|
-
} catch (error) {
|
|
620
|
-
console.error("[Checkout] 取消结账失败:", error);
|
|
621
|
-
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* 获取结账状态
|
|
626
|
-
*/
|
|
627
|
-
getCheckoutStatus() {
|
|
628
|
-
return {
|
|
629
|
-
status: this.store.status,
|
|
630
|
-
step: this.store.step,
|
|
631
|
-
progress: (0, import_utils.calculateProgress)(this.store.status, this.store.step),
|
|
632
|
-
message: this.getStatusMessage(),
|
|
633
|
-
error: this.store.lastError
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* 获取结账摘要
|
|
638
|
-
*/
|
|
639
|
-
async getCheckoutSummaryAsync() {
|
|
640
|
-
var _a, _b;
|
|
641
|
-
const totalAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0.00";
|
|
642
|
-
const paidAmount = await this.calculatePaidAmountAsync();
|
|
643
|
-
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
644
|
-
return {
|
|
645
|
-
order: this.store.currentOrder,
|
|
646
|
-
totalAmount,
|
|
647
|
-
paidAmount,
|
|
648
|
-
remainingAmount,
|
|
649
|
-
paymentStatus: ((_b = this.store.currentOrder) == null ? void 0 : _b.payment_status) || import_types2.PaymentStatus.Processing,
|
|
650
|
-
availablePaymentMethods: this.store.paymentMethods
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* 获取可用支付方式
|
|
655
|
-
*/
|
|
656
|
-
async getAvailablePaymentMethodsAsync() {
|
|
657
|
-
return await this.getPaymentMethodsAsync();
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* 刷新支付方式缓存
|
|
661
|
-
*
|
|
662
|
-
* 强制重新从服务器获取支付方式列表,更新本地缓存
|
|
663
|
-
*/
|
|
664
|
-
async refreshPaymentMethodsAsync() {
|
|
665
|
-
console.log("[Checkout] 强制刷新支付方式缓存...");
|
|
666
|
-
try {
|
|
667
|
-
const methods = await this.payment.getPayMethodListAsync();
|
|
668
|
-
this.store.paymentMethods = methods;
|
|
669
|
-
console.log(
|
|
670
|
-
`[Checkout] 强制刷新完成,获取到 ${methods.length} 种支付方式`
|
|
671
|
-
);
|
|
672
|
-
return methods;
|
|
673
|
-
} catch (error) {
|
|
674
|
-
console.error("[Checkout] 强制刷新支付方式失败:", error);
|
|
675
|
-
return this.store.paymentMethods;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
402
|
/**
|
|
679
403
|
* 获取订单原始数据
|
|
680
404
|
*/
|
|
@@ -689,7 +413,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
689
413
|
*/
|
|
690
414
|
getCurrentOrderInfo() {
|
|
691
415
|
try {
|
|
692
|
-
const { currentOrder,
|
|
416
|
+
const { currentOrder, cartItems, localOrderData } = this.store;
|
|
693
417
|
if (!currentOrder) {
|
|
694
418
|
console.log("[Checkout] 当前没有活跃订单");
|
|
695
419
|
return null;
|
|
@@ -701,8 +425,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
701
425
|
const result = {
|
|
702
426
|
uuid: currentOrder.uuid,
|
|
703
427
|
orderId: currentOrder.order_id,
|
|
704
|
-
status,
|
|
705
|
-
step,
|
|
706
428
|
totalAmount: currentOrder.total_amount,
|
|
707
429
|
remainingAmount: currentOrder.expect_amount,
|
|
708
430
|
paymentStatus: currentOrder.payment_status,
|
|
@@ -714,13 +436,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
714
436
|
itemCount: cartItems.length,
|
|
715
437
|
hasLocalOrderData: Boolean(localOrderData)
|
|
716
438
|
};
|
|
717
|
-
console.log("[Checkout] 获取当前订单基础信息:", {
|
|
718
|
-
uuid: result.uuid,
|
|
719
|
-
orderId: result.orderId,
|
|
720
|
-
status: result.status,
|
|
721
|
-
totalAmount: result.totalAmount,
|
|
722
|
-
remainingAmount: result.remainingAmount
|
|
723
|
-
});
|
|
724
439
|
return result;
|
|
725
440
|
} catch (error) {
|
|
726
441
|
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
@@ -739,89 +454,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
739
454
|
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
740
455
|
return [];
|
|
741
456
|
}
|
|
742
|
-
console.log("[Checkout] 获取当前订单支付项:", {
|
|
743
|
-
orderUuid: currentOrder.uuid,
|
|
744
|
-
orderId: currentOrder.order_id
|
|
745
|
-
});
|
|
746
457
|
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
747
458
|
currentOrder.uuid
|
|
748
459
|
);
|
|
749
|
-
console.log("[Checkout] 成功获取支付项:", {
|
|
750
|
-
orderUuid: currentOrder.uuid,
|
|
751
|
-
paymentItemCount: paymentItems.length,
|
|
752
|
-
activeItems: paymentItems.filter((item) => item.status !== "voided").length,
|
|
753
|
-
voidedItems: paymentItems.filter((item) => item.status === "voided").length,
|
|
754
|
-
totalPaidAmount: paymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => sum + parseFloat(item.amount || "0"), 0).toFixed(2),
|
|
755
|
-
paymentMethods: paymentItems.map((item) => ({
|
|
756
|
-
uuid: item.uuid,
|
|
757
|
-
code: item.code,
|
|
758
|
-
amount: item.amount,
|
|
759
|
-
status: item.status,
|
|
760
|
-
voucher_id: item.voucher_id
|
|
761
|
-
}))
|
|
762
|
-
});
|
|
763
460
|
return paymentItems;
|
|
764
461
|
} catch (error) {
|
|
765
462
|
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
766
463
|
return [];
|
|
767
464
|
}
|
|
768
465
|
}
|
|
769
|
-
/**
|
|
770
|
-
* 验证结账前置条件
|
|
771
|
-
*/
|
|
772
|
-
async validateCheckoutAsync() {
|
|
773
|
-
const errors = [];
|
|
774
|
-
if (!this.store.cartItems || this.store.cartItems.length === 0) {
|
|
775
|
-
errors.push("购物车为空");
|
|
776
|
-
}
|
|
777
|
-
if (this.store.paymentMethods.length === 0) {
|
|
778
|
-
errors.push("无可用支付方式");
|
|
779
|
-
}
|
|
780
|
-
if (this.store.status === import_types.CheckoutStatus.Error) {
|
|
781
|
-
errors.push("结账流程存在错误");
|
|
782
|
-
}
|
|
783
|
-
return {
|
|
784
|
-
valid: errors.length === 0,
|
|
785
|
-
errors
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* 重试失败的操作
|
|
790
|
-
*/
|
|
791
|
-
async retryFailedOperationAsync() {
|
|
792
|
-
try {
|
|
793
|
-
if (this.store.status === import_types.CheckoutStatus.Error && this.store.lastError) {
|
|
794
|
-
switch (this.store.lastError.type) {
|
|
795
|
-
case import_types.CheckoutErrorType.OrderCreationFailed:
|
|
796
|
-
if (this.store.cartItems.length > 0) {
|
|
797
|
-
await this.createOrderAsync({
|
|
798
|
-
cartItems: this.store.cartItems
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
break;
|
|
802
|
-
default:
|
|
803
|
-
console.warn(
|
|
804
|
-
"[Checkout] 无法重试此类型的错误:",
|
|
805
|
-
this.store.lastError.type
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
} catch (error) {
|
|
810
|
-
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* 设置当前步骤
|
|
815
|
-
*/
|
|
816
|
-
setCurrentStep(step) {
|
|
817
|
-
const oldStep = this.store.step;
|
|
818
|
-
this.store.step = step;
|
|
819
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
820
|
-
oldStep,
|
|
821
|
-
newStep: step,
|
|
822
|
-
timestamp: Date.now()
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
466
|
/**
|
|
826
467
|
* 获取订单模块
|
|
827
468
|
*/
|
|
@@ -890,7 +531,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
890
531
|
if (oldAmount === formattedAmount) {
|
|
891
532
|
return;
|
|
892
533
|
}
|
|
893
|
-
this.
|
|
534
|
+
this.logInfo("[Checkout] 设置自定义支付金额:", {
|
|
894
535
|
oldAmount,
|
|
895
536
|
newAmount: formattedAmount
|
|
896
537
|
});
|
|
@@ -900,10 +541,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
900
541
|
newAmount: formattedAmount,
|
|
901
542
|
timestamp: Date.now()
|
|
902
543
|
});
|
|
903
|
-
console.log("[Checkout] 自定义支付金额已更新:", {
|
|
904
|
-
oldAmount,
|
|
905
|
-
newAmount: formattedAmount
|
|
906
|
-
});
|
|
907
544
|
} catch (error) {
|
|
908
545
|
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
909
546
|
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
@@ -932,14 +569,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
932
569
|
getBalanceDueAmount() {
|
|
933
570
|
return this.store.balanceDueAmount;
|
|
934
571
|
}
|
|
935
|
-
/**
|
|
936
|
-
* 刷新 stateAmount 为当前剩余未支付金额
|
|
937
|
-
*
|
|
938
|
-
* UI 可以调用此方法来主动刷新支付金额状态
|
|
939
|
-
*/
|
|
940
|
-
async refreshStateAmountAsync() {
|
|
941
|
-
await this.updateStateAmountToRemaining();
|
|
942
|
-
}
|
|
943
572
|
/**
|
|
944
573
|
* 获取购物车小计数据
|
|
945
574
|
*
|
|
@@ -952,7 +581,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
952
581
|
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
953
582
|
return null;
|
|
954
583
|
}
|
|
955
|
-
|
|
584
|
+
this.logInfo("获取购物车小计数据:", {
|
|
956
585
|
itemCount: this.store.cartSummary.length,
|
|
957
586
|
items: this.store.cartSummary.map((item) => ({
|
|
958
587
|
key: item.key,
|
|
@@ -962,24 +591,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
962
591
|
});
|
|
963
592
|
return [...this.store.cartSummary];
|
|
964
593
|
}
|
|
965
|
-
/**
|
|
966
|
-
* 获取提取的金额详细信息
|
|
967
|
-
*
|
|
968
|
-
* 从当前的购物车小计数据中提取结构化的金额信息
|
|
969
|
-
*
|
|
970
|
-
* @returns 提取的金额信息对象,如果没有小计数据则返回 null
|
|
971
|
-
*/
|
|
972
|
-
getExtractedAmountInfo() {
|
|
973
|
-
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
974
|
-
console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
|
|
975
|
-
return null;
|
|
976
|
-
}
|
|
977
|
-
const extractedInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
978
|
-
this.store.cartSummary
|
|
979
|
-
);
|
|
980
|
-
console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
|
|
981
|
-
return extractedInfo;
|
|
982
|
-
}
|
|
983
594
|
/**
|
|
984
595
|
* 获取支付方式列表
|
|
985
596
|
*
|
|
@@ -990,21 +601,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
990
601
|
*/
|
|
991
602
|
async getPaymentMethodsAsync() {
|
|
992
603
|
if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
|
|
993
|
-
|
|
994
|
-
|
|
604
|
+
this.logInfo(
|
|
605
|
+
`使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
|
|
995
606
|
);
|
|
996
607
|
return this.store.paymentMethods;
|
|
997
608
|
}
|
|
998
|
-
|
|
609
|
+
this.logInfo("store 中无缓存,从 Payment 模块获取支付方式...");
|
|
999
610
|
try {
|
|
1000
611
|
const methods = await this.payment.getPayMethodListAsync();
|
|
1001
612
|
this.store.paymentMethods = methods;
|
|
1002
|
-
|
|
1003
|
-
|
|
613
|
+
this.logInfo(
|
|
614
|
+
`从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
|
|
1004
615
|
);
|
|
1005
616
|
return methods;
|
|
1006
617
|
} catch (error) {
|
|
1007
|
-
|
|
618
|
+
this.logError("获取支付方式失败:", error);
|
|
1008
619
|
return [];
|
|
1009
620
|
}
|
|
1010
621
|
}
|
|
@@ -1017,19 +628,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1017
628
|
* @throws 当前没有活跃订单时抛出错误
|
|
1018
629
|
*/
|
|
1019
630
|
async addPaymentItemAsync(paymentItem) {
|
|
1020
|
-
var _a, _b
|
|
1021
|
-
this.logInfo("addPaymentItemAsync called",
|
|
1022
|
-
paymentCode: paymentItem.code,
|
|
1023
|
-
paymentType: paymentItem.type,
|
|
1024
|
-
amount: paymentItem.amount,
|
|
1025
|
-
voucherId: paymentItem.voucher_id,
|
|
1026
|
-
serviceCharge: paymentItem.service_charge,
|
|
1027
|
-
roundingAmount: paymentItem.rounding_amount,
|
|
1028
|
-
hasMetadata: !!paymentItem.metadata,
|
|
1029
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
1030
|
-
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1031
|
-
isDepositOrder: (_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit
|
|
1032
|
-
});
|
|
631
|
+
var _a, _b;
|
|
632
|
+
this.logInfo("addPaymentItemAsync called", paymentItem);
|
|
1033
633
|
try {
|
|
1034
634
|
if (!this.store.currentOrder) {
|
|
1035
635
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -1049,66 +649,53 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1049
649
|
order_payment_type: orderPaymentType,
|
|
1050
650
|
metadata
|
|
1051
651
|
};
|
|
1052
|
-
console.log("[Checkout] 为当前订单添加支付项:", {
|
|
1053
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1054
|
-
paymentItem: {
|
|
1055
|
-
code: paymentItemWithType.code,
|
|
1056
|
-
name: paymentItemWithType.name,
|
|
1057
|
-
type: paymentItemWithType.type,
|
|
1058
|
-
amount: paymentItemWithType.amount,
|
|
1059
|
-
service_charge: paymentItemWithType.service_charge,
|
|
1060
|
-
rounding_amount: paymentItemWithType.rounding_amount,
|
|
1061
|
-
voucher_id: paymentItemWithType.voucher_id,
|
|
1062
|
-
order_payment_type: paymentItemWithType.order_payment_type,
|
|
1063
|
-
metadata: paymentItemWithType.metadata
|
|
1064
|
-
},
|
|
1065
|
-
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1066
|
-
calculatedOrderPaymentType: orderPaymentType,
|
|
1067
|
-
// 现金支付找零详情
|
|
1068
|
-
isCashPayment: this.isCashPayment(paymentItem.code, paymentItem.type),
|
|
1069
|
-
originalAmount: paymentItem.amount,
|
|
1070
|
-
processedAmount: paymentItemWithType.amount,
|
|
1071
|
-
actualPaidAmount: (_c = paymentItemWithType.metadata) == null ? void 0 : _c.actual_paid_amount,
|
|
1072
|
-
changeGivenAmount: (_d = paymentItemWithType.metadata) == null ? void 0 : _d.change_given_amount
|
|
1073
|
-
});
|
|
1074
652
|
await this.payment.addPaymentItemAsync(
|
|
1075
653
|
this.store.currentOrder.uuid,
|
|
1076
654
|
paymentItemWithType
|
|
1077
655
|
);
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
isEftposPayment
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
656
|
+
this.logInfo("支付项添加成功");
|
|
657
|
+
await this.updateStateAmountToRemaining();
|
|
658
|
+
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
659
|
+
if (Number(remainingAmount) > 0) {
|
|
660
|
+
this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
|
|
661
|
+
const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
|
|
662
|
+
const isCashPayment2 = paymentItem.code === "CASHMANUAL";
|
|
663
|
+
const isCustomePayment = paymentItem.type === "custom";
|
|
664
|
+
this.logInfo("EFTPOS 支付检查:", {
|
|
665
|
+
paymentCode: paymentItem.code,
|
|
666
|
+
paymentType: paymentItem.type,
|
|
667
|
+
isEftposPayment,
|
|
668
|
+
currentOrderSynced: this.store.isOrderSynced
|
|
669
|
+
});
|
|
670
|
+
if (isEftposPayment || isCashPayment2 || isCustomePayment) {
|
|
671
|
+
this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
|
|
672
|
+
try {
|
|
673
|
+
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
674
|
+
this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
|
|
675
|
+
orderId: syncResult.orderId,
|
|
676
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
677
|
+
backendResponse: syncResult.response
|
|
678
|
+
});
|
|
679
|
+
} catch (error) {
|
|
680
|
+
this.logError("EFTPOS 支付后订单同步失败:", error);
|
|
681
|
+
await this.handleError(
|
|
682
|
+
new Error(
|
|
683
|
+
`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
684
|
+
),
|
|
685
|
+
import_types.CheckoutErrorType.OrderCreationFailed
|
|
686
|
+
);
|
|
687
|
+
}
|
|
1101
688
|
}
|
|
1102
689
|
}
|
|
1103
|
-
await this.
|
|
1104
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
690
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentItemAdded, {
|
|
1105
691
|
orderUuid: this.store.currentOrder.uuid,
|
|
1106
692
|
paymentMethodCode: paymentItem.code,
|
|
693
|
+
paymentMethodName: paymentItem.name,
|
|
1107
694
|
amount: String(paymentItem.amount),
|
|
1108
695
|
timestamp: Date.now()
|
|
1109
696
|
});
|
|
1110
697
|
} catch (error) {
|
|
1111
|
-
|
|
698
|
+
this.logError("添加支付项失败:", error);
|
|
1112
699
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1113
700
|
throw error;
|
|
1114
701
|
}
|
|
@@ -1130,7 +717,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1130
717
|
"当前没有活跃订单,无法删除支付项"
|
|
1131
718
|
);
|
|
1132
719
|
}
|
|
1133
|
-
|
|
720
|
+
this.logWarning("开始删除支付项:", {
|
|
1134
721
|
orderUuid: this.store.currentOrder.uuid,
|
|
1135
722
|
paymentUuid
|
|
1136
723
|
});
|
|
@@ -1146,7 +733,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1146
733
|
`支付项不存在: ${paymentUuid}`
|
|
1147
734
|
);
|
|
1148
735
|
}
|
|
1149
|
-
|
|
736
|
+
this.logInfo("找到要删除的支付项:", {
|
|
1150
737
|
uuid: paymentItem.uuid,
|
|
1151
738
|
code: paymentItem.code,
|
|
1152
739
|
amount: paymentItem.amount,
|
|
@@ -1156,7 +743,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1156
743
|
this.store.currentOrder.uuid,
|
|
1157
744
|
paymentUuid
|
|
1158
745
|
);
|
|
1159
|
-
|
|
746
|
+
this.logInfo("Payment支付项删除完成", paymentItem);
|
|
1160
747
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1161
748
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1162
749
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1164,7 +751,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1164
751
|
);
|
|
1165
752
|
if (updatedOrder) {
|
|
1166
753
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1167
|
-
|
|
754
|
+
this.logWarning(
|
|
1168
755
|
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1169
756
|
{
|
|
1170
757
|
currentRealId: currentOrderId,
|
|
@@ -1174,10 +761,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1174
761
|
updatedOrder.order_id = currentOrderId;
|
|
1175
762
|
}
|
|
1176
763
|
this.store.currentOrder = updatedOrder;
|
|
1177
|
-
console.log(
|
|
1178
|
-
"[Checkout] 订单数据已同步,当前支付项数量:",
|
|
1179
|
-
updatedOrder.payment.length
|
|
1180
|
-
);
|
|
1181
764
|
}
|
|
1182
765
|
await this.updateStateAmountToRemaining();
|
|
1183
766
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1187,9 +770,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1187
770
|
// 负数表示删除
|
|
1188
771
|
timestamp: Date.now()
|
|
1189
772
|
});
|
|
1190
|
-
console.log("[Checkout] 支付项删除成功");
|
|
1191
773
|
} catch (error) {
|
|
1192
|
-
|
|
774
|
+
this.logError("删除支付项失败:", error);
|
|
1193
775
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1194
776
|
throw error;
|
|
1195
777
|
}
|
|
@@ -1212,9 +794,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1212
794
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
1213
795
|
);
|
|
1214
796
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
797
|
+
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
798
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
799
|
+
const isOrderSynced = this.store.isOrderSynced;
|
|
800
|
+
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0) {
|
|
801
|
+
this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
|
|
802
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
803
|
+
orderId: this.store.currentOrder.order_id,
|
|
804
|
+
remainingAmount,
|
|
805
|
+
isOrderSynced,
|
|
806
|
+
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
807
|
+
reason: "Order synced and payment completed, skip clear vouchers to avoid duplicate sync"
|
|
808
|
+
});
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
this.logInfo("开始批量更新代金券支付项:", {
|
|
1218
812
|
voucherPaymentItems
|
|
1219
813
|
});
|
|
1220
814
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
@@ -1236,16 +830,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1236
830
|
metadata
|
|
1237
831
|
};
|
|
1238
832
|
});
|
|
1239
|
-
console.log("[Checkout] 代金券支付项订单支付类型设置:", {
|
|
1240
|
-
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1241
|
-
calculatedOrderPaymentType: orderPaymentType,
|
|
1242
|
-
itemsCount: voucherPaymentItemsWithType.length
|
|
1243
|
-
});
|
|
1244
833
|
await this.payment.updateVoucherPaymentItemsAsync(
|
|
1245
834
|
this.store.currentOrder.uuid,
|
|
1246
835
|
voucherPaymentItemsWithType
|
|
1247
836
|
);
|
|
1248
|
-
console.log("[Checkout] Payment模块批量更新完成");
|
|
1249
837
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1250
838
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1251
839
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1253,8 +841,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1253
841
|
);
|
|
1254
842
|
if (updatedOrder) {
|
|
1255
843
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1256
|
-
|
|
1257
|
-
"
|
|
844
|
+
this.logWarning(
|
|
845
|
+
"updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1258
846
|
{
|
|
1259
847
|
currentRealId: currentOrderId,
|
|
1260
848
|
retrievedVirtualId: updatedOrder.order_id
|
|
@@ -1263,22 +851,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1263
851
|
updatedOrder.order_id = currentOrderId;
|
|
1264
852
|
}
|
|
1265
853
|
this.store.currentOrder = updatedOrder;
|
|
1266
|
-
console.log(
|
|
1267
|
-
"[Checkout] 订单数据已同步,当前支付项数量:",
|
|
1268
|
-
updatedOrder.payment.length
|
|
1269
|
-
);
|
|
1270
|
-
const voucherItems = updatedOrder.payment.filter(
|
|
1271
|
-
(payment) => payment.voucher_id && payment.status !== "voided"
|
|
1272
|
-
);
|
|
1273
|
-
console.log("[Checkout] 更新后的代金券支付项:", {
|
|
1274
|
-
voucherCount: voucherItems.length,
|
|
1275
|
-
items: voucherItems.map((item) => ({
|
|
1276
|
-
uuid: item.uuid,
|
|
1277
|
-
code: item.code,
|
|
1278
|
-
amount: item.amount,
|
|
1279
|
-
voucher_id: item.voucher_id
|
|
1280
|
-
}))
|
|
1281
|
-
});
|
|
1282
854
|
}
|
|
1283
855
|
await this.updateStateAmountToRemaining();
|
|
1284
856
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1287,9 +859,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1287
859
|
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1288
860
|
timestamp: Date.now()
|
|
1289
861
|
});
|
|
1290
|
-
|
|
862
|
+
this.logInfo("代金券支付项批量更新成功");
|
|
1291
863
|
} catch (error) {
|
|
1292
|
-
|
|
864
|
+
this.logError("[Checkout] 批量更新代金券支付项失败:", error);
|
|
1293
865
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1294
866
|
throw error;
|
|
1295
867
|
}
|
|
@@ -1322,18 +894,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1322
894
|
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1323
895
|
return;
|
|
1324
896
|
}
|
|
1325
|
-
console.log("[Checkout] 更新订单定金状态:", {
|
|
1326
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1327
|
-
orderId: this.store.currentOrder.order_id,
|
|
1328
|
-
oldIsDeposit: oldDepositValue,
|
|
1329
|
-
newIsDeposit: newDepositValue
|
|
1330
|
-
});
|
|
1331
897
|
const updateParams = {
|
|
1332
898
|
is_deposit: newDepositValue
|
|
1333
899
|
};
|
|
1334
900
|
if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== "0.00") {
|
|
1335
901
|
updateParams.deposit_amount = "0.00";
|
|
1336
|
-
|
|
902
|
+
this.logInfo("订单从定金改为全款,清空定金金额");
|
|
1337
903
|
}
|
|
1338
904
|
await this.payment.updateOrderAsync(
|
|
1339
905
|
this.store.currentOrder.uuid,
|
|
@@ -1350,12 +916,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1350
916
|
order: this.store.currentOrder,
|
|
1351
917
|
timestamp: Date.now()
|
|
1352
918
|
});
|
|
1353
|
-
|
|
919
|
+
this.logInfo("订单定金状态更新成功:", {
|
|
1354
920
|
isDeposit: newDepositValue,
|
|
1355
921
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1356
922
|
});
|
|
1357
923
|
} catch (error) {
|
|
1358
|
-
|
|
924
|
+
this.logError("更新订单定金状态失败:", error);
|
|
1359
925
|
await this.handleError(
|
|
1360
926
|
error,
|
|
1361
927
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1364,40 +930,99 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1364
930
|
}
|
|
1365
931
|
}
|
|
1366
932
|
/**
|
|
1367
|
-
*
|
|
933
|
+
* 手动设置当前订单的定金金额
|
|
1368
934
|
*
|
|
1369
|
-
*
|
|
935
|
+
* 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
|
|
1370
936
|
*
|
|
1371
|
-
* @param
|
|
937
|
+
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
1372
938
|
* @throws 当前没有活跃订单时抛出错误
|
|
939
|
+
* @throws 定金金额格式无效或超过订单总额时抛出错误
|
|
1373
940
|
*/
|
|
1374
|
-
async
|
|
941
|
+
async setDepositAmountAsync(depositAmount) {
|
|
942
|
+
var _a, _b;
|
|
943
|
+
this.logInfo("setDepositAmountAsync called", {
|
|
944
|
+
depositAmount,
|
|
945
|
+
hasCurrentOrder: !!this.store.currentOrder,
|
|
946
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
947
|
+
currentTotalAmount: (_b = this.store.currentOrder) == null ? void 0 : _b.total_amount
|
|
948
|
+
});
|
|
1375
949
|
try {
|
|
950
|
+
const depositValue = new import_decimal.default(depositAmount);
|
|
951
|
+
if (depositValue.isNaN() || depositValue.lt(0)) {
|
|
952
|
+
throw (0, import_utils.createCheckoutError)(
|
|
953
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
954
|
+
`无效的定金金额格式: ${depositAmount}`
|
|
955
|
+
);
|
|
956
|
+
}
|
|
1376
957
|
if (!this.store.currentOrder) {
|
|
1377
958
|
throw (0, import_utils.createCheckoutError)(
|
|
1378
959
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1379
|
-
"
|
|
960
|
+
"未找到当前订单,无法设置定金金额"
|
|
1380
961
|
);
|
|
1381
962
|
}
|
|
1382
|
-
|
|
963
|
+
const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
964
|
+
if (depositValue.gt(totalAmount)) {
|
|
965
|
+
throw (0, import_utils.createCheckoutError)(
|
|
966
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
967
|
+
`定金金额 ${depositAmount} 不能超过订单总额 ${totalAmount.toFixed(2)}`
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
const formattedDepositAmount = depositValue.toFixed(2);
|
|
971
|
+
const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
|
|
972
|
+
if (formattedDepositAmount === oldDepositAmount) {
|
|
973
|
+
this.logInfo("定金金额无变化,跳过更新:", {
|
|
974
|
+
currentAmount: oldDepositAmount,
|
|
975
|
+
newAmount: formattedDepositAmount
|
|
976
|
+
});
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
this.logInfo("开始设置订单定金金额:", {
|
|
1383
980
|
orderUuid: this.store.currentOrder.uuid,
|
|
1384
|
-
|
|
1385
|
-
|
|
981
|
+
orderId: this.store.currentOrder.order_id,
|
|
982
|
+
oldDepositAmount,
|
|
983
|
+
newDepositAmount: formattedDepositAmount,
|
|
984
|
+
totalAmount: totalAmount.toFixed(2)
|
|
1386
985
|
});
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
customer_name: customer.customer_name
|
|
986
|
+
const updateParams = {
|
|
987
|
+
deposit_amount: formattedDepositAmount
|
|
1390
988
|
};
|
|
1391
|
-
if (this.store.
|
|
1392
|
-
|
|
1393
|
-
this.
|
|
989
|
+
if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
|
|
990
|
+
updateParams.is_deposit = 1;
|
|
991
|
+
this.logInfo("定金金额大于0,自动设置为定金订单");
|
|
992
|
+
} else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
993
|
+
updateParams.is_deposit = 0;
|
|
994
|
+
this.logInfo("定金金额为0,自动设置为全款订单");
|
|
1394
995
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
996
|
+
await this.payment.updateOrderAsync(
|
|
997
|
+
this.store.currentOrder.uuid,
|
|
998
|
+
updateParams
|
|
1398
999
|
);
|
|
1000
|
+
this.store.currentOrder = {
|
|
1001
|
+
...this.store.currentOrder,
|
|
1002
|
+
...updateParams
|
|
1003
|
+
};
|
|
1004
|
+
if (this.store.localOrderData) {
|
|
1005
|
+
if ("deposit_amount" in this.store.localOrderData) {
|
|
1006
|
+
this.store.localOrderData.deposit_amount = formattedDepositAmount;
|
|
1007
|
+
}
|
|
1008
|
+
if (updateParams.is_deposit !== void 0) {
|
|
1009
|
+
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
1013
|
+
order: this.store.currentOrder,
|
|
1014
|
+
timestamp: Date.now()
|
|
1015
|
+
});
|
|
1016
|
+
this.logInfo("订单定金金额设置成功:", {
|
|
1017
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1018
|
+
orderId: this.store.currentOrder.order_id,
|
|
1019
|
+
oldDepositAmount,
|
|
1020
|
+
newDepositAmount: formattedDepositAmount,
|
|
1021
|
+
isDeposit: this.store.currentOrder.is_deposit,
|
|
1022
|
+
totalAmount: this.store.currentOrder.total_amount
|
|
1023
|
+
});
|
|
1399
1024
|
} catch (error) {
|
|
1400
|
-
|
|
1025
|
+
this.logError("设置订单定金金额失败:", error);
|
|
1401
1026
|
await this.handleError(
|
|
1402
1027
|
error,
|
|
1403
1028
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1405,58 +1030,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1405
1030
|
throw error;
|
|
1406
1031
|
}
|
|
1407
1032
|
}
|
|
1408
|
-
/**
|
|
1409
|
-
* 获取当前订单的客户信息
|
|
1410
|
-
*
|
|
1411
|
-
* @returns 当前客户信息,如果没有则返回 null
|
|
1412
|
-
*/
|
|
1413
|
-
getCurrentCustomer() {
|
|
1414
|
-
return this.store.currentCustomer || null;
|
|
1415
|
-
}
|
|
1416
|
-
/**
|
|
1417
|
-
* 检查订单是否需要手动同步(异步版本)
|
|
1418
|
-
*
|
|
1419
|
-
* 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
|
|
1420
|
-
* 从 Payment 模块获取最新的支付项数据
|
|
1421
|
-
*/
|
|
1422
|
-
async needsManualSyncAsync() {
|
|
1423
|
-
try {
|
|
1424
|
-
if (!this.store.currentOrder || this.store.isOrderSynced) {
|
|
1425
|
-
return false;
|
|
1426
|
-
}
|
|
1427
|
-
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1428
|
-
const remainingValue = new import_decimal.default(remainingAmount);
|
|
1429
|
-
if (remainingValue.gt(0)) {
|
|
1430
|
-
return false;
|
|
1431
|
-
}
|
|
1432
|
-
const currentPayments = await this.payment.getPaymentItemsAsync(
|
|
1433
|
-
this.store.currentOrder.uuid,
|
|
1434
|
-
false
|
|
1435
|
-
// 不包括已撤销的支付项
|
|
1436
|
-
);
|
|
1437
|
-
const allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(
|
|
1438
|
-
(item) => item.status !== "voided" && item.voucher_id
|
|
1439
|
-
);
|
|
1440
|
-
console.log("[Checkout] needsManualSyncAsync 检查结果:", {
|
|
1441
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1442
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
1443
|
-
remainingAmount,
|
|
1444
|
-
hasPayments: currentPayments.length > 0,
|
|
1445
|
-
allPaymentsHaveVoucherId,
|
|
1446
|
-
needsManualSync: allPaymentsHaveVoucherId,
|
|
1447
|
-
paymentItems: currentPayments.map((p) => ({
|
|
1448
|
-
code: p.code,
|
|
1449
|
-
amount: p.amount,
|
|
1450
|
-
status: p.status,
|
|
1451
|
-
hasVoucherId: !!p.voucher_id
|
|
1452
|
-
}))
|
|
1453
|
-
});
|
|
1454
|
-
return allPaymentsHaveVoucherId;
|
|
1455
|
-
} catch (error) {
|
|
1456
|
-
console.error("[Checkout] needsManualSyncAsync 检查失败:", error);
|
|
1457
|
-
return false;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
1033
|
/**
|
|
1461
1034
|
* 手动同步订单到后端
|
|
1462
1035
|
*
|
|
@@ -1482,16 +1055,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1482
1055
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1483
1056
|
const oldOrderId = this.store.currentOrder.order_id;
|
|
1484
1057
|
if (this.store.isOrderSynced) {
|
|
1485
|
-
|
|
1058
|
+
this.logInfo("订单已同步过,将执行更新操作");
|
|
1486
1059
|
}
|
|
1487
|
-
|
|
1060
|
+
this.logInfo("开始手动同步订单到后端:", {
|
|
1488
1061
|
orderUuid,
|
|
1489
1062
|
orderId: oldOrderId,
|
|
1490
1063
|
totalAmount: this.store.currentOrder.total_amount,
|
|
1491
1064
|
remainingAmount: await this.calculateRemainingAmountAsync()
|
|
1492
1065
|
});
|
|
1493
1066
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1494
|
-
|
|
1067
|
+
this.logInfo("手动同步订单完成:", {
|
|
1495
1068
|
orderUuid,
|
|
1496
1069
|
syncResult,
|
|
1497
1070
|
oldOrderId,
|
|
@@ -1500,24 +1073,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1500
1073
|
});
|
|
1501
1074
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1502
1075
|
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId);
|
|
1503
|
-
console.log("[Checkout] manualSyncOrderAsync 最终状态验证:", {
|
|
1504
|
-
returnedOrderId: syncResult.orderId,
|
|
1505
|
-
storedOrderId: finalOrderId,
|
|
1506
|
-
storedIdIsVirtual: finalIsVirtual,
|
|
1507
|
-
isConsistent: syncResult.orderId === finalOrderId,
|
|
1508
|
-
syncStatus: this.store.isOrderSynced
|
|
1509
|
-
});
|
|
1510
1076
|
if (finalIsVirtual) {
|
|
1511
|
-
|
|
1077
|
+
this.logError("严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1512
1078
|
}
|
|
1513
1079
|
if (syncResult.orderId !== finalOrderId) {
|
|
1514
|
-
|
|
1080
|
+
this.logError(
|
|
1515
1081
|
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1516
1082
|
);
|
|
1517
1083
|
}
|
|
1518
1084
|
return syncResult;
|
|
1519
1085
|
} catch (error) {
|
|
1520
|
-
|
|
1086
|
+
this.logError("手动同步订单失败:", error);
|
|
1521
1087
|
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1522
1088
|
return {
|
|
1523
1089
|
success: false,
|
|
@@ -1578,7 +1144,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1578
1144
|
async cancelCurrentOrderAsync(cancelReason) {
|
|
1579
1145
|
var _a, _b;
|
|
1580
1146
|
try {
|
|
1581
|
-
|
|
1147
|
+
this.logInfo("开始取消当前本地订单:", {
|
|
1582
1148
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1583
1149
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1584
1150
|
orderId: (_b = this.store.currentOrder) == null ? void 0 : _b.order_id,
|
|
@@ -1586,7 +1152,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1586
1152
|
cancelReason
|
|
1587
1153
|
});
|
|
1588
1154
|
if (!this.store.currentOrder) {
|
|
1589
|
-
|
|
1155
|
+
this.logInfo("没有当前订单,无需取消");
|
|
1590
1156
|
return {
|
|
1591
1157
|
success: false,
|
|
1592
1158
|
message: "没有当前订单可取消"
|
|
@@ -1596,7 +1162,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1596
1162
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1597
1163
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1598
1164
|
if (isOrderSynced) {
|
|
1599
|
-
|
|
1165
|
+
this.logInfo("订单已同步到后端,不能取消:", {
|
|
1600
1166
|
orderId: currentOrderId,
|
|
1601
1167
|
orderUuid: currentOrderUuid
|
|
1602
1168
|
});
|
|
@@ -1606,15 +1172,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1606
1172
|
orderId: currentOrderId
|
|
1607
1173
|
};
|
|
1608
1174
|
}
|
|
1609
|
-
console.log("[Checkout] 订单尚未同步,可以取消");
|
|
1610
1175
|
try {
|
|
1611
|
-
|
|
1176
|
+
this.logInfo("删除本地订单数据");
|
|
1612
1177
|
await this.payment.deletePaymentOrderAsync(currentOrderUuid);
|
|
1613
|
-
|
|
1178
|
+
this.logInfo("本地订单数据删除成功");
|
|
1614
1179
|
} catch (error) {
|
|
1615
|
-
|
|
1180
|
+
this.logWarning("删除本地订单数据失败,但继续执行:", error);
|
|
1616
1181
|
}
|
|
1617
|
-
|
|
1182
|
+
this.logInfo("清理订单相关状态");
|
|
1618
1183
|
this.store.currentOrder = void 0;
|
|
1619
1184
|
this.store.localOrderData = void 0;
|
|
1620
1185
|
this.store.stateAmount = "0.00";
|
|
@@ -1622,7 +1187,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1622
1187
|
this.store.isOrderSynced = false;
|
|
1623
1188
|
this.store.currentCustomer = void 0;
|
|
1624
1189
|
this.payment.wallet.clearAllCache();
|
|
1625
|
-
|
|
1190
|
+
this.logInfo("订单状态清理完成,currentOrder已释放");
|
|
1626
1191
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCancelled, {
|
|
1627
1192
|
orderUuid: currentOrderUuid,
|
|
1628
1193
|
orderId: currentOrderId,
|
|
@@ -1631,7 +1196,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1631
1196
|
// 只有未同步订单可以被取消
|
|
1632
1197
|
timestamp: Date.now()
|
|
1633
1198
|
});
|
|
1634
|
-
|
|
1199
|
+
this.logInfo("本地订单取消完成:", {
|
|
1635
1200
|
orderUuid: currentOrderUuid,
|
|
1636
1201
|
orderId: currentOrderId,
|
|
1637
1202
|
cancelReason
|
|
@@ -1642,7 +1207,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1642
1207
|
orderId: currentOrderId
|
|
1643
1208
|
};
|
|
1644
1209
|
} catch (error) {
|
|
1645
|
-
|
|
1210
|
+
this.logError("取消本地订单失败:", error);
|
|
1646
1211
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
|
1647
1212
|
return {
|
|
1648
1213
|
success: false,
|
|
@@ -1667,7 +1232,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1667
1232
|
}
|
|
1668
1233
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1669
1234
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1670
|
-
|
|
1235
|
+
this.logInfo("开始保存订单并稍后支付:", {
|
|
1671
1236
|
orderUuid,
|
|
1672
1237
|
orderId: currentOrderId,
|
|
1673
1238
|
totalAmount: this.store.currentOrder.total_amount
|
|
@@ -1676,10 +1241,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1676
1241
|
this.store.currentOrder.uuid
|
|
1677
1242
|
);
|
|
1678
1243
|
const syncResult = await this.syncOrderToBackendWithReturn(
|
|
1679
|
-
|
|
1244
|
+
true,
|
|
1680
1245
|
allPaymentItems
|
|
1681
1246
|
);
|
|
1682
|
-
|
|
1247
|
+
this.logInfo("保存订单完成:", {
|
|
1683
1248
|
orderUuid,
|
|
1684
1249
|
oldOrderId: currentOrderId,
|
|
1685
1250
|
syncResult,
|
|
@@ -1687,13 +1252,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1687
1252
|
isOrderSynced: this.store.isOrderSynced,
|
|
1688
1253
|
filteredPaymentsCount: allPaymentItems.length
|
|
1689
1254
|
});
|
|
1690
|
-
const finalOrderId = this.store.currentOrder.order_id;
|
|
1691
|
-
console.log("[Checkout] saveForLaterPaymentAsync 最终状态验证:", {
|
|
1692
|
-
returnedOrderId: syncResult.orderId,
|
|
1693
|
-
storedOrderId: finalOrderId,
|
|
1694
|
-
isConsistent: syncResult.orderId === finalOrderId,
|
|
1695
|
-
syncStatus: this.store.isOrderSynced
|
|
1696
|
-
});
|
|
1697
1255
|
return {
|
|
1698
1256
|
success: true,
|
|
1699
1257
|
message: "订单保存成功,可稍后继续支付",
|
|
@@ -1702,7 +1260,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1702
1260
|
response: syncResult.response
|
|
1703
1261
|
};
|
|
1704
1262
|
} catch (error) {
|
|
1705
|
-
|
|
1263
|
+
this.logError("保存订单失败:", error);
|
|
1706
1264
|
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1707
1265
|
return {
|
|
1708
1266
|
success: false,
|
|
@@ -1711,93 +1269,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1711
1269
|
};
|
|
1712
1270
|
}
|
|
1713
1271
|
}
|
|
1714
|
-
/**
|
|
1715
|
-
* 获取当前商店折扣金额
|
|
1716
|
-
*
|
|
1717
|
-
* @returns 当前的商店折扣金额,如果没有则返回0
|
|
1718
|
-
*/
|
|
1719
|
-
getShopDiscount() {
|
|
1720
|
-
var _a;
|
|
1721
|
-
if (((_a = this.store.localOrderData) == null ? void 0 : _a.shop_discount) !== void 0) {
|
|
1722
|
-
return this.store.localOrderData.shop_discount;
|
|
1723
|
-
}
|
|
1724
|
-
if (this.store.cartSummary) {
|
|
1725
|
-
const shopDiscountItem = this.store.cartSummary.find(
|
|
1726
|
-
(item) => item.key === "shop_discount"
|
|
1727
|
-
);
|
|
1728
|
-
if (shopDiscountItem) {
|
|
1729
|
-
return shopDiscountItem.value;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
return 0;
|
|
1733
|
-
}
|
|
1734
|
-
/**
|
|
1735
|
-
* 更新订单商店折扣
|
|
1736
|
-
*
|
|
1737
|
-
* 同时更新cartSummary和localOrderData中的shop_discount值
|
|
1738
|
-
*
|
|
1739
|
-
* @param discountAmount 商店折扣金额
|
|
1740
|
-
*/
|
|
1741
|
-
async updateShopDiscountAsync(discountAmount) {
|
|
1742
|
-
var _a, _b;
|
|
1743
|
-
try {
|
|
1744
|
-
const oldDiscount = this.getShopDiscount();
|
|
1745
|
-
console.log("[Checkout] 更新商店折扣:", {
|
|
1746
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1747
|
-
oldDiscount,
|
|
1748
|
-
newDiscount: discountAmount
|
|
1749
|
-
});
|
|
1750
|
-
if (this.store.cartSummary) {
|
|
1751
|
-
const shopDiscountItem = this.store.cartSummary.find(
|
|
1752
|
-
(item) => item.key === "shop_discount"
|
|
1753
|
-
);
|
|
1754
|
-
if (shopDiscountItem) {
|
|
1755
|
-
shopDiscountItem.value = discountAmount;
|
|
1756
|
-
console.log("[Checkout] cartSummary 中的商店折扣已更新");
|
|
1757
|
-
} else {
|
|
1758
|
-
this.store.cartSummary.push({
|
|
1759
|
-
key: "shop_discount",
|
|
1760
|
-
value: discountAmount,
|
|
1761
|
-
hidden: true,
|
|
1762
|
-
label: "Shop Discount"
|
|
1763
|
-
});
|
|
1764
|
-
console.log("[Checkout] cartSummary 中已添加新的商店折扣项");
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
if (this.store.localOrderData) {
|
|
1768
|
-
this.store.localOrderData.shop_discount = discountAmount;
|
|
1769
|
-
console.log("[Checkout] localOrderData 中的商店折扣已更新");
|
|
1770
|
-
} else {
|
|
1771
|
-
console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
|
|
1772
|
-
}
|
|
1773
|
-
if (this.store.currentOrder && this.store.cartSummary) {
|
|
1774
|
-
const updatedAmountInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
1775
|
-
this.store.cartSummary
|
|
1776
|
-
);
|
|
1777
|
-
console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
|
|
1778
|
-
this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
|
|
1779
|
-
this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
|
|
1780
|
-
}
|
|
1781
|
-
await this.updateStateAmountToRemaining();
|
|
1782
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnShopDiscountChanged, {
|
|
1783
|
-
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1784
|
-
oldDiscount,
|
|
1785
|
-
newDiscount: discountAmount,
|
|
1786
|
-
timestamp: Date.now()
|
|
1787
|
-
});
|
|
1788
|
-
console.log("[Checkout] 商店折扣更新成功:", {
|
|
1789
|
-
oldDiscount,
|
|
1790
|
-
newDiscount: discountAmount
|
|
1791
|
-
});
|
|
1792
|
-
} catch (error) {
|
|
1793
|
-
console.error("[Checkout] 更新商店折扣失败:", error);
|
|
1794
|
-
await this.handleError(
|
|
1795
|
-
error,
|
|
1796
|
-
import_types.CheckoutErrorType.ValidationFailed
|
|
1797
|
-
);
|
|
1798
|
-
throw error;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
1272
|
/**
|
|
1802
1273
|
* 更新订单备注
|
|
1803
1274
|
*
|
|
@@ -1853,40 +1324,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1853
1324
|
throw error;
|
|
1854
1325
|
}
|
|
1855
1326
|
}
|
|
1856
|
-
/**
|
|
1857
|
-
* 设置状态
|
|
1858
|
-
*/
|
|
1859
|
-
setStatus(status) {
|
|
1860
|
-
const oldStatus = this.store.status;
|
|
1861
|
-
this.store.status = status;
|
|
1862
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStatusChanged, {
|
|
1863
|
-
oldStatus,
|
|
1864
|
-
newStatus: status,
|
|
1865
|
-
timestamp: Date.now()
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
|
-
* 设置步骤
|
|
1870
|
-
*/
|
|
1871
|
-
setStep(step) {
|
|
1872
|
-
const oldStep = this.store.step;
|
|
1873
|
-
this.store.step = step;
|
|
1874
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
1875
|
-
oldStep,
|
|
1876
|
-
newStep: step,
|
|
1877
|
-
timestamp: Date.now()
|
|
1878
|
-
});
|
|
1879
|
-
}
|
|
1880
1327
|
/**
|
|
1881
1328
|
* 处理错误
|
|
1882
1329
|
*/
|
|
1883
1330
|
async handleError(error, type) {
|
|
1884
1331
|
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1885
1332
|
this.store.lastError = checkoutError;
|
|
1886
|
-
this.setStatus(import_types.CheckoutStatus.Error);
|
|
1887
1333
|
await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
|
|
1888
1334
|
error: checkoutError,
|
|
1889
|
-
context: {
|
|
1335
|
+
context: {},
|
|
1890
1336
|
timestamp: Date.now()
|
|
1891
1337
|
});
|
|
1892
1338
|
console.error("[Checkout] 错误:", checkoutError);
|
|
@@ -1896,7 +1342,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1896
1342
|
*/
|
|
1897
1343
|
async handlePaymentSuccess(data) {
|
|
1898
1344
|
var _a;
|
|
1899
|
-
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
1900
1345
|
await this.updateStateAmountToRemaining();
|
|
1901
1346
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
1902
1347
|
orderUuid: data.orderUuid,
|
|
@@ -1934,24 +1379,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1934
1379
|
}
|
|
1935
1380
|
/**
|
|
1936
1381
|
* 处理现金支付项的找零逻辑
|
|
1937
|
-
*
|
|
1382
|
+
*
|
|
1938
1383
|
* @param paymentItem 原始支付项
|
|
1939
1384
|
* @returns 处理后的支付项(包含找零信息)
|
|
1940
1385
|
*/
|
|
1941
1386
|
async processCashPaymentItem(paymentItem) {
|
|
1942
|
-
const
|
|
1943
|
-
if (!
|
|
1387
|
+
const cashPayment = (0, import_utils.isCashPayment)(paymentItem.code, paymentItem.type);
|
|
1388
|
+
if (!cashPayment) {
|
|
1944
1389
|
return paymentItem;
|
|
1945
1390
|
}
|
|
1946
1391
|
try {
|
|
1947
1392
|
const remainingAmountStr = await this.calculateRemainingAmountAsync();
|
|
1948
1393
|
let remainingAmount = new import_decimal.default(remainingAmountStr);
|
|
1949
1394
|
const cashAmount = new import_decimal.default(String(paymentItem.amount));
|
|
1950
|
-
console.log("[Checkout] 现金支付处理:", {
|
|
1951
|
-
cashAmount: cashAmount.toNumber(),
|
|
1952
|
-
remainingAmount: remainingAmount.toNumber(),
|
|
1953
|
-
needsChange: cashAmount.gt(remainingAmount)
|
|
1954
|
-
});
|
|
1955
1395
|
if (cashAmount.lte(remainingAmount)) {
|
|
1956
1396
|
return paymentItem;
|
|
1957
1397
|
}
|
|
@@ -1960,14 +1400,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1960
1400
|
if (Number(paymentItem.rounding_amount) === changeAmount.toNumber()) {
|
|
1961
1401
|
return paymentItem;
|
|
1962
1402
|
} else {
|
|
1963
|
-
remainingAmount = remainingAmount.add(
|
|
1403
|
+
remainingAmount = remainingAmount.add(
|
|
1404
|
+
new import_decimal.default(paymentItem.rounding_amount || "0")
|
|
1405
|
+
);
|
|
1964
1406
|
}
|
|
1965
1407
|
}
|
|
1966
|
-
console.log("[Checkout] 现金支付需要找零:", {
|
|
1967
|
-
actualPaidAmount: cashAmount.toFixed(2),
|
|
1968
|
-
chargedAmount: remainingAmount.toFixed(2),
|
|
1969
|
-
changeGivenAmount: changeAmount.toFixed(2)
|
|
1970
|
-
});
|
|
1971
1408
|
const processedPaymentItem = {
|
|
1972
1409
|
...paymentItem,
|
|
1973
1410
|
amount: remainingAmount.toFixed(2),
|
|
@@ -1995,25 +1432,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1995
1432
|
});
|
|
1996
1433
|
return processedPaymentItem;
|
|
1997
1434
|
} catch (error) {
|
|
1998
|
-
|
|
1435
|
+
this.logError("处理现金支付项时出错:", error);
|
|
1999
1436
|
return paymentItem;
|
|
2000
1437
|
}
|
|
2001
1438
|
}
|
|
2002
|
-
/**
|
|
2003
|
-
* 判断是否为现金支付
|
|
2004
|
-
*
|
|
2005
|
-
* @param paymentCode 支付代码
|
|
2006
|
-
* @param paymentType 支付类型
|
|
2007
|
-
* @returns 是否为现金支付
|
|
2008
|
-
*/
|
|
2009
|
-
isCashPayment(paymentCode, paymentType) {
|
|
2010
|
-
const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
|
|
2011
|
-
const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
|
|
2012
|
-
const cashIdentifiers = ["CASH", "CASHMANUAL", "MANUAL"];
|
|
2013
|
-
return cashIdentifiers.some(
|
|
2014
|
-
(identifier) => codeUpper.includes(identifier) || typeUpper.includes(identifier)
|
|
2015
|
-
);
|
|
2016
|
-
}
|
|
2017
1439
|
/**
|
|
2018
1440
|
* 预加载支付方式(在初始化时调用)
|
|
2019
1441
|
*/
|
|
@@ -2030,7 +1452,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2030
1452
|
}
|
|
2031
1453
|
/**
|
|
2032
1454
|
* 清理过期的已同步订单数据
|
|
2033
|
-
*
|
|
1455
|
+
*
|
|
2034
1456
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
2035
1457
|
*/
|
|
2036
1458
|
async cleanupExpiredOrdersAsync() {
|
|
@@ -2044,7 +1466,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2044
1466
|
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
2045
1467
|
return;
|
|
2046
1468
|
}
|
|
2047
|
-
console.log(
|
|
1469
|
+
console.log(
|
|
1470
|
+
`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`
|
|
1471
|
+
);
|
|
2048
1472
|
const allOrders = await this.payment.getOrderListAsync();
|
|
2049
1473
|
if (!allOrders || allOrders.length === 0) {
|
|
2050
1474
|
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
@@ -2064,7 +1488,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2064
1488
|
if ((_a = order.order_info) == null ? void 0 : _a.created_at) {
|
|
2065
1489
|
orderCreatedAt = new Date(order.order_info.created_at);
|
|
2066
1490
|
} else if ((_c = (_b = order.order_info) == null ? void 0 : _b.original_order_data) == null ? void 0 : _c.created_at) {
|
|
2067
|
-
orderCreatedAt = new Date(
|
|
1491
|
+
orderCreatedAt = new Date(
|
|
1492
|
+
order.order_info.original_order_data.created_at
|
|
1493
|
+
);
|
|
2068
1494
|
}
|
|
2069
1495
|
if (!orderCreatedAt || isNaN(orderCreatedAt.getTime())) {
|
|
2070
1496
|
continue;
|
|
@@ -2074,7 +1500,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2074
1500
|
uuid: order.uuid,
|
|
2075
1501
|
orderId: order.order_id,
|
|
2076
1502
|
createdAt: orderCreatedAt.toISOString(),
|
|
2077
|
-
daysSinceCreated: Math.floor(
|
|
1503
|
+
daysSinceCreated: Math.floor(
|
|
1504
|
+
(Date.now() - orderCreatedAt.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1505
|
+
)
|
|
2078
1506
|
});
|
|
2079
1507
|
}
|
|
2080
1508
|
} catch (error) {
|
|
@@ -2082,13 +1510,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2082
1510
|
continue;
|
|
2083
1511
|
}
|
|
2084
1512
|
}
|
|
2085
|
-
ordersToDelete.sort(
|
|
1513
|
+
ordersToDelete.sort(
|
|
1514
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
1515
|
+
);
|
|
2086
1516
|
const actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete);
|
|
2087
1517
|
for (const orderInfo of actualOrdersToDelete) {
|
|
2088
1518
|
try {
|
|
2089
1519
|
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
2090
1520
|
deletedCount++;
|
|
2091
|
-
console.log(
|
|
1521
|
+
console.log(
|
|
1522
|
+
`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`
|
|
1523
|
+
);
|
|
2092
1524
|
} catch (error) {
|
|
2093
1525
|
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
2094
1526
|
}
|
|
@@ -2105,9 +1537,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2105
1537
|
};
|
|
2106
1538
|
this.logInfo("Expired orders cleanup completed", summary);
|
|
2107
1539
|
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
2108
|
-
console.log(
|
|
1540
|
+
console.log(
|
|
1541
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`
|
|
1542
|
+
);
|
|
2109
1543
|
} else {
|
|
2110
|
-
console.log(
|
|
1544
|
+
console.log(
|
|
1545
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`
|
|
1546
|
+
);
|
|
2111
1547
|
}
|
|
2112
1548
|
} catch (error) {
|
|
2113
1549
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -2120,7 +1556,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2120
1556
|
*/
|
|
2121
1557
|
async calculatePaidAmountAsync() {
|
|
2122
1558
|
if (!this.store.currentOrder) {
|
|
2123
|
-
|
|
1559
|
+
this.logWarning("[Checkout] calculatePaidAmountAsync: 没有当前订单");
|
|
2124
1560
|
return "0.00";
|
|
2125
1561
|
}
|
|
2126
1562
|
try {
|
|
@@ -2129,16 +1565,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2129
1565
|
false
|
|
2130
1566
|
// 不包括已撤销的支付项
|
|
2131
1567
|
);
|
|
2132
|
-
console.log("[Checkout] calculatePaidAmountAsync: 支付项详情:", {
|
|
2133
|
-
paymentCount: payments.length,
|
|
2134
|
-
payments: payments.map((p) => ({
|
|
2135
|
-
uuid: p.uuid,
|
|
2136
|
-
amount: p.amount,
|
|
2137
|
-
code: p.code,
|
|
2138
|
-
status: p.status,
|
|
2139
|
-
rounding_amount: p.rounding_amount
|
|
2140
|
-
}))
|
|
2141
|
-
});
|
|
2142
1568
|
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
2143
1569
|
const amount = new import_decimal.default(payment.amount || "0");
|
|
2144
1570
|
const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
|
|
@@ -2158,10 +1584,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2158
1584
|
return sum.add(effectiveAmount);
|
|
2159
1585
|
}, new import_decimal.default(0));
|
|
2160
1586
|
const result = paidAmount.toFixed(2);
|
|
2161
|
-
|
|
1587
|
+
this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
|
|
2162
1588
|
return result;
|
|
2163
1589
|
} catch (error) {
|
|
2164
|
-
|
|
1590
|
+
this.logError("calculatePaidAmountAsync 失败:", error);
|
|
2165
1591
|
return "0.00";
|
|
2166
1592
|
}
|
|
2167
1593
|
}
|
|
@@ -2170,45 +1596,26 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2170
1596
|
*/
|
|
2171
1597
|
async calculateRemainingAmountAsync() {
|
|
2172
1598
|
if (!this.store.currentOrder) {
|
|
2173
|
-
|
|
1599
|
+
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
2174
1600
|
return "0.00";
|
|
2175
1601
|
}
|
|
2176
|
-
const totalAmount = new import_decimal.default(
|
|
1602
|
+
const totalAmount = new import_decimal.default(
|
|
1603
|
+
this.store.currentOrder.total_amount || "0"
|
|
1604
|
+
);
|
|
2177
1605
|
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
2178
1606
|
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
2179
1607
|
const remainingAmount = totalAmount.sub(paidAmount);
|
|
2180
1608
|
const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
2181
|
-
|
|
2182
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2183
|
-
totalAmount: totalAmount.toFixed(2),
|
|
2184
|
-
paidAmount: paidAmount.toFixed(2),
|
|
2185
|
-
calculatedRemaining: remainingAmount.toFixed(2),
|
|
2186
|
-
finalResult: result,
|
|
2187
|
-
description: "已支付金额包含抹零计算(amount + |rounding_amount|)",
|
|
2188
|
-
// Decimal 精度验证
|
|
2189
|
-
preciseCalculationValues: {
|
|
2190
|
-
totalAmount: totalAmount.toString(),
|
|
2191
|
-
paidAmount: paidAmount.toString(),
|
|
2192
|
-
remainingAmount: remainingAmount.toString(),
|
|
2193
|
-
resultAfterMax: import_decimal.default.max(0, remainingAmount).toString()
|
|
2194
|
-
}
|
|
2195
|
-
});
|
|
1609
|
+
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
2196
1610
|
return result;
|
|
2197
1611
|
}
|
|
2198
1612
|
/**
|
|
2199
1613
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
2200
1614
|
*/
|
|
2201
1615
|
async updateBalanceDueAmount() {
|
|
2202
|
-
var _a;
|
|
2203
1616
|
try {
|
|
2204
1617
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2205
1618
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
2206
|
-
console.log("[Checkout] updateBalanceDueAmount: 状态检查:", {
|
|
2207
|
-
calculatedRemainingAmount: remainingAmount,
|
|
2208
|
-
currentBalanceDueAmount,
|
|
2209
|
-
needsUpdate: remainingAmount !== currentBalanceDueAmount,
|
|
2210
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
2211
|
-
});
|
|
2212
1619
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
2213
1620
|
this.store.balanceDueAmount = remainingAmount;
|
|
2214
1621
|
await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
|
|
@@ -2216,34 +1623,27 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2216
1623
|
newAmount: remainingAmount,
|
|
2217
1624
|
timestamp: Date.now()
|
|
2218
1625
|
});
|
|
2219
|
-
|
|
1626
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
2220
1627
|
oldAmount: currentBalanceDueAmount,
|
|
2221
1628
|
newAmount: remainingAmount
|
|
2222
1629
|
});
|
|
2223
1630
|
} else {
|
|
2224
|
-
|
|
1631
|
+
this.logInfo("balanceDueAmount 无需更新,当前值已是最新:", {
|
|
2225
1632
|
balanceDueAmount: currentBalanceDueAmount,
|
|
2226
1633
|
remainingAmount
|
|
2227
1634
|
});
|
|
2228
1635
|
}
|
|
2229
1636
|
} catch (error) {
|
|
2230
|
-
|
|
1637
|
+
this.logError("更新 balanceDueAmount 失败:", error);
|
|
2231
1638
|
}
|
|
2232
1639
|
}
|
|
2233
1640
|
/**
|
|
2234
1641
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
2235
1642
|
*/
|
|
2236
1643
|
async updateStateAmountToRemaining() {
|
|
2237
|
-
var _a;
|
|
2238
1644
|
try {
|
|
2239
1645
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2240
1646
|
const currentStateAmount = this.store.stateAmount;
|
|
2241
|
-
console.log("[Checkout] updateStateAmountToRemaining: 状态检查:", {
|
|
2242
|
-
calculatedRemainingAmount: remainingAmount,
|
|
2243
|
-
currentStateAmount,
|
|
2244
|
-
needsUpdate: remainingAmount !== currentStateAmount,
|
|
2245
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
2246
|
-
});
|
|
2247
1647
|
if (remainingAmount !== currentStateAmount) {
|
|
2248
1648
|
this.store.stateAmount = remainingAmount;
|
|
2249
1649
|
this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
@@ -2251,12 +1651,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2251
1651
|
newAmount: remainingAmount,
|
|
2252
1652
|
timestamp: Date.now()
|
|
2253
1653
|
});
|
|
2254
|
-
|
|
1654
|
+
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
2255
1655
|
oldAmount: currentStateAmount,
|
|
2256
1656
|
newAmount: remainingAmount
|
|
2257
1657
|
});
|
|
2258
1658
|
} else {
|
|
2259
|
-
|
|
1659
|
+
this.logInfo("stateAmount 无需更新,当前值已是最新:", {
|
|
2260
1660
|
stateAmount: currentStateAmount,
|
|
2261
1661
|
remainingAmount
|
|
2262
1662
|
});
|
|
@@ -2264,7 +1664,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2264
1664
|
await this.updateBalanceDueAmount();
|
|
2265
1665
|
await this.checkOrderPaymentCompletion();
|
|
2266
1666
|
} catch (error) {
|
|
2267
|
-
|
|
1667
|
+
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
2268
1668
|
}
|
|
2269
1669
|
}
|
|
2270
1670
|
/**
|
|
@@ -2282,7 +1682,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2282
1682
|
if (remainingValue.lte(0)) {
|
|
2283
1683
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
2284
1684
|
const paidAmount = await this.calculatePaidAmountAsync();
|
|
2285
|
-
|
|
1685
|
+
this.logInfo("检测到订单支付完成:", {
|
|
2286
1686
|
orderUuid: this.store.currentOrder.uuid,
|
|
2287
1687
|
orderId: this.store.currentOrder.order_id,
|
|
2288
1688
|
totalAmount,
|
|
@@ -2300,7 +1700,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2300
1700
|
(item) => item.status !== "voided" && item.voucher_id
|
|
2301
1701
|
);
|
|
2302
1702
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
2303
|
-
|
|
1703
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
2304
1704
|
paymentCount: currentPayments.length,
|
|
2305
1705
|
hasPaymentItems,
|
|
2306
1706
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
@@ -2318,13 +1718,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2318
1718
|
}))
|
|
2319
1719
|
});
|
|
2320
1720
|
if (shouldAutoSync) {
|
|
2321
|
-
|
|
2322
|
-
await this.
|
|
1721
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
1722
|
+
await this.syncOrderToBackendWithReturn(false);
|
|
2323
1723
|
} else {
|
|
2324
1724
|
if (!hasPaymentItems) {
|
|
2325
|
-
|
|
1725
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
2326
1726
|
} else if (allPaymentsHaveVoucherId) {
|
|
2327
|
-
|
|
1727
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
2328
1728
|
}
|
|
2329
1729
|
}
|
|
2330
1730
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
|
|
@@ -2337,14 +1737,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2337
1737
|
});
|
|
2338
1738
|
}
|
|
2339
1739
|
} catch (error) {
|
|
2340
|
-
|
|
1740
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2341
1741
|
}
|
|
2342
1742
|
}
|
|
2343
|
-
/**
|
|
2344
|
-
* 同步订单到后端
|
|
2345
|
-
*
|
|
2346
|
-
* 调用后端 /order/checkout 接口创建真实订单
|
|
2347
|
-
*/
|
|
2348
1743
|
/**
|
|
2349
1744
|
* 同步订单到后端并返回真实订单ID
|
|
2350
1745
|
*
|
|
@@ -2353,72 +1748,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2353
1748
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
2354
1749
|
*/
|
|
2355
1750
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2356
|
-
var _a, _b, _c, _d, _e, _f
|
|
1751
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2357
1752
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2358
1753
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2359
1754
|
}
|
|
2360
|
-
this.logInfo("syncOrderToBackendWithReturn called", {
|
|
2361
|
-
isManual,
|
|
2362
|
-
hasCustomPaymentItems: !!customPaymentItems,
|
|
2363
|
-
customPaymentItemsCount: (customPaymentItems == null ? void 0 : customPaymentItems.length) || 0,
|
|
2364
|
-
currentOrderId: this.store.currentOrder.order_id,
|
|
2365
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2366
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2367
|
-
isVirtualOrderId: (0, import_utils.isVirtualOrderId)(this.store.currentOrder.order_id),
|
|
2368
|
-
localOrderDataType: this.store.localOrderData.type,
|
|
2369
|
-
platform: this.store.localOrderData.platform,
|
|
2370
|
-
customerId: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id
|
|
2371
|
-
});
|
|
2372
|
-
const syncType = isManual ? "手动" : "自动";
|
|
1755
|
+
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2373
1756
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
2374
|
-
const
|
|
2375
|
-
|
|
2376
|
-
let reason = "";
|
|
2377
|
-
if (this.store.isOrderSynced) {
|
|
2378
|
-
isUpdateOperation = true;
|
|
2379
|
-
reason = "订单已同步过";
|
|
2380
|
-
} else if (hasRealOrderId) {
|
|
2381
|
-
isUpdateOperation = true;
|
|
2382
|
-
reason = "有真实订单ID";
|
|
2383
|
-
} else {
|
|
2384
|
-
isUpdateOperation = false;
|
|
2385
|
-
reason = "既未同步也无真实ID";
|
|
2386
|
-
}
|
|
2387
|
-
const operation = isUpdateOperation ? "更新" : "创建";
|
|
2388
|
-
console.log("[Checkout] 操作类型判断详情:", {
|
|
2389
|
-
currentOrderId,
|
|
2390
|
-
hasRealOrderId,
|
|
2391
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2392
|
-
isManual,
|
|
2393
|
-
reason,
|
|
2394
|
-
finalDecision: operation
|
|
2395
|
-
});
|
|
2396
|
-
console.log(`[Checkout] 开始${syncType}${operation}订单到后端...`, {
|
|
1757
|
+
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1758
|
+
this.logInfo(`开始同步订单到后端...`, {
|
|
2397
1759
|
currentOrderId,
|
|
2398
1760
|
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2399
|
-
operation,
|
|
2400
1761
|
orderUuid: this.store.currentOrder.uuid,
|
|
2401
|
-
isOrderSynced: this.store.isOrderSynced
|
|
1762
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1763
|
+
isManual
|
|
2402
1764
|
});
|
|
2403
1765
|
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2404
|
-
console.log("[Checkout] 获取到支付项:", {
|
|
2405
|
-
count: paymentItems.length,
|
|
2406
|
-
isCustomFiltered: !!customPaymentItems,
|
|
2407
|
-
methods: paymentItems.map((p) => p.code),
|
|
2408
|
-
totalAmount: paymentItems.reduce((sum, p) => sum + parseFloat(p.amount), 0).toFixed(2),
|
|
2409
|
-
paymentDetails: paymentItems.map((p) => {
|
|
2410
|
-
var _a2;
|
|
2411
|
-
return {
|
|
2412
|
-
uuid: p.uuid,
|
|
2413
|
-
code: p.code,
|
|
2414
|
-
amount: p.amount,
|
|
2415
|
-
uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
|
|
2416
|
-
voucherId: p.voucher_id,
|
|
2417
|
-
orderPaymentType: p.order_payment_type,
|
|
2418
|
-
metadata: p.metadata
|
|
2419
|
-
};
|
|
2420
|
-
})
|
|
2421
|
-
});
|
|
2422
1766
|
const processedPaymentItems = paymentItems.map((item) => {
|
|
2423
1767
|
var _a2, _b2;
|
|
2424
1768
|
return {
|
|
@@ -2430,23 +1774,55 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2430
1774
|
}
|
|
2431
1775
|
};
|
|
2432
1776
|
});
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
1777
|
+
let finalDepositAmount;
|
|
1778
|
+
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
1779
|
+
const depositPaymentItems = processedPaymentItems.filter(
|
|
1780
|
+
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1781
|
+
);
|
|
1782
|
+
const calculatedDepositAmount = depositPaymentItems.reduce((sum, item) => {
|
|
1783
|
+
const amount = new import_decimal.default(item.amount || "0");
|
|
1784
|
+
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
1785
|
+
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
1786
|
+
return sum.add(effectiveAmount);
|
|
1787
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
1788
|
+
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
1789
|
+
const calculatedDepositValue = new import_decimal.default(calculatedDepositAmount);
|
|
1790
|
+
if (manualDepositValue.gt(0)) {
|
|
1791
|
+
finalDepositAmount = manualDepositAmount;
|
|
1792
|
+
this.logInfo("使用手动设置的定金金额", {
|
|
1793
|
+
manualDepositAmount,
|
|
1794
|
+
calculatedDepositAmount,
|
|
1795
|
+
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
1796
|
+
});
|
|
1797
|
+
} else if (calculatedDepositValue.gt(0)) {
|
|
1798
|
+
finalDepositAmount = calculatedDepositAmount;
|
|
1799
|
+
this.logInfo("使用从支付项计算的定金金额", {
|
|
1800
|
+
manualDepositAmount,
|
|
1801
|
+
calculatedDepositAmount,
|
|
1802
|
+
reason: "未手动设置定金金额,从定金类型支付项计算得出"
|
|
1803
|
+
});
|
|
1804
|
+
} else {
|
|
1805
|
+
finalDepositAmount = "0.00";
|
|
1806
|
+
this.logInfo("定金金额为0", {
|
|
1807
|
+
manualDepositAmount,
|
|
1808
|
+
calculatedDepositAmount,
|
|
1809
|
+
reason: "手动设置和计算值均为0"
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
this.logInfo("定金金额确定结果", {
|
|
1813
|
+
depositPaymentItemsCount: depositPaymentItems.length,
|
|
1814
|
+
depositPaymentItems: depositPaymentItems.map((item) => ({
|
|
1815
|
+
uuid: item.uuid,
|
|
1816
|
+
code: item.code,
|
|
1817
|
+
amount: item.amount,
|
|
1818
|
+
rounding_amount: item.rounding_amount,
|
|
1819
|
+
order_payment_type: item.order_payment_type,
|
|
1820
|
+
status: item.status
|
|
1821
|
+
})),
|
|
1822
|
+
manualDepositAmount,
|
|
1823
|
+
calculatedDepositAmount,
|
|
1824
|
+
finalDepositAmount,
|
|
1825
|
+
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
2450
1826
|
});
|
|
2451
1827
|
const orderParams = {
|
|
2452
1828
|
...this.store.localOrderData,
|
|
@@ -2468,34 +1844,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2468
1844
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2469
1845
|
currency_format: this.otherParams.currency_format,
|
|
2470
1846
|
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0,
|
|
2471
|
-
deposit_amount:
|
|
2472
|
-
//
|
|
2473
|
-
// surcharges: ,
|
|
1847
|
+
deposit_amount: finalDepositAmount,
|
|
1848
|
+
// 使用最终确定的定金金额(手动设置优先)
|
|
2474
1849
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
2475
1850
|
note: this.store.localOrderData.shop_note
|
|
2476
|
-
// deposit_amount:
|
|
2477
1851
|
};
|
|
2478
1852
|
if (isUpdateOperation) {
|
|
2479
1853
|
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2480
|
-
|
|
2481
|
-
"
|
|
2482
|
-
{
|
|
2483
|
-
currentOrderId,
|
|
2484
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2485
|
-
reason,
|
|
2486
|
-
orderUuid: this.store.currentOrder.uuid
|
|
2487
|
-
}
|
|
2488
|
-
);
|
|
2489
|
-
console.log("[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理");
|
|
2490
|
-
console.log(
|
|
2491
|
-
"[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
1854
|
+
this.logWarning(
|
|
1855
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2492
1856
|
);
|
|
2493
1857
|
} else {
|
|
2494
1858
|
orderParams.order_id = currentOrderId;
|
|
2495
|
-
console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
|
|
2496
1859
|
}
|
|
2497
|
-
} else {
|
|
2498
|
-
console.log("[Checkout] 创建新订单操作");
|
|
2499
1860
|
}
|
|
2500
1861
|
const startTime = Date.now();
|
|
2501
1862
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitStart, {
|
|
@@ -2511,29 +1872,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2511
1872
|
try {
|
|
2512
1873
|
this.logInfo("Calling backend checkout API", {
|
|
2513
1874
|
url: "/order/checkout",
|
|
2514
|
-
operation,
|
|
2515
1875
|
isManual,
|
|
2516
|
-
|
|
2517
|
-
platform: orderParams.platform,
|
|
2518
|
-
customerId: orderParams.customer_id,
|
|
2519
|
-
isDeposit: orderParams.is_deposit,
|
|
2520
|
-
depositAmount: orderParams.deposit_amount,
|
|
2521
|
-
bookingsCount: ((_f = orderParams.bookings) == null ? void 0 : _f.length) || 0,
|
|
2522
|
-
relationProductsCount: ((_g = orderParams.relation_products) == null ? void 0 : _g.length) || 0,
|
|
2523
|
-
paymentsCount: ((_h = orderParams.payments) == null ? void 0 : _h.length) || 0,
|
|
2524
|
-
paymentMethods: ((_i = orderParams.payments) == null ? void 0 : _i.map((p) => p.code)) || [],
|
|
2525
|
-
hasOrderId: !!orderParams.order_id,
|
|
2526
|
-
orderIdIncluded: orderParams.order_id,
|
|
2527
|
-
productTaxFee: orderParams.product_tax_fee,
|
|
2528
|
-
note: orderParams.note,
|
|
2529
|
-
scheduleDate: orderParams.schedule_date
|
|
1876
|
+
...orderParams
|
|
2530
1877
|
});
|
|
2531
1878
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2532
1879
|
submitSuccess = true;
|
|
2533
|
-
|
|
1880
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2534
1881
|
} catch (error) {
|
|
2535
1882
|
submitSuccess = false;
|
|
2536
1883
|
submitError = error instanceof Error ? error.message : String(error);
|
|
1884
|
+
this.logError("下单接口调用失败:", submitError);
|
|
2537
1885
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2538
1886
|
orderUuid: this.store.currentOrder.uuid,
|
|
2539
1887
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2550,29 +1898,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2550
1898
|
orderUuid: this.store.currentOrder.uuid,
|
|
2551
1899
|
operation: isUpdateOperation ? "update" : "create",
|
|
2552
1900
|
isManual,
|
|
2553
|
-
orderId: submitSuccess ? ((
|
|
1901
|
+
orderId: submitSuccess ? ((_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2554
1902
|
error: submitError,
|
|
2555
1903
|
duration: Date.now() - startTime,
|
|
2556
1904
|
timestamp: Date.now()
|
|
2557
1905
|
});
|
|
2558
1906
|
}
|
|
2559
|
-
console.log("[Checkout] 后端返回的响应数据:", {
|
|
2560
|
-
status: checkoutResponse == null ? void 0 : checkoutResponse.status,
|
|
2561
|
-
code: checkoutResponse == null ? void 0 : checkoutResponse.code,
|
|
2562
|
-
message: checkoutResponse == null ? void 0 : checkoutResponse.message,
|
|
2563
|
-
data: checkoutResponse == null ? void 0 : checkoutResponse.data
|
|
2564
|
-
});
|
|
2565
1907
|
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2566
1908
|
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2567
1909
|
if (!isSuccessResponse) {
|
|
2568
1910
|
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
2569
|
-
console.error("[Checkout] 订单同步失败,响应状态检查未通过:", {
|
|
2570
|
-
expectedSuccess: true,
|
|
2571
|
-
actualStatus: responseStatus,
|
|
2572
|
-
code: checkoutResponse == null ? void 0 : checkoutResponse.code,
|
|
2573
|
-
message: checkoutResponse == null ? void 0 : checkoutResponse.message,
|
|
2574
|
-
errorMessage
|
|
2575
|
-
});
|
|
2576
1911
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2577
1912
|
orderUuid: this.store.currentOrder.uuid,
|
|
2578
1913
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2585,13 +1920,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2585
1920
|
});
|
|
2586
1921
|
throw new Error(errorMessage);
|
|
2587
1922
|
}
|
|
2588
|
-
console.log("[Checkout] 响应状态检查通过,开始处理订单数据");
|
|
2589
1923
|
let realOrderId;
|
|
2590
1924
|
if (isUpdateOperation) {
|
|
2591
1925
|
realOrderId = currentOrderId;
|
|
2592
|
-
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
2593
1926
|
} else {
|
|
2594
|
-
let extractedOrderId = (
|
|
1927
|
+
let extractedOrderId = (_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id;
|
|
2595
1928
|
if (!extractedOrderId) {
|
|
2596
1929
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2597
1930
|
}
|
|
@@ -2599,11 +1932,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2599
1932
|
extractedOrderId = String(extractedOrderId);
|
|
2600
1933
|
}
|
|
2601
1934
|
if (!extractedOrderId) {
|
|
2602
|
-
|
|
1935
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
2603
1936
|
}
|
|
2604
1937
|
realOrderId = extractedOrderId;
|
|
2605
|
-
|
|
2606
|
-
console.log("[Checkout] 准备替换订单ID:", {
|
|
1938
|
+
this.logInfo("准备替换订单ID:", {
|
|
2607
1939
|
orderUuid: this.store.currentOrder.uuid,
|
|
2608
1940
|
oldOrderId: this.store.currentOrder.order_id,
|
|
2609
1941
|
newOrderId: realOrderId
|
|
@@ -2613,38 +1945,38 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2613
1945
|
this.store.currentOrder.uuid,
|
|
2614
1946
|
realOrderId
|
|
2615
1947
|
);
|
|
2616
|
-
|
|
1948
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
2617
1949
|
wasSuccessful: !!updatedOrder,
|
|
2618
1950
|
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2619
1951
|
expectedOrderId: realOrderId
|
|
2620
1952
|
});
|
|
2621
1953
|
if (updatedOrder) {
|
|
2622
|
-
|
|
1954
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
2623
1955
|
uuid: updatedOrder.uuid,
|
|
2624
1956
|
orderId: updatedOrder.order_id,
|
|
2625
1957
|
totalAmount: updatedOrder.total_amount
|
|
2626
1958
|
});
|
|
2627
1959
|
this.store.currentOrder = updatedOrder;
|
|
2628
|
-
|
|
1960
|
+
this.logInfo(
|
|
2629
1961
|
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2630
1962
|
this.store.currentOrder.order_id
|
|
2631
1963
|
);
|
|
2632
1964
|
} else {
|
|
2633
|
-
|
|
1965
|
+
this.logError(
|
|
2634
1966
|
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2635
1967
|
);
|
|
2636
1968
|
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2637
1969
|
this.store.currentOrder.order_id = realOrderId;
|
|
2638
|
-
|
|
1970
|
+
this.logInfo("手动设置订单ID:", {
|
|
2639
1971
|
beforeReplacement: beforeManualUpdate,
|
|
2640
1972
|
afterReplacement: this.store.currentOrder.order_id,
|
|
2641
1973
|
目标ID: realOrderId
|
|
2642
1974
|
});
|
|
2643
1975
|
}
|
|
2644
1976
|
} catch (error) {
|
|
2645
|
-
|
|
1977
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2646
1978
|
this.store.currentOrder.order_id = realOrderId;
|
|
2647
|
-
|
|
1979
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2648
1980
|
}
|
|
2649
1981
|
}
|
|
2650
1982
|
this.store.isOrderSynced = true;
|
|
@@ -2656,69 +1988,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2656
1988
|
isManual,
|
|
2657
1989
|
response: checkoutResponse
|
|
2658
1990
|
});
|
|
2659
|
-
const finalOrderId = this.store.currentOrder.order_id;
|
|
2660
|
-
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId || "");
|
|
2661
|
-
console.log(`[Checkout] ${syncType}${operation}订单到后端完成`, {
|
|
2662
|
-
returnedOrderId: realOrderId,
|
|
2663
|
-
currentStoredOrderId: finalOrderId,
|
|
2664
|
-
isStillVirtualId: finalIsVirtual,
|
|
2665
|
-
isSynced: this.store.isOrderSynced
|
|
2666
|
-
});
|
|
2667
|
-
if (finalIsVirtual && !isUpdateOperation) {
|
|
2668
|
-
console.warn(
|
|
2669
|
-
"[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题"
|
|
2670
|
-
);
|
|
2671
|
-
}
|
|
2672
1991
|
return {
|
|
2673
1992
|
success: true,
|
|
2674
|
-
message: `订单${operation}成功`,
|
|
2675
1993
|
orderId: realOrderId,
|
|
2676
1994
|
orderUuid: this.store.currentOrder.uuid,
|
|
2677
1995
|
response: checkoutResponse
|
|
2678
1996
|
};
|
|
2679
1997
|
}
|
|
2680
|
-
async syncOrderToBackend() {
|
|
2681
|
-
try {
|
|
2682
|
-
const syncResult = await this.syncOrderToBackendWithReturn(false);
|
|
2683
|
-
console.log("[Checkout] 自动同步订单完成:", syncResult);
|
|
2684
|
-
} catch (error) {
|
|
2685
|
-
console.error("[Checkout] 同步订单到后端失败:", error);
|
|
2686
|
-
await this.handleError(
|
|
2687
|
-
new Error(
|
|
2688
|
-
`订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
2689
|
-
),
|
|
2690
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
2691
|
-
);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
/**
|
|
2695
|
-
* 获取状态消息
|
|
2696
|
-
*/
|
|
2697
|
-
getStatusMessage() {
|
|
2698
|
-
var _a;
|
|
2699
|
-
switch (this.store.status) {
|
|
2700
|
-
case import_types.CheckoutStatus.Initializing:
|
|
2701
|
-
return "正在初始化结账流程...";
|
|
2702
|
-
case import_types.CheckoutStatus.Ready:
|
|
2703
|
-
return "准备就绪,可以开始结账";
|
|
2704
|
-
case import_types.CheckoutStatus.CreatingOrder:
|
|
2705
|
-
return "正在创建订单...";
|
|
2706
|
-
case import_types.CheckoutStatus.OrderCreated:
|
|
2707
|
-
return "订单创建成功,请选择支付方式";
|
|
2708
|
-
case import_types.CheckoutStatus.ProcessingPayment:
|
|
2709
|
-
return "正在处理支付...";
|
|
2710
|
-
case import_types.CheckoutStatus.PaymentCompleted:
|
|
2711
|
-
return "支付完成";
|
|
2712
|
-
case import_types.CheckoutStatus.Completed:
|
|
2713
|
-
return "结账完成";
|
|
2714
|
-
case import_types.CheckoutStatus.Cancelled:
|
|
2715
|
-
return "结账已取消";
|
|
2716
|
-
case import_types.CheckoutStatus.Error:
|
|
2717
|
-
return ((_a = this.store.lastError) == null ? void 0 : _a.message) || "发生未知错误";
|
|
2718
|
-
default:
|
|
2719
|
-
return "";
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
1998
|
async setOtherParams(params, { cover = false } = {}) {
|
|
2723
1999
|
if (cover) {
|
|
2724
2000
|
this.otherParams = params;
|
|
@@ -2739,15 +2015,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2739
2015
|
this.logInfo("editOrderNoteByOrderIdAsync called", {
|
|
2740
2016
|
orderId,
|
|
2741
2017
|
note,
|
|
2742
|
-
noteLength: note.length
|
|
2743
|
-
isCurrentOrder: this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))
|
|
2018
|
+
noteLength: note.length
|
|
2744
2019
|
});
|
|
2745
2020
|
try {
|
|
2746
|
-
console.log("[Checkout] 开始编辑订单备注:", {
|
|
2747
|
-
orderId,
|
|
2748
|
-
note,
|
|
2749
|
-
noteLength: note.length
|
|
2750
|
-
});
|
|
2751
2021
|
if (!orderId) {
|
|
2752
2022
|
return {
|
|
2753
2023
|
success: false,
|
|
@@ -2762,22 +2032,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2762
2032
|
note,
|
|
2763
2033
|
noteLength: note.length
|
|
2764
2034
|
});
|
|
2765
|
-
const response = await this.request.put(
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
}
|
|
2770
|
-
);
|
|
2771
|
-
console.log("[Checkout] 订单备注编辑响应:", {
|
|
2035
|
+
const response = await this.request.put(`/order/order/${orderId}/note`, {
|
|
2036
|
+
note
|
|
2037
|
+
});
|
|
2038
|
+
this.logInfo("订单备注编辑响应:", {
|
|
2772
2039
|
orderId,
|
|
2773
2040
|
status: response.status,
|
|
2774
2041
|
message: response.message,
|
|
2775
2042
|
response
|
|
2776
2043
|
});
|
|
2777
2044
|
if (response.status === true || response.status === 200) {
|
|
2778
|
-
console.log(`[Checkout] 订单 ${orderId} 备注修改成功`);
|
|
2779
2045
|
if (this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))) {
|
|
2780
|
-
console.log("[Checkout] 更新本地订单备注状态");
|
|
2781
2046
|
const previousNote = this.getOrderNote();
|
|
2782
2047
|
if (this.store.localOrderData) {
|
|
2783
2048
|
this.store.localOrderData.shop_note = note;
|
|
@@ -2796,7 +2061,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2796
2061
|
};
|
|
2797
2062
|
} else {
|
|
2798
2063
|
const errorMessage = response.message || "订单备注修改失败";
|
|
2799
|
-
|
|
2064
|
+
this.logError(`订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
2800
2065
|
return {
|
|
2801
2066
|
success: false,
|
|
2802
2067
|
message: errorMessage,
|
|
@@ -2804,7 +2069,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2804
2069
|
};
|
|
2805
2070
|
}
|
|
2806
2071
|
} catch (error) {
|
|
2807
|
-
|
|
2072
|
+
this.logError("编辑订单备注失败:", error);
|
|
2808
2073
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2809
2074
|
return {
|
|
2810
2075
|
success: false,
|
|
@@ -2831,11 +2096,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2831
2096
|
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2832
2097
|
});
|
|
2833
2098
|
try {
|
|
2834
|
-
console.log("[Checkout] 开始发送客户支付链接邮件:", {
|
|
2835
|
-
orderIds: params.order_ids,
|
|
2836
|
-
emails: params.emails,
|
|
2837
|
-
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2838
|
-
});
|
|
2839
2099
|
if (!params.order_ids || params.order_ids.length === 0) {
|
|
2840
2100
|
return {
|
|
2841
2101
|
success: false,
|
|
@@ -2863,27 +2123,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2863
2123
|
notify_action: params.notify_action || "order_payment_reminder",
|
|
2864
2124
|
emails: params.emails
|
|
2865
2125
|
};
|
|
2866
|
-
console.log("[Checkout] 发送支付链接邮件请求参数:", requestBody);
|
|
2867
2126
|
this.logInfo("Calling batch email API", {
|
|
2868
2127
|
url: "/order/batch-email",
|
|
2869
|
-
|
|
2870
|
-
orderIdsCount: requestBody.order_ids.length,
|
|
2871
|
-
notifyAction: requestBody.notify_action,
|
|
2872
|
-
emails: requestBody.emails,
|
|
2873
|
-
emailsCount: requestBody.emails.length
|
|
2128
|
+
...requestBody
|
|
2874
2129
|
});
|
|
2875
2130
|
const response = await this.request.post(
|
|
2876
2131
|
"/order/batch-email",
|
|
2877
2132
|
requestBody
|
|
2878
2133
|
);
|
|
2879
|
-
|
|
2134
|
+
this.logInfo("支付链接邮件发送响应:", {
|
|
2880
2135
|
status: response.status,
|
|
2881
2136
|
message: response.message,
|
|
2882
2137
|
data: response.data,
|
|
2883
2138
|
response
|
|
2884
2139
|
});
|
|
2885
2140
|
if (response.status === true || response.status === 200) {
|
|
2886
|
-
console.log("[Checkout] 支付链接邮件发送成功");
|
|
2887
2141
|
return {
|
|
2888
2142
|
success: true,
|
|
2889
2143
|
message: response.message || "支付链接邮件发送成功"
|
|
@@ -2897,7 +2151,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2897
2151
|
};
|
|
2898
2152
|
}
|
|
2899
2153
|
} catch (error) {
|
|
2900
|
-
|
|
2154
|
+
this.logError("发送客户支付链接邮件失败:", error);
|
|
2901
2155
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2902
2156
|
return {
|
|
2903
2157
|
success: false,
|
|
@@ -2918,9 +2172,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2918
2172
|
(_a = this.otherParams.order_rounding_setting) == null ? void 0 : _a.interval,
|
|
2919
2173
|
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.type
|
|
2920
2174
|
);
|
|
2921
|
-
console.log(
|
|
2922
|
-
`[Checkout] 金额舍入完成 - 原始: ${result.originalAmount}, 舍入后: ${result.roundedAmount}, 差额: ${result.roundingDifference}`
|
|
2923
|
-
);
|
|
2924
2175
|
return result;
|
|
2925
2176
|
}
|
|
2926
2177
|
async destroy() {
|
|
@@ -2954,8 +2205,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2954
2205
|
this.store.lastError = void 0;
|
|
2955
2206
|
this.store.cartItems = [];
|
|
2956
2207
|
this.payment.wallet.clearAllCache();
|
|
2957
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
2958
|
-
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
2959
2208
|
console.log("[Checkout] Store 状态重置完成");
|
|
2960
2209
|
if (prevOrderInfo) {
|
|
2961
2210
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
|
|
@@ -2967,33 +2216,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2967
2216
|
console.error("[Checkout] 重置 store 状态失败:", error);
|
|
2968
2217
|
}
|
|
2969
2218
|
}
|
|
2970
|
-
/**
|
|
2971
|
-
* 手动清理已完成的订单状态(公开方法)
|
|
2972
|
-
*
|
|
2973
|
-
* 供UI层调用的公开方法,用于手动清理订单状态
|
|
2974
|
-
*
|
|
2975
|
-
* @returns 清理结果
|
|
2976
|
-
*/
|
|
2977
|
-
async clearCompletedOrderAsync() {
|
|
2978
|
-
try {
|
|
2979
|
-
const prevOrderInfo = this.store.currentOrder ? {
|
|
2980
|
-
uuid: this.store.currentOrder.uuid,
|
|
2981
|
-
orderId: this.store.currentOrder.order_id
|
|
2982
|
-
} : null;
|
|
2983
|
-
await this.resetStoreStateAsync();
|
|
2984
|
-
return {
|
|
2985
|
-
success: true,
|
|
2986
|
-
message: prevOrderInfo ? "订单状态已成功清理" : "没有需要清理的订单状态",
|
|
2987
|
-
clearedOrder: prevOrderInfo
|
|
2988
|
-
};
|
|
2989
|
-
} catch (error) {
|
|
2990
|
-
console.error("[Checkout] 手动清理订单状态失败:", error);
|
|
2991
|
-
return {
|
|
2992
|
-
success: false,
|
|
2993
|
-
message: error instanceof Error ? error.message : "清理失败"
|
|
2994
|
-
};
|
|
2995
|
-
}
|
|
2996
|
-
}
|
|
2997
2219
|
};
|
|
2998
2220
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2999
2221
|
0 && (module.exports = {
|