@pisell/pisellos 0.10.95 → 0.10.96

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.
@@ -130,6 +130,7 @@ var Server = /*#__PURE__*/function () {
130
130
  _defineProperty(this, "localPaymentUpdateQueues", new Map());
131
131
  _defineProperty(this, "paymentIdentityRefreshes", new Map());
132
132
  _defineProperty(this, "receiptFulfillmentConfigInFlight", new Map());
133
+ _defineProperty(this, "cloudInvoiceSubmissions", new Map());
133
134
  _defineProperty(this, "floorPlanQuerySubscribers", new Map());
134
135
  // 模块注册表 - 定义所有可用的模块配置
135
136
  _defineProperty(this, "moduleRegistry", {
@@ -789,7 +790,7 @@ var Server = /*#__PURE__*/function () {
789
790
  _defineProperty(this, "handleUpdateLocalOrder", /*#__PURE__*/function () {
790
791
  var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref32) {
791
792
  var _data$order_id, _ref34, _this$app;
792
- var url, data, batchIds, rawOrderId, orderId, backendPath, _response$data, response, fresh, exists, _yield$_this$order$ov, overwritten, errorMessage;
793
+ var url, data, batchIds, rawOrderId, orderId, backendPath, _response$data, response, _fresh, exists, _yield$_this$order$ov, overwritten, errorMessage;
793
794
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
794
795
  while (1) switch (_context13.prev = _context13.next) {
795
796
  case 0:
@@ -863,8 +864,8 @@ var Server = /*#__PURE__*/function () {
863
864
  });
864
865
  case 22:
865
866
  response = _context13.sent;
866
- fresh = (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : response;
867
- if (!(!fresh || _typeof(fresh) !== 'object' || fresh.order_id == null)) {
867
+ _fresh = (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : response;
868
+ if (!(!_fresh || _typeof(_fresh) !== 'object' || _fresh.order_id == null)) {
868
869
  _context13.next = 27;
869
870
  break;
870
871
  }
@@ -885,7 +886,7 @@ var Server = /*#__PURE__*/function () {
885
886
  break;
886
887
  }
887
888
  _context13.next = 31;
888
- return _this.order.overwriteExistingOrder(fresh);
889
+ return _this.order.overwriteExistingOrder(_fresh);
889
890
  case 31:
890
891
  _yield$_this$order$ov = _context13.sent;
891
892
  overwritten = _yield$_this$order$ov.overwritten;
@@ -905,7 +906,7 @@ var Server = /*#__PURE__*/function () {
905
906
  });
906
907
  case 35:
907
908
  _context13.next = 37;
908
- return _this.order.upsertOrdersFromRemote([fresh]);
909
+ return _this.order.upsertOrdersFromRemote([_fresh]);
909
910
  case 37:
910
911
  _this.logInfo('handleUpdateLocalOrder: 本地合并新订单完成', {
911
912
  orderId: orderId
@@ -1411,7 +1412,7 @@ var Server = /*#__PURE__*/function () {
1411
1412
  _defineProperty(this, "handleLocalOrderReceiptSnapshot", /*#__PURE__*/function () {
1412
1413
  var _ref52 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(_ref51) {
1413
1414
  var _this$order2;
1414
- var data, input, lookup, _payment_info, sourceOrder, remoteResult, paymentInfo, rebuiltOrder, smallTicketData, message;
1415
+ var data, input, lookup, _payment_info, sourceOrder, remoteResult, rebuiltOrder, smallTicketData, message;
1415
1416
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1416
1417
  while (1) switch (_context22.prev = _context22.next) {
1417
1418
  case 0:
@@ -1474,24 +1475,13 @@ var Server = /*#__PURE__*/function () {
1474
1475
  case 17:
1475
1476
  sourceOrder = remoteResult.order;
1476
1477
  case 18:
1477
- paymentInfo = _objectSpread({}, sourceOrder.payment_info || {});
1478
- delete paymentInfo.small_ticket_data;
1479
- _context22.next = 22;
1480
- return _this.withLocalSmallTicketData(_objectSpread(_objectSpread({}, sourceOrder), {}, {
1481
- small_ticket_data_flag: 1,
1482
- payment_info: paymentInfo
1483
- }), {
1484
- locales: _this.normalizeRequestedReceiptLocales(input.locales),
1485
- invoiceTemplateSettings: input.template_settings === undefined ? undefined : _this.normalizePrintInvoiceTemplateSettings(input.template_settings),
1486
- applyTemplateVisibility: true,
1487
- includeReceiptKeys: input.template_settings !== undefined,
1488
- refreshResourceReference: true
1489
- });
1490
- case 22:
1478
+ _context22.next = 20;
1479
+ return _this.rebuildOrderReceipt(sourceOrder, input.template_settings === undefined ? undefined : _this.normalizePrintInvoiceTemplateSettings(input.template_settings), _this.normalizeRequestedReceiptLocales(input.locales));
1480
+ case 20:
1491
1481
  rebuiltOrder = _context22.sent;
1492
1482
  smallTicketData = (_payment_info = rebuiltOrder.payment_info) === null || _payment_info === void 0 ? void 0 : _payment_info.small_ticket_data;
1493
1483
  if (hasSmallTicketData(smallTicketData)) {
1494
- _context22.next = 26;
1484
+ _context22.next = 24;
1495
1485
  break;
1496
1486
  }
1497
1487
  return _context22.abrupt("return", {
@@ -1502,7 +1492,7 @@ var Server = /*#__PURE__*/function () {
1502
1492
  small_ticket_data: null
1503
1493
  }
1504
1494
  });
1505
- case 26:
1495
+ case 24:
1506
1496
  return _context22.abrupt("return", {
1507
1497
  code: 200,
1508
1498
  status: true,
@@ -1519,8 +1509,8 @@ var Server = /*#__PURE__*/function () {
1519
1509
  })
1520
1510
  }
1521
1511
  });
1522
- case 29:
1523
- _context22.prev = 29;
1512
+ case 27:
1513
+ _context22.prev = 27;
1524
1514
  _context22.t0 = _context22["catch"](7);
1525
1515
  message = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1526
1516
  _this.logError('handleLocalOrderReceiptSnapshot: 生成失败', {
@@ -1535,11 +1525,11 @@ var Server = /*#__PURE__*/function () {
1535
1525
  small_ticket_data: null
1536
1526
  }
1537
1527
  });
1538
- case 34:
1528
+ case 32:
1539
1529
  case "end":
1540
1530
  return _context22.stop();
1541
1531
  }
1542
- }, _callee22, null, [[7, 29]]);
1532
+ }, _callee22, null, [[7, 27]]);
1543
1533
  }));
1544
1534
  return function (_x21) {
1545
1535
  return _ref52.apply(this, arguments);
@@ -3760,6 +3750,20 @@ var Server = /*#__PURE__*/function () {
3760
3750
  method: 'post',
3761
3751
  path: '/shop/local/print-order',
3762
3752
  handler: this.handleLocalPrintOrder.bind(this)
3753
+ }, {
3754
+ method: 'post',
3755
+ path: '/shop/local/cloud-order-invoice/lookup',
3756
+ handler: function handler(_ref65) {
3757
+ var data = _ref65.data;
3758
+ return _this9.handleCloudOrderInvoice(data, false);
3759
+ }
3760
+ }, {
3761
+ method: 'post',
3762
+ path: '/shop/local/cloud-order-invoice/submit',
3763
+ handler: function handler(_ref66) {
3764
+ var data = _ref66.data;
3765
+ return _this9.handleCloudOrderInvoice(data, true);
3766
+ }
3763
3767
  }, {
3764
3768
  method: 'post',
3765
3769
  path: '/shop/local/order-receipt-snapshot',
@@ -3780,13 +3784,13 @@ var Server = /*#__PURE__*/function () {
3780
3784
  method: 'post',
3781
3785
  path: '/shop/local/orderPaymentReadiness',
3782
3786
  handler: function () {
3783
- var _handler = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(_ref65) {
3787
+ var _handler = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(_ref67) {
3784
3788
  var _this9$order;
3785
3789
  var data;
3786
3790
  return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3787
3791
  while (1) switch (_context44.prev = _context44.next) {
3788
3792
  case 0:
3789
- data = _ref65.data;
3793
+ data = _ref67.data;
3790
3794
  _context44.next = 3;
3791
3795
  return (_this9$order = _this9.order) === null || _this9$order === void 0 ? void 0 : _this9$order.getLocalOrderForPaymentReadiness(data === null || data === void 0 ? void 0 : data.sale_id);
3792
3796
  case 3:
@@ -4192,11 +4196,11 @@ var Server = /*#__PURE__*/function () {
4192
4196
  */
4193
4197
  }, {
4194
4198
  key: "syncProductQueryScheduleTimers",
4195
- value: function syncProductQueryScheduleTimers(_ref67) {
4199
+ value: function syncProductQueryScheduleTimers(_ref69) {
4196
4200
  var _this$products$getLas3, _this$products2, _this$products2$getLa;
4197
- var subscriberId = _ref67.subscriberId,
4198
- menu_list_ids = _ref67.menu_list_ids,
4199
- strategy_context = _ref67.strategy_context;
4201
+ var subscriberId = _ref69.subscriberId,
4202
+ menu_list_ids = _ref69.menu_list_ids,
4203
+ strategy_context = _ref69.strategy_context;
4200
4204
  this.clearSubscriberScheduleTimers(subscriberId);
4201
4205
  if (!this.shouldScheduleProductQueryReload(strategy_context)) {
4202
4206
  return;
@@ -4373,7 +4377,7 @@ var Server = /*#__PURE__*/function () {
4373
4377
  */
4374
4378
  function () {
4375
4379
  var _handleSalesSearchRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(kind, backendPath, data, config) {
4376
- var queryPayload, result, _ref68, callback, subscriberId, resetVisibleOrderIds, contextSignature, existing, shouldReset, visibleOrderIds, _iterator5, _step5, orderId;
4380
+ var queryPayload, result, _ref70, callback, subscriberId, resetVisibleOrderIds, contextSignature, existing, shouldReset, visibleOrderIds, _iterator5, _step5, orderId;
4377
4381
  return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4378
4382
  while (1) switch (_context52.prev = _context52.next) {
4379
4383
  case 0:
@@ -4382,7 +4386,7 @@ var Server = /*#__PURE__*/function () {
4382
4386
  return this.fetchSalesSearchFromAPI(backendPath, queryPayload);
4383
4387
  case 3:
4384
4388
  result = _context52.sent;
4385
- _ref68 = config || {}, callback = _ref68.callback, subscriberId = _ref68.subscriberId, resetVisibleOrderIds = _ref68.resetVisibleOrderIds;
4389
+ _ref70 = config || {}, callback = _ref70.callback, subscriberId = _ref70.subscriberId, resetVisibleOrderIds = _ref70.resetVisibleOrderIds;
4386
4390
  if (subscriberId && typeof callback === 'function') {
4387
4391
  contextSignature = this.buildSalesSearchSignature(kind, queryPayload);
4388
4392
  existing = this.salesSearchSubscribers.get(subscriberId);
@@ -6640,17 +6644,409 @@ var Server = /*#__PURE__*/function () {
6640
6644
  }, {
6641
6645
  key: "mergeLocalPrintOrderInput",
6642
6646
  value: function mergeLocalPrintOrderInput(localOrder, inputOrder) {
6643
- var _ref73, _localOrder$order_id, _ref74, _external_sale_number4;
6644
- var definedInput = Object.fromEntries(Object.entries(inputOrder || {}).filter(function (_ref71) {
6645
- var _ref72 = _slicedToArray(_ref71, 2),
6646
- value = _ref72[1];
6647
+ var _ref75, _localOrder$order_id, _ref76, _external_sale_number4;
6648
+ var definedInput = Object.fromEntries(Object.entries(inputOrder || {}).filter(function (_ref73) {
6649
+ var _ref74 = _slicedToArray(_ref73, 2),
6650
+ value = _ref74[1];
6647
6651
  return value !== undefined;
6648
6652
  }));
6649
6653
  return _objectSpread(_objectSpread(_objectSpread({}, localOrder), definedInput), {}, {
6650
- order_id: (_ref73 = (_localOrder$order_id = localOrder.order_id) !== null && _localOrder$order_id !== void 0 ? _localOrder$order_id : definedInput.order_id) !== null && _ref73 !== void 0 ? _ref73 : definedInput.orderId,
6651
- external_sale_number: (_ref74 = (_external_sale_number4 = localOrder.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : definedInput.external_sale_number) !== null && _ref74 !== void 0 ? _ref74 : definedInput.externalSaleNumber
6654
+ order_id: (_ref75 = (_localOrder$order_id = localOrder.order_id) !== null && _localOrder$order_id !== void 0 ? _localOrder$order_id : definedInput.order_id) !== null && _ref75 !== void 0 ? _ref75 : definedInput.orderId,
6655
+ external_sale_number: (_ref76 = (_external_sale_number4 = localOrder.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : definedInput.external_sale_number) !== null && _ref76 !== void 0 ? _ref76 : definedInput.externalSaleNumber
6652
6656
  });
6653
6657
  }
6658
+ }, {
6659
+ key: "getCloudInvoiceDevice",
6660
+ value: function () {
6661
+ var _getCloudInvoiceDevice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee68(shopId) {
6662
+ var readDevice, iot, iotId, fullNumber;
6663
+ return _regeneratorRuntime().wrap(function _callee68$(_context68) {
6664
+ while (1) switch (_context68.prev = _context68.next) {
6665
+ case 0:
6666
+ readDevice = this.getAppData('async_iot_device_info');
6667
+ _context68.next = 3;
6668
+ return readDevice === null || readDevice === void 0 ? void 0 : readDevice();
6669
+ case 3:
6670
+ iot = _context68.sent;
6671
+ if (!((iot === null || iot === void 0 ? void 0 : iot.shop_id) != null && String(iot.shop_id) !== shopId)) {
6672
+ _context68.next = 6;
6673
+ break;
6674
+ }
6675
+ throw new Error('Cloud invoice device belongs to another shop');
6676
+ case 6:
6677
+ iotId = String((iot === null || iot === void 0 ? void 0 : iot.id) || '').trim();
6678
+ fullNumber = String((iot === null || iot === void 0 ? void 0 : iot.number) || !iotId && this.getAppData('device_id') || '').trim();
6679
+ if (!(fullNumber && fullNumber !== '0')) {
6680
+ _context68.next = 10;
6681
+ break;
6682
+ }
6683
+ return _context68.abrupt("return", {
6684
+ id: fullNumber,
6685
+ target: (iot === null || iot === void 0 ? void 0 : iot.short_number) || fullNumber.slice(-2)
6686
+ });
6687
+ case 10:
6688
+ if (!(iotId && iotId !== '0')) {
6689
+ _context68.next = 12;
6690
+ break;
6691
+ }
6692
+ return _context68.abrupt("return", {
6693
+ id: 'iot-id:' + iotId,
6694
+ target: (iot === null || iot === void 0 ? void 0 : iot.short_number) || iotId
6695
+ });
6696
+ case 12:
6697
+ throw new Error('Cloud invoice device is unavailable');
6698
+ case 13:
6699
+ case "end":
6700
+ return _context68.stop();
6701
+ }
6702
+ }, _callee68, this);
6703
+ }));
6704
+ function getCloudInvoiceDevice(_x72) {
6705
+ return _getCloudInvoiceDevice.apply(this, arguments);
6706
+ }
6707
+ return getCloudInvoiceDevice;
6708
+ }()
6709
+ }, {
6710
+ key: "assertCloudInvoiceContext",
6711
+ value: function assertCloudInvoiceContext(context) {
6712
+ var _this$getAppData2, _this$getAppData3;
6713
+ if (String((_this$getAppData2 = this.getAppData('shop_id')) !== null && _this$getAppData2 !== void 0 ? _this$getAppData2 : '') !== context.shopId || String((_this$getAppData3 = this.getAppData('tenant_id')) !== null && _this$getAppData3 !== void 0 ? _this$getAppData3 : '') !== context.tenantId) {
6714
+ throw new Error('Cloud invoice shop context changed');
6715
+ }
6716
+ }
6717
+ }, {
6718
+ key: "loadCloudInvoiceOrder",
6719
+ value: function () {
6720
+ var _loadCloudInvoiceOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee69(context) {
6721
+ var _this19 = this;
6722
+ var orderId, shopId, hasReceiptDetail, local, result, saved;
6723
+ return _regeneratorRuntime().wrap(function _callee69$(_context69) {
6724
+ while (1) switch (_context69.prev = _context69.next) {
6725
+ case 0:
6726
+ if (this.order) {
6727
+ _context69.next = 2;
6728
+ break;
6729
+ }
6730
+ throw new Error('Cloud invoice order service is unavailable');
6731
+ case 2:
6732
+ orderId = context.orderId, shopId = context.shopId;
6733
+ hasReceiptDetail = function hasReceiptDetail(order) {
6734
+ var _order$summary, _order$summary2;
6735
+ // Use the same amount fields as the receipt builder, including historical
6736
+ // top-level amounts. Zero is a valid total; a missing total in a list row is not.
6737
+ var total = [(_order$summary = order.summary) === null || _order$summary === void 0 ? void 0 : _order$summary.expect_amount, order.expect_amount, (_order$summary2 = order.summary) === null || _order$summary2 === void 0 ? void 0 : _order$summary2.total_amount, order.total_amount].find(function (value) {
6738
+ return value != null && value !== '';
6739
+ });
6740
+ return typeof order.business_code === 'string' && !!order.business_code.trim() && (typeof total === 'number' || typeof total === 'string' && !!total.trim()) && Number.isFinite(Number(total)) && (Array.isArray(order.products) || Array.isArray(order.bookings));
6741
+ };
6742
+ _context69.next = 6;
6743
+ return this.order.getLocalOrderByLookup(orderId, {
6744
+ exactOrderId: true
6745
+ });
6746
+ case 6:
6747
+ local = _context69.sent;
6748
+ this.assertCloudInvoiceContext(context);
6749
+ if (!(local && String(local.order_id) === orderId)) {
6750
+ _context69.next = 13;
6751
+ break;
6752
+ }
6753
+ if (!(local.shop_id != null && String(local.shop_id) !== shopId)) {
6754
+ _context69.next = 11;
6755
+ break;
6756
+ }
6757
+ throw new Error('Cloud invoice order belongs to another shop');
6758
+ case 11:
6759
+ if (!(String(local.shop_id) === shopId && hasReceiptDetail(local))) {
6760
+ _context69.next = 13;
6761
+ break;
6762
+ }
6763
+ return _context69.abrupt("return", local);
6764
+ case 13:
6765
+ _context69.next = 15;
6766
+ return this.fetchAndPersistSalesOrderByLookup(orderId, {
6767
+ with: ['all']
6768
+ }, 'cloudOrderInvoice', undefined, function (fresh) {
6769
+ _this19.assertCloudInvoiceContext(context);
6770
+ if (String(fresh.order_id) !== orderId || fresh.shop_id != null && String(fresh.shop_id) !== shopId || !hasReceiptDetail(fresh)) {
6771
+ throw new Error('Cloud invoice order identity or detail is invalid');
6772
+ }
6773
+ // Some older shop-authenticated detail responses omit shop_id.
6774
+ return fresh.shop_id == null ? _objectSpread(_objectSpread({}, fresh), {}, {
6775
+ shop_id: Number(shopId)
6776
+ }) : fresh;
6777
+ });
6778
+ case 15:
6779
+ result = _context69.sent;
6780
+ this.assertCloudInvoiceContext(context);
6781
+ saved = result.order;
6782
+ if (!(!saved || String(saved.order_id) !== orderId || String(saved.shop_id) !== shopId || !hasReceiptDetail(saved))) {
6783
+ _context69.next = 20;
6784
+ break;
6785
+ }
6786
+ throw new Error(result.message || 'Cloud invoice order detail is unavailable');
6787
+ case 20:
6788
+ return _context69.abrupt("return", saved);
6789
+ case 21:
6790
+ case "end":
6791
+ return _context69.stop();
6792
+ }
6793
+ }, _callee69, this);
6794
+ }));
6795
+ function loadCloudInvoiceOrder(_x73) {
6796
+ return _loadCloudInvoiceOrder.apply(this, arguments);
6797
+ }
6798
+ return loadCloudInvoiceOrder;
6799
+ }()
6800
+ }, {
6801
+ key: "resolveCloudOrderInvoice",
6802
+ value: function () {
6803
+ var _resolveCloudOrderInvoice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee70(context, input, submit) {
6804
+ var _input$template_setti, _receipt$payment_info;
6805
+ var deviceTask, prior, _prior$payload, _prior$payload2, order, businessCode, settings, receipt, smallTicketData, device, task;
6806
+ return _regeneratorRuntime().wrap(function _callee70$(_context70) {
6807
+ while (1) switch (_context70.prev = _context70.next) {
6808
+ case 0:
6809
+ deviceTask = this.getDeviceTaskPlugin();
6810
+ if (!(!(deviceTask !== null && deviceTask !== void 0 && deviceTask.findByIdempotencyKey) || !deviceTask.dispatch)) {
6811
+ _context70.next = 3;
6812
+ break;
6813
+ }
6814
+ throw new Error('Cloud invoice task service is unavailable');
6815
+ case 3:
6816
+ _context70.next = 5;
6817
+ return deviceTask.findByIdempotencyKey(context.taskKey);
6818
+ case 5:
6819
+ prior = _context70.sent;
6820
+ this.assertCloudInvoiceContext(context);
6821
+ if (!prior) {
6822
+ _context70.next = 11;
6823
+ break;
6824
+ }
6825
+ if (!(!prior.uuid || String((_prior$payload = prior.payload) === null || _prior$payload === void 0 || (_prior$payload = _prior$payload.data) === null || _prior$payload === void 0 ? void 0 : _prior$payload.order_id) !== context.orderId || ((_prior$payload2 = prior.payload) === null || _prior$payload2 === void 0 ? void 0 : _prior$payload2.channel) !== context.channel)) {
6826
+ _context70.next = 10;
6827
+ break;
6828
+ }
6829
+ throw new Error('Cloud invoice message UUID conflicts with another task');
6830
+ case 10:
6831
+ return _context70.abrupt("return", {
6832
+ task_uuid: prior.uuid
6833
+ });
6834
+ case 11:
6835
+ _context70.next = 13;
6836
+ return this.loadCloudInvoiceOrder(context);
6837
+ case 13:
6838
+ order = _context70.sent;
6839
+ businessCode = order.business_code.trim();
6840
+ if (submit) {
6841
+ _context70.next = 17;
6842
+ break;
6843
+ }
6844
+ return _context70.abrupt("return", {
6845
+ business_code: businessCode,
6846
+ device_id: context.deviceId
6847
+ });
6848
+ case 17:
6849
+ if (!(input.business_code !== businessCode || typeof ((_input$template_setti = input.template_settings) === null || _input$template_setti === void 0 ? void 0 : _input$template_setti.template) !== 'string' || !input.template_settings.template.trim() || !Array.isArray(input.template_settings.modules))) {
6850
+ _context70.next = 19;
6851
+ break;
6852
+ }
6853
+ throw new Error('Cloud invoice template is missing or belongs to another business');
6854
+ case 19:
6855
+ settings = this.normalizePrintInvoiceTemplateSettings(input.template_settings);
6856
+ _context70.next = 22;
6857
+ return this.rebuildOrderReceipt(order, settings);
6858
+ case 22:
6859
+ receipt = _context70.sent;
6860
+ smallTicketData = (_receipt$payment_info = receipt.payment_info) === null || _receipt$payment_info === void 0 ? void 0 : _receipt$payment_info.small_ticket_data;
6861
+ if (hasSmallTicketData(smallTicketData)) {
6862
+ _context70.next = 26;
6863
+ break;
6864
+ }
6865
+ throw new Error('Cloud invoice snapshot is unavailable');
6866
+ case 26:
6867
+ _context70.next = 28;
6868
+ return this.getCloudInvoiceDevice(context.shopId);
6869
+ case 28:
6870
+ device = _context70.sent;
6871
+ if (!(device.id !== context.deviceId)) {
6872
+ _context70.next = 31;
6873
+ break;
6874
+ }
6875
+ throw new Error('Cloud invoice device changed');
6876
+ case 31:
6877
+ this.assertCloudInvoiceContext(context);
6878
+ _context70.next = 34;
6879
+ return deviceTask.dispatch({
6880
+ action: 'print_all',
6881
+ device_id: device.target,
6882
+ name: 'PRINT_V1',
6883
+ source: 'server',
6884
+ source_type: 'cloud_order_invoice',
6885
+ source_id: order.order_id,
6886
+ durability: 'durable',
6887
+ idempotency_key: context.taskKey,
6888
+ payload: {
6889
+ type: '0',
6890
+ shop_id: context.shopId,
6891
+ device_id: context.deviceId,
6892
+ message_uuid: context.messageUuid,
6893
+ channel: context.channel,
6894
+ template_settings: settings,
6895
+ data: {
6896
+ order_id: order.order_id,
6897
+ small_ticket_data: smallTicketData
6898
+ }
6899
+ }
6900
+ });
6901
+ case 34:
6902
+ task = _context70.sent;
6903
+ if (task !== null && task !== void 0 && task.uuid) {
6904
+ _context70.next = 37;
6905
+ break;
6906
+ }
6907
+ throw new Error('Cloud invoice task was not accepted');
6908
+ case 37:
6909
+ return _context70.abrupt("return", {
6910
+ task_uuid: task.uuid
6911
+ });
6912
+ case 38:
6913
+ case "end":
6914
+ return _context70.stop();
6915
+ }
6916
+ }, _callee70, this);
6917
+ }));
6918
+ function resolveCloudOrderInvoice(_x74, _x75, _x76) {
6919
+ return _resolveCloudOrderInvoice.apply(this, arguments);
6920
+ }
6921
+ return resolveCloudOrderInvoice;
6922
+ }()
6923
+ }, {
6924
+ key: "handleCloudOrderInvoice",
6925
+ value: function () {
6926
+ var _handleCloudOrderInvoice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee71(input, submit) {
6927
+ var _input$order_id2, _input$shop_id;
6928
+ var orderId, shopId, messageUuid, channel, _this$getAppData4, tenantId, _yield$this$getCloudI, deviceId, taskKey, context, result, pending, submission, message;
6929
+ return _regeneratorRuntime().wrap(function _callee71$(_context71) {
6930
+ while (1) switch (_context71.prev = _context71.next) {
6931
+ case 0:
6932
+ orderId = String((_input$order_id2 = input === null || input === void 0 ? void 0 : input.order_id) !== null && _input$order_id2 !== void 0 ? _input$order_id2 : '').trim();
6933
+ shopId = String((_input$shop_id = input === null || input === void 0 ? void 0 : input.shop_id) !== null && _input$shop_id !== void 0 ? _input$shop_id : '').trim();
6934
+ messageUuid = typeof (input === null || input === void 0 ? void 0 : input.message_uuid) === 'string' ? input.message_uuid.trim() : '';
6935
+ channel = typeof (input === null || input === void 0 ? void 0 : input.channel) === 'string' ? input.channel.trim() : '';
6936
+ if (!(!/^[1-9]\d*$/.test(orderId) || !/^[1-9]\d*$/.test(shopId) || !Number.isSafeInteger(Number(shopId)) || typeof input.order_id === 'number' && !Number.isSafeInteger(input.order_id) || !messageUuid || !channel)) {
6937
+ _context71.next = 6;
6938
+ break;
6939
+ }
6940
+ return _context71.abrupt("return", {
6941
+ code: 400,
6942
+ status: false,
6943
+ message: 'Invalid cloud invoice command',
6944
+ data: null
6945
+ });
6946
+ case 6:
6947
+ _context71.prev = 6;
6948
+ tenantId = String((_this$getAppData4 = this.getAppData('tenant_id')) !== null && _this$getAppData4 !== void 0 ? _this$getAppData4 : '');
6949
+ _context71.next = 10;
6950
+ return this.getCloudInvoiceDevice(shopId);
6951
+ case 10:
6952
+ _yield$this$getCloudI = _context71.sent;
6953
+ deviceId = _yield$this$getCloudI.id;
6954
+ if (!(submit && input.device_id !== deviceId)) {
6955
+ _context71.next = 14;
6956
+ break;
6957
+ }
6958
+ throw new Error('Cloud invoice device changed');
6959
+ case 14:
6960
+ taskKey = 'cloud_order_invoice:' + JSON.stringify([shopId, deviceId, messageUuid]);
6961
+ context = {
6962
+ taskKey: taskKey,
6963
+ shopId: shopId,
6964
+ tenantId: tenantId,
6965
+ deviceId: deviceId,
6966
+ orderId: orderId,
6967
+ messageUuid: messageUuid,
6968
+ channel: channel
6969
+ };
6970
+ this.assertCloudInvoiceContext(context);
6971
+ pending = this.cloudInvoiceSubmissions.get(taskKey);
6972
+ if (!pending) {
6973
+ _context71.next = 26;
6974
+ break;
6975
+ }
6976
+ if (!(pending.context.orderId !== orderId || pending.context.channel !== channel || pending.context.tenantId !== tenantId)) {
6977
+ _context71.next = 21;
6978
+ break;
6979
+ }
6980
+ throw new Error('Cloud invoice message UUID conflicts with an in-flight order');
6981
+ case 21:
6982
+ _context71.next = 23;
6983
+ return pending.result;
6984
+ case 23:
6985
+ result = _context71.sent;
6986
+ _context71.next = 41;
6987
+ break;
6988
+ case 26:
6989
+ if (!submit) {
6990
+ _context71.next = 38;
6991
+ break;
6992
+ }
6993
+ submission = this.resolveCloudOrderInvoice(context, input, true);
6994
+ this.cloudInvoiceSubmissions.set(taskKey, {
6995
+ context: context,
6996
+ result: submission
6997
+ });
6998
+ _context71.prev = 29;
6999
+ _context71.next = 32;
7000
+ return submission;
7001
+ case 32:
7002
+ result = _context71.sent;
7003
+ case 33:
7004
+ _context71.prev = 33;
7005
+ this.cloudInvoiceSubmissions.delete(taskKey);
7006
+ return _context71.finish(33);
7007
+ case 36:
7008
+ _context71.next = 41;
7009
+ break;
7010
+ case 38:
7011
+ _context71.next = 40;
7012
+ return this.resolveCloudOrderInvoice(context, input, false);
7013
+ case 40:
7014
+ result = _context71.sent;
7015
+ case 41:
7016
+ return _context71.abrupt("return", {
7017
+ code: 200,
7018
+ status: true,
7019
+ message: '',
7020
+ data: result
7021
+ });
7022
+ case 44:
7023
+ _context71.prev = 44;
7024
+ _context71.t0 = _context71["catch"](6);
7025
+ message = this.getUnknownErrorMessage(_context71.t0);
7026
+ this.logWarning('Cloud invoice request failed', {
7027
+ shopId: shopId,
7028
+ orderId: orderId,
7029
+ messageUuid: messageUuid,
7030
+ channel: channel,
7031
+ message: message
7032
+ });
7033
+ return _context71.abrupt("return", {
7034
+ code: 500,
7035
+ status: false,
7036
+ message: message,
7037
+ data: null
7038
+ });
7039
+ case 49:
7040
+ case "end":
7041
+ return _context71.stop();
7042
+ }
7043
+ }, _callee71, this, [[6, 44], [29,, 33, 36]]);
7044
+ }));
7045
+ function handleCloudOrderInvoice(_x77, _x78) {
7046
+ return _handleCloudOrderInvoice.apply(this, arguments);
7047
+ }
7048
+ return handleCloudOrderInvoice;
7049
+ }()
6654
7050
  }, {
6655
7051
  key: "normalizeRequestedReceiptLocales",
6656
7052
  value: function normalizeRequestedReceiptLocales(value) {
@@ -6661,6 +7057,22 @@ var Server = /*#__PURE__*/function () {
6661
7057
  return locale.trim();
6662
7058
  }).filter(Boolean)));
6663
7059
  }
7060
+ }, {
7061
+ key: "rebuildOrderReceipt",
7062
+ value: function rebuildOrderReceipt(order, templateSettings, locales) {
7063
+ var paymentInfo = _objectSpread({}, order.payment_info);
7064
+ delete paymentInfo.small_ticket_data;
7065
+ return this.withLocalSmallTicketData(_objectSpread(_objectSpread({}, order), {}, {
7066
+ small_ticket_data_flag: 1,
7067
+ payment_info: paymentInfo
7068
+ }), {
7069
+ locales: locales,
7070
+ invoiceTemplateSettings: templateSettings,
7071
+ applyTemplateVisibility: true,
7072
+ includeReceiptKeys: templateSettings !== undefined,
7073
+ refreshResourceReference: true
7074
+ });
7075
+ }
6664
7076
  }, {
6665
7077
  key: "resolveMachinecodeBatchMetadataLookup",
6666
7078
  value: function resolveMachinecodeBatchMetadataLookup(data) {
@@ -6672,57 +7084,57 @@ var Server = /*#__PURE__*/function () {
6672
7084
  }, {
6673
7085
  key: "syncMachinecodeRedeemStatusToLocalOrder",
6674
7086
  value: function () {
6675
- var _syncMachinecodeRedeemStatusToLocalOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee68(data, ids, status) {
7087
+ var _syncMachinecodeRedeemStatusToLocalOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee72(data, ids, status) {
6676
7088
  var _this$order5, _data$order_id2;
6677
7089
  var title, lookup, localOrder, orderId, voucherIdSet, vouchers, hasUpdatedVoucher, nextVouchers;
6678
- return _regeneratorRuntime().wrap(function _callee68$(_context68) {
6679
- while (1) switch (_context68.prev = _context68.next) {
7090
+ return _regeneratorRuntime().wrap(function _callee72$(_context72) {
7091
+ while (1) switch (_context72.prev = _context72.next) {
6680
7092
  case 0:
6681
7093
  title = 'handleMachinecodeBatchMetadata';
6682
7094
  lookup = this.resolveMachinecodeBatchMetadataLookup(data);
6683
7095
  if (!(lookup === undefined)) {
6684
- _context68.next = 5;
7096
+ _context72.next = 5;
6685
7097
  break;
6686
7098
  }
6687
7099
  this.logWarning("".concat(title, ": order lookup \u7F3A\u5931\uFF0C\u8DF3\u8FC7\u672C\u5730\u8BA2\u5355\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6688
7100
  batchSize: ids.length,
6689
7101
  status: status
6690
7102
  });
6691
- return _context68.abrupt("return");
7103
+ return _context72.abrupt("return");
6692
7104
  case 5:
6693
7105
  if ((_this$order5 = this.order) !== null && _this$order5 !== void 0 && _this$order5.getLocalOrderByLookup) {
6694
- _context68.next = 8;
7106
+ _context72.next = 8;
6695
7107
  break;
6696
7108
  }
6697
7109
  this.logWarning("".concat(title, ": Order \u6A21\u5757\u672A\u6CE8\u518C\uFF0C\u8DF3\u8FC7\u672C\u5730\u8BA2\u5355\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6698
7110
  lookup: lookup,
6699
7111
  status: status
6700
7112
  });
6701
- return _context68.abrupt("return");
7113
+ return _context72.abrupt("return");
6702
7114
  case 8:
6703
- _context68.next = 10;
7115
+ _context72.next = 10;
6704
7116
  return this.order.getLocalOrderByLookup(lookup);
6705
7117
  case 10:
6706
- localOrder = _context68.sent;
7118
+ localOrder = _context72.sent;
6707
7119
  orderId = (_data$order_id2 = data === null || data === void 0 ? void 0 : data.order_id) !== null && _data$order_id2 !== void 0 ? _data$order_id2 : data === null || data === void 0 ? void 0 : data.orderId;
6708
7120
  if (!(!localOrder && orderId !== undefined && orderId !== null && orderId !== '' && String(orderId) !== String(lookup))) {
6709
- _context68.next = 16;
7121
+ _context72.next = 16;
6710
7122
  break;
6711
7123
  }
6712
- _context68.next = 15;
7124
+ _context72.next = 15;
6713
7125
  return this.order.getLocalOrderByLookup(orderId);
6714
7126
  case 15:
6715
- localOrder = _context68.sent;
7127
+ localOrder = _context72.sent;
6716
7128
  case 16:
6717
7129
  if (localOrder) {
6718
- _context68.next = 19;
7130
+ _context72.next = 19;
6719
7131
  break;
6720
7132
  }
6721
7133
  this.logWarning("".concat(title, ": \u672C\u5730\u8BA2\u5355\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6722
7134
  lookup: lookup,
6723
7135
  status: status
6724
7136
  });
6725
- return _context68.abrupt("return");
7137
+ return _context72.abrupt("return");
6726
7138
  case 19:
6727
7139
  voucherIdSet = new Set(ids.filter(function (id) {
6728
7140
  return id !== undefined && id !== null && id !== '';
@@ -6730,14 +7142,14 @@ var Server = /*#__PURE__*/function () {
6730
7142
  return String(id);
6731
7143
  }));
6732
7144
  if (!(voucherIdSet.size === 0)) {
6733
- _context68.next = 23;
7145
+ _context72.next = 23;
6734
7146
  break;
6735
7147
  }
6736
7148
  this.logWarning("".concat(title, ": voucher ids \u7F3A\u5931\uFF0C\u8DF3\u8FC7\u672C\u5730\u8BA2\u5355\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6737
7149
  lookup: lookup,
6738
7150
  status: status
6739
7151
  });
6740
- return _context68.abrupt("return");
7152
+ return _context72.abrupt("return");
6741
7153
  case 23:
6742
7154
  vouchers = Array.isArray(localOrder.vouchers) ? localOrder.vouchers : [];
6743
7155
  hasUpdatedVoucher = false;
@@ -6751,7 +7163,7 @@ var Server = /*#__PURE__*/function () {
6751
7163
  });
6752
7164
  });
6753
7165
  if (hasUpdatedVoucher) {
6754
- _context68.next = 29;
7166
+ _context72.next = 29;
6755
7167
  break;
6756
7168
  }
6757
7169
  this.logWarning("".concat(title, ": \u672C\u5730\u8BA2\u5355\u672A\u547D\u4E2D\u4EFB\u4F55 voucher\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
@@ -6759,13 +7171,13 @@ var Server = /*#__PURE__*/function () {
6759
7171
  voucher_ids: Array.from(voucherIdSet),
6760
7172
  status: status
6761
7173
  });
6762
- return _context68.abrupt("return");
7174
+ return _context72.abrupt("return");
6763
7175
  case 29:
6764
7176
  if (!(typeof this.order.overwriteExistingOrder === 'function')) {
6765
- _context68.next = 34;
7177
+ _context72.next = 34;
6766
7178
  break;
6767
7179
  }
6768
- _context68.next = 32;
7180
+ _context72.next = 32;
6769
7181
  return this.order.overwriteExistingOrder(_objectSpread(_objectSpread({}, localOrder), {}, {
6770
7182
  vouchers: nextVouchers
6771
7183
  }));
@@ -6775,13 +7187,13 @@ var Server = /*#__PURE__*/function () {
6775
7187
  updatedCount: voucherIdSet.size,
6776
7188
  status: status
6777
7189
  });
6778
- return _context68.abrupt("return");
7190
+ return _context72.abrupt("return");
6779
7191
  case 34:
6780
7192
  if (!(data !== null && data !== void 0 && data.external_sale_number && typeof this.order.markOrderSyncedByExternalSaleNumber === 'function')) {
6781
- _context68.next = 39;
7193
+ _context72.next = 39;
6782
7194
  break;
6783
7195
  }
6784
- _context68.next = 37;
7196
+ _context72.next = 37;
6785
7197
  return this.order.markOrderSyncedByExternalSaleNumber({
6786
7198
  externalSaleNumber: data.external_sale_number,
6787
7199
  patch: {
@@ -6794,7 +7206,7 @@ var Server = /*#__PURE__*/function () {
6794
7206
  updatedCount: voucherIdSet.size,
6795
7207
  status: status
6796
7208
  });
6797
- return _context68.abrupt("return");
7209
+ return _context72.abrupt("return");
6798
7210
  case 39:
6799
7211
  this.logWarning("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u8BA2\u5355\u8986\u76D6\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6800
7212
  lookup: lookup,
@@ -6802,11 +7214,11 @@ var Server = /*#__PURE__*/function () {
6802
7214
  });
6803
7215
  case 40:
6804
7216
  case "end":
6805
- return _context68.stop();
7217
+ return _context72.stop();
6806
7218
  }
6807
- }, _callee68, this);
7219
+ }, _callee72, this);
6808
7220
  }));
6809
- function syncMachinecodeRedeemStatusToLocalOrder(_x72, _x73, _x74) {
7221
+ function syncMachinecodeRedeemStatusToLocalOrder(_x79, _x80, _x81) {
6810
7222
  return _syncMachinecodeRedeemStatusToLocalOrder.apply(this, arguments);
6811
7223
  }
6812
7224
  return syncMachinecodeRedeemStatusToLocalOrder;
@@ -6814,30 +7226,30 @@ var Server = /*#__PURE__*/function () {
6814
7226
  }, {
6815
7227
  key: "handleOrderCheckoutSubmit",
6816
7228
  value: function () {
6817
- var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee69(params) {
7229
+ var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee73(params) {
6818
7230
  var _params$data5, _params$data6, _this$order6, _this$order6$getLocal;
6819
7231
  var backendPath, title, lookup, localOrder, extractedInvoice, extractedTemplateSettings, data, invoiceLayoutConfig, invoiceTemplateSettings, receiptAutoPrintPaymentStatuses, normalizedData, numberedData, checkoutData, pendingResult, pendingOrder;
6820
- return _regeneratorRuntime().wrap(function _callee69$(_context69) {
6821
- while (1) switch (_context69.prev = _context69.next) {
7232
+ return _regeneratorRuntime().wrap(function _callee73$(_context73) {
7233
+ while (1) switch (_context73.prev = _context73.next) {
6822
7234
  case 0:
6823
7235
  backendPath = params.backendPath, title = params.title;
6824
7236
  lookup = ((_params$data5 = params.data) === null || _params$data5 === void 0 ? void 0 : _params$data5.order_id) || ((_params$data6 = params.data) === null || _params$data6 === void 0 ? void 0 : _params$data6.external_sale_number);
6825
- _context69.t0 = lookup;
6826
- if (!_context69.t0) {
6827
- _context69.next = 7;
7237
+ _context73.t0 = lookup;
7238
+ if (!_context73.t0) {
7239
+ _context73.next = 7;
6828
7240
  break;
6829
7241
  }
6830
- _context69.next = 6;
7242
+ _context73.next = 6;
6831
7243
  return (_this$order6 = this.order) === null || _this$order6 === void 0 || (_this$order6$getLocal = _this$order6.getLocalOrderByLookup) === null || _this$order6$getLocal === void 0 ? void 0 : _this$order6$getLocal.call(_this$order6, lookup);
6832
7244
  case 6:
6833
- _context69.t0 = _context69.sent;
7245
+ _context73.t0 = _context73.sent;
6834
7246
  case 7:
6835
- localOrder = _context69.t0;
7247
+ localOrder = _context73.t0;
6836
7248
  if (!(requiresLocalPaymentRefresh(params.data) || requiresLocalPaymentRefresh(localOrder))) {
6837
- _context69.next = 10;
7249
+ _context73.next = 10;
6838
7250
  break;
6839
7251
  }
6840
- return _context69.abrupt("return", {
7252
+ return _context73.abrupt("return", {
6841
7253
  code: 409,
6842
7254
  status: false,
6843
7255
  message: PAYMENT_REFRESH_MESSAGE,
@@ -6861,10 +7273,10 @@ var Server = /*#__PURE__*/function () {
6861
7273
  order_number: data === null || data === void 0 ? void 0 : data.order_number
6862
7274
  });
6863
7275
  if (!(data !== null && data !== void 0 && data.sync_mode || data !== null && data !== void 0 && data.syncMode)) {
6864
- _context69.next = 19;
7276
+ _context73.next = 19;
6865
7277
  break;
6866
7278
  }
6867
- return _context69.abrupt("return", this.handleSyncCheckoutSubmit({
7279
+ return _context73.abrupt("return", this.handleSyncCheckoutSubmit({
6868
7280
  backendPath: backendPath,
6869
7281
  data: data,
6870
7282
  title: title,
@@ -6873,16 +7285,16 @@ var Server = /*#__PURE__*/function () {
6873
7285
  receiptAutoPrintPaymentStatuses: receiptAutoPrintPaymentStatuses
6874
7286
  }));
6875
7287
  case 19:
6876
- _context69.next = 21;
7288
+ _context73.next = 21;
6877
7289
  return this.normalizeCheckoutSubmitData(data, title);
6878
7290
  case 21:
6879
- normalizedData = _context69.sent;
6880
- _context69.next = 24;
7291
+ normalizedData = _context73.sent;
7292
+ _context73.next = 24;
6881
7293
  return this.ensureCheckoutOrderNumbers(normalizedData, title);
6882
7294
  case 24:
6883
- numberedData = _context69.sent;
7295
+ numberedData = _context73.sent;
6884
7296
  checkoutData = this.normalizeCheckoutCollections(stripOsPrivatePayloadFields(this.applyCheckoutFulfillmentBuzzer(numberedData, title)));
6885
- _context69.next = 28;
7297
+ _context73.next = 28;
6886
7298
  return this.handlePendingSyncCheckoutOrder({
6887
7299
  backendPath: backendPath,
6888
7300
  data: checkoutData,
@@ -6891,18 +7303,18 @@ var Server = /*#__PURE__*/function () {
6891
7303
  invoiceTemplateSettings: invoiceTemplateSettings
6892
7304
  });
6893
7305
  case 28:
6894
- pendingResult = _context69.sent;
7306
+ pendingResult = _context73.sent;
6895
7307
  if (!((pendingResult === null || pendingResult === void 0 ? void 0 : pendingResult.status) === true)) {
6896
- _context69.next = 43;
7308
+ _context73.next = 43;
6897
7309
  break;
6898
7310
  }
6899
7311
  pendingOrder = pendingResult.data;
6900
7312
  if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData, invoiceTemplateSettings) && this.shouldAutoPrintReceiptForPaymentStatus(pendingOrder, receiptAutoPrintPaymentStatuses) && this.shouldAutoPrintCheckoutReceipt())) {
6901
- _context69.next = 41;
7313
+ _context73.next = 41;
6902
7314
  break;
6903
7315
  }
6904
- _context69.prev = 32;
6905
- _context69.next = 35;
7316
+ _context73.prev = 32;
7317
+ _context73.next = 35;
6906
7318
  return this.dispatchLocalReceiptPrint({
6907
7319
  checkoutData: checkoutData,
6908
7320
  order: pendingOrder,
@@ -6912,19 +7324,19 @@ var Server = /*#__PURE__*/function () {
6912
7324
  invoiceTemplateSettings: invoiceTemplateSettings
6913
7325
  });
6914
7326
  case 35:
6915
- _context69.next = 41;
7327
+ _context73.next = 41;
6916
7328
  break;
6917
7329
  case 37:
6918
- _context69.prev = 37;
6919
- _context69.t1 = _context69["catch"](32);
7330
+ _context73.prev = 37;
7331
+ _context73.t1 = _context73["catch"](32);
6920
7332
  // The sale is already persisted. A failed receipt must not cancel its
6921
7333
  // sync task or send an unfiltered fallback to the printer.
6922
- pendingResult.receipt_print_error = this.getUnknownErrorMessage(_context69.t1);
7334
+ pendingResult.receipt_print_error = this.getUnknownErrorMessage(_context73.t1);
6923
7335
  this.logError("".concat(title, ": \u5C0F\u7968\u751F\u6210\u5931\u8D25\uFF0C\u8BA2\u5355\u4ECD\u7EE7\u7EED\u540C\u6B65"), {
6924
7336
  error: pendingResult.receipt_print_error
6925
7337
  });
6926
7338
  case 41:
6927
- _context69.next = 43;
7339
+ _context73.next = 43;
6928
7340
  return this.dispatchCheckoutSyncTask({
6929
7341
  backendPath: backendPath,
6930
7342
  data: checkoutData,
@@ -6934,23 +7346,23 @@ var Server = /*#__PURE__*/function () {
6934
7346
  });
6935
7347
  case 43:
6936
7348
  if (pendingResult.data.order_id) {
6937
- _context69.next = 45;
7349
+ _context73.next = 45;
6938
7350
  break;
6939
7351
  }
6940
- return _context69.abrupt("return", _objectSpread(_objectSpread({}, pendingResult), {}, {
7352
+ return _context73.abrupt("return", _objectSpread(_objectSpread({}, pendingResult), {}, {
6941
7353
  data: _objectSpread(_objectSpread({}, pendingResult.data), {}, {
6942
7354
  order_id: pendingResult.data.external_sale_number
6943
7355
  })
6944
7356
  }));
6945
7357
  case 45:
6946
- return _context69.abrupt("return", pendingResult);
7358
+ return _context73.abrupt("return", pendingResult);
6947
7359
  case 46:
6948
7360
  case "end":
6949
- return _context69.stop();
7361
+ return _context73.stop();
6950
7362
  }
6951
- }, _callee69, this, [[32, 37]]);
7363
+ }, _callee73, this, [[32, 37]]);
6952
7364
  }));
6953
- function handleOrderCheckoutSubmit(_x75) {
7365
+ function handleOrderCheckoutSubmit(_x82) {
6954
7366
  return _handleOrderCheckoutSubmit.apply(this, arguments);
6955
7367
  }
6956
7368
  return handleOrderCheckoutSubmit;
@@ -6958,27 +7370,27 @@ var Server = /*#__PURE__*/function () {
6958
7370
  }, {
6959
7371
  key: "handleSyncCheckoutSubmit",
6960
7372
  value: function () {
6961
- var _handleSyncCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee70(params) {
7373
+ var _handleSyncCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee74(params) {
6962
7374
  var _this$app18;
6963
7375
  var backendPath, data, title, invoiceLayoutConfig, invoiceTemplateSettings, receiptAutoPrintPaymentStatuses, syncResult, _normalized$data, normalized, response, syncedOrder, backendError, _normalized$data2, _normalized, message;
6964
- return _regeneratorRuntime().wrap(function _callee70$(_context70) {
6965
- while (1) switch (_context70.prev = _context70.next) {
7376
+ return _regeneratorRuntime().wrap(function _callee74$(_context74) {
7377
+ while (1) switch (_context74.prev = _context74.next) {
6966
7378
  case 0:
6967
7379
  backendPath = params.backendPath, data = params.data, title = params.title, invoiceLayoutConfig = params.invoiceLayoutConfig, invoiceTemplateSettings = params.invoiceTemplateSettings, receiptAutoPrintPaymentStatuses = params.receiptAutoPrintPaymentStatuses;
6968
7380
  if ((_this$app18 = this.app) !== null && _this$app18 !== void 0 && (_this$app18 = _this$app18.request) !== null && _this$app18 !== void 0 && _this$app18.post) {
6969
- _context70.next = 4;
7381
+ _context74.next = 4;
6970
7382
  break;
6971
7383
  }
6972
7384
  this.logError("".concat(title, ": sync checkout app.request \u4E0D\u53EF\u7528"));
6973
- return _context70.abrupt("return", {
7385
+ return _context74.abrupt("return", {
6974
7386
  code: 500,
6975
7387
  status: false,
6976
7388
  message: 'app.request 不可用',
6977
7389
  data: null
6978
7390
  });
6979
7391
  case 4:
6980
- _context70.prev = 4;
6981
- _context70.next = 7;
7392
+ _context74.prev = 4;
7393
+ _context74.next = 7;
6982
7394
  return this.runCheckoutSync({
6983
7395
  backendPath: backendPath,
6984
7396
  data: data,
@@ -6988,13 +7400,13 @@ var Server = /*#__PURE__*/function () {
6988
7400
  invoiceTemplateSettings: invoiceTemplateSettings
6989
7401
  });
6990
7402
  case 7:
6991
- syncResult = _context70.sent;
7403
+ syncResult = _context74.sent;
6992
7404
  if (!syncResult.rejected) {
6993
- _context70.next = 11;
7405
+ _context74.next = 11;
6994
7406
  break;
6995
7407
  }
6996
7408
  normalized = this.normalizeCheckoutResponse(syncResult.errorResponse);
6997
- return _context70.abrupt("return", _objectSpread(_objectSpread({}, normalized), {}, {
7409
+ return _context74.abrupt("return", _objectSpread(_objectSpread({}, normalized), {}, {
6998
7410
  status: false,
6999
7411
  message: syncResult.message || (normalized === null || normalized === void 0 ? void 0 : normalized.message) || '后端明确拒绝 checkout',
7000
7412
  data: (_normalized$data = normalized === null || normalized === void 0 ? void 0 : normalized.data) !== null && _normalized$data !== void 0 ? _normalized$data : null
@@ -7003,11 +7415,11 @@ var Server = /*#__PURE__*/function () {
7003
7415
  response = this.withSyncedOrderIdInCheckoutResponse(syncResult.normalizedResponse, syncResult.syncedOrder);
7004
7416
  syncedOrder = syncResult.syncedOrder;
7005
7417
  if (!(syncedOrder && this.shouldBuildSmallTicketData(syncResult.checkoutData, invoiceTemplateSettings) && this.shouldAutoPrintReceiptForPaymentStatus(syncedOrder, receiptAutoPrintPaymentStatuses) && (receiptAutoPrintPaymentStatuses === undefined || this.shouldAutoPrintCheckoutReceipt()))) {
7006
- _context70.next = 23;
7418
+ _context74.next = 23;
7007
7419
  break;
7008
7420
  }
7009
- _context70.prev = 14;
7010
- _context70.next = 17;
7421
+ _context74.prev = 14;
7422
+ _context74.next = 17;
7011
7423
  return this.dispatchLocalReceiptPrint({
7012
7424
  checkoutData: syncResult.checkoutData,
7013
7425
  order: syncedOrder,
@@ -7017,41 +7429,41 @@ var Server = /*#__PURE__*/function () {
7017
7429
  invoiceTemplateSettings: invoiceTemplateSettings
7018
7430
  });
7019
7431
  case 17:
7020
- _context70.next = 23;
7432
+ _context74.next = 23;
7021
7433
  break;
7022
7434
  case 19:
7023
- _context70.prev = 19;
7024
- _context70.t0 = _context70["catch"](14);
7435
+ _context74.prev = 19;
7436
+ _context74.t0 = _context74["catch"](14);
7025
7437
  // Checkout already succeeded remotely; report the receipt failure
7026
7438
  // separately instead of implying that payment/order creation failed.
7027
- response.receipt_print_error = this.getUnknownErrorMessage(_context70.t0);
7439
+ response.receipt_print_error = this.getUnknownErrorMessage(_context74.t0);
7028
7440
  this.logError("".concat(title, ": \u5C0F\u7968\u751F\u6210\u5931\u8D25\uFF0C\u8BA2\u5355\u5DF2\u540C\u6B65"), {
7029
7441
  error: response.receipt_print_error
7030
7442
  });
7031
7443
  case 23:
7032
- return _context70.abrupt("return", response);
7444
+ return _context74.abrupt("return", response);
7033
7445
  case 26:
7034
- _context70.prev = 26;
7035
- _context70.t1 = _context70["catch"](4);
7036
- backendError = this.extractBackendErrorResponse(_context70.t1);
7446
+ _context74.prev = 26;
7447
+ _context74.t1 = _context74["catch"](4);
7448
+ backendError = this.extractBackendErrorResponse(_context74.t1);
7037
7449
  if (!backendError) {
7038
- _context70.next = 32;
7450
+ _context74.next = 32;
7039
7451
  break;
7040
7452
  }
7041
7453
  _normalized = this.normalizeCheckoutResponse(backendError);
7042
- return _context70.abrupt("return", _objectSpread(_objectSpread({}, _normalized), {}, {
7454
+ return _context74.abrupt("return", _objectSpread(_objectSpread({}, _normalized), {}, {
7043
7455
  status: false,
7044
7456
  message: (backendError === null || backendError === void 0 ? void 0 : backendError.message) || (_normalized === null || _normalized === void 0 ? void 0 : _normalized.message) || '后端明确拒绝 checkout',
7045
7457
  data: (_normalized$data2 = _normalized === null || _normalized === void 0 ? void 0 : _normalized.data) !== null && _normalized$data2 !== void 0 ? _normalized$data2 : null
7046
7458
  }));
7047
7459
  case 32:
7048
- message = this.getUnknownErrorMessage(_context70.t1);
7460
+ message = this.getUnknownErrorMessage(_context74.t1);
7049
7461
  this.logError("".concat(title, ": sync checkout \u8BF7\u6C42\u672A\u660E\u786E\u6210\u529F"), {
7050
7462
  backendPath: backendPath,
7051
7463
  error: message,
7052
- error_detail: this.normalizeUnknownError(_context70.t1)
7464
+ error_detail: this.normalizeUnknownError(_context74.t1)
7053
7465
  });
7054
- return _context70.abrupt("return", {
7466
+ return _context74.abrupt("return", {
7055
7467
  code: 500,
7056
7468
  status: false,
7057
7469
  message: message,
@@ -7059,11 +7471,11 @@ var Server = /*#__PURE__*/function () {
7059
7471
  });
7060
7472
  case 35:
7061
7473
  case "end":
7062
- return _context70.stop();
7474
+ return _context74.stop();
7063
7475
  }
7064
- }, _callee70, this, [[4, 26], [14, 19]]);
7476
+ }, _callee74, this, [[4, 26], [14, 19]]);
7065
7477
  }));
7066
- function handleSyncCheckoutSubmit(_x76) {
7478
+ function handleSyncCheckoutSubmit(_x83) {
7067
7479
  return _handleSyncCheckoutSubmit.apply(this, arguments);
7068
7480
  }
7069
7481
  return handleSyncCheckoutSubmit;
@@ -7071,10 +7483,10 @@ var Server = /*#__PURE__*/function () {
7071
7483
  }, {
7072
7484
  key: "handleOrderDraftSubmit",
7073
7485
  value: function () {
7074
- var _handleOrderDraftSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee71(params) {
7486
+ var _handleOrderDraftSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee75(params) {
7075
7487
  var title, extractedInvoice, _this$extractInvoiceT, data, normalizedData, createdAt, draftOrder, _draftOrder$summary, _draftOrder$summary2, _draftOrder$summary3, errorMessage;
7076
- return _regeneratorRuntime().wrap(function _callee71$(_context71) {
7077
- while (1) switch (_context71.prev = _context71.next) {
7488
+ return _regeneratorRuntime().wrap(function _callee75$(_context75) {
7489
+ while (1) switch (_context75.prev = _context75.next) {
7078
7490
  case 0:
7079
7491
  title = params.title;
7080
7492
  extractedInvoice = this.extractInvoiceLayoutConfig(params.data, {
@@ -7088,10 +7500,10 @@ var Server = /*#__PURE__*/function () {
7088
7500
  external_sale_number: data === null || data === void 0 ? void 0 : data.external_sale_number,
7089
7501
  order_number: data === null || data === void 0 ? void 0 : data.order_number
7090
7502
  });
7091
- _context71.next = 6;
7503
+ _context75.next = 6;
7092
7504
  return this.normalizeCheckoutSubmitData(data, title);
7093
7505
  case 6:
7094
- normalizedData = _context71.sent;
7506
+ normalizedData = _context75.sent;
7095
7507
  createdAt = normalizedData.created_at || normalizedData.create_date || dayjs().format('YYYY-MM-DD HH:mm:ss');
7096
7508
  draftOrder = _objectSpread(_objectSpread({}, normalizedData), {}, {
7097
7509
  external_sale_number: normalizedData.external_sale_number || "LOCAL_DRAFT_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2, 10)),
@@ -7101,26 +7513,26 @@ var Server = /*#__PURE__*/function () {
7101
7513
  is_draft_order: 1
7102
7514
  });
7103
7515
  if (!(!this.order || typeof this.order.upsertLocalDraftOrders !== 'function')) {
7104
- _context71.next = 12;
7516
+ _context75.next = 12;
7105
7517
  break;
7106
7518
  }
7107
7519
  this.logError("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u8349\u7A3F\u5199\u5165"));
7108
- return _context71.abrupt("return", {
7520
+ return _context75.abrupt("return", {
7109
7521
  code: 500,
7110
7522
  status: false,
7111
7523
  message: 'Order 模块不支持本地草稿写入',
7112
7524
  data: null
7113
7525
  });
7114
7526
  case 12:
7115
- _context71.prev = 12;
7116
- _context71.next = 15;
7527
+ _context75.prev = 12;
7528
+ _context75.next = 15;
7117
7529
  return this.order.upsertLocalDraftOrders([draftOrder]);
7118
7530
  case 15:
7119
7531
  this.logInfo("".concat(title, ": \u8349\u7A3F\u8BA2\u5355\u5DF2\u5199\u5165\u672C\u5730"), {
7120
7532
  order_id: draftOrder.order_id,
7121
7533
  external_sale_number: draftOrder.external_sale_number
7122
7534
  });
7123
- return _context71.abrupt("return", {
7535
+ return _context75.abrupt("return", {
7124
7536
  code: 200,
7125
7537
  status: true,
7126
7538
  message: '',
@@ -7132,13 +7544,13 @@ var Server = /*#__PURE__*/function () {
7132
7544
  })
7133
7545
  });
7134
7546
  case 19:
7135
- _context71.prev = 19;
7136
- _context71.t0 = _context71["catch"](12);
7137
- errorMessage = _context71.t0 instanceof Error ? _context71.t0.message : String(_context71.t0);
7547
+ _context75.prev = 19;
7548
+ _context75.t0 = _context75["catch"](12);
7549
+ errorMessage = _context75.t0 instanceof Error ? _context75.t0.message : String(_context75.t0);
7138
7550
  this.logError("".concat(title, ": \u5199\u5165\u672C\u5730\u8349\u7A3F\u8BA2\u5355\u5931\u8D25"), {
7139
7551
  error: errorMessage
7140
7552
  });
7141
- return _context71.abrupt("return", {
7553
+ return _context75.abrupt("return", {
7142
7554
  code: 500,
7143
7555
  status: false,
7144
7556
  message: errorMessage,
@@ -7146,11 +7558,11 @@ var Server = /*#__PURE__*/function () {
7146
7558
  });
7147
7559
  case 24:
7148
7560
  case "end":
7149
- return _context71.stop();
7561
+ return _context75.stop();
7150
7562
  }
7151
- }, _callee71, this, [[12, 19]]);
7563
+ }, _callee75, this, [[12, 19]]);
7152
7564
  }));
7153
- function handleOrderDraftSubmit(_x77) {
7565
+ function handleOrderDraftSubmit(_x84) {
7154
7566
  return _handleOrderDraftSubmit.apply(this, arguments);
7155
7567
  }
7156
7568
  return handleOrderDraftSubmit;
@@ -7158,26 +7570,26 @@ var Server = /*#__PURE__*/function () {
7158
7570
  }, {
7159
7571
  key: "handlePendingSyncCheckoutOrder",
7160
7572
  value: function () {
7161
- var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee72(params) {
7162
- var _this19 = this;
7573
+ var _handlePendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee76(params) {
7574
+ var _this20 = this;
7163
7575
  var backendPath, data, title, reason, invoiceTemplateSettings, pendingOrder, _pendingOrder$payment, _pendingOrder$summary, _pendingOrder$summary2, _pendingOrder$summary3, changeGivenAmount, errorMessage;
7164
- return _regeneratorRuntime().wrap(function _callee72$(_context72) {
7165
- while (1) switch (_context72.prev = _context72.next) {
7576
+ return _regeneratorRuntime().wrap(function _callee76$(_context76) {
7577
+ while (1) switch (_context76.prev = _context76.next) {
7166
7578
  case 0:
7167
7579
  backendPath = params.backendPath, data = params.data, title = params.title, reason = params.reason, invoiceTemplateSettings = params.invoiceTemplateSettings;
7168
- _context72.next = 3;
7580
+ _context76.next = 3;
7169
7581
  return this.buildPendingSyncCheckoutOrder(data, invoiceTemplateSettings);
7170
7582
  case 3:
7171
- pendingOrder = _context72.sent;
7583
+ pendingOrder = _context76.sent;
7172
7584
  if (pendingOrder) {
7173
- _context72.next = 7;
7585
+ _context76.next = 7;
7174
7586
  break;
7175
7587
  }
7176
7588
  this.logError("".concat(title, ": checkout \u5931\u8D25\u4E14\u8BA2\u5355\u7F3A\u5C11\u672C\u5730\u5B58\u50A8\u6807\u8BC6"), {
7177
7589
  backendPath: backendPath,
7178
7590
  reason: reason
7179
7591
  });
7180
- return _context72.abrupt("return", {
7592
+ return _context76.abrupt("return", {
7181
7593
  code: 500,
7182
7594
  status: false,
7183
7595
  message: '订单缺少本地存储标识,无法写入待同步队列',
@@ -7185,22 +7597,22 @@ var Server = /*#__PURE__*/function () {
7185
7597
  });
7186
7598
  case 7:
7187
7599
  if (!(!this.order || typeof this.order.upsertPendingSyncOrders !== 'function')) {
7188
- _context72.next = 10;
7600
+ _context76.next = 10;
7189
7601
  break;
7190
7602
  }
7191
7603
  this.logError("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u5F85\u540C\u6B65\u5199\u5165"), {
7192
7604
  backendPath: backendPath,
7193
7605
  reason: reason
7194
7606
  });
7195
- return _context72.abrupt("return", {
7607
+ return _context76.abrupt("return", {
7196
7608
  code: 500,
7197
7609
  status: false,
7198
7610
  message: 'Order 模块不支持本地待同步写入',
7199
7611
  data: null
7200
7612
  });
7201
7613
  case 10:
7202
- _context72.prev = 10;
7203
- _context72.next = 13;
7614
+ _context76.prev = 10;
7615
+ _context76.next = 13;
7204
7616
  return this.order.upsertPendingSyncOrders([pendingOrder]);
7205
7617
  case 13:
7206
7618
  this.logInfo("".concat(title, ": \u8BA2\u5355\u5DF2\u5199\u5165\u672C\u5730\u5F85\u540C\u6B65"), {
@@ -7212,9 +7624,9 @@ var Server = /*#__PURE__*/function () {
7212
7624
  });
7213
7625
  changeGivenAmount = pendingOrder === null || pendingOrder === void 0 || (_pendingOrder$payment = pendingOrder.payments) === null || _pendingOrder$payment === void 0 ? void 0 : _pendingOrder$payment.reduce(function (sum, payment) {
7214
7626
  var _payment$metadata;
7215
- return sum + _this19.toAmountNumber(payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.change_given_amount);
7627
+ return sum + _this20.toAmountNumber(payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.change_given_amount);
7216
7628
  }, 0);
7217
- return _context72.abrupt("return", {
7629
+ return _context76.abrupt("return", {
7218
7630
  code: 200,
7219
7631
  status: true,
7220
7632
  message: '',
@@ -7229,15 +7641,15 @@ var Server = /*#__PURE__*/function () {
7229
7641
  })
7230
7642
  });
7231
7643
  case 18:
7232
- _context72.prev = 18;
7233
- _context72.t0 = _context72["catch"](10);
7234
- errorMessage = _context72.t0 instanceof Error ? _context72.t0.message : String(_context72.t0);
7644
+ _context76.prev = 18;
7645
+ _context76.t0 = _context76["catch"](10);
7646
+ errorMessage = _context76.t0 instanceof Error ? _context76.t0.message : String(_context76.t0);
7235
7647
  this.logError("".concat(title, ": \u5199\u5165\u672C\u5730\u5F85\u540C\u6B65\u8BA2\u5355\u5931\u8D25"), {
7236
7648
  backendPath: backendPath,
7237
7649
  reason: reason,
7238
7650
  error: errorMessage
7239
7651
  });
7240
- return _context72.abrupt("return", {
7652
+ return _context76.abrupt("return", {
7241
7653
  code: 500,
7242
7654
  status: false,
7243
7655
  message: errorMessage,
@@ -7245,11 +7657,11 @@ var Server = /*#__PURE__*/function () {
7245
7657
  });
7246
7658
  case 23:
7247
7659
  case "end":
7248
- return _context72.stop();
7660
+ return _context76.stop();
7249
7661
  }
7250
- }, _callee72, this, [[10, 18]]);
7662
+ }, _callee76, this, [[10, 18]]);
7251
7663
  }));
7252
- function handlePendingSyncCheckoutOrder(_x78) {
7664
+ function handlePendingSyncCheckoutOrder(_x85) {
7253
7665
  return _handlePendingSyncCheckoutOrder.apply(this, arguments);
7254
7666
  }
7255
7667
  return handlePendingSyncCheckoutOrder;
@@ -7257,45 +7669,45 @@ var Server = /*#__PURE__*/function () {
7257
7669
  }, {
7258
7670
  key: "buildPendingSyncCheckoutOrder",
7259
7671
  value: function () {
7260
- var _buildPendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee73(data, invoiceTemplateSettings) {
7672
+ var _buildPendingSyncCheckoutOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee77(data, invoiceTemplateSettings) {
7261
7673
  var hasStorageKey, pendingOrder, productMap, orderWithProductTitles;
7262
- return _regeneratorRuntime().wrap(function _callee73$(_context73) {
7263
- while (1) switch (_context73.prev = _context73.next) {
7674
+ return _regeneratorRuntime().wrap(function _callee77$(_context77) {
7675
+ while (1) switch (_context77.prev = _context77.next) {
7264
7676
  case 0:
7265
7677
  if (!(!data || _typeof(data) !== 'object')) {
7266
- _context73.next = 2;
7678
+ _context77.next = 2;
7267
7679
  break;
7268
7680
  }
7269
- return _context73.abrupt("return", null);
7681
+ return _context77.abrupt("return", null);
7270
7682
  case 2:
7271
7683
  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 !== '';
7272
7684
  if (hasStorageKey) {
7273
- _context73.next = 5;
7685
+ _context77.next = 5;
7274
7686
  break;
7275
7687
  }
7276
- return _context73.abrupt("return", null);
7688
+ return _context77.abrupt("return", null);
7277
7689
  case 5:
7278
7690
  pendingOrder = this.normalizeCheckoutCollections(_objectSpread(_objectSpread({}, data), {}, {
7279
7691
  need_sync: 1,
7280
7692
  is_draft_order: 0
7281
7693
  }));
7282
- _context73.next = 8;
7694
+ _context77.next = 8;
7283
7695
  return this.buildSmallTicketProductMap(pendingOrder);
7284
7696
  case 8:
7285
- productMap = _context73.sent;
7697
+ productMap = _context77.sent;
7286
7698
  orderWithProductTitles = this.withPendingSyncProductTitles(pendingOrder, productMap);
7287
- return _context73.abrupt("return", this.withLocalSmallTicketData(orderWithProductTitles, {
7699
+ return _context77.abrupt("return", this.withLocalSmallTicketData(orderWithProductTitles, {
7288
7700
  requireFullyPaid: true,
7289
7701
  productMap: productMap,
7290
7702
  invoiceTemplateSettings: invoiceTemplateSettings
7291
7703
  }));
7292
7704
  case 11:
7293
7705
  case "end":
7294
- return _context73.stop();
7706
+ return _context77.stop();
7295
7707
  }
7296
- }, _callee73, this);
7708
+ }, _callee77, this);
7297
7709
  }));
7298
- function buildPendingSyncCheckoutOrder(_x79, _x80) {
7710
+ function buildPendingSyncCheckoutOrder(_x86, _x87) {
7299
7711
  return _buildPendingSyncCheckoutOrder.apply(this, arguments);
7300
7712
  }
7301
7713
  return buildPendingSyncCheckoutOrder;
@@ -7332,11 +7744,11 @@ var Server = /*#__PURE__*/function () {
7332
7744
  }, {
7333
7745
  key: "shouldAutoPrintReceiptForPaymentStatus",
7334
7746
  value: function shouldAutoPrintReceiptForPaymentStatus(order, statuses) {
7335
- var _this20 = this;
7747
+ var _this21 = this;
7336
7748
  if (statuses === undefined) return this.isSalesOrderFullyPaid(order);
7337
7749
  var paymentStatus = String((order === null || order === void 0 ? void 0 : order.payment_status) || '').toLowerCase();
7338
7750
  return statuses.some(function (status) {
7339
- return status === 'paid' ? _this20.isSalesOrderFullyPaid(order) : paymentStatus === status;
7751
+ return status === 'paid' ? _this21.isSalesOrderFullyPaid(order) : paymentStatus === status;
7340
7752
  });
7341
7753
  }
7342
7754
  }, {
@@ -7365,32 +7777,32 @@ var Server = /*#__PURE__*/function () {
7365
7777
  }, {
7366
7778
  key: "isSalesOrderFullyPaid",
7367
7779
  value: function isSalesOrderFullyPaid(order) {
7368
- var _order$summary$amount, _order$summary, _ref75, _ref76, _order$summary$expect, _order$summary2, _order$summary3;
7780
+ var _order$summary$amount, _order$summary3, _ref77, _ref78, _order$summary$expect, _order$summary4, _order$summary5;
7369
7781
  if (!order || _typeof(order) !== 'object') return false;
7370
7782
  var paymentStatus = String(order.payment_status || '').toLowerCase();
7371
7783
  if (paymentStatus === 'paid' || paymentStatus === 'finished') return true;
7372
7784
  if (paymentStatus === 'partially_paid' || paymentStatus === 'payment_processing' || paymentStatus === 'pending' || paymentStatus === 'unpaid') {
7373
7785
  return false;
7374
7786
  }
7375
- 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;
7787
+ var amountGap = (_order$summary$amount = (_order$summary3 = order.summary) === null || _order$summary3 === void 0 ? void 0 : _order$summary3.amount_gap) !== null && _order$summary$amount !== void 0 ? _order$summary$amount : order.amount_gap;
7376
7788
  if (amountGap !== undefined && amountGap !== null && amountGap !== '') {
7377
7789
  return this.toAmountNumber(amountGap) <= 0;
7378
7790
  }
7379
7791
  var paidAmount = this.sumPaidOrderPayments(order.payments);
7380
- var targetAmount = this.toAmountNumber((_ref75 = (_ref76 = (_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 && _ref76 !== void 0 ? _ref76 : order.expect_amount) !== null && _ref75 !== void 0 ? _ref75 : order.total_amount);
7792
+ var targetAmount = this.toAmountNumber((_ref77 = (_ref78 = (_order$summary$expect = (_order$summary4 = order.summary) === null || _order$summary4 === void 0 ? void 0 : _order$summary4.expect_amount) !== null && _order$summary$expect !== void 0 ? _order$summary$expect : (_order$summary5 = order.summary) === null || _order$summary5 === void 0 ? void 0 : _order$summary5.total_amount) !== null && _ref78 !== void 0 ? _ref78 : order.expect_amount) !== null && _ref77 !== void 0 ? _ref77 : order.total_amount);
7381
7793
  if (targetAmount <= 0) return paidAmount > 0;
7382
7794
  return paidAmount >= targetAmount;
7383
7795
  }
7384
7796
  }, {
7385
7797
  key: "sumPaidOrderPayments",
7386
7798
  value: function sumPaidOrderPayments(payments) {
7387
- var _this21 = this;
7799
+ var _this22 = this;
7388
7800
  if (!Array.isArray(payments)) return 0;
7389
7801
  return payments.reduce(function (sum, payment) {
7390
7802
  var _payment$amount;
7391
7803
  var status = String((payment === null || payment === void 0 ? void 0 : payment.status) || '').toLowerCase();
7392
7804
  if (status !== 'paid') return sum;
7393
- return sum + _this21.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);
7805
+ return sum + _this22.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);
7394
7806
  }, 0);
7395
7807
  }
7396
7808
  }, {
@@ -7404,12 +7816,12 @@ var Server = /*#__PURE__*/function () {
7404
7816
  }, {
7405
7817
  key: "buildSmallTicketProductMap",
7406
7818
  value: function () {
7407
- var _buildSmallTicketProductMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee75(order) {
7819
+ var _buildSmallTicketProductMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee79(order) {
7408
7820
  var _this$products4,
7409
- _this22 = this;
7821
+ _this23 = this;
7410
7822
  var products, productIdSet, productIds, entries;
7411
- return _regeneratorRuntime().wrap(function _callee75$(_context75) {
7412
- while (1) switch (_context75.prev = _context75.next) {
7823
+ return _regeneratorRuntime().wrap(function _callee79$(_context79) {
7824
+ while (1) switch (_context79.prev = _context79.next) {
7413
7825
  case 0:
7414
7826
  products = Array.isArray(order === null || order === void 0 ? void 0 : order.products) ? order.products : [];
7415
7827
  productIdSet = new Set();
@@ -7421,8 +7833,8 @@ var Server = /*#__PURE__*/function () {
7421
7833
  }
7422
7834
  if (Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle)) {
7423
7835
  product.product_bundle.forEach(function (bundle) {
7424
- var _ref77, _bundle$bundle_produc;
7425
- var bundleProductId = (_ref77 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref77 !== void 0 ? _ref77 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
7836
+ var _ref79, _bundle$bundle_produc;
7837
+ var bundleProductId = (_ref79 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref79 !== void 0 ? _ref79 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
7426
7838
  if (bundleProductId !== undefined && bundleProductId !== null && bundleProductId !== '') {
7427
7839
  productIdSet.add(bundleProductId);
7428
7840
  }
@@ -7431,45 +7843,45 @@ var Server = /*#__PURE__*/function () {
7431
7843
  });
7432
7844
  productIds = Array.from(productIdSet);
7433
7845
  if (!(!productIds.length || typeof ((_this$products4 = this.products) === null || _this$products4 === void 0 ? void 0 : _this$products4.getProductById) !== 'function')) {
7434
- _context75.next = 6;
7846
+ _context79.next = 6;
7435
7847
  break;
7436
7848
  }
7437
- return _context75.abrupt("return", {});
7849
+ return _context79.abrupt("return", {});
7438
7850
  case 6:
7439
- _context75.next = 8;
7851
+ _context79.next = 8;
7440
7852
  return Promise.all(productIds.map( /*#__PURE__*/function () {
7441
- var _ref78 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee74(id) {
7442
- var _this22$products, _this22$products$getP, product;
7443
- return _regeneratorRuntime().wrap(function _callee74$(_context74) {
7444
- while (1) switch (_context74.prev = _context74.next) {
7853
+ var _ref80 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee78(id) {
7854
+ var _this23$products, _this23$products$getP, product;
7855
+ return _regeneratorRuntime().wrap(function _callee78$(_context78) {
7856
+ while (1) switch (_context78.prev = _context78.next) {
7445
7857
  case 0:
7446
- _context74.prev = 0;
7447
- _context74.next = 3;
7448
- return (_this22$products = _this22.products) === null || _this22$products === void 0 || (_this22$products$getP = _this22$products.getProductById) === null || _this22$products$getP === void 0 ? void 0 : _this22$products$getP.call(_this22$products, Number(id));
7858
+ _context78.prev = 0;
7859
+ _context78.next = 3;
7860
+ return (_this23$products = _this23.products) === null || _this23$products === void 0 || (_this23$products$getP = _this23$products.getProductById) === null || _this23$products$getP === void 0 ? void 0 : _this23$products$getP.call(_this23$products, Number(id));
7449
7861
  case 3:
7450
- product = _context74.sent;
7451
- return _context74.abrupt("return", product ? [String(id), product] : null);
7862
+ product = _context78.sent;
7863
+ return _context78.abrupt("return", product ? [String(id), product] : null);
7452
7864
  case 7:
7453
- _context74.prev = 7;
7454
- _context74.t0 = _context74["catch"](0);
7455
- _this22.logWarning('buildSmallTicketProductMap: 查询本地商品失败', {
7865
+ _context78.prev = 7;
7866
+ _context78.t0 = _context78["catch"](0);
7867
+ _this23.logWarning('buildSmallTicketProductMap: 查询本地商品失败', {
7456
7868
  product_id: id,
7457
- error: _context74.t0 instanceof Error ? _context74.t0.message : String(_context74.t0)
7869
+ error: _context78.t0 instanceof Error ? _context78.t0.message : String(_context78.t0)
7458
7870
  });
7459
- return _context74.abrupt("return", null);
7871
+ return _context78.abrupt("return", null);
7460
7872
  case 11:
7461
7873
  case "end":
7462
- return _context74.stop();
7874
+ return _context78.stop();
7463
7875
  }
7464
- }, _callee74, null, [[0, 7]]);
7876
+ }, _callee78, null, [[0, 7]]);
7465
7877
  }));
7466
- return function (_x82) {
7467
- return _ref78.apply(this, arguments);
7878
+ return function (_x89) {
7879
+ return _ref80.apply(this, arguments);
7468
7880
  };
7469
7881
  }()));
7470
7882
  case 8:
7471
- entries = _context75.sent;
7472
- return _context75.abrupt("return", entries.reduce(function (map, entry) {
7883
+ entries = _context79.sent;
7884
+ return _context79.abrupt("return", entries.reduce(function (map, entry) {
7473
7885
  if (!entry) return map;
7474
7886
  var _entry = _slicedToArray(entry, 2),
7475
7887
  id = _entry[0],
@@ -7479,11 +7891,11 @@ var Server = /*#__PURE__*/function () {
7479
7891
  }, {}));
7480
7892
  case 10:
7481
7893
  case "end":
7482
- return _context75.stop();
7894
+ return _context79.stop();
7483
7895
  }
7484
- }, _callee75, this);
7896
+ }, _callee79, this);
7485
7897
  }));
7486
- function buildSmallTicketProductMap(_x81) {
7898
+ function buildSmallTicketProductMap(_x88) {
7487
7899
  return _buildSmallTicketProductMap.apply(this, arguments);
7488
7900
  }
7489
7901
  return buildSmallTicketProductMap;
@@ -7503,8 +7915,8 @@ var Server = /*#__PURE__*/function () {
7503
7915
  addProductId((_product$product_id2 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : product === null || product === void 0 ? void 0 : product.id);
7504
7916
  if (Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle)) {
7505
7917
  product.product_bundle.forEach(function (bundle) {
7506
- var _ref79, _bundle$bundle_produc2;
7507
- addProductId((_ref79 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref79 !== void 0 ? _ref79 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id);
7918
+ var _ref81, _bundle$bundle_produc2;
7919
+ addProductId((_ref81 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref81 !== void 0 ? _ref81 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id);
7508
7920
  });
7509
7921
  }
7510
7922
  });
@@ -7513,40 +7925,40 @@ var Server = /*#__PURE__*/function () {
7513
7925
  }, {
7514
7926
  key: "buildSalesDetailProductSnapshotMap",
7515
7927
  value: function () {
7516
- var _buildSalesDetailProductSnapshotMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee76(order) {
7928
+ var _buildSalesDetailProductSnapshotMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee80(order) {
7517
7929
  var _this$products5;
7518
7930
  var productIds, getSnapshots;
7519
- return _regeneratorRuntime().wrap(function _callee76$(_context76) {
7520
- while (1) switch (_context76.prev = _context76.next) {
7931
+ return _regeneratorRuntime().wrap(function _callee80$(_context80) {
7932
+ while (1) switch (_context80.prev = _context80.next) {
7521
7933
  case 0:
7522
7934
  productIds = this.collectSalesDetailProductIds(order);
7523
7935
  getSnapshots = (_this$products5 = this.products) === null || _this$products5 === void 0 ? void 0 : _this$products5.getProductSnapshotsByIds;
7524
7936
  if (!(!productIds.length || typeof getSnapshots !== 'function')) {
7525
- _context76.next = 4;
7937
+ _context80.next = 4;
7526
7938
  break;
7527
7939
  }
7528
- return _context76.abrupt("return", {});
7940
+ return _context80.abrupt("return", {});
7529
7941
  case 4:
7530
- _context76.prev = 4;
7531
- _context76.next = 7;
7942
+ _context80.prev = 4;
7943
+ _context80.next = 7;
7532
7944
  return getSnapshots.call(this.products, productIds);
7533
7945
  case 7:
7534
- return _context76.abrupt("return", _context76.sent);
7946
+ return _context80.abrupt("return", _context80.sent);
7535
7947
  case 10:
7536
- _context76.prev = 10;
7537
- _context76.t0 = _context76["catch"](4);
7948
+ _context80.prev = 10;
7949
+ _context80.t0 = _context80["catch"](4);
7538
7950
  this.logWarning('buildSalesDetailProductSnapshotMap: 查询本地商品快照失败', {
7539
7951
  product_ids: productIds,
7540
- error: _context76.t0 instanceof Error ? _context76.t0.message : String(_context76.t0)
7952
+ error: _context80.t0 instanceof Error ? _context80.t0.message : String(_context80.t0)
7541
7953
  });
7542
- return _context76.abrupt("return", {});
7954
+ return _context80.abrupt("return", {});
7543
7955
  case 14:
7544
7956
  case "end":
7545
- return _context76.stop();
7957
+ return _context80.stop();
7546
7958
  }
7547
- }, _callee76, this, [[4, 10]]);
7959
+ }, _callee80, this, [[4, 10]]);
7548
7960
  }));
7549
- function buildSalesDetailProductSnapshotMap(_x83) {
7961
+ function buildSalesDetailProductSnapshotMap(_x90) {
7550
7962
  return _buildSalesDetailProductSnapshotMap.apply(this, arguments);
7551
7963
  }
7552
7964
  return buildSalesDetailProductSnapshotMap;
@@ -7580,9 +7992,9 @@ var Server = /*#__PURE__*/function () {
7580
7992
  if (!Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle)) return product;
7581
7993
  var hasChanged = false;
7582
7994
  var productBundle = product.product_bundle.map(function (bundle) {
7583
- var _ref80, _bundle$bundle_produc3;
7995
+ var _ref82, _bundle$bundle_produc3;
7584
7996
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
7585
- var rawProductId = (_ref80 = (_bundle$bundle_produc3 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref80 !== void 0 ? _ref80 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
7997
+ var rawProductId = (_ref82 = (_bundle$bundle_produc3 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref82 !== void 0 ? _ref82 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
7586
7998
  if (rawProductId === undefined || rawProductId === null || rawProductId === '') return bundle;
7587
7999
  var productId = Number(rawProductId);
7588
8000
  if (!Number.isFinite(productId)) return bundle;
@@ -7602,53 +8014,53 @@ var Server = /*#__PURE__*/function () {
7602
8014
  }, {
7603
8015
  key: "withSalesDetailProductSnapshots",
7604
8016
  value: function () {
7605
- var _withSalesDetailProductSnapshots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee77(order) {
7606
- var _this23 = this;
8017
+ var _withSalesDetailProductSnapshots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee81(order) {
8018
+ var _this24 = this;
7607
8019
  var products, snapshotMap, hasChanged, enrichedProducts, enrichedOrder;
7608
- return _regeneratorRuntime().wrap(function _callee77$(_context77) {
7609
- while (1) switch (_context77.prev = _context77.next) {
8020
+ return _regeneratorRuntime().wrap(function _callee81$(_context81) {
8021
+ while (1) switch (_context81.prev = _context81.next) {
7610
8022
  case 0:
7611
8023
  products = Array.isArray(order === null || order === void 0 ? void 0 : order.products) ? order.products : null;
7612
8024
  if (products !== null && products !== void 0 && products.length) {
7613
- _context77.next = 3;
8025
+ _context81.next = 3;
7614
8026
  break;
7615
8027
  }
7616
- return _context77.abrupt("return", order);
8028
+ return _context81.abrupt("return", order);
7617
8029
  case 3:
7618
- _context77.next = 5;
8030
+ _context81.next = 5;
7619
8031
  return this.buildSalesDetailProductSnapshotMap(order);
7620
8032
  case 5:
7621
- snapshotMap = _context77.sent;
8033
+ snapshotMap = _context81.sent;
7622
8034
  if (Object.keys(snapshotMap).length) {
7623
- _context77.next = 8;
8035
+ _context81.next = 8;
7624
8036
  break;
7625
8037
  }
7626
- return _context77.abrupt("return", order);
8038
+ return _context81.abrupt("return", order);
7627
8039
  case 8:
7628
8040
  hasChanged = false;
7629
8041
  enrichedProducts = products.map(function (product) {
7630
- var productWithBundleSnapshots = _this23.withBundleCatalogSnapshots(product, snapshotMap);
7631
- var nextProduct = _this23.withProductCatalogSnapshots(productWithBundleSnapshots, snapshotMap);
8042
+ var productWithBundleSnapshots = _this24.withBundleCatalogSnapshots(product, snapshotMap);
8043
+ var nextProduct = _this24.withProductCatalogSnapshots(productWithBundleSnapshots, snapshotMap);
7632
8044
  if (nextProduct !== product) hasChanged = true;
7633
8045
  return nextProduct;
7634
8046
  });
7635
8047
  if (hasChanged) {
7636
- _context77.next = 12;
8048
+ _context81.next = 12;
7637
8049
  break;
7638
8050
  }
7639
- return _context77.abrupt("return", order);
8051
+ return _context81.abrupt("return", order);
7640
8052
  case 12:
7641
8053
  enrichedOrder = _objectSpread(_objectSpread({}, order), {}, {
7642
8054
  products: enrichedProducts
7643
8055
  });
7644
- return _context77.abrupt("return", enrichedOrder);
8056
+ return _context81.abrupt("return", enrichedOrder);
7645
8057
  case 14:
7646
8058
  case "end":
7647
- return _context77.stop();
8059
+ return _context81.stop();
7648
8060
  }
7649
- }, _callee77, this);
8061
+ }, _callee81, this);
7650
8062
  }));
7651
- function withSalesDetailProductSnapshots(_x84) {
8063
+ function withSalesDetailProductSnapshots(_x91) {
7652
8064
  return _withSalesDetailProductSnapshots.apply(this, arguments);
7653
8065
  }
7654
8066
  return withSalesDetailProductSnapshots;
@@ -7656,13 +8068,13 @@ var Server = /*#__PURE__*/function () {
7656
8068
  }, {
7657
8069
  key: "withPendingSyncProductTitles",
7658
8070
  value: function withPendingSyncProductTitles(order, productMap) {
7659
- var _this24 = this;
8071
+ var _this25 = this;
7660
8072
  var products = Array.isArray(order.products) ? order.products : null;
7661
8073
  if (!(products !== null && products !== void 0 && products.length)) return order;
7662
8074
  return _objectSpread(_objectSpread({}, order), {}, {
7663
8075
  products: products.map(function (product) {
7664
8076
  return _objectSpread(_objectSpread({}, product), {}, {
7665
- product_title: _this24.buildProductTitleSnapshot(product, productMap)
8077
+ product_title: _this25.buildProductTitleSnapshot(product, productMap)
7666
8078
  });
7667
8079
  })
7668
8080
  });
@@ -7673,7 +8085,7 @@ var Server = /*#__PURE__*/function () {
7673
8085
  var _product$product_id4,
7674
8086
  _product$product,
7675
8087
  _fallbackProduct$prod,
7676
- _this25 = this;
8088
+ _this26 = this;
7677
8089
  var productId = (_product$product_id4 = product.product_id) !== null && _product$product_id4 !== void 0 ? _product$product_id4 : product.id;
7678
8090
  var fallbackProduct = productId !== undefined && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
7679
8091
  var ownTitle = product.product_title || product.title || product.name || ((_product$product = product.product) === null || _product$product === void 0 ? void 0 : _product$product.title);
@@ -7681,7 +8093,7 @@ var Server = /*#__PURE__*/function () {
7681
8093
  var currentLocale = this.getProductTitleSnapshotCurrentLocale();
7682
8094
  var autoTitle = this.resolveFirstProductTitleValue(ownTitle) || this.resolveFirstProductTitleValue(fallbackTitle);
7683
8095
  return PRODUCT_TITLE_SNAPSHOT_KEYS.reduce(function (snapshot, key) {
7684
- snapshot[key] = _this25.resolveProductTitleValue(ownTitle, key, currentLocale) || _this25.resolveProductTitleValue(fallbackTitle, key, currentLocale) || (key === 'auto' || key === 'original' ? autoTitle : null);
8096
+ snapshot[key] = _this26.resolveProductTitleValue(ownTitle, key, currentLocale) || _this26.resolveProductTitleValue(fallbackTitle, key, currentLocale) || (key === 'auto' || key === 'original' ? autoTitle : null);
7685
8097
  return snapshot;
7686
8098
  }, {});
7687
8099
  }
@@ -7706,7 +8118,7 @@ var Server = /*#__PURE__*/function () {
7706
8118
  }, {
7707
8119
  key: "resolveProductTitleValue",
7708
8120
  value: function resolveProductTitleValue(value, key, currentLocale) {
7709
- var _ref81, _ref82, _value$key;
8121
+ var _ref83, _ref84, _value$key;
7710
8122
  if (value === undefined || value === null || value === '') return null;
7711
8123
  if (_typeof(value) !== 'object') {
7712
8124
  var title = String(value);
@@ -7716,7 +8128,7 @@ var Server = /*#__PURE__*/function () {
7716
8128
  }
7717
8129
  var normalizedKey = key.replace('-', '_');
7718
8130
  var dashedKey = key.replace('_', '-');
7719
- var rawValue = (_ref81 = (_ref82 = (_value$key = value[key]) !== null && _value$key !== void 0 ? _value$key : value[normalizedKey]) !== null && _ref82 !== void 0 ? _ref82 : value[dashedKey]) !== null && _ref81 !== void 0 ? _ref81 : key === 'auto' ? value.default : undefined;
8131
+ var rawValue = (_ref83 = (_ref84 = (_value$key = value[key]) !== null && _value$key !== void 0 ? _value$key : value[normalizedKey]) !== null && _ref84 !== void 0 ? _ref84 : value[dashedKey]) !== null && _ref83 !== void 0 ? _ref83 : key === 'auto' ? value.default : undefined;
7720
8132
  if (rawValue === undefined || rawValue === null || rawValue === '') return null;
7721
8133
  if (_typeof(rawValue) === 'object') return this.resolveFirstProductTitleValue(rawValue);
7722
8134
  return String(rawValue);
@@ -7779,31 +8191,31 @@ var Server = /*#__PURE__*/function () {
7779
8191
  }, {
7780
8192
  key: "enrichPaymentNamesByCode",
7781
8193
  value: function () {
7782
- var _enrichPaymentNamesByCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee78(order) {
7783
- var _this26 = this;
8194
+ var _enrichPaymentNamesByCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee82(order) {
8195
+ var _this27 = this;
7784
8196
  var payments, hasMissingName, paymentModule, payMethods, nameByCode, _iterator12, _step12, method, codeKey, name, hasResolvedName, enrichedPayments;
7785
- return _regeneratorRuntime().wrap(function _callee78$(_context78) {
7786
- while (1) switch (_context78.prev = _context78.next) {
8197
+ return _regeneratorRuntime().wrap(function _callee82$(_context82) {
8198
+ while (1) switch (_context82.prev = _context82.next) {
7787
8199
  case 0:
7788
8200
  payments = Array.isArray(order === null || order === void 0 ? void 0 : order.payments) ? order.payments : [];
7789
8201
  hasMissingName = payments.some(function (payment) {
7790
- return _this26.isBlankPaymentName(payment === null || payment === void 0 ? void 0 : payment.name) && _this26.shouldLookupPaymentMethodNameByCode(payment === null || payment === void 0 ? void 0 : payment.code);
8202
+ return _this27.isBlankPaymentName(payment === null || payment === void 0 ? void 0 : payment.name) && _this27.shouldLookupPaymentMethodNameByCode(payment === null || payment === void 0 ? void 0 : payment.code);
7791
8203
  });
7792
8204
  if (hasMissingName) {
7793
- _context78.next = 4;
8205
+ _context82.next = 4;
7794
8206
  break;
7795
8207
  }
7796
- return _context78.abrupt("return", order);
8208
+ return _context82.abrupt("return", order);
7797
8209
  case 4:
7798
- _context78.prev = 4;
7799
- _context78.next = 7;
8210
+ _context82.prev = 4;
8211
+ _context82.next = 7;
7800
8212
  return this.getPaymentRouteModule();
7801
8213
  case 7:
7802
- paymentModule = _context78.sent;
7803
- _context78.next = 10;
8214
+ paymentModule = _context82.sent;
8215
+ _context82.next = 10;
7804
8216
  return paymentModule.getPayMethodListAsync();
7805
8217
  case 10:
7806
- payMethods = _context78.sent;
8218
+ payMethods = _context82.sent;
7807
8219
  nameByCode = new Map();
7808
8220
  _iterator12 = _createForOfIteratorHelper(payMethods || []);
7809
8221
  try {
@@ -7820,9 +8232,9 @@ var Server = /*#__PURE__*/function () {
7820
8232
  }
7821
8233
  hasResolvedName = false;
7822
8234
  enrichedPayments = payments.map(function (payment) {
7823
- if (!_this26.isBlankPaymentName(payment === null || payment === void 0 ? void 0 : payment.name)) return payment;
7824
- if (!_this26.shouldLookupPaymentMethodNameByCode(payment === null || payment === void 0 ? void 0 : payment.code)) return payment;
7825
- var name = nameByCode.get(_this26.getPaymentCodeKey(payment === null || payment === void 0 ? void 0 : payment.code));
8235
+ if (!_this27.isBlankPaymentName(payment === null || payment === void 0 ? void 0 : payment.name)) return payment;
8236
+ if (!_this27.shouldLookupPaymentMethodNameByCode(payment === null || payment === void 0 ? void 0 : payment.code)) return payment;
8237
+ var name = nameByCode.get(_this27.getPaymentCodeKey(payment === null || payment === void 0 ? void 0 : payment.code));
7826
8238
  if (!name) return payment;
7827
8239
  hasResolvedName = true;
7828
8240
  return _objectSpread(_objectSpread({}, payment), {}, {
@@ -7830,28 +8242,28 @@ var Server = /*#__PURE__*/function () {
7830
8242
  });
7831
8243
  });
7832
8244
  if (hasResolvedName) {
7833
- _context78.next = 18;
8245
+ _context82.next = 18;
7834
8246
  break;
7835
8247
  }
7836
- return _context78.abrupt("return", order);
8248
+ return _context82.abrupt("return", order);
7837
8249
  case 18:
7838
- return _context78.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
8250
+ return _context82.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
7839
8251
  payments: enrichedPayments
7840
8252
  }));
7841
8253
  case 21:
7842
- _context78.prev = 21;
7843
- _context78.t0 = _context78["catch"](4);
8254
+ _context82.prev = 21;
8255
+ _context82.t0 = _context82["catch"](4);
7844
8256
  this.logWarning('enrichPaymentNamesByCode: 支付方式名称回填失败', {
7845
- error: _context78.t0 instanceof Error ? _context78.t0.message : String(_context78.t0)
8257
+ error: _context82.t0 instanceof Error ? _context82.t0.message : String(_context82.t0)
7846
8258
  });
7847
- return _context78.abrupt("return", order);
8259
+ return _context82.abrupt("return", order);
7848
8260
  case 25:
7849
8261
  case "end":
7850
- return _context78.stop();
8262
+ return _context82.stop();
7851
8263
  }
7852
- }, _callee78, this, [[4, 21]]);
8264
+ }, _callee82, this, [[4, 21]]);
7853
8265
  }));
7854
- function enrichPaymentNamesByCode(_x85) {
8266
+ function enrichPaymentNamesByCode(_x92) {
7855
8267
  return _enrichPaymentNamesByCode.apply(this, arguments);
7856
8268
  }
7857
8269
  return enrichPaymentNamesByCode;
@@ -7859,25 +8271,25 @@ var Server = /*#__PURE__*/function () {
7859
8271
  }, {
7860
8272
  key: "withLocalSmallTicketData",
7861
8273
  value: function () {
7862
- var _withLocalSmallTicketData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee79(order, options) {
7863
- var mustApplyVisibility, _options$productMap, normalizedCollections, normalizedOrder, collapsedDuplicateCounts, _ref83, _ref84, _order_id, receiptOrder, enrichedOrder, productMap, smallTicketData;
7864
- return _regeneratorRuntime().wrap(function _callee79$(_context79) {
7865
- while (1) switch (_context79.prev = _context79.next) {
8274
+ var _withLocalSmallTicketData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee83(order, options) {
8275
+ var mustApplyVisibility, _options$productMap, normalizedCollections, normalizedOrder, collapsedDuplicateCounts, _ref85, _ref86, _order_id, receiptOrder, enrichedOrder, productMap, smallTicketData;
8276
+ return _regeneratorRuntime().wrap(function _callee83$(_context83) {
8277
+ while (1) switch (_context83.prev = _context83.next) {
7866
8278
  case 0:
7867
8279
  mustApplyVisibility = (options === null || options === void 0 ? void 0 : options.applyTemplateVisibility) === true && requiresInvoiceDataFiltering(options.invoiceTemplateSettings);
7868
8280
  if (!(!this.shouldBuildSmallTicketData(order) && !mustApplyVisibility)) {
7869
- _context79.next = 3;
8281
+ _context83.next = 3;
7870
8282
  break;
7871
8283
  }
7872
- return _context79.abrupt("return", order);
8284
+ return _context83.abrupt("return", order);
7873
8285
  case 3:
7874
8286
  if (!(options !== null && options !== void 0 && options.requireFullyPaid && !this.isSalesOrderFullyPaid(order))) {
7875
- _context79.next = 5;
8287
+ _context83.next = 5;
7876
8288
  break;
7877
8289
  }
7878
- return _context79.abrupt("return", order);
8290
+ return _context83.abrupt("return", order);
7879
8291
  case 5:
7880
- _context79.prev = 5;
8292
+ _context83.prev = 5;
7881
8293
  normalizedCollections = normalizeOrderCollections(order, {
7882
8294
  ensureUid: false
7883
8295
  });
@@ -7891,42 +8303,42 @@ var Server = /*#__PURE__*/function () {
7891
8303
  return count > 0;
7892
8304
  })) {
7893
8305
  this.logWarning('withLocalSmallTicketData: 折叠重复订单子项', {
7894
- order_identifier: (_ref83 = (_ref84 = (_order_id = normalizedOrder.order_id) !== null && _order_id !== void 0 ? _order_id : normalizedOrder.external_sale_number) !== null && _ref84 !== void 0 ? _ref84 : normalizedOrder.shop_order_number) !== null && _ref83 !== void 0 ? _ref83 : null,
8306
+ order_identifier: (_ref85 = (_ref86 = (_order_id = normalizedOrder.order_id) !== null && _order_id !== void 0 ? _order_id : normalizedOrder.external_sale_number) !== null && _ref86 !== void 0 ? _ref86 : normalizedOrder.shop_order_number) !== null && _ref85 !== void 0 ? _ref85 : null,
7895
8307
  collapsed_duplicate_counts: collapsedDuplicateCounts
7896
8308
  });
7897
8309
  }
7898
8310
  if (!(options !== null && options !== void 0 && options.refreshResourceReference)) {
7899
- _context79.next = 16;
8311
+ _context83.next = 16;
7900
8312
  break;
7901
8313
  }
7902
- _context79.next = 13;
8314
+ _context83.next = 13;
7903
8315
  return this.withCurrentReceiptResourceReference(normalizedOrder);
7904
8316
  case 13:
7905
- _context79.t0 = _context79.sent;
7906
- _context79.next = 17;
8317
+ _context83.t0 = _context83.sent;
8318
+ _context83.next = 17;
7907
8319
  break;
7908
8320
  case 16:
7909
- _context79.t0 = normalizedOrder;
8321
+ _context83.t0 = normalizedOrder;
7910
8322
  case 17:
7911
- receiptOrder = _context79.t0;
7912
- _context79.next = 20;
8323
+ receiptOrder = _context83.t0;
8324
+ _context83.next = 20;
7913
8325
  return this.enrichPaymentNamesByCode(receiptOrder);
7914
8326
  case 20:
7915
- enrichedOrder = _context79.sent;
8327
+ enrichedOrder = _context83.sent;
7916
8328
  if (!((_options$productMap = options === null || options === void 0 ? void 0 : options.productMap) !== null && _options$productMap !== void 0)) {
7917
- _context79.next = 25;
8329
+ _context83.next = 25;
7918
8330
  break;
7919
8331
  }
7920
- _context79.t1 = _options$productMap;
7921
- _context79.next = 28;
8332
+ _context83.t1 = _options$productMap;
8333
+ _context83.next = 28;
7922
8334
  break;
7923
8335
  case 25:
7924
- _context79.next = 27;
8336
+ _context83.next = 27;
7925
8337
  return this.buildSmallTicketProductMap(enrichedOrder);
7926
8338
  case 27:
7927
- _context79.t1 = _context79.sent;
8339
+ _context83.t1 = _context83.sent;
7928
8340
  case 28:
7929
- productMap = _context79.t1;
8341
+ productMap = _context83.t1;
7930
8342
  smallTicketData = buildSmallTicketData({
7931
8343
  order: enrichedOrder,
7932
8344
  shopInfo: this.getSmallTicketShopInfo(),
@@ -7935,31 +8347,31 @@ var Server = /*#__PURE__*/function () {
7935
8347
  includeReceiptKeys: options === null || options === void 0 ? void 0 : options.includeReceiptKeys,
7936
8348
  templateSettings: options !== null && options !== void 0 && options.applyTemplateVisibility ? options.invoiceTemplateSettings : undefined
7937
8349
  });
7938
- return _context79.abrupt("return", _objectSpread(_objectSpread({}, enrichedOrder), {}, {
8350
+ return _context83.abrupt("return", _objectSpread(_objectSpread({}, enrichedOrder), {}, {
7939
8351
  payment_info: _objectSpread(_objectSpread({}, enrichedOrder.payment_info || {}), {}, {
7940
8352
  small_ticket_data: smallTicketData
7941
8353
  })
7942
8354
  }));
7943
8355
  case 33:
7944
- _context79.prev = 33;
7945
- _context79.t2 = _context79["catch"](5);
8356
+ _context83.prev = 33;
8357
+ _context83.t2 = _context83["catch"](5);
7946
8358
  this.logError('withLocalSmallTicketData: 生成本地小票数据失败', {
7947
- error: _context79.t2 instanceof Error ? _context79.t2.message : String(_context79.t2)
8359
+ error: _context83.t2 instanceof Error ? _context83.t2.message : String(_context83.t2)
7948
8360
  });
7949
8361
  if (!mustApplyVisibility) {
7950
- _context79.next = 38;
8362
+ _context83.next = 38;
7951
8363
  break;
7952
8364
  }
7953
- throw _context79.t2;
8365
+ throw _context83.t2;
7954
8366
  case 38:
7955
- return _context79.abrupt("return", order);
8367
+ return _context83.abrupt("return", order);
7956
8368
  case 39:
7957
8369
  case "end":
7958
- return _context79.stop();
8370
+ return _context83.stop();
7959
8371
  }
7960
- }, _callee79, this, [[5, 33]]);
8372
+ }, _callee83, this, [[5, 33]]);
7961
8373
  }));
7962
- function withLocalSmallTicketData(_x86, _x87) {
8374
+ function withLocalSmallTicketData(_x93, _x94) {
7963
8375
  return _withLocalSmallTicketData.apply(this, arguments);
7964
8376
  }
7965
8377
  return withLocalSmallTicketData;
@@ -7974,37 +8386,37 @@ var Server = /*#__PURE__*/function () {
7974
8386
  }, {
7975
8387
  key: "fetchAndPersistSalesOrderByLookup",
7976
8388
  value: function () {
7977
- var _fetchAndPersistSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee80(lookup, data, title, paymentIdentityOrder) {
8389
+ var _fetchAndPersistSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee84(lookup, data, title, paymentIdentityOrder, prepareExactOrderForPersist) {
7978
8390
  var _this$order7, _this$order8, _this$app20;
7979
- var backendPath, _this$order$getLocalO, _this$order9, response, _response$code3, responseStatusCode, code, message, fresh, localBeforeRefresh, orderToPersist, remotePayments, paidPayments, paymentIdsComplete, savedOrder, _errorRecord$response, backendError, errorRecord, _responseStatusCode, _ref85, _backendError$code2, backendStatusCode, _code, _message2, _message3;
7980
- return _regeneratorRuntime().wrap(function _callee80$(_context80) {
7981
- while (1) switch (_context80.prev = _context80.next) {
8391
+ var backendPath, _this$order$getOrderB, _this$order9, _this$order$getLocalO, _this$order10, response, _response$code3, responseStatusCode, code, message, _fresh2, localBeforeRefresh, orderToPersist, remotePayments, paidPayments, paymentIdsComplete, savedOrder, _errorRecord$response, backendError, errorRecord, _responseStatusCode, _ref87, _backendError$code2, backendStatusCode, _code, _message2, _message3;
8392
+ return _regeneratorRuntime().wrap(function _callee84$(_context84) {
8393
+ while (1) switch (_context84.prev = _context84.next) {
7982
8394
  case 0:
7983
8395
  if (!(!((_this$order7 = this.order) !== null && _this$order7 !== void 0 && _this$order7.getLocalOrderByLookup) || !((_this$order8 = this.order) !== null && _this$order8 !== void 0 && _this$order8.upsertOrdersFromRemote))) {
7984
- _context80.next = 3;
8396
+ _context84.next = 3;
7985
8397
  break;
7986
8398
  }
7987
8399
  this.logError("".concat(title, ": Order \u6A21\u5757\u672A\u6CE8\u518C"));
7988
- return _context80.abrupt("return", {
8400
+ return _context84.abrupt("return", {
7989
8401
  code: 500,
7990
8402
  message: 'Order 模块未注册',
7991
8403
  order: null
7992
8404
  });
7993
8405
  case 3:
7994
8406
  if ((_this$app20 = this.app) !== null && _this$app20 !== void 0 && (_this$app20 = _this$app20.request) !== null && _this$app20 !== void 0 && _this$app20.get) {
7995
- _context80.next = 6;
8407
+ _context84.next = 6;
7996
8408
  break;
7997
8409
  }
7998
8410
  this.logError("".concat(title, ": app.request \u4E0D\u53EF\u7528"));
7999
- return _context80.abrupt("return", {
8411
+ return _context84.abrupt("return", {
8000
8412
  code: 500,
8001
8413
  message: 'app.request 不可用',
8002
8414
  order: null
8003
8415
  });
8004
8416
  case 6:
8005
8417
  backendPath = this.buildOrderSalesDetailBackendPath(String(lookup), data);
8006
- _context80.prev = 7;
8007
- _context80.next = 10;
8418
+ _context84.prev = 7;
8419
+ _context84.next = 10;
8008
8420
  return this.app.request.get(backendPath, {
8009
8421
  lookup_mode: 'multi'
8010
8422
  }, {
@@ -8012,9 +8424,9 @@ var Server = /*#__PURE__*/function () {
8012
8424
  customToast: function customToast() {}
8013
8425
  });
8014
8426
  case 10:
8015
- response = _context80.sent;
8427
+ response = _context84.sent;
8016
8428
  if (!this.isCheckoutResponseRejected(response)) {
8017
- _context80.next = 17;
8429
+ _context84.next = 17;
8018
8430
  break;
8019
8431
  }
8020
8432
  responseStatusCode = typeof (response === null || response === void 0 ? void 0 : response.status) === 'number' ? response.status : undefined;
@@ -8026,70 +8438,80 @@ var Server = /*#__PURE__*/function () {
8026
8438
  code: code,
8027
8439
  message: message
8028
8440
  });
8029
- return _context80.abrupt("return", {
8441
+ return _context84.abrupt("return", {
8030
8442
  code: code,
8031
8443
  message: message,
8032
8444
  order: null
8033
8445
  });
8034
8446
  case 17:
8035
- fresh = this.extractOrderDataFromCheckoutResponse(response);
8036
- if (!(!fresh || fresh.order_id === undefined || fresh.order_id === null || String(fresh.order_id).trim() === '')) {
8037
- _context80.next = 21;
8447
+ _fresh2 = this.extractOrderDataFromCheckoutResponse(response);
8448
+ if (!(!_fresh2 || _fresh2.order_id === undefined || _fresh2.order_id === null || String(_fresh2.order_id).trim() === '')) {
8449
+ _context84.next = 21;
8038
8450
  break;
8039
8451
  }
8040
8452
  this.logInfo("".concat(title, ": \u540E\u7AEF\u8FD4\u56DE\u8BA2\u5355\u4E3A\u7A7A"), {
8041
8453
  lookup: lookup,
8042
8454
  backendPath: backendPath
8043
8455
  });
8044
- return _context80.abrupt("return", {
8456
+ return _context84.abrupt("return", {
8045
8457
  code: 500,
8046
8458
  message: '后端返回订单为空',
8047
8459
  order: null
8048
8460
  });
8049
8461
  case 21:
8050
- _context80.t0 = (_this$order$getLocalO = (_this$order9 = this.order).getLocalOrderFromMemoryByLookup) === null || _this$order$getLocalO === void 0 ? void 0 : _this$order$getLocalO.call(_this$order9, lookup);
8051
- if (_context80.t0) {
8052
- _context80.next = 31;
8462
+ if (!prepareExactOrderForPersist) {
8463
+ _context84.next = 25;
8464
+ break;
8465
+ }
8466
+ _context84.t0 = (_this$order$getOrderB = (_this$order9 = this.order).getOrderByOrderId) === null || _this$order$getOrderB === void 0 ? void 0 : _this$order$getOrderB.call(_this$order9, lookup);
8467
+ _context84.next = 36;
8468
+ break;
8469
+ case 25:
8470
+ _context84.t1 = (_this$order$getLocalO = (_this$order10 = this.order).getLocalOrderFromMemoryByLookup) === null || _this$order$getLocalO === void 0 ? void 0 : _this$order$getLocalO.call(_this$order10, lookup);
8471
+ if (_context84.t1) {
8472
+ _context84.next = 35;
8053
8473
  break;
8054
8474
  }
8055
8475
  if (!this.shouldForceRemoteSalesDetail(data)) {
8056
- _context80.next = 29;
8476
+ _context84.next = 33;
8057
8477
  break;
8058
8478
  }
8059
- _context80.next = 26;
8479
+ _context84.next = 30;
8060
8480
  return this.order.getLocalOrderByLookup(lookup);
8061
- case 26:
8062
- _context80.t1 = _context80.sent;
8063
- _context80.next = 30;
8064
- break;
8065
- case 29:
8066
- _context80.t1 = null;
8067
8481
  case 30:
8068
- _context80.t0 = _context80.t1;
8069
- case 31:
8070
- localBeforeRefresh = _context80.t0;
8071
- orderToPersist = fresh;
8482
+ _context84.t2 = _context84.sent;
8483
+ _context84.next = 34;
8484
+ break;
8485
+ case 33:
8486
+ _context84.t2 = null;
8487
+ case 34:
8488
+ _context84.t1 = _context84.t2;
8489
+ case 35:
8490
+ _context84.t0 = _context84.t1;
8491
+ case 36:
8492
+ localBeforeRefresh = _context84.t0;
8493
+ orderToPersist = _fresh2;
8072
8494
  if (!paymentIdentityOrder) {
8073
- _context80.next = 44;
8495
+ _context84.next = 49;
8074
8496
  break;
8075
8497
  }
8076
- if (!(String(fresh.order_id) !== String(paymentIdentityOrder.order_id) || fresh.external_sale_number && paymentIdentityOrder.external_sale_number && fresh.external_sale_number !== paymentIdentityOrder.external_sale_number || !Array.isArray(fresh.payments))) {
8077
- _context80.next = 36;
8498
+ if (!(String(_fresh2.order_id) !== String(paymentIdentityOrder.order_id) || _fresh2.external_sale_number && paymentIdentityOrder.external_sale_number && _fresh2.external_sale_number !== paymentIdentityOrder.external_sale_number || !Array.isArray(_fresh2.payments))) {
8499
+ _context84.next = 41;
8078
8500
  break;
8079
8501
  }
8080
8502
  throw new Error('远端订单身份不匹配或缺少付款明细,暂不补齐付款 ID');
8081
- case 36:
8503
+ case 41:
8082
8504
  if (!(!localBeforeRefresh || Number(localBeforeRefresh.need_sync || 0) === 1 || Number(localBeforeRefresh.is_draft_order || 0) === 1)) {
8083
- _context80.next = 38;
8505
+ _context84.next = 43;
8084
8506
  break;
8085
8507
  }
8086
- return _context80.abrupt("return", {
8508
+ return _context84.abrupt("return", {
8087
8509
  code: 200,
8088
8510
  message: '',
8089
8511
  order: localBeforeRefresh || paymentIdentityOrder
8090
8512
  });
8091
- case 38:
8092
- remotePayments = fresh.payments;
8513
+ case 43:
8514
+ remotePayments = _fresh2.payments;
8093
8515
  paidPayments = (localBeforeRefresh.payments || []).filter(function (payment) {
8094
8516
  return payment.status === 'paid';
8095
8517
  });
@@ -8105,115 +8527,131 @@ var Server = /*#__PURE__*/function () {
8105
8527
  return matches.length === 1 && paymentId !== undefined && paymentId !== null && String(paymentId).trim() !== '';
8106
8528
  });
8107
8529
  if (paymentIdsComplete) {
8108
- _context80.next = 43;
8530
+ _context84.next = 48;
8109
8531
  break;
8110
8532
  }
8111
8533
  throw new Error('远端付款 ID 尚未齐全或付款身份匹配不唯一,保留本地付款等待重试');
8112
- case 43:
8113
- orderToPersist = _objectSpread(_objectSpread({}, fresh), {}, {
8534
+ case 48:
8535
+ orderToPersist = _objectSpread(_objectSpread({}, _fresh2), {}, {
8114
8536
  payments: mergeOrderPaymentListsByIdentity(localBeforeRefresh.payments, remotePayments, {
8115
8537
  preserveUnmatchedExisting: true
8116
8538
  })
8117
8539
  });
8118
- case 44:
8540
+ case 49:
8541
+ if (prepareExactOrderForPersist) orderToPersist = prepareExactOrderForPersist(orderToPersist);
8119
8542
  if (!requiresLocalPaymentRefresh(localBeforeRefresh)) {
8120
- _context80.next = 51;
8543
+ _context84.next = 57;
8121
8544
  break;
8122
8545
  }
8123
- if (!(String(fresh.order_id) !== String(localBeforeRefresh.order_id))) {
8124
- _context80.next = 47;
8546
+ if (!(String(_fresh2.order_id) !== String(localBeforeRefresh.order_id))) {
8547
+ _context84.next = 53;
8125
8548
  break;
8126
8549
  }
8127
8550
  throw new Error('远端订单身份不匹配,请重新刷新');
8128
- case 47:
8129
- _context80.next = 49;
8551
+ case 53:
8552
+ _context84.next = 55;
8130
8553
  return this.order.completeLocalPaymentRefresh(orderToPersist);
8131
- case 49:
8132
- _context80.next = 53;
8554
+ case 55:
8555
+ _context84.next = 59;
8133
8556
  break;
8134
- case 51:
8135
- _context80.next = 53;
8557
+ case 57:
8558
+ _context84.next = 59;
8136
8559
  return this.order.upsertOrdersFromRemote([orderToPersist]);
8137
- case 53:
8138
- _context80.next = 55;
8560
+ case 59:
8561
+ if (!prepareExactOrderForPersist) {
8562
+ _context84.next = 65;
8563
+ break;
8564
+ }
8565
+ _context84.next = 62;
8566
+ return this.order.getLocalOrderByLookup(lookup, {
8567
+ exactOrderId: true
8568
+ });
8569
+ case 62:
8570
+ _context84.t3 = _context84.sent;
8571
+ _context84.next = 68;
8572
+ break;
8573
+ case 65:
8574
+ _context84.next = 67;
8139
8575
  return this.order.getLocalOrderByLookup(lookup);
8140
- case 55:
8141
- savedOrder = _context80.sent;
8142
- if (!(!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup))) {
8143
- _context80.next = 60;
8576
+ case 67:
8577
+ _context84.t3 = _context84.sent;
8578
+ case 68:
8579
+ savedOrder = _context84.t3;
8580
+ if (!(!savedOrder && _fresh2.order_id !== undefined && _fresh2.order_id !== null && String(_fresh2.order_id) !== String(lookup))) {
8581
+ _context84.next = 73;
8144
8582
  break;
8145
8583
  }
8146
- _context80.next = 59;
8147
- return this.order.getLocalOrderByLookup(fresh.order_id);
8148
- case 59:
8149
- savedOrder = _context80.sent;
8150
- case 60:
8584
+ _context84.next = 72;
8585
+ return this.order.getLocalOrderByLookup(_fresh2.order_id);
8586
+ case 72:
8587
+ savedOrder = _context84.sent;
8588
+ case 73:
8151
8589
  if (savedOrder) {
8152
- _context80.next = 63;
8590
+ _context84.next = 76;
8153
8591
  break;
8154
8592
  }
8155
8593
  this.logError("".concat(title, ": \u8BA2\u5355\u5199\u5165\u540E\u56DE\u8BFB\u5931\u8D25"), {
8156
8594
  lookup: lookup,
8157
- remote_order_id: fresh.order_id
8595
+ remote_order_id: _fresh2.order_id
8158
8596
  });
8159
- return _context80.abrupt("return", {
8597
+ return _context84.abrupt("return", {
8160
8598
  code: 500,
8161
8599
  message: '订单写入后回读失败',
8162
8600
  order: null
8163
8601
  });
8164
- case 63:
8602
+ case 76:
8165
8603
  this.logInfo("".concat(title, ": \u8FDC\u7AEF\u8BA2\u5355\u5DF2\u540C\u6B65\u5230\u672C\u5730"), {
8166
8604
  lookup: lookup,
8167
- remote_order_id: fresh.order_id
8605
+ remote_order_id: _fresh2.order_id
8168
8606
  });
8169
- return _context80.abrupt("return", {
8607
+ return _context84.abrupt("return", {
8170
8608
  code: 200,
8171
8609
  message: '',
8172
8610
  order: savedOrder
8173
8611
  });
8174
- case 67:
8175
- _context80.prev = 67;
8176
- _context80.t2 = _context80["catch"](7);
8177
- backendError = this.extractBackendErrorResponse(_context80.t2);
8178
- errorRecord = _context80.t2;
8612
+ case 80:
8613
+ _context84.prev = 80;
8614
+ _context84.t4 = _context84["catch"](7);
8615
+ backendError = this.extractBackendErrorResponse(_context84.t4);
8616
+ errorRecord = _context84.t4;
8179
8617
  _responseStatusCode = typeof (errorRecord === null || errorRecord === void 0 || (_errorRecord$response = errorRecord.response) === null || _errorRecord$response === void 0 ? void 0 : _errorRecord$response.status) === 'number' ? errorRecord.response.status : undefined;
8180
8618
  if (!(backendError || _responseStatusCode !== undefined)) {
8181
- _context80.next = 78;
8619
+ _context84.next = 91;
8182
8620
  break;
8183
8621
  }
8184
8622
  backendStatusCode = typeof (backendError === null || backendError === void 0 ? void 0 : backendError.status) === 'number' ? backendError.status : undefined;
8185
- _code = this.normalizeRemoteSalesOrderErrorCode((_ref85 = (_backendError$code2 = backendError === null || backendError === void 0 ? void 0 : backendError.code) !== null && _backendError$code2 !== void 0 ? _backendError$code2 : backendStatusCode) !== null && _ref85 !== void 0 ? _ref85 : _responseStatusCode);
8186
- _message2 = (backendError === null || backendError === void 0 ? void 0 : backendError.message) || this.getUnknownErrorMessage(_context80.t2);
8623
+ _code = this.normalizeRemoteSalesOrderErrorCode((_ref87 = (_backendError$code2 = backendError === null || backendError === void 0 ? void 0 : backendError.code) !== null && _backendError$code2 !== void 0 ? _backendError$code2 : backendStatusCode) !== null && _ref87 !== void 0 ? _ref87 : _responseStatusCode);
8624
+ _message2 = (backendError === null || backendError === void 0 ? void 0 : backendError.message) || this.getUnknownErrorMessage(_context84.t4);
8187
8625
  this.logInfo("".concat(title, ": \u540E\u7AEF\u8BA2\u5355\u67E5\u8BE2\u5931\u8D25"), {
8188
8626
  lookup: lookup,
8189
8627
  backendPath: backendPath,
8190
8628
  code: _code,
8191
8629
  message: _message2
8192
8630
  });
8193
- return _context80.abrupt("return", {
8631
+ return _context84.abrupt("return", {
8194
8632
  code: _code,
8195
8633
  message: _message2,
8196
8634
  order: null
8197
8635
  });
8198
- case 78:
8199
- _message3 = this.getUnknownErrorMessage(_context80.t2);
8636
+ case 91:
8637
+ _message3 = this.getUnknownErrorMessage(_context84.t4);
8200
8638
  this.logInfo("".concat(title, ": \u8BF7\u6C42\u5931\u8D25"), {
8201
8639
  lookup: lookup,
8202
8640
  backendPath: backendPath,
8203
8641
  error: _message3
8204
8642
  });
8205
- return _context80.abrupt("return", {
8643
+ return _context84.abrupt("return", {
8206
8644
  code: 500,
8207
8645
  message: _message3,
8208
8646
  order: null
8209
8647
  });
8210
- case 81:
8648
+ case 94:
8211
8649
  case "end":
8212
- return _context80.stop();
8650
+ return _context84.stop();
8213
8651
  }
8214
- }, _callee80, this, [[7, 67]]);
8652
+ }, _callee84, this, [[7, 80]]);
8215
8653
  }));
8216
- function fetchAndPersistSalesOrderByLookup(_x88, _x89, _x90, _x91) {
8654
+ function fetchAndPersistSalesOrderByLookup(_x95, _x96, _x97, _x98, _x99) {
8217
8655
  return _fetchAndPersistSalesOrderByLookup.apply(this, arguments);
8218
8656
  }
8219
8657
  return fetchAndPersistSalesOrderByLookup;
@@ -8275,22 +8713,22 @@ var Server = /*#__PURE__*/function () {
8275
8713
  }, {
8276
8714
  key: "handleUpdateLocalOrdersBatch",
8277
8715
  value: (function () {
8278
- var _handleUpdateLocalOrdersBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee81(orderIds) {
8716
+ var _handleUpdateLocalOrdersBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee85(orderIds) {
8279
8717
  var _this$app21;
8280
- var existedBefore, _iterator13, _step13, id, fetched, message, fetchedMap, _iterator14, _step14, order, oid, freshOrders, succeedIds, failed, _iterator15, _step15, _id, fresh, _message4, overwritten, inserted;
8281
- return _regeneratorRuntime().wrap(function _callee81$(_context81) {
8282
- while (1) switch (_context81.prev = _context81.next) {
8718
+ var existedBefore, _iterator13, _step13, id, fetched, message, fetchedMap, _iterator14, _step14, order, oid, freshOrders, succeedIds, failed, _iterator15, _step15, _id, _fresh3, _message4, overwritten, inserted;
8719
+ return _regeneratorRuntime().wrap(function _callee85$(_context85) {
8720
+ while (1) switch (_context85.prev = _context85.next) {
8283
8721
  case 0:
8284
8722
  this.logInfo('handleUpdateLocalOrdersBatch: 开始处理', {
8285
8723
  count: orderIds.length,
8286
8724
  orderIds: orderIds
8287
8725
  });
8288
8726
  if (this.order) {
8289
- _context81.next = 4;
8727
+ _context85.next = 4;
8290
8728
  break;
8291
8729
  }
8292
8730
  this.logError('handleUpdateLocalOrdersBatch: Order 模块未注册');
8293
- return _context81.abrupt("return", {
8731
+ return _context85.abrupt("return", {
8294
8732
  code: 500,
8295
8733
  status: false,
8296
8734
  message: 'Order 模块未注册',
@@ -8298,11 +8736,11 @@ var Server = /*#__PURE__*/function () {
8298
8736
  });
8299
8737
  case 4:
8300
8738
  if ((_this$app21 = this.app) !== null && _this$app21 !== void 0 && _this$app21.request) {
8301
- _context81.next = 7;
8739
+ _context85.next = 7;
8302
8740
  break;
8303
8741
  }
8304
8742
  this.logError('handleUpdateLocalOrdersBatch: app.request 不可用');
8305
- return _context81.abrupt("return", {
8743
+ return _context85.abrupt("return", {
8306
8744
  code: 500,
8307
8745
  status: false,
8308
8746
  message: 'app.request 不可用',
@@ -8325,21 +8763,21 @@ var Server = /*#__PURE__*/function () {
8325
8763
  _iterator13.f();
8326
8764
  }
8327
8765
  fetched = [];
8328
- _context81.prev = 11;
8329
- _context81.next = 14;
8766
+ _context85.prev = 11;
8767
+ _context85.next = 14;
8330
8768
  return this.order.fetchOrdersByHttp(orderIds);
8331
8769
  case 14:
8332
- fetched = _context81.sent;
8333
- _context81.next = 22;
8770
+ fetched = _context85.sent;
8771
+ _context85.next = 22;
8334
8772
  break;
8335
8773
  case 17:
8336
- _context81.prev = 17;
8337
- _context81.t0 = _context81["catch"](11);
8338
- message = _context81.t0 instanceof Error ? _context81.t0.message : String(_context81.t0);
8774
+ _context85.prev = 17;
8775
+ _context85.t0 = _context85["catch"](11);
8776
+ message = _context85.t0 instanceof Error ? _context85.t0.message : String(_context85.t0);
8339
8777
  this.logError('handleUpdateLocalOrdersBatch: 批量拉取失败', {
8340
8778
  message: message
8341
8779
  });
8342
- return _context81.abrupt("return", {
8780
+ return _context85.abrupt("return", {
8343
8781
  code: 500,
8344
8782
  status: false,
8345
8783
  message: message,
@@ -8349,36 +8787,36 @@ var Server = /*#__PURE__*/function () {
8349
8787
  // 按返回结果中的 order_id 建索引,未命中即视为单笔失败
8350
8788
  fetchedMap = new Map();
8351
8789
  _iterator14 = _createForOfIteratorHelper(fetched);
8352
- _context81.prev = 24;
8790
+ _context85.prev = 24;
8353
8791
  _iterator14.s();
8354
8792
  case 26:
8355
8793
  if ((_step14 = _iterator14.n()).done) {
8356
- _context81.next = 34;
8794
+ _context85.next = 34;
8357
8795
  break;
8358
8796
  }
8359
8797
  order = _step14.value;
8360
8798
  oid = order === null || order === void 0 ? void 0 : order.order_id;
8361
8799
  if (!(oid === undefined || oid === null)) {
8362
- _context81.next = 31;
8800
+ _context85.next = 31;
8363
8801
  break;
8364
8802
  }
8365
- return _context81.abrupt("continue", 32);
8803
+ return _context85.abrupt("continue", 32);
8366
8804
  case 31:
8367
8805
  fetchedMap.set(String(oid), order);
8368
8806
  case 32:
8369
- _context81.next = 26;
8807
+ _context85.next = 26;
8370
8808
  break;
8371
8809
  case 34:
8372
- _context81.next = 39;
8810
+ _context85.next = 39;
8373
8811
  break;
8374
8812
  case 36:
8375
- _context81.prev = 36;
8376
- _context81.t1 = _context81["catch"](24);
8377
- _iterator14.e(_context81.t1);
8813
+ _context85.prev = 36;
8814
+ _context85.t1 = _context85["catch"](24);
8815
+ _iterator14.e(_context85.t1);
8378
8816
  case 39:
8379
- _context81.prev = 39;
8817
+ _context85.prev = 39;
8380
8818
  _iterator14.f();
8381
- return _context81.finish(39);
8819
+ return _context85.finish(39);
8382
8820
  case 42:
8383
8821
  freshOrders = [];
8384
8822
  succeedIds = [];
@@ -8387,9 +8825,9 @@ var Server = /*#__PURE__*/function () {
8387
8825
  try {
8388
8826
  for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
8389
8827
  _id = _step15.value;
8390
- fresh = fetchedMap.get(_id);
8391
- if (fresh) {
8392
- freshOrders.push(fresh);
8828
+ _fresh3 = fetchedMap.get(_id);
8829
+ if (_fresh3) {
8830
+ freshOrders.push(_fresh3);
8393
8831
  succeedIds.push(_id);
8394
8832
  } else {
8395
8833
  failed.push({
@@ -8404,23 +8842,23 @@ var Server = /*#__PURE__*/function () {
8404
8842
  _iterator15.f();
8405
8843
  }
8406
8844
  if (!(freshOrders.length > 0)) {
8407
- _context81.next = 58;
8845
+ _context85.next = 58;
8408
8846
  break;
8409
8847
  }
8410
- _context81.prev = 48;
8411
- _context81.next = 51;
8848
+ _context85.prev = 48;
8849
+ _context85.next = 51;
8412
8850
  return this.order.upsertOrdersFromRemote(freshOrders);
8413
8851
  case 51:
8414
- _context81.next = 58;
8852
+ _context85.next = 58;
8415
8853
  break;
8416
8854
  case 53:
8417
- _context81.prev = 53;
8418
- _context81.t2 = _context81["catch"](48);
8419
- _message4 = _context81.t2 instanceof Error ? _context81.t2.message : String(_context81.t2);
8855
+ _context85.prev = 53;
8856
+ _context85.t2 = _context85["catch"](48);
8857
+ _message4 = _context85.t2 instanceof Error ? _context85.t2.message : String(_context85.t2);
8420
8858
  this.logError('handleUpdateLocalOrdersBatch: 合并写入失败', {
8421
8859
  message: _message4
8422
8860
  });
8423
- return _context81.abrupt("return", {
8861
+ return _context85.abrupt("return", {
8424
8862
  code: 500,
8425
8863
  status: false,
8426
8864
  message: _message4,
@@ -8439,7 +8877,7 @@ var Server = /*#__PURE__*/function () {
8439
8877
  insertedCount: inserted.length,
8440
8878
  failedCount: failed.length
8441
8879
  });
8442
- return _context81.abrupt("return", {
8880
+ return _context85.abrupt("return", {
8443
8881
  code: 200,
8444
8882
  status: true,
8445
8883
  message: '',
@@ -8451,11 +8889,11 @@ var Server = /*#__PURE__*/function () {
8451
8889
  });
8452
8890
  case 62:
8453
8891
  case "end":
8454
- return _context81.stop();
8892
+ return _context85.stop();
8455
8893
  }
8456
- }, _callee81, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
8894
+ }, _callee85, this, [[11, 17], [24, 36, 39, 42], [48, 53]]);
8457
8895
  }));
8458
- function handleUpdateLocalOrdersBatch(_x92) {
8896
+ function handleUpdateLocalOrdersBatch(_x100) {
8459
8897
  return _handleUpdateLocalOrdersBatch.apply(this, arguments);
8460
8898
  }
8461
8899
  return handleUpdateLocalOrdersBatch;
@@ -8702,10 +9140,10 @@ var Server = /*#__PURE__*/function () {
8702
9140
  value: function extractBackendErrorResponse(error) {
8703
9141
  var _error$response3,
8704
9142
  _error$response4,
8705
- _this27 = this;
9143
+ _this28 = this;
8706
9144
  var candidates = [error === null || error === void 0 || (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.body, error === null || error === void 0 ? void 0 : error.body];
8707
9145
  return candidates.find(function (candidate) {
8708
- return _this27.isExplicitBackendErrorResponse(candidate);
9146
+ return _this28.isExplicitBackendErrorResponse(candidate);
8709
9147
  }) || null;
8710
9148
  }
8711
9149
  }, {
@@ -8824,16 +9262,16 @@ var Server = /*#__PURE__*/function () {
8824
9262
  }, {
8825
9263
  key: "recomputeAndNotifyFloorPlanQuery",
8826
9264
  value: (function () {
8827
- var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee82() {
9265
+ var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee86() {
8828
9266
  var _iterator17, _step17, _step17$value, subscriberId, sub, result, errorMessage;
8829
- return _regeneratorRuntime().wrap(function _callee82$(_context82) {
8830
- while (1) switch (_context82.prev = _context82.next) {
9267
+ return _regeneratorRuntime().wrap(function _callee86$(_context86) {
9268
+ while (1) switch (_context86.prev = _context86.next) {
8831
9269
  case 0:
8832
9270
  if (!(this.floorPlanQuerySubscribers.size === 0)) {
8833
- _context82.next = 2;
9271
+ _context86.next = 2;
8834
9272
  break;
8835
9273
  }
8836
- return _context82.abrupt("return");
9274
+ return _context86.abrupt("return");
8837
9275
  case 2:
8838
9276
  this.logInfo('recomputeAndNotifyFloorPlanQuery: 开始推送', {
8839
9277
  subscriberCount: this.floorPlanQuerySubscribers.size
@@ -8863,9 +9301,9 @@ var Server = /*#__PURE__*/function () {
8863
9301
  }
8864
9302
  case 5:
8865
9303
  case "end":
8866
- return _context82.stop();
9304
+ return _context86.stop();
8867
9305
  }
8868
- }, _callee82, this);
9306
+ }, _callee86, this);
8869
9307
  }));
8870
9308
  function recomputeAndNotifyFloorPlanQuery() {
8871
9309
  return _recomputeAndNotifyFloorPlanQuery.apply(this, arguments);
@@ -8895,20 +9333,20 @@ var Server = /*#__PURE__*/function () {
8895
9333
  * filter 逻辑暂为 mock,仅记录参数
8896
9334
  */
8897
9335
  function () {
8898
- var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee83(data) {
9336
+ var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee87(data) {
8899
9337
  var rawList, result;
8900
- return _regeneratorRuntime().wrap(function _callee83$(_context83) {
8901
- while (1) switch (_context83.prev = _context83.next) {
9338
+ return _regeneratorRuntime().wrap(function _callee87$(_context87) {
9339
+ while (1) switch (_context87.prev = _context87.next) {
8902
9340
  case 0:
8903
9341
  this.logInfo('computeOrderQueryResult: 开始过滤', {
8904
9342
  data: data
8905
9343
  });
8906
9344
  if (this.order) {
8907
- _context83.next = 4;
9345
+ _context87.next = 4;
8908
9346
  break;
8909
9347
  }
8910
9348
  this.logError('computeOrderQueryResult: Order 模块未注册');
8911
- return _context83.abrupt("return", {
9349
+ return _context87.abrupt("return", {
8912
9350
  code: 500,
8913
9351
  message: 'Order 模块未注册',
8914
9352
  data: {
@@ -8940,7 +9378,7 @@ var Server = /*#__PURE__*/function () {
8940
9378
  skip: result.skip,
8941
9379
  rejected: result.rejected
8942
9380
  });
8943
- return _context83.abrupt("return", {
9381
+ return _context87.abrupt("return", {
8944
9382
  code: 200,
8945
9383
  data: result,
8946
9384
  message: '',
@@ -8948,11 +9386,11 @@ var Server = /*#__PURE__*/function () {
8948
9386
  });
8949
9387
  case 10:
8950
9388
  case "end":
8951
- return _context83.stop();
9389
+ return _context87.stop();
8952
9390
  }
8953
- }, _callee83, this);
9391
+ }, _callee87, this);
8954
9392
  }));
8955
- function computeOrderQueryResult(_x93) {
9393
+ function computeOrderQueryResult(_x101) {
8956
9394
  return _computeOrderQueryResult.apply(this, arguments);
8957
9395
  }
8958
9396
  return computeOrderQueryResult;
@@ -8965,17 +9403,17 @@ var Server = /*#__PURE__*/function () {
8965
9403
  }, {
8966
9404
  key: "computeBookingQueryResult",
8967
9405
  value: (function () {
8968
- var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee84(data) {
9406
+ var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee88(data) {
8969
9407
  var rawOrders, result;
8970
- return _regeneratorRuntime().wrap(function _callee84$(_context84) {
8971
- while (1) switch (_context84.prev = _context84.next) {
9408
+ return _regeneratorRuntime().wrap(function _callee88$(_context88) {
9409
+ while (1) switch (_context88.prev = _context88.next) {
8972
9410
  case 0:
8973
9411
  if (this.order) {
8974
- _context84.next = 3;
9412
+ _context88.next = 3;
8975
9413
  break;
8976
9414
  }
8977
9415
  this.logError('computeBookingQueryResult: Order 模块未注册');
8978
- return _context84.abrupt("return", {
9416
+ return _context88.abrupt("return", {
8979
9417
  code: 500,
8980
9418
  message: 'Order 模块未注册',
8981
9419
  data: {
@@ -8994,7 +9432,7 @@ var Server = /*#__PURE__*/function () {
8994
9432
  size: result.size,
8995
9433
  skip: result.skip
8996
9434
  });
8997
- return _context84.abrupt("return", {
9435
+ return _context88.abrupt("return", {
8998
9436
  code: 200,
8999
9437
  data: result,
9000
9438
  message: '',
@@ -9002,11 +9440,11 @@ var Server = /*#__PURE__*/function () {
9002
9440
  });
9003
9441
  case 8:
9004
9442
  case "end":
9005
- return _context84.stop();
9443
+ return _context88.stop();
9006
9444
  }
9007
- }, _callee84, this);
9445
+ }, _callee88, this);
9008
9446
  }));
9009
- function computeBookingQueryResult(_x94) {
9447
+ function computeBookingQueryResult(_x102) {
9010
9448
  return _computeBookingQueryResult.apply(this, arguments);
9011
9449
  }
9012
9450
  return computeBookingQueryResult;
@@ -9065,12 +9503,12 @@ var Server = /*#__PURE__*/function () {
9065
9503
  }, {
9066
9504
  key: "computeProductQueryResult",
9067
9505
  value: (function () {
9068
- var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee85(context, options) {
9506
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee89(context, options) {
9069
9507
  var _menu_list_ids$length3,
9070
- _this28 = this;
9508
+ _this29 = this;
9071
9509
  var tTotal, menu_list_ids, ids, schedule_date, schedule_datetime, customer_id, extension_type, product_id, application_code, strategy_context, isVisibleProduct, queryIds, startupPreloadTask, formatterContext, uniqueIds, _tPrice, productsWithPrice, _filteredProducts, extensionFilteredProducts, _published$find, pid, _tPrice2, allProductsWithPrice, published, item, _tPrice3, _filteredProducts2, _tStatus, _beforeStatusCount, _tExtensionType, _beforeExtensionTypeCount, _tSort, activeMenuList, tMenu, getActiveMenus, tFilter, productScope, scopedProductIds, tPrice, filteredProducts, tStatus, beforeStatusCount, tExtensionType, beforeExtensionTypeCount, tSort;
9072
- return _regeneratorRuntime().wrap(function _callee85$(_context85) {
9073
- while (1) switch (_context85.prev = _context85.next) {
9510
+ return _regeneratorRuntime().wrap(function _callee89$(_context89) {
9511
+ while (1) switch (_context89.prev = _context89.next) {
9074
9512
  case 0:
9075
9513
  tTotal = performance.now();
9076
9514
  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, extension_type = context.extension_type, product_id = context.product_id, application_code = context.application_code, strategy_context = context.strategy_context; // 仅 Kiosk 查询额外按商品销售渠道过滤。
@@ -9099,10 +9537,10 @@ var Server = /*#__PURE__*/function () {
9099
9537
  // SQLite/IndexDB,造成 preload 读到空数据并重复请求。正常运行期该字段为 null,不增加等待。
9100
9538
  startupPreloadTask = this.startupModulePreloadInFlight;
9101
9539
  if (!startupPreloadTask) {
9102
- _context85.next = 9;
9540
+ _context89.next = 9;
9103
9541
  break;
9104
9542
  }
9105
- _context85.next = 9;
9543
+ _context89.next = 9;
9106
9544
  return startupPreloadTask;
9107
9545
  case 9:
9108
9546
  // Menu/Schedule preload 会替换 store 中的数组;必须在等待完成后再读取,
@@ -9114,28 +9552,28 @@ var Server = /*#__PURE__*/function () {
9114
9552
  strategy_context: strategy_context
9115
9553
  });
9116
9554
  if (this.products) {
9117
- _context85.next = 13;
9555
+ _context89.next = 13;
9118
9556
  break;
9119
9557
  }
9120
9558
  this.logError('computeProductQueryResult: Products 模块未注册');
9121
- return _context85.abrupt("return", {
9559
+ return _context89.abrupt("return", {
9122
9560
  message: 'Products 模块未注册',
9123
9561
  data: this.buildProductQueryResultPayload([], 0)
9124
9562
  });
9125
9563
  case 13:
9126
9564
  if (!(queryIds.length > 0)) {
9127
- _context85.next = 25;
9565
+ _context89.next = 25;
9128
9566
  break;
9129
9567
  }
9130
9568
  uniqueIds = Array.from(new Set(queryIds));
9131
9569
  _tPrice = performance.now();
9132
- _context85.next = 18;
9570
+ _context89.next = 18;
9133
9571
  return this.products.getProductsWithPrice(schedule_date, formatterContext, {
9134
9572
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds,
9135
9573
  productIds: uniqueIds
9136
9574
  });
9137
9575
  case 18:
9138
- productsWithPrice = _context85.sent;
9576
+ productsWithPrice = _context89.sent;
9139
9577
  perfMark('computeQuery.getProductsWithPrice(ids)', performance.now() - _tPrice, {
9140
9578
  count: productsWithPrice.length,
9141
9579
  ids: uniqueIds
@@ -9153,7 +9591,7 @@ var Server = /*#__PURE__*/function () {
9153
9591
  ids: uniqueIds,
9154
9592
  count: extensionFilteredProducts.length
9155
9593
  });
9156
- return _context85.abrupt("return", {
9594
+ return _context89.abrupt("return", {
9157
9595
  code: 200,
9158
9596
  data: this.buildProductQueryResultPayload(extensionFilteredProducts),
9159
9597
  message: '',
@@ -9161,17 +9599,17 @@ var Server = /*#__PURE__*/function () {
9161
9599
  });
9162
9600
  case 25:
9163
9601
  if (!(product_id != null && Number.isFinite(Number(product_id)))) {
9164
- _context85.next = 37;
9602
+ _context89.next = 37;
9165
9603
  break;
9166
9604
  }
9167
9605
  pid = Number(product_id);
9168
9606
  _tPrice2 = performance.now();
9169
- _context85.next = 30;
9607
+ _context89.next = 30;
9170
9608
  return this.products.getProductsWithPrice(schedule_date, formatterContext, {
9171
9609
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
9172
9610
  });
9173
9611
  case 30:
9174
- allProductsWithPrice = _context85.sent;
9612
+ allProductsWithPrice = _context89.sent;
9175
9613
  perfMark('computeQuery.getProductsWithPrice(single)', performance.now() - _tPrice2, {
9176
9614
  count: allProductsWithPrice.length,
9177
9615
  productId: pid
@@ -9189,7 +9627,7 @@ var Server = /*#__PURE__*/function () {
9189
9627
  productId: pid,
9190
9628
  found: !!item
9191
9629
  });
9192
- return _context85.abrupt("return", {
9630
+ return _context89.abrupt("return", {
9193
9631
  code: 200,
9194
9632
  data: item,
9195
9633
  message: item ? '' : '商品不存在或未发布',
@@ -9197,16 +9635,16 @@ var Server = /*#__PURE__*/function () {
9197
9635
  });
9198
9636
  case 37:
9199
9637
  if (!this.shouldQueryProductsByExtensionTypes(extension_type)) {
9200
- _context85.next = 57;
9638
+ _context89.next = 57;
9201
9639
  break;
9202
9640
  }
9203
9641
  _tPrice3 = performance.now();
9204
- _context85.next = 41;
9642
+ _context89.next = 41;
9205
9643
  return this.products.getProductsWithPrice(schedule_date, formatterContext, {
9206
9644
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
9207
9645
  });
9208
9646
  case 41:
9209
- _filteredProducts2 = _context85.sent;
9647
+ _filteredProducts2 = _context89.sent;
9210
9648
  perfMark('computeQuery.getProductsWithPrice(extensionType)', performance.now() - _tPrice3, {
9211
9649
  count: _filteredProducts2.length,
9212
9650
  extension_type: extension_type
@@ -9243,7 +9681,7 @@ var Server = /*#__PURE__*/function () {
9243
9681
  filteredCount: _filteredProducts2.length,
9244
9682
  extension_type: extension_type
9245
9683
  });
9246
- return _context85.abrupt("return", {
9684
+ return _context89.abrupt("return", {
9247
9685
  code: 200,
9248
9686
  data: this.buildProductQueryResultPayload(_filteredProducts2),
9249
9687
  message: '',
@@ -9251,50 +9689,50 @@ var Server = /*#__PURE__*/function () {
9251
9689
  });
9252
9690
  case 57:
9253
9691
  if (this.menu) {
9254
- _context85.next = 60;
9692
+ _context89.next = 60;
9255
9693
  break;
9256
9694
  }
9257
9695
  this.logError('computeProductQueryResult: Menu 模块未注册');
9258
- return _context85.abrupt("return", {
9696
+ return _context89.abrupt("return", {
9259
9697
  message: 'Menu 模块未注册',
9260
9698
  data: this.buildProductQueryResultPayload([], 0)
9261
9699
  });
9262
9700
  case 60:
9263
9701
  if (this.schedule) {
9264
- _context85.next = 63;
9702
+ _context89.next = 63;
9265
9703
  break;
9266
9704
  }
9267
9705
  this.logError('computeProductQueryResult: Schedule 模块未注册');
9268
- return _context85.abrupt("return", {
9706
+ return _context89.abrupt("return", {
9269
9707
  message: 'Schedule 模块未注册',
9270
9708
  data: this.buildProductQueryResultPayload([], 0)
9271
9709
  });
9272
9710
  case 63:
9273
9711
  activeMenuList = [];
9274
9712
  if (!(menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0)) {
9275
- _context85.next = 76;
9713
+ _context89.next = 76;
9276
9714
  break;
9277
9715
  }
9278
9716
  tMenu = performance.now();
9279
9717
  getActiveMenus = function getActiveMenus() {
9280
- return _this28.menu.getMenuByIds(menu_list_ids).filter(function (menu) {
9281
- var _this28$schedule;
9282
- return ((_this28$schedule = _this28.schedule) === null || _this28$schedule === void 0 ? void 0 : _this28$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
9718
+ return _this29.menu.getMenuByIds(menu_list_ids).filter(function (menu) {
9719
+ var _this29$schedule;
9720
+ return ((_this29$schedule = _this29.schedule) === null || _this29$schedule === void 0 ? void 0 : _this29$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
9283
9721
  });
9284
9722
  };
9285
9723
  activeMenuList = getActiveMenus();
9286
- _context85.t0 = !activeMenuList.length;
9287
- if (!_context85.t0) {
9288
- _context85.next = 73;
9724
+ _context89.t0 = !activeMenuList.length;
9725
+ if (!_context89.t0) {
9726
+ _context89.next = 73;
9289
9727
  break;
9290
9728
  }
9291
- _context85.next = 72;
9729
+ _context89.next = 72;
9292
9730
  return this.refreshMenuScheduleCacheAfterEmptyResult();
9293
9731
  case 72:
9294
- _context85.t0 = _context85.sent;
9732
+ _context89.t0 = _context89.sent;
9295
9733
  case 73:
9296
- if (!_context85.t0) {
9297
- _context85.next = 75;
9734
+ if (!_context89.t0) {
9735
+ _context89.next = 75;
9298
9736
  break;
9299
9737
  }
9300
9738
  activeMenuList = getActiveMenus();
@@ -9314,22 +9752,22 @@ var Server = /*#__PURE__*/function () {
9314
9752
  });
9315
9753
  tPrice = performance.now();
9316
9754
  if (!(scopedProductIds.length > 0)) {
9317
- _context85.next = 87;
9755
+ _context89.next = 87;
9318
9756
  break;
9319
9757
  }
9320
- _context85.next = 84;
9758
+ _context89.next = 84;
9321
9759
  return this.products.getProductsWithPrice(schedule_date, formatterContext, {
9322
9760
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds,
9323
9761
  productIds: productScope.isAllProducts ? undefined : scopedProductIds
9324
9762
  });
9325
9763
  case 84:
9326
- _context85.t1 = _context85.sent;
9327
- _context85.next = 88;
9764
+ _context89.t1 = _context89.sent;
9765
+ _context89.next = 88;
9328
9766
  break;
9329
9767
  case 87:
9330
- _context85.t1 = [];
9768
+ _context89.t1 = [];
9331
9769
  case 88:
9332
- filteredProducts = _context85.t1;
9770
+ filteredProducts = _context89.t1;
9333
9771
  perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
9334
9772
  count: filteredProducts.length,
9335
9773
  scopedProductCount: scopedProductIds.length
@@ -9368,7 +9806,7 @@ var Server = /*#__PURE__*/function () {
9368
9806
  filteredCount: filteredProducts.length,
9369
9807
  activeMenuCount: activeMenuList.length
9370
9808
  });
9371
- return _context85.abrupt("return", {
9809
+ return _context89.abrupt("return", {
9372
9810
  code: 200,
9373
9811
  data: this.buildProductQueryResultPayload(filteredProducts),
9374
9812
  message: '',
@@ -9376,11 +9814,11 @@ var Server = /*#__PURE__*/function () {
9376
9814
  });
9377
9815
  case 104:
9378
9816
  case "end":
9379
- return _context85.stop();
9817
+ return _context89.stop();
9380
9818
  }
9381
- }, _callee85, this);
9819
+ }, _callee89, this);
9382
9820
  }));
9383
- function computeProductQueryResult(_x95, _x96) {
9821
+ function computeProductQueryResult(_x103, _x104) {
9384
9822
  return _computeProductQueryResult.apply(this, arguments);
9385
9823
  }
9386
9824
  return computeProductQueryResult;
@@ -9418,74 +9856,74 @@ var Server = /*#__PURE__*/function () {
9418
9856
  }, {
9419
9857
  key: "recomputeAndNotifyProductQuery",
9420
9858
  value: (function () {
9421
- var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee86(options) {
9859
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee90(options) {
9422
9860
  var _iterator18, _step18, _step18$value, subscriberId, subscriber, result, errorMessage;
9423
- return _regeneratorRuntime().wrap(function _callee86$(_context86) {
9424
- while (1) switch (_context86.prev = _context86.next) {
9861
+ return _regeneratorRuntime().wrap(function _callee90$(_context90) {
9862
+ while (1) switch (_context90.prev = _context90.next) {
9425
9863
  case 0:
9426
9864
  if (!(this.productQuerySubscribers.size === 0)) {
9427
- _context86.next = 2;
9865
+ _context90.next = 2;
9428
9866
  break;
9429
9867
  }
9430
- return _context86.abrupt("return");
9868
+ return _context90.abrupt("return");
9431
9869
  case 2:
9432
9870
  this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
9433
9871
  subscriberCount: this.productQuerySubscribers.size,
9434
9872
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
9435
9873
  });
9436
9874
  _iterator18 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
9437
- _context86.prev = 4;
9875
+ _context90.prev = 4;
9438
9876
  _iterator18.s();
9439
9877
  case 6:
9440
9878
  if ((_step18 = _iterator18.n()).done) {
9441
- _context86.next = 23;
9879
+ _context90.next = 23;
9442
9880
  break;
9443
9881
  }
9444
9882
  _step18$value = _slicedToArray(_step18.value, 2), subscriberId = _step18$value[0], subscriber = _step18$value[1];
9445
- _context86.prev = 8;
9446
- _context86.next = 11;
9883
+ _context90.prev = 8;
9884
+ _context90.next = 11;
9447
9885
  return this.computeProductQueryResult(subscriber.context, {
9448
9886
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
9449
9887
  });
9450
9888
  case 11:
9451
- result = _context86.sent;
9452
- _context86.next = 14;
9889
+ result = _context90.sent;
9890
+ _context90.next = 14;
9453
9891
  return subscriber.callback(result);
9454
9892
  case 14:
9455
9893
  this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
9456
9894
  subscriberId: subscriberId
9457
9895
  });
9458
- _context86.next = 21;
9896
+ _context90.next = 21;
9459
9897
  break;
9460
9898
  case 17:
9461
- _context86.prev = 17;
9462
- _context86.t0 = _context86["catch"](8);
9463
- errorMessage = _context86.t0 instanceof Error ? _context86.t0.message : String(_context86.t0);
9899
+ _context90.prev = 17;
9900
+ _context90.t0 = _context90["catch"](8);
9901
+ errorMessage = _context90.t0 instanceof Error ? _context90.t0.message : String(_context90.t0);
9464
9902
  this.logError('recomputeAndNotifyProductQuery: 推送失败', {
9465
9903
  subscriberId: subscriberId,
9466
9904
  error: errorMessage
9467
9905
  });
9468
9906
  case 21:
9469
- _context86.next = 6;
9907
+ _context90.next = 6;
9470
9908
  break;
9471
9909
  case 23:
9472
- _context86.next = 28;
9910
+ _context90.next = 28;
9473
9911
  break;
9474
9912
  case 25:
9475
- _context86.prev = 25;
9476
- _context86.t1 = _context86["catch"](4);
9477
- _iterator18.e(_context86.t1);
9913
+ _context90.prev = 25;
9914
+ _context90.t1 = _context90["catch"](4);
9915
+ _iterator18.e(_context90.t1);
9478
9916
  case 28:
9479
- _context86.prev = 28;
9917
+ _context90.prev = 28;
9480
9918
  _iterator18.f();
9481
- return _context86.finish(28);
9919
+ return _context90.finish(28);
9482
9920
  case 31:
9483
9921
  case "end":
9484
- return _context86.stop();
9922
+ return _context90.stop();
9485
9923
  }
9486
- }, _callee86, this, [[4, 25, 28, 31], [8, 17]]);
9924
+ }, _callee90, this, [[4, 25, 28, 31], [8, 17]]);
9487
9925
  }));
9488
- function recomputeAndNotifyProductQuery(_x97) {
9926
+ function recomputeAndNotifyProductQuery(_x105) {
9489
9927
  return _recomputeAndNotifyProductQuery.apply(this, arguments);
9490
9928
  }
9491
9929
  return recomputeAndNotifyProductQuery;
@@ -9497,16 +9935,16 @@ var Server = /*#__PURE__*/function () {
9497
9935
  }, {
9498
9936
  key: "recomputeAndNotifyOrderQuery",
9499
9937
  value: (function () {
9500
- var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee87() {
9938
+ var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee91() {
9501
9939
  var notifyStartAt, _iterator19, _step19, _step19$value, subscriberId, subscriber, computeStartAt, result, computeEndAt, callbackStartAt, callbackEndAt, errorMessage, notifyEndAt;
9502
- return _regeneratorRuntime().wrap(function _callee87$(_context87) {
9503
- while (1) switch (_context87.prev = _context87.next) {
9940
+ return _regeneratorRuntime().wrap(function _callee91$(_context91) {
9941
+ while (1) switch (_context91.prev = _context91.next) {
9504
9942
  case 0:
9505
9943
  if (!(this.orderQuerySubscribers.size === 0)) {
9506
- _context87.next = 2;
9944
+ _context91.next = 2;
9507
9945
  break;
9508
9946
  }
9509
- return _context87.abrupt("return");
9947
+ return _context91.abrupt("return");
9510
9948
  case 2:
9511
9949
  notifyStartAt = Date.now();
9512
9950
  this.logInfo('recomputeAndNotifyOrderQuery: 开始推送', {
@@ -9514,20 +9952,20 @@ var Server = /*#__PURE__*/function () {
9514
9952
  notifyStartAt: new Date(notifyStartAt).toISOString()
9515
9953
  });
9516
9954
  _iterator19 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
9517
- _context87.prev = 5;
9955
+ _context91.prev = 5;
9518
9956
  _iterator19.s();
9519
9957
  case 7:
9520
9958
  if ((_step19 = _iterator19.n()).done) {
9521
- _context87.next = 27;
9959
+ _context91.next = 27;
9522
9960
  break;
9523
9961
  }
9524
9962
  _step19$value = _slicedToArray(_step19.value, 2), subscriberId = _step19$value[0], subscriber = _step19$value[1];
9525
- _context87.prev = 9;
9963
+ _context91.prev = 9;
9526
9964
  computeStartAt = Date.now();
9527
- _context87.next = 13;
9965
+ _context91.next = 13;
9528
9966
  return this.computeOrderQueryResult(subscriber.context);
9529
9967
  case 13:
9530
- result = _context87.sent;
9968
+ result = _context91.sent;
9531
9969
  computeEndAt = Date.now();
9532
9970
  callbackStartAt = Date.now();
9533
9971
  subscriber.callback(result);
@@ -9538,30 +9976,30 @@ var Server = /*#__PURE__*/function () {
9538
9976
  callbackDurationMs: callbackEndAt - callbackStartAt,
9539
9977
  totalDurationMs: callbackEndAt - computeStartAt
9540
9978
  });
9541
- _context87.next = 25;
9979
+ _context91.next = 25;
9542
9980
  break;
9543
9981
  case 21:
9544
- _context87.prev = 21;
9545
- _context87.t0 = _context87["catch"](9);
9546
- errorMessage = _context87.t0 instanceof Error ? _context87.t0.message : String(_context87.t0);
9982
+ _context91.prev = 21;
9983
+ _context91.t0 = _context91["catch"](9);
9984
+ errorMessage = _context91.t0 instanceof Error ? _context91.t0.message : String(_context91.t0);
9547
9985
  this.logError('recomputeAndNotifyOrderQuery: 推送失败', {
9548
9986
  subscriberId: subscriberId,
9549
9987
  error: errorMessage
9550
9988
  });
9551
9989
  case 25:
9552
- _context87.next = 7;
9990
+ _context91.next = 7;
9553
9991
  break;
9554
9992
  case 27:
9555
- _context87.next = 32;
9993
+ _context91.next = 32;
9556
9994
  break;
9557
9995
  case 29:
9558
- _context87.prev = 29;
9559
- _context87.t1 = _context87["catch"](5);
9560
- _iterator19.e(_context87.t1);
9996
+ _context91.prev = 29;
9997
+ _context91.t1 = _context91["catch"](5);
9998
+ _iterator19.e(_context91.t1);
9561
9999
  case 32:
9562
- _context87.prev = 32;
10000
+ _context91.prev = 32;
9563
10001
  _iterator19.f();
9564
- return _context87.finish(32);
10002
+ return _context91.finish(32);
9565
10003
  case 35:
9566
10004
  notifyEndAt = Date.now();
9567
10005
  this.logInfo('recomputeAndNotifyOrderQuery: 推送完成', {
@@ -9570,9 +10008,9 @@ var Server = /*#__PURE__*/function () {
9570
10008
  });
9571
10009
  case 37:
9572
10010
  case "end":
9573
- return _context87.stop();
10011
+ return _context91.stop();
9574
10012
  }
9575
- }, _callee87, this, [[5, 29, 32, 35], [9, 21]]);
10013
+ }, _callee91, this, [[5, 29, 32, 35], [9, 21]]);
9576
10014
  }));
9577
10015
  function recomputeAndNotifyOrderQuery() {
9578
10016
  return _recomputeAndNotifyOrderQuery.apply(this, arguments);
@@ -9590,7 +10028,7 @@ var Server = /*#__PURE__*/function () {
9590
10028
  }, {
9591
10029
  key: "notifySalesSearchSubscribers",
9592
10030
  value: function notifySalesSearchSubscribers(payload) {
9593
- var _this29 = this;
10031
+ var _this30 = this;
9594
10032
  if (this.salesSearchSubscribers.size === 0) return;
9595
10033
  var changedOrders = this.extractChangedOrdersFromPayload(payload);
9596
10034
  if (changedOrders.length === 0) {
@@ -9608,21 +10046,21 @@ var Server = /*#__PURE__*/function () {
9608
10046
  subscriber = _step20$value[1];
9609
10047
  try {
9610
10048
  var changedVisibleOrders = changedOrders.filter(function (order) {
9611
- var orderId = _this29.getSalesSearchOrderId(order);
10049
+ var orderId = _this30.getSalesSearchOrderId(order);
9612
10050
  return !!orderId && subscriber.visibleOrderIds.has(orderId);
9613
10051
  });
9614
10052
  if (changedVisibleOrders.length === 0) {
9615
10053
  return 1; // continue
9616
10054
  }
9617
- subscriber.callback(_this29.buildSalesSearchDeltaResponse(subscriber, changedVisibleOrders));
9618
- _this29.logInfo('notifySalesSearchSubscribers: 已推送 delta', {
10055
+ subscriber.callback(_this30.buildSalesSearchDeltaResponse(subscriber, changedVisibleOrders));
10056
+ _this30.logInfo('notifySalesSearchSubscribers: 已推送 delta', {
9619
10057
  subscriberId: subscriberId,
9620
10058
  kind: subscriber.kind,
9621
10059
  count: changedVisibleOrders.length
9622
10060
  });
9623
10061
  } catch (error) {
9624
10062
  var errorMessage = error instanceof Error ? error.message : String(error);
9625
- _this29.logError('notifySalesSearchSubscribers: 推送失败', {
10063
+ _this30.logError('notifySalesSearchSubscribers: 推送失败', {
9626
10064
  subscriberId: subscriberId,
9627
10065
  error: errorMessage
9628
10066
  });
@@ -9713,67 +10151,67 @@ var Server = /*#__PURE__*/function () {
9713
10151
  }, {
9714
10152
  key: "recomputeAndNotifyBookingQuery",
9715
10153
  value: (function () {
9716
- var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee88() {
10154
+ var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee92() {
9717
10155
  var _iterator21, _step21, _step21$value, subscriberId, subscriber, result, errorMessage;
9718
- return _regeneratorRuntime().wrap(function _callee88$(_context88) {
9719
- while (1) switch (_context88.prev = _context88.next) {
10156
+ return _regeneratorRuntime().wrap(function _callee92$(_context92) {
10157
+ while (1) switch (_context92.prev = _context92.next) {
9720
10158
  case 0:
9721
10159
  if (!(this.bookingQuerySubscribers.size === 0)) {
9722
- _context88.next = 2;
10160
+ _context92.next = 2;
9723
10161
  break;
9724
10162
  }
9725
- return _context88.abrupt("return");
10163
+ return _context92.abrupt("return");
9726
10164
  case 2:
9727
10165
  this.logInfo('recomputeAndNotifyBookingQuery: 开始推送', {
9728
10166
  subscriberCount: this.bookingQuerySubscribers.size
9729
10167
  });
9730
10168
  _iterator21 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
9731
- _context88.prev = 4;
10169
+ _context92.prev = 4;
9732
10170
  _iterator21.s();
9733
10171
  case 6:
9734
10172
  if ((_step21 = _iterator21.n()).done) {
9735
- _context88.next = 22;
10173
+ _context92.next = 22;
9736
10174
  break;
9737
10175
  }
9738
10176
  _step21$value = _slicedToArray(_step21.value, 2), subscriberId = _step21$value[0], subscriber = _step21$value[1];
9739
- _context88.prev = 8;
9740
- _context88.next = 11;
10177
+ _context92.prev = 8;
10178
+ _context92.next = 11;
9741
10179
  return this.computeBookingQueryResult(subscriber.context);
9742
10180
  case 11:
9743
- result = _context88.sent;
10181
+ result = _context92.sent;
9744
10182
  subscriber.callback(result);
9745
10183
  this.logInfo('recomputeAndNotifyBookingQuery: 已推送', {
9746
10184
  subscriberId: subscriberId
9747
10185
  });
9748
- _context88.next = 20;
10186
+ _context92.next = 20;
9749
10187
  break;
9750
10188
  case 16:
9751
- _context88.prev = 16;
9752
- _context88.t0 = _context88["catch"](8);
9753
- errorMessage = _context88.t0 instanceof Error ? _context88.t0.message : String(_context88.t0);
10189
+ _context92.prev = 16;
10190
+ _context92.t0 = _context92["catch"](8);
10191
+ errorMessage = _context92.t0 instanceof Error ? _context92.t0.message : String(_context92.t0);
9754
10192
  this.logError('recomputeAndNotifyBookingQuery: 推送失败', {
9755
10193
  subscriberId: subscriberId,
9756
10194
  error: errorMessage
9757
10195
  });
9758
10196
  case 20:
9759
- _context88.next = 6;
10197
+ _context92.next = 6;
9760
10198
  break;
9761
10199
  case 22:
9762
- _context88.next = 27;
10200
+ _context92.next = 27;
9763
10201
  break;
9764
10202
  case 24:
9765
- _context88.prev = 24;
9766
- _context88.t1 = _context88["catch"](4);
9767
- _iterator21.e(_context88.t1);
10203
+ _context92.prev = 24;
10204
+ _context92.t1 = _context92["catch"](4);
10205
+ _iterator21.e(_context92.t1);
9768
10206
  case 27:
9769
- _context88.prev = 27;
10207
+ _context92.prev = 27;
9770
10208
  _iterator21.f();
9771
- return _context88.finish(27);
10209
+ return _context92.finish(27);
9772
10210
  case 30:
9773
10211
  case "end":
9774
- return _context88.stop();
10212
+ return _context92.stop();
9775
10213
  }
9776
- }, _callee88, this, [[4, 24, 27, 30], [8, 16]]);
10214
+ }, _callee92, this, [[4, 24, 27, 30], [8, 16]]);
9777
10215
  }));
9778
10216
  function recomputeAndNotifyBookingQuery() {
9779
10217
  return _recomputeAndNotifyBookingQuery.apply(this, arguments);