diff --git a/backend/app.py b/backend/app.py index f8e6fff..cfa7d90 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2208,6 +2208,35 @@ def admin(): FROM claim_tokens """) token_stats = cursor.fetchone() + + # 반려동물 통계 + cursor.execute(""" + SELECT + COUNT(*) as total_pets, + SUM(CASE WHEN species = 'dog' THEN 1 ELSE 0 END) as dog_count, + SUM(CASE WHEN species = 'cat' THEN 1 ELSE 0 END) as cat_count, + COUNT(DISTINCT user_id) as owners_count + FROM pets + WHERE is_active = 1 + """) + pet_stats = cursor.fetchone() + + # 최근 등록 반려동물 (10마리) + cursor.execute(""" + SELECT p.id, p.name, p.species, p.breed, p.photo_url, p.created_at, + u.nickname as owner_name, u.phone as owner_phone + FROM pets p + JOIN users u ON p.user_id = u.id + WHERE p.is_active = 1 + ORDER BY p.created_at DESC + LIMIT 10 + """) + recent_pets_raw = cursor.fetchall() + recent_pets = [] + for pet in recent_pets_raw: + pet_dict = dict(pet) + pet_dict['created_at'] = utc_to_kst_str(pet['created_at']) + recent_pets.append(pet_dict) # 최근 QR 발행 내역 (20건) cursor.execute(""" @@ -2237,7 +2266,9 @@ def admin(): recent_users=recent_users, recent_transactions=recent_transactions, token_stats=token_stats, - recent_tokens=recent_tokens) + recent_tokens=recent_tokens, + pet_stats=pet_stats, + recent_pets=recent_pets) # ============================================================================ diff --git a/backend/templates/admin.html b/backend/templates/admin.html index d74b6a9..5ef63b8 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -457,8 +457,44 @@ {% endif %} +