• bin目录:程序启动入口

ATM_start.py:

 #!/usr/bin/python
# -*- coding: utf-8 -*-
# 模拟ATM电子银行+登录账户权限控制+管理员管理模块
# 本程序可以在windows下运行基于python2.7.8版本开发
# 管理员账号:admin 密码:123123
# python04_homework
# __author__:Mr.chen
# 程序启动入口 import sys
sys.path.append('..')
from src import user_business user_business.Main()
  • crontab目录:定时任务触发入口

Auto_mission.py

 #!/usr/bin/python
# -*- coding: utf-8 -*-
# 计划任务定时触发启动文件 import sys
sys.path.append('..')
from lib import common common.Traverse_folder()
  • lib目录:公共类文件

common.py

 #!/usr/bin/python
# -*- coding: utf-8 -*-
# 公共方法层 import os,time,random,pickle DIR = os.path.dirname(__file__)
DIR = DIR.replace('lib','db/') TAG = True #循环控制标志 def Exit():
'''
系统退出
:return:None
'''
print ('程序退出!')
exit() def MD5(password):
'''
加密函数
:param firstsite: 密码字符串
:return: 加密字符串
'''
import hashlib
return hashlib.md5(password).hexdigest() def Verification_input():
'''
登录验证码校验
:return: True
'''
while TAG:
re = Verification_Code()
code = raw_input('请输入括号里的验证码,不区分大小写({0}):'.format(re))
if code.strip().lower() != re.lower():
print('您输入的验证码有误,请重新输入!')
else:
return True def Verification_Code():
'''
生成随机的6位验证码:大小写字母数字的组合
:return: 验证码
'''
code = ''
b = random.randrange(0, 5)
c = random.randrange(0, 5)
for i in range(6):
if i == b:
a = random.randrange(1, 9)
code = code + str(a)
else:
a = random.randrange(65, 90)
if i == c:
code = code + chr(a).lower()
else:
code = code + chr(a)
return code def pwd_money_check(user):
'''
用户银行卡密码登录验证
:return: True or False
'''
while TAG:
pwd = raw_input('请输入6位银行卡密码:')
if pwd.isdigit() and len(pwd) == 6:
pwd_money = log_info_specific_read(user, 'pwd_money')
if pwd_money == False:
print ('用户日志不存在!')
return False
else:
if MD5(pwd) == pwd_money:
print ('密码验证成功!')
return True
else:
return False
else:
print ('您的输入有误!') ###########################前台请求输入方法组################################################################## def name_login_input():
'''
键盘输入登录名
:return:新用户名
'''
while TAG:
name_login = raw_input('请输入登陆用户的用户名(n=返回上级菜单):')
if name_login == 'n':
return
elif os.path.exists('db/'+name_login+'_log'):
print('你输入的用户名已存在,请重新输入!')
elif len(name_login) != len(name_login.strip()) or len(name_login.strip().split()) != 1:
print('登录名不能为空,且不能有空格,请重新输入!')
else:
return name_login def pwd_login_input():
'''
键盘输入登录密码
:return:新登录密码
'''
while TAG:
pwd_login = raw_input('请输入登陆密码(n=返回上级菜单):')
if pwd_login == 'n':
return
elif len(pwd_login) < 8:
print('您输入的密码不能小于8位数(8位以上字母数字+至少一位大写字母组合),请重新输入!')
elif len(pwd_login.strip().split()) != 1:
print('您输入的密码不能有空格,密码也不能为空,请重新输入!')
elif pwd_login.isdigit():
print('密码不能全为数字(8位以上字母数字+至少一位大写字母组合),请重新输入!')
elif pwd_login.lower() == pwd_login:
print('请至少保留一位的大写字母(8位以上字母数字+至少一位大写字母组合),请重新输入!')
else:
pwd_login = MD5(pwd_login)
return pwd_login def account_input():
'''
键盘输入银行卡号
:return: 新银行卡号
'''
while TAG:
account = raw_input('请输入银行卡号(如果没有可以为空)(n=返回上级菜单):')
if account.strip() == '':
account = 'empty'
return account
elif account == 'n':
return
elif len(account.strip()) < 16:
print('银行卡号是不能小于16位的纯数字,请重新输入!')
elif account.isdigit() != True:
print('银行卡号是不能小于16位的纯数字,请重新输入!')
else:
return account def pwd_money_input():
'''
键盘输入银行卡密码
:return: 新银行卡密码
'''
while TAG:
pwd_money = raw_input('请输入银行卡的6位数字取款(转账)密码(n=返回上级菜单):')
if pwd_money == 'n':
return
elif len(pwd_money.strip()) != 6:
print('取款密码只能是6位纯数字,请重新输入!')
elif pwd_money.strip().isdigit() != True:
print('取款密码只能是6位纯数字,请重新输入!')
else:
pwd_money = MD5(pwd_money)
return pwd_money ##################################数据读取写入方法组#################################################################### def log_info_read(user):
'''
指定用户日志文件全部读取
:param user:用户名
:return:dict字典
如果无文件返回False
'''
if os.path.exists(DIR+user+'_log'):
with open(DIR+user+'_log','r') as f:
dict = pickle.load(f)
return dict
else:
return False def log_info_specific_read(user,text):
'''
指定用户日志文件指定内容读取
:param user: 用户名
:param text: 预读取的字段名
:return: 指定的字段内容
如果无文件返回False
'''
if os.path.exists(DIR+user+'_log'):
with open(DIR+user+'_log','r') as f:
dict = pickle.load(f)
re = dict[text]
return re
else:
return False def log_info_write(user,dict = None):
'''
指定用户日志文件全部写入
:param user:用户名
:param dict: 日志字典
:return: True or False
'''
#if os.path.exists(user+'_log'):
#print (DIR+user+'_log')
with open(DIR+user+'_log','w') as f:
pickle.dump(dict,f)
return True def log_info_specific_write(user,dict):
'''
指定用户日志文件指定内容写入
:param user: 用户名
:param dict: 预修改的字典内容
:return: True or False
'''
dictt = log_info_read(user)
if dictt == False:
print ('用户日志文件不存在!')
return False
dictt[dict.keys()[0]] = dict[dict.keys()[0]]
re = log_info_write(user,dictt)
if re == True:
return True
else:
return False def log_info_billing_write(user,text):
'''
指定用户日志文件流水数据写入
:param user: 用户名
:param text: 用户流水数据
:return: True or False
''' dict = log_info_read(user)
if dict == False:
print ('用户日志文件不存在!')
return False
dict['Not_out_billing'].append(text)
re = log_info_write(user, dict)
if re == True:
return True
else:
return False ###############################windows计划任务执行方法组####################################################### def Autopay(user):
'''
自动还款模块
:param user: 用户
:return: True or False
'''
dict = log_info_read(user)
tm = time.localtime()
tm_text = str(tm.tm_year) + '-' + str(tm.tm_mon) + '-' + str(tm.tm_mday) + ' ' + str(tm.tm_hour) + ':' + str(tm.tm_min)
if time.localtime().tm_mday == int(dict['Repayment_date']) and dict['Debt_Bill_amount'] != '':
if int(dict['cash']) >= int(dict['Debt_Bill_amount']):
print ('用户{0}日期吻合触发自动还款!'.format(user))
dict['cash'] = str(int(dict['cash']) - int(dict['Debt_Bill_amount']))
dict['Actual_overdraft'] = str(int(dict['Actual_overdraft'])-int(dict['Debt_Bill_amount']))
text = '{0}:触发“自动还款”操作,还款成功,还款总额为:{1},电子现金余额为{2},总透支金额为{3}'.format(tm_text,dict['Debt_Bill_amount'],dict['cash'],dict['Actual_overdraft'])
# log_info_billing_write(user,'{0}:触发“自动还款”操作,还款成功,还款总额为:{1},电子现金余额为{2},总透支金额为{3}'.format(tm_text,dict['Debt_Bill_amount'],dict['cash'],dict['Actual_overdraft']))
dict['Not_out_billing'].append(text)
dict['Debt_Bill_amount'] = ''
log_info_write(user, dict)
print ('用户{0}自动还款成功!'.format(user))
return True
else:
print ('用户{0}自动还款失败!电子现金账户余额不足!请存够钱再行尝试'.format(user))
log_info_billing_write(user,'{0}:触发“自动还款”操作,还款失败,失败原因:电子现金余额不足。还款总额为:{1},电子现金余额为{2},总透支金额为{3}'.format(tm_text,dict['Debt_Bill_amount'],dict['cash'],dict['Actual_overdraft']))
return False
else:
return def AutoBilling(user):
'''
账单自动生成模块
:param user: 用户
:return:True or False
'''
dict = log_info_read(user)
time_year = time.localtime().tm_year
time_mon = time.localtime().tm_mon
time_mday = time.localtime().tm_mday
date = str(time_year)+'-'+str(time_mon) text = '''
亲爱的{0},您的{1}年{2}月账单如下: 账单总金额为:{3}(当期+历史欠账),最后还款日为下月{4}日
请您按时还款,谢谢您的使用,再见!'''.format(user,str(time_year),str(time_mon),dict['Actual_overdraft'],dict['Repayment_date'])
if date not in dict['Debt_record']:
dict['Debt_record'][date] = text
dict['Debt_Bill_amount'] = dict['Actual_overdraft']
if date not in dict['Has_been_out_billing']:
dict['Has_been_out_billing'][date] = dict['Not_out_billing']
dict['Not_out_billing'] = []
log_info_write(user,dict) def Traverse_folder():
'''
根据条件遍历某文件夹里的全部文件内容,
找出符合条件的文件后调用自动执行模块
(需windows计划任务触发)
:return:None
'''
list = os.listdir(DIR)
time_year = time.localtime().tm_year
time_mon = time.localtime().tm_mon
time_mday = time.localtime().tm_mday
for i in list:
if i == '__init__.py' or i == '__init__.pyc':
continue
else:
name = i.strip().split('_')[0]
dict = log_info_read(name)
if dict['billing_day'] == str(time_mday):
AutoBilling(name)
if dict['Repayment_date'] == str(time_mday):
Autopay(name) def test():
'''
自动还款测试函数
:return:None
'''
dict = log_info_read('chensiqi')
dict['Debt_Bill_amount'] = ''
dict['cash'] = ''
dict['Actual_overdraft'] = ''
dict ['Repayment_date'] = ''
log_info_write('chensiqi',dict)
print (dict['Not_out_billing'])
  • src目录:业务逻辑文件

