chore(version): 버전 8.58 업데이트 및 문자 이력 고객정보 저장 기능 추가

수동 일반 발주의 이름·연락처·주소를 문자 이력에 함께 저장하고
최근 전송 메시지 클릭 시 다시 불러오도록 개선

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 11:37:44 +09:00
parent 2f73e605aa
commit 7afe90646b
4 changed files with 119 additions and 31 deletions
+54 -22
View File
@@ -214,12 +214,20 @@ templates = Jinja2Templates(directory="templates")
# Globals
SMS_HISTORY_FILE = 'sms_history.dat'
SMS_HISTORY_HEADERS = ["일시", "주문유형", "입금액", "주문아이템", "메시지 내용", "이름", "연락처", "주소"]
GSPREAD_CRED_FILE = 'manual-ordering.json'
MANUAL_SPREADSHEET_ID = '1QxFtjDurPPZd8NmtXBy4XEUIzkf93aXD5Mlx5kB33xw'
SETTINGS_SPREADSHEET_ID = '1k7SNEdIaRtGXzQNdJSQAiNSDRwzOePDRTLHY_mNCO8M'
MANUAL_HISTORY_FILE = 'manual_history.dat'
# ----- Utility Functions -----
def first_nonempty(data: dict, *keys: str) -> str:
for key in keys:
value = data.get(key)
if value is not None and str(value).strip():
return str(value)
return ""
def read_config(force_refresh=False):
global _CONFIG_ROWS_CACHE, _CONFIG_ROWS_CACHE_TIME
@@ -508,7 +516,7 @@ def get_sms_history_worksheet():
worksheet_sms_history_global = ss.worksheet("문자내역")
except gspread.exceptions.WorksheetNotFound:
worksheet_sms_history_global = ss.add_worksheet(title="문자내역", rows=1000, cols=10)
worksheet_sms_history_global.append_row(["일시", "주문유형", "입금액", "주문아이템", "메시지 내용"])
worksheet_sms_history_global.append_row(SMS_HISTORY_HEADERS)
return worksheet_sms_history_global
def get_manual_history_worksheet():
@@ -647,6 +655,16 @@ async def download_and_clear_sheet():
@app.get("/api/sms/history")
async def get_history():
local_history = {}
def merge_history_item(sheet_item, local_item):
if not local_item:
return sheet_item
merged = dict(sheet_item)
merged.update(local_item)
for key in ("custName", "custPhone", "custAddress", "customer_name", "phone", "address"):
if not merged.get(key) and sheet_item.get(key):
merged[key] = sheet_item[key]
return merged
if os.path.exists(SMS_HISTORY_FILE):
with open(SMS_HISTORY_FILE, 'r', encoding='utf-8') as f:
for line in f:
@@ -657,7 +675,7 @@ async def get_history():
local_history[item["timestamp"]] = item
except:
pass
history = []
try:
ws = get_sms_history_worksheet()
@@ -667,23 +685,30 @@ async def get_history():
if not row or not row[0].strip():
continue
timestamp = row[0]
if timestamp in local_history:
history.append(local_history[timestamp])
else:
order_type = row[1] if len(row) > 1 else ""
deposit_amt = row[2] if len(row) > 2 else ""
items_str = row[3] if len(row) > 3 else ""
preview_text = row[4] if len(row) > 4 else ""
preview_text = preview_text.replace(" ", "\n")
history.append({
"timestamp": timestamp,
"orderType": order_type,
"deposit_amount_str": deposit_amt,
"items_str": items_str,
"previewText": preview_text
})
order_type = row[1] if len(row) > 1 else ""
deposit_amt = row[2] if len(row) > 2 else ""
items_str = row[3] if len(row) > 3 else ""
preview_text = row[4] if len(row) > 4 else ""
cust_name = row[5] if len(row) > 5 else ""
cust_phone = row[6] if len(row) > 6 else ""
cust_address = row[7] if len(row) > 7 else ""
preview_text = preview_text.replace(" ", "\n")
sheet_item = {
"timestamp": timestamp,
"orderType": order_type,
"deposit_amount_str": deposit_amt,
"items_str": items_str,
"previewText": preview_text,
"custName": cust_name,
"custPhone": cust_phone,
"custAddress": cust_address,
"customer_name": cust_name,
"phone": cust_phone,
"address": cust_address
}
history.append(merge_history_item(sheet_item, local_history.get(timestamp)))
return history
except Exception as e:
print(f"구글 시트에서 기록을 읽어오는 중 에러: {e}")
@@ -710,15 +735,22 @@ async def add_history(data: dict):
# 행 높이가 길어지지 않도록 줄바꿈을 띄어쓰기로 변경
preview_text = data.get("previewText", "").replace("\n", " ").replace("\r", "")
customer_name = first_nonempty(data, "custName", "customer_name", "customerName", "name")
customer_phone = first_nonempty(data, "custPhone", "phone", "customer_phone", "customerPhone")
customer_address = first_nonempty(data, "custAddress", "address", "customer_address", "customerAddress")
row = [
data.get("timestamp", ""),
data.get("orderType", ""),
data.get("deposit_amount_str", ""),
items_str,
preview_text
preview_text,
customer_name,
customer_phone,
customer_address
]
ws.append_row(row, value_input_option='USER_ENTERED')
next_row = len(ws.col_values(1)) + 1
ws.update(values=[row], range_name=f"A{next_row}:H{next_row}", value_input_option='USER_ENTERED')
except Exception as e:
print(f"구글 시트 문자내역 기록 실패: {e}")