diff --git a/backend/app.py b/backend/app.py index a7ba557..69651c3 100644 --- a/backend/app.py +++ b/backend/app.py @@ -807,7 +807,8 @@ def admin_search_product(): 'user_id': claim_row['claimed_by_user_id'], 'user_name': claim_row['nickname'], 'user_phone': claim_row['phone'], - 'purchase_date': claim_row['claimed_at'][:16].replace('T', ' ') if claim_row['claimed_at'] else '-', + 'purchase_date': str(mssql_row.InsertTime)[:16].replace('T', ' ') if mssql_row.InsertTime else '-', # MSSQL 실제 거래 시간 + 'claimed_date': str(claim_row['claimed_at'])[:16].replace('T', ' ') if claim_row['claimed_at'] else '-', # 적립 시간 'quantity': float(mssql_row.SL_NM_item or 0), 'total_amount': int(claim_row['total_amount']) }) diff --git a/backend/templates/admin.html b/backend/templates/admin.html index 4453979..54499d1 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -254,6 +254,28 @@ color: #6366f1; } + .sort-btn { + padding: 8px 16px; + border: 2px solid #e9ecef; + background: #fff; + border-radius: 8px; + cursor: pointer; + font-size: 13px; + font-weight: 600; + color: #868e96; + transition: all 0.2s; + } + + .sort-btn:hover { + border-color: #ced4da; + } + + .sort-btn.active { + border-color: #6366f1; + background: #f8f9ff; + color: #6366f1; + } + .search-input-wrapper { position: relative; } @@ -709,7 +731,14 @@ // ===== 사용자 상세 모달 함수 ===== + // 전역 변수: 현재 사용자 데이터 저장 + let currentUserData = null; + let currentSortType = 'date'; // 'date' 또는 'amount' + function showUserDetail(userId) { + // 정렬 타입 초기화 + currentSortType = 'date'; + document.getElementById('userDetailModal').style.display = 'block'; document.getElementById('userDetailContent').innerHTML = '
불러오는 중...
'; @@ -742,6 +771,9 @@ } function renderUserDetail(data) { + // 전역 변수에 데이터 저장 + currentUserData = data; + const user = data.user; const mileageHistory = data.mileage_history; const purchases = data.purchases; @@ -784,11 +816,89 @@ + +
+ + +
+
+
+
+ + + + `; + + document.getElementById('userDetailContent').innerHTML = html; + + // 구매 이력 렌더링 (정렬 적용) + renderPurchaseHistory(); + } + + function renderPurchaseHistory() { + if (!currentUserData) return; + + const purchases = [...currentUserData.purchases]; // 복사본 생성 + + // 정렬 적용 + if (currentSortType === 'date') { + // 날짜별 정렬 (최신순) + purchases.sort((a, b) => { + const dateA = new Date(a.date); + const dateB = new Date(b.date); + return dateB - dateA; + }); + } else if (currentSortType === 'amount') { + // 금액별 정렬 (높은 순) + purchases.sort((a, b) => b.amount - a.amount); + } + + // HTML 생성 + let html = ''; if (purchases.length > 0) { purchases.forEach((purchase, index) => { const accordionId = `accordion-${index}`; @@ -849,55 +959,23 @@ `; }); } else { - html += '

구매 이력이 없습니다.

'; + html = '

구매 이력이 없습니다.

'; } - html += ` - + document.getElementById('purchase-history-container').innerHTML = html; + } - - - `; - - document.getElementById('userDetailContent').innerHTML = html; + // 구매 이력 다시 렌더링 + renderPurchaseHistory(); } function toggleAccordion(accordionId) { @@ -931,6 +1009,12 @@ document.getElementById('tab-' + tabName).style.borderBottom = '3px solid #6366f1'; document.getElementById('tab-' + tabName).style.color = '#6366f1'; document.getElementById('tab-content-' + tabName).style.display = 'block'; + + // 정렬 버튼 표시/숨기기 (구매 이력 탭에만 표시) + const sortButtons = document.getElementById('sort-buttons'); + if (sortButtons) { + sortButtons.style.display = (tabName === 'purchases') ? 'flex' : 'none'; + } } // ===== 포인트 사용 기능 ===== @@ -1190,6 +1274,7 @@ 이름 전화번호 구매일시 + 적립일시 수량 구매금액 @@ -1203,6 +1288,7 @@ ${result.user_name} ${result.user_phone} ${result.purchase_date} + ${result.claimed_date} ${result.quantity} ${result.total_amount.toLocaleString()}원