修复管理员卡密管理页面统计数据显示不准确
This commit is contained in:
@@ -446,6 +446,28 @@ func handleGetCards(c *gin.Context) {
|
||||
var total int64
|
||||
query.Count(&total)
|
||||
|
||||
baseQuery := database.DB.Model(&model.Card{}).
|
||||
Joins("JOIN card_types ON cards.card_type_id = card_types.id").
|
||||
Joins("JOIN applications ON card_types.application_id = applications.id")
|
||||
|
||||
if len(authorizedAppIDs) > 0 {
|
||||
baseQuery = baseQuery.Where("applications.user_id = ? OR (cards.application_id IN ? AND cards.creator_id = ?)", userID, authorizedAppIDs, userID)
|
||||
} else {
|
||||
baseQuery = baseQuery.Where("applications.user_id = ?", userID)
|
||||
}
|
||||
|
||||
var unusedCount int64
|
||||
baseQuery.Where("cards.status = ?", "unused").Count(&unusedCount)
|
||||
|
||||
var usedCount int64
|
||||
baseQuery.Where("cards.status = ?", "used").Count(&usedCount)
|
||||
|
||||
var bannedCount int64
|
||||
baseQuery.Where("cards.status = ?", "banned").Count(&bannedCount)
|
||||
|
||||
var expiredCount int64
|
||||
baseQuery.Where("cards.status = ?", "expired").Count(&expiredCount)
|
||||
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||
offset := (page - 1) * pageSize
|
||||
@@ -459,11 +481,15 @@ func handleGetCards(c *gin.Context) {
|
||||
fmt.Printf("[DEBUG] Found %d cards for user %d\n", len(cards), userID)
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"cards": cards,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"total_page": (total + int64(pageSize) - 1) / int64(pageSize),
|
||||
"cards": cards,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"total_page": (total + int64(pageSize) - 1) / int64(pageSize),
|
||||
"unused_count": unusedCount,
|
||||
"used_count": usedCount,
|
||||
"banned_count": bannedCount,
|
||||
"expired_count": expiredCount,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user