@pisell/pisellos 2.2.276 → 2.2.800

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 (119) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +0 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  12. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  13. package/dist/modules/OpenData/index.d.ts +0 -2
  14. package/dist/modules/OpenData/index.js +0 -8
  15. package/dist/modules/Order/index.d.ts +8 -28
  16. package/dist/modules/Order/index.js +496 -808
  17. package/dist/modules/Order/types.d.ts +1 -35
  18. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  19. package/dist/modules/Order/utils.js +6 -10
  20. package/dist/modules/Payment/index.d.ts +0 -2
  21. package/dist/modules/Payment/index.js +49 -78
  22. package/dist/modules/Payment/types.d.ts +25 -104
  23. package/dist/modules/Payment/types.js +0 -17
  24. package/dist/modules/Payment/walletpass.d.ts +1 -38
  25. package/dist/modules/Payment/walletpass.js +114 -917
  26. package/dist/modules/Rules/index.d.ts +0 -3
  27. package/dist/modules/Rules/index.js +70 -100
  28. package/dist/server/index.d.ts +0 -25
  29. package/dist/server/index.js +1069 -2001
  30. package/dist/server/modules/index.d.ts +1 -1
  31. package/dist/server/modules/order/index.d.ts +4 -70
  32. package/dist/server/modules/order/index.js +728 -1816
  33. package/dist/server/modules/order/types.d.ts +3 -25
  34. package/dist/server/modules/order/types.js +1 -7
  35. package/dist/server/utils/small-ticket.js +2 -1
  36. package/dist/solution/BaseSales/index.d.ts +5 -104
  37. package/dist/solution/BaseSales/index.js +436 -1767
  38. package/dist/solution/BaseSales/types.d.ts +1 -55
  39. package/dist/solution/BaseSales/types.js +1 -2
  40. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  41. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  42. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -7
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +5 -21
  46. package/dist/solution/BookingTicket/index.js +56 -139
  47. package/dist/solution/BookingTicket/types.d.ts +0 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +83 -173
  50. package/dist/solution/Sales/index.d.ts +0 -2
  51. package/dist/solution/Sales/index.js +4 -26
  52. package/dist/solution/ScanOrder/index.js +20 -31
  53. package/dist/solution/VenueBooking/index.d.ts +0 -1
  54. package/dist/solution/VenueBooking/index.js +19 -30
  55. package/dist/types/index.d.ts +0 -1
  56. package/lib/core/index.d.ts +0 -2
  57. package/lib/core/index.js +0 -4
  58. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  59. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  60. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  61. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  62. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  63. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  64. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  65. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  66. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  67. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  68. package/lib/modules/OpenData/index.d.ts +0 -2
  69. package/lib/modules/OpenData/index.js +0 -5
  70. package/lib/modules/Order/index.d.ts +8 -28
  71. package/lib/modules/Order/index.js +69 -231
  72. package/lib/modules/Order/types.d.ts +1 -35
  73. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  74. package/lib/modules/Order/utils.js +4 -11
  75. package/lib/modules/Payment/index.d.ts +0 -2
  76. package/lib/modules/Payment/index.js +12 -33
  77. package/lib/modules/Payment/types.d.ts +25 -104
  78. package/lib/modules/Payment/types.js +0 -1
  79. package/lib/modules/Payment/walletpass.d.ts +1 -38
  80. package/lib/modules/Payment/walletpass.js +21 -730
  81. package/lib/modules/Rules/index.d.ts +0 -3
  82. package/lib/modules/Rules/index.js +9 -38
  83. package/lib/server/index.d.ts +0 -25
  84. package/lib/server/index.js +31 -726
  85. package/lib/server/modules/index.d.ts +1 -1
  86. package/lib/server/modules/order/index.d.ts +4 -70
  87. package/lib/server/modules/order/index.js +69 -818
  88. package/lib/server/modules/order/types.d.ts +3 -25
  89. package/lib/server/modules/order/types.js +0 -1
  90. package/lib/server/utils/small-ticket.js +1 -1
  91. package/lib/solution/BaseSales/index.d.ts +5 -104
  92. package/lib/solution/BaseSales/index.js +27 -858
  93. package/lib/solution/BaseSales/types.d.ts +1 -55
  94. package/lib/solution/BaseSales/types.js +1 -2
  95. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  96. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  97. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  98. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -4
  99. package/lib/solution/BookingByStep/index.d.ts +1 -1
  100. package/lib/solution/BookingTicket/index.d.ts +5 -21
  101. package/lib/solution/BookingTicket/index.js +13 -64
  102. package/lib/solution/BookingTicket/types.d.ts +0 -1
  103. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  104. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +5 -37
  105. package/lib/solution/Sales/index.d.ts +0 -2
  106. package/lib/solution/Sales/index.js +6 -20
  107. package/lib/solution/ScanOrder/index.js +0 -8
  108. package/lib/solution/VenueBooking/index.d.ts +0 -1
  109. package/lib/solution/VenueBooking/index.js +0 -8
  110. package/lib/types/index.d.ts +0 -1
  111. package/package.json +1 -1
  112. package/dist/modules/Order/payment-utils.d.ts +0 -26
  113. package/dist/modules/Order/payment-utils.js +0 -225
  114. package/dist/utils/payment-number.d.ts +0 -9
  115. package/dist/utils/payment-number.js +0 -69
  116. package/lib/modules/Order/payment-utils.d.ts +0 -26
  117. package/lib/modules/Order/payment-utils.js +0 -224
  118. package/lib/utils/payment-number.d.ts +0 -9
  119. package/lib/utils/payment-number.js +0 -64
@@ -35,7 +35,6 @@ import dayjs from 'dayjs';
35
35
  import { BaseModule } from "../../../modules/BaseModule";
36
36
  import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
37
37
  import { OrderHooks } from "./types";
38
- import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
39
38
 
40
39
  /**
41
40
  * SQLite 存储名称
@@ -49,7 +48,7 @@ var ORDER_SQLITE_DEDUPE_MS = 15000;
49
48
  /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
50
49
  var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
51
50
  /** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
52
- var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'upsertLocalDraftOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber', 'updateLocalPayment']);
51
+ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
53
52
 
54
53
  /**
55
54
  * 合并热路径全表去重自检开关:默认关闭。
@@ -57,7 +56,6 @@ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPen
57
56
  * 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
58
57
  */
59
58
  var ORDER_MERGE_SELF_CHECK = false;
60
- var PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER = '__pisell_os_pending_payment_without_unique_number__';
61
59
  var ORDER_AUTHORITATIVE_COLLECTION_FIELDS = ['products', 'bookings', 'payments'];
62
60
  var ORDER_COLLECTION_KIND_BY_FIELD = {
63
61
  products: 'product',
@@ -135,77 +133,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
135
133
  return _emitOrdersChanged.apply(this, arguments);
136
134
  }
137
135
  return emitOrdersChanged;
138
- }()
139
- /**
140
- * 广播远端商品成员增删。监听器异常必须与订单落库和原有订单广播隔离。
141
- */
142
- )
143
- }, {
144
- key: "emitRemoteProductMembershipChanges",
145
- value: (function () {
146
- var _emitRemoteProductMembershipChanges = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(changes) {
147
- var _iterator, _step, payload;
148
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
149
- while (1) switch (_context2.prev = _context2.next) {
150
- case 0:
151
- _iterator = _createForOfIteratorHelper(changes);
152
- _context2.prev = 1;
153
- _iterator.s();
154
- case 3:
155
- if ((_step = _iterator.n()).done) {
156
- _context2.next = 15;
157
- break;
158
- }
159
- payload = _step.value;
160
- _context2.prev = 5;
161
- _context2.next = 8;
162
- return this.core.effects.emit(OrderHooks.onRemoteProductMembershipChanged, payload);
163
- case 8:
164
- _context2.next = 13;
165
- break;
166
- case 10:
167
- _context2.prev = 10;
168
- _context2.t0 = _context2["catch"](5);
169
- this.logError('广播远端订单商品成员变更失败', {
170
- order_id: payload.order_id,
171
- source: payload.source,
172
- added_product_count: payload.added_product_keys.length,
173
- removed_product_count: payload.removed_product_keys.length,
174
- error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
175
- });
176
- case 13:
177
- _context2.next = 3;
178
- break;
179
- case 15:
180
- _context2.next = 20;
181
- break;
182
- case 17:
183
- _context2.prev = 17;
184
- _context2.t1 = _context2["catch"](1);
185
- _iterator.e(_context2.t1);
186
- case 20:
187
- _context2.prev = 20;
188
- _iterator.f();
189
- return _context2.finish(20);
190
- case 23:
191
- case "end":
192
- return _context2.stop();
193
- }
194
- }, _callee2, this, [[1, 17, 20, 23], [5, 10]]);
195
- }));
196
- function emitRemoteProductMembershipChanges(_x) {
197
- return _emitRemoteProductMembershipChanges.apply(this, arguments);
198
- }
199
- return emitRemoteProductMembershipChanges;
200
136
  }())
201
137
  }, {
202
138
  key: "initialize",
203
139
  value: function () {
204
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(core, options) {
205
- var _options$initialState;
140
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
141
+ var _options$initialState,
142
+ _this3 = this;
206
143
  var appPlugin, app;
207
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
208
- while (1) switch (_context3.prev = _context3.next) {
144
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
145
+ while (1) switch (_context2.prev = _context2.next) {
209
146
  case 0:
210
147
  this.core = core;
211
148
  this.store = options === null || options === void 0 ? void 0 : options.store;
@@ -219,7 +156,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
219
156
  this.updateCreateStore();
220
157
  }
221
158
  if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
222
- this.store.list = this.normalizeOrdersForMemoryList(options.initialState.list, 'initialState');
159
+ this.store.list = options.initialState.list.map(function (order) {
160
+ return _this3.normalizeOrderForMemoryList(order);
161
+ });
223
162
  this.syncOrdersMap();
224
163
  this.emitOrdersChanged([], 'initialState');
225
164
  } else {
@@ -235,11 +174,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
235
174
  });
236
175
  case 10:
237
176
  case "end":
238
- return _context3.stop();
177
+ return _context2.stop();
239
178
  }
240
- }, _callee3, this);
179
+ }, _callee2, this);
241
180
  }));
242
- function initialize(_x2, _x3) {
181
+ function initialize(_x, _x2) {
243
182
  return _initialize.apply(this, arguments);
244
183
  }
245
184
  return initialize;
@@ -308,31 +247,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
308
247
  }, {
309
248
  key: "normalizeOrderCollectionsForIngress",
310
249
  value: function normalizeOrderCollectionsForIngress(order, source) {
311
- var sourceOrder = cloneDeep(order);
312
- var sourceOrderRecord = sourceOrder;
313
- 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));
321
- });
322
- }
323
- var result = normalizeOrderCollections(sourceOrder);
324
- var normalizedOrderRecord = result.order;
325
- if (Array.isArray(normalizedOrderRecord.payments)) {
326
- normalizedOrderRecord.payments = normalizedOrderRecord.payments.map(function (payment) {
327
- if (!(payment !== null && payment !== void 0 && payment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER])) return payment;
328
- var nextPayment = _objectSpread({}, payment);
329
- var metadata = _objectSpread({}, nextPayment.metadata || {});
330
- delete metadata.unique_payment_number;
331
- delete nextPayment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER];
332
- nextPayment.metadata = metadata;
333
- return nextPayment;
334
- });
335
- }
250
+ var result = normalizeOrderCollections(order);
336
251
  var kinds = ['product', 'booking', 'payment'];
337
252
  var hasChanges = kinds.some(function (kind) {
338
253
  var stats = result.stats[kind];
@@ -376,14 +291,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
376
291
  key: "mergeAuthoritativeOrderCollection",
377
292
  value: function mergeAuthoritativeOrderCollection(field, existing, incoming) {
378
293
  var uidRemaps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
379
- var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
380
294
  var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
381
295
  var existingItems = Array.isArray(existing) ? existing : [];
382
- if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
383
- return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
384
- preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
385
- });
386
- }
387
296
  return incoming.map(function (incomingItem) {
388
297
  var existingItem = existingItems.find(function (item) {
389
298
  return isSameOrderCollectionItem(kind, item, incomingItem);
@@ -392,11 +301,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
392
301
  var mergedItem = mergeOrderCollectionItems(kind, existingItem, incomingItem);
393
302
  var mergedUid = getOrderCollectionUid(kind, mergedItem);
394
303
  if (mergedUid) {
395
- var _iterator2 = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
396
- _step2;
304
+ var _iterator = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
305
+ _step;
397
306
  try {
398
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
399
- var from = _step2.value;
307
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
308
+ var from = _step.value;
400
309
  if (!from || from === mergedUid) continue;
401
310
  uidRemaps.push({
402
311
  kind: kind,
@@ -406,9 +315,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
406
315
  });
407
316
  }
408
317
  } catch (err) {
409
- _iterator2.e(err);
318
+ _iterator.e(err);
410
319
  } finally {
411
- _iterator2.f();
320
+ _iterator.f();
412
321
  }
413
322
  }
414
323
  return mergedItem;
@@ -439,11 +348,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
439
348
  key: "recordRecentSqliteWrite",
440
349
  value: function recordRecentSqliteWrite(source, orders) {
441
350
  var now = Date.now();
442
- var _iterator3 = _createForOfIteratorHelper(orders),
443
- _step3;
351
+ var _iterator2 = _createForOfIteratorHelper(orders),
352
+ _step2;
444
353
  try {
445
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
446
- var order = _step3.value;
354
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
355
+ var order = _step2.value;
447
356
  var storageKey = this.getOrderStorageKey(order);
448
357
  if (!storageKey) continue;
449
358
  this.recentSqliteWriteByStorageKey.set(storageKey, {
@@ -452,9 +361,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
452
361
  });
453
362
  }
454
363
  } catch (err) {
455
- _iterator3.e(err);
364
+ _iterator2.e(err);
456
365
  } finally {
457
- _iterator3.f();
366
+ _iterator2.f();
458
367
  }
459
368
  }
460
369
 
@@ -467,7 +376,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
467
376
  }, {
468
377
  key: "filterRedundantPatchOrders",
469
378
  value: function filterRedundantPatchOrders(source, orders, mergeActions) {
470
- var forceWriteStorageKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Set();
471
379
  var eligibleSkipSources = new Set(['pubsub.bodyUpsert', 'pubsub.httpRefresh']);
472
380
  if (!eligibleSkipSources.has(source)) {
473
381
  return {
@@ -478,11 +386,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
478
386
  var now = Date.now();
479
387
  var toWrite = [];
480
388
  var skipped = [];
481
- var _iterator4 = _createForOfIteratorHelper(orders),
482
- _step4;
389
+ var _iterator3 = _createForOfIteratorHelper(orders),
390
+ _step3;
483
391
  try {
484
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
485
- var order = _step4.value;
392
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
393
+ var order = _step3.value;
486
394
  var storageKey = this.getOrderStorageKey(order);
487
395
  if (!storageKey) {
488
396
  toWrite.push(order);
@@ -496,12 +404,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
496
404
  toWrite.push(order);
497
405
  continue;
498
406
  }
499
-
500
- // 远端商品成员确实发生增删时必须落库,避免内存已更新但 SQLite 仍被回声窗口跳过。
501
- if (forceWriteStorageKeys.has(storageKey)) {
502
- toWrite.push(order);
503
- continue;
504
- }
505
407
  var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
506
408
  if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
507
409
  var _order$order_id2;
@@ -517,9 +419,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
517
419
  toWrite.push(order);
518
420
  }
519
421
  } catch (err) {
520
- _iterator4.e(err);
422
+ _iterator3.e(err);
521
423
  } finally {
522
- _iterator4.f();
424
+ _iterator3.f();
523
425
  }
524
426
  return {
525
427
  toWrite: toWrite,
@@ -539,11 +441,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
539
441
  var now = Date.now();
540
442
  var toFetch = [];
541
443
  var skipped = [];
542
- var _iterator5 = _createForOfIteratorHelper(ids),
543
- _step5;
444
+ var _iterator4 = _createForOfIteratorHelper(ids),
445
+ _step4;
544
446
  try {
545
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
546
- var id = _step5.value;
447
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
448
+ var id = _step4.value;
547
449
  var existing = this.getOrderByOrderId(id);
548
450
  if (!existing) {
549
451
  toFetch.push(id);
@@ -562,9 +464,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
562
464
  toFetch.push(id);
563
465
  }
564
466
  } catch (err) {
565
- _iterator5.e(err);
467
+ _iterator4.e(err);
566
468
  } finally {
567
- _iterator5.f();
469
+ _iterator4.f();
568
470
  }
569
471
  return {
570
472
  toFetch: toFetch,
@@ -700,26 +602,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
700
602
  key: "preload",
701
603
  value: function () {
702
604
  var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
703
- var orders;
605
+ var _this4 = this;
606
+ var getData;
704
607
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
705
608
  while (1) switch (_context4.prev = _context4.next) {
706
609
  case 0:
707
- _context4.next = 2;
708
- return this.loadOrdersByServer();
610
+ // const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
611
+ // // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
612
+ // if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
613
+ // this.store.list = cloneDeep(cachedOrders)
614
+ // this.syncOrdersMap()
615
+ // this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
616
+ // return
617
+ // }
618
+ // if (hasPulledInCurrentWindow) {
619
+ // this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
620
+ // lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
621
+ // })
622
+ // return
623
+ // }
624
+ getData = /*#__PURE__*/function () {
625
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
626
+ var orders;
627
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
628
+ while (1) switch (_context3.prev = _context3.next) {
629
+ case 0:
630
+ _context3.next = 2;
631
+ return _this4.loadOrdersByServer();
632
+ case 2:
633
+ orders = _context3.sent;
634
+ if (!(orders.length === 0)) {
635
+ _context3.next = 5;
636
+ break;
637
+ }
638
+ return _context3.abrupt("return");
639
+ case 5:
640
+ _this4.store.list = cloneDeep(orders);
641
+ _this4.syncOrdersMap();
642
+ _this4.emitOrdersChanged([], 'preload');
643
+ _this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
644
+ case 9:
645
+ case "end":
646
+ return _context3.stop();
647
+ }
648
+ }, _callee3);
649
+ }));
650
+ return function getData() {
651
+ return _ref.apply(this, arguments);
652
+ };
653
+ }();
654
+ getData();
709
655
  case 2:
710
- orders = _context4.sent;
711
- this.store.list = cloneDeep(orders);
712
- this.syncOrdersMap();
713
- _context4.next = 7;
714
- return this.emitOrdersChanged([], 'preload');
715
- case 7:
716
- _context4.next = 9;
717
- return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
718
- case 9:
719
656
  case "end":
720
657
  return _context4.stop();
721
658
  }
722
- }, _callee4, this);
659
+ }, _callee4);
723
660
  }));
