@pisell/pisellos 2.1.7 → 2.1.9
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/Order/index.js +10 -4
- package/dist/modules/Payment/index.js +20 -24
- package/dist/modules/Payment/walletpass.js +2 -3
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +1 -153
- package/dist/solution/Checkout/index.js +1003 -2473
- package/dist/solution/Checkout/types.d.ts +0 -221
- package/dist/solution/Checkout/types.js +0 -49
- package/dist/solution/Checkout/utils/index.d.ts +9 -5
- package/dist/solution/Checkout/utils/index.js +18 -56
- package/lib/modules/Order/index.js +6 -0
- package/lib/modules/Payment/index.js +2 -6
- package/lib/modules/Payment/walletpass.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +1 -153
- package/lib/solution/Checkout/index.js +172 -1116
- package/lib/solution/Checkout/types.d.ts +0 -221
- package/lib/solution/Checkout/types.js +2 -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()
|
|
@@ -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);
|
|
@@ -216,12 +210,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
216
210
|
selling_price: item.product.price - (item.product.discount_amount || 0) - getDiscountListAmount(item.product.discount_list)
|
|
217
211
|
})
|
|
218
212
|
)) || [];
|
|
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(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
219
|
+
})
|
|
220
|
+
)) || [];
|
|
225
221
|
return [...productList, ...relationProducts];
|
|
226
222
|
}
|
|
227
223
|
async initWalletData(params) {
|
|
@@ -242,6 +238,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
242
238
|
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
243
239
|
walletBusinessData
|
|
244
240
|
);
|
|
241
|
+
if (!this.store.currentOrder) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
245
244
|
await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
|
|
246
245
|
orderUuid: (_d = this.store.currentOrder) == null ? void 0 : _d.uuid,
|
|
247
246
|
customerId: walletBusinessData.customer_id,
|
|
@@ -273,9 +272,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
273
272
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
274
273
|
});
|
|
275
274
|
try {
|
|
276
|
-
console.time("createLocalOrderAsync");
|
|
277
275
|
await this.resetStoreStateAsync();
|
|
278
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
279
276
|
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
280
277
|
if (!validation.valid) {
|
|
281
278
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -320,20 +317,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
320
317
|
amount_breakdown: amountInfo
|
|
321
318
|
}
|
|
322
319
|
});
|
|
323
|
-
console.timeEnd("createLocalOrderAsync");
|
|
324
320
|
this.store.currentOrder = paymentOrder;
|
|
325
321
|
this.initWalletData();
|
|
326
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
327
|
-
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
328
322
|
if (params.autoPayment) {
|
|
329
|
-
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
330
323
|
}
|
|
331
324
|
this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
332
325
|
order: paymentOrder,
|
|
333
326
|
timestamp: Date.now()
|
|
334
327
|
});
|
|
335
328
|
await this.updateStateAmountToRemaining();
|
|
336
|
-
|
|
329
|
+
this.logInfo("本地订单创建成功:", {
|
|
337
330
|
localOrderId,
|
|
338
331
|
uuid: paymentOrder.uuid,
|
|
339
332
|
totalAmount: amountInfo.totalAmount,
|
|
@@ -354,206 +347,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
354
347
|
throw error;
|
|
355
348
|
}
|
|
356
349
|
}
|
|
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
350
|
/**
|
|
558
351
|
* 完成结账
|
|
559
352
|
*/
|
|
@@ -575,8 +368,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
575
368
|
);
|
|
576
369
|
}
|
|
577
370
|
this.payment.wallet.clearAllCache();
|
|
578
|
-
this.setStatus(import_types.CheckoutStatus.Completed);
|
|
579
|
-
this.setStep(import_types.CheckoutStep.Complete);
|
|
580
371
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
581
372
|
orderId: order.id,
|
|
582
373
|
timestamp: Date.now()
|
|
@@ -592,89 +383,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
592
383
|
return { success: false };
|
|
593
384
|
}
|
|
594
385
|
}
|
|
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
386
|
/**
|
|
679
387
|
* 获取订单原始数据
|
|
680
388
|
*/
|
|
@@ -689,7 +397,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
689
397
|
*/
|
|
690
398
|
getCurrentOrderInfo() {
|
|
691
399
|
try {
|
|
692
|
-
const { currentOrder,
|
|
400
|
+
const { currentOrder, cartItems, localOrderData } = this.store;
|
|
693
401
|
if (!currentOrder) {
|
|
694
402
|
console.log("[Checkout] 当前没有活跃订单");
|
|
695
403
|
return null;
|
|
@@ -701,8 +409,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
701
409
|
const result = {
|
|
702
410
|
uuid: currentOrder.uuid,
|
|
703
411
|
orderId: currentOrder.order_id,
|
|
704
|
-
status,
|
|
705
|
-
step,
|
|
706
412
|
totalAmount: currentOrder.total_amount,
|
|
707
413
|
remainingAmount: currentOrder.expect_amount,
|
|
708
414
|
paymentStatus: currentOrder.payment_status,
|
|
@@ -714,13 +420,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
714
420
|
itemCount: cartItems.length,
|
|
715
421
|
hasLocalOrderData: Boolean(localOrderData)
|
|
716
422
|
};
|
|
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
423
|
return result;
|
|
725
424
|
} catch (error) {
|
|
726
425
|
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
@@ -739,89 +438,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
739
438
|
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
740
439
|
return [];
|
|
741
440
|
}
|
|
742
|
-
console.log("[Checkout] 获取当前订单支付项:", {
|
|
743
|
-
orderUuid: currentOrder.uuid,
|
|
744
|
-
orderId: currentOrder.order_id
|
|
745
|
-
});
|
|
746
441
|
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
747
442
|
currentOrder.uuid
|
|
748
443
|
);
|
|
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
444
|
return paymentItems;
|
|
764
445
|
} catch (error) {
|
|
765
446
|
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
766
447
|
return [];
|
|
767
448
|
}
|
|
768
449
|
}
|
|
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
450
|
/**
|
|
826
451
|
* 获取订单模块
|
|
827
452
|
*/
|
|
@@ -900,10 +525,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
900
525
|
newAmount: formattedAmount,
|
|
901
526
|
timestamp: Date.now()
|
|
902
527
|
});
|
|
903
|
-
console.log("[Checkout] 自定义支付金额已更新:", {
|
|
904
|
-
oldAmount,
|
|
905
|
-
newAmount: formattedAmount
|
|
906
|
-
});
|
|
907
528
|
} catch (error) {
|
|
908
529
|
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
909
530
|
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
@@ -932,14 +553,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
932
553
|
getBalanceDueAmount() {
|
|
933
554
|
return this.store.balanceDueAmount;
|
|
934
555
|
}
|
|
935
|
-
/**
|
|
936
|
-
* 刷新 stateAmount 为当前剩余未支付金额
|
|
937
|
-
*
|
|
938
|
-
* UI 可以调用此方法来主动刷新支付金额状态
|
|
939
|
-
*/
|
|
940
|
-
async refreshStateAmountAsync() {
|
|
941
|
-
await this.updateStateAmountToRemaining();
|
|
942
|
-
}
|
|
943
556
|
/**
|
|
944
557
|
* 获取购物车小计数据
|
|
945
558
|
*
|
|
@@ -952,7 +565,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
952
565
|
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
953
566
|
return null;
|
|
954
567
|
}
|
|
955
|
-
|
|
568
|
+
this.logInfo("获取购物车小计数据:", {
|
|
956
569
|
itemCount: this.store.cartSummary.length,
|
|
957
570
|
items: this.store.cartSummary.map((item) => ({
|
|
958
571
|
key: item.key,
|
|
@@ -962,24 +575,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
962
575
|
});
|
|
963
576
|
return [...this.store.cartSummary];
|
|
964
577
|
}
|
|
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
578
|
/**
|
|
984
579
|
* 获取支付方式列表
|
|
985
580
|
*
|
|
@@ -990,21 +585,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
990
585
|
*/
|
|
991
586
|
async getPaymentMethodsAsync() {
|
|
992
587
|
if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
|
|
993
|
-
|
|
994
|
-
|
|
588
|
+
this.logInfo(
|
|
589
|
+
`使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
|
|
995
590
|
);
|
|
996
591
|
return this.store.paymentMethods;
|
|
997
592
|
}
|
|
998
|
-
|
|
593
|
+
this.logInfo("store 中无缓存,从 Payment 模块获取支付方式...");
|
|
999
594
|
try {
|
|
1000
595
|
const methods = await this.payment.getPayMethodListAsync();
|
|
1001
596
|
this.store.paymentMethods = methods;
|
|
1002
|
-
|
|
1003
|
-
|
|
597
|
+
this.logInfo(
|
|
598
|
+
`从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
|
|
1004
599
|
);
|
|
1005
600
|
return methods;
|
|
1006
601
|
} catch (error) {
|
|
1007
|
-
|
|
602
|
+
this.logError("获取支付方式失败:", error);
|
|
1008
603
|
return [];
|
|
1009
604
|
}
|
|
1010
605
|
}
|
|
@@ -1017,19 +612,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1017
612
|
* @throws 当前没有活跃订单时抛出错误
|
|
1018
613
|
*/
|
|
1019
614
|
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
|
-
});
|
|
615
|
+
var _a, _b;
|
|
616
|
+
this.logInfo("addPaymentItemAsync called", paymentItem);
|
|
1033
617
|
try {
|
|
1034
618
|
if (!this.store.currentOrder) {
|
|
1035
619
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -1049,53 +633,33 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1049
633
|
order_payment_type: orderPaymentType,
|
|
1050
634
|
metadata
|
|
1051
635
|
};
|
|
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
636
|
await this.payment.addPaymentItemAsync(
|
|
1075
637
|
this.store.currentOrder.uuid,
|
|
1076
638
|
paymentItemWithType
|
|
1077
639
|
);
|
|
1078
|
-
|
|
1079
|
-
const isEftposPayment = ((
|
|
1080
|
-
|
|
640
|
+
this.logInfo("支付项添加成功");
|
|
641
|
+
const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
|
|
642
|
+
this.logInfo("EFTPOS 支付检查:", {
|
|
1081
643
|
paymentCode: paymentItem.code,
|
|
1082
644
|
paymentType: paymentItem.type,
|
|
1083
645
|
isEftposPayment,
|
|
1084
646
|
currentOrderSynced: this.store.isOrderSynced
|
|
1085
647
|
});
|
|
1086
648
|
if (isEftposPayment) {
|
|
1087
|
-
|
|
649
|
+
this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
|
|
1088
650
|
try {
|
|
1089
651
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1090
|
-
|
|
652
|
+
this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
|
|
1091
653
|
orderId: syncResult.orderId,
|
|
1092
654
|
isOrderSynced: this.store.isOrderSynced,
|
|
1093
655
|
backendResponse: syncResult.response
|
|
1094
656
|
});
|
|
1095
657
|
} catch (error) {
|
|
1096
|
-
|
|
658
|
+
this.logError("EFTPOS 支付后订单同步失败:", error);
|
|
1097
659
|
await this.handleError(
|
|
1098
|
-
new Error(
|
|
660
|
+
new Error(
|
|
661
|
+
`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
662
|
+
),
|
|
1099
663
|
import_types.CheckoutErrorType.OrderCreationFailed
|
|
1100
664
|
);
|
|
1101
665
|
}
|
|
@@ -1108,7 +672,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1108
672
|
timestamp: Date.now()
|
|
1109
673
|
});
|
|
1110
674
|
} catch (error) {
|
|
1111
|
-
|
|
675
|
+
this.logError("添加支付项失败:", error);
|
|
1112
676
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1113
677
|
throw error;
|
|
1114
678
|
}
|
|
@@ -1130,7 +694,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1130
694
|
"当前没有活跃订单,无法删除支付项"
|
|
1131
695
|
);
|
|
1132
696
|
}
|
|
1133
|
-
|
|
697
|
+
this.logWarning("开始删除支付项:", {
|
|
1134
698
|
orderUuid: this.store.currentOrder.uuid,
|
|
1135
699
|
paymentUuid
|
|
1136
700
|
});
|
|
@@ -1146,7 +710,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1146
710
|
`支付项不存在: ${paymentUuid}`
|
|
1147
711
|
);
|
|
1148
712
|
}
|
|
1149
|
-
|
|
713
|
+
this.logInfo("找到要删除的支付项:", {
|
|
1150
714
|
uuid: paymentItem.uuid,
|
|
1151
715
|
code: paymentItem.code,
|
|
1152
716
|
amount: paymentItem.amount,
|
|
@@ -1156,7 +720,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1156
720
|
this.store.currentOrder.uuid,
|
|
1157
721
|
paymentUuid
|
|
1158
722
|
);
|
|
1159
|
-
|
|
723
|
+
this.logInfo("Payment支付项删除完成", paymentItem);
|
|
1160
724
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1161
725
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1162
726
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1164,7 +728,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1164
728
|
);
|
|
1165
729
|
if (updatedOrder) {
|
|
1166
730
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1167
|
-
|
|
731
|
+
this.logWarning(
|
|
1168
732
|
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1169
733
|
{
|
|
1170
734
|
currentRealId: currentOrderId,
|
|
@@ -1174,10 +738,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1174
738
|
updatedOrder.order_id = currentOrderId;
|
|
1175
739
|
}
|
|
1176
740
|
this.store.currentOrder = updatedOrder;
|
|
1177
|
-
console.log(
|
|
1178
|
-
"[Checkout] 订单数据已同步,当前支付项数量:",
|
|
1179
|
-
updatedOrder.payment.length
|
|
1180
|
-
);
|
|
1181
741
|
}
|
|
1182
742
|
await this.updateStateAmountToRemaining();
|
|
1183
743
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1187,9 +747,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1187
747
|
// 负数表示删除
|
|
1188
748
|
timestamp: Date.now()
|
|
1189
749
|
});
|
|
1190
|
-
console.log("[Checkout] 支付项删除成功");
|
|
1191
750
|
} catch (error) {
|
|
1192
|
-
|
|
751
|
+
this.logError("删除支付项失败:", error);
|
|
1193
752
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1194
753
|
throw error;
|
|
1195
754
|
}
|
|
@@ -1212,9 +771,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1212
771
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
1213
772
|
);
|
|
1214
773
|
}
|
|
1215
|
-
|
|
1216
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1217
|
-
newVoucherCount: voucherPaymentItems.length,
|
|
774
|
+
this.logInfo("开始批量更新代金券支付项:", {
|
|
1218
775
|
voucherPaymentItems
|
|
1219
776
|
});
|
|
1220
777
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
@@ -1236,16 +793,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1236
793
|
metadata
|
|
1237
794
|
};
|
|
1238
795
|
});
|
|
1239
|
-
console.log("[Checkout] 代金券支付项订单支付类型设置:", {
|
|
1240
|
-
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1241
|
-
calculatedOrderPaymentType: orderPaymentType,
|
|
1242
|
-
itemsCount: voucherPaymentItemsWithType.length
|
|
1243
|
-
});
|
|
1244
796
|
await this.payment.updateVoucherPaymentItemsAsync(
|
|
1245
797
|
this.store.currentOrder.uuid,
|
|
1246
798
|
voucherPaymentItemsWithType
|
|
1247
799
|
);
|
|
1248
|
-
console.log("[Checkout] Payment模块批量更新完成");
|
|
1249
800
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1250
801
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1251
802
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1253,8 +804,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1253
804
|
);
|
|
1254
805
|
if (updatedOrder) {
|
|
1255
806
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1256
|
-
|
|
1257
|
-
"
|
|
807
|
+
this.logWarning(
|
|
808
|
+
"updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1258
809
|
{
|
|
1259
810
|
currentRealId: currentOrderId,
|
|
1260
811
|
retrievedVirtualId: updatedOrder.order_id
|
|
@@ -1263,22 +814,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1263
814
|
updatedOrder.order_id = currentOrderId;
|
|
1264
815
|
}
|
|
1265
816
|
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
817
|
}
|
|
1283
818
|
await this.updateStateAmountToRemaining();
|
|
1284
819
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1287,9 +822,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1287
822
|
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1288
823
|
timestamp: Date.now()
|
|
1289
824
|
});
|
|
1290
|
-
|
|
825
|
+
this.logInfo("代金券支付项批量更新成功");
|
|
1291
826
|
} catch (error) {
|
|
1292
|
-
|
|
827
|
+
this.logError("[Checkout] 批量更新代金券支付项失败:", error);
|
|
1293
828
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1294
829
|
throw error;
|
|
1295
830
|
}
|
|
@@ -1322,18 +857,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1322
857
|
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1323
858
|
return;
|
|
1324
859
|
}
|
|
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
860
|
const updateParams = {
|
|
1332
861
|
is_deposit: newDepositValue
|
|
1333
862
|
};
|
|
1334
863
|
if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== "0.00") {
|
|
1335
864
|
updateParams.deposit_amount = "0.00";
|
|
1336
|
-
|
|
865
|
+
this.logInfo("订单从定金改为全款,清空定金金额");
|
|
1337
866
|
}
|
|
1338
867
|
await this.payment.updateOrderAsync(
|
|
1339
868
|
this.store.currentOrder.uuid,
|
|
@@ -1350,12 +879,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1350
879
|
order: this.store.currentOrder,
|
|
1351
880
|
timestamp: Date.now()
|
|
1352
881
|
});
|
|
1353
|
-
|
|
882
|
+
this.logInfo("订单定金状态更新成功:", {
|
|
1354
883
|
isDeposit: newDepositValue,
|
|
1355
884
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1356
885
|
});
|
|
1357
886
|
} catch (error) {
|
|
1358
|
-
|
|
887
|
+
this.logError("更新订单定金状态失败:", error);
|
|
1359
888
|
await this.handleError(
|
|
1360
889
|
error,
|
|
1361
890
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1363,100 +892,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1363
892
|
throw error;
|
|
1364
893
|
}
|
|
1365
894
|
}
|
|
1366
|
-
/**
|
|
1367
|
-
* 更新当前订单的客户信息
|
|
1368
|
-
*
|
|
1369
|
-
* 更新当前订单关联的客户信息,用于标识订单的所属客户
|
|
1370
|
-
*
|
|
1371
|
-
* @param customer 客户信息 (customer_id 和/或 customer_name)
|
|
1372
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1373
|
-
*/
|
|
1374
|
-
async updateOrderCustomerAsync(customer) {
|
|
1375
|
-
try {
|
|
1376
|
-
if (!this.store.currentOrder) {
|
|
1377
|
-
throw (0, import_utils.createCheckoutError)(
|
|
1378
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
1379
|
-
"未找到当前订单,无法更新客户信息"
|
|
1380
|
-
);
|
|
1381
|
-
}
|
|
1382
|
-
console.log("[Checkout] 更新订单客户信息:", {
|
|
1383
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1384
|
-
oldCustomer: this.store.currentCustomer,
|
|
1385
|
-
newCustomer: customer
|
|
1386
|
-
});
|
|
1387
|
-
this.store.currentCustomer = {
|
|
1388
|
-
customer_id: customer.customer_id,
|
|
1389
|
-
customer_name: customer.customer_name
|
|
1390
|
-
};
|
|
1391
|
-
if (this.store.localOrderData) {
|
|
1392
|
-
this.store.localOrderData.customer_id = customer.customer_id;
|
|
1393
|
-
this.store.localOrderData.customer_name = customer.customer_name;
|
|
1394
|
-
}
|
|
1395
|
-
console.log(
|
|
1396
|
-
"[Checkout] 订单客户信息更新成功:",
|
|
1397
|
-
this.store.currentCustomer
|
|
1398
|
-
);
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
console.error("[Checkout] 更新订单客户信息失败:", error);
|
|
1401
|
-
await this.handleError(
|
|
1402
|
-
error,
|
|
1403
|
-
import_types.CheckoutErrorType.ValidationFailed
|
|
1404
|
-
);
|
|
1405
|
-
throw error;
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
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
895
|
/**
|
|
1461
896
|
* 手动同步订单到后端
|
|
1462
897
|
*
|
|
@@ -1482,16 +917,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1482
917
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1483
918
|
const oldOrderId = this.store.currentOrder.order_id;
|
|
1484
919
|
if (this.store.isOrderSynced) {
|
|
1485
|
-
|
|
920
|
+
this.logInfo("订单已同步过,将执行更新操作");
|
|
1486
921
|
}
|
|
1487
|
-
|
|
922
|
+
this.logInfo("开始手动同步订单到后端:", {
|
|
1488
923
|
orderUuid,
|
|
1489
924
|
orderId: oldOrderId,
|
|
1490
925
|
totalAmount: this.store.currentOrder.total_amount,
|
|
1491
926
|
remainingAmount: await this.calculateRemainingAmountAsync()
|
|
1492
927
|
});
|
|
1493
928
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1494
|
-
|
|
929
|
+
this.logInfo("手动同步订单完成:", {
|
|
1495
930
|
orderUuid,
|
|
1496
931
|
syncResult,
|
|
1497
932
|
oldOrderId,
|
|
@@ -1500,24 +935,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1500
935
|
});
|
|
1501
936
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1502
937
|
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
938
|
if (finalIsVirtual) {
|
|
1511
|
-
|
|
939
|
+
this.logError("严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1512
940
|
}
|
|
1513
941
|
if (syncResult.orderId !== finalOrderId) {
|
|
1514
|
-
|
|
942
|
+
this.logError(
|
|
1515
943
|
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1516
944
|
);
|
|
1517
945
|
}
|
|
1518
946
|
return syncResult;
|
|
1519
947
|
} catch (error) {
|
|
1520
|
-
|
|
948
|
+
this.logError("手动同步订单失败:", error);
|
|
1521
949
|
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1522
950
|
return {
|
|
1523
951
|
success: false,
|
|
@@ -1578,7 +1006,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1578
1006
|
async cancelCurrentOrderAsync(cancelReason) {
|
|
1579
1007
|
var _a, _b;
|
|
1580
1008
|
try {
|
|
1581
|
-
|
|
1009
|
+
this.logInfo("开始取消当前本地订单:", {
|
|
1582
1010
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1583
1011
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1584
1012
|
orderId: (_b = this.store.currentOrder) == null ? void 0 : _b.order_id,
|
|
@@ -1586,7 +1014,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1586
1014
|
cancelReason
|
|
1587
1015
|
});
|
|
1588
1016
|
if (!this.store.currentOrder) {
|
|
1589
|
-
|
|
1017
|
+
this.logInfo("没有当前订单,无需取消");
|
|
1590
1018
|
return {
|
|
1591
1019
|
success: false,
|
|
1592
1020
|
message: "没有当前订单可取消"
|
|
@@ -1596,7 +1024,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1596
1024
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1597
1025
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1598
1026
|
if (isOrderSynced) {
|
|
1599
|
-
|
|
1027
|
+
this.logInfo("订单已同步到后端,不能取消:", {
|
|
1600
1028
|
orderId: currentOrderId,
|
|
1601
1029
|
orderUuid: currentOrderUuid
|
|
1602
1030
|
});
|
|
@@ -1606,15 +1034,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1606
1034
|
orderId: currentOrderId
|
|
1607
1035
|
};
|
|
1608
1036
|
}
|
|
1609
|
-
console.log("[Checkout] 订单尚未同步,可以取消");
|
|
1610
1037
|
try {
|
|
1611
|
-
|
|
1038
|
+
this.logInfo("删除本地订单数据");
|
|
1612
1039
|
await this.payment.deletePaymentOrderAsync(currentOrderUuid);
|
|
1613
|
-
|
|
1040
|
+
this.logInfo("本地订单数据删除成功");
|
|
1614
1041
|
} catch (error) {
|
|
1615
|
-
|
|
1042
|
+
this.logWarning("删除本地订单数据失败,但继续执行:", error);
|
|
1616
1043
|
}
|
|
1617
|
-
|
|
1044
|
+
this.logInfo("清理订单相关状态");
|
|
1618
1045
|
this.store.currentOrder = void 0;
|
|
1619
1046
|
this.store.localOrderData = void 0;
|
|
1620
1047
|
this.store.stateAmount = "0.00";
|
|
@@ -1622,7 +1049,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1622
1049
|
this.store.isOrderSynced = false;
|
|
1623
1050
|
this.store.currentCustomer = void 0;
|
|
1624
1051
|
this.payment.wallet.clearAllCache();
|
|
1625
|
-
|
|
1052
|
+
this.logInfo("订单状态清理完成,currentOrder已释放");
|
|
1626
1053
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCancelled, {
|
|
1627
1054
|
orderUuid: currentOrderUuid,
|
|
1628
1055
|
orderId: currentOrderId,
|
|
@@ -1631,7 +1058,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1631
1058
|
// 只有未同步订单可以被取消
|
|
1632
1059
|
timestamp: Date.now()
|
|
1633
1060
|
});
|
|
1634
|
-
|
|
1061
|
+
this.logInfo("本地订单取消完成:", {
|
|
1635
1062
|
orderUuid: currentOrderUuid,
|
|
1636
1063
|
orderId: currentOrderId,
|
|
1637
1064
|
cancelReason
|
|
@@ -1642,7 +1069,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1642
1069
|
orderId: currentOrderId
|
|
1643
1070
|
};
|
|
1644
1071
|
} catch (error) {
|
|
1645
|
-
|
|
1072
|
+
this.logError("取消本地订单失败:", error);
|
|
1646
1073
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
|
1647
1074
|
return {
|
|
1648
1075
|
success: false,
|
|
@@ -1667,7 +1094,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1667
1094
|
}
|
|
1668
1095
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1669
1096
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1670
|
-
|
|
1097
|
+
this.logInfo("开始保存订单并稍后支付:", {
|
|
1671
1098
|
orderUuid,
|
|
1672
1099
|
orderId: currentOrderId,
|
|
1673
1100
|
totalAmount: this.store.currentOrder.total_amount
|
|
@@ -1679,7 +1106,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1679
1106
|
false,
|
|
1680
1107
|
allPaymentItems
|
|
1681
1108
|
);
|
|
1682
|
-
|
|
1109
|
+
this.logInfo("保存订单完成:", {
|
|
1683
1110
|
orderUuid,
|
|
1684
1111
|
oldOrderId: currentOrderId,
|
|
1685
1112
|
syncResult,
|
|
@@ -1687,13 +1114,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1687
1114
|
isOrderSynced: this.store.isOrderSynced,
|
|
1688
1115
|
filteredPaymentsCount: allPaymentItems.length
|
|
1689
1116
|
});
|
|
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
1117
|
return {
|
|
1698
1118
|
success: true,
|
|
1699
1119
|
message: "订单保存成功,可稍后继续支付",
|
|
@@ -1702,7 +1122,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1702
1122
|
response: syncResult.response
|
|
1703
1123
|
};
|
|
1704
1124
|
} catch (error) {
|
|
1705
|
-
|
|
1125
|
+
this.logError("保存订单失败:", error);
|
|
1706
1126
|
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1707
1127
|
return {
|
|
1708
1128
|
success: false,
|
|
@@ -1711,93 +1131,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1711
1131
|
};
|
|
1712
1132
|
}
|
|
1713
1133
|
}
|
|
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
1134
|
/**
|
|
1802
1135
|
* 更新订单备注
|
|
1803
1136
|
*
|
|
@@ -1853,40 +1186,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1853
1186
|
throw error;
|
|
1854
1187
|
}
|
|
1855
1188
|
}
|
|
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
1189
|
/**
|
|
1881
1190
|
* 处理错误
|
|
1882
1191
|
*/
|
|
1883
1192
|
async handleError(error, type) {
|
|
1884
1193
|
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1885
1194
|
this.store.lastError = checkoutError;
|
|
1886
|
-
this.setStatus(import_types.CheckoutStatus.Error);
|
|
1887
1195
|
await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
|
|
1888
1196
|
error: checkoutError,
|
|
1889
|
-
context: {
|
|
1197
|
+
context: {},
|
|
1890
1198
|
timestamp: Date.now()
|
|
1891
1199
|
});
|
|
1892
1200
|
console.error("[Checkout] 错误:", checkoutError);
|
|
@@ -1896,7 +1204,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1896
1204
|
*/
|
|
1897
1205
|
async handlePaymentSuccess(data) {
|
|
1898
1206
|
var _a;
|
|
1899
|
-
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
1900
1207
|
await this.updateStateAmountToRemaining();
|
|
1901
1208
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
1902
1209
|
orderUuid: data.orderUuid,
|
|
@@ -1934,24 +1241,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1934
1241
|
}
|
|
1935
1242
|
/**
|
|
1936
1243
|
* 处理现金支付项的找零逻辑
|
|
1937
|
-
*
|
|
1244
|
+
*
|
|
1938
1245
|
* @param paymentItem 原始支付项
|
|
1939
1246
|
* @returns 处理后的支付项(包含找零信息)
|
|
1940
1247
|
*/
|
|
1941
1248
|
async processCashPaymentItem(paymentItem) {
|
|
1942
|
-
const
|
|
1943
|
-
if (!
|
|
1249
|
+
const cashPayment = (0, import_utils.isCashPayment)(paymentItem.code, paymentItem.type);
|
|
1250
|
+
if (!cashPayment) {
|
|
1944
1251
|
return paymentItem;
|
|
1945
1252
|
}
|
|
1946
1253
|
try {
|
|
1947
1254
|
const remainingAmountStr = await this.calculateRemainingAmountAsync();
|
|
1948
1255
|
let remainingAmount = new import_decimal.default(remainingAmountStr);
|
|
1949
1256
|
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
1257
|
if (cashAmount.lte(remainingAmount)) {
|
|
1956
1258
|
return paymentItem;
|
|
1957
1259
|
}
|
|
@@ -1960,14 +1262,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1960
1262
|
if (Number(paymentItem.rounding_amount) === changeAmount.toNumber()) {
|
|
1961
1263
|
return paymentItem;
|
|
1962
1264
|
} else {
|
|
1963
|
-
remainingAmount = remainingAmount.add(
|
|
1265
|
+
remainingAmount = remainingAmount.add(
|
|
1266
|
+
new import_decimal.default(paymentItem.rounding_amount || "0")
|
|
1267
|
+
);
|
|
1964
1268
|
}
|
|
1965
1269
|
}
|
|
1966
|
-
console.log("[Checkout] 现金支付需要找零:", {
|
|
1967
|
-
actualPaidAmount: cashAmount.toFixed(2),
|
|
1968
|
-
chargedAmount: remainingAmount.toFixed(2),
|
|
1969
|
-
changeGivenAmount: changeAmount.toFixed(2)
|
|
1970
|
-
});
|
|
1971
1270
|
const processedPaymentItem = {
|
|
1972
1271
|
...paymentItem,
|
|
1973
1272
|
amount: remainingAmount.toFixed(2),
|
|
@@ -1995,25 +1294,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1995
1294
|
});
|
|
1996
1295
|
return processedPaymentItem;
|
|
1997
1296
|
} catch (error) {
|
|
1998
|
-
|
|
1297
|
+
this.logError("处理现金支付项时出错:", error);
|
|
1999
1298
|
return paymentItem;
|
|
2000
1299
|
}
|
|
2001
1300
|
}
|
|
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
1301
|
/**
|
|
2018
1302
|
* 预加载支付方式(在初始化时调用)
|
|
2019
1303
|
*/
|
|
@@ -2030,7 +1314,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2030
1314
|
}
|
|
2031
1315
|
/**
|
|
2032
1316
|
* 清理过期的已同步订单数据
|
|
2033
|
-
*
|
|
1317
|
+
*
|
|
2034
1318
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
2035
1319
|
*/
|
|
2036
1320
|
async cleanupExpiredOrdersAsync() {
|
|
@@ -2044,7 +1328,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2044
1328
|
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
2045
1329
|
return;
|
|
2046
1330
|
}
|
|
2047
|
-
console.log(
|
|
1331
|
+
console.log(
|
|
1332
|
+
`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`
|
|
1333
|
+
);
|
|
2048
1334
|
const allOrders = await this.payment.getOrderListAsync();
|
|
2049
1335
|
if (!allOrders || allOrders.length === 0) {
|
|
2050
1336
|
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
@@ -2064,7 +1350,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2064
1350
|
if ((_a = order.order_info) == null ? void 0 : _a.created_at) {
|
|
2065
1351
|
orderCreatedAt = new Date(order.order_info.created_at);
|
|
2066
1352
|
} else if ((_c = (_b = order.order_info) == null ? void 0 : _b.original_order_data) == null ? void 0 : _c.created_at) {
|
|
2067
|
-
orderCreatedAt = new Date(
|
|
1353
|
+
orderCreatedAt = new Date(
|
|
1354
|
+
order.order_info.original_order_data.created_at
|
|
1355
|
+
);
|
|
2068
1356
|
}
|
|
2069
1357
|
if (!orderCreatedAt || isNaN(orderCreatedAt.getTime())) {
|
|
2070
1358
|
continue;
|
|
@@ -2074,7 +1362,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2074
1362
|
uuid: order.uuid,
|
|
2075
1363
|
orderId: order.order_id,
|
|
2076
1364
|
createdAt: orderCreatedAt.toISOString(),
|
|
2077
|
-
daysSinceCreated: Math.floor(
|
|
1365
|
+
daysSinceCreated: Math.floor(
|
|
1366
|
+
(Date.now() - orderCreatedAt.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1367
|
+
)
|
|
2078
1368
|
});
|
|
2079
1369
|
}
|
|
2080
1370
|
} catch (error) {
|
|
@@ -2082,13 +1372,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2082
1372
|
continue;
|
|
2083
1373
|
}
|
|
2084
1374
|
}
|
|
2085
|
-
ordersToDelete.sort(
|
|
1375
|
+
ordersToDelete.sort(
|
|
1376
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
1377
|
+
);
|
|
2086
1378
|
const actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete);
|
|
2087
1379
|
for (const orderInfo of actualOrdersToDelete) {
|
|
2088
1380
|
try {
|
|
2089
1381
|
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
2090
1382
|
deletedCount++;
|
|
2091
|
-
console.log(
|
|
1383
|
+
console.log(
|
|
1384
|
+
`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`
|
|
1385
|
+
);
|
|
2092
1386
|
} catch (error) {
|
|
2093
1387
|
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
2094
1388
|
}
|
|
@@ -2105,9 +1399,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2105
1399
|
};
|
|
2106
1400
|
this.logInfo("Expired orders cleanup completed", summary);
|
|
2107
1401
|
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
2108
|
-
console.log(
|
|
1402
|
+
console.log(
|
|
1403
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`
|
|
1404
|
+
);
|
|
2109
1405
|
} else {
|
|
2110
|
-
console.log(
|
|
1406
|
+
console.log(
|
|
1407
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`
|
|
1408
|
+
);
|
|
2111
1409
|
}
|
|
2112
1410
|
} catch (error) {
|
|
2113
1411
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -2120,7 +1418,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2120
1418
|
*/
|
|
2121
1419
|
async calculatePaidAmountAsync() {
|
|
2122
1420
|
if (!this.store.currentOrder) {
|
|
2123
|
-
|
|
1421
|
+
this.logWarning("[Checkout] calculatePaidAmountAsync: 没有当前订单");
|
|
2124
1422
|
return "0.00";
|
|
2125
1423
|
}
|
|
2126
1424
|
try {
|
|
@@ -2129,16 +1427,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2129
1427
|
false
|
|
2130
1428
|
// 不包括已撤销的支付项
|
|
2131
1429
|
);
|
|
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
1430
|
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
2143
1431
|
const amount = new import_decimal.default(payment.amount || "0");
|
|
2144
1432
|
const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
|
|
@@ -2158,10 +1446,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2158
1446
|
return sum.add(effectiveAmount);
|
|
2159
1447
|
}, new import_decimal.default(0));
|
|
2160
1448
|
const result = paidAmount.toFixed(2);
|
|
2161
|
-
|
|
1449
|
+
this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
|
|
2162
1450
|
return result;
|
|
2163
1451
|
} catch (error) {
|
|
2164
|
-
|
|
1452
|
+
this.logError("calculatePaidAmountAsync 失败:", error);
|
|
2165
1453
|
return "0.00";
|
|
2166
1454
|
}
|
|
2167
1455
|
}
|
|
@@ -2170,45 +1458,26 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2170
1458
|
*/
|
|
2171
1459
|
async calculateRemainingAmountAsync() {
|
|
2172
1460
|
if (!this.store.currentOrder) {
|
|
2173
|
-
|
|
1461
|
+
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
2174
1462
|
return "0.00";
|
|
2175
1463
|
}
|
|
2176
|
-
const totalAmount = new import_decimal.default(
|
|
1464
|
+
const totalAmount = new import_decimal.default(
|
|
1465
|
+
this.store.currentOrder.total_amount || "0"
|
|
1466
|
+
);
|
|
2177
1467
|
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
2178
1468
|
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
2179
1469
|
const remainingAmount = totalAmount.sub(paidAmount);
|
|
2180
1470
|
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
|
-
});
|
|
1471
|
+
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
2196
1472
|
return result;
|
|
2197
1473
|
}
|
|
2198
1474
|
/**
|
|
2199
1475
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
2200
1476
|
*/
|
|
2201
1477
|
async updateBalanceDueAmount() {
|
|
2202
|
-
var _a;
|
|
2203
1478
|
try {
|
|
2204
1479
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2205
1480
|
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
1481
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
2213
1482
|
this.store.balanceDueAmount = remainingAmount;
|
|
2214
1483
|
await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
|
|
@@ -2216,34 +1485,27 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2216
1485
|
newAmount: remainingAmount,
|
|
2217
1486
|
timestamp: Date.now()
|
|
2218
1487
|
});
|
|
2219
|
-
|
|
1488
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
2220
1489
|
oldAmount: currentBalanceDueAmount,
|
|
2221
1490
|
newAmount: remainingAmount
|
|
2222
1491
|
});
|
|
2223
1492
|
} else {
|
|
2224
|
-
|
|
1493
|
+
this.logInfo("balanceDueAmount 无需更新,当前值已是最新:", {
|
|
2225
1494
|
balanceDueAmount: currentBalanceDueAmount,
|
|
2226
1495
|
remainingAmount
|
|
2227
1496
|
});
|
|
2228
1497
|
}
|
|
2229
1498
|
} catch (error) {
|
|
2230
|
-
|
|
1499
|
+
this.logError("更新 balanceDueAmount 失败:", error);
|
|
2231
1500
|
}
|
|
2232
1501
|
}
|
|
2233
1502
|
/**
|
|
2234
1503
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
2235
1504
|
*/
|
|
2236
1505
|
async updateStateAmountToRemaining() {
|
|
2237
|
-
var _a;
|
|
2238
1506
|
try {
|
|
2239
1507
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2240
1508
|
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
1509
|
if (remainingAmount !== currentStateAmount) {
|
|
2248
1510
|
this.store.stateAmount = remainingAmount;
|
|
2249
1511
|
this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
@@ -2251,12 +1513,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2251
1513
|
newAmount: remainingAmount,
|
|
2252
1514
|
timestamp: Date.now()
|
|
2253
1515
|
});
|
|
2254
|
-
|
|
1516
|
+
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
2255
1517
|
oldAmount: currentStateAmount,
|
|
2256
1518
|
newAmount: remainingAmount
|
|
2257
1519
|
});
|
|
2258
1520
|
} else {
|
|
2259
|
-
|
|
1521
|
+
this.logInfo("stateAmount 无需更新,当前值已是最新:", {
|
|
2260
1522
|
stateAmount: currentStateAmount,
|
|
2261
1523
|
remainingAmount
|
|
2262
1524
|
});
|
|
@@ -2264,7 +1526,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2264
1526
|
await this.updateBalanceDueAmount();
|
|
2265
1527
|
await this.checkOrderPaymentCompletion();
|
|
2266
1528
|
} catch (error) {
|
|
2267
|
-
|
|
1529
|
+
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
2268
1530
|
}
|
|
2269
1531
|
}
|
|
2270
1532
|
/**
|
|
@@ -2282,7 +1544,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2282
1544
|
if (remainingValue.lte(0)) {
|
|
2283
1545
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
2284
1546
|
const paidAmount = await this.calculatePaidAmountAsync();
|
|
2285
|
-
|
|
1547
|
+
this.logInfo("检测到订单支付完成:", {
|
|
2286
1548
|
orderUuid: this.store.currentOrder.uuid,
|
|
2287
1549
|
orderId: this.store.currentOrder.order_id,
|
|
2288
1550
|
totalAmount,
|
|
@@ -2300,7 +1562,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2300
1562
|
(item) => item.status !== "voided" && item.voucher_id
|
|
2301
1563
|
);
|
|
2302
1564
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
2303
|
-
|
|
1565
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
2304
1566
|
paymentCount: currentPayments.length,
|
|
2305
1567
|
hasPaymentItems,
|
|
2306
1568
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
@@ -2318,13 +1580,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2318
1580
|
}))
|
|
2319
1581
|
});
|
|
2320
1582
|
if (shouldAutoSync) {
|
|
2321
|
-
|
|
2322
|
-
await this.
|
|
1583
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
1584
|
+
await this.syncOrderToBackendWithReturn(false);
|
|
2323
1585
|
} else {
|
|
2324
1586
|
if (!hasPaymentItems) {
|
|
2325
|
-
|
|
1587
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
2326
1588
|
} else if (allPaymentsHaveVoucherId) {
|
|
2327
|
-
|
|
1589
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
2328
1590
|
}
|
|
2329
1591
|
}
|
|
2330
1592
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
|
|
@@ -2337,14 +1599,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2337
1599
|
});
|
|
2338
1600
|
}
|
|
2339
1601
|
} catch (error) {
|
|
2340
|
-
|
|
1602
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2341
1603
|
}
|
|
2342
1604
|
}
|
|
2343
|
-
/**
|
|
2344
|
-
* 同步订单到后端
|
|
2345
|
-
*
|
|
2346
|
-
* 调用后端 /order/checkout 接口创建真实订单
|
|
2347
|
-
*/
|
|
2348
1605
|
/**
|
|
2349
1606
|
* 同步订单到后端并返回真实订单ID
|
|
2350
1607
|
*
|
|
@@ -2353,72 +1610,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2353
1610
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
2354
1611
|
*/
|
|
2355
1612
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2356
|
-
var _a, _b, _c, _d, _e
|
|
1613
|
+
var _a, _b, _c, _d, _e;
|
|
2357
1614
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2358
1615
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2359
1616
|
}
|
|
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 ? "手动" : "自动";
|
|
1617
|
+
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2373
1618
|
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}订单到后端...`, {
|
|
1619
|
+
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1620
|
+
this.logInfo(`开始同步订单到后端...`, {
|
|
2397
1621
|
currentOrderId,
|
|
2398
1622
|
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2399
|
-
operation,
|
|
2400
1623
|
orderUuid: this.store.currentOrder.uuid,
|
|
2401
|
-
isOrderSynced: this.store.isOrderSynced
|
|
1624
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1625
|
+
isManual
|
|
2402
1626
|
});
|
|
2403
1627
|
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
1628
|
const processedPaymentItems = paymentItems.map((item) => {
|
|
2423
1629
|
var _a2, _b2;
|
|
2424
1630
|
return {
|
|
@@ -2430,23 +1636,27 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2430
1636
|
}
|
|
2431
1637
|
};
|
|
2432
1638
|
});
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
1639
|
+
const depositPaymentItems = processedPaymentItems.filter(
|
|
1640
|
+
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1641
|
+
);
|
|
1642
|
+
const calculatedDepositAmount = depositPaymentItems.reduce((sum, item) => {
|
|
1643
|
+
const amount = new import_decimal.default(item.amount || "0");
|
|
1644
|
+
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
1645
|
+
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
1646
|
+
return sum.add(effectiveAmount);
|
|
1647
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
1648
|
+
this.logInfo("计算定金支付项总金额", {
|
|
1649
|
+
depositPaymentItemsCount: depositPaymentItems.length,
|
|
1650
|
+
depositPaymentItems: depositPaymentItems.map((item) => ({
|
|
1651
|
+
uuid: item.uuid,
|
|
1652
|
+
code: item.code,
|
|
1653
|
+
amount: item.amount,
|
|
1654
|
+
rounding_amount: item.rounding_amount,
|
|
1655
|
+
order_payment_type: item.order_payment_type,
|
|
1656
|
+
status: item.status
|
|
1657
|
+
})),
|
|
1658
|
+
calculatedDepositAmount,
|
|
1659
|
+
originalDepositAmount: ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00"
|
|
2450
1660
|
});
|
|
2451
1661
|
const orderParams = {
|
|
2452
1662
|
...this.store.localOrderData,
|
|
@@ -2454,7 +1664,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2454
1664
|
platform: this.store.localOrderData.platform,
|
|
2455
1665
|
payments: processedPaymentItems,
|
|
2456
1666
|
// 使用处理过的支付项数据
|
|
2457
|
-
customer_id: (
|
|
1667
|
+
customer_id: (_b = this.store.currentCustomer) == null ? void 0 : _b.customer_id,
|
|
2458
1668
|
// 添加客户ID
|
|
2459
1669
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2460
1670
|
// core 有
|
|
@@ -2467,35 +1677,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2467
1677
|
currency_code: this.otherParams.currency_code,
|
|
2468
1678
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2469
1679
|
currency_format: this.otherParams.currency_format,
|
|
2470
|
-
is_deposit: ((
|
|
2471
|
-
deposit_amount:
|
|
2472
|
-
//
|
|
2473
|
-
// surcharges: ,
|
|
1680
|
+
is_deposit: ((_c = this.store.currentOrder) == null ? void 0 : _c.is_deposit) || 0,
|
|
1681
|
+
deposit_amount: calculatedDepositAmount,
|
|
1682
|
+
// 使用从支付项中计算出的定金金额
|
|
2474
1683
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
2475
1684
|
note: this.store.localOrderData.shop_note
|
|
2476
|
-
// deposit_amount:
|
|
2477
1685
|
};
|
|
2478
1686
|
if (isUpdateOperation) {
|
|
2479
1687
|
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] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
1688
|
+
this.logWarning(
|
|
1689
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2492
1690
|
);
|
|
2493
1691
|
} else {
|
|
2494
1692
|
orderParams.order_id = currentOrderId;
|
|
2495
|
-
console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
|
|
2496
1693
|
}
|
|
2497
|
-
} else {
|
|
2498
|
-
console.log("[Checkout] 创建新订单操作");
|
|
2499
1694
|
}
|
|
2500
1695
|
const startTime = Date.now();
|
|
2501
1696
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitStart, {
|
|
@@ -2511,29 +1706,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2511
1706
|
try {
|
|
2512
1707
|
this.logInfo("Calling backend checkout API", {
|
|
2513
1708
|
url: "/order/checkout",
|
|
2514
|
-
operation,
|
|
2515
1709
|
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
|
|
1710
|
+
...orderParams
|
|
2530
1711
|
});
|
|
2531
1712
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2532
1713
|
submitSuccess = true;
|
|
2533
|
-
|
|
1714
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2534
1715
|
} catch (error) {
|
|
2535
1716
|
submitSuccess = false;
|
|
2536
1717
|
submitError = error instanceof Error ? error.message : String(error);
|
|
1718
|
+
this.logError("下单接口调用失败:", submitError);
|
|
2537
1719
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2538
1720
|
orderUuid: this.store.currentOrder.uuid,
|
|
2539
1721
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2550,29 +1732,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2550
1732
|
orderUuid: this.store.currentOrder.uuid,
|
|
2551
1733
|
operation: isUpdateOperation ? "update" : "create",
|
|
2552
1734
|
isManual,
|
|
2553
|
-
orderId: submitSuccess ? ((
|
|
1735
|
+
orderId: submitSuccess ? ((_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2554
1736
|
error: submitError,
|
|
2555
1737
|
duration: Date.now() - startTime,
|
|
2556
1738
|
timestamp: Date.now()
|
|
2557
1739
|
});
|
|
2558
1740
|
}
|
|
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
1741
|
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2566
1742
|
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2567
1743
|
if (!isSuccessResponse) {
|
|
2568
1744
|
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
1745
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2577
1746
|
orderUuid: this.store.currentOrder.uuid,
|
|
2578
1747
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2585,13 +1754,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2585
1754
|
});
|
|
2586
1755
|
throw new Error(errorMessage);
|
|
2587
1756
|
}
|
|
2588
|
-
console.log("[Checkout] 响应状态检查通过,开始处理订单数据");
|
|
2589
1757
|
let realOrderId;
|
|
2590
1758
|
if (isUpdateOperation) {
|
|
2591
1759
|
realOrderId = currentOrderId;
|
|
2592
|
-
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
2593
1760
|
} else {
|
|
2594
|
-
let extractedOrderId = (
|
|
1761
|
+
let extractedOrderId = (_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id;
|
|
2595
1762
|
if (!extractedOrderId) {
|
|
2596
1763
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2597
1764
|
}
|
|
@@ -2599,11 +1766,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2599
1766
|
extractedOrderId = String(extractedOrderId);
|
|
2600
1767
|
}
|
|
2601
1768
|
if (!extractedOrderId) {
|
|
2602
|
-
|
|
1769
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
2603
1770
|
}
|
|
2604
1771
|
realOrderId = extractedOrderId;
|
|
2605
|
-
|
|
2606
|
-
console.log("[Checkout] 准备替换订单ID:", {
|
|
1772
|
+
this.logInfo("准备替换订单ID:", {
|
|
2607
1773
|
orderUuid: this.store.currentOrder.uuid,
|
|
2608
1774
|
oldOrderId: this.store.currentOrder.order_id,
|
|
2609
1775
|
newOrderId: realOrderId
|
|
@@ -2613,38 +1779,38 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2613
1779
|
this.store.currentOrder.uuid,
|
|
2614
1780
|
realOrderId
|
|
2615
1781
|
);
|
|
2616
|
-
|
|
1782
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
2617
1783
|
wasSuccessful: !!updatedOrder,
|
|
2618
1784
|
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2619
1785
|
expectedOrderId: realOrderId
|
|
2620
1786
|
});
|
|
2621
1787
|
if (updatedOrder) {
|
|
2622
|
-
|
|
1788
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
2623
1789
|
uuid: updatedOrder.uuid,
|
|
2624
1790
|
orderId: updatedOrder.order_id,
|
|
2625
1791
|
totalAmount: updatedOrder.total_amount
|
|
2626
1792
|
});
|
|
2627
1793
|
this.store.currentOrder = updatedOrder;
|
|
2628
|
-
|
|
1794
|
+
this.logInfo(
|
|
2629
1795
|
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2630
1796
|
this.store.currentOrder.order_id
|
|
2631
1797
|
);
|
|
2632
1798
|
} else {
|
|
2633
|
-
|
|
1799
|
+
this.logError(
|
|
2634
1800
|
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2635
1801
|
);
|
|
2636
1802
|
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2637
1803
|
this.store.currentOrder.order_id = realOrderId;
|
|
2638
|
-
|
|
1804
|
+
this.logInfo("手动设置订单ID:", {
|
|
2639
1805
|
beforeReplacement: beforeManualUpdate,
|
|
2640
1806
|
afterReplacement: this.store.currentOrder.order_id,
|
|
2641
1807
|
目标ID: realOrderId
|
|
2642
1808
|
});
|
|
2643
1809
|
}
|
|
2644
1810
|
} catch (error) {
|
|
2645
|
-
|
|
1811
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2646
1812
|
this.store.currentOrder.order_id = realOrderId;
|
|
2647
|
-
|
|
1813
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2648
1814
|
}
|
|
2649
1815
|
}
|
|
2650
1816
|
this.store.isOrderSynced = true;
|
|
@@ -2656,69 +1822,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2656
1822
|
isManual,
|
|
2657
1823
|
response: checkoutResponse
|
|
2658
1824
|
});
|
|
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
1825
|
return {
|
|
2673
1826
|
success: true,
|
|
2674
|
-
message: `订单${operation}成功`,
|
|
2675
1827
|
orderId: realOrderId,
|
|
2676
1828
|
orderUuid: this.store.currentOrder.uuid,
|
|
2677
1829
|
response: checkoutResponse
|
|
2678
1830
|
};
|
|
2679
1831
|
}
|
|
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
1832
|
async setOtherParams(params, { cover = false } = {}) {
|
|
2723
1833
|
if (cover) {
|
|
2724
1834
|
this.otherParams = params;
|
|
@@ -2739,15 +1849,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2739
1849
|
this.logInfo("editOrderNoteByOrderIdAsync called", {
|
|
2740
1850
|
orderId,
|
|
2741
1851
|
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))
|
|
1852
|
+
noteLength: note.length
|
|
2744
1853
|
});
|
|
2745
1854
|
try {
|
|
2746
|
-
console.log("[Checkout] 开始编辑订单备注:", {
|
|
2747
|
-
orderId,
|
|
2748
|
-
note,
|
|
2749
|
-
noteLength: note.length
|
|
2750
|
-
});
|
|
2751
1855
|
if (!orderId) {
|
|
2752
1856
|
return {
|
|
2753
1857
|
success: false,
|
|
@@ -2762,22 +1866,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2762
1866
|
note,
|
|
2763
1867
|
noteLength: note.length
|
|
2764
1868
|
});
|
|
2765
|
-
const response = await this.request.put(
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
}
|
|
2770
|
-
);
|
|
2771
|
-
console.log("[Checkout] 订单备注编辑响应:", {
|
|
1869
|
+
const response = await this.request.put(`/order/order/${orderId}/note`, {
|
|
1870
|
+
note
|
|
1871
|
+
});
|
|
1872
|
+
this.logInfo("订单备注编辑响应:", {
|
|
2772
1873
|
orderId,
|
|
2773
1874
|
status: response.status,
|
|
2774
1875
|
message: response.message,
|
|
2775
1876
|
response
|
|
2776
1877
|
});
|
|
2777
1878
|
if (response.status === true || response.status === 200) {
|
|
2778
|
-
console.log(`[Checkout] 订单 ${orderId} 备注修改成功`);
|
|
2779
1879
|
if (this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))) {
|
|
2780
|
-
console.log("[Checkout] 更新本地订单备注状态");
|
|
2781
1880
|
const previousNote = this.getOrderNote();
|
|
2782
1881
|
if (this.store.localOrderData) {
|
|
2783
1882
|
this.store.localOrderData.shop_note = note;
|
|
@@ -2796,7 +1895,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2796
1895
|
};
|
|
2797
1896
|
} else {
|
|
2798
1897
|
const errorMessage = response.message || "订单备注修改失败";
|
|
2799
|
-
|
|
1898
|
+
this.logError(`订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
2800
1899
|
return {
|
|
2801
1900
|
success: false,
|
|
2802
1901
|
message: errorMessage,
|
|
@@ -2804,7 +1903,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2804
1903
|
};
|
|
2805
1904
|
}
|
|
2806
1905
|
} catch (error) {
|
|
2807
|
-
|
|
1906
|
+
this.logError("编辑订单备注失败:", error);
|
|
2808
1907
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2809
1908
|
return {
|
|
2810
1909
|
success: false,
|
|
@@ -2831,11 +1930,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2831
1930
|
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2832
1931
|
});
|
|
2833
1932
|
try {
|
|
2834
|
-
console.log("[Checkout] 开始发送客户支付链接邮件:", {
|
|
2835
|
-
orderIds: params.order_ids,
|
|
2836
|
-
emails: params.emails,
|
|
2837
|
-
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2838
|
-
});
|
|
2839
1933
|
if (!params.order_ids || params.order_ids.length === 0) {
|
|
2840
1934
|
return {
|
|
2841
1935
|
success: false,
|
|
@@ -2863,27 +1957,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2863
1957
|
notify_action: params.notify_action || "order_payment_reminder",
|
|
2864
1958
|
emails: params.emails
|
|
2865
1959
|
};
|
|
2866
|
-
console.log("[Checkout] 发送支付链接邮件请求参数:", requestBody);
|
|
2867
1960
|
this.logInfo("Calling batch email API", {
|
|
2868
1961
|
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
|
|
1962
|
+
...requestBody
|
|
2874
1963
|
});
|
|
2875
1964
|
const response = await this.request.post(
|
|
2876
1965
|
"/order/batch-email",
|
|
2877
1966
|
requestBody
|
|
2878
1967
|
);
|
|
2879
|
-
|
|
1968
|
+
this.logInfo("支付链接邮件发送响应:", {
|
|
2880
1969
|
status: response.status,
|
|
2881
1970
|
message: response.message,
|
|
2882
1971
|
data: response.data,
|
|
2883
1972
|
response
|
|
2884
1973
|
});
|
|
2885
1974
|
if (response.status === true || response.status === 200) {
|
|
2886
|
-
console.log("[Checkout] 支付链接邮件发送成功");
|
|
2887
1975
|
return {
|
|
2888
1976
|
success: true,
|
|
2889
1977
|
message: response.message || "支付链接邮件发送成功"
|
|
@@ -2897,7 +1985,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2897
1985
|
};
|
|
2898
1986
|
}
|
|
2899
1987
|
} catch (error) {
|
|
2900
|
-
|
|
1988
|
+
this.logError("发送客户支付链接邮件失败:", error);
|
|
2901
1989
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2902
1990
|
return {
|
|
2903
1991
|
success: false,
|
|
@@ -2918,9 +2006,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2918
2006
|
(_a = this.otherParams.order_rounding_setting) == null ? void 0 : _a.interval,
|
|
2919
2007
|
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.type
|
|
2920
2008
|
);
|
|
2921
|
-
console.log(
|
|
2922
|
-
`[Checkout] 金额舍入完成 - 原始: ${result.originalAmount}, 舍入后: ${result.roundedAmount}, 差额: ${result.roundingDifference}`
|
|
2923
|
-
);
|
|
2924
2009
|
return result;
|
|
2925
2010
|
}
|
|
2926
2011
|
async destroy() {
|
|
@@ -2954,8 +2039,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2954
2039
|
this.store.lastError = void 0;
|
|
2955
2040
|
this.store.cartItems = [];
|
|
2956
2041
|
this.payment.wallet.clearAllCache();
|
|
2957
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
2958
|
-
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
2959
2042
|
console.log("[Checkout] Store 状态重置完成");
|
|
2960
2043
|
if (prevOrderInfo) {
|
|
2961
2044
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
|
|
@@ -2967,33 +2050,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2967
2050
|
console.error("[Checkout] 重置 store 状态失败:", error);
|
|
2968
2051
|
}
|
|
2969
2052
|
}
|
|
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
2053
|
};
|
|
2998
2054
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2999
2055
|
0 && (module.exports = {
|