@pisell/pisellos 0.0.479 → 0.0.481

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/core/index.d.ts +3 -2
  2. package/dist/core/index.js +7 -0
  3. package/dist/effects/index.d.ts +2 -2
  4. package/dist/effects/index.js +34 -81
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
  7. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  8. package/dist/model/strategy/adapter/walletPass/utils.js +111 -72
  9. package/dist/modules/Customer/index.js +1 -1
  10. package/dist/modules/Discount/index.d.ts +6 -2
  11. package/dist/modules/Discount/index.js +14 -8
  12. package/dist/modules/Order/index.d.ts +1 -1
  13. package/dist/modules/Order/index.js +18 -13
  14. package/dist/modules/Payment/index.d.ts +4 -0
  15. package/dist/modules/Payment/index.js +774 -649
  16. package/dist/modules/Payment/walletpass.js +44 -17
  17. package/dist/modules/Product/index.d.ts +1 -1
  18. package/dist/modules/Product/types.d.ts +2 -0
  19. package/dist/modules/ProductList/index.d.ts +3 -0
  20. package/dist/modules/ProductList/index.js +9 -7
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +37 -31
  23. package/dist/modules/Rules/types.d.ts +2 -2
  24. package/dist/modules/Schedule/index.d.ts +9 -0
  25. package/dist/modules/Schedule/index.js +15 -2
  26. package/dist/plugins/app-types/app/app.d.ts +1 -0
  27. package/dist/plugins/request.d.ts +2 -0
  28. package/dist/server/index.d.ts +107 -2
  29. package/dist/server/index.js +1507 -279
  30. package/dist/server/modules/index.d.ts +6 -0
  31. package/dist/server/modules/index.js +7 -0
  32. package/dist/server/modules/menu/index.d.ts +19 -0
  33. package/dist/server/modules/menu/index.js +221 -71
  34. package/dist/server/modules/order/index.d.ts +87 -0
  35. package/dist/server/modules/order/index.js +916 -0
  36. package/dist/server/modules/order/types.d.ts +530 -0
  37. package/dist/server/modules/order/types.js +141 -0
  38. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  39. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  40. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  41. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  42. package/dist/server/modules/products/index.d.ts +117 -5
  43. package/dist/server/modules/products/index.js +1450 -240
  44. package/dist/server/modules/products/types.d.ts +25 -1
  45. package/dist/server/modules/products/types.js +3 -0
  46. package/dist/server/modules/resource/index.d.ts +86 -0
  47. package/dist/server/modules/resource/index.js +1128 -0
  48. package/dist/server/modules/resource/types.d.ts +121 -0
  49. package/dist/server/modules/resource/types.js +47 -0
  50. package/dist/server/modules/schedule/index.d.ts +19 -0
  51. package/dist/server/modules/schedule/index.js +229 -68
  52. package/dist/server/utils/product.d.ts +5 -0
  53. package/dist/server/utils/product.js +71 -31
  54. package/dist/solution/BookingTicket/index.d.ts +10 -2
  55. package/dist/solution/BookingTicket/index.js +41 -28
  56. package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
  57. package/dist/solution/Checkout/index.d.ts +1 -0
  58. package/dist/solution/Checkout/index.js +286 -188
  59. package/dist/solution/Checkout/utils/index.d.ts +2 -1
  60. package/dist/solution/Checkout/utils/index.js +6 -4
  61. package/dist/solution/RegisterAndLogin/config.js +340 -1
  62. package/dist/solution/Sales/index.d.ts +96 -0
  63. package/dist/solution/Sales/index.js +566 -0
  64. package/dist/solution/Sales/types.d.ts +67 -0
  65. package/dist/solution/Sales/types.js +26 -0
  66. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/index.js +35 -22
  68. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  69. package/dist/solution/ShopDiscount/utils.d.ts +9 -0
  70. package/dist/solution/ShopDiscount/utils.js +21 -27
  71. package/dist/solution/index.d.ts +2 -1
  72. package/dist/solution/index.js +2 -1
  73. package/dist/types/index.d.ts +5 -0
  74. package/lib/core/index.d.ts +3 -2
  75. package/lib/core/index.js +4 -0
  76. package/lib/effects/index.d.ts +2 -2
  77. package/lib/effects/index.js +22 -31
  78. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  79. package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
  80. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  81. package/lib/model/strategy/adapter/walletPass/utils.js +115 -48
  82. package/lib/modules/Customer/index.js +1 -1
  83. package/lib/modules/Discount/index.d.ts +6 -2
  84. package/lib/modules/Discount/index.js +3 -1
  85. package/lib/modules/Order/index.d.ts +1 -1
  86. package/lib/modules/Order/index.js +20 -18
  87. package/lib/modules/Payment/index.d.ts +4 -0
  88. package/lib/modules/Payment/index.js +134 -66
  89. package/lib/modules/Payment/walletpass.js +23 -4
  90. package/lib/modules/Product/index.d.ts +1 -1
  91. package/lib/modules/Product/types.d.ts +2 -0
  92. package/lib/modules/ProductList/index.d.ts +3 -0
  93. package/lib/modules/ProductList/index.js +2 -2
  94. package/lib/modules/Rules/index.d.ts +2 -2
  95. package/lib/modules/Rules/index.js +69 -73
  96. package/lib/modules/Rules/types.d.ts +2 -2
  97. package/lib/modules/Schedule/index.d.ts +9 -0
  98. package/lib/modules/Schedule/index.js +11 -0
  99. package/lib/plugins/app-types/app/app.d.ts +1 -0
  100. package/lib/plugins/request.d.ts +2 -0
  101. package/lib/server/index.d.ts +107 -2
  102. package/lib/server/index.js +773 -51
  103. package/lib/server/modules/index.d.ts +6 -0
  104. package/lib/server/modules/index.js +16 -2
  105. package/lib/server/modules/menu/index.d.ts +19 -0
  106. package/lib/server/modules/menu/index.js +121 -2
  107. package/lib/server/modules/order/index.d.ts +87 -0
  108. package/lib/server/modules/order/index.js +543 -0
  109. package/lib/server/modules/order/types.d.ts +530 -0
  110. package/lib/server/modules/order/types.js +34 -0
  111. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  112. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  113. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  114. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  115. package/lib/server/modules/products/index.d.ts +117 -5
  116. package/lib/server/modules/products/index.js +799 -62
  117. package/lib/server/modules/products/types.d.ts +25 -1
  118. package/lib/server/modules/products/types.js +1 -0
  119. package/lib/server/modules/resource/index.d.ts +86 -0
  120. package/lib/server/modules/resource/index.js +557 -0
  121. package/lib/server/modules/resource/types.d.ts +121 -0
  122. package/lib/server/modules/resource/types.js +35 -0
  123. package/lib/server/modules/schedule/index.d.ts +19 -0
  124. package/lib/server/modules/schedule/index.js +141 -12
  125. package/lib/server/utils/product.d.ts +5 -0
  126. package/lib/server/utils/product.js +56 -27
  127. package/lib/solution/BookingTicket/index.d.ts +10 -2
  128. package/lib/solution/BookingTicket/index.js +10 -2
  129. package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
  130. package/lib/solution/Checkout/index.d.ts +1 -0
  131. package/lib/solution/Checkout/index.js +399 -331
  132. package/lib/solution/Checkout/utils/index.d.ts +2 -1
  133. package/lib/solution/Checkout/utils/index.js +6 -4
  134. package/lib/solution/RegisterAndLogin/config.js +266 -1
  135. package/lib/solution/Sales/index.d.ts +96 -0
  136. package/lib/solution/Sales/index.js +416 -0
  137. package/lib/solution/Sales/types.d.ts +67 -0
  138. package/lib/solution/Sales/types.js +35 -0
  139. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  140. package/lib/solution/ShopDiscount/index.js +14 -6
  141. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  142. package/lib/solution/ShopDiscount/utils.d.ts +9 -0
  143. package/lib/solution/ShopDiscount/utils.js +6 -10
  144. package/lib/solution/index.d.ts +2 -1
  145. package/lib/solution/index.js +4 -2
  146. package/lib/types/index.d.ts +5 -0
  147. package/package.json +1 -1
@@ -1,12 +1,12 @@
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 _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; }
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; }
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
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
8
3
  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); } }
9
4
  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); }); }; }
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; }
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 _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; } } }; }
8
+ 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); }
9
+ 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; }
10
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -102,6 +102,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
102
102
  // IndexDBManager 实例
103
103
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
104
104
  // LoggerManager 实例
105
+ _defineProperty(_assertThisInitialized(_this), "voucherUpdateLockByOrderUuid", new Map());
105
106
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
106
107
  // 支付方式实例
107
108
  _defineProperty(_assertThisInitialized(_this), "cash", void 0);
@@ -113,6 +114,50 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
113
114
  return _this;
114
115
  }
115
116
  _createClass(PaymentModule, [{
117
+ key: "runVoucherUpdateLocked",
118
+ value: function runVoucherUpdateLocked(orderUuid, task) {
119
+ var _this2 = this;
120
+ var previous = this.voucherUpdateLockByOrderUuid.get(orderUuid) || Promise.resolve();
121
+ var next = previous.catch(function () {
122
+ return undefined;
123
+ }).then(task).finally(function () {
124
+ if (_this2.voucherUpdateLockByOrderUuid.get(orderUuid) === next) {
125
+ _this2.voucherUpdateLockByOrderUuid.delete(orderUuid);
126
+ }
127
+ });
128
+ this.voucherUpdateLockByOrderUuid.set(orderUuid, next);
129
+ return next;
130
+ }
131
+ }, {
132
+ key: "normalizeVoucherPaymentItems",
133
+ value: function normalizeVoucherPaymentItems(voucherPaymentItems) {
134
+ var normalized = new Map();
135
+ var _iterator = _createForOfIteratorHelper(voucherPaymentItems || []),
136
+ _step;
137
+ try {
138
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
139
+ var item = _step.value;
140
+ if (!(item !== null && item !== void 0 && item.voucher_id)) {
141
+ throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
142
+ }
143
+ var orderPaymentType = item.order_payment_type || 'normal';
144
+ var key = "".concat(item.voucher_id, "|").concat(orderPaymentType);
145
+ normalized.set(key, _objectSpread(_objectSpread({}, item), {}, {
146
+ order_payment_type: orderPaymentType
147
+ }));
148
+ }
149
+ } catch (err) {
150
+ _iterator.e(err);
151
+ } finally {
152
+ _iterator.f();
153
+ }
154
+ return {
155
+ items: Array.from(normalized.values()),
156
+ originalCount: (voucherPaymentItems === null || voucherPaymentItems === void 0 ? void 0 : voucherPaymentItems.length) || 0,
157
+ normalizedCount: normalized.size
158
+ };
159
+ }
160
+ }, {
116
161
  key: "initialize",
117
162
  value: function () {
118
163
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
@@ -248,7 +293,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
248
293
  }, {
249
294
  key: "registerNetworkHandlers",
250
295
  value: function registerNetworkHandlers() {
251
- var _this2 = this;
296
+ var _this3 = this;
252
297
  var network = this.app.plugins.get('network');
253
298
  this.logInfo('Registering network status listener');
254
299
  network === null || network === void 0 || network.addListener('networkStatusChange', /*#__PURE__*/function () {
@@ -257,12 +302,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
257
302
  while (1) switch (_context2.prev = _context2.next) {
258
303
  case 0:
259
304
  console.log('网络状态:', status.connected);
260
- _this2.logInfo('Network status changed', {
305
+ _this3.logInfo('Network status changed', {
261
306
  connected: status.connected,
262
307
  previousStatus: status.previousStatus
263
308
  });
264
309
  if (status.connected) {
265
- _this2.logInfo('Network reconnected');
310
+ _this3.logInfo('Network reconnected');
266
311
  // 网络恢复时的处理逻辑可以在这里添加
267
312
  }
268
313
  case 3:
@@ -276,105 +321,142 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
276
321
  };
277
322
  }());
278
323
  }
279
-
324
+ }, {
325
+ key: "filterPayMethods",
326
+ value: function () {
327
+ var _filterPayMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payMethods) {
328
+ var walletPassMethod;
329
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
330
+ while (1) switch (_context3.prev = _context3.next) {
331
+ case 0:
332
+ // 1. 筛选 status === 1 && disable === 0的数据
333
+ // 2. 检查列表里是否有 code=WALLET_PASS的数据,如果没有,则列表里如果有 PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 则删除他们
334
+ // 如果有 code = WALLET_PASS的数据,则列表里PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 的channel_application 指向 WALLET_PASS 的 channel_application
335
+ payMethods = payMethods.filter(function (method) {
336
+ return method.status === 1 && method.disable === 0;
337
+ });
338
+ walletPassMethod = payMethods.find(function (method) {
339
+ return method.code === 'WALLET_PASS';
340
+ });
341
+ if (walletPassMethod) {
342
+ payMethods.forEach(function (method) {
343
+ if (method.code === 'PRODUCTVOUCHER' || method.code === 'GIFTCARD' || method.code === 'POINTCARD') {
344
+ method.channel_application = walletPassMethod.channel_application;
345
+ }
346
+ });
347
+ } else {
348
+ payMethods = payMethods.filter(function (method) {
349
+ return method.code !== 'PRODUCTVOUCHER' && method.code !== 'GIFTCARD' && method.code !== 'POINTCARD';
350
+ });
351
+ }
352
+ return _context3.abrupt("return", payMethods);
353
+ case 4:
354
+ case "end":
355
+ return _context3.stop();
356
+ }
357
+ }, _callee3);
358
+ }));
359
+ function filterPayMethods(_x4) {
360
+ return _filterPayMethods.apply(this, arguments);
361
+ }
362
+ return filterPayMethods;
363
+ }()
280
364
  /**
281
365
  * 获取支付方式列表
282
366
  */
