@pisell/pisellos 0.0.236 → 0.0.238

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.
@@ -393,7 +393,11 @@ export declare enum CheckoutHooks {
393
393
  /** 订单取消 */
394
394
  OnOrderCancelled = "checkout:onOrderCancelled",
395
395
  /** 订单状态已清理 */
396
- OnOrderCleared = "checkout:onOrderCleared"
396
+ OnOrderCleared = "checkout:onOrderCleared",
397
+ /** 下单接口请求开始 */
398
+ OnOrderSubmitStart = "checkout:onOrderSubmitStart",
399
+ /** 下单接口请求完成 */
400
+ OnOrderSubmitEnd = "checkout:onOrderSubmitEnd"
397
401
  }
398
402
  /**
399
403
  * 结账状态数据
@@ -824,4 +828,34 @@ export interface CheckoutEventData {
824
828
  } | null;
825
829
  timestamp: number;
826
830
  };
831
+ /** 下单接口请求开始事件 */
832
+ orderSubmitStart: {
833
+ /** 订单UUID */
834
+ orderUuid: string;
835
+ /** 操作类型 */
836
+ operation: 'create' | 'update';
837
+ /** 是否手动同步 */
838
+ isManual: boolean;
839
+ /** 支付项数量 */
840
+ paymentItemCount: number;
841
+ timestamp: number;
842
+ };
843
+ /** 下单接口请求完成事件 */
844
+ orderSubmitEnd: {
845
+ /** 是否成功 */
846
+ success: boolean;
847
+ /** 订单UUID */
848
+ orderUuid: string;
849
+ /** 操作类型 */
850
+ operation: 'create' | 'update';
851
+ /** 是否手动同步 */
852
+ isManual: boolean;
853
+ /** 返回的订单ID(成功时) */
854
+ orderId?: string;
855
+ /** 错误信息(失败时) */
856
+ error?: string;
857
+ /** 耗时(毫秒) */
858
+ duration?: number;
859
+ timestamp: number;
860
+ };
827
861
  }
@@ -119,6 +119,8 @@ export var CheckoutHooks = /*#__PURE__*/function (CheckoutHooks) {
119
119
  CheckoutHooks["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
120
120
  CheckoutHooks["OnOrderCancelled"] = "checkout:onOrderCancelled";
121
121
  CheckoutHooks["OnOrderCleared"] = "checkout:onOrderCleared";
122
+ CheckoutHooks["OnOrderSubmitStart"] = "checkout:onOrderSubmitStart";
123
+ CheckoutHooks["OnOrderSubmitEnd"] = "checkout:onOrderSubmitEnd";
122
124
  return CheckoutHooks;
123
125
  }({});
124
126
 
@@ -47,6 +47,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
47
47
  private setDiscountList;
48
48
  private getDiscountList;
49
49
  private getCustomerWallet;
50
+ private bestDiscount;
50
51
  private loadPrepareConfig;
51
52
  }
52
53
  export default ShopDiscountImpl;
@@ -50,7 +50,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
50
50
  customer: null,
51
51
  productList: [],
52
52
  discount: null,
53
- rules: null
53
+ rules: null,
54
+ originalDiscountList: []
54
55
  };
55
56
  return _this;
56
57
  }
@@ -360,26 +361,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
360
361
  discountList: this.getDiscountList()
361
362
  }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
362
363
  if (!isAvailable) {
363
- _context5.next = 20;
364
+ _context5.next = 21;
364
365
  break;
365
366
  }
366
367
  this.setDiscountList(newDiscountList || []);
368
+ this.store.originalDiscountList = newDiscountList || [];
367
369
  this.setProductList(newProductList || []);
368
370
  if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
369
- _context5.next = 20;
371
+ _context5.next = 21;
370
372
  break;
371
373
  }
372
- _context5.next = 20;
374
+ _context5.next = 21;
373
375
  return this.getCustomerWallet(resultDiscountList[0].customer_id);
374
- case 20:
376
+ case 21:
375
377
  return _context5.abrupt("return", {
376
378
  type: "clientCalc",
377
379
  isAvailable: isAvailable || false,
378
380
  productList: newProductList || this.store.productList || [],
379
381
  discountList: newDiscountList || this.getDiscountList()
380
382
  });
