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