@pisell/pisellos 0.0.193 → 0.0.195

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 (161) hide show
  1. package/dist/modules/Cart/index.js +1 -1
  2. package/dist/modules/Payment/cash.d.ts +11 -0
  3. package/dist/modules/Payment/cash.js +78 -0
  4. package/dist/modules/Payment/eftpos.d.ts +11 -0
  5. package/dist/modules/Payment/eftpos.js +80 -0
  6. package/dist/modules/Payment/index.d.ts +182 -9
  7. package/dist/modules/Payment/index.js +1945 -102
  8. package/dist/modules/Payment/types.d.ts +351 -31
  9. package/dist/modules/Payment/types.js +116 -14
  10. package/dist/modules/Payment/wallet.d.ts +11 -0
  11. package/dist/modules/Payment/wallet.js +78 -0
  12. package/dist/plugins/app-types/app/app.d.ts +83 -0
  13. package/dist/plugins/app-types/app/const.d.ts +4 -0
  14. package/dist/plugins/app-types/app/index.d.ts +14 -0
  15. package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
  16. package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
  17. package/dist/plugins/app-types/config.d.ts +3 -0
  18. package/dist/plugins/app-types/cookie/index.d.ts +13 -0
  19. package/dist/plugins/app-types/data/index.d.ts +8 -0
  20. package/dist/plugins/app-types/history/config.d.ts +24 -0
  21. package/dist/plugins/app-types/history/index.d.ts +20 -0
  22. package/dist/plugins/app-types/history/type.d.ts +2 -0
  23. package/dist/plugins/app-types/hooks/index.d.ts +12 -0
  24. package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  25. package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  26. package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  27. package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  28. package/dist/plugins/app-types/index.d.ts +6 -0
  29. package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
  30. package/dist/plugins/app-types/locales/en.d.ts +3 -0
  31. package/dist/plugins/app-types/locales/index.d.ts +37 -0
  32. package/dist/plugins/app-types/locales/original.d.ts +3 -0
  33. package/dist/plugins/app-types/locales/type.d.ts +19 -0
  34. package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
  35. package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
  36. package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
  37. package/dist/plugins/app-types/logger/index.d.ts +122 -0
  38. package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
  39. package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
  40. package/dist/plugins/app-types/models/global.d.ts +32 -0
  41. package/dist/plugins/app-types/models/index.d.ts +45 -0
  42. package/dist/plugins/app-types/models/type.d.ts +2 -0
  43. package/dist/plugins/app-types/package.json +15 -0
  44. package/dist/plugins/app-types/plugin/index.d.ts +0 -0
  45. package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
  46. package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
  47. package/dist/plugins/app-types/request/cache.d.ts +46 -0
  48. package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
  49. package/dist/plugins/app-types/request/config.d.ts +3 -0
  50. package/dist/plugins/app-types/request/constants.d.ts +2 -0
  51. package/dist/plugins/app-types/request/index.d.ts +24 -0
  52. package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
  53. package/dist/plugins/app-types/request/type.d.ts +41 -0
  54. package/dist/plugins/app-types/request/utils.d.ts +46 -0
  55. package/dist/plugins/app-types/routes/config.d.ts +7 -0
  56. package/dist/plugins/app-types/routes/index.d.ts +28 -0
  57. package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  58. package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
  59. package/dist/plugins/app-types/socket/constants.d.ts +33 -0
  60. package/dist/plugins/app-types/socket/events.d.ts +31 -0
  61. package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
  62. package/dist/plugins/app-types/socket/index.d.ts +61 -0
  63. package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
  64. package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
  65. package/dist/plugins/app-types/socket/socket.d.ts +129 -0
  66. package/dist/plugins/app-types/socket/types.d.ts +85 -0
  67. package/dist/plugins/app-types/storage/index.d.ts +17 -0
  68. package/dist/plugins/app-types/tasks/index.d.ts +77 -0
  69. package/dist/plugins/app-types/tasks/type.d.ts +62 -0
  70. package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
  71. package/dist/plugins/app-types/type.d.ts +2 -0
  72. package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  73. package/dist/plugins/app-types/variables/config.d.ts +3 -0
  74. package/dist/plugins/app-types/variables/index.d.ts +6 -0
  75. package/dist/plugins/app-types/variables/type.d.ts +2 -0
  76. package/dist/plugins/app-types/website/index.d.ts +6 -0
  77. package/dist/plugins/app.d.ts +8 -0
  78. package/dist/plugins/app.js +1 -0
  79. package/dist/solution/BookingByStep/index.js +1 -1
  80. package/dist/solution/BookingByStep/utils/resources.js +2 -8
  81. package/lib/modules/Cart/index.js +1 -1
  82. package/lib/modules/Payment/cash.d.ts +11 -0
  83. package/lib/modules/Payment/cash.js +51 -0
  84. package/lib/modules/Payment/eftpos.d.ts +11 -0
  85. package/lib/modules/Payment/eftpos.js +51 -0
  86. package/lib/modules/Payment/index.d.ts +182 -9
  87. package/lib/modules/Payment/index.js +993 -50
  88. package/lib/modules/Payment/types.d.ts +351 -31
  89. package/lib/modules/Payment/types.js +41 -6
  90. package/lib/modules/Payment/wallet.d.ts +11 -0
  91. package/lib/modules/Payment/wallet.js +51 -0
  92. package/lib/plugins/app-types/app/app.d.ts +83 -0
  93. package/lib/plugins/app-types/app/const.d.ts +4 -0
  94. package/lib/plugins/app-types/app/index.d.ts +14 -0
  95. package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
  96. package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
  97. package/lib/plugins/app-types/config.d.ts +3 -0
  98. package/lib/plugins/app-types/cookie/index.d.ts +13 -0
  99. package/lib/plugins/app-types/data/index.d.ts +8 -0
  100. package/lib/plugins/app-types/history/config.d.ts +24 -0
  101. package/lib/plugins/app-types/history/index.d.ts +20 -0
  102. package/lib/plugins/app-types/history/type.d.ts +2 -0
  103. package/lib/plugins/app-types/hooks/index.d.ts +12 -0
  104. package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  105. package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  106. package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  107. package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  108. package/lib/plugins/app-types/index.d.ts +6 -0
  109. package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
  110. package/lib/plugins/app-types/locales/en.d.ts +3 -0
  111. package/lib/plugins/app-types/locales/index.d.ts +37 -0
  112. package/lib/plugins/app-types/locales/original.d.ts +3 -0
  113. package/lib/plugins/app-types/locales/type.d.ts +19 -0
  114. package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
  115. package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
  116. package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
  117. package/lib/plugins/app-types/logger/index.d.ts +122 -0
  118. package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
  119. package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
  120. package/lib/plugins/app-types/models/global.d.ts +32 -0
  121. package/lib/plugins/app-types/models/index.d.ts +45 -0
  122. package/lib/plugins/app-types/models/type.d.ts +2 -0
  123. package/lib/plugins/app-types/package.json +15 -0
  124. package/lib/plugins/app-types/plugin/index.d.ts +0 -0
  125. package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
  126. package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
  127. package/lib/plugins/app-types/request/cache.d.ts +46 -0
  128. package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
  129. package/lib/plugins/app-types/request/config.d.ts +3 -0
  130. package/lib/plugins/app-types/request/constants.d.ts +2 -0
  131. package/lib/plugins/app-types/request/index.d.ts +24 -0
  132. package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
  133. package/lib/plugins/app-types/request/type.d.ts +41 -0
  134. package/lib/plugins/app-types/request/utils.d.ts +46 -0
  135. package/lib/plugins/app-types/routes/config.d.ts +7 -0
  136. package/lib/plugins/app-types/routes/index.d.ts +28 -0
  137. package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  138. package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
  139. package/lib/plugins/app-types/socket/constants.d.ts +33 -0
  140. package/lib/plugins/app-types/socket/events.d.ts +31 -0
  141. package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
  142. package/lib/plugins/app-types/socket/index.d.ts +61 -0
  143. package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
  144. package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
  145. package/lib/plugins/app-types/socket/socket.d.ts +129 -0
  146. package/lib/plugins/app-types/socket/types.d.ts +85 -0
  147. package/lib/plugins/app-types/storage/index.d.ts +17 -0
  148. package/lib/plugins/app-types/tasks/index.d.ts +77 -0
  149. package/lib/plugins/app-types/tasks/type.d.ts +62 -0
  150. package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
  151. package/lib/plugins/app-types/type.d.ts +2 -0
  152. package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  153. package/lib/plugins/app-types/variables/config.d.ts +3 -0
  154. package/lib/plugins/app-types/variables/index.d.ts +6 -0
  155. package/lib/plugins/app-types/variables/type.d.ts +2 -0
  156. package/lib/plugins/app-types/website/index.d.ts +6 -0
  157. package/lib/plugins/app.d.ts +8 -0
  158. package/lib/plugins/app.js +17 -0
  159. package/lib/solution/BookingByStep/index.js +1 -2
  160. package/lib/solution/BookingByStep/utils/resources.js +2 -10
  161. package/package.json +3 -1
@@ -1,7 +1,10 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- 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; }
2
+ 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; } } }; }
3
+ 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); }
4
+ 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; }
3
5
  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; }
4
6
  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; }
7
+ 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; }
5
8
  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); } }
6
9
  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); }); }; }
7
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -18,7 +21,73 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
18
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
23
  import { BaseModule } from "../BaseModule";
