@pisell/pisellos 2.2.314 → 2.2.315

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 (214) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  8. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  9. package/dist/modules/BookingContext/utils/productExtend.d.ts +7 -0
  10. package/dist/modules/BookingContext/utils/productExtend.js +62 -18
  11. package/dist/modules/BookingContext/utils/resources.js +1 -1
  12. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  13. package/dist/modules/BusinessAvailability/index.js +204 -0
  14. package/dist/modules/Cart/index.js +4 -3
  15. package/dist/modules/Cart/types.d.ts +2 -0
  16. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  17. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  18. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  19. package/dist/modules/FulfillmentTiming/index.js +407 -0
  20. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  21. package/dist/modules/FulfillmentTiming/types.js +1 -0
  22. package/dist/modules/OpenData/types.d.ts +14 -0
  23. package/dist/modules/Order/index.d.ts +14 -2
  24. package/dist/modules/Order/index.js +856 -486
  25. package/dist/modules/Order/localEftposState.d.ts +13 -0
  26. package/dist/modules/Order/localEftposState.js +39 -0
  27. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  28. package/dist/modules/Order/pickupTiming.js +53 -0
  29. package/dist/modules/Order/types.d.ts +30 -2
  30. package/dist/modules/Order/utils.js +25 -7
  31. package/dist/modules/Payment/index.js +9 -10
  32. package/dist/modules/Product/types.d.ts +11 -0
  33. package/dist/modules/ProductList/index.js +1 -1
  34. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  35. package/dist/modules/ResourcePlanner/planner.js +332 -23
  36. package/dist/modules/ResourcePlanner/types.d.ts +29 -0
  37. package/dist/modules/Schedule/index.d.ts +8 -0
  38. package/dist/modules/Schedule/index.js +141 -39
  39. package/dist/modules/index.d.ts +1 -0
  40. package/dist/modules/index.js +1 -0
  41. package/dist/plugins/request.d.ts +7 -0
  42. package/dist/server/index.d.ts +1 -0
  43. package/dist/server/index.js +1536 -1309
  44. package/dist/server/modules/form/index.d.ts +19 -0
  45. package/dist/server/modules/form/index.js +205 -0
  46. package/dist/server/modules/form/types.d.ts +13 -0
  47. package/dist/server/modules/form/types.js +3 -0
  48. package/dist/server/modules/index.d.ts +3 -0
  49. package/dist/server/modules/index.js +4 -0
  50. package/dist/server/modules/order/index.d.ts +15 -0
  51. package/dist/server/modules/order/index.js +920 -688
  52. package/dist/server/modules/order/types.d.ts +1 -0
  53. package/dist/server/test.json +1 -1
  54. package/dist/server/utils/small-ticket.d.ts +1 -85
  55. package/dist/server/utils/small-ticket.js +2 -2542
  56. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  57. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  58. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  59. package/dist/shared/receipt/customerInvoiceLanguages.js +60 -0
  60. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  61. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +184 -0
  62. package/dist/shared/receipt/small-ticket.d.ts +96 -0
  63. package/dist/shared/receipt/small-ticket.js +2751 -0
  64. package/dist/shared/receipt/templateVisibility.d.ts +23 -0
  65. package/dist/shared/receipt/templateVisibility.js +64 -0
  66. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  67. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  68. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  69. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  70. package/dist/solution/BaseSales/index.d.ts +39 -16
  71. package/dist/solution/BaseSales/index.js +1754 -1154
  72. package/dist/solution/BaseSales/pickupTiming.d.ts +47 -0
  73. package/dist/solution/BaseSales/pickupTiming.js +616 -0
  74. package/dist/solution/BaseSales/types.d.ts +11 -0
  75. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  76. package/dist/solution/BookingByStep/index.d.ts +3 -1
  77. package/dist/solution/BookingByStep/index.js +8 -3
  78. package/dist/solution/BookingTicket/index.d.ts +8 -2
  79. package/dist/solution/BookingTicket/index.js +513 -436
  80. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  81. package/dist/solution/BookingTicket/utils/addProductDecision.js +1 -1
  82. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  83. package/dist/solution/OrderInvoicePreview/index.d.ts +66 -0
  84. package/dist/solution/OrderInvoicePreview/index.js +340 -0
  85. package/dist/solution/RegisterAndLogin/config.js +54 -11
  86. package/dist/solution/RegisterAndLogin/index.d.ts +2 -0
  87. package/dist/solution/RegisterAndLogin/index.js +1 -1
  88. package/dist/solution/RegisterAndLogin/utils.d.ts +12 -4
  89. package/dist/solution/RegisterAndLogin/utils.js +36 -16
  90. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  91. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  92. package/dist/solution/UnifiedBookingSales/index.d.ts +36 -4
  93. package/dist/solution/UnifiedBookingSales/index.js +1714 -905
  94. package/dist/solution/UnifiedBookingSales/types.d.ts +16 -2
  95. package/dist/solution/VenueBooking/index.d.ts +15 -2
  96. package/dist/solution/VenueBooking/index.js +1062 -785
  97. package/dist/solution/VenueBooking/types.d.ts +2 -1
  98. package/dist/solution/VenueBooking/types.js +1 -0
  99. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  100. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  101. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  102. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  103. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  104. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  105. package/dist/solution/index.d.ts +1 -0
  106. package/dist/solution/index.js +2 -1
  107. package/lib/index.d.ts +2 -0
  108. package/lib/index.js +21 -1
  109. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  110. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  111. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  112. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  113. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  114. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  115. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  116. package/lib/modules/BookingContext/utils/productExtend.d.ts +7 -0
  117. package/lib/modules/BookingContext/utils/productExtend.js +45 -2
  118. package/lib/modules/BookingContext/utils/resources.js +1 -1
  119. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  120. package/lib/modules/BusinessAvailability/index.js +146 -0
  121. package/lib/modules/Cart/index.js +4 -2
  122. package/lib/modules/Cart/types.d.ts +2 -0
  123. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  124. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  125. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  126. package/lib/modules/FulfillmentTiming/index.js +359 -0
  127. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  128. package/lib/modules/FulfillmentTiming/types.js +5 -0
  129. package/lib/modules/OpenData/types.d.ts +14 -0
  130. package/lib/modules/Order/index.d.ts +14 -2
  131. package/lib/modules/Order/index.js +240 -38
  132. package/lib/modules/Order/localEftposState.d.ts +13 -0
  133. package/lib/modules/Order/localEftposState.js +44 -0
  134. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  135. package/lib/modules/Order/pickupTiming.js +61 -0
  136. package/lib/modules/Order/types.d.ts +30 -2
  137. package/lib/modules/Order/utils.js +21 -5
  138. package/lib/modules/Payment/index.js +3 -4
  139. package/lib/modules/Product/types.d.ts +11 -0
  140. package/lib/modules/ProductList/index.js +1 -1
  141. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  142. package/lib/modules/ResourcePlanner/planner.js +252 -8
  143. package/lib/modules/ResourcePlanner/types.d.ts +29 -0
  144. package/lib/modules/Schedule/index.d.ts +8 -0
  145. package/lib/modules/Schedule/index.js +68 -12
  146. package/lib/modules/index.d.ts +1 -0
  147. package/lib/modules/index.js +11 -0
  148. package/lib/plugins/request.d.ts +7 -0
  149. package/lib/server/index.d.ts +1 -0
  150. package/lib/server/index.js +158 -37
  151. package/lib/server/modules/form/index.d.ts +19 -0
  152. package/lib/server/modules/form/index.js +73 -0
  153. package/lib/server/modules/form/types.d.ts +13 -0
  154. package/lib/server/modules/form/types.js +9 -0
  155. package/lib/server/modules/index.d.ts +3 -0
  156. package/lib/server/modules/index.js +15 -1
  157. package/lib/server/modules/order/index.d.ts +15 -0
  158. package/lib/server/modules/order/index.js +114 -3
  159. package/lib/server/modules/order/types.d.ts +1 -0
  160. package/lib/server/test.json +1 -1
  161. package/lib/server/utils/small-ticket.d.ts +1 -85
  162. package/lib/server/utils/small-ticket.js +9 -2305
  163. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  164. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  165. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  166. package/lib/shared/receipt/customerInvoiceLanguages.js +58 -0
  167. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  168. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +124 -0
  169. package/lib/shared/receipt/small-ticket.d.ts +96 -0
  170. package/lib/shared/receipt/small-ticket.js +2546 -0
  171. package/lib/shared/receipt/templateVisibility.d.ts +23 -0
  172. package/lib/shared/receipt/templateVisibility.js +63 -0
  173. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  174. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  175. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  176. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  177. package/lib/solution/BaseSales/index.d.ts +39 -16
  178. package/lib/solution/BaseSales/index.js +333 -31
  179. package/lib/solution/BaseSales/pickupTiming.d.ts +47 -0
  180. package/lib/solution/BaseSales/pickupTiming.js +290 -0
  181. package/lib/solution/BaseSales/types.d.ts +11 -0
  182. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  183. package/lib/solution/BookingByStep/index.d.ts +3 -1
  184. package/lib/solution/BookingByStep/index.js +7 -3
  185. package/lib/solution/BookingTicket/index.d.ts +8 -2
  186. package/lib/solution/BookingTicket/index.js +65 -6
  187. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  188. package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -1
  189. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  190. package/lib/solution/OrderInvoicePreview/index.d.ts +66 -0
  191. package/lib/solution/OrderInvoicePreview/index.js +246 -0
  192. package/lib/solution/RegisterAndLogin/config.js +57 -11
  193. package/lib/solution/RegisterAndLogin/index.d.ts +2 -0
  194. package/lib/solution/RegisterAndLogin/index.js +9 -1
  195. package/lib/solution/RegisterAndLogin/utils.d.ts +12 -4
  196. package/lib/solution/RegisterAndLogin/utils.js +24 -17
  197. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  198. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  199. package/lib/solution/UnifiedBookingSales/index.d.ts +36 -4
  200. package/lib/solution/UnifiedBookingSales/index.js +561 -74
  201. package/lib/solution/UnifiedBookingSales/types.d.ts +16 -2
  202. package/lib/solution/VenueBooking/index.d.ts +15 -2
  203. package/lib/solution/VenueBooking/index.js +243 -96
  204. package/lib/solution/VenueBooking/types.d.ts +2 -1
  205. package/lib/solution/VenueBooking/types.js +1 -0
  206. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  207. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  208. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  209. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  210. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  211. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  212. package/lib/solution/index.d.ts +1 -0
  213. package/lib/solution/index.js +11 -0
  214. package/package.json +1 -1
@@ -31,6 +31,7 @@ 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 } 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";
36
37
  import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
@@ -387,9 +388,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
387
388
  var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
388
389
  var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
389
390
  var existingItems = Array.isArray(existing) ? existing : [];
390
- if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
391
+ if (field === 'payments' && (options.preserveIdentifiedPendingPayments || existingItems.some(isLocalFinalizedPayment))) {
391
392
  return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
392
- preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
393
+ preserveUnmatchedExistingWhen: function preserveUnmatchedExistingWhen(payment) {
394
+ return options.preserveIdentifiedPendingPayments === true && isIdentifiedPendingOrderPayment(payment) || isLocalFinalizedPayment(payment);
395
+ }
393
396
  });
394
397
  }
395
398
  return incoming.map(function (incomingItem) {
@@ -888,11 +891,91 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
888
891
  });
889
892
  return memoryOrder || null;
890
893
  }
894
+
895
+ /** Read-only payment gate lookup; never hydrate the whole order list on a miss. */
896
+ }, {
897
+ key: "getLocalOrderForPaymentReadiness",
898
+ value: (function () {
899
+ var _getLocalOrderForPaymentReadiness = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
900
+ var _this$dbManager,
901
+ _this4 = this;
902
+ var memoryOrder, key, fields, candidates, _i2, _fields, column, rows;
903
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
904
+ while (1) switch (_context5.prev = _context5.next) {
905
+ case 0:
906
+ if (!(lookup === undefined || lookup === null || lookup === '')) {
907
+ _context5.next = 2;
908
+ break;
909
+ }
910
+ return _context5.abrupt("return", null);
911
+ case 2:
912
+ memoryOrder = this.getLocalOrderFromMemoryByLookup(lookup);
913
+ if (!memoryOrder) {
914
+ _context5.next = 5;
915
+ break;
916
+ }
917
+ return _context5.abrupt("return", memoryOrder);
918
+ case 5:
919
+ if (!(typeof ((_this$dbManager = this.dbManager) === null || _this$dbManager === void 0 ? void 0 : _this$dbManager.find) !== 'function')) {
920
+ _context5.next = 7;
921
+ break;
922
+ }
923
+ return _context5.abrupt("return", this.getLocalOrderByLookup(lookup));
924
+ case 7:
925
+ key = this.getIdKey(lookup);
926
+ fields = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
927
+ candidates = [];
928
+ _i2 = 0, _fields = fields;
929
+ case 11:
930
+ if (!(_i2 < _fields.length)) {
931
+ _context5.next = 20;
932
+ break;
933
+ }
934
+ column = _fields[_i2];
935
+ _context5.next = 15;
936
+ return this.dbManager.find(INDEXDB_STORE_NAME, {
937
+ filters: [{
938
+ column: column,
939
+ op: '=',
940
+ value: key
941
+ }],
942
+ orderBy: [{
943
+ column: '__order_storage_key',
944
+ dir: 'asc'
945
+ }],
946
+ limit: 1
947
+ });
948
+ case 15:
949
+ rows = _context5.sent;
950
+ if (rows !== null && rows !== void 0 && rows[0] && this.isOrderLookupMatch(rows[0], key)) candidates.push(rows[0]);
951
+ case 17:
952
+ _i2++;
953
+ _context5.next = 11;
954
+ break;
955
+ case 20:
956
+ candidates.sort(function (left, right) {
957
+ var _order_storage_key, _order_storage_key2;
958
+ var leftKey = String((_order_storage_key = left.__order_storage_key) !== null && _order_storage_key !== void 0 ? _order_storage_key : _this4.getOrderStorageKey(left));
959
+ var rightKey = String((_order_storage_key2 = right.__order_storage_key) !== null && _order_storage_key2 !== void 0 ? _order_storage_key2 : _this4.getOrderStorageKey(right));
960
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
961
+ });
962
+ return _context5.abrupt("return", candidates.length ? this.normalizeOrderForMemoryList(candidates[0], 'paymentReadiness.sqlite') : null);
963
+ case 22:
964
+ case "end":
965
+ return _context5.stop();
966
+ }
967
+ }, _callee5, this);
968
+ }));
969
+ function getLocalOrderForPaymentReadiness(_x4) {
970
+ return _getLocalOrderForPaymentReadiness.apply(this, arguments);
971
+ }
972
+ return getLocalOrderForPaymentReadiness;
973
+ }())
891
974
  }, {
892
975
  key: "getLocalOrderByLookup",
893
976
  value: function () {
894
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
895
- var _this4 = this;
977
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lookup) {
978
+ var _this5 = this;
896
979
  var options,
897
980
  key,
898
981
  logContext,
@@ -901,11 +984,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
901
984
  orders,
902
985
  localOrder,
903
986
  normalizedOrder,
904
- _args5 = arguments;
905
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
906
- while (1) switch (_context5.prev = _context5.next) {
987
+ _args6 = arguments;
988
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
989
+ while (1) switch (_context6.prev = _context6.next) {
907
990
  case 0:
908
- options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
991
+ options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
909
992
  key = this.getIdKey(lookup);
910
993
  logContext = {
911
994
  operation_id: options.operationId,
@@ -917,38 +1000,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
917
1000
  }
918
1001
  memoryOrderById = this.store.map.get(key);
919
1002
  if (!memoryOrderById) {
920
- _context5.next = 8;
1003
+ _context6.next = 8;
921
1004
  break;
922
1005
  }
923
1006
  if (options.operationId) {
924
1007
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
925
1008
  }
926
- return _context5.abrupt("return", memoryOrderById);
1009
+ return _context6.abrupt("return", memoryOrderById);
927
1010
  case 8:
928
1011
  memoryOrder = this.store.list.find(function (order) {
929
- return _this4.isOrderLookupMatch(order, key);
1012
+ return _this5.isOrderLookupMatch(order, key);
930
1013
  });
931
1014
  if (!memoryOrder) {
932
- _context5.next = 12;
1015
+ _context6.next = 12;
933
1016
  break;
934
1017
  }
935
1018
  if (options.operationId) {
936
1019
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
937
1020
  }
938
- return _context5.abrupt("return", memoryOrder);
1021
+ return _context6.abrupt("return", memoryOrder);
939
1022
  case 12:
940
1023
  if (options.operationId) {
941
1024
  this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
942
1025
  }
943
- _context5.next = 15;
1026
+ _context6.next = 15;
944
1027
  return this.loadOrdersFromSQLite();
945
1028
  case 15:
946
- orders = _context5.sent;
1029
+ orders = _context6.sent;
947
1030
  localOrder = orders.find(function (order) {
948
- return _this4.isOrderLookupMatch(order, key);
1031
+ return _this5.isOrderLookupMatch(order, key);
949
1032
  });
950
1033
  if (localOrder) {
951
- _context5.next = 20;
1034
+ _context6.next = 20;
952
1035
  break;
953
1036
  }
954
1037
  if (options.operationId) {
@@ -956,7 +1039,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
956
1039
  sqlite_order_count: orders.length
957
1040
  }));
958
1041
  }
959
- return _context5.abrupt("return", null);
1042
+ return _context6.abrupt("return", null);
960
1043
  case 20:
961
1044
  this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
962
1045
  this.syncOrdersMap();
@@ -966,14 +1049,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
966
1049
  sqlite_order_count: orders.length
967
1050
  }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