283
367
  }, {
284
368
  key: "getPayMethodListAsync",
285
369
  value: (function () {
286
- var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
287
- var cachedMethods, hasCache, response, payMethods, _iterator, _step, method;
288
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
289
- while (1) switch (_context3.prev = _context3.next) {
370
+ var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
371
+ var cachedMethods, hasCache, response, payMethods, _iterator2, _step2, method;
372
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
373
+ while (1) switch (_context4.prev = _context4.next) {
290
374
  case 0:
291
375
  this.logInfo('Starting getPayMethodListAsync');
292
- _context3.prev = 1;
376
+ _context4.prev = 1;
293
377
  // 先尝试从 IndexDB 获取缓存
294
378
  cachedMethods = [];
295
- _context3.prev = 3;
296
- _context3.next = 6;
379
+ _context4.prev = 3;
380
+ _context4.next = 6;
297
381
  return this.dbManager.getAll('pay_method');
298
382
  case 6:
299
- cachedMethods = _context3.sent;
300
- _context3.next = 12;
383
+ cachedMethods = _context4.sent;
384
+ _context4.next = 12;
301
385
  break;
302
386
  case 9:
303
- _context3.prev = 9;
304
- _context3.t0 = _context3["catch"](3);
387
+ _context4.prev = 9;
388
+ _context4.t0 = _context4["catch"](3);
305
389
  console.warn('[PaymentModule] pay_method 表不存在,将从服务器获取数据');
306
390
  case 12:
307
391
  // 如果有缓存,先返回缓存数据
308
392
  hasCache = cachedMethods.length > 0;
309
393
  if (!hasCache) {
310
- _context3.next = 16;
394
+ _context4.next = 16;
311
395
  break;
312
396
  }
313
397
  // 后台异步获取最新数据
314
398
  this.refreshPaymentMethodsInBackground(cachedMethods);
315
- return _context3.abrupt("return", cachedMethods);
399
+ return _context4.abrupt("return", cachedMethods);
316
400
  case 16:
317
- _context3.next = 18;
318
- return this.request.get('/pay/custom-payment/available', {
319
- channel: 'pos'
320
- });
401
+ _context4.next = 18;
402
+ return this.request.get('/pay/custom-payment/all');
321
403
  case 18:
322
- response = _context3.sent;
404
+ response = _context4.sent;
405
+ response.data = this.filterPayMethods(response.data);
323
406
  payMethods = response.data || []; // 尝试缓存到 IndexDB
324
- _context3.prev = 20;
325
- _iterator = _createForOfIteratorHelper(payMethods);
326
- _context3.prev = 22;
327
- _iterator.s();
328
- case 24:
329
- if ((_step = _iterator.n()).done) {
330
- _context3.next = 30;
407
+ _context4.prev = 21;
408
+ _iterator2 = _createForOfIteratorHelper(payMethods);
409
+ _context4.prev = 23;
410
+ _iterator2.s();
411
+ case 25:
412
+ if ((_step2 = _iterator2.n()).done) {
413
+ _context4.next = 31;
331
414
  break;
332
415
  }
333
- method = _step.value;
334
- _context3.next = 28;
416
+ method = _step2.value;
417
+ _context4.next = 29;
335
418
  return this.dbManager.update('pay_method', method);
336
- case 28:
337
- _context3.next = 24;
419
+ case 29:
420
+ _context4.next = 25;
338
421
  break;
339
- case 30:
340
- _context3.next = 35;
422
+ case 31:
423
+ _context4.next = 36;
341
424
  break;
342
- case 32:
343
- _context3.prev = 32;
344
- _context3.t1 = _context3["catch"](22);
345
- _iterator.e(_context3.t1);
346
- case 35:
347
- _context3.prev = 35;
348
- _iterator.f();
349
- return _context3.finish(35);
350
- case 38:
351
- _context3.next = 43;
425
+ case 33:
426
+ _context4.prev = 33;
427
+ _context4.t1 = _context4["catch"](23);
428
+ _iterator2.e(_context4.t1);
429
+ case 36:
430
+ _context4.prev = 36;
431
+ _iterator2.f();
432
+ return _context4.finish(36);
433
+ case 39:
434
+ _context4.next = 44;
352
435
  break;
353
- case 40:
354
- _context3.prev = 40;
355
- _context3.t2 = _context3["catch"](20);
436
+ case 41:
437
+ _context4.prev = 41;
438
+ _context4.t2 = _context4["catch"](21);
356
439
  console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
357
- case 43:
358
- _context3.next = 45;
440
+ case 44:
441
+ _context4.next = 46;
359
442
  return this.core.effects.emit("".concat(this.name, ":onPaymentMethodsLoaded"), payMethods);
360
- case 45:
443
+ case 46:
361
444
  this.logInfo('getPayMethodListAsync completed successfully', {
362
- methodCount: payMethods.length,
363
- hasCache: cachedMethods.length > 0
445
+ payMethods: payMethods
364
446
  });
365
- return _context3.abrupt("return", payMethods);
366
- case 49:
367
- _context3.prev = 49;
368
- _context3.t3 = _context3["catch"](1);
369
- console.error('[PaymentModule] 获取支付方式列表失败', _context3.t3);
370
- this.logError('getPayMethodListAsync failed', _context3.t3);
447
+ return _context4.abrupt("return", payMethods);
448
+ case 50:
449
+ _context4.prev = 50;
450
+ _context4.t3 = _context4["catch"](1);
451
+ console.error('[PaymentModule] 获取支付方式列表失败', _context4.t3);
452
+ this.logError('getPayMethodListAsync failed', _context4.t3);
371
453
  // 如果所有操作都失败,返回空数组
372
- return _context3.abrupt("return", []);
373
- case 54:
454
+ return _context4.abrupt("return", []);
455
+ case 55:
374
456
  case "end":
375
- return _context3.stop();
457
+ return _context4.stop();
376
458
  }
377
- }, _callee3, this, [[1, 49], [3, 9], [20, 40], [22, 32, 35, 38]]);
459
+ }, _callee4, this, [[1, 50], [3, 9], [21, 41], [23, 33, 36, 39]]);
378
460
  }));
379
461
  function getPayMethodListAsync() {
380
462
  return _getPayMethodListAsync.apply(this, arguments);
@@ -388,28 +470,27 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
388
470
  }, {
389
471
  key: "refreshPaymentMethodsInBackground",
390
472
  value: (function () {
391
- var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cachedMethods) {
392
- var response, newPayMethods, hasChanges, _iterator2, _step2, method, _iterator3, _step3, _method, eventData;
393
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
394
- while (1) switch (_context4.prev = _context4.next) {
473
+ var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(cachedMethods) {
474
+ var response, newPayMethods, hasChanges, _iterator3, _step3, method, _iterator4, _step4, _method, eventData;
475
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
476
+ while (1) switch (_context5.prev = _context5.next) {
395
477
  case 0:
396
478
  this.logInfo('Starting refreshPaymentMethodsInBackground', {
397
479
  cachedMethodsCount: cachedMethods.length
398
480
  });
399
- _context4.prev = 1;
481
+ _context5.prev = 1;
400
482
  console.log('[PaymentModule] 后台刷新支付方式列表...');
401
483
 
402
484
  // 从服务器获取最新数据
403
- _context4.next = 5;
404
- return this.request.get('/pay/custom-payment/available', {
405
- channel: 'pos'
406
- });
485
+ _context5.next = 5;
486
+ return this.request.get('/pay/custom-payment/all');
407
487
  case 5:
408
- response = _context4.sent;
488
+ response = _context5.sent;
489
+ response.data = this.filterPayMethods(response.data);
409
490
  newPayMethods = response.data || []; // 检查是否有变化
410
491
  hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
411
492
  if (!hasChanges) {
412
- _context4.next = 56;
493
+ _context5.next = 57;
413
494
  break;
414
495
  }
415
496
  console.log('[PaymentModule] 支付方式列表已更新');
@@ -419,94 +500,94 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
419
500
  });
420
501
 
421
502
  // 更新缓存
422
- _context4.prev = 11;
503
+ _context5.prev = 12;
423
504
  // 先清除旧数据
424
- _iterator2 = _createForOfIteratorHelper(cachedMethods);
425
- _context4.prev = 13;
426
- _iterator2.s();
427
- case 15:
428
- if ((_step2 = _iterator2.n()).done) {
429
- _context4.next = 21;
505
+ _iterator3 = _createForOfIteratorHelper(cachedMethods);
506
+ _context5.prev = 14;
507
+ _iterator3.s();
508
+ case 16:
509
+ if ((_step3 = _iterator3.n()).done) {
510
+ _context5.next = 22;
430
511
  break;
431
512
  }
432
- method = _step2.value;
433
- _context4.next = 19;
513
+ method = _step3.value;
514
+ _context5.next = 20;
434
515
  return this.dbManager.delete('pay_method', method.id);
435
- case 19:
436
- _context4.next = 15;
516
+ case 20:
517
+ _context5.next = 16;
437
518
  break;
438
- case 21:
439
- _context4.next = 26;
519
+ case 22:
520
+ _context5.next = 27;
440
521
  break;
441
- case 23:
442
- _context4.prev = 23;
443
- _context4.t0 = _context4["catch"](13);
444
- _iterator2.e(_context4.t0);
445
- case 26:
446
- _context4.prev = 26;
447
- _iterator2.f();
448
- return _context4.finish(26);
449
- case 29:
522
+ case 24:
523
+ _context5.prev = 24;
524
+ _context5.t0 = _context5["catch"](14);
525
+ _iterator3.e(_context5.t0);
526
+ case 27:
527
+ _context5.prev = 27;
528
+ _iterator3.f();
529
+ return _context5.finish(27);
530
+ case 30:
450
531
  // 添加新数据
451
- _iterator3 = _createForOfIteratorHelper(newPayMethods);
452
- _context4.prev = 30;
453
- _iterator3.s();
454
- case 32:
455
- if ((_step3 = _iterator3.n()).done) {
456
- _context4.next = 38;
532
+ _iterator4 = _createForOfIteratorHelper(newPayMethods);
533
+ _context5.prev = 31;
534
+ _iterator4.s();
535
+ case 33:
536
+ if ((_step4 = _iterator4.n()).done) {
537
+ _context5.next = 39;
457
538
  break;
458
539
  }
459
- _method = _step3.value;
460
- _context4.next = 36;
540
+ _method = _step4.value;
541
+ _context5.next = 37;
461
542
  return this.dbManager.update('pay_method', _method);
462
- case 36:
463
- _context4.next = 32;
543
+ case 37:
544
+ _context5.next = 33;
464
545
  break;
465
- case 38:
466
- _context4.next = 43;
546
+ case 39:
547
+ _context5.next = 44;
467
548
  break;
468
- case 40:
469
- _context4.prev = 40;
470
- _context4.t1 = _context4["catch"](30);
471
- _iterator3.e(_context4.t1);
472
- case 43:
473
- _context4.prev = 43;
474
- _iterator3.f();
475
- return _context4.finish(43);
476
- case 46:
477
- _context4.next = 51;
549
+ case 41:
550
+ _context5.prev = 41;
551
+ _context5.t1 = _context5["catch"](31);
552
+ _iterator4.e(_context5.t1);
553
+ case 44:
554
+ _context5.prev = 44;
555
+ _iterator4.f();
556
+ return _context5.finish(44);
557
+ case 47:
558
+ _context5.next = 52;
478
559
  break;
479
- case 48:
480
- _context4.prev = 48;
481
- _context4.t2 = _context4["catch"](11);
482
- console.warn('[PaymentModule] 无法更新支付方式缓存', _context4.t2);
483
- case 51:
560
+ case 49:
561
+ _context5.prev = 49;
562
+ _context5.t2 = _context5["catch"](12);
563
+ console.warn('[PaymentModule] 无法更新支付方式缓存', _context5.t2);
564
+ case 52:
484
565
  // 通知外部支付方式已变化
485
566
  eventData = {
486
567
  oldMethods: cachedMethods,
487
568
  newMethods: newPayMethods
488
569
  };
489
- _context4.next = 54;
570
+ _context5.next = 55;
490
571
  return this.core.effects.emit("".concat(this.name, ":onPaymentMethodsChanged"), eventData);
491
- case 54:
492
- _context4.next = 57;
572
+ case 55:
573
+ _context5.next = 58;
493
574
  break;
494
- case 56:
495
- console.log('[PaymentModule] 支付方式列表无变化');
496
575
  case 57:
497
- _context4.next = 62;
576
+ console.log('[PaymentModule] 支付方式列表无变化');
577
+ case 58:
578
+ _context5.next = 63;
498
579
  break;
499
- case 59:
500
- _context4.prev = 59;
501
- _context4.t3 = _context4["catch"](1);
502
- console.error('[PaymentModule] 后台刷新支付方式失败', _context4.t3);
503
- case 62:
580
+ case 60:
581
+ _context5.prev = 60;
582
+ _context5.t3 = _context5["catch"](1);
583
+ console.error('[PaymentModule] 后台刷新支付方式失败', _context5.t3);
584
+ case 63:
504
585
  case "end":
505
- return _context4.stop();
586
+ return _context5.stop();
506
587
  }
507
- }, _callee4, this, [[1, 59], [11, 48], [13, 23, 26, 29], [30, 40, 43, 46]]);
588
+ }, _callee5, this, [[1, 60], [12, 49], [14, 24, 27, 30], [31, 41, 44, 47]]);
508
589
  }));
