def userBuyTicket(username, card, departure, destination, date, BusId): # assert type(BusId) == int BT = BusTable() PT = PurchaseTable() num = 0 _list = PT.searchRecord({ 'username': username, 'card': card, 'departure': departure, 'destination': destination, 'date': date, 'BusId': BusId }) # print(_list) for i in _list: num += 1 if num != 0: print("db do not has the ticket {}".format(BusId)) return False f, price = BT.buy(departure, destination, date, BusId) if f: PT.insertRecord(username, card, departure, destination, date, BusId, price) return True else: print('{} buy error'.format(username)) return False
def userBuyTicket(username, card, departure, destination, date, BusId): BT = BusTable() PT = PurchaseTable() num = 0 _list = PT.searchRecord({ 'card': card, 'departure': departure, 'destination': destination, 'date': date, 'BusId': BusId }) for i in _list: num = num + 1 if num != 0: return 0 f, price = BT.buy(departure, destination, date, BusId) if f: PT.insertRecord(username, card, departure, destination, date, BusId, price) return 2 else: return 1