diff --git a/backend/internal/router/agent/agent.go b/backend/internal/router/agent/agent.go index 393423f..8615a93 100644 --- a/backend/internal/router/agent/agent.go +++ b/backend/internal/router/agent/agent.go @@ -14,6 +14,7 @@ import ( func SetupAgentRoutes(r *gin.RouterGroup) { r.GET("/stats", handleGetStats) r.GET("/apps", handleGetApps) + r.GET("/apps/:id", handleGetAppDetail) r.GET("/cards", handleGetCards) r.POST("/cards/generate", handleGenerateCards) r.GET("/users", handleGetUsers) @@ -89,6 +90,66 @@ func handleGetApps(c *gin.Context) { }) } +func handleGetAppDetail(c *gin.Context) { + userID := c.GetUint("user_id") + appID := c.Param("id") + + // 检查代理是否有该应用的授权 + var agentApp model.AgentApplication + if err := database.DB.Where("agent_id = ? AND application_id = ?", userID, appID).Preload("Application").First(&agentApp).Error; err != nil { + response.Error(c, 404, "应用不存在或无权访问") + return + } + + // 获取该应用可用的卡类 + var cardTypes []model.CardType + if err := database.DB.Where("application_id = ?", appID).Find(&cardTypes).Error; err != nil { + response.Error(c, 500, "获取卡类列表失败") + return + } + + // 获取代理对该应用的卡类权限和价格 + var agentCardTypes []model.AgentApplicationCardType + database.DB.Where("agent_application_id = ?", agentApp.ID).Find(&agentCardTypes) + + // 构建卡类列表,包含代理权限信息 + cardTypesList := make([]gin.H, 0) + for _, ct := range cardTypes { + // 查找代理是否有该卡类的权限 + var agentPrice float64 + var canGenerate bool + for _, act := range agentCardTypes { + if act.CardTypeID == ct.ID { + agentPrice = act.Price + canGenerate = act.CanGenerate + break + } + } + + // 只返回代理有权限的卡类 + if canGenerate { + cardTypesList = append(cardTypesList, gin.H{ + "id": ct.ID, + "name": ct.Name, + "billing_type": ct.RechargeType, + "price": agentPrice, + "value": ct.Value, + "duration_days": ct.Value, + }) + } + } + + response.Success(c, gin.H{ + "app": gin.H{ + "id": agentApp.Application.ID, + "name": agentApp.Application.Name, + "description": agentApp.Application.Description, + "status": agentApp.Application.Status, + }, + "cardTypes": cardTypesList, + }) +} + func handleGetCards(c *gin.Context) { userID := c.GetUint("user_id")