@pisell/pisellos 2.2.264 → 2.2.265

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 (152) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  14. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  15. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  16. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  17. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  18. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  19. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  20. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  21. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  22. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  23. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
  24. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  25. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  26. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  27. package/dist/modules/Discount/index.d.ts +5 -2
  28. package/dist/modules/Discount/index.js +30 -7
  29. package/dist/modules/Discount/types.d.ts +4 -0
  30. package/dist/modules/Order/index.d.ts +41 -10
  31. package/dist/modules/Order/index.js +1370 -808
  32. package/dist/modules/Order/payment-utils.d.ts +26 -0
  33. package/dist/modules/Order/payment-utils.js +225 -0
  34. package/dist/modules/Order/types.d.ts +49 -1
  35. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/dist/modules/Order/utils/orderCollectionIdentity.js +410 -0
  37. package/dist/modules/Order/utils.d.ts +4 -3
  38. package/dist/modules/Order/utils.js +62 -66
  39. package/dist/modules/Payment/index.d.ts +2 -0
  40. package/dist/modules/Payment/index.js +78 -49
  41. package/dist/modules/Payment/types.d.ts +26 -24
  42. package/dist/modules/Payment/types.js +2 -0
  43. package/dist/modules/Product/types.d.ts +22 -0
  44. package/dist/modules/ProductList/index.d.ts +1 -1
  45. package/dist/modules/ProductList/index.js +4 -2
  46. package/dist/modules/ProductList/types.d.ts +2 -0
  47. package/dist/modules/Rules/index.d.ts +2 -9
  48. package/dist/modules/Rules/index.js +69 -43
  49. package/dist/modules/Rules/types.d.ts +10 -1
  50. package/dist/server/index.d.ts +71 -0
  51. package/dist/server/index.js +2504 -1187
  52. package/dist/server/modules/order/index.d.ts +56 -5
  53. package/dist/server/modules/order/index.js +1718 -834
  54. package/dist/server/modules/order/types.d.ts +15 -3
  55. package/dist/server/modules/order/types.js +1 -1
  56. package/dist/server/modules/products/index.d.ts +31 -8
  57. package/dist/server/modules/products/index.js +549 -390
  58. package/dist/server/modules/products/types.d.ts +18 -0
  59. package/dist/solution/BaseSales/index.d.ts +54 -4
  60. package/dist/solution/BaseSales/index.js +1448 -788
  61. package/dist/solution/BaseSales/types.d.ts +6 -1
  62. package/dist/solution/BaseSales/types.js +1 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +50 -97
  65. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  66. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
  68. package/dist/solution/BookingByStep/index.d.ts +1 -1
  69. package/dist/solution/BookingTicket/index.js +61 -26
  70. package/dist/solution/BookingTicket/types.d.ts +2 -0
  71. package/dist/solution/Sales/index.d.ts +1 -0
  72. package/dist/solution/Sales/index.js +10 -2
  73. package/dist/solution/ScanOrder/index.js +20 -31
  74. package/dist/solution/ShopDiscount/index.js +15 -14
  75. package/dist/solution/VenueBooking/index.js +19 -30
  76. package/dist/utils/payment-number.d.ts +9 -0
  77. package/dist/utils/payment-number.js +69 -0
  78. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  79. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  80. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  81. package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
  82. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  83. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  84. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  85. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  86. package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  87. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  88. package/lib/model/strategy/adapter/index.d.ts +4 -0
  89. package/lib/model/strategy/adapter/index.js +13 -2
  90. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  91. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  92. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  93. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  94. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  95. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  96. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  97. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  98. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  99. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  100. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
  101. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  102. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  103. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  104. package/lib/modules/Discount/index.d.ts +5 -2
  105. package/lib/modules/Discount/index.js +23 -3
  106. package/lib/modules/Discount/types.d.ts +4 -0
  107. package/lib/modules/Order/index.d.ts +41 -10
  108. package/lib/modules/Order/index.js +505 -119
  109. package/lib/modules/Order/payment-utils.d.ts +26 -0
  110. package/lib/modules/Order/payment-utils.js +224 -0
  111. package/lib/modules/Order/types.d.ts +49 -1
  112. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  113. package/lib/modules/Order/utils/orderCollectionIdentity.js +418 -0
  114. package/lib/modules/Order/utils.d.ts +4 -3
  115. package/lib/modules/Order/utils.js +27 -26
  116. package/lib/modules/Payment/index.d.ts +2 -0
  117. package/lib/modules/Payment/index.js +33 -12
  118. package/lib/modules/Payment/types.d.ts +26 -24
  119. package/lib/modules/Product/types.d.ts +22 -0
  120. package/lib/modules/ProductList/index.d.ts +1 -1
  121. package/lib/modules/ProductList/index.js +4 -2
  122. package/lib/modules/ProductList/types.d.ts +2 -0
  123. package/lib/modules/Rules/index.d.ts +2 -9
  124. package/lib/modules/Rules/index.js +61 -29
  125. package/lib/modules/Rules/types.d.ts +10 -1
  126. package/lib/server/index.d.ts +71 -0
  127. package/lib/server/index.js +1002 -52
  128. package/lib/server/modules/order/index.d.ts +56 -5
  129. package/lib/server/modules/order/index.js +798 -148
  130. package/lib/server/modules/order/types.d.ts +15 -3
  131. package/lib/server/modules/products/index.d.ts +31 -8
  132. package/lib/server/modules/products/index.js +134 -35
  133. package/lib/server/modules/products/types.d.ts +18 -0
  134. package/lib/solution/BaseSales/index.d.ts +54 -4
  135. package/lib/solution/BaseSales/index.js +475 -50
  136. package/lib/solution/BaseSales/types.d.ts +6 -1
  137. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  138. package/lib/solution/BaseSales/utils/cartPromotion.js +25 -64
  139. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  140. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  141. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
  142. package/lib/solution/BookingByStep/index.d.ts +1 -1
  143. package/lib/solution/BookingTicket/index.js +35 -9
  144. package/lib/solution/BookingTicket/types.d.ts +2 -0
  145. package/lib/solution/Sales/index.d.ts +1 -0
  146. package/lib/solution/Sales/index.js +5 -3
  147. package/lib/solution/ScanOrder/index.js +0 -8
  148. package/lib/solution/ShopDiscount/index.js +2 -1
  149. package/lib/solution/VenueBooking/index.js +0 -8
  150. package/lib/utils/payment-number.d.ts +9 -0
  151. package/lib/utils/payment-number.js +64 -0
  152. package/package.json +1 -1
@@ -7,11 +7,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
7
7
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
10
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
11
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
15
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
17
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -33,7 +33,9 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
33
33
  import { cloneDeep } from 'lodash-es';
34
34
  import dayjs from 'dayjs';
35
35
  import { BaseModule } from "../../../modules/BaseModule";
36
+ import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
36
37
  import { OrderHooks } from "./types";
38
+ import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
37
39
 
38
40
  /**
39
41
  * SQLite 存储名称
@@ -47,7 +49,7 @@ var ORDER_SQLITE_DEDUPE_MS = 15000;
47
49
  /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
48
50
  var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
49
51
  /** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
50
- var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
52
+ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'upsertLocalDraftOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber', 'updateLocalPayment']);
51
53
 
52
54
  /**
53
55
  * 合并热路径全表去重自检开关:默认关闭。
@@ -55,6 +57,13 @@ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPen
55
57
  * 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
56
58
  */
57
59
  var ORDER_MERGE_SELF_CHECK = false;
60
+ var PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER = '__pisell_os_pending_payment_without_unique_number__';
61
+ var ORDER_AUTHORITATIVE_COLLECTION_FIELDS = ['products', 'bookings', 'payments'];
62
+ var ORDER_COLLECTION_KIND_BY_FIELD = {
63
+ products: 'product',
64
+ bookings: 'booking',
65
+ payments: 'payment'
66
+ };
58
67
 
59
68
  /**
60
69
  * Order 模块 - 基础框架
@@ -131,8 +140,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
131
140
  key: "initialize",
132
141
  value: function () {
133
142
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
134
- var _options$initialState,
135
- _this3 = this;
143
+ var _options$initialState;
136
144
  var appPlugin, app;
137
145
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
138
146
  while (1) switch (_context2.prev = _context2.next) {
@@ -149,9 +157,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
149
157
  this.updateCreateStore();
150
158
  }
151
159
  if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
152
- this.store.list = options.initialState.list.map(function (order) {
153
- return _this3.normalizeOrderForMemoryList(order);
154
- });
160
+ this.store.list = this.normalizeOrdersForMemoryList(options.initialState.list, 'initialState');
155
161
  this.syncOrdersMap();
156
162
  this.emitOrdersChanged([], 'initialState');
157
163
  } else {
@@ -233,6 +239,134 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
233
239
  }
234
240
  }
235
241
 
242
+ /**
243
+ * 在订单进入内存或 SQLite 前统一压缩子项强身份重复并补齐协议 UID。
244
+ * 仅记录计数与订单标识,不输出商品、预约、支付或客户明细。
245
+ */
246
+ }, {
247
+ key: "normalizeOrderCollectionsForIngress",
248
+ value: function normalizeOrderCollectionsForIngress(order, source) {
249
+ var sourceOrder = cloneDeep(order);
250
+ var sourceOrderRecord = sourceOrder;
251
+ if (Array.isArray(sourceOrderRecord.payments)) {
252
+ sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
253
+ if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
254
+ return key.startsWith('unique_payment_number:');
255
+ })) {
256
+ return payment;
257
+ }
258
+ return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
259
+ });
260
+ }
261
+ var result = normalizeOrderCollections(sourceOrder);
262
+ var normalizedOrderRecord = result.order;
263
+ if (Array.isArray(normalizedOrderRecord.payments)) {
264
+ normalizedOrderRecord.payments = normalizedOrderRecord.payments.map(function (payment) {
265
+ if (!(payment !== null && payment !== void 0 && payment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER])) return payment;
266
+ var nextPayment = _objectSpread({}, payment);
267
+ var metadata = _objectSpread({}, nextPayment.metadata || {});
268
+ delete metadata.unique_payment_number;
269
+ delete nextPayment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER];
270
+ nextPayment.metadata = metadata;
271
+ return nextPayment;
272
+ });
273
+ }
274
+ var kinds = ['product', 'booking', 'payment'];
275
+ var hasChanges = kinds.some(function (kind) {
276
+ var stats = result.stats[kind];
277
+ return stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
278
+ });
279
+ if (hasChanges) {
280
+ var _order$order_id, _external_sale_number;
281
+ var summarize = function summarize(stats) {
282
+ return {
283
+ backfilled_uid_count: stats.backfilledUidCount,
284
+ collapsed_duplicate_count: stats.collapsedDuplicateCount,
285
+ uid_conflict_count: stats.uidConflictCount,
286
+ anonymous_row_count: stats.anonymousRowCount
287
+ };
288
+ };
289
+ var context = {
290
+ source: source,
291
+ order_id: (_order$order_id = order === null || order === void 0 ? void 0 : order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
292
+ external_sale_number: (_external_sale_number = order === null || order === void 0 ? void 0 : order.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : null,
293
+ products: summarize(result.stats.product),
294
+ bookings: summarize(result.stats.booking),
295
+ payments: summarize(result.stats.payment)
296
+ };
297
+ var hasUnsafeIdentity = kinds.some(function (kind) {
298
+ var stats = result.stats[kind];
299
+ return stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
300
+ });
301
+ if (hasUnsafeIdentity) {
302
+ this.logWarning('订单子项身份存在冲突或匿名行', context);
303
+ } else {
304
+ this.logInfo('订单子项身份已规范化', context);
305
+ }
306
+ }
307
+ return result.order;
308
+ }
309
+
310
+ /**
311
+ * incoming 决定权威成员集合;同一持久化行仍从 existing 补齐 incoming 省略的本地展示字段。
312
+ */
313
+ }, {
314
+ key: "mergeAuthoritativeOrderCollection",
315
+ value: function mergeAuthoritativeOrderCollection(field, existing, incoming) {
316
+ var uidRemaps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
317
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
318
+ var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
319
+ var existingItems = Array.isArray(existing) ? existing : [];
320
+ if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
321
+ return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
322
+ preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
323
+ });
324
+ }
325
+ return incoming.map(function (incomingItem) {
326
+ var existingItem = existingItems.find(function (item) {
327
+ return isSameOrderCollectionItem(kind, item, incomingItem);
328
+ });
329
+ if (!existingItem) return cloneDeep(incomingItem);
330
+ var mergedItem = mergeOrderCollectionItems(kind, existingItem, incomingItem);
331
+ var mergedUid = getOrderCollectionUid(kind, mergedItem);
332
+ if (mergedUid) {
333
+ var _iterator = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
334
+ _step;
335
+ try {
336
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
337
+ var from = _step.value;
338
+ if (!from || from === mergedUid) continue;
339
+ uidRemaps.push({
340
+ kind: kind,
341
+ from: from,
342
+ to: mergedUid,
343
+ persistentId: getOrderCollectionPersistentId(kind, incomingItem) || getOrderCollectionPersistentId(kind, existingItem)
344
+ });
345
+ }
346
+ } catch (err) {
347
+ _iterator.e(err);
348
+ } finally {
349
+ _iterator.f();
350
+ }
351
+ }
352
+ return mergedItem;
353
+ });
354
+ }
355
+ }, {
356
+ key: "reconcileOverwriteOrderCollections",
357
+ value: function reconcileOverwriteOrderCollections(existing, incoming) {
358
+ var reconciled = cloneDeep(incoming);
359
+ var existingRecord = existing;
360
+ var incomingRecord = incoming;
361
+ var uidRemaps = [];
362
+ for (var _i = 0, _ORDER_AUTHORITATIVE_ = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i < _ORDER_AUTHORITATIVE_.length; _i++) {
363
+ var field = _ORDER_AUTHORITATIVE_[_i];
364
+ if (!Array.isArray(incomingRecord[field])) continue;
365
+ reconciled[field] = this.mergeAuthoritativeOrderCollection(field, existingRecord[field], incomingRecord[field], uidRemaps);
366
+ }
367
+ return this.normalizeOrderCollectionsForIngress(applyOrderCollectionUidRemaps(reconciled, uidRemaps), 'overwriteExistingOrder.reconciled');
368
+ }
369
+
236
370
  /**
237
371
  * 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
238
372
  *
@@ -243,11 +377,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
243
377
  key: "recordRecentSqliteWrite",
244
378
  value: function recordRecentSqliteWrite(source, orders) {
245
379
  var now = Date.now();
246
- var _iterator = _createForOfIteratorHelper(orders),
247
- _step;
380
+ var _iterator2 = _createForOfIteratorHelper(orders),
381
+ _step2;
248
382
  try {
249
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
250
- var order = _step.value;
383
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
384
+ var order = _step2.value;
251
385
  var storageKey = this.getOrderStorageKey(order);
252
386
  if (!storageKey) continue;
253
387
  this.recentSqliteWriteByStorageKey.set(storageKey, {
@@ -256,9 +390,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
256
390
  });
257
391
  }
258
392
  } catch (err) {
259
- _iterator.e(err);
393
+ _iterator2.e(err);
260
394
  } finally {
261
- _iterator.f();
395
+ _iterator2.f();
262
396
  }
263
397
  }
264
398
 
@@ -281,11 +415,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
281
415
  var now = Date.now();
282
416
  var toWrite = [];
283
417
  var skipped = [];
284
- var _iterator2 = _createForOfIteratorHelper(orders),
285
- _step2;
418
+ var _iterator3 = _createForOfIteratorHelper(orders),
419
+ _step3;
286
420
  try {
287
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
288
- var order = _step2.value;
421
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
422
+ var order = _step3.value;
289
423
  var storageKey = this.getOrderStorageKey(order);
290
424
  if (!storageKey) {
291
425
  toWrite.push(order);
@@ -301,9 +435,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
301
435
  }
302
436
  var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
303
437
  if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
304
- var _order$order_id;
438
+ var _order$order_id2;
305
439
  skipped.push({
306
- orderId: (_order$order_id = order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
440
+ orderId: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
307
441
  storageKey: storageKey,
308
442
  reason: 'skip_pubsub_echo_after_business_write',
309
443
  lastSource: recent.source,
@@ -314,9 +448,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
314
448
  toWrite.push(order);
315
449
  }
316
450
  } catch (err) {
317
- _iterator2.e(err);
451
+ _iterator3.e(err);
318
452
  } finally {
319
- _iterator2.f();
453
+ _iterator3.f();
320
454
  }
321
455
  return {
322
456
  toWrite: toWrite,
@@ -336,11 +470,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
336
470
  var now = Date.now();
337
471
  var toFetch = [];
338
472
  var skipped = [];
339
- var _iterator3 = _createForOfIteratorHelper(ids),
340
- _step3;
473
+ var _iterator4 = _createForOfIteratorHelper(ids),
474
+ _step4;
341
475
  try {
342
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
343
- var id = _step3.value;
476
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
477
+ var id = _step4.value;
344
478
  var existing = this.getOrderByOrderId(id);
345
479
  if (!existing) {
346
480
  toFetch.push(id);
@@ -359,9 +493,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
359
493
  toFetch.push(id);
360
494
  }
361
495
  } catch (err) {
362
- _iterator3.e(err);
496
+ _iterator4.e(err);
363
497
  } finally {
364
- _iterator3.f();
498
+ _iterator4.f();
365
499
  }
366
500
  return {
367
501
  toFetch: toFetch,
@@ -496,62 +630,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
496
630
  }, {
497
631
  key: "preload",
498
632
  value: function () {
499
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
500
- var _this4 = this;
501
- var getData;
502
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
503
- while (1) switch (_context4.prev = _context4.next) {
633
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
634
+ var orders;
635
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
636
+ while (1) switch (_context3.prev = _context3.next) {
504
637
  case 0:
505
- // const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
506
- // // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
507
- // if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
508
- // this.store.list = cloneDeep(cachedOrders)
509
- // this.syncOrdersMap()
510
- // this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
511
- // return
512
- // }
513
- // if (hasPulledInCurrentWindow) {
514
- // this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
515
- // lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
516
- // })
517
- // return
518
- // }
519
- getData = /*#__PURE__*/function () {
520
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
521
- var orders;
522
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
523
- while (1) switch (_context3.prev = _context3.next) {
524
- case 0:
525
- _context3.next = 2;
526
- return _this4.loadOrdersByServer();
527
- case 2:
528
- orders = _context3.sent;
529
- if (!(orders.length === 0)) {
530
- _context3.next = 5;
531
- break;
532
- }
533
- return _context3.abrupt("return");
534
- case 5:
535
- _this4.store.list = cloneDeep(orders);
536
- _this4.syncOrdersMap();
537
- _this4.emitOrdersChanged([], 'preload');
538
- _this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
539
- case 9:
540
- case "end":
541
- return _context3.stop();
542
- }
543
- }, _callee3);
544
- }));
545
- return function getData() {
546
- return _ref.apply(this, arguments);
547
- };
548
- }();
549
- getData();
638
+ _context3.next = 2;
639
+ return this.loadOrdersByServer();
550
640
  case 2:
641
+ orders = _context3.sent;
642
+ this.store.list = cloneDeep(orders);
643
+ this.syncOrdersMap();
644
+ _context3.next = 7;
645
+ return this.emitOrdersChanged([], 'preload');
646
+ case 7:
647
+ _context3.next = 9;
648
+ return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
649
+ case 9:
551
650
  case "end":
552
- return _context4.stop();
651
+ return _context3.stop();
553
652
  }
554
- }, _callee4);
653
+ }, _callee3, this);
555
654
  }));
556
655
  function preload() {
557
656
  return _preload.apply(this, arguments);
@@ -575,67 +674,125 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
575
674
  value: function getOrderByOrderId(orderId) {
576
675
  return this.store.map.get(this.getIdKey(orderId));
577
676
  }
677
+ }, {
678
+ key: "buildLocalPaymentOrderLogContext",
679
+ value: function buildLocalPaymentOrderLogContext(order) {
680
+ var _order$order_id3, _order$external_sale_, _order$order_number, _order$shop_order_num, _order$shop_full_orde, _order$status, _order$payment_status, _order$platform, _order$business_code, _order$order_sales_ch, _order$sales_channel, _order$type;
681
+ if (!order) return {};
682
+ return {
683
+ order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
684
+ external_sale_number: (_order$external_sale_ = order.external_sale_number) !== null && _order$external_sale_ !== void 0 ? _order$external_sale_ : null,
685
+ order_number: (_order$order_number = order.order_number) !== null && _order$order_number !== void 0 ? _order$order_number : null,
686
+ shop_order_number: (_order$shop_order_num = order.shop_order_number) !== null && _order$shop_order_num !== void 0 ? _order$shop_order_num : null,
687
+ shop_full_order_number: (_order$shop_full_orde = order.shop_full_order_number) !== null && _order$shop_full_orde !== void 0 ? _order$shop_full_orde : null,
688
+ order_status: (_order$status = order.status) !== null && _order$status !== void 0 ? _order$status : null,
689
+ payment_status: (_order$payment_status = order.payment_status) !== null && _order$payment_status !== void 0 ? _order$payment_status : null,
690
+ is_draft_order: Number(order.is_draft_order || 0),
691
+ need_sync: Number(order.need_sync || 0),
692
+ platform: (_order$platform = order.platform) !== null && _order$platform !== void 0 ? _order$platform : null,
693
+ business_code: (_order$business_code = order.business_code) !== null && _order$business_code !== void 0 ? _order$business_code : null,
694
+ order_sales_channel: (_order$order_sales_ch = order.order_sales_channel) !== null && _order$order_sales_ch !== void 0 ? _order$order_sales_ch : null,
695
+ sales_channel: (_order$sales_channel = order.sales_channel) !== null && _order$sales_channel !== void 0 ? _order$sales_channel : null,
696
+ order_type: (_order$type = order.type) !== null && _order$type !== void 0 ? _order$type : null,
697
+ payments_count: Array.isArray(order.payments) ? order.payments.length : 0
698
+ };
699
+ }
578
700
  }, {
579
701
  key: "getLocalOrderFromMemoryByLookup",
580
702
  value: function getLocalOrderFromMemoryByLookup(lookup) {
581
- var _this5 = this;
703
+ var _this3 = this;
582
704
  var key = this.getIdKey(lookup);
583
705
  var memoryOrderById = this.store.map.get(key);
584
706
  if (memoryOrderById) return memoryOrderById;
585
707
  var memoryOrder = this.store.list.find(function (order) {
586
- return _this5.isOrderLookupMatch(order, key);
708
+ return _this3.isOrderLookupMatch(order, key);
587
709
  });
588
710
  return memoryOrder || null;
589
711
  }
590
712
  }, {
591
713
  key: "getLocalOrderByLookup",
592
714
  value: function () {
593
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
594
- var _this6 = this;
595
- var key, memoryOrderById, memoryOrder, orders, localOrder;
596
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
597
- while (1) switch (_context5.prev = _context5.next) {
715
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
716
+ var _this4 = this;
717
+ var options,
718
+ key,
719
+ logContext,
720
+ memoryOrderById,
721
+ memoryOrder,
722
+ orders,
723
+ localOrder,
724
+ normalizedOrder,
725
+ _args4 = arguments;
726
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
727
+ while (1) switch (_context4.prev = _context4.next) {
598
728
  case 0:
729
+ options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
599
730
  key = this.getIdKey(lookup);
731
+ logContext = {
732
+ operation_id: options.operationId,
733
+ lookup: key,
734
+ memory_order_count: this.store.list.length
735
+ };
736
+ if (options.operationId) {
737
+ this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
738
+ }
600
739
  memoryOrderById = this.store.map.get(key);
601
740
  if (!memoryOrderById) {
602
- _context5.next = 4;
741
+ _context4.next = 8;
603
742
  break;
604
743
  }
605
- return _context5.abrupt("return", memoryOrderById);
606
- case 4:
744
+ if (options.operationId) {
745
+ this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
746
+ }
747
+ return _context4.abrupt("return", memoryOrderById);
748
+ case 8:
607
749
  memoryOrder = this.store.list.find(function (order) {
608
- return _this6.isOrderLookupMatch(order, key);
750
+ return _this4.isOrderLookupMatch(order, key);
609
751
  });
610
752
  if (!memoryOrder) {
611
- _context5.next = 7;
753
+ _context4.next = 12;
612
754
  break;
613
755
  }
614
- return _context5.abrupt("return", memoryOrder);
615
- case 7:
616
- _context5.next = 9;
756
+ if (options.operationId) {
757
+ this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
758
+ }
759
+ return _context4.abrupt("return", memoryOrder);
760
+ case 12:
761
+ if (options.operationId) {
762
+ this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
763
+ }
764
+ _context4.next = 15;
617
765
  return this.loadOrdersFromSQLite();
618
- case 9:
619
- orders = _context5.sent;
766
+ case 15:
767
+ orders = _context4.sent;
620
768
  localOrder = orders.find(function (order) {
621
- return _this6.isOrderLookupMatch(order, key);
769
+ return _this4.isOrderLookupMatch(order, key);
622
770
  });
623
771
  if (localOrder) {
624
- _context5.next = 13;
772
+ _context4.next = 20;
625
773
  break;
626
774
  }
627
- return _context5.abrupt("return", null);
628
- case 13:
629
- this.store.list = orders.map(function (order) {
630
- return _this6.normalizeOrderForMemoryList(order);
631
- });
775
+ if (options.operationId) {
776
+ this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', _objectSpread(_objectSpread({}, logContext), {}, {
777
+ sqlite_order_count: orders.length
778
+ }));
779
+ }
780
+ return _context4.abrupt("return", null);
781
+ case 20:
782
+ this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
632
783
  this.syncOrdersMap();
633
- return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
634
- case 16:
784
+ normalizedOrder = this.normalizeOrderForMemoryList(localOrder);
785
+ if (options.operationId) {
786
+ this.logInfo('getLocalOrderByLookup-localPayment-SQLite命中', _objectSpread(_objectSpread({}, logContext), {}, {
787
+ sqlite_order_count: orders.length
788
+ }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
789
+ }
790
+ return _context4.abrupt("return", normalizedOrder);
791
+ case 25:
635
792
  case "end":
636
- return _context5.stop();
793
+ return _context4.stop();
637
794
  }
638
- }, _callee5, this);
795
+ }, _callee4, this);
639
796
  }));
640
797
  function getLocalOrderByLookup(_x3) {
641
798
  return _getLocalOrderByLookup.apply(this, arguments);
@@ -643,66 +800,254 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
643
800
  return getLocalOrderByLookup;
644
801
  }()
645
802
  }, {
646
- key: "loadOrdersByServer",
803
+ key: "getLocalPayment",
804
+ value: function () {
805
+ var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
806
+ var logContext, order, payments, match;
807
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
808
+ while (1) switch (_context5.prev = _context5.next) {
809
+ case 0:
810
+ logContext = {
811
+ operation_id: params.operationId,
812
+ sale_id: params.saleId,
813
+ payment_number: params.paymentNumber
814
+ };
815
+ this.logInfo('getLocalPayment-开始', logContext);
816
+ _context5.prev = 2;
817
+ _context5.next = 5;
818
+ return this.getLocalOrderByLookup(params.saleId, {
819
+ operationId: params.operationId
820
+ });
821
+ case 5:
822
+ order = _context5.sent;
823
+ if (order) {
824
+ _context5.next = 9;
825
+ break;
826
+ }
827
+ this.logWarning('getLocalPayment-订单未命中', logContext);
828
+ return _context5.abrupt("return", null);
829
+ case 9:
830
+ payments = order.payments || [];
831
+ match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
832
+ if (match) {
833
+ _context5.next = 14;
834
+ break;
835
+ }
836
+ this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
837
+ payments: payments
838
+ }));
839
+ return _context5.abrupt("return", null);
840
+ case 14:
841
+ this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
842
+ matched_by: match.matchedBy,
843
+ payment_index: match.index,
844
+ payment: match.payment
845
+ }));
846
+ return _context5.abrupt("return", {
847
+ order: order,
848
+ payment: match.payment,
849
+ paymentIndex: match.index,
850
+ matchedBy: match.matchedBy
851
+ });
852
+ case 18:
853
+ _context5.prev = 18;
854
+ _context5.t0 = _context5["catch"](2);
855
+ this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
856
+ error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
857
+ }));
858
+ throw _context5.t0;
859
+ case 22:
860
+ case "end":
861
+ return _context5.stop();
862
+ }
863
+ }, _callee5, this, [[2, 18]]);
864
+ }));
865
+ function getLocalPayment(_x4) {
866
+ return _getLocalPayment.apply(this, arguments);
867
+ }
868
+ return getLocalPayment;
869
+ }()
870
+ }, {
871
+ key: "updateLocalPayment",
647
872
  value: function () {
648
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
649
- var _this$store,
650
- _this7 = this;
651
- var orderList, data, mergedOrders, memoryOrders;
873
+ var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
874
+ var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
652
875
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
653
876
  while (1) switch (_context6.prev = _context6.next) {
877
+ case 0:
878
+ logContext = {
879
+ operation_id: params.operationId,
880
+ sale_id: params.saleId,
881
+ payment_number: params.paymentNumber,
882
+ incoming_payment_update: params.updates
883
+ };
884
+ this.logInfo('updateLocalPayment-开始', logContext);
885
+ _context6.next = 4;
886
+ return this.getLocalPayment(params);
887
+ case 4:
888
+ found = _context6.sent;
889
+ if (found) {
890
+ _context6.next = 8;
891
+ break;
892
+ }
893
+ this.logWarning('updateLocalPayment-支付项未命中', logContext);
894
+ return _context6.abrupt("return", null);
895
+ case 8:
896
+ previousPayment = cloneDeep(found.payment);
897
+ nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
898
+ updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
899
+ }));
900
+ nextOrder = _objectSpread(_objectSpread({}, found.order), {}, {
901
+ payments: (found.order.payments || []).map(function (payment, index) {
902
+ return index === found.paymentIndex ? nextPayment : payment;
903
+ }),
904
+ updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
905
+ });
906
+ paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
907
+ matched_by: found.matchedBy,
908
+ payment_index: found.paymentIndex
909
+ }, this.buildLocalPaymentOrderLogContext(nextOrder)), {}, {
910
+ previous_payment: previousPayment,
911
+ payment: nextPayment
912
+ });
913
+ this.logInfo('updateLocalPayment-支付项合并完成', paymentContext);
914
+ targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
915
+ shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
916
+ if (!(targetIndex < 0 && shouldKeepInMemory)) {
917
+ _context6.next = 18;
918
+ break;
919
+ }
920
+ this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
921
+ return _context6.abrupt("return", null);
922
+ case 18:
923
+ previousList = this.store.list;
924
+ this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
925
+ return index === targetIndex ? nextOrder : order;
926
+ }) : this.store.list.filter(function (_, index) {
927
+ return index !== targetIndex;
928
+ });
929
+ this.syncOrdersMap();
930
+ storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
931
+ _context6.prev = 22;
932
+ this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
933
+ storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
934
+ }));
935
+ _context6.next = 26;
936
+ return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
937
+ throwOnError: true
938
+ });
939
+ case 26:
940
+ this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
941
+ storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
942
+ }));
943
+ _context6.next = 35;
944
+ break;
945
+ case 29:
946
+ _context6.prev = 29;
947
+ _context6.t0 = _context6["catch"](22);
948
+ this.store.list = previousList;
949
+ this.syncOrdersMap();
950
+ this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
951
+ storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
952
+ error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
953
+ }));
954
+ throw _context6.t0;
955
+ case 35:
956
+ if (!(shouldKeepInMemory || targetIndex >= 0)) {
957
+ _context6.next = 38;
958
+ break;
959
+ }
960
+ _context6.next = 38;
961
+ return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
962
+ case 38:
963
+ this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
964
+ return _context6.abrupt("return", {
965
+ order: nextOrder,
966
+ payment: nextPayment,
967
+ previousPayment: previousPayment
968
+ });
969
+ case 40:
970
+ case "end":
971
+ return _context6.stop();
972
+ }
973
+ }, _callee6, this, [[22, 29]]);
974
+ }));
975
+ function updateLocalPayment(_x5) {
976
+ return _updateLocalPayment.apply(this, arguments);
977
+ }
978
+ return updateLocalPayment;
979
+ }()
980
+ }, {
981
+ key: "loadOrdersByServer",
982
+ value: function () {
983
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
984
+ var _this5 = this,
985
+ _this$store;
986
+ var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
987
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
988
+ while (1) switch (_context7.prev = _context7.next) {
654
989
  case 0:
655
990
  orderList = [];
991
+ _context7.next = 3;
992
+ return this.loadOrdersFromSQLite();
993
+ case 3:
994
+ protectedOrdersBeforeRemoteFetch = _context7.sent.filter(function (order) {
995
+ return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
996
+ });
656
997
  this.logInfo('loadOrdersByServer-开始', {
657
998
  hasOrderDataSource: !!this.orderDataSource,
658
- query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
999
+ query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1000
+ protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
1001
+ protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
1002
+ return count + _this5.getIdentifiedPendingPayments(order).length;
1003
+ }, 0)
659
1004
  });
660
1005
  if (!this.orderDataSource) {
661
- _context6.next = 17;
1006
+ _context7.next = 20;
662
1007
  break;
663
1008
  }
664
- _context6.prev = 3;
665
- _context6.next = 6;
1009
+ _context7.prev = 6;
1010
+ _context7.next = 9;
666
1011
  return this.orderDataSource.run({
667
1012
  sse: {
668
1013
  query: this.store.createdAtQuery
669
1014
  }
670
1015
  });
671
- case 6:
672
- data = _context6.sent;
1016
+ case 9:
1017
+ data = _context7.sent;
673
1018
  orderList = data || [];
674
1019
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
675
1020
  count: orderList.length
676
1021
  });
677
1022
  this.markOrderPulledAtNow();
678
1023
  this.lastServerFullFetchAtMs = Date.now();
679
- _context6.next = 17;
1024
+ _context7.next = 20;
680
1025
  break;
681
- case 13:
682
- _context6.prev = 13;
683
- _context6.t0 = _context6["catch"](3);
1026
+ case 16:
1027
+ _context7.prev = 16;
1028
+ _context7.t0 = _context7["catch"](6);
684
1029
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
685
- return _context6.abrupt("return", this.store.list);
686
- case 17:
687
- _context6.next = 19;
688
- return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
689
- case 19:
690
- mergedOrders = _context6.sent;
691
- memoryOrders = mergedOrders.map(function (order) {
692
- return _this7.normalizeOrderForMemoryList(order);
693
- });
1030
+ return _context7.abrupt("return", this.store.list);
1031
+ case 20:
1032
+ _context7.next = 22;
1033
+ return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1034
+ case 22:
1035
+ mergedOrders = _context7.sent;
1036
+ memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
694
1037
  this.logInfo('loadOrdersByServer-结束', {
695
- count: memoryOrders.length
1038
+ count: memoryOrders.length,
1039
+ persistedCount: mergedOrders.length,
1040
+ sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
696
1041
  });
697
- _context6.next = 24;
1042
+ _context7.next = 27;
698
1043
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
699
- case 24:
700
- return _context6.abrupt("return", memoryOrders);
701
- case 25:
1044
+ case 27:
1045
+ return _context7.abrupt("return", memoryOrders);
1046
+ case 28:
702
1047
  case "end":
703
- return _context6.stop();
1048
+ return _context7.stop();
704
1049
  }
705
- }, _callee6, this, [[3, 13]]);
1050
+ }, _callee7, this, [[6, 16]]);
706
1051
  }));
707
1052
  function loadOrdersByServer() {
708
1053
  return _loadOrdersByServer.apply(this, arguments);
@@ -717,61 +1062,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
717
1062
  }, {
718
1063
  key: "silentRefresh",
719
1064
  value: (function () {
720
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1065
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
721
1066
  var startTime, elapsedSinceFullFetch, orders, errorMessage;
722
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
723
- while (1) switch (_context7.prev = _context7.next) {
1067
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1068
+ while (1) switch (_context8.prev = _context8.next) {
724
1069
  case 0:
725
1070
  startTime = Date.now();
726
1071
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
727
1072
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
728
- _context7.next = 4;
1073
+ _context8.next = 4;
729
1074
  break;
730
1075
  }
731
- return _context7.abrupt("return", this.store.list);
1076
+ return _context8.abrupt("return", this.store.list);
732
1077
  case 4:
733
1078
  this.logInfo('silentRefresh 开始');
734
- _context7.prev = 5;
1079
+ _context8.prev = 5;
735
1080
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
736
1081
  this.updateCreateStore();
737
- _context7.next = 9;
1082
+ _context8.next = 9;
738
1083
  return this.loadOrdersByServer();
739
1084
  case 9:
740
- orders = _context7.sent;
741
- if (!(orders.length > 0)) {
742
- _context7.next = 19;
743
- break;
744
- }
1085
+ orders = _context8.sent;
745
1086
  this.store.list = cloneDeep(orders);
746
1087
  this.syncOrdersMap();
747
- this.emitOrdersChanged([], 'silentRefresh');
748
- _context7.next = 16;
1088
+ _context8.next = 14;
1089
+ return this.emitOrdersChanged([], 'silentRefresh');
1090
+ case 14:
1091
+ _context8.next = 16;
749
1092
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
750
1093
  case 16:
751
1094
  this.logInfo('silentRefresh 完成', {
752
1095
  orderCount: orders.length,
753
1096
  duration: "".concat(Date.now() - startTime, "ms")
754
1097
  });
755
- _context7.next = 20;
756
- break;
757
- case 19:
758
- this.logInfo('silentRefresh: 服务器未返回数据');
1098
+ return _context8.abrupt("return", this.store.list);
759
1099
  case 20:
760
- return _context7.abrupt("return", this.store.list);
761
- case 23:
762
- _context7.prev = 23;
763
- _context7.t0 = _context7["catch"](5);
764
- errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
1100
+ _context8.prev = 20;
1101
+ _context8.t0 = _context8["catch"](5);
1102
+ errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
765
1103
  this.logError('silentRefresh 失败', {
766
1104
  duration: "".concat(Date.now() - startTime, "ms"),
767
1105
  error: errorMessage
768
1106
  });
769
- return _context7.abrupt("return", this.store.list);
770
- case 28:
1107
+ return _context8.abrupt("return", this.store.list);
1108
+ case 25:
771
1109
  case "end":
772
- return _context7.stop();
1110
+ return _context8.stop();
773
1111
  }
774
- }, _callee7, this, [[5, 23]]);
1112
+ }, _callee8, this, [[5, 20]]);
775
1113
  }));