381
- case 23:
382
- _context5.prev = 23;
383
+ case 24:
384
+ _context5.prev = 24;
383
385
  _context5.t1 = _context5["catch"](0);
384
386
  console.error('[ShopDiscount] 扫码出错:', _context5.t1);
385
387
  return _context5.abrupt("return", {
@@ -388,11 +390,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
388
390
  productList: this.store.productList || [],
389
391
  discountList: this.getDiscountList()
390
392
  });
391
- case 27:
393
+ case 28:
392
394
  case "end":
393
395
  return _context5.stop();
394
396
  }
395
- }, _callee5, this, [[0, 23]]);
397
+ }, _callee5, this, [[0, 24]]);
396
398
  }));
397
399
  function scanCode(_x4, _x5) {
398
400
  return _scanCode.apply(this, arguments);
@@ -580,20 +582,52 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
580
582
  return _getCustomerWallet.apply(this, arguments);
581
583
  }
582
584
  return getCustomerWallet;
583
- }() // 加载准备配置
585
+ }()
584
586
  }, {
585
- key: "loadPrepareConfig",
587
+ key: "bestDiscount",
586
588
  value: function () {
587
- var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
588
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
589
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
590
+ var _this$store$productLi;
591
+ var newDiscountList, result;
589
592
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
590
593
  while (1) switch (_context8.prev = _context8.next) {
591
594
  case 0:
592
- _context8.prev = 0;
595
+ newDiscountList = this.store.originalDiscountList;
596
+ this.setDiscountList(newDiscountList);
597
+ if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
598
+ _context8.next = 6;
599
+ break;
600
+ }
601
+ result = this.calcDiscount(this.store.productList);
602
+ _context8.next = 6;
603
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
604
+ case 6:
605
+ _context8.next = 8;
606
+ return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
607
+ case 8:
608
+ case "end":
609
+ return _context8.stop();
610
+ }
611
+ }, _callee8, this);
612
+ }));
613
+ function bestDiscount() {
614
+ return _bestDiscount.apply(this, arguments);
615
+ }
616
+ return bestDiscount;
617
+ }() // 加载准备配置
618
+ }, {
619
+ key: "loadPrepareConfig",
620
+ value: function () {
621
+ var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
622
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
623
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
624
+ while (1) switch (_context9.prev = _context9.next) {
625
+ case 0:
626
+ _context9.prev = 0;
593
627
  customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
594
628
  // return
595
629
  // }
596
- _context8.next = 4;
630
+ _context9.next = 4;
597
631
  return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
598
632
  customer_id: customerId,
599
633
  action: 'create',
@@ -601,7 +635,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
601
635
  with_discount_card: 1
602
636
  });
603
637
  case 4:
604
- goodPassList = _context8.sent;
638
+ goodPassList = _context9.sent;
605
639
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
606
640
  return item.isScan;
607
641
  }); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
@@ -612,29 +646,30 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
612
646
  return !scanDiscountIds.includes(n.id);
613
647
  });
614
648
  newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
649
+ this.store.originalDiscountList = newDiscountList;
615
650
  this.setDiscountList(newDiscountList || []);
616
- if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
617
- _context8.next = 14;
651
+ if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
652
+ _context9.next = 15;
618
653
  break;
619
654
  }
620
655
  result = this.calcDiscount(this.store.productList);
621
- _context8.next = 14;
656
+ _context9.next = 15;
622
657
  return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
623
- case 14:
624
- _context8.next = 16;
658
+ case 15:
659
+ _context9.next = 17;
625
660
  return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
626
- case 16:
627
- _context8.next = 21;
661
+ case 17:
662
+ _context9.next = 22;
628
663
  break;
629
- case 18:
630
- _context8.prev = 18;
631
- _context8.t0 = _context8["catch"](0);
632
- console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
633
- case 21:
664
+ case 19:
665
+ _context9.prev = 19;
666
+ _context9.t0 = _context9["catch"](0);
667
+ console.error('[ShopDiscount] 加载准备配置出错:', _context9.t0);
668
+ case 22:
634
669
  case "end":
635
- return _context8.stop();
670
+ return _context9.stop();
636
671
  }
