@pisell/pisellos 2.3.68 → 2.3.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/core/index.d.ts +7 -0
  2. package/dist/core/index.js +109 -65
  3. package/dist/modules/Quotation/index.d.ts +6 -0
  4. package/dist/modules/Quotation/index.js +75 -19
  5. package/dist/plugins/request.d.ts +1 -0
  6. package/dist/server/index.d.ts +8 -2
  7. package/dist/server/index.js +206 -140
  8. package/dist/server/modules/floor-plan/index.d.ts +4 -0
  9. package/dist/server/modules/floor-plan/index.js +240 -98
  10. package/dist/server/modules/menu/index.js +48 -23
  11. package/dist/server/modules/order/index.d.ts +17 -7
  12. package/dist/server/modules/order/index.js +419 -207
  13. package/dist/server/modules/products/index.d.ts +8 -2
  14. package/dist/server/modules/products/index.js +167 -75
  15. package/dist/server/modules/resource/index.js +21 -13
  16. package/dist/solution/BaseSales/index.d.ts +10 -0
  17. package/dist/solution/BaseSales/index.js +861 -806
  18. package/dist/solution/BookingTicket/index.d.ts +3 -1
  19. package/dist/solution/BookingTicket/index.js +187 -149
  20. package/lib/core/index.d.ts +7 -0
  21. package/lib/core/index.js +20 -2
  22. package/lib/modules/Quotation/index.d.ts +6 -0
  23. package/lib/modules/Quotation/index.js +49 -5
  24. package/lib/plugins/request.d.ts +1 -0
  25. package/lib/server/index.d.ts +8 -2
  26. package/lib/server/index.js +52 -17
  27. package/lib/server/modules/floor-plan/index.d.ts +4 -0
  28. package/lib/server/modules/floor-plan/index.js +54 -6
  29. package/lib/server/modules/menu/index.js +31 -5
  30. package/lib/server/modules/order/index.d.ts +17 -7
  31. package/lib/server/modules/order/index.js +197 -40
  32. package/lib/server/modules/products/index.d.ts +8 -2
  33. package/lib/server/modules/products/index.js +97 -24
  34. package/lib/server/modules/resource/index.js +7 -2
  35. package/lib/solution/BaseSales/index.d.ts +10 -0
  36. package/lib/solution/BaseSales/index.js +32 -2
  37. package/lib/solution/BookingTicket/index.d.ts +3 -1
  38. package/lib/solution/BookingTicket/index.js +12 -0
  39. package/package.json +1 -1
@@ -43,6 +43,7 @@ import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPending
43
43
  var INDEXDB_STORE_NAME = 'orders';
44
44
  var ORDER_STORAGE_KEY_FIELD = '__order_storage_key';
45
45
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
46
+ var ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY = 'server_order_last_full_fetch_shop_id';
46
47
  var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
47
48
  var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
