@pisell/pisellos 2.2.314 → 2.2.316

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