968
1051
  }
969
- return _context5.abrupt("return", normalizedOrder);
1052
+ return _context6.abrupt("return", normalizedOrder);
970
1053
  case 25:
971
1054
  case "end":
972
- return _context5.stop();
1055
+ return _context6.stop();
973
1056
  }
974
- }, _callee5, this);
1057
+ }, _callee6, this);
975
1058
  }));
976
- function getLocalOrderByLookup(_x4) {
1059
+ function getLocalOrderByLookup(_x5) {
977
1060
  return _getLocalOrderByLookup.apply(this, arguments);
978
1061
  }
979
1062
  return getLocalOrderByLookup;
@@ -981,10 +1064,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
981
1064
  }, {
982
1065
  key: "getLocalPayment",
983
1066
  value: function () {
984
- var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1067
+ var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
985
1068
  var logContext, order, payments, match;
986
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
987
- while (1) switch (_context6.prev = _context6.next) {
1069
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1070
+ while (1) switch (_context7.prev = _context7.next) {
988
1071
  case 0:
989
1072
  logContext = {
990
1073
  operation_id: params.operationId,
@@ -992,56 +1075,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
992
1075
  payment_number: params.paymentNumber
993
1076
  };
994
1077
  this.logInfo('getLocalPayment-开始', logContext);
995
- _context6.prev = 2;
996
- _context6.next = 5;
1078
+ _context7.prev = 2;
1079
+ _context7.next = 5;
997
1080
  return this.getLocalOrderByLookup(params.saleId, {
998
1081
  operationId: params.operationId
999
1082
  });
1000
1083
  case 5:
1001
- order = _context6.sent;
1084
+ order = _context7.sent;
1002
1085
  if (order) {
1003
- _context6.next = 9;
1086
+ _context7.next = 9;
1004
1087
  break;
1005
1088
  }
1006
1089
  this.logWarning('getLocalPayment-订单未命中', logContext);
1007
- return _context6.abrupt("return", null);
1090
+ return _context7.abrupt("return", null);
1008
1091
  case 9:
1009
1092
  payments = order.payments || [];
1010
1093
  match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
1011
1094
  if (match) {
1012
- _context6.next = 14;
1095
+ _context7.next = 14;
1013
1096
  break;
1014
1097
  }
1015
1098
  this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1016
1099
  payments: payments
1017
1100
  }));
1018
- return _context6.abrupt("return", null);
1101
+ return _context7.abrupt("return", null);
1019
1102
  case 14:
1020
1103
  this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1021
1104
  matched_by: match.matchedBy,
1022
1105
  payment_index: match.index,
1023
1106
  payment: match.payment
1024
1107
  }));
1025
- return _context6.abrupt("return", {
1108
+ return _context7.abrupt("return", {
1026
1109
  order: order,
1027
1110
  payment: match.payment,
1028
1111
  paymentIndex: match.index,
1029
1112
  matchedBy: match.matchedBy
1030
1113
  });
1031
1114
  case 18:
1032
- _context6.prev = 18;
1033
- _context6.t0 = _context6["catch"](2);
1115
+ _context7.prev = 18;
1116
+ _context7.t0 = _context7["catch"](2);
1034
1117
  this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
1035
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1118
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1036
1119
  }));
1037
- throw _context6.t0;
1120
+ throw _context7.t0;
1038
1121
  case 22:
1039
1122
  case "end":
1040
- return _context6.stop();
1123
+ return _context7.stop();
1041
1124
  }
1042
- }, _callee6, this, [[2, 18]]);
1125
+ }, _callee7, this, [[2, 18]]);
1043
1126
  }));
1044
- function getLocalPayment(_x5) {
1127
+ function getLocalPayment(_x6) {
1045
1128
  return _getLocalPayment.apply(this, arguments);
1046
1129
  }
1047
1130
  return getLocalPayment;
@@ -1049,10 +1132,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1049
1132
  }, {
1050
1133
  key: "updateLocalPayment",
1051
1134
  value: function () {
1052
- var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
1135
+ var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1136
+ var _found$payment$metada;
1053
1137
  var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
1054
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1055
- while (1) switch (_context7.prev = _context7.next) {
1138
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1139
+ while (1) switch (_context8.prev = _context8.next) {
1056
1140
  case 0:
1057
1141
  logContext = {
1058
1142
  operation_id: params.operationId,
@@ -1061,18 +1145,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1061
1145
  incoming_payment_update: params.updates
1062
1146
  };
1063
1147
  this.logInfo('updateLocalPayment-开始', logContext);
1064
- _context7.next = 4;
1148
+ _context8.next = 4;
1065
1149
  return this.getLocalPayment(params);
1066
1150
  case 4:
1067
- found = _context7.sent;
1151
+ found = _context8.sent;
1068
1152
  if (found) {
1069
- _context7.next = 8;
1153
+ _context8.next = 8;
1070
1154
  break;
1071
1155
  }
1072
1156
  this.logWarning('updateLocalPayment-支付项未命中', logContext);
1073
- return _context7.abrupt("return", null);
1157
+ return _context8.abrupt("return", null);
1074
1158
  case 8:
1075
1159
  previousPayment = cloneDeep(found.payment);
1160
+ 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) {
1161
+ return transaction.status === 'success';
1162
+ }) || isLocalFinalizedPayment(found.payment)))) {
1163
+ _context8.next = 11;
1164
+ break;
1165
+ }
1166
+ return _context8.abrupt("return", {
1167
+ order: found.order,
1168
+ payment: found.payment,
1169
+ previousPayment: previousPayment
1170
+ });
1171
+ case 11:
1076
1172
  nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
1077
1173
  updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
1078
1174
  }));
@@ -1082,6 +1178,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1082
1178
  }),
1083
1179
  updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
1084
1180
  });
1181
+ if (params.finalizeUnsuccessful && this.hasRealOrderId(found.order) && Number(found.order.need_sync || 0) === 0 && !(nextOrder.payments || []).some(isPendingOrderPayment)) {
1182
+ nextOrder.is_draft_order = 0;
1183
+ nextOrder.metadata = _objectSpread(_objectSpread({}, nextOrder.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
1184
+ }
1085
1185
  paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
1086
1186
  matched_by: found.matchedBy,
1087
1187
  payment_index: found.paymentIndex
@@ -1093,12 +1193,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1093
1193
  targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
1094
1194
  shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
1095
1195
  if (!(targetIndex < 0 && shouldKeepInMemory)) {
1096
- _context7.next = 18;
1196
+ _context8.next = 21;
1097
1197
  break;
1098
1198
  }
1099
1199
  this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
1100
- return _context7.abrupt("return", null);
1101
- case 18:
1200
+ return _context8.abrupt("return", null);
1201
+ case 21:
1102
1202
  previousList = this.store.list;
1103
1203
  this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
1104
1204
  return index === targetIndex ? nextOrder : order;
@@ -1107,60 +1207,189 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1107
1207
  });
1108
1208
  this.syncOrdersMap();
1109
1209
  storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
1110
- _context7.prev = 22;
1210
+ _context8.prev = 25;
1111
1211
  this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
1112
1212
  storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
1113
1213
  }));
1114
- _context7.next = 26;
1214
+ _context8.next = 29;
1115
1215
  return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
1116
1216
  throwOnError: true
1117
1217
  });
1118
- case 26:
1218
+ case 29:
1119
1219
  this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
1120
1220
  storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
1121
1221
  }));
1122
- _context7.next = 35;
1222
+ _context8.next = 38;
1123
1223
  break;
1124
- case 29:
1125
- _context7.prev = 29;
1126
- _context7.t0 = _context7["catch"](22);
1224
+ case 32:
1225
+ _context8.prev = 32;
1226
+ _context8.t0 = _context8["catch"](25);
1127
1227
  this.store.list = previousList;
1128
1228
  this.syncOrdersMap();
1129
1229
  this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
1130
1230
  storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
1131
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1231
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
1132
1232
  }));
1133
- throw _context7.t0;
1134
- case 35:
1233
+ throw _context8.t0;
1234
+ case 38:
1135
1235
  if (!(shouldKeepInMemory || targetIndex >= 0)) {
1136
- _context7.next = 38;
1236
+ _context8.next = 41;
1137
1237
  break;
1138
1238
  }
1139
- _context7.next = 38;
1239
+ _context8.next = 41;
1140
1240
  return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
1141
- case 38:
1241
+ case 41:
1142
1242
  this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
1143
- return _context7.abrupt("return", {
1243
+ return _context8.abrupt("return", {
1144
1244
  order: nextOrder,
1145
1245
  payment: nextPayment,
1146
1246
  previousPayment: previousPayment
1147
1247
  });
1148
- case 40:
1248
+ case 43:
1149
1249
  case "end":
1150
- return _context7.stop();
1250
+ return _context8.stop();
1151
1251
  }
1152
- }, _callee7, this, [[22, 29]]);
1252
+ }, _callee8, this, [[25, 32]]);
1153
1253
  }));
1154
- function updateLocalPayment(_x6) {
1254
+ function updateLocalPayment(_x7) {
1155
1255
  return _updateLocalPayment.apply(this, arguments);
1156
1256
  }
1157
1257
  return updateLocalPayment;
1158
1258
  }()
1259
+ }, {
1260
+ key: "finalizeLocalEftposPayment",
1261
+ value: function () {
1262
+ var _finalizeLocalEftposPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1263
+ var _found$payment$metada2;
1264
+ var found, transactions;
1265
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1266
+ while (1) switch (_context9.prev = _context9.next) {
1267
+ case 0:
1268
+ _context9.next = 2;
1269
+ return this.getLocalPayment(params);
1270
+ case 2:
1271
+ found = _context9.sent;
1272
+ if (found) {
1273
+ _context9.next = 5;
1274
+ break;
1275
+ }
1276
+ throw new Error('未找到本地支付记录');
1277
+ case 5:
1278
+ transactions = ((_found$payment$metada2 = found.payment.metadata) === null || _found$payment$metada2 === void 0 ? void 0 : _found$payment$metada2.transactions) || [];
1279
+ if (!transactions.some(function (transaction) {
1280
+ return transaction.status !== 'fail' && transaction.status !== 'success' && !params.failedTransactionNumbers.includes(String(transaction.number));
1281
+ })) {
1282
+ _context9.next = 8;
1283
+ break;
1284
+ }
1285
+ throw new Error('仍有结果未知的交易,保留待确认支付');
1286
+ case 8:
1287
+ if (!(params.result === 'not_started' && transactions.length > 0 && !isLocalFinalizedPayment(found.payment) && found.payment.status !== 'paid')) {
1288
+ _context9.next = 10;
1289
+ break;
1290
+ }
1291
+ throw new Error('支付已有交易记录,不能按未发起交易结束');
1292
+ case 10:
1293
+ return _context9.abrupt("return", this.updateLocalPayment(_objectSpread(_objectSpread({}, params), {}, {
1294
+ finalizeUnsuccessful: true,
1295
+ updates: {
1296
+ status: 'voided',
1297
+ metadata: _defineProperty(_defineProperty({}, LOCAL_EFTPOS_FINALIZED, true), "transactions", params.failedTransactionNumbers.map(function (number) {
1298
+ return {
1299
+ number: number,
1300
+ status: 'fail'
1301
+ };
1302
+ }))
1303
+ }
1304
+ })));
1305
+ case 11:
1306
+ case "end":
1307
+ return _context9.stop();
1308
+ }
1309
+ }, _callee9, this);
1310
+ }));
1311
+ function finalizeLocalEftposPayment(_x8) {
1312
+ return _finalizeLocalEftposPayment.apply(this, arguments);
1313
+ }
1314
+ return finalizeLocalEftposPayment;
1315
+ }() /** Only a successful full detail GET may release the persisted payment gate. */
1316
+ }, {
1317
+ key: "completeLocalPaymentRefresh",
1318
+ value: (function () {
1319
+ var _completeLocalPaymentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1320
+ var existing, nextOrder, index;
1321
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1322
+ while (1) switch (_context10.prev = _context10.next) {
1323
+ case 0:
1324
+ _context10.next = 2;
1325
+ return this.getLocalOrderByLookup(fresh.order_id);
1326
+ case 2:
1327
+ existing = _context10.sent;
1328
+ if (!(!existing || !requiresLocalPaymentRefresh(existing))) {
1329
+ _context10.next = 12;
1330
+ break;
1331
+ }
1332
+ _context10.next = 6;
1333
+ return this.upsertOrdersFromRemote([fresh]);
1334
+ case 6:
1335
+ _context10.next = 8;
1336
+ return this.getLocalOrderByLookup(fresh.order_id);
1337
+ case 8:
1338
+ _context10.t0 = _context10.sent;
1339
+ if (_context10.t0) {
1340
+ _context10.next = 11;
1341
+ break;
1342
+ }
1343
+ _context10.t0 = fresh;
1344
+ case 11:
1345
+ return _context10.abrupt("return", _context10.t0);
1346
+ case 12:
1347
+ if (!(this.isPendingSyncOrder(existing) || this.isDraftOrder(existing) || (existing.payments || []).some(isPendingOrderPayment))) {
1348
+ _context10.next = 14;
1349
+ break;
1350
+ }
1351
+ throw new Error('订单仍有未结束支付或待同步改动,暂不能刷新');
1352
+ case 14:
1353
+ if (!(!Array.isArray(fresh.products) || !fresh.summary)) {
1354
+ _context10.next = 16;
1355
+ break;
1356
+ }
1357
+ throw new Error('远端订单详情不完整,请重新刷新');
1358
+ case 16:
1359
+ nextOrder = this.mergeOrderRecords(existing, this.normalizeRemoteSyncedOrder(fresh));
1360
+ nextOrder.metadata = _objectSpread({}, nextOrder.metadata);
1361
+ delete nextOrder.metadata[LOCAL_EFTPOS_REFRESH_REQUIRED];
1362
+ // Do not publish/clear the gate in memory until SQLite has accepted the full snapshot.
1363
+ _context10.next = 21;
1364
+ return this.updateOrderInSQLite(nextOrder, 'completeLocalPaymentRefresh', {
1365
+ throwOnError: true
1366
+ });
1367
+ case 21:
1368
+ index = this.findOrderIndexByIdentity(this.store.list, existing);
1369
+ this.store.list = index < 0 ? [].concat(_toConsumableArray(this.store.list), [nextOrder]) : this.store.list.map(function (order, i) {
1370
+ return i === index ? nextOrder : order;
1371
+ });
1372
+ this.syncOrdersMap();
1373
+ _context10.next = 26;
1374
+ return this.emitOrdersChanged([nextOrder], 'completeLocalPaymentRefresh');
1375
+ case 26:
1376
+ return _context10.abrupt("return", nextOrder);
1377
+ case 27:
1378
+ case "end":
1379
+ return _context10.stop();
1380
+ }
1381
+ }, _callee10, this);
1382
+ }));
1383
+ function completeLocalPaymentRefresh(_x9) {
1384
+ return _completeLocalPaymentRefresh.apply(this, arguments);
1385
+ }
1386
+ return completeLocalPaymentRefresh;
1387
+ }())
1159
1388
  }, {
1160
1389
  key: "loadOrdersByServer",
1161
1390
  value: function () {
1162
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1163
- var _this5 = this,
1391
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1392
+ var _this6 = this,
1164
1393
  _this$store;
1165
1394
  var options,
1166
1395
  orderList,
@@ -1172,19 +1401,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1172
1401
  mergedOrders,
1173
1402
  isRemoteSnapshotPersisted,
1174
1403
  memoryOrders,
1175
- _args8 = arguments;
1176
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1177
- while (1) switch (_context8.prev = _context8.next) {
1404
+ _args11 = arguments;
1405
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1406
+ while (1) switch (_context11.prev = _context11.next) {
1178
1407
  case 0:
1179
- options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1408
+ options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
1180
1409
  orderList = [];
1181
1410
  hasFetchedRemoteSnapshot = false;
1182
1411
  trigger = options.trigger || 'unknown';
1183
- _context8.next = 6;
1412
+ _context11.next = 6;
1184
1413
  return this.loadOrdersFromSQLite();
1185
1414
  case 6:
1186
- protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1187
- return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1415
+ protectedOrdersBeforeRemoteFetch = _context11.sent.filter(function (order) {
1416
+ return _this6.shouldProtectLocalOrderFromRemoteSnapshot(order);
1188
1417
  });
1189
1418
  this.logInfo('loadOrdersByServer-开始', {
1190
1419
  trigger: trigger,
@@ -1192,22 +1421,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1192
1421
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1193
1422
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
1194
1423
  protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
1195
- return count + _this5.getIdentifiedPendingPayments(order).length;
1424
+ return count + _this6.getIdentifiedPendingPayments(order).length;
1196
1425
  }, 0)
1197
1426
  });
1198
1427
  if (!this.orderDataSource) {
1199
- _context8.next = 23;
1428
+ _context11.next = 23;
1200
1429
  break;
1201
1430
  }
1202
- _context8.prev = 9;
1203
- _context8.next = 12;
1431
+ _context11.prev = 9;
1432
+ _context11.next = 12;
1204
1433
  return this.orderDataSource.run({
1205
1434
  sse: {
1206
1435
  query: this.store.createdAtQuery
1207
1436
  }
1208
1437
  });
1209
1438
  case 12:
1210
- data = _context8.sent;
1439
+ data = _context11.sent;
1211
1440
  orderList = data || [];
1212
1441
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1213
1442
  trigger: trigger,
@@ -1215,21 +1444,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1215
1444
  });
