DeepLearning101 commited on
Commit
ef50b1a
·
verified ·
1 Parent(s): d8955c7

客人點擊確認或取消後都會通知店家老闆

Browse files

新訂位通知 (Space A -> 老闆):50 則
發送確認信 (Space B -> 客人):50 則
客人點擊確認通知 (Space A -> 老闆):50 則
行前提醒 (Space B -> 客人):50 則

Files changed (1) hide show
  1. app.py +42 -6
app.py CHANGED
@@ -149,7 +149,7 @@ def handle_booking(name, tel, email, date_str, time, pax, remarks, line_id):
149
  return """<div style='text-align: center; color: #fff; padding: 20px; border: 1px solid #d4af37; border-radius: 8px; background: #222;'><h2 style='color: #d4af37; margin: 0;'>Request Received</h2><p style='margin: 10px 0;'>🥂 預約申請已提交</p><p style='font-size: 0.9em; color: #aaa;'>請留意 Email 確認信 或 Line 訊息。</p></div>"""
150
  except Exception as e: return f"❌ 系統錯誤: {str(e)}"
151
 
152
- # --- 5. Webhook (確認/取消 + 回傳轉址 URL) ---
153
  def check_confirmation(request: gr.Request):
154
  if not request: return ""
155
  action = request.query_params.get('action')
@@ -157,19 +157,55 @@ def check_confirmation(request: gr.Request):
157
 
158
  OFFICIAL_SITE = "https://ciecietaipei.github.io/index.html"
159
 
 
 
160
  if action == 'confirm' and bid:
161
  try:
 
162
  supabase.table("bookings").update({"status": "顧客已確認"}).eq("id", bid).execute()
163
- return f"{OFFICIAL_SITE}?status=confirmed"
164
- except: pass
 
 
 
 
 
 
 
 
165
 
166
  elif action == 'cancel' and bid:
167
  try:
 
168
  supabase.table("bookings").update({"status": "顧客已取消"}).eq("id", bid).execute()
169
- return f"{OFFICIAL_SITE}?status=canceled"
170
- except: pass
171
 
172
- return ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  # --- 6. 介面 ---
175
  theme = gr.themes.Soft(primary_hue="amber", neutral_hue="zinc").set(body_background_fill="#0F0F0F", block_background_fill="#1a1a1a", block_border_width="1px", block_border_color="#333", input_background_fill="#262626", input_border_color="#444", body_text_color="#E0E0E0", block_title_text_color="#d4af37", button_primary_background_fill="#d4af37", button_primary_text_color="#000000")
 
149
  return """<div style='text-align: center; color: #fff; padding: 20px; border: 1px solid #d4af37; border-radius: 8px; background: #222;'><h2 style='color: #d4af37; margin: 0;'>Request Received</h2><p style='margin: 10px 0;'>🥂 預約申請已提交</p><p style='font-size: 0.9em; color: #aaa;'>請留意 Email 確認信 或 Line 訊息。</p></div>"""
150
  except Exception as e: return f"❌ 系統錯誤: {str(e)}"
151
 
152
+ # --- 5. Webhook (確認/取消 + 回傳轉址 URL + 🔥通知老闆) ---
153
  def check_confirmation(request: gr.Request):
154
  if not request: return ""
155
  action = request.query_params.get('action')
 
157
 
158
  OFFICIAL_SITE = "https://ciecietaipei.github.io/index.html"
159
 
160
+ notify_msg = "" # 用來存要發給老闆的訊息
161
+
162
  if action == 'confirm' and bid:
163
  try:
164
+ # 更新狀態
165
  supabase.table("bookings").update({"status": "顧客已確認"}).eq("id", bid).execute()
166
+
167
+ # 🔥 抓資料,準備通知
168
+ res = supabase.table("bookings").select("name, date, time, pax").eq("id", bid).execute()
169
+ if res.data:
170
+ b = res.data[0]
171
+ notify_msg = f"🎉 客人已按確認!\n姓名:{b['name']}\n日期:{b['date']}\n時間:{b['time']}\n人數:{b['pax']}人"
172
+
173
+ final_url = f"{OFFICIAL_SITE}?status=confirmed"
174
+ except:
175
+ final_url = f"{OFFICIAL_SITE}"
176
 
177
  elif action == 'cancel' and bid:
178
  try:
179
+ # 更新狀態
180
  supabase.table("bookings").update({"status": "顧客已取消"}).eq("id", bid).execute()
 
 
181
 
182
+ # 🔥 抓資料,準備通知
183
+ res = supabase.table("bookings").select("name, date, time").eq("id", bid).execute()
184
+ if res.data:
185
+ b = res.data[0]
186
+ notify_msg = f"⚠️ 客人已取消...\n姓名:{b['name']}\n日期:{b['date']}\n時間:{b['time']}"
187
+
188
+ final_url = f"{OFFICIAL_SITE}?status=canceled"
189
+ except:
190
+ final_url = f"{OFFICIAL_SITE}"
191
+ else:
192
+ final_url = ""
193
+
194
+ # 🔥🔥🔥 統一發送通知給老闆 (如果 notify_msg 有內容) 🔥🔥🔥
195
+ if notify_msg and LINE_ACCESS_TOKEN and LINE_ADMIN_ID:
196
+ try:
197
+ requests.post(
198
+ "https://api.line.me/v2/bot/message/push",
199
+ headers={"Authorization": f"Bearer {LINE_ACCESS_TOKEN}", "Content-Type": "application/json"},
200
+ json={
201
+ "to": LINE_ADMIN_ID,
202
+ "messages": [{"type": "text", "text": notify_msg}]
203
+ }
204
+ )
205
+ except Exception as e:
206
+ print(f"LINE 通知發送失敗: {e}")
207
+
208
+ return final_url
209
 
210
  # --- 6. 介面 ---
211
  theme = gr.themes.Soft(primary_hue="amber", neutral_hue="zinc").set(body_background_fill="#0F0F0F", block_background_fill="#1a1a1a", block_border_width="1px", block_border_color="#333", input_background_fill="#262626", input_border_color="#444", body_text_color="#E0E0E0", block_title_text_color="#d4af37", button_primary_background_fill="#d4af37", button_primary_text_color="#000000")