diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 06755894..bc8b8135 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -149,6 +149,18 @@ class Index extends Base } ]) ->find(); + if($cjlist->cj_student == Null) + { + $stu = new \app\renshi\model\Student; + $stuinfo = $stu::withTrashed() + ->where('id',$cjlist->student) + ->field('id,xingming,sex') + ->find(); + $cjlist->cj_student = array( + 'id'=>$stuinfo->id, + 'xingming'=>$stuinfo->xingming + ); + } $cjlist->sbj = Subject::where('id',$sbj)->field('id,title')->find(); // 获取列名 @@ -269,7 +281,7 @@ class Index extends Base public function index($kaoshi) { // 设置要给模板赋值的信息 - $list['webtitle'] = '成绩列表'; + $list['webtitle'] = '学生成绩列表'; // 实例化考试数据模型 $ks = new \app\kaoshi\model\Kaoshi; @@ -303,19 +315,20 @@ class Index extends Base { // 获取参数 $src = $this->request - ->only([ - 'page'=>'1', - 'limit'=>'10', - 'field'=>'banji', - 'type'=>'desc', - 'kaoshi'=>'1', - 'school'=>array(), - 'nianji'=>array(), - 'paixu'=>array(), - 'searchval'=>'' + ->only(['page','limit','field','type','kaoshi','school','nianji','paixu','searchval' ],'POST'); + // 根据班级排序获取班级id + if(isset($src['paixu'])) + { + $banji = new \app\teach\model\Banji; + $src['banji'] = $banji + ->where('paixu','in',$src['paixu']) + ->column('id'); + } + + // 实例化 $kaohao = new Kaohao; @@ -473,21 +486,20 @@ class Index extends Base if(!$result){ $this->error($msg); } - - - - set_time_limit(0); - $list = input(); - $kaoshi = $list['kaoshi']; + // 获取数据库信息 - $cj = new Chengji(); - $chengjiinfo = $cj->srcChengji($kaoshi,$list['banji']); + $kh = new Kaohao(); + $src = [ + 'kaoshi'=>$list['kaoshi'], + 'banji'=>$list['banji'], + ]; + $chengjiinfo = $kh->srcChengji($src); // 获取考试标题 $ks = new \app\kaoshi\model\Kaoshi; - $ks = $ks->where('id',$kaoshi) + $ks = $ks->where('id',$list['kaoshi']) ->field('id,title') ->with([ 'ksSubject'=>function($query){ @@ -504,7 +516,7 @@ class Index extends Base $colname = excelLieming(); - + set_time_limit(0); // 创建表格 $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet; $sheet = $spreadsheet->getActiveSheet(); @@ -539,14 +551,14 @@ class Index extends Base $sheet->setCellValue($colname[$i+2].'2', '全科及格率%'); - // 循环写出信息 + // 循环写出成绩及个人信息 $i = 3; foreach ($chengjiinfo as $key => $value) { // 表格赋值 $sheet->setCellValue('A'.$i, $i-2); $sheet->setCellValue('B'.$i, $value['banji']); $sheet->setCellValue('C'.$i, $value['student']); - $sheet->setCellValue('D'.$i, $value['sex']); + $sheet->setCellValue('D'.$i, $value['sex']); $colcnt = 4; foreach ($ks->ks_subject as $k => $val) { if(isset($value[$val->subject_name->lieming])) @@ -562,12 +574,12 @@ class Index extends Base $tj = new \app\chengji\model\Tongji; $nianji = array(); - $chengjiinfo = $tj->srcChengji($kaoshi,$list['banji']); - $temp = $tj->tongji($chengjiinfo,$kaoshi); + $chengjiinfo = $tj->srcChengji($list['kaoshi'],$list['banji']); + $temp = $tj->tongji($chengjiinfo,$list['kaoshi']); $colcnt = $colcnt+5; // 循环写出统计结果 foreach ($ks->ks_subject as $key => $value) { - $sheet->setCellValue($colname[$colcnt].'3', $temp[$value->subject_name->lieming]['sum']); + $sheet->setCellValue($colname[$colcnt].'3', $temp[$value->subject_name->lieming]['cnt']); $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 bf6c4711..a2797a69 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -15,85 +15,92 @@ 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; - $khlist = $kh->where('kaoshi',$kaoshi) - ->field('id,school,student,nianji,banji') - ->when(count($banji)>0,function($query) use($banji){ - $query->where('banji','in',$banji); - }) - ->with([ - 'ksChengji'=>function($query){ - $query->field('kaohao_id,subject_id,defen'); - } - ,'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian') - ->append(['numTitle','banjiTitle']); - } - ,'cjSchool'=>function($query){ - $query->field('id,jiancheng'); - } - ,'cjStudent'=>function($query){ - $query->field('id,xingming,sex'); - } - ]) - ->select(); + // /** + // * 根据考试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; + // $khlist = $kh->where('kaoshi',$kaoshi) + // ->field('id,school,student,nianji,banji') + // ->when(count($banji)>0,function($query) use($banji){ + // $query->where('banji','in',$banji); + // }) + // ->with([ + // 'ksChengji'=>function($query){ + // $query->field('kaohao_id,subject_id,defen'); + // } + // ,'cjBanji'=>function($query){ + // $query->field('id,paixu,ruxuenian') + // ->append(['numTitle','banjiTitle']); + // } + // ,'cjSchool'=>function($query){ + // $query->field('id,jiancheng'); + // } + // ,'cjStudent'=>function($query){ + // $query->field('id,xingming,sex'); + // } + // ]) + // ->select(); - // 获取参考学科 - $ks = new \app\kaoshi\model\Kaoshi; - $ksinfo = $ks->where('id',$kaoshi) - ->with([ - 'ksSubject'=>function($query){ - $query->field('kaoshiid,subjectid,lieming'); - } - ]) - ->find(); - $xk = array(); - foreach ($ksinfo->ks_subject as $key => $value) { - $xk[$value->subjectid] = $value->lieming; - } + // // 获取参考学科 + // $ks = new \app\kaoshi\model\Kaoshi; + // $ksinfo = $ks->where('id',$kaoshi) + // ->with([ + // 'ksSubject'=>function($query){ + // $query->field('kaoshiid,subjectid,lieming'); + // } + // ]) + // ->find(); + // $xk = array(); + // foreach ($ksinfo->ks_subject as $key => $value) { + // $xk[$value->subjectid] = $value->lieming; + // } - // 整理数据 - $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; - $data[$key]['sex'] = $value->cj_student->sex; - $data[$key]['nianji'] = $value->nianji; - $data[$key]['banji'] = $value->cj_banji->banji_title; - $dfsum = 0; - $sbjcnt = 0; - foreach ($value->ks_chengji as $k => $val) { - $data[$key][$xk[$val->subject_id]] = $val->defen*1; - $dfsum = $dfsum + $val->defen*1; - $sbjcnt ++; - } - $data[$key]['sum'] = $dfsum; - if($sbjcnt>0){ - $data[$key]['avg'] = round($dfsum/$sbjcnt,1); - }else{ - $data[$key]['avg'] = 0; - } - } + // // 整理数据 + // $data = array(); + // foreach ($khlist as $key => $value) { + // $data[$key]['id'] = $value->id; + // $data[$key]['school'] = $value->cj_school->jiancheng; + // if(isset($value->cj_student)){ + // $data[$key]['student'] = $value->cj_student->xingming; + // $data[$key]['sex'] = $value->cj_student->sex; + // }else{ + // $stu = new \app\renshi\model\Student; + // $stuname = $stu::withTrashed()->where('id',$value->student)->field('id,xingming,sex')->find(); + // $data[$key]['student'] = $stuname->xingming; + // $data[$key]['sex'] = $stuname->sex; + // } + // $data[$key]['nianji'] = $value->nianji; + // $data[$key]['banji'] = $value->cj_banji->banji_title; + // $dfsum = 0; + // $sbjcnt = 0; + // foreach ($value->ks_chengji as $k => $val) { + // $data[$key][$xk[$val->subject_id]] = $val->defen*1; + // $dfsum = $dfsum + $val->defen*1; + // $sbjcnt ++; + // } + // $data[$key]['sum'] = $dfsum; + // if($sbjcnt>0){ + // $data[$key]['avg'] = round($dfsum/$sbjcnt,1); + // }else{ + // $data[$key]['avg'] = 0; + // } + // } - // // 按条件排序 - // if(count($data)>0){ - // $data = arraySequence($data,$src['field'],$src['type']); //排序 - // } - return $data; - } + // // // 按条件排序 + // // if(count($data)>0){ + // // $data = arraySequence($data,$src['field'],$src['type']); //排序 + // // } + // return $data; + // } // 学科关联 diff --git a/application/chengji/model/Tongji.php b/application/chengji/model/Tongji.php index 97547321..373baa07 100644 --- a/application/chengji/model/Tongji.php +++ b/application/chengji/model/Tongji.php @@ -7,7 +7,16 @@ use think\Model; class Tongji extends Model { - // 查询学生成绩 + /** + * 以考号为基础查询学生成绩 + * 信息包括:各学科成绩、平均分、总分 + * @access public + * @param number $kaoshi 考试id + * @param array $banji 班级 + * @param array $nianji 年级 + * @param array $school 学校 + * @return array 返回类型 + */ public function srcChengji($kaoshi,$banji=array(),$nianji=array(),$school=array()) { $kh = new \app\kaoshi\model\Kaohao; diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html index f5c204da..5fc4d0c9 100644 --- a/application/chengji/view/index/index.html +++ b/application/chengji/view/index/index.html @@ -32,9 +32,15 @@
- {php} $njlist = nianjiList();{/php} + {php} + $nianji = new \app\kaoshi\model\KaoshiNianji; + $njlist = $nianji + ->where('kaoshiid',$list['kaoshi']) + ->field('nianji,nianjiname') + ->select(); + {/php} {foreach $njlist as $key=>$vo} - + {/foreach}
@@ -43,9 +49,9 @@
{php} $banji = new \app\teach\model\Banji; - $ruxuenian = array_keys($njlist); + $njlist = $njlist->column('nianji'); $paixu = $banji->where('status',1) - ->where('ruxuenian','in',$ruxuenian) + ->where('ruxuenian','in',$njlist) ->max('paixu'); $bjlist = banjinamelist(); {/php} diff --git a/application/chengji/view/index/malu.html b/application/chengji/view/index/malu.html index 7430e821..194bfb09 100644 --- a/application/chengji/view/index/malu.html +++ b/application/chengji/view/index/malu.html @@ -57,7 +57,7 @@ success: function(data){ $('#xsschool').text(data.cj_school.jiancheng); $('#xsbanji').text(data.cj_banji.banjiTitle); - $('#xsxingming').text(data.cj_student.xingming); + $('#xsxingming').text(data.cj_student['xingming']); $('#xsxueke').text(data.sbj.title); $('#kaohao_id').val(data.id); diff --git a/application/common.php b/application/common.php index 1f1bbbb7..445e8b40 100644 --- a/application/common.php +++ b/application/common.php @@ -304,3 +304,21 @@ function arraySequence($array, $field = 'id', $sort = 'desc') { } return $array; } + + +/** + * 根据键值,用数组2的值替换数组1的值 + * $cover 覆盖数组,存储新值的数组 + * $covered 被覆盖数组,被更改值的数组 + * 返回 新arr1 + * */ +function array_cover( $cover = array(), $covered = array() ) +{ + foreach ($cover as $key => $value) { + if(isset($covered[$key]) == true) + { + $covered[$key] = $cover[$key]; + } + } + return $covered; +} diff --git a/application/kaoshi/controller/Kaohao.php b/application/kaoshi/controller/Kaohao.php index ac7e5007..4bb2fde1 100644 --- a/application/kaoshi/controller/Kaohao.php +++ b/application/kaoshi/controller/Kaohao.php @@ -368,7 +368,7 @@ class Kaohao extends Base $sheet->setCellValue('C'.$i, $bj->cj_school->jiancheng); $sheet->setCellValue('D'.$i, $bj->cj_banji->numTitle); $sheet->setCellValue('E'.$i, $sbj->subject_name->jiancheng); - $sheet->setCellValue('F'.$i, $kh->cj_student->xingming); + $sheet->setCellValue('F'.$i, $kh->cj_student['xingming']); $i++; } } diff --git a/application/kaoshi/model/Kaohao.php b/application/kaoshi/model/Kaohao.php index 68ec4006..e505e513 100644 --- a/application/kaoshi/model/Kaohao.php +++ b/application/kaoshi/model/Kaohao.php @@ -8,7 +8,7 @@ use app\common\model\Base; class Kaohao extends Base { /** - * 根据班级ID查询参加当前考试的学生信息 + * 根据班级ID和考试ID,以班级为单位分组,查询参加当前考试的学生信息 * * @access public * @param mixed $kaoshi 当前考试ID @@ -43,12 +43,29 @@ class Kaohao extends Base } ]) ->select(); + + $stu = new \app\renshi\model\Student; + // 找出已经被删除学生,并添加该学生信息 + foreach ($data as $key => $value) { + foreach ($value->banji_kaohao as $k => $val) { + if($val->cj_student == Null) + { + $stuinof = $stu::withTrashed() + ->where('id',$val->student) + ->field('id,xingming') + ->find(); + $data[$key]->banji_kaohao[$key]->cj_student = array('id'=>$stuinof->id,'xingming'=>$stuinof->xingming); + } + } + } + return $data; } /** - * 以考号为基础查询学生成绩并排序 + * 以考号为基础查询学生成绩信息并排序 + * 信息包括:学校、年级、班级、姓名、性别、各学科成绩、平均分、总分 * @access public * @param array $src 参数数组 * @param number $src['school'] 学生所在学校 @@ -59,26 +76,39 @@ class Kaohao extends Base * @param number $src['type'] 排序类型 * @return array 返回类型 */ - public function srcChengji($src) + public function srcChengji($srcfrom) { + // 初始化参数 + $src = array( + 'page'=>'1', + 'limit'=>'10', + 'field'=>'banji', + 'type'=>'desc', + 'kaoshi'=>'1', + 'school'=>array(), + 'nianji'=>array(), + 'banji'=>array(), + 'searchval'=>'' + ); + // 用新值替换初始值 + $src = array_cover( $srcfrom , $src ) ; + + $school = $src['school']; $nianji = $src['nianji']; - $paixu = $src['paixu']; + $banji = $src['banji']; $seachval = $src['searchval']; - $khlist = $this->where('kaoshi',$src['kaoshi']) ->field('id,school,student,nianji,banji') ->when(count($school)>0,function($query) use($school){ $query->where('school','in',$school); }) - ->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'); - }); + ->when(count($banji)>0,function($query) use($banji){ + $query->where('banji','in',$banji); }) ->when(count($nianji)>0,function($query) use($nianji){ - $query->where('nianji','in',$nianji); + $query->where('ruxuenian','in',$nianji); }) ->when(strlen($seachval)>0,function($query) use($seachval){ $query->where(function($w) use ($seachval){ @@ -100,7 +130,7 @@ class Kaohao extends Base $query->field('id,jiancheng'); } ,'cjStudent'=>function($query){ - $query->field('id,xingming'); + $query->field('id,xingming,sex'); } ]) ->select(); @@ -128,19 +158,22 @@ class Kaohao extends Base $xk[$value->subjectid] = $value->lieming; } - // halt($khlist); - + $stu = new \app\renshi\model\Student; // 整理数据 $data = array(); foreach ($khlist as $key => $value) { $data[$key]['id'] = $value->id; $data[$key]['school'] = $value->cj_school->jiancheng; - if(isset($value->cj_student)){ + if($value->cj_student != Null){ $data[$key]['student'] = $value->cj_student->xingming; + $data[$key]['sex'] = $stuinfo->sex; }else{ - $stu = new \app\renshi\model\Student; - $stuname = $stu::withTrashed()->where('id',$value->student)->value('xingming'); - $data[$key]['student'] = $stuname; + $stuinfo = $stu::withTrashed() + ->where('id',$value->student) + ->field('id,xingming,sex') + ->find(); + $data[$key]['student'] = $stuinfo->xingming; + $data[$key]['sex'] = $stuinfo->sex; } $data[$key]['nianji'] = $value->nianji; $data[$key]['banji'] = $value->cj_banji->num_title;