1216
1445
  hasFetchedRemoteSnapshot = true;
1217
1446
  this.lastServerFullFetchAtMs = Date.now();
1218
- _context8.next = 23;
1447
+ _context11.next = 23;
1219
1448
  break;
1220
1449
  case 19:
1221
- _context8.prev = 19;
1222
- _context8.t0 = _context8["catch"](9);
1450
+ _context11.prev = 19;
1451
+ _context11.t0 = _context11["catch"](9);
1223
1452
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1224
- return _context8.abrupt("return", this.store.list);
1453
+ return _context11.abrupt("return", this.store.list);
1225
1454
  case 23:
1226
1455
  if (hasFetchedRemoteSnapshot) {
1227
1456
  this.clearOrderSnapshotMarker();
1228
1457
  }
1229
- _context8.next = 26;
1458
+ _context11.next = 26;
1230
1459
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1231
1460
  case 26:
1232
- _yield$this$replaceOr = _context8.sent;
1461
+ _yield$this$replaceOr = _context11.sent;
1233
1462
  mergedOrders = _yield$this$replaceOr.orders;
1234
1463
  isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1235
1464
  if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
@@ -1242,15 +1471,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1242
1471
  persistedCount: mergedOrders.length,
1243
1472
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1244
1473
  });
1245
- _context8.next = 34;
1474
+ _context11.next = 34;
1246
1475
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1247
1476
  case 34:
1248
- return _context8.abrupt("return", memoryOrders);
1477
+ return _context11.abrupt("return", memoryOrders);
1249
1478
  case 35:
1250
1479
  case "end":
1251
- return _context8.stop();
1480
+ return _context11.stop();
1252
1481
  }
1253
- }, _callee8, this, [[9, 19]]);
1482
+ }, _callee11, this, [[9, 19]]);
1254
1483
  }));
1255
1484
  function loadOrdersByServer() {
1256
1485
  return _loadOrdersByServer.apply(this, arguments);
@@ -1264,25 +1493,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1264
1493
  }, {
1265
1494
  key: "refreshOrdersForCurrentBusinessDay",
1266
1495
  value: (function () {
1267
- var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1496
+ var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1268
1497
  var options,
1269
1498
  refreshPromise,
1270
- _args9 = arguments;
1271
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1272
- while (1) switch (_context9.prev = _context9.next) {
1499
+ _args12 = arguments;
1500
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1501
+ while (1) switch (_context12.prev = _context12.next) {
1273
1502
  case 0:
1274
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1503
+ options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1275
1504
  if (!this.businessDayRefreshPromise) {
1276
- _context9.next = 3;
1505
+ _context12.next = 3;
1277
1506
  break;
1278
1507
  }
1279
- return _context9.abrupt("return", this.businessDayRefreshPromise);
1508
+ return _context12.abrupt("return", this.businessDayRefreshPromise);
1280
1509
  case 3:
1281
1510
  if (!(!this.orderDataSource || !this.getCurrentShopId() || this.hasPulledOrdersToday())) {
1282
- _context9.next = 5;
1511
+ _context12.next = 5;
1283
1512
  break;
1284
1513
  }
1285
- return _context9.abrupt("return");
1514
+ return _context12.abrupt("return");
1286
1515
  case 5:
1287
1516
  refreshPromise = this.silentRefresh({
1288
1517
  trigger: options.trigger || 'business_day_rollover'
@@ -1290,18 +1519,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1290
1519
  return undefined;
1291
1520
  });
1292
1521
  this.businessDayRefreshPromise = refreshPromise;
1293
- _context9.prev = 7;
1294
- _context9.next = 10;
1522
+ _context12.prev = 7;
1523
+ _context12.next = 10;
1295
1524
  return refreshPromise;
1296
1525
  case 10:
1297
- _context9.prev = 10;
1526
+ _context12.prev = 10;
1298
1527
  this.businessDayRefreshPromise = null;
1299
- return _context9.finish(10);
1528
+ return _context12.finish(10);
1300
1529
  case 13:
1301
1530
  case "end":
1302
- return _context9.stop();
1531
+ return _context12.stop();
1303
1532
  }
1304
- }, _callee9, this, [[7,, 10, 13]]);
1533
+ }, _callee12, this, [[7,, 10, 13]]);
1305
1534
  }));
1306
1535
  function refreshOrdersForCurrentBusinessDay() {
1307
1536
  return _refreshOrdersForCurrentBusinessDay.apply(this, arguments);
@@ -1317,23 +1546,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1317
1546
  }, {
1318
1547
  key: "silentRefresh",
1319
1548
  value: (function () {
1320
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1549
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1321
1550
  var options,
1322
1551
  startTime,
1323
1552
  trigger,
1324
1553
  elapsedSinceFullFetch,
1325
1554
  orders,
1326
1555
  errorMessage,
1327
- _args10 = arguments;
1328
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1329
- while (1) switch (_context10.prev = _context10.next) {
1556
+ _args13 = arguments;
1557
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1558
+ while (1) switch (_context13.prev = _context13.next) {
1330
1559
  case 0:
1331
- options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1560
+ options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
1332
1561
  startTime = Date.now();
1333
1562
  trigger = options.trigger || 'background';
1334
1563
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1335
1564
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1336
- _context10.next = 7;
1565
+ _context13.next = 7;
1337
1566
  break;
1338
1567
  }
1339
1568
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -1343,28 +1572,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1343
1572
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1344
1573
  orderCount: this.store.list.length
1345
1574
  });
1346
- return _context10.abrupt("return", this.store.list);
1575
+ return _context13.abrupt("return", this.store.list);
1347
1576
  case 7:
1348
1577
  this.logInfo('silentRefresh 开始', {
1349
1578
  trigger: trigger,
1350
1579
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1351
1580
  orderCount: this.store.list.length
1352
1581
  });
1353
- _context10.prev = 8;
1582
+ _context13.prev = 8;
1354
1583
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1355
1584
  this.updateCreateStore();
1356
- _context10.next = 12;
1585
+ _context13.next = 12;
1357
1586
  return this.loadOrdersByServer({
1358
1587
  trigger: trigger
1359
1588
  });
1360
1589
  case 12:
1361
- orders = _context10.sent;
1590
+ orders = _context13.sent;
1362
1591
  this.store.list = cloneDeep(orders);
1363
1592
  this.syncOrdersMap();
1364
- _context10.next = 17;
1593
+ _context13.next = 17;
1365
1594
  return this.emitOrdersChanged([], 'silentRefresh');
1366
1595
  case 17:
1367
- _context10.next = 19;
1596
+ _context13.next = 19;
1368
1597
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1369
1598
  case 19:
1370
1599
  this.logInfo('silentRefresh 完成', {
@@ -1372,22 +1601,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1372
1601
  orderCount: orders.length,
1373
1602
  duration: "".concat(Date.now() - startTime, "ms")
1374
1603
  });
1375
- return _context10.abrupt("return", this.store.list);
1604
+ return _context13.abrupt("return", this.store.list);
1376
1605
  case 23:
1377
- _context10.prev = 23;
1378
- _context10.t0 = _context10["catch"](8);
1379
- errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1606
+ _context13.prev = 23;
1607
+ _context13.t0 = _context13["catch"](8);
1608
+ errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1380
1609
  this.logError('silentRefresh 失败', {
1381
1610
  trigger: trigger,
1382
1611
  duration: "".concat(Date.now() - startTime, "ms"),
1383
1612
  error: errorMessage
1384
1613
  });
1385
- return _context10.abrupt("return", this.store.list);
1614
+ return _context13.abrupt("return", this.store.list);
1386
1615
  case 28:
1387
1616
  case "end":
1388
- return _context10.stop();
1617
+ return _context13.stop();
1389
1618
  }
1390
- }, _callee10, this, [[8, 23]]);
1619
+ }, _callee13, this, [[8, 23]]);
1391
1620
  }));
1392
1621
  function silentRefresh() {
1393
1622
  return _silentRefresh.apply(this, arguments);
@@ -1425,21 +1654,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1425
1654
  }, {
1426
1655
  key: "prepareNormalizedOrdersForMemoryList",
1427
1656
  value: function prepareNormalizedOrdersForMemoryList(orders) {
1428
- var _this6 = this;
1657
+ var _this7 = this;
1429
1658
  return orders.map(function (order) {
1430
- return _this6.prepareNormalizedOrderForMemoryList(order);
1659
+ return _this7.prepareNormalizedOrderForMemoryList(order);
1431
1660
  }).filter(function (order) {
1432
- return _this6.shouldKeepOrderInMemory(order);
1661
+ return _this7.shouldKeepOrderInMemory(order);
1433
1662
  });
1434
1663
  }
1435
1664
  }, {
1436
1665
  key: "normalizeOrdersForMemoryList",
1437
1666
  value: function normalizeOrdersForMemoryList(orders, source) {
1438
- var _this7 = this;
1667
+ var _this8 = this;
1439
1668
  return orders.map(function (order) {
1440
- return _this7.normalizeOrderForMemoryList(order, source);
1669
+ return _this8.normalizeOrderForMemoryList(order, source);
1441
1670
  }).filter(function (order) {
1442
- return _this7.shouldKeepOrderInMemory(order);
1671
+ return _this8.shouldKeepOrderInMemory(order);
1443
1672
  });
1444
1673
  }
1445
1674
  }, {
@@ -1473,31 +1702,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1473
1702
  }, {
1474
1703
  key: "overwriteExistingOrder",
1475
1704
  value: (function () {
1476
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fresh) {
1477
- var _this8 = this;
1705
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(fresh) {
1706
+ var _this9 = this;
1478
1707
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1479
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1480
- while (1) switch (_context11.prev = _context11.next) {
1708
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1709
+ while (1) switch (_context14.prev = _context14.next) {
1481
1710
  case 0:
1482
1711
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1483
1712
  if (!(orderId === undefined || orderId === null)) {
1484
- _context11.next = 4;
1713
+ _context14.next = 4;
1485
1714
  break;
1486
1715
  }
1487
1716
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1488
- return _context11.abrupt("return", {
1717
+ return _context14.abrupt("return", {
1489
1718
  overwritten: false
1490
1719
  });
1491
1720
  case 4:
1492
1721
  key = this.getIdKey(orderId);
1493
1722
  if (this.store.map.has(key)) {
1494
- _context11.next = 8;
1723
+ _context14.next = 8;
1495
1724
  break;
1496
1725
  }
1497
1726
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1498
1727
  orderId: orderId
1499
1728
  });
1500
- return _context11.abrupt("return", {
1729
+ return _context14.abrupt("return", {
1501
1730
  overwritten: false
1502
1731
  });
1503
1732
  case 8:
@@ -1511,31 +1740,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1511
1740
  this.store.list = this.store.list.map(function (order) {
1512
1741
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1513
1742
  if (id === undefined || id === null) {
1514
- return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1743
+ return _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1515
1744
  }
1516
- return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1745
+ return _this9.getIdKey(id) === key ? reconciledFresh : _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1517
1746
  });
1518
1747
  this.syncOrdersMap();
1519
- _context11.next = 16;
1748
+ _context14.next = 16;
1520
1749
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1521
1750
  case 16:
1522
1751
  this.logInfo('overwriteExistingOrder-结束', {
1523
1752
  orderId: orderId,
1524
1753
  storeOrderCountAfter: this.store.list.length
1525
1754
  });
1526
- _context11.next = 19;
1755
+ _context14.next = 19;
1527
1756
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1528
1757
  case 19:
1529
- return _context11.abrupt("return", {
1758
+ return _context14.abrupt("return", {
1530
1759
  overwritten: true
1531
1760
  });
1532
1761
  case 20:
1533
1762
  case "end":
1534
- return _context11.stop();
1763
+ return _context14.stop();
1535
1764
  }
1536
- }, _callee11, this);
1765
+ }, _callee14, this);
1537
1766
  }));
1538
- function overwriteExistingOrder(_x7) {
1767
+ function overwriteExistingOrder(_x10) {
1539
1768
  return _overwriteExistingOrder.apply(this, arguments);
1540
1769
  }
1541
1770
  return overwriteExistingOrder;
@@ -1548,35 +1777,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1548
1777
  }, {
1549
1778
  key: "upsertOrdersFromRemote",
1550
1779
  value: (function () {
1551
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(freshOrders) {
1780
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(freshOrders) {
1552
1781
  var source,
1553
- _args12 = arguments;
1554
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1555
- while (1) switch (_context12.prev = _context12.next) {
1782
+ _args15 = arguments;
1783
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1784
+ while (1) switch (_context15.prev = _context15.next) {
1556
1785
  case 0:
1557
- source = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : 'upsertOrdersFromRemote';
1786
+ source = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : 'upsertOrdersFromRemote';
1558
1787
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1559
- _context12.next = 4;
1788
+ _context15.next = 4;
1560
1789
  break;
1561
1790
  }
1562
1791
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {
1563
1792
  source: source
1564
1793
  });
1565
- return _context12.abrupt("return");
1794
+ return _context15.abrupt("return");
1566
1795
  case 4:
1567
1796
  this.logInfo('upsertOrdersFromRemote-开始', {
1568
1797
  count: freshOrders.length,
1569
1798
  source: source
1570
1799
  });
1571
- _context12.next = 7;
1800
+ _context15.next = 7;
1572
1801
  return this.mergeOrdersToStore(freshOrders, source);
1573
1802
  case 7:
1574
1803
  case "end":
1575
- return _context12.stop();
1804
+ return _context15.stop();
1576
1805
  }
1577
- }, _callee12, this);
1806
+ }, _callee15, this);
1578
1807
  }));
1579
- function upsertOrdersFromRemote(_x8) {
1808
+ function upsertOrdersFromRemote(_x11) {
1580
1809
  return _upsertOrdersFromRemote.apply(this, arguments);
1581
1810
  }
1582
1811
  return upsertOrdersFromRemote;
@@ -1584,21 +1813,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1584
1813
  }, {
1585
1814
  key: "markOrderSyncedByExternalSaleNumber",
1586
1815
  value: function () {
1587
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1588
- var _this9 = this,
1816
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1817
+ var _this10 = this,
1589
1818
  _existing$external_sa,
1590
1819
  _nextOrder$order_id;
1591
1820
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1592
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1593
- while (1) switch (_context13.prev = _context13.next) {
1821
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1822
+ while (1) switch (_context16.prev = _context16.next) {
1594
1823
  case 0:
1595
1824
  externalSaleNumber = params.externalSaleNumber;
1596
1825
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1597
- _context13.next = 4;
1826
+ _context16.next = 4;
1598
1827
  break;
1599
1828
  }
1600
1829
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1601
- return _context13.abrupt("return", {
1830
+ return _context16.abrupt("return", {
1602
1831
  updated: false
1603
1832
  });
1604
1833
  case 4:
@@ -1606,16 +1835,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1606
1835
  targetIndex = this.store.list.findIndex(function (order) {
1607
1836
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1608
1837
  if (value === undefined || value === null || value === '') return false;
1609
- return _this9.getIdKey(value) === key;
1838
+ return _this10.getIdKey(value) === key;
1610
1839
  });
1611
1840
  if (!(targetIndex < 0)) {
1612
- _context13.next = 9;
1841
+ _context16.next = 9;
1613
1842
  break;
1614
1843
  }
1615
1844
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1616
1845
  external_sale_number: externalSaleNumber
1617
1846
  });
1618
- return _context13.abrupt("return", {
1847
+ return _context16.abrupt("return", {
1619
1848
  updated: false
1620
1849
  });
1621
1850
  case 9:
@@ -1631,27 +1860,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1631
1860
  return nextOrder;
1632
1861
  });
1633
1862
  this.syncOrdersMap();
1634
- _context13.next = 16;
1863
+ _context16.next = 16;
1635
1864
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1636
1865
  case 16:
1637
1866
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1638
1867
  external_sale_number: externalSaleNumber,
1639
1868
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1640
1869
  });
1641
- _context13.next = 19;
1870
+ _context16.next = 19;
1642
1871
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1643
1872
  case 19:
1644
- return _context13.abrupt("return", {
1873
+ return _context16.abrupt("return", {
1645
1874
  updated: true,
1646
1875
  order: nextOrder
1647
1876
  });
1648
1877
  case 20:
1649
1878
  case "end":
1650
- return _context13.stop();
1879
+ return _context16.stop();
1651
1880
  }
1652
- }, _callee13, this);
1881
+ }, _callee16, this);
1653
1882
  }));
