@pisell/pisellos 3.0.55 → 3.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/dist/core/index.js +2 -1
  2. package/dist/effects/index.d.ts +4 -3
  3. package/dist/effects/index.js +15 -6
  4. package/dist/modules/AccountList/index.d.ts +7 -1
  5. package/dist/modules/AccountList/index.js +81 -14
  6. package/dist/modules/AccountList/types.d.ts +28 -0
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/Cart/index.js +1 -1
  9. package/dist/modules/Cart/utils/changePrice.d.ts +2 -2
  10. package/dist/modules/Cart/utils/changePrice.js +1 -1
  11. package/dist/modules/Customer/constants.d.ts +7 -0
  12. package/dist/modules/Customer/constants.js +12 -0
  13. package/dist/modules/Customer/index.d.ts +122 -0
  14. package/dist/modules/Customer/index.js +697 -0
  15. package/dist/modules/Customer/types.d.ts +146 -0
  16. package/dist/modules/Customer/types.js +41 -0
  17. package/dist/modules/Payment/cash.d.ts +11 -0
  18. package/dist/modules/Payment/cash.js +78 -0
  19. package/dist/modules/Payment/eftpos.d.ts +11 -0
  20. package/dist/modules/Payment/eftpos.js +80 -0
  21. package/dist/modules/Payment/index.d.ts +273 -9
  22. package/dist/modules/Payment/index.js +2525 -109
  23. package/dist/modules/Payment/types.d.ts +382 -30
  24. package/dist/modules/Payment/types.js +116 -14
  25. package/dist/modules/Payment/wallet.d.ts +11 -0
  26. package/dist/modules/Payment/wallet.js +78 -0
  27. package/dist/modules/Payment/walletpass.d.ts +0 -0
  28. package/dist/modules/Payment/walletpass.js +0 -0
  29. package/dist/modules/ProductList/index.d.ts +14 -3
  30. package/dist/modules/ProductList/index.js +58 -44
  31. package/dist/modules/ProductList/types.d.ts +0 -1
  32. package/dist/modules/Rules/index.js +27 -14
  33. package/dist/modules/Rules/types.d.ts +1 -0
  34. package/dist/modules/index.d.ts +1 -0
  35. package/dist/modules/index.js +1 -0
  36. package/dist/plugins/app-types/app/app.d.ts +83 -0
  37. package/dist/plugins/app-types/app/const.d.ts +4 -0
  38. package/dist/plugins/app-types/app/index.d.ts +14 -0
  39. package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
  40. package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
  41. package/dist/plugins/app-types/config.d.ts +3 -0
  42. package/dist/plugins/app-types/cookie/index.d.ts +13 -0
  43. package/dist/plugins/app-types/data/index.d.ts +8 -0
  44. package/dist/plugins/app-types/history/config.d.ts +24 -0
  45. package/dist/plugins/app-types/history/index.d.ts +20 -0
  46. package/dist/plugins/app-types/history/type.d.ts +2 -0
  47. package/dist/plugins/app-types/hooks/index.d.ts +12 -0
  48. package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  49. package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  50. package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  51. package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  52. package/dist/plugins/app-types/index.d.ts +6 -0
  53. package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
  54. package/dist/plugins/app-types/locales/en.d.ts +3 -0
  55. package/dist/plugins/app-types/locales/index.d.ts +37 -0
  56. package/dist/plugins/app-types/locales/original.d.ts +3 -0
  57. package/dist/plugins/app-types/locales/type.d.ts +19 -0
  58. package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
  59. package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
  60. package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
  61. package/dist/plugins/app-types/logger/index.d.ts +122 -0
  62. package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
  63. package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
  64. package/dist/plugins/app-types/models/global.d.ts +32 -0
  65. package/dist/plugins/app-types/models/index.d.ts +45 -0
  66. package/dist/plugins/app-types/models/type.d.ts +2 -0
  67. package/dist/plugins/app-types/package.json +15 -0
  68. package/dist/plugins/app-types/plugin/index.d.ts +0 -0
  69. package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
  70. package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
  71. package/dist/plugins/app-types/request/cache.d.ts +46 -0
  72. package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
  73. package/dist/plugins/app-types/request/config.d.ts +3 -0
  74. package/dist/plugins/app-types/request/constants.d.ts +2 -0
  75. package/dist/plugins/app-types/request/index.d.ts +24 -0
  76. package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
  77. package/dist/plugins/app-types/request/type.d.ts +41 -0
  78. package/dist/plugins/app-types/request/utils.d.ts +46 -0
  79. package/dist/plugins/app-types/routes/config.d.ts +7 -0
  80. package/dist/plugins/app-types/routes/index.d.ts +28 -0
  81. package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  82. package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
  83. package/dist/plugins/app-types/socket/constants.d.ts +33 -0
  84. package/dist/plugins/app-types/socket/events.d.ts +31 -0
  85. package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
  86. package/dist/plugins/app-types/socket/index.d.ts +61 -0
  87. package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
  88. package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
  89. package/dist/plugins/app-types/socket/socket.d.ts +129 -0
  90. package/dist/plugins/app-types/socket/types.d.ts +85 -0
  91. package/dist/plugins/app-types/storage/index.d.ts +17 -0
  92. package/dist/plugins/app-types/tasks/index.d.ts +77 -0
  93. package/dist/plugins/app-types/tasks/type.d.ts +62 -0
  94. package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
  95. package/dist/plugins/app-types/type.d.ts +2 -0
  96. package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  97. package/dist/plugins/app-types/variables/config.d.ts +3 -0
  98. package/dist/plugins/app-types/variables/index.d.ts +6 -0
  99. package/dist/plugins/app-types/variables/type.d.ts +2 -0
  100. package/dist/plugins/app-types/website/index.d.ts +6 -0
  101. package/dist/plugins/app.d.ts +8 -0
  102. package/dist/plugins/app.js +1 -0
  103. package/dist/plugins/window.d.ts +1 -0
  104. package/dist/solution/BookingByStep/index.js +59 -35
  105. package/dist/solution/BookingByStep/types.d.ts +3 -2
  106. package/dist/solution/BookingTicket/index.d.ts +172 -0
  107. package/dist/solution/BookingTicket/index.js +665 -0
  108. package/dist/solution/BookingTicket/types.d.ts +68 -0
  109. package/dist/solution/BookingTicket/types.js +43 -0
  110. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  111. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
  112. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +16 -0
  113. package/dist/solution/BookingTicket/utils/scan/handleScan.js +174 -0
  114. package/dist/solution/BookingTicket/utils/scan/index.d.ts +81 -0
  115. package/dist/solution/BookingTicket/utils/scan/index.js +285 -0
  116. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  117. package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
  118. package/dist/solution/BuyTickets/index.d.ts +2 -2
  119. package/dist/solution/BuyTickets/index.js +1 -1
  120. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  121. package/dist/solution/Checkout/index.d.ts +181 -0
  122. package/dist/solution/Checkout/index.js +1596 -0
  123. package/dist/solution/Checkout/types.d.ts +550 -0
  124. package/dist/solution/Checkout/types.js +132 -0
  125. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  126. package/dist/solution/Checkout/utils/index.js +371 -0
  127. package/dist/solution/ShopDiscount/index.js +4 -2
  128. package/dist/solution/index.d.ts +2 -0
  129. package/dist/solution/index.js +3 -1
  130. package/dist/types/index.d.ts +3 -1
  131. package/dist/utils/task.d.ts +40 -0
  132. package/dist/utils/task.js +171 -0
  133. package/dist/utils/watch.d.ts +102 -0
  134. package/dist/utils/watch.js +294 -0
  135. package/lib/core/index.js +1 -1
  136. package/lib/effects/index.d.ts +4 -3
  137. package/lib/effects/index.js +4 -1
  138. package/lib/modules/AccountList/index.d.ts +7 -1
  139. package/lib/modules/AccountList/index.js +27 -0
  140. package/lib/modules/AccountList/types.d.ts +28 -0
  141. package/lib/modules/Cart/index.js +1 -1
  142. package/lib/modules/Cart/utils/changePrice.d.ts +2 -2
  143. package/lib/modules/Cart/utils/changePrice.js +1 -1
  144. package/lib/modules/Customer/constants.d.ts +7 -0
  145. package/lib/modules/Customer/constants.js +39 -0
  146. package/lib/modules/Customer/index.d.ts +122 -0
  147. package/lib/modules/Customer/index.js +440 -0
  148. package/lib/modules/Customer/types.d.ts +146 -0
  149. package/lib/modules/Customer/types.js +37 -0
  150. package/lib/modules/Payment/cash.d.ts +11 -0
  151. package/lib/modules/Payment/cash.js +51 -0
  152. package/lib/modules/Payment/eftpos.d.ts +11 -0
  153. package/lib/modules/Payment/eftpos.js +51 -0
  154. package/lib/modules/Payment/index.d.ts +273 -9
  155. package/lib/modules/Payment/index.js +1285 -50
  156. package/lib/modules/Payment/types.d.ts +382 -30
  157. package/lib/modules/Payment/types.js +41 -6
  158. package/lib/modules/Payment/wallet.d.ts +11 -0
  159. package/lib/modules/Payment/wallet.js +51 -0
  160. package/lib/modules/Payment/walletpass.d.ts +0 -0
  161. package/lib/modules/Payment/walletpass.js +0 -0
  162. package/lib/modules/ProductList/index.d.ts +14 -3
  163. package/lib/modules/ProductList/index.js +42 -28
  164. package/lib/modules/ProductList/types.d.ts +0 -1
  165. package/lib/modules/Rules/index.js +20 -12
  166. package/lib/modules/Rules/types.d.ts +1 -0
  167. package/lib/modules/index.d.ts +1 -0
  168. package/lib/modules/index.js +2 -0
  169. package/lib/plugins/app-types/app/app.d.ts +83 -0
  170. package/lib/plugins/app-types/app/const.d.ts +4 -0
  171. package/lib/plugins/app-types/app/index.d.ts +14 -0
  172. package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
  173. package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
  174. package/lib/plugins/app-types/config.d.ts +3 -0
  175. package/lib/plugins/app-types/cookie/index.d.ts +13 -0
  176. package/lib/plugins/app-types/data/index.d.ts +8 -0
  177. package/lib/plugins/app-types/history/config.d.ts +24 -0
  178. package/lib/plugins/app-types/history/index.d.ts +20 -0
  179. package/lib/plugins/app-types/history/type.d.ts +2 -0
  180. package/lib/plugins/app-types/hooks/index.d.ts +12 -0
  181. package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  182. package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  183. package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  184. package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  185. package/lib/plugins/app-types/index.d.ts +6 -0
  186. package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
  187. package/lib/plugins/app-types/locales/en.d.ts +3 -0
  188. package/lib/plugins/app-types/locales/index.d.ts +37 -0
  189. package/lib/plugins/app-types/locales/original.d.ts +3 -0
  190. package/lib/plugins/app-types/locales/type.d.ts +19 -0
  191. package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
  192. package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
  193. package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
  194. package/lib/plugins/app-types/logger/index.d.ts +122 -0
  195. package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
  196. package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
  197. package/lib/plugins/app-types/models/global.d.ts +32 -0
  198. package/lib/plugins/app-types/models/index.d.ts +45 -0
  199. package/lib/plugins/app-types/models/type.d.ts +2 -0
  200. package/lib/plugins/app-types/package.json +15 -0
  201. package/lib/plugins/app-types/plugin/index.d.ts +0 -0
  202. package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
  203. package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
  204. package/lib/plugins/app-types/request/cache.d.ts +46 -0
  205. package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
  206. package/lib/plugins/app-types/request/config.d.ts +3 -0
  207. package/lib/plugins/app-types/request/constants.d.ts +2 -0
  208. package/lib/plugins/app-types/request/index.d.ts +24 -0
  209. package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
  210. package/lib/plugins/app-types/request/type.d.ts +41 -0
  211. package/lib/plugins/app-types/request/utils.d.ts +46 -0
  212. package/lib/plugins/app-types/routes/config.d.ts +7 -0
  213. package/lib/plugins/app-types/routes/index.d.ts +28 -0
  214. package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  215. package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
  216. package/lib/plugins/app-types/socket/constants.d.ts +33 -0
  217. package/lib/plugins/app-types/socket/events.d.ts +31 -0
  218. package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
  219. package/lib/plugins/app-types/socket/index.d.ts +61 -0
  220. package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
  221. package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
  222. package/lib/plugins/app-types/socket/socket.d.ts +129 -0
  223. package/lib/plugins/app-types/socket/types.d.ts +85 -0
  224. package/lib/plugins/app-types/storage/index.d.ts +17 -0
  225. package/lib/plugins/app-types/tasks/index.d.ts +77 -0
  226. package/lib/plugins/app-types/tasks/type.d.ts +62 -0
  227. package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
  228. package/lib/plugins/app-types/type.d.ts +2 -0
  229. package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  230. package/lib/plugins/app-types/variables/config.d.ts +3 -0
  231. package/lib/plugins/app-types/variables/index.d.ts +6 -0
  232. package/lib/plugins/app-types/variables/type.d.ts +2 -0
  233. package/lib/plugins/app-types/website/index.d.ts +6 -0
  234. package/lib/plugins/app.d.ts +8 -0
  235. package/lib/plugins/app.js +17 -0
  236. package/lib/plugins/window.d.ts +1 -0
  237. package/lib/solution/BookingByStep/index.js +40 -29
  238. package/lib/solution/BookingByStep/types.d.ts +3 -2
  239. package/lib/solution/BookingTicket/index.d.ts +172 -0
  240. package/lib/solution/BookingTicket/index.js +399 -0
  241. package/lib/solution/BookingTicket/types.d.ts +68 -0
  242. package/lib/solution/BookingTicket/types.js +72 -0
  243. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  244. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
  245. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +16 -0
  246. package/lib/solution/BookingTicket/utils/scan/handleScan.js +125 -0
  247. package/lib/solution/BookingTicket/utils/scan/index.d.ts +81 -0
  248. package/lib/solution/BookingTicket/utils/scan/index.js +210 -0
  249. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  250. package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
  251. package/lib/solution/BuyTickets/index.d.ts +2 -2
  252. package/lib/solution/BuyTickets/index.js +1 -1
  253. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  254. package/lib/solution/Checkout/index.d.ts +181 -0
  255. package/lib/solution/Checkout/index.js +864 -0
  256. package/lib/solution/Checkout/types.d.ts +550 -0
  257. package/lib/solution/Checkout/types.js +75 -0
  258. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  259. package/lib/solution/Checkout/utils/index.js +266 -0
  260. package/lib/solution/ShopDiscount/index.js +2 -1
  261. package/lib/solution/index.d.ts +2 -0
  262. package/lib/solution/index.js +5 -1
  263. package/lib/types/index.d.ts +3 -1
  264. package/lib/utils/task.d.ts +40 -0
  265. package/lib/utils/task.js +109 -0
  266. package/lib/utils/watch.d.ts +102 -0
  267. package/lib/utils/watch.js +217 -0
  268. package/package.json +4 -2