724
661
  function preload() {
725
662
  return _preload.apply(this, arguments);
@@ -743,38 +680,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
743
680
  value: function getOrderByOrderId(orderId) {
744
681
  return this.store.map.get(this.getIdKey(orderId));
745
682
  }
746
- }, {
747
- key: "buildLocalPaymentOrderLogContext",
748
- value: function buildLocalPaymentOrderLogContext(order) {
749
- var _order$order_id3, _order$external_sale_, _order$order_number, _order$shop_order_num, _order$shop_full_orde, _order$status, _order$payment_status, _order$platform, _order$business_code, _order$order_sales_ch, _order$sales_channel, _order$type;
750
- if (!order) return {};
751
- return {
752
- order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
753
- external_sale_number: (_order$external_sale_ = order.external_sale_number) !== null && _order$external_sale_ !== void 0 ? _order$external_sale_ : null,
754
- order_number: (_order$order_number = order.order_number) !== null && _order$order_number !== void 0 ? _order$order_number : null,
755
- shop_order_number: (_order$shop_order_num = order.shop_order_number) !== null && _order$shop_order_num !== void 0 ? _order$shop_order_num : null,
756
- shop_full_order_number: (_order$shop_full_orde = order.shop_full_order_number) !== null && _order$shop_full_orde !== void 0 ? _order$shop_full_orde : null,
757
- order_status: (_order$status = order.status) !== null && _order$status !== void 0 ? _order$status : null,
758
- payment_status: (_order$payment_status = order.payment_status) !== null && _order$payment_status !== void 0 ? _order$payment_status : null,
759
- is_draft_order: Number(order.is_draft_order || 0),
760
- need_sync: Number(order.need_sync || 0),
761
- platform: (_order$platform = order.platform) !== null && _order$platform !== void 0 ? _order$platform : null,
762
- business_code: (_order$business_code = order.business_code) !== null && _order$business_code !== void 0 ? _order$business_code : null,
763
- order_sales_channel: (_order$order_sales_ch = order.order_sales_channel) !== null && _order$order_sales_ch !== void 0 ? _order$order_sales_ch : null,
764
- sales_channel: (_order$sales_channel = order.sales_channel) !== null && _order$sales_channel !== void 0 ? _order$sales_channel : null,
765
- order_type: (_order$type = order.type) !== null && _order$type !== void 0 ? _order$type : null,
766
- payments_count: Array.isArray(order.payments) ? order.payments.length : 0
767
- };
768
- }
769
683
  }, {
770
684
  key: "getLocalOrderFromMemoryByLookup",
771
685
  value: function getLocalOrderFromMemoryByLookup(lookup) {
772
- var _this3 = this;
686
+ var _this5 = this;
773
687
  var key = this.getIdKey(lookup);
774
688
  var memoryOrderById = this.store.map.get(key);
775
689
  if (memoryOrderById) return memoryOrderById;
776
690
  var memoryOrder = this.store.list.find(function (order) {
777
- return _this3.isOrderLookupMatch(order, key);
691
+ return _this5.isOrderLookupMatch(order, key);
778
692
  });
779
693
  return memoryOrder || null;
780
694
  }
@@ -782,341 +696,118 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
782
696
  key: "getLocalOrderByLookup",
783
697
  value: function () {
784
698
  var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
785
- var _this4 = this;
786
- var options,
787
- key,
788
- logContext,
789
- memoryOrderById,
790
- memoryOrder,
791
- orders,
792
- localOrder,
793
- normalizedOrder,
794
- _args5 = arguments;
699
+ var _this6 = this;
700
+ var key, memoryOrderById, memoryOrder, orders, localOrder;
795
701
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
796
702
  while (1) switch (_context5.prev = _context5.next) {
797
703
  case 0:
798
- options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
799
704
  key = this.getIdKey(lookup);
800
- logContext = {
801
- operation_id: options.operationId,
802
- lookup: key,
803
- memory_order_count: this.store.list.length
804
- };
805
- if (options.operationId) {
806
- this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
807
- }
808
705
  memoryOrderById = this.store.map.get(key);
809
706
  if (!memoryOrderById) {
810
- _context5.next = 8;
707
+ _context5.next = 4;
811
708
  break;
812
709
  }
813
- if (options.operationId) {
814
- this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
815
- }
816
710
  return _context5.abrupt("return", memoryOrderById);
817
- case 8:
711
+ case 4:
818
712
  memoryOrder = this.store.list.find(function (order) {
819
- return _this4.isOrderLookupMatch(order, key);
713
+ return _this6.isOrderLookupMatch(order, key);
820
714
  });
821
715
  if (!memoryOrder) {
822
- _context5.next = 12;
716
+ _context5.next = 7;
823
717
  break;
824
718
  }
825
- if (options.operationId) {
826
- this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
827
- }
828
719
  return _context5.abrupt("return", memoryOrder);
829
- case 12:
830
- if (options.operationId) {
831
- this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
832
- }
833
- _context5.next = 15;
720
+ case 7:
721
+ _context5.next = 9;
834
722
  return this.loadOrdersFromSQLite();
835
- case 15:
723
+ case 9:
836
724
  orders = _context5.sent;
837
725
  localOrder = orders.find(function (order) {
838
- return _this4.isOrderLookupMatch(order, key);
726
+ return _this6.isOrderLookupMatch(order, key);
839
727
  });
840
728
  if (localOrder) {
841
- _context5.next = 20;
729
+ _context5.next = 13;
842
730
  break;
843
731
  }
844
- if (options.operationId) {
845
- this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', _objectSpread(_objectSpread({}, logContext), {}, {
846
- sqlite_order_count: orders.length
847
- }));
848
- }
849
732
  return _context5.abrupt("return", null);
850
- case 20:
851
- this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
733
+ case 13:
734
+ this.store.list = orders.map(function (order) {
735
+ return _this6.normalizeOrderForMemoryList(order);
736
+ });
852
737
  this.syncOrdersMap();
853
- normalizedOrder = this.normalizeOrderForMemoryList(localOrder);
854
- if (options.operationId) {
855
- this.logInfo('getLocalOrderByLookup-localPayment-SQLite命中', _objectSpread(_objectSpread({}, logContext), {}, {
856
- sqlite_order_count: orders.length
857
- }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
858
- }
859
- return _context5.abrupt("return", normalizedOrder);
860
- case 25:
738
+ return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
739
+ case 16:
861
740
  case "end":
862
741
  return _context5.stop();
863
742
  }
864
743
  }, _callee5, this);
865
744
  }));
866
- function getLocalOrderByLookup(_x4) {
745
+ function getLocalOrderByLookup(_x3) {
867
746
  return _getLocalOrderByLookup.apply(this, arguments);
868
747
  }
869
748
  return getLocalOrderByLookup;
870
749
  }()
871
750
  }, {
872
- key: "getLocalPayment",
751
+ key: "loadOrdersByServer",
873
752
  value: function () {
874
- var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
875
- var logContext, order, payments, match;
753
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
754
+ var _this$store,
755
+ _this7 = this;
756
+ var orderList, data, mergedOrders, memoryOrders;
876
757
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
877
758
  while (1) switch (_context6.prev = _context6.next) {
878
- case 0:
879
- logContext = {
880
- operation_id: params.operationId,
881
- sale_id: params.saleId,
882
- payment_number: params.paymentNumber
883
- };
884
- this.logInfo('getLocalPayment-开始', logContext);
885
- _context6.prev = 2;
886
- _context6.next = 5;
887
- return this.getLocalOrderByLookup(params.saleId, {
888
- operationId: params.operationId
889
- });
890
- case 5:
891
- order = _context6.sent;
892
- if (order) {
893
- _context6.next = 9;
894
- break;
895
- }
896
- this.logWarning('getLocalPayment-订单未命中', logContext);
897
- return _context6.abrupt("return", null);
898
- case 9:
899
- payments = order.payments || [];
900
- match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
901
- if (match) {
902
- _context6.next = 14;
903
- break;
904
- }
905
- this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
906
- payments: payments
907
- }));
908
- return _context6.abrupt("return", null);
909
- case 14:
910
- this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
911
- matched_by: match.matchedBy,
912
- payment_index: match.index,
913
- payment: match.payment
914
- }));
915
- return _context6.abrupt("return", {
916
- order: order,
917
- payment: match.payment,
918
- paymentIndex: match.index,
919
- matchedBy: match.matchedBy
920
- });
921
- case 18:
922
- _context6.prev = 18;
923
- _context6.t0 = _context6["catch"](2);
924
- this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
925
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
926
- }));
927
- throw _context6.t0;
928
- case 22:
929
- case "end":
930
- return _context6.stop();
931
- }
932
- }, _callee6, this, [[2, 18]]);
933
- }));
934
- function getLocalPayment(_x5) {
935
- return _getLocalPayment.apply(this, arguments);
936
- }
937
- return getLocalPayment;
938
- }()
939
- }, {
940
- key: "updateLocalPayment",
941
- value: function () {
942
- var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
943
- var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
944
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
945
- while (1) switch (_context7.prev = _context7.next) {
946
- case 0:
947
- logContext = {
948
- operation_id: params.operationId,
949
- sale_id: params.saleId,
950
- payment_number: params.paymentNumber,
951
- incoming_payment_update: params.updates
952
- };
953
- this.logInfo('updateLocalPayment-开始', logContext);
954
- _context7.next = 4;
955
- return this.getLocalPayment(params);
956
- case 4:
957
- found = _context7.sent;
958
- if (found) {
959
- _context7.next = 8;
960
- break;
961
- }
962
- this.logWarning('updateLocalPayment-支付项未命中', logContext);
963
- return _context7.abrupt("return", null);
964
- case 8:
965
- previousPayment = cloneDeep(found.payment);
966
- nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
967
- updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
968
- }));
969
- nextOrder = _objectSpread(_objectSpread({}, found.order), {}, {
970
- payments: (found.order.payments || []).map(function (payment, index) {
971
- return index === found.paymentIndex ? nextPayment : payment;
972
- }),
973
- updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
974
- });
975
- paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
976
- matched_by: found.matchedBy,
977
- payment_index: found.paymentIndex
978
- }, this.buildLocalPaymentOrderLogContext(nextOrder)), {}, {
979
- previous_payment: previousPayment,
980
- payment: nextPayment
981
- });
982
- this.logInfo('updateLocalPayment-支付项合并完成', paymentContext);
983
- targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
984
- shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
985
- if (!(targetIndex < 0 && shouldKeepInMemory)) {
986
- _context7.next = 18;
987
- break;
988
- }
989
- this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
990
- return _context7.abrupt("return", null);
991
- case 18:
992
- previousList = this.store.list;
993
- this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
994
- return index === targetIndex ? nextOrder : order;
995
- }) : this.store.list.filter(function (_, index) {
996
- return index !== targetIndex;
997
- });
998
- this.syncOrdersMap();
999
- storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
1000
- _context7.prev = 22;
1001
- this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
1002
- storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
1003
- }));
1004
- _context7.next = 26;
1005
- return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
1006
- throwOnError: true
1007
- });
1008
- case 26:
1009
- this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
1010
- storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
1011
- }));
1012
- _context7.next = 35;
1013
- break;
1014
- case 29:
1015
- _context7.prev = 29;
1016
- _context7.t0 = _context7["catch"](22);
1017
- this.store.list = previousList;
1018
- this.syncOrdersMap();
1019
- this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
1020
- storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
1021
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1022
- }));
1023
- throw _context7.t0;
1024
- case 35:
1025
- if (!(shouldKeepInMemory || targetIndex >= 0)) {
1026
- _context7.next = 38;
1027
- break;
1028
- }
1029
- _context7.next = 38;
1030
- return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
1031
- case 38:
1032
- this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
1033
- return _context7.abrupt("return", {
1034
- order: nextOrder,
1035
- payment: nextPayment,
1036
- previousPayment: previousPayment
1037
- });
1038
- case 40:
1039
- case "end":
1040
- return _context7.stop();
1041
- }
1042
- }, _callee7, this, [[22, 29]]);
1043
- }));
1044
- function updateLocalPayment(_x6) {
1045
- return _updateLocalPayment.apply(this, arguments);
1046
- }
1047
- return updateLocalPayment;
1048
- }()
1049
- }, {
1050
- key: "loadOrdersByServer",
1051
- value: function () {
1052
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1053
- var _this5 = this,
1054
- _this$store;
1055
- var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
1056
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1057
- while (1) switch (_context8.prev = _context8.next) {
1058
759
  case 0:
1059
760
  orderList = [];
1060
- _context8.next = 3;
1061
- return this.loadOrdersFromSQLite();
1062
- case 3:
1063
- protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1064
- return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1065
- });
1066
761
  this.logInfo('loadOrdersByServer-开始', {
1067
762
  hasOrderDataSource: !!this.orderDataSource,
1068
- query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1069
- protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
1070
- protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
1071
- return count + _this5.getIdentifiedPendingPayments(order).length;
1072
- }, 0)
763
+ query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
1073
764
  });
1074
765
  if (!this.orderDataSource) {
1075
- _context8.next = 20;
766
+ _context6.next = 17;
1076
767
  break;
1077
768
  }
1078
- _context8.prev = 6;
1079
- _context8.next = 9;
769
+ _context6.prev = 3;
770
+ _context6.next = 6;
1080
771
  return this.orderDataSource.run({
1081
772
  sse: {
1082
773
  query: this.store.createdAtQuery
1083
774
  }
1084
775
  });
1085
- case 9:
1086
- data = _context8.sent;
776
+ case 6:
777
+ data = _context6.sent;
1087
778
  orderList = data || [];
1088
779
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1089
780
  count: orderList.length
1090
781
  });
1091
782
  this.markOrderPulledAtNow();
1092
783
  this.lastServerFullFetchAtMs = Date.now();
1093
- _context8.next = 20;
784
+ _context6.next = 17;
1094
785
  break;
1095
- case 16:
1096
- _context8.prev = 16;
1097
- _context8.t0 = _context8["catch"](6);
786
+ case 13:
787
+ _context6.prev = 13;
788
+ _context6.t0 = _context6["catch"](3);
1098
789
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1099
- return _context8.abrupt("return", this.store.list);
1100
- case 20:
1101
- _context8.next = 22;
1102
- return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1103
- case 22:
1104
- mergedOrders = _context8.sent;
1105
- memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
790
+ return _context6.abrupt("return", this.store.list);
791
+ case 17:
792
+ _context6.next = 19;
793
+ return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
794
+ case 19:
795
+ mergedOrders = _context6.sent;
796
+ memoryOrders = mergedOrders.map(function (order) {
797
+ return _this7.normalizeOrderForMemoryList(order);
798
+ });
1106
799
  this.logInfo('loadOrdersByServer-结束', {
1107
- count: memoryOrders.length,
1108
- persistedCount: mergedOrders.length,
1109
- sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
800
+ count: memoryOrders.length
1110
801
  });
1111
- _context8.next = 27;
802
+ _context6.next = 24;
1112
803
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1113
- case 27:
1114
- return _context8.abrupt("return", memoryOrders);
1115
- case 28:
804
+ case 24:
805
+ return _context6.abrupt("return", memoryOrders);
806
+ case 25:
1116
807
  case "end":
1117
- return _context8.stop();
808
+ return _context6.stop();
1118
809
  }
1119
- }, _callee8, this, [[6, 16]]);
810
+ }, _callee6, this, [[3, 13]]);
1120
811
  }));
1121
812
  function loadOrdersByServer() {
1122
813
  return _loadOrdersByServer.apply(this, arguments);
@@ -1131,54 +822,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1131
822
  }, {
1132
823
  key: "silentRefresh",
1133
824
  value: (function () {
1134
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
825
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1135
826
  var startTime, elapsedSinceFullFetch, orders, errorMessage;
1136
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1137
- while (1) switch (_context9.prev = _context9.next) {
827
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
828
+ while (1) switch (_context7.prev = _context7.next) {
1138
829
  case 0:
1139
830
  startTime = Date.now();
1140
831
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1141
832
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1142
- _context9.next = 4;
833
+ _context7.next = 4;
1143
834
  break;
1144
835
  }
1145
- return _context9.abrupt("return", this.store.list);
836
+ return _context7.abrupt("return", this.store.list);
1146
837
  case 4:
1147
838
  this.logInfo('silentRefresh 开始');
1148
- _context9.prev = 5;
839
+ _context7.prev = 5;
1149
840
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1150
841
  this.updateCreateStore();
1151
- _context9.next = 9;
842
+ _context7.next = 9;
1152
843
  return this.loadOrdersByServer();
1153
844
  case 9:
1154
- orders = _context9.sent;
845
+ orders = _context7.sent;
846
+ if (!(orders.length > 0)) {
847
+ _context7.next = 19;
848
+ break;
849
+ }
1155
850
  this.store.list = cloneDeep(orders);
1156
851
  this.syncOrdersMap();
1157
- _context9.next = 14;
1158
- return this.emitOrdersChanged([], 'silentRefresh');
1159
- case 14:
1160
- _context9.next = 16;
852
+ this.emitOrdersChanged([], 'silentRefresh');
853
+ _context7.next = 16;
1161
854
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1162
855
  case 16:
1163
856
  this.logInfo('silentRefresh 完成', {
1164
857
  orderCount: orders.length,
1165
858
  duration: "".concat(Date.now() - startTime, "ms")
1166
859
  });
1167
- return _context9.abrupt("return", this.store.list);
860
+ _context7.next = 20;
861
+ break;
862
+ case 19:
863
+ this.logInfo('silentRefresh: 服务器未返回数据');
1168
864
  case 20:
1169
- _context9.prev = 20;
1170
- _context9.t0 = _context9["catch"](5);
1171
- errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
865
+ return _context7.abrupt("return", this.store.list);
866
+ case 23:
867
+ _context7.prev = 23;
868
+ _context7.t0 = _context7["catch"](5);
869
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
1172
870
  this.logError('silentRefresh 失败', {
1173
871
  duration: "".concat(Date.now() - startTime, "ms"),
1174
872
  error: errorMessage
1175
873
  });
1176
- return _context9.abrupt("return", this.store.list);
1177
- case 25:
874
+ return _context7.abrupt("return", this.store.list);
875
+ case 28:
1178
876
  case "end":
1179
- return _context9.stop();
877
+ return _context7.stop();
1180
878
  }
1181
- }, _callee9, this, [[5, 20]]);
879
+ }, _callee7, this, [[5, 23]]);
1182
880
  }));