21
- import { PaymentHooks } from "./types";
24
+ import { PaymentStatus, PaymentHooks, PaymentMethodType } from "./types";
25
+ import { getUniqueId } from "../Cart/utils";
26
+ import { CashPaymentImpl } from "./cash";
27
+ import { EftposPaymentImpl } from "./eftpos";
28
+ import { WalletPaymentImpl } from "./wallet";
29
+ import { Decimal } from 'decimal.js';
30
+ export * from "./types";
31
+ export { generateRequestUniqueId };
32
+
33
+ /**
34
+ * 格式化金额为保留两位小数的字符串
35
+ */
36
+ function formatAmount(amount) {
37
+ try {
38
+ var decimal = new Decimal(amount);
39
+ return decimal.toFixed(2);
40
+ } catch (error) {
41
+ console.warn("[PaymentModule] \u91D1\u989D\u683C\u5F0F\u5316\u5931\u8D25: ".concat(amount, "\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C 0.00"));
42
+ return '0.00';
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 生成请求唯一ID
48
+ * 格式: 年月日时分秒毫秒+4位随机数
49
+ * 示例: 20241201143025123456
50
+ */
51
+ function generateRequestUniqueId() {
52
+ var now = new Date();
53
+ var year = now.getFullYear();
54
+ var month = String(now.getMonth() + 1).padStart(2, '0');
55
+ var day = String(now.getDate()).padStart(2, '0');
56
+ var hour = String(now.getHours()).padStart(2, '0');
57
+ var minute = String(now.getMinutes()).padStart(2, '0');
58
+ var second = String(now.getSeconds()).padStart(2, '0');
59
+ var millisecond = String(now.getMilliseconds()).padStart(3, '0');
60
+ var randomDigits = Math.floor(Math.random() * 9000) + 1000; // 1000-9999的4位随机数
61
+
62
+ return "".concat(year).concat(month).concat(day).concat(hour).concat(minute).concat(second).concat(millisecond).concat(randomDigits);
63
+ }
64
+
65
+ /**
66
+ * 支付模块实现
67
+ *
68
+ * 支付流程说明:
69
+ * 1. 用户操作 → 调用支付API (pushPaymentAsync, submitPayAsync等)
70
+ * 2. 数据处理 → 更新本地IndexDB中的订单和支付项数据
71
+ * 3. 立即完成 → 本地订单状态立即更新为PaymentStatus.Finished(isSynced保持false)
72
+ * 4. 后台同步 → 网络请求推送到TasksManager异步同步到服务器
73
+ * 5. 同步成功 → 网络请求成功后,isSynced设为true
74
+ * 6. 自动重试 → TasksManager自动重试失败的网络请求,直到isSynced为true
75
+ *
76
+ * 数据状态说明:
77
+ * - PaymentStatus.Processing: 订单正在进行支付操作
78
+ * - PaymentStatus.PartiallyPaid + isSynced=false: 部分支付完成,等待服务器同步
79
+ * - PaymentStatus.PartiallyPaid + isSynced=true: 部分支付且已同步到服务器
80
+ * - PaymentStatus.Finished + isSynced=false: 本地支付完成,等待服务器同步
81
+ * - PaymentStatus.Finished + isSynced=true: 支付完成且已同步到服务器
82
+ *
83
+ * 这种设计的优势:
84
+ * - 即时反馈:支付操作后立即显示完成状态,用户体验更佳
85
+ * - 离线支持:即使网络断开也能正常操作,数据保存在本地
86
+ * - 同步追踪:通过isSynced清楚知道哪些数据还未同步到服务器
87
+ * - 自动重试:TasksManager会自动重试失败的网络请求
88
+ * - 异步处理:不阻塞用户界面,网络同步在后台进行
89
+ * - 数据一致性:通过事件系统确保数据状态同步
90
+ */
22
91
  export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
23
92
  _inherits(PaymentModule, _BaseModule);
24
93
  var _super = _createSuper(PaymentModule);
@@ -26,26 +95,66 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
26
95
  var _this;
27
96
  _classCallCheck(this, PaymentModule);
28
97
  _this = _super.call(this, name, version);
29
- _defineProperty(_assertThisInitialized(_this), "defaultName", 'bookingByStep');
98
+ // 初始化支付方式实例
99
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'pay');
30
100
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
31
- _defineProperty(_assertThisInitialized(_this), "state", {
32
- currentPayment: null,
33
- paymentHistory: []
34
- });
101
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
102
+ _defineProperty(_assertThisInitialized(_this), "app", void 0);
103
+ // App instance
104
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
105
+ _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
106
+ // IndexDBManager 实例
107
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
108
+ // LoggerManager 实例
109
+ // 支付方式实例
110
+ _defineProperty(_assertThisInitialized(_this), "cash", void 0);
111
+ _defineProperty(_assertThisInitialized(_this), "eftpos", void 0);
112
+ _defineProperty(_assertThisInitialized(_this), "wallet", void 0);
113
+ _this.cash = new CashPaymentImpl(_assertThisInitialized(_this));
114
+ _this.eftpos = new EftposPaymentImpl(_assertThisInitialized(_this));
115
+ _this.wallet = new WalletPaymentImpl(_assertThisInitialized(_this));
35
116
  return _this;
36
117
  }