637
- }, _callee8, this, [[0, 18]]);
672
+ }, _callee9, this, [[0, 19]]);
638
673
  }));
639
674
  function loadPrepareConfig(_x8) {
640
675
  return _loadPrepareConfig.apply(this, arguments);
@@ -1,4 +1,4 @@
1
- import { DiscountModule } from '../../modules/Discount';
1
+ import { DiscountModule, Discount } from '../../modules/Discount';
2
2
  import { RulesModule } from '../../modules/Rules';
3
3
  export declare enum ShopDiscountHooks {
4
4
  onInited = "shopDiscount:onInited",
@@ -22,4 +22,5 @@ export interface ShopDiscountState {
22
22
  discount: DiscountModule | null;
23
23
  rules: RulesModule | null;
24
24
  productList: Record<string, any>[];
25
+ originalDiscountList: Discount[];
25
26
  }
@@ -30,3 +30,4 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
30
30
  clear(): Promise<void>;
31
31
  storeChange(): void;
32
32
  }
33
+ export type { Discount } from './types';
@@ -10,7 +10,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
10
10
  constructor(name?: string, version?: string);
11
11
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
12
  createOrder(params: CommitOrderParams['query']): {
13
- type: "appointment_booking" | "virtual";
13
+ type: "virtual" | "appointment_booking";
14
14
  platform: string;
15
15
  sales_channel: string;
16
16
  order_sales_channel: string;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Order/index.ts
@@ -25,6 +35,7 @@ module.exports = __toCommonJS(Order_exports);
25
35
  var import_BaseModule = require("../BaseModule");
26
36
  var import_utils = require("./utils");
27
37
  var import_utils2 = require("../Product/utils");
38
+ var import_dayjs = __toESM(require("dayjs"));
28
39
  var OrderModule = class extends import_BaseModule.BaseModule {
29
40
  constructor(name, version) {
30
41
  super(name, version);
@@ -143,6 +154,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
143
154
  orderData.bookings = [];
144
155
  orderData.relation_products = [];
145
156
  }
157
+ if (!params.order_id && !orderData.schedule_date) {
158
+ orderData.schedule_date = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
159
+ }
146
160
  console.log("[Order] 调用后端接口创建订单:", {
147
161
  url: "/order/checkout",
148
162
  orderType: orderData.type,
@@ -476,6 +476,48 @@ export interface OnSearchIdentificationCodeCompletedEventData {
476
476
  /** 搜索参数 */
477
477
  searchParams: SearchIdentificationCodeParams;
478
478
  }
479
+ /**
480
+ * 钱包初始化开始事件数据
481
+ */
482
+ export interface OnWalletInitializationStartedEventData {
483
+ /** 业务数据 */
484
+ businessData: WalletInitBusinessData;
485
+ /** 开始时间 */
486
+ startTime: number;
487
+ }
488
+ /**
489
+ * 钱包初始化完成事件数据
490
+ */
491
+ export interface OnWalletInitializationCompletedEventData {
492
+ /** 业务数据 */
493
+ businessData: WalletInitBusinessData;
494
+ /** 初始化结果 */
495
+ result: {
496
+ walletRecommendList: WalletRecommendItem[];
497
+ userIdentificationCodes: UserIdentificationCodeItem[];
498
+ };
499
+ /** 开始时间 */
500
+ startTime: number;
501
+ /** 结束时间 */
502
+ endTime: number;
503
+ /** 执行时长(毫秒) */
504
+ duration: number;
505
+ }
506
+ /**
507
+ * 钱包初始化失败事件数据
508
+ */
509
+ export interface OnWalletInitializationFailedEventData {
510
+ /** 业务数据 */
511
+ businessData: WalletInitBusinessData;
512
+ /** 错误信息 */
513
+ error: Error;
514
+ /** 开始时间 */
515
+ startTime: number;
516
+ /** 结束时间 */
517
+ endTime: number;
518
+ /** 执行时长(毫秒) */
519
+ duration: number;
520
+ }
479
521
  /**
480
522
  * 钱包支付事件枚举
481
523
  */
@@ -485,7 +527,10 @@ export declare enum WalletPassHooks {
485
527
  OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated",
486
528
  OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared",
487
529
  OnWalletCacheCleared = "wallet:onWalletCacheCleared",
488
- OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted"
530
+ OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted",
531
+ OnWalletInitializationStarted = "wallet:onWalletInitializationStarted",
532
+ OnWalletInitializationCompleted = "wallet:onWalletInitializationCompleted",
533
+ OnWalletInitializationFailed = "wallet:onWalletInitializationFailed"
489
534
  }
490
535
  /**
491
536
  * 支付钩子事件(统一接口)
@@ -69,6 +69,9 @@ var WalletPassHooks = /* @__PURE__ */ ((WalletPassHooks2) => {
69
69
  WalletPassHooks2["OnUserIdentificationCodesCleared"] = "wallet:onUserIdentificationCodesCleared";
70
70
  WalletPassHooks2["OnWalletCacheCleared"] = "wallet:onWalletCacheCleared";
71
71
  WalletPassHooks2["OnSearchIdentificationCodeCompleted"] = "wallet:onSearchIdentificationCodeCompleted";
72
+ WalletPassHooks2["OnWalletInitializationStarted"] = "wallet:onWalletInitializationStarted";
73
+ WalletPassHooks2["OnWalletInitializationCompleted"] = "wallet:onWalletInitializationCompleted";
74
+ WalletPassHooks2["OnWalletInitializationFailed"] = "wallet:onWalletInitializationFailed";
72
75
  return WalletPassHooks2;
73
76
  })(WalletPassHooks || {});
74
77
  var PaymentHooks = /* @__PURE__ */ ((PaymentHooks2) => {
@@ -88,11 +88,36 @@ var WalletPassPaymentImpl = class {
88
88
  * 内部生成参数,然后调用标准的初始化流程
89
89
  */
90
90
  async initializeWalletDataFromBusinessAsync(businessData) {
91
+ const startTime = Date.now();
92
+ this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationStarted, {
93
+ businessData,
94
+ startTime
95
+ });
91
96
  try {
92
97
  const walletParams = this.generateWalletParams(businessData);
93
- return await this.initializeWalletDataAsync(walletParams);
98
+ const result = await this.initializeWalletDataAsync(walletParams);
99
+ const endTime = Date.now();
100
+ const duration = endTime - startTime;
101
+ this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationCompleted, {
102
+ businessData,
103
+ result,
104
+ startTime,
105
+ endTime,
106
+ duration
107
+ });
108
+ console.log(`[WalletPass] 从业务数据初始化钱包数据成功,耗时: ${duration}ms`);
109
+ return result;
94
110
  } catch (error) {
95
- console.error("[WalletPass] 从业务数据初始化钱包数据失败:", error);
111
+ const endTime = Date.now();
112
+ const duration = endTime - startTime;
113
+ this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationFailed, {
114
+ businessData,
115
+ error,
116
+ startTime,
117
+ endTime,
118
+ duration
119
+ });
120
+ console.error(`[WalletPass] 从业务数据初始化钱包数据失败,耗时: ${duration}ms`, error);
96
121
  throw error;
97
122
  }
98
123
  }
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
111
111
  * 获取当前的客户搜索条件
112
112
  * @returns 当前搜索条件
113
113
  */
114
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
114
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
115
115
  /**
116
116
  * 获取客户列表状态(包含滚动加载相关状态)
117
117
  * @returns 客户状态
@@ -137,7 +137,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
137
137
  }
138
138
  }
139
139
  getProductListByOrder() {
140
- var _a;
140
+ var _a, _b, _c, _d, _e;
141
141
  if (!this.store.currentOrder) {
142
142
  return [];
143
143
  }
@@ -146,15 +146,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
146
146
  return pre + (item.amount || 0);
147
147
  }, 0);
148
148
  };
149
- const productList = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data.bookings.map(
149
+ const productList = ((_b = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data.bookings) == null ? void 0 : _b.map(
150
150
  (item) => ({
151
151
  product_id: item.product.product_id,
152
152
  product_variant_id: item.product.product_variant_id,
153
153
  quantity: item.product.num,
154
154
  selling_price: item.product.price - (item.product.discount_amount || 0) - getDiscountListAmount(item.product.discount_list)
155
155
  })
156
- );
157
- return productList;
156
+ )) || [];
157
+ const relationProducts = ((_e = (_d = (_c = this.store.currentOrder.order_info) == null ? void 0 : _c.original_order_data) == null ? void 0 : _d.relation_products) == null ? void 0 : _e.map((item) => ({
158
+ product_id: item.product_id,
159
+ product_variant_id: item.product_variant_id,
160
+ quantity: item.num,
161
+ selling_price: item.source_product_price
162
+ }))) || [];
163
+ return [...productList, ...relationProducts];
158
164
  }
159
165
  async initWalletData(params) {
160
166
  var _a, _b, _c;
@@ -902,6 +908,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
902
908
  * @throws 当前没有活跃订单时抛出错误
903
909
  */
904
910
  async addPaymentItemAsync(paymentItem) {
911
+ var _a, _b;
905
912
  try {
906
913
  if (!this.store.currentOrder) {
907
914
  throw (0, import_utils.createCheckoutError)(
@@ -924,12 +931,29 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
924
931
  paymentItem
925
932
  );
926
933
  console.log("[Checkout] 支付项添加成功");
927
- const currentOrderId = this.store.currentOrder.order_id;
928
- const isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
929
- console.log("[Checkout] 准备同步订单数据:", {
930
- 当前订单ID: currentOrderId,
931
- 是否为真实ID: isCurrentOrderReal
934
+ const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
935
+ console.log("[Checkout] EFTPOS 支付检查:", {
936
+ paymentCode: paymentItem.code,
937
+ paymentType: paymentItem.type,
938
+ isEftposPayment,
939
+ currentOrderSynced: this.store.isOrderSynced
932
940
  });
941
+ if (isEftposPayment) {
942
+ console.log("[Checkout] 检测到 EFTPOS 支付,立即同步订单到后端...");
943
+ try {
944
+ await this.syncOrderToBackendWithReturn(true);
945
+ console.log("[Checkout] EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
946
+ 订单ID: this.store.currentOrder.order_id,
947
+ 是否已同步: this.store.isOrderSynced
948
+ });
949
+ } catch (error) {
950
+ console.error("[Checkout] EFTPOS 支付后订单同步失败:", error);
951
+ await this.handleError(
952
+ new Error(`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`),
953
+ import_types.CheckoutErrorType.OrderCreationFailed
954
+ );
955
+ }
956
+ }
933
957
  await this.updateStateAmountToRemaining();
934
958
  await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
935
959
  orderUuid: this.store.currentOrder.uuid,
@@ -1486,10 +1510,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1486
1510
  this.store.currentOrder.uuid
1487
1511
  );
1488
1512
  const filteredPaymentItems = allPaymentItems.filter(
1489
- (payment) => !payment.voucher_id || payment.voucher_id.trim() === ""
1513
+ (payment) => !payment.voucher_id
1490
1514
  );
1491
1515
  const voucherItems = allPaymentItems.filter(
1492
- (payment) => payment.voucher_id && payment.voucher_id.trim() !== ""
1516
+ (payment) => payment.voucher_id
1493
1517
  );
1494
1518
  console.log("[Checkout] 支付项过滤结果:", {
1495
1519
  总支付项: allPaymentItems.length,
@@ -2017,12 +2041,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2017
2041
  false
2018
2042
  // 不包括已撤销的支付项
2019
2043
  );
2020
- const allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(
2044
+ const hasPaymentItems = currentPayments.length > 0;
2045
+ const allPaymentsHaveVoucherId = hasPaymentItems && currentPayments.every(
2021
2046
  (item) => item.status !== "voided" && item.voucher_id
2022
2047
  );
2023
- console.log("[Checkout] 支付项voucher_id检查:", {
2048
+ const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
2049
+ console.log("[Checkout] 自动同步订单条件检查:", {
2024
2050
  paymentCount: currentPayments.length,
2051
+ hasPaymentItems,
2025
2052
  allHaveVoucherId: allPaymentsHaveVoucherId,
2053
+ isOrderSynced: this.store.isOrderSynced,
2054
+ shouldAutoSync,
2055
+ reason: shouldAutoSync ? "支付完成,需要同步最终支付状态" : "跳过同步",
2026
2056
  paymentItems: currentPayments.map((p) => ({
2027
2057
  uuid: p.uuid,
2028
2058
  code: p.code,
@@ -2031,11 +2061,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2031
2061
  status: p.status
2032
2062
  }))
2033
2063
  });
2034
- if (allPaymentsHaveVoucherId) {
2035
- console.log("[Checkout] 所有支付项均为代金券类型,跳过订单同步");
2036
- } else {
2037
- console.log("[Checkout] 支付完成但订单未同步,开始同步订单到后端...");
2064
+ if (shouldAutoSync) {
2065
+ console.log("[Checkout] 满足自动同步条件,开始同步订单到后端...");
2038
2066
  await this.syncOrderToBackend();
2067
+ } else {
2068
+ if (!hasPaymentItems) {
2069
+ console.log("[Checkout] 没有支付项,跳过订单同步");
2070
+ } else if (allPaymentsHaveVoucherId) {
2071
+ console.log("[Checkout] 所有支付项均为代金券类型,跳过订单同步");
2072
+ }
2039
2073
  }
2040
2074
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
2041
2075
  orderUuid: this.store.currentOrder.uuid,
@@ -2098,7 +2132,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2098
2132
  * @returns 后端返回的真实订单ID
2099
2133
  */
2100
2134
  async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
2101
- var _a, _b, _c, _d;
2135
+ var _a, _b, _c, _d, _e;
2102
2136
  if (!this.store.localOrderData || !this.store.currentOrder) {
2103
2137
  throw new Error("缺少必要的订单数据,无法同步到后端");
2104
2138
  }
@@ -2198,7 +2232,38 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2198
2232
  } else {
2199
2233
  console.log("[Checkout] 创建新订单操作");
2200
2234
  }
2201
- const checkoutResponse = await this.order.createOrderByCheckout(orderParams);
2235
+ const startTime = Date.now();
2236
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitStart, {
2237
+ orderUuid: this.store.currentOrder.uuid,
2238
+ operation: isUpdateOperation ? "update" : "create",
2239
+ isManual,
2240
+ paymentItemCount: paymentItems.length,
2241
+ timestamp: startTime
2242
+ });
2243
+ let checkoutResponse;
2244
+ let submitSuccess = false;
2245
+ let submitError;
2246
+ try {
2247
+ checkoutResponse = await this.order.createOrderByCheckout(orderParams);
2248
+ submitSuccess = true;
2249
+ console.log("[Checkout] 下单接口调用成功");
2250
+ } catch (error) {
2251
+ submitSuccess = false;
2252
+ submitError = error instanceof Error ? error.message : String(error);
2253
+ console.error("[Checkout] 下单接口调用失败:", submitError);
2254
+ throw error;
2255
+ } finally {
2256
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitEnd, {
2257
+ success: submitSuccess,
2258
+ orderUuid: this.store.currentOrder.uuid,
2259
+ operation: isUpdateOperation ? "update" : "create",
2260
+ isManual,
2261
+ orderId: submitSuccess ? ((_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
2262
+ error: submitError,
2263
+ duration: Date.now() - startTime,
2264
+ timestamp: Date.now()
2265
+ });
2266
+ }
2202
2267
  console.log("[Checkout] 后端返回的响应数据:", {
2203
2268
  status: checkoutResponse == null ? void 0 : checkoutResponse.status,
2204
2269
  code: checkoutResponse == null ? void 0 : checkoutResponse.code,
@@ -2210,7 +2275,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2210
2275
  realOrderId = currentOrderId;
2211
2276
  console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
2212
2277
  } else {
2213
- let extractedOrderId = (_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id;
2278
+ let extractedOrderId = (_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id;
2214
2279
  if (!extractedOrderId) {
2215
2280
  extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
2216
2281
  }
@@ -2535,9 +2600,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2535
2600
  this.store.currentCustomer = void 0;
2536
2601
  this.store.lastError = void 0;
2537
2602
  this.store.cartItems = [];
2603
+ this.payment.wallet.clearAllCache();
2538
2604
  await this.setStatus(import_types.CheckoutStatus.Ready);
2539
2605
  await this.setStep(import_types.CheckoutStep.OrderConfirmation);
2540
- this.payment.wallet.clearAllCache();
2541
2606
  console.log("[Checkout] Store 状态重置完成");
2542
2607
  if (prevOrderInfo) {
2543
2608
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {