@pisell/pisellos 0.0.256 → 0.0.258
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/Discount/types.d.ts +3 -0
- package/dist/modules/Order/index.js +10 -4
- package/dist/modules/Payment/index.d.ts +1 -0
- package/dist/modules/Payment/index.js +38 -31
- package/dist/modules/Payment/walletpass.js +1 -1
- package/dist/modules/Rules/index.js +35 -10
- package/dist/modules/Schedule/index.d.ts +1 -1
- package/dist/modules/Schedule/index.js +9 -0
- package/dist/solution/Checkout/index.d.ts +1 -153
- package/dist/solution/Checkout/index.js +1040 -2504
- 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/dist/solution/ShopDiscount/utils.d.ts +11 -0
- package/dist/solution/ShopDiscount/utils.js +29 -0
- package/lib/modules/Discount/types.d.ts +3 -0
- package/lib/modules/Order/index.js +6 -0
- package/lib/modules/Payment/index.d.ts +1 -0
- package/lib/modules/Payment/index.js +13 -6
- package/lib/modules/Payment/walletpass.js +1 -1
- package/lib/modules/Rules/index.js +21 -5
- package/lib/modules/Schedule/index.d.ts +1 -1
- package/lib/modules/Schedule/index.js +9 -0
- package/lib/solution/Checkout/index.d.ts +1 -153
- package/lib/solution/Checkout/index.js +219 -1148
- 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/lib/solution/ShopDiscount/utils.d.ts +11 -0
- package/lib/solution/ShopDiscount/utils.js +24 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
17
19
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/solution/Checkout/index.ts
|
|
@@ -24,6 +34,7 @@ __export(Checkout_exports, {
|
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(Checkout_exports);
|
|
26
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
27
38
|
var import_Order = require("../../modules/Order");
|
|
28
39
|
var import_Payment = require("../../modules/Payment");
|
|
29
40
|
var import_types = require("./types");
|
|
@@ -54,8 +65,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
54
65
|
this.order = new import_Order.OrderModule();
|
|
55
66
|
this.payment = new import_Payment.PaymentModule();
|
|
56
67
|
this.store = {
|
|
57
|
-
status: import_types.CheckoutStatus.Initializing,
|
|
58
|
-
step: import_types.CheckoutStep.OrderConfirmation,
|
|
59
68
|
cartItems: [],
|
|
60
69
|
paymentMethods: [],
|
|
61
70
|
stateAmount: "0.00",
|
|
@@ -67,7 +76,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
67
76
|
await this.initializeSubModules(core, options);
|
|
68
77
|
await this.preloadPaymentMethods();
|
|
69
78
|
await this.cleanupExpiredOrdersAsync();
|
|
70
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
71
79
|
console.log("[Checkout] 初始化完成");
|
|
72
80
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
|
|
73
81
|
timestamp: Date.now()
|
|
@@ -81,7 +89,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
81
89
|
if (this.logger) {
|
|
82
90
|
this.logger.addLog({
|
|
83
91
|
type: "info",
|
|
84
|
-
title: `[CheckoutModule] ${title}`,
|
|
92
|
+
title: `[CheckoutModule] ${this.getCurrentOrderId()} ${title}`,
|
|
85
93
|
metadata: metadata || {}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
@@ -117,11 +125,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
117
125
|
var _a, _b;
|
|
118
126
|
core.registerModule(this.order, {
|
|
119
127
|
store: ((_a = options.store) == null ? void 0 : _a.order) || {},
|
|
120
|
-
otherParams: { ...this.otherParams,
|
|
128
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
121
129
|
});
|
|
122
130
|
core.registerModule(this.payment, {
|
|
123
131
|
store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
|
|
124
|
-
otherParams: { ...this.otherParams,
|
|
132
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
125
133
|
});
|
|
126
134
|
this.setupPaymentEventListeners();
|
|
127
135
|
}
|
|
@@ -170,7 +178,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
170
178
|
platform: params.platform
|
|
171
179
|
});
|
|
172
180
|
try {
|
|
173
|
-
this.setStatus(import_types.CheckoutStatus.Initializing);
|
|
174
181
|
const validation = this.validateCheckoutParams(params);
|
|
175
182
|
if (!validation.valid) {
|
|
176
183
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -179,8 +186,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
179
186
|
);
|
|
180
187
|
}
|
|
181
188
|
this.store.cartItems = params.cartItems;
|
|
182
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
183
|
-
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
184
189
|
console.log("[Checkout] 结账流程初始化完成");
|
|
185
190
|
} catch (error) {
|
|
186
191
|
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
@@ -205,12 +210,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
205
210
|
selling_price: item.product.price - (item.product.discount_amount || 0) - getDiscountListAmount(item.product.discount_list)
|
|
206
211
|
})
|
|
207
212
|
)) || [];
|
|
208
|
-
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(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
)) || [];
|
|
214
221
|
return [...productList, ...relationProducts];
|
|
215
222
|
}
|
|
216
223
|
async initWalletData(params) {
|
|
@@ -231,6 +238,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
231
238
|
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
232
239
|
walletBusinessData
|
|
233
240
|
);
|
|
241
|
+
if (!this.store.currentOrder) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
234
244
|
await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
|
|
235
245
|
orderUuid: (_d = this.store.currentOrder) == null ? void 0 : _d.uuid,
|
|
236
246
|
customerId: walletBusinessData.customer_id,
|
|
@@ -262,9 +272,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
262
272
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
263
273
|
});
|
|
264
274
|
try {
|
|
265
|
-
console.time("createLocalOrderAsync");
|
|
266
275
|
await this.resetStoreStateAsync();
|
|
267
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
268
276
|
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
269
277
|
if (!validation.valid) {
|
|
270
278
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -309,20 +317,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
309
317
|
amount_breakdown: amountInfo
|
|
310
318
|
}
|
|
311
319
|
});
|
|
312
|
-
console.timeEnd("createLocalOrderAsync");
|
|
313
320
|
this.store.currentOrder = paymentOrder;
|
|
314
321
|
this.initWalletData();
|
|
315
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
316
|
-
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
317
322
|
if (params.autoPayment) {
|
|
318
|
-
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
319
323
|
}
|
|
320
324
|
this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
321
325
|
order: paymentOrder,
|
|
322
326
|
timestamp: Date.now()
|
|
323
327
|
});
|
|
324
328
|
await this.updateStateAmountToRemaining();
|
|
325
|
-
|
|
329
|
+
this.logInfo("本地订单创建成功:", {
|
|
326
330
|
localOrderId,
|
|
327
331
|
uuid: paymentOrder.uuid,
|
|
328
332
|
totalAmount: amountInfo.totalAmount,
|
|
@@ -343,206 +347,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
343
347
|
throw error;
|
|
344
348
|
}
|
|
345
349
|
}
|
|
346
|
-
/**
|
|
347
|
-
* 手动下单 (根据虚拟订单生成实际订单)
|
|
348
|
-
*
|
|
349
|
-
* 使用当前存储的本地订单数据调用 Order 模块创建真实订单
|
|
350
|
-
*/
|
|
351
|
-
async placeOrderAsync(params = {}) {
|
|
352
|
-
var _a, _b;
|
|
353
|
-
this.logInfo("placeOrderAsync called", {
|
|
354
|
-
url: params.url,
|
|
355
|
-
autoReplaceOrderId: params.autoReplaceOrderId,
|
|
356
|
-
hasLocalOrderData: !!this.store.localOrderData,
|
|
357
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
358
|
-
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
359
|
-
isOrderSynced: this.store.isOrderSynced
|
|
360
|
-
});
|
|
361
|
-
try {
|
|
362
|
-
if (!this.store.localOrderData) {
|
|
363
|
-
throw (0, import_utils.createCheckoutError)(
|
|
364
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
365
|
-
"没有找到本地订单数据,请先调用 createLocalOrderAsync 创建虚拟订单"
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
if (!this.store.currentOrder) {
|
|
369
|
-
throw (0, import_utils.createCheckoutError)(
|
|
370
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
371
|
-
"没有找到当前订单,请先创建虚拟订单"
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
console.log("[Checkout] 开始手动下单流程...");
|
|
375
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
376
|
-
const orderData = {
|
|
377
|
-
cartItems: this.store.cartItems,
|
|
378
|
-
type: this.store.localOrderData.type,
|
|
379
|
-
platform: this.store.localOrderData.platform
|
|
380
|
-
};
|
|
381
|
-
const orderResponse = await this.order.submitOrder({
|
|
382
|
-
url: params.url,
|
|
383
|
-
// 可选的自定义 URL
|
|
384
|
-
query: orderData
|
|
385
|
-
});
|
|
386
|
-
const realOrderId = ((_b = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _b.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
|
|
387
|
-
if (!realOrderId) {
|
|
388
|
-
throw (0, import_utils.createCheckoutError)(
|
|
389
|
-
import_types.CheckoutErrorType.OrderCreationFailed,
|
|
390
|
-
"订单创建成功但未返回订单ID"
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
console.log("[Checkout] 真实订单创建成功:", realOrderId);
|
|
394
|
-
if (params.autoReplaceOrderId !== false) {
|
|
395
|
-
console.log("[Checkout] 自动替换虚拟订单ID为真实订单ID...");
|
|
396
|
-
const updatedOrder = await this.replaceLocalOrderIdAsync(realOrderId);
|
|
397
|
-
if (updatedOrder) {
|
|
398
|
-
console.log("[Checkout] 订单ID替换成功:", {
|
|
399
|
-
oldId: this.store.currentOrder.order_id,
|
|
400
|
-
newId: realOrderId
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
405
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
406
|
-
order: this.store.currentOrder,
|
|
407
|
-
timestamp: Date.now()
|
|
408
|
-
});
|
|
409
|
-
this.store.isOrderSynced = true;
|
|
410
|
-
console.log("[Checkout] 手动下单流程完成");
|
|
411
|
-
return {
|
|
412
|
-
success: true,
|
|
413
|
-
orderId: realOrderId
|
|
414
|
-
};
|
|
415
|
-
} catch (error) {
|
|
416
|
-
let errorMessage = "下单失败";
|
|
417
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
418
|
-
errorMessage = error.message;
|
|
419
|
-
} else if (error instanceof Error) {
|
|
420
|
-
errorMessage = error.message;
|
|
421
|
-
}
|
|
422
|
-
console.error("[Checkout] 手动下单失败:", errorMessage);
|
|
423
|
-
await this.handleError(
|
|
424
|
-
error,
|
|
425
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
426
|
-
);
|
|
427
|
-
return {
|
|
428
|
-
success: false,
|
|
429
|
-
error: errorMessage
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* 创建订单
|
|
435
|
-
*/
|
|
436
|
-
async createOrderAsync(params) {
|
|
437
|
-
var _a;
|
|
438
|
-
try {
|
|
439
|
-
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
440
|
-
const checkResult = this.order.checkBeforeSubmitOrder({
|
|
441
|
-
cartItems: params.cartItems,
|
|
442
|
-
type: "account"
|
|
443
|
-
// 默认使用 account 类型
|
|
444
|
-
});
|
|
445
|
-
if (!checkResult) {
|
|
446
|
-
throw (0, import_utils.createCheckoutError)(
|
|
447
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
448
|
-
"购物车数据验证失败,请检查商品信息"
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
const orderResponse = await this.order.submitOrder({
|
|
452
|
-
query: {
|
|
453
|
-
cartItems: params.cartItems,
|
|
454
|
-
type: params.type || "appointment_booking",
|
|
455
|
-
platform: params.platform || "pc"
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
459
|
-
order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
|
|
460
|
-
total_amount: (0, import_utils.calculateTotalAmount)(params.cartItems),
|
|
461
|
-
order_info: orderResponse == null ? void 0 : orderResponse.data
|
|
462
|
-
});
|
|
463
|
-
this.store.currentOrder = paymentOrder;
|
|
464
|
-
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
465
|
-
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
466
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
467
|
-
order: paymentOrder,
|
|
468
|
-
timestamp: Date.now()
|
|
469
|
-
});
|
|
470
|
-
this.store.isOrderSynced = true;
|
|
471
|
-
await this.updateStateAmountToRemaining();
|
|
472
|
-
console.log("[Checkout] 订单创建成功:", paymentOrder.id);
|
|
473
|
-
return paymentOrder;
|
|
474
|
-
} catch (error) {
|
|
475
|
-
await this.handleError(
|
|
476
|
-
error,
|
|
477
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
478
|
-
);
|
|
479
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
|
|
480
|
-
error: this.store.lastError,
|
|
481
|
-
timestamp: Date.now()
|
|
482
|
-
});
|
|
483
|
-
throw error;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* 处理支付
|
|
488
|
-
*/
|
|
489
|
-
async processPaymentAsync(params) {
|
|
490
|
-
try {
|
|
491
|
-
if (!this.store.currentOrder) {
|
|
492
|
-
throw (0, import_utils.createCheckoutError)(
|
|
493
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
494
|
-
"未找到当前订单,请先创建订单"
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
this.setStatus(import_types.CheckoutStatus.ProcessingPayment);
|
|
498
|
-
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
499
|
-
const paymentMethod = this.store.paymentMethods.find(
|
|
500
|
-
(method) => method.code === params.paymentMethodCode
|
|
501
|
-
);
|
|
502
|
-
if (!paymentMethod) {
|
|
503
|
-
throw (0, import_utils.createCheckoutError)(
|
|
504
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
505
|
-
`未找到支付方式: ${params.paymentMethodCode}`
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
const paymentItem = {
|
|
509
|
-
code: paymentMethod.code,
|
|
510
|
-
name: paymentMethod.name,
|
|
511
|
-
type: paymentMethod.type,
|
|
512
|
-
amount: String(params.amount),
|
|
513
|
-
id: paymentMethod.id
|
|
514
|
-
};
|
|
515
|
-
await this.payment.addPaymentItemAsync(
|
|
516
|
-
this.store.currentOrder.uuid,
|
|
517
|
-
paymentItem
|
|
518
|
-
);
|
|
519
|
-
const result = await this.payment.submitPayAsync(
|
|
520
|
-
this.store.currentOrder.uuid
|
|
521
|
-
);
|
|
522
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
523
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
524
|
-
paymentMethodCode: params.paymentMethodCode,
|
|
525
|
-
amount: String(params.amount),
|
|
526
|
-
timestamp: Date.now()
|
|
527
|
-
});
|
|
528
|
-
if (result.status === "success") {
|
|
529
|
-
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
530
|
-
await this.updateStateAmountToRemaining();
|
|
531
|
-
await this.handlePaymentSuccess({
|
|
532
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
533
|
-
timestamp: Date.now()
|
|
534
|
-
});
|
|
535
|
-
} else {
|
|
536
|
-
throw (0, import_utils.createCheckoutError)(
|
|
537
|
-
import_types.CheckoutErrorType.PaymentFailed,
|
|
538
|
-
"支付处理失败,请重试"
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
} catch (error) {
|
|
542
|
-
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
543
|
-
throw error;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
350
|
/**
|
|
547
351
|
* 完成结账
|
|
548
352
|
*/
|
|
@@ -564,8 +368,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
564
368
|
);
|
|
565
369
|
}
|
|
566
370
|
this.payment.wallet.clearAllCache();
|
|
567
|
-
this.setStatus(import_types.CheckoutStatus.Completed);
|
|
568
|
-
this.setStep(import_types.CheckoutStep.Complete);
|
|
569
371
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
570
372
|
orderId: order.id,
|
|
571
373
|
timestamp: Date.now()
|
|
@@ -581,89 +383,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
581
383
|
return { success: false };
|
|
582
384
|
}
|
|
583
385
|
}
|
|
584
|
-
/**
|
|
585
|
-
* 取消结账
|
|
586
|
-
*/
|
|
587
|
-
async cancelCheckoutAsync() {
|
|
588
|
-
try {
|
|
589
|
-
if (this.store.currentOrder) {
|
|
590
|
-
await this.payment.deletePaymentOrderAsync(
|
|
591
|
-
this.store.currentOrder.uuid
|
|
592
|
-
);
|
|
593
|
-
this.store.currentOrder = void 0;
|
|
594
|
-
}
|
|
595
|
-
this.store.localOrderData = void 0;
|
|
596
|
-
this.store.cartSummary = void 0;
|
|
597
|
-
this.payment.wallet.clearAllCache();
|
|
598
|
-
this.store.cartItems = [];
|
|
599
|
-
this.store.stateAmount = "0.00";
|
|
600
|
-
this.store.balanceDueAmount = "0.00";
|
|
601
|
-
this.store.isOrderSynced = false;
|
|
602
|
-
this.store.currentCustomer = void 0;
|
|
603
|
-
this.setStatus(import_types.CheckoutStatus.Cancelled);
|
|
604
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
|
|
605
|
-
timestamp: Date.now()
|
|
606
|
-
});
|
|
607
|
-
console.log("[Checkout] 结账流程已取消");
|
|
608
|
-
} catch (error) {
|
|
609
|
-
console.error("[Checkout] 取消结账失败:", error);
|
|
610
|
-
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* 获取结账状态
|
|
615
|
-
*/
|
|
616
|
-
getCheckoutStatus() {
|
|
617
|
-
return {
|
|
618
|
-
status: this.store.status,
|
|
619
|
-
step: this.store.step,
|
|
620
|
-
progress: (0, import_utils.calculateProgress)(this.store.status, this.store.step),
|
|
621
|
-
message: this.getStatusMessage(),
|
|
622
|
-
error: this.store.lastError
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* 获取结账摘要
|
|
627
|
-
*/
|
|
628
|
-
async getCheckoutSummaryAsync() {
|
|
629
|
-
var _a, _b;
|
|
630
|
-
const totalAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0.00";
|
|
631
|
-
const paidAmount = await this.calculatePaidAmountAsync();
|
|
632
|
-
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
633
|
-
return {
|
|
634
|
-
order: this.store.currentOrder,
|
|
635
|
-
totalAmount,
|
|
636
|
-
paidAmount,
|
|
637
|
-
remainingAmount,
|
|
638
|
-
paymentStatus: ((_b = this.store.currentOrder) == null ? void 0 : _b.payment_status) || import_types2.PaymentStatus.Processing,
|
|
639
|
-
availablePaymentMethods: this.store.paymentMethods
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* 获取可用支付方式
|
|
644
|
-
*/
|
|
645
|
-
async getAvailablePaymentMethodsAsync() {
|
|
646
|
-
return await this.getPaymentMethodsAsync();
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* 刷新支付方式缓存
|
|
650
|
-
*
|
|
651
|
-
* 强制重新从服务器获取支付方式列表,更新本地缓存
|
|
652
|
-
*/
|
|
653
|
-
async refreshPaymentMethodsAsync() {
|
|
654
|
-
console.log("[Checkout] 强制刷新支付方式缓存...");
|
|
655
|
-
try {
|
|
656
|
-
const methods = await this.payment.getPayMethodListAsync();
|
|
657
|
-
this.store.paymentMethods = methods;
|
|
658
|
-
console.log(
|
|
659
|
-
`[Checkout] 强制刷新完成,获取到 ${methods.length} 种支付方式`
|
|
660
|
-
);
|
|
661
|
-
return methods;
|
|
662
|
-
} catch (error) {
|
|
663
|
-
console.error("[Checkout] 强制刷新支付方式失败:", error);
|
|
664
|
-
return this.store.paymentMethods;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
386
|
/**
|
|
668
387
|
* 获取订单原始数据
|
|
669
388
|
*/
|
|
@@ -678,7 +397,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
678
397
|
*/
|
|
679
398
|
getCurrentOrderInfo() {
|
|
680
399
|
try {
|
|
681
|
-
const { currentOrder,
|
|
400
|
+
const { currentOrder, cartItems, localOrderData } = this.store;
|
|
682
401
|
if (!currentOrder) {
|
|
683
402
|
console.log("[Checkout] 当前没有活跃订单");
|
|
684
403
|
return null;
|
|
@@ -690,8 +409,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
690
409
|
const result = {
|
|
691
410
|
uuid: currentOrder.uuid,
|
|
692
411
|
orderId: currentOrder.order_id,
|
|
693
|
-
status,
|
|
694
|
-
step,
|
|
695
412
|
totalAmount: currentOrder.total_amount,
|
|
696
413
|
remainingAmount: currentOrder.expect_amount,
|
|
697
414
|
paymentStatus: currentOrder.payment_status,
|
|
@@ -703,13 +420,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
703
420
|
itemCount: cartItems.length,
|
|
704
421
|
hasLocalOrderData: Boolean(localOrderData)
|
|
705
422
|
};
|
|
706
|
-
console.log("[Checkout] 获取当前订单基础信息:", {
|
|
707
|
-
uuid: result.uuid,
|
|
708
|
-
orderId: result.orderId,
|
|
709
|
-
status: result.status,
|
|
710
|
-
totalAmount: result.totalAmount,
|
|
711
|
-
remainingAmount: result.remainingAmount
|
|
712
|
-
});
|
|
713
423
|
return result;
|
|
714
424
|
} catch (error) {
|
|
715
425
|
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
@@ -728,89 +438,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
728
438
|
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
729
439
|
return [];
|
|
730
440
|
}
|
|
731
|
-
console.log("[Checkout] 获取当前订单支付项:", {
|
|
732
|
-
orderUuid: currentOrder.uuid,
|
|
733
|
-
orderId: currentOrder.order_id
|
|
734
|
-
});
|
|
735
441
|
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
736
442
|
currentOrder.uuid
|
|
737
443
|
);
|
|
738
|
-
console.log("[Checkout] 成功获取支付项:", {
|
|
739
|
-
orderUuid: currentOrder.uuid,
|
|
740
|
-
paymentItemCount: paymentItems.length,
|
|
741
|
-
activeItems: paymentItems.filter((item) => item.status !== "voided").length,
|
|
742
|
-
voidedItems: paymentItems.filter((item) => item.status === "voided").length,
|
|
743
|
-
totalPaidAmount: paymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => sum + parseFloat(item.amount || "0"), 0).toFixed(2),
|
|
744
|
-
paymentMethods: paymentItems.map((item) => ({
|
|
745
|
-
uuid: item.uuid,
|
|
746
|
-
code: item.code,
|
|
747
|
-
amount: item.amount,
|
|
748
|
-
status: item.status,
|
|
749
|
-
voucher_id: item.voucher_id
|
|
750
|
-
}))
|
|
751
|
-
});
|
|
752
444
|
return paymentItems;
|
|
753
445
|
} catch (error) {
|
|
754
446
|
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
755
447
|
return [];
|
|
756
448
|
}
|
|
757
449
|
}
|
|
758
|
-
/**
|
|
759
|
-
* 验证结账前置条件
|
|
760
|
-
*/
|
|
761
|
-
async validateCheckoutAsync() {
|
|
762
|
-
const errors = [];
|
|
763
|
-
if (!this.store.cartItems || this.store.cartItems.length === 0) {
|
|
764
|
-
errors.push("购物车为空");
|
|
765
|
-
}
|
|
766
|
-
if (this.store.paymentMethods.length === 0) {
|
|
767
|
-
errors.push("无可用支付方式");
|
|
768
|
-
}
|
|
769
|
-
if (this.store.status === import_types.CheckoutStatus.Error) {
|
|
770
|
-
errors.push("结账流程存在错误");
|
|
771
|
-
}
|
|
772
|
-
return {
|
|
773
|
-
valid: errors.length === 0,
|
|
774
|
-
errors
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* 重试失败的操作
|
|
779
|
-
*/
|
|
780
|
-
async retryFailedOperationAsync() {
|
|
781
|
-
try {
|
|
782
|
-
if (this.store.status === import_types.CheckoutStatus.Error && this.store.lastError) {
|
|
783
|
-
switch (this.store.lastError.type) {
|
|
784
|
-
case import_types.CheckoutErrorType.OrderCreationFailed:
|
|
785
|
-
if (this.store.cartItems.length > 0) {
|
|
786
|
-
await this.createOrderAsync({
|
|
787
|
-
cartItems: this.store.cartItems
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
break;
|
|
791
|
-
default:
|
|
792
|
-
console.warn(
|
|
793
|
-
"[Checkout] 无法重试此类型的错误:",
|
|
794
|
-
this.store.lastError.type
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
} catch (error) {
|
|
799
|
-
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
/**
|
|
803
|
-
* 设置当前步骤
|
|
804
|
-
*/
|
|
805
|
-
setCurrentStep(step) {
|
|
806
|
-
const oldStep = this.store.step;
|
|
807
|
-
this.store.step = step;
|
|
808
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
809
|
-
oldStep,
|
|
810
|
-
newStep: step,
|
|
811
|
-
timestamp: Date.now()
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
450
|
/**
|
|
815
451
|
* 获取订单模块
|
|
816
452
|
*/
|
|
@@ -879,7 +515,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
879
515
|
if (oldAmount === formattedAmount) {
|
|
880
516
|
return;
|
|
881
517
|
}
|
|
882
|
-
this.
|
|
518
|
+
this.logInfo("[Checkout] 设置自定义支付金额:", {
|
|
883
519
|
oldAmount,
|
|
884
520
|
newAmount: formattedAmount
|
|
885
521
|
});
|
|
@@ -889,10 +525,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
889
525
|
newAmount: formattedAmount,
|
|
890
526
|
timestamp: Date.now()
|
|
891
527
|
});
|
|
892
|
-
console.log("[Checkout] 自定义支付金额已更新:", {
|
|
893
|
-
oldAmount,
|
|
894
|
-
newAmount: formattedAmount
|
|
895
|
-
});
|
|
896
528
|
} catch (error) {
|
|
897
529
|
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
898
530
|
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
@@ -921,14 +553,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
921
553
|
getBalanceDueAmount() {
|
|
922
554
|
return this.store.balanceDueAmount;
|
|
923
555
|
}
|
|
924
|
-
/**
|
|
925
|
-
* 刷新 stateAmount 为当前剩余未支付金额
|
|
926
|
-
*
|
|
927
|
-
* UI 可以调用此方法来主动刷新支付金额状态
|
|
928
|
-
*/
|
|
929
|
-
async refreshStateAmountAsync() {
|
|
930
|
-
await this.updateStateAmountToRemaining();
|
|
931
|
-
}
|
|
932
556
|
/**
|
|
933
557
|
* 获取购物车小计数据
|
|
934
558
|
*
|
|
@@ -941,7 +565,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
941
565
|
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
942
566
|
return null;
|
|
943
567
|
}
|
|
944
|
-
|
|
568
|
+
this.logInfo("获取购物车小计数据:", {
|
|
945
569
|
itemCount: this.store.cartSummary.length,
|
|
946
570
|
items: this.store.cartSummary.map((item) => ({
|
|
947
571
|
key: item.key,
|
|
@@ -951,24 +575,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
951
575
|
});
|
|
952
576
|
return [...this.store.cartSummary];
|
|
953
577
|
}
|
|
954
|
-
/**
|
|
955
|
-
* 获取提取的金额详细信息
|
|
956
|
-
*
|
|
957
|
-
* 从当前的购物车小计数据中提取结构化的金额信息
|
|
958
|
-
*
|
|
959
|
-
* @returns 提取的金额信息对象,如果没有小计数据则返回 null
|
|
960
|
-
*/
|
|
961
|
-
getExtractedAmountInfo() {
|
|
962
|
-
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
963
|
-
console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
|
|
964
|
-
return null;
|
|
965
|
-
}
|
|
966
|
-
const extractedInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
967
|
-
this.store.cartSummary
|
|
968
|
-
);
|
|
969
|
-
console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
|
|
970
|
-
return extractedInfo;
|
|
971
|
-
}
|
|
972
578
|
/**
|
|
973
579
|
* 获取支付方式列表
|
|
974
580
|
*
|
|
@@ -979,21 +585,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
979
585
|
*/
|
|
980
586
|
async getPaymentMethodsAsync() {
|
|
981
587
|
if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
|
|
982
|
-
|
|
983
|
-
|
|
588
|
+
this.logInfo(
|
|
589
|
+
`使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
|
|
984
590
|
);
|
|
985
591
|
return this.store.paymentMethods;
|
|
986
592
|
}
|
|
987
|
-
|
|
593
|
+
this.logInfo("store 中无缓存,从 Payment 模块获取支付方式...");
|
|
988
594
|
try {
|
|
989
595
|
const methods = await this.payment.getPayMethodListAsync();
|
|
990
596
|
this.store.paymentMethods = methods;
|
|
991
|
-
|
|
992
|
-
|
|
597
|
+
this.logInfo(
|
|
598
|
+
`从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
|
|
993
599
|
);
|
|
994
600
|
return methods;
|
|
995
601
|
} catch (error) {
|
|
996
|
-
|
|
602
|
+
this.logError("获取支付方式失败:", error);
|
|
997
603
|
return [];
|
|
998
604
|
}
|
|
999
605
|
}
|
|
@@ -1006,19 +612,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1006
612
|
* @throws 当前没有活跃订单时抛出错误
|
|
1007
613
|
*/
|
|
1008
614
|
async addPaymentItemAsync(paymentItem) {
|
|
1009
|
-
var _a, _b
|
|
1010
|
-
this.logInfo("addPaymentItemAsync called",
|
|
1011
|
-
paymentCode: paymentItem.code,
|
|
1012
|
-
paymentType: paymentItem.type,
|
|
1013
|
-
amount: paymentItem.amount,
|
|
1014
|
-
voucherId: paymentItem.voucher_id,
|
|
1015
|
-
serviceCharge: paymentItem.service_charge,
|
|
1016
|
-
roundingAmount: paymentItem.rounding_amount,
|
|
1017
|
-
hasMetadata: !!paymentItem.metadata,
|
|
1018
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
1019
|
-
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1020
|
-
isDepositOrder: (_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit
|
|
1021
|
-
});
|
|
615
|
+
var _a, _b;
|
|
616
|
+
this.logInfo("addPaymentItemAsync called", paymentItem);
|
|
1022
617
|
try {
|
|
1023
618
|
if (!this.store.currentOrder) {
|
|
1024
619
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -1038,53 +633,33 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1038
633
|
order_payment_type: orderPaymentType,
|
|
1039
634
|
metadata
|
|
1040
635
|
};
|
|
1041
|
-
console.log("[Checkout] 为当前订单添加支付项:", {
|
|
1042
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1043
|
-
paymentItem: {
|
|
1044
|
-
code: paymentItemWithType.code,
|
|
1045
|
-
name: paymentItemWithType.name,
|
|
1046
|
-
type: paymentItemWithType.type,
|
|
1047
|
-
amount: paymentItemWithType.amount,
|
|
1048
|
-
service_charge: paymentItemWithType.service_charge,
|
|
1049
|
-
rounding_amount: paymentItemWithType.rounding_amount,
|
|
1050
|
-
voucher_id: paymentItemWithType.voucher_id,
|
|
1051
|
-
order_payment_type: paymentItemWithType.order_payment_type,
|
|
1052
|
-
metadata: paymentItemWithType.metadata
|
|
1053
|
-
},
|
|
1054
|
-
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1055
|
-
calculatedOrderPaymentType: orderPaymentType,
|
|
1056
|
-
// 现金支付找零详情
|
|
1057
|
-
isCashPayment: this.isCashPayment(paymentItem.code, paymentItem.type),
|
|
1058
|
-
originalAmount: paymentItem.amount,
|
|
1059
|
-
processedAmount: paymentItemWithType.amount,
|
|
1060
|
-
actualPaidAmount: (_c = paymentItemWithType.metadata) == null ? void 0 : _c.actual_paid_amount,
|
|
1061
|
-
changeGivenAmount: (_d = paymentItemWithType.metadata) == null ? void 0 : _d.change_given_amount
|
|
1062
|
-
});
|
|
1063
636
|
await this.payment.addPaymentItemAsync(
|
|
1064
637
|
this.store.currentOrder.uuid,
|
|
1065
638
|
paymentItemWithType
|
|
1066
639
|
);
|
|
1067
|
-
|
|
1068
|
-
const isEftposPayment = ((
|
|
1069
|
-
|
|
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 支付检查:", {
|
|
1070
643
|
paymentCode: paymentItem.code,
|
|
1071
644
|
paymentType: paymentItem.type,
|
|
1072
645
|
isEftposPayment,
|
|
1073
646
|
currentOrderSynced: this.store.isOrderSynced
|
|
1074
647
|
});
|
|
1075
648
|
if (isEftposPayment) {
|
|
1076
|
-
|
|
649
|
+
this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
|
|
1077
650
|
try {
|
|
1078
651
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
652
|
+
this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
|
|
653
|
+
orderId: syncResult.orderId,
|
|
654
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
655
|
+
backendResponse: syncResult.response
|
|
1083
656
|
});
|
|
1084
657
|
} catch (error) {
|
|
1085
|
-
|
|
658
|
+
this.logError("EFTPOS 支付后订单同步失败:", error);
|
|
1086
659
|
await this.handleError(
|
|
1087
|
-
new Error(
|
|
660
|
+
new Error(
|
|
661
|
+
`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
662
|
+
),
|
|
1088
663
|
import_types.CheckoutErrorType.OrderCreationFailed
|
|
1089
664
|
);
|
|
1090
665
|
}
|
|
@@ -1097,7 +672,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1097
672
|
timestamp: Date.now()
|
|
1098
673
|
});
|
|
1099
674
|
} catch (error) {
|
|
1100
|
-
|
|
675
|
+
this.logError("添加支付项失败:", error);
|
|
1101
676
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1102
677
|
throw error;
|
|
1103
678
|
}
|
|
@@ -1119,7 +694,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1119
694
|
"当前没有活跃订单,无法删除支付项"
|
|
1120
695
|
);
|
|
1121
696
|
}
|
|
1122
|
-
|
|
697
|
+
this.logWarning("开始删除支付项:", {
|
|
1123
698
|
orderUuid: this.store.currentOrder.uuid,
|
|
1124
699
|
paymentUuid
|
|
1125
700
|
});
|
|
@@ -1135,7 +710,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1135
710
|
`支付项不存在: ${paymentUuid}`
|
|
1136
711
|
);
|
|
1137
712
|
}
|
|
1138
|
-
|
|
713
|
+
this.logInfo("找到要删除的支付项:", {
|
|
1139
714
|
uuid: paymentItem.uuid,
|
|
1140
715
|
code: paymentItem.code,
|
|
1141
716
|
amount: paymentItem.amount,
|
|
@@ -1145,7 +720,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1145
720
|
this.store.currentOrder.uuid,
|
|
1146
721
|
paymentUuid
|
|
1147
722
|
);
|
|
1148
|
-
|
|
723
|
+
this.logInfo("Payment支付项删除完成", paymentItem);
|
|
1149
724
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1150
725
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1151
726
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1153,20 +728,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1153
728
|
);
|
|
1154
729
|
if (updatedOrder) {
|
|
1155
730
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1156
|
-
|
|
731
|
+
this.logWarning(
|
|
1157
732
|
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1158
733
|
{
|
|
1159
|
-
|
|
1160
|
-
|
|
734
|
+
currentRealId: currentOrderId,
|
|
735
|
+
retrievedVirtualId: updatedOrder.order_id
|
|
1161
736
|
}
|
|
1162
737
|
);
|
|
1163
738
|
updatedOrder.order_id = currentOrderId;
|
|
1164
739
|
}
|
|
1165
740
|
this.store.currentOrder = updatedOrder;
|
|
1166
|
-
console.log(
|
|
1167
|
-
"[Checkout] 订单数据已同步,当前支付项数量:",
|
|
1168
|
-
updatedOrder.payment.length
|
|
1169
|
-
);
|
|
1170
741
|
}
|
|
1171
742
|
await this.updateStateAmountToRemaining();
|
|
1172
743
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1176,9 +747,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1176
747
|
// 负数表示删除
|
|
1177
748
|
timestamp: Date.now()
|
|
1178
749
|
});
|
|
1179
|
-
console.log("[Checkout] 支付项删除成功");
|
|
1180
750
|
} catch (error) {
|
|
1181
|
-
|
|
751
|
+
this.logError("删除支付项失败:", error);
|
|
1182
752
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1183
753
|
throw error;
|
|
1184
754
|
}
|
|
@@ -1201,9 +771,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1201
771
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
1202
772
|
);
|
|
1203
773
|
}
|
|
1204
|
-
|
|
1205
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1206
|
-
newVoucherCount: voucherPaymentItems.length,
|
|
774
|
+
this.logInfo("开始批量更新代金券支付项:", {
|
|
1207
775
|
voucherPaymentItems
|
|
1208
776
|
});
|
|
1209
777
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
@@ -1225,16 +793,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1225
793
|
metadata
|
|
1226
794
|
};
|
|
1227
795
|
});
|
|
1228
|
-
console.log("[Checkout] 代金券支付项订单支付类型设置:", {
|
|
1229
|
-
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1230
|
-
calculatedOrderPaymentType: orderPaymentType,
|
|
1231
|
-
itemsCount: voucherPaymentItemsWithType.length
|
|
1232
|
-
});
|
|
1233
796
|
await this.payment.updateVoucherPaymentItemsAsync(
|
|
1234
797
|
this.store.currentOrder.uuid,
|
|
1235
798
|
voucherPaymentItemsWithType
|
|
1236
799
|
);
|
|
1237
|
-
console.log("[Checkout] Payment模块批量更新完成");
|
|
1238
800
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1239
801
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1240
802
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -1242,32 +804,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1242
804
|
);
|
|
1243
805
|
if (updatedOrder) {
|
|
1244
806
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1245
|
-
|
|
1246
|
-
"
|
|
807
|
+
this.logWarning(
|
|
808
|
+
"updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1247
809
|
{
|
|
1248
|
-
|
|
1249
|
-
|
|
810
|
+
currentRealId: currentOrderId,
|
|
811
|
+
retrievedVirtualId: updatedOrder.order_id
|
|
1250
812
|
}
|
|
1251
813
|
);
|
|
1252
814
|
updatedOrder.order_id = currentOrderId;
|
|
1253
815
|
}
|
|
1254
816
|
this.store.currentOrder = updatedOrder;
|
|
1255
|
-
console.log(
|
|
1256
|
-
"[Checkout] 订单数据已同步,当前支付项数量:",
|
|
1257
|
-
updatedOrder.payment.length
|
|
1258
|
-
);
|
|
1259
|
-
const voucherItems = updatedOrder.payment.filter(
|
|
1260
|
-
(payment) => payment.voucher_id && payment.status !== "voided"
|
|
1261
|
-
);
|
|
1262
|
-
console.log("[Checkout] 更新后的代金券支付项:", {
|
|
1263
|
-
voucherCount: voucherItems.length,
|
|
1264
|
-
items: voucherItems.map((item) => ({
|
|
1265
|
-
uuid: item.uuid,
|
|
1266
|
-
code: item.code,
|
|
1267
|
-
amount: item.amount,
|
|
1268
|
-
voucher_id: item.voucher_id
|
|
1269
|
-
}))
|
|
1270
|
-
});
|
|
1271
817
|
}
|
|
1272
818
|
await this.updateStateAmountToRemaining();
|
|
1273
819
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -1276,9 +822,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1276
822
|
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1277
823
|
timestamp: Date.now()
|
|
1278
824
|
});
|
|
1279
|
-
|
|
825
|
+
this.logInfo("代金券支付项批量更新成功");
|
|
1280
826
|
} catch (error) {
|
|
1281
|
-
|
|
827
|
+
this.logError("[Checkout] 批量更新代金券支付项失败:", error);
|
|
1282
828
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1283
829
|
throw error;
|
|
1284
830
|
}
|
|
@@ -1311,18 +857,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1311
857
|
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1312
858
|
return;
|
|
1313
859
|
}
|
|
1314
|
-
console.log("[Checkout] 更新订单定金状态:", {
|
|
1315
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1316
|
-
orderId: this.store.currentOrder.order_id,
|
|
1317
|
-
oldIsDeposit: oldDepositValue,
|
|
1318
|
-
newIsDeposit: newDepositValue
|
|
1319
|
-
});
|
|
1320
860
|
const updateParams = {
|
|
1321
861
|
is_deposit: newDepositValue
|
|
1322
862
|
};
|
|
1323
863
|
if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== "0.00") {
|
|
1324
864
|
updateParams.deposit_amount = "0.00";
|
|
1325
|
-
|
|
865
|
+
this.logInfo("订单从定金改为全款,清空定金金额");
|
|
1326
866
|
}
|
|
1327
867
|
await this.payment.updateOrderAsync(
|
|
1328
868
|
this.store.currentOrder.uuid,
|
|
@@ -1339,54 +879,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1339
879
|
order: this.store.currentOrder,
|
|
1340
880
|
timestamp: Date.now()
|
|
1341
881
|
});
|
|
1342
|
-
|
|
882
|
+
this.logInfo("订单定金状态更新成功:", {
|
|
1343
883
|
isDeposit: newDepositValue,
|
|
1344
884
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1345
885
|
});
|
|
1346
886
|
} catch (error) {
|
|
1347
|
-
|
|
1348
|
-
await this.handleError(
|
|
1349
|
-
error,
|
|
1350
|
-
import_types.CheckoutErrorType.ValidationFailed
|
|
1351
|
-
);
|
|
1352
|
-
throw error;
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* 更新当前订单的客户信息
|
|
1357
|
-
*
|
|
1358
|
-
* 更新当前订单关联的客户信息,用于标识订单的所属客户
|
|
1359
|
-
*
|
|
1360
|
-
* @param customer 客户信息 (customer_id 和/或 customer_name)
|
|
1361
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1362
|
-
*/
|
|
1363
|
-
async updateOrderCustomerAsync(customer) {
|
|
1364
|
-
try {
|
|
1365
|
-
if (!this.store.currentOrder) {
|
|
1366
|
-
throw (0, import_utils.createCheckoutError)(
|
|
1367
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
1368
|
-
"未找到当前订单,无法更新客户信息"
|
|
1369
|
-
);
|
|
1370
|
-
}
|
|
1371
|
-
console.log("[Checkout] 更新订单客户信息:", {
|
|
1372
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1373
|
-
oldCustomer: this.store.currentCustomer,
|
|
1374
|
-
newCustomer: customer
|
|
1375
|
-
});
|
|
1376
|
-
this.store.currentCustomer = {
|
|
1377
|
-
customer_id: customer.customer_id,
|
|
1378
|
-
customer_name: customer.customer_name
|
|
1379
|
-
};
|
|
1380
|
-
if (this.store.localOrderData) {
|
|
1381
|
-
this.store.localOrderData.customer_id = customer.customer_id;
|
|
1382
|
-
this.store.localOrderData.customer_name = customer.customer_name;
|
|
1383
|
-
}
|
|
1384
|
-
console.log(
|
|
1385
|
-
"[Checkout] 订单客户信息更新成功:",
|
|
1386
|
-
this.store.currentCustomer
|
|
1387
|
-
);
|
|
1388
|
-
} catch (error) {
|
|
1389
|
-
console.error("[Checkout] 更新订单客户信息失败:", error);
|
|
887
|
+
this.logError("更新订单定金状态失败:", error);
|
|
1390
888
|
await this.handleError(
|
|
1391
889
|
error,
|
|
1392
890
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1394,58 +892,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1394
892
|
throw error;
|
|
1395
893
|
}
|
|
1396
894
|
}
|
|
1397
|
-
/**
|
|
1398
|
-
* 获取当前订单的客户信息
|
|
1399
|
-
*
|
|
1400
|
-
* @returns 当前客户信息,如果没有则返回 null
|
|
1401
|
-
*/
|
|
1402
|
-
getCurrentCustomer() {
|
|
1403
|
-
return this.store.currentCustomer || null;
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* 检查订单是否需要手动同步(异步版本)
|
|
1407
|
-
*
|
|
1408
|
-
* 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
|
|
1409
|
-
* 从 Payment 模块获取最新的支付项数据
|
|
1410
|
-
*/
|
|
1411
|
-
async needsManualSyncAsync() {
|
|
1412
|
-
try {
|
|
1413
|
-
if (!this.store.currentOrder || this.store.isOrderSynced) {
|
|
1414
|
-
return false;
|
|
1415
|
-
}
|
|
1416
|
-
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1417
|
-
const remainingValue = parseFloat(remainingAmount);
|
|
1418
|
-
if (remainingValue > 0) {
|
|
1419
|
-
return false;
|
|
1420
|
-
}
|
|
1421
|
-
const currentPayments = await this.payment.getPaymentItemsAsync(
|
|
1422
|
-
this.store.currentOrder.uuid,
|
|
1423
|
-
false
|
|
1424
|
-
// 不包括已撤销的支付项
|
|
1425
|
-
);
|
|
1426
|
-
const allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(
|
|
1427
|
-
(item) => item.status !== "voided" && item.voucher_id
|
|
1428
|
-
);
|
|
1429
|
-
console.log("[Checkout] needsManualSyncAsync 检查结果:", {
|
|
1430
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1431
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
1432
|
-
remainingAmount,
|
|
1433
|
-
hasPayments: currentPayments.length > 0,
|
|
1434
|
-
allPaymentsHaveVoucherId,
|
|
1435
|
-
needsManualSync: allPaymentsHaveVoucherId,
|
|
1436
|
-
paymentItems: currentPayments.map((p) => ({
|
|
1437
|
-
code: p.code,
|
|
1438
|
-
amount: p.amount,
|
|
1439
|
-
status: p.status,
|
|
1440
|
-
hasVoucherId: !!p.voucher_id
|
|
1441
|
-
}))
|
|
1442
|
-
});
|
|
1443
|
-
return allPaymentsHaveVoucherId;
|
|
1444
|
-
} catch (error) {
|
|
1445
|
-
console.error("[Checkout] needsManualSyncAsync 检查失败:", error);
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
895
|
/**
|
|
1450
896
|
* 手动同步订单到后端
|
|
1451
897
|
*
|
|
@@ -1471,16 +917,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1471
917
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1472
918
|
const oldOrderId = this.store.currentOrder.order_id;
|
|
1473
919
|
if (this.store.isOrderSynced) {
|
|
1474
|
-
|
|
920
|
+
this.logInfo("订单已同步过,将执行更新操作");
|
|
1475
921
|
}
|
|
1476
|
-
|
|
922
|
+
this.logInfo("开始手动同步订单到后端:", {
|
|
1477
923
|
orderUuid,
|
|
1478
924
|
orderId: oldOrderId,
|
|
1479
925
|
totalAmount: this.store.currentOrder.total_amount,
|
|
1480
926
|
remainingAmount: await this.calculateRemainingAmountAsync()
|
|
1481
927
|
});
|
|
1482
928
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1483
|
-
|
|
929
|
+
this.logInfo("手动同步订单完成:", {
|
|
1484
930
|
orderUuid,
|
|
1485
931
|
syncResult,
|
|
1486
932
|
oldOrderId,
|
|
@@ -1489,24 +935,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1489
935
|
});
|
|
1490
936
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1491
937
|
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId);
|
|
1492
|
-
console.log("[Checkout] manualSyncOrderAsync 最终状态验证:", {
|
|
1493
|
-
返回的订单ID: syncResult.orderId,
|
|
1494
|
-
存储的订单ID: finalOrderId,
|
|
1495
|
-
存储的ID是否虚拟: finalIsVirtual,
|
|
1496
|
-
是否一致: syncResult.orderId === finalOrderId,
|
|
1497
|
-
同步状态: this.store.isOrderSynced
|
|
1498
|
-
});
|
|
1499
938
|
if (finalIsVirtual) {
|
|
1500
|
-
|
|
939
|
+
this.logError("严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1501
940
|
}
|
|
1502
941
|
if (syncResult.orderId !== finalOrderId) {
|
|
1503
|
-
|
|
942
|
+
this.logError(
|
|
1504
943
|
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1505
944
|
);
|
|
1506
945
|
}
|
|
1507
946
|
return syncResult;
|
|
1508
947
|
} catch (error) {
|
|
1509
|
-
|
|
948
|
+
this.logError("手动同步订单失败:", error);
|
|
1510
949
|
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1511
950
|
return {
|
|
1512
951
|
success: false,
|
|
@@ -1567,7 +1006,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1567
1006
|
async cancelCurrentOrderAsync(cancelReason) {
|
|
1568
1007
|
var _a, _b;
|
|
1569
1008
|
try {
|
|
1570
|
-
|
|
1009
|
+
this.logInfo("开始取消当前本地订单:", {
|
|
1571
1010
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1572
1011
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1573
1012
|
orderId: (_b = this.store.currentOrder) == null ? void 0 : _b.order_id,
|
|
@@ -1575,7 +1014,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1575
1014
|
cancelReason
|
|
1576
1015
|
});
|
|
1577
1016
|
if (!this.store.currentOrder) {
|
|
1578
|
-
|
|
1017
|
+
this.logInfo("没有当前订单,无需取消");
|
|
1579
1018
|
return {
|
|
1580
1019
|
success: false,
|
|
1581
1020
|
message: "没有当前订单可取消"
|
|
@@ -1585,7 +1024,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1585
1024
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1586
1025
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1587
1026
|
if (isOrderSynced) {
|
|
1588
|
-
|
|
1027
|
+
this.logInfo("订单已同步到后端,不能取消:", {
|
|
1589
1028
|
orderId: currentOrderId,
|
|
1590
1029
|
orderUuid: currentOrderUuid
|
|
1591
1030
|
});
|
|
@@ -1595,15 +1034,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1595
1034
|
orderId: currentOrderId
|
|
1596
1035
|
};
|
|
1597
1036
|
}
|
|
1598
|
-
console.log("[Checkout] 订单尚未同步,可以取消");
|
|
1599
1037
|
try {
|
|
1600
|
-
|
|
1038
|
+
this.logInfo("删除本地订单数据");
|
|
1601
1039
|
await this.payment.deletePaymentOrderAsync(currentOrderUuid);
|
|
1602
|
-
|
|
1040
|
+
this.logInfo("本地订单数据删除成功");
|
|
1603
1041
|
} catch (error) {
|
|
1604
|
-
|
|
1042
|
+
this.logWarning("删除本地订单数据失败,但继续执行:", error);
|
|
1605
1043
|
}
|
|
1606
|
-
|
|
1044
|
+
this.logInfo("清理订单相关状态");
|
|
1607
1045
|
this.store.currentOrder = void 0;
|
|
1608
1046
|
this.store.localOrderData = void 0;
|
|
1609
1047
|
this.store.stateAmount = "0.00";
|
|
@@ -1611,7 +1049,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1611
1049
|
this.store.isOrderSynced = false;
|
|
1612
1050
|
this.store.currentCustomer = void 0;
|
|
1613
1051
|
this.payment.wallet.clearAllCache();
|
|
1614
|
-
|
|
1052
|
+
this.logInfo("订单状态清理完成,currentOrder已释放");
|
|
1615
1053
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCancelled, {
|
|
1616
1054
|
orderUuid: currentOrderUuid,
|
|
1617
1055
|
orderId: currentOrderId,
|
|
@@ -1620,7 +1058,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1620
1058
|
// 只有未同步订单可以被取消
|
|
1621
1059
|
timestamp: Date.now()
|
|
1622
1060
|
});
|
|
1623
|
-
|
|
1061
|
+
this.logInfo("本地订单取消完成:", {
|
|
1624
1062
|
orderUuid: currentOrderUuid,
|
|
1625
1063
|
orderId: currentOrderId,
|
|
1626
1064
|
cancelReason
|
|
@@ -1631,7 +1069,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1631
1069
|
orderId: currentOrderId
|
|
1632
1070
|
};
|
|
1633
1071
|
} catch (error) {
|
|
1634
|
-
|
|
1072
|
+
this.logError("取消本地订单失败:", error);
|
|
1635
1073
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
|
1636
1074
|
return {
|
|
1637
1075
|
success: false,
|
|
@@ -1656,7 +1094,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1656
1094
|
}
|
|
1657
1095
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1658
1096
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1659
|
-
|
|
1097
|
+
this.logInfo("开始保存订单并稍后支付:", {
|
|
1660
1098
|
orderUuid,
|
|
1661
1099
|
orderId: currentOrderId,
|
|
1662
1100
|
totalAmount: this.store.currentOrder.total_amount
|
|
@@ -1668,7 +1106,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1668
1106
|
false,
|
|
1669
1107
|
allPaymentItems
|
|
1670
1108
|
);
|
|
1671
|
-
|
|
1109
|
+
this.logInfo("保存订单完成:", {
|
|
1672
1110
|
orderUuid,
|
|
1673
1111
|
oldOrderId: currentOrderId,
|
|
1674
1112
|
syncResult,
|
|
@@ -1676,13 +1114,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1676
1114
|
isOrderSynced: this.store.isOrderSynced,
|
|
1677
1115
|
filteredPaymentsCount: allPaymentItems.length
|
|
1678
1116
|
});
|
|
1679
|
-
const finalOrderId = this.store.currentOrder.order_id;
|
|
1680
|
-
console.log("[Checkout] saveForLaterPaymentAsync 最终状态验证:", {
|
|
1681
|
-
返回的订单ID: syncResult.orderId,
|
|
1682
|
-
存储的订单ID: finalOrderId,
|
|
1683
|
-
是否一致: syncResult.orderId === finalOrderId,
|
|
1684
|
-
同步状态: this.store.isOrderSynced
|
|
1685
|
-
});
|
|
1686
1117
|
return {
|
|
1687
1118
|
success: true,
|
|
1688
1119
|
message: "订单保存成功,可稍后继续支付",
|
|
@@ -1691,7 +1122,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1691
1122
|
response: syncResult.response
|
|
1692
1123
|
};
|
|
1693
1124
|
} catch (error) {
|
|
1694
|
-
|
|
1125
|
+
this.logError("保存订单失败:", error);
|
|
1695
1126
|
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1696
1127
|
return {
|
|
1697
1128
|
success: false,
|
|
@@ -1700,93 +1131,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1700
1131
|
};
|
|
1701
1132
|
}
|
|
1702
1133
|
}
|
|
1703
|
-
/**
|
|
1704
|
-
* 获取当前商店折扣金额
|
|
1705
|
-
*
|
|
1706
|
-
* @returns 当前的商店折扣金额,如果没有则返回0
|
|
1707
|
-
*/
|
|
1708
|
-
getShopDiscount() {
|
|
1709
|
-
var _a;
|
|
1710
|
-
if (((_a = this.store.localOrderData) == null ? void 0 : _a.shop_discount) !== void 0) {
|
|
1711
|
-
return this.store.localOrderData.shop_discount;
|
|
1712
|
-
}
|
|
1713
|
-
if (this.store.cartSummary) {
|
|
1714
|
-
const shopDiscountItem = this.store.cartSummary.find(
|
|
1715
|
-
(item) => item.key === "shop_discount"
|
|
1716
|
-
);
|
|
1717
|
-
if (shopDiscountItem) {
|
|
1718
|
-
return shopDiscountItem.value;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
return 0;
|
|
1722
|
-
}
|
|
1723
|
-
/**
|
|
1724
|
-
* 更新订单商店折扣
|
|
1725
|
-
*
|
|
1726
|
-
* 同时更新cartSummary和localOrderData中的shop_discount值
|
|
1727
|
-
*
|
|
1728
|
-
* @param discountAmount 商店折扣金额
|
|
1729
|
-
*/
|
|
1730
|
-
async updateShopDiscountAsync(discountAmount) {
|
|
1731
|
-
var _a, _b;
|
|
1732
|
-
try {
|
|
1733
|
-
const oldDiscount = this.getShopDiscount();
|
|
1734
|
-
console.log("[Checkout] 更新商店折扣:", {
|
|
1735
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1736
|
-
oldDiscount,
|
|
1737
|
-
newDiscount: discountAmount
|
|
1738
|
-
});
|
|
1739
|
-
if (this.store.cartSummary) {
|
|
1740
|
-
const shopDiscountItem = this.store.cartSummary.find(
|
|
1741
|
-
(item) => item.key === "shop_discount"
|
|
1742
|
-
);
|
|
1743
|
-
if (shopDiscountItem) {
|
|
1744
|
-
shopDiscountItem.value = discountAmount;
|
|
1745
|
-
console.log("[Checkout] cartSummary 中的商店折扣已更新");
|
|
1746
|
-
} else {
|
|
1747
|
-
this.store.cartSummary.push({
|
|
1748
|
-
key: "shop_discount",
|
|
1749
|
-
value: discountAmount,
|
|
1750
|
-
hidden: true,
|
|
1751
|
-
label: "Shop Discount"
|
|
1752
|
-
});
|
|
1753
|
-
console.log("[Checkout] cartSummary 中已添加新的商店折扣项");
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
if (this.store.localOrderData) {
|
|
1757
|
-
this.store.localOrderData.shop_discount = discountAmount;
|
|
1758
|
-
console.log("[Checkout] localOrderData 中的商店折扣已更新");
|
|
1759
|
-
} else {
|
|
1760
|
-
console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
|
|
1761
|
-
}
|
|
1762
|
-
if (this.store.currentOrder && this.store.cartSummary) {
|
|
1763
|
-
const updatedAmountInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
1764
|
-
this.store.cartSummary
|
|
1765
|
-
);
|
|
1766
|
-
console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
|
|
1767
|
-
this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
|
|
1768
|
-
this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
|
|
1769
|
-
}
|
|
1770
|
-
await this.updateStateAmountToRemaining();
|
|
1771
|
-
await this.core.effects.emit(import_types.CheckoutHooks.OnShopDiscountChanged, {
|
|
1772
|
-
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1773
|
-
oldDiscount,
|
|
1774
|
-
newDiscount: discountAmount,
|
|
1775
|
-
timestamp: Date.now()
|
|
1776
|
-
});
|
|
1777
|
-
console.log("[Checkout] 商店折扣更新成功:", {
|
|
1778
|
-
oldDiscount,
|
|
1779
|
-
newDiscount: discountAmount
|
|
1780
|
-
});
|
|
1781
|
-
} catch (error) {
|
|
1782
|
-
console.error("[Checkout] 更新商店折扣失败:", error);
|
|
1783
|
-
await this.handleError(
|
|
1784
|
-
error,
|
|
1785
|
-
import_types.CheckoutErrorType.ValidationFailed
|
|
1786
|
-
);
|
|
1787
|
-
throw error;
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
1134
|
/**
|
|
1791
1135
|
* 更新订单备注
|
|
1792
1136
|
*
|
|
@@ -1842,40 +1186,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1842
1186
|
throw error;
|
|
1843
1187
|
}
|
|
1844
1188
|
}
|
|
1845
|
-
/**
|
|
1846
|
-
* 设置状态
|
|
1847
|
-
*/
|
|
1848
|
-
setStatus(status) {
|
|
1849
|
-
const oldStatus = this.store.status;
|
|
1850
|
-
this.store.status = status;
|
|
1851
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStatusChanged, {
|
|
1852
|
-
oldStatus,
|
|
1853
|
-
newStatus: status,
|
|
1854
|
-
timestamp: Date.now()
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
/**
|
|
1858
|
-
* 设置步骤
|
|
1859
|
-
*/
|
|
1860
|
-
setStep(step) {
|
|
1861
|
-
const oldStep = this.store.step;
|
|
1862
|
-
this.store.step = step;
|
|
1863
|
-
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
1864
|
-
oldStep,
|
|
1865
|
-
newStep: step,
|
|
1866
|
-
timestamp: Date.now()
|
|
1867
|
-
});
|
|
1868
|
-
}
|
|
1869
1189
|
/**
|
|
1870
1190
|
* 处理错误
|
|
1871
1191
|
*/
|
|
1872
1192
|
async handleError(error, type) {
|
|
1873
1193
|
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1874
1194
|
this.store.lastError = checkoutError;
|
|
1875
|
-
this.setStatus(import_types.CheckoutStatus.Error);
|
|
1876
1195
|
await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
|
|
1877
1196
|
error: checkoutError,
|
|
1878
|
-
context: {
|
|
1197
|
+
context: {},
|
|
1879
1198
|
timestamp: Date.now()
|
|
1880
1199
|
});
|
|
1881
1200
|
console.error("[Checkout] 错误:", checkoutError);
|
|
@@ -1885,7 +1204,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1885
1204
|
*/
|
|
1886
1205
|
async handlePaymentSuccess(data) {
|
|
1887
1206
|
var _a;
|
|
1888
|
-
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
1889
1207
|
await this.updateStateAmountToRemaining();
|
|
1890
1208
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
1891
1209
|
orderUuid: data.orderUuid,
|
|
@@ -1923,73 +1241,63 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1923
1241
|
}
|
|
1924
1242
|
/**
|
|
1925
1243
|
* 处理现金支付项的找零逻辑
|
|
1926
|
-
*
|
|
1244
|
+
*
|
|
1927
1245
|
* @param paymentItem 原始支付项
|
|
1928
1246
|
* @returns 处理后的支付项(包含找零信息)
|
|
1929
1247
|
*/
|
|
1930
1248
|
async processCashPaymentItem(paymentItem) {
|
|
1931
|
-
const
|
|
1932
|
-
if (!
|
|
1249
|
+
const cashPayment = (0, import_utils.isCashPayment)(paymentItem.code, paymentItem.type);
|
|
1250
|
+
if (!cashPayment) {
|
|
1933
1251
|
return paymentItem;
|
|
1934
1252
|
}
|
|
1935
1253
|
try {
|
|
1936
1254
|
const remainingAmountStr = await this.calculateRemainingAmountAsync();
|
|
1937
|
-
|
|
1938
|
-
const cashAmount =
|
|
1939
|
-
|
|
1940
|
-
cashAmount,
|
|
1941
|
-
remainingAmount,
|
|
1942
|
-
needsChange: cashAmount > remainingAmount
|
|
1943
|
-
});
|
|
1944
|
-
if (cashAmount <= remainingAmount) {
|
|
1255
|
+
let remainingAmount = new import_decimal.default(remainingAmountStr);
|
|
1256
|
+
const cashAmount = new import_decimal.default(String(paymentItem.amount));
|
|
1257
|
+
if (cashAmount.lte(remainingAmount)) {
|
|
1945
1258
|
return paymentItem;
|
|
1946
1259
|
}
|
|
1947
|
-
const changeAmount = cashAmount
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1260
|
+
const changeAmount = cashAmount.sub(remainingAmount);
|
|
1261
|
+
if (Number(paymentItem.rounding_amount) > 0) {
|
|
1262
|
+
if (Number(paymentItem.rounding_amount) === changeAmount.toNumber()) {
|
|
1263
|
+
return paymentItem;
|
|
1264
|
+
} else {
|
|
1265
|
+
remainingAmount = remainingAmount.add(
|
|
1266
|
+
new import_decimal.default(paymentItem.rounding_amount || "0")
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1953
1270
|
const processedPaymentItem = {
|
|
1954
1271
|
...paymentItem,
|
|
1955
|
-
amount: remainingAmount,
|
|
1956
|
-
// 将 amount
|
|
1272
|
+
amount: remainingAmount.toFixed(2),
|
|
1273
|
+
// 将 amount 设置为剩余待付金额,保留2位小数
|
|
1957
1274
|
metadata: {
|
|
1958
1275
|
...paymentItem.metadata,
|
|
1959
|
-
actual_paid_amount: cashAmount,
|
|
1276
|
+
actual_paid_amount: cashAmount.toNumber(),
|
|
1960
1277
|
// 实付金额
|
|
1961
|
-
change_given_amount: changeAmount
|
|
1278
|
+
change_given_amount: changeAmount.toNumber()
|
|
1962
1279
|
// 找零金额
|
|
1963
1280
|
}
|
|
1964
1281
|
};
|
|
1965
1282
|
this.logInfo("Cash payment with change processed", {
|
|
1966
|
-
originalAmount: cashAmount,
|
|
1967
|
-
chargedAmount: remainingAmount,
|
|
1968
|
-
changeAmount,
|
|
1283
|
+
originalAmount: cashAmount.toFixed(2),
|
|
1284
|
+
chargedAmount: remainingAmount.toFixed(2),
|
|
1285
|
+
changeAmount: changeAmount.toFixed(2),
|
|
1969
1286
|
paymentCode: paymentItem.code,
|
|
1970
|
-
paymentType: paymentItem.type
|
|
1287
|
+
paymentType: paymentItem.type,
|
|
1288
|
+
// 额外的精度验证信息
|
|
1289
|
+
decimalPrecisionCheck: {
|
|
1290
|
+
cashAmountPrecise: cashAmount.toString(),
|
|
1291
|
+
remainingAmountPrecise: remainingAmount.toString(),
|
|
1292
|
+
changeAmountPrecise: changeAmount.toString()
|
|
1293
|
+
}
|
|
1971
1294
|
});
|
|
1972
1295
|
return processedPaymentItem;
|
|
1973
1296
|
} catch (error) {
|
|
1974
|
-
|
|
1297
|
+
this.logError("处理现金支付项时出错:", error);
|
|
1975
1298
|
return paymentItem;
|
|
1976
1299
|
}
|
|
1977
1300
|
}
|
|
1978
|
-
/**
|
|
1979
|
-
* 判断是否为现金支付
|
|
1980
|
-
*
|
|
1981
|
-
* @param paymentCode 支付代码
|
|
1982
|
-
* @param paymentType 支付类型
|
|
1983
|
-
* @returns 是否为现金支付
|
|
1984
|
-
*/
|
|
1985
|
-
isCashPayment(paymentCode, paymentType) {
|
|
1986
|
-
const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
|
|
1987
|
-
const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
|
|
1988
|
-
const cashIdentifiers = ["CASH", "CASHMANUAL", "MANUAL"];
|
|
1989
|
-
return cashIdentifiers.some(
|
|
1990
|
-
(identifier) => codeUpper.includes(identifier) || typeUpper.includes(identifier)
|
|
1991
|
-
);
|
|
1992
|
-
}
|
|
1993
1301
|
/**
|
|
1994
1302
|
* 预加载支付方式(在初始化时调用)
|
|
1995
1303
|
*/
|
|
@@ -2006,7 +1314,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2006
1314
|
}
|
|
2007
1315
|
/**
|
|
2008
1316
|
* 清理过期的已同步订单数据
|
|
2009
|
-
*
|
|
1317
|
+
*
|
|
2010
1318
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
2011
1319
|
*/
|
|
2012
1320
|
async cleanupExpiredOrdersAsync() {
|
|
@@ -2020,7 +1328,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2020
1328
|
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
2021
1329
|
return;
|
|
2022
1330
|
}
|
|
2023
|
-
console.log(
|
|
1331
|
+
console.log(
|
|
1332
|
+
`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`
|
|
1333
|
+
);
|
|
2024
1334
|
const allOrders = await this.payment.getOrderListAsync();
|
|
2025
1335
|
if (!allOrders || allOrders.length === 0) {
|
|
2026
1336
|
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
@@ -2040,7 +1350,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2040
1350
|
if ((_a = order.order_info) == null ? void 0 : _a.created_at) {
|
|
2041
1351
|
orderCreatedAt = new Date(order.order_info.created_at);
|
|
2042
1352
|
} else if ((_c = (_b = order.order_info) == null ? void 0 : _b.original_order_data) == null ? void 0 : _c.created_at) {
|
|
2043
|
-
orderCreatedAt = new Date(
|
|
1353
|
+
orderCreatedAt = new Date(
|
|
1354
|
+
order.order_info.original_order_data.created_at
|
|
1355
|
+
);
|
|
2044
1356
|
}
|
|
2045
1357
|
if (!orderCreatedAt || isNaN(orderCreatedAt.getTime())) {
|
|
2046
1358
|
continue;
|
|
@@ -2050,7 +1362,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2050
1362
|
uuid: order.uuid,
|
|
2051
1363
|
orderId: order.order_id,
|
|
2052
1364
|
createdAt: orderCreatedAt.toISOString(),
|
|
2053
|
-
daysSinceCreated: Math.floor(
|
|
1365
|
+
daysSinceCreated: Math.floor(
|
|
1366
|
+
(Date.now() - orderCreatedAt.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1367
|
+
)
|
|
2054
1368
|
});
|
|
2055
1369
|
}
|
|
2056
1370
|
} catch (error) {
|
|
@@ -2058,13 +1372,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2058
1372
|
continue;
|
|
2059
1373
|
}
|
|
2060
1374
|
}
|
|
2061
|
-
ordersToDelete.sort(
|
|
1375
|
+
ordersToDelete.sort(
|
|
1376
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
1377
|
+
);
|
|
2062
1378
|
const actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete);
|
|
2063
1379
|
for (const orderInfo of actualOrdersToDelete) {
|
|
2064
1380
|
try {
|
|
2065
1381
|
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
2066
1382
|
deletedCount++;
|
|
2067
|
-
console.log(
|
|
1383
|
+
console.log(
|
|
1384
|
+
`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`
|
|
1385
|
+
);
|
|
2068
1386
|
} catch (error) {
|
|
2069
1387
|
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
2070
1388
|
}
|
|
@@ -2081,9 +1399,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2081
1399
|
};
|
|
2082
1400
|
this.logInfo("Expired orders cleanup completed", summary);
|
|
2083
1401
|
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
2084
|
-
console.log(
|
|
1402
|
+
console.log(
|
|
1403
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`
|
|
1404
|
+
);
|
|
2085
1405
|
} else {
|
|
2086
|
-
console.log(
|
|
1406
|
+
console.log(
|
|
1407
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`
|
|
1408
|
+
);
|
|
2087
1409
|
}
|
|
2088
1410
|
} catch (error) {
|
|
2089
1411
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -2096,7 +1418,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2096
1418
|
*/
|
|
2097
1419
|
async calculatePaidAmountAsync() {
|
|
2098
1420
|
if (!this.store.currentOrder) {
|
|
2099
|
-
|
|
1421
|
+
this.logWarning("[Checkout] calculatePaidAmountAsync: 没有当前订单");
|
|
2100
1422
|
return "0.00";
|
|
2101
1423
|
}
|
|
2102
1424
|
try {
|
|
@@ -2105,33 +1427,29 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2105
1427
|
false
|
|
2106
1428
|
// 不包括已撤销的支付项
|
|
2107
1429
|
);
|
|
2108
|
-
console.log("[Checkout] calculatePaidAmountAsync: 支付项详情:", {
|
|
2109
|
-
paymentCount: payments.length,
|
|
2110
|
-
payments: payments.map((p) => ({
|
|
2111
|
-
uuid: p.uuid,
|
|
2112
|
-
amount: p.amount,
|
|
2113
|
-
code: p.code,
|
|
2114
|
-
status: p.status,
|
|
2115
|
-
rounding_amount: p.rounding_amount
|
|
2116
|
-
}))
|
|
2117
|
-
});
|
|
2118
1430
|
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
2119
|
-
const amount =
|
|
2120
|
-
const roundingAmount =
|
|
2121
|
-
const effectiveAmount = amount
|
|
1431
|
+
const amount = new import_decimal.default(payment.amount || "0");
|
|
1432
|
+
const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
|
|
1433
|
+
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
2122
1434
|
console.log(`[Checkout] 计算支付项: ${payment.code}`, {
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
1435
|
+
originalAmount: amount.toFixed(2),
|
|
1436
|
+
roundingAmount: roundingAmount.toFixed(2),
|
|
1437
|
+
effectiveAmount: effectiveAmount.toFixed(2),
|
|
1438
|
+
description: !roundingAmount.isZero() ? `抹零金额 ${roundingAmount.toFixed(2)} 元,有效支付增加 ${roundingAmount.abs().toFixed(2)} 元` : "无抹零",
|
|
1439
|
+
// Decimal 精度验证
|
|
1440
|
+
preciseCalculationValues: {
|
|
1441
|
+
amount: amount.toString(),
|
|
1442
|
+
roundingAmount: roundingAmount.toString(),
|
|
1443
|
+
effectiveAmount: effectiveAmount.toString()
|
|
1444
|
+
}
|
|
2127
1445
|
});
|
|
2128
|
-
return sum
|
|
2129
|
-
}, 0);
|
|
1446
|
+
return sum.add(effectiveAmount);
|
|
1447
|
+
}, new import_decimal.default(0));
|
|
2130
1448
|
const result = paidAmount.toFixed(2);
|
|
2131
|
-
|
|
1449
|
+
this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
|
|
2132
1450
|
return result;
|
|
2133
1451
|
} catch (error) {
|
|
2134
|
-
|
|
1452
|
+
this.logError("calculatePaidAmountAsync 失败:", error);
|
|
2135
1453
|
return "0.00";
|
|
2136
1454
|
}
|
|
2137
1455
|
}
|
|
@@ -2140,37 +1458,26 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2140
1458
|
*/
|
|
2141
1459
|
async calculateRemainingAmountAsync() {
|
|
2142
1460
|
if (!this.store.currentOrder) {
|
|
2143
|
-
|
|
1461
|
+
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
2144
1462
|
return "0.00";
|
|
2145
1463
|
}
|
|
2146
|
-
const totalAmount =
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
const
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
calculatedRemaining: remainingAmount.toFixed(2),
|
|
2155
|
-
finalResult: result,
|
|
2156
|
-
说明: "已支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
2157
|
-
});
|
|
1464
|
+
const totalAmount = new import_decimal.default(
|
|
1465
|
+
this.store.currentOrder.total_amount || "0"
|
|
1466
|
+
);
|
|
1467
|
+
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
1468
|
+
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
1469
|
+
const remainingAmount = totalAmount.sub(paidAmount);
|
|
1470
|
+
const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
1471
|
+
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
2158
1472
|
return result;
|
|
2159
1473
|
}
|
|
2160
1474
|
/**
|
|
2161
1475
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
2162
1476
|
*/
|
|
2163
1477
|
async updateBalanceDueAmount() {
|
|
2164
|
-
var _a;
|
|
2165
1478
|
try {
|
|
2166
1479
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2167
1480
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
2168
|
-
console.log("[Checkout] updateBalanceDueAmount: 状态检查:", {
|
|
2169
|
-
calculatedRemainingAmount: remainingAmount,
|
|
2170
|
-
currentBalanceDueAmount,
|
|
2171
|
-
needsUpdate: remainingAmount !== currentBalanceDueAmount,
|
|
2172
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
2173
|
-
});
|
|
2174
1481
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
2175
1482
|
this.store.balanceDueAmount = remainingAmount;
|
|
2176
1483
|
await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
|
|
@@ -2178,34 +1485,27 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2178
1485
|
newAmount: remainingAmount,
|
|
2179
1486
|
timestamp: Date.now()
|
|
2180
1487
|
});
|
|
2181
|
-
|
|
1488
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
2182
1489
|
oldAmount: currentBalanceDueAmount,
|
|
2183
1490
|
newAmount: remainingAmount
|
|
2184
1491
|
});
|
|
2185
1492
|
} else {
|
|
2186
|
-
|
|
1493
|
+
this.logInfo("balanceDueAmount 无需更新,当前值已是最新:", {
|
|
2187
1494
|
balanceDueAmount: currentBalanceDueAmount,
|
|
2188
1495
|
remainingAmount
|
|
2189
1496
|
});
|
|
2190
1497
|
}
|
|
2191
1498
|
} catch (error) {
|
|
2192
|
-
|
|
1499
|
+
this.logError("更新 balanceDueAmount 失败:", error);
|
|
2193
1500
|
}
|
|
2194
1501
|
}
|
|
2195
1502
|
/**
|
|
2196
1503
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
2197
1504
|
*/
|
|
2198
1505
|
async updateStateAmountToRemaining() {
|
|
2199
|
-
var _a;
|
|
2200
1506
|
try {
|
|
2201
1507
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2202
1508
|
const currentStateAmount = this.store.stateAmount;
|
|
2203
|
-
console.log("[Checkout] updateStateAmountToRemaining: 状态检查:", {
|
|
2204
|
-
calculatedRemainingAmount: remainingAmount,
|
|
2205
|
-
currentStateAmount,
|
|
2206
|
-
needsUpdate: remainingAmount !== currentStateAmount,
|
|
2207
|
-
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
2208
|
-
});
|
|
2209
1509
|
if (remainingAmount !== currentStateAmount) {
|
|
2210
1510
|
this.store.stateAmount = remainingAmount;
|
|
2211
1511
|
this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
@@ -2213,12 +1513,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2213
1513
|
newAmount: remainingAmount,
|
|
2214
1514
|
timestamp: Date.now()
|
|
2215
1515
|
});
|
|
2216
|
-
|
|
1516
|
+
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
2217
1517
|
oldAmount: currentStateAmount,
|
|
2218
1518
|
newAmount: remainingAmount
|
|
2219
1519
|
});
|
|
2220
1520
|
} else {
|
|
2221
|
-
|
|
1521
|
+
this.logInfo("stateAmount 无需更新,当前值已是最新:", {
|
|
2222
1522
|
stateAmount: currentStateAmount,
|
|
2223
1523
|
remainingAmount
|
|
2224
1524
|
});
|
|
@@ -2226,7 +1526,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2226
1526
|
await this.updateBalanceDueAmount();
|
|
2227
1527
|
await this.checkOrderPaymentCompletion();
|
|
2228
1528
|
} catch (error) {
|
|
2229
|
-
|
|
1529
|
+
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
2230
1530
|
}
|
|
2231
1531
|
}
|
|
2232
1532
|
/**
|
|
@@ -2240,11 +1540,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2240
1540
|
return;
|
|
2241
1541
|
}
|
|
2242
1542
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2243
|
-
const remainingValue =
|
|
2244
|
-
if (remainingValue
|
|
1543
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
1544
|
+
if (remainingValue.lte(0)) {
|
|
2245
1545
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
2246
1546
|
const paidAmount = await this.calculatePaidAmountAsync();
|
|
2247
|
-
|
|
1547
|
+
this.logInfo("检测到订单支付完成:", {
|
|
2248
1548
|
orderUuid: this.store.currentOrder.uuid,
|
|
2249
1549
|
orderId: this.store.currentOrder.order_id,
|
|
2250
1550
|
totalAmount,
|
|
@@ -2262,7 +1562,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2262
1562
|
(item) => item.status !== "voided" && item.voucher_id
|
|
2263
1563
|
);
|
|
2264
1564
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
2265
|
-
|
|
1565
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
2266
1566
|
paymentCount: currentPayments.length,
|
|
2267
1567
|
hasPaymentItems,
|
|
2268
1568
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
@@ -2280,13 +1580,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2280
1580
|
}))
|
|
2281
1581
|
});
|
|
2282
1582
|
if (shouldAutoSync) {
|
|
2283
|
-
|
|
2284
|
-
await this.
|
|
1583
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
1584
|
+
await this.syncOrderToBackendWithReturn(false);
|
|
2285
1585
|
} else {
|
|
2286
1586
|
if (!hasPaymentItems) {
|
|
2287
|
-
|
|
1587
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
2288
1588
|
} else if (allPaymentsHaveVoucherId) {
|
|
2289
|
-
|
|
1589
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
2290
1590
|
}
|
|
2291
1591
|
}
|
|
2292
1592
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
|
|
@@ -2299,14 +1599,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2299
1599
|
});
|
|
2300
1600
|
}
|
|
2301
1601
|
} catch (error) {
|
|
2302
|
-
|
|
1602
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2303
1603
|
}
|
|
2304
1604
|
}
|
|
2305
|
-
/**
|
|
2306
|
-
* 同步订单到后端
|
|
2307
|
-
*
|
|
2308
|
-
* 调用后端 /order/checkout 接口创建真实订单
|
|
2309
|
-
*/
|
|
2310
1605
|
/**
|
|
2311
1606
|
* 同步订单到后端并返回真实订单ID
|
|
2312
1607
|
*
|
|
@@ -2315,72 +1610,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2315
1610
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
2316
1611
|
*/
|
|
2317
1612
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2318
|
-
var _a, _b, _c, _d, _e
|
|
1613
|
+
var _a, _b, _c, _d, _e;
|
|
2319
1614
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2320
1615
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2321
1616
|
}
|
|
2322
|
-
this.logInfo("syncOrderToBackendWithReturn called", {
|
|
2323
|
-
isManual,
|
|
2324
|
-
hasCustomPaymentItems: !!customPaymentItems,
|
|
2325
|
-
customPaymentItemsCount: (customPaymentItems == null ? void 0 : customPaymentItems.length) || 0,
|
|
2326
|
-
currentOrderId: this.store.currentOrder.order_id,
|
|
2327
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2328
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2329
|
-
isVirtualOrderId: (0, import_utils.isVirtualOrderId)(this.store.currentOrder.order_id),
|
|
2330
|
-
localOrderDataType: this.store.localOrderData.type,
|
|
2331
|
-
platform: this.store.localOrderData.platform,
|
|
2332
|
-
customerId: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id
|
|
2333
|
-
});
|
|
2334
|
-
const syncType = isManual ? "手动" : "自动";
|
|
1617
|
+
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2335
1618
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
2336
|
-
const
|
|
2337
|
-
|
|
2338
|
-
let reason = "";
|
|
2339
|
-
if (this.store.isOrderSynced) {
|
|
2340
|
-
isUpdateOperation = true;
|
|
2341
|
-
reason = "订单已同步过";
|
|
2342
|
-
} else if (hasRealOrderId) {
|
|
2343
|
-
isUpdateOperation = true;
|
|
2344
|
-
reason = "有真实订单ID";
|
|
2345
|
-
} else {
|
|
2346
|
-
isUpdateOperation = false;
|
|
2347
|
-
reason = "既未同步也无真实ID";
|
|
2348
|
-
}
|
|
2349
|
-
const operation = isUpdateOperation ? "更新" : "创建";
|
|
2350
|
-
console.log("[Checkout] 操作类型判断详情:", {
|
|
2351
|
-
currentOrderId,
|
|
2352
|
-
hasRealOrderId,
|
|
2353
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2354
|
-
isManual,
|
|
2355
|
-
reason,
|
|
2356
|
-
finalDecision: operation
|
|
2357
|
-
});
|
|
2358
|
-
console.log(`[Checkout] 开始${syncType}${operation}订单到后端...`, {
|
|
1619
|
+
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1620
|
+
this.logInfo(`开始同步订单到后端...`, {
|
|
2359
1621
|
currentOrderId,
|
|
2360
1622
|
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2361
|
-
operation,
|
|
2362
1623
|
orderUuid: this.store.currentOrder.uuid,
|
|
2363
|
-
isOrderSynced: this.store.isOrderSynced
|
|
1624
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1625
|
+
isManual
|
|
2364
1626
|
});
|
|
2365
1627
|
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2366
|
-
console.log("[Checkout] 获取到支付项:", {
|
|
2367
|
-
count: paymentItems.length,
|
|
2368
|
-
isCustomFiltered: !!customPaymentItems,
|
|
2369
|
-
methods: paymentItems.map((p) => p.code),
|
|
2370
|
-
totalAmount: paymentItems.reduce((sum, p) => sum + parseFloat(p.amount), 0).toFixed(2),
|
|
2371
|
-
paymentDetails: paymentItems.map((p) => {
|
|
2372
|
-
var _a2;
|
|
2373
|
-
return {
|
|
2374
|
-
uuid: p.uuid,
|
|
2375
|
-
code: p.code,
|
|
2376
|
-
amount: p.amount,
|
|
2377
|
-
uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
|
|
2378
|
-
voucherId: p.voucher_id,
|
|
2379
|
-
orderPaymentType: p.order_payment_type,
|
|
2380
|
-
metadata: p.metadata
|
|
2381
|
-
};
|
|
2382
|
-
})
|
|
2383
|
-
});
|
|
2384
1628
|
const processedPaymentItems = paymentItems.map((item) => {
|
|
2385
1629
|
var _a2, _b2;
|
|
2386
1630
|
return {
|
|
@@ -2392,31 +1636,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2392
1636
|
}
|
|
2393
1637
|
};
|
|
2394
1638
|
});
|
|
2395
|
-
console.log("[Checkout] 处理后的支付项数据(包含完整metadata):", {
|
|
2396
|
-
originalCount: paymentItems.length,
|
|
2397
|
-
processedCount: processedPaymentItems.length,
|
|
2398
|
-
sampleMetadata: (_b = processedPaymentItems[0]) == null ? void 0 : _b.metadata,
|
|
2399
|
-
allPaymentItems: processedPaymentItems.map((p) => {
|
|
2400
|
-
var _a2, _b2;
|
|
2401
|
-
return {
|
|
2402
|
-
code: p.code,
|
|
2403
|
-
amount: p.amount,
|
|
2404
|
-
voucherId: p.voucher_id,
|
|
2405
|
-
orderPaymentType: p.order_payment_type,
|
|
2406
|
-
metadata: p.metadata,
|
|
2407
|
-
// 现金支付找零信息
|
|
2408
|
-
actualPaidAmount: (_a2 = p.metadata) == null ? void 0 : _a2.actual_paid_amount,
|
|
2409
|
-
changeGivenAmount: (_b2 = p.metadata) == null ? void 0 : _b2.change_given_amount
|
|
2410
|
-
};
|
|
2411
|
-
})
|
|
2412
|
-
});
|
|
2413
1639
|
const orderParams = {
|
|
2414
1640
|
...this.store.localOrderData,
|
|
2415
1641
|
type: this.store.localOrderData.type,
|
|
2416
1642
|
platform: this.store.localOrderData.platform,
|
|
2417
1643
|
payments: processedPaymentItems,
|
|
2418
1644
|
// 使用处理过的支付项数据
|
|
2419
|
-
customer_id: (
|
|
1645
|
+
customer_id: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id,
|
|
2420
1646
|
// 添加客户ID
|
|
2421
1647
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2422
1648
|
// core 有
|
|
@@ -2429,35 +1655,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2429
1655
|
currency_code: this.otherParams.currency_code,
|
|
2430
1656
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2431
1657
|
currency_format: this.otherParams.currency_format,
|
|
2432
|
-
is_deposit: ((
|
|
2433
|
-
deposit_amount: ((
|
|
2434
|
-
// surcharge_fee: this.otherParams.surcharge_fee,
|
|
2435
|
-
// surcharges: ,
|
|
1658
|
+
is_deposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0,
|
|
1659
|
+
deposit_amount: ((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount) || "0.00",
|
|
2436
1660
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
2437
1661
|
note: this.store.localOrderData.shop_note
|
|
2438
|
-
// deposit_amount:
|
|
2439
1662
|
};
|
|
2440
1663
|
if (isUpdateOperation) {
|
|
2441
1664
|
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2442
|
-
|
|
2443
|
-
"
|
|
2444
|
-
{
|
|
2445
|
-
currentOrderId,
|
|
2446
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2447
|
-
reason,
|
|
2448
|
-
orderUuid: this.store.currentOrder.uuid
|
|
2449
|
-
}
|
|
2450
|
-
);
|
|
2451
|
-
console.log("[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理");
|
|
2452
|
-
console.log(
|
|
2453
|
-
"[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
1665
|
+
this.logWarning(
|
|
1666
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2454
1667
|
);
|
|
2455
1668
|
} else {
|
|
2456
1669
|
orderParams.order_id = currentOrderId;
|
|
2457
|
-
console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
|
|
2458
1670
|
}
|
|
2459
|
-
} else {
|
|
2460
|
-
console.log("[Checkout] 创建新订单操作");
|
|
2461
1671
|
}
|
|
2462
1672
|
const startTime = Date.now();
|
|
2463
1673
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitStart, {
|
|
@@ -2473,29 +1683,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2473
1683
|
try {
|
|
2474
1684
|
this.logInfo("Calling backend checkout API", {
|
|
2475
1685
|
url: "/order/checkout",
|
|
2476
|
-
operation,
|
|
2477
1686
|
isManual,
|
|
2478
|
-
|
|
2479
|
-
platform: orderParams.platform,
|
|
2480
|
-
customerId: orderParams.customer_id,
|
|
2481
|
-
isDeposit: orderParams.is_deposit,
|
|
2482
|
-
depositAmount: orderParams.deposit_amount,
|
|
2483
|
-
bookingsCount: ((_f = orderParams.bookings) == null ? void 0 : _f.length) || 0,
|
|
2484
|
-
relationProductsCount: ((_g = orderParams.relation_products) == null ? void 0 : _g.length) || 0,
|
|
2485
|
-
paymentsCount: ((_h = orderParams.payments) == null ? void 0 : _h.length) || 0,
|
|
2486
|
-
paymentMethods: ((_i = orderParams.payments) == null ? void 0 : _i.map((p) => p.code)) || [],
|
|
2487
|
-
hasOrderId: !!orderParams.order_id,
|
|
2488
|
-
orderIdIncluded: orderParams.order_id,
|
|
2489
|
-
productTaxFee: orderParams.product_tax_fee,
|
|
2490
|
-
note: orderParams.note,
|
|
2491
|
-
scheduleDate: orderParams.schedule_date
|
|
1687
|
+
...orderParams
|
|
2492
1688
|
});
|
|
2493
1689
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2494
1690
|
submitSuccess = true;
|
|
2495
|
-
|
|
1691
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2496
1692
|
} catch (error) {
|
|
2497
1693
|
submitSuccess = false;
|
|
2498
1694
|
submitError = error instanceof Error ? error.message : String(error);
|
|
1695
|
+
this.logError("下单接口调用失败:", submitError);
|
|
2499
1696
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2500
1697
|
orderUuid: this.store.currentOrder.uuid,
|
|
2501
1698
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2512,29 +1709,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2512
1709
|
orderUuid: this.store.currentOrder.uuid,
|
|
2513
1710
|
operation: isUpdateOperation ? "update" : "create",
|
|
2514
1711
|
isManual,
|
|
2515
|
-
orderId: submitSuccess ? ((
|
|
1712
|
+
orderId: submitSuccess ? ((_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2516
1713
|
error: submitError,
|
|
2517
1714
|
duration: Date.now() - startTime,
|
|
2518
1715
|
timestamp: Date.now()
|
|
2519
1716
|
});
|
|
2520
1717
|
}
|
|
2521
|
-
console.log("[Checkout] 后端返回的响应数据:", {
|
|
2522
|
-
status: checkoutResponse == null ? void 0 : checkoutResponse.status,
|
|
2523
|
-
code: checkoutResponse == null ? void 0 : checkoutResponse.code,
|
|
2524
|
-
message: checkoutResponse == null ? void 0 : checkoutResponse.message,
|
|
2525
|
-
data: checkoutResponse == null ? void 0 : checkoutResponse.data
|
|
2526
|
-
});
|
|
2527
1718
|
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2528
1719
|
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2529
1720
|
if (!isSuccessResponse) {
|
|
2530
1721
|
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
2531
|
-
console.error("[Checkout] 订单同步失败,响应状态检查未通过:", {
|
|
2532
|
-
expectedSuccess: true,
|
|
2533
|
-
actualStatus: responseStatus,
|
|
2534
|
-
code: checkoutResponse == null ? void 0 : checkoutResponse.code,
|
|
2535
|
-
message: checkoutResponse == null ? void 0 : checkoutResponse.message,
|
|
2536
|
-
errorMessage
|
|
2537
|
-
});
|
|
2538
1722
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
|
|
2539
1723
|
orderUuid: this.store.currentOrder.uuid,
|
|
2540
1724
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2547,13 +1731,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2547
1731
|
});
|
|
2548
1732
|
throw new Error(errorMessage);
|
|
2549
1733
|
}
|
|
2550
|
-
console.log("[Checkout] 响应状态检查通过,开始处理订单数据");
|
|
2551
1734
|
let realOrderId;
|
|
2552
1735
|
if (isUpdateOperation) {
|
|
2553
1736
|
realOrderId = currentOrderId;
|
|
2554
|
-
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
2555
1737
|
} else {
|
|
2556
|
-
let extractedOrderId = (
|
|
1738
|
+
let extractedOrderId = (_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id;
|
|
2557
1739
|
if (!extractedOrderId) {
|
|
2558
1740
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2559
1741
|
}
|
|
@@ -2561,11 +1743,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2561
1743
|
extractedOrderId = String(extractedOrderId);
|
|
2562
1744
|
}
|
|
2563
1745
|
if (!extractedOrderId) {
|
|
2564
|
-
|
|
1746
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
2565
1747
|
}
|
|
2566
1748
|
realOrderId = extractedOrderId;
|
|
2567
|
-
|
|
2568
|
-
console.log("[Checkout] 准备替换订单ID:", {
|
|
1749
|
+
this.logInfo("准备替换订单ID:", {
|
|
2569
1750
|
orderUuid: this.store.currentOrder.uuid,
|
|
2570
1751
|
oldOrderId: this.store.currentOrder.order_id,
|
|
2571
1752
|
newOrderId: realOrderId
|
|
@@ -2575,38 +1756,38 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2575
1756
|
this.store.currentOrder.uuid,
|
|
2576
1757
|
realOrderId
|
|
2577
1758
|
);
|
|
2578
|
-
|
|
1759
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
2579
1760
|
wasSuccessful: !!updatedOrder,
|
|
2580
1761
|
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2581
1762
|
expectedOrderId: realOrderId
|
|
2582
1763
|
});
|
|
2583
1764
|
if (updatedOrder) {
|
|
2584
|
-
|
|
1765
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
2585
1766
|
uuid: updatedOrder.uuid,
|
|
2586
1767
|
orderId: updatedOrder.order_id,
|
|
2587
1768
|
totalAmount: updatedOrder.total_amount
|
|
2588
1769
|
});
|
|
2589
1770
|
this.store.currentOrder = updatedOrder;
|
|
2590
|
-
|
|
1771
|
+
this.logInfo(
|
|
2591
1772
|
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2592
1773
|
this.store.currentOrder.order_id
|
|
2593
1774
|
);
|
|
2594
1775
|
} else {
|
|
2595
|
-
|
|
1776
|
+
this.logError(
|
|
2596
1777
|
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2597
1778
|
);
|
|
2598
1779
|
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2599
1780
|
this.store.currentOrder.order_id = realOrderId;
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
1781
|
+
this.logInfo("手动设置订单ID:", {
|
|
1782
|
+
beforeReplacement: beforeManualUpdate,
|
|
1783
|
+
afterReplacement: this.store.currentOrder.order_id,
|
|
2603
1784
|
目标ID: realOrderId
|
|
2604
1785
|
});
|
|
2605
1786
|
}
|
|
2606
1787
|
} catch (error) {
|
|
2607
|
-
|
|
1788
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2608
1789
|
this.store.currentOrder.order_id = realOrderId;
|
|
2609
|
-
|
|
1790
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2610
1791
|
}
|
|
2611
1792
|
}
|
|
2612
1793
|
this.store.isOrderSynced = true;
|
|
@@ -2618,69 +1799,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2618
1799
|
isManual,
|
|
2619
1800
|
response: checkoutResponse
|
|
2620
1801
|
});
|
|
2621
|
-
const finalOrderId = this.store.currentOrder.order_id;
|
|
2622
|
-
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId || "");
|
|
2623
|
-
console.log(`[Checkout] ${syncType}${operation}订单到后端完成`, {
|
|
2624
|
-
返回的订单ID: realOrderId,
|
|
2625
|
-
当前存储的订单ID: finalOrderId,
|
|
2626
|
-
是否还是虚拟ID: finalIsVirtual,
|
|
2627
|
-
是否同步: this.store.isOrderSynced
|
|
2628
|
-
});
|
|
2629
|
-
if (finalIsVirtual && !isUpdateOperation) {
|
|
2630
|
-
console.warn(
|
|
2631
|
-
"[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题"
|
|
2632
|
-
);
|
|
2633
|
-
}
|
|
2634
1802
|
return {
|
|
2635
1803
|
success: true,
|
|
2636
|
-
message: `订单${operation}成功`,
|
|
2637
1804
|
orderId: realOrderId,
|
|
2638
1805
|
orderUuid: this.store.currentOrder.uuid,
|
|
2639
1806
|
response: checkoutResponse
|
|
2640
1807
|
};
|
|
2641
1808
|
}
|
|
2642
|
-
async syncOrderToBackend() {
|
|
2643
|
-
try {
|
|
2644
|
-
const syncResult = await this.syncOrderToBackendWithReturn(false);
|
|
2645
|
-
console.log("[Checkout] 自动同步订单完成:", syncResult);
|
|
2646
|
-
} catch (error) {
|
|
2647
|
-
console.error("[Checkout] 同步订单到后端失败:", error);
|
|
2648
|
-
await this.handleError(
|
|
2649
|
-
new Error(
|
|
2650
|
-
`订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
2651
|
-
),
|
|
2652
|
-
import_types.CheckoutErrorType.OrderCreationFailed
|
|
2653
|
-
);
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
/**
|
|
2657
|
-
* 获取状态消息
|
|
2658
|
-
*/
|
|
2659
|
-
getStatusMessage() {
|
|
2660
|
-
var _a;
|
|
2661
|
-
switch (this.store.status) {
|
|
2662
|
-
case import_types.CheckoutStatus.Initializing:
|
|
2663
|
-
return "正在初始化结账流程...";
|
|
2664
|
-
case import_types.CheckoutStatus.Ready:
|
|
2665
|
-
return "准备就绪,可以开始结账";
|
|
2666
|
-
case import_types.CheckoutStatus.CreatingOrder:
|
|
2667
|
-
return "正在创建订单...";
|
|
2668
|
-
case import_types.CheckoutStatus.OrderCreated:
|
|
2669
|
-
return "订单创建成功,请选择支付方式";
|
|
2670
|
-
case import_types.CheckoutStatus.ProcessingPayment:
|
|
2671
|
-
return "正在处理支付...";
|
|
2672
|
-
case import_types.CheckoutStatus.PaymentCompleted:
|
|
2673
|
-
return "支付完成";
|
|
2674
|
-
case import_types.CheckoutStatus.Completed:
|
|
2675
|
-
return "结账完成";
|
|
2676
|
-
case import_types.CheckoutStatus.Cancelled:
|
|
2677
|
-
return "结账已取消";
|
|
2678
|
-
case import_types.CheckoutStatus.Error:
|
|
2679
|
-
return ((_a = this.store.lastError) == null ? void 0 : _a.message) || "发生未知错误";
|
|
2680
|
-
default:
|
|
2681
|
-
return "";
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
1809
|
async setOtherParams(params, { cover = false } = {}) {
|
|
2685
1810
|
if (cover) {
|
|
2686
1811
|
this.otherParams = params;
|
|
@@ -2701,15 +1826,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2701
1826
|
this.logInfo("editOrderNoteByOrderIdAsync called", {
|
|
2702
1827
|
orderId,
|
|
2703
1828
|
note,
|
|
2704
|
-
noteLength: note.length
|
|
2705
|
-
isCurrentOrder: this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))
|
|
1829
|
+
noteLength: note.length
|
|
2706
1830
|
});
|
|
2707
1831
|
try {
|
|
2708
|
-
console.log("[Checkout] 开始编辑订单备注:", {
|
|
2709
|
-
orderId,
|
|
2710
|
-
note,
|
|
2711
|
-
noteLength: note.length
|
|
2712
|
-
});
|
|
2713
1832
|
if (!orderId) {
|
|
2714
1833
|
return {
|
|
2715
1834
|
success: false,
|
|
@@ -2724,22 +1843,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2724
1843
|
note,
|
|
2725
1844
|
noteLength: note.length
|
|
2726
1845
|
});
|
|
2727
|
-
const response = await this.request.put(
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}
|
|
2732
|
-
);
|
|
2733
|
-
console.log("[Checkout] 订单备注编辑响应:", {
|
|
1846
|
+
const response = await this.request.put(`/order/order/${orderId}/note`, {
|
|
1847
|
+
note
|
|
1848
|
+
});
|
|
1849
|
+
this.logInfo("订单备注编辑响应:", {
|
|
2734
1850
|
orderId,
|
|
2735
1851
|
status: response.status,
|
|
2736
1852
|
message: response.message,
|
|
2737
1853
|
response
|
|
2738
1854
|
});
|
|
2739
1855
|
if (response.status === true || response.status === 200) {
|
|
2740
|
-
console.log(`[Checkout] 订单 ${orderId} 备注修改成功`);
|
|
2741
1856
|
if (this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))) {
|
|
2742
|
-
console.log("[Checkout] 更新本地订单备注状态");
|
|
2743
1857
|
const previousNote = this.getOrderNote();
|
|
2744
1858
|
if (this.store.localOrderData) {
|
|
2745
1859
|
this.store.localOrderData.shop_note = note;
|
|
@@ -2758,7 +1872,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2758
1872
|
};
|
|
2759
1873
|
} else {
|
|
2760
1874
|
const errorMessage = response.message || "订单备注修改失败";
|
|
2761
|
-
|
|
1875
|
+
this.logError(`订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
2762
1876
|
return {
|
|
2763
1877
|
success: false,
|
|
2764
1878
|
message: errorMessage,
|
|
@@ -2766,7 +1880,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2766
1880
|
};
|
|
2767
1881
|
}
|
|
2768
1882
|
} catch (error) {
|
|
2769
|
-
|
|
1883
|
+
this.logError("编辑订单备注失败:", error);
|
|
2770
1884
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2771
1885
|
return {
|
|
2772
1886
|
success: false,
|
|
@@ -2793,11 +1907,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2793
1907
|
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2794
1908
|
});
|
|
2795
1909
|
try {
|
|
2796
|
-
console.log("[Checkout] 开始发送客户支付链接邮件:", {
|
|
2797
|
-
orderIds: params.order_ids,
|
|
2798
|
-
emails: params.emails,
|
|
2799
|
-
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2800
|
-
});
|
|
2801
1910
|
if (!params.order_ids || params.order_ids.length === 0) {
|
|
2802
1911
|
return {
|
|
2803
1912
|
success: false,
|
|
@@ -2825,27 +1934,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2825
1934
|
notify_action: params.notify_action || "order_payment_reminder",
|
|
2826
1935
|
emails: params.emails
|
|
2827
1936
|
};
|
|
2828
|
-
console.log("[Checkout] 发送支付链接邮件请求参数:", requestBody);
|
|
2829
1937
|
this.logInfo("Calling batch email API", {
|
|
2830
1938
|
url: "/order/batch-email",
|
|
2831
|
-
|
|
2832
|
-
orderIdsCount: requestBody.order_ids.length,
|
|
2833
|
-
notifyAction: requestBody.notify_action,
|
|
2834
|
-
emails: requestBody.emails,
|
|
2835
|
-
emailsCount: requestBody.emails.length
|
|
1939
|
+
...requestBody
|
|
2836
1940
|
});
|
|
2837
1941
|
const response = await this.request.post(
|
|
2838
1942
|
"/order/batch-email",
|
|
2839
1943
|
requestBody
|
|
2840
1944
|
);
|
|
2841
|
-
|
|
1945
|
+
this.logInfo("支付链接邮件发送响应:", {
|
|
2842
1946
|
status: response.status,
|
|
2843
1947
|
message: response.message,
|
|
2844
1948
|
data: response.data,
|
|
2845
1949
|
response
|
|
2846
1950
|
});
|
|
2847
1951
|
if (response.status === true || response.status === 200) {
|
|
2848
|
-
console.log("[Checkout] 支付链接邮件发送成功");
|
|
2849
1952
|
return {
|
|
2850
1953
|
success: true,
|
|
2851
1954
|
message: response.message || "支付链接邮件发送成功"
|
|
@@ -2859,7 +1962,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2859
1962
|
};
|
|
2860
1963
|
}
|
|
2861
1964
|
} catch (error) {
|
|
2862
|
-
|
|
1965
|
+
this.logError("发送客户支付链接邮件失败:", error);
|
|
2863
1966
|
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2864
1967
|
return {
|
|
2865
1968
|
success: false,
|
|
@@ -2880,9 +1983,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2880
1983
|
(_a = this.otherParams.order_rounding_setting) == null ? void 0 : _a.interval,
|
|
2881
1984
|
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.type
|
|
2882
1985
|
);
|
|
2883
|
-
console.log(
|
|
2884
|
-
`[Checkout] 金额舍入完成 - 原始: ${result.originalAmount}, 舍入后: ${result.roundedAmount}, 差额: ${result.roundingDifference}`
|
|
2885
|
-
);
|
|
2886
1986
|
return result;
|
|
2887
1987
|
}
|
|
2888
1988
|
async destroy() {
|
|
@@ -2916,8 +2016,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2916
2016
|
this.store.lastError = void 0;
|
|
2917
2017
|
this.store.cartItems = [];
|
|
2918
2018
|
this.payment.wallet.clearAllCache();
|
|
2919
|
-
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
2920
|
-
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
2921
2019
|
console.log("[Checkout] Store 状态重置完成");
|
|
2922
2020
|
if (prevOrderInfo) {
|
|
2923
2021
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
|
|
@@ -2929,33 +2027,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2929
2027
|
console.error("[Checkout] 重置 store 状态失败:", error);
|
|
2930
2028
|
}
|
|
2931
2029
|
}
|
|
2932
|
-
/**
|
|
2933
|
-
* 手动清理已完成的订单状态(公开方法)
|
|
2934
|
-
*
|
|
2935
|
-
* 供UI层调用的公开方法,用于手动清理订单状态
|
|
2936
|
-
*
|
|
2937
|
-
* @returns 清理结果
|
|
2938
|
-
*/
|
|
2939
|
-
async clearCompletedOrderAsync() {
|
|
2940
|
-
try {
|
|
2941
|
-
const prevOrderInfo = this.store.currentOrder ? {
|
|
2942
|
-
uuid: this.store.currentOrder.uuid,
|
|
2943
|
-
orderId: this.store.currentOrder.order_id
|
|
2944
|
-
} : null;
|
|
2945
|
-
await this.resetStoreStateAsync();
|
|
2946
|
-
return {
|
|
2947
|
-
success: true,
|
|
2948
|
-
message: prevOrderInfo ? "订单状态已成功清理" : "没有需要清理的订单状态",
|
|
2949
|
-
clearedOrder: prevOrderInfo
|
|
2950
|
-
};
|
|
2951
|
-
} catch (error) {
|
|
2952
|
-
console.error("[Checkout] 手动清理订单状态失败:", error);
|
|
2953
|
-
return {
|
|
2954
|
-
success: false,
|
|
2955
|
-
message: error instanceof Error ? error.message : "清理失败"
|
|
2956
|
-
};
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
2030
|
};
|
|
2960
2031
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2961
2032
|
0 && (module.exports = {
|