@pisell/pisellos 0.10.90 → 0.10.93

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 (229) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  6. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  7. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  8. package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
  14. package/dist/modules/BookingContext/utils/productExtend.js +132 -33
  15. package/dist/modules/BookingContext/utils/resources.js +1 -1
  16. package/dist/modules/Cart/index.js +4 -3
  17. package/dist/modules/Cart/types.d.ts +2 -0
  18. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  19. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  20. package/dist/modules/Date/index.d.ts +1 -1
  21. package/dist/modules/Date/index.js +60 -14
  22. package/dist/modules/Date/types.d.ts +5 -0
  23. package/dist/modules/OpenData/salesSettings.js +1 -1
  24. package/dist/modules/OpenData/types.d.ts +9 -0
  25. package/dist/modules/OpenData/utils.d.ts +1 -1
  26. package/dist/modules/OpenData/utils.js +3 -2
  27. package/dist/modules/Order/index.d.ts +22 -7
  28. package/dist/modules/Order/index.js +1565 -1161
  29. package/dist/modules/Order/localEftposState.d.ts +13 -0
  30. package/dist/modules/Order/localEftposState.js +39 -0
  31. package/dist/modules/Order/types.d.ts +33 -11
  32. package/dist/modules/Order/types.js +2 -2
  33. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  34. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  35. package/dist/modules/Order/utils.d.ts +4 -1
  36. package/dist/modules/Order/utils.js +75 -52
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/index.d.ts +1 -1
  39. package/dist/modules/Product/types.d.ts +16 -0
  40. package/dist/modules/ProductList/index.js +1 -1
  41. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  42. package/dist/modules/ResourcePlanner/planner.js +383 -24
  43. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  44. package/dist/modules/Rules/index.js +86 -54
  45. package/dist/modules/Schedule/index.d.ts +7 -1
  46. package/dist/modules/Schedule/index.js +155 -39
  47. package/dist/modules/Schedule/types.d.ts +2 -0
  48. package/dist/modules/bookingReadValidation.d.ts +6 -0
  49. package/dist/modules/bookingReadValidation.js +72 -0
  50. package/dist/plugins/request.d.ts +2 -0
  51. package/dist/server/index.d.ts +9 -0
  52. package/dist/server/index.js +1928 -1462
  53. package/dist/server/modules/form/index.d.ts +19 -0
  54. package/dist/server/modules/form/index.js +205 -0
  55. package/dist/server/modules/form/types.d.ts +13 -0
  56. package/dist/server/modules/form/types.js +3 -0
  57. package/dist/server/modules/index.d.ts +3 -0
  58. package/dist/server/modules/index.js +4 -0
  59. package/dist/server/modules/order/index.d.ts +21 -0
  60. package/dist/server/modules/order/index.js +1399 -831
  61. package/dist/server/modules/order/types.d.ts +3 -0
  62. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  63. package/dist/server/modules/products/index.d.ts +28 -7
  64. package/dist/server/modules/products/index.js +1295 -769
  65. package/dist/server/modules/products/replication.d.ts +8 -0
  66. package/dist/server/modules/products/replication.js +69 -0
  67. package/dist/server/modules/products/types.d.ts +12 -1
  68. package/dist/server/modules/products/types.js +4 -0
  69. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  70. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  71. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  72. package/dist/shared/receipt/small-ticket.js +58 -26
  73. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  74. package/dist/shared/receipt/templateVisibility.js +6 -2
  75. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  76. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  77. package/dist/solution/BaseSales/index.d.ts +22 -6
  78. package/dist/solution/BaseSales/index.js +1881 -1347
  79. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  80. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  81. package/dist/solution/BaseSales/types.d.ts +4 -0
  82. package/dist/solution/BaseSales/types.js +1 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  84. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  86. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  87. package/dist/solution/BookingByStep/index.d.ts +20 -4
  88. package/dist/solution/BookingByStep/index.js +681 -361
  89. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  90. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  91. package/dist/solution/BookingTicket/index.d.ts +10 -0
  92. package/dist/solution/BookingTicket/index.js +686 -598
  93. package/dist/solution/BookingTicket/types.d.ts +1 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  95. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  96. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  98. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  99. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  101. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  102. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  103. package/dist/solution/Sales/index.js +1 -1
  104. package/dist/solution/ScanOrder/index.d.ts +2 -0
  105. package/dist/solution/ScanOrder/index.js +230 -97
  106. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  107. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  108. package/dist/solution/ScanOrder/types.d.ts +3 -0
  109. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  110. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  111. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  112. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  113. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  114. package/dist/utils/pos-receipt-auto-print.js +14 -0
  115. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  116. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  117. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  118. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  119. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  120. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  121. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  122. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  123. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  124. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  125. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  126. package/lib/modules/BookingContext/utils/index.js +11 -0
  127. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  128. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  129. package/lib/modules/BookingContext/utils/resources.js +1 -1
  130. package/lib/modules/Cart/index.js +4 -2
  131. package/lib/modules/Cart/types.d.ts +2 -0
  132. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  133. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  134. package/lib/modules/Date/index.d.ts +1 -1
  135. package/lib/modules/Date/index.js +28 -5
  136. package/lib/modules/Date/types.d.ts +5 -0
  137. package/lib/modules/OpenData/salesSettings.js +1 -1
  138. package/lib/modules/OpenData/types.d.ts +9 -0
  139. package/lib/modules/OpenData/utils.d.ts +1 -1
  140. package/lib/modules/OpenData/utils.js +3 -2
  141. package/lib/modules/Order/index.d.ts +22 -7
  142. package/lib/modules/Order/index.js +457 -174
  143. package/lib/modules/Order/localEftposState.d.ts +13 -0
  144. package/lib/modules/Order/localEftposState.js +44 -0
  145. package/lib/modules/Order/types.d.ts +33 -11
  146. package/lib/modules/Order/types.js +2 -2
  147. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  148. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  149. package/lib/modules/Order/utils.d.ts +4 -1
  150. package/lib/modules/Order/utils.js +29 -3
  151. package/lib/modules/Payment/walletpass.js +23 -1
  152. package/lib/modules/Product/index.d.ts +1 -1
  153. package/lib/modules/Product/types.d.ts +16 -0
  154. package/lib/modules/ProductList/index.js +1 -1
  155. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  156. package/lib/modules/ResourcePlanner/planner.js +299 -9
  157. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  158. package/lib/modules/Rules/index.js +32 -3
  159. package/lib/modules/Schedule/index.d.ts +7 -1
  160. package/lib/modules/Schedule/index.js +68 -4
  161. package/lib/modules/Schedule/types.d.ts +2 -0
  162. package/lib/modules/bookingReadValidation.d.ts +6 -0
  163. package/lib/modules/bookingReadValidation.js +56 -0
  164. package/lib/plugins/request.d.ts +2 -0
  165. package/lib/server/index.d.ts +9 -0
  166. package/lib/server/index.js +279 -30
  167. package/lib/server/modules/form/index.d.ts +19 -0
  168. package/lib/server/modules/form/index.js +73 -0
  169. package/lib/server/modules/form/types.d.ts +13 -0
  170. package/lib/server/modules/form/types.js +9 -0
  171. package/lib/server/modules/index.d.ts +3 -0
  172. package/lib/server/modules/index.js +15 -1
  173. package/lib/server/modules/order/index.d.ts +21 -0
  174. package/lib/server/modules/order/index.js +344 -35
  175. package/lib/server/modules/order/types.d.ts +3 -0
  176. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  177. package/lib/server/modules/products/index.d.ts +28 -7
  178. package/lib/server/modules/products/index.js +224 -62
  179. package/lib/server/modules/products/replication.d.ts +8 -0
  180. package/lib/server/modules/products/replication.js +30 -0
  181. package/lib/server/modules/products/types.d.ts +12 -1
  182. package/lib/server/modules/products/types.js +3 -0
  183. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  184. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  185. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  186. package/lib/shared/receipt/small-ticket.js +53 -25
  187. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  188. package/lib/shared/receipt/templateVisibility.js +6 -2
  189. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  190. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  191. package/lib/solution/BaseSales/index.d.ts +22 -6
  192. package/lib/solution/BaseSales/index.js +347 -59
  193. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  194. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  195. package/lib/solution/BaseSales/types.d.ts +4 -0
  196. package/lib/solution/BaseSales/types.js +1 -0
  197. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  198. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  199. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  200. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  201. package/lib/solution/BookingByStep/index.d.ts +20 -4
  202. package/lib/solution/BookingByStep/index.js +229 -17
  203. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  204. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  205. package/lib/solution/BookingTicket/index.d.ts +10 -0
  206. package/lib/solution/BookingTicket/index.js +57 -6
  207. package/lib/solution/BookingTicket/types.d.ts +1 -1
  208. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  209. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  210. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
  211. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  212. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  213. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  214. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  215. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  216. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  217. package/lib/solution/Sales/index.js +1 -1
  218. package/lib/solution/ScanOrder/index.d.ts +2 -0
  219. package/lib/solution/ScanOrder/index.js +131 -22
  220. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  221. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  222. package/lib/solution/ScanOrder/types.d.ts +3 -0
  223. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  224. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  225. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  226. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  227. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  228. package/lib/utils/pos-receipt-auto-print.js +13 -0
  229. package/package.json +1 -1
@@ -31,8 +31,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
31
31
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
33
  import { cloneDeep, isEqual } from 'lodash-es';
34
+ import { isLocalFinalizedPayment, LOCAL_EFTPOS_FINALIZED, LOCAL_EFTPOS_REFRESH_REQUIRED, requiresLocalPaymentRefresh } from "../../../modules/Order/localEftposState";
34
35
  import dayjs from 'dayjs';
35
36
  import { BaseModule } from "../../../modules/BaseModule";
37
+ import { normalizeUnpaidOrderAmountGap } from "../../../modules/Order/unpaidAmountGap";
36
38
  import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
37
39
  import { OrderHooks } from "./types";
38
40
  import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
@@ -374,7 +376,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
374
376
  this.logInfo('订单子项身份已规范化', context);
375
377
  }
376
378
  }
377
- return result.order;
379
+ return normalizeUnpaidOrderAmountGap(result.order);
378
380
  }
379
381
 
380
382
  /**
@@ -387,9 +389,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
387
389
  var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
388
390
  var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
389
391
  var existingItems = Array.isArray(existing) ? existing : [];
390
- if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
392
+ if (field === 'payments' && (options.preserveIdentifiedPendingPayments || existingItems.some(isLocalFinalizedPayment))) {
391
393
  return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
392
- preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
394
+ preserveUnmatchedExistingWhen: function preserveUnmatchedExistingWhen(payment) {
395
+ return options.preserveIdentifiedPendingPayments === true && isIdentifiedPendingOrderPayment(payment) || isLocalFinalizedPayment(payment);
396
+ }
393
397
  });
394
398
  }
395
399
  return incoming.map(function (incomingItem) {
@@ -538,7 +542,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
538
542
  continue;
539
543
  }
540
544
 
541
- // 远端商品成员或 Holder 关系确实变化时必须落库,避免被回声窗口跳过。
545
+ // 远端商品成员、Holder 关系或预约数据确实变化时必须落库,避免被回声窗口跳过。
542
546
  if (forceWriteStorageKeys.has(storageKey)) {
543
547
  toWrite.push(order);
544
548
  continue;
@@ -889,11 +893,91 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
889
893
  });
890
894
  return memoryOrder || null;
891
895
  }
896
+
897
+ /** Read-only payment gate lookup; never hydrate the whole order list on a miss. */
898
+ }, {
899
+ key: "getLocalOrderForPaymentReadiness",
900
+ value: (function () {
901
+ var _getLocalOrderForPaymentReadiness = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
902
+ var _this$dbManager,
903
+ _this4 = this;
904
+ var memoryOrder, key, fields, candidates, _i2, _fields, column, rows;
905
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
906
+ while (1) switch (_context5.prev = _context5.next) {
907
+ case 0:
908
+ if (!(lookup === undefined || lookup === null || lookup === '')) {
909
+ _context5.next = 2;
910
+ break;
911
+ }
912
+ return _context5.abrupt("return", null);
913
+ case 2:
914
+ memoryOrder = this.getLocalOrderFromMemoryByLookup(lookup);
915
+ if (!memoryOrder) {
916
+ _context5.next = 5;
917
+ break;
918
+ }
919
+ return _context5.abrupt("return", memoryOrder);
920
+ case 5:
921
+ if (!(typeof ((_this$dbManager = this.dbManager) === null || _this$dbManager === void 0 ? void 0 : _this$dbManager.find) !== 'function')) {
922
+ _context5.next = 7;
923
+ break;
924
+ }
925
+ return _context5.abrupt("return", this.getLocalOrderByLookup(lookup));
926
+ case 7:
927
+ key = this.getIdKey(lookup);
928
+ fields = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
929
+ candidates = [];
930
+ _i2 = 0, _fields = fields;
931
+ case 11:
932
+ if (!(_i2 < _fields.length)) {
933
+ _context5.next = 20;
934
+ break;
935
+ }
936
+ column = _fields[_i2];
937
+ _context5.next = 15;
938
+ return this.dbManager.find(INDEXDB_STORE_NAME, {
939
+ filters: [{
940
+ column: column,
941
+ op: '=',
942
+ value: key
943
+ }],
944
+ orderBy: [{
945
+ column: '__order_storage_key',
946
+ dir: 'asc'
947
+ }],
948
+ limit: 1
949
+ });
950
+ case 15:
951
+ rows = _context5.sent;
952
+ if (rows !== null && rows !== void 0 && rows[0] && this.isOrderLookupMatch(rows[0], key)) candidates.push(rows[0]);
953
+ case 17:
954
+ _i2++;
955
+ _context5.next = 11;
956
+ break;
957
+ case 20:
958
+ candidates.sort(function (left, right) {
959
+ var _order_storage_key, _order_storage_key2;
960
+ var leftKey = String((_order_storage_key = left.__order_storage_key) !== null && _order_storage_key !== void 0 ? _order_storage_key : _this4.getOrderStorageKey(left));
961
+ var rightKey = String((_order_storage_key2 = right.__order_storage_key) !== null && _order_storage_key2 !== void 0 ? _order_storage_key2 : _this4.getOrderStorageKey(right));
962
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
963
+ });
964
+ return _context5.abrupt("return", candidates.length ? this.normalizeOrderForMemoryList(candidates[0], 'paymentReadiness.sqlite') : null);
965
+ case 22:
966
+ case "end":
967
+ return _context5.stop();
968
+ }
969
+ }, _callee5, this);
970
+ }));
971
+ function getLocalOrderForPaymentReadiness(_x4) {
972
+ return _getLocalOrderForPaymentReadiness.apply(this, arguments);
973
+ }
974
+ return getLocalOrderForPaymentReadiness;
975
+ }())
892
976
  }, {
893
977
  key: "getLocalOrderByLookup",
894
978
  value: function () {
895
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
896
- var _this4 = this;
979
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lookup) {
980
+ var _this5 = this;
897
981
  var options,
898
982
  key,
899
983
  logContext,
@@ -902,11 +986,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
902
986
  orders,
903
987
  localOrder,
904
988
  normalizedOrder,
905
- _args5 = arguments;
906
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
907
- while (1) switch (_context5.prev = _context5.next) {
989
+ _args6 = arguments;
990
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
991
+ while (1) switch (_context6.prev = _context6.next) {
908
992
  case 0:
909
- options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
993
+ options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
910
994
  key = this.getIdKey(lookup);
911
995
  logContext = {
912
996
  operation_id: options.operationId,
@@ -918,38 +1002,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
918
1002
  }
919
1003
  memoryOrderById = this.store.map.get(key);
920
1004
  if (!memoryOrderById) {
921
- _context5.next = 8;
1005
+ _context6.next = 8;
922
1006
  break;
923
1007
  }
924
1008
  if (options.operationId) {
925
1009
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
926
1010
  }
927
- return _context5.abrupt("return", memoryOrderById);
1011
+ return _context6.abrupt("return", memoryOrderById);
928
1012
  case 8:
929
1013
  memoryOrder = this.store.list.find(function (order) {
930
- return _this4.isOrderLookupMatch(order, key);
1014
+ return _this5.isOrderLookupMatch(order, key);
931
1015
  });
932
1016
  if (!memoryOrder) {
933
- _context5.next = 12;
1017
+ _context6.next = 12;
934
1018
  break;
935
1019
  }
936
1020
  if (options.operationId) {
937
1021
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
938
1022
  }
939
- return _context5.abrupt("return", memoryOrder);
1023
+ return _context6.abrupt("return", memoryOrder);
940
1024
  case 12:
941
1025
  if (options.operationId) {
942
1026
  this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
943
1027
  }
944
- _context5.next = 15;
1028
+ _context6.next = 15;
945
1029
  return this.loadOrdersFromSQLite();
946
1030
  case 15:
947
- orders = _context5.sent;
1031
+ orders = _context6.sent;
948
1032
  localOrder = orders.find(function (order) {
949
- return _this4.isOrderLookupMatch(order, key);
1033
+ return _this5.isOrderLookupMatch(order, key);
950
1034
  });
951
1035
  if (localOrder) {
952
- _context5.next = 20;
1036
+ _context6.next = 20;
953
1037
  break;
954
1038
  }
955
1039
  if (options.operationId) {
@@ -957,7 +1041,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
957
1041
  sqlite_order_count: orders.length
958
1042
  }));
959
1043
  }
960
- return _context5.abrupt("return", null);
1044
+ return _context6.abrupt("return", null);
961
1045
  case 20:
962
1046
  this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
963
1047
  this.syncOrdersMap();
@@ -967,14 +1051,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
967
1051
  sqlite_order_count: orders.length
968
1052
  }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
969
1053
  }
970
- return _context5.abrupt("return", normalizedOrder);
1054
+ return _context6.abrupt("return", normalizedOrder);
971
1055
  case 25:
972
1056
  case "end":
973
- return _context5.stop();
1057
+ return _context6.stop();
974
1058
  }
975
- }, _callee5, this);
1059
+ }, _callee6, this);
976
1060
  }));
977
- function getLocalOrderByLookup(_x4) {
1061
+ function getLocalOrderByLookup(_x5) {
978
1062
  return _getLocalOrderByLookup.apply(this, arguments);
979
1063
  }
980
1064
  return getLocalOrderByLookup;
@@ -982,10 +1066,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
982
1066
  }, {
983
1067
  key: "getLocalPayment",
984
1068
  value: function () {
985
- var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1069
+ var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
986
1070
  var logContext, order, payments, match;
987
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
988
- while (1) switch (_context6.prev = _context6.next) {
1071
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1072
+ while (1) switch (_context7.prev = _context7.next) {
989
1073
  case 0:
990
1074
  logContext = {
991
1075
  operation_id: params.operationId,
@@ -993,56 +1077,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
993
1077
  payment_number: params.paymentNumber
994
1078
  };
995
1079
  this.logInfo('getLocalPayment-开始', logContext);
996
- _context6.prev = 2;
997
- _context6.next = 5;
1080
+ _context7.prev = 2;
1081
+ _context7.next = 5;
998
1082
  return this.getLocalOrderByLookup(params.saleId, {
999
1083
  operationId: params.operationId
1000
1084
  });
1001
1085
  case 5:
1002
- order = _context6.sent;
1086
+ order = _context7.sent;
1003
1087
  if (order) {
1004
- _context6.next = 9;
1088
+ _context7.next = 9;
1005
1089
  break;
1006
1090
  }
1007
1091
  this.logWarning('getLocalPayment-订单未命中', logContext);
1008
- return _context6.abrupt("return", null);
1092
+ return _context7.abrupt("return", null);
1009
1093
  case 9:
1010
1094
  payments = order.payments || [];
1011
1095
  match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
1012
1096
  if (match) {
1013
- _context6.next = 14;
1097
+ _context7.next = 14;
1014
1098
  break;
1015
1099
  }
1016
1100
  this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1017
1101
  payments: payments
1018
1102
  }));
1019
- return _context6.abrupt("return", null);
1103
+ return _context7.abrupt("return", null);
1020
1104
  case 14:
1021
1105
  this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1022
1106
  matched_by: match.matchedBy,
1023
1107
  payment_index: match.index,
1024
1108
  payment: match.payment
1025
1109
  }));
1026
- return _context6.abrupt("return", {
1110
+ return _context7.abrupt("return", {
1027
1111
  order: order,
1028
1112
  payment: match.payment,
1029
1113
  paymentIndex: match.index,
1030
1114
  matchedBy: match.matchedBy
1031
1115
  });
1032
1116
  case 18:
1033
- _context6.prev = 18;
1034
- _context6.t0 = _context6["catch"](2);
1117
+ _context7.prev = 18;
1118
+ _context7.t0 = _context7["catch"](2);
1035
1119
  this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
1036
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1120
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1037
1121
  }));
