@pisell/pisellos 0.0.235 → 0.0.236

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.
@@ -96,6 +96,23 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
96
96
  await this.handlePaymentError(data);
97
97
  }
98
98
  });
99
+ this.core.effects.on(
100
+ import_types2.PaymentHooks.OnPaymentMethodsLoaded,
101
+ async (methods) => {
102
+ console.log("[Checkout] 收到支付方式加载完成事件:", methods.length);
103
+ this.store.paymentMethods = methods;
104
+ }
105
+ );
106
+ this.core.effects.on(
107
+ import_types2.PaymentHooks.OnPaymentMethodsChanged,
108
+ async (data) => {
109
+ console.log("[Checkout] 收到支付方式变更事件:", {
110
+ oldCount: data.oldMethods.length,
111
+ newCount: data.newMethods.length
112
+ });
113
+ this.store.paymentMethods = data.newMethods;
114
+ }
115
+ );
99
116
  }
100
117
  /**
101
118
  * 初始化结账流程
@@ -160,7 +177,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
160
177
  }
161
178
  /**
162
179
  * 创建本地订单 (前端模拟下单流程)
163
- *
180
+ *
164
181
  * 此方法用于在前端模拟整个下单流程,创建一个本地的虚拟订单。
165
182
  * 用户在购物车点击下单时,会把购物车参数传递给此方法,
166
183
  * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
@@ -168,6 +185,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
168
185
  async createLocalOrderAsync(params) {
169
186
  var _a, _b, _c, _d;
170
187
  try {
188
+ await this.resetStoreStateAsync();
171
189
  await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
172
190
  const validation = await this.validateLocalOrderData(params.orderData);
173
191
  if (!validation.valid) {
@@ -233,7 +251,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
233
251
  });
234
252
  return paymentOrder;
235
253
  } catch (error) {
236
- await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
254
+ await this.handleError(
255
+ error,
256
+ import_types.CheckoutErrorType.OrderCreationFailed
257
+ );
237
258
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
238
259
  error: this.store.lastError,
239
260
  timestamp: Date.now()
@@ -243,7 +264,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
243
264
  }
244
265
  /**
245
266
  * 手动下单 (根据虚拟订单生成实际订单)
246
- *
267
+ *
247
268
  * 使用当前存储的本地订单数据调用 Order 模块创建真实订单
248
269
  */
249
270
  async placeOrderAsync(params = {}) {
@@ -310,7 +331,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
310
331
  errorMessage = error.message;
311
332
  }
312
333
  console.error("[Checkout] 手动下单失败:", errorMessage);
313
- await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
334
+ await this.handleError(
335
+ error,
336
+ import_types.CheckoutErrorType.OrderCreationFailed
337
+ );
314
338
  return {
315
339
  success: false,
316
340
  error: errorMessage
@@ -359,7 +383,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
359
383
  console.log("[Checkout] 订单创建成功:", paymentOrder.id);
360
384
  return paymentOrder;
361
385
  } catch (error) {
362
- await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
386
+ await this.handleError(
387
+ error,
388
+ import_types.CheckoutErrorType.OrderCreationFailed
389
+ );
363
390
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
364
391
  error: this.store.lastError,
365
392
  timestamp: Date.now()
@@ -455,6 +482,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
455
482
  timestamp: Date.now()
456
483
  });
457
484
  console.log("[Checkout] 结账流程完成:", order.id);