776
1114
  function silentRefresh() {
777
1115
  return _silentRefresh.apply(this, arguments);
@@ -781,17 +1119,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
781
1119
  }, {
782
1120
  key: "normalizeOrderForMemoryList",
783
1121
  value: function normalizeOrderForMemoryList(order) {
784
- var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
785
- if ((order === null || order === void 0 ? void 0 : order.order_id) !== undefined && (order === null || order === void 0 ? void 0 : order.order_id) !== null && (order === null || order === void 0 ? void 0 : order.order_id) !== '') {
786
- return order;
1122
+ var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
1123
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
1124
+ var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
1125
+ if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
1126
+ return normalizedOrder;
1127
+ }
1128
+ if ((normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== undefined && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== null && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== '') {
1129
+ return normalizedOrder;
787
1130
  }
788
1131
  if (externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '') {
789
- return order;
1132
+ return normalizedOrder;
790
1133
  }
791
- return _objectSpread(_objectSpread({}, order), {}, {
1134
+ return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
792
1135
  order_id: externalSaleNumber
793
1136
  });
794
1137
  }
1138
+ }, {
1139
+ key: "normalizeOrdersForMemoryList",
1140
+ value: function normalizeOrdersForMemoryList(orders, source) {
1141
+ var _this6 = this;
1142
+ return orders.map(function (order) {
1143
+ return _this6.normalizeOrderForMemoryList(order, source);
1144
+ }).filter(function (order) {
1145
+ return _this6.shouldKeepOrderInMemory(order);
1146
+ });
1147
+ }
1148
+ }, {
1149
+ key: "hasRealOrderId",
1150
+ value: function hasRealOrderId(order) {
1151
+ if (!order || this.isBlankIdentityValue(order.order_id)) return false;
1152
+ var externalSaleNumber = order.external_sale_number;
1153
+ return !(this.isDraftOrder(order) && !this.isBlankIdentityValue(externalSaleNumber) && String(order.order_id) === String(externalSaleNumber));
1154
+ }
1155
+ }, {
1156
+ key: "shouldKeepOrderInMemory",
1157
+ value: function shouldKeepOrderInMemory(order) {
1158
+ return !this.isDraftOrder(order) || this.hasRealOrderId(order);
1159
+ }
1160
+ }, {
1161
+ key: "withoutSyntheticDraftOrderId",
1162
+ value: function withoutSyntheticDraftOrderId(order) {
1163
+ var externalSaleNumber = order.external_sale_number;
1164
+ if (Number(order.is_draft_order || 0) !== 1 || order.order_id === undefined || externalSaleNumber === undefined || String(order.order_id) !== String(externalSaleNumber)) {
1165
+ return order;
1166
+ }
1167
+ var next = _objectSpread({}, order);
1168
+ delete next.order_id;
1169
+ return next;
1170
+ }
795
1171
 
796
1172
  /**
797
1173
  * 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
@@ -800,31 +1176,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
800
1176
  }, {
801
1177
  key: "overwriteExistingOrder",
802
1178
  value: (function () {
803
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
804
- var _this8 = this;
805
- var orderId, key;
806
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
807
- while (1) switch (_context8.prev = _context8.next) {
1179
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
1180
+ var _this7 = this;
1181
+ var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1182
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1183
+ while (1) switch (_context9.prev = _context9.next) {
808
1184
  case 0:
809
1185
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
810
1186
  if (!(orderId === undefined || orderId === null)) {
811
- _context8.next = 4;
1187
+ _context9.next = 4;
812
1188
  break;
813
1189
  }
814
1190
  this.logError('overwriteExistingOrder-入参缺少 order_id');
815
- return _context8.abrupt("return", {
1191
+ return _context9.abrupt("return", {
816
1192
  overwritten: false
817
1193
  });
818
1194
  case 4:
819
1195
  key = this.getIdKey(orderId);
820
1196
  if (this.store.map.has(key)) {
821
- _context8.next = 8;
1197
+ _context9.next = 8;
822
1198
  break;
823
1199
  }
824
1200
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
825
1201
  orderId: orderId
826
1202
  });
827
- return _context8.abrupt("return", {
1203
+ return _context9.abrupt("return", {
828
1204
  overwritten: false
829
1205
  });
830
1206
  case 8:
@@ -832,32 +1208,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
832
1208
  orderId: orderId,
833
1209
  storeOrderCountBefore: this.store.list.length
834
1210
  });
1211
+ normalizedFresh = this.normalizeOrderForMemoryList(fresh, 'overwriteExistingOrder.incoming');
1212
+ existingOrder = this.store.map.get(key);
1213
+ reconciledFresh = this.reconcileOverwriteOrderCollections(existingOrder, normalizedFresh);
835
1214
  this.store.list = this.store.list.map(function (order) {
836
1215
  var id = order === null || order === void 0 ? void 0 : order.order_id;
837
- if (id === undefined || id === null) return order;
838
- return _this8.getIdKey(id) === key ? fresh : order;
1216
+ if (id === undefined || id === null) {
1217
+ return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1218
+ }
1219
+ return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
839
1220
  });
840
1221
  this.syncOrdersMap();
841
- _context8.next = 13;
842
- return this.updateOrderInSQLite(fresh, 'overwriteExistingOrder');
843
- case 13:
1222
+ _context9.next = 16;
1223
+ return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1224
+ case 16:
844
1225
  this.logInfo('overwriteExistingOrder-结束', {
845
1226
  orderId: orderId,
846
1227
  storeOrderCountAfter: this.store.list.length
847
1228
  });
848
- _context8.next = 16;
849
- return this.emitOrdersChanged([fresh], 'overwriteExistingOrder');
850
- case 16:
851
- return _context8.abrupt("return", {
1229
+ _context9.next = 19;
1230
+ return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1231
+ case 19:
1232
+ return _context9.abrupt("return", {
852
1233
  overwritten: true
853
1234
  });
854
- case 17:
1235
+ case 20:
855
1236
  case "end":
856
- return _context8.stop();
1237
+ return _context9.stop();
857
1238
  }
858
- }, _callee8, this);
1239
+ }, _callee9, this);
859
1240
  }));
860
- function overwriteExistingOrder(_x4) {
1241
+ function overwriteExistingOrder(_x6) {
861
1242
  return _overwriteExistingOrder.apply(this, arguments);
862
1243
  }
863
1244
  return overwriteExistingOrder;
@@ -870,29 +1251,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
870
1251
  }, {
871
1252
  key: "upsertOrdersFromRemote",
872
1253
  value: (function () {
873
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
874
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
875
- while (1) switch (_context9.prev = _context9.next) {
1254
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(freshOrders) {
1255
+ var source,
1256
+ _args10 = arguments;
1257
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1258
+ while (1) switch (_context10.prev = _context10.next) {
876
1259
  case 0:
1260
+ source = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : 'upsertOrdersFromRemote';
877
1261
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
878
- _context9.next = 3;
1262
+ _context10.next = 4;
879
1263
  break;
880
1264
  }
881
1265
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
882
- return _context9.abrupt("return");
883
- case 3:
1266
+ return _context10.abrupt("return");
1267
+ case 4:
884
1268
  this.logInfo('upsertOrdersFromRemote-开始', {
885
- count: freshOrders.length
1269
+ count: freshOrders.length,
1270
+ source: source
886
1271
  });
887
- _context9.next = 6;
888
- return this.mergeOrdersToStore(freshOrders, 'upsertOrdersFromRemote');
889
- case 6:
1272
+ _context10.next = 7;
1273
+ return this.mergeOrdersToStore(freshOrders, source);
1274
+ case 7:
890
1275
  case "end":
891
- return _context9.stop();
1276
+ return _context10.stop();
892
1277
  }
893
- }, _callee9, this);
1278
+ }, _callee10, this);
894
1279
  }));
895
- function upsertOrdersFromRemote(_x5) {
1280
+ function upsertOrdersFromRemote(_x7) {
896
1281
  return _upsertOrdersFromRemote.apply(this, arguments);
897
1282
  }
898
1283
  return upsertOrdersFromRemote;
@@ -900,21 +1285,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
900
1285
  }, {
901
1286
  key: "markOrderSyncedByExternalSaleNumber",
902
1287
  value: function () {
903
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
904
- var _this9 = this,
1288
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
1289
+ var _this8 = this,
905
1290
  _existing$external_sa,
906
1291
  _nextOrder$order_id;
907
1292
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
908
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
909
- while (1) switch (_context10.prev = _context10.next) {
1293
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1294
+ while (1) switch (_context11.prev = _context11.next) {
910
1295
  case 0:
911
1296
  externalSaleNumber = params.externalSaleNumber;
912
1297
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
913
- _context10.next = 4;
1298
+ _context11.next = 4;
914
1299
  break;
915
1300
  }
916
1301
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
917
- return _context10.abrupt("return", {
1302
+ return _context11.abrupt("return", {
918
1303
  updated: false
919
1304
  });
920
1305
  case 4:
@@ -922,23 +1307,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
922
1307
  targetIndex = this.store.list.findIndex(function (order) {
923
1308
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
924
1309
  if (value === undefined || value === null || value === '') return false;
925
- return _this9.getIdKey(value) === key;
1310
+ return _this8.getIdKey(value) === key;
926
1311
  });
927
1312
  if (!(targetIndex < 0)) {
928
- _context10.next = 9;
1313
+ _context11.next = 9;
929
1314
  break;
930
1315
  }
931
1316
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
932
1317
  external_sale_number: externalSaleNumber
933
1318
  });
934
- return _context10.abrupt("return", {
1319
+ return _context11.abrupt("return", {
935
1320
  updated: false
936
1321
  });
937
1322
  case 9:
938
1323
  existing = this.store.list[targetIndex];
939
1324
  nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
940
1325
  external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
941
- need_sync: 0
1326
+ need_sync: 0,
1327
+ is_draft_order: 0
942
1328
  }));
943
1329
  storageKey = this.getOrderStorageKey(nextOrder) || key;
944
1330
  this.store.list = this.store.list.map(function (order, index) {
@@ -946,27 +1332,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
946
1332
  return nextOrder;
947
1333
  });
948
1334
  this.syncOrdersMap();
949
- _context10.next = 16;
1335
+ _context11.next = 16;
950
1336
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
951
1337
  case 16:
952
1338
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
953
1339
  external_sale_number: externalSaleNumber,
954
1340
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
955
1341
  });
956
- _context10.next = 19;
1342
+ _context11.next = 19;
957
1343
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
958
1344
  case 19:
959
- return _context10.abrupt("return", {
1345
+ return _context11.abrupt("return", {
960
1346
  updated: true,
961
1347
  order: nextOrder
962
1348
  });
963
1349
  case 20:
964
1350
  case "end":
965
- return _context10.stop();
1351
+ return _context11.stop();
966
1352
  }
967
- }, _callee10, this);
1353
+ }, _callee11, this);
968
1354
  }));
969
- function markOrderSyncedByExternalSaleNumber(_x6) {
1355
+ function markOrderSyncedByExternalSaleNumber(_x8) {
970
1356
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
971
1357
  }
972
1358
  return markOrderSyncedByExternalSaleNumber;
@@ -978,149 +1364,387 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
978
1364
  }, {
979
1365
  key: "upsertPendingSyncOrders",
980
1366
  value: (function () {
981
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
982
- var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator5, _step5, key, _iterator6, _step6, _step6$value, _storageKey, pendingOrder, matchIndex, mergedOrder, insertIndex;
983
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
984
- while (1) switch (_context11.prev = _context11.next) {
1367
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(pendingOrders) {
1368
+ var _this9 = this;
1369
+ var options,
1370
+ pendingMap,
1371
+ memoryPendingMap,
1372
+ _iterator5,
1373
+ _step5,
1374
+ order,
1375
+ normalizedOrder,
1376
+ pendingOrder,
1377
+ storageKey,
1378
+ mergeActions,
1379
+ updatedList,
1380
+ identityKeyToIndex,
1381
+ index,
1382
+ _iterator6,
1383
+ _step6,
1384
+ key,
1385
+ _iterator7,
1386
+ _step7,
1387
+ _step7$value,
1388
+ _storageKey,
1389
+ _pendingOrder,
1390
+ matchIndex,
1391
+ existingOrder,
1392
+ mergedOrder,
1393
+ nextOrder,
1394
+ pendingSnapshot,
1395
+ insertIndex,
1396
+ patchedOrders,
1397
+ previousList,
1398
+ _args12 = arguments;
1399
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1400
+ while (1) switch (_context12.prev = _context12.next) {
985
1401
  case 0:
1402
+ options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {};
986
1403
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
987
- _context11.next = 3;
1404
+ _context12.next = 4;
988
1405
  break;
989
1406
  }
990
1407
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
991
- return _context11.abrupt("return");
992
- case 3:
1408
+ return _context12.abrupt("return");
1409
+ case 4:
993
1410
  pendingMap = new Map();
994
1411
  memoryPendingMap = new Map();
995
- _iterator4 = _createForOfIteratorHelper(pendingOrders);
996
- _context11.prev = 6;
997
- _iterator4.s();
998
- case 8:
999
- if ((_step4 = _iterator4.n()).done) {
1000
- _context11.next = 17;
1412
+ _iterator5 = _createForOfIteratorHelper(pendingOrders);
1413
+ _context12.prev = 7;
1414
+ _iterator5.s();
1415
+ case 9:
1416
+ if ((_step5 = _iterator5.n()).done) {
1417
+ _context12.next = 20;
1001
1418
  break;
1002
1419
  }
1003
- order = _step4.value;
1004
- storageKey = this.getOrderStorageKey(order);
1420
+ order = _step5.value;
1421
+ normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
1422
+ pendingOrder = _objectSpread(_objectSpread({}, normalizedOrder), {}, {
1423
+ need_sync: 1,
1424
+ is_draft_order: 0
1425
+ });
1426
+ storageKey = this.getOrderStorageKey(pendingOrder);
1005
1427
  if (storageKey) {
1006
- _context11.next = 13;
1428
+ _context12.next = 16;
1007
1429
  break;
1008
1430
  }
1009
- return _context11.abrupt("continue", 15);
1010
- case 13:
1011
- pendingMap.set(storageKey, order);
1012
- memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(order));
1013
- case 15:
1014
- _context11.next = 8;
1431
+ return _context12.abrupt("continue", 18);
1432
+ case 16:
1433
+ pendingMap.set(storageKey, pendingOrder);
1434
+ memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1435
+ case 18:
1436
+ _context12.next = 9;
1015
1437
  break;
1016
- case 17:
1017
- _context11.next = 22;
1438
+ case 20:
1439
+ _context12.next = 25;
1018
1440
  break;
1019
- case 19:
1020
- _context11.prev = 19;
1021
- _context11.t0 = _context11["catch"](6);
1022
- _iterator4.e(_context11.t0);
1023
1441
  case 22:
1024
- _context11.prev = 22;
1025
- _iterator4.f();
1026
- return _context11.finish(22);
1442
+ _context12.prev = 22;
1443
+ _context12.t0 = _context12["catch"](7);
1444
+ _iterator5.e(_context12.t0);
1027
1445
  case 25:
1446
+ _context12.prev = 25;
1447
+ _iterator5.f();
1448
+ return _context12.finish(25);
1449
+ case 28:
1028
1450
  if (!(pendingMap.size === 0)) {
1029
- _context11.next = 28;
1451
+ _context12.next = 31;
1030
1452
  break;
1031
1453
  }
1032
1454
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1033
1455
  count: pendingOrders.length
1034
1456
  });
1035
- return _context11.abrupt("return");
1036
- case 28:
1457
+ return _context12.abrupt("return");
1458
+ case 31:
1037
1459
  this.logInfo('upsertPendingSyncOrders-开始', {
1038
1460
  count: pendingMap.size
1039
1461
  });
1040
- patchedOrders = _toConsumableArray(pendingMap.values());
1041
1462
  mergeActions = {};
1042
- updatedList = _toConsumableArray(this.store.list); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1463
+ updatedList = this.store.list.map(function (order) {
1464
+ return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1465
+ }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1043
1466
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1044
1467
  identityKeyToIndex = new Map();
1045
1468
  for (index = 0; index < updatedList.length; index += 1) {
1046
- _iterator5 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1469
+ _iterator6 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1047
1470
  try {
1048
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1049
- key = _step5.value;
1471
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1472
+ key = _step6.value;
1050
1473
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1051
1474
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1052
1475
  }
1053
1476
  } catch (err) {
1054
- _iterator5.e(err);
1477
+ _iterator6.e(err);
1055
1478
  } finally {
1056
- _iterator5.f();
1479
+ _iterator6.f();
1057
1480
  }
1058
1481
  }
1059
- _iterator6 = _createForOfIteratorHelper(memoryPendingMap.entries());
1060
- _context11.prev = 35;
1061
- _iterator6.s();
1062
- case 37:
1063
- if ((_step6 = _iterator6.n()).done) {
1064
- _context11.next = 52;
1482
+ _iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
1483
+ _context12.prev = 37;
1484
+ _iterator7.s();
1485
+ case 39:
1486
+ if ((_step7 = _iterator7.n()).done) {
1487
+ _context12.next = 58;
1065
1488
  break;
1066
1489
  }
1067
- _step6$value = _slicedToArray(_step6.value, 2), _storageKey = _step6$value[0], pendingOrder = _step6$value[1];
1068
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(pendingOrder));
1490
+ _step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], _pendingOrder = _step7$value[1];
1491
+ matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1069
1492
  if (!(matchIndex >= 0)) {
1070
- _context11.next = 46;
1493
+ _context12.next = 52;
1071
1494
  break;
1072
1495
  }
1073
- mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder, {
1074
- preferIncomingProducts: true
1496
+ existingOrder = updatedList[matchIndex];
1497
+ mergedOrder = this.mergeOrderRecords(existingOrder, _pendingOrder);
1498
+ nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
1499
+ need_sync: 1,
1500
+ is_draft_order: 0
1075
1501
  });
1076
- updatedList[matchIndex] = mergedOrder;
1502
+ updatedList[matchIndex] = nextOrder;
1503
+ pendingSnapshot = pendingMap.get(_storageKey);
1504
+ if (pendingSnapshot) {
1505
+ pendingMap.set(_storageKey, this.reconcileOverwriteOrderCollections(existingOrder, pendingSnapshot));
1506
+ }
1077
1507
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1078
- this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
1508
+ this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1079
1509
  mergeActions[_storageKey] = 'update';
1080
- return _context11.abrupt("continue", 50);
1081
- case 46:
1510
+ return _context12.abrupt("continue", 56);
1511
+ case 52:
1082
1512
  insertIndex = updatedList.length;
1083
- updatedList.push(pendingOrder);
1084
- this.registerOrderIdentityKeys(identityKeyToIndex, pendingOrder, insertIndex);
1513
+ updatedList.push(_pendingOrder);
1514
+ this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1085
1515
  mergeActions[_storageKey] = 'insert';
1086
- case 50:
1087
- _context11.next = 37;
1516
+ case 56:
1517
+ _context12.next = 39;
1088
1518
  break;
1089
- case 52:
1090
- _context11.next = 57;
1519
+ case 58:
1520
+ _context12.next = 63;
1091
1521
  break;
1092
- case 54:
1093
- _context11.prev = 54;
1094
- _context11.t1 = _context11["catch"](35);
1095
- _iterator6.e(_context11.t1);
1096
- case 57:
1097
- _context11.prev = 57;
1098
- _iterator6.f();
1099
- return _context11.finish(57);
1100
1522
  case 60:
1101
- // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1523
+ _context12.prev = 60;
1524
+ _context12.t1 = _context12["catch"](37);
1525
+ _iterator7.e(_context12.t1);
1526
+ case 63:
1527
+ _context12.prev = 63;
1528
+ _iterator7.f();
1529
+ return _context12.finish(63);
1530
+ case 66:
1531
+ patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1532
+ previousList = this.store.list;
1102
1533
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1103
1534
  this.syncOrdersMap();
1104
- _context11.next = 64;
1105
- return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
1106
- case 64:
1535
+ _context12.prev = 70;
1536
+ _context12.next = 73;
1537
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1538
+ case 73:
1539
+ _context12.next = 80;
1540
+ break;
1541
+ case 75:
1542
+ _context12.prev = 75;
1543
+ _context12.t2 = _context12["catch"](70);
1544
+ this.store.list = previousList;
1545
+ this.syncOrdersMap();
1546
+ throw _context12.t2;
1547
+ case 80:
1107
1548
  this.logInfo('upsertPendingSyncOrders-结束', {
1108
1549
  count: patchedOrders.length,
1109
1550
  storeOrderCountAfter: this.store.list.length
1110
1551
  });
1111
- _context11.next = 67;
1552
+ _context12.next = 83;
1112
1553
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1113
- case 67:
1554
+ case 83:
1114
1555
  case "end":
1115
- return _context11.stop();
1556
+ return _context12.stop();
1116
1557
  }
1117
- }, _callee11, this, [[6, 19, 22, 25], [35, 54, 57, 60]]);
1558
+ }, _callee12, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1118
1559
  }));
1119
- function upsertPendingSyncOrders(_x7) {
1560
+ function upsertPendingSyncOrders(_x9) {
1120
1561
  return _upsertPendingSyncOrders.apply(this, arguments);
1121
1562
  }
1122
1563
  return upsertPendingSyncOrders;
1123
1564
  }()
1565
+ /**
1566
+ * 将 POS 草稿订单按 SQLite storage key 落库。
1567
+ * 只有具备真实 order_id 的草稿进入 store;其余草稿仅供本地恢复查询。
1568
+ */
1569
+ )
1570
+ }, {
1571
+ key: "upsertLocalDraftOrders",
1572
+ value: (function () {
1573
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(draftOrders) {
1574
+ var _this10 = this;
1575
+ var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, mergedOrder, nextOrder, insertIndex, previousList, removedLegacyMemoryDraft;
1576
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1577
+ while (1) switch (_context13.prev = _context13.next) {
1578
+ case 0:
1579
+ if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1580
+ _context13.next = 3;
1581
+ break;
1582
+ }
1583
+ this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1584
+ return _context13.abrupt("return");
1585
+ case 3:
1586
+ draftMap = new Map();
1587
+ memoryDraftMap = new Map();
1588
+ _iterator8 = _createForOfIteratorHelper(draftOrders);
1589
+ _context13.prev = 6;
1590
+ _iterator8.s();
1591
+ case 8:
1592
+ if ((_step8 = _iterator8.n()).done) {
1593
+ _context13.next = 19;
1594
+ break;
1595
+ }
1596
+ order = _step8.value;
1597
+ draftOrder = _objectSpread(_objectSpread({}, order), {}, {
1598
+ need_sync: 0,
1599
+ is_draft_order: 1
1600
+ });
1601
+ storageKey = this.getOrderStorageKey(draftOrder);
1602
+ if (storageKey) {
1603
+ _context13.next = 14;
1604
+ break;
1605
+ }
1606
+ return _context13.abrupt("continue", 17);
1607
+ case 14:
1608
+ draftMap.set(storageKey, draftOrder);
1609
+ memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
1610
+ if (this.shouldKeepOrderInMemory(memoryDraftOrder)) {
1611
+ memoryDraftMap.set(storageKey, memoryDraftOrder);
1612
+ }
1613
+ case 17:
1614
+ _context13.next = 8;
1615
+ break;
1616
+ case 19:
1617
+ _context13.next = 24;
1618
+ break;
1619
+ case 21:
1620
+ _context13.prev = 21;
1621
+ _context13.t0 = _context13["catch"](6);
1622
+ _iterator8.e(_context13.t0);
1623
+ case 24:
1624
+ _context13.prev = 24;
1625
+ _iterator8.f();
1626
+ return _context13.finish(24);
1627
+ case 27:
1628
+ if (!(draftMap.size === 0)) {
1629
+ _context13.next = 30;
1630
+ break;
1631
+ }
1632
+ this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1633
+ count: draftOrders.length
1634
+ });
1635
+ return _context13.abrupt("return");
1636
+ case 30:
1637
+ this.logInfo('upsertLocalDraftOrders-开始', {
1638
+ count: draftMap.size,
1639
+ memoryDraftCount: memoryDraftMap.size,
1640
+ sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
1641
+ });
1642
+ patchedOrders = _toConsumableArray(draftMap.values());
1643
+ mergeActions = {};
1644
+ updatedList = this.store.list.filter(function (order) {
1645
+ return _this10.shouldKeepOrderInMemory(order);
1646
+ });
1647
+ identityKeyToIndex = new Map();
1648
+ for (index = 0; index < updatedList.length; index += 1) {
1649
+ _iterator9 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1650
+ try {
1651
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1652
+ key = _step9.value;
1653
+ if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1654
+ }
1655
+ } catch (err) {
1656
+ _iterator9.e(err);
1657
+ } finally {
1658
+ _iterator9.f();
1659
+ }
1660
+ }
1661
+ _iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
1662
+ _context13.prev = 37;
1663
+ _iterator10.s();
1664
+ case 39:
1665
+ if ((_step10 = _iterator10.n()).done) {
1666
+ _context13.next = 55;
1667
+ break;
1668
+ }
1669
+ _step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
1670
+ matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1671
+ if (!(matchIndex >= 0)) {
1672
+ _context13.next = 49;
1673
+ break;
1674
+ }
1675
+ mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], _draftOrder);
1676
+ nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
1677
+ need_sync: 0,
1678
+ is_draft_order: 1
1679
+ });
1680
+ updatedList[matchIndex] = nextOrder;
1681
+ this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1682
+ mergeActions[_storageKey2] = 'update';
1683
+ return _context13.abrupt("continue", 53);
1684
+ case 49:
1685
+ insertIndex = updatedList.length;
1686
+ updatedList.push(_draftOrder);
1687
+ this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1688
+ mergeActions[_storageKey2] = 'insert';
1689
+ case 53:
1690
+ _context13.next = 39;
1691
+ break;
1692
+ case 55:
1693
+ _context13.next = 60;
1694
+ break;
1695
+ case 57:
1696
+ _context13.prev = 57;
1697
+ _context13.t1 = _context13["catch"](37);
1698
+ _iterator10.e(_context13.t1);
1699
+ case 60:
1700
+ _context13.prev = 60;
1701
+ _iterator10.f();
1702
+ return _context13.finish(60);
1703
+ case 63:
1704
+ previousList = this.store.list;
1705
+ this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
1706
+ this.syncOrdersMap();
1707
+ _context13.prev = 66;
1708
+ _context13.next = 69;
1709
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
1710
+ throwOnError: true
1711
+ });
1712
+ case 69:
1713
+ _context13.next = 76;
1714
+ break;
1715
+ case 71:
1716
+ _context13.prev = 71;
1717
+ _context13.t2 = _context13["catch"](66);
1718
+ this.store.list = previousList;
1719
+ this.syncOrdersMap();
1720
+ throw _context13.t2;
1721
+ case 76:
1722
+ this.logInfo('upsertLocalDraftOrders-结束', {
1723
+ count: patchedOrders.length,
1724
+ storeOrderCountAfter: this.store.list.length
1725
+ });
1726
+ removedLegacyMemoryDraft = previousList.some(function (order) {
1727
+ return !_this10.shouldKeepOrderInMemory(order);
1728
+ });
1729
+ if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1730
+ _context13.next = 81;
1731
+ break;
1732
+ }
1733
+ _context13.next = 81;
1734
+ return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1735
+ return _this10.shouldKeepOrderInMemory(order);
1736
+ }), 'upsertLocalDraftOrders');
1737
+ case 81:
1738
+ case "end":
1739
+ return _context13.stop();
1740
+ }
1741
+ }, _callee13, this, [[6, 21, 24, 27], [37, 57, 60, 63], [66, 71]]);
1742
+ }));
1743
+ function upsertLocalDraftOrders(_x10) {
1744
+ return _upsertLocalDraftOrders.apply(this, arguments);
1745
+ }
1746
+ return upsertLocalDraftOrders;
1747
+ }()
1124
1748
  /**
1125
1749
  * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
1126
1750
  */
