示例#1
0
def unfreeze_account(*args):
    """
    用户解冻函数
    :param args:接收非固定参数
    :return:
    """
    while True:
        username = input("请输入要解冻的用户名:").strip()
        get_user_info = db_handler.get_info_db()           # 获取相应的数据访问函数
        user_dict = get_user_info(username)                # 获取用户信息
        if user_dict:
            if user_dict["status"] == 0:
                print("\033[31;1m用户%s是正常状态,不需要解冻!\033[0m" % username)
                time.sleep(1)
                break
            user_dict["status"] = 0
            dump_info = db_handler.dump_info_db()
            dump_info(user_dict)
            print("\033[31;1m用户%s解冻成功!\033[0m" % username)
            manage_logger.info("用户%s已被管理者%s解冻" % (username, args[0]["username"]))
            time.sleep(1)
            break
        else:
            print("输入不规范,请重新输入!")
            continue
示例#2
0
def freeze_account(*args):
    """
    用户冻结函数
    :param args: 接收非固定参数
    :return:
    """
    while True:
        username = input("请输入要冻结的用户名:").strip()
        get_user_info = db_handler.get_info_db()
        user_dict = get_user_info(username)                # 获取用户信息
        if user_dict:
            if user_dict["status"] == 1:
                print("\033[31;1m用户%s已经处于冻结状态!\033[0m" % username)
                time.sleep(1)
                break
            user_dict["status"] = 1
            dump_info = db_handler.dump_info_db()
            dump_info(user_dict)
            print("\033[31;1m用户%s冻结成功!\033[0m" % username)
            manage_logger.info("用户%s已被管理者%s冻结" % (username, args[0]["username"]))
            time.sleep(1)
            break
        else:
            print("输入不规范,请重新输入!")
            continue
示例#3
0
def credit_change(*args):
    """
    用户信用额度调整函数
    :param args: 接收非固定参数
    :return:
    """
    while True:
        username = input("请输入要调整的用户名:").strip()
        credit = input("请输入要调整的额度:").strip()
        get_user_info = db_handler.get_info_db()
        user_dict = get_user_info(username)  # 获取用户信息
        if user_dict:
            if credit.isdigit() and int(credit) > 0:
                user_dict["credit"] = credit
                dump_info = db_handler.dump_info_db()
                dump_info(user_dict)
                print("\033[31;1m用户%s信用额度调整成功!\033[0m"%username)
                manage_logger.info("用户%s已被管理者%s重新设置信用额度,新额度为:%s"
                                   % (username, args[0]["username"], credit))
                time.sleep(1)
                break
            else:
                print("\033[31;1m输入不规范,请重新输入!\033[0m")
                continue
        else:
            print("要调整的用户不存在,请重新输入!")
            continue
示例#4
0
def add_user(*args):
    """
    添加用户函数
    :param args: 接收非固定参数
    :return:
    """
    get_file = db_handler.get_all_db()
    user_id_path = settings.DATABASE["userid"]
    user_id = get_file(user_id_path)
    tmp_username_list = user_id[1]  # 临时存储所有的用户名
    tmp_userid_list = user_id[0]
    while True:
        username = input("请输入要添加的用户名:").strip()
        if username in tmp_username_list:
            print("\033[31;1m您要添加的用户名已经存在,无需添加!\033[0m")
            break
        elif username.isidentifier():
            user_dict = settings.DEFAULT_USER_DICT
            id = tmp_userid_list[-1]+1  # id自增
            # 设置用户信息
            user_dict["id"] = id
            user_dict["username"] = username
            user_dict["enroll_date"] = str(today)
            tmp_expire_date = datetime.datetime.now().replace(year=datetime.datetime.now().year+5)
            user_dict["expire_date"] = str(tmp_expire_date)[:10]
            # 将用户ID,用户名添加至数据库以便核查
            user_id[0].append(id)
            user_id[1].append(username)
            # 创建两个导入信息至数据库的对象
            dump_file = db_handler.dump_all_db()
            dump_info = db_handler.dump_info_db()
            # 将用户信息以及userid更新至数据库
            dump_info(user_dict)
            dump_file(user_id,settings.DATABASE["userid"])
            # 创建一个新用户的报告文件
            report_file_path = os.path.join(settings.REPORT_PATH, "%s.rp" % username)
            data_access.write_file("",report_file_path)
            # 打印信息
            print("用户%s已被管理者%s添加至ATM系统!" % (username, args[0]["username"]))
            # 记录管理日志
            manage_logger.info("用户%s已被管理者%s添加至ATM系统!" % (username, args[0]["username"]))
            return
        else:
            print("\033[31;1m输入不规范,请重新输入!\033[0m")
            continue