485
+ await this.resetStoreStateAsync();
458
486
  return {
459
487
  success: true,
460
488
  orderId: String(order.id)
@@ -470,7 +498,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
470
498
  async cancelCheckoutAsync() {
471
499
  try {
472
500
  if (this.store.currentOrder) {
473
- await this.payment.deletePaymentOrderAsync(this.store.currentOrder.uuid);
501
+ await this.payment.deletePaymentOrderAsync(
502
+ this.store.currentOrder.uuid
503
+ );
474
504
  this.store.currentOrder = void 0;
475
505
  }
476
506
  this.store.localOrderData = void 0;
@@ -523,21 +553,26 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
523
553
  * 获取可用支付方式
524
554
  */
525
555
  async getAvailablePaymentMethodsAsync() {
526
- if (this.store.paymentMethods.length === 0) {
527
- console.log("[Checkout] 支付方式缓存为空,重新加载...");
528
- await this.preloadPaymentMethods();
529
- }
530
- return this.store.paymentMethods;
556
+ return await this.getPaymentMethodsAsync();
531
557
  }
532
558
  /**
533
559
  * 刷新支付方式缓存
534
- *
560
+ *
535
561
  * 强制重新从服务器获取支付方式列表,更新本地缓存
536
562
  */
537
563
  async refreshPaymentMethodsAsync() {
538
564
  console.log("[Checkout] 强制刷新支付方式缓存...");
539
- await this.preloadPaymentMethods();
540
- return this.store.paymentMethods;
565
+ try {
566
+ const methods = await this.payment.getPayMethodListAsync();
567
+ this.store.paymentMethods = methods;
568
+ console.log(
569
+ `[Checkout] 强制刷新完成,获取到 ${methods.length} 种支付方式`
570
+ );
571
+ return methods;
572
+ } catch (error) {
573
+ console.error("[Checkout] 强制刷新支付方式失败:", error);
574
+ return this.store.paymentMethods;
575
+ }
541
576
  }
542
577
  /**
543
578
  * 获取订单原始数据
@@ -548,7 +583,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
548
583
  }
549
584
  /**
550
585
  * 获取当前订单基础信息
551
- *
586
+ *
552
587
  * 返回当前订单的基础信息,包括订单状态、金额、支付状态等
553
588
  */
554
589
  getCurrentOrderInfo() {
@@ -593,7 +628,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
593
628
  }
594
629
  /**
595
630
  * 获取当前订单的支付项
596
- *
631
+ *
597
632
  * 返回当前订单的所有支付项,包括活跃和已撤销的支付项
598
633
  */
599
634
  async getCurrentOrderPaymentItemsAsync() {
@@ -607,7 +642,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
607
642
  orderUuid: currentOrder.uuid,
608
643
  orderId: currentOrder.order_id
609
644
  });
610
- const paymentItems = await this.payment.getPaymentItemsAsync(currentOrder.uuid);
645
+ const paymentItems = await this.payment.getPaymentItemsAsync(
646
+ currentOrder.uuid
647
+ );
611
648
  console.log("[Checkout] 成功获取支付项:", {
612
649
  orderUuid: currentOrder.uuid,
613
650
  paymentItemCount: paymentItems.length,
@@ -662,7 +699,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
662
699
  }
663
700
  break;
664
701
  default:
665
- console.warn("[Checkout] 无法重试此类型的错误:", this.store.lastError.type);
702
+ console.warn(
703
+ "[Checkout] 无法重试此类型的错误:",
704
+ this.store.lastError.type
705
+ );
666
706
  }
667
707
  }
668
708
  } catch (error) {
@@ -695,9 +735,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
695
735
  }
696
736
  /**
697
737
  * 替换本地订单ID为真实订单ID
698
- *
738
+ *
699
739
  * 当后端订单创建完成后,调用此方法将本地虚拟订单ID替换为真实订单ID
700
- *
740
+ *
701
741
  * @param newOrderId 后端返回的真实订单ID
702
742
  * @returns 更新后的订单对象,如果当前没有订单则返回null
703
743
  */
@@ -733,9 +773,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
733
773
  }
734
774
  /**
735
775
  * 设置自定义支付金额
736
- *
776
+ *
737
777
  * 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
738
- *
778
+ *
739
779
  * @param amount 自定义支付金额,必须是有效的数字字符串
740
780
  */
741
781
  async setStateAmountAsync(amount) {
@@ -771,7 +811,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
771
811
  }
772
812
  /**
773
813
  * 获取当前自定义支付金额
774
- *
814
+ *
775
815
  * @returns 当前设置的自定义支付金额
776
816
  */
777
817
  getStateAmount() {
@@ -779,7 +819,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
779
819
  }
780
820
  /**
781
821
  * 刷新 stateAmount 为当前剩余未支付金额
782
- *
822
+ *
783
823
  * UI 可以调用此方法来主动刷新支付金额状态
784
824
  */
785
825
  async refreshStateAmountAsync() {
@@ -787,9 +827,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
787
827
  }
788
828
  /**
789
829
  * 获取购物车小计数据
790
- *
830
+ *
791
831
  * 返回当前结账流程中的购物车小计项数据,包含各种费用明细
792
- *
832
+ *
793
833
  * @returns 购物车小计数据数组,如果没有则返回 null
794
834
  */
795
835
  getCartSummary() {
@@ -799,15 +839,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
799
839
  }
800
840
  console.log("[Checkout] 获取购物车小计数据:", {
801
841
  itemCount: this.store.cartSummary.length,
802
- items: this.store.cartSummary.map((item) => ({ key: item.key, value: item.value, label: item.label }))
842
+ items: this.store.cartSummary.map((item) => ({
843
+ key: item.key,
844
+ value: item.value,
845
+ label: item.label
846
+ }))
803
847
  });
804
848
  return [...this.store.cartSummary];
805
849
  }
806
850
  /**
807
851
  * 获取提取的金额详细信息
808
- *
852
+ *
809
853
  * 从当前的购物车小计数据中提取结构化的金额信息
810
- *
854
+ *
811
855
  * @returns 提取的金额信息对象,如果没有小计数据则返回 null
812
856
  */
813
857
  getExtractedAmountInfo() {
@@ -815,25 +859,45 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
815
859
  console.warn("[Checkout] 没有可用的购物车小计数据,无法提取金额信息");
816
860
  return null;
817
861
  }
