示例#1
0
文件: main.py 项目: if000else/ATM
def mag_change(car_number):
    '''
    modify user card change
    :param car_number:
    :return:
    '''
    try:
        data = api_func.db_hander("select", "card_info")
        print("Your current change:", data[car_number]["change"])
        change_input = input("\033[1;33;1m Input amount>>:\033[0m")
        data[car_number]["change"] = float(change_input)  # modify freeze flag
    except Exception as e:
        if e:
            functions.colordisplay("Input error!", "red")
        else:
            api_func.db_hander("modify", "card_info", data)
            print("Modify change successfully!")
示例#2
0
def transfer(card_info):
    '''
    call when user need to transfer
    :param card_info: dic type
    :return: None
    '''
    if  card_info["freeze"]:# card is freeze
        functions.colordisplay("your card is frozen!Please refreeze first!","red")
    try:
        cur_card_number = card_info["card_number"]
        all_card_info = api_func.db_hander("select","card_info")
        print("current all cards: ")
        for key in all_card_info.keys():
            print(key)
        print("Your card num is:%s" %card_info["card_number"])
        change = card_info["change"]
        print("change:", change)
        trans_num = input("\033[1;33;1m Input card number you want to transfer:>>\033[0m")
        if trans_num in all_card_info.keys():
            amount = input("\033[1;33;1m Input amount:>>\033[0m")
            interest = config.TransType["transfer"]
            new_change = calculate(amount, change, 'minus', interest)
            pay_auth = input("\033[1;33;1m Input pay password:>>\033[0m")
            if pay_auth == card_info["pay_password"]:
                if trans_num in all_card_info.keys():
                    all_card_info[cur_card_number]["change"] -= new_change
                    all_card_info[trans_num]["change"] += float(change)  # receive account no interest
                    api_func.db_hander("modify", "card_info", all_card_info)  # Write in file
                    print("Your change remain:%s yuan"%all_card_info[cur_card_number]["change"])
                    log.set_log("transaction",20,"User %s transfer successfully!"%card_info["username"])

                else:
                    functions.colordisplay("Can not find the card number!","red")
            else:
                functions.colordisplay("Pay password is incorrect!","red")
                log.set_log("transaction",20,"User %s transfer failed,wrong pay_password!"%card_info["username"])
        else:
            functions.colordisplay("card does not exist!","red")

    except Exception as e:
        functions.colordisplay(e, "red")
        log.set_log("error",40,"User %s transfer failed, error!"%card_info["username"])
    return None
示例#3
0
def calculate(amount,change,type,interest):
    '''
    calculate all kinds of transactions in detail
    :param amount:
    :param change:
    :param type:
    :param interest:
    :return: float change
    '''
    amount = float(amount)
    change = float(change)
    interest = float(interest)
    if type == 'plus':#plus
        change = amount + change*(1 - interest)

    elif type == 'minus':#minus
        change = change - amount - interest * amount
    else:
        functions.colordisplay("type error!","red")
        return None
    return change
示例#4
0
def withdraw(card_info):
    '''
    call when user need to withdraw
    :param card_info: dic type
    :return:
    '''
    if  card_info["freeze"]:# card is freeze
        functions.colordisplay("your card is frozen!Please refreeze first!", "red")
        return None
    card_number = card_info["card_number"]
    try:
        change = card_info["change"]
        print("Your change:%s yuan"%change)
        amount = input("\033[1;33;1m Input amount:>>\033[0m")
        interest = config.TransType["withdraw"]
        print("Service fee %s%%:"%interest)
        new_change = calculate(amount, change, 'minus', interest)
        pay_auth = input("\033[1;33;1m Input pay password:>>\033[0m")
        if pay_auth == card_info["pay_password"]:
            data = api_func.db_hander("select", "card_info")
            data[card_number]["change"] = new_change
            api_func.db_hander("modify", "card_info", data)  # write in file
            print("Your new change:%s yuan"%new_change)
        else:
            functions.colordisplay("Repay failed because of incorrect pay password!", "red")
            log.set_log("transaction",20,"User %s withdraw failed,wrong pay password!"%card_info["username"])

    except Exception as e:
        functions.colordisplay(e, "red")
        log.set_log("error",40,"User %s withdraw failed, error!",card_info["username"])
