Exemple #1
0
def acc_auth2(account, password, retry):
    """用户认证"""
    data = accounts.load_current_balance(account)
    all_count = user_login_authentication_count
    # retry_count = user_login_authentication_count + 1
    if data:
        if data['password'] == password:
            exp_time_stamp = datetime.strptime(data['expire_date'], "%Y-%m-%d")
            if datetime.now() > exp_time_stamp:
                print("\033[31;1m用户 [%s] 已经过期了,请重新申请卡!\033[0m" % account)
                exit()
            elif data['status'] == 0:
                print("\033[31;1m用户 [%s] 已经冻结,请到相应的银行解冻!\033[0m" % account)
                exit()
            else:  # passed the authentication
                access_logger = logger.card_log(account, 'access')
                access_logger.info('%s用户进行登录%d次成功' % (account, retry))
                return data
        else:
            access_logger = logger.card_log(account, 'access')
            access_logger.info('%s用户进行登录,但是密码错误,还剩下%d次' %
                               (account, all_count - retry))
            print("\033[31;1m密码错误,还剩下%d次\033[0m" % (all_count - retry))
    else:
        count = all_count - retry
        print('\033[31;1m用户名不存在,还剩下%d次\033[0m' % count)
Exemple #2
0
def choice_user():
    """
     选择需要操作的用户名

    """
    while True:
        user_account = []
        db_accounts_path = os.path.join(settings.DATABASE['path'],
                                        settings.DATABASE['name'])
        db_accounts_files = os.listdir(db_accounts_path)
        for i in db_accounts_files:
            data = accounts.load_current_balance(i.split('.')[0])
            if data['type'] == 0:
                user_account.append(data['username'])
        user_choice_number = []
        print('''\033[31;0m------------请选择需要操作的账户-----------\033[0m''')
        for number in range(len(user_account)):
            user_choice_number.append(number)
            print('%s : %s' % (number, user_account[number]))
        user_choice = input('\033[35;1m请选择操作用户>>>:\033[0m').strip()
        if user_choice.isdigit() and int(user_choice) in user_choice_number:
            acknowledgement = input('再次确认是否是这个用户%s,选择b重新选择,选择c退出这项操作,其它任意键确认' %
                                    user_account[int(user_choice)])
            if acknowledgement == 'b':
                print('重新选择用户')
            elif acknowledgement == 'c':
                print('退出这项操作,重新选择')
            else:
                global now_username
                now_username = user_account[int(user_choice)]
                break

        else:
            print('\033[31;1m请输入有效操作方式\033[0m')
Exemple #3
0
def transfer(user_account):
    # 定义一个用户转账的函数
    count = 0
    while count < 3:
        transfer = input('\033[33;1m请输入需转账人用户名,取消转账c>>>\033[0m')
        if transfer == 'c':
            break
        db_path_user1 = db_path + '\%s.json' % transfer  # 需被转账用户
        login_account_username = user_account['account_data']["username"]
        if transfer == login_account_username:
            print('\033[31;1m转账不能转给自己\033[0m')
        else:
            if os.path.isfile(db_path_user1):
                # 判断用户文件是否存在
                account_data_transfer = accounts.load_current_balance(transfer)  # 转账用户
                account_data_user = accounts.load_current_balance(login_account_username)  # 当前用户
                print('\033[33;1m转账用户信用卡号为:\033[0m \033[32;1m %s \033[0m' % transfer)
                while True:
                    inputs = input('\033[33;1m取消转账:按Q|q取消>>>\033[0m')
                    if inputs.capitalize() == 'Q':
                        break
                    money = input('\033[33;1m请输入需转账金额:\033[0m')
                    if money.isdigit():
                        money = int(money)
                        if money > account_data_user["balance"]:  # 判断转账金额是否大于存款
                            print('\033[31;1m对不起您的存款不足,无法转账\033[0m')
                        else:
                            print('\033[31;1m转账用户卡号: %s 转账金额:¥%s\033[0m'
                                  % (account_data_transfer["username"], money))
                            inputs = input('\033[33;1m请再次确认转账信息数据:按Q|q取消>>>\033[0m')
                            if inputs.capitalize() == 'Q':
                                break
                            else:
                                data = transaction.make_transaction(account_data=account_data_user,
                                                                    tran_type='transfer',
                                                                    amount=money)
                                print('ok')
                                if data:
                                    account_data_transfer['balance'] = account_data_transfer['balance'] + money
                                    accounts.dump_account(account_data_transfer)


                    else:
                        print('\033[31;1m请输入有效转账金额\033[0m')
            else:
                count += 1
                print('\033[31;1m该用户不存在,请重新输入还剩 %s 次机会\033[0m' % (3 - count))
Exemple #4
0
def account_info(user_account):
    # 定义一个查看用户信息的函数
    username = user_account['account_data']['username']
    data = accounts.load_current_balance(username)
    print("\033[33;1m我的账户信息:"
          "\n持卡人: %s "
          "\n卡号: %s"
          "\n存款: ¥%s"
          "\n可提现额度: ¥%s \033[0m"
          % (user_account['account_data']["username"], user_account['account_data']["cardid"], data["balance"],
             data["credit"]))
    input('\033[33;1m按任意键返回上一级菜单>>>:\033[0m')
Exemple #5
0
def defrosting(account):
    # 定义一个解冻函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        if data['status'] == 1:
            print('\033[31;1m当前信用卡未冻结\033[0m')
        if data['status'] == 0:
            free = input('\033[33;1m当前信用卡已解冻,按任意键选择解冻 按b返回>>>\033[0m')
            if free != 'b':
                data['status'] = 1
                accounts.dump_account(data)
                print('\033[31;1m当前信用卡已解冻\033[0m')