818
- const extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
862
+ const extractedInfo = this.extractAmountFromCartSummary(
863
+ this.store.cartSummary
864
+ );
819
865
  console.log("[Checkout] 获取提取的金额信息:", extractedInfo);
820
866
  return extractedInfo;
821
867
  }
822
868
  /**
823
869
  * 获取支付方式列表
824
- *
825
- * 直接调用 Payment 模块的 getPayMethodListAsync 方法
826
- *
870
+ *
871
+ * 优先使用 store 中的缓存数据,避免重复接口调用。
872
+ * 如果 store 中没有数据,则调用 Payment 模块的方法获取。
873
+ *
827
874
  * @returns 支付方式列表
828
875
  */
829
876
  async getPaymentMethodsAsync() {
830
- return await this.payment.getPayMethodListAsync();
877
+ if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
878
+ console.log(
879
+ `[Checkout] 使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
880
+ );
881
+ return this.store.paymentMethods;
882
+ }
883
+ console.log("[Checkout] store 中无缓存,从 Payment 模块获取支付方式...");
884
+ try {
885
+ const methods = await this.payment.getPayMethodListAsync();
886
+ this.store.paymentMethods = methods;
887
+ console.log(
888
+ `[Checkout] 从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
889
+ );
890
+ return methods;
891
+ } catch (error) {
892
+ console.error("[Checkout] 获取支付方式失败:", error);
893
+ return [];
894
+ }
831
895
  }
832
896
  /**
833
897
  * 为当前订单添加支付项
834
- *
898
+ *
835
899
  * 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
836
- *
900
+ *
837
901
  * @param paymentItem 支付项数据
838
902
  * @throws 当前没有活跃订单时抛出错误
839
903
  */
@@ -881,9 +945,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
881
945
  }
882
946
  /**
883
947
  * 删除当前订单的支付项
884
- *
948
+ *
885
949
  * 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
886
- *
950
+ *
887
951
  * @param paymentUuid 要删除的支付项UUID
888
952
  * @throws 当前没有活跃订单时抛出错误
889
953
  * @throws 支付项不存在时抛出错误
@@ -925,17 +989,25 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
925
989
  console.log("[Checkout] Payment模块删除完成");
926
990
  const currentOrderId = this.store.currentOrder.order_id;
927
991
  const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
928
- const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
992
+ const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
993
+ this.store.currentOrder.uuid
994
+ );
929
995
  if (updatedOrder) {
930
996
  if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
931
- console.warn("[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:", {
932
- 当前真实ID: currentOrderId,
933
- 获取到的虚拟ID: updatedOrder.order_id
934
- });
997
+ console.warn(
998
+ "[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
999
+ {
1000
+ 当前真实ID: currentOrderId,
1001
+ 获取到的虚拟ID: updatedOrder.order_id
1002
+ }
1003
+ );
935
1004
  updatedOrder.order_id = currentOrderId;
936
1005
  }
937
1006
  this.store.currentOrder = updatedOrder;
938
- console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
1007
+ console.log(
1008
+ "[Checkout] 订单数据已同步,当前支付项数量:",
1009
+ updatedOrder.payment.length
1010
+ );
939
1011
  }
940
1012
  await this.updateStateAmountToRemaining();
941
1013
  await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
@@ -954,10 +1026,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
954
1026
  }
955
1027
  /**
956
1028
  * 批量更新当前订单的代金券支付项(覆盖更新)
957
- *
1029
+ *
958
1030
  * 删除所有现有的代金券支付项,然后添加新的代金券支付项。
959
1031
  * 这是一个覆盖式更新操作,确保代金券支付项的一致性。
960
- *
1032
+ *
961
1033
  * @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
962
1034
  * @throws 当前没有活跃订单时抛出错误
963
1035
  * @throws 支付项缺少 voucher_id 时抛出错误
@@ -990,17 +1062,25 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
990
1062
  console.log("[Checkout] Payment模块批量更新完成");
991
1063
  const currentOrderId = this.store.currentOrder.order_id;
992
1064
  const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
993
- const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1065
+ const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
1066
+ this.store.currentOrder.uuid
1067
+ );
994
1068
  if (updatedOrder) {
995
1069
  if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
996
- console.warn("[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:", {
997
- 当前真实ID: currentOrderId,
998
- 获取到的虚拟ID: updatedOrder.order_id
999
- });
1070
+ console.warn(
1071
+ "[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
1072
+ {
1073
+ 当前真实ID: currentOrderId,
1074
+ 获取到的虚拟ID: updatedOrder.order_id
1075
+ }
1076
+ );
1000
1077
  updatedOrder.order_id = currentOrderId;
1001
1078
  }
1002
1079
  this.store.currentOrder = updatedOrder;
1003
- console.log("[Checkout] 订单数据已同步,当前支付项数量:", updatedOrder.payment.length);
1080
+ console.log(
1081
+ "[Checkout] 订单数据已同步,当前支付项数量:",
1082
+ updatedOrder.payment.length
1083
+ );
1004
1084
  const voucherItems = updatedOrder.payment.filter(
1005
1085
  (payment) => payment.voucher_id && payment.status !== "voided"
1006
1086
  );
@@ -1030,9 +1110,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1030
1110
  }
1031
1111
  /**
1032
1112
  * 修改当前订单的定金状态
1033
- *
1113
+ *
1034
1114
  * 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
1035
- *
1115
+ *
1036
1116
  * @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
1037
1117
  * @throws 当前没有活跃订单时抛出错误
1038
1118
  */
