예제 #1
0
def card_add():
    res = False
    temp_cards = get_cards()
    flag = False
    while not flag:
        card_id = input('请输入信用卡卡号(必须为纯数字8位):')
        if not card_id.isdigit() or len(card_id) != 8:
            print('\033[1;31;1m卡号错误!\033[0m')
            continue
        else:
            if re_cardid(temp_cards, card_id):
                print('\033[1;31;1m卡号已存在!\033[0m')
                continue
            else:
                while not flag:
                    card_limit = input('请输入信用卡最高额度:')
                    if not card_limit.isdigit():
                        print('\033[1;31;1m信用卡额度必须为整数!\033[0m')
                        continue
                    else:
                        #获取用户列表并循环显示,记录进临时列表
                        temp_user = user.get_users()
                        i = 0
                        user_list = []
                        for users in temp_user:
                            user_list.append(users)
                            print(i, '┄', users)
                            i += 1
                        while not flag:
                            card_woner = input('请选择卡片所有者:')
                            if card_woner.isdigit():
                                card_woner = int(card_woner)
                                #判断用户是否有卡
                                if re_card_owner(temp_cards,
                                                 user_list[card_woner]):
                                    print('\033[1;31;1m他有卡了,别添加了!\033[0m')
                                    continue
                                else:
                                    temp_cards[card_id] = {
                                        'limit': int(card_limit),
                                        'owner': user_list[card_woner],
                                        'banlance': int(card_limit),
                                        'frozen': False
                                    }
                                    with open('%s\\db\\cards.txt' % (BASE_DIR),
                                              'w',
                                              encoding='utf-8') as f:
                                        f.write(
                                            json.dumps(temp_cards,
                                                       ensure_ascii=False))
                                    flag = True
                                    res = temp_cards[card_id]
                                    break
                            else:
                                print('\033[1;31;1m错误的选择!\033[0m')
                                continue
                break
        break
    return res
예제 #2
0
def transfer_accounts(user_info):
    '''
    转账
    :param user_info:
    :return:
    '''
    res = False
    # print(user_info)
    temp_users = user.get_users()
    temp_cards = card_manage.get_cards()
    user_card = get_user_card(user_info[0])
    while True:
        print('信用卡转账'.center(50, '#'))
        print('\033[1;36;1m您现在拥有现金【%d】元。\033[0m' % (user_info[1]['money']))
        if user_info[1]['money'] == 0:
            print('\033[1;31;1m钱都没有,转毛线啊!滚蛋!\033[0m')
            break
        tran_money = input('请输入转账金额(q退出):')
        if tran_money.isdigit() and int(tran_money) <= user_info[1]['money']:
            tran_money = int(tran_money)
            card_list = []
            i = 0
            for card in temp_cards:
                card_list.append(card)
                print(i, '=> 卡号:', card, '||所有者:', temp_cards[card]['owner'])
                i += 1
            while True:
                act = input('请选择转入的信用卡(q退出):')
                if act.isdigit() and int(act) < len(temp_cards):
                    act = int(act)
                    temp_cards[card_list[act]]['banlance'] += tran_money
                    user_info[1]['money'] -= tran_money
                    temp_users[user_info[0]] = user_info[1]
                    with open('%s\\db\\users.txt' % (BASE_DIR),
                              'w',
                              encoding='utf-8') as f:
                        f.write(json.dumps(temp_users, ensure_ascii=False))
                    with open('%s\\db\\cards.txt' % (BASE_DIR),
                              'w',
                              encoding='utf-8') as f:
                        f.write(json.dumps(temp_cards, ensure_ascii=False))
                    str = '\033[1;36;1m【%s】向【%s】转账%d元成功。\033[0m' % (
                        user_info[0], temp_cards[card_list[act]]['owner'],
                        user_info[1]['money'], tran_money)
                    res = {'errcode': 0, 'msg': str}
                    info = '向%s转账%d元\n' % (temp_cards[card_list[act]]['owner'],
                                           tran_money)
                    write_card_log('tran', user_info[0], info)
                    break
                else:
                    print('选择错误!')
                    continue
        else:
            continue
        break
    return res
예제 #3
0
def repayment(user_info):
    '''
    还款
    :return:
    '''
    res = False
    #print(user_info)
    temp_users = user.get_users()
    temp_cards = card_manage.get_cards()
    user_card = get_user_card(user_info[0])
    debt = user_card['msg'][1]['limit'] - user_card['msg'][1]['banlance']
    while True:
        print('您当前拥有现金【%d】元。' % (user_info[1]['money']))
        print('您当前信用卡欠款金额【%d】元。' % (debt))
        if user_info[1]['money'] == 0:
            print('钱都没有,还毛线啊!滚蛋!')
            break
        re_money = input('请输入要还款的金额(输入all归还全部欠款):')
        if re_money.isdigit() and int(re_money) <= user_info[1]['money']:
            re_money = int(re_money)
            if re_money > debt:
                print('您只需归还【%d】元,系统为您自动扣除,多余部分返还现金。' % (debt))
                user_card['msg'][1]['banlance'] = user_card['msg'][1]['limit']
                #temp_users[user_info[0]]['money']
                user_info[1]['money'] -= debt
            else:
                user_card['msg'][1]['banlance'] += re_money
                user_info[1]['money'] -= re_money
        elif re_money.lower() == 'all':
            re_money = debt
            user_card['msg'][1]['banlance'] = user_card['msg'][1]['limit']
            user_info[1]['money'] -= debt
        elif re_money.lower() == 'q':
            break
        else:
            print('输入的还款金额错误!')
            continue
        temp_users[user_info[0]] = user_info[1]
        temp_cards[user_card['msg'][0]] = user_card['msg'][1]
        with open('%s\\db\\users.txt' % (BASE_DIR), 'w',
                  encoding='utf-8') as f:
            f.write(json.dumps(temp_users, ensure_ascii=False))
        with open('%s\\db\\cards.txt' % (BASE_DIR), 'w',
                  encoding='utf-8') as f:
            f.write(json.dumps(temp_cards, ensure_ascii=False))
        str = '\033[1;36;1m【%s】还款【%s】元,剩余现金【%s】元,信用卡可用额度【%s】元。\033[0m' % (
            user_info[0], re_money, user_info[1]['money'],
            user_card['msg'][1]['banlance'])
        res = {'errcode': 0, 'msg': str}
        info = '还款%d元\n' % (re_money)
        write_card_log('repay', user_info[0], info)
        break
        #print(res)
    return res