示例#5
0
def repay(card_info):
    '''
    call when user need to repay
    :param card_info:
    :return:
    '''
    if  card_info["freeze"]:# card is freeze
        functions.colordisplay("your card is frozen!Please refreeze first!", "red")
        return None
    card_number = card_info["card_number"]
    repay_change = card_info["credit"] - card_info["change"]
    if repay_change > 0:
        functions.colordisplay("You need to repay:%s yuan"%repay_change,"red")
    try:
        change = card_info["change"]
        print("Your change:%s yuan"%change)
        print("Your credit:%s yuan"%card_info["credit"])
        amount = input("\033[1;33;1m Input amount:>>\033[0m")
        interest = config.TransType["repay"]
        print("current interest:%s%%"%interest)
        new_change = calculate(amount, change, 'plus', interest)
        pay_auth = input("\033[1;33;1m Input pay password:>>\033[0m")
        if pay_auth == card_info["pay_password"]:
            data = api_func.db_hander("select","card_info")
            data[card_number]["change"] = new_change
            api_func.db_hander("modify", "card_info",data)# write in file
            print("new change:",new_change)
            log.set_log("transaction",20,"User %s repay successfully!"%card_info["username"])
        else:
            functions.colordisplay("Repay failed because of incorrect pay password!", "red")
            log.set_log("transaction",20,"User %s failed to repay,because of incorrect password" %card_info["username"])
    except Exception as e:
        log.set_log("errror",40,"User %s repay with error \n %s" %(card_info["username"],e))
示例#6
0
文件: main.py 项目: if000else/ATM
def main():
    # try:
    flag_menu = True  # end program
    while flag_menu:
        if auth_tool["auth"]:  # already authorized
            functions.colordisplay(menu_logout, "yellow")
        else:  # login is required
            functions.colordisplay(menu_login, "yellow")
        menu_choice = functions.inpmsg("Input >>:",
                                       ('1', '2', '3', '4')).strip()
        if menu_choice == '1':
            if auth_tool["auth"]:  # user want to logoff
                auth_tool["auth"] = False
            else:  # user want to login
                login_data = functions.login()
                if login_data:
                    auth_tool["data"] = login_data
                    auth_tool["name"] = login_data["username"]
                    auth_tool["auth"] = True
                    auth_tool["admin"] = login_data["admin"]
        elif menu_choice == '2':  # Credit Card Center
            card_center(auth_tool)
        elif menu_choice == '3':  # Store
            if auth_tool["auth"]:
                store.shopping(auth_tool)
            else:
                functions.colordisplay("please login first!", "red")
        elif menu_choice == '4':  # Exit
            print("Bye...")
            flag_menu = False
        else:
            print("Invalid input!")
示例#7
0
文件: store.py 项目: if000else/ATM
def shopping(autu_tool):
    '''
    This is a life store.You can buy something special according to your need.And you can add things
    to your shop car,then pay with your credit card.
    :param autu_tool: login check
    :return: None
    '''
    shop_car = {}
    shop_flag = True
    while shop_flag:
        functions.colordisplay(display.shop_list, "yellow")
        choice = functions.inpmsg(
            "Input:", ('1001', '1002', '1003', '1004', '1005', '1006', '1007',
                       '1008', '1009', 'ok', 'pay', 'b'))
        select = config.ShopLists.keys()
        single = {"number": None, "price": None, "amount": 0}
        if choice in select:
            if choice in shop_car.keys():  #already select
                shop_car[choice]["amount"] += 1
            else:
                single["number"] = choice
                single["price"] = config.ShopLists[choice]["price"]
                single["amount"] = 1
                new_dic = {single["number"]: single}
                shop_car.update(new_dic)
                print("Added to shop car...")
        elif choice == 'ok':
            if shop_car:
                print("You have choose:")
                print("number price amount")
                for items in shop_car.values():
                    print(items["number"], ' ', items["price"], ' ',
                          items["amount"])
            else:
                functions.colordisplay("You didn't add any things!", 'red')
        elif choice == 'pay':
            if not shop_car:  # shop_car is empty!!!
                functions.colordisplay("You didn't add any things!", 'red')
            else:
                print("Generating bill...")
                time.sleep(2)
                total = shop_car_dc(shop_car)  #get total price
                order_num = api_func.gene_order(total, shop_car,
                                                autu_tool["name"])
                print("Skipping to payment...")
                time.sleep(2)
                pay_flag = main.store_payment(
                    order_num, total, autu_tool["name"])  # call payment
                if pay_flag:  # pay success
                    api_func.user_bill(order_num, autu_tool["name"])
                    shop_car.clear()  # clear shop car
                else:
                    print("Pay failed,please check!")
        else:
            print("User %s leave store..." % autu_tool["name"])
            shop_flag = False
    return None
