Пример #1
0
def buyProductsCompute(username, result):
    user_info = connect.getUserCountInfoBaseUsername(username)
    money = 0
    for k,v in result[user_info[0]].items():
        money += float(v[0]) * v[1]
    print(money)
    if user_info[4] >= money:
        flag = 0
        for k,v in result[user_info[0]].items():
            flag += 1
            productID = k
            productBuyNum = v[0]
            productInfo = connect.getProductInfoBasedOnProductID(productID)
            numberOfProductShengYu = productInfo[3]
            if int(productBuyNum) > numberOfProductShengYu:
                return "No enough product to sales."
            else:
                connect.modifyProductInfoTableBaseOnQuantity(productID,int(productBuyNum))
                money1 = float(v[0]) * float(v[1])
                connect.modifyBalanceBaseAccountID(user_info[0], "minus", money1)
                user_info = connect.getUserCountInfoBaseUsername(username)
                shengyu = user_info[4]
                connect.addBillInfo(user_info[0], "shopping",money1 , shengyu)
                product_name = connect.getProductInfoBasedOnProductID(productID)[1]
                connect.addProductToShoppingCart(user_info[0], product_name, v[1], v[0])
    else:
        return "fail, you do not have enough money to buy."
Пример #2
0
 def wrapper(*args,**kwargs):
     user_info = connect.getUserCountInfoBaseUsername(args[0])
     if user_info[5] == 'True':
         return func(*args,**kwargs)
     else:
         login()
         user_info = connect.getUserCountInfoBaseUsername(args[0])
         if user_info[5] == 'True':
             return func(*args,**kwargs)
Пример #3
0
def login(*args, **kwargs):
    flag = 0
    while flag < 3:
        if len(args) == 0:
            username = input('pelase input your name:').strip()
            passwd = input('please input your password:'******'no user %s' % (username))
            flag += 1
            continue
        else:
            password = user_info[3]
            if password == passwd:
                if user_info[1]== 'True':
                    connect.modiyUserLoginStatus('True', username)
                    return username
                else:
                    exit('Hello {0}, you are locked.'.format(username))

            else:
                flag += 1
                if flag < 3:
                    continue
                else:
                    return 'fail'
Пример #4
0
def updateUserLockStatus(status, username):
    user_info = connect.getUserCountInfoBaseUsername(username)
    if len(user_info) == 0:
        print('No User....., this user {0} has no way to lock or is locked.'.format(username))
    else:
        connect.modiyUserLoginLockStatus(status, username)
        print('Hello {0}, your lock status is {1}.\n'.format(username, status))
Пример #5
0
def buyProducts(username):
    print('Hello {0}, you can buy these products: '.format(username))
    result = connect.getAllProductInfo()
    table = PrettyTable(['productID','productName','productPrice', 'product_remaining_amount'])
    table.align['productID'] = 'l'
    table.align['productName'] = 'l'
    table.align['productPrice'] = 'l'
    table.align['product_remaining_amount'] = 'l'
    table.padding_width = 1
    for product_line in result:
        table.add_row([product_line[0],product_line[1],product_line[2], product_line[3]])
    print(table)
    buyProductsList = {}
    while True:
        ch = input('Please input B/b(购买) or E/e(退出): ').strip()
        if ch == "B" or ch == 'b':
            buyProductId = input('Please input you want to buy productID: ').strip()
            buyProdubtNumber = input('Please input you want to buy productNumber(多少个/台/条等): ').strip()
            buyProductPrice = connect.getProductInfoBasedOnProductID(buyProductId)[2]
            buyProductsList[buyProductId]=[buyProdubtNumber,buyProductPrice]
        elif ch == "E" or ch == 'e':
            break
        else:
            print('no way, you input error.')
    user_info = connect.getUserCountInfoBaseUsername(username)
    result2 = {}
    result2[user_info[0]] = buyProductsList
    return result2
