@pisell/pisellos 2.2.205 → 2.2.207

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 (44) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/OpenData/index.d.ts +1 -0
  3. package/dist/modules/OpenData/index.js +21 -16
  4. package/dist/modules/Order/index.d.ts +9 -0
  5. package/dist/modules/Order/index.js +230 -145
  6. package/dist/modules/Order/types.d.ts +10 -0
  7. package/dist/modules/Order/utils.js +7 -5
  8. package/dist/server/index.d.ts +136 -0
  9. package/dist/server/index.js +2055 -781
  10. package/dist/server/modules/order/index.d.ts +7 -0
  11. package/dist/server/modules/order/index.js +375 -337
  12. package/dist/server/modules/order/types.d.ts +15 -0
  13. package/dist/server/modules/order/types.js +8 -0
  14. package/dist/server/utils/small-ticket.d.ts +69 -0
  15. package/dist/server/utils/small-ticket.js +528 -0
  16. package/dist/solution/BaseSales/index.d.ts +4 -2
  17. package/dist/solution/BaseSales/index.js +248 -188
  18. package/dist/solution/BookingByStep/index.d.ts +1 -1
  19. package/dist/solution/BookingTicket/index.d.ts +8 -1
  20. package/dist/solution/BookingTicket/index.js +443 -263
  21. package/dist/solution/BookingTicket/types.d.ts +2 -1
  22. package/dist/solution/BookingTicket/types.js +3 -1
  23. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  24. package/lib/modules/OpenData/index.d.ts +1 -0
  25. package/lib/modules/OpenData/index.js +6 -4
  26. package/lib/modules/Order/index.d.ts +9 -0
  27. package/lib/modules/Order/index.js +59 -3
  28. package/lib/modules/Order/types.d.ts +10 -0
  29. package/lib/modules/Order/utils.js +4 -3
  30. package/lib/server/index.d.ts +136 -0
  31. package/lib/server/index.js +823 -50
  32. package/lib/server/modules/order/index.d.ts +7 -0
  33. package/lib/server/modules/order/index.js +21 -7
  34. package/lib/server/modules/order/types.d.ts +15 -0
  35. package/lib/server/utils/small-ticket.d.ts +69 -0
  36. package/lib/server/utils/small-ticket.js +555 -0
  37. package/lib/solution/BaseSales/index.d.ts +4 -2
  38. package/lib/solution/BaseSales/index.js +47 -1
  39. package/lib/solution/BookingByStep/index.d.ts +1 -1
  40. package/lib/solution/BookingTicket/index.d.ts +8 -1
  41. package/lib/solution/BookingTicket/index.js +108 -1
  42. package/lib/solution/BookingTicket/types.d.ts +2 -1
  43. package/lib/solution/BookingTicket/types.js +5 -0
  44. 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,377 @@ 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$core$getPlugin, _this$core$getPlugin$, _this$app9, _this$app9$getData, _this$app10, _this$app10$getStore, _this$app10$getStore$, _this$app10$getStore$2, _this$app11, _this$app11$getStore, _this$app11$getStore$, _this$app11$getStore$2, _this$app12, _this$app12$getStore, _this$app12$getStore$, _this$app12$getStore$2;
