예제 #1
0
def set_password(username, userinfo):
    print("现在的用户密码是 %s" % userinfo[username]['info'][0]['password'])
    new_password = input("请输入新的密码:").strip()
    userinfo[username]['info'][0]['password'] = new_password
    write_into(username, userinfo)
    print("修改用户密码成功")
    print("现在的用户密码是 %s" % userinfo[username]['info'][0]['password'])
예제 #2
0
def set_money(username, userinfo):
    print("现在的用户余额是 %s元" % userinfo[username]['money'][0]['money'])
    new_money = int(input("请输入新的余额:").strip())
    userinfo[username]['money'][0]['money'] = new_money
    write_into(username, userinfo)
    print("修改用户余额成功")
    print("现在的用户余额是 %s元" % userinfo[username]['money'][0]['money'])
예제 #3
0
def transfer_accounts(username,userinfo):
    if userinfo[username]['money'][0]:
        print("您现在的余额为 %s元"%userinfo[username]['money'][0]['money'])
        to_username = input("请输入目的账户用户名:")
        if os.path.exists('%s/db/%s.json' % (p_dir,to_username)):
            to_money = int(input("请输入转账金额/元:"))
            if to_money <= int(userinfo[username]['money'][0]['money']):
                ##更新转账用户的信息
                money = int(userinfo[username]['money'][0]['money']) - to_money
                userinfo[username]['money'][0]['money'] = money
                write_into(username, userinfo)
                print("更新数据成功")
                ##更新转账目的用户的信息
                userinfo = read_info(to_username)
                #print(userinfo)
                if not userinfo[to_username]['money'][0]:
                    userinfo[to_username]['money'][0]['money'] = 0
                new_money = int(userinfo[to_username]['money'][0]['money']) + to_money
                userinfo[to_username]['money'][0]['money'] = new_money
                write_into(to_username,userinfo)
                print("转账成功")
                userinfo = read_info(username)
            else:
                print("你的账户余额小于转账金额,转账取消....")
        else:
            print("用户不存在...")
            exit()
    else:
        print("您的账户中还没有余额,请前去商城充值...")
        exit()
예제 #4
0
def set_username(username, userinfo):
    return
    print("现在的用户名是 %s" % userinfo[username]['info'][0]['username'])
    new_name = input("请输入新的名字:").strip()
    userinfo[username]['info'][0]['username'] = new_name
    write_into(username, userinfo)
    print("修改用户名成功")
    print("现在的用户名是 %s" % userinfo[username]['info'][0]['username'])
예제 #5
0
def take_money(username,userinfo):
    print("您现在的余额为 %s元"%userinfo[username]['money'][0]['money'])
    ta_money = int(input("提现需要5%的手续费,请输入提现金额:"))
    ot_money = ta_money * 0.05
    tb_money = ot_money + ta_money
    if ta_money <= int(userinfo[username]['money'][0]['money']):
        new_money = int(userinfo[username]['money'][0]['money']) - tb_money
        userinfo[username]['money'][0]['money'] = new_money
        write_into(username, userinfo)
        print("本次提现%s元,手续费%s元,账户余额%s元,请保管好你的钱包!"%(ta_money,ot_money,new_money))
예제 #6
0
def adminer():
    while True:
        userinfo = read_info('adm')
        #print(userinfo)
        select_info = input("你是否有注册过管理员账号了? Please select Y/N:")
        if select_info == 'N' or select_info == 'n':
            print("开始注册用户信息【只允许注册3个管理员账号】:")
            rgcode = input("请输入注册邀请码(默认定为'root123456.'):").strip()
            if rgcode == userinfo['rgcode']:
                if userinfo['now_number'] < userinfo['max_number']:
                    username = input("Please enter your username:"******"Please enter your password:"******"Please enter your phon_number:")

                    if not os.path.exists('%s/db/%s.json' % (p_dir, username)):
                        userinfo['now_number'] = userinfo['now_number'] + 1
                        write_into('adm', userinfo)
                        userinfo = {}
                        userinfo = {
                            "%s" % username: [{
                                "username": "******" % username,
                                "password": "******" % password,
                                "phon_number": "%s" % phone_number,
                                "login_count": 0
                            }],
                        }
                        write_into(username, userinfo)
                        print("恭喜注册成功!")
                    else:
                        print("用户已存在...")
                        #continue
                else:
                    print("管理员名额已满,不可注册")
            else:
                print("你的邀请码无效,不可以注册管理员账号。")
        elif select_info == 'Y' or select_info == 'y':
            print("开始登录验证信息:")
            username = input("Please enter your username:"******"Please enter your password:"******"没有该用户,请确认你的用户名!")
                    #continue
                # 判断用户登陆失败的次数是否小于3
                #print(userinfo)
                if userinfo[username][0]['login_count'] < 3:
                    ##判断用户账号密码是否吻合
                    if username in userinfo and password == userinfo[username][
                            0]['password']:  ##【优化2次】用户及密码已经一一对应
                        print(
                            "\033[35;1mwelcom login {_username}\033[0m".format(
                                _username=username).center(150, '#'))
                        ##登陆成功后将失败次数清零,便于下一次统计
                        userinfo[username][0]['login_count'] = 0
                        write_into(username, userinfo)
                        ##开始执行后台管理菜单
                        mamager_info()
                        break
                        ##返回username给后面函数调用
                        # return username,userinfo
                        # break
                    else:
                        # count += 1
                        ##修改用户登陆失败的次数
                        userinfo[username][0]['login_count'] = userinfo[
                            username][0]['login_count'] + 1
                        print('Check fail...Check again...')
                        print("您还有%s次登录机会" %
                              (3 - userinfo[username][0]['login_count']))
                        write_into(username, userinfo)
                        continue
                else:
                    print("重复登陆多次失败,请15分钟后再尝试登陆...")
                    userinfo[username][0]['login_count'] = 0
                    write_into(username, userinfo)
                    time.sleep(15)
                    continue
            else:
                print("用户不存在,请注册...")
        else:
            print("您输入的内容错误! Please enter again...")
            continue
