示例#1
0
def transfer():
    """
    用户转账功能函数
    :return:
    """
    target = input('请输入收款方姓名:').strip()
    source_data = user_data[0]
    target_data = db_handler.load_db(target)
    source_credit = source_data['credit']  # 原账户额度
    target_credit = target_data['credit']  # 对方账户额度
    amount = input('请输入要转账的金额:').strip()
    if amount.isdigit():
        amount = int(amount)
        if amount <= source_credit:
            amount = int(amount)
            target_data['credit'] = target_credit + amount
            db_handler.save_db(source_data['id'], source_data)
            db_handler.save_db(target, target_data)
            # 流水记录
            cost_record('transfer to %s' % target, amount, source_data)
            # 日志记录
            logger.logger.info('{0} transfer to {1} ${2}'.format(
                source_data['id'], target, amount))
            print('转账成功!')
        else:
            print('\033[31;1m 您的额度不够!无法完成转账。\033[0m')
    else:
        print('\033[31;1m Inval values! \033[0m')
示例#2
0
def run():
    """
    manager程序入口启动函数
    :return:
    """
    while True:
        username = input('username >>:').strip()
        # 加载管理员账户信息
        mananger_data = db_handler.load_db('admin')
        password = input('password >>:').strip()
        if username == mananger_data['id'] and password == mananger_data['password']:
            # 记录日志
            logger.ad_logger.info('manager login.')
            while True:
                print(MENU)
                choice = input('请输入您要进行的操作:').strip()
                if choice == '1':
                    add_user()
                elif choice == '2':
                    credit_modify()
                elif choice == '3':
                    block_user()
                else:
                    print('\033[31;1m Invail value! \033[0m')
        else:
            print('\033[31;1m 账号密码错误!\033[0m')
            # 记录manager登陆错误日志
            logger.ad_logger.warning('manager 登陆账号密码错误。')
示例#3
0
def block_user():
    """
    manager冻结账户
    :return:
    """
    username = input('username >>:').strip()
    user_data = db_handler.load_db(username)
    if user_data['status'] == 0:  # 判断block之前用户是否已经被block
        user_data['status'] = 1
        db_handler.save_db(user_data['id'], user_data)  # 写入用户json文件
        # 记录数据库
        logger.ad_logger.info('account %s is blockd!' % username)
        print('账户%s 冻结成功!' % username)
示例#4
0
 def inner(*args, **kwargs):
     global login_status  # 声明全局变量 login_status
     if not login_status:  # 当login_status状态为False时,用户是未登录状态,进行登陆操作
         username = input('username >>: ').strip()
         data = db_handler.load_db(username)  # 加载用户数据
         user_data.append(data)  # 用来存当前登陆用户的数据(字典格式), 给被装饰的函数用
         password = input('password >>: ').strip()
         if password == data['password']:
             if user_data[0]['status'] == 0:  # 判断用户是否被冻结, '0'代表正常, '1'代表已冻结
                 login_status = True
                 func(*args, **kwargs)
             else:
                 print('用户已被冻结!')
     elif login_status:
         func(*args, **kwargs)
示例#5
0
def credit_modify():
    """
    manager修改用户额度
    :return:
    """
    username = input('username >>:').strip()
    user_data = db_handler.load_db(username)
    old_credit = user_data['credit']
    new_credit = input('目前用户额度为 %s , 新额度:' % old_credit)
    if new_credit.isdigit():
        new_credit = int(new_credit)
        user_data['credit'] = new_credit
        db_handler.save_db(user_data['id'], user_data)  # 写入用户json文件
        # 记录数据库
        logger.ad_logger.info('%s credit modify : %s.' % (username, new_credit))
        print('修改成功,目前用户{0}额度为{1}'.format(user_data['id'], user_data['credit']))
    else:
        print('Invalid value!')