37
118
  _createClass(PaymentModule, [{
38
119
  key: "initialize",
39
120
  value: function () {
40
121
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
122
+ var appPlugin;
41
123
  return _regeneratorRuntime().wrap(function _callee$(_context) {
42
124
  while (1) switch (_context.prev = _context.next) {
43
125
  case 0:
44
126
  this.core = core;
45
- if (options !== null && options !== void 0 && options.initialState) {
46
- this.state = _objectSpread(_objectSpread({}, this.state), options.initialState);
127
+ this.store = options.store;
128
+
129
+ // 获取依赖的插件
130
+ this.request = core.getPlugin('request');
131
+ appPlugin = core.getPlugin('app');
132
+ if (this.request) {
133
+ _context.next = 6;
134
+ break;
47
135
  }
48
- case 2:
136
+ throw new Error('支付模块需要 request 插件支持');
137
+ case 6:
138
+ if (appPlugin) {
139
+ _context.next = 8;
140
+ break;
141
+ }
142
+ throw new Error('支付模块需要 app 插件支持');
143
+ case 8:
144
+ this.app = appPlugin.getApp();
145
+ this.dbManager = this.app.dbManager;
146
+ this.logger = this.app.logger;
147
+
148
+ // 确保支付模块所需的对象存储已创建
149
+ _context.next = 13;
150
+ return this.ensurePaymentTables();
151
+ case 13:
152
+ // 注册任务处理函数
153
+ this.registerTaskHandlers();
154
+ this.registerNetworkHandlers();
155
+ console.log('[PaymentModule] 初始化完成');
156
+ this.logInfo('PaymentModule initialized successfully');
157
+ case 17:
49
158
  case "end":
50
159
  return _context.stop();
51
160
  }
@@ -55,158 +164,1892 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
55
164
  return _initialize.apply(this, arguments);
56
165
  }
57
166
  return initialize;
58
- }() // async initPayment(order: OrderModule, method: PaymentMethod) {
59
- // const payment: Payment = {}
60
- // this.state.currentPayment = payment
61
- // await this.core.effects.emit(PaymentHooks.OnPaymentInit, payment)
62
- // return payment
63
- // }
64
- }, {
65
- key: "processPayment",
66
- value: function () {
67
- var _processPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(paymentId) {
68
- var payment;
167
+ }()
168
+ /**
169
+ * 记录信息日志
170
+ */
171
+ }, {
172
+ key: "logInfo",
173
+ value: function logInfo(title, metadata) {
174
+ if (this.logger) {
175
+ this.logger.addLog({
176
+ type: 'info',
177
+ title: "[PaymentModule] ".concat(title),
178
+ metadata: metadata || {}
179
+ });
180
+ }
181
+ }
182
+
183
+ /**
184
+ * 记录警告日志
185
+ */
186
+ }, {
187
+ key: "logWarning",
188
+ value: function logWarning(title, metadata) {
189
+ if (this.logger) {
190
+ this.logger.addLog({
191
+ type: 'warning',
192
+ title: "[PaymentModule] ".concat(title),
193
+ metadata: metadata || {}
194
+ });
195
+ }
196
+ }
197
+
198
+ /**
199
+ * 记录错误日志
200
+ */
201
+ }, {
202
+ key: "logError",
203
+ value: function logError(title, error, metadata) {
204
+ if (this.logger) {
205
+ this.logger.addLog({
206
+ type: 'error',
207
+ title: "[PaymentModule] ".concat(title),
208
+ metadata: _objectSpread({
209
+ error: error ? _objectSpread({
210
+ message: error.message,
211
+ stack: error.stack,
212
+ code: error.code
213
+ }, error) : undefined
214
+ }, metadata || {})
215
+ });
216
+ }
217
+ }
218
+
219
+ /**
220
+ * 记录调试日志
221
+ */
222
+ }, {
223
+ key: "logDebug",
224
+ value: function logDebug(title, metadata) {
225
+ if (this.logger) {
226
+ this.logger.addLog({
227
+ type: 'debug',
228
+ title: "[PaymentModule] ".concat(title),
229
+ metadata: metadata || {}
230
+ });
231
+ }
232
+ }
233
+
234
+ /**
235
+ * 网络恢复以后,尝试执行队列
236
+ *
237
+ */
238
+ }, {
239
+ key: "registerNetworkHandlers",
240
+ value: function registerNetworkHandlers() {
241
+ var _this2 = this;
242
+ var network = this.app.plugins.get('network');
243
+ this.logInfo('Registering network status listener');
244
+ network === null || network === void 0 || network.addListener('networkStatusChange', function (status) {
245
+ console.log('网络状态:', status.connected);
246
+ _this2.logInfo('Network status changed', {
247
+ connected: status.connected,
248
+ previousStatus: status.previousStatus
249
+ });
250
+ if (status.connected) {
251
+ _this2.logInfo('Network reconnected - triggering payment sync queue');
252
+ _this2.runPaymentSyncQueue();
253
+ }
254
+ });
255
+ }
256
+
257
+ /**
258
+ * 获取支付方式列表
259
+ */
260
+ }, {
261
+ key: "getPayMethodListAsync",
262
+ value: (function () {
263
+ var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
264
+ var cachedMethods, hasCache, response, payMethods, _iterator, _step, method;
69
265
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
70
266
  while (1) switch (_context2.prev = _context2.next) {
71
267
  case 0:
72
- payment = this.state.paymentHistory.find(function (p) {
73
- return p.id === paymentId;
74
- });
75
- if (payment) {
76
- _context2.next = 3;
268
+ this.logInfo('Starting getPayMethodListAsync');
269
+ _context2.prev = 1;
270
+ // 先尝试从 IndexDB 获取缓存
271
+ cachedMethods = [];
272
+ _context2.prev = 3;
273
+ _context2.next = 6;
274
+ return this.dbManager.getAll('pay_method');
275
+ case 6:
276
+ cachedMethods = _context2.sent;
277
+ _context2.next = 12;
278
+ break;
279
+ case 9:
280
+ _context2.prev = 9;
281
+ _context2.t0 = _context2["catch"](3);
282
+ console.warn('[PaymentModule] pay_method 表不存在,将从服务器获取数据');
283
+ case 12:
284
+ // 如果有缓存,先返回缓存数据
285
+ hasCache = cachedMethods.length > 0;
286
+ if (!hasCache) {
287
+ _context2.next = 16;
77
288
  break;
78
289
  }
79
- return _context2.abrupt("return");
80
- case 3:
81
- payment.status = 'processing';
82
- payment.updatedAt = new Date();
83
- _context2.next = 7;
84
- return this.core.effects.emit(PaymentHooks.OnPaymentSuccess, payment);
85
- case 7:
290
+ // 后台异步获取最新数据
291
+ this.refreshPaymentMethodsInBackground(cachedMethods);
292
+ return _context2.abrupt("return", cachedMethods);
293
+ case 16:
294
+ _context2.next = 18;
295
+ return this.request.get('/pay/custom-payment/available');
296
+ case 18:
297
+ response = _context2.sent;
298
+ payMethods = response.data || []; // 尝试缓存到 IndexDB
299
+ _context2.prev = 20;
300
+ _iterator = _createForOfIteratorHelper(payMethods);
301
+ _context2.prev = 22;
302
+ _iterator.s();
303
+ case 24:
304
+ if ((_step = _iterator.n()).done) {
305
+ _context2.next = 30;
306
+ break;
307
+ }
308
+ method = _step.value;
309
+ _context2.next = 28;
310
+ return this.dbManager.update('pay_method', method);
311
+ case 28:
312
+ _context2.next = 24;
313
+ break;
314
+ case 30:
315
+ _context2.next = 35;
316
+ break;
317
+ case 32:
318
+ _context2.prev = 32;
319
+ _context2.t1 = _context2["catch"](22);
320
+ _iterator.e(_context2.t1);
321
+ case 35:
322
+ _context2.prev = 35;
323
+ _iterator.f();
324
+ return _context2.finish(35);
325
+ case 38:
326
+ _context2.next = 43;
327
+ break;
328
+ case 40:
329
+ _context2.prev = 40;
330
+ _context2.t2 = _context2["catch"](20);
331
+ console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
332
+ case 43:
333
+ _context2.next = 45;
334
+ return this.core.effects.emit(PaymentHooks.OnPaymentMethodsLoaded, payMethods);
335
+ case 45:
336
+ this.logInfo('getPayMethodListAsync completed successfully', {
337
+ methodCount: payMethods.length,
338
+ hasCache: cachedMethods.length > 0
339
+ });
340
+ return _context2.abrupt("return", payMethods);
341
+ case 49:
342
+ _context2.prev = 49;
343
+ _context2.t3 = _context2["catch"](1);
344
+ console.error('[PaymentModule] 获取支付方式列表失败', _context2.t3);
345
+ this.logError('getPayMethodListAsync failed', _context2.t3);
346
+ // 如果所有操作都失败,返回空数组
347
+ return _context2.abrupt("return", []);
348
+ case 54:
86
349
  case "end":
87
350
  return _context2.stop();
88
351
  }
89
- }, _callee2, this);
352
+ }, _callee2, this, [[1, 49], [3, 9], [20, 40], [22, 32, 35, 38]]);
90
353
  }));
91
- function processPayment(_x3) {
92
- return _processPayment.apply(this, arguments);
354
+ function getPayMethodListAsync() {
355
+ return _getPayMethodListAsync.apply(this, arguments);
93
356
  }
94
- return processPayment;
357
+ return getPayMethodListAsync;
95
358
  }()
359
+ /**
360
+ * 后台刷新支付方式列表
361
+ */
362
+ )
96
363
  }, {
97
- key: "getPayment",
98
- value: function () {
99
- var _getPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(paymentId) {
100
- var payment;
364
+ key: "refreshPaymentMethodsInBackground",
365
+ value: (function () {
366
+ var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(cachedMethods) {
367
+ var response, newPayMethods, hasChanges, _iterator2, _step2, method, _iterator3, _step3, _method, eventData;
101
368
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
102
369
  while (1) switch (_context3.prev = _context3.next) {
103
370
  case 0:
104
- payment = this.state.paymentHistory.find(function (p) {
105
- return p.id === paymentId;
371
+ this.logInfo('Starting refreshPaymentMethodsInBackground', {
372
+ cachedMethodsCount: cachedMethods.length
106
373
  });
107
- if (payment) {
108
- _context3.next = 3;
374
+ _context3.prev = 1;
375
+ console.log('[PaymentModule] 后台刷新支付方式列表...');
376
+
377
+ // 从服务器获取最新数据
378
+ _context3.next = 5;
379
+ return this.request.get('/pay/custom-payment/available');
380
+ case 5:
381
+ response = _context3.sent;
382
+ newPayMethods = response.data || []; // 检查是否有变化
383
+ hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
384
+ if (!hasChanges) {
385
+ _context3.next = 56;
109
386
  break;
110
387
  }
111
- throw new Error('Payment not found');
112
- case 3:
113
- return _context3.abrupt("return", payment);
114
- case 4:
388
+ console.log('[PaymentModule] 支付方式列表已更新');
389
+ this.logInfo('Payment methods updated in background', {
390
+ oldCount: cachedMethods.length,
391
+ newCount: newPayMethods.length
392
+ });
393
+
394
+ // 更新缓存
395
+ _context3.prev = 11;
396
+ // 先清除旧数据
397
+ _iterator2 = _createForOfIteratorHelper(cachedMethods);
398
+ _context3.prev = 13;
399
+ _iterator2.s();
400
+ case 15:
401
+ if ((_step2 = _iterator2.n()).done) {
402
+ _context3.next = 21;
403
+ break;
404
+ }
405
+ method = _step2.value;
406
+ _context3.next = 19;
407
+ return this.dbManager.delete('pay_method', method.id);
408
+ case 19:
409
+ _context3.next = 15;
410
+ break;
411
+ case 21:
412
+ _context3.next = 26;
413
+ break;
414
+ case 23:
415
+ _context3.prev = 23;
416
+ _context3.t0 = _context3["catch"](13);
417
+ _iterator2.e(_context3.t0);
418
+ case 26:
419
+ _context3.prev = 26;
420
+ _iterator2.f();
421
+ return _context3.finish(26);
422
+ case 29:
423
+ // 添加新数据
424
+ _iterator3 = _createForOfIteratorHelper(newPayMethods);
425
+ _context3.prev = 30;
426
+ _iterator3.s();
427
+ case 32:
428
+ if ((_step3 = _iterator3.n()).done) {
429
+ _context3.next = 38;
430
+ break;
431
+ }
432
+ _method = _step3.value;
433
+ _context3.next = 36;
434
+ return this.dbManager.update('pay_method', _method);
435
+ case 36:
436
+ _context3.next = 32;
437
+ break;
438
+ case 38:
439
+ _context3.next = 43;
440
+ break;
441
+ case 40:
442
+ _context3.prev = 40;
443
+ _context3.t1 = _context3["catch"](30);
444
+ _iterator3.e(_context3.t1);
445
+ case 43:
446
+ _context3.prev = 43;
447
+ _iterator3.f();
448
+ return _context3.finish(43);
449
+ case 46:
450
+ _context3.next = 51;
451
+ break;
452
+ case 48:
453
+ _context3.prev = 48;
454
+ _context3.t2 = _context3["catch"](11);
455
+ console.warn('[PaymentModule] 无法更新支付方式缓存', _context3.t2);
456
+ case 51:
457
+ // 通知外部支付方式已变化
458
+ eventData = {
459
+ oldMethods: cachedMethods,
460
+ newMethods: newPayMethods
461
+ };
462
+ _context3.next = 54;
463
+ return this.core.effects.emit(PaymentHooks.OnPaymentMethodsChanged, eventData);
464
+ case 54:
465
+ _context3.next = 57;
466
+ break;
467
+ case 56:
468
+ console.log('[PaymentModule] 支付方式列表无变化');
469
+ case 57:
470
+ _context3.next = 62;
471
+ break;
472
+ case 59:
473
+ _context3.prev = 59;
474
+ _context3.t3 = _context3["catch"](1);
475
+ console.error('[PaymentModule] 后台刷新支付方式失败', _context3.t3);
476
+ case 62:
115
477
  case "end":
116
478
  return _context3.stop();
117
479
  }
118
- }, _callee3, this);
480
+ }, _callee3, this, [[1, 59], [11, 48], [13, 23, 26, 29], [30, 40, 43, 46]]);
119
481
  }));
120
- function getPayment(_x4) {
121
- return _getPayment.apply(this, arguments);
482
+ function refreshPaymentMethodsInBackground(_x3) {
483
+ return _refreshPaymentMethodsInBackground.apply(this, arguments);
122
484
  }
123
- return getPayment;
485
+ return refreshPaymentMethodsInBackground;
124
486
  }()
487
+ /**
488
+ * 检查支付方式列表是否有变化
489
+ */
490
+ )
125
491
  }, {
126
- key: "getPaymentHistory",
127
- value: function () {
128
- var _getPaymentHistory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
492
+ key: "hasPaymentMethodsChanged",
493
+ value: function hasPaymentMethodsChanged(oldMethods, newMethods) {
494
+ if (oldMethods.length !== newMethods.length) {
495
+ return true;
496
+ }
497
+
498
+ // 创建旧数据的 Map 便于查找
499
+ var oldMethodsMap = new Map(oldMethods.map(function (method) {
500
+ return [method.id, method];
501
+ }));
502
+
503
+ // 检查每个新方法是否与旧方法相同
504
+ var _iterator4 = _createForOfIteratorHelper(newMethods),
505
+ _step4;
506
+ try {
507
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
508
+ var newMethod = _step4.value;
509
+ var oldMethod = oldMethodsMap.get(newMethod.id);
510
+ if (!oldMethod) {
511
+ return true; // 新增方法
512
+ }
513
+
514
+ // 检查关键字段是否有变化
515
+ if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.enabled !== newMethod.enabled) {
516
+ return true; // 方法属性有变化
517
+ }
518
+ }
519
+ } catch (err) {
520
+ _iterator4.e(err);
521
+ } finally {
522
+ _iterator4.f();
523
+ }
524
+ return false;
525
+ }
526
+
527
+ /**
528
+ * 获取订单列表
529
+ */
530
+ }, {
531
+ key: "getOrderListAsync",
532
+ value: (function () {
533
+ var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
129
534
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
130
535
  while (1) switch (_context4.prev = _context4.next) {
131
536
  case 0:
132
- return _context4.abrupt("return", this.state.paymentHistory);
133
- case 1:
537
+ _context4.prev = 0;
538
+ _context4.next = 3;
539
+ return this.dbManager.getAll('order');
540
+ case 3:
541
+ return _context4.abrupt("return", _context4.sent);
542
+ case 6:
543
+ _context4.prev = 6;
544
+ _context4.t0 = _context4["catch"](0);
545
+ console.error('[PaymentModule] 获取订单列表失败', _context4.t0);
546
+ return _context4.abrupt("return", []);
547
+ case 10:
134
548
  case "end":
135
549
  return _context4.stop();
136
550
  }
137
- }, _callee4, this);
551
+ }, _callee4, this, [[0, 6]]);
138
552
  }));
139
- function getPaymentHistory() {
140
- return _getPaymentHistory.apply(this, arguments);
553
+ function getOrderListAsync() {
554
+ return _getOrderListAsync.apply(this, arguments);
141
555
  }
142
- return getPaymentHistory;
556
+ return getOrderListAsync;
143
557
  }()