1183
881
  function silentRefresh() {
1184
882
  return _silentRefresh.apply(this, arguments);
@@ -1191,9 +889,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1191
889
  var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
1192
890
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
1193
891
  var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
1194
- if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
1195
- return normalizedOrder;
1196
- }
1197
892
  if ((normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== undefined && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== null && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== '') {
1198
893
  return normalizedOrder;
1199
894
  }
@@ -1204,39 +899,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1204
899
  order_id: externalSaleNumber
1205
900
  });
1206
901
  }
1207
- }, {
1208
- key: "normalizeOrdersForMemoryList",
1209
- value: function normalizeOrdersForMemoryList(orders, source) {
1210
- var _this6 = this;
1211
- return orders.map(function (order) {
1212
- return _this6.normalizeOrderForMemoryList(order, source);
1213
- }).filter(function (order) {
1214
- return _this6.shouldKeepOrderInMemory(order);
1215
- });
1216
- }
1217
- }, {
1218
- key: "hasRealOrderId",
1219
- value: function hasRealOrderId(order) {
1220
- if (!order || this.isBlankIdentityValue(order.order_id)) return false;
1221
- var externalSaleNumber = order.external_sale_number;
1222
- return !(this.isDraftOrder(order) && !this.isBlankIdentityValue(externalSaleNumber) && String(order.order_id) === String(externalSaleNumber));
1223
- }
1224
- }, {
1225
- key: "shouldKeepOrderInMemory",
1226
- value: function shouldKeepOrderInMemory(order) {
1227
- return !this.isDraftOrder(order) || this.hasRealOrderId(order);
1228
- }
1229
- }, {
1230
- key: "withoutSyntheticDraftOrderId",
1231
- value: function withoutSyntheticDraftOrderId(order) {
1232
- var externalSaleNumber = order.external_sale_number;
1233
- if (Number(order.is_draft_order || 0) !== 1 || order.order_id === undefined || externalSaleNumber === undefined || String(order.order_id) !== String(externalSaleNumber)) {
1234
- return order;
1235
- }
1236
- var next = _objectSpread({}, order);
1237
- delete next.order_id;
1238
- return next;
1239
- }
1240
902
 
1241
903
  /**
1242
904
  * 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
@@ -1245,31 +907,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1245
907
  }, {
1246
908
  key: "overwriteExistingOrder",
1247
909
  value: (function () {
1248
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1249
- var _this7 = this;
910
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
911
+ var _this8 = this;
1250
912
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1251
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1252
- while (1) switch (_context10.prev = _context10.next) {
913
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
914
+ while (1) switch (_context8.prev = _context8.next) {
1253
915
  case 0:
1254
916
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1255
917
  if (!(orderId === undefined || orderId === null)) {
1256
- _context10.next = 4;
918
+ _context8.next = 4;
1257
919
  break;
1258
920
  }
1259
921
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1260
- return _context10.abrupt("return", {
922
+ return _context8.abrupt("return", {
1261
923
  overwritten: false
1262
924
  });
1263
925
  case 4:
1264
926
  key = this.getIdKey(orderId);
1265
927
  if (this.store.map.has(key)) {
1266
- _context10.next = 8;
928
+ _context8.next = 8;
1267
929
  break;
1268
930
  }
1269
931
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1270
932
  orderId: orderId
1271
933
  });
1272
- return _context10.abrupt("return", {
934
+ return _context8.abrupt("return", {
1273
935
  overwritten: false
1274
936
  });
1275
937
  case 8:
@@ -1283,31 +945,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1283
945
  this.store.list = this.store.list.map(function (order) {
1284
946
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1285
947
  if (id === undefined || id === null) {
1286
- return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
948
+ return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1287
949
  }
1288
- return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
950
+ return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1289
951
  });
1290
952
  this.syncOrdersMap();
1291
- _context10.next = 16;
953
+ _context8.next = 16;
1292
954
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1293
955
  case 16:
1294
956
  this.logInfo('overwriteExistingOrder-结束', {
1295
957
  orderId: orderId,
1296
958
  storeOrderCountAfter: this.store.list.length
1297
959
  });
1298
- _context10.next = 19;
960
+ _context8.next = 19;
1299
961
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1300
962
  case 19:
1301
- return _context10.abrupt("return", {
963
+ return _context8.abrupt("return", {
1302
964
  overwritten: true
1303
965
  });
1304
966
  case 20:
1305
967
  case "end":
1306
- return _context10.stop();
968
+ return _context8.stop();
1307
969
  }
1308
- }, _callee10, this);
970
+ }, _callee8, this);
1309
971
  }));
1310
- function overwriteExistingOrder(_x7) {
972
+ function overwriteExistingOrder(_x4) {
1311
973
  return _overwriteExistingOrder.apply(this, arguments);
1312
974
  }
1313
975
  return overwriteExistingOrder;
@@ -1320,33 +982,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1320
982
  }, {
1321
983
  key: "upsertOrdersFromRemote",
1322
984
  value: (function () {
1323
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(freshOrders) {
1324
- var source,
1325
- _args11 = arguments;
1326
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1327
- while (1) switch (_context11.prev = _context11.next) {
985
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
986
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
987
+ while (1) switch (_context9.prev = _context9.next) {
1328
988
  case 0:
1329
- source = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : 'upsertOrdersFromRemote';
1330
989
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1331
- _context11.next = 4;
990
+ _context9.next = 3;
1332
991
  break;
1333
992
  }
1334
993
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
1335
- return _context11.abrupt("return");
1336
- case 4:
994
+ return _context9.abrupt("return");
995
+ case 3:
1337
996
  this.logInfo('upsertOrdersFromRemote-开始', {
1338
- count: freshOrders.length,
1339
- source: source
997
+ count: freshOrders.length
1340
998
  });
1341
- _context11.next = 7;
1342
- return this.mergeOrdersToStore(freshOrders, source);
1343
- case 7:
999
+ _context9.next = 6;
1000
+ return this.mergeOrdersToStore(freshOrders, 'upsertOrdersFromRemote');
1001
+ case 6:
1344
1002
  case "end":
1345
- return _context11.stop();
1003
+ return _context9.stop();
1346
1004
  }
1347
- }, _callee11, this);
1005
+ }, _callee9, this);
1348
1006
  }));
1349
- function upsertOrdersFromRemote(_x8) {
1007
+ function upsertOrdersFromRemote(_x5) {
1350
1008
  return _upsertOrdersFromRemote.apply(this, arguments);
1351
1009
  }
1352
1010
  return upsertOrdersFromRemote;
@@ -1354,21 +1012,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1354
1012
  }, {
1355
1013
  key: "markOrderSyncedByExternalSaleNumber",
1356
1014
  value: function () {
1357
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1358
- var _this8 = this,
1015
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1016
+ var _this9 = this,
1359
1017
  _existing$external_sa,
1360
1018
  _nextOrder$order_id;
1361
1019
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1362
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1363
- while (1) switch (_context12.prev = _context12.next) {
1020
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1021
+ while (1) switch (_context10.prev = _context10.next) {
1364
1022
  case 0:
1365
1023
  externalSaleNumber = params.externalSaleNumber;
1366
1024
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1367
- _context12.next = 4;
1025
+ _context10.next = 4;
1368
1026
  break;
1369
1027
  }
1370
1028
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1371
- return _context12.abrupt("return", {
1029
+ return _context10.abrupt("return", {
1372
1030
  updated: false
1373
1031
  });
1374
1032
  case 4:
@@ -1376,24 +1034,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1376
1034
  targetIndex = this.store.list.findIndex(function (order) {
1377
1035
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1378
1036
  if (value === undefined || value === null || value === '') return false;
1379
- return _this8.getIdKey(value) === key;
1037
+ return _this9.getIdKey(value) === key;
1380
1038
  });
1381
1039
  if (!(targetIndex < 0)) {
1382
- _context12.next = 9;
1040
+ _context10.next = 9;
1383
1041
  break;
1384
1042
  }
1385
1043
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1386
1044
  external_sale_number: externalSaleNumber
1387
1045
  });
1388
- return _context12.abrupt("return", {
1046
+ return _context10.abrupt("return", {
1389
1047
  updated: false
1390
1048
  });
1391
1049
  case 9:
1392
1050
  existing = this.store.list[targetIndex];
1393
1051
  nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
1394
1052
  external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
1395
- need_sync: 0,
1396
- is_draft_order: 0
1053
+ need_sync: 0
1397
1054
  }));
1398
1055
  storageKey = this.getOrderStorageKey(nextOrder) || key;
1399
1056
  this.store.list = this.store.list.map(function (order, index) {
@@ -1401,27 +1058,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1401
1058
  return nextOrder;
1402
1059
  });
1403
1060
  this.syncOrdersMap();
1404
- _context12.next = 16;
1061
+ _context10.next = 16;
1405
1062
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1406
1063
  case 16:
1407
1064
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1408
1065
  external_sale_number: externalSaleNumber,
1409
1066
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1410
1067
  });
1411
- _context12.next = 19;
1068
+ _context10.next = 19;
1412
1069
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1413
1070
  case 19:
1414
- return _context12.abrupt("return", {
1071
+ return _context10.abrupt("return", {
1415
1072
  updated: true,
1416
1073
  order: nextOrder
1417
1074
  });
1418
1075
  case 20:
1419
1076
  case "end":
1420
- return _context12.stop();
1077
+ return _context10.stop();
1421
1078
  }
1422
- }, _callee12, this);
1079
+ }, _callee10, this);
1423
1080
  }));
1424
- function markOrderSyncedByExternalSaleNumber(_x9) {
1081
+ function markOrderSyncedByExternalSaleNumber(_x6) {
1425
1082
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1426
1083
  }
1427
1084
  return markOrderSyncedByExternalSaleNumber;
@@ -1433,391 +1090,155 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1433
1090
  }, {
1434
1091
  key: "upsertPendingSyncOrders",
1435
1092
  value: (function () {
1436
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
1437
- var _this9 = this;
1438
- var options,
1439
- pendingMap,
1440
- memoryPendingMap,
1441
- _iterator6,
1442
- _step6,
1443
- order,
1444
- normalizedOrder,
1445
- pendingOrder,
1446
- storageKey,
1447
- mergeActions,
1448
- updatedList,
1449
- identityKeyToIndex,
1450
- index,
1451
- _iterator7,
1452
- _step7,
1453
- key,
1454
- _iterator8,
1455
- _step8,
1456
- _step8$value,
1457
- _storageKey,
1458
- _pendingOrder,
1459
- matchIndex,
1460
- existingOrder,
1461
- mergedOrder,
1462
- nextOrder,
1463
- pendingSnapshot,
1464
- insertIndex,
1465
- patchedOrders,
1466
- previousList,
1467
- _args13 = arguments;
1468
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1469
- while (1) switch (_context13.prev = _context13.next) {
1093
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
1094
+ var _this10 = this;
1095
+ var pendingMap, memoryPendingMap, _iterator5, _step5, order, normalizedOrder, storageKey, mergeActions, updatedList, identityKeyToIndex, index, _iterator6, _step6, key, _iterator7, _step7, _step7$value, _storageKey, pendingOrder, matchIndex, existingOrder, mergedOrder, pendingSnapshot, insertIndex, patchedOrders;
1096
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1097
+ while (1) switch (_context11.prev = _context11.next) {
1470
1098
  case 0:
1471
- options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
1472
1099
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1473
- _context13.next = 4;
1100
+ _context11.next = 3;
1474
1101
  break;
1475
1102
  }
1476
1103
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1477
- return _context13.abrupt("return");
1478
- case 4:
1104
+ return _context11.abrupt("return");
1105
+ case 3:
1479
1106
  pendingMap = new Map();
1480
1107
  memoryPendingMap = new Map();
1481
- _iterator6 = _createForOfIteratorHelper(pendingOrders);
1482
- _context13.prev = 7;
1483
- _iterator6.s();
1484
- case 9:
1485
- if ((_step6 = _iterator6.n()).done) {
1486
- _context13.next = 20;
1108
+ _iterator5 = _createForOfIteratorHelper(pendingOrders);
1109
+ _context11.prev = 6;
1110
+ _iterator5.s();
1111
+ case 8:
1112
+ if ((_step5 = _iterator5.n()).done) {
1113
+ _context11.next = 18;
1487
1114
  break;
1488
1115
  }
1489
- order = _step6.value;
1116
+ order = _step5.value;
1490
1117
  normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
1491
- pendingOrder = _objectSpread(_objectSpread({}, normalizedOrder), {}, {
1492
- need_sync: 1,
1493
- is_draft_order: 0
1494
- });
1495
- storageKey = this.getOrderStorageKey(pendingOrder);
1118
+ storageKey = this.getOrderStorageKey(normalizedOrder);
1496
1119
  if (storageKey) {
1497
- _context13.next = 16;
1120
+ _context11.next = 14;
1498
1121
  break;
1499
1122
  }
1500
- return _context13.abrupt("continue", 18);
1123
+ return _context11.abrupt("continue", 16);
1124
+ case 14:
1125
+ pendingMap.set(storageKey, normalizedOrder);
1126
+ memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(normalizedOrder, 'upsertPendingSyncOrders.memory'));
1501
1127
  case 16:
1502
- pendingMap.set(storageKey, pendingOrder);
1503
- memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1128
+ _context11.next = 8;
1129
+ break;
1504
1130
  case 18:
1505
- _context13.next = 9;
1131
+ _context11.next = 23;
1506
1132
  break;
1507
1133
  case 20:
1508
- _context13.next = 25;
1509
- break;
1510
- case 22:
1511
- _context13.prev = 22;
1512
- _context13.t0 = _context13["catch"](7);
1513
- _iterator6.e(_context13.t0);
1514
- case 25:
1515
- _context13.prev = 25;
1516
- _iterator6.f();
1517
- return _context13.finish(25);
1518
- case 28:
1134
+ _context11.prev = 20;
1135
+ _context11.t0 = _context11["catch"](6);
1136
+ _iterator5.e(_context11.t0);
1137
+ case 23:
1138
+ _context11.prev = 23;
1139
+ _iterator5.f();
1140
+ return _context11.finish(23);
1141
+ case 26:
1519
1142
  if (!(pendingMap.size === 0)) {
1520
- _context13.next = 31;
1143
+ _context11.next = 29;
1521
1144
  break;
1522
1145
  }
1523
1146
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1524
1147
  count: pendingOrders.length
1525
1148
  });
1526
- return _context13.abrupt("return");
1527
- case 31:
1149
+ return _context11.abrupt("return");
1150
+ case 29:
1528
1151
  this.logInfo('upsertPendingSyncOrders-开始', {
1529
1152
  count: pendingMap.size
1530
1153
  });
1531
1154
  mergeActions = {};
1532
1155
  updatedList = this.store.list.map(function (order) {
1533
- return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1156
+ return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1534
1157
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1535
1158
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1536
1159
  identityKeyToIndex = new Map();
1537
1160
  for (index = 0; index < updatedList.length; index += 1) {
1538
- _iterator7 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1161
+ _iterator6 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1539
1162
  try {
1540
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1541
- key = _step7.value;
1163
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1164
+ key = _step6.value;
1542
1165
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1543
1166
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1544
1167
  }
1545
1168
  } catch (err) {
1546
- _iterator7.e(err);
1169
+ _iterator6.e(err);
1547
1170
  } finally {
1548
- _iterator7.f();
1171
+ _iterator6.f();
1549
1172
  }
1550
1173
  }
1551
- _iterator8 = _createForOfIteratorHelper(memoryPendingMap.entries());
1552
- _context13.prev = 37;
1553
- _iterator8.s();
1554
- case 39:
1555
- if ((_step8 = _iterator8.n()).done) {
1556
- _context13.next = 58;
1174
+ _iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
1175
+ _context11.prev = 35;
1176
+ _iterator7.s();
1177
+ case 37:
1178
+ if ((_step7 = _iterator7.n()).done) {
1179
+ _context11.next = 55;
1557
1180
  break;
1558
1181
  }
1559
- _step8$value = _slicedToArray(_step8.value, 2), _storageKey = _step8$value[0], _pendingOrder = _step8$value[1];
1560
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1182
+ _step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], pendingOrder = _step7$value[1];
1183
+ matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(pendingOrder));
1561
1184
  if (!(matchIndex >= 0)) {
1562
- _context13.next = 52;
1185
+ _context11.next = 49;
1563
1186
  break;
1564
1187
  }
1565
1188
  existingOrder = updatedList[matchIndex];
1566
- mergedOrder = this.mergeOrderRecords(existingOrder, _pendingOrder);
1567
- nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
1568
- need_sync: 1,
1569
- is_draft_order: 0
1570
- });
1571
- updatedList[matchIndex] = nextOrder;
1189
+ mergedOrder = this.mergeOrderRecords(existingOrder, pendingOrder);
1190
+ updatedList[matchIndex] = mergedOrder;
1572
1191
  pendingSnapshot = pendingMap.get(_storageKey);
1573
1192
  if (pendingSnapshot) {
1574
1193
  pendingMap.set(_storageKey, this.reconcileOverwriteOrderCollections(existingOrder, pendingSnapshot));
1575
1194
  }
1576
1195
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1577
- this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1196
+ this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
1578
1197
  mergeActions[_storageKey] = 'update';
1579
- return _context13.abrupt("continue", 56);
1580
- case 52:
1198
+ return _context11.abrupt("continue", 53);
1199
+ case 49:
1581
1200
  insertIndex = updatedList.length;
1582
- updatedList.push(_pendingOrder);
1583
- this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1201
+ updatedList.push(pendingOrder);
1202
+ this.registerOrderIdentityKeys(identityKeyToIndex, pendingOrder, insertIndex);
1584
1203
  mergeActions[_storageKey] = 'insert';
1585
- case 56:
1586
- _context13.next = 39;
1204
+ case 53:
1205
+ _context11.next = 37;
1587
1206
  break;
1588
- case 58:
1589
- _context13.next = 63;
1207
+ case 55:
1208
+ _context11.next = 60;
1590
1209
  break;
1210
+ case 57:
1211
+ _context11.prev = 57;
1212
+ _context11.t1 = _context11["catch"](35);
1213
+ _iterator7.e(_context11.t1);
1591
1214
  case 60:
1592
- _context13.prev = 60;
1593
- _context13.t1 = _context13["catch"](37);
1594
- _iterator8.e(_context13.t1);
1215
+ _context11.prev = 60;
1216
+ _iterator7.f();
1217
+ return _context11.finish(60);
1595
1218
  case 63:
1596
- _context13.prev = 63;
1597
- _iterator8.f();
1598
- return _context13.finish(63);
1599
- case 66:
1600
1219
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1601
- previousList = this.store.list;
1602
1220
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1603
1221
  this.syncOrdersMap();
1604
- _context13.prev = 70;
1605
- _context13.next = 73;
1606
- return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1607
- case 73:
1608
- _context13.next = 80;
1609
- break;
1610
- case 75:
1611
- _context13.prev = 75;
1612
- _context13.t2 = _context13["catch"](70);
1613
- this.store.list = previousList;
1614
- this.syncOrdersMap();
1615
- throw _context13.t2;
1616
- case 80:
1222
+ _context11.next = 68;
1223
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
1224
+ case 68:
1617
1225
  this.logInfo('upsertPendingSyncOrders-结束', {
1618
1226
  count: patchedOrders.length,
1619
1227
  storeOrderCountAfter: this.store.list.length
1620
1228
  });
1621
- _context13.next = 83;
1229
+ _context11.next = 71;
1622
1230
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1623
- case 83:
1231
+ case 71:
1624
1232
  case "end":
1625
- return _context13.stop();
1233
+ return _context11.stop();
1626
1234
  }
1627
- }, _callee13, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1235
+ }, _callee11, this, [[6, 20, 23, 26], [35, 57, 60, 63]]);
1628
1236
  }));
1629
- function upsertPendingSyncOrders(_x10) {
1237
+ function upsertPendingSyncOrders(_x7) {
1630
1238
  return _upsertPendingSyncOrders.apply(this, arguments);
1631
1239
  }
1632
1240
  return upsertPendingSyncOrders;
1633
1241
  }()
1634
- /**
1635
- * 将 POS 草稿订单按 SQLite storage key 落库。
1636
- * 只有具备真实 order_id 的草稿进入 store;其余草稿仅供本地恢复查询。
1637
- */
1638
- )
1639
- }, {
1640
- key: "upsertLocalDraftOrders",
1641
- value: (function () {
1642
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
1643
- var _this10 = this;
1644
- 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;
1645
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1646
- while (1) switch (_context14.prev = _context14.next) {
1647
- case 0:
1648
- if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1649
- _context14.next = 3;
1650
- break;
1651
- }
1652
- this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1653
- return _context14.abrupt("return");
1654
- case 3:
1655
- draftMap = new Map();
1656
- memoryDraftMap = new Map();
1657
- _iterator9 = _createForOfIteratorHelper(draftOrders);
1658
- _context14.prev = 6;
1659
- _iterator9.s();
1660
- case 8:
1661
- if ((_step9 = _iterator9.n()).done) {
1662
- _context14.next = 19;
1663
- break;
1664
- }
1665
- order = _step9.value;
1666
- draftOrder = _objectSpread(_objectSpread({}, order), {}, {
1667
- need_sync: 0,
1668
- is_draft_order: 1
1669
- });
1670
- storageKey = this.getOrderStorageKey(draftOrder);
1671
- if (storageKey) {
1672
- _context14.next = 14;
1673
- break;
1674
- }
1675
- return _context14.abrupt("continue", 17);
1676
- case 14:
1677
- draftMap.set(storageKey, draftOrder);
1678
- memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
1679
- if (this.shouldKeepOrderInMemory(memoryDraftOrder)) {
1680
- memoryDraftMap.set(storageKey, memoryDraftOrder);
1681
- }
1682
- case 17:
1683
- _context14.next = 8;
1684
- break;
1685
- case 19:
1686
- _context14.next = 24;
1687
- break;
1688
- case 21:
1689
- _context14.prev = 21;
1690
- _context14.t0 = _context14["catch"](6);
1691
- _iterator9.e(_context14.t0);
1692
- case 24:
1693
- _context14.prev = 24;
1694
- _iterator9.f();
1695
- return _context14.finish(24);
1696
- case 27:
1697
- if (!(draftMap.size === 0)) {
1698
- _context14.next = 30;
1699
- break;
1700
- }
1701
- this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1702
- count: draftOrders.length
1703
- });
1704
- return _context14.abrupt("return");
1705
- case 30:
1706
- this.logInfo('upsertLocalDraftOrders-开始', {
1707
- count: draftMap.size,
1708
- memoryDraftCount: memoryDraftMap.size,
1709
- sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
1710
- });
1711
- mergeActions = {};
1712
- updatedList = this.store.list.filter(function (order) {
1713
- return _this10.shouldKeepOrderInMemory(order);
1714
- });
1715
- identityKeyToIndex = new Map();
1716
- for (index = 0; index < updatedList.length; index += 1) {
1717
- _iterator10 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1718
- try {
1719
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1720
- key = _step10.value;
1721
- if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1722
- }
1723
- } catch (err) {
1724
- _iterator10.e(err);
1725
- } finally {
1726
- _iterator10.f();
1727
- }
1728
- }
1729
- _iterator11 = _createForOfIteratorHelper(memoryDraftMap.entries());
1730
- _context14.prev = 36;
1731
- _iterator11.s();
1732
- case 38:
1733
- if ((_step11 = _iterator11.n()).done) {
1734
- _context14.next = 57;
1735
- break;
1736
- }
1737
- _step11$value = _slicedToArray(_step11.value, 2), _storageKey2 = _step11$value[0], _draftOrder = _step11$value[1];
1738
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1739
- if (!(matchIndex >= 0)) {
1740
- _context14.next = 51;
1741
- break;
1742
- }
1743
- existingOrder = updatedList[matchIndex];
1744
- reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, _draftOrder);
1745
- mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
1746
- nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
1747
- need_sync: 0,
1748
- is_draft_order: 1
1749
- });
1750
- updatedList[matchIndex] = nextOrder;
1751
- // SQLite 必须与内存中的草稿保持同一份 business_code,避免下次 hydrate 再次丢失分类。
1752
- draftMap.set(_storageKey2, reconciledDraftOrder);
1753
- this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1754
- mergeActions[_storageKey2] = 'update';
1755
- return _context14.abrupt("continue", 55);
1756
- case 51:
1757
- insertIndex = updatedList.length;
1758
- updatedList.push(_draftOrder);
1759
- this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1760
- mergeActions[_storageKey2] = 'insert';
1761
- case 55:
1762
- _context14.next = 38;
1763
- break;
1764
- case 57:
1765
- _context14.next = 62;
1766
- break;
1767
- case 59:
1768
- _context14.prev = 59;
1769
- _context14.t1 = _context14["catch"](36);
1770
- _iterator11.e(_context14.t1);
1771
- case 62:
1772
- _context14.prev = 62;
1773
- _iterator11.f();
1774
- return _context14.finish(62);
1775
- case 65:
1776
- patchedOrders = _toConsumableArray(draftMap.values());
1777
- previousList = this.store.list;
1778
- this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
1779
- this.syncOrdersMap();
1780
- _context14.prev = 69;
1781
- _context14.next = 72;
1782
- return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
1783
- throwOnError: true
1784
- });
1785
- case 72:
1786
- _context14.next = 79;
1787
- break;
1788
- case 74:
1789
- _context14.prev = 74;
1790
- _context14.t2 = _context14["catch"](69);
1791
- this.store.list = previousList;
1792
- this.syncOrdersMap();
1793
- throw _context14.t2;
1794
- case 79:
1795
- this.logInfo('upsertLocalDraftOrders-结束', {
1796
- count: patchedOrders.length,
1797
- storeOrderCountAfter: this.store.list.length
1798
- });
1799
- removedLegacyMemoryDraft = previousList.some(function (order) {
1800
- return !_this10.shouldKeepOrderInMemory(order);
1801
- });
1802
- if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1803
- _context14.next = 84;
1804
- break;
1805
- }
1806
- _context14.next = 84;
1807
- return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1808
- return _this10.shouldKeepOrderInMemory(order);
1809
- }), 'upsertLocalDraftOrders');
1810
- case 84:
1811
- case "end":
1812
- return _context14.stop();
1813
- }
1814
- }, _callee14, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
1815
- }));
1816
- function upsertLocalDraftOrders(_x11) {
1817
- return _upsertLocalDraftOrders.apply(this, arguments);
1818
- }
1819
- return upsertLocalDraftOrders;
1820
- }()
1821
1242
  /**
1822
1243
  * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
1823
1244
  */
