From e63753a8539891ea97aeab9cc2848719d6ca2d9a Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 9 May 2026 23:58:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85=E5=92=8C?= =?UTF-8?q?=E5=8D=A1=E7=B1=BB=E5=88=97=E8=A1=A8API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 GET /agent/apps/:id 接口 - 返回代理有权使用的卡类列表及其价格 Co-Authored-By: Claude Opus 4.7 --- backend/internal/router/agent/agent.go | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) 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")