509
- function refreshPaymentMethodsInBackground(_x4) {
590
+ function refreshPaymentMethodsInBackground(_x5) {
510
591
  return _refreshPaymentMethodsInBackground.apply(this, arguments);
511
592
  }
512
593
  return refreshPaymentMethodsInBackground;
@@ -528,11 +609,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
528
609
  }));
529
610
 
530
611
  // 检查每个新方法是否与旧方法相同
531
- var _iterator4 = _createForOfIteratorHelper(newMethods),
532
- _step4;
612
+ var _iterator5 = _createForOfIteratorHelper(newMethods),
613
+ _step5;
533
614
  try {
534
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
535
- var newMethod = _step4.value;
615
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
616
+ var newMethod = _step5.value;
536
617
  var oldMethod = oldMethodsMap.get(newMethod.id);
537
618
  if (!oldMethod) {
538
619
  return true; // 新增方法
@@ -601,9 +682,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
601
682
  }
602
683
  }
603
684
  } catch (err) {
604
- _iterator4.e(err);
685
+ _iterator5.e(err);
605
686
  } finally {
606
- _iterator4.f();
687
+ _iterator5.f();
607
688
  }
608
689
  return false;
609
690
  }
@@ -614,25 +695,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
614
695
  }, {
615
696
  key: "getOrderListAsync",
616
697
  value: (function () {
617
- var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
618
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
619
- while (1) switch (_context5.prev = _context5.next) {
698
+ var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
699
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
700
+ while (1) switch (_context6.prev = _context6.next) {
620
701
  case 0:
621
- _context5.prev = 0;
622
- _context5.next = 3;
702
+ _context6.prev = 0;
703
+ _context6.next = 3;
623
704
  return this.dbManager.getAll('order');
624
705
  case 3:
625
- return _context5.abrupt("return", _context5.sent);
706
+ return _context6.abrupt("return", _context6.sent);
626
707
  case 6:
627
- _context5.prev = 6;
628
- _context5.t0 = _context5["catch"](0);
629
- console.error('[PaymentModule] 获取订单列表失败', _context5.t0);
630
- return _context5.abrupt("return", []);
708
+ _context6.prev = 6;
709
+ _context6.t0 = _context6["catch"](0);
710
+ console.error('[PaymentModule] 获取订单列表失败', _context6.t0);
711
+ return _context6.abrupt("return", []);
631
712
  case 10:
632
713
  case "end":
633
- return _context5.stop();
714
+ return _context6.stop();
634
715
  }
635
- }, _callee5, this, [[0, 6]]);
716
+ }, _callee6, this, [[0, 6]]);
636
717
  }));
637
718
  function getOrderListAsync() {
638
719
  return _getOrderListAsync.apply(this, arguments);
@@ -646,27 +727,27 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
646
727
  }, {
647
728
  key: "getPaymentOrderByUuidAsync",
648
729
  value: (function () {
649
- var _getPaymentOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
650
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
651
- while (1) switch (_context6.prev = _context6.next) {
730
+ var _getPaymentOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(orderUuid) {
731
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
732
+ while (1) switch (_context7.prev = _context7.next) {
652
733
  case 0:
653
- _context6.prev = 0;
654
- _context6.next = 3;
734
+ _context7.prev = 0;
735
+ _context7.next = 3;
655
736
  return this.dbManager.get('order', orderUuid, true);
656
737
  case 3:
657
- return _context6.abrupt("return", _context6.sent);
738
+ return _context7.abrupt("return", _context7.sent);
658
739
  case 6:
659
- _context6.prev = 6;
660
- _context6.t0 = _context6["catch"](0);
661
- console.error('[PaymentModule] 获取支付订单失败', _context6.t0);
662
- return _context6.abrupt("return", null);
740
+ _context7.prev = 6;
741
+ _context7.t0 = _context7["catch"](0);
742
+ console.error('[PaymentModule] 获取支付订单失败', _context7.t0);
743
+ return _context7.abrupt("return", null);
663
744
  case 10:
664
745
  case "end":
665
- return _context6.stop();
746
+ return _context7.stop();
666
747
  }
667
- }, _callee6, this, [[0, 6]]);
748
+ }, _callee7, this, [[0, 6]]);
668
749
  }));
669
- function getPaymentOrderByUuidAsync(_x5) {
750
+ function getPaymentOrderByUuidAsync(_x6) {
670
751
  return _getPaymentOrderByUuidAsync.apply(this, arguments);
671
752
  }
672
753
  return getPaymentOrderByUuidAsync;
@@ -678,17 +759,17 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
678
759
  }, {
679
760
  key: "createPaymentOrderAsync",
680
761
  value: (function () {
681
- var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
682
- var _this3 = this;
762
+ var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
763
+ var _this4 = this;
683
764
  var newOrder, currentTime, dbAddStartTime, dbAddDuration;
684
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
685
- while (1) switch (_context7.prev = _context7.next) {
765
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
766
+ while (1) switch (_context8.prev = _context8.next) {
686
767
  case 0:
687
768
  this.logInfo('Starting createPaymentOrderAsync', {
688
769
  orderId: params.order_id,
689
770
  totalAmount: params.total_amount
690
771
  });
691
- _context7.prev = 1;
772
+ _context8.prev = 1;
692
773
  // 检测是否有重复的 order_id
693
774
  // console.time('createLocalOrderAsync: getExistingOrder')
694
775
  // const existingOrder = await this.dbManager.get('order', params.order_id);
@@ -774,7 +855,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
774
855
 
775
856
  // 🚀 性能监控:记录数据库添加操作耗时
776
857
  dbAddStartTime = Date.now();
777
- _context7.next = 7;
858
+ _context8.next = 7;
778
859
  return this.dbManager.add('order', newOrder, true);
779
860
  case 7:
780
861
  dbAddDuration = Date.now() - dbAddStartTime;
@@ -787,24 +868,24 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
787
868
  performance: dbAddDuration > 100 ? 'slow' : dbAddDuration > 50 ? 'medium' : 'fast'
788
869
  });
789
870
  setTimeout(function () {
790
- _this3.core.effects.emit("".concat(_this3.name, ":onOrderAdded"), newOrder);
871
+ _this4.core.effects.emit("".concat(_this4.name, ":onOrderAdded"), newOrder);
791
872
  }, 0);
792
- return _context7.abrupt("return", newOrder);
873
+ return _context8.abrupt("return", newOrder);
793
874
  case 13:
794
- _context7.prev = 13;
795
- _context7.t0 = _context7["catch"](1);
796
- console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
797
- this.logError('createPaymentOrderAsync failed', _context7.t0, {
875
+ _context8.prev = 13;
876
+ _context8.t0 = _context8["catch"](1);
877
+ console.error('[PaymentModule] 创建支付订单失败', _context8.t0);
878
+ this.logError('createPaymentOrderAsync failed', _context8.t0, {
798
879
  orderId: params.order_id
799
880
  });
800
- throw _context7.t0;
881
+ throw _context8.t0;
801
882
  case 18:
802
883
  case "end":
803
- return _context7.stop();
884
+ return _context8.stop();
804
885
  }
805
- }, _callee7, this, [[1, 13]]);
886
+ }, _callee8, this, [[1, 13]]);
806
887
  }));
807
- function createPaymentOrderAsync(_x6) {
888
+ function createPaymentOrderAsync(_x7) {
808
889
  return _createPaymentOrderAsync.apply(this, arguments);
809
890
  }
810
891
  return createPaymentOrderAsync;
@@ -816,42 +897,42 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
816
897
  }, {
817
898
  key: "deletePaymentOrderAsync",
818
899
  value: (function () {
819
- var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
900
+ var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid) {
820
901
  var order;
821
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
822
- while (1) switch (_context8.prev = _context8.next) {
902
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
903
+ while (1) switch (_context9.prev = _context9.next) {
823
904
  case 0:
824
- _context8.prev = 0;
825
- _context8.next = 3;
905
+ _context9.prev = 0;
906
+ _context9.next = 3;
826
907
  return this.dbManager.get('order', orderUuid);
827
908
  case 3:
828
- order = _context8.sent;
909
+ order = _context9.sent;
829
910
  if (!order) {
830
- _context8.next = 10;
911
+ _context9.next = 10;
831
912
  break;
832
913
  }
833
- _context8.next = 7;
914
+ _context9.next = 7;
834
915
  return this.dbManager.delete('order', orderUuid);
835
916
  case 7:
836
- _context8.next = 9;
917
+ _context9.next = 9;
837
918
  return this.core.effects.emit("".concat(this.name, ":onOrderDeleted"), order);
838
919
  case 9:
839
920
  console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
840
921
  case 10:
841
- _context8.next = 16;
922
+ _context9.next = 16;
842
923
  break;
843
924
  case 12:
844
- _context8.prev = 12;
845
- _context8.t0 = _context8["catch"](0);
846
- console.error('[PaymentModule] 删除支付订单失败', _context8.t0);
847
- throw _context8.t0;
925
+ _context9.prev = 12;
926
+ _context9.t0 = _context9["catch"](0);
927
+ console.error('[PaymentModule] 删除支付订单失败', _context9.t0);
928
+ throw _context9.t0;
848
929
  case 16:
849
930
  case "end":
850
- return _context8.stop();
931
+ return _context9.stop();
851
932
  }
852
- }, _callee8, this, [[0, 12]]);
933
+ }, _callee9, this, [[0, 12]]);
853
934
  }));
854
- function deletePaymentOrderAsync(_x7) {
935
+ function deletePaymentOrderAsync(_x8) {
855
936
  return _deletePaymentOrderAsync.apply(this, arguments);
856
937
  }
857
938
  return deletePaymentOrderAsync;
@@ -863,49 +944,49 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
863
944
  }, {
864
945
  key: "updateOrderAsync",
865
946
  value: (function () {
866
- var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid, params) {
947
+ var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid, params) {
867
948
  var order, updatedOrder;
868
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
869
- while (1) switch (_context9.prev = _context9.next) {
949
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
950
+ while (1) switch (_context10.prev = _context10.next) {
870
951
  case 0:
871
- _context9.prev = 0;
872
- _context9.next = 3;
952
+ _context10.prev = 0;
953
+ _context10.next = 3;
873
954
  return this.dbManager.get('order', orderUuid);
874
955
  case 3:
875
- order = _context9.sent;
956
+ order = _context10.sent;
876
957
  if (!order) {
877
- _context9.next = 13;
958
+ _context10.next = 13;
878
959
  break;
879
960
  }
880
961
  updatedOrder = _objectSpread(_objectSpread({}, order), params);
881
962
  this.recalculateOrderAmount(updatedOrder);
882
- _context9.next = 9;
963
+ _context10.next = 9;
883
964
  return this.dbManager.update('order', updatedOrder);
884
965
  case 9:
885
- _context9.next = 11;
966
+ _context10.next = 11;
886
967
  return this.core.effects.emit("".concat(this.name, ":onOrderUpdated"), updatedOrder);
887
968
  case 11:
888
- _context9.next = 13;
969
+ _context10.next = 13;
889
970
  return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
890
971
  action: 'update',
891
972
  order: updatedOrder,
892
973
  originalOrder: order
893
974
  });
894
975
  case 13:
895
- _context9.next = 19;
976
+ _context10.next = 19;
896
977
  break;
897
978
  case 15:
898
- _context9.prev = 15;
899
- _context9.t0 = _context9["catch"](0);
900
- console.error('[PaymentModule] 更新订单失败', _context9.t0);
901
- throw _context9.t0;
979
+ _context10.prev = 15;
980
+ _context10.t0 = _context10["catch"](0);
981
+ console.error('[PaymentModule] 更新订单失败', _context10.t0);
982
+ throw _context10.t0;
902
983
  case 19:
903
984
  case "end":
904
- return _context9.stop();
985
+ return _context10.stop();
905
986
  }
906
- }, _callee9, this, [[0, 15]]);
987
+ }, _callee10, this, [[0, 15]]);
907
988
  }));
