ATM+购物车系统
ATM目录
start.py
import os,sys
from core import src
base_path=os.path.dirname(os.path.dirname(__file__))
sys.path.append(base_path)
if __name__=='__main__':
src.run()
start.py
配置文件setting.py
import os
base_path=os.path.dirname(os.path.dirname(__file__))
DB=os.path.join(base_path,'db')
BASE_LOG_LOCAL=os.path.join(base_path,'log')
LOG_PATH=r'%s\log\user.log'%base_path
ADMIN_LOG_PATH=r'%s\log\admin.log'%base_path # 定义三种日志输出格式
standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
'[%(levelname)s][%(message)s]' #其中name为getlogger指定的名字 simple_format = '[task_id:%(name)s][%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s' id_simple_format = '[task_id:%(name)s][%(levelname)s][%(asctime)s] %(message)s' # log配置字典
LOGGING_DIC = {
'version': ,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': standard_format
},
'simple': {
'format': simple_format
},
'id_simple':{
'format':id_simple_format
}
},
'filters': {}, 'handlers': {
'stream': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'user': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'standard',
'filename': LOG_PATH,
'maxBytes': **,
'backupCount': ,
'encoding': 'utf-8',
},
'admin': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'id_simple',
'filename': ADMIN_LOG_PATH,
'maxBytes': **,
'backupCount': ,
'encoding': 'utf-8',
},
}, 'loggers': {
'': {
'handlers': ['user', 'stream','user','admin'],
'level': 'DEBUG',
'propagate': False,
},
},
}
setting.py
主体函数src.py、admin.py、user.py
src.py
from core import user,admin
user_dic={
'':admin.run,
'':user.run,
}
def run():
while True:
print('''
、管理员
、用户 ''')
choice=input('>>>>:').strip()
if choice=='':break
if choice not in user_dic:continue
user_dic[choice]()
src
admin.py
from lib import common
data={'name':None}
def login():
if data['name']:
print('已经登录')
return
while True:
name=input('账号').strip()
pwd=input('密码').strip()
flog,msg=admin_interface.login(name,pwd)
if flog:
print(msg)
data['name']=name
break
else:
print(msg)
#解冻信用卡
@common.login_auth(auth_name='admin')
def thaw():
while True:
name=input('请输入要解冻用户的名字或输入q退出').strip()
if name=='q':break
user_dic=user_interface.select(name)
if not user_dic:
print('用户不存在')
continue
if user_dic['card_lick']:
print('用户未被冻结')
continue
admin_interface.card_thaw(user_dic)
print('信用卡解冻成功')
#冻结信用卡
@common.login_auth(auth_name='admin')
def card_lick():
while True:
name = input('请输入要冻结用户的名字或输入q退出').strip()
if name == 'q': break
user_dic=user_interface.select(name)
if not user_dic:
print('用户不存在')
continue
if not user_dic['card_lick']:
print('信用卡已被冻结')
continue
admin_interface.card_lick(user_dic)
print('冻结成功')
#解除用户锁定
@common.login_auth(auth_name='admin')
def thaw_user():
while True:
name = input('请输入要锁定用户的名字或输入q退出').strip()
if name == 'q': break
user_dic=user_interface.select(name)
if not user_dic:
print('用户不存在')
continue
if user_dic['user_lick']:
print('用户未被锁定')
continue
admin_interface.user_thaw(user_dic)
print('解除锁定成功')
#锁定用户
@common.login_auth(auth_name='admin')
def user_lick():
while True:
name = input('请输入要解锁用户的名字或输入q退出').strip()
if name == 'q': break
user_dic=user_interface.select(name)
if not user_dic:
print('用户不存在')
continue
if not user_dic['card_lick']:
print('用户已被锁定')
continue
admin_interface.user_lick(user_dic)
print('锁定成功') user_dic={
'':login,
'':thaw,
'':card_lick,
'':thaw_user,
'':user_lick }
def run():
while True:
print('''
、登录
、解冻信用卡
、冻结信用卡
、解除用户锁定
、锁定用户
、退出
''')
choice=input('>>>>:').strip()
if choice=='':break
if choice not in user_dic:continue
user_dic[choice]()
admin.py
user.py
from interface import bank_interface,user_interface
from lib import common
data={'name':None}
shops=[{'name':'至尊宝','price':},
{'name':'韦小宝','price':},
{'name':'宋小宝','price':},
{'name':'唐玉小宝','price':}]
def register():
while True:
name=input('输入姓名或输入q退出:').strip()
if name=='q':break
user=user_interface.select(name)
if not user:
pwd=input('密码').strip()
pwd2=input('再次输入密码').strip()
if pwd==pwd2:
user_interface.update(name,pwd)
print('注册成功')
break
else:
print('两次密码不一样')
else:
print('用户已存在')
# register()
def login():
if data['name']:
print('你已经登陆过')
return
count=
while True:
name=input('输入姓名或输入q退出:').strip()
if name == 'q': break
if not name:continue
user_dic=user_interface.select(name)
if not user_dic:
print('用户名不存在')
continue
if not user_dic['user_lick']:
print('被锁定,请联系管理员')
return
pwd=input('密码').strip()
if pwd==user_dic['pwd']:
print('登陆成功')
data['name']=name
break
else:
if count<:
print('密码错误,请重新输入')
count+=
continue
else:
print('密码错误次数超过三次,被锁定')
user_interface.login(user_dic)
break
# login()
#还款
@common.login_auth(auth_name='user')
def repayment():
user_dic=user_interface.select(data['name'])
if user_dic['bal'] >= :print('无欠款')
else:
print('你需要还%s'%(-user_dic['bal']))
while True:
money=input('请输入还款金额或输入q退出:')
if money=='q':break
if money.isdigit():
bank_interface.repayment(user_dic,int(money))
print('还款%s¥'%money)
else:
print('金额必须是数字')
# repayment()
#流水
@common.login_auth(auth_name='user')
def detailed_list():
user_dic=user_interface.select(data['name'])
bank_interface.detailed_list(user_dic) #取现
@common.login_auth(auth_name='user')
def loan():
user_dic=user_interface.select(data['name'])
if not user_dic['card_lick']:
print('你的信用卡账户被冻结,无法取现')
return
while True:
money=input('输入取现金额或输入q退出').strip()
if money=='q':break
if not money.isdigit():
print('金额必须是数字')
continue
else:
flog,msg=bank_interface.loan(user_dic,int(money))
if flog:
print(msg)
else:
print(msg)
#购物
@common.login_auth(auth_name='user')
def shopping():
while True:
user_dic = user_interface.select(data['name'])
print('''
编号 商品名 价格
至尊宝
韦小宝
宋小宝
唐玉小宝
''')
choice=input('输入编号或输入q退出').strip()
if choice=='q':break
choice=int(choice)-
if choice<=len(shops):
if not user_dic['card_lick']:
print('你的信用卡账户被冻结,无法购买')
return
flog,msg=bank_interface.shopping(user_dic,shops[choice])
if flog:
print(msg)
else:
print(msg) #转账
@common.login_auth(auth_name='user')
def transfer_accounts():
while True:
user_dic=user_interface.select(data['name'])
if not user_dic['card_lick']:
print('你的信用卡账户被冻结,无法转账')
return
to_user_name=input('输入对方的名字或q退出').strip()
if to_user_name=='q':break
if to_user_name==data['name']:
print('不能转给自己')
continue
to_user_dic=user_interface.select(to_user_name)
if not to_user_dic:
print('该用户不存在')
continue
money=input('转账金额').strip()
if not money.isdigit():
print('金额必须是数字')
continue
flog,msg=bank_interface.transfer_accounts(user_dic,to_user_dic,int(money))
if flog:
print(msg)
else:
print(msg) user_dic={
'':register,
'':login,
'':repayment,
'':detailed_list,
'':loan,
'':shopping,
'':transfer_accounts
}
def run():
while True:
print('''
、注册
、登录
、还款
、信用卡清单
、取现
、购物
、转账
、退出
''')
choice=input('>>>>:').strip()
if choice=='':break
if choice not in user_dic:continue
user_dic[choice]()
user.py
接口:admin_interface.py,bank_interface.py,user_interface.py
admin_interface.py
from db import db_handler
from lib import common
logger_admin=common.get_logger('admin')
def login(name,pwd):
admin = db_handler.select(name)
if admin:
if pwd==admin['pwd']:
return True,'登陆成功' else:
return False,'密码错误'
else:
return False,'用户不存在' def card_lick(user_dic):
user_dic['card_lick']=False
db_handler.update(user_dic)
logger_admin.info('管理员冻结了%s的信用卡'%user_dic['name'])
def card_thaw(user_dic):
user_dic['card_lick']=True
db_handler.update(user_dic)
logger_admin.info('管理员解冻了%s的信用卡' % user_dic['name'])
def user_lick(user_dic):
user_dic['user_lick']=False
db_handler.update(user_dic)
logger_admin.info('管理员锁定了%s的账号' % user_dic['name'])
def user_thaw(user_dic):
user_dic['user_lick']=True
db_handler.update(user_dic)
logger_admin.info('管理员解锁了%s的账号' % user_dic['name'])
admin_interface
bank_interface.py
from db import db_handler
from lib import common
from lib import common
logger_user=common.get_logger('admin')
def repayment(user_dic,money):
user_dic['bal']+=money
print(user_dic['bal'])
user_dic['ls'].append('你还款%s'%(money))
db_handler.update(user_dic)
logger_user.debug('%s还款%s' % (user_dic['name'],money)) def detailed_list(user_dic):
if not user_dic['ls'] :print('你还没有消费过')
for line in user_dic['ls']:print(line) def loan(user_dic,money):
if user_dic['bal']<money:
return False,'你的额度不够'
user_dic['bal']-=money*1.05
user_dic['ls'].append('你取现%s' % money)
db_handler.update(user_dic)
logger_user.debug('%s取现%s' % (user_dic['name'], money))
return True,'取现成功' def transfer_accounts(user_dic,to_user_dic,money):
if user_dic['bal']<money:
return False,'你的额度不够'
user_dic['bal']-=money
user_dic['ls'].append('你给%s转了%s¥'%(to_user_dic['name'],money))
db_handler.update(user_dic)
to_user_dic['bal']+=money
to_user_dic['ls'].append('你收到%s转账%s¥'%(user_dic['name'],money))
db_handler.update(to_user_dic)
logger_user.debug('%s转账给%s%s¥' % (user_dic['name'],to_user_dic['name'], money))
return True,'转账成功' def shopping(user_dic,shop):
if user_dic['bal']<shop['price']:
return False,'你的额度不够'
user_dic['bal']-=shop['price']
user_dic['ls'].append('你购买%s花了%s¥' % (shop['name'],shop['price']))
db_handler.update(user_dic)
logger_user.info('%s在商城购买了%s花了%s¥' % (user_dic['name'], shop['name'], shop['price']))
return True,'购买成功'
bank_interface
user_interface.py
from db import db_handler
def select(name):
return db_handler.select(name)
def update(name,pwd):
user_dic={'name':name,'pwd':pwd,'card_lick':True,'user_lick':True,'bal':,'imin':,'ls':[]}
db_handler.update(user_dic) def login(user_dic):
user_dic['user_lick'] = False
db_handler.update(user_dic)
user_interface
装饰器以及常用功能common.py
from conf import setting
import logging.config
def login_auth(auth_name):
from core import user, admin
def login(func):
def wrapper(*args,**kwargs):
if auth_name=='user':
if not user.data['name']:
print('请先登录')
user.login()
else:
return func(*args, **kwargs)
if auth_name=='admin':
if not admin.data['name']:
print('请先登录')
admin.login()
else:
return func(*args, **kwargs)
return wrapper
return login def get_logger(name):
logging.config.dictConfig(setting.LOGGING_DIC) # 导入上面定义的logging配置
logger = logging.getLogger(name) # 生成一个log实例
return logger
common.py
ATM+购物车系统的更多相关文章
- Python学习--------------Atm+购物车系统
一.程序需求 模拟实现一个ATM + 购物商城程序: 1.额度 15000或自定义 2.实现购物商城,买东西加入 购物车,调用信用卡接口结账 3.可以提现,手续费5% 4.每月22号出账单,每月10号 ...
- ATM系统和购物车系统 不需要文件支撑
目录 ATM系统 购物车系统 ATM系统 #coding=utf8 #Version:python 3.6.4 #Tools:Python 2019.9.7 _data_ = '2019/9/7/01 ...
- 使用MongoDB和JSP实现一个简单的购物车系统
目录 1 问题描述 2 解决方案 2.1 实现功能 2.2 最终运行效果图 2.3 系统功能框架示意图 2.4 有关MongoDB简介及系统环境配置 2.5 核心功能代码讲解 ...
- Java课设-购物车系统
1.团队课程设计博客链接 /[博客链接]http://www.cnblogs.com/yayaya/p/7062197.html 2.个人负责模板或任务说明 1.建立Action类 2.购物车的属性 ...
- Java课程设计 购物车系统(个人博客)
1. 团队课程设计博客链接 课程设计 2. 个人负责模块或任务说明 编写ShoppingCart类,连接数据库 编写updateCart类,从数据库中获取商品信息,获取指定编号的商品信息 编写User ...
- java 课程设计 购物车系统 个人
Q1.团队课程设计博客链接 团队博客 Q2.个人负责模块或任务说明 我主要负责main函数的编写和系统中瞎看功能代码的编写. Q3.自己的代码提交记录截图 main函数代码如下: public sta ...
- day19 十九、ATM+购物车
项目:ATM+购物车 作业需求:模拟实现一个ATM + 购物商城程序1.额度 15000或自定义 2.实现购物商城,买东西加入 购物车,调用信用卡接口结账 3.可以提现,手续费5% 4.每月22号出账 ...
- Python 入门基础16 -- ATM + 购物车
ATM + 购物车 1.需求分析 2.设计程序以及程序的架构 设计程序的好处: - 扩展性强 - 逻辑清晰 3.分任务开发 4.测试 黑盒: 白盒: 对程序性能的测试 5.上线运行 # Tank -- ...
- python实现简单购物车系统(练习)
#!Anaconda/anaconda/python #coding: utf-8 #列表练习,实现简单购物车系统 product_lists = [('iphone',5000), ('comput ...
随机推荐
- Beat 冲刺 (3/7)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...
- beta版本冲刺三
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- cygwin上编译RPC框架thrift
cygwin的配置就不多说了,缺什么就通过安装器安装好了. 在thrift的官网下载 thrift-0.11.0源码,通过cmake编译,生成Makefile之后,make出现编译错误 /cygdri ...
- [BZOJ2090/2089] [Poi2010]Monotonicity 2/Monotonicity 树状数组优化dp
这个dp乍看不科学,仔细一看更不科学,所以作为一个执着BOY,我决定要造数据卡死波兰人民,但是我造着造着就......证出来了......... 这个就是把 < > =分开讨论每次找到f[ ...
- volatile的原理分析
前言:Volatile作为一个多线程开发中的强有力的轻量级的线程协助工具,在实际编程中随处可见,它比synchronized更加轻量和方便,消耗的资源更少,了解Volatile对后面了解多线程有很重要 ...
- string 类型转换
string转int "; int n = atoi(str.c_str()); cout << n << endl; int转string #include < ...
- Unescape JavaScript's escape() using C#
js里面的 unescape escape 对应C#里面 var unescapedString = Microsoft.JScript.GlobalObject.unescape(yourEscap ...
- POJ1797:Heavy Transportation(改造Dijkstra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 52728 Accepted: ...
- Document base D:\devTools\apache-tomcat-6.0.51\webapps\AppService does not exist or is not a readable directory
tomcat通过eclipse发布项目到webapp后 手动删除在webapp目录下的文件,启动tomcat时,会报出异常找不到那个删除的项目. 解决方法是(1)重新发布项目到webapp (2)在 ...
- codeforces 111D
题目链接 D. Petya and Coloring time limit per test 5 seconds memory limit per test 256 megabytes input s ...