项目运行
需要先安装Python的相关依赖:pymysql,Django ,requests ,opencv-python=4.5.5.64,scikit-image,dlib,numpy使用pip install 安装
第一步:创建数据库
第二步:执行SQL语句,.sql文件,运行该文件中的SQL语句
第三步:修改源代码中的settings.py文件,改成自己的mysql数据库用户名和密码
第四步:运行命令:python manage.py runserver 8000
第五步:打开浏览器查看http://127.0.0.1:8000
毕设帮助,指导,本源码分享,调试部署(见文末)
系统介绍:
本项目是一个基于Django、MySQL、Python开发的在线票务系统,采用前后端分离模式,前台实现用户注册、公告须知、购票信息查看和在线购票等功能,后台实现管理员信息管理、用户管理、公告须知管理、购票信息发布管理、在线订票订单管理、支付信息管理、支付统计、验票信息管理和退票信息登记等功能。
人脸识别是本系统的重要功能之一,它可以帮助提高用户身份验证的精确度和安全性,提升验票的效率和准确性,减少了因人工验票带来的错误和漏检的情况。此外,人脸识别还可以快速识别购票者的信息,避免了因输入错误信息而产生的票务问题,大大提高了购票体验。在在线验票方面,系统还提供了笔记本摄像头验票功能,方便了用户的验票操作。同时,系统还提供了我的验票管理和我的退票情况等功能,方便用户查询和管理自己的验票和退票信息。
总之,本系统通过采用人脸识别技术,为用户提供了更加安全和便捷的购票和验票服务,并通过提供我的验票管理和我的退票情况等功能,进一步提高了用户体验和管理效率。
程序上交给用户进行使用时,需要提供程序的操作流程图,这样便于用户容易理解程序的具体工作步骤,现如今程序的操作流程都有一个大致的标准,即先通过登录页面提交登录数据,通过程序验证正确之后,用户才能在程序功能操作区页面操作对应的功能。
功能截图:
编程人员在搭建的开发环境中,会让各种编程技术一起呈现出最终效果。本节就展示关键部分的页面效果。
5.1 管理员功能实现
5.2 用户功能实现
代码实现:
import datetime
import os
import time
from django.contrib.auth import logout
from django.core.paginator import Paginator
from django.db.models import Count
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden, JsonResponse
from django.shortcuts import render
from user.models import User
from utils import common
from .models import *
workdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def login(request):
"""
跳转登录
:param request:
:return:
"""
# tip_obj = Tip.objects.all().order_by('-id')
return render(request, 'login.html', locals())
def search(request):
"""
跳转登录
:param request:
:return:
"""
keyword = request.GET.get('search')
print(keyword)
jingqus = JingQu.objects.filter(name__contains=keyword).all()
return render(request, 'scene.html', locals())
def scene(request):
jingqus = JingQu.objects.all()
return render(request, 'scene.html', locals())
def see(request, jingqu_id):
jingqu = JingQu.objects.filter(id=jingqu_id).first()
return render(request, 'scene_detail.html', locals())
def register(request):
return render(request, 'register.html', locals())
def order(request):
username = request.session.get('username', 'admin')
orders = Order.objects.filter(owner=username).all()
return render(request, 'order.html', locals())
def collect_face(request):
print("开始采集人脸")
time.sleep(3)
user = User.objects.filter(name=request.session.get('username')).first()
from .recognize_face.workAttendanceSystem import WAS
frame = WAS()
user_id = user.id
face_id= "100" + str(user_id)
name = user.name
result = frame.register_cap(name,face_id)
User.objects.filter(id=user_id).update(
face_id=face_id
)
return JsonResponse({'msg': 'ok'})
def detection(request):
from .recognize_face.workAttendanceSystem import WAS
frame = WAS()
order_id = request.GET.get('order_id')
order = Order.objects.filter(id=order_id).first()
username = order.owner
user = User.objects.filter(username=username).first()
current_face_id = user.face_id
print("开始验证")
face_id = frame.punchcard_cap()
# app.ExitMainLoop()
current_time = time.strftime('%Y-%m-%d', time.localtime())
room_end_time = order.append_time
current_time = datetime.datetime.strptime(current_time, "%Y-%m-%d")
if room_end_time < current_time:
return JsonResponse({'msg': '已超过预定时间,无法进入园区!', 'status': 'error'},status=400)
if int(current_face_id) == int(face_id):
Order.objects.filter(id=order_id).update(
stauts="已验票",
)
return JsonResponse({'msg': '验票成功!', 'status': 'success'})
else:
Order.objects.create(
status="验票失败,人脸不匹配,无法进入!"
)
return JsonResponse({'msg': '验票失败,人脸不匹配!', 'status': 'error'},status=500)
def personal(request):
"""
跳转登录
:param request:
:return:
"""
user = User.objects.filter(name=request.session.get('username')).first()
return render(request, 'personal.html', locals())
def add_order(request):
jid = request.POST.get('id')
count = request.POST.get('count')
price = request.POST.get('price')
append_time = request.POST.get('append_time')
Order.objects.create(
jingqu_id=jid,
count=count,
price=price,
owner=request.session.get('username', 'admin'),
status='已购买',
append_time=append_time
)
return JsonResponse({'msg': 'ok'})
def suggest(request):
"""
跳转注册
:param request:
:return:
"""
return render(request, 'suggest.html')
def add_suggest(request):
text = request.POST.get('text')
phone = request.POST.get('phone')
manyi = request.POST.get('manyi')
Suggestion.objects.create(
text=text,
phone=phone,
owner=request.user.username,
manyi_id=manyi
)
return JsonResponse({'msg': 'ok'})
def index(request):
"""
跳转首页
:param request:
:return:
"""
username = request.session.get('username', '')
role = int(request.session.get('role', 3))
user_id = request.session.get('user_id', 1)
total_user = len(User.objects.all())
date = datetime.datetime.today()
month = date.month
year = date.year
day = date.day
current_day = "{}-{}-{}".format(year, month, day)
jrtj = JingQu.objects.all().order_by('-id')[0:8]
rq = JingQu.objects.all()[0:4]
cnxh = JingQu.objects.all()[6:10]
# 获取近七天的操作
seven_days = common.get_recent_seven_day()
seven_data_dict = dict.fromkeys(seven_days, 0)
for i in seven_days:
d = datetime.timedelta
r = JingQu.objects.filter(create_time__year=i.split('-')[0], create_time__month=i.split('-')[1],
create_time__day=i.split('-')[2]).all()
if r:
seven_data_dict[i] = r.count()
seven_count_list = [seven_data_dict[x] for x in seven_days]
return render(request, 'index.html', locals())
def login_out(request):
"""
注销登录
:param request:
:return:
"""
logout(request)
return HttpResponseRedirect('/')
def personal(request):
username = request.session['username']
role_id = request.session['role']
user = User.objects.filter(name=username).first()
return render(request, 'personal.html', locals())
def get_data(request):
"""
获取列表信息 | 模糊查询
:param request:
:return:
"""
keyword = request.GET.get('name')
page = request.GET.get("page", '')
limit = request.GET.get("limit", '')
response_data = {}
response_data['code'] = 0
response_data['msg'] = ''
data = []
if keyword is None:
results_obj = User.objects.all()
else:
results_obj = User.objects.filter(name__contains=keyword).all()
paginator = Paginator(results_obj, limit)
results = paginator.page(page)
if results:
for user in results:
record = {
"id": user.id,
"name": user.name,
"password": user.password,
"phone": user.phone,
"role": user.role,
'create_time': user.create_time.strftime('%Y-%m-%d %H:%m:%S'),
"desc": user.description,
}
data.append(record)
response_data['count'] = len(results_obj)
response_data['data'] = data
return JsonResponse(response_data)
def data(request):
"""
跳转页面
"""
username = request.session.get('username', '')
role = int(request.session.get('role', 3))
user_id = request.session.get('user_id', 1)
return render(request, 'data.html', locals())
def edit_data(request):
"""
修改信息
"""
response_data = {}
user_id = request.POST.get('id')
username = request.POST.get('username')
phone = request.POST.get('phone')
User.objects.filter(id=user_id).update(
name=username,
phone=phone)
response_data['msg'] = 'success'
return JsonResponse(response_data, status=201)
def del_data(request):
"""
删除信息
"""
user_id = request.POST.get('id')
result = User.objects.filter(id=user_id).first()
try:
if not result:
response_data = {'error': '删除失败!', 'message': '找不到id为%s' % user_id}
return JsonResponse(response_data, status=403)
result.delete()
response_data = {'message': '删除成功!'}
return JsonResponse(response_data, status=201)
except Exception as e:
response_data = {'message': '删除失败!'}
return JsonResponse(response_data, status=403)
def save_file(file):
"""
保存文件
"""
if file is not None:
file_dir = os.path.join(workdir, 'static', 'uploadImg')
if not os.path.exists(file_dir):
os.mkdir(file_dir)
file_name = os.path.join(file_dir, file.name)
with open(file_name, 'wb')as f:
# chunks()每次读取数据默认 我64k
for chunk in file.chunks():
f.write(chunk)
f.close()
return file_name
else:
return None
def predict(request):
image = request.FILES.get('image')
file_name = save_file(image)
file_path = os.path.join(workdir, 'static', 'uploadImg', image.name)
try:
result = main(file_path)
print(result)
status = '无烟'
Pic.objects.create(name=image.name,
status="成功",
result=status,
owner=request.session.get('username', 'admin'),
)
return JsonResponse({"result": status})
except Exception as e:
print(e)
return JsonResponse({"error": 403})
def analysis(request):
results = Pic.objects.values('result').annotate(myCount=Count('result')) # 返回查询集合
country = []
count = []
for i in results:
country.append(i['result'])
count.append(i['myCount'])
result1 = Pic.objects.values('owner').annotate(myCount=Count('owner')) # 返回查询集合
values = []
for i in result1:
values.append({'name': i['owner'], 'value': i['myCount']})
username = request.session.get('username', 'admin')
role = int(request.session.get('role', 3))
user_id = request.session.get('user_id', 1)
return render(request, 'analysis.html', locals())
源码获取:
大家点赞、收藏、关注、评论啦 、查看👇🏻获取联系方式👇🏻