修复管理员卡密管理页面统计数据显示不准确
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
|
||||
@@ -464,6 +486,10 @@ func handleGetCards(c *gin.Context) {
|
||||
"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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ const filteredCardTypes = computed(() => {
|
||||
return cardTypes.value
|
||||
})
|
||||
|
||||
const unusedCount = computed(() => cards.value.filter(card => card.status === 'unused').length)
|
||||
const usedCount = computed(() => cards.value.filter(card => card.status === 'used').length)
|
||||
const bannedCount = computed(() => cards.value.filter(card => card.status === 'banned').length)
|
||||
const unusedCount = ref(0)
|
||||
const usedCount = ref(0)
|
||||
const bannedCount = ref(0)
|
||||
|
||||
const applicationOptions = computed(() => {
|
||||
return applications.value.map(app => ({
|
||||
@@ -132,9 +132,12 @@ async function fetchCards() {
|
||||
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 || []
|
||||
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) {
|
||||
console.error('获取卡密列表失败:', error)
|
||||
|
||||
Reference in New Issue
Block a user