diff --git a/app/chengji/controller/Bjtongji.php b/app/chengji/controller/Bjtongji.php index 967ad907..f61e8bca 100644 --- a/app/chengji/controller/Bjtongji.php +++ b/app/chengji/controller/Bjtongji.php @@ -68,6 +68,7 @@ class Bjtongji extends BaseController $src['school'] = strToarray($src['school']); $src['ruxuenian'] = strToarray($src['ruxuenian']); + // 获取参与考试的班级 $kh = new \app\kaoshi\model\Kaohao; $src['banji']= array_column($kh->cyBanji($src),'id'); @@ -76,6 +77,7 @@ class Bjtongji extends BaseController $btj = new BTJ; $data = $btj->search($src); + // 获取记录总数 $cnt = count($data); @@ -175,7 +177,8 @@ class Bjtongji extends BaseController ->setKeywords("尚码 成绩管理") //关键字 ->setCategory("成绩管理"); //分类 - $sbjcol = ['xkcnt'=>'人数','avg'=>'平均分','jige'=>'及格率%','youxiu'=>'优秀率%']; + + $sbjcol = ['cj_cnt'=>'人数','avg'=>'平均分','jige'=>'及格率%','youxiu'=>'优秀率%']; $sbjcolcnt = count($sbjcol); $colname = excelLieming(); $colcnt = $sbjcolcnt*count($xk)+3; @@ -206,24 +209,34 @@ class Bjtongji extends BaseController $sheet->setCellValue($colname[$col].'3', '全科平均'); + $row = 5; foreach ($data as $key => $value) { $col = 2; $sheet->setCellValue('A'.$row, $row-4); - $sheet->setCellValue('B'.$row, $value['title']); + if($key === 'all') + { + $sheet->setCellValue('B'.$row, '合计'); + $a = 'hj'; + }else{ + $sheet->setCellValue('B'.$row, $value['title']); + $a = 'val'; + } + foreach ($xk as $ke => $val) { foreach ($sbjcol as $k => $v) { $sheet->setCellValue($colname[$col].$row, $value['chengji'][$val->subjectName->lieming][$k]); $col++; } } - $sheet->setCellValue($colname[$col].$row, $value['quanke']['rate']); + $sheet->setCellValue($colname[$col].$row, $value['quanke']['jige']); $col++; $sheet->setCellValue($colname[$col].$row, $value['quanke']['avg']); $row++; } + // 居中 $styleArray = [ 'alignment' => [ diff --git a/app/chengji/controller/Njtongji.php b/app/chengji/controller/Njtongji.php index addd7a36..e35b6d3f 100644 --- a/app/chengji/controller/Njtongji.php +++ b/app/chengji/controller/Njtongji.php @@ -127,8 +127,12 @@ class Njtongji extends BaseController // 统计成绩 $ntj = new NTJ; - $data = $ntj->tjNianji($src); - + $data = $ntj->search($src); + $schtj = new \app\chengji\model\TongjiSch; + $dataAll = $schtj->search($src); + count($dataAll)>0 ? $data['all'] = $dataAll['all'] : $data; + + // 获取参考学科 $ks = new \app\kaoshi\model\Kaoshi; $ksinfo = $ks->where('id',$src['kaoshi']) @@ -168,7 +172,7 @@ class Njtongji extends BaseController ->setKeywords("尚码 成绩管理") //关键字 ->setCategory("成绩管理"); //分类 - $sbjcol = ['xkcnt'=>'人数','avg'=>'平均分','jige'=>'及格率%','youxiu'=>'优秀率%']; + $sbjcol = ['cj_cnt'=>'人数','avg'=>'平均分','jige'=>'及格率%','youxiu'=>'优秀率%']; $sbjcolcnt = count($sbjcol); $colname = excelLieming(); $colcnt = $sbjcolcnt*count($xk)+3; @@ -209,9 +213,9 @@ class Njtongji extends BaseController $col++; } } - $sheet->setCellValue($colname[$col].$row, $value['chengji']['rate']); + $sheet->setCellValue($colname[$col].$row, $value['quanke']['jige']); $col++; - $sheet->setCellValue($colname[$col].$row, $value['chengji']['avg']); + $sheet->setCellValue($colname[$col].$row, $value['quanke']['avg']); $row++; } diff --git a/app/chengji/controller/Tongji.php b/app/chengji/controller/Tongji.php index df83eea2..310dfee5 100644 --- a/app/chengji/controller/Tongji.php +++ b/app/chengji/controller/Tongji.php @@ -39,7 +39,7 @@ class Tongji extends BaseController $list['webtitle'] = '各年级的班级成绩列表'; $list['kaoshi'] = $kaoshi; $list['kaoshititle'] = $ksinfo->title; - $list['dataurl'] = '/chengji/bjtj/data'; + $list['dataurl'] = '/chengji/tongji/data'; // 模板赋值 @@ -49,4 +49,51 @@ class Tongji extends BaseController return $this->view->fetch(); } + + // 获取年级成绩统计结果 + public function ajaxData() + { + // 获取参数 + $src = $this->request + ->only([ + 'page'=>'1', + 'limit'=>'10', + 'kaoshi'=>'', + 'ruxuenian'=>'', + 'school'=>array(), + 'paixu'=>array(), + ],'POST'); + + + $src['school'] = strToarray($src['school']); + + + // 获取参与考试的班级 + $kh = new \app\kaoshi\model\Kaohao; + $src['banji']= $kh->cyBanji($src); + + + // 统计成绩 + $btj = new \app\chengji\model\TongjiBj; + + $data = $btj->tjBanjiCnt($src); + + + // 获取记录总数 + $cnt = count($data); + // 截取当前页数据 + $data = array_slice($data,($src['page']-1)*$src['limit'],$src['limit']); + + // 重组返回内容 + $data = [ + 'code'=> 0 , // ajax请求次数,作为标识符 + 'msg'=>"", // 获取到的结果数(每页显示数量) + 'count'=>$cnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + return json($data); + } + + } diff --git a/app/chengji/model/Tongji.php b/app/chengji/model/Tongji.php index c833910e..cf639ab0 100644 --- a/app/chengji/model/Tongji.php +++ b/app/chengji/model/Tongji.php @@ -9,7 +9,7 @@ class Tongji extends Base { // 统计成绩 - public function tongji($cj=array(),$kaoshi) + public function tongjiCnt($cj=array(),$kaoshi) { // 获取考试信息 $ks = new \app\kaoshi\model\Kaoshi; @@ -24,43 +24,14 @@ class Tongji extends Base // 循环统计各学科成绩 foreach ($ksinfo->ksSubject as $key => $value) { $cjcol = array_column($cj,$value->lieming); - $stucnt = count($cjcol); + // $stucnt = count($cjcol); $cjcol = array_filter($cjcol,function($item){ return $item !== null; }); $temp = array(); - if($cjcol==null) - { - $temp = [ - 'id'=>$value->subjectid, - 'xkcnt'=>0, - 'sum'=>'', - 'biaozhuncha'=>'', - 'avg'=>'', - 'youxiu'=>'', - 'jige'=>'', - 'sifenwei'=>[ - '0'=>'', - '1'=>'', - '2'=>'' - ], - 'max'=>'', - 'min'=>'' - ]; - }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); - } + $temp['xkcnt'] = count($cjcol); $data[$value->lieming] = $temp; } $cjcol = array_column($cj,'sum'); @@ -69,26 +40,13 @@ class Tongji extends Base }); $data['stucnt'] = count($cj); $data['bmcnt'] = count($cjcol); # 报名人数 - $data['sum'] = array_sum($cjcol); - 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']); - } - $data['rate'] = $this->rateAll($cj,$ksinfo->ks_subject); #全科及格率 - + return $data; } + // 统计成绩 public function tongjiSubject($cj=array(),$kaoshi) { diff --git a/app/chengji/model/TongjiBj.php b/app/chengji/model/TongjiBj.php index c12f947d..21056027 100644 --- a/app/chengji/model/TongjiBj.php +++ b/app/chengji/model/TongjiBj.php @@ -102,6 +102,75 @@ class TongjiBj extends Base + /** + * 统计指定个年级的各班级成绩 + * 统计项目参考tongji方法 + * @access public + * @param number $kaoshi 考试id + * @param number $ruxuenian 入学年 + * @return array 返回类型 + */ + public function tjBanjiCnt($srcfrom) + { + + // 初始化参数 + $src = array( + 'page'=>'1', + 'limit'=>'10', + 'kaoshi'=>'', + 'banji'=>array(), + ); + + + // 用新值替换初始值 + $src = array_cover( $srcfrom , $src ) ; + + if(count($src['banji']) == 0){ + return array(); + } + + // 实例化学生成绩统计类 + $tj = new TJ; + $cj = new Chengji; + + + // 获取并统计各班级成绩 + $data = array(); + foreach ($src['banji'] as $key => $value) { + $srcfrom = [ + 'kaoshi'=>$src['kaoshi'], + 'banji'=>[$value['id']] + ]; + $temp = $cj->search($srcfrom); + $temp = $tj->tongjiCnt($temp,$srcfrom['kaoshi']); + $data[] = [ + 'banji'=>$value['banjiTitle'], + 'banjinum'=>$value['banjiNum'], + 'school'=>$value['glSchool']['jiancheng'], + 'chengji'=>$temp + ]; + } + + + $srcfrom['banji'] = array_column($src['banji'], 'id'); + // 获取年级成绩 + // $allcj = $tj->srcChengji($kaoshi=$kaoshi,$banji=$bjs,$nianji=$nianji,$school=array()); + $allcj = $cj->search($srcfrom); + $temp = $tj->tongjiCnt($allcj,$srcfrom['kaoshi']); + $data[] = [ + 'banji'=>'合计', + 'banjinum'=>'合计', + 'school'=>'合计', + 'chengji'=>$temp + ]; + + + return $data; + } + + + + /** * 班级成绩统计结果查询 * 从数据库中取出数据 @@ -130,7 +199,7 @@ class TongjiBj extends Base $tongjiJg = $this ->where('kaoshi_id',$src['kaoshi']) ->where('banji_id','in',$src['banji']) - ->field('id,banji_id,kaoshi_id') + ->field('banji_id,kaoshi_id') ->with([ 'bjBanji'=>function($query){ $query->field('id,school,paixu') @@ -149,14 +218,11 @@ class TongjiBj extends Base ]) ->order(['subject_id']); } - ]) - ->group('banji_id') + ->group('banji_id,kaoshi_id') ->append(['banjiTitle']) ->select(); - // halt($tongjiJg->toArray()); - // 初始化数组 $data = array(); @@ -204,6 +270,7 @@ class TongjiBj extends Base return $this->belongsTo('\app\kaoshi\model\Kaoshi','kaoshi_id','id'); } + // 班级关联 public function bjBanji() { diff --git a/app/chengji/model/TongjiNj.php b/app/chengji/model/TongjiNj.php index e582dda8..7bedc8e5 100644 --- a/app/chengji/model/TongjiNj.php +++ b/app/chengji/model/TongjiNj.php @@ -162,7 +162,7 @@ class TongjiNj extends Base ->when(count($school)>0,function($query) use($school){ $query->where('school_id','in',$school); }) - ->field('id,kaoshi_id,school_id,ruxuenian') + ->field('kaoshi_id,school_id,ruxuenian') ->with([ 'njSchool'=>function($query){ $query->field('id,paixu,jiancheng'); @@ -179,7 +179,7 @@ class TongjiNj extends Base } ]) - ->group('school_id') + ->group('kaoshi_id,school_id,ruxuenian') ->select(); diff --git a/app/chengji/model/TongjiSch.php b/app/chengji/model/TongjiSch.php index 6dbbb5c8..3d3998b8 100644 --- a/app/chengji/model/TongjiSch.php +++ b/app/chengji/model/TongjiSch.php @@ -129,7 +129,7 @@ class TongjiSch extends Base $tongjiJg = $this ->where('kaoshi_id',$src['kaoshi']) ->where('ruxuenian',$src['ruxuenian']) - ->field('id,kaoshi_id,ruxuenian') + ->field('kaoshi_id,ruxuenian') ->with([ 'schJieguo'=>function($query){ $query->field('subject_id,ruxuenian,chengji_cnt,avg,youxiu,jige') @@ -142,7 +142,7 @@ class TongjiSch extends Base } ]) - ->group('ruxuenian') + ->group('kaoshi_id,ruxuenian') ->select(); diff --git a/app/chengji/route/chengji.php b/app/chengji/route/chengji.php index 2564b08d..34dfcbd8 100644 --- a/app/chengji/route/chengji.php +++ b/app/chengji/route/chengji.php @@ -37,6 +37,7 @@ Route::group('index', function () { // 成绩统计 Route::group('tongji', function () { Route::rule('yilucnt/','Tongji/yiluCnt'); # 更新信息 + Route::rule('data','Tongji/ajaxData','post'); # 扫码界面 }); diff --git a/app/chengji/view/tongji/yilu_cnt.html b/app/chengji/view/tongji/yilu_cnt.html index c5ea8d1e..28f10560 100644 --- a/app/chengji/view/tongji/yilu_cnt.html +++ b/app/chengji/view/tongji/yilu_cnt.html @@ -88,7 +88,7 @@ var str=''; if(d.chengji) { - str = d.chengji.stucnt + str = d.chengji.bmcnt } return str; }},