diff --git a/app/chengji/common.php b/app/chengji/common.php index 9719a412..8101e3e9 100644 --- a/app/chengji/common.php +++ b/app/chengji/common.php @@ -51,3 +51,6 @@ function manfenvalidate($defen,$manfen) return $data; } + + + diff --git a/app/chengji/controller/Bjtongji.php b/app/chengji/controller/Bjtongji.php index 4f93cf55..e720c523 100644 --- a/app/chengji/controller/Bjtongji.php +++ b/app/chengji/controller/Bjtongji.php @@ -70,13 +70,10 @@ class Bjtongji extends BaseController $srcfrom = [ 'kaoshi'=>$src['kaoshi'], 'ruxuenian'=>$src['nianji'], - // 'school'=>explode(',', $src['school']), - 'school'=>$src['school'], 'paixu'=>$src['paixu'], ]; - - is_array($src['school']) ? $srcfrom['school'] = $src['school'] : $srcfrom['school'] = explode(',', $src['school']); - + // 如果获取到的school是字符串,将它转换成数组 + $srcfrom['school'] = strToarray($src['school']); $data = $btj->tjBanji($srcfrom); diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index 87a385d4..75f3f9f1 100644 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -330,7 +330,7 @@ class Index extends BaseController { // 获取参数 $src = $this->request - ->only(['page','limit','field','type','kaoshi','school','nianji','paixu','searchval' + ->only(['page','limit','field','type','kaoshi','school','ruxuenian','paixu','searchval' ],'POST'); // 根据班级排序获取班级id @@ -350,7 +350,7 @@ class Index extends BaseController $cj = new Chengji; // 查询要显示的数据 - $data = $cj->search($src); + $data = $cj->list($src); diff --git a/app/chengji/model/Bjtongji.php b/app/chengji/model/Bjtongji.php index c2a974dc..a85d7205 100644 --- a/app/chengji/model/Bjtongji.php +++ b/app/chengji/model/Bjtongji.php @@ -23,6 +23,8 @@ class Bjtongji extends Base // 查询要统计成绩的班级 $kh = new \app\kaoshi\model\Kaohao; + + $bj = $kh->cyBanji($srcfrom); $srcfrom['nianji'] = $srcfrom['ruxuenian']; @@ -30,9 +32,8 @@ class Bjtongji extends Base unset($srcfrom['ruxuenian'],$srcfrom['paixu']); - $data = array(); - if($bj->isEmpty()){ + if(count($bj) == 0){ return $data; } @@ -44,16 +45,15 @@ class Bjtongji extends Base $data = array(); $bjs = array(); foreach ($bj as $key => $value) { - $bjs[] = $value->banji; - $banji=[$value->banji]; + $bjs[] = $value['id']; # 记录班级数组,为统计所有班级成绩做准备 + $srcfrom['banji']=[$value['id']]; $temp = $cj->search($srcfrom); $temp = $tj->tongji($temp,$srcfrom['kaoshi']); $data[] = [ - 'banji'=>$value->bjtitle, - 'school'=>$value->cj_school->jiancheng, + 'banji'=>$value['banjiTitle'], + 'school'=>$value['glSchool']['jiancheng'], 'chengji'=>$temp ]; - } $srcfrom['banji'] = $bjs; diff --git a/app/chengji/model/Chengji.php b/app/chengji/model/Chengji.php index dec2b6f0..8dc5df67 100644 --- a/app/chengji/model/Chengji.php +++ b/app/chengji/model/Chengji.php @@ -28,8 +28,8 @@ class Chengji extends Base } - // 查询成绩 - public function search($srcfrom) + // 列出要显示的学生成绩 + public function list($srcfrom) { // 初始化参数 @@ -40,15 +40,15 @@ class Chengji extends Base 'type'=>'desc', 'kaoshi'=>'', 'school'=>array(), - 'nianji'=>'', - 'banji'=>array('0'), + 'ruxuenian'=>'', + 'banji'=>array(), 'searchval'=>'' ); // 用新值替换初始值 $src = array_cover( $srcfrom , $src ) ; - // halt($src); + // 实例化考号数据模型 $kh = new \app\kaoshi\model\Kaohao; @@ -88,6 +88,7 @@ class Chengji extends Base // 实例化学生数据模型 $stu = new \app\renshi\model\Student; + // 整理数据 $data = array(); foreach ($chengjilist as $key => $value) { @@ -104,8 +105,8 @@ class Chengji extends Base $data[$key]['student'] = $stuinfo->xingming; $data[$key]['sex'] = $stuinfo->sex; } - $data[$key]['nianji'] = $value->nianji; - $data[$key]['banji'] = $value->nianji.$bjlist[$value->cj_banji->paixu]; + // $data[$key]['nianji'] = $value->nianji; + $data[$key]['banji'] = $value->banjiTitle; $dfsum = 0; $sbjcnt = 0; @@ -116,6 +117,8 @@ class Chengji extends Base $sbjcnt = 0; foreach ($xk as $k => $val) { + // 设置总分的初始值 + $dfsum = null; // 为每个学科赋值并记录学科数 if(array_key_exists($k,$cjarr)) { @@ -123,16 +126,143 @@ class Chengji extends Base $sbjcnt++; $dfsum = $dfsum + $data[$key][$val]; }else{ - $data[$key][$val]=''; + $data[$key][$val]= null; } } + $data[$key]['sum'] = $dfsum; if($sbjcnt>0){ $data[$key]['avg'] = round($dfsum/$sbjcnt,1); }else{ - $data[$key]['avg'] = 0; + $data[$key]['avg'] = null; + } + } + + + // 按条件排序 + if(count($data)>0){ + $data = arraySequence($data,$src['field'],$src['type']); //排序 + } + + return $data; + + } + + + + + + // 列出要统计的学生成绩 + public function search($srcfrom) + { + + // 初始化参数 + $src = array( + 'page'=>'1', + 'limit'=>'10', + 'field'=>'banji', + 'type'=>'desc', + 'kaoshi'=>'', + 'school'=>array(), + 'ruxuenian'=>'', + 'banji'=>array(), + 'searchval'=>'' + ); + + // 用新值替换初始值 + $src = array_cover( $srcfrom , $src ) ; + + + + // 实例化考号数据模型 + $kh = new \app\kaoshi\model\Kaohao; + + // 以考号为基础查询成绩 + $chengjilist = $kh->srcChengji($src); + + // 成绩整理 + if($chengjilist->isEmpty()) + { + return $data = array(); + } + + + // 获取参考学科 + $kaoshi = new \app\kaoshi\model\Kaoshi; + $ksinfo = $kaoshi->where('id',$src['kaoshi']) + ->with([ + 'ksSubject'=>function($query){ + $query->field('kaoshiid,subjectid,lieming'); + } + ]) + ->find(); + + if($ksinfo->ks_subject->isEmpty()) + { + return $data = array(); + } + + $xk = array(); + foreach ($ksinfo->ks_subject as $key => $value) { + $xk[$value->subjectid] = $value->lieming; + } + + $bjlist = banjinamelist(); + + // 实例化学生数据模型 + $stu = new \app\renshi\model\Student; + + + // 整理数据 + $data = array(); + foreach ($chengjilist 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; + }else{ + $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->banjiTitle; + $dfsum = 0; + $sbjcnt = 0; + + $cjarr = $this->zzcj($value->ks_chengji); + + // 初始化参数 + $dfsum = 0; + $sbjcnt = 0; + + foreach ($xk as $k => $val) { + // 设置总分的初始值 + $dfsum = null; + // 为每个学科赋值并记录学科数 + if(array_key_exists($k,$cjarr)) + { + $data[$key][$val]=$cjarr[$k] * 1; + $sbjcnt++; + $dfsum = $dfsum + $data[$key][$val]; + }else{ + $data[$key][$val]= null; + } + } + + + + $data[$key]['sum'] = $dfsum; + if($sbjcnt>0){ + $data[$key]['avg'] = round($dfsum/$sbjcnt,1); + }else{ + $data[$key]['avg'] = null; } } @@ -159,14 +289,5 @@ class Chengji extends Base } return $arr; } - - - - - - - - - } diff --git a/app/chengji/model/Tongji.php b/app/chengji/model/Tongji.php index f6b9562d..13aaa742 100644 --- a/app/chengji/model/Tongji.php +++ b/app/chengji/model/Tongji.php @@ -9,8 +9,9 @@ class Tongji extends Base { /** - * 以考号为基础查询学生成绩 + * 取出学生原始成绩 * 信息包括:各学科成绩、平均分、总分 + * 用于学生成绩统计 * @access public * @param number $kaoshi 考试id * @param array $banji 班级 @@ -18,7 +19,7 @@ class Tongji extends Base * @param array $school 学校 * @return array 返回类型 */ - // public function srcChengji1($srcfrom) + // public function srcChengji($srcfrom) // { // // 初始化参数 @@ -59,6 +60,8 @@ class Tongji extends Base // return $data = array(); // } + // halt($khlist->toArray()); + // // 获取参考学科 // $ks = new \app\kaoshi\model\Kaoshi; // $ksinfo = $ks->where('id',$kaoshi) @@ -102,7 +105,6 @@ class Tongji extends Base // 统计成绩 public function tongji($cj=array(),$kaoshi) { - $ks = new \app\kaoshi\model\Kaoshi; $ksinfo = $ks->where('id',$kaoshi) ->field('id') @@ -113,6 +115,17 @@ class Tongji extends Base foreach ($ksinfo->ks_subject as $key => $value) { $cjcol = array_column($cj,$value->lieming); + $filtered = array_filter($data, function($item){ + + return $item['cate'] !== '摄影美图'; + + }); + $cjcol = array_filter($cjcol,function($item){ + return $item !== null; + }); + + halt($cjcol); + // $allcj = array_merge($allcj,$cjcol); $temp = array(); $temp['xkcnt'] = count($cjcol); diff --git a/app/chengji/view/index/index.html b/app/chengji/view/index/index.html index f8201d59..3cddc127 100644 --- a/app/chengji/view/index/index.html +++ b/app/chengji/view/index/index.html @@ -33,7 +33,7 @@
- +
{php} $nianji = new \app\kaoshi\model\KaoshiNianji; @@ -43,7 +43,7 @@ ->select(); {/php} {foreach $njlist as $key=>$vo} - {/foreach}
@@ -117,6 +117,7 @@ kaoshi:"{$list.kaoshi}" ,nianji:"{$list.nianji}" ,school:$("input[name='school']:checked").val() + ,ruxuenian:$("input[name='ruxuenian']:checked").val() } // 设置每页显示条数 diff --git a/app/chengji/view/tongji/yilu_cnt.html b/app/chengji/view/tongji/yilu_cnt.html index f3cab26d..fe3b86a2 100644 --- a/app/chengji/view/tongji/yilu_cnt.html +++ b/app/chengji/view/tongji/yilu_cnt.html @@ -16,10 +16,10 @@
+ {php} $schoollist = schlist('校级','校级',['小学','中小学']);{/php} {volist name="schoollist" id="vo"} - + {/volist}
diff --git a/app/common.php b/app/common.php index 6ea8846b..f87385c2 100644 --- a/app/common.php +++ b/app/common.php @@ -340,6 +340,31 @@ function subjectList() } +/** + * 把request到的参数转换成数组,并删除空值 + * + * @access public + * @param str或array $str 表单中获取的参数 + * @return array 返回类型 + */ +function strToarray($str) +{ + // 如果str是字符串,则转换成数组 + if(is_array($str)==false) + { + $str = explode(',', $str); + } + // 循环数组,删除空元素 + foreach ($str as $key => $value) { + if($value == "" && $value == null){ + unset($str[$key]); + } + } + return $str; +} + + + diff --git a/app/kaoshi/controller/Kaohao.php b/app/kaoshi/controller/Kaohao.php index 6b1f4890..bd17c812 100644 --- a/app/kaoshi/controller/Kaohao.php +++ b/app/kaoshi/controller/Kaohao.php @@ -529,14 +529,14 @@ class Kaohao extends BaseController $sheet->setCellValue('C3', '班级'); $sheet->setCellValue('D3', '姓名'); // 获取列数并合并和一行 - $col = $lieming[count($kslist->ks_subject)+3]; + $col = $lieming[count($kslist->ksSubject)+3]; $sheet->mergeCells('A1:'.$col.'1'); // 写入列名 - foreach ($kslist->ks_subject as $key => $value) { - $sheet->setCellValue($lieming[$key + 4].'3', $value->subject_name->title); - $sheet->setCellValue($lieming[$key + 4].'2', $value->subject_name->id); + foreach ($kslist->ksSubject as $key => $value) { + $sheet->setCellValue($lieming[$key + 4].'3', $value->subjectName->title); + $sheet->setCellValue($lieming[$key + 4].'2', $value->subjectName->id); } // 隐藏第二行和第二列 $sheet->getRowDimension('2')->setRowHeight('0'); @@ -547,11 +547,11 @@ class Kaohao extends BaseController $i = 4; foreach ($kaohao as $key=>$bj) { - foreach ($bj->banji_kaohao as $k => $kh) { + foreach ($bj->banjiKaohao as $k => $kh) { $sheet->setCellValue('A'.$i, $i-3); $sheet->setCellValue('B'.$i, $kh->id); - $sheet->setCellValue('C'.$i, $bj->cj_banji->banjiTitle); - $sheet->setCellValue('D'.$i, $kh->cj_student->xingming); + $sheet->setCellValue('C'.$i, $bj->cjBanji->banjiTitle); + $sheet->setCellValue('D'.$i, $kh->cjStudent->xingming); $i++; } } diff --git a/app/kaoshi/model/Kaohao.php b/app/kaoshi/model/Kaohao.php index 05fc18ba..7463d1fe 100644 --- a/app/kaoshi/model/Kaohao.php +++ b/app/kaoshi/model/Kaohao.php @@ -24,10 +24,7 @@ class Kaohao extends Base ->order(['banji']) ->group('banji,school') ->with([ - 'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian') - ->append(['numTitle','banjiTitle']); - } + 'cjBanji' , 'cjSchool'=>function($query){ $query->field('id,jiancheng'); @@ -67,6 +64,7 @@ class Kaohao extends Base /** + * 列出适合显示的学生成绩, * 以考号为基础查询学生成绩信息并排序,计划在网页上显示成绩列表中使用 * 信息包括:学校、年级、班级、姓名、性别、各学科成绩、平均分、总分 * @access public @@ -83,37 +81,35 @@ class Kaohao extends Base { // 初始化参数 $src = array( - 'page'=>'1', - 'limit'=>'10', - // 'field'=>'banji', - // 'type'=>'desc', 'kaoshi'=>'', - 'school'=>array(), - 'nianji'=>'', + 'school'=>array('0'), + 'ruxuenian'=>'', 'banji'=>array('0'), 'searchval'=>'' ); + // 用新值替换初始值 $src = array_cover( $srcfrom , $src ) ; // 重新定义变量 $school = $src['school']; - $nianji = $src['nianji']; + $ruxuenian = $src['ruxuenian']; $banji = $src['banji']; $seachval = $src['searchval']; + // 查询成绩 $khlist = $this->where('kaoshi',$src['kaoshi']) - ->field('id,school,student,nianji,banji') + ->field('id,school,student,banji,kaoshi') ->when(count($school)>0,function($query) use($school){ $query->where('school','in',$school); }) ->when(count($banji)>0,function($query) use($banji){ $query->where('banji','in',$banji); }) - ->when(strlen($nianji)>0,function($query) use($nianji){ - $query->where('ruxuenian',$nianji); + ->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){ @@ -128,9 +124,6 @@ class Kaohao extends Base 'ksChengji'=>function($query){ $query->field('kaohao_id,subject_id,defen'); } - ,'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian'); - } ,'cjSchool'=>function($query){ $query->field('id,jiancheng'); } @@ -138,6 +131,7 @@ class Kaohao extends Base $query->field('id,xingming,sex'); } ]) + ->append(['banjiTitle']) ->select(); return $khlist; @@ -218,7 +212,7 @@ class Kaohao extends Base * @access public * @param number $kaoshi 考试id * @param number $ruxuenian 入学年 - * @return array 返回类型 + * @return array 返回班级数据模型 */ public function cyBanji($srcfrom) { @@ -240,11 +234,10 @@ class Kaohao extends Base // 获取考试时间 $ks = new \app\kaoshi\model\Kaoshi; - $kssj = $ks::where('id',$src['ruxuenian'])->value('bfdate'); - $year = date('Y',$kssj); + $kssj = $ks::where('id',$src['kaoshi'])->value('bfdate'); - - $data = $this->where('ruxuenian',$src['ruxuenian']) + $bjids = $this + ->where('ruxuenian',$src['ruxuenian']) ->where('kaoshi',$src['kaoshi']) ->when(count($school)>0,function($query) use($school){ $query->where('school','in',$school); @@ -255,26 +248,61 @@ class Kaohao extends Base }); }) ->with([ - 'cjBanji'=>function($query){ - $query->field('id,paixu,ruxuenian'); - } - ,'cjSchool'=>function($query){ + 'cjSchool'=>function($query){ $query->field('id,jiancheng'); } ]) - ->group('banji,school') - ->field('banji,school') - ->select(); - $njlist = nianjiList($year); - $bjlist = banjinamelist(); + ->group('banji') + ->field(['banji']) + ->select() + ->toArray(); - - foreach ($data as $key => $value) { - # code... - $data[$key]['bjtitle'] = $njlist[$value->cjBanji->ruxuenian].$bjlist[$value->cjBanji->paixu]; + foreach ($bjids as $key => $value) { + // halt($key); + $bjids[$key] = $value['banji']; } - return $data; + + $bj = new \app\teach\model\Banji; + + $data = $bj->where('id','in',$bjids) + ->field('id,school') + ->with([ + 'glSchool'=>function($query){ + $query->field('id,title,jiancheng'); + }, + ]) + ->select(); + foreach ($data as $key => $value) { + $data[$key]->banjiTitle = $bj->myBanjiTitle($value->id,$kssj); + } + + return $data->toArray(); + } + + + /** + * 获取参加考试的班级 + * @access public + * @param number $kaoshi 考试id + * @param number $ruxuenian 入学年 + * @return array 返回类型 + */ + public function getBanjiTitleAttr() + { + $ks = $this->where('id',$this->id) + ->with([ + 'cjKaoshi'=>function($query){ + $query->field('id,bfdate'); + } + ]) + ->find(); + $bfdate = $ks->cjKaoshi->getData('bfdate'); + + $bj = new \app\teach\model\Banji; + $title = $bj->myBanjiTitle($this->getAttr('banji'),$bfdate); + + return $title; } } diff --git a/app/teach/model/Banji.php b/app/teach/model/Banji.php index 526f378e..175b44e7 100644 --- a/app/teach/model/Banji.php +++ b/app/teach/model/Banji.php @@ -18,7 +18,7 @@ class Banji extends Base // 查询数据 $data = $this - ->order('school','ruxuenian','paixu') + // ->order('school','ruxuenian','paixu') ->order([$src['field'] =>$src['type']]) ->when(strlen($school)>0,function($query) use($school){ $query->where('school',$school); @@ -43,6 +43,7 @@ class Banji extends Base ]) ->append(['banjiTitle']) ->select(); + return $data; } @@ -70,9 +71,9 @@ class Banji extends Base if(array_key_exists($nj,$numnj)) { - $numname = ($numnj[$nj] + 1).'级'.$bj.'班'; + $numname = ($numnj[$nj] + 1).'.'.$bj; }else{ - $numname = $nj.'级'.$bj.'班'; + $numname = $nj.'.'.$bj; } @@ -84,21 +85,12 @@ class Banji extends Base // 班级名获取器 public function getBanjiTitleAttr() { - $njname = nianjilist(); - $bjname = banjinamelist(); - $nj = $this->getAttr('ruxuenian'); - $bj = $this->getAttr('paixu'); - - $njkeys = array_keys($njname); - $bjkeys = array_keys($bjname); - - in_array($nj,$njkeys) ? $title = $njname[$nj] : $title = $nj.'届'; - in_array($bj,$bjkeys) ? $title = $title.$bjname[$bj] : $title = $title.$bj.'班'; - + // 获取班级名 + $title = $this->myBanjiTitle($this->getAttr('id')); return $title; } - // 班级名获取器 + // 班名获取器 public function getBanTitleAttr() { $bjname = banjinamelist(); @@ -118,4 +110,41 @@ class Banji extends Base return $this->hasMany('Banji','ruxuenian','ruxuenian'); } + + /** + * 获取考试时的班级名称 + * $jdshijian 考试开始时间 + * $ruxuenian 年级 + * $paixu 班级 + * 返回 $str 班级名称 + * */ + public function myBanjiTitle($bjid,$jdshijian=0) + { + // 查询班级信息 + $bjinfo = $this::withTrashed() + ->where('id',$bjid) + ->field('id,ruxuenian,paixu,delete_time') + ->find(); + + + //获取班级、年级列表 + $njlist = nianjiList($jdshijian); + $bjlist = banjinamelist(); + + if(array_key_exists($bjinfo->ruxuenian,$njlist)) + { + $bjtitle = $njlist[$bjinfo->ruxuenian].$bjlist[$bjinfo->paixu]; + }else{ + $bjtitle = $bjinfo->ruxuenian.'界'.$bjinfo->paixu.'班'; + } + + // 如果该班级被删除,则瓢删除 + if($bjinfo->delete_time != null) + { + $bjtitle = $bjtitle.'(删)'; + } + + return $bjtitle; + } + }