@@ -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,2465 @@ 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;
69
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
70
- while (1) switch (_context2.prev = _context2.next) {
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', /*#__PURE__*/function () {
245
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(status) {
246
+ var requeuedCount;
247
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
248
+ while (1) switch (_context2.prev = _context2.next) {
249
+ case 0:
250
+ console.log('网络状态:', status.connected);
251
+ _this2.logInfo('Network status changed', {
252
+ connected: status.connected,
253
+ previousStatus: status.previousStatus
254
+ });
255
+ if (!status.connected) {
256
+ _context2.next = 10;
257
+ break;
258
+ }
259
+ _this2.logInfo('Network reconnected - triggering payment sync queue');
260
+ // this.runPaymentSyncQueue();
261
+ // 1. 先检查并重新排队未同步订单,然后执行队列
262
+ _context2.next = 6;
263
+ return _this2.recheckAndRequeueUnsyncedOrders();
264
+ case 6:
265
+ requeuedCount = _context2.sent;
266
+ if (!(requeuedCount > 0)) {
267
+ _context2.next = 10;
268
+ break;
269
+ }
270
+ _context2.next = 10;
271
+ return _this2.runPaymentSyncQueue();
272
+ case 10:
273
+ case "end":
274
+ return _context2.stop();
275
+ }
276
+ }, _callee2);
277
+ }));
278
+ return function (_x3) {
279
+ return _ref.apply(this, arguments);
280
+ };
281
+ }());
282
+ }
283
+
284
+ /**
285
+ * 获取支付方式列表
286
+ */
287
+ }, {
288
+ key: "getPayMethodListAsync",
289
+ value: (function () {
290
+ var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
291
+ var cachedMethods, hasCache, response, payMethods, _iterator, _step, method;
292
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
293
+ while (1) switch (_context3.prev = _context3.next) {
71
294
  case 0:
72
- payment = this.state.paymentHistory.find(function (p) {
73
- return p.id === paymentId;
295
+ this.logInfo('Starting getPayMethodListAsync');
296
+ _context3.prev = 1;
297
+ // 先尝试从 IndexDB 获取缓存
298
+ cachedMethods = [];
299
+ _context3.prev = 3;
300
+ _context3.next = 6;
301
+ return this.dbManager.getAll('pay_method');
302
+ case 6:
303
+ cachedMethods = _context3.sent;
304
+ _context3.next = 12;
305
+ break;
306
+ case 9:
307
+ _context3.prev = 9;
308
+ _context3.t0 = _context3["catch"](3);
309
+ console.warn('[PaymentModule] pay_method 表不存在,将从服务器获取数据');
310
+ case 12:
311
+ // 如果有缓存,先返回缓存数据
312
+ hasCache = cachedMethods.length > 0;
313
+ if (!hasCache) {
314
+ _context3.next = 16;
315
+ break;
316
+ }
317
+ // 后台异步获取最新数据
318
+ this.refreshPaymentMethodsInBackground(cachedMethods);
319
+ return _context3.abrupt("return", cachedMethods);
320
+ case 16:
321
+ _context3.next = 18;
322
+ return this.request.get('/pay/custom-payment/available');
323
+ case 18:
324
+ response = _context3.sent;
325
+ payMethods = response.data || []; // 尝试缓存到 IndexDB
326
+ _context3.prev = 20;
327
+ _iterator = _createForOfIteratorHelper(payMethods);
328
+ _context3.prev = 22;
329
+ _iterator.s();
330
+ case 24:
331
+ if ((_step = _iterator.n()).done) {
332
+ _context3.next = 30;
333
+ break;
334
+ }
335
+ method = _step.value;
336
+ _context3.next = 28;
337
+ return this.dbManager.update('pay_method', method);
338
+ case 28:
339
+ _context3.next = 24;
340
+ break;
341
+ case 30:
342
+ _context3.next = 35;
343
+ break;
344
+ case 32:
345
+ _context3.prev = 32;
346
+ _context3.t1 = _context3["catch"](22);
347
+ _iterator.e(_context3.t1);
348
+ case 35:
349
+ _context3.prev = 35;
350
+ _iterator.f();
351
+ return _context3.finish(35);
352
+ case 38:
353
+ _context3.next = 43;
354
+ break;
355
+ case 40:
356
+ _context3.prev = 40;
357
+ _context3.t2 = _context3["catch"](20);
358
+ console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
359
+ case 43:
360
+ _context3.next = 45;
361
+ return this.core.effects.emit(PaymentHooks.OnPaymentMethodsLoaded, payMethods);
362
+ case 45:
363
+ this.logInfo('getPayMethodListAsync completed successfully', {
364
+ methodCount: payMethods.length,
365
+ hasCache: cachedMethods.length > 0
366
+ });
367
+ return _context3.abrupt("return", payMethods);
368
+ case 49:
369
+ _context3.prev = 49;
370
+ _context3.t3 = _context3["catch"](1);
371
+ console.error('[PaymentModule] 获取支付方式列表失败', _context3.t3);
372
+ this.logError('getPayMethodListAsync failed', _context3.t3);
373
+ // 如果所有操作都失败,返回空数组
374
+ return _context3.abrupt("return", []);
375
+ case 54:
376
+ case "end":
377
+ return _context3.stop();
378
+ }
379
+ }, _callee3, this, [[1, 49], [3, 9], [20, 40], [22, 32, 35, 38]]);
380
+ }));
381
+ function getPayMethodListAsync() {
382
+ return _getPayMethodListAsync.apply(this, arguments);
383
+ }
384
+ return getPayMethodListAsync;
385
+ }()
386
+ /**
387
+ * 后台刷新支付方式列表
388
+ */
389
+ )
390
+ }, {
391
+ key: "refreshPaymentMethodsInBackground",
392
+ value: (function () {
393
+ var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cachedMethods) {
394
+ var response, newPayMethods, hasChanges, _iterator2, _step2, method, _iterator3, _step3, _method, eventData;
395
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
396
+ while (1) switch (_context4.prev = _context4.next) {
397
+ case 0:
398
+ this.logInfo('Starting refreshPaymentMethodsInBackground', {
399
+ cachedMethodsCount: cachedMethods.length
400
+ });
401
+ _context4.prev = 1;
402
+ console.log('[PaymentModule] 后台刷新支付方式列表...');
403
+
404
+ // 从服务器获取最新数据
405
+ _context4.next = 5;
406
+ return this.request.get('/pay/custom-payment/available');
407
+ case 5:
408
+ response = _context4.sent;
409
+ newPayMethods = response.data || []; // 检查是否有变化
410
+ hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
411
+ if (!hasChanges) {
412
+ _context4.next = 56;
413
+ break;
414
+ }
415
+ console.log('[PaymentModule] 支付方式列表已更新');
416
+ this.logInfo('Payment methods updated in background', {
417
+ oldCount: cachedMethods.length,
418
+ newCount: newPayMethods.length
74
419
  });
75
- if (payment) {
76
- _context2.next = 3;
420
+
421
+ // 更新缓存
422
+ _context4.prev = 11;
423
+ // 先清除旧数据
424
+ _iterator2 = _createForOfIteratorHelper(cachedMethods);
425
+ _context4.prev = 13;
426
+ _iterator2.s();
427
+ case 15:
428
+ if ((_step2 = _iterator2.n()).done) {
429
+ _context4.next = 21;
430
+ break;
431
+ }
432
+ method = _step2.value;
433
+ _context4.next = 19;
434
+ return this.dbManager.delete('pay_method', method.id);
435
+ case 19:
436
+ _context4.next = 15;
437
+ break;
438
+ case 21:
439
+ _context4.next = 26;
440
+ break;
441
+ case 23:
442
+ _context4.prev = 23;
443
+ _context4.t0 = _context4["catch"](13);
444
+ _iterator2.e(_context4.t0);
445
+ case 26:
446
+ _context4.prev = 26;
447
+ _iterator2.f();
448
+ return _context4.finish(26);
449
+ case 29:
450
+ // 添加新数据
451
+ _iterator3 = _createForOfIteratorHelper(newPayMethods);
452
+ _context4.prev = 30;
453
+ _iterator3.s();
454
+ case 32:
455
+ if ((_step3 = _iterator3.n()).done) {
456
+ _context4.next = 38;
77
457
  break;
78
458
  }
79
- return _context2.abrupt("return");
459
+ _method = _step3.value;
460
+ _context4.next = 36;
461
+ return this.dbManager.update('pay_method', _method);
462
+ case 36:
463
+ _context4.next = 32;
464
+ break;
465
+ case 38:
466
+ _context4.next = 43;
467
+ break;
468
+ case 40:
469
+ _context4.prev = 40;
470
+ _context4.t1 = _context4["catch"](30);
471
+ _iterator3.e(_context4.t1);
472
+ case 43:
473
+ _context4.prev = 43;
474
+ _iterator3.f();
475
+ return _context4.finish(43);
476
+ case 46:
477
+ _context4.next = 51;
478
+ break;
479
+ case 48:
480
+ _context4.prev = 48;
481
+ _context4.t2 = _context4["catch"](11);
482
+ console.warn('[PaymentModule] 无法更新支付方式缓存', _context4.t2);
483
+ case 51:
484
+ // 通知外部支付方式已变化
485
+ eventData = {
486
+ oldMethods: cachedMethods,
487
+ newMethods: newPayMethods
488
+ };
489
+ _context4.next = 54;
490
+ return this.core.effects.emit(PaymentHooks.OnPaymentMethodsChanged, eventData);
491
+ case 54:
492
+ _context4.next = 57;
493
+ break;
494
+ case 56:
495
+ console.log('[PaymentModule] 支付方式列表无变化');
496
+ case 57:
497
+ _context4.next = 62;
498
+ break;
499
+ case 59:
500
+ _context4.prev = 59;
501
+ _context4.t3 = _context4["catch"](1);
502
+ console.error('[PaymentModule] 后台刷新支付方式失败', _context4.t3);
503
+ case 62:
504
+ case "end":
505
+ return _context4.stop();
506
+ }
507
+ }, _callee4, this, [[1, 59], [11, 48], [13, 23, 26, 29], [30, 40, 43, 46]]);
508
+ }));
509
+ function refreshPaymentMethodsInBackground(_x4) {
510
+ return _refreshPaymentMethodsInBackground.apply(this, arguments);
511
+ }
512
+ return refreshPaymentMethodsInBackground;
513
+ }()
514
+ /**
515
+ * 检查支付方式列表是否有变化
516
+ */
517
+ )
518
+ }, {
519
+ key: "hasPaymentMethodsChanged",
520
+ value: function hasPaymentMethodsChanged(oldMethods, newMethods) {
521
+ if (oldMethods.length !== newMethods.length) {
522
+ return true;
523
+ }
524
+
525
+ // 创建旧数据的 Map 便于查找
526
+ var oldMethodsMap = new Map(oldMethods.map(function (method) {
527
+ return [method.id, method];
528
+ }));
529
+
530
+ // 检查每个新方法是否与旧方法相同
531
+ var _iterator4 = _createForOfIteratorHelper(newMethods),
532
+ _step4;
533
+ try {
534
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
535
+ var newMethod = _step4.value;
536
+ var oldMethod = oldMethodsMap.get(newMethod.id);
537
+ if (!oldMethod) {
538
+ return true; // 新增方法
539
+ }
540
+
541
+ // 检查关键字段是否有变化
542
+ if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.enabled !== newMethod.enabled) {
543
+ return true; // 方法属性有变化
544
+ }
545
+ }
546
+ } catch (err) {
547
+ _iterator4.e(err);
548
+ } finally {
549
+ _iterator4.f();
550
+ }
551
+ return false;
552
+ }
553
+
554
+ /**
555
+ * 获取订单列表
556
+ */
557
+ }, {
558
+ key: "getOrderListAsync",
559
+ value: (function () {
560
+ var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
561
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
562
+ while (1) switch (_context5.prev = _context5.next) {
563
+ case 0:
564
+ _context5.prev = 0;
565
+ _context5.next = 3;
566
+ return this.dbManager.getAll('order');
80
567
  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:
568
+ return _context5.abrupt("return", _context5.sent);
569
+ case 6:
570
+ _context5.prev = 6;
571
+ _context5.t0 = _context5["catch"](0);
572
+ console.error('[PaymentModule] 获取订单列表失败', _context5.t0);
573
+ return _context5.abrupt("return", []);
574
+ case 10:
86
575
  case "end":
87
- return _context2.stop();
576
+ return _context5.stop();
88
577
  }
89
- }, _callee2, this);
578
+ }, _callee5, this, [[0, 6]]);
90
579
  }));