1038
- throw _context6.t0;
1122
+ throw _context7.t0;
1039
1123
  case 22:
1040
1124
  case "end":
1041
- return _context6.stop();
1125
+ return _context7.stop();
1042
1126
  }
1043
- }, _callee6, this, [[2, 18]]);
1127
+ }, _callee7, this, [[2, 18]]);
1044
1128
  }));
1045
- function getLocalPayment(_x5) {
1129
+ function getLocalPayment(_x6) {
1046
1130
  return _getLocalPayment.apply(this, arguments);
1047
1131
  }
1048
1132
  return getLocalPayment;
@@ -1050,10 +1134,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1050
1134
  }, {
1051
1135
  key: "updateLocalPayment",
1052
1136
  value: function () {
1053
- var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
1137
+ var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1138
+ var _found$payment$metada;
1054
1139
  var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
1055
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1056
- while (1) switch (_context7.prev = _context7.next) {
1140
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1141
+ while (1) switch (_context8.prev = _context8.next) {
1057
1142
  case 0:
1058
1143
  logContext = {
1059
1144
  operation_id: params.operationId,
@@ -1062,18 +1147,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1062
1147
  incoming_payment_update: params.updates
1063
1148
  };
1064
1149
  this.logInfo('updateLocalPayment-开始', logContext);
1065
- _context7.next = 4;
1150
+ _context8.next = 4;
1066
1151
  return this.getLocalPayment(params);
1067
1152
  case 4:
1068
- found = _context7.sent;
1153
+ found = _context8.sent;
1069
1154
  if (found) {
1070
- _context7.next = 8;
1155
+ _context8.next = 8;
1071
1156
  break;
1072
1157
  }
1073
1158
  this.logWarning('updateLocalPayment-支付项未命中', logContext);
1074
- return _context7.abrupt("return", null);
1159
+ return _context8.abrupt("return", null);
1075
1160
  case 8:
1076
1161
  previousPayment = cloneDeep(found.payment);
1162
+ if (!(params.finalizeUnsuccessful && (found.payment.status === 'paid' || (_found$payment$metada = found.payment.metadata) !== null && _found$payment$metada !== void 0 && (_found$payment$metada = _found$payment$metada.transactions) !== null && _found$payment$metada !== void 0 && _found$payment$metada.some(function (transaction) {
1163
+ return transaction.status === 'success';
1164
+ }) || isLocalFinalizedPayment(found.payment)))) {
1165
+ _context8.next = 11;
1166
+ break;
1167
+ }
1168
+ return _context8.abrupt("return", {
1169
+ order: found.order,
1170
+ payment: found.payment,
1171
+ previousPayment: previousPayment
1172
+ });
1173
+ case 11:
1077
1174
  nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
1078
1175
  updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
1079
1176
  }));
@@ -1083,6 +1180,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1083
1180
  }),
1084
1181
  updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
1085
1182
  });
1183
+ if (params.finalizeUnsuccessful && this.hasRealOrderId(found.order) && Number(found.order.need_sync || 0) === 0 && !(nextOrder.payments || []).some(isPendingOrderPayment)) {
1184
+ nextOrder.is_draft_order = 0;
1185
+ nextOrder.metadata = _objectSpread(_objectSpread({}, nextOrder.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
1186
+ }
1086
1187
  paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
1087
1188
  matched_by: found.matchedBy,
1088
1189
  payment_index: found.paymentIndex
@@ -1094,12 +1195,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1094
1195
  targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
1095
1196
  shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
1096
1197
  if (!(targetIndex < 0 && shouldKeepInMemory)) {
1097
- _context7.next = 18;
1198
+ _context8.next = 21;
1098
1199
  break;
1099
1200
  }
1100
1201
  this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
1101
- return _context7.abrupt("return", null);
1102
- case 18:
1202
+ return _context8.abrupt("return", null);
1203
+ case 21:
1103
1204
  previousList = this.store.list;
1104
1205
  this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
1105
1206
  return index === targetIndex ? nextOrder : order;
@@ -1108,60 +1209,189 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1108
1209
  });
1109
1210
  this.syncOrdersMap();
1110
1211
  storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
1111
- _context7.prev = 22;
1212
+ _context8.prev = 25;
1112
1213
  this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
1113
1214
  storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
1114
1215
  }));
1115
- _context7.next = 26;
1216
+ _context8.next = 29;
1116
1217
  return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
1117
1218
  throwOnError: true
1118
1219
  });
1119
- case 26:
1220
+ case 29:
1120
1221
  this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
1121
1222
  storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
1122
1223
  }));
1123
- _context7.next = 35;
1224
+ _context8.next = 38;
1124
1225
  break;
1125
- case 29:
1126
- _context7.prev = 29;
1127
- _context7.t0 = _context7["catch"](22);
1226
+ case 32:
1227
+ _context8.prev = 32;
1228
+ _context8.t0 = _context8["catch"](25);
1128
1229
  this.store.list = previousList;
1129
1230
  this.syncOrdersMap();
1130
1231
  this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
1131
1232
  storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
1132
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1233
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
1133
1234
  }));
1134
- throw _context7.t0;
1135
- case 35:
1235
+ throw _context8.t0;
1236
+ case 38:
1136
1237
  if (!(shouldKeepInMemory || targetIndex >= 0)) {
1137
- _context7.next = 38;
1238
+ _context8.next = 41;
1138
1239
  break;
1139
1240
  }
1140
- _context7.next = 38;
1241
+ _context8.next = 41;
1141
1242
  return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
1142
- case 38:
1243
+ case 41:
1143
1244
  this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
1144
- return _context7.abrupt("return", {
1245
+ return _context8.abrupt("return", {
1145
1246
  order: nextOrder,
1146
1247
  payment: nextPayment,
1147
1248
  previousPayment: previousPayment
1148
1249
  });
1149
- case 40:
1250
+ case 43:
1150
1251
  case "end":
1151
- return _context7.stop();
1252
+ return _context8.stop();
1152
1253
  }
1153
- }, _callee7, this, [[22, 29]]);
1254
+ }, _callee8, this, [[25, 32]]);
1154
1255
  }));
1155
- function updateLocalPayment(_x6) {
1256
+ function updateLocalPayment(_x7) {
1156
1257
  return _updateLocalPayment.apply(this, arguments);
1157
1258
  }
1158
1259
  return updateLocalPayment;
1159
1260
  }()
1261
+ }, {
1262
+ key: "finalizeLocalEftposPayment",
1263
+ value: function () {
1264
+ var _finalizeLocalEftposPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1265
+ var _found$payment$metada2;
1266
+ var found, transactions;
1267
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1268
+ while (1) switch (_context9.prev = _context9.next) {
1269
+ case 0:
1270
+ _context9.next = 2;
1271
+ return this.getLocalPayment(params);
1272
+ case 2:
1273
+ found = _context9.sent;
1274
+ if (found) {
1275
+ _context9.next = 5;
1276
+ break;
1277
+ }
1278
+ throw new Error('未找到本地支付记录');
1279
+ case 5:
1280
+ transactions = ((_found$payment$metada2 = found.payment.metadata) === null || _found$payment$metada2 === void 0 ? void 0 : _found$payment$metada2.transactions) || [];
1281
+ if (!transactions.some(function (transaction) {
1282
+ return transaction.status !== 'fail' && transaction.status !== 'success' && !params.failedTransactionNumbers.includes(String(transaction.number));
1283
+ })) {
1284
+ _context9.next = 8;
1285
+ break;
1286
+ }
1287
+ throw new Error('仍有结果未知的交易,保留待确认支付');
1288
+ case 8:
1289
+ if (!(params.result === 'not_started' && transactions.length > 0 && !isLocalFinalizedPayment(found.payment) && found.payment.status !== 'paid')) {
1290
+ _context9.next = 10;
1291
+ break;
1292
+ }
1293
+ throw new Error('支付已有交易记录,不能按未发起交易结束');
1294
+ case 10:
1295
+ return _context9.abrupt("return", this.updateLocalPayment(_objectSpread(_objectSpread({}, params), {}, {
1296
+ finalizeUnsuccessful: true,
1297
+ updates: {
1298
+ status: 'voided',
1299
+ metadata: _defineProperty(_defineProperty({}, LOCAL_EFTPOS_FINALIZED, true), "transactions", params.failedTransactionNumbers.map(function (number) {
1300
+ return {
1301
+ number: number,
1302
+ status: 'fail'
1303
+ };
1304
+ }))
1305
+ }
1306
+ })));
1307
+ case 11:
1308
+ case "end":
1309
+ return _context9.stop();
1310
+ }
1311
+ }, _callee9, this);
1312
+ }));
1313
+ function finalizeLocalEftposPayment(_x8) {
1314
+ return _finalizeLocalEftposPayment.apply(this, arguments);
1315
+ }
1316
+ return finalizeLocalEftposPayment;
1317
+ }() /** Only a successful full detail GET may release the persisted payment gate. */
1318
+ }, {
1319
+ key: "completeLocalPaymentRefresh",
1320
+ value: (function () {
1321
+ var _completeLocalPaymentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1322
+ var existing, nextOrder, index;
1323
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1324
+ while (1) switch (_context10.prev = _context10.next) {
1325
+ case 0:
1326
+ _context10.next = 2;
1327
+ return this.getLocalOrderByLookup(fresh.order_id);
1328
+ case 2:
1329
+ existing = _context10.sent;
1330
+ if (!(!existing || !requiresLocalPaymentRefresh(existing))) {
1331
+ _context10.next = 12;
1332
+ break;
1333
+ }
1334
+ _context10.next = 6;
1335
+ return this.upsertOrdersFromRemote([fresh]);
1336
+ case 6:
1337
+ _context10.next = 8;
1338
+ return this.getLocalOrderByLookup(fresh.order_id);
1339
+ case 8:
1340
+ _context10.t0 = _context10.sent;
1341
+ if (_context10.t0) {
1342
+ _context10.next = 11;
1343
+ break;
1344
+ }
1345
+ _context10.t0 = fresh;
1346
+ case 11:
1347
+ return _context10.abrupt("return", _context10.t0);
1348
+ case 12:
1349
+ if (!(this.isPendingSyncOrder(existing) || this.isDraftOrder(existing) || (existing.payments || []).some(isPendingOrderPayment))) {
1350
+ _context10.next = 14;
1351
+ break;
1352
+ }
1353
+ throw new Error('订单仍有未结束支付或待同步改动,暂不能刷新');
1354
+ case 14:
1355
+ if (!(!Array.isArray(fresh.products) || !fresh.summary)) {
1356
+ _context10.next = 16;
1357
+ break;
1358
+ }
1359
+ throw new Error('远端订单详情不完整,请重新刷新');
1360
+ case 16:
1361
+ nextOrder = this.mergeOrderRecords(existing, this.normalizeRemoteSyncedOrder(fresh));
1362
+ nextOrder.metadata = _objectSpread({}, nextOrder.metadata);
1363
+ delete nextOrder.metadata[LOCAL_EFTPOS_REFRESH_REQUIRED];
1364
+ // Do not publish/clear the gate in memory until SQLite has accepted the full snapshot.
1365
+ _context10.next = 21;
1366
+ return this.updateOrderInSQLite(nextOrder, 'completeLocalPaymentRefresh', {
1367
+ throwOnError: true
1368
+ });
1369
+ case 21:
1370
+ index = this.findOrderIndexByIdentity(this.store.list, existing);
1371
+ this.store.list = index < 0 ? [].concat(_toConsumableArray(this.store.list), [nextOrder]) : this.store.list.map(function (order, i) {
1372
+ return i === index ? nextOrder : order;
1373
+ });
1374
+ this.syncOrdersMap();
1375
+ _context10.next = 26;
1376
+ return this.emitOrdersChanged([nextOrder], 'completeLocalPaymentRefresh');
1377
+ case 26:
1378
+ return _context10.abrupt("return", nextOrder);
1379
+ case 27:
1380
+ case "end":
1381
+ return _context10.stop();
1382
+ }
1383
+ }, _callee10, this);
1384
+ }));
1385
+ function completeLocalPaymentRefresh(_x9) {
1386
+ return _completeLocalPaymentRefresh.apply(this, arguments);
1387
+ }
1388
+ return completeLocalPaymentRefresh;
1389
+ }())
1160
1390
  }, {
1161
1391
  key: "loadOrdersByServer",
1162
1392
  value: function () {
1163
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1164
- var _this5 = this,
1393
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1394
+ var _this6 = this,
1165
1395
  _this$store;
1166
1396
  var options,
1167
1397
  orderList,
@@ -1173,19 +1403,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1173
1403
  mergedOrders,
1174
1404
  isRemoteSnapshotPersisted,
1175
1405
  memoryOrders,
1176
- _args8 = arguments;
1177
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1178
- while (1) switch (_context8.prev = _context8.next) {
1406
+ _args11 = arguments;
1407
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1408
+ while (1) switch (_context11.prev = _context11.next) {
1179
1409
  case 0:
1180
- options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1410
+ options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
1181
1411
  orderList = [];
1182
1412
  hasFetchedRemoteSnapshot = false;
1183
1413
  trigger = options.trigger || 'unknown';
1184
- _context8.next = 6;
1414
+ _context11.next = 6;
1185
1415
  return this.loadOrdersFromSQLite();
1186
1416
  case 6:
1187
- protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1188
- return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1417
+ protectedOrdersBeforeRemoteFetch = _context11.sent.filter(function (order) {
1418
+ return _this6.shouldProtectLocalOrderFromRemoteSnapshot(order);
1189
1419
  });
1190
1420
  this.logInfo('loadOrdersByServer-开始', {
1191
1421
  trigger: trigger,
@@ -1193,22 +1423,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1193
1423
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1194
1424
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
1195
1425
  protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
1196
- return count + _this5.getIdentifiedPendingPayments(order).length;
1426
+ return count + _this6.getIdentifiedPendingPayments(order).length;
1197
1427
  }, 0)
1198
1428
  });
1199
1429
  if (!this.orderDataSource) {
1200
- _context8.next = 23;
1430
+ _context11.next = 23;
1201
1431
  break;
1202
1432
  }
1203
- _context8.prev = 9;
1204
- _context8.next = 12;
1433
+ _context11.prev = 9;
1434
+ _context11.next = 12;
1205
1435
  return this.orderDataSource.run({
1206
1436
  sse: {
1207
1437
  query: this.store.createdAtQuery
1208
1438
  }
1209
1439
  });
1210
1440
  case 12:
1211
- data = _context8.sent;
1441
+ data = _context11.sent;
1212
1442
  orderList = data || [];
1213
1443
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1214
1444
  trigger: trigger,
@@ -1216,21 +1446,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1216
1446
  });
1217
1447
  hasFetchedRemoteSnapshot = true;
1218
1448
  this.lastServerFullFetchAtMs = Date.now();
1219
- _context8.next = 23;
1449
+ _context11.next = 23;
1220
1450
  break;
1221
1451
  case 19:
1222
- _context8.prev = 19;
1223
- _context8.t0 = _context8["catch"](9);
1452
+ _context11.prev = 19;
1453
+ _context11.t0 = _context11["catch"](9);
1224
1454
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1225
- return _context8.abrupt("return", this.store.list);
1455
+ return _context11.abrupt("return", this.store.list);
1226
1456
  case 23:
1227
1457
  if (hasFetchedRemoteSnapshot) {
1228
1458
  this.clearOrderSnapshotMarker();
1229
1459
  }
1230
- _context8.next = 26;
1460
+ _context11.next = 26;
1231
1461
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1232
1462
  case 26:
1233
- _yield$this$replaceOr = _context8.sent;
1463
+ _yield$this$replaceOr = _context11.sent;
1234
1464
  mergedOrders = _yield$this$replaceOr.orders;
1235
1465
  isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1236
1466
  if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
@@ -1243,15 +1473,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1243
1473
  persistedCount: mergedOrders.length,
1244
1474
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1245
1475
  });
1246
- _context8.next = 34;
1476
+ _context11.next = 34;
1247
1477
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1248
1478
  case 34:
1249
- return _context8.abrupt("return", memoryOrders);
1479
+ return _context11.abrupt("return", memoryOrders);
1250
1480
  case 35:
1251
1481
  case "end":
1252
- return _context8.stop();
1482
+ return _context11.stop();
1253
1483
  }
1254
- }, _callee8, this, [[9, 19]]);
1484
+ }, _callee11, this, [[9, 19]]);
1255
1485
  }));
1256
1486
  function loadOrdersByServer() {
1257
1487
  return _loadOrdersByServer.apply(this, arguments);
@@ -1265,25 +1495,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1265
1495
  }, {
1266
1496
  key: "refreshOrdersForCurrentBusinessDay",
1267
1497
  value: (function () {
1268
- var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1498
+ var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1269
1499
  var options,
1270
1500
  refreshPromise,
1271
- _args9 = arguments;
1272
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1273
- while (1) switch (_context9.prev = _context9.next) {
1501
+ _args12 = arguments;
1502
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1503
+ while (1) switch (_context12.prev = _context12.next) {
1274
1504
  case 0:
1275
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1505
+ options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1276
1506
  if (!this.businessDayRefreshPromise) {
1277
- _context9.next = 3;
1507
+ _context12.next = 3;
1278
1508
  break;
1279
1509
  }
1280
- return _context9.abrupt("return", this.businessDayRefreshPromise);
1510
+ return _context12.abrupt("return", this.businessDayRefreshPromise);
1281
1511
  case 3:
1282
1512
  if (!(!this.orderDataSource || !this.getCurrentShopId() || this.hasPulledOrdersToday())) {
1283
- _context9.next = 5;
1513
+ _context12.next = 5;
1284
1514
  break;
1285
1515
  }
1286
- return _context9.abrupt("return");
1516
+ return _context12.abrupt("return");
1287
1517
  case 5:
1288
1518
  refreshPromise = this.silentRefresh({
1289
1519
  trigger: options.trigger || 'business_day_rollover'
@@ -1291,18 +1521,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1291
1521
  return undefined;
1292
1522
  });
1293
1523
  this.businessDayRefreshPromise = refreshPromise;
1294
- _context9.prev = 7;
1295
- _context9.next = 10;
1524
+ _context12.prev = 7;
1525
+ _context12.next = 10;
1296
1526
  return refreshPromise;
1297
1527
  case 10:
1298
- _context9.prev = 10;
1528
+ _context12.prev = 10;
1299
1529
  this.businessDayRefreshPromise = null;
1300
- return _context9.finish(10);
1530
+ return _context12.finish(10);
1301
1531
  case 13:
1302
1532
  case "end":
1303
- return _context9.stop();
1533
+ return _context12.stop();
1304
1534
  }
1305
- }, _callee9, this, [[7,, 10, 13]]);
1535
+ }, _callee12, this, [[7,, 10, 13]]);
1306
1536
  }));