示例#5
0
def make_trade(user_info, money, trade_type, logger_obj, **kwargs):
    """
    交易中心函数,处理所有的交易行为
    :param user_info: 用户信息
    :param money: 交易金额
    :param trade_type: 交易类型
    :param logger_obj: 日志对象
    :param kwargs: 其他拓展参数
    :return:
    """
    money = float(money)
    dump_info = db_handler.dump_info_db()
    if trade_type in settings.TRADE_TYPE:
        interest = money * settings.TRADE_TYPE[trade_type][
            'interest']  # 获取交易利息
        balance_before = user_info["user_dict"]["balance"]  # 获取当前余额
        if settings.TRADE_TYPE[trade_type]['action'] == "plus":
            balance_after = balance_before + money + interest
            trade_money = money
            trade_interest = interest
        elif settings.TRADE_TYPE[trade_type]['action'] == "minus":
            balance_after = balance_before - money - interest
            trade_money = -money
            trade_interest = -interest
            if balance_after < 0:
                print("\033[31;1m您的当前余额为:%s,此次交易金额为-%s,余额不足无法完成交易!\033[0m" %
                      (balance_before, money + interest))
                return
        else:
            logger_obj.warning("交易类型%s配置信息有误,请检查!" % trade_type)
            return
        if trade_type == "transfer":
            other_account = kwargs["other_account"]
            if user_info["user_dict"]["username"] == other_account:
                print("\033[31;1m请不要自己转自己账户!OK!\033[0m")
                time.sleep(1)
                return
            get_user_info = db_handler.get_info_db()
            other_account_dict = get_user_info(other_account)
            if other_account_dict:
                expire_date_timestamp = time.mktime(
                    time.strptime(other_account_dict["expire_date"],
                                  "%Y-%m-%d"))
                if time.time() > expire_date_timestamp:
                    print("\033[31;1m要转账的用户%s已经过期,请告知对方!\033[0m" %
                          other_account)
                    time.sleep(1)
                    return
                if other_account_dict["status"] == 1:
                    print("\033[31;1m要转账的用户%s已被冻结,请告知对方!\033[0m" %
                          other_account)
                    time.sleep(1)
                    return
                if other_account_dict:
                    other_account_dict["balance"] += money  # 将转账对象的账户里面添加一笔资金
                    dump_info(other_account_dict)  # 将新的转账对象的用户信息存入数据库
                    print("转账对象%s接收到%s来自您的资金!" % (other_account, money))
                    # 生成交易日志
                    logger_obj.info(
                        "account_id:%s  trade:%s  amount:%s " %
                        (other_account_dict["id"], trade_type, money))
                    # 以下为报告生成
                    date = time.strftime("%Y-%m-%d&%H:%M:%S", time.localtime())
                    report = "%s %s %s %s %s" % (date, "收到转账", money, 0,
                                                 other_account_dict["balance"])
                    report_handle.create_report(other_account_dict, report)
            else:
                print("\033[31;1m要转账的用户对象%s不存在,请检查!\033[0m" % other_account)
                return
        user_info["user_dict"]["balance"] = balance_after  # 获取用户最新余额
        user_dict = user_info["user_dict"]  # 用户信息
        ret = dump_info(user_dict)  # 将新的用户信息存入数据库
        if ret:
            print("您之前的余额为:%s,此次交易金额为:%s,利息为:%s,最新余额为:\033[31;1m%s\033[0m" %
                  (balance_before, trade_money, trade_interest, balance_after))
            time.sleep(1)
            # 生成交易日志
            logger_obj.info(
                "account_id:%s  trade:%s  amount:%s  interest:%s" %
                (user_dict["id"], trade_type, trade_money, trade_interest))
            # 以下为报告生成
            date = time.strftime("%Y-%m-%d&%H:%M:%S", time.localtime())
            report = "%s %s %s %s %s" % (
                date, settings.TRADE_TYPE[trade_type]["zh"], trade_money,
                trade_interest, balance_after)
            report_handle.create_report(user_dict, report)
        else:
            logger_obj.warning("%s用户文件不存在!" % user_dict["username"])
            return
        return "done"
    else:
        print("\033[31;1m%s交易类型不存在!\033[0m" % trade_type)
        return