48
49
  /** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
@@ -308,18 +309,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
308
309
  }, {
309
310
  key: "normalizeOrderCollectionsForIngress",
310
311
  value: function normalizeOrderCollectionsForIngress(order, source) {
311
- var sourceOrder = cloneDeep(order);
312
- var sourceOrderRecord = sourceOrder;
312
+ var sourceOrderRecord = order;
313
+ var sourceOrder = sourceOrderRecord;
313
314
  if (Array.isArray(sourceOrderRecord.payments)) {
314
- sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
315
- if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
316
- return key.startsWith('unique_payment_number:');
317
- })) {
318
- return payment;
319
- }
320
- return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
315
+ sourceOrder = _objectSpread(_objectSpread({}, sourceOrderRecord), {}, {
316
+ payments: sourceOrderRecord.payments.map(function (payment) {
317
+ if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
318
+ return key.startsWith('unique_payment_number:');
319
+ })) {
320
+ return payment;
321
+ }
322
+ return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
323
+ })
321
324
  });
322
325
  }
326
+
327
+ // normalizeOrderCollections 内部已经 cloneDeep;这里只浅复制被改写的 payments,
328
+ // 既不修改调用方对象,也避免对整笔订单重复深拷贝。
323
329
  var result = normalizeOrderCollections(sourceOrder);
324
330
  var normalizedOrderRecord = result.order;
325
331
  if (Array.isArray(normalizedOrderRecord.payments)) {
@@ -700,26 +706,96 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
700
706
  key: "preload",
701
707
  value: function () {
702
708
  var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
703
- var orders;
709
+ var preloadStartedAt, cachedOrders, sqliteLoadTimings, memoryPrepareStartedAt, memoryOrders, memoryPrepareMs, syncMapStartedAt, syncMapMs, onOrdersLoadedStartedAt, onOrdersLoadedMs, emitOrdersChangedStartedAt, emitOrdersChangedMs, orders;
704
710
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
705
711
  while (1) switch (_context4.prev = _context4.next) {
706
712
  case 0:
707
- _context4.next = 2;
708
- return this.loadOrdersByServer();
709
- case 2:
713
+ preloadStartedAt = Date.now();
714
+ cachedOrders = null;
715
+ if (!this.dbManager) {
716
+ _context4.next = 12;
717
+ break;
718
+ }
719
+ _context4.prev = 3;
720
+ _context4.next = 6;
721
+ return this.loadOrdersFromSQLite({
722
+ throwOnError: true,
723
+ onTiming: function onTiming(timings) {
724
+ sqliteLoadTimings = timings;
725
+ }
726
+ });
727
+ case 6:
728
+ cachedOrders = _context4.sent;
729
+ _context4.next = 12;
730
+ break;
731
+ case 9:
732
+ _context4.prev = 9;
733
+ _context4.t0 = _context4["catch"](3);
734
+ this.logWarning('preload-SQLite读取失败,回退远端全量拉取', {
735
+ error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
736
+ });
737
+ case 12:
738
+ if (!(cachedOrders !== null && this.hasPulledOrdersToday())) {
739
+ _context4.next = 30;
740
+ break;
741
+ }
742
+ memoryPrepareStartedAt = performance.now();
743
+ memoryOrders = this.prepareNormalizedOrdersForMemoryList(cachedOrders);
744
+ memoryPrepareMs = +(performance.now() - memoryPrepareStartedAt).toFixed(2); // loadOrdersFromSQLite 已返回独立且完成集合规范化的新对象;直接进入 store,
745
+ // 不再进行第二轮 normalize 和没有隔离收益的最终 cloneDeep。
746
+ this.store.list = memoryOrders;
747
+ syncMapStartedAt = performance.now();
748
+ this.syncOrdersMap();
749
+ syncMapMs = +(performance.now() - syncMapStartedAt).toFixed(2);
750
+ onOrdersLoadedStartedAt = performance.now();
751
+ _context4.next = 23;
752
+ return this.core.effects.emit(OrderHooks.onOrdersLoaded, this.store.list);
753
+ case 23:
754
+ onOrdersLoadedMs = +(performance.now() - onOrdersLoadedStartedAt).toFixed(2);
755
+ emitOrdersChangedStartedAt = performance.now();
756
+ _context4.next = 27;
757
+ return this.emitOrdersChanged([], 'preload.sqlite');
758
+ case 27:
759
+ emitOrdersChangedMs = +(performance.now() - emitOrdersChangedStartedAt).toFixed(2);
760
+ this.logInfo('预加载完成', {
761
+ trigger: 'preload',
762
+ source: 'SQLite',
763
+ orderCount: this.store.list.length,
764
+ duration: "".concat(Date.now() - preloadStartedAt, "ms"),
765
+ stages: _objectSpread(_objectSpread({}, sqliteLoadTimings || {}), {}, {
766
+ memoryPrepareMs: memoryPrepareMs,
767
+ syncMapMs: syncMapMs,
768
+ onOrdersLoadedMs: onOrdersLoadedMs,
769
+ emitOrdersChangedMs: emitOrdersChangedMs
770
+ })
771
+ });
772
+ return _context4.abrupt("return");
773
+ case 30:
774
+ _context4.next = 32;
775
+ return this.loadOrdersByServer({
776
+ trigger: 'preload'
777
+ });
778
+ case 32:
710
779
  orders = _context4.sent;
711
780
  this.store.list = cloneDeep(orders);
712
781
  this.syncOrdersMap();
713
- _context4.next = 7;
782
+ _context4.next = 37;
714
783
  return this.emitOrdersChanged([], 'preload');
715
- case 7:
716
- _context4.next = 9;
784
+ case 37:
785
+ _context4.next = 39;
717
786
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
718
- case 9:
787
+ case 39:
788
+ this.logInfo('预加载完成', {
789
+ trigger: 'preload',
790
+ source: 'Server',
791
+ orderCount: this.store.list.length,
792
+ duration: "".concat(Date.now() - preloadStartedAt, "ms")
793
+ });
794
+ case 40:
719
795
  case "end":
720
796
  return _context4.stop();
721
797
  }
722
- }, _callee4, this);
798
+ }, _callee4, this, [[3, 9]]);
723
799
  }));
724
800
  function preload() {
725
801
  return _preload.apply(this, arguments);
@@ -1052,18 +1128,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1052
1128
  var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1053
1129
  var _this5 = this,
1054
1130
  _this$store;
1055
- var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
1131
+ var options,
1132
+ orderList,
1133
+ hasFetchedRemoteSnapshot,
1134
+ trigger,
1135
+ protectedOrdersBeforeRemoteFetch,
1136
+ data,
1137
+ _yield$this$replaceOr,
1138
+ mergedOrders,
1139
+ isRemoteSnapshotPersisted,
1140
+ memoryOrders,
1141
+ _args8 = arguments;
1056
1142
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1057
1143
  while (1) switch (_context8.prev = _context8.next) {
1058
1144
  case 0:
1145
+ options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1059
1146
  orderList = [];
1060
- _context8.next = 3;
1147
+ hasFetchedRemoteSnapshot = false;
1148
+ trigger = options.trigger || 'unknown';
1149
+ _context8.next = 6;
1061
1150
  return this.loadOrdersFromSQLite();
1062
- case 3:
1151
+ case 6:
1063
1152
  protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1064
1153
  return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1065
1154
  });
1066
1155
  this.logInfo('loadOrdersByServer-开始', {
1156
+ trigger: trigger,
1067
1157
  hasOrderDataSource: !!this.orderDataSource,
1068
1158
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1069
1159
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
@@ -1072,51 +1162,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1072
1162
  }, 0)
1073
1163
  });
1074
1164
  if (!this.orderDataSource) {
1075
- _context8.next = 20;
1165
+ _context8.next = 23;
1076
1166
  break;
1077
1167
  }
1078
- _context8.prev = 6;
1079
- _context8.next = 9;
1168
+ _context8.prev = 9;
1169
+ _context8.next = 12;
1080
1170
  return this.orderDataSource.run({
1081
1171
  sse: {
1082
1172
  query: this.store.createdAtQuery
1083
1173
  }
1084
1174
  });
1085
- case 9:
1175
+ case 12:
1086
1176
  data = _context8.sent;
1087
1177
  orderList = data || [];
1088
1178
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1179
+ trigger: trigger,
1089
1180
  count: orderList.length
1090
1181
  });
1091
- this.markOrderPulledAtNow();
1182
+ hasFetchedRemoteSnapshot = true;
1092
1183
  this.lastServerFullFetchAtMs = Date.now();
1093
- _context8.next = 20;
1184
+ _context8.next = 23;
1094
1185
  break;
1095
- case 16:
1096
- _context8.prev = 16;
1097
- _context8.t0 = _context8["catch"](6);
1186
+ case 19:
1187
+ _context8.prev = 19;
1188
+ _context8.t0 = _context8["catch"](9);
1098
1189
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1099
1190
  return _context8.abrupt("return", this.store.list);
1100
- case 20:
1101
- _context8.next = 22;
1191
+ case 23:
1192
+ if (hasFetchedRemoteSnapshot) {
1193
+ this.clearOrderSnapshotMarker();
1194
+ }
1195
+ _context8.next = 26;
1102
1196
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1103
- case 22:
1104
- mergedOrders = _context8.sent;
1197
+ case 26:
1198
+ _yield$this$replaceOr = _context8.sent;
1199
+ mergedOrders = _yield$this$replaceOr.orders;
1200
+ isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1201
+ if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
1202
+ this.markOrderPulledAtNow();
1203
+ }
1105
1204
  memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
1106
1205
  this.logInfo('loadOrdersByServer-结束', {
1206
+ trigger: trigger,
1107
1207
  count: memoryOrders.length,
1108
1208
  persistedCount: mergedOrders.length,
1109
1209
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1110
1210
  });
1111
- _context8.next = 27;
1211
+ _context8.next = 34;
1112
1212
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1113
- case 27:
1213
+ case 34:
1114
1214
  return _context8.abrupt("return", memoryOrders);
1115
- case 28:
1215
+ case 35:
1116
1216
  case "end":
1117
1217
  return _context8.stop();
1118
1218
  }
1119
- }, _callee8, this, [[6, 16]]);
1219
+ }, _callee8, this, [[9, 19]]);
1120
1220
  }));
1121
1221
  function loadOrdersByServer() {
1122
1222
  return _loadOrdersByServer.apply(this, arguments);
@@ -1132,53 +1232,76 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1132
1232
  key: "silentRefresh",
1133
1233
  value: (function () {
1134
1234
  var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1135
- var startTime, elapsedSinceFullFetch, orders, errorMessage;
1235
+ var options,
1236
+ startTime,
1237
+ trigger,
1238
+ elapsedSinceFullFetch,
1239
+ orders,
1240
+ errorMessage,
1241
+ _args9 = arguments;
1136
1242
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1137
1243
  while (1) switch (_context9.prev = _context9.next) {
1138
1244
  case 0:
1245
+ options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1139
1246
  startTime = Date.now();
1247
+ trigger = options.trigger || 'background';
1140
1248
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1141
1249
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1142
- _context9.next = 4;
1250
+ _context9.next = 7;
1143
1251
  break;
1144
1252
  }
1253
+ this.logInfo('silentRefresh 跳过全量 SSE', {
1254
+ trigger: trigger,
1255
+ reason: 'within_min_interval',
1256
+ minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
1257
+ elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1258
+ orderCount: this.store.list.length
1259
+ });
1145
1260
  return _context9.abrupt("return", this.store.list);
1146
- case 4:
1147
- this.logInfo('silentRefresh 开始');
1148
- _context9.prev = 5;
1261
+ case 7:
1262
+ this.logInfo('silentRefresh 开始', {
1263
+ trigger: trigger,
1264
+ elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1265
+ orderCount: this.store.list.length
1266
+ });
1267
+ _context9.prev = 8;
1149
1268
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1150
1269
  this.updateCreateStore();
1151
- _context9.next = 9;
1152
- return this.loadOrdersByServer();
1153
- case 9:
1270
+ _context9.next = 12;
1271
+ return this.loadOrdersByServer({
1272
+ trigger: trigger
1273
+ });
1274
+ case 12:
1154
1275
  orders = _context9.sent;
1155
1276
  this.store.list = cloneDeep(orders);
1156
1277
  this.syncOrdersMap();
1157
- _context9.next = 14;
1278
+ _context9.next = 17;
1158
1279
  return this.emitOrdersChanged([], 'silentRefresh');
1159
- case 14:
1160
- _context9.next = 16;
1280
+ case 17:
1281
+ _context9.next = 19;
1161
1282
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1162
- case 16:
1283
+ case 19:
1163
1284
  this.logInfo('silentRefresh 完成', {
1285
+ trigger: trigger,
1164
1286
  orderCount: orders.length,
1165
1287
  duration: "".concat(Date.now() - startTime, "ms")
1166
1288
  });
1167
1289
  return _context9.abrupt("return", this.store.list);
1168
- case 20:
1169
- _context9.prev = 20;
1170
- _context9.t0 = _context9["catch"](5);
1290
+ case 23:
1291
+ _context9.prev = 23;
1292
+ _context9.t0 = _context9["catch"](8);
1171
1293
  errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1172
1294
  this.logError('silentRefresh 失败', {
1295
+ trigger: trigger,
1173
1296
  duration: "".concat(Date.now() - startTime, "ms"),
1174
1297
  error: errorMessage
1175
1298
  });
1176
1299
  return _context9.abrupt("return", this.store.list);
1177
- case 25:
1300
+ case 28:
1178
1301
  case "end":
1179
1302
  return _context9.stop();
1180
1303
  }
1181
- }, _callee9, this, [[5, 20]]);
1304
+ }, _callee9, this, [[8, 23]]);
1182
1305
  }));
1183
1306
  function silentRefresh() {
1184
1307
  return _silentRefresh.apply(this, arguments);
@@ -1190,6 +1313,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1190
1313
  value: function normalizeOrderForMemoryList(order) {
1191
1314
  var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
1192
1315
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
1316
+ return this.prepareNormalizedOrderForMemoryList(normalizedOrder);
1317
+ }
1318
+
1319
+ /**
1320
+ * 将已经完成集合规范化的订单转换为内存身份,不重复扫描 products/bookings/payments。
1321
+ */
1322
+ }, {
1323
+ key: "prepareNormalizedOrderForMemoryList",
1324
+ value: function prepareNormalizedOrderForMemoryList(normalizedOrder) {
1193
1325
  var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
1194
1326
  if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
1195
1327
  return normalizedOrder;
@@ -1205,15 +1337,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1205
1337
  });