user_business.py

 #!/usr/bin/python
# -*- coding: utf-8 -*-
# 用户业务层 import os,random,time,sys
sys.path.append('..')
from src import admin_business
from lib import common DIR = os.path.dirname(__file__)
DIR = DIR.replace('src','db/') LOGINING = [] #用户时时登录列表
ERROR = [] #账户临时锁定字典
TAG = True #循环控制标志 def login_status(func):
'''
装饰器用于用户登录状态验证
:param func: 对象
:return: 对象
'''
def inner():
if LOGINING == []:
log = '用户状态未登录...'
else:
log = '{0}登录中...'.format(LOGINING[0])
func(log)
return inner def Permission_checking(func):
'''
装饰器用于用户功能权限验证
:param func:对象
:return:对象
'''
def inner():
if LOGINING == []:
print ('您尚未登录,请登录后再来!')
return
func()
return inner def Account_checking(func):
'''
装饰器对用户是否创建银行卡及银行卡状态进行验证
:param func: 对象
:return: 对象
'''
def inner():
re = common.log_info_specific_read(LOGINING[0],'account')
ree = common.log_info_specific_read(LOGINING[0],'status')
reee = common.log_info_specific_read(LOGINING[0],'pwd_money')
if re == 'empty':
print ('您尚未关联银行卡,请关联后再来!')
return
elif ree == '':
print ('您的银行卡已经被管理员冻结!请解冻后再来')
return
elif reee == 'empty':
print ('您的银行卡密码还未设定,请设定后再来!')
return
func()
return inner @login_status
def User_Manage(log = None):
'''
用户管理界面,用户登录及注册
:param log: 用户登录状态标志
:return: None
'''
while TAG:
text = '''
欢迎光临用户管理模块 {0} 1,用户登录
2,用户注册
3,返回菜单 '''.format(log) print (text)
choose = raw_input('请输入索引进行选择:')
if choose == '':
Login()
elif choose == '':
User_registration()
elif choose == '':
return
else:
print ('您的输入有误,请重新输入!') def Login():
'''
用户登录功能模块
:return: None
'''
global ERROR
num = 0
while TAG:
user = raw_input('请输入用户名:')
pwd = raw_input('请输入密码:')
ree = Login_check(user,pwd)
if ree == True:
print ('用户名和密码校验成功!')
break
elif ree == '':
print('没有这个用户名,请注册后再来!')
return
elif num == 2:
print ('您已经连续输错3次,账号已经锁定!')
ERROR.append(user)
return
elif ree == '':
print ('密码输入错误,请重新输入!')
num += 1
continue
elif ree == '':
print('这个账号已经被锁定!')
return
common.Verification_input()
LOGINING.insert(0,user)
Main() def Login_check(user,pwd):
'''
用户登录验证功能模块:
:param user: 用户名
:param pwd: 登录密码
:return: 1:用户名不存在
2:用户名密码不匹配
3:用户名存在于锁定列表中
True:登录信息正确
'''
if user == 'admin' and pwd == '':
LOGINING.insert(0,'admin')
admin_business.admin_manage('admin')
re = common.log_info_read(user)
if user in ERROR:
return ''
elif os.path.exists(DIR+user+'_log') == False:
return ''
elif re['pwd_login'] != common.MD5(pwd):
return ''
else:
return True def User_registration():
'''
用户注册功能模块
:return: None
'''
while TAG:
name_login = common.name_login_input() #得到新用户名
if name_login == None:
return
pwd_login = common.pwd_login_input() #得到新登录密码
if pwd_login == None:
return
account = common.account_input() #得到新银行卡号
if account == None:
return
if account != 'empty':
pwd_money = common.pwd_money_input() #得到新取款密码
if pwd_money == None:
return
else:
pwd_money = 'empty'
common.Verification_input() #进行验证码验证
while TAG:
information = '''
您要注册的信息如下: 登录用户名:{0}
登录的密码:{1}
银行卡账号:{2}
银行取款码:{3} '''.format(name_login,pwd_login,account,pwd_money)
print (information)
decide = raw_input('注册信息是否确认?(y/n):')
if decide == 'y':
tm = time.localtime()
tm_text = str(tm.tm_year) +'-'+ str(tm.tm_mon) +'-'+ str(tm.tm_mday) +' '+ str(tm.tm_hour) +':'+ str(tm.tm_min)
#user_information = '{0}|{1}|{2}|{3}|{4}|15000|活跃|10000'.format(name_login,pwd_login,account,pwd_money,tm_text)
dict_info = {'name_login':name_login, #用户名
'pwd_login':pwd_login, #登录密码
'account':account, #银行卡号
'pwd_money':pwd_money, #银行卡密码
'tm_text':tm_text, #注册时间
'billing_day':'', #账单日
'Repayment_date':'', #还款日
'status':'', #账户状态(0:活跃 1:冻结)
'cash':'', #现金电子余额
'Actual_overdraft':'', #总透支金额
'Overdraft_limit':'', #透支额度上限
'Debt_Bill_amount':'', #账单欠账金额记录
'Debt_record':{}, #已出账单历史记录
'Has_been_out_billing':{}, #已出账单流水历史记录
'Not_out_billing':[] #未出账单流水记录
}
common.log_info_write(name_login,dict_info)
print ('注册成功!')
LOGINING.insert(0,name_login)
User_Manage()
Main()
elif decide == 'n':
break
else:
print ('您的输入有误,请重新输入!') #def Log_Pretreatment(firstsite) @login_status
def Main(log = None):
'''
用户功能选择界面
:param log: 用户登录状态标志
:return: None
'''
while TAG:
text = '''
欢迎光临ATM电子银行 {0} 1,用户管理
2,个人信息
3,存款取款
4,时时转账
5,还款设置
6,查询账单
7,退出系统 '''.format(log)
print (text)
Choose = {'': User_Manage,
'': User_information,
'': User_Save_Money,
'': User_Transfer_Money,
'': User_Pay_back_Money,
'': Select_Billing,
'': common.Exit
}
choose = raw_input('请输入索引进行选择:')
# print (choose)
if choose in Choose:
Choose[choose]()
else:
print ('您输入有误,请重新输入!') @Permission_checking
def User_information():
'''
个人信息查询模块
:return:
'''
while TAG:
dict = common.log_info_read(LOGINING[0])
if dict['status'] == '':
lab = '正常'
else:
lab = '冻结'
if dict['account'] == 'empty':
labb = '未绑定'
else:
labb = dict['account']
text = '''
您的个人注册信息如下: 登录名:{0}
银行卡号:{1}
注册时间:{2}
账单日(每月):{3}
还款日(每月):{4}
银行卡状态:{5}
电子现金余额:{6}
银行卡已透支额度:{7}
银行卡透支额度上限:{8}
'''.format(dict['name_login'],labb,dict['tm_text'],dict['billing_day'],
dict['Repayment_date'],lab,dict['cash'],
dict['Actual_overdraft'],dict['Overdraft_limit'])
print(text)
print ('''
您可以进行如下操作:
1,修改登录密码
2,绑定银行卡
3,修改银行卡密码
4,返回菜单
''')
while TAG:
decide = raw_input('你想做点什么?')
if decide == '':
pwd_login = common.pwd_login_input()
if pwd_login == None:
return
else:
dict['pwd_login'] = pwd_login
common.log_info_write(LOGINING[0],dict)
print('登录密码修改成功')
break
elif decide == '':
if dict['account'] != 'empty':
print ('您已经绑定过银行卡了!不能再次绑定!')
break
else:
account = common.account_input()
if account == None:
return
else:
dict['account'] = account
common.log_info_write(LOGINING[0], dict)
print ('银行卡绑定成功!')
break
elif decide == '':
if dict['account'] == 'empty':
print ('您尚未绑定银行卡,请绑定后再来!')
break
else:
pwd_money = common.pwd_money_input()
if pwd_money == None:
return
else:
dict['pwd_money'] = pwd_money
common.log_info_write(LOGINING[0], dict)
print ('银行卡密码修改成功!')
break
elif decide == '':
return
else:
print ('您的输入有误!') @Permission_checking
@Account_checking
@login_status
def User_Save_Money(log = None):
'''
用户存款取款模块
:return:True or False
'''
while TAG:
cash = common.log_info_specific_read(LOGINING[0],'cash')
Actual_overdraft = common.log_info_specific_read(LOGINING[0],'Actual_overdraft')
Overdraft_limit = common.log_info_specific_read(LOGINING[0],'Overdraft_limit')
tm = time.localtime()
tm_text = str(tm.tm_year) + '-' + str(tm.tm_mon) + '-' + str(tm.tm_mday) + ' ' + str(tm.tm_hour) + ':' + str(tm.tm_min) text = '''
自助存取款功能界面 {0} 1,取款
2,存款
3,返回 '''.format(log)
print (text)
print ('您的电子账户现金为{0}元,透支额度上限为{1}元,已经透支的额度为{2}元'.format(cash, Overdraft_limit, Actual_overdraft))
choose = raw_input('请问你想做点什么?:')
if choose == '':
while TAG:
money = raw_input('请输入你想提取的金额:')
re = common.pwd_money_check(LOGINING[0])
if re == False:
print ('密码校验错误!')
break
elif money.isdigit():
if int(cash) >= int(money):
cash = str(int(cash)-int(money))
common.log_info_specific_write(LOGINING[0],{'cash':cash})
#common.log_info_specific_write(LOGINING[0], {'billing': cash})
common.log_info_billing_write(LOGINING[0],'{0}:您进行了“提款”操作,提款金额为{1},现金余额为{2},总透支金额为{3}'
.format(tm_text,money,cash,Actual_overdraft))
break
else:
a = int(Actual_overdraft)+int(money)-int(cash)
if a <= int(Overdraft_limit):
Actual_overdraft = str(a)
common.log_info_specific_write(LOGINING[0], {'cash': ''})
common.log_info_specific_write(LOGINING[0], {'Actual_overdraft': Actual_overdraft})
common.log_info_billing_write(LOGINING[0], '{0}:您进行了“提款”操作,提款金额为{1},电子现金余额为{2},总透支金额为{3}'
.format(tm_text,money,'',Actual_overdraft))
break
else:
a = str(int(Overdraft_limit) - int(Actual_overdraft))
print ('您想提取的金额已超透支额度上限,您最多还能提取{0}元'.format(a))
break
else:
print ('您的输入有误!')
elif choose == '':
while TAG:
money = raw_input("请输入你想存入的金额:")
re = common.pwd_money_check(LOGINING[0])
if re == False:
print ('密码校验错误!')
break
elif money.isdigit():
cash = str(int(cash)+int(money))
common.log_info_specific_write(LOGINING[0], {'cash': cash})
common.log_info_billing_write(LOGINING[0], '{0}:您进行了“存款”操作,存款金额为{1},电子现金余额为{2},总透支额度为{3}'
.format(tm_text, money, cash,Actual_overdraft))
break
else:
print ('您的输入有误!') elif choose == '':
return
else:
print ('您的输入有误!') @Permission_checking
@Account_checking
@login_status
def User_Transfer_Money(log = None):
'''
用户时时转账模块
:return:
'''
while TAG:
dictt = common.log_info_read(LOGINING[0])
tm = time.localtime()
tm_text = str(tm.tm_year) + '-' + str(tm.tm_mon) + '-' + str(tm.tm_mday) + ' ' + str(tm.tm_hour) + ':' + str(tm.tm_min)
text = '''
时时转账功能界面 {0}
1,时时转账
2,返回菜单
'''.format(log)
print (text)
while TAG:
decide = raw_input('请问你想做点什么?')
if decide == '':
name = raw_input('请输入你想转账的人的用户名:')
if os.path.exists(DIR +name+'_log') == False:
print ('没有这个用户存在!请重新输入!')
break
elif common.log_info_specific_read(name, 'account') == 'empty':
print ('对方没有关联银行卡!')
break
else:
card = raw_input('请输入你想要转账的对方的银行卡号:')
account = common.log_info_specific_read(name, 'account')
if card == account:
print ('银行卡号验证成功!')
money = raw_input('请输入你想要转账的金额:')
re = common.pwd_money_check(LOGINING[0])
if re == False:
print ('密码校验错误!')
break
elif int(dictt['cash']) < int(money):
print ('您没有足够的现金转账!')
break
elif money.isdigit():
dict = common.log_info_read(name)
dict['cash'] = str(int(dict['cash'])+int(money))
common.log_info_write(name,dict)
text = '{0}:银行卡为{1}的用户 向您转账{2}元,电子现金账户余额为{3},总透支额度为{4}'\
.format(tm_text,dictt['account'],money,dict['cash'],dict['Actual_overdraft'])
common.log_info_billing_write(name,text)
dictt['cash'] = str(int(dictt['cash'])-int(money))
common.log_info_write(LOGINING[0], dictt)
text = '{0}:您进行了“转账”操作,转账金额为{1},对方银行卡号为{2},电子现金余额为{3},总透支额度为{4}'\
.format(tm_text,money,dict['account'],dictt['cash'],dictt['Actual_overdraft'])
common.log_info_billing_write(LOGINING[0], text)
print ('转账成功!')
else:
print ('您的银行卡号输入错误!')
break
elif decide == '':
return
else:
print ('您的输入有误!') @Permission_checking
@Account_checking
def User_Pay_back_Money():
'''
用户定期还款设置模块
:return:
'''
dict = common.log_info_read(LOGINING[0])
print ('您目前的自动还款设置为每月的{0}日还款').format(dict['Repayment_date'])
while TAG:
decide = raw_input('你想重新设置自动还款日吗?(y/n):')
if decide == 'y':
day = raw_input('请输入您想设置的日期(1----10):')
if day.isdigit() and int(day) <= 10:
dict['Repayment_date'] = day
common.log_info_write(LOGINING[0],dict)
print ('自动还款日期修改成功!')
return
else:
print ('您的输入有误!')
elif decide == 'n':
return
else:
print ('您的输入有误!') @Permission_checking
@Account_checking
@login_status
def Select_Billing(log = None):
'''
用户账单查询模块
:return:
''' dictt = {}
while TAG:
num = 0
dict = common.log_info_read(LOGINING[0])
tm = time.localtime()
tm_text = str(tm.tm_year) + '-' + str(tm.tm_mon) + '-' + str(tm.tm_mday) + ' ' + str(tm.tm_hour) + ':' + str(tm.tm_min) text = '''
账单功能如下: {0}
1,账单查询
2,未出账单流水记录查询
3,返回菜单
'''.format(log)
print (text)
while TAG:
choose = raw_input('请输入索引进行选择:')
if choose == '':
num = 0
if len(dict['Debt_record'].keys()) != 0:
for i in dict['Debt_record'].keys():
num += 1
dictt[str(num)] = i
print ('{0},{1}账单'.format(str(num),i))
while TAG:
choose = raw_input('请输入你的选择:')
if choose in dictt:
print (dict['Debt_record'][dictt[choose]])
print ('{0}月账单流水信息如下:'.format(dictt[choose]))
for i in dict['Has_been_out_billing'][dictt[choose]]:
print (i)
break
else:
print ('你的输入有误!')
else:
print ('目前您没有任何账单生成!')
break
elif choose == '':
print ('未出账单流水记录如下:')
for line in dict['Not_out_billing']:
print (line)
break
elif choose == '':
return
else:
print ('您的输入有误!')