558
+ /**
559
+ * 根据uuid获取指定订单
560
+ */
561
+ )
144
562
  }, {
145
- key: "refund",
146
- value: function () {
147
- var _refund = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(paymentId) {
148
- var payment;
563
+ key: "getOrderByUuidAsync",
564
+ value: (function () {
565
+ var _getOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderUuid) {
149
566
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
150
567
  while (1) switch (_context5.prev = _context5.next) {
151
568
  case 0:
152
- payment = this.state.paymentHistory.find(function (p) {
153
- return p.id === paymentId;
569
+ _context5.prev = 0;
570
+ _context5.next = 3;
571
+ return this.dbManager.get('order', orderUuid);
572
+ case 3:
573
+ return _context5.abrupt("return", _context5.sent);
574
+ case 6:
575
+ _context5.prev = 6;
576
+ _context5.t0 = _context5["catch"](0);
577
+ console.error('[PaymentModule] 获取订单失败', _context5.t0);
578
+ return _context5.abrupt("return", null);
579
+ case 10:
580
+ case "end":
581
+ return _context5.stop();
582
+ }
583
+ }, _callee5, this, [[0, 6]]);
584
+ }));
585
+ function getOrderByUuidAsync(_x4) {
586
+ return _getOrderByUuidAsync.apply(this, arguments);
587
+ }
588
+ return getOrderByUuidAsync;
589
+ }()
590
+ /**
591
+ * 往交易组中添加订单
592
+ */
593
+ )
594
+ }, {
595
+ key: "pushOrderAsync",
596
+ value: (function () {
597
+ var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
598
+ var existingOrders, existingOrder, originalOrder, newOrder;
599
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
600
+ while (1) switch (_context6.prev = _context6.next) {
601
+ case 0:
602
+ this.logInfo('Starting pushOrderAsync', {
603
+ orderId: params.order_info.order_id,
604
+ totalAmount: params.order_info.total_amount
605
+ });
606
+ _context6.prev = 1;
607
+ _context6.next = 4;
608
+ return this.dbManager.getAll('order');
609
+ case 4:
610
+ existingOrders = _context6.sent;
611
+ existingOrder = existingOrders.find(function (order) {
612
+ return order.id === params.order_info.order_id;
154
613
  });
155
- if (payment) {
156
- _context5.next = 3;
614
+ if (!existingOrder) {
615
+ _context6.next = 21;
157
616
  break;
158
617
  }
159
- return _context5.abrupt("return");
618
+ // 如果存在相同 order_id 的订单,更新该订单的 order_info
619
+ console.log("[PaymentModule] \u53D1\u73B0\u91CD\u590D\u8BA2\u5355 ID: ".concat(params.order_info.order_id, "\uFF0C\u66F4\u65B0\u73B0\u6709\u8BA2\u5355"));
620
+ originalOrder = _objectSpread({}, existingOrder);
621
+ existingOrder.order_info = params.order_info;
622
+ existingOrder.total_amount = params.order_info.total_amount;
623
+
624
+ // 重新计算待付金额
625
+ this.recalculateOrderAmount(existingOrder);
626
+
627
+ // 更新到数据库
628
+ _context6.next = 14;
629
+ return this.dbManager.update('order', existingOrder);
630
+ case 14:
631
+ _context6.next = 16;
632
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
633
+ case 16:
634
+ _context6.next = 18;
635
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
636
+ action: 'update',
637
+ order: existingOrder,
638
+ originalOrder: originalOrder
639
+ });
640
+ case 18:
641
+ return _context6.abrupt("return", existingOrder);
642
+ case 21:
643
+ // 如果不存在相同 order_id 的订单,创建新订单
644
+ newOrder = {
645
+ uuid: getUniqueId('pay_order_'),
646
+ id: params.order_info.order_id,
647
+ order_info: params.order_info,
648
+ payment_status: PaymentStatus.Processing,
649
+ payment: [],
650
+ adjust_offline_payments: [],
651
+ total_amount: params.order_info.total_amount,
652
+ expect_amount: params.order_info.total_amount,
653
+ tax_fee: '0.00'
654
+ };
655
+ _context6.next = 24;
656
+ return this.dbManager.add('order', newOrder);
657
+ case 24:
658
+ _context6.next = 26;
659
+ return this.core.effects.emit(PaymentHooks.OnOrderAdded, newOrder);
660
+ case 26:
661
+ _context6.next = 28;
662
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
663
+ action: 'add',
664
+ order: newOrder
665
+ });
666
+ case 28:
667
+ this.logInfo('pushOrderAsync completed - new order created', {
668
+ orderUuid: newOrder.uuid,
669
+ orderId: newOrder.id
670
+ });
671
+ return _context6.abrupt("return", newOrder);
672
+ case 30:
673
+ _context6.next = 37;
674
+ break;
675
+ case 32:
676
+ _context6.prev = 32;
677
+ _context6.t0 = _context6["catch"](1);
678
+ console.error('[PaymentModule] 添加订单失败', _context6.t0);
679
+ this.logError('pushOrderAsync failed', _context6.t0, {
680
+ orderId: params.order_info.order_id
681
+ });
682
+ throw _context6.t0;
683
+ case 37:
684
+ case "end":
685
+ return _context6.stop();
686
+ }
687
+ }, _callee6, this, [[1, 32]]);
688
+ }));
689
+ function pushOrderAsync(_x5) {
690
+ return _pushOrderAsync.apply(this, arguments);
691
+ }
692
+ return pushOrderAsync;
693
+ }()
694
+ /**
695
+ * 删除订单
696
+ */
697
+ )
698
+ }, {
699
+ key: "deleteOrderAsync",
700
+ value: (function () {
701
+ var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(orderUuid) {
702
+ var order;
703
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
704
+ while (1) switch (_context7.prev = _context7.next) {
705
+ case 0:
706
+ _context7.prev = 0;
707
+ _context7.next = 3;
708
+ return this.dbManager.get('order', orderUuid);
160
709
  case 3:
161
- payment.status = 'refunded';
162
- payment.updatedAt = new Date();
163
- _context5.next = 7;
164
- return this.core.effects.emit(PaymentHooks.OnPaymentRefund, payment);
710
+ order = _context7.sent;
711
+ if (!order) {
712
+ _context7.next = 11;
713
+ break;
714
+ }
715
+ _context7.next = 7;
716
+ return this.dbManager.delete('order', orderUuid);
165
717
  case 7:
718
+ _context7.next = 9;
719
+ return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
720
+ case 9:
721
+ _context7.next = 11;
722
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
723
+ action: 'delete',
724
+ order: order
725
+ });
726
+ case 11:
727
+ _context7.next = 17;
728
+ break;
729
+ case 13:
730
+ _context7.prev = 13;
731
+ _context7.t0 = _context7["catch"](0);
732
+ console.error('[PaymentModule] 删除订单失败', _context7.t0);
733
+ throw _context7.t0;
734
+ case 17:
166
735
  case "end":
167
- return _context5.stop();
736
+ return _context7.stop();
168
737
  }
169
- }, _callee5, this);
738
+ }, _callee7, this, [[0, 13]]);
170
739
  }));
171
- function refund(_x5) {
172
- return _refund.apply(this, arguments);
740
+ function deleteOrderAsync(_x6) {
741
+ return _deleteOrderAsync.apply(this, arguments);
173
742
  }
174
- return refund;
743
+ return deleteOrderAsync;
175
744
  }()
745
+ /**
746
+ * 更新订单
747
+ */
748
+ )
176
749
  }, {
177
- key: "getAvailablePaymentMethods",
178
- value: function getAvailablePaymentMethods() {
179
- return ['credit_card', 'debit_card', 'alipay', 'wechat_pay'];
180
- }
750
+ key: "updateOrderAsync",
751
+ value: (function () {
752
+ var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid, params) {
753
+ var order, updatedOrder;
754
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
755
+ while (1) switch (_context8.prev = _context8.next) {
756
+ case 0:
757
+ _context8.prev = 0;
758
+ _context8.next = 3;
759
+ return this.dbManager.get('order', orderUuid);
760
+ case 3:
761
+ order = _context8.sent;
762
+ if (!order) {
763
+ _context8.next = 12;
764
+ break;
765
+ }
766
+ updatedOrder = _objectSpread(_objectSpread({}, order), params);
767
+ _context8.next = 8;
768
+ return this.dbManager.update('order', updatedOrder);
769
+ case 8:
770
+ _context8.next = 10;
771
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
772
+ case 10:
773
+ _context8.next = 12;
774
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
775
+ action: 'update',
776
+ order: updatedOrder,
777
+ originalOrder: order
778
+ });
779
+ case 12:
780
+ _context8.next = 18;
781
+ break;
782
+ case 14:
783
+ _context8.prev = 14;
784
+ _context8.t0 = _context8["catch"](0);
785
+ console.error('[PaymentModule] 更新订单失败', _context8.t0);
786
+ throw _context8.t0;
787
+ case 18:
788
+ case "end":
789
+ return _context8.stop();
790
+ }
791
+ }, _callee8, this, [[0, 14]]);
792
+ }));
793
+ function updateOrderAsync(_x7, _x8) {
794
+ return _updateOrderAsync.apply(this, arguments);
795
+ }
796
+ return updateOrderAsync;
797
+ }()
798
+ /**
799
+ * 获取支付项
800
+ */
801
+ )
181
802
  }, {
182
- key: "checkPaymentStatus",
183
- value: function () {
184
- var _checkPaymentStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(paymentId) {
185
- var payment;
186
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
187
- while (1) switch (_context6.prev = _context6.next) {
803
+ key: "getPaymentAsync",
804
+ value: (function () {
805
+ var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid) {
806
+ var order;
807
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
808
+ while (1) switch (_context9.prev = _context9.next) {
809
+ case 0:
810
+ if (orderUuid) {
811
+ _context9.next = 2;
812
+ break;
813
+ }
814
+ throw new Error('orderUuid is required');
815
+ case 2:
816
+ _context9.next = 4;
817
+ return this.getOrderByUuidAsync(orderUuid);
818
+ case 4:
819
+ order = _context9.sent;
820
+ return _context9.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
821
+ case 6:
822
+ case "end":
823
+ return _context9.stop();
824
+ }
825
+ }, _callee9, this);
826
+ }));
827
+ function getPaymentAsync(_x9) {
828
+ return _getPaymentAsync.apply(this, arguments);
829
+ }
830
+ return getPaymentAsync;
831
+ }()
832
+ /**
833
+ * 为某个订单设置一个支付项
834
+ */
835
+ )
836
+ }, {
837
+ key: "pushPaymentAsync",
838
+ value: (function () {
839
+ var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid, paymentItem) {
840
+ var order, newPaymentItem;
841
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
842
+ while (1) switch (_context10.prev = _context10.next) {
188
843
  case 0:
189
- payment = this.state.paymentHistory.find(function (p) {
190
- return p.id === paymentId;
844
+ this.logInfo('Starting pushPaymentAsync', {
845
+ orderUuid: orderUuid,
846
+ paymentAmount: paymentItem.amount,
847
+ paymentCode: paymentItem.code
191
848
  });
192
- if (payment) {
193
- _context6.next = 3;
849
+ _context10.prev = 1;
850
+ _context10.next = 4;
851
+ return this.dbManager.get('order', orderUuid);
852
+ case 4:
853
+ order = _context10.sent;
854
+ if (order) {
855
+ _context10.next = 7;
194
856
  break;
195
857
  }
196
- throw new Error('Payment not found');
197
- case 3:
198
- return _context6.abrupt("return", payment.status);
858
+ throw new Error('订单不存在');
859
+ case 7:
860
+ newPaymentItem = _objectSpread(_objectSpread({}, paymentItem), {}, {
861
+ amount: formatAmount(paymentItem.amount),
862
+ // 格式化金额为保留两位小数的字符串
863
+ uuid: getUniqueId('pay_item_'),
864
+ isSynced: false
865
+ });
866
+ order.payment.push(newPaymentItem);
867
+
868
+ // 重新计算待付金额
869
+ this.recalculateOrderAmount(order);
870
+
871
+ // 更新到 IndexDB
872
+ _context10.next = 12;
873
+ return this.dbManager.update('order', order);
874
+ case 12:
875
+ _context10.next = 14;
876
+ return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
877
+ order: order,
878
+ paymentItem: newPaymentItem
879
+ });
880
+ case 14:
881
+ _context10.next = 16;
882
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
883
+ action: 'payment_add',
884
+ order: order,
885
+ paymentItem: newPaymentItem
886
+ });
887
+ case 16:
888
+ this.logInfo('pushPaymentAsync completed successfully', {
889
+ orderUuid: orderUuid,
890
+ paymentUuid: newPaymentItem.uuid,
891
+ newExpectAmount: order.expect_amount
892
+ });
893
+ _context10.next = 24;
894
+ break;
895
+ case 19:
896
+ _context10.prev = 19;
897
+ _context10.t0 = _context10["catch"](1);
898
+ console.error('[PaymentModule] 添加支付项失败', _context10.t0);
899
+ this.logError('pushPaymentAsync failed', _context10.t0, {
900
+ orderUuid: orderUuid,
901
+ paymentItem: paymentItem
902
+ });
903
+ throw _context10.t0;
904
+ case 24:
905
+ case "end":
906
+ return _context10.stop();
907
+ }
908
+ }, _callee10, this, [[1, 19]]);
909
+ }));
910
+ function pushPaymentAsync(_x10, _x11) {
911
+ return _pushPaymentAsync.apply(this, arguments);
912
+ }
913
+ return pushPaymentAsync;
914
+ }()
915
+ /**
916
+ * 删除一个支付项
917
+ */
918
+ )
919
+ }, {
920
+ key: "deletePaymentAsync",
921
+ value: (function () {
922
+ var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, paymentUuid) {
923
+ var order, index, deletedPayment;
924
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
925
+ while (1) switch (_context11.prev = _context11.next) {
926
+ case 0:
927
+ this.logInfo('Starting deletePaymentAsync', {
928
+ orderUuid: orderUuid,
929
+ paymentUuid: paymentUuid
930
+ });
931
+ _context11.prev = 1;
932
+ _context11.next = 4;
933
+ return this.dbManager.get('order', orderUuid);
199
934
  case 4:
935
+ order = _context11.sent;
936
+ if (order) {
937
+ _context11.next = 7;
938
+ break;
939
+ }
940
+ throw new Error('订单不存在');
941
+ case 7:
942
+ index = order.payment.findIndex(function (payment) {
943
+ return payment.uuid === paymentUuid;
944
+ });
945
+ if (!(index > -1)) {
946
+ _context11.next = 17;
947
+ break;
948
+ }
949
+ deletedPayment = order.payment.splice(index, 1)[0]; // 重新计算待付金额
950
+ this.recalculateOrderAmount(order);
951
+
952
+ // 更新到 IndexDB
953
+ _context11.next = 13;
954
+ return this.dbManager.update('order', order);
955
+ case 13:
956
+ _context11.next = 15;
957
+ return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
958
+ order: order,
959
+ paymentItem: deletedPayment
960
+ });
961
+ case 15:
962
+ _context11.next = 17;
963
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
964
+ action: 'payment_delete',
965
+ order: order,
966
+ paymentItem: deletedPayment
967
+ });
968
+ case 17:
969
+ _context11.next = 23;
970
+ break;
971
+ case 19:
972
+ _context11.prev = 19;
973
+ _context11.t0 = _context11["catch"](1);
974
+ console.error('[PaymentModule] 删除支付项失败', _context11.t0);
975
+ throw _context11.t0;
976
+ case 23:
200
977
  case "end":