3483
+ var getData = (_this$core$getPlugin = this.core.getPlugin('app')) === null || _this$core$getPlugin === void 0 || (_this$core$getPlugin$ = _this$core$getPlugin.getData) === null || _this$core$getPlugin$ === void 0 ? void 0 : _this$core$getPlugin$.call(_this$core$getPlugin);
3484
+ if (typeof getData === 'function') return getData(key);
3485
+ var directValue = (_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, key);
3486
+ if (directValue !== undefined) return directValue;
3487
+ var coreData = ((_this$app10 = this.app) === null || _this$app10 === void 0 || (_this$app10 = _this$app10.models) === null || _this$app10 === void 0 || (_this$app10$getStore = _this$app10.getStore) === null || _this$app10$getStore === void 0 || (_this$app10$getStore$ = (_this$app10$getStore$2 = _this$app10$getStore.call(_this$app10)).getDataByModel) === null || _this$app10$getStore$ === void 0 ? void 0 : _this$app10$getStore$.call(_this$app10$getStore$2, 'core', 'core')) || ((_this$app11 = this.app) === null || _this$app11 === void 0 || (_this$app11 = _this$app11.data) === null || _this$app11 === void 0 || (_this$app11 = _this$app11.store) === 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 || (_this$app12$getStore$ = _this$app12$getStore$.call(_this$app12$getStore$2, 'core')) === null || _this$app12$getStore$ === void 0 ? void 0 : _this$app12$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
+ debugger;
3496
+ return _objectSpread(_objectSpread({}, shopInfo), {}, {
3497
+ currency_symbol: shopInfo.currency_symbol || this.getAppData('shop_symbol') || this.getAppData('currency_symbol'),
3498
+ currency_code: shopInfo.currency_code || this.getAppData('shop_currency_code') || this.getAppData('currency_code'),
3499
+ tax_title: shopInfo.tax_title || this.getAppData('tax_title'),
3500
+ tax_country_code: shopInfo.tax_country_code || this.getAppData('tax_country_code'),
3501
+ 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')
3502
+ });
3503
+ }
3504
+ }, {
3505
+ key: "taskOk",
3506
+ value: function taskOk(result) {
3507
+ return {
3508
+ status: 'success',
3509
+ result: result
3510
+ };
3511
+ }
3512
+ }, {
3513
+ key: "taskFail",
3514
+ value: function taskFail(code, message, result) {
3515
+ return _objectSpread({
3516
+ status: 'failed',
3517
+ error: {
3518
+ code: code,
3519
+ message: message
3520
+ }
3521
+ }, result !== undefined ? {
3522
+ result: result
3523
+ } : {});
3524
+ }
3525
+ }, {
3526
+ key: "taskTimeout",
3527
+ value: function taskTimeout(message) {
3528
+ return {
3529
+ status: 'timeout',
3530
+ error: {
3531
+ code: 'TIMEOUT',
3532
+ message: message
3533
+ }
3534
+ };
3535
+ }
3536
+ }, {
3537
+ key: "resolveCheckoutTaskDeviceId",
3538
+ value: function resolveCheckoutTaskDeviceId(_data) {
3539
+ return this.getAppData('device_id') || 0;
3540
+ }
3541
+ }, {
3542
+ key: "buildCheckoutTaskIdempotencyKey",
3543
+ value: function buildCheckoutTaskIdempotencyKey(data) {
3544
+ 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);
3545
+ if (identity === undefined || identity === null || identity === '') return undefined;
3546
+ return "sync_sales:".concat(identity);
3547
+ }
3548
+ }, {
3549
+ key: "ensureCheckoutOrderNumbers",
3550
+ value: function () {
3551
+ var _ensureCheckoutOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(data, title) {
3552
+ var next, needsShopOrderNumber, needsShopFullOrderNumber, idGenerator;
3553
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3554
+ while (1) switch (_context37.prev = _context37.next) {
3555
+ case 0:
3556
+ if (!(!data || _typeof(data) !== 'object')) {
3557
+ _context37.next = 2;
3558
+ break;
3559
+ }
3560
+ return _context37.abrupt("return", data);
3561
+ case 2:
3562
+ next = _objectSpread({}, data);
3563
+ needsShopOrderNumber = next.shop_order_number === undefined || next.shop_order_number === null || next.shop_order_number === '';
3564
+ needsShopFullOrderNumber = next.shop_full_order_number === undefined || next.shop_full_order_number === null || next.shop_full_order_number === '';
3565
+ if (!(!needsShopOrderNumber && !needsShopFullOrderNumber)) {
3566
+ _context37.next = 7;
3567
+ break;
3568
+ }
3569
+ return _context37.abrupt("return", next);
3570
+ case 7:
3571
+ idGenerator = this.getIdGeneratorPlugin();
3572
+ if (idGenerator) {
3573
+ _context37.next = 11;
3574
+ break;
3575
+ }
3576
+ this.logWarning("".concat(title, ": idGenerator \u63D2\u4EF6\u4E0D\u53EF\u7528\uFF0C\u65E0\u6CD5\u751F\u6210\u8BA2\u5355\u53F7"), {
3577
+ needsShopOrderNumber: needsShopOrderNumber,
3578
+ needsShopFullOrderNumber: needsShopFullOrderNumber
3579
+ });
3580
+ return _context37.abrupt("return", next);
3581
+ case 11:
3582
+ _context37.prev = 11;
3583
+ if (!(needsShopOrderNumber && idGenerator.generateShopOrderNumber)) {
3584
+ _context37.next = 16;
3585
+ break;
3586
+ }
3587
+ _context37.next = 15;
3588
+ return idGenerator.generateShopOrderNumber({
3589
+ biz: next.business_code || 'ticket'
3590
+ });
3591
+ case 15:
3592
+ next.shop_order_number = _context37.sent;
3593
+ case 16:
3594
+ if (!(needsShopFullOrderNumber && idGenerator.generateReceiptId)) {
3595
+ _context37.next = 20;
3596
+ break;
3597
+ }
3598
+ _context37.next = 19;
3599
+ return idGenerator.generateReceiptId({
3600
+ biz: next.business_code || 'ticket'
3601
+ });
3602
+ case 19:
3603
+ next.shop_full_order_number = _context37.sent;
3604
+ case 20:
3605
+ this.logInfo("".concat(title, ": checkout \u8BA2\u5355\u53F7\u5DF2\u51C6\u5907"), {
3606
+ shop_order_number: next.shop_order_number,
3607
+ shop_full_order_number: next.shop_full_order_number
3608
+ });
3609
+ _context37.next = 26;
3610
+ break;
3611
+ case 23:
3612
+ _context37.prev = 23;
3613
+ _context37.t0 = _context37["catch"](11);
3614
+ this.logError("".concat(title, ": \u751F\u6210 checkout \u8BA2\u5355\u53F7\u5931\u8D25"), {
3615
+ error: _context37.t0 instanceof Error ? _context37.t0.message : String(_context37.t0)
3616
+ });
3617
+ case 26:
3618
+ return _context37.abrupt("return", next);
3619
+ case 27:
3620
+ case "end":
3621
+ return _context37.stop();
3622
+ }
3623
+ }, _callee37, this, [[11, 23]]);
3624
+ }));
3625
+ function ensureCheckoutOrderNumbers(_x40, _x41) {
3626
+ return _ensureCheckoutOrderNumbers.apply(this, arguments);
3627
+ }
3628
+ return ensureCheckoutOrderNumbers;
3629
+ }()
3630
+ }, {
3631
+ key: "dispatchCheckoutSyncTask",
3632
+ value: function () {
3633
+ var _dispatchCheckoutSyncTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3634
+ var deviceTask, debugDeviceId, debugIdempotencyKey, _params$data, _params$data2, _params$data3, result;
3635
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3636
+ while (1) switch (_context38.prev = _context38.next) {
3637
+ case 0:
3638
+ this.registerDeviceTaskActions();
3639
+ deviceTask = this.getDeviceTaskPlugin();
3640
+ debugDeviceId = this.resolveCheckoutTaskDeviceId(params.data);
3641
+ debugIdempotencyKey = this.buildCheckoutTaskIdempotencyKey(params.data);
3642
+ if (deviceTask !== null && deviceTask !== void 0 && deviceTask.dispatch) {
3643
+ _context38.next = 7;
3644
+ break;
3645
+ }
3646
+ this.logError("".concat(params.title, ": deviceTask.dispatch \u4E0D\u53EF\u7528"));
3647
+ return _context38.abrupt("return");
3648
+ case 7:
3649
+ _context38.prev = 7;
3650
+ _context38.next = 10;
3651
+ return deviceTask.dispatch({
3652
+ action: 'sync_sales',
3653
+ device_id: debugDeviceId,
3654
+ payload: {
3655
+ backendPath: params.backendPath,
3656
+ data: params.data,
3657
+ title: params.title
3658
+ },
3659
+ retry_limit: 5,
3660
+ idempotency_key: debugIdempotencyKey,
3661
+ name: '同步订单',
3662
+ source: 'server',
3663
+ source_type: 'order',
3664
+ 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)
3665
+ });
3666
+ case 10:
3667
+ result = _context38.sent;
3668
+ this.logInfo("".concat(params.title, ": sync_sales \u4EFB\u52A1\u5DF2\u6D3E\u53D1"), {
3669
+ uuid: result === null || result === void 0 ? void 0 : result.uuid,
3670
+ status: result === null || result === void 0 ? void 0 : result.status,
3671
+ reused: result === null || result === void 0 ? void 0 : result.reused
3672
+ });
3673
+ _context38.next = 17;
3674
+ break;
3675
+ case 14:
3676
+ _context38.prev = 14;
3677
+ _context38.t0 = _context38["catch"](7);
3678
+ this.logError("".concat(params.title, ": \u6D3E\u53D1 sync_sales \u4EFB\u52A1\u5931\u8D25"), {
3679
+ error: _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0)
3680
+ });
3681
+ case 17:
3682
+ case "end":
3683
+ return _context38.stop();
3684
+ }
3685
+ }, _callee38, this, [[7, 14]]);
3686
+ }));
3687
+ function dispatchCheckoutSyncTask(_x42) {
3688
+ return _dispatchCheckoutSyncTask.apply(this, arguments);
3689
+ }
3690
+ return dispatchCheckoutSyncTask;
3691
+ }()
3692
+ }, {
3693
+ key: "dispatchPrintOtherReceiptTask",
3694
+ value: function () {
3695
+ var _dispatchPrintOtherReceiptTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3696
+ var deviceTask, _params$deviceId, _params$syncedOrder, _params$syncedOrder2, _params$syncedOrder3, printIdentity;
3697
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3698
+ while (1) switch (_context39.prev = _context39.next) {
3699
+ case 0:
3700
+ deviceTask = this.getDeviceTaskPlugin();
3701
+ if (deviceTask !== null && deviceTask !== void 0 && deviceTask.dispatch) {
3702
+ _context39.next = 4;
3703
+ break;
3704
+ }
3705
+ this.logWarning('dispatchPrintOtherReceiptTask: deviceTask.dispatch 不可用');
3706
+ return _context39.abrupt("return");
3707
+ case 4:
3708
+ _context39.prev = 4;
3709
+ printIdentity = this.getPrintOrderIdentity(params.syncedOrder);
3710
+ _context39.next = 8;
3711
+ return deviceTask.dispatch({
3712
+ action: 'print_all',
3713
+ device_id: (_params$deviceId = params.deviceId) !== null && _params$deviceId !== void 0 ? _params$deviceId : this.resolveCheckoutTaskDeviceId(params.checkoutData),
3714
+ payload: {
3715
+ type: params.receiptOnly ? '0' : '99',
3716
+ data: params.receiptOnly ? {
3717
+ order_id: printIdentity,
3718
+ 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
3719
+ } : {
3720
+ order_id: printIdentity,
3721
+ 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,
3722
+ machine_code_print_info_v2: (_params$syncedOrder3 = params.syncedOrder) === null || _params$syncedOrder3 === void 0 ? void 0 : _params$syncedOrder3.machine_code_print_info_v2,
3723
+ skip_receipt: true
3724
+ }
3725
+ },
3726
+ idempotency_key: this.buildPrintOtherReceiptIdempotencyKey(params.syncedOrder, {
3727
+ receiptOnly: params.receiptOnly
3728
+ }),
3729
+ name: '打印转发',
3730
+ source: 'server',
3731
+ source_type: 'order',
3732
+ source_id: printIdentity
3733
+ });
3734
+ case 8:
3735
+ _context39.next = 13;
3736
+ break;
3737
+ case 10:
3738
+ _context39.prev = 10;
3739
+ _context39.t0 = _context39["catch"](4);
3740
+ this.logError('dispatchPrintOtherReceiptTask: 派发失败', {
3741
+ error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
3742
+ });
3743
+ case 13:
3744
+ case "end":
3745
+ return _context39.stop();
3746
+ }
3747
+ }, _callee39, this, [[4, 10]]);
3748
+ }));
3749
+ function dispatchPrintOtherReceiptTask(_x43) {
3750
+ return _dispatchPrintOtherReceiptTask.apply(this, arguments);
3751
+ }
3752
+ return dispatchPrintOtherReceiptTask;
3753
+ }()
3754
+ }, {
3755
+ key: "buildPrintOtherReceiptIdempotencyKey",
3756
+ value: function buildPrintOtherReceiptIdempotencyKey(order, options) {
3757
+ 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);
3758
+ if (identity === undefined || identity === null || identity === '') return undefined;
3759
+ return "".concat(options !== null && options !== void 0 && options.receiptOnly ? 'print_receipt' : 'print_voucher', ":").concat(identity);
3760
+ }
3761
+ }, {
3762
+ key: "getPrintOrderIdentity",
3763
+ value: function getPrintOrderIdentity(order) {
3764
+ 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);
3765
+ }
3766
+ }, {
3767
+ key: "dispatchLocalReceiptPrint",
3768
+ value: function () {
3769
+ var _dispatchLocalReceiptPrint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3770
+ var _payment_info;
3771
+ var printableOrder;
3772
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3773
+ while (1) switch (_context40.prev = _context40.next) {
3774
+ case 0:
3775
+ if (!(params.requireFullyPaid && !this.isSalesOrderFullyPaid(params.order))) {
3776
+ _context40.next = 2;
3777
+ break;
3778
+ }
3779
+ return _context40.abrupt("return", {
3780
+ printed: false,
3781
+ order: params.order
3782
+ });
3783
+ case 2:
3784
+ _context40.next = 4;
3785
+ return this.withLocalSmallTicketData(params.order, {
3786
+ requireFullyPaid: params.requireFullyPaid
3787
+ });
3788
+ case 4:
3789
+ printableOrder = _context40.sent;
3790
+ if (hasSmallTicketData((_payment_info = printableOrder.payment_info) === null || _payment_info === void 0 ? void 0 : _payment_info.small_ticket_data)) {
3791
+ _context40.next = 7;
3792
+ break;
3793
+ }
3794
+ return _context40.abrupt("return", {
3795
+ printed: false,
3796
+ order: printableOrder
3797
+ });
3798
+ case 7:
3799
+ _context40.next = 9;
3800
+ return this.dispatchPrintOtherReceiptTask({
3801
+ checkoutData: params.checkoutData,
3802
+ syncedOrder: printableOrder,
3803
+ response: params.response,
3804
+ receiptOnly: true
3805
+ });
3806
+ case 9:
3807
+ return _context40.abrupt("return", {
3808
+ printed: true,
3809
+ order: printableOrder
3810
+ });
3811
+ case 10:
3812
+ case "end":
3813
+ return _context40.stop();
2862
3814
  }
2863
- }, _callee29, this, [[3, 23]]);
3815
+ }, _callee40, this);
2864
3816
  }));
2865
- function fetchBookingListFromAPI(_x28) {
2866
- return _fetchBookingListFromAPI.apply(this, arguments);
3817
+ function dispatchLocalReceiptPrint(_x44) {
3818
+ return _dispatchLocalReceiptPrint.apply(this, arguments);
2867
3819
  }
2868
- return fetchBookingListFromAPI;
2869
- }())
3820
+ return dispatchLocalReceiptPrint;
3821
+ }()
2870
3822
  }, {
2871
3823
  key: "handleOrderCheckoutSubmit",
2872
3824
  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) {
3825
+ var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3826
+ var backendPath, data, title, checkoutData, pendingResult, pendingOrder;
3827
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3828
+ while (1) switch (_context41.prev = _context41.next) {
2878
3829
  case 0:
2879
3830
  backendPath = params.backendPath, data = params.data, title = params.title;
2880
3831
  this.logInfo("".concat(title, ": \u5F00\u59CB\u5904\u7406"), {
@@ -2883,79 +3834,51 @@ var Server = /*#__PURE__*/function () {
2883
3834
  external_sale_number: data === null || data === void 0 ? void 0 : data.external_sale_number,
2884
3835
  order_number: data === null || data === void 0 ? void 0 : data.order_number
2885
3836
  });
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({
3837
+ _context41.next = 4;
3838
+ return this.ensureCheckoutOrderNumbers(data, title);
3839
+ case 4:
3840
+ checkoutData = _context41.sent;
3841
+ _context41.next = 7;
3842
+ return this.handlePendingSyncCheckoutOrder({
2892
3843
  backendPath: backendPath,
2893
- data: data,
3844
+ data: checkoutData,
2894
3845
  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() {}
3846
+ reason: 'checkout 已转入设备任务同步'
2903
3847
  });
2904
- case 8:
2905
- response = _context30.sent;
2906
- fresh = this.extractOrderDataFromCheckoutResponse(response);
2907
- if (!(fresh && this.order)) {
2908
- _context30.next = 17;
3848
+ case 7:
3849
+ pendingResult = _context41.sent;
3850
+ if (!((pendingResult === null || pendingResult === void 0 ? void 0 : pendingResult.status) === true)) {
3851
+ _context41.next = 15;
2909
3852
  break;
2910
3853
  }
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;
3854
+ pendingOrder = pendingResult.data;
3855
+ if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder))) {
3856
+ _context41.next = 13;
2942
3857
  break;
2943
3858
  }
2944
- return _context30.abrupt("return", backendError);
2945
- case 28:
2946
- return _context30.abrupt("return", this.handlePendingSyncCheckoutOrder({
3859
+ _context41.next = 13;
3860
+ return this.dispatchLocalReceiptPrint({
3861
+ checkoutData: checkoutData,
3862
+ order: pendingOrder,
3863
+ response: pendingResult,
3864
+ requireFullyPaid: true
3865
+ });
3866
+ case 13:
3867
+ _context41.next = 15;
3868
+ return this.dispatchCheckoutSyncTask({
2947
3869
  backendPath: backendPath,
2948
- data: data,
2949
- title: title,
2950
- reason: errorMessage
2951
- }));
2952
- case 29:
3870
+ data: checkoutData,
3871
+ title: title
3872
+ });
3873
+ case 15:
3874
+ return _context41.abrupt("return", pendingResult);
3875
+ case 16:
2953
3876
  case "end":
2954
- return _context30.stop();
3877
+ return _context41.stop();
2955
3878
  }
2956
- }, _callee30, this, [[5, 21]]);
3879
+ }, _callee41, this);
2957
3880
  }));