admin_business.py

 #!/usr/bin/python
# -*- coding: utf-8 -*-
# 管理员业务层 from lib import common
import user_business
import os
DIR = os.path.dirname(__file__)
DIR = DIR.replace('src','db/') LOGINING = [] #用户时时登录列表
TAG = True #循环控制标志 def admin_manage(log = None):
'''
管理员操作界面,只有管理员能进
:param log: 用户登录状态标志
:return: None
'''
while TAG:
text = '''
欢迎光临管理员操作界面 {0} 1,添加用户银行卡号
2,指定用户透支额度
3,冻结用户银行卡号
4,系统退出 '''.format(log)
print (text)
while TAG:
choose = raw_input('管理员你好,你想做点什么?:')
if choose in {'','','',''}:
if choose == '':
admin_add_bankcard()
break
elif choose == '':
admin_Overdraft_limit()
break
elif choose == '':
admin_Freeze_bankcard()
break
elif choose == '':
common.Exit()
else:
print ('您的输入有误!') def admin_add_bankcard():
'''
给没有关联银行卡的用户关联银行卡号
:return:None
'''
dict = {}
print ('尚未建立银行卡关联信息的账户如下:\n')
list = os.listdir(DIR)
num = 0
for i in list:
if i == '__init__.py' or i == '__init__.pyc':
continue
else:
re_dict = common.log_info_read(i.strip().split('_')[0])
if re_dict['account'] == 'empty':
num += 1
print ('{0} 登录名称:{1} \n'.format(num,re_dict['name_login']))
dict[str(num)] = re_dict['name_login']
while TAG:
choose = raw_input('输入索引选择你想添加银行卡的用户(n = 返回上级菜单):')
if choose == 'n':
return
elif choose in dict:
account = common.account_input()
re_dict = common.log_info_read(dict[choose])
re_dict['account'] = account
common.log_info_write(dict[choose],re_dict)
print ('用户{0}的银行卡关联成功'.format(dict[choose]))
else:
print('您输入的信息有误!') def admin_Overdraft_limit():
'''
修改用户银行卡的透支额度
:return:None
'''
dict = {}
print ('所有用户额度信息如下:\n')
list = os.listdir(DIR)
num = 0
for i in list:
if i == '__init__.py' or i == '__init__.pyc':
continue
else:
re_dict = common.log_info_read(i.strip().split('_')[0])
num += 1
print ('{0} 登录名称:{1} 透支额度为:{2} \n'.format(num, re_dict['name_login'],re_dict['Overdraft_limit']))
dict[str(num)] = re_dict['name_login']
while TAG:
choose = raw_input('输入索引选择你想修改额度的账户(n = 返回上级菜单):')
if choose == 'n':
return
elif choose in dict:
Quota = raw_input('你想把额度改成多少?:')
re_dict = common.log_info_read(dict[choose])
re_dict['Overdraft_limit'] = Quota
common.log_info_write(dict[choose], re_dict)
print ('用户{0}的额度修改成功!'.format(dict[choose]))
else:
print('您输入的信息有误!') def admin_Freeze_bankcard():
'''
冻结or解冻用户的银行卡号
:return:None
'''
dict = {}
print ('所有已关联银行卡的用户的银行卡状态信息如下:\n')
list = os.listdir(DIR)
num = 0
for i in list:
if i == '__init__.py' or i == '__init__.pyc':
continue
else:
re_dict = common.log_info_read(i.strip().split('_')[0])
if re_dict['account'] != 'empty':
num += 1
if re_dict['status'] == '':
lab = '活跃'
else:
lab = '冻结'
print ('{0} 登录名称:{1} 账户状态:{2} \n'.format(num, re_dict['name_login'],lab))
dict[str(num)] = re_dict['name_login']
while TAG:
choose = raw_input('输入索引选择用户来改变他的银行卡状态(活跃-->冻结-->活跃)(n = 返回上级菜单):')
if choose == 'n':
return
elif choose in dict:
re_dict = common.log_info_read(dict[choose])
if re_dict['status'] == '':
labb = '冻结'
labbb = ''
else:
labb = '活跃'
labbb = ''
decide = raw_input('你确定要将用户{0}的银行卡的状态改成{1}吗?(y/n):'.format(dict[choose],labb))
if decide == 'n':
return
re_dict['status'] = labbb
common.log_info_write(dict[choose], re_dict)
print('用户{0}的银行卡的状态信息已经改变!'.format(dict[choose]))
else:
print('您输入的信息有误!')