@@ -1825,42 +1246,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1825
1246
  }, {
1826
1247
  key: "fetchOrdersBySSE",
1827
1248
  value: (function () {
1828
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1249
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1829
1250
  var query,
1830
1251
  data,
1831
- _args15 = arguments;
1832
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1833
- while (1) switch (_context15.prev = _context15.next) {
1252
+ _args12 = arguments;
1253
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1254
+ while (1) switch (_context12.prev = _context12.next) {
1834
1255
  case 0:
1835
- query = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
1256
+ query = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1836
1257
  if (this.orderDataSource) {
1837
- _context15.next = 3;
1258
+ _context12.next = 3;
1838
1259
  break;
1839
1260
  }
1840
- return _context15.abrupt("return", []);
1261
+ return _context12.abrupt("return", []);
1841
1262
  case 3:
1842
- _context15.prev = 3;
1843
- _context15.next = 6;
1263
+ _context12.prev = 3;
1264
+ _context12.next = 6;
1844
1265
  return this.orderDataSource.run({
1845
1266
  sse: {
1846
1267
  query: query
1847
1268
  }
1848
1269
  });
1849
1270
  case 6:
1850
- data = _context15.sent;
1851
- return _context15.abrupt("return", data || []);
1271
+ data = _context12.sent;
1272
+ return _context12.abrupt("return", data || []);
1852
1273
  case 10:
1853
- _context15.prev = 10;
1854
- _context15.t0 = _context15["catch"](3);
1274
+ _context12.prev = 10;
1275
+ _context12.t0 = _context12["catch"](3);
1855
1276
  this.logError('fetchOrdersBySSE-失败', {
1856
- error: _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0)
1277
+ error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0)
1857
1278
  });
1858
- return _context15.abrupt("return", []);
1279
+ return _context12.abrupt("return", []);
1859
1280
  case 14:
1860
1281
  case "end":
1861
- return _context15.stop();
1282
+ return _context12.stop();
1862
1283
  }
1863
- }, _callee15, this, [[3, 10]]);
1284
+ }, _callee12, this, [[3, 10]]);
1864
1285
  }));
1865
1286
  function fetchOrdersBySSE() {
1866
1287
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -1888,24 +1309,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1888
1309
  }, {
1889
1310
  key: "syncOrdersMap",
1890
1311
  value: function syncOrdersMap() {
1891
- var _this11 = this;
1892
- this.store.list = this.store.list.filter(function (order) {
1893
- return _this11.shouldKeepOrderInMemory(order);
1894
- });
1895
1312
  this.store.map.clear();
1896
- var _iterator12 = _createForOfIteratorHelper(this.store.list),
1897
- _step12;
1313
+ var _iterator8 = _createForOfIteratorHelper(this.store.list),
1314
+ _step8;
1898
1315
  try {
1899
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1900
- var order = _step12.value;
1316
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1317
+ var order = _step8.value;
1901
1318
  var primaryIdentity = this.getOrderMapKey(order);
1902
1319
  if (!primaryIdentity) continue;
1903
1320
  this.store.map.set(primaryIdentity, order);
1904
1321
  }
1905
1322
  } catch (err) {
1906
- _iterator12.e(err);
1323
+ _iterator8.e(err);
1907
1324
  } finally {
1908
- _iterator12.f();
1325
+ _iterator8.f();
1909
1326
  }
1910
1327
  }
1911
1328
  }, {
@@ -1926,27 +1343,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1926
1343
  value: function isBlankIdentityValue(value) {
1927
1344
  return value === undefined || value === null || value === '';
1928
1345
  }
1929
-
1930
- /**
1931
- * `/sales/draft` 的旧调用方可能把未设置的 business_code 传成空串。
1932
- * 对同一真实订单,空值不能覆盖已有的分类,否则 booking 查询会把该订单从 Party 列表过滤掉。
1933
- */
1934
- }, {
1935
- key: "preserveExistingBusinessCodeForDraft",
1936
- value: function preserveExistingBusinessCodeForDraft(existingOrder, draftOrder) {
1937
- var existingBusinessCode = existingOrder.business_code;
1938
- var draftBusinessCode = draftOrder.business_code;
1939
- var hasExistingBusinessCode = typeof existingBusinessCode === 'string' && existingBusinessCode.trim() !== '';
1940
- var hasDraftBusinessCode = typeof draftBusinessCode === 'string' && draftBusinessCode.trim() !== '';
1941
- if (!hasExistingBusinessCode || hasDraftBusinessCode) return draftOrder;
1942
- return _objectSpread(_objectSpread({}, draftOrder), {}, {
1943
- business_code: existingBusinessCode
1944
- });
1945
- }
1946
1346
  }, {
1947
1347
  key: "getOrderIdentityEntries",
1948
1348
  value: function getOrderIdentityEntries(order) {
1949
- var _this12 = this;
1349
+ var _this11 = this;
1950
1350
  if (!order) return [];
1951
1351
  var record = order;
1952
1352
  var candidates = [{
@@ -1965,8 +1365,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1965
1365
  var entries = [];
1966
1366
  var _loop = function _loop() {
1967
1367
  var candidate = _candidates[_i2];
1968
- if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
1969
- var key = _this12.getIdKey(candidate.value);
1368
+ if (_this11.isBlankIdentityValue(candidate.value)) return 0; // continue
1369
+ var key = _this11.getIdKey(candidate.value);
1970
1370
  if (entries.some(function (entry) {
1971
1371
  return entry.field === candidate.field && entry.key === key;
1972
1372
  })) return 0; // continue
@@ -1986,17 +1386,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1986
1386
  key: "getOrderIdentityKeys",
1987
1387
  value: function getOrderIdentityKeys(order) {
1988
1388
  var keys = [];
1989
- var _iterator13 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1990
- _step13;
1389
+ var _iterator9 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1390
+ _step9;
1991
1391
  try {
1992
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1993
- var entry = _step13.value;
1392
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1393
+ var entry = _step9.value;
1994
1394
  if (!keys.includes(entry.key)) keys.push(entry.key);
1995
1395
  }
1996
1396
  } catch (err) {
1997
- _iterator13.e(err);
1397
+ _iterator9.e(err);
1998
1398
  } finally {
1999
- _iterator13.f();
1399
+ _iterator9.f();
2000
1400
  }
2001
1401
  return keys;
2002
1402
  }
@@ -2033,7 +1433,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2033
1433
  }, {
2034
1434
  key: "setupOrderSync",
2035
1435
  value: function setupOrderSync() {
2036
- var _this13 = this;
1436
+ var _this12 = this;
2037
1437
  if (!this.orderDataSource) return;
2038
1438
  this.orderDataSource.run({
2039
1439
  pubsub: {
@@ -2041,22 +1441,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2041
1441
  var _message$id, _message$order_id, _message$type;
2042
1442
  console.log('orderDataSource', res);
2043
1443
  var pubsubReceivedAt = Date.now();
2044
- var message = _this13.normalizeOrderSyncMessage(res);
1444
+ var message = _this12.normalizeOrderSyncMessage(res);
2045
1445
  if (!message) return;
2046
1446
  message._pubsubReceivedAt = pubsubReceivedAt;
2047
- _this13.pendingSyncMessages.push(message);
2048
- var throttleMs = _this13.getOrderSyncThrottleMs();
2049
- var routeInfo = _this13.resolveSyncMessageRoute(message);
2050
- _this13.logInfo('orderSync-收到消息并入队', {
1447
+ _this12.pendingSyncMessages.push(message);
1448
+ var throttleMs = _this12.getOrderSyncThrottleMs();
1449
+ var routeInfo = _this12.resolveSyncMessageRoute(message);
1450
+ _this12.logInfo('orderSync-收到消息并入队', {
2051
1451
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2052
1452
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2053
1453
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2054
- pendingCount: _this13.pendingSyncMessages.length,
1454
+ pendingCount: _this12.pendingSyncMessages.length,
2055
1455
  throttleMs: throttleMs,
2056
1456
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2057
1457
  fullMessage: JSON.stringify(message)
2058
1458
  });
2059
- _this13.scheduleOrderSyncThrottle();
1459
+ _this12.scheduleOrderSyncThrottle();
2060
1460
  }
2061
1461
  }
2062
1462
  }).catch(function () {
@@ -2073,7 +1473,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2073
1473
  }, {
2074
1474
  key: "scheduleOrderSyncThrottle",
2075
1475
  value: function scheduleOrderSyncThrottle() {
2076
- var _this14 = this;
1476
+ var _this13 = this;
2077
1477
  if (this.isProcessingSyncBatch) return;
2078
1478
  if (this.isIdlePhase) {
2079
1479
  this.isIdlePhase = false;
@@ -2084,8 +1484,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2084
1484
  if (this.syncTimer) return;
2085
1485
  var throttleMs = this.getOrderSyncThrottleMs();
2086
1486
  this.syncTimer = setTimeout(function () {
2087
- _this14.syncTimer = undefined;
2088
- void _this14.flushOrderSyncMessagesByThrottle();
1487
+ _this13.syncTimer = undefined;
1488
+ void _this13.flushOrderSyncMessagesByThrottle();
2089
1489
  }, throttleMs);
2090
1490
  }
2091
1491
 
@@ -2096,41 +1496,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2096
1496
  }, {
2097
1497
  key: "flushOrderSyncMessagesByThrottle",
2098
1498
  value: (function () {
2099
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2100
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2101
- while (1) switch (_context16.prev = _context16.next) {
1499
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1500
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1501
+ while (1) switch (_context13.prev = _context13.next) {
2102
1502
  case 0:
2103
1503
  if (!this.isProcessingSyncBatch) {
2104
- _context16.next = 2;
1504
+ _context13.next = 2;
2105
1505
  break;
2106
1506
  }
2107
- return _context16.abrupt("return");
1507
+ return _context13.abrupt("return");
2108
1508
  case 2:
2109
1509
  if (!(this.pendingSyncMessages.length === 0)) {
2110
- _context16.next = 5;
1510
+ _context13.next = 5;
2111
1511
  break;
2112
1512
  }
2113
1513
  this.isIdlePhase = true;
2114
- return _context16.abrupt("return");
1514
+ return _context13.abrupt("return");
2115
1515
  case 5:
2116
1516
  this.isProcessingSyncBatch = true;
2117
- _context16.prev = 6;
2118
- _context16.next = 9;
1517
+ _context13.prev = 6;
1518
+ _context13.next = 9;
2119
1519
  return this.processOrderSyncMessages();
2120
1520
  case 9:
2121
- _context16.prev = 9;
1521
+ _context13.prev = 9;
2122
1522
  this.isProcessingSyncBatch = false;
2123
1523
  if (this.pendingSyncMessages.length > 0) {
2124
1524
  this.scheduleOrderSyncThrottle();
2125
1525
  } else {
2126
1526
  this.isIdlePhase = true;
2127
1527
  }
2128
- return _context16.finish(9);
1528
+ return _context13.finish(9);
2129
1529
  case 13:
2130
1530
  case "end":
2131
- return _context16.stop();
1531
+ return _context13.stop();
2132
1532
  }
2133
- }, _callee16, this, [[6,, 9, 13]]);
1533
+ }, _callee13, this, [[6,, 9, 13]]);
2134
1534
  }));
2135
1535
  function flushOrderSyncMessagesByThrottle() {
2136
1536
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2152,19 +1552,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2152
1552
  }, {
2153
1553
  key: "processOrderSyncMessages",
2154
1554
  value: (function () {
2155
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2156
- var _this15 = this;
1555
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1556
+ var _this14 = this;
2157
1557
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2158
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2159
- while (1) switch (_context17.prev = _context17.next) {
1558
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1559
+ while (1) switch (_context14.prev = _context14.next) {
2160
1560
  case 0:
2161
1561
  messages = _toConsumableArray(this.pendingSyncMessages);
2162
1562
  this.pendingSyncMessages = [];
2163
1563
  if (!(messages.length === 0)) {
2164
- _context17.next = 4;
1564
+ _context14.next = 4;
2165
1565
  break;
2166
1566
  }
2167
- return _context17.abrupt("return");
1567
+ return _context14.abrupt("return");
2168
1568
  case 4:
2169
1569
  batchProcessStartAt = Date.now();
2170
1570
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2180,13 +1580,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2180
1580
  upsertOrders = new Map();
2181
1581
  refreshIds = [];
2182
1582
  messages.forEach(function (msg, msgIndex) {
2183
- var routeInfo = _this15.resolveSyncMessageRoute(msg);
1583
+ var routeInfo = _this14.resolveSyncMessageRoute(msg);
2184
1584
  var hasBatchIds = routeInfo.hasBatchIds;
2185
1585
  var singleId = routeInfo.singleId;
2186
1586
  var hasSingleId = routeInfo.hasSingleId;
2187
- var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
1587
+ var normalizedBody = _this14.normalizeOrderSyncPayload(msg.body || msg.data);
2188
1588
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2189
- upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
1589
+ upsertOrders.set(_this14.getIdKey(normalizedBody.order_id), normalizedBody);
2190
1590
  return;
2191
1591
  }
2192
1592
  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));
@@ -2198,41 +1598,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2198
1598
  refreshIdCount: uniqueRefreshIds.length
2199
1599
  });
2200
1600
  if (!(upsertList.length > 0)) {
2201
- _context17.next = 16;
1601
+ _context14.next = 16;
2202
1602
  break;
2203
1603
  }
2204
- _context17.next = 16;
1604
+ _context14.next = 16;
2205
1605
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2206
1606
  case 16:
2207
1607
  if (!(uniqueRefreshIds.length > 0)) {
2208
- _context17.next = 28;
1608
+ _context14.next = 28;
2209
1609
  break;
2210
1610
  }
2211
1611
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2212
1612
  if (skipped.length > 0) {}
2213
1613
  if (!(toFetch.length > 0)) {
2214
- _context17.next = 28;
1614
+ _context14.next = 28;
2215
1615
  break;
2216
1616
  }
2217
- _context17.next = 22;
1617
+ _context14.next = 22;
2218
1618
  return this.fetchOrdersByHttp(toFetch);
2219
1619
  case 22:
2220
- freshOrders = _context17.sent;
1620
+ freshOrders = _context14.sent;
2221
1621
  if (!(freshOrders.length > 0)) {
2222
- _context17.next = 28;
1622
+ _context14.next = 28;
2223
1623
  break;
2224
1624
  }
2225
- _context17.next = 26;
1625
+ _context14.next = 26;
2226
1626
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2227
1627
  case 26:
2228
- _context17.next = 28;
1628
+ _context14.next = 28;
2229
1629
  break;
2230
1630
  case 28:
2231
1631
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2232
- _context17.next = 30;
1632
+ _context14.next = 30;
2233
1633
  break;
2234
1634
  }
2235
- return _context17.abrupt("return");
1635
+ return _context14.abrupt("return");
2236
1636
  case 30:
2237
1637
  batchProcessEndAt = Date.now();
2238
1638
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2241,13 +1641,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2241
1641
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2242
1642
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2243
1643
  });
2244
- _context17.next = 34;
1644
+ _context14.next = 34;
2245
1645
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2246
1646
  case 34:
2247
1647
  case "end":
2248
- return _context17.stop();
1648
+ return _context14.stop();
2249
1649
  }
2250
- }, _callee17, this);
1650
+ }, _callee14, this);
2251
1651
  }));