201
- return _context6.stop();
978
+ return _context11.stop();
979
+ }
980
+ }, _callee11, this, [[1, 19]]);
981
+ }));
982
+ function deletePaymentAsync(_x12, _x13) {
983
+ return _deletePaymentAsync.apply(this, arguments);
984
+ }
985
+ return deletePaymentAsync;
986
+ }()
987
+ /**
988
+ * 更新一个支付项
989
+ */
990
+ )
991
+ }, {
992
+ key: "updatePaymentAsync",
993
+ value: (function () {
994
+ var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, paymentUuid, params) {
995
+ var order, paymentItem, formattedParams;
996
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
997
+ while (1) switch (_context12.prev = _context12.next) {
998
+ case 0:
999
+ _context12.prev = 0;
1000
+ _context12.next = 3;
1001
+ return this.dbManager.get('order', orderUuid);
1002
+ case 3:
1003
+ order = _context12.sent;
1004
+ if (order) {
1005
+ _context12.next = 6;
1006
+ break;
1007
+ }
1008
+ throw new Error('订单不存在');
1009
+ case 6:
1010
+ paymentItem = order.payment.find(function (payment) {
1011
+ return payment.uuid === paymentUuid;
1012
+ });
1013
+ if (!paymentItem) {
1014
+ _context12.next = 18;
1015
+ break;
1016
+ }
1017
+ // 如果更新参数中包含 amount,先格式化
1018
+ formattedParams = _objectSpread({}, params);
1019
+ if ('amount' in formattedParams && formattedParams.amount !== undefined) {
1020
+ formattedParams.amount = formatAmount(formattedParams.amount);
1021
+ }
1022
+ Object.assign(paymentItem, formattedParams);
1023
+
1024
+ // 重新计算待付金额
1025
+ this.recalculateOrderAmount(order);
1026
+
1027
+ // 更新到 IndexDB
1028
+ _context12.next = 14;
1029
+ return this.dbManager.update('order', order);
1030
+ case 14:
1031
+ _context12.next = 16;
1032
+ return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
1033
+ order: order,
1034
+ paymentItem: paymentItem
1035
+ });
1036
+ case 16:
1037
+ _context12.next = 18;
1038
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1039
+ action: 'payment_update',
1040
+ order: order,
1041
+ paymentItem: paymentItem
1042
+ });
1043
+ case 18:
1044
+ _context12.next = 24;
1045
+ break;
1046
+ case 20:
1047
+ _context12.prev = 20;
1048
+ _context12.t0 = _context12["catch"](0);
1049
+ console.error('[PaymentModule] 更新支付项失败', _context12.t0);
1050
+ throw _context12.t0;
1051
+ case 24:
1052
+ case "end":
1053
+ return _context12.stop();
1054
+ }
1055
+ }, _callee12, this, [[0, 20]]);
1056
+ }));
1057
+ function updatePaymentAsync(_x14, _x15, _x16) {
1058
+ return _updatePaymentAsync.apply(this, arguments);
1059
+ }
1060
+ return updatePaymentAsync;
1061
+ }()
1062
+ /**
1063
+ * 提交支付
1064
+ */
1065
+ )
1066
+ }, {
1067
+ key: "submitPayAsync",
1068
+ value: (function () {
1069
+ var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid) {
1070
+ var orderToSubmit, order, _allOrders, _iterator5, _step5, _order, allOrders, allOrdersProcessed, result;
1071
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1072
+ while (1) switch (_context13.prev = _context13.next) {
1073
+ case 0:
1074
+ this.logInfo('Starting submitPayAsync', {
1075
+ orderUuid: orderUuid
1076
+ });
1077
+ _context13.prev = 1;
1078
+ if (!orderUuid) {
1079
+ _context13.next = 9;
1080
+ break;
1081
+ }
1082
+ _context13.next = 5;
1083
+ return this.dbManager.get('order', orderUuid);
1084
+ case 5:
1085
+ order = _context13.sent;
1086
+ orderToSubmit = order ? [order] : [];
1087
+ _context13.next = 13;
1088
+ break;
1089
+ case 9:
1090
+ _context13.next = 11;
1091
+ return this.dbManager.getAll('order');
1092
+ case 11:
1093
+ _allOrders = _context13.sent;
1094
+ // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1095
+ orderToSubmit = _allOrders.filter(function (order) {
1096
+ return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
1097
+ });
1098
+ case 13:
1099
+ _iterator5 = _createForOfIteratorHelper(orderToSubmit);
1100
+ _context13.prev = 14;
1101
+ _iterator5.s();
1102
+ case 16:
1103
+ if ((_step5 = _iterator5.n()).done) {
1104
+ _context13.next = 22;
1105
+ break;
1106
+ }
1107
+ _order = _step5.value;
1108
+ _context13.next = 20;
1109
+ return this.submitSingleOrderPayment(_order);
1110
+ case 20:
1111
+ _context13.next = 16;
1112
+ break;
1113
+ case 22:
1114
+ _context13.next = 27;
1115
+ break;
1116
+ case 24:
1117
+ _context13.prev = 24;
1118
+ _context13.t0 = _context13["catch"](14);
1119
+ _iterator5.e(_context13.t0);
1120
+ case 27:
1121
+ _context13.prev = 27;
1122
+ _iterator5.f();
1123
+ return _context13.finish(27);
1124
+ case 30:
1125
+ _context13.next = 32;
1126
+ return this.runPaymentSyncQueue();
1127
+ case 32:
1128
+ _context13.next = 34;
1129
+ return this.dbManager.getAll('order');
1130
+ case 34:
1131
+ allOrders = _context13.sent;
1132
+ allOrdersProcessed = allOrders.every(function (order) {
1133
+ return order.payment.every(function (payment) {
1134
+ return payment.isSynced === true;
1135
+ });
1136
+ });
1137
+ if (!allOrdersProcessed) {
1138
+ _context13.next = 42;
1139
+ break;
1140
+ }
1141
+ result = {
1142
+ status: 'success'
1143
+ };
1144
+ this.logInfo('submitPayAsync completed', {
1145
+ result: result.status,
1146
+ processedOrdersCount: allOrders.length
1147
+ });
1148
+ return _context13.abrupt("return", result);
1149
+ case 42:
1150
+ this.logWarning('submitPayAsync completed with unprocessed orders', {
1151
+ totalOrders: allOrders.length
1152
+ });
1153
+ return _context13.abrupt("return", {
1154
+ status: 'failed'
1155
+ });
1156
+ case 44:
1157
+ _context13.next = 51;
1158
+ break;
1159
+ case 46:
1160
+ _context13.prev = 46;
1161
+ _context13.t1 = _context13["catch"](1);
1162
+ console.error('[PaymentModule] 提交支付失败', _context13.t1);
1163
+ this.logError('submitPayAsync failed', _context13.t1, {
1164
+ orderUuid: orderUuid
1165
+ });
1166
+ return _context13.abrupt("return", {
1167
+ status: 'failed'
1168
+ });
1169
+ case 51:
1170
+ case "end":
1171
+ return _context13.stop();
1172
+ }
1173
+ }, _callee13, this, [[1, 46], [14, 24, 27, 30]]);
1174
+ }));
1175
+ function submitPayAsync(_x17) {
1176
+ return _submitPayAsync.apply(this, arguments);
1177
+ }
1178
+ return submitPayAsync;
1179
+ }()
1180
+ /**
1181
+ * 提交单个订单的支付(推送到任务队列)
1182
+ */
1183
+ )
1184
+ }, {
1185
+ key: "submitSingleOrderPayment",
1186
+ value: (function () {
1187
+ var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(order) {
1188
+ var paymentData, totalPaidAmount, orderTotalAmount;
1189
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1190
+ while (1) switch (_context14.prev = _context14.next) {
1191
+ case 0:
1192
+ _context14.prev = 0;
1193
+ paymentData = {
1194
+ payments: order.payment.map(function (payment) {
1195
+ return payment;
1196
+ }),
1197
+ payment_status: 'pending'
1198
+ }; // 计算总支付金额
1199
+ totalPaidAmount = paymentData.payments.reduce(function (sum, payment) {
1200
+ return sum.plus(payment.amount);
1201
+ }, new Decimal(0));
1202
+ orderTotalAmount = new Decimal(order.order_info.total_amount); // 根据支付金额判断订单状态
1203
+ if (totalPaidAmount.gte(orderTotalAmount)) {
1204
+ // 支付金额足够,标记为已完成
1205
+ order.payment_status = PaymentStatus.Finished;
1206
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5B8C\u6210\uFF0C\u91D1\u989D: ").concat(totalPaidAmount.toString(), "/").concat(orderTotalAmount.toString()));
1207
+ } else {
1208
+ // 支付金额不足,标记为部分支付
1209
+ order.payment_status = PaymentStatus.PartiallyPaid;
1210
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u90E8\u5206\u652F\u4ED8\uFF0C\u91D1\u989D: ").concat(totalPaidAmount.toString(), "/").concat(orderTotalAmount.toString()));
1211
+ }
1212
+
1213
+ // 给后端标记一下是全部支付(paid)还是部分支付
1214
+ paymentData.payment_status = order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid';
1215
+
1216
+ // 更新订单状态到数据库
1217
+ // 注意:isSynced 保持为 false,直到网络同步成功后才设为 true
1218
+ _context14.next = 8;
1219
+ return this.dbManager.update('order', order);
1220
+ case 8:
1221
+ _context14.next = 10;
1222
+ return this.addToSyncQueue(order, paymentData);
1223
+ case 10:
1224
+ _context14.next = 12;
1225
+ return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
1226
+ case 12:
1227
+ _context14.next = 14;
1228
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1229
+ action: 'submit',
1230
+ order: order
1231
+ });
1232
+ case 14:
1233
+ _context14.next = 20;
1234
+ break;
1235
+ case 16:
1236
+ _context14.prev = 16;
1237
+ _context14.t0 = _context14["catch"](0);
1238
+ console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context14.t0);
1239
+ throw _context14.t0;
1240
+ case 20:
1241
+ case "end":
1242
+ return _context14.stop();
1243
+ }
1244
+ }, _callee14, this, [[0, 16]]);
1245
+ }));
1246
+ function submitSingleOrderPayment(_x18) {
1247
+ return _submitSingleOrderPayment.apply(this, arguments);
1248
+ }
1249
+ return submitSingleOrderPayment;
1250
+ }()
1251
+ /**
1252
+ * 添加到同步任务队列
1253
+ */
1254
+ )
1255
+ }, {
1256
+ key: "addToSyncQueue",
1257
+ value: (function () {
1258
+ var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(order, paymentData) {
1259
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1260
+ while (1) switch (_context15.prev = _context15.next) {
1261
+ case 0:
1262
+ try {
1263
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
1264
+
1265
+ // 集成TasksManager
1266
+ if (this.app.tasksManager) {
1267
+ this.app.tasksManager.addTask({
1268
+ module: 'payment',
1269
+ queueId: 'payment_sync',
1270
+ tasks: [{
1271
+ id: "payment_".concat(order.uuid),
1272
+ action: 'syncPayment',
1273
+ payload: {
1274
+ orderUuid: order.uuid,
1275
+ orderId: order.order_info.order_id,
1276
+ paymentData: paymentData,
1277
+ core: this.core
1278
+ },
1279
+ maxRetries: 3,
1280
+ type: 'cloud'
1281
+ }]
1282
+ });
1283
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u540C\u6B65\u4EFB\u52A1\u5DF2\u6DFB\u52A0\u5230\u961F\u5217"));
1284
+ } else {
1285
+ console.warn('[PaymentModule] TasksManager 未初始化,无法添加同步任务');
1286
+ }
1287
+ } catch (error) {
1288
+ console.error('[PaymentModule] 添加同步任务失败', error);
1289
+ }
1290
+ case 1:
1291
+ case "end":
1292
+ return _context15.stop();
1293
+ }
1294
+ }, _callee15, this);
1295
+ }));
1296
+ function addToSyncQueue(_x19, _x20) {
1297
+ return _addToSyncQueue.apply(this, arguments);
1298
+ }
1299
+ return addToSyncQueue;
1300
+ }()
1301
+ /**
1302
+ * 获取订单剩余待付金额
1303
+ */
1304
+ )
1305
+ }, {
1306
+ key: "getRemainingOrderAmountAsync",
1307
+ value: (function () {
1308
+ var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid) {
1309
+ var order;
1310
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1311
+ while (1) switch (_context16.prev = _context16.next) {
1312
+ case 0:
1313
+ _context16.next = 2;
1314
+ return this.getOrderByUuidAsync(orderUuid);
1315
+ case 2:
1316
+ order = _context16.sent;
1317
+ if (order) {
1318
+ _context16.next = 5;
1319
+ break;
1320
+ }
1321
+ throw new Error('订单不存在');
1322
+ case 5:
1323
+ return _context16.abrupt("return", new Decimal(order.expect_amount).toNumber());
1324
+ case 6:
1325
+ case "end":
1326
+ return _context16.stop();
1327
+ }
1328
+ }, _callee16, this);
1329
+ }));
1330
+ function getRemainingOrderAmountAsync(_x21) {
1331
+ return _getRemainingOrderAmountAsync.apply(this, arguments);
1332
+ }
1333
+ return getRemainingOrderAmountAsync;
1334
+ }()
1335
+ /**
1336
+ * 在比如现金支付界面的地方,用户输入了一个金额,在下方显示剩余多少金额,通过此方法获取
1337
+ */
1338
+ )
1339
+ }, {
1340
+ key: "getRemainingOrderAmountWithInputAsync",
1341
+ value: (function () {
1342
+ var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(inputAmount, orderUuid) {
1343
+ var order, inputDecimal;
1344
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1345
+ while (1) switch (_context17.prev = _context17.next) {
1346
+ case 0:
1347
+ _context17.next = 2;
1348
+ return this.getOrderByUuidAsync(orderUuid);
1349
+ case 2:
1350
+ order = _context17.sent;
1351
+ if (order) {
1352
+ _context17.next = 5;
1353
+ break;
1354
+ }
1355
+ throw new Error('订单不存在');
1356
+ case 5:
1357
+ if (!(inputAmount === null || inputAmount === undefined)) {
1358
+ _context17.next = 7;
1359
+ break;
1360
+ }
1361
+ return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1362
+ case 7:
1363
+ if (!(typeof inputAmount === 'string')) {
1364
+ _context17.next = 10;
1365
+ break;
1366
+ }
1367
+ if (!(inputAmount.trim() === '')) {
1368
+ _context17.next = 10;
1369
+ break;
1370
+ }
1371
+ return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1372
+ case 10:
1373
+ if (!(typeof inputAmount === 'number')) {
1374
+ _context17.next = 14;
1375
+ break;
1376
+ }
1377
+ if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
1378
+ _context17.next = 14;
1379
+ break;
1380
+ }
1381
+ // 如果输入是 NaN 或无穷大,返回原始的待付金额
1382
+ console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1383
+ return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1384
+ case 14:
1385
+ _context17.prev = 14;
1386
+ inputDecimal = new Decimal(inputAmount);
1387
+ return _context17.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1388
+ case 19:
1389
+ _context17.prev = 19;
1390
+ _context17.t0 = _context17["catch"](14);
1391
+ // 如果输入不是有效的数字,返回原始的待付金额
1392
+ console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1393
+ return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1394
+ case 23:
1395
+ case "end":
1396
+ return _context17.stop();
1397
+ }
1398
+ }, _callee17, this, [[14, 19]]);
1399
+ }));
1400
+ function getRemainingOrderAmountWithInputAsync(_x22, _x23) {
1401
+ return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
1402
+ }
1403
+ return getRemainingOrderAmountWithInputAsync;
1404
+ }()
1405
+ /**
1406
+ * 重新计算订单金额
1407
+ */
1408
+ )
1409
+ }, {
1410
+ key: "recalculateOrderAmount",
1411
+ value: function recalculateOrderAmount(order) {
1412
+ var totalAmount = new Decimal(order.order_info.total_amount);
1413
+ var paidAmount = order.payment.reduce(function (sum, payment) {
1414
+ return sum.plus(payment.amount);
1415
+ }, new Decimal(0));
1416
+ var remainingAmount = totalAmount.minus(paidAmount);
1417
+ order.expect_amount = Decimal.max(0, remainingAmount).toFixed(2);
1418
+ }
1419
+
1420
+ /**
1421
+ * 获取现金支付方式
1422
+ */
1423
+ }, {
1424
+ key: "getCashPaymentMethod",
1425
+ value: (function () {
1426
+ var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1427
+ var payMethods;
1428
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1429
+ while (1) switch (_context18.prev = _context18.next) {
1430
+ case 0:
1431
+ _context18.prev = 0;
1432
+ _context18.next = 3;
1433
+ return this.dbManager.getAll('pay_method');
1434
+ case 3:
1435
+ payMethods = _context18.sent;
1436
+ return _context18.abrupt("return", payMethods.find(function (method) {
1437
+ return method.code === PaymentMethodType.Cash;
1438
+ }) || null);
1439
+ case 7:
1440
+ _context18.prev = 7;
1441
+ _context18.t0 = _context18["catch"](0);
1442
+ console.error('[PaymentModule] 获取现金支付方式失败', _context18.t0);
1443
+ return _context18.abrupt("return", null);
1444
+ case 11:
1445
+ case "end":
1446
+ return _context18.stop();
1447
+ }
1448
+ }, _callee18, this, [[0, 7]]);
1449
+ }));
1450
+ function getCashPaymentMethod() {
1451
+ return _getCashPaymentMethod.apply(this, arguments);
1452
+ }
1453
+ return getCashPaymentMethod;
1454
+ }()
1455
+ /**
1456
+ * 获取Eftpos支付方式
1457
+ */
1458
+ )
1459
+ }, {
1460
+ key: "getEftposPaymentMethod",
1461
+ value: (function () {
1462
+ var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1463
+ var payMethods;
1464
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1465
+ while (1) switch (_context19.prev = _context19.next) {
1466
+ case 0:
1467
+ _context19.prev = 0;
1468
+ _context19.next = 3;
1469
+ return this.dbManager.getAll('pay_method');
1470
+ case 3:
1471
+ payMethods = _context19.sent;
1472
+ return _context19.abrupt("return", payMethods.find(function (method) {
1473
+ return method.code === PaymentMethodType.Eftpos;
1474
+ }) || null);
1475
+ case 7:
1476
+ _context19.prev = 7;
1477
+ _context19.t0 = _context19["catch"](0);
1478
+ console.error('[PaymentModule] 获取Eftpos支付方式失败', _context19.t0);
1479
+ return _context19.abrupt("return", null);
1480
+ case 11:
1481
+ case "end":
1482
+ return _context19.stop();
1483
+ }
1484
+ }, _callee19, this, [[0, 7]]);
1485
+ }));
1486
+ function getEftposPaymentMethod() {
1487
+ return _getEftposPaymentMethod.apply(this, arguments);
1488
+ }
1489
+ return getEftposPaymentMethod;
1490
+ }()
1491
+ /**
1492
+ * 获取钱包支付方式
1493
+ */
1494
+ )
1495
+ }, {
1496
+ key: "getWalletPaymentMethod",
1497
+ value: (function () {
1498
+ var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1499
+ var payMethods;
1500
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1501
+ while (1) switch (_context20.prev = _context20.next) {
1502
+ case 0:
1503
+ _context20.prev = 0;
1504
+ _context20.next = 3;
1505
+ return this.dbManager.getAll('pay_method');
1506
+ case 3:
1507
+ payMethods = _context20.sent;
1508
+ return _context20.abrupt("return", payMethods.find(function (method) {
1509
+ return method.code === PaymentMethodType.Wallet;
1510
+ }) || null);
1511
+ case 7:
1512
+ _context20.prev = 7;
1513
+ _context20.t0 = _context20["catch"](0);
1514
+ console.error('[PaymentModule] 获取钱包支付方式失败', _context20.t0);
1515
+ return _context20.abrupt("return", null);
1516
+ case 11:
1517
+ case "end":
1518
+ return _context20.stop();
1519
+ }
1520
+ }, _callee20, this, [[0, 7]]);
1521
+ }));
1522
+ function getWalletPaymentMethod() {
1523
+ return _getWalletPaymentMethod.apply(this, arguments);
1524
+ }
1525
+ return getWalletPaymentMethod;
1526
+ }()
1527
+ /**
1528
+ * 注册任务处理函数
1529
+ */
1530
+ )
1531
+ }, {
1532
+ key: "registerTaskHandlers",
1533
+ value: function registerTaskHandlers() {
1534
+ if (this.app.tasksManager) {
1535
+ // 注册支付同步任务处理函数
1536
+ this.app.tasksManager.addTaskFunction('syncPayment', PaymentModule.syncPaymentTask);
1537
+ console.log('[PaymentModule] 任务处理函数已注册');
1538
+ } else {
1539
+ console.warn('[PaymentModule] TasksManager 未初始化,无法注册任务处理函数');
1540
+ }
1541
+ }
1542
+
1543
+ /**
1544
+ * 静态方法:处理支付同步任务(后台网络同步)
1545
+ * 这个方法里不允许用 this,因为需要作为静态方法注入到任务队列里
1546
+ */
1547
+ }, {
1548
+ key: "ensurePaymentTables",
1549
+ value: (
1550
+ /**
1551
+ * 确保支付模块所需的数据库表已创建
1552
+ */
1553
+ function () {
1554
+ var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1555
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1556
+ while (1) switch (_context21.prev = _context21.next) {
1557
+ case 0:
1558
+ _context21.prev = 0;
1559
+ _context21.next = 3;
1560
+ return this.dbManager.getAll('pay_method');
1561
+ case 3:
1562
+ _context21.next = 9;
1563
+ break;
1564
+ case 5:
1565
+ _context21.prev = 5;
1566
+ _context21.t0 = _context21["catch"](0);
1567
+ console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
1568
+ console.warn('{ name: "pay_method", keyPath: "id" }');
1569
+ case 9:
1570
+ _context21.prev = 9;
1571
+ _context21.next = 12;
1572
+ return this.dbManager.getAll('order');
1573
+ case 12:
1574
+ _context21.next = 18;
1575
+ break;
1576
+ case 14:
1577
+ _context21.prev = 14;
1578
+ _context21.t1 = _context21["catch"](9);
1579
+ console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
1580
+ console.warn('{ name: "order", keyPath: "uuid" }');
1581
+ case 18:
1582
+ case "end":
1583
+ return _context21.stop();
202
1584
  }
203
- }, _callee6, this);
1585
+ }, _callee21, this, [[0, 5], [9, 14]]);
204
1586
  }));
