基于Python+Django实现药品管理系统

简介: 项目编号:BS-Python-001技术架构:Python+Django前端:Boostrap开发工具:IDEA数据库:sqlite项目实现的功能:   用户分三个角色:管理员、仓库管理员、经销商管理员主要实现的功能包含:药品的进销存操作、客户管理、供应商管理、经营数据统计、数据导出、系统管理等模块

 作者主页:编程指南针

简介:Java领域优质创作者、CSDN博客专家  Java项目、简历模板、学习资料、面试题库、技术互助

文末获取源码

项目编号:BS-Python-001

技术架构:Python+Django

前端:Boostrap

开发工具:IDEA

数据库:sqlite

项目实现的功能:

  用户分三个角色:管理员、仓库管理员、经销商管理员

主要实现的功能包含:药品的进销存操作、客户管理、供应商管理、经营数据统计、数据导出、系统管理等模块

具体功能展示如下:

image.gif编辑

库存管理

image.gif编辑

image.gif编辑

image.gif编辑

客户管理

image.gif编辑

image.gif编辑

供应商管理

image.gif编辑

image.gif编辑

经营统计分析

image.gif编辑

数据导出

image.gif编辑

系统管理

image.gif编辑

image.gif编辑

数据打印

image.gif编辑

部分核心代码:

from datetime import datetime
import time
from django.http.response import FileResponse
from django.shortcuts import render, redirect
from hnyhms_app.models import *
import pandas as pd
# 首页
def index(request):
    return render(request, 'index.html', context={'flag': True})
# 登录
def login(request):
    # 用户登录信息判断
    if request.method == "POST":
        # 获取用户登录信息
        username = request.POST.get('username')
        userpass = request.POST.get('userpass')
        # 查询用户信息
        admin_user = Admin_users.objects.filter(au_account=username, au_pwd=userpass).first()
        if admin_user:
            rep = redirect('/adminpage')
            rep.set_cookie('adminuser', username)
            rep.set_cookie('au_role', admin_user.au_role)
            return rep
    rep = render(request, 'index.html', context={'flag': False})
    rep.delete_cookie("adminuser")
    return rep
# 退出登录
def outlogin(request):
    rep = redirect('/')
    rep.delete_cookie("adminuser")
    return rep