2252
1652
  function processOrderSyncMessages() {
2253
1653
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2268,29 +1668,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2268
1668
  }, {
2269
1669
  key: "fetchOrdersByHttp",
2270
1670
  value: (function () {
2271
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
1671
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
2272
1672
  var _orderList, orderList;
2273
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2274
- while (1) switch (_context18.prev = _context18.next) {
1673
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1674
+ while (1) switch (_context15.prev = _context15.next) {
2275
1675
  case 0:
2276
1676
  if (!(!this.orderDataSource || ids.length === 0)) {
2277
- _context18.next = 2;
1677
+ _context15.next = 2;
2278
1678
  break;
2279
1679
  }
2280
- return _context18.abrupt("return", []);
1680
+ return _context15.abrupt("return", []);
2281
1681
  case 2:
2282
- _context18.prev = 2;
1682
+ _context15.prev = 2;
2283
1683
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2284
- _context18.next = 8;
1684
+ _context15.next = 8;
2285
1685
  break;
2286
1686
  }
2287
- _context18.next = 6;
1687
+ _context15.next = 6;
2288
1688
  return this.orderDataSource.fetchOrdersByIds(ids);
2289
1689
  case 6:
2290
- _orderList = _context18.sent;
2291
- return _context18.abrupt("return", _orderList || []);
1690
+ _orderList = _context15.sent;
1691
+ return _context15.abrupt("return", _orderList || []);
2292
1692
  case 8:
2293
- _context18.next = 10;
1693
+ _context15.next = 10;
2294
1694
  return this.orderDataSource.run({
2295
1695
  http: {
2296
1696
  query: {
@@ -2299,19 +1699,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2299
1699
  }
2300
1700
  });
2301
1701
  case 10:
2302
- orderList = _context18.sent;
2303
- return _context18.abrupt("return", orderList || []);
1702
+ orderList = _context15.sent;
1703
+ return _context15.abrupt("return", orderList || []);
2304
1704
  case 14:
2305
- _context18.prev = 14;
2306
- _context18.t0 = _context18["catch"](2);
2307
- return _context18.abrupt("return", []);
1705
+ _context15.prev = 14;
1706
+ _context15.t0 = _context15["catch"](2);
1707
+ return _context15.abrupt("return", []);
2308
1708
  case 17:
2309
1709
  case "end":
2310
- return _context18.stop();
1710
+ return _context15.stop();
2311
1711
  }
2312
- }, _callee18, this, [[2, 14]]);
1712
+ }, _callee15, this, [[2, 14]]);
2313
1713
  }));
2314
- function fetchOrdersByHttp(_x12) {
1714
+ function fetchOrdersByHttp(_x8) {
2315
1715
  return _fetchOrdersByHttp.apply(this, arguments);
2316
1716
  }
2317
1717
  return fetchOrdersByHttp;
@@ -2323,11 +1723,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2323
1723
  }, {
2324
1724
  key: "mergeOrdersToStore",
2325
1725
  value: (function () {
2326
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2327
- var _this16 = this;
2328
- var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _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, mergedStorageKey, insertIndex, insertCount, updateCount;
2329
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2330
- while (1) switch (_context19.prev = _context19.next) {
1726
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
1727
+ var _this15 = this;
1728
+ var storeOrderCountBefore, normalizedFreshOrders, _iterator10, _step10, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator11, _step11, key, _iterator12, _step12, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref2, _existingOrder$order_, _ref3, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, mergedOrder, insertIndex, insertCount, updateCount;
1729
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1730
+ while (1) switch (_context16.prev = _context16.next) {
2331
1731
  case 0:
2332
1732
  storeOrderCountBefore = this.store.list.length;
2333
1733
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2337,234 +1737,127 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2337
1737
  });
2338
1738
  this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
2339
1739
  normalizedFreshOrders = [];
2340
- incomingProductsHaveStableIdentity = new Map();
2341
- _iterator14 = _createForOfIteratorHelper(freshOrders);
2342
- _context19.prev = 6;
2343
- _iterator14.s();
2344
- case 8:
2345
- if ((_step14 = _iterator14.n()).done) {
2346
- _context19.next = 18;
1740
+ _iterator10 = _createForOfIteratorHelper(freshOrders);
1741
+ _context16.prev = 5;
1742
+ _iterator10.s();
1743
+ case 7:
1744
+ if ((_step10 = _iterator10.n()).done) {
1745
+ _context16.next = 15;
2347
1746
  break;
2348
1747
  }
2349
- order = _step14.value;
1748
+ order = _step10.value;
2350
1749
  id = order === null || order === void 0 ? void 0 : order.order_id;
2351
1750
  if (!(id === undefined || id === null)) {
2352
- _context19.next = 13;
1751
+ _context16.next = 12;
2353
1752
  break;
2354
1753
  }
2355
- return _context19.abrupt("continue", 16);
2356
- case 13:
2357
- rawProducts = order.products;
2358
- if (Array.isArray(rawProducts)) {
2359
- allProductsHaveStableIdentity = this.doProductsHaveStableMembershipIdentity(rawProducts);
2360
- orderIdKey = this.getIdKey(id);
2361
- incomingProductsHaveStableIdentity.set(orderIdKey, ((_incomingProductsHave = incomingProductsHaveStableIdentity.get(orderIdKey)) !== null && _incomingProductsHave !== void 0 ? _incomingProductsHave : true) && allProductsHaveStableIdentity);
2362
- }
1754
+ return _context16.abrupt("continue", 13);
1755
+ case 12:
2363
1756
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2364
- case 16:
2365
- _context19.next = 8;
1757
+ case 13:
1758
+ _context16.next = 7;
2366
1759
  break;
2367
- case 18:
2368
- _context19.next = 23;
1760
+ case 15:
1761
+ _context16.next = 20;
2369
1762
  break;
1763
+ case 17:
1764
+ _context16.prev = 17;
1765
+ _context16.t0 = _context16["catch"](5);
1766
+ _iterator10.e(_context16.t0);
2370
1767
  case 20:
2371
- _context19.prev = 20;
2372
- _context19.t0 = _context19["catch"](6);
2373
- _iterator14.e(_context19.t0);
1768
+ _context16.prev = 20;
1769
+ _iterator10.f();
1770
+ return _context16.finish(20);
2374
1771
  case 23:
2375
- _context19.prev = 23;
2376
- _iterator14.f();
2377
- return _context19.finish(23);
2378
- case 26:
2379
1772
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2380
1773
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
2381
1774
  uniqueFreshCount = uniqueFreshOrders.length;
2382
1775
  patchedOrders = [];
2383
- remoteProductMembershipChanges = [];
2384
- forceWriteStorageKeys = new Set();
2385
1776
  mergeActions = {};
2386
- existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2387
- return _this16.doProductsHaveStableMembershipIdentity(order.products);
2388
- });
2389
1777
  updatedList = this.store.list.map(function (order) {
2390
- return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
1778
+ return _this15.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2391
1779
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2392
1780
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2393
1781
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
2394
1782
  identityKeyToIndex = new Map();
2395
1783
  for (index = 0; index < updatedList.length; index += 1) {
2396
1784
  identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
2397
- _iterator15 = _createForOfIteratorHelper(identityKeys);
1785
+ _iterator11 = _createForOfIteratorHelper(identityKeys);
2398
1786
  try {
2399
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2400
- key = _step15.value;
1787
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1788
+ key = _step11.value;
2401
1789
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
2402
1790
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
2403
1791
  }
2404
1792
  } catch (err) {
2405
- _iterator15.e(err);
1793
+ _iterator11.e(err);
2406
1794
  } finally {
2407
- _iterator15.f();
1795
+ _iterator11.f();
2408
1796
  }
2409
1797
  }
2410
- _iterator16 = _createForOfIteratorHelper(uniqueFreshOrders);
2411
- _context19.prev = 37;
2412
- _iterator16.s();
2413
- case 39:
2414
- if ((_step16 = _iterator16.n()).done) {
2415
- _context19.next = 96;
1798
+ _iterator12 = _createForOfIteratorHelper(uniqueFreshOrders);
1799
+ _context16.prev = 31;
1800
+ _iterator12.s();
1801
+ case 33:
1802
+ if ((_step12 = _iterator12.n()).done) {
1803
+ _context16.next = 57;
2416
1804
  break;
2417
1805
  }
2418
- fresh = _step16.value;
1806
+ fresh = _step12.value;
2419
1807
  freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
2420
1808
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
2421
1809
  storageKey = this.getOrderStorageKey(fresh);
2422
1810
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2423
1811
  if (!(matchIndex >= 0)) {
2424
- _context19.next = 88;
1812
+ _context16.next = 50;
2425
1813
  break;
2426
1814
  }
2427
1815
  existingOrder = updatedList[matchIndex];
2428
1816
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2429
- _context19.next = 50;
1817
+ _context16.next = 44;
2430
1818
  break;
2431
1819
  }
2432
1820
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
2433
1821
  source: source,
2434
- order_id: (_ref = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref !== void 0 ? _ref : null,
2435
- external_sale_number: (_ref2 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref2 !== void 0 ? _ref2 : null,
1822
+ order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
1823
+ external_sale_number: (_ref3 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
2436
1824
  local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
2437
1825
  remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
2438
1826
  local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
2439
1827
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2440
1828
  reason: 'protect_pending_sync_order_from_remote_echo'
2441
1829
  });
2442
- return _context19.abrupt("continue", 94);
2443
- case 50:
2444
- if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2445
- _context19.next = 53;
2446
- break;
2447
- }
2448
- this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
2449
- source: source,
2450
- order_id: (_ref3 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref3 !== void 0 ? _ref3 : null,
2451
- external_sale_number: (_ref4 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref4 !== void 0 ? _ref4 : null,
2452
- local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
2453
- remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2454
- reason: 'protect_draft_order_from_remote_echo'
2455
- });
2456
- return _context19.abrupt("continue", 94);
2457
- case 53:
1830
+ return _context16.abrupt("continue", 55);
1831
+ case 44:
2458
1832
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2459
- freshOrderId = fresh.order_id;
2460
- incomingProductsAreStable = freshOrderId !== undefined && freshOrderId !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(freshOrderId)) !== false;
2461
- membershipChange = null;
2462
- if (Array.isArray(fresh.products) && freshOrderId !== undefined && freshOrderId !== null && existingProductsHaveStableIdentity[matchIndex] !== false && incomingProductsAreStable) {
2463
- membershipChange = this.getRemoteProductMembershipChange(existingOrder, mergedOrder, source);
2464
- }
2465
- mergedProductsHaveStableIdentity = existingProductsHaveStableIdentity[matchIndex] !== false && incomingProductsAreStable;
2466
- adjustedMatchIndex = matchIndex;
2467
- duplicateIndexes = new Set();
2468
- _iterator17 = _createForOfIteratorHelper(freshIdentityKeys);
2469
- _context19.prev = 62;
2470
- _iterator17.s();
2471
- case 64:
2472
- if ((_step17 = _iterator17.n()).done) {
2473
- _context19.next = 72;
2474
- break;
2475
- }
2476
- _key2 = _step17.value;
2477
- _duplicateIndex = identityKeyToIndex.get(_key2);
2478
- if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2479
- _context19.next = 69;
2480
- break;
2481
- }
2482
- return _context19.abrupt("continue", 70);
2483
- case 69:
2484
- duplicateIndexes.add(_duplicateIndex);
2485
- case 70:
2486
- _context19.next = 64;
2487
- break;
2488
- case 72:
2489
- _context19.next = 77;
2490
- break;
2491
- case 74:
2492
- _context19.prev = 74;
2493
- _context19.t1 = _context19["catch"](62);
2494
- _iterator17.e(_context19.t1);
2495
- case 77:
2496
- _context19.prev = 77;
2497
- _iterator17.f();
2498
- return _context19.finish(77);
2499
- case 80:
2500
- if (duplicateIndexes.size > 0) {
2501
- _iterator18 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2502
- return right - left;
2503
- }));
2504
- try {
2505
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2506
- duplicateIndex = _step18.value;
2507
- mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
2508
- mergedProductsHaveStableIdentity = mergedProductsHaveStableIdentity && existingProductsHaveStableIdentity[duplicateIndex] !== false;
2509
- updatedList.splice(duplicateIndex, 1);
2510
- existingProductsHaveStableIdentity.splice(duplicateIndex, 1);
2511
- if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
2512
- }
2513
- } catch (err) {
2514
- _iterator18.e(err);
2515
- } finally {
2516
- _iterator18.f();
2517
- }
2518
- identityKeyToIndex.clear();
2519
- for (_index = 0; _index < updatedList.length; _index += 1) {
2520
- _iterator19 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
2521
- try {
2522
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2523
- _key = _step19.value;
2524
- if (!identityKeyToIndex.has(_key)) identityKeyToIndex.set(_key, _index);
2525
- }
2526
- } catch (err) {
2527
- _iterator19.e(err);
2528
- } finally {
2529
- _iterator19.f();
2530
- }
2531
- }
2532
- }
2533
- updatedList[adjustedMatchIndex] = mergedOrder;
2534
- existingProductsHaveStableIdentity[adjustedMatchIndex] = mergedProductsHaveStableIdentity;
2535
- if (membershipChange) {
2536
- remoteProductMembershipChanges.push(membershipChange);
2537
- mergedStorageKey = this.getOrderStorageKey(mergedOrder);
2538
- if (mergedStorageKey) forceWriteStorageKeys.add(mergedStorageKey);
2539
- }
1833
+ updatedList[matchIndex] = mergedOrder;
2540
1834
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
2541
1835
  // 供同批后续 fresh 命中同一槽位,避免重复插入