1206
1338
  }
1207
1339
  }, {
1208
- key: "normalizeOrdersForMemoryList",
1209
- value: function normalizeOrdersForMemoryList(orders, source) {
1340
+ key: "prepareNormalizedOrdersForMemoryList",
1341
+ value: function prepareNormalizedOrdersForMemoryList(orders) {
1210
1342
  var _this6 = this;
1211
1343
  return orders.map(function (order) {
1212
- return _this6.normalizeOrderForMemoryList(order, source);
1344
+ return _this6.prepareNormalizedOrderForMemoryList(order);
1213
1345
  }).filter(function (order) {
1214
1346
  return _this6.shouldKeepOrderInMemory(order);
1215
1347
  });
1216
1348
  }
1349
+ }, {
1350
+ key: "normalizeOrdersForMemoryList",
1351
+ value: function normalizeOrdersForMemoryList(orders, source) {
1352
+ var _this7 = this;
1353
+ return orders.map(function (order) {
1354
+ return _this7.normalizeOrderForMemoryList(order, source);
1355
+ }).filter(function (order) {
1356
+ return _this7.shouldKeepOrderInMemory(order);
1357
+ });
1358
+ }
1217
1359
  }, {
1218
1360
  key: "hasRealOrderId",
1219
1361
  value: function hasRealOrderId(order) {
@@ -1246,7 +1388,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1246
1388
  key: "overwriteExistingOrder",
1247
1389
  value: (function () {
1248
1390
  var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1249
- var _this7 = this;
1391
+ var _this8 = this;
1250
1392
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1251
1393
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1252
1394
  while (1) switch (_context10.prev = _context10.next) {
@@ -1283,9 +1425,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1283
1425
  this.store.list = this.store.list.map(function (order) {
1284
1426
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1285
1427
  if (id === undefined || id === null) {
1286
- return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1428
+ return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1287
1429
  }
1288
- return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1430
+ return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1289
1431
  });
1290
1432
  this.syncOrdersMap();
1291
1433
  _context10.next = 16;
@@ -1357,7 +1499,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1357
1499
  key: "markOrderSyncedByExternalSaleNumber",
1358
1500
  value: function () {
1359
1501
  var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1360
- var _this8 = this,
1502
+ var _this9 = this,
1361
1503
  _existing$external_sa,
1362
1504
  _nextOrder$order_id;
1363
1505
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
@@ -1378,7 +1520,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1378
1520
  targetIndex = this.store.list.findIndex(function (order) {
1379
1521
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1380
1522
  if (value === undefined || value === null || value === '') return false;
1381
- return _this8.getIdKey(value) === key;
1523
+ return _this9.getIdKey(value) === key;
1382
1524
  });
1383
1525
  if (!(targetIndex < 0)) {
1384
1526
  _context12.next = 9;
@@ -1436,7 +1578,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1436
1578
  key: "upsertPendingSyncOrders",
1437
1579
  value: (function () {
1438
1580
  var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
1439
- var _this9 = this;
1581
+ var _this10 = this;
1440
1582
  var options,
1441
1583
  pendingMap,
1442
1584
  memoryPendingMap,
@@ -1532,7 +1674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1532
1674
  });
1533
1675
  mergeActions = {};
1534
1676
  updatedList = this.store.list.map(function (order) {
1535
- return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1677
+ return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1536
1678
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1537
1679
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1538
1680
  identityKeyToIndex = new Map();
@@ -1642,7 +1784,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1642
1784
  key: "upsertLocalDraftOrders",
1643
1785
  value: (function () {
1644
1786
  var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
1645
- var _this10 = this;
1787
+ var _this11 = this;
1646
1788
  var draftMap, memoryDraftMap, _iterator9, _step9, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator10, _step10, key, _iterator11, _step11, _step11$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1647
1789
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1648
1790
  while (1) switch (_context14.prev = _context14.next) {
@@ -1712,7 +1854,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1712
1854
  });
1713
1855
  mergeActions = {};
1714
1856
  updatedList = this.store.list.filter(function (order) {
1715
- return _this10.shouldKeepOrderInMemory(order);
1857
+ return _this11.shouldKeepOrderInMemory(order);
1716
1858
  });
1717
1859
  identityKeyToIndex = new Map();
1718
1860
  for (index = 0; index < updatedList.length; index += 1) {
@@ -1799,7 +1941,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1799
1941
  storeOrderCountAfter: this.store.list.length
1800
1942
  });
1801
1943
  removedLegacyMemoryDraft = previousList.some(function (order) {
1802
- return !_this10.shouldKeepOrderInMemory(order);
1944
+ return !_this11.shouldKeepOrderInMemory(order);
1803
1945
  });
1804
1946
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1805
1947
  _context14.next = 84;
@@ -1807,7 +1949,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1807
1949
  }
1808
1950
  _context14.next = 84;
1809
1951
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1810
- return _this10.shouldKeepOrderInMemory(order);
1952
+ return _this11.shouldKeepOrderInMemory(order);
1811
1953
  }), 'upsertLocalDraftOrders');
1812
1954
  case 84:
1813
1955
  case "end":
@@ -1890,9 +2032,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1890
2032
  }, {
1891
2033
  key: "syncOrdersMap",
1892
2034
  value: function syncOrdersMap() {
1893
- var _this11 = this;
2035
+ var _this12 = this;
1894
2036
  this.store.list = this.store.list.filter(function (order) {
1895
- return _this11.shouldKeepOrderInMemory(order);
2037
+ return _this12.shouldKeepOrderInMemory(order);
1896
2038
  });
1897
2039
  this.store.map.clear();
1898
2040
  var _iterator12 = _createForOfIteratorHelper(this.store.list),
@@ -1948,7 +2090,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1948
2090
  }, {
1949
2091
  key: "getOrderIdentityEntries",
1950
2092
  value: function getOrderIdentityEntries(order) {
1951
- var _this12 = this;
2093
+ var _this13 = this;
1952
2094
  if (!order) return [];
1953
2095
  var record = order;
1954
2096
  var candidates = [{
@@ -1967,8 +2109,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1967
2109
  var entries = [];
1968
2110
  var _loop = function _loop() {
1969
2111
  var candidate = _candidates[_i2];
1970
- if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
1971
- var key = _this12.getIdKey(candidate.value);
2112
+ if (_this13.isBlankIdentityValue(candidate.value)) return 0; // continue
2113
+ var key = _this13.getIdKey(candidate.value);
1972
2114
  if (entries.some(function (entry) {
1973
2115
  return entry.field === candidate.field && entry.key === key;
1974
2116
  })) return 0; // continue
@@ -2035,7 +2177,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2035
2177
  }, {
2036
2178
  key: "setupOrderSync",
2037
2179
  value: function setupOrderSync() {
2038
- var _this13 = this;
2180
+ var _this14 = this;
2039
2181
  if (!this.orderDataSource) return;
2040
2182
  this.orderDataSource.run({
2041
2183
  pubsub: {
@@ -2043,22 +2185,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2043
2185
  var _message$id, _message$order_id, _message$type;
2044
2186
  console.log('orderDataSource', res);
2045
2187
  var pubsubReceivedAt = Date.now();
2046
- var message = _this13.normalizeOrderSyncMessage(res);
2188
+ var message = _this14.normalizeOrderSyncMessage(res);
2047
2189
  if (!message) return;
2048
2190
  message._pubsubReceivedAt = pubsubReceivedAt;
2049
- _this13.pendingSyncMessages.push(message);
2050
- var throttleMs = _this13.getOrderSyncThrottleMs();
2051
- var routeInfo = _this13.resolveSyncMessageRoute(message);
2052
- _this13.logInfo('orderSync-收到消息并入队', {
2191
+ _this14.pendingSyncMessages.push(message);
2192
+ var throttleMs = _this14.getOrderSyncThrottleMs();
2193
+ var routeInfo = _this14.resolveSyncMessageRoute(message);
2194
+ _this14.logInfo('orderSync-收到消息并入队', {
2053
2195
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2054
2196
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2055
2197
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2056
- pendingCount: _this13.pendingSyncMessages.length,
2198
+ pendingCount: _this14.pendingSyncMessages.length,
2057
2199
  throttleMs: throttleMs,
2058
2200
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2059
2201
  fullMessage: JSON.stringify(message)
2060
2202
  });
2061
- _this13.scheduleOrderSyncThrottle();
2203
+ _this14.scheduleOrderSyncThrottle();
2062
2204
  }
2063
2205
  }
2064
2206
  }).catch(function () {
@@ -2075,7 +2217,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2075
2217
  }, {
2076
2218
  key: "scheduleOrderSyncThrottle",
2077
2219
  value: function scheduleOrderSyncThrottle() {
2078
- var _this14 = this;
2220
+ var _this15 = this;
2079
2221
  if (this.isProcessingSyncBatch) return;
2080
2222
  if (this.isIdlePhase) {
2081
2223
  this.isIdlePhase = false;
@@ -2086,8 +2228,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2086
2228
  if (this.syncTimer) return;
2087
2229
  var throttleMs = this.getOrderSyncThrottleMs();
2088
2230
  this.syncTimer = setTimeout(function () {
2089
- _this14.syncTimer = undefined;
2090
- void _this14.flushOrderSyncMessagesByThrottle();
2231
+ _this15.syncTimer = undefined;
2232
+ void _this15.flushOrderSyncMessagesByThrottle();
2091
2233
  }, throttleMs);
2092
2234
  }
2093
2235
 
@@ -2155,7 +2297,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2155
2297
  key: "processOrderSyncMessages",
2156
2298
  value: (function () {
2157
2299
  var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2158
- var _this15 = this;
2300
+ var _this16 = this;
2159
2301
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2160
2302
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2161
2303
  while (1) switch (_context17.prev = _context17.next) {
@@ -2182,13 +2324,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2182
2324
  upsertOrders = new Map();
2183
2325
  refreshIds = [];
2184
2326
  messages.forEach(function (msg, msgIndex) {
2185
- var routeInfo = _this15.resolveSyncMessageRoute(msg);
2327
+ var routeInfo = _this16.resolveSyncMessageRoute(msg);
2186
2328
  var hasBatchIds = routeInfo.hasBatchIds;
2187
2329
  var singleId = routeInfo.singleId;
2188
2330
  var hasSingleId = routeInfo.hasSingleId;
2189
- var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
2331
+ var normalizedBody = _this16.normalizeOrderSyncPayload(msg.body || msg.data);
2190
2332
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2191
- upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
2333
+ upsertOrders.set(_this16.getIdKey(normalizedBody.order_id), normalizedBody);
2192
2334
  return;
2193
2335
  }
2194
2336
  if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
@@ -2326,7 +2468,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2326
2468
  key: "mergeOrdersToStore",
2327
2469
  value: (function () {
2328
2470
  var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2329
- var _this16 = this;
2471
+ var _this17 = this;
2330
2472
  var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator17, _step17, _key2, _duplicateIndex, _iterator18, _step18, duplicateIndex, _index, _iterator19, _step19, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2331
2473
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2332
2474
  while (1) switch (_context19.prev = _context19.next) {
@@ -2387,10 +2529,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2387
2529
  storageKeyMigrations = [];
2388
2530
  mergeActions = {};
2389
2531
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2390
- return _this16.doProductsHaveStableMembershipIdentity(order.products);
2532
+ return _this17.doProductsHaveStableMembershipIdentity(order.products);
2391
2533
  });
2392
2534
  updatedList = this.store.list.map(function (order) {
2393
- return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2535
+ return _this17.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2394
2536
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2395
2537
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2396
2538
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
@@ -2694,7 +2836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2694
2836
  }, {
2695
2837
  key: "getRemoteProductMembershipChange",
2696
2838
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2697
- var _this17 = this,
2839
+ var _this18 = this,
2698
2840
  _mergedOrder$order_id2;
2699
2841
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
2700
2842
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
@@ -2709,13 +2851,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2709
2851
  var _loop2 = function _loop2() {
2710
2852
  var previousProduct = _step21.value;
2711
2853
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2712
- return unmatchedCurrentIndexes.has(index) && _this17.isSameProductMembershipItem(previousProduct, currentProduct);
2854
+ return unmatchedCurrentIndexes.has(index) && _this18.isSameProductMembershipItem(previousProduct, currentProduct);
2713
2855
  });
2714
2856
  if (matchedIndex >= 0) {
2715
2857
  unmatchedCurrentIndexes.delete(matchedIndex);
2716
2858
  return 1; // continue
2717
2859
  }
2718
- var productKey = _this17.getProductMembershipKey(previousProduct);
2860
+ var productKey = _this18.getProductMembershipKey(previousProduct);
2719
2861
  if (productKey) removedProductKeys.push(productKey);
2720
2862
  };
2721
2863
  for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
@@ -2727,7 +2869,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2727
2869
  _iterator21.f();
2728
2870
  }
2729
2871
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2730
- return _this17.getProductMembershipKey(currentProducts[index]);
2872
+ return _this18.getProductMembershipKey(currentProducts[index]);
2731
2873
  }).filter(Boolean);
2732
2874
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2733
2875
  return null;
@@ -2842,12 +2984,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2842
2984
  }, {
2843
2985
  key: "isOrderLookupMatch",
2844
2986
  value: function isOrderLookupMatch(order, lookupKey) {
2845
- var _this18 = this;
2987
+ var _this19 = this;
2846
2988
  if (!order || !lookupKey) return false;
2847
2989
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
2848
2990
  return candidates.some(function (value) {
2849
2991
  if (value === undefined || value === null || value === '') return false;
2850
- return _this18.getIdKey(value) === lookupKey;
2992
+ return _this19.getIdKey(value) === lookupKey;
2851
2993
  });
2852
2994
  }
2853
2995
 
@@ -2899,10 +3041,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2899
3041
  }, {
2900
3042
  key: "findOrderIndexByIdentity",
2901
3043
  value: function findOrderIndexByIdentity(orders, target) {
2902
- var _this19 = this;
3044
+ var _this20 = this;
2903
3045
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
2904
3046
  return orders.findIndex(function (order) {
2905
- return _this19.doOrdersShareIdentity(order, target);
3047
+ return _this20.doOrdersShareIdentity(order, target);
2906
3048
  });
2907
3049
  }
2908
3050
  }, {
@@ -3214,25 +3356,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3214
3356
  }
3215
3357
 
3216
3358
  /**
3217
- * 当前订单拉取窗口:
3218
- * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
3219
- * - 无法解析时退化为自然日窗口
3359
+ * 当前订单缓存可复用窗口。
3360
+ * start_time 模式使用精确的营业日起止时间;配置缺失或异常时退化为自然日。
3220
3361
  */
3221
3362
  }, {
3222
- key: "getCurrentPullWindow",
3223
- value: function getCurrentPullWindow() {
3224
- var _this$store2;
3363
+ key: "getCurrentOrderCacheWindow",
3364
+ value: function getCurrentOrderCacheWindow() {
3225
3365
  var now = dayjs();
3226
- var range = (_this$store2 = this.store) === null || _this$store2 === void 0 || (_this$store2 = _this$store2.createdAtQuery) === null || _this$store2 === void 0 ? void 0 : _this$store2.sales_time_between;
3227
- if (Array.isArray(range) && range.length >= 2) {
3228
- var _startAt = dayjs(range[0]);
3229
- var endExclusiveAt = dayjs(range[1]);
3230
- if (_startAt.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(_startAt)) {
3231
- return {
3232
- startAt: _startAt,
3233
- endExclusiveAt: endExclusiveAt
3234
- };
3366
+ try {
3367
+ var _coreData$core;
3368
+ var appPlugin = this.core.getPlugin('app');
3369
+ var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3370
+ var coreData = app === null || app === void 0 ? void 0 : app.data.store.getStore().getDataByModel('core');
3371
+ var boundary = coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.operating_day_boundary;
3372
+ if ((boundary === null || boundary === void 0 ? void 0 : boundary.type) === 'start_time') {
3373
+ var boundaryTime = String(boundary.time || '').trim();
3374
+ var todayBoundary = dayjs("".concat(now.format('YYYY-MM-DD'), " ").concat(boundaryTime));
3375
+ if (todayBoundary.isValid()) {
3376
+ var _startAt = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, 'day') : todayBoundary;
3377
+ return {
3378
+ startAt: _startAt,
3379
+ endExclusiveAt: _startAt.add(1, 'day')
3380
+ };
3381
+ }
3235
3382
  }
3383
+ } catch (_unused6) {
3384
+ // 读取营业日配置失败时按自然日兜底,不影响启动。
3236
3385
  }
3237
3386
  var startAt = now.startOf('day');
3238
3387
  return {
@@ -3245,20 +3394,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3245
3394
  value: function hasPulledOrdersToday() {
3246
3395
  var lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
3247
3396
  if (!lastFullFetchAt) return false;
3397
+ var currentShopId = this.getCurrentShopId();
3398
+ var lastFullFetchShopId = this.getStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY);
3399
+ if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
3400
+ return false;
3401
+ }
3248
3402
  var parsed = dayjs(lastFullFetchAt);
3249
3403
  if (!parsed.isValid()) return false;
3250
-
3251
- // 按当前拉取窗口判断,而不是自然日判断。
3252
- // 这样在营业日跨日边界(start_time)场景下也能正确判定是否需要重新拉取。
3253
- var _this$getCurrentPullW = this.getCurrentPullWindow(),
3254
- startAt = _this$getCurrentPullW.startAt,
3255
- endExclusiveAt = _this$getCurrentPullW.endExclusiveAt;
3404
+ var _this$getCurrentOrder = this.getCurrentOrderCacheWindow(),
3405
+ startAt = _this$getCurrentOrder.startAt,
3406
+ endExclusiveAt = _this$getCurrentOrder.endExclusiveAt;
3256
3407
  return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
3257
3408
  }
3258
3409
  }, {
3259
3410
  key: "markOrderPulledAtNow",
3260
3411
  value: function markOrderPulledAtNow() {
3412
+ var currentShopId = this.getCurrentShopId();
3413
+ if (!currentShopId) return;
3261
3414
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, dayjs().format('YYYY-MM-DD HH:mm:ss'));
3415
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, currentShopId);
3416
+ }
3417
+ }, {
3418
+ key: "clearOrderSnapshotMarker",
3419
+ value: function clearOrderSnapshotMarker() {
3420
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
3421
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, '');
3422
+ }
3423
+ }, {
3424
+ key: "getCurrentShopId",
3425
+ value: function getCurrentShopId() {
3426
+ try {
3427
+ var _coreData$core2;
3428
+ var appPlugin = this.core.getPlugin('app');
3429
+ var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3430
+ if (!app) return null;
3431
+ var coreData = app.data.store.getStore().getDataByModel('core');
3432
+ var shopId = coreData === null || coreData === void 0 || (_coreData$core2 = coreData.core) === null || _coreData$core2 === void 0 ? void 0 : _coreData$core2.id;
3433
+ if (shopId === undefined || shopId === null || shopId === '') return null;
3434
+ return String(shopId);
3435
+ } catch (_unused7) {
3436
+ return null;
3437
+ }
3262
3438
  }
3263
3439
  }, {
3264
3440
  key: "getStorageItem",
@@ -3269,7 +3445,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3269
3445
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3270
3446
  return globalThis.localStorage.getItem(key);
3271
3447
  }
3272
- } catch (_unused6) {
3448
+ } catch (_unused8) {
3273
3449
  // 忽略存储异常,避免影响主流程
3274
3450
  }
3275
3451
  return null;
@@ -3286,7 +3462,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3286
3462
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3287
3463
  globalThis.localStorage.setItem(key, value);
3288
3464
  }
3289
- } catch (_unused7) {
3465
+ } catch (_unused9) {
3290
3466
  // 忽略存储异常,避免影响主流程
3291
3467
  }
3292
3468
  }
@@ -3294,34 +3470,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3294
3470
  key: "loadOrdersFromSQLite",
3295
3471
  value: function () {
3296
3472
  var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3297
- var _this20 = this;
3298
- var orders;
3473
+ var _this21 = this;
3474
+ var options,
3475
+ _options$onTiming,
3476
+ loadStartedAt,
3477
+ rawReadStartedAt,
3478
+ orders,
3479
+ sqliteRawReadMs,
3480
+ normalizeStartedAt,
3481
+ normalizedOrders,
3482
+ sqliteNormalizeMs,
3483
+ _args20 = arguments;
3299
3484
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3300
3485
  while (1) switch (_context20.prev = _context20.next) {
3301
3486
  case 0:
3487
+ options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
3302
3488
  if (this.dbManager) {
3303
- _context20.next = 2;
3489
+ _context20.next = 3;
3304
3490
  break;
3305
3491
  }
3306
3492
  return _context20.abrupt("return", []);
3307
- case 2:
3308
- _context20.prev = 2;
3309
- _context20.next = 5;
3493
+ case 3:
3494
+ _context20.prev = 3;
3495
+ loadStartedAt = performance.now();
3496
+ rawReadStartedAt = performance.now();
3497
+ _context20.next = 8;
3310
3498
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3311
- case 5:
3499
+ case 8:
3312
3500
  orders = _context20.sent;
3313
- return _context20.abrupt("return", (orders || []).map(function (order) {
3314
- return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3315
- }));
3316
- case 9:
3317
- _context20.prev = 9;
3318
- _context20.t0 = _context20["catch"](2);
3501
+ sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3502
+ normalizeStartedAt = performance.now();
3503
+ normalizedOrders = (orders || []).map(function (order) {
3504
+ return _this21.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3505
+ });
3506
+ sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3507
+ (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
3508
+ sqliteRawReadMs: sqliteRawReadMs,
3509
+ sqliteNormalizeMs: sqliteNormalizeMs,
3510
+ sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3511
+ });
3512
+ return _context20.abrupt("return", normalizedOrders);
3513
+ case 17:
3514
+ _context20.prev = 17;
3515
+ _context20.t0 = _context20["catch"](3);
3516
+ if (!options.throwOnError) {
3517
+ _context20.next = 21;
3518
+ break;
3519
+ }
3520
+ throw _context20.t0;
3521
+ case 21:
3319
3522
  return _context20.abrupt("return", []);
3320
- case 12:
3523
+ case 22:
3321
3524
  case "end":
3322
3525
  return _context20.stop();
3323
3526
  }
3324
- }, _callee20, this, [[2, 9]]);
3527
+ }, _callee20, this, [[3, 17]]);
3325
3528
  }));
3326
3529
  function loadOrdersFromSQLite() {
3327
3530
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3371,9 +3574,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3371
3574
  }, {
3372
3575
  key: "mergeRemoteSnapshotWithPendingOrders",
3373
3576
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3374
- var _this21 = this;
3577
+ var _this22 = this;
3375
3578
  var merged = remoteOrders.map(function (order) {
3376
- return _this21.normalizeRemoteSyncedOrder(order);
3579
+ return _this22.normalizeRemoteSyncedOrder(order);
3377
3580
  });
3378
3581
  var _iterator31 = _createForOfIteratorHelper(existingOrders),
3379
3582
  _step31;
@@ -3447,7 +3650,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3447
3650
  key: "patchOrdersInSQLite",
3448
3651
  value: (function () {
3449
3652
  var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3450
- var _this22 = this;
3653
+ var _this23 = this;
3451
3654
  var mergeActions,
3452
3655
  options,
3453
3656
  forceWriteStorageKeys,
@@ -3491,13 +3694,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3491
3694
  return migration.to;
3492
3695
  }));
3493
3696
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3494
- return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3697
+ return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3495
3698
  }).map(function (order) {
3496
- var storageKey = _this22.getOrderStorageKey(order);
3699
+ var storageKey = _this23.getOrderStorageKey(order);
3497
3700
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
3498
3701
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
3499
3702
  }).filter(function (order) {
3500
- return _this22.getOrderStorageKey(order);
3703
+ return _this23.getOrderStorageKey(order);
3501
3704
  });
3502
3705
  if (!(ordersSnapshot.length === 0)) {
3503
3706
  _context23.next = 13;
@@ -3520,7 +3723,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3520
3723
  return _context23.abrupt("return");
3521
3724
  case 19:
3522
3725
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3523
- return _this22.getOrderStorageKey(order);
3726
+ return _this23.getOrderStorageKey(order);
3524
3727
  }).filter(Boolean));