908
- function updateOrderAsync(_x8, _x9) {
989
+ function updateOrderAsync(_x9, _x10) {
909
990
  return _updateOrderAsync.apply(this, arguments);
910
991
  }
911
992
  return updateOrderAsync;
@@ -924,38 +1005,38 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
924
1005
  }, {
925
1006
  key: "replaceOrderIdByUuidAsync",
926
1007
  value: (function () {
927
- var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid, newOrderId) {
1008
+ var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, newOrderId) {
928
1009
  var existingOrder, allOrders, duplicateOrder, originalOrderId, updatedOrder;
929
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
930
- while (1) switch (_context10.prev = _context10.next) {
1010
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1011
+ while (1) switch (_context11.prev = _context11.next) {
931
1012
  case 0:
932
1013
  this.logInfo('Starting replaceOrderIdByUuidAsync', {
933
1014
  orderUuid: orderUuid,
934
1015
  newOrderId: newOrderId
935
1016
  });
936
- _context10.prev = 1;
937
- _context10.next = 4;
1017
+ _context11.prev = 1;
1018
+ _context11.next = 4;
938
1019
  return this.dbManager.get('order', orderUuid);
939
1020
  case 4:
940
- existingOrder = _context10.sent;
1021
+ existingOrder = _context11.sent;
941
1022
  if (existingOrder) {
942
- _context10.next = 8;
1023
+ _context11.next = 8;
943
1024
  break;
944
1025
  }
945
1026
  this.logWarning('Order not found for UUID replacement', {
946
1027
  orderUuid: orderUuid
947
1028
  });
948
- return _context10.abrupt("return", null);
1029
+ return _context11.abrupt("return", null);
949
1030
  case 8:
950
- _context10.next = 10;
1031
+ _context11.next = 10;
951
1032
  return this.dbManager.getAll('order');
952
1033
  case 10:
953
- allOrders = _context10.sent;
1034
+ allOrders = _context11.sent;
954
1035
  duplicateOrder = allOrders.find(function (order) {
955
1036
  return String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid;
956
1037
  });
957
1038
  if (!duplicateOrder) {
958
- _context10.next = 15;
1039
+ _context11.next = 15;
959
1040
  break;
960
1041
  }
961
1042
  this.logWarning('New order ID already exists', {
@@ -977,13 +1058,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
977
1058
  updated_at: new Date().toISOString()
978
1059
  })
979
1060
  }); // 更新到数据库
980
- _context10.next = 19;
1061
+ _context11.next = 19;
981
1062
  return this.dbManager.update('order', updatedOrder);
982
1063
  case 19:
983
- _context10.next = 21;
1064
+ _context11.next = 21;
984
1065
  return this.core.effects.emit("".concat(this.name, ":onOrderUpdated"), updatedOrder);
985
1066
  case 21:
986
- _context10.next = 23;
1067
+ _context11.next = 23;
987
1068
  return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
988
1069
  action: 'order_id_replaced',
989
1070
  order: updatedOrder,
@@ -1000,23 +1081,23 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1000
1081
  newOrderId: newOrderId
1001
1082
  });
1002
1083
  console.log("[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ".concat(originalOrderId, " \u2192 ").concat(newOrderId));
1003
- return _context10.abrupt("return", updatedOrder);
1084
+ return _context11.abrupt("return", updatedOrder);
1004
1085
  case 28:
1005
- _context10.prev = 28;
1006
- _context10.t0 = _context10["catch"](1);
1007
- console.error('[PaymentModule] 替换订单ID失败', _context10.t0);
1008
- this.logError('replaceOrderIdByUuidAsync failed', _context10.t0, {
1086
+ _context11.prev = 28;
1087
+ _context11.t0 = _context11["catch"](1);
1088
+ console.error('[PaymentModule] 替换订单ID失败', _context11.t0);
1089
+ this.logError('replaceOrderIdByUuidAsync failed', _context11.t0, {
1009
1090
  orderUuid: orderUuid,
1010
1091
  newOrderId: newOrderId
1011
1092
  });
1012
- throw _context10.t0;
1093
+ throw _context11.t0;
1013
1094
  case 33:
1014
1095
  case "end":
1015
- return _context10.stop();
1096
+ return _context11.stop();
1016
1097
  }
1017
- }, _callee10, this, [[1, 28]]);
1098
+ }, _callee11, this, [[1, 28]]);
1018
1099
  }));
1019
- function replaceOrderIdByUuidAsync(_x10, _x11) {
1100
+ function replaceOrderIdByUuidAsync(_x11, _x12) {
1020
1101
  return _replaceOrderIdByUuidAsync.apply(this, arguments);
1021
1102
  }
1022
1103
  return replaceOrderIdByUuidAsync;
@@ -1032,42 +1113,42 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1032
1113
  }, {
1033
1114
  key: "getPaymentItemsAsync",
1034
1115
  value: (function () {
1035
- var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid) {
1116
+ var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid) {
1036
1117
  var includeVoided,
1037
1118
  order,
1038
1119
  allPayments,
1039
- _args11 = arguments;
1040
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1041
- while (1) switch (_context11.prev = _context11.next) {
1120
+ _args12 = arguments;
1121
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1122
+ while (1) switch (_context12.prev = _context12.next) {
1042
1123
  case 0:
1043
- includeVoided = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : false;
1124
+ includeVoided = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
1044
1125
  if (orderUuid) {
1045
- _context11.next = 3;
1126
+ _context12.next = 3;
1046
1127
  break;
1047
1128
  }
1048
1129
  throw new Error('orderUuid is required');
1049
1130
  case 3:
1050
- _context11.next = 5;
1131
+ _context12.next = 5;
1051
1132
  return this.getPaymentOrderByUuidAsync(orderUuid);
1052
1133
  case 5:
1053
- order = _context11.sent;
1134
+ order = _context12.sent;
1054
1135
  allPayments = (order === null || order === void 0 ? void 0 : order.payment) || [];
1055
1136
  if (!includeVoided) {
1056
- _context11.next = 9;
1137
+ _context12.next = 9;
1057
1138
  break;
1058
1139
  }
1059
- return _context11.abrupt("return", allPayments);
1140
+ return _context12.abrupt("return", allPayments);
1060
1141
  case 9:
1061
- return _context11.abrupt("return", allPayments.filter(function (payment) {
1142
+ return _context12.abrupt("return", allPayments.filter(function (payment) {
1062
1143
  return payment.status !== 'voided';
1063
1144
  }));
1064
1145
  case 10:
1065
1146
  case "end":
1066
- return _context11.stop();
1147
+ return _context12.stop();
1067
1148
  }
1068
- }, _callee11, this);
1149
+ }, _callee12, this);
1069
1150
  }));
1070
- function getPaymentItemsAsync(_x12) {
1151
+ function getPaymentItemsAsync(_x13) {
1071
1152
  return _getPaymentItemsAsync.apply(this, arguments);
1072
1153
  }
1073
1154
  return getPaymentItemsAsync;
@@ -1082,18 +1163,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1082
1163
  }, {
1083
1164
  key: "getAllPaymentItemsAsync",
1084
1165
  value: (function () {
1085
- var _getAllPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid) {
1086
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1087
- while (1) switch (_context12.prev = _context12.next) {
1166
+ var _getAllPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid) {
1167
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1168
+ while (1) switch (_context13.prev = _context13.next) {
1088
1169
  case 0:
1089
- return _context12.abrupt("return", this.getPaymentItemsAsync(orderUuid, true));
1170
+ return _context13.abrupt("return", this.getPaymentItemsAsync(orderUuid, true));
1090
1171
  case 1:
1091
1172
  case "end":
1092
- return _context12.stop();
1173
+ return _context13.stop();
1093
1174
  }
1094
- }, _callee12, this);
1175
+ }, _callee13, this);
1095
1176
  }));
1096
- function getAllPaymentItemsAsync(_x13) {
1177
+ function getAllPaymentItemsAsync(_x14) {
1097
1178
  return _getAllPaymentItemsAsync.apply(this, arguments);
1098
1179
  }
1099
1180
  return getAllPaymentItemsAsync;
@@ -1105,10 +1186,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1105
1186
  }, {
1106
1187
  key: "addPaymentItemAsync",
1107
1188
  value: (function () {
1108
- var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
1189
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid, paymentItem) {
1109
1190
  var _paymentItem$metadata, _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, expectAmount, paidDepositAmount, expectedDepositAmount, warningMessage, paymentUuid, currentTime, newPaymentItem;
1110
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1111
- while (1) switch (_context13.prev = _context13.next) {
1191
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1192
+ while (1) switch (_context14.prev = _context14.next) {
1112
1193
  case 0:
1113
1194
  this.logInfo('Starting addPaymentItemAsync', {
1114
1195
  orderUuid: orderUuid,
@@ -1116,20 +1197,20 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1116
1197
  paymentCode: paymentItem.code,
1117
1198
  orderPaymentType: paymentItem.order_payment_type
1118
1199
  });
1119
- _context13.prev = 1;
1200
+ _context14.prev = 1;
1120
1201
  this.logInfo('准备获取订单', {
1121
1202
  orderUuid: orderUuid
1122
1203
  });
1123
- _context13.next = 5;
1204
+ _context14.next = 5;
1124
1205
  return this.getPaymentOrderByUuidAsync(orderUuid);
1125
1206
  case 5:
1126
- order = _context13.sent;
1207
+ order = _context14.sent;
1127
1208
  this.logInfo('获取订单信息成功', {
1128
1209
  orderUuid: orderUuid,
1129
1210
  order: order
1130
1211
  });
1131
1212
  if (order) {
1132
- _context13.next = 9;
1213
+ _context14.next = 9;
1133
1214
  break;
1134
1215
  }
1135
1216
  throw new Error("Order not found: ".concat(orderUuid));
@@ -1144,7 +1225,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1144
1225
  }, new Decimal(0));
1145
1226
  expectedDepositAmount = new Decimal(order.deposit_amount || '0').sub(paidDepositAmount); // 有一种特殊情况,订单金额为 0,但是定金金额>0,且此时是定金状态的,允许添加支付项
1146
1227
  if (!(expectAmount.lte(0) && expectedDepositAmount.eq(0))) {
1147
- _context13.next = 17;
1228
+ _context14.next = 17;
1148
1229
  break;
1149
1230
  }
1150
1231
  warningMessage = "\u8BA2\u5355 ".concat(orderUuid, " \u5F85\u4ED8\u91D1\u989D\u5DF2\u4E3A0\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u65B0\u7684\u652F\u4ED8\u9879");
@@ -1199,7 +1280,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1199
1280
  orderUuid: orderUuid,
1200
1281
  order: order
1201
1282
  });
1202
- _context13.next = 25;
1283
+ _context14.next = 25;
1203
1284
  return this.dbManager.update('order', order, true);
1204
1285
  case 25:
1205
1286
  this.logInfo('更新订单支付项完成', {
@@ -1222,24 +1303,24 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1222
1303
  actualPaidAmount: (_newPaymentItem$metad2 = newPaymentItem.metadata) === null || _newPaymentItem$metad2 === void 0 ? void 0 : _newPaymentItem$metad2.actual_paid_amount,
1223
1304
  changeGivenAmount: (_newPaymentItem$metad3 = newPaymentItem.metadata) === null || _newPaymentItem$metad3 === void 0 ? void 0 : _newPaymentItem$metad3.change_given_amount
1224
1305
  });
1225
- _context13.next = 35;
1306
+ _context14.next = 35;
1226
1307
  break;
1227
1308
  case 30:
1228
- _context13.prev = 30;
1229
- _context13.t0 = _context13["catch"](1);
1230
- console.error('[PaymentModule] 添加支付项失败', _context13.t0);
1231
- this.logError('addPaymentItemAsync failed', _context13.t0, {
1309
+ _context14.prev = 30;
1310
+ _context14.t0 = _context14["catch"](1);
1311
+ console.error('[PaymentModule] 添加支付项失败', _context14.t0);
1312
+ this.logError('addPaymentItemAsync failed', _context14.t0, {
1232
1313
  orderUuid: orderUuid,
1233
1314
  paymentItem: paymentItem
1234
1315
  });
1235
- throw _context13.t0;
1316
+ throw _context14.t0;
1236
1317
  case 35:
1237
1318
  case "end":
1238
- return _context13.stop();
1319
+ return _context14.stop();
1239
1320
  }
1240
- }, _callee13, this, [[1, 30]]);
1321
+ }, _callee14, this, [[1, 30]]);
1241
1322
  }));