@@ -1128,42 +1752,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1128
1752
  }, {
1129
1753
  key: "fetchOrdersBySSE",
1130
1754
  value: (function () {
1131
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1755
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1132
1756
  var query,
1133
1757
  data,
1134
- _args12 = arguments;
1135
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1136
- while (1) switch (_context12.prev = _context12.next) {
1758
+ _args14 = arguments;
1759
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1760
+ while (1) switch (_context14.prev = _context14.next) {
1137
1761
  case 0:
1138
- query = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1762
+ query = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
1139
1763
  if (this.orderDataSource) {
1140
- _context12.next = 3;
1764
+ _context14.next = 3;
1141
1765
  break;
1142
1766
  }
1143
- return _context12.abrupt("return", []);
1767
+ return _context14.abrupt("return", []);
1144
1768
  case 3:
1145
- _context12.prev = 3;
1146
- _context12.next = 6;
1769
+ _context14.prev = 3;
1770
+ _context14.next = 6;
1147
1771
  return this.orderDataSource.run({
1148
1772
  sse: {
1149
1773
  query: query
1150
1774
  }
1151
1775
  });
1152
1776
  case 6:
1153
- data = _context12.sent;
1154
- return _context12.abrupt("return", data || []);
1777
+ data = _context14.sent;
1778
+ return _context14.abrupt("return", data || []);
1155
1779
  case 10:
1156
- _context12.prev = 10;
1157
- _context12.t0 = _context12["catch"](3);
1780
+ _context14.prev = 10;
1781
+ _context14.t0 = _context14["catch"](3);
1158
1782
  this.logError('fetchOrdersBySSE-失败', {
1159
- error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0)
1783
+ error: _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0)
1160
1784
  });
1161
- return _context12.abrupt("return", []);
1785
+ return _context14.abrupt("return", []);
1162
1786
  case 14:
1163
1787
  case "end":
1164
- return _context12.stop();
1788
+ return _context14.stop();
1165
1789
  }
1166
- }, _callee12, this, [[3, 10]]);
1790
+ }, _callee14, this, [[3, 10]]);
1167
1791
  }));
1168
1792
  function fetchOrdersBySSE() {
1169
1793
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -1191,20 +1815,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1191
1815
  }, {
1192
1816
  key: "syncOrdersMap",
1193
1817
  value: function syncOrdersMap() {
1818
+ var _this11 = this;
1819
+ this.store.list = this.store.list.filter(function (order) {
1820
+ return _this11.shouldKeepOrderInMemory(order);
1821
+ });
1194
1822
  this.store.map.clear();
1195
- var _iterator7 = _createForOfIteratorHelper(this.store.list),
1196
- _step7;
1823
+ var _iterator11 = _createForOfIteratorHelper(this.store.list),
1824
+ _step11;
1197
1825
  try {
1198
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1199
- var order = _step7.value;
1826
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1827
+ var order = _step11.value;
1200
1828
  var primaryIdentity = this.getOrderMapKey(order);
1201
1829
  if (!primaryIdentity) continue;
1202
1830
  this.store.map.set(primaryIdentity, order);
1203
1831
  }
1204
1832
  } catch (err) {
1205
- _iterator7.e(err);
1833
+ _iterator11.e(err);
1206
1834
  } finally {
1207
- _iterator7.f();
1835
+ _iterator11.f();
1208
1836
  }
1209
1837
  }
1210
1838
  }, {
@@ -1228,7 +1856,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1228
1856
  }, {
1229
1857
  key: "getOrderIdentityEntries",
1230
1858
  value: function getOrderIdentityEntries(order) {
1231
- var _this10 = this;
1859
+ var _this12 = this;
1232
1860
  if (!order) return [];
1233
1861
  var record = order;
1234
1862
  var candidates = [{
@@ -1246,9 +1874,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1246
1874
  }];
1247
1875
  var entries = [];
1248
1876
  var _loop = function _loop() {
1249
- var candidate = _candidates[_i];
1250
- if (_this10.isBlankIdentityValue(candidate.value)) return 0; // continue
1251
- var key = _this10.getIdKey(candidate.value);
1877
+ var candidate = _candidates[_i2];
1878
+ if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
1879
+ var key = _this12.getIdKey(candidate.value);
1252
1880
  if (entries.some(function (entry) {
1253
1881
  return entry.field === candidate.field && entry.key === key;
1254
1882
  })) return 0; // continue
@@ -1258,7 +1886,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1258
1886
  });
1259
1887
  },
1260
1888
  _ret;
1261
- for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
1889
+ for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
1262
1890
  _ret = _loop();
1263
1891
  if (_ret === 0) continue;
1264
1892
  }
@@ -1268,17 +1896,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1268
1896
  key: "getOrderIdentityKeys",
1269
1897
  value: function getOrderIdentityKeys(order) {
1270
1898
  var keys = [];
1271
- var _iterator8 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1272
- _step8;
1899
+ var _iterator12 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1900
+ _step12;
1273
1901
  try {
1274
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1275
- var entry = _step8.value;
1902
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1903
+ var entry = _step12.value;
1276
1904
  if (!keys.includes(entry.key)) keys.push(entry.key);
1277
1905
  }
1278
1906
  } catch (err) {
1279
- _iterator8.e(err);
1907
+ _iterator12.e(err);
1280
1908
  } finally {
1281
- _iterator8.f();
1909
+ _iterator12.f();
1282
1910
  }
1283
1911
  return keys;
1284
1912
  }
@@ -1287,8 +1915,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1287
1915
  value: function getOrderDateKey(order) {
1288
1916
  var _order$bookings, _order$bookings2;
1289
1917
  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];
