diff --git a/backend/app.py b/backend/app.py index 01354a1..1d67a33 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1854,12 +1854,38 @@ def admin(): """) recent_users_raw = cursor.fetchall() - # 시간을 KST로 변환 + # 시간을 KST로 변환 + 조제 이력 확인 recent_users = [] + + # MSSQL 세션 (조제 이력 확인용) + try: + mssql_session = db_manager.get_session('PM_PRES') + except: + mssql_session = None + for user in recent_users_raw: user_dict = dict(user) user_dict['created_at'] = utc_to_kst_str(user['created_at']) user_dict['kakao_verified_at'] = utc_to_kst_str(user['kakao_verified_at']) if user['kakao_verified_at'] else None + + # 조제 이력 확인 (MSSQL) + user_dict['has_prescription'] = False + if mssql_session and user['phone']: + try: + phone_clean = user['phone'].replace('-', '').replace(' ', '') + pres_check = mssql_session.execute(text(""" + SELECT TOP 1 p.CusCode + FROM PM_BASE.dbo.CD_PERSON p + INNER JOIN PS_main ps ON p.CUSCODE = ps.CusCode + WHERE REPLACE(REPLACE(p.PHONE, '-', ''), ' ', '') = :phone + OR REPLACE(REPLACE(p.PHONE2, '-', ''), ' ', '') = :phone + OR REPLACE(REPLACE(p.TEL_NO, '-', ''), ' ', '') = :phone + """), {'phone': phone_clean}).fetchone() + if pres_check: + user_dict['has_prescription'] = True + except Exception as e: + logging.warning(f"조제 이력 확인 실패 (user {user['id']}): {e}") + recent_users.append(user_dict) # 최근 적립 내역 (50건) diff --git a/backend/templates/admin.html b/backend/templates/admin.html index 60aa84d..8c29a67 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -472,7 +472,8 @@