示例#8
0
文件: main.py 项目: if000else/ATM
def card_center(login_data):
    '''

    :param user_data:
    :return:
    '''
    if login_data["auth"]:  # user is login
        flag_card = True
        while flag_card:
            card_number = creditcard.find_user(login_data["name"])
            if not card_number:  # user does not bind credit card
                functions.colordisplay("can not find user in db", "red")
                flag_card = False
            else:
                all_cards = api_func.db_hander("select", "card_info")
                current_card = all_cards[card_number]  # get current user info
                functions.colordisplay(menu_credit, "yellow")
                menu_choice = functions.inpmsg("Input >>:",
                                               ('1', '2', '3', '4', '5', '6',
                                                '7', '8', '9', 'b')).strip()
                if menu_choice == '1':  #User Info
                    print("Current user: [%s]" % login_data["name"])
                elif menu_choice == '2':  #Card Info
                    print("Your card number: [%s]" % card_number)
                    detail = functions.inpmsg("[m] to display more...")
                    if detail == "m":
                        for k, v in current_card:
                            print(k, ':', v)

                elif menu_choice == '3':  # Repay
                    creditcard.repay(current_card)
                elif menu_choice == '4':  #Withdraw
                    creditcard.withdraw(current_card)
                elif menu_choice == '5':  #Transfer
                    creditcard.transfer(current_card)
                elif menu_choice == '6':  #Freeze
                    freeze(current_card["card_number"])
                elif menu_choice == '7':  #See my Bill
                    api_func.see_bill(auth_tool["name"])
                elif menu_choice == '8':  #Manage credit
                    mag_credit(current_card["card_number"])
                elif menu_choice == '9':  #Manage change
                    mag_change(current_card["card_number"])
                else:  # menu_choice == 'b'---Back
                    flag_card = False

    else:
        functions.colordisplay("Sorry,you need to login first!", "red")
示例#9
0
文件: main.py 项目: if000else/ATM
def store_payment(order_num, money, username):
    '''
    This is pay api for store.According order number and order price to pay,
    return True if success,else return False.
    :param order_num:
    :param money:
    :param username:
    :return:
    '''
    card_number = creditcard.find_user(username)  # find card num by username
    print("Found your credit card:\033[1;34;1m%s\033[0m" % card_number)
    print("order:", order_num)
    print("aomount:%s yuan" % money)
    data = api_func.db_hander("select", "card_info")
    if data[card_number]["freeze"]:
        functions.colordisplay("This card is frozen! payment is denied!",
                               "red")
    else:
        user_card = data[card_number]  # get user card info
        pay_psd = input("\033[1;33;1m Input pay password:\033[0m")
        if pay_psd == user_card["pay_password"]:
            if user_card["change"] < money:
                functions.colordisplay("Your balance is not enough!", "red")
            else:
                data[card_number]["change"] -= money
                api_func.db_hander("modify", "card_info", data)  #write in file
                log.set_log("transaction", 20,
                            "User %s pay successfully!" % username)
                return True
        else:
            functions.colordisplay("Sorry,pay password is incorrect!!!", "red")
            log.set_log(
                "transaction", 20,
                "User %s failed to pay because of incorrect pay_password!" %
                username)
    return False
示例#10
0
文件: main.py 项目: if000else/ATM
 def wrapper(*args, **kwargs):
     if auth_tool["admin"]:
         fun(*args, **kwargs)
     else:
         functions.colordisplay("Acess is denied!", "red")