Пример #6
0
def shoppingConsumption(username, type, numberOfMoney):
    user_info = connect.getUserCountInfoBaseUsername(username)
    if user_info[4] >= numberOfMoney:
        result = connect.modifyBalanceBaseAccountID(user_info[0],'minus',numberOfMoney)
        connect.addBillInfo(user_info[0], 'shopping', numberOfMoney, user_info[4] - numberOfMoney )
        return result
    else:
        return 'fail'
Пример #7
0
def check_user_info(username):
    user_info = connect.getUserCountInfoBaseUsername(username)
    table = PrettyTable(['用户ID','用户名是否可用','用户名', '用户余额', '用户登录态'])

    table.align['用户ID'] = "l"
    table.align['用户名是否可用'] = "l"
    table.padding_width = 1
    table.add_row([user_info[0],user_info[1],user_info[2],user_info[4],user_info[5]])
    return table
Пример #8
0
def transfer(Transcriber, accessor, numberOfMoney):
    user_info = connect.getUserCountInfoBaseUsername(Transcriber)
    if user_info[4] >= numberOfMoney:

        accessor_user_info = connect.getUserCountInfoBaseUsername(accessor)
        if len(accessor_user_info) == 0:
            print('Hi {0}, accont_info has no such person: {1}'.format(user_info[0],accessor_user_info[0] ))
        else:
            result = withDrawalsOrRepayMent(Transcriber, 'minus', numberOfMoney)
            #connect.addBillInfo(user_info[0], 'transfer', numberOfMoney, user_info[4] - numberOfMoney )
            result2 = connect.modifyBalanceBaseAccountID(accessor_user_info[0], 'plus', numberOfMoney)
            connect.addBillInfo(accessor_user_info[0], 'Receipt', numberOfMoney, accessor_user_info[4] + numberOfMoney )
            if result == 'success' and result2 == 'success':
                return 'sucess'
            else:
               return 'fail'
    else:
        result = 'Hello {0}, You do not have enough money to transfer, you have {1} yuan.'
Пример #9
0
def withDrawalsOrRepayMent(username, type, numberOfMoney):
    user_info = connect.getUserCountInfoBaseUsername(username)
    if type == 'minus' and user_info[4] >= numberOfMoney and numberOfMoney %100 == 0:
        connect.addBillInfo(user_info[0], 'withDrawals', numberOfMoney, user_info[4] - numberOfMoney )
        result = connect.modifyBalanceBaseAccountID(user_info[0], type, numberOfMoney)
        return result
    elif type == 'plus':
        connect.addBillInfo(user_info[0], 'repayMent', numberOfMoney, user_info[4] + numberOfMoney )
        result = connect.modifyBalanceBaseAccountID(user_info[0],type,numberOfMoney)
        return result
Пример #10
0
def checkPurchasedProductInformation(username):
    user_info = connect.getUserCountInfoBaseUsername(username)
    result = connect.viewPurchasedProductInformation(user_info[0])
    table = PrettyTable(['userID','productName','productPrice', 'shoppingNumber'])
    table.align['userID'] = 'l'
    table.align['productName'] = 'l'
    table.align['productPrice'] = 'l'
    table.align['shoppingNumber'] = 'l'
    table.padding_width = 1
    for product_line in result:
        table.add_row([product_line[0],product_line[2],product_line[3], product_line[4]])
    return table
Пример #11
0
def checkBillInfoBaseUsername(username):
    user_info = connect.getUserCountInfoBaseUsername(username)
    user_id = user_info[0]
    result = connect.getBillInfoBaseUserID(int(user_id))
    table = PrettyTable(['UserID','Time','BillType', 'moneyofBill', 'Balance'])
    table.align['UserID'] = 'l'
    table.align['Time'] = 'l'
    table.align['BillType'] = 'l'
    table.align['moneyofBill'] = 'l'
    table.align['Balance'] = 'l'
    table.padding_width = 1
    for i in range(0,len(result)):
            table.add_row([result[i][0],result[i][1],result[i][2],result[i][3],result[i][4]])
    return table
Пример #12
0
def userexit(username):
    user_info = connect.getUserCountInfoBaseUsername(username)
    user_id = user_info[0]
    connect.modiyUserLoginStatus('False', username)