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