修复: 1.管理员编辑代理云端数据权限switch无效(后端缺少CanViewCloudData字段) 2.代理卡密status显示disabledbanned 3.代理用户管理只显示代理/子代理卡密充值过的用户
This commit is contained in:
@@ -29,6 +29,7 @@ type User struct {
|
||||
|
||||
ParentAgentID *uint `gorm:"index" json:"parent_agent_id"`
|
||||
CanCreateAgent bool `gorm:"default:false" json:"can_create_agent"`
|
||||
CanViewCloudData bool `gorm:"default:false" json:"can_view_cloud_data"`
|
||||
Balance float64 `gorm:"default:0" json:"balance"`
|
||||
TotalConsumption float64 `gorm:"default:0" json:"total_consumption"`
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ type AgentTreeNode struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
LastLoginAt string `json:"last_login_at"`
|
||||
Balance float64 `json:"balance"`
|
||||
CanCreateAgent bool `json:"can_create_agent"`
|
||||
CanCreateAgent bool `json:"can_create_agent"`
|
||||
CanViewCloudData bool `json:"can_view_cloud_data"`
|
||||
CardsCount int `json:"cards_count"`
|
||||
ChildAgentsCount int `json:"child_agents_count"`
|
||||
Children []AgentTreeNode `json:"children,omitempty"`
|
||||
@@ -80,6 +81,7 @@ func handleGetAgents(c *gin.Context) {
|
||||
Balance float64 `json:"balance"`
|
||||
TotalConsumption float64 `json:"total_consumption"`
|
||||
CanCreateAgent bool `json:"can_create_agent"`
|
||||
CanViewCloudData bool `json:"can_view_cloud_data"`
|
||||
CardsCount int `json:"cards_count"`
|
||||
ChildAgentsCount int `json:"child_agents_count"`
|
||||
}
|
||||
@@ -152,8 +154,9 @@ func handleGetAgents(c *gin.Context) {
|
||||
LastLoginAt: lastLoginAt,
|
||||
Balance: user.Balance,
|
||||
TotalConsumption: user.TotalConsumption,
|
||||
CanCreateAgent: user.CanCreateAgent,
|
||||
CardsCount: cardsCountMap[user.ID],
|
||||
CanCreateAgent: user.CanCreateAgent,
|
||||
CanViewCloudData: user.CanViewCloudData,
|
||||
CardsCount: cardsCountMap[user.ID],
|
||||
ChildAgentsCount: childCountMap[user.ID],
|
||||
})
|
||||
}
|
||||
@@ -229,8 +232,9 @@ func handleGetAgentsTree(c *gin.Context) {
|
||||
CreatedAt: user.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
LastLoginAt: lastLoginAt,
|
||||
Balance: user.Balance,
|
||||
CanCreateAgent: user.CanCreateAgent,
|
||||
CardsCount: int(cardsCount),
|
||||
CanCreateAgent: user.CanCreateAgent,
|
||||
CanViewCloudData: user.CanViewCloudData,
|
||||
CardsCount: int(cardsCount),
|
||||
ChildAgentsCount: int(childAgentsCount),
|
||||
}
|
||||
|
||||
@@ -256,12 +260,13 @@ func handleGetAgentsTree(c *gin.Context) {
|
||||
|
||||
func handleCreateAgent(c *gin.Context) {
|
||||
var req struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
ParentAgentID *uint `json:"parent_agent_id"`
|
||||
CanCreateAgent bool `json:"can_create_agent"`
|
||||
Balance float64 `json:"balance"`
|
||||
Username string `json:"username" binding:"required"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
ParentAgentID *uint `json:"parent_agent_id"`
|
||||
CanCreateAgent bool `json:"can_create_agent"`
|
||||
CanViewCloudData bool `json:"can_view_cloud_data"`
|
||||
Balance float64 `json:"balance"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, 400, "参数错误")
|
||||
@@ -296,13 +301,14 @@ func handleCreateAgent(c *gin.Context) {
|
||||
}
|
||||
|
||||
user := model.User{
|
||||
Username: req.Username,
|
||||
Password: string(hashedPassword),
|
||||
Role: "agent",
|
||||
Status: "active",
|
||||
ParentAgentID: req.ParentAgentID,
|
||||
CanCreateAgent: req.CanCreateAgent,
|
||||
Balance: req.Balance,
|
||||
Username: req.Username,
|
||||
Password: string(hashedPassword),
|
||||
Role: "agent",
|
||||
Status: "active",
|
||||
ParentAgentID: req.ParentAgentID,
|
||||
CanCreateAgent: req.CanCreateAgent,
|
||||
CanViewCloudData: req.CanViewCloudData,
|
||||
Balance: req.Balance,
|
||||
}
|
||||
|
||||
if req.Email != "" {
|
||||
@@ -406,7 +412,8 @@ func handleGetAgentDetail(c *gin.Context) {
|
||||
"role": user.Role,
|
||||
"parent_agent_id": user.ParentAgentID,
|
||||
"parent_agent_name": parentAgentName,
|
||||
"can_create_agent": user.CanCreateAgent,
|
||||
"can_create_agent": user.CanCreateAgent,
|
||||
"can_view_cloud_data": user.CanViewCloudData,
|
||||
"balance": user.Balance,
|
||||
"created_at": user.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"last_login_at": lastLoginAt,
|
||||
@@ -426,11 +433,12 @@ func handleUpdateAgent(c *gin.Context) {
|
||||
}
|
||||
|
||||
var req struct {
|
||||
ParentAgentID *uint `json:"parent_agent_id"`
|
||||
Email *string `json:"email"`
|
||||
Password *string `json:"password"`
|
||||
CanCreateAgent *bool `json:"can_create_agent"`
|
||||
Balance *float64 `json:"balance"`
|
||||
ParentAgentID *uint `json:"parent_agent_id"`
|
||||
Email *string `json:"email"`
|
||||
Password *string `json:"password"`
|
||||
CanCreateAgent *bool `json:"can_create_agent"`
|
||||
CanViewCloudData *bool `json:"can_view_cloud_data"`
|
||||
Balance *float64 `json:"balance"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, 400, "参数错误")
|
||||
@@ -464,6 +472,9 @@ func handleUpdateAgent(c *gin.Context) {
|
||||
if req.CanCreateAgent != nil {
|
||||
user.CanCreateAgent = *req.CanCreateAgent
|
||||
}
|
||||
if req.CanViewCloudData != nil {
|
||||
user.CanViewCloudData = *req.CanViewCloudData
|
||||
}
|
||||
if req.Balance != nil {
|
||||
user.Balance = *req.Balance
|
||||
}
|
||||
|
||||
@@ -181,8 +181,8 @@ func handleGetCards(c *gin.Context) {
|
||||
var expiredCount int64
|
||||
database.DB.Model(&model.Card{}).Where("("+baseCondition+") AND status = ?", userID, userID, "expired").Count(&expiredCount)
|
||||
|
||||
var disabledCount int64
|
||||
database.DB.Model(&model.Card{}).Where("("+baseCondition+") AND status = ?", userID, userID, "disabled").Count(&disabledCount)
|
||||
var bannedCount int64
|
||||
database.DB.Model(&model.Card{}).Where("("+baseCondition+") AND status = ?", userID, userID, "banned").Count(&bannedCount)
|
||||
|
||||
query := database.DB.Model(&model.Card{}).Where(baseCondition, userID, userID)
|
||||
|
||||
@@ -283,7 +283,7 @@ func handleGetCards(c *gin.Context) {
|
||||
"unused_count": unusedCount,
|
||||
"used_count": usedCount,
|
||||
"expired_count": expiredCount,
|
||||
"disabled_count": disabledCount,
|
||||
"banned_count": bannedCount,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -412,17 +412,40 @@ func generateCardCode() string {
|
||||
func handleGetUsers(c *gin.Context) {
|
||||
userID := c.GetUint("user_id")
|
||||
|
||||
var agentApps []model.AgentApplication
|
||||
database.DB.Where("agent_id = ?", userID).Find(&agentApps)
|
||||
appIDs := make([]uint, 0)
|
||||
for _, app := range agentApps {
|
||||
appIDs = append(appIDs, app.ApplicationID)
|
||||
agentIDs := []uint{userID}
|
||||
var childAgents []model.User
|
||||
database.DB.Where("parent_agent_id = ? AND role = ?", userID, "agent").Find(&childAgents)
|
||||
for _, child := range childAgents {
|
||||
agentIDs = append(agentIDs, child.ID)
|
||||
}
|
||||
|
||||
if len(appIDs) == 0 {
|
||||
var cardIDs []uint
|
||||
database.DB.Model(&model.Card{}).Where("agent_id IN ?", agentIDs).Pluck("id", &cardIDs)
|
||||
|
||||
if len(cardIDs) == 0 {
|
||||
response.Success(c, gin.H{
|
||||
"users": []interface{}{},
|
||||
"total": 0,
|
||||
"users": []interface{}{},
|
||||
"total": 0,
|
||||
"active_count": 0,
|
||||
"disabled_count": 0,
|
||||
"banned_count": 0,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var appUserIDs []uint
|
||||
database.DB.Model(&model.RechargeRecord{}).
|
||||
Where("card_id IN ? AND status = ?", cardIDs, "success").
|
||||
Distinct("user_id").
|
||||
Pluck("user_id", &appUserIDs)
|
||||
|
||||
if len(appUserIDs) == 0 {
|
||||
response.Success(c, gin.H{
|
||||
"users": []interface{}{},
|
||||
"total": 0,
|
||||
"active_count": 0,
|
||||
"disabled_count": 0,
|
||||
"banned_count": 0,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -431,12 +454,12 @@ func handleGetUsers(c *gin.Context) {
|
||||
pageSize := c.DefaultQuery("page_size", "20")
|
||||
|
||||
var total int64
|
||||
database.DB.Model(&model.AppUser{}).Where("application_id IN ?", appIDs).Count(&total)
|
||||
database.DB.Model(&model.AppUser{}).Where("id IN ?", appUserIDs).Count(&total)
|
||||
|
||||
var activeCount, disabledCount, bannedCount int64
|
||||
database.DB.Model(&model.AppUser{}).Where("application_id IN ? AND status = ?", appIDs, "active").Count(&activeCount)
|
||||
database.DB.Model(&model.AppUser{}).Where("application_id IN ? AND status = ?", appIDs, "disabled").Count(&disabledCount)
|
||||
database.DB.Model(&model.AppUser{}).Where("application_id IN ? AND status = ?", appIDs, "banned").Count(&bannedCount)
|
||||
database.DB.Model(&model.AppUser{}).Where("id IN ? AND status = ?", appUserIDs, "active").Count(&activeCount)
|
||||
database.DB.Model(&model.AppUser{}).Where("id IN ? AND status = ?", appUserIDs, "disabled").Count(&disabledCount)
|
||||
database.DB.Model(&model.AppUser{}).Where("id IN ? AND status = ?", appUserIDs, "banned").Count(&bannedCount)
|
||||
|
||||
var users []model.AppUser
|
||||
offset := 0
|
||||
@@ -449,7 +472,7 @@ func handleGetUsers(c *gin.Context) {
|
||||
limit = pageSizeInt
|
||||
}
|
||||
|
||||
database.DB.Where("application_id IN ?", appIDs).Order("created_at DESC").Limit(limit).Offset(offset).Find(&users)
|
||||
database.DB.Where("id IN ?", appUserIDs).Order("created_at DESC").Limit(limit).Offset(offset).Find(&users)
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"users": users,
|
||||
@@ -710,7 +733,7 @@ func handleExportCards(c *gin.Context) {
|
||||
for _, card := range cards {
|
||||
ct := cardTypeMap[card.CardTypeID]
|
||||
app := appMap[card.ApplicationID]
|
||||
statusMap := map[string]string{"unused": "未使用", "used": "已使用", "expired": "已过期", "disabled": "已禁用"}
|
||||
statusMap := map[string]string{"unused": "未使用", "used": "已使用", "expired": "已过期", "banned": "已禁用"}
|
||||
statusText := statusMap[card.Status]
|
||||
if statusText == "" {
|
||||
statusText = card.Status
|
||||
|
||||
Reference in New Issue
Block a user