@pisell/pisellos 0.0.373 → 0.0.376

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 (92) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/model/strategy/adapter/walletPass/utils.js +7 -2
  3. package/dist/model/strategy/type.d.ts +1 -1
  4. package/dist/modules/Customer/types.d.ts +1 -1
  5. package/dist/modules/Payment/index.js +35 -7
  6. package/dist/modules/Payment/types.d.ts +9 -7
  7. package/dist/modules/Product/index.d.ts +1 -1
  8. package/dist/modules/Rules/types.d.ts +1 -1
  9. package/dist/modules/Schedule/type.d.ts +7 -7
  10. package/dist/modules/Schedule/types.d.ts +9 -9
  11. package/dist/solution/BookingByStep/index.d.ts +2 -2
  12. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  13. package/dist/solution/Checkout/index.js +31 -2
  14. package/dist/solution/Checkout/types.d.ts +2 -0
  15. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  16. package/dist/solution/ShopDiscount/utils.d.ts +2 -2
  17. package/dist/types/index.d.ts +1 -1
  18. package/dist/utils/task.d.ts +2 -2
  19. package/dist/utils/watch.d.ts +2 -2
  20. package/lib/core/index.js +28 -27
  21. package/lib/effects/index.d.ts +2 -2
  22. package/lib/effects/index.js +7 -3
  23. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -3
  24. package/lib/model/strategy/adapter/walletPass/example.js +21 -21
  25. package/lib/model/strategy/adapter/walletPass/index.js +4 -2
  26. package/lib/model/strategy/adapter/walletPass/locales.js +10 -10
  27. package/lib/model/strategy/adapter/walletPass/utils.js +9 -4
  28. package/lib/model/strategy/index.js +10 -7
  29. package/lib/model/strategy/strategy-example.js +19 -19
  30. package/lib/model/strategy/type.d.ts +1 -1
  31. package/lib/modules/Account/index.js +10 -9
  32. package/lib/modules/AccountList/index.js +11 -14
  33. package/lib/modules/BaseModule.js +3 -6
  34. package/lib/modules/Cart/index.js +9 -14
  35. package/lib/modules/Cart/utils/cartProduct.js +6 -3
  36. package/lib/modules/Customer/constants.js +1 -1
  37. package/lib/modules/Customer/index.js +15 -18
  38. package/lib/modules/Customer/types.d.ts +1 -1
  39. package/lib/modules/Date/index.js +6 -10
  40. package/lib/modules/Date/types.js +0 -1
  41. package/lib/modules/Discount/index.js +6 -11
  42. package/lib/modules/Guests/index.js +15 -10
  43. package/lib/modules/Order/index.js +9 -11
  44. package/lib/modules/Payment/cash.js +1 -1
  45. package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
  46. package/lib/modules/Payment/eftpos.js +1 -1
  47. package/lib/modules/Payment/index.js +94 -86
  48. package/lib/modules/Payment/types.d.ts +9 -7
  49. package/lib/modules/Payment/utils.js +6 -3
  50. package/lib/modules/Payment/walletpass.js +33 -33
  51. package/lib/modules/Product/index.d.ts +1 -1
  52. package/lib/modules/Product/index.js +5 -6
  53. package/lib/modules/ProductList/index.js +3 -5
  54. package/lib/modules/Resource/index.js +12 -8
  55. package/lib/modules/Rules/index.js +21 -16
  56. package/lib/modules/Rules/types.d.ts +1 -1
  57. package/lib/modules/Schedule/index.js +5 -8
  58. package/lib/modules/Schedule/type.d.ts +7 -7
  59. package/lib/modules/Schedule/types.d.ts +9 -9
  60. package/lib/modules/Schedule/utils.js +4 -2
  61. package/lib/modules/Step/index.js +4 -7
  62. package/lib/modules/Summary/index.js +4 -9
  63. package/lib/plugins/request.js +33 -34
  64. package/lib/plugins/window.js +113 -101
  65. package/lib/solution/BookingByStep/index.d.ts +2 -2
  66. package/lib/solution/BookingByStep/index.js +129 -86
  67. package/lib/solution/BookingByStep/utils/capacity.js +15 -10
  68. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  69. package/lib/solution/BookingByStep/utils/resources.js +8 -4
  70. package/lib/solution/BookingByStep/utils/stock.js +6 -3
  71. package/lib/solution/BookingByStep/utils/timeslots.js +27 -24
  72. package/lib/solution/BookingTicket/index.js +14 -19
  73. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
  74. package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
  75. package/lib/solution/BookingTicket/utils/scan/index.js +1 -3
  76. package/lib/solution/BookingTicket/utils/scan/scanCache.js +9 -10
  77. package/lib/solution/BuyTickets/index.js +15 -15
  78. package/lib/solution/Checkout/index.js +233 -217
  79. package/lib/solution/Checkout/types.d.ts +2 -0
  80. package/lib/solution/Checkout/utils/index.js +22 -18
  81. package/lib/solution/RegisterAndLogin/config.js +2 -2
  82. package/lib/solution/RegisterAndLogin/index.js +110 -114
  83. package/lib/solution/RegisterAndLogin/utils.js +9 -9
  84. package/lib/solution/ShopDiscount/index.js +13 -16
  85. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  86. package/lib/solution/ShopDiscount/utils.d.ts +2 -2
  87. package/lib/types/index.d.ts +1 -1
  88. package/lib/utils/task.d.ts +2 -2
  89. package/lib/utils/task.js +3 -3
  90. package/lib/utils/watch.d.ts +2 -2
  91. package/lib/utils/watch.js +7 -5
  92. package/package.json +18 -17