1654
- function markOrderSyncedByExternalSaleNumber(_x9) {
1883
+ function markOrderSyncedByExternalSaleNumber(_x12) {
1655
1884
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1656
1885
  }
1657
1886
  return markOrderSyncedByExternalSaleNumber;
@@ -1663,8 +1892,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1663
1892
  }, {
1664
1893
  key: "upsertPendingSyncOrders",
1665
1894
  value: (function () {
1666
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(pendingOrders) {
1667
- var _this10 = this;
1895
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(pendingOrders) {
1896
+ var _this11 = this;
1668
1897
  var options,
1669
1898
  pendingMap,
1670
1899
  memoryPendingMap,
@@ -1694,26 +1923,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1694
1923
  insertIndex,
1695
1924
  patchedOrders,
1696
1925
  previousList,
1697
- _args14 = arguments;
1698
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1699
- while (1) switch (_context14.prev = _context14.next) {
1926
+ _args17 = arguments;
1927
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1928
+ while (1) switch (_context17.prev = _context17.next) {
1700
1929
  case 0:
1701
- options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1930
+ options = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {};
1702
1931
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1703
- _context14.next = 4;
1932
+ _context17.next = 4;
1704
1933
  break;
1705
1934
  }
1706
1935
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1707
- return _context14.abrupt("return");
1936
+ return _context17.abrupt("return");
1708
1937
  case 4:
1709
1938
  pendingMap = new Map();
1710
1939
  memoryPendingMap = new Map();
1711
1940
  _iterator7 = _createForOfIteratorHelper(pendingOrders);
1712
- _context14.prev = 7;
1941
+ _context17.prev = 7;
1713
1942
  _iterator7.s();
1714
1943
  case 9:
1715
1944
  if ((_step7 = _iterator7.n()).done) {
1716
- _context14.next = 20;
1945
+ _context17.next = 20;
1717
1946
  break;
1718
1947
  }
1719
1948
  order = _step7.value;
@@ -1724,43 +1953,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1724
1953
  });
1725
1954
  storageKey = this.getOrderStorageKey(pendingOrder);
1726
1955
  if (storageKey) {
1727
- _context14.next = 16;
1956
+ _context17.next = 16;
1728
1957
  break;
1729
1958
  }
1730
- return _context14.abrupt("continue", 18);
1959
+ return _context17.abrupt("continue", 18);
1731
1960
  case 16:
1732
1961
  pendingMap.set(storageKey, pendingOrder);
1733
1962
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1734
1963
  case 18:
1735
- _context14.next = 9;
1964
+ _context17.next = 9;
1736
1965
  break;
1737
1966
  case 20:
1738
- _context14.next = 25;
1967
+ _context17.next = 25;
1739
1968
  break;
1740
1969
  case 22:
1741
- _context14.prev = 22;
1742
- _context14.t0 = _context14["catch"](7);
1743
- _iterator7.e(_context14.t0);
1970
+ _context17.prev = 22;
1971
+ _context17.t0 = _context17["catch"](7);
1972
+ _iterator7.e(_context17.t0);
1744
1973
  case 25:
1745
- _context14.prev = 25;
1974
+ _context17.prev = 25;
1746
1975
  _iterator7.f();
1747
- return _context14.finish(25);
1976
+ return _context17.finish(25);
1748
1977
  case 28:
1749
1978
  if (!(pendingMap.size === 0)) {
1750
- _context14.next = 31;
1979
+ _context17.next = 31;
1751
1980
  break;
1752
1981
  }
1753
1982
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1754
1983
  count: pendingOrders.length
1755
1984
  });
1756
- return _context14.abrupt("return");
1985
+ return _context17.abrupt("return");
1757
1986
  case 31:
1758
1987
  this.logInfo('upsertPendingSyncOrders-开始', {
1759
1988
  count: pendingMap.size
1760
1989
  });
1761
1990
  mergeActions = {};
1762
1991
  updatedList = this.store.list.map(function (order) {
1763
- return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1992
+ return _this11.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1764
1993
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1765
1994
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1766
1995
  identityKeyToIndex = new Map();
@@ -1779,17 +2008,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1779
2008
  }
1780
2009
  }
1781
2010
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
1782
- _context14.prev = 37;
2011
+ _context17.prev = 37;
1783
2012
  _iterator9.s();
1784
2013
  case 39:
1785
2014
  if ((_step9 = _iterator9.n()).done) {
1786
- _context14.next = 58;
2015
+ _context17.next = 58;
1787
2016
  break;
1788
2017
  }
1789
2018
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
1790
2019
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1791
2020
  if (!(matchIndex >= 0)) {
1792
- _context14.next = 52;
2021
+ _context17.next = 52;
1793
2022
  break;
1794
2023
  }
1795
2024
  existingOrder = updatedList[matchIndex];
@@ -1806,57 +2035,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1806
2035
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1807
2036
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1808
2037
  mergeActions[_storageKey] = 'update';
1809
- return _context14.abrupt("continue", 56);
2038
+ return _context17.abrupt("continue", 56);
1810
2039
  case 52:
1811
2040
  insertIndex = updatedList.length;
1812
2041
  updatedList.push(_pendingOrder);
1813
2042
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1814
2043
  mergeActions[_storageKey] = 'insert';
1815
2044
  case 56:
1816
- _context14.next = 39;
2045
+ _context17.next = 39;
1817
2046
  break;
1818
2047
  case 58:
1819
- _context14.next = 63;
2048
+ _context17.next = 63;
1820
2049
  break;
1821
2050
  case 60:
1822
- _context14.prev = 60;
1823
- _context14.t1 = _context14["catch"](37);
1824
- _iterator9.e(_context14.t1);
2051
+ _context17.prev = 60;
2052
+ _context17.t1 = _context17["catch"](37);
2053
+ _iterator9.e(_context17.t1);
1825
2054
  case 63:
1826
- _context14.prev = 63;
2055
+ _context17.prev = 63;
1827
2056
  _iterator9.f();
1828
- return _context14.finish(63);
2057
+ return _context17.finish(63);
1829
2058
  case 66:
1830
2059
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1831
2060
  previousList = this.store.list;
1832
2061
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1833
2062
  this.syncOrdersMap();
1834
- _context14.prev = 70;
1835
- _context14.next = 73;
2063
+ _context17.prev = 70;
2064
+ _context17.next = 73;
1836
2065
  return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1837
2066
  case 73:
1838
- _context14.next = 80;
2067
+ _context17.next = 80;
1839
2068
  break;
1840
2069
  case 75:
1841
- _context14.prev = 75;
1842
- _context14.t2 = _context14["catch"](70);
2070
+ _context17.prev = 75;
2071
+ _context17.t2 = _context17["catch"](70);
1843
2072
  this.store.list = previousList;
1844
2073
  this.syncOrdersMap();
1845
- throw _context14.t2;
2074
+ throw _context17.t2;
1846
2075
  case 80:
1847
2076
  this.logInfo('upsertPendingSyncOrders-结束', {
1848
2077
  count: patchedOrders.length,
1849
2078
  storeOrderCountAfter: this.store.list.length
1850
2079
  });
1851
- _context14.next = 83;
2080
+ _context17.next = 83;
1852
2081
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1853
2082
  case 83:
1854
2083
  case "end":
1855
- return _context14.stop();
2084
+ return _context17.stop();
1856
2085
  }
1857
- }, _callee14, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2086
+ }, _callee17, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1858
2087
  }));
1859
- function upsertPendingSyncOrders(_x10) {
2088
+ function upsertPendingSyncOrders(_x13) {
1860
2089
  return _upsertPendingSyncOrders.apply(this, arguments);
1861
2090
  }
1862
2091
  return upsertPendingSyncOrders;
@@ -1869,27 +2098,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1869
2098
  }, {
1870
2099
  key: "upsertLocalDraftOrders",
1871
2100
  value: (function () {
1872
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(draftOrders) {
1873
- var _this11 = this;
2101
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(draftOrders) {
2102
+ var _this12 = this;
1874
2103
  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;
1875
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1876
- while (1) switch (_context15.prev = _context15.next) {
2104
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2105
+ while (1) switch (_context18.prev = _context18.next) {
1877
2106
  case 0:
1878
2107
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1879
- _context15.next = 3;
2108
+ _context18.next = 3;
1880
2109
  break;
1881
2110
  }
1882
2111
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1883
- return _context15.abrupt("return");
2112
+ return _context18.abrupt("return");
1884
2113
  case 3:
1885
2114
  draftMap = new Map();
1886
2115
  memoryDraftMap = new Map();
1887
2116
  _iterator10 = _createForOfIteratorHelper(draftOrders);
1888
- _context15.prev = 6;
2117
+ _context18.prev = 6;
1889
2118
  _iterator10.s();
1890
2119
  case 8:
1891
2120
  if ((_step10 = _iterator10.n()).done) {
1892
- _context15.next = 19;
2121
+ _context18.next = 19;
1893
2122
  break;
1894
2123
  }
1895
2124
  order = _step10.value;
@@ -1899,10 +2128,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1899
2128
  });
1900
2129
  storageKey = this.getOrderStorageKey(draftOrder);
1901
2130
  if (storageKey) {
1902
- _context15.next = 14;
2131
+ _context18.next = 14;
1903
2132
  break;
1904
2133
  }
1905
- return _context15.abrupt("continue", 17);
2134
+ return _context18.abrupt("continue", 17);
1906
2135
  case 14:
1907
2136
  draftMap.set(storageKey, draftOrder);
1908
2137
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -1910,28 +2139,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1910
2139
  memoryDraftMap.set(storageKey, memoryDraftOrder);
1911
2140
  }
1912
2141
  case 17:
1913
- _context15.next = 8;
2142
+ _context18.next = 8;
1914
2143
  break;
1915
2144
  case 19:
1916
- _context15.next = 24;
2145
+ _context18.next = 24;
1917
2146
  break;
1918
2147
  case 21:
1919
- _context15.prev = 21;
1920
- _context15.t0 = _context15["catch"](6);
1921
- _iterator10.e(_context15.t0);
2148
+ _context18.prev = 21;
2149
+ _context18.t0 = _context18["catch"](6);
2150
+ _iterator10.e(_context18.t0);
1922
2151
  case 24:
1923
- _context15.prev = 24;
2152
+ _context18.prev = 24;
1924
2153
  _iterator10.f();
1925
- return _context15.finish(24);
2154
+ return _context18.finish(24);
1926
2155
  case 27:
1927
2156
  if (!(draftMap.size === 0)) {
1928
- _context15.next = 30;
2157
+ _context18.next = 30;
1929
2158
  break;
1930
2159
  }
1931
2160
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1932
2161
  count: draftOrders.length
1933
2162
  });
1934
- return _context15.abrupt("return");
2163
+ return _context18.abrupt("return");
1935
2164
  case 30:
1936
2165
  this.logInfo('upsertLocalDraftOrders-开始', {
1937
2166
  count: draftMap.size,
@@ -1940,7 +2169,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1940
2169
  });
1941
2170
  mergeActions = {};
1942
2171
  updatedList = this.store.list.filter(function (order) {
1943
- return _this11.shouldKeepOrderInMemory(order);
2172
+ return _this12.shouldKeepOrderInMemory(order);
1944
2173
  });
1945
2174
  identityKeyToIndex = new Map();
1946
2175
  for (index = 0; index < updatedList.length; index += 1) {
@@ -1957,17 +2186,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1957
2186
  }
1958
2187
  }
1959
2188
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
1960
- _context15.prev = 36;
2189
+ _context18.prev = 36;
1961
2190
  _iterator12.s();
1962
2191
  case 38:
1963
2192
  if ((_step12 = _iterator12.n()).done) {
1964
- _context15.next = 57;
2193
+ _context18.next = 57;
1965
2194
  break;
1966
2195
  }
1967
2196
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
1968
2197
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1969
2198
  if (!(matchIndex >= 0)) {
1970
- _context15.next = 51;
2199
+ _context18.next = 51;
1971
2200
  break;
1972
2201
  }
1973
2202
  existingOrder = updatedList[matchIndex];
@@ -1982,68 +2211,68 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1982
2211
  draftMap.set(_storageKey2, reconciledDraftOrder);
1983
2212
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1984
2213
  mergeActions[_storageKey2] = 'update';
1985
- return _context15.abrupt("continue", 55);
2214
+ return _context18.abrupt("continue", 55);
1986
2215
  case 51:
1987
2216
  insertIndex = updatedList.length;
1988
2217
  updatedList.push(_draftOrder);
1989
2218
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1990
2219
  mergeActions[_storageKey2] = 'insert';
1991
2220
  case 55:
1992
- _context15.next = 38;
2221
+ _context18.next = 38;
1993
2222
  break;
1994
2223
  case 57:
1995
- _context15.next = 62;
2224
+ _context18.next = 62;
1996
2225
  break;
1997
2226
  case 59:
1998
- _context15.prev = 59;
1999
- _context15.t1 = _context15["catch"](36);
2000
- _iterator12.e(_context15.t1);
2227
+ _context18.prev = 59;
2228
+ _context18.t1 = _context18["catch"](36);
2229
+ _iterator12.e(_context18.t1);
2001
2230
  case 62:
2002
- _context15.prev = 62;
2231
+ _context18.prev = 62;
2003
2232
  _iterator12.f();
2004
- return _context15.finish(62);
2233
+ return _context18.finish(62);
2005
2234
  case 65:
2006
2235
  patchedOrders = _toConsumableArray(draftMap.values());
2007
2236
  previousList = this.store.list;
2008
2237
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2009
2238
  this.syncOrdersMap();
2010
- _context15.prev = 69;
2011
- _context15.next = 72;
2239
+ _context18.prev = 69;
2240
+ _context18.next = 72;
2012
2241
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2013
2242
  throwOnError: true
2014
2243
  });
2015
2244
  case 72:
2016
- _context15.next = 79;
2245
+ _context18.next = 79;
2017
2246
  break;
2018
2247
  case 74:
2019
- _context15.prev = 74;
2020
- _context15.t2 = _context15["catch"](69);
2248
+ _context18.prev = 74;
2249
+ _context18.t2 = _context18["catch"](69);
2021
2250
  this.store.list = previousList;
2022
2251
  this.syncOrdersMap();
2023
- throw _context15.t2;
2252
+ throw _context18.t2;
2024
2253
  case 79:
2025
2254
  this.logInfo('upsertLocalDraftOrders-结束', {
2026
2255
  count: patchedOrders.length,
2027
2256
  storeOrderCountAfter: this.store.list.length
2028
2257
  });
2029
2258
  removedLegacyMemoryDraft = previousList.some(function (order) {
2030
- return !_this11.shouldKeepOrderInMemory(order);
2259
+ return !_this12.shouldKeepOrderInMemory(order);
2031
2260
  });
2032
2261
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2033
- _context15.next = 84;
2262
+ _context18.next = 84;
2034
2263
  break;
2035
2264
  }
2036
- _context15.next = 84;
2265
+ _context18.next = 84;
2037
2266
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2038
- return _this11.shouldKeepOrderInMemory(order);
2267
+ return _this12.shouldKeepOrderInMemory(order);
2039
2268
  }), 'upsertLocalDraftOrders');
2040
2269
  case 84:
2041
2270
  case "end":
2042
- return _context15.stop();
2271
+ return _context18.stop();
2043
2272
  }
2044
- }, _callee15, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2273
+ }, _callee18, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2045
2274
  }));
2046
- function upsertLocalDraftOrders(_x11) {
2275
+ function upsertLocalDraftOrders(_x14) {
2047
2276
  return _upsertLocalDraftOrders.apply(this, arguments);
2048
2277
  }
2049
2278
  return upsertLocalDraftOrders;
@@ -2055,42 +2284,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2055
2284
  }, {
2056
2285
  key: "fetchOrdersBySSE",
2057
2286
  value: (function () {
2058
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2287
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2059
2288
  var query,
2060
2289
  data,
2061
- _args16 = arguments;
2062
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2063
- while (1) switch (_context16.prev = _context16.next) {
2290
+ _args19 = arguments;
2291
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2292
+ while (1) switch (_context19.prev = _context19.next) {
2064
2293
  case 0:
2065
- query = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
2294
+ query = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {};
2066
2295
  if (this.orderDataSource) {
2067
- _context16.next = 3;
2296
+ _context19.next = 3;
2068
2297
  break;
2069
2298
  }
2070
- return _context16.abrupt("return", []);
2299
+ return _context19.abrupt("return", []);
2071
2300
  case 3:
2072
- _context16.prev = 3;
2073
- _context16.next = 6;
2301
+ _context19.prev = 3;
2302
+ _context19.next = 6;
2074
2303
  return this.orderDataSource.run({
2075
2304
  sse: {
2076
2305
  query: query
2077
2306
  }
2078
2307
  });
2079
2308
  case 6:
2080
- data = _context16.sent;
2081
- return _context16.abrupt("return", data || []);
2309
+ data = _context19.sent;
2310
+ return _context19.abrupt("return", data || []);
2082
2311
  case 10:
2083
- _context16.prev = 10;
2084
- _context16.t0 = _context16["catch"](3);
2312
+ _context19.prev = 10;
2313
+ _context19.t0 = _context19["catch"](3);
2085
2314
  this.logError('fetchOrdersBySSE-失败', {
2086
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0)
2315
+ error: _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0)
2087
2316
  });
2088
- return _context16.abrupt("return", []);
2317
+ return _context19.abrupt("return", []);
2089
2318
  case 14:
2090
2319
  case "end":
2091
- return _context16.stop();
2320
+ return _context19.stop();
2092
2321
  }
2093
- }, _callee16, this, [[3, 10]]);
2322
+ }, _callee19, this, [[3, 10]]);
2094
2323
  }));