1307
1537
  function refreshOrdersForCurrentBusinessDay() {
1308
1538
  return _refreshOrdersForCurrentBusinessDay.apply(this, arguments);
@@ -1318,23 +1548,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1318
1548
  }, {
1319
1549
  key: "silentRefresh",
1320
1550
  value: (function () {
1321
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1551
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1322
1552
  var options,
1323
1553
  startTime,
1324
1554
  trigger,
1325
1555
  elapsedSinceFullFetch,
1326
1556
  orders,
1327
1557
  errorMessage,
1328
- _args10 = arguments;
1329
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1330
- while (1) switch (_context10.prev = _context10.next) {
1558
+ _args13 = arguments;
1559
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1560
+ while (1) switch (_context13.prev = _context13.next) {
1331
1561
  case 0:
1332
- options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1562
+ options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
1333
1563
  startTime = Date.now();
1334
1564
  trigger = options.trigger || 'background';
1335
1565
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1336
1566
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1337
- _context10.next = 7;
1567
+ _context13.next = 7;
1338
1568
  break;
1339
1569
  }
1340
1570
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -1344,28 +1574,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1344
1574
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1345
1575
  orderCount: this.store.list.length
1346
1576
  });
1347
- return _context10.abrupt("return", this.store.list);
1577
+ return _context13.abrupt("return", this.store.list);
1348
1578
  case 7:
1349
1579
  this.logInfo('silentRefresh 开始', {
1350
1580
  trigger: trigger,
1351
1581
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1352
1582
  orderCount: this.store.list.length
1353
1583
  });
1354
- _context10.prev = 8;
1584
+ _context13.prev = 8;
1355
1585
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1356
1586
  this.updateCreateStore();
1357
- _context10.next = 12;
1587
+ _context13.next = 12;
1358
1588
  return this.loadOrdersByServer({
1359
1589
  trigger: trigger
1360
1590
  });
1361
1591
  case 12:
1362
- orders = _context10.sent;
1592
+ orders = _context13.sent;
1363
1593
  this.store.list = cloneDeep(orders);
1364
1594
  this.syncOrdersMap();
1365
- _context10.next = 17;
1595
+ _context13.next = 17;
1366
1596
  return this.emitOrdersChanged([], 'silentRefresh');
1367
1597
  case 17:
1368
- _context10.next = 19;
1598
+ _context13.next = 19;
1369
1599
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1370
1600
  case 19:
1371
1601
  this.logInfo('silentRefresh 完成', {
@@ -1373,22 +1603,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1373
1603
  orderCount: orders.length,
1374
1604
  duration: "".concat(Date.now() - startTime, "ms")
1375
1605
  });
1376
- return _context10.abrupt("return", this.store.list);
1606
+ return _context13.abrupt("return", this.store.list);
1377
1607
  case 23:
1378
- _context10.prev = 23;
1379
- _context10.t0 = _context10["catch"](8);
1380
- errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1608
+ _context13.prev = 23;
1609
+ _context13.t0 = _context13["catch"](8);
1610
+ errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1381
1611
  this.logError('silentRefresh 失败', {
1382
1612
  trigger: trigger,
1383
1613
  duration: "".concat(Date.now() - startTime, "ms"),
1384
1614
  error: errorMessage
1385
1615
  });
1386
- return _context10.abrupt("return", this.store.list);
1616
+ return _context13.abrupt("return", this.store.list);
1387
1617
  case 28:
1388
1618
  case "end":
1389
- return _context10.stop();
1619
+ return _context13.stop();
1390
1620
  }
1391
- }, _callee10, this, [[8, 23]]);
1621
+ }, _callee13, this, [[8, 23]]);
1392
1622
  }));
1393
1623
  function silentRefresh() {
1394
1624
  return _silentRefresh.apply(this, arguments);
@@ -1426,21 +1656,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1426
1656
  }, {
1427
1657
  key: "prepareNormalizedOrdersForMemoryList",
1428
1658
  value: function prepareNormalizedOrdersForMemoryList(orders) {
1429
- var _this6 = this;
1659
+ var _this7 = this;
1430
1660
  return orders.map(function (order) {
1431
- return _this6.prepareNormalizedOrderForMemoryList(order);
1661
+ return _this7.prepareNormalizedOrderForMemoryList(order);
1432
1662
  }).filter(function (order) {
1433
- return _this6.shouldKeepOrderInMemory(order);
1663
+ return _this7.shouldKeepOrderInMemory(order);
1434
1664
  });
1435
1665
  }
1436
1666
  }, {
1437
1667
  key: "normalizeOrdersForMemoryList",
1438
1668
  value: function normalizeOrdersForMemoryList(orders, source) {
1439
- var _this7 = this;
1669
+ var _this8 = this;
1440
1670
  return orders.map(function (order) {
1441
- return _this7.normalizeOrderForMemoryList(order, source);
1671
+ return _this8.normalizeOrderForMemoryList(order, source);
1442
1672
  }).filter(function (order) {
1443
- return _this7.shouldKeepOrderInMemory(order);
1673
+ return _this8.shouldKeepOrderInMemory(order);
1444
1674
  });
1445
1675
  }
1446
1676
  }, {
@@ -1474,31 +1704,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1474
1704
  }, {
1475
1705
  key: "overwriteExistingOrder",
1476
1706
  value: (function () {
1477
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fresh) {
1478
- var _this8 = this;
1707
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(fresh) {
1708
+ var _this9 = this;
1479
1709
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1480
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1481
- while (1) switch (_context11.prev = _context11.next) {
1710
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1711
+ while (1) switch (_context14.prev = _context14.next) {
1482
1712
  case 0:
1483
1713
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1484
1714
  if (!(orderId === undefined || orderId === null)) {
1485
- _context11.next = 4;
1715
+ _context14.next = 4;
1486
1716
  break;
1487
1717
  }
1488
1718
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1489
- return _context11.abrupt("return", {
1719
+ return _context14.abrupt("return", {
1490
1720
  overwritten: false
1491
1721
  });
1492
1722
  case 4:
1493
1723
  key = this.getIdKey(orderId);
1494
1724
  if (this.store.map.has(key)) {
1495
- _context11.next = 8;
1725
+ _context14.next = 8;
1496
1726
  break;
1497
1727
  }
1498
1728
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1499
1729
  orderId: orderId
1500
1730
  });
1501
- return _context11.abrupt("return", {
1731
+ return _context14.abrupt("return", {
1502
1732
  overwritten: false
1503
1733
  });
1504
1734
  case 8:
@@ -1512,31 +1742,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1512
1742
  this.store.list = this.store.list.map(function (order) {
1513
1743
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1514
1744
  if (id === undefined || id === null) {
1515
- return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1745
+ return _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1516
1746
  }
1517
- return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1747
+ return _this9.getIdKey(id) === key ? reconciledFresh : _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1518
1748
  });
1519
1749
  this.syncOrdersMap();
1520
- _context11.next = 16;
1750
+ _context14.next = 16;
1521
1751
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1522
1752
  case 16:
1523
1753
  this.logInfo('overwriteExistingOrder-结束', {
1524
1754
  orderId: orderId,
1525
1755
  storeOrderCountAfter: this.store.list.length
1526
1756
  });
1527
- _context11.next = 19;
1757
+ _context14.next = 19;
1528
1758
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1529
1759
  case 19:
1530
- return _context11.abrupt("return", {
1760
+ return _context14.abrupt("return", {
1531
1761
  overwritten: true
1532
1762
  });
1533
1763
  case 20:
1534
1764
  case "end":
1535
- return _context11.stop();
1765
+ return _context14.stop();
1536
1766
  }
1537
- }, _callee11, this);
1767
+ }, _callee14, this);
1538
1768
  }));
1539
- function overwriteExistingOrder(_x7) {
1769
+ function overwriteExistingOrder(_x10) {
1540
1770
  return _overwriteExistingOrder.apply(this, arguments);
1541
1771
  }
1542
1772
  return overwriteExistingOrder;
@@ -1549,35 +1779,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1549
1779
  }, {
1550
1780
  key: "upsertOrdersFromRemote",
1551
1781
  value: (function () {
1552
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(freshOrders) {
1782
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(freshOrders) {
1553
1783
  var source,
1554
- _args12 = arguments;
1555
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1556
- while (1) switch (_context12.prev = _context12.next) {
1784
+ _args15 = arguments;
1785
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1786
+ while (1) switch (_context15.prev = _context15.next) {
1557
1787
  case 0:
1558
- source = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : 'upsertOrdersFromRemote';
1788
+ source = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : 'upsertOrdersFromRemote';
1559
1789
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1560
- _context12.next = 4;
1790
+ _context15.next = 4;
1561
1791
  break;
1562
1792
  }
1563
1793
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {
1564
1794
  source: source
1565
1795
  });
1566
- return _context12.abrupt("return");
1796
+ return _context15.abrupt("return");
1567
1797
  case 4:
1568
1798
  this.logInfo('upsertOrdersFromRemote-开始', {
1569
1799
  count: freshOrders.length,
1570
1800
  source: source
1571
1801
  });
1572
- _context12.next = 7;
1802
+ _context15.next = 7;
1573
1803
  return this.mergeOrdersToStore(freshOrders, source);
1574
1804
  case 7:
1575
1805
  case "end":
1576
- return _context12.stop();
1806
+ return _context15.stop();
1577
1807
  }
1578
- }, _callee12, this);
1808
+ }, _callee15, this);
1579
1809
  }));
1580
- function upsertOrdersFromRemote(_x8) {
1810
+ function upsertOrdersFromRemote(_x11) {
1581
1811
  return _upsertOrdersFromRemote.apply(this, arguments);
1582
1812
  }
1583
1813
  return upsertOrdersFromRemote;
@@ -1585,21 +1815,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1585
1815
  }, {
1586
1816
  key: "markOrderSyncedByExternalSaleNumber",
1587
1817
  value: function () {
1588
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1589
- var _this9 = this,
1818
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1819
+ var _this10 = this,
1590
1820
  _existing$external_sa,
1591
1821
  _nextOrder$order_id;
1592
1822
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1593
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1594
- while (1) switch (_context13.prev = _context13.next) {
1823
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1824
+ while (1) switch (_context16.prev = _context16.next) {
1595
1825
  case 0:
1596
1826
  externalSaleNumber = params.externalSaleNumber;
1597
1827
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1598
- _context13.next = 4;
1828
+ _context16.next = 4;
1599
1829
  break;
1600
1830
  }
1601
1831
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1602
- return _context13.abrupt("return", {
1832
+ return _context16.abrupt("return", {
1603
1833
  updated: false
1604
1834
  });
1605
1835
  case 4:
@@ -1607,16 +1837,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1607
1837
  targetIndex = this.store.list.findIndex(function (order) {
1608
1838
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1609
1839
  if (value === undefined || value === null || value === '') return false;
1610
- return _this9.getIdKey(value) === key;
1840
+ return _this10.getIdKey(value) === key;
1611
1841
  });
1612
1842
  if (!(targetIndex < 0)) {
1613
- _context13.next = 9;
1843
+ _context16.next = 9;
1614
1844
  break;
1615
1845
  }
1616
1846
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1617
1847
  external_sale_number: externalSaleNumber
1618
1848
  });
1619
- return _context13.abrupt("return", {
1849
+ return _context16.abrupt("return", {
1620
1850
  updated: false
1621
1851
  });
1622
1852
  case 9:
@@ -1632,27 +1862,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1632
1862
  return nextOrder;
1633
1863
  });
1634
1864
  this.syncOrdersMap();
1635
- _context13.next = 16;
1865
+ _context16.next = 16;
1636
1866
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1637
1867
  case 16:
1638
1868
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1639
1869
  external_sale_number: externalSaleNumber,
1640
1870
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1641
1871
  });
1642
- _context13.next = 19;
1872
+ _context16.next = 19;
1643
1873
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1644
1874
  case 19:
1645
- return _context13.abrupt("return", {
1875
+ return _context16.abrupt("return", {
1646
1876
  updated: true,
1647
1877
  order: nextOrder
1648
1878
  });
1649
1879
  case 20:
1650
1880
  case "end":
1651
- return _context13.stop();
1881
+ return _context16.stop();
1652
1882
  }
1653
- }, _callee13, this);
1883
+ }, _callee16, this);
1654
1884
  }));
1655
- function markOrderSyncedByExternalSaleNumber(_x9) {
1885
+ function markOrderSyncedByExternalSaleNumber(_x12) {
1656
1886
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1657
1887
  }
1658
1888
  return markOrderSyncedByExternalSaleNumber;
@@ -1664,8 +1894,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1664
1894
  }, {
1665
1895
  key: "upsertPendingSyncOrders",
1666
1896
  value: (function () {
1667
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(pendingOrders) {
1668
- var _this10 = this;
1897
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(pendingOrders) {
1898
+ var _this11 = this;
1669
1899
  var options,
1670
1900
  pendingMap,
1671
1901
  memoryPendingMap,
@@ -1675,6 +1905,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1675
1905
  normalizedOrder,
1676
1906
  pendingOrder,
1677
1907
  storageKey,
1908
+ storageKeyMigrations,
1909
+ previousStorageKeys,
1678
1910
  mergeActions,
1679
1911
  updatedList,
1680
1912
  identityKeyToIndex,
@@ -1691,30 +1923,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1691
1923
  existingOrder,
1692
1924
  mergedOrder,
1693
1925
  nextOrder,
1926
+ previousStorageKey,
1927
+ _nextOrder$order_id2,
1694
1928
  pendingSnapshot,
1695
1929
  insertIndex,
1696
1930
  patchedOrders,
1697
1931
  previousList,
1698
- _args14 = arguments;
1699
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1700
- while (1) switch (_context14.prev = _context14.next) {
1932
+ _args17 = arguments;
1933
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1934
+ while (1) switch (_context17.prev = _context17.next) {
1701
1935
  case 0:
1702
- options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1936
+ options = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {};
1703
1937
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1704
- _context14.next = 4;
1938
+ _context17.next = 4;
1705
1939
  break;
1706
1940
  }
1707
1941
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1708
- return _context14.abrupt("return");
1942
+ return _context17.abrupt("return");
1709
1943
  case 4:
1710
1944
  pendingMap = new Map();
1711
1945
  memoryPendingMap = new Map();
1712
1946
  _iterator7 = _createForOfIteratorHelper(pendingOrders);
1713
- _context14.prev = 7;
1947
+ _context17.prev = 7;
1714
1948
  _iterator7.s();
1715
1949
  case 9:
1716
1950
  if ((_step7 = _iterator7.n()).done) {
1717
- _context14.next = 20;
1951
+ _context17.next = 20;
1718
1952
  break;
1719
1953
  }
1720
1954
  order = _step7.value;
@@ -1725,43 +1959,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1725
1959
  });
1726
1960
  storageKey = this.getOrderStorageKey(pendingOrder);
1727
1961
  if (storageKey) {
1728
- _context14.next = 16;
1962
+ _context17.next = 16;
1729
1963
  break;
1730
1964
  }
1731
- return _context14.abrupt("continue", 18);
1965
+ return _context17.abrupt("continue", 18);
1732
1966
  case 16:
1733
1967
  pendingMap.set(storageKey, pendingOrder);
1734
1968
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1735
1969
  case 18:
1736
- _context14.next = 9;
1970
+ _context17.next = 9;
1737
1971
  break;
1738
1972
  case 20:
1739
- _context14.next = 25;
1973
+ _context17.next = 25;
1740
1974
  break;
1741
1975
  case 22:
1742
- _context14.prev = 22;
1743
- _context14.t0 = _context14["catch"](7);
1744
- _iterator7.e(_context14.t0);
1976
+ _context17.prev = 22;
1977
+ _context17.t0 = _context17["catch"](7);
1978
+ _iterator7.e(_context17.t0);
1745
1979
  case 25:
1746
- _context14.prev = 25;
1980
+ _context17.prev = 25;
1747
1981
  _iterator7.f();
1748
- return _context14.finish(25);
1982
+ return _context17.finish(25);
1749
1983
  case 28:
1750
1984
  if (!(pendingMap.size === 0)) {
1751
- _context14.next = 31;
1985
+ _context17.next = 31;
1752
1986
  break;
1753
1987
  }
1754
1988
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1755
1989
  count: pendingOrders.length
1756
1990
  });
1757
- return _context14.abrupt("return");
1991
+ return _context17.abrupt("return");
1758
1992
  case 31:
1759
1993
  this.logInfo('upsertPendingSyncOrders-开始', {
1760
1994
  count: pendingMap.size
1761
1995
  });
1996
+ storageKeyMigrations = [];
1997
+ previousStorageKeys = this.store.list.map(function (order) {
1998
+ return _this11.getPersistedOrderStorageKey(order);
1999
+ });
1762
2000
  mergeActions = {};
1763
2001
  updatedList = this.store.list.map(function (order) {
1764
- return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
2002
+ return _this11.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1765
2003
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1766
2004
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1767
2005
  identityKeyToIndex = new Map();
@@ -1780,17 +2018,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1780
2018
  }
1781
2019
  }
1782
2020
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
1783
- _context14.prev = 37;
2021
+ _context17.prev = 39;
1784
2022
  _iterator9.s();
1785
- case 39:
2023
+ case 41:
1786
2024
  if ((_step9 = _iterator9.n()).done) {
1787
- _context14.next = 58;
2025
+ _context17.next = 62;
1788
2026
  break;
1789
2027
  }
1790
2028
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
1791
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
2029
+ matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, _pendingOrder);
1792
2030
  if (!(matchIndex >= 0)) {
1793
- _context14.next = 52;
2031
+ _context17.next = 56;
1794
2032
  break;
1795
2033
  }
1796
2034
  existingOrder = updatedList[matchIndex];
@@ -1799,6 +2037,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1799
2037
  need_sync: 1,
1800
2038
  is_draft_order: 0
1801
2039
  });
2040
+ previousStorageKey = previousStorageKeys[matchIndex];
2041
+ if (previousStorageKey && previousStorageKey !== _storageKey) {
2042
+ storageKeyMigrations.push({
2043
+ orderId: (_nextOrder$order_id2 = nextOrder.order_id) !== null && _nextOrder$order_id2 !== void 0 ? _nextOrder$order_id2 : null,
2044
+ from: previousStorageKey,
2045
+ to: _storageKey
2046
+ });
2047
+ delete nextOrder[ORDER_STORAGE_KEY_FIELD];
2048
+ }
1802
2049
  updatedList[matchIndex] = nextOrder;
1803
2050
  pendingSnapshot = pendingMap.get(_storageKey);
1804
2051
  if (pendingSnapshot) {
@@ -1807,57 +2054,59 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1807
2054
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1808
2055
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1809
2056
  mergeActions[_storageKey] = 'update';
1810
- return _context14.abrupt("continue", 56);
1811
- case 52:
2057
+ return _context17.abrupt("continue", 60);
2058
+ case 56:
1812
2059
  insertIndex = updatedList.length;
1813
2060
  updatedList.push(_pendingOrder);
1814
2061
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1815
2062
  mergeActions[_storageKey] = 'insert';
1816
- case 56:
1817
- _context14.next = 39;
2063
+ case 60:
2064
+ _context17.next = 41;
1818
2065
  break;
1819
- case 58:
1820
- _context14.next = 63;
2066
+ case 62:
2067
+ _context17.next = 67;
1821
2068
  break;
1822
- case 60:
1823
- _context14.prev = 60;
1824
- _context14.t1 = _context14["catch"](37);
1825
- _iterator9.e(_context14.t1);
1826
- case 63:
1827
- _context14.prev = 63;
2069
+ case 64:
2070
+ _context17.prev = 64;
2071
+ _context17.t1 = _context17["catch"](39);
2072
+ _iterator9.e(_context17.t1);
2073
+ case 67:
2074
+ _context17.prev = 67;
1828
2075
  _iterator9.f();
1829
- return _context14.finish(63);
1830
- case 66:
2076
+ return _context17.finish(67);
2077
+ case 70:
1831
2078
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1832
2079
  previousList = this.store.list;
1833
2080
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1834
2081
  this.syncOrdersMap();
1835
- _context14.prev = 70;
1836
- _context14.next = 73;
1837
- return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1838
- case 73:
1839
- _context14.next = 80;
2082
+ _context17.prev = 74;
2083
+ _context17.next = 77;
2084
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, _objectSpread(_objectSpread({}, options), {}, {
2085
+ storageKeyMigrations: storageKeyMigrations
2086
+ }));
2087
+ case 77:
2088
+ _context17.next = 84;
1840
2089
  break;
1841
- case 75:
1842
- _context14.prev = 75;
1843
- _context14.t2 = _context14["catch"](70);
2090
+ case 79:
2091
+ _context17.prev = 79;
2092
+ _context17.t2 = _context17["catch"](74);
1844
2093
  this.store.list = previousList;
1845
2094
  this.syncOrdersMap();
1846
- throw _context14.t2;
1847
- case 80:
2095
+ throw _context17.t2;
2096
+ case 84:
1848
2097
  this.logInfo('upsertPendingSyncOrders-结束', {
1849
2098
  count: patchedOrders.length,
1850
2099
  storeOrderCountAfter: this.store.list.length
1851
2100
  });
1852
- _context14.next = 83;
2101
+ _context17.next = 87;
1853
2102
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1854
- case 83:
2103
+ case 87:
1855
2104
  case "end":
1856
- return _context14.stop();
2105
+ return _context17.stop();
1857
2106
  }
1858
- }, _callee14, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2107
+ }, _callee17, this, [[7, 22, 25, 28], [39, 64, 67, 70], [74, 79]]);
1859
2108
  }));