@@ -1069,7 +1149,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1069
1149
  updateParams.deposit_amount = "0.00";
1070
1150
  console.log("[Checkout] 订单从定金改为全款,清空定金金额");
1071
1151
  }
1072
- await this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1152
+ await this.payment.updateOrderAsync(
1153
+ this.store.currentOrder.uuid,
1154
+ updateParams
1155
+ );
1073
1156
  this.store.currentOrder = {
1074
1157
  ...this.store.currentOrder,
1075
1158
  ...updateParams
@@ -1087,15 +1170,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1087
1170
  });
1088
1171
  } catch (error) {
1089
1172
  console.error("[Checkout] 更新订单定金状态失败:", error);
1090
- await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1173
+ await this.handleError(
1174
+ error,
1175
+ import_types.CheckoutErrorType.ValidationFailed
1176
+ );
1091
1177
  throw error;
1092
1178
  }
1093
1179
  }
1094
1180
  /**
1095
1181
  * 更新当前订单的客户信息
1096
- *
1182
+ *
1097
1183
  * 更新当前订单关联的客户信息,用于标识订单的所属客户
1098
- *
1184
+ *
1099
1185
  * @param customer 客户信息 (customer_id 和/或 customer_name)
1100
1186
  * @throws 当前没有活跃订单时抛出错误
1101
1187
  */
@@ -1120,16 +1206,22 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1120
1206
  this.store.localOrderData.customer_id = customer.customer_id;
1121
1207
  this.store.localOrderData.customer_name = customer.customer_name;
1122
1208
  }
1123
- console.log("[Checkout] 订单客户信息更新成功:", this.store.currentCustomer);
1209
+ console.log(
1210
+ "[Checkout] 订单客户信息更新成功:",
1211
+ this.store.currentCustomer
1212
+ );
1124
1213
  } catch (error) {
1125
1214
  console.error("[Checkout] 更新订单客户信息失败:", error);
1126
- await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1215
+ await this.handleError(
1216
+ error,
1217
+ import_types.CheckoutErrorType.ValidationFailed
1218
+ );
1127
1219
  throw error;
1128
1220
  }
1129
1221
  }
1130
1222
  /**
1131
1223
  * 获取当前订单的客户信息
1132
- *
1224
+ *
1133
1225
  * @returns 当前客户信息,如果没有则返回 null
1134
1226
  */
1135
1227
  getCurrentCustomer() {
@@ -1137,7 +1229,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1137
1229
  }
1138
1230
  /**
1139
1231
  * 检查订单是否需要手动同步(异步版本)
1140
- *
1232
+ *
1141
1233
  * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
1142
1234
  * 从 Payment 模块获取最新的支付项数据
1143
1235
  */
@@ -1181,7 +1273,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1181
1273
  }
1182
1274
  /**
1183
1275
  * 手动同步订单到后端
1184
- *
1276
+ *
1185
1277
  * 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
1186
1278
  */
1187
1279
  async manualSyncOrderAsync() {
@@ -1224,7 +1316,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1224
1316
  console.error("[Checkout] 严重警告:手动同步完成后订单ID仍为虚拟ID!");
1225
1317
  }
1226
1318
  if (realOrderId !== finalOrderId) {
1227
- console.error("[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!");
1319
+ console.error(
1320
+ "[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
1321
+ );
1228
1322
  }
1229
1323
  return {
1230
1324
  success: true,
@@ -1245,7 +1339,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1245
1339
  }
1246
1340
  /**
1247
1341
  * 获取当前订单备注
1248
- *
1342
+ *
1249
1343
  * @returns 当前订单的备注内容,如果没有则返回空字符串
1250
1344
  */
1251
1345
  getOrderNote() {
@@ -1257,7 +1351,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1257
1351
  }
1258
1352
  /**
1259
1353
  * 获取当前订单ID
1260
- *
1354
+ *
1261
1355
  * @returns 当前订单的ID,如果没有订单则返回null
1262
1356
  */
1263
1357
  getCurrentOrderId() {
@@ -1268,7 +1362,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1268
1362
  }
1269
1363
  /**
1270
1364
  * 获取当前订单是否已同步到后端
1271
- *
1365
+ *
1272
1366
  * @returns 当前订单是否已同步状态,如果没有订单则返回false
1273
1367
  */
