def handle_imgmessage(event): print(event) filepath = './test.jpg' UserId = event.source.user_id #ert = event.reply_token firebase_rec = {} doc_ref = firedb.collection('內用購物車').document(UserId) doc = doc_ref.get() message_content = line_bot_api.get_message_content(event.message.id) with open(filepath, 'wb') as fd: for chunk in message_content.iter_content(): fd.write(chunk) try: m1 = cv2.imread(filepath, 1) r = pyzbar.decode(m1) msg = "" for i, d in enumerate(r): msg = d.data.decode("UTF-8") print("第", i + 1, "個條碼, 類型:", d.type, ", 內容:", d.data.decode("UTF-8")) if bool(re.match('akanar', msg)): # 金鑰認證 table = msg.split(' ')[1] firebase_rec['桌號'] = table if doc.to_dict() == None: # 無過往紀錄 doc_ref.set(firebase_rec) else: doc_ref.update(firebase_rec) # update 桌號 doc_ref = firedb.collection('是否訂位').document(UserId) firebase_rec = {} firebase_rec['status'] = 'oin' firebase_rec['step'] = '1' doc_ref.update(firebase_rec) # update 狀態 Menu_Message = AllMessage.Menu_Message() line_bot_api.push_message(UserId, Menu_Message) else: line_bot_api.push_message( UserId, TextSendMessage(text='QRcode的內容為: ' + msg)) except: line_bot_api.push_message( UserId, TextSendMessage(text='圖片不是QRcode,請上傳QRcode圖片')) return 0
def handle_postback(event): UserId = event.source.user_id ert = event.reply_token firebase_rec = {} profile = line_bot_api.get_profile(UserId) doc_ref = firedb.collection('是否訂位').document(UserId) doc = doc_ref.get() print(event.postback) ''' 訂位功能step6 - 同意訂位 ''' if 'yes' in event.postback.data: InOrder = 1 # 取得順位 dict_doc = doc.to_dict() doc_ref = firedb.collection_group('訂位紀錄') docs = doc_ref.stream() # generator # 1個ID(collection)算一次迴圈 for doc in docs: for d in doc.to_dict(): # for each in dict try:# 如果他訂的時間一小時內沒有人的話就第一順位, 有的話就後延 selected_time = datetime.strptime(dict_doc['selected_time'], '%Y-%m-%dT%H:%M') selected_time_plus = datetime.strptime(dict_doc['selected_time'], '%Y-%m-%dT%H:%M') + timedelta(hours = 1) other_selected_time = datetime.strptime(doc.to_dict()[d][1], '%Y-%m-%dT%H:%M') if selected_time <= other_selected_time and selected_time_plus >= other_selected_time: InOrder += 1 else: pass except: pass oreferencenumber = datetime.now().strftime("%Y%m%d%H%M%S") # 訂位編號 data = event.postback.data.split(' ') # [1]: OrderName, [2]:Selected Time, [3]:number of man, [4]: Selected Seat, [5]:UserId doc_ref = firedb.collection('是否訂位').document(data[5]) doc = doc_ref.get() firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' firebase_rec['InOrder'] = str(InOrder) firebase_rec['orfn'] = oreferencenumber doc_ref.update(firebase_rec) # 接收並更新db的time rec = data[1:5] # rec[0]: OrderName, rec[1]:Selected Time, rec[2]:number of man, rec[3]:Selected Seatm, rec[4]:UserId ord_ref = firedb.collection('訂位紀錄').document(data[5]) order_rec = {} if ord_ref.get().to_dict() == None: # 無過往紀錄 order_rec['record_1'] = rec ord_ref.set(order_rec) else: checkrec = 'record_'+str(len(ord_ref.get().to_dict())) lenrec = 'record_'+str(len(ord_ref.get().to_dict())+1) # 如果跟前一筆一樣的話 代表重複同意 try: if ord_ref.get().to_dict()[checkrec][0] in rec[0] and ord_ref.get().to_dict()[checkrec][2] in rec[2] and ord_ref.get().to_dict()[checkrec][1] in rec[1] and ord_ref.get().to_dict()[checkrec][3] in rec[3]: line_bot_api.push_message(UserId, TextSendMessage(text='已有其他管理員同意訂位, 本次同意不列入紀錄!')) return 0 else: rec.append(str(InOrder)) rec.append(oreferencenumber) # 訂單編號 order_rec[lenrec] = rec ord_ref.update(order_rec) except: rec.append(str(InOrder)) rec.append(oreferencenumber) # 訂單編號 order_rec[lenrec] = rec ord_ref.update(order_rec) doc = doc_ref.get() dict_doc = doc.to_dict() OrderMessage = AllMessage.Order_Message(dict_doc) # 回傳給Customer端成功訊息 line_bot_api_client.push_message(data[5], OrderMessage) reply_message = '姓名: ' + data[1] + "\n訂單編號: " + oreferencenumber +'\n預約日期: ' + data[2].split('T')[0] + '\n預約時間: ' + data[2].split('T')[1] + '\n預約人數: ' + data[3] + '\n預約順位: ' + str(InOrder) + '\n預約座位: ' + data[4] doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api.push_message(doc.to_dict()['User_Id'] , TextSendMessage( text='管理員 {0} 已同意客人訂位!\n訂單詳細內容如下:\n{2}'.format(profile.display_name, reply_message)) ) #text='管理員 {0} 已同意客人訂位!\n訂單詳細內容如下:\n{1}'.format(profile.display_name, reply_message)) ) return 0 ''' 訂位功能step6 - 拒絕訂位 ''' if 'no' in event.postback.data: firebase_rec['step'] = '4' doc_ref.update(firebase_rec) # 接收並更新db的time data = event.postback.data.split(' ') # [1]: OrderName, [2]:Selected Time, [3]:number of man, [4]:UserId reply_message = '姓名: ' + data[1] + '\n時間: ' + data[2].replace('T',' ') + '\n人數: ' + data[3] line_bot_api_client.push_message(data[4], TextSendMessage(text='店家拒絕此次訂位!\n麻煩請於上方選時間處選其它時刻,感謝您~')) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api.push_message(doc.to_dict()['User_Id'] , TextSendMessage( text='管理員 {0} 已拒絕客人訂位!\n訂單詳細內容如下:\n{1}'.format(profile.display_name, reply_message)) ) return 0 ''' Manager取消功能step2 ''' if event.postback.data == 'selected time': SelectTime = event.postback.params['date'] # 根據時間搜尋database # ex.2020-01-16 ManagerCancelMessage = AllMessage.Manager_Cancel_Message(SelectTime) line_bot_api.push_message(UserId, ManagerCancelMessage) return 0 ''' Manager取消功能step3 ''' if "cancel" in event.postback.data: data = event.postback.data.split(' ') # 1:Customer Name, 2:Customer SelectTime, 3: num of customer doc_ref = firedb.collection_group('訂位紀錄') docs = doc_ref.stream() # generator # 1個ID(collection)算一次迴圈 for doc in docs: for d in doc.to_dict(): # for each in dict try: if (datetime.strptime(doc.to_dict()[d][1], '%Y-%m-%dT%H:%M') == datetime.strptime(data[2], '%Y-%m-%dT%H:%M')) and doc.to_dict()[d][0] in data[1] and doc.to_dict()[d][2] in data[3]: # 跟選取的為同一天 doc_ref = firedb.collection('訂位紀錄').document(doc.id) cancel_rec = {} cancel_rec[d] = None doc_ref.update(cancel_rec) # 用None取代 except: pass reply_message = "姓名: " + data[1] + "\n訂位時間: " + data[2].replace('T',' ')+ "\n人數: " + data[3] + "\n桌號: " + data[4] line_bot_api_client.push_message(data[5], TextSendMessage(text='店家已取消您的訂位!\n訂單詳細內容如下:\n{0}'.format(reply_message))) # Client profile = line_bot_api.get_profile(UserId) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api.push_message(doc.to_dict()['User_Id'] , TextSendMessage( text='管理員 {0} 已取消客人訂位!\n訂單詳細內容如下:\n{1}'.format(profile.display_name, reply_message)) ) return 0 else: line_bot_api.reply_message(ert, TextSendMessage(text='無效操作') ) return 0
def handle_message(event): UserId = event.source.user_id UserMessage = event.message.text ert = event.reply_token firebase_rec = {} if '目前訂位' in UserMessage:# in c: doc_ref = firedb.collection_group('訂位紀錄') docs = doc_ref.stream() # generator reply_message = '目前有以下訂位: ' for doc in docs: dic = doc.to_dict() for record in dic: try: if datetime.strptime(dic[record][1], '%Y-%m-%dT%H:%M') > datetime.now(): reply_message += '\n\n姓名: ' + dic[record][0] + '\n預約時間: ' + dic[record][1].replace('T',' ') + "\n人數: " + dic[record][2] else: pass except: # NoneType pass #print(u'{} => {}'.format(doc.id, doc.to_dict())) line_bot_api.reply_message(ert, TextSendMessage(text=reply_message) ) return 0 ''' 發送公告step1 ''' if '發送公告' in UserMessage: firebase_rec['step'] = 'b1' doc_ref = firedb.collection('發送公告').document(UserId) doc_ref.set(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text="注意!!!\n下一句傳輸之訊息將會公告給所有客人,請確保訊息無誤再傳輸!") ) return 0 ''' 發送公告step2 ''' doc_ref = firedb.collection('發送公告').document(UserId) doc = doc_ref.get() if doc.to_dict()['step'] == 'b1' and '目前訂位' not in UserMessage and '取消訂位' not in UserMessage and '發送公告' not in UserMessage: firebase_rec['step'] = 'b2' doc_ref = firedb.collection('發送公告').document(UserId) doc_ref.update(firebase_rec) # update 狀態 doc_ref = firedb.collection_group('客戶端') # 收集客戶端全部的 User Id docs = doc_ref.stream() # generator for doc in docs: dic = doc.to_dict() line_bot_api_client.push_message(dic['User_Id'], TextSendMessage(text=UserMessage) ) # 客戶端的LineBot會傳公告訊息給客戶 profile = line_bot_api.get_profile(UserId) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api.push_message(doc.to_dict()['User_Id'] , TextSendMessage( text='管理員 {0} 已發送公告!\n公告內容如下:\n{1}'.format(profile.display_name, UserMessage)) ) return 0 elif doc.to_dict()['step'] == 'b1': firebase_rec['step'] = 'b2' doc_ref = firedb.collection('發送公告').document(UserId) doc_ref.update(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text='取消公告')) if '目前訂位' in UserMessage: doc_ref = firedb.collection_group('訂位紀錄') docs = doc_ref.stream() # generator reply_message = '目前有以下訂位: ' for doc in docs: dic = doc.to_dict() for record in dic: try: if datetime.strptime(dic[record][1], '%Y-%m-%dT%H:%M') > datetime.now(): reply_message += '\n\n姓名: ' + dic[record][0] + '\n預約時間: ' + dic[record][1].replace('T',' ') + "\n人數: " + dic[record][2] else: pass except: # NoneType pass line_bot_api.reply_message(ert, TextSendMessage(text=reply_message) ) return 0 elif '取消訂位' in UserMessage: TimeMessage = AllMessage.Time_Message() line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message return 0 elif '發送公告' in UserMessage: firebase_rec['step'] = 'b1' doc_ref = firedb.collection('發送公告').document(UserId) doc_ref.set(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text="注意!!!\n下一句傳輸之訊息將會公告給所有客人,請確保訊息無誤再傳輸!") ) return 0 return 0 ''' Manager取消客戶訂位step1 ''' if '取消訂位' in UserMessage: TimeMessage = AllMessage.Time_Message() line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message return 0 ''' 清空過往訂單(暫時沒有開放) ''' if '清空' in UserMessage: doc_ref = firedb.collection_group('訂位紀錄') docs = doc_ref.stream() # generator # 1個ID(collection)算一次迴圈 for doc in docs: for d in doc.to_dict(): # for each in dict try: if (datetime.strptime(doc.to_dict()[d][1].split("T")[0], '%Y-%m-%d') < datetime.today()): doc_ref = firedb.collection('訂位紀錄').document(doc.id) cancel_rec = {} cancel_rec[d] = None doc_ref.update(cancel_rec) # 用None取代 except: pass else: line_bot_api.reply_message(ert, TextSendMessage(text='無效操作') ) return 0
def handle_postback(event): UserId = event.source.user_id ert = event.reply_token firebase_rec = {} data = event.postback.data doc_ref = firedb.collection('是否訂位').document(UserId) doc = doc_ref.get() print(event.postback) ''' 訂位功能step3 ''' if doc.to_dict()['status'] == 'order' and doc.to_dict()['step'] == '2': firebase_rec['step'] = '3' firebase_rec['Name'] = doc.to_dict()['Name'] + event.postback.data doc_ref.update(firebase_rec) TimeMessage = AllMessage.Time_Message(number=1) line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message return 0 ''' 訂位功能step3.5 ''' if event.postback.data == 'selected time' and doc.to_dict( )['status'] == 'order' and doc.to_dict()['step'] == '3': # 傳送選擇時間的Message, if 正確下一個step, 錯誤叫他重新點 hour = int(event.postback.params['datetime'][-5:-3]) minute = int(event.postback.params['datetime'][-2:]) Select_time = hour * 3600 + minute * 60 if 49800 >= Select_time >= 41400 or 71400 >= Select_time >= 61200: firebase_rec['step'] = '3.5' doc_ref.update(firebase_rec) ConfirmPostMessage = AllMessage.Confirm_PostMessage( event.postback.params['datetime'], number=5) line_bot_api.reply_message(ert, ConfirmPostMessage) else: line_bot_api.reply_message(ert, TextSendMessage(text='麻煩請選擇其他時間')) return 0 ''' 訂位功能step4 ''' if doc.to_dict()['status'] == 'order' and doc.to_dict()['step'] == '3.5': if 'yes' in event.postback.data: data = event.postback.data.split(' ') firebase_rec['step'] = '4' firebase_rec['selected_time'] = data[1] doc_ref.update(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text='請問共有幾位貴賓?')) else: firebase_rec['step'] = '3' doc_ref.update(firebase_rec) TimeMessage = AllMessage.Time_Message(number=1) line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message return 0 ''' 取消訂位step2 ''' if doc.to_dict()['step'] == 'C1' and doc.to_dict()['status'] == 'cancel': firebase_rec['step'] = 'C2' doc_ref.update(firebase_rec) ConfirmMessage = AllMessage.Confirm_PostMessage(data, number=1) line_bot_api.reply_message(ert, ConfirmMessage) return 0 ''' 取消訂位step3 ''' if doc.to_dict()['step'] == 'C2' and doc.to_dict()['status'] == 'cancel': if data == 'no': firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref.update(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text='感謝您不取消訂位~')) return 0 doc_ref = firedb.collection('訂位紀錄').document(UserId) doc = doc_ref.get() reply_message = '[取消訂位]\n詳細資訊如下:\n姓名: ' + doc.to_dict( )[data][0] + '\n預約日期: ' + doc.to_dict()[data][1].split( 'T')[0] + '\n預約時間: ' + doc.to_dict()[data][1].split( 'T')[1] + '\n預約人數: ' + doc.to_dict( )[data][2] + '\n訂單編號: ' + doc.to_dict()[data][4] cancel_rec = {} cancel_rec[data] = None doc_ref.update(cancel_rec) # 用None 取代 firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref = firedb.collection('是否訂位').document(UserId) doc_ref.update(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text=reply_message)) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api_server.push_message( doc.to_dict()['User_Id'], TextSendMessage(text='[客人取消訂位]\n詳細資訊如下:\n' + reply_message[10:])) # 通知Manager端 取消訂位 return 0 ''' 新增餐點 ''' if bool(re.match('加', event.postback.data)): data = event.postback.data.split(' ') # list if doc.to_dict()['status'] == 'oout': doc_ref = firedb.collection('外帶購物車').document(UserId) else: doc_ref = firedb.collection('內用購物車').document(UserId) doc = doc_ref.get() if doc.to_dict() == None: # 無過往紀錄 firebase_rec[data[1]] = 1 doc_ref.set(firebase_rec) else: if data[1] in doc.to_dict(): firebase_rec[data[1]] = doc.to_dict()[data[1]] + 1 doc_ref.update(firebase_rec) else: firebase_rec[data[1]] = 1 doc_ref.update(firebase_rec) return 0 ''' 刪除餐點 ''' if bool(re.match('減', event.postback.data)): data = event.postback.data.split(' ') if doc.to_dict()['status'] == 'oout': doc_ref = firedb.collection('外帶購物車').document(UserId) else: doc_ref = firedb.collection('內用購物車').document(UserId) doc = doc_ref.get() if doc.to_dict() == None: # 無過往紀錄 pass else: if data[1] in doc.to_dict(): if doc.to_dict()[data[1]] == 0: pass else: firebase_rec[data[1]] = doc.to_dict()[data[1]] - 1 if firebase_rec[data[1]] == 0: firebase_rec[data[1]] = None doc_ref.update(firebase_rec) else: pass return 0 ''' 當日外帶 step3 ''' if doc.to_dict()['status'] == 'oout' and doc.to_dict()['step'] == '3': # 傳送選擇時間的Message, if 正確下一個step, 錯誤叫他重新點 hour = int(event.postback.params['datetime'][-5:-3]) minute = int(event.postback.params['datetime'][-2:]) Select_time = hour * 3600 + minute * 60 if 49800 >= Select_time >= 41400 or 71400 >= Select_time >= 61200: firebase_rec['step'] = '3.5' doc_ref.update(firebase_rec) ConfirmPostMessage = AllMessage.Confirm_PostMessage( event.postback.params['datetime'], number=5) line_bot_api.reply_message(ert, ConfirmPostMessage) else: line_bot_api.reply_message(ert, TextSendMessage(text='麻煩請選擇其他時間')) return 0 ''' 當日外帶 step4 ''' if doc.to_dict()['status'] == 'oout' and doc.to_dict()['step'] == '3.5': if bool(re.match('yes', event.postback.data)): data = event.postback.data.split(' ') firebase_rec['selected_time'] = data[1] firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref.update(firebase_rec) doc_ref = firedb.collection('外帶購物車').document(UserId) dict_doc = doc_ref.get().to_dict() profile = line_bot_api.get_profile(UserId) reply_message = "顧客 " + profile.display_name + " 的外帶詳細如下:" + "\n外帶時間: " + data[ 1] for key, value in dict_doc.items(): reply_message += "\n" + key + ":" + str(value) + "份" firebase_rec = None doc_ref.set(firebase_rec) line_bot_api.reply_message(ert, TextSendMessage(text=reply_message)) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api_server.push_message( doc.to_dict()['User_Id'], TextSendMessage( text=reply_message)) # 通知Manager端, 讓其確認是否同意 else: firebase_rec['step'] = '3' doc_ref.update(firebase_rec) TimeMessage = AllMessage.Time_Message(number=1) line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message return 0 if bool(re.match('confirm', event.postback.data)): firebase_rec['step'] = '2' doc_ref.update(firebase_rec) if doc.to_dict()['status'] == 'oout': doc_ref = firedb.collection('外帶購物車').document(UserId) else: doc_ref = firedb.collection('內用購物車').document(UserId) doc = doc_ref.get() dict_doc = doc.to_dict() #{'東坡肉': 1, '芒果炒雞柳': 3} ConfirmPostMessage = AllMessage.Confirm_PostMessage(dict_doc, 6) line_bot_api.push_message(UserId, ConfirmPostMessage) return 0 ''' 確認餐點 step2''' if bool(re.match('menu', event.postback.data)) and doc.to_dict()['step'] == '2': if bool(re.match('yes', event.postback.data)): if doc.to_dict()['status'] == 'oin': firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref.update(firebase_rec) doc_ref = firedb.collection('內用購物車').document(UserId) line_bot_api.push_message( UserId, TextSendMessage(text='好的! 已幫您告知告知店家,請於用餐完畢後結帳,感謝您!')) data = event.postback.data.split(' ')[2:] profile = line_bot_api.get_profile(UserId) reply_message = "顧客 " + profile.display_name + " 的店內點餐餐點詳細如下:" for d in range(0, len(data) - 1, 2): reply_message = reply_message + '\n' + data[ d] + ' ' + data[d + 1] + "份" firebase_rec = None doc_ref.set(firebase_rec) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api_server.push_message( doc.to_dict()['User_Id'], TextSendMessage( text=reply_message)) # 通知Manager端, 讓其確認 else: firebase_rec['step'] = '3' doc_ref.update(firebase_rec) TimeMessage = AllMessage.Time_Message(number=1) line_bot_api.reply_message(ert, TimeMessage) # 傳送選擇日期的Message else: Menu_Message = AllMessage.Menu_Message() line_bot_api.push_message(UserId, Menu_Message) return 0 else: line_bot_api.reply_message(ert, TextSendMessage(text='麻煩請重新操作!!')) return 0
def handle_message(event): #print(event) UserId = event.source.user_id UserMessage = event.message.text ert = event.reply_token firebase_rec = {} doc_ref = firedb.collection('是否訂位').document(UserId) doc = doc_ref.get() ''' 訂位管理 ''' if bool(re.match('訂位管理', UserMessage)): ConfirmPostMessage = AllMessage.Confirm_PostMessage(UserMessage, number=4) line_bot_api.push_message(UserId, ConfirmPostMessage) return 0 ''' 訂位功能step1 ''' if doc.to_dict() == None: # 無過往紀錄 UseSeveralTimesMessage = AllMessage.Use_Several_Times_Message( number=2, UserId=UserId, UserMessage=UserMessage) line_bot_api.reply_message(ert, UseSeveralTimesMessage) # 接續step3 return 0 elif '預約訂位' in UserMessage and doc.to_dict( )['status'] == 'free': # 如果有關鍵字以及status為order UseSeveralTimesMessage = AllMessage.Use_Several_Times_Message( number=3, UserId=UserId, UserMessage=UserMessage) line_bot_api.reply_message(ert, UseSeveralTimesMessage) # 接續step3 return 0 ''' 訂位功能step2 ''' if doc.to_dict()['status'] == 'order' and doc.to_dict( )['step'] == '1' and '訂位管理' not in UserMessage and '店內點餐' not in UserMessage and '預約訂位' not in UserMessage: firebase_rec['Name'] = UserMessage[0] # 取第一個字 firebase_rec['step'] = '2' doc_ref = firedb.collection('是否訂位').document(UserId) doc_ref.update(firebase_rec) ConfirmPostMessage = AllMessage.Confirm_PostMessage(UserMessage, number=3) line_bot_api.reply_message(ert, ConfirmPostMessage) # 傳送先生小姐按鈕 return 0 # 如果中途按下其他按鈕,取消訂位並狀態清空 elif doc.to_dict()['status'] == 'order' and doc.to_dict()['step'] == '1': firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref = firedb.collection('是否訂位').document(UserId) doc_ref.update(firebase_rec) if bool(re.match('訂位管理', UserMessage)): line_bot_api.reply_message(ert, TextSendMessage(text='取消訂位')) UseSeveralTimesMessage = AllMessage.Use_Several_Times_Message( number=1, UserId=UserId, UserMessage=UserMessage) line_bot_api.push_message( UserId, TextSendMessage(text=UseSeveralTimesMessage)) return 0 elif bool(re.match('店內點餐', UserMessage)): line_bot_api.reply_message(ert, [ TextSendMessage(text='取消訂位'), TextSendMessage(text='麻煩拍照或上傳桌面上QRcode照片') ]) return 0 elif bool(re.match('預約訂位', UserMessage)): doc_ref = firedb.collection('是否訂位').document(UserId) doc = doc_ref.get() if doc.to_dict() == None: # 無過往紀錄 UseSeveralTimesMessage = AllMessage.Use_Several_Times_Message( number=2, UserId=UserId, UserMessage=UserMessage) line_bot_api.push_message(UserId, UseSeveralTimesMessage) # 接續step3 return 0 elif bool(re.match('訂位', UserMessage)) and doc.to_dict( )['status'] == 'free': # 如果有關鍵字以及status為order UseSeveralTimesMessage = AllMessage.Use_Several_Times_Message( number=3, UserId=UserId, UserMessage=UserMessage) line_bot_api.push_message(UserId, UseSeveralTimesMessage) # 接續step3 return 0 ''' 訂位功能step5 傳送確認訊息 ''' if doc.to_dict()['status'] == 'order' and doc.to_dict( )['step'] == '4' and '訂位管理' not in UserMessage and '店內點餐' not in UserMessage: firebase_rec['Num_People'] = UserMessage firebase_rec['step'] = '5' doc_ref.update(firebase_rec) # 更新db的點餐狀態 rec = [] rec.append(doc.to_dict()['Name']) rec.append(doc.to_dict()['selected_time']) rec.append(UserMessage) rec.append(UserId) line_bot_api.push_message(UserId, TextSendMessage(text='等候回覆中')) ConfirmPostMessage = AllMessage.Confirm_PostMessage(rec, number=2) doc_ref = firedb.collection_group('控制端') docs = doc_ref.stream() # generator for doc in docs: line_bot_api_server.push_message( doc.to_dict()['User_Id'], ConfirmPostMessage) # 通知Manager端, 讓其確認是否同意 return 0 ''' 取消訂位step1 ''' if bool(re.match('取消預約', UserMessage)): stickermessage = AllMessage.Sticker_Message(1) CancelMessage = AllMessage.Cancel_Message(UserId) line_bot_api.push_message(UserId, [stickermessage, CancelMessage]) return 0 ''' 店內點餐 ''' if bool(re.match('店內點餐', UserMessage)): line_bot_api.push_message(UserId, TextSendMessage(text='麻煩拍照或上傳桌面上QRcode照片')) return 0 ''' 當日外帶 ''' if bool(re.match('當日外帶', UserMessage)): firebase_rec['status'] = 'oout' firebase_rec['step'] = '1' doc_ref.update(firebase_rec) Menu_Message = AllMessage.Menu_Message() line_bot_api.reply_message(ert, Menu_Message) return 0 ''' 等待商家回覆 ''' if doc.to_dict()['step'] == '5': if bool(re.match('訂位管理', UserMessage)): firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref.update(firebase_rec) ConfirmPostMessage = AllMessage.Confirm_PostMessage(UserMessage, number=4) line_bot_api.push_message(UserId, ConfirmPostMessage) return 0 elif bool(re.match('店內點餐', UserMessage)): line_bot_api.push_message( UserId, TextSendMessage(text='麻煩拍照或上傳桌面上QRcode照片')) return 0 elif bool(re.match('當日外帶', UserMessage)): Menu_Message = AllMessage.Menu_Message() line_bot_api.push_message(UserId, Menu_Message) return 0 else: line_bot_api.reply_message( ert, TextSendMessage(text='正在等待店家同意訂位中,請稍後~')) return 0 else: # 非選單上的功能及不知所云的話會到這 firebase_rec['step'] = 'F' firebase_rec['status'] = 'free' doc_ref.update(firebase_rec) line_bot_api.push_message(UserId, TextSendMessage(text='麻煩重新操作,感謝您!')) return 0