2095
2324
  function fetchOrdersBySSE() {
2096
2325
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -2120,9 +2349,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2120
2349
  }, {
2121
2350
  key: "syncOrdersMap",
2122
2351
  value: function syncOrdersMap() {
2123
- var _this12 = this;
2352
+ var _this13 = this;
2124
2353
  this.store.list = this.store.list.filter(function (order) {
2125
- return _this12.shouldKeepOrderInMemory(order);
2354
+ return _this13.shouldKeepOrderInMemory(order);
2126
2355
  });
2127
2356
  this.store.map.clear();
2128
2357
  var _iterator13 = _createForOfIteratorHelper(this.store.list),
@@ -2178,7 +2407,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2178
2407
  }, {
2179
2408
  key: "getOrderIdentityEntries",
2180
2409
  value: function getOrderIdentityEntries(order) {
2181
- var _this13 = this;
2410
+ var _this14 = this;
2182
2411
  if (!order) return [];
2183
2412
  var record = order;
2184
2413
  var candidates = [{
@@ -2196,9 +2425,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2196
2425
  }];
2197
2426
  var entries = [];
2198
2427
  var _loop = function _loop() {
2199
- var candidate = _candidates[_i2];
2200
- if (_this13.isBlankIdentityValue(candidate.value)) return 0; // continue
2201
- var key = _this13.getIdKey(candidate.value);
2428
+ var candidate = _candidates[_i3];
2429
+ if (_this14.isBlankIdentityValue(candidate.value)) return 0; // continue
2430
+ var key = _this14.getIdKey(candidate.value);
2202
2431
  if (entries.some(function (entry) {
2203
2432
  return entry.field === candidate.field && entry.key === key;
2204
2433
  })) return 0; // continue
@@ -2208,7 +2437,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2208
2437
  });
2209
2438
  },
2210
2439
  _ret;
2211
- for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
2440
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
2212
2441
  _ret = _loop();
2213
2442
  if (_ret === 0) continue;
2214
2443
  }
@@ -2237,8 +2466,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2237
2466
  value: function getOrderDateKey(order) {
2238
2467
  var _order$bookings, _order$bookings2;
2239
2468
  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];
2240
- for (var _i3 = 0, _candidates2 = candidates; _i3 < _candidates2.length; _i3++) {
2241
- var v = _candidates2[_i3];
2469
+ for (var _i4 = 0, _candidates2 = candidates; _i4 < _candidates2.length; _i4++) {
2470
+ var v = _candidates2[_i4];
2242
2471
  if (!v) continue;
2243
2472
  var text = String(v);
2244
2473
  if (!text) continue;
@@ -2265,29 +2494,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2265
2494
  }, {
2266
2495
  key: "setupOrderSync",
2267
2496
  value: function setupOrderSync() {
2268
- var _this14 = this;
2497
+ var _this15 = this;
2269
2498
  if (!this.orderDataSource) return;
2270
2499
  this.orderDataSource.run({
2271
2500
  pubsub: {
2272
2501
  callback: function callback(res) {
2273
2502
  var _message$id, _message$order_id, _message$type;
2274
2503
  var pubsubReceivedAt = Date.now();
2275
- var message = _this14.normalizeOrderSyncMessage(res);
2504
+ var message = _this15.normalizeOrderSyncMessage(res);
2276
2505
  if (!message) return;
2277
2506
  message._pubsubReceivedAt = pubsubReceivedAt;
2278
- _this14.pendingSyncMessages.push(message);
2279
- var throttleMs = _this14.getOrderSyncThrottleMs();
2280
- var routeInfo = _this14.resolveSyncMessageRoute(message);
2281
- _this14.logInfo('orderSync-收到消息并入队', {
2507
+ _this15.pendingSyncMessages.push(message);
2508
+ var throttleMs = _this15.getOrderSyncThrottleMs();
2509
+ var routeInfo = _this15.resolveSyncMessageRoute(message);
2510
+ _this15.logInfo('orderSync-收到消息并入队', {
2282
2511
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2283
2512
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2284
2513
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2285
- pendingCount: _this14.pendingSyncMessages.length,
2514
+ pendingCount: _this15.pendingSyncMessages.length,
2286
2515
  throttleMs: throttleMs,
2287
2516
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2288
2517
  fullMessage: JSON.stringify(message)
2289
2518
  });
2290
- _this14.scheduleOrderSyncThrottle();
2519
+ _this15.scheduleOrderSyncThrottle();
2291
2520
  }
2292
2521
  }
2293
2522
  }).catch(function () {
@@ -2304,7 +2533,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2304
2533
  }, {
2305
2534
  key: "scheduleOrderSyncThrottle",
2306
2535
  value: function scheduleOrderSyncThrottle() {
2307
- var _this15 = this;
2536
+ var _this16 = this;
2308
2537
  if (this.isProcessingSyncBatch) return;
2309
2538
  if (this.isIdlePhase) {
2310
2539
  this.isIdlePhase = false;
@@ -2315,8 +2544,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2315
2544
  if (this.syncTimer) return;
2316
2545
  var throttleMs = this.getOrderSyncThrottleMs();
2317
2546
  this.syncTimer = setTimeout(function () {
2318
- _this15.syncTimer = undefined;
2319
- void _this15.flushOrderSyncMessagesByThrottle();
2547
+ _this16.syncTimer = undefined;
2548
+ void _this16.flushOrderSyncMessagesByThrottle();
2320
2549
  }, throttleMs);
2321
2550
  }
2322
2551
 
@@ -2327,41 +2556,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2327
2556
  }, {
2328
2557
  key: "flushOrderSyncMessagesByThrottle",
2329
2558
  value: (function () {
2330
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2331
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2332
- while (1) switch (_context17.prev = _context17.next) {
2559
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2560
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2561
+ while (1) switch (_context20.prev = _context20.next) {
2333
2562
  case 0:
2334
2563
  if (!this.isProcessingSyncBatch) {
2335
- _context17.next = 2;
2564
+ _context20.next = 2;
2336
2565
  break;
2337
2566
  }
2338
- return _context17.abrupt("return");
2567
+ return _context20.abrupt("return");
2339
2568
  case 2:
2340
2569
  if (!(this.pendingSyncMessages.length === 0)) {
2341
- _context17.next = 5;
2570
+ _context20.next = 5;
2342
2571
  break;
2343
2572
  }
2344
2573
  this.isIdlePhase = true;
2345
- return _context17.abrupt("return");
2574
+ return _context20.abrupt("return");
2346
2575
  case 5:
2347
2576
  this.isProcessingSyncBatch = true;
2348
- _context17.prev = 6;
2349
- _context17.next = 9;
2577
+ _context20.prev = 6;
2578
+ _context20.next = 9;
2350
2579
  return this.processOrderSyncMessages();
2351
2580
  case 9:
2352
- _context17.prev = 9;
2581
+ _context20.prev = 9;
2353
2582
  this.isProcessingSyncBatch = false;
2354
2583
  if (this.pendingSyncMessages.length > 0) {
2355
2584
  this.scheduleOrderSyncThrottle();
2356
2585
  } else {
2357
2586
  this.isIdlePhase = true;
2358
2587
  }
2359
- return _context17.finish(9);
2588
+ return _context20.finish(9);
2360
2589
  case 13:
2361
2590
  case "end":
2362
- return _context17.stop();
2591
+ return _context20.stop();
2363
2592
  }
2364
- }, _callee17, this, [[6,, 9, 13]]);
2593
+ }, _callee20, this, [[6,, 9, 13]]);
2365
2594
  }));
2366
2595
  function flushOrderSyncMessagesByThrottle() {
2367
2596
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2383,19 +2612,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2383
2612
  }, {
2384
2613
  key: "processOrderSyncMessages",
2385
2614
  value: (function () {
2386
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2387
- var _this16 = this;
2615
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2616
+ var _this17 = this;
2388
2617
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2389
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2390
- while (1) switch (_context18.prev = _context18.next) {
2618
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2619
+ while (1) switch (_context21.prev = _context21.next) {
2391
2620
  case 0:
2392
2621
  messages = _toConsumableArray(this.pendingSyncMessages);
2393
2622
  this.pendingSyncMessages = [];
2394
2623
  if (!(messages.length === 0)) {
2395
- _context18.next = 4;
2624
+ _context21.next = 4;
2396
2625
  break;
2397
2626
  }
2398
- return _context18.abrupt("return");
2627
+ return _context21.abrupt("return");
2399
2628
  case 4:
2400
2629
  batchProcessStartAt = Date.now();
2401
2630
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2411,13 +2640,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2411
2640
  upsertOrders = new Map();
2412
2641
  refreshIds = [];
2413
2642
  messages.forEach(function (msg, msgIndex) {
2414
- var routeInfo = _this16.resolveSyncMessageRoute(msg);
2643
+ var routeInfo = _this17.resolveSyncMessageRoute(msg);
2415
2644
  var hasBatchIds = routeInfo.hasBatchIds;
2416
2645
  var singleId = routeInfo.singleId;
2417
2646
  var hasSingleId = routeInfo.hasSingleId;
2418
- var normalizedBody = _this16.normalizeOrderSyncPayload(msg.body || msg.data);
2647
+ var normalizedBody = _this17.normalizeOrderSyncPayload(msg.body || msg.data);
2419
2648
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2420
- upsertOrders.set(_this16.getIdKey(normalizedBody.order_id), normalizedBody);
2649
+ upsertOrders.set(_this17.getIdKey(normalizedBody.order_id), normalizedBody);
2421
2650
  return;
2422
2651
  }
2423
2652
  if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
@@ -2429,41 +2658,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2429
2658
  refreshIdCount: uniqueRefreshIds.length
2430
2659
  });
2431
2660
  if (!(upsertList.length > 0)) {
2432
- _context18.next = 16;
2661
+ _context21.next = 16;
2433
2662
  break;
2434
2663
  }
2435
- _context18.next = 16;
2664
+ _context21.next = 16;
2436
2665
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2437
2666
  case 16:
2438
2667
  if (!(uniqueRefreshIds.length > 0)) {
2439
- _context18.next = 28;
2668
+ _context21.next = 28;
2440
2669
  break;
2441
2670
  }
2442
2671
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2443
2672
  if (skipped.length > 0) {}
2444
2673
  if (!(toFetch.length > 0)) {
2445
- _context18.next = 28;
2674
+ _context21.next = 28;
2446
2675
  break;
2447
2676
  }
2448
- _context18.next = 22;
2677
+ _context21.next = 22;
2449
2678
  return this.fetchOrdersByHttp(toFetch);
2450
2679
  case 22:
2451
- freshOrders = _context18.sent;
2680
+ freshOrders = _context21.sent;
2452
2681
  if (!(freshOrders.length > 0)) {
2453
- _context18.next = 28;
2682
+ _context21.next = 28;
2454
2683
  break;
2455
2684
  }
2456
- _context18.next = 26;
2685
+ _context21.next = 26;
2457
2686
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2458
2687
  case 26:
2459
- _context18.next = 28;
2688
+ _context21.next = 28;
2460
2689
  break;
2461
2690
  case 28:
2462
2691
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2463
- _context18.next = 30;
2692
+ _context21.next = 30;
2464
2693
  break;
2465
2694
  }
2466
- return _context18.abrupt("return");
2695
+ return _context21.abrupt("return");
2467
2696
  case 30:
2468
2697
  batchProcessEndAt = Date.now();
2469
2698
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2472,13 +2701,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2472
2701
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2473
2702
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2474
2703
  });
2475
- _context18.next = 34;
2704
+ _context21.next = 34;
2476
2705
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2477
2706
  case 34:
2478
2707
  case "end":
2479
- return _context18.stop();
2708
+ return _context21.stop();
2480
2709
  }
2481
- }, _callee18, this);
2710
+ }, _callee21, this);
2482
2711
  }));
2483
2712
  function processOrderSyncMessages() {
2484
2713
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2499,29 +2728,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2499
2728
  }, {
2500
2729
  key: "fetchOrdersByHttp",
2501
2730
  value: (function () {
2502
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
2731
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids) {
2503
2732
  var _orderList, orderList;
2504
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2505
- while (1) switch (_context19.prev = _context19.next) {
2733
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2734
+ while (1) switch (_context22.prev = _context22.next) {
2506
2735
  case 0:
2507
2736
  if (!(!this.orderDataSource || ids.length === 0)) {
2508
- _context19.next = 2;
2737
+ _context22.next = 2;
2509
2738
  break;
2510
2739
  }
2511
- return _context19.abrupt("return", []);
2740
+ return _context22.abrupt("return", []);
2512
2741
  case 2:
2513
- _context19.prev = 2;
2742
+ _context22.prev = 2;
2514
2743
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2515
- _context19.next = 8;
2744
+ _context22.next = 8;
2516
2745
  break;
2517
2746
  }
2518
- _context19.next = 6;
2747
+ _context22.next = 6;
2519
2748
  return this.orderDataSource.fetchOrdersByIds(ids);
2520
2749
  case 6:
2521
- _orderList = _context19.sent;
2522
- return _context19.abrupt("return", _orderList || []);
2750
+ _orderList = _context22.sent;
2751
+ return _context22.abrupt("return", _orderList || []);
2523
2752
  case 8:
2524
- _context19.next = 10;
2753
+ _context22.next = 10;
2525
2754
  return this.orderDataSource.run({
2526
2755
  http: {
2527
2756
  query: {
@@ -2530,19 +2759,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2530
2759
  }
2531
2760
  });
2532
2761
  case 10:
2533
- orderList = _context19.sent;
2534
- return _context19.abrupt("return", orderList || []);
2762
+ orderList = _context22.sent;
2763
+ return _context22.abrupt("return", orderList || []);
2535
2764
  case 14:
2536
- _context19.prev = 14;
2537
- _context19.t0 = _context19["catch"](2);
2538
- return _context19.abrupt("return", []);
2765
+ _context22.prev = 14;
2766
+ _context22.t0 = _context22["catch"](2);
2767
+ return _context22.abrupt("return", []);
2539
2768
  case 17:
2540
2769
  case "end":
2541
- return _context19.stop();
2770
+ return _context22.stop();
2542
2771
  }
2543
- }, _callee19, this, [[2, 14]]);
2772
+ }, _callee22, this, [[2, 14]]);
2544
2773
  }));