205
- function checkPaymentStatus(_x6) {
206
- return _checkPaymentStatus.apply(this, arguments);
1587
+ function ensurePaymentTables() {
1588
+ return _ensurePaymentTables.apply(this, arguments);
207
1589
  }
208
- return checkPaymentStatus;
1590
+ return ensurePaymentTables;
209
1591
  }()
1592
+ /**
1593
+ * 获取部分支付的订单
1594
+ */
1595
+ )
1596
+ }, {
1597
+ key: "getPartiallyPaidOrdersAsync",
1598
+ value: (function () {
1599
+ var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1600
+ var allOrders;
1601
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1602
+ while (1) switch (_context22.prev = _context22.next) {
1603
+ case 0:
1604
+ _context22.prev = 0;
1605
+ _context22.next = 3;
1606
+ return this.dbManager.getAll('order');
1607
+ case 3:
1608
+ allOrders = _context22.sent;
1609
+ return _context22.abrupt("return", allOrders.filter(function (order) {
1610
+ return order.payment_status === PaymentStatus.PartiallyPaid;
1611
+ }));
1612
+ case 7:
1613
+ _context22.prev = 7;
1614
+ _context22.t0 = _context22["catch"](0);
1615
+ console.error('[PaymentModule] 获取部分支付订单失败', _context22.t0);
1616
+ return _context22.abrupt("return", []);
1617
+ case 11:
1618
+ case "end":
1619
+ return _context22.stop();
1620
+ }
1621
+ }, _callee22, this, [[0, 7]]);
1622
+ }));
1623
+ function getPartiallyPaidOrdersAsync() {
1624
+ return _getPartiallyPaidOrdersAsync.apply(this, arguments);
1625
+ }
1626
+ return getPartiallyPaidOrdersAsync;
1627
+ }()
1628
+ /**
1629
+ * 获取未同步到服务器的订单
1630
+ */
1631
+ )
1632
+ }, {
1633
+ key: "getUnsyncedOrdersAsync",
1634
+ value: (function () {
1635
+ var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1636
+ var allOrders;
1637
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1638
+ while (1) switch (_context23.prev = _context23.next) {
1639
+ case 0:
1640
+ _context23.prev = 0;
1641
+ _context23.next = 3;
1642
+ return this.dbManager.getAll('order');
1643
+ case 3:
1644
+ allOrders = _context23.sent;
1645
+ return _context23.abrupt("return", allOrders.filter(function (order) {
1646
+ // 订单已完成或部分支付,但支付项还未同步
1647
+ return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
1648
+ return !payment.isSynced;
1649
+ });
1650
+ }));
1651
+ case 7:
1652
+ _context23.prev = 7;
1653
+ _context23.t0 = _context23["catch"](0);
1654
+ console.error('[PaymentModule] 获取未同步订单失败', _context23.t0);
1655
+ return _context23.abrupt("return", []);
1656
+ case 11:
1657
+ case "end":
1658
+ return _context23.stop();
1659
+ }
1660
+ }, _callee23, this, [[0, 7]]);
1661
+ }));
1662
+ function getUnsyncedOrdersAsync() {
1663
+ return _getUnsyncedOrdersAsync.apply(this, arguments);
1664
+ }
1665
+ return getUnsyncedOrdersAsync;
1666
+ }()
1667
+ /**
1668
+ * 清理已完成且已同步的订单
1669
+ * 注意:只清理完全支付的订单,部分支付的订单保留以便继续支付
1670
+ */
1671
+ )
1672
+ }, {
1673
+ key: "cleanupFinishedOrders",
1674
+ value: (function () {
1675
+ var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1676
+ var allOrders, finishedAndSyncedOrders, _iterator6, _step6, order;
1677
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1678
+ while (1) switch (_context24.prev = _context24.next) {
1679
+ case 0:
1680
+ _context24.prev = 0;
1681
+ _context24.next = 3;
1682
+ return this.dbManager.getAll('order');
1683
+ case 3:
1684
+ allOrders = _context24.sent;
1685
+ finishedAndSyncedOrders = allOrders.filter(function (order) {
1686
+ return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
1687
+ return payment.isSynced;
1688
+ });
1689
+ });
1690
+ _iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
1691
+ _context24.prev = 6;
1692
+ _iterator6.s();
1693
+ case 8:
1694
+ if ((_step6 = _iterator6.n()).done) {
1695
+ _context24.next = 14;
1696
+ break;
1697
+ }
1698
+ order = _step6.value;
1699
+ _context24.next = 12;
1700
+ return this.deleteOrderAsync(order.uuid);
1701
+ case 12:
1702
+ _context24.next = 8;
1703
+ break;
1704
+ case 14:
1705
+ _context24.next = 19;
1706
+ break;
1707
+ case 16:
1708
+ _context24.prev = 16;
1709
+ _context24.t0 = _context24["catch"](6);
1710
+ _iterator6.e(_context24.t0);
1711
+ case 19:
1712
+ _context24.prev = 19;
1713
+ _iterator6.f();
1714
+ return _context24.finish(19);
1715
+ case 22:
1716
+ console.log("[PaymentModule] \u6E05\u7406\u4E86 ".concat(finishedAndSyncedOrders.length, " \u4E2A\u5DF2\u5B8C\u6210\u4E14\u5DF2\u540C\u6B65\u7684\u8BA2\u5355"));
1717
+ _context24.next = 28;
1718
+ break;
1719
+ case 25:
1720
+ _context24.prev = 25;
1721
+ _context24.t1 = _context24["catch"](0);
1722
+ console.error('[PaymentModule] 清理已完成订单失败', _context24.t1);
1723
+ case 28:
1724
+ case "end":
1725
+ return _context24.stop();
1726
+ }
1727
+ }, _callee24, this, [[0, 25], [6, 16, 19, 22]]);
1728
+ }));
1729
+ function cleanupFinishedOrders() {
1730
+ return _cleanupFinishedOrders.apply(this, arguments);
1731
+ }
1732
+ return cleanupFinishedOrders;
1733
+ }()
1734
+ /**
1735
+ * 手动执行支付同步队列
1736
+ * 外部可以调用此方法来触发支付同步任务的执行
1737
+ */
1738
+ )
1739
+ }, {
1740
+ key: "runPaymentSyncQueue",
1741
+ value: (function () {
1742
+ var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1743
+ var _this3 = this;
1744
+ var _queue$tasks, queue;
1745
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1746
+ while (1) switch (_context25.prev = _context25.next) {
1747
+ case 0:
1748
+ this.logInfo('Starting runPaymentSyncQueue');
1749
+ _context25.prev = 1;
1750
+ if (this.app.tasksManager) {
1751
+ _context25.next = 6;
1752
+ break;
1753
+ }
1754
+ console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
1755
+ this.logWarning('TasksManager not initialized, cannot run sync queue');
1756
+ return _context25.abrupt("return");
1757
+ case 6:
1758
+ // 检查队列里有没有要跑的东西,没有就不 run 了
1759
+ queue = this.app.tasksManager.getTaskQueue({
1760
+ module: 'payment',
1761
+ queueId: 'payment_sync'
1762
+ });
1763
+ if (queue !== null && queue !== void 0 && (_queue$tasks = queue.tasks) !== null && _queue$tasks !== void 0 && _queue$tasks.length) {
1764
+ _context25.next = 10;
1765
+ break;
1766
+ }
1767
+ console.log('[PaymentModule] 支付同步队列无内容,不执行');
1768
+ return _context25.abrupt("return");
1769
+ case 10:
1770
+ console.log('[PaymentModule] 开始执行支付同步队列');
1771
+ _context25.next = 13;
1772
+ return this.app.tasksManager.run({
1773
+ module: 'payment',
1774
+ queueId: 'payment_sync',
1775
+ callback: function callback() {
1776
+ console.log('[PaymentModule] 支付同步队列执行完成');
1777
+ if (_this3.logger) {
1778
+ _this3.logger.addLog({
1779
+ type: 'info',
1780
+ title: '[PaymentModule] Payment sync queue completed',
1781
+ metadata: {}
1782
+ });
1783
+ }
1784
+ }
1785
+ });
1786
+ case 13:
1787
+ this.logInfo('runPaymentSyncQueue completed successfully');
1788
+ _context25.next = 20;
1789
+ break;
1790
+ case 16:
1791
+ _context25.prev = 16;
1792
+ _context25.t0 = _context25["catch"](1);
1793
+ console.error('[PaymentModule] 执行支付同步队列失败', _context25.t0);
1794
+ this.logError('runPaymentSyncQueue failed', _context25.t0);
1795
+ // 不抛出错误,避免影响主流程
1796
+ case 20:
1797
+ case "end":
1798
+ return _context25.stop();
1799
+ }
1800
+ }, _callee25, this, [[1, 16]]);
1801
+ }));
1802
+ function runPaymentSyncQueue() {
1803
+ return _runPaymentSyncQueue.apply(this, arguments);
1804
+ }
1805
+ return runPaymentSyncQueue;
1806
+ }())
1807
+ }], [{
1808
+ key: "syncPaymentTask",
1809
+ value: (function () {
1810
+ var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(payload) {
1811
+ var _payload$task$payload, orderUuid, orderId, paymentData, core, app, logger, request, dbManager, requestRes, order, businessError, _error$message, _error$message2, _error$message3, isNetworkError, _error$response3, _error$response, errorData, _error$response2, _order2;
1812
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1813
+ while (1) switch (_context26.prev = _context26.next) {
1814
+ case 0:
1815
+ _payload$task$payload = payload.task.payload, orderUuid = _payload$task$payload.orderUuid, orderId = _payload$task$payload.orderId, paymentData = _payload$task$payload.paymentData, core = _payload$task$payload.core;
1816
+ console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
1817
+
1818
+ // 生成request_unique: 年月日时分秒毫秒+4位随机数
1819
+ paymentData.request_unique = generateRequestUniqueId();
1820
+
1821
+ // 从全局获取必要的实例
1822
+ app = window.app;
1823
+ logger = app === null || app === void 0 ? void 0 : app.logger; // 记录开始日志
1824
+ if (logger) {
1825
+ logger.addLog({
1826
+ type: 'info',
1827
+ title: '[PaymentModule] Starting syncPaymentTask',
1828
+ metadata: {
1829
+ orderUuid: orderUuid,
1830
+ orderId: orderId,
1831
+ paymentDataKeys: Object.keys(paymentData)
1832
+ }
1833
+ });
1834
+ }
1835
+ if (app) {
1836
+ _context26.next = 8;
1837
+ break;
1838
+ }
1839
+ throw new Error('App 实例未找到');
1840
+ case 8:
1841
+ request = app.request;
1842
+ if (request) {
1843
+ _context26.next = 11;
1844
+ break;
1845
+ }
1846
+ throw new Error('Request 插件未找到');
1847
+ case 11:
1848
+ dbManager = app.dbManager;
1849
+ if (dbManager) {
1850
+ _context26.next = 14;
1851
+ break;
1852
+ }
1853
+ throw new Error('DBManager 未找到');
1854
+ case 14:
1855
+ _context26.prev = 14;
1856
+ _context26.next = 17;
1857
+ return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
1858
+ noToast: true
1859
+ });
1860
+ case 17:
1861
+ requestRes = _context26.sent;
1862
+ if (!(requestRes.status === true)) {
1863
+ _context26.next = 35;
1864
+ break;
1865
+ }
1866
+ _context26.next = 21;
1867
+ return dbManager.get('order', orderUuid);
1868
+ case 21:
1869
+ order = _context26.sent;
1870
+ if (!order) {
1871
+ _context26.next = 27;
1872
+ break;
1873
+ }
1874
+ order.payment.forEach(function (payment) {
1875
+ payment.isSynced = true;
1876
+ // 清除之前的错误状态
1877
+ delete payment.syncError;
1878
+ });
1879
+ _context26.next = 26;
1880
+ return dbManager.update('order', order);
1881
+ case 26:
1882
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
1883
+ case 27:
1884
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
1885
+ _context26.next = 30;
1886
+ return core.effects.emit('payment:onPaymentSyncSuccess', {
1887
+ orderUuid: orderUuid,
1888
+ orderId: orderId,
1889
+ timestamp: Date.now()
1890
+ });
1891
+ case 30:
1892
+ console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u6210\u529F"));
1893
+
1894
+ // 记录成功日志
1895
+ if (logger) {
1896
+ logger.addLog({
1897
+ type: 'info',
1898
+ title: '[PaymentModule] syncPaymentTask completed successfully',
1899
+ metadata: {
1900
+ orderUuid: orderUuid,
1901
+ orderId: orderId
1902
+ }
1903
+ });
1904
+ }
1905
+ return _context26.abrupt("return", {
1906
+ status: 'success',
1907
+ orderUuid: orderUuid,
1908
+ orderId: orderId
1909
+ });
1910
+ case 35:
1911
+ // 接口返回失败,视为业务错误处理
1912
+ console.log("[PaymentModule] \u63A5\u53E3\u8FD4\u56DE\u5931\u8D25\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25"));
1913
+
1914
+ // 模拟业务错误,抛出一个包含响应信息的错误
1915
+ businessError = new Error(requestRes.message || '接口返回失败');
1916
+ businessError.response = {
1917
+ status: 200
1918
+ }; // HTTP 状态码是 200,但业务失败
1919
+ businessError.isBusinessError = true;
1920
+ businessError.responseData = requestRes;
1921
+ throw businessError;
1922
+ case 41:
1923
+ _context26.next = 80;
1924
+ break;
1925
+ case 43:
1926
+ _context26.prev = 43;
1927
+ _context26.t0 = _context26["catch"](14);
1928
+ console.error('[PaymentModule] 后台同步失败:', _context26.t0);
1929
+
1930
+ // 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
1931
+ isNetworkError = !_context26.t0.response && !_context26.t0.status && (_context26.t0.code === 'NETWORK_ERROR' || _context26.t0.code === 'ERR_NETWORK' || _context26.t0.code === 'ECONNREFUSED' || _context26.t0.code === 'ENOTFOUND' || _context26.t0.code === 'ETIMEDOUT' || ((_error$message = _context26.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context26.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context26.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
1932
+ if (!isNetworkError) {
1933
+ _context26.next = 53;
1934
+ break;
1935
+ }
1936
+ // 网络错误:重试
1937
+ console.log("[PaymentModule] \u7F51\u7EDC\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u5C06\u91CD\u8BD5\u540C\u6B65"));
1938
+
1939
+ // 记录网络错误日志
1940
+ if (logger) {
1941
+ logger.addLog({
1942
+ type: 'warning',
1943
+ title: '[PaymentModule] syncPaymentTask network error - will retry',
1944
+ metadata: {
1945
+ orderUuid: orderUuid,
1946
+ orderId: orderId,
1947
+ errorCode: _context26.t0.code,
1948
+ errorMessage: _context26.t0.message
1949
+ }
1950
+ });
1951
+ }
1952
+ throw _context26.t0;
1953
+ case 53:
1954
+ // 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
1955
+ console.log("[PaymentModule] \u4E1A\u52A1\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25\uFF0C\u901A\u77E5\u524D\u7AEF"));
1956
+ _context26.prev = 54;
1957
+ if (!(core && core.effects)) {
1958
+ _context26.next = 63;
1959
+ break;
1960
+ }
1961
+ // 通过 effects 通知前端同步错误
1962
+ errorData = {
1963
+ orderUuid: orderUuid,
1964
+ orderId: orderId,
1965
+ error: _context26.t0.message || '业务错误',
1966
+ errorCode: _context26.t0.code,
1967
+ statusCode: ((_error$response = _context26.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context26.t0.status,
1968
+ timestamp: Date.now()
1969
+ }; // 如果是业务错误,添加响应数据
1970
+ if (_context26.t0.isBusinessError && _context26.t0.responseData) {
1971
+ errorData.error = _context26.t0.responseData.message || _context26.t0.message || '接口返回失败';
1972
+ // 可以添加更多响应数据
1973
+ errorData.responseData = _context26.t0.responseData;
1974
+ }
1975
+ _context26.next = 60;
1976
+ return core.effects.emit('payment:onPaymentSyncError', errorData);
1977
+ case 60:
1978
+ console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
1979
+ _context26.next = 64;
1980
+ break;
1981
+ case 63:
1982
+ console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
1983
+ case 64:
1984
+ // 记录业务错误日志
1985
+ if (logger) {
1986
+ logger.addLog({
1987
+ type: 'error',
1988
+ title: '[PaymentModule] syncPaymentTask business error',
1989
+ metadata: {
1990
+ orderUuid: orderUuid,
1991
+ orderId: orderId,
1992
+ errorCode: _context26.t0.code,
1993
+ errorMessage: _context26.t0.message,
1994
+ statusCode: ((_error$response2 = _context26.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context26.t0.status,
1995
+ isBusinessError: _context26.t0.isBusinessError
1996
+ }
1997
+ });
1998
+ }
1999
+ _context26.next = 71;
2000
+ break;
2001
+ case 67:
2002
+ _context26.prev = 67;
2003
+ _context26.t1 = _context26["catch"](54);
2004
+ console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context26.t1);
2005
+
2006
+ // 记录通知错误日志
2007
+ if (logger) {
2008
+ logger.addLog({
2009
+ type: 'error',
2010
+ title: '[PaymentModule] Failed to notify frontend of sync error',
2011
+ metadata: {
2012
+ orderUuid: orderUuid,
2013
+ orderId: orderId,
2014
+ notifyError: _context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1)
2015
+ }
2016
+ });
2017
+ }
2018
+ case 71:
2019
+ _context26.next = 73;
2020
+ return dbManager.get('order', orderUuid);
2021
+ case 73:
2022
+ _order2 = _context26.sent;
2023
+ if (!_order2) {
2024
+ _context26.next = 79;
2025
+ break;
2026
+ }
2027
+ _order2.payment.forEach(function (payment) {
2028
+ payment.isSynced = true;
2029
+ });
2030
+ _context26.next = 78;
2031
+ return dbManager.update('order', _order2);
2032
+ case 78:
2033
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
2034
+ case 79:
2035
+ return _context26.abrupt("return", {
2036
+ status: 'completed_with_error',
2037
+ orderUuid: orderUuid,
2038
+ orderId: orderId,
2039
+ error: _context26.t0.message || '业务错误',
2040
+ statusCode: ((_error$response3 = _context26.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context26.t0.status
2041
+ });
2042
+ case 80:
2043
+ case "end":
2044
+ return _context26.stop();
2045
+ }
2046
+ }, _callee26, null, [[14, 43], [54, 67]]);
2047
+ }));
2048
+ function syncPaymentTask(_x24) {
2049
+ return _syncPaymentTask.apply(this, arguments);
2050
+ }
2051
+ return syncPaymentTask;
2052
+ }())
210
2053
  }]);
211
2054
  return PaymentModule;
212
2055
  }(BaseModule);