1274
1368
  isCurrentOrderSynced() {
@@ -1286,9 +1380,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1286
1380
  }
1287
1381
  /**
1288
1382
  * 取消当前本地订单
1289
- *
1383
+ *
1290
1384
  * 只能取消未同步到后端的本地订单,如果订单已同步则不能取消
1291
- *
1385
+ *
1292
1386
  * @param cancelReason 取消原因(可选)
1293
1387
  * @returns 取消结果
1294
1388
  */
@@ -1368,7 +1462,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1368
1462
  }
1369
1463
  /**
1370
1464
  * 保存订单并稍后支付
1371
- *
1465
+ *
1372
1466
  * 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
1373
1467
  * 适用于用户想要保存订单但稍后完成支付的场景
1374
1468
  */
@@ -1388,7 +1482,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1388
1482
  orderId: currentOrderId,
1389
1483
  totalAmount: this.store.currentOrder.total_amount
1390
1484
  });
1391
- const allPaymentItems = await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1485
+ const allPaymentItems = await this.payment.getPaymentItemsAsync(
1486
+ this.store.currentOrder.uuid
1487
+ );
1392
1488
  const filteredPaymentItems = allPaymentItems.filter(
1393
1489
  (payment) => !payment.voucher_id || payment.voucher_id.trim() === ""
1394
1490
  );
@@ -1411,7 +1507,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1411
1507
  amount: item.amount
1412
1508
  }))
1413
1509
  });
1414
- const realOrderId = await this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
1510
+ const realOrderId = await this.syncOrderToBackendWithReturn(
1511
+ false,
1512
+ filteredPaymentItems
1513
+ );
1415
1514
  console.log("[Checkout] 保存订单完成:", {
1416
1515
  orderUuid,
1417
1516
  oldOrderId: currentOrderId,
@@ -1444,7 +1543,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1444
1543
  }
1445
1544
  /**
1446
1545
  * 获取当前商店折扣金额
1447
- *
1546
+ *
1448
1547
  * @returns 当前的商店折扣金额,如果没有则返回0
1449
1548
  */
1450
1549
  getShopDiscount() {
@@ -1453,7 +1552,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1453
1552
  return this.store.localOrderData.shop_discount;
1454
1553
  }
1455
1554
  if (this.store.cartSummary) {
1456
- const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
1555
+ const shopDiscountItem = this.store.cartSummary.find(
1556
+ (item) => item.key === "shop_discount"
1557
+ );
1457
1558
  if (shopDiscountItem) {
1458
1559
  return shopDiscountItem.value;
1459
1560
  }
@@ -1462,9 +1563,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1462
1563
  }
1463
1564
  /**
1464
1565
  * 更新订单商店折扣
1465
- *
1566
+ *
1466
1567
  * 同时更新cartSummary和localOrderData中的shop_discount值
1467
- *
1568
+ *
1468
1569
  * @param discountAmount 商店折扣金额
1469
1570
  */
1470
1571
  async updateShopDiscountAsync(discountAmount) {
@@ -1477,7 +1578,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1477
1578
  newDiscount: discountAmount
1478
1579
  });
1479
1580
  if (this.store.cartSummary) {
1480
- const shopDiscountItem = this.store.cartSummary.find((item) => item.key === "shop_discount");
1581
+ const shopDiscountItem = this.store.cartSummary.find(
1582
+ (item) => item.key === "shop_discount"
1583
+ );
1481
1584
  if (shopDiscountItem) {
1482
1585
  shopDiscountItem.value = discountAmount;
1483
1586
  console.log("[Checkout] cartSummary 中的商店折扣已更新");
@@ -1498,7 +1601,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1498
1601
  console.warn("[Checkout] localOrderData 不存在,无法更新商店折扣");
1499
1602
  }
1500
1603
  if (this.store.currentOrder && this.store.cartSummary) {
1501
- const updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
1604
+ const updatedAmountInfo = this.extractAmountFromCartSummary(
1605
+ this.store.cartSummary
1606
+ );
1502
1607
  console.log("[Checkout] 重新计算订单金额:", updatedAmountInfo);
1503
1608
  this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
1504
1609
  this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
@@ -1516,13 +1621,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1516
1621
  });
1517
1622
  } catch (error) {
1518
1623
  console.error("[Checkout] 更新商店折扣失败:", error);
1519
- await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1624
+ await this.handleError(
1625
+ error,
1626
+ import_types.CheckoutErrorType.ValidationFailed
1627
+ );
1520
1628
  throw error;
1521
1629
  }
1522
1630
  }
1523
1631
  /**
1524
1632
  * 更新订单备注
1525
- *
1633
+ *
1526
1634
  * @param note 订单备注内容
1527
1635
  */
