From bdbb7f18d5f621a094682998b97eab40c684edf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E4=BD=A9=E5=BA=AD?= Date: Mon, 29 Sep 2025 23:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E5=8F=B0=E5=BE=97=E7=8D=8E=E7=85=A7?= =?UTF-8?q?=E7=89=87=E5=91=88=E7=8F=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/admin/competition-management.tsx | 22 +++++++++++++++++---- lib/services/database-service.ts | 5 ++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/admin/competition-management.tsx b/components/admin/competition-management.tsx index 50adcc1..9af65b0 100644 --- a/components/admin/competition-management.tsx +++ b/components/admin/competition-management.tsx @@ -1885,11 +1885,25 @@ export function CompetitionManagement() { } // 準備獎項數據 + console.log('🔍 準備獎項數據 - 參賽者資訊:', { + actualParticipantType, + participantId: newAward.participantId, + participantName, + participant: participant ? { + id: participant.id, + name: participant.name, + primary_app_id: participant.primary_app_id, + primary_app_name: participant.primary_app_name, + app_id: participant.app_id, + app_name: participant.app_name + } : null + }); + const awardData = { competition_id: newAward.competitionId, - app_id: actualParticipantType === "individual" ? newAward.participantId : (participant?.app_id || null), + app_id: actualParticipantType === "individual" ? newAward.participantId : (participant?.primary_app_id || null), team_id: actualParticipantType === "team" ? newAward.participantId : null, - app_name: actualParticipantType === "individual" ? participantName : (participant?.app_name || null), + app_name: actualParticipantType === "individual" ? participantName : (participant?.primary_app_name || null), team_name: actualParticipantType === "team" ? participantName : null, creator: creatorName, award_type: newAward.awardType, @@ -1936,9 +1950,9 @@ export function CompetitionManagement() { const awardItem = { id: result.data.id || selectedAward.id, competitionId: newAward.competitionId, - appId: actualParticipantType === "individual" ? newAward.participantId : (participant?.app_id || null), + appId: actualParticipantType === "individual" ? newAward.participantId : (participant?.primary_app_id || null), teamId: actualParticipantType === "team" ? newAward.participantId : null, - appName: actualParticipantType === "individual" ? participantName : (participant?.app_name || null), + appName: actualParticipantType === "individual" ? participantName : (participant?.primary_app_name || null), teamName: actualParticipantType === "team" ? participantName : null, creator: creatorName, awardType: newAward.awardType as any, diff --git a/lib/services/database-service.ts b/lib/services/database-service.ts index 9764222..939bafd 100644 --- a/lib/services/database-service.ts +++ b/lib/services/database-service.ts @@ -1728,7 +1728,10 @@ export class CompetitionService extends DatabaseServiceBase { u.name as leader_name, u.phone as leader_phone, COUNT(DISTINCT tm.id) as actual_member_count, - COUNT(DISTINCT a.id) as app_count + COUNT(DISTINCT a.id) as app_count, + -- 獲取團隊的主要應用(第一個應用) + (SELECT a2.id FROM apps a2 WHERE a2.team_id = t.id AND a2.is_active = 1 ORDER BY a2.created_at ASC LIMIT 1) as primary_app_id, + (SELECT a2.name FROM apps a2 WHERE a2.team_id = t.id AND a2.is_active = 1 ORDER BY a2.created_at ASC LIMIT 1) as primary_app_name FROM competition_teams ct JOIN teams t ON ct.team_id = t.id LEFT JOIN users u ON t.leader_id = u.id