Example #1
0
def register():
    '''
    注册函数,登录了不能继续注册,已存在的用户不能再次注册
    :return:
    '''
    if user_data['is_auth']:
        print('you is login')
        return
    print('注册:')
    while True:
        name = input('please input username>>').strip()
        if 'q' == name: break
        user_dic = user.get_userinfo_by_name(name)
        if user_dic:
            print('user is exist')
            continue
        else:
            password = input('please input password>>').strip()
            password2 = input('please config password>>').strip()
            if password == password2:
                user.register_user(name, password)
                break
            else:
                print('password not equles')
                continue
Example #2
0
def transfer():
    print('转账')
    while True:
        trans_name = input('please input transfer user(q to exit)>>').strip()
        if trans_name == user_data['name']:
            print('connot transfer to yourself')
            continue
        if 'q' == trans_name: break
        trans_dic = user.get_userinfo_by_name(trans_name)
        if trans_dic:
            trans_money = input('please input transfer money>>:').strip()
            if trans_money.isdigit():
                trans_money = int(trans_money)
                user_balance = bank.get_balance_interface(user_data['name'])
                if user_balance >= trans_money:
                    bank.transfer_interface(user_data['name'], trans_name,
                                            trans_money)
                    break
                else:
                    print('money not enough')
                    continue
            else:
                print('please input numbers')
                continue
        else:
            print('user do not exist')
            continue
Example #3
0
def login():
    '''
    登录函数,密码输错三次锁定,用户名输错可以一直输入
    :return:
    '''
    print('请登录:')
    count = 0
    while True:
        name = input('please input username>>:').strip()
        if 'q' == name: break
        user_dic = user.get_userinfo_by_name(name)
        if count >= 3:
            # 锁定用户
            user.lock_user(name)
            print('try too many,user locked')
            break
        if user_dic:
            passwrod = input('please input password>>:').strip()
            if user_dic['password'] == passwrod and not user_dic['locked']:
                user_data['name'] = name
                user_data['is_auth'] = True
                print('login success')
                break
            else:
                print('password error or user locked')
                count += 1
                continue
        else:
            print('user do not exist')
            continue
Example #4
0
def check_record(name):
    '''
    查看流水接口
    :param name:
    :return:
    '''
    current_user = user.get_userinfo_by_name(name)
    logger_bank.info('%s 查看了银行流水' % name)
    return current_user['bankflow']
Example #5
0
def look_shoppingcart(name):
    '''
    查看购物车接口
    :param name:
    :return:
    '''
    user_dic = user.get_userinfo_by_name(name)
    logger_shopping.info('%s 查看了购物车' % name)
    return user_dic['shopping_cart']
Example #6
0
def get_balance_interface(name):
    '''
    查看余额接口
    :param name:
    :return:
    '''
    # user_dic=user.get_userinfo_by_name(name)
    # return user_dic['account']
    # logger_bank.info('%s 查看了余额' % (name))
    return user.get_userinfo_by_name(name)['account']
Example #7
0
def repay_interface(name, account):
    '''
    还款接口
    :param name:
    :param account:
    :return:
    '''
    user_dic = user.get_userinfo_by_name(name)
    user_dic['account'] += account
    # 记录流水
    user_dic['bankflow'].extend(['%s repay %s yuan' % (name, account)])
    db_handle.update(user_dic)
    logger_bank.info('%s 还款 %s 元' % (name, account))
Example #8
0
def transfer_interface(from_name, to_name, account):
    '''
    转账接口
    :param from_name:
    :param to_name:
    :param account:
    :return:
    '''
    from_user_dic = user.get_userinfo_by_name(from_name)
    to_user_dic = user.get_userinfo_by_name(to_name)
    if from_user_dic['account'] >= account:
        from_user_dic['account'] -= account
        to_user_dic['account'] += account
        # 记录流水
        from_user_dic['bankflow'].extend(
            ['%s transfer %s yuan to %s' % (from_name, account, to_name)])
        to_user_dic['bankflow'].extend(
            ['%s accept %s yuan from %s' % (to_name, account, from_name)])
        db_handle.update(from_user_dic)
        db_handle.update(to_user_dic)
        logger_bank.info('%s 向 %s 转账 %s' % (from_name, to_name, account))
        return True
    else:
        return False
Example #9
0
def withdraw_interface(name, account):
    '''
    取款接口(扣手续费)
    :param name:
    :param account:
    :return:
    '''
    user_dic = user.get_userinfo_by_name(name)
    if user_dic['account'] >= account * 1.05:
        user_dic['account'] -= account * 1.05
        # 记录流水
        user_dic['bankflow'].extend(['%s withdraw %s yuan' % (name, account)])
        db_handle.update(user_dic)
        logger_bank.info('%s 取款 %s 元' % (name, account))
        return True
    else:
        return False
Example #10
0
def consum_interface(name, account):
    '''
    消费接口
    :param name:
    :param account:
    :return:
    '''
    user_dic = user.get_userinfo_by_name(name)
    if user_dic['account'] >= account:
        user_dic['account'] -= account
        # 记录流水
        user_dic['bankflow'].extend(['%s consum %s yuan' % (name, account)])
        db_handle.update(user_dic)
        logger_bank.info('%s 消费 %s 元' % (name, account))
        return True
    else:
        return False
Example #11
0
def shopping_interface(name, shopping_cart, cost_money):
    '''
    购物接口
    :param name:
    :param shopping_cart:
    :param cost_money:
    :return:
    '''

    # 调用信用卡扣款接口付款
    if bank.consum_interface(name, cost_money):
        # 保存购物车
        user_dic = user.get_userinfo_by_name(name)
        user_dic['shopping_cart'] = shopping_cart
        db_handle.update(user_dic)
        logger_shopping.info('%s 花费 %s 购买了 %s' %
                             (name, cost_money, shopping_cart))
        return True
    else:
        return False