1860
- function upsertPendingSyncOrders(_x10) {
2109
+ function upsertPendingSyncOrders(_x13) {
1861
2110
  return _upsertPendingSyncOrders.apply(this, arguments);
1862
2111
  }
1863
2112
  return upsertPendingSyncOrders;
@@ -1870,27 +2119,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1870
2119
  }, {
1871
2120
  key: "upsertLocalDraftOrders",
1872
2121
  value: (function () {
1873
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(draftOrders) {
1874
- var _this11 = this;
1875
- var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1876
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1877
- while (1) switch (_context15.prev = _context15.next) {
2122
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(draftOrders) {
2123
+ var _this12 = this;
2124
+ var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, storageKeyMigrations, mergeActions, updatedList, previousStorageKeys, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, previousStorageKey, reconciledDraftOrder, mergedOrder, nextOrder, _nextOrder$order_id3, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
2125
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2126
+ while (1) switch (_context18.prev = _context18.next) {
1878
2127
  case 0:
1879
2128
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1880
- _context15.next = 3;
2129
+ _context18.next = 3;
1881
2130
  break;
1882
2131
  }
1883
2132
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1884
- return _context15.abrupt("return");
2133
+ return _context18.abrupt("return");
1885
2134
  case 3:
1886
2135
  draftMap = new Map();
1887
2136
  memoryDraftMap = new Map();
1888
2137
  _iterator10 = _createForOfIteratorHelper(draftOrders);
1889
- _context15.prev = 6;
2138
+ _context18.prev = 6;
1890
2139
  _iterator10.s();
1891
2140
  case 8:
1892
2141
  if ((_step10 = _iterator10.n()).done) {
1893
- _context15.next = 19;
2142
+ _context18.next = 19;
1894
2143
  break;
1895
2144
  }
1896
2145
  order = _step10.value;
@@ -1900,10 +2149,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1900
2149
  });
1901
2150
  storageKey = this.getOrderStorageKey(draftOrder);
1902
2151
  if (storageKey) {
1903
- _context15.next = 14;
2152
+ _context18.next = 14;
1904
2153
  break;
1905
2154
  }
1906
- return _context15.abrupt("continue", 17);
2155
+ return _context18.abrupt("continue", 17);
1907
2156
  case 14:
1908
2157
  draftMap.set(storageKey, draftOrder);
1909
2158
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -1911,37 +2160,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1911
2160
  memoryDraftMap.set(storageKey, memoryDraftOrder);
1912
2161
  }
1913
2162
  case 17:
1914
- _context15.next = 8;
2163
+ _context18.next = 8;
1915
2164
  break;
1916
2165
  case 19:
1917
- _context15.next = 24;
2166
+ _context18.next = 24;
1918
2167
  break;
1919
2168
  case 21:
1920
- _context15.prev = 21;
1921
- _context15.t0 = _context15["catch"](6);
1922
- _iterator10.e(_context15.t0);
2169
+ _context18.prev = 21;
2170
+ _context18.t0 = _context18["catch"](6);
2171
+ _iterator10.e(_context18.t0);
1923
2172
  case 24:
1924
- _context15.prev = 24;
2173
+ _context18.prev = 24;
1925
2174
  _iterator10.f();
1926
- return _context15.finish(24);
2175
+ return _context18.finish(24);
1927
2176
  case 27:
1928
2177
  if (!(draftMap.size === 0)) {
1929
- _context15.next = 30;
2178
+ _context18.next = 30;
1930
2179
  break;
1931
2180
  }
1932
2181
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1933
2182
  count: draftOrders.length
1934
2183
  });
1935
- return _context15.abrupt("return");
2184
+ return _context18.abrupt("return");
1936
2185
  case 30:
1937
2186
  this.logInfo('upsertLocalDraftOrders-开始', {
1938
2187
  count: draftMap.size,
1939
2188
  memoryDraftCount: memoryDraftMap.size,
1940
2189
  sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
1941
2190
  });
2191
+ storageKeyMigrations = [];
1942
2192
  mergeActions = {};
1943
2193
  updatedList = this.store.list.filter(function (order) {
1944
- return _this11.shouldKeepOrderInMemory(order);
2194
+ return _this12.shouldKeepOrderInMemory(order);
2195
+ });
2196
+ previousStorageKeys = updatedList.map(function (order) {
2197
+ return _this12.getPersistedOrderStorageKey(order);
1945
2198
  });
1946
2199
  identityKeyToIndex = new Map();
1947
2200
  for (index = 0; index < updatedList.length; index += 1) {
@@ -1958,20 +2211,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1958
2211
  }
1959
2212
  }
1960
2213
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
1961
- _context15.prev = 36;
2214
+ _context18.prev = 38;
1962
2215
  _iterator12.s();
1963
- case 38:
2216
+ case 40:
1964
2217
  if ((_step12 = _iterator12.n()).done) {
1965
- _context15.next = 58;
2218
+ _context18.next = 62;
1966
2219
  break;
1967
2220
  }
1968
2221
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
1969
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
2222
+ matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, _draftOrder);
1970
2223
  if (!(matchIndex >= 0)) {
1971
- _context15.next = 52;
2224
+ _context18.next = 56;
1972
2225
  break;
1973
2226
  }
1974
2227
  existingOrder = updatedList[matchIndex];
2228
+ previousStorageKey = previousStorageKeys[matchIndex];
1975
2229
  reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, _draftOrder);
1976
2230
  this.applyHolderRelationsSnapshot(reconciledDraftOrder, existingOrder, _draftOrder);
1977
2231
  mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
@@ -1979,73 +2233,82 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1979
2233
  need_sync: 0,
1980
2234
  is_draft_order: 1
1981
2235
  });
2236
+ if (previousStorageKey && previousStorageKey !== _storageKey2) {
2237
+ storageKeyMigrations.push({
2238
+ orderId: (_nextOrder$order_id3 = nextOrder.order_id) !== null && _nextOrder$order_id3 !== void 0 ? _nextOrder$order_id3 : null,
2239
+ from: previousStorageKey,
2240
+ to: _storageKey2
2241
+ });
2242
+ delete nextOrder[ORDER_STORAGE_KEY_FIELD];
2243
+ }
1982
2244
  updatedList[matchIndex] = nextOrder;
1983
2245
  // SQLite 必须与内存中的草稿保持同一份 business_code,避免下次 hydrate 再次丢失分类。
1984
2246
  draftMap.set(_storageKey2, reconciledDraftOrder);
1985
2247
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1986
2248
  mergeActions[_storageKey2] = 'update';
1987
- return _context15.abrupt("continue", 56);
1988
- case 52:
2249
+ return _context18.abrupt("continue", 60);
2250
+ case 56:
1989
2251
  insertIndex = updatedList.length;
1990
2252
  updatedList.push(_draftOrder);
1991
2253
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1992
2254
  mergeActions[_storageKey2] = 'insert';
1993
- case 56:
1994
- _context15.next = 38;
2255
+ case 60:
2256
+ _context18.next = 40;
1995
2257
  break;
1996
- case 58:
1997
- _context15.next = 63;
2258
+ case 62:
2259
+ _context18.next = 67;
1998
2260
  break;
1999
- case 60:
2000
- _context15.prev = 60;
2001
- _context15.t1 = _context15["catch"](36);
2002
- _iterator12.e(_context15.t1);
2003
- case 63:
2004
- _context15.prev = 63;
2261
+ case 64:
2262
+ _context18.prev = 64;
2263
+ _context18.t1 = _context18["catch"](38);
2264
+ _iterator12.e(_context18.t1);
2265
+ case 67:
2266
+ _context18.prev = 67;
2005
2267
  _iterator12.f();
2006
- return _context15.finish(63);
2007
- case 66:
2268
+ return _context18.finish(67);
2269
+ case 70:
2008
2270
  patchedOrders = _toConsumableArray(draftMap.values());
2009
2271
  previousList = this.store.list;
2010
2272
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2011
2273
  this.syncOrdersMap();
2012
- _context15.prev = 70;
2013
- _context15.next = 73;
2274
+ _context18.prev = 74;
2275
+ _context18.next = 77;
2014
2276
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2015
- throwOnError: true
2277
+ throwOnError: true,
2278
+ storageKeyMigrations: storageKeyMigrations
2016
2279
  });
2017
- case 73:
2018
- _context15.next = 80;
2280
+ case 77:
2281
+ _context18.next = 84;
2019
2282
  break;
2020
- case 75:
2021
- _context15.prev = 75;
2022
- _context15.t2 = _context15["catch"](70);
2283
+ case 79:
2284
+ _context18.prev = 79;
2285
+ _context18.t2 = _context18["catch"](74);
2023
2286
  this.store.list = previousList;
2024
2287
  this.syncOrdersMap();
2025
- throw _context15.t2;
2026
- case 80:
2288
+ throw _context18.t2;
2289
+ case 84:
2027
2290
  this.logInfo('upsertLocalDraftOrders-结束', {
2028
2291
  count: patchedOrders.length,
2029
2292
  storeOrderCountAfter: this.store.list.length
2030
2293
  });
2031
2294
  removedLegacyMemoryDraft = previousList.some(function (order) {
2032
- return !_this11.shouldKeepOrderInMemory(order);
2295
+ return !_this12.shouldKeepOrderInMemory(order);
2033
2296
  });
2034
2297
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2035
- _context15.next = 85;
2298
+ _context18.next = 89;
2036
2299
  break;
2037
2300
  }
2038
- _context15.next = 85;
2301
+ _context18.next = 89;
2039
2302
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2040
- return _this11.shouldKeepOrderInMemory(order);
2303
+ return _this12.shouldKeepOrderInMemory(order);
2041
2304
  }), 'upsertLocalDraftOrders');
2042
- case 85:
2305
+ case 89:
2043
2306
  case "end":
2044
- return _context15.stop();
2307
+ return _context18.stop();
2045
2308
  }
2046
- }, _callee15, this, [[6, 21, 24, 27], [36, 60, 63, 66], [70, 75]]);
2309
+ }, _callee18, this, [[6, 21, 24, 27], [38, 64, 67, 70], [74, 79]]);
2047
2310
  }));
2048
- function upsertLocalDraftOrders(_x11) {
2311
+ function upsertLocalDraftOrders(_x14) {
2049
2312
  return _upsertLocalDraftOrders.apply(this, arguments);
2050
2313
  }
2051
2314
  return upsertLocalDraftOrders;
@@ -2057,42 +2320,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2057
2320
  }, {
2058
2321
  key: "fetchOrdersBySSE",
2059
2322
  value: (function () {
2060
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2323
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2061
2324
  var query,
2062
2325
  data,
2063
- _args16 = arguments;
2064
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2065
- while (1) switch (_context16.prev = _context16.next) {
2326
+ _args19 = arguments;
2327
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2328
+ while (1) switch (_context19.prev = _context19.next) {
2066
2329
  case 0:
2067
- query = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
2330
+ query = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {};
2068
2331
  if (this.orderDataSource) {
2069
- _context16.next = 3;
2332
+ _context19.next = 3;
2070
2333
  break;
2071
2334
  }
2072
- return _context16.abrupt("return", []);
2335
+ return _context19.abrupt("return", []);
2073
2336
  case 3:
2074
- _context16.prev = 3;
2075
- _context16.next = 6;
2337
+ _context19.prev = 3;
2338
+ _context19.next = 6;
2076
2339
  return this.orderDataSource.run({
2077
2340
  sse: {
2078
2341
  query: query
2079
2342
  }
2080
2343
  });
2081
2344
  case 6:
2082
- data = _context16.sent;
2083
- return _context16.abrupt("return", data || []);
2345
+ data = _context19.sent;
2346
+ return _context19.abrupt("return", data || []);
2084
2347
  case 10:
2085
- _context16.prev = 10;
2086
- _context16.t0 = _context16["catch"](3);
2348
+ _context19.prev = 10;
2349
+ _context19.t0 = _context19["catch"](3);
2087
2350
  this.logError('fetchOrdersBySSE-失败', {
2088
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0)
2351
+ error: _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0)
2089
2352
  });
2090
- return _context16.abrupt("return", []);
2353
+ return _context19.abrupt("return", []);
2091
2354
  case 14:
2092
2355
  case "end":
2093
- return _context16.stop();
2356
+ return _context19.stop();
2094
2357
  }
2095
- }, _callee16, this, [[3, 10]]);
2358
+ }, _callee19, this, [[3, 10]]);
2096
2359
  }));
2097
2360
  function fetchOrdersBySSE() {
2098
2361
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -2122,9 +2385,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2122
2385
  }, {
2123
2386
  key: "syncOrdersMap",
2124
2387
  value: function syncOrdersMap() {
2125
- var _this12 = this;
2388
+ var _this13 = this;
2126
2389
  this.store.list = this.store.list.filter(function (order) {
2127
- return _this12.shouldKeepOrderInMemory(order);
2390
+ return _this13.shouldKeepOrderInMemory(order);
2128
2391
  });
2129
2392
  this.store.map.clear();
2130
2393
  var _iterator13 = _createForOfIteratorHelper(this.store.list),
@@ -2180,7 +2443,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2180
2443
  }, {
2181
2444
  key: "getOrderIdentityEntries",
2182
2445
  value: function getOrderIdentityEntries(order) {
2183
- var _this13 = this;
2446
+ var _this14 = this;
2184
2447
  if (!order) return [];
2185
2448
  var record = order;
2186
2449
  var candidates = [{
@@ -2198,9 +2461,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2198
2461
  }];
2199
2462
  var entries = [];
2200
2463
  var _loop = function _loop() {
2201
- var candidate = _candidates[_i2];
2202
- if (_this13.isBlankIdentityValue(candidate.value)) return 0; // continue
2203
- var key = _this13.getIdKey(candidate.value);
2464
+ var candidate = _candidates[_i3];
2465
+ if (_this14.isBlankIdentityValue(candidate.value)) return 0; // continue
2466
+ var key = _this14.getIdKey(candidate.value);
2204
2467
  if (entries.some(function (entry) {
2205
2468
  return entry.field === candidate.field && entry.key === key;
2206
2469
  })) return 0; // continue
@@ -2210,7 +2473,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2210
2473
  });
2211
2474
  },
2212
2475
  _ret;
2213
- for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
2476
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
2214
2477
  _ret = _loop();
2215
2478
  if (_ret === 0) continue;
2216
2479
  }
@@ -2239,8 +2502,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2239
2502
  value: function getOrderDateKey(order) {
2240
2503
  var _order$bookings, _order$bookings2;
2241
2504
  var candidates = [order === null || order === void 0 ? void 0 : order.schedule_date, order === null || order === void 0 ? void 0 : order.create_date, order === null || order === void 0 ? void 0 : order.created_at, order === null || order === void 0 || (_order$bookings = order.bookings) === null || _order$bookings === void 0 || (_order$bookings = _order$bookings[0]) === null || _order$bookings === void 0 ? void 0 : _order$bookings.start_date, order === null || order === void 0 || (_order$bookings2 = order.bookings) === null || _order$bookings2 === void 0 || (_order$bookings2 = _order$bookings2[0]) === null || _order$bookings2 === void 0 ? void 0 : _order$bookings2.select_date];
2242
- for (var _i3 = 0, _candidates2 = candidates; _i3 < _candidates2.length; _i3++) {
2243
- var v = _candidates2[_i3];
2505
+ for (var _i4 = 0, _candidates2 = candidates; _i4 < _candidates2.length; _i4++) {
2506
+ var v = _candidates2[_i4];
2244
2507
  if (!v) continue;
2245
2508
  var text = String(v);
2246
2509
  if (!text) continue;
@@ -2267,29 +2530,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2267
2530
  }, {
2268
2531
  key: "setupOrderSync",
2269
2532
  value: function setupOrderSync() {
2270
- var _this14 = this;
2533
+ var _this15 = this;
2271
2534
  if (!this.orderDataSource) return;
2272
2535
  this.orderDataSource.run({
2273
2536
  pubsub: {
2274
2537
  callback: function callback(res) {
2275
2538
  var _message$id, _message$order_id, _message$type;
2276
2539
  var pubsubReceivedAt = Date.now();
2277
- var message = _this14.normalizeOrderSyncMessage(res);
2540
+ var message = _this15.normalizeOrderSyncMessage(res);
2278
2541
  if (!message) return;
2279
2542
  message._pubsubReceivedAt = pubsubReceivedAt;
2280
- _this14.pendingSyncMessages.push(message);
2281
- var throttleMs = _this14.getOrderSyncThrottleMs();
2282
- var routeInfo = _this14.resolveSyncMessageRoute(message);
2283
- _this14.logInfo('orderSync-收到消息并入队', {
2543
+ _this15.pendingSyncMessages.push(message);
2544
+ var throttleMs = _this15.getOrderSyncThrottleMs();
2545
+ var routeInfo = _this15.resolveSyncMessageRoute(message);
2546
+ _this15.logInfo('orderSync-收到消息并入队', {
2284
2547
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2285
2548
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2286
2549
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2287
- pendingCount: _this14.pendingSyncMessages.length,
2550
+ pendingCount: _this15.pendingSyncMessages.length,
2288
2551
  throttleMs: throttleMs,
2289
2552
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2290
2553
  fullMessage: JSON.stringify(message)
2291
2554
  });
2292
- _this14.scheduleOrderSyncThrottle();
2555
+ _this15.scheduleOrderSyncThrottle();
2293
2556
  }
2294
2557
  }
2295
2558
  }).catch(function () {
@@ -2306,7 +2569,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2306
2569
  }, {
2307
2570
  key: "scheduleOrderSyncThrottle",
2308
2571
  value: function scheduleOrderSyncThrottle() {
2309
- var _this15 = this;
2572
+ var _this16 = this;
2310
2573
  if (this.isProcessingSyncBatch) return;
2311
2574
  if (this.isIdlePhase) {
2312
2575
  this.isIdlePhase = false;
@@ -2317,8 +2580,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2317
2580
  if (this.syncTimer) return;
2318
2581
  var throttleMs = this.getOrderSyncThrottleMs();
2319
2582
  this.syncTimer = setTimeout(function () {
2320
- _this15.syncTimer = undefined;
2321
- void _this15.flushOrderSyncMessagesByThrottle();
2583
+ _this16.syncTimer = undefined;
2584
+ void _this16.flushOrderSyncMessagesByThrottle();
2322
2585
  }, throttleMs);
2323
2586
  }
2324
2587
 
@@ -2329,41 +2592,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2329
2592
  }, {
2330
2593
  key: "flushOrderSyncMessagesByThrottle",
2331
2594
  value: (function () {
2332
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2333
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2334
- while (1) switch (_context17.prev = _context17.next) {
2595
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2596
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2597
+ while (1) switch (_context20.prev = _context20.next) {
2335
2598
  case 0:
2336
2599
  if (!this.isProcessingSyncBatch) {
2337
- _context17.next = 2;
2600
+ _context20.next = 2;
2338
2601
  break;
2339
2602
  }
2340
- return _context17.abrupt("return");
2603
+ return _context20.abrupt("return");
2341
2604
  case 2:
2342
2605
  if (!(this.pendingSyncMessages.length === 0)) {
2343
- _context17.next = 5;
2606
+ _context20.next = 5;
2344
2607
  break;
2345
2608
  }
2346
2609
  this.isIdlePhase = true;
2347
- return _context17.abrupt("return");
2610
+ return _context20.abrupt("return");
2348
2611
  case 5:
2349
2612
  this.isProcessingSyncBatch = true;
2350
- _context17.prev = 6;
2351
- _context17.next = 9;
2613
+ _context20.prev = 6;
2614
+ _context20.next = 9;
2352
2615
  return this.processOrderSyncMessages();
2353
2616
  case 9:
2354
- _context17.prev = 9;
2617
+ _context20.prev = 9;
2355
2618
  this.isProcessingSyncBatch = false;
2356
2619
  if (this.pendingSyncMessages.length > 0) {
2357
2620
  this.scheduleOrderSyncThrottle();
2358
2621
  } else {
2359
2622
  this.isIdlePhase = true;
2360
2623
  }
2361
- return _context17.finish(9);
2624
+ return _context20.finish(9);
2362
2625
  case 13:
2363
2626
  case "end":
2364
- return _context17.stop();
2627
+ return _context20.stop();
2365
2628
  }
2366
- }, _callee17, this, [[6,, 9, 13]]);
2629
+ }, _callee20, this, [[6,, 9, 13]]);
2367
2630
  }));
2368
2631
  function flushOrderSyncMessagesByThrottle() {
2369
2632
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2385,19 +2648,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2385
2648
  }, {
2386
2649
  key: "processOrderSyncMessages",
2387
2650
  value: (function () {
2388
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2389
- var _this16 = this;
2651
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2652
+ var _this17 = this;
2390
2653
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2391
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2392
- while (1) switch (_context18.prev = _context18.next) {
2654
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2655
+ while (1) switch (_context21.prev = _context21.next) {
2393
2656
  case 0:
2394
2657
  messages = _toConsumableArray(this.pendingSyncMessages);
2395
2658
  this.pendingSyncMessages = [];
2396
2659
  if (!(messages.length === 0)) {
2397
- _context18.next = 4;
2660
+ _context21.next = 4;
2398
2661
  break;
2399
2662
  }
2400
- return _context18.abrupt("return");
2663
+ return _context21.abrupt("return");
2401
2664
  case 4:
2402
2665
  batchProcessStartAt = Date.now();
2403
2666
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2413,15 +2676,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2413
2676
  upsertOrders = new Map();
2414
2677
  refreshIds = [];
2415
2678
  messages.forEach(function (msg, msgIndex) {
2416
- var routeInfo = _this16.resolveSyncMessageRoute(msg);
2679
+ var routeInfo = _this17.resolveSyncMessageRoute(msg);
2417
2680
  var hasBatchIds = routeInfo.hasBatchIds;
2418
2681
  var singleId = routeInfo.singleId;
2419
2682
  var hasSingleId = routeInfo.hasSingleId;
2420
- var normalizedBody = _this16.normalizeOrderSyncPayload(msg.body || msg.data);
2683
+ var normalizedBody = _this17.normalizeOrderSyncPayload(msg.body || msg.data);
2421
2684
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2422
- var orderKey = _this16.getIdKey(normalizedBody.order_id);
2685
+ var orderKey = _this17.getIdKey(normalizedBody.order_id);
2423
2686
  var previousBody = upsertOrders.get(orderKey);
2424
- if (previousBody) _this16.applyHolderRelationsSnapshot(normalizedBody, previousBody, normalizedBody);
2687
+ if (previousBody) _this17.applyHolderRelationsSnapshot(normalizedBody, previousBody, normalizedBody);
2425
2688
  upsertOrders.set(orderKey, normalizedBody);
2426
2689
  return;
2427
2690
  }
@@ -2434,41 +2697,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2434
2697
  refreshIdCount: uniqueRefreshIds.length
2435
2698
  });
2436
2699
  if (!(upsertList.length > 0)) {
2437
- _context18.next = 16;
2700
+ _context21.next = 16;
2438
2701
  break;
2439
2702
  }
2440
- _context18.next = 16;
2703
+ _context21.next = 16;
2441
2704
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2442
2705
  case 16:
2443
2706
  if (!(uniqueRefreshIds.length > 0)) {
2444
- _context18.next = 28;
2707
+ _context21.next = 28;
2445
2708
  break;
2446
2709
  }
2447
2710
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2448
2711
  if (skipped.length > 0) {}
2449
2712
  if (!(toFetch.length > 0)) {
2450
- _context18.next = 28;
2713
+ _context21.next = 28;
2451
2714
  break;
2452
2715
  }
2453
- _context18.next = 22;
2716
+ _context21.next = 22;
2454
2717
  return this.fetchOrdersByHttp(toFetch);
2455
2718
  case 22:
2456
- freshOrders = _context18.sent;
2719
+ freshOrders = _context21.sent;
2457
2720
  if (!(freshOrders.length > 0)) {
2458
- _context18.next = 28;
2721
+ _context21.next = 28;
2459
2722
  break;
2460
2723
  }
2461
- _context18.next = 26;
2724
+ _context21.next = 26;
2462
2725
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2463
2726
  case 26:
2464
- _context18.next = 28;
2727
+ _context21.next = 28;
2465
2728
  break;
2466
2729
  case 28:
2467
2730
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2468
- _context18.next = 30;
2731
+ _context21.next = 30;
2469
2732
  break;
2470
2733
  }
2471
- return _context18.abrupt("return");
2734
+ return _context21.abrupt("return");
2472
2735
  case 30:
2473
2736
  batchProcessEndAt = Date.now();
2474
2737
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2477,13 +2740,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2477
2740
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2478
2741
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2479
2742
  });
2480
- _context18.next = 34;
2743
+ _context21.next = 34;
2481
2744
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2482
2745
  case 34:
2483
2746
  case "end":
2484
- return _context18.stop();
2747
+ return _context21.stop();
2485
2748
  }
2486
- }, _callee18, this);
2749
+ }, _callee21, this);
2487
2750
  }));
