@pisell/pisellos 0.0.568 → 0.10.1

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 (588) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +2 -2
  13. package/dist/modules/BaseModule.js +12 -14
  14. package/dist/modules/BookingContext/index.d.ts +48 -0
  15. package/dist/modules/BookingContext/index.js +566 -0
  16. package/dist/modules/BookingContext/types.d.ts +102 -0
  17. package/dist/modules/BookingContext/types.js +51 -0
  18. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  19. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  20. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  21. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  22. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  23. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  24. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  25. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  26. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  27. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  28. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  29. package/dist/modules/BookingContext/utils/index.js +11 -0
  30. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  31. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  32. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  33. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  34. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  35. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  36. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  37. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  38. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  39. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  40. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  41. package/dist/modules/BookingContext/utils/resources.js +486 -0
  42. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  43. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  44. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  45. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  46. package/dist/modules/Cart/index.js +3 -0
  47. package/dist/modules/Cart/utils/cartProduct.js +27 -5
  48. package/dist/modules/Cart/utils/cartResource.js +0 -2
  49. package/dist/modules/Cart/utils/changePrice.js +11 -11
  50. package/dist/modules/Customer/index.d.ts +20 -0
  51. package/dist/modules/Customer/index.js +172 -83
  52. package/dist/modules/Customer/types.d.ts +2 -0
  53. package/dist/modules/Date/index.js +5 -1
  54. package/dist/modules/Discount/index.d.ts +2 -2
  55. package/dist/modules/Discount/index.js +43 -30
  56. package/dist/modules/Discount/types.d.ts +1 -1
  57. package/dist/modules/OpenData/index.d.ts +8 -0
  58. package/dist/modules/OpenData/index.js +38 -16
  59. package/dist/modules/Order/index.d.ts +449 -24
  60. package/dist/modules/Order/index.js +5460 -574
  61. package/dist/modules/Order/types.d.ts +693 -88
  62. package/dist/modules/Order/types.js +68 -1
  63. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  64. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  65. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  66. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  67. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  68. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  69. package/dist/modules/Order/utils.d.ts +167 -18
  70. package/dist/modules/Order/utils.js +960 -165
  71. package/dist/modules/Payment/index.d.ts +10 -9
  72. package/dist/modules/Payment/index.js +573 -746
  73. package/dist/modules/Payment/types.d.ts +44 -24
  74. package/dist/modules/Payment/utils.d.ts +1 -1
  75. package/dist/modules/Payment/utils.js +4 -3
  76. package/dist/modules/Payment/walletpass.d.ts +0 -2
  77. package/dist/modules/Payment/walletpass.js +49 -33
  78. package/dist/modules/Product/types.d.ts +29 -7
  79. package/dist/modules/ProductList/index.d.ts +17 -13
  80. package/dist/modules/ProductList/index.js +182 -81
  81. package/dist/modules/ProductList/types.d.ts +16 -0
  82. package/dist/modules/Quotation/index.d.ts +22 -2
  83. package/dist/modules/Quotation/index.js +108 -42
  84. package/dist/modules/Quotation/types.d.ts +19 -0
  85. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  86. package/dist/modules/ResourcePlanner/index.js +181 -0
  87. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  88. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  89. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  90. package/dist/modules/ResourcePlanner/types.js +1 -0
  91. package/dist/modules/Rules/index.d.ts +8 -10
  92. package/dist/modules/Rules/index.js +324 -513
  93. package/dist/modules/Rules/types.d.ts +14 -3
  94. package/dist/modules/SalesSummary/index.d.ts +23 -26
  95. package/dist/modules/SalesSummary/index.js +152 -46
  96. package/dist/modules/SalesSummary/types.d.ts +9 -1
  97. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  98. package/dist/modules/SalesSummary/utils.js +804 -165
  99. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
  100. package/dist/modules/Schedule/index.d.ts +18 -5
  101. package/dist/modules/Schedule/index.js +79 -24
  102. package/dist/modules/Schedule/types.d.ts +2 -0
  103. package/dist/modules/Schedule/utils.js +1 -0
  104. package/dist/modules/Step/index.js +1 -0
  105. package/dist/modules/Summary/index.js +4 -3
  106. package/dist/modules/Summary/utils.js +22 -43
  107. package/dist/modules/SurchargeList/index.d.ts +18 -0
  108. package/dist/modules/SurchargeList/index.js +185 -0
  109. package/dist/modules/SurchargeList/types.d.ts +15 -0
  110. package/dist/modules/SurchargeList/types.js +1 -0
  111. package/dist/modules/index.d.ts +3 -0
  112. package/dist/modules/index.js +4 -1
  113. package/dist/plugins/app.d.ts +2 -0
  114. package/dist/plugins/request.d.ts +1 -0
  115. package/dist/plugins/request.js +4 -1
  116. package/dist/plugins/window.js +6 -2
  117. package/dist/server/index.d.ts +462 -8
  118. package/dist/server/index.js +6168 -680
  119. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  120. package/dist/server/modules/floor-plan/index.js +595 -0
  121. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  122. package/dist/server/modules/floor-plan/types.js +13 -0
  123. package/dist/server/modules/index.d.ts +7 -2
  124. package/dist/server/modules/index.js +6 -0
  125. package/dist/server/modules/menu/index.js +41 -32
  126. package/dist/server/modules/order/index.d.ts +207 -14
  127. package/dist/server/modules/order/index.js +2328 -379
  128. package/dist/server/modules/order/types.d.ts +76 -5
  129. package/dist/server/modules/order/types.js +14 -1
  130. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  131. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  132. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  133. package/dist/server/modules/payment/index.d.ts +28 -0
  134. package/dist/server/modules/payment/index.js +305 -0
  135. package/dist/server/modules/payment/types.d.ts +9 -0
  136. package/dist/server/modules/payment/types.js +1 -0
  137. package/dist/server/modules/products/index.d.ts +105 -14
  138. package/dist/server/modules/products/index.js +1416 -521
  139. package/dist/server/modules/products/types.d.ts +34 -1
  140. package/dist/server/modules/products/types.js +4 -0
  141. package/dist/server/modules/quotation/index.d.ts +39 -0
  142. package/dist/server/modules/quotation/index.js +298 -77
  143. package/dist/server/modules/resource/index.d.ts +2 -3
  144. package/dist/server/modules/resource/index.js +109 -86
  145. package/dist/server/modules/schedule/index.d.ts +6 -4
  146. package/dist/server/modules/schedule/index.js +145 -106
  147. package/dist/server/test.json +713 -0
  148. package/dist/server/types.d.ts +2 -0
  149. package/dist/server/utils/product.js +3 -2
  150. package/dist/server/utils/small-ticket.d.ts +71 -0
  151. package/dist/server/utils/small-ticket.js +963 -0
  152. package/dist/solution/BaseSales/index.d.ts +378 -0
  153. package/dist/solution/BaseSales/index.js +4009 -0
  154. package/dist/solution/BaseSales/types.d.ts +394 -0
  155. package/dist/solution/BaseSales/types.js +40 -0
  156. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  157. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  158. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  159. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  160. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  161. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  162. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  163. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  164. package/dist/solution/BaseSales/utils.d.ts +40 -0
  165. package/dist/solution/BaseSales/utils.js +263 -0
  166. package/dist/solution/BookingByStep/index.d.ts +1 -1
  167. package/dist/solution/BookingByStep/index.js +60 -11
  168. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  169. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  170. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  171. package/dist/solution/BookingTicket/index.d.ts +393 -24
  172. package/dist/solution/BookingTicket/index.js +2508 -443
  173. package/dist/solution/BookingTicket/types.d.ts +191 -6
  174. package/dist/solution/BookingTicket/types.js +83 -10
  175. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  176. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  177. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  178. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  179. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  180. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  181. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  182. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  183. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  184. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  185. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  186. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  187. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  189. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  190. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  191. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  192. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
  193. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  194. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  195. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  196. package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
  197. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  198. package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
  199. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  200. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  201. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  202. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  203. package/dist/solution/BuyTickets/index.js +12 -9
  204. package/dist/solution/Checkout/index.d.ts +1 -0
  205. package/dist/solution/Checkout/index.js +275 -209
  206. package/dist/solution/Checkout/utils/index.js +20 -8
  207. package/dist/solution/RegisterAndLogin/config.js +2 -10
  208. package/dist/solution/RegisterAndLogin/index.js +76 -30
  209. package/dist/solution/Sales/index.d.ts +50 -5
  210. package/dist/solution/Sales/index.js +484 -92
  211. package/dist/solution/Sales/types.d.ts +26 -2
  212. package/dist/solution/ScanOrder/index.d.ts +27 -21
  213. package/dist/solution/ScanOrder/index.js +519 -444
  214. package/dist/solution/ScanOrder/types.d.ts +33 -11
  215. package/dist/solution/ScanOrder/types.js +4 -5
  216. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  217. package/dist/solution/ScanOrder/utils.js +109 -34
  218. package/dist/solution/ShopDiscount/index.js +18 -19
  219. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  220. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  221. package/dist/solution/ShopDiscount/utils.js +0 -9
  222. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  223. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  224. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  225. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  226. package/dist/solution/VenueBooking/index.d.ts +32 -51
  227. package/dist/solution/VenueBooking/index.js +741 -808
  228. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  229. package/dist/solution/VenueBooking/types.d.ts +1 -3
  230. package/dist/solution/VenueBooking/types.js +0 -1
  231. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  232. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  233. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  234. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  235. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  236. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  237. package/dist/solution/index.d.ts +2 -0
  238. package/dist/solution/index.js +3 -1
  239. package/dist/types/index.d.ts +12 -2
  240. package/dist/utils/task.js +18 -15
  241. package/dist/utils/watch.js +1 -0
  242. package/lib/apis/picoding.js +0 -2
  243. package/lib/core/index.js +132 -130
  244. package/lib/effects/index.js +57 -46
  245. package/lib/index.d.ts +0 -1
  246. package/lib/index.js +50 -92
  247. package/lib/model/index.js +21 -14
  248. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  249. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  250. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  251. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  252. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  253. package/lib/model/strategy/adapter/index.js +64 -100
  254. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  255. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  256. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  257. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  258. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  259. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  260. package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
  261. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  262. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  263. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  264. package/lib/model/strategy/adapter/type.js +16 -4
  265. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  266. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  267. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  268. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  269. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  270. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  271. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  272. package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
  273. package/lib/model/strategy/engine.js +168 -270
  274. package/lib/model/strategy/index.js +34 -49
  275. package/lib/model/strategy/strategy-example.js +239 -243
  276. package/lib/model/strategy/type.js +40 -100
  277. package/lib/modules/Account/index.js +53 -39
  278. package/lib/modules/Account/types.js +33 -20
  279. package/lib/modules/AccountList/index.js +154 -116
  280. package/lib/modules/AccountList/types.js +31 -30
  281. package/lib/modules/AccountList/utils.js +30 -18
  282. package/lib/modules/BaseModule.d.ts +2 -2
  283. package/lib/modules/BaseModule.js +50 -29
  284. package/lib/modules/BookingContext/index.d.ts +48 -0
  285. package/lib/modules/BookingContext/index.js +368 -0
  286. package/lib/modules/BookingContext/types.d.ts +102 -0
  287. package/lib/modules/BookingContext/types.js +34 -0
  288. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  289. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
  290. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  291. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
  292. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  293. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
  294. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  295. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  296. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  297. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  298. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  299. package/lib/modules/BookingContext/utils/index.js +43 -0
  300. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  301. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  302. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  303. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  304. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  305. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  306. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  307. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  308. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  309. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  310. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  311. package/lib/modules/BookingContext/utils/resources.js +377 -0
  312. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  313. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  314. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  315. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  316. package/lib/modules/Cart/index.js +124 -170
  317. package/lib/modules/Cart/types.js +51 -46
  318. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  319. package/lib/modules/Cart/utils/cartDate.js +61 -56
  320. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  321. package/lib/modules/Cart/utils/cartNote.js +32 -27
  322. package/lib/modules/Cart/utils/cartProduct.js +261 -309
  323. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  324. package/lib/modules/Cart/utils/cartResource.js +78 -72
  325. package/lib/modules/Cart/utils/changePrice.js +59 -31
  326. package/lib/modules/Cart/utils/index.js +48 -106
  327. package/lib/modules/Customer/constants.js +34 -13
  328. package/lib/modules/Customer/index.d.ts +20 -0
  329. package/lib/modules/Customer/index.js +207 -217
  330. package/lib/modules/Customer/types.d.ts +2 -0
  331. package/lib/modules/Customer/types.js +35 -38
  332. package/lib/modules/Date/index.js +115 -116
  333. package/lib/modules/Date/types.js +28 -16
  334. package/lib/modules/Date/utils.js +123 -174
  335. package/lib/modules/Discount/index.d.ts +2 -2
  336. package/lib/modules/Discount/index.js +133 -119
  337. package/lib/modules/Discount/types.d.ts +1 -1
  338. package/lib/modules/Discount/types.js +31 -9
  339. package/lib/modules/Guests/index.js +56 -30
  340. package/lib/modules/Guests/types.js +33 -23
  341. package/lib/modules/Holder/index.js +189 -209
  342. package/lib/modules/Holder/types.js +16 -4
  343. package/lib/modules/Holder/utils.js +49 -20
  344. package/lib/modules/OpenData/index.d.ts +8 -0
  345. package/lib/modules/OpenData/index.js +88 -63
  346. package/lib/modules/OpenData/types.js +16 -4
  347. package/lib/modules/OpenData/utils.js +78 -44
  348. package/lib/modules/Order/index.d.ts +449 -24
  349. package/lib/modules/Order/index.js +4184 -514
  350. package/lib/modules/Order/types.d.ts +693 -88
  351. package/lib/modules/Order/types.js +35 -24
  352. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  353. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  354. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  355. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  356. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  357. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  358. package/lib/modules/Order/utils.d.ts +167 -18
  359. package/lib/modules/Order/utils.js +1085 -414
  360. package/lib/modules/Payment/cash.js +33 -20
  361. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  362. package/lib/modules/Payment/eftpos.js +30 -16
  363. package/lib/modules/Payment/index.d.ts +10 -9
  364. package/lib/modules/Payment/index.js +402 -636
  365. package/lib/modules/Payment/mx51.js +0 -1
  366. package/lib/modules/Payment/types.d.ts +44 -24
  367. package/lib/modules/Payment/types.js +107 -216
  368. package/lib/modules/Payment/utils.d.ts +1 -1
  369. package/lib/modules/Payment/utils.js +50 -52
  370. package/lib/modules/Payment/walletpass.d.ts +0 -2
  371. package/lib/modules/Payment/walletpass.js +216 -221
  372. package/lib/modules/Product/index.js +46 -51
  373. package/lib/modules/Product/types.d.ts +29 -7
  374. package/lib/modules/Product/types.js +16 -4
  375. package/lib/modules/Product/utils.js +33 -32
  376. package/lib/modules/ProductList/index.d.ts +17 -13
  377. package/lib/modules/ProductList/index.js +161 -120
  378. package/lib/modules/ProductList/types.d.ts +16 -0
  379. package/lib/modules/ProductList/types.js +31 -9
  380. package/lib/modules/Quotation/index.d.ts +22 -2
  381. package/lib/modules/Quotation/index.js +154 -64
  382. package/lib/modules/Quotation/types.d.ts +19 -0
  383. package/lib/modules/Quotation/types.js +16 -4
  384. package/lib/modules/Resource/index.js +59 -27
  385. package/lib/modules/Resource/types.js +32 -22
  386. package/lib/modules/Resource/utils.js +38 -30
  387. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  388. package/lib/modules/ResourcePlanner/index.js +148 -0
  389. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  390. package/lib/modules/ResourcePlanner/planner.js +933 -0
  391. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  392. package/lib/modules/ResourcePlanner/types.js +17 -0
  393. package/lib/modules/Rules/index.d.ts +8 -10
  394. package/lib/modules/Rules/index.js +960 -1440
  395. package/lib/modules/Rules/types.d.ts +14 -3
  396. package/lib/modules/Rules/types.js +40 -17
  397. package/lib/modules/SalesSummary/index.d.ts +23 -26
  398. package/lib/modules/SalesSummary/index.js +134 -61
  399. package/lib/modules/SalesSummary/types.d.ts +9 -1
  400. package/lib/modules/SalesSummary/types.js +16 -4
  401. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  402. package/lib/modules/SalesSummary/utils.js +814 -233
  403. package/lib/modules/ScanOrderLogger/index.js +79 -59
  404. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  405. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  406. package/lib/modules/ScanOrderLogger/types.js +16 -4
  407. package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
  408. package/lib/modules/Schedule/index.d.ts +18 -5
  409. package/lib/modules/Schedule/index.js +153 -104
  410. package/lib/modules/Schedule/type.js +16 -4
  411. package/lib/modules/Schedule/types.d.ts +2 -0
  412. package/lib/modules/Schedule/types.js +16 -4
  413. package/lib/modules/Schedule/utils.js +291 -433
  414. package/lib/modules/Step/index.js +52 -40
  415. package/lib/modules/Step/tyeps.js +16 -4
  416. package/lib/modules/Summary/index.js +71 -66
  417. package/lib/modules/Summary/types.js +16 -4
  418. package/lib/modules/Summary/utils.js +418 -791
  419. package/lib/modules/SurchargeList/index.d.ts +18 -0
  420. package/lib/modules/SurchargeList/index.js +109 -0
  421. package/lib/modules/SurchargeList/types.d.ts +15 -0
  422. package/lib/modules/SurchargeList/types.js +17 -0
  423. package/lib/modules/index.d.ts +3 -0
  424. package/lib/modules/index.js +63 -212
  425. package/lib/plugins/app.d.ts +2 -0
  426. package/lib/plugins/app.js +16 -4
  427. package/lib/plugins/index.js +25 -36
  428. package/lib/plugins/request.d.ts +1 -0
  429. package/lib/plugins/request.js +126 -137
  430. package/lib/plugins/shopStore.js +16 -4
  431. package/lib/plugins/user.js +16 -4
  432. package/lib/plugins/window.js +179 -171
  433. package/lib/server/index.d.ts +462 -8
  434. package/lib/server/index.js +4520 -1162
  435. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  436. package/lib/server/modules/floor-plan/index.js +327 -0
  437. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  438. package/lib/server/modules/floor-plan/types.js +34 -0
  439. package/lib/server/modules/index.d.ts +7 -2
  440. package/lib/server/modules/index.js +67 -84
  441. package/lib/server/modules/menu/index.js +122 -146
  442. package/lib/server/modules/menu/types.js +31 -18
  443. package/lib/server/modules/order/index.d.ts +207 -14
  444. package/lib/server/modules/order/index.js +1543 -285
  445. package/lib/server/modules/order/types.d.ts +76 -5
  446. package/lib/server/modules/order/types.js +32 -107
  447. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  448. package/lib/server/modules/order/utils/filterBookings.js +259 -176
  449. package/lib/server/modules/order/utils/filterOrders.js +293 -94
  450. package/lib/server/modules/payment/index.d.ts +28 -0
  451. package/lib/server/modules/payment/index.js +192 -0
  452. package/lib/server/modules/payment/types.d.ts +9 -0
  453. package/lib/server/modules/payment/types.js +17 -0
  454. package/lib/server/modules/products/index.d.ts +105 -14
  455. package/lib/server/modules/products/index.js +850 -475
  456. package/lib/server/modules/products/types.d.ts +34 -1
  457. package/lib/server/modules/products/types.js +34 -41
  458. package/lib/server/modules/quotation/index.d.ts +39 -0
  459. package/lib/server/modules/quotation/index.js +254 -75
  460. package/lib/server/modules/quotation/types.js +31 -21
  461. package/lib/server/modules/resource/index.d.ts +2 -3
  462. package/lib/server/modules/resource/index.js +240 -243
  463. package/lib/server/modules/resource/types.js +33 -42
  464. package/lib/server/modules/schedule/index.d.ts +6 -4
  465. package/lib/server/modules/schedule/index.js +146 -147
  466. package/lib/server/modules/schedule/types.js +21 -14
  467. package/lib/server/modules/schedule/utils.js +163 -334
  468. package/lib/server/test.json +713 -0
  469. package/lib/server/types.d.ts +2 -0
  470. package/lib/server/types.js +16 -4
  471. package/lib/server/utils/index.js +23 -25
  472. package/lib/server/utils/product.js +140 -197
  473. package/lib/server/utils/schedule.js +41 -34
  474. package/lib/server/utils/small-ticket.d.ts +71 -0
  475. package/lib/server/utils/small-ticket.js +904 -0
  476. package/lib/server/utils/time.js +49 -40
  477. package/lib/solution/BaseSales/index.d.ts +378 -0
  478. package/lib/solution/BaseSales/index.js +2533 -0
  479. package/lib/solution/BaseSales/types.d.ts +394 -0
  480. package/lib/solution/BaseSales/types.js +43 -0
  481. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  482. package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
  483. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  484. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  485. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  486. package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
  487. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  488. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
  489. package/lib/solution/BaseSales/utils.d.ts +40 -0
  490. package/lib/solution/BaseSales/utils.js +244 -0
  491. package/lib/solution/BookingByStep/index.d.ts +1 -1
  492. package/lib/solution/BookingByStep/index.js +1340 -1530
  493. package/lib/solution/BookingByStep/types.js +99 -40
  494. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  495. package/lib/solution/BookingByStep/utils/products.js +52 -42
  496. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  497. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  498. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  499. package/lib/solution/BookingTicket/index.d.ts +393 -24
  500. package/lib/solution/BookingTicket/index.js +1374 -184
  501. package/lib/solution/BookingTicket/types.d.ts +191 -6
  502. package/lib/solution/BookingTicket/types.js +79 -40
  503. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  504. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  505. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  506. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  507. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  508. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
  509. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  510. package/lib/solution/BookingTicket/utils/cartView.js +184 -0
  511. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  512. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  513. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  514. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  515. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  516. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  517. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  518. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  519. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  520. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
  521. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  522. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  523. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  524. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
  525. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  526. package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
  527. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  528. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  529. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  530. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  531. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  532. package/lib/solution/BuyTickets/index.js +70 -67
  533. package/lib/solution/BuyTickets/types.js +38 -22
  534. package/lib/solution/Checkout/index.d.ts +1 -0
  535. package/lib/solution/Checkout/index.js +1169 -1463
  536. package/lib/solution/Checkout/types.js +61 -91
  537. package/lib/solution/Checkout/utils/index.js +156 -228
  538. package/lib/solution/PlaceOrder/index.js +0 -55
  539. package/lib/solution/RegisterAndLogin/config.js +462 -503
  540. package/lib/solution/RegisterAndLogin/index.js +630 -633
  541. package/lib/solution/RegisterAndLogin/types.js +76 -189
  542. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  543. package/lib/solution/Sales/index.d.ts +50 -5
  544. package/lib/solution/Sales/index.js +498 -238
  545. package/lib/solution/Sales/types.d.ts +26 -2
  546. package/lib/solution/Sales/types.js +33 -27
  547. package/lib/solution/ScanOrder/index.d.ts +27 -21
  548. package/lib/solution/ScanOrder/index.js +936 -864
  549. package/lib/solution/ScanOrder/types.d.ts +33 -11
  550. package/lib/solution/ScanOrder/types.js +34 -34
  551. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  552. package/lib/solution/ScanOrder/utils.js +422 -385
  553. package/lib/solution/ShopDiscount/index.js +233 -235
  554. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  555. package/lib/solution/ShopDiscount/types.js +37 -15
  556. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  557. package/lib/solution/ShopDiscount/utils.js +172 -309
  558. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  559. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  560. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  561. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  562. package/lib/solution/VenueBooking/index.d.ts +32 -51
  563. package/lib/solution/VenueBooking/index.js +1008 -984
  564. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  565. package/lib/solution/VenueBooking/types.d.ts +1 -3
  566. package/lib/solution/VenueBooking/types.js +39 -20
  567. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  568. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  569. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  570. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  571. package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
  572. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  573. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  574. package/lib/solution/VenueBooking/utils.js +67 -130
  575. package/lib/solution/index.d.ts +2 -0
  576. package/lib/solution/index.js +41 -102
  577. package/lib/store/createStore.js +29 -32
  578. package/lib/types/index.d.ts +12 -2
  579. package/lib/types/index.js +16 -4
  580. package/lib/utils/task.js +36 -36
  581. package/lib/utils/watch.js +47 -81
  582. package/package.json +2 -4
  583. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  584. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  585. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  586. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  587. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  588. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,110 +1,89 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- generateRequestUniqueId: true,