2542
- this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
1836
+ this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
2543
1837
  patchedOrders.push(mergedOrder);
2544
1838
  if (mergeKey) mergeActions[mergeKey] = 'update';
2545
- return _context19.abrupt("continue", 94);
2546
- case 88:
1839
+ return _context16.abrupt("continue", 55);
1840
+ case 50:
2547
1841
  insertIndex = updatedList.length;
2548
1842
  updatedList.push(fresh);
2549
- existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
2550
1843
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
2551
1844
  patchedOrders.push(fresh);
2552
1845
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2553
- case 94:
2554
- _context19.next = 39;
1846
+ case 55:
1847
+ _context16.next = 33;
2555
1848
  break;
2556
- case 96:
2557
- _context19.next = 101;
1849
+ case 57:
1850
+ _context16.next = 62;
2558
1851
  break;
2559
- case 98:
2560
- _context19.prev = 98;
2561
- _context19.t2 = _context19["catch"](37);
2562
- _iterator16.e(_context19.t2);
2563
- case 101:
2564
- _context19.prev = 101;
2565
- _iterator16.f();
2566
- return _context19.finish(101);
2567
- case 104:
1852
+ case 59:
1853
+ _context16.prev = 59;
1854
+ _context16.t1 = _context16["catch"](31);
1855
+ _iterator12.e(_context16.t1);
1856
+ case 62:
1857
+ _context16.prev = 62;
1858
+ _iterator12.f();
1859
+ return _context16.finish(62);
1860
+ case 65:
2568
1861
  insertCount = Object.values(mergeActions).filter(function (v) {
2569
1862
  return v === 'insert';
2570
1863
  }).length;
@@ -2580,27 +1873,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2580
1873
  // 仅在自检开关开启时做一次兜底校验。
2581
1874
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2582
1875
  this.syncOrdersMap();
2583
- _context19.next = 111;
2584
- return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {}, forceWriteStorageKeys);
2585
- case 111:
1876
+ _context16.next = 72;
1877
+ return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1878
+ case 72:
2586
1879
  this.logInfo('mergeOrdersToStore-结束', {
2587
1880
  uniqueFreshCount: uniqueFreshCount,
2588
1881
  storeOrderCountAfter: this.store.list.length,
2589
1882
  insertCount: insertCount,
2590
1883
  updateCount: updateCount
2591
1884
  });
2592
- _context19.next = 114;
2593
- return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2594
- case 114:
2595
- _context19.next = 116;
1885
+ _context16.next = 75;
2596
1886
  return this.emitOrdersChanged(patchedOrders, source);
2597
- case 116:
1887
+ case 75:
2598
1888
  case "end":
2599
- return _context19.stop();
1889
+ return _context16.stop();
2600
1890
  }
2601
- }, _callee19, this, [[6, 20, 23, 26], [37, 98, 101, 104], [62, 74, 77, 80]]);
1891
+ }, _callee16, this, [[5, 17, 20, 23], [31, 59, 62, 65]]);
2602
1892
  }));
2603
- function mergeOrdersToStore(_x13, _x14) {
1893
+ function mergeOrdersToStore(_x9, _x10) {
2604
1894
  return _mergeOrdersToStore.apply(this, arguments);
2605
1895
  }
2606
1896
  return mergeOrdersToStore;
@@ -2617,19 +1907,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2617
1907
  key: "lookupOrderIndexByIdentityKeys",
2618
1908
  value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
2619
1909
  var matchIndex = -1;
2620
- var _iterator20 = _createForOfIteratorHelper(identityKeys),
2621
- _step20;
1910
+ var _iterator13 = _createForOfIteratorHelper(identityKeys),
1911
+ _step13;
2622
1912
  try {
2623
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2624
- var key = _step20.value;
1913
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1914
+ var key = _step13.value;
2625
1915
  var index = identityKeyToIndex.get(key);
2626
1916
  if (index === undefined) continue;
2627
1917
  if (matchIndex < 0 || index < matchIndex) matchIndex = index;
2628
1918
  }
2629
1919
  } catch (err) {
2630
- _iterator20.e(err);
1920
+ _iterator13.e(err);
2631
1921
  } finally {
2632
- _iterator20.f();
1922
+ _iterator13.f();
2633
1923
  }
2634
1924
  return matchIndex;
2635
1925
  }
@@ -2638,92 +1928,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2638
1928
  value: function isRemoteEchoMergeSource(source) {
2639
1929
  return source === 'pubsub.bodyUpsert' || source === 'pubsub.httpRefresh';
2640
1930
  }
2641
- }, {
2642
- key: "getProductMembershipKey",
2643
- value: function getProductMembershipKey(product) {
2644
- var persistentId = getOrderCollectionPersistentId('product', product);
2645
- if (persistentId) return "order_detail_id:".concat(persistentId);
2646
- var uid = getOrderCollectionUid('product', product);
2647
- return uid ? "unique_identification_number:".concat(uid) : '';
2648
- }
2649
- }, {
2650
- key: "doProductsHaveStableMembershipIdentity",
2651
- value: function doProductsHaveStableMembershipIdentity(products) {
2652
- if (!Array.isArray(products)) return true;
2653
- return products.every(function (product) {
2654
- return Boolean(getOrderCollectionPersistentId('product', product) || getOrderCollectionUid('product', product));
2655
- });
2656
- }
2657
-
2658
- /**
2659
- * 冲突提示关注逻辑商品行,而不是服务端 checkout 过程中可能被重建的 detail 记录。
2660
- * 通用集合合并仍以 order_detail_id 为事实主键;这里只允许相同稳定 UID 跨 detail id 对齐,
2661
- * 避免本机 checkout 回声被误判成“一删一增”。
2662
- */
2663
- }, {
2664
- key: "isSameProductMembershipItem",
2665
- value: function isSameProductMembershipItem(left, right) {
2666
- if (isSameOrderCollectionItem('product', left, right)) return true;
2667
- var leftUid = getOrderCollectionUid('product', left);
2668
- var rightUid = getOrderCollectionUid('product', right);
2669
- return Boolean(leftUid && rightUid && leftUid === rightUid);
2670
- }
2671
-
2672
- /**
2673
- * 对比合并前后的商品成员集合。商品字段修改与数组重排不会产生 diff。
2674
- */
2675
- }, {
2676
- key: "getRemoteProductMembershipChange",
2677
- value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2678
- var _this17 = this,
2679
- _mergedOrder$order_id;
2680
- if (!this.isRemoteEchoMergeSource(source)) return null;
2681
- var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
2682
- var currentProducts = Array.isArray(mergedOrder.products) ? mergedOrder.products : [];
2683
- var unmatchedCurrentIndexes = new Set(currentProducts.map(function (_, index) {
2684
- return index;
2685
- }));
2686
- var removedProductKeys = [];
2687
- var _iterator21 = _createForOfIteratorHelper(previousProducts),
2688
- _step21;
2689
- try {
2690
- var _loop2 = function _loop2() {
2691
- var previousProduct = _step21.value;
2692
- var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2693
- return unmatchedCurrentIndexes.has(index) && _this17.isSameProductMembershipItem(previousProduct, currentProduct);
2694
- });
2695
- if (matchedIndex >= 0) {
2696
- unmatchedCurrentIndexes.delete(matchedIndex);
2697
- return 1; // continue
2698
- }
2699
- var productKey = _this17.getProductMembershipKey(previousProduct);
2700
- if (productKey) removedProductKeys.push(productKey);
2701
- };
2702
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2703
- if (_loop2()) continue;
2704
- }
2705
- } catch (err) {
2706
- _iterator21.e(err);
2707
- } finally {
2708
- _iterator21.f();
2709
- }
2710
- var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2711
- return _this17.getProductMembershipKey(currentProducts[index]);
2712
- }).filter(Boolean);
2713
- if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2714
- return null;
2715
- }
2716
- var orderId = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id;
2717
- if (orderId === undefined || orderId === null) return null;
2718
- return {
2719
- order_id: orderId,
2720
- source: source,
2721
- added_product_keys: addedProductKeys,
2722
- removed_product_keys: removedProductKeys,
2723
- previous_product_count: previousProducts.length,
2724
- current_product_count: currentProducts.length
2725
- };
2726
- }
2727
1931
 