2488
2751
  function processOrderSyncMessages() {
2489
2752
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2504,29 +2767,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2504
2767
  }, {
2505
2768
  key: "fetchOrdersByHttp",
2506
2769
  value: (function () {
2507
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
2770
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids) {
2508
2771
  var _orderList, orderList;
2509
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2510
- while (1) switch (_context19.prev = _context19.next) {
2772
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2773
+ while (1) switch (_context22.prev = _context22.next) {
2511
2774
  case 0:
2512
2775
  if (!(!this.orderDataSource || ids.length === 0)) {
2513
- _context19.next = 2;
2776
+ _context22.next = 2;
2514
2777
  break;
2515
2778
  }
2516
- return _context19.abrupt("return", []);
2779
+ return _context22.abrupt("return", []);
2517
2780
  case 2:
2518
- _context19.prev = 2;
2781
+ _context22.prev = 2;
2519
2782
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2520
- _context19.next = 8;
2783
+ _context22.next = 8;
2521
2784
  break;
2522
2785
  }
2523
- _context19.next = 6;
2786
+ _context22.next = 6;
2524
2787
  return this.orderDataSource.fetchOrdersByIds(ids);
2525
2788
  case 6:
2526
- _orderList = _context19.sent;
2527
- return _context19.abrupt("return", _orderList || []);
2789
+ _orderList = _context22.sent;
2790
+ return _context22.abrupt("return", _orderList || []);
2528
2791
  case 8:
2529
- _context19.next = 10;
2792
+ _context22.next = 10;
2530
2793
  return this.orderDataSource.run({
2531
2794
  http: {
2532
2795
  query: {
@@ -2535,19 +2798,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2535
2798
  }
2536
2799
  });
2537
2800
  case 10:
2538
- orderList = _context19.sent;
2539
- return _context19.abrupt("return", orderList || []);
2801
+ orderList = _context22.sent;
2802
+ return _context22.abrupt("return", orderList || []);
2540
2803
  case 14:
2541
- _context19.prev = 14;
2542
- _context19.t0 = _context19["catch"](2);
2543
- return _context19.abrupt("return", []);
2804
+ _context22.prev = 14;
2805
+ _context22.t0 = _context22["catch"](2);
2806
+ return _context22.abrupt("return", []);
2544
2807
  case 17:
2545
2808
  case "end":
2546
- return _context19.stop();
2809
+ return _context22.stop();
2547
2810
  }
2548
- }, _callee19, this, [[2, 14]]);
2811
+ }, _callee22, this, [[2, 14]]);
2549
2812
  }));
2550
- function fetchOrdersByHttp(_x12) {
2813
+ function fetchOrdersByHttp(_x15) {
2551
2814
  return _fetchOrdersByHttp.apply(this, arguments);
2552
2815
  }
2553
2816
  return fetchOrdersByHttp;
@@ -2559,11 +2822,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2559
2822
  }, {
2560
2823
  key: "mergeOrdersToStore",
2561
2824
  value: (function () {
2562
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshOrders, source) {
2563
- var _this17 = this;
2825
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(freshOrders, source) {
2826
+ var _this18 = this;
2564
2827
  var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator15, _step15, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator16, _step16, key, _iterator17, _step17, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator18, _step18, _key2, _duplicateIndex, _iterator19, _step19, duplicateIndex, _index, _iterator20, _step20, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2565
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2566
- while (1) switch (_context20.prev = _context20.next) {
2828
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2829
+ while (1) switch (_context23.prev = _context23.next) {
2567
2830
  case 0:
2568
2831
  storeOrderCountBefore = this.store.list.length;
2569
2832
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2575,20 +2838,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2575
2838
  normalizedFreshOrders = [];
2576
2839
  incomingProductsHaveStableIdentity = new Map();
2577
2840
  _iterator15 = _createForOfIteratorHelper(freshOrders);
2578
- _context20.prev = 6;
2841
+ _context23.prev = 6;
2579
2842
  _iterator15.s();
2580
2843
  case 8:
2581
2844
  if ((_step15 = _iterator15.n()).done) {
2582
- _context20.next = 18;
2845
+ _context23.next = 18;
2583
2846
  break;
2584
2847
  }
2585
2848
  order = _step15.value;
2586
2849
  id = order === null || order === void 0 ? void 0 : order.order_id;
2587
2850
  if (!(id === undefined || id === null)) {
2588
- _context20.next = 13;
2851
+ _context23.next = 13;
2589
2852
  break;
2590
2853
  }
2591
- return _context20.abrupt("continue", 16);
2854
+ return _context23.abrupt("continue", 16);
2592
2855
  case 13:
2593
2856
  rawProducts = order.products;
2594
2857
  if (Array.isArray(rawProducts)) {
@@ -2598,19 +2861,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2598
2861
  }
2599
2862
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2600
2863
  case 16:
2601
- _context20.next = 8;
2864
+ _context23.next = 8;
2602
2865
  break;
2603
2866
  case 18:
2604
- _context20.next = 23;
2867
+ _context23.next = 23;
2605
2868
  break;
2606
2869
  case 20:
2607
- _context20.prev = 20;
2608
- _context20.t0 = _context20["catch"](6);
2609
- _iterator15.e(_context20.t0);
2870
+ _context23.prev = 20;
2871
+ _context23.t0 = _context23["catch"](6);
2872
+ _iterator15.e(_context23.t0);
2610
2873
  case 23:
2611
- _context20.prev = 23;
2874
+ _context23.prev = 23;
2612
2875
  _iterator15.f();
2613
- return _context20.finish(23);
2876
+ return _context23.finish(23);
2614
2877
  case 26:
2615
2878
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2616
2879
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
@@ -2621,10 +2884,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2621
2884
  storageKeyMigrations = [];
2622
2885
  mergeActions = {};
2623
2886
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2624
- return _this17.doProductsHaveStableMembershipIdentity(order.products);
2887
+ return _this18.doProductsHaveStableMembershipIdentity(order.products);
2625
2888
  });
2626
2889
  updatedList = this.store.list.map(function (order) {
2627
- return _this17.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2890
+ return _this18.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2628
2891
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2629
2892
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2630
2893
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
@@ -2645,11 +2908,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2645
2908
  }
2646
2909
  }
2647
2910
  _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2648
- _context20.prev = 38;
2911
+ _context23.prev = 38;
2649
2912
  _iterator17.s();
2650
2913
  case 40:
2651
2914
  if ((_step17 = _iterator17.n()).done) {
2652
- _context20.next = 101;
2915
+ _context23.next = 101;
2653
2916
  break;
2654
2917
  }
2655
2918
  fresh = _step17.value;
@@ -2658,13 +2921,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2658
2921
  storageKey = this.getOrderStorageKey(fresh);
2659
2922
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2660
2923
  if (!(matchIndex >= 0)) {
2661
- _context20.next = 93;
2924
+ _context23.next = 93;
2662
2925
  break;
2663
2926
  }
2664
2927
  existingOrder = updatedList[matchIndex];
2665
2928
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2666
2929
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2667
- _context20.next = 52;
2930
+ _context23.next = 52;
2668
2931
  break;
2669
2932
  }
2670
2933
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2677,10 +2940,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2677
2940
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2678
2941
  reason: 'protect_pending_sync_order_from_remote_echo'
2679
2942
  });
2680
- return _context20.abrupt("continue", 99);
2943
+ return _context23.abrupt("continue", 99);
2681
2944
  case 52:
2682
2945
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2683
- _context20.next = 55;
2946
+ _context23.next = 55;
2684
2947
  break;
2685
2948
  }
2686
2949
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2691,7 +2954,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2691
2954
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2692
2955
  reason: 'protect_draft_order_from_remote_echo'
2693
2956
  });
2694
- return _context20.abrupt("continue", 99);
2957
+ return _context23.abrupt("continue", 99);
2695
2958
  case 55:
2696
2959
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2697
2960
  freshOrderId = fresh.order_id;
@@ -2704,36 +2967,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2704
2967
  adjustedMatchIndex = matchIndex;
2705
2968
  duplicateIndexes = new Set();
2706
2969
  _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2707
- _context20.prev = 64;
2970
+ _context23.prev = 64;
2708
2971
  _iterator18.s();
2709
2972
  case 66:
2710
2973
  if ((_step18 = _iterator18.n()).done) {
2711
- _context20.next = 74;
2974
+ _context23.next = 74;
2712
2975
  break;
2713
2976
  }
2714
2977
  _key2 = _step18.value;
2715
2978
  _duplicateIndex = identityKeyToIndex.get(_key2);
2716
2979
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2717
- _context20.next = 71;
2980
+ _context23.next = 71;
2718
2981
  break;
2719
2982
  }
2720
- return _context20.abrupt("continue", 72);
2983
+ return _context23.abrupt("continue", 72);
2721
2984
  case 71:
2722
2985
  duplicateIndexes.add(_duplicateIndex);
2723
2986
  case 72:
2724
- _context20.next = 66;
2987
+ _context23.next = 66;
2725
2988
  break;
2726
2989
  case 74:
2727
- _context20.next = 79;
2990
+ _context23.next = 79;
2728
2991
  break;
2729
2992
  case 76:
2730
- _context20.prev = 76;
2731
- _context20.t1 = _context20["catch"](64);
2732
- _iterator18.e(_context20.t1);
2993
+ _context23.prev = 76;
2994
+ _context23.t1 = _context23["catch"](64);
2995
+ _iterator18.e(_context23.t1);
2733
2996
  case 79:
2734
- _context20.prev = 79;
2997
+ _context23.prev = 79;
2735
2998
  _iterator18.f();
2736
- return _context20.finish(79);
2999
+ return _context23.finish(79);
2737
3000
  case 82:
2738
3001
  if (duplicateIndexes.size > 0) {
2739
3002
  _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
@@ -2783,7 +3046,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2783
3046
  mergedStorageKey = this.getOrderStorageKey(mergedOrder);
2784
3047
  if (mergedStorageKey) forceWriteStorageKeys.add(mergedStorageKey);
2785
3048
  }
2786
- if (nextStorageKey && !isEqual(existingOrder.holder_relations, mergedOrder.holder_relations)) {
3049
+ if (nextStorageKey && (!isEqual(existingOrder.holder_relations, mergedOrder.holder_relations) || !isEqual(existingOrder.bookings, mergedOrder.bookings))) {
2787
3050
  forceWriteStorageKeys.add(nextStorageKey);
2788
3051
  }
2789
3052
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
@@ -2791,7 +3054,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2791
3054
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2792
3055
  patchedOrders.push(mergedOrder);
2793
3056
  if (mergeKey) mergeActions[mergeKey] = 'update';
2794
- return _context20.abrupt("continue", 99);
3057
+ return _context23.abrupt("continue", 99);
2795
3058
  case 93:
2796
3059
  insertIndex = updatedList.length;
2797
3060
  updatedList.push(fresh);
@@ -2800,19 +3063,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2800
3063
  patchedOrders.push(fresh);
2801
3064
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2802
3065
  case 99:
2803
- _context20.next = 40;
3066
+ _context23.next = 40;
2804
3067
  break;
2805
3068
  case 101:
2806
- _context20.next = 106;
3069
+ _context23.next = 106;
2807
3070
  break;
2808
3071
  case 103:
2809
- _context20.prev = 103;
2810
- _context20.t2 = _context20["catch"](38);
2811
- _iterator17.e(_context20.t2);
3072
+ _context23.prev = 103;
3073
+ _context23.t2 = _context23["catch"](38);
3074
+ _iterator17.e(_context23.t2);
2812
3075
  case 106:
2813
- _context20.prev = 106;
3076
+ _context23.prev = 106;
2814
3077
  _iterator17.f();
2815
- return _context20.finish(106);
3078
+ return _context23.finish(106);
2816
3079
  case 109:
2817
3080
  insertCount = Object.values(mergeActions).filter(function (v) {
2818
3081
  return v === 'insert';
@@ -2829,7 +3092,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2829
3092
  // 仅在自检开关开启时做一次兜底校验。
2830
3093
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2831
3094
  this.syncOrdersMap();
2832
- _context20.next = 116;
3095
+ _context23.next = 116;
2833
3096
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2834
3097
  storageKeyMigrations: storageKeyMigrations
2835
3098
  }, forceWriteStorageKeys);
@@ -2840,18 +3103,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2840
3103
  insertCount: insertCount,
2841
3104
  updateCount: updateCount
2842
3105
  });
2843
- _context20.next = 119;
3106
+ _context23.next = 119;
2844
3107
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2845
3108
  case 119:
2846
- _context20.next = 121;
3109
+ _context23.next = 121;
2847
3110
  return this.emitOrdersChanged(patchedOrders, source);
2848
3111
  case 121:
2849
3112
  case "end":
2850
- return _context20.stop();
3113
+ return _context23.stop();
2851
3114
  }
2852
- }, _callee20, this, [[6, 20, 23, 26], [38, 103, 106, 109], [64, 76, 79, 82]]);
3115
+ }, _callee23, this, [[6, 20, 23, 26], [38, 103, 106, 109], [64, 76, 79, 82]]);
2853
3116
  }));
2854
- function mergeOrdersToStore(_x13, _x14) {
3117
+ function mergeOrdersToStore(_x16, _x17) {
2855
3118
  return _mergeOrdersToStore.apply(this, arguments);
2856
3119
  }
2857
3120
  return mergeOrdersToStore;
@@ -2931,7 +3194,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2931
3194
  }, {
2932
3195
  key: "getRemoteProductMembershipChange",
2933
3196
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2934
- var _this18 = this,
3197
+ var _this19 = this,
2935
3198
  _mergedOrder$order_id2;
2936
3199
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
2937
3200
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
@@ -2946,13 +3209,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2946
3209
  var _loop2 = function _loop2() {
2947
3210
  var previousProduct = _step22.value;
2948
3211
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2949
- return unmatchedCurrentIndexes.has(index) && _this18.isSameProductMembershipItem(previousProduct, currentProduct);
3212
+ return unmatchedCurrentIndexes.has(index) && _this19.isSameProductMembershipItem(previousProduct, currentProduct);
2950
3213
  });
2951
3214
  if (matchedIndex >= 0) {
2952
3215
  unmatchedCurrentIndexes.delete(matchedIndex);
2953
3216
  return 1; // continue
2954
3217
  }
2955
- var productKey = _this18.getProductMembershipKey(previousProduct);
3218
+ var productKey = _this19.getProductMembershipKey(previousProduct);
2956
3219
  if (productKey) removedProductKeys.push(productKey);
2957
3220
  };
2958
3221
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
@@ -2964,7 +3227,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2964
3227
  _iterator22.f();
2965
3228
  }
2966
3229
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2967
- return _this18.getProductMembershipKey(currentProducts[index]);
3230
+ return _this19.getProductMembershipKey(currentProducts[index]);
2968
3231
  }).filter(Boolean);
2969
3232
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2970
3233
  return null;
@@ -3079,12 +3342,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3079
3342
  }, {
3080
3343
  key: "isOrderLookupMatch",
3081
3344
  value: function isOrderLookupMatch(order, lookupKey) {
3082
- var _this19 = this;
3345
+ var _this20 = this;
3083
3346
  if (!order || !lookupKey) return false;
3084
3347
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
3085
3348
  return candidates.some(function (value) {
3086
3349
  if (value === undefined || value === null || value === '') return false;
3087
- return _this19.getIdKey(value) === lookupKey;
3350
+ return _this20.getIdKey(value) === lookupKey;
3088
3351
  });
3089
3352
  }
3090
3353
 
@@ -3117,6 +3380,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3117
3380
  }
3118
3381
  return this.getOrderStorageKey(order);
3119
3382
  }