从零开始学Python04作业源码:模拟ATM电子银行(仅供参考)的更多相关文章

  1. 从零开始学Python04作业思路:模拟ATM电子银行

    标签(空格分隔):Python 一,程序文件说明 程序分为5个组成部分 bin:放置Python程序的启动接口文件 通过Python命令启动文件夹内文件即正常执行Python程序 例如:ATM_sta ...

  2. 从零开始学Python07作业源码:虚拟人生(仅供参考)

    bin目录: Simulated_life_start.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: im ...

  3. 从零开始学Python08作业源码:开发简单的FTP(仅供参考)

    服务器端:server_server.py #!usr/bin/env python # -*- coding:utf-8 -*- # auther:Mr.chen # 描述: import sock ...

  4. 从零开始学Python06作业源码(仅供参考)

    Python Version 2.7x 一,bin目录:程序启动入口 SelectLesson_start.py #!usr/bin/env python # -*- coding:utf-8 -*- ...

  5. 【原创】从零开始学SpagoBI5.X源码汉化编译

    从零开始学SpagoBI5.X源码汉化编译 一.新建Tomact Server 服务器并配置测试1.文件-新建-其他-过滤server-服务类型选择Tomact V7.0 Server2.根据需要修改 ...

  6. Asp.net MVC4 +EF6开发的个人网站源码和介绍(仅供新手学习)

    本项目是我去年利用业余时间开发的,采用的是asp.net mvc 4 +EF6+三层架构,适合新手进行学习,高手就没有什么价值了,可以直接跳过. 源码和数据库下载(已上传到git):https://g ...

  7. 最新咕咆+鲁班+图灵+享学+蚂蚁+硅谷+源码 Java架构师资料《Java架构师VIP课程》

    最新的Java架构师完整资料,完整视频+源码+文档. 每一套都是一百多个G的资料,无密. JAVA架构师全套课程 咕泡学院互联网架构师第一期 咕泡学院互联网架构师第二期 咕泡学院互联网架构师第三期 博 ...

  8. Unity上一页下一页切换功能实现源码(仅供参考)

    在做项目时我们有时需要实现切换上一页下一页图片,切换上一首下一首歌曲等等类似的功能.这里写了个简单的实现源码(仅供参考),要是有更好的方法欢迎提出来,共同进步~ 以切换上一页下一页图片为例: usin ...

  9. 从零开始学Python07作业思路:模拟人生小游戏

    标签(空格分隔): 从零开始学Python 一,作业说明 模拟人生: 1 定义三个人物,屌丝John,美女Liz,高富帅Peter. John和Liz大学时是恋人,毕业工作后,Liz傍上了Peter, ...