1242
- function addPaymentItemAsync(_x14, _x15) {
1323
+ function addPaymentItemAsync(_x15, _x16) {
1243
1324
  return _addPaymentItemAsync.apply(this, arguments);
1244
1325
  }
1245
1326
  return addPaymentItemAsync;
@@ -1251,22 +1332,22 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1251
1332
  }, {
1252
1333
  key: "deletePaymentAsync",
1253
1334
  value: (function () {
1254
- var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid, paymentUuid) {
1335
+ var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, paymentUuid) {
1255
1336
  var order, paymentItem;
1256
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1257
- while (1) switch (_context14.prev = _context14.next) {
1337
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1338
+ while (1) switch (_context15.prev = _context15.next) {
1258
1339
  case 0:
1259
1340
  this.logInfo('Starting deletePaymentAsync (mark as voided)', {
1260
1341
  orderUuid: orderUuid,
1261
1342
  paymentUuid: paymentUuid
1262
1343
  });
1263
- _context14.prev = 1;
1264
- _context14.next = 4;
1344
+ _context15.prev = 1;
1345
+ _context15.next = 4;
1265
1346
  return this.dbManager.get('order', orderUuid);
1266
1347
  case 4:
1267
- order = _context14.sent;
1348
+ order = _context15.sent;
1268
1349
  if (order) {
1269
- _context14.next = 7;
1350
+ _context15.next = 7;
1270
1351
  break;
1271
1352
  }
1272
1353
  throw new Error('订单不存在');
@@ -1275,17 +1356,17 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1275
1356
  return payment.uuid === paymentUuid;
1276
1357
  });
1277
1358
  if (paymentItem) {
1278
- _context14.next = 10;
1359
+ _context15.next = 10;
1279
1360
  break;
1280
1361
  }
1281
1362
  throw new Error("\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
1282
1363
  case 10:
1283
1364
  if (!(paymentItem.status === 'voided')) {
1284
- _context14.next = 13;
1365
+ _context15.next = 13;
1285
1366
  break;
1286
1367
  }
1287
1368
  console.warn("[PaymentModule] \u652F\u4ED8\u9879 ".concat(paymentUuid, " \u5DF2\u7ECF\u88AB\u5220\u9664\uFF0C\u8DF3\u8FC7\u64CD\u4F5C"));
1288
- return _context14.abrupt("return");
1369
+ return _context15.abrupt("return");
1289
1370
  case 13:
1290
1371
  // 标记删除而不是物理删除
1291
1372
  paymentItem.status = 'voided';
@@ -1302,16 +1383,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1302
1383
  this.recalculateOrderAmount(order);
1303
1384
 
1304
1385
  // 更新到 IndexDB
1305
- _context14.next = 20;
1386
+ _context15.next = 20;
1306
1387
  return this.dbManager.update('order', order);
1307
1388
  case 20:
1308
- _context14.next = 22;
1389
+ _context15.next = 22;
1309
1390
  return this.core.effects.emit("".concat(this.name, ":onPaymentDeleted"), {
1310
1391
  order: order,
1311
1392
  paymentItem: paymentItem
1312
1393
  });
1313
1394
  case 22:
1314
- _context14.next = 24;
1395
+ _context15.next = 24;
1315
1396
  return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
1316
1397
  action: 'payment_delete',
1317
1398
  order: order,
@@ -1324,24 +1405,24 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1324
1405
  originalAmount: paymentItem.origin_amount,
1325
1406
  newExpectAmount: order.expect_amount
1326
1407
  });
1327
- _context14.next = 32;
1408
+ _context15.next = 32;
1328
1409
  break;
1329
1410
  case 27:
1330
- _context14.prev = 27;
1331
- _context14.t0 = _context14["catch"](1);
1332
- console.error('[PaymentModule] 删除支付项失败', _context14.t0);
1333
- this.logError('deletePaymentAsync failed', _context14.t0, {
1411
+ _context15.prev = 27;
1412
+ _context15.t0 = _context15["catch"](1);
1413
+ console.error('[PaymentModule] 删除支付项失败', _context15.t0);
1414
+ this.logError('deletePaymentAsync failed', _context15.t0, {
1334
1415
  orderUuid: orderUuid,
1335
1416
  paymentUuid: paymentUuid
1336
1417
  });
1337
- throw _context14.t0;
1418
+ throw _context15.t0;
1338
1419
  case 32:
1339
1420
  case "end":
1340
- return _context14.stop();
1421
+ return _context15.stop();
1341
1422
  }
1342
- }, _callee14, this, [[1, 27]]);
1423
+ }, _callee15, this, [[1, 27]]);
1343
1424
  }));
1344
- function deletePaymentAsync(_x16, _x17) {
1425
+ function deletePaymentAsync(_x17, _x18) {
1345
1426
  return _deletePaymentAsync.apply(this, arguments);
1346
1427
  }
1347
1428
  return deletePaymentAsync;
@@ -1356,159 +1437,202 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1356
1437
  }, {
1357
1438
  key: "updateVoucherPaymentItemsAsync",
1358
1439
  value: (function () {
1359
- var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, voucherPaymentItems) {
1360
- var order, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
1361
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1362
- while (1) switch (_context15.prev = _context15.next) {
1440
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid, voucherPaymentItems) {
1441
+ var _this5 = this;
1442
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1443
+ while (1) switch (_context17.prev = _context17.next) {
1363
1444
  case 0:
1364
- this.logInfo('Starting updateVoucherPaymentItemsAsync', {
1365
- orderUuid: orderUuid,
1366
- newVoucherCount: voucherPaymentItems.length,
1367
- voucherItems: voucherPaymentItems.map(function (item) {
1368
- return {
1369
- code: item.code,
1370
- amount: item.amount,
1371
- voucher_id: item.voucher_id,
1372
- order_payment_type: item.order_payment_type
1373
- };
1374
- })
1375
- });
1376
- _context15.prev = 1;
1377
- _context15.next = 4;
1378
- return this.getPaymentOrderByUuidAsync(orderUuid);
1379
- case 4:
1380
- order = _context15.sent;
1381
- if (order) {
1382
- _context15.next = 7;
1383
- break;
1384
- }
1385
- throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1386
- case 7:
1387
- // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)并且还没有同步给后端
1388
- // 如果同步给了后端的voucher 不允许删除
1389
- existingVoucherItems = order.payment.filter(function (payment) {
1390
- return payment.voucher_id && payment.status !== 'voided' && !payment.isSynced;
1391
- });
1392
- console.log('[PaymentModule] 发现现有代金券支付项:', {
1393
- orderUuid: orderUuid,
1394
- existingVoucherCount: existingVoucherItems.length,
1395
- existingItems: existingVoucherItems.map(function (item) {
1396
- return {
1397
- uuid: item.uuid,
1398
- code: item.code,
1399
- amount: item.amount,
1400
- voucher_id: item.voucher_id,
1401
- isSynced: item.isSynced
1402
- };
1403
- })
1404
- });
1445
+ return _context17.abrupt("return", this.runVoucherUpdateLocked(orderUuid, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1446
+ var _this5$normalizeVouch, normalizedVoucherItems, originalCount, normalizedCount, order, existingVoucherItems, _iterator6, _step6, voucherItem, orderAfterDelete, existingActiveVoucherKeys, _iterator7, _step7, _voucherItem, orderPaymentType, key, updatedOrder;
1447
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1448
+ while (1) switch (_context16.prev = _context16.next) {
1449
+ case 0:
1450
+ _this5$normalizeVouch = _this5.normalizeVoucherPaymentItems(voucherPaymentItems), normalizedVoucherItems = _this5$normalizeVouch.items, originalCount = _this5$normalizeVouch.originalCount, normalizedCount = _this5$normalizeVouch.normalizedCount;
1451
+ _this5.logInfo('Starting updateVoucherPaymentItemsAsync', {
1452
+ orderUuid: orderUuid,
1453
+ originalVoucherCount: originalCount,
1454
+ normalizedVoucherCount: normalizedCount,
1455
+ voucherItems: normalizedVoucherItems.map(function (item) {
1456
+ return {
1457
+ code: item.code,
1458
+ amount: item.amount,
1459
+ voucher_id: item.voucher_id,
1460
+ order_payment_type: item.order_payment_type
1461
+ };
1462
+ })
1463
+ });
1464
+ if (originalCount !== normalizedCount) {
1465
+ console.warn('[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)', {
1466
+ orderUuid: orderUuid,
1467
+ originalCount: originalCount,
1468
+ normalizedCount: normalizedCount
1469
+ });
1470
+ }
1471
+ _context16.prev = 3;
1472
+ _context16.next = 6;
1473
+ return _this5.getPaymentOrderByUuidAsync(orderUuid);
1474
+ case 6:
1475
+ order = _context16.sent;
1476
+ if (order) {
1477
+ _context16.next = 9;
1478
+ break;
1479
+ }
1480
+ throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1481
+ case 9:
1482
+ // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)并且还没有同步给后端
1483
+ // 如果同步给了后端的voucher 不允许删除
1484
+ existingVoucherItems = order.payment.filter(function (payment) {
1485
+ return payment.voucher_id && payment.status !== 'voided' && !payment.isSynced;
1486
+ });
1487
+ console.log('[PaymentModule] 发现现有代金券支付项:', {
1488
+ orderUuid: orderUuid,
1489
+ existingVoucherCount: existingVoucherItems.length,
1490
+ existingItems: existingVoucherItems.map(function (item) {
1491
+ return {
1492
+ uuid: item.uuid,
1493
+ code: item.code,
1494
+ amount: item.amount,
1495
+ voucher_id: item.voucher_id,
1496
+ isSynced: item.isSynced
1497
+ };
1498
+ })
1499
+ });
1405
1500
 
1406
- // 2. 删除所有现有的代金券支付项
1407
- _iterator5 = _createForOfIteratorHelper(existingVoucherItems);
1408
- _context15.prev = 10;
1409
- _iterator5.s();
1410
- case 12:
1411
- if ((_step5 = _iterator5.n()).done) {
1412
- _context15.next = 19;
1413
- break;
1414
- }
1415
- voucherItem = _step5.value;
1416
- console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
1417
- _context15.next = 17;
1418
- return this.deletePaymentAsync(orderUuid, voucherItem.uuid);
1419
- case 17:
1420
- _context15.next = 12;
1421
- break;
1422
- case 19:
1423
- _context15.next = 24;
1424
- break;
1425
- case 21:
1426
- _context15.prev = 21;
1427
- _context15.t0 = _context15["catch"](10);
1428
- _iterator5.e(_context15.t0);
1429
- case 24:
1430
- _context15.prev = 24;
1431
- _iterator5.f();
1432
- return _context15.finish(24);
1433
- case 27:
1434
- // 3. 添加新的代金券支付项
1435
- console.log('[PaymentModule] 添加新的代金券支付项:', {
1436
- orderUuid: orderUuid,
1437
- newItemCount: voucherPaymentItems.length
1438
- });
1439
- _iterator6 = _createForOfIteratorHelper(voucherPaymentItems);
1440
- _context15.prev = 29;
1441
- _iterator6.s();
1442
- case 31:
1443
- if ((_step6 = _iterator6.n()).done) {
1444
- _context15.next = 40;
1445
- break;
1446
- }
1447
- _voucherItem = _step6.value;
1448
- if (_voucherItem.voucher_id) {
1449
- _context15.next = 35;
1450
- break;
1451
- }
1452
- throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(_voucherItem)));
1453
- case 35:
1454
- console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
1455
- code: _voucherItem.code,
1456
- amount: _voucherItem.amount,
1457
- voucher_id: _voucherItem.voucher_id,
1458
- order_payment_type: _voucherItem.order_payment_type
1459
- });
1460
- _context15.next = 38;
1461
- return this.addPaymentItemAsync(orderUuid, _voucherItem);
1462
- case 38:
1463
- _context15.next = 31;
1464
- break;
1465
- case 40:
1466
- _context15.next = 45;
1467
- break;
1468
- case 42:
1469
- _context15.prev = 42;
1470
- _context15.t1 = _context15["catch"](29);
1471
- _iterator6.e(_context15.t1);
1472
- case 45:
1473
- _context15.prev = 45;
1474
- _iterator6.f();
1475
- return _context15.finish(45);
1476
- case 48:
1477
- _context15.next = 50;
1478
- return this.getPaymentOrderByUuidAsync(orderUuid);
1479
- case 50:
1480
- updatedOrder = _context15.sent;
1481
- _context15.next = 53;
1482
- return this.core.effects.emit("".concat(this.name, ":onPaymentAdded"), {
1483
- orderUuid: orderUuid,
1484
- order: updatedOrder,
1485
- payment: null // 批量操作不提供单个支付项
1486
- });
1487
- case 53:
1488
- this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
1489
- orderUuid: orderUuid,
1490
- removedVoucherCount: existingVoucherItems.length,
1491
- addedVoucherCount: voucherPaymentItems.length,
1492
- finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
1493
- });
1494
- _context15.next = 61;
1495
- break;
1496
- case 56:
1497
- _context15.prev = 56;
1498
- _context15.t2 = _context15["catch"](1);
1499
- console.error('[PaymentModule] 批量更新代金券支付项失败:', _context15.t2);
1500
- this.logError('updateVoucherPaymentItemsAsync failed', _context15.t2, {
1501
- orderUuid: orderUuid,
1502
- voucherPaymentItems: voucherPaymentItems
1503
- });
1504
- throw _context15.t2;
1505
- case 61:
1501
+ // 2. 删除所有现有的代金券支付项(仅删除未同步的)
1502
+ _iterator6 = _createForOfIteratorHelper(existingVoucherItems);
1503
+ _context16.prev = 12;
1504
+ _iterator6.s();
1505
+ case 14:
1506
+ if ((_step6 = _iterator6.n()).done) {
1507
+ _context16.next = 21;
1508
+ break;
1509
+ }
1510
+ voucherItem = _step6.value;
1511
+ console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
1512
+ _context16.next = 19;
1513
+ return _this5.deletePaymentAsync(orderUuid, voucherItem.uuid);
1514
+ case 19:
1515
+ _context16.next = 14;
1516
+ break;
1517
+ case 21:
1518
+ _context16.next = 26;
1519
+ break;
1520
+ case 23:
1521
+ _context16.prev = 23;
1522
+ _context16.t0 = _context16["catch"](12);
1523
+ _iterator6.e(_context16.t0);
1524
+ case 26:
1525
+ _context16.prev = 26;
1526
+ _iterator6.f();
1527
+ return _context16.finish(26);
1528
+ case 29:
1529
+ _context16.next = 31;
1530
+ return _this5.getPaymentOrderByUuidAsync(orderUuid);
1531
+ case 31:
1532
+ orderAfterDelete = _context16.sent;
1533
+ if (orderAfterDelete) {
1534
+ _context16.next = 34;
1535
+ break;
1536
+ }
1537
+ throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1538
+ case 34:
1539
+ existingActiveVoucherKeys = new Set(orderAfterDelete.payment.filter(function (p) {
1540
+ return p.voucher_id && p.status !== 'voided' && !p.isSynced;
1541
+ }).map(function (p) {
1542
+ return "".concat(p.voucher_id, "|").concat(p.order_payment_type || 'normal');
1543
+ }));
1544
+ console.log('[PaymentModule] 添加新的代金券支付项:', {
1545
+ orderUuid: orderUuid,
1546
+ newItemCount: normalizedVoucherItems.length
1547
+ });
1548
+ _iterator7 = _createForOfIteratorHelper(normalizedVoucherItems);
1549
+ _context16.prev = 37;
1550
+ _iterator7.s();
1551
+ case 39:
1552
+ if ((_step7 = _iterator7.n()).done) {
1553
+ _context16.next = 52;
1554
+ break;
1555
+ }
1556
+ _voucherItem = _step7.value;
1557
+ orderPaymentType = _voucherItem.order_payment_type || 'normal';
1558
+ key = "".concat(_voucherItem.voucher_id, "|").concat(orderPaymentType);
1559
+ if (!existingActiveVoucherKeys.has(key)) {
1560
+ _context16.next = 46;
1561
+ break;
1562
+ }
1563
+ console.warn('[PaymentModule] Skip adding voucher payment item because it already exists (active)', {
1564
+ orderUuid: orderUuid,
1565
+ voucher_id: _voucherItem.voucher_id,
1566
+ order_payment_type: orderPaymentType
1567
+ });
1568
+ return _context16.abrupt("continue", 50);
1569
+ case 46:
1570
+ console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
1571
+ code: _voucherItem.code,
1572
+ amount: _voucherItem.amount,
1573
+ voucher_id: _voucherItem.voucher_id,
1574
+ order_payment_type: orderPaymentType
1575
+ });
1576
+ _context16.next = 49;
1577
+ return _this5.addPaymentItemAsync(orderUuid, _voucherItem);
1578
+ case 49:
1579
+ existingActiveVoucherKeys.add(key);
1580
+ case 50:
1581
+ _context16.next = 39;
1582
+ break;
1583
+ case 52:
1584
+ _context16.next = 57;
1585
+ break;
1586
+ case 54:
1587
+ _context16.prev = 54;
1588
+ _context16.t1 = _context16["catch"](37);
1589
+ _iterator7.e(_context16.t1);
1590
+ case 57:
1591
+ _context16.prev = 57;
1592
+ _iterator7.f();
1593
+ return _context16.finish(57);
1594
+ case 60:
1595
+ _context16.next = 62;
1596
+ return _this5.getPaymentOrderByUuidAsync(orderUuid);
1597
+ case 62:
1598
+ updatedOrder = _context16.sent;
1599
+ _context16.next = 65;
1600
+ return _this5.core.effects.emit("".concat(_this5.name, ":onPaymentAdded"), {
1601
+ orderUuid: orderUuid,
1602
+ order: updatedOrder,
1603
+ payment: null // 批量操作不提供单个支付项
1604
+ });
1605
+ case 65:
1606
+ _this5.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
1607
+ orderUuid: orderUuid,
1608
+ removedVoucherCount: existingVoucherItems.length,
1609
+ addedVoucherCount: normalizedVoucherItems.length,
1610
+ finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
1611
+ });
1612
+ _context16.next = 73;
1613
+ break;
1614
+ case 68:
1615
+ _context16.prev = 68;
1616
+ _context16.t2 = _context16["catch"](3);
1617
+ console.error('[PaymentModule] 批量更新代金券支付项失败:', _context16.t2);
1618
+ _this5.logError('updateVoucherPaymentItemsAsync failed', _context16.t2, {
1619
+ orderUuid: orderUuid,
1620
+ voucherPaymentItems: voucherPaymentItems
1621
+ });
1622
+ throw _context16.t2;
1623
+ case 73:
1624
+ case "end":
1625
+ return _context16.stop();
1626
+ }
1627
+ }, _callee16, null, [[3, 68], [12, 23, 26, 29], [37, 54, 57, 60]]);
1628
+ }))));
1629
+ case 1:
1506
1630
  case "end":