1290
- for (var _i2 = 0, _candidates2 = candidates; _i2 < _candidates2.length; _i2++) {
1291
- var v = _candidates2[_i2];
1918
+ for (var _i3 = 0, _candidates2 = candidates; _i3 < _candidates2.length; _i3++) {
1919
+ var v = _candidates2[_i3];
1292
1920
  if (!v) continue;
1293
1921
  var text = String(v);
1294
1922
  if (!text) continue;
@@ -1315,7 +1943,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1315
1943
  }, {
1316
1944
  key: "setupOrderSync",
1317
1945
  value: function setupOrderSync() {
1318
- var _this11 = this;
1946
+ var _this13 = this;
1319
1947
  if (!this.orderDataSource) return;
1320
1948
  this.orderDataSource.run({
1321
1949
  pubsub: {
@@ -1323,22 +1951,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1323
1951
  var _message$id, _message$order_id, _message$type;
1324
1952
  console.log('orderDataSource', res);
1325
1953
  var pubsubReceivedAt = Date.now();
1326
- var message = _this11.normalizeOrderSyncMessage(res);
1954
+ var message = _this13.normalizeOrderSyncMessage(res);
1327
1955
  if (!message) return;
1328
1956
  message._pubsubReceivedAt = pubsubReceivedAt;
1329
- _this11.pendingSyncMessages.push(message);
1330
- var throttleMs = _this11.getOrderSyncThrottleMs();
1331
- var routeInfo = _this11.resolveSyncMessageRoute(message);
1332
- _this11.logInfo('orderSync-收到消息并入队', {
1957
+ _this13.pendingSyncMessages.push(message);
1958
+ var throttleMs = _this13.getOrderSyncThrottleMs();
1959
+ var routeInfo = _this13.resolveSyncMessageRoute(message);
1960
+ _this13.logInfo('orderSync-收到消息并入队', {
1333
1961
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
1334
1962
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
1335
1963
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
1336
- pendingCount: _this11.pendingSyncMessages.length,
1964
+ pendingCount: _this13.pendingSyncMessages.length,
1337
1965
  throttleMs: throttleMs,
1338
1966
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
1339
1967
  fullMessage: JSON.stringify(message)
1340
1968
  });
1341
- _this11.scheduleOrderSyncThrottle();
1969
+ _this13.scheduleOrderSyncThrottle();
1342
1970
  }
1343
1971
  }
1344
1972
  }).catch(function () {
@@ -1355,7 +1983,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1355
1983
  }, {
1356
1984
  key: "scheduleOrderSyncThrottle",
1357
1985
  value: function scheduleOrderSyncThrottle() {
1358
- var _this12 = this;
1986
+ var _this14 = this;
1359
1987
  if (this.isProcessingSyncBatch) return;
1360
1988
  if (this.isIdlePhase) {
1361
1989
  this.isIdlePhase = false;
@@ -1366,8 +1994,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1366
1994
  if (this.syncTimer) return;
1367
1995
  var throttleMs = this.getOrderSyncThrottleMs();
1368
1996
  this.syncTimer = setTimeout(function () {
1369
- _this12.syncTimer = undefined;
1370
- void _this12.flushOrderSyncMessagesByThrottle();
1997
+ _this14.syncTimer = undefined;
1998
+ void _this14.flushOrderSyncMessagesByThrottle();
1371
1999
  }, throttleMs);
1372
2000
  }
1373
2001
 
@@ -1378,41 +2006,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1378
2006
  }, {
1379
2007
  key: "flushOrderSyncMessagesByThrottle",
1380
2008
  value: (function () {
1381
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1382
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1383
- while (1) switch (_context13.prev = _context13.next) {
2009
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
2010
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2011
+ while (1) switch (_context15.prev = _context15.next) {
1384
2012
  case 0:
1385
2013
  if (!this.isProcessingSyncBatch) {
1386
- _context13.next = 2;
2014
+ _context15.next = 2;
1387
2015
  break;
1388
2016
  }
1389
- return _context13.abrupt("return");
2017
+ return _context15.abrupt("return");
1390
2018
  case 2:
1391
2019
  if (!(this.pendingSyncMessages.length === 0)) {
1392
- _context13.next = 5;
2020
+ _context15.next = 5;
1393
2021
  break;
1394
2022
  }
1395
2023
  this.isIdlePhase = true;
1396
- return _context13.abrupt("return");
2024
+ return _context15.abrupt("return");
1397
2025
  case 5:
1398
2026
  this.isProcessingSyncBatch = true;
1399
- _context13.prev = 6;
1400
- _context13.next = 9;
2027
+ _context15.prev = 6;
2028
+ _context15.next = 9;
1401
2029
  return this.processOrderSyncMessages();
1402
2030
  case 9:
1403
- _context13.prev = 9;
2031
+ _context15.prev = 9;
1404
2032
  this.isProcessingSyncBatch = false;
1405
2033
  if (this.pendingSyncMessages.length > 0) {
1406
2034
  this.scheduleOrderSyncThrottle();
1407
2035
  } else {
1408
2036
  this.isIdlePhase = true;
1409
2037
  }
1410
- return _context13.finish(9);
2038
+ return _context15.finish(9);
1411
2039
  case 13:
1412
2040
  case "end":
1413
- return _context13.stop();
2041
+ return _context15.stop();
1414
2042
  }
1415
- }, _callee13, this, [[6,, 9, 13]]);
2043
+ }, _callee15, this, [[6,, 9, 13]]);
1416
2044
  }));
1417
2045
  function flushOrderSyncMessagesByThrottle() {
1418
2046
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -1434,19 +2062,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1434
2062
  }, {
1435
2063
  key: "processOrderSyncMessages",
1436
2064
  value: (function () {
1437
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1438
- var _this13 = this;
2065
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2066
+ var _this15 = this;
1439
2067
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
1440
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1441
- while (1) switch (_context14.prev = _context14.next) {
2068
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2069
+ while (1) switch (_context16.prev = _context16.next) {
1442
2070
  case 0:
1443
2071
  messages = _toConsumableArray(this.pendingSyncMessages);
1444
2072
  this.pendingSyncMessages = [];
1445
2073
  if (!(messages.length === 0)) {
1446
- _context14.next = 4;
2074
+ _context16.next = 4;
1447
2075
  break;
1448
2076
  }
1449
- return _context14.abrupt("return");
2077
+ return _context16.abrupt("return");
1450
2078
  case 4:
1451
2079
  batchProcessStartAt = Date.now();
1452
2080
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -1462,13 +2090,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1462
2090
  upsertOrders = new Map();
1463
2091
  refreshIds = [];
1464
2092
  messages.forEach(function (msg, msgIndex) {
1465
- var routeInfo = _this13.resolveSyncMessageRoute(msg);
2093
+ var routeInfo = _this15.resolveSyncMessageRoute(msg);
1466
2094
  var hasBatchIds = routeInfo.hasBatchIds;
1467
2095
  var singleId = routeInfo.singleId;
1468
2096
  var hasSingleId = routeInfo.hasSingleId;
1469
- var normalizedBody = _this13.normalizeOrderSyncPayload(msg.body || msg.data);
2097
+ var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
1470
2098
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
1471
- upsertOrders.set(_this13.getIdKey(normalizedBody.order_id), normalizedBody);
2099
+ upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
1472
2100
  return;
1473
2101
  }
1474
2102
  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));
@@ -1480,41 +2108,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1480
2108
  refreshIdCount: uniqueRefreshIds.length
1481
2109
  });
1482
2110
  if (!(upsertList.length > 0)) {
1483
- _context14.next = 16;
2111
+ _context16.next = 16;
1484
2112
  break;
1485
2113
  }
1486
- _context14.next = 16;
2114
+ _context16.next = 16;
1487
2115
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
1488
2116
  case 16:
1489
2117
  if (!(uniqueRefreshIds.length > 0)) {
1490
- _context14.next = 28;
2118
+ _context16.next = 28;
1491
2119
  break;
1492
2120
  }
1493
2121
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
1494
2122
  if (skipped.length > 0) {}
1495
2123
  if (!(toFetch.length > 0)) {
1496
- _context14.next = 28;
2124
+ _context16.next = 28;
1497
2125
  break;
1498
2126
  }
1499
- _context14.next = 22;
2127
+ _context16.next = 22;
1500
2128
  return this.fetchOrdersByHttp(toFetch);
1501
2129
  case 22:
1502
- freshOrders = _context14.sent;
2130
+ freshOrders = _context16.sent;
1503
2131
  if (!(freshOrders.length > 0)) {
1504
- _context14.next = 28;
2132
+ _context16.next = 28;
1505
2133
  break;
1506
2134
  }
1507
- _context14.next = 26;
2135
+ _context16.next = 26;
1508
2136
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
1509
2137
  case 26:
1510
- _context14.next = 28;
2138
+ _context16.next = 28;
1511
2139
  break;
1512
2140
  case 28:
1513
2141
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
1514
- _context14.next = 30;
2142
+ _context16.next = 30;
1515
2143
  break;
1516
2144
  }
1517
- return _context14.abrupt("return");
2145
+ return _context16.abrupt("return");
1518
2146
  case 30:
1519
2147
  batchProcessEndAt = Date.now();
1520
2148
  this.logInfo('processOrderSyncMessages-结束', {
@@ -1523,13 +2151,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1523
2151
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
1524
2152
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
1525
2153
  });
1526
- _context14.next = 34;
2154
+ _context16.next = 34;
1527
2155
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1528
2156
  case 34:
1529
2157
  case "end":
1530
- return _context14.stop();
2158
+ return _context16.stop();
1531
2159
  }
1532
- }, _callee14, this);
2160
+ }, _callee16, this);
1533
2161
  }));
1534
2162
  function processOrderSyncMessages() {
1535
2163
  return _processOrderSyncMessages.apply(this, arguments);
@@ -1550,29 +2178,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1550
2178
  }, {
1551
2179
  key: "fetchOrdersByHttp",
1552
2180
  value: (function () {
1553
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
2181
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(ids) {
1554
2182
  var _orderList, orderList;
1555
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1556
- while (1) switch (_context15.prev = _context15.next) {
2183
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2184
+ while (1) switch (_context17.prev = _context17.next) {
1557
2185
  case 0:
1558
2186
  if (!(!this.orderDataSource || ids.length === 0)) {
1559
- _context15.next = 2;
2187
+ _context17.next = 2;
1560
2188
  break;
1561
2189
  }
1562
- return _context15.abrupt("return", []);
2190
+ return _context17.abrupt("return", []);
1563
2191
  case 2:
1564
- _context15.prev = 2;
2192
+ _context17.prev = 2;
1565
2193
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
1566
- _context15.next = 8;
2194
+ _context17.next = 8;
1567
2195
  break;
1568
2196
  }
1569
- _context15.next = 6;
2197
+ _context17.next = 6;
1570
2198
  return this.orderDataSource.fetchOrdersByIds(ids);
1571
2199
  case 6:
1572
- _orderList = _context15.sent;
1573
- return _context15.abrupt("return", _orderList || []);
2200
+ _orderList = _context17.sent;
2201
+ return _context17.abrupt("return", _orderList || []);
1574
2202
  case 8:
1575
- _context15.next = 10;
2203
+ _context17.next = 10;
1576
2204
  return this.orderDataSource.run({
1577
2205
  http: {
1578
2206
  query: {
@@ -1581,19 +2209,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1581
2209
  }
1582
2210
  });
1583
2211
  case 10:
1584
- orderList = _context15.sent;
1585
- return _context15.abrupt("return", orderList || []);
2212
+ orderList = _context17.sent;
2213
+ return _context17.abrupt("return", orderList || []);
1586
2214
  case 14:
1587
- _context15.prev = 14;
1588
- _context15.t0 = _context15["catch"](2);
1589
- return _context15.abrupt("return", []);
2215
+ _context17.prev = 14;
2216
+ _context17.t0 = _context17["catch"](2);
2217
+ return _context17.abrupt("return", []);
1590
2218
  case 17:
1591
2219
  case "end":
1592
- return _context15.stop();
2220
+ return _context17.stop();
1593
2221
  }
1594
- }, _callee15, this, [[2, 14]]);
2222
+ }, _callee17, this, [[2, 14]]);
1595
2223
  }));
1596
- function fetchOrdersByHttp(_x8) {
2224
+ function fetchOrdersByHttp(_x11) {
1597
2225
  return _fetchOrdersByHttp.apply(this, arguments);
1598
2226
  }
1599
2227
  return fetchOrdersByHttp;
@@ -1605,10 +2233,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1605
2233
  }, {
1606
2234
  key: "mergeOrdersToStore",
1607
2235
  value: (function () {
1608
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
1609
- var storeOrderCountBefore, normalizedFreshOrders, _iterator9, _step9, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator10, _step10, key, _iterator11, _step11, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref2, _existingOrder$order_, _ref3, _external_sale_number, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, mergedOrder, insertIndex, insertCount, updateCount;
1610
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1611
- while (1) switch (_context16.prev = _context16.next) {
2236
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(freshOrders, source) {
2237
+ var _this16 = this;
2238
+ var storeOrderCountBefore, normalizedFreshOrders, _iterator13, _step13, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator14, _step14, key, _iterator15, _step15, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, adjustedMatchIndex, duplicateIndexes, _iterator16, _step16, _key2, _duplicateIndex, _iterator17, _step17, duplicateIndex, _index, _iterator18, _step18, _key, insertIndex, insertCount, updateCount;
2239
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2240
+ while (1) switch (_context18.prev = _context18.next) {
1612
2241
  case 0:
1613
2242
  storeOrderCountBefore = this.store.list.length;
1614
2243
  this.logInfo('mergeOrdersToStore-开始', {
@@ -1618,125 +2247,206 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1618
2247
  });
1619
2248
  this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
1620
2249
  normalizedFreshOrders = [];
1621
- _iterator9 = _createForOfIteratorHelper(freshOrders);
1622
- _context16.prev = 5;
1623
- _iterator9.s();
2250
+ _iterator13 = _createForOfIteratorHelper(freshOrders);
2251
+ _context18.prev = 5;
2252
+ _iterator13.s();
1624
2253
  case 7:
1625
- if ((_step9 = _iterator9.n()).done) {
1626
- _context16.next = 15;
2254
+ if ((_step13 = _iterator13.n()).done) {
2255
+ _context18.next = 15;
1627
2256
  break;
1628
2257
  }
1629
- order = _step9.value;
2258
+ order = _step13.value;
1630
2259
  id = order === null || order === void 0 ? void 0 : order.order_id;
1631
2260
  if (!(id === undefined || id === null)) {
1632
- _context16.next = 12;
2261
+ _context18.next = 12;
1633
2262
  break;
1634
2263
  }
1635
- return _context16.abrupt("continue", 13);
2264
+ return _context18.abrupt("continue", 13);
1636
2265
  case 12:
1637
2266
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
1638
2267
  case 13:
1639
- _context16.next = 7;
2268
+ _context18.next = 7;
1640
2269
  break;
1641
2270
  case 15:
1642
- _context16.next = 20;
2271
+ _context18.next = 20;
1643
2272
  break;
1644
2273
  case 17:
1645
- _context16.prev = 17;
1646
- _context16.t0 = _context16["catch"](5);
1647
- _iterator9.e(_context16.t0);
2274
+ _context18.prev = 17;
2275
+ _context18.t0 = _context18["catch"](5);
2276
+ _iterator13.e(_context18.t0);
1648
2277
  case 20:
1649
- _context16.prev = 20;
1650
- _iterator9.f();
1651
- return _context16.finish(20);
2278
+ _context18.prev = 20;
2279
+ _iterator13.f();
2280
+ return _context18.finish(20);
1652
2281
  case 23:
1653
2282
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
1654
2283
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
1655
2284
  uniqueFreshCount = uniqueFreshOrders.length;
1656
2285
  patchedOrders = [];
1657
2286
  mergeActions = {};
1658
- updatedList = _toConsumableArray(this.store.list); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2287
+ updatedList = this.store.list.map(function (order) {
2288
+ return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2289
+ }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
1659
2290
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
1660
2291
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
1661
2292
  identityKeyToIndex = new Map();
1662
2293
  for (index = 0; index < updatedList.length; index += 1) {
1663
2294
  identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
1664
- _iterator10 = _createForOfIteratorHelper(identityKeys);
2295
+ _iterator14 = _createForOfIteratorHelper(identityKeys);
1665
2296
  try {
1666
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1667
- key = _step10.value;
2297
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2298
+ key = _step14.value;
1668
2299
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1669
2300
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1670
2301
  }
1671
2302
  } catch (err) {
1672
- _iterator10.e(err);
2303
+ _iterator14.e(err);
1673
2304
  } finally {
1674
- _iterator10.f();
2305
+ _iterator14.f();
1675
2306
  }
1676
2307
  }
1677
- _iterator11 = _createForOfIteratorHelper(uniqueFreshOrders);
1678
- _context16.prev = 31;
1679
- _iterator11.s();
2308
+ _iterator15 = _createForOfIteratorHelper(uniqueFreshOrders);
2309
+ _context18.prev = 31;
2310
+ _iterator15.s();
1680
2311
  case 33:
1681
- if ((_step11 = _iterator11.n()).done) {
1682
- _context16.next = 57;
2312
+ if ((_step15 = _iterator15.n()).done) {
2313
+ _context18.next = 82;
1683
2314
  break;
1684
2315
  }
1685
- fresh = _step11.value;
2316
+ fresh = _step15.value;
1686
2317
  freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
1687
2318
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
1688
2319
  storageKey = this.getOrderStorageKey(fresh);
1689
2320
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
1690
2321
  if (!(matchIndex >= 0)) {
1691
- _context16.next = 50;
2322
+ _context18.next = 75;
1692
2323
  break;
1693
2324
  }
1694
2325
  existingOrder = updatedList[matchIndex];
1695
2326
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
1696
- _context16.next = 44;
2327
+ _context18.next = 44;
1697
2328
  break;
1698
2329
  }
1699
- this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
1700
- source: source,
1701
- order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
1702
- external_sale_number: (_ref3 = (_external_sale_number = existingOrder.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
1703
- local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
1704
- remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
1705
- local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
1706
- remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
1707
- reason: 'protect_pending_sync_order_from_remote_echo'
1708
- });
1709
- return _context16.abrupt("continue", 55);
1710
- case 44:
1711
- mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
1712
- updatedList[matchIndex] = mergedOrder;
2330
+ this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
2331
+ source: source,
2332
+ order_id: (_ref = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref !== void 0 ? _ref : null,
2333
+ external_sale_number: (_ref2 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref2 !== void 0 ? _ref2 : null,
2334
+ local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
2335
+ remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
2336
+ local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
2337
+ remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2338
+ reason: 'protect_pending_sync_order_from_remote_echo'
2339
+ });
2340
+ return _context18.abrupt("continue", 80);
2341
+ case 44:
2342
+ if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2343
+ _context18.next = 47;
2344
+ break;
2345
+ }
2346
+ this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
2347
+ source: source,
2348
+ order_id: (_ref3 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref3 !== void 0 ? _ref3 : null,
2349
+ external_sale_number: (_ref4 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref4 !== void 0 ? _ref4 : null,
2350
+ local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
2351
+ remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2352
+ reason: 'protect_draft_order_from_remote_echo'
2353
+ });
2354
+ return _context18.abrupt("continue", 80);
2355
+ case 47:
2356
+ mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2357
+ adjustedMatchIndex = matchIndex;
2358
+ duplicateIndexes = new Set();
2359
+ _iterator16 = _createForOfIteratorHelper(freshIdentityKeys);
2360
+ _context18.prev = 51;
2361
+ _iterator16.s();
2362
+ case 53:
2363
+ if ((_step16 = _iterator16.n()).done) {
2364
+ _context18.next = 61;
2365
+ break;
2366
+ }
2367
+ _key2 = _step16.value;
2368
+ _duplicateIndex = identityKeyToIndex.get(_key2);
2369
+ if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2370
+ _context18.next = 58;
2371
+ break;
2372
+ }
2373
+ return _context18.abrupt("continue", 59);
2374
+ case 58:
2375
+ duplicateIndexes.add(_duplicateIndex);
2376
+ case 59:
2377
+ _context18.next = 53;
2378
+ break;
2379
+ case 61:
2380
+ _context18.next = 66;
2381
+ break;
2382
+ case 63:
2383
+ _context18.prev = 63;
2384
+ _context18.t1 = _context18["catch"](51);
2385
+ _iterator16.e(_context18.t1);
2386
+ case 66:
2387
+ _context18.prev = 66;
2388
+ _iterator16.f();
2389
+ return _context18.finish(66);
2390
+ case 69:
2391
+ if (duplicateIndexes.size > 0) {
2392
+ _iterator17 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2393
+ return right - left;
2394
+ }));
2395
+ try {
2396
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2397
+ duplicateIndex = _step17.value;
2398
+ mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
2399
+ updatedList.splice(duplicateIndex, 1);
2400
+ if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
2401
+ }
2402
+ } catch (err) {
2403
+ _iterator17.e(err);
2404
+ } finally {
2405
+ _iterator17.f();
2406
+ }
2407
+ identityKeyToIndex.clear();
2408
+ for (_index = 0; _index < updatedList.length; _index += 1) {
2409
+ _iterator18 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
2410
+ try {
2411
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2412
+ _key = _step18.value;
2413
+ if (!identityKeyToIndex.has(_key)) identityKeyToIndex.set(_key, _index);
2414
+ }
2415
+ } catch (err) {
2416
+ _iterator18.e(err);
2417
+ } finally {
2418
+ _iterator18.f();
2419
+ }
2420
+ }
2421
+ }
2422
+ updatedList[adjustedMatchIndex] = mergedOrder;
1713
2423
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
1714
2424
  // 供同批后续 fresh 命中同一槽位,避免重复插入