3525
3728
  storageKeyMigrations = new Map();
3526
3729
  _iterator32 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
@@ -3568,34 +3771,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3568
3771
  while (1) switch (_context22.prev = _context22.next) {
3569
3772
  case 0:
3570
3773
  writeMethod = 'none';
3571
- _this22.logInfo('patchOrdersInSQLite-开始', {
3774
+ _this23.logInfo('patchOrdersInSQLite-开始', {
3572
3775
  source: source,
3573
3776
  count: compactedToWrite.length,
3574
3777
  dedupedCount: skipped.length
3575
3778
  });
3576
- if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3779
+ if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3577
3780
  _context22.next = 8;
3578
3781
  break;
3579
3782
  }
3580
3783
  writeMethod = 'bulkUpdate';
3581
3784
  _context22.next = 6;
3582
- return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3785
+ return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3583
3786
  case 6:
3584
3787
  _context22.next = 37;
3585
3788
  break;
3586
3789
  case 8:
3587
- if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3790
+ if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3588
3791
  _context22.next = 14;
3589
3792
  break;
3590
3793
  }
3591
3794
  writeMethod = 'bulkAdd';
3592
3795
  _context22.next = 12;
3593
- return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3796
+ return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3594
3797
  case 12:
3595
3798
  _context22.next = 37;
3596
3799
  break;
3597
3800
  case 14:
3598
- if (!(typeof _this22.dbManager.update === 'function')) {
3801
+ if (!(typeof _this23.dbManager.update === 'function')) {
3599
3802
  _context22.next = 35;
3600
3803
  break;
3601
3804
  }
@@ -3610,7 +3813,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3610
3813
  }
3611
3814
  order = _step33.value;
3612
3815
  _context22.next = 23;
3613
- return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
3816
+ return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
3614
3817
  case 23:
3615
3818
  _context22.next = 19;
3616
3819
  break;
@@ -3635,7 +3838,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3635
3838
  }