@@ -37,7 +37,7 @@ function formatAmount(amount) {
37
37
  const decimal = new import_decimal.Decimal(amount);
38
38
  return decimal.toFixed(2);
39
39
  } catch (error) {
40
- console.warn(`[PaymentModule] \u91D1\u989D\u683C\u5F0F\u5316\u5931\u8D25: ${amount}\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C 0.00`);
40
+ console.warn(`[PaymentModule] 金额格式化失败: ${amount},使用默认值 0.00`);
41
41
  return "0.00";
42
42
  }
43
43
  }
@@ -54,25 +54,12 @@ function generateRequestUniqueId() {
54
54
  return `${year}${month}${day}${hour}${minute}${second}${millisecond}${randomDigits}`;
55
55
  }
56
56
  var PaymentModule = class extends import_BaseModule.BaseModule {
57
- defaultName = "pay";
58
- defaultVersion = "1.0.0";
59
- request;
60
- app;
61
- // App instance
62
- store;
63
- window;
64
- // WindowPlugin 实例
65
- dbManager;
66
- // IndexDBManager 实例
67
- logger;
68
- // LoggerManager 实例
69
- otherParams = {};
70
- // 支付方式实例
71
- cash;
72
- eftpos;
73
- wallet;
74
57
  constructor(name, version) {
75
58
  super(name || "payment", version);
59
+ this.defaultName = "pay";
60
+ this.defaultVersion = "1.0.0";
61
+ // LoggerManager 实例
62
+ this.otherParams = {};
76
63
  this.cash = new import_cash.CashPaymentImpl(this);
77
64
  this.eftpos = new import_eftpos.EftposPaymentImpl(this);
78
65
  this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
@@ -85,17 +72,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
85
72
  const appPlugin = core.getPlugin("app");
86
73
  this.window = core.getPlugin("window");
87
74
  if (!this.request) {
88
- throw new Error("\u652F\u4ED8\u6A21\u5757\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
75
+ throw new Error("支付模块需要 request 插件支持");
89
76
  }
90
77
  if (!appPlugin) {
91
- throw new Error("\u652F\u4ED8\u6A21\u5757\u9700\u8981 app \u63D2\u4EF6\u652F\u6301");
78
+ throw new Error("支付模块需要 app 插件支持");
92
79
  }
93
80
  this.app = appPlugin.getApp();
94
81
  this.dbManager = this.app.dbManager;
95
82
  this.logger = this.app.logger;
96
83
  await this.ensurePaymentTables();
97
84
  this.registerNetworkHandlers();
98
- console.log("[PaymentModule] \u521D\u59CB\u5316\u5B8C\u6210");
85
+ console.log("[PaymentModule] 初始化完成");
99
86
  this.logInfo("PaymentModule initialized successfully");
100
87
  }
101
88
  /**
@@ -170,7 +157,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
170
157
  const network = this.app.plugins.get("network");
171
158
  this.logInfo("Registering network status listener");
172
159
  network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
173
- console.log("\u7F51\u7EDC\u72B6\u6001:", status.connected);
160
+ console.log("网络状态:", status.connected);
174
161
  this.logInfo("Network status changed", {
175
162
  connected: status.connected,
176
163
  previousStatus: status.previousStatus
@@ -190,7 +177,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
190
177
  try {
191
178
  cachedMethods = await this.dbManager.getAll("pay_method");
192
179
  } catch (dbError) {
193
- console.warn("[PaymentModule] pay_method \u8868\u4E0D\u5B58\u5728\uFF0C\u5C06\u4ECE\u670D\u52A1\u5668\u83B7\u53D6\u6570\u636E");
180
+ console.warn("[PaymentModule] pay_method 表不存在,将从服务器获取数据");
194
181
  }
195
182
  const hasCache = cachedMethods.length > 0;
196
183
  if (hasCache) {
@@ -204,7 +191,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
204
191
  await this.dbManager.update("pay_method", method);
205
192
  }
206
193
  } catch (dbError) {
207
- console.warn("[PaymentModule] \u65E0\u6CD5\u7F13\u5B58\u652F\u4ED8\u65B9\u5F0F\uFF0Cpay_method \u8868\u4E0D\u5B58\u5728");
194
+ console.warn("[PaymentModule] 无法缓存支付方式,pay_method 表不存在");
208
195
  }
209
196
  await this.core.effects.emit(
210
197
  `${this.name}:onPaymentMethodsLoaded`,
@@ -216,7 +203,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
216
203
  });
217
204
  return payMethods;
218
205
  } catch (error) {
219
- console.error("[PaymentModule] \u83B7\u53D6\u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u5931\u8D25", error);
206
+ console.error("[PaymentModule] 获取支付方式列表失败", error);
220
207
  this.logError("getPayMethodListAsync failed", error);
221
208
  return [];
222
209
  }
@@ -229,7 +216,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
229
216
  cachedMethodsCount: cachedMethods.length
230
217
  });
231
218
  try {
232
- console.log("[PaymentModule] \u540E\u53F0\u5237\u65B0\u652F\u4ED8\u65B9\u5F0F\u5217\u8868...");
219
+ console.log("[PaymentModule] 后台刷新支付方式列表...");
233
220
  const response = await this.request.get("/pay/custom-payment/available", { channel: "pos" });
234
221
  const newPayMethods = response.data || [];
235
222
  const hasChanges = this.hasPaymentMethodsChanged(
@@ -237,7 +224,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
237
224
  newPayMethods
238
225
  );
239
226
  if (hasChanges) {
240
- console.log("[PaymentModule] \u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u5DF2\u66F4\u65B0");
227
+ console.log("[PaymentModule] 支付方式列表已更新");
241
228
  this.logInfo("Payment methods updated in background", {
242
229
  oldCount: cachedMethods.length,
243
230
  newCount: newPayMethods.length
@@ -250,7 +237,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
250
237
  await this.dbManager.update("pay_method", method);
251
238
  }
252
239
  } catch (dbError) {
253
- console.warn("[PaymentModule] \u65E0\u6CD5\u66F4\u65B0\u652F\u4ED8\u65B9\u5F0F\u7F13\u5B58", dbError);
240
+ console.warn("[PaymentModule] 无法更新支付方式缓存", dbError);
254
241
  }
255
242
  const eventData = {
256
243
  oldMethods: cachedMethods,
@@ -261,10 +248,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
261
248
  eventData
262
249
  );
263
250
  } else {
264
- console.log("[PaymentModule] \u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u65E0\u53D8\u5316");
251
+ console.log("[PaymentModule] 支付方式列表无变化");
265
252
  }
266
253
  } catch (error) {
267
- console.error("[PaymentModule] \u540E\u53F0\u5237\u65B0\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
254
+ console.error("[PaymentModule] 后台刷新支付方式失败", error);
268
255
  }
269
256
  }
270
257
  /**
@@ -283,7 +270,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
283
270
  return true;
284
271
  }
285
272
  if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.description !== newMethod.description || oldMethod.status !== newMethod.status || oldMethod.disable !== newMethod.disable || oldMethod.is_surcharge !== newMethod.is_surcharge || oldMethod.fixed !== newMethod.fixed || oldMethod.percentage !== newMethod.percentage || oldMethod.enabled !== newMethod.enabled || JSON.stringify(oldMethod.channel_application || []) !== JSON.stringify(newMethod.channel_application || []) || JSON.stringify(oldMethod.companies || []) !== JSON.stringify(newMethod.companies || []) || JSON.stringify(oldMethod.metadata || {}) !== JSON.stringify(newMethod.metadata || {})) {
286
- console.log(`[PaymentModule] \u652F\u4ED8\u65B9\u5F0F ${newMethod.id} (${newMethod.code}) \u53D1\u751F\u53D8\u5316:`, {
273
+ console.log(`[PaymentModule] 支付方式 ${newMethod.id} (${newMethod.code}) 发生变化:`, {
287
274
  id: newMethod.id,
288
275
  changes: {
289
276
  code: oldMethod.code !== newMethod.code ? { old: oldMethod.code, new: newMethod.code } : void 0,
@@ -313,7 +300,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
313
300
  try {
314
301
  return await this.dbManager.getAll("order");
315
302
  } catch (error) {
316
- console.error("[PaymentModule] \u83B7\u53D6\u8BA2\u5355\u5217\u8868\u5931\u8D25", error);
303
+ console.error("[PaymentModule] 获取订单列表失败", error);
317
304
  return [];
318
305
  }
319
306
  }
@@ -324,7 +311,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
324
311
  try {
325
312
  return await this.dbManager.get("order", orderUuid, true);
326
313
  } catch (error) {
327
- console.error("[PaymentModule] \u83B7\u53D6\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
314
+ console.error("[PaymentModule] 获取支付订单失败", error);
328
315
  return null;
329
316
  }
330
317
  }
@@ -351,6 +338,27 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
351
338
  is_deposit: params.is_deposit || 0,
352
339
  deposit_amount: params.deposit_amount || "0.00"
353
340
  };
341
+ if (params.existPayment && params.existPayment.length > 0) {
342
+ newOrder.payment = params.existPayment.map((payment) => ({
343
+ ...payment,
344
+ isSynced: true,
345
+ // 标记为已同步
346
+ status: payment.status || "active"
347
+ }));
348
+ this.recalculateOrderAmount(newOrder);
349
+ this.logInfo("创建订单时包含云端支付项", {
350
+ orderId: params.order_id,
351
+ existPaymentCount: params.existPayment.length,
352
+ totalAmount: newOrder.total_amount,
353
+ expectAmount: newOrder.expect_amount,
354
+ paymentDetails: params.existPayment.map((p) => ({
355
+ uuid: p.uuid,
356
+ code: p.code,
357
+ amount: p.amount,
358
+ status: p.status
359
+ }))
360
+ });
361
+ }
354
362
  const dbAddStartTime = Date.now();
355
363
  await this.dbManager.add("order", newOrder, true);
356
364
  const dbAddDuration = Date.now() - dbAddStartTime;
@@ -367,7 +375,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
367
375
  }, 0);
368
376
  return newOrder;
369
377
  } catch (error) {
370
- console.error("[PaymentModule] \u521B\u5EFA\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
378
+ console.error("[PaymentModule] 创建支付订单失败", error);
371
379
  this.logError("createPaymentOrderAsync failed", error, {
372
380
  orderId: params.order_id
373
381
  });
@@ -383,10 +391,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
383
391
  if (order) {
384
392
  await this.dbManager.delete("order", orderUuid);
385
393
  await this.core.effects.emit(`${this.name}:onOrderDeleted`, order);
386
- console.log("[PaymentModule] \u652F\u4ED8\u8BA2\u5355\u5220\u9664\u6210\u529F:", orderUuid);
394
+ console.log("[PaymentModule] 支付订单删除成功:", orderUuid);
387
395
  }
388
396
  } catch (error) {
389
- console.error("[PaymentModule] \u5220\u9664\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
397
+ console.error("[PaymentModule] 删除支付订单失败", error);
390
398
  throw error;
391
399
  }
392
400
  }
@@ -408,7 +416,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
408
416
  });
409
417
  }
410
418
  } catch (error) {
411
- console.error("[PaymentModule] \u66F4\u65B0\u8BA2\u5355\u5931\u8D25", error);
419
+ console.error("[PaymentModule] 更新订单失败", error);
412
420
  throw error;
413
421
  }
414
422
  }
@@ -442,7 +450,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
442
450
  newOrderId,
443
451
  existingOrderUuid: duplicateOrder.uuid
444
452
  });
445
- throw new Error(`\u8BA2\u5355ID ${newOrderId} \u5DF2\u5B58\u5728`);
453
+ throw new Error(`订单ID ${newOrderId} 已存在`);
446
454
  }
447
455
  const originalOrderId = existingOrder.id;
448
456
  const updatedOrder = {
@@ -474,10 +482,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
474
482
  originalOrderId,
475
483
  newOrderId
476
484
  });
477
- console.log(`[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ${originalOrderId} \u2192 ${newOrderId}`);
485
+ console.log(`[PaymentModule] 订单ID替换成功: ${originalOrderId} ${newOrderId}`);
478
486
  return updatedOrder;
479
487
  } catch (error) {
480
- console.error("[PaymentModule] \u66FF\u6362\u8BA2\u5355ID\u5931\u8D25", error);
488
+ console.error("[PaymentModule] 替换订单ID失败", error);
481
489
  this.logError("replaceOrderIdByUuidAsync failed", error, {
482
490
  orderUuid,
483
491
  newOrderId
@@ -524,11 +532,11 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
524
532
  orderPaymentType: paymentItem.order_payment_type
525
533
  });
526
534
  try {
527
- this.logInfo("\u51C6\u5907\u83B7\u53D6\u8BA2\u5355", {
535
+ this.logInfo("准备获取订单", {
528
536
  orderUuid
529
537
  });
530
538
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
531
- this.logInfo("\u83B7\u53D6\u8BA2\u5355\u4FE1\u606F\u6210\u529F", {
539
+ this.logInfo("获取订单信息成功", {
532
540
  orderUuid,
533
541
  order
534
542
  });
@@ -544,7 +552,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
544
552
  }, new import_decimal.Decimal(0));
545
553
  const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
546
554
  if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
547
- const warningMessage = `\u8BA2\u5355 ${orderUuid} \u5F85\u4ED8\u91D1\u989D\u5DF2\u4E3A0\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u65B0\u7684\u652F\u4ED8\u9879`;
555
+ const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
548
556
  console.warn("[PaymentModule] Payment lock triggered:", {
549
557
  orderUuid,
550
558
  expectAmount: order.expect_amount,
@@ -588,12 +596,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
588
596
  };
589
597
  order.payment.push(newPaymentItem);
590
598
  this.recalculateOrderAmount(order);
591
- this.logInfo("\u5F00\u59CB\u66F4\u65B0\u8BA2\u5355\u652F\u4ED8\u9879", {
599
+ this.logInfo("开始更新订单支付项", {
592
600
  orderUuid,
593
601
  order
594
602
  });
595
603
  await this.dbManager.update("order", order, true);
596
- this.logInfo("\u66F4\u65B0\u8BA2\u5355\u652F\u4ED8\u9879\u5B8C\u6210", {
604
+ this.logInfo("更新订单支付项完成", {
597
605
  orderUuid
598
606
  });
599
607
  this.core.effects.emit(`${this.name}:onPaymentAdded`, {
@@ -614,7 +622,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
614
622
  changeGivenAmount: (_d = newPaymentItem.metadata) == null ? void 0 : _d.change_given_amount
615
623
  });
616
624
  } catch (error) {
617
- console.error("[PaymentModule] \u6DFB\u52A0\u652F\u4ED8\u9879\u5931\u8D25", error);
625
+ console.error("[PaymentModule] 添加支付项失败", error);
618
626
  this.logError("addPaymentItemAsync failed", error, {
619
627
  orderUuid,
620
628
  paymentItem
@@ -630,22 +638,22 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
630
638
  try {
631
639
  const order = await this.dbManager.get("order", orderUuid);
632
640
  if (!order) {
633
- throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
641
+ throw new Error("订单不存在");
634
642
  }
635
643
  const paymentItem = order.payment.find(
636
644
  (payment) => payment.uuid === paymentUuid
637
645
  );
638
646
  if (!paymentItem) {
639
- throw new Error(`\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ${paymentUuid}`);
647
+ throw new Error(`支付项不存在: ${paymentUuid}`);
640
648
  }
641
649
  if (paymentItem.status === "voided") {
642
- console.warn(`[PaymentModule] \u652F\u4ED8\u9879 ${paymentUuid} \u5DF2\u7ECF\u88AB\u5220\u9664\uFF0C\u8DF3\u8FC7\u64CD\u4F5C`);
650
+ console.warn(`[PaymentModule] 支付项 ${paymentUuid} 已经被删除,跳过操作`);
643
651
  return;
644
652
  }
645
653
  paymentItem.status = "voided";
646
654
  paymentItem.origin_amount = paymentItem.amount;
647
655
  paymentItem.amount = "0.00";
648
- console.log(`[PaymentModule] \u652F\u4ED8\u9879\u6807\u8BB0\u4E3A\u5220\u9664:`, {
656
+ console.log(`[PaymentModule] 支付项标记为删除:`, {
649
657
  uuid: paymentItem.uuid,
650
658
  originalAmount: paymentItem.origin_amount,
651
659
  status: paymentItem.status
@@ -668,7 +676,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
668
676
  newExpectAmount: order.expect_amount
669
677
  });
670
678
  } catch (error) {
671
- console.error("[PaymentModule] \u5220\u9664\u652F\u4ED8\u9879\u5931\u8D25", error);
679
+ console.error("[PaymentModule] 删除支付项失败", error);
672
680
  this.logError("deletePaymentAsync failed", error, {
673
681
  orderUuid,
674
682
  paymentUuid
@@ -696,12 +704,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
696
704
  try {
697
705
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
698
706
  if (!order) {
699
- throw new Error(`\u8BA2\u5355\u4E0D\u5B58\u5728: ${orderUuid}`);
707
+ throw new Error(`订单不存在: ${orderUuid}`);
700
708
  }
701
709
  const existingVoucherItems = order.payment.filter(
702
710
  (payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
703
711
  );
704
- console.log("[PaymentModule] \u53D1\u73B0\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
712
+ console.log("[PaymentModule] 发现现有代金券支付项:", {
705
713
  orderUuid,
706
714
  existingVoucherCount: existingVoucherItems.length,
707
715
  existingItems: existingVoucherItems.map((item) => ({
@@ -713,18 +721,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
713
721
  }))
714
722
  });
715
723
  for (const voucherItem of existingVoucherItems) {
716
- console.log(`[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ${voucherItem.uuid}`);
724
+ console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
717
725
  await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
718
726
  }
719
- console.log("[PaymentModule] \u6DFB\u52A0\u65B0\u7684\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
727
+ console.log("[PaymentModule] 添加新的代金券支付项:", {
720
728
  orderUuid,
721
729
  newItemCount: voucherPaymentItems.length
722
730
  });
723
731
  for (const voucherItem of voucherPaymentItems) {
724
732
  if (!voucherItem.voucher_id) {
725
- throw new Error(`\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ${JSON.stringify(voucherItem)}`);
733
+ throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(voucherItem)}`);
726
734
  }
727
- console.log(`[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:`, {
735
+ console.log(`[PaymentModule] 添加代金券支付项:`, {
728
736
  code: voucherItem.code,
729
737
  amount: voucherItem.amount,
730
738
  voucher_id: voucherItem.voucher_id,
@@ -746,7 +754,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
746
754
  finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
747
755
  });
748
756
  } catch (error) {
749
- console.error("[PaymentModule] \u6279\u91CF\u66F4\u65B0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u5931\u8D25:", error);
757
+ console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
750
758
  this.logError("updateVoucherPaymentItemsAsync failed", error, {
751
759
  orderUuid,
752
760
  voucherPaymentItems
@@ -761,7 +769,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
761
769
  try {
762
770
  const order = await this.dbManager.get("order", orderUuid);
763
771
  if (!order) {
764
- throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
772
+ throw new Error("订单不存在");
765
773
  }
766
774
  const paymentItem = order.payment.find(
767
775
  (payment) => payment.uuid === paymentUuid
@@ -785,7 +793,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
785
793
  });
786
794
  }
787
795
  } catch (error) {
788
- console.error("[PaymentModule] \u66F4\u65B0\u652F\u4ED8\u9879\u5931\u8D25", error);
796
+ console.error("[PaymentModule] 更新支付项失败", error);
789
797
  throw error;
790
798
  }
791
799
  }
@@ -815,7 +823,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
815
823
  });
816
824
  return result;
817
825
  } catch (error) {
818
- console.error("[PaymentModule] \u63D0\u4EA4\u652F\u4ED8\u5931\u8D25", error);
826
+ console.error("[PaymentModule] 提交支付失败", error);
819
827
  this.logError("submitPayAsync failed", error, { orderUuid });
820
828
  return { status: "failed" };
821
829
  }
@@ -848,18 +856,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
848
856
  if (totalPaidAmount.gte(orderTotalAmount)) {
849
857
  order.payment_status = import_types.PaymentStatus.Finished;
850
858
  console.log(
851
- `[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u5B8C\u6210\uFF0C\u91D1\u989D: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
859
+ `[PaymentModule] 订单 ${order.uuid} 支付完成,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
852
860
  );
853
861
  } else {
854
862
  order.payment_status = import_types.PaymentStatus.PartiallyPaid;
855
863
  console.log(
856
- `[PaymentModule] \u8BA2\u5355 ${order.uuid} \u90E8\u5206\u652F\u4ED8\uFF0C\u91D1\u989D: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
864
+ `[PaymentModule] 订单 ${order.uuid} 部分支付,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
857
865
  );
858
866
  }
859
867
  paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
860
868
  await this.dbManager.update("order", order);
861
869
  if (paymentData.payments.length === 0) {
862
- console.log(`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u652F\u4ED8\u5904\u7406`);
870
+ console.log(`[PaymentModule] 订单 ${order.uuid} 支付列表为空,跳过支付处理`);
863
871
  this.logWarning("Empty payment list", {
864
872
  orderUuid: order.uuid,
865
873
  orderId: order.order_id
@@ -872,7 +880,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
872
880
  order
873
881
  });
874
882
  } catch (error) {
875
- console.error(`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25`, error);
883
+ console.error(`[PaymentModule] 订单 ${order.uuid} 支付提交失败`, error);
876
884
  throw error;
877
885
  }
878
886
  }
@@ -882,7 +890,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
882
890
  async getRemainingOrderAmountAsync(orderUuid) {
883
891
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
884
892
  if (!order) {
885
- throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
893
+ throw new Error("订单不存在");
886
894
  }
887
895
  return new import_decimal.Decimal(order.expect_amount).toNumber();
888
896
  }
@@ -892,7 +900,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
892
900
  async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
893
901
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
894
902
  if (!order) {
895
- throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
903
+ throw new Error("订单不存在");
896
904
  }
897
905
  if (inputAmount === null || inputAmount === void 0) {
898
906
  return new import_decimal.Decimal(order.expect_amount).toNumber();
@@ -905,7 +913,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
905
913
  if (typeof inputAmount === "number") {
906
914
  if (isNaN(inputAmount) || !isFinite(inputAmount)) {
907
915
  console.warn(
908
- `[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ${inputAmount}\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D`
916
+ `[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`
909
917
  );
910
918
  return new import_decimal.Decimal(order.expect_amount).toNumber();
911
919
  }
@@ -915,7 +923,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
915
923
  return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
916
924
  } catch (error) {
917
925
  console.warn(
918
- `[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ${inputAmount}\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D`
926
+ `[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`
919
927
  );
920
928
  return new import_decimal.Decimal(order.expect_amount).toNumber();
921
929
  }
@@ -936,7 +944,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
936
944
  const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
937
945
  return sum.plus(effectiveAmount);
938
946
  } catch (error) {
939
- console.warn(`[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=${payment.amount}, rounding_amount=${payment.rounding_amount}\uFF0C\u8DF3\u8FC7\u8BA1\u7B97`);
947
+ console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
940
948
  return sum;
941
949
  }
942
950
  },
@@ -944,7 +952,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
944
952
  );
945
953
  const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
946
954
  order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
947
- console.log(`[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:`, {
955
+ console.log(`[PaymentModule] 重新计算订单金额:`, {
948
956
  orderUuid: order.uuid,
949
957
  totalAmount: order.total_amount,
950
958
  effectivePaidAmount: paidAmount.toFixed(2),
@@ -957,7 +965,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
957
965
  rounding_amount: p.rounding_amount || "0.00",
958
966
  effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
959
967
  })),
960
- \u8BF4\u660E: "\u6709\u6548\u652F\u4ED8\u91D1\u989D\u5305\u542B\u62B9\u96F6\u8BA1\u7B97\uFF08amount + |rounding_amount|\uFF09"
968
+ 说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
961
969
  });
962
970
  }
963
971
  /**
@@ -970,7 +978,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
970
978
  (method) => method.code === import_types.PaymentMethodType.Cash
971
979
  ) || null;
972
980
  } catch (error) {
973
- console.error("[PaymentModule] \u83B7\u53D6\u73B0\u91D1\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
981
+ console.error("[PaymentModule] 获取现金支付方式失败", error);
974
982
  return null;
975
983
  }
976
984
  }
@@ -984,7 +992,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
984
992
  (method) => method.code === import_types.PaymentMethodType.Eftpos
985
993
  ) || null;
986
994
  } catch (error) {
987
- console.error("[PaymentModule] \u83B7\u53D6Eftpos\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
995
+ console.error("[PaymentModule] 获取Eftpos支付方式失败", error);
988
996
  return null;
989
997
  }
990
998
  }
@@ -998,7 +1006,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
998
1006
  (method) => method.code === import_types.PaymentMethodType.Wallet
999
1007
  ) || null;
1000
1008
  } catch (error) {
1001
- console.error("[PaymentModule] \u83B7\u53D6\u94B1\u5305\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
1009
+ console.error("[PaymentModule] 获取钱包支付方式失败", error);
1002
1010
  return null;
1003
1011
  }
1004
1012
  }
@@ -1010,7 +1018,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1010
1018
  await this.dbManager.getAll("pay_method");
1011
1019
  } catch (error) {
1012
1020
  console.warn(
1013
- "[PaymentModule] pay_method \u8868\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u6570\u636E\u5E93\u914D\u7F6E\u4E2D\u6DFB\u52A0\u4EE5\u4E0B\u914D\u7F6E\uFF1A"
1021
+ "[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:"
1014
1022
  );
1015
1023
  console.warn('{ name: "pay_method", keyPath: "id" }');
1016
1024
  }
@@ -1018,7 +1026,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1018
1026
  await this.dbManager.getAll("order");
1019
1027
  } catch (error) {
1020
1028
  console.warn(
1021
- "[PaymentModule] order \u8868\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u6570\u636E\u5E93\u914D\u7F6E\u4E2D\u6DFB\u52A0\u4EE5\u4E0B\u914D\u7F6E\uFF1A"
1029
+ "[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:"
1022
1030
  );
1023
1031
  console.warn('{ name: "order", keyPath: "uuid" }');
1024
1032
  }
@@ -1033,7 +1041,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1033
1041
  (order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
1034
1042
  );
1035
1043
  } catch (error) {
1036
- console.error("[PaymentModule] \u83B7\u53D6\u90E8\u5206\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
1044
+ console.error("[PaymentModule] 获取部分支付订单失败", error);
1037
1045
  return [];
1038
1046
  }
1039
1047
  }
@@ -1053,15 +1061,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1053
1061
  const amount = new import_decimal.Decimal(originalAmount);
1054
1062
  const roundingInterval = new import_decimal.Decimal(interval);
1055
1063
  if (roundingInterval.lte(0)) {
1056
- throw new Error("\u820D\u5165\u95F4\u9694\u5FC5\u987B\u5927\u4E8E 0");
1064
+ throw new Error("舍入间隔必须大于 0");
1057
1065
  }
1058
1066
  const supportedIntervals = [0.05, 0.1, 0.5, 1];
1059
1067
  const intervalValue = roundingInterval.toNumber();
1060
1068
  if (!supportedIntervals.includes(intervalValue)) {
1061
- console.warn(`[PaymentModule] \u4E0D\u652F\u6301\u7684\u820D\u5165\u95F4\u9694: ${intervalValue}, \u652F\u6301\u7684\u95F4\u9694: ${supportedIntervals.join(", ")}`);
1069
+ console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(", ")}`);
1062
1070
  }
1063
1071
  const baseValue = amount.div(roundingInterval);
1064
- console.log(`[PaymentModule] \u820D\u5165\u8BA1\u7B97 - \u539F\u59CB\u91D1\u989D: ${amount.toString()}, \u95F4\u9694: ${intervalValue}, \u57FA\u7840\u503C: ${baseValue.toString()}, \u89C4\u5219: ${rule}`);
1072
+ console.log(`[PaymentModule] 舍入计算 - 原始金额: ${amount.toString()}, 间隔: ${intervalValue}, 基础值: ${baseValue.toString()}, 规则: ${rule}`);
1065
1073
  let roundedValue;
1066
1074
  switch (rule) {
1067
1075
  case import_types.RoundingRule.Standard:
@@ -1081,12 +1089,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1081
1089
  roundedValue = baseValue.floor();
1082
1090
  break;
1083
1091
  default:
1084
- throw new Error(`\u4E0D\u652F\u6301\u7684\u820D\u5165\u89C4\u5219: ${rule}`);
1092
+ throw new Error(`不支持的舍入规则: ${rule}`);
1085
1093
  }
1086
1094
  const finalAmount = roundedValue.mul(roundingInterval);
1087
1095
  const originalAmountStr = amount.toFixed(2);
1088
1096
  if (finalAmount.eq(0)) {
1089
- console.log(`[PaymentModule] \u6700\u7EC8\u91D1\u989D\u4E3A0\uFF0C\u8FD4\u56DE\u539F\u59CB\u91D1\u989D: ${originalAmountStr}`);
1097
+ console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
1090
1098
  return {
1091
1099
  originalAmount: originalAmountStr,
1092
1100
  roundedAmount: originalAmountStr,
@@ -1096,15 +1104,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1096
1104
  const roundedAmountStr = finalAmount.toFixed(2);
1097
1105
  const roundingDifference = finalAmount.sub(amount);
1098
1106
  const roundingDifferenceStr = roundingDifference.toFixed(2);
1099
- console.log(`[PaymentModule] \u820D\u5165\u7ED3\u679C - \u539F\u59CB\u91D1\u989D: ${originalAmountStr}, \u820D\u5165\u540E\u91D1\u989D: ${roundedAmountStr}, \u820D\u5165\u5DEE\u989D: ${roundingDifferenceStr}`);
1107
+ console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
1100
1108
  return {
1101
1109
  originalAmount: originalAmountStr,
1102
1110
  roundedAmount: roundedAmountStr,
1103
1111
  roundingDifference: roundingDifferenceStr
1104
1112
  };
1105
1113
  } catch (error) {
1106
- console.error("[PaymentModule] \u91D1\u989D\u820D\u5165\u5931\u8D25:", error);
1107
- throw new Error(`\u91D1\u989D\u820D\u5165\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
1114
+ console.error("[PaymentModule] 金额舍入失败:", error);
1115
+ throw new Error(`金额舍入失败: ${error instanceof Error ? error.message : String(error)}`);
1108
1116
  }
1109
1117
  }
1110
1118
  /**
@@ -200,6 +200,8 @@ export interface PushOrderParams {
200
200
  deposit_amount?: string;
201
201
  /** 原始订单数据(可选,由 Checkout 模块传入) */
202
202
  order_info?: any;
203
+ /** 云端已存在的支付项(可选,用于处理订单在其他设备或云端生成的场景) */
204
+ existPayment?: PaymentItem[];
203
205
  }
204
206
  /**
205
207
  * 更新订单参数
@@ -581,12 +583,12 @@ export declare enum PaymentHooks {
581
583
  OnOrderAmountChanged = "payment:onOrderAmountChanged",
582
584
  OnPaymentSyncError = "payment:onPaymentSyncError",
583
585
  OnPaymentSyncSuccess = "payment:onPaymentSyncSuccess",
584
- OnWalletRecommendListUpdated = 0,
585
- OnWalletRecommendListCleared = 0,
586
- OnUserIdentificationCodesUpdated = 0,
587
- OnUserIdentificationCodesCleared = 0,
588
- OnWalletCacheCleared = 0,
589
- OnSearchIdentificationCodeCompleted = 0
586
+ OnWalletRecommendListUpdated = "wallet:onWalletRecommendListUpdated",
587
+ OnWalletRecommendListCleared = "wallet:onWalletRecommendListCleared",
588
+ OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated",
589
+ OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared",
590
+ OnWalletCacheCleared = "wallet:onWalletCacheCleared",
591
+ OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted"
590
592
  }
591
593
  /**
592
594
  * 钱包推荐扣款请求参数
@@ -749,7 +751,7 @@ export interface SearchIdentificationCodeResponse {
749
751
  /**
750
752
  * 搜索识别码结果类型
751
753
  */
752
- export declare type SearchIdentificationCodeResult = {
754
+ export type SearchIdentificationCodeResult = {
753
755
  type: 'walletCode';
754
756
  data: SearchIdentificationCodeItem[];
755
757
  } | {
@@ -49,9 +49,12 @@ var sortUserIdentificationCodeList = (list) => {
49
49
  var _a;
50
50
  const errorCode = (_a = item.unified_error_code) == null ? void 0 : _a.toString();
51
51
  const availableStatus = item.unified_available_status;
52
- if (errorCode && middlePriorityErrorCodes.includes(errorCode)) return 2;
53
- if (availableStatus === 0) return 3;
54
- if (availableStatus === 1) return 1;
52
+ if (errorCode && middlePriorityErrorCodes.includes(errorCode))
53
+ return 2;
54
+ if (availableStatus === 0)
55
+ return 3;
56
+ if (availableStatus === 1)
57
+ return 1;
55
58
  return 0;
56
59
  };
57
60
  const aPriority = getPriority(a);