1715
- this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
2425
+ this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
1716
2426
  patchedOrders.push(mergedOrder);
1717
2427
  if (mergeKey) mergeActions[mergeKey] = 'update';
1718
- return _context16.abrupt("continue", 55);
1719
- case 50:
2428
+ return _context18.abrupt("continue", 80);
2429
+ case 75:
1720
2430
  insertIndex = updatedList.length;
1721
2431
  updatedList.push(fresh);
1722
2432
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
1723
2433
  patchedOrders.push(fresh);
1724
2434
  if (mergeKey) mergeActions[mergeKey] = 'insert';
1725
- case 55:
1726
- _context16.next = 33;
2435
+ case 80:
2436
+ _context18.next = 33;
1727
2437
  break;
1728
- case 57:
1729
- _context16.next = 62;
2438
+ case 82:
2439
+ _context18.next = 87;
1730
2440
  break;
1731
- case 59:
1732
- _context16.prev = 59;
1733
- _context16.t1 = _context16["catch"](31);
1734
- _iterator11.e(_context16.t1);
1735
- case 62:
1736
- _context16.prev = 62;
1737
- _iterator11.f();
1738
- return _context16.finish(62);
1739
- case 65:
2441
+ case 84:
2442
+ _context18.prev = 84;
2443
+ _context18.t2 = _context18["catch"](31);
2444
+ _iterator15.e(_context18.t2);
2445
+ case 87:
2446
+ _context18.prev = 87;
2447
+ _iterator15.f();
2448
+ return _context18.finish(87);
2449
+ case 90:
1740
2450
  insertCount = Object.values(mergeActions).filter(function (v) {
1741
2451
  return v === 'insert';
1742
2452
  }).length;
@@ -1752,24 +2462,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1752
2462
  // 仅在自检开关开启时做一次兜底校验。
1753
2463
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
1754
2464
  this.syncOrdersMap();
1755
- _context16.next = 72;
2465
+ _context18.next = 97;
1756
2466
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1757
- case 72:
2467
+ case 97:
1758
2468
  this.logInfo('mergeOrdersToStore-结束', {
1759
2469
  uniqueFreshCount: uniqueFreshCount,
1760
2470
  storeOrderCountAfter: this.store.list.length,
1761
2471
  insertCount: insertCount,
1762
2472
  updateCount: updateCount
1763
2473
  });
1764
- _context16.next = 75;
2474
+ _context18.next = 100;
1765
2475
  return this.emitOrdersChanged(patchedOrders, source);
1766
- case 75:
2476
+ case 100:
1767
2477
  case "end":
1768
- return _context16.stop();
2478
+ return _context18.stop();
1769
2479
  }
1770
- }, _callee16, this, [[5, 17, 20, 23], [31, 59, 62, 65]]);
2480
+ }, _callee18, this, [[5, 17, 20, 23], [31, 84, 87, 90], [51, 63, 66, 69]]);
1771
2481
  }));
1772
- function mergeOrdersToStore(_x9, _x10) {
2482
+ function mergeOrdersToStore(_x12, _x13) {
1773
2483
  return _mergeOrdersToStore.apply(this, arguments);
1774
2484
  }
1775
2485
  return mergeOrdersToStore;
@@ -1786,19 +2496,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1786
2496
  key: "lookupOrderIndexByIdentityKeys",
1787
2497
  value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
1788
2498
  var matchIndex = -1;
1789
- var _iterator12 = _createForOfIteratorHelper(identityKeys),
1790
- _step12;
2499
+ var _iterator19 = _createForOfIteratorHelper(identityKeys),
2500
+ _step19;
1791
2501
  try {
1792
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1793
- var key = _step12.value;
2502
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2503
+ var key = _step19.value;
1794
2504
  var index = identityKeyToIndex.get(key);
1795
2505
  if (index === undefined) continue;
1796
2506
  if (matchIndex < 0 || index < matchIndex) matchIndex = index;
1797
2507
  }
1798
2508
  } catch (err) {
1799
- _iterator12.e(err);
2509
+ _iterator19.e(err);
1800
2510
  } finally {
1801
- _iterator12.f();
2511
+ _iterator19.f();
1802
2512
  }
1803
2513
  return matchIndex;
1804
2514
  }
@@ -1819,17 +2529,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1819
2529
  key: "registerOrderIdentityKeys",
1820
2530
  value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
1821
2531
  var identityKeys = this.getOrderIdentityMatchKeys(order);
1822
- var _iterator13 = _createForOfIteratorHelper(identityKeys),
1823
- _step13;
2532
+ var _iterator20 = _createForOfIteratorHelper(identityKeys),
2533
+ _step20;
1824
2534
  try {
1825
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1826
- var key = _step13.value;
2535
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2536
+ var key = _step20.value;
1827
2537
  identityKeyToIndex.set(key, index);
1828
2538
  }
1829
2539
  } catch (err) {
1830
- _iterator13.e(err);
2540
+ _iterator20.e(err);
1831
2541
  } finally {
1832
- _iterator13.f();
2542
+ _iterator20.f();
1833
2543
  }
1834
2544
  }
1835
2545
 
@@ -1884,17 +2594,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1884
2594
  key: "uniqueOrderIds",
1885
2595
  value: function uniqueOrderIds(ids) {
1886
2596
  var idMap = new Map();
1887
- var _iterator14 = _createForOfIteratorHelper(ids),
1888
- _step14;
2597
+ var _iterator21 = _createForOfIteratorHelper(ids),
2598
+ _step21;
1889
2599
  try {
1890
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1891
- var id = _step14.value;
2600
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2601
+ var id = _step21.value;
1892
2602
  idMap.set(this.getIdKey(id), id);
1893
2603
  }
1894
2604
  } catch (err) {
1895
- _iterator14.e(err);
2605
+ _iterator21.e(err);
1896
2606
  } finally {
1897
- _iterator14.f();
2607
+ _iterator21.f();
1898
2608
  }
1899
2609
  return _toConsumableArray(idMap.values());
1900
2610
  }
@@ -1906,12 +2616,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1906
2616
  }, {
1907
2617
  key: "isOrderLookupMatch",
1908
2618
  value: function isOrderLookupMatch(order, lookupKey) {
1909
- var _this14 = this;
2619
+ var _this17 = this;
1910
2620
  if (!order || !lookupKey) return false;
1911
2621
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
1912
2622
  return candidates.some(function (value) {
1913
2623
  if (value === undefined || value === null || value === '') return false;
1914
- return _this14.getIdKey(value) === lookupKey;
2624
+ return _this17.getIdKey(value) === lookupKey;
1915
2625
  });
1916
2626
  }
1917
2627
 
@@ -1954,10 +2664,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1954
2664
  }, {
1955
2665
  key: "findOrderIndexByIdentity",
1956
2666
  value: function findOrderIndexByIdentity(orders, target) {
1957
- var _this15 = this;
2667
+ var _this18 = this;
1958
2668
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
1959
2669
  return orders.findIndex(function (order) {
1960
- return _this15.doOrdersShareIdentity(order, target);
2670
+ return _this18.doOrdersShareIdentity(order, target);
1961
2671
  });
1962
2672
  }
1963
2673
  }, {
@@ -2006,128 +2716,112 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2006
2716
  if (secondaryList.length === 0) return preferredList;
2007
2717
  if (preferredList.length === 0) return secondaryList;
2008
2718
  var seenKeys = new Set();
2009
- var _iterator15 = _createForOfIteratorHelper(preferredList),
2010
- _step15;
2719
+ var _iterator22 = _createForOfIteratorHelper(preferredList),
2720
+ _step22;
2011
2721
  try {
2012
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2013
- var item = _step15.value;
2722
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
2723
+ var item = _step22.value;
2014
2724
  var keys = this.getProductIdentityKeys(item);
2015
- var _iterator17 = _createForOfIteratorHelper(keys),
2016
- _step17;
2725
+ var _iterator24 = _createForOfIteratorHelper(keys),
2726
+ _step24;
2017
2727
  try {
2018
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2019
- var key = _step17.value;
2728
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
2729
+ var key = _step24.value;
2020
2730
  seenKeys.add(key);
2021
2731
  }
2022
2732
  } catch (err) {
2023
- _iterator17.e(err);
2733
+ _iterator24.e(err);
2024
2734
  } finally {
2025
- _iterator17.f();
2735
+ _iterator24.f();
2026
2736
  }
2027
2737
  }
2028
2738
  } catch (err) {
2029
- _iterator15.e(err);
2739
+ _iterator22.e(err);
2030
2740
  } finally {
2031
- _iterator15.f();
2741
+ _iterator22.f();
2032
2742
  }
2033
2743
  var result = _toConsumableArray(preferredList);
2034
- var _iterator16 = _createForOfIteratorHelper(secondaryList),
2035
- _step16;
2744
+ var _iterator23 = _createForOfIteratorHelper(secondaryList),
2745
+ _step23;
2036
2746
  try {
2037
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2038
- var _item = _step16.value;
2747
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
2748
+ var _item = _step23.value;
2039
2749
  var _keys = this.getProductIdentityKeys(_item);
2040
2750
  if (_keys.length === 0 || _keys.some(function (key) {
2041
2751
  return seenKeys.has(key);
2042
2752
  })) continue;
2043
- var _iterator18 = _createForOfIteratorHelper(_keys),
2044
- _step18;
2753
+ var _iterator25 = _createForOfIteratorHelper(_keys),
2754
+ _step25;
2045
2755
  try {
2046
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2047
- var _key = _step18.value;
2048
- seenKeys.add(_key);
2756
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
2757
+ var _key3 = _step25.value;
2758
+ seenKeys.add(_key3);
2049
2759
  }
2050
2760
  } catch (err) {
2051
- _iterator18.e(err);
2761
+ _iterator25.e(err);
2052
2762
  } finally {
2053
- _iterator18.f();
2763
+ _iterator25.f();
2054
2764
  }
2055
2765
  result.push(cloneDeep(_item));
2056
2766
  }
2057
2767
  } catch (err) {
2058
- _iterator16.e(err);
2768
+ _iterator23.e(err);
2059
2769
  } finally {
2060
- _iterator16.f();
2770
+ _iterator23.f();
2061
2771
  }
2062
2772
  return result;
2063
2773
  }