예제 #7
0
def set_login(username, userinfo):
    userinfo[username]['info'][0]['login_count'] = 10
    write_into(username, userinfo)
    print("冻结用户成功")
예제 #8
0
def Get_commodity(username, userinfo):
    logging.basicConfig(filename='logs/%s_%s.log' % (username, now_time),
                        format='%(asctime)s %(levelname)s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    already_get_commodity = []
    userinfo = read_info(username)
    if userinfo[username]['money'][0]:
        print("你的余额为:\033[1;32m %s元 \033[0m,你的购买历史如下:" %
              userinfo[username]['money'][0]['money'])
        print("#   序号 商品    价格    购买时间")
        for i in userinfo[username]['already_get_commodity']:
            if i:
                print('#   ', i['ID'], i['商品'], i['价格'], i['购买时间'])
        print_yellow('购物历史清单End'.center(25, '#'))
    while True:
        if not userinfo[username]['money'][0]:
            money = input("请输入你拥有的金额:")
            if money.isdigit():
                money = int(money)
                userinfo[username]['money'][0]['money'] = '%s' % money
                logging.info('充值金额: %s元' % money)
                break
            else:
                print("请输入数字金额!")
                logging.warning('充值金额时输入错误...')
                continue
        else:
            break

    while True:
        while True:
            print(' ')
            print_red('商品列表'.center(25, '#'))
            print("#   序号 商品  价格")
            ##获取商品列表
            for key, commodity in enumerate(commodity_list):
                print('#   ', key, commodity[0], commodity[1])
            print(' ')
            get_commodity = input("\033[1;35m请选择你购买商品的序号:\033[0m")
            buy_time = time.strftime("%Y-%m-%d %H:%M:%S")
            ##得到商品序号
            if get_commodity.isdigit(
            ) and int(get_commodity) < len(commodity_list):
                get_commodity = int(get_commodity)
                ##判断商品价格是否大于用户金钱数
                if commodity_list[get_commodity][1] <= int(
                        userinfo[username]['money'][0]['money']):
                    ##计算用户金钱数
                    real_money = int(
                        userinfo[username]['money'][0]['money']) - int(
                            commodity_list[get_commodity][1])
                    money = real_money
                    ##把当前购买的商品信息写到已购买商品的信息字典
                    already_get_commodity.append([
                        '%s' % get_commodity,
                        '%s' % commodity_list[get_commodity][0],
                        '%s' % commodity_list[get_commodity][1],
                        '%s' % buy_time
                    ])
                    #print(already_get_commodity)
                    print(
                        "购买商品\033[1;32m %s \033[0m成功,你余额为\033[1;32m %s元 \033[0m"
                        % (commodity_list[get_commodity][0], money))
                    logging.info('在商场购买商品 %s 成功,话费 %s元' %
                                 (commodity_list[get_commodity][0], money))
                    ##追加总商品信息到字典
                    userinfo[username]['already_get_commodity'].append({
                        "ID":
                        "%s" % get_commodity,
                        "商品":
                        "%s" % commodity_list[get_commodity][0],
                        "价格":
                        "%s" % commodity_list[get_commodity][1],
                        "购买时间":
                        "%s" % buy_time
                    })
                    ##修改用户信息剩余金钱
                    userinfo[username]['money'][0]['money'] = '%s' % money
                    #print(UF.UserInfo)
                else:
                    print(
                        "你没有足够的金钱去购买\033[1;35m %s \033[0m,它的价格为\033[1;35m %s元 \033[0m,而你的余额为\033[1;35m %s元 \033[0m"
                        % (commodity_list[get_commodity][0],
                           commodity_list[get_commodity][1],
                           userinfo[username]['money'][0]['money']))
                    logging.warning(
                        '%s 没有足够的金钱去购买 %s ,该商品价格为 %s元' %
                        (username, commodity_list[get_commodity][0],
                         commodity_list[get_commodity][1]))
                print(' ')
                per_select = input("请问是否继续购买商品\033[1;35my/n\033[0m:")
                if per_select.startswith('y'):
                    continue
                elif per_select.startswith('n'):
                    print(' ')
                    print("\033[1;32m你本次购买的商品如下:\033[0m")
                    print_red('商品列表'.center(25, '#'))
                    print("#   序号 商品  价格")
                    for already_getp in already_get_commodity:
                        print('#   ', already_getp[0], already_getp[1],
                              already_getp[2])
                    print("你的余额为:\033[1;32m %s元 \033[0m" %
                          userinfo[username]['money'][0]['money'])
                    print_red('结算结束'.center(25, '#'))
                    ##退出程序前,把所有信息写进json信息记录文件,以便下一次登陆提取
                    write_into(username, userinfo)
                    return
            else:
                print("输入有错,请重新输入!")
                logging.warning('购买时输入商品序号错误....')
                continue
예제 #9
0
def Checkout_money(username,userinfo):
    return
    balance = int(userinfo[username]['money'][0]['money']) - spend_money
    userinfo[username]['money'][0]['money'] = balance
    write_into(username, userinfo)