diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 412d2245..3f32eb73 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -158,17 +158,46 @@ class Index extends Base // 删除空单元格得到学科列名数组 array_splice($cjinfo[1],0,4); $xk = $cjinfo[1]; - - + // 删除成绩采集表无用的标题行得到成绩数组 array_splice($cjinfo,0,3); + // 查询考试信息 + $kh = new Kaohao; + $ks = new \app\kaoshi\model\Kaoshi; $user_id = session('userid'); // 重新组合成绩信息 foreach ($cjinfo as $key => $value) { foreach ($xk as $k => $val) { - if($value[$k+4] === null){ + + $thissbj = $val; # 当前学科 + $defen = $value[$k+4]; # 当前学科 + + // 如果不存在值,跳过这次循环 + if($defen === null){ + continue; + } + // 如果不为数字、则跳过 + if(is_numeric($defen)==false){ + continue; + } + + + $kaoshiid = $kh->where('id',$value[1])->value('kaoshi'); + $manfen = $ks->where('id',$kaoshiid) + ->field('id') + ->with([ + 'ksSubject'=>function($query) use($thissbj){ + $query->field('kaoshiid,subjectid,manfen') + ->where('subjectid',$thissbj); + } + ]) + ->find(); + + // 如果大于满分、小于0分的时候也跳过 + if( $defen<0 || $defen>$manfen->ks_subject[0]->manfen ) + { continue; } // 查询是否存在这个成绩 @@ -183,7 +212,7 @@ class Index extends Base 'kaohao_id'=>$value[1], 'subject_id'=>$val, 'user_id'=>$user_id, - 'defen'=>$value[$k+4] + 'defen'=>$defen ]); } } @@ -273,8 +302,6 @@ class Index extends Base $data = $chengji->srcChengji($src); - - // 获取符合条件记录总数 $cnt = count($data); // 获取当前页数据 @@ -520,10 +547,6 @@ class Index extends Base $sheet->setCellValue($colname[$colcnt+2].'3', $temp['rate']); - - - - // 保存文件 $filename = $ks->title.'学生成绩列表'.date('ymdHis').'.xlsx'; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); diff --git a/application/chengji/controller/Tongji.php b/application/chengji/controller/Tongji.php index 742fa57e..c3937666 100644 --- a/application/chengji/controller/Tongji.php +++ b/application/chengji/controller/Tongji.php @@ -255,7 +255,7 @@ class Tongji extends Base $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet; $sheet = $spreadsheet->getActiveSheet(); - $sbjcol = ['cnt'=>'人数','avg'=>'平均分','youxiu'=>'优秀率','jige'=>'及格率']; + $sbjcol = ['cnt'=>'人数','avg'=>'平均分','jige'=>'及格率','youxiu'=>'优秀率']; $sbjcolcnt = count($sbjcol); $colname = excelLieming(); $colcnt = $sbjcolcnt*count($xk)+3; @@ -364,26 +364,14 @@ class Tongji extends Base 'limit'=>'10', 'kaoshi'=>'', 'nianji'=>'一年级', - 'paixu'=>array(), ],'POST'); // 查询要统计成绩的班级 $kh = new \app\kaoshi\model\Kaohao; - $paixu = $src['paixu']; - $bj = $kh->where('nianji',$src['nianji']) + $nianji = $kh->where('nianji',$src['nianji']) ->where('kaoshi',$src['kaoshi']) - ->when(count($paixu)>0,function($query) use($paixu){ - $query->where('banji','in',function($q)use($paixu){ - $q->name('banji')->where('paixu','in',$paixu)->field('id'); - }); - }) - ->with([ - 'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian') - ->append(['numTitle','banjiTitle']); - } - ,'cjSchool'=>function($query){ + ->with(['cjSchool'=>function($query){ $query->field('id,jiancheng'); } ]) @@ -391,7 +379,7 @@ class Tongji extends Base ->field('id,banji,school') ->select(); - if($bj->isEmpty()){ + if($nianji->isEmpty()){ // 重组返回内容 $data = [ 'code'=> 0 , // ajax请求次数,作为标识符 @@ -404,16 +392,14 @@ class Tongji extends Base } - // 获取并统计各班级成绩 $tj = new TJ; $data = array(); $allcj = array(); - foreach ($bj as $key => $value) { - $school=array(); + foreach ($nianji as $key => $value) { + $school=[$value->cj_school->id]; $nianji = [$src['nianji']]; - $banji = array(); #不限定班级 - $temp = $tj->srcChengji($src['kaoshi'],$banji,$nianji,$school); + $temp = $tj->srcChengji($src['kaoshi'],array(),$nianji,$school); $allcj = array_merge($allcj, $temp);; $temp = $tj->tongji($temp,$src['kaoshi']); $data[] = [ @@ -477,26 +463,14 @@ class Tongji extends Base 'limit'=>'10', 'kaoshi'=>'', 'nianji'=>'一年级', - 'paixu'=>array(), ],'POST'); // 查询要统计成绩的班级 $kh = new \app\kaoshi\model\Kaohao; - $paixu = $src['paixu']; - $bj = $kh->where('nianji',$src['nianji']) + $nianji = $kh->where('nianji',$src['nianji']) ->where('kaoshi',$src['kaoshi']) - ->when(count($paixu)>0,function($query) use($paixu){ - $query->where('banji','in',function($q)use($paixu){ - $q->name('banji')->where('paixu','in',$paixu)->field('id'); - }); - }) - ->with([ - 'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian') - ->append(['numTitle','banjiTitle']); - } - ,'cjSchool'=>function($query){ + ->with(['cjSchool'=>function($query){ $query->field('id,jiancheng'); } ]) @@ -504,7 +478,8 @@ class Tongji extends Base ->field('id,banji,school') ->select(); - if($bj->isEmpty()){ + + if($nianji->isEmpty()){ // 重组返回内容 $data = [ 'code'=> 0 , // ajax请求次数,作为标识符 @@ -517,16 +492,14 @@ class Tongji extends Base } - // 获取并统计各班级成绩 $tj = new TJ; $data = array(); $allcj = array(); - foreach ($bj as $key => $value) { - $school=array(); + foreach ($nianji as $key => $value) { + $school=[$value->cj_school->id]; $nianji = [$src['nianji']]; - $banji = array(); #不限定班级 - $temp = $tj->srcChengji($src['kaoshi'],$banji,$nianji,$school); + $temp = $tj->srcChengji($src['kaoshi'],array(),$nianji,$school); $allcj = array_merge($allcj, $temp);; $temp = $tj->tongji($temp,$src['kaoshi']); $data[] = [ @@ -564,7 +537,7 @@ class Tongji extends Base $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet; $sheet = $spreadsheet->getActiveSheet(); - $sbjcol = ['cnt'=>'人数','avg'=>'平均分','youxiu'=>'优秀率','jige'=>'及格率']; + $sbjcol = ['cnt'=>'人数','avg'=>'平均分','jige'=>'及格率%','youxiu'=>'优秀率%']; $sbjcolcnt = count($sbjcol); $colname = excelLieming(); $colcnt = $sbjcolcnt*count($xk)+3; @@ -588,10 +561,10 @@ class Tongji extends Base } } $sheet->mergeCells($colname[$col].'3:'.$colname[$col].'4'); - $sheet->setCellValue($colname[$col].'3', '全科及格'); + $sheet->setCellValue($colname[$col].'3', '全科及格率%'); $col++; $sheet->mergeCells($colname[$col].'3:'.$colname[$col].'4'); - $sheet->setCellValue($colname[$col].'3', '全科平均'); + $sheet->setCellValue($colname[$col].'3', '总平均分'); $row = 5; foreach ($data as $key => $value) { diff --git a/application/chengji/model/Tongji.php b/application/chengji/model/Tongji.php index e54201ee..97547321 100644 --- a/application/chengji/model/Tongji.php +++ b/application/chengji/model/Tongji.php @@ -55,6 +55,10 @@ class Tongji extends Model // 整理数据 $data = array(); foreach ($khlist as $key => $value) { + if(count($value->ks_chengji)== 0) + { + continue; + } $data[$key]['sum'] = 0; $sbjcnt = 0; foreach ($value->ks_chengji as $k => $val) { @@ -88,7 +92,7 @@ class Tongji extends Model $temp['sum'] = array_sum($cjcol); $temp['cnt']>0 ? $temp['avg'] = $temp['sum']/$temp['cnt'] : $temp['avg']=0; $temp['biaozhuncha'] = round($this->getVariance($temp['avg'], $cjcol,true),2); - $temp['avg'] = round($temp['avg'],1); + $temp['avg'] = round($temp['avg'],2); $temp['youxiu'] = $this->rate($cjcol,$value->youxiu); $temp['jige'] = $this->rate($cjcol,$value->jige); $temp['sifenwei'] = $this->quartile($cjcol); @@ -97,7 +101,11 @@ class Tongji extends Model $cjcol = array_column($cj,'sum'); $data['cnt'] = count($cjcol); $data['sum'] = array_sum($cjcol); - $data['cnt']>0 ? $data['avg'] = round($data['sum']/$data['cnt'],1) : $data['avg']=0; + $data['cnt']>0 ? $data['avg'] = round($data['sum']/$data['cnt'],2) : $data['avg']=0; + foreach ($cj as $key => $value) { + unset($cj[$key]['avg']); + unset($cj[$key]['sum']); + } $data['rate'] = $this->rateAll($cj,$ksinfo->ks_subject); #全科及格率 return $data; @@ -116,7 +124,7 @@ class Tongji extends Model } if(count($cj)>0) { - return round($cnt/count($cj)*100,1); + return round($cnt/count($cj)*100,2); }else{ return ''; } @@ -127,25 +135,28 @@ class Tongji extends Model // 全科及格率 public function rateAll($cj = array(), $sbj=array()) { - $jige = 0; + $jige = 0; # 总及格人数 + // 开始循环每个人的成绩 foreach ($cj as $key => $value) { - $tempcj = count($value); + $temjige = 0; #记录学生及格的学科数 + // 开始循环这个学生的每个学科成绩 foreach ($sbj as $k => $val) { - $tempsbj = 0; if(isset($value[$val->lieming])) { if($value[$val->lieming]>=$val->jige) { - $tempsbj++; + $temjige++; } } } - $tempcj == $tempsbj ? $jige++ : $jige ; + // 如果这个学生及格学科数等于学科总数,那么全科及格总数加1 + $temjige == count($value) && $temjige>0 ? $jige++ : $jige ; } + if(count($cj)>0) { - return round($jige/count($cj)*100,1); + return round($jige/count($cj)*100,2); }else{ return ''; } diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html index a79d043f..701ca040 100644 --- a/application/chengji/view/index/index.html +++ b/application/chengji/view/index/index.html @@ -85,10 +85,10 @@ // 设置列 options.cols=[[ //表头 {type:'checkbox', fixed: 'left'}, - {field: 'school', title: '学校',sort: true}, + {field: 'school', title: '学校', minWidth:100,sort: true}, {field: 'nianji', title: '年级 ', minWidth:100,sort: true}, {field: "banji",title: '班级',sort: true}, - {field: "student",title: '学生姓名',sort: true}, + {field: "student",title: '学生姓名',sort: true, minWidth:100}, ]]; @@ -98,9 +98,8 @@ { options.cols[0].push({field: xk[x].subject_name.lieming, title: xk[x].subject_name.jiancheng ,sort: true}); } - options.cols[0].push({field: 'avg', title: '平均分',sort: true}); - options.cols[0].push({field: 'cnt', title: '总分',sort: true}); - options.cols[0].push({field: 'cnt', title: '总分',sort: true}); + options.cols[0].push({field: 'avg', title: '平均分', minWidth:100,sort: true}); + options.cols[0].push({field: 'sum', title: '总分', minWidth:100,sort: true}); options.cols[0].push({field: 'id', title: '操作',toolbar: '#barDemo',minWidth:125}); // 设置查询条件 @@ -108,6 +107,10 @@ kaoshi:"{$list.kaoshi}" } + // 设置每页显示条数 + options.limit = 55; + options.limits = [55,60,100,150,200]; + // 提交搜索条件后重载表格 layui.use(['table','cjgl'],function(){ @@ -118,10 +121,10 @@ switch(obj.event){ case 'dels': var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值 - cjgl.delAll(checkStatus,'/school','mytable'); + cjgl.delAll(checkStatus,'/kaohao','mytable'); break; case 'add': - cjgl.add('添加单位','/school/create','650','500'); + cjgl.add('添加单位','/kaohao/create','650','500'); break; case 'download': cjgl.add('下载成绩','/chengji/{$list.kaoshi}/dwChengji','650','300'); @@ -139,10 +142,10 @@ layer.msg('查看' + data.id); break; case 'del':// 删除 - cjgl.del(obj,"/school"); + cjgl.del(obj,"/kaohao"); break; case 'edit':// 编辑 - cjgl.add('编辑单位','/school/'+obj.data.id+'/edit','650','500'); + cjgl.add('编辑单位','/kaohao/'+obj.data.id+'/edit','650','500'); break; case 'status':// 状态 cjgl.status(obj,"{:url('setstatus')}"); diff --git a/application/chengji/view/tongji/dw_nianji.html b/application/chengji/view/tongji/dw_nianji.html index fd559c18..52338857 100644 --- a/application/chengji/view/tongji/dw_nianji.html +++ b/application/chengji/view/tongji/dw_nianji.html @@ -3,17 +3,15 @@ {block name="form"}
-