示例#1
0
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
示例#2
0
def adminUpdateBus(OBus, NBus):
    BT = BusTable()
    PT = PurchaseTable()
    _list = PT.findRecordForOneBus(OBus['Departure'], OBus['Destination'], OBus['BusDate'], OBus['BusId'])
    if NBus['BusId'] != OBus['BusId']:
        for i in _list:
            PT.updateRecord(i, 'undefined', 'undefined', 'undefined', NBus['BusId'])

    BT.update_bus(OBus, NBus)
示例#3
0
def adminDeleteBus(departure, destination, date, BusId):
    BT = BusTable()
    b = BT.get_one_bus(departure, destination, date, BusId)
    flag = BT.delete_bus(b)
    PT = PurchaseTable()
    _list = PT.findRecordForOneBus(departure, destination, date, BusId)
    for i in _list:
        userAction.userDeleteTicket(i['username'], i['card'], departure, destination, date, BusId)
    return flag
示例#4
0
def updateTicketInfo(username):
    BT = BusTable()
    PT = PurchaseTable()
    ET = ExpireTable()
    _list = PT.searchRecord({'username': username})  #找某个用户的所有购买记录
    for i in _list:
        b = BT.get_one_bus(i['departure'], i['destination'], i['date'],
                           i['BusId'])
        ticketTime = b['BusDate'] + b['dTime']
        currTime = time.strftime('%Y-%m-%d%H:%M', time.localtime(time.time()))
        if currTime > ticketTime:  #过期票,将记录从perchase表移入到expire表
            PT.deleteOneRecord(username, i['card'], i['departure'],
                               i['destination'], i['date'], i['BusId'])
            ET.insertRecord(i)
示例#5
0
def userDeleteTicket(username, card, departure, destination, date, BusId):
    BT = BusTable()
    PT = PurchaseTable()
    DT = DeleteTable()
    condition = {
        'username': username,
        'card': card,
        'departure': departure,
        'destination': destination,
        'date': date,
        'BusId': BusId
    }
    p = PT.searchRecord(condition)
    i = p[0]
    PT.deleteOneRecord(username, card, departure, destination, date, BusId)
    DT.insertRecord(username, card, departure, destination, date, BusId,
                    i['price'])
    BT.addOneSeat(departure, destination, date, BusId)
示例#6
0
def checkDeleteList(username, card=-1):
    DT = DeleteTable()
    BT = BusTable()
    condition = {}
    condition['username'] = username
    if card != -1:
        condition['card'] = card

    _list1 = DT.searchRecord(condition)
    _list2 = []
    total_num = 0
    for i in _list1:
        _list2.append(
            BT.get_one_bus(i['departure'], i['destination'], i['date'],
                           i['BusId']))
        _list2[total_num]['Price'] = i['price']
        total_num = total_num + 1
    return _list2, total_num
示例#7
0
def checkBookList(username, card="-1"):
    PT = PurchaseTable()
    BT = BusTable()
    condition = {}
    condition['username'] = username
    if card != "-1":
        condition['card'] = str(card)

    _list1 = PT.searchRecord(condition)
    _list2 = []
    total_num = 0
    for i in _list1:
        ticket = TicketInterface.TicketInterface(
            BT.get_one_bus(i['departure'], i['destination'], i['date'],
                           i['BusId']), i)
        _list2.append(ticket)
        _list2[total_num]['Price'] = i['price']
        total_num = total_num + 1
    return _list2, total_num
示例#8
0
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
示例#9
0
def userDeleteTicket(username, card, departure, destination, date, BusId):
    BT = BusTable()
    PT = PurchaseTable()
    DT = DeleteTable()
    # <<<<<<< HEAD
    PT.deleteOneRecord(username, card, departure, destination, date, BusId)
    DT.insertRecord(username, card, departure, destination, date, BusId, 4396)
    # =======
    condition = {
        'username': username,
        'card': card,
        'departure': departure,
        'destination': destination,
        'date': date,
        'BusId': BusId
    }
    p = PT.searchRecord(condition)
    i = p[0]
    PT.deleteOneRecord(username, card, departure, destination, date, BusId)
    DT.insertRecord(username, card, departure, destination, date, BusId,
                    i['price'])
    # >>>>>>> 1dfb90fd307e946b179efd04504ebd442b8c498d
    BT.addOneSeat(departure, destination, date, BusId)
示例#10
0
def userSearchBus(departure, destination, date):
    BT = BusTable()
    return BT.find_bus(departure, destination, date)
示例#11
0
from flask import render_template
from Core.BusTable import BusTable
from Core.Bus import Bus
from Core import userAction
from Interface import PassengerInterface
import re
import random

bus_table = BusTable()


def register(username: str, password: str):
    return userAction.userCreateAccount(username, password, 0)


def get_bus(start, end, date="2018-10-07"):
    start_rexExp = re.compile('.*{}.*'.format(start), re.IGNORECASE)
    end_rexExp = re.compile('.*{}.*'.format(end), re.IGNORECASE)
    _list = [i for i in bus_table.find_bus(start_rexExp, end_rexExp, date)]
    pass


def get_buses():
    return bus_table.get_all()


def get_one_bus(Departure, Destination, BusId, BusDate):

    return bus_table.get_one_bus(Departure, Destination, BusDate, BusId)

示例#12
0
def adminInsertBus(Bus):
    BT = BusTable()
    return BT.insert_bus(Bus)
示例#13
0
from Core.BusTable import BusTable
from Core.Bus import Bus
import re
import random
import util

bus_table = BusTable()


def get_bus(start, end, date="2018-10-07"):
    start_rexExp = re.compile('.*{}.*'.format(start), re.IGNORECASE)
    end_rexExp = re.compile('.*{}.*'.format(end), re.IGNORECASE)
    _list = [i for i in bus_table.find_bus(start_rexExp, end_rexExp, date)]
    _list = sorted(_list, key=util.cmp_min_to_sec)
    return _list


def get_buses():
    _list = [i for i in bus_table.get_all()]
    _list = sorted(_list, key=util.cmp_min_to_sec)
    return _list


def get_passenger():
    user_list = [{'姓名': '文毅鸿', '身份证号码': '440582199810342930'}]
    pass


def assert_not_none(argv: list):
    for i in argv:
        assert i is not None
示例#14
0
def adminDeleteBus(departure, destination, date, BusId):
    BT = BusTable()
    b = BT.get_one_bus(departure, destination, date, BusId)
    BT.delete_bus(b)