#__author: Administrator
#date: 2018/5/30
#bin
import os
import sys
import json
import re
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from module.loggin_site import *
login_website()
#settings
import json
def web_page():
list={'1':'Home','2':'Phone','3':'Cars'}
f=open('web_page','w')
json.dump(list,f)
f.close()
if __name__=='__main__':
web_page()
def homepage_info():
list={1:['LV',5000],2:['bike',800],3:['iwatch',3000],4:['PS4',1300]}
f=open('homepage_info','w')
json.dump(list,f)
f.close()
def phonepage_info():
list={1:['htc',3000],2:['iphone',5000],3:['xiaomi',2000],4:['chuizi',1500]}
f=open('phonepage_info','w')
json.dump(list,f)
f.close()
def carpage_info():
list={1:['byd',30000],2:['dazhong',50000],3:['qiya',20000],4:['aotuo',7500]}
f=open('carpage_info','w')
json.dump(list,f)
f.close()
def account_info():
list={'user':['johnny','1234'],'user1':['jack','6789']}
f=open('account_info','w')
json.dump(list,f)
f.close()
if __name__=='__main__':
account_info()
def atm_info():
list={'id':{'name':'cd1234','password':'1234','saving':0,'limit':15000},'id1':{'name':'cd6789','password':'6789','saving':0,'limit':15000}}
f=open('atm_info','w')
json.dump(list,f)
f.close()
def atm_option_list():
list={'1':'查询个人信息','2':'修改额度','3':'转账','4':'付款'}
f=open('atm_option_list','w')
json.dump(list,f)
f.close()
#atm_info
import os
import sys
import json
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from conf.settings import *
def login_atm_account():
global login_status,name
loop_flag=True
atm_info()
f=open('atm_info','r')
data=json.load(f)
f.close()
while loop_flag:
name=input('请输入银行卡用户名>>')
password=input('请输入银行卡登录密码>>')
num=0
for i in data:
if name==data[i]['name']:
if password==data[i]['password']:
print('登录成功')
loop_flag=False
login_status=True
else:
print('密码错误')
else:
num+=1
if num==len(data):
print('id或密码错误')
break
def search_id():
f = open('atm_info', 'r')
data = json.load(f)
f.close()
for i in data:
if data[i]['name']== name:
a = i
return a
def view_accountinfo():
print(data1[id])
def set_limit():
data1[id]['limit'] = int(input('请输入要设定的额度:'))
f = open('atm_info', 'w')
f.write(str(data1))
f.close()
def transfer_amount():
account = input('请输入收款账号:')
num=0
for i in data1:
if account == data1[i]['name']:
transfer_amount = int(input('请输入转账金额:'))
data1[i]['saving'] += transfer_amount
data1[id]['saving']-= transfer_amount
f = open('atm_info', 'w')
f.write(str(data1))
f.close()
else:
num+=1
if num==len(data1):
print('账号不存在')
def pay():
money=checkout()
print('已成功付款%s'%money)
data1[id]['saving']-=money
def atm():
global login_status
login_status = False
def outter():
global login_status,name,data1,id
id=''
while True:
if login_status == True:
atm_option_list()
f = open('atm_option_list', 'r')
data = json.load(f)
for i in data:
print('%s >> %s' % (i, data[i]))
id=search_id()
f = open('atm_info', 'r')
data1 = json.load(f)
f.close()
num=input('请输入选项编号:')
if num=='1':
view_accountinfo()
elif num=='2':
set_limit()
elif num=='3':
transfer_amount()
elif num=='4':
pay()
break
else:
login_atm_account()
return outter()
if __name__=='__main__':
atm()
#loggin_site
import os
import sys
import json
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from conf.settings import *
from module.page_content import *
from module.start_shopping import *
from module.atm_api import *
import re
def select_page():
loop_flag=True
while loop_flag:
num=input('请输入访问页面编号[退出:q]>>')
if re.search('[0a-pr-zA-Z4-9]',num):
print('\033[31;1m请输入正确的数字\033[0m')
else:
if num=='1':
homepage_content()
loop_flag = False
shopping_homepage()
elif num=='2':
phonepage_content()
loop_flag = False
shopping_phonepage()
elif num=='3':
carpage_content()
loop_flag = False
shopping_carpage()
elif num=='q':
print('欢迎下次光临')
break
def login_website():
web_page()
f=open('web_page','r')
data=json.load(f)
for i in data:
print('%s >> %s'%(i,data[i]))
select_page()
if __name__=='__main__':
login_website()
#page_content
import os
import sys
import json
import re
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from conf.settings import *
def homepage_content():
homepage_info()
f = open('homepage_info', 'r')
data = json.load(f)
print('welcome to visit the homepage')
for i in data:
print('%s.%s>>%d'%(i,data[i][0],data[i][1]))
def phonepage_content():
phonepage_info()
f = open('phonepage_info', 'r')
data = json.load(f)
print('welcome to visit the phonepage')
for i in data:
print('%s.%s>>%d' % (i, data[i][0], data[i][1]))
def carpage_content():
carpage_info()
f = open('welcome to visit the carpage', 'r')
data = json.load(f)
for i in data:
print('%s.%s>>%d' % (i, data[i][0], data[i][1]))
if __name__=='__main__':
homepage_content()
#start_shopping
import os
import sys
import json
import re
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from conf.settings import *
from module.atm_api import *
shopping_car=[]
def checkout():
checkout_money=0
title='已购买以下商品'
print(title.center(20,'-'))
for i in shopping_car:
print(i)
for i in shopping_car:
checkout_money+=i[1]
print('合计:%d'%checkout_money)
return checkout_money
def login_account():
global account_status
loop_flag = True
account_info()
f = open('account_info', 'r')
data = json.load(f)
while loop_flag:
user = input('请输入账号名称:')
password = input('请输入密码:')
num = 0
for i in data:
if user == data[i][0]:
if password == data[i][1]:
print('登录成功')
loop_flag = False
account_status = True
else:
print('密码错误')
else:
num += 1
if num == len(data):
print('账户或密码错误')
break
def shopping_homepage():
global shopping_car,account_status
homepage_info()
f = open('homepage_info', 'r')
data1 = json.load(f)
account_status = False
loop_flag = True
while loop_flag:
num = input('请输入商品编号将商品加入购物车[结算:c]>>')
if account_status == False:
def inner():
global account_status
login_account()
inner()
else:
if re.search('[0a-bd-or-zA-Z5-9]', num):
print('请输入正确的数字')
elif num=='c':
checkout()
pay = input('是否立即支付?[y/n]')
if pay=='y':
atm()
else:
shopping_car.append(data1[num])
if __name__=='__main__':
shopping_homepage()
def shopping_phonepage():
homepage_info()
f = open('phonepage_info', 'r')
data1 = json.load(f)
global account_status
account_status = False
loop_flag = True
while loop_flag:
num = input('请输入商品编号将商品加入购物车[结算:c]>>')
if account_status == False:
def inner():
global account_status
login_account()
inner()
else:
if re.search('[0a-bd-or-zA-Z5-9]', num):
print('请输入正确的数字')
elif num=='c':
checkout()
pay = input('是否立即支付?[y/n]')
if pay=='y':
atm()
else:
shopping_car.append(data1[num])
def shopping_carpage():
homepage_info()
f = open('carpage_info', 'r')
data1 = json.load(f)
global account_status
account_status = False
loop_flag = True
while loop_flag:
num = input('请输入商品编号将商品加入购物车[结算:c]>>')
if account_status == False:
def inner():
global account_status
login_account()
inner()
else:
if re.search('[0a-bd-or-zA-Z5-9]', num):
print('请输入正确的数字')
elif num=='c':
checkout()
pay = input('是否立即支付?[y/n]')
if pay=='y':
atm()
else:
shopping_car.append(data1[num])