feat: 대시보드에 조제 이력 뱃지 추가
- PM_BASE.CD_PERSON에서 전화번호로 CUSCODE 매칭
- PS_main에서 조제 기록 유무 확인
- 조제 기록 있으면 녹색 '💊 환자' 뱃지
- 조제 기록 없으면 회색 '일반' 뱃지
This commit is contained in:
parent
04b0f3a8ca
commit
d0e7d6bbd2
@ -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건)
|
||||
|
||||
@ -472,7 +472,8 @@
|
||||
<th>전화번호</th>
|
||||
<th>포인트</th>
|
||||
<th>가입일</th>
|
||||
<th>인증</th>
|
||||
<th>카카오</th>
|
||||
<th>조제</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -490,6 +491,13 @@
|
||||
<span style="display: inline-flex; align-items: center; background: #f1f3f5; color: #868e96; font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 10px;">미인증</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.has_prescription %}
|
||||
<span style="display: inline-flex; align-items: center; gap: 3px; background: #d3f9d8; color: #2b8a3e; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 10px;">💊 환자</span>
|
||||
{% else %}
|
||||
<span style="display: inline-flex; align-items: center; background: #f1f3f5; color: #adb5bd; font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 10px;">일반</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user