3636
3839
  throw new Error('订单 SQLite 数据库不支持写入');
3637
3840
  case 37:
3638
- _this22.recordRecentSqliteWrite(source, compactedToWrite);
3841
+ _this23.recordRecentSqliteWrite(source, compactedToWrite);
3639
3842
  if (!(writeMethod !== 'none')) {
3640
3843
  _context22.next = 84;
3641
3844
  break;
@@ -3651,9 +3854,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3651
3854
  migration = _step34.value;
3652
3855
  _context22.prev = 44;
3653
3856
  _context22.next = 47;
3654
- return _this22.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3857
+ return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3655
3858
  case 47:
3656
- _this22.recentSqliteWriteByStorageKey.delete(migration.from);
3859
+ _this23.recentSqliteWriteByStorageKey.delete(migration.from);
3657
3860
  _iterator35 = _createForOfIteratorHelper(orders);
3658
3861
  _context22.prev = 49;
3659
3862
  _iterator35.s();
@@ -3663,7 +3866,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3663
3866
  break;
3664
3867
  }
3665
3868
  _order = _step35.value;
3666
- if (!(_this22.getOrderStorageKey(_order) !== migration.to)) {
3869
+ if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
3667
3870
  _context22.next = 55;
3668
3871
  break;
3669
3872
  }