91
- function processPayment(_x3) {
92
- return _processPayment.apply(this, arguments);
580
+ function getOrderListAsync() {
581
+ return _getOrderListAsync.apply(this, arguments);
93
582
  }
94
- return processPayment;
583
+ return getOrderListAsync;
95
584
  }()
585
+ /**
586
+ * 根据订单UUID获取支付订单(新方法)
587
+ */
588
+ )
96
589
  }, {
97
- key: "getPayment",
98
- value: function () {
99
- var _getPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(paymentId) {
100
- var payment;
101
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
102
- while (1) switch (_context3.prev = _context3.next) {
590
+ key: "getPaymentOrderByUuidAsync",
591
+ value: (function () {
592
+ var _getPaymentOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
593
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
594
+ while (1) switch (_context6.prev = _context6.next) {
103
595
  case 0:
104
- payment = this.state.paymentHistory.find(function (p) {
105
- return p.id === paymentId;
596
+ _context6.prev = 0;
597
+ _context6.next = 3;
598
+ return this.dbManager.get('order', orderUuid);
599
+ case 3:
600
+ return _context6.abrupt("return", _context6.sent);
601
+ case 6:
602
+ _context6.prev = 6;
603
+ _context6.t0 = _context6["catch"](0);
604
+ console.error('[PaymentModule] 获取支付订单失败', _context6.t0);
605
+ return _context6.abrupt("return", null);
606
+ case 10:
607
+ case "end":
608
+ return _context6.stop();
609
+ }
610
+ }, _callee6, this, [[0, 6]]);
611
+ }));
612
+ function getPaymentOrderByUuidAsync(_x5) {
613
+ return _getPaymentOrderByUuidAsync.apply(this, arguments);
614
+ }
615
+ return getPaymentOrderByUuidAsync;
616
+ }()
617
+ /**
618
+ * 创建支付订单(新方法,专注支付数据)
619
+ */
620
+ )
621
+ }, {
622
+ key: "createPaymentOrderAsync",
623
+ value: (function () {
624
+ var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
625
+ var existingOrders, existingOrder, originalOrder, newOrder;
626
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
627
+ while (1) switch (_context7.prev = _context7.next) {
628
+ case 0:
629
+ this.logInfo('Starting createPaymentOrderAsync', {
630
+ orderId: params.order_id,
631
+ totalAmount: params.total_amount
106
632
  });
107
- if (payment) {
108
- _context3.next = 3;
633
+ _context7.prev = 1;
634
+ _context7.next = 4;
635
+ return this.dbManager.getAll('order');
636
+ case 4:
637
+ existingOrders = _context7.sent;
638
+ existingOrder = existingOrders.find(function (order) {
639
+ return String(order.id) === String(params.order_id);
640
+ });
641
+ if (!existingOrder) {
642
+ _context7.next = 21;
109
643
  break;
110
644
  }
111
- throw new Error('Payment not found');
645
+ // 如果存在相同 order_id 的订单,更新该订单信息
646
+ console.log("[PaymentModule] \u53D1\u73B0\u91CD\u590D\u8BA2\u5355 ID: ".concat(params.order_id, "\uFF0C\u66F4\u65B0\u73B0\u6709\u652F\u4ED8\u8BA2\u5355"));
647
+ originalOrder = _objectSpread({}, existingOrder);
648
+ existingOrder.order_info = params.order_info;
649
+ existingOrder.total_amount = params.total_amount;
650
+ existingOrder.is_deposit = params.is_deposit || 0;
651
+ existingOrder.deposit_amount = params.deposit_amount || '0.00';
652
+
653
+ // 重新计算待付金额
654
+ this.recalculateOrderAmount(existingOrder);
655
+
656
+ // 更新到数据库
657
+ _context7.next = 16;
658
+ return this.dbManager.update('order', existingOrder);
659
+ case 16:
660
+ _context7.next = 18;
661
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
662
+ case 18:
663
+ return _context7.abrupt("return", existingOrder);
664
+ case 21:
665
+ // 创建新的支付订单
666
+ newOrder = {
667
+ uuid: getUniqueId('pay_order_'),
668
+ id: params.order_id,
669
+ order_id: params.order_id,
670
+ order_info: params.order_info,
671
+ payment_status: PaymentStatus.Processing,
672
+ payment: [],
673
+ adjust_offline_payments: [],
674
+ total_amount: params.total_amount,
675
+ expect_amount: params.total_amount,
676
+ tax_fee: '0.00',
677
+ is_deposit: params.is_deposit || 0,
678
+ deposit_amount: params.deposit_amount || '0.00'
679
+ };
680
+ _context7.next = 24;
681
+ return this.dbManager.add('order', newOrder);
682
+ case 24:
683
+ _context7.next = 26;
684
+ return this.core.effects.emit(PaymentHooks.OnOrderAdded, newOrder);
685
+ case 26:
686
+ this.logInfo('createPaymentOrderAsync completed - new payment order created', {
687
+ orderUuid: newOrder.uuid,
688
+ orderId: newOrder.id
689
+ });
690
+ return _context7.abrupt("return", newOrder);
691
+ case 28:
692
+ _context7.next = 35;
693
+ break;
694
+ case 30:
695
+ _context7.prev = 30;
696
+ _context7.t0 = _context7["catch"](1);
697
+ console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
698
+ this.logError('createPaymentOrderAsync failed', _context7.t0, {
699
+ orderId: params.order_id
700
+ });
701
+ throw _context7.t0;
702
+ case 35:
703
+ case "end":
704
+ return _context7.stop();
705
+ }
706
+ }, _callee7, this, [[1, 30]]);
707
+ }));
708
+ function createPaymentOrderAsync(_x6) {
709
+ return _createPaymentOrderAsync.apply(this, arguments);
710
+ }
711
+ return createPaymentOrderAsync;
712
+ }()
713
+ /**
714
+ * 往交易组中添加订单(兼容性方法)
715
+ * @deprecated 使用 createPaymentOrderAsync 替代
716
+ */
717
+ )
718
+ }, {
719
+ key: "pushOrderAsync",
720
+ value: (function () {
721
+ var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
722
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
723
+ while (1) switch (_context8.prev = _context8.next) {
724
+ case 0:
725
+ console.warn('[PaymentModule] pushOrderAsync 已废弃,请使用 createPaymentOrderAsync 替代');
726
+ return _context8.abrupt("return", this.createPaymentOrderAsync(params));
727
+ case 2:
728
+ case "end":
729
+ return _context8.stop();
730
+ }
731
+ }, _callee8, this);
732
+ }));
733
+ function pushOrderAsync(_x7) {
734
+ return _pushOrderAsync.apply(this, arguments);
735
+ }
736
+ return pushOrderAsync;
737
+ }()
738
+ /**
739
+ * 删除支付订单(新方法)
740
+ */
741
+ )
742
+ }, {
743
+ key: "deletePaymentOrderAsync",
744
+ value: (function () {
745
+ var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid) {
746
+ var order;
747
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
748
+ while (1) switch (_context9.prev = _context9.next) {
749
+ case 0:
750
+ _context9.prev = 0;
751
+ _context9.next = 3;
752
+ return this.dbManager.get('order', orderUuid);
112
753
  case 3:
113
- return _context3.abrupt("return", payment);
754
+ order = _context9.sent;
755
+ if (!order) {
756
+ _context9.next = 10;
757
+ break;
758
+ }
759
+ _context9.next = 7;
760
+ return this.dbManager.delete('order', orderUuid);
761
+ case 7:
762
+ _context9.next = 9;
763
+ return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
764
+ case 9:
765
+ console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
766
+ case 10:
767
+ _context9.next = 16;
768
+ break;
769
+ case 12:
770
+ _context9.prev = 12;
771
+ _context9.t0 = _context9["catch"](0);
772
+ console.error('[PaymentModule] 删除支付订单失败', _context9.t0);
773
+ throw _context9.t0;
774
+ case 16:
775
+ case "end":
776
+ return _context9.stop();
777
+ }
778
+ }, _callee9, this, [[0, 12]]);
779
+ }));
780
+ function deletePaymentOrderAsync(_x8) {
781
+ return _deletePaymentOrderAsync.apply(this, arguments);
782
+ }
783
+ return deletePaymentOrderAsync;
784
+ }()
785
+ /**
786
+ * 删除订单(兼容性方法)
787
+ * @deprecated 使用 deletePaymentOrderAsync 替代
788
+ */
789
+ )
790
+ }, {
791
+ key: "deleteOrderAsync",
792
+ value: (function () {
793
+ var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
794
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
795
+ while (1) switch (_context10.prev = _context10.next) {
796
+ case 0:
797
+ console.warn('[PaymentModule] deleteOrderAsync 已废弃,请使用 deletePaymentOrderAsync 替代');
798
+ return _context10.abrupt("return", this.deletePaymentOrderAsync(orderUuid));
799
+ case 2:
800
+ case "end":
801
+ return _context10.stop();
802
+ }
803
+ }, _callee10, this);
804
+ }));
805
+ function deleteOrderAsync(_x9) {
806
+ return _deleteOrderAsync.apply(this, arguments);
807
+ }
808
+ return deleteOrderAsync;
809
+ }()
810
+ /**
811
+ * 更新订单
812
+ */
813
+ )
814
+ }, {
815
+ key: "updateOrderAsync",
816
+ value: (function () {
817
+ var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, params) {
818
+ var order, updatedOrder;
819
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
820
+ while (1) switch (_context11.prev = _context11.next) {
821
+ case 0:
822
+ _context11.prev = 0;
823
+ _context11.next = 3;
824
+ return this.dbManager.get('order', orderUuid);
825
+ case 3:
826
+ order = _context11.sent;
827
+ if (!order) {
828
+ _context11.next = 12;
829
+ break;
830
+ }
831
+ updatedOrder = _objectSpread(_objectSpread({}, order), params);
832
+ _context11.next = 8;
833
+ return this.dbManager.update('order', updatedOrder);
834
+ case 8:
835
+ _context11.next = 10;
836
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
837
+ case 10:
838
+ _context11.next = 12;
839
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
840
+ action: 'update',
841
+ order: updatedOrder,
842
+ originalOrder: order
843
+ });
844
+ case 12:
845
+ _context11.next = 18;
846
+ break;
847
+ case 14:
848
+ _context11.prev = 14;
849
+ _context11.t0 = _context11["catch"](0);
850
+ console.error('[PaymentModule] 更新订单失败', _context11.t0);
851
+ throw _context11.t0;
852
+ case 18:
853
+ case "end":
854
+ return _context11.stop();
855
+ }
856
+ }, _callee11, this, [[0, 14]]);
857
+ }));
858
+ function updateOrderAsync(_x10, _x11) {
859
+ return _updateOrderAsync.apply(this, arguments);
860
+ }
861
+ return updateOrderAsync;
862
+ }()
863
+ /**
864
+ * 基于UUID替换订单ID
865
+ *
866
+ * 此方法用于将本地虚拟订单ID替换为真实的订单ID。
867
+ * 当前端模拟下单流程完成后,后端返回真实订单ID时调用此方法。
868
+ *
869
+ * @param orderUuid 订单的UUID
870
+ * @param newOrderId 新的订单ID (来自后端)
871
+ * @returns 更新后的订单对象,如果订单不存在则返回null
872
+ */
873
+ )
874
+ }, {
875
+ key: "replaceOrderIdByUuidAsync",
876
+ value: (function () {
877
+ var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, newOrderId) {
878
+ var existingOrder, allOrders, duplicateOrder, originalOrderId, updatedOrder;
879
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
880
+ while (1) switch (_context12.prev = _context12.next) {
881
+ case 0:
882
+ this.logInfo('Starting replaceOrderIdByUuidAsync', {
883
+ orderUuid: orderUuid,
884
+ newOrderId: newOrderId
885
+ });
886
+ _context12.prev = 1;
887
+ _context12.next = 4;
888
+ return this.dbManager.get('order', orderUuid);
114
889
  case 4:
890
+ existingOrder = _context12.sent;
891
+ if (existingOrder) {
892
+ _context12.next = 8;
893
+ break;
894
+ }
895
+ this.logWarning('Order not found for UUID replacement', {
896
+ orderUuid: orderUuid
897
+ });
898
+ return _context12.abrupt("return", null);
899
+ case 8:
900
+ _context12.next = 10;
901
+ return this.dbManager.getAll('order');
902
+ case 10:
903
+ allOrders = _context12.sent;
904
+ duplicateOrder = allOrders.find(function (order) {
905
+ return String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid;
906
+ });
907
+ if (!duplicateOrder) {
908
+ _context12.next = 15;
909
+ break;
910
+ }
911
+ this.logWarning('New order ID already exists', {
912
+ newOrderId: newOrderId,
913
+ existingOrderUuid: duplicateOrder.uuid
914
+ });
915
+ throw new Error("\u8BA2\u5355ID ".concat(newOrderId, " \u5DF2\u5B58\u5728"));
916
+ case 15:
917
+ // 保存原始订单ID用于日志
918
+ originalOrderId = existingOrder.id; // 更新订单ID
919
+ updatedOrder = _objectSpread(_objectSpread({}, existingOrder), {}, {
920
+ id: newOrderId,
921
+ order_info: _objectSpread(_objectSpread({}, existingOrder.order_info), {}, {
922
+ order_id: newOrderId,
923
+ // 保留原始本地订单ID作为参考
924
+ original_local_order_id: originalOrderId,
925
+ updated_at: new Date().toISOString()
926
+ })
927
+ }); // 更新到数据库
928
+ _context12.next = 19;
929
+ return this.dbManager.update('order', updatedOrder);
930
+ case 19:
931
+ _context12.next = 21;
932
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
933
+ case 21:
934
+ _context12.next = 23;
935
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
936
+ action: 'order_id_replaced',
937
+ order: updatedOrder,
938
+ originalOrder: existingOrder,
939
+ metadata: {
940
+ originalOrderId: originalOrderId,
941
+ newOrderId: newOrderId
942
+ }
943
+ });
944
+ case 23:
945
+ this.logInfo('Order ID replacement completed successfully', {
946
+ orderUuid: orderUuid,
947
+ originalOrderId: originalOrderId,
948
+ newOrderId: newOrderId
949
+ });
950
+ console.log("[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ".concat(originalOrderId, " \u2192 ").concat(newOrderId));
951
+ return _context12.abrupt("return", updatedOrder);
952
+ case 28:
953
+ _context12.prev = 28;
954
+ _context12.t0 = _context12["catch"](1);
955
+ console.error('[PaymentModule] 替换订单ID失败', _context12.t0);
956
+ this.logError('replaceOrderIdByUuidAsync failed', _context12.t0, {
957
+ orderUuid: orderUuid,
958
+ newOrderId: newOrderId
959
+ });
960
+ throw _context12.t0;
961
+ case 33:
115
962
  case "end":
116
- return _context3.stop();
963
+ return _context12.stop();
117
964
  }
118
- }, _callee3, this);
965
+ }, _callee12, this, [[1, 28]]);
119
966
  }));