# 管理页面
def admin(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    if adminuser is not None:
        # 登录用户信息
        admin_user = Admin_users.objects.get(au_account=adminuser)
        admin_user_name = admin_user.au_name
        admin_user_role = admin_user.au_role
        if admin_user_role == 1:
            return render(request, 'admin_1.html', context={'admin_user_name': admin_user_name})
        if admin_user_role == 2:
            return render(request, 'admin_2.html', context={'admin_user_name': admin_user_name})
        if admin_user_role == 3:
            return render(request, 'admin_3.html', context={'admin_user_name': admin_user_name})
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 库存管理
def kcpg(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        # 判断是否有查询信息
        if request.GET.get('s') is None or request.GET.get('s') == '':
            # 返回全部列表
            medicines_list = Medicines.objects.all().values()
            customers_suppliers = Customers_suppliers.objects.filter(cs_attitude='供应商').values()
            warehouse_record = Warehouse_record.objects.all()
            context = {'medicines': medicines_list, 'customers_suppliers': customers_suppliers, 'warehouse_record': warehouse_record}
            return render(request, 'funcpage/kcpg.html', context=context)
        # 返回符合查询内容的列表
        medicines_list = Medicines.objects.filter(medicine_name__contains=request.GET.get('s')).values()
        customers_suppliers = Customers_suppliers.objects.filter(cs_attitude='供应商').values()
        warehouse_record = Warehouse_record.objects.all().values()
        context = {'medicines': medicines_list, 'customers_suppliers': customers_suppliers, 'warehouse_record': warehouse_record}
        return render(request, 'funcpage/kcpg.html', context=context)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品入库页面
def in_medicine(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine_id = request.GET.get('id')
        medicine_data = list(Medicines.objects.filter(id=medicine_id).values())[0]
        customers_suppliers = Customers_suppliers.objects.filter(cs_attitude='供应商').values()
        return render(request, 'funcpage/in_medicine.html', context={'medicine_data': medicine_data, 'customers_suppliers': customers_suppliers})
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品出库
def out_medicine(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine_id = request.GET.get('id')
        medicine_data = list(Medicines.objects.filter(id=medicine_id).values())[0]
        customers_suppliers = Customers_suppliers.objects.filter(cs_attitude='客户').values()
        return render(request, 'funcpage/out_medicine.html', context={'medicine_data': medicine_data, 'customers_suppliers': customers_suppliers})
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品入库保存
def in_medicine_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine = Medicines.objects.filter(id=request.POST.get('id'))
        medicine.update(medicine_quantity = medicine[0].medicine_quantity + float(request.POST.get('medicine_quantity')))
        # 进货金额计算
        in_amount = float(request.POST.get('medicine_quantity')) * float(request.POST.get('medicine_purchase'))
        # 添加入库记录
        warehouse_record = Warehouse_record(wr_in_out = '入库', 
                            wr_quantity = request.POST.get('medicine_quantity'),
                            wr_cs_name = request.POST.get('medicine_suppliers'),
                            wr_admin_name = request.COOKIES.get('adminuser'),
                            wr_medicine_name = request.POST.get('medicine_name'),
                            wr_in_out_time = time.strftime("%Y-%m-%d", time.localtime()),
                            wr_amount = in_amount)
        warehouse_record.save()
        return redirect('/kcpg')
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品出库保存
def out_medicine_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine = Medicines.objects.filter(id=request.POST.get('id'))
        if medicine[0].medicine_quantity >= float(request.POST.get('medicine_quantity')):
            medicine.update(medicine_quantity = medicine[0].medicine_quantity - float(request.POST.get('medicine_quantity')))
            # 出货金额计算
            out_amount = float(request.POST.get('medicine_quantity')) * float(request.POST.get('medicine_selling'))
            # 添加出库记录
            warehouse_record = Warehouse_record(wr_in_out = '出库', 
                                wr_quantity = request.POST.get('medicine_quantity'),
                                wr_cs_name = request.POST.get('medicine_suppliers'),
                                wr_admin_name = request.COOKIES.get('adminuser'),
                                wr_medicine_name = request.POST.get('medicine_name'),
                                wr_in_out_time = time.strftime("%Y-%m-%d", time.localtime()),
                                wr_amount = out_amount)
            warehouse_record.save()
            return redirect('/kcpg')
        else:
            return render(request, 'funcpage/error.html', context={'info': '库存数量已不够出库,请返回或重新填写出库数量', 'up': '/kcpg'}, status=403)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 新增药品保存
def add_medicine(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        # 药品保存
        medicine = Medicines(medicine_name = request.POST.get('medicine_name'), 
                            medicine_manufacturers = request.POST.get('medicine_manufacturers'), 
                            medicine_trademark = request.POST.get('medicine_trademark'), 
                            medicine_production_address = request.POST.get('medicine_production_address'), 
                            medicine_code = request.POST.get('medicine_code'), 
                            medicine_specification = request.POST.get('medicine_specification'), 
                            medicine_purchase = request.POST.get('medicine_purchase'), 
                            medicine_selling = request.POST.get('medicine_selling'))
        medicine.save()
        return redirect("/kcpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品编辑页面
def edit_medicine_page(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine_id = request.GET.get('id')
        medicine_data = list(Medicines.objects.filter(id=medicine_id).values())[0]
        return render(request, 'funcpage/edit_medicine.html', context={'medicine_data': medicine_data})
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 药品编辑保存
def edit_medicine_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine = Medicines.objects.filter(id=request.POST.get('id'))
        medicine.update(medicine_name=request.POST.get('medicine_name'),
                        medicine_manufacturers = request.POST.get('medicine_manufacturers'),
                        medicine_trademark = request.POST.get('medicine_trademark'),
                        medicine_production_address = request.POST.get('medicine_production_address'),
                        medicine_code = request.POST.get('medicine_code'),
                        medicine_specification = request.POST.get('medicine_specification'),
                        medicine_purchase = request.POST.get('medicine_purchase'),
                        medicine_selling = request.POST.get('medicine_selling'))
        return redirect('/kcpg')
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 删除库存
def del_medicine(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 2):
        medicine = Medicines.objects.get(id = request.GET.get('id'))
        medicine.delete()
        return redirect("/kcpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 客户管理
def khpg(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        # 判断是否有查询信息
        if request.GET.get('s') is None or request.GET.get('s') == '':
            customers_suppliers = Customers_suppliers.objects.filter(
            cs_attitude='客户').values()
            context = {'customers_suppliers': customers_suppliers}
            return render(request, 'funcpage/khpg.html', context=context)
        # 返回符合查询内容的列表
        customers_suppliers = Customers_suppliers.objects.filter(cs_unit__contains = request.GET.get('s')).values()
        context = {'customers_suppliers': customers_suppliers}
        return render(request, 'funcpage/khpg.html', context=context)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 新增客户
def add_customers(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        customers = Customers_suppliers(cs_attitude = request.POST.get('cs_attitude'), 
                            cs_postCode = request.POST.get('cs_postCode'), 
                            cs_address = request.POST.get('cs_address'), 
                            cs_tel = request.POST.get('cs_tel'), 
                            cs_unit = request.POST.get('cs_unit'), 
                            cs_name = request.POST.get('cs_name'))
        customers.save()
        return redirect("/khpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 客户编辑页面
def edit_customers_page(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        customers_id = request.GET.get('id')
        customers_data = list(Customers_suppliers.objects.filter(id=customers_id).values())[0]
        return render(request, 'funcpage/edit_customers.html', context=customers_data)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 客户编辑保存
def edit_customers_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        medicine = Customers_suppliers.objects.filter(id=request.POST.get('id'))
        medicine.update(cs_postCode=request.POST.get('cs_postCode'),
                        cs_address = request.POST.get('cs_address'),
                        cs_tel = request.POST.get('cs_tel'),
                        cs_unit = request.POST.get('cs_unit'),
                        cs_name = request.POST.get('cs_name'))
        return redirect('/khpg')
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 删除客户
def del_customers(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        customers_suppliers = Customers_suppliers.objects.get(id = request.GET.get('id'))
        customers_suppliers.delete()
        return redirect("/khpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 供应商管理
def gyspg(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        # 判断是否有查询信息
        if request.GET.get('s') is None or request.GET.get('s') == '':
            customers_suppliers = Customers_suppliers.objects.filter(
            cs_attitude='供应商').values()
            context = {'customers_suppliers': customers_suppliers}
            return render(request, 'funcpage/gyspg.html', context=context)
        # 返回符合查询内容的列表
        customers_suppliers = Customers_suppliers.objects.filter(cs_unit__contains = request.GET.get('s')).values()
        context = {'customers_suppliers': customers_suppliers}
        return render(request, 'funcpage/gyspg.html', context=context)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 新增供应商
def add_suppliers(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        suppliers = Customers_suppliers(cs_attitude = request.POST.get('cs_attitude'), 
                            cs_postCode = request.POST.get('cs_postCode'), 
                            cs_address = request.POST.get('cs_address'), 
                            cs_tel = request.POST.get('cs_tel'),
                            cs_unit = request.POST.get('cs_unit'), 
                            cs_name = request.POST.get('cs_name'))
        suppliers.save()
        return redirect("/gyspg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 供应商编辑页面
def edit_suppliers_page(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        suppliers_id = request.GET.get('id')
        suppliers_data = list(Customers_suppliers.objects.filter(id=suppliers_id).values())[0]
        return render(request, 'funcpage/edit_suppliers.html', context=suppliers_data)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 供应商编辑保存
def edit_suppliers_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        suppliers = Customers_suppliers.objects.filter(id=request.POST.get('id'))
        suppliers.update(cs_postCode=request.POST.get('cs_postCode'),
                        cs_address = request.POST.get('cs_address'),
                        cs_tel = request.POST.get('cs_tel'),
                        cs_unit = request.POST.get('cs_unit'),
                        cs_name = request.POST.get('cs_name'))
        return redirect('/gyspg')
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 删除供应商
def del_suppliers(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1 or admin_user_role == 3):
        customers_suppliers = Customers_suppliers.objects.get(id = request.GET.get('id'))
        customers_suppliers.delete()
        return redirect("/gyspg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 统计分析
def tjpg(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        try:
            # 年销售额/成本/占比
            # 年数据
            year_data = {}
            now_year = datetime.now().year
            year_in_warehouse_record = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '入库', wr_in_out_time__year = now_year).values())
            year_out_warehouse_record = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '出库', wr_in_out_time__year = now_year).values())
            # 年收入
            year_data['year_income'] = sum(year_out_warehouse_record['wr_amount'])
            # 年支出
            year_data['year_expenditure'] = sum(year_in_warehouse_record['wr_amount'])
            # 年利润
            year_data['year_profit'] = year_data['year_income'] - year_data['year_expenditure']
            # 年盈亏比
            year_data['year_ratio'] = round((year_data['year_profit'] / year_data['year_expenditure']) * 100, 3)
            # 月销售额/成本/占比
            # 月数据
            month_data = {}
            now_month = datetime.now().month
            month_in_warehouse_record = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '入库', wr_in_out_time__month = now_month).values())
            month_out_warehouse_record = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '出库', wr_in_out_time__month = now_month).values())
            # 月收入
            month_data['month_income'] = sum(month_out_warehouse_record['wr_amount'])
            # 月支出
            month_data['month_expenditure'] = sum(month_in_warehouse_record['wr_amount'])
            # 月利润
            month_data['month_profit'] = month_data['month_income'] - month_data['month_expenditure']
            # 月盈亏比
            month_data['month_ratio'] = round((month_data['month_profit'] / month_data['month_expenditure']) * 100, 3)
            # 药品排行
            medicine_ranking = {}
            # 年药品排行
            year_medicine = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '出库', wr_in_out_time__year = now_year).values())
            year_medicine = year_medicine.sort_values('wr_amount')
            year_medicine_ranking = year_medicine.groupby(['wr_medicine_name'])['wr_amount'].sum()[::-1]
            medicine_ranking['year_medicine_ranking'] = year_medicine_ranking.to_dict()
            # 月药品排行
            month_medicine = pd.DataFrame(Warehouse_record.objects.filter(wr_in_out = '出库', wr_in_out_time__month = now_month).values())
            month_medicine = month_medicine.sort_values('wr_amount')
            month_medicine_ranking = month_medicine.groupby(['wr_medicine_name'])['wr_amount'].sum()[::-1]
            medicine_ranking['month_medicine_ranking'] = month_medicine_ranking.to_dict()
            # 盈利亏损情况
            pl = {}
            pl['year'] = True
            pl['month'] = True
            if year_data['year_profit'] < 0:
                pl['year'] = False
            if month_data['month_profit'] < 0:
                pl['month'] = False
            context = {'year_data': year_data, 'month_data': month_data, 'medicine_ranking': medicine_ranking, 'pl': pl}
            return render(request, 'funcpage/tjpg.html', context=context)
        except:
            return render(request, 'funcpage/error.html', context={'info': '现有出入库数据无法进行统计分析!', 'up': ''})
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 库存数据下载
def down_kc(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        # 生成数据文件
        data = pd.DataFrame(Medicines.objects.all().values())
        data.to_excel('hnyhms_app/data_file/kc_data.xls', index=False)
        # 返回文件
        file = open('hnyhms_app/data_file/kc_data.xls', 'rb')
        response = FileResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="kc_data_' + datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S') + '.xls"'
        return response
    return render(request, 'funcpage/error.html', context={'info': '您没有权限下载文件!', 'up': '/'})
# 出入库记录下载
def down_io(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        # 生成数据文件
        data = pd.DataFrame(Warehouse_record.objects.all().values())
        data.to_excel('hnyhms_app/data_file/io_data.xls', index=False)
        # 返回文件
        file = open('hnyhms_app/data_file/io_data.xls', 'rb')
        response = FileResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="io_data_' + datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S') + '.xls"'
        return response
    return render(request, 'funcpage/error.html', context={'info': '您没有权限下载文件!', 'up': '/'})
# 客户数据下载
def down_kh(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        # 生成数据文件
        data = pd.DataFrame(Customers_suppliers.objects.filter(cs_attitude='客户').values())
        data.to_excel('hnyhms_app/data_file/cs_data.xls', index=False)
        # 返回文件
        file = open('hnyhms_app/data_file/cs_data.xls', 'rb')
        response = FileResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="cs_data_' + datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S') + '.xls"'
        return response
    return render(request, 'funcpage/error.html', context={'info': '您没有权限下载文件!', 'up': '/'})
# 供应商数据下载
def down_gys(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        # 生成数据文件
        data = pd.DataFrame(Customers_suppliers.objects.filter(cs_attitude='供应商').values())
        data.to_excel('hnyhms_app/data_file/gys_data.xls', index=False)
        # 返回文件
        file = open('hnyhms_app/data_file/gys_data.xls', 'rb')
        response = FileResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="gys_data_' + datetime.strftime(datetime.now(),'%Y-%m-%d %H:%M:%S') + '.xls"'
        return response
    return render(request, 'funcpage/error.html', context={'info': '您没有权限下载文件!', 'up': '/'})
# 系统管理
def xtpg(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        admin_users = Admin_users.objects.all().values()
        context = {'admin_users': admin_users}
        return render(request, 'funcpage/xtpg.html', context=context)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 新增管理员
def add_admin_users(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        admin_users = Admin_users(au_name = request.POST.get('au_name'), 
                            au_account = request.POST.get('au_account'), 
                            au_pwd = request.POST.get('au_pwd'), 
                            au_role = request.POST.get('au_role'), 
                            au_tel = request.POST.get('au_tel'))
        admin_users.save()
        return redirect("/xtpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 管理员编辑页面
def edit_admin_page(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        admin_id = request.GET.get('id')
        admin_data = list(Admin_users.objects.filter(id=admin_id).values())[0]
        return render(request, 'funcpage/edit_admin.html', context=admin_data)
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 管理员编辑保存
def edit_admin_save(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        admin = Admin_users.objects.filter(id=request.POST.get('id'))
        if request.POST.get('au_pwd') == '':
            admin.update(au_name=request.POST.get('au_name'),
                        au_account = request.POST.get('au_account'),
                        au_role = request.POST.get('au_role'),
                        au_tel = request.POST.get('au_tel'))
        else:
            admin.update(au_name=request.POST.get('au_name'),
                            au_account = request.POST.get('au_account'),
                            au_pwd = request.POST.get('au_pwd'),
                            au_role = request.POST.get('au_role'),
                            au_tel = request.POST.get('au_tel'))
        return redirect('/xtpg')
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)
# 删除管理员
def del_adminuser(request):
    # 收到浏览器的再次请求,判断浏览器携带的cookie是不是登录成功的时候响应的cookie
    adminuser = request.COOKIES.get('adminuser')
    # 权限判断
    admin_user_role = Admin_users.objects.get(au_account = adminuser).au_role
    if adminuser is not None and (admin_user_role == 1):
        admin_users = Admin_users.objects.get(id = request.GET.get('id'))
        admin_users.delete()
        return redirect("/xtpg")
    return render(request, 'funcpage/error.html', context={'info': '您没有权限访问该页面!', 'up': '/'}, status=403)

image.gif

from django.db import models
# Create your models here.
# 管理员
class Admin_users(models.Model):
    au_name = models.CharField('姓名', max_length=30)
    au_account = models.CharField('账号', max_length=30)
    au_pwd = models.CharField('密码', max_length=30)
    au_role = models.IntegerField('角色', default=2)
    au_tel = models.CharField('电话', max_length=30)
    def __str__(self):
        return self.au_name
    class Meta:
        verbose_name = '管理员'
        verbose_name_plural = '管理员'
# 供应商和客户
class Customers_suppliers(models.Model):
    cs_attitude = models.CharField('供应商/客户', max_length=20)
    cs_postCode = models.IntegerField('邮编', default=0)
    cs_address = models.CharField('地址', max_length=50)
    cs_tel = models.CharField('电话', max_length=20)
    cs_unit = models.CharField('单位', max_length=30)  # 单位
    cs_name = models.CharField('联系人', max_length=30)  # 联系人
    def __str__(self):
        return self.cs_unit
    class Meta:
        verbose_name = '供应商和客户'
        verbose_name_plural = '供应商和客户'
# 药品
class Medicines(models.Model):
    medicine_name = models.CharField('药品名', max_length=30)
    medicine_manufacturers = models.CharField('生产商', max_length=30)  # 生产商
    medicine_trademark = models.CharField('品牌', max_length=30)  # 品牌
    medicine_production_address = models.CharField('生产地址', max_length=50)  # 生产地址
    medicine_code = models.CharField('条码号', max_length=30)
    medicine_specification = models.CharField('规格', max_length=20)  # 规格
    medicine_purchase = models.FloatField('进货价', default=0)  # 进货价
    medicine_selling = models.FloatField('出售价', default=0)  # 出售价
    medicine_quantity = models.IntegerField('数量', default=0)  # 出售价
    def __str__(self):
        return self.medicine_name
    class Meta:
        verbose_name = '药品'
        verbose_name_plural = '药品'
# 出入库
class Warehouse_record(models.Model):
    wr_in_out = models.CharField('入库/出库', max_length=20)
    wr_quantity = models.IntegerField('数量', default=0)  # 出入库量
    wr_cs_name = models.CharField('供应商/客户', max_length=20)
    wr_admin_name = models.CharField('记录管理员', max_length=20)
    wr_medicine_name = models.CharField('药品名', max_length=20)
    wr_in_out_time = models.DateField('时间', auto_now=True)
    wr_amount = models.FloatField('金额', default=0)
    class Meta:
        verbose_name = '出入库记录'
        verbose_name_plural = '出入库记录'

image.gif


相关文章
|
22天前
|
机器学习/深度学习 数据采集 供应链
使用Python实现智能食品安全追溯系统的深度学习模型
使用Python实现智能食品安全追溯系统的深度学习模型
48 4
|
1天前
|
机器学习/深度学习 人工智能 算法
猫狗宠物识别系统Python+TensorFlow+人工智能+深度学习+卷积网络算法
宠物识别系统使用Python和TensorFlow搭建卷积神经网络,基于37种常见猫狗数据集训练高精度模型,并保存为h5格式。通过Django框架搭建Web平台,用户上传宠物图片即可识别其名称,提供便捷的宠物识别服务。
87 55
|
11天前
|
机器学习/深度学习 人工智能 算法
【宠物识别系统】Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+图像识别
宠物识别系统,本系统使用Python作为主要开发语言,基于TensorFlow搭建卷积神经网络算法,并收集了37种常见的猫狗宠物种类数据集【'阿比西尼亚猫(Abyssinian)', '孟加拉猫(Bengal)', '暹罗猫(Birman)', '孟买猫(Bombay)', '英国短毛猫(British Shorthair)', '埃及猫(Egyptian Mau)', '缅因猫(Maine Coon)', '波斯猫(Persian)', '布偶猫(Ragdoll)', '俄罗斯蓝猫(Russian Blue)', '暹罗猫(Siamese)', '斯芬克斯猫(Sphynx)', '美国斗牛犬
77 29
【宠物识别系统】Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+图像识别
|
12天前
|
机器学习/深度学习 算法 前端开发
基于Python深度学习的果蔬识别系统实现
果蔬识别系统,主要开发语言为Python,基于TensorFlow搭建ResNet卷积神经网络算法模型,通过对12种常见的果蔬('土豆', '圣女果', '大白菜', '大葱', '梨', '胡萝卜', '芒果', '苹果', '西红柿', '韭菜', '香蕉', '黄瓜')图像数据集进行训练,最后得到一个识别精度较高的模型文件。再基于Django框架搭建Web网页端可视化操作界面,以下为项目实现介绍。
23 4
基于Python深度学习的果蔬识别系统实现
|
1月前
|
设计模式 前端开发 数据库
Python Web开发:Django框架下的全栈开发实战
【10月更文挑战第27天】本文介绍了Django框架在Python Web开发中的应用,涵盖了Django与Flask等框架的比较、项目结构、模型、视图、模板和URL配置等内容,并展示了实际代码示例,帮助读者快速掌握Django全栈开发的核心技术。
160 45
|
1月前
|
弹性计算 数据管理 数据库
从零开始构建员工管理系统:Python与SQLite3的完美结合
本文介绍如何使用Python和Tkinter构建一个图形界面的员工管理系统(EMS)。系统包括数据库设计、核心功能实现和图形用户界面创建。主要功能有查询、添加、删除员工信息及统计员工数量。通过本文,你将学会如何结合SQLite数据库进行数据管理,并使用Tkinter创建友好的用户界面。
55 2
从零开始构建员工管理系统:Python与SQLite3的完美结合
|
25天前
|
Python
Python之音乐专辑管理系统
音乐专辑管理系统是一款用于管理和维护音乐专辑信息的应用程序,支持添加、删除、修改和查询专辑详情(如专辑名、艺术家、发行日期及曲目列表)。系统运行需Python 3.x环境,硬件要求较低,适合个人及小型团队使用。
47 4
|
28天前
|
Python
Django 框架的路由系统
Django 框架的路由系统
39 6
|
27天前
|
Python
Python实现摇号系统
本文介绍了如何使用Python构建一个简单的摇号系统,包括用户输入、随机抽取、结果展示和日志记录等功能。通过导入`random`、`datetime`和`logging`模块,实现了从参与者名单中随机抽取中奖者,并记录每次摇号的结果,方便后续查看和审计。完整代码示例提供了从功能实现到主程序调用的全过程。
34 2
|
29天前
|
机器学习/深度学习 人工智能 算法
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络
垃圾识别分类系统。本系统采用Python作为主要编程语言,通过收集了5种常见的垃圾数据集('塑料', '玻璃', '纸张', '纸板', '金属'),然后基于TensorFlow搭建卷积神经网络算法模型,通过对图像数据集进行多轮迭代训练,最后得到一个识别精度较高的模型文件。然后使用Django搭建Web网页端可视化操作界面,实现用户在网页端上传一张垃圾图片识别其名称。
75 0
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络