1507
- return _context15.stop();
1631
+ return _context17.stop();
1508
1632
  }
1509
- }, _callee15, this, [[1, 56], [10, 21, 24, 27], [29, 42, 45, 48]]);
1633
+ }, _callee17, this);
1510
1634
  }));
1511
- function updateVoucherPaymentItemsAsync(_x18, _x19) {
1635
+ function updateVoucherPaymentItemsAsync(_x19, _x20) {
1512
1636
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1513
1637
  }
1514
1638
  return updateVoucherPaymentItemsAsync;
@@ -1520,18 +1644,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1520
1644
  }, {
1521
1645
  key: "updatePaymentAsync",
1522
1646
  value: (function () {
1523
- var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentUuid, params) {
1647
+ var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(orderUuid, paymentUuid, params) {
1524
1648
  var order, paymentItem, formattedParams;
1525
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1526
- while (1) switch (_context16.prev = _context16.next) {
1649
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1650
+ while (1) switch (_context18.prev = _context18.next) {
1527
1651
  case 0:
1528
- _context16.prev = 0;
1529
- _context16.next = 3;
1652
+ _context18.prev = 0;
1653
+ _context18.next = 3;
1530
1654
  return this.dbManager.get('order', orderUuid);
1531
1655
  case 3:
1532
- order = _context16.sent;
1656
+ order = _context18.sent;
1533
1657
  if (order) {
1534
- _context16.next = 6;
1658
+ _context18.next = 6;
1535
1659
  break;
1536
1660
  }
1537
1661
  throw new Error('订单不存在');
@@ -1540,7 +1664,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1540
1664
  return payment.uuid === paymentUuid;
1541
1665
  });
1542
1666
  if (!paymentItem) {
1543
- _context16.next = 18;
1667
+ _context18.next = 18;
1544
1668
  break;
1545
1669
  }
1546
1670
  // 如果更新参数中包含 amount,先格式化
@@ -1554,36 +1678,36 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1554
1678
  this.recalculateOrderAmount(order);
1555
1679
 
1556
1680
  // 更新到 IndexDB
1557
- _context16.next = 14;
1681
+ _context18.next = 14;
1558
1682
  return this.dbManager.update('order', order);
1559
1683
  case 14:
1560
- _context16.next = 16;
1684
+ _context18.next = 16;
1561
1685
  return this.core.effects.emit("".concat(this.name, ":onPaymentUpdated"), {
1562
1686
  order: order,
1563
1687
  paymentItem: paymentItem
1564
1688
  });
1565
1689
  case 16:
1566
- _context16.next = 18;
1690
+ _context18.next = 18;
1567
1691
  return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
1568
1692
  action: 'payment_update',
1569
1693
  order: order,
1570
1694
  paymentItem: paymentItem
1571
1695
  });
1572
1696
  case 18:
1573
- _context16.next = 24;
1697
+ _context18.next = 24;
1574
1698
  break;
1575
1699
  case 20:
1576
- _context16.prev = 20;
1577
- _context16.t0 = _context16["catch"](0);
1578
- console.error('[PaymentModule] 更新支付项失败', _context16.t0);
1579
- throw _context16.t0;
1700
+ _context18.prev = 20;
1701
+ _context18.t0 = _context18["catch"](0);
1702
+ console.error('[PaymentModule] 更新支付项失败', _context18.t0);
1703
+ throw _context18.t0;
1580
1704
  case 24:
1581
1705
  case "end":
1582
- return _context16.stop();
1706
+ return _context18.stop();
1583
1707
  }
1584
- }, _callee16, this, [[0, 20]]);
1708
+ }, _callee18, this, [[0, 20]]);
1585
1709
  }));
