diff --git a/app/chengji/controller/Bjtongji.php b/app/chengji/controller/Bjtongji.php index bb6d187d..507d0119 100644 --- a/app/chengji/controller/Bjtongji.php +++ b/app/chengji/controller/Bjtongji.php @@ -27,7 +27,7 @@ class Bjtongji extends BaseController ->field('id,title') ->find(); - if(count($ksinfo->ks_nianji)>0) + if(count($ksinfo->ksNianji)>0) { $list['nianji'] = $ksinfo->ksNianji[0]->nianji; }else{ @@ -68,7 +68,6 @@ class Bjtongji extends BaseController // 获取参与考试的班级 $kh = new \app\kaoshi\model\Kaohao; - // $src['banji']= array_column($kh->cyBanji($src), 'id'); $src['banji']= $kh->cyBanji($src); @@ -210,7 +209,7 @@ class Bjtongji extends BaseController $sheet->setCellValue('B'.$row, $value['banjinum']); foreach ($xk as $ke => $val) { foreach ($sbjcol as $k => $v) { - $sheet->setCellValue($colname[$col].$row, $value['chengji'][$val->subject_name->lieming][$k]); + $sheet->setCellValue($colname[$col].$row, $value['chengji'][$val->subjectName->lieming][$k]); $col++; } } diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index 4af40611..b0cf6add 100644 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -227,7 +227,7 @@ class Index extends BaseController // 保存表格批量上传的成绩 public function saveAll() { - set_time_limit(0); + // set_time_limit(0); // 获以电子表格存储位置 $url = input('post.url'); @@ -240,7 +240,7 @@ class Index extends BaseController $kaoshiid = $cjinfo[1][0]; #获取考号 - if($kaoshiid == null || $cjinfo[2][0] != '序号' || $cjinfo[2][1] != '考号' || $cjinfo[2][2] != '班级' || $cjinfo[2][3] != '姓名') + if($kaoshiid == null || $cjinfo[2][0] != '序号' || $cjinfo[2][1] != '编号' || $cjinfo[2][2] != '班级' || $cjinfo[2][3] != '姓名') { $data=['msg'=>'请使用模板上传','val'=>0]; return json($data); @@ -319,8 +319,8 @@ class Index extends BaseController // 判断成绩更新结果 $data=['msg'=>'成绩导入成功','val'=>1]; - ob_flush(); - flush(); + // ob_flush(); + // flush(); // 返回成绩结果 return json($data); } @@ -401,15 +401,14 @@ class Index extends BaseController // 获取参与考试的班级 $kh = new \app\kaoshi\model\Kaohao; $src['banji']= array_column($kh->cyBanji($src), 'id'); - + + // 实例化 $cj = new Chengji; // 查询要显示的数据 $data = $cj->search($src); - - // 获取符合条件记录总数 $cnt = count($data); // 获取当前页数据 diff --git a/app/chengji/model/Bjtongji.php b/app/chengji/model/Bjtongji.php index deea247c..7615775f 100644 --- a/app/chengji/model/Bjtongji.php +++ b/app/chengji/model/Bjtongji.php @@ -59,6 +59,7 @@ class Bjtongji extends Base ]; } + $srcfrom['banji'] = array_column($src['banji'], 'id'); // 获取年级成绩 // $allcj = $tj->srcChengji($kaoshi=$kaoshi,$banji=$bjs,$nianji=$nianji,$school=array()); diff --git a/app/chengji/model/Chengji.php b/app/chengji/model/Chengji.php index f1df985e..20b6cd4e 100644 --- a/app/chengji/model/Chengji.php +++ b/app/chengji/model/Chengji.php @@ -43,9 +43,11 @@ class Chengji extends Base 'searchval'=>'' ); + // 用新值替换初始值 $src = array_cover( $srcfrom , $src ) ; + // 实例化考号数据模型 $kh = new \app\kaoshi\model\Kaohao; diff --git a/app/chengji/model/Tongji.php b/app/chengji/model/Tongji.php index 21cae20b..c4eddcd1 100644 --- a/app/chengji/model/Tongji.php +++ b/app/chengji/model/Tongji.php @@ -105,38 +105,68 @@ class Tongji extends Base // 统计成绩 public function tongji($cj=array(),$kaoshi) { + // 获取考试信息 $ks = new \app\kaoshi\model\Kaoshi; $ksinfo = $ks->where('id',$kaoshi) ->field('id') - ->with('ksSubject') + ->with(['ksSubject'=>function($query){ + $query->field('id,kaoshiid,subjectid,lieming'); + }]) ->find(); $data = array(); - // $allcj = array(); - foreach ($ksinfo->ks_subject as $key => $value) { + + // 循环统计各学科成绩 + foreach ($ksinfo->ksSubject as $key => $value) { $cjcol = array_column($cj,$value->lieming); $cjcol = array_filter($cjcol,function($item){ return $item !== null; }); - - // $allcj = array_merge($allcj,$cjcol); $temp = array(); - $temp['xkcnt'] = count($cjcol); - $temp['sum'] = array_sum($cjcol); - $temp['xkcnt']>0 ? $temp['avg'] = $temp['sum']/$temp['xkcnt'] : $temp['avg']=0; - $temp['biaozhuncha'] = round($this->getVariance($temp['avg'], $cjcol,true),2); - $temp['avg'] = round($temp['avg'],2); - $temp['youxiu'] = $this->rate($cjcol,$value->youxiu); - $temp['jige'] = $this->rate($cjcol,$value->jige); - $temp['max'] = max($cjcol); - $temp['min'] = min($cjcol); - $temp['sifenwei'] = $this->quartile($cjcol); + + if($cjcol==null) + { + $temp = [ + 'xkcnt'=>0, + 'sum'=>'', + 'biaozhuncha'=>'', + 'avg'=>'', + 'youxiu'=>'', + 'jige'=>'', + 'sifenwei'=>[ + '0'=>'', + '1'=>'', + '2'=>'' + ], + ]; + }else{ + $temp['xkcnt'] = count($cjcol); + $temp['sum'] = array_sum($cjcol); + $temp['xkcnt']>0 ? $temp['avg'] = $temp['sum']/$temp['xkcnt'] : $temp['avg']=0; + $temp['biaozhuncha'] = round($this->getVariance($temp['avg'], $cjcol,true),2); + $temp['avg'] = round($temp['avg'],2); + $temp['youxiu'] = $this->rate($cjcol,$value->youxiu); + $temp['jige'] = $this->rate($cjcol,$value->jige); + // $temp['max'] = max($cjcol); + // $temp['min'] = min($cjcol); + $temp['sifenwei'] = $this->quartile($cjcol); + } $data[$value->lieming] = $temp; } $cjcol = array_column($cj,'sum'); - $data['bmcnt'] = count($cj); # 报名人数 + $cjcol = array_filter($cjcol,function($item){ + return $item !== null; + }); + $data['bmcnt'] = count($cjcol); # 报名人数 $data['sum'] = array_sum($cjcol); - $data['bmcnt']>0 ? $data['avg'] = round($data['sum']/$data['bmcnt'],2) : $data['avg']=0; + if($data['bmcnt']>0) + { + $data['sum'] = array_sum($cjcol); + $data['avg'] = round($data['sum']/$data['bmcnt'],2); + }else{ + $data['sum'] = ''; + $data['avg'] = ''; + } foreach ($cj as $key => $value) { unset($cj[$key]['avg']); unset($cj[$key]['sum']); diff --git a/app/chengji/view/index/index.html b/app/chengji/view/index/index.html index 96373fbd..ad42d921 100644 --- a/app/chengji/view/index/index.html +++ b/app/chengji/view/index/index.html @@ -115,7 +115,6 @@ // 设置查询条件 options.where = { kaoshi:"{$list.kaoshi}" - ,nianji:"{$list.nianji}" ,school:$("input[name='school']:checked").val() ,ruxuenian:$("input[name='ruxuenian']:checked").val() } diff --git a/app/kaoshi/controller/Kaohao.php b/app/kaoshi/controller/Kaohao.php index 5cc908a3..544d4a18 100644 --- a/app/kaoshi/controller/Kaohao.php +++ b/app/kaoshi/controller/Kaohao.php @@ -529,7 +529,7 @@ class Kaohao extends BaseController $sheet->setCellValue('A2', $kaoshi); $sheet->setCellValue('A3', '序号'); - $sheet->setCellValue('B3', '考号'); + $sheet->setCellValue('B3', '编号'); $sheet->setCellValue('C3', '班级'); $sheet->setCellValue('D3', '姓名'); // 获取列数并合并和一行 diff --git a/app/kaoshi/model/Kaohao.php b/app/kaoshi/model/Kaohao.php index 6821e235..49f918e3 100644 --- a/app/kaoshi/model/Kaohao.php +++ b/app/kaoshi/model/Kaohao.php @@ -34,12 +34,12 @@ class Kaohao extends Base } , 'banjiKaohao'=>function($query) use($kaoshi){ - $query->field('id,student') + $query->field('id,student,banji') ->where('kaoshi',$kaoshi) ->order(['banji','id']) ->with([ 'cjStudent'=>function($q){ - $q->field('id,xingming'); + $q->field('id,xingming,sex'); } ]); } @@ -62,8 +62,6 @@ class Kaohao extends Base } } - halt($data->toArray()); - return $data; } @@ -96,26 +94,17 @@ class Kaohao extends Base // 重新定义变量 - // $school = $src['school']; - // $ruxuenian = $src['ruxuenian']; $banji = $src['banji']; $seachval = $src['searchval']; // 查询成绩 $khlist = $this->where('kaoshi',$src['kaoshi']) - ->field('id,school,student,banji,kaoshi') - // ->when(count($school)>0,function($query) use($school){ - // $query->where('school','in',$school); - // }) + ->field('id,school,student,ruxuenian,paixu,kaoshi') ->where('banji','in',$banji) - // ->when(strlen($ruxuenian)>0,function($query) use($ruxuenian){ - // $query->where('ruxuenian',$ruxuenian); - // }) ->when(strlen($seachval)>0,function($query) use($seachval){ $query->where(function($w) use ($seachval){ $w - // ->whereOr('id',$seachval) ->whereOr('student','in',function($q)use($seachval){ $q->name('student')->where('xingming','like','%'.$seachval.'%')->field('id'); }); @@ -136,6 +125,7 @@ class Kaohao extends Base ->select(); + // 成绩整理 if($khlist->isEmpty()) { @@ -153,13 +143,13 @@ class Kaohao extends Base ]) ->find(); - if($ksinfo->ks_subject->isEmpty()) + if($ksinfo->ksSubject->isEmpty()) { return $data = array(); } $xk = array(); - foreach ($ksinfo->ks_subject as $key => $value) { + foreach ($ksinfo->ksSubject as $key => $value) { $xk[$value->subjectid] = $value->lieming; } @@ -173,10 +163,10 @@ class Kaohao extends Base $data = array(); foreach ($khlist as $key => $value) { $data[$key]['id'] = $value->id; - $data[$key]['school'] = $value->cj_school->jiancheng; - if($value->cj_student != Null){ - $data[$key]['student'] = $value->cj_student->xingming; - $data[$key]['sex'] = $value->cj_student->sex; + $data[$key]['school'] = $value->cjSchool->jiancheng; + if($value->cjStudent != Null){ + $data[$key]['student'] = $value->cjStudent->xingming; + $data[$key]['sex'] = $value->cjStudent->sex; }else{ $stuinfo = $stu::withTrashed() ->where('id',$value->student) @@ -190,6 +180,7 @@ class Kaohao extends Base $dfsum = 0; $sbjcnt = 0; + // 整理当前学生成绩 $cjarr = $this->zzcj($value->ks_chengji); // 初始化参数 @@ -207,11 +198,11 @@ class Kaohao extends Base } - - $data[$key]['sum'] = array_sum($cjarr); if($sbjcnt>0){ + $data[$key]['sum'] = array_sum($cjarr); $data[$key]['avg'] = round($data[$key]['sum']/$sbjcnt,1); }else{ + $data[$key]['sum'] = null; $data[$key]['avg'] = null; } } @@ -335,21 +326,16 @@ class Kaohao extends Base $ks = new \app\kaoshi\model\Kaoshi; $kssj = $ks::where('id',$src['kaoshi'])->value('bfdate'); - + // 通过给定参数,从考号表中获取参加考试的班级 $bjids = $this - // ->where('ruxuenian',$src['ruxuenian']) + ->where('ruxuenian',$src['ruxuenian']) ->where('kaoshi',$src['kaoshi']) - // ->when(count($school)>0,function($query) use($school){ - // $query->where('school','in',$school); - // }) - // ->when(count($paixu)>0,function($query) use($paixu){ - // $query->withTrashed() - // ->where('banji','in',function($q)use($paixu){ - // $q->name('banji') - // ->where('paixu','in',$paixu) - // ->field('id'); - // }); - // }) + ->when(count($school)>0,function($query) use($school){ + $query->where('school','in',$school); + }) + ->when(count($paixu)>0,function($query) use($paixu){ + $query->where('paixu','in',$paixu); + }) ->with([ 'cjSchool'=>function($query){ $query->field('id,jiancheng'); @@ -360,17 +346,15 @@ class Kaohao extends Base ->select() ->toArray(); - halt($bjids); - - + // 将二维数组的班级转换成一维数组 foreach ($bjids as $key => $value) { // halt($key); $bjids[$key] = $value['banji']; } + // 查询班级信息并赋值 $bj = new \app\teach\model\Banji; - $data = $bj->withTrashed() ->where('id','in',$bjids) ->field('id,school,paixu') @@ -381,14 +365,12 @@ class Kaohao extends Base ]) ->select() ->toArray(); - foreach ($data as $key => $value) { $data[$key]['banjiNum'] = $bj->myBanjiNum($value['id'],$kssj); $data[$key]['banjiTitle'] = $bj->myBanjiTitle($value['id'],$kssj); $data[$key]['schOrd'] = $value['glSchool']['paixu']; unset($data[$key]['glSchool']['paixu']); } - $data = sortArrByManyField($data,'schOrd',SORT_ASC,'paixu',SORT_ASC); return $data; @@ -413,8 +395,11 @@ class Kaohao extends Base ->find(); $bfdate = $ks->cjKaoshi->getData('bfdate'); - $bj = new \app\teach\model\Banji; - $title = $bj->myBanjiTitle($this->getAttr('banji'),$bfdate); + $nj = nianjiList($bfdate); + $bj = banjinamelist(); + + $title = $nj[$this->getAttr('ruxuenian')] . $bj[$this->getAttr('paixu')]; + return $title; } diff --git a/app/kaoshi/model/Kaoshi.php b/app/kaoshi/model/Kaoshi.php index 6a12b82c..88266f0d 100644 --- a/app/kaoshi/model/Kaoshi.php +++ b/app/kaoshi/model/Kaoshi.php @@ -28,9 +28,6 @@ class Kaoshi extends Base // 查询数据 $data = $this ->order([$src['field'] =>$src['order']]) - // ->when(count($xingzhi)>0,function($query) use($xingzhi){ - // $query->where('xingzhi','in',$xingzhi); - // }) ->when(strlen($searchval)>0,function($query) use($searchval){ $query->where('title','like','%'.$searchval.'%'); })