3383
+ }, {
3384
+ key: "getRealOrderId",
3385
+ value: function getRealOrderId(order) {
3386
+ if (this.isBlankIdentityValue(order.order_id)) return '';
3387
+ if (String(order.order_id) === String(order.external_sale_number)) return '';
3388
+ return String(order.order_id);
3389
+ }
3390
+ }, {
3391
+ key: "findLocalOrderIndexByIdentity",
3392
+ value: function findLocalOrderIndexByIdentity(identityKeyToIndex, orders, target) {
3393
+ var _indexes$find,
3394
+ _this21 = this;
3395
+ var id = this.getRealOrderId(target);
3396
+ var keys = id ? ["order_id:".concat(id)] : [];
3397
+ if (!this.isBlankIdentityValue(target.external_sale_number)) {
3398
+ keys.push("external_sale_number:".concat(target.external_sale_number));
3399
+ }
3400
+ var indexes = keys.map(function (key) {
3401
+ return identityKeyToIndex.get(key);
3402
+ }).filter(function (index) {
3403
+ return index !== undefined;
3404
+ }).sort(function (left, right) {
3405
+ return left - right;
3406
+ });
3407
+ return (_indexes$find = indexes.find(function (index) {
3408
+ var existingId = _this21.getRealOrderId(orders[index]);
3409
+ return !id || !existingId || id === existingId;
3410
+ })) !== null && _indexes$find !== void 0 ? _indexes$find : -1;
3411
+ }
3120
3412
  }, {
3121
3413
  key: "getOrderIdentityMatchKeys",
3122
3414
  value: function getOrderIdentityMatchKeys(order) {
@@ -3136,10 +3428,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3136
3428
  }, {
3137
3429
  key: "findOrderIndexByIdentity",
3138
3430
  value: function findOrderIndexByIdentity(orders, target) {
3139
- var _this20 = this;
3431
+ var _this22 = this;
3140
3432
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
3141
3433
  return orders.findIndex(function (order) {
3142
- return _this20.doOrdersShareIdentity(order, target);
3434
+ return _this22.doOrdersShareIdentity(order, target);
3143
3435
  });
3144
3436
  }
3145
3437
  }, {
@@ -3262,7 +3554,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3262
3554
  }, {
3263
3555
  key: "shouldProtectLocalOrderFromRemoteSnapshot",
3264
3556
  value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
3265
- return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
3557
+ return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0 || requiresLocalPaymentRefresh(order) || (order.payments || []).some(isLocalFinalizedPayment);
3266
3558
  }
3267
3559
  }, {
3268
3560
  key: "getUnmatchedIdentifiedPendingPayments",
@@ -3296,7 +3588,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3296
3588
  }, {
3297
3589
  key: "preserveOmittedHolderRelations",
3298
3590
  value: function preserveOmittedHolderRelations(incomingOrders, existingOrders) {
3299
- var _this21 = this;
3591
+ var _this23 = this;
3300
3592
  var existingByIdentity = new Map();
3301
3593
  var _iterator29 = _createForOfIteratorHelper(existingOrders),
3302
3594
  _step29;
@@ -3324,12 +3616,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3324
3616
  }
3325
3617
  return incomingOrders.map(function (order) {
3326
3618
  if (Array.isArray(order.holder_relations)) return order;
3327
- var existingOrder = _this21.getOrderIdentityMatchKeys(order).map(function (key) {
3619
+ var existingOrder = _this23.getOrderIdentityMatchKeys(order).map(function (key) {
3328
3620
  return existingByIdentity.get(key);
3329
3621
  }).find(Boolean);
3330
3622
  if (!existingOrder) return order;
3331
3623
  var nextOrder = _objectSpread({}, order);
3332
- _this21.applyHolderRelationsSnapshot(nextOrder, existingOrder, order);
3624
+ _this23.applyHolderRelationsSnapshot(nextOrder, existingOrder, order);
3333
3625
  return nextOrder;
3334
3626
  });
3335
3627
  }
@@ -3346,9 +3638,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3346
3638
  var secondaryRecord = secondary;
3347
3639
  var existingRecord = existing;
3348
3640
  var incomingRecord = incoming;
3641
+ if (requiresLocalPaymentRefresh(existing)) {
3642
+ mergedRecord.metadata = _objectSpread(_objectSpread({}, mergedRecord.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
3643
+ }
3349
3644
  var childUidRemaps = [];
3350
- for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
3351
- var field = _fieldsToPreserve[_i4];
3645
+ for (var _i5 = 0, _fieldsToPreserve = fieldsToPreserve; _i5 < _fieldsToPreserve.length; _i5++) {
3646
+ var field = _fieldsToPreserve[_i5];
3352
3647
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
3353
3648
  mergedRecord[field] = preferredRecord[field];
3354
3649
  continue;
@@ -3357,8 +3652,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3357
3652
  mergedRecord[field] = secondaryRecord[field];
3358
3653
  }
3359
3654
  }
3360
- for (var _i5 = 0, _incomingPatchFields = incomingPatchFields; _i5 < _incomingPatchFields.length; _i5++) {
3361
- var _field = _incomingPatchFields[_i5];
3655
+ for (var _i6 = 0, _incomingPatchFields = incomingPatchFields; _i6 < _incomingPatchFields.length; _i6++) {
3656
+ var _field = _incomingPatchFields[_i6];
3362
3657
  if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
3363
3658
  if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
3364
3659
  if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
@@ -3374,8 +3669,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3374
3669
 
3375
3670
  // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
3376
3671
  // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
3377
- for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
3378
- var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
3672
+ for (var _i7 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i7 < _ORDER_AUTHORITATIVE_2.length; _i7++) {
3673
+ var _field2 = _ORDER_AUTHORITATIVE_2[_i7];
3379
3674
  if (Array.isArray(incomingRecord[_field2])) {
3380
3675
  if (_field2 === 'payments') {
3381
3676
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
@@ -3626,67 +3921,398 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3626
3921
  }, {
3627
3922
  key: "loadOrdersFromSQLite",
3628
3923
  value: function () {
3629
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3630
- var _this22 = this;
3924
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3925
+ var _this24 = this;
3631
3926
  var options,
3632
- _options$onTiming,
3633
3927
  loadStartedAt,
3634
- rawReadStartedAt,
3635
- orders,
3636
- sqliteRawReadMs,
3637
- normalizeStartedAt,
3928
+ memoryBeforeLoad,
3638
3929
  normalizedOrders,
3639
- sqliteNormalizeMs,
3640
- _args21 = arguments;
3641
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3642
- while (1) switch (_context21.prev = _context21.next) {
3930
+ previousOrders,
3931
+ protectedMemoryOrders,
3932
+ _args25 = arguments;
3933
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3934
+ while (1) switch (_context25.prev = _context25.next) {
3643
3935
  case 0:
3644
- options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
3936
+ options = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
3645
3937
  if (this.dbManager) {
3646
- _context21.next = 3;
3938
+ _context25.next = 3;
3647
3939
  break;
3648
3940
  }
3649
- return _context21.abrupt("return", []);
3941
+ return _context25.abrupt("return", []);
3650
3942
  case 3:
3651
- _context21.prev = 3;
3943
+ _context25.prev = 3;
3652
3944
  loadStartedAt = performance.now();
3653
- rawReadStartedAt = performance.now();
3654
- _context21.next = 8;
3655
- return this.dbManager.getAll(INDEXDB_STORE_NAME);
3656
- case 8:
3657
- orders = _context21.sent;
3658
- sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3659
- normalizeStartedAt = performance.now();
3660
- normalizedOrders = (orders || []).map(function (order) {
3661
- return _this22.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3662
- });
3663
- sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3664
- (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
3665
- sqliteRawReadMs: sqliteRawReadMs,
3666
- sqliteNormalizeMs: sqliteNormalizeMs,
3667
- sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3668
- });
3669
- return _context21.abrupt("return", normalizedOrders);
3670
- case 17:
3671
- _context21.prev = 17;
3672
- _context21.t0 = _context21["catch"](3);
3945
+ memoryBeforeLoad = this.store.list;
3946
+ normalizedOrders = []; // 读修复与普通订单写入共用队列,避免用排队前的旧快照覆盖新的待同步订单。
3947
+ _context25.next = 9;
3948
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3949
+ var _options$onTiming;
3950
+ var rawReadStartedAt, orders, sqliteRawReadMs, normalizeStartedAt, _this24$deduplicateSt, list, repairs, obsoleteKeys, sqliteNormalizeMs, _iterator34, _step34, key;
3951
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3952
+ while (1) switch (_context24.prev = _context24.next) {
3953
+ case 0:
3954
+ rawReadStartedAt = performance.now();
3955
+ _context24.next = 3;
3956
+ return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
3957
+ case 3:
3958
+ orders = _context24.sent;
3959
+ sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3960
+ normalizeStartedAt = performance.now();
3961
+ _this24$deduplicateSt = _this24.deduplicateStoredOrders(orders || []), list = _this24$deduplicateSt.list, repairs = _this24$deduplicateSt.repairs, obsoleteKeys = _this24$deduplicateSt.obsoleteKeys;
3962
+ normalizedOrders = list;
3963
+ sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3964
+ if (!(repairs.length > 0)) {
3965
+ _context24.next = 38;
3966
+ break;
3967
+ }
3968
+ _context24.prev = 10;
3969
+ _context24.next = 13;
3970
+ return _this24.writeOrderRowsToSQLite(repairs);
3971
+ case 13:
3972
+ _this24.recordRecentSqliteWrite('loadOrdersFromSQLite.deduplicate', repairs);
3973
+ _iterator34 = _createForOfIteratorHelper(obsoleteKeys);
3974
+ _context24.prev = 15;
3975
+ _iterator34.s();
3976
+ case 17:
3977
+ if ((_step34 = _iterator34.n()).done) {
3978
+ _context24.next = 24;
3979
+ break;
3980
+ }
3981
+ key = _step34.value;
3982
+ _context24.next = 21;
3983
+ return _this24.dbManager.delete(INDEXDB_STORE_NAME, key);
3984
+ case 21:
3985
+ _this24.recentSqliteWriteByStorageKey.delete(key);
3986
+ case 22:
3987
+ _context24.next = 17;
3988
+ break;
3989
+ case 24:
3990
+ _context24.next = 29;
3991
+ break;
3992
+ case 26:
3993
+ _context24.prev = 26;
3994
+ _context24.t0 = _context24["catch"](15);
3995
+ _iterator34.e(_context24.t0);
3996
+ case 29:
3997
+ _context24.prev = 29;
3998
+ _iterator34.f();
3999
+ return _context24.finish(29);
4000
+ case 32:
4001
+ _this24.logInfo('SQLite重复订单已修复', {
4002
+ beforeCount: orders.length,
4003
+ afterCount: list.length,
4004
+ repairedCount: repairs.length,
4005
+ deletedKeyCount: obsoleteKeys.size
4006
+ });
4007
+ _context24.next = 38;
4008
+ break;
4009
+ case 35:
4010
+ _context24.prev = 35;
4011
+ _context24.t1 = _context24["catch"](10);
4012
+ // 本次仍使用去重后的内存快照;保留磁盘记录,后续读取可重试修复。
4013
+ _this24.logError('SQLite重复订单修复写入失败', {
4014
+ error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4015
+ repairedCount: repairs.length
4016
+ });
4017
+ case 38:
4018
+ (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
4019
+ sqliteRawReadMs: sqliteRawReadMs,
4020
+ sqliteNormalizeMs: sqliteNormalizeMs,
4021
+ sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
4022
+ });
4023
+ case 39:
4024
+ case "end":
4025
+ return _context24.stop();
4026
+ }
4027
+ }, _callee24, null, [[10, 35], [15, 26, 29, 32]]);
4028
+ })));
4029
+ case 9:
4030
+ if (this.store.list !== memoryBeforeLoad) {
4031
+ // 读取期间可能已开始新的本地结账;回灌不能抹掉尚在排队落库的修改。
4032
+ previousOrders = new Map(memoryBeforeLoad.map(function (order) {
4033
+ return [_this24.getOrderStorageKey(order), order];
4034
+ }));
4035
+ protectedMemoryOrders = this.store.list.filter(function (order) {
4036
+ return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order) && !isEqual(previousOrders.get(_this24.getOrderStorageKey(order)), order);
4037
+ });
4038
+ normalizedOrders = this.deduplicateStoredOrders([].concat(_toConsumableArray(normalizedOrders), _toConsumableArray(protectedMemoryOrders)), new Set(protectedMemoryOrders)).list;
4039
+ }
4040
+ return _context25.abrupt("return", normalizedOrders);
4041
+ case 13:
4042
+ _context25.prev = 13;
4043
+ _context25.t0 = _context25["catch"](3);
3673
4044
  if (!options.throwOnError) {
3674
- _context21.next = 21;
4045
+ _context25.next = 17;
3675
4046
  break;
3676
4047
  }
3677
- throw _context21.t0;
3678
- case 21:
3679
- return _context21.abrupt("return", []);
3680
- case 22:
4048
+ throw _context25.t0;
4049
+ case 17:
4050
+ return _context25.abrupt("return", []);
4051
+ case 18:
3681
4052
  case "end":
3682
- return _context21.stop();
4053
+ return _context25.stop();
3683
4054
  }
3684
- }, _callee21, this, [[3, 17]]);
4055
+ }, _callee25, this, [[3, 13]]);
3685
4056
  }));
3686
4057
  function loadOrdersFromSQLite() {
3687
4058
  return _loadOrdersFromSQLite.apply(this, arguments);
3688
4059
  }
3689
4060
  return loadOrdersFromSQLite;
4061
+ }() /** 历史记录只按真实订单 ID / 唯一本地编号归组,不使用桌号或小票短号。 */
4062
+ }, {
4063
+ key: "deduplicateStoredOrders",
4064
+ value: function deduplicateStoredOrders(orders) {
4065
+ var _this25 = this;
4066
+ var authoritativeOrders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
4067
+ var idsByExternal = new Map();
4068
+ var _iterator35 = _createForOfIteratorHelper(orders),
4069
+ _step35;
4070
+ try {
4071
+ for (_iterator35.s(); !(_step35 = _iterator35.n()).done;) {
4072
+ var order = _step35.value;
4073
+ var id = this.getRealOrderId(order);
4074
+ var external = order.external_sale_number;
4075
+ if (!id || this.isBlankIdentityValue(external)) continue;
4076
+ var key = String(external);
4077
+ var previous = idsByExternal.get(key);
4078
+ idsByExternal.set(key, previous === undefined || previous === id ? id : null);
4079
+ }
4080
+ } catch (err) {
4081
+ _iterator35.e(err);
4082
+ } finally {
4083
+ _iterator35.f();
4084
+ }
4085
+ var groups = new Map();
4086
+ var _iterator36 = _createForOfIteratorHelper(orders.entries()),
4087
+ _step36;
4088
+ try {
4089
+ for (_iterator36.s(); !(_step36 = _iterator36.n()).done;) {
4090
+ var _step36$value = _slicedToArray(_step36.value, 2),
4091
+ index = _step36$value[0],
4092
+ rawOrder = _step36$value[1];
4093
+ var _external = this.isBlankIdentityValue(rawOrder.external_sale_number) ? '' : String(rawOrder.external_sale_number);
4094
+ var _id = this.getRealOrderId(rawOrder) || _external && idsByExternal.get(_external);
4095
+ var identity = _id ? "id:".concat(_id) : _external ? "external:".concat(_external) : "row:".concat(index);
4096
+ var storageKey = this.getPersistedOrderStorageKey(rawOrder);
4097
+ var _order = this.normalizeOrderCollectionsForIngress(rawOrder, 'loadOrdersFromSQLite');
4098
+ var group = groups.get(identity);
4099
+ if (group) {
4100
+ group.order = this.mergeStoredOrderCopies(group.order, _order, authoritativeOrders.has(rawOrder));
4101
+ group.keys.add(storageKey);
4102
+ group.count += 1;
4103
+ } else {
4104
+ groups.set(identity, {
4105
+ order: _order,
4106
+ keys: new Set([storageKey]),
4107
+ count: 1
4108
+ });
4109
+ }
4110
+ }
4111
+ } catch (err) {
4112
+ _iterator36.e(err);
4113
+ } finally {
4114
+ _iterator36.f();
4115
+ }
4116
+ var canonicalKeyCounts = new Map();
4117
+ var _iterator37 = _createForOfIteratorHelper(groups.values()),
4118
+ _step37;
4119
+ try {
4120
+ for (_iterator37.s(); !(_step37 = _iterator37.n()).done;) {
4121
+ var _order2 = _step37.value.order;
4122
+ var _key4 = this.getOrderStorageKey(_order2);
4123
+ canonicalKeyCounts.set(_key4, (canonicalKeyCounts.get(_key4) || 0) + 1);
4124
+ }
4125
+ } catch (err) {
4126
+ _iterator37.e(err);
4127
+ } finally {
4128
+ _iterator37.f();
4129
+ }
4130
+ var list = [];
4131
+ var repairs = [];
4132
+ var obsoleteKeys = new Set();
4133
+ var _iterator38 = _createForOfIteratorHelper(groups.values()),
4134
+ _step38;
4135
+ try {
4136
+ var _loop3 = function _loop3() {
4137
+ var group = _step38.value;
4138
+ var key = _this25.getOrderStorageKey(group.order);
4139
+ var needsRepair = group.count > 1 || _toConsumableArray(group.keys).some(function (oldKey) {
4140
+ return oldKey !== key;
4141
+ });
4142
+ // 不同真实订单若错误地共用 external 编号,不允许修复写入互相覆盖。
4143
+ if (needsRepair && key && canonicalKeyCounts.get(key) === 1) {
4144
+ group.order = _objectSpread(_objectSpread({}, group.order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, key));
4145
+ repairs.push(group.order);
4146
+ var _iterator39 = _createForOfIteratorHelper(group.keys),
4147
+ _step39;
4148
+ try {
4149
+ for (_iterator39.s(); !(_step39 = _iterator39.n()).done;) {
4150
+ var oldKey = _step39.value;
4151
+ if (oldKey && oldKey !== key && !canonicalKeyCounts.has(oldKey)) obsoleteKeys.add(oldKey);
4152
+ }
4153
+ } catch (err) {
4154
+ _iterator39.e(err);
4155
+ } finally {
4156
+ _iterator39.f();
4157
+ }
4158
+ }
4159
+ list.push(group.order);
4160
+ };
4161
+ for (_iterator38.s(); !(_step38 = _iterator38.n()).done;) {
4162
+ _loop3();
4163
+ }
4164
+ } catch (err) {
4165
+ _iterator38.e(err);
4166
+ } finally {
4167
+ _iterator38.f();
4168
+ }
4169
+ return {
4170
+ list: list,
4171
+ repairs: repairs,
4172
+ obsoleteKeys: obsoleteKeys
4173
+ };
4174
+ }
4175
+ }, {
4176
+ key: "mergeStoredOrderCopies",
4177
+ value: function mergeStoredOrderCopies(left, right) {
4178
+ var _this26 = this;
4179
+ var preferIncoming = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
4180
+ var priority = function priority(order) {
4181
+ return _this26.isPendingSyncOrder(order) ? 2 : _this26.isDraftOrder(order) ? 1 : 0;
4182
+ };
4183
+ var leftHasExternal = !this.isBlankIdentityValue(left.external_sale_number);
4184
+ var rightHasExternal = !this.isBlankIdentityValue(right.external_sale_number);
4185
+ var preferred = leftHasExternal !== rightHasExternal ? leftHasExternal ? left : right : this.pickPreferredOrder(left, right);
4186
+ if (preferIncoming) {
4187
+ preferred = right;
4188
+ } else if (priority(left) !== priority(right)) {
4189
+ preferred = priority(left) > priority(right) ? left : right;
4190
+ } else {
4191
+ var _iterator40 = _createForOfIteratorHelper(['updated_at', 'created_at']),
4192
+ _step40;
4193
+ try {
4194
+ var _loop4 = function _loop4() {
4195
+ var field = _step40.value;
4196
+ var timestamp = function timestamp(order) {
4197
+ var value = order[field];
4198
+ if (!value) return 0;
4199
+ var parsed = dayjs(value);
4200
+ return parsed.isValid() ? parsed.valueOf() : 0;
4201
+ };
4202
+ if (timestamp(left) === timestamp(right)) return 0; // continue
4203
+ preferred = timestamp(left) > timestamp(right) ? left : right;
4204
+ return 1; // break
4205
+ },
4206
+ _ret2;
4207
+ for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
4208
+ _ret2 = _loop4();
4209
+ if (_ret2 === 0) continue;
4210
+ if (_ret2 === 1) break;
4211
+ }
4212
+ } catch (err) {
4213
+ _iterator40.e(err);
4214
+ } finally {
4215
+ _iterator40.f();
4216
+ }
4217
+ }
4218
+ var secondary = preferred === left ? right : left;
4219
+ // 复用集合合并中的 pending/finalized 支付保护,但完整业务快照以胜者为准。
4220
+ var reconciled = this.mergeOrderRecords(secondary, preferred);
4221
+ var merged = _objectSpread(_objectSpread({}, reconciled), cloneDeep(preferred));
4222
+ var realOrder = this.getRealOrderId(preferred) ? preferred : secondary;
4223
+ if (this.getRealOrderId(realOrder)) merged.order_id = realOrder.order_id;
4224
+ var _iterator41 = _createForOfIteratorHelper(this.getOrderIdentityEntries(reconciled)),
4225
+ _step41;
4226
+ try {
4227
+ for (_iterator41.s(); !(_step41 = _iterator41.n()).done;) {
4228
+ var _field3 = _step41.value.field;
4229
+ if (this.isBlankIdentityValue(merged[_field3])) merged[_field3] = reconciled[_field3];
4230
+ }
4231
+ } catch (err) {
4232
+ _iterator41.e(err);
4233
+ } finally {
4234
+ _iterator41.f();
4235
+ }
4236
+ for (var _i8 = 0, _ORDER_AUTHORITATIVE_3 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i8 < _ORDER_AUTHORITATIVE_3.length; _i8++) {
4237
+ var field = _ORDER_AUTHORITATIVE_3[_i8];
4238
+ if (Object.prototype.hasOwnProperty.call(reconciled, field)) merged[field] = reconciled[field];
4239
+ }
4240
+ if (requiresLocalPaymentRefresh(secondary)) {
4241
+ merged.metadata = _objectSpread(_objectSpread({}, merged.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
4242
+ }
4243
+ merged.need_sync = this.isPendingSyncOrder(left) || this.isPendingSyncOrder(right) ? 1 : 0;
4244
+ merged.is_draft_order = this.isDraftOrder(preferred) ? 1 : 0;
4245
+ return merged;
4246
+ }
4247
+ }, {
4248
+ key: "writeOrderRowsToSQLite",
4249
+ value: function () {
4250
+ var _writeOrderRowsToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orders) {
4251
+ var _iterator42, _step42, order;
4252
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4253
+ while (1) switch (_context26.prev = _context26.next) {
4254
+ case 0:
4255
+ if (!(typeof this.dbManager.bulkUpdate === 'function')) {
4256
+ _context26.next = 4;
4257
+ break;
4258
+ }
4259
+ _context26.next = 3;
4260
+ return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders);
4261
+ case 3:
4262
+ return _context26.abrupt("return", 'bulkUpdate');
4263
+ case 4:
4264
+ if (!(typeof this.dbManager.bulkAdd === 'function')) {
4265
+ _context26.next = 8;
4266
+ break;
4267
+ }
4268
+ _context26.next = 7;
4269
+ return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orders);
4270
+ case 7:
4271
+ return _context26.abrupt("return", 'bulkAdd');
4272
+ case 8:
4273
+ if (!(typeof this.dbManager.update === 'function')) {
4274
+ _context26.next = 27;
4275
+ break;
4276
+ }
4277
+ _iterator42 = _createForOfIteratorHelper(orders);
4278
+ _context26.prev = 10;
4279
+ _iterator42.s();
4280
+ case 12:
4281
+ if ((_step42 = _iterator42.n()).done) {
4282
+ _context26.next = 18;
4283
+ break;
4284
+ }
4285
+ order = _step42.value;
4286
+ _context26.next = 16;
4287
+ return this.dbManager.update(INDEXDB_STORE_NAME, order);
4288
+ case 16:
4289
+ _context26.next = 12;
4290
+ break;
4291
+ case 18:
4292
+ _context26.next = 23;
4293
+ break;
4294
+ case 20:
4295
+ _context26.prev = 20;
4296
+ _context26.t0 = _context26["catch"](10);
4297
+ _iterator42.e(_context26.t0);
4298
+ case 23:
4299
+ _context26.prev = 23;
4300
+ _iterator42.f();
4301
+ return _context26.finish(23);
4302
+ case 26:
4303
+ return _context26.abrupt("return", 'update');
4304
+ case 27:
4305
+ throw new Error('订单 SQLite 数据库不支持写入');
4306
+ case 28:
4307
+ case "end":
4308
+ return _context26.stop();
4309
+ }
4310
+ }, _callee26, this, [[10, 20, 23, 26]]);
4311
+ }));
4312
+ function writeOrderRowsToSQLite(_x18) {
4313
+ return _writeOrderRowsToSQLite.apply(this, arguments);
4314
+ }
4315
+ return writeOrderRowsToSQLite;
3690
4316
  }()