1528
1636
  async updateOrderNoteAsync(note) {
@@ -1543,12 +1651,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1543
1651
  this.store.localOrderData.shop_note = note;
1544
1652
  if (this.store.currentOrder) {
1545
1653
  try {
1546
- const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1654
+ const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(
1655
+ this.store.currentOrder.uuid
1656
+ );
1547
1657
  if (orderInPayment && orderInPayment.note !== void 0) {
1548
1658
  console.log("[Checkout] 同步备注到Payment模块的订单数据中");
1549
1659
  }
1550
1660
  } catch (syncError) {
1551
- console.warn("[Checkout] 同步备注到Payment模块失败,但本地更新成功:", syncError);
1661
+ console.warn(
1662
+ "[Checkout] 同步备注到Payment模块失败,但本地更新成功:",
1663
+ syncError
1664
+ );
1552
1665
  }
1553
1666
  }
1554
1667
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
@@ -1563,7 +1676,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1563
1676
  });
1564
1677
  } catch (error) {
1565
1678
  console.error("[Checkout] 更新订单备注失败:", error);
1566
- await this.handleError(error, import_types.CheckoutErrorType.ValidationFailed);
1679
+ await this.handleError(
1680
+ error,
1681
+ import_types.CheckoutErrorType.ValidationFailed
1682
+ );
1567
1683
  throw error;
1568
1684
  }
1569
1685
  }
@@ -1629,7 +1745,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1629
1745
  import_types.CheckoutErrorType.PaymentFailed,
1630
1746
  data.error || "支付同步失败"
1631
1747
  );
