From 45eac027cfe34f01505bcb1f779f9470cca321c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E4=BD=A9=E5=BA=AD?= Date: Sat, 27 Sep 2025 17:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=BA=E6=B0=A3=E6=8E=92?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E6=95=B8=E9=87=8F=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/competition/popularity-rankings.tsx | 11 ++++++----- lib/services/database-service.ts | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/competition/popularity-rankings.tsx b/components/competition/popularity-rankings.tsx index 1aafec4..fd4ab75 100644 --- a/components/competition/popularity-rankings.tsx +++ b/components/competition/popularity-rankings.tsx @@ -376,10 +376,11 @@ export function PopularityRankings() { const currentPage = teamCurrentPage const setCurrentPage = setTeamCurrentPage - const totalPages = Math.ceil(teamsWithScores.length / ITEMS_PER_PAGE) + const validTeams = teamsWithScores.filter(team => team && team.id) + const totalPages = Math.ceil(validTeams.length / ITEMS_PER_PAGE) const startIndex = currentPage * ITEMS_PER_PAGE const endIndex = startIndex + ITEMS_PER_PAGE - const currentTeams = teamsWithScores.slice(startIndex, endIndex) + const currentTeams = validTeams.slice(startIndex, endIndex) return ( @@ -391,7 +392,7 @@ export function PopularityRankings() { {title} - {currentCompetition?.name || "暫無進行中的競賽"} - {title}人氣排名 (共 {teamsWithScores.length} 個團隊) + {currentCompetition?.name || "暫無進行中的競賽"} - {title}人氣排名 (共 {teamsWithScores.filter(team => team && team.id).length} 個團隊)
@@ -408,7 +409,7 @@ export function PopularityRankings() { {totalPages > 1 && (
- 顯示第 {startIndex + 1}-{Math.min(endIndex, teamsWithScores.length)} 名,共 {teamsWithScores.length}{" "} + 顯示第 {startIndex + 1}-{Math.min(endIndex, teamsWithScores.filter(team => team && team.id).length)} 名,共 {teamsWithScores.filter(team => team && team.id).length}{" "} 個團隊
@@ -638,7 +639,7 @@ export function PopularityRankings() { {currentCompetition.type === 'team' - ? `${competitionTeams.length} 個參賽團隊` + ? `${competitionTeams.filter(team => team && team.id).length} 個參賽團隊` : `${filteredApps.length} 個參賽應用`}
diff --git a/lib/services/database-service.ts b/lib/services/database-service.ts index db9754c..dd380c9 100644 --- a/lib/services/database-service.ts +++ b/lib/services/database-service.ts @@ -1727,16 +1727,15 @@ export class CompetitionService extends DatabaseServiceBase { ct.registered_at, u.name as leader_name, u.phone as leader_phone, - COUNT(tm.id) as actual_member_count, - a.id as app_id, - a.name as app_name + COUNT(DISTINCT tm.id) as actual_member_count, + COUNT(DISTINCT a.id) as app_count FROM competition_teams ct JOIN teams t ON ct.team_id = t.id LEFT JOIN users u ON t.leader_id = u.id LEFT JOIN team_members tm ON t.id = tm.team_id LEFT JOIN apps a ON t.id = a.team_id AND a.is_active = 1 WHERE ct.competition_id = ? AND t.is_active = 1 - GROUP BY t.id, ct.registered_at, u.name, u.phone, a.id, a.name + GROUP BY t.id, t.name, t.leader_id, t.department, t.contact_email, t.total_likes, t.is_active, t.created_at, t.updated_at, ct.registered_at, u.name, u.phone ORDER BY ct.registered_at ASC `; return await DatabaseServiceBase.safeQuery(sql, [competitionId]);