1586
- function updatePaymentAsync(_x20, _x21, _x22) {
1710
+ function updatePaymentAsync(_x21, _x22, _x23) {
1587
1711
  return _updatePaymentAsync.apply(this, arguments);
1588
1712
  }
1589
1713
  return updatePaymentAsync;
@@ -1595,61 +1719,61 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1595
1719
  }, {
1596
1720
  key: "submitPayAsync",
1597
1721
  value: (function () {
1598
- var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
1599
- var orderToSubmit, order, allOrders, _iterator7, _step7, _order, result;
1600
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1601
- while (1) switch (_context17.prev = _context17.next) {
1722
+ var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
1723
+ var orderToSubmit, order, allOrders, _iterator8, _step8, _order, result;
1724
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1725
+ while (1) switch (_context19.prev = _context19.next) {
1602
1726
  case 0:
1603
1727
  this.logInfo('Starting submitPayAsync', {
1604
1728
  orderUuid: orderUuid
1605
1729
  });
1606
- _context17.prev = 1;
1730
+ _context19.prev = 1;
1607
1731
  if (!orderUuid) {
1608
- _context17.next = 9;
1732
+ _context19.next = 9;
1609
1733
  break;
1610
1734
  }
1611
- _context17.next = 5;
1735
+ _context19.next = 5;
1612
1736
  return this.dbManager.get('order', orderUuid);
1613
1737
  case 5:
1614
- order = _context17.sent;
1738
+ order = _context19.sent;
1615
1739
  orderToSubmit = order ? [order] : [];
1616
- _context17.next = 13;
1740
+ _context19.next = 13;
1617
1741
  break;
1618
1742
  case 9:
1619
- _context17.next = 11;
1743
+ _context19.next = 11;
1620
1744
  return this.dbManager.getAll('order');
1621
1745
  case 11:
1622
- allOrders = _context17.sent;
1746
+ allOrders = _context19.sent;
1623
1747
  // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1624
1748
  orderToSubmit = allOrders.filter(function (order) {
1625
1749
  return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
1626
1750
  });
1627
1751
  case 13:
1628
- _iterator7 = _createForOfIteratorHelper(orderToSubmit);
1629
- _context17.prev = 14;
1630
- _iterator7.s();
1752
+ _iterator8 = _createForOfIteratorHelper(orderToSubmit);
1753
+ _context19.prev = 14;
1754
+ _iterator8.s();
1631
1755
  case 16:
1632
- if ((_step7 = _iterator7.n()).done) {
1633
- _context17.next = 22;
1756
+ if ((_step8 = _iterator8.n()).done) {
1757
+ _context19.next = 22;
1634
1758
  break;
1635
1759
  }
1636
- _order = _step7.value;
1637
- _context17.next = 20;
1760
+ _order = _step8.value;
1761
+ _context19.next = 20;
1638
1762
  return this.submitSingleOrderPayment(_order);
1639
1763
  case 20:
1640
- _context17.next = 16;
1764
+ _context19.next = 16;
1641
1765
  break;
1642
1766
  case 22:
1643
- _context17.next = 27;
1767
+ _context19.next = 27;
1644
1768
  break;
1645
1769
  case 24:
1646
- _context17.prev = 24;
1647
- _context17.t0 = _context17["catch"](14);
1648
- _iterator7.e(_context17.t0);
1770
+ _context19.prev = 24;
1771
+ _context19.t0 = _context19["catch"](14);
1772
+ _iterator8.e(_context19.t0);
1649
1773
  case 27:
1650
- _context17.prev = 27;
1651
- _iterator7.f();
1652
- return _context17.finish(27);
1774
+ _context19.prev = 27;
1775
+ _iterator8.f();
1776
+ return _context19.finish(27);
1653
1777
  case 30:
1654
1778
  result = {
1655
1779
  status: 'success'
@@ -1658,24 +1782,24 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1658
1782
  result: result.status,
1659
1783
  processedOrdersCount: orderToSubmit.length
1660
1784
  });
1661
- return _context17.abrupt("return", result);
1785
+ return _context19.abrupt("return", result);
1662
1786
  case 35:
1663
- _context17.prev = 35;
1664
- _context17.t1 = _context17["catch"](1);
1665
- console.error('[PaymentModule] 提交支付失败', _context17.t1);
1666
- this.logError('submitPayAsync failed', _context17.t1, {
1787
+ _context19.prev = 35;
1788
+ _context19.t1 = _context19["catch"](1);
1789
+ console.error('[PaymentModule] 提交支付失败', _context19.t1);
1790
+ this.logError('submitPayAsync failed', _context19.t1, {
1667
1791
  orderUuid: orderUuid
1668
1792
  });
1669
- return _context17.abrupt("return", {
1793
+ return _context19.abrupt("return", {
1670
1794
  status: 'failed'
1671
1795
  });
1672
1796
  case 40:
1673
1797
  case "end":
1674
- return _context17.stop();
1798
+ return _context19.stop();
1675
1799
  }
1676
- }, _callee17, this, [[1, 35], [14, 24, 27, 30]]);
1800
+ }, _callee19, this, [[1, 35], [14, 24, 27, 30]]);
1677
1801
  }));
1678
- function submitPayAsync(_x23) {
1802
+ function submitPayAsync(_x24) {
1679
1803
  return _submitPayAsync.apply(this, arguments);
1680
1804
  }
1681
1805
  return submitPayAsync;
@@ -1687,12 +1811,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1687
1811
  }, {
1688
1812
  key: "submitSingleOrderPayment",
1689
1813
  value: (function () {
1690
- var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(order) {
1814
+ var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(order) {
1691
1815
  var paymentData, totalPaidAmount, orderTotalAmount;
1692
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1693
- while (1) switch (_context18.prev = _context18.next) {
1816
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1817
+ while (1) switch (_context20.prev = _context20.next) {
1694
1818
  case 0:
1695
- _context18.prev = 0;
1819
+ _context20.prev = 0;
1696
1820
  paymentData = {
1697
1821
  payments: order.payment.map(function (payment) {
1698
1822
  return {
@@ -1728,11 +1852,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1728
1852
  paymentData.payment_status = order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid';
1729
1853
 
1730
1854
  // 更新订单状态到数据库
1731
- _context18.next = 8;
1855
+ _context20.next = 8;
1732
1856
  return this.dbManager.update('order', order);
1733
1857
  case 8:
1734
1858
  if (!(paymentData.payments.length === 0)) {
1735
- _context18.next = 12;
1859
+ _context20.next = 12;
1736
1860
  break;
1737
1861
  }
1738
1862
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u652F\u4ED8\u5904\u7406"));
@@ -1740,31 +1864,31 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1740
1864
  orderUuid: order.uuid,
1741
1865
  orderId: order.order_id
1742
1866
  });
1743
- return _context18.abrupt("return");
1867
+ return _context20.abrupt("return");
1744
1868
  case 12:
1745
- _context18.next = 14;
1869
+ _context20.next = 14;
1746
1870
  return this.core.effects.emit("".concat(this.name, ":onPaymentSubmitted"), order);
1747
1871
  case 14:
1748
- _context18.next = 16;
1872
+ _context20.next = 16;
1749
1873
  return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
1750
1874
  action: 'submit',
1751
1875
  order: order
1752
1876
  });
1753
1877
  case 16:
1754
- _context18.next = 22;
1878
+ _context20.next = 22;
1755
1879
  break;
1756
1880
  case 18:
1757
- _context18.prev = 18;
1758
- _context18.t0 = _context18["catch"](0);
1759
- console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context18.t0);
1760
- throw _context18.t0;
1881
+ _context20.prev = 18;
1882
+ _context20.t0 = _context20["catch"](0);
1883
+ console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context20.t0);
1884
+ throw _context20.t0;
1761
1885
  case 22:
1762
1886
  case "end":
1763
- return _context18.stop();
1887
+ return _context20.stop();
1764
1888
  }
1765
- }, _callee18, this, [[0, 18]]);
1889
+ }, _callee20, this, [[0, 18]]);
1766
1890
  }));
1767
- function submitSingleOrderPayment(_x24) {
1891
+ function submitSingleOrderPayment(_x25) {
1768
1892
  return _submitSingleOrderPayment.apply(this, arguments);
1769
1893
  }
1770
1894
  return submitSingleOrderPayment;
@@ -1776,29 +1900,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1776
1900
  }, {
1777
1901
  key: "getRemainingOrderAmountAsync",
1778
1902
  value: (function () {
1779
- var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
1903
+ var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(orderUuid) {
1780
1904
  var order;
1781
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1782
- while (1) switch (_context19.prev = _context19.next) {
1905
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1906
+ while (1) switch (_context21.prev = _context21.next) {
1783
1907
  case 0:
1784
- _context19.next = 2;
1908
+ _context21.next = 2;
1785
1909
  return this.getPaymentOrderByUuidAsync(orderUuid);
1786
1910
  case 2:
1787
- order = _context19.sent;
1911
+ order = _context21.sent;
1788
1912
  if (order) {
1789
- _context19.next = 5;
1913
+ _context21.next = 5;
1790
1914
  break;
1791
1915
  }
1792
1916
  throw new Error('订单不存在');
1793
1917
  case 5:
1794
- return _context19.abrupt("return", new Decimal(order.expect_amount).toNumber());
1918
+ return _context21.abrupt("return", new Decimal(order.expect_amount).toNumber());
1795
1919
  case 6:
1796
1920
  case "end":
1797
- return _context19.stop();
1921
+ return _context21.stop();
1798
1922
  }
1799
- }, _callee19, this);
1923
+ }, _callee21, this);
1800
1924
  }));
1801
- function getRemainingOrderAmountAsync(_x25) {
1925
+ function getRemainingOrderAmountAsync(_x26) {
1802
1926
  return _getRemainingOrderAmountAsync.apply(this, arguments);
1803
1927
  }
1804
1928
  return getRemainingOrderAmountAsync;
@@ -1810,65 +1934,65 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1810
1934
  }, {
1811
1935
  key: "getRemainingOrderAmountWithInputAsync",
1812
1936
  value: (function () {
1813
- var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(inputAmount, orderUuid) {
1937
+ var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(inputAmount, orderUuid) {
1814
1938
  var order, inputDecimal;
1815
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1816
- while (1) switch (_context20.prev = _context20.next) {
1939
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1940
+ while (1) switch (_context22.prev = _context22.next) {
1817
1941
  case 0:
1818
- _context20.next = 2;
1942
+ _context22.next = 2;
1819
1943
  return this.getPaymentOrderByUuidAsync(orderUuid);
1820
1944
  case 2:
1821
- order = _context20.sent;
1945
+ order = _context22.sent;
1822
1946
  if (order) {
1823
- _context20.next = 5;
1947
+ _context22.next = 5;
1824
1948
  break;
1825
1949
  }
1826
1950
  throw new Error('订单不存在');
1827
1951
  case 5:
1828
1952
  if (!(inputAmount === null || inputAmount === undefined)) {
1829
- _context20.next = 7;
1953
+ _context22.next = 7;
1830
1954
  break;
1831
1955
  }
1832
- return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1956
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1833
1957
  case 7:
1834
1958
  if (!(typeof inputAmount === 'string')) {
1835
- _context20.next = 10;
1959
+ _context22.next = 10;
1836
1960
  break;
1837
1961
  }
1838
1962
  if (!(inputAmount.trim() === '')) {
1839
- _context20.next = 10;
1963
+ _context22.next = 10;
1840
1964
  break;
1841
1965
  }
1842
- return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1966
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1843
1967
  case 10:
1844
1968
  if (!(typeof inputAmount === 'number')) {
1845
- _context20.next = 14;
1969
+ _context22.next = 14;
1846
1970
  break;
1847
1971
  }
1848
1972
  if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
1849
- _context20.next = 14;
1973
+ _context22.next = 14;
1850
1974
  break;
1851
1975
  }
1852
1976
  // 如果输入是 NaN 或无穷大,返回原始的待付金额
1853
1977
  console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1854
- return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1978
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1855
1979
  case 14:
1856
- _context20.prev = 14;
1980
+ _context22.prev = 14;
1857
1981
  inputDecimal = new Decimal(inputAmount);
1858
- return _context20.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1982
+ return _context22.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1859
1983
  case 19:
1860
- _context20.prev = 19;
1861
- _context20.t0 = _context20["catch"](14);
1984
+ _context22.prev = 19;
1985
+ _context22.t0 = _context22["catch"](14);
1862
1986
  // 如果输入不是有效的数字,返回原始的待付金额
1863
1987
  console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1864
- return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1988
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1865
1989
  case 23:
1866
1990
  case "end":
1867
- return _context20.stop();
1991
+ return _context22.stop();
1868
1992
  }
1869
- }, _callee20, this, [[14, 19]]);
1993
+ }, _callee22, this, [[14, 19]]);
1870
1994
  }));
1871
- function getRemainingOrderAmountWithInputAsync(_x26, _x27) {
1995
+ function getRemainingOrderAmountWithInputAsync(_x27, _x28) {
1872
1996
  return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
1873
1997
  }
1874
1998
  return getRemainingOrderAmountWithInputAsync;
@@ -1891,9 +2015,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1891
2015
  // 计算有效支付金额:支付金额 + 抹零金额的绝对值
1892
2016
  // 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
1893
2017
  // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
2018
+ // 例2:amount=15,rounding_amount=0.2,有效支付 14.8
1894
2019
  var paymentAmount = new Decimal(payment.amount || 0);
1895
2020
  var roundingAmount = new Decimal(payment.rounding_amount || 0);
1896
- var effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
2021
+ var effectiveAmount = paymentAmount.minus(roundingAmount);
1897
2022
  return sum.plus(effectiveAmount);
1898
2023
  } catch (error) {
1899
2024
  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"));
@@ -1921,7 +2046,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1921
2046
  code: p.code,
1922
2047
  amount: p.amount,
1923
2048
  rounding_amount: p.rounding_amount || '0.00',
1924
- effective_amount: new Decimal(p.amount || 0).plus(new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
2049
+ effective_amount: new Decimal(p.amount || 0).minus(new Decimal(p.rounding_amount || 0)).toFixed(2)
1925
2050
  };
1926
2051
  }),
1927
2052
  说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
@@ -1934,29 +2059,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1934
2059
  }, {
1935
2060
  key: "getCashPaymentMethod",
1936
2061
  value: (function () {
1937
- var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2062
+ var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1938
2063
  var payMethods;
1939
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1940
- while (1) switch (_context21.prev = _context21.next) {
2064
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2065
+ while (1) switch (_context23.prev = _context23.next) {
1941
2066
  case 0:
1942
- _context21.prev = 0;
1943
- _context21.next = 3;
2067
+ _context23.prev = 0;
2068
+ _context23.next = 3;
1944
2069
  return this.dbManager.getAll('pay_method');
1945
2070
  case 3:
1946
- payMethods = _context21.sent;
1947
- return _context21.abrupt("return", payMethods.find(function (method) {
2071
+ payMethods = _context23.sent;
2072
+ return _context23.abrupt("return", payMethods.find(function (method) {
1948
2073
  return method.code === PaymentMethodType.Cash;
1949
2074
  }) || null);
1950
2075
  case 7:
1951
- _context21.prev = 7;
1952
- _context21.t0 = _context21["catch"](0);
1953
- console.error('[PaymentModule] 获取现金支付方式失败', _context21.t0);
1954
- return _context21.abrupt("return", null);
2076
+ _context23.prev = 7;
2077
+ _context23.t0 = _context23["catch"](0);
2078
+ console.error('[PaymentModule] 获取现金支付方式失败', _context23.t0);
2079
+ return _context23.abrupt("return", null);
1955
2080
  case 11:
1956
2081
  case "end":
1957
- return _context21.stop();
2082
+ return _context23.stop();
1958
2083
  }
1959
- }, _callee21, this, [[0, 7]]);
2084
+ }, _callee23, this, [[0, 7]]);
1960
2085
  }));