2545
- function fetchOrdersByHttp(_x12) {
2774
+ function fetchOrdersByHttp(_x15) {
2546
2775
  return _fetchOrdersByHttp.apply(this, arguments);
2547
2776
  }
2548
2777
  return fetchOrdersByHttp;
@@ -2554,11 +2783,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2554
2783
  }, {
2555
2784
  key: "mergeOrdersToStore",
2556
2785
  value: (function () {
2557
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshOrders, source) {
2558
- var _this17 = this;
2786
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(freshOrders, source) {
2787
+ var _this18 = this;
2559
2788
  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;
2560
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2561
- while (1) switch (_context20.prev = _context20.next) {
2789
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2790
+ while (1) switch (_context23.prev = _context23.next) {
2562
2791
  case 0:
2563
2792
  storeOrderCountBefore = this.store.list.length;
2564
2793
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2570,20 +2799,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2570
2799
  normalizedFreshOrders = [];
2571
2800
  incomingProductsHaveStableIdentity = new Map();
2572
2801
  _iterator15 = _createForOfIteratorHelper(freshOrders);
2573
- _context20.prev = 6;
2802
+ _context23.prev = 6;
2574
2803
  _iterator15.s();
2575
2804
  case 8:
2576
2805
  if ((_step15 = _iterator15.n()).done) {
2577
- _context20.next = 18;
2806
+ _context23.next = 18;
2578
2807
  break;
2579
2808
  }
2580
2809
  order = _step15.value;
2581
2810
  id = order === null || order === void 0 ? void 0 : order.order_id;
2582
2811
  if (!(id === undefined || id === null)) {
2583
- _context20.next = 13;
2812
+ _context23.next = 13;
2584
2813
  break;
2585
2814
  }
2586
- return _context20.abrupt("continue", 16);
2815
+ return _context23.abrupt("continue", 16);
2587
2816
  case 13:
2588
2817
  rawProducts = order.products;
2589
2818
  if (Array.isArray(rawProducts)) {
@@ -2593,19 +2822,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2593
2822
  }
2594
2823
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2595
2824
  case 16:
2596
- _context20.next = 8;
2825
+ _context23.next = 8;
2597
2826
  break;
2598
2827
  case 18:
2599
- _context20.next = 23;
2828
+ _context23.next = 23;
2600
2829
  break;
2601
2830
  case 20:
2602
- _context20.prev = 20;
2603
- _context20.t0 = _context20["catch"](6);
2604
- _iterator15.e(_context20.t0);
2831
+ _context23.prev = 20;
2832
+ _context23.t0 = _context23["catch"](6);
2833
+ _iterator15.e(_context23.t0);
2605
2834
  case 23:
2606
- _context20.prev = 23;
2835
+ _context23.prev = 23;
2607
2836
  _iterator15.f();
2608
- return _context20.finish(23);
2837
+ return _context23.finish(23);
2609
2838
  case 26:
2610
2839
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2611
2840
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
@@ -2616,10 +2845,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2616
2845
  storageKeyMigrations = [];
2617
2846
  mergeActions = {};
2618
2847
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2619
- return _this17.doProductsHaveStableMembershipIdentity(order.products);
2848
+ return _this18.doProductsHaveStableMembershipIdentity(order.products);
2620
2849
  });
2621
2850
  updatedList = this.store.list.map(function (order) {
2622
- return _this17.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2851
+ return _this18.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2623
2852
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2624
2853
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2625
2854
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
@@ -2640,11 +2869,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2640
2869
  }
2641
2870
  }
2642
2871
  _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2643
- _context20.prev = 38;
2872
+ _context23.prev = 38;
2644
2873
  _iterator17.s();
2645
2874
  case 40:
2646
2875
  if ((_step17 = _iterator17.n()).done) {
2647
- _context20.next = 100;
2876
+ _context23.next = 100;
2648
2877
  break;
2649
2878
  }
2650
2879
  fresh = _step17.value;
@@ -2653,13 +2882,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2653
2882
  storageKey = this.getOrderStorageKey(fresh);
2654
2883
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2655
2884
  if (!(matchIndex >= 0)) {
2656
- _context20.next = 92;
2885
+ _context23.next = 92;
2657
2886
  break;
2658
2887
  }
2659
2888
  existingOrder = updatedList[matchIndex];
2660
2889
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2661
2890
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2662
- _context20.next = 52;
2891
+ _context23.next = 52;
2663
2892
  break;
2664
2893
  }
2665
2894
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2672,10 +2901,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2672
2901
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2673
2902
  reason: 'protect_pending_sync_order_from_remote_echo'
2674
2903
  });
2675
- return _context20.abrupt("continue", 98);
2904
+ return _context23.abrupt("continue", 98);
2676
2905
  case 52:
2677
2906
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2678
- _context20.next = 55;
2907
+ _context23.next = 55;
2679
2908
  break;
2680
2909
  }
2681
2910
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2686,7 +2915,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2686
2915
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2687
2916
  reason: 'protect_draft_order_from_remote_echo'
2688
2917
  });
2689
- return _context20.abrupt("continue", 98);
2918
+ return _context23.abrupt("continue", 98);
2690
2919
  case 55:
2691
2920
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2692
2921
  freshOrderId = fresh.order_id;
@@ -2699,36 +2928,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2699
2928
  adjustedMatchIndex = matchIndex;
2700
2929
  duplicateIndexes = new Set();
2701
2930
  _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2702
- _context20.prev = 64;
2931
+ _context23.prev = 64;
2703
2932
  _iterator18.s();
2704
2933
  case 66:
2705
2934
  if ((_step18 = _iterator18.n()).done) {
2706
- _context20.next = 74;
2935
+ _context23.next = 74;
2707
2936
  break;
2708
2937
  }
2709
2938
  _key2 = _step18.value;
2710
2939
  _duplicateIndex = identityKeyToIndex.get(_key2);
2711
2940
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2712
- _context20.next = 71;
2941
+ _context23.next = 71;
2713
2942
  break;
2714
2943
  }
2715
- return _context20.abrupt("continue", 72);
2944
+ return _context23.abrupt("continue", 72);
2716
2945
  case 71:
2717
2946
  duplicateIndexes.add(_duplicateIndex);
2718
2947
  case 72:
2719
- _context20.next = 66;
2948
+ _context23.next = 66;
2720
2949
  break;
2721
2950
  case 74:
2722
- _context20.next = 79;
2951
+ _context23.next = 79;
2723
2952
  break;
2724
2953
  case 76:
2725
- _context20.prev = 76;
2726
- _context20.t1 = _context20["catch"](64);
2727
- _iterator18.e(_context20.t1);
2954
+ _context23.prev = 76;
2955
+ _context23.t1 = _context23["catch"](64);
2956
+ _iterator18.e(_context23.t1);
2728
2957
  case 79:
2729
- _context20.prev = 79;
2958
+ _context23.prev = 79;
2730
2959
  _iterator18.f();
2731
- return _context20.finish(79);
2960
+ return _context23.finish(79);
2732
2961
  case 82:
2733
2962
  if (duplicateIndexes.size > 0) {
2734
2963
  _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
@@ -2783,7 +3012,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2783
3012
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2784
3013
  patchedOrders.push(mergedOrder);
2785
3014
  if (mergeKey) mergeActions[mergeKey] = 'update';
2786
- return _context20.abrupt("continue", 98);
3015
+ return _context23.abrupt("continue", 98);
2787
3016
  case 92:
2788
3017
  insertIndex = updatedList.length;
2789
3018
  updatedList.push(fresh);
@@ -2792,19 +3021,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2792
3021
  patchedOrders.push(fresh);
2793
3022
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2794
3023
  case 98:
2795
- _context20.next = 40;
3024
+ _context23.next = 40;
2796
3025
  break;
2797
3026
  case 100:
2798
- _context20.next = 105;
3027
+ _context23.next = 105;
2799
3028
  break;
2800
3029
  case 102:
2801
- _context20.prev = 102;
2802
- _context20.t2 = _context20["catch"](38);
2803
- _iterator17.e(_context20.t2);
3030
+ _context23.prev = 102;
3031
+ _context23.t2 = _context23["catch"](38);
3032
+ _iterator17.e(_context23.t2);
2804
3033
  case 105:
2805
- _context20.prev = 105;
3034
+ _context23.prev = 105;
2806
3035
  _iterator17.f();
2807
- return _context20.finish(105);
3036
+ return _context23.finish(105);
2808
3037
  case 108:
2809
3038
  insertCount = Object.values(mergeActions).filter(function (v) {
2810
3039
  return v === 'insert';
@@ -2821,7 +3050,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2821
3050
  // 仅在自检开关开启时做一次兜底校验。
2822
3051
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2823
3052
  this.syncOrdersMap();
2824
- _context20.next = 115;
3053
+ _context23.next = 115;
2825
3054
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2826
3055
  storageKeyMigrations: storageKeyMigrations
2827
3056
  }, forceWriteStorageKeys);
@@ -2832,18 +3061,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2832
3061
  insertCount: insertCount,
2833
3062
  updateCount: updateCount
2834
3063
  });
2835
- _context20.next = 118;
3064
+ _context23.next = 118;
2836
3065
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2837
3066
  case 118:
2838
- _context20.next = 120;
3067
+ _context23.next = 120;
2839
3068
  return this.emitOrdersChanged(patchedOrders, source);
2840
3069
  case 120:
2841
3070
  case "end":
2842
- return _context20.stop();
3071
+ return _context23.stop();
2843
3072
  }
2844
- }, _callee20, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
3073
+ }, _callee23, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2845
3074
  }));
2846
- function mergeOrdersToStore(_x13, _x14) {
3075
+ function mergeOrdersToStore(_x16, _x17) {
2847
3076
  return _mergeOrdersToStore.apply(this, arguments);
2848
3077
  }
2849
3078
  return mergeOrdersToStore;
@@ -2923,7 +3152,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2923
3152
  }, {
2924
3153
  key: "getRemoteProductMembershipChange",
2925
3154
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2926
- var _this18 = this,
3155
+ var _this19 = this,
2927
3156
  _mergedOrder$order_id2;
2928
3157
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
2929
3158
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
@@ -2938,13 +3167,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2938
3167
  var _loop2 = function _loop2() {
2939
3168
  var previousProduct = _step22.value;
2940
3169
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2941
- return unmatchedCurrentIndexes.has(index) && _this18.isSameProductMembershipItem(previousProduct, currentProduct);
3170
+ return unmatchedCurrentIndexes.has(index) && _this19.isSameProductMembershipItem(previousProduct, currentProduct);
2942
3171
  });
2943
3172
  if (matchedIndex >= 0) {
2944
3173
  unmatchedCurrentIndexes.delete(matchedIndex);
2945
3174
  return 1; // continue
2946
3175
  }
2947
- var productKey = _this18.getProductMembershipKey(previousProduct);
3176
+ var productKey = _this19.getProductMembershipKey(previousProduct);
2948
3177
  if (productKey) removedProductKeys.push(productKey);
2949
3178
  };
2950
3179
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
@@ -2956,7 +3185,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2956
3185
  _iterator22.f();
2957
3186
  }
2958
3187
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2959
- return _this18.getProductMembershipKey(currentProducts[index]);
3188
+ return _this19.getProductMembershipKey(currentProducts[index]);
2960
3189
  }).filter(Boolean);
2961
3190
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2962
3191
  return null;
@@ -3071,12 +3300,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3071
3300
  }, {
3072
3301
  key: "isOrderLookupMatch",
3073
3302
  value: function isOrderLookupMatch(order, lookupKey) {
3074
- var _this19 = this;
3303
+ var _this20 = this;
3075
3304
  if (!order || !lookupKey) return false;
3076
3305
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
3077
3306
  return candidates.some(function (value) {
3078
3307
  if (value === undefined || value === null || value === '') return false;
3079
- return _this19.getIdKey(value) === lookupKey;
3308
+ return _this20.getIdKey(value) === lookupKey;
3080
3309
  });
3081
3310
  }
3082
3311
 
@@ -3128,10 +3357,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3128
3357
  }, {
3129
3358
  key: "findOrderIndexByIdentity",
3130
3359
  value: function findOrderIndexByIdentity(orders, target) {
3131
- var _this20 = this;
3360
+ var _this21 = this;
3132
3361
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
3133
3362
  return orders.findIndex(function (order) {
3134
- return _this20.doOrdersShareIdentity(order, target);
3363
+ return _this21.doOrdersShareIdentity(order, target);
3135
3364
  });
3136
3365
  }
3137
3366
  }, {
@@ -3254,7 +3483,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3254
3483
  }, {
3255
3484
  key: "shouldProtectLocalOrderFromRemoteSnapshot",
3256
3485
  value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
3257
- return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
3486
+ return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0 || requiresLocalPaymentRefresh(order) || (order.payments || []).some(isLocalFinalizedPayment);
3258
3487
  }
3259
3488
  }, {
3260
3489
  key: "getUnmatchedIdentifiedPendingPayments",
@@ -3283,9 +3512,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3283
3512
  var secondaryRecord = secondary;
3284
3513
  var existingRecord = existing;
3285
3514
  var incomingRecord = incoming;
3515
+ if (requiresLocalPaymentRefresh(existing)) {
3516
+ mergedRecord.metadata = _objectSpread(_objectSpread({}, mergedRecord.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
3517
+ }
3286
3518
  var childUidRemaps = [];
3287
- for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
3288
- var field = _fieldsToPreserve[_i4];
3519
+ for (var _i5 = 0, _fieldsToPreserve = fieldsToPreserve; _i5 < _fieldsToPreserve.length; _i5++) {
3520
+ var field = _fieldsToPreserve[_i5];
3289
3521
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
3290
3522
  mergedRecord[field] = preferredRecord[field];
3291
3523
  continue;
@@ -3294,8 +3526,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3294
3526
  mergedRecord[field] = secondaryRecord[field];
3295
3527
  }
3296
3528
  }
3297
- for (var _i5 = 0, _incomingPatchFields = incomingPatchFields; _i5 < _incomingPatchFields.length; _i5++) {
3298
- var _field = _incomingPatchFields[_i5];
3529
+ for (var _i6 = 0, _incomingPatchFields = incomingPatchFields; _i6 < _incomingPatchFields.length; _i6++) {
3530
+ var _field = _incomingPatchFields[_i6];
3299
3531
  if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
3300
3532
  if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
3301
3533
  if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
@@ -3310,8 +3542,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3310
3542
 
3311
3543
  // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
3312
3544
  // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
3313
- for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
3314
- var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
3545
+ for (var _i7 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i7 < _ORDER_AUTHORITATIVE_2.length; _i7++) {
3546
+ var _field2 = _ORDER_AUTHORITATIVE_2[_i7];
3315
3547
  if (Array.isArray(incomingRecord[_field2])) {
3316
3548
  if (_field2 === 'payments') {
3317
3549
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
@@ -3562,8 +3794,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3562
3794
  }, {
3563
3795
  key: "loadOrdersFromSQLite",
3564
3796
  value: function () {
3565
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3566
- var _this21 = this;
3797
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3798
+ var _this22 = this;
3567
3799
  var options,
3568
3800
  _options$onTiming,
3569
3801
  loadStartedAt,
@@ -3573,28 +3805,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3573
3805
  normalizeStartedAt,
3574
3806
  normalizedOrders,
3575
3807
  sqliteNormalizeMs,
3576
- _args21 = arguments;
3577
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3578
- while (1) switch (_context21.prev = _context21.next) {
3808
+ _args24 = arguments;
3809
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3810
+ while (1) switch (_context24.prev = _context24.next) {
3579
3811
  case 0:
3580
- options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
3812
+ options = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
3581
3813
  if (this.dbManager) {
3582
- _context21.next = 3;
3814
+ _context24.next = 3;
3583
3815
  break;
3584
3816
  }
3585
- return _context21.abrupt("return", []);
3817
+ return _context24.abrupt("return", []);
3586
3818
  case 3:
3587
- _context21.prev = 3;
3819
+ _context24.prev = 3;
3588
3820
  loadStartedAt = performance.now();
3589
3821
  rawReadStartedAt = performance.now();
3590
- _context21.next = 8;
3822
+ _context24.next = 8;
3591
3823
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3592
3824
  case 8:
3593
- orders = _context21.sent;
3825
+ orders = _context24.sent;
3594
3826
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3595
3827
  normalizeStartedAt = performance.now();
3596
3828
  normalizedOrders = (orders || []).map(function (order) {
3597
- return _this21.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3829
+ return _this22.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3598
3830
  });
3599
3831
  sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3600
3832
  (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
@@ -3602,22 +3834,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3602
3834
  sqliteNormalizeMs: sqliteNormalizeMs,
3603
3835
  sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3604
3836
  });
3605
- return _context21.abrupt("return", normalizedOrders);
3837
+ return _context24.abrupt("return", normalizedOrders);
3606
3838
  case 17:
3607
- _context21.prev = 17;
3608
- _context21.t0 = _context21["catch"](3);
3839
+ _context24.prev = 17;
3840
+ _context24.t0 = _context24["catch"](3);
3609
3841
  if (!options.throwOnError) {
3610
- _context21.next = 21;
3842
+ _context24.next = 21;
3611
3843
  break;
3612
3844
  }
3613
- throw _context21.t0;
3845
+ throw _context24.t0;
3614
3846
  case 21:
3615
- return _context21.abrupt("return", []);
3847
+ return _context24.abrupt("return", []);
3616
3848
  case 22:
3617
3849
  case "end":
3618
- return _context21.stop();
3850
+ return _context24.stop();
3619
3851
  }
3620
- }, _callee21, this, [[3, 17]]);
3852
+ }, _callee24, this, [[3, 17]]);
3621
3853
  }));
3622
3854
  function loadOrdersFromSQLite() {
3623
3855
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3656,8 +3888,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3656
3888
  value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3657
3889
  var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3658
3890
  var remote = remoteOrder;
3659
- for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
3660
- var field = _arr[_i7];
3891
+ for (var _i8 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i8 < _arr.length; _i8++) {
3892
+ var field = _arr[_i8];
3661
3893
  if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3662
3894
  merged[field] = remote[field];
3663
3895
  }
@@ -3667,9 +3899,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3667
3899
  }, {
3668
3900
  key: "mergeRemoteSnapshotWithPendingOrders",
3669
3901
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3670
- var _this22 = this;
3902
+ var _this23 = this;
3671
3903
  var merged = remoteOrders.map(function (order) {
3672
- return _this22.normalizeRemoteSyncedOrder(order);
3904
+ return _this23.normalizeRemoteSyncedOrder(order);
3673
3905
  });
3674
3906
  var _iterator32 = _createForOfIteratorHelper(existingOrders),
3675
3907
  _step32;
@@ -3709,10 +3941,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3709
3941
  }, {
3710
3942
  key: "runInOrderSQLiteSaveQueue",
3711
3943
  value: (function () {
3712
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(task) {
3944
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(task) {
3713
3945
  var queuedTask;
3714
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3715
- while (1) switch (_context22.prev = _context22.next) {
3946
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3947
+ while (1) switch (_context25.prev = _context25.next) {
3716
3948
  case 0:
3717
3949
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3718
3950
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3720,14 +3952,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3720
3952
  }, function () {
3721
3953
  return undefined;
3722
3954
  });
3723
- return _context22.abrupt("return", queuedTask);
3955
+ return _context25.abrupt("return", queuedTask);
3724
3956
  case 3:
3725
3957
  case "end":
3726
- return _context22.stop();
3958
+ return _context25.stop();
3727
3959
  }
3728
- }, _callee22, this);
3960
+ }, _callee25, this);
3729
3961
  }));
