| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | package routes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"tyapi-server/internal/infrastructure/http/handlers" | 
					
						
							|  |  |  | 	sharedhttp "tyapi-server/internal/shared/http" | 
					
						
							|  |  |  | 	"tyapi-server/internal/shared/middleware" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"go.uber.org/zap" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // FinanceRoutes 财务路由注册器 | 
					
						
							|  |  |  | type FinanceRoutes struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	financeHandler      *handlers.FinanceHandler | 
					
						
							|  |  |  | 	authMiddleware      *middleware.JWTAuthMiddleware | 
					
						
							|  |  |  | 	adminAuthMiddleware *middleware.AdminAuthMiddleware | 
					
						
							|  |  |  | 	logger              *zap.Logger | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewFinanceRoutes 创建财务路由注册器 | 
					
						
							|  |  |  | func NewFinanceRoutes( | 
					
						
							|  |  |  | 	financeHandler *handlers.FinanceHandler, | 
					
						
							|  |  |  | 	authMiddleware *middleware.JWTAuthMiddleware, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	adminAuthMiddleware *middleware.AdminAuthMiddleware, | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 	logger *zap.Logger, | 
					
						
							|  |  |  | ) *FinanceRoutes { | 
					
						
							|  |  |  | 	return &FinanceRoutes{ | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		financeHandler:      financeHandler, | 
					
						
							|  |  |  | 		authMiddleware:      authMiddleware, | 
					
						
							|  |  |  | 		adminAuthMiddleware: adminAuthMiddleware, | 
					
						
							|  |  |  | 		logger:              logger, | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Register 注册财务相关路由 | 
					
						
							|  |  |  | func (r *FinanceRoutes) Register(router *sharedhttp.GinRouter) { | 
					
						
							|  |  |  | 	engine := router.GetEngine() | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 支付宝回调路由(不需要认证) | 
					
						
							|  |  |  | 	alipayGroup := engine.Group("/api/v1/finance/alipay") | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		alipayGroup.POST("/callback", r.financeHandler.HandleAlipayCallback) // 支付宝异步回调 | 
					
						
							|  |  |  | 		alipayGroup.GET("/return", r.financeHandler.HandleAlipayReturn)      // 支付宝同步回调 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 财务路由组,需要用户认证 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 	financeGroup := engine.Group("/api/v1/finance") | 
					
						
							|  |  |  | 	financeGroup.Use(r.authMiddleware.Handle()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// 钱包相关路由 | 
					
						
							|  |  |  | 		walletGroup := financeGroup.Group("/wallet") | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 			walletGroup.GET("", r.financeHandler.GetWallet)                             // 获取钱包信息 | 
					
						
							|  |  |  | 			walletGroup.GET("/transactions", r.financeHandler.GetUserWalletTransactions) // 获取钱包交易记录 | 
					
						
							|  |  |  | 			walletGroup.GET("/recharge-config", r.financeHandler.GetRechargeConfig)      // 获取充值配置 | 
					
						
							|  |  |  | 			walletGroup.POST("/alipay-recharge", r.financeHandler.CreateAlipayRecharge) // 创建支付宝充值订单 | 
					
						
							|  |  |  | 			walletGroup.GET("/recharge-records", r.financeHandler.GetUserRechargeRecords) // 用户充值记录分页 | 
					
						
							|  |  |  | 			walletGroup.GET("/alipay-order-status", r.financeHandler.GetAlipayOrderStatus) // 获取支付宝订单状态 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-02 02:54:21 +08:00
										 |  |  | 	// 发票相关路由,需要用户认证 | 
					
						
							|  |  |  | 	invoiceGroup := engine.Group("/api/v1/invoices") | 
					
						
							|  |  |  | 	invoiceGroup.Use(r.authMiddleware.Handle()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		invoiceGroup.POST("/apply", r.financeHandler.ApplyInvoice)                    // 申请开票 | 
					
						
							|  |  |  | 		invoiceGroup.GET("/info", r.financeHandler.GetUserInvoiceInfo)                // 获取用户发票信息 | 
					
						
							|  |  |  | 		invoiceGroup.PUT("/info", r.financeHandler.UpdateUserInvoiceInfo)             // 更新用户发票信息 | 
					
						
							|  |  |  | 		invoiceGroup.GET("/records", r.financeHandler.GetUserInvoiceRecords)          // 获取用户开票记录 | 
					
						
							|  |  |  | 		invoiceGroup.GET("/available-amount", r.financeHandler.GetAvailableAmount)    // 获取可开票金额 | 
					
						
							|  |  |  | 		invoiceGroup.GET("/:application_id/download", r.financeHandler.DownloadInvoiceFile) // 下载发票文件 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	// 管理员财务路由组 | 
					
						
							|  |  |  | 	adminFinanceGroup := engine.Group("/api/v1/admin/finance") | 
					
						
							|  |  |  | 	adminFinanceGroup.Use(r.adminAuthMiddleware.Handle()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		adminFinanceGroup.POST("/transfer-recharge", r.financeHandler.TransferRecharge) // 对公转账充值 | 
					
						
							|  |  |  | 		adminFinanceGroup.POST("/gift-recharge", r.financeHandler.GiftRecharge)         // 赠送充值 | 
					
						
							|  |  |  | 		adminFinanceGroup.GET("/recharge-records", r.financeHandler.GetAdminRechargeRecords) // 管理员充值记录分页 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-02 02:54:21 +08:00
										 |  |  | 	// 管理员发票相关路由组 | 
					
						
							|  |  |  | 	adminInvoiceGroup := engine.Group("/api/v1/admin/invoices") | 
					
						
							|  |  |  | 	adminInvoiceGroup.Use(r.adminAuthMiddleware.Handle()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		adminInvoiceGroup.GET("/pending", r.financeHandler.GetPendingApplications)                    // 获取待处理申请列表 | 
					
						
							|  |  |  | 		adminInvoiceGroup.POST("/:application_id/approve", r.financeHandler.ApproveInvoiceApplication) // 通过发票申请 | 
					
						
							|  |  |  | 		adminInvoiceGroup.POST("/:application_id/reject", r.financeHandler.RejectInvoiceApplication)   // 拒绝发票申请 | 
					
						
							|  |  |  | 		adminInvoiceGroup.GET("/:application_id/download", r.financeHandler.AdminDownloadInvoiceFile)  // 下载发票文件 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  | 	r.logger.Info("财务路由注册完成") | 
					
						
							|  |  |  | } |