Esempio n. 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
Esempio n. 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
Esempio n. 3
0
def account_info(*args):
    """
    账户信息查询函数
    :param args: 接收非固定参数
    :return:
    """
    user_info = args[0]
    get_user_info = db_handler.get_info_db()
    user_info["user_dict"] = get_user_info(user_info["user_dict"]["username"])  # 获取用户最新信息
    str_status = settings.STR_STATUS
    while True:
        os.system("cls")
        print(exhibition.account_info_show.format(
                                                user=user_info["user_dict"]["username"],
                                                today=user_info["today"],
                                                week=user_info["week"],
                                                id=user_info["user_dict"]["id"],
                                                status=str_status[user_info["user_dict"]["status"]],
                                                enroll_date=user_info["user_dict"]["enroll_date"],
                                                expire_date=user_info["user_dict"]["expire_date"],
                                                credit=user_info["user_dict"]["credit"],
                                                balance=user_info["user_dict"]["balance"]
                                                ))
        user_choice = input("请输入功能选项>>").strip()
        if user_choice == "1":
            return
        elif user_choice == "2":
            exit()
        else:
            print("\033[31;1m请输入正确的功能选项!\033[0m")
Esempio n. 4
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
Esempio n. 5
0
def atm_show(user_info):
    '''
    ATM首界面展示函数
    :return:
    '''
    get_user_info = db_handler.get_info_db()
    user_info["user_dict"] = get_user_info(user_info["user_dict"]["username"])  # 获取用户最新信息
    exit_flag = None
    while not exit_flag:
        os.system("cls")                                       #清屏
        print(exhibition.atm_show.format(
                                        user=user_info["user_dict"]["username"],
                                        today=user_info["today"],
                                        week=user_info["week"]))            #ATM展示界面
        choice = {
                "1":account_info,
                "2":withdraw,
                "3":transfer,
                "4":repay,
                "5":bill_inquiry,
                "6":cancellation,
                "7":logout
                 }
        user_choice = input("请输入功能选项>>").strip()
        if user_choice in choice:
            exit_flag = choice[user_choice](user_info)
        else:print("\033[31;1m请输入正确的功能选项!\033[0m")
Esempio n. 6
0
def transfer(*args):
    '''
    转账函数
    :param args: 接收非固定参数
    :return:
    '''
    user_info = args[0]
    get_user_info = db_handler.get_info_db()
    user_info["user_dict"] = get_user_info(user_info["user_dict"]["username"])  # 获取用户最新信息
    while True:
        os.system("cls")
        print(exhibition.transfer_show.format(
                                            user = user_info["user_dict"]["username"],
                                            today = user_info["today"],
                                            week = user_info["week"],
                                            credit = user_info["user_dict"]["credit"],
                                            balance = user_info["user_dict"]["balance"]
                                            ))
        user_choice = input("请输入功能选项>>").strip()
        if user_choice == "1":
            while True:
                transfer_obj = input("请输入您想转账的对象用户名:").strip()
                money = input("请输入您想转账的现金:").strip()
                if len(money) == 0: continue
                try:
                    money = float(money)
                    if money == 0: continue
                    make_trade(user_info, money, "transfer", trade_logger,other_account = transfer_obj)
                    break
                except ValueError:print("\033[31;1m输入不规范请重新输入!\033[0m")
        elif user_choice == "2":return
        elif user_choice == "3":exit()
        else:print("\033[31;1m请输入正确的功能选项!\033[0m")
Esempio n. 7
0
def repay(*args):
    """
    还款接口
    :param args: 接收非固定参数
    :return:
    """
    while True:
        user_info = args[0]
        get_user_info = db_handler.get_info_db()
        user_info["user_dict"] = get_user_info(user_info["user_dict"]["username"])  # 获取用户最新信息
        credit = user_info["user_dict"]["credit"]
        balance = user_info["user_dict"]["balance"]
        my_repay = float(credit) - float(balance)
        os.system("cls")
        print(exhibition.repay_show.format(
                                            user = user_info["user_dict"]["username"],
                                            today = user_info["today"],
                                            week = user_info["week"],
                                            credit = user_info["user_dict"]["credit"],
                                            balance = user_info["user_dict"]["balance"],
                                            repay = my_repay
                                            ))
        user_choice = input("请输入功能选项>>").strip()
        if user_choice == "1":
            if my_repay <= 0:
                print("\033[31;1m亲,您不需要进行还款!\033[0m")
                time.sleep(1)
                continue
            while True:
                money = input("请输入您想还款的现金:").strip()
                if len(money) == 0:
                    continue
                try:
                    money = float(money)
                    if money == 0:
                        continue
                    elif money <= my_repay:
                        user_info = make_trade(user_info, money, "repay", trade_logger)
                        break
                    elif money > my_repay:
                        print("\033[31;1m亲,您不需要还这么多!\033[0m")
                except ValueError:
                    print("\033[31;1m输入不规范请重新输入!\033[0m")
        elif user_choice == "2":
            return
        elif user_choice == "3":
            exit()
        else:
            print("\033[31;1m请输入正确的功能选项!\033[0m")
Esempio n. 8
0
def consume(*args):
    """
    消费接口,对外提供
    :param args:
    :return:
    """
    user_info = args[0]
    money = args[1]
    get_user_info = db_handler.get_info_db()
    user_info["user_dict"] = get_user_info(user_info["user_dict"]["username"])  # 获取用户信息
    try:
        ret = make_trade(user_info, money, "consume", trade_logger)
    except TypeError:
        print("该用户未办理信用卡!")
        return
    return ret
Esempio n. 9
0
def login_check(*args):
    """
    登陆验证函数
    :return: 验证成功,返回用户账号信息
    """
    count = 0
    while count < 3:
        username = input("请输入您的用户名:").strip()
        passwd = input("请输入您的密码:").strip()
        get_user_info = db_handler.get_info_db()  # 执行获取用户信息转换函数,用来适应多种数据源
        if len(args) == 1:
            user_dict = get_user_info(username)
        else:
            user_dict = get_user_info(username, args[1])
        if user_dict is None:
            print("\033[31;1m用户名不存在!请检查后再输入!\033[0m")
            count += 1
            continue
        if user_dict["status"] == 1:
            print("\033[31;1m该账户已被冻结!\033[0m")
            args[0].warning("冻结用户%s尝试登陆ATM!" % user_dict["username"])
            return
        elif passwd == user_dict["password"]:
            expire_date_timestamp = time.mktime(time.strptime(user_dict["expire_date"], "%Y-%m-%d"))
            if time.time() > expire_date_timestamp:
                print("\033[31;1m账户%s已经过期,请重新办理!\033[0m" % user_dict["username"])
                time.sleep(1)
                exit()
            else:
                print("\033[32;1m登陆成功\033[0m")
                args[0].info("%s用户登陆了ATM!" % user_dict["username"])
                return user_dict
        else:
            print("\033[31;1m密码错误!\033[0m")
            count += 1
            continue
    else:
        print("\033[31;1m您已输错三次,请下次重试!谢谢!\033[0m")
Esempio n. 10
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