@pisell/pisellos 3.0.76 → 3.0.77

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