2728
1932
  /**
2729
1933
  * 将订单的全部身份键登记到索引并指向其在列表中的下标。
@@ -2736,17 +1940,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2736
1940
  key: "registerOrderIdentityKeys",
2737
1941
  value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
2738
1942
  var identityKeys = this.getOrderIdentityMatchKeys(order);
2739
- var _iterator22 = _createForOfIteratorHelper(identityKeys),
2740
- _step22;
1943
+ var _iterator14 = _createForOfIteratorHelper(identityKeys),
1944
+ _step14;
2741
1945
  try {
2742
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
2743
- var key = _step22.value;
1946
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1947
+ var key = _step14.value;
2744
1948
  identityKeyToIndex.set(key, index);
2745
1949
  }
2746
1950
  } catch (err) {
2747
- _iterator22.e(err);
1951
+ _iterator14.e(err);
2748
1952
  } finally {
2749
- _iterator22.f();
1953
+ _iterator14.f();
2750
1954
  }
2751
1955
  }
2752
1956
 
@@ -2801,17 +2005,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2801
2005
  key: "uniqueOrderIds",
2802
2006
  value: function uniqueOrderIds(ids) {
2803
2007
  var idMap = new Map();
2804
- var _iterator23 = _createForOfIteratorHelper(ids),
2805
- _step23;
2008
+ var _iterator15 = _createForOfIteratorHelper(ids),
2009
+ _step15;
2806
2010
  try {
2807
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
2808
- var id = _step23.value;
2011
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2012
+ var id = _step15.value;
2809
2013
  idMap.set(this.getIdKey(id), id);
2810
2014
  }
2811
2015
  } catch (err) {
2812
- _iterator23.e(err);
2016
+ _iterator15.e(err);
2813
2017
  } finally {
2814
- _iterator23.f();
2018
+ _iterator15.f();
2815
2019
  }
2816
2020
  return _toConsumableArray(idMap.values());
2817
2021
  }
@@ -2823,12 +2027,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2823
2027
  }, {
2824
2028
  key: "isOrderLookupMatch",
2825
2029
  value: function isOrderLookupMatch(order, lookupKey) {
2826
- var _this18 = this;
2030
+ var _this16 = this;
2827
2031
  if (!order || !lookupKey) return false;
2828
2032
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
2829
2033
  return candidates.some(function (value) {
2830
2034
  if (value === undefined || value === null || value === '') return false;
2831
- return _this18.getIdKey(value) === lookupKey;
2035
+ return _this16.getIdKey(value) === lookupKey;
2832
2036
  });
2833
2037
  }
2834
2038
 
@@ -2871,10 +2075,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2871
2075
  }, {
2872
2076
  key: "findOrderIndexByIdentity",
2873
2077
  value: function findOrderIndexByIdentity(orders, target) {
2874
- var _this19 = this;
2078
+ var _this17 = this;
2875
2079
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
2876
2080
  return orders.findIndex(function (order) {
2877
- return _this19.doOrdersShareIdentity(order, target);
2081
+ return _this17.doOrdersShareIdentity(order, target);
2878
2082
  });
2879
2083
  }
2880
2084
  }, {
@@ -2898,121 +2102,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2898
2102
  if (rightScore >= leftScore) return right;
2899
2103
  return left;
2900
2104
  }
2901
- }, {
2902
- key: "getProductIdentityKeys",
2903
- value: function getProductIdentityKeys(product) {
2904
- var _record$metadata;
2905
- var record = product;
2906
- if (!record) return [];
2907
- var keys = [];
2908
- var metadataUid = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.unique_identification_number;
2909
- if (!this.isBlankIdentityValue(metadataUid)) keys.push("uid:".concat(String(metadataUid)));
2910
- var topLevelUid = record.unique_identification_number;
2911
- if (!this.isBlankIdentityValue(topLevelUid)) keys.push("uid:".concat(String(topLevelUid)));
2912
- var orderDetailId = record.order_detail_id;
2913
- if (!this.isBlankIdentityValue(orderDetailId)) keys.push("detail:".concat(String(orderDetailId)));
2914
- var bookingUid = record.booking_uid;
2915
- if (!this.isBlankIdentityValue(bookingUid)) keys.push("booking:".concat(String(bookingUid)));
2916
- return keys;
2917
- }
2918
- }, {
2919
- key: "mergeOrderProductLists",
2920
- value: function mergeOrderProductLists(preferred, secondary) {
2921
- var preferredList = Array.isArray(preferred) ? preferred : [];
2922
- var secondaryList = Array.isArray(secondary) ? secondary : [];
2923
- if (secondaryList.length === 0) return preferredList;
2924
- if (preferredList.length === 0) return secondaryList;
2925
- var seenKeys = new Set();
2926
- var _iterator24 = _createForOfIteratorHelper(preferredList),
2927
- _step24;
2928
- try {
2929
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
2930
- var item = _step24.value;
2931
- var keys = this.getProductIdentityKeys(item);
2932
- var _iterator26 = _createForOfIteratorHelper(keys),
2933
- _step26;
2934
- try {
2935
- for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
2936
- var key = _step26.value;
2937
- seenKeys.add(key);
2938
- }
2939
- } catch (err) {
2940
- _iterator26.e(err);
2941
- } finally {
2942
- _iterator26.f();
2943
- }
2944
- }
2945
- } catch (err) {
2946
- _iterator24.e(err);
2947
- } finally {
2948
- _iterator24.f();
2949
- }
2950
- var result = _toConsumableArray(preferredList);
2951
- var _iterator25 = _createForOfIteratorHelper(secondaryList),
2952
- _step25;
2953
- try {
2954
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
2955
- var _item = _step25.value;
2956
- var _keys = this.getProductIdentityKeys(_item);
2957
- if (_keys.length === 0 || _keys.some(function (key) {
2958
- return seenKeys.has(key);
2959
- })) continue;
2960
- var _iterator27 = _createForOfIteratorHelper(_keys),
2961
- _step27;
2962
- try {
2963
- for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
2964
- var _key3 = _step27.value;
2965
- seenKeys.add(_key3);
2966
- }
2967
- } catch (err) {
2968
- _iterator27.e(err);
2969
- } finally {
2970
- _iterator27.f();
2971
- }
2972
- result.push(cloneDeep(_item));
2973
- }
2974
- } catch (err) {
2975
- _iterator25.e(err);
2976
- } finally {
2977
- _iterator25.f();
2978
- }
2979
- return result;
2980
- }
2981
- }, {
2982
- key: "mergeOrderPaymentLists",
2983
- value: function mergeOrderPaymentLists(existing, incoming) {
2984
- var existingList = Array.isArray(existing) ? existing : [];
2985
- var incomingList = Array.isArray(incoming) ? incoming : [];
2986
- if (incomingList.length === 0) return cloneDeep(existingList);
2987
- return mergeOrderPaymentListsByIdentity(existingList, incomingList);
2988
- }
2989
- }, {
2990
- key: "getIdentifiedPendingPayments",
2991
- value: function getIdentifiedPendingPayments(order) {
2992
- var payments = Array.isArray(order === null || order === void 0 ? void 0 : order.payments) ? order.payments : [];
2993
- return payments.filter(function (payment) {
2994
- return isIdentifiedPendingOrderPayment(payment);
2995
- });
2996
- }
2997
- }, {
2998
- key: "shouldProtectLocalOrderFromRemoteSnapshot",
2999
- value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
3000
- return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
3001
- }
3002
- }, {
3003
- key: "getUnmatchedIdentifiedPendingPayments",
3004
- value: function getUnmatchedIdentifiedPendingPayments(existing, incoming) {
3005
- var existingPayments = Array.isArray(existing) ? existing : [];
3006
- var incomingPayments = Array.isArray(incoming) ? incoming : [];
3007
- var incomingIdentityKeys = new Set(incomingPayments.flatMap(function (payment) {
3008
- return getOrderPaymentIdentityKeys(payment);
3009
- }));
3010
- return existingPayments.filter(function (payment) {
3011
- return isIdentifiedPendingOrderPayment(payment) && !getOrderPaymentIdentityKeys(payment).some(function (key) {
3012
- return incomingIdentityKeys.has(key);
3013
- });
3014
- });
3015
- }
3016
2105
  }, {
3017
2106
  key: "mergeOrderRecords",
3018
2107
  value: function mergeOrderRecords(existing, incoming) {
@@ -3020,7 +2109,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3020
2109
  var secondary = preferred === existing ? incoming : existing;
3021
2110
  var merged = _objectSpread(_objectSpread({}, secondary), preferred);
3022
2111
  var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
3023
- var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms', 'is_draft_order'];
2112
+ var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms'];
3024
2113
  var mergedRecord = merged;
3025
2114
  var preferredRecord = preferred;
3026
2115
  var secondaryRecord = secondary;
@@ -3050,23 +2139,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3050
2139
  for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
3051
2140
  var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
3052
2141
  if (Array.isArray(incomingRecord[_field2])) {
3053
- if (_field2 === 'payments') {
3054
- var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
3055
- if (preservedPending.length > 0) {
3056
- var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
3057
- this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
3058
- order_id: (_ref5 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
3059
- external_sale_number: (_ref6 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref6 !== void 0 ? _ref6 : null,
3060
- preserved_pending_count: preservedPending.length,
3061
- preserved_payment_identities: preservedPending.map(function (payment) {
3062
- return getOrderPaymentIdentityKeys(payment);
3063
- })
3064
- });
3065
- }
3066
- }
3067
- mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps, {
3068
- preserveIdentifiedPendingPayments: _field2 === 'payments'
3069
- });
2142
+ mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps);
3070
2143
  continue;
3071
2144
  }
3072
2145
  if (Object.prototype.hasOwnProperty.call(existingRecord, _field2)) {
@@ -3084,51 +2157,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
2157
  key: "summarizeDuplicateOrders",
3085
2158
  value: function summarizeDuplicateOrders(orders) {
3086
2159
  var groups = new Map();
3087
- var _iterator28 = _createForOfIteratorHelper(orders),
3088
- _step28;
2160
+ var _iterator16 = _createForOfIteratorHelper(orders),
2161
+ _step16;
3089
2162
  try {
3090
- for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
3091
- var order = _step28.value;
3092
- var _iterator29 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3093
- _step29;
2163
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2164
+ var order = _step16.value;
2165
+ var _iterator17 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2166
+ _step17;
3094
2167
  try {
3095
- for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3096
- var key = _step29.value;
2168
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2169
+ var key = _step17.value;
3097
2170
  var group = groups.get(key) || [];
3098
2171
  group.push(order);
3099
2172
  groups.set(key, group);
3100
2173
  }
3101
2174
  } catch (err) {
3102
- _iterator29.e(err);
2175
+ _iterator17.e(err);
3103
2176
  } finally {
3104
- _iterator29.f();
2177
+ _iterator17.f();
3105
2178
  }
3106
2179
  }
3107
2180
  } catch (err) {
3108
- _iterator28.e(err);
2181
+ _iterator16.e(err);
3109
2182
  } finally {
3110
- _iterator28.f();
2183
+ _iterator16.f();
3111
2184
  }
3112
- return _toConsumableArray(groups.entries()).filter(function (_ref7) {
3113
- var _ref8 = _slicedToArray(_ref7, 2),
3114
- group = _ref8[1];
2185
+ return _toConsumableArray(groups.entries()).filter(function (_ref4) {
2186
+ var _ref5 = _slicedToArray(_ref4, 2),
2187
+ group = _ref5[1];
3115
2188
  return group.length > 1;
3116
- }).slice(0, 20).map(function (_ref9) {
3117
- var _ref10 = _slicedToArray(_ref9, 2),
3118
- key = _ref10[0],
3119
- group = _ref10[1];
2189
+ }).slice(0, 20).map(function (_ref6) {
2190
+ var _ref7 = _slicedToArray(_ref6, 2),
2191
+ key = _ref7[0],
2192
+ group = _ref7[1];
3120
2193
  return {
3121
2194
  key: key,
3122
2195
  count: group.length,
3123
2196
  orders: group.map(function (order) {
3124
- var _order$order_id4, _external_sale_number4, _shop_order_number, _shop_full_order_numb, _order$need_sync, _order$is_draft_order;
2197
+ var _order$order_id3, _external_sale_number3, _shop_order_number, _shop_full_order_numb, _order$need_sync;
3125
2198
  return {
3126
- order_id: (_order$order_id4 = order.order_id) !== null && _order$order_id4 !== void 0 ? _order$order_id4 : null,
3127
- external_sale_number: (_external_sale_number4 = order.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : null,
2199
+ order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
2200
+ external_sale_number: (_external_sale_number3 = order.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : null,
3128
2201
  shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
3129
2202
  shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
3130
- need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null,
3131
- is_draft_order: (_order$is_draft_order = order.is_draft_order) !== null && _order$is_draft_order !== void 0 ? _order$is_draft_order : null
2203
+ need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
3132
2204
  };
3133
2205
  })
3134
2206
  };
@@ -3150,11 +2222,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3150
2222
  value: function compactOrderListByIdentity(orders, source) {
3151
2223
  var list = [];
3152
2224
  var removedCount = 0;
3153
- var _iterator30 = _createForOfIteratorHelper(orders),
3154
- _step30;
2225
+ var _iterator18 = _createForOfIteratorHelper(orders),
2226
+ _step18;
3155
2227
  try {
3156
- for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3157
- var order = _step30.value;
2228
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2229
+ var order = _step18.value;
3158
2230
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
3159
2231
  var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
3160
2232
  if (matchIndex < 0) {
@@ -3165,9 +2237,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3165
2237
  removedCount += 1;
3166
2238
  }
3167
2239
  } catch (err) {
3168
- _iterator30.e(err);
2240
+ _iterator18.e(err);
3169
2241
  } finally {
3170
- _iterator30.f();
2242
+ _iterator18.f();
3171
2243
  }
3172
2244
  if (removedCount > 0) {
3173
2245
  this.logWarning('订单列表重复项已压缩', {
@@ -3265,35 +2337,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3265
2337
  }, {
3266
2338
  key: "loadOrdersFromSQLite",
3267
2339
  value: function () {
3268
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3269
- var _this20 = this;
2340
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2341
+ var _this18 = this;
3270
2342
  var orders;
3271
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3272
- while (1) switch (_context20.prev = _context20.next) {
2343
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2344
+ while (1) switch (_context17.prev = _context17.next) {
3273
2345
  case 0:
3274
2346
  if (this.dbManager) {
3275
- _context20.next = 2;
2347
+ _context17.next = 2;
3276
2348
  break;
3277
2349
  }
3278
- return _context20.abrupt("return", []);
2350
+ return _context17.abrupt("return", []);
3279
2351
  case 2:
3280
- _context20.prev = 2;
3281
- _context20.next = 5;
2352
+ _context17.prev = 2;
2353
+ _context17.next = 5;
3282
2354
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3283
2355
  case 5:
3284
- orders = _context20.sent;
3285
- return _context20.abrupt("return", (orders || []).map(function (order) {
3286
- return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
2356
+ orders = _context17.sent;
2357
+ return _context17.abrupt("return", (orders || []).map(function (order) {
2358
+ return _this18.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3287
2359
  }));
3288
2360
  case 9:
3289
- _context20.prev = 9;
3290
- _context20.t0 = _context20["catch"](2);
3291
- return _context20.abrupt("return", []);
2361
+ _context17.prev = 9;
2362
+ _context17.t0 = _context17["catch"](2);
2363
+ return _context17.abrupt("return", []);
3292
2364
  case 12:
3293
2365
  case "end":
3294
- return _context20.stop();
2366
+ return _context17.stop();
3295
2367
  }
3296
- }, _callee20, this, [[2, 9]]);
2368
+ }, _callee17, this, [[2, 9]]);
3297
2369
  }));
3298
2370
  function loadOrdersFromSQLite() {
3299
2371
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3305,71 +2377,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3305
2377
  value: function isPendingSyncOrder(order) {
3306
2378
  return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
3307
2379
  }
3308
- }, {
3309
- key: "isDraftOrder",
3310
- value: function isDraftOrder(order) {
3311
- return Number(order === null || order === void 0 ? void 0 : order.is_draft_order) === 1;
3312
- }
3313
- }, {
3314
- key: "shouldProtectDraftOrderFromIncoming",
3315
- value: function shouldProtectDraftOrderFromIncoming(source) {
3316
- return source !== 'checkoutSync';
3317
- }
3318
2380
  }, {
3319
2381
  key: "normalizeRemoteSyncedOrder",
3320
2382
  value: function normalizeRemoteSyncedOrder(order) {
3321
2383
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'normalizeRemoteSyncedOrder');
3322
- if (this.isPendingSyncOrder(normalizedOrder)) return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
3323
- is_draft_order: 0
3324
- });
2384
+ if (this.isPendingSyncOrder(normalizedOrder)) return normalizedOrder;
3325
2385
  return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
3326
- need_sync: 0,
3327
- is_draft_order: 0
2386
+ need_sync: 0
3328
2387
  });
3329
2388
  }
3330
- }, {
3331
- key: "mergeRemoteIdentityIntoDraftOrder",
3332
- value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3333
- var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3334
- var remote = remoteOrder;
3335
- for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
3336
- var field = _arr[_i7];
3337
- if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3338
- merged[field] = remote[field];
3339
- }
3340
- }
3341
- return this.normalizeOrderCollectionsForIngress(merged, 'mergeRemoteIdentityIntoDraftOrder');
3342
- }
3343
2389
  }, {
3344
2390
  key: "mergeRemoteSnapshotWithPendingOrders",
3345
2391
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3346
- var _this21 = this;
2392
+ var _this19 = this;
3347
2393
  var merged = remoteOrders.map(function (order) {
3348
- return _this21.normalizeRemoteSyncedOrder(order);
2394
+ return _this19.normalizeRemoteSyncedOrder(order);
3349
2395
  });
3350
- var _iterator31 = _createForOfIteratorHelper(existingOrders),
3351
- _step31;
2396
+ var _iterator19 = _createForOfIteratorHelper(existingOrders),
2397
+ _step19;
3352
2398
  try {
3353
- for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3354
- var rawOrder = _step31.value;
2399
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2400
+ var rawOrder = _step19.value;
3355
2401
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3356
- if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
2402
+ if (!this.isPendingSyncOrder(order)) continue;
3357
2403
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
3358
2404
  if (matchIndex >= 0) {
3359
- if (this.isDraftOrder(order)) {
3360
- merged[matchIndex] = this.mergeRemoteIdentityIntoDraftOrder(order, merged[matchIndex]);
3361
- } else {
3362
- merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
3363
- }
2405
+ merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
3364
2406
  continue;
3365
2407
  }
3366
2408
  if (!this.getOrderStorageKey(order)) continue;
3367
2409
  merged.push(order);
3368
2410
  }
3369
2411
  } catch (err) {
3370
- _iterator31.e(err);
2412
+ _iterator19.e(err);
3371
2413
  } finally {
3372
- _iterator31.f();
2414
+ _iterator19.f();
3373
2415
  }
3374
2416
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
3375
2417
  }
@@ -3385,10 +2427,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3385
2427
  }, {
3386
2428
  key: "runInOrderSQLiteSaveQueue",
3387
2429
  value: (function () {
3388
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(task) {
2430
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
3389
2431
  var queuedTask;
3390
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3391
- while (1) switch (_context21.prev = _context21.next) {
2432
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2433
+ while (1) switch (_context18.prev = _context18.next) {
3392
2434
  case 0:
3393
2435
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3394
2436
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3396,14 +2438,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3396
2438
  }, function () {
3397
2439
  return undefined;
3398
2440
  });
3399
- return _context21.abrupt("return", queuedTask);
2441
+ return _context18.abrupt("return", queuedTask);
3400
2442
  case 3:
3401
2443
  case "end":
3402
- return _context21.stop();
2444
+ return _context18.stop();
3403
2445
  }
3404
- }, _callee21, this);
2446
+ }, _callee18, this);
3405
2447
  }));
3406
- function runInOrderSQLiteSaveQueue(_x15) {
2448
+ function runInOrderSQLiteSaveQueue(_x11) {
3407
2449
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3408
2450
  }
3409
2451
  return runInOrderSQLiteSaveQueue;
@@ -3418,176 +2460,146 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3418
2460
  }, {
3419
2461
  key: "patchOrdersInSQLite",
3420
2462
  value: (function () {
3421
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3422
- var _this22 = this;
2463
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
2464
+ var _this20 = this;
3423
2465
  var mergeActions,
3424
- options,
3425
- forceWriteStorageKeys,
3426
2466
  ordersSnapshot,
3427
2467
  _this$filterRedundant2,
3428
2468
  toWrite,
3429
2469
  skipped,
3430
2470
  compactedToWrite,
3431
- _args23 = arguments;
3432
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3433
- while (1) switch (_context23.prev = _context23.next) {
2471
+ _args20 = arguments;
2472
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2473
+ while (1) switch (_context20.prev = _context20.next) {
3434
2474
  case 0:
3435
- mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
3436
- options = _args23.length > 3 && _args23[3] !== undefined ? _args23[3] : {};
3437
- forceWriteStorageKeys = _args23.length > 4 && _args23[4] !== undefined ? _args23[4] : new Set();
3438
- if (!(orders.length === 0)) {
3439
- _context23.next = 5;
3440
- break;
3441
- }
3442
- return _context23.abrupt("return");
3443
- case 5:
3444
- if (this.dbManager) {
3445
- _context23.next = 9;
3446
- break;
3447
- }
3448
- if (!options.throwOnError) {
3449
- _context23.next = 8;
2475
+ mergeActions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2476
+ if (!(!this.dbManager || orders.length === 0)) {
2477
+ _context20.next = 3;
3450
2478
  break;
3451
2479
  }
3452
- throw new Error('订单 SQLite 数据库未初始化');
3453
- case 8:
3454
- return _context23.abrupt("return");
3455
- case 9:
2480
+ return _context20.abrupt("return");
2481
+ case 3:
3456
2482
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3457
- return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
2483
+ return _this20.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3458
2484
  }).filter(function (order) {
3459
- return _this22.getOrderStorageKey(order);
2485
+ return _this20.getOrderStorageKey(order);
3460
2486
  });
3461
2487
  if (!(ordersSnapshot.length === 0)) {
3462
- _context23.next = 12;
2488
+ _context20.next = 6;
3463
2489
  break;
3464
2490
  }
3465
- return _context23.abrupt("return");
3466
- case 12:
3467
- _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
2491
+ return _context20.abrupt("return");
2492
+ case 6:
2493
+ _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3468
2494
  if (!(toWrite.length === 0)) {
3469
- _context23.next = 15;
2495
+ _context20.next = 9;
3470
2496
  break;
3471
2497
  }
3472
- return _context23.abrupt("return");
3473
- case 15:
2498
+ return _context20.abrupt("return");
2499
+ case 9:
3474
2500
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3475
2501
  if (!(compactedToWrite.length === 0)) {
3476
- _context23.next = 18;
2502
+ _context20.next = 12;
3477
2503
  break;
3478
2504
  }
3479
- return _context23.abrupt("return");
3480
- case 18:
3481
- _context23.prev = 18;
3482
- _context23.next = 21;
3483
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3484
- var writeMethod, _iterator32, _step32, order;
3485
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3486
- while (1) switch (_context22.prev = _context22.next) {
2505
+ return _context20.abrupt("return");
2506
+ case 12:
2507
+ _context20.prev = 12;
2508
+ _context20.next = 15;
2509
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2510
+ var writeMethod, _iterator20, _step20, order;
2511
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2512
+ while (1) switch (_context19.prev = _context19.next) {
3487
2513
  case 0:
3488
2514
  writeMethod = 'none';
3489
- _this22.logInfo('patchOrdersInSQLite-开始', {
2515
+ _this20.logInfo('patchOrdersInSQLite-开始', {
3490
2516
  source: source,
3491
2517
  count: compactedToWrite.length,
3492
2518
  dedupedCount: skipped.length
3493
2519
  });
3494
- if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3495
- _context22.next = 8;
2520
+ if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
2521
+ _context19.next = 8;
3496
2522
  break;
3497
2523
  }
3498
2524
  writeMethod = 'bulkUpdate';
3499
- _context22.next = 6;
3500
- return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2525
+ _context19.next = 6;
2526
+ return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3501
2527
  case 6:
3502
- _context22.next = 37;
2528
+ _context19.next = 33;
3503
2529
  break;
3504
2530
  case 8:
3505
- if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3506
- _context22.next = 14;
2531
+ if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
2532
+ _context19.next = 14;
3507
2533
  break;
3508
2534
  }
3509
2535
  writeMethod = 'bulkAdd';
3510
- _context22.next = 12;
3511
- return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2536
+ _context19.next = 12;
2537
+ return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3512
2538
  case 12:
3513
- _context22.next = 37;
2539
+ _context19.next = 33;
3514
2540
  break;
3515
2541
  case 14:
3516
- if (!(typeof _this22.dbManager.update === 'function')) {
3517
- _context22.next = 35;
2542
+ if (!(typeof _this20.dbManager.update === 'function')) {
2543
+ _context19.next = 33;
3518
2544
  break;
3519
2545
  }
3520
2546
  writeMethod = 'update';
3521
- _iterator32 = _createForOfIteratorHelper(compactedToWrite);
3522
- _context22.prev = 17;
3523
- _iterator32.s();
2547
+ _iterator20 = _createForOfIteratorHelper(compactedToWrite);
2548
+ _context19.prev = 17;
2549
+ _iterator20.s();
3524
2550
  case 19:
3525
- if ((_step32 = _iterator32.n()).done) {
3526
- _context22.next = 25;
2551
+ if ((_step20 = _iterator20.n()).done) {
2552
+ _context19.next = 25;
3527
2553
  break;
3528
2554
  }
3529
- order = _step32.value;
3530
- _context22.next = 23;
3531
- return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
2555
+ order = _step20.value;
2556
+ _context19.next = 23;
2557
+ return _this20.dbManager.update(INDEXDB_STORE_NAME, order);
3532
2558
  case 23:
3533
- _context22.next = 19;
2559
+ _context19.next = 19;
3534
2560
  break;
3535
2561
  case 25:
3536
- _context22.next = 30;
2562
+ _context19.next = 30;
3537
2563
  break;
3538
2564
  case 27:
3539
- _context22.prev = 27;
3540
- _context22.t0 = _context22["catch"](17);
3541
- _iterator32.e(_context22.t0);
2565
+ _context19.prev = 27;
2566
+ _context19.t0 = _context19["catch"](17);
2567
+ _iterator20.e(_context19.t0);
3542
2568
  case 30:
3543
- _context22.prev = 30;
3544
- _iterator32.f();
3545
- return _context22.finish(30);
2569
+ _context19.prev = 30;
2570
+ _iterator20.f();
2571
+ return _context19.finish(30);
3546
2572
  case 33:
3547
- _context22.next = 37;
3548
- break;
3549
- case 35:
3550
- if (!options.throwOnError) {
3551
- _context22.next = 37;
3552
- break;
3553
- }
3554
- throw new Error('订单 SQLite 数据库不支持写入');
3555
- case 37:
3556
- _this22.recordRecentSqliteWrite(source, compactedToWrite);
3557
- _this22.logInfo('patchOrdersInSQLite-完成', {
2573
+ _this20.recordRecentSqliteWrite(source, compactedToWrite);
2574
+ _this20.logInfo('patchOrdersInSQLite-完成', {
3558
2575
  source: source,
3559
2576
  count: compactedToWrite.length,
3560
2577
  writeMethod: writeMethod,
3561
2578
  dedupedCount: skipped.length
3562
2579
  });
3563
- case 39:
2580
+ case 35:
3564
2581
  case "end":
3565
- return _context22.stop();
2582
+ return _context19.stop();
3566
2583
  }
3567
- }, _callee22, null, [[17, 27, 30, 33]]);
2584
+ }, _callee19, null, [[17, 27, 30, 33]]);
3568
2585
  })));
3569
- case 21:
3570
- _context23.next = 28;
2586
+ case 15:
2587
+ _context20.next = 20;
3571
2588
  break;
3572
- case 23:
3573
- _context23.prev = 23;
3574
- _context23.t0 = _context23["catch"](18);
2589
+ case 17:
2590
+ _context20.prev = 17;
2591
+ _context20.t0 = _context20["catch"](12);
3575
2592
  this.logError('增量保存订单到 SQLite 失败', {
3576
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
2593
+ error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
3577
2594
  orderCount: ordersSnapshot.length
3578
2595
  });
3579
- if (!options.throwOnError) {
3580
- _context23.next = 28;
3581
- break;
3582
- }
3583
- throw _context23.t0;
3584
- case 28:
2596
+ case 20:
3585
2597
  case "end":
3586
- return _context23.stop();
2598
+ return _context20.stop();
3587
2599
  }
3588
- }, _callee23, this, [[18, 23]]);
2600
+ }, _callee20, this, [[12, 17]]);
3589
2601
  }));
3590
- function patchOrdersInSQLite(_x16, _x17) {
2602
+ function patchOrdersInSQLite(_x12, _x13) {
3591
2603
  return _patchOrdersInSQLite.apply(this, arguments);
3592
2604
  }
3593
2605
  return patchOrdersInSQLite;
@@ -3602,135 +2614,98 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3602
2614
  }, {
3603
2615
  key: "updateOrderInSQLite",
3604
2616
  value: (function () {
3605
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
3606
- var _this23 = this;
3607
- var options,
3608
- orderSnapshot,
3609
- _orderSnapshot$order_3,
3610
- _args25 = arguments;
3611
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3612
- while (1) switch (_context25.prev = _context25.next) {
2617
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
2618
+ var _this21 = this;
2619
+ var orderSnapshot, _orderSnapshot$order_3;
2620
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2621
+ while (1) switch (_context22.prev = _context22.next) {
3613
2622
  case 0:
3614
- options = _args25.length > 2 && _args25[2] !== undefined ? _args25[2] : {};
3615
- if (this.getOrderStorageKey(order)) {
3616
- _context25.next = 5;
2623
+ if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
2624
+ _context22.next = 2;
3617
2625
  break;
3618
2626
  }
3619
- if (!options.throwOnError) {
3620
- _context25.next = 4;
3621
- break;
3622
- }
3623
- throw new Error('订单缺少可用的 SQLite 存储主键');
3624
- case 4:
3625
- return _context25.abrupt("return");
3626
- case 5:
3627
- if (this.dbManager) {
3628
- _context25.next = 9;
3629
- break;
3630
- }
3631
- if (!options.throwOnError) {
3632
- _context25.next = 8;
3633
- break;
3634
- }
3635
- throw new Error('订单 SQLite 数据库未初始化');
3636
- case 8:
3637
- return _context25.abrupt("return");
3638
- case 9:
2627
+ return _context22.abrupt("return");
2628
+ case 2:
3639
2629
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
3640
- _context25.prev = 10;
3641
- _context25.next = 13;
3642
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2630
+ _context22.prev = 3;
2631
+ _context22.next = 6;
2632
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3643
2633
  var _orderSnapshot$order_, _orderSnapshot$order_2;
3644
2634
  var writeMethod;
3645
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3646
- while (1) switch (_context24.prev = _context24.next) {
2635
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2636
+ while (1) switch (_context21.prev = _context21.next) {
3647
2637
  case 0:
3648
2638
  writeMethod = 'none';
3649
- _this23.logInfo('updateOrderInSQLite-开始', {
2639
+ _this21.logInfo('updateOrderInSQLite-开始', {
3650
2640
  source: source,
3651
2641
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
3652
- storageKey: _this23.getOrderStorageKey(orderSnapshot)
2642
+ storageKey: _this21.getOrderStorageKey(orderSnapshot)
3653
2643
  });
3654
- if (!(typeof _this23.dbManager.update === 'function')) {
3655
- _context24.next = 8;
2644
+ if (!(typeof _this21.dbManager.update === 'function')) {
2645
+ _context21.next = 8;
3656
2646
  break;
3657
2647
  }
3658
2648
  writeMethod = 'update';
3659
- _context24.next = 6;
3660
- return _this23.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2649
+ _context21.next = 6;
2650
+ return _this21.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3661
2651
  case 6:
3662
- _context24.next = 22;
2652
+ _context21.next = 18;
3663
2653
  break;
3664
2654
  case 8:
3665
- if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3666
- _context24.next = 14;
2655
+ if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
2656
+ _context21.next = 14;
3667
2657
  break;
3668
2658
  }
3669
2659
  writeMethod = 'bulkUpdate';
3670
- _context24.next = 12;
3671
- return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2660
+ _context21.next = 12;
2661
+ return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3672
2662
  case 12:
3673
- _context24.next = 22;
2663
+ _context21.next = 18;
3674
2664
  break;
3675
2665
  case 14:
3676
- if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3677
- _context24.next = 20;
2666
+ if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
2667
+ _context21.next = 18;
3678
2668
  break;
3679
2669
  }
3680
2670
  writeMethod = 'bulkAdd';
3681
- _context24.next = 18;
3682
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2671
+ _context21.next = 18;
2672
+ return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3683
2673
  case 18:
3684
- _context24.next = 22;
3685
- break;
3686
- case 20:
3687
- if (!options.throwOnError) {
3688
- _context24.next = 22;
3689
- break;
3690
- }
3691
- throw new Error('订单 SQLite 数据库不支持写入');
3692
- case 22:
3693
- _this23.recordRecentSqliteWrite(source, [orderSnapshot]);
3694
- _this23.logInfo('updateOrderInSQLite-完成', {
2674
+ _this21.recordRecentSqliteWrite(source, [orderSnapshot]);
2675
+ _this21.logInfo('updateOrderInSQLite-完成', {
3695
2676
  source: source,
3696
2677
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
3697
2678
  writeMethod: writeMethod
3698
2679
  });
3699
- case 24:
2680
+ case 20:
3700
2681
  case "end":
3701
- return _context24.stop();
2682
+ return _context21.stop();
3702
2683
  }
3703
- }, _callee24);
2684
+ }, _callee21);
3704
2685
  })));
3705
- case 13:
3706
- _context25.next = 20;
2686
+ case 6:
2687
+ _context22.next = 11;
3707
2688
  break;
3708
- case 15:
3709
- _context25.prev = 15;
3710
- _context25.t0 = _context25["catch"](10);
2689
+ case 8:
2690
+ _context22.prev = 8;
2691
+ _context22.t0 = _context22["catch"](3);
3711
2692
  this.logError('单条保存订单到 SQLite 失败', {
3712
- error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0),
2693
+ error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
3713
2694
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
3714
2695
  });
3715
- if (!options.throwOnError) {
3716
- _context25.next = 20;
3717
- break;
3718
- }
3719
- throw _context25.t0;
3720
- case 20:
2696
+ case 11:
3721
2697
  case "end":
3722
- return _context25.stop();
2698
+ return _context22.stop();
3723
2699
  }
3724
- }, _callee25, this, [[10, 15]]);
2700
+ }, _callee22, this, [[3, 8]]);
3725
2701
  }));
3726
- function updateOrderInSQLite(_x18, _x19) {
2702
+ function updateOrderInSQLite(_x14, _x15) {
3727
2703
  return _updateOrderInSQLite.apply(this, arguments);
3728
2704
  }
3729
2705
  return updateOrderInSQLite;
3730
2706
  }()
3731
2707
  /**
3732
- * 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync / pending 支付订单。
3733
- * 用于 SSE 全量拉取与营业日窗口裁剪。
2708
+ * 全量快照替换 orders 表(clear + bulkAdd),用于 SSE 全量拉取与营业日窗口裁剪。
3734
2709
  *
3735
2710
  * @example
3736
2711
  * await this.replaceOrdersSnapshotInSQLite(orderList)
@@ -3739,163 +2714,100 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3739
2714
  }, {
3740
2715
  key: "replaceOrdersSnapshotInSQLite",
3741
2716
  value: (function () {
3742
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
3743
- var _this24 = this;
3744
- var protectedOrdersBeforeRemoteFetch,
3745
- remoteSnapshot,
3746
- mergedSnapshot,
3747
- _args27 = arguments;
3748
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3749
- while (1) switch (_context27.prev = _context27.next) {
2717
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
2718
+ var _this22 = this;
2719
+ var remoteSnapshot, mergedSnapshot;
2720
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2721
+ while (1) switch (_context24.prev = _context24.next) {
3750
2722
  case 0:
3751
- protectedOrdersBeforeRemoteFetch = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : [];
3752
2723
  if (this.dbManager) {
3753
- _context27.next = 3;
2724
+ _context24.next = 2;
3754
2725
  break;
3755
2726
  }
3756
- return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3757
- return _this24.normalizeRemoteSyncedOrder(order);
2727
+ return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
2728
+ return _this22.normalizeRemoteSyncedOrder(order);
3758
2729
  }), "".concat(source, ".snapshotNoDb")).list);
3759
- case 3:
2730
+ case 2:
3760
2731
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
3761
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
2732
+ return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3762
2733
  });
3763
2734
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
3764
- return _this24.normalizeRemoteSyncedOrder(order);
2735
+ return _this22.normalizeRemoteSyncedOrder(order);
3765
2736
  }), "".concat(source, ".remoteSnapshot")).list;
3766
- _context27.prev = 5;
3767
- _context27.next = 8;
3768
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3769
- var existingOrders, protectedLocalOrders, _iterator33, _step33, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3770
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3771
- while (1) switch (_context26.prev = _context26.next) {
2737
+ _context24.prev = 4;
2738
+ _context24.next = 7;
2739
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2740
+ var existingOrders, orderListSnapshot;
2741
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2742
+ while (1) switch (_context23.prev = _context23.next) {
3772
2743
  case 0:
3773
- if (!(typeof _this24.dbManager.getAll === 'function')) {
3774
- _context26.next = 6;
2744
+ if (!(typeof _this22.dbManager.getAll === 'function')) {
2745
+ _context23.next = 6;
3775
2746
  break;
3776
2747
  }
3777
- _context26.next = 3;
3778
- return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
2748
+ _context23.next = 3;
2749
+ return _this22.dbManager.getAll(INDEXDB_STORE_NAME);
3779
2750
  case 3:
3780
- _context26.t0 = _context26.sent;
3781
- _context26.next = 7;
2751
+ _context23.t0 = _context23.sent;
2752
+ _context23.next = 7;
3782
2753
  break;
3783
2754
  case 6:
3784
- _context26.t0 = [];
2755
+ _context23.t0 = [];
3785
2756
  case 7:
3786
- existingOrders = _context26.t0;
3787
- protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
3788
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3789
- }).filter(function (order) {
3790
- return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
3791
- });
3792
- _iterator33 = _createForOfIteratorHelper(existingOrders || []);
3793
- _context26.prev = 10;
3794
- _iterator33.s();
3795
- case 12:
3796
- if ((_step33 = _iterator33.n()).done) {
3797
- _context26.next = 23;
3798
- break;
3799
- }
3800
- rawCurrentOrder = _step33.value;
3801
- currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3802
- protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3803
- currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3804
- if (!(protectedIndex >= 0)) {
3805
- _context26.next = 20;
3806
- break;
3807
- }
3808
- if (currentNeedsProtection) {
3809
- protectedLocalOrders[protectedIndex] = currentOrder;
3810
- } else {
3811
- protectedLocalOrders.splice(protectedIndex, 1);
3812
- }
3813
- return _context26.abrupt("continue", 21);
3814
- case 20:
3815
- if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
3816
- case 21:
3817
- _context26.next = 12;
3818
- break;
3819
- case 23:
3820
- _context26.next = 28;
3821
- break;
3822
- case 25:
3823
- _context26.prev = 25;
3824
- _context26.t1 = _context26["catch"](10);
3825
- _iterator33.e(_context26.t1);
3826
- case 28:
3827
- _context26.prev = 28;
3828
- _iterator33.f();
3829
- return _context26.finish(28);
3830
- case 31:
3831
- orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3832
- mergedSnapshot = _this24.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3833
- _this24.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2757
+ existingOrders = _context23.t0;
2758
+ orderListSnapshot = _this22.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2759
+ mergedSnapshot = _this22.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2760
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3834
2761
  source: source,
3835
2762
  count: mergedSnapshot.length,
3836
2763
  remoteCount: remoteSnapshot.length,
3837
- protectedBeforeRemoteFetchCount: protectedOrdersBeforeRemoteFetch.length,
3838
- protectedLocalOrderCount: protectedLocalOrders.length,
3839
- preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
3840
- protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
3841
- return count + _this24.getIdentifiedPendingPayments(order).length;
3842
- }, 0),
3843
- protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
3844
- return _this24.getIdentifiedPendingPayments(order).map(function (payment) {
3845
- var _order$order_id5, _external_sale_number5;
3846
- return {
3847
- order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
3848
- external_sale_number: (_external_sale_number5 = order.external_sale_number) !== null && _external_sale_number5 !== void 0 ? _external_sale_number5 : null,
3849
- payment_identities: getOrderPaymentIdentityKeys(payment)
3850
- };
3851
- });
3852
- })
2764
+ preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
3853
2765
  });
3854
- _context26.next = 36;
3855
- return _this24.dbManager.clear(INDEXDB_STORE_NAME);
3856
- case 36:
3857
- _this24.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2766
+ _context23.next = 13;
2767
+ return _this22.dbManager.clear(INDEXDB_STORE_NAME);
2768
+ case 13:
2769
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
3858
2770
  count: mergedSnapshot.length
3859
2771
  });
3860
2772
  if (!(mergedSnapshot.length === 0)) {
3861
- _context26.next = 39;
2773
+ _context23.next = 16;
3862
2774
  break;
3863
2775
  }
3864
- return _context26.abrupt("return");
3865
- case 39:
3866
- _context26.next = 41;
3867
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
3868
- case 41:
3869
- _this24.recordRecentSqliteWrite(source, mergedSnapshot);
3870
- _this24.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2776
+ return _context23.abrupt("return");
2777
+ case 16:
2778
+ _context23.next = 18;
2779
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2780
+ case 18:
2781
+ _this22.recordRecentSqliteWrite(source, mergedSnapshot);
2782
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
3871
2783
  source: source,
3872
2784
  count: mergedSnapshot.length
3873
2785
  });
3874
- case 43:
2786
+ case 20:
3875
2787
  case "end":
3876
- return _context26.stop();
2788
+ return _context23.stop();
3877
2789
  }
3878
- }, _callee26, null, [[10, 25, 28, 31]]);
2790
+ }, _callee23);
3879
2791
  })));
3880
- case 8:
3881
- _context27.next = 13;
2792
+ case 7:
2793
+ _context24.next = 12;
3882
2794
  break;
3883
- case 10:
3884
- _context27.prev = 10;
3885
- _context27.t0 = _context27["catch"](5);
2795
+ case 9:
2796
+ _context24.prev = 9;
2797
+ _context24.t0 = _context24["catch"](4);
3886
2798
  this.logError('全量保存订单到 SQLite 失败', {
3887
- error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
2799
+ error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
3888
2800
  orderList: remoteSnapshot.length
3889
2801
  });
2802
+ case 12:
2803
+ return _context24.abrupt("return", mergedSnapshot);
3890
2804
  case 13:
3891
- return _context27.abrupt("return", mergedSnapshot);
3892
- case 14:
3893
2805
  case "end":
3894
- return _context27.stop();
2806
+ return _context24.stop();
3895
2807
  }
3896
- }, _callee27, this, [[5, 10]]);
2808
+ }, _callee24, this, [[4, 9]]);
3897
2809
  }));
3898
- function replaceOrdersSnapshotInSQLite(_x20, _x21) {
2810
+ function replaceOrdersSnapshotInSQLite(_x16, _x17) {
3899
2811
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
3900
2812
  }
3901
2813
  return replaceOrdersSnapshotInSQLite;
@@ -3910,38 +2822,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3910
2822
  }, {
3911
2823
  key: "clear",
3912
2824
  value: (function () {
3913
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
3914
- var _this25 = this;
3915
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
3916
- while (1) switch (_context29.prev = _context29.next) {
2825
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2826
+ var _this23 = this;
2827
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2828
+ while (1) switch (_context26.prev = _context26.next) {
3917
2829
  case 0:
3918
2830
  this.store.list = [];
3919
2831
  this.store.map = new Map();
3920
2832
  if (!this.dbManager) {
3921
- _context29.next = 5;
2833
+ _context26.next = 5;
3922
2834
  break;
3923
2835
  }
3924
- _context29.next = 5;
3925
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3926
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
3927
- while (1) switch (_context28.prev = _context28.next) {
2836
+ _context26.next = 5;
2837
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2838
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2839
+ while (1) switch (_context25.prev = _context25.next) {
3928
2840
  case 0:
3929
- _context28.next = 2;
3930
- return _this25.dbManager.clear(INDEXDB_STORE_NAME);
2841
+ _context25.next = 2;
2842
+ return _this23.dbManager.clear(INDEXDB_STORE_NAME);
3931
2843
  case 2:
3932
2844
  case "end":
3933
- return _context28.stop();
2845
+ return _context25.stop();
3934
2846
  }
3935
- }, _callee28);
2847
+ }, _callee25);
3936
2848
  })));
3937
2849
  case 5:
3938
2850
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
3939
2851
  this.emitOrdersChanged([], 'clear');
3940
2852
  case 7:
3941
2853
  case "end":
3942
- return _context29.stop();
2854
+ return _context26.stop();
3943
2855
  }
3944
- }, _callee29, this);
2856
+ }, _callee26, this);
3945
2857
  }));
3946
2858
  function clear() {
3947
2859
  return _clear.apply(this, arguments);