Exemple #6
0
def freezing(account):
    # 定义一个冻结信用卡函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        if data['status'] == 0:
            print('\033[31;1m当前信用卡已冻结\033[0m')
        if data['status'] == 1:
            free = input('\033[33;1m当前信用卡未冻结,按任意键选择冻结 按b返回>>>\033[0m')
            if free != 'b':
                data['status'] = 0
                accounts.dump_account(data)
                print('\033[31;1m当前信用卡已冻结\033[0m')
Exemple #7
0
def repay(user_account):
    # 定义一个用户存款函数
    username = user_account['account_data']['username']
    account_data = accounts.load_current_balance(username)
    print("\033[33;1m您的当前存款为: ¥%s " % account_data["balance"])
    while True:
        repays = input('\033[33;1m请输入存款金额并确认存款,按Q取消存款>>>\033[0m')
        if repays.capitalize() == 'Q':
            break
        else:
            if repays.isdigit():
                repays = int(repays)
                transaction.make_transaction(account_data=account_data, tran_type="repay", amount=repays)
                break
            else:
                print('\033[31;1m请输入有效存款金额\033[0m')
Exemple #8
0
def shop_car(user_account):
    # 定义一个购物车函数
    money_list, product_list = [], []
    shop_car_paths = shop_car_path % user_account['account_data']['username']
    if not os.path.isfile(shop_car_paths):
        print('\033[31;1m您还未有购物记录,请先进入商城购物\033[0m')
        shopping(user_account)
    else:
        with open(shop_car_paths, 'r', encoding='utf-8')as fc:
            print(('\033[32;1m购物车清单\033[0m').center(32, '-'))
            print("编号\t\t商品\t\t价格\t\t数量")
            lock_list = fc.readlines()
            for index, lock_info in enumerate(lock_list):
                lock = lock_info.split()
                product_name = lock[0]
                money = lock[1]
                num = lock[2]
                print('%s\t\t%s\t%s\t\t%s' % (index, product_name, money, num))
                moneys = int(money) * int(num)  # 定义moneys变量来计算 单个商品总金额 = 商品金额*数量
                product_info = '%s商品%s件' % (product_name, num)  # 定义打印商品名称及数量 字符串
                money_list.append(moneys)  # 将单个商品总金额 添加至 金额列表中
                product_list.append(product_info)  # 将product_info添加至 购物信息列表中

        if sum(money_list) == 0:  # sum(money_list) = 购物车所有商品总金额
            print('\033[31;1m购物车空空如也\033[0m')
        else:
            fd = accounts.load_current_balance(user_account['account_data']['username'])
            print('\n\33[33;0m您当前余额为 %s 元,当前商品金额为 %s 元' % (fd['balance'], sum(money_list)))
            go_shop = input("\n\33[34;0m是否选择购买 "
                            "任意键:购买 /【返回输入b】\33[0m:")  # 使用sum方法求出购物车商品总支付金额
            if go_shop == 'b':
                print('返回重新选择')
            else:
                if sum(money_list) < fd["balance"]:  # 判断用户余额买得起购物商品
                    balance = fd["balance"] - sum(money_list)  # 当前余额 = 原余额-商品总额
                    log = ('\033[31;1m尊敬的用户您已成功购物 %s ,购物总额为 %s 元,您购物后余额: %s元!\033[0m'
                           % (str(product_list), sum(money_list), balance))
                    transaction.make_transaction(account_data=fd, tran_type='consume', amount=sum(money_list))
                    logger.shop_log(user_account['account_data']['username'], log)  # 调用购物日志打印函数
                    print("\033[33;1m购物成功!余额为: ¥%s\033[0m" % balance)
                    shop_car_paths = shop_car_path % user_account['account_data']["username"]
                    with open(shop_car_paths, 'w', encoding='utf-8') as fc:
                        fc.truncate(0)  # 购物支付完成后 购物车文件清空
                else:
                    print("\33[31;0m对不起您的余额不足无法购买:\33[0m\n")
Exemple #9
0
def limit(account):
    # 定义一个提升信用额度函数
    choice_user()
    username = now_username
    if username:
        data = accounts.load_current_balance(username)
        print('\033[33;1m尊敬的用户您当前信用额度是 %s元' % data["credit"])
        limit = input('\033[34;1m是否选择提升信用额度  按任意键确认提示  按Q取消提升>>>')
        if limit.capitalize() != 'Q':
            while True:
                lines = input('\033[35;1m请输入提升信用额度>>>\033[0m')
                if lines.isdigit():
                    lines = int(lines)
                    if lines <= 2000:
                        data['credit'] = data['credit'] + lines
                        accounts.dump_account(data)
                        print('\033[31;1m当前信用额度提升为:%s元 \033[0m' %
                              data['credit'])
                        break
                    else:
                        print('\033[31;1m提升额度超出提升范围\033[0m')
                else:
                    print('\033[31;1m请输入有效提升额度\033[0m')
Exemple #10
0
def withdraw(acc_data):
    """
    提现
    """
    account_data = accounts.load_current_balance(acc_data['account_data']['username'])
    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        withdraw_amount = input("\033[33;1m输入提现金额,退出b:\033[0m").strip()
        if len(withdraw_amount) > 0 and withdraw_amount.isdigit():
            new_balance = transaction.make_transaction(account_data=account_data, tran_type='withdraw',
                                                       amount=withdraw_amount)
            if new_balance:
                print('\033[42;1m余额为:%s\033[0m' % (new_balance['balance']))
            else:
                print('余额%s,不足' % acc_data['account_data']['balance'])
        else:
            print('\033[31;1m[%s] 输入有误,应该输入数字!\033[0m' % withdraw_amount)

        if withdraw_amount == 'b':
            back_flag = True