예제 #4
0
def cash(user_info):
    '''
    提现
    :return:
    '''
    res = False
    # print(user_info)
    temp_users = user.get_users()
    temp_cards = card_manage.get_cards()
    user_card = get_user_card(user_info[0])
    while True:
        print('\033[1;36;1m您现在拥有现金【%d】元,可提现额度【%d】元。\033[0m' %
              (user_info[1]['money'], user_card['msg'][1]['banlance']))
        cash_moeny = input('请输入您要提现的金额\033[1;31;1m(5%手续费哦)\033[0m:')
        if cash_moeny.isdigit(
        ) and int(cash_moeny) <= user_card['msg'][1]['banlance']:
            user_info[1]['money'] += int(cash_moeny)
            user_card['msg'][1]['banlance'] -= int(int(cash_moeny) * 1.05)
            temp_users[user_info[0]] = user_info[1]
            temp_cards[user_card['msg'][0]] = user_card['msg'][1]
            with open('%s\\db\\users.txt' % (BASE_DIR), 'w',
                      encoding='utf-8') as f:
                f.write(json.dumps(temp_users, ensure_ascii=False))
            with open('%s\\db\\cards.txt' % (BASE_DIR), 'w',
                      encoding='utf-8') as f:
                f.write(json.dumps(temp_cards, ensure_ascii=False))
            str = '\033[1;36;1m【%s】提现【%d】元,现金合计【%d】元,信用卡可用额度【%d】元\033[0m' % (
                user_info[0], int(cash_moeny), user_info[1]['money'],
                user_card['msg'][1]['banlance'])
            res = {'errcode': 0, 'msg': str}
            info = '提现%d元\n' % (int(cash_moeny))
            write_card_log('cash', user_info[0], info)
            break
        else:
            print('\033[1;31;1m提现金额输入错误\033[0m')
            continue
    return res
예제 #5
0
def shopping(user_info):
    #user_info = user.login()
    money = user_info[1]['money']
    res = card.get_user_card(user_info[0])
    money_str = '当前现金【\033[1;36;1m%d元\033[0m】' % (money)
    if res['errcode'] == 0:
        card_limit = res['msg'][1]['limit']
        card_banlance = res['msg'][1]['banlance']  #可用余额
        card_frozen = res['msg'][1]['frozen']
        if not card_frozen:
            card_str = '信用卡可用额度【\033[1;36;1m%d元\033[0m】,' % (card_banlance)
            total_card = card_banlance
        else:
            card_str = '\033[1;31;1m信用卡已冻结\033[0m'
            total_card = 0
    else:
        print(res['msg'])
    total_money = money + total_card
    banlance = total_money
    print(money_str, card_str)
    user_shopping = []
    if total_money == 0:
        print('\033[1;31;1m没钱买毛啊!\033[0m')
        return
    flag = False
    while not flag:
        product = show_product()
        #print(product)
        act = input('请选择商品(q退出并结账):')
        if act.isdigit():
            act = int(act)
            if act < product[0]:
                if total_money - product[1][act][1] < 0:
                    print('\033[1;31;1m余额不足!\033[0m')
                    continue
                else:
                    banlance = banlance - product[1][act][1]
                    user_shopping.append(product[1][act])
                    print('您将【\033[1;32;1m%s\033[0m】加入购物车。' %
                          (product[1][act][0]))
                    print(
                        '目前已消费【\033[1;36;1m%d\033[0m】元,余额【\033[1;36;1m%d\033[0m】元'
                        % (total_money - banlance, banlance))
            else:
                print('错误的编号!')
                continue
        elif act == 'q':
            flag = True
        else:
            print('错误的选择!')
            continue
    #写入记录
    if len(user_shopping) > 0:
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        shopping_list = user_shopping
        total_now = total_money - banlance
        username = user_info[0]
        if money - total_now < 0:
            money = 0
            total_card = total_card - (total_now - money)
        else:
            money = money - total_now
        str = '[shop]|{_user}|{_time}|{_list}|{_total_now}|{_money}|{_total_card}\n'.format(
            _user=username,
            _time=now,
            _list=shopping_list,
            _total_now=total_now,
            _money=money,
            _total_card=total_card)

        with open('%s\\db\\user_log.txt' % (BASE_DIR), 'a',
                  encoding='utf-8') as f:
            f.write(str)
        #写入用户记录
        temp_user = user.get_users()
        temp_user[username]['money'] = money
        with open('%s\\db\\users.txt' % (BASE_DIR), 'w',
                  encoding='utf-8') as f:
            f.write(json.dumps(temp_user, ensure_ascii=False))
        #写入信用卡记录
        temp_cards = card_manage.get_cards()
        for card_id in temp_cards:
            if temp_cards[card_id]['owner'] == username:
                temp_cards[card_id]['banlance'] = total_card
        with open('%s\\db\\cards.txt' % (BASE_DIR), 'w',
                  encoding='utf-8') as f:
            f.write(json.dumps(temp_cards, ensure_ascii=False))