def bind_creditcard(current_user): # 信用卡绑定 while True: print('\033[32;1m信用卡绑定中心\033[0m'.center(40, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) creditcard = users_dict[current_user]['creditcard'] if creditcard == 0: print('当前用户: %s' % current_user) print('信用卡绑定状态:\033[31;1m未绑定\033[0m') else: print('当前用户: %s' % current_user) print('信用卡绑定: %s' % creditcard) if_update = input('\033[34;1m是否要修改信用卡绑定 确定【Y】/返回【B】\033[0m:').strip().lower() if if_update == 'y': creditcard_new = input('\033[34;1m请输入要绑定的信用卡卡号(6位数字):\033[0m') if creditcard_new.isdigit() and len(creditcard_new) == 6: with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) # print(credit_dict.keys()) if str(creditcard_new) in credit_dict.keys(): users_dict[current_user]['creditcard'] = creditcard_new dict = json.dumps(users_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dict) print('\033[32;1m信用卡%s绑定成功!\033[0m' % creditcard_new) else: print('\033[31;1m输入的信用卡卡号不存在!\033[0m') else: print('\033[31;1m信用卡格式输入有误!\033[0m') elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def repayment(current_creditcard): # 信用卡还款 while True: print('\033[32;1m还款\033[0m'.center(40, '-')) if_repay = input('\033[34;1m是否进行还款操作 确定【Y】/返回【B】:').strip().lower() if if_repay == 'y': repay_cash = input('\033[34;1m请输入要还款的金额\033[0m:') if repay_cash.isdigit(): repay_cash = int(repay_cash) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[current_creditcard]['limit'] limit += repay_cash credit_dict[current_creditcard]['limit'] = limit dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[32;1m信用卡 %s 还款金额 ¥%s 还款成功!\033[0m' % (current_creditcard, repay_cash) print(record, '\n') creditcard_record(current_creditcard, record) else: print('\033[31;1m还款金额格式输入有误!\033[0m') elif if_repay == 'b': break else: errorlog.log('error', logging.INFO)
def update_password(current_user): # 修改登录密码 while True: print('\033[32;1m修改登录密码\033[0m'.center(40, '-')) print('当前用户:\t%s\n当前密码:\t***' % current_user) if_update = input('\033[34;0m是否要修改 %s 登录密码 确定【Y】/返回【B】:' % current_user).strip().lower() if if_update == 'y': with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) password = users_dict[current_user]['password'] old_pwd = input('\033[34;1m请输入原来的密码:\033[0m') if old_pwd == password: new_pwd = input('\033[34;1m请输入新密码:') again_new_pwd = input('\033[34;1m请再次输入新密码:') if new_pwd == again_new_pwd: users_dict[current_user]['password'] = new_pwd dict = json.dumps(users_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dict) print('\033[32;1m用户%s密码修改成功!' % current_user) else: print('\033[31;1m输入的两次密码不一致!\033[0m') else: print('\033[31;1m密码输入错误!\033[0m') elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def lock_user(): # 用户锁定模块 while True: print('\033[32;1m锁定用户\033[0m'.center(50, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: user_dict = json.load(f_users_dict) for key in user_dict: if user_dict[key]['locked'] == 0: print('\033[32;1m系统用户【%s】\t\t锁定状态:【未锁定】\033[0m' % key) else: print('\033[31;1m系统用户【%s】\t\t锁定状态:【已锁定】\033[0m' % key) if_lock = input('\033[34;1m是否要进行用户锁定 确定【Y】/返回【B】:\033[0m').strip().lower() if if_lock == 'y': will_lock_user = input('\033[34;1m输入要锁定的用户名:\033[0m') if will_lock_user in user_dict.keys(): if user_dict[will_lock_user]['locked'] == 0: user_dict[will_lock_user]['locked'] = 1 dict = json.dumps(user_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dict) print('\033[32;1m用户%s锁定成功!\033[0m' % will_lock_user) else: print('\033[31;1m此次锁定失败,用户%s之前已被锁定!\033[0m' % will_lock_user) else: print('\033[31;1m用户%s不存在!' % will_lock_user) elif if_lock == 'b': break else: errorlog.log('error', logging.INFO)
def repayment(current_creditcard): # 信用卡还款 while True: print('\033[32;1m还款\033[0m'.center(40, '-')) if_repay = input('\033[34;1m是否进行还款操作 确定【Y】/返回【B】:').strip().lower() if if_repay == 'y': repay_cash = input('\033[34;1m请输入要还款的金额\033[0m:') if repay_cash.isdigit(): repay_cash = int(repay_cash) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[current_creditcard]['limit'] limit += repay_cash credit_dict[current_creditcard]['limit'] = limit dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[32;1m信用卡 %s 还款金额 ¥%s 还款成功!\033[0m' % ( current_creditcard, repay_cash) print(record, '\n') creditcard_record(current_creditcard, record) else: print('\033[31;1m还款金额格式输入有误!\033[0m') elif if_repay == 'b': break else: errorlog.log('error', logging.INFO)
def unlock_user(): # 用户解锁模块 while True: print('\033[32;1m解锁用户\033[0m'.center(50, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: user_dict = json.load(f_users_dict) for key in user_dict: if user_dict[key]['locked'] == 0: print('\033[32;1m系统用户【%s】\t\t锁定状态:【未锁定】\033[0m' % key) else: print('\033[31;1m系统用户【%s】\t\t锁定状态:【已锁定】\033[0m' % key) if_lock = input( '\033[34;1m是否要进行用户解锁 确定【Y】/返回【B】:\033[0m').strip().lower() if if_lock == 'y': will_unlock_user = input('\033[34;1m输入要解锁的用户名:\033[0m') if will_unlock_user in user_dict.keys(): if user_dict[will_unlock_user]['locked'] == 1: user_dict[will_unlock_user]['locked'] = 0 dict = json.dumps(user_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dict) print('\033[32;1m用户%s解锁成功!\033[0m' % will_unlock_user) else: print('\033[31;1m此次解锁失败,用户%s此前并未锁定!\033[0m' % will_unlock_user) else: print('\033[31;1m用户%s不存在!' % will_unlock_user) elif if_lock == 'b': break else: errorlog.log('error', logging.INFO)
def user_create(address='None', locked=0, creditcard=0): # 创建用户 while True: print('开始创建用户'.center(50, '-')) with open(settings._db_users_dict, 'r+')as f_user_dict: users_dict = json.load(f_user_dict) for key in users_dict: print('系统已有用户【%s】' % key) if_creat = input('\033[34;1m是否要创建新用户 确定【Y】/返回【B】:\033[0m').strip().lower() if if_creat == 'y': username = input('\033[34;1m请输入要添加的账户的用户名:\033[0m') password = input('\033[34;1m请输入要添加的账户的密码:\033[0m') if username not in users_dict.keys(): if len(username.strip()) > 0: if len(password.strip()) > 0: users_dict[username] = {"username": username, "password": password, "creditcard": creditcard , "address": address, "locked": locked} dict = json.dumps(users_dict) f_user_dict.seek(0) f_user_dict.truncate(0) f_user_dict.write(dict) print('\033[32;1m创建用户%s成功!\033[0m' % username) else: print('\033[31;1m密码输入为空,请重新输入!\033[0m') else: print('\033[31;1m用户名输入格式有误,请重新输入!\033[0m') else: print('\033[31;1m用户%s已经存在!\033[0m') elif if_creat == 'b': break else: errorlog.log('error', logging.INFO)
def unlock_creditcard(): # 解冻信用卡模块 while True: print('\033[32;1m解冻信用卡\033[0m'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: if credit_dict[key]['locked'] == 0: print('\033[32;1m信用卡账户【%s】\t\t冻结状态:【未冻结】' % key) else: print('\033[31;1m信用卡账户【%s】\t\t冻结状态:【已冻结】' % key) if_lock = input('\033[34;1m是否要进行信用卡冻结 确定【Y】/返回【B】:\033[0m').strip().lower() if if_lock == 'y': will_lock_credit = input('\033[34;1m输入要解冻的信用卡账号:\033[0m') if will_lock_credit in credit_dict.keys(): if credit_dict[will_lock_credit]['locked'] == 1: credit_dict[will_lock_credit]['locked'] = 0 dic = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dic) print('\033[32;1m信用卡账号%s解冻成功\033[0m' % will_lock_credit) else: print('\033[31;1m信用卡账号%s解冻失败,该账号此前未被冻结!\033[0m' % will_lock_credit) else: print('\033[31;1m信用卡账号%s不存在!' % will_lock_credit) elif if_lock == 'b': break else: errorlog.log('error', logging.INFO)
def unlock_creditcard(): # 解冻信用卡模块 while True: print('\033[32;1m解冻信用卡\033[0m'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: if credit_dict[key]['locked'] == 0: print('\033[32;1m信用卡账户【%s】\t\t冻结状态:【未冻结】' % key) else: print('\033[31;1m信用卡账户【%s】\t\t冻结状态:【已冻结】' % key) if_lock = input( '\033[34;1m是否要进行信用卡冻结 确定【Y】/返回【B】:\033[0m').strip().lower() if if_lock == 'y': will_lock_credit = input('\033[34;1m输入要解冻的信用卡账号:\033[0m') if will_lock_credit in credit_dict.keys(): if credit_dict[will_lock_credit]['locked'] == 1: credit_dict[will_lock_credit]['locked'] = 0 dic = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dic) print('\033[32;1m信用卡账号%s解冻成功\033[0m' % will_lock_credit) else: print('\033[31;1m信用卡账号%s解冻失败,该账号此前未被冻结!\033[0m' % will_lock_credit) else: print('\033[31;1m信用卡账号%s不存在!' % will_lock_credit) elif if_lock == 'b': break else: errorlog.log('error', logging.INFO)
def transfer(current_creditcard): # 信用卡转账 while True: print('\033[32;1m转账\033[0m'.center(40, '-')) if_trans = input( '\033[34;1m 是否进行转账 确定【Y】/返回【B】:\033[0m').strip().lower() if if_trans == 'y': with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) current_limit = credit_dict[current_creditcard]['limit'] transfer_creditcard = input('\033[34;1m输入要转账的银行卡卡号:\033[0m') if transfer_creditcard.isdigit(): if len(transfer_creditcard) == 6: if transfer_creditcard in credit_dict.keys(): again_credit = input('\033[34;1m请再次确认转账的银行卡卡号:') if again_credit == transfer_creditcard: transfer_cash = input('\033[34;1m请输入要转账的金额:') if transfer_cash.isdigit(): transfer_cash = int(transfer_cash) if transfer_cash <= current_limit: credit_dict[current_creditcard][ 'limit'] -= transfer_cash credit_dict[transfer_creditcard][ 'limit'] += transfer_cash dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[32;1m转账卡号 %s 金额 ¥%s 转账成功!\033[0m' % \ (transfer_creditcard, transfer_cash) print(record, '\n') creditcard_record( current_creditcard, record) else: print('\033[31;1m 余额不足 转账失败!\033[0m') else: print('\033[31;1m输入金额有误!\033[0m') else: print('\033[31;1m两次输入的银行卡卡号不一致!\033[0m') else: print('\033[31;1m您输入的银行卡卡号不存在!\033[0m') else: print('\033[31;1m输入的银行卡卡号有误!\033[0m') else: print('\033[31;1m输入的银行卡卡号有误!\033[0m') elif if_trans == 'b': break else: errorlog.log('error', logging.INFO)
def pay_shopping(current_user): # 支付模块 while True: sum_money = 0 print('\033[32;1m购物结算\033[0m'.center(40, '-')) with open(settings._db_shopping_car, 'r+') as f_shopping_car: shopping_dict = json.load(f_shopping_car) for item in shopping_dict: sum_money += int(item[1]) if_pay = input('\033[34;1m当前商品总额:%s 是否进行支付 确定【Y】/返回【B】:\033[0m' % sum_money).strip().lower() if if_pay == 'y': with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) creditcard = users_dict[current_user]['creditcard'] if creditcard == 0: print('\033[31;1m账号 %s还未绑定信用卡,请到个人中心进行信用卡绑定\033[0m' % current_user) else: with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[creditcard]['limit'] limit_new = limit - sum_money if limit_new >= 0: res = auth_creditcard(creditcard) if res == True: credit_dict[creditcard][ 'limit'] = limit_new dic = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dic) value = '购物支付 %s' % (sum_money) print('\033[32;1m支付成功,当前余额 ¥%s\033[0m' % limit_new) shoppingcar_record(current_user, shopping_dict) creditcard_record(creditcard, value) empty_shopping_car() else: print( '\033[31;1m当前信用卡额度 %s 不足以支付当前账单,可选择绑定其他信用卡进行支付!' % limit_new) elif if_pay == 'b': break else: errorlog.log('error', logging.INFO)
def creditcard_create(limit=15000, locked=0): # 信用卡发放模块 while True: print('进行信用卡发放'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: print("系统已有信用卡【%s】 \t 持卡人【%s】" % (key, credit_dict[key]['personinfo'])) if_credit = input( '\033[34;1m是否发放新的信用卡 确定【Y】/返回【B】:\033[0m').strip().lower() if if_credit == 'y': credit_card = input( '\033[34;1m请输入将要发放的信用卡的卡号(6位数字):\033[0m').strip() if credit_card not in credit_dict.keys(): if credit_card.isdigit() and len(credit_card) == 6: password = input('\033[34;1m请为要发放的信用卡账号设置密码:\033[0m') if len(password.strip()) > 0: personinfo = input( '\033[34;1m请输入要发放的信用卡申请人的名字:\033[0m') if len(personinfo.strip()) > 0: credit_dict[credit_card] = { "personinfo": personinfo, "password": password, 'limit': limit, 'locked': locked, 'limitcash': limit // 2, 'deflimit': limit, 'creditcard': credit_card } dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) print('\033[32;1m信用卡%s发放成功,额度%s!\033[0m' % (credit_card, limit)) else: print('\033[31;1m申请人姓名输入为空!\033[0m') else: print('\033[31;1m账号密码输入为空!\033[0m') else: print('\033[31;1m信用卡%s输入格式有误!\033[0m' % credit_card) else: print('\033[31;1m信用卡%s已经存在!' % credit_card) elif if_credit == 'b': break else: errorlog.log('error', logging.INFO)
def transfer(current_creditcard): # 信用卡转账 while True: print('\033[32;1m转账\033[0m'.center(40, '-')) if_trans = input('\033[34;1m 是否进行转账 确定【Y】/返回【B】:\033[0m').strip().lower() if if_trans == 'y': with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) current_limit = credit_dict[current_creditcard]['limit'] transfer_creditcard = input('\033[34;1m输入要转账的银行卡卡号:\033[0m') if transfer_creditcard.isdigit(): if len(transfer_creditcard) == 6: if transfer_creditcard in credit_dict.keys(): again_credit = input('\033[34;1m请再次确认转账的银行卡卡号:') if again_credit == transfer_creditcard: transfer_cash = input('\033[34;1m请输入要转账的金额:') if transfer_cash.isdigit(): transfer_cash = int(transfer_cash) if transfer_cash <= current_limit: credit_dict[current_creditcard]['limit'] -= transfer_cash credit_dict[transfer_creditcard]['limit'] += transfer_cash dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[32;1m转账卡号 %s 金额 ¥%s 转账成功!\033[0m' % \ (transfer_creditcard, transfer_cash) print(record, '\n') creditcard_record(current_creditcard, record) else: print('\033[31;1m 余额不足 转账失败!\033[0m') else: print('\033[31;1m输入金额有误!\033[0m') else: print('\033[31;1m两次输入的银行卡卡号不一致!\033[0m') else: print('\033[31;1m您输入的银行卡卡号不存在!\033[0m') else: print('\033[31;1m输入的银行卡卡号有误!\033[0m') else: print('\033[31;1m输入的银行卡卡号有误!\033[0m') elif if_trans == 'b': break else: errorlog.log('error', logging.INFO)
def update_limit(): # 修改信用卡额度 while True: print('\033[31;1m修改信用卡额度\033[0m'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: limitcash = credit_dict[key]['limitcash'] print('信用卡【%s】\t目前可用额度:【¥%s】\t取现额度:【¥%s】' % (key, credit_dict[key]['limit'], limitcash)) if_update = input( '\033[34;1m是否进行信用卡额度调整 确定【Y】/返回【B】:\033[0m').strip().lower() if if_update == 'y': creditcard = input('\033[34;1m输入要修改的信用卡的卡号:\033[1m').strip() if creditcard in credit_dict.keys(): limit_cash = input('\033[34;1m输入额度修改后的金额(至少5000¥):\033[1m') if limit_cash.isdigit(): limit_default = credit_dict[creditcard]['limit'] limit_cash = int(limit_cash) if limit_cash >= 5000: update = limit_cash - limit_default credit_dict[creditcard][ 'limitcash'] += update // 2 # 取现额度调整 credit_dict[creditcard][ 'limit'] += update # 可用额度调整 credit_dict[creditcard][ 'deflimit'] = limit_cash # 信用卡原本的默认额度 dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) print('\033[32;1m信用卡%s额度修改成功!\033[0m' % creditcard) else: print('\033[31;1m输入金额 ¥%s 小于¥5000\033[0m' % limit_cash) else: print('\033[31;1m输入金额 ¥%s 格式有误\033[0m' % limit_cash) else: print('\033[31;1m信用卡【%s】不存在\033[0m' % creditcard) elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def cash_advance(current_creditcard): # 提现操作(传入的值是当前操作的信用卡账号) while True: print('\033[32;1m提现\033[0m'.center(40, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[current_creditcard]['limit'] limitcash = credit_dict[current_creditcard]['limitcash'] print('信用卡号:\t【%s】\n提现额度:\t【¥%s】' % (current_creditcard, limitcash)) details_tip() if_cash = input( '\033[34;1m是否进行提现 确定【Y】/返回【B】:\033[0m').strip().lower() if if_cash == 'y': cash = input('\033[34;1m输入要提现的金额 收取%5手续费\033[0m:') if cash.isdigit(): cash = int(cash) if cash != 0: if cash <= limitcash: limitcash -= int(cash * 1.05) limit -= int(cash * 1.05) credit_dict[current_creditcard]['limit'] = limit credit_dict[current_creditcard][ 'limitcash'] = limitcash dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[31;1m提现¥%s手续费¥%s\033[0m' % ( cash, int(cash * 0.05)) print(record, '\n') creditcard_record(current_creditcard, record) else: print('\033[31;1m超出信用卡提现额度!\033[0m') else: print('\033[31;1m提现额度不能为空!\033[0m') else: print('\033[31;1m格式输入有误!\033[0m') elif if_cash == 'b': break else: errorlog.log('error', logging.INFO)
def update_address(current_user): # 修改个人资料中收货地址信息 while True: print('\033[32;1m修改个人资料\033[0m'.center(40, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) address = users_dict[current_user]['address'] print('当前用户:\t%s\n当前收货地址:\t%s\n' % (current_user, address)) if_update = input('\033[34;1m是否要修改用户%s的收货地址 确定【Y】/返回【B】:').strip().lower() if if_update == 'y': address_new = input('\033[34;0m输入新的收货地址:\033[0m') users_dict[current_user]['address'] = address_new dic = json.dumps(users_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dic) print('\033[32;1m用户%s的收货地址修改成功!' % current_user) elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def pay_shopping(current_user): # 支付模块 while True: sum_money = 0 print('\033[32;1m购物结算\033[0m'.center(40, '-')) with open(settings._db_shopping_car, 'r+') as f_shopping_car: shopping_dict = json.load(f_shopping_car) for item in shopping_dict: sum_money += int(item[1]) if_pay = input('\033[34;1m当前商品总额:%s 是否进行支付 确定【Y】/返回【B】:\033[0m' % sum_money).strip().lower() if if_pay == 'y': with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) creditcard = users_dict[current_user]['creditcard'] if creditcard == 0: print('\033[31;1m账号 %s还未绑定信用卡,请到个人中心进行信用卡绑定\033[0m' % current_user) else: with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[creditcard]['limit'] limit_new = limit - sum_money if limit_new >= 0: res = auth_creditcard(creditcard) if res == True: credit_dict[creditcard]['limit'] = limit_new dic = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dic) value = '购物支付 %s' % (sum_money) print('\033[32;1m支付成功,当前余额 ¥%s\033[0m' % limit_new) shoppingcar_record(current_user, shopping_dict) creditcard_record(creditcard, value) empty_shopping_car() else: print('\033[31;1m当前信用卡额度 %s 不足以支付当前账单,可选择绑定其他信用卡进行支付!' % limit_new) elif if_pay == 'b': break else: errorlog.log('error', logging.INFO)
def update_address(current_user): # 修改个人资料中收货地址信息 while True: print('\033[32;1m修改个人资料\033[0m'.center(40, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) address = users_dict[current_user]['address'] print('当前用户:\t%s\n当前收货地址:\t%s\n' % (current_user, address)) if_update = input( '\033[34;1m是否要修改用户%s的收货地址 确定【Y】/返回【B】:').strip().lower() if if_update == 'y': address_new = input('\033[34;0m输入新的收货地址:\033[0m') users_dict[current_user]['address'] = address_new dic = json.dumps(users_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dic) print('\033[32;1m用户%s的收货地址修改成功!' % current_user) elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def bind_creditcard(current_user): # 信用卡绑定 while True: print('\033[32;1m信用卡绑定中心\033[0m'.center(40, '-')) with open(settings._db_users_dict, 'r+') as f_users_dict: users_dict = json.load(f_users_dict) creditcard = users_dict[current_user]['creditcard'] if creditcard == 0: print('当前用户: %s' % current_user) print('信用卡绑定状态:\033[31;1m未绑定\033[0m') else: print('当前用户: %s' % current_user) print('信用卡绑定: %s' % creditcard) if_update = input( '\033[34;1m是否要修改信用卡绑定 确定【Y】/返回【B】\033[0m:').strip().lower() if if_update == 'y': creditcard_new = input('\033[34;1m请输入要绑定的信用卡卡号(6位数字):\033[0m') if creditcard_new.isdigit() and len(creditcard_new) == 6: with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) # print(credit_dict.keys()) if str(creditcard_new) in credit_dict.keys(): users_dict[current_user][ 'creditcard'] = creditcard_new dict = json.dumps(users_dict) f_users_dict.seek(0) f_users_dict.truncate(0) f_users_dict.write(dict) print('\033[32;1m信用卡%s绑定成功!\033[0m' % creditcard_new) else: print('\033[31;1m输入的信用卡卡号不存在!\033[0m') else: print('\033[31;1m信用卡格式输入有误!\033[0m') elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def update_limit(): # 修改信用卡额度 while True: print('\033[31;1m修改信用卡额度\033[0m'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: limitcash = credit_dict[key]['limitcash'] print('信用卡【%s】\t目前可用额度:【¥%s】\t取现额度:【¥%s】' % (key, credit_dict[key]['limit'], limitcash)) if_update = input('\033[34;1m是否进行信用卡额度调整 确定【Y】/返回【B】:\033[0m').strip().lower() if if_update == 'y': creditcard = input('\033[34;1m输入要修改的信用卡的卡号:\033[1m').strip() if creditcard in credit_dict.keys(): limit_cash = input('\033[34;1m输入额度修改后的金额(至少5000¥):\033[1m') if limit_cash.isdigit(): limit_default = credit_dict[creditcard]['limit'] limit_cash = int(limit_cash) if limit_cash >= 5000: update = limit_cash - limit_default credit_dict[creditcard]['limitcash'] += update//2 # 取现额度调整 credit_dict[creditcard]['limit'] += update # 可用额度调整 credit_dict[creditcard]['deflimit'] = limit_cash # 信用卡原本的默认额度 dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) print('\033[32;1m信用卡%s额度修改成功!\033[0m' % creditcard) else: print('\033[31;1m输入金额 ¥%s 小于¥5000\033[0m' % limit_cash) else: print('\033[31;1m输入金额 ¥%s 格式有误\033[0m' % limit_cash) else: print('\033[31;1m信用卡【%s】不存在\033[0m' % creditcard) elif if_update == 'b': break else: errorlog.log('error', logging.INFO)
def user_create(address='None', locked=0, creditcard=0): # 创建用户 while True: print('开始创建用户'.center(50, '-')) with open(settings._db_users_dict, 'r+') as f_user_dict: users_dict = json.load(f_user_dict) for key in users_dict: print('系统已有用户【%s】' % key) if_creat = input( '\033[34;1m是否要创建新用户 确定【Y】/返回【B】:\033[0m').strip().lower() if if_creat == 'y': username = input('\033[34;1m请输入要添加的账户的用户名:\033[0m') password = input('\033[34;1m请输入要添加的账户的密码:\033[0m') if username not in users_dict.keys(): if len(username.strip()) > 0: if len(password.strip()) > 0: users_dict[username] = { "username": username, "password": password, "creditcard": creditcard, "address": address, "locked": locked } dict = json.dumps(users_dict) f_user_dict.seek(0) f_user_dict.truncate(0) f_user_dict.write(dict) print('\033[32;1m创建用户%s成功!\033[0m' % username) else: print('\033[31;1m密码输入为空,请重新输入!\033[0m') else: print('\033[31;1m用户名输入格式有误,请重新输入!\033[0m') else: print('\033[31;1m用户%s已经存在!\033[0m') elif if_creat == 'b': break else: errorlog.log('error', logging.INFO)
def cash_advance(current_creditcard): # 提现操作(传入的值是当前操作的信用卡账号) while True: print('\033[32;1m提现\033[0m'.center(40, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) limit = credit_dict[current_creditcard]['limit'] limitcash = credit_dict[current_creditcard]['limitcash'] print('信用卡号:\t【%s】\n提现额度:\t【¥%s】' % (current_creditcard, limitcash)) details_tip() if_cash = input('\033[34;1m是否进行提现 确定【Y】/返回【B】:\033[0m').strip().lower() if if_cash == 'y': cash = input('\033[34;1m输入要提现的金额 收取%5手续费\033[0m:') if cash.isdigit(): cash = int(cash) if cash != 0: if cash <= limitcash: limitcash -= int(cash*1.05) limit -= int(cash*1.05) credit_dict[current_creditcard]['limit'] = limit credit_dict[current_creditcard]['limitcash'] = limitcash dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) record = '\033[31;1m提现¥%s手续费¥%s\033[0m' % (cash, int(cash*0.05)) print(record, '\n') creditcard_record(current_creditcard, record) else: print('\033[31;1m超出信用卡提现额度!\033[0m') else: print('\033[31;1m提现额度不能为空!\033[0m') else: print('\033[31;1m格式输入有误!\033[0m') elif if_cash == 'b': break else: errorlog.log('error', logging.INFO)
def creditcard_create(limit=15000, locked=0): # 信用卡发放模块 while True: print('进行信用卡发放'.center(50, '-')) with open(settings._db_credit_dict, 'r+') as f_credit_dict: credit_dict = json.load(f_credit_dict) for key in credit_dict: print("系统已有信用卡【%s】 \t 持卡人【%s】" % (key, credit_dict[key]['personinfo'])) if_credit = input('\033[34;1m是否发放新的信用卡 确定【Y】/返回【B】:\033[0m').strip().lower() if if_credit == 'y': credit_card = input('\033[34;1m请输入将要发放的信用卡的卡号(6位数字):\033[0m').strip() if credit_card not in credit_dict.keys(): if credit_card.isdigit() and len(credit_card) == 6: password = input('\033[34;1m请为要发放的信用卡账号设置密码:\033[0m') if len(password.strip())>0: personinfo = input('\033[34;1m请输入要发放的信用卡申请人的名字:\033[0m') if len(personinfo.strip()) > 0: credit_dict[credit_card] = {"personinfo": personinfo, "password": password, 'limit': limit, 'locked': locked, 'limitcash': limit//2, 'deflimit': limit, 'creditcard':credit_card} dict = json.dumps(credit_dict) f_credit_dict.seek(0) f_credit_dict.truncate(0) f_credit_dict.write(dict) print('\033[32;1m信用卡%s发放成功,额度%s!\033[0m' % (credit_card, limit)) else: print('\033[31;1m申请人姓名输入为空!\033[0m') else: print('\033[31;1m账号密码输入为空!\033[0m') else: print('\033[31;1m信用卡%s输入格式有误!\033[0m'% credit_card) else: print('\033[31;1m信用卡%s已经存在!'% credit_card) elif if_credit == 'b': break else: errorlog.log('error', logging.INFO)
'3. 修改个人信息\n' '4. 修改银行卡绑定\n' 'b. 返回\n') choice_id = input('\033[34;1m选择要进入模式的ID:\033[0m').strip().lower() if choice_id == '1': shopping.cat_shopping_record(current_user) elif choice_id == '2': shopping.update_password(current_user) elif choice_id == '3': shopping.update_address(current_user) elif choice_id == '4': shopping.bind_creditcard(current_user) elif choice_id == 'b': break else: errorlog.log('error', logging.INFO) # print('\033[31;1m无效的输入!\033[0m') elif choice_id == 'b': break else: errorlog.log('error', logging.INFO) # print('\033[31;1m无效的输入!\033[0m') elif choice_id == '2': res = authentication.credit_auth() if res: if res[0] == True: current_creditcard = res[1] while True: print('\033[36;1m信用卡中心\033[0m'.center(50, '='), '\n1. 我的信用卡\n' '2. 提现\n'
'4. 修改银行卡绑定\n' 'b. 返回\n') choice_id = input('\033[34;1m选择要进入模式的ID:\033[0m' ).strip().lower() if choice_id == '1': shopping.cat_shopping_record(current_user) elif choice_id == '2': shopping.update_password(current_user) elif choice_id == '3': shopping.update_address(current_user) elif choice_id == '4': shopping.bind_creditcard(current_user) elif choice_id == 'b': break else: errorlog.log('error', logging.INFO) # print('\033[31;1m无效的输入!\033[0m') elif choice_id == 'b': break else: errorlog.log('error', logging.INFO) # print('\033[31;1m无效的输入!\033[0m') elif choice_id == '2': res = authentication.credit_auth() if res: if res[0] == True: current_creditcard = res[1] while True: print( '\033[36;1m信用卡中心\033[0m'.center(50, '='), '\n1. 我的信用卡\n'