@pisell/pisellos 0.0.230 → 0.0.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +13 -2
- package/dist/modules/Order/index.js +93 -1
- package/dist/modules/Order/types.d.ts +45 -0
- package/dist/modules/Order/types.js +8 -0
- package/dist/modules/Payment/cash.d.ts +8 -0
- package/dist/modules/Payment/cash.js +20 -1
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
- package/dist/modules/Payment/eftpos.js +1 -1
- package/dist/modules/Payment/index.d.ts +34 -124
- package/dist/modules/Payment/index.js +662 -1280
- package/dist/modules/Payment/mx51.d.ts +0 -0
- package/dist/modules/Payment/mx51.js +0 -0
- package/dist/modules/Payment/types.d.ts +323 -45
- package/dist/modules/Payment/types.js +101 -2
- package/dist/modules/Payment/utils.d.ts +17 -0
- package/dist/modules/Payment/utils.js +62 -0
- package/dist/modules/Payment/walletpass.d.ts +96 -0
- package/dist/modules/Payment/walletpass.js +492 -0
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +60 -0
- package/dist/solution/Checkout/index.d.ts +254 -2
- package/dist/solution/Checkout/index.js +2472 -320
- package/dist/solution/Checkout/types.d.ts +207 -6
- package/dist/solution/Checkout/types.js +5 -0
- package/lib/modules/Order/index.d.ts +13 -2
- package/lib/modules/Order/index.js +65 -1
- package/lib/modules/Order/types.d.ts +45 -0
- package/lib/modules/Payment/cash.d.ts +8 -0
- package/lib/modules/Payment/cash.js +14 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.d.ts +34 -124
- package/lib/modules/Payment/index.js +232 -533
- package/lib/modules/Payment/mx51.d.ts +0 -0
- package/lib/modules/Payment/mx51.js +0 -0
- package/lib/modules/Payment/types.d.ts +323 -45
- package/lib/modules/Payment/types.js +37 -2
- package/lib/modules/Payment/utils.d.ts +17 -0
- package/lib/modules/Payment/utils.js +67 -0
- package/lib/modules/Payment/walletpass.d.ts +96 -0
- package/lib/modules/Payment/walletpass.js +304 -0
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +36 -0
- package/lib/solution/Checkout/index.d.ts +254 -2
- package/lib/solution/Checkout/index.js +1361 -39
- package/lib/solution/Checkout/types.d.ts +207 -6
- package/lib/solution/Checkout/types.js +5 -0
- package/package.json +1 -1
- package/dist/modules/Payment/wallet.d.ts +0 -11
- package/dist/modules/Payment/wallet.js +0 -78
- package/lib/modules/Payment/wallet.d.ts +0 -11
- package/lib/modules/Payment/wallet.js +0 -51
|
@@ -45,13 +45,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
45
45
|
if (!this.request) {
|
|
46
46
|
throw new Error("Checkout 解决方案需要 request 插件支持");
|
|
47
47
|
}
|
|
48
|
+
this.order = new import_Order.OrderModule();
|
|
49
|
+
this.payment = new import_Payment.PaymentModule();
|
|
48
50
|
this.store = {
|
|
49
|
-
order: new import_Order.OrderModule(),
|
|
50
|
-
payment: new import_Payment.PaymentModule(),
|
|
51
51
|
status: import_types.CheckoutStatus.Initializing,
|
|
52
52
|
step: import_types.CheckoutStep.OrderConfirmation,
|
|
53
53
|
cartItems: [],
|
|
54
|
-
paymentMethods: []
|
|
54
|
+
paymentMethods: [],
|
|
55
|
+
stateAmount: "0.00",
|
|
56
|
+
cartSummary: void 0,
|
|
57
|
+
isOrderSynced: false,
|
|
58
|
+
currentCustomer: void 0
|
|
55
59
|
};
|
|
56
60
|
await this.initializeSubModules(core, options);
|
|
57
61
|
await this.preloadPaymentMethods();
|
|
@@ -66,11 +70,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
66
70
|
*/
|
|
67
71
|
async initializeSubModules(core, options) {
|
|
68
72
|
var _a, _b;
|
|
69
|
-
core.registerModule(this.
|
|
73
|
+
core.registerModule(this.order, {
|
|
70
74
|
store: ((_a = options.store) == null ? void 0 : _a.order) || {},
|
|
71
75
|
otherParams: { ...this.otherParams, parentModule: this.name }
|
|
72
76
|
});
|
|
73
|
-
core.registerModule(this.
|
|
77
|
+
core.registerModule(this.payment, {
|
|
74
78
|
store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
|
|
75
79
|
otherParams: { ...this.otherParams, parentModule: this.name }
|
|
76
80
|
});
|
|
@@ -115,6 +119,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
115
119
|
throw error;
|
|
116
120
|
}
|
|
117
121
|
}
|
|
122
|
+
getProductListByOrder() {
|
|
123
|
+
var _a;
|
|
124
|
+
if (!this.store.currentOrder) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
const productList = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data.bookings.map((item) => ({
|
|
128
|
+
product_id: item.product.product_id,
|
|
129
|
+
product_variant_id: item.product.product_variant_id,
|
|
130
|
+
quantity: item.product.num,
|
|
131
|
+
selling_price: item.product.price - (item.product.discount_amount || 0)
|
|
132
|
+
}));
|
|
133
|
+
return productList;
|
|
134
|
+
}
|
|
118
135
|
/**
|
|
119
136
|
* 创建本地订单 (前端模拟下单流程)
|
|
120
137
|
*
|
|
@@ -123,6 +140,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
123
140
|
* 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
|
|
124
141
|
*/
|
|
125
142
|
async createLocalOrderAsync(params) {
|
|
143
|
+
var _a, _b, _c, _d, _e;
|
|
126
144
|
try {
|
|
127
145
|
await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
128
146
|
const validation = await this.validateLocalOrderData(params.orderData);
|
|
@@ -134,8 +152,24 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
134
152
|
}
|
|
135
153
|
const localOrderId = this.generateLocalOrderId();
|
|
136
154
|
const amountInfo = this.extractAmountFromCartSummary(params.cartSummary);
|
|
155
|
+
params.orderData.platform = "pos";
|
|
156
|
+
params.orderData.created_at = this.formatDateTime(/* @__PURE__ */ new Date());
|
|
157
|
+
params.orderData.surcharge_fee = (_b = (_a = params.totalInfo) == null ? void 0 : _a.total) == null ? void 0 : _b.paySurchargeFee;
|
|
158
|
+
params.orderData.shop_discount = (_d = (_c = params.totalInfo) == null ? void 0 : _c.total) == null ? void 0 : _d.shopDiscount;
|
|
137
159
|
this.store.localOrderData = params.orderData;
|
|
138
|
-
|
|
160
|
+
this.store.cartSummary = params.cartSummary;
|
|
161
|
+
const customerInfo = {
|
|
162
|
+
customer_id: params.orderData.customer_id,
|
|
163
|
+
customer_name: params.orderData.customer_name
|
|
164
|
+
};
|
|
165
|
+
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
166
|
+
this.store.currentCustomer = customerInfo;
|
|
167
|
+
console.log("[Checkout] 保存客户信息:", customerInfo);
|
|
168
|
+
} else {
|
|
169
|
+
this.store.currentCustomer = void 0;
|
|
170
|
+
console.log("[Checkout] 未提供客户信息");
|
|
171
|
+
}
|
|
172
|
+
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
139
173
|
order_id: localOrderId,
|
|
140
174
|
total_amount: amountInfo.totalAmount,
|
|
141
175
|
is_deposit: params.orderData.is_deposit || 0,
|
|
@@ -144,7 +178,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
144
178
|
original_order_data: params.orderData,
|
|
145
179
|
cart_summary: params.cartSummary,
|
|
146
180
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
147
|
-
platform: params.orderData.platform
|
|
181
|
+
platform: params.orderData.platform,
|
|
148
182
|
type: params.orderData.type,
|
|
149
183
|
schedule_date: params.orderData.schedule_date,
|
|
150
184
|
shop_note: params.orderData.shop_note,
|
|
@@ -152,6 +186,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
152
186
|
}
|
|
153
187
|
});
|
|
154
188
|
this.store.currentOrder = paymentOrder;
|
|
189
|
+
const walletBusinessData = {
|
|
190
|
+
customer_id: ((_e = this.store.currentCustomer) == null ? void 0 : _e.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
|
|
191
|
+
amountInfo: {
|
|
192
|
+
totalAmount: amountInfo.totalAmount,
|
|
193
|
+
subTotal: amountInfo.subTotal
|
|
194
|
+
},
|
|
195
|
+
products: this.getProductListByOrder()
|
|
196
|
+
};
|
|
197
|
+
const walletData = await this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
|
|
198
|
+
console.log(walletData.walletRecommendList, "walletRecommendList");
|
|
199
|
+
console.log(walletData.userIdentificationCodes, "userIdentificationCodes");
|
|
155
200
|
await this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
156
201
|
await this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
157
202
|
if (params.autoPayment) {
|
|
@@ -161,12 +206,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
161
206
|
order: paymentOrder,
|
|
162
207
|
timestamp: Date.now()
|
|
163
208
|
});
|
|
209
|
+
await this.updateStateAmountToRemaining();
|
|
164
210
|
console.log("[Checkout] 本地订单创建成功:", {
|
|
165
211
|
localOrderId,
|
|
166
212
|
uuid: paymentOrder.uuid,
|
|
167
213
|
totalAmount: amountInfo.totalAmount,
|
|
168
214
|
subTotal: amountInfo.subTotal,
|
|
169
|
-
taxAmount: amountInfo.taxAmount
|
|
215
|
+
taxAmount: amountInfo.taxAmount,
|
|
216
|
+
stateAmount: this.store.stateAmount
|
|
170
217
|
});
|
|
171
218
|
return paymentOrder;
|
|
172
219
|
} catch (error) {
|
|
@@ -184,7 +231,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
184
231
|
* 使用当前存储的本地订单数据调用 Order 模块创建真实订单
|
|
185
232
|
*/
|
|
186
233
|
async placeOrderAsync(params = {}) {
|
|
187
|
-
var _a
|
|
234
|
+
var _a;
|
|
188
235
|
try {
|
|
189
236
|
if (!this.store.localOrderData) {
|
|
190
237
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -203,14 +250,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
203
250
|
const orderData = {
|
|
204
251
|
cartItems: this.store.cartItems,
|
|
205
252
|
type: this.store.localOrderData.type,
|
|
206
|
-
platform:
|
|
253
|
+
platform: this.store.localOrderData.platform
|
|
207
254
|
};
|
|
208
|
-
const orderResponse = await this.
|
|
255
|
+
const orderResponse = await this.order.submitOrder({
|
|
209
256
|
url: params.url,
|
|
210
257
|
// 可选的自定义 URL
|
|
211
258
|
query: orderData
|
|
212
259
|
});
|
|
213
|
-
const realOrderId = ((
|
|
260
|
+
const realOrderId = ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
|
|
214
261
|
if (!realOrderId) {
|
|
215
262
|
throw (0, import_utils.createCheckoutError)(
|
|
216
263
|
import_types.CheckoutErrorType.OrderCreationFailed,
|
|
@@ -233,6 +280,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
233
280
|
order: this.store.currentOrder,
|
|
234
281
|
timestamp: Date.now()
|
|
235
282
|
});
|
|
283
|
+
this.store.isOrderSynced = true;
|
|
236
284
|
console.log("[Checkout] 手动下单流程完成");
|
|
237
285
|
return {
|
|
238
286
|
success: true,
|
|
@@ -260,7 +308,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
260
308
|
var _a;
|
|
261
309
|
try {
|
|
262
310
|
await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
263
|
-
const checkResult = this.
|
|
311
|
+
const checkResult = this.order.checkBeforeSubmitOrder({
|
|
264
312
|
cartItems: params.cartItems,
|
|
265
313
|
type: "account"
|
|
266
314
|
// 默认使用 account 类型
|
|
@@ -271,14 +319,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
271
319
|
"购物车数据验证失败,请检查商品信息"
|
|
272
320
|
);
|
|
273
321
|
}
|
|
274
|
-
const orderResponse = await this.
|
|
322
|
+
const orderResponse = await this.order.submitOrder({
|
|
275
323
|
query: {
|
|
276
324
|
cartItems: params.cartItems,
|
|
277
325
|
type: params.type || "appointment_booking",
|
|
278
326
|
platform: params.platform || "pc"
|
|
279
327
|
}
|
|
280
328
|
});
|
|
281
|
-
const paymentOrder = await this.
|
|
329
|
+
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
282
330
|
order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
|
|
283
331
|
total_amount: this.calculateTotalAmount(params.cartItems),
|
|
284
332
|
order_info: orderResponse == null ? void 0 : orderResponse.data
|
|
@@ -290,6 +338,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
290
338
|
order: paymentOrder,
|
|
291
339
|
timestamp: Date.now()
|
|
292
340
|
});
|
|
341
|
+
this.store.isOrderSynced = true;
|
|
342
|
+
await this.updateStateAmountToRemaining();
|
|
293
343
|
console.log("[Checkout] 订单创建成功:", paymentOrder.id);
|
|
294
344
|
return paymentOrder;
|
|
295
345
|
} catch (error) {
|
|
@@ -330,11 +380,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
330
380
|
amount: String(params.amount),
|
|
331
381
|
id: paymentMethod.id
|
|
332
382
|
};
|
|
333
|
-
await this.
|
|
383
|
+
await this.payment.addPaymentItemAsync(
|
|
334
384
|
this.store.currentOrder.uuid,
|
|
335
385
|
paymentItem
|
|
336
386
|
);
|
|
337
|
-
const result = await this.
|
|
387
|
+
const result = await this.payment.submitPayAsync(
|
|
338
388
|
this.store.currentOrder.uuid
|
|
339
389
|
);
|
|
340
390
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
@@ -345,6 +395,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
345
395
|
});
|
|
346
396
|
if (result.status === "success") {
|
|
347
397
|
await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
398
|
+
await this.updateStateAmountToRemaining();
|
|
348
399
|
await this.handlePaymentSuccess({
|
|
349
400
|
orderUuid: this.store.currentOrder.uuid,
|
|
350
401
|
timestamp: Date.now()
|
|
@@ -371,7 +422,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
371
422
|
"未找到当前订单"
|
|
372
423
|
);
|
|
373
424
|
}
|
|
374
|
-
const order = await this.
|
|
425
|
+
const order = await this.payment.getPaymentOrderByUuidAsync(
|
|
375
426
|
this.store.currentOrder.uuid
|
|
376
427
|
);
|
|
377
428
|
if (!order || order.payment_status !== import_types2.PaymentStatus.Finished) {
|
|
@@ -380,6 +431,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
380
431
|
"订单支付未完成,无法完成结账"
|
|
381
432
|
);
|
|
382
433
|
}
|
|
434
|
+
this.payment.wallet.clearAllCache();
|
|
383
435
|
await this.setStatus(import_types.CheckoutStatus.Completed);
|
|
384
436
|
await this.setStep(import_types.CheckoutStep.Complete);
|
|
385
437
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
@@ -402,9 +454,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
402
454
|
async cancelCheckoutAsync() {
|
|
403
455
|
try {
|
|
404
456
|
if (this.store.currentOrder) {
|
|
405
|
-
await this.
|
|
457
|
+
await this.payment.deletePaymentOrderAsync(this.store.currentOrder.uuid);
|
|
406
458
|
this.store.currentOrder = void 0;
|
|
407
459
|
}
|
|
460
|
+
this.store.localOrderData = void 0;
|
|
461
|
+
this.store.cartSummary = void 0;
|
|
462
|
+
this.payment.wallet.clearAllCache();
|
|
463
|
+
this.store.cartItems = [];
|
|
464
|
+
this.store.stateAmount = "0.00";
|
|
465
|
+
this.store.isOrderSynced = false;
|
|
466
|
+
this.store.currentCustomer = void 0;
|
|
408
467
|
await this.setStatus(import_types.CheckoutStatus.Cancelled);
|
|
409
468
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
|
|
410
469
|
timestamp: Date.now()
|
|
@@ -431,16 +490,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
431
490
|
* 获取结账摘要
|
|
432
491
|
*/
|
|
433
492
|
async getCheckoutSummaryAsync() {
|
|
434
|
-
var _a, _b
|
|
493
|
+
var _a, _b;
|
|
435
494
|
const totalAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0.00";
|
|
436
495
|
const paidAmount = this.calculatePaidAmount();
|
|
437
|
-
const remainingAmount =
|
|
496
|
+
const remainingAmount = this.calculateRemainingAmount();
|
|
438
497
|
return {
|
|
439
498
|
order: this.store.currentOrder,
|
|
440
499
|
totalAmount,
|
|
441
500
|
paidAmount,
|
|
442
501
|
remainingAmount,
|
|
443
|
-
paymentStatus: ((
|
|
502
|
+
paymentStatus: ((_b = this.store.currentOrder) == null ? void 0 : _b.payment_status) || import_types2.PaymentStatus.Processing,
|
|
444
503
|
availablePaymentMethods: this.store.paymentMethods
|
|
445
504
|
};
|
|
446
505
|
}
|
|
@@ -464,13 +523,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
464
523
|
await this.preloadPaymentMethods();
|
|
465
524
|
return this.store.paymentMethods;
|
|
466
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* 获取订单原始数据
|
|
528
|
+
*/
|
|
529
|
+
getOrderOriginalData() {
|
|
530
|
+
var _a;
|
|
531
|
+
return (_a = this.store.currentOrder) == null ? void 0 : _a.order_info;
|
|
532
|
+
}
|
|
467
533
|
/**
|
|
468
534
|
* 获取当前订单基础信息
|
|
469
535
|
*
|
|
470
536
|
* 返回当前订单的基础信息,包括订单状态、金额、支付状态等
|
|
471
537
|
*/
|
|
472
538
|
getCurrentOrderInfo() {
|
|
473
|
-
var _a;
|
|
474
539
|
try {
|
|
475
540
|
const { currentOrder, status, step, cartItems, localOrderData } = this.store;
|
|
476
541
|
if (!currentOrder) {
|
|
@@ -480,7 +545,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
480
545
|
const orderInfo = currentOrder.order_info || {};
|
|
481
546
|
const createdAt = orderInfo.created_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
482
547
|
const orderType = (localOrderData == null ? void 0 : localOrderData.type) || orderInfo.type || "virtual";
|
|
483
|
-
const platform = (
|
|
548
|
+
const platform = (localOrderData == null ? void 0 : localOrderData.platform) || orderInfo.platform || "pc";
|
|
484
549
|
const result = {
|
|
485
550
|
uuid: currentOrder.uuid,
|
|
486
551
|
orderId: currentOrder.order_id,
|
|
@@ -510,6 +575,43 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
510
575
|
return null;
|
|
511
576
|
}
|
|
512
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* 获取当前订单的支付项
|
|
580
|
+
*
|
|
581
|
+
* 返回当前订单的所有支付项,包括活跃和已撤销的支付项
|
|
582
|
+
*/
|
|
583
|
+
async getCurrentOrderPaymentItemsAsync() {
|
|
584
|
+
try {
|
|
585
|
+
const { currentOrder } = this.store;
|
|
586
|
+
if (!currentOrder) {
|
|
587
|
+
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
588
|
+
return [];
|
|
589
|
+
}
|
|
590
|
+
console.log("[Checkout] 获取当前订单支付项:", {
|
|
591
|
+
orderUuid: currentOrder.uuid,
|
|
592
|
+
orderId: currentOrder.order_id
|
|
593
|
+
});
|
|
594
|
+
const paymentItems = await this.payment.getPaymentItemsAsync(currentOrder.uuid);
|
|
595
|
+
console.log("[Checkout] 成功获取支付项:", {
|
|
596
|
+
orderUuid: currentOrder.uuid,
|
|
597
|
+
paymentItemCount: paymentItems.length,
|
|
598
|
+
activeItems: paymentItems.filter((item) => item.status !== "voided").length,
|
|
599
|
+
voidedItems: paymentItems.filter((item) => item.status === "voided").length,
|
|
600
|
+
totalPaidAmount: paymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => sum + parseFloat(item.amount || "0"), 0).toFixed(2),
|
|
601
|
+
paymentMethods: paymentItems.map((item) => ({
|
|
602
|
+
uuid: item.uuid,
|
|
603
|
+
code: item.code,
|
|
604
|
+
amount: item.amount,
|
|
605
|
+
status: item.status,
|
|
606
|
+
voucher_id: item.voucher_id
|
|
607
|
+
}))
|
|
608
|
+
});
|
|
609
|
+
return paymentItems;
|
|
610
|
+
} catch (error) {
|
|
611
|
+
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
612
|
+
return [];
|
|
613
|
+
}
|
|
614
|
+
}
|
|
513
615
|
/**
|
|
514
616
|
* 验证结账前置条件
|
|
515
617
|
*/
|
|
@@ -543,11 +645,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
543
645
|
});
|
|
544
646
|
}
|
|
545
647
|
break;
|
|
546
|
-
case import_types.CheckoutErrorType.PaymentFailed:
|
|
547
|
-
if (this.store.currentOrder) {
|
|
548
|
-
await this.store.payment.runPaymentSyncQueue();
|
|
549
|
-
}
|
|
550
|
-
break;
|
|
551
648
|
default:
|
|
552
649
|
console.warn("[Checkout] 无法重试此类型的错误:", this.store.lastError.type);
|
|
553
650
|
}
|
|
@@ -572,13 +669,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
572
669
|
* 获取订单模块
|
|
573
670
|
*/
|
|
574
671
|
getOrderModule() {
|
|
575
|
-
return this.
|
|
672
|
+
return this.order;
|
|
576
673
|
}
|
|
577
674
|
/**
|
|
578
675
|
* 获取支付模块
|
|
579
676
|
*/
|
|
580
677
|
getPaymentModule() {
|
|
581
|
-
return this.
|
|
678
|
+
return this.payment;
|
|
582
679
|
}
|
|
583
680
|
/**
|
|
584
681
|
* 替换本地订单ID为真实订单ID
|
|
@@ -594,7 +691,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
594
691
|
console.warn("[Checkout] 没有当前订单,无法替换订单ID");
|
|
595
692
|
return null;
|
|
596
693
|
}
|
|
597
|
-
const updatedOrder = await this.
|
|
694
|
+
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
598
695
|
this.store.currentOrder.uuid,
|
|
599
696
|
newOrderId
|
|
600
697
|
);
|
|
@@ -608,6 +705,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
608
705
|
uuid: updatedOrder.uuid,
|
|
609
706
|
newOrderId: updatedOrder.id
|
|
610
707
|
});
|
|
708
|
+
this.store.isOrderSynced = true;
|
|
709
|
+
await this.updateStateAmountToRemaining();
|
|
611
710
|
}
|
|
612
711
|
return updatedOrder;
|
|
613
712
|
} catch (error) {
|
|
@@ -616,6 +715,765 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
616
715
|
return null;
|
|
617
716
|
}
|
|
618
717
|
}
|
|
718
|
+
/**
|
|
719
|
+
* 设置自定义支付金额
|
|
720
|
+
*
|
|
721
|
+
* 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
|
|
722
|
+
*
|
|
723
|
+
* @param amount 自定义支付金额,必须是有效的数字字符串
|
|
724
|
+
*/
|
|
725
|
+
async setStateAmountAsync(amount) {
|
|
726
|
+
try {
|
|
727
|
+
const numAmount = parseFloat(amount);
|
|
728
|
+
if (isNaN(numAmount) || numAmount < 0) {
|
|
729
|
+
throw new Error(`无效的支付金额: ${amount}`);
|
|
730
|
+
}
|
|
731
|
+
const oldAmount = this.store.stateAmount;
|
|
732
|
+
const formattedAmount = numAmount.toFixed(2);
|
|
733
|
+
if (oldAmount === formattedAmount) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
this.store.stateAmount = formattedAmount;
|
|
737
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
738
|
+
oldAmount,
|
|
739
|
+
newAmount: formattedAmount,
|
|
740
|
+
timestamp: Date.now()
|
|
741
|
+
});
|
|
742
|
+
console.log("[Checkout] 自定义支付金额已更新:", {
|
|
743
|
+
oldAmount,
|
|
744
|
+
newAmount: formattedAmount
|
|
745
|
+
});
|
|
746
|
+
} catch (error) {
|
|
747
|
+
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
748
|
+
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
749
|
+
await this.handleError(
|
|
750
|
+
new Error(errorMessage),
|
|
751
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
752
|
+
);
|
|
753
|
+
throw error;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* 获取当前自定义支付金额
|
|
758
|
+
*
|
|
759
|
+
* @returns 当前设置的自定义支付金额
|
|
760
|
+
*/
|
|
761
|
+
getStateAmount() {
|
|
762
|
+
return this.store.stateAmount;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* 刷新 stateAmount 为当前剩余未支付金额
|
|
766
|
+
*
|
|
767
|
+
* UI 可以调用此方法来主动刷新支付金额状态
|
|
768
|
+
*/
|
|
769
|
+
async refreshStateAmountAsync() {
|
|
770
|
+
await this.updateStateAmountToRemaining();
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* 获取购物车小计数据
|
|
774
|
+
*
|
|
775
|
+
* 返回当前结账流程中的购物车小计项数据,包含各种费用明细
|
|
776
|
+
*
|
|
777
|
+
* @returns 购物车小计数据数组,如果没有则返回 null
|
|
778
|
+
*/
|
|
779
|
+
getCartSummary() {
|
|
780
|
+
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
781
|
+
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
782
|
+
return null;
|
|
783
|
+
}
|
|
784
|
+
console.log("[Checkout] 获取购物车小计数据:", {
|
|
785
|
+
itemCount: this.store.cartSummary.length,
|
|
786
|
+
items: this.store.cartSummary.map((item) => ({ key: item.key, value: item.value, label: item.label }))
|
|
787
|
+
});
|
|
788
|
+
return [...this.store.cartSummary];
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* 获取提取的金额详细信息
|
|
792
|
+
*
|
|
793
|
+
* 从当前的购物车小计数据中提取结构化的金额信息
|
|
794
|
+
*
|
|
795
|
+
* @returns 提取的金额信息对象,如果没有小计数据则返回 null
|
|
796
|
+
*/
|
|
797
|
+
getExtractedAmountInfo() {
|
|
798
|
+
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
799
|
+
console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
const extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
|
|
803
|
+
console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
|
|
804
|
+
return extractedInfo;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* 获取支付方式列表
|
|
808
|
+
*
|
|
809
|
+
* 直接调用 Payment 模块的 getPayMethodListAsync 方法
|
|
810
|
+
*
|
|
811
|
+
* @returns 支付方式列表
|
|
812
|
+
*/
|
|
813
|
+
async getPaymentMethodsAsync() {
|
|
814
|
+
return await this.payment.getPayMethodListAsync();
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* 为当前订单添加支付项
|
|
818
|
+
*
|
|
819
|
+
* 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
|
|
820
|
+
*
|
|
821
|
+
* @param paymentItem 支付项数据
|
|
822
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
823
|
+
*/
|
|
824
|
+
async addPaymentItemAsync(paymentItem) {
|
|
825
|
+
try {
|
|
826
|
+
if (!this.store.currentOrder) {
|
|
827
|
+
throw (0, import_utils.createCheckoutError)(
|
|
828
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
829
|
+
"未找到当前订单,无法添加支付项"
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
console.log("[Checkout] 为当前订单添加支付项:", {
|
|
833
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
834
|
+
paymentItem: {
|
|
835
|
+
code: paymentItem.code,
|
|
836
|
+
name: paymentItem.name,
|
|
837
|
+
type: paymentItem.type,
|
|
838
|
+
amount: paymentItem.amount,
|
|
839
|
+
service_charge: paymentItem.service_charge
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
await this.payment.addPaymentItemAsync(
|
|
843
|
+
this.store.currentOrder.uuid,
|
|
844
|
+
paymentItem
|
|
845
|
+
);
|
|
846
|
+
console.log("[Checkout] 支付项添加成功");
|
|
847
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
848
|
+
const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
|
|
849
|
+
console.log("[Checkout] 准备同步订单数据:", {
|
|
850
|
+
当前订单ID: currentOrderId,
|
|
851
|
+
是否为真实ID: isCurrentOrderReal
|
|
852
|
+
});
|
|
853
|
+
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
854
|
+
if (updatedOrder) {
|
|
855
|
+
if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
|
|
856
|
+
console.warn("[Checkout] 检测到订单ID回退,保护真实订单ID:", {
|
|
857
|
+
当前真实ID: currentOrderId,
|
|
858
|
+
获取到的虚拟ID: updatedOrder.order_id
|
|
859
|
+
});
|
|
860
|
+
updatedOrder.order_id = currentOrderId;
|
|
861
|
+
}
|
|
862
|
+
this.store.currentOrder = updatedOrder;
|
|
863
|
+
console.log("[Checkout] 订单数据已同步:", {
|
|
864
|
+
支付项数量: updatedOrder.payment.length,
|
|
865
|
+
最终订单ID: updatedOrder.order_id,
|
|
866
|
+
是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
const needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
|
|
870
|
+
console.log("[Checkout] 支付项同步检查:", {
|
|
871
|
+
paymentCode: paymentItem.code,
|
|
872
|
+
paymentType: paymentItem.type,
|
|
873
|
+
paymentAmount: paymentItem.amount,
|
|
874
|
+
expectedCashCode: import_types2.PaymentMethodType.Cash,
|
|
875
|
+
needsOrderSync,
|
|
876
|
+
isOrderSynced: this.store.isOrderSynced
|
|
877
|
+
});
|
|
878
|
+
if (needsOrderSync) {
|
|
879
|
+
console.log("[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...", {
|
|
880
|
+
同步前订单ID: this.store.currentOrder.order_id,
|
|
881
|
+
是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
|
|
882
|
+
订单同步状态: this.store.isOrderSynced,
|
|
883
|
+
订单UUID: this.store.currentOrder.uuid
|
|
884
|
+
});
|
|
885
|
+
await this.syncOrderToBackend();
|
|
886
|
+
console.log("[Checkout] addPaymentItemAsync 中的同步完成:", {
|
|
887
|
+
同步后订单ID: this.store.currentOrder.order_id,
|
|
888
|
+
是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
|
|
889
|
+
订单同步状态: this.store.isOrderSynced
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
await this.updateStateAmountToRemaining();
|
|
893
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
894
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
895
|
+
paymentMethodCode: paymentItem.code,
|
|
896
|
+
amount: String(paymentItem.amount),
|
|
897
|
+
timestamp: Date.now()
|
|
898
|
+
});
|
|
899
|
+
} catch (error) {
|
|
900
|
+
console.error("[Checkout] 添加支付项失败:", error);
|
|
901
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
902
|
+
throw error;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* 删除当前订单的支付项
|
|
907
|
+
*
|
|
908
|
+
* 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
|
|
909
|
+
*
|
|
910
|
+
* @param paymentUuid 要删除的支付项UUID
|
|
911
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
912
|
+
* @throws 支付项不存在时抛出错误
|
|
913
|
+
*/
|
|
914
|
+
async deletePaymentItemAsync(paymentUuid) {
|
|
915
|
+
try {
|
|
916
|
+
if (!this.store.currentOrder) {
|
|
917
|
+
throw (0, import_utils.createCheckoutError)(
|
|
918
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
919
|
+
"当前没有活跃订单,无法删除支付项"
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
console.log("[Checkout] 开始删除支付项:", {
|
|
923
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
924
|
+
paymentUuid
|
|
925
|
+
});
|
|
926
|
+
const paymentItem = this.store.currentOrder.payment.find((p) => p.uuid === paymentUuid);
|
|
927
|
+
if (!paymentItem) {
|
|
928
|
+
throw (0, import_utils.createCheckoutError)(
|
|
929
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
930
|
+
`支付项不存在: ${paymentUuid}`
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
console.log("[Checkout] 找到要删除的支付项:", {
|
|
934
|
+
uuid: paymentItem.uuid,
|
|
935
|
+
code: paymentItem.code,
|
|
936
|
+
amount: paymentItem.amount,
|
|
937
|
+
status: paymentItem.status
|
|
938
|
+
});
|
|
939
|
+
await this.payment.deletePaymentAsync(
|
|
940
|
+
this.store.currentOrder.uuid,
|
|
941
|
+
paymentUuid
|
|
942
|
+
);
|
|
943
|
+
console.log("[Checkout] Payment模块删除完成");
|
|
944
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
945
|
+
const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
|
|
946
|
+
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
947
|
+
if (updatedOrder) {
|
|
948
|
+
if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
|
|
949
|
+
console.warn("[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:", {
|
|
950
|
+
当前真实ID: currentOrderId,
|
|
951
|
+
获取到的虚拟ID: updatedOrder.order_id
|
|
952
|
+
});
|
|
953
|
+
updatedOrder.order_id = currentOrderId;
|
|
954
|
+
}
|
|
955
|
+
this.store.currentOrder = updatedOrder;
|
|
956
|
+
console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
|
|
957
|
+
}
|
|
958
|
+
await this.updateStateAmountToRemaining();
|
|
959
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
960
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
961
|
+
paymentMethodCode: paymentItem.code,
|
|
962
|
+
amount: `-${paymentItem.amount}`,
|
|
963
|
+
// 负数表示删除
|
|
964
|
+
timestamp: Date.now()
|
|
965
|
+
});
|
|
966
|
+
console.log("[Checkout] 支付项删除成功");
|
|
967
|
+
} catch (error) {
|
|
968
|
+
console.error("[Checkout] 删除支付项失败:", error);
|
|
969
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
970
|
+
throw error;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* 批量更新当前订单的代金券支付项(覆盖更新)
|
|
975
|
+
*
|
|
976
|
+
* 删除所有现有的代金券支付项,然后添加新的代金券支付项。
|
|
977
|
+
* 这是一个覆盖式更新操作,确保代金券支付项的一致性。
|
|
978
|
+
*
|
|
979
|
+
* @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
|
|
980
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
981
|
+
* @throws 支付项缺少 voucher_id 时抛出错误
|
|
982
|
+
*/
|
|
983
|
+
async updateVoucherPaymentItemsAsync(voucherPaymentItems) {
|
|
984
|
+
try {
|
|
985
|
+
if (!this.store.currentOrder) {
|
|
986
|
+
throw (0, import_utils.createCheckoutError)(
|
|
987
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
988
|
+
"当前没有活跃订单,无法更新代金券支付项"
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
console.log("[Checkout] 开始批量更新代金券支付项:", {
|
|
992
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
993
|
+
newVoucherCount: voucherPaymentItems.length,
|
|
994
|
+
voucherPaymentItems
|
|
995
|
+
});
|
|
996
|
+
for (const item of voucherPaymentItems) {
|
|
997
|
+
if (!item.voucher_id) {
|
|
998
|
+
throw (0, import_utils.createCheckoutError)(
|
|
999
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1000
|
+
`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
await this.payment.updateVoucherPaymentItemsAsync(
|
|
1005
|
+
this.store.currentOrder.uuid,
|
|
1006
|
+
voucherPaymentItems
|
|
1007
|
+
);
|
|
1008
|
+
console.log("[Checkout] Payment模块批量更新完成");
|
|
1009
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
1010
|
+
const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
|
|
1011
|
+
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1012
|
+
if (updatedOrder) {
|
|
1013
|
+
if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
|
|
1014
|
+
console.warn("[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:", {
|
|
1015
|
+
当前真实ID: currentOrderId,
|
|
1016
|
+
获取到的虚拟ID: updatedOrder.order_id
|
|
1017
|
+
});
|
|
1018
|
+
updatedOrder.order_id = currentOrderId;
|
|
1019
|
+
}
|
|
1020
|
+
this.store.currentOrder = updatedOrder;
|
|
1021
|
+
console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
|
|
1022
|
+
const voucherItems = updatedOrder.payment.filter(
|
|
1023
|
+
(payment) => payment.voucher_id && payment.status !== "voided"
|
|
1024
|
+
);
|
|
1025
|
+
console.log("[Checkout] 更新后的代金券支付项:", {
|
|
1026
|
+
voucherCount: voucherItems.length,
|
|
1027
|
+
items: voucherItems.map((item) => ({
|
|
1028
|
+
uuid: item.uuid,
|
|
1029
|
+
code: item.code,
|
|
1030
|
+
amount: item.amount,
|
|
1031
|
+
voucher_id: item.voucher_id
|
|
1032
|
+
}))
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
await this.updateStateAmountToRemaining();
|
|
1036
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
1037
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1038
|
+
paymentMethodCode: "VOUCHER_BATCH",
|
|
1039
|
+
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1040
|
+
timestamp: Date.now()
|
|
1041
|
+
});
|
|
1042
|
+
console.log("[Checkout] 代金券支付项批量更新成功");
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
console.error("[Checkout] 批量更新代金券支付项失败:", error);
|
|
1045
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1046
|
+
throw error;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* 修改当前订单的定金状态
|
|
1051
|
+
*
|
|
1052
|
+
* 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
|
|
1053
|
+
*
|
|
1054
|
+
* @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
|
|
1055
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
1056
|
+
*/
|
|
1057
|
+
async updateOrderDepositStatusAsync(isDeposit) {
|
|
1058
|
+
try {
|
|
1059
|
+
if (isDeposit !== 0 && isDeposit !== 1) {
|
|
1060
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1061
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1062
|
+
"isDeposit 参数只能是 0(全款订单)或 1(定金订单)"
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
if (!this.store.currentOrder) {
|
|
1066
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1067
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1068
|
+
"未找到当前订单,无法修改定金状态"
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
const newDepositValue = isDeposit;
|
|
1072
|
+
const oldDepositValue = this.store.currentOrder.is_deposit;
|
|
1073
|
+
if (oldDepositValue === newDepositValue) {
|
|
1074
|
+
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
console.log("[Checkout] 更新订单定金状态:", {
|
|
1078
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1079
|
+
orderId: this.store.currentOrder.order_id,
|
|
1080
|
+
oldIsDeposit: oldDepositValue,
|
|
1081
|
+
newIsDeposit: newDepositValue
|
|
1082
|
+
});
|
|
1083
|
+
const updateParams = {
|
|
1084
|
+
is_deposit: newDepositValue
|
|
1085
|
+
};
|
|
1086
|
+
if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== "0.00") {
|
|
1087
|
+
updateParams.deposit_amount = "0.00";
|
|
1088
|
+
console.log("[Checkout] 订单从定金改为全款,清空定金金额");
|
|
1089
|
+
}
|
|
1090
|
+
await this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
|
|
1091
|
+
this.store.currentOrder = {
|
|
1092
|
+
...this.store.currentOrder,
|
|
1093
|
+
...updateParams
|
|
1094
|
+
};
|
|
1095
|
+
if (this.store.localOrderData) {
|
|
1096
|
+
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1097
|
+
}
|
|
1098
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
1099
|
+
order: this.store.currentOrder,
|
|
1100
|
+
timestamp: Date.now()
|
|
1101
|
+
});
|
|
1102
|
+
console.log("[Checkout] 订单定金状态更新成功:", {
|
|
1103
|
+
isDeposit: newDepositValue,
|
|
1104
|
+
depositAmount: this.store.currentOrder.deposit_amount
|
|
1105
|
+
});
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
console.error("[Checkout] 更新订单定金状态失败:", error);
|
|
1108
|
+
await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
|
|
1109
|
+
throw error;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* 更新当前订单的客户信息
|
|
1114
|
+
*
|
|
1115
|
+
* 更新当前订单关联的客户信息,用于标识订单的所属客户
|
|
1116
|
+
*
|
|
1117
|
+
* @param customer 客户信息 (customer_id 和/或 customer_name)
|
|
1118
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
1119
|
+
*/
|
|
1120
|
+
async updateOrderCustomerAsync(customer) {
|
|
1121
|
+
try {
|
|
1122
|
+
if (!this.store.currentOrder) {
|
|
1123
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1124
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1125
|
+
"未找到当前订单,无法更新客户信息"
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
console.log("[Checkout] 更新订单客户信息:", {
|
|
1129
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1130
|
+
oldCustomer: this.store.currentCustomer,
|
|
1131
|
+
newCustomer: customer
|
|
1132
|
+
});
|
|
1133
|
+
this.store.currentCustomer = {
|
|
1134
|
+
customer_id: customer.customer_id,
|
|
1135
|
+
customer_name: customer.customer_name
|
|
1136
|
+
};
|
|
1137
|
+
if (this.store.localOrderData) {
|
|
1138
|
+
this.store.localOrderData.customer_id = customer.customer_id;
|
|
1139
|
+
this.store.localOrderData.customer_name = customer.customer_name;
|
|
1140
|
+
}
|
|
1141
|
+
console.log("[Checkout] 订单客户信息更新成功:", this.store.currentCustomer);
|
|
1142
|
+
} catch (error) {
|
|
1143
|
+
console.error("[Checkout] 更新订单客户信息失败:", error);
|
|
1144
|
+
await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
|
|
1145
|
+
throw error;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* 获取当前订单的客户信息
|
|
1150
|
+
*
|
|
1151
|
+
* @returns 当前客户信息,如果没有则返回 null
|
|
1152
|
+
*/
|
|
1153
|
+
getCurrentCustomer() {
|
|
1154
|
+
return this.store.currentCustomer || null;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* 检查订单是否需要手动同步
|
|
1158
|
+
*
|
|
1159
|
+
* 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
|
|
1160
|
+
*/
|
|
1161
|
+
needsManualSync() {
|
|
1162
|
+
var _a;
|
|
1163
|
+
try {
|
|
1164
|
+
if (!this.store.currentOrder || this.store.isOrderSynced) {
|
|
1165
|
+
return false;
|
|
1166
|
+
}
|
|
1167
|
+
const remainingAmount = this.calculateRemainingAmount();
|
|
1168
|
+
const remainingValue = parseFloat(remainingAmount);
|
|
1169
|
+
if (remainingValue > 0) {
|
|
1170
|
+
return false;
|
|
1171
|
+
}
|
|
1172
|
+
const allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(
|
|
1173
|
+
(item) => item.status !== "voided" && item.voucher_id
|
|
1174
|
+
);
|
|
1175
|
+
console.log("[Checkout] needsManualSync 检查结果:", {
|
|
1176
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1177
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1178
|
+
remainingAmount,
|
|
1179
|
+
hasPayments: ((_a = this.store.currentOrder.payment) == null ? void 0 : _a.length) > 0,
|
|
1180
|
+
allPaymentsHaveVoucherId,
|
|
1181
|
+
needsManualSync: allPaymentsHaveVoucherId
|
|
1182
|
+
});
|
|
1183
|
+
return allPaymentsHaveVoucherId;
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
console.error("[Checkout] needsManualSync 检查失败:", error);
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* 手动同步订单到后端
|
|
1191
|
+
*
|
|
1192
|
+
* 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
|
|
1193
|
+
*/
|
|
1194
|
+
async manualSyncOrderAsync() {
|
|
1195
|
+
var _a;
|
|
1196
|
+
try {
|
|
1197
|
+
if (!this.store.currentOrder) {
|
|
1198
|
+
return {
|
|
1199
|
+
success: false,
|
|
1200
|
+
message: "当前没有活跃订单,无法同步"
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
const orderUuid = this.store.currentOrder.uuid;
|
|
1204
|
+
const oldOrderId = this.store.currentOrder.order_id;
|
|
1205
|
+
if (this.store.isOrderSynced) {
|
|
1206
|
+
console.log("[Checkout] 订单已同步过,将执行更新操作");
|
|
1207
|
+
}
|
|
1208
|
+
console.log("[Checkout] 开始手动同步订单到后端:", {
|
|
1209
|
+
orderUuid,
|
|
1210
|
+
orderId: oldOrderId,
|
|
1211
|
+
totalAmount: this.store.currentOrder.total_amount,
|
|
1212
|
+
remainingAmount: this.calculateRemainingAmount()
|
|
1213
|
+
});
|
|
1214
|
+
const realOrderId = await this.syncOrderToBackendWithReturn(true);
|
|
1215
|
+
console.log("[Checkout] 手动同步订单完成:", {
|
|
1216
|
+
orderUuid,
|
|
1217
|
+
oldOrderId,
|
|
1218
|
+
realOrderId,
|
|
1219
|
+
isOrderSynced: this.store.isOrderSynced
|
|
1220
|
+
});
|
|
1221
|
+
const finalOrderId = this.store.currentOrder.order_id;
|
|
1222
|
+
const finalIsVirtual = this.isVirtualOrderId(finalOrderId);
|
|
1223
|
+
console.log("[Checkout] manualSyncOrderAsync 最终状态验证:", {
|
|
1224
|
+
返回的订单ID: realOrderId,
|
|
1225
|
+
存储的订单ID: finalOrderId,
|
|
1226
|
+
存储的ID是否虚拟: finalIsVirtual,
|
|
1227
|
+
是否一致: realOrderId === finalOrderId,
|
|
1228
|
+
同步状态: this.store.isOrderSynced
|
|
1229
|
+
});
|
|
1230
|
+
if (finalIsVirtual) {
|
|
1231
|
+
console.error("[Checkout] 严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1232
|
+
}
|
|
1233
|
+
if (realOrderId !== finalOrderId) {
|
|
1234
|
+
console.error("[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!");
|
|
1235
|
+
}
|
|
1236
|
+
return {
|
|
1237
|
+
success: true,
|
|
1238
|
+
message: "订单同步成功",
|
|
1239
|
+
orderId: realOrderId,
|
|
1240
|
+
// 直接返回从后端获取的真实订单ID
|
|
1241
|
+
orderUuid
|
|
1242
|
+
};
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
console.error("[Checkout] 手动同步订单失败:", error);
|
|
1245
|
+
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1246
|
+
return {
|
|
1247
|
+
success: false,
|
|
1248
|
+
message: `订单同步失败: ${errorMessage}`,
|
|
1249
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* 获取当前订单备注
|
|
1255
|
+
*
|
|
1256
|
+
* @returns 当前订单的备注内容,如果没有则返回空字符串
|
|
1257
|
+
*/
|
|
1258
|
+
getOrderNote() {
|
|
1259
|
+
if (!this.store.localOrderData) {
|
|
1260
|
+
console.log("[Checkout] 没有本地订单数据,无法获取备注");
|
|
1261
|
+
return "";
|
|
1262
|
+
}
|
|
1263
|
+
return this.store.localOrderData.shop_note || "";
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* 获取当前订单ID
|
|
1267
|
+
*
|
|
1268
|
+
* @returns 当前订单的ID,如果没有订单则返回null
|
|
1269
|
+
*/
|
|
1270
|
+
getCurrentOrderId() {
|
|
1271
|
+
if (!this.store.currentOrder) {
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
return this.store.currentOrder.order_id;
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* 保存订单并稍后支付
|
|
1278
|
+
*
|
|
1279
|
+
* 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
|
|
1280
|
+
* 适用于用户想要保存订单但稍后完成支付的场景
|
|
1281
|
+
*/
|
|
1282
|
+
async saveForLaterPaymentAsync() {
|
|
1283
|
+
var _a;
|
|
1284
|
+
try {
|
|
1285
|
+
if (!this.store.currentOrder) {
|
|
1286
|
+
return {
|
|
1287
|
+
success: false,
|
|
1288
|
+
message: "当前没有活跃订单,无法保存"
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
const orderUuid = this.store.currentOrder.uuid;
|
|
1292
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
1293
|
+
console.log("[Checkout] 开始保存订单并稍后支付:", {
|
|
1294
|
+
orderUuid,
|
|
1295
|
+
orderId: currentOrderId,
|
|
1296
|
+
totalAmount: this.store.currentOrder.total_amount
|
|
1297
|
+
});
|
|
1298
|
+
const allPaymentItems = await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
1299
|
+
const filteredPaymentItems = allPaymentItems.filter(
|
|
1300
|
+
(payment) => !payment.voucher_id || payment.voucher_id.trim() === ""
|
|
1301
|
+
);
|
|
1302
|
+
const voucherItems = allPaymentItems.filter(
|
|
1303
|
+
(payment) => payment.voucher_id && payment.voucher_id.trim() !== ""
|
|
1304
|
+
);
|
|
1305
|
+
console.log("[Checkout] 支付项过滤结果:", {
|
|
1306
|
+
总支付项: allPaymentItems.length,
|
|
1307
|
+
过滤后支付项: filteredPaymentItems.length,
|
|
1308
|
+
被过滤的代金券项: voucherItems.length,
|
|
1309
|
+
代金券详情: voucherItems.map((item) => ({
|
|
1310
|
+
uuid: item.uuid,
|
|
1311
|
+
code: item.code,
|
|
1312
|
+
amount: item.amount,
|
|
1313
|
+
voucherId: item.voucher_id
|
|
1314
|
+
})),
|
|
1315
|
+
保留的支付项: filteredPaymentItems.map((item) => ({
|
|
1316
|
+
uuid: item.uuid,
|
|
1317
|
+
code: item.code,
|
|
1318
|
+
amount: item.amount
|
|
1319
|
+
}))
|
|
1320
|
+
});
|
|
1321
|
+
const realOrderId = await this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
|
|
1322
|
+
console.log("[Checkout] 保存订单完成:", {
|
|
1323
|
+
orderUuid,
|
|
1324
|
+
oldOrderId: currentOrderId,
|
|
1325
|
+
realOrderId,
|
|
1326
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1327
|
+
filteredPaymentsCount: filteredPaymentItems.length
|
|
1328
|
+
});
|
|
1329
|
+
const finalOrderId = this.store.currentOrder.order_id;
|
|
1330
|
+
console.log("[Checkout] saveForLaterPaymentAsync 最终状态验证:", {
|
|
1331
|
+
返回的订单ID: realOrderId,
|
|
1332
|
+
存储的订单ID: finalOrderId,
|
|
1333
|
+
是否一致: realOrderId === finalOrderId,
|
|
1334
|
+
同步状态: this.store.isOrderSynced
|
|
1335
|
+
});
|
|
1336
|
+
return {
|
|
1337
|
+
success: true,
|
|
1338
|
+
message: "订单保存成功,可稍后继续支付",
|
|
1339
|
+
orderId: realOrderId,
|
|
1340
|
+
orderUuid
|
|
1341
|
+
};
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
console.error("[Checkout] 保存订单失败:", error);
|
|
1344
|
+
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1345
|
+
return {
|
|
1346
|
+
success: false,
|
|
1347
|
+
message: `订单保存失败: ${errorMessage}`,
|
|
1348
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* 获取当前商店折扣金额
|
|
1354
|
+
*
|
|
1355
|
+
* @returns 当前的商店折扣金额,如果没有则返回0
|
|
1356
|
+
*/
|
|
1357
|
+
getShopDiscount() {
|
|
1358
|
+
var _a;
|
|
1359
|
+
if (((_a = this.store.localOrderData) == null ? void 0 : _a.shop_discount) !== void 0) {
|
|
1360
|
+
return this.store.localOrderData.shop_discount;
|
|
1361
|
+
}
|
|
1362
|
+
if (this.store.cartSummary) {
|
|
1363
|
+
const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
|
|
1364
|
+
if (shopDiscountItem) {
|
|
1365
|
+
return shopDiscountItem.value;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
return 0;
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* 更新订单商店折扣
|
|
1372
|
+
*
|
|
1373
|
+
* 同时更新cartSummary和localOrderData中的shop_discount值
|
|
1374
|
+
*
|
|
1375
|
+
* @param discountAmount 商店折扣金额
|
|
1376
|
+
*/
|
|
1377
|
+
async updateShopDiscountAsync(discountAmount) {
|
|
1378
|
+
var _a, _b;
|
|
1379
|
+
try {
|
|
1380
|
+
const oldDiscount = this.getShopDiscount();
|
|
1381
|
+
console.log("[Checkout] 更新商店折扣:", {
|
|
1382
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1383
|
+
oldDiscount,
|
|
1384
|
+
newDiscount: discountAmount
|
|
1385
|
+
});
|
|
1386
|
+
if (this.store.cartSummary) {
|
|
1387
|
+
const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
|
|
1388
|
+
if (shopDiscountItem) {
|
|
1389
|
+
shopDiscountItem.value = discountAmount;
|
|
1390
|
+
console.log("[Checkout] cartSummary 中的商店折扣已更新");
|
|
1391
|
+
} else {
|
|
1392
|
+
this.store.cartSummary.push({
|
|
1393
|
+
key: "shop_discount",
|
|
1394
|
+
value: discountAmount,
|
|
1395
|
+
hidden: true,
|
|
1396
|
+
label: "Shop Discount"
|
|
1397
|
+
});
|
|
1398
|
+
console.log("[Checkout] cartSummary 中已添加新的商店折扣项");
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
if (this.store.localOrderData) {
|
|
1402
|
+
this.store.localOrderData.shop_discount = discountAmount;
|
|
1403
|
+
console.log("[Checkout] localOrderData 中的商店折扣已更新");
|
|
1404
|
+
} else {
|
|
1405
|
+
console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
|
|
1406
|
+
}
|
|
1407
|
+
if (this.store.currentOrder && this.store.cartSummary) {
|
|
1408
|
+
const updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
|
|
1409
|
+
console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
|
|
1410
|
+
this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
|
|
1411
|
+
this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
|
|
1412
|
+
}
|
|
1413
|
+
await this.updateStateAmountToRemaining();
|
|
1414
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnShopDiscountChanged, {
|
|
1415
|
+
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1416
|
+
oldDiscount,
|
|
1417
|
+
newDiscount: discountAmount,
|
|
1418
|
+
timestamp: Date.now()
|
|
1419
|
+
});
|
|
1420
|
+
console.log("[Checkout] 商店折扣更新成功:", {
|
|
1421
|
+
oldDiscount,
|
|
1422
|
+
newDiscount: discountAmount
|
|
1423
|
+
});
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
console.error("[Checkout] 更新商店折扣失败:", error);
|
|
1426
|
+
await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
|
|
1427
|
+
throw error;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* 更新订单备注
|
|
1432
|
+
*
|
|
1433
|
+
* @param note 订单备注内容
|
|
1434
|
+
*/
|
|
1435
|
+
async updateOrderNoteAsync(note) {
|
|
1436
|
+
var _a, _b;
|
|
1437
|
+
try {
|
|
1438
|
+
if (!this.store.localOrderData) {
|
|
1439
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1440
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1441
|
+
"没有本地订单数据,无法更新备注"
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
console.log("[Checkout] 更新订单备注:", {
|
|
1445
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1446
|
+
oldNote: this.store.localOrderData.shop_note,
|
|
1447
|
+
newNote: note
|
|
1448
|
+
});
|
|
1449
|
+
const oldNote = this.store.localOrderData.shop_note;
|
|
1450
|
+
this.store.localOrderData.shop_note = note;
|
|
1451
|
+
if (this.store.currentOrder) {
|
|
1452
|
+
try {
|
|
1453
|
+
const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1454
|
+
if (orderInPayment && orderInPayment.note !== void 0) {
|
|
1455
|
+
console.log("[Checkout] 同步备注到Payment模块的订单数据中");
|
|
1456
|
+
}
|
|
1457
|
+
} catch (syncError) {
|
|
1458
|
+
console.warn("[Checkout] 同步备注到Payment模块失败,但本地更新成功:", syncError);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
|
|
1462
|
+
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1463
|
+
oldNote,
|
|
1464
|
+
newNote: note,
|
|
1465
|
+
timestamp: Date.now()
|
|
1466
|
+
});
|
|
1467
|
+
console.log("[Checkout] 订单备注更新成功:", {
|
|
1468
|
+
oldNote,
|
|
1469
|
+
newNote: note
|
|
1470
|
+
});
|
|
1471
|
+
} catch (error) {
|
|
1472
|
+
console.error("[Checkout] 更新订单备注失败:", error);
|
|
1473
|
+
await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
|
|
1474
|
+
throw error;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
619
1477
|
/**
|
|
620
1478
|
* 设置状态
|
|
621
1479
|
*/
|
|
@@ -660,6 +1518,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
660
1518
|
async handlePaymentSuccess(data) {
|
|
661
1519
|
var _a;
|
|
662
1520
|
await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
1521
|
+
await this.updateStateAmountToRemaining();
|
|
663
1522
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
664
1523
|
orderUuid: data.orderUuid,
|
|
665
1524
|
paymentMethodCode: "",
|
|
@@ -731,6 +1590,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
731
1590
|
const random = Math.floor(Math.random() * 1e4).toString().padStart(4, "0");
|
|
732
1591
|
return `local_order_${timestamp}_${random}`;
|
|
733
1592
|
}
|
|
1593
|
+
/**
|
|
1594
|
+
* 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
|
|
1595
|
+
*
|
|
1596
|
+
* @param date 要格式化的日期对象
|
|
1597
|
+
* @returns 格式化后的日期时间字符串
|
|
1598
|
+
*/
|
|
1599
|
+
formatDateTime(date) {
|
|
1600
|
+
const year = date.getFullYear();
|
|
1601
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
1602
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
1603
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
1604
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
1605
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
1606
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
1607
|
+
}
|
|
734
1608
|
/**
|
|
735
1609
|
* 从购物车小计数据中提取金额信息
|
|
736
1610
|
*/
|
|
@@ -790,7 +1664,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
790
1664
|
async preloadPaymentMethods() {
|
|
791
1665
|
try {
|
|
792
1666
|
console.log("[Checkout] 预加载支付方式...");
|
|
793
|
-
const methods = await this.
|
|
1667
|
+
const methods = await this.payment.getPayMethodListAsync();
|
|
794
1668
|
this.store.paymentMethods = methods;
|
|
795
1669
|
console.log(`[Checkout] 预加载完成,共 ${methods.length} 种支付方式`);
|
|
796
1670
|
} catch (error) {
|
|
@@ -813,12 +1687,381 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
813
1687
|
* 计算已支付金额
|
|
814
1688
|
*/
|
|
815
1689
|
calculatePaidAmount() {
|
|
816
|
-
if (!this.store.currentOrder)
|
|
1690
|
+
if (!this.store.currentOrder) {
|
|
1691
|
+
console.log("[Checkout] calculatePaidAmount: 没有当前订单");
|
|
817
1692
|
return "0.00";
|
|
818
|
-
|
|
819
|
-
|
|
1693
|
+
}
|
|
1694
|
+
const payments = this.store.currentOrder.payment || [];
|
|
1695
|
+
console.log("[Checkout] calculatePaidAmount: 支付项详情:", {
|
|
1696
|
+
paymentCount: payments.length,
|
|
1697
|
+
payments: payments.map((p) => ({
|
|
1698
|
+
uuid: p.uuid,
|
|
1699
|
+
amount: p.amount,
|
|
1700
|
+
code: p.code,
|
|
1701
|
+
status: p.status
|
|
1702
|
+
}))
|
|
1703
|
+
});
|
|
1704
|
+
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
1705
|
+
const amount = parseFloat(payment.amount || "0");
|
|
1706
|
+
console.log(`[Checkout] 计算支付项: ${payment.code} = ${amount}`);
|
|
1707
|
+
return sum + amount;
|
|
820
1708
|
}, 0);
|
|
821
|
-
|
|
1709
|
+
const result = paidAmount.toFixed(2);
|
|
1710
|
+
console.log("[Checkout] calculatePaidAmount: 计算结果 =", result);
|
|
1711
|
+
return result;
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* 计算剩余未支付金额
|
|
1715
|
+
*/
|
|
1716
|
+
calculateRemainingAmount() {
|
|
1717
|
+
if (!this.store.currentOrder) {
|
|
1718
|
+
console.log("[Checkout] calculateRemainingAmount: 没有当前订单");
|
|
1719
|
+
return "0.00";
|
|
1720
|
+
}
|
|
1721
|
+
const totalAmount = parseFloat(this.store.currentOrder.total_amount || "0");
|
|
1722
|
+
const paidAmount = parseFloat(this.calculatePaidAmount());
|
|
1723
|
+
const remainingAmount = totalAmount - paidAmount;
|
|
1724
|
+
const result = Math.max(0, remainingAmount).toFixed(2);
|
|
1725
|
+
console.log("[Checkout] calculateRemainingAmount: 计算详情:", {
|
|
1726
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1727
|
+
totalAmount: totalAmount.toFixed(2),
|
|
1728
|
+
paidAmount: paidAmount.toFixed(2),
|
|
1729
|
+
calculatedRemaining: remainingAmount.toFixed(2),
|
|
1730
|
+
finalResult: result
|
|
1731
|
+
});
|
|
1732
|
+
return result;
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* 更新 stateAmount 为当前剩余未支付金额
|
|
1736
|
+
*/
|
|
1737
|
+
async updateStateAmountToRemaining() {
|
|
1738
|
+
var _a;
|
|
1739
|
+
try {
|
|
1740
|
+
const remainingAmount = this.calculateRemainingAmount();
|
|
1741
|
+
const currentStateAmount = this.store.stateAmount;
|
|
1742
|
+
console.log("[Checkout] updateStateAmountToRemaining: 状态检查:", {
|
|
1743
|
+
calculatedRemainingAmount: remainingAmount,
|
|
1744
|
+
currentStateAmount,
|
|
1745
|
+
needsUpdate: remainingAmount !== currentStateAmount,
|
|
1746
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
1747
|
+
});
|
|
1748
|
+
if (remainingAmount !== currentStateAmount) {
|
|
1749
|
+
this.store.stateAmount = remainingAmount;
|
|
1750
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
1751
|
+
oldAmount: currentStateAmount,
|
|
1752
|
+
newAmount: remainingAmount,
|
|
1753
|
+
timestamp: Date.now()
|
|
1754
|
+
});
|
|
1755
|
+
console.log("[Checkout] stateAmount 已自动更新为剩余金额:", {
|
|
1756
|
+
oldAmount: currentStateAmount,
|
|
1757
|
+
newAmount: remainingAmount
|
|
1758
|
+
});
|
|
1759
|
+
} else {
|
|
1760
|
+
console.log("[Checkout] stateAmount 无需更新,当前值已是最新:", {
|
|
1761
|
+
stateAmount: currentStateAmount,
|
|
1762
|
+
remainingAmount
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
await this.checkOrderPaymentCompletion();
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
console.error("[Checkout] 更新 stateAmount 为剩余金额失败:", error);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* 检查订单支付是否完成
|
|
1772
|
+
*
|
|
1773
|
+
* 当剩余待付款金额 <= 0 时,触发订单支付完成事件
|
|
1774
|
+
*/
|
|
1775
|
+
async checkOrderPaymentCompletion() {
|
|
1776
|
+
var _a, _b;
|
|
1777
|
+
try {
|
|
1778
|
+
if (!this.store.currentOrder) {
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
const remainingAmount = this.calculateRemainingAmount();
|
|
1782
|
+
const remainingValue = parseFloat(remainingAmount);
|
|
1783
|
+
if (remainingValue <= 0) {
|
|
1784
|
+
const totalAmount = this.store.currentOrder.total_amount;
|
|
1785
|
+
const paidAmount = this.calculatePaidAmount();
|
|
1786
|
+
console.log("[Checkout] 检测到订单支付完成:", {
|
|
1787
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1788
|
+
orderId: this.store.currentOrder.order_id,
|
|
1789
|
+
totalAmount,
|
|
1790
|
+
paidAmount,
|
|
1791
|
+
remainingAmount,
|
|
1792
|
+
isOrderSynced: this.store.isOrderSynced
|
|
1793
|
+
});
|
|
1794
|
+
const allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(
|
|
1795
|
+
(item) => item.status !== "voided" && item.voucher_id
|
|
1796
|
+
);
|
|
1797
|
+
console.log("[Checkout] 支付项voucher_id检查:", {
|
|
1798
|
+
paymentCount: ((_a = this.store.currentOrder.payment) == null ? void 0 : _a.length) || 0,
|
|
1799
|
+
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
1800
|
+
paymentItems: (_b = this.store.currentOrder.payment) == null ? void 0 : _b.map((p) => ({
|
|
1801
|
+
uuid: p.uuid,
|
|
1802
|
+
code: p.code,
|
|
1803
|
+
amount: p.amount,
|
|
1804
|
+
voucher_id: p.voucher_id,
|
|
1805
|
+
status: p.status
|
|
1806
|
+
}))
|
|
1807
|
+
});
|
|
1808
|
+
if (!this.store.isOrderSynced) {
|
|
1809
|
+
if (allPaymentsHaveVoucherId) {
|
|
1810
|
+
console.log("[Checkout] 所有支付项均为代金券类型,跳过订单同步");
|
|
1811
|
+
} else {
|
|
1812
|
+
console.log("[Checkout] 支付完成但订单未同步,开始同步订单到后端...");
|
|
1813
|
+
await this.syncOrderToBackend();
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
|
|
1817
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1818
|
+
orderId: this.store.currentOrder.order_id,
|
|
1819
|
+
totalAmount,
|
|
1820
|
+
paidAmount,
|
|
1821
|
+
remainingAmount,
|
|
1822
|
+
timestamp: Date.now()
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
} catch (error) {
|
|
1826
|
+
console.error("[Checkout] 检查订单支付完成状态失败:", error);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* 判断支付方式是否需要同步订单到后端
|
|
1831
|
+
*
|
|
1832
|
+
* 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
|
|
1833
|
+
*
|
|
1834
|
+
* @param paymentCode 支付方式代码
|
|
1835
|
+
* @param paymentType 支付方式类型
|
|
1836
|
+
* @returns 是否需要同步订单
|
|
1837
|
+
*/
|
|
1838
|
+
shouldSyncOrderForPayment(paymentCode, paymentType) {
|
|
1839
|
+
const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
|
|
1840
|
+
const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
|
|
1841
|
+
const cashIdentifiers = ["CASHMANUAL", "CASH", "MANUAL"];
|
|
1842
|
+
if (cashIdentifiers.some((id) => codeUpper.includes(id) || typeUpper.includes(id))) {
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
if (paymentCode === import_types2.PaymentMethodType.Cash || paymentType === import_types2.PaymentMethodType.Cash) {
|
|
1846
|
+
return false;
|
|
1847
|
+
}
|
|
1848
|
+
if (codeUpper.includes("CUSTOM") || typeUpper.includes("CUSTOM")) {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
return true;
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* 同步订单到后端
|
|
1855
|
+
*
|
|
1856
|
+
* 调用后端 /order/checkout 接口创建真实订单
|
|
1857
|
+
*/
|
|
1858
|
+
/**
|
|
1859
|
+
* 判断订单ID是否为本地生成的虚拟ID
|
|
1860
|
+
*
|
|
1861
|
+
* @param orderId 订单ID
|
|
1862
|
+
* @returns true 表示是虚拟ID,false 表示是真实的后端ID
|
|
1863
|
+
*/
|
|
1864
|
+
isVirtualOrderId(orderId) {
|
|
1865
|
+
return orderId.startsWith("local_order_");
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* 同步订单到后端并返回真实订单ID
|
|
1869
|
+
*
|
|
1870
|
+
* @param isManual 是否为手动同步,默认为 false
|
|
1871
|
+
* @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
|
|
1872
|
+
* @returns 后端返回的真实订单ID
|
|
1873
|
+
*/
|
|
1874
|
+
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
1875
|
+
var _a, _b, _c, _d;
|
|
1876
|
+
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
1877
|
+
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
1878
|
+
}
|
|
1879
|
+
const syncType = isManual ? "手动" : "自动";
|
|
1880
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
1881
|
+
const hasRealOrderId = currentOrderId && !this.isVirtualOrderId(currentOrderId);
|
|
1882
|
+
let isUpdateOperation = false;
|
|
1883
|
+
let reason = "";
|
|
1884
|
+
if (this.store.isOrderSynced) {
|
|
1885
|
+
isUpdateOperation = true;
|
|
1886
|
+
reason = "订单已同步过";
|
|
1887
|
+
} else if (hasRealOrderId) {
|
|
1888
|
+
isUpdateOperation = true;
|
|
1889
|
+
reason = "有真实订单ID";
|
|
1890
|
+
} else {
|
|
1891
|
+
isUpdateOperation = false;
|
|
1892
|
+
reason = "既未同步也无真实ID";
|
|
1893
|
+
}
|
|
1894
|
+
const operation = isUpdateOperation ? "更新" : "创建";
|
|
1895
|
+
console.log("[Checkout] 操作类型判断详情:", {
|
|
1896
|
+
currentOrderId,
|
|
1897
|
+
hasRealOrderId,
|
|
1898
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1899
|
+
isManual,
|
|
1900
|
+
reason,
|
|
1901
|
+
finalDecision: operation
|
|
1902
|
+
});
|
|
1903
|
+
console.log(`[Checkout] 开始${syncType}${operation}订单到后端...`, {
|
|
1904
|
+
currentOrderId,
|
|
1905
|
+
isVirtualId: this.isVirtualOrderId(currentOrderId || ""),
|
|
1906
|
+
operation,
|
|
1907
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1908
|
+
isOrderSynced: this.store.isOrderSynced
|
|
1909
|
+
});
|
|
1910
|
+
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
1911
|
+
console.log("[Checkout] 获取到支付项:", {
|
|
1912
|
+
count: paymentItems.length,
|
|
1913
|
+
isCustomFiltered: !!customPaymentItems,
|
|
1914
|
+
methods: paymentItems.map((p) => p.code),
|
|
1915
|
+
totalAmount: paymentItems.reduce((sum, p) => sum + parseFloat(p.amount), 0).toFixed(2),
|
|
1916
|
+
paymentDetails: paymentItems.map((p) => {
|
|
1917
|
+
var _a2;
|
|
1918
|
+
return {
|
|
1919
|
+
uuid: p.uuid,
|
|
1920
|
+
code: p.code,
|
|
1921
|
+
amount: p.amount,
|
|
1922
|
+
uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
|
|
1923
|
+
voucherId: p.voucher_id
|
|
1924
|
+
};
|
|
1925
|
+
})
|
|
1926
|
+
});
|
|
1927
|
+
const orderParams = {
|
|
1928
|
+
...this.store.localOrderData,
|
|
1929
|
+
type: this.store.localOrderData.type,
|
|
1930
|
+
platform: this.store.localOrderData.platform,
|
|
1931
|
+
payments: paymentItems,
|
|
1932
|
+
// 添加支付项
|
|
1933
|
+
customer_id: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id,
|
|
1934
|
+
// 添加客户ID
|
|
1935
|
+
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
1936
|
+
// core 有
|
|
1937
|
+
tax_title: this.otherParams.tax_title,
|
|
1938
|
+
// core 没有
|
|
1939
|
+
tax_rate: this.otherParams.tax_rate,
|
|
1940
|
+
// core 有
|
|
1941
|
+
tax_country_code: this.otherParams.tax_country_code,
|
|
1942
|
+
// core 没有
|
|
1943
|
+
currency_code: this.otherParams.currency_code,
|
|
1944
|
+
currency_symbol: this.otherParams.currency_symbol,
|
|
1945
|
+
currency_format: this.otherParams.currency_format,
|
|
1946
|
+
is_deposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0,
|
|
1947
|
+
deposit_amount: ((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount) || "0.00",
|
|
1948
|
+
// surcharge_fee: this.otherParams.surcharge_fee,
|
|
1949
|
+
// surcharges: ,
|
|
1950
|
+
note: this.store.localOrderData.shop_note
|
|
1951
|
+
// deposit_amount:
|
|
1952
|
+
};
|
|
1953
|
+
if (isUpdateOperation) {
|
|
1954
|
+
if (this.isVirtualOrderId(currentOrderId)) {
|
|
1955
|
+
console.error("[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!", {
|
|
1956
|
+
currentOrderId,
|
|
1957
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1958
|
+
reason,
|
|
1959
|
+
orderUuid: this.store.currentOrder.uuid
|
|
1960
|
+
});
|
|
1961
|
+
console.log("[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理");
|
|
1962
|
+
console.log("[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性");
|
|
1963
|
+
} else {
|
|
1964
|
+
orderParams.order_id = currentOrderId;
|
|
1965
|
+
console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
|
|
1966
|
+
}
|
|
1967
|
+
} else {
|
|
1968
|
+
console.log("[Checkout] 创建新订单操作");
|
|
1969
|
+
}
|
|
1970
|
+
const checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
1971
|
+
console.log("[Checkout] 后端返回的响应数据:", {
|
|
1972
|
+
status: checkoutResponse == null ? void 0 : checkoutResponse.status,
|
|
1973
|
+
code: checkoutResponse == null ? void 0 : checkoutResponse.code,
|
|
1974
|
+
message: checkoutResponse == null ? void 0 : checkoutResponse.message,
|
|
1975
|
+
data: checkoutResponse == null ? void 0 : checkoutResponse.data
|
|
1976
|
+
});
|
|
1977
|
+
let realOrderId;
|
|
1978
|
+
if (isUpdateOperation) {
|
|
1979
|
+
realOrderId = currentOrderId;
|
|
1980
|
+
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
1981
|
+
} else {
|
|
1982
|
+
let extractedOrderId = (_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id;
|
|
1983
|
+
if (!extractedOrderId) {
|
|
1984
|
+
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
1985
|
+
}
|
|
1986
|
+
if (extractedOrderId !== void 0 && extractedOrderId !== null) {
|
|
1987
|
+
extractedOrderId = String(extractedOrderId);
|
|
1988
|
+
}
|
|
1989
|
+
if (!extractedOrderId) {
|
|
1990
|
+
throw new Error("后端返回的订单信息中未包含订单ID");
|
|
1991
|
+
}
|
|
1992
|
+
realOrderId = extractedOrderId;
|
|
1993
|
+
console.log("[Checkout] 订单创建成功,真实订单ID:", realOrderId);
|
|
1994
|
+
console.log("[Checkout] 准备替换订单ID:", {
|
|
1995
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1996
|
+
oldOrderId: this.store.currentOrder.order_id,
|
|
1997
|
+
newOrderId: realOrderId
|
|
1998
|
+
});
|
|
1999
|
+
try {
|
|
2000
|
+
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
2001
|
+
this.store.currentOrder.uuid,
|
|
2002
|
+
realOrderId
|
|
2003
|
+
);
|
|
2004
|
+
console.log("[Checkout] Payment模块替换订单ID结果:", {
|
|
2005
|
+
wasSuccessful: !!updatedOrder,
|
|
2006
|
+
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2007
|
+
expectedOrderId: realOrderId
|
|
2008
|
+
});
|
|
2009
|
+
if (updatedOrder) {
|
|
2010
|
+
console.log("[Checkout] Payment模块返回的更新后订单:", {
|
|
2011
|
+
uuid: updatedOrder.uuid,
|
|
2012
|
+
orderId: updatedOrder.order_id,
|
|
2013
|
+
totalAmount: updatedOrder.total_amount
|
|
2014
|
+
});
|
|
2015
|
+
this.store.currentOrder = updatedOrder;
|
|
2016
|
+
console.log("[Checkout] 订单ID替换成功,当前订单ID:", this.store.currentOrder.order_id);
|
|
2017
|
+
} else {
|
|
2018
|
+
console.error("[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换");
|
|
2019
|
+
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2020
|
+
this.store.currentOrder.order_id = realOrderId;
|
|
2021
|
+
console.log("[Checkout] 手动设置订单ID:", {
|
|
2022
|
+
替换前: beforeManualUpdate,
|
|
2023
|
+
替换后: this.store.currentOrder.order_id,
|
|
2024
|
+
目标ID: realOrderId
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
} catch (error) {
|
|
2028
|
+
console.error("[Checkout] 调用Payment模块替换订单ID时发生错误:", error);
|
|
2029
|
+
this.store.currentOrder.order_id = realOrderId;
|
|
2030
|
+
console.log("[Checkout] 错误恢复:手动设置订单ID:", realOrderId);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
this.store.isOrderSynced = true;
|
|
2034
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSynced, {
|
|
2035
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2036
|
+
realOrderId,
|
|
2037
|
+
virtualOrderId: this.store.currentOrder.order_id,
|
|
2038
|
+
timestamp: Date.now(),
|
|
2039
|
+
isManual,
|
|
2040
|
+
response: checkoutResponse
|
|
2041
|
+
});
|
|
2042
|
+
const finalOrderId = this.store.currentOrder.order_id;
|
|
2043
|
+
const finalIsVirtual = this.isVirtualOrderId(finalOrderId || "");
|
|
2044
|
+
console.log(`[Checkout] ${syncType}${operation}订单到后端完成`, {
|
|
2045
|
+
返回的订单ID: realOrderId,
|
|
2046
|
+
当前存储的订单ID: finalOrderId,
|
|
2047
|
+
是否还是虚拟ID: finalIsVirtual,
|
|
2048
|
+
是否同步: this.store.isOrderSynced
|
|
2049
|
+
});
|
|
2050
|
+
if (finalIsVirtual && !isUpdateOperation) {
|
|
2051
|
+
console.warn("[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题");
|
|
2052
|
+
}
|
|
2053
|
+
return realOrderId;
|
|
2054
|
+
}
|
|
2055
|
+
async syncOrderToBackend() {
|
|
2056
|
+
try {
|
|
2057
|
+
await this.syncOrderToBackendWithReturn(false);
|
|
2058
|
+
} catch (error) {
|
|
2059
|
+
console.error("[Checkout] 同步订单到后端失败:", error);
|
|
2060
|
+
await this.handleError(
|
|
2061
|
+
new Error(`订单同步失败: ${error instanceof Error ? error.message : String(error)}`),
|
|
2062
|
+
import_types.CheckoutErrorType.OrderCreationFailed
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
822
2065
|
}
|
|
823
2066
|
/**
|
|
824
2067
|
* 获取状态消息
|
|
@@ -848,11 +2091,90 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
848
2091
|
return "";
|
|
849
2092
|
}
|
|
850
2093
|
}
|
|
2094
|
+
async setOtherParams(params, { cover = false } = {}) {
|
|
2095
|
+
if (cover) {
|
|
2096
|
+
this.otherParams = params;
|
|
2097
|
+
} else {
|
|
2098
|
+
this.otherParams = { ...this.otherParams, ...params };
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
/**
|
|
2102
|
+
* 通过订单ID编辑订单备注
|
|
2103
|
+
*
|
|
2104
|
+
* 用于修改已同步到后端的订单备注,通常在支付成功后的弹窗中使用
|
|
2105
|
+
*
|
|
2106
|
+
* @param orderId 后端订单ID
|
|
2107
|
+
* @param note 新的订单备注
|
|
2108
|
+
* @returns 修改结果
|
|
2109
|
+
*/
|
|
2110
|
+
async editOrderNoteByOrderIdAsync(orderId, note) {
|
|
2111
|
+
try {
|
|
2112
|
+
console.log("[Checkout] 开始编辑订单备注:", {
|
|
2113
|
+
orderId,
|
|
2114
|
+
note,
|
|
2115
|
+
noteLength: note.length
|
|
2116
|
+
});
|
|
2117
|
+
if (!orderId) {
|
|
2118
|
+
return {
|
|
2119
|
+
success: false,
|
|
2120
|
+
message: "订单ID不能为空",
|
|
2121
|
+
orderId
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
const response = await this.request.put(`/shop/order/order/${orderId}/note`, {
|
|
2125
|
+
note
|
|
2126
|
+
});
|
|
2127
|
+
console.log("[Checkout] 订单备注编辑响应:", {
|
|
2128
|
+
orderId,
|
|
2129
|
+
status: response.status,
|
|
2130
|
+
message: response.message,
|
|
2131
|
+
response
|
|
2132
|
+
});
|
|
2133
|
+
if (response.status === true || response.status === 200) {
|
|
2134
|
+
console.log(`[Checkout] 订单 ${orderId} 备注修改成功`);
|
|
2135
|
+
if (this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))) {
|
|
2136
|
+
console.log("[Checkout] 更新本地订单备注状态");
|
|
2137
|
+
const previousNote = this.getOrderNote();
|
|
2138
|
+
if (this.store.localOrderData) {
|
|
2139
|
+
this.store.localOrderData.shop_note = note;
|
|
2140
|
+
}
|
|
2141
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
|
|
2142
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2143
|
+
oldNote: previousNote,
|
|
2144
|
+
newNote: note,
|
|
2145
|
+
timestamp: Date.now()
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
return {
|
|
2149
|
+
success: true,
|
|
2150
|
+
message: response.message || "订单备注修改成功",
|
|
2151
|
+
orderId
|
|
2152
|
+
};
|
|
2153
|
+
} else {
|
|
2154
|
+
const errorMessage = response.message || "订单备注修改失败";
|
|
2155
|
+
console.error(`[Checkout] 订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
2156
|
+
return {
|
|
2157
|
+
success: false,
|
|
2158
|
+
message: errorMessage,
|
|
2159
|
+
orderId
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
} catch (error) {
|
|
2163
|
+
console.error("[Checkout] 编辑订单备注失败:", error);
|
|
2164
|
+
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2165
|
+
return {
|
|
2166
|
+
success: false,
|
|
2167
|
+
message: `编辑订单备注失败: ${errorMessage}`,
|
|
2168
|
+
orderId
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
851
2172
|
async destroy() {
|
|
852
2173
|
var _a, _b, _c, _d;
|
|
2174
|
+
this.payment.wallet.clearAllCache();
|
|
853
2175
|
this.core.effects.offByModuleDestroy(this.name);
|
|
854
|
-
await ((_b = (_a = this.
|
|
855
|
-
await ((_d = (_c = this.
|
|
2176
|
+
await ((_b = (_a = this.order) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a));
|
|
2177
|
+
await ((_d = (_c = this.payment) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c));
|
|
856
2178
|
this.core.unregisterModule(this);
|
|
857
2179
|
console.log("[Checkout] 已销毁");
|
|
858
2180
|
}
|