3691
4317
  }, {
3692
4318
  key: "isPendingSyncOrder",
@@ -3720,8 +4346,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3720
4346
  value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3721
4347
  var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3722
4348
  var remote = remoteOrder;
3723
- for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
3724
- var field = _arr[_i7];
4349
+ for (var _i9 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i9 < _arr.length; _i9++) {
4350
+ var field = _arr[_i9];
3725
4351
  if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3726
4352
  merged[field] = remote[field];
3727
4353
  }
@@ -3731,15 +4357,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3731
4357
  }, {
3732
4358
  key: "mergeRemoteSnapshotWithPendingOrders",
3733
4359
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3734
- var _this23 = this;
4360
+ var _this27 = this;
3735
4361
  var merged = remoteOrders.map(function (order) {
3736
- return _this23.normalizeRemoteSyncedOrder(order);
4362
+ return _this27.normalizeRemoteSyncedOrder(order);
3737
4363
  });
3738
- var _iterator34 = _createForOfIteratorHelper(existingOrders),
3739
- _step34;
4364
+ var _iterator43 = _createForOfIteratorHelper(existingOrders),
4365
+ _step43;
3740
4366
  try {
3741
- for (_iterator34.s(); !(_step34 = _iterator34.n()).done;) {
3742
- var rawOrder = _step34.value;
4367
+ for (_iterator43.s(); !(_step43 = _iterator43.n()).done;) {
4368
+ var rawOrder = _step43.value;
3743
4369
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3744
4370
  if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
3745
4371
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
@@ -3755,9 +4381,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3755
4381
  merged.push(order);
3756
4382
  }
3757
4383
  } catch (err) {
3758
- _iterator34.e(err);
4384
+ _iterator43.e(err);
3759
4385
  } finally {
3760
- _iterator34.f();
4386
+ _iterator43.f();
3761
4387
  }
3762
4388
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
3763
4389
  }
@@ -3773,10 +4399,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3773
4399
  }, {
3774
4400
  key: "runInOrderSQLiteSaveQueue",
3775
4401
  value: (function () {
3776
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(task) {
4402
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(task) {
3777
4403
  var queuedTask;
3778
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3779
- while (1) switch (_context22.prev = _context22.next) {
4404
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4405
+ while (1) switch (_context27.prev = _context27.next) {
3780
4406
  case 0:
3781
4407
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3782
4408
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3784,14 +4410,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3784
4410
  }, function () {
3785
4411
  return undefined;
3786
4412
  });
3787
- return _context22.abrupt("return", queuedTask);
4413
+ return _context27.abrupt("return", queuedTask);
3788
4414
  case 3:
3789
4415
  case "end":
3790
- return _context22.stop();
4416
+ return _context27.stop();
3791
4417
  }
3792
- }, _callee22, this);
4418
+ }, _callee27, this);
3793
4419
  }));
3794
- function runInOrderSQLiteSaveQueue(_x15) {
4420
+ function runInOrderSQLiteSaveQueue(_x19) {
3795
4421
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3796
4422
  }
3797
4423
  return runInOrderSQLiteSaveQueue;
@@ -3806,8 +4432,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3806
4432
  }, {
3807
4433
  key: "patchOrdersInSQLite",
3808
4434
  value: (function () {
3809
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orders, source) {
3810
- var _this24 = this;
4435
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(orders, source) {
4436
+ var _this28 = this;
3811
4437
  var mergeActions,
3812
4438
  options,
3813
4439
  forceWriteStorageKeys,
@@ -3819,300 +4445,242 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3819
4445
  compactedToWrite,
3820
4446
  writtenStorageKeys,
3821
4447
  storageKeyMigrations,
3822
- _iterator35,
3823
- _step35,
4448
+ _iterator44,
4449
+ _step44,
3824
4450
  migration,
3825
- _args24 = arguments;
3826
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3827
- while (1) switch (_context24.prev = _context24.next) {
4451
+ _args29 = arguments;
4452
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4453
+ while (1) switch (_context29.prev = _context29.next) {
3828
4454
  case 0:
3829
- mergeActions = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3830
- options = _args24.length > 3 && _args24[3] !== undefined ? _args24[3] : {};
3831
- forceWriteStorageKeys = _args24.length > 4 && _args24[4] !== undefined ? _args24[4] : new Set();
4455
+ mergeActions = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4456
+ options = _args29.length > 3 && _args29[3] !== undefined ? _args29[3] : {};
4457
+ forceWriteStorageKeys = _args29.length > 4 && _args29[4] !== undefined ? _args29[4] : new Set();
3832
4458
  if (!(orders.length === 0)) {
3833
- _context24.next = 5;
4459
+ _context29.next = 5;
3834
4460
  break;
3835
4461
  }
3836
- return _context24.abrupt("return");
4462
+ return _context29.abrupt("return");
3837
4463
  case 5:
3838
4464
  if (this.dbManager) {
3839
- _context24.next = 9;
4465
+ _context29.next = 9;
3840
4466
  break;
3841
4467
  }
3842
4468
  if (!options.throwOnError) {
3843
- _context24.next = 8;
4469
+ _context29.next = 8;
3844
4470
  break;
3845
4471
  }
3846
4472
  throw new Error('订单 SQLite 数据库未初始化');
3847
4473
  case 8:
3848
- return _context24.abrupt("return");
4474
+ return _context29.abrupt("return");
3849
4475
  case 9:
3850
4476
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3851
4477
  return migration.to;
3852
4478
  }));
3853
4479
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3854
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4480
+ return _this28.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3855
4481
  }).map(function (order) {
3856
- var storageKey = _this24.getOrderStorageKey(order);
4482
+ var storageKey = _this28.getOrderStorageKey(order);
3857
4483
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
3858
4484
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
3859
4485
  }).filter(function (order) {
3860
- return _this24.getOrderStorageKey(order);
4486
+ return _this28.getOrderStorageKey(order);
3861
4487
  });
3862
4488
  if (!(ordersSnapshot.length === 0)) {
3863
- _context24.next = 13;
4489
+ _context29.next = 13;
3864
4490
  break;
3865
4491
  }
3866
- return _context24.abrupt("return");
4492
+ return _context29.abrupt("return");
3867
4493
  case 13:
3868
- _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
4494
+ _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, new Set([].concat(_toConsumableArray(forceWriteStorageKeys), _toConsumableArray(migrationTargetStorageKeys)))), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3869
4495
  if (!(toWrite.length === 0)) {
3870
- _context24.next = 16;
4496
+ _context29.next = 16;
3871
4497
  break;
3872
4498
  }
3873
- return _context24.abrupt("return");
4499
+ return _context29.abrupt("return");
3874
4500
  case 16:
3875
4501
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3876
4502
  if (!(compactedToWrite.length === 0)) {
3877
- _context24.next = 19;
4503
+ _context29.next = 19;
3878
4504
  break;
3879
4505
  }
3880
- return _context24.abrupt("return");
4506
+ return _context29.abrupt("return");
3881
4507
  case 19:
3882
4508
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3883
- return _this24.getOrderStorageKey(order);
4509
+ return _this28.getOrderStorageKey(order);
3884
4510
  }).filter(Boolean));
3885
4511
  storageKeyMigrations = new Map();
3886
- _iterator35 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3887
- _context24.prev = 22;
3888
- _iterator35.s();
4512
+ _iterator44 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4513
+ _context29.prev = 22;
4514
+ _iterator44.s();
3889
4515
  case 24:
3890
- if ((_step35 = _iterator35.n()).done) {
3891
- _context24.next = 33;
4516
+ if ((_step44 = _iterator44.n()).done) {
4517
+ _context29.next = 33;
3892
4518
  break;
3893
4519
  }
3894
- migration = _step35.value;
4520
+ migration = _step44.value;
3895
4521
  if (writtenStorageKeys.has(migration.to)) {
3896
- _context24.next = 28;
4522
+ _context29.next = 28;
3897
4523
  break;
3898
4524
  }
3899
- return _context24.abrupt("continue", 31);
4525
+ return _context29.abrupt("continue", 31);
3900
4526
  case 28:
3901
4527
  if (!writtenStorageKeys.has(migration.from)) {
3902
- _context24.next = 30;
4528
+ _context29.next = 30;
3903
4529
  break;
3904
4530
  }
3905
- return _context24.abrupt("continue", 31);
4531
+ return _context29.abrupt("continue", 31);
3906
4532
  case 30:
3907
4533
  storageKeyMigrations.set(migration.from, migration);
3908
4534
  case 31:
3909
- _context24.next = 24;
4535
+ _context29.next = 24;
3910
4536
  break;
3911
4537
  case 33:
3912
- _context24.next = 38;
4538
+ _context29.next = 38;
3913
4539
  break;
3914
4540
  case 35:
3915
- _context24.prev = 35;
3916
- _context24.t0 = _context24["catch"](22);
3917
- _iterator35.e(_context24.t0);
4541
+ _context29.prev = 35;
4542
+ _context29.t0 = _context29["catch"](22);
4543
+ _iterator44.e(_context29.t0);
3918
4544
  case 38:
3919
- _context24.prev = 38;
3920
- _iterator35.f();
3921
- return _context24.finish(38);
4545
+ _context29.prev = 38;
4546
+ _iterator44.f();
4547
+ return _context29.finish(38);
3922
4548
  case 41:
3923
- _context24.prev = 41;
3924
- _context24.next = 44;
3925
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3926
- var writeMethod, _iterator36, _step36, order, _iterator37, _step37, migration, _iterator38, _step38, _orderRecord$ORDER_ST, _order, orderRecord;
3927
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3928
- while (1) switch (_context23.prev = _context23.next) {
4549
+ _context29.prev = 41;
4550
+ _context29.next = 44;
4551
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4552
+ var writeMethod, _iterator45, _step45, migration, _iterator46, _step46, _orderRecord$ORDER_ST, order, orderRecord;
4553
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4554
+ while (1) switch (_context28.prev = _context28.next) {
3929
4555
  case 0:
3930
4556
  writeMethod = 'none';
3931
- _this24.logInfo('patchOrdersInSQLite-开始', {
4557
+ _this28.logInfo('patchOrdersInSQLite-开始', {
3932
4558
  source: source,
3933
4559
  count: compactedToWrite.length,
3934
4560
  dedupedCount: skipped.length
3935
4561
  });
3936
- if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
3937
- _context23.next = 8;
3938
- break;
3939
- }
3940
- writeMethod = 'bulkUpdate';
3941
- _context23.next = 6;
3942
- return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3943
- case 6:
3944
- _context23.next = 37;
3945
- break;
3946
- case 8:
3947
- if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
3948
- _context23.next = 14;
3949
- break;
3950
- }
3951
- writeMethod = 'bulkAdd';
3952
- _context23.next = 12;
3953
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3954
- case 12:
3955
- _context23.next = 37;
3956
- break;
3957
- case 14:
3958
- if (!(typeof _this24.dbManager.update === 'function')) {
3959
- _context23.next = 35;
3960
- break;
3961
- }
3962
- writeMethod = 'update';
3963
- _iterator36 = _createForOfIteratorHelper(compactedToWrite);
3964
- _context23.prev = 17;
3965
- _iterator36.s();
3966
- case 19:
3967
- if ((_step36 = _iterator36.n()).done) {
3968
- _context23.next = 25;
3969
- break;
3970
- }
3971
- order = _step36.value;
3972
- _context23.next = 23;
3973
- return _this24.dbManager.update(INDEXDB_STORE_NAME, order);
3974
- case 23:
3975
- _context23.next = 19;
3976
- break;
3977
- case 25:
3978
- _context23.next = 30;
3979
- break;
3980
- case 27:
3981
- _context23.prev = 27;
3982
- _context23.t0 = _context23["catch"](17);
3983
- _iterator36.e(_context23.t0);
3984
- case 30:
3985
- _context23.prev = 30;
3986
- _iterator36.f();
3987
- return _context23.finish(30);
3988
- case 33:
3989
- _context23.next = 37;
3990
- break;
3991
- case 35:
3992
- if (!options.throwOnError) {
3993
- _context23.next = 37;
3994
- break;
3995
- }
3996
- throw new Error('订单 SQLite 数据库不支持写入');
3997
- case 37:
3998
- _this24.recordRecentSqliteWrite(source, compactedToWrite);
4562
+ _context28.next = 4;
4563
+ return _this28.writeOrderRowsToSQLite(compactedToWrite);
4564
+ case 4:
4565
+ writeMethod = _context28.sent;
4566
+ _this28.recordRecentSqliteWrite(source, compactedToWrite);
3999
4567
  if (!(writeMethod !== 'none')) {
4000
- _context23.next = 84;
4568
+ _context28.next = 52;
4001
4569
  break;
4002
4570
  }
4003
- _iterator37 = _createForOfIteratorHelper(storageKeyMigrations.values());
4004
- _context23.prev = 40;
4005
- _iterator37.s();
4006
- case 42:
4007
- if ((_step37 = _iterator37.n()).done) {
4008
- _context23.next = 76;
4571
+ _iterator45 = _createForOfIteratorHelper(storageKeyMigrations.values());
4572
+ _context28.prev = 8;
4573
+ _iterator45.s();
4574
+ case 10:
4575
+ if ((_step45 = _iterator45.n()).done) {
4576
+ _context28.next = 44;
4009
4577
  break;
4010
4578
  }
4011
- migration = _step37.value;
4012
- _context23.prev = 44;
4013
- _context23.next = 47;
4014
- return _this24.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4015
- case 47:
4016
- _this24.recentSqliteWriteByStorageKey.delete(migration.from);
4017
- _iterator38 = _createForOfIteratorHelper(orders);
4018
- _context23.prev = 49;
4019
- _iterator38.s();
4020
- case 51:
4021
- if ((_step38 = _iterator38.n()).done) {
4022
- _context23.next = 61;
4579
+ migration = _step45.value;
4580
+ _context28.prev = 12;
4581
+ _context28.next = 15;
4582
+ return _this28.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4583
+ case 15:
4584
+ _this28.recentSqliteWriteByStorageKey.delete(migration.from);
4585
+ _iterator46 = _createForOfIteratorHelper(orders);
4586
+ _context28.prev = 17;
4587
+ _iterator46.s();
4588
+ case 19:
4589
+ if ((_step46 = _iterator46.n()).done) {
4590
+ _context28.next = 29;
4023
4591
  break;
4024
4592
  }
4025
- _order = _step38.value;
4026
- if (!(_this24.getOrderStorageKey(_order) !== migration.to)) {
4027
- _context23.next = 55;
4593
+ order = _step46.value;
4594
+ if (!(_this28.getOrderStorageKey(order) !== migration.to)) {
4595
+ _context28.next = 23;
4028
4596
  break;
4029
4597
  }
4030
- return _context23.abrupt("continue", 59);
4031
- case 55:
4032
- orderRecord = _order;
4598
+ return _context28.abrupt("continue", 27);
4599
+ case 23:
4600
+ orderRecord = order;
4033
4601
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
4034
- _context23.next = 58;
4602
+ _context28.next = 26;
4035
4603
  break;
4036
4604
  }
4037
- return _context23.abrupt("continue", 59);
4038
- case 58:
4605
+ return _context28.abrupt("continue", 27);
4606
+ case 26:
4039
4607
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
4040
- case 59:
4041
- _context23.next = 51;
4608
+ case 27:
4609
+ _context28.next = 19;
4042
4610
  break;
4043
- case 61:
4044
- _context23.next = 66;
4611
+ case 29:
4612
+ _context28.next = 34;
4045
4613
  break;
4046
- case 63:
4047
- _context23.prev = 63;
4048
- _context23.t1 = _context23["catch"](49);
4049
- _iterator38.e(_context23.t1);
4050
- case 66:
4051
- _context23.prev = 66;
4052
- _iterator38.f();
4053
- return _context23.finish(66);
4054
- case 69:
4055
- _context23.next = 74;
4614
+ case 31:
4615
+ _context28.prev = 31;
4616
+ _context28.t0 = _context28["catch"](17);
4617
+ _iterator46.e(_context28.t0);
4618
+ case 34:
4619
+ _context28.prev = 34;
4620
+ _iterator46.f();
4621
+ return _context28.finish(34);
4622
+ case 37:
4623
+ _context28.next = 42;
4056
4624
  break;
4057
- case 71:
4058
- _context23.prev = 71;
4059
- _context23.t2 = _context23["catch"](44);
4060
- _this24.logError('删除订单旧 SQLite storage key 失败', {
4625
+ case 39:
4626
+ _context28.prev = 39;
4627
+ _context28.t1 = _context28["catch"](12);
4628
+ _this28.logError('删除订单旧 SQLite storage key 失败', {
4061
4629
  source: source,
4062
4630
  order_id: migration.orderId,
4063
4631
  oldStorageKey: migration.from,
4064
4632
  newStorageKey: migration.to,
4065
- error: _context23.t2 instanceof Error ? _context23.t2.message : String(_context23.t2)
4633
+ error: _context28.t1 instanceof Error ? _context28.t1.message : String(_context28.t1)
4066
4634
  });
4067
- case 74:
4068
- _context23.next = 42;
4635
+ case 42:
4636
+ _context28.next = 10;
4069
4637
  break;
4070
- case 76:
4071
- _context23.next = 81;
4638
+ case 44:
4639
+ _context28.next = 49;
4072
4640
  break;
4073
- case 78:
4074
- _context23.prev = 78;
4075
- _context23.t3 = _context23["catch"](40);
4076
- _iterator37.e(_context23.t3);
4077
- case 81:
4078
- _context23.prev = 81;
4079
- _iterator37.f();
4080
- return _context23.finish(81);
4081
- case 84:
4082
- _this24.logInfo('patchOrdersInSQLite-完成', {
4641
+ case 46:
4642
+ _context28.prev = 46;
4643
+ _context28.t2 = _context28["catch"](8);
4644
+ _iterator45.e(_context28.t2);
4645
+ case 49:
4646
+ _context28.prev = 49;
4647
+ _iterator45.f();
4648
+ return _context28.finish(49);
4649
+ case 52:
4650
+ _this28.logInfo('patchOrdersInSQLite-完成', {
4083
4651
  source: source,
4084
4652
  count: compactedToWrite.length,
4085
4653
  writeMethod: writeMethod,
4086
4654
  dedupedCount: skipped.length
4087
4655
  });
4088
- case 85:
4656
+ case 53:
4089
4657
  case "end":
4090
- return _context23.stop();
4658
+ return _context28.stop();
4091
4659
  }
4092
- }, _callee23, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4660
+ }, _callee28, null, [[8, 46, 49, 52], [12, 39], [17, 31, 34, 37]]);
4093
4661
  })));
4094
4662
  case 44:
4095
- _context24.next = 51;
4663
+ _context29.next = 51;
4096
4664
  break;
4097
4665
  case 46:
4098
- _context24.prev = 46;
4099
- _context24.t1 = _context24["catch"](41);
4666
+ _context29.prev = 46;
4667
+ _context29.t1 = _context29["catch"](41);
4100
4668
  this.logError('增量保存订单到 SQLite 失败', {
4101
- error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4669
+ error: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1),
4102
4670
  orderCount: ordersSnapshot.length
4103
4671
  });