@@ -3697,7 +3900,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3697
3900
  case 71:
3698
3901
  _context22.prev = 71;
3699
3902
  _context22.t2 = _context22["catch"](44);
3700
- _this22.logError('删除订单旧 SQLite storage key 失败', {
3903
+ _this23.logError('删除订单旧 SQLite storage key 失败', {
3701
3904
  source: source,
3702
3905
  order_id: migration.orderId,
3703
3906
  oldStorageKey: migration.from,
@@ -3719,7 +3922,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3719
3922
  _iterator34.f();
3720
3923
  return _context22.finish(81);
3721
3924
  case 84:
3722
- _this22.logInfo('patchOrdersInSQLite-完成', {
3925
+ _this23.logInfo('patchOrdersInSQLite-完成', {
3723
3926
  source: source,
3724
3927
  count: compactedToWrite.length,
3725
3928
  writeMethod: writeMethod,
@@ -3768,7 +3971,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3768
3971
  key: "updateOrderInSQLite",
3769
3972
  value: (function () {
3770
3973
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
3771
- var _this23 = this;
3974
+ var _this24 = this;
3772
3975
  var options,
3773
3976
  orderSnapshot,
3774
3977
  _orderSnapshot$order_3,
@@ -3811,40 +4014,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3811
4014
  while (1) switch (_context24.prev = _context24.next) {
3812
4015
  case 0:
3813
4016
  writeMethod = 'none';
3814
- _this23.logInfo('updateOrderInSQLite-开始', {
4017
+ _this24.logInfo('updateOrderInSQLite-开始', {
3815
4018
  source: source,
3816
4019
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
3817
- storageKey: _this23.getOrderStorageKey(orderSnapshot)
4020
+ storageKey: _this24.getOrderStorageKey(orderSnapshot)
3818
4021
  });
3819
- if (!(typeof _this23.dbManager.update === 'function')) {
4022
+ if (!(typeof _this24.dbManager.update === 'function')) {
3820
4023
  _context24.next = 8;
3821
4024
  break;
3822
4025
  }
3823
4026
  writeMethod = 'update';
3824
4027
  _context24.next = 6;
3825
- return _this23.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4028
+ return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3826
4029
  case 6:
3827
4030
  _context24.next = 22;
3828
4031
  break;
3829
4032
  case 8:
3830
- if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
4033
+ if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
3831
4034
  _context24.next = 14;
3832
4035
  break;
3833
4036
  }
3834
4037
  writeMethod = 'bulkUpdate';
3835
4038
  _context24.next = 12;
3836
- return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4039
+ return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3837
4040
  case 12:
3838
4041
  _context24.next = 22;
3839
4042
  break;
3840
4043
  case 14:
3841
- if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
4044
+ if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
3842
4045
  _context24.next = 20;
3843
4046
  break;
3844
4047
  }
3845
4048
  writeMethod = 'bulkAdd';
3846
4049
  _context24.next = 18;
3847
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4050
+ return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3848
4051
  case 18:
3849
4052
  _context24.next = 22;
3850
4053
  break;
@@ -3855,8 +4058,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3855
4058
  }
3856
4059
  throw new Error('订单 SQLite 数据库不支持写入');
3857
4060
  case 22:
3858
- _this23.recordRecentSqliteWrite(source, [orderSnapshot]);
3859
- _this23.logInfo('updateOrderInSQLite-完成', {
4061
+ _this24.recordRecentSqliteWrite(source, [orderSnapshot]);
4062
+ _this24.logInfo('updateOrderInSQLite-完成', {
3860
4063
  source: source,
3861
4064
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
3862
4065
  writeMethod: writeMethod
@@ -3898,17 +4101,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3898
4101
  * 用于 SSE 全量拉取与营业日窗口裁剪。
3899
4102
  *
3900
4103
  * @example
3901
- * await this.replaceOrdersSnapshotInSQLite(orderList)
4104
+ * const { orders, persisted } = await this.replaceOrdersSnapshotInSQLite(orderList, 'refresh')
3902
4105
  */
3903
4106
  )
3904
4107
  }, {
3905
4108
  key: "replaceOrdersSnapshotInSQLite",
3906
4109
  value: (function () {
3907
4110
  var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
3908
- var _this24 = this;
4111
+ var _this25 = this;
3909
4112
  var protectedOrdersBeforeRemoteFetch,
3910
4113
  remoteSnapshot,
3911
4114
  mergedSnapshot,
4115
+ persisted,
3912
4116
  _args27 = arguments;
3913
4117
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3914
4118
  while (1) switch (_context27.prev = _context27.next) {
@@ -3918,29 +4122,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3918
4122
  _context27.next = 3;
3919
4123
  break;
3920
4124
  }
3921
- return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3922
- return _this24.normalizeRemoteSyncedOrder(order);
3923
- }), "".concat(source, ".snapshotNoDb")).list);
4125
+ return _context27.abrupt("return", {
4126
+ orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4127
+ return _this25.normalizeRemoteSyncedOrder(order);
4128
+ }), "".concat(source, ".snapshotNoDb")).list,
4129
+ persisted: false
4130
+ });
3924
4131
  case 3:
3925
4132
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
3926
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4133
+ return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3927
4134
  });
3928
4135
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
3929
- return _this24.normalizeRemoteSyncedOrder(order);
4136
+ return _this25.normalizeRemoteSyncedOrder(order);
3930
4137
  }), "".concat(source, ".remoteSnapshot")).list;
3931
- _context27.prev = 5;
3932
- _context27.next = 8;
4138
+ persisted = false;
4139
+ _context27.prev = 6;
4140
+ _context27.next = 9;
3933
4141
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3934
4142
  var existingOrders, protectedLocalOrders, _iterator36, _step36, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3935
4143
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3936
4144
  while (1) switch (_context26.prev = _context26.next) {
3937
4145
  case 0:
3938
- if (!(typeof _this24.dbManager.getAll === 'function')) {
4146
+ if (!(typeof _this25.dbManager.getAll === 'function')) {
3939
4147
  _context26.next = 6;
3940
4148
  break;
3941
4149
  }
3942
4150
  _context26.next = 3;
3943
- return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
4151
+ return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
3944
4152
  case 3:
3945
4153
  _context26.t0 = _context26.sent;
3946
4154
  _context26.next = 7;
@@ -3950,9 +4158,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3950
4158
  case 7:
3951
4159
  existingOrders = _context26.t0;
3952
4160
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
3953
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4161
+ return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3954
4162
  }).filter(function (order) {
3955
- return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
4163
+ return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
3956
4164
  });
3957
4165
  _iterator36 = _createForOfIteratorHelper(existingOrders || []);
3958
4166
  _context26.prev = 10;
@@ -3963,9 +4171,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3963
4171
  break;
3964
4172
  }
3965
4173
  rawCurrentOrder = _step36.value;
3966
- currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3967
- protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3968
- currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4174
+ currentOrder = _this25.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4175
+ protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4176
+ currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3969
4177
  if (!(protectedIndex >= 0)) {
3970
4178
  _context26.next = 20;
3971
4179
  break;
@@ -3993,9 +4201,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3993
4201
  _iterator36.f();
3994
4202
  return _context26.finish(28);
3995
4203
  case 31:
3996
- orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3997
- mergedSnapshot = _this24.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3998
- _this24.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4204
+ orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4205
+ mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4206
+ _this25.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3999
4207
  source: source,
4000
4208
  count: mergedSnapshot.length,
4001
4209
  remoteCount: remoteSnapshot.length,
@@ -4003,10 +4211,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4003
4211
  protectedLocalOrderCount: protectedLocalOrders.length,
4004
4212
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4005
4213
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4006
- return count + _this24.getIdentifiedPendingPayments(order).length;
4214
+ return count + _this25.getIdentifiedPendingPayments(order).length;
4007
4215
  }, 0),
4008
4216
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4009
- return _this24.getIdentifiedPendingPayments(order).map(function (payment) {
4217
+ return _this25.getIdentifiedPendingPayments(order).map(function (payment) {
4010
4218
  var _order$order_id5, _external_sale_number5;
4011
4219
  return {
4012
4220
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4017,9 +4225,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4017
4225
  })
4018
4226
  });
4019
4227
  _context26.next = 36;
4020
- return _this24.dbManager.clear(INDEXDB_STORE_NAME);
4228
+ return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4021
4229
  case 36:
4022
- _this24.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4230
+ _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4023
4231
  count: mergedSnapshot.length
4024
4232
  });
4025
4233
  if (!(mergedSnapshot.length === 0)) {
@@ -4029,10 +4237,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4029
4237
  return _context26.abrupt("return");
4030
4238
  case 39:
4031
4239
  _context26.next = 41;
4032
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4240
+ return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4033
4241
  case 41:
4034
- _this24.recordRecentSqliteWrite(source, mergedSnapshot);
4035
- _this24.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4242
+ _this25.recordRecentSqliteWrite(source, mergedSnapshot);
4243
+ _this25.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4036
4244
  source: source,
4037
4245
  count: mergedSnapshot.length
4038
4246
  });
