@pisell/pisellos 0.0.229 → 0.0.231

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.
Files changed (65) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +57 -94
  11. package/dist/modules/Payment/index.js +810 -1109
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +358 -50
  15. package/dist/modules/Payment/types.js +103 -4
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  24. package/dist/solution/Checkout/index.d.ts +415 -0
  25. package/dist/solution/Checkout/index.js +3622 -0
  26. package/dist/solution/Checkout/types.d.ts +737 -0
  27. package/dist/solution/Checkout/types.js +137 -0
  28. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  29. package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
  30. package/dist/solution/index.d.ts +1 -0
  31. package/dist/solution/index.js +2 -1
  32. package/lib/modules/Order/index.d.ts +13 -2
  33. package/lib/modules/Order/index.js +58 -1
  34. package/lib/modules/Order/types.d.ts +43 -0
  35. package/lib/modules/Payment/cash.d.ts +8 -0
  36. package/lib/modules/Payment/cash.js +14 -1
  37. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  38. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  39. package/lib/modules/Payment/eftpos.js +1 -1
  40. package/lib/modules/Payment/index.d.ts +57 -94
  41. package/lib/modules/Payment/index.js +363 -525
  42. package/lib/modules/Payment/mx51.d.ts +0 -0
  43. package/lib/modules/Payment/mx51.js +0 -0
  44. package/lib/modules/Payment/types.d.ts +358 -50
  45. package/lib/modules/Payment/types.js +37 -2
  46. package/lib/modules/Payment/utils.d.ts +17 -0
  47. package/lib/modules/Payment/utils.js +67 -0
  48. package/lib/modules/Payment/walletpass.d.ts +96 -0
  49. package/lib/modules/Payment/walletpass.js +304 -0
  50. package/lib/modules/Schedule/index.d.ts +9 -0
  51. package/lib/modules/Schedule/index.js +36 -0
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  54. package/lib/solution/Checkout/index.d.ts +415 -0
  55. package/lib/solution/Checkout/index.js +2107 -0
  56. package/lib/solution/Checkout/types.d.ts +737 -0
  57. package/lib/solution/Checkout/types.js +80 -0
  58. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  59. package/lib/solution/Checkout/utils/index.js +266 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/package.json +1 -1
  63. package/dist/modules/Payment/wallet.d.ts +0 -11
  64. package/lib/modules/Payment/wallet.d.ts +0 -11
  65. package/lib/modules/Payment/wallet.js +0 -51
