diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index eb900280..06755894 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -298,7 +298,7 @@ class Index extends Base - // 获取考试信息 + // 获取成绩信息 public function ajaxData() { // 获取参数 @@ -317,10 +317,10 @@ class Index extends Base // 实例化 - $chengji = new Kaohao; + $kaohao = new Kaohao; // 查询要显示的数据 - $data = $chengji->srcChengji($src); + $data = $kaohao->srcChengji($src); // 获取符合条件记录总数 @@ -482,7 +482,6 @@ class Index extends Base $kaoshi = $list['kaoshi']; // 获取数据库信息 $cj = new Chengji(); - // $kh = new \app\kaoshi\model\Kaohao; $chengjiinfo = $cj->srcChengji($kaoshi,$list['banji']); @@ -509,7 +508,6 @@ class Index extends Base // 创建表格 $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet; $sheet = $spreadsheet->getActiveSheet(); - // 设置表头信息 @@ -558,7 +556,7 @@ class Index extends Base $colcnt++; } $sheet->setCellValue($colname[$colcnt].$i, $value['avg']); - $sheet->setCellValue($colname[$colcnt+1].$i, $value['cnt']); + $sheet->setCellValue($colname[$colcnt+1].$i, $value['sum']); $i++; } @@ -569,7 +567,7 @@ class Index extends Base $colcnt = $colcnt+5; // 循环写出统计结果 foreach ($ks->ks_subject as $key => $value) { - $sheet->setCellValue($colname[$colcnt].'3', $temp[$value->subject_name->lieming]['cnt']); + $sheet->setCellValue($colname[$colcnt].'3', $temp[$value->subject_name->lieming]['sum']); $sheet->setCellValue($colname[$colcnt].'4', $temp[$value->subject_name->lieming]['avg']); $sheet->setCellValue($colname[$colcnt].'5', $temp[$value->subject_name->lieming]['youxiu']); $sheet->setCellValue($colname[$colcnt].'6', $temp[$value->subject_name->lieming]['jige']); diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index e650488f..bf6c4711 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -15,7 +15,14 @@ class Chengji extends Base return $this->belongsTo('\app\teach\model\Subject'); } - // 查询学生成绩 + /** + * 根据考试ID和班级获取学生各学科成绩、平均分、总分 + * + * @access public + * @param mixed $kaoshi 当前考试ID + * @param array $banji 学生所在班级 + * @return array 返回类型 + */ public function srcChengji($kaoshi=0,$banji=array()) { $kh = new \app\kaoshi\model\Kaohao; @@ -66,16 +73,16 @@ class Chengji extends Base $data[$key]['sex'] = $value->cj_student->sex; $data[$key]['nianji'] = $value->nianji; $data[$key]['banji'] = $value->cj_banji->banji_title; - $dfcnt = 0; + $dfsum = 0; $sbjcnt = 0; foreach ($value->ks_chengji as $k => $val) { $data[$key][$xk[$val->subject_id]] = $val->defen*1; - $dfcnt = $dfcnt + $val->defen*1; + $dfsum = $dfsum + $val->defen*1; $sbjcnt ++; } - $data[$key]['cnt'] = $dfcnt; + $data[$key]['sum'] = $dfsum; if($sbjcnt>0){ - $data[$key]['avg'] = round($dfcnt/$sbjcnt,1); + $data[$key]['avg'] = round($dfsum/$sbjcnt,1); }else{ $data[$key]['avg'] = 0; } diff --git a/application/kaoshi/model/Kaohao.php b/application/kaoshi/model/Kaohao.php index 6bf2b70b..68ec4006 100644 --- a/application/kaoshi/model/Kaohao.php +++ b/application/kaoshi/model/Kaohao.php @@ -128,12 +128,20 @@ class Kaohao extends Base $xk[$value->subjectid] = $value->lieming; } + // halt($khlist); + // 整理数据 $data = array(); foreach ($khlist as $key => $value) { $data[$key]['id'] = $value->id; $data[$key]['school'] = $value->cj_school->jiancheng; - $data[$key]['student'] = $value->cj_student->xingming; + if(isset($value->cj_student)){ + $data[$key]['student'] = $value->cj_student->xingming; + }else{ + $stu = new \app\renshi\model\Student; + $stuname = $stu::withTrashed()->where('id',$value->student)->value('xingming'); + $data[$key]['student'] = $stuname; + } $data[$key]['nianji'] = $value->nianji; $data[$key]['banji'] = $value->cj_banji->num_title; $dfsum = 0;