|
@@ -23,18 +23,60 @@ dbRouter = APIRouter()
|
|
|
|
|
|
|
|
|
@dbRouter.get("/click")
|
|
|
-def add_click_time():
|
|
|
+def add_click_time(click_type :str = None,brand:str = None):
|
|
|
|
|
|
try:
|
|
|
+ if click_type == None :
|
|
|
|
|
|
- response = supabase.table('click_time').select("*").execute()
|
|
|
+ response = supabase.table('click_time').select("*").eq('id', 1).execute()
|
|
|
|
|
|
- click_time = response.data[0]['click_time'] + 1
|
|
|
+ click_time = response.data[0]['click_time'] + 1
|
|
|
|
|
|
- data, count = supabase.table('click_time') \
|
|
|
- .update({'click_time':click_time,'update_time':str(datetime.now())})\
|
|
|
- .eq('id', 1)\
|
|
|
- .execute()
|
|
|
+ data, count = supabase.table('click_time') \
|
|
|
+ .update({'click_time':click_time,'update_time':str(datetime.now())})\
|
|
|
+ .eq('id', 1)\
|
|
|
+ .execute()
|
|
|
+
|
|
|
+ elif click_type == "card" :
|
|
|
+ response = supabase.table('click_time').select("*").eq('id', 2).execute()
|
|
|
+
|
|
|
+ click_time = response.data[0]['click_time'] + 1
|
|
|
+
|
|
|
+ data, count = supabase.table('click_time') \
|
|
|
+ .update({'click_time':click_time,'update_time':str(datetime.now())})\
|
|
|
+ .eq('id', 2)\
|
|
|
+ .execute()
|
|
|
+
|
|
|
+ elif click_type == "card-en" :
|
|
|
+ response = supabase.table('click_time').select("*").eq('name', "國際貴賓卡-en").execute()
|
|
|
+
|
|
|
+ click_time = response.data[0]['click_time'] + 1
|
|
|
+ print(response)
|
|
|
+
|
|
|
+ data, count = supabase.table('click_time') \
|
|
|
+ .update({'click_time':click_time,'update_time':str(datetime.now())})\
|
|
|
+ .eq('id', 3)\
|
|
|
+ .execute()
|
|
|
+
|
|
|
+ elif click_type == "click_url" and brand:
|
|
|
+ response = supabase.table('101_brand').select("*").eq("name",brand).execute()
|
|
|
+
|
|
|
+ click_time = response.data[0][click_type] + 1
|
|
|
+
|
|
|
+ data, count = supabase.table('101_brand') \
|
|
|
+ .update({click_type:click_time})\
|
|
|
+ .eq("name",brand)\
|
|
|
+ .execute()
|
|
|
+
|
|
|
+ elif click_type == "click_address" and brand:
|
|
|
+ response = supabase.table('101_brand').select("*").eq("name",brand).execute()
|
|
|
+
|
|
|
+ click_time = response.data[0][click_type] + 1
|
|
|
+
|
|
|
+ data, count = supabase.table('101_brand') \
|
|
|
+ .update({click_type:click_time})\
|
|
|
+ .eq("name",brand)\
|
|
|
+ .execute()
|
|
|
|
|
|
return {"state":"success","click_time" : click_time}
|
|
|
|
|
@@ -58,7 +100,7 @@ def find_brand(keyword:str = None,language :str = "ch",page_num : int = None,pag
|
|
|
if search_name:
|
|
|
query = query.like('name', f'%{search_name}%')
|
|
|
|
|
|
- result,_ = query.execute()
|
|
|
+ result,_ = query.order("id", desc=True).execute()
|
|
|
count = len(result[1])
|
|
|
|
|
|
if page_num and page_amount :
|
|
@@ -167,6 +209,7 @@ def read_root(type:str,language :str = "ch"):
|
|
|
.eq("floor","館外")\
|
|
|
.eq("language", language)\
|
|
|
.or_(f"tags.ilike.%{keyword1}%,tags.ilike.%{keyword2}%")\
|
|
|
+ .order("id", desc=True)\
|
|
|
.execute()
|
|
|
|
|
|
result = data[1]
|
|
@@ -183,16 +226,38 @@ def read_root(type:str,language :str = "ch"):
|
|
|
return {"data": random_row}
|
|
|
|
|
|
@dbRouter.post("/message_not_in_cache")
|
|
|
-def message_not_in_cache(question :str ,answer :str,client_id : str = "0" ):
|
|
|
+def message_not_in_cache(question :str ,answer :str,data_list :str='[]',client_id : str = "0" ):
|
|
|
|
|
|
try:
|
|
|
data, count = supabase.table('client_message').select('*').eq("question",question).execute()
|
|
|
-
|
|
|
+
|
|
|
if len(data[1]) != 0 :
|
|
|
return {"state": 200 , "message" : "have saved"}
|
|
|
|
|
|
data, count = supabase.table('client_message').insert({"client_id": client_id, "question": question,"answer":answer}).execute()
|
|
|
-
|
|
|
+ return {"state": 200 , "message" : "success"}
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+
|
|
|
+ return {"state": 500 , "message" : str(e)}
|
|
|
+
|
|
|
+from typing import List, Optional
|
|
|
+from pydantic import BaseModel
|
|
|
+
|
|
|
+class MessageSaveRequest(BaseModel):
|
|
|
+ question: str
|
|
|
+ answer: str
|
|
|
+ data_list: str
|
|
|
+
|
|
|
+
|
|
|
+@dbRouter.post("/message_save")
|
|
|
+def message_save(request:MessageSaveRequest):
|
|
|
+ try :
|
|
|
+ data, count = supabase.table("log_record").insert({
|
|
|
+ "question": request.question,
|
|
|
+ "answer": request.answer,
|
|
|
+ "data_list": request.data_list
|
|
|
+ }).execute()
|
|
|
return {"state": 200 , "message" : "success"}
|
|
|
|
|
|
except Exception as e:
|
|
@@ -268,7 +333,7 @@ def insert_table(data: dataform):
|
|
|
email_content = f"問題類別:{response[1][0]['type']}\n標題:{response[1][0]['title']}\n內容:{response[1][0]['content']}\n姓名:{response[1][0]['client_name']}\n性別:{response[1][0]['gender']}\n電子郵件:{response[1][0]['email']}\n聯絡電話:{response[1][0]['phone']}\n"
|
|
|
|
|
|
try:
|
|
|
- send_email("steven@choozmo.com","mia@choozmo.com",str(email_content)) # mallservice@tfc101.com.tw
|
|
|
+ send_email("mallservice@tfc101.com.tw","mia@choozmo.com",str(email_content)) # mallservice@tfc101.com.tw
|
|
|
except Exception as e:
|
|
|
print(str(e))
|
|
|
|
|
@@ -316,8 +381,12 @@ def video_cache(client_message :str ):
|
|
|
|
|
|
result = ask_question(client_message)
|
|
|
|
|
|
+ # result[0]["answer"]
|
|
|
+
|
|
|
if result == None :
|
|
|
return {"state": 500 , "message" : "no data"}
|
|
|
+
|
|
|
+ data, count = supabase.table("log_record").insert({"question":client_message, "answer":result[0]["answer"]}).execute()
|
|
|
|
|
|
return {"state": 200 , "message" : result }
|
|
|
|