2064
- }, {
2065
- key: "getPaymentMergeKey",
2066
- value: function getPaymentMergeKey(payment) {
2067
- var _record$metadata2;
2068
- var record = payment;
2069
- if (!record) return '';
2070
- var uniquePaymentNumber = (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.unique_payment_number;
2071
- if (!this.isBlankIdentityValue(uniquePaymentNumber)) {
2072
- return "unique:".concat(String(uniquePaymentNumber));
2073
- }
2074
- var orderPaymentId = record.order_payment_id;
2075
- if (!this.isBlankIdentityValue(orderPaymentId)) return "order_payment:".concat(String(orderPaymentId));
2076
- var code = record.code;
2077
- var customPaymentId = record.custom_payment_id;
2078
- if (!this.isBlankIdentityValue(code) && !this.isBlankIdentityValue(customPaymentId)) {
2079
- return "custom:".concat(String(code), "#").concat(String(customPaymentId));
2080
- }
2081
- return '';
2082
- }
2083
2774
  }, {
2084
2775
  key: "mergeOrderPaymentLists",
2085
2776
  value: function mergeOrderPaymentLists(existing, incoming) {
2086
- var _this16 = this;
2087
2777
  var existingList = Array.isArray(existing) ? existing : [];
2088
2778
  var incomingList = Array.isArray(incoming) ? incoming : [];
2089
2779
  if (incomingList.length === 0) return cloneDeep(existingList);
2090
- if (existingList.length === 0) return cloneDeep(incomingList);
2091
- var existingByKey = new Map();
2092
- var _iterator19 = _createForOfIteratorHelper(existingList),
2093
- _step19;
2094
- try {
2095
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2096
- var payment = _step19.value;
2097
- var key = this.getPaymentMergeKey(payment);
2098
- if (!key) continue;
2099
- existingByKey.set(key, payment);
2100
- }
2101
- } catch (err) {
2102
- _iterator19.e(err);
2103
- } finally {
2104
- _iterator19.f();
2105
- }
2106
- return incomingList.map(function (payment) {
2107
- var incomingPayment = payment;
2108
- var key = _this16.getPaymentMergeKey(incomingPayment);
2109
- var existingPayment = key ? existingByKey.get(key) : undefined;
2110
- if (!existingPayment) return cloneDeep(incomingPayment);
2111
- return _objectSpread(_objectSpread(_objectSpread({}, cloneDeep(existingPayment)), cloneDeep(incomingPayment)), {}, {
2112
- metadata: _objectSpread(_objectSpread({}, cloneDeep(existingPayment.metadata || {})), cloneDeep(incomingPayment.metadata || {}))
2780
+ return mergeOrderPaymentListsByIdentity(existingList, incomingList);
2781
+ }
2782
+ }, {
2783
+ key: "getIdentifiedPendingPayments",
2784
+ value: function getIdentifiedPendingPayments(order) {
2785
+ var payments = Array.isArray(order === null || order === void 0 ? void 0 : order.payments) ? order.payments : [];
2786
+ return payments.filter(function (payment) {
2787
+ return isIdentifiedPendingOrderPayment(payment);
2788
+ });
2789
+ }
2790
+ }, {
2791
+ key: "shouldProtectLocalOrderFromRemoteSnapshot",
2792
+ value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
2793
+ return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
2794
+ }
2795
+ }, {
2796
+ key: "getUnmatchedIdentifiedPendingPayments",
2797
+ value: function getUnmatchedIdentifiedPendingPayments(existing, incoming) {
2798
+ var existingPayments = Array.isArray(existing) ? existing : [];
2799
+ var incomingPayments = Array.isArray(incoming) ? incoming : [];
2800
+ var incomingIdentityKeys = new Set(incomingPayments.flatMap(function (payment) {
2801
+ return getOrderPaymentIdentityKeys(payment);
2802
+ }));
2803
+ return existingPayments.filter(function (payment) {
2804
+ return isIdentifiedPendingOrderPayment(payment) && !getOrderPaymentIdentityKeys(payment).some(function (key) {
2805
+ return incomingIdentityKeys.has(key);
2113
2806
  });
2114
2807
  });
2115
2808
  }
2116
2809
  }, {
2117
2810
  key: "mergeOrderRecords",
2118
- value: function mergeOrderRecords(existing, incoming, options) {
2811
+ value: function mergeOrderRecords(existing, incoming) {
2119
2812
  var preferred = this.pickPreferredOrder(existing, incoming);
2120
2813
  var secondary = preferred === existing ? incoming : existing;
2121
2814
  var merged = _objectSpread(_objectSpread({}, secondary), preferred);
2122
2815
  var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
2123
- var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'products', 'bookings', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms'];
2816
+ var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms', 'is_draft_order'];
2124
2817
  var mergedRecord = merged;
2125
2818
  var preferredRecord = preferred;
2126
2819
  var secondaryRecord = secondary;
2820
+ var existingRecord = existing;
2127
2821
  var incomingRecord = incoming;
2128
- var previousRecord = preferred === incoming ? secondaryRecord : preferredRecord;
2129
- for (var _i3 = 0, _fieldsToPreserve = fieldsToPreserve; _i3 < _fieldsToPreserve.length; _i3++) {
2130
- var field = _fieldsToPreserve[_i3];
2822
+ var childUidRemaps = [];
2823
+ for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
2824
+ var field = _fieldsToPreserve[_i4];
2131
2825
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
2132
2826
  mergedRecord[field] = preferredRecord[field];
2133
2827
  continue;
@@ -2136,76 +2830,98 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2136
2830
  mergedRecord[field] = secondaryRecord[field];
2137
2831
  }
2138
2832
  }
2139
- var hasIncomingProducts = Object.prototype.hasOwnProperty.call(incomingRecord, 'products');
2140
- var shouldUseIncomingProductsSnapshot = (options === null || options === void 0 ? void 0 : options.preferIncomingProducts) === true && hasIncomingProducts && incomingRecord.products !== undefined && incomingRecord.products !== null;
2141
- for (var _i4 = 0, _incomingPatchFields = incomingPatchFields; _i4 < _incomingPatchFields.length; _i4++) {
2142
- var _field = _incomingPatchFields[_i4];
2833
+ for (var _i5 = 0, _incomingPatchFields = incomingPatchFields; _i5 < _incomingPatchFields.length; _i5++) {
2834
+ var _field = _incomingPatchFields[_i5];
2143
2835
  if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
2144
2836
  if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
2145
2837
  if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
2146
2838
  mergedRecord[_field] = cloneDeep(incomingRecord[_field]);
2147
2839
  }
2148
- mergedRecord.products = shouldUseIncomingProductsSnapshot ? cloneDeep(incomingRecord.products) : this.mergeOrderProductLists(preferredRecord.products, secondaryRecord.products);
2149
- if (Object.prototype.hasOwnProperty.call(incomingRecord, 'payments')) {
2150
- if (Array.isArray(incomingRecord.payments)) {
2151
- mergedRecord.payments = this.mergeOrderPaymentLists(previousRecord.payments, incomingRecord.payments);
2152
- } else if (incomingRecord.payments !== undefined && incomingRecord.payments !== null) {
2153
- mergedRecord.payments = cloneDeep(incomingRecord.payments);
2840
+
2841
+ // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
2842
+ // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
2843
+ for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
2844
+ var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
2845
+ if (Array.isArray(incomingRecord[_field2])) {
2846
+ if (_field2 === 'payments') {
2847
+ var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
2848
+ if (preservedPending.length > 0) {
2849
+ var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
2850
+ this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
2851
+ order_id: (_ref5 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
2852
+ external_sale_number: (_ref6 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref6 !== void 0 ? _ref6 : null,
2853
+ preserved_pending_count: preservedPending.length,
2854
+ preserved_payment_identities: preservedPending.map(function (payment) {
2855
+ return getOrderPaymentIdentityKeys(payment);
2856
+ })
2857
+ });
2858
+ }
2859
+ }
2860
+ mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps, {
2861
+ preserveIdentifiedPendingPayments: _field2 === 'payments'
2862
+ });
2863
+ continue;
2864
+ }
2865
+ if (Object.prototype.hasOwnProperty.call(existingRecord, _field2)) {
2866
+ mergedRecord[_field2] = cloneDeep(existingRecord[_field2]);
2867
+ } else {
2868
+ delete mergedRecord[_field2];
2154
2869
  }
2155
2870
  }
2156
2871
  if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
2157
2872
  merged.need_sync = 0;
2158
2873
  }
2159
- return merged;
2874
+ return this.normalizeOrderCollectionsForIngress(applyOrderCollectionUidRemaps(merged, childUidRemaps), 'mergeOrderRecords');
2160
2875
  }
2161
2876
  }, {
2162
2877
  key: "summarizeDuplicateOrders",
2163
2878
  value: function summarizeDuplicateOrders(orders) {
2164
2879
  var groups = new Map();
2165
- var _iterator20 = _createForOfIteratorHelper(orders),
2166
- _step20;
2880
+ var _iterator26 = _createForOfIteratorHelper(orders),
2881
+ _step26;
2167
2882
  try {
2168
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2169
- var order = _step20.value;
2170
- var _iterator21 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2171
- _step21;
2883
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
2884
+ var order = _step26.value;
2885
+ var _iterator27 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2886
+ _step27;
2172
2887
  try {
2173
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2174
- var key = _step21.value;
2888
+ for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
2889
+ var key = _step27.value;
2175
2890
  var group = groups.get(key) || [];
2176
2891
  group.push(order);
2177
2892
  groups.set(key, group);
2178
2893
  }
2179
2894
  } catch (err) {
2180
- _iterator21.e(err);
2895
+ _iterator27.e(err);
2181
2896
  } finally {
2182
- _iterator21.f();
2897
+ _iterator27.f();
2183
2898
  }
2184
2899
  }
2185
2900
  } catch (err) {
2186
- _iterator20.e(err);
2901
+ _iterator26.e(err);
2187
2902
  } finally {
2188
- _iterator20.f();
2903
+ _iterator26.f();
2189
2904
  }
2190
- return _toConsumableArray(groups.entries()).filter(function (_ref4) {
2191
- var _ref5 = _slicedToArray(_ref4, 2),
2192
- group = _ref5[1];
2905
+ return _toConsumableArray(groups.entries()).filter(function (_ref7) {
2906
+ var _ref8 = _slicedToArray(_ref7, 2),
2907
+ group = _ref8[1];
2193
2908
  return group.length > 1;
2194
- }).slice(0, 20).map(function (_ref6) {
2195
- var _ref7 = _slicedToArray(_ref6, 2),
2196
- key = _ref7[0],
2197
- group = _ref7[1];
2909
+ }).slice(0, 20).map(function (_ref9) {
2910
+ var _ref10 = _slicedToArray(_ref9, 2),
2911
+ key = _ref10[0],
2912
+ group = _ref10[1];
2198
2913
  return {
2199
2914
  key: key,
2200
2915
  count: group.length,
2201
2916
  orders: group.map(function (order) {
2202
- var _order$order_id2, _external_sale_number2, _shop_order_number, _shop_full_order_numb, _order$need_sync;
2917
+ var _order$order_id4, _external_sale_number4, _shop_order_number, _shop_full_order_numb, _order$need_sync, _order$is_draft_order;
2203
2918
  return {
2204
- order_id: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
2205
- external_sale_number: (_external_sale_number2 = order.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : null,
2919
+ order_id: (_order$order_id4 = order.order_id) !== null && _order$order_id4 !== void 0 ? _order$order_id4 : null,
2920
+ external_sale_number: (_external_sale_number4 = order.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : null,
2206
2921
  shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
2207
2922
  shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
2208
- need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
2923
+ need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null,
2924
+ is_draft_order: (_order$is_draft_order = order.is_draft_order) !== null && _order$is_draft_order !== void 0 ? _order$is_draft_order : null
2209
2925
  };
2210
2926
  })
2211
2927
  };
@@ -2227,23 +2943,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2227
2943
  value: function compactOrderListByIdentity(orders, source) {
2228
2944
  var list = [];
2229
2945
  var removedCount = 0;
2230
- var _iterator22 = _createForOfIteratorHelper(orders),
2231
- _step22;
2946
+ var _iterator28 = _createForOfIteratorHelper(orders),
2947
+ _step28;
2232
2948
  try {
2233
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
2234
- var order = _step22.value;
2235
- var matchIndex = this.findOrderIndexByIdentity(list, order);
2949
+ for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
2950
+ var order = _step28.value;
2951
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
2952
+ var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
2236
2953
  if (matchIndex < 0) {
2237
- list.push(order);
2954
+ list.push(normalizedOrder);
2238
2955
  continue;
2239
2956
  }
2240
- list[matchIndex] = this.mergeOrderRecords(list[matchIndex], order);
2957
+ list[matchIndex] = this.mergeOrderRecords(list[matchIndex], normalizedOrder);
2241
2958
  removedCount += 1;
2242
2959
  }
2243
2960
  } catch (err) {
2244
- _iterator22.e(err);
2961
+ _iterator28.e(err);
2245
2962
  } finally {
2246
- _iterator22.f();
2963
+ _iterator28.f();
2247
2964
  }
2248
2965
  if (removedCount > 0) {
2249
2966
  this.logWarning('订单列表重复项已压缩', {
@@ -2341,32 +3058,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2341
3058
  }, {
2342
3059
  key: "loadOrdersFromSQLite",
2343
3060
  value: function () {
2344
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
3061
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
3062
+ var _this19 = this;
2345
3063
  var orders;
2346
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2347
- while (1) switch (_context17.prev = _context17.next) {
3064
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
3065
+ while (1) switch (_context19.prev = _context19.next) {
2348
3066
  case 0:
2349
3067
  if (this.dbManager) {
2350
- _context17.next = 2;
3068
+ _context19.next = 2;
2351
3069
  break;
2352
3070
  }
2353
- return _context17.abrupt("return", []);
3071
+ return _context19.abrupt("return", []);
2354
3072
  case 2:
2355
- _context17.prev = 2;
2356
- _context17.next = 5;
3073
+ _context19.prev = 2;
3074
+ _context19.next = 5;
2357
3075
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
2358
3076
  case 5:
2359
- orders = _context17.sent;
2360
- return _context17.abrupt("return", orders || []);
3077
+ orders = _context19.sent;
3078
+ return _context19.abrupt("return", (orders || []).map(function (order) {
3079
+ return _this19.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3080
+ }));
2361
3081
  case 9:
2362
- _context17.prev = 9;
2363
- _context17.t0 = _context17["catch"](2);
2364
- return _context17.abrupt("return", []);
3082
+ _context19.prev = 9;
3083
+ _context19.t0 = _context19["catch"](2);
3084
+ return _context19.abrupt("return", []);
2365
3085
  case 12:
2366
3086
  case "end":
2367
- return _context17.stop();
3087
+ return _context19.stop();
2368
3088
  }
2369
- }, _callee17, this, [[2, 9]]);
3089
+ }, _callee19, this, [[2, 9]]);
2370
3090
  }));
2371
3091
  function loadOrdersFromSQLite() {
2372
3092
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -2378,39 +3098,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2378
3098
  value: function isPendingSyncOrder(order) {
2379
3099
  return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
2380
3100
  }
3101
+ }, {
3102
+ key: "isDraftOrder",
3103
+ value: function isDraftOrder(order) {
3104
+ return Number(order === null || order === void 0 ? void 0 : order.is_draft_order) === 1;
3105
+ }
3106
+ }, {
3107
+ key: "shouldProtectDraftOrderFromIncoming",
3108
+ value: function shouldProtectDraftOrderFromIncoming(source) {
3109
+ return source !== 'checkoutSync';
3110
+ }
2381
3111
  }, {
2382
3112
  key: "normalizeRemoteSyncedOrder",
2383
3113
  value: function normalizeRemoteSyncedOrder(order) {
2384
- if (this.isPendingSyncOrder(order)) return order;
2385
- return _objectSpread(_objectSpread({}, order), {}, {
2386
- need_sync: 0
3114
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'normalizeRemoteSyncedOrder');
3115
+ if (this.isPendingSyncOrder(normalizedOrder)) return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
3116
+ is_draft_order: 0
3117
+ });
3118
+ return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
3119
+ need_sync: 0,
3120
+ is_draft_order: 0
2387
3121
  });
2388
3122
  }
3123
+ }, {
3124
+ key: "mergeRemoteIdentityIntoDraftOrder",
3125
+ value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3126
+ var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3127
+ var remote = remoteOrder;
3128
+ for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
3129
+ var field = _arr[_i7];
3130
+ if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3131
+ merged[field] = remote[field];
3132
+ }
3133
+ }
3134
+ return this.normalizeOrderCollectionsForIngress(merged, 'mergeRemoteIdentityIntoDraftOrder');
3135
+ }
2389
3136
  }, {
2390
3137
  key: "mergeRemoteSnapshotWithPendingOrders",
2391
3138
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
2392
- var _this17 = this;
3139
+ var _this20 = this;
2393
3140
  var merged = remoteOrders.map(function (order) {
2394
- return _this17.normalizeRemoteSyncedOrder(order);
3141
+ return _this20.normalizeRemoteSyncedOrder(order);
2395
3142
  });
2396
- var _iterator23 = _createForOfIteratorHelper(existingOrders),
2397
- _step23;
3143
+ var _iterator29 = _createForOfIteratorHelper(existingOrders),
3144
+ _step29;
2398
3145
  try {
2399
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
2400
- var order = _step23.value;
2401
- if (!this.isPendingSyncOrder(order)) continue;
3146
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3147
+ var rawOrder = _step29.value;
3148
+ var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3149
+ if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
2402
3150
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
2403
3151
  if (matchIndex >= 0) {
2404
- merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
3152
+ if (this.isDraftOrder(order)) {
3153
+ merged[matchIndex] = this.mergeRemoteIdentityIntoDraftOrder(order, merged[matchIndex]);
3154
+ } else {
3155
+ merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
3156
+ }
2405
3157
  continue;
2406
3158
  }
2407
3159
  if (!this.getOrderStorageKey(order)) continue;
2408
3160
  merged.push(order);
2409
3161
  }
2410
3162
  } catch (err) {
2411
- _iterator23.e(err);
3163
+ _iterator29.e(err);
2412
3164
  } finally {
2413
- _iterator23.f();
3165
+ _iterator29.f();
2414
3166
  }
2415
3167
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
2416
3168
  }
@@ -2426,10 +3178,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2426
3178
  }, {
2427
3179
  key: "runInOrderSQLiteSaveQueue",
2428
3180
  value: (function () {
2429
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
3181
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(task) {
2430
3182
  var queuedTask;
2431
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2432
- while (1) switch (_context18.prev = _context18.next) {
3183
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3184
+ while (1) switch (_context20.prev = _context20.next) {
2433
3185
  case 0:
2434
3186
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
2435
3187
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -2437,14 +3189,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2437
3189
  }, function () {
2438
3190
  return undefined;
2439
3191
  });
2440
- return _context18.abrupt("return", queuedTask);
3192
+ return _context20.abrupt("return", queuedTask);
2441
3193
  case 3:
2442
3194
  case "end":
2443
- return _context18.stop();
3195
+ return _context20.stop();
2444
3196
  }
2445
- }, _callee18, this);
3197
+ }, _callee20, this);
2446
3198
  }));
2447
- function runInOrderSQLiteSaveQueue(_x11) {
3199
+ function runInOrderSQLiteSaveQueue(_x14) {
2448
3200
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
2449
3201
  }
2450
3202
  return runInOrderSQLiteSaveQueue;
@@ -2459,144 +3211,174 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2459
3211
  }, {
2460
3212
  key: "patchOrdersInSQLite",
2461
3213
  value: (function () {
2462
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
2463
- var _this18 = this;
3214
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orders, source) {
3215
+ var _this21 = this;
2464
3216
  var mergeActions,
3217
+ options,
2465
3218
  ordersSnapshot,
2466
3219
  _this$filterRedundant2,
2467
3220
  toWrite,
2468
3221
  skipped,
2469
3222
  compactedToWrite,
2470
- _args20 = arguments;
2471
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2472
- while (1) switch (_context20.prev = _context20.next) {
3223
+ _args22 = arguments;
3224
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3225
+ while (1) switch (_context22.prev = _context22.next) {
2473
3226
  case 0:
2474
- mergeActions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2475
- if (!(!this.dbManager || orders.length === 0)) {
2476
- _context20.next = 3;
3227
+ mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
3228
+ options = _args22.length > 3 && _args22[3] !== undefined ? _args22[3] : {};
3229
+ if (!(orders.length === 0)) {
3230
+ _context22.next = 4;
2477
3231
  break;
2478
3232
  }
2479
- return _context20.abrupt("return");
2480
- case 3:
2481
- ordersSnapshot = cloneDeep(orders).filter(function (order) {
2482
- return _this18.getOrderStorageKey(order);
3233
+ return _context22.abrupt("return");
3234
+ case 4:
3235
+ if (this.dbManager) {
3236
+ _context22.next = 8;
3237
+ break;
3238
+ }
3239
+ if (!options.throwOnError) {
3240
+ _context22.next = 7;
3241
+ break;
3242
+ }
3243
+ throw new Error('订单 SQLite 数据库未初始化');
3244
+ case 7:
3245
+ return _context22.abrupt("return");
3246
+ case 8:
3247
+ ordersSnapshot = cloneDeep(orders).map(function (order) {
3248
+ return _this21.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3249
+ }).filter(function (order) {
3250
+ return _this21.getOrderStorageKey(order);
2483
3251
  });
2484
3252
  if (!(ordersSnapshot.length === 0)) {
2485
- _context20.next = 6;
3253
+ _context22.next = 11;
2486
3254
  break;
2487
3255
  }
2488
- return _context20.abrupt("return");
2489
- case 6:
3256
+ return _context22.abrupt("return");
3257
+ case 11:
2490
3258
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
2491
3259
  if (!(toWrite.length === 0)) {
2492
- _context20.next = 9;
3260
+ _context22.next = 14;
2493
3261
  break;
2494
3262
  }
2495
- return _context20.abrupt("return");
2496
- case 9:
3263
+ return _context22.abrupt("return");
3264
+ case 14:
2497
3265
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
2498
3266
  if (!(compactedToWrite.length === 0)) {
2499
- _context20.next = 12;
3267
+ _context22.next = 17;
2500
3268
  break;
2501
3269
  }
2502
- return _context20.abrupt("return");
2503
- case 12:
2504
- _context20.prev = 12;
2505
- _context20.next = 15;
2506
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2507
- var writeMethod, _iterator24, _step24, order;
2508
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2509
- while (1) switch (_context19.prev = _context19.next) {
3270
+ return _context22.abrupt("return");
3271
+ case 17:
3272
+ _context22.prev = 17;
3273
+ _context22.next = 20;
3274
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3275
+ var writeMethod, _iterator30, _step30, order;
3276
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3277
+ while (1) switch (_context21.prev = _context21.next) {
2510
3278
  case 0:
2511
3279
  writeMethod = 'none';
2512
- _this18.logInfo('patchOrdersInSQLite-开始', {
3280
+ _this21.logInfo('patchOrdersInSQLite-开始', {
2513
3281
  source: source,
2514
3282
  count: compactedToWrite.length,
2515
3283
  dedupedCount: skipped.length
2516
3284
  });
2517
- if (!(typeof _this18.dbManager.bulkUpdate === 'function')) {
2518
- _context19.next = 8;
3285
+ if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
3286
+ _context21.next = 8;
2519
3287
  break;
2520
3288
  }
2521
3289
  writeMethod = 'bulkUpdate';
2522
- _context19.next = 6;
2523
- return _this18.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3290
+ _context21.next = 6;
3291
+ return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2524
3292
  case 6:
2525
- _context19.next = 33;
3293
+ _context21.next = 37;
2526
3294
  break;
2527
3295
  case 8:
2528
- if (!(typeof _this18.dbManager.bulkAdd === 'function')) {
2529
- _context19.next = 14;
3296
+ if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
3297
+ _context21.next = 14;
2530
3298
  break;
2531
3299
  }
2532
3300
  writeMethod = 'bulkAdd';
2533
- _context19.next = 12;
2534
- return _this18.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3301
+ _context21.next = 12;
3302
+ return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2535
3303
  case 12:
2536
- _context19.next = 33;
3304
+ _context21.next = 37;
2537
3305
  break;
2538
3306
  case 14:
2539
- if (!(typeof _this18.dbManager.update === 'function')) {
2540
- _context19.next = 33;
3307
+ if (!(typeof _this21.dbManager.update === 'function')) {
3308
+ _context21.next = 35;
2541
3309
  break;
2542
3310
  }
2543
3311
  writeMethod = 'update';
2544
- _iterator24 = _createForOfIteratorHelper(compactedToWrite);
2545
- _context19.prev = 17;
2546
- _iterator24.s();
3312
+ _iterator30 = _createForOfIteratorHelper(compactedToWrite);
3313
+ _context21.prev = 17;
3314
+ _iterator30.s();
2547
3315
  case 19:
2548
- if ((_step24 = _iterator24.n()).done) {
2549
- _context19.next = 25;
3316
+ if ((_step30 = _iterator30.n()).done) {
3317
+ _context21.next = 25;
2550
3318
  break;
2551
3319
  }
2552
- order = _step24.value;
2553
- _context19.next = 23;
2554
- return _this18.dbManager.update(INDEXDB_STORE_NAME, order);
3320
+ order = _step30.value;
3321
+ _context21.next = 23;
3322
+ return _this21.dbManager.update(INDEXDB_STORE_NAME, order);
2555
3323
  case 23:
2556
- _context19.next = 19;
3324
+ _context21.next = 19;
2557
3325
  break;
2558
3326
  case 25:
2559
- _context19.next = 30;
3327
+ _context21.next = 30;
2560
3328
  break;
2561
3329
  case 27:
2562
- _context19.prev = 27;
2563
- _context19.t0 = _context19["catch"](17);
2564
- _iterator24.e(_context19.t0);
3330
+ _context21.prev = 27;
3331
+ _context21.t0 = _context21["catch"](17);
3332
+ _iterator30.e(_context21.t0);
2565
3333
  case 30:
2566
- _context19.prev = 30;
2567
- _iterator24.f();
2568
- return _context19.finish(30);
3334
+ _context21.prev = 30;
3335
+ _iterator30.f();
3336
+ return _context21.finish(30);
2569
3337
  case 33:
2570
- _this18.recordRecentSqliteWrite(source, compactedToWrite);
2571
- _this18.logInfo('patchOrdersInSQLite-完成', {
3338
+ _context21.next = 37;
3339
+ break;
3340
+ case 35:
3341
+ if (!options.throwOnError) {
3342
+ _context21.next = 37;
3343
+ break;
3344
+ }
3345
+ throw new Error('订单 SQLite 数据库不支持写入');
3346
+ case 37:
3347
+ _this21.recordRecentSqliteWrite(source, compactedToWrite);
3348
+ _this21.logInfo('patchOrdersInSQLite-完成', {
2572
3349
  source: source,
2573
3350
  count: compactedToWrite.length,
2574
3351
  writeMethod: writeMethod,
2575
3352
  dedupedCount: skipped.length
2576
3353
  });
2577
- case 35:
3354
+ case 39:
2578
3355
  case "end":
2579
- return _context19.stop();
3356
+ return _context21.stop();
2580
3357
  }
2581
- }, _callee19, null, [[17, 27, 30, 33]]);
3358
+ }, _callee21, null, [[17, 27, 30, 33]]);
2582
3359
  })));
2583
- case 15:
2584
- _context20.next = 20;
3360
+ case 20:
3361
+ _context22.next = 27;
2585
3362
  break;
2586
- case 17:
2587
- _context20.prev = 17;
2588
- _context20.t0 = _context20["catch"](12);
3363
+ case 22:
3364
+ _context22.prev = 22;
3365
+ _context22.t0 = _context22["catch"](17);
2589
3366
  this.logError('增量保存订单到 SQLite 失败', {
2590
- error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
3367
+ error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
2591
3368
  orderCount: ordersSnapshot.length
2592
3369
  });
2593
- case 20:
3370
+ if (!options.throwOnError) {
3371
+ _context22.next = 27;
3372
+ break;
3373
+ }
3374
+ throw _context22.t0;
3375
+ case 27:
2594
3376
  case "end":
2595
- return _context20.stop();
3377
+ return _context22.stop();
2596
3378
  }
2597
- }, _callee20, this, [[12, 17]]);
3379
+ }, _callee22, this, [[17, 22]]);
2598
3380
  }));