4104
4672
  if (!options.throwOnError) {
4105
- _context24.next = 51;
4673
+ _context29.next = 51;
4106
4674
  break;
4107
4675
  }
4108
- throw _context24.t1;
4676
+ throw _context29.t1;
4109
4677
  case 51:
4110
4678
  case "end":
4111
- return _context24.stop();
4679
+ return _context29.stop();
4112
4680
  }
4113
- }, _callee24, this, [[22, 35, 38, 41], [41, 46]]);
4681
+ }, _callee29, this, [[22, 35, 38, 41], [41, 46]]);
4114
4682
  }));
4115
- function patchOrdersInSQLite(_x16, _x17) {
4683
+ function patchOrdersInSQLite(_x20, _x21) {
4116
4684
  return _patchOrdersInSQLite.apply(this, arguments);
4117
4685
  }
4118
4686
  return patchOrdersInSQLite;
@@ -4127,128 +4695,128 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4127
4695
  }, {
4128
4696
  key: "updateOrderInSQLite",
4129
4697
  value: (function () {
4130
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order, source) {
4131
- var _this25 = this;
4698
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(order, source) {
4699
+ var _this29 = this;
4132
4700
  var options,
4133
4701
  orderSnapshot,
4134
4702
  _orderSnapshot$order_3,
4135
- _args26 = arguments;
4136
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4137
- while (1) switch (_context26.prev = _context26.next) {
4703
+ _args31 = arguments;
4704
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4705
+ while (1) switch (_context31.prev = _context31.next) {
4138
4706
  case 0:
4139
- options = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
4707
+ options = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : {};
4140
4708
  if (this.getOrderStorageKey(order)) {
4141
- _context26.next = 5;
4709
+ _context31.next = 5;
4142
4710
  break;
4143
4711
  }
4144
4712
  if (!options.throwOnError) {
4145
- _context26.next = 4;
4713
+ _context31.next = 4;
4146
4714
  break;
4147
4715
  }
4148
4716
  throw new Error('订单缺少可用的 SQLite 存储主键');
4149
4717
  case 4:
4150
- return _context26.abrupt("return");
4718
+ return _context31.abrupt("return");
4151
4719
  case 5:
4152
4720
  if (this.dbManager) {
4153
- _context26.next = 9;
4721
+ _context31.next = 9;
4154
4722
  break;
4155
4723
  }
4156
4724
  if (!options.throwOnError) {
4157
- _context26.next = 8;
4725
+ _context31.next = 8;
4158
4726
  break;
4159
4727
  }
4160
4728
  throw new Error('订单 SQLite 数据库未初始化');
4161
4729
  case 8:
4162
- return _context26.abrupt("return");
4730
+ return _context31.abrupt("return");
4163
4731
  case 9:
4164
4732
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4165
- _context26.prev = 10;
4166
- _context26.next = 13;
4167
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4733
+ _context31.prev = 10;
4734
+ _context31.next = 13;
4735
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4168
4736
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4169
4737
  var writeMethod;
4170
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4171
- while (1) switch (_context25.prev = _context25.next) {
4738
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4739
+ while (1) switch (_context30.prev = _context30.next) {
4172
4740
  case 0:
4173
4741
  writeMethod = 'none';
4174
- _this25.logInfo('updateOrderInSQLite-开始', {
4742
+ _this29.logInfo('updateOrderInSQLite-开始', {
4175
4743
  source: source,
4176
4744
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
4177
- storageKey: _this25.getOrderStorageKey(orderSnapshot)
4745
+ storageKey: _this29.getOrderStorageKey(orderSnapshot)
4178
4746
  });
4179
- if (!(typeof _this25.dbManager.update === 'function')) {
4180
- _context25.next = 8;
4747
+ if (!(typeof _this29.dbManager.update === 'function')) {
4748
+ _context30.next = 8;
4181
4749
  break;
4182
4750
  }
4183
4751
  writeMethod = 'update';
4184
- _context25.next = 6;
4185
- return _this25.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4752
+ _context30.next = 6;
4753
+ return _this29.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4186
4754
  case 6:
4187
- _context25.next = 22;
4755
+ _context30.next = 22;
4188
4756
  break;
4189
4757
  case 8:
4190
- if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4191
- _context25.next = 14;
4758
+ if (!(typeof _this29.dbManager.bulkUpdate === 'function')) {
4759
+ _context30.next = 14;
4192
4760
  break;
4193
4761
  }
4194
4762
  writeMethod = 'bulkUpdate';
4195
- _context25.next = 12;
4196
- return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4763
+ _context30.next = 12;
4764
+ return _this29.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4197
4765
  case 12:
4198
- _context25.next = 22;
4766
+ _context30.next = 22;
4199
4767
  break;
4200
4768
  case 14:
4201
- if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4202
- _context25.next = 20;
4769
+ if (!(typeof _this29.dbManager.bulkAdd === 'function')) {
4770
+ _context30.next = 20;
4203
4771
  break;
4204
4772
  }
4205
4773
  writeMethod = 'bulkAdd';
4206
- _context25.next = 18;
4207
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4774
+ _context30.next = 18;
4775
+ return _this29.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4208
4776
  case 18:
4209
- _context25.next = 22;
4777
+ _context30.next = 22;
4210
4778
  break;
4211
4779
  case 20:
4212
4780
  if (!options.throwOnError) {
4213
- _context25.next = 22;
4781
+ _context30.next = 22;
4214
4782
  break;
4215
4783
  }
4216
4784
  throw new Error('订单 SQLite 数据库不支持写入');
4217
4785
  case 22:
4218
- _this25.recordRecentSqliteWrite(source, [orderSnapshot]);
4219
- _this25.logInfo('updateOrderInSQLite-完成', {
4786
+ _this29.recordRecentSqliteWrite(source, [orderSnapshot]);
4787
+ _this29.logInfo('updateOrderInSQLite-完成', {
4220
4788
  source: source,
4221
4789
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
4222
4790
  writeMethod: writeMethod
4223
4791
  });
4224
4792
  case 24:
4225
4793
  case "end":
4226
- return _context25.stop();
4794
+ return _context30.stop();
4227
4795
  }
4228
- }, _callee25);
4796
+ }, _callee30);
4229
4797
  })));
4230
4798
  case 13:
4231
- _context26.next = 20;
4799
+ _context31.next = 20;
4232
4800
  break;
4233
4801
  case 15:
4234
- _context26.prev = 15;
4235
- _context26.t0 = _context26["catch"](10);
4802
+ _context31.prev = 15;
4803
+ _context31.t0 = _context31["catch"](10);
4236
4804
  this.logError('单条保存订单到 SQLite 失败', {
4237
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
4805
+ error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4238
4806
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4239
4807
  });
4240
4808
  if (!options.throwOnError) {
4241
- _context26.next = 20;
4809
+ _context31.next = 20;
4242
4810
  break;
4243
4811
  }
4244
- throw _context26.t0;
4812
+ throw _context31.t0;
4245
4813
  case 20:
4246
4814
  case "end":
4247
- return _context26.stop();
4815
+ return _context31.stop();
4248
4816
  }
4249
- }, _callee26, this, [[10, 15]]);
4817
+ }, _callee31, this, [[10, 15]]);
4250
4818
  }));
4251
- function updateOrderInSQLite(_x18, _x19) {
4819
+ function updateOrderInSQLite(_x22, _x23) {
4252
4820
  return _updateOrderInSQLite.apply(this, arguments);
4253
4821
  }
4254
4822
  return updateOrderInSQLite;
@@ -4264,76 +4832,76 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4264
4832
  }, {
4265
4833
  key: "replaceOrdersSnapshotInSQLite",
4266
4834
  value: (function () {
4267
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(orderList, source) {
4268
- var _this26 = this;
4835
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(orderList, source) {
4836
+ var _this30 = this;
4269
4837
  var protectedOrdersBeforeRemoteFetch,
4270
4838
  remoteSnapshot,
4271
4839
  mergedSnapshot,
4272
4840
  persisted,
4273
- _args28 = arguments;
4274
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4275
- while (1) switch (_context28.prev = _context28.next) {
4841
+ _args33 = arguments;
4842
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4843
+ while (1) switch (_context33.prev = _context33.next) {
4276
4844
  case 0:
4277
- protectedOrdersBeforeRemoteFetch = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : [];
4845
+ protectedOrdersBeforeRemoteFetch = _args33.length > 2 && _args33[2] !== undefined ? _args33[2] : [];
4278
4846
  if (this.dbManager) {
4279
- _context28.next = 3;
4847
+ _context33.next = 3;
4280
4848
  break;
4281
4849
  }
4282
- return _context28.abrupt("return", {
4850
+ return _context33.abrupt("return", {
4283
4851
  orders: this.compactOrderListByIdentity(this.preserveOmittedHolderRelations(orderList, this.store.list).map(function (order) {
4284
- return _this26.normalizeRemoteSyncedOrder(order);
4852
+ return _this30.normalizeRemoteSyncedOrder(order);
4285
4853
  }), "".concat(source, ".snapshotNoDb")).list,
4286
4854
  persisted: false
4287
4855
  });
4288
4856
  case 3:
4289
4857
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
4290
- return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4858
+ return _this30.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4291
4859
  });
4292
4860
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
4293
- return _this26.normalizeRemoteSyncedOrder(order);
4861
+ return _this30.normalizeRemoteSyncedOrder(order);
4294
4862
  }), "".concat(source, ".remoteSnapshot")).list;
4295
4863
  persisted = false;
4296
- _context28.prev = 6;
4297
- _context28.next = 9;
4298
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4299
- var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator39, _step39, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4300
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4301
- while (1) switch (_context27.prev = _context27.next) {
4864
+ _context33.prev = 6;
4865
+ _context33.next = 9;
4866
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4867
+ var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator47, _step47, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4868
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4869
+ while (1) switch (_context32.prev = _context32.next) {
4302
4870
  case 0:
4303
- if (!(typeof _this26.dbManager.getAll === 'function')) {
4304
- _context27.next = 6;
4871
+ if (!(typeof _this30.dbManager.getAll === 'function')) {
4872
+ _context32.next = 6;
4305
4873
  break;
4306
4874
  }
4307
- _context27.next = 3;
4308
- return _this26.dbManager.getAll(INDEXDB_STORE_NAME);
4875
+ _context32.next = 3;
4876
+ return _this30.dbManager.getAll(INDEXDB_STORE_NAME);
4309
4877
  case 3:
4310
- _context27.t0 = _context27.sent;
4311
- _context27.next = 7;
4878
+ _context32.t0 = _context32.sent;
4879
+ _context32.next = 7;
4312
4880
  break;
4313
4881
  case 6:
4314
- _context27.t0 = [];
4882
+ _context32.t0 = [];
4315
4883
  case 7:
4316
- existingOrders = _context27.t0;
4317
- remoteSnapshotWithHolderRelations = _this26.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4884
+ existingOrders = _context32.t0;
4885
+ remoteSnapshotWithHolderRelations = _this30.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4318
4886
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4319
- return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4887
+ return _this30.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4320
4888
  }).filter(function (order) {
4321
- return _this26.shouldProtectLocalOrderFromRemoteSnapshot(order);
4889
+ return _this30.shouldProtectLocalOrderFromRemoteSnapshot(order);
4322
4890
  });
4323
- _iterator39 = _createForOfIteratorHelper(existingOrders || []);
4324
- _context27.prev = 11;
4325
- _iterator39.s();
4891
+ _iterator47 = _createForOfIteratorHelper(existingOrders || []);
4892
+ _context32.prev = 11;
4893
+ _iterator47.s();
4326
4894
  case 13:
4327
- if ((_step39 = _iterator39.n()).done) {
4328
- _context27.next = 24;
4895
+ if ((_step47 = _iterator47.n()).done) {
4896
+ _context32.next = 24;
4329
4897
  break;
4330
4898
  }
4331
- rawCurrentOrder = _step39.value;
4332
- currentOrder = _this26.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4333
- protectedIndex = _this26.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4334
- currentNeedsProtection = _this26.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4899
+ rawCurrentOrder = _step47.value;
4900
+ currentOrder = _this30.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4901
+ protectedIndex = _this30.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4902
+ currentNeedsProtection = _this30.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4335
4903
  if (!(protectedIndex >= 0)) {
4336
- _context27.next = 21;
4904
+ _context32.next = 21;
4337
4905
  break;
4338
4906
  }
4339
4907
  if (currentNeedsProtection) {
@@ -4341,27 +4909,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4341
4909
  } else {
4342
4910
  protectedLocalOrders.splice(protectedIndex, 1);
4343
4911
  }
4344
- return _context27.abrupt("continue", 22);
4912
+ return _context32.abrupt("continue", 22);
4345
4913
  case 21:
4346
4914
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4347
4915
  case 22:
4348
- _context27.next = 13;
4916
+ _context32.next = 13;
4349
4917
  break;
4350
4918
  case 24:
4351
- _context27.next = 29;
4919
+ _context32.next = 29;
4352
4920
  break;
4353
4921
  case 26:
4354
- _context27.prev = 26;
4355
- _context27.t1 = _context27["catch"](11);
4356
- _iterator39.e(_context27.t1);
4922
+ _context32.prev = 26;
4923
+ _context32.t1 = _context32["catch"](11);
4924
+ _iterator47.e(_context32.t1);
4357
4925
  case 29:
4358
- _context27.prev = 29;
4359
- _iterator39.f();
4360
- return _context27.finish(29);
4926
+ _context32.prev = 29;
4927
+ _iterator47.f();
4928
+ return _context32.finish(29);
4361
4929
  case 32:
4362
- orderListSnapshot = _this26.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4363
- mergedSnapshot = _this26.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4364
- _this26.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4930
+ orderListSnapshot = _this30.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4931
+ mergedSnapshot = _this30.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4932
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4365
4933
  source: source,
4366
4934
  count: mergedSnapshot.length,
4367
4935
  remoteCount: remoteSnapshot.length,
@@ -4369,10 +4937,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4369
4937
  protectedLocalOrderCount: protectedLocalOrders.length,
4370
4938
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4371
4939
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4372
- return count + _this26.getIdentifiedPendingPayments(order).length;
4940
+ return count + _this30.getIdentifiedPendingPayments(order).length;
4373
4941
  }, 0),
4374
4942
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4375
- return _this26.getIdentifiedPendingPayments(order).map(function (payment) {
4943
+ return _this30.getIdentifiedPendingPayments(order).map(function (payment) {
4376
4944
  var _order$order_id5, _external_sale_number5;
4377
4945
  return {
4378
4946
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4382,55 +4950,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4382
4950
  });
4383
4951
  })
4384
4952
  });
4385
- _context27.next = 37;
4386
- return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4953
+ _context32.next = 37;
4954
+ return _this30.dbManager.clear(INDEXDB_STORE_NAME);
4387
4955
  case 37:
4388
- _this26.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4956
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4389
4957
  count: mergedSnapshot.length
4390
4958
  });
4391
4959
  if (!(mergedSnapshot.length === 0)) {
4392
- _context27.next = 40;
4960
+ _context32.next = 40;
4393
4961
  break;
4394
4962
  }
4395
- return _context27.abrupt("return");
4963
+ return _context32.abrupt("return");
4396
4964
  case 40:
4397
- _context27.next = 42;
4398
- return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4965
+ _context32.next = 42;
4966
+ return _this30.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4399
4967
  case 42:
4400
- _this26.recordRecentSqliteWrite(source, mergedSnapshot);
4401
- _this26.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4968
+ _this30.recordRecentSqliteWrite(source, mergedSnapshot);
4969
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4402
4970
  source: source,
4403
4971
  count: mergedSnapshot.length
4404
4972
  });
4405
4973
  case 44:
4406
4974
  case "end":
4407
- return _context27.stop();
4975
+ return _context32.stop();
4408
4976
  }
4409
- }, _callee27, null, [[11, 26, 29, 32]]);
4977
+ }, _callee32, null, [[11, 26, 29, 32]]);
4410
4978
  })));
4411
4979
  case 9:
4412
4980
  persisted = true;
4413
- _context28.next = 15;
4981
+ _context33.next = 15;
4414
4982
  break;
4415
4983
  case 12:
4416
- _context28.prev = 12;
4417
- _context28.t0 = _context28["catch"](6);
4984
+ _context33.prev = 12;
4985
+ _context33.t0 = _context33["catch"](6);
4418
4986
  this.logError('全量保存订单到 SQLite 失败', {
4419
- error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4987
+ error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0),
4420
4988
  orderList: remoteSnapshot.length
4421
4989
  });
4422
4990
  case 15:
4423
- return _context28.abrupt("return", {
4991
+ return _context33.abrupt("return", {
4424
4992
  orders: mergedSnapshot,
4425
4993
  persisted: persisted
4426
4994
  });
4427
4995
  case 16:
4428
4996
  case "end":
4429
- return _context28.stop();
4997
+ return _context33.stop();
4430
4998
  }
4431
- }, _callee28, this, [[6, 12]]);
4999
+ }, _callee33, this, [[6, 12]]);
4432
5000
  }));
4433
- function replaceOrdersSnapshotInSQLite(_x20, _x21) {
5001
+ function replaceOrdersSnapshotInSQLite(_x24, _x25) {
4434
5002
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
4435
5003
  }
4436
5004
  return replaceOrdersSnapshotInSQLite;
@@ -4445,38 +5013,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4445
5013
  }, {
4446
5014
  key: "clear",
4447
5015
  value: (function () {
4448
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4449
- var _this27 = this;
4450
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4451
- while (1) switch (_context30.prev = _context30.next) {
5016
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
5017
+ var _this31 = this;
5018
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
5019
+ while (1) switch (_context35.prev = _context35.next) {
4452
5020
  case 0:
4453
5021
  this.store.list = [];
4454
5022
  this.store.map = new Map();
4455
5023
  if (!this.dbManager) {
4456
- _context30.next = 5;
5024
+ _context35.next = 5;
4457
5025
  break;
4458
5026
  }
4459
- _context30.next = 5;
4460
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4461
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4462
- while (1) switch (_context29.prev = _context29.next) {
5027
+ _context35.next = 5;
5028
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
5029
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
5030
+ while (1) switch (_context34.prev = _context34.next) {
4463
5031
  case 0:
4464
- _context29.next = 2;
4465
- return _this27.dbManager.clear(INDEXDB_STORE_NAME);
5032
+ _context34.next = 2;
5033
+ return _this31.dbManager.clear(INDEXDB_STORE_NAME);
4466
5034
  case 2:
4467
5035
  case "end":
4468
- return _context29.stop();
5036
+ return _context34.stop();
4469
5037
  }
4470
- }, _callee29);
5038
+ }, _callee34);
4471
5039
  })));
4472
5040
  case 5:
4473
5041
  this.clearOrderSnapshotMarker();
4474
5042
  this.emitOrdersChanged([], 'clear');
4475
5043
  case 7:
4476
5044
  case "end":
4477
- return _context30.stop();
5045
+ return _context35.stop();
4478
5046
  }
4479
- }, _callee30, this);
5047
+ }, _callee35, this);
4480
5048
  }));
4481
5049
  function clear() {
4482
5050
  return _clear.apply(this, arguments);