def pay(name, money): # 商城调用信用卡 f = file_opt.File_Option() # print(f.file_read().get(name)[3]) # 卡号 date = f.file_read() card_num = date.get(name)[3] if card_num: info = file_option.read() yue = info.get(card_num)[8] if yue >= money: info[card_num][8] -= money # print(info) file_option.write(json.dumps(info)) log_opt.info(name + ': quick pay success') bill_opt.info( card_num, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' 商城消费:' + str(money)) print('扣款成功') return 'ok' else: log_opt.info(name + ': quick pay error') print('信用卡余额不足。') else: print('暂未绑定任何信用卡。')
def transafe(card_num): # 转账 num = input('请输入要转账的卡号:').strip() if card_num == num: print('给自己转账干毛啊。。。') else: date = file_option.read() print('余额为:', date.get(card_num)[8]) if date.get(num): print('对方姓名为*', date.get(num)[2][-1]) print('确认转账?y/n') c = input(':').strip() if c == 'y': money = input('输入金额').strip() if money.isdigit(): money = int(money) if money < date.get(card_num)[8]: date[card_num][8] -= money date[num][8] += money file_option.write(json.dumps(date)) log_opt.info(card_num + ': transafe ' + num + ' ' + str(money)) bill_opt.info( card_num, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' 转出:' + str(money)) print('转账成功,余额为:', date[card_num][8]) else: print('没有那么多钱了。') else: print('输入有误。') else: print('卡号不存在')
def bind(name): # 商城绑定信用卡 f = file_opt.File_Option() date = f.file_read() if date.get(name)[3] == 0: card_num = atm_login.login() if card_num: date[name][3] = card_num f.file_write(date) log_opt.info(name + ':bind' + card_num) print('绑定成功。') else: print('已绑定信用卡:', date.get(name)[3])
def manage(): # 管理ATM 账号:admin 密码:admin name = input('name').strip() pwd = input('pwd').strip() if name == 'admin' and pwd == 'admin': log_opt.info('admin :login success') while True: print('现有用用户列表') date = file_option.read() for i in date.keys(): print(i) print('b返回首页') user_num = input('输入要操作的账号:').strip() if user_num in date.keys(): print('1、调整用户额度2、冻结/解冻用户') cho = input().strip() if cho == '1': print('当前额度为:', date.get(user_num)[7]) o = input('调整为:').strip() if o.isdigit(): o = int(o) date[user_num][7] = o file_option.write(json.dumps(date)) log_opt.info(user_num + ': quota set:' + str(o)) print(user_num, '的额度调整为', o) else: print('输入有误。') elif cho == '2': print('1,冻结,2,解冻') c = input().strip() if c == '1': date[user_num][4] = 1 file_option.write(json.dumps(date)) log_opt.info(user_num + ': lock') print(user_num, '已冻结') elif c == '2': date[user_num][4] = 0 file_option.write(json.dumps(date)) log_opt.info(user_num + ': unlock') print(user_num, '已解冻') else: print('输入有误。') else: print('输入有误') else: if user_num == 'b': break else: print('卡号不存在。') else: print('用户名或密码错误')
def withdrowal(card_num): # 取现 o = 0 info = file_option.read() m = info[card_num][8] i = info[card_num][7] if m >= i / 2: o = m - i / 2 else: o = m print('当前可用额度:', m, '可取现额度:', o) print('信用卡取款收取取款金额的5%手续费。') print('最小取款金额为1元') p = input('输入取款金额:').strip() if p.isdigit(): p = int(p) if p <= o: x = p * 0.05 print('取现手续费', x, '直接从余额中扣除') if x < (m - p): info[card_num][8] -= p info[card_num][8] -= x log_opt.info(card_num + ': withdrowal ' + str(p)) file_option.write(json.dumps(info)) bill_opt.info( card_num, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' 取现:' + str(p)) bill_opt.info( card_num, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' 取现手续费:' + str(x)) print('取款成功。') else: print('取款数额太大,余额不足以支付手续费') else: print('没有那么取现额度了,我的哥。') else: print('输入错误。')
def repay(card_num): # 存款/还款 date = file_option.read() if date.get(card_num): m = input('输入金额:').strip() if m.isdigit(): m = int(m) if m > 0: date[card_num][8] += m file_option.write(json.dumps(date)) log_opt.info(card_num + ': repay ' + str(m)) bill_opt.info( card_num, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' 还款:' + str(m)) print('存款成功,当前可用余额:人民币', date[card_num][8], '元') else: print('别闹,好好的。') else: print('别闹,好好的。') else: print('账户不存在。')
def login(): # ATM登陆 card = input('卡号:').strip() pwd = input('密码:').strip() status = '' f = file_option.read() user_info = f.get(card) if user_info: # 判断用户名是否存在 if user_info[4] == 1: # 判断锁定状态 print('账户被锁定。') else: if user_info[0] == '': # 如果没有密码,则为新注册用户,进入激活程序 while True: print('信用卡未激活') print('b: 返回') time.sleep(1) print('激活信用卡'.center(40,'-')) name = input('请输入申请信用卡时填写的姓名:').strip() if name == user_info[2]: passwd = input('请输入6位数字密码:').strip() if passwd.isdigit() and len(passwd) == 6: user_info[0] = passwd file_option.write(json.dumps(f)) log_opt.info(card + ': active success') print('激活成功。') break else: print('请按格式输入。') elif name == 'b': break else: print('请输入申请信用卡时对应的用户名。') elif user_info[1] < 3: if pwd == user_info[0]: # 判断密码 user_info[1] = 0 # 登陆成功,清空密码错误统计 f[card] = user_info file_option.write(json.dumps(f)) log_opt.info(card + ': login success') print(card + '登陆成功') status = card else: # 密码错误,将用户信息文件中登陆错误次数+1 user_info[1] += 1 f[card] = user_info file_option.write(json.dumps(f)) log_opt.info(card+ ': pwd error') print('密码错误') else: print('因密码输入错误次数太多,账户已被暂停使用。') else: print('卡号不存在') return status
def apply(): card_info = {} USER_INFO = [] pwd = '' lock = 0 bill_date = '19' repayment_date = '10' while True: m = 30 b = 100 print('欢迎申请中国人民很行信用卡,请填写相关资料,我行审核通过后将给您核发信用卡。') name = input('name').strip() if name == '': print('请输入姓名。') continue age = input('age').strip() if age == '': print('请输入年龄。') continue elif age.isdigit(): age = int(age) if age > 60 or age < 18: print('您的年龄无法申请信用卡。') break else: print('请输入正确的年龄。') continue job = input('请选择您的工作:1、实习生 2、工地民工 3、运维工程师 4、开发工程师 5、行政 6、其他').strip() if job == '': print('请选择职业。') continue if job.isdigit(): job = int(job) if job == 3: m *= 6 b *= 6 elif job == 4: m *= 8 b *= 8 elif job == 1 or job == 2 or job == 5: m *= 4 b *= 4 if age < 25: limit = random.randint(m * 30, m * 40 * 2) elif age >= 25 and age <= 35: limit = random.randint(m * 40, m * 50 * 2) elif age > 35 and age <= 60: limit = random.randint(40000, 50000) # num = file_option.card_num() num = json.loads(num) + 1 num = json.dumps(num) # print(num, type(num)) # USER_INFO.append(num) # 卡号 USER_INFO.append(pwd) # 密码 USER_INFO.append(0) # 密码错误次数 USER_INFO.append(name) # 姓名 USER_INFO.append(age) # 年龄 USER_INFO.append(lock) # 锁定状态 USER_INFO.append(bill_date) # 账单日 USER_INFO.append(repayment_date) # 还款日 USER_INFO.append(limit) # 额度 USER_INFO.append(limit) # 余额 # USER_INFO = json.dumps(USER_INFO) card_info = file_option.read() card_info[num] = USER_INFO card_info = json.dumps(card_info) file_option.write(card_info, num) bill_path = os.path.join(paa, 'db', 'atm', 'bill', num, 'tmp') # 创建账户对应的账单文件夹 os.makedirs(bill_path) log_opt.info(num + ': card application success') # 记录日志 print(name, '信用卡申请成功,您的信用卡额度为{}'.format(limit)) print( '您的卡号为', num, ) print('账单日', bill_date, '还款日', repayment_date) print('请牢记个人信息,并及时还款。') return USER_INFO