@@ -4042,23 +4250,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4042
4250
  }
4043
4251
  }, _callee26, null, [[10, 25, 28, 31]]);
4044
4252
  })));
4045
- case 8:
4046
- _context27.next = 13;
4253
+ case 9:
4254
+ persisted = true;
4255
+ _context27.next = 15;
4047
4256
  break;
4048
- case 10:
4049
- _context27.prev = 10;
4050
- _context27.t0 = _context27["catch"](5);
4257
+ case 12:
4258
+ _context27.prev = 12;
4259
+ _context27.t0 = _context27["catch"](6);
4051
4260
  this.logError('全量保存订单到 SQLite 失败', {
4052
4261
  error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
4053
4262
  orderList: remoteSnapshot.length
4054
4263
  });
4055
- case 13:
4056
- return _context27.abrupt("return", mergedSnapshot);
4057
- case 14:
4264
+ case 15:
4265
+ return _context27.abrupt("return", {
4266
+ orders: mergedSnapshot,
4267
+ persisted: persisted
4268
+ });
4269
+ case 16:
4058
4270
  case "end":
4059
4271
  return _context27.stop();
4060
4272
  }
4061
- }, _callee27, this, [[5, 10]]);
4273
+ }, _callee27, this, [[6, 12]]);
4062
4274
  }));
4063
4275
  function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4064
4276
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -4076,7 +4288,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4076
4288
  key: "clear",
4077
4289
  value: (function () {
4078
4290
  var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4079
- var _this25 = this;
4291
+ var _this26 = this;
4080
4292
  return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4081
4293
  while (1) switch (_context29.prev = _context29.next) {
4082
4294
  case 0:
@@ -4092,7 +4304,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4092
4304
  while (1) switch (_context28.prev = _context28.next) {
4093
4305
  case 0:
4094
4306
  _context28.next = 2;
4095
- return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4307
+ return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4096
4308
  case 2:
4097
4309
  case "end":
4098
4310
  return _context28.stop();
@@ -4100,7 +4312,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4100
4312
  }, _callee28);
4101
4313
  })));
4102
4314
  case 5:
4103
- this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
4315
+ this.clearOrderSnapshotMarker();
4104
4316
  this.emitOrdersChanged([], 'clear');
4105
4317
  case 7:
4106
4318
  case "end":