随机推荐

  1. Atitit 马尔可夫过程(Markov process) hmm隐马尔科夫。 马尔可夫链,的原理attilax总结

    Atitit 马尔可夫过程(Markov process) hmm隐马尔科夫. 马尔可夫链,的原理attilax总结 1. 马尔可夫过程1 1.1. 马尔科夫的应用 生成一篇"看起来像文章的 ...

  2. Atitit usrqbg1821 Tls 线程本地存储(ThreadLocal Storage 规范标准化草案解决方案ThreadStatic

    Atitit usrqbg1821 Tls 线程本地存储(ThreadLocal Storage 规范标准化草案解决方案ThreadStatic 1.1. ThreadLocal 设计模式1 1.2. ...

  3. Atitit.现在的常用gui技术与gui技术趋势评价总结

    Atitit.现在的常用gui技术与gui技术趋势评价总结 1. Gui俩种分类:  native 和 dsl 和 script1 2. 最好的跨平台gui技术h51 2.1. 几大技术体系(java ...

  4. salesforce 零基础学习(三十六)通过Process Builder以及Apex代码实现锁定记录( Lock Record)

    上一篇内容是通过Process Builder和Approval Processes实现锁定记录的功能,有的时候,往往锁定一条记录需要很多的限制条件,如果通过Approval Processes的条件 ...

  5. Java面试(3)-- Java关系运算符

    class Demo03{ public static void main(String[] args){ //关系运算符 == //例1 int a = 10; int b = 10; double ...

  6. jquery 的队列queue

    使用示列代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  7. linux安全检查

    1 ssh后门 检察语句: grep -E "user,pas|user:pas" /usr/bin/* /usr/local/sbin/* /usr/local/bin/* /b ...

  8. Design4:数据库设计规范

    当数据模型从概念层转到逻辑层时,需要进行规范化设计.要想设计一个结构合理的关系型数据库,至少需要满足1NF,2NF,3NF,即第一范式,第二范式,第三范式. 1,1NF(原子性) 1NF是最基本的,数 ...

  9. 深入理解PHP内核(十)变量及数据类型-类型提示的实现

    原文链接:http://www.orlion.ga/253/ PHP是弱类型语言,向方法传递参数时也并不严格检查数据类型.不过有时候需要判断传递到方法中的参数,为此PHP中提供了一些函数来判断数据的类 ...

  10. 决战JS(二)

    紧接着上次的<决战JS>,分析总结一些比较实用的DEMO与新手分享,望大神拍砖. demo5.点击隐藏: 要实现这个功能只需要知道在onclick事件中加入对父节点的样式dislay设置为 ...