@pisell/pisellos 2.2.205 → 2.2.206

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 (42) hide show
  1. package/dist/modules/OpenData/index.d.ts +1 -0
  2. package/dist/modules/OpenData/index.js +21 -16
  3. package/dist/modules/Order/index.d.ts +9 -0
  4. package/dist/modules/Order/index.js +230 -145
  5. package/dist/modules/Order/types.d.ts +10 -0
  6. package/dist/modules/Order/utils.js +7 -5
  7. package/dist/server/index.d.ts +136 -0
  8. package/dist/server/index.js +2054 -781
  9. package/dist/server/modules/order/index.d.ts +7 -0
  10. package/dist/server/modules/order/index.js +375 -337
  11. package/dist/server/modules/order/types.d.ts +15 -0
  12. package/dist/server/modules/order/types.js +8 -0
  13. package/dist/server/utils/small-ticket.d.ts +69 -0
  14. package/dist/server/utils/small-ticket.js +528 -0
  15. package/dist/solution/BaseSales/index.d.ts +4 -2
  16. package/dist/solution/BaseSales/index.js +248 -188
  17. package/dist/solution/BookingByStep/index.d.ts +1 -1
  18. package/dist/solution/BookingTicket/index.d.ts +8 -1
  19. package/dist/solution/BookingTicket/index.js +443 -263
  20. package/dist/solution/BookingTicket/types.d.ts +2 -1
  21. package/dist/solution/BookingTicket/types.js +3 -1
  22. package/lib/modules/OpenData/index.d.ts +1 -0
  23. package/lib/modules/OpenData/index.js +6 -4
  24. package/lib/modules/Order/index.d.ts +9 -0
  25. package/lib/modules/Order/index.js +59 -3
  26. package/lib/modules/Order/types.d.ts +10 -0
  27. package/lib/modules/Order/utils.js +4 -3
  28. package/lib/server/index.d.ts +136 -0
  29. package/lib/server/index.js +822 -50
  30. package/lib/server/modules/order/index.d.ts +7 -0
  31. package/lib/server/modules/order/index.js +21 -7
  32. package/lib/server/modules/order/types.d.ts +15 -0
  33. package/lib/server/utils/small-ticket.d.ts +69 -0
  34. package/lib/server/utils/small-ticket.js +555 -0
  35. package/lib/solution/BaseSales/index.d.ts +4 -2
  36. package/lib/solution/BaseSales/index.js +47 -1
  37. package/lib/solution/BookingByStep/index.d.ts +1 -1
  38. package/lib/solution/BookingTicket/index.d.ts +8 -1
  39. package/lib/solution/BookingTicket/index.js +108 -1
  40. package/lib/solution/BookingTicket/types.d.ts +2 -1
  41. package/lib/solution/BookingTicket/types.js +5 -0
  42. package/package.json +1 -1
@@ -37,6 +37,7 @@ import { OrderModule } from "./modules/order";
37
37
  import { OrderHooks } from "./modules/order/types";
38
38
  import { filterOrders } from "./modules/order/utils/filterOrders";
39
39
  import { filterBookingsFromOrders, sortBookings } from "./modules/order/utils/filterBookings";
40
+ import { buildSmallTicketData, hasSmallTicketData } from "./utils/small-ticket";
40
41
 
41
42
  // 重新导出类型供外部使用
42
43
 
@@ -92,6 +93,8 @@ var Server = /*#__PURE__*/function () {
92
93
  _defineProperty(this, "bookingRemoteCache", new Map());
93
94
  _defineProperty(this, "BOOKING_REMOTE_CACHE_TTL_MS", 5 * 60 * 1000);
94
95
  _defineProperty(this, "BOOKING_REMOTE_CACHE_MAX_ENTRIES", 80);
96
+ _defineProperty(this, "salesSearchSubscribers", new Map());
97
+ _defineProperty(this, "deviceTaskActionsRegistered", false);
95
98
  _defineProperty(this, "floorPlanQuerySubscribers", new Map());
96
99
  // 模块注册表 - 定义所有可用的模块配置
97
100
  _defineProperty(this, "moduleRegistry", {
@@ -182,23 +185,22 @@ var Server = /*#__PURE__*/function () {
182
185
  while (1) switch (_context.prev = _context.next) {
183
186
  case 0:
184
187
  data = _ref.data, config = _ref.config;
185
- debugger;
186
- _context.next = 4;
188
+ _context.next = 3;
187
189
  return _this.getPaymentRouteModule();
188
- case 4:
190
+ case 3:
189
191
  payment = _context.sent;
190
- _context.next = 7;
192
+ _context.next = 6;
191
193
  return payment.getPayMethodListAsync({
192
194
  shouldFilter: (data === null || data === void 0 ? void 0 : data.filterPaymentMethods) === true || (config === null || config === void 0 ? void 0 : config.filterPaymentMethods) === true
193
195
  });
194
- case 7:
196
+ case 6:
195
197
  payMethods = _context.sent;
196
198
  return _context.abrupt("return", {
197
199
  code: 200,
198
200
  status: true,
199
201
  data: payMethods
200
202
  });
201
- case 9:
203
+ case 8:
202
204
  case "end":
203
205
  return _context.stop();
204
206
  }
@@ -447,6 +449,90 @@ var Server = /*#__PURE__*/function () {
447
449
  return _ref15.apply(this, arguments);
448
450
  };
449
451
  }());
452
+ /**
453
+ * 处理 sales 单模块搜索:请求透传后端,仅在 OS 层维护已返回订单号集合。
454
+ *
455
+ * @example
456
+ * await this.handleSalesSearchModule({ url: '/shop/es/search/sales', method: 'post', data: { keyword: 'A' } })
457
+ */
458
+ _defineProperty(this, "handleSalesSearchModule", /*#__PURE__*/function () {
459
+ var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref17) {
460
+ var data, config;
461
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
462
+ while (1) switch (_context7.prev = _context7.next) {
463
+ case 0:
464
+ data = _ref17.data, config = _ref17.config;
465
+ return _context7.abrupt("return", _this.handleSalesSearchRequest('single', '/shop/es/search/sales', data, config));
466
+ case 2:
467
+ case "end":
468
+ return _context7.stop();
469
+ }
470
+ }, _callee7);
471
+ }));
472
+ return function (_x7) {
473
+ return _ref18.apply(this, arguments);
474
+ };
475
+ }());
476
+ /**
477
+ * 处理 sales 聚合搜索:请求透传后端,仅订阅 sales 分组的已返回订单号。
478
+ *
479
+ * @example
480
+ * await this.handleSalesSearchAggregate({ url: '/shop/es/search', method: 'post', data: { modules: [] } })
481
+ */
482
+ _defineProperty(this, "handleSalesSearchAggregate", /*#__PURE__*/function () {
483
+ var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref19) {
484
+ var data, config;
485
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
486
+ while (1) switch (_context8.prev = _context8.next) {
487
+ case 0:
488
+ data = _ref19.data, config = _ref19.config;
489
+ return _context8.abrupt("return", _this.handleSalesSearchRequest('aggregate', '/shop/es/search', data, config));
490
+ case 2:
491
+ case "end":
492
+ return _context8.stop();
493
+ }
494
+ }, _callee8);
495
+ }));
496
+ return function (_x8) {
497
+ return _ref20.apply(this, arguments);
498
+ };
499
+ }());
500
+ /**
501
+ * 取消 sales 搜索订阅。
502
+ *
503
+ * @example
504
+ * await this.handleUnsubscribeSalesSearch({ data: { subscriberId: 'global-search-order' } } as any)
505
+ */
506
+ _defineProperty(this, "handleUnsubscribeSalesSearch", /*#__PURE__*/function () {
507
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref21) {
508
+ var data, _ref23, subscriberId;
509
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
510
+ while (1) switch (_context9.prev = _context9.next) {
511
+ case 0:
512
+ data = _ref21.data;
513
+ _ref23 = data || {}, subscriberId = _ref23.subscriberId;
514
+ if (subscriberId) {
515
+ _this.salesSearchSubscribers.delete(subscriberId);
516
+ _this.logInfo('handleUnsubscribeSalesSearch: 已移除订阅者', {
517
+ subscriberId: subscriberId,
518
+ remaining: _this.salesSearchSubscribers.size
519
+ });
520
+ }
521
+ return _context9.abrupt("return", {
522
+ code: 200,
523
+ message: 'ok',
524
+ status: true
525
+ });
526
+ case 4:
527
+ case "end":
528
+ return _context9.stop();
529
+ }
530
+ }, _callee9);
531
+ }));
532
+ return function (_x9) {
533
+ return _ref22.apply(this, arguments);
534
+ };
535
+ }());
450
536
  /**
451
537
  * 日历(compact_fields)场景下要直接在 SSE 层排除的订单类型:
452
538
  * 这些类型不会出现在日历上,拉取它们只会浪费带宽并增加前端过滤成本。
@@ -457,22 +543,22 @@ var Server = /*#__PURE__*/function () {
457
543
  * 今天:注册订阅者 + 本地数据筛选;非今天:清理订阅者 + 走真实 API
458
544
  */
459
545
  _defineProperty(this, "handleBookingList", /*#__PURE__*/function () {
460
- var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref17) {
461
- var url, method, data, config, queryPayload, _ref19, callback, subscriberId, useLocal, withFields, requestPayload, cacheKey;
462
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
463
- while (1) switch (_context7.prev = _context7.next) {
546
+ var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref24) {
547
+ var url, method, data, config, queryPayload, _ref26, callback, subscriberId, useLocal, withFields, requestPayload, cacheKey;
548
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
549
+ while (1) switch (_context10.prev = _context10.next) {
464
550
  case 0:
465
- url = _ref17.url, method = _ref17.method, data = _ref17.data, config = _ref17.config;
551
+ url = _ref24.url, method = _ref24.method, data = _ref24.data, config = _ref24.config;
466
552
  console.log('[Server] handleBookingList:', url, method, data, config);
467
553
  queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
468
- _ref19 = config || {}, callback = _ref19.callback, subscriberId = _ref19.subscriberId;
554
+ _ref26 = config || {}, callback = _ref26.callback, subscriberId = _ref26.subscriberId;
469
555
  useLocal = _this.shouldUseLocalBookingQuery(queryPayload);
470
556
  _this.logInfo('handleBookingList: 开始处理预约列表请求', {
471
557
  data: queryPayload,
472
558
  useLocal: useLocal
473
559
  });
474
560
  if (!useLocal) {
475
- _context7.next = 12;
561
+ _context10.next = 12;
476
562
  break;
477
563
  }
478
564
  if (subscriberId) {
@@ -488,7 +574,7 @@ var Server = /*#__PURE__*/function () {
488
574
  totalSubscribers: _this.bookingQuerySubscribers.size
489
575
  });
490
576
  }
491
- return _context7.abrupt("return", _this.computeBookingQueryResult(queryPayload));
577
+ return _context10.abrupt("return", _this.computeBookingQueryResult(queryPayload));
492
578
  case 12:
493
579
  if (subscriberId) {
494
580
  _this.bookingQuerySubscribers.delete(subscriberId);
@@ -514,15 +600,15 @@ var Server = /*#__PURE__*/function () {
514
600
  remaining: _this.bookingQuerySubscribers.size
515
601
  });
516
602
  }
517
- return _context7.abrupt("return", _this.fetchBookingListFromAPI(queryPayload));
603
+ return _context10.abrupt("return", _this.fetchBookingListFromAPI(queryPayload));
518
604
  case 16:
519
605
  case "end":
520
- return _context7.stop();
606
+ return _context10.stop();
521
607
  }
522
- }, _callee7);
608
+ }, _callee10);
523
609
  }));
524
- return function (_x7) {
525
- return _ref18.apply(this, arguments);
610
+ return function (_x10) {
611
+ return _ref25.apply(this, arguments);
526
612
  };
527
613
  }());
