文章出處
文章列表
- 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('您輸入的信息有誤!')
文章列表
全站熱搜