3730
- function runInOrderSQLiteSaveQueue(_x15) {
3962
+ function runInOrderSQLiteSaveQueue(_x18) {
3731
3963
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3732
3964
  }
3733
3965
  return runInOrderSQLiteSaveQueue;
@@ -3742,8 +3974,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3742
3974
  }, {
3743
3975
  key: "patchOrdersInSQLite",
3744
3976
  value: (function () {
3745
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orders, source) {
3746
- var _this23 = this;
3977
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orders, source) {
3978
+ var _this24 = this;
3747
3979
  var mergeActions,
3748
3980
  options,
3749
3981
  forceWriteStorageKeys,
@@ -3758,264 +3990,264 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3758
3990
  _iterator33,
3759
3991
  _step33,
3760
3992
  migration,
3761
- _args24 = arguments;
3762
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3763
- while (1) switch (_context24.prev = _context24.next) {
3993
+ _args27 = arguments;
3994
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3995
+ while (1) switch (_context27.prev = _context27.next) {
3764
3996
  case 0:
3765
- mergeActions = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3766
- options = _args24.length > 3 && _args24[3] !== undefined ? _args24[3] : {};
3767
- forceWriteStorageKeys = _args24.length > 4 && _args24[4] !== undefined ? _args24[4] : new Set();
3997
+ mergeActions = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : {};
3998
+ options = _args27.length > 3 && _args27[3] !== undefined ? _args27[3] : {};
3999
+ forceWriteStorageKeys = _args27.length > 4 && _args27[4] !== undefined ? _args27[4] : new Set();
3768
4000
  if (!(orders.length === 0)) {
3769
- _context24.next = 5;
4001
+ _context27.next = 5;
3770
4002
  break;
3771
4003
  }
3772
- return _context24.abrupt("return");
4004
+ return _context27.abrupt("return");
3773
4005
  case 5:
3774
4006
  if (this.dbManager) {
3775
- _context24.next = 9;
4007
+ _context27.next = 9;
3776
4008
  break;
3777
4009
  }
3778
4010
  if (!options.throwOnError) {
3779
- _context24.next = 8;
4011
+ _context27.next = 8;
3780
4012
  break;
3781
4013
  }
3782
4014
  throw new Error('订单 SQLite 数据库未初始化');
3783
4015
  case 8:
3784
- return _context24.abrupt("return");
4016
+ return _context27.abrupt("return");
3785
4017
  case 9:
3786
4018
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3787
4019
  return migration.to;
3788
4020
  }));
3789
4021
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3790
- return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4022
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3791
4023
  }).map(function (order) {
3792
- var storageKey = _this23.getOrderStorageKey(order);
4024
+ var storageKey = _this24.getOrderStorageKey(order);
3793
4025
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
3794
4026
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
3795
4027
  }).filter(function (order) {
3796
- return _this23.getOrderStorageKey(order);
4028
+ return _this24.getOrderStorageKey(order);
3797
4029
  });
3798
4030
  if (!(ordersSnapshot.length === 0)) {
3799
- _context24.next = 13;
4031
+ _context27.next = 13;
3800
4032
  break;
3801
4033
  }
3802
- return _context24.abrupt("return");
4034
+ return _context27.abrupt("return");
3803
4035
  case 13:
3804
4036
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3805
4037
  if (!(toWrite.length === 0)) {
3806
- _context24.next = 16;
4038
+ _context27.next = 16;
3807
4039
  break;
3808
4040
  }
3809
- return _context24.abrupt("return");
4041
+ return _context27.abrupt("return");
3810
4042
  case 16:
3811
4043
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3812
4044
  if (!(compactedToWrite.length === 0)) {
3813
- _context24.next = 19;
4045
+ _context27.next = 19;
3814
4046
  break;
3815
4047
  }
3816
- return _context24.abrupt("return");
4048
+ return _context27.abrupt("return");
3817
4049
  case 19:
3818
4050
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3819
- return _this23.getOrderStorageKey(order);
4051
+ return _this24.getOrderStorageKey(order);
3820
4052
  }).filter(Boolean));
3821
4053
  storageKeyMigrations = new Map();
3822
4054
  _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3823
- _context24.prev = 22;
4055
+ _context27.prev = 22;
3824
4056
  _iterator33.s();
3825
4057
  case 24:
3826
4058
  if ((_step33 = _iterator33.n()).done) {
3827
- _context24.next = 33;
4059
+ _context27.next = 33;
3828
4060
  break;
3829
4061
  }
3830
4062
  migration = _step33.value;
3831
4063
  if (writtenStorageKeys.has(migration.to)) {
3832
- _context24.next = 28;
4064
+ _context27.next = 28;
3833
4065
  break;
3834
4066
  }
3835
- return _context24.abrupt("continue", 31);
4067
+ return _context27.abrupt("continue", 31);
3836
4068
  case 28:
3837
4069
  if (!writtenStorageKeys.has(migration.from)) {
3838
- _context24.next = 30;
4070
+ _context27.next = 30;
3839
4071
  break;
3840
4072
  }
3841
- return _context24.abrupt("continue", 31);
4073
+ return _context27.abrupt("continue", 31);
3842
4074
  case 30:
3843
4075
  storageKeyMigrations.set(migration.from, migration);
3844
4076
  case 31:
3845
- _context24.next = 24;
4077
+ _context27.next = 24;
3846
4078
  break;
3847
4079
  case 33:
3848
- _context24.next = 38;
4080
+ _context27.next = 38;
3849
4081
  break;
3850
4082
  case 35:
3851
- _context24.prev = 35;
3852
- _context24.t0 = _context24["catch"](22);
3853
- _iterator33.e(_context24.t0);
4083
+ _context27.prev = 35;
4084
+ _context27.t0 = _context27["catch"](22);
4085
+ _iterator33.e(_context27.t0);
3854
4086
  case 38:
3855
- _context24.prev = 38;
4087
+ _context27.prev = 38;
3856
4088
  _iterator33.f();
3857
- return _context24.finish(38);
4089
+ return _context27.finish(38);
3858
4090
  case 41:
3859
- _context24.prev = 41;
3860
- _context24.next = 44;
3861
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
4091
+ _context27.prev = 41;
4092
+ _context27.next = 44;
4093
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3862
4094
  var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
3863
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3864
- while (1) switch (_context23.prev = _context23.next) {
4095
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4096
+ while (1) switch (_context26.prev = _context26.next) {
3865
4097
  case 0:
3866
4098
  writeMethod = 'none';
3867
- _this23.logInfo('patchOrdersInSQLite-开始', {
4099
+ _this24.logInfo('patchOrdersInSQLite-开始', {
3868
4100
  source: source,
3869
4101
  count: compactedToWrite.length,
3870
4102
  dedupedCount: skipped.length
3871
4103
  });
3872
- if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3873
- _context23.next = 8;
4104
+ if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4105
+ _context26.next = 8;
3874
4106
  break;
3875
4107
  }
3876
4108
  writeMethod = 'bulkUpdate';
3877
- _context23.next = 6;
3878
- return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4109
+ _context26.next = 6;
4110
+ return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3879
4111
  case 6:
3880
- _context23.next = 37;
4112
+ _context26.next = 37;
3881
4113
  break;
3882
4114
  case 8:
3883
- if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3884
- _context23.next = 14;
4115
+ if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4116
+ _context26.next = 14;
3885
4117
  break;
3886
4118
  }
3887
4119
  writeMethod = 'bulkAdd';
3888
- _context23.next = 12;
3889
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4120
+ _context26.next = 12;
4121
+ return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3890
4122
  case 12:
3891
- _context23.next = 37;
4123
+ _context26.next = 37;
3892
4124
  break;
3893
4125
  case 14:
3894
- if (!(typeof _this23.dbManager.update === 'function')) {
3895
- _context23.next = 35;
4126
+ if (!(typeof _this24.dbManager.update === 'function')) {
4127
+ _context26.next = 35;
3896
4128
  break;
3897
4129
  }
3898
4130
  writeMethod = 'update';
3899
4131
  _iterator34 = _createForOfIteratorHelper(compactedToWrite);
3900
- _context23.prev = 17;
4132
+ _context26.prev = 17;
3901
4133
  _iterator34.s();
3902
4134
  case 19:
3903
4135
  if ((_step34 = _iterator34.n()).done) {
3904
- _context23.next = 25;
4136
+ _context26.next = 25;
3905
4137
  break;
3906
4138
  }
3907
4139
  order = _step34.value;
3908
- _context23.next = 23;
3909
- return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
4140
+ _context26.next = 23;
4141
+ return _this24.dbManager.update(INDEXDB_STORE_NAME, order);
3910
4142
  case 23:
3911
- _context23.next = 19;
4143
+ _context26.next = 19;
3912
4144
  break;
3913
4145
  case 25:
3914
- _context23.next = 30;
4146
+ _context26.next = 30;
3915
4147
  break;
3916
4148
  case 27:
3917
- _context23.prev = 27;
3918
- _context23.t0 = _context23["catch"](17);
3919
- _iterator34.e(_context23.t0);
4149
+ _context26.prev = 27;
4150
+ _context26.t0 = _context26["catch"](17);
4151
+ _iterator34.e(_context26.t0);
3920
4152
  case 30:
3921
- _context23.prev = 30;
4153
+ _context26.prev = 30;
3922
4154
  _iterator34.f();
3923
- return _context23.finish(30);
4155
+ return _context26.finish(30);
3924
4156
  case 33:
3925
- _context23.next = 37;
4157
+ _context26.next = 37;
3926
4158
  break;
3927
4159
  case 35:
3928
4160
  if (!options.throwOnError) {
3929
- _context23.next = 37;
4161
+ _context26.next = 37;
3930
4162
  break;
3931
4163
  }
3932
4164
  throw new Error('订单 SQLite 数据库不支持写入');
3933
4165
  case 37:
3934
- _this23.recordRecentSqliteWrite(source, compactedToWrite);
4166
+ _this24.recordRecentSqliteWrite(source, compactedToWrite);
3935
4167
  if (!(writeMethod !== 'none')) {
3936
- _context23.next = 84;
4168
+ _context26.next = 84;
3937
4169
  break;
3938
4170
  }
3939
4171
  _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
3940
- _context23.prev = 40;
4172
+ _context26.prev = 40;
3941
4173
  _iterator35.s();
3942
4174
  case 42:
3943
4175
  if ((_step35 = _iterator35.n()).done) {
3944
- _context23.next = 76;
4176
+ _context26.next = 76;
3945
4177
  break;
3946
4178
  }
3947
4179
  migration = _step35.value;
3948
- _context23.prev = 44;
3949
- _context23.next = 47;
3950
- return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4180
+ _context26.prev = 44;
4181
+ _context26.next = 47;
4182
+ return _this24.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3951
4183
  case 47:
3952
- _this23.recentSqliteWriteByStorageKey.delete(migration.from);
4184
+ _this24.recentSqliteWriteByStorageKey.delete(migration.from);
3953
4185
  _iterator36 = _createForOfIteratorHelper(orders);
3954
- _context23.prev = 49;
4186
+ _context26.prev = 49;
3955
4187
  _iterator36.s();
3956
4188
  case 51:
3957
4189
  if ((_step36 = _iterator36.n()).done) {
3958
- _context23.next = 61;
4190
+ _context26.next = 61;
3959
4191
  break;
3960
4192
  }
3961
4193
  _order = _step36.value;
3962
- if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
3963
- _context23.next = 55;
4194
+ if (!(_this24.getOrderStorageKey(_order) !== migration.to)) {
4195
+ _context26.next = 55;
3964
4196
  break;
3965
4197
  }
3966
- return _context23.abrupt("continue", 59);
4198
+ return _context26.abrupt("continue", 59);
3967
4199
  case 55:
3968
4200
  orderRecord = _order;
3969
4201
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
3970
- _context23.next = 58;
4202
+ _context26.next = 58;
3971
4203
  break;
3972
4204
  }
3973
- return _context23.abrupt("continue", 59);
4205
+ return _context26.abrupt("continue", 59);
3974
4206
  case 58:
3975
4207
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
3976
4208
  case 59:
3977
- _context23.next = 51;
4209
+ _context26.next = 51;
3978
4210
  break;
3979
4211
  case 61:
3980
- _context23.next = 66;
4212
+ _context26.next = 66;
3981
4213
  break;
3982
4214
  case 63:
3983
- _context23.prev = 63;
3984
- _context23.t1 = _context23["catch"](49);
3985
- _iterator36.e(_context23.t1);
4215
+ _context26.prev = 63;
4216
+ _context26.t1 = _context26["catch"](49);
4217
+ _iterator36.e(_context26.t1);
3986
4218
  case 66:
3987
- _context23.prev = 66;
4219
+ _context26.prev = 66;
3988
4220
  _iterator36.f();
3989
- return _context23.finish(66);
4221
+ return _context26.finish(66);
3990
4222
  case 69:
3991
- _context23.next = 74;
4223
+ _context26.next = 74;
3992
4224
  break;
3993
4225
  case 71:
3994
- _context23.prev = 71;
3995
- _context23.t2 = _context23["catch"](44);
3996
- _this23.logError('删除订单旧 SQLite storage key 失败', {
4226
+ _context26.prev = 71;
4227
+ _context26.t2 = _context26["catch"](44);
4228
+ _this24.logError('删除订单旧 SQLite storage key 失败', {
3997
4229
  source: source,
3998
4230
  order_id: migration.orderId,
3999
4231
  oldStorageKey: migration.from,
4000
4232
  newStorageKey: migration.to,
4001
- error: _context23.t2 instanceof Error ? _context23.t2.message : String(_context23.t2)
4233
+ error: _context26.t2 instanceof Error ? _context26.t2.message : String(_context26.t2)
4002
4234
  });
4003
4235
  case 74:
4004
- _context23.next = 42;
4236
+ _context26.next = 42;
4005
4237
  break;
4006
4238
  case 76:
4007
- _context23.next = 81;
4239
+ _context26.next = 81;
4008
4240
  break;
4009
4241
  case 78:
4010
- _context23.prev = 78;
4011
- _context23.t3 = _context23["catch"](40);
4012
- _iterator35.e(_context23.t3);
4242
+ _context26.prev = 78;
4243
+ _context26.t3 = _context26["catch"](40);
4244
+ _iterator35.e(_context26.t3);
4013
4245
  case 81:
4014
- _context23.prev = 81;
4246
+ _context26.prev = 81;
4015
4247
  _iterator35.f();
4016
- return _context23.finish(81);
4248
+ return _context26.finish(81);
4017
4249
  case 84:
4018
- _this23.logInfo('patchOrdersInSQLite-完成', {
4250
+ _this24.logInfo('patchOrdersInSQLite-完成', {
4019
4251
  source: source,
4020
4252
  count: compactedToWrite.length,
4021
4253
  writeMethod: writeMethod,
@@ -4023,32 +4255,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4023
4255
  });
4024
4256
  case 85:
4025
4257
  case "end":
4026
- return _context23.stop();
4258
+ return _context26.stop();
4027
4259
  }
4028
- }, _callee23, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4260
+ }, _callee26, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4029
4261
  })));
4030
4262
  case 44:
4031
- _context24.next = 51;
4263
+ _context27.next = 51;
4032
4264
  break;
4033
4265
  case 46:
4034
- _context24.prev = 46;
4035
- _context24.t1 = _context24["catch"](41);
4266
+ _context27.prev = 46;
4267
+ _context27.t1 = _context27["catch"](41);
4036
4268
  this.logError('增量保存订单到 SQLite 失败', {
4037
- error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4269
+ error: _context27.t1 instanceof Error ? _context27.t1.message : String(_context27.t1),
4038
4270
  orderCount: ordersSnapshot.length
4039
4271
  });
4040
4272
  if (!options.throwOnError) {
4041
- _context24.next = 51;
4273
+ _context27.next = 51;
4042
4274
  break;
4043
4275
  }
4044
- throw _context24.t1;
4276
+ throw _context27.t1;
4045
4277
  case 51:
4046
4278
  case "end":
4047
- return _context24.stop();
4279
+ return _context27.stop();
4048
4280
  }
4049
- }, _callee24, this, [[22, 35, 38, 41], [41, 46]]);
4281
+ }, _callee27, this, [[22, 35, 38, 41], [41, 46]]);
4050
4282
  }));