2599
- function patchOrdersInSQLite(_x12, _x13) {
3381
+ function patchOrdersInSQLite(_x15, _x16) {
2600
3382
  return _patchOrdersInSQLite.apply(this, arguments);
2601
3383
  }
2602
3384
  return patchOrdersInSQLite;
@@ -2611,98 +3393,135 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2611
3393
  }, {
2612
3394
  key: "updateOrderInSQLite",
2613
3395
  value: (function () {
2614
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
2615
- var _this19 = this;
2616
- var orderSnapshot, _orderSnapshot$order_3;
2617
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2618
- while (1) switch (_context22.prev = _context22.next) {
3396
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order, source) {
3397
+ var _this22 = this;
3398
+ var options,
3399
+ orderSnapshot,
3400
+ _orderSnapshot$order_3,
3401
+ _args24 = arguments;
3402
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3403
+ while (1) switch (_context24.prev = _context24.next) {
2619
3404
  case 0:
2620
- if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
2621
- _context22.next = 2;
3405
+ options = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3406
+ if (this.getOrderStorageKey(order)) {
3407
+ _context24.next = 5;
2622
3408
  break;
2623
3409
  }
2624
- return _context22.abrupt("return");
2625
- case 2:
2626
- orderSnapshot = cloneDeep(order);
2627
- _context22.prev = 3;
2628
- _context22.next = 6;
2629
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3410
+ if (!options.throwOnError) {
3411
+ _context24.next = 4;
3412
+ break;
3413
+ }
3414
+ throw new Error('订单缺少可用的 SQLite 存储主键');
3415
+ case 4:
3416
+ return _context24.abrupt("return");
3417
+ case 5:
3418
+ if (this.dbManager) {
3419
+ _context24.next = 9;
3420
+ break;
3421
+ }
3422
+ if (!options.throwOnError) {
3423
+ _context24.next = 8;
3424
+ break;
3425
+ }
3426
+ throw new Error('订单 SQLite 数据库未初始化');
3427
+ case 8:
3428
+ return _context24.abrupt("return");
3429
+ case 9:
3430
+ orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
3431
+ _context24.prev = 10;
3432
+ _context24.next = 13;
3433
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2630
3434
  var _orderSnapshot$order_, _orderSnapshot$order_2;
2631
3435
  var writeMethod;
2632
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2633
- while (1) switch (_context21.prev = _context21.next) {
3436
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3437
+ while (1) switch (_context23.prev = _context23.next) {
2634
3438
  case 0:
2635
3439
  writeMethod = 'none';
2636
- _this19.logInfo('updateOrderInSQLite-开始', {
3440
+ _this22.logInfo('updateOrderInSQLite-开始', {
2637
3441
  source: source,
2638
3442
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2639
- storageKey: _this19.getOrderStorageKey(orderSnapshot)
3443
+ storageKey: _this22.getOrderStorageKey(orderSnapshot)
2640
3444
  });
2641
- if (!(typeof _this19.dbManager.update === 'function')) {
2642
- _context21.next = 8;
3445
+ if (!(typeof _this22.dbManager.update === 'function')) {
3446
+ _context23.next = 8;
2643
3447
  break;
2644
3448
  }
2645
3449
  writeMethod = 'update';
2646
- _context21.next = 6;
2647
- return _this19.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3450
+ _context23.next = 6;
3451
+ return _this22.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2648
3452
  case 6:
2649
- _context21.next = 18;
3453
+ _context23.next = 22;
2650
3454
  break;
2651
3455
  case 8:
2652
- if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
2653
- _context21.next = 14;
3456
+ if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3457
+ _context23.next = 14;
2654
3458
  break;
2655
3459
  }
2656
3460
  writeMethod = 'bulkUpdate';
2657
- _context21.next = 12;
2658
- return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3461
+ _context23.next = 12;
3462
+ return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2659
3463
  case 12:
2660
- _context21.next = 18;
3464
+ _context23.next = 22;
2661
3465
  break;
2662
3466
  case 14:
2663
- if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
2664
- _context21.next = 18;
3467
+ if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3468
+ _context23.next = 20;
2665
3469
  break;
2666
3470
  }
2667
3471
  writeMethod = 'bulkAdd';
2668
- _context21.next = 18;
2669
- return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3472
+ _context23.next = 18;
3473
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2670
3474
  case 18:
2671
- _this19.recordRecentSqliteWrite(source, [orderSnapshot]);
2672
- _this19.logInfo('updateOrderInSQLite-完成', {
3475
+ _context23.next = 22;
3476
+ break;
3477
+ case 20:
3478
+ if (!options.throwOnError) {
3479
+ _context23.next = 22;
3480
+ break;
3481
+ }
3482
+ throw new Error('订单 SQLite 数据库不支持写入');
3483
+ case 22:
3484
+ _this22.recordRecentSqliteWrite(source, [orderSnapshot]);
3485
+ _this22.logInfo('updateOrderInSQLite-完成', {
2673
3486
  source: source,
2674
3487
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
2675
3488
  writeMethod: writeMethod
2676
3489
  });
2677
- case 20:
3490
+ case 24:
2678
3491
  case "end":
2679
- return _context21.stop();
3492
+ return _context23.stop();
2680
3493
  }
2681
- }, _callee21);
3494
+ }, _callee23);
2682
3495
  })));
2683
- case 6:
2684
- _context22.next = 11;
3496
+ case 13:
3497
+ _context24.next = 20;
2685
3498
  break;
2686
- case 8:
2687
- _context22.prev = 8;
2688
- _context22.t0 = _context22["catch"](3);
3499
+ case 15:
3500
+ _context24.prev = 15;
3501
+ _context24.t0 = _context24["catch"](10);
2689
3502
  this.logError('单条保存订单到 SQLite 失败', {
2690
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
3503
+ error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
2691
3504
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
2692
3505
  });
2693
- case 11:
3506
+ if (!options.throwOnError) {
3507
+ _context24.next = 20;
3508
+ break;
3509
+ }
3510
+ throw _context24.t0;
3511
+ case 20:
2694
3512
  case "end":
2695
- return _context22.stop();
3513
+ return _context24.stop();
2696
3514
  }
2697
- }, _callee22, this, [[3, 8]]);
3515
+ }, _callee24, this, [[10, 15]]);
2698
3516
  }));
2699
- function updateOrderInSQLite(_x14, _x15) {
3517
+ function updateOrderInSQLite(_x17, _x18) {
2700
3518
  return _updateOrderInSQLite.apply(this, arguments);
2701
3519
  }
2702
3520
  return updateOrderInSQLite;
2703
3521
  }()
2704
3522
  /**
2705
- * 全量快照替换 orders 表(clear + bulkAdd),用于 SSE 全量拉取与营业日窗口裁剪。
3523
+ * 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync / pending 支付订单。
3524
+ * 用于 SSE 全量拉取与营业日窗口裁剪。
2706
3525
  *
2707
3526
  * @example
2708
3527
  * await this.replaceOrdersSnapshotInSQLite(orderList)
@@ -2711,98 +3530,163 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2711
3530
  }, {
2712
3531
  key: "replaceOrdersSnapshotInSQLite",
2713
3532
  value: (function () {
2714
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
2715
- var _this20 = this;
2716
- var remoteSnapshot, mergedSnapshot;
2717
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2718
- while (1) switch (_context24.prev = _context24.next) {
3533
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orderList, source) {
3534
+ var _this23 = this;
3535
+ var protectedOrdersBeforeRemoteFetch,
3536
+ remoteSnapshot,
3537
+ mergedSnapshot,
3538
+ _args26 = arguments;
3539
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3540
+ while (1) switch (_context26.prev = _context26.next) {
2719
3541
  case 0:
3542
+ protectedOrdersBeforeRemoteFetch = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : [];
2720
3543
  if (this.dbManager) {
2721
- _context24.next = 2;
3544
+ _context26.next = 3;
2722
3545
  break;
2723
3546
  }
2724
- return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
2725
- return _this20.normalizeRemoteSyncedOrder(order);
3547
+ return _context26.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3548
+ return _this23.normalizeRemoteSyncedOrder(order);
2726
3549
  }), "".concat(source, ".snapshotNoDb")).list);
2727
- case 2:
2728
- remoteSnapshot = cloneDeep(orderList);
3550
+ case 3:
3551
+ remoteSnapshot = cloneDeep(orderList).map(function (order) {
3552
+ return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3553
+ });
2729
3554
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
2730
- return _this20.normalizeRemoteSyncedOrder(order);
3555
+ return _this23.normalizeRemoteSyncedOrder(order);
2731
3556
  }), "".concat(source, ".remoteSnapshot")).list;
2732
- _context24.prev = 4;
2733
- _context24.next = 7;
2734
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2735
- var existingOrders, orderListSnapshot;
2736
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2737
- while (1) switch (_context23.prev = _context23.next) {
3557
+ _context26.prev = 5;
3558
+ _context26.next = 8;
3559
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3560
+ var existingOrders, protectedLocalOrders, _iterator31, _step31, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3561
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3562
+ while (1) switch (_context25.prev = _context25.next) {
2738
3563
  case 0:
2739
- if (!(typeof _this20.dbManager.getAll === 'function')) {
2740
- _context23.next = 6;
3564
+ if (!(typeof _this23.dbManager.getAll === 'function')) {
3565
+ _context25.next = 6;
2741
3566
  break;
2742
3567
  }
2743
- _context23.next = 3;
2744
- return _this20.dbManager.getAll(INDEXDB_STORE_NAME);
3568
+ _context25.next = 3;
3569
+ return _this23.dbManager.getAll(INDEXDB_STORE_NAME);
2745
3570
  case 3:
2746
- _context23.t0 = _context23.sent;
2747
- _context23.next = 7;
3571
+ _context25.t0 = _context25.sent;
3572
+ _context25.next = 7;
2748
3573
  break;
2749
3574
  case 6:
2750
- _context23.t0 = [];
3575
+ _context25.t0 = [];
2751
3576
  case 7:
2752
- existingOrders = _context23.t0;
2753
- orderListSnapshot = _this20.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2754
- mergedSnapshot = _this20.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2755
- _this20.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3577
+ existingOrders = _context25.t0;
3578
+ protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
3579
+ return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3580
+ }).filter(function (order) {
3581
+ return _this23.shouldProtectLocalOrderFromRemoteSnapshot(order);
3582
+ });
3583
+ _iterator31 = _createForOfIteratorHelper(existingOrders || []);
3584
+ _context25.prev = 10;
3585
+ _iterator31.s();
3586
+ case 12:
3587
+ if ((_step31 = _iterator31.n()).done) {
3588
+ _context25.next = 23;
3589
+ break;
3590
+ }
3591
+ rawCurrentOrder = _step31.value;
3592
+ currentOrder = _this23.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3593
+ protectedIndex = _this23.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3594
+ currentNeedsProtection = _this23.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3595
+ if (!(protectedIndex >= 0)) {
3596
+ _context25.next = 20;
3597
+ break;
3598
+ }
3599
+ if (currentNeedsProtection) {
3600
+ protectedLocalOrders[protectedIndex] = currentOrder;
3601
+ } else {
3602
+ protectedLocalOrders.splice(protectedIndex, 1);
3603
+ }
3604
+ return _context25.abrupt("continue", 21);
3605
+ case 20:
3606
+ if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
3607
+ case 21:
3608
+ _context25.next = 12;
3609
+ break;
3610
+ case 23:
3611
+ _context25.next = 28;
3612
+ break;
3613
+ case 25:
3614
+ _context25.prev = 25;
3615
+ _context25.t1 = _context25["catch"](10);
3616
+ _iterator31.e(_context25.t1);
3617
+ case 28:
3618
+ _context25.prev = 28;
3619
+ _iterator31.f();
3620
+ return _context25.finish(28);
3621
+ case 31:
3622
+ orderListSnapshot = _this23.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3623
+ mergedSnapshot = _this23.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3624
+ _this23.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2756
3625
  source: source,
2757
3626
  count: mergedSnapshot.length,
2758
3627
  remoteCount: remoteSnapshot.length,
2759
- preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
3628
+ protectedBeforeRemoteFetchCount: protectedOrdersBeforeRemoteFetch.length,
3629
+ protectedLocalOrderCount: protectedLocalOrders.length,
3630
+ preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
3631
+ protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
3632
+ return count + _this23.getIdentifiedPendingPayments(order).length;
3633
+ }, 0),
3634
+ protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
3635
+ return _this23.getIdentifiedPendingPayments(order).map(function (payment) {
3636
+ var _order$order_id5, _external_sale_number5;
3637
+ return {
3638
+ order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
3639
+ external_sale_number: (_external_sale_number5 = order.external_sale_number) !== null && _external_sale_number5 !== void 0 ? _external_sale_number5 : null,
3640
+ payment_identities: getOrderPaymentIdentityKeys(payment)
3641
+ };
3642
+ });
3643
+ })
2760
3644
  });
2761
- _context23.next = 13;
2762
- return _this20.dbManager.clear(INDEXDB_STORE_NAME);
2763
- case 13:
2764
- _this20.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
3645
+ _context25.next = 36;
3646
+ return _this23.dbManager.clear(INDEXDB_STORE_NAME);
3647
+ case 36:
3648
+ _this23.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2765
3649
  count: mergedSnapshot.length
2766
3650
  });
2767
3651
  if (!(mergedSnapshot.length === 0)) {
2768
- _context23.next = 16;
3652
+ _context25.next = 39;
2769
3653
  break;
2770
3654
  }
2771
- return _context23.abrupt("return");
2772
- case 16:
2773
- _context23.next = 18;
2774
- return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2775
- case 18:
2776
- _this20.recordRecentSqliteWrite(source, mergedSnapshot);
2777
- _this20.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
3655
+ return _context25.abrupt("return");
3656
+ case 39:
3657
+ _context25.next = 41;
3658
+ return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
3659
+ case 41:
3660
+ _this23.recordRecentSqliteWrite(source, mergedSnapshot);
3661
+ _this23.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2778
3662
  source: source,
2779
3663
  count: mergedSnapshot.length
2780
3664
  });
2781
- case 20:
3665
+ case 43:
2782
3666
  case "end":
2783
- return _context23.stop();
3667
+ return _context25.stop();
2784
3668
  }
2785
- }, _callee23);
3669
+ }, _callee25, null, [[10, 25, 28, 31]]);
2786
3670
  })));
2787
- case 7:
2788
- _context24.next = 12;
3671
+ case 8:
3672
+ _context26.next = 13;
2789
3673
  break;
2790
- case 9:
2791
- _context24.prev = 9;
2792
- _context24.t0 = _context24["catch"](4);
3674
+ case 10:
3675
+ _context26.prev = 10;
3676
+ _context26.t0 = _context26["catch"](5);
2793
3677
  this.logError('全量保存订单到 SQLite 失败', {
2794
- error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
3678
+ error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
2795
3679
  orderList: remoteSnapshot.length
2796
3680
  });
2797
- case 12:
2798
- return _context24.abrupt("return", mergedSnapshot);
2799
3681
  case 13:
3682
+ return _context26.abrupt("return", mergedSnapshot);
3683
+ case 14:
2800
3684
  case "end":
2801
- return _context24.stop();
3685
+ return _context26.stop();
2802
3686
  }
2803
- }, _callee24, this, [[4, 9]]);
3687
+ }, _callee26, this, [[5, 10]]);
2804
3688
  }));
2805
- function replaceOrdersSnapshotInSQLite(_x16, _x17) {
3689
+ function replaceOrdersSnapshotInSQLite(_x19, _x20) {
2806
3690
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
2807
3691
  }
2808
3692
  return replaceOrdersSnapshotInSQLite;
@@ -2817,38 +3701,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2817
3701
  }, {
2818
3702
  key: "clear",
2819
3703
  value: (function () {
2820
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2821
- var _this21 = this;
2822
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2823
- while (1) switch (_context26.prev = _context26.next) {
3704
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3705
+ var _this24 = this;
3706
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
3707
+ while (1) switch (_context28.prev = _context28.next) {
2824
3708
  case 0:
2825
3709
  this.store.list = [];
2826
3710
  this.store.map = new Map();
2827
3711
  if (!this.dbManager) {
2828
- _context26.next = 5;
3712
+ _context28.next = 5;
2829
3713
  break;
2830
3714
  }
2831
- _context26.next = 5;
2832
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2833
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2834
- while (1) switch (_context25.prev = _context25.next) {
3715
+ _context28.next = 5;
3716
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
3717
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3718
+ while (1) switch (_context27.prev = _context27.next) {
2835
3719
  case 0:
2836
- _context25.next = 2;
2837
- return _this21.dbManager.clear(INDEXDB_STORE_NAME);
3720
+ _context27.next = 2;
3721
+ return _this24.dbManager.clear(INDEXDB_STORE_NAME);
2838
3722
  case 2:
2839
3723
  case "end":
2840
- return _context25.stop();
3724
+ return _context27.stop();
2841
3725
  }
2842
- }, _callee25);
3726
+ }, _callee27);
2843
3727
  })));
2844
3728
  case 5:
2845
3729
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
2846
3730
  this.emitOrdersChanged([], 'clear');
2847
3731
  case 7:
2848
3732
  case "end":
2849
- return _context26.stop();
3733
+ return _context28.stop();
2850
3734
  }
2851
- }, _callee26, this);
3735
+ }, _callee28, this);
2852
3736
  }));
2853
3737
  function clear() {
2854
3738
  return _clear.apply(this, arguments);