528
614
  /**
@@ -530,13 +616,13 @@ var Server = /*#__PURE__*/function () {
530
616
  * 转发到资源模块去
531
617
  */
532
618
  _defineProperty(this, "handleResourceList", /*#__PURE__*/function () {
533
- var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref20) {
619
+ var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref27) {
534
620
  var _this$resource;
535
621
  var url, method, data, config, list;
536
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
537
- while (1) switch (_context8.prev = _context8.next) {
622
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
623
+ while (1) switch (_context11.prev = _context11.next) {
538
624
  case 0:
539
- url = _ref20.url, method = _ref20.method, data = _ref20.data, config = _ref20.config;
625
+ url = _ref27.url, method = _ref27.method, data = _ref27.data, config = _ref27.config;
540
626
  console.log('[Server] handleResourceList:', url, method, data, config);
541
627
  list = (_this$resource = _this.resource) === null || _this$resource === void 0 ? void 0 : _this$resource.getResources({
542
628
  skip: (data === null || data === void 0 ? void 0 : data.skip) || 1,
@@ -545,7 +631,7 @@ var Server = /*#__PURE__*/function () {
545
631
  _this.logInfo('Server 劫持 Resource 接口:handleResourceList: 资源列表查询结果', {
546
632
  list: list
547
633
  });
548
- return _context8.abrupt("return", {
634
+ return _context11.abrupt("return", {
549
635
  code: 200,
550
636
  data: {
551
637
  list: list,
@@ -556,12 +642,12 @@ var Server = /*#__PURE__*/function () {
556
642
  });
557
643
  case 5:
558
644
  case "end":
559
- return _context8.stop();
645
+ return _context11.stop();
560
646
  }
561
- }, _callee8);
647
+ }, _callee11);
562
648
  }));
563
- return function (_x8) {
564
- return _ref21.apply(this, arguments);
649
+ return function (_x11) {
650
+ return _ref28.apply(this, arguments);
565
651
  };
566
652
  }());
567
653
  /**
@@ -579,35 +665,35 @@ var Server = /*#__PURE__*/function () {
579
665
  * @example 批量:GET /update/localOrder?order_ids=96971,96972,96973
580
666
  */
581
667
  _defineProperty(this, "handleUpdateLocalOrder", /*#__PURE__*/function () {
582
- var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref22) {
583
- var _ref24, _this$app;
668
+ var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref29) {
669
+ var _ref31, _this$app;
584
670
  var url, data, batchIds, rawOrderId, orderId, backendPath, _response$data, response, fresh, exists, _yield$_this$order$ov, overwritten, errorMessage;
585
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
586
- while (1) switch (_context9.prev = _context9.next) {
671
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
672
+ while (1) switch (_context12.prev = _context12.next) {
587
673
  case 0:
588
- url = _ref22.url, data = _ref22.data;
674
+ url = _ref29.url, data = _ref29.data;
589
675
  batchIds = _this.parseOrderIdsParam(url, data);
590
676
  if (!(batchIds.length > 0)) {
591
- _context9.next = 4;
677
+ _context12.next = 4;
592
678
  break;
593
679
  }
594
- return _context9.abrupt("return", _this.handleUpdateLocalOrdersBatch(batchIds));
680
+ return _context12.abrupt("return", _this.handleUpdateLocalOrdersBatch(batchIds));
595
681
  case 4:
596
- rawOrderId = (_ref24 = data && _typeof(data) === 'object' ? data.order_id : undefined) !== null && _ref24 !== void 0 ? _ref24 : _this.extractQueryParam(url, 'order_id');
682
+ rawOrderId = (_ref31 = data && _typeof(data) === 'object' ? data.order_id : undefined) !== null && _ref31 !== void 0 ? _ref31 : _this.extractQueryParam(url, 'order_id');
597
683
  orderId = rawOrderId === undefined || rawOrderId === null || rawOrderId === '' ? null : String(rawOrderId).trim();
598
684
  _this.logInfo('handleUpdateLocalOrder: 开始处理', {
599
685
  url: url,
600
686
  orderId: orderId
601
687
  });
602
688
  if (orderId) {
603
- _context9.next = 10;
689
+ _context12.next = 10;
604
690
  break;
605
691
  }
606
692
  _this.logWarning('handleUpdateLocalOrder: order_id 缺失', {
607
693
  url: url,
608
694
  data: data
609
695
  });
610
- return _context9.abrupt("return", {
696
+ return _context12.abrupt("return", {
611
697
  code: 400,
612
698
  status: false,
613
699
  message: 'order_id 缺失',
@@ -615,11 +701,11 @@ var Server = /*#__PURE__*/function () {
615
701
  });
616
702
  case 10:
617
703
  if (_this.order) {
618
- _context9.next = 13;
704
+ _context12.next = 13;
619
705
  break;
620
706
  }
621
707
  _this.logError('handleUpdateLocalOrder: Order 模块未注册');
622
- return _context9.abrupt("return", {
708
+ return _context12.abrupt("return", {
623
709
  code: 500,
624
710
  status: false,
625
711
  message: 'Order 模块未注册',
@@ -627,11 +713,11 @@ var Server = /*#__PURE__*/function () {
627
713
  });
628
714
  case 13:
629
715
  if ((_this$app = _this.app) !== null && _this$app !== void 0 && _this$app.request) {
630
- _context9.next = 16;
716
+ _context12.next = 16;
631
717
  break;
632
718
  }
633
719
  _this.logError('handleUpdateLocalOrder: app.request 不可用');
634
- return _context9.abrupt("return", {
720
+ return _context12.abrupt("return", {
635
721
  code: 500,
636
722
  status: false,
637
723
  message: 'app.request 不可用',
@@ -639,23 +725,23 @@ var Server = /*#__PURE__*/function () {
639
725
  });
640
726
  case 16:
641
727
  backendPath = "/shop/order/sales/".concat(encodeURIComponent(orderId), "?with%5B%5D=all");
642
- _context9.prev = 17;
643
- _context9.next = 20;
728
+ _context12.prev = 17;
729
+ _context12.next = 20;
644
730
  return _this.app.request.get(backendPath, undefined, {
645
731
  isShopApi: true
646
732
  });
647
733
  case 20:
648
- response = _context9.sent;
734
+ response = _context12.sent;
649
735
  fresh = (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : response;
650
736
  if (!(!fresh || _typeof(fresh) !== 'object' || fresh.order_id == null)) {
651
- _context9.next = 25;
737
+ _context12.next = 25;
652
738
  break;
653
739
  }
654
740
  _this.logError('handleUpdateLocalOrder: 后端返回订单为空', {
655
741
  orderId: orderId,
656
742
  backendPath: backendPath
657
743
  });
658
- return _context9.abrupt("return", {
744
+ return _context12.abrupt("return", {
659
745
  code: 500,
660
746
  status: false,
661
747
  message: '后端返回订单为空',
@@ -664,19 +750,19 @@ var Server = /*#__PURE__*/function () {
664
750
  case 25:
665
751
  exists = !!_this.order.getOrderByOrderId(orderId);
666
752
  if (!exists) {
667
- _context9.next = 33;
753
+ _context12.next = 33;
668
754
  break;
669
755
  }
670
- _context9.next = 29;
756
+ _context12.next = 29;
671
757
  return _this.order.overwriteExistingOrder(fresh);
672
758
  case 29:
673
- _yield$_this$order$ov = _context9.sent;
759
+ _yield$_this$order$ov = _context12.sent;
674
760
  overwritten = _yield$_this$order$ov.overwritten;
675
761
  _this.logInfo('handleUpdateLocalOrder: 覆盖完成', {
676
762
  orderId: orderId,
677
763
  overwritten: overwritten
678
764
  });
679
- return _context9.abrupt("return", {
765
+ return _context12.abrupt("return", {
680
766
  code: 200,
681
767
  status: true,
682
768
  message: '',
@@ -687,13 +773,13 @@ var Server = /*#__PURE__*/function () {
687
773
  }
688
774
  });
689
775
  case 33:
690
- _context9.next = 35;
776
+ _context12.next = 35;
691
777
  return _this.order.upsertOrdersFromRemote([fresh]);
692
778
  case 35:
693
779
  _this.logInfo('handleUpdateLocalOrder: 本地合并新订单完成', {
694
780
  orderId: orderId
695
781
  });
696
- return _context9.abrupt("return", {
782
+ return _context12.abrupt("return", {
697
783
  code: 200,
698
784
  status: true,
699
785
  message: '',
@@ -704,15 +790,15 @@ var Server = /*#__PURE__*/function () {
704
790
  }
705
791
  });
706
792
  case 39:
707
- _context9.prev = 39;
708
- _context9.t0 = _context9["catch"](17);
709
- errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
793
+ _context12.prev = 39;
794
+ _context12.t0 = _context12["catch"](17);
795
+ errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
710
796
  _this.logError('handleUpdateLocalOrder: 请求失败', {
711
797
  orderId: orderId,
712
798
  backendPath: backendPath,
713
799
  error: errorMessage
714
800
  });
715
- return _context9.abrupt("return", {
801
+ return _context12.abrupt("return", {
716
802
  code: 500,
717
803
  status: false,
718
804
  message: errorMessage,
@@ -720,66 +806,142 @@ var Server = /*#__PURE__*/function () {
720
806
  });
721
807
  case 44:
722
808
  case "end":
723
- return _context9.stop();
809
+ return _context12.stop();
724
810
  }
725
- }, _callee9, null, [[17, 39]]);
811
+ }, _callee12, null, [[17, 39]]);
726
812
  }));
727
- return function (_x9) {
728
- return _ref23.apply(this, arguments);
813
+ return function (_x12) {
814
+ return _ref30.apply(this, arguments);
729
815
  };
730
816
  }());
731
817
  _defineProperty(this, "handleOrderSalesCheckout", /*#__PURE__*/function () {
732
- var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref25) {
818
+ var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref32) {
733
819
  var data;
734
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
735
- while (1) switch (_context10.prev = _context10.next) {
820
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
821
+ while (1) switch (_context13.prev = _context13.next) {
736
822
  case 0:
737
- data = _ref25.data;
738
- return _context10.abrupt("return", _this.handleOrderCheckoutSubmit({
823
+ data = _ref32.data;
824
+ return _context13.abrupt("return", _this.handleOrderCheckoutSubmit({
739
825
  backendPath: '/shop/order/sales/checkout',
740
826
  data: data,
741
827
  title: 'handleOrderSalesCheckout'
742
828
  }));
743
829
  case 2:
744
830
  case "end":
745
- return _context10.stop();
831
+ return _context13.stop();
746
832
  }
747
- }, _callee10);
833
+ }, _callee13);
748
834
  }));
749
- return function (_x10) {
750
- return _ref26.apply(this, arguments);
835
+ return function (_x13) {
836
+ return _ref33.apply(this, arguments);
751
837
  };
752
838
  }());
753
839
  _defineProperty(this, "handleOrderCheckout", /*#__PURE__*/function () {
754
- var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref27) {
840
+ var _ref35 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref34) {
755
841
  var data;
756
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
757
- while (1) switch (_context11.prev = _context11.next) {
842
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
843
+ while (1) switch (_context14.prev = _context14.next) {
758
844
  case 0:
759
- data = _ref27.data;
760
- return _context11.abrupt("return", _this.handleOrderCheckoutSubmit({
845
+ data = _ref34.data;
846
+ return _context14.abrupt("return", _this.handleOrderCheckoutSubmit({
761
847
  backendPath: '/order/checkout',
762
848
  data: data,
763
849
  title: 'handleOrderCheckout'
764
850
  }));
765
851
  case 2:
766
852
  case "end":
767
- return _context11.stop();
853
+ return _context14.stop();
768
854
  }
769
- }, _callee11);
855
+ }, _callee14);
770
856
  }));
771
- return function (_x11) {
772
- return _ref28.apply(this, arguments);
857
+ return function (_x14) {
858
+ return _ref35.apply(this, arguments);
859
+ };
860
+ }());
861
+ _defineProperty(this, "handleLocalPrintOrder", /*#__PURE__*/function () {
862
+ var _ref37 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref36) {
863
+ var data, _need_sync, inputOrder, checkoutData, printableOrder, printResult, message;
864
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
865
+ while (1) switch (_context15.prev = _context15.next) {
866
+ case 0:
867
+ data = _ref36.data;
868
+ _context15.prev = 1;
869
+ inputOrder = data !== null && data !== void 0 && data.order && _typeof(data.order) === 'object' ? data.order : data;
870
+ if (!(!inputOrder || _typeof(inputOrder) !== 'object')) {
871
+ _context15.next = 5;
872
+ break;
873
+ }
874
+ return _context15.abrupt("return", {
875
+ code: 400,
876
+ status: false,
877
+ message: '订单数据不能为空',
878
+ data: {
879
+ printed: false,
880
+ order: null
881
+ }
882
+ });
883
+ case 5:
884
+ _context15.next = 7;
885
+ return _this.ensureCheckoutOrderNumbers(_objectSpread(_objectSpread({}, inputOrder), {}, {
886
+ small_ticket_data_flag: 1
887
+ }), 'handleLocalPrintOrder');
888
+ case 7:
889
+ checkoutData = _context15.sent;
890
+ printableOrder = _objectSpread(_objectSpread({}, checkoutData), {}, {
891
+ need_sync: (_need_sync = checkoutData.need_sync) !== null && _need_sync !== void 0 ? _need_sync : 1
892
+ });
893
+ _context15.next = 11;
894
+ return _this.dispatchLocalReceiptPrint({
895
+ checkoutData: checkoutData,
896
+ order: printableOrder,
897
+ response: null,
898
+ requireFullyPaid: false
899
+ });
900
+ case 11:
901
+ printResult = _context15.sent;
902
+ return _context15.abrupt("return", {
903
+ code: 200,
904
+ status: true,
905
+ message: '',
906
+ data: {
907
+ printed: printResult.printed,
908
+ order: printResult.order
909
+ }
910
+ });
911
+ case 15:
912
+ _context15.prev = 15;
913
+ _context15.t0 = _context15["catch"](1);
914
+ message = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
915
+ _this.logError('handleLocalPrintOrder: 本地打印小票失败', {
916
+ error: message
917
+ });
918
+ return _context15.abrupt("return", {
919
+ code: 500,
920
+ status: false,
921
+ message: message,
922
+ data: {
923
+ printed: false,
924
+ order: null
925
+ }
926
+ });
927
+ case 20:
928
+ case "end":
929
+ return _context15.stop();
930
+ }
931
+ }, _callee15, null, [[1, 15]]);
932
+ }));
933
+ return function (_x15) {
934
+ return _ref37.apply(this, arguments);
773
935
  };
774
936
  }());
775
937
  _defineProperty(this, "handleOrderSalesDetail", /*#__PURE__*/function () {
776
- var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref29) {
938
+ var _ref39 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(_ref38) {
777
939
  var _this$app2;
778
940
  var url, data, path, requestPath, lookup, localOrder, backendPath, _response$data2, response, fresh, savedOrder, errorMessage;
779
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
780
- while (1) switch (_context12.prev = _context12.next) {
941
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
942
+ while (1) switch (_context16.prev = _context16.next) {
781
943
  case 0:
782
- url = _ref29.url, data = _ref29.data, path = _ref29.path;
944
+ url = _ref38.url, data = _ref38.data, path = _ref38.path;
783
945
  requestPath = _this.parseRequestPath(url, path);
784
946
  lookup = _this.extractOrderSalesDetailLookup(requestPath);
785
947
  _this.logInfo('handleOrderSalesDetail: 开始处理', {
@@ -788,14 +950,14 @@ var Server = /*#__PURE__*/function () {
788
950
  lookup: lookup
789
951
  });
790
952
  if (lookup) {
791
- _context12.next = 7;
953
+ _context16.next = 7;
792
954
  break;
793
955
  }
794
956
  _this.logWarning('handleOrderSalesDetail: lookup 缺失', {
795
957
  url: url,
796
958
  path: requestPath
797
959
  });
798
- return _context12.abrupt("return", {
960
+ return _context16.abrupt("return", {
799
961
  code: 400,
800
962
  status: false,
801
963
  message: '订单 lookup 缺失',
@@ -803,11 +965,11 @@ var Server = /*#__PURE__*/function () {
803
965
  });
804
966
  case 7:
805
967
  if (_this.order) {
806
- _context12.next = 10;
968
+ _context16.next = 10;
807
969
  break;
808
970
  }
809
971
  _this.logError('handleOrderSalesDetail: Order 模块未注册');
810
- return _context12.abrupt("return", {
972
+ return _context16.abrupt("return", {
811
973
  code: 500,
812
974
  status: false,
813
975
  message: 'Order 模块未注册',
@@ -815,21 +977,21 @@ var Server = /*#__PURE__*/function () {
815
977
  });
816
978
  case 10:
817
979
  if (_this.shouldForceRemoteSalesDetail(data)) {
818
- _context12.next = 17;
980
+ _context16.next = 17;
819
981
  break;
820
982
  }
821
- _context12.next = 13;
983
+ _context16.next = 13;
822
984
  return _this.order.getLocalOrderByLookup(lookup);
823
985
  case 13:
824
- localOrder = _context12.sent;
986
+ localOrder = _context16.sent;
825
987
  if (!localOrder) {
826
- _context12.next = 17;
988
+ _context16.next = 17;
827
989
  break;
828
990
  }
829
991
  _this.logInfo('handleOrderSalesDetail: 命中本地订单', {
830
992
  lookup: lookup
831
993
  });
832
- return _context12.abrupt("return", {
994
+ return _context16.abrupt("return", {
833
995
  code: 200,
834
996
  status: true,
835
997
  message: '',
@@ -837,11 +999,11 @@ var Server = /*#__PURE__*/function () {
837
999
  });
838
1000
  case 17:
839
1001
  if ((_this$app2 = _this.app) !== null && _this$app2 !== void 0 && _this$app2.request) {
840
- _context12.next = 20;
1002
+ _context16.next = 20;
841
1003
  break;
842
1004
  }
843
1005
  _this.logError('handleOrderSalesDetail: app.request 不可用');
844
- return _context12.abrupt("return", {
1006
+ return _context16.abrupt("return", {
845
1007
  code: 500,
846
1008
  status: false,
847
1009
  message: 'app.request 不可用',
@@ -849,8 +1011,8 @@ var Server = /*#__PURE__*/function () {
849
1011
  });
850
1012
  case 20:
851
1013
  backendPath = _this.buildOrderSalesDetailBackendPath(lookup, data);
852
- _context12.prev = 21;
853
- _context12.next = 24;
1014
+ _context16.prev = 21;
1015
+ _context16.next = 24;
854
1016
  return _this.app.request.get(backendPath, {
855
1017
  lookup_mode: 'multi'
856
1018
  }, {
@@ -858,38 +1020,38 @@ var Server = /*#__PURE__*/function () {
858
1020
  customToast: function customToast() {}
859
1021
  });
860
1022
  case 24:
861
- response = _context12.sent;
1023
+ response = _context16.sent;
862
1024
  fresh = (_response$data2 = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data2 !== void 0 ? _response$data2 : response;
863
1025
  if (!(!fresh || _typeof(fresh) !== 'object' || fresh.order_id == null)) {
864
- _context12.next = 29;
1026
+ _context16.next = 29;
865
1027
  break;
866
1028
  }
867
1029
  _this.logInfo('handleOrderSalesDetail: 后端返回订单为空', {
868
1030
  lookup: lookup,
869
1031
  backendPath: backendPath
870
1032
  });
871
- return _context12.abrupt("return", {
1033
+ return _context16.abrupt("return", {
872
1034
  code: 500,
873
1035
  status: false,
874
1036
  message: '后端返回订单为空',
875
1037
  data: null
876
1038
  });
877
1039
  case 29:
878
- _context12.next = 31;
1040
+ _context16.next = 31;
879
1041
  return _this.order.upsertOrdersFromRemote([fresh]);
880
1042
  case 31:
881
- _context12.next = 33;
1043
+ _context16.next = 33;
882
1044
  return _this.order.getLocalOrderByLookup(lookup);
883
1045
  case 33:
884
- savedOrder = _context12.sent;
1046
+ savedOrder = _context16.sent;
885
1047
  if (savedOrder) {
886
- _context12.next = 37;
1048
+ _context16.next = 37;
887
1049
  break;
888
1050
  }
889
1051
  _this.logError('handleOrderSalesDetail: 订单写入后回读失败', {
890
1052
  lookup: lookup
891
1053
  });
892
- return _context12.abrupt("return", {
1054
+ return _context16.abrupt("return", {
893
1055
  code: 500,
894
1056
  status: false,
895
1057
  message: '订单写入后回读失败',
@@ -899,22 +1061,22 @@ var Server = /*#__PURE__*/function () {
899
1061
  _this.logInfo('handleOrderSalesDetail: 远端订单已同步到本地', {
900
1062
  lookup: lookup
901
1063
  });
902
- return _context12.abrupt("return", {
1064
+ return _context16.abrupt("return", {
903
1065
  code: 200,
904
1066
  status: true,
905
1067
  message: '',
906
1068
  data: savedOrder
907
1069
  });
908
1070
  case 41:
909
- _context12.prev = 41;
910
- _context12.t0 = _context12["catch"](21);
911
- errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
1071
+ _context16.prev = 41;
1072
+ _context16.t0 = _context16["catch"](21);
1073
+ errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
912
1074
  _this.logError('handleOrderSalesDetail: 请求失败', {
913
1075
  lookup: lookup,
914
1076
  backendPath: backendPath,
915
1077
  error: errorMessage
916
1078
  });
917
- return _context12.abrupt("return", {
1079
+ return _context16.abrupt("return", {
918
1080
  code: 500,
919
1081
  status: false,
920
1082
  message: errorMessage,
@@ -922,28 +1084,28 @@ var Server = /*#__PURE__*/function () {
922
1084
  });
923
1085
  case 46:
924
1086
  case "end":
925
- return _context12.stop();
1087
+ return _context16.stop();
926
1088
  }
927
- }, _callee12, null, [[21, 41]]);
1089
+ }, _callee16, null, [[21, 41]]);
928
1090
  }));
929
- return function (_x12) {
930
- return _ref30.apply(this, arguments);
1091
+ return function (_x16) {
1092
+ return _ref39.apply(this, arguments);
931
1093
  };
932
1094
  }());
933
1095
  /**
934
1096
  * GET /shop/schedule/floor-plan* 前缀路由:读本地 store;支持 subscriberId + callback 订阅更新
935
1097
  */
936
1098
  _defineProperty(this, "handleFloorPlanGet", /*#__PURE__*/function () {
937
- var _ref32 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref31) {
938
- var url, data, config, routePath, base, path, _subscriberId, _ref33, callback, subscriberId, ctx;
939
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
940
- while (1) switch (_context13.prev = _context13.next) {
1099
+ var _ref41 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref40) {
1100
+ var url, data, config, routePath, base, path, _subscriberId, _ref42, callback, subscriberId, ctx;
1101
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1102
+ while (1) switch (_context17.prev = _context17.next) {
941
1103
  case 0:
942
- url = _ref31.url, data = _ref31.data, config = _ref31.config, routePath = _ref31.path;
1104
+ url = _ref40.url, data = _ref40.data, config = _ref40.config, routePath = _ref40.path;
943
1105
  base = '/shop/schedule/floor-plan';
944
1106
  path = _this.parseRequestPath(url, routePath);
945
1107
  if (!(path === "".concat(base, "/unsubscribe"))) {
946
- _context13.next = 7;
1108
+ _context17.next = 7;
947
1109
  break;
948
1110
  }
949
1111
  _subscriberId = data === null || data === void 0 ? void 0 : data.subscriberId;
@@ -954,19 +1116,19 @@ var Server = /*#__PURE__*/function () {
954
1116
  remaining: _this.floorPlanQuerySubscribers.size
955
1117
  });
956
1118
  }
957
- return _context13.abrupt("return", {
1119
+ return _context17.abrupt("return", {
958
1120
  code: 200,
959
1121
  message: 'ok',
960
1122
  status: true
961
1123
  });
962
1124
  case 7:
963
- _ref33 = config || {}, callback = _ref33.callback, subscriberId = _ref33.subscriberId;
1125
+ _ref42 = config || {}, callback = _ref42.callback, subscriberId = _ref42.subscriberId;
964
1126
  ctx = _this.resolveFloorPlanQueryContext(path, base);
965
1127
  if (ctx) {
966
- _context13.next = 11;
1128
+ _context17.next = 11;
967
1129
  break;
968
1130
  }
969
- return _context13.abrupt("return", {
1131
+ return _context17.abrupt("return", {
970
1132
  status: false,
971
1133
  code: 404,
972
1134
  message: 'Not Found',
@@ -984,28 +1146,28 @@ var Server = /*#__PURE__*/function () {
984
1146
  total: _this.floorPlanQuerySubscribers.size
985
1147
  });
986
1148
  }
987
- return _context13.abrupt("return", _this.computeFloorPlanQueryResult(ctx));
1149
+ return _context17.abrupt("return", _this.computeFloorPlanQueryResult(ctx));
988
1150
  case 13:
989
1151
  case "end":
990
- return _context13.stop();
1152
+ return _context17.stop();
991
1153
  }
992
- }, _callee13);
1154
+ }, _callee17);
993
1155
  }));
994
- return function (_x13) {
995
- return _ref32.apply(this, arguments);
1156
+ return function (_x17) {
1157
+ return _ref41.apply(this, arguments);
996
1158
  };
997
1159
  }());
998
1160
  /**
999
1161
  * 取消预约列表查询订阅(HTTP 路由入口)
1000
1162
  */
1001
1163
  _defineProperty(this, "handleUnsubscribeBookingQuery", /*#__PURE__*/function () {
1002
- var _ref35 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(_ref34) {
1003
- var data, _ref36, subscriberId;
1004
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1005
- while (1) switch (_context14.prev = _context14.next) {
1164
+ var _ref44 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(_ref43) {
1165
+ var data, _ref45, subscriberId;
1166
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1167
+ while (1) switch (_context18.prev = _context18.next) {
1006
1168
  case 0:
1007
- data = _ref34.data;
1008
- _ref36 = data || {}, subscriberId = _ref36.subscriberId;
1169
+ data = _ref43.data;
1170
+ _ref45 = data || {}, subscriberId = _ref45.subscriberId;
1009
1171
  if (subscriberId) {
1010
1172
  _this.bookingQuerySubscribers.delete(subscriberId);
1011
1173
  _this.bookingRemoteQuerySubscribers.delete(subscriberId);
@@ -1015,19 +1177,19 @@ var Server = /*#__PURE__*/function () {
1015
1177
  remainingRemote: _this.bookingRemoteQuerySubscribers.size
1016
1178
  });
1017
1179
  }
1018
- return _context14.abrupt("return", {
1180
+ return _context18.abrupt("return", {
1019
1181
  code: 200,
1020
1182
  message: 'ok',
1021
1183
  status: true
1022
1184
  });
1023
1185
  case 4:
1024
1186
  case "end":
1025
- return _context14.stop();
1187
+ return _context18.stop();
1026
1188
  }
1027
- }, _callee14);
1189
+ }, _callee18);
1028
1190
  }));
1029
- return function (_x14) {
1030
- return _ref35.apply(this, arguments);
1191
+ return function (_x18) {
1192
+ return _ref44.apply(this, arguments);
1031
1193
  };
1032
1194
  }());
1033
1195
  /**
@@ -1035,13 +1197,13 @@ var Server = /*#__PURE__*/function () {
1035
1197
  * 通过餐牌ID列表获取所有相关日程的时间段点
1036
1198
  */
1037
1199
  _defineProperty(this, "handleGetScheduleTimePoints", /*#__PURE__*/function () {
1038
- var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref37) {
1200
+ var _ref47 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(_ref46) {
1039
1201
  var _menu_list_ids$length;
1040
1202
  var url, method, data, config, menu_list_ids, _menu_list_ids$length2, menuList, scheduleIds, scheduleList, timePoints, errorMessage;
1041
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1042
- while (1) switch (_context15.prev = _context15.next) {
1203
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1204
+ while (1) switch (_context19.prev = _context19.next) {
1043
1205
  case 0:
1044
- url = _ref37.url, method = _ref37.method, data = _ref37.data, config = _ref37.config;
1206
+ url = _ref46.url, method = _ref46.method, data = _ref46.data, config = _ref46.config;
1045
1207
  console.log('[Server] handleGetScheduleTimePoints:', url, method, data, config);
1046
1208
  menu_list_ids = data.menu_list_ids;
1047
1209
  _this.logInfo('handleGetScheduleTimePoints 开始处理', {
@@ -1051,12 +1213,12 @@ var Server = /*#__PURE__*/function () {
1051
1213
 
1052
1214
  // 检查必要的模块是否已注册
1053
1215
  if (_this.menu) {
1054
- _context15.next = 8;
1216
+ _context19.next = 8;
1055
1217
  break;
1056
1218
  }
1057
1219
  console.error('[Server] Menu 模块未注册');
1058
1220
  _this.logError('handleGetScheduleTimePoints: Menu 模块未注册');
1059
- return _context15.abrupt("return", {
1221
+ return _context19.abrupt("return", {
1060
1222
  code: 500,
1061
1223
  message: 'Menu 模块未注册',
1062
1224
  data: [],
@@ -1064,12 +1226,12 @@ var Server = /*#__PURE__*/function () {
1064
1226
  });
1065
1227
  case 8:
1066
1228
  if (_this.schedule) {
1067
- _context15.next = 12;
1229
+ _context19.next = 12;
1068
1230
  break;
1069
1231
  }
1070
1232
  console.error('[Server] Schedule 模块未注册');
1071
1233
  _this.logError('handleGetScheduleTimePoints: Schedule 模块未注册');
1072
- return _context15.abrupt("return", {
1234
+ return _context19.abrupt("return", {
1073
1235
  code: 500,
1074
1236
  message: 'Schedule 模块未注册',
1075
1237
  data: [],
@@ -1077,7 +1239,7 @@ var Server = /*#__PURE__*/function () {
1077
1239
  });
1078
1240
  case 12:
1079
1241
  if (!(!menu_list_ids || !Array.isArray(menu_list_ids) || menu_list_ids.length === 0)) {
1080
- _context15.next = 16;
1242
+ _context19.next = 16;
1081
1243
  break;
1082
1244
  }
1083
1245
  console.error('[Server] menu_list_ids 参数无效');
@@ -1085,14 +1247,14 @@ var Server = /*#__PURE__*/function () {
1085
1247
  menuListIdsCount: (_menu_list_ids$length2 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length2 !== void 0 ? _menu_list_ids$length2 : 0,
1086
1248
  menu_list_ids: menu_list_ids
1087
1249
  });
1088
- return _context15.abrupt("return", {
1250
+ return _context19.abrupt("return", {
1089
1251
  code: 400,
1090
1252
  message: 'menu_list_ids 参数无效',
1091
1253
  data: [],
1092
1254
  status: false
1093
1255
  });
1094
1256
  case 16:
1095
- _context15.prev = 16;
1257
+ _context19.prev = 16;
1096
1258
  // 1. 获取餐牌列表
1097
1259
  menuList = _this.menu.getMenuByIds(menu_list_ids);
1098
1260
  console.log("[Server] \u627E\u5230 ".concat(menuList.length, " \u4E2A\u9910\u724C"));
@@ -1110,13 +1272,13 @@ var Server = /*#__PURE__*/function () {
1110
1272
  scheduleCount: scheduleIds.length
1111
1273
  });
1112
1274
  if (!(scheduleIds.length === 0)) {
1113
- _context15.next = 26;
1275
+ _context19.next = 26;
1114
1276
  break;
1115
1277
  }
1116
1278
  _this.logInfo('handleGetScheduleTimePoints: 没有找到相关日程', {
1117
1279
  menuListIdsCount: menu_list_ids.length
1118
1280
  });
1119
- return _context15.abrupt("return", {
1281
+ return _context19.abrupt("return", {
1120
1282
  code: 200,
1121
1283
  message: '没有找到相关日程',
1122
1284
  data: [],
@@ -1140,22 +1302,22 @@ var Server = /*#__PURE__*/function () {
1140
1302
  scheduleCount: scheduleList.length,
1141
1303
  timePointCount: timePoints.length
1142
1304
  });
1143
- return _context15.abrupt("return", {
1305
+ return _context19.abrupt("return", {
1144
1306
  code: 200,
1145
1307
  message: '获取成功',
1146
1308
  data: timePoints,
1147
1309
  status: true
1148
1310
  });
1149
1311
  case 35:
1150
- _context15.prev = 35;
1151
- _context15.t0 = _context15["catch"](16);
1152
- errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : '未知错误';
1153
- console.error('[Server] 获取日程时间点失败:', _context15.t0);
1312
+ _context19.prev = 35;
1313
+ _context19.t0 = _context19["catch"](16);
1314
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : '未知错误';
1315
+ console.error('[Server] 获取日程时间点失败:', _context19.t0);
1154
1316
  _this.logError('handleGetScheduleTimePoints: 获取日程时间点失败', {
1155
1317
  menuListIdsCount: menu_list_ids.length,
1156
1318
  error: errorMessage
1157
1319
  });
1158
- return _context15.abrupt("return", {
1320
+ return _context19.abrupt("return", {
1159
1321
  code: 500,
1160
1322
  message: "\u83B7\u53D6\u5931\u8D25: ".concat(errorMessage),
1161
1323
  data: [],
@@ -1163,12 +1325,12 @@ var Server = /*#__PURE__*/function () {
1163
1325
  });
1164
1326
  case 41:
1165
1327
  case "end":
1166
- return _context15.stop();
1328
+ return _context19.stop();
1167
1329
  }
1168
- }, _callee15, null, [[16, 35]]);
1330
+ }, _callee19, null, [[16, 35]]);
1169
1331
  }));
1170
- return function (_x15) {
1171
- return _ref38.apply(this, arguments);
1332
+ return function (_x19) {
1333
+ return _ref47.apply(this, arguments);
1172
1334
  };
1173
1335
  }());
1174
1336
  this.core = core;
@@ -1265,10 +1427,10 @@ var Server = /*#__PURE__*/function () {
1265
1427
  }, {
1266
1428
  key: "registerModuleWithRoutes",
1267
1429
  value: (function () {
1268
- var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(module, options, moduleName) {
1430
+ var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(module, options, moduleName) {
1269
1431
  var routes;
1270
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1271
- while (1) switch (_context16.prev = _context16.next) {
1432
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1433
+ while (1) switch (_context20.prev = _context20.next) {
1272
1434
  case 0:
1273
1435
  this.logInfo("\u5F00\u59CB\u6CE8\u518C\u6A21\u5757: ".concat(moduleName), {
1274
1436
  moduleName: moduleName,
@@ -1276,7 +1438,7 @@ var Server = /*#__PURE__*/function () {
1276
1438
  });
1277
1439
 
1278
1440
  // 注册模块到 Core
1279
- _context16.next = 3;
1441
+ _context20.next = 3;
1280
1442
  return this.core.registerModule(module, options);
1281
1443
  case 3:
1282
1444
  console.log("[Server] \u2705 ".concat(moduleName, " \u6A21\u5757\u5DF2\u6CE8\u518C"));
@@ -1297,11 +1459,11 @@ var Server = /*#__PURE__*/function () {
1297
1459
  }
1298
1460
  case 6:
1299
1461
  case "end":
1300
- return _context16.stop();
1462
+ return _context20.stop();
1301
1463
  }
1302
- }, _callee16, this);
1464
+ }, _callee20, this);
1303
1465
  }));
1304
- function registerModuleWithRoutes(_x16, _x17, _x18) {
1466
+ function registerModuleWithRoutes(_x20, _x21, _x22) {
1305
1467
  return _registerModuleWithRoutes.apply(this, arguments);
1306
1468
  }
1307
1469
  return registerModuleWithRoutes;
@@ -1314,10 +1476,10 @@ var Server = /*#__PURE__*/function () {
1314
1476
  }, {
1315
1477
  key: "registerModuleByName",
1316
1478
  value: (function () {
1317
- var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(moduleConfig) {
1479
+ var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(moduleConfig) {
1318
1480
  var moduleName, shouldPreload, customConfig, registryConfig, ModuleClass, moduleInstance, moduleOptions;
1319
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1320
- while (1) switch (_context17.prev = _context17.next) {
1481
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1482
+ while (1) switch (_context21.prev = _context21.next) {
1321
1483
  case 0:
1322
1484
  // 解析配置
1323
1485
  moduleName = typeof moduleConfig === 'string' ? moduleConfig : moduleConfig.name;
@@ -1332,7 +1494,7 @@ var Server = /*#__PURE__*/function () {
1332
1494
  // 查找模块配置
1333
1495
  registryConfig = this.moduleRegistry[moduleName];
1334
1496
  if (registryConfig) {
1335
- _context17.next = 8;
1497
+ _context21.next = 8;
1336
1498
  break;
1337
1499
  }
1338
1500
  this.logError("\u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
@@ -1346,7 +1508,7 @@ var Server = /*#__PURE__*/function () {
1346
1508
  moduleOptions = _objectSpread({
1347
1509
  store: _objectSpread({}, registryConfig.defaultStore)
1348
1510
  }, customConfig); // 注册模块和路由
1349
- _context17.next = 13;
1511
+ _context21.next = 13;
1350
1512
  return this.registerModuleWithRoutes(moduleInstance, moduleOptions, moduleName.charAt(0).toUpperCase() + moduleName.slice(1));
1351
1513
  case 13:
1352
1514
  // 保存模块实例
@@ -1356,18 +1518,18 @@ var Server = /*#__PURE__*/function () {
1356
1518
  shouldPreload: shouldPreload,
1357
1519
  version: registryConfig.version
1358
1520
  });
1359
- return _context17.abrupt("return", {
1521
+ return _context21.abrupt("return", {
1360
1522
  module: moduleInstance,
1361
1523
  config: registryConfig,
1362
1524
  shouldPreload: shouldPreload
1363
1525
  });
1364
1526
  case 16:
1365
1527
  case "end":
1366
- return _context17.stop();
1528
+ return _context21.stop();
1367
1529
  }
1368
- }, _callee17, this);
1530
+ }, _callee21, this);
1369
1531
  }));
1370
- function registerModuleByName(_x19) {
1532
+ function registerModuleByName(_x23) {
1371
1533
  return _registerModuleByName.apply(this, arguments);
1372
1534
  }
1373
1535
  return registerModuleByName;
@@ -1380,10 +1542,10 @@ var Server = /*#__PURE__*/function () {
1380
1542
  }, {
1381
1543
  key: "registerModules",
1382
1544
  value: (function () {
1383
- var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(moduleConfigs) {
1545
+ var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(moduleConfigs) {
1384
1546
  var configs, registeredModules, _iterator2, _step2, config, configName, result, errorMessage;
1385
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1386
- while (1) switch (_context18.prev = _context18.next) {
1547
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1548
+ while (1) switch (_context22.prev = _context22.next) {
1387
1549
  case 0:
1388
1550
  console.log('[Server] 开始注册模块...');
1389
1551
 
@@ -1395,47 +1557,47 @@ var Server = /*#__PURE__*/function () {
1395
1557
  });
1396
1558
  registeredModules = [];
1397
1559
  _iterator2 = _createForOfIteratorHelper(configs);
1398
- _context18.prev = 5;
1560
+ _context22.prev = 5;
1399
1561
  _iterator2.s();
1400
1562
  case 7:
1401
1563
  if ((_step2 = _iterator2.n()).done) {
1402
- _context18.next = 25;
1564
+ _context22.next = 25;
1403
1565
  break;
1404
1566
  }
1405
1567
  config = _step2.value;
1406
1568
  configName = typeof config === 'string' ? config : config.name;
1407
- _context18.prev = 10;
1408
- _context18.next = 13;
1569
+ _context22.prev = 10;
1570
+ _context22.next = 13;
1409
1571
  return this.registerModuleByName(config);
1410
1572
  case 13:
1411
- result = _context18.sent;
1573
+ result = _context22.sent;
1412
1574
  registeredModules.push(result);
1413
- _context18.next = 23;
1575
+ _context22.next = 23;
1414
1576
  break;
1415
1577
  case 17:
1416
- _context18.prev = 17;
1417
- _context18.t0 = _context18["catch"](10);
1418
- errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1578
+ _context22.prev = 17;
1579
+ _context22.t0 = _context22["catch"](10);
1580
+ errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1419
1581
  this.logError("\u6A21\u5757\u6CE8\u518C\u5931\u8D25: ".concat(configName), {
1420
1582
  moduleName: configName,
1421
1583
  error: errorMessage
1422
1584
  });
1423
- console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context18.t0);
1424
- throw _context18.t0;
1585
+ console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context22.t0);
1586
+ throw _context22.t0;
1425
1587
  case 23:
1426
- _context18.next = 7;
1588
+ _context22.next = 7;
1427
1589
  break;
1428
1590
  case 25:
1429
- _context18.next = 30;
1591
+ _context22.next = 30;
1430
1592
  break;
1431
1593
  case 27:
1432
- _context18.prev = 27;
1433
- _context18.t1 = _context18["catch"](5);
1434
- _iterator2.e(_context18.t1);
1594
+ _context22.prev = 27;
1595
+ _context22.t1 = _context22["catch"](5);
1596
+ _iterator2.e(_context22.t1);
1435
1597
  case 30:
1436
- _context18.prev = 30;
1598
+ _context22.prev = 30;
1437
1599
  _iterator2.f();
1438
- return _context18.finish(30);
1600
+ return _context22.finish(30);
1439
1601
  case 33:
1440
1602
  console.log('[Server] ✅ 所有模块注册完成');
1441
1603
  this.logInfo('所有模块注册完成', {
@@ -1445,14 +1607,14 @@ var Server = /*#__PURE__*/function () {
1445
1607
  return m === null || m === void 0 || (_m$config = m.config) === null || _m$config === void 0 ? void 0 : _m$config.name;
1446
1608
  })
1447
1609
  });
1448
- return _context18.abrupt("return", registeredModules);
1610
+ return _context22.abrupt("return", registeredModules);
1449
1611
  case 36:
1450
1612
  case "end":
1451
- return _context18.stop();
1613
+ return _context22.stop();
1452
1614
  }
1453
- }, _callee18, this, [[5, 27, 30, 33], [10, 17]]);
1615
+ }, _callee22, this, [[5, 27, 30, 33], [10, 17]]);
1454
1616
  }));
1455
- function registerModules(_x20) {
1617
+ function registerModules(_x24) {
1456
1618
  return _registerModules.apply(this, arguments);
1457
1619
  }
1458
1620
  return registerModules;
@@ -1465,10 +1627,10 @@ var Server = /*#__PURE__*/function () {
1465
1627
  }, {
1466
1628
  key: "preloadModulesData",
1467
1629
  value: (function () {
1468
- var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(registeredModules, options) {
1630
+ var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(registeredModules, options) {
1469
1631
  var modulesToPreload, preloadResults, _iterator3, _step3, _step3$value, module, config, shouldPreload, startTime, _options$onModuleLoad, _options$onModuleLoad2, duration, _duration, errorMessage, successCount, failCount;
1470
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1471
- while (1) switch (_context19.prev = _context19.next) {
1632
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1633
+ while (1) switch (_context23.prev = _context23.next) {
1472
1634
  case 0:
1473
1635
  console.log('[Server] 开始预加载模块数据...');
1474
1636
  modulesToPreload = registeredModules.filter(function (m) {
@@ -1481,16 +1643,16 @@ var Server = /*#__PURE__*/function () {
1481
1643
  });
1482
1644
  preloadResults = [];
1483
1645
  _iterator3 = _createForOfIteratorHelper(registeredModules);
1484
- _context19.prev = 5;
1646
+ _context23.prev = 5;
1485
1647
  _iterator3.s();
1486
1648
  case 7:
1487
1649
  if ((_step3 = _iterator3.n()).done) {
1488
- _context19.next = 40;
1650
+ _context23.next = 40;
1489
1651
  break;
1490
1652
  }
1491
1653
  _step3$value = _step3.value, module = _step3$value.module, config = _step3$value.config, shouldPreload = _step3$value.shouldPreload;
1492
1654
  if (shouldPreload) {
1493
- _context19.next = 13;
1655
+ _context23.next = 13;
1494
1656
  break;
1495
1657
  }
1496
1658
  console.log("[Server] \u23ED\uFE0F \u8DF3\u8FC7 ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D"));
@@ -1498,19 +1660,19 @@ var Server = /*#__PURE__*/function () {
1498
1660
  moduleName: config.name,
1499
1661
  reason: 'shouldPreload=false'
1500
1662
  });
1501
- return _context19.abrupt("continue", 38);
1663
+ return _context23.abrupt("continue", 38);
1502
1664
  case 13:
1503
1665
  if (!(typeof module.preload === 'function')) {
1504
- _context19.next = 36;
1666
+ _context23.next = 36;
1505
1667
  break;
1506
1668
  }
1507
1669
  startTime = Date.now();
1508
- _context19.prev = 15;
1670
+ _context23.prev = 15;
1509
1671
  this.logInfo("\u5F00\u59CB\u9884\u52A0\u8F7D\u6A21\u5757: ".concat(config.name), {
1510
1672
  moduleName: config.name
1511
1673
  });
1512
1674
  options === null || options === void 0 || (_options$onModuleLoad = options.onModuleLoad) === null || _options$onModuleLoad === void 0 || _options$onModuleLoad.call(options, config.name);
1513
- _context19.next = 20;
1675
+ _context23.next = 20;
1514
1676
  return module.preload();
1515
1677
  case 20:
1516
1678
  options === null || options === void 0 || (_options$onModuleLoad2 = options.onModuleLoadComplete) === null || _options$onModuleLoad2 === void 0 || _options$onModuleLoad2.call(options, config.name);
@@ -1524,14 +1686,14 @@ var Server = /*#__PURE__*/function () {
1524
1686
  name: config.name,
1525
1687
  success: true
1526
1688
  });
1527
- _context19.next = 34;
1689
+ _context23.next = 34;
1528
1690
  break;
1529
1691
  case 27:
1530
- _context19.prev = 27;
1531
- _context19.t0 = _context19["catch"](15);
1692
+ _context23.prev = 27;
1693
+ _context23.t0 = _context23["catch"](15);
1532
1694
  _duration = Date.now() - startTime;
1533
- errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0);
1534
- console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context19.t0);
1695
+ errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
1696
+ console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context23.t0);
1535
1697
  this.logError("\u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25: ".concat(config.name), {
1536
1698
  moduleName: config.name,
1537
1699
  duration: "".concat(_duration, "ms"),
@@ -1543,7 +1705,7 @@ var Server = /*#__PURE__*/function () {
1543
1705
  error: errorMessage
1544
1706
  });
1545
1707
  case 34:
1546
- _context19.next = 38;
1708
+ _context23.next = 38;
1547
1709
  break;
1548
1710
  case 36:
1549
1711
  console.log("[Server] \u26A0\uFE0F ".concat(config.name, " \u6A21\u5757\u672A\u5B9E\u73B0 preload() \u65B9\u6CD5"));
@@ -1551,19 +1713,19 @@ var Server = /*#__PURE__*/function () {
1551
1713
  moduleName: config.name
1552
1714
  });
1553
1715
  case 38:
1554
- _context19.next = 7;
1716
+ _context23.next = 7;
1555
1717
  break;
1556
1718
  case 40:
1557
- _context19.next = 45;
1719
+ _context23.next = 45;
1558
1720
  break;
1559
1721
  case 42:
1560
- _context19.prev = 42;
1561
- _context19.t1 = _context19["catch"](5);
1562
- _iterator3.e(_context19.t1);
1722
+ _context23.prev = 42;
1723
+ _context23.t1 = _context23["catch"](5);
1724
+ _iterator3.e(_context23.t1);
1563
1725
  case 45:
1564
- _context19.prev = 45;
1726
+ _context23.prev = 45;
1565
1727
  _iterator3.f();
1566
- return _context19.finish(45);
1728
+ return _context23.finish(45);
1567
1729
  case 48:
1568
1730
  successCount = preloadResults.filter(function (r) {
1569
1731
  return r.success;
@@ -1578,11 +1740,11 @@ var Server = /*#__PURE__*/function () {
1578
1740
  });
1579
1741
  case 52:
1580
1742
  case "end":
1581
- return _context19.stop();
1743
+ return _context23.stop();
1582
1744
  }
1583
- }, _callee19, this, [[5, 42, 45, 48], [15, 27]]);
1745
+ }, _callee23, this, [[5, 42, 45, 48], [15, 27]]);
1584
1746
  }));
1585
- function preloadModulesData(_x21, _x22) {
1747
+ function preloadModulesData(_x25, _x26) {
1586
1748
  return _preloadModulesData.apply(this, arguments);
1587
1749
  }
1588
1750
  return preloadModulesData;
@@ -1596,7 +1758,7 @@ var Server = /*#__PURE__*/function () {
1596
1758
  }, {
1597
1759
  key: "initialize",
1598
1760
  value: (function () {
1599
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(moduleConfigs) {
1761
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(moduleConfigs) {
1600
1762
  var _moduleConfigs$length,
1601
1763
  _this3 = this;
1602
1764
  var autoPreload,
@@ -1604,12 +1766,12 @@ var Server = /*#__PURE__*/function () {
1604
1766
  startTime,
1605
1767
  registeredModules,
1606
1768
  duration,
1607
- _args20 = arguments;
1608
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1609
- while (1) switch (_context20.prev = _context20.next) {
1769
+ _args24 = arguments;
1770
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1771
+ while (1) switch (_context24.prev = _context24.next) {
1610
1772
  case 0:
1611
- autoPreload = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : true;
1612
- options = _args20.length > 2 ? _args20[2] : undefined;
1773
+ autoPreload = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : true;
1774
+ options = _args24.length > 2 ? _args24[2] : undefined;
1613
1775
  startTime = Date.now();
1614
1776
  this.logInfo('Server 初始化开始', {
1615
1777
  moduleConfigCount: (_moduleConfigs$length = moduleConfigs === null || moduleConfigs === void 0 ? void 0 : moduleConfigs.length) !== null && _moduleConfigs$length !== void 0 ? _moduleConfigs$length : 'all',
@@ -1619,29 +1781,30 @@ var Server = /*#__PURE__*/function () {
1619
1781
 
1620
1782
  // 注册 Server 层的业务路由
1621
1783
  this.registerServerRoutes();
1784
+ this.registerDeviceTaskActions();
1622
1785
 
1623
1786
  // 注册模块
1624
- _context20.next = 7;
1787
+ _context24.next = 8;
1625
1788
  return this.registerModules(moduleConfigs);
1626
- case 7:
1627
- registeredModules = _context20.sent;
1789
+ case 8:
1790
+ registeredModules = _context24.sent;
1628
1791
  if (!autoPreload) {
1629
- _context20.next = 13;
1792
+ _context24.next = 14;
1630
1793
  break;
1631
1794
  }
1632
- _context20.next = 11;
1795
+ _context24.next = 12;
1633
1796
  return this.preloadModulesData(registeredModules, options);
1634
- case 11:
1635
- _context20.next = 14;
1797
+ case 12:
1798
+ _context24.next = 15;
1636
1799
  break;
1637
- case 13:
1800
+ case 14:
1638
1801
  this.logInfo('跳过自动预加载', {
1639
1802
  autoPreload: autoPreload
1640
1803
  });
1641
- case 14:
1642
- _context20.next = 16;
1804
+ case 15:
1805
+ _context24.next = 17;
1643
1806
  return this.setupProductsQuotationPriceBridge();
1644
- case 16:
1807
+ case 17:
1645
1808
  // 监听 ProductsModule 同步完成事件,重新计算并推送查询结果
1646
1809
  this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function (payload) {
1647
1810
  _this3.recomputeAndNotifyProductQuery({
@@ -1655,80 +1818,244 @@ var Server = /*#__PURE__*/function () {
1655
1818
  });
1656
1819
 
1657
1820
  // 订单 / 预约本地数据变更时,向订阅者推送最新列表
1658
- this.core.effects.on(OrderHooks.onOrdersChanged, function () {
1821
+ this.core.effects.on(OrderHooks.onOrdersChanged, function (payload) {
1659
1822
  _this3.recomputeAndNotifyOrderQuery();
1660
1823
  _this3.recomputeAndNotifyBookingQuery();
1661
1824
  _this3.syncBookingRemoteCacheFromOrderChanges();
1825
+ _this3.notifySalesSearchSubscribers(payload);
1662
1826
  });
1663
1827
  duration = Date.now() - startTime;
1664
1828
  this.logInfo('Server 初始化完成', {
1665
1829
  duration: "".concat(duration, "ms"),
1666
1830
  registeredModuleCount: registeredModules.length
1667
1831
  });
1668
- return _context20.abrupt("return", registeredModules);
1669
- case 22:
1832
+ return _context24.abrupt("return", registeredModules);
1833
+ case 23:
1670
1834
  case "end":
1671
- return _context20.stop();
1835
+ return _context24.stop();
1672
1836
  }
1673
- }, _callee20, this);
1837
+ }, _callee24, this);
1674
1838
  }));
1675
- function initialize(_x23) {
1839
+ function initialize(_x27) {
1676
1840
  return _initialize.apply(this, arguments);
1677
1841
  }
1678
1842
  return initialize;
1843
+ }())
1844
+ }, {
1845
+ key: "registerDeviceTaskActions",
1846
+ value: function registerDeviceTaskActions() {
1847
+ var _this4 = this;
1848
+ if (this.deviceTaskActionsRegistered) return;
1849
+ var deviceTask = this.getDeviceTaskPlugin();
1850
+ if (!(deviceTask !== null && deviceTask !== void 0 && deviceTask.registerAction)) {
1851
+ this.logWarning('registerDeviceTaskActions: deviceTask 插件不可用');
1852
+ return;
1853
+ }
1854
+ var registeredActions = new Set(typeof deviceTask.getActions === 'function' ? (deviceTask.getActions() || []).map(function (action) {
1855
+ return action === null || action === void 0 ? void 0 : action.action;
1856
+ }).filter(Boolean) : []);
1857
+ var register = function register(definition) {
1858
+ var _deviceTask$registerA;
1859
+ if (registeredActions.has(definition.action)) return;
1860
+ (_deviceTask$registerA = deviceTask.registerAction) === null || _deviceTask$registerA === void 0 || _deviceTask$registerA.call(deviceTask, definition);
1861
+ registeredActions.add(definition.action);
1862
+ };
1863
+ register({
1864
+ action: 'sync_sales',
1865
+ name: '同步订单',
1866
+ validate: function validate(payload) {
1867
+ return payload !== null && payload !== void 0 && payload.backendPath && payload !== null && payload !== void 0 && payload.data ? null : '缺少 backendPath 或 data';
1868
+ },
1869
+ handler: function handler(ctx) {
1870
+ return _this4.handleSyncSalesTask(ctx);
1871
+ }
1872
+ });
1873
+ this.deviceTaskActionsRegistered = true;
1874
+ this.logInfo('DeviceTask actions 已注册', {
1875
+ actions: ['sync_sales']
1876
+ });
1877
+ }
1878
+ }, {
1879
+ key: "handleSyncSalesTask",
1880
+ value: function () {
1881
+ var _handleSyncSalesTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(ctx) {
1882
+ var _ctx$task, _this$app4;
1883
+ var payload, backendPath, data, title, response, message, fresh, syncedOrder, _ctx$task2, backendError, _message, errorMessage;
1884
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1885
+ while (1) switch (_context25.prev = _context25.next) {
1886
+ case 0:
1887
+ payload = ((_ctx$task = ctx.task) === null || _ctx$task === void 0 ? void 0 : _ctx$task.payload) || {};
1888
+ backendPath = payload.backendPath;
1889
+ data = payload.data;
1890
+ title = payload.title || 'sync_sales';
1891
+ if (!(!backendPath || !data)) {
1892
+ _context25.next = 6;
1893
+ break;
1894
+ }
1895
+ return _context25.abrupt("return", this.taskFail('INVALID_PAYLOAD', '缺少 backendPath 或 data'));
1896
+ case 6:
1897
+ if ((_this$app4 = this.app) !== null && _this$app4 !== void 0 && _this$app4.request) {
1898
+ _context25.next = 9;
1899
+ break;
1900
+ }
1901
+ this.logError("".concat(title, ": sync_sales app.request \u4E0D\u53EF\u7528"));
1902
+ return _context25.abrupt("return", this.taskTimeout('app.request 不可用'));
1903
+ case 9:
1904
+ _context25.prev = 9;
1905
+ _context25.next = 12;
1906
+ return this.app.request.post('/shop/order/sales/checkout', data, {
1907
+ isShopApi: true,
1908
+ customToast: function customToast() {}
1909
+ });
1910
+ case 12:
1911
+ response = _context25.sent;
1912
+ if (!this.isCheckoutResponseRejected(response)) {
1913
+ _context25.next = 17;
1914
+ break;
1915
+ }
1916
+ message = (response === null || response === void 0 ? void 0 : response.message) || '后端明确拒绝 checkout';
1917
+ this.logError("".concat(title, ": sync_sales \u540E\u7AEF\u660E\u786E\u5931\u8D25"), {
1918
+ backendPath: backendPath,
1919
+ response: response
1920
+ });
1921
+ return _context25.abrupt("return", this.taskFail('BACKEND_REJECTED', message, response));
1922
+ case 17:
1923
+ fresh = this.extractOrderDataFromCheckoutResponse(response);
1924
+ if (fresh) {
1925
+ _context25.next = 21;
1926
+ break;
1927
+ }
1928
+ this.logWarning("".concat(title, ": sync_sales \u8FD4\u56DE\u672A\u5305\u542B\u53EF\u540C\u6B65\u8BA2\u5355"), {
1929
+ backendPath: backendPath,
1930
+ response: response
1931
+ });
1932
+ return _context25.abrupt("return", this.taskTimeout('checkout 返回未包含可同步订单'));
1933
+ case 21:
1934
+ syncedOrder = _objectSpread(_objectSpread({}, fresh), {}, {
1935
+ need_sync: 0
1936
+ });
1937
+ if (!this.order) {
1938
+ _context25.next = 28;
1939
+ break;
1940
+ }
1941
+ _context25.next = 25;
1942
+ return this.order.upsertOrdersFromRemote([syncedOrder]);
1943
+ case 25:
1944
+ this.logInfo("".concat(title, ": sync_sales \u8BA2\u5355\u5DF2\u540C\u6B65\u5230\u672C\u5730"), {
1945
+ order_id: fresh.order_id,
1946
+ external_sale_number: fresh.external_sale_number,
1947
+ order_number: fresh.order_number
1948
+ });
1949
+ _context25.next = 29;
1950
+ break;
1951
+ case 28:
1952
+ this.logWarning("".concat(title, ": sync_sales Order \u6A21\u5757\u672A\u6CE8\u518C"), {
1953
+ backendPath: backendPath,
1954
+ order_id: fresh.order_id
1955
+ });
1956
+ case 29:
1957
+ if (!this.shouldPrintSyncedOrder({
1958
+ checkoutData: data,
1959
+ syncedOrder: syncedOrder
1960
+ })) {
1961
+ _context25.next = 32;
1962
+ break;
1963
+ }
1964
+ _context25.next = 32;
1965
+ return this.dispatchPrintOtherReceiptTask({
1966
+ checkoutData: data,
1967
+ syncedOrder: syncedOrder,
1968
+ response: response,
1969
+ deviceId: (_ctx$task2 = ctx.task) === null || _ctx$task2 === void 0 ? void 0 : _ctx$task2.device_id
1970
+ });
1971
+ case 32:
1972
+ return _context25.abrupt("return", this.taskOk({
1973
+ order: syncedOrder,
1974
+ response: this.normalizeCheckoutResponse(response)
1975
+ }));
1976
+ case 35:
1977
+ _context25.prev = 35;
1978
+ _context25.t0 = _context25["catch"](9);
1979
+ backendError = this.extractBackendErrorResponse(_context25.t0);
1980
+ if (!backendError) {
1981
+ _context25.next = 42;
1982
+ break;
1983
+ }
1984
+ _message = (backendError === null || backendError === void 0 ? void 0 : backendError.message) || '后端明确拒绝 checkout';
1985
+ this.logError("".concat(title, ": sync_sales \u540E\u7AEF\u660E\u786E\u5931\u8D25"), {
1986
+ backendPath: backendPath,
1987
+ backendError: backendError
1988
+ });
1989
+ return _context25.abrupt("return", this.taskFail('BACKEND_REJECTED', _message, backendError));
1990
+ case 42:
1991
+ errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
1992
+ this.logError("".concat(title, ": sync_sales \u8BF7\u6C42\u672A\u660E\u786E\u6210\u529F"), {
1993
+ backendPath: backendPath,
1994
+ error: errorMessage
1995
+ });
1996
+ return _context25.abrupt("return", this.taskTimeout(errorMessage));
1997
+ case 45:
1998
+ case "end":
1999
+ return _context25.stop();
2000
+ }
2001
+ }, _callee25, this, [[9, 35]]);
2002
+ }));
2003
+ function handleSyncSalesTask(_x28) {
2004
+ return _handleSyncSalesTask.apply(this, arguments);
2005
+ }
2006
+ return handleSyncSalesTask;
1679
2007
  }()
1680
2008
  /**
1681
2009
  * 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
1682
2010
  */
1683
- )
1684
2011
  }, {
1685
2012
  key: "setupProductsQuotationPriceBridge",
1686
2013
  value: (function () {
1687
- var _setupProductsQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2014
+ var _setupProductsQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1688
2015
  var _this$core$context, errorMessage;
1689
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1690
- while (1) switch (_context21.prev = _context21.next) {
2016
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2017
+ while (1) switch (_context26.prev = _context26.next) {
1691
2018
  case 0:
1692
2019
  if (this.products) {
1693
- _context21.next = 3;
2020
+ _context26.next = 3;
1694
2021
  break;
1695
2022
  }
1696
2023
  this.logInfo('setupProductsQuotationPriceBridge: Products 模块未注册');
1697
- return _context21.abrupt("return");
2024
+ return _context26.abrupt("return");
1698
2025
  case 3:
1699
2026
  if (this.schedule) {
1700
- _context21.next = 6;
2027
+ _context26.next = 6;
1701
2028
  break;
1702
2029
  }
1703
2030
  this.logInfo('setupProductsQuotationPriceBridge: Schedule 模块未注册');
1704
- return _context21.abrupt("return");
2031
+ return _context26.abrupt("return");
1705
2032
  case 6:
1706
- _context21.prev = 6;
1707
- _context21.next = 9;
2033
+ _context26.prev = 6;
2034
+ _context26.next = 9;
1708
2035
  return this.schedule.loadAllSchedule();
1709
2036
  case 9:
1710
2037
  this.products.clearPriceCache();
1711
- _context21.next = 12;
2038
+ _context26.next = 12;
1712
2039
  return this.products.setupQuotationPriceBridge({
1713
2040
  scheduleModule: this.schedule,
1714
2041
  channel: (_this$core$context = this.core.context) === null || _this$core$context === void 0 ? void 0 : _this$core$context.channel
1715
2042
  });
1716
2043
  case 12:
1717
2044
  this.logInfo('Products 报价单价格桥接初始化完成');
1718
- _context21.next = 19;
2045
+ _context26.next = 19;
1719
2046
  break;
1720
2047
  case 15:
1721
- _context21.prev = 15;
1722
- _context21.t0 = _context21["catch"](6);
1723
- errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
2048
+ _context26.prev = 15;
2049
+ _context26.t0 = _context26["catch"](6);
2050
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
1724
2051
  this.logError('Products 报价单价格桥接初始化失败', {
1725
2052
  error: errorMessage
1726
2053
  });
1727
2054
  case 19:
1728
2055
  case "end":
1729
- return _context21.stop();
2056
+ return _context26.stop();
1730
2057
  }
1731
- }, _callee21, this, [[6, 15]]);
2058
+ }, _callee26, this, [[6, 15]]);
1732
2059
  }));
1733
2060
  function setupProductsQuotationPriceBridge() {
1734
2061
  return _setupProductsQuotationPriceBridge.apply(this, arguments);
@@ -1797,45 +2124,45 @@ var Server = /*#__PURE__*/function () {
1797
2124
  }, {
1798
2125
  key: "refreshProductsInBackground",
1799
2126
  value: (function () {
1800
- var _refreshProductsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2127
+ var _refreshProductsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1801
2128
  var startTime, duration, _duration2, errorMessage;
1802
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1803
- while (1) switch (_context22.prev = _context22.next) {
2129
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2130
+ while (1) switch (_context27.prev = _context27.next) {
1804
2131
  case 0:
1805
2132
  if (this.products) {
1806
- _context22.next = 3;
2133
+ _context27.next = 3;
1807
2134
  break;
1808
2135
  }
1809
2136
  this.logWarning('refreshProductsInBackground: Products 模块未注册');
1810
- return _context22.abrupt("return");
2137
+ return _context27.abrupt("return");
1811
2138
  case 3:
1812
2139
  this.logInfo('refreshProductsInBackground 开始');
1813
2140
  startTime = Date.now();
1814
- _context22.prev = 5;
1815
- _context22.next = 8;
2141
+ _context27.prev = 5;
2142
+ _context27.next = 8;
1816
2143
  return this.products.silentRefresh();
1817
2144
  case 8:
1818
2145
  duration = Date.now() - startTime;
1819
2146
  this.logInfo('refreshProductsInBackground 完成', {
1820
2147
  duration: "".concat(duration, "ms")
1821
2148
  });
1822
- _context22.next = 18;
2149
+ _context27.next = 18;
1823
2150
  break;
1824
2151
  case 12:
1825
- _context22.prev = 12;
1826
- _context22.t0 = _context22["catch"](5);
2152
+ _context27.prev = 12;
2153
+ _context27.t0 = _context27["catch"](5);
1827
2154
  _duration2 = Date.now() - startTime;
1828
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1829
- console.error('[Server] refreshProductsInBackground 失败:', _context22.t0);
2155
+ errorMessage = _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0);
2156
+ console.error('[Server] refreshProductsInBackground 失败:', _context27.t0);
1830
2157
  this.logError('refreshProductsInBackground 失败', {
1831
2158
  duration: "".concat(_duration2, "ms"),
1832
2159
  error: errorMessage
1833
2160
  });
1834
2161
  case 18:
1835
2162
  case "end":
1836
- return _context22.stop();
2163
+ return _context27.stop();
1837
2164
  }
1838
- }, _callee22, this, [[5, 12]]);
2165
+ }, _callee27, this, [[5, 12]]);
1839
2166
  }));
1840
2167
  function refreshProductsInBackground() {
1841
2168
  return _refreshProductsInBackground.apply(this, arguments);
@@ -1851,45 +2178,45 @@ var Server = /*#__PURE__*/function () {
1851
2178
  }, {
1852
2179
  key: "refreshOrdersInBackground",
1853
2180
  value: (function () {
1854
- var _refreshOrdersInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2181
+ var _refreshOrdersInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
1855
2182
  var startTime, duration, _duration3, errorMessage;
1856
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1857
- while (1) switch (_context23.prev = _context23.next) {
2183
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2184
+ while (1) switch (_context28.prev = _context28.next) {
1858
2185
  case 0:
1859
2186
  if (this.order) {
1860
- _context23.next = 3;
2187
+ _context28.next = 3;
1861
2188
  break;
1862
2189
  }
1863
2190
  this.logWarning('refreshOrdersInBackground: Order 模块未注册');
1864
- return _context23.abrupt("return");
2191
+ return _context28.abrupt("return");
1865
2192
  case 3:
1866
2193
  this.logInfo('refreshOrdersInBackground 开始');
1867
2194
  startTime = Date.now();
1868
- _context23.prev = 5;
1869
- _context23.next = 8;
2195
+ _context28.prev = 5;
2196
+ _context28.next = 8;
1870
2197
  return this.order.silentRefresh();
1871
2198
  case 8:
1872
2199
  duration = Date.now() - startTime;
1873
2200
  this.logInfo('refreshOrdersInBackground 完成', {
1874
2201
  duration: "".concat(duration, "ms")
1875
2202
  });
1876
- _context23.next = 18;
2203
+ _context28.next = 18;
1877
2204
  break;
1878
2205
  case 12:
1879
- _context23.prev = 12;
1880
- _context23.t0 = _context23["catch"](5);
2206
+ _context28.prev = 12;
2207
+ _context28.t0 = _context28["catch"](5);
1881
2208
  _duration3 = Date.now() - startTime;
1882
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
1883
- console.error('[Server] refreshOrdersInBackground 失败:', _context23.t0);
2209
+ errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0);
2210
+ console.error('[Server] refreshOrdersInBackground 失败:', _context28.t0);
1884
2211
  this.logError('refreshOrdersInBackground 失败', {
1885
2212
  duration: "".concat(_duration3, "ms"),
1886
2213
  error: errorMessage
1887
2214
  });
1888
2215
  case 18:
1889
2216
  case "end":
1890
- return _context23.stop();
2217
+ return _context28.stop();
1891
2218
  }
1892
- }, _callee23, this, [[5, 12]]);
2219
+ }, _callee28, this, [[5, 12]]);
1893
2220
  }));
1894
2221
  function refreshOrdersInBackground() {
1895
2222
  return _refreshOrdersInBackground.apply(this, arguments);
@@ -1904,10 +2231,10 @@ var Server = /*#__PURE__*/function () {
1904
2231
  }, {
1905
2232
  key: "clearAllIndexDB",
1906
2233
  value: (function () {
1907
- var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2234
+ var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
1908
2235
  var clearTasks, moduleNames, errorMessage;
1909
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1910
- while (1) switch (_context24.prev = _context24.next) {
2236
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2237
+ while (1) switch (_context29.prev = _context29.next) {
1911
2238
  case 0:
1912
2239
  console.log('[Server] 开始清空所有模块的IndexedDB缓存...');
1913
2240
  this.logInfo('开始清空所有模块的 IndexedDB 缓存');
@@ -1942,41 +2269,41 @@ var Server = /*#__PURE__*/function () {
1942
2269
  moduleNames.push('FloorPlan');
1943
2270
  }
1944
2271
  if (!(clearTasks.length === 0)) {
1945
- _context24.next = 15;
2272
+ _context29.next = 15;
1946
2273
  break;
1947
2274
  }
1948
2275
  console.warn('[Server] 没有找到已注册的模块,无需清空');
1949
2276
  this.logWarning('没有找到已注册的模块,无需清空 IndexedDB');
1950
- return _context24.abrupt("return");
2277
+ return _context29.abrupt("return");
1951
2278
  case 15:
1952
2279
  this.logInfo('准备清空模块缓存', {
1953
2280
  moduleNames: moduleNames
1954
2281
  });
1955
- _context24.prev = 16;
1956
- _context24.next = 19;
2282
+ _context29.prev = 16;
2283
+ _context29.next = 19;
1957
2284
  return Promise.all(clearTasks);
1958
2285
  case 19:
1959
2286
  console.log("[Server] \u2705 \u5DF2\u6210\u529F\u6E05\u7A7A\u6240\u6709\u6A21\u5757\u7684IndexedDB\u7F13\u5B58: ".concat(moduleNames.join(', ')));
1960
2287
  this.logInfo('成功清空所有模块的 IndexedDB 缓存', {
1961
2288
  moduleNames: moduleNames
1962
2289
  });
1963
- _context24.next = 29;
2290
+ _context29.next = 29;
1964
2291
  break;
1965
2292
  case 23:
1966
- _context24.prev = 23;
1967
- _context24.t0 = _context24["catch"](16);
1968
- errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
1969
- console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context24.t0);
2293
+ _context29.prev = 23;
2294
+ _context29.t0 = _context29["catch"](16);
2295
+ errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
2296
+ console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context29.t0);
1970
2297
  this.logError('清空 IndexedDB 缓存时发生错误', {
1971
2298
  moduleNames: moduleNames,
1972
2299
  error: errorMessage
1973
2300
  });
1974
- throw _context24.t0;
2301
+ throw _context29.t0;
1975
2302
  case 29:
1976
2303
  case "end":
1977
- return _context24.stop();
2304
+ return _context29.stop();
1978
2305
  }
1979
- }, _callee24, this, [[16, 23]]);
2306
+ }, _callee29, this, [[16, 23]]);
1980
2307
  }));
1981
2308
  function clearAllIndexDB() {
1982
2309
  return _clearAllIndexDB.apply(this, arguments);
@@ -2051,10 +2378,10 @@ var Server = /*#__PURE__*/function () {
2051
2378
  }, {
2052
2379
  key: "handleRoute",
2053
2380
  value: (function () {
2054
- var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(method, path, params) {
2381
+ var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(method, path, params) {
2055
2382
  var startTime, handler, result, duration, _duration4, errorMessage;
2056
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2057
- while (1) switch (_context25.prev = _context25.next) {
2383
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2384
+ while (1) switch (_context30.prev = _context30.next) {
2058
2385
  case 0:
2059
2386
  startTime = Date.now();
2060
2387
  this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5F00\u59CB: ".concat(method.toUpperCase(), " ").concat(path), {
@@ -2065,7 +2392,7 @@ var Server = /*#__PURE__*/function () {
2065
2392
  });
2066
2393
  handler = this.getRouteHandler(method, path);
2067
2394
  if (handler) {
2068
- _context25.next = 6;
2395
+ _context30.next = 6;
2069
2396
  break;
2070
2397
  }
2071
2398
  this.logError("\u8DEF\u7531\u672A\u627E\u5230: ".concat(method.toUpperCase(), " ").concat(path), {
@@ -2074,13 +2401,13 @@ var Server = /*#__PURE__*/function () {
2074
2401
  });
2075
2402
  throw new Error("Route not found: ".concat(method.toUpperCase(), " ").concat(path));
2076
2403
  case 6:
2077
- _context25.prev = 6;
2078
- _context25.next = 9;
2404
+ _context30.prev = 6;
2405
+ _context30.next = 9;
2079
2406
  return handler(_objectSpread(_objectSpread({}, params), {}, {
2080
2407
  path: path
2081
2408
  }));
2082
2409
  case 9:
2083
- result = _context25.sent;
2410
+ result = _context30.sent;
2084
2411
  duration = Date.now() - startTime;
2085
2412
  this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5B8C\u6210: ".concat(method.toUpperCase(), " ").concat(path), {
2086
2413
  method: method.toUpperCase(),
@@ -2089,12 +2416,12 @@ var Server = /*#__PURE__*/function () {
2089
2416
  resultCode: result === null || result === void 0 ? void 0 : result.code,
2090
2417
  resultStatus: result === null || result === void 0 ? void 0 : result.status
2091
2418
  });
2092
- return _context25.abrupt("return", result);
2419
+ return _context30.abrupt("return", result);
2093
2420
  case 15:
2094
- _context25.prev = 15;
2095
- _context25.t0 = _context25["catch"](6);
2421
+ _context30.prev = 15;
2422
+ _context30.t0 = _context30["catch"](6);
2096
2423
  _duration4 = Date.now() - startTime;
2097
- errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2424
+ errorMessage = _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0);
2098
2425
  this.logError("\u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), {
2099
2426
  method: method.toUpperCase(),
2100
2427
  path: path,
@@ -2102,15 +2429,15 @@ var Server = /*#__PURE__*/function () {
2102
2429
  error: errorMessage,
2103
2430
  data: params.data
2104
2431
  });
2105
- console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context25.t0);
2106
- throw _context25.t0;
2432
+ console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context30.t0);
2433
+ throw _context30.t0;
2107
2434
  case 22:
2108
2435
  case "end":
2109
- return _context25.stop();
2436
+ return _context30.stop();
2110
2437
  }
2111
- }, _callee25, this, [[6, 15]]);
2438
+ }, _callee30, this, [[6, 15]]);
2112
2439
  }));
2113
- function handleRoute(_x24, _x25, _x26) {
2440
+ function handleRoute(_x29, _x30, _x31) {
2114
2441
  return _handleRoute.apply(this, arguments);
2115
2442
  }
2116
2443
  return handleRoute;
@@ -2122,10 +2449,10 @@ var Server = /*#__PURE__*/function () {
2122
2449
  }, {
2123
2450
  key: "getAllRoutes",
2124
2451
  value: function getAllRoutes() {
2125
- var _this4 = this;
2452
+ var _this5 = this;
2126
2453
  var routes = [];
2127
2454
  ['get', 'post', 'put', 'remove'].forEach(function (method) {
2128
- Object.keys(_this4.router[method]).forEach(function (path) {
2455
+ Object.keys(_this5.router[method]).forEach(function (path) {
2129
2456
  routes.push({
2130
2457
  method: method,
2131
2458
  path: path
@@ -2164,6 +2491,22 @@ var Server = /*#__PURE__*/function () {
2164
2491
  method: 'post',
2165
2492
  path: '/shop/order/v2/list/unsubscribe',
2166
2493
  handler: this.handleUnsubscribeOrderQuery.bind(this)
2494
+ }, {
2495
+ method: 'post',
2496
+ path: '/shop/es/search/sales',
2497
+ handler: this.handleSalesSearchModule.bind(this)
2498
+ }, {
2499
+ method: 'post',
2500
+ path: '/shop/es/search/sales/unsubscribe',
2501
+ handler: this.handleUnsubscribeSalesSearch.bind(this)
2502
+ }, {
2503
+ method: 'post',
2504
+ path: '/shop/es/search',
2505
+ handler: this.handleSalesSearchAggregate.bind(this)
2506
+ }, {
2507
+ method: 'post',
2508
+ path: '/shop/es/search/unsubscribe',
2509
+ handler: this.handleUnsubscribeSalesSearch.bind(this)
2167
2510
  }, {
2168
2511
  method: 'get',
2169
2512
  path: '/shop/schedule/booking',
@@ -2190,8 +2533,12 @@ var Server = /*#__PURE__*/function () {
2190
2533
  handler: this.handleOrderSalesCheckout.bind(this)
2191
2534
  }, {
2192
2535
  method: 'post',
2193
- path: '/shop/order/checkout',
2536
+ path: '/order/checkout',
2194
2537
  handler: this.handleOrderCheckout.bind(this)
2538
+ }, {
2539
+ method: 'post',
2540
+ path: '/local/print-order',
2541
+ handler: this.handleLocalPrintOrder.bind(this)
2195
2542
  }]);
2196
2543
  this.registerPrefixRoutes([{
2197
2544
  method: 'get',
@@ -2206,58 +2553,58 @@ var Server = /*#__PURE__*/function () {
2206
2553
  }, {
2207
2554
  key: "getPaymentRouteModule",
2208
2555
  value: function () {
2209
- var _getPaymentRouteModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2210
- var _this5 = this;
2211
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2212
- while (1) switch (_context27.prev = _context27.next) {
2556
+ var _getPaymentRouteModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2557
+ var _this6 = this;
2558
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2559
+ while (1) switch (_context32.prev = _context32.next) {
2213
2560
  case 0:
2214
2561
  if (!this.payment) {
2215
- _context27.next = 2;
2562
+ _context32.next = 2;
2216
2563
  break;
2217
2564
  }
2218
- return _context27.abrupt("return", this.payment);
2565
+ return _context32.abrupt("return", this.payment);
2219
2566
  case 2:
2220
2567
  if (!this.paymentRouteModule) {
2221
- _context27.next = 4;
2568
+ _context32.next = 4;
2222
2569
  break;
2223
2570
  }
2224
- return _context27.abrupt("return", this.paymentRouteModule);
2571
+ return _context32.abrupt("return", this.paymentRouteModule);
2225
2572
  case 4:
2226
2573
  if (!this.paymentRouteModuleInFlight) {
2227
- _context27.next = 6;
2574
+ _context32.next = 6;
2228
2575
  break;
2229
2576
  }
2230
- return _context27.abrupt("return", this.paymentRouteModuleInFlight);
2577
+ return _context32.abrupt("return", this.paymentRouteModuleInFlight);
2231
2578
  case 6:
2232
- this.paymentRouteModuleInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2579
+ this.paymentRouteModuleInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2233
2580
  var module;
2234
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2235
- while (1) switch (_context26.prev = _context26.next) {
2581
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2582
+ while (1) switch (_context31.prev = _context31.next) {
2236
2583
  case 0:
2237
2584
  module = new PaymentServerModule('server_payment_route', '1.0.0');
2238
- _context26.next = 3;
2239
- return module.initialize(_this5.core, {
2585
+ _context31.next = 3;
2586
+ return module.initialize(_this6.core, {
2240
2587
  store: {
2241
2588
  payMethods: []
2242
2589
  }
2243
2590
  });
2244
2591
  case 3:
2245
- _this5.paymentRouteModule = module;
2246
- return _context26.abrupt("return", module);
2592
+ _this6.paymentRouteModule = module;
2593
+ return _context31.abrupt("return", module);
2247
2594
  case 5:
2248
2595
  case "end":
2249
- return _context26.stop();
2596
+ return _context31.stop();
2250
2597
  }
2251
- }, _callee26);
2598
+ }, _callee31);
2252
2599
  }))().finally(function () {
2253
- _this5.paymentRouteModuleInFlight = undefined;
2600
+ _this6.paymentRouteModuleInFlight = undefined;
2254
2601
  });
2255
- return _context27.abrupt("return", this.paymentRouteModuleInFlight);
2602
+ return _context32.abrupt("return", this.paymentRouteModuleInFlight);
2256
2603
  case 8:
2257
2604
  case "end":
2258
- return _context27.stop();
2605
+ return _context32.stop();
2259
2606
  }
2260
- }, _callee27, this);
2607
+ }, _callee32, this);
2261
2608
  }));
2262
2609
  function getPaymentRouteModule() {
2263
2610
  return _getPaymentRouteModule.apply(this, arguments);
@@ -2280,15 +2627,265 @@ var Server = /*#__PURE__*/function () {
2280
2627
  }
2281
2628
  }
2282
2629
  }, {
2283
- key: "extractQueryDate",
2284
- value:
2630
+ key: "handleSalesSearchRequest",
2631
+ value: (
2632
+ /**
2633
+ * 执行 sales 搜索并登记可见订单号。
2634
+ * 搜索参数完全透传后端,OS 不做过滤、筛选、排序。
2635
+ *
2636
+ * @example
2637
+ * const result = await this.handleSalesSearchRequest('single', '/shop/es/search/sales', { keyword: '1001' }, {})
2638
+ */
2639
+ function () {
2640
+ var _handleSalesSearchRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(kind, backendPath, data, config) {
2641
+ var queryPayload, result, _ref49, callback, subscriberId, resetVisibleOrderIds, contextSignature, existing, shouldReset, visibleOrderIds, _iterator5, _step5, orderId;
2642
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2643
+ while (1) switch (_context33.prev = _context33.next) {
2644
+ case 0:
2645
+ queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
2646
+ _context33.next = 3;
2647
+ return this.fetchSalesSearchFromAPI(backendPath, queryPayload);
2648
+ case 3:
2649
+ result = _context33.sent;
2650
+ _ref49 = config || {}, callback = _ref49.callback, subscriberId = _ref49.subscriberId, resetVisibleOrderIds = _ref49.resetVisibleOrderIds;
2651
+ if (subscriberId && typeof callback === 'function') {
2652
+ contextSignature = this.buildSalesSearchSignature(kind, queryPayload);
2653
+ existing = this.salesSearchSubscribers.get(subscriberId);
2654
+ shouldReset = resetVisibleOrderIds === true || !existing || existing.kind !== kind || existing.contextSignature !== contextSignature;
2655
+ visibleOrderIds = shouldReset ? new Set() : new Set(existing.visibleOrderIds);
2656
+ _iterator5 = _createForOfIteratorHelper(this.extractSalesSearchOrderIds(kind, result));
2657
+ try {
2658
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2659
+ orderId = _step5.value;
2660
+ visibleOrderIds.add(orderId);
2661
+ }
2662
+ } catch (err) {
2663
+ _iterator5.e(err);
2664
+ } finally {
2665
+ _iterator5.f();
2666
+ }
2667
+ this.salesSearchSubscribers.set(subscriberId, {
2668
+ callback: callback,
2669
+ kind: kind,
2670
+ contextSignature: contextSignature,
2671
+ visibleOrderIds: visibleOrderIds,
2672
+ lastResponseData: this.extractSalesSearchResponseData(result)
2673
+ });
2674
+ this.logInfo('handleSalesSearchRequest: 已注册/更新订阅者', {
2675
+ subscriberId: subscriberId,
2676
+ kind: kind,
2677
+ shouldReset: shouldReset,
2678
+ visibleCount: visibleOrderIds.size
2679
+ });
2680
+ }
2681
+ return _context33.abrupt("return", result);
2682
+ case 7:
2683
+ case "end":
2684
+ return _context33.stop();
2685
+ }
2686
+ }, _callee33, this);
2687
+ }));
2688
+ function handleSalesSearchRequest(_x32, _x33, _x34, _x35) {
2689
+ return _handleSalesSearchRequest.apply(this, arguments);
2690
+ }
2691
+ return handleSalesSearchRequest;
2692
+ }()
2693
+ /**
2694
+ * 透传调用后端 sales 搜索接口。
2695
+ *
2696
+ * @example
2697
+ * const res = await this.fetchSalesSearchFromAPI('/shop/es/search/sales', { keyword: '1001' })
2698
+ */
2699
+ )
2700
+ }, {
2701
+ key: "fetchSalesSearchFromAPI",
2702
+ value: (function () {
2703
+ var _fetchSalesSearchFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(backendPath, data) {
2704
+ var _this$app5;
2705
+ var _response$data3, _response$code, _response$status, _response$message, response, _payload, errorMessage;
2706
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2707
+ while (1) switch (_context34.prev = _context34.next) {
2708
+ case 0:
2709
+ if ((_this$app5 = this.app) !== null && _this$app5 !== void 0 && _this$app5.request) {
2710
+ _context34.next = 3;
2711
+ break;
2712
+ }
2713
+ this.logError('fetchSalesSearchFromAPI: app.request 不可用', {
2714
+ backendPath: backendPath
2715
+ });
2716
+ return _context34.abrupt("return", {
2717
+ code: 500,
2718
+ message: 'app.request 不可用',
2719
+ data: backendPath === '/shop/es/search' ? {
2720
+ results: []
2721
+ } : {
2722
+ list: [],
2723
+ count: 0
2724
+ },
2725
+ status: false
2726
+ });
2727
+ case 3:
2728
+ _context34.prev = 3;
2729
+ _context34.next = 6;
2730
+ return this.app.request.post(backendPath, data, {
2731
+ isShopApi: true
2732
+ });
2733
+ case 6:
2734
+ response = _context34.sent;
2735
+ _payload = (_response$data3 = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data3 !== void 0 ? _response$data3 : response;
2736
+ return _context34.abrupt("return", {
2737
+ code: (_response$code = response === null || response === void 0 ? void 0 : response.code) !== null && _response$code !== void 0 ? _response$code : 200,
2738
+ status: (_response$status = response === null || response === void 0 ? void 0 : response.status) !== null && _response$status !== void 0 ? _response$status : true,
2739
+ message: (_response$message = response === null || response === void 0 ? void 0 : response.message) !== null && _response$message !== void 0 ? _response$message : '',
2740
+ data: _payload
2741
+ });
2742
+ case 11:
2743
+ _context34.prev = 11;
2744
+ _context34.t0 = _context34["catch"](3);
2745
+ errorMessage = _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0);
2746
+ this.logError('fetchSalesSearchFromAPI: 请求失败', {
2747
+ backendPath: backendPath,
2748
+ error: errorMessage
2749
+ });
2750
+ return _context34.abrupt("return", {
2751
+ code: 500,
2752
+ message: errorMessage,
2753
+ data: backendPath === '/shop/es/search' ? {
2754
+ results: []
2755
+ } : {
2756
+ list: [],
2757
+ count: 0
2758
+ },
2759
+ status: false
2760
+ });
2761
+ case 16:
2762
+ case "end":
2763
+ return _context34.stop();
2764
+ }
2765
+ }, _callee34, this, [[3, 11]]);
2766
+ }));
2767
+ function fetchSalesSearchFromAPI(_x36, _x37) {
2768
+ return _fetchSalesSearchFromAPI.apply(this, arguments);
2769
+ }
2770
+ return fetchSalesSearchFromAPI;
2771
+ }()
2772
+ /**
2773
+ * 构建搜索订阅签名;页码变化不重置,可继续累计 visibleOrderIds。
2774
+ *
2775
+ * @example
2776
+ * const signature = this.buildSalesSearchSignature('single', { keyword: 'A', page: 2 })
2777
+ */
2778
+ )
2779
+ }, {
2780
+ key: "buildSalesSearchSignature",
2781
+ value: function buildSalesSearchSignature(kind, payload) {
2782
+ return this.stableSerialize({
2783
+ kind: kind,
2784
+ payload: this.stripSalesSearchPageParams(payload)
2785
+ });
2786
+ }
2787
+
2788
+ /**
2789
+ * 移除页码参数,保留 page size、keyword、filters、sort 等查询语义参数。
2790
+ *
2791
+ * @example
2792
+ * this.stripSalesSearchPageParams({ page: 2, per_page: 20, keyword: 'A' })
2793
+ */
2794
+ }, {
2795
+ key: "stripSalesSearchPageParams",
2796
+ value: function stripSalesSearchPageParams(value) {
2797
+ var _this7 = this;
2798
+ if (Array.isArray(value)) {
2799
+ return value.map(function (item) {
2800
+ return _this7.stripSalesSearchPageParams(item);
2801
+ });
2802
+ }
2803
+ if (!value || _typeof(value) !== 'object') return value;
2804
+ var next = {};
2805
+ for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
2806
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2807
+ _key = _Object$entries$_i[0],
2808
+ item = _Object$entries$_i[1];
2809
+ if (_key === 'page' || _key === 'skip') continue;
2810
+ next[_key] = this.stripSalesSearchPageParams(item);
2811
+ }
2812
+ return next;
2813
+ }
2814
+
2815
+ /**
2816
+ * 提取响应 data,兼容 OS 包装结构与后端直接响应结构。
2817
+ *
2818
+ * @example
2819
+ * const data = this.extractSalesSearchResponseData(result)
2820
+ */
2821
+ }, {
2822
+ key: "extractSalesSearchResponseData",
2823
+ value: function extractSalesSearchResponseData(result) {
2824
+ var _result$data;
2825
+ return (_result$data = result === null || result === void 0 ? void 0 : result.data) !== null && _result$data !== void 0 ? _result$data : result;
2826
+ }
2827
+
2828
+ /**
2829
+ * 从搜索响应中提取 sales 命中的订单号。
2830
+ *
2831
+ * @example
2832
+ * const ids = this.extractSalesSearchOrderIds('single', result)
2833
+ */
2834
+ }, {
2835
+ key: "extractSalesSearchOrderIds",
2836
+ value: function extractSalesSearchOrderIds(kind, result) {
2837
+ var _this$findSalesSearch,
2838
+ _this8 = this;
2839
+ var data = this.extractSalesSearchResponseData(result);
2840
+ var list = kind === 'aggregate' ? (_this$findSalesSearch = this.findSalesSearchAggregateGroup(data)) === null || _this$findSalesSearch === void 0 ? void 0 : _this$findSalesSearch.list : data === null || data === void 0 ? void 0 : data.list;
2841
+ if (!Array.isArray(list)) return [];
2842
+ return list.map(function (item) {
2843
+ return _this8.getSalesSearchOrderId(item);
2844
+ }).filter(function (id) {
2845
+ return !!id;
2846
+ });
2847
+ }
2848
+
2849
+ /**
2850
+ * 查找聚合搜索响应中的 sales 分组。
2851
+ *
2852
+ * @example
2853
+ * const group = this.findSalesSearchAggregateGroup({ results: [{ module: 'sales' }] })
2854
+ */
2855
+ }, {
2856
+ key: "findSalesSearchAggregateGroup",
2857
+ value: function findSalesSearchAggregateGroup(data) {
2858
+ var results = Array.isArray(data === null || data === void 0 ? void 0 : data.results) ? data.results : [];
2859
+ return results.find(function (item) {
2860
+ return (item === null || item === void 0 ? void 0 : item.module) === 'sales';
2861
+ }) || null;
2862
+ }
2863
+
2864
+ /**
2865
+ * 从订单或搜索命中项中取订单号。
2866
+ *
2867
+ * @example
2868
+ * const id = this.getSalesSearchOrderId({ order_id: 1001 })
2869
+ */
2870
+ }, {
2871
+ key: "getSalesSearchOrderId",
2872
+ value: function getSalesSearchOrderId(order) {
2873
+ var _order$order_id;
2874
+ if (!order || _typeof(order) !== 'object') return null;
2875
+ var raw = (_order$order_id = order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : order.id;
2876
+ if (raw === undefined || raw === null || raw === '') return null;
2877
+ return String(raw);
2878
+ }
2879
+
2285
2880
  /**
2286
2881
  * 从查询值中提取 YYYY-MM-DD 日期串。
2287
2882
  *
2288
2883
  * @example
2289
2884
  * this.extractQueryDate('2026-04-15 09:58:00') // => '2026-04-15'
2290
2885
  */
2291
- function extractQueryDate(raw) {
2886
+ }, {
2887
+ key: "extractQueryDate",
2888
+ value: function extractQueryDate(raw) {
2292
2889
  if (raw == null) return null;
2293
2890
  var date = dayjs(raw);
2294
2891
  if (date.isValid()) {
@@ -2394,11 +2991,11 @@ var Server = /*#__PURE__*/function () {
2394
2991
  }, {
2395
2992
  key: "stableSerialize",
2396
2993
  value: function stableSerialize(value) {
2397
- var _this6 = this;
2994
+ var _this9 = this;
2398
2995
  if (value === null || value === undefined) return 'null';
2399
2996
  if (Array.isArray(value)) {
2400
2997
  return "[".concat(value.map(function (item) {
2401
- return _this6.stableSerialize(item);
2998
+ return _this9.stableSerialize(item);
2402
2999
  }).join(','), "]");
2403
3000
  }
2404
3001
  if (_typeof(value) === 'object') {
@@ -2407,7 +3004,7 @@ var Server = /*#__PURE__*/function () {
2407
3004
  return obj[k] !== undefined;
2408
3005
  }).sort();
2409
3006
  return "{".concat(keys.map(function (k) {
2410
- return "".concat(JSON.stringify(k), ":").concat(_this6.stableSerialize(obj[k]));
3007
+ return "".concat(JSON.stringify(k), ":").concat(_this9.stableSerialize(obj[k]));
2411
3008
  }).join(','), "}");
2412
3009
  }
2413
3010
  return JSON.stringify(value);
@@ -2456,22 +3053,22 @@ var Server = /*#__PURE__*/function () {
2456
3053
  }
2457
3054
  var oldestKey = null;
2458
3055
  var oldestTime = Number.POSITIVE_INFINITY;
2459
- var _iterator5 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
2460
- _step5;
3056
+ var _iterator6 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
3057
+ _step6;
2461
3058
  try {
2462
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2463
- var _step5$value = _slicedToArray(_step5.value, 2),
2464
- key = _step5$value[0],
2465
- cache = _step5$value[1];
3059
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
3060
+ var _step6$value = _slicedToArray(_step6.value, 2),
3061
+ _key2 = _step6$value[0],
3062
+ cache = _step6$value[1];
2466
3063
  if (cache.updatedAt < oldestTime) {
2467
3064
  oldestTime = cache.updatedAt;
2468
- oldestKey = key;
3065
+ oldestKey = _key2;
2469
3066
  }
2470
3067
  }
2471
3068
  } catch (err) {
2472
- _iterator5.e(err);
3069
+ _iterator6.e(err);
2473
3070
  } finally {
2474
- _iterator5.f();
3071
+ _iterator6.f();
2475
3072
  }
2476
3073
  if (oldestKey) this.bookingRemoteCache.delete(oldestKey);
2477
3074
  }
@@ -2487,17 +3084,17 @@ var Server = /*#__PURE__*/function () {
2487
3084
  key: "markBookingRemoteCacheAllStale",
2488
3085
  value: function markBookingRemoteCacheAllStale(reason) {
2489
3086
  if (this.bookingRemoteCache.size === 0) return;
2490
- var _iterator6 = _createForOfIteratorHelper(this.bookingRemoteCache.values()),
2491
- _step6;
3087
+ var _iterator7 = _createForOfIteratorHelper(this.bookingRemoteCache.values()),
3088
+ _step7;
2492
3089
  try {
2493
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
2494
- var entry = _step6.value;
3090
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
3091
+ var entry = _step7.value;
2495
3092
  entry.stale = true;
2496
3093
  }
2497
3094
  } catch (err) {
2498
- _iterator6.e(err);
3095
+ _iterator7.e(err);
2499
3096
  } finally {
2500
- _iterator6.f();
3097
+ _iterator7.f();
2501
3098
  }
2502
3099
  this.logWarning('bookingRemoteCache: 全量标记失效', {
2503
3100
  reason: reason,
@@ -2523,13 +3120,13 @@ var Server = /*#__PURE__*/function () {
2523
3120
  key: "notifyBookingRemoteSubscribersByCacheKey",
2524
3121
  value: function notifyBookingRemoteSubscribersByCacheKey(cacheKey, entry, reason) {
2525
3122
  if (this.bookingRemoteQuerySubscribers.size === 0) return;
2526
- var _iterator7 = _createForOfIteratorHelper(this.bookingRemoteQuerySubscribers.entries()),
2527
- _step7;
3123
+ var _iterator8 = _createForOfIteratorHelper(this.bookingRemoteQuerySubscribers.entries()),
3124
+ _step8;
2528
3125
  try {
2529
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
2530
- var _step7$value = _slicedToArray(_step7.value, 2),
2531
- subscriberId = _step7$value[0],
2532
- subscriber = _step7$value[1];
3126
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3127
+ var _step8$value = _slicedToArray(_step8.value, 2),
3128
+ subscriberId = _step8$value[0],
3129
+ subscriber = _step8$value[1];
2533
3130
  if (subscriber.cacheKey !== cacheKey) continue;
2534
3131
  try {
2535
3132
  var callbackStartAt = Date.now();
@@ -2556,9 +3153,9 @@ var Server = /*#__PURE__*/function () {
2556
3153
  }
2557
3154
  }
2558
3155
  } catch (err) {
2559
- _iterator7.e(err);
3156
+ _iterator8.e(err);
2560
3157
  } finally {
2561
- _iterator7.f();
3158
+ _iterator8.f();
2562
3159
  }
2563
3160
  }
2564
3161
  }, {
@@ -2573,13 +3170,13 @@ var Server = /*#__PURE__*/function () {
2573
3170
  return;
2574
3171
  }
2575
3172
  var syncedEntryCount = 0;
2576
- var _iterator8 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
2577
- _step8;
3173
+ var _iterator9 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
3174
+ _step9;
2578
3175
  try {
2579
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
2580
- var _step8$value = _slicedToArray(_step8.value, 2),
2581
- cacheKey = _step8$value[0],
2582
- entry = _step8$value[1];
3176
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3177
+ var _step9$value = _slicedToArray(_step9.value, 2),
3178
+ cacheKey = _step9$value[0],
3179
+ entry = _step9$value[1];
2583
3180
  if (entry.stale) {
2584
3181
  this.bookingRemoteCache.delete(cacheKey);
2585
3182
  continue;
@@ -2587,39 +3184,39 @@ var Server = /*#__PURE__*/function () {
2587
3184
  try {
2588
3185
  var queryPayload = entry.queryPayload;
2589
3186
  var orderMap = new Map();
2590
- var _iterator9 = _createForOfIteratorHelper(entry.rawOrders),
2591
- _step9;
3187
+ var _iterator10 = _createForOfIteratorHelper(entry.rawOrders),
3188
+ _step10;
2592
3189
  try {
2593
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
2594
- var order = _step9.value;
2595
- var key = this.toOrderIdKey(order);
2596
- if (key) orderMap.set(key, order);
3190
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3191
+ var order = _step10.value;
3192
+ var _key3 = this.toOrderIdKey(order);
3193
+ if (_key3) orderMap.set(_key3, order);
2597
3194
  }
2598
3195
  } catch (err) {
2599
- _iterator9.e(err);
3196
+ _iterator10.e(err);
2600
3197
  } finally {
2601
- _iterator9.f();
3198
+ _iterator10.f();
2602
3199
  }
2603
3200
  var changed = false;
2604
- var _iterator10 = _createForOfIteratorHelper(latestOrders),
2605
- _step10;
3201
+ var _iterator11 = _createForOfIteratorHelper(latestOrders),
3202
+ _step11;
2606
3203
  try {
2607
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
2608
- var latest = _step10.value;
2609
- var _key = this.toOrderIdKey(latest);
2610
- if (!_key) continue;
2611
- if (orderMap.has(_key)) {
2612
- orderMap.set(_key, latest);
3204
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3205
+ var latest = _step11.value;
3206
+ var _key4 = this.toOrderIdKey(latest);
3207
+ if (!_key4) continue;
3208
+ if (orderMap.has(_key4)) {
3209
+ orderMap.set(_key4, latest);
2613
3210
  changed = true;
2614
3211
  continue;
2615
3212
  }
2616
- orderMap.set(_key, latest);
3213
+ orderMap.set(_key4, latest);
2617
3214
  changed = true;
2618
3215
  }
2619
3216
  } catch (err) {
2620
- _iterator10.e(err);
3217
+ _iterator11.e(err);
2621
3218
  } finally {
2622
- _iterator10.f();
3219
+ _iterator11.f();
2623
3220
  }
2624
3221
  if (!changed) continue;
2625
3222
  var mergedOrders = _toConsumableArray(orderMap.values());
@@ -2652,9 +3249,9 @@ var Server = /*#__PURE__*/function () {
2652
3249
  }
2653
3250
  }
2654
3251
  } catch (err) {
2655
- _iterator8.e(err);
3252
+ _iterator9.e(err);
2656
3253
  } finally {
2657
- _iterator8.f();
3254
+ _iterator9.f();
2658
3255
  }
2659
3256
  var syncEndAt = Date.now();
2660
3257
  if (syncedEntryCount > 0) {
@@ -2672,18 +3269,18 @@ var Server = /*#__PURE__*/function () {
2672
3269
  }, {
2673
3270
  key: "fetchOrderListFromAPI",
2674
3271
  value: (function () {
2675
- var _fetchOrderListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(data) {
2676
- var _this$app4;
2677
- var _response$data3, response, payload, list, count, errorMessage;
2678
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2679
- while (1) switch (_context28.prev = _context28.next) {
3272
+ var _fetchOrderListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
3273
+ var _this$app6;
3274
+ var _response$data4, response, _payload2, list, count, errorMessage;
3275
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3276
+ while (1) switch (_context35.prev = _context35.next) {
2680
3277
  case 0:
2681
- if ((_this$app4 = this.app) !== null && _this$app4 !== void 0 && _this$app4.request) {
2682
- _context28.next = 3;
3278
+ if ((_this$app6 = this.app) !== null && _this$app6 !== void 0 && _this$app6.request) {
3279
+ _context35.next = 3;
2683
3280
  break;
2684
3281
  }
2685
3282
  this.logError('fetchOrderListFromAPI: app.request 不可用');
2686
- return _context28.abrupt("return", {
3283
+ return _context35.abrupt("return", {
2687
3284
  code: 500,
2688
3285
  message: 'app.request 不可用',
2689
3286
  data: {
@@ -2693,19 +3290,19 @@ var Server = /*#__PURE__*/function () {
2693
3290
  status: false
2694
3291
  });
2695
3292
  case 3:
2696
- _context28.prev = 3;
2697
- _context28.next = 6;
3293
+ _context35.prev = 3;
3294
+ _context35.next = 6;
2698
3295
  return this.app.request.post('/shop/order/v2/list', data, {
2699
3296
  isShopApi: true
2700
3297
  });
2701
3298
  case 6:
2702
- response = _context28.sent;
2703
- payload = (_response$data3 = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data3 !== void 0 ? _response$data3 : response;
2704
- list = Array.isArray(payload === null || payload === void 0 ? void 0 : payload.list) ? payload.list : [];
2705
- count = typeof (payload === null || payload === void 0 ? void 0 : payload.count) === 'number' ? payload.count : list.length;
2706
- return _context28.abrupt("return", {
3299
+ response = _context35.sent;
3300
+ _payload2 = (_response$data4 = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data4 !== void 0 ? _response$data4 : response;
3301
+ list = Array.isArray(_payload2 === null || _payload2 === void 0 ? void 0 : _payload2.list) ? _payload2.list : [];
3302
+ count = typeof (_payload2 === null || _payload2 === void 0 ? void 0 : _payload2.count) === 'number' ? _payload2.count : list.length;
3303
+ return _context35.abrupt("return", {
2707
3304
  code: 200,
2708
- data: _objectSpread(_objectSpread({}, payload), {}, {
3305
+ data: _objectSpread(_objectSpread({}, _payload2), {}, {
2709
3306
  list: list,
2710
3307
  count: count
2711
3308
  }),
@@ -2713,13 +3310,13 @@ var Server = /*#__PURE__*/function () {
2713
3310
  status: true
2714
3311
  });
2715
3312
  case 13:
2716
- _context28.prev = 13;
2717
- _context28.t0 = _context28["catch"](3);
2718
- errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0);
3313
+ _context35.prev = 13;
3314
+ _context35.t0 = _context35["catch"](3);
3315
+ errorMessage = _context35.t0 instanceof Error ? _context35.t0.message : String(_context35.t0);
2719
3316
  this.logError('fetchOrderListFromAPI: 请求失败', {
2720
3317
  error: errorMessage
2721
3318
  });
2722
- return _context28.abrupt("return", {
3319
+ return _context35.abrupt("return", {
2723
3320
  code: 500,
2724
3321
  message: errorMessage,
2725
3322
  data: {
@@ -2730,11 +3327,11 @@ var Server = /*#__PURE__*/function () {
2730
3327
  });
2731
3328
  case 18:
2732
3329
  case "end":
2733
- return _context28.stop();
3330
+ return _context35.stop();
2734
3331
  }
2735
- }, _callee28, this, [[3, 13]]);
3332
+ }, _callee35, this, [[3, 13]]);
2736
3333
  }));
2737
- function fetchOrderListFromAPI(_x27) {
3334
+ function fetchOrderListFromAPI(_x38) {
2738
3335
  return _fetchOrderListFromAPI.apply(this, arguments);
2739
3336
  }
2740
3337
  return fetchOrderListFromAPI;
@@ -2746,17 +3343,17 @@ var Server = /*#__PURE__*/function () {
2746
3343
  }, {
2747
3344
  key: "fetchBookingListFromAPI",
2748
3345
  value: (function () {
2749
- var _fetchBookingListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(data) {
3346
+ var _fetchBookingListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(data) {
2750
3347
  var memoryCacheEnabled, withFields, requestPayload, cacheKey, cached, rawList, bookingResult, _bookingResult$list, errorMessage;
2751
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2752
- while (1) switch (_context29.prev = _context29.next) {
3348
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3349
+ while (1) switch (_context36.prev = _context36.next) {
2753
3350
  case 0:
2754
3351
  if (this.order) {
2755
- _context29.next = 3;
3352
+ _context36.next = 3;
2756
3353
  break;
2757
3354
  }
2758
3355
  this.logError('fetchBookingListFromAPI: Order 模块不可用');
2759
- return _context29.abrupt("return", {
3356
+ return _context36.abrupt("return", {
2760
3357
  code: 500,
2761
3358
  message: 'Order 模块不可用',
2762
3359
  data: {
@@ -2766,18 +3363,18 @@ var Server = /*#__PURE__*/function () {
2766
3363
  status: false
2767
3364
  });
2768
3365
  case 3:
2769
- _context29.prev = 3;
3366
+ _context36.prev = 3;
2770
3367
  memoryCacheEnabled = this.isBookingRemoteMemoryCacheEnabled(data);
2771
3368
  withFields = this.resolveBookingSalesWith(data);
2772
3369
  requestPayload = this.normalizeBookingRemoteQueryPayload(data, withFields);
2773
3370
  cacheKey = this.buildBookingRemoteCacheKey(requestPayload);
2774
3371
  if (!memoryCacheEnabled) {
2775
- _context29.next = 13;
3372
+ _context36.next = 13;
2776
3373
  break;
2777
3374
  }
2778
3375
  cached = this.readBookingRemoteCache(cacheKey);
2779
3376
  if (!cached) {
2780
- _context29.next = 13;
3377
+ _context36.next = 13;
2781
3378
  break;
2782
3379
  }
2783
3380
  this.logInfo('fetchBookingListFromAPI: 命中内存缓存', {
@@ -2785,14 +3382,14 @@ var Server = /*#__PURE__*/function () {
2785
3382
  listCount: cached.bookingResult.count,
2786
3383
  withFields: cached.withFields
2787
3384
  });
2788
- return _context29.abrupt("return", this.buildBookingResponse(cached.bookingResult, {
3385
+ return _context36.abrupt("return", this.buildBookingResponse(cached.bookingResult, {
2789
3386
  cache_hit: true
2790
3387
  }));
2791
3388
  case 13:
2792
- _context29.next = 15;
3389
+ _context36.next = 15;
2793
3390
  return this.order.fetchOrdersBySSE(requestPayload);
2794
3391
  case 15:
2795
- rawList = _context29.sent;
3392
+ rawList = _context36.sent;
2796
3393
  bookingResult = sortBookings(filterBookingsFromOrders(rawList, data), data); // DEBUG: 挂到 window 上方便排查 SSE → 日历数据丢失问题
2797
3394
  if (typeof globalThis !== 'undefined') {
2798
3395
  globalThis.__SSE_BOOKING_DEBUG__ = {
@@ -2839,15 +3436,15 @@ var Server = /*#__PURE__*/function () {
2839
3436
  cacheKey: cacheKey,
2840
3437
  withFields: withFields
2841
3438
  });
2842
- return _context29.abrupt("return", this.buildBookingResponse(bookingResult));
3439
+ return _context36.abrupt("return", this.buildBookingResponse(bookingResult));
2843
3440
  case 23:
2844
- _context29.prev = 23;
2845
- _context29.t0 = _context29["catch"](3);
2846
- errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
3441
+ _context36.prev = 23;
3442
+ _context36.t0 = _context36["catch"](3);
3443
+ errorMessage = _context36.t0 instanceof Error ? _context36.t0.message : String(_context36.t0);
2847
3444
  this.logError('fetchBookingListFromAPI: SSE 请求失败', {
2848
3445
  error: errorMessage
2849
3446
  });
2850
- return _context29.abrupt("return", {
3447
+ return _context36.abrupt("return", {
2851
3448
  code: 500,
2852
3449
  message: errorMessage,
2853
3450
  data: {
@@ -2858,23 +3455,376 @@ var Server = /*#__PURE__*/function () {
2858
3455
  });
2859
3456
  case 28:
2860
3457
  case "end":
2861
- return _context29.stop();
3458
+ return _context36.stop();
3459
+ }
3460
+ }, _callee36, this, [[3, 23]]);
3461
+ }));
3462
+ function fetchBookingListFromAPI(_x39) {
3463
+ return _fetchBookingListFromAPI.apply(this, arguments);
3464
+ }
3465
+ return fetchBookingListFromAPI;
3466
+ }())
3467
+ }, {
3468
+ key: "getDeviceTaskPlugin",
3469
+ value: function getDeviceTaskPlugin() {
3470
+ var _this$app7, _this$app7$getPlugin;
3471
+ return ((_this$app7 = this.app) === null || _this$app7 === void 0 || (_this$app7$getPlugin = _this$app7.getPlugin) === null || _this$app7$getPlugin === void 0 ? void 0 : _this$app7$getPlugin.call(_this$app7, 'deviceTask')) || null;
3472
+ }
3473
+ }, {
3474
+ key: "getIdGeneratorPlugin",
3475
+ value: function getIdGeneratorPlugin() {
3476
+ var _this$app8, _this$app8$getPlugin;
3477
+ return ((_this$app8 = this.app) === null || _this$app8 === void 0 || (_this$app8$getPlugin = _this$app8.getPlugin) === null || _this$app8$getPlugin === void 0 ? void 0 : _this$app8$getPlugin.call(_this$app8, 'idGenerator')) || null;
3478
+ }
3479
+ }, {
3480
+ key: "getAppData",
3481
+ value: function getAppData(key) {
3482
+ var _this$app9, _this$app9$getData, _this$app10, _this$app10$getData, _this$app11, _this$app11$getStore, _this$app11$getStore$, _this$app11$getStore$2, _this$app12, _this$app12$getStore, _this$app12$getStore$, _this$app12$getStore$2, _this$app13, _this$app13$getStore, _this$app13$getStore$, _this$app13$getStore$2;
3483
+ var getData = (_this$app9 = this.app) === null || _this$app9 === void 0 || (_this$app9$getData = _this$app9.getData) === null || _this$app9$getData === void 0 ? void 0 : _this$app9$getData.call(_this$app9);
3484
+ if (typeof getData === 'function') return getData(key);
3485
+ var directValue = (_this$app10 = this.app) === null || _this$app10 === void 0 || (_this$app10$getData = _this$app10.getData) === null || _this$app10$getData === void 0 ? void 0 : _this$app10$getData.call(_this$app10, key);
3486
+ if (directValue !== undefined) return directValue;
3487
+ var coreData = ((_this$app11 = this.app) === null || _this$app11 === void 0 || (_this$app11 = _this$app11.models) === null || _this$app11 === void 0 || (_this$app11$getStore = _this$app11.getStore) === null || _this$app11$getStore === void 0 || (_this$app11$getStore$ = (_this$app11$getStore$2 = _this$app11$getStore.call(_this$app11)).getDataByModel) === null || _this$app11$getStore$ === void 0 ? void 0 : _this$app11$getStore$.call(_this$app11$getStore$2, 'core', 'core')) || ((_this$app12 = this.app) === null || _this$app12 === void 0 || (_this$app12 = _this$app12.data) === null || _this$app12 === void 0 || (_this$app12 = _this$app12.store) === null || _this$app12 === void 0 || (_this$app12$getStore = _this$app12.getStore) === null || _this$app12$getStore === void 0 || (_this$app12$getStore$ = (_this$app12$getStore$2 = _this$app12$getStore.call(_this$app12)).getDataByModel) === null || _this$app12$getStore$ === void 0 ? void 0 : _this$app12$getStore$.call(_this$app12$getStore$2, 'core', 'core')) || ((_this$app13 = this.app) === null || _this$app13 === void 0 || (_this$app13 = _this$app13.data) === null || _this$app13 === void 0 || (_this$app13 = _this$app13.store) === null || _this$app13 === void 0 || (_this$app13$getStore = _this$app13.getStore) === null || _this$app13$getStore === void 0 || (_this$app13$getStore$ = (_this$app13$getStore$2 = _this$app13$getStore.call(_this$app13)).getDataByModel) === null || _this$app13$getStore$ === void 0 || (_this$app13$getStore$ = _this$app13$getStore$.call(_this$app13$getStore$2, 'core')) === null || _this$app13$getStore$ === void 0 ? void 0 : _this$app13$getStore$.core);
3488
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
3489
+ }
3490
+ }, {
3491
+ key: "getSmallTicketShopInfo",
3492
+ value: function getSmallTicketShopInfo() {
3493
+ var _shopInfo$is_price_in;
3494
+ var shopInfo = this.getAppData('shop_info') || {};
3495
+ return _objectSpread(_objectSpread({}, shopInfo), {}, {
3496
+ currency_symbol: shopInfo.currency_symbol || this.getAppData('shop_symbol') || this.getAppData('currency_symbol'),
3497
+ currency_code: shopInfo.currency_code || this.getAppData('shop_currency_code') || this.getAppData('currency_code'),
3498
+ tax_title: shopInfo.tax_title || this.getAppData('tax_title'),
3499
+ tax_country_code: shopInfo.tax_country_code || this.getAppData('tax_country_code'),
3500
+ is_price_include_tax: (_shopInfo$is_price_in = shopInfo.is_price_include_tax) !== null && _shopInfo$is_price_in !== void 0 ? _shopInfo$is_price_in : this.getAppData('is_price_include_tax')
3501
+ });
3502
+ }
3503
+ }, {
3504
+ key: "taskOk",
3505
+ value: function taskOk(result) {
3506
+ return {
3507
+ status: 'success',
3508
+ result: result
3509
+ };
3510
+ }
3511
+ }, {
3512
+ key: "taskFail",
3513
+ value: function taskFail(code, message, result) {
3514
+ return _objectSpread({
3515
+ status: 'failed',
3516
+ error: {
3517
+ code: code,
3518
+ message: message
3519
+ }
3520
+ }, result !== undefined ? {
3521
+ result: result
3522
+ } : {});
3523
+ }
3524
+ }, {
3525
+ key: "taskTimeout",
3526
+ value: function taskTimeout(message) {
3527
+ return {
3528
+ status: 'timeout',
3529
+ error: {
3530
+ code: 'TIMEOUT',
3531
+ message: message
3532
+ }
3533
+ };
3534
+ }
3535
+ }, {
3536
+ key: "resolveCheckoutTaskDeviceId",
3537
+ value: function resolveCheckoutTaskDeviceId(_data) {
3538
+ return this.getAppData('device_id') || 0;
3539
+ }
3540
+ }, {
3541
+ key: "buildCheckoutTaskIdempotencyKey",
3542
+ value: function buildCheckoutTaskIdempotencyKey(data) {
3543
+ var identity = (data === null || data === void 0 ? void 0 : data.request_unique_idempotency_token) || (data === null || data === void 0 ? void 0 : data.external_sale_number) || (data === null || data === void 0 ? void 0 : data.order_id) || (data === null || data === void 0 ? void 0 : data.shop_order_number) || (data === null || data === void 0 ? void 0 : data.shop_full_order_number);
3544
+ if (identity === undefined || identity === null || identity === '') return undefined;
3545
+ return "sync_sales:".concat(identity);
3546
+ }
3547
+ }, {
3548
+ key: "ensureCheckoutOrderNumbers",
3549
+ value: function () {
3550
+ var _ensureCheckoutOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(data, title) {
3551
+ var next, needsShopOrderNumber, needsShopFullOrderNumber, idGenerator;
3552
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3553
+ while (1) switch (_context37.prev = _context37.next) {
3554
+ case 0:
3555
+ if (!(!data || _typeof(data) !== 'object')) {
3556
+ _context37.next = 2;
3557
+ break;
3558
+ }
3559
+ return _context37.abrupt("return", data);
3560
+ case 2:
3561
+ next = _objectSpread({}, data);
3562
+ needsShopOrderNumber = next.shop_order_number === undefined || next.shop_order_number === null || next.shop_order_number === '';
3563
+ needsShopFullOrderNumber = next.shop_full_order_number === undefined || next.shop_full_order_number === null || next.shop_full_order_number === '';
3564
+ if (!(!needsShopOrderNumber && !needsShopFullOrderNumber)) {
3565
+ _context37.next = 7;
3566
+ break;
3567
+ }
3568
+ return _context37.abrupt("return", next);
3569
+ case 7:
3570
+ idGenerator = this.getIdGeneratorPlugin();
3571
+ if (idGenerator) {
3572
+ _context37.next = 11;
3573
+ break;
3574
+ }
3575
+ this.logWarning("".concat(title, ": idGenerator \u63D2\u4EF6\u4E0D\u53EF\u7528\uFF0C\u65E0\u6CD5\u751F\u6210\u8BA2\u5355\u53F7"), {
3576
+ needsShopOrderNumber: needsShopOrderNumber,
3577
+ needsShopFullOrderNumber: needsShopFullOrderNumber
3578
+ });
3579
+ return _context37.abrupt("return", next);
3580
+ case 11:
3581
+ _context37.prev = 11;
3582
+ if (!(needsShopOrderNumber && idGenerator.generateShopOrderNumber)) {
3583
+ _context37.next = 16;
3584
+ break;
3585
+ }
3586
+ _context37.next = 15;
3587
+ return idGenerator.generateShopOrderNumber({
3588
+ biz: next.business_code || 'ticket'
3589
+ });
3590
+ case 15:
3591
+ next.shop_order_number = _context37.sent;
3592
+ case 16:
3593
+ if (!(needsShopFullOrderNumber && idGenerator.generateReceiptId)) {
3594
+ _context37.next = 20;
3595
+ break;
3596
+ }
3597
+ _context37.next = 19;
3598
+ return idGenerator.generateReceiptId({
3599
+ biz: next.business_code || 'ticket'
3600
+ });
3601
+ case 19:
3602
+ next.shop_full_order_number = _context37.sent;
3603
+ case 20:
3604
+ this.logInfo("".concat(title, ": checkout \u8BA2\u5355\u53F7\u5DF2\u51C6\u5907"), {
3605
+ shop_order_number: next.shop_order_number,
3606
+ shop_full_order_number: next.shop_full_order_number
3607
+ });
3608
+ _context37.next = 26;
3609
+ break;
3610
+ case 23:
3611
+ _context37.prev = 23;
3612
+ _context37.t0 = _context37["catch"](11);
3613
+ this.logError("".concat(title, ": \u751F\u6210 checkout \u8BA2\u5355\u53F7\u5931\u8D25"), {
3614
+ error: _context37.t0 instanceof Error ? _context37.t0.message : String(_context37.t0)
3615
+ });
3616
+ case 26:
3617
+ return _context37.abrupt("return", next);
3618
+ case 27:
3619
+ case "end":
3620
+ return _context37.stop();
3621
+ }
3622
+ }, _callee37, this, [[11, 23]]);
3623
+ }));
3624
+ function ensureCheckoutOrderNumbers(_x40, _x41) {
3625
+ return _ensureCheckoutOrderNumbers.apply(this, arguments);
3626
+ }
3627
+ return ensureCheckoutOrderNumbers;
3628
+ }()
3629
+ }, {
3630
+ key: "dispatchCheckoutSyncTask",
3631
+ value: function () {
3632
+ var _dispatchCheckoutSyncTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3633
+ var deviceTask, debugDeviceId, debugIdempotencyKey, _params$data, _params$data2, _params$data3, result;
3634
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3635
+ while (1) switch (_context38.prev = _context38.next) {
3636
+ case 0:
3637
+ this.registerDeviceTaskActions();
3638
+ deviceTask = this.getDeviceTaskPlugin();
3639
+ debugDeviceId = this.resolveCheckoutTaskDeviceId(params.data);
3640
+ debugIdempotencyKey = this.buildCheckoutTaskIdempotencyKey(params.data);
3641
+ if (deviceTask !== null && deviceTask !== void 0 && deviceTask.dispatch) {
3642
+ _context38.next = 7;
3643
+ break;
3644
+ }
3645
+ this.logError("".concat(params.title, ": deviceTask.dispatch \u4E0D\u53EF\u7528"));
3646
+ return _context38.abrupt("return");
3647
+ case 7:
3648
+ _context38.prev = 7;
3649
+ _context38.next = 10;
3650
+ return deviceTask.dispatch({
3651
+ action: 'sync_sales',
3652
+ device_id: debugDeviceId,
3653
+ payload: {
3654
+ backendPath: params.backendPath,
3655
+ data: params.data,
3656
+ title: params.title
3657
+ },
3658
+ retry_limit: 5,
3659
+ idempotency_key: debugIdempotencyKey,
3660
+ name: '同步订单',
3661
+ source: 'server',
3662
+ source_type: 'order',
3663
+ source_id: ((_params$data = params.data) === null || _params$data === void 0 ? void 0 : _params$data.order_id) || ((_params$data2 = params.data) === null || _params$data2 === void 0 ? void 0 : _params$data2.external_sale_number) || ((_params$data3 = params.data) === null || _params$data3 === void 0 ? void 0 : _params$data3.shop_order_number)
3664
+ });
3665
+ case 10:
3666
+ result = _context38.sent;
3667
+ this.logInfo("".concat(params.title, ": sync_sales \u4EFB\u52A1\u5DF2\u6D3E\u53D1"), {
3668
+ uuid: result === null || result === void 0 ? void 0 : result.uuid,
3669
+ status: result === null || result === void 0 ? void 0 : result.status,
3670
+ reused: result === null || result === void 0 ? void 0 : result.reused
3671
+ });
3672
+ _context38.next = 17;
3673
+ break;
3674
+ case 14:
3675
+ _context38.prev = 14;
3676
+ _context38.t0 = _context38["catch"](7);
3677
+ this.logError("".concat(params.title, ": \u6D3E\u53D1 sync_sales \u4EFB\u52A1\u5931\u8D25"), {
3678
+ error: _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0)
3679
+ });
3680
+ case 17:
3681
+ case "end":
3682
+ return _context38.stop();
3683
+ }
3684
+ }, _callee38, this, [[7, 14]]);
3685
+ }));
3686
+ function dispatchCheckoutSyncTask(_x42) {
3687
+ return _dispatchCheckoutSyncTask.apply(this, arguments);
3688
+ }
3689
+ return dispatchCheckoutSyncTask;
3690
+ }()
3691
+ }, {
3692
+ key: "dispatchPrintOtherReceiptTask",
3693
+ value: function () {
3694
+ var _dispatchPrintOtherReceiptTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3695
+ var deviceTask, _params$deviceId, _params$syncedOrder, _params$syncedOrder2, _params$syncedOrder3, printIdentity;
3696
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3697
+ while (1) switch (_context39.prev = _context39.next) {
3698
+ case 0:
3699
+ deviceTask = this.getDeviceTaskPlugin();
3700
+ if (deviceTask !== null && deviceTask !== void 0 && deviceTask.dispatch) {
3701
+ _context39.next = 4;
3702
+ break;
3703
+ }
3704
+ this.logWarning('dispatchPrintOtherReceiptTask: deviceTask.dispatch 不可用');
3705
+ return _context39.abrupt("return");
3706
+ case 4:
3707
+ _context39.prev = 4;
3708
+ printIdentity = this.getPrintOrderIdentity(params.syncedOrder);
3709
+ _context39.next = 8;
3710
+ return deviceTask.dispatch({
3711
+ action: 'print_all',
3712
+ device_id: (_params$deviceId = params.deviceId) !== null && _params$deviceId !== void 0 ? _params$deviceId : this.resolveCheckoutTaskDeviceId(params.checkoutData),
3713
+ payload: {
3714
+ type: params.receiptOnly ? '0' : '99',
3715
+ data: params.receiptOnly ? {
3716
+ order_id: printIdentity,
3717
+ small_ticket_data: (_params$syncedOrder = params.syncedOrder) === null || _params$syncedOrder === void 0 || (_params$syncedOrder = _params$syncedOrder.payment_info) === null || _params$syncedOrder === void 0 ? void 0 : _params$syncedOrder.small_ticket_data
3718
+ } : {
3719
+ order_id: printIdentity,
3720
+ machine_code_print_info: (_params$syncedOrder2 = params.syncedOrder) === null || _params$syncedOrder2 === void 0 || (_params$syncedOrder2 = _params$syncedOrder2.payment_info) === null || _params$syncedOrder2 === void 0 ? void 0 : _params$syncedOrder2.machine_code_print_info,
3721
+ machine_code_print_info_v2: (_params$syncedOrder3 = params.syncedOrder) === null || _params$syncedOrder3 === void 0 ? void 0 : _params$syncedOrder3.machine_code_print_info_v2,
3722
+ skip_receipt: true
3723
+ }
3724
+ },
3725
+ idempotency_key: this.buildPrintOtherReceiptIdempotencyKey(params.syncedOrder, {
3726
+ receiptOnly: params.receiptOnly
3727
+ }),
3728
+ name: '打印转发',
3729
+ source: 'server',
3730
+ source_type: 'order',
3731
+ source_id: printIdentity
3732
+ });
3733
+ case 8:
3734
+ _context39.next = 13;
3735
+ break;
3736
+ case 10:
3737
+ _context39.prev = 10;
3738
+ _context39.t0 = _context39["catch"](4);
3739
+ this.logError('dispatchPrintOtherReceiptTask: 派发失败', {
3740
+ error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
3741
+ });
3742
+ case 13:
3743
+ case "end":
3744
+ return _context39.stop();
3745
+ }
3746
+ }, _callee39, this, [[4, 10]]);
3747
+ }));
3748
+ function dispatchPrintOtherReceiptTask(_x43) {
3749
+ return _dispatchPrintOtherReceiptTask.apply(this, arguments);
3750
+ }
3751
+ return dispatchPrintOtherReceiptTask;
3752
+ }()
3753
+ }, {
3754
+ key: "buildPrintOtherReceiptIdempotencyKey",
3755
+ value: function buildPrintOtherReceiptIdempotencyKey(order, options) {
3756
+ var identity = (order === null || order === void 0 ? void 0 : order.external_sale_number) || (order === null || order === void 0 ? void 0 : order.shop_order_number) || (order === null || order === void 0 ? void 0 : order.shop_full_order_number) || (order === null || order === void 0 ? void 0 : order.order_id);
3757
+ if (identity === undefined || identity === null || identity === '') return undefined;
3758
+ return "".concat(options !== null && options !== void 0 && options.receiptOnly ? 'print_receipt' : 'print_voucher', ":").concat(identity);
3759
+ }
3760
+ }, {
3761
+ key: "getPrintOrderIdentity",
3762
+ value: function getPrintOrderIdentity(order) {
3763
+ return (order === null || order === void 0 ? void 0 : order.order_id) || (order === null || order === void 0 ? void 0 : order.external_sale_number) || (order === null || order === void 0 ? void 0 : order.shop_order_number) || (order === null || order === void 0 ? void 0 : order.shop_full_order_number);
3764
+ }
3765
+ }, {
3766
+ key: "dispatchLocalReceiptPrint",
3767
+ value: function () {
3768
+ var _dispatchLocalReceiptPrint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3769
+ var _payment_info;
3770
+ var printableOrder;
3771
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3772
+ while (1) switch (_context40.prev = _context40.next) {
3773
+ case 0:
3774
+ if (!(params.requireFullyPaid && !this.isSalesOrderFullyPaid(params.order))) {
3775
+ _context40.next = 2;
3776
+ break;
3777
+ }
3778
+ return _context40.abrupt("return", {
3779
+ printed: false,
3780
+ order: params.order
3781
+ });
3782
+ case 2:
3783
+ _context40.next = 4;
3784
+ return this.withLocalSmallTicketData(params.order, {
3785
+ requireFullyPaid: params.requireFullyPaid
3786
+ });
3787
+ case 4:
3788
+ printableOrder = _context40.sent;
3789
+ if (hasSmallTicketData((_payment_info = printableOrder.payment_info) === null || _payment_info === void 0 ? void 0 : _payment_info.small_ticket_data)) {
3790
+ _context40.next = 7;
3791
+ break;
3792
+ }
3793
+ return _context40.abrupt("return", {
3794
+ printed: false,
3795
+ order: printableOrder
3796
+ });
3797
+ case 7:
3798
+ _context40.next = 9;
3799
+ return this.dispatchPrintOtherReceiptTask({
3800
+ checkoutData: params.checkoutData,
3801
+ syncedOrder: printableOrder,
3802
+ response: params.response,
3803
+ receiptOnly: true
3804
+ });
3805
+ case 9:
3806
+ return _context40.abrupt("return", {
3807
+ printed: true,
3808
+ order: printableOrder
3809
+ });
3810
+ case 10:
3811
+ case "end":
3812
+ return _context40.stop();
2862
3813
  }
2863
- }, _callee29, this, [[3, 23]]);
3814
+ }, _callee40, this);
2864
3815
  }));
2865
- function fetchBookingListFromAPI(_x28) {
2866
- return _fetchBookingListFromAPI.apply(this, arguments);
3816
+ function dispatchLocalReceiptPrint(_x44) {
3817
+ return _dispatchLocalReceiptPrint.apply(this, arguments);
2867
3818
  }
2868
- return fetchBookingListFromAPI;
2869
- }())
3819
+ return dispatchLocalReceiptPrint;
3820
+ }()
2870
3821
  }, {
2871
3822
  key: "handleOrderCheckoutSubmit",
2872
3823
  value: function () {
2873
- var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2874
- var _this$app5;
2875
- var backendPath, data, title, response, fresh, syncedOrder, errorMessage, backendError;
2876
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2877
- while (1) switch (_context30.prev = _context30.next) {
3824
+ var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3825
+ var backendPath, data, title, checkoutData, pendingResult, pendingOrder;
3826
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3827
+ while (1) switch (_context41.prev = _context41.next) {
2878
3828
  case 0:
2879
3829
  backendPath = params.backendPath, data = params.data, title = params.title;
2880
3830
  this.logInfo("".concat(title, ": \u5F00\u59CB\u5904\u7406"), {
@@ -2883,79 +3833,51 @@ var Server = /*#__PURE__*/function () {
2883
3833
  external_sale_number: data === null || data === void 0 ? void 0 : data.external_sale_number,
2884
3834
  order_number: data === null || data === void 0 ? void 0 : data.order_number
2885
3835
  });
2886
- if ((_this$app5 = this.app) !== null && _this$app5 !== void 0 && _this$app5.request) {
2887
- _context30.next = 5;
2888
- break;
2889
- }
2890
- this.logError("".concat(title, ": app.request \u4E0D\u53EF\u7528"));
2891
- return _context30.abrupt("return", this.handlePendingSyncCheckoutOrder({
3836
+ _context41.next = 4;
3837
+ return this.ensureCheckoutOrderNumbers(data, title);
3838
+ case 4:
3839
+ checkoutData = _context41.sent;
3840
+ _context41.next = 7;
3841
+ return this.handlePendingSyncCheckoutOrder({
2892
3842
  backendPath: backendPath,
2893
- data: data,
3843
+ data: checkoutData,
2894
3844
  title: title,
2895
- reason: 'app.request 不可用'
2896
- }));
2897
- case 5:
2898
- _context30.prev = 5;
2899
- _context30.next = 8;
2900
- return this.app.request.post(backendPath, data, {
2901
- isShopApi: true,
2902
- customToast: function customToast() {}
3845
+ reason: 'checkout 已转入设备任务同步'
2903
3846
  });
2904
- case 8:
2905
- response = _context30.sent;
2906
- fresh = this.extractOrderDataFromCheckoutResponse(response);
2907
- if (!(fresh && this.order)) {
2908
- _context30.next = 17;
3847
+ case 7:
3848
+ pendingResult = _context41.sent;
3849
+ if (!((pendingResult === null || pendingResult === void 0 ? void 0 : pendingResult.status) === true)) {
3850
+ _context41.next = 15;
2909
3851
  break;
2910
3852
  }
2911
- syncedOrder = _objectSpread(_objectSpread({}, fresh), {}, {
2912
- need_sync: 0
2913
- });
2914
- _context30.next = 14;
2915
- return this.order.upsertOrdersFromRemote([syncedOrder]);
2916
- case 14:
2917
- this.logInfo("".concat(title, ": \u8BA2\u5355\u5DF2\u540C\u6B65\u5230\u672C\u5730"), {
2918
- order_id: fresh.order_id,
2919
- external_sale_number: fresh.external_sale_number,
2920
- order_number: fresh.order_number
2921
- });
2922
- _context30.next = 18;
2923
- break;
2924
- case 17:
2925
- this.logWarning("".concat(title, ": checkout \u8FD4\u56DE\u672A\u5305\u542B\u53EF\u540C\u6B65\u8BA2\u5355"), {
2926
- hasOrderModule: !!this.order,
2927
- backendPath: backendPath
2928
- });
2929
- case 18:
2930
- return _context30.abrupt("return", this.normalizeCheckoutResponse(response));
2931
- case 21:
2932
- _context30.prev = 21;
2933
- _context30.t0 = _context30["catch"](5);
2934
- errorMessage = _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0);
2935
- this.logError("".concat(title, ": \u8BF7\u6C42\u5931\u8D25"), {
2936
- backendPath: backendPath,
2937
- error: errorMessage
2938
- });
2939
- backendError = this.extractBackendErrorResponse(_context30.t0);
2940
- if (!backendError) {
2941
- _context30.next = 28;
3853
+ pendingOrder = pendingResult.data;
3854
+ if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder))) {
3855
+ _context41.next = 13;
2942
3856
  break;
2943
3857
  }
2944
- return _context30.abrupt("return", backendError);
2945
- case 28:
2946
- return _context30.abrupt("return", this.handlePendingSyncCheckoutOrder({
3858
+ _context41.next = 13;
3859
+ return this.dispatchLocalReceiptPrint({
3860
+ checkoutData: checkoutData,
3861
+ order: pendingOrder,
3862
+ response: pendingResult,
3863
+ requireFullyPaid: true
3864
+ });
3865
+ case 13:
3866
+ _context41.next = 15;
3867
+ return this.dispatchCheckoutSyncTask({
2947
3868
  backendPath: backendPath,
2948
- data: data,
2949
- title: title,
2950
- reason: errorMessage
2951
- }));
2952
- case 29:
3869
+ data: checkoutData,
3870
+ title: title
3871
+ });
3872
+ case 15:
3873
+ return _context41.abrupt("return", pendingResult);
3874
+ case 16:
2953
3875
  case "end":
2954
- return _context30.stop();
3876
+ return _context41.stop();
2955
3877
  }
2956
- }, _callee30, this, [[5, 21]]);
3878
+ }, _callee41, this);
2957
3879
  }));
2958
- function handleOrderCheckoutSubmit(_x29) {
3880
+ function handleOrderCheckoutSubmit(_x45) {
2959
3881
  return _handleOrderCheckoutSubmit.apply(this, arguments);
2960
3882
  }
2961
3883
  return handleOrderCheckoutSubmit;
@@ -2963,96 +3885,314 @@ var Server = /*#__PURE__*/function () {
2963
3885
  }, {
2964
3886
  key: "handlePendingSyncCheckoutOrder",
2965
3887
  value: function () {
2966
- var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3888
+ var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
2967
3889
  var backendPath, data, title, reason, pendingOrder, errorMessage;
2968
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2969
- while (1) switch (_context31.prev = _context31.next) {
3890
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3891
+ while (1) switch (_context42.prev = _context42.next) {
2970
3892
  case 0:
2971
3893
  backendPath = params.backendPath, data = params.data, title = params.title, reason = params.reason;
2972
- pendingOrder = this.buildPendingSyncCheckoutOrder(data);
3894
+ _context42.next = 3;
3895
+ return this.buildPendingSyncCheckoutOrder(data);
3896
+ case 3:
3897
+ pendingOrder = _context42.sent;
2973
3898
  if (pendingOrder) {
2974
- _context31.next = 5;
3899
+ _context42.next = 7;
2975
3900
  break;
2976
3901
  }
2977
3902
  this.logError("".concat(title, ": checkout \u5931\u8D25\u4E14\u8BA2\u5355\u7F3A\u5C11\u672C\u5730\u5B58\u50A8\u6807\u8BC6"), {
2978
3903
  backendPath: backendPath,
2979
3904
  reason: reason
2980
3905
  });
2981
- return _context31.abrupt("return", {
3906
+ return _context42.abrupt("return", {
2982
3907
  code: 500,
2983
3908
  status: false,
2984
3909
  message: '订单缺少本地存储标识,无法写入待同步队列',
2985
3910
  data: null
2986
3911
  });
2987
- case 5:
3912
+ case 7:
2988
3913
  if (!(!this.order || typeof this.order.upsertPendingSyncOrders !== 'function')) {
2989
- _context31.next = 8;
3914
+ _context42.next = 10;
2990
3915
  break;
2991
3916
  }
2992
3917
  this.logError("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u5F85\u540C\u6B65\u5199\u5165"), {
2993
3918
  backendPath: backendPath,
2994
3919
  reason: reason
2995
3920
  });
2996
- return _context31.abrupt("return", {
3921
+ return _context42.abrupt("return", {
2997
3922
  code: 500,
2998
3923
  status: false,
2999
3924
  message: 'Order 模块不支持本地待同步写入',
3000
3925
  data: null
3001
3926
  });
3002
- case 8:
3003
- _context31.prev = 8;
3004
- _context31.next = 11;
3927
+ case 10:
3928
+ _context42.prev = 10;
3929
+ _context42.next = 13;
3005
3930
  return this.order.upsertPendingSyncOrders([pendingOrder]);
3006
- case 11:
3007
- this.logWarning("".concat(title, ": \u540E\u7AEF\u672A\u660E\u786E\u62A5\u9519\uFF0C\u8BA2\u5355\u5DF2\u5199\u5165\u672C\u5730\u5F85\u540C\u6B65"), {
3931
+ case 13:
3932
+ this.logWarning("".concat(title, ": \u8BA2\u5355\u5DF2\u5199\u5165\u672C\u5730\u5F85\u540C\u6B65"), {
3008
3933
  backendPath: backendPath,
3009
3934
  reason: reason,
3010
3935
  order_id: pendingOrder.order_id,
3011
3936
  external_sale_number: pendingOrder.external_sale_number,
3012
3937
  order_number: pendingOrder.order_number
3013
3938
  });
3014
- return _context31.abrupt("return", {
3939
+ return _context42.abrupt("return", {
3015
3940
  code: 200,
3016
3941
  status: true,
3017
3942
  message: '',
3018
3943
  data: pendingOrder
3019
3944
  });
3020
- case 15:
3021
- _context31.prev = 15;
3022
- _context31.t0 = _context31["catch"](8);
3023
- errorMessage = _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0);
3945
+ case 17:
3946
+ _context42.prev = 17;
3947
+ _context42.t0 = _context42["catch"](10);
3948
+ errorMessage = _context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0);
3024
3949
  this.logError("".concat(title, ": \u5199\u5165\u672C\u5730\u5F85\u540C\u6B65\u8BA2\u5355\u5931\u8D25"), {
3025
3950
  backendPath: backendPath,
3026
3951
  reason: reason,
3027
3952
  error: errorMessage
3028
3953
  });
3029
- return _context31.abrupt("return", {
3954
+ return _context42.abrupt("return", {
3030
3955
  code: 500,
3031
3956
  status: false,
3032
3957
  message: errorMessage,
3033
3958
  data: null
3034
3959
  });
3035
- case 20:
3960
+ case 22:
3036
3961
  case "end":
3037
- return _context31.stop();
3962
+ return _context42.stop();
3038
3963
  }
3039
- }, _callee31, this, [[8, 15]]);
3964
+ }, _callee42, this, [[10, 17]]);
3040
3965
  }));
3041
- function handlePendingSyncCheckoutOrder(_x30) {
3966
+ function handlePendingSyncCheckoutOrder(_x46) {
3042
3967
  return _handlePendingSyncCheckoutOrder.apply(this, arguments);
3043
3968
  }
3044
3969
  return handlePendingSyncCheckoutOrder;
3045
3970
  }()
3046
3971
  }, {
3047
3972
  key: "buildPendingSyncCheckoutOrder",
3048
- value: function buildPendingSyncCheckoutOrder(data) {
3049
- if (!data || _typeof(data) !== 'object') return null;
3050
- var hasStorageKey = data.external_sale_number !== undefined && data.external_sale_number !== null && data.external_sale_number !== '' ? true : data.order_id !== undefined && data.order_id !== null && data.order_id !== '';
3051
- if (!hasStorageKey) return null;
3052
- return _objectSpread(_objectSpread({}, data), {}, {
3053
- need_sync: 1
3054
- });
3973
+ value: function () {
3974
+ var _buildPendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(data) {
3975
+ var hasStorageKey;
3976
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3977
+ while (1) switch (_context43.prev = _context43.next) {
3978
+ case 0:
3979
+ if (!(!data || _typeof(data) !== 'object')) {
3980
+ _context43.next = 2;
3981
+ break;
3982
+ }
3983
+ return _context43.abrupt("return", null);
3984
+ case 2:
3985
+ hasStorageKey = data.external_sale_number !== undefined && data.external_sale_number !== null && data.external_sale_number !== '' ? true : data.order_id !== undefined && data.order_id !== null && data.order_id !== '';
3986
+ if (hasStorageKey) {
3987
+ _context43.next = 5;
3988
+ break;
3989
+ }
3990
+ return _context43.abrupt("return", null);
3991
+ case 5:
3992
+ return _context43.abrupt("return", this.withLocalSmallTicketData(_objectSpread(_objectSpread({}, data), {}, {
3993
+ need_sync: 1
3994
+ }), {
3995
+ requireFullyPaid: true
3996
+ }));
3997
+ case 6:
3998
+ case "end":
3999
+ return _context43.stop();
4000
+ }
4001
+ }, _callee43, this);
4002
+ }));
4003
+ function buildPendingSyncCheckoutOrder(_x47) {
4004
+ return _buildPendingSyncCheckoutOrder.apply(this, arguments);
4005
+ }
4006
+ return buildPendingSyncCheckoutOrder;
4007
+ }()
4008
+ }, {
4009
+ key: "shouldBuildSmallTicketData",
4010
+ value: function shouldBuildSmallTicketData(order) {
4011
+ var _order$payment_info, _ref50, _order$small_ticket_d;
4012
+ if (!order || _typeof(order) !== 'object') return false;
4013
+ if (hasSmallTicketData((_order$payment_info = order.payment_info) === null || _order$payment_info === void 0 ? void 0 : _order$payment_info.small_ticket_data)) return false;
4014
+ return Number((_ref50 = (_order$small_ticket_d = order.small_ticket_data_flag) !== null && _order$small_ticket_d !== void 0 ? _order$small_ticket_d : order.smallTicketDataFlag) !== null && _ref50 !== void 0 ? _ref50 : 0) === 1;
4015
+ }
4016
+ }, {
4017
+ key: "shouldPrintSyncedOrder",
4018
+ value: function shouldPrintSyncedOrder(params) {
4019
+ if (this.hasPaymentStatus(params.syncedOrder)) {
4020
+ return this.isSalesOrderFullyPaid(params.syncedOrder);
4021
+ }
4022
+ return this.isSalesOrderFullyPaid(params.checkoutData);
4023
+ }
4024
+ }, {
4025
+ key: "hasPaymentStatus",
4026
+ value: function hasPaymentStatus(order) {
4027
+ return (order === null || order === void 0 ? void 0 : order.payment_status) !== undefined && (order === null || order === void 0 ? void 0 : order.payment_status) !== null && (order === null || order === void 0 ? void 0 : order.payment_status) !== '';
4028
+ }
4029
+ }, {
4030
+ key: "isSalesOrderFullyPaid",
4031
+ value: function isSalesOrderFullyPaid(order) {
4032
+ var _order$summary$amount, _order$summary, _ref51, _ref52, _order$summary$expect, _order$summary2, _order$summary3;
4033
+ if (!order || _typeof(order) !== 'object') return false;
4034
+ var paymentStatus = String(order.payment_status || '').toLowerCase();
4035
+ if (paymentStatus === 'paid' || paymentStatus === 'finished') return true;
4036
+ if (paymentStatus === 'partially_paid' || paymentStatus === 'payment_processing' || paymentStatus === 'pending' || paymentStatus === 'unpaid') {
4037
+ return false;
4038
+ }
4039
+ var amountGap = (_order$summary$amount = (_order$summary = order.summary) === null || _order$summary === void 0 ? void 0 : _order$summary.amount_gap) !== null && _order$summary$amount !== void 0 ? _order$summary$amount : order.amount_gap;
4040
+ if (amountGap !== undefined && amountGap !== null && amountGap !== '') {
4041
+ return this.toAmountNumber(amountGap) <= 0;
4042
+ }
4043
+ var paidAmount = this.sumPaidOrderPayments(order.payments);
4044
+ var targetAmount = this.toAmountNumber((_ref51 = (_ref52 = (_order$summary$expect = (_order$summary2 = order.summary) === null || _order$summary2 === void 0 ? void 0 : _order$summary2.expect_amount) !== null && _order$summary$expect !== void 0 ? _order$summary$expect : (_order$summary3 = order.summary) === null || _order$summary3 === void 0 ? void 0 : _order$summary3.total_amount) !== null && _ref52 !== void 0 ? _ref52 : order.expect_amount) !== null && _ref51 !== void 0 ? _ref51 : order.total_amount);
4045
+ if (targetAmount <= 0) return paidAmount > 0;
4046
+ return paidAmount >= targetAmount;
3055
4047
  }
4048
+ }, {
4049
+ key: "sumPaidOrderPayments",
4050
+ value: function sumPaidOrderPayments(payments) {
4051
+ var _this10 = this;
4052
+ if (!Array.isArray(payments)) return 0;
4053
+ return payments.reduce(function (sum, payment) {
4054
+ var _payment$amount;
4055
+ var status = String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase();
4056
+ if (status === 'voided' || status === 'failed' || status === 'cancelled') return sum;
4057
+ return sum + _this10.toAmountNumber((_payment$amount = payment === null || payment === void 0 ? void 0 : payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment === null || payment === void 0 ? void 0 : payment.origin_amount);
4058
+ }, 0);
4059
+ }
4060
+ }, {
4061
+ key: "toAmountNumber",
4062
+ value: function toAmountNumber(value) {
4063
+ if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
4064
+ if (typeof value !== 'string') return 0;
4065
+ var parsed = Number(value.replace(/[^\d.-]/g, ''));
4066
+ return Number.isFinite(parsed) ? parsed : 0;
4067
+ }
4068
+ }, {
4069
+ key: "buildSmallTicketProductMap",
4070
+ value: function () {
4071
+ var _buildSmallTicketProductMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order) {
4072
+ var _this$products,
4073
+ _this11 = this;
4074
+ var products, productIds, entries;
4075
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4076
+ while (1) switch (_context45.prev = _context45.next) {
4077
+ case 0:
4078
+ products = Array.isArray(order === null || order === void 0 ? void 0 : order.products) ? order.products : [];
4079
+ productIds = Array.from(new Set(products.map(function (product) {
4080
+ var _product$product_id;
4081
+ return (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product === null || product === void 0 ? void 0 : product.id;
4082
+ }).filter(function (id) {
4083
+ return id !== undefined && id !== null && id !== '';
4084
+ })));
4085
+ if (!(!productIds.length || typeof ((_this$products = this.products) === null || _this$products === void 0 ? void 0 : _this$products.getProductById) !== 'function')) {
4086
+ _context45.next = 4;
4087
+ break;
4088
+ }
4089
+ return _context45.abrupt("return", {});
4090
+ case 4:
4091
+ _context45.next = 6;
4092
+ return Promise.all(productIds.map( /*#__PURE__*/function () {
4093
+ var _ref53 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(id) {
4094
+ var _this11$products, _this11$products$getP, product;
4095
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4096
+ while (1) switch (_context44.prev = _context44.next) {
4097
+ case 0:
4098
+ _context44.prev = 0;
4099
+ _context44.next = 3;
4100
+ return (_this11$products = _this11.products) === null || _this11$products === void 0 || (_this11$products$getP = _this11$products.getProductById) === null || _this11$products$getP === void 0 ? void 0 : _this11$products$getP.call(_this11$products, Number(id));
4101
+ case 3:
4102
+ product = _context44.sent;
4103
+ return _context44.abrupt("return", product ? [String(id), product] : null);
4104
+ case 7:
4105
+ _context44.prev = 7;
4106
+ _context44.t0 = _context44["catch"](0);
4107
+ _this11.logWarning('buildSmallTicketProductMap: 查询本地商品失败', {
4108
+ product_id: id,
4109
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
4110
+ });
4111
+ return _context44.abrupt("return", null);
4112
+ case 11:
4113
+ case "end":
4114
+ return _context44.stop();
4115
+ }
4116
+ }, _callee44, null, [[0, 7]]);
4117
+ }));
4118
+ return function (_x49) {
4119
+ return _ref53.apply(this, arguments);
4120
+ };
4121
+ }()));
4122
+ case 6:
4123
+ entries = _context45.sent;
4124
+ return _context45.abrupt("return", entries.reduce(function (map, entry) {
4125
+ if (!entry) return map;
4126
+ var _entry = _slicedToArray(entry, 2),
4127
+ id = _entry[0],
4128
+ product = _entry[1];
4129
+ map[id] = product;
4130
+ return map;
4131
+ }, {}));
4132
+ case 8:
4133
+ case "end":
4134
+ return _context45.stop();
4135
+ }
4136
+ }, _callee45, this);
4137
+ }));
4138
+ function buildSmallTicketProductMap(_x48) {
4139
+ return _buildSmallTicketProductMap.apply(this, arguments);
4140
+ }
4141
+ return buildSmallTicketProductMap;
4142
+ }()
4143
+ }, {
4144
+ key: "withLocalSmallTicketData",
4145
+ value: function () {
4146
+ var _withLocalSmallTicketData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(order, options) {
4147
+ var productMap, smallTicketData;
4148
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4149
+ while (1) switch (_context46.prev = _context46.next) {
4150
+ case 0:
4151
+ if (this.shouldBuildSmallTicketData(order)) {
4152
+ _context46.next = 2;
4153
+ break;
4154
+ }
4155
+ return _context46.abrupt("return", order);
4156
+ case 2:
4157
+ if (!(options !== null && options !== void 0 && options.requireFullyPaid && !this.isSalesOrderFullyPaid(order))) {
4158
+ _context46.next = 4;
4159
+ break;
4160
+ }
4161
+ return _context46.abrupt("return", order);
4162
+ case 4:
4163
+ _context46.prev = 4;
4164
+ _context46.next = 7;
4165
+ return this.buildSmallTicketProductMap(order);
4166
+ case 7:
4167
+ productMap = _context46.sent;
4168
+ smallTicketData = buildSmallTicketData({
4169
+ order: order,
4170
+ shopInfo: this.getSmallTicketShopInfo(),
4171
+ productMap: productMap
4172
+ });
4173
+ return _context46.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
4174
+ payment_info: _objectSpread(_objectSpread({}, order.payment_info || {}), {}, {
4175
+ small_ticket_data: smallTicketData
4176
+ })
4177
+ }));
4178
+ case 12:
4179
+ _context46.prev = 12;
4180
+ _context46.t0 = _context46["catch"](4);
4181
+ this.logError('withLocalSmallTicketData: 生成本地小票数据失败', {
4182
+ error: _context46.t0 instanceof Error ? _context46.t0.message : String(_context46.t0)
4183
+ });
4184
+ return _context46.abrupt("return", order);
4185
+ case 16:
4186
+ case "end":
4187
+ return _context46.stop();
4188
+ }
4189
+ }, _callee46, this, [[4, 12]]);
4190
+ }));
4191
+ function withLocalSmallTicketData(_x50, _x51) {
4192
+ return _withLocalSmallTicketData.apply(this, arguments);
4193
+ }
4194
+ return withLocalSmallTicketData;
4195
+ }()
3056
4196
  }, {
3057
4197
  key: "parseOrderIdsParam",
3058
4198
  value:
@@ -3090,8 +4230,8 @@ var Server = /*#__PURE__*/function () {
3090
4230
  pushRaw(this.extractQueryParam(url, 'order_ids'));
3091
4231
  var seen = new Set();
3092
4232
  var result = [];
3093
- for (var _i = 0, _collected = collected; _i < _collected.length; _i++) {
3094
- var id = _collected[_i];
4233
+ for (var _i2 = 0, _collected = collected; _i2 < _collected.length; _i2++) {
4234
+ var id = _collected[_i2];
3095
4235
  if (seen.has(id)) continue;
3096
4236
  seen.add(id);
3097
4237
  result.push(id);
@@ -3110,34 +4250,34 @@ var Server = /*#__PURE__*/function () {
3110
4250
  }, {
3111
4251
  key: "handleUpdateLocalOrdersBatch",
3112
4252
  value: (function () {
3113
- var _handleUpdateLocalOrdersBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(orderIds) {
3114
- var _this$app6;
3115
- var existedBefore, _iterator11, _step11, id, fetched, message, fetchedMap, _iterator12, _step12, order, oid, freshOrders, succeedIds, failed, _iterator13, _step13, _id, fresh, _message, overwritten, inserted;
3116
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3117
- while (1) switch (_context32.prev = _context32.next) {
4253
+ var _handleUpdateLocalOrdersBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(orderIds) {
4254
+ var _this$app14;
4255
+ var existedBefore, _iterator12, _step12, id, fetched, message, fetchedMap, _iterator13, _step13, order, oid, freshOrders, succeedIds, failed, _iterator14, _step14, _id, fresh, _message2, overwritten, inserted;
4256
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4257
+ while (1) switch (_context47.prev = _context47.next) {
3118
4258
  case 0:
3119
4259
  this.logInfo('handleUpdateLocalOrdersBatch: 开始处理', {
3120
4260
  count: orderIds.length,
3121
4261
  orderIds: orderIds
3122
4262
  });
3123
4263
  if (this.order) {
3124
- _context32.next = 4;
4264
+ _context47.next = 4;
3125
4265
  break;
3126
4266
  }
3127
4267
  this.logError('handleUpdateLocalOrdersBatch: Order 模块未注册');
3128
- return _context32.abrupt("return", {
4268
+ return _context47.abrupt("return", {
3129
4269
  code: 500,
3130
4270
  status: false,
3131
4271
  message: 'Order 模块未注册',
3132
4272
  data: null
3133
4273
  });
3134
4274
  case 4:
3135
- if ((_this$app6 = this.app) !== null && _this$app6 !== void 0 && _this$app6.request) {
3136
- _context32.next = 7;
4275
+ if ((_this$app14 = this.app) !== null && _this$app14 !== void 0 && _this$app14.request) {
4276
+ _context47.next = 7;
3137
4277
  break;
3138
4278
  }
3139
4279
  this.logError('handleUpdateLocalOrdersBatch: app.request 不可用');
3140
- return _context32.abrupt("return", {
4280
+ return _context47.abrupt("return", {
3141
4281
  code: 500,
3142
4282
  status: false,
3143
4283
  message: 'app.request 不可用',
@@ -3146,35 +4286,35 @@ var Server = /*#__PURE__*/function () {
3146
4286
  case 7:
3147
4287
  // 拉取前先记录"本地是否已存在",用于区分 overwritten / inserted
3148
4288
  existedBefore = new Map();
3149
- _iterator11 = _createForOfIteratorHelper(orderIds);
4289
+ _iterator12 = _createForOfIteratorHelper(orderIds);
3150
4290
  try {
3151
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3152
- id = _step11.value;
4291
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
4292
+ id = _step12.value;
3153
4293
  existedBefore.set(id, !!this.order.getOrderByOrderId(id));
3154
4294
  }
3155
4295
 
3156
4296
  // 走 orderDataSource 的批量 HTTP 通道,一次请求拉回多笔详情
3157
4297
  } catch (err) {
3158
- _iterator11.e(err);
4298
+ _iterator12.e(err);
3159
4299
  } finally {
3160
- _iterator11.f();
4300
+ _iterator12.f();
3161
4301
  }
3162
4302
  fetched = [];
3163
- _context32.prev = 11;
3164
- _context32.next = 14;
4303
+ _context47.prev = 11;
4304
+ _context47.next = 14;
3165
4305
  return this.order.fetchOrdersByHttp(orderIds);
3166
4306
  case 14:
3167
- fetched = _context32.sent;
3168
- _context32.next = 22;
4307
+ fetched = _context47.sent;
4308
+ _context47.next = 22;
3169
4309
  break;
3170
4310
  case 17:
3171
- _context32.prev = 17;
3172
- _context32.t0 = _context32["catch"](11);
3173
- message = _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0);
4311
+ _context47.prev = 17;
4312
+ _context47.t0 = _context47["catch"](11);
4313
+ message = _context47.t0 instanceof Error ? _context47.t0.message : String(_context47.t0);
3174
4314
  this.logError('handleUpdateLocalOrdersBatch: 批量拉取失败', {
3175
4315
  message: message
3176
4316
  });
3177
- return _context32.abrupt("return", {
4317
+ return _context47.abrupt("return", {
3178
4318
  code: 500,
3179
4319
  status: false,
3180
4320
  message: message,
@@ -3183,45 +4323,45 @@ var Server = /*#__PURE__*/function () {
3183
4323
  case 22:
3184
4324
  // 按返回结果中的 order_id 建索引,未命中即视为单笔失败
3185
4325
  fetchedMap = new Map();
3186
- _iterator12 = _createForOfIteratorHelper(fetched);
3187
- _context32.prev = 24;
3188
- _iterator12.s();
4326
+ _iterator13 = _createForOfIteratorHelper(fetched);
4327
+ _context47.prev = 24;
4328
+ _iterator13.s();
3189
4329
  case 26:
3190
- if ((_step12 = _iterator12.n()).done) {
3191
- _context32.next = 34;
4330
+ if ((_step13 = _iterator13.n()).done) {
4331
+ _context47.next = 34;
3192
4332
  break;
3193
4333
  }
3194
- order = _step12.value;
4334
+ order = _step13.value;
3195
4335
  oid = order === null || order === void 0 ? void 0 : order.order_id;
3196
4336
  if (!(oid === undefined || oid === null)) {
3197
- _context32.next = 31;
4337
+ _context47.next = 31;
3198
4338
  break;
3199
4339
  }
3200
- return _context32.abrupt("continue", 32);
4340
+ return _context47.abrupt("continue", 32);
3201
4341
  case 31:
3202
4342
  fetchedMap.set(String(oid), order);
3203
4343
  case 32:
3204
- _context32.next = 26;
4344
+ _context47.next = 26;
3205
4345
  break;
3206
4346
  case 34:
3207
- _context32.next = 39;
4347
+ _context47.next = 39;
3208
4348
  break;
3209
4349
  case 36:
3210
- _context32.prev = 36;
3211
- _context32.t1 = _context32["catch"](24);
3212
- _iterator12.e(_context32.t1);
4350
+ _context47.prev = 36;
4351
+ _context47.t1 = _context47["catch"](24);
4352
+ _iterator13.e(_context47.t1);
3213
4353
  case 39:
3214
- _context32.prev = 39;
3215
- _iterator12.f();
3216
- return _context32.finish(39);
4354
+ _context47.prev = 39;
4355
+ _iterator13.f();
4356
+ return _context47.finish(39);
3217
4357
  case 42:
3218
4358
  freshOrders = [];
3219
4359
  succeedIds = [];
3220
4360
  failed = [];
3221
- _iterator13 = _createForOfIteratorHelper(orderIds);
4361
+ _iterator14 = _createForOfIteratorHelper(orderIds);
3222
4362
  try {
3223
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3224
- _id = _step13.value;
4363
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
4364
+ _id = _step14.value;
3225
4365
  fresh = fetchedMap.get(_id);
3226
4366
  if (fresh) {
3227
4367
  freshOrders.push(fresh);
@@ -3234,31 +4374,31 @@ var Server = /*#__PURE__*/function () {
3234
4374
  }
3235
4375
  }
3236
4376
  } catch (err) {
3237
- _iterator13.e(err);
4377
+ _iterator14.e(err);
3238
4378
  } finally {
3239
- _iterator13.f();
4379
+ _iterator14.f();
3240
4380
  }
3241
4381
  if (!(freshOrders.length > 0)) {
3242
- _context32.next = 58;
4382
+ _context47.next = 58;
3243
4383
  break;
3244
4384
  }
3245
- _context32.prev = 48;
3246
- _context32.next = 51;
4385
+ _context47.prev = 48;
4386
+ _context47.next = 51;
3247
4387
  return this.order.upsertOrdersFromRemote(freshOrders);
3248
4388
  case 51:
3249
- _context32.next = 58;
4389
+ _context47.next = 58;
3250
4390
  break;
3251
4391
  case 53:
3252
- _context32.prev = 53;
3253
- _context32.t2 = _context32["catch"](48);
3254
- _message = _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2);
4392
+ _context47.prev = 53;
4393
+ _context47.t2 = _context47["catch"](48);
4394
+ _message2 = _context47.t2 instanceof Error ? _context47.t2.message : String(_context47.t2);
3255
4395
  this.logError('handleUpdateLocalOrdersBatch: 合并写入失败', {
3256
- message: _message
4396
+ message: _message2
3257
4397
  });
3258
- return _context32.abrupt("return", {
4398
+ return _context47.abrupt("return", {
3259
4399
  code: 500,
3260
4400
  status: false,
3261
- message: _message,
4401
+ message: _message2,
3262
4402
  data: null
3263
4403
  });
3264
4404
  case 58:
@@ -3274,7 +4414,7 @@ var Server = /*#__PURE__*/function () {
3274
4414
  insertedCount: inserted.length,
3275
4415
  failedCount: failed.length
3276
4416
  });
3277
- return _context32.abrupt("return", {
4417
+ return _context47.abrupt("return", {
3278
4418
  code: 200,
3279
4419
  status: true,
3280
4420
  message: '',
@@ -3286,11 +4426,11 @@ var Server = /*#__PURE__*/function () {
3286
4426
  });
3287
4427
  case 62:
3288
4428
  case "end":
3289
- return _context32.stop();
4429
+ return _context47.stop();
3290
4430
  }
3291
- }, _callee32, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
4431
+ }, _callee47, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
3292
4432
  }));
3293
- function handleUpdateLocalOrdersBatch(_x31) {
4433
+ function handleUpdateLocalOrdersBatch(_x52) {
3294
4434
  return _handleUpdateLocalOrdersBatch.apply(this, arguments);
3295
4435
  }
3296
4436
  return handleUpdateLocalOrdersBatch;
@@ -3311,11 +4451,11 @@ var Server = /*#__PURE__*/function () {
3311
4451
  var queryIndex = url.indexOf('?');
3312
4452
  if (queryIndex < 0) return null;
3313
4453
  var query = url.slice(queryIndex + 1);
3314
- var _iterator14 = _createForOfIteratorHelper(query.split('&')),
3315
- _step14;
4454
+ var _iterator15 = _createForOfIteratorHelper(query.split('&')),
4455
+ _step15;
3316
4456
  try {
3317
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3318
- var pair = _step14.value;
4457
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
4458
+ var pair = _step15.value;
3319
4459
  if (!pair) continue;
3320
4460
  var _pair$split = pair.split('='),
3321
4461
  _pair$split2 = _slicedToArray(_pair$split, 2),
@@ -3331,9 +4471,9 @@ var Server = /*#__PURE__*/function () {
3331
4471
  }
3332
4472
  }
3333
4473
  } catch (err) {
3334
- _iterator14.e(err);
4474
+ _iterator15.e(err);
3335
4475
  } finally {
3336
- _iterator14.f();
4476
+ _iterator15.f();
3337
4477
  }
3338
4478
  return null;
3339
4479
  }
@@ -3367,10 +4507,10 @@ var Server = /*#__PURE__*/function () {
3367
4507
  }, {
3368
4508
  key: "extractOrderDataFromCheckoutResponse",
3369
4509
  value: function extractOrderDataFromCheckoutResponse(response) {
3370
- var _response$data4, _response$data5;
3371
- var candidates = [response === null || response === void 0 || (_response$data4 = response.data) === null || _response$data4 === void 0 ? void 0 : _response$data4.order, response === null || response === void 0 || (_response$data5 = response.data) === null || _response$data5 === void 0 ? void 0 : _response$data5.sales, response === null || response === void 0 ? void 0 : response.data, response === null || response === void 0 ? void 0 : response.order, response === null || response === void 0 ? void 0 : response.sales, response];
3372
- for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
3373
- var candidate = _candidates[_i2];
4510
+ var _response$data5, _response$data6;
4511
+ var candidates = [response === null || response === void 0 || (_response$data5 = response.data) === null || _response$data5 === void 0 ? void 0 : _response$data5.order, response === null || response === void 0 || (_response$data6 = response.data) === null || _response$data6 === void 0 ? void 0 : _response$data6.sales, response === null || response === void 0 ? void 0 : response.data, response === null || response === void 0 ? void 0 : response.order, response === null || response === void 0 ? void 0 : response.sales, response];
4512
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
4513
+ var candidate = _candidates[_i3];
3374
4514
  if (!candidate || _typeof(candidate) !== 'object') continue;
3375
4515
  if (candidate.order_id !== undefined && candidate.order_id !== null) {
3376
4516
  return candidate;
@@ -3391,15 +4531,24 @@ var Server = /*#__PURE__*/function () {
3391
4531
  data: response
3392
4532
  };
3393
4533
  }
4534
+ }, {
4535
+ key: "isCheckoutResponseRejected",
4536
+ value: function isCheckoutResponseRejected(response) {
4537
+ var normalized = this.normalizeCheckoutResponse(response);
4538
+ var isErrorCode = (normalized === null || normalized === void 0 ? void 0 : normalized.code) !== undefined && normalized.code !== 200 && normalized.code !== '200';
4539
+ var isErrorStatus = (normalized === null || normalized === void 0 ? void 0 : normalized.status) === false || typeof (normalized === null || normalized === void 0 ? void 0 : normalized.status) === 'number' && normalized.status >= 400;
4540
+ var isErrorSuccess = (normalized === null || normalized === void 0 ? void 0 : normalized.success) === false;
4541
+ return isErrorCode || isErrorStatus || isErrorSuccess;
4542
+ }
3394
4543
  }, {
3395
4544
  key: "extractBackendErrorResponse",
3396
4545
  value: function extractBackendErrorResponse(error) {
3397
4546
  var _error$response,
3398
4547
  _error$response2,
3399
- _this7 = this;
4548
+ _this12 = this;
3400
4549
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
3401
4550
  return candidates.find(function (candidate) {
3402
- return _this7.isExplicitBackendErrorResponse(candidate);
4551
+ return _this12.isExplicitBackendErrorResponse(candidate);
3403
4552
  }) || null;
3404
4553
  }
3405
4554
  }, {
@@ -3518,24 +4667,24 @@ var Server = /*#__PURE__*/function () {
3518
4667
  }, {
3519
4668
  key: "recomputeAndNotifyFloorPlanQuery",
3520
4669
  value: (function () {
3521
- var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
3522
- var _iterator15, _step15, _step15$value, subscriberId, sub, result, errorMessage;
3523
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3524
- while (1) switch (_context33.prev = _context33.next) {
4670
+ var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48() {
4671
+ var _iterator16, _step16, _step16$value, subscriberId, sub, result, errorMessage;
4672
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4673
+ while (1) switch (_context48.prev = _context48.next) {
3525
4674
  case 0:
3526
4675
  if (!(this.floorPlanQuerySubscribers.size === 0)) {
3527
- _context33.next = 2;
4676
+ _context48.next = 2;
3528
4677
  break;
3529
4678
  }
3530
- return _context33.abrupt("return");
4679
+ return _context48.abrupt("return");
3531
4680
  case 2:
3532
4681
  this.logInfo('recomputeAndNotifyFloorPlanQuery: 开始推送', {
3533
4682
  subscriberCount: this.floorPlanQuerySubscribers.size
3534
4683
  });
3535
- _iterator15 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
4684
+ _iterator16 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
3536
4685
  try {
3537
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
3538
- _step15$value = _slicedToArray(_step15.value, 2), subscriberId = _step15$value[0], sub = _step15$value[1];
4686
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
4687
+ _step16$value = _slicedToArray(_step16.value, 2), subscriberId = _step16$value[0], sub = _step16$value[1];
3539
4688
  try {
3540
4689
  result = this.computeFloorPlanQueryResult(sub.context);
3541
4690
  sub.callback(result);
@@ -3551,15 +4700,15 @@ var Server = /*#__PURE__*/function () {
3551
4700
  }
3552
4701
  }
3553
4702
  } catch (err) {
3554
- _iterator15.e(err);
4703
+ _iterator16.e(err);
3555
4704
  } finally {
3556
- _iterator15.f();
4705
+ _iterator16.f();
3557
4706
  }
3558
4707
  case 5:
3559
4708
  case "end":
3560
- return _context33.stop();
4709
+ return _context48.stop();
3561
4710
  }
3562
- }, _callee33, this);
4711
+ }, _callee48, this);
3563
4712
  }));
3564
4713
  function recomputeAndNotifyFloorPlanQuery() {
3565
4714
  return _recomputeAndNotifyFloorPlanQuery.apply(this, arguments);
@@ -3589,21 +4738,21 @@ var Server = /*#__PURE__*/function () {
3589
4738
  * filter 逻辑暂为 mock,仅记录参数
3590
4739
  */
3591
4740
  function () {
3592
- var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(data) {
4741
+ var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(data) {
3593
4742
  var rawList, result;
3594
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3595
- while (1) switch (_context34.prev = _context34.next) {
4743
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4744
+ while (1) switch (_context49.prev = _context49.next) {
3596
4745
  case 0:
3597
4746
  this.logInfo('computeOrderQueryResult: 开始过滤', {
3598
4747
  data: data
3599
4748
  });
3600
4749
  console.log('[Server] computeOrderQueryResult', data);
3601
4750
  if (this.order) {
3602
- _context34.next = 5;
4751
+ _context49.next = 5;
3603
4752
  break;
3604
4753
  }
3605
4754
  this.logError('computeOrderQueryResult: Order 模块未注册');
3606
- return _context34.abrupt("return", {
4755
+ return _context49.abrupt("return", {
3607
4756
  code: 500,
3608
4757
  message: 'Order 模块未注册',
3609
4758
  data: {
@@ -3627,7 +4776,7 @@ var Server = /*#__PURE__*/function () {
3627
4776
  skip: result.skip,
3628
4777
  rejected: result.rejected
3629
4778
  });
3630
- return _context34.abrupt("return", {
4779
+ return _context49.abrupt("return", {
3631
4780
  code: 200,
3632
4781
  data: result,
3633
4782
  message: '',
@@ -3635,11 +4784,11 @@ var Server = /*#__PURE__*/function () {
3635
4784
  });
3636
4785
  case 10:
3637
4786
  case "end":
3638
- return _context34.stop();
4787
+ return _context49.stop();
3639
4788
  }
3640
- }, _callee34, this);
4789
+ }, _callee49, this);
3641
4790
  }));
3642
- function computeOrderQueryResult(_x32) {
4791
+ function computeOrderQueryResult(_x53) {
3643
4792
  return _computeOrderQueryResult.apply(this, arguments);
3644
4793
  }
3645
4794
  return computeOrderQueryResult;
@@ -3652,17 +4801,17 @@ var Server = /*#__PURE__*/function () {
3652
4801
  }, {
3653
4802
  key: "computeBookingQueryResult",
3654
4803
  value: (function () {
3655
- var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
4804
+ var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(data) {
3656
4805
  var rawOrders, result;
3657
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3658
- while (1) switch (_context35.prev = _context35.next) {
4806
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4807
+ while (1) switch (_context50.prev = _context50.next) {
3659
4808
  case 0:
3660
4809
  if (this.order) {
3661
- _context35.next = 3;
4810
+ _context50.next = 3;
3662
4811
  break;
3663
4812
  }
3664
4813
  this.logError('computeBookingQueryResult: Order 模块未注册');
3665
- return _context35.abrupt("return", {
4814
+ return _context50.abrupt("return", {
3666
4815
  code: 500,
3667
4816
  message: 'Order 模块未注册',
3668
4817
  data: {
@@ -3681,7 +4830,7 @@ var Server = /*#__PURE__*/function () {
3681
4830
  size: result.size,
3682
4831
  skip: result.skip
3683
4832
  });
3684
- return _context35.abrupt("return", {
4833
+ return _context50.abrupt("return", {
3685
4834
  code: 200,
3686
4835
  data: result,
3687
4836
  message: '',
@@ -3689,11 +4838,11 @@ var Server = /*#__PURE__*/function () {
3689
4838
  });
3690
4839
  case 8:
3691
4840
  case "end":
3692
- return _context35.stop();
4841
+ return _context50.stop();
3693
4842
  }
3694
- }, _callee35, this);
4843
+ }, _callee50, this);
3695
4844
  }));
3696
- function computeBookingQueryResult(_x33) {
4845
+ function computeBookingQueryResult(_x54) {
3697
4846
  return _computeBookingQueryResult.apply(this, arguments);
3698
4847
  }
3699
4848
  return computeBookingQueryResult;
@@ -3709,12 +4858,12 @@ var Server = /*#__PURE__*/function () {
3709
4858
  }, {
3710
4859
  key: "computeProductQueryResult",
3711
4860
  value: (function () {
3712
- var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(context, options) {
4861
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(context, options) {
3713
4862
  var _menu_list_ids$length3,
3714
- _this8 = this;
4863
+ _this13 = this;
3715
4864
  var tTotal, menu_list_ids, ids, schedule_date, schedule_datetime, customer_id, product_id, queryIds, uniqueIds, _tPrice, productsWithPrice, _filteredProducts, _published$find, pid, _tPrice2, allProductsWithPrice, published, item, activeMenuList, tMenu, menuList, tFilter, productScope, scopedProductIds, tPrice, filteredProducts, tStatus, beforeStatusCount, tSort;
3716
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3717
- while (1) switch (_context36.prev = _context36.next) {
4865
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4866
+ while (1) switch (_context51.prev = _context51.next) {
3718
4867
  case 0:
3719
4868
  tTotal = performance.now();
3720
4869
  menu_list_ids = context.menu_list_ids, ids = context.ids, schedule_date = context.schedule_date, schedule_datetime = context.schedule_datetime, customer_id = context.customer_id, product_id = context.product_id;
@@ -3733,11 +4882,11 @@ var Server = /*#__PURE__*/function () {
3733
4882
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3734
4883
  });
3735
4884
  if (this.products) {
3736
- _context36.next = 7;
4885
+ _context51.next = 7;
3737
4886
  break;
3738
4887
  }
3739
4888
  this.logError('computeProductQueryResult: Products 模块未注册');
3740
- return _context36.abrupt("return", {
4889
+ return _context51.abrupt("return", {
3741
4890
  message: 'Products 模块未注册',
3742
4891
  data: {
3743
4892
  list: [],
@@ -3746,12 +4895,12 @@ var Server = /*#__PURE__*/function () {
3746
4895
  });
3747
4896
  case 7:
3748
4897
  if (!(queryIds.length > 0)) {
3749
- _context36.next = 18;
4898
+ _context51.next = 18;
3750
4899
  break;
3751
4900
  }
3752
4901
  uniqueIds = Array.from(new Set(queryIds));
3753
4902
  _tPrice = performance.now();
3754
- _context36.next = 12;
4903
+ _context51.next = 12;
3755
4904
  return this.products.getProductsWithPrice(schedule_date, {
3756
4905
  scheduleModule: this.getSchedule(),
3757
4906
  schedule_datetime: schedule_datetime,
@@ -3761,7 +4910,7 @@ var Server = /*#__PURE__*/function () {
3761
4910
  productIds: uniqueIds
3762
4911
  });
3763
4912
  case 12:
3764
- productsWithPrice = _context36.sent;
4913
+ productsWithPrice = _context51.sent;
3765
4914
  perfMark('computeQuery.getProductsWithPrice(ids)', performance.now() - _tPrice, {
3766
4915
  count: productsWithPrice.length,
3767
4916
  ids: uniqueIds
@@ -3780,7 +4929,7 @@ var Server = /*#__PURE__*/function () {
3780
4929
  ids: uniqueIds,
3781
4930
  count: _filteredProducts.length
3782
4931
  });
3783
- return _context36.abrupt("return", {
4932
+ return _context51.abrupt("return", {
3784
4933
  code: 200,
3785
4934
  data: {
3786
4935
  list: _filteredProducts,
@@ -3791,19 +4940,19 @@ var Server = /*#__PURE__*/function () {
3791
4940
  });
3792
4941
  case 18:
3793
4942
  if (!(product_id != null && Number.isFinite(Number(product_id)))) {
3794
- _context36.next = 30;
4943
+ _context51.next = 30;
3795
4944
  break;
3796
4945
  }
3797
4946
  pid = Number(product_id);
3798
4947
  _tPrice2 = performance.now();
3799
- _context36.next = 23;
4948
+ _context51.next = 23;
3800
4949
  return this.products.getProductsWithPrice(schedule_date, {
3801
4950
  scheduleModule: this.getSchedule()
3802
4951
  }, {
3803
4952
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3804
4953
  });
3805
4954
  case 23:
3806
- allProductsWithPrice = _context36.sent;
4955
+ allProductsWithPrice = _context51.sent;
3807
4956
  perfMark('computeQuery.getProductsWithPrice(single)', performance.now() - _tPrice2, {
3808
4957
  count: allProductsWithPrice.length,
3809
4958
  productId: pid
@@ -3823,7 +4972,7 @@ var Server = /*#__PURE__*/function () {
3823
4972
  productId: pid,
3824
4973
  found: !!item
3825
4974
  });
3826
- return _context36.abrupt("return", {
4975
+ return _context51.abrupt("return", {
3827
4976
  code: 200,
3828
4977
  data: item,
3829
4978
  message: item ? '' : '商品不存在或未发布',
@@ -3831,11 +4980,11 @@ var Server = /*#__PURE__*/function () {
3831
4980
  });
3832
4981
  case 30:
3833
4982
  if (this.menu) {
3834
- _context36.next = 33;
4983
+ _context51.next = 33;
3835
4984
  break;
3836
4985
  }
3837
4986
  this.logError('computeProductQueryResult: Menu 模块未注册');
3838
- return _context36.abrupt("return", {
4987
+ return _context51.abrupt("return", {
3839
4988
  message: 'Menu 模块未注册',
3840
4989
  data: {
3841
4990
  list: [],
@@ -3844,11 +4993,11 @@ var Server = /*#__PURE__*/function () {
3844
4993
  });
3845
4994
  case 33:
3846
4995
  if (this.schedule) {
3847
- _context36.next = 36;
4996
+ _context51.next = 36;
3848
4997
  break;
3849
4998
  }
3850
4999
  this.logError('computeProductQueryResult: Schedule 模块未注册');
3851
- return _context36.abrupt("return", {
5000
+ return _context51.abrupt("return", {
3852
5001
  message: 'Schedule 模块未注册',
3853
5002
  data: {
3854
5003
  list: [],
@@ -3861,8 +5010,8 @@ var Server = /*#__PURE__*/function () {
3861
5010
  tMenu = performance.now();
3862
5011
  menuList = this.menu.getMenuByIds(menu_list_ids);
3863
5012
  activeMenuList = menuList.filter(function (menu) {
3864
- var _this8$schedule;
3865
- return ((_this8$schedule = _this8.schedule) === null || _this8$schedule === void 0 ? void 0 : _this8$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
5013
+ var _this13$schedule;
5014
+ return ((_this13$schedule = _this13.schedule) === null || _this13$schedule === void 0 ? void 0 : _this13$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
3866
5015
  });
3867
5016
  perfMark('computeQuery.filterActiveMenu', performance.now() - tMenu, {
3868
5017
  totalMenu: menuList.length,
@@ -3879,10 +5028,10 @@ var Server = /*#__PURE__*/function () {
3879
5028
  });
3880
5029
  tPrice = performance.now();
3881
5030
  if (!(scopedProductIds.length > 0)) {
3882
- _context36.next = 49;
5031
+ _context51.next = 49;
3883
5032
  break;
3884
5033
  }
3885
- _context36.next = 46;
5034
+ _context51.next = 46;
3886
5035
  return this.products.getProductsWithPrice(schedule_date, {
3887
5036
  scheduleModule: this.getSchedule(),
3888
5037
  schedule_datetime: schedule_datetime,
@@ -3892,13 +5041,13 @@ var Server = /*#__PURE__*/function () {
3892
5041
  productIds: productScope.isAllProducts ? undefined : scopedProductIds
3893
5042
  });
3894
5043
  case 46:
3895
- _context36.t0 = _context36.sent;
3896
- _context36.next = 50;
5044
+ _context51.t0 = _context51.sent;
5045
+ _context51.next = 50;
3897
5046
  break;
3898
5047
  case 49:
3899
- _context36.t0 = [];
5048
+ _context51.t0 = [];
3900
5049
  case 50:
3901
- filteredProducts = _context36.t0;
5050
+ filteredProducts = _context51.t0;
3902
5051
  perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
3903
5052
  count: filteredProducts.length,
3904
5053
  scopedProductCount: scopedProductIds.length
@@ -3931,7 +5080,7 @@ var Server = /*#__PURE__*/function () {
3931
5080
  filteredCount: filteredProducts.length,
3932
5081
  activeMenuCount: activeMenuList.length
3933
5082
  });
3934
- return _context36.abrupt("return", {
5083
+ return _context51.abrupt("return", {
3935
5084
  code: 200,
3936
5085
  data: {
3937
5086
  list: filteredProducts,
@@ -3942,11 +5091,11 @@ var Server = /*#__PURE__*/function () {
3942
5091
  });
3943
5092
  case 62:
3944
5093
  case "end":
3945
- return _context36.stop();
5094
+ return _context51.stop();
3946
5095
  }
3947
- }, _callee36, this);
5096
+ }, _callee51, this);
3948
5097
  }));
3949
- function computeProductQueryResult(_x34, _x35) {
5098
+ function computeProductQueryResult(_x55, _x56) {
3950
5099
  return _computeProductQueryResult.apply(this, arguments);
3951
5100
  }
3952
5101
  return computeProductQueryResult;
@@ -3961,72 +5110,72 @@ var Server = /*#__PURE__*/function () {
3961
5110
  }, {
3962
5111
  key: "recomputeAndNotifyProductQuery",
3963
5112
  value: (function () {
3964
- var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(options) {
3965
- var _iterator16, _step16, _step16$value, subscriberId, subscriber, result, errorMessage;
3966
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3967
- while (1) switch (_context37.prev = _context37.next) {
5113
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(options) {
5114
+ var _iterator17, _step17, _step17$value, subscriberId, subscriber, result, errorMessage;
5115
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
5116
+ while (1) switch (_context52.prev = _context52.next) {
3968
5117
  case 0:
3969
5118
  if (!(this.productQuerySubscribers.size === 0)) {
3970
- _context37.next = 2;
5119
+ _context52.next = 2;
3971
5120
  break;
3972
5121
  }
3973
- return _context37.abrupt("return");
5122
+ return _context52.abrupt("return");
3974
5123
  case 2:
3975
5124
  this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
3976
5125
  subscriberCount: this.productQuerySubscribers.size,
3977
5126
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3978
5127
  });
3979
- _iterator16 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
3980
- _context37.prev = 4;
3981
- _iterator16.s();
5128
+ _iterator17 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
5129
+ _context52.prev = 4;
5130
+ _iterator17.s();
3982
5131
  case 6:
3983
- if ((_step16 = _iterator16.n()).done) {
3984
- _context37.next = 22;
5132
+ if ((_step17 = _iterator17.n()).done) {
5133
+ _context52.next = 22;
3985
5134
  break;
3986
5135
  }
3987
- _step16$value = _slicedToArray(_step16.value, 2), subscriberId = _step16$value[0], subscriber = _step16$value[1];
3988
- _context37.prev = 8;
3989
- _context37.next = 11;
5136
+ _step17$value = _slicedToArray(_step17.value, 2), subscriberId = _step17$value[0], subscriber = _step17$value[1];
5137
+ _context52.prev = 8;
5138
+ _context52.next = 11;
3990
5139
  return this.computeProductQueryResult(subscriber.context, {
3991
5140
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3992
5141
  });
3993
5142
  case 11:
3994
- result = _context37.sent;
5143
+ result = _context52.sent;
3995
5144
  subscriber.callback(result);
3996
5145
  this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
3997
5146
  subscriberId: subscriberId
3998
5147
  });
3999
- _context37.next = 20;
5148
+ _context52.next = 20;
4000
5149
  break;
4001
5150
  case 16:
4002
- _context37.prev = 16;
4003
- _context37.t0 = _context37["catch"](8);
4004
- errorMessage = _context37.t0 instanceof Error ? _context37.t0.message : String(_context37.t0);
5151
+ _context52.prev = 16;
5152
+ _context52.t0 = _context52["catch"](8);
5153
+ errorMessage = _context52.t0 instanceof Error ? _context52.t0.message : String(_context52.t0);
4005
5154
  this.logError('recomputeAndNotifyProductQuery: 推送失败', {
4006
5155
  subscriberId: subscriberId,
4007
5156
  error: errorMessage
4008
5157
  });
4009
5158
  case 20:
4010
- _context37.next = 6;
5159
+ _context52.next = 6;
4011
5160
  break;
4012
5161
  case 22:
4013
- _context37.next = 27;
5162
+ _context52.next = 27;
4014
5163
  break;
4015
5164
  case 24:
4016
- _context37.prev = 24;
4017
- _context37.t1 = _context37["catch"](4);
4018
- _iterator16.e(_context37.t1);
5165
+ _context52.prev = 24;
5166
+ _context52.t1 = _context52["catch"](4);
5167
+ _iterator17.e(_context52.t1);
4019
5168
  case 27:
4020
- _context37.prev = 27;
4021
- _iterator16.f();
4022
- return _context37.finish(27);
5169
+ _context52.prev = 27;
5170
+ _iterator17.f();
5171
+ return _context52.finish(27);
4023
5172
  case 30:
4024
5173
  case "end":
4025
- return _context37.stop();
5174
+ return _context52.stop();
4026
5175
  }
4027
- }, _callee37, this, [[4, 24, 27, 30], [8, 16]]);
5176
+ }, _callee52, this, [[4, 24, 27, 30], [8, 16]]);
4028
5177
  }));
4029
- function recomputeAndNotifyProductQuery(_x36) {
5178
+ function recomputeAndNotifyProductQuery(_x57) {
4030
5179
  return _recomputeAndNotifyProductQuery.apply(this, arguments);
4031
5180
  }
4032
5181
  return recomputeAndNotifyProductQuery;
@@ -4038,37 +5187,37 @@ var Server = /*#__PURE__*/function () {
4038
5187
  }, {
4039
5188
  key: "recomputeAndNotifyOrderQuery",
4040
5189
  value: (function () {
4041
- var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
4042
- var notifyStartAt, _iterator17, _step17, _step17$value, subscriberId, subscriber, computeStartAt, result, computeEndAt, callbackStartAt, callbackEndAt, errorMessage, notifyEndAt;
4043
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
4044
- while (1) switch (_context38.prev = _context38.next) {
5190
+ var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53() {
5191
+ var notifyStartAt, _iterator18, _step18, _step18$value, subscriberId, subscriber, computeStartAt, result, computeEndAt, callbackStartAt, callbackEndAt, errorMessage, notifyEndAt;
5192
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
5193
+ while (1) switch (_context53.prev = _context53.next) {
4045
5194
  case 0:
4046
5195
  if (!(this.orderQuerySubscribers.size === 0)) {
4047
- _context38.next = 2;
5196
+ _context53.next = 2;
4048
5197
  break;
4049
5198
  }
4050
- return _context38.abrupt("return");
5199
+ return _context53.abrupt("return");
4051
5200
  case 2:
4052
5201
  notifyStartAt = Date.now();
4053
5202
  this.logInfo('recomputeAndNotifyOrderQuery: 开始推送', {
4054
5203
  subscriberCount: this.orderQuerySubscribers.size,
4055
5204
  notifyStartAt: new Date(notifyStartAt).toISOString()
4056
5205
  });
4057
- _iterator17 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
4058
- _context38.prev = 5;
4059
- _iterator17.s();
5206
+ _iterator18 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
5207
+ _context53.prev = 5;
5208
+ _iterator18.s();
4060
5209
  case 7:
4061
- if ((_step17 = _iterator17.n()).done) {
4062
- _context38.next = 27;
5210
+ if ((_step18 = _iterator18.n()).done) {
5211
+ _context53.next = 27;
4063
5212
  break;
4064
5213
  }
4065
- _step17$value = _slicedToArray(_step17.value, 2), subscriberId = _step17$value[0], subscriber = _step17$value[1];
4066
- _context38.prev = 9;
5214
+ _step18$value = _slicedToArray(_step18.value, 2), subscriberId = _step18$value[0], subscriber = _step18$value[1];
5215
+ _context53.prev = 9;
4067
5216
  computeStartAt = Date.now();
4068
- _context38.next = 13;
5217
+ _context53.next = 13;
4069
5218
  return this.computeOrderQueryResult(subscriber.context);
4070
5219
  case 13:
4071
- result = _context38.sent;
5220
+ result = _context53.sent;
4072
5221
  computeEndAt = Date.now();
4073
5222
  callbackStartAt = Date.now();
4074
5223
  subscriber.callback(result);
@@ -4079,30 +5228,30 @@ var Server = /*#__PURE__*/function () {
4079
5228
  callbackDurationMs: callbackEndAt - callbackStartAt,
4080
5229
  totalDurationMs: callbackEndAt - computeStartAt
4081
5230
  });
4082
- _context38.next = 25;
5231
+ _context53.next = 25;
4083
5232
  break;
4084
5233
  case 21:
4085
- _context38.prev = 21;
4086
- _context38.t0 = _context38["catch"](9);
4087
- errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0);
5234
+ _context53.prev = 21;
5235
+ _context53.t0 = _context53["catch"](9);
5236
+ errorMessage = _context53.t0 instanceof Error ? _context53.t0.message : String(_context53.t0);
4088
5237
  this.logError('recomputeAndNotifyOrderQuery: 推送失败', {
4089
5238
  subscriberId: subscriberId,
4090
5239
  error: errorMessage
4091
5240
  });
4092
5241
  case 25:
4093
- _context38.next = 7;
5242
+ _context53.next = 7;
4094
5243
  break;
4095
5244
  case 27:
4096
- _context38.next = 32;
5245
+ _context53.next = 32;
4097
5246
  break;
4098
5247
  case 29:
4099
- _context38.prev = 29;
4100
- _context38.t1 = _context38["catch"](5);
4101
- _iterator17.e(_context38.t1);
5248
+ _context53.prev = 29;
5249
+ _context53.t1 = _context53["catch"](5);
5250
+ _iterator18.e(_context53.t1);
4102
5251
  case 32:
4103
- _context38.prev = 32;
4104
- _iterator17.f();
4105
- return _context38.finish(32);
5252
+ _context53.prev = 32;
5253
+ _iterator18.f();
5254
+ return _context53.finish(32);
4106
5255
  case 35:
4107
5256
  notifyEndAt = Date.now();
4108
5257
  this.logInfo('recomputeAndNotifyOrderQuery: 推送完成', {
@@ -4111,9 +5260,9 @@ var Server = /*#__PURE__*/function () {
4111
5260
  });
4112
5261
  case 37:
4113
5262
  case "end":
4114
- return _context38.stop();
5263
+ return _context53.stop();
4115
5264
  }
4116
- }, _callee38, this, [[5, 29, 32, 35], [9, 21]]);
5265
+ }, _callee53, this, [[5, 29, 32, 35], [9, 21]]);
4117
5266
  }));
4118
5267
  function recomputeAndNotifyOrderQuery() {
4119
5268
  return _recomputeAndNotifyOrderQuery.apply(this, arguments);
@@ -4121,73 +5270,197 @@ var Server = /*#__PURE__*/function () {
4121
5270
  return recomputeAndNotifyOrderQuery;
4122
5271
  }()
4123
5272
  /**
4124
- * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
5273
+ * 订单变更后通知 sales 搜索订阅者。
5274
+ * 仅回传当前查询已返回订单号集合中的变更订单。
5275
+ *
5276
+ * @example
5277
+ * this.notifySalesSearchSubscribers({ list: [], changedOrders: [order], source: 'pubsub.bodyUpsert' })
4125
5278
  */
4126
5279
  )
5280
+ }, {
5281
+ key: "notifySalesSearchSubscribers",
5282
+ value: function notifySalesSearchSubscribers(payload) {
5283
+ var _this14 = this;
5284
+ if (this.salesSearchSubscribers.size === 0) return;
5285
+ var changedOrders = this.extractChangedOrdersFromPayload(payload);
5286
+ if (changedOrders.length === 0) {
5287
+ return;
5288
+ }
5289
+ var _iterator19 = _createForOfIteratorHelper(this.salesSearchSubscribers.entries()),
5290
+ _step19;
5291
+ try {
5292
+ var _loop = function _loop() {
5293
+ var _step19$value = _slicedToArray(_step19.value, 2),
5294
+ subscriberId = _step19$value[0],
5295
+ subscriber = _step19$value[1];
5296
+ try {
5297
+ var changedVisibleOrders = changedOrders.filter(function (order) {
5298
+ var orderId = _this14.getSalesSearchOrderId(order);
5299
+ return !!orderId && subscriber.visibleOrderIds.has(orderId);
5300
+ });
5301
+ if (changedVisibleOrders.length === 0) {
5302
+ return 1; // continue
5303
+ }
5304
+ subscriber.callback(_this14.buildSalesSearchDeltaResponse(subscriber, changedVisibleOrders));
5305
+ _this14.logInfo('notifySalesSearchSubscribers: 已推送 delta', {
5306
+ subscriberId: subscriberId,
5307
+ kind: subscriber.kind,
5308
+ count: changedVisibleOrders.length
5309
+ });
5310
+ } catch (error) {
5311
+ var errorMessage = error instanceof Error ? error.message : String(error);
5312
+ _this14.logError('notifySalesSearchSubscribers: 推送失败', {
5313
+ subscriberId: subscriberId,
5314
+ error: errorMessage
5315
+ });
5316
+ }
5317
+ };
5318
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
5319
+ if (_loop()) continue;
5320
+ }
5321
+ } catch (err) {
5322
+ _iterator19.e(err);
5323
+ } finally {
5324
+ _iterator19.f();
5325
+ }
5326
+ }
5327
+
5328
+ /**
5329
+ * 从订单变更事件中提取明确 delta。
5330
+ *
5331
+ * @example
5332
+ * const list = this.extractChangedOrdersFromPayload(payload)
5333
+ */
5334
+ }, {
5335
+ key: "extractChangedOrdersFromPayload",
5336
+ value: function extractChangedOrdersFromPayload(payload) {
5337
+ if (!payload || Array.isArray(payload)) return [];
5338
+ return Array.isArray(payload.changedOrders) ? payload.changedOrders : [];
5339
+ }
5340
+
5341
+ /**
5342
+ * 构建与当前搜索接口一致的 delta 响应。
5343
+ *
5344
+ * @example
5345
+ * const response = this.buildSalesSearchDeltaResponse(subscriber, [order])
5346
+ */
5347
+ }, {
5348
+ key: "buildSalesSearchDeltaResponse",
5349
+ value: function buildSalesSearchDeltaResponse(subscriber, changedOrders) {
5350
+ if (subscriber.kind === 'aggregate') {
5351
+ return this.buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders);
5352
+ }
5353
+ var data = subscriber.lastResponseData || {};
5354
+ return {
5355
+ code: 200,
5356
+ status: true,
5357
+ message: '',
5358
+ data: _objectSpread(_objectSpread({}, data), {}, {
5359
+ list: changedOrders
5360
+ })
5361
+ };
5362
+ }
5363
+
5364
+ /**
5365
+ * 构建聚合搜索接口的 sales 分组 delta 响应。
5366
+ *
5367
+ * @example
5368
+ * const response = this.buildAggregateSalesSearchDeltaResponse(subscriber, [order])
5369
+ */
5370
+ }, {
5371
+ key: "buildAggregateSalesSearchDeltaResponse",
5372
+ value: function buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders) {
5373
+ var data = subscriber.lastResponseData || {};
5374
+ var results = Array.isArray(data === null || data === void 0 ? void 0 : data.results) ? data.results : [];
5375
+ var hasSalesGroup = results.some(function (item) {
5376
+ return (item === null || item === void 0 ? void 0 : item.module) === 'sales';
5377
+ });
5378
+ var nextResults = hasSalesGroup ? results.map(function (item) {
5379
+ return (item === null || item === void 0 ? void 0 : item.module) === 'sales' ? _objectSpread(_objectSpread({}, item), {}, {
5380
+ list: changedOrders
5381
+ }) : item;
5382
+ }) : [{
5383
+ module: 'sales',
5384
+ list: changedOrders,
5385
+ count: changedOrders.length
5386
+ }];
5387
+ return {
5388
+ code: 200,
5389
+ status: true,
5390
+ message: '',
5391
+ data: _objectSpread(_objectSpread({}, data), {}, {
5392
+ results: nextResults
5393
+ })
5394
+ };
5395
+ }
5396
+
5397
+ /**
5398
+ * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
5399
+ */
4127
5400
  }, {
4128
5401
  key: "recomputeAndNotifyBookingQuery",
4129
5402
  value: (function () {
4130
- var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
4131
- var _iterator18, _step18, _step18$value, subscriberId, subscriber, result, errorMessage;
4132
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
4133
- while (1) switch (_context39.prev = _context39.next) {
5403
+ var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54() {
5404
+ var _iterator20, _step20, _step20$value, subscriberId, subscriber, result, errorMessage;
5405
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
5406
+ while (1) switch (_context54.prev = _context54.next) {
4134
5407
  case 0:
4135
5408
  if (!(this.bookingQuerySubscribers.size === 0)) {
4136
- _context39.next = 2;
5409
+ _context54.next = 2;
4137
5410
  break;
4138
5411
  }
4139
- return _context39.abrupt("return");
5412
+ return _context54.abrupt("return");
4140
5413
  case 2:
4141
5414
  this.logInfo('recomputeAndNotifyBookingQuery: 开始推送', {
4142
5415
  subscriberCount: this.bookingQuerySubscribers.size
4143
5416
  });
4144
- _iterator18 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
4145
- _context39.prev = 4;
4146
- _iterator18.s();
5417
+ _iterator20 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
5418
+ _context54.prev = 4;
5419
+ _iterator20.s();
4147
5420
  case 6:
4148
- if ((_step18 = _iterator18.n()).done) {
4149
- _context39.next = 22;
5421
+ if ((_step20 = _iterator20.n()).done) {
5422
+ _context54.next = 22;
4150
5423
  break;
4151
5424
  }
4152
- _step18$value = _slicedToArray(_step18.value, 2), subscriberId = _step18$value[0], subscriber = _step18$value[1];
4153
- _context39.prev = 8;
4154
- _context39.next = 11;
5425
+ _step20$value = _slicedToArray(_step20.value, 2), subscriberId = _step20$value[0], subscriber = _step20$value[1];
5426
+ _context54.prev = 8;
5427
+ _context54.next = 11;
4155
5428
  return this.computeBookingQueryResult(subscriber.context);
4156
5429
  case 11:
4157
- result = _context39.sent;
5430
+ result = _context54.sent;
4158
5431
  subscriber.callback(result);
4159
5432
  this.logInfo('recomputeAndNotifyBookingQuery: 已推送', {
4160
5433
  subscriberId: subscriberId
4161
5434
  });
4162
- _context39.next = 20;
5435
+ _context54.next = 20;
4163
5436
  break;
4164
5437
  case 16:
4165
- _context39.prev = 16;
4166
- _context39.t0 = _context39["catch"](8);
4167
- errorMessage = _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0);
5438
+ _context54.prev = 16;
5439
+ _context54.t0 = _context54["catch"](8);
5440
+ errorMessage = _context54.t0 instanceof Error ? _context54.t0.message : String(_context54.t0);
4168
5441
  this.logError('recomputeAndNotifyBookingQuery: 推送失败', {
4169
5442
  subscriberId: subscriberId,
4170
5443
  error: errorMessage
4171
5444
  });
4172
5445
  case 20:
4173
- _context39.next = 6;
5446
+ _context54.next = 6;
4174
5447
  break;
4175
5448
  case 22:
4176
- _context39.next = 27;
5449
+ _context54.next = 27;
4177
5450
  break;
4178
5451
  case 24:
4179
- _context39.prev = 24;
4180
- _context39.t1 = _context39["catch"](4);
4181
- _iterator18.e(_context39.t1);
5452
+ _context54.prev = 24;
5453
+ _context54.t1 = _context54["catch"](4);
5454
+ _iterator20.e(_context54.t1);
4182
5455
  case 27:
4183
- _context39.prev = 27;
4184
- _iterator18.f();
4185
- return _context39.finish(27);
5456
+ _context54.prev = 27;
5457
+ _iterator20.f();
5458
+ return _context54.finish(27);
4186
5459
  case 30:
4187
5460
  case "end":
4188
- return _context39.stop();
5461
+ return _context54.stop();
4189
5462
  }
4190
- }, _callee39, this, [[4, 24, 27, 30], [8, 16]]);
5463
+ }, _callee54, this, [[4, 24, 27, 30], [8, 16]]);
4191
5464
  }));
4192
5465
  function recomputeAndNotifyBookingQuery() {
4193
5466
  return _recomputeAndNotifyBookingQuery.apply(this, arguments);
@@ -4217,11 +5490,11 @@ var Server = /*#__PURE__*/function () {
4217
5490
  var allowedProductIds = new Set();
4218
5491
  var allowedCollectionIds = new Set();
4219
5492
  var hasProductAll = false;
4220
- var _iterator19 = _createForOfIteratorHelper(activeMenuList),
4221
- _step19;
5493
+ var _iterator21 = _createForOfIteratorHelper(activeMenuList),
5494
+ _step21;
4222
5495
  try {
4223
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
4224
- var menu = _step19.value;
5496
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
5497
+ var menu = _step21.value;
4225
5498
  var config = menu.partyroom_package;
4226
5499
  if (!config) {
4227
5500
  console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
@@ -4281,9 +5554,9 @@ var Server = /*#__PURE__*/function () {
4281
5554
 
4282
5555
  // 如果有餐牌允许所有商品,返回所有商品
4283
5556
  } catch (err) {
4284
- _iterator19.e(err);
5557
+ _iterator21.e(err);
4285
5558
  } finally {
4286
- _iterator19.f();
5559
+ _iterator21.f();
4287
5560
  }
4288
5561
  if (hasProductAll) {
4289
5562
  this.logInfo('getProductScopeByMenuConfig: 返回所有商品 scope(product_all)');