从零开始学Python04作业源码:模拟ATM电子银行(仅供参考)
- bin目录:程序启动入口
ATM_start.py:
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 # 模拟ATM电子银行+登录账户权限控制+管理员管理模块 4 # 本程序可以在windows下运行基于python2.7.8版本开发 5 # 管理员账号:admin 密码:123123 6 # python04_homework 7 # __author__:Mr.chen 8 # 程序启动入口 9 10 import sys 11 sys.path.append(\'..\') 12 from src import user_business 13 14 15 16 user_business.Main()
- crontab目录:定时任务触发入口
Auto_mission.py
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 # 计划任务定时触发启动文件 4 5 import sys 6 sys.path.append(\'..\') 7 from lib import common 8 9 common.Traverse_folder()
- lib目录:公共类文件
common.py
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 # 公共方法层 4 5 import os,time,random,pickle 6 7 DIR = os.path.dirname(__file__) 8 DIR = DIR.replace(\'lib\',\'db/\') 9 10 11 TAG = True #循环控制标志 12 13 14 def Exit(): 15 \'\'\' 16 系统退出 17 :return:None 18 \'\'\' 19 print (\'程序退出!\') 20 exit() 21 22 23 def MD5(password): 24 \'\'\' 25 加密函数 26 :param firstsite: 密码字符串 27 :return: 加密字符串 28 \'\'\' 29 import hashlib 30 return hashlib.md5(password).hexdigest() 31 32 33 def Verification_input(): 34 \'\'\' 35 登录验证码校验 36 :return: True 37 \'\'\' 38 while TAG: 39 re = Verification_Code() 40 code = raw_input(\'请输入括号里的验证码,不区分大小写({0}):\'.format(re)) 41 if code.strip().lower() != re.lower(): 42 print(\'您输入的验证码有误,请重新输入!\') 43 else: 44 return True 45 46 47 def Verification_Code(): 48 \'\'\' 49 生成随机的6位验证码:大小写字母数字的组合 50 :return: 验证码 51 \'\'\' 52 code = \'\' 53 b = random.randrange(0, 5) 54 c = random.randrange(0, 5) 55 for i in range(6): 56 if i == b: 57 a = random.randrange(1, 9) 58 code = code + str(a) 59 else: 60 a = random.randrange(65, 90) 61 if i == c: 62 code = code + chr(a).lower() 63 else: 64 code = code + chr(a) 65 return code 66 67 68 69 def pwd_money_check(user): 70 \'\'\' 71 用户银行卡密码登录验证 72 :return: True or False 73 \'\'\' 74 while TAG: 75 pwd = raw_input(\'请输入6位银行卡密码:\') 76 if pwd.isdigit() and len(pwd) == 6: 77 pwd_money = log_info_specific_read(user, \'pwd_money\') 78 if pwd_money == False: 79 print (\'用户日志不存在!\') 80 return False 81 else: 82 if MD5(pwd) == pwd_money: 83 print (\'密码验证成功!\') 84 return True 85 else: 86 return False 87 else: 88 print (\'您的输入有误!\') 89 90 91 ###########################前台请求输入方法组################################################################## 92 93 def name_login_input(): 94 \'\'\' 95 键盘输入登录名 96 :return:新用户名 97 \'\'\' 98 while TAG: 99 name_login = raw_input(\'请输入登陆用户的用户名(n=返回上级菜单):\') 100 if name_login == \'n\': 101 return 102 elif os.path.exists(\'db/\'+name_login+\'_log\'): 103 print(\'你输入的用户名已存在,请重新输入!\') 104 elif len(name_login) != len(name_login.strip()) or len(name_login.strip().split()) != 1: 105 print(\'登录名不能为空,且不能有空格,请重新输入!\') 106 else: 107 return name_login 108 109 110 def pwd_login_input(): 111 \'\'\' 112 键盘输入登录密码 113 :return:新登录密码 114 \'\'\' 115 while TAG: 116 pwd_login = raw_input(\'请输入登陆密码(n=返回上级菜单):\') 117 if pwd_login == \'n\': 118 return 119 elif len(pwd_login) < 8: 120 print(\'您输入的密码不能小于8位数(8位以上字母数字+至少一位大写字母组合),请重新输入!\') 121 elif len(pwd_login.strip().split()) != 1: 122 print(\'您输入的密码不能有空格,密码也不能为空,请重新输入!\') 123 elif pwd_login.isdigit(): 124 print(\'密码不能全为数字(8位以上字母数字+至少一位大写字母组合),请重新输入!\') 125 elif pwd_login.lower() == pwd_login: 126 print(\'请至少保留一位的大写字母(8位以上字母数字+至少一位大写字母组合),请重新输入!\') 127 else: 128 pwd_login = MD5(pwd_login) 129 return pwd_login 130 131 132 def account_input(): 133 \'\'\' 134 键盘输入银行卡号 135 :return: 新银行卡号 136 \'\'\' 137 while TAG: 138 account = raw_input(\'请输入银行卡号(如果没有可以为空)(n=返回上级菜单):\') 139 if account.strip() == \'\': 140 account = \'empty\' 141 return account 142 elif account == \'n\': 143 return 144 elif len(account.strip()) < 16: 145 print(\'银行卡号是不能小于16位的纯数字,请重新输入!\') 146 elif account.isdigit() != True: 147 print(\'银行卡号是不能小于16位的纯数字,请重新输入!\') 148 else: 149 return account 150 151 152 def pwd_money_input(): 153 \'\'\' 154 键盘输入银行卡密码 155 :return: 新银行卡密码 156 \'\'\' 157 while TAG: 158 pwd_money = raw_input(\'请输入银行卡的6位数字取款(转账)密码(n=返回上级菜单):\') 159 if pwd_money == \'n\': 160 return 161 elif len(pwd_money.strip()) != 6: 162 print(\'取款密码只能是6位纯数字,请重新输入!\') 163 elif pwd_money.strip().isdigit() != True: 164 print(\'取款密码只能是6位纯数字,请重新输入!\') 165 else: 166 pwd_money = MD5(pwd_money) 167 return pwd_money 168 169 170 171 172 ##################################数据读取写入方法组#################################################################### 173 174 175 def log_info_read(user): 176 \'\'\' 177 指定用户日志文件全部读取 178 :param user:用户名 179 :return:dict字典 180 如果无文件返回False 181 \'\'\' 182 if os.path.exists(DIR+user+\'_log\'): 183 with open(DIR+user+\'_log\',\'r\') as f: 184 dict = pickle.load(f) 185 return dict 186 else: 187 return False 188 189 190 def log_info_specific_read(user,text): 191 \'\'\' 192 指定用户日志文件指定内容读取 193 :param user: 用户名 194 :param text: 预读取的字段名 195 :return: 指定的字段内容 196 如果无文件返回False 197 \'\'\' 198 if os.path.exists(DIR+user+\'_log\'): 199 with open(DIR+user+\'_log\',\'r\') as f: 200 dict = pickle.load(f) 201 re = dict[text] 202 return re 203 else: 204 return False 205 206 207 def log_info_write(user,dict = None): 208 \'\'\' 209 指定用户日志文件全部写入 210 :param user:用户名 211 :param dict: 日志字典 212 :return: True or False 213 \'\'\' 214 #if os.path.exists(user+\'_log\'): 215 #print (DIR+user+\'_log\') 216 with open(DIR+user+\'_log\',\'w\') as f: 217 pickle.dump(dict,f) 218 return True 219 220 221 def log_info_specific_write(user,dict): 222 \'\'\' 223 指定用户日志文件指定内容写入 224 :param user: 用户名 225 :param dict: 预修改的字典内容 226 :return: True or False 227 \'\'\' 228 dictt = log_info_read(user) 229 if dictt == False: 230 print (\'用户日志文件不存在!\') 231 return False 232 dictt[dict.keys()[0]] = dict[dict.keys()[0]] 233 re = log_info_write(user,dictt) 234 if re == True: 235 return True 236 else: 237 return False 238 239 240 def log_info_billing_write(user,text): 241 \'\'\' 242 指定用户日志文件流水数据写入 243 :param user: 用户名 244 :param text: 用户流水数据 245 :return: True or False 246 \'\'\' 247 248 dict = log_info_read(user) 249 if dict == False: 250 print (\'用户日志文件不存在!\') 251 return False 252 dict[\'Not_out_billing\'].append(text) 253 re = log_info_write(user, dict) 254 if re == True: 255 return True 256 else: 257 return False 258 259 260 ###############################windows计划任务执行方法组####################################################### 261 262 263 def Autopay(user): 264 \'\'\' 265 自动还款模块 266 :param user: 用户 267 :return: True or False 268 \'\'\' 269 dict = log_info_read(user) 270 tm = time.localtime() 271 tm_text = str(tm.tm_year) + \'-\' + str(tm.tm_mon) + \'-\' + str(tm.tm_mday) + \' \' + str(tm.tm_hour) + \':\' + str(tm.tm_min) 272 if time.localtime().tm_mday == int(dict[\'Repayment_date\']) and dict[\'Debt_Bill_amount\'] != \'0\': 273 if int(dict[\'cash\']) >= int(dict[\'Debt_Bill_amount\']): 274 print (\'用户{0}日期吻合触发自动还款!\'.format(user)) 275 dict[\'cash\'] = str(int(dict[\'cash\']) - int(dict[\'Debt_Bill_amount\'])) 276 dict[\'Actual_overdraft\'] = str(int(dict[\'Actual_overdraft\'])-int(dict[\'Debt_Bill_amount\'])) 277 text = \'{0}:触发“自动还款”操作,还款成功,还款总额为:{1},电子现金余额为{2},总透支金额为{3}\'.format(tm_text,dict[\'Debt_Bill_amount\'],dict[\'cash\'],dict[\'Actual_overdraft\']) 278 # log_info_billing_write(user,\'{0}:触发“自动还款”操作,还款成功,还款总额为:{1},电子现金余额为{2},总透支金额为{3}\'.format(tm_text,dict[\'Debt_Bill_amount\'],dict[\'cash\'],dict[\'Actual_overdraft\'])) 279 dict[\'Not_out_billing\'].append(text) 280 dict[\'Debt_Bill_amount\'] = \'0\' 281 log_info_write(user, dict) 282 print (\'用户{0}自动还款成功!\'.format(user)) 283 return True 284 else: 285 print (\'用户{0}自动还款失败!电子现金账户余额不足!请存够钱再行尝试\'.format(user)) 286 log_info_billing_write(user,\'{0}:触发“自动还款”操作,还款失败,失败原因:电子现金余额不足。还款总额为:{1},电子现金余额为{2},总透支金额为{3}\'.format(tm_text,dict[\'Debt_Bill_amount\'],dict[\'cash\'],dict[\'Actual_overdraft\'])) 287 return False 288 else: 289 return 290 291 292 def AutoBilling(user): 293 \'\'\' 294 账单自动生成模块 295 :param user: 用户 296 :return:True or False 297 \'\'\' 298 dict = log_info_read(user) 299 time_year = time.localtime().tm_year 300 time_mon = time.localtime().tm_mon 301 time_mday = time.localtime().tm_mday 302 date = str(time_year)+\'-\'+str(time_mon) 303 304 text = \'\'\' 305 亲爱的{0},您的{1}年{2}月账单如下: 306 307 账单总金额为:{3}(当期+历史欠账),最后还款日为下月{4}日 308 请您按时还款,谢谢您的使用,再见!\'\'\'.format(user,str(time_year),str(time_mon),dict[\'Actual_overdraft\'],dict[\'Repayment_date\']) 309 if date not in dict[\'Debt_record\']: 310 dict[\'Debt_record\'][date] = text 311 dict[\'Debt_Bill_amount\'] = dict[\'Actual_overdraft\'] 312 if date not in dict[\'Has_been_out_billing\']: 313 dict[\'Has_been_out_billing\'][date] = dict[\'Not_out_billing\'] 314 dict[\'Not_out_billing\'] = [] 315 log_info_write(user,dict) 316 317 318 319 320 def Traverse_folder(): 321 \'\'\' 322 根据条件遍历某文件夹里的全部文件内容, 323 找出符合条件的文件后调用自动执行模块 324 (需windows计划任务触发) 325 :return:None 326 \'\'\' 327 list = os.listdir(DIR) 328 time_year = time.localtime().tm_year 329 time_mon = time.localtime().tm_mon 330 time_mday = time.localtime().tm_mday 331 for i in list: 332 if i == \'__init__.py\' or i == \'__init__.pyc\': 333 continue 334 else: 335 name = i.strip().split(\'_\')[0] 336 dict = log_info_read(name) 337 if dict[\'billing_day\'] == str(time_mday): 338 AutoBilling(name) 339 if dict[\'Repayment_date\'] == str(time_mday): 340 Autopay(name) 341 342 343 def test(): 344 \'\'\' 345 自动还款测试函数 346 :return:None 347 \'\'\' 348 dict = log_info_read(\'chensiqi\') 349 dict[\'Debt_Bill_amount\'] = \'4000\' 350 dict[\'cash\'] = \'5000\' 351 dict[\'Actual_overdraft\'] = \'5000\' 352 dict [\'Repayment_date\'] = \'6\' 353 log_info_write(\'chensiqi\',dict) 354 print (dict[\'Not_out_billing\'])
- src目录:业务逻辑文件
user_business.py
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 # 用户业务层 4 5 import os,random,time,sys 6 sys.path.append(\'..\') 7 from src import admin_business 8 from lib import common 9 10 11 DIR = os.path.dirname(__file__) 12 DIR = DIR.replace(\'src\',\'db/\') 13 14 15 LOGINING = [] #用户时时登录列表 16 ERROR = [] #账户临时锁定字典 17 TAG = True #循环控制标志 18 19 20 21 def login_status(func): 22 \'\'\' 23 装饰器用于用户登录状态验证 24 :param func: 对象 25 :return: 对象 26 \'\'\' 27 def inner(): 28 if LOGINING == []: 29 log = \'用户状态未登录...\' 30 else: 31 log = \'{0}登录中...\'.format(LOGINING[0]) 32 func(log) 33 return inner 34 35 36 def Permission_checking(func): 37 \'\'\' 38 装饰器用于用户功能权限验证 39 :param func:对象 40 :return:对象 41 \'\'\' 42 def inner(): 43 if LOGINING == []: 44 print (\'您尚未登录,请登录后再来!\') 45 return 46 func() 47 return inner 48 49 50 def Account_checking(func): 51 \'\'\' 52 装饰器对用户是否创建银行卡及银行卡状态进行验证 53 :param func: 对象 54 :return: 对象 55 \'\'\' 56 def inner(): 57 re = common.log_info_specific_read(LOGINING[0],\'account\') 58 ree = common.log_info_specific_read(LOGINING[0],\'status\') 59 reee = common.log_info_specific_read(LOGINING[0],\'pwd_money\') 60 if re == \'empty\': 61 print (\'您尚未关联银行卡,请关联后再来!\') 62 return 63 elif ree == \'1\': 64 print (\'您的银行卡已经被管理员冻结!请解冻后再来\') 65 return 66 elif reee == \'empty\': 67 print (\'您的银行卡密码还未设定,请设定后再来!\') 68 return 69 func() 70 return inner 71 72 73 @login_status 74 def User_Manage(log = None): 75 \'\'\' 76 用户管理界面,用户登录及注册 77 :param log: 用户登录状态标志 78 :return: None 79 \'\'\' 80 while TAG: 81 text = \'\'\' 82 欢迎光临用户管理模块 {0} 83 84 1,用户登录 85 2,用户注册 86 3,返回菜单 \'\'\'.format(log) 87 88 print (text) 89 choose = raw_input(\'请输入索引进行选择:\') 90 if choose == \'1\': 91 Login() 92 elif choose == \'2\': 93 User_registration() 94 elif choose == \'3\': 95 return 96 else: 97 print (\'您的输入有误,请重新输入!\') 98 99 100 def Login(): 101 \'\'\' 102 用户登录功能模块 103 :return: None 104 \'\'\' 105 global ERROR 106 num = 0 107 while TAG: 108 user = raw_input(\'请输入用户名:\') 109 pwd = raw_input(\'请输入密码:\') 110 ree = Login_check(user,pwd) 111 if ree == True: 112 print (\'用户名和密码校验成功!\') 113 break 114 elif ree == \'1\': 115 print(\'没有这个用户名,请注册后再来!\') 116 return 117 elif num == 2: 118 print (\'您已经连续输错3次,账号已经锁定!\') 119 ERROR.append(user) 120 return 121 elif ree == \'2\': 122 print (\'密码输入错误,请重新输入!\') 123 num += 1 124 continue 125 elif ree == \'3\': 126 print(\'这个账号已经被锁定!\') 127 return 128 common.Verification_input() 129 LOGINING.insert(0,user) 130 Main() 131 132 133 134 def Login_check(user,pwd): 135 \'\'\' 136 用户登录验证功能模块: 137 :param user: 用户名 138 :param pwd: 登录密码 139 :return: 1:用户名不存在 140 2:用户名密码不匹配 141 3:用户名存在于锁定列表中 142 True:登录信息正确 143 \'\'\' 144 if user == \'admin\' and pwd == \'123123\': 145 LOGINING.insert(0,\'admin\') 146 admin_business.admin_manage(\'admin\') 147 re = common.log_info_read(user) 148 if user in ERROR: 149 return \'3\' 150 elif os.path.exists(DIR+user+\'_log\') == False: 151 return \'1\' 152 elif re[\'pwd_login\'] != common.MD5(pwd): 153 return \'2\' 154 else: 155 return True 156 157 158 def User_registration(): 159 \'\'\' 160 用户注册功能模块 161 :return: None 162 \'\'\' 163 while TAG: 164 name_login = common.name_login_input() #得到新用户名 165 if name_login == None: 166 return 167 pwd_login = common.pwd_login_input() #得到新登录密码 168 if pwd_login == None: 169 return 170 account = common.account_input() #得到新银行卡号 171 if account == None: 172 return 173 if account != \'empty\': 174 pwd_money = common.pwd_money_input() #得到新取款密码 175 if pwd_money == None: 176 return 177 else: 178 pwd_money = \'empty\' 179 common.Verification_input() #进行验证码验证 180 while TAG: 181 information = \'\'\' 182 您要注册的信息如下: 183 184 登录用户名:{0} 185 登录的密码:{1} 186 银行卡账号:{2} 187 银行取款码:{3} \'\'\'.format(name_login,pwd_login,account,pwd_money) 188 print (information) 189 decide = raw_input(\'注册信息是否确认?(y/n):\') 190 if decide == \'y\': 191 tm = time.localtime() 192 tm_text = str(tm.tm_year) +\'-\'+ str(tm.tm_mon) +\'-\'+ str(tm.tm_mday) +\' \'+ str(tm.tm_hour) +\':\'+ str(tm.tm_min) 193 #user_information = \'{0}|{1}|{2}|{3}|{4}|15000|活跃|10000\'.format(name_login,pwd_login,account,pwd_money,tm_text) 194 dict_info = {\'name_login\':name_login, #用户名 195 \'pwd_login\':pwd_login, #登录密码 196 \'account\':account, #银行卡号 197 \'pwd_money\':pwd_money, #银行卡密码 198 \'tm_text\':tm_text, #注册时间 199 \'billing_day\':\'15\', #账单日 200 \'Repayment_date\':\'1\', #还款日 201 \'status\':\'0\', #账户状态(0:活跃 1:冻结) 202 \'cash\':\'0\', #现金电子余额 203 \'Actual_overdraft\':\'0\', #总透支金额 204 \'Overdraft_limit\':\'15000\', #透支额度上限 205 \'Debt_Bill_amount\':\'0\', #账单欠账金额记录 206 \'Debt_record\':{}, #已出账单历史记录 207 \'Has_been_out_billing\':{}, #已出账单流水历史记录 208 \'Not_out_billing\':[] #未出账单流水记录 209 } 210 common.log_info_write(name_login,dict_info) 211 print (\'注册成功!\') 212 LOGINING.insert(0,name_login) 213 User_Manage() 214 Main() 215 elif decide == \'n\': 216 break 217 else: 218 print (\'您的输入有误,请重新输入!\') 219 220 221 222 #def Log_Pretreatment(firstsite) 223 224 225 226 @login_status 227 def Main(log = None): 228 \'\'\' 229 用户功能选择界面 230 :param log: 用户登录状态标志 231 :return: None 232 \'\'\' 233 while TAG: 234 text = \'\'\' 235 欢迎光临ATM电子银行 {0} 236 237 1,用户管理 238 2,个人信息 239 3,存款取款 240 4,时时转账 241 5,还款设置 242 6,查询账单 243 7,退出系统 \'\'\'.format(log) 244 print (text) 245 Choose = {\'1\': User_Manage, 246 \'2\': User_information, 247 \'3\': User_Save_Money, 248 \'4\': User_Transfer_Money, 249 \'5\': User_Pay_back_Money, 250 \'6\': Select_Billing, 251 \'7\': common.Exit 252 } 253 choose = raw_input(\'请输入索引进行选择:\') 254 # print (choose) 255 if choose in Choose: 256 Choose[choose]() 257 else: 258 print (\'您输入有误,请重新输入!\') 259 260 261 262 @Permission_checking 263 def User_information(): 264 \'\'\' 265 个人信息查询模块 266 :return: 267 \'\'\' 268 while TAG: 269 dict = common.log_info_read(LOGINING[0]) 270 if dict[\'status\'] == \'0\': 271 lab = \'正常\' 272 else: 273 lab = \'冻结\' 274 if dict[\'account\'] == \'empty\': 275 labb = \'未绑定\' 276 else: 277 labb = dict[\'account\'] 278 text = \'\'\' 279 您的个人注册信息如下: 280 281 登录名:{0} 282 银行卡号:{1} 283 注册时间:{2} 284 账单日(每月):{3} 285 还款日(每月):{4} 286 银行卡状态:{5} 287 电子现金余额:{6} 288 银行卡已透支额度:{7} 289 银行卡透支额度上限:{8} 290 \'\'\'.format(dict[\'name_login\'],labb,dict[\'tm_text\'],dict[\'billing_day\'], 291 dict[\'Repayment_date\'],lab,dict[\'cash\'], 292 dict[\'Actual_overdraft\'],dict[\'Overdraft_limit\']) 293 print(text) 294 print (\'\'\' 295 您可以进行如下操作: 296 1,修改登录密码 297 2,绑定银行卡 298 3,修改银行卡密码 299 4,返回菜单 300 \'\'\') 301 while TAG: 302 decide = raw_input(\'你想做点什么?\') 303 if decide == \'1\': 304 pwd_login = common.pwd_login_input() 305 if pwd_login == None: 306 return 307 else: 308 dict[\'pwd_login\'] = pwd_login 309 common.log_info_write(LOGINING[0],dict) 310 print(\'登录密码修改成功\') 311 break 312 elif decide == \'2\': 313 if dict[\'account\'] != \'empty\': 314 print (\'您已经绑定过银行卡了!不能再次绑定!\') 315 break 316 else: 317 account = common.account_input() 318 if account == None: 319 return 320 else: 321 dict[\'account\'] = account 322 common.log_info_write(LOGINING[0], dict) 323 print (\'银行卡绑定成功!\') 324 break 325 elif decide == \'3\': 326 if dict[\'account\'] == \'empty\': 327 print (\'您尚未绑定银行卡,请绑定后再来!\') 328 break 329 else: 330 pwd_money = common.pwd_money_input() 331 if pwd_money == None: 332 return 333 else: 334 dict[\'pwd_money\'] = pwd_money 335 common.log_info_write(LOGINING[0], dict) 336 print (\'银行卡密码修改成功!\') 337 break 338 elif decide == \'4\': 339 return 340 else: 341 print (\'您的输入有误!\') 342 343 344 345 346 @Permission_checking 347 @Account_checking 348 @login_status 349 def User_Save_Money(log = None): 350 \'\'\' 351 用户存款取款模块 352 :return:True or False 353 \'\'\' 354 while TAG: 355 cash = common.log_info_specific_read(LOGINING[0],\'cash\') 356 Actual_overdraft = common.log_info_specific_read(LOGINING[0],\'Actual_overdraft\') 357 Overdraft_limit = common.log_info_specific_read(LOGINING[0],\'Overdraft_limit\') 358 tm = time.localtime() 359 tm_text = str(tm.tm_year) + \'-\' + str(tm.tm_mon) + \'-\' + str(tm.tm_mday) + \' \' + str(tm.tm_hour) + \':\' + str(tm.tm_min) 360 361 text = \'\'\' 362 自助存取款功能界面 {0} 363 364 1,取款 365 2,存款 366 3,返回 \'\'\'.format(log) 367 print (text) 368 print (\'您的电子账户现金为{0}元,透支额度上限为{1}元,已经透支的额度为{2}元\'.format(cash, Overdraft_limit, Actual_overdraft)) 369 choose = raw_input(\'请问你想做点什么?:\') 370 if choose == \'1\': 371 while TAG: 372 money = raw_input(\'请输入你想提取的金额:\') 373 re = common.pwd_money_check(LOGINING[0]) 374 if re == False: 375 print (\'密码校验错误!\') 376 break 377 elif money.isdigit(): 378 if int(cash) >= int(money): 379 cash = str(int(cash)-int(money)) 380 common.log_info_specific_write(LOGINING[0],{\'cash\':cash}) 381 #common.log_info_specific_write(LOGINING[0], {\'billing\': cash}) 382 common.log_info_billing_write(LOGINING[0],\'{0}:您进行了“提款”操作,提款金额为{1},现金余额为{2},总透支金额为{3}\' 383 .format(tm_text,money,cash,Actual_overdraft)) 384 break 385 else: 386 a = int(Actual_overdraft)+int(money)-int(cash) 387 if a <= int(Overdraft_limit): 388 Actual_overdraft = str(a) 389 common.log_info_specific_write(LOGINING[0], {\'cash\': \'0\'}) 390 common.log_info_specific_write(LOGINING[0], {\'Actual_overdraft\': Actual_overdraft}) 391 common.log_info_billing_write(LOGINING[0], \'{0}:您进行了“提款”操作,提款金额为{1},电子现金余额为{2},总透支金额为{3}\' 392 .format(tm_text,money,\'0\',Actual_overdraft)) 393 break 394 else: 395 a = str(int(Overdraft_limit) - int(Actual_overdraft)) 396 print (\'您想提取的金额已超透支额度上限,您最多还能提取{0}元\'.format(a)) 397 break 398 else: 399 print (\'您的输入有误!\') 400 elif choose == \'2\': 401 while TAG: 402 money = raw_input("请输入你想存入的金额:") 403 re = common.pwd_money_check(LOGINING[0]) 404 if re == False: 405 print (\'密码校验错误!\') 406 break 407 elif money.isdigit(): 408 cash = str(int(cash)+int(money)) 409 common.log_info_specific_write(LOGINING[0], {\'cash\': cash}) 410 common.log_info_billing_write(LOGINING[0], \'{0}:您进行了“存款”操作,存款金额为{1},电子现金余额为{2},总透支额度为{3}\' 411 .format(tm_text, money, cash,Actual_overdraft)) 412 break 413 else: 414 print (\'您的输入有误!\') 415 416 elif choose == \'3\': 417 return 418 else: 419 print (\'您的输入有误!\') 420 421 422 423 @Permission_checking 424 @Account_checking 425 @login_status 426 def User_Transfer_Money(log = None): 427 \'\'\' 428 用户时时转账模块 429 :return: 430 \'\'\' 431 while TAG: 432 dictt = common.log_info_read(LOGINING[0]) 433 tm = time.localtime() 434 tm_text = str(tm.tm_year) + \'-\' + str(tm.tm_mon) + \'-\' + str(tm.tm_mday) + \' \' + str(tm.tm_hour) + \':\' + str(tm.tm_min) 435 text = \'\'\' 436 时时转账功能界面 {0} 437 1,时时转账 438 2,返回菜单 439 \'\'\'.format(log) 440 print (text) 441 while TAG: 442 decide = raw_input(\'请问你想做点什么?\') 443 if decide == \'1\': 444 name = raw_input(\'请输入你想转账的人的用户名:\') 445 if os.path.exists(DIR +name+\'_log\') == False: 446 print (\'没有这个用户存在!请重新输入!\') 447 break 448 elif common.log_info_specific_read(name, \'account\') == \'empty\': 449 print (\'对方没有关联银行卡!\') 450 break 451 else: 452 card = raw_input(\'请输入你想要转账的对方的银行卡号:\') 453 account = common.log_info_specific_read(name, \'account\') 454 if card == account: 455 print (\'银行卡号验证成功!\') 456 money = raw_input(\'请输入你想要转账的金额:\') 457 re = common.pwd_money_check(LOGINING[0]) 458 if re == False: 459 print (\'密码校验错误!\') 460 break 461 elif int(dictt[\'cash\']) < int(money): 462 print (\'您没有足够的现金转账!\') 463 break 464 elif money.isdigit(): 465 dict = common.log_info_read(name) 466 dict[\'cash\'] = str(int(dict[\'cash\'])+int(money)) 467 common.log_info_write(name,dict) 468 text = \'{0}:银行卡为{1}的用户 向您转账{2}元,电子现金账户余额为{3},总透支额度为{4}\'\ 469 .format(tm_text,dictt[\'account\'],money,dict[\'cash\'],dict[\'Actual_overdraft\']) 470 common.log_info_billing_write(name,text) 471 dictt[\'cash\'] = str(int(dictt[\'cash\'])-int(money)) 472 common.log_info_write(LOGINING[0], dictt) 473 text = \'{0}:您进行了“转账”操作,转账金额为{1},对方银行卡号为{2},电子现金余额为{3},总透支额度为{4}\'\ 474 .format(tm_text,money,dict[\'account\'],dictt[\'cash\'],dictt[\'Actual_overdraft\']) 475 common.log_info_billing_write(LOGINING[0], text) 476 print (\'转账成功!\') 477 else: 478 print (\'您的银行卡号输入错误!\') 479 break 480 elif decide == \'2\': 481 return 482 else: 483 print (\'您的输入有误!\') 484 485 486 @Permission_checking 487 @Account_checking 488 def User_Pay_back_Money(): 489 \'\'\' 490 用户定期还款设置模块 491 :return: 492 \'\'\' 493 dict = common.log_info_read(LOGINING[0]) 494 print (\'您目前的自动还款设置为每月的{0}日还款\').format(dict[\'Repayment_date\']) 495 while TAG: 496 decide = raw_input(\'你想重新设置自动还款日吗?(y/n):\') 497 if decide == \'y\': 498 day = raw_input(\'请输入您想设置的日期(1----10):\') 499 if day.isdigit() and int(day) <= 10: 500 dict[\'Repayment_date\'] = day 501 common.log_info_write(LOGINING[0],dict) 502 print (\'自动还款日期修改成功!\') 503 return 504 else: 505 print (\'您的输入有误!\') 506 elif decide == \'n\': 507 return 508 else: 509 print (\'您的输入有误!\') 510 511 512 @Permission_checking 513 @Account_checking 514 @login_status 515 def Select_Billing(log = None): 516 \'\'\' 517 用户账单查询模块 518 :return: 519 \'\'\' 520 521 dictt = {} 522 while TAG: 523 num = 0 524 dict = common.log_info_read(LOGINING[0]) 525 tm = time.localtime() 526 tm_text = str(tm.tm_year) + \'-\' + str(tm.tm_mon) + \'-\' + str(tm.tm_mday) + \' \' + str(tm.tm_hour) + \':\' + str(tm.tm_min) 527 528 text = \'\'\' 529 账单功能如下: {0} 530 1,账单查询 531 2,未出账单流水记录查询 532 3,返回菜单 533 \'\'\'.format(log) 534 print (text) 535 while TAG: 536 choose = raw_input(\'请输入索引进行选择:\') 537 if choose == \'1\': 538 num = 0 539 if len(dict[\'Debt_record\'].keys()) != 0: 540 for i in dict[\'Debt_record\'].keys(): 541 num += 1 542 dictt[str(num)] = i 543 print (\'{0},{1}账单\'.format(str(num),i)) 544 while TAG: 545 choose = raw_input(\'请输入你的选择:\') 546 if choose in dictt: 547 print (dict[\'Debt_record\'][dictt[choose]]) 548 print (\'{0}月账单流水信息如下:\'.format(dictt[choose])) 549 for i in dict[\'Has_been_out_billing\'][dictt[choose]]: 550 print (i) 551 break 552 else: 553 print (\'你的输入有误!\') 554 else: 555 print (\'目前您没有任何账单生成!\') 556 break 557 elif choose == \'2\': 558 print (\'未出账单流水记录如下:\') 559 for line in dict[\'Not_out_billing\']: 560 print (line) 561 break 562 elif choose == \'3\': 563 return 564 else: 565 print (\'您的输入有误!\')
admin_business.py
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 # 管理员业务层 4 5 6 from lib import common 7 import user_business 8 import os 9 DIR = os.path.dirname(__file__) 10 DIR = DIR.replace(\'src\',\'db/\') 11 12 13 LOGINING = [] #用户时时登录列表 14 TAG = True #循环控制标志 15 16 17 def admin_manage(log = None): 18 \'\'\' 19 管理员操作界面,只有管理员能进 20 :param log: 用户登录状态标志 21 :return: None 22 \'\'\' 23 while TAG: 24 text = \'\'\' 25 欢迎光临管理员操作界面 {0} 26 27 1,添加用户银行卡号 28 2,指定用户透支额度 29 3,冻结用户银行卡号 30 4,系统退出 \'\'\'.format(log) 31 print (text) 32 while TAG: 33 choose = raw_input(\'管理员你好,你想做点什么?:\') 34 if choose in {\'1\',\'2\',\'3\',\'4\'}: 35 if choose == \'1\': 36 admin_add_bankcard() 37 break 38 elif choose == \'2\': 39 admin_Overdraft_limit() 40 break 41 elif choose == \'3\': 42 admin_Freeze_bankcard() 43 break 44 elif choose == \'4\': 45 common.Exit() 46 else: 47 print (\'您的输入有误!\') 48 49 50 def admin_add_bankcard(): 51 \'\'\' 52 给没有关联银行卡的用户关联银行卡号 53 :return:None 54 \'\'\' 55 dict = {} 56 print (\'尚未建立银行卡关联信息的账户如下:\n\') 57 list = os.listdir(DIR) 58 num = 0 59 for i in list: 60 if i == \'__init__.py\' or i == \'__init__.pyc\': 61 continue 62 else: 63 re_dict = common.log_info_read(i.strip().split(\'_\')[0]) 64 if re_dict[\'account\'] == \'empty\': 65 num += 1 66 print (\'{0} 登录名称:{1} \n\'.format(num,re_dict[\'name_login\'])) 67 dict[str(num)] = re_dict[\'name_login\'] 68 while TAG: 69 choose = raw_input(\'输入索引选择你想添加银行卡的用户(n = 返回上级菜单):\') 70 if choose == \'n\': 71 return 72 elif choose in dict: 73 account = common.account_input() 74 re_dict = common.log_info_read(dict[choose]) 75 re_dict[\'account\'] = account 76 common.log_info_write(dict[choose],re_dict) 77 print (\'用户{0}的银行卡关联成功\'.format(dict[choose])) 78 else: 79 print(\'您输入的信息有误!\') 80 81 82 83 def admin_Overdraft_limit(): 84 \'\'\' 85 修改用户银行卡的透支额度 86 :return:None 87 \'\'\' 88 dict = {} 89 print (\'所有用户额度信息如下:\n\') 90 list = os.listdir(DIR) 91 num = 0 92 for i in list: 93 if i == \'__init__.py\' or i == \'__init__.pyc\': 94 continue 95 else: 96 re_dict = common.log_info_read(i.strip().split(\'_\')[0]) 97 num += 1 98 print (\'{0} 登录名称:{1} 透支额度为:{2} \n\'.format(num, re_dict[\'name_login\'],re_dict[\'Overdraft_limit\'])) 99 dict[str(num)] = re_dict[\'name_login\'] 100 while TAG: 101 choose = raw_input(\'输入索引选择你想修改额度的账户(n = 返回上级菜单):\') 102 if choose == \'n\': 103 return 104 elif choose in dict: 105 Quota = raw_input(\'你想把额度改成多少?:\') 106 re_dict = common.log_info_read(dict[choose]) 107 re_dict[\'Overdraft_limit\'] = Quota 108 common.log_info_write(dict[choose], re_dict) 109 print (\'用户{0}的额度修改成功!\'.format(dict[choose])) 110 else: 111 print(\'您输入的信息有误!\') 112 113 114 115 def admin_Freeze_bankcard(): 116 \'\'\' 117 冻结or解冻用户的银行卡号 118 :return:None 119 \'\'\' 120 dict = {} 121 print (\'所有已关联银行卡的用户的银行卡状态信息如下:\n\') 122 list = os.listdir(DIR) 123 num = 0 124 for i in list: 125 if i == \'__init__.py\' or i == \'__init__.pyc\': 126 continue 127 else: 128 re_dict = common.log_info_read(i.strip().split(\'_\')[0]) 129 if re_dict[\'account\'] != \'empty\': 130 num += 1 131 if re_dict[\'status\'] == \'0\': 132 lab = \'活跃\' 133 else: 134 lab = \'冻结\' 135 print (\'{0} 登录名称:{1} 账户状态:{2} \n\'.format(num, re_dict[\'name_login\'],lab)) 136 dict[str(num)] = re_dict[\'name_login\'] 137 while TAG: 138 choose = raw_input(\'输入索引选择用户来改变他的银行卡状态(活跃-->冻结-->活跃)(n = 返回上级菜单):\') 139 if choose == \'n\': 140 return 141 elif choose in dict: 142 re_dict = common.log_info_read(dict[choose]) 143 if re_dict[\'status\'] == \'0\': 144 labb = \'冻结\' 145 labbb = \'1\' 146 else: 147 labb = \'活跃\' 148 labbb = \'0\' 149 decide = raw_input(\'你确定要将用户{0}的银行卡的状态改成{1}吗?(y/n):\'.format(dict[choose],labb)) 150 if decide == \'n\': 151 return 152 re_dict[\'status\'] = labbb 153 common.log_info_write(dict[choose], re_dict) 154 print(\'用户{0}的银行卡的状态信息已经改变!\'.format(dict[choose])) 155 else: 156 print(\'您输入的信息有误!\')
版权声明:本文为chensiqiqi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。