1961
2086
  function getCashPaymentMethod() {
1962
2087
  return _getCashPaymentMethod.apply(this, arguments);
@@ -1970,29 +2095,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1970
2095
  }, {
1971
2096
  key: "getEftposPaymentMethod",
1972
2097
  value: (function () {
1973
- var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2098
+ var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1974
2099
  var payMethods;
1975
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1976
- while (1) switch (_context22.prev = _context22.next) {
2100
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2101
+ while (1) switch (_context24.prev = _context24.next) {
1977
2102
  case 0:
1978
- _context22.prev = 0;
1979
- _context22.next = 3;
2103
+ _context24.prev = 0;
2104
+ _context24.next = 3;
1980
2105
  return this.dbManager.getAll('pay_method');
1981
2106
  case 3:
1982
- payMethods = _context22.sent;
1983
- return _context22.abrupt("return", payMethods.find(function (method) {
2107
+ payMethods = _context24.sent;
2108
+ return _context24.abrupt("return", payMethods.find(function (method) {
1984
2109
  return method.code === PaymentMethodType.Eftpos;
1985
2110
  }) || null);
1986
2111
  case 7:
1987
- _context22.prev = 7;
1988
- _context22.t0 = _context22["catch"](0);
1989
- console.error('[PaymentModule] 获取Eftpos支付方式失败', _context22.t0);
1990
- return _context22.abrupt("return", null);
2112
+ _context24.prev = 7;
2113
+ _context24.t0 = _context24["catch"](0);
2114
+ console.error('[PaymentModule] 获取Eftpos支付方式失败', _context24.t0);
2115
+ return _context24.abrupt("return", null);
1991
2116
  case 11:
1992
2117
  case "end":
1993
- return _context22.stop();
2118
+ return _context24.stop();
1994
2119
  }
1995
- }, _callee22, this, [[0, 7]]);
2120
+ }, _callee24, this, [[0, 7]]);
1996
2121
  }));
1997
2122
  function getEftposPaymentMethod() {
1998
2123
  return _getEftposPaymentMethod.apply(this, arguments);
@@ -2006,29 +2131,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2006
2131
  }, {
2007
2132
  key: "getWalletPaymentMethod",
2008
2133
  value: (function () {
2009
- var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2134
+ var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2010
2135
  var payMethods;
2011
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2012
- while (1) switch (_context23.prev = _context23.next) {
2136
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2137
+ while (1) switch (_context25.prev = _context25.next) {
2013
2138
  case 0:
2014
- _context23.prev = 0;
2015
- _context23.next = 3;
2139
+ _context25.prev = 0;
2140
+ _context25.next = 3;
2016
2141
  return this.dbManager.getAll('pay_method');
2017
2142
  case 3:
2018
- payMethods = _context23.sent;
2019
- return _context23.abrupt("return", payMethods.find(function (method) {
2143
+ payMethods = _context25.sent;
2144
+ return _context25.abrupt("return", payMethods.find(function (method) {
2020
2145
  return method.code === PaymentMethodType.Wallet;
2021
2146
  }) || null);
2022
2147
  case 7:
2023
- _context23.prev = 7;
2024
- _context23.t0 = _context23["catch"](0);
2025
- console.error('[PaymentModule] 获取钱包支付方式失败', _context23.t0);
2026
- return _context23.abrupt("return", null);
2148
+ _context25.prev = 7;
2149
+ _context25.t0 = _context25["catch"](0);
2150
+ console.error('[PaymentModule] 获取钱包支付方式失败', _context25.t0);
2151
+ return _context25.abrupt("return", null);
2027
2152
  case 11:
2028
2153
  case "end":
2029
- return _context23.stop();
2154
+ return _context25.stop();
2030
2155
  }
2031
- }, _callee23, this, [[0, 7]]);
2156
+ }, _callee25, this, [[0, 7]]);
2032
2157
  }));
2033
2158
  function getWalletPaymentMethod() {
2034
2159
  return _getWalletPaymentMethod.apply(this, arguments);
@@ -2042,38 +2167,38 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2042
2167
  }, {
2043
2168
  key: "ensurePaymentTables",
2044
2169
  value: (function () {
2045
- var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2046
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2047
- while (1) switch (_context24.prev = _context24.next) {
2170
+ var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2171
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2172
+ while (1) switch (_context26.prev = _context26.next) {
2048
2173
  case 0:
2049
- _context24.prev = 0;
2050
- _context24.next = 3;
2174
+ _context26.prev = 0;
2175
+ _context26.next = 3;
2051
2176
  return this.dbManager.getAll('pay_method');
2052
2177
  case 3:
2053
- _context24.next = 9;
2178
+ _context26.next = 9;
2054
2179
  break;
2055
2180
  case 5:
2056
- _context24.prev = 5;
2057
- _context24.t0 = _context24["catch"](0);
2181
+ _context26.prev = 5;
2182
+ _context26.t0 = _context26["catch"](0);
2058
2183
  console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
2059
2184
  console.warn('{ name: "pay_method", keyPath: "id" }');
2060
2185
  case 9:
2061
- _context24.prev = 9;
2062
- _context24.next = 12;
2186
+ _context26.prev = 9;
2187
+ _context26.next = 12;
2063
2188
  return this.dbManager.getAll('order');
2064
2189
  case 12:
2065
- _context24.next = 18;
2190
+ _context26.next = 18;
2066
2191
  break;
2067
2192
  case 14:
2068
- _context24.prev = 14;
2069
- _context24.t1 = _context24["catch"](9);
2193
+ _context26.prev = 14;
2194
+ _context26.t1 = _context26["catch"](9);
2070
2195
  console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
2071
2196
  console.warn('{ name: "order", keyPath: "uuid" }');
2072
2197
  case 18:
2073
2198
  case "end":
2074
- return _context24.stop();
2199
+ return _context26.stop();
2075
2200
  }
2076
- }, _callee24, this, [[0, 5], [9, 14]]);
2201
+ }, _callee26, this, [[0, 5], [9, 14]]);
2077
2202
  }));
2078
2203
  function ensurePaymentTables() {
2079
2204
  return _ensurePaymentTables.apply(this, arguments);
@@ -2087,29 +2212,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2087
2212
  }, {
2088
2213
  key: "getPartiallyPaidOrdersAsync",
2089
2214
  value: (function () {
2090
- var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2215
+ var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2091
2216
  var allOrders;
2092
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2093
- while (1) switch (_context25.prev = _context25.next) {
2217
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2218
+ while (1) switch (_context27.prev = _context27.next) {
2094
2219
  case 0:
2095
- _context25.prev = 0;
2096
- _context25.next = 3;
2220
+ _context27.prev = 0;
2221
+ _context27.next = 3;
2097
2222
  return this.dbManager.getAll('order');
2098
2223
  case 3:
2099
- allOrders = _context25.sent;
2100
- return _context25.abrupt("return", allOrders.filter(function (order) {
2224
+ allOrders = _context27.sent;
2225
+ return _context27.abrupt("return", allOrders.filter(function (order) {
2101
2226
  return order.payment_status === PaymentStatus.PartiallyPaid;
2102
2227
  }));
2103
2228
  case 7:
2104
- _context25.prev = 7;
2105
- _context25.t0 = _context25["catch"](0);
2106
- console.error('[PaymentModule] 获取部分支付订单失败', _context25.t0);
2107
- return _context25.abrupt("return", []);
2229
+ _context27.prev = 7;
2230
+ _context27.t0 = _context27["catch"](0);
2231
+ console.error('[PaymentModule] 获取部分支付订单失败', _context27.t0);
2232
+ return _context27.abrupt("return", []);
2108
2233
  case 11:
2109
2234
  case "end":
2110
- return _context25.stop();
2235
+ return _context27.stop();
2111
2236
  }
2112
- }, _callee25, this, [[0, 7]]);
2237
+ }, _callee27, this, [[0, 7]]);
2113
2238
  }));
2114
2239
  function getPartiallyPaidOrdersAsync() {
2115
2240
  return _getPartiallyPaidOrdersAsync.apply(this, arguments);
@@ -2130,17 +2255,17 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2130
2255
  }, {
2131
2256
  key: "roundAmountAsync",
2132
2257
  value: function () {
2133
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(originalAmount, interval, rule) {
2258
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(originalAmount, interval, rule) {
2134
2259
  var amount, roundingInterval, supportedIntervals, intervalValue, baseValue, roundedValue, finalAmount, originalAmountStr, roundedAmountStr, roundingDifference, roundingDifferenceStr;
2135
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2136
- while (1) switch (_context26.prev = _context26.next) {
2260
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2261
+ while (1) switch (_context28.prev = _context28.next) {
2137
2262
  case 0:
2138
- _context26.prev = 0;
2263
+ _context28.prev = 0;
2139
2264
  // 参数验证
2140
2265
  amount = new Decimal(originalAmount);
2141
2266
  roundingInterval = new Decimal(interval);
2142
2267
  if (!roundingInterval.lte(0)) {
2143
- _context26.next = 5;
2268
+ _context28.next = 5;
2144
2269
  break;
2145
2270
  }
2146
2271
  throw new Error('舍入间隔必须大于 0');
@@ -2155,25 +2280,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2155
2280
  // 计算基础值:x / interval
2156
2281
  baseValue = amount.div(roundingInterval);
2157
2282
  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));
2158
- _context26.t0 = rule;
2159
- _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;
2283
+ _context28.t0 = rule;
2284
+ _context28.next = _context28.t0 === RoundingRule.Standard ? 13 : _context28.t0 === 'standard' ? 13 : _context28.t0 === RoundingRule.StandardDown ? 15 : _context28.t0 === 'standard_down' ? 15 : _context28.t0 === RoundingRule.AlwaysUp ? 17 : _context28.t0 === 'always_up' ? 17 : _context28.t0 === RoundingRule.AlwaysDown ? 19 : _context28.t0 === 'always_down' ? 19 : 21;
2160
2285
  break;
2161
2286
  case 13:
2162
2287
  // 标准舍入(中点向上)
2163
2288
  roundedValue = this.standardRound(baseValue, true);
2164
- return _context26.abrupt("break", 22);
2289
+ return _context28.abrupt("break", 22);
2165
2290
  case 15:
2166
2291
  // 标准舍入(中点向下)
2167
2292
  roundedValue = this.standardRound(baseValue, false);
2168
- return _context26.abrupt("break", 22);
2293
+ return _context28.abrupt("break", 22);
2169
2294
  case 17:
2170
2295
  // 总是向上舍入
2171
2296
  roundedValue = baseValue.ceil();
2172
- return _context26.abrupt("break", 22);
2297
+ return _context28.abrupt("break", 22);
2173
2298
  case 19:
2174
2299
  // 总是向下舍入
2175
2300
  roundedValue = baseValue.floor();
2176
- return _context26.abrupt("break", 22);
2301
+ return _context28.abrupt("break", 22);
2177
2302
  case 21:
2178
2303
  throw new Error("\u4E0D\u652F\u6301\u7684\u820D\u5165\u89C4\u5219: ".concat(rule));
2179
2304
  case 22:
@@ -2181,11 +2306,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2181
2306
  finalAmount = roundedValue.mul(roundingInterval);
2182
2307
  originalAmountStr = amount.toFixed(2); // 如果最终金额是 0 元,则不采用舍入金额,返回原始金额
2183
2308
  if (!finalAmount.eq(0)) {
2184
- _context26.next = 27;
2309
+ _context28.next = 27;
2185
2310
  break;
2186
2311
  }
2187
2312
  console.log("[PaymentModule] \u6700\u7EC8\u91D1\u989D\u4E3A0\uFF0C\u8FD4\u56DE\u539F\u59CB\u91D1\u989D: ".concat(originalAmountStr));
2188
- return _context26.abrupt("return", {
2313
+ return _context28.abrupt("return", {
2189
2314
  originalAmount: originalAmountStr,
2190
2315
  roundedAmount: originalAmountStr,
2191
2316
  roundingDifference: '0.00'
@@ -2195,23 +2320,23 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2195
2320
  roundingDifference = finalAmount.sub(amount);
2196
2321
  roundingDifferenceStr = roundingDifference.toFixed(2);
2197
2322
  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));
2198
- return _context26.abrupt("return", {
2323
+ return _context28.abrupt("return", {
2199
2324
  originalAmount: originalAmountStr,
2200
2325
  roundedAmount: roundedAmountStr,
2201
2326
  roundingDifference: roundingDifferenceStr
2202
2327
  });
2203
2328
  case 34:
2204
- _context26.prev = 34;
2205
- _context26.t1 = _context26["catch"](0);
2206
- console.error('[PaymentModule] 金额舍入失败:', _context26.t1);
2207
- throw new Error("\u91D1\u989D\u820D\u5165\u5931\u8D25: ".concat(_context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1)));
2329
+ _context28.prev = 34;
2330
+ _context28.t1 = _context28["catch"](0);
2331
+ console.error('[PaymentModule] 金额舍入失败:', _context28.t1);
2332
+ throw new Error("\u91D1\u989D\u820D\u5165\u5931\u8D25: ".concat(_context28.t1 instanceof Error ? _context28.t1.message : String(_context28.t1)));
2208
2333
  case 38:
2209
2334
  case "end":
2210
- return _context26.stop();
2335
+ return _context28.stop();
2211
2336
  }
2212
- }, _callee26, this, [[0, 34]]);
2337
+ }, _callee28, this, [[0, 34]]);
2213
2338
  }));
2214
- function roundAmountAsync(_x28, _x29, _x30) {
2339
+ function roundAmountAsync(_x29, _x30, _x31) {
2215
2340
  return _roundAmountAsync.apply(this, arguments);
2216
2341
  }
2217
2342
  return roundAmountAsync;