利用TP5做学生信息补录系统

    xiaoxiao2022-07-07  180

    学生信息补录系统

    用户页面用户登录登陆成功后显示个人信息确认信息后填写家长信息界面退出当前登录用户 管理员后台页面管理员登录界面管理员登录成功界面导入数据:导入数据表页面查看数据:学生信息进行分页显示导出数据:以Excel的形式导出数据库中的表统计数据:前端显示各个学院完成情况,分别用表格和图表显示退出当前登录管理员用户

    用户页面

    涉及用户文件夹

    用户登录

    如上图,利用bootstrap做的学生用户登录界面

    表单 application/index/view/index/login.html <div class="panel panel-primary"> <div class="panel-heading text-center"> <h2>泸职院学生信息补录系统</h2> </div> <div class="panel-body"> <h3 class="text-center">用户登录</h3> <form class="form-horizontal" role="form" method="post" action="{:url('logincheck')}"> //将表单交给Index模块下面的logincheck方法 <div class="form-group"> <label for="stuno">学号</label> <input type="text" class="form-control" id="stuno" placeholder="请输入学号" name="stuno"> </div> <div class="form-group"> <label for="idnum">身份证号</label> <input type="password" class="form-control" id="idnum" placeholder="请输入身份证号" name="idnum"> </div> <div class="form-group"> <button type="submit" class="btn btn-success form-control input-lg">登录</button> </div> <p>说明:根据教育部《关于做好高等学校学生数据信息核准和补录工作的通知》(教学司函<2019>)的要求,配合个人所得税专项附加扣除,特核对学生信息和补录学生父母或监护人信息,此教据将关系到您及您的家庭的切身利益,请各位同学认真对待,仔细核对,准确填写。</p> </form> </div> </div>

    2.前端jquery对表单进行非空验证 application/index/view/index/login.html

    <script type="text/javascript"> $().ready(function(){ $("form").submit(function(){ var stuno=$("#stuno").val(); var idnum=$("#idnum").val(); if(stuno==""){ alert("请输入学号!"); $("#stuno").focus(); return false; }; if(idnum==""){ alert("请输入身份证号!"); $("#idnum").focus(); return false; } }); }); </script> 后台进行用户登录判断 application/index/controller/Index.php <?php namespace app\index\controller; use think\Controller; use think\Db; use think\Session; class Index extends Controller{ public function index(){ return $this->fetch("index/login"); } public function logincheck(){ $stuno=input('post.stuno'); $idnum=input('post.idnum'); if(Db::table("tb_stu")->where('stuno',$stuno)->where('idnum',$idnum)->find()){ Session::set("idnum",$idnum); Db::table('tb_stu')->where('idnum',$idnum)->setInc('loginnum');//登录成功数据表中登录次数字段自增1 return $this->success("登录成功","Stu/index"); } else{ return $this->error("学号和身份证号不正确"); } } } ?>

    登陆成功后显示个人信息

    application/index/view/Stu/index.html 1.显示学生信息

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> {load href="__STATIC__/bootstrap-3.3.7/css/bootstrap.min.css" /} </head> <body> <table class="table"> <h2 class="text-center">学生信息表</h2> <tr class="active"> <td>学号</td> <td>{$info.stuno}</td> </tr> <tr class="success"> <td>身份证</td> <td>{$info.idnum}</td> </tr> <tr class="warning"> <td>姓名</td> <td>{$info.truename}</td> </tr> <tr class="danger"> <td>学校</td> <td>{$info.college}</td> </tr> <tr class="info"> <td>入学时间</td> <td>{$info.starttime}</td> </tr> <tr class="active"> <td>在校情况</td> <td>{$info.status}</td> </tr> </table> <center> <a href="{:url('confirm')}"><button type="button" class="btn btn-primary btn-lg active text-center">确认信息</button></a> <a href="{:url('loginout')}"><button type="button" class="btn btn-primary btn-lg active text-center">退出登录</button></a> </center> </body> </html>

    2.后台确认信息 application/index/controller/Stu.php

    <?php namespace app\index\controller; use think\Controller; use think\Db; use think\Session; class Stu extends Controller{// public function _initialize(){ if(!session::has('idnum')){ return $this->success("请先登录!","index"); } } public function index(){//查询学生信息 $info=Db::table("tb_stu")->where("idnum",session::get('idnum'))->find(); $this->assign('info',$info); return $this->fetch(); } public function confirm(){//修改学生表确认信息状态 if(Db::table("tb_stu")->where('idnum',session::get('idnum'))->update(['confirm'=>1,'lasttime'=>date("Y-m-d H:i:s",time())])){ $this->redirect("showparents"); } else{ echo "操作失败"; } }

    确认信息后填写家长信息界面

    application/index/view/Stu/showparents.html 1.显示家长信息表单

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> {load href="__STATIC__/bootstrap-3.3.7/css/bootstrap.min.css" /} {load href="__JS__/jquery.min.js" /} </head> <body> <script type="text/javascript">//判断表单信息不为空 $().ready(function(){ $("form").submit(function(){ var relation1=$("#relation1").val(); var relation2=$("#relation2").val(); var pname1=$("#pname1").val(); var pname2=$("#pname2").val(); var pidnum1=$("#pidnum1").val(); var pidnum2=$("#pidnum2").val(); if(relation1==""){ alert("请选择家长1关系!"); $("#relation1").focus(); return false; }; if(pname1==""){ alert("请输入家长1姓名!"); $("#pname1").focus(); return false; }; if(pidnum1==""){ alert("请输入家长1身份证号!"); $("#pidnum1").focus(); return false; }; if(relation2==""){ alert("请选择家长2关系!"); $("#relation2").focus(); return false; }; if(pname2==""){ alert("请输入家长2姓名!"); $("#pname2").focus(); return false; }; if(pidnum2==""){ alert("请输入家长2身份证号!"); $("#pidnum2").focus(); return false; } }); }); </script> <form action="{:url('parentswrite')}" class="form-horizontal" role="form" method="POST"> <table class="table"> <h2 class="text-center">家长信息表</h2> <tr class="active"> <td><label for="relation1">家长1关系</label></td> <td> <select name="relation1" id="relation1"> <option value="" {eq name="info.relation1" value="">} selected="selected"{/eq}>--选择家长1与本人关系--</option> <option value="1" {eq name="info.relation1" value="1">} selected="selected"{/eq}>父亲</option> <option value="2" {eq name="info.relation1" value="2">} selected="selected"{/eq}>母亲</option> <option value="3" {eq name="info.relation1" value="3">} selected="selected"{/eq}>其他监护人</option> </select> </td> </tr> <tr class="success"> <td><label for="pname1">家长1姓名</label></td> <td><input type="text" id="pname1" placeholder="家长1姓名" name="pname1" value="{$info.pname1}"></td> </tr> <tr class="warning"> <td><label for="pidnum1">家长1身份证号</label></td> <td><input type="text" id="pidnum1" placeholder="家长1身份证号" name="pidnum1" value="{$info.pidnum1}"></td> </tr> <tr class="danger"> <td><label for="relation2">家长2关系</label></td> <td><select name="relation2" id="relation2"> <option value="" {eq name="info.relation2" value="">} selected="selected"{/eq}>--选择家长2与本人关系--</option> <option value="1" {eq name="info.relation2" value="1">} selected="selected"{/eq}>父亲</option> <option value="2" {eq name="info.relation2" value="2">} selected="selected"{/eq}>母亲</option> <option value="3" {eq name="info.relation2" value="3">} selected="selected"{/eq}>其他监护人</option> </select></td> </tr> <tr class="info"> <td><label for="pname2">家长2姓名</label></td> <td><input type="text" id="pname2" placeholder="家长2姓名" name="pname2" value="{$info.pname2}"></td> </tr> <tr class="active"> <td><label for="pidnum2">家长2身份证号</label></td> <td><input type="text" id="pidnum2" placeholder="家长2身份证号" name="pidnum2" value="{$info.pidnum2}"></td> </tr></table> <input type="submit" class="btn btn-success form-control input-lg"> </form> </body> </html>

    2.后台查询家长信息 application/index/controller/Stu.php

    public function showparents(){//显示家长信息 $info=Db::table('tb_stu')->where('idnum',session::get('idnum'))->find(); $this->assign('info',$info); return $this->fetch(); }

    3.写入家长信息 application/index/controller/Stu.php

    public function parentswrite(){ $relation1=input('post.relation1'); $pname1=input('post.pname1'); $pidnum1=input('post.pidnum1'); $relation2=input('post.relation2'); $pname2=input('post.pname2'); $pidnum2=input('post.pidnum2'); if(Db::table("tb_stu")->where('idnum',session::get('idnum'))->update(['relation1'=>$relation1,'pname1'=>$pname1,'pidnum1'=>$pidnum1,'relation2'=>$relation2,'pname2'=>$pname2,'pidnum2'=>$pidnum2,'uptime'=>date("Y-m-d H:i:s",time())])){ return $this->success("家长信息添加成功","Stu/index"); } else{ return $this->error("家长信息添加失败"); } }

    退出当前登录用户

    家长信息成功写入后返回学生详细信息页面,学生可选择退出登录 application/index/controller/Stu.php

    public function loginout(){//退出登录 session_destroy(); session_unset(); return $this->success("退出成功!","index/index"); }

    管理员后台页面

    涉及后台管理员文件夹

    管理员登录界面

    1.管理员登陆表单 application/admin/view/Login/index.html

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> {load href="__STATIC__/bootstrap-3.3.7/css/bootstrap.min.css" /} {js href="__JS__/jquery.min.js" /} </head> <body> <h2 class="text-center">管理员登录</h2> <form class="form-horizontal" role="form" action="{:url('check')}" method="post"> <div class="form-group"> <label for="username" class="col-sm-2 control-label">用户名</label> <div class="col-sm-10"> <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">密码</label> <div class="col-sm-10"> <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码"> </div> </div> <div class="form-group"> <label for="vcode" class="col-sm-2 control-label">验证码</label> <div class="col-sm-5"> <input type="text" class="form-control" id="vcode" name="vcode" placeholder="请输入验证码"> </div> <div class="col-sm-2" style="height:50px;"> <div id="vcode_img"><img src="{:captcha_src()}" alt="captcha"></div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <input type="submit" class="btn btn-default" value="登录"> <!-- <button type="submit" class="btn btn-default">登录</button> --> </div> </div> </form> <script type="text/javascript">//验证码 $(function(){ $("#vcode_img img").click(function(){ var src=$(this).attr("src"); var newsrc=src+"?"+Math.random(); $(this).attr("src",newsrc); }) }) </script> </body> </html>

    2.登录判断 application/admin/controller/Login.php

    <?php namespace app\admin\controller; use think\Controller; use think\Session; use think\Db; class Login extends Controller{ public function index(){ return $this->fetch(); } public function check(){ $vcode=input('post.vcode'); $username=input('post.username'); $password=sha1(md5(input('post.password'))); if(!captcha_check($vcode)){ echo "验证码错误"; } else{ if(Db::table("tb_admin")->where('username',$username)->where('password',$password)->find()){ Session::set("info_admin",$username); return $this->success("登录成功","Admin/index"); } else{ return $this->error("用户名或密码不正确"); } } } } ?>

    管理员登录成功界面

    因为后台管理页面头部都相同,避免改一处另一处没改到,所有用layout模板标签 application/admin/view/Admin/layout.html

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> {load href="__STATIC__/bootstrap-3.3.7/css/bootstrap.min.css" /} {js href="__JS__/jquery.min.js"} {js href="__STATIC__/JS/echarts.min.js"} {js href="__STATIC__/bootstrap-3.3.7/js/bootstrap.min.js"} </head> <body> <center> <h2>欢迎来到后台管理页面</h2> <ul class="breadcrumb"> <li class="active"><a href="{:url('index')}">首页</a></li> <li class="active"><a href="{:url('count')}">统计数据</a></li> <li class="active"><a href="{:url('import')}">导入数据</a></li> <li class="active"><a href="{:url('info')}">查看数据</a></li> <li class="active"><a href="{:url('down')}">导出数据</a></li> <li class="active"><a href="{:url('loginout')}">退出登录</a></li> <li class="active"></li> <li class="active"></li> </ul> </center> {__CONTENT__} <footer><div class="text-center footer_text"><a href="http://www.lzy.edu.cn">泸州职业技术学院官网</a> | <span>学院地址:泸州市龙马潭区红星街道长桥路2号</span> | <span>邮编:646000</span></div> </footer> </body> </html>

    application/admin/view/Admin/index.html和其他页面要用时

    {layout name="admin/layout"} <h3>欢迎来到后台页面</h3>

    导入数据:导入数据表页面

    1.前端页面 application/admin/view/Admin/import.php

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> {load href="__STATIC__/bootstrap-3.3.7/css/bootstrap.min.css" /} {js href="__JS__/jquery.min.js" /} </head> <body> <h2 class="text-danger">第一步:下载空数据表</h2> <a href="__ROOT__/down/stu.xls">【点击下载】</a> <h2 class="text-info">第二步:上传数据表</h2> <form class="form-horizontal" role="form" action="{:url('importWrite')}" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="excelfile" class="col-sm-2 control-label">导入学生基础信息</label> <div class="col-sm-10"> <input type="file" class="form-control col-sm-10" id="excelfile" name="excelfile" placeholder=""> </div> </div> <div class="form-group"> <label for="key" class="col-sm-2 control-label">口令</label> <div class="col-sm-10"> <input type="text" class="form-control" id="key" name="key" placeholder="请输入口令"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <input type="submit" class="btn btn-default"> <!-- <button type="submit" class="btn btn-default">登录</button> --> </div> </div> </form> </body> </html>

    2.后台 application/admin/controller/Admin.php

    <?php namespace app\admin\controller; use think\Controller; use think\Session; use think\Db; use PHPExcel_IOFactory; use PHPExcel; use think\paginate; class Admin extends Controller{ public function _initialize(){ if(!session::has('info_admin')){ return $this->success("请先登录!","Login/index"); } else{ $this->admin=session::get("info_admin"); } } public function index(){//显示后台页面 return $this->fetch(); } public function import(){ return $this->fetch(); } public function importWrite(){//导入文件 $key=input("post.key"); if($key!='123'){ return $this->error("口令错误"); } $file=request()->file('excelfile'); $info=$file->validate(['ext'=>'xls,xlsx','size'=>10240000])->move(ROOT_PATH.'public/uploads'); if($info){ $fileName=$info->getSaveName(); $fileName=ROOT_PATH . 'public' . DS . 'uploads'."/". $fileName; //$fileName=ROOT_PATH.'public/uploads/'.$fileName; if($info->getExtension()=='xls'){ $objReader = \PHPExcel_IOFactory::createReader('Excel5'); }else{ $objReader = \PHPExcel_IOFactory::createReader('Excel2007'); } $objPHPExcel = $objReader->load($fileName,$encode='utf-8'); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 $datalist=array(); $writenum=0; $key=0; for($i=2;$i<=$highestRow;$i++){//循环读取各行 if($writenum>=3000){ $key++; $writenum=0; } $stuno=$sheet->getCell('B'.$i)->getValue(); $truename=$sheet->getCell('C'.$i)->getValue(); $idnum=$sheet->getCell('D'.$i)->getValue(); $college=$sheet->getCell('G'.$i)->getValue(); $starttime=$sheet->getCell('E'.$i)->getValue(); $status=$sheet->getCell('F'.$i)->getValue(); $datalist[$key][]=array( 'stuno'=>$stuno, 'truename'=>$truename, 'idnum'=>$idnum, 'college'=>$college, 'starttime'=>$starttime, 'status'=>$status, ); $writenum++; } $num=0; foreach ($datalist as $key=> $value) { if(Db::table('tb_stu')->insertAll($value)){ $num+=count($value); }else{ echo "写入失败"; } } echo $num; } }

    查看数据:学生信息进行分页显示

    1.前端显示 application/admin/view/Admin/info.html

    {layout name="admin/layout"} <script type="text/javascript">//点击学生id模态框中显示学生详细信息 $(function(){ $(".truename").click(function(){ var id=$(this).attr("data-id"); $.post("{:url('ajaxGetInfo')}",{id:id},function(data){ $("#modal-truename").text(data.truename); $("#modal-stuno").text(data.stuno); $("#modal-college").text(data.college); $("#modal-idnum").text(data.idnum); $("#myModal").modal('show'); }); }); }); </script> <table class="table table-striped"> <caption class="text-center"><h2>学生详细信息表</h2></caption> <thead> <tr> <th>序号</th> <th>姓名</th> <th>身份证号</th> <th>学号</th> </tr> </thead> <tbody> {volist name='info' id='vo'} <tr> <td>{$i+($nowpage-1)*10}</td> <td class="truename" data-id="{$vo.id}">{$vo.truename}</td> <td>{$vo.idnum}</td> <td>{$vo.stuno}</td> </tr> {/volist} </tbody> </table><center> {$info->render()} </center> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel"><span id="modal-truename"></span>的详细信息如下</h4> </div> <div class="modal-body"> <p>学号:<span id="modal-stuno"></span></p> <p>学院:<span id="modal-college"></span></p> <p>身份证号:<span id="modal-idnum"></span></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div>

    2.后台 application/admin/controller/Admin.php

    public function info(){//学生信息分页 $info=Db::table('tb_stu')->order('id desc')->paginate(20); $nowpage=$info->getCurrentPage(); $this->assign('nowpage',$nowpage); $this->assign('info',$info); return $this->fetch('info'); } public function ajaxGetInfo(){ $id=input("post.id"); $info=Db::table("tb_stu")->where("id",$id)->find(); $info=json($info); return $info; }

    导出数据:以Excel的形式导出数据库中的表

    1.前端点击导出数据就会自动新建一个excel文件装数据并下载 application/admin/controller/Admin.php

    public function down(){ //导出数据库 $fileName="数据导出文件";//导出文件的名称 $PHPExcel = new \PHPExcel();//创建一个PHPExcel对象 $PHPExcel->createSheet();//创建工作表 $subObject = $PHPExcel->getSheet(0);//选择第一个工作表 $subObject->setTitle('数据表');//设置工作表名称 $subObject->mergeCells('A1:D1'); $subObject->getStyle('A1')->getFont()->setBold(true); $subObject->getStyle('A1')->getFont()->setSize(18); //填入标题行 $topNumber = 2;//表头有几行占用 $subObject->setCellValue('A1',"数据导出文件"); $subObject->setCellValue('A2','序号');//设置某个单元格的值 $subObject->setCellValue('B2','姓名'); $subObject->setCellValue('C2','身份证号'); $subObject->setCellValue('D2','学号'); //填入列表 $info=Db::table("tb_stu")->select(); $k=1;//序号 $r=3;//行号 foreach($info as $value){ $subObject->setCellValue('A'.($r),$k); $subObject->setCellValue('B'.($r),$value['truename']); $subObject->setCellValue('C'.($r),$value['idnum']); $subObject->setCellValue('D'.($r),$value['stuno']); $k++; $r++; } $objWriter =\PHPExcel_IOFactory:: createWriter($PHPExcel, 'Excel2007'); //创建EXCEL写入对象 ob_end_clean();//消除缓存,否则导出的将是乱码 header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download"); $ua = $_SERVER["HTTP_USER_AGENT"]; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); if (preg_match("/Firefox/", $ua)) {//如果是火狐浏览器 header('Content-Disposition: attachment; filename*="utf8\'\'' . $fileName . '.xlsx"'); } else{ $fileName = urlencode($fileName); header("Content-Disposition: attachment; filename=".$fileName.".xlsx"); } header('Cache-Control: max-age=0'); $objWriter->save( 'php://output'); }

    统计数据:前端显示各个学院完成情况,分别用表格和图表显示

    1.前端显示页面 application/admin/view/Admin/count.html

    {layout name="admin/layout"} <table class="table table-striped"> <caption class="text-center"><h2>学生完成情况统计表</h2></caption> <thead> <tr> <th>序号</th> <th>学院</th> <th>学生总人数</th> <th>学生完成人数</th> <th>完成比例</th> </tr> </thead> <tbody> {volist name='info' id='vo'} <tr> <td>{$i}</td> <td>{$vo.college}</td> <td>{$vo.allnum}</td> <td>{$vo.overnum}</td> <td>{$vo.pe}</td> </tr> {/volist} </tbody> </table> <br> <center><div id="main" style="width: 1200px;height:400px;"></div></center> <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 var option = { title: { text: '学生完成情况' }, tooltip: {}, legend: { data:['学生总人数','完成人数'] }, xAxis: { data: [{volist name='info' id='vo'}"{$vo.college}",{/volist}] }, yAxis: {}, series: [ { name: '学生总人数', type: 'bar', barGap: 0, data: [{volist name="info" id="vo"}{$vo.allnum},{/volist}] }, { name: '完成人数', type: 'bar', barGap: 0, data: [{volist name="info" id="vo"}{$vo.overnum},{/volist}] } ] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); </script>

    2.后台 application/admin/controller/Admin.php

    public function count(){//学生信息统计 $collegearr=Db::table('tb_stu')->distinct(true)->column('college'); $info=array(); foreach($collegearr as $key=>$value){ $info[$key]['college']=$value; $info[$key]['allnum']=Db::table("tb_stu")->where('college',$value)->count(); $where['college']=$value; $where['relation1']=['<>','null']; $info[$key]['overnum']=Db::table('tb_stu')->where($where)->count(); $info[$key]['pe']=round($info[$key]['overnum']/$info[$key]['allnum']*100,2)."%"; }; $this->assign('info',$info); return $this->fetch('count'); }

    退出当前登录管理员用户

    application/admin/controller/Admin.php

    public function loginout(){//退出登录 session_destroy(); session_unset(); return $this->success("退出成功!","Login/index"); }
    最新回复(0)