4051
- function patchOrdersInSQLite(_x16, _x17) {
4283
+ function patchOrdersInSQLite(_x19, _x20) {
4052
4284
  return _patchOrdersInSQLite.apply(this, arguments);
4053
4285
  }
4054
4286
  return patchOrdersInSQLite;
@@ -4063,128 +4295,128 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4063
4295
  }, {
4064
4296
  key: "updateOrderInSQLite",
4065
4297
  value: (function () {
4066
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order, source) {
4067
- var _this24 = this;
4298
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order, source) {
4299
+ var _this25 = this;
4068
4300
  var options,
4069
4301
  orderSnapshot,
4070
4302
  _orderSnapshot$order_3,
4071
- _args26 = arguments;
4072
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4073
- while (1) switch (_context26.prev = _context26.next) {
4303
+ _args29 = arguments;
4304
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4305
+ while (1) switch (_context29.prev = _context29.next) {
4074
4306
  case 0:
4075
- options = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
4307
+ options = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4076
4308
  if (this.getOrderStorageKey(order)) {
4077
- _context26.next = 5;
4309
+ _context29.next = 5;
4078
4310
  break;
4079
4311
  }
4080
4312
  if (!options.throwOnError) {
4081
- _context26.next = 4;
4313
+ _context29.next = 4;
4082
4314
  break;
4083
4315
  }
4084
4316
  throw new Error('订单缺少可用的 SQLite 存储主键');
4085
4317
  case 4:
4086
- return _context26.abrupt("return");
4318
+ return _context29.abrupt("return");
4087
4319
  case 5:
4088
4320
  if (this.dbManager) {
4089
- _context26.next = 9;
4321
+ _context29.next = 9;
4090
4322
  break;
4091
4323
  }
4092
4324
  if (!options.throwOnError) {
4093
- _context26.next = 8;
4325
+ _context29.next = 8;
4094
4326
  break;
4095
4327
  }
4096
4328
  throw new Error('订单 SQLite 数据库未初始化');
4097
4329
  case 8:
4098
- return _context26.abrupt("return");
4330
+ return _context29.abrupt("return");
4099
4331
  case 9:
4100
4332
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4101
- _context26.prev = 10;
4102
- _context26.next = 13;
4103
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4333
+ _context29.prev = 10;
4334
+ _context29.next = 13;
4335
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4104
4336
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4105
4337
  var writeMethod;
4106
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4107
- while (1) switch (_context25.prev = _context25.next) {
4338
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4339
+ while (1) switch (_context28.prev = _context28.next) {
4108
4340
  case 0:
4109
4341
  writeMethod = 'none';
4110
- _this24.logInfo('updateOrderInSQLite-开始', {
4342
+ _this25.logInfo('updateOrderInSQLite-开始', {
4111
4343
  source: source,
4112
4344
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
4113
- storageKey: _this24.getOrderStorageKey(orderSnapshot)
4345
+ storageKey: _this25.getOrderStorageKey(orderSnapshot)
4114
4346
  });
4115
- if (!(typeof _this24.dbManager.update === 'function')) {
4116
- _context25.next = 8;
4347
+ if (!(typeof _this25.dbManager.update === 'function')) {
4348
+ _context28.next = 8;
4117
4349
  break;
4118
4350
  }
4119
4351
  writeMethod = 'update';
4120
- _context25.next = 6;
4121
- return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4352
+ _context28.next = 6;
4353
+ return _this25.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4122
4354
  case 6:
4123
- _context25.next = 22;
4355
+ _context28.next = 22;
4124
4356
  break;
4125
4357
  case 8:
4126
- if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4127
- _context25.next = 14;
4358
+ if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4359
+ _context28.next = 14;
4128
4360
  break;
4129
4361
  }
4130
4362
  writeMethod = 'bulkUpdate';
4131
- _context25.next = 12;
4132
- return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4363
+ _context28.next = 12;
4364
+ return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4133
4365
  case 12:
4134
- _context25.next = 22;
4366
+ _context28.next = 22;
4135
4367
  break;
4136
4368
  case 14:
4137
- if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4138
- _context25.next = 20;
4369
+ if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4370
+ _context28.next = 20;
4139
4371
  break;
4140
4372
  }
4141
4373
  writeMethod = 'bulkAdd';
4142
- _context25.next = 18;
4143
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4374
+ _context28.next = 18;
4375
+ return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4144
4376
  case 18:
4145
- _context25.next = 22;
4377
+ _context28.next = 22;
4146
4378
  break;
4147
4379
  case 20:
4148
4380
  if (!options.throwOnError) {
4149
- _context25.next = 22;
4381
+ _context28.next = 22;
4150
4382
  break;
4151
4383
  }
4152
4384
  throw new Error('订单 SQLite 数据库不支持写入');
4153
4385
  case 22:
4154
- _this24.recordRecentSqliteWrite(source, [orderSnapshot]);
4155
- _this24.logInfo('updateOrderInSQLite-完成', {
4386
+ _this25.recordRecentSqliteWrite(source, [orderSnapshot]);
4387
+ _this25.logInfo('updateOrderInSQLite-完成', {
4156
4388
  source: source,
4157
4389
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
4158
4390
  writeMethod: writeMethod
4159
4391
  });
4160
4392
  case 24:
4161
4393
  case "end":
4162
- return _context25.stop();
4394
+ return _context28.stop();
4163
4395
  }
4164
- }, _callee25);
4396
+ }, _callee28);
4165
4397
  })));
4166
4398
  case 13:
4167
- _context26.next = 20;
4399
+ _context29.next = 20;
4168
4400
  break;
4169
4401
  case 15:
4170
- _context26.prev = 15;
4171
- _context26.t0 = _context26["catch"](10);
4402
+ _context29.prev = 15;
4403
+ _context29.t0 = _context29["catch"](10);
4172
4404
  this.logError('单条保存订单到 SQLite 失败', {
4173
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
4405
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0),
4174
4406
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4175
4407
  });
4176
4408
  if (!options.throwOnError) {
4177
- _context26.next = 20;
4409
+ _context29.next = 20;
4178
4410
  break;
4179
4411
  }
4180
- throw _context26.t0;
4412
+ throw _context29.t0;
4181
4413
  case 20:
4182
4414
  case "end":
4183
- return _context26.stop();
4415
+ return _context29.stop();
4184
4416
  }
4185
- }, _callee26, this, [[10, 15]]);
4417
+ }, _callee29, this, [[10, 15]]);
4186
4418
  }));
4187
- function updateOrderInSQLite(_x18, _x19) {
4419
+ function updateOrderInSQLite(_x21, _x22) {
4188
4420
  return _updateOrderInSQLite.apply(this, arguments);
4189
4421
  }
4190
4422
  return updateOrderInSQLite;
@@ -4200,75 +4432,75 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4200
4432
  }, {
4201
4433
  key: "replaceOrdersSnapshotInSQLite",
4202
4434
  value: (function () {
4203
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(orderList, source) {
4204
- var _this25 = this;
4435
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderList, source) {
4436
+ var _this26 = this;
4205
4437
  var protectedOrdersBeforeRemoteFetch,
4206
4438
  remoteSnapshot,
4207
4439
  mergedSnapshot,
4208
4440
  persisted,
4209
- _args28 = arguments;
4210
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4211
- while (1) switch (_context28.prev = _context28.next) {
4441
+ _args31 = arguments;
4442
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4443
+ while (1) switch (_context31.prev = _context31.next) {
4212
4444
  case 0:
4213
- protectedOrdersBeforeRemoteFetch = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : [];
4445
+ protectedOrdersBeforeRemoteFetch = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : [];
4214
4446
  if (this.dbManager) {
4215
- _context28.next = 3;
4447
+ _context31.next = 3;
4216
4448
  break;
4217
4449
  }
4218
- return _context28.abrupt("return", {
4450
+ return _context31.abrupt("return", {
4219
4451
  orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4220
- return _this25.normalizeRemoteSyncedOrder(order);
4452
+ return _this26.normalizeRemoteSyncedOrder(order);
4221
4453
  }), "".concat(source, ".snapshotNoDb")).list,
4222
4454
  persisted: false
4223
4455
  });
4224
4456
  case 3:
4225
4457
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
4226
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4458
+ return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4227
4459
  });
4228
4460
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
4229
- return _this25.normalizeRemoteSyncedOrder(order);
4461
+ return _this26.normalizeRemoteSyncedOrder(order);
4230
4462
  }), "".concat(source, ".remoteSnapshot")).list;
4231
4463
  persisted = false;
4232
- _context28.prev = 6;
4233
- _context28.next = 9;
4234
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4464
+ _context31.prev = 6;
4465
+ _context31.next = 9;
4466
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4235
4467
  var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4236
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4237
- while (1) switch (_context27.prev = _context27.next) {
4468
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4469
+ while (1) switch (_context30.prev = _context30.next) {
4238
4470
  case 0:
4239
- if (!(typeof _this25.dbManager.getAll === 'function')) {
4240
- _context27.next = 6;
4471
+ if (!(typeof _this26.dbManager.getAll === 'function')) {
4472
+ _context30.next = 6;
4241
4473
  break;
4242
4474
  }
4243
- _context27.next = 3;
4244
- return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
4475
+ _context30.next = 3;
4476
+ return _this26.dbManager.getAll(INDEXDB_STORE_NAME);
4245
4477
  case 3:
4246
- _context27.t0 = _context27.sent;
4247
- _context27.next = 7;
4478
+ _context30.t0 = _context30.sent;
4479
+ _context30.next = 7;
4248
4480
  break;
4249
4481
  case 6:
4250
- _context27.t0 = [];
4482
+ _context30.t0 = [];
4251
4483
  case 7:
4252
- existingOrders = _context27.t0;
4484
+ existingOrders = _context30.t0;
4253
4485
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4254
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4486
+ return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4255
4487
  }).filter(function (order) {
4256
- return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
4488
+ return _this26.shouldProtectLocalOrderFromRemoteSnapshot(order);
4257
4489
  });
4258
4490
  _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4259
- _context27.prev = 10;
4491
+ _context30.prev = 10;
4260
4492
  _iterator37.s();
4261
4493
  case 12:
4262
4494
  if ((_step37 = _iterator37.n()).done) {
4263
- _context27.next = 23;
4495
+ _context30.next = 23;
4264
4496
  break;
4265
4497
  }
4266
4498
  rawCurrentOrder = _step37.value;
4267
- currentOrder = _this25.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4268
- protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4269
- currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4499
+ currentOrder = _this26.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4500
+ protectedIndex = _this26.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4501
+ currentNeedsProtection = _this26.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4270
4502
  if (!(protectedIndex >= 0)) {
4271
- _context27.next = 20;
4503
+ _context30.next = 20;
4272
4504
  break;
4273
4505
  }
4274
4506
  if (currentNeedsProtection) {
@@ -4276,27 +4508,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4276
4508
  } else {
4277
4509
  protectedLocalOrders.splice(protectedIndex, 1);
4278
4510
  }
4279
- return _context27.abrupt("continue", 21);
4511
+ return _context30.abrupt("continue", 21);
4280
4512
  case 20:
4281
4513
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4282
4514
  case 21:
4283
- _context27.next = 12;
4515
+ _context30.next = 12;
4284
4516
  break;
4285
4517
  case 23:
4286
- _context27.next = 28;
4518
+ _context30.next = 28;
4287
4519
  break;
4288
4520
  case 25:
4289
- _context27.prev = 25;
4290
- _context27.t1 = _context27["catch"](10);
4291
- _iterator37.e(_context27.t1);
4521
+ _context30.prev = 25;
4522
+ _context30.t1 = _context30["catch"](10);
4523
+ _iterator37.e(_context30.t1);
4292
4524
  case 28:
4293
- _context27.prev = 28;
4525
+ _context30.prev = 28;
4294
4526
  _iterator37.f();
4295
- return _context27.finish(28);
4527
+ return _context30.finish(28);
4296
4528
  case 31:
4297
- orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4298
- mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4299
- _this25.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4529
+ orderListSnapshot = _this26.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4530
+ mergedSnapshot = _this26.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4531
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4300
4532
  source: source,
4301
4533
  count: mergedSnapshot.length,
4302
4534
  remoteCount: remoteSnapshot.length,
@@ -4304,10 +4536,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4304
4536
  protectedLocalOrderCount: protectedLocalOrders.length,
4305
4537
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4306
4538
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4307
- return count + _this25.getIdentifiedPendingPayments(order).length;
4539
+ return count + _this26.getIdentifiedPendingPayments(order).length;
4308
4540
  }, 0),
4309
4541
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4310
- return _this25.getIdentifiedPendingPayments(order).map(function (payment) {
4542
+ return _this26.getIdentifiedPendingPayments(order).map(function (payment) {
4311
4543
  var _order$order_id5, _external_sale_number5;
4312
4544
  return {
4313
4545
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4317,55 +4549,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4317
4549
  });
4318
4550
  })
4319
4551
  });
4320
- _context27.next = 36;
4321
- return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4552
+ _context30.next = 36;
4553
+ return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4322
4554
  case 36:
4323
- _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4555
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4324
4556
  count: mergedSnapshot.length
4325
4557
  });
4326
4558
  if (!(mergedSnapshot.length === 0)) {
4327
- _context27.next = 39;
4559
+ _context30.next = 39;
4328
4560
  break;
4329
4561
  }
4330
- return _context27.abrupt("return");
4562
+ return _context30.abrupt("return");
4331
4563
  case 39:
4332
- _context27.next = 41;
4333
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4564
+ _context30.next = 41;
4565
+ return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4334
4566
  case 41:
4335
- _this25.recordRecentSqliteWrite(source, mergedSnapshot);
4336
- _this25.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4567
+ _this26.recordRecentSqliteWrite(source, mergedSnapshot);
4568
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4337
4569
  source: source,
4338
4570
  count: mergedSnapshot.length
4339
4571
  });
4340
4572
  case 43:
4341
4573
  case "end":
4342
- return _context27.stop();
4574
+ return _context30.stop();
4343
4575
  }
4344
- }, _callee27, null, [[10, 25, 28, 31]]);
4576
+ }, _callee30, null, [[10, 25, 28, 31]]);
4345
4577
  })));
4346
4578
  case 9:
4347
4579
  persisted = true;
4348
- _context28.next = 15;
4580
+ _context31.next = 15;
4349
4581
  break;
4350
4582
  case 12:
4351
- _context28.prev = 12;
4352
- _context28.t0 = _context28["catch"](6);
4583
+ _context31.prev = 12;
4584
+ _context31.t0 = _context31["catch"](6);
4353
4585
  this.logError('全量保存订单到 SQLite 失败', {
4354
- error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4586
+ error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4355
4587
  orderList: remoteSnapshot.length
4356
4588
  });
4357
4589
  case 15:
4358
- return _context28.abrupt("return", {
4590
+ return _context31.abrupt("return", {
4359
4591
  orders: mergedSnapshot,
4360
4592
  persisted: persisted
4361
4593
  });
4362
4594
  case 16:
4363
4595
  case "end":
4364
- return _context28.stop();
4596
+ return _context31.stop();
4365
4597
  }
4366
- }, _callee28, this, [[6, 12]]);
4598
+ }, _callee31, this, [[6, 12]]);
4367
4599
  }));
4368
- function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4600
+ function replaceOrdersSnapshotInSQLite(_x23, _x24) {
4369
4601
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
4370
4602
  }
4371
4603
  return replaceOrdersSnapshotInSQLite;
@@ -4380,38 +4612,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4380
4612
  }, {
4381
4613
  key: "clear",
4382
4614
  value: (function () {
4383
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4384
- var _this26 = this;
4385
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4386
- while (1) switch (_context30.prev = _context30.next) {
4615
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4616
+ var _this27 = this;
4617
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4618
+ while (1) switch (_context33.prev = _context33.next) {
4387
4619
  case 0:
4388
4620
  this.store.list = [];
4389
4621
  this.store.map = new Map();
4390
4622
  if (!this.dbManager) {
4391
- _context30.next = 5;
4623
+ _context33.next = 5;
4392
4624
  break;
4393
4625
  }
4394
- _context30.next = 5;
4395
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4396
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4397
- while (1) switch (_context29.prev = _context29.next) {
4626
+ _context33.next = 5;
4627
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4628
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4629
+ while (1) switch (_context32.prev = _context32.next) {
4398
4630
  case 0:
4399
- _context29.next = 2;
4400
- return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4631
+ _context32.next = 2;
4632
+ return _this27.dbManager.clear(INDEXDB_STORE_NAME);
4401
4633
  case 2:
4402
4634
  case "end":
4403
- return _context29.stop();
4635
+ return _context32.stop();
4404
4636
  }
4405
- }, _callee29);
4637
+ }, _callee32);
4406
4638
  })));
4407
4639
  case 5:
4408
4640
  this.clearOrderSnapshotMarker();
4409
4641
  this.emitOrdersChanged([], 'clear');
4410
4642
  case 7:
4411
4643
  case "end":
4412
- return _context30.stop();
4644
+ return _context33.stop();
4413
4645
  }
4414
- }, _callee30, this);
4646
+ }, _callee33, this);
4415
4647
  }));
4416
4648
  function clear() {
4417
4649
  return _clear.apply(this, arguments);