2958
- function handleOrderCheckoutSubmit(_x29) {
3881
+ function handleOrderCheckoutSubmit(_x45) {
2959
3882
  return _handleOrderCheckoutSubmit.apply(this, arguments);
2960
3883
  }
2961
3884
  return handleOrderCheckoutSubmit;
@@ -2963,96 +3886,314 @@ var Server = /*#__PURE__*/function () {
2963
3886
  }, {
2964
3887
  key: "handlePendingSyncCheckoutOrder",
2965
3888
  value: function () {
2966
- var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3889
+ var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
2967
3890
  var backendPath, data, title, reason, pendingOrder, errorMessage;
2968
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2969
- while (1) switch (_context31.prev = _context31.next) {
3891
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3892
+ while (1) switch (_context42.prev = _context42.next) {
2970
3893
  case 0:
2971
3894
  backendPath = params.backendPath, data = params.data, title = params.title, reason = params.reason;
2972
- pendingOrder = this.buildPendingSyncCheckoutOrder(data);
3895
+ _context42.next = 3;
3896
+ return this.buildPendingSyncCheckoutOrder(data);
3897
+ case 3:
3898
+ pendingOrder = _context42.sent;
2973
3899
  if (pendingOrder) {
2974
- _context31.next = 5;
3900
+ _context42.next = 7;
2975
3901
  break;
2976
3902
  }
2977
3903
  this.logError("".concat(title, ": checkout \u5931\u8D25\u4E14\u8BA2\u5355\u7F3A\u5C11\u672C\u5730\u5B58\u50A8\u6807\u8BC6"), {
2978
3904
  backendPath: backendPath,
2979
3905
  reason: reason
2980
3906
  });
2981
- return _context31.abrupt("return", {
3907
+ return _context42.abrupt("return", {
2982
3908
  code: 500,
2983
3909
  status: false,
2984
3910
  message: '订单缺少本地存储标识,无法写入待同步队列',
2985
3911
  data: null
2986
3912
  });
2987
- case 5:
3913
+ case 7:
2988
3914
  if (!(!this.order || typeof this.order.upsertPendingSyncOrders !== 'function')) {
2989
- _context31.next = 8;
3915
+ _context42.next = 10;
2990
3916
  break;
2991
3917
  }
2992
3918
  this.logError("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u5F85\u540C\u6B65\u5199\u5165"), {
2993
3919
  backendPath: backendPath,
2994
3920
  reason: reason
2995
3921
  });
2996
- return _context31.abrupt("return", {
3922
+ return _context42.abrupt("return", {
2997
3923
  code: 500,
2998
3924
  status: false,
2999
3925
  message: 'Order 模块不支持本地待同步写入',
3000
3926
  data: null
3001
3927
  });
3002
- case 8:
3003
- _context31.prev = 8;
3004
- _context31.next = 11;
3928
+ case 10:
3929
+ _context42.prev = 10;
3930
+ _context42.next = 13;
3005
3931
  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"), {
3932
+ case 13:
3933
+ this.logWarning("".concat(title, ": \u8BA2\u5355\u5DF2\u5199\u5165\u672C\u5730\u5F85\u540C\u6B65"), {
3008
3934
  backendPath: backendPath,
3009
3935
  reason: reason,
3010
3936
  order_id: pendingOrder.order_id,
3011
3937
  external_sale_number: pendingOrder.external_sale_number,
3012
3938
  order_number: pendingOrder.order_number
3013
3939
  });
3014
- return _context31.abrupt("return", {
3940
+ return _context42.abrupt("return", {
3015
3941
  code: 200,
3016
3942
  status: true,
3017
3943
  message: '',
3018
3944
  data: pendingOrder
3019
3945
  });
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);
3946
+ case 17:
3947
+ _context42.prev = 17;
3948
+ _context42.t0 = _context42["catch"](10);
3949
+ errorMessage = _context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0);
3024
3950
  this.logError("".concat(title, ": \u5199\u5165\u672C\u5730\u5F85\u540C\u6B65\u8BA2\u5355\u5931\u8D25"), {
3025
3951
  backendPath: backendPath,
3026
3952
  reason: reason,
3027
3953
  error: errorMessage
3028
3954
  });
3029
- return _context31.abrupt("return", {
3955
+ return _context42.abrupt("return", {
3030
3956
  code: 500,
3031
3957
  status: false,
3032
3958
  message: errorMessage,
3033
3959
  data: null
3034
3960
  });
3035
- case 20:
3961
+ case 22:
3036
3962
  case "end":
3037
- return _context31.stop();
3963
+ return _context42.stop();
3038
3964
  }
3039
- }, _callee31, this, [[8, 15]]);
3965
+ }, _callee42, this, [[10, 17]]);
3040
3966
  }));
3041
- function handlePendingSyncCheckoutOrder(_x30) {
3967
+ function handlePendingSyncCheckoutOrder(_x46) {
3042
3968
  return _handlePendingSyncCheckoutOrder.apply(this, arguments);
3043
3969
  }
3044
3970
  return handlePendingSyncCheckoutOrder;
3045
3971
  }()
3046
3972
  }, {
3047
3973
  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
- });
3974
+ value: function () {
3975
+ var _buildPendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(data) {
3976
+ var hasStorageKey;
3977
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3978
+ while (1) switch (_context43.prev = _context43.next) {
3979
+ case 0:
3980
+ if (!(!data || _typeof(data) !== 'object')) {
3981
+ _context43.next = 2;
3982
+ break;
3983
+ }
3984
+ return _context43.abrupt("return", null);
3985
+ case 2:
3986
+ 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 !== '';
3987
+ if (hasStorageKey) {
3988
+ _context43.next = 5;
3989
+ break;
3990
+ }
3991
+ return _context43.abrupt("return", null);
3992
+ case 5:
3993
+ return _context43.abrupt("return", this.withLocalSmallTicketData(_objectSpread(_objectSpread({}, data), {}, {
3994
+ need_sync: 1
3995
+ }), {
3996
+ requireFullyPaid: true
3997
+ }));
3998
+ case 6:
3999
+ case "end":
4000
+ return _context43.stop();
4001
+ }
4002
+ }, _callee43, this);
4003
+ }));
4004
+ function buildPendingSyncCheckoutOrder(_x47) {
4005
+ return _buildPendingSyncCheckoutOrder.apply(this, arguments);
4006
+ }
4007
+ return buildPendingSyncCheckoutOrder;
4008
+ }()
4009
+ }, {
4010
+ key: "shouldBuildSmallTicketData",
4011
+ value: function shouldBuildSmallTicketData(order) {
4012
+ var _order$payment_info, _ref50, _order$small_ticket_d;
4013
+ if (!order || _typeof(order) !== 'object') return false;
4014
+ if (hasSmallTicketData((_order$payment_info = order.payment_info) === null || _order$payment_info === void 0 ? void 0 : _order$payment_info.small_ticket_data)) return false;
4015
+ 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;
4016
+ }
4017
+ }, {
4018
+ key: "shouldPrintSyncedOrder",
4019
+ value: function shouldPrintSyncedOrder(params) {
4020
+ if (this.hasPaymentStatus(params.syncedOrder)) {
4021
+ return this.isSalesOrderFullyPaid(params.syncedOrder);
4022
+ }
4023
+ return this.isSalesOrderFullyPaid(params.checkoutData);
4024
+ }
4025
+ }, {
4026
+ key: "hasPaymentStatus",
4027
+ value: function hasPaymentStatus(order) {
4028
+ 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) !== '';
4029
+ }
4030
+ }, {
4031
+ key: "isSalesOrderFullyPaid",
4032
+ value: function isSalesOrderFullyPaid(order) {
4033
+ var _order$summary$amount, _order$summary, _ref51, _ref52, _order$summary$expect, _order$summary2, _order$summary3;
4034
+ if (!order || _typeof(order) !== 'object') return false;
4035
+ var paymentStatus = String(order.payment_status || '').toLowerCase();
4036
+ if (paymentStatus === 'paid' || paymentStatus === 'finished') return true;
4037
+ if (paymentStatus === 'partially_paid' || paymentStatus === 'payment_processing' || paymentStatus === 'pending' || paymentStatus === 'unpaid') {
4038
+ return false;
4039
+ }
4040
+ 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;
4041
+ if (amountGap !== undefined && amountGap !== null && amountGap !== '') {
4042
+ return this.toAmountNumber(amountGap) <= 0;
4043
+ }
4044
+ var paidAmount = this.sumPaidOrderPayments(order.payments);
4045
+ 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);
4046
+ if (targetAmount <= 0) return paidAmount > 0;
4047
+ return paidAmount >= targetAmount;
3055
4048
  }