120
- function getPayment(_x4) {
121
- return _getPayment.apply(this, arguments);
967
+ function replaceOrderIdByUuidAsync(_x12, _x13) {
968
+ return _replaceOrderIdByUuidAsync.apply(this, arguments);
122
969
  }
123
- return getPayment;
970
+ return replaceOrderIdByUuidAsync;
124
971
  }()
972
+ /**
973
+ * 获取支付项(新方法)
974
+ */
975
+ )
125
976
  }, {
126
- key: "getPaymentHistory",
127
- value: function () {
128
- var _getPaymentHistory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
129
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
130
- while (1) switch (_context4.prev = _context4.next) {
977
+ key: "getPaymentItemsAsync",
978
+ value: (function () {
979
+ var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid) {
980
+ var order;
981
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
982
+ while (1) switch (_context13.prev = _context13.next) {
131
983
  case 0:
132
- return _context4.abrupt("return", this.state.paymentHistory);
133
- case 1:
984
+ if (orderUuid) {
985
+ _context13.next = 2;
986
+ break;
987
+ }
988
+ throw new Error('orderUuid is required');
989
+ case 2:
990
+ _context13.next = 4;
991
+ return this.getPaymentOrderByUuidAsync(orderUuid);
992
+ case 4:
993
+ order = _context13.sent;
994
+ return _context13.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
995
+ case 6:
134
996
  case "end":
135
- return _context4.stop();
997
+ return _context13.stop();
136
998
  }
137
- }, _callee4, this);
999
+ }, _callee13, this);
138
1000
  }));
139
- function getPaymentHistory() {
140
- return _getPaymentHistory.apply(this, arguments);
1001
+ function getPaymentItemsAsync(_x14) {
1002
+ return _getPaymentItemsAsync.apply(this, arguments);
141
1003
  }
142
- return getPaymentHistory;
1004
+ return getPaymentItemsAsync;
143
1005
  }()