8
- PaymentModule: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
9
8
  };
10
- exports.PaymentModule = void 0;
11
- exports.generateRequestUniqueId = generateRequestUniqueId;
12
- var _BaseModule = require("../BaseModule");
13
- var _types = require("./types");
14
- Object.keys(_types).forEach(function (key) {
15
- if (key === "default" || key === "__esModule") return;
16
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
- if (key in exports && exports[key] === _types[key]) return;
18
- Object.defineProperty(exports, key, {
19
- enumerable: true,
20
- get: function () {
21
- return _types[key];
22
- }
23
- });
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/Payment/index.ts
21
+ var Payment_exports = {};
22
+ __export(Payment_exports, {
23
+ PaymentModule: () => PaymentModule,
24
+ generateRequestUniqueId: () => generateRequestUniqueId
24
25
  });
25
- var _utils = require("../Cart/utils");
26
- var _cash = require("./cash");
27
- var _eftpos = require("./eftpos");
28
- var _walletpass = require("./walletpass");
29
- var _decimal = require("decimal.js");
30
- /**
31
- * 格式化金额为保留两位小数的字符串
32
- */
26
+ module.exports = __toCommonJS(Payment_exports);
27
+ var import_BaseModule = require("../BaseModule");
28
+ var import_types = require("./types");
29
+ var import_utils = require("../Cart/utils");
30
+ var import_cash = require("./cash");
31
+ var import_eftpos = require("./eftpos");
32
+ var import_walletpass = require("./walletpass");
33
+ var import_decimal = require("decimal.js");
34
+ __reExport(Payment_exports, require("./types"), module.exports);
33
35
  function formatAmount(amount) {
34
36
  try {
35
- const decimal = new _decimal.Decimal(amount);
37
+ const decimal = new import_decimal.Decimal(amount);
36
38
  return decimal.toFixed(2);
37
39
  } catch (error) {
38
40
  console.warn(`[PaymentModule] 金额格式化失败: ${amount},使用默认值 0.00`);
39
- return '0.00';
41
+ return "0.00";
40
42
  }
41
43
  }
42
-
43
- /**
44
- * 格式化日期时间为字符串
45
- * 格式: YYYY-MM-DD HH:mm:ss
46
- * 示例: 2025-12-10 16:14:50
47
- */
48
44
  function formatDateTime(date) {
49
45
  const year = date.getFullYear();
50
- const month = String(date.getMonth() + 1).padStart(2, '0');
51
- const day = String(date.getDate()).padStart(2, '0');
52
- const hours = String(date.getHours()).padStart(2, '0');
53
- const minutes = String(date.getMinutes()).padStart(2, '0');
54
- const seconds = String(date.getSeconds()).padStart(2, '0');
46
+ const month = String(date.getMonth() + 1).padStart(2, "0");
47
+ const day = String(date.getDate()).padStart(2, "0");
48
+ const hours = String(date.getHours()).padStart(2, "0");
49
+ const minutes = String(date.getMinutes()).padStart(2, "0");
50
+ const seconds = String(date.getSeconds()).padStart(2, "0");
55
51
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
56
52
  }
57
-
58
- /**
59
- * 生成请求唯一ID
60
- * 格式: 年月日时分秒毫秒+4位随机数
61
- * 示例: 20241201143025123456
62
- */
63
53
  function generateRequestUniqueId() {
64
- const now = new Date();
54
+ const now = /* @__PURE__ */ new Date();
65
55
  const year = now.getFullYear();
66
- const month = String(now.getMonth() + 1).padStart(2, '0');
67
- const day = String(now.getDate()).padStart(2, '0');
68
- const hour = String(now.getHours()).padStart(2, '0');
69
- const minute = String(now.getMinutes()).padStart(2, '0');
70
- const second = String(now.getSeconds()).padStart(2, '0');
71
- const millisecond = String(now.getMilliseconds()).padStart(3, '0');
72
- const randomDigits = Math.floor(Math.random() * 9000) + 1000; // 1000-9999的4位随机数
73
-
56
+ const month = String(now.getMonth() + 1).padStart(2, "0");
57
+ const day = String(now.getDate()).padStart(2, "0");
58
+ const hour = String(now.getHours()).padStart(2, "0");
59
+ const minute = String(now.getMinutes()).padStart(2, "0");
60
+ const second = String(now.getSeconds()).padStart(2, "0");
61
+ const millisecond = String(now.getMilliseconds()).padStart(3, "0");
62
+ const randomDigits = Math.floor(Math.random() * 9e3) + 1e3;
74
63
  return `${year}${month}${day}${hour}${minute}${second}${millisecond}${randomDigits}`;
75
64
  }
76
-
77
- /**
78
- * 支付模块实现
79
- *
80
- * 负责处理支付相关的数据管理和本地存储
81
- */
82
- class PaymentModule extends _BaseModule.BaseModule {
83
- defaultName = 'pay';
84
- defaultVersion = '1.0.0';
85
- request;
86
- app; // App instance
87
- store;
88
- window; // WindowPlugin 实例
89
- dbManager; // IndexDBManager 实例
90
- logger; // LoggerManager 实例
91
- voucherUpdateLockByOrderUuid = new Map();
92
- otherParams = {};
93
-
94
- // 支付方式实例
95
- cash;
96
- eftpos;
97
- wallet;
65
+ function normalizeCustomPaymentId(paymentItem) {
66
+ const rawId = paymentItem.custom_payment_id ?? paymentItem.id ?? 0;
67
+ const parsedId = Number(rawId);
68
+ if (!Number.isFinite(parsedId))
69
+ return 0;
70
+ return parsedId;
71
+ }
72
+ var PaymentModule = class extends import_BaseModule.BaseModule {
98
73
  constructor(name, version) {
99
74
  super(name || "payment", version);
100
- // 初始化支付方式实例
101
- this.cash = new _cash.CashPaymentImpl(this);
102
- this.eftpos = new _eftpos.EftposPaymentImpl(this);
103
- this.wallet = new _walletpass.WalletPassPaymentImpl(this);
75
+ this.defaultName = "pay";
76
+ this.defaultVersion = "1.0.0";
77
+ // LoggerManager 实例
78
+ this.voucherUpdateLockByOrderUuid = /* @__PURE__ */ new Map();
79
+ this.otherParams = {};
80
+ this.cash = new import_cash.CashPaymentImpl(this);
81
+ this.eftpos = new import_eftpos.EftposPaymentImpl(this);
82
+ this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
104
83
  }
105
84
  runVoucherUpdateLocked(orderUuid, task) {
106
85
  const previous = this.voucherUpdateLockByOrderUuid.get(orderUuid) || Promise.resolve();
107
- const next = previous.catch(() => undefined).then(task).finally(() => {
86
+ const next = previous.catch(() => void 0).then(task).finally(() => {
108
87
  if (this.voucherUpdateLockByOrderUuid.get(orderUuid) === next) {
109
88
  this.voucherUpdateLockByOrderUuid.delete(orderUuid);
110
89
  }
@@ -113,21 +92,18 @@ class PaymentModule extends _BaseModule.BaseModule {
113
92
  return next;
114
93
  }
115
94
  normalizeVoucherPaymentItems(voucherPaymentItems) {
116
- const normalized = new Map();
95
+ const normalized = /* @__PURE__ */ new Map();
117
96
  for (const item of voucherPaymentItems || []) {
118
- if (!item?.voucher_id) {
97
+ if (!(item == null ? void 0 : item.voucher_id)) {
119
98
  throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`);
120
99
  }
121
- const orderPaymentType = item.order_payment_type || 'normal';
100
+ const orderPaymentType = item.order_payment_type || "normal";
122
101
  const key = `${item.voucher_id}|${orderPaymentType}`;
123
- normalized.set(key, {
124
- ...item,
125
- order_payment_type: orderPaymentType
126
- });
102
+ normalized.set(key, { ...item, order_payment_type: orderPaymentType });
127
103
  }
128
104
  return {
129
105
  items: Array.from(normalized.values()),
130
- originalCount: voucherPaymentItems?.length || 0,
106
+ originalCount: (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) || 0,
131
107
  normalizedCount: normalized.size
132
108
  };
133
109
  }
@@ -135,37 +111,38 @@ class PaymentModule extends _BaseModule.BaseModule {
135
111
  this.core = core;
136
112
  this.store = options.store;
137
113
  this.otherParams = options.otherParams || {};
138
-
139
- // 获取依赖的插件
140
- this.request = core.getPlugin('request');
141
- const appPlugin = core.getPlugin('app');
142
- this.window = core.getPlugin('window');
114
+ this.request = core.getPlugin("request");
115
+ const appPlugin = core.getPlugin("app");
116
+ this.window = core.getPlugin("window");
143
117
  if (!this.request) {
144
- throw new Error('支付模块需要 request 插件支持');
118
+ throw new Error("支付模块需要 request 插件支持");
145
119
  }
146
120
  if (!appPlugin) {
147
- throw new Error('支付模块需要 app 插件支持');
121
+ throw new Error("支付模块需要 app 插件支持");
148
122
  }
149
123
  this.app = appPlugin.getApp();
150
124
  this.dbManager = this.app.dbManager;
151
125
  this.logger = this.app.logger;
152
-
153
- // 确保支付模块所需的对象存储已创建
154
- await this.ensurePaymentTables();
155
126
  this.registerNetworkHandlers();
156
-
157
- // // 预连接数据库
158
- // this.dbManager.connect()
159
-
160
- this.logInfo('PaymentModule initialized successfully');
127
+ console.log("[PaymentModule] 初始化完成");
128
+ this.logInfo("PaymentModule initialized successfully");
129
+ }
130
+ /**
131
+ * 更新父级解决方案透传的运行态参数,主要用于日志父模块等上下文。
132
+ *
133
+ * @example
134
+ * paymentModule.updateOtherParams({ fatherModule: 'bookingTicket' });
135
+ */
136
+ updateOtherParams(params) {
137
+ this.otherParams = params || {};
161
138
  }
162
-
163
139
  /**
164
140
  * 记录信息日志
165
141
  */
166
142
  logInfo(title, metadata) {
167
- if (this.otherParams?.fatherModule) {
168
- const fatherModule = this.core.getModule(this.otherParams?.fatherModule);
143
+ var _a, _b;
144
+ if ((_a = this.otherParams) == null ? void 0 : _a.fatherModule) {
145
+ const fatherModule = this.core.getModule((_b = this.otherParams) == null ? void 0 : _b.fatherModule);
169
146
  if (fatherModule) {
170
147
  fatherModule.logInfo(`${title}`, metadata);
171
148
  return;
@@ -173,33 +150,31 @@ class PaymentModule extends _BaseModule.BaseModule {
173
150
  }
174
151
  if (this.logger) {
175
152
  this.logger.addLog({
176
- type: 'info',
153
+ type: "info",
177
154
  title: `[PaymentModule] ${title}`,
178
155
  metadata: metadata || {}
179
156
  });
180
157
  }
181
158
  }
182
-
183
159
  /**
184
160
  * 记录警告日志
185
161
  */
186
162
  logWarning(title, metadata) {
187
163
  if (this.logger) {
188
164
  this.logger.addLog({
189
- type: 'warning',
165
+ type: "warning",
190
166
  title: `[PaymentModule] ${title}`,
191
167
  metadata: metadata || {}
192
168
  });
193
169
  }
194
170
  }
195
-
196
171
  /**
197
172
  * 记录错误日志
198
173
  */
199
174
  logError(title, error, metadata) {
200
175
  if (this.logger) {
201
176
  this.logger.addLog({
202
- type: 'error',
177
+ type: "error",
203
178
  title: `[PaymentModule] ${title}`,
204
179
  metadata: {
205
180
  error: error ? {
@@ -207,295 +182,128 @@ class PaymentModule extends _BaseModule.BaseModule {
207
182
  stack: error.stack,
208
183
  code: error.code,
209
184
  ...error
210
- } : undefined,
211
- ...(metadata || {})
185
+ } : void 0,
186
+ ...metadata || {}
212
187
  }
213
188
  });
214
189
  }
215
190
  }
216
-
217
191
  /**
218
192
  * 记录调试日志
219
193
  */
220
194
  logDebug(title, metadata) {
221
195
  if (this.logger) {
222
196
  this.logger.addLog({
223
- type: 'debug',
197
+ type: "debug",
224
198
  title: `[PaymentModule] ${title}`,
225
199
  metadata: metadata || {}
226
200
  });
227
201
  }
228
202
  }
229
-
230
203
  /**
231
204
  * 网络恢复以后,尝试执行队列
232
205
  *
233
206
  */
234
207
  registerNetworkHandlers() {
235
- const network = this.app.plugins.get('network');
236
- this.logInfo('Registering network status listener');
237
- network?.addListener('networkStatusChange', async status => {
238
- this.logInfo('Network status changed', {
208
+ const network = this.app.plugins.get("network");
209
+ this.logInfo("Registering network status listener");
210
+ network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
211
+ console.log("网络状态:", status.connected);
212
+ this.logInfo("Network status changed", {
239
213
  connected: status.connected,
240
214
  previousStatus: status.previousStatus
241
215
  });
242
216
  if (status.connected) {
243
- this.logInfo('Network reconnected');
244
- // 网络恢复时的处理逻辑可以在这里添加
217
+ this.logInfo("Network reconnected");
245
218
  }
246
219
  });
247
220
  }
248
- async filterPayMethods(payMethods) {
249
- // 1. 筛选 status === 1 && disable === 0的数据
250
- // 2. 检查列表里是否有 code=WALLET_PASS的数据,如果没有,则列表里如果有 PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 则删除他们
251
- // 如果有 code = WALLET_PASS的数据,则列表里PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 的channel_application 指向 WALLET_PASS 的 channel_application
252
- payMethods = payMethods.filter(method => method.status === 1 && method.disable === 0);
253
- const walletPassMethod = payMethods.find(method => method.code === 'WALLET_PASS');
254
- if (walletPassMethod) {
255
- payMethods.forEach(method => {
256
- if (method.code === 'PRODUCTVOUCHER' || method.code === 'GIFTCARD' || method.code === 'POINTCARD') {
257
- method.channel_application = walletPassMethod.channel_application;
258
- }
259
- });
260
- } else {
261
- payMethods = payMethods.filter(method => method.code !== 'PRODUCTVOUCHER' && method.code !== 'GIFTCARD' && method.code !== 'POINTCARD');
262
- }
263
- return payMethods;
264
- }
265
-
266
221
  /**
267
222
  * 获取支付方式列表
268
223
  */
269
224
  async getPayMethodListAsync() {
270
- this.logInfo('Starting getPayMethodListAsync');
225
+ this.logInfo("Starting getPayMethodListAsync");
271
226
  try {
272
- // 先尝试从 IndexDB 获取缓存
273
- let cachedMethods = [];
274
- try {
275
- cachedMethods = await this.dbManager.getAll('pay_method');
276
- } catch (dbError) {
277
- console.warn('[PaymentModule] pay_method 表不存在,将从服务器获取数据');
278
- }
279
-
280
- // 如果有缓存,先返回缓存数据
281
- const hasCache = cachedMethods.length > 0;
282
- if (hasCache) {
283
- // 后台异步获取最新数据
284
- this.refreshPaymentMethodsInBackground(cachedMethods);
285
- return cachedMethods;
286
- }
287
-
288
- // 没有缓存时,直接从服务器获取
289
- const response = await this.request.get('/pay/custom-payment/all');
290
- response.data = this.filterPayMethods(response.data);
291
- const payMethods = response.data || [];
292
-
293
- // 尝试缓存到 IndexDB
294
- try {
295
- for (const method of payMethods) {
296
- await this.dbManager.update('pay_method', method);
297
- }
298
- } catch (dbError) {
299
- console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
300
- }
301
- await this.core.effects.emit(`${this.name}:onPaymentMethodsLoaded`, payMethods);
302
- this.logInfo('getPayMethodListAsync completed successfully', {
227
+ const response = await this.request.get("/pay/custom-payment/all", {
228
+ filterPaymentMethods: true
229
+ }, {
230
+ osServer: true
231
+ });
232
+ const payMethods = (response == null ? void 0 : response.data) || response || [];
233
+ this.logInfo("getPayMethodListAsync completed successfully", {
303
234
  payMethods
304
235
  });
305
236
  return payMethods;
306
237
  } catch (error) {
307
- console.error('[PaymentModule] 获取支付方式列表失败', error);
308
- this.logError('getPayMethodListAsync failed', error);
309
- // 如果所有操作都失败,返回空数组
238
+ console.error("[PaymentModule] 获取支付方式列表失败", error);
239
+ this.logError("getPayMethodListAsync failed", error);
310
240
  return [];
311
241
  }
312
242
  }
313
-
314
- /**
315
- * 后台刷新支付方式列表
316
- */
317
- async refreshPaymentMethodsInBackground(cachedMethods) {
318
- this.logInfo('Starting refreshPaymentMethodsInBackground', {
319
- cachedMethodsCount: cachedMethods.length
320
- });
321
- try {
322
- // 从服务器获取最新数据
323
- const response = await this.request.get('/pay/custom-payment/all');
324
- response.data = this.filterPayMethods(response.data);
325
- const newPayMethods = response.data || [];
326
-
327
- // 检查是否有变化
328
- const hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
329
- if (hasChanges) {
330
- this.logInfo('Payment methods updated in background', {
331
- oldCount: cachedMethods.length,
332
- newCount: newPayMethods.length
333
- });
334
-
335
- // 更新缓存
336
- try {
337
- // 先清除旧数据
338
- for (const method of cachedMethods) {
339
- await this.dbManager.delete('pay_method', method.id);
340
- }
341
- // 添加新数据
342
- for (const method of newPayMethods) {
343
- await this.dbManager.update('pay_method', method);
344
- }
345
- } catch (dbError) {
346
- console.warn('[PaymentModule] 无法更新支付方式缓存', dbError);
347
- }
348
-
349
- // 通知外部支付方式已变化
350
- const eventData = {
351
- oldMethods: cachedMethods,
352
- newMethods: newPayMethods
353
- };
354
- await this.core.effects.emit(`${this.name}:onPaymentMethodsChanged`, eventData);
355
- } else {}
356
- } catch (error) {
357
- console.error('[PaymentModule] 后台刷新支付方式失败', error);
358
- }
359
- }
360
-
361
- /**
362
- * 检查支付方式列表是否有变化
363
- */
364
- hasPaymentMethodsChanged(oldMethods, newMethods) {
365
- if (oldMethods.length !== newMethods.length) {
366
- return true;
367
- }
368
-
369
- // 创建旧数据的 Map 便于查找
370
- const oldMethodsMap = new Map(oldMethods.map(method => [method.id, method]));
371
-
372
- // 检查每个新方法是否与旧方法相同
373
- for (const newMethod of newMethods) {
374
- const oldMethod = oldMethodsMap.get(newMethod.id);
375
- if (!oldMethod) {
376
- return true; // 新增方法
377
- }
378
-
379
- // 检查关键字段是否有变化
380
- 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 || {})) {
381
- return true; // 方法属性有变化
382
- }
383
- }
384
- return false;
385
- }
386
-
387
243
  /**
388
244
  * 获取订单列表
389
245
  */
246
+ /** @deprecated */
390
247
  async getOrderListAsync() {
391
248
  try {
392
- return await this.dbManager.getAll('order');
249
+ return await this.dbManager.getAll("order");
393
250
  } catch (error) {
394
- console.error('[PaymentModule] 获取订单列表失败', error);
251
+ console.error("[PaymentModule] 获取订单列表失败", error);
395
252
  return [];
396
253
  }
397
254
  }
398
-
399
255
  /**
400
256
  * 根据订单UUID获取支付订单(新方法)
401
257
  */
402
258
  async getPaymentOrderByUuidAsync(orderUuid) {
403
259
  try {
404
- return await this.dbManager.get('order', orderUuid, true);
260
+ return await this.dbManager.get("order", orderUuid, true);
405
261
  } catch (error) {
406
- console.error('[PaymentModule] 获取支付订单失败', error);
262
+ console.error("[PaymentModule] 获取支付订单失败", error);
407
263
  return null;
408
264
  }
409
265
  }
410
-
411
266
  /**
412
267
  * 创建支付订单(新方法,专注支付数据)
413
268
  */
414
269
  async createPaymentOrderAsync(params) {
415
- this.logInfo('Starting createPaymentOrderAsync', {
270
+ this.logInfo("Starting createPaymentOrderAsync", {
416
271
  orderId: params.order_id,
417
272
  totalAmount: params.total_amount
418
273
  });
419
274
  try {
420
- // 检测是否有重复的 order_id
421
- // console.time('createLocalOrderAsync: getExistingOrder')
422
- // const existingOrder = await this.dbManager.get('order', params.order_id);
423
- // const existingOrders = await this.dbManager.getAll('order');
424
- // const existingOrder = existingOrders.find(
425
- // (order: PaymentOrder) => String(order.id) === String(params.order_id),
426
- // );
427
-
428
- // this.logInfo('createPaymentOrderAsync existingOrder', {
429
- // existingOrder
430
- // });
431
- // console.timeEnd('createLocalOrderAsync: getExistingOrder')
432
- // const existingOrder = existingOrders.find(
433
- // (order: PaymentOrder) => String(order.id) === String(params.order_id),
434
- // );
435
-
436
- // if (existingOrder) {
437
- // // 如果存在相同 order_id 的订单,更新该订单信息
438
- // this.logInfo(
439
- // `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`,
440
- // );
441
-
442
- // // const originalOrder = { ...existingOrder };
443
- // existingOrder.order_info = params.order_info;
444
- // existingOrder.total_amount = params.total_amount;
445
- // existingOrder.is_deposit = params.is_deposit || 0;
446
- // existingOrder.deposit_amount = params.deposit_amount || '0.00';
447
-
448
- // // 重新计算待付金额
449
- // this.recalculateOrderAmount(existingOrder);
450
-
451
- // // 更新到数据库
452
- // await this.dbManager.update('order', existingOrder);
453
-
454
- // // 触发更新事件
455
- // this.core.effects.emit(
456
- // `${this.name}:onOrderUpdated`,
457
- // existingOrder,
458
- // );
459
-
460
- // return existingOrder;
461
- // } else {
462
- // 创建新的支付订单
463
275
  const newOrder = {
464
- uuid: (0, _utils.getUniqueId)('pay_order_'),
276
+ uuid: (0, import_utils.getUniqueId)("pay_order_"),
465
277
  id: params.order_id,
466
278
  order_id: params.order_id,
467
279
  order_info: params.order_info,
468
- payment_status: _types.PaymentStatus.Processing,
280
+ payment_status: import_types.PaymentStatus.Processing,
469
281
  payment: [],
470
282
  adjust_offline_payments: [],
471
283
  total_amount: params.total_amount,
472
284
  expect_amount: params.total_amount,
473
- tax_fee: '0.00',
285
+ tax_fee: "0.00",
474
286
  is_deposit: params.is_deposit || 0,
475
- deposit_amount: params.deposit_amount || '0.00'
287
+ deposit_amount: params.deposit_amount || "0.00"
476
288
  };
477
-
478
- // 🔧 新增: 处理云端已存在的支付项
479
289
  if (params.existPayment && params.existPayment.length > 0) {
480
- const currentTime = formatDateTime(new Date());
481
- newOrder.payment = params.existPayment.map(payment => ({
290
+ const currentTime = formatDateTime(/* @__PURE__ */ new Date());
291
+ newOrder.payment = params.existPayment.map((payment) => ({
482
292
  ...payment,
483
293
  isSynced: true,
484
294
  // 标记为已同步
485
- status: payment.status || 'active',
295
+ status: payment.status || "active",
486
296
  // 如果云端支付项已有时间戳,则保留;否则使用当前时间
487
297
  created_at: payment.created_at || currentTime,
488
298
  updated_at: payment.updated_at || currentTime
489
299
  }));
490
-
491
- // 重新计算待付金额
492
300
  this.recalculateOrderAmount(newOrder);
493
- this.logInfo('创建订单时包含云端支付项', {
301
+ this.logInfo("创建订单时包含云端支付项", {
494
302
  orderId: params.order_id,
495
303
  existPaymentCount: params.existPayment.length,
496
304
  totalAmount: newOrder.total_amount,
497
305
  expectAmount: newOrder.expect_amount,
498
- paymentDetails: params.existPayment.map(p => ({
306
+ paymentDetails: params.existPayment.map((p) => ({
499
307
  uuid: p.uuid,
500
308
  code: p.code,
501
309
  amount: p.amount,
@@ -505,75 +313,67 @@ class PaymentModule extends _BaseModule.BaseModule {
505
313
  }))
506
314
  });
507
315
  }
508
-
509
- // 🚀 性能监控:记录数据库添加操作耗时
510
316
  const dbAddStartTime = Date.now();
511
- await this.dbManager.add('order', newOrder, true);
317
+ await this.dbManager.add("order", newOrder, true);
512
318
  const dbAddDuration = Date.now() - dbAddStartTime;
513
- this.logInfo('Database add operation completed', {
514
- operation: 'dbManager.add',
515
- table: 'order',
319
+ this.logInfo("Database add operation completed", {
320
+ operation: "dbManager.add",
321
+ table: "order",
516
322
  orderUuid: newOrder.uuid,
517
323
  orderId: newOrder.order_id,
518
324
  duration: `${dbAddDuration}ms`,
519
- performance: dbAddDuration > 100 ? 'slow' : dbAddDuration > 50 ? 'medium' : 'fast'
325
+ performance: dbAddDuration > 100 ? "slow" : dbAddDuration > 50 ? "medium" : "fast"
520
326
  });
521
327
  setTimeout(() => {
522
328
  this.core.effects.emit(`${this.name}:onOrderAdded`, newOrder);
523
329
  }, 0);
524
330
  return newOrder;
525
- // }
526
331
  } catch (error) {
527
- console.error('[PaymentModule] 创建支付订单失败', error);
528
- this.logError('createPaymentOrderAsync failed', error, {
332
+ console.error("[PaymentModule] 创建支付订单失败", error);
333
+ this.logError("createPaymentOrderAsync failed", error, {
529
334
  orderId: params.order_id
530
335
  });
531
336
  throw error;
532
337
  }
533
338
  }
534
-
535
339
  /**
536
340
  * 删除支付订单(新方法)
537
341
  */
538
342
  async deletePaymentOrderAsync(orderUuid) {
539
343
  try {
540
- const order = await this.dbManager.get('order', orderUuid);
344
+ const order = await this.dbManager.get("order", orderUuid);
541
345
  if (order) {
542
- await this.dbManager.delete('order', orderUuid);
346
+ await this.dbManager.delete("order", orderUuid);
543
347
  await this.core.effects.emit(`${this.name}:onOrderDeleted`, order);
348
+ console.log("[PaymentModule] 支付订单删除成功:", orderUuid);
544
349
  }
545
350
  } catch (error) {
546
- console.error('[PaymentModule] 删除支付订单失败', error);
351
+ console.error("[PaymentModule] 删除支付订单失败", error);
547
352
  throw error;
548
353
  }
549
354
  }
550
-
551
355
  /**
552
356
  * 更新订单
553
357
  */
554
358
  async updateOrderAsync(orderUuid, params) {
555
359
  try {
556
- const order = await this.dbManager.get('order', orderUuid);
360
+ const order = await this.dbManager.get("order", orderUuid);
557
361
  if (order) {
558
- const updatedOrder = {
559
- ...order,
560
- ...params
561
- };
362
+ const updatedOrder = { ...order, ...params };
562
363
  this.recalculateOrderAmount(updatedOrder);
563
- await this.dbManager.update('order', updatedOrder);
364
+ await this.dbManager.update("order", updatedOrder);
564
365
  await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
565
366
  await this.core.effects.emit(`${this.name}:onOrderChanged`, {
566
- action: 'update',
367
+ action: "update",
567
368
  order: updatedOrder,
568
369
  originalOrder: order
569
370
  });
570
371
  }
571
372
  } catch (error) {
572
- console.error('[PaymentModule] 更新订单失败', error);
373
+ console.error("[PaymentModule] 更新订单失败", error);
573
374
  throw error;
574
375
  }
575
376
  }
576
-
577
377
  /**
578
378
  * 基于UUID替换订单ID
579
379
  *
@@ -585,35 +385,28 @@ class PaymentModule extends _BaseModule.BaseModule {
585
385
  * @returns 更新后的订单对象,如果订单不存在则返回null
586
386
  */
587
387
  async replaceOrderIdByUuidAsync(orderUuid, newOrderId) {
588
- this.logInfo('Starting replaceOrderIdByUuidAsync', {
388
+ this.logInfo("Starting replaceOrderIdByUuidAsync", {
589
389
  orderUuid,
590
390
  newOrderId
591
391
  });
592
392
  try {
593
- // 获取现有订单
594
- const existingOrder = await this.dbManager.get('order', orderUuid);
393
+ const existingOrder = await this.dbManager.get("order", orderUuid);
595
394
  if (!existingOrder) {
596
- this.logWarning('Order not found for UUID replacement', {
597
- orderUuid
598
- });
395
+ this.logWarning("Order not found for UUID replacement", { orderUuid });
599
396
  return null;
600
397
  }
601
-
602
- // 检查新的订单ID是否已经存在
603
- const allOrders = await this.dbManager.getAll('order');
604
- const duplicateOrder = allOrders.find(order => String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid);
398
+ const allOrders = await this.dbManager.getAll("order");
399
+ const duplicateOrder = allOrders.find(
400
+ (order) => String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid
401
+ );
605
402
  if (duplicateOrder) {
606
- this.logWarning('New order ID already exists', {
403
+ this.logWarning("New order ID already exists", {
607
404
  newOrderId,
608
405
  existingOrderUuid: duplicateOrder.uuid
609
406
  });
610
407
  throw new Error(`订单ID ${newOrderId} 已存在`);
611
408
  }
612
-
613
- // 保存原始订单ID用于日志
614
409
  const originalOrderId = existingOrder.id;
615
-
616
- // 更新订单ID
617
410
  const updatedOrder = {
618
411
  ...existingOrder,
619
412
  id: newOrderId,
@@ -624,17 +417,13 @@ class PaymentModule extends _BaseModule.BaseModule {
624
417
  order_id: newOrderId,
625
418
  // 保留原始本地订单ID作为参考
626
419
  original_local_order_id: originalOrderId,
627
- updated_at: new Date().toISOString()
420
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
628
421
  }
629
422
  };
630
-
631
- // 更新到数据库
632
- await this.dbManager.update('order', updatedOrder);
633
-
634
- // 触发事件
423
+ await this.dbManager.update("order", updatedOrder);
635
424
  await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
636
425
  await this.core.effects.emit(`${this.name}:onOrderChanged`, {
637
- action: 'order_id_replaced',
426
+ action: "order_id_replaced",
638
427
  order: updatedOrder,
639
428
  originalOrder: existingOrder,
640
429
  metadata: {
@@ -642,22 +431,22 @@ class PaymentModule extends _BaseModule.BaseModule {
642
431
  newOrderId
643
432
  }
644
433
  });
645
- this.logInfo('Order ID replacement completed successfully', {
434
+ this.logInfo("Order ID replacement completed successfully", {
646
435
  orderUuid,
647
436
  originalOrderId,
648
437
  newOrderId
649
438
  });
439
+ console.log(`[PaymentModule] 订单ID替换成功: ${originalOrderId} → ${newOrderId}`);
650
440
  return updatedOrder;
651
441
  } catch (error) {
652
- console.error('[PaymentModule] 替换订单ID失败', error);
653
- this.logError('replaceOrderIdByUuidAsync failed', error, {
442
+ console.error("[PaymentModule] 替换订单ID失败", error);
443
+ this.logError("replaceOrderIdByUuidAsync failed", error, {
654
444
  orderUuid,
655
445
  newOrderId
656
446
  });
657
447
  throw error;
658
448
  }
659
449
  }
660
-
661
450
  /**
662
451
  * 获取支付项(新方法)
663
452
  *
@@ -667,18 +456,15 @@ class PaymentModule extends _BaseModule.BaseModule {
667
456
  */
668
457
  async getPaymentItemsAsync(orderUuid, includeVoided = false) {
669
458
  if (!orderUuid) {
670
- throw new Error('orderUuid is required');
459
+ throw new Error("orderUuid is required");
671
460
  }
672
461
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
673
- const allPayments = order?.payment || [];
462
+ const allPayments = (order == null ? void 0 : order.payment) || [];
674
463
  if (includeVoided) {
675
464
  return allPayments;
676
465
  }
677
-
678
- // 默认只返回活跃的支付项
679
- return allPayments.filter(payment => payment.status !== 'voided');
466
+ return allPayments.filter((payment) => payment.status !== "voided");
680
467
  }
681
-
682
468
  /**
683
469
  * 获取所有支付项(包括已撤销的)
684
470
  *
@@ -688,51 +474,47 @@ class PaymentModule extends _BaseModule.BaseModule {
688
474
  async getAllPaymentItemsAsync(orderUuid) {
689
475
  return this.getPaymentItemsAsync(orderUuid, true);
690
476
  }
691
-
692
477
  /**
693
478
  * 为某个订单添加支付项(新方法)
694
479
  */
695
480
  async addPaymentItemAsync(orderUuid, paymentItem) {
696
- this.logInfo('Starting addPaymentItemAsync', {
481
+ var _a, _b, _c, _d;
482
+ this.logInfo("Starting addPaymentItemAsync", {
697
483
  orderUuid,
698
484
  paymentAmount: paymentItem.amount,
699
485
  paymentCode: paymentItem.code,
700
486
  orderPaymentType: paymentItem.order_payment_type
701
487
  });
702
488
  try {
703
- this.logInfo('准备获取订单', {
489
+ this.logInfo("准备获取订单", {
704
490
  orderUuid
705
491
  });
706
492
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
707
- this.logInfo('获取订单信息成功', {
493
+ this.logInfo("获取订单信息成功", {
708
494
  orderUuid,
709
495
  order
710
496
  });
711
497
  if (!order) {
712
498
  throw new Error(`Order not found: ${orderUuid}`);
713
499
  }
714
-
715
- // 🔒 支付锁检查:如果订单待付金额已经为0,不允许继续添加支付项
716
- const expectAmount = new _decimal.Decimal(order.expect_amount);
500
+ const expectAmount = new import_decimal.Decimal(order.expect_amount);
717
501
  const paidDepositAmount = order.payment.reduce((sum, payment) => {
718
- if (payment.order_payment_type === 'deposit' && payment.status !== 'voided') {
719
- return sum.plus(new _decimal.Decimal(payment.amount));
502
+ if (payment.order_payment_type === "deposit" && payment.status !== "voided") {
503
+ return sum.plus(new import_decimal.Decimal(payment.amount));
720
504
  }
721
505
  return sum;
722
- }, new _decimal.Decimal(0));
723
- const expectedDepositAmount = new _decimal.Decimal(order.deposit_amount || '0').sub(paidDepositAmount);
724
-
725
- // 有一种特殊情况,订单金额为 0,但是定金金额>0,且此时是定金状态的,允许添加支付项
506
+ }, new import_decimal.Decimal(0));
507
+ const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
726
508
  if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
727
509
  const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
728
- console.warn('[PaymentModule] Payment lock triggered:', {
510
+ console.warn("[PaymentModule] Payment lock triggered:", {
729
511
  orderUuid,
730
512
  expectAmount: order.expect_amount,
731
513
  attemptedPaymentAmount: paymentItem.amount,
732
514
  attemptedPaymentCode: paymentItem.code,
733
- reason: 'Order already fully paid'
515
+ reason: "Order already fully paid"
734
516
  });
735
- this.logError('addPaymentItemAsync blocked by payment lock', new Error(warningMessage), {
517
+ this.logError("addPaymentItemAsync blocked by payment lock", new Error(warningMessage), {
736
518
  orderUuid,
737
519
  expectAmount: order.expect_amount,
738
520
  paymentItem
@@ -740,134 +522,129 @@ class PaymentModule extends _BaseModule.BaseModule {
740
522
  throw new Error(warningMessage);
741
523
  }
742
524
  let paymentUuid;
743
- if (paymentItem.metadata?.unique_payment_number) {
525
+ if ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) {
744
526
  paymentUuid = paymentItem.metadata.unique_payment_number;
745
527
  } else {
746
- paymentUuid = (0, _utils.getUniqueId)('payment_');
528
+ paymentUuid = (0, import_utils.getUniqueId)("payment_");
747
529
  }
748
- const currentTime = formatDateTime(new Date());
530
+ const currentTime = formatDateTime(/* @__PURE__ */ new Date());
749
531
  const newPaymentItem = {
750
532
  uuid: paymentUuid,
751
- custom_payment_id: paymentItem.custom_payment_id || 0,
533
+ custom_payment_id: normalizeCustomPaymentId(paymentItem),
752
534
  name: paymentItem.name,
753
535
  code: paymentItem.code,
754
536
  type: paymentItem.type,
755
537
  amount: formatAmount(paymentItem.amount),
756
- voucher_id: paymentItem.voucher_id || '',
757
- rounding_amount: paymentItem.rounding_amount || '0.00',
538
+ voucher_id: paymentItem.voucher_id || "",
539
+ wallet_pass_usage_unit: paymentItem.wallet_pass_usage_unit,
540
+ wallet_pass_use_value: paymentItem.wallet_pass_use_value,
541
+ rounding_amount: paymentItem.rounding_amount || "0.00",
758
542
  service_charge: paymentItem.service_charge,
759
- status: 'active',
543
+ status: "active",
760
544
  // 新支付项默认为活跃状态
761
- order_payment_type: paymentItem.order_payment_type || 'normal',
545
+ order_payment_type: paymentItem.order_payment_type || "normal",
762
546
  // 默认为正常支付
763
547
  created_at: currentTime,
764
548
  // 创建时间
765
549
  updated_at: currentTime,
766
550
  // 更新时间
767
- wallet_pass_usage_unit: paymentItem?.wallet_pass_usage_unit,
768
- wallet_pass_use_value: paymentItem?.wallet_pass_use_value,
769
551
  metadata: {
770
552
  ...paymentItem.metadata,
771
553
  // 保留传入的所有 metadata 字段
772
- unique_payment_number: paymentUuid // 设置唯一支付号为支付项的 uuid
554
+ unique_payment_number: paymentUuid
555
+ // 设置唯一支付号为支付项的 uuid
773
556
  }
774
557
  };
775
558
  order.payment.push(newPaymentItem);
776
559
  this.recalculateOrderAmount(order);
777
- this.logInfo('开始更新订单支付项', {
560
+ this.logInfo("开始更新订单支付项", {
778
561
  orderUuid,
779
562
  order
780
563
  });
781
- await this.dbManager.update('order', order, true);
782
- this.logInfo('更新订单支付项完成', {
564
+ await this.dbManager.update("order", order, true);
565
+ this.logInfo("更新订单支付项完成", {
783
566
  orderUuid
784
567
  });
785
568
  this.core.effects.emit(`${this.name}:onPaymentAdded`, {
786
569
  orderUuid,
787
570
  payment: newPaymentItem
788
571
  });
789
- this.logInfo('addPaymentItemAsync completed successfully', {
572
+ this.logInfo("addPaymentItemAsync completed successfully", {
790
573
  orderUuid,
791
574
  paymentUuid: newPaymentItem.uuid,
792
- uniquePaymentNumber: newPaymentItem.metadata?.unique_payment_number,
575
+ uniquePaymentNumber: (_b = newPaymentItem.metadata) == null ? void 0 : _b.unique_payment_number,
793
576
  newExpectAmount: order.expect_amount,
794
577
  paymentAmount: newPaymentItem.amount,
795
578
  paymentCode: newPaymentItem.code,
796
579
  orderPaymentType: newPaymentItem.order_payment_type,
797
580
  metadataFields: Object.keys(newPaymentItem.metadata || {}),
798
581
  // 现金支付找零信息
799
- actualPaidAmount: newPaymentItem.metadata?.actual_paid_amount,
800
- changeGivenAmount: newPaymentItem.metadata?.change_given_amount
582
+ actualPaidAmount: (_c = newPaymentItem.metadata) == null ? void 0 : _c.actual_paid_amount,
583
+ changeGivenAmount: (_d = newPaymentItem.metadata) == null ? void 0 : _d.change_given_amount
801
584
  });
802
585
  } catch (error) {
803
- console.error('[PaymentModule] 添加支付项失败', error);
804
- this.logError('addPaymentItemAsync failed', error, {
586
+ console.error("[PaymentModule] 添加支付项失败", error);
587
+ this.logError("addPaymentItemAsync failed", error, {
805
588
  orderUuid,
806
589
  paymentItem
807
590
  });
808
591
  throw error;
809
592
  }
810
593
  }
811
-
812
594
  /**
813
595
  * 删除一个支付项 - 标记删除而非物理删除
814
596
  */
815
597
  async deletePaymentAsync(orderUuid, paymentUuid) {
816
- this.logInfo('Starting deletePaymentAsync (mark as voided)', {
817
- orderUuid,
818
- paymentUuid
819
- });
598
+ this.logInfo("Starting deletePaymentAsync (mark as voided)", { orderUuid, paymentUuid });
820
599
  try {
821
- const order = await this.dbManager.get('order', orderUuid);
600
+ const order = await this.dbManager.get("order", orderUuid);
822
601
  if (!order) {
823
- throw new Error('订单不存在');
602
+ throw new Error("订单不存在");
824
603
  }
825
- const paymentItem = order.payment.find(payment => payment.uuid === paymentUuid);
604
+ const paymentItem = order.payment.find(
605
+ (payment) => payment.uuid === paymentUuid
606
+ );
826
607
  if (!paymentItem) {
827
608
  throw new Error(`支付项不存在: ${paymentUuid}`);
828
609
  }
829
-
830
- // 检查是否已经被删除(撤销)
831
- if (paymentItem.status === 'voided') {
610
+ if (paymentItem.status === "voided") {
832
611
  console.warn(`[PaymentModule] 支付项 ${paymentUuid} 已经被删除,跳过操作`);
833
612
  return;
834
613
  }
835
-
836
- // 标记删除而不是物理删除
837
- paymentItem.status = 'voided';
838
- paymentItem.origin_amount = paymentItem.amount; // 保存原始金额
839
- paymentItem.amount = '0.00'; // 将金额设为0,不参与订单金额计算
840
-
841
- // 重新计算待付金额
614
+ paymentItem.status = "voided";
615
+ paymentItem.origin_amount = paymentItem.amount;
616
+ paymentItem.amount = "0.00";
617
+ console.log(`[PaymentModule] 支付项标记为删除:`, {
618
+ uuid: paymentItem.uuid,
619
+ originalAmount: paymentItem.origin_amount,
620
+ status: paymentItem.status
621
+ });
842
622
  this.recalculateOrderAmount(order);
843
-
844
- // 更新到 IndexDB
845
- await this.dbManager.update('order', order);
623
+ await this.dbManager.update("order", order);
846
624
  await this.core.effects.emit(`${this.name}:onPaymentDeleted`, {
847
625
  order,
848
- paymentItem: paymentItem
626
+ paymentItem
849
627
  });
850
628
  await this.core.effects.emit(`${this.name}:onOrderChanged`, {
851
- action: 'payment_delete',
629
+ action: "payment_delete",
852
630
  order,
853
- paymentItem: paymentItem
631
+ paymentItem
854
632
  });
855
- this.logInfo('deletePaymentAsync completed successfully (marked as voided)', {
633
+ this.logInfo("deletePaymentAsync completed successfully (marked as voided)", {
856
634
  orderUuid,
857
635
  paymentUuid,
858
636
  originalAmount: paymentItem.origin_amount,
859
637
  newExpectAmount: order.expect_amount
860
638
  });
861
639
  } catch (error) {
862
- console.error('[PaymentModule] 删除支付项失败', error);
863
- this.logError('deletePaymentAsync failed', error, {
640
+ console.error("[PaymentModule] 删除支付项失败", error);
641
+ this.logError("deletePaymentAsync failed", error, {
864
642
  orderUuid,
865
643
  paymentUuid
866
644
  });
867
645
  throw error;
868
646
  }
869
647
  }
870
-
871
648
  /**
872
649
  * 批量更新代金券类支付项(覆盖更新)
873
650
  *
@@ -876,16 +653,12 @@ class PaymentModule extends _BaseModule.BaseModule {
876
653
  */
877
654
  async updateVoucherPaymentItemsAsync(orderUuid, voucherPaymentItems) {
878
655
  return this.runVoucherUpdateLocked(orderUuid, async () => {
879
- const {
880
- items: normalizedVoucherItems,
881
- originalCount,
882
- normalizedCount
883
- } = this.normalizeVoucherPaymentItems(voucherPaymentItems);
884
- this.logInfo('Starting updateVoucherPaymentItemsAsync', {
656
+ const { items: normalizedVoucherItems, originalCount, normalizedCount } = this.normalizeVoucherPaymentItems(voucherPaymentItems);
657
+ this.logInfo("Starting updateVoucherPaymentItemsAsync", {
885
658
  orderUuid,
886
659
  originalVoucherCount: originalCount,
887
660
  normalizedVoucherCount: normalizedCount,
888
- voucherItems: normalizedVoucherItems.map(item => ({
661
+ voucherItems: normalizedVoucherItems.map((item) => ({
889
662
  code: item.code,
890
663
  amount: item.amount,
891
664
  voucher_id: item.voucher_id,
@@ -893,7 +666,7 @@ class PaymentModule extends _BaseModule.BaseModule {
893
666
  }))
894
667
  });
895
668
  if (originalCount !== normalizedCount) {
896
- console.warn('[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)', {
669
+ console.warn("[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)", {
897
670
  orderUuid,
898
671
  originalCount,
899
672
  normalizedCount
@@ -904,52 +677,72 @@ class PaymentModule extends _BaseModule.BaseModule {
904
677
  if (!order) {
905
678
  throw new Error(`订单不存在: ${orderUuid}`);
906
679
  }
907
-
908
- // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)并且还没有同步给后端
909
- // 如果同步给了后端的voucher 不允许删除
910
- const existingVoucherItems = order.payment.filter(payment => payment.voucher_id && payment.status !== 'voided' && !payment.isSynced);
911
- // 2. 删除所有现有的代金券支付项(仅删除未同步的)
680
+ const existingVoucherItems = order.payment.filter(
681
+ (payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
682
+ );
683
+ console.log("[PaymentModule] 发现现有代金券支付项:", {
684
+ orderUuid,
685
+ existingVoucherCount: existingVoucherItems.length,
686
+ existingItems: existingVoucherItems.map((item) => ({
687
+ uuid: item.uuid,
688
+ code: item.code,
689
+ amount: item.amount,
690
+ voucher_id: item.voucher_id,
691
+ isSynced: item.isSynced
692
+ }))
693
+ });
912
694
  for (const voucherItem of existingVoucherItems) {
695
+ console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
913
696
  await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
914
697
  }
915
-
916
- // 3. 添加新的代金券支付项(幂等:如果已存在同 voucher_id + order_payment_type 的 active 项则跳过)
917
698
  const orderAfterDelete = await this.getPaymentOrderByUuidAsync(orderUuid);
918
699
  if (!orderAfterDelete) {
919
700
  throw new Error(`订单不存在: ${orderUuid}`);
920
701
  }
921
- const existingActiveVoucherKeys = new Set(orderAfterDelete.payment.filter(p => p.voucher_id && p.status !== 'voided' && !p.isSynced).map(p => `${p.voucher_id}|${p.order_payment_type || 'normal'}`));
702
+ const existingActiveVoucherKeys = new Set(
703
+ orderAfterDelete.payment.filter((p) => p.voucher_id && p.status !== "voided" && !p.isSynced).map((p) => `${p.voucher_id}|${p.order_payment_type || "normal"}`)
704
+ );
705
+ console.log("[PaymentModule] 添加新的代金券支付项:", {
706
+ orderUuid,
707
+ newItemCount: normalizedVoucherItems.length
708
+ });
922
709
  for (const voucherItem of normalizedVoucherItems) {
923
- const orderPaymentType = voucherItem.order_payment_type || 'normal';
710
+ const orderPaymentType = voucherItem.order_payment_type || "normal";
924
711
  const key = `${voucherItem.voucher_id}|${orderPaymentType}`;
925
712
  if (existingActiveVoucherKeys.has(key)) {
926
- console.warn('[PaymentModule] Skip adding voucher payment item because it already exists (active)', {
713
+ console.warn("[PaymentModule] Skip adding voucher payment item because it already exists (active)", {
927
714
  orderUuid,
928
715
  voucher_id: voucherItem.voucher_id,
929
716
  order_payment_type: orderPaymentType
930
717
  });
931
718
  continue;
932
719
  }
720
+ console.log(`[PaymentModule] 添加代金券支付项:`, {
721
+ ...voucherItem,
722
+ code: voucherItem.code,
723
+ amount: voucherItem.amount,
724
+ voucher_id: voucherItem.voucher_id,
725
+ order_payment_type: orderPaymentType
726
+ });
933
727
  await this.addPaymentItemAsync(orderUuid, voucherItem);
934
728
  existingActiveVoucherKeys.add(key);
935
729
  }
936
-
937
- // 4. 触发支付项更新事件
938
730
  const updatedOrder = await this.getPaymentOrderByUuidAsync(orderUuid);
939
731
  await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
940
732
  orderUuid,
941
733
  order: updatedOrder,
942
- payment: null // 批量操作不提供单个支付项
734
+ payment: null
735
+ // 批量操作不提供单个支付项
943
736
  });
944
- this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
737
+ this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
945
738
  orderUuid,
946
739
  removedVoucherCount: existingVoucherItems.length,
947
740
  addedVoucherCount: normalizedVoucherItems.length,
948
- finalExpectAmount: updatedOrder?.expect_amount
741
+ finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
949
742
  });
950
743
  } catch (error) {
951
- console.error('[PaymentModule] 批量更新代金券支付项失败:', error);
952
- this.logError('updateVoucherPaymentItemsAsync failed', error, {
744
+ console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
745
+ this.logError("updateVoucherPaymentItemsAsync failed", error, {
953
746
  orderUuid,
954
747
  voucherPaymentItems
955
748
  });
@@ -957,94 +750,79 @@ class PaymentModule extends _BaseModule.BaseModule {
957
750
  }
958
751
  });
959
752
  }
960
-
961
753
  /**
962
754
  * 更新一个支付项
963
755
  */
964
756
  async updatePaymentAsync(orderUuid, paymentUuid, params) {
965
757
  try {
966
- const order = await this.dbManager.get('order', orderUuid);
758
+ const order = await this.dbManager.get("order", orderUuid);
967
759
  if (!order) {
968
- throw new Error('订单不存在');
760
+ throw new Error("订单不存在");
969
761
  }
970
- const paymentItem = order.payment.find(payment => payment.uuid === paymentUuid);
762
+ const paymentItem = order.payment.find(
763
+ (payment) => payment.uuid === paymentUuid
764
+ );
971
765
  if (paymentItem) {
972
- // 如果更新参数中包含 amount,先格式化
973
- const formattedParams = {
974
- ...params
975
- };
976
- if ('amount' in formattedParams && formattedParams.amount !== undefined) {
766
+ const formattedParams = { ...params };
767
+ if ("amount" in formattedParams && formattedParams.amount !== void 0) {
977
768
  formattedParams.amount = formatAmount(formattedParams.amount);
978
769
  }
979
770
  Object.assign(paymentItem, formattedParams);
980
-
981
- // 重新计算待付金额
982
771
  this.recalculateOrderAmount(order);
983
-
984
- // 更新到 IndexDB
985
- await this.dbManager.update('order', order);
772
+ await this.dbManager.update("order", order);
986
773
  await this.core.effects.emit(`${this.name}:onPaymentUpdated`, {
987
774
  order,
988
775
  paymentItem
989
776
  });
990
777
  await this.core.effects.emit(`${this.name}:onOrderChanged`, {
991
- action: 'payment_update',
778
+ action: "payment_update",
992
779
  order,
993
780
  paymentItem
994
781
  });
995
782
  }
996
783
  } catch (error) {
997
- console.error('[PaymentModule] 更新支付项失败', error);
784
+ console.error("[PaymentModule] 更新支付项失败", error);
998
785
  throw error;
999
786
  }
1000
787
  }
1001
-
1002
788
  /**
1003
789
  * 提交支付
1004
790
  */
1005
791
  async submitPayAsync(orderUuid) {
1006
- this.logInfo('Starting submitPayAsync', {
1007
- orderUuid
1008
- });
792
+ this.logInfo("Starting submitPayAsync", { orderUuid });
1009
793
  try {
1010
794
  let orderToSubmit;
1011
795
  if (orderUuid) {
1012
- const order = await this.dbManager.get('order', orderUuid);
796
+ const order = await this.dbManager.get("order", orderUuid);
1013
797
  orderToSubmit = order ? [order] : [];
1014
798
  } else {
1015
- const allOrders = await this.dbManager.getAll('order');
1016
- // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1017
- orderToSubmit = allOrders.filter(order => order.payment_status === _types.PaymentStatus.Processing || order.payment_status === _types.PaymentStatus.PartiallyPaid);
799
+ const allOrders = await this.dbManager.getAll("order");
800
+ orderToSubmit = allOrders.filter(
801
+ (order) => order.payment_status === import_types.PaymentStatus.Processing || order.payment_status === import_types.PaymentStatus.PartiallyPaid
802
+ );
1018
803
  }
1019
804
  for (const order of orderToSubmit) {
1020
805
  await this.submitSingleOrderPayment(order);
1021
806
  }
1022
- const result = {
1023
- status: 'success'
1024
- };
1025
- this.logInfo('submitPayAsync completed', {
807
+ const result = { status: "success" };
808
+ this.logInfo("submitPayAsync completed", {
1026
809
  result: result.status,
1027
810
  processedOrdersCount: orderToSubmit.length
1028
811
  });
1029
812
  return result;
1030
813
  } catch (error) {
1031
- console.error('[PaymentModule] 提交支付失败', error);
1032
- this.logError('submitPayAsync failed', error, {
1033
- orderUuid
1034
- });
1035
- return {
1036
- status: 'failed'
1037
- };
814
+ console.error("[PaymentModule] 提交支付失败", error);
815
+ this.logError("submitPayAsync failed", error, { orderUuid });
816
+ return { status: "failed" };
1038
817
  }
1039
818
  }
1040
-
1041
819
  /**
1042
820
  * 提交单个订单的支付(推送到任务队列)
1043
821
  */
1044
822
  async submitSingleOrderPayment(order) {
1045
823
  try {
1046
824
  const paymentData = {
1047
- payments: order.payment.map(payment => ({
825
+ payments: order.payment.map((payment) => ({
1048
826
  uuid: payment.uuid,
1049
827
  amount: payment.amount,
1050
828
  code: payment.code,
@@ -1056,41 +834,37 @@ class PaymentModule extends _BaseModule.BaseModule {
1056
834
  rounding_amount: payment.rounding_amount,
1057
835
  service_charge: payment.service_charge
1058
836
  })),
1059
- payment_status: 'pending'
837
+ payment_status: "pending"
1060
838
  };
1061
-
1062
- // 计算总支付金额
1063
- const totalPaidAmount = paymentData.payments.reduce((sum, payment) => sum.plus(payment.amount), new _decimal.Decimal(0));
1064
- const orderTotalAmount = new _decimal.Decimal(order.total_amount);
1065
-
1066
- // 根据支付金额判断订单状态
839
+ const totalPaidAmount = paymentData.payments.reduce(
840
+ (sum, payment) => sum.plus(payment.amount),
841
+ new import_decimal.Decimal(0)
842
+ );
843
+ const orderTotalAmount = new import_decimal.Decimal(order.total_amount);
1067
844
  if (totalPaidAmount.gte(orderTotalAmount)) {
1068
- // 支付金额足够,标记为已完成
1069
- order.payment_status = _types.PaymentStatus.Finished;
845
+ order.payment_status = import_types.PaymentStatus.Finished;
846
+ console.log(
847
+ `[PaymentModule] 订单 ${order.uuid} 支付完成,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
848
+ );
1070
849
  } else {
1071
- // 支付金额不足,标记为部分支付
1072
- order.payment_status = _types.PaymentStatus.PartiallyPaid;
850
+ order.payment_status = import_types.PaymentStatus.PartiallyPaid;
851
+ console.log(
852
+ `[PaymentModule] 订单 ${order.uuid} 部分支付,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
853
+ );
1073
854
  }
1074
-
1075
- // 给后端标记一下是全部支付(paid)还是部分支付
1076
- paymentData.payment_status = order.payment_status === _types.PaymentStatus.Finished ? 'paid' : 'partially_paid';
1077
-
1078
- // 更新订单状态到数据库
1079
- await this.dbManager.update('order', order);
1080
-
1081
- // 检查支付列表是否为空
855
+ paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
856
+ await this.dbManager.update("order", order);
1082
857
  if (paymentData.payments.length === 0) {
1083
- this.logWarning('Empty payment list', {
858
+ console.log(`[PaymentModule] 订单 ${order.uuid} 支付列表为空,跳过支付处理`);
859
+ this.logWarning("Empty payment list", {
1084
860
  orderUuid: order.uuid,
1085
861
  orderId: order.order_id
1086
862
  });
1087
863
  return;
1088
864
  }
1089
-
1090
- // 触发支付提交事件
1091
865
  await this.core.effects.emit(`${this.name}:onPaymentSubmitted`, order);
1092
866
  await this.core.effects.emit(`${this.name}:onOrderChanged`, {
1093
- action: 'submit',
867
+ action: "submit",
1094
868
  order
1095
869
  });
1096
870
  } catch (error) {
@@ -1098,163 +872,170 @@ class PaymentModule extends _BaseModule.BaseModule {
1098
872
  throw error;
1099
873
  }
1100
874
  }
1101
-
1102
875
  /**
1103
876
  * 获取订单剩余待付金额
1104
877
  */
1105
878
  async getRemainingOrderAmountAsync(orderUuid) {
1106
879
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
1107
880
  if (!order) {
1108
- throw new Error('订单不存在');
881
+ throw new Error("订单不存在");
1109
882
  }
1110
- return new _decimal.Decimal(order.expect_amount).toNumber();
883
+ return new import_decimal.Decimal(order.expect_amount).toNumber();
1111
884
  }
1112
-
1113
885
  /**
1114
886
  * 在比如现金支付界面的地方,用户输入了一个金额,在下方显示剩余多少金额,通过此方法获取
1115
887
  */
1116
888
  async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
1117
889
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
1118
890
  if (!order) {
1119
- throw new Error('订单不存在');
891
+ throw new Error("订单不存在");
1120
892
  }
1121
-
1122
- // 对输入金额做保护,确保是有效的数字
1123
- if (inputAmount === null || inputAmount === undefined) {
1124
- // 如果输入为空,返回原始的待付金额
1125
- return new _decimal.Decimal(order.expect_amount).toNumber();
893
+ if (inputAmount === null || inputAmount === void 0) {
894
+ return new import_decimal.Decimal(order.expect_amount).toNumber();
1126
895
  }
1127
-
1128
- // 处理字符串类型的输入
1129
- if (typeof inputAmount === 'string') {
1130
- if (inputAmount.trim() === '') {
1131
- // 如果输入为空字符串,返回原始的待付金额
1132
- return new _decimal.Decimal(order.expect_amount).toNumber();
896
+ if (typeof inputAmount === "string") {
897
+ if (inputAmount.trim() === "") {
898
+ return new import_decimal.Decimal(order.expect_amount).toNumber();
1133
899
  }
1134
900
  }
1135
-
1136
- // 处理数字类型的输入
1137
- if (typeof inputAmount === 'number') {
901
+ if (typeof inputAmount === "number") {
1138
902
  if (isNaN(inputAmount) || !isFinite(inputAmount)) {
1139
- // 如果输入是 NaN 或无穷大,返回原始的待付金额
1140
- console.warn(`[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`);
1141
- return new _decimal.Decimal(order.expect_amount).toNumber();
903
+ console.warn(
904
+ `[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`
905
+ );
906
+ return new import_decimal.Decimal(order.expect_amount).toNumber();
1142
907
  }
1143
908
  }
1144
909
  try {
1145
- const inputDecimal = new _decimal.Decimal(inputAmount);
1146
- return new _decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
910
+ const inputDecimal = new import_decimal.Decimal(inputAmount);
911
+ return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
1147
912
  } catch (error) {
1148
- // 如果输入不是有效的数字,返回原始的待付金额
1149
- console.warn(`[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`);
1150
- return new _decimal.Decimal(order.expect_amount).toNumber();
913
+ console.warn(
914
+ `[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`
915
+ );
916
+ return new import_decimal.Decimal(order.expect_amount).toNumber();
1151
917
  }
1152
918
  }
1153
-
1154
919
  /**
1155
920
  * 重新计算订单金额
1156
921
  */
1157
922
  recalculateOrderAmount(order) {
1158
- const totalAmount = new _decimal.Decimal(order.total_amount);
1159
- const paidAmount = order.payment.reduce((sum, payment) => {
1160
- try {
1161
- // 忽略已撤销的支付项
1162
- if (payment.status === 'voided') {
923
+ const totalAmount = new import_decimal.Decimal(order.total_amount);
924
+ const paidAmount = order.payment.reduce(
925
+ (sum, payment) => {
926
+ try {
927
+ if (payment.status === "voided") {
928
+ return sum;
929
+ }
930
+ const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
931
+ const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
932
+ const effectiveAmount = paymentAmount.minus(roundingAmount);
933
+ return sum.plus(effectiveAmount);
934
+ } catch (error) {
935
+ console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
1163
936
  return sum;
1164
937
  }
1165
-
1166
- // 计算有效支付金额:支付金额 + 抹零金额的绝对值
1167
- // 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
1168
- // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
1169
- // 例2:amount=15,rounding_amount=0.2,有效支付 14.8
1170
- const paymentAmount = new _decimal.Decimal(payment.amount || 0);
1171
- const roundingAmount = new _decimal.Decimal(payment.rounding_amount || 0);
1172
- const effectiveAmount = paymentAmount.minus(roundingAmount);
1173
- return sum.plus(effectiveAmount);
1174
- } catch (error) {
1175
- console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
1176
- return sum;
1177
- }
1178
- }, new _decimal.Decimal(0));
1179
- // 如果是定金模式,则使用deposit_amount 去减已付款金额
1180
- const remainingAmount = order.is_deposit === 1 ? new _decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
1181
- order.expect_amount = _decimal.Decimal.max(0, remainingAmount).toFixed(2);
938
+ },
939
+ new import_decimal.Decimal(0)
940
+ );
941
+ const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
942
+ order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
943
+ console.log(`[PaymentModule] 重新计算订单金额:`, {
944
+ orderUuid: order.uuid,
945
+ totalAmount: order.total_amount,
946
+ effectivePaidAmount: paidAmount.toFixed(2),
947
+ remainingAmount: order.expect_amount,
948
+ activePayments: order.payment.filter((p) => p.status !== "voided").length,
949
+ voidedPayments: order.payment.filter((p) => p.status === "voided").length,
950
+ paymentDetails: order.payment.filter((p) => p.status !== "voided").map((p) => ({
951
+ code: p.code,
952
+ amount: p.amount,
953
+ rounding_amount: p.rounding_amount || "0.00",
954
+ effective_amount: new import_decimal.Decimal(p.amount || 0).minus(new import_decimal.Decimal(p.rounding_amount || 0)).toFixed(2)
955
+ })),
956
+ 说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
957
+ });
1182
958
  }
1183
-
1184
959
  /**
1185
960
  * 获取现金支付方式
1186
961
  */
1187
962
  async getCashPaymentMethod() {
1188
963
  try {
1189
- const payMethods = await this.dbManager.getAll('pay_method');
1190
- return payMethods.find(method => method.code === _types.PaymentMethodType.Cash) || null;
964
+ const payMethods = await this.dbManager.getAll("pay_method");
965
+ return payMethods.find(
966
+ (method) => method.code === import_types.PaymentMethodType.Cash
967
+ ) || null;
1191
968
  } catch (error) {
1192
- console.error('[PaymentModule] 获取现金支付方式失败', error);
969
+ console.error("[PaymentModule] 获取现金支付方式失败", error);
1193
970
  return null;
1194
971
  }
1195
972
  }
1196
-
1197
973
  /**
1198
974
  * 获取Eftpos支付方式
1199
975
  */
1200
976
  async getEftposPaymentMethod() {
1201
977
  try {
1202
- const payMethods = await this.dbManager.getAll('pay_method');
1203
- return payMethods.find(method => method.code === _types.PaymentMethodType.Eftpos) || null;
978
+ const payMethods = await this.dbManager.getAll("pay_method");
979
+ return payMethods.find(
980
+ (method) => method.code === import_types.PaymentMethodType.Eftpos
981
+ ) || null;
1204
982
  } catch (error) {
1205
- console.error('[PaymentModule] 获取Eftpos支付方式失败', error);
983
+ console.error("[PaymentModule] 获取Eftpos支付方式失败", error);
1206
984
  return null;
1207
985
  }
1208
986
  }
1209
-
1210
987
  /**
1211
988
  * 获取钱包支付方式
1212
989
  */
1213
990
  async getWalletPaymentMethod() {
1214
991
  try {
1215
- const payMethods = await this.dbManager.getAll('pay_method');
1216
- return payMethods.find(method => method.code === _types.PaymentMethodType.Wallet) || null;
992
+ const payMethods = await this.dbManager.getAll("pay_method");
993
+ return payMethods.find(
994
+ (method) => method.code === import_types.PaymentMethodType.Wallet
995
+ ) || null;
1217
996
  } catch (error) {
1218
- console.error('[PaymentModule] 获取钱包支付方式失败', error);
997
+ console.error("[PaymentModule] 获取钱包支付方式失败", error);
1219
998
  return null;
1220
999
  }
1221
1000
  }
1222
-
1223
1001
  /**
1224
1002
  * 确保支付模块所需的数据库表已创建
1225
1003
  */
1004
+ /** @deprecated */
1226
1005
  async ensurePaymentTables() {
1227
1006
  try {
1228
- // 尝试访问 pay_method 表,如果不存在会抛出错误
1229
- await this.dbManager.getAll('pay_method');
1007
+ await this.dbManager.getAll("pay_method");
1230
1008
  } catch (error) {
1231
- console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
1009
+ console.warn(
1010
+ "[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:"
1011
+ );
1232
1012
  console.warn('{ name: "pay_method", keyPath: "id" }');
1233
1013
  }
1234
1014
  try {
1235
- // 尝试访问 order 表,如果不存在会抛出错误
1236
- await this.dbManager.getAll('order');
1015
+ await this.dbManager.getAll("order");
1237
1016
  } catch (error) {
1238
- console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
1017
+ console.warn(
1018
+ "[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:"
1019
+ );
1239
1020
  console.warn('{ name: "order", keyPath: "uuid" }');
1240
1021
  }
1241
1022
  }
1242
-
1243
1023
  /**
1244
1024
  * 获取部分支付的订单
1245
1025
  */
1026
+ /** @deprecated */
1246
1027
  async getPartiallyPaidOrdersAsync() {
1247
1028
  try {
1248
- const allOrders = await this.dbManager.getAll('order');
1249
- return allOrders.filter(order => order.payment_status === _types.PaymentStatus.PartiallyPaid);
1029
+ const allOrders = await this.dbManager.getAll("order");
1030
+ return allOrders.filter(
1031
+ (order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
1032
+ );
1250
1033
  } catch (error) {
1251
- console.error('[PaymentModule] 获取部分支付订单失败', error);
1034
+ console.error("[PaymentModule] 获取部分支付订单失败", error);
1252
1035
  return [];
1253
1036
  }
1254
1037
  }
1255
-
1256
1038
  // === 新的 API 方法实现 ===
1257
-
1258
1039
  /**
1259
1040
  * 智能金额舍入
1260
1041
  *
@@ -1267,78 +1048,63 @@ class PaymentModule extends _BaseModule.BaseModule {
1267
1048
  */
1268
1049
  async roundAmountAsync(originalAmount, interval, rule) {
1269
1050
  try {
1270
- // 参数验证
1271
- const amount = new _decimal.Decimal(originalAmount);
1272
- const roundingInterval = new _decimal.Decimal(interval);
1051
+ const amount = new import_decimal.Decimal(originalAmount);
1052
+ const roundingInterval = new import_decimal.Decimal(interval);
1273
1053
  if (roundingInterval.lte(0)) {
1274
- throw new Error('舍入间隔必须大于 0');
1054
+ throw new Error("舍入间隔必须大于 0");
1275
1055
  }
1276
-
1277
- // 支持的舍入间隔
1278
1056
  const supportedIntervals = [0.05, 0.1, 0.5, 1];
1279
1057
  const intervalValue = roundingInterval.toNumber();
1280
1058
  if (!supportedIntervals.includes(intervalValue)) {
1281
- console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(', ')}`);
1059
+ console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(", ")}`);
1282
1060
  }
1283
-
1284
- // 计算基础值:x / interval
1285
1061
  const baseValue = amount.div(roundingInterval);
1062
+ console.log(`[PaymentModule] 舍入计算 - 原始金额: ${amount.toString()}, 间隔: ${intervalValue}, 基础值: ${baseValue.toString()}, 规则: ${rule}`);
1286
1063
  let roundedValue;
1287
-
1288
- // 根据舍入规则处理
1289
1064
  switch (rule) {
1290
- case _types.RoundingRule.Standard:
1291
- case 'standard':
1292
- // 标准舍入(中点向上)
1065
+ case import_types.RoundingRule.Standard:
1066
+ case "standard":
1293
1067
  roundedValue = this.standardRound(baseValue, true);
1294
1068
  break;
1295
- case _types.RoundingRule.StandardDown:
1296
- case 'standard_down':
1297
- // 标准舍入(中点向下)
1069
+ case import_types.RoundingRule.StandardDown:
1070
+ case "standard_down":
1298
1071
  roundedValue = this.standardRound(baseValue, false);
1299
1072
  break;
1300
- case _types.RoundingRule.AlwaysUp:
1301
- case 'always_up':
1302
- // 总是向上舍入
1073
+ case import_types.RoundingRule.AlwaysUp:
1074
+ case "always_up":
1303
1075
  roundedValue = baseValue.ceil();
1304
1076
  break;
1305
- case _types.RoundingRule.AlwaysDown:
1306
- case 'always_down':
1307
- // 总是向下舍入
1077
+ case import_types.RoundingRule.AlwaysDown:
1078
+ case "always_down":
1308
1079
  roundedValue = baseValue.floor();
1309
1080
  break;
1310
1081
  default:
1311
1082
  throw new Error(`不支持的舍入规则: ${rule}`);
1312
1083
  }
1313
-
1314
- // 计算最终金额:roundedValue * interval
1315
1084
  const finalAmount = roundedValue.mul(roundingInterval);
1316
1085
  const originalAmountStr = amount.toFixed(2);
1317
-
1318
- // 如果最终金额是 0 元,则不采用舍入金额,返回原始金额
1319
1086
  if (finalAmount.eq(0)) {
1087
+ console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
1320
1088
  return {
1321
1089
  originalAmount: originalAmountStr,
1322
1090
  roundedAmount: originalAmountStr,
1323
- roundingDifference: '0.00'
1091
+ roundingDifference: "0.00"
1324
1092
  };
1325
1093
  }
1326
1094
  const roundedAmountStr = finalAmount.toFixed(2);
1327
-
1328
- // 计算舍入差额
1329
1095
  const roundingDifference = finalAmount.sub(amount);
1330
1096
  const roundingDifferenceStr = roundingDifference.toFixed(2);
1097
+ console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
1331
1098
  return {
1332
1099
  originalAmount: originalAmountStr,
1333
1100
  roundedAmount: roundedAmountStr,
1334
1101
  roundingDifference: roundingDifferenceStr
1335
1102
  };
1336
1103
  } catch (error) {
1337
- console.error('[PaymentModule] 金额舍入失败:', error);
1104
+ console.error("[PaymentModule] 金额舍入失败:", error);
1338
1105
  throw new Error(`金额舍入失败: ${error instanceof Error ? error.message : String(error)}`);
1339
1106
  }
1340
1107
  }
1341
-
1342
1108
  /**
1343
1109
  * 标准舍入处理(处理中点情况)
1344
1110
  *
@@ -1349,18 +1115,18 @@ class PaymentModule extends _BaseModule.BaseModule {
1349
1115
  standardRound(value, midpointUp) {
1350
1116
  const floorValue = value.floor();
1351
1117
  const fractionalPart = value.minus(floorValue);
1352
-
1353
- // 检查是否是中点(小数部分 = 0.5)
1354
1118
  if (fractionalPart.eq(0.5)) {
1355
- // 中点情况,根据规则决定
1356
1119
  return midpointUp ? floorValue.plus(1) : floorValue;
1357
1120
  } else if (fractionalPart.gt(0.5)) {
1358
- // 大于中点,向上舍入
1359
1121
  return floorValue.plus(1);
1360
1122
  } else {
1361
- // 小于中点,向下舍入
1362
1123
  return floorValue;
1363
1124
  }
1364
1125
  }
1365
- }
1366
- exports.PaymentModule = PaymentModule;
1126
+ };
1127
+ // Annotate the CommonJS export names for ESM import in node:
1128
+ 0 && (module.exports = {
1129
+ PaymentModule,
1130
+ generateRequestUniqueId,
1131
+ ...require("./types")
1132
+ });