@pisell/pisellos 0.0.252 → 0.0.253
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 -0
- package/dist/modules/Order/index.js +130 -15
- package/dist/solution/Checkout/index.d.ts +17 -38
- package/dist/solution/Checkout/index.js +947 -836
- package/dist/solution/Checkout/utils/index.d.ts +45 -1
- package/dist/solution/Checkout/utils/index.js +179 -1
- package/lib/modules/Order/index.d.ts +13 -0
- package/lib/modules/Order/index.js +108 -9
- package/lib/solution/Checkout/index.d.ts +17 -38
- package/lib/solution/Checkout/index.js +291 -214
- package/lib/solution/Checkout/utils/index.d.ts +45 -1
- package/lib/solution/Checkout/utils/index.js +139 -2
- package/package.json +1 -1
|
@@ -45,6 +45,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
45
45
|
if (!this.request) {
|
|
46
46
|
throw new Error("Checkout 解决方案需要 request 插件支持");
|
|
47
47
|
}
|
|
48
|
+
this.logger = core.getPlugin("logger");
|
|
48
49
|
this.order = new import_Order.OrderModule();
|
|
49
50
|
this.payment = new import_Payment.PaymentModule();
|
|
50
51
|
this.store = {
|
|
@@ -60,11 +61,49 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
60
61
|
};
|
|
61
62
|
await this.initializeSubModules(core, options);
|
|
62
63
|
await this.preloadPaymentMethods();
|
|
63
|
-
await this.
|
|
64
|
+
await this.cleanupExpiredOrdersAsync();
|
|
65
|
+
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
64
66
|
console.log("[Checkout] 初始化完成");
|
|
65
67
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
|
|
66
68
|
timestamp: Date.now()
|
|
67
69
|
});
|
|
70
|
+
this.logInfo("CheckoutModule initialized successfully");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 记录信息日志
|
|
74
|
+
*/
|
|
75
|
+
logInfo(title, metadata) {
|
|
76
|
+
if (this.logger) {
|
|
77
|
+
this.logger.addLog({
|
|
78
|
+
type: "info",
|
|
79
|
+
title: `[CheckoutModule] ${title}`,
|
|
80
|
+
metadata: metadata || {}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 记录警告日志
|
|
86
|
+
*/
|
|
87
|
+
logWarning(title, metadata) {
|
|
88
|
+
if (this.logger) {
|
|
89
|
+
this.logger.addLog({
|
|
90
|
+
type: "warning",
|
|
91
|
+
title: `[CheckoutModule] ${title}`,
|
|
92
|
+
metadata: metadata || {}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 记录错误日志
|
|
98
|
+
*/
|
|
99
|
+
logError(title, metadata) {
|
|
100
|
+
if (this.logger) {
|
|
101
|
+
this.logger.addLog({
|
|
102
|
+
type: "error",
|
|
103
|
+
title: `[CheckoutModule] ${title}`,
|
|
104
|
+
metadata: metadata || {}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
68
107
|
}
|
|
69
108
|
/**
|
|
70
109
|
* 初始化子模块
|
|
@@ -119,8 +158,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
119
158
|
* 初始化结账流程
|
|
120
159
|
*/
|
|
121
160
|
async initializeCheckoutAsync(params) {
|
|
161
|
+
var _a;
|
|
162
|
+
this.logInfo("initializeCheckoutAsync called", {
|
|
163
|
+
cartItemsCount: ((_a = params.cartItems) == null ? void 0 : _a.length) || 0,
|
|
164
|
+
orderType: params.orderType,
|
|
165
|
+
platform: params.platform
|
|
166
|
+
});
|
|
122
167
|
try {
|
|
123
|
-
|
|
168
|
+
this.setStatus(import_types.CheckoutStatus.Initializing);
|
|
124
169
|
const validation = this.validateCheckoutParams(params);
|
|
125
170
|
if (!validation.valid) {
|
|
126
171
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -129,8 +174,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
129
174
|
);
|
|
130
175
|
}
|
|
131
176
|
this.store.cartItems = params.cartItems;
|
|
132
|
-
|
|
133
|
-
|
|
177
|
+
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
178
|
+
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
134
179
|
console.log("[Checkout] 结账流程初始化完成");
|
|
135
180
|
} catch (error) {
|
|
136
181
|
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
@@ -200,25 +245,36 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
200
245
|
* 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
|
|
201
246
|
*/
|
|
202
247
|
async createLocalOrderAsync(params) {
|
|
203
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
248
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
249
|
+
this.logInfo("createLocalOrderAsync called", {
|
|
250
|
+
orderDataType: (_a = params.orderData) == null ? void 0 : _a.type,
|
|
251
|
+
platform: (_b = params.orderData) == null ? void 0 : _b.platform,
|
|
252
|
+
bookingsCount: ((_d = (_c = params.orderData) == null ? void 0 : _c.bookings) == null ? void 0 : _d.length) || 0,
|
|
253
|
+
relationProductsCount: ((_f = (_e = params.orderData) == null ? void 0 : _e.relation_products) == null ? void 0 : _f.length) || 0,
|
|
254
|
+
customerId: (_g = params.orderData) == null ? void 0 : _g.customer_id,
|
|
255
|
+
autoPayment: params.autoPayment,
|
|
256
|
+
cartSummaryCount: ((_h = params.cartSummary) == null ? void 0 : _h.length) || 0,
|
|
257
|
+
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
258
|
+
});
|
|
204
259
|
try {
|
|
260
|
+
console.time("createLocalOrderAsync");
|
|
205
261
|
await this.resetStoreStateAsync();
|
|
206
|
-
|
|
207
|
-
const validation =
|
|
262
|
+
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
263
|
+
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
208
264
|
if (!validation.valid) {
|
|
209
265
|
throw (0, import_utils.createCheckoutError)(
|
|
210
266
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
211
267
|
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
212
268
|
);
|
|
213
269
|
}
|
|
214
|
-
const localOrderId =
|
|
215
|
-
const amountInfo =
|
|
270
|
+
const localOrderId = (0, import_utils.generateLocalOrderId)();
|
|
271
|
+
const amountInfo = (0, import_utils.extractAmountFromCartSummary)(params.cartSummary);
|
|
216
272
|
params.orderData.platform = "pos";
|
|
217
|
-
params.orderData.created_at =
|
|
218
|
-
params.orderData.surcharge_fee = (
|
|
219
|
-
params.orderData.surcharges = (
|
|
220
|
-
params.orderData.shop_discount = (
|
|
221
|
-
params.orderData.tax_fee = (
|
|
273
|
+
params.orderData.created_at = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
274
|
+
params.orderData.surcharge_fee = (_j = (_i = params.totalInfo) == null ? void 0 : _i.total) == null ? void 0 : _j.otherAmount;
|
|
275
|
+
params.orderData.surcharges = (_l = (_k = params.totalInfo) == null ? void 0 : _k.total) == null ? void 0 : _l.surcharge;
|
|
276
|
+
params.orderData.shop_discount = (_n = (_m = params.totalInfo) == null ? void 0 : _m.total) == null ? void 0 : _n.shopDiscount;
|
|
277
|
+
params.orderData.tax_fee = (_p = (_o = params.totalInfo) == null ? void 0 : _o.total) == null ? void 0 : _p.tax;
|
|
222
278
|
this.store.localOrderData = params.orderData;
|
|
223
279
|
this.store.cartSummary = params.cartSummary;
|
|
224
280
|
const customerInfo = {
|
|
@@ -248,12 +304,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
248
304
|
amount_breakdown: amountInfo
|
|
249
305
|
}
|
|
250
306
|
});
|
|
307
|
+
console.timeEnd("createLocalOrderAsync");
|
|
251
308
|
this.store.currentOrder = paymentOrder;
|
|
252
309
|
this.initWalletData();
|
|
253
|
-
|
|
254
|
-
|
|
310
|
+
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
311
|
+
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
255
312
|
if (params.autoPayment) {
|
|
256
|
-
|
|
313
|
+
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
257
314
|
}
|
|
258
315
|
this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
259
316
|
order: paymentOrder,
|
|
@@ -287,7 +344,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
287
344
|
* 使用当前存储的本地订单数据调用 Order 模块创建真实订单
|
|
288
345
|
*/
|
|
289
346
|
async placeOrderAsync(params = {}) {
|
|
290
|
-
var _a;
|
|
347
|
+
var _a, _b;
|
|
348
|
+
this.logInfo("placeOrderAsync called", {
|
|
349
|
+
url: params.url,
|
|
350
|
+
autoReplaceOrderId: params.autoReplaceOrderId,
|
|
351
|
+
hasLocalOrderData: !!this.store.localOrderData,
|
|
352
|
+
hasCurrentOrder: !!this.store.currentOrder,
|
|
353
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
354
|
+
isOrderSynced: this.store.isOrderSynced
|
|
355
|
+
});
|
|
291
356
|
try {
|
|
292
357
|
if (!this.store.localOrderData) {
|
|
293
358
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -302,7 +367,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
302
367
|
);
|
|
303
368
|
}
|
|
304
369
|
console.log("[Checkout] 开始手动下单流程...");
|
|
305
|
-
|
|
370
|
+
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
306
371
|
const orderData = {
|
|
307
372
|
cartItems: this.store.cartItems,
|
|
308
373
|
type: this.store.localOrderData.type,
|
|
@@ -313,7 +378,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
313
378
|
// 可选的自定义 URL
|
|
314
379
|
query: orderData
|
|
315
380
|
});
|
|
316
|
-
const realOrderId = ((
|
|
381
|
+
const realOrderId = ((_b = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _b.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
|
|
317
382
|
if (!realOrderId) {
|
|
318
383
|
throw (0, import_utils.createCheckoutError)(
|
|
319
384
|
import_types.CheckoutErrorType.OrderCreationFailed,
|
|
@@ -331,7 +396,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
331
396
|
});
|
|
332
397
|
}
|
|
333
398
|
}
|
|
334
|
-
|
|
399
|
+
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
335
400
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
336
401
|
order: this.store.currentOrder,
|
|
337
402
|
timestamp: Date.now()
|
|
@@ -366,7 +431,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
366
431
|
async createOrderAsync(params) {
|
|
367
432
|
var _a;
|
|
368
433
|
try {
|
|
369
|
-
|
|
434
|
+
this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
370
435
|
const checkResult = this.order.checkBeforeSubmitOrder({
|
|
371
436
|
cartItems: params.cartItems,
|
|
372
437
|
type: "account"
|
|
@@ -387,12 +452,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
387
452
|
});
|
|
388
453
|
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
389
454
|
order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
|
|
390
|
-
total_amount:
|
|
455
|
+
total_amount: (0, import_utils.calculateTotalAmount)(params.cartItems),
|
|
391
456
|
order_info: orderResponse == null ? void 0 : orderResponse.data
|
|
392
457
|
});
|
|
393
458
|
this.store.currentOrder = paymentOrder;
|
|
394
|
-
|
|
395
|
-
|
|
459
|
+
this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
460
|
+
this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
396
461
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
397
462
|
order: paymentOrder,
|
|
398
463
|
timestamp: Date.now()
|
|
@@ -424,8 +489,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
424
489
|
"未找到当前订单,请先创建订单"
|
|
425
490
|
);
|
|
426
491
|
}
|
|
427
|
-
|
|
428
|
-
|
|
492
|
+
this.setStatus(import_types.CheckoutStatus.ProcessingPayment);
|
|
493
|
+
this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
429
494
|
const paymentMethod = this.store.paymentMethods.find(
|
|
430
495
|
(method) => method.code === params.paymentMethodCode
|
|
431
496
|
);
|
|
@@ -456,7 +521,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
456
521
|
timestamp: Date.now()
|
|
457
522
|
});
|
|
458
523
|
if (result.status === "success") {
|
|
459
|
-
|
|
524
|
+
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
460
525
|
await this.updateStateAmountToRemaining();
|
|
461
526
|
await this.handlePaymentSuccess({
|
|
462
527
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -494,8 +559,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
494
559
|
);
|
|
495
560
|
}
|
|
496
561
|
this.payment.wallet.clearAllCache();
|
|
497
|
-
|
|
498
|
-
|
|
562
|
+
this.setStatus(import_types.CheckoutStatus.Completed);
|
|
563
|
+
this.setStep(import_types.CheckoutStep.Complete);
|
|
499
564
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
500
565
|
orderId: order.id,
|
|
501
566
|
timestamp: Date.now()
|
|
@@ -530,7 +595,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
530
595
|
this.store.balanceDueAmount = "0.00";
|
|
531
596
|
this.store.isOrderSynced = false;
|
|
532
597
|
this.store.currentCustomer = void 0;
|
|
533
|
-
|
|
598
|
+
this.setStatus(import_types.CheckoutStatus.Cancelled);
|
|
534
599
|
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
|
|
535
600
|
timestamp: Date.now()
|
|
536
601
|
});
|
|
@@ -889,7 +954,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
889
954
|
console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
|
|
890
955
|
return null;
|
|
891
956
|
}
|
|
892
|
-
const extractedInfo =
|
|
957
|
+
const extractedInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
893
958
|
this.store.cartSummary
|
|
894
959
|
);
|
|
895
960
|
console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
|
|
@@ -932,7 +997,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
932
997
|
* @throws 当前没有活跃订单时抛出错误
|
|
933
998
|
*/
|
|
934
999
|
async addPaymentItemAsync(paymentItem) {
|
|
935
|
-
var _a, _b;
|
|
1000
|
+
var _a, _b, _c, _d;
|
|
1001
|
+
this.logInfo("addPaymentItemAsync called", {
|
|
1002
|
+
paymentCode: paymentItem.code,
|
|
1003
|
+
paymentType: paymentItem.type,
|
|
1004
|
+
amount: paymentItem.amount,
|
|
1005
|
+
voucherId: paymentItem.voucher_id,
|
|
1006
|
+
serviceCharge: paymentItem.service_charge,
|
|
1007
|
+
roundingAmount: paymentItem.rounding_amount,
|
|
1008
|
+
hasMetadata: !!paymentItem.metadata,
|
|
1009
|
+
hasCurrentOrder: !!this.store.currentOrder,
|
|
1010
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1011
|
+
isDepositOrder: (_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit
|
|
1012
|
+
});
|
|
936
1013
|
try {
|
|
937
1014
|
if (!this.store.currentOrder) {
|
|
938
1015
|
throw (0, import_utils.createCheckoutError)(
|
|
@@ -972,7 +1049,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
972
1049
|
paymentItemWithType
|
|
973
1050
|
);
|
|
974
1051
|
console.log("[Checkout] 支付项添加成功");
|
|
975
|
-
const isEftposPayment = ((
|
|
1052
|
+
const isEftposPayment = ((_c = paymentItem.type) == null ? void 0 : _c.toLowerCase()) === "eftpos" || ((_d = paymentItem.code) == null ? void 0 : _d.toUpperCase().includes("EFTPOS"));
|
|
976
1053
|
console.log("[Checkout] EFTPOS 支付检查:", {
|
|
977
1054
|
paymentCode: paymentItem.code,
|
|
978
1055
|
paymentType: paymentItem.type,
|
|
@@ -1054,12 +1131,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1054
1131
|
);
|
|
1055
1132
|
console.log("[Checkout] Payment模块删除完成");
|
|
1056
1133
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1057
|
-
const isCurrentOrderReal = currentOrderId && !
|
|
1134
|
+
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1058
1135
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
1059
1136
|
this.store.currentOrder.uuid
|
|
1060
1137
|
);
|
|
1061
1138
|
if (updatedOrder) {
|
|
1062
|
-
if (isCurrentOrderReal &&
|
|
1139
|
+
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1063
1140
|
console.warn(
|
|
1064
1141
|
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1065
1142
|
{
|
|
@@ -1143,12 +1220,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1143
1220
|
);
|
|
1144
1221
|
console.log("[Checkout] Payment模块批量更新完成");
|
|
1145
1222
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1146
|
-
const isCurrentOrderReal = currentOrderId && !
|
|
1223
|
+
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1147
1224
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
1148
1225
|
this.store.currentOrder.uuid
|
|
1149
1226
|
);
|
|
1150
1227
|
if (updatedOrder) {
|
|
1151
|
-
if (isCurrentOrderReal &&
|
|
1228
|
+
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1152
1229
|
console.warn(
|
|
1153
1230
|
"[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1154
1231
|
{
|
|
@@ -1359,7 +1436,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1359
1436
|
* 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
|
|
1360
1437
|
*/
|
|
1361
1438
|
async manualSyncOrderAsync() {
|
|
1362
|
-
var _a;
|
|
1439
|
+
var _a, _b, _c, _d;
|
|
1440
|
+
this.logInfo("manualSyncOrderAsync called", {
|
|
1441
|
+
hasCurrentOrder: !!this.store.currentOrder,
|
|
1442
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1443
|
+
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1444
|
+
totalAmount: (_c = this.store.currentOrder) == null ? void 0 : _c.total_amount,
|
|
1445
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
1446
|
+
isVirtualOrderId: this.store.currentOrder ? (0, import_utils.isVirtualOrderId)(this.store.currentOrder.order_id) : false
|
|
1447
|
+
});
|
|
1363
1448
|
try {
|
|
1364
1449
|
if (!this.store.currentOrder) {
|
|
1365
1450
|
return {
|
|
@@ -1387,7 +1472,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1387
1472
|
isOrderSynced: this.store.isOrderSynced
|
|
1388
1473
|
});
|
|
1389
1474
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1390
|
-
const finalIsVirtual =
|
|
1475
|
+
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId);
|
|
1391
1476
|
console.log("[Checkout] manualSyncOrderAsync 最终状态验证:", {
|
|
1392
1477
|
返回的订单ID: syncResult.orderId,
|
|
1393
1478
|
存储的订单ID: finalOrderId,
|
|
@@ -1410,7 +1495,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1410
1495
|
return {
|
|
1411
1496
|
success: false,
|
|
1412
1497
|
message: `订单同步失败: ${errorMessage}`,
|
|
1413
|
-
orderUuid: (
|
|
1498
|
+
orderUuid: (_d = this.store.currentOrder) == null ? void 0 : _d.uuid
|
|
1414
1499
|
};
|
|
1415
1500
|
}
|
|
1416
1501
|
}
|
|
@@ -1659,7 +1744,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1659
1744
|
console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
|
|
1660
1745
|
}
|
|
1661
1746
|
if (this.store.currentOrder && this.store.cartSummary) {
|
|
1662
|
-
const updatedAmountInfo =
|
|
1747
|
+
const updatedAmountInfo = (0, import_utils.extractAmountFromCartSummary)(
|
|
1663
1748
|
this.store.cartSummary
|
|
1664
1749
|
);
|
|
1665
1750
|
console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
|
|
@@ -1744,10 +1829,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1744
1829
|
/**
|
|
1745
1830
|
* 设置状态
|
|
1746
1831
|
*/
|
|
1747
|
-
|
|
1832
|
+
setStatus(status) {
|
|
1748
1833
|
const oldStatus = this.store.status;
|
|
1749
1834
|
this.store.status = status;
|
|
1750
|
-
|
|
1835
|
+
this.core.effects.emit(import_types.CheckoutHooks.OnStatusChanged, {
|
|
1751
1836
|
oldStatus,
|
|
1752
1837
|
newStatus: status,
|
|
1753
1838
|
timestamp: Date.now()
|
|
@@ -1756,10 +1841,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1756
1841
|
/**
|
|
1757
1842
|
* 设置步骤
|
|
1758
1843
|
*/
|
|
1759
|
-
|
|
1844
|
+
setStep(step) {
|
|
1760
1845
|
const oldStep = this.store.step;
|
|
1761
1846
|
this.store.step = step;
|
|
1762
|
-
|
|
1847
|
+
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
1763
1848
|
oldStep,
|
|
1764
1849
|
newStep: step,
|
|
1765
1850
|
timestamp: Date.now()
|
|
@@ -1771,7 +1856,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1771
1856
|
async handleError(error, type) {
|
|
1772
1857
|
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1773
1858
|
this.store.lastError = checkoutError;
|
|
1774
|
-
|
|
1859
|
+
this.setStatus(import_types.CheckoutStatus.Error);
|
|
1775
1860
|
await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
|
|
1776
1861
|
error: checkoutError,
|
|
1777
1862
|
context: { status: this.store.status, step: this.store.step },
|
|
@@ -1784,7 +1869,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1784
1869
|
*/
|
|
1785
1870
|
async handlePaymentSuccess(data) {
|
|
1786
1871
|
var _a;
|
|
1787
|
-
|
|
1872
|
+
this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
1788
1873
|
await this.updateStateAmountToRemaining();
|
|
1789
1874
|
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
1790
1875
|
orderUuid: data.orderUuid,
|
|
@@ -1820,115 +1905,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1820
1905
|
validateCheckoutParams(params) {
|
|
1821
1906
|
return (0, import_utils.validateCheckoutData)(params);
|
|
1822
1907
|
}
|
|
1823
|
-
/**
|
|
1824
|
-
* 验证本地订单数据
|
|
1825
|
-
*/
|
|
1826
|
-
validateLocalOrderData(orderData) {
|
|
1827
|
-
var _a;
|
|
1828
|
-
const errors = [];
|
|
1829
|
-
if (!orderData.type) {
|
|
1830
|
-
errors.push("订单类型不能为空");
|
|
1831
|
-
}
|
|
1832
|
-
if (!orderData.platform) {
|
|
1833
|
-
errors.push("平台信息不能为空");
|
|
1834
|
-
}
|
|
1835
|
-
if ((!orderData.bookings || orderData.bookings.length === 0) && !((_a = orderData == null ? void 0 : orderData.relation_products) == null ? void 0 : _a.length)) {
|
|
1836
|
-
errors.push("预订信息不能为空");
|
|
1837
|
-
}
|
|
1838
|
-
if (orderData.bookings) {
|
|
1839
|
-
orderData.bookings.forEach((booking, index) => {
|
|
1840
|
-
if (!booking.product || !booking.product.product_id) {
|
|
1841
|
-
errors.push(`预订项 ${index + 1} 缺少商品信息`);
|
|
1842
|
-
}
|
|
1843
|
-
if (!booking.start_date) {
|
|
1844
|
-
errors.push(`预订项 ${index + 1} 缺少开始日期`);
|
|
1845
|
-
}
|
|
1846
|
-
if (!booking.start_time) {
|
|
1847
|
-
errors.push(`预订项 ${index + 1} 缺少开始时间`);
|
|
1848
|
-
}
|
|
1849
|
-
});
|
|
1850
|
-
}
|
|
1851
|
-
return {
|
|
1852
|
-
valid: errors.length === 0,
|
|
1853
|
-
errors
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
/**
|
|
1857
|
-
* 生成本地订单ID
|
|
1858
|
-
*/
|
|
1859
|
-
generateLocalOrderId() {
|
|
1860
|
-
const timestamp = Date.now();
|
|
1861
|
-
const random = Math.floor(Math.random() * 1e4).toString().padStart(4, "0");
|
|
1862
|
-
return `local_order_${timestamp}_${random}`;
|
|
1863
|
-
}
|
|
1864
|
-
/**
|
|
1865
|
-
* 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
|
|
1866
|
-
*
|
|
1867
|
-
* @param date 要格式化的日期对象
|
|
1868
|
-
* @returns 格式化后的日期时间字符串
|
|
1869
|
-
*/
|
|
1870
|
-
formatDateTime(date) {
|
|
1871
|
-
const year = date.getFullYear();
|
|
1872
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
1873
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
1874
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
1875
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
1876
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
1877
|
-
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
1878
|
-
}
|
|
1879
|
-
/**
|
|
1880
|
-
* 从购物车小计数据中提取金额信息
|
|
1881
|
-
*/
|
|
1882
|
-
extractAmountFromCartSummary(cartSummary) {
|
|
1883
|
-
const result = {
|
|
1884
|
-
totalAmount: "0.00",
|
|
1885
|
-
subTotal: "0.00",
|
|
1886
|
-
taxAmount: "0.00",
|
|
1887
|
-
discountAmount: "0.00",
|
|
1888
|
-
shopDiscountAmount: "0.00",
|
|
1889
|
-
roundingAmount: "0.00"
|
|
1890
|
-
};
|
|
1891
|
-
cartSummary.forEach((item) => {
|
|
1892
|
-
const value = Number(item.value).toFixed(2);
|
|
1893
|
-
switch (item.key) {
|
|
1894
|
-
case "expect_amount":
|
|
1895
|
-
result.totalAmount = value;
|
|
1896
|
-
break;
|
|
1897
|
-
case "sub_total":
|
|
1898
|
-
result.subTotal = value;
|
|
1899
|
-
break;
|
|
1900
|
-
case "tax":
|
|
1901
|
-
result.taxAmount = value;
|
|
1902
|
-
if (item.tax) {
|
|
1903
|
-
result.taxDetails = item.tax;
|
|
1904
|
-
}
|
|
1905
|
-
break;
|
|
1906
|
-
case "discount":
|
|
1907
|
-
result.discountAmount = value;
|
|
1908
|
-
break;
|
|
1909
|
-
case "shop_discount":
|
|
1910
|
-
result.shopDiscountAmount = value;
|
|
1911
|
-
break;
|
|
1912
|
-
case "custom_roundingAmount":
|
|
1913
|
-
result.roundingAmount = value;
|
|
1914
|
-
break;
|
|
1915
|
-
default:
|
|
1916
|
-
if (item.key.includes("deposit")) {
|
|
1917
|
-
result.depositAmount = value;
|
|
1918
|
-
}
|
|
1919
|
-
break;
|
|
1920
|
-
}
|
|
1921
|
-
});
|
|
1922
|
-
console.log("[Checkout] 从购物车小计提取金额信息:", {
|
|
1923
|
-
totalAmount: result.totalAmount,
|
|
1924
|
-
subTotal: result.subTotal,
|
|
1925
|
-
taxAmount: result.taxAmount,
|
|
1926
|
-
discountAmount: result.discountAmount,
|
|
1927
|
-
shopDiscountAmount: result.shopDiscountAmount,
|
|
1928
|
-
roundingAmount: result.roundingAmount
|
|
1929
|
-
});
|
|
1930
|
-
return result;
|
|
1931
|
-
}
|
|
1932
1908
|
/**
|
|
1933
1909
|
* 预加载支付方式(在初始化时调用)
|
|
1934
1910
|
*/
|
|
@@ -1944,15 +1920,91 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1944
1920
|
}
|
|
1945
1921
|
}
|
|
1946
1922
|
/**
|
|
1947
|
-
*
|
|
1923
|
+
* 清理过期的已同步订单数据
|
|
1924
|
+
*
|
|
1925
|
+
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
1948
1926
|
*/
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1927
|
+
async cleanupExpiredOrdersAsync() {
|
|
1928
|
+
var _a, _b, _c;
|
|
1929
|
+
try {
|
|
1930
|
+
const cleanupConfig = this.otherParams.orderDataCleanup || {};
|
|
1931
|
+
const isCleanupEnabled = cleanupConfig.enabled !== false;
|
|
1932
|
+
const retentionDays = cleanupConfig.retentionDays || 7;
|
|
1933
|
+
const maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100;
|
|
1934
|
+
if (!isCleanupEnabled) {
|
|
1935
|
+
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
console.log(`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`);
|
|
1939
|
+
const allOrders = await this.payment.getOrderListAsync();
|
|
1940
|
+
if (!allOrders || allOrders.length === 0) {
|
|
1941
|
+
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
const thresholdDate = /* @__PURE__ */ new Date();
|
|
1945
|
+
thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
|
|
1946
|
+
let deletedCount = 0;
|
|
1947
|
+
const ordersToDelete = [];
|
|
1948
|
+
for (const order of allOrders) {
|
|
1949
|
+
try {
|
|
1950
|
+
const isSynced = order.order_id && !(0, import_utils.isVirtualOrderId)(order.order_id);
|
|
1951
|
+
if (!isSynced) {
|
|
1952
|
+
continue;
|
|
1953
|
+
}
|
|
1954
|
+
let orderCreatedAt = null;
|
|
1955
|
+
if ((_a = order.order_info) == null ? void 0 : _a.created_at) {
|
|
1956
|
+
orderCreatedAt = new Date(order.order_info.created_at);
|
|
1957
|
+
} else if ((_c = (_b = order.order_info) == null ? void 0 : _b.original_order_data) == null ? void 0 : _c.created_at) {
|
|
1958
|
+
orderCreatedAt = new Date(order.order_info.original_order_data.created_at);
|
|
1959
|
+
}
|
|
1960
|
+
if (!orderCreatedAt || isNaN(orderCreatedAt.getTime())) {
|
|
1961
|
+
continue;
|
|
1962
|
+
}
|
|
1963
|
+
if (orderCreatedAt < thresholdDate) {
|
|
1964
|
+
ordersToDelete.push({
|
|
1965
|
+
uuid: order.uuid,
|
|
1966
|
+
orderId: order.order_id,
|
|
1967
|
+
createdAt: orderCreatedAt.toISOString(),
|
|
1968
|
+
daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1e3 * 60 * 60 * 24))
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
} catch (error) {
|
|
1972
|
+
console.warn(`[Checkout] 处理订单 ${order.uuid} 时出错:`, error);
|
|
1973
|
+
continue;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
ordersToDelete.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1977
|
+
const actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete);
|
|
1978
|
+
for (const orderInfo of actualOrdersToDelete) {
|
|
1979
|
+
try {
|
|
1980
|
+
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
1981
|
+
deletedCount++;
|
|
1982
|
+
console.log(`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`);
|
|
1983
|
+
} catch (error) {
|
|
1984
|
+
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
const summary = {
|
|
1988
|
+
totalOrders: allOrders.length,
|
|
1989
|
+
expiredSyncedOrders: ordersToDelete.length,
|
|
1990
|
+
maxOrdersToDelete,
|
|
1991
|
+
actualDeletedOrders: deletedCount,
|
|
1992
|
+
retentionDays,
|
|
1993
|
+
cleanupDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1994
|
+
thresholdDate: thresholdDate.toISOString(),
|
|
1995
|
+
skippedOrders: Math.max(0, ordersToDelete.length - maxOrdersToDelete)
|
|
1996
|
+
};
|
|
1997
|
+
this.logInfo("Expired orders cleanup completed", summary);
|
|
1998
|
+
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
1999
|
+
console.log(`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`);
|
|
2000
|
+
} else {
|
|
2001
|
+
console.log(`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`);
|
|
2002
|
+
}
|
|
2003
|
+
} catch (error) {
|
|
2004
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2005
|
+
console.error("[Checkout] 清理过期订单数据失败:", error);
|
|
2006
|
+
this.logError("Expired orders cleanup failed", { error: errorMessage });
|
|
2007
|
+
}
|
|
1956
2008
|
}
|
|
1957
2009
|
/**
|
|
1958
2010
|
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
@@ -2071,7 +2123,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2071
2123
|
});
|
|
2072
2124
|
if (remainingAmount !== currentStateAmount) {
|
|
2073
2125
|
this.store.stateAmount = remainingAmount;
|
|
2074
|
-
|
|
2126
|
+
this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
2075
2127
|
oldAmount: currentStateAmount,
|
|
2076
2128
|
newAmount: remainingAmount,
|
|
2077
2129
|
timestamp: Date.now()
|
|
@@ -2165,46 +2217,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2165
2217
|
console.error("[Checkout] 检查订单支付完成状态失败:", error);
|
|
2166
2218
|
}
|
|
2167
2219
|
}
|
|
2168
|
-
/**
|
|
2169
|
-
* 判断支付方式是否需要同步订单到后端
|
|
2170
|
-
*
|
|
2171
|
-
* 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
|
|
2172
|
-
*
|
|
2173
|
-
* @param paymentCode 支付方式代码
|
|
2174
|
-
* @param paymentType 支付方式类型
|
|
2175
|
-
* @returns 是否需要同步订单
|
|
2176
|
-
*/
|
|
2177
|
-
shouldSyncOrderForPayment(paymentCode, paymentType) {
|
|
2178
|
-
const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
|
|
2179
|
-
const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
|
|
2180
|
-
const cashIdentifiers = ["CASHMANUAL", "CASH", "MANUAL"];
|
|
2181
|
-
if (cashIdentifiers.some(
|
|
2182
|
-
(id) => codeUpper.includes(id) || typeUpper.includes(id)
|
|
2183
|
-
)) {
|
|
2184
|
-
return false;
|
|
2185
|
-
}
|
|
2186
|
-
if (paymentCode === import_types2.PaymentMethodType.Cash || paymentType === import_types2.PaymentMethodType.Cash) {
|
|
2187
|
-
return false;
|
|
2188
|
-
}
|
|
2189
|
-
if (codeUpper.includes("CUSTOM") || typeUpper.includes("CUSTOM")) {
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
|
-
return true;
|
|
2193
|
-
}
|
|
2194
2220
|
/**
|
|
2195
2221
|
* 同步订单到后端
|
|
2196
2222
|
*
|
|
2197
2223
|
* 调用后端 /order/checkout 接口创建真实订单
|
|
2198
2224
|
*/
|
|
2199
|
-
/**
|
|
2200
|
-
* 判断订单ID是否为本地生成的虚拟ID
|
|
2201
|
-
*
|
|
2202
|
-
* @param orderId 订单ID
|
|
2203
|
-
* @returns true 表示是虚拟ID,false 表示是真实的后端ID
|
|
2204
|
-
*/
|
|
2205
|
-
isVirtualOrderId(orderId) {
|
|
2206
|
-
return orderId.startsWith("local_order_");
|
|
2207
|
-
}
|
|
2208
2225
|
/**
|
|
2209
2226
|
* 同步订单到后端并返回真实订单ID
|
|
2210
2227
|
*
|
|
@@ -2213,13 +2230,25 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2213
2230
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
2214
2231
|
*/
|
|
2215
2232
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2216
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2233
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2217
2234
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2218
2235
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2219
2236
|
}
|
|
2237
|
+
this.logInfo("syncOrderToBackendWithReturn called", {
|
|
2238
|
+
isManual,
|
|
2239
|
+
hasCustomPaymentItems: !!customPaymentItems,
|
|
2240
|
+
customPaymentItemsCount: (customPaymentItems == null ? void 0 : customPaymentItems.length) || 0,
|
|
2241
|
+
currentOrderId: this.store.currentOrder.order_id,
|
|
2242
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2243
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
2244
|
+
isVirtualOrderId: (0, import_utils.isVirtualOrderId)(this.store.currentOrder.order_id),
|
|
2245
|
+
localOrderDataType: this.store.localOrderData.type,
|
|
2246
|
+
platform: this.store.localOrderData.platform,
|
|
2247
|
+
customerId: (_a = this.store.currentCustomer) == null ? void 0 : _a.customer_id
|
|
2248
|
+
});
|
|
2220
2249
|
const syncType = isManual ? "手动" : "自动";
|
|
2221
2250
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
2222
|
-
const hasRealOrderId = currentOrderId && !
|
|
2251
|
+
const hasRealOrderId = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
2223
2252
|
let isUpdateOperation = false;
|
|
2224
2253
|
let reason = "";
|
|
2225
2254
|
if (this.store.isOrderSynced) {
|
|
@@ -2243,7 +2272,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2243
2272
|
});
|
|
2244
2273
|
console.log(`[Checkout] 开始${syncType}${operation}订单到后端...`, {
|
|
2245
2274
|
currentOrderId,
|
|
2246
|
-
isVirtualId:
|
|
2275
|
+
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2247
2276
|
operation,
|
|
2248
2277
|
orderUuid: this.store.currentOrder.uuid,
|
|
2249
2278
|
isOrderSynced: this.store.isOrderSynced
|
|
@@ -2281,7 +2310,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2281
2310
|
console.log("[Checkout] 处理后的支付项数据(包含完整metadata):", {
|
|
2282
2311
|
originalCount: paymentItems.length,
|
|
2283
2312
|
processedCount: processedPaymentItems.length,
|
|
2284
|
-
sampleMetadata: (
|
|
2313
|
+
sampleMetadata: (_b = processedPaymentItems[0]) == null ? void 0 : _b.metadata,
|
|
2285
2314
|
allPaymentItems: processedPaymentItems.map((p) => ({
|
|
2286
2315
|
code: p.code,
|
|
2287
2316
|
amount: p.amount,
|
|
@@ -2294,7 +2323,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2294
2323
|
platform: this.store.localOrderData.platform,
|
|
2295
2324
|
payments: processedPaymentItems,
|
|
2296
2325
|
// 使用处理过的支付项数据
|
|
2297
|
-
customer_id: (
|
|
2326
|
+
customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
|
|
2298
2327
|
// 添加客户ID
|
|
2299
2328
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2300
2329
|
// core 有
|
|
@@ -2307,8 +2336,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2307
2336
|
currency_code: this.otherParams.currency_code,
|
|
2308
2337
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2309
2338
|
currency_format: this.otherParams.currency_format,
|
|
2310
|
-
is_deposit: ((
|
|
2311
|
-
deposit_amount: ((
|
|
2339
|
+
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0,
|
|
2340
|
+
deposit_amount: ((_e = this.store.currentOrder) == null ? void 0 : _e.deposit_amount) || "0.00",
|
|
2312
2341
|
// surcharge_fee: this.otherParams.surcharge_fee,
|
|
2313
2342
|
// surcharges: ,
|
|
2314
2343
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
@@ -2316,7 +2345,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2316
2345
|
// deposit_amount:
|
|
2317
2346
|
};
|
|
2318
2347
|
if (isUpdateOperation) {
|
|
2319
|
-
if (
|
|
2348
|
+
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2320
2349
|
console.error(
|
|
2321
2350
|
"[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!",
|
|
2322
2351
|
{
|
|
@@ -2349,6 +2378,25 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2349
2378
|
let submitSuccess = false;
|
|
2350
2379
|
let submitError;
|
|
2351
2380
|
try {
|
|
2381
|
+
this.logInfo("Calling backend checkout API", {
|
|
2382
|
+
url: "/order/checkout",
|
|
2383
|
+
operation,
|
|
2384
|
+
isManual,
|
|
2385
|
+
orderType: orderParams.type,
|
|
2386
|
+
platform: orderParams.platform,
|
|
2387
|
+
customerId: orderParams.customer_id,
|
|
2388
|
+
isDeposit: orderParams.is_deposit,
|
|
2389
|
+
depositAmount: orderParams.deposit_amount,
|
|
2390
|
+
bookingsCount: ((_f = orderParams.bookings) == null ? void 0 : _f.length) || 0,
|
|
2391
|
+
relationProductsCount: ((_g = orderParams.relation_products) == null ? void 0 : _g.length) || 0,
|
|
2392
|
+
paymentsCount: ((_h = orderParams.payments) == null ? void 0 : _h.length) || 0,
|
|
2393
|
+
paymentMethods: ((_i = orderParams.payments) == null ? void 0 : _i.map((p) => p.code)) || [],
|
|
2394
|
+
hasOrderId: !!orderParams.order_id,
|
|
2395
|
+
orderIdIncluded: orderParams.order_id,
|
|
2396
|
+
productTaxFee: orderParams.product_tax_fee,
|
|
2397
|
+
note: orderParams.note,
|
|
2398
|
+
scheduleDate: orderParams.schedule_date
|
|
2399
|
+
});
|
|
2352
2400
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2353
2401
|
submitSuccess = true;
|
|
2354
2402
|
console.log("[Checkout] 下单接口调用成功");
|
|
@@ -2371,7 +2419,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2371
2419
|
orderUuid: this.store.currentOrder.uuid,
|
|
2372
2420
|
operation: isUpdateOperation ? "update" : "create",
|
|
2373
2421
|
isManual,
|
|
2374
|
-
orderId: submitSuccess ? ((
|
|
2422
|
+
orderId: submitSuccess ? ((_j = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _j.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2375
2423
|
error: submitError,
|
|
2376
2424
|
duration: Date.now() - startTime,
|
|
2377
2425
|
timestamp: Date.now()
|
|
@@ -2412,7 +2460,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2412
2460
|
realOrderId = currentOrderId;
|
|
2413
2461
|
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
2414
2462
|
} else {
|
|
2415
|
-
let extractedOrderId = (
|
|
2463
|
+
let extractedOrderId = (_k = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _k.order_id;
|
|
2416
2464
|
if (!extractedOrderId) {
|
|
2417
2465
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2418
2466
|
}
|
|
@@ -2478,7 +2526,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2478
2526
|
response: checkoutResponse
|
|
2479
2527
|
});
|
|
2480
2528
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
2481
|
-
const finalIsVirtual =
|
|
2529
|
+
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId || "");
|
|
2482
2530
|
console.log(`[Checkout] ${syncType}${operation}订单到后端完成`, {
|
|
2483
2531
|
返回的订单ID: realOrderId,
|
|
2484
2532
|
当前存储的订单ID: finalOrderId,
|
|
@@ -2557,6 +2605,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2557
2605
|
* @returns 修改结果
|
|
2558
2606
|
*/
|
|
2559
2607
|
async editOrderNoteByOrderIdAsync(orderId, note) {
|
|
2608
|
+
this.logInfo("editOrderNoteByOrderIdAsync called", {
|
|
2609
|
+
orderId,
|
|
2610
|
+
note,
|
|
2611
|
+
noteLength: note.length,
|
|
2612
|
+
isCurrentOrder: this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))
|
|
2613
|
+
});
|
|
2560
2614
|
try {
|
|
2561
2615
|
console.log("[Checkout] 开始编辑订单备注:", {
|
|
2562
2616
|
orderId,
|
|
@@ -2570,6 +2624,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2570
2624
|
orderId
|
|
2571
2625
|
};
|
|
2572
2626
|
}
|
|
2627
|
+
this.logInfo("Calling order note edit API", {
|
|
2628
|
+
url: `/order/order/${orderId}/note`,
|
|
2629
|
+
method: "PUT",
|
|
2630
|
+
orderId,
|
|
2631
|
+
note,
|
|
2632
|
+
noteLength: note.length
|
|
2633
|
+
});
|
|
2573
2634
|
const response = await this.request.put(
|
|
2574
2635
|
`/order/order/${orderId}/note`,
|
|
2575
2636
|
{
|
|
@@ -2630,6 +2691,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2630
2691
|
* @returns 发送结果
|
|
2631
2692
|
*/
|
|
2632
2693
|
async sendCustomerPayLinkAsync(params) {
|
|
2694
|
+
var _a, _b;
|
|
2695
|
+
this.logInfo("sendCustomerPayLinkAsync called", {
|
|
2696
|
+
orderIds: params.order_ids,
|
|
2697
|
+
orderIdsCount: ((_a = params.order_ids) == null ? void 0 : _a.length) || 0,
|
|
2698
|
+
emails: params.emails,
|
|
2699
|
+
emailsCount: ((_b = params.emails) == null ? void 0 : _b.length) || 0,
|
|
2700
|
+
notifyAction: params.notify_action || "order_payment_reminder"
|
|
2701
|
+
});
|
|
2633
2702
|
try {
|
|
2634
2703
|
console.log("[Checkout] 开始发送客户支付链接邮件:", {
|
|
2635
2704
|
orderIds: params.order_ids,
|
|
@@ -2664,6 +2733,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2664
2733
|
emails: params.emails
|
|
2665
2734
|
};
|
|
2666
2735
|
console.log("[Checkout] 发送支付链接邮件请求参数:", requestBody);
|
|
2736
|
+
this.logInfo("Calling batch email API", {
|
|
2737
|
+
url: "/order/batch-email",
|
|
2738
|
+
orderIds: requestBody.order_ids,
|
|
2739
|
+
orderIdsCount: requestBody.order_ids.length,
|
|
2740
|
+
notifyAction: requestBody.notify_action,
|
|
2741
|
+
emails: requestBody.emails,
|
|
2742
|
+
emailsCount: requestBody.emails.length
|
|
2743
|
+
});
|
|
2667
2744
|
const response = await this.request.post(
|
|
2668
2745
|
"/order/batch-email",
|
|
2669
2746
|
requestBody
|
|
@@ -2746,8 +2823,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2746
2823
|
this.store.lastError = void 0;
|
|
2747
2824
|
this.store.cartItems = [];
|
|
2748
2825
|
this.payment.wallet.clearAllCache();
|
|
2749
|
-
|
|
2750
|
-
|
|
2826
|
+
this.setStatus(import_types.CheckoutStatus.Ready);
|
|
2827
|
+
this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
2751
2828
|
console.log("[Checkout] Store 状态重置完成");
|
|
2752
2829
|
if (prevOrderInfo) {
|
|
2753
2830
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
|