DeepLearning101 commited on
Commit
eb21330
·
verified ·
1 Parent(s): b9803e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -85,13 +85,44 @@ def send_confirmation_hybrid(booking_id):
85
  email = booking.get('email')
86
  user_id = booking.get('user_id')
87
  current_status = booking.get('status', '')
 
88
 
89
  confirm_link = f"{PUBLIC_SPACE_URL}?id={booking_id}&action=confirm"
90
  cancel_link = f"{PUBLIC_SPACE_URL}?id={booking_id}&action=cancel"
91
  log_msg = f"🆔 {booking_id} 處理結果: "
 
92
  is_reminder = "確認" in current_status
93
-
94
- if is_reminder:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  # --- 🔔 提醒模式 ---
96
  mail_subject = f"🔔 行前提醒: {booking['date']} - Cié Cié Taipei"
97
  line_text = (f"🔔 行前提醒\n\n{booking['name']} 您好,期待今晚與您相見!\n\n"
@@ -131,7 +162,7 @@ def send_confirmation_hybrid(booking_id):
131
  except: log_msg += f"❌ LINE錯誤 "
132
  else: log_msg += "⚠️ 無LINE ID "
133
 
134
- if not is_reminder:
135
  supabase.table("bookings").update({"status": "已發確認信"}).eq("id", booking_id).execute()
136
  return log_msg
137
  except Exception as e: return f"嚴重錯誤: {str(e)}"
@@ -418,7 +449,7 @@ with gr.Blocks(title="Cié Cié Admin", css=custom_css, theme=gr.themes.Monochro
418
  update_status_btn = gr.Button("💾 變更狀態", variant="secondary", scale=1)
419
  check_lp_btn = gr.Button("🔍 查 LINE Pay", variant="secondary", scale=1)
420
  noshow_btn = gr.Button("🚫 標記 No-Show", variant="stop", scale=1)
421
- revert_noshow_btn = gr.Button("✅ 撤銷 No-Show", scale=1) # 👈 補回這個遺失的按鈕!
422
  refresh_btn = gr.Button("🔄 刷新列表", scale=1)
423
 
424
  log_output = gr.Textbox(label="執行結果日誌", lines=1)
@@ -523,5 +554,4 @@ with gr.Blocks(title="Cié Cié Admin", css=custom_css, theme=gr.themes.Monochro
523
  )
524
 
525
  if __name__ == "__main__":
526
- # 將 css 與 theme 設定保留在此以確保相容性,Gradio 的 UserWarning 不會影響系統執行
527
  demo.launch()
 
85
  email = booking.get('email')
86
  user_id = booking.get('user_id')
87
  current_status = booking.get('status', '')
88
+ remarks = booking.get('remarks', '')
89
 
90
  confirm_link = f"{PUBLIC_SPACE_URL}?id={booking_id}&action=confirm"
91
  cancel_link = f"{PUBLIC_SPACE_URL}?id={booking_id}&action=cancel"
92
  log_msg = f"🆔 {booking_id} 處理結果: "
93
+
94
  is_reminder = "確認" in current_status
95
+ is_pending_payment = "待付款" in current_status
96
+
97
+ # 🌟 處理補付款/催繳情境 🌟
98
+ if is_pending_payment:
99
+ # 從備註中萃取原本的訂單號
100
+ order_id = None
101
+ for line in remarks.split('\n'):
102
+ if "訂單號:" in line:
103
+ order_id = line.split(":")[-1].strip()
104
+
105
+ payment_link = ""
106
+ if order_id:
107
+ # 這裡是一個簡化的重製付款連結邏輯
108
+ # 實際應用中,您可以呼叫 FastAPI 的一個專屬端點來重新產生有效的 LINE Pay 連結
109
+ # 為了演示,我們假設這個連結可以直接導向您前台的特定補付款頁面
110
+ payment_link = f"{PUBLIC_SPACE_URL}?action=repay&order_id={order_id}"
111
+
112
+ mail_subject = f"💳 提醒付款: {booking['date']} 訂單 - Cié Cié Taipei"
113
+ line_text = (f"💳 付款提醒\n\n{booking['name']} 您好,您有一筆訂單尚未完成付款。\n\n"
114
+ f"📅 日期:{booking['date']}\n⏰ 時間:{booking['time']}\n\n"
115
+ f"👉 請點擊下方連結完成線上結帳:\n{payment_link}\n\n"
116
+ f"如已付款請忽略此訊息。")
117
+ mail_html = f"""<div style="background:#1a1a1a; color:#d4af37; padding:20px; border-radius:8px; font-family:sans-serif;">
118
+ <h2 style="text-align:center; border-bottom:1px solid #444; padding-bottom:15px;">Cié Cié Taipei</h2>
119
+ <p style="color:#eee; font-size:16px;"><strong>{booking['name']}</strong> 您好,您的訂單尚未完成付款:</p>
120
+ <ul style="color:#ddd; line-height:1.8;"><li>📅 日期:{booking['date']}</li><li>⏰ 時間:{booking['time']}</li></ul>
121
+ <div style="text-align:center; margin-top:30px;">
122
+ <a href="{payment_link}" style="display:inline-block; background:#3498db; color:#fff; padding:12px 30px; text-decoration:none; border-radius:50px; font-weight:bold;">💳 前往完成付款</a>
123
+ </div></div>"""
124
+
125
+ elif is_reminder:
126
  # --- 🔔 提醒模式 ---
127
  mail_subject = f"🔔 行前提醒: {booking['date']} - Cié Cié Taipei"
128
  line_text = (f"🔔 行前提醒\n\n{booking['name']} 您好,期待今晚與您相見!\n\n"
 
162
  except: log_msg += f"❌ LINE錯誤 "
163
  else: log_msg += "⚠️ 無LINE ID "
164
 
165
+ if not is_reminder and not is_pending_payment:
166
  supabase.table("bookings").update({"status": "已發確認信"}).eq("id", booking_id).execute()
167
  return log_msg
168
  except Exception as e: return f"嚴重錯誤: {str(e)}"
 
449
  update_status_btn = gr.Button("💾 變更狀態", variant="secondary", scale=1)
450
  check_lp_btn = gr.Button("🔍 查 LINE Pay", variant="secondary", scale=1)
451
  noshow_btn = gr.Button("🚫 標記 No-Show", variant="stop", scale=1)
452
+ revert_noshow_btn = gr.Button("✅ 撤銷 No-Show", scale=1)
453
  refresh_btn = gr.Button("🔄 刷新列表", scale=1)
454
 
455
  log_output = gr.Textbox(label="執行結果日誌", lines=1)
 
554
  )
555
 
556
  if __name__ == "__main__":
 
557
  demo.launch()