1006
+ /**
1007
+ * 获取支付项(兼容性方法)
1008
+ * @deprecated 使用 getPaymentItemsAsync 替代
1009
+ */
1010
+ )
144
1011
  }, {
145
- key: "refund",
146
- value: function () {
147
- var _refund = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(paymentId) {
148
- var payment;
149
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
150
- while (1) switch (_context5.prev = _context5.next) {
1012
+ key: "getPaymentAsync",
1013
+ value: (function () {
1014
+ var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid) {
1015
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1016
+ while (1) switch (_context14.prev = _context14.next) {
1017
+ case 0:
1018
+ console.warn('[PaymentModule] getPaymentAsync 已废弃,请使用 getPaymentItemsAsync 替代');
1019
+ return _context14.abrupt("return", this.getPaymentItemsAsync(orderUuid));
1020
+ case 2:
1021
+ case "end":
1022
+ return _context14.stop();
1023
+ }
1024
+ }, _callee14, this);
1025
+ }));
1026
+ function getPaymentAsync(_x15) {
1027
+ return _getPaymentAsync.apply(this, arguments);
1028
+ }
1029
+ return getPaymentAsync;
1030
+ }()
1031
+ /**
1032
+ * 为某个订单添加支付项(新方法)
1033
+ */
1034
+ )
1035
+ }, {
1036
+ key: "addPaymentItemAsync",
1037
+ value: (function () {
1038
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, paymentItem) {
1039
+ var order, newPaymentItem;
1040
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1041
+ while (1) switch (_context15.prev = _context15.next) {
1042
+ case 0:
1043
+ this.logInfo('Starting addPaymentItemAsync', {
1044
+ orderUuid: orderUuid,
1045
+ paymentAmount: paymentItem.amount,
1046
+ paymentCode: paymentItem.code
1047
+ });
1048
+ _context15.prev = 1;
1049
+ _context15.next = 4;
1050
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1051
+ case 4:
1052
+ order = _context15.sent;
1053
+ if (order) {
1054
+ _context15.next = 7;
1055
+ break;
1056
+ }
1057
+ throw new Error("Order not found: ".concat(orderUuid));
1058
+ case 7:
1059
+ newPaymentItem = {
1060
+ uuid: getUniqueId('payment_'),
1061
+ id: paymentItem.id || 0,
1062
+ name: paymentItem.name,
1063
+ code: paymentItem.code,
1064
+ type: paymentItem.type,
1065
+ amount: formatAmount(paymentItem.amount),
1066
+ voucher_id: paymentItem.voucher_id || '',
1067
+ rounding_amount: '0.00',
1068
+ service_charge: {
1069
+ percentage: '0.00',
1070
+ amount: '0.00'
1071
+ },
1072
+ isSynced: false
1073
+ };
1074
+ order.payment.push(newPaymentItem);
1075
+ this.recalculateOrderAmount(order);
1076
+ _context15.next = 12;
1077
+ return this.dbManager.update('order', order);
1078
+ case 12:
1079
+ _context15.next = 14;
1080
+ return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
1081
+ orderUuid: orderUuid,
1082
+ payment: newPaymentItem
1083
+ });
1084
+ case 14:
1085
+ this.logInfo('addPaymentItemAsync completed successfully', {
1086
+ orderUuid: orderUuid,
1087
+ paymentUuid: newPaymentItem.uuid,
1088
+ newExpectAmount: order.expect_amount
1089
+ });
1090
+ _context15.next = 22;
1091
+ break;
1092
+ case 17:
1093
+ _context15.prev = 17;
1094
+ _context15.t0 = _context15["catch"](1);
1095
+ console.error('[PaymentModule] 添加支付项失败', _context15.t0);
1096
+ this.logError('addPaymentItemAsync failed', _context15.t0, {
1097
+ orderUuid: orderUuid,
1098
+ paymentItem: paymentItem
1099
+ });
1100
+ throw _context15.t0;
1101
+ case 22:
1102
+ case "end":
1103
+ return _context15.stop();
1104
+ }
1105
+ }, _callee15, this, [[1, 17]]);
1106
+ }));
1107
+ function addPaymentItemAsync(_x16, _x17) {
1108
+ return _addPaymentItemAsync.apply(this, arguments);
1109
+ }
1110
+ return addPaymentItemAsync;
1111
+ }()
1112
+ /**
1113
+ * 为某个订单设置一个支付项(兼容性方法)
1114
+ * @deprecated 使用 addPaymentItemAsync 替代
1115
+ */
1116
+ )
1117
+ }, {
1118
+ key: "pushPaymentAsync",
1119
+ value: (function () {
1120
+ var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentItem) {
1121
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1122
+ while (1) switch (_context16.prev = _context16.next) {
1123
+ case 0:
1124
+ console.warn('[PaymentModule] pushPaymentAsync 已废弃,请使用 addPaymentItemAsync 替代');
1125
+ return _context16.abrupt("return", this.addPaymentItemAsync(orderUuid, paymentItem));
1126
+ case 2:
1127
+ case "end":
1128
+ return _context16.stop();
1129
+ }
1130
+ }, _callee16, this);
1131
+ }));
1132
+ function pushPaymentAsync(_x18, _x19) {
1133
+ return _pushPaymentAsync.apply(this, arguments);
1134
+ }
1135
+ return pushPaymentAsync;
1136
+ }()
1137
+ /**
1138
+ * 删除一个支付项
1139
+ */
1140
+ )
1141
+ }, {
1142
+ key: "deletePaymentAsync",
1143
+ value: (function () {
1144
+ var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid, paymentUuid) {
1145
+ var order, index, deletedPayment;
1146
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1147
+ while (1) switch (_context17.prev = _context17.next) {
1148
+ case 0:
1149
+ this.logInfo('Starting deletePaymentAsync', {
1150
+ orderUuid: orderUuid,
1151
+ paymentUuid: paymentUuid
1152
+ });
1153
+ _context17.prev = 1;
1154
+ _context17.next = 4;
1155
+ return this.dbManager.get('order', orderUuid);
1156
+ case 4:
1157
+ order = _context17.sent;
1158
+ if (order) {
1159
+ _context17.next = 7;
1160
+ break;
1161
+ }
1162
+ throw new Error('订单不存在');
1163
+ case 7:
1164
+ index = order.payment.findIndex(function (payment) {
1165
+ return payment.uuid === paymentUuid;
1166
+ });
1167
+ if (!(index > -1)) {
1168
+ _context17.next = 17;
1169
+ break;
1170
+ }
1171
+ deletedPayment = order.payment.splice(index, 1)[0]; // 重新计算待付金额
1172
+ this.recalculateOrderAmount(order);
1173
+
1174
+ // 更新到 IndexDB
1175
+ _context17.next = 13;
1176
+ return this.dbManager.update('order', order);
1177
+ case 13:
1178
+ _context17.next = 15;
1179
+ return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
1180
+ order: order,
1181
+ paymentItem: deletedPayment
1182
+ });
1183
+ case 15:
1184
+ _context17.next = 17;
1185
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1186
+ action: 'payment_delete',
1187
+ order: order,
1188
+ paymentItem: deletedPayment
1189
+ });
1190
+ case 17:
1191
+ _context17.next = 23;
1192
+ break;
1193
+ case 19:
1194
+ _context17.prev = 19;
1195
+ _context17.t0 = _context17["catch"](1);
1196
+ console.error('[PaymentModule] 删除支付项失败', _context17.t0);
1197
+ throw _context17.t0;
1198
+ case 23:
1199
+ case "end":
1200
+ return _context17.stop();
1201
+ }
1202
+ }, _callee17, this, [[1, 19]]);
1203
+ }));
1204
+ function deletePaymentAsync(_x20, _x21) {
1205
+ return _deletePaymentAsync.apply(this, arguments);
1206
+ }
1207
+ return deletePaymentAsync;
1208
+ }()
1209
+ /**
1210
+ * 更新一个支付项
1211
+ */
1212
+ )
1213
+ }, {
1214
+ key: "updatePaymentAsync",
1215
+ value: (function () {
1216
+ var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(orderUuid, paymentUuid, params) {
1217
+ var order, paymentItem, formattedParams;
1218
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1219
+ while (1) switch (_context18.prev = _context18.next) {
1220
+ case 0:
1221
+ _context18.prev = 0;
1222
+ _context18.next = 3;
1223
+ return this.dbManager.get('order', orderUuid);
1224
+ case 3:
1225
+ order = _context18.sent;
1226
+ if (order) {
1227
+ _context18.next = 6;
1228
+ break;
1229
+ }
1230
+ throw new Error('订单不存在');
1231
+ case 6:
1232
+ paymentItem = order.payment.find(function (payment) {
1233
+ return payment.uuid === paymentUuid;
1234
+ });
1235
+ if (!paymentItem) {
1236
+ _context18.next = 18;
1237
+ break;
1238
+ }
1239
+ // 如果更新参数中包含 amount,先格式化
1240
+ formattedParams = _objectSpread({}, params);
1241
+ if ('amount' in formattedParams && formattedParams.amount !== undefined) {
1242
+ formattedParams.amount = formatAmount(formattedParams.amount);
1243
+ }
1244
+ Object.assign(paymentItem, formattedParams);
1245
+
1246
+ // 重新计算待付金额
1247
+ this.recalculateOrderAmount(order);
1248
+
1249
+ // 更新到 IndexDB
1250
+ _context18.next = 14;
1251
+ return this.dbManager.update('order', order);
1252
+ case 14:
1253
+ _context18.next = 16;
1254
+ return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
1255
+ order: order,
1256
+ paymentItem: paymentItem
1257
+ });
1258
+ case 16:
1259
+ _context18.next = 18;
1260
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1261
+ action: 'payment_update',
1262
+ order: order,
1263
+ paymentItem: paymentItem
1264
+ });
1265
+ case 18:
1266
+ _context18.next = 24;
1267
+ break;
1268
+ case 20:
1269
+ _context18.prev = 20;
1270
+ _context18.t0 = _context18["catch"](0);
1271
+ console.error('[PaymentModule] 更新支付项失败', _context18.t0);
1272
+ throw _context18.t0;
1273
+ case 24:
1274
+ case "end":
1275
+ return _context18.stop();
1276
+ }
1277
+ }, _callee18, this, [[0, 20]]);
1278
+ }));
1279
+ function updatePaymentAsync(_x22, _x23, _x24) {
1280
+ return _updatePaymentAsync.apply(this, arguments);
1281
+ }
1282
+ return updatePaymentAsync;
1283
+ }()
1284
+ /**
1285
+ * 提交支付
1286
+ */
1287
+ )
1288
+ }, {
1289
+ key: "submitPayAsync",
1290
+ value: (function () {
1291
+ var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
1292
+ var orderToSubmit, order, _allOrders, _iterator5, _step5, _order, allOrders, allOrdersProcessed, result;
1293
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1294
+ while (1) switch (_context19.prev = _context19.next) {
1295
+ case 0:
1296
+ this.logInfo('Starting submitPayAsync', {
1297
+ orderUuid: orderUuid
1298
+ });
1299
+ _context19.prev = 1;
1300
+ if (!orderUuid) {
1301
+ _context19.next = 9;
1302
+ break;
1303
+ }
1304
+ _context19.next = 5;
1305
+ return this.dbManager.get('order', orderUuid);
1306
+ case 5:
1307
+ order = _context19.sent;
1308
+ orderToSubmit = order ? [order] : [];
1309
+ _context19.next = 13;
1310
+ break;
1311
+ case 9:
1312
+ _context19.next = 11;
1313
+ return this.dbManager.getAll('order');
1314
+ case 11:
1315
+ _allOrders = _context19.sent;
1316
+ // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1317
+ orderToSubmit = _allOrders.filter(function (order) {
1318
+ return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
1319
+ });
1320
+ case 13:
1321
+ _iterator5 = _createForOfIteratorHelper(orderToSubmit);
1322
+ _context19.prev = 14;
1323
+ _iterator5.s();
1324
+ case 16:
1325
+ if ((_step5 = _iterator5.n()).done) {
1326
+ _context19.next = 22;
1327
+ break;
1328
+ }
1329
+ _order = _step5.value;
1330
+ _context19.next = 20;
1331
+ return this.submitSingleOrderPayment(_order);
1332
+ case 20:
1333
+ _context19.next = 16;
1334
+ break;
1335
+ case 22:
1336
+ _context19.next = 27;
1337
+ break;
1338
+ case 24:
1339
+ _context19.prev = 24;
1340
+ _context19.t0 = _context19["catch"](14);
1341
+ _iterator5.e(_context19.t0);
1342
+ case 27:
1343
+ _context19.prev = 27;
1344
+ _iterator5.f();
1345
+ return _context19.finish(27);
1346
+ case 30:
1347
+ _context19.next = 32;
1348
+ return this.runPaymentSyncQueue();
1349
+ case 32:
1350
+ _context19.next = 34;
1351
+ return this.dbManager.getAll('order');
1352
+ case 34:
1353
+ allOrders = _context19.sent;
1354
+ allOrdersProcessed = allOrders.every(function (order) {
1355
+ return order.payment.every(function (payment) {
1356
+ return payment.isSynced === true;
1357
+ });
1358
+ });
1359
+ if (!allOrdersProcessed) {
1360
+ _context19.next = 42;
1361
+ break;
1362
+ }
1363
+ result = {
1364
+ status: 'success'
1365
+ };
1366
+ this.logInfo('submitPayAsync completed', {
1367
+ result: result.status,
1368
+ processedOrdersCount: allOrders.length
1369
+ });
1370
+ return _context19.abrupt("return", result);
1371
+ case 42:
1372
+ this.logWarning('submitPayAsync completed with unprocessed orders', {
1373
+ totalOrders: allOrders.length
1374
+ });
1375
+ return _context19.abrupt("return", {
1376
+ status: 'failed'
1377
+ });
1378
+ case 44:
1379
+ _context19.next = 51;
1380
+ break;
1381
+ case 46:
1382
+ _context19.prev = 46;
1383
+ _context19.t1 = _context19["catch"](1);
1384
+ console.error('[PaymentModule] 提交支付失败', _context19.t1);
1385
+ this.logError('submitPayAsync failed', _context19.t1, {
1386
+ orderUuid: orderUuid
1387
+ });
1388
+ return _context19.abrupt("return", {
1389
+ status: 'failed'
1390
+ });
1391
+ case 51:
1392
+ case "end":
1393
+ return _context19.stop();
1394
+ }
1395
+ }, _callee19, this, [[1, 46], [14, 24, 27, 30]]);
1396
+ }));
1397
+ function submitPayAsync(_x25) {
1398
+ return _submitPayAsync.apply(this, arguments);
1399
+ }
1400
+ return submitPayAsync;
1401
+ }()
1402
+ /**
1403
+ * 提交单个订单的支付(推送到任务队列)
1404
+ */
1405
+ )
1406
+ }, {
1407
+ key: "submitSingleOrderPayment",
1408
+ value: (function () {
1409
+ var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(order) {
1410
+ var paymentData, totalPaidAmount, orderTotalAmount;
1411
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1412
+ while (1) switch (_context20.prev = _context20.next) {
151
1413
  case 0:
152
- payment = this.state.paymentHistory.find(function (p) {
153
- return p.id === paymentId;
1414
+ _context20.prev = 0;
1415
+ paymentData = {
1416
+ payments: order.payment.map(function (payment) {
1417
+ return {
1418
+ uuid: payment.uuid,
1419
+ amount: payment.amount,
1420
+ code: payment.code,
1421
+ id: payment.id,
1422
+ name: payment.name,
1423
+ type: payment.type,
1424
+ voucher_id: payment.voucher_id,
1425
+ metadata: payment.metadata,
1426
+ rounding_amount: payment.rounding_amount,
1427
+ service_charge: payment.service_charge
1428
+ };
1429
+ }),
1430
+ payment_status: 'pending'
1431
+ }; // 计算总支付金额
1432
+ totalPaidAmount = paymentData.payments.reduce(function (sum, payment) {
1433
+ return sum.plus(payment.amount);
1434
+ }, new Decimal(0));
1435
+ orderTotalAmount = new Decimal(order.total_amount); // 根据支付金额判断订单状态
1436
+ if (totalPaidAmount.gte(orderTotalAmount)) {
1437
+ // 支付金额足够,标记为已完成
1438
+ order.payment_status = PaymentStatus.Finished;
1439
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5B8C\u6210\uFF0C\u91D1\u989D: ").concat(totalPaidAmount.toString(), "/").concat(orderTotalAmount.toString()));
1440
+ } else {
1441
+ // 支付金额不足,标记为部分支付
1442
+ order.payment_status = PaymentStatus.PartiallyPaid;
1443
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u90E8\u5206\u652F\u4ED8\uFF0C\u91D1\u989D: ").concat(totalPaidAmount.toString(), "/").concat(orderTotalAmount.toString()));
1444
+ }
1445
+
1446
+ // 给后端标记一下是全部支付(paid)还是部分支付
1447
+ paymentData.payment_status = order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid';
1448
+
1449
+ // 更新订单状态到数据库
1450
+ // 注意:isSynced 保持为 false,直到网络同步成功后才设为 true
1451
+ _context20.next = 8;
1452
+ return this.dbManager.update('order', order);
1453
+ case 8:
1454
+ if (!(paymentData.payments.length === 0)) {
1455
+ _context20.next = 12;
1456
+ break;
1457
+ }
1458
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u961F\u5217\u63A8\u9001"));
1459
+ this.logWarning('Empty payment queue submission', {
1460
+ orderUuid: order.uuid,
1461
+ orderId: order.order_id
154
1462
  });
155
- if (payment) {
156
- _context5.next = 3;
1463
+ return _context20.abrupt("return");
1464
+ case 12:
1465
+ _context20.next = 14;
1466
+ return this.addToSyncQueue(order, paymentData);
1467
+ case 14:
1468
+ _context20.next = 16;
1469
+ return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
1470
+ case 16:
1471
+ _context20.next = 18;
1472
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1473
+ action: 'submit',
1474
+ order: order
1475
+ });
1476
+ case 18:
1477
+ _context20.next = 24;
1478
+ break;
1479
+ case 20:
1480
+ _context20.prev = 20;
1481
+ _context20.t0 = _context20["catch"](0);
1482
+ console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context20.t0);
1483
+ throw _context20.t0;
1484
+ case 24:
1485
+ case "end":
1486
+ return _context20.stop();
1487
+ }
1488
+ }, _callee20, this, [[0, 20]]);
1489
+ }));
1490
+ function submitSingleOrderPayment(_x26) {
1491
+ return _submitSingleOrderPayment.apply(this, arguments);
1492
+ }
1493
+ return submitSingleOrderPayment;
1494
+ }()
1495
+ /**
1496
+ * 添加到同步任务队列
1497
+ */
1498
+ )
1499
+ }, {
1500
+ key: "addToSyncQueue",
1501
+ value: (function () {
1502
+ var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order, paymentData) {
1503
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1504
+ while (1) switch (_context21.prev = _context21.next) {
1505
+ case 0:
1506
+ try {
1507
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
1508
+
1509
+ // 集成TasksManager
1510
+ if (this.app.tasksManager) {
1511
+ this.app.tasksManager.addTask({
1512
+ module: 'payment',
1513
+ queueId: 'payment_sync',
1514
+ tasks: [{
1515
+ id: "payment_".concat(order.uuid),
1516
+ action: 'syncPayment',
1517
+ payload: {
1518
+ orderUuid: order.uuid,
1519
+ orderId: order.order_id,
1520
+ paymentData: paymentData,
1521
+ core: this.core
1522
+ },
1523
+ maxRetries: 3,
1524
+ type: 'cloud'
1525
+ }]
1526
+ });
1527
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u540C\u6B65\u4EFB\u52A1\u5DF2\u6DFB\u52A0\u5230\u961F\u5217"));
1528
+ } else {
1529
+ console.warn('[PaymentModule] TasksManager 未初始化,无法添加同步任务');
1530
+ }
1531
+ } catch (error) {
1532
+ console.error('[PaymentModule] 添加同步任务失败', error);
1533
+ }
1534
+ case 1:
1535
+ case "end":
1536
+ return _context21.stop();
1537
+ }
1538
+ }, _callee21, this);
1539
+ }));
1540
+ function addToSyncQueue(_x27, _x28) {
1541
+ return _addToSyncQueue.apply(this, arguments);
1542
+ }
1543
+ return addToSyncQueue;
1544
+ }()
1545
+ /**
1546
+ * 获取订单剩余待付金额
1547
+ */
1548
+ )
1549
+ }, {
1550
+ key: "getRemainingOrderAmountAsync",
1551
+ value: (function () {
1552
+ var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderUuid) {
1553
+ var order;
1554
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1555
+ while (1) switch (_context22.prev = _context22.next) {
1556
+ case 0:
1557
+ _context22.next = 2;
1558
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1559
+ case 2:
1560
+ order = _context22.sent;
1561
+ if (order) {
1562
+ _context22.next = 5;
1563
+ break;
1564
+ }
1565
+ throw new Error('订单不存在');
1566
+ case 5:
1567
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1568
+ case 6:
1569
+ case "end":
1570
+ return _context22.stop();
1571
+ }
1572
+ }, _callee22, this);
1573
+ }));
1574
+ function getRemainingOrderAmountAsync(_x29) {
1575
+ return _getRemainingOrderAmountAsync.apply(this, arguments);
1576
+ }
1577
+ return getRemainingOrderAmountAsync;
1578
+ }()
1579
+ /**
1580
+ * 在比如现金支付界面的地方,用户输入了一个金额,在下方显示剩余多少金额,通过此方法获取
1581
+ */
1582
+ )
1583
+ }, {
1584
+ key: "getRemainingOrderAmountWithInputAsync",
1585
+ value: (function () {
1586
+ var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(inputAmount, orderUuid) {
1587
+ var order, inputDecimal;
1588
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1589
+ while (1) switch (_context23.prev = _context23.next) {
1590
+ case 0:
1591
+ _context23.next = 2;
1592
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1593
+ case 2:
1594
+ order = _context23.sent;
1595
+ if (order) {
1596
+ _context23.next = 5;
1597
+ break;
1598
+ }
1599
+ throw new Error('订单不存在');
1600
+ case 5:
1601
+ if (!(inputAmount === null || inputAmount === undefined)) {
1602
+ _context23.next = 7;
1603
+ break;
1604
+ }
1605
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1606
+ case 7:
1607
+ if (!(typeof inputAmount === 'string')) {
1608
+ _context23.next = 10;
1609
+ break;
1610
+ }
1611
+ if (!(inputAmount.trim() === '')) {
1612
+ _context23.next = 10;
1613
+ break;
1614
+ }
1615
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1616
+ case 10:
1617
+ if (!(typeof inputAmount === 'number')) {
1618
+ _context23.next = 14;
1619
+ break;
1620
+ }
1621
+ if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
1622
+ _context23.next = 14;
157
1623
  break;
158
1624
  }
159
- return _context5.abrupt("return");
1625
+ // 如果输入是 NaN 或无穷大,返回原始的待付金额
1626
+ console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1627
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1628
+ case 14:
1629
+ _context23.prev = 14;
1630
+ inputDecimal = new Decimal(inputAmount);
1631
+ return _context23.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1632
+ case 19:
1633
+ _context23.prev = 19;
1634
+ _context23.t0 = _context23["catch"](14);
1635
+ // 如果输入不是有效的数字,返回原始的待付金额
1636
+ console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1637
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1638
+ case 23:
1639
+ case "end":
1640
+ return _context23.stop();
1641
+ }
1642
+ }, _callee23, this, [[14, 19]]);
1643
+ }));
1644
+ function getRemainingOrderAmountWithInputAsync(_x30, _x31) {
1645
+ return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
1646
+ }
1647
+ return getRemainingOrderAmountWithInputAsync;
1648
+ }()
1649
+ /**
1650
+ * 重新计算订单金额
1651
+ */
1652
+ )
1653
+ }, {
1654
+ key: "recalculateOrderAmount",
1655
+ value: function recalculateOrderAmount(order) {
1656
+ var totalAmount = new Decimal(order.total_amount);
1657
+ var paidAmount = order.payment.reduce(function (sum, payment) {
1658
+ try {
1659
+ return sum.plus(payment.amount);
1660
+ } catch (error) {
1661
+ console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
1662
+ return sum;
1663
+ }
1664
+ }, new Decimal(0));
1665
+ var remainingAmount = totalAmount.minus(paidAmount);
1666
+ order.expect_amount = Decimal.max(0, remainingAmount).toFixed(2);
1667
+ }
1668
+
1669
+ /**
1670
+ * 获取现金支付方式
1671
+ */
1672
+ }, {
1673
+ key: "getCashPaymentMethod",
1674
+ value: (function () {
1675
+ var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1676
+ var payMethods;
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('pay_method');
160
1683
  case 3:
161
- payment.status = 'refunded';
162
- payment.updatedAt = new Date();
163
- _context5.next = 7;
164
- return this.core.effects.emit(PaymentHooks.OnPaymentRefund, payment);
1684
+ payMethods = _context24.sent;
1685
+ return _context24.abrupt("return", payMethods.find(function (method) {
1686
+ return method.code === PaymentMethodType.Cash;
1687
+ }) || null);
165
1688
  case 7:
1689
+ _context24.prev = 7;
1690
+ _context24.t0 = _context24["catch"](0);
1691
+ console.error('[PaymentModule] 获取现金支付方式失败', _context24.t0);
1692
+ return _context24.abrupt("return", null);
1693
+ case 11:
166
1694
  case "end":
167
- return _context5.stop();
1695
+ return _context24.stop();
168
1696
  }
169
- }, _callee5, this);
1697
+ }, _callee24, this, [[0, 7]]);
170
1698
  }));