@@ -0,0 +1,2107 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/solution/Checkout/index.ts
21
+ var Checkout_exports = {};
22
+ __export(Checkout_exports, {
23
+ CheckoutImpl: () => CheckoutImpl
24
+ });
25
+ module.exports = __toCommonJS(Checkout_exports);
26
+ var import_BaseModule = require("../../modules/BaseModule");
27
+ var import_Order = require("../../modules/Order");
28
+ var import_Payment = require("../../modules/Payment");
29
+ var import_types = require("./types");
30
+ var import_types2 = require("../../modules/Payment/types");
31
+ var import_utils = require("./utils");
32
+ __reExport(Checkout_exports, require("./types"), module.exports);
33
+ var CheckoutImpl = class extends import_BaseModule.BaseModule {
34
+ constructor(name, version) {
35
+ super(name || "checkout", version || "1.0.0");
36
+ this.defaultName = "checkout";
37
+ this.defaultVersion = "1.0.0";
38
+ this.isSolution = true;
39
+ this.otherParams = {};
40
+ }
41
+ async initialize(core, options) {
42
+ this.core = core;
43
+ this.otherParams = options.otherParams || {};
44
+ this.request = core.getPlugin("request");
45
+ if (!this.request) {
46
+ throw new Error("Checkout 解决方案需要 request 插件支持");
47
+ }
48
+ this.order = new import_Order.OrderModule();
49
+ this.payment = new import_Payment.PaymentModule();
50
+ this.store = {
51
+ status: import_types.CheckoutStatus.Initializing,
52
+ step: import_types.CheckoutStep.OrderConfirmation,
53
+ cartItems: [],
54
+ paymentMethods: [],
55
+ stateAmount: "0.00",
56
+ cartSummary: void 0,
57
+ isOrderSynced: false,
58
+ currentCustomer: void 0
59
+ };
60
+ await this.initializeSubModules(core, options);
61
+ await this.preloadPaymentMethods();
62
+ await this.setStatus(import_types.CheckoutStatus.Ready);
63
+ console.log("[Checkout] 初始化完成");
64
+ await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
65
+ timestamp: Date.now()
66
+ });
67
+ }
68
+ /**
69
+ * 初始化子模块
70
+ */
71
+ async initializeSubModules(core, options) {
72
+ var _a, _b;
73
+ core.registerModule(this.order, {
74
+ store: ((_a = options.store) == null ? void 0 : _a.order) || {},
75
+ otherParams: { ...this.otherParams, parentModule: this.name }
76
+ });
77
+ core.registerModule(this.payment, {
78
+ store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
79
+ otherParams: { ...this.otherParams, parentModule: this.name }
80
+ });
81
+ this.setupPaymentEventListeners();
82
+ }
83
+ /**
84
+ * 设置支付模块事件监听
85
+ */
86
+ setupPaymentEventListeners() {
87
+ this.core.effects.on("payment:onPaymentSyncSuccess", async (data) => {
88
+ var _a;
89
+ if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
90
+ await this.handlePaymentSuccess(data);
91
+ }
92
+ });
93
+ this.core.effects.on("payment:onPaymentSyncError", async (data) => {
94
+ var _a;
95
+ if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
96
+ await this.handlePaymentError(data);
97
+ }
98
+ });
99
+ }
100
+ /**
101
+ * 初始化结账流程
102
+ */
103
+ async initializeCheckoutAsync(params) {
104
+ try {
105
+ await this.setStatus(import_types.CheckoutStatus.Initializing);
106
+ const validation = await this.validateCheckoutParams(params);
107
+ if (!validation.valid) {
108
+ throw (0, import_utils.createCheckoutError)(
109
+ import_types.CheckoutErrorType.ValidationFailed,
110
+ `参数验证失败: ${validation.errors.join(", ")}`
111
+ );
112
+ }
113
+ this.store.cartItems = params.cartItems;
114
+ await this.setStatus(import_types.CheckoutStatus.Ready);
115
+ await this.setStep(import_types.CheckoutStep.OrderConfirmation);
116
+ console.log("[Checkout] 结账流程初始化完成");
117
+ } catch (error) {
118
+ await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
119
+ throw error;
120
+ }
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
+ }
135
+ /**
136
+ * 创建本地订单 (前端模拟下单流程)
137
+ *
138
+ * 此方法用于在前端模拟整个下单流程,创建一个本地的虚拟订单。
139
+ * 用户在购物车点击下单时,会把购物车参数传递给此方法,
140
+ * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
141
+ */
142
+ async createLocalOrderAsync(params) {
143
+ var _a, _b, _c, _d, _e;
144
+ try {
145
+ await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
146
+ const validation = await this.validateLocalOrderData(params.orderData);
147
+ if (!validation.valid) {
148
+ throw (0, import_utils.createCheckoutError)(
149
+ import_types.CheckoutErrorType.ValidationFailed,
150
+ `订单数据验证失败: ${validation.errors.join(", ")}`
151
+ );
152
+ }
153
+ const localOrderId = this.generateLocalOrderId();
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;
159
+ this.store.localOrderData = params.orderData;
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({
173
+ order_id: localOrderId,
174
+ total_amount: amountInfo.totalAmount,
175
+ is_deposit: params.orderData.is_deposit || 0,
176
+ deposit_amount: amountInfo.depositAmount || "0.00",
177
+ order_info: {
178
+ original_order_data: params.orderData,
179
+ cart_summary: params.cartSummary,
180
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
181
+ platform: params.orderData.platform,
182
+ type: params.orderData.type,
183
+ schedule_date: params.orderData.schedule_date,
184
+ shop_note: params.orderData.shop_note,
185
+ amount_breakdown: amountInfo
186
+ }
187
+ });
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");
200
+ await this.setStatus(import_types.CheckoutStatus.OrderCreated);
201
+ await this.setStep(import_types.CheckoutStep.PaymentMethod);
202
+ if (params.autoPayment) {
203
+ await this.setStep(import_types.CheckoutStep.PaymentProcessing);
204
+ }
205
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
206
+ order: paymentOrder,
207
+ timestamp: Date.now()
208
+ });
209
+ await this.updateStateAmountToRemaining();
210
+ console.log("[Checkout] 本地订单创建成功:", {
211
+ localOrderId,
212
+ uuid: paymentOrder.uuid,
213
+ totalAmount: amountInfo.totalAmount,
214
+ subTotal: amountInfo.subTotal,
215
+ taxAmount: amountInfo.taxAmount,
216
+ stateAmount: this.store.stateAmount
217
+ });
218
+ return paymentOrder;
219
+ } catch (error) {
220
+ await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
221
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
222
+ error: this.store.lastError,
223
+ timestamp: Date.now()
224
+ });
225
+ throw error;
226
+ }
227
+ }
228
+ /**
229
+ * 手动下单 (根据虚拟订单生成实际订单)
230
+ *
231
+ * 使用当前存储的本地订单数据调用 Order 模块创建真实订单
232
+ */
233
+ async placeOrderAsync(params = {}) {
234
+ var _a;
235
+ try {
236
+ if (!this.store.localOrderData) {
237
+ throw (0, import_utils.createCheckoutError)(
238
+ import_types.CheckoutErrorType.ValidationFailed,
239
+ "没有找到本地订单数据,请先调用 createLocalOrderAsync 创建虚拟订单"
240
+ );
241
+ }
242
+ if (!this.store.currentOrder) {
243
+ throw (0, import_utils.createCheckoutError)(
244
+ import_types.CheckoutErrorType.ValidationFailed,
245
+ "没有找到当前订单,请先创建虚拟订单"
246
+ );
247
+ }
248
+ console.log("[Checkout] 开始手动下单流程...");
249
+ await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
250
+ const orderData = {
251
+ cartItems: this.store.cartItems,
252
+ type: this.store.localOrderData.type,
253
+ platform: this.store.localOrderData.platform
254
+ };
255
+ const orderResponse = await this.order.submitOrder({
256
+ url: params.url,
257
+ // 可选的自定义 URL
258
+ query: orderData
259
+ });
260
+ const realOrderId = ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
261
+ if (!realOrderId) {
262
+ throw (0, import_utils.createCheckoutError)(
263
+ import_types.CheckoutErrorType.OrderCreationFailed,
264
+ "订单创建成功但未返回订单ID"
265
+ );
266
+ }
267
+ console.log("[Checkout] 真实订单创建成功:", realOrderId);
268
+ if (params.autoReplaceOrderId !== false) {
269
+ console.log("[Checkout] 自动替换虚拟订单ID为真实订单ID...");
270
+ const updatedOrder = await this.replaceLocalOrderIdAsync(realOrderId);
271
+ if (updatedOrder) {
272
+ console.log("[Checkout] 订单ID替换成功:", {
273
+ oldId: this.store.currentOrder.order_id,
274
+ newId: realOrderId
275
+ });
276
+ }
277
+ }
278
+ await this.setStatus(import_types.CheckoutStatus.OrderCreated);
279
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
280
+ order: this.store.currentOrder,
281
+ timestamp: Date.now()
282
+ });
283
+ this.store.isOrderSynced = true;
284
+ console.log("[Checkout] 手动下单流程完成");
285
+ return {
286
+ success: true,
287
+ orderId: realOrderId
288
+ };
289
+ } catch (error) {
290
+ let errorMessage = "下单失败";
291
+ if (error && typeof error === "object" && "message" in error) {
292
+ errorMessage = error.message;
293
+ } else if (error instanceof Error) {
294
+ errorMessage = error.message;
295
+ }
296
+ console.error("[Checkout] 手动下单失败:", errorMessage);
297
+ await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
298
+ return {
299
+ success: false,
300
+ error: errorMessage
301
+ };
302
+ }
303
+ }
304
+ /**
305
+ * 创建订单
306
+ */
307
+ async createOrderAsync(params) {
308
+ var _a;
309
+ try {
310
+ await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
311
+ const checkResult = this.order.checkBeforeSubmitOrder({
312
+ cartItems: params.cartItems,
313
+ type: "account"
314
+ // 默认使用 account 类型
315
+ });
316
+ if (!checkResult) {
317
+ throw (0, import_utils.createCheckoutError)(
318
+ import_types.CheckoutErrorType.ValidationFailed,
319
+ "购物车数据验证失败,请检查商品信息"
320
+ );
321
+ }
322
+ const orderResponse = await this.order.submitOrder({
323
+ query: {
324
+ cartItems: params.cartItems,
325
+ type: params.type || "appointment_booking",
326
+ platform: params.platform || "pc"
327
+ }
328
+ });
329
+ const paymentOrder = await this.payment.createPaymentOrderAsync({
330
+ order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
331
+ total_amount: this.calculateTotalAmount(params.cartItems),
332
+ order_info: orderResponse == null ? void 0 : orderResponse.data
333
+ });
334
+ this.store.currentOrder = paymentOrder;
335
+ await this.setStatus(import_types.CheckoutStatus.OrderCreated);
336
+ await this.setStep(import_types.CheckoutStep.PaymentMethod);
337
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
338
+ order: paymentOrder,
339
+ timestamp: Date.now()
340
+ });
341
+ this.store.isOrderSynced = true;
342
+ await this.updateStateAmountToRemaining();
343
+ console.log("[Checkout] 订单创建成功:", paymentOrder.id);
344
+ return paymentOrder;
345
+ } catch (error) {
346
+ await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
347
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
348
+ error: this.store.lastError,
349
+ timestamp: Date.now()
350
+ });
351
+ throw error;
352
+ }
353
+ }
354
+ /**
355
+ * 处理支付
356
+ */
357
+ async processPaymentAsync(params) {
358
+ try {
359
+ if (!this.store.currentOrder) {
360
+ throw (0, import_utils.createCheckoutError)(
361
+ import_types.CheckoutErrorType.ValidationFailed,
362
+ "未找到当前订单,请先创建订单"
363
+ );
364
+ }
365
+ await this.setStatus(import_types.CheckoutStatus.ProcessingPayment);
366
+ await this.setStep(import_types.CheckoutStep.PaymentProcessing);
367
+ const paymentMethod = this.store.paymentMethods.find(
368
+ (method) => method.code === params.paymentMethodCode
369
+ );
370
+ if (!paymentMethod) {
371
+ throw (0, import_utils.createCheckoutError)(
372
+ import_types.CheckoutErrorType.ValidationFailed,
373
+ `未找到支付方式: ${params.paymentMethodCode}`
374
+ );
375
+ }
376
+ const paymentItem = {
377
+ code: paymentMethod.code,
378
+ name: paymentMethod.name,
379
+ type: paymentMethod.type,
380
+ amount: String(params.amount),
381
+ id: paymentMethod.id
382
+ };
383
+ await this.payment.addPaymentItemAsync(
384
+ this.store.currentOrder.uuid,
385
+ paymentItem
386
+ );
387
+ const result = await this.payment.submitPayAsync(
388
+ this.store.currentOrder.uuid
389
+ );
390
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
391
+ orderUuid: this.store.currentOrder.uuid,
392
+ paymentMethodCode: params.paymentMethodCode,
393
+ amount: String(params.amount),
394
+ timestamp: Date.now()
395
+ });
396
+ if (result.status === "success") {
397
+ await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
398
+ await this.updateStateAmountToRemaining();
399
+ await this.handlePaymentSuccess({
400
+ orderUuid: this.store.currentOrder.uuid,
401
+ timestamp: Date.now()
402
+ });
403
+ } else {
404
+ throw (0, import_utils.createCheckoutError)(
405
+ import_types.CheckoutErrorType.PaymentFailed,
406
+ "支付处理失败,请重试"
407
+ );
408
+ }
409
+ } catch (error) {
410
+ await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
411
+ throw error;
412
+ }
413
+ }
414
+ /**
415
+ * 完成结账
416
+ */
417
+ async completeCheckoutAsync() {
418
+ try {
419
+ if (!this.store.currentOrder) {
420
+ throw (0, import_utils.createCheckoutError)(
421
+ import_types.CheckoutErrorType.ValidationFailed,
422
+ "未找到当前订单"
423
+ );
424
+ }
425
+ const order = await this.payment.getPaymentOrderByUuidAsync(
426
+ this.store.currentOrder.uuid
427
+ );
428
+ if (!order || order.payment_status !== import_types2.PaymentStatus.Finished) {
429
+ throw (0, import_utils.createCheckoutError)(
430
+ import_types.CheckoutErrorType.ValidationFailed,
431
+ "订单支付未完成,无法完成结账"
432
+ );
433
+ }
434
+ this.payment.wallet.clearAllCache();
435
+ await this.setStatus(import_types.CheckoutStatus.Completed);
436
+ await this.setStep(import_types.CheckoutStep.Complete);
437
+ await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
438
+ orderId: order.id,
439
+ timestamp: Date.now()
440
+ });
441
+ console.log("[Checkout] 结账流程完成:", order.id);
442
+ return {
443
+ success: true,
444
+ orderId: String(order.id)
445
+ };
446
+ } catch (error) {
447
+ await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
448
+ return { success: false };
449
+ }
450
+ }
451
+ /**
452
+ * 取消结账
453
+ */
454
+ async cancelCheckoutAsync() {
455
+ try {
456
+ if (this.store.currentOrder) {
457
+ await this.payment.deletePaymentOrderAsync(this.store.currentOrder.uuid);
458
+ this.store.currentOrder = void 0;
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;
467
+ await this.setStatus(import_types.CheckoutStatus.Cancelled);
468
+ await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
469
+ timestamp: Date.now()
470
+ });
471
+ console.log("[Checkout] 结账流程已取消");
472
+ } catch (error) {
473
+ console.error("[Checkout] 取消结账失败:", error);
474
+ await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
475
+ }
476
+ }
477
+ /**
478
+ * 获取结账状态
479
+ */
480
+ getCheckoutStatus() {
481
+ return {
482
+ status: this.store.status,
483
+ step: this.store.step,
484
+ progress: (0, import_utils.calculateProgress)(this.store.status, this.store.step),
485
+ message: this.getStatusMessage(),
486
+ error: this.store.lastError
487
+ };
488
+ }
489
+ /**
490
+ * 获取结账摘要
491
+ */
492
+ async getCheckoutSummaryAsync() {
493
+ var _a, _b;
494
+ const totalAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0.00";
495
+ const paidAmount = this.calculatePaidAmount();
496
+ const remainingAmount = this.calculateRemainingAmount();
497
+ return {
498
+ order: this.store.currentOrder,
499
+ totalAmount,
500
+ paidAmount,
501
+ remainingAmount,
502
+ paymentStatus: ((_b = this.store.currentOrder) == null ? void 0 : _b.payment_status) || import_types2.PaymentStatus.Processing,
503
+ availablePaymentMethods: this.store.paymentMethods
504
+ };
505
+ }
506
+ /**
507
+ * 获取可用支付方式
508
+ */
509
+ async getAvailablePaymentMethodsAsync() {
510
+ if (this.store.paymentMethods.length === 0) {
511
+ console.log("[Checkout] 支付方式缓存为空,重新加载...");
512
+ await this.preloadPaymentMethods();
513
+ }
514
+ return this.store.paymentMethods;
515
+ }
516
+ /**
517
+ * 刷新支付方式缓存
518
+ *
519
+ * 强制重新从服务器获取支付方式列表,更新本地缓存
520
+ */
521
+ async refreshPaymentMethodsAsync() {
522
+ console.log("[Checkout] 强制刷新支付方式缓存...");
523
+ await this.preloadPaymentMethods();
524
+ return this.store.paymentMethods;
525
+ }
526
+ /**
527
+ * 获取当前订单基础信息
528
+ *
529
+ * 返回当前订单的基础信息,包括订单状态、金额、支付状态等
530
+ */
531
+ getCurrentOrderInfo() {
532
+ try {
533
+ const { currentOrder, status, step, cartItems, localOrderData } = this.store;
534
+ if (!currentOrder) {
535
+ console.log("[Checkout] 当前没有活跃订单");
536
+ return null;
537
+ }
538
+ const orderInfo = currentOrder.order_info || {};
539
+ const createdAt = orderInfo.created_at || (/* @__PURE__ */ new Date()).toISOString();
540
+ const orderType = (localOrderData == null ? void 0 : localOrderData.type) || orderInfo.type || "virtual";
541
+ const platform = (localOrderData == null ? void 0 : localOrderData.platform) || orderInfo.platform || "pc";
542
+ const result = {
543
+ uuid: currentOrder.uuid,
544
+ orderId: currentOrder.order_id,
545
+ status,
546
+ step,
547
+ totalAmount: currentOrder.total_amount,
548
+ remainingAmount: currentOrder.expect_amount,
549
+ paymentStatus: currentOrder.payment_status,
550
+ isDeposit: Boolean(currentOrder.is_deposit),
551
+ depositAmount: currentOrder.deposit_amount,
552
+ orderType,
553
+ platform,
554
+ createdAt,
555
+ itemCount: cartItems.length,
556
+ hasLocalOrderData: Boolean(localOrderData)
557
+ };
558
+ console.log("[Checkout] 获取当前订单基础信息:", {
559
+ uuid: result.uuid,
560
+ orderId: result.orderId,
561
+ status: result.status,
562
+ totalAmount: result.totalAmount,
563
+ remainingAmount: result.remainingAmount
564
+ });
565
+ return result;
566
+ } catch (error) {
567
+ console.error("[Checkout] 获取当前订单基础信息失败:", error);
568
+ return null;
569
+ }
570
+ }
571
+ /**
572
+ * 获取当前订单的支付项
573
+ *
574
+ * 返回当前订单的所有支付项,包括活跃和已撤销的支付项
575
+ */
576
+ async getCurrentOrderPaymentItemsAsync() {
577
+ try {
578
+ const { currentOrder } = this.store;
579
+ if (!currentOrder) {
580
+ console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
581
+ return [];
582
+ }
583
+ console.log("[Checkout] 获取当前订单支付项:", {
584
+ orderUuid: currentOrder.uuid,
585
+ orderId: currentOrder.order_id
586
+ });
587
+ const paymentItems = await this.payment.getPaymentItemsAsync(currentOrder.uuid);
588
+ console.log("[Checkout] 成功获取支付项:", {
589
+ orderUuid: currentOrder.uuid,
590
+ paymentItemCount: paymentItems.length,
591
+ activeItems: paymentItems.filter((item) => item.status !== "voided").length,
592
+ voidedItems: paymentItems.filter((item) => item.status === "voided").length,
593
+ totalPaidAmount: paymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => sum + parseFloat(item.amount || "0"), 0).toFixed(2),
594
+ paymentMethods: paymentItems.map((item) => ({
595
+ uuid: item.uuid,
596
+ code: item.code,
597
+ amount: item.amount,
598
+ status: item.status,
599
+ voucher_id: item.voucher_id
600
+ }))
601
+ });
602
+ return paymentItems;
603
+ } catch (error) {
604
+ console.error("[Checkout] 获取当前订单支付项失败:", error);
605
+ return [];
606
+ }
607
+ }
608
+ /**
609
+ * 验证结账前置条件
610
+ */
611
+ async validateCheckoutAsync() {
612
+ const errors = [];
613
+ if (!this.store.cartItems || this.store.cartItems.length === 0) {
614
+ errors.push("购物车为空");
615
+ }
616
+ if (this.store.paymentMethods.length === 0) {
617
+ errors.push("无可用支付方式");
618
+ }
619
+ if (this.store.status === import_types.CheckoutStatus.Error) {
620
+ errors.push("结账流程存在错误");
621
+ }
622
+ return {
623
+ valid: errors.length === 0,
624
+ errors
625
+ };
626
+ }
627
+ /**
628
+ * 重试失败的操作
629
+ */
630
+ async retryFailedOperationAsync() {
631
+ try {
632
+ if (this.store.status === import_types.CheckoutStatus.Error && this.store.lastError) {
633
+ switch (this.store.lastError.type) {
634
+ case import_types.CheckoutErrorType.OrderCreationFailed:
635
+ if (this.store.cartItems.length > 0) {
636
+ await this.createOrderAsync({
637
+ cartItems: this.store.cartItems
638
+ });
639
+ }
640
+ break;
641
+ default:
642
+ console.warn("[Checkout] 无法重试此类型的错误:", this.store.lastError.type);
643
+ }
644
+ }
645
+ } catch (error) {
646
+ await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
647
+ }
648
+ }
649
+ /**
650
+ * 设置当前步骤
651
+ */
652
+ setCurrentStep(step) {
653
+ const oldStep = this.store.step;
654
+ this.store.step = step;
655
+ this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
656
+ oldStep,
657
+ newStep: step,
658
+ timestamp: Date.now()
659
+ });
660
+ }
661
+ /**
662
+ * 获取订单模块
663
+ */
664
+ getOrderModule() {
665
+ return this.order;
666
+ }
667
+ /**
668
+ * 获取支付模块
669
+ */
670
+ getPaymentModule() {
671
+ return this.payment;
672
+ }
673
+ /**
674
+ * 替换本地订单ID为真实订单ID
675
+ *
676
+ * 当后端订单创建完成后,调用此方法将本地虚拟订单ID替换为真实订单ID
677
+ *
678
+ * @param newOrderId 后端返回的真实订单ID
679
+ * @returns 更新后的订单对象,如果当前没有订单则返回null
680
+ */
681
+ async replaceLocalOrderIdAsync(newOrderId) {
682
+ try {
683
+ if (!this.store.currentOrder) {
684
+ console.warn("[Checkout] 没有当前订单,无法替换订单ID");
685
+ return null;
686
+ }
687
+ const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
688
+ this.store.currentOrder.uuid,
689
+ newOrderId
690
+ );
691
+ if (updatedOrder) {
692
+ this.store.currentOrder = updatedOrder;
693
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
694
+ order: updatedOrder,
695
+ timestamp: Date.now()
696
+ });
697
+ console.log("[Checkout] 本地订单ID替换成功:", {
698
+ uuid: updatedOrder.uuid,
699
+ newOrderId: updatedOrder.id
700
+ });
701
+ this.store.isOrderSynced = true;
702
+ await this.updateStateAmountToRemaining();
703
+ }
704
+ return updatedOrder;
705
+ } catch (error) {
706
+ console.error("[Checkout] 替换订单ID失败:", error);
707
+ await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
708
+ return null;
709
+ }
710
+ }
711
+ /**
712
+ * 设置自定义支付金额
713
+ *
714
+ * 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
715
+ *
716
+ * @param amount 自定义支付金额,必须是有效的数字字符串
717
+ */
718
+ async setStateAmountAsync(amount) {
719
+ try {
720
+ const numAmount = parseFloat(amount);
721
+ if (isNaN(numAmount) || numAmount < 0) {
722
+ throw new Error(`无效的支付金额: ${amount}`);
723
+ }
724
+ const oldAmount = this.store.stateAmount;
725
+ const formattedAmount = numAmount.toFixed(2);
726
+ if (oldAmount === formattedAmount) {
727
+ return;
728
+ }
729
+ this.store.stateAmount = formattedAmount;
730
+ await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
731
+ oldAmount,
732
+ newAmount: formattedAmount,
733
+ timestamp: Date.now()
734
+ });
735
+ console.log("[Checkout] 自定义支付金额已更新:", {
736
+ oldAmount,
737
+ newAmount: formattedAmount
738
+ });
739
+ } catch (error) {
740
+ const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
741
+ console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
742
+ await this.handleError(
743
+ new Error(errorMessage),
744
+ import_types.CheckoutErrorType.ValidationFailed
745
+ );
746
+ throw error;
747
+ }
748
+ }
749
+ /**
750
+ * 获取当前自定义支付金额
751
+ *
752
+ * @returns 当前设置的自定义支付金额
753
+ */
754
+ getStateAmount() {
755
+ return this.store.stateAmount;
756
+ }
757
+ /**
758
+ * 刷新 stateAmount 为当前剩余未支付金额
759
+ *
760
+ * UI 可以调用此方法来主动刷新支付金额状态
761
+ */
762
+ async refreshStateAmountAsync() {
763
+ await this.updateStateAmountToRemaining();
764
+ }
765
+ /**
766
+ * 获取购物车小计数据
767
+ *
768
+ * 返回当前结账流程中的购物车小计项数据,包含各种费用明细
769
+ *
770
+ * @returns 购物车小计数据数组,如果没有则返回 null
771
+ */
772
+ getCartSummary() {
773
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
774
+ console.warn("[Checkout] 没有可用的购物车小计数据");
775
+ return null;
776
+ }
777
+ console.log("[Checkout] 获取购物车小计数据:", {
778
+ itemCount: this.store.cartSummary.length,
779
+ items: this.store.cartSummary.map((item) => ({ key: item.key, value: item.value, label: item.label }))
780
+ });
781
+ return [...this.store.cartSummary];
782
+ }
783
+ /**
784
+ * 获取提取的金额详细信息
785
+ *
786
+ * 从当前的购物车小计数据中提取结构化的金额信息
787
+ *
788
+ * @returns 提取的金额信息对象,如果没有小计数据则返回 null
789
+ */
790
+ getExtractedAmountInfo() {
791
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
792
+ console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
793
+ return null;
794
+ }
795
+ const extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
796
+ console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
797
+ return extractedInfo;
798
+ }
799
+ /**
800
+ * 获取支付方式列表
801
+ *
802
+ * 直接调用 Payment 模块的 getPayMethodListAsync 方法
803
+ *
804
+ * @returns 支付方式列表
805
+ */
806
+ async getPaymentMethodsAsync() {
807
+ return await this.payment.getPayMethodListAsync();
808
+ }
809
+ /**
810
+ * 为当前订单添加支付项
811
+ *
812
+ * 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
813
+ *
814
+ * @param paymentItem 支付项数据
815
+ * @throws 当前没有活跃订单时抛出错误
816
+ */
817
+ async addPaymentItemAsync(paymentItem) {
818
+ try {
819
+ if (!this.store.currentOrder) {
820
+ throw (0, import_utils.createCheckoutError)(
821
+ import_types.CheckoutErrorType.ValidationFailed,
822
+ "未找到当前订单,无法添加支付项"
823
+ );
824
+ }
825
+ console.log("[Checkout] 为当前订单添加支付项:", {
826
+ orderUuid: this.store.currentOrder.uuid,
827
+ paymentItem: {
828
+ code: paymentItem.code,
829
+ name: paymentItem.name,
830
+ type: paymentItem.type,
831
+ amount: paymentItem.amount,
832
+ service_charge: paymentItem.service_charge
833
+ }
834
+ });
835
+ await this.payment.addPaymentItemAsync(
836
+ this.store.currentOrder.uuid,
837
+ paymentItem
838
+ );
839
+ console.log("[Checkout] 支付项添加成功");
840
+ const currentOrderId = this.store.currentOrder.order_id;
841
+ const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
842
+ console.log("[Checkout] 准备同步订单数据:", {
843
+ 当前订单ID: currentOrderId,
844
+ 是否为真实ID: isCurrentOrderReal
845
+ });
846
+ const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
847
+ if (updatedOrder) {
848
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
849
+ console.warn("[Checkout] 检测到订单ID回退,保护真实订单ID:", {
850
+ 当前真实ID: currentOrderId,
851
+ 获取到的虚拟ID: updatedOrder.order_id
852
+ });
853
+ updatedOrder.order_id = currentOrderId;
854
+ }
855
+ this.store.currentOrder = updatedOrder;
856
+ console.log("[Checkout] 订单数据已同步:", {
857
+ 支付项数量: updatedOrder.payment.length,
858
+ 最终订单ID: updatedOrder.order_id,
859
+ 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
860
+ });
861
+ }
862
+ const needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
863
+ console.log("[Checkout] 支付项同步检查:", {
864
+ paymentCode: paymentItem.code,
865
+ paymentType: paymentItem.type,
866
+ paymentAmount: paymentItem.amount,
867
+ expectedCashCode: import_types2.PaymentMethodType.Cash,
868
+ needsOrderSync,
869
+ isOrderSynced: this.store.isOrderSynced
870
+ });
871
+ if (needsOrderSync) {
872
+ console.log("[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...", {
873
+ 同步前订单ID: this.store.currentOrder.order_id,
874
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
875
+ 订单同步状态: this.store.isOrderSynced,
876
+ 订单UUID: this.store.currentOrder.uuid
877
+ });
878
+ await this.syncOrderToBackend();
879
+ console.log("[Checkout] addPaymentItemAsync 中的同步完成:", {
880
+ 同步后订单ID: this.store.currentOrder.order_id,
881
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
882
+ 订单同步状态: this.store.isOrderSynced
883
+ });
884
+ }
885
+ await this.updateStateAmountToRemaining();
886
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
887
+ orderUuid: this.store.currentOrder.uuid,
888
+ paymentMethodCode: paymentItem.code,
889
+ amount: String(paymentItem.amount),
890
+ timestamp: Date.now()
891
+ });
892
+ } catch (error) {
893
+ console.error("[Checkout] 添加支付项失败:", error);
894
+ await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
895
+ throw error;
896
+ }
897
+ }
898
+ /**
899
+ * 删除当前订单的支付项
900
+ *
901
+ * 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
902
+ *
903
+ * @param paymentUuid 要删除的支付项UUID
904
+ * @throws 当前没有活跃订单时抛出错误
905
+ * @throws 支付项不存在时抛出错误
906
+ */
907
+ async deletePaymentItemAsync(paymentUuid) {
908
+ try {
909
+ if (!this.store.currentOrder) {
910
+ throw (0, import_utils.createCheckoutError)(
911
+ import_types.CheckoutErrorType.ValidationFailed,
912
+ "当前没有活跃订单,无法删除支付项"
913
+ );
914
+ }
915
+ console.log("[Checkout] 开始删除支付项:", {
916
+ orderUuid: this.store.currentOrder.uuid,
917
+ paymentUuid
918
+ });
919
+ const paymentItem = this.store.currentOrder.payment.find((p) => p.uuid === paymentUuid);
920
+ if (!paymentItem) {
921
+ throw (0, import_utils.createCheckoutError)(
922
+ import_types.CheckoutErrorType.ValidationFailed,
923
+ `支付项不存在: ${paymentUuid}`
924
+ );
925
+ }
926
+ console.log("[Checkout] 找到要删除的支付项:", {
927
+ uuid: paymentItem.uuid,
928
+ code: paymentItem.code,
929
+ amount: paymentItem.amount,
930
+ status: paymentItem.status
931
+ });
932
+ await this.payment.deletePaymentAsync(
933
+ this.store.currentOrder.uuid,
934
+ paymentUuid
935
+ );
936
+ console.log("[Checkout] Payment模块删除完成");
937
+ const currentOrderId = this.store.currentOrder.order_id;
938
+ const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
939
+ const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
940
+ if (updatedOrder) {
941
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
942
+ console.warn("[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:", {
943
+ 当前真实ID: currentOrderId,
944
+ 获取到的虚拟ID: updatedOrder.order_id
945
+ });
946
+ updatedOrder.order_id = currentOrderId;
947
+ }
948
+ this.store.currentOrder = updatedOrder;
949
+ console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
950
+ }
951
+ await this.updateStateAmountToRemaining();
952
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
953
+ orderUuid: this.store.currentOrder.uuid,
954
+ paymentMethodCode: paymentItem.code,
955
+ amount: `-${paymentItem.amount}`,
956
+ // 负数表示删除
957
+ timestamp: Date.now()
958
+ });
959
+ console.log("[Checkout] 支付项删除成功");
960
+ } catch (error) {
961
+ console.error("[Checkout] 删除支付项失败:", error);
962
+ await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
963
+ throw error;
964
+ }
965
+ }
966
+ /**
967
+ * 批量更新当前订单的代金券支付项(覆盖更新)
968
+ *
969
+ * 删除所有现有的代金券支付项,然后添加新的代金券支付项。
970
+ * 这是一个覆盖式更新操作,确保代金券支付项的一致性。
971
+ *
972
+ * @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
973
+ * @throws 当前没有活跃订单时抛出错误
974
+ * @throws 支付项缺少 voucher_id 时抛出错误
975
+ */
976
+ async updateVoucherPaymentItemsAsync(voucherPaymentItems) {
977
+ try {
978
+ if (!this.store.currentOrder) {
979
+ throw (0, import_utils.createCheckoutError)(
980
+ import_types.CheckoutErrorType.ValidationFailed,
981
+ "当前没有活跃订单,无法更新代金券支付项"
982
+ );
983
+ }
984
+ console.log("[Checkout] 开始批量更新代金券支付项:", {
985
+ orderUuid: this.store.currentOrder.uuid,
986
+ newVoucherCount: voucherPaymentItems.length,
987
+ voucherPaymentItems
988
+ });
989
+ for (const item of voucherPaymentItems) {
990
+ if (!item.voucher_id) {
991
+ throw (0, import_utils.createCheckoutError)(
992
+ import_types.CheckoutErrorType.ValidationFailed,
993
+ `代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
994
+ );
995
+ }
996
+ }
997
+ await this.payment.updateVoucherPaymentItemsAsync(
998
+ this.store.currentOrder.uuid,
999
+ voucherPaymentItems
1000
+ );
1001
+ console.log("[Checkout] Payment模块批量更新完成");
1002
+ const currentOrderId = this.store.currentOrder.order_id;
1003
+ const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1004
+ const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1005
+ if (updatedOrder) {
1006
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1007
+ console.warn("[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:", {
1008
+ 当前真实ID: currentOrderId,
1009
+ 获取到的虚拟ID: updatedOrder.order_id
1010
+ });
1011
+ updatedOrder.order_id = currentOrderId;
1012
+ }
1013
+ this.store.currentOrder = updatedOrder;
1014
+ console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
1015
+ const voucherItems = updatedOrder.payment.filter(
1016
+ (payment) => payment.voucher_id && payment.status !== "voided"
1017
+ );
1018
+ console.log("[Checkout] 更新后的代金券支付项:", {
1019
+ voucherCount: voucherItems.length,
1020
+ items: voucherItems.map((item) => ({
1021
+ uuid: item.uuid,
1022
+ code: item.code,
1023
+ amount: item.amount,
1024
+ voucher_id: item.voucher_id
1025
+ }))
1026
+ });
1027
+ }
1028
+ await this.updateStateAmountToRemaining();
1029
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
1030
+ orderUuid: this.store.currentOrder.uuid,
1031
+ paymentMethodCode: "VOUCHER_BATCH",
1032
+ amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
1033
+ timestamp: Date.now()
1034
+ });
1035
+ console.log("[Checkout] 代金券支付项批量更新成功");
1036
+ } catch (error) {
1037
+ console.error("[Checkout] 批量更新代金券支付项失败:", error);
1038
+ await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
1039
+ throw error;
1040
+ }
1041
+ }
1042
+ /**
1043
+ * 修改当前订单的定金状态
1044
+ *
1045
+ * 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
1046
+ *
1047
+ * @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
1048
+ * @throws 当前没有活跃订单时抛出错误
1049
+ */
1050
+ async updateOrderDepositStatusAsync(isDeposit) {
1051
+ try {
1052
+ if (isDeposit !== 0 && isDeposit !== 1) {
1053
+ throw (0, import_utils.createCheckoutError)(
1054
+ import_types.CheckoutErrorType.ValidationFailed,
1055
+ "isDeposit 参数只能是 0(全款订单)或 1(定金订单)"
1056
+ );
1057
+ }
1058
+ if (!this.store.currentOrder) {
1059
+ throw (0, import_utils.createCheckoutError)(
1060
+ import_types.CheckoutErrorType.ValidationFailed,
1061
+ "未找到当前订单,无法修改定金状态"
1062
+ );
1063
+ }
1064
+ const newDepositValue = isDeposit;
1065
+ const oldDepositValue = this.store.currentOrder.is_deposit;
1066
+ if (oldDepositValue === newDepositValue) {
1067
+ console.log("[Checkout] 定金状态无变化,跳过更新");
1068
+ return;
1069
+ }
1070
+ console.log("[Checkout] 更新订单定金状态:", {
1071
+ orderUuid: this.store.currentOrder.uuid,
1072
+ orderId: this.store.currentOrder.order_id,
1073
+ oldIsDeposit: oldDepositValue,
1074
+ newIsDeposit: newDepositValue
1075
+ });
1076
+ const updateParams = {
1077
+ is_deposit: newDepositValue
1078
+ };
1079
+ if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== "0.00") {
1080
+ updateParams.deposit_amount = "0.00";
1081
+ console.log("[Checkout] 订单从定金改为全款,清空定金金额");
1082
+ }
1083
+ await this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1084
+ this.store.currentOrder = {
1085
+ ...this.store.currentOrder,
1086
+ ...updateParams
1087
+ };
1088
+ if (this.store.localOrderData) {
1089
+ this.store.localOrderData.is_deposit = newDepositValue;
1090
+ }
1091
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
1092
+ order: this.store.currentOrder,
1093
+ timestamp: Date.now()
1094
+ });
1095
+ console.log("[Checkout] 订单定金状态更新成功:", {
1096
+ isDeposit: newDepositValue,
1097
+ depositAmount: this.store.currentOrder.deposit_amount
1098
+ });
1099
+ } catch (error) {
1100
+ console.error("[Checkout] 更新订单定金状态失败:", error);
1101
+ await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1102
+ throw error;
1103
+ }
1104
+ }
1105
+ /**
1106
+ * 更新当前订单的客户信息
1107
+ *
1108
+ * 更新当前订单关联的客户信息,用于标识订单的所属客户
1109
+ *
1110
+ * @param customer 客户信息 (customer_id 和/或 customer_name)
1111
+ * @throws 当前没有活跃订单时抛出错误
1112
+ */
1113
+ async updateOrderCustomerAsync(customer) {
1114
+ try {
1115
+ if (!this.store.currentOrder) {
1116
+ throw (0, import_utils.createCheckoutError)(
1117
+ import_types.CheckoutErrorType.ValidationFailed,
1118
+ "未找到当前订单,无法更新客户信息"
1119
+ );
1120
+ }
1121
+ console.log("[Checkout] 更新订单客户信息:", {
1122
+ orderUuid: this.store.currentOrder.uuid,
1123
+ oldCustomer: this.store.currentCustomer,
1124
+ newCustomer: customer
1125
+ });
1126
+ this.store.currentCustomer = {
1127
+ customer_id: customer.customer_id,
1128
+ customer_name: customer.customer_name
1129
+ };
1130
+ if (this.store.localOrderData) {
1131
+ this.store.localOrderData.customer_id = customer.customer_id;
1132
+ this.store.localOrderData.customer_name = customer.customer_name;
1133
+ }
1134
+ console.log("[Checkout] 订单客户信息更新成功:", this.store.currentCustomer);
1135
+ } catch (error) {
1136
+ console.error("[Checkout] 更新订单客户信息失败:", error);
1137
+ await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1138
+ throw error;
1139
+ }
1140
+ }
1141
+ /**
1142
+ * 获取当前订单的客户信息
1143
+ *
1144
+ * @returns 当前客户信息,如果没有则返回 null
1145
+ */
1146
+ getCurrentCustomer() {
1147
+ return this.store.currentCustomer || null;
1148
+ }
1149
+ /**
1150
+ * 检查订单是否需要手动同步
1151
+ *
1152
+ * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
1153
+ */
1154
+ needsManualSync() {
1155
+ var _a;
1156
+ try {
1157
+ if (!this.store.currentOrder || this.store.isOrderSynced) {
1158
+ return false;
1159
+ }
1160
+ const remainingAmount = this.calculateRemainingAmount();
1161
+ const remainingValue = parseFloat(remainingAmount);
1162
+ if (remainingValue > 0) {
1163
+ return false;
1164
+ }
1165
+ const allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(
1166
+ (item) => item.status !== "voided" && item.voucher_id
1167
+ );
1168
+ console.log("[Checkout] needsManualSync 检查结果:", {
1169
+ orderUuid: this.store.currentOrder.uuid,
1170
+ isOrderSynced: this.store.isOrderSynced,
1171
+ remainingAmount,
1172
+ hasPayments: ((_a = this.store.currentOrder.payment) == null ? void 0 : _a.length) > 0,
1173
+ allPaymentsHaveVoucherId,
1174
+ needsManualSync: allPaymentsHaveVoucherId
1175
+ });
1176
+ return allPaymentsHaveVoucherId;
1177
+ } catch (error) {
1178
+ console.error("[Checkout] needsManualSync 检查失败:", error);
1179
+ return false;
1180
+ }
1181
+ }
1182
+ /**
1183
+ * 手动同步订单到后端
1184
+ *
1185
+ * 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
1186
+ */
1187
+ async manualSyncOrderAsync() {
1188
+ var _a;
1189
+ try {
1190
+ if (!this.store.currentOrder) {
1191
+ return {
1192
+ success: false,
1193
+ message: "当前没有活跃订单,无法同步"
1194
+ };
1195
+ }
1196
+ const orderUuid = this.store.currentOrder.uuid;
1197
+ const oldOrderId = this.store.currentOrder.order_id;
1198
+ if (this.store.isOrderSynced) {
1199
+ console.log("[Checkout] 订单已同步过,将执行更新操作");
1200
+ }
1201
+ console.log("[Checkout] 开始手动同步订单到后端:", {
1202
+ orderUuid,
1203
+ orderId: oldOrderId,
1204
+ totalAmount: this.store.currentOrder.total_amount,
1205
+ remainingAmount: this.calculateRemainingAmount()
1206
+ });
1207
+ const realOrderId = await this.syncOrderToBackendWithReturn(true);
1208
+ console.log("[Checkout] 手动同步订单完成:", {
1209
+ orderUuid,
1210
+ oldOrderId,
1211
+ realOrderId,
1212
+ isOrderSynced: this.store.isOrderSynced
1213
+ });
1214
+ const finalOrderId = this.store.currentOrder.order_id;
1215
+ const finalIsVirtual = this.isVirtualOrderId(finalOrderId);
1216
+ console.log("[Checkout] manualSyncOrderAsync 最终状态验证:", {
1217
+ 返回的订单ID: realOrderId,
1218
+ 存储的订单ID: finalOrderId,
1219
+ 存储的ID是否虚拟: finalIsVirtual,
1220
+ 是否一致: realOrderId === finalOrderId,
1221
+ 同步状态: this.store.isOrderSynced
1222
+ });
1223
+ if (finalIsVirtual) {
1224
+ console.error("[Checkout] 严重警告:手动同步完成后订单ID仍为虚拟ID!");
1225
+ }
1226
+ if (realOrderId !== finalOrderId) {
1227
+ console.error("[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!");
1228
+ }
1229
+ return {
1230
+ success: true,
1231
+ message: "订单同步成功",
1232
+ orderId: realOrderId,
1233
+ // 直接返回从后端获取的真实订单ID
1234
+ orderUuid
1235
+ };
1236
+ } catch (error) {
1237
+ console.error("[Checkout] 手动同步订单失败:", error);
1238
+ const errorMessage = error instanceof Error ? error.message : "同步失败";
1239
+ return {
1240
+ success: false,
1241
+ message: `订单同步失败: ${errorMessage}`,
1242
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
1243
+ };
1244
+ }
1245
+ }
1246
+ /**
1247
+ * 获取当前订单备注
1248
+ *
1249
+ * @returns 当前订单的备注内容,如果没有则返回空字符串
1250
+ */
1251
+ getOrderNote() {
1252
+ if (!this.store.localOrderData) {
1253
+ console.log("[Checkout] 没有本地订单数据,无法获取备注");
1254
+ return "";
1255
+ }
1256
+ return this.store.localOrderData.shop_note || "";
1257
+ }
1258
+ /**
1259
+ * 获取当前订单ID
1260
+ *
1261
+ * @returns 当前订单的ID,如果没有订单则返回null
1262
+ */
1263
+ getCurrentOrderId() {
1264
+ if (!this.store.currentOrder) {
1265
+ return null;
1266
+ }
1267
+ return this.store.currentOrder.order_id;
1268
+ }
1269
+ /**
1270
+ * 保存订单并稍后支付
1271
+ *
1272
+ * 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
1273
+ * 适用于用户想要保存订单但稍后完成支付的场景
1274
+ */
1275
+ async saveForLaterPaymentAsync() {
1276
+ var _a;
1277
+ try {
1278
+ if (!this.store.currentOrder) {
1279
+ return {
1280
+ success: false,
1281
+ message: "当前没有活跃订单,无法保存"
1282
+ };
1283
+ }
1284
+ const orderUuid = this.store.currentOrder.uuid;
1285
+ const currentOrderId = this.store.currentOrder.order_id;
1286
+ console.log("[Checkout] 开始保存订单并稍后支付:", {
1287
+ orderUuid,
1288
+ orderId: currentOrderId,
1289
+ totalAmount: this.store.currentOrder.total_amount
1290
+ });
1291
+ const allPaymentItems = await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1292
+ const filteredPaymentItems = allPaymentItems.filter(
1293
+ (payment) => !payment.voucher_id || payment.voucher_id.trim() === ""
1294
+ );
1295
+ const voucherItems = allPaymentItems.filter(
1296
+ (payment) => payment.voucher_id && payment.voucher_id.trim() !== ""
1297
+ );
1298
+ console.log("[Checkout] 支付项过滤结果:", {
1299
+ 总支付项: allPaymentItems.length,
1300
+ 过滤后支付项: filteredPaymentItems.length,
1301
+ 被过滤的代金券项: voucherItems.length,
1302
+ 代金券详情: voucherItems.map((item) => ({
1303
+ uuid: item.uuid,
1304
+ code: item.code,
1305
+ amount: item.amount,
1306
+ voucherId: item.voucher_id
1307
+ })),
1308
+ 保留的支付项: filteredPaymentItems.map((item) => ({
1309
+ uuid: item.uuid,
1310
+ code: item.code,
1311
+ amount: item.amount
1312
+ }))
1313
+ });
1314
+ const realOrderId = await this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
1315
+ console.log("[Checkout] 保存订单完成:", {
1316
+ orderUuid,
1317
+ oldOrderId: currentOrderId,
1318
+ realOrderId,
1319
+ isOrderSynced: this.store.isOrderSynced,
1320
+ filteredPaymentsCount: filteredPaymentItems.length
1321
+ });
1322
+ const finalOrderId = this.store.currentOrder.order_id;
1323
+ console.log("[Checkout] saveForLaterPaymentAsync 最终状态验证:", {
1324
+ 返回的订单ID: realOrderId,
1325
+ 存储的订单ID: finalOrderId,
1326
+ 是否一致: realOrderId === finalOrderId,
1327
+ 同步状态: this.store.isOrderSynced
1328
+ });
1329
+ return {
1330
+ success: true,
1331
+ message: "订单保存成功,可稍后继续支付",
1332
+ orderId: realOrderId,
1333
+ orderUuid
1334
+ };
1335
+ } catch (error) {
1336
+ console.error("[Checkout] 保存订单失败:", error);
1337
+ const errorMessage = error instanceof Error ? error.message : "保存失败";
1338
+ return {
1339
+ success: false,
1340
+ message: `订单保存失败: ${errorMessage}`,
1341
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
1342
+ };
1343
+ }
1344
+ }
1345
+ /**
1346
+ * 获取当前商店折扣金额
1347
+ *
1348
+ * @returns 当前的商店折扣金额,如果没有则返回0
1349
+ */
1350
+ getShopDiscount() {
1351
+ var _a;
1352
+ if (((_a = this.store.localOrderData) == null ? void 0 : _a.shop_discount) !== void 0) {
1353
+ return this.store.localOrderData.shop_discount;
1354
+ }
1355
+ if (this.store.cartSummary) {
1356
+ const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
1357
+ if (shopDiscountItem) {
1358
+ return shopDiscountItem.value;
1359
+ }
1360
+ }
1361
+ return 0;
1362
+ }
1363
+ /**
1364
+ * 更新订单商店折扣
1365
+ *
1366
+ * 同时更新cartSummary和localOrderData中的shop_discount值
1367
+ *
1368
+ * @param discountAmount 商店折扣金额
1369
+ */
1370
+ async updateShopDiscountAsync(discountAmount) {
1371
+ var _a, _b;
1372
+ try {
1373
+ const oldDiscount = this.getShopDiscount();
1374
+ console.log("[Checkout] 更新商店折扣:", {
1375
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
1376
+ oldDiscount,
1377
+ newDiscount: discountAmount
1378
+ });
1379
+ if (this.store.cartSummary) {
1380
+ const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
1381
+ if (shopDiscountItem) {
1382
+ shopDiscountItem.value = discountAmount;
1383
+ console.log("[Checkout] cartSummary 中的商店折扣已更新");
1384
+ } else {
1385
+ this.store.cartSummary.push({
1386
+ key: "shop_discount",
1387
+ value: discountAmount,
1388
+ hidden: true,
1389
+ label: "Shop Discount"
1390
+ });
1391
+ console.log("[Checkout] cartSummary 中已添加新的商店折扣项");
1392
+ }
1393
+ }
1394
+ if (this.store.localOrderData) {
1395
+ this.store.localOrderData.shop_discount = discountAmount;
1396
+ console.log("[Checkout] localOrderData 中的商店折扣已更新");
1397
+ } else {
1398
+ console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
1399
+ }
1400
+ if (this.store.currentOrder && this.store.cartSummary) {
1401
+ const updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
1402
+ console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
1403
+ this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
1404
+ this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
1405
+ }
1406
+ await this.updateStateAmountToRemaining();
1407
+ await this.core.effects.emit(import_types.CheckoutHooks.OnShopDiscountChanged, {
1408
+ orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
1409
+ oldDiscount,
1410
+ newDiscount: discountAmount,
1411
+ timestamp: Date.now()
1412
+ });
1413
+ console.log("[Checkout] 商店折扣更新成功:", {
1414
+ oldDiscount,
1415
+ newDiscount: discountAmount
1416
+ });
1417
+ } catch (error) {
1418
+ console.error("[Checkout] 更新商店折扣失败:", error);
1419
+ await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1420
+ throw error;
1421
+ }
1422
+ }
1423
+ /**
1424
+ * 更新订单备注
1425
+ *
1426
+ * @param note 订单备注内容
1427
+ */
1428
+ async updateOrderNoteAsync(note) {
1429
+ var _a, _b;
1430
+ try {
1431
+ if (!this.store.localOrderData) {
1432
+ throw (0, import_utils.createCheckoutError)(
1433
+ import_types.CheckoutErrorType.ValidationFailed,
1434
+ "没有本地订单数据,无法更新备注"
1435
+ );
1436
+ }
1437
+ console.log("[Checkout] 更新订单备注:", {
1438
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
1439
+ oldNote: this.store.localOrderData.shop_note,
1440
+ newNote: note
1441
+ });
1442
+ const oldNote = this.store.localOrderData.shop_note;
1443
+ this.store.localOrderData.shop_note = note;
1444
+ if (this.store.currentOrder) {
1445
+ try {
1446
+ const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1447
+ if (orderInPayment && orderInPayment.note !== void 0) {
1448
+ console.log("[Checkout] 同步备注到Payment模块的订单数据中");
1449
+ }
1450
+ } catch (syncError) {
1451
+ console.warn("[Checkout] 同步备注到Payment模块失败,但本地更新成功:", syncError);
1452
+ }
1453
+ }
1454
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
1455
+ orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
1456
+ oldNote,
1457
+ newNote: note,
1458
+ timestamp: Date.now()
1459
+ });
1460
+ console.log("[Checkout] 订单备注更新成功:", {
1461
+ oldNote,
1462
+ newNote: note
1463
+ });
1464
+ } catch (error) {
1465
+ console.error("[Checkout] 更新订单备注失败:", error);
1466
+ await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1467
+ throw error;
1468
+ }
1469
+ }
1470
+ /**
1471
+ * 设置状态
1472
+ */
1473
+ async setStatus(status) {
1474
+ const oldStatus = this.store.status;
1475
+ this.store.status = status;
1476
+ await this.core.effects.emit(import_types.CheckoutHooks.OnStatusChanged, {
1477
+ oldStatus,
1478
+ newStatus: status,
1479
+ timestamp: Date.now()
1480
+ });
1481
+ }
1482
+ /**
1483
+ * 设置步骤
1484
+ */
1485
+ async setStep(step) {
1486
+ const oldStep = this.store.step;
1487
+ this.store.step = step;
1488
+ await this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
1489
+ oldStep,
1490
+ newStep: step,
1491
+ timestamp: Date.now()
1492
+ });
1493
+ }
1494
+ /**
1495
+ * 处理错误
1496
+ */
1497
+ async handleError(error, type) {
1498
+ const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
1499
+ this.store.lastError = checkoutError;
1500
+ await this.setStatus(import_types.CheckoutStatus.Error);
1501
+ await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
1502
+ error: checkoutError,
1503
+ context: { status: this.store.status, step: this.store.step },
1504
+ timestamp: Date.now()
1505
+ });
1506
+ console.error("[Checkout] 错误:", checkoutError);
1507
+ }
1508
+ /**
1509
+ * 处理支付成功
1510
+ */
1511
+ async handlePaymentSuccess(data) {
1512
+ var _a;
1513
+ await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
1514
+ await this.updateStateAmountToRemaining();
1515
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
1516
+ orderUuid: data.orderUuid,
1517
+ paymentMethodCode: "",
1518
+ amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
1519
+ timestamp: data.timestamp
1520
+ });
1521
+ await this.completeCheckoutAsync();
1522
+ }
1523
+ /**
1524
+ * 处理支付错误
1525
+ */
1526
+ async handlePaymentError(data) {
1527
+ var _a;
1528
+ const error = (0, import_utils.createCheckoutError)(
1529
+ import_types.CheckoutErrorType.PaymentFailed,
1530
+ data.error || "支付同步失败"
1531
+ );
1532
+ await this.handleError(error instanceof Error ? error : new Error(String(error)), import_types.CheckoutErrorType.PaymentFailed);
1533
+ await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentFailed, {
1534
+ orderUuid: data.orderUuid,
1535
+ paymentMethodCode: "",
1536
+ amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
1537
+ timestamp: data.timestamp
1538
+ });
1539
+ }
1540
+ /**
1541
+ * 验证结账参数
1542
+ */
1543
+ async validateCheckoutParams(params) {
1544
+ return (0, import_utils.validateCheckoutData)(params);
1545
+ }
1546
+ /**
1547
+ * 验证本地订单数据
1548
+ */
1549
+ async validateLocalOrderData(orderData) {
1550
+ const errors = [];
1551
+ if (!orderData.type) {
1552
+ errors.push("订单类型不能为空");
1553
+ }
1554
+ if (!orderData.platform) {
1555
+ errors.push("平台信息不能为空");
1556
+ }
1557
+ if (!orderData.bookings || orderData.bookings.length === 0) {
1558
+ errors.push("预订信息不能为空");
1559
+ }
1560
+ if (orderData.bookings) {
1561
+ orderData.bookings.forEach((booking, index) => {
1562
+ if (!booking.product || !booking.product.product_id) {
1563
+ errors.push(`预订项 ${index + 1} 缺少商品信息`);
1564
+ }
1565
+ if (!booking.start_date) {
1566
+ errors.push(`预订项 ${index + 1} 缺少开始日期`);
1567
+ }
1568
+ if (!booking.start_time) {
1569
+ errors.push(`预订项 ${index + 1} 缺少开始时间`);
1570
+ }
1571
+ });
1572
+ }
1573
+ return {
1574
+ valid: errors.length === 0,
1575
+ errors
1576
+ };
1577
+ }
1578
+ /**
1579
+ * 生成本地订单ID
1580
+ */
1581
+ generateLocalOrderId() {
1582
+ const timestamp = Date.now();
1583
+ const random = Math.floor(Math.random() * 1e4).toString().padStart(4, "0");
1584
+ return `local_order_${timestamp}_${random}`;
1585
+ }
1586
+ /**
1587
+ * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
1588
+ *
1589
+ * @param date 要格式化的日期对象
1590
+ * @returns 格式化后的日期时间字符串
1591
+ */
1592
+ formatDateTime(date) {
1593
+ const year = date.getFullYear();
1594
+ const month = String(date.getMonth() + 1).padStart(2, "0");
1595
+ const day = String(date.getDate()).padStart(2, "0");
1596
+ const hours = String(date.getHours()).padStart(2, "0");
1597
+ const minutes = String(date.getMinutes()).padStart(2, "0");
1598
+ const seconds = String(date.getSeconds()).padStart(2, "0");
1599
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
1600
+ }
1601
+ /**
1602
+ * 从购物车小计数据中提取金额信息
1603
+ */
1604
+ extractAmountFromCartSummary(cartSummary) {
1605
+ const result = {
1606
+ totalAmount: "0.00",
1607
+ subTotal: "0.00",
1608
+ taxAmount: "0.00",
1609
+ discountAmount: "0.00",
1610
+ shopDiscountAmount: "0.00",
1611
+ roundingAmount: "0.00"
1612
+ };
1613
+ cartSummary.forEach((item) => {
1614
+ const value = Number(item.value).toFixed(2);
1615
+ switch (item.key) {
1616
+ case "expect_amount":
1617
+ result.totalAmount = value;
1618
+ break;
1619
+ case "sub_total":
1620
+ result.subTotal = value;
1621
+ break;
1622
+ case "tax":
1623
+ result.taxAmount = value;
1624
+ if (item.tax) {
1625
+ result.taxDetails = item.tax;
1626
+ }
1627
+ break;
1628
+ case "discount":
1629
+ result.discountAmount = value;
1630
+ break;
1631
+ case "shop_discount":
1632
+ result.shopDiscountAmount = value;
1633
+ break;
1634
+ case "custom_roundingAmount":
1635
+ result.roundingAmount = value;
1636
+ break;
1637
+ default:
1638
+ if (item.key.includes("deposit")) {
1639
+ result.depositAmount = value;
1640
+ }
1641
+ break;
1642
+ }
1643
+ });
1644
+ console.log("[Checkout] 从购物车小计提取金额信息:", {
1645
+ totalAmount: result.totalAmount,
1646
+ subTotal: result.subTotal,
1647
+ taxAmount: result.taxAmount,
1648
+ discountAmount: result.discountAmount,
1649
+ shopDiscountAmount: result.shopDiscountAmount,
1650
+ roundingAmount: result.roundingAmount
1651
+ });
1652
+ return result;
1653
+ }
1654
+ /**
1655
+ * 预加载支付方式(在初始化时调用)
1656
+ */
1657
+ async preloadPaymentMethods() {
1658
+ try {
1659
+ console.log("[Checkout] 预加载支付方式...");
1660
+ const methods = await this.payment.getPayMethodListAsync();
1661
+ this.store.paymentMethods = methods;
1662
+ console.log(`[Checkout] 预加载完成,共 ${methods.length} 种支付方式`);
1663
+ } catch (error) {
1664
+ console.error("[Checkout] 预加载支付方式失败:", error);
1665
+ this.store.paymentMethods = [];
1666
+ }
1667
+ }
1668
+ /**
1669
+ * 计算总金额
1670
+ */
1671
+ calculateTotalAmount(cartItems) {
1672
+ const total = cartItems.reduce((sum, item) => {
1673
+ const price = parseFloat(String(item.price) || "0");
1674
+ const quantity = item.quantity || 1;
1675
+ return sum + price * quantity;
1676
+ }, 0);
1677
+ return total.toFixed(2);
1678
+ }
1679
+ /**
1680
+ * 计算已支付金额
1681
+ */
1682
+ calculatePaidAmount() {
1683
+ if (!this.store.currentOrder) {
1684
+ console.log("[Checkout] calculatePaidAmount: 没有当前订单");
1685
+ return "0.00";
1686
+ }
1687
+ const payments = this.store.currentOrder.payment || [];
1688
+ console.log("[Checkout] calculatePaidAmount: 支付项详情:", {
1689
+ paymentCount: payments.length,
1690
+ payments: payments.map((p) => ({
1691
+ uuid: p.uuid,
1692
+ amount: p.amount,
1693
+ code: p.code,
1694
+ status: p.status
1695
+ }))
1696
+ });
1697
+ const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
1698
+ const amount = parseFloat(payment.amount || "0");
1699
+ console.log(`[Checkout] 计算支付项: ${payment.code} = ${amount}`);
1700
+ return sum + amount;
1701
+ }, 0);
1702
+ const result = paidAmount.toFixed(2);
1703
+ console.log("[Checkout] calculatePaidAmount: 计算结果 =", result);
1704
+ return result;
1705
+ }
1706
+ /**
1707
+ * 计算剩余未支付金额
1708
+ */
1709
+ calculateRemainingAmount() {
1710
+ if (!this.store.currentOrder) {
1711
+ console.log("[Checkout] calculateRemainingAmount: 没有当前订单");
1712
+ return "0.00";
1713
+ }
1714
+ const totalAmount = parseFloat(this.store.currentOrder.total_amount || "0");
1715
+ const paidAmount = parseFloat(this.calculatePaidAmount());
1716
+ const remainingAmount = totalAmount - paidAmount;
1717
+ const result = Math.max(0, remainingAmount).toFixed(2);
1718
+ console.log("[Checkout] calculateRemainingAmount: 计算详情:", {
1719
+ orderUuid: this.store.currentOrder.uuid,
1720
+ totalAmount: totalAmount.toFixed(2),
1721
+ paidAmount: paidAmount.toFixed(2),
1722
+ calculatedRemaining: remainingAmount.toFixed(2),
1723
+ finalResult: result
1724
+ });
1725
+ return result;
1726
+ }
1727
+ /**
1728
+ * 更新 stateAmount 为当前剩余未支付金额
1729
+ */
1730
+ async updateStateAmountToRemaining() {
1731
+ var _a;
1732
+ try {
1733
+ const remainingAmount = this.calculateRemainingAmount();
1734
+ const currentStateAmount = this.store.stateAmount;
1735
+ console.log("[Checkout] updateStateAmountToRemaining: 状态检查:", {
1736
+ calculatedRemainingAmount: remainingAmount,
1737
+ currentStateAmount,
1738
+ needsUpdate: remainingAmount !== currentStateAmount,
1739
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
1740
+ });
1741
+ if (remainingAmount !== currentStateAmount) {
1742
+ this.store.stateAmount = remainingAmount;
1743
+ await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
1744
+ oldAmount: currentStateAmount,
1745
+ newAmount: remainingAmount,
1746
+ timestamp: Date.now()
1747
+ });
1748
+ console.log("[Checkout] stateAmount 已自动更新为剩余金额:", {
1749
+ oldAmount: currentStateAmount,
1750
+ newAmount: remainingAmount
1751
+ });
1752
+ } else {
1753
+ console.log("[Checkout] stateAmount 无需更新,当前值已是最新:", {
1754
+ stateAmount: currentStateAmount,
1755
+ remainingAmount
1756
+ });
1757
+ }
1758
+ await this.checkOrderPaymentCompletion();
1759
+ } catch (error) {
1760
+ console.error("[Checkout] 更新 stateAmount 为剩余金额失败:", error);
1761
+ }
1762
+ }
1763
+ /**
1764
+ * 检查订单支付是否完成
1765
+ *
1766
+ * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
1767
+ */
1768
+ async checkOrderPaymentCompletion() {
1769
+ var _a, _b;
1770
+ try {
1771
+ if (!this.store.currentOrder) {
1772
+ return;
1773
+ }
1774
+ const remainingAmount = this.calculateRemainingAmount();
1775
+ const remainingValue = parseFloat(remainingAmount);
1776
+ if (remainingValue <= 0) {
1777
+ const totalAmount = this.store.currentOrder.total_amount;
1778
+ const paidAmount = this.calculatePaidAmount();
1779
+ console.log("[Checkout] 检测到订单支付完成:", {
1780
+ orderUuid: this.store.currentOrder.uuid,
1781
+ orderId: this.store.currentOrder.order_id,
1782
+ totalAmount,
1783
+ paidAmount,
1784
+ remainingAmount,
1785
+ isOrderSynced: this.store.isOrderSynced
1786
+ });
1787
+ const allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(
1788
+ (item) => item.status !== "voided" && item.voucher_id
1789
+ );
1790
+ console.log("[Checkout] 支付项voucher_id检查:", {
1791
+ paymentCount: ((_a = this.store.currentOrder.payment) == null ? void 0 : _a.length) || 0,
1792
+ allHaveVoucherId: allPaymentsHaveVoucherId,
1793
+ paymentItems: (_b = this.store.currentOrder.payment) == null ? void 0 : _b.map((p) => ({
1794
+ uuid: p.uuid,
1795
+ code: p.code,
1796
+ amount: p.amount,
1797
+ voucher_id: p.voucher_id,
1798
+ status: p.status
1799
+ }))
1800
+ });
1801
+ if (!this.store.isOrderSynced) {
1802
+ if (allPaymentsHaveVoucherId) {
1803
+ console.log("[Checkout] 所有支付项均为代金券类型,跳过订单同步");
1804
+ } else {
1805
+ console.log("[Checkout] 支付完成但订单未同步,开始同步订单到后端...");
1806
+ await this.syncOrderToBackend();
1807
+ }
1808
+ }
1809
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
1810
+ orderUuid: this.store.currentOrder.uuid,
1811
+ orderId: this.store.currentOrder.order_id,
1812
+ totalAmount,
1813
+ paidAmount,
1814
+ remainingAmount,
1815
+ timestamp: Date.now()
1816
+ });
1817
+ }
1818
+ } catch (error) {
1819
+ console.error("[Checkout] 检查订单支付完成状态失败:", error);
1820
+ }
1821
+ }
1822
+ /**
1823
+ * 判断支付方式是否需要同步订单到后端
1824
+ *
1825
+ * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
1826
+ *
1827
+ * @param paymentCode 支付方式代码
1828
+ * @param paymentType 支付方式类型
1829
+ * @returns 是否需要同步订单
1830
+ */
1831
+ shouldSyncOrderForPayment(paymentCode, paymentType) {
1832
+ const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
1833
+ const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
1834
+ const cashIdentifiers = ["CASHMANUAL", "CASH", "MANUAL"];
1835
+ if (cashIdentifiers.some((id) => codeUpper.includes(id) || typeUpper.includes(id))) {
1836
+ return false;
1837
+ }
1838
+ if (paymentCode === import_types2.PaymentMethodType.Cash || paymentType === import_types2.PaymentMethodType.Cash) {
1839
+ return false;
1840
+ }
1841
+ if (codeUpper.includes("CUSTOM") || typeUpper.includes("CUSTOM")) {
1842
+ return false;
1843
+ }
1844
+ return true;
1845
+ }
1846
+ /**
1847
+ * 同步订单到后端
1848
+ *
1849
+ * 调用后端 /order/checkout 接口创建真实订单
1850
+ */
1851
+ /**
1852
+ * 判断订单ID是否为本地生成的虚拟ID
1853
+ *
1854
+ * @param orderId 订单ID
1855
+ * @returns true 表示是虚拟ID,false 表示是真实的后端ID
1856
+ */
1857
+ isVirtualOrderId(orderId) {
1858
+ return orderId.startsWith("local_order_");
1859
+ }
1860
+ /**
1861
+ * 同步订单到后端并返回真实订单ID
1862
+ *
1863
+ * @param isManual 是否为手动同步,默认为 false
1864
+ * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
1865
+ * @returns 后端返回的真实订单ID
1866
+ */
1867
+ async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
1868
+ var _a, _b, _c, _d;
1869
+ if (!this.store.localOrderData || !this.store.currentOrder) {
1870
+ throw new Error("缺少必要的订单数据,无法同步到后端");
1871
+ }
1872
+ const syncType = isManual ? "手动" : "自动";
1873
+ const currentOrderId = this.store.currentOrder.order_id;
1874
+ const hasRealOrderId = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1875
+ let isUpdateOperation = false;
1876
+ let reason = "";
1877
+ if (this.store.isOrderSynced) {
1878
+ isUpdateOperation = true;
1879
+ reason = "订单已同步过";
1880
+ } else if (hasRealOrderId) {
1881
+ isUpdateOperation = true;
1882
+ reason = "有真实订单ID";
1883
+ } else {
1884
+ isUpdateOperation = false;
1885
+ reason = "既未同步也无真实ID";
1886
+ }
1887
+ const operation = isUpdateOperation ? "更新" : "创建";
1888
+ console.log("[Checkout] 操作类型判断详情:", {
1889
+ currentOrderId,
1890
+ hasRealOrderId,
1891
+ isOrderSynced: this.store.isOrderSynced,
1892
+ isManual,
1893
+ reason,
1894
+ finalDecision: operation
1895
+ });
1896
+ console.log(`[Checkout] 开始${syncType}${operation}订单到后端...`, {
1897
+ currentOrderId,
1898
+ isVirtualId: this.isVirtualOrderId(currentOrderId || ""),
1899
+ operation,
1900
+ orderUuid: this.store.currentOrder.uuid,
1901
+ isOrderSynced: this.store.isOrderSynced
1902
+ });
1903
+ const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1904
+ console.log("[Checkout] 获取到支付项:", {
1905
+ count: paymentItems.length,
1906
+ isCustomFiltered: !!customPaymentItems,
1907
+ methods: paymentItems.map((p) => p.code),
1908
+ totalAmount: paymentItems.reduce((sum, p) => sum + parseFloat(p.amount), 0).toFixed(2),
1909
+ paymentDetails: paymentItems.map((p) => {
1910
+ var _a2;
1911
+ return {
1912
+ uuid: p.uuid,
1913
+ code: p.code,
1914
+ amount: p.amount,
1915
+ uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
1916
+ voucherId: p.voucher_id
1917
+ };
1918
+ })
1919
+ });
1920
+ const orderParams = {
1921
+ ...this.store.localOrderData,
1922
+ type: this.store.localOrderData.type,
1923
+ platform: this.store.localOrderData.platform,
1924
+ payments: paymentItems,
1925
+ // 添加支付项
1926
+ customer_id: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id,
1927
+ // 添加客户ID
1928
+ is_price_include_tax: this.otherParams.is_price_include_tax,
1929
+ // core 有
1930
+ tax_title: this.otherParams.tax_title,
1931
+ // core 没有
1932
+ tax_rate: this.otherParams.tax_rate,
1933
+ // core 有
1934
+ tax_country_code: this.otherParams.tax_country_code,
1935
+ // core 没有
1936
+ currency_code: this.otherParams.currency_code,
1937
+ currency_symbol: this.otherParams.currency_symbol,
1938
+ currency_format: this.otherParams.currency_format,
1939
+ is_deposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0,
1940
+ deposit_amount: ((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount) || "0.00",
1941
+ // surcharge_fee: this.otherParams.surcharge_fee,
1942
+ // surcharges: ,
1943
+ note: this.store.localOrderData.shop_note
1944
+ // deposit_amount:
1945
+ };
1946
+ if (isUpdateOperation) {
1947
+ if (this.isVirtualOrderId(currentOrderId)) {
1948
+ console.error("[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!", {
1949
+ currentOrderId,
1950
+ isOrderSynced: this.store.isOrderSynced,
1951
+ reason,
1952
+ orderUuid: this.store.currentOrder.uuid
1953
+ });
1954
+ console.log("[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理");
1955
+ console.log("[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性");
1956
+ } else {
1957
+ orderParams.order_id = currentOrderId;
1958
+ console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
1959
+ }
1960
+ } else {
1961
+ console.log("[Checkout] 创建新订单操作");
1962
+ }
1963
+ const checkoutResponse = await this.order.createOrderByCheckout(orderParams);
1964
+ console.log("[Checkout] 后端返回的响应数据:", {
1965
+ status: checkoutResponse == null ? void 0 : checkoutResponse.status,
1966
+ code: checkoutResponse == null ? void 0 : checkoutResponse.code,
1967
+ message: checkoutResponse == null ? void 0 : checkoutResponse.message,
1968
+ data: checkoutResponse == null ? void 0 : checkoutResponse.data
1969
+ });
1970
+ let realOrderId;
1971
+ if (isUpdateOperation) {
1972
+ realOrderId = currentOrderId;
1973
+ console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
1974
+ } else {
1975
+ let extractedOrderId = (_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id;
1976
+ if (!extractedOrderId) {
1977
+ extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
1978
+ }
1979
+ if (extractedOrderId !== void 0 && extractedOrderId !== null) {
1980
+ extractedOrderId = String(extractedOrderId);
1981
+ }
1982
+ if (!extractedOrderId) {
1983
+ throw new Error("后端返回的订单信息中未包含订单ID");
1984
+ }
1985
+ realOrderId = extractedOrderId;
1986
+ console.log("[Checkout] 订单创建成功,真实订单ID:", realOrderId);
1987
+ console.log("[Checkout] 准备替换订单ID:", {
1988
+ orderUuid: this.store.currentOrder.uuid,
1989
+ oldOrderId: this.store.currentOrder.order_id,
1990
+ newOrderId: realOrderId
1991
+ });
1992
+ try {
1993
+ const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
1994
+ this.store.currentOrder.uuid,
1995
+ realOrderId
1996
+ );
1997
+ console.log("[Checkout] Payment模块替换订单ID结果:", {
1998
+ wasSuccessful: !!updatedOrder,
1999
+ returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
2000
+ expectedOrderId: realOrderId
2001
+ });
2002
+ if (updatedOrder) {
2003
+ console.log("[Checkout] Payment模块返回的更新后订单:", {
2004
+ uuid: updatedOrder.uuid,
2005
+ orderId: updatedOrder.order_id,
2006
+ totalAmount: updatedOrder.total_amount
2007
+ });
2008
+ this.store.currentOrder = updatedOrder;
2009
+ console.log("[Checkout] 订单ID替换成功,当前订单ID:", this.store.currentOrder.order_id);
2010
+ } else {
2011
+ console.error("[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换");
2012
+ const beforeManualUpdate = this.store.currentOrder.order_id;
2013
+ this.store.currentOrder.order_id = realOrderId;
2014
+ console.log("[Checkout] 手动设置订单ID:", {
2015
+ 替换前: beforeManualUpdate,
2016
+ 替换后: this.store.currentOrder.order_id,
2017
+ 目标ID: realOrderId
2018
+ });
2019
+ }
2020
+ } catch (error) {
2021
+ console.error("[Checkout] 调用Payment模块替换订单ID时发生错误:", error);
2022
+ this.store.currentOrder.order_id = realOrderId;
2023
+ console.log("[Checkout] 错误恢复:手动设置订单ID:", realOrderId);
2024
+ }
2025
+ }
2026
+ this.store.isOrderSynced = true;
2027
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSynced, {
2028
+ orderUuid: this.store.currentOrder.uuid,
2029
+ realOrderId,
2030
+ virtualOrderId: this.store.currentOrder.order_id,
2031
+ timestamp: Date.now(),
2032
+ isManual
2033
+ });
2034
+ const finalOrderId = this.store.currentOrder.order_id;
2035
+ const finalIsVirtual = this.isVirtualOrderId(finalOrderId || "");
2036
+ console.log(`[Checkout] ${syncType}${operation}订单到后端完成`, {
2037
+ 返回的订单ID: realOrderId,
2038
+ 当前存储的订单ID: finalOrderId,
2039
+ 是否还是虚拟ID: finalIsVirtual,
2040
+ 是否同步: this.store.isOrderSynced
2041
+ });
2042
+ if (finalIsVirtual && !isUpdateOperation) {
2043
+ console.warn("[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题");
2044
+ }
2045
+ return realOrderId;
2046
+ }
2047
+ async syncOrderToBackend() {
2048
+ try {
2049
+ await this.syncOrderToBackendWithReturn(false);
2050
+ } catch (error) {
2051
+ console.error("[Checkout] 同步订单到后端失败:", error);
2052
+ await this.handleError(
2053
+ new Error(`订单同步失败: ${error instanceof Error ? error.message : String(error)}`),
2054
+ import_types.CheckoutErrorType.OrderCreationFailed
2055
+ );
2056
+ }
2057
+ }
2058
+ /**
2059
+ * 获取状态消息
2060
+ */
2061
+ getStatusMessage() {
2062
+ var _a;
2063
+ switch (this.store.status) {
2064
+ case import_types.CheckoutStatus.Initializing:
2065
+ return "正在初始化结账流程...";
2066
+ case import_types.CheckoutStatus.Ready:
2067
+ return "准备就绪,可以开始结账";
2068
+ case import_types.CheckoutStatus.CreatingOrder:
2069
+ return "正在创建订单...";
2070
+ case import_types.CheckoutStatus.OrderCreated:
2071
+ return "订单创建成功,请选择支付方式";
2072
+ case import_types.CheckoutStatus.ProcessingPayment:
2073
+ return "正在处理支付...";
2074
+ case import_types.CheckoutStatus.PaymentCompleted:
2075
+ return "支付完成";
2076
+ case import_types.CheckoutStatus.Completed:
2077
+ return "结账完成";
2078
+ case import_types.CheckoutStatus.Cancelled:
2079
+ return "结账已取消";
2080
+ case import_types.CheckoutStatus.Error:
2081
+ return ((_a = this.store.lastError) == null ? void 0 : _a.message) || "发生未知错误";
2082
+ default:
2083
+ return "";
2084
+ }
2085
+ }
2086
+ async setOtherParams(params, { cover = false } = {}) {
2087
+ if (cover) {
2088
+ this.otherParams = params;
2089
+ } else {
2090
+ this.otherParams = { ...this.otherParams, ...params };
2091
+ }
2092
+ }
2093
+ async destroy() {
2094
+ var _a, _b, _c, _d;
2095
+ this.payment.wallet.clearAllCache();
2096
+ this.core.effects.offByModuleDestroy(this.name);
2097
+ await ((_b = (_a = this.order) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a));
2098
+ await ((_d = (_c = this.payment) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c));
2099
+ this.core.unregisterModule(this);
2100
+ console.log("[Checkout] 已销毁");
2101
+ }
2102
+ };
2103
+ // Annotate the CommonJS export names for ESM import in node:
2104
+ 0 && (module.exports = {
2105
+ CheckoutImpl,
2106
+ ...require("./types")
2107
+ });