修复管理员卡密管理页面统计数据显示不准确
This commit is contained in:
@@ -446,6 +446,28 @@ func handleGetCards(c *gin.Context) {
|
|||||||
var total int64
|
var total int64
|
||||||
query.Count(&total)
|
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"))
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||||
offset := (page - 1) * pageSize
|
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)
|
fmt.Printf("[DEBUG] Found %d cards for user %d\n", len(cards), userID)
|
||||||
|
|
||||||
response.Success(c, gin.H{
|
response.Success(c, gin.H{
|
||||||
"cards": cards,
|
"cards": cards,
|
||||||
"total": total,
|
"total": total,
|
||||||
"page": page,
|
"page": page,
|
||||||
"page_size": pageSize,
|
"page_size": pageSize,
|
||||||
"total_page": (total + int64(pageSize) - 1) / int64(pageSize),
|
"total_page": (total + int64(pageSize) - 1) / int64(pageSize),
|
||||||
|
"unused_count": unusedCount,
|
||||||
|
"used_count": usedCount,
|
||||||
|
"banned_count": bannedCount,
|
||||||
|
"expired_count": expiredCount,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ const filteredCardTypes = computed(() => {
|
|||||||
return cardTypes.value
|
return cardTypes.value
|
||||||
})
|
})
|
||||||
|
|
||||||
const unusedCount = computed(() => cards.value.filter(card => card.status === 'unused').length)
|
const unusedCount = ref(0)
|
||||||
const usedCount = computed(() => cards.value.filter(card => card.status === 'used').length)
|
const usedCount = ref(0)
|
||||||
const bannedCount = computed(() => cards.value.filter(card => card.status === 'banned').length)
|
const bannedCount = ref(0)
|
||||||
|
|
||||||
const applicationOptions = computed(() => {
|
const applicationOptions = computed(() => {
|
||||||
return applications.value.map(app => ({
|
return applications.value.map(app => ({
|
||||||
@@ -132,9 +132,12 @@ async function fetchCards() {
|
|||||||
params.append('search', searchFilter.value.trim())
|
params.append('search', searchFilter.value.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await api.get<{ cards: Card[], total: number }>(`/dev/cards?${params.toString()}`)
|
const data = await api.get<any>(`/dev/cards?${params.toString()}`)
|
||||||
cards.value = data?.cards || []
|
cards.value = data?.cards || []
|
||||||
total.value = data?.total || 0
|
total.value = data?.total || 0
|
||||||
|
unusedCount.value = data?.unused_count || 0
|
||||||
|
usedCount.value = data?.used_count || 0
|
||||||
|
bannedCount.value = data?.banned_count || 0
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('获取卡密列表失败:', error)
|
console.error('获取卡密列表失败:', error)
|
||||||
|
|||||||
Reference in New Issue
Block a user