修改成绩查询数据模型
This commit is contained in:
1 parent
09f06c5c07
commit
8542901614
8 files changed
+209
-124
No files matched your search
@@ -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']);
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
|
||||
|
||||
// 学科关联
|
||||
|
||||
@@ -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;
|
||||
|
||||
Loaded 3 of 8 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user