1632
- await this.handleError(error instanceof Error ? error : new Error(String(error)), import_types.CheckoutErrorType.PaymentFailed);
1748
+ await this.handleError(
1749
+ error instanceof Error ? error : new Error(String(error)),
1750
+ import_types.CheckoutErrorType.PaymentFailed
1751
+ );
1633
1752
  await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentFailed, {
1634
1753
  orderUuid: data.orderUuid,
1635
1754
  paymentMethodCode: "",
@@ -1647,6 +1766,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1647
1766
  * 验证本地订单数据
1648
1767
  */
1649
1768
  async validateLocalOrderData(orderData) {
1769
+ var _a;
1650
1770
  const errors = [];
1651
1771
  if (!orderData.type) {
1652
1772
  errors.push("订单类型不能为空");
@@ -1654,7 +1774,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1654
1774
  if (!orderData.platform) {
1655
1775
  errors.push("平台信息不能为空");
1656
1776
  }
1657
- if (!orderData.bookings || orderData.bookings.length === 0) {
1777
+ if ((!orderData.bookings || orderData.bookings.length === 0) && !((_a = orderData == null ? void 0 : orderData.relation_products) == null ? void 0 : _a.length)) {
1658
1778
  errors.push("预订信息不能为空");
1659
1779
  }
1660
1780
  if (orderData.bookings) {
@@ -1685,7 +1805,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1685
1805
  }
1686
1806
  /**
1687
1807
  * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
1688
- *
1808
+ *
1689
1809
  * @param date 要格式化的日期对象
1690
1810
  * @returns 格式化后的日期时间字符串
1691
1811
  */
@@ -1871,7 +1991,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1871
1991
  }
1872
1992
  /**
1873
1993
  * 检查订单支付是否完成
1874
- *
1994
+ *
1875
1995
  * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
1876
1996
  */
1877
1997
  async checkOrderPaymentCompletion() {
@@ -1932,18 +2052,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1932
2052
  }
1933
2053
  /**
1934
2054
  * 判断支付方式是否需要同步订单到后端
1935
- *
2055
+ *
1936
2056
  * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
1937
- *
2057
+ *
1938
2058
  * @param paymentCode 支付方式代码
1939
- * @param paymentType 支付方式类型
2059
+ * @param paymentType 支付方式类型
1940
2060
  * @returns 是否需要同步订单
1941
2061
  */
1942
2062
  shouldSyncOrderForPayment(paymentCode, paymentType) {
1943
2063
  const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
1944
2064
  const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
1945
2065
  const cashIdentifiers = ["CASHMANUAL", "CASH", "MANUAL"];
1946
- if (cashIdentifiers.some((id) => codeUpper.includes(id) || typeUpper.includes(id))) {
2066
+ if (cashIdentifiers.some(
2067
+ (id) => codeUpper.includes(id) || typeUpper.includes(id)
2068
+ )) {
1947
2069
  return false;
1948
2070
  }
1949
2071
  if (paymentCode === import_types2.PaymentMethodType.Cash || paymentType === import_types2.PaymentMethodType.Cash) {
@@ -1956,12 +2078,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1956
2078
  }
1957
2079
  /**
1958
2080
  * 同步订单到后端
1959
- *
2081
+ *
1960
2082
  * 调用后端 /order/checkout 接口创建真实订单
1961
2083
  */
1962
2084
  /**
1963
2085
  * 判断订单ID是否为本地生成的虚拟ID
1964
- *
2086
+ *
1965
2087
  * @param orderId 订单ID
1966
2088
  * @returns true 表示是虚拟ID,false 表示是真实的后端ID
1967
2089
  */
@@ -1970,7 +2092,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1970
2092
  }
1971
2093
  /**
1972
2094
  * 同步订单到后端并返回真实订单ID
1973
- *
2095
+ *
1974
2096
  * @param isManual 是否为手动同步,默认为 false
1975
2097
  * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
1976
2098
  * @returns 后端返回的真实订单ID
@@ -2052,18 +2174,23 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2052
2174
  // surcharge_fee: this.otherParams.surcharge_fee,
2053
2175
  // surcharges: ,
2054
2176
  note: this.store.localOrderData.shop_note
2055
- // deposit_amount:
2177
+ // deposit_amount:
2056
2178
  };
2057
2179
  if (isUpdateOperation) {
2058
2180
  if (this.isVirtualOrderId(currentOrderId)) {
2059
- console.error("[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!", {
2060
- currentOrderId,
2061
- isOrderSynced: this.store.isOrderSynced,
2062
- reason,
2063
- orderUuid: this.store.currentOrder.uuid
2064
- });
2181
+ console.error(
2182
+ "[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!",
2183
+ {
2184
+ currentOrderId,
2185
+ isOrderSynced: this.store.isOrderSynced,
2186
+ reason,
2187
+ orderUuid: this.store.currentOrder.uuid
2188
+ }
2189
+ );
2065
2190
  console.log("[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理");
2066
- console.log("[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性");
2191
+ console.log(
2192
+ "[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
2193
+ );
2067
2194
  } else {
2068
2195
  orderParams.order_id = currentOrderId;
2069
2196
  console.log(`[Checkout] 更新订单操作,包含订单ID: ${currentOrderId}`);
@@ -2117,9 +2244,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2117
2244
  totalAmount: updatedOrder.total_amount
2118
2245
  });
2119
2246
  this.store.currentOrder = updatedOrder;
2120
- console.log("[Checkout] 订单ID替换成功,当前订单ID:", this.store.currentOrder.order_id);
2247
+ console.log(
2248
+ "[Checkout] 订单ID替换成功,当前订单ID:",
2249
+ this.store.currentOrder.order_id
2250
+ );
2121
2251
  } else {
2122
- console.error("[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换");
2252
+ console.error(
2253
+ "[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
2254
+ );
2123
2255
  const beforeManualUpdate = this.store.currentOrder.order_id;
2124
2256
  this.store.currentOrder.order_id = realOrderId;
2125
2257
  console.log("[Checkout] 手动设置订单ID:", {
@@ -2152,7 +2284,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2152
2284
  是否同步: this.store.isOrderSynced
2153
2285
  });
2154
2286
  if (finalIsVirtual && !isUpdateOperation) {
2155
- console.warn("[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题");
2287
+ console.warn(
2288
+ "[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题"
2289
+ );
2156
2290
  }
2157
2291
  return realOrderId;
2158
2292
  }
@@ -2162,7 +2296,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2162
2296
  } catch (error) {
2163
2297
  console.error("[Checkout] 同步订单到后端失败:", error);
2164
2298
  await this.handleError(
2165
- new Error(`订单同步失败: ${error instanceof Error ? error.message : String(error)}`),
2299
+ new Error(
2300
+ `订单同步失败: ${error instanceof Error ? error.message : String(error)}`
2301
+ ),
2166
2302
  import_types.CheckoutErrorType.OrderCreationFailed
2167
2303
  );
2168
2304
  }
@@ -2204,9 +2340,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2204
2340
  }
2205
2341
  /**
2206
2342
  * 通过订单ID编辑订单备注
2207
- *
2343
+ *
2208
2344
  * 用于修改已同步到后端的订单备注,通常在支付成功后的弹窗中使用
2209
- *
2345
+ *
2210
2346
  * @param orderId 后端订单ID
2211
2347
  * @param note 新的订单备注
2212
2348
  * @returns 修改结果
@@ -2225,9 +2361,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2225
2361
  orderId
2226
2362
  };
2227
2363
  }
2228
- const response = await this.request.put(`/shop/order/order/${orderId}/note`, {
2229
- note
2230
- });
2364
+ const response = await this.request.put(
2365
+ `/shop/order/order/${orderId}/note`,
2366
+ {
2367
+ note
2368
+ }
2369
+ );
2231
2370
  console.log("[Checkout] 订单备注编辑响应:", {
2232
2371
  orderId,
2233
2372
  status: response.status,
@@ -2275,9 +2414,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2275
2414
  }
2276
2415
  /**
2277
2416
  * 发送客户支付链接邮件
2278
- *
2417
+ *
2279
2418
  * 向指定邮箱发送订单支付提醒邮件
2280
- *
2419
+ *
2281
2420
  * @param params 发送参数
2282
2421
  * @returns 发送结果
2283
2422
  */
@@ -2301,7 +2440,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2301
2440
  };
2302
2441
  }
2303
2442
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
2304
- const invalidEmails = params.emails.filter((email) => !emailRegex.test(email));
2443
+ const invalidEmails = params.emails.filter(
2444
+ (email) => !emailRegex.test(email)
2445
+ );
2305
2446
  if (invalidEmails.length > 0) {
2306
2447
  return {
2307
2448
  success: false,
@@ -2314,7 +2455,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2314
2455
  emails: params.emails
2315
2456
  };
2316
2457
  console.log("[Checkout] 发送支付链接邮件请求参数:", requestBody);
2317
- const response = await this.request.post("/order/batch-email", requestBody);
2458
+ const response = await this.request.post(
2459
+ "/order/batch-email",
2460
+ requestBody
2461
+ );
2318
2462
  console.log("[Checkout] 支付链接邮件发送响应:", {
2319
2463
  status: response.status,
2320
2464
  message: response.message,
@@ -2346,7 +2490,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2346
2490
  }
2347
2491
  /**
2348
2492
  * 金额舍入
2349
- *
2493
+ *
2350
2494
  * @param amount 原始金额
2351
2495
  * @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
2352
2496
  */
@@ -2357,7 +2501,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2357
2501
  (_a = this.otherParams.order_rounding_setting) == null ? void 0 : _a.interval,
2358
2502
  (_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.type
2359
2503
  );
2360
- console.log(`[Checkout] 金额舍入完成 - 原始: ${result.originalAmount}, 舍入后: ${result.roundedAmount}, 差额: ${result.roundingDifference}`);
2504
+ console.log(
2505
+ `[Checkout] 金额舍入完成 - 原始: ${result.originalAmount}, 舍入后: ${result.roundedAmount}, 差额: ${result.roundingDifference}`
2506
+ );
2361
2507
  return result;
2362
2508
  }
2363
2509
  async destroy() {
@@ -2369,6 +2515,67 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2369
2515
  this.core.unregisterModule(this);
2370
2516
  console.log("[Checkout] 已销毁");
2371
2517
  }
2518
+ /**
2519
+ * 重置 store 状态
2520
+ *
2521
+ * 在创建新订单前调用,确保状态完全干净
2522
+ */
2523
+ async resetStoreStateAsync() {
2524
+ try {
2525
+ const prevOrderInfo = this.store.currentOrder ? {
2526
+ uuid: this.store.currentOrder.uuid,
2527
+ orderId: this.store.currentOrder.order_id
2528
+ } : null;
2529
+ console.log("[Checkout] 重置 store 状态,准备创建新订单", prevOrderInfo);
2530
+ this.store.currentOrder = void 0;
2531
+ this.store.localOrderData = void 0;
2532
+ this.store.cartSummary = void 0;
2533
+ this.store.stateAmount = "0.00";
2534
+ this.store.isOrderSynced = false;
2535
+ this.store.currentCustomer = void 0;
2536
+ this.store.lastError = void 0;
2537
+ this.store.cartItems = [];
2538
+ await this.setStatus(import_types.CheckoutStatus.Ready);
2539
+ await this.setStep(import_types.CheckoutStep.OrderConfirmation);
2540
+ this.payment.wallet.clearAllCache();
2541
+ console.log("[Checkout] Store 状态重置完成");
2542
+ if (prevOrderInfo) {
2543
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
2544
+ previousOrder: prevOrderInfo,
2545
+ timestamp: Date.now()
2546
+ });
2547
+ }
2548
+ } catch (error) {
2549
+ console.error("[Checkout] 重置 store 状态失败:", error);
2550
+ }
2551
+ }
2552
+ /**
2553
+ * 手动清理已完成的订单状态(公开方法)
2554
+ *
2555
+ * 供UI层调用的公开方法,用于手动清理订单状态
2556
+ *
2557
+ * @returns 清理结果
2558
+ */
2559
+ async clearCompletedOrderAsync() {
2560
+ try {
2561
+ const prevOrderInfo = this.store.currentOrder ? {
2562
+ uuid: this.store.currentOrder.uuid,
2563
+ orderId: this.store.currentOrder.order_id
2564
+ } : null;
2565
+ await this.resetStoreStateAsync();
2566
+ return {
2567
+ success: true,
2568
+ message: prevOrderInfo ? "订单状态已成功清理" : "没有需要清理的订单状态",
2569
+ clearedOrder: prevOrderInfo
2570
+ };
2571
+ } catch (error) {
2572
+ console.error("[Checkout] 手动清理订单状态失败:", error);
2573
+ return {
2574
+ success: false,
2575
+ message: error instanceof Error ? error.message : "清理失败"
2576
+ };
2577
+ }
2578
+ }
2372
2579
  };
2373
2580
  // Annotate the CommonJS export names for ESM import in node:
2374
2581
  0 && (module.exports = {