4049
+ }, {
4050
+ key: "sumPaidOrderPayments",
4051
+ value: function sumPaidOrderPayments(payments) {
4052
+ var _this10 = this;
4053
+ if (!Array.isArray(payments)) return 0;
4054
+ return payments.reduce(function (sum, payment) {
4055
+ var _payment$amount;
4056
+ var status = String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase();
4057
+ if (status === 'voided' || status === 'failed' || status === 'cancelled') return sum;
4058
+ 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);
4059
+ }, 0);
4060
+ }
4061
+ }, {
4062
+ key: "toAmountNumber",
4063
+ value: function toAmountNumber(value) {
4064
+ if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
4065
+ if (typeof value !== 'string') return 0;
4066
+ var parsed = Number(value.replace(/[^\d.-]/g, ''));
4067
+ return Number.isFinite(parsed) ? parsed : 0;
4068
+ }
4069
+ }, {
4070
+ key: "buildSmallTicketProductMap",
4071
+ value: function () {
4072
+ var _buildSmallTicketProductMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order) {
4073
+ var _this$products,
4074
+ _this11 = this;
4075
+ var products, productIds, entries;
4076
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4077
+ while (1) switch (_context45.prev = _context45.next) {
4078
+ case 0:
4079
+ products = Array.isArray(order === null || order === void 0 ? void 0 : order.products) ? order.products : [];
4080
+ productIds = Array.from(new Set(products.map(function (product) {
4081
+ var _product$product_id;
4082
+ 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;
4083
+ }).filter(function (id) {
4084
+ return id !== undefined && id !== null && id !== '';
4085
+ })));
4086
+ if (!(!productIds.length || typeof ((_this$products = this.products) === null || _this$products === void 0 ? void 0 : _this$products.getProductById) !== 'function')) {
4087
+ _context45.next = 4;
4088
+ break;
4089
+ }
4090
+ return _context45.abrupt("return", {});
4091
+ case 4:
4092
+ _context45.next = 6;
4093
+ return Promise.all(productIds.map( /*#__PURE__*/function () {
4094
+ var _ref53 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(id) {
4095
+ var _this11$products, _this11$products$getP, product;
4096
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4097
+ while (1) switch (_context44.prev = _context44.next) {
4098
+ case 0:
4099
+ _context44.prev = 0;
4100
+ _context44.next = 3;
4101
+ 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));
4102
+ case 3:
4103
+ product = _context44.sent;
4104
+ return _context44.abrupt("return", product ? [String(id), product] : null);
4105
+ case 7:
4106
+ _context44.prev = 7;
4107
+ _context44.t0 = _context44["catch"](0);
4108
+ _this11.logWarning('buildSmallTicketProductMap: 查询本地商品失败', {
4109
+ product_id: id,
4110
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
4111
+ });
4112
+ return _context44.abrupt("return", null);
4113
+ case 11:
4114
+ case "end":
4115
+ return _context44.stop();
4116
+ }
4117
+ }, _callee44, null, [[0, 7]]);
4118
+ }));
4119
+ return function (_x49) {
4120
+ return _ref53.apply(this, arguments);
4121
+ };
4122
+ }()));
4123
+ case 6:
4124
+ entries = _context45.sent;
4125
+ return _context45.abrupt("return", entries.reduce(function (map, entry) {
4126
+ if (!entry) return map;
4127
+ var _entry = _slicedToArray(entry, 2),
4128
+ id = _entry[0],
4129
+ product = _entry[1];
4130
+ map[id] = product;
4131
+ return map;
4132
+ }, {}));
4133
+ case 8:
4134
+ case "end":
4135
+ return _context45.stop();
4136
+ }
4137
+ }, _callee45, this);
4138
+ }));
4139
+ function buildSmallTicketProductMap(_x48) {
4140
+ return _buildSmallTicketProductMap.apply(this, arguments);
4141
+ }
4142
+ return buildSmallTicketProductMap;
4143
+ }()
4144
+ }, {
4145
+ key: "withLocalSmallTicketData",
4146
+ value: function () {
4147
+ var _withLocalSmallTicketData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(order, options) {
4148
+ var productMap, smallTicketData;
4149
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4150
+ while (1) switch (_context46.prev = _context46.next) {
4151
+ case 0:
4152
+ if (this.shouldBuildSmallTicketData(order)) {
4153
+ _context46.next = 2;
4154
+ break;
4155
+ }
4156
+ return _context46.abrupt("return", order);
4157
+ case 2:
4158
+ if (!(options !== null && options !== void 0 && options.requireFullyPaid && !this.isSalesOrderFullyPaid(order))) {
4159
+ _context46.next = 4;
4160
+ break;
4161
+ }
4162
+ return _context46.abrupt("return", order);
4163
+ case 4:
4164
+ _context46.prev = 4;
4165
+ _context46.next = 7;
4166
+ return this.buildSmallTicketProductMap(order);
4167
+ case 7:
4168
+ productMap = _context46.sent;
4169
+ smallTicketData = buildSmallTicketData({
4170
+ order: order,
4171
+ shopInfo: this.getSmallTicketShopInfo(),
4172
+ productMap: productMap
4173
+ });
4174
+ return _context46.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
4175
+ payment_info: _objectSpread(_objectSpread({}, order.payment_info || {}), {}, {
4176
+ small_ticket_data: smallTicketData
4177
+ })
4178
+ }));
4179
+ case 12:
4180
+ _context46.prev = 12;
4181
+ _context46.t0 = _context46["catch"](4);
4182
+ this.logError('withLocalSmallTicketData: 生成本地小票数据失败', {
4183
+ error: _context46.t0 instanceof Error ? _context46.t0.message : String(_context46.t0)
4184
+ });
4185
+ return _context46.abrupt("return", order);
4186
+ case 16:
4187
+ case "end":
4188
+ return _context46.stop();
4189
+ }
4190
+ }, _callee46, this, [[4, 12]]);
4191
+ }));
4192
+ function withLocalSmallTicketData(_x50, _x51) {
4193
+ return _withLocalSmallTicketData.apply(this, arguments);
4194
+ }
4195
+ return withLocalSmallTicketData;
4196
+ }()
3056
4197
  }, {
3057
4198
  key: "parseOrderIdsParam",
3058
4199
  value:
@@ -3090,8 +4231,8 @@ var Server = /*#__PURE__*/function () {
3090
4231
  pushRaw(this.extractQueryParam(url, 'order_ids'));
3091
4232
  var seen = new Set();
3092
4233
  var result = [];
3093
- for (var _i = 0, _collected = collected; _i < _collected.length; _i++) {
3094
- var id = _collected[_i];
4234
+ for (var _i2 = 0, _collected = collected; _i2 < _collected.length; _i2++) {
4235
+ var id = _collected[_i2];
3095
4236
  if (seen.has(id)) continue;
3096
4237
  seen.add(id);
3097
4238
  result.push(id);
@@ -3110,34 +4251,34 @@ var Server = /*#__PURE__*/function () {
3110
4251
  }, {
3111
4252
  key: "handleUpdateLocalOrdersBatch",
3112
4253
  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) {
4254
+ var _handleUpdateLocalOrdersBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(orderIds) {
4255
+ var _this$app13;
4256
+ var existedBefore, _iterator12, _step12, id, fetched, message, fetchedMap, _iterator13, _step13, order, oid, freshOrders, succeedIds, failed, _iterator14, _step14, _id, fresh, _message2, overwritten, inserted;
4257
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4258
+ while (1) switch (_context47.prev = _context47.next) {
3118
4259
  case 0:
3119
4260
  this.logInfo('handleUpdateLocalOrdersBatch: 开始处理', {
3120
4261
  count: orderIds.length,
3121
4262
  orderIds: orderIds
3122
4263
  });
3123
4264
  if (this.order) {
3124
- _context32.next = 4;
4265
+ _context47.next = 4;
3125
4266
  break;
3126
4267
  }
3127
4268
  this.logError('handleUpdateLocalOrdersBatch: Order 模块未注册');
3128
- return _context32.abrupt("return", {
4269
+ return _context47.abrupt("return", {
3129
4270
  code: 500,
3130
4271
  status: false,
3131
4272
  message: 'Order 模块未注册',
3132
4273
  data: null
3133
4274
  });
3134
4275
  case 4:
3135
- if ((_this$app6 = this.app) !== null && _this$app6 !== void 0 && _this$app6.request) {
3136
- _context32.next = 7;
4276
+ if ((_this$app13 = this.app) !== null && _this$app13 !== void 0 && _this$app13.request) {
4277
+ _context47.next = 7;
3137
4278
  break;
3138
4279
  }
3139
4280
  this.logError('handleUpdateLocalOrdersBatch: app.request 不可用');
3140
- return _context32.abrupt("return", {
4281
+ return _context47.abrupt("return", {
3141
4282
  code: 500,
3142
4283
  status: false,
3143
4284
  message: 'app.request 不可用',
@@ -3146,35 +4287,35 @@ var Server = /*#__PURE__*/function () {
3146
4287
  case 7:
3147
4288
  // 拉取前先记录"本地是否已存在",用于区分 overwritten / inserted
3148
4289
  existedBefore = new Map();
3149
- _iterator11 = _createForOfIteratorHelper(orderIds);
4290
+ _iterator12 = _createForOfIteratorHelper(orderIds);
3150
4291
  try {
3151
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3152
- id = _step11.value;
4292
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
4293
+ id = _step12.value;
3153
4294
  existedBefore.set(id, !!this.order.getOrderByOrderId(id));
3154
4295
  }
3155
4296
 
3156
4297
  // 走 orderDataSource 的批量 HTTP 通道,一次请求拉回多笔详情
3157
4298
  } catch (err) {
3158
- _iterator11.e(err);
4299
+ _iterator12.e(err);
3159
4300
  } finally {
3160
- _iterator11.f();
4301
+ _iterator12.f();
3161
4302
  }
3162
4303
  fetched = [];
3163
- _context32.prev = 11;
3164
- _context32.next = 14;
4304
+ _context47.prev = 11;
4305
+ _context47.next = 14;
3165
4306
  return this.order.fetchOrdersByHttp(orderIds);
3166
4307
  case 14:
3167
- fetched = _context32.sent;
3168
- _context32.next = 22;
4308
+ fetched = _context47.sent;
4309
+ _context47.next = 22;
3169
4310
  break;
3170
4311
  case 17:
3171
- _context32.prev = 17;
3172
- _context32.t0 = _context32["catch"](11);
3173
- message = _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0);
4312
+ _context47.prev = 17;
4313
+ _context47.t0 = _context47["catch"](11);
4314
+ message = _context47.t0 instanceof Error ? _context47.t0.message : String(_context47.t0);
3174
4315
  this.logError('handleUpdateLocalOrdersBatch: 批量拉取失败', {
3175
4316
  message: message
3176
4317
  });
3177
- return _context32.abrupt("return", {
4318
+ return _context47.abrupt("return", {
3178
4319
  code: 500,
3179
4320
  status: false,
3180
4321
  message: message,
@@ -3183,45 +4324,45 @@ var Server = /*#__PURE__*/function () {
3183
4324
  case 22:
3184
4325
  // 按返回结果中的 order_id 建索引,未命中即视为单笔失败
3185
4326
  fetchedMap = new Map();
3186
- _iterator12 = _createForOfIteratorHelper(fetched);
3187
- _context32.prev = 24;
3188
- _iterator12.s();
4327
+ _iterator13 = _createForOfIteratorHelper(fetched);
4328
+ _context47.prev = 24;
4329
+ _iterator13.s();
3189
4330
  case 26:
3190
- if ((_step12 = _iterator12.n()).done) {
3191
- _context32.next = 34;
4331
+ if ((_step13 = _iterator13.n()).done) {
4332
+ _context47.next = 34;
3192
4333
  break;
3193
4334
  }
3194
- order = _step12.value;
4335
+ order = _step13.value;
3195
4336
  oid = order === null || order === void 0 ? void 0 : order.order_id;
3196
4337
  if (!(oid === undefined || oid === null)) {
3197
- _context32.next = 31;
4338
+ _context47.next = 31;
3198
4339
  break;
3199
4340
  }
3200
- return _context32.abrupt("continue", 32);
4341
+ return _context47.abrupt("continue", 32);
3201
4342
  case 31:
3202
4343
  fetchedMap.set(String(oid), order);
3203
4344
  case 32:
3204
- _context32.next = 26;
4345
+ _context47.next = 26;
3205
4346
  break;
3206
4347
  case 34:
3207
- _context32.next = 39;
4348
+ _context47.next = 39;
3208
4349
  break;
3209
4350
  case 36:
3210
- _context32.prev = 36;
3211
- _context32.t1 = _context32["catch"](24);
3212
- _iterator12.e(_context32.t1);
4351
+ _context47.prev = 36;
4352
+ _context47.t1 = _context47["catch"](24);
4353
+ _iterator13.e(_context47.t1);
3213
4354
  case 39:
3214
- _context32.prev = 39;
3215
- _iterator12.f();
3216
- return _context32.finish(39);
4355
+ _context47.prev = 39;
4356
+ _iterator13.f();
4357
+ return _context47.finish(39);
3217
4358
  case 42:
3218
4359
  freshOrders = [];
3219
4360
  succeedIds = [];
3220
4361
  failed = [];
3221
- _iterator13 = _createForOfIteratorHelper(orderIds);
4362
+ _iterator14 = _createForOfIteratorHelper(orderIds);
3222
4363
  try {
3223
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3224
- _id = _step13.value;
4364
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
4365
+ _id = _step14.value;
3225
4366
  fresh = fetchedMap.get(_id);
3226
4367
  if (fresh) {
3227
4368
  freshOrders.push(fresh);
@@ -3234,31 +4375,31 @@ var Server = /*#__PURE__*/function () {
3234
4375
  }
3235
4376
  }
3236
4377
  } catch (err) {
3237
- _iterator13.e(err);
4378
+ _iterator14.e(err);
3238
4379
  } finally {
3239
- _iterator13.f();
4380
+ _iterator14.f();
3240
4381
  }
3241
4382
  if (!(freshOrders.length > 0)) {
3242
- _context32.next = 58;
4383
+ _context47.next = 58;
3243
4384
  break;
3244
4385
  }
3245
- _context32.prev = 48;
3246
- _context32.next = 51;
4386
+ _context47.prev = 48;
4387
+ _context47.next = 51;
3247
4388
  return this.order.upsertOrdersFromRemote(freshOrders);
3248
4389
  case 51:
3249
- _context32.next = 58;
4390
+ _context47.next = 58;
3250
4391
  break;
3251
4392
  case 53:
3252
- _context32.prev = 53;
3253
- _context32.t2 = _context32["catch"](48);
3254
- _message = _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2);
4393
+ _context47.prev = 53;
4394
+ _context47.t2 = _context47["catch"](48);
4395
+ _message2 = _context47.t2 instanceof Error ? _context47.t2.message : String(_context47.t2);
3255
4396
  this.logError('handleUpdateLocalOrdersBatch: 合并写入失败', {
3256
- message: _message
4397
+ message: _message2
3257
4398
  });
3258
- return _context32.abrupt("return", {
4399
+ return _context47.abrupt("return", {
3259
4400
  code: 500,
3260
4401
  status: false,
3261
- message: _message,
4402
+ message: _message2,
3262
4403
  data: null
3263
4404
  });
3264
4405
  case 58:
@@ -3274,7 +4415,7 @@ var Server = /*#__PURE__*/function () {
3274
4415
  insertedCount: inserted.length,
3275
4416
  failedCount: failed.length
3276
4417
  });
3277
- return _context32.abrupt("return", {
4418
+ return _context47.abrupt("return", {
3278
4419
  code: 200,
3279
4420
  status: true,
3280
4421
  message: '',
@@ -3286,11 +4427,11 @@ var Server = /*#__PURE__*/function () {
3286
4427
  });
3287
4428
  case 62:
3288
4429
  case "end":
3289
- return _context32.stop();
4430
+ return _context47.stop();
3290
4431
  }
3291
- }, _callee32, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
4432
+ }, _callee47, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
3292
4433
  }));
3293
- function handleUpdateLocalOrdersBatch(_x31) {
4434
+ function handleUpdateLocalOrdersBatch(_x52) {
3294
4435
  return _handleUpdateLocalOrdersBatch.apply(this, arguments);
3295
4436
  }
3296
4437
  return handleUpdateLocalOrdersBatch;
@@ -3311,11 +4452,11 @@ var Server = /*#__PURE__*/function () {
3311
4452
  var queryIndex = url.indexOf('?');
3312
4453
  if (queryIndex < 0) return null;
3313
4454
  var query = url.slice(queryIndex + 1);
3314
- var _iterator14 = _createForOfIteratorHelper(query.split('&')),
3315
- _step14;
4455
+ var _iterator15 = _createForOfIteratorHelper(query.split('&')),
4456
+ _step15;
3316
4457
  try {
3317
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3318
- var pair = _step14.value;
4458
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
4459
+ var pair = _step15.value;
3319
4460
  if (!pair) continue;
3320
4461
  var _pair$split = pair.split('='),
3321
4462
  _pair$split2 = _slicedToArray(_pair$split, 2),
@@ -3331,9 +4472,9 @@ var Server = /*#__PURE__*/function () {
3331
4472
  }
3332
4473
  }
3333
4474
  } catch (err) {
3334
- _iterator14.e(err);
4475
+ _iterator15.e(err);
3335
4476
  } finally {
3336
- _iterator14.f();
4477
+ _iterator15.f();
3337
4478
  }
3338
4479
  return null;
3339
4480
  }
@@ -3367,10 +4508,10 @@ var Server = /*#__PURE__*/function () {
3367
4508
  }, {
3368
4509
  key: "extractOrderDataFromCheckoutResponse",
3369
4510
  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];
4511
+ var _response$data5, _response$data6;
4512
+ 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];
4513
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
4514
+ var candidate = _candidates[_i3];
3374
4515
  if (!candidate || _typeof(candidate) !== 'object') continue;
3375
4516
  if (candidate.order_id !== undefined && candidate.order_id !== null) {
3376
4517
  return candidate;
@@ -3391,15 +4532,24 @@ var Server = /*#__PURE__*/function () {
3391
4532
  data: response
3392
4533
  };
3393
4534
  }
4535
+ }, {
4536
+ key: "isCheckoutResponseRejected",
4537
+ value: function isCheckoutResponseRejected(response) {
4538
+ var normalized = this.normalizeCheckoutResponse(response);
4539
+ var isErrorCode = (normalized === null || normalized === void 0 ? void 0 : normalized.code) !== undefined && normalized.code !== 200 && normalized.code !== '200';
4540
+ 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;
4541
+ var isErrorSuccess = (normalized === null || normalized === void 0 ? void 0 : normalized.success) === false;
4542
+ return isErrorCode || isErrorStatus || isErrorSuccess;
4543
+ }
3394
4544
  }, {
3395
4545
  key: "extractBackendErrorResponse",
3396
4546
  value: function extractBackendErrorResponse(error) {
3397
4547
  var _error$response,
3398
4548
  _error$response2,
3399
- _this7 = this;
4549
+ _this12 = this;
3400
4550
  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
4551
  return candidates.find(function (candidate) {
3402
- return _this7.isExplicitBackendErrorResponse(candidate);
4552
+ return _this12.isExplicitBackendErrorResponse(candidate);
3403
4553
  }) || null;
3404
4554
  }
3405
4555
  }, {
@@ -3518,24 +4668,24 @@ var Server = /*#__PURE__*/function () {
3518
4668
  }, {
3519
4669
  key: "recomputeAndNotifyFloorPlanQuery",
3520
4670
  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) {
4671
+ var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48() {
4672
+ var _iterator16, _step16, _step16$value, subscriberId, sub, result, errorMessage;
4673
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4674
+ while (1) switch (_context48.prev = _context48.next) {
3525
4675
  case 0:
3526
4676
  if (!(this.floorPlanQuerySubscribers.size === 0)) {
3527
- _context33.next = 2;
4677
+ _context48.next = 2;
3528
4678
  break;
3529
4679
  }
3530
- return _context33.abrupt("return");
4680
+ return _context48.abrupt("return");
3531
4681
  case 2:
3532
4682
  this.logInfo('recomputeAndNotifyFloorPlanQuery: 开始推送', {
3533
4683
  subscriberCount: this.floorPlanQuerySubscribers.size
3534
4684
  });
3535
- _iterator15 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
4685
+ _iterator16 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
3536
4686
  try {
3537
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
3538
- _step15$value = _slicedToArray(_step15.value, 2), subscriberId = _step15$value[0], sub = _step15$value[1];
4687
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
4688
+ _step16$value = _slicedToArray(_step16.value, 2), subscriberId = _step16$value[0], sub = _step16$value[1];
3539
4689
  try {
3540
4690
  result = this.computeFloorPlanQueryResult(sub.context);
3541
4691
  sub.callback(result);
@@ -3551,15 +4701,15 @@ var Server = /*#__PURE__*/function () {
3551
4701
  }
3552
4702
  }
3553
4703
  } catch (err) {
3554
- _iterator15.e(err);
4704
+ _iterator16.e(err);
3555
4705
  } finally {
3556
- _iterator15.f();
4706
+ _iterator16.f();
3557
4707
  }
3558
4708
  case 5:
3559
4709
  case "end":
3560
- return _context33.stop();
4710
+ return _context48.stop();
3561
4711
  }
3562
- }, _callee33, this);
4712
+ }, _callee48, this);
3563
4713
  }));
3564
4714
  function recomputeAndNotifyFloorPlanQuery() {
3565
4715
  return _recomputeAndNotifyFloorPlanQuery.apply(this, arguments);
@@ -3589,21 +4739,21 @@ var Server = /*#__PURE__*/function () {
3589
4739
  * filter 逻辑暂为 mock,仅记录参数
3590
4740
  */
3591
4741
  function () {
3592
- var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(data) {
4742
+ var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(data) {
3593
4743
  var rawList, result;
3594
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3595
- while (1) switch (_context34.prev = _context34.next) {
4744
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4745
+ while (1) switch (_context49.prev = _context49.next) {
3596
4746
  case 0:
3597
4747
  this.logInfo('computeOrderQueryResult: 开始过滤', {
3598
4748
  data: data
3599
4749
  });
3600
4750
  console.log('[Server] computeOrderQueryResult', data);
3601
4751
  if (this.order) {
3602
- _context34.next = 5;
4752
+ _context49.next = 5;
3603
4753
  break;
3604
4754
  }
3605
4755
  this.logError('computeOrderQueryResult: Order 模块未注册');
3606
- return _context34.abrupt("return", {
4756
+ return _context49.abrupt("return", {
3607
4757
  code: 500,
3608
4758
  message: 'Order 模块未注册',
3609
4759
  data: {
@@ -3627,7 +4777,7 @@ var Server = /*#__PURE__*/function () {
3627
4777
  skip: result.skip,
3628
4778
  rejected: result.rejected
3629
4779
  });
3630
- return _context34.abrupt("return", {
4780
+ return _context49.abrupt("return", {
3631
4781
  code: 200,
3632
4782
  data: result,
3633
4783
  message: '',
@@ -3635,11 +4785,11 @@ var Server = /*#__PURE__*/function () {
3635
4785
  });
3636
4786
  case 10:
3637
4787
  case "end":
3638
- return _context34.stop();
4788
+ return _context49.stop();
3639
4789
  }
3640
- }, _callee34, this);
4790
+ }, _callee49, this);
3641
4791
  }));
3642
- function computeOrderQueryResult(_x32) {
4792
+ function computeOrderQueryResult(_x53) {
3643
4793
  return _computeOrderQueryResult.apply(this, arguments);
3644
4794
  }
3645
4795
  return computeOrderQueryResult;
@@ -3652,17 +4802,17 @@ var Server = /*#__PURE__*/function () {
3652
4802
  }, {
3653
4803
  key: "computeBookingQueryResult",
3654
4804
  value: (function () {
3655
- var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
4805
+ var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(data) {
3656
4806
  var rawOrders, result;
3657
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3658
- while (1) switch (_context35.prev = _context35.next) {
4807
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4808
+ while (1) switch (_context50.prev = _context50.next) {
3659
4809
  case 0:
3660
4810
  if (this.order) {
3661
- _context35.next = 3;
4811
+ _context50.next = 3;
3662
4812
  break;
3663
4813
  }
3664
4814
  this.logError('computeBookingQueryResult: Order 模块未注册');
3665
- return _context35.abrupt("return", {
4815
+ return _context50.abrupt("return", {
3666
4816
  code: 500,
3667
4817
  message: 'Order 模块未注册',
3668
4818
  data: {
@@ -3681,7 +4831,7 @@ var Server = /*#__PURE__*/function () {
3681
4831
  size: result.size,
3682
4832
  skip: result.skip
3683
4833
  });
3684
- return _context35.abrupt("return", {
4834
+ return _context50.abrupt("return", {
3685
4835
  code: 200,
3686
4836
  data: result,
3687
4837
  message: '',
@@ -3689,11 +4839,11 @@ var Server = /*#__PURE__*/function () {
3689
4839
  });
3690
4840
  case 8:
3691
4841
  case "end":
3692
- return _context35.stop();
4842
+ return _context50.stop();
3693
4843
  }
3694
- }, _callee35, this);
4844
+ }, _callee50, this);
3695
4845
  }));
3696
- function computeBookingQueryResult(_x33) {
4846
+ function computeBookingQueryResult(_x54) {
3697
4847
  return _computeBookingQueryResult.apply(this, arguments);
3698
4848
  }
3699
4849
  return computeBookingQueryResult;
@@ -3709,12 +4859,12 @@ var Server = /*#__PURE__*/function () {
3709
4859
  }, {
3710
4860
  key: "computeProductQueryResult",
3711
4861
  value: (function () {
3712
- var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(context, options) {
4862
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(context, options) {
3713
4863
  var _menu_list_ids$length3,
3714
- _this8 = this;
4864
+ _this13 = this;
3715
4865
  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) {
4866
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4867
+ while (1) switch (_context51.prev = _context51.next) {
3718
4868
  case 0:
3719
4869
  tTotal = performance.now();
3720
4870
  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 +4883,11 @@ var Server = /*#__PURE__*/function () {
3733
4883
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3734
4884
  });
3735
4885
  if (this.products) {
3736
- _context36.next = 7;
4886
+ _context51.next = 7;
3737
4887
  break;
3738
4888
  }
3739
4889
  this.logError('computeProductQueryResult: Products 模块未注册');
3740
- return _context36.abrupt("return", {
4890
+ return _context51.abrupt("return", {
3741
4891
  message: 'Products 模块未注册',
3742
4892
  data: {
3743
4893
  list: [],
@@ -3746,12 +4896,12 @@ var Server = /*#__PURE__*/function () {
3746
4896
  });
3747
4897
  case 7:
3748
4898
  if (!(queryIds.length > 0)) {
3749
- _context36.next = 18;
4899
+ _context51.next = 18;
3750
4900
  break;
3751
4901
  }
3752
4902
  uniqueIds = Array.from(new Set(queryIds));
3753
4903
  _tPrice = performance.now();
3754
- _context36.next = 12;
4904
+ _context51.next = 12;
3755
4905
  return this.products.getProductsWithPrice(schedule_date, {
3756
4906
  scheduleModule: this.getSchedule(),
3757
4907
  schedule_datetime: schedule_datetime,
@@ -3761,7 +4911,7 @@ var Server = /*#__PURE__*/function () {
3761
4911
  productIds: uniqueIds
3762
4912
  });
3763
4913
  case 12:
3764
- productsWithPrice = _context36.sent;
4914
+ productsWithPrice = _context51.sent;
3765
4915
  perfMark('computeQuery.getProductsWithPrice(ids)', performance.now() - _tPrice, {
3766
4916
  count: productsWithPrice.length,
3767
4917
  ids: uniqueIds
@@ -3780,7 +4930,7 @@ var Server = /*#__PURE__*/function () {
3780
4930
  ids: uniqueIds,
3781
4931
  count: _filteredProducts.length
3782
4932
  });
3783
- return _context36.abrupt("return", {
4933
+ return _context51.abrupt("return", {
3784
4934
  code: 200,
3785
4935
  data: {
3786
4936
  list: _filteredProducts,
@@ -3791,19 +4941,19 @@ var Server = /*#__PURE__*/function () {
3791
4941
  });
3792
4942
  case 18:
3793
4943
  if (!(product_id != null && Number.isFinite(Number(product_id)))) {
3794
- _context36.next = 30;
4944
+ _context51.next = 30;
3795
4945
  break;
3796
4946
  }
3797
4947
  pid = Number(product_id);
3798
4948
  _tPrice2 = performance.now();
3799
- _context36.next = 23;
4949
+ _context51.next = 23;
3800
4950
  return this.products.getProductsWithPrice(schedule_date, {
3801
4951
  scheduleModule: this.getSchedule()
3802
4952
  }, {
3803
4953
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3804
4954
  });
3805
4955
  case 23:
3806
- allProductsWithPrice = _context36.sent;
4956
+ allProductsWithPrice = _context51.sent;
3807
4957
  perfMark('computeQuery.getProductsWithPrice(single)', performance.now() - _tPrice2, {
3808
4958
  count: allProductsWithPrice.length,
3809
4959
  productId: pid
@@ -3823,7 +4973,7 @@ var Server = /*#__PURE__*/function () {
3823
4973
  productId: pid,
3824
4974
  found: !!item
3825
4975
  });
3826
- return _context36.abrupt("return", {
4976
+ return _context51.abrupt("return", {
3827
4977
  code: 200,
3828
4978
  data: item,
3829
4979
  message: item ? '' : '商品不存在或未发布',
@@ -3831,11 +4981,11 @@ var Server = /*#__PURE__*/function () {
3831
4981
  });
3832
4982
  case 30:
3833
4983
  if (this.menu) {
3834
- _context36.next = 33;
4984
+ _context51.next = 33;
3835
4985
  break;
3836
4986
  }
3837
4987
  this.logError('computeProductQueryResult: Menu 模块未注册');
3838
- return _context36.abrupt("return", {
4988
+ return _context51.abrupt("return", {
3839
4989
  message: 'Menu 模块未注册',
3840
4990
  data: {
3841
4991
  list: [],
@@ -3844,11 +4994,11 @@ var Server = /*#__PURE__*/function () {
3844
4994
  });
3845
4995
  case 33:
3846
4996
  if (this.schedule) {
3847
- _context36.next = 36;
4997
+ _context51.next = 36;
3848
4998
  break;
3849
4999
  }
3850
5000
  this.logError('computeProductQueryResult: Schedule 模块未注册');
3851
- return _context36.abrupt("return", {
5001
+ return _context51.abrupt("return", {
3852
5002
  message: 'Schedule 模块未注册',
3853
5003
  data: {
3854
5004
  list: [],
@@ -3861,8 +5011,8 @@ var Server = /*#__PURE__*/function () {
3861
5011
  tMenu = performance.now();
3862
5012
  menuList = this.menu.getMenuByIds(menu_list_ids);
3863
5013
  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;
5014
+ var _this13$schedule;
5015
+ return ((_this13$schedule = _this13.schedule) === null || _this13$schedule === void 0 ? void 0 : _this13$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
3866
5016
  });
3867
5017
  perfMark('computeQuery.filterActiveMenu', performance.now() - tMenu, {
3868
5018
  totalMenu: menuList.length,
@@ -3879,10 +5029,10 @@ var Server = /*#__PURE__*/function () {
3879
5029
  });
3880
5030
  tPrice = performance.now();
3881
5031
  if (!(scopedProductIds.length > 0)) {
3882
- _context36.next = 49;
5032
+ _context51.next = 49;
3883
5033
  break;
3884
5034
  }
3885
- _context36.next = 46;
5035
+ _context51.next = 46;
3886
5036
  return this.products.getProductsWithPrice(schedule_date, {
3887
5037
  scheduleModule: this.getSchedule(),
3888
5038
  schedule_datetime: schedule_datetime,
@@ -3892,13 +5042,13 @@ var Server = /*#__PURE__*/function () {
3892
5042
  productIds: productScope.isAllProducts ? undefined : scopedProductIds
3893
5043
  });
3894
5044
  case 46:
3895
- _context36.t0 = _context36.sent;
3896
- _context36.next = 50;
5045
+ _context51.t0 = _context51.sent;
5046
+ _context51.next = 50;
3897
5047
  break;
3898
5048
  case 49:
3899
- _context36.t0 = [];
5049
+ _context51.t0 = [];
3900
5050
  case 50:
3901
- filteredProducts = _context36.t0;
5051
+ filteredProducts = _context51.t0;
3902
5052
  perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
3903
5053
  count: filteredProducts.length,
3904
5054
  scopedProductCount: scopedProductIds.length
@@ -3931,7 +5081,7 @@ var Server = /*#__PURE__*/function () {
3931
5081
  filteredCount: filteredProducts.length,
3932
5082
  activeMenuCount: activeMenuList.length
3933
5083
  });
3934
- return _context36.abrupt("return", {
5084
+ return _context51.abrupt("return", {
3935
5085
  code: 200,
3936
5086
  data: {
3937
5087
  list: filteredProducts,
@@ -3942,11 +5092,11 @@ var Server = /*#__PURE__*/function () {
3942
5092
  });
3943
5093
  case 62:
3944
5094
  case "end":
3945
- return _context36.stop();
5095
+ return _context51.stop();
3946
5096
  }
3947
- }, _callee36, this);
5097
+ }, _callee51, this);
3948
5098
  }));
3949
- function computeProductQueryResult(_x34, _x35) {
5099
+ function computeProductQueryResult(_x55, _x56) {
3950
5100
  return _computeProductQueryResult.apply(this, arguments);
3951
5101
  }
3952
5102
  return computeProductQueryResult;
@@ -3961,72 +5111,72 @@ var Server = /*#__PURE__*/function () {
3961
5111
  }, {
3962
5112
  key: "recomputeAndNotifyProductQuery",
3963
5113
  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) {
5114
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(options) {
5115
+ var _iterator17, _step17, _step17$value, subscriberId, subscriber, result, errorMessage;
5116
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
5117
+ while (1) switch (_context52.prev = _context52.next) {
3968
5118
  case 0:
3969
5119
  if (!(this.productQuerySubscribers.size === 0)) {
3970
- _context37.next = 2;
5120
+ _context52.next = 2;
3971
5121
  break;
3972
5122
  }
3973
- return _context37.abrupt("return");
5123
+ return _context52.abrupt("return");
3974
5124
  case 2:
3975
5125
  this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
3976
5126
  subscriberCount: this.productQuerySubscribers.size,
3977
5127
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3978
5128
  });
3979
- _iterator16 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
3980
- _context37.prev = 4;
3981
- _iterator16.s();
5129
+ _iterator17 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
5130
+ _context52.prev = 4;
5131
+ _iterator17.s();
3982
5132
  case 6:
3983
- if ((_step16 = _iterator16.n()).done) {
3984
- _context37.next = 22;
5133
+ if ((_step17 = _iterator17.n()).done) {
5134
+ _context52.next = 22;
3985
5135
  break;
3986
5136
  }
3987
- _step16$value = _slicedToArray(_step16.value, 2), subscriberId = _step16$value[0], subscriber = _step16$value[1];
3988
- _context37.prev = 8;
3989
- _context37.next = 11;
5137
+ _step17$value = _slicedToArray(_step17.value, 2), subscriberId = _step17$value[0], subscriber = _step17$value[1];
5138
+ _context52.prev = 8;
5139
+ _context52.next = 11;
3990
5140
  return this.computeProductQueryResult(subscriber.context, {
3991
5141
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
3992
5142
  });
3993
5143
  case 11:
3994
- result = _context37.sent;
5144
+ result = _context52.sent;
3995
5145
  subscriber.callback(result);
3996
5146
  this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
3997
5147
  subscriberId: subscriberId
3998
5148
  });
3999
- _context37.next = 20;
5149
+ _context52.next = 20;
4000
5150
  break;
4001
5151
  case 16:
4002
- _context37.prev = 16;
4003
- _context37.t0 = _context37["catch"](8);
4004
- errorMessage = _context37.t0 instanceof Error ? _context37.t0.message : String(_context37.t0);
5152
+ _context52.prev = 16;
5153
+ _context52.t0 = _context52["catch"](8);
5154
+ errorMessage = _context52.t0 instanceof Error ? _context52.t0.message : String(_context52.t0);
4005
5155
  this.logError('recomputeAndNotifyProductQuery: 推送失败', {
4006
5156
  subscriberId: subscriberId,
4007
5157
  error: errorMessage
4008
5158
  });
4009
5159
  case 20:
4010
- _context37.next = 6;
5160
+ _context52.next = 6;
4011
5161
  break;
4012
5162
  case 22:
4013
- _context37.next = 27;
5163
+ _context52.next = 27;
4014
5164
  break;
4015
5165
  case 24:
4016
- _context37.prev = 24;
4017
- _context37.t1 = _context37["catch"](4);
4018
- _iterator16.e(_context37.t1);
5166
+ _context52.prev = 24;
5167
+ _context52.t1 = _context52["catch"](4);
5168
+ _iterator17.e(_context52.t1);
4019
5169
  case 27:
4020
- _context37.prev = 27;
4021
- _iterator16.f();
4022
- return _context37.finish(27);
5170
+ _context52.prev = 27;
5171
+ _iterator17.f();
5172
+ return _context52.finish(27);
4023
5173
  case 30:
4024
5174
  case "end":
4025
- return _context37.stop();
5175
+ return _context52.stop();
4026
5176
  }
4027
- }, _callee37, this, [[4, 24, 27, 30], [8, 16]]);
5177
+ }, _callee52, this, [[4, 24, 27, 30], [8, 16]]);
4028
5178
  }));
4029
- function recomputeAndNotifyProductQuery(_x36) {
5179
+ function recomputeAndNotifyProductQuery(_x57) {
4030
5180
  return _recomputeAndNotifyProductQuery.apply(this, arguments);
4031
5181
  }
4032
5182
  return recomputeAndNotifyProductQuery;
@@ -4038,37 +5188,37 @@ var Server = /*#__PURE__*/function () {
4038
5188
  }, {
4039
5189
  key: "recomputeAndNotifyOrderQuery",
4040
5190
  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) {
5191
+ var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53() {
5192
+ var notifyStartAt, _iterator18, _step18, _step18$value, subscriberId, subscriber, computeStartAt, result, computeEndAt, callbackStartAt, callbackEndAt, errorMessage, notifyEndAt;
5193
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
5194
+ while (1) switch (_context53.prev = _context53.next) {
4045
5195
  case 0:
4046
5196
  if (!(this.orderQuerySubscribers.size === 0)) {
4047
- _context38.next = 2;
5197
+ _context53.next = 2;
4048
5198
  break;
4049
5199
  }
4050
- return _context38.abrupt("return");
5200
+ return _context53.abrupt("return");
4051
5201
  case 2:
4052
5202
  notifyStartAt = Date.now();
4053
5203
  this.logInfo('recomputeAndNotifyOrderQuery: 开始推送', {
4054
5204
  subscriberCount: this.orderQuerySubscribers.size,
4055
5205
  notifyStartAt: new Date(notifyStartAt).toISOString()
4056
5206
  });
4057
- _iterator17 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
4058
- _context38.prev = 5;
4059
- _iterator17.s();
5207
+ _iterator18 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
5208
+ _context53.prev = 5;
5209
+ _iterator18.s();
4060
5210
  case 7:
4061
- if ((_step17 = _iterator17.n()).done) {
4062
- _context38.next = 27;
5211
+ if ((_step18 = _iterator18.n()).done) {
5212
+ _context53.next = 27;
4063
5213
  break;
4064
5214
  }
4065
- _step17$value = _slicedToArray(_step17.value, 2), subscriberId = _step17$value[0], subscriber = _step17$value[1];
4066
- _context38.prev = 9;
5215
+ _step18$value = _slicedToArray(_step18.value, 2), subscriberId = _step18$value[0], subscriber = _step18$value[1];
5216
+ _context53.prev = 9;
4067
5217
  computeStartAt = Date.now();
4068
- _context38.next = 13;
5218
+ _context53.next = 13;
4069
5219
  return this.computeOrderQueryResult(subscriber.context);
4070
5220
  case 13:
4071
- result = _context38.sent;
5221
+ result = _context53.sent;
4072
5222
  computeEndAt = Date.now();
4073
5223
  callbackStartAt = Date.now();
4074
5224
  subscriber.callback(result);
@@ -4079,30 +5229,30 @@ var Server = /*#__PURE__*/function () {
4079
5229
  callbackDurationMs: callbackEndAt - callbackStartAt,
4080
5230
  totalDurationMs: callbackEndAt - computeStartAt
4081
5231
  });
4082
- _context38.next = 25;
5232
+ _context53.next = 25;
4083
5233
  break;
4084
5234
  case 21:
4085
- _context38.prev = 21;
4086
- _context38.t0 = _context38["catch"](9);
4087
- errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0);
5235
+ _context53.prev = 21;
5236
+ _context53.t0 = _context53["catch"](9);
5237
+ errorMessage = _context53.t0 instanceof Error ? _context53.t0.message : String(_context53.t0);
4088
5238
  this.logError('recomputeAndNotifyOrderQuery: 推送失败', {
4089
5239
  subscriberId: subscriberId,
4090
5240
  error: errorMessage
4091
5241
  });
4092
5242
  case 25:
4093
- _context38.next = 7;
5243
+ _context53.next = 7;
4094
5244
  break;
4095
5245
  case 27:
4096
- _context38.next = 32;
5246
+ _context53.next = 32;
4097
5247
  break;
4098
5248
  case 29:
4099
- _context38.prev = 29;
4100
- _context38.t1 = _context38["catch"](5);
4101
- _iterator17.e(_context38.t1);
5249
+ _context53.prev = 29;
5250
+ _context53.t1 = _context53["catch"](5);
5251
+ _iterator18.e(_context53.t1);
4102
5252
  case 32:
4103
- _context38.prev = 32;
4104
- _iterator17.f();
4105
- return _context38.finish(32);
5253
+ _context53.prev = 32;
5254
+ _iterator18.f();
5255
+ return _context53.finish(32);
4106
5256
  case 35:
4107
5257
  notifyEndAt = Date.now();
4108
5258
  this.logInfo('recomputeAndNotifyOrderQuery: 推送完成', {
@@ -4111,9 +5261,9 @@ var Server = /*#__PURE__*/function () {
4111
5261
  });
4112
5262
  case 37:
4113
5263
  case "end":
4114
- return _context38.stop();
5264
+ return _context53.stop();
4115
5265
  }
4116
- }, _callee38, this, [[5, 29, 32, 35], [9, 21]]);
5266
+ }, _callee53, this, [[5, 29, 32, 35], [9, 21]]);
4117
5267
  }));
4118
5268
  function recomputeAndNotifyOrderQuery() {
4119
5269
  return _recomputeAndNotifyOrderQuery.apply(this, arguments);
@@ -4121,73 +5271,197 @@ var Server = /*#__PURE__*/function () {
4121
5271
  return recomputeAndNotifyOrderQuery;
4122
5272
  }()
4123
5273
  /**
4124
- * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
5274
+ * 订单变更后通知 sales 搜索订阅者。
5275
+ * 仅回传当前查询已返回订单号集合中的变更订单。
5276
+ *
5277
+ * @example
5278
+ * this.notifySalesSearchSubscribers({ list: [], changedOrders: [order], source: 'pubsub.bodyUpsert' })
4125
5279
  */
4126
5280
  )
5281
+ }, {
5282
+ key: "notifySalesSearchSubscribers",
5283
+ value: function notifySalesSearchSubscribers(payload) {
5284
+ var _this14 = this;
5285
+ if (this.salesSearchSubscribers.size === 0) return;
5286
+ var changedOrders = this.extractChangedOrdersFromPayload(payload);
5287
+ if (changedOrders.length === 0) {
5288
+ return;
5289
+ }
5290
+ var _iterator19 = _createForOfIteratorHelper(this.salesSearchSubscribers.entries()),
5291
+ _step19;
5292
+ try {
5293
+ var _loop = function _loop() {
5294
+ var _step19$value = _slicedToArray(_step19.value, 2),
5295
+ subscriberId = _step19$value[0],
5296
+ subscriber = _step19$value[1];
5297
+ try {
5298
+ var changedVisibleOrders = changedOrders.filter(function (order) {
5299
+ var orderId = _this14.getSalesSearchOrderId(order);
5300
+ return !!orderId && subscriber.visibleOrderIds.has(orderId);
5301
+ });
5302
+ if (changedVisibleOrders.length === 0) {
5303
+ return 1; // continue
5304
+ }
5305
+ subscriber.callback(_this14.buildSalesSearchDeltaResponse(subscriber, changedVisibleOrders));
5306
+ _this14.logInfo('notifySalesSearchSubscribers: 已推送 delta', {
5307
+ subscriberId: subscriberId,
5308
+ kind: subscriber.kind,
5309
+ count: changedVisibleOrders.length
5310
+ });
5311
+ } catch (error) {
5312
+ var errorMessage = error instanceof Error ? error.message : String(error);
5313
+ _this14.logError('notifySalesSearchSubscribers: 推送失败', {
5314
+ subscriberId: subscriberId,
5315
+ error: errorMessage
5316
+ });
5317
+ }
5318
+ };
5319
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
5320
+ if (_loop()) continue;
5321
+ }
5322
+ } catch (err) {
5323
+ _iterator19.e(err);
5324
+ } finally {
5325
+ _iterator19.f();
5326
+ }
5327
+ }
5328
+
5329
+ /**
5330
+ * 从订单变更事件中提取明确 delta。
5331
+ *
5332
+ * @example
5333
+ * const list = this.extractChangedOrdersFromPayload(payload)
5334
+ */
5335
+ }, {
5336
+ key: "extractChangedOrdersFromPayload",
5337
+ value: function extractChangedOrdersFromPayload(payload) {
5338
+ if (!payload || Array.isArray(payload)) return [];
5339
+ return Array.isArray(payload.changedOrders) ? payload.changedOrders : [];
5340
+ }
5341
+
5342
+ /**
5343
+ * 构建与当前搜索接口一致的 delta 响应。
5344
+ *
5345
+ * @example
5346
+ * const response = this.buildSalesSearchDeltaResponse(subscriber, [order])
5347
+ */
5348
+ }, {
5349
+ key: "buildSalesSearchDeltaResponse",
5350
+ value: function buildSalesSearchDeltaResponse(subscriber, changedOrders) {
5351
+ if (subscriber.kind === 'aggregate') {
5352
+ return this.buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders);
5353
+ }
5354
+ var data = subscriber.lastResponseData || {};
5355
+ return {
5356
+ code: 200,
5357
+ status: true,
5358
+ message: '',
5359
+ data: _objectSpread(_objectSpread({}, data), {}, {
5360
+ list: changedOrders
5361
+ })
5362
+ };
5363
+ }
5364
+
5365
+ /**
5366
+ * 构建聚合搜索接口的 sales 分组 delta 响应。
5367
+ *
5368
+ * @example
5369
+ * const response = this.buildAggregateSalesSearchDeltaResponse(subscriber, [order])
5370
+ */
5371
+ }, {
5372
+ key: "buildAggregateSalesSearchDeltaResponse",
5373
+ value: function buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders) {
5374
+ var data = subscriber.lastResponseData || {};
5375
+ var results = Array.isArray(data === null || data === void 0 ? void 0 : data.results) ? data.results : [];
5376
+ var hasSalesGroup = results.some(function (item) {
5377
+ return (item === null || item === void 0 ? void 0 : item.module) === 'sales';
5378
+ });
5379
+ var nextResults = hasSalesGroup ? results.map(function (item) {
5380
+ return (item === null || item === void 0 ? void 0 : item.module) === 'sales' ? _objectSpread(_objectSpread({}, item), {}, {
5381
+ list: changedOrders
5382
+ }) : item;
5383
+ }) : [{
5384
+ module: 'sales',
5385
+ list: changedOrders,
5386
+ count: changedOrders.length
5387
+ }];
5388
+ return {
5389
+ code: 200,
5390
+ status: true,
5391
+ message: '',
5392
+ data: _objectSpread(_objectSpread({}, data), {}, {
5393
+ results: nextResults
5394
+ })
5395
+ };
5396
+ }
5397
+
5398
+ /**
5399
+ * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
5400
+ */
4127
5401
  }, {
4128
5402
  key: "recomputeAndNotifyBookingQuery",
4129
5403
  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) {
5404
+ var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54() {
5405
+ var _iterator20, _step20, _step20$value, subscriberId, subscriber, result, errorMessage;
5406
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
5407
+ while (1) switch (_context54.prev = _context54.next) {
4134
5408
  case 0:
4135
5409
  if (!(this.bookingQuerySubscribers.size === 0)) {
4136
- _context39.next = 2;
5410
+ _context54.next = 2;
4137
5411
  break;
4138
5412
  }
4139
- return _context39.abrupt("return");
5413
+ return _context54.abrupt("return");
4140
5414
  case 2:
4141
5415
  this.logInfo('recomputeAndNotifyBookingQuery: 开始推送', {
4142
5416
  subscriberCount: this.bookingQuerySubscribers.size
4143
5417
  });
4144
- _iterator18 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
4145
- _context39.prev = 4;
4146
- _iterator18.s();
5418
+ _iterator20 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
5419
+ _context54.prev = 4;
5420
+ _iterator20.s();
4147
5421
  case 6:
4148
- if ((_step18 = _iterator18.n()).done) {
4149
- _context39.next = 22;
5422
+ if ((_step20 = _iterator20.n()).done) {
5423
+ _context54.next = 22;
4150
5424
  break;
4151
5425
  }
4152
- _step18$value = _slicedToArray(_step18.value, 2), subscriberId = _step18$value[0], subscriber = _step18$value[1];
4153
- _context39.prev = 8;
4154
- _context39.next = 11;
5426
+ _step20$value = _slicedToArray(_step20.value, 2), subscriberId = _step20$value[0], subscriber = _step20$value[1];
5427
+ _context54.prev = 8;
5428
+ _context54.next = 11;
4155
5429
  return this.computeBookingQueryResult(subscriber.context);
4156
5430
  case 11:
4157
- result = _context39.sent;
5431
+ result = _context54.sent;
4158
5432
  subscriber.callback(result);
4159
5433
  this.logInfo('recomputeAndNotifyBookingQuery: 已推送', {
4160
5434
  subscriberId: subscriberId
4161
5435
  });
4162
- _context39.next = 20;
5436
+ _context54.next = 20;
4163
5437
  break;
4164
5438
  case 16:
4165
- _context39.prev = 16;
4166
- _context39.t0 = _context39["catch"](8);
4167
- errorMessage = _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0);
5439
+ _context54.prev = 16;
5440
+ _context54.t0 = _context54["catch"](8);
5441
+ errorMessage = _context54.t0 instanceof Error ? _context54.t0.message : String(_context54.t0);
4168
5442
  this.logError('recomputeAndNotifyBookingQuery: 推送失败', {
4169
5443
  subscriberId: subscriberId,
4170
5444
  error: errorMessage
4171
5445
  });
4172
5446
  case 20:
4173
- _context39.next = 6;
5447
+ _context54.next = 6;
4174
5448
  break;
4175
5449
  case 22:
4176
- _context39.next = 27;
5450
+ _context54.next = 27;
4177
5451
  break;
4178
5452
  case 24:
4179
- _context39.prev = 24;
4180
- _context39.t1 = _context39["catch"](4);
4181
- _iterator18.e(_context39.t1);
5453
+ _context54.prev = 24;
5454
+ _context54.t1 = _context54["catch"](4);
5455
+ _iterator20.e(_context54.t1);
4182
5456
  case 27:
4183
- _context39.prev = 27;
4184
- _iterator18.f();
4185
- return _context39.finish(27);
5457
+ _context54.prev = 27;
5458
+ _iterator20.f();
5459
+ return _context54.finish(27);
4186
5460
  case 30:
4187
5461
  case "end":
4188
- return _context39.stop();
5462
+ return _context54.stop();
4189
5463
  }
4190
- }, _callee39, this, [[4, 24, 27, 30], [8, 16]]);
5464
+ }, _callee54, this, [[4, 24, 27, 30], [8, 16]]);
4191
5465
  }));
4192
5466
  function recomputeAndNotifyBookingQuery() {
4193
5467
  return _recomputeAndNotifyBookingQuery.apply(this, arguments);
@@ -4217,11 +5491,11 @@ var Server = /*#__PURE__*/function () {
4217
5491
  var allowedProductIds = new Set();
4218
5492
  var allowedCollectionIds = new Set();
4219
5493
  var hasProductAll = false;
4220
- var _iterator19 = _createForOfIteratorHelper(activeMenuList),
4221
- _step19;
5494
+ var _iterator21 = _createForOfIteratorHelper(activeMenuList),
5495
+ _step21;
4222
5496
  try {
4223
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
4224
- var menu = _step19.value;
5497
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
5498
+ var menu = _step21.value;
4225
5499
  var config = menu.partyroom_package;
4226
5500
  if (!config) {
4227
5501
  console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
@@ -4281,9 +5555,9 @@ var Server = /*#__PURE__*/function () {
4281
5555
 
4282
5556
  // 如果有餐牌允许所有商品,返回所有商品
4283
5557
  } catch (err) {
4284
- _iterator19.e(err);
5558
+ _iterator21.e(err);
4285
5559
  } finally {
4286
- _iterator19.f();
5560
+ _iterator21.f();
4287
5561
  }
4288
5562
  if (hasProductAll) {
4289
5563
  this.logInfo('getProductScopeByMenuConfig: 返回所有商品 scope(product_all)');