171
- function refund(_x5) {
172
- return _refund.apply(this, arguments);
1699
+ function getCashPaymentMethod() {
1700
+ return _getCashPaymentMethod.apply(this, arguments);
173
1701
  }
174
- return refund;
1702
+ return getCashPaymentMethod;
175
1703
  }()
1704
+ /**
1705
+ * 获取Eftpos支付方式
1706
+ */
1707
+ )
176
1708
  }, {
177
- key: "getAvailablePaymentMethods",
178
- value: function getAvailablePaymentMethods() {
179
- return ['credit_card', 'debit_card', 'alipay', 'wechat_pay'];
1709
+ key: "getEftposPaymentMethod",
1710
+ value: (function () {
1711
+ var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1712
+ var payMethods;
1713
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1714
+ while (1) switch (_context25.prev = _context25.next) {
1715
+ case 0:
1716
+ _context25.prev = 0;
1717
+ _context25.next = 3;
1718
+ return this.dbManager.getAll('pay_method');
1719
+ case 3:
1720
+ payMethods = _context25.sent;
1721
+ return _context25.abrupt("return", payMethods.find(function (method) {
1722
+ return method.code === PaymentMethodType.Eftpos;
1723
+ }) || null);
1724
+ case 7:
1725
+ _context25.prev = 7;
1726
+ _context25.t0 = _context25["catch"](0);
1727
+ console.error('[PaymentModule] 获取Eftpos支付方式失败', _context25.t0);
1728
+ return _context25.abrupt("return", null);
1729
+ case 11:
1730
+ case "end":
1731
+ return _context25.stop();
1732
+ }
1733
+ }, _callee25, this, [[0, 7]]);
1734
+ }));
1735
+ function getEftposPaymentMethod() {
1736
+ return _getEftposPaymentMethod.apply(this, arguments);
1737
+ }
1738
+ return getEftposPaymentMethod;
1739
+ }()
1740
+ /**
1741
+ * 获取钱包支付方式
1742
+ */
1743
+ )
1744
+ }, {
1745
+ key: "getWalletPaymentMethod",
1746
+ value: (function () {
1747
+ var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1748
+ var payMethods;
1749
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1750
+ while (1) switch (_context26.prev = _context26.next) {
1751
+ case 0:
1752
+ _context26.prev = 0;
1753
+ _context26.next = 3;
1754
+ return this.dbManager.getAll('pay_method');
1755
+ case 3:
1756
+ payMethods = _context26.sent;
1757
+ return _context26.abrupt("return", payMethods.find(function (method) {
1758
+ return method.code === PaymentMethodType.Wallet;
1759
+ }) || null);
1760
+ case 7:
1761
+ _context26.prev = 7;
1762
+ _context26.t0 = _context26["catch"](0);
1763
+ console.error('[PaymentModule] 获取钱包支付方式失败', _context26.t0);
1764
+ return _context26.abrupt("return", null);
1765
+ case 11:
1766
+ case "end":
1767
+ return _context26.stop();
1768
+ }
1769
+ }, _callee26, this, [[0, 7]]);
1770
+ }));
1771
+ function getWalletPaymentMethod() {
1772
+ return _getWalletPaymentMethod.apply(this, arguments);
1773
+ }
1774
+ return getWalletPaymentMethod;
1775
+ }()
1776
+ /**
1777
+ * 注册任务处理函数
1778
+ */
1779
+ )
1780
+ }, {
1781
+ key: "registerTaskHandlers",
1782
+ value: function registerTaskHandlers() {
1783
+ if (this.app.tasksManager) {
1784
+ // 注册支付同步任务处理函数
1785
+ this.app.tasksManager.addTaskFunction('syncPayment', PaymentModule.syncPaymentTask);
1786
+ console.log('[PaymentModule] 任务处理函数已注册');
1787
+ } else {
1788
+ console.warn('[PaymentModule] TasksManager 未初始化,无法注册任务处理函数');
1789
+ }
180
1790
  }
1791
+
1792
+ /**
1793
+ * 静态方法:处理支付同步任务(后台网络同步)
1794
+ * 这个方法里不允许用 this,因为需要作为静态方法注入到任务队列里
1795
+ */
181
1796
  }, {
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) {
1797
+ key: "ensurePaymentTables",
1798
+ value: (
1799
+ /**
1800
+ * 确保支付模块所需的数据库表已创建
1801
+ */
1802
+ function () {
1803
+ var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1804
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1805
+ while (1) switch (_context27.prev = _context27.next) {
188
1806
  case 0:
189
- payment = this.state.paymentHistory.find(function (p) {
190
- return p.id === paymentId;
1807
+ _context27.prev = 0;
1808
+ _context27.next = 3;
1809
+ return this.dbManager.getAll('pay_method');
1810
+ case 3:
1811
+ _context27.next = 9;
1812
+ break;
1813
+ case 5:
1814
+ _context27.prev = 5;
1815
+ _context27.t0 = _context27["catch"](0);
1816
+ console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
1817
+ console.warn('{ name: "pay_method", keyPath: "id" }');
1818
+ case 9:
1819
+ _context27.prev = 9;
1820
+ _context27.next = 12;
1821
+ return this.dbManager.getAll('order');
1822
+ case 12:
1823
+ _context27.next = 18;
1824
+ break;
1825
+ case 14:
1826
+ _context27.prev = 14;
1827
+ _context27.t1 = _context27["catch"](9);
1828
+ console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
1829
+ console.warn('{ name: "order", keyPath: "uuid" }');
1830
+ case 18:
1831
+ case "end":
1832
+ return _context27.stop();
1833
+ }
1834
+ }, _callee27, this, [[0, 5], [9, 14]]);
1835
+ }));
1836
+ function ensurePaymentTables() {
1837
+ return _ensurePaymentTables.apply(this, arguments);
1838
+ }
1839
+ return ensurePaymentTables;
1840
+ }()
1841
+ /**
1842
+ * 获取部分支付的订单
1843
+ */
1844
+ )
1845
+ }, {
1846
+ key: "getPartiallyPaidOrdersAsync",
1847
+ value: (function () {
1848
+ var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
1849
+ var allOrders;
1850
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1851
+ while (1) switch (_context28.prev = _context28.next) {
1852
+ case 0:
1853
+ _context28.prev = 0;
1854
+ _context28.next = 3;
1855
+ return this.dbManager.getAll('order');
1856
+ case 3:
1857
+ allOrders = _context28.sent;
1858
+ return _context28.abrupt("return", allOrders.filter(function (order) {
1859
+ return order.payment_status === PaymentStatus.PartiallyPaid;
1860
+ }));
1861
+ case 7:
1862
+ _context28.prev = 7;
1863
+ _context28.t0 = _context28["catch"](0);
1864
+ console.error('[PaymentModule] 获取部分支付订单失败', _context28.t0);
1865
+ return _context28.abrupt("return", []);
1866
+ case 11:
1867
+ case "end":
1868
+ return _context28.stop();
1869
+ }
1870
+ }, _callee28, this, [[0, 7]]);
1871
+ }));
1872
+ function getPartiallyPaidOrdersAsync() {
1873
+ return _getPartiallyPaidOrdersAsync.apply(this, arguments);
1874
+ }
1875
+ return getPartiallyPaidOrdersAsync;
1876
+ }()
1877
+ /**
1878
+ * 获取未同步到服务器的订单
1879
+ */
1880
+ )
1881
+ }, {
1882
+ key: "getUnsyncedOrdersAsync",
1883
+ value: (function () {
1884
+ var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
1885
+ var allOrders;
1886
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1887
+ while (1) switch (_context29.prev = _context29.next) {
1888
+ case 0:
1889
+ _context29.prev = 0;
1890
+ _context29.next = 3;
1891
+ return this.dbManager.getAll('order');
1892
+ case 3:
1893
+ allOrders = _context29.sent;
1894
+ return _context29.abrupt("return", allOrders.filter(function (order) {
1895
+ // 订单已完成或部分支付,但支付项还未同步
1896
+ return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
1897
+ return !payment.isSynced;
1898
+ });
1899
+ }));
1900
+ case 7:
1901
+ _context29.prev = 7;
1902
+ _context29.t0 = _context29["catch"](0);
1903
+ console.error('[PaymentModule] 获取未同步订单失败', _context29.t0);
1904
+ return _context29.abrupt("return", []);
1905
+ case 11:
1906
+ case "end":
1907
+ return _context29.stop();
1908
+ }
1909
+ }, _callee29, this, [[0, 7]]);
1910
+ }));
1911
+ function getUnsyncedOrdersAsync() {
1912
+ return _getUnsyncedOrdersAsync.apply(this, arguments);
1913
+ }
1914
+ return getUnsyncedOrdersAsync;
1915
+ }()
1916
+ /**
1917
+ * 清理已完成且已同步的订单
1918
+ * 注意:只清理完全支付的订单,部分支付的订单保留以便继续支付
1919
+ */
1920
+ )
1921
+ }, {
1922
+ key: "cleanupFinishedOrders",
1923
+ value: (function () {
1924
+ var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
1925
+ var allOrders, finishedAndSyncedOrders, _iterator6, _step6, order;
1926
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
1927
+ while (1) switch (_context30.prev = _context30.next) {
1928
+ case 0:
1929
+ _context30.prev = 0;
1930
+ _context30.next = 3;
1931
+ return this.dbManager.getAll('order');
1932
+ case 3:
1933
+ allOrders = _context30.sent;
1934
+ finishedAndSyncedOrders = allOrders.filter(function (order) {
1935
+ return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
1936
+ return payment.isSynced;
1937
+ });
191
1938
  });
192
- if (payment) {
193
- _context6.next = 3;
1939
+ _iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
1940
+ _context30.prev = 6;
1941
+ _iterator6.s();
1942
+ case 8:
1943
+ if ((_step6 = _iterator6.n()).done) {
1944
+ _context30.next = 14;
194
1945
  break;
195
1946
  }
196
- throw new Error('Payment not found');
197
- case 3:
198
- return _context6.abrupt("return", payment.status);
199
- case 4:
1947
+ order = _step6.value;
1948
+ _context30.next = 12;
1949
+ return this.deleteOrderAsync(order.uuid);
1950
+ case 12:
1951
+ _context30.next = 8;
1952
+ break;
1953
+ case 14:
1954
+ _context30.next = 19;
1955
+ break;
1956
+ case 16:
1957
+ _context30.prev = 16;
1958
+ _context30.t0 = _context30["catch"](6);
1959
+ _iterator6.e(_context30.t0);
1960
+ case 19:
1961
+ _context30.prev = 19;
1962
+ _iterator6.f();
1963
+ return _context30.finish(19);
1964
+ case 22:
1965
+ console.log("[PaymentModule] \u6E05\u7406\u4E86 ".concat(finishedAndSyncedOrders.length, " \u4E2A\u5DF2\u5B8C\u6210\u4E14\u5DF2\u540C\u6B65\u7684\u8BA2\u5355"));
1966
+ _context30.next = 28;
1967
+ break;
1968
+ case 25:
1969
+ _context30.prev = 25;
1970
+ _context30.t1 = _context30["catch"](0);
1971
+ console.error('[PaymentModule] 清理已完成订单失败', _context30.t1);
1972
+ case 28:
200
1973
  case "end":
201
- return _context6.stop();
1974
+ return _context30.stop();
202
1975
  }
203
- }, _callee6, this);
1976
+ }, _callee30, this, [[0, 25], [6, 16, 19, 22]]);
204
1977
  }));
205
- function checkPaymentStatus(_x6) {
206
- return _checkPaymentStatus.apply(this, arguments);
1978
+ function cleanupFinishedOrders() {
1979
+ return _cleanupFinishedOrders.apply(this, arguments);
207
1980
  }
208
- return checkPaymentStatus;
1981
+ return cleanupFinishedOrders;
209
1982
  }()
1983
+ /**
1984
+ * 检测未同步的订单并重新加入任务队列
1985
+ *
1986
+ * 此方法专门用于处理因网络问题导致任务队列执行失败但队列被清空的情况。
1987
+ * 它会检查本地 IndexDB 中所有未同步的订单(isSynced: false),
1988
+ * 并将这些订单重新添加到任务队列中。
1989
+ *
1990
+ * 使用场景:
1991
+ * - 网络恢复后重新检查未同步的订单
1992
+ * - 应用启动时检查并重新排队未完成的支付
1993
+ * - 用户手动重试前的预检查
1994
+ *
1995
+ * @returns Promise<number> 返回重新加入队列的订单数量
1996
+ */
1997
+ )
1998
+ }, {
1999
+ key: "recheckAndRequeueUnsyncedOrders",
2000
+ value: (function () {
2001
+ var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2002
+ var unsyncedOrders, requeuedCount, _iterator7, _step7, order, success;
2003
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2004
+ while (1) switch (_context31.prev = _context31.next) {
2005
+ case 0:
2006
+ this.logInfo('Starting recheckAndRequeueUnsyncedOrders');
2007
+ _context31.prev = 1;
2008
+ if (this.app.tasksManager) {
2009
+ _context31.next = 6;
2010
+ break;
2011
+ }
2012
+ console.warn('[PaymentModule] TasksManager 未初始化,无法重新排队未同步订单');
2013
+ this.logWarning('TasksManager not initialized, cannot requeue unsynced orders');
2014
+ return _context31.abrupt("return", 0);
2015
+ case 6:
2016
+ _context31.next = 8;
2017
+ return this.getUnsyncedOrdersAsync();
2018
+ case 8:
2019
+ unsyncedOrders = _context31.sent;
2020
+ if (!(unsyncedOrders.length === 0)) {
2021
+ _context31.next = 13;
2022
+ break;
2023
+ }
2024
+ console.log('[PaymentModule] 没有发现未同步的订单');
2025
+ this.logInfo('No unsynced orders found');
2026
+ return _context31.abrupt("return", 0);
2027
+ case 13:
2028
+ console.log("[PaymentModule] \u53D1\u73B0 ".concat(unsyncedOrders.length, " \u4E2A\u672A\u540C\u6B65\u7684\u8BA2\u5355\uFF0C\u5F00\u59CB\u91CD\u65B0\u52A0\u5165\u4EFB\u52A1\u961F\u5217"));
2029
+ this.logInfo('Found unsynced orders, adding to sync queue', {
2030
+ unsyncedCount: unsyncedOrders.length,
2031
+ orderUuids: unsyncedOrders.map(function (o) {
2032
+ return o.uuid;
2033
+ })
2034
+ });
2035
+ requeuedCount = 0; // 将未同步的订单重新添加到任务队列
2036
+ _iterator7 = _createForOfIteratorHelper(unsyncedOrders);
2037
+ _context31.prev = 17;
2038
+ _iterator7.s();
2039
+ case 19:
2040
+ if ((_step7 = _iterator7.n()).done) {
2041
+ _context31.next = 27;
2042
+ break;
2043
+ }
2044
+ order = _step7.value;
2045
+ _context31.next = 23;
2046
+ return this.reAddOrderToSyncQueue(order);
2047
+ case 23:
2048
+ success = _context31.sent;
2049
+ if (success) {
2050
+ requeuedCount++;
2051
+ }
2052
+ case 25:
2053
+ _context31.next = 19;
2054
+ break;
2055
+ case 27:
2056
+ _context31.next = 32;
2057
+ break;
2058
+ case 29:
2059
+ _context31.prev = 29;
2060
+ _context31.t0 = _context31["catch"](17);
2061
+ _iterator7.e(_context31.t0);
2062
+ case 32:
2063
+ _context31.prev = 32;
2064
+ _iterator7.f();
2065
+ return _context31.finish(32);
2066
+ case 35:
2067
+ console.log("[PaymentModule] \u6210\u529F\u91CD\u65B0\u52A0\u5165 ".concat(requeuedCount, " \u4E2A\u8BA2\u5355\u5230\u4EFB\u52A1\u961F\u5217"));
2068
+ this.logInfo('Successfully requeued unsynced orders', {
2069
+ requeuedCount: requeuedCount,
2070
+ totalFound: unsyncedOrders.length
2071
+ });
2072
+ return _context31.abrupt("return", requeuedCount);
2073
+ case 40:
2074
+ _context31.prev = 40;
2075
+ _context31.t1 = _context31["catch"](1);
2076
+ console.error('[PaymentModule] 重新排队未同步订单失败', _context31.t1);
2077
+ this.logError('recheckAndRequeueUnsyncedOrders failed', _context31.t1);
2078
+ return _context31.abrupt("return", 0);
2079
+ case 45:
2080
+ case "end":
2081
+ return _context31.stop();
2082
+ }
2083
+ }, _callee31, this, [[1, 40], [17, 29, 32, 35]]);
2084
+ }));
2085
+ function recheckAndRequeueUnsyncedOrders() {
2086
+ return _recheckAndRequeueUnsyncedOrders.apply(this, arguments);
2087
+ }
2088
+ return recheckAndRequeueUnsyncedOrders;
2089
+ }()
2090
+ /**
2091
+ * 手动执行支付同步队列
2092
+ * 外部可以调用此方法来触发支付同步任务的执行
2093
+ *
2094
+ * 注意:此方法只执行现有队列中的任务,不会检查未同步的订单。
2095
+ * 如果需要检查未同步订单,请先调用 recheckAndRequeueUnsyncedOrders()
2096
+ *
2097
+ * 使用示例:
2098
+ * ```typescript
2099
+ * // 1. 先检查并重新排队未同步订单,然后执行队列
2100
+ * const requeuedCount = await paymentModule.recheckAndRequeueUnsyncedOrders();
2101
+ * if (requeuedCount > 0) {
2102
+ * await paymentModule.runPaymentSyncQueue();
2103
+ * }
2104
+ *
2105
+ * // 2. 或者直接执行现有队列(不检查未同步订单)
2106
+ * await paymentModule.runPaymentSyncQueue();
2107
+ * ```
2108
+ */
2109
+ )
2110
+ }, {
2111
+ key: "runPaymentSyncQueue",
2112
+ value: (function () {
2113
+ var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2114
+ var _this3 = this;
2115
+ var queue;
2116
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2117
+ while (1) switch (_context32.prev = _context32.next) {
2118
+ case 0:
2119
+ this.logInfo('Starting runPaymentSyncQueue');
2120
+ _context32.prev = 1;
2121
+ if (this.app.tasksManager) {
2122
+ _context32.next = 6;
2123
+ break;
2124
+ }
2125
+ console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
2126
+ this.logWarning('TasksManager not initialized, cannot run sync queue');
2127
+ return _context32.abrupt("return");
2128
+ case 6:
2129
+ // 检查队列里有没有要跑的东西,没有就不 run 了
2130
+ queue = this.app.tasksManager.getTaskQueue({
2131
+ module: 'payment',
2132
+ queueId: 'payment_sync'
2133
+ });
2134
+ if (queue !== null && queue !== void 0 && queue.length) {
2135
+ _context32.next = 10;
2136
+ break;
2137
+ }
2138
+ console.log('[PaymentModule] 支付同步队列无内容,不执行');
2139
+ return _context32.abrupt("return");
2140
+ case 10:
2141
+ console.log('[PaymentModule] 开始执行支付同步队列');
2142
+ _context32.next = 13;
2143
+ return this.app.tasksManager.run({
2144
+ module: 'payment',
2145
+ queueId: 'payment_sync',
2146
+ callback: function callback() {
2147
+ console.log('[PaymentModule] 支付同步队列执行完成');
2148
+ if (_this3.logger) {
2149
+ _this3.logger.addLog({
2150
+ type: 'info',
2151
+ title: '[PaymentModule] Payment sync queue completed',
2152
+ metadata: {}
2153
+ });
2154
+ }
2155
+ }
2156
+ });
2157
+ case 13:
2158
+ this.logInfo('runPaymentSyncQueue completed successfully');
2159
+ _context32.next = 20;
2160
+ break;
2161
+ case 16:
2162
+ _context32.prev = 16;
2163
+ _context32.t0 = _context32["catch"](1);
2164
+ console.error('[PaymentModule] 执行支付同步队列失败', _context32.t0);
2165
+ this.logError('runPaymentSyncQueue failed', _context32.t0);
2166
+ // 不抛出错误,避免影响主流程
2167
+ case 20:
2168
+ case "end":
2169
+ return _context32.stop();
2170
+ }
2171
+ }, _callee32, this, [[1, 16]]);
2172
+ }));
2173
+ function runPaymentSyncQueue() {
2174
+ return _runPaymentSyncQueue.apply(this, arguments);
2175
+ }
2176
+ return runPaymentSyncQueue;
2177
+ }()
2178
+ /**
2179
+ * 重新将订单添加到同步队列
2180
+ * 用于处理因网络问题导致任务队列清空但订单未同步的情况
2181
+ *
2182
+ * @param order 要重新添加的订单
2183
+ * @returns Promise<boolean> 是否成功添加到队列
2184
+ */
2185
+ )
2186
+ }, {
2187
+ key: "reAddOrderToSyncQueue",
2188
+ value: (function () {
2189
+ var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
2190
+ var paymentData, existingQueue, taskId, taskExists;
2191
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2192
+ while (1) switch (_context33.prev = _context33.next) {
2193
+ case 0:
2194
+ _context33.prev = 0;
2195
+ // 构造支付数据
2196
+ paymentData = {
2197
+ payments: order.payment.map(function (payment) {
2198
+ return {
2199
+ uuid: payment.uuid,
2200
+ amount: payment.amount,
2201
+ code: payment.code,
2202
+ id: payment.id,
2203
+ name: payment.name,
2204
+ type: payment.type,
2205
+ voucher_id: payment.voucher_id,
2206
+ metadata: payment.metadata,
2207
+ rounding_amount: payment.rounding_amount,
2208
+ service_charge: payment.service_charge
2209
+ };
2210
+ }),
2211
+ payment_status: order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid'
2212
+ }; // 检查是否已经在队列中,避免重复添加
2213
+ existingQueue = this.app.tasksManager.getTaskQueue({
2214
+ module: 'payment',
2215
+ queueId: 'payment_sync'
2216
+ });
2217
+ taskId = "payment_".concat(order.uuid);
2218
+ taskExists = existingQueue === null || existingQueue === void 0 ? void 0 : existingQueue.some(function (task) {
2219
+ return task.id === taskId;
2220
+ });
2221
+ if (!taskExists) {
2222
+ _context33.next = 8;
2223
+ break;
2224
+ }
2225
+ console.log("[PaymentModule] \u4EFB\u52A1 ".concat(taskId, " \u5DF2\u5B58\u5728\u4E8E\u961F\u5217\u4E2D\uFF0C\u8DF3\u8FC7\u91CD\u590D\u6DFB\u52A0"));
2226
+ return _context33.abrupt("return", false);
2227
+ case 8:
2228
+ _context33.next = 10;
2229
+ return this.addToSyncQueue(order, paymentData);
2230
+ case 10:
2231
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u91CD\u65B0\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
2232
+ this.logInfo('Order re-added to sync queue', {
2233
+ orderUuid: order.uuid,
2234
+ orderId: order.order_id,
2235
+ paymentStatus: order.payment_status,
2236
+ unsyncedPayments: order.payment.filter(function (p) {
2237
+ return !p.isSynced;
2238
+ }).length
2239
+ });
2240
+ return _context33.abrupt("return", true);
2241
+ case 15:
2242
+ _context33.prev = 15;
2243
+ _context33.t0 = _context33["catch"](0);
2244
+ console.error("[PaymentModule] \u91CD\u65B0\u6DFB\u52A0\u8BA2\u5355 ".concat(order.uuid, " \u5230\u540C\u6B65\u961F\u5217\u5931\u8D25"), _context33.t0);
2245
+ this.logError('Failed to re-add order to sync queue', _context33.t0, {
2246
+ orderUuid: order.uuid,
2247
+ orderId: order.order_id
2248
+ });
2249
+ return _context33.abrupt("return", false);
2250
+ case 20:
2251
+ case "end":
2252
+ return _context33.stop();
2253
+ }
2254
+ }, _callee33, this, [[0, 15]]);
2255
+ }));
2256
+ function reAddOrderToSyncQueue(_x32) {
2257
+ return _reAddOrderToSyncQueue.apply(this, arguments);
2258
+ }
2259
+ return reAddOrderToSyncQueue;
2260
+ }() // === 新的 API 方法实现 ===
2261
+ /**
2262
+ * 删除支付项(新方法)
2263
+ */
2264
+ )
2265
+ }, {
2266
+ key: "deletePaymentItemAsync",
2267
+ value: function () {
2268
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderUuid, paymentUuid) {
2269
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2270
+ while (1) switch (_context34.prev = _context34.next) {
2271
+ case 0:
2272
+ console.warn('[PaymentModule] deletePaymentItemAsync 暂时使用 deletePaymentAsync 实现');
2273
+ return _context34.abrupt("return", this.deletePaymentAsync(orderUuid, paymentUuid));
2274
+ case 2:
2275
+ case "end":
2276
+ return _context34.stop();
2277
+ }
2278
+ }, _callee34, this);
2279
+ }));
2280
+ function deletePaymentItemAsync(_x33, _x34) {
2281
+ return _deletePaymentItemAsync.apply(this, arguments);
2282
+ }
2283
+ return deletePaymentItemAsync;
2284
+ }()
2285
+ /**
2286
+ * 更新支付项(新方法)
2287
+ */
2288
+ }, {
2289
+ key: "updatePaymentItemAsync",
2290
+ value: (function () {
2291
+ var _updatePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderUuid, paymentUuid, params) {
2292
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2293
+ while (1) switch (_context35.prev = _context35.next) {
2294
+ case 0:
2295
+ console.warn('[PaymentModule] updatePaymentItemAsync 暂时使用 updatePaymentAsync 实现');
2296
+ return _context35.abrupt("return", this.updatePaymentAsync(orderUuid, paymentUuid, params));
2297
+ case 2:
2298
+ case "end":
2299
+ return _context35.stop();
2300
+ }
2301
+ }, _callee35, this);
2302
+ }));
2303
+ function updatePaymentItemAsync(_x35, _x36, _x37) {
2304
+ return _updatePaymentItemAsync.apply(this, arguments);
2305
+ }
2306
+ return updatePaymentItemAsync;
2307
+ }()
2308
+ /**
2309
+ * 获取订单剩余待付金额(新方法)
2310
+ */
2311
+ )
2312
+ }, {
2313
+ key: "getRemainingAmountAsync",
2314
+ value: (function () {
2315
+ var _getRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(orderUuid) {
2316
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2317
+ while (1) switch (_context36.prev = _context36.next) {
2318
+ case 0:
2319
+ console.warn('[PaymentModule] getRemainingAmountAsync 暂时使用 getRemainingOrderAmountAsync 实现');
2320
+ return _context36.abrupt("return", this.getRemainingOrderAmountAsync(orderUuid));
2321
+ case 2:
2322
+ case "end":
2323
+ return _context36.stop();
2324
+ }
2325
+ }, _callee36, this);
2326
+ }));
2327
+ function getRemainingAmountAsync(_x38) {
2328
+ return _getRemainingAmountAsync.apply(this, arguments);
2329
+ }
2330
+ return getRemainingAmountAsync;
2331
+ }()
2332
+ /**
2333
+ * 获取订单剩余待付金额(基于用户输入的金额)(新方法)
2334
+ */
2335
+ )
2336
+ }, {
2337
+ key: "getRemainingAmountWithInputAsync",
2338
+ value: (function () {
2339
+ var _getRemainingAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(inputAmount, orderUuid) {
2340
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2341
+ while (1) switch (_context37.prev = _context37.next) {
2342
+ case 0:
2343
+ console.warn('[PaymentModule] getRemainingAmountWithInputAsync 暂时使用 getRemainingOrderAmountWithInputAsync 实现');
2344
+ return _context37.abrupt("return", this.getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid));
2345
+ case 2:
2346
+ case "end":
2347
+ return _context37.stop();
2348
+ }
2349
+ }, _callee37, this);
2350
+ }));
2351
+ function getRemainingAmountWithInputAsync(_x39, _x40) {
2352
+ return _getRemainingAmountWithInputAsync.apply(this, arguments);
2353
+ }
2354
+ return getRemainingAmountWithInputAsync;
2355
+ }()
2356
+ /**
2357
+ * 提交支付(新方法)
2358
+ */
2359
+ )
2360
+ }, {
2361
+ key: "submitPaymentAsync",
2362
+ value: (function () {
2363
+ var _submitPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderUuid) {
2364
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2365
+ while (1) switch (_context38.prev = _context38.next) {
2366
+ case 0:
2367
+ console.warn('[PaymentModule] submitPaymentAsync 暂时使用 submitPayAsync 实现');
2368
+ return _context38.abrupt("return", this.submitPayAsync(orderUuid));
2369
+ case 2:
2370
+ case "end":
2371
+ return _context38.stop();
2372
+ }
2373
+ }, _callee38, this);
2374
+ }));
2375
+ function submitPaymentAsync(_x41) {
2376
+ return _submitPaymentAsync.apply(this, arguments);
2377
+ }
2378
+ return submitPaymentAsync;
2379
+ }())
2380
+ }], [{
2381
+ key: "syncPaymentTask",
2382
+ value: (function () {
2383
+ var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(payload) {
2384
+ 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;
2385
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2386
+ while (1) switch (_context39.prev = _context39.next) {
2387
+ case 0:
2388
+ _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;
2389
+ console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
2390
+
2391
+ // 生成request_unique: 年月日时分秒毫秒+4位随机数
2392
+ paymentData.request_unique = generateRequestUniqueId();
2393
+
2394
+ // 从全局获取必要的实例
2395
+ app = window.app;
2396
+ logger = app === null || app === void 0 ? void 0 : app.logger; // 记录开始日志
2397
+ if (logger) {
2398
+ logger.addLog({
2399
+ type: 'info',
2400
+ title: '[PaymentModule] Starting syncPaymentTask',
2401
+ metadata: {
2402
+ orderUuid: orderUuid,
2403
+ orderId: orderId,
2404
+ paymentDataKeys: Object.keys(paymentData)
2405
+ }
2406
+ });
2407
+ }
2408
+ if (app) {
2409
+ _context39.next = 8;
2410
+ break;
2411
+ }
2412
+ throw new Error('App 实例未找到');
2413
+ case 8:
2414
+ request = app.request;
2415
+ if (request) {
2416
+ _context39.next = 11;
2417
+ break;
2418
+ }
2419
+ throw new Error('Request 插件未找到');
2420
+ case 11:
2421
+ dbManager = app.dbManager;
2422
+ if (dbManager) {
2423
+ _context39.next = 14;
2424
+ break;
2425
+ }
2426
+ throw new Error('DBManager 未找到');
2427
+ case 14:
2428
+ _context39.prev = 14;
2429
+ _context39.next = 17;
2430
+ return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
2431
+ noToast: true
2432
+ });
2433
+ case 17:
2434
+ requestRes = _context39.sent;
2435
+ if (!(requestRes.status === true)) {
2436
+ _context39.next = 35;
2437
+ break;
2438
+ }
2439
+ _context39.next = 21;
2440
+ return dbManager.get('order', orderUuid);
2441
+ case 21:
2442
+ order = _context39.sent;
2443
+ if (!order) {
2444
+ _context39.next = 27;
2445
+ break;
2446
+ }
2447
+ order.payment.forEach(function (payment) {
2448
+ payment.isSynced = true;
2449
+ // 清除之前的错误状态
2450
+ delete payment.syncError;
2451
+ });
2452
+ _context39.next = 26;
2453
+ return dbManager.update('order', order);
2454
+ case 26:
2455
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
2456
+ case 27:
2457
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
2458
+ _context39.next = 30;
2459
+ return core.effects.emit('payment:onPaymentSyncSuccess', {
2460
+ orderUuid: orderUuid,
2461
+ orderId: orderId,
2462
+ timestamp: Date.now()
2463
+ });
2464
+ case 30:
2465
+ console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u6210\u529F"));
2466
+
2467
+ // 记录成功日志
2468
+ if (logger) {
2469
+ logger.addLog({
2470
+ type: 'info',
2471
+ title: '[PaymentModule] syncPaymentTask completed successfully',
2472
+ metadata: {
2473
+ orderUuid: orderUuid,
2474
+ orderId: orderId
2475
+ }
2476
+ });
2477
+ }
2478
+ return _context39.abrupt("return", {
2479
+ status: 'success',
2480
+ orderUuid: orderUuid,
2481
+ orderId: orderId
2482
+ });
2483
+ case 35:
2484
+ // 接口返回失败,视为业务错误处理
2485
+ console.log("[PaymentModule] \u63A5\u53E3\u8FD4\u56DE\u5931\u8D25\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25"));
2486
+
2487
+ // 模拟业务错误,抛出一个包含响应信息的错误
2488
+ businessError = new Error(requestRes.message || '接口返回失败');
2489
+ businessError.response = {
2490
+ status: 200
2491
+ }; // HTTP 状态码是 200,但业务失败
2492
+ businessError.isBusinessError = true;
2493
+ businessError.responseData = requestRes;
2494
+ throw businessError;
2495
+ case 41:
2496
+ _context39.next = 80;
2497
+ break;
2498
+ case 43:
2499
+ _context39.prev = 43;
2500
+ _context39.t0 = _context39["catch"](14);
2501
+ console.error('[PaymentModule] 后台同步失败:', _context39.t0);
2502
+
2503
+ // 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
2504
+ isNetworkError = !_context39.t0.response && !_context39.t0.status && (_context39.t0.code === 'NETWORK_ERROR' || _context39.t0.code === 'ERR_NETWORK' || _context39.t0.code === 'ECONNREFUSED' || _context39.t0.code === 'ENOTFOUND' || _context39.t0.code === 'ETIMEDOUT' || ((_error$message = _context39.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context39.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context39.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
2505
+ if (!isNetworkError) {
2506
+ _context39.next = 53;
2507
+ break;
2508
+ }
2509
+ // 网络错误:重试
2510
+ console.log("[PaymentModule] \u7F51\u7EDC\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u5C06\u91CD\u8BD5\u540C\u6B65"));
2511
+
2512
+ // 记录网络错误日志
2513
+ if (logger) {
2514
+ logger.addLog({
2515
+ type: 'warning',
2516
+ title: '[PaymentModule] syncPaymentTask network error - will retry',
2517
+ metadata: {
2518
+ orderUuid: orderUuid,
2519
+ orderId: orderId,
2520
+ errorCode: _context39.t0.code,
2521
+ errorMessage: _context39.t0.message
2522
+ }
2523
+ });
2524
+ }
2525
+ throw _context39.t0;
2526
+ case 53:
2527
+ // 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
2528
+ console.log("[PaymentModule] \u4E1A\u52A1\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25\uFF0C\u901A\u77E5\u524D\u7AEF"));
2529
+ _context39.prev = 54;
2530
+ if (!(core && core.effects)) {
2531
+ _context39.next = 63;
2532
+ break;
2533
+ }
2534
+ // 通过 effects 通知前端同步错误
2535
+ errorData = {
2536
+ orderUuid: orderUuid,
2537
+ orderId: orderId,
2538
+ error: _context39.t0.message || '业务错误',
2539
+ errorCode: _context39.t0.code,
2540
+ statusCode: ((_error$response = _context39.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context39.t0.status,
2541
+ timestamp: Date.now()
2542
+ }; // 如果是业务错误,添加响应数据
2543
+ if (_context39.t0.isBusinessError && _context39.t0.responseData) {
2544
+ errorData.error = _context39.t0.responseData.message || _context39.t0.message || '接口返回失败';
2545
+ // 可以添加更多响应数据
2546
+ errorData.responseData = _context39.t0.responseData;
2547
+ }
2548
+ _context39.next = 60;
2549
+ return core.effects.emit('payment:onPaymentSyncError', errorData);
2550
+ case 60:
2551
+ console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
2552
+ _context39.next = 64;
2553
+ break;
2554
+ case 63:
2555
+ console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
2556
+ case 64:
2557
+ // 记录业务错误日志
2558
+ if (logger) {
2559
+ logger.addLog({
2560
+ type: 'error',
2561
+ title: '[PaymentModule] syncPaymentTask business error',
2562
+ metadata: {
2563
+ orderUuid: orderUuid,
2564
+ orderId: orderId,
2565
+ errorCode: _context39.t0.code,
2566
+ errorMessage: _context39.t0.message,
2567
+ statusCode: ((_error$response2 = _context39.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context39.t0.status,
2568
+ isBusinessError: _context39.t0.isBusinessError
2569
+ }
2570
+ });
2571
+ }
2572
+ _context39.next = 71;
2573
+ break;
2574
+ case 67:
2575
+ _context39.prev = 67;
2576
+ _context39.t1 = _context39["catch"](54);
2577
+ console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context39.t1);
2578
+
2579
+ // 记录通知错误日志
2580
+ if (logger) {
2581
+ logger.addLog({
2582
+ type: 'error',
2583
+ title: '[PaymentModule] Failed to notify frontend of sync error',
2584
+ metadata: {
2585
+ orderUuid: orderUuid,
2586
+ orderId: orderId,
2587
+ notifyError: _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1)
2588
+ }
2589
+ });
2590
+ }
2591
+ case 71:
2592
+ _context39.next = 73;
2593
+ return dbManager.get('order', orderUuid);
2594
+ case 73:
2595
+ _order2 = _context39.sent;
2596
+ if (!_order2) {
2597
+ _context39.next = 79;
2598
+ break;
2599
+ }
2600
+ _order2.payment.forEach(function (payment) {
2601
+ payment.isSynced = true;
2602
+ });
2603
+ _context39.next = 78;
2604
+ return dbManager.update('order', _order2);
2605
+ case 78:
2606
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
2607
+ case 79:
2608
+ return _context39.abrupt("return", {
2609
+ status: 'completed_with_error',
2610
+ orderUuid: orderUuid,
2611
+ orderId: orderId,
2612
+ error: _context39.t0.message || '业务错误',
2613
+ statusCode: ((_error$response3 = _context39.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context39.t0.status
2614
+ });
2615
+ case 80:
2616
+ case "end":
2617
+ return _context39.stop();
2618
+ }
2619
+ }, _callee39, null, [[14, 43], [54, 67]]);
2620
+ }));
2621
+ function syncPaymentTask(_x42) {
2622
+ return _syncPaymentTask.apply(this, arguments);
2623
+ }
2624
+ return syncPaymentTask;
2625
+ }())
210
2626
  }]);
211
2627
  return PaymentModule;
212
2628
  }(BaseModule);