diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index 5148c3c1..4af40611 100644 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -401,7 +401,6 @@ class Index extends BaseController // 获取参与考试的班级 $kh = new \app\kaoshi\model\Kaohao; $src['banji']= array_column($kh->cyBanji($src), 'id'); - // 实例化 $cj = new Chengji; @@ -664,15 +663,7 @@ class Index extends BaseController // 获取参与考试的班级 $kh = new \app\kaoshi\model\Kaohao; - $src['banji']= array_column($kh->cyBanji($src), 'id'); - - - // 获取数据库信息 - $kh = new Kaohao(); - // $src = [ - // 'kaoshi'=>$list['kaoshi'], - // 'banji'=>$list['banji'], - // ]; + $chengjiinfo = $kh->srcChengji($src); @@ -788,6 +779,185 @@ class Index extends BaseController + // 下载成绩表格 + public function dwChengjitiao($kaoshi) + { + + // 设置页面标题 + $list['set'] = array( + 'webtitle'=>'成绩下载', + 'butname'=>'下载', + 'formpost'=>'POST', + 'url'=>'/chengji/index/dwcjtiaoxlsx', + 'kaoshi'=>$kaoshi + ); + + // 模板赋值 + $this->view->assign('list',$list); + // 渲染 + return $this->view->fetch(); + } + + + + + + //生成学生表格 + public function dwchengjitiaoxlsx() + { + // 获取参数 + $src = $this->request + ->only([ + 'kaoshi'=>'1', + 'banji'=>array(), + 'school', + 'ruxuenian' + ],'POST'); + + + // 获取要下载成绩的学校和年级信息 + $school = new \app\system\model\School; + $schoolname = $school->where('id',$src['school'])->value('jiancheng'); + + // 实例化验证模型 + $validate = new \app\chengji\validate\Cjdownload; + // 验证表单数据 + $result = $validate->check($src); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + $this->error($msg); + } + + $src['school'] = strToarray($src['school']); + + // 获取当前年级成绩统计结果 + $kh = new Kaohao; + $tj = new \app\chengji\model\Tongji; + $srcAll = [ + 'kaoshi'=>$src['kaoshi'], + 'ruxuenian'=>$src['ruxuenian'] + ]; + $srcAll['banji']= array_column($kh->cyBanji($srcAll), 'id'); + $chengjiinfo = $kh->srcChengji($src); + + $njtj = $tj->tongji($chengjiinfo,$src['kaoshi']); + + // 获取部分学生成绩 + $chengjiinfo = $kh->srcChengji($src); + + + // 获取考试标题 + $ks = new \app\kaoshi\model\Kaoshi; + $ks = $ks->where('id',$src['kaoshi']) + ->field('id,title,bfdate') + ->with([ + 'ksSubject'=>function($query){ + $query->field('kaoshiid,subjectid') + ->with(['subjectName'=>function($q){ + $q->field('id,title,lieming'); + }] + ); + } + ]) + ->find(); + // 获取考试年级名称 + $njlist = nianjiList($ks->getData('bfdate')); + $nianji = $njlist[$src['ruxuenian']]; + + $tabletitle =$ks->title.' '.$schoolname.' '.$nianji.' '.'学生成绩条'; + + $colname = excelLieming(); + + set_time_limit(0); + // 创建表格 + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet; + $sheet = $spreadsheet->getActiveSheet(); + + + $row = 1; # 定义从 $row 行开始写入数据 + $rows = count($ks->ks_subject); # 定义学生信息列要合并的行数 + + // 给单元格加边框 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'color' => ['argb' => '00000000'], + ], + ], + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, //垂直居中 + ], + ]; + + // 从这里开始循环写入学生成绩 + foreach ($chengjiinfo as $key => $value) { + + // 写入学生信息 + $sheet->setCellValue('A'.$row, '学校'); + $sheet->mergeCells('A'.($row+1).':'.'A'.($row+$rows)); # 输入学科名 + $sheet->setCellValue('A'.($row+1), $schoolname); + $sheet->setCellValue('B'.$row, '班级'); + $sheet->mergeCells('B'.($row+1).':'.'B'.($row+$rows)); # 输入学科名 + $sheet->getStyle('B'.($row+1))->getAlignment()->setWrapText(true); + $sheet->setCellValue('B'.($row+1), $value['banji']); + $sheet->setCellValue('C'.$row, '姓名'); + $sheet->mergeCells('C'.($row+1).':'.'C'.($row+$rows)); # 输入学科名 + $sheet->setCellValue('C'.($row+1), $value['student']); + $sheet->setCellValue('D'.$row, '学科'); + $sheet->setCellValue('E'.$row, '得分'); + $sheet->setCellValue('F'.$row, '平均分'); + $sheet->setCellValue('G'.$row, '优秀率%'); + $sheet->setCellValue('H'.$row, '及格率%'); + $sheet->setCellValue('I'.$row, '最高分'); + $sheet->setCellValue('J'.$row, '%75'); + $sheet->setCellValue('K'.$row, '%50'); + $sheet->setCellValue('L'.$row, '%25'); + $row = $row + 1 ; + + + // 写入成绩 + foreach ($ks->ks_subject as $k => $val) { + $sheet->setCellValue('D'.($row+$k), $val->subjectName->title); + $sheet->setCellValue('E'.($row+$k), $value[$val->subject_name->lieming]); # 得分 + $sheet->setCellValue('F'.($row+$k), $njtj[$val->subject_name->lieming]['avg']); + $sheet->setCellValue('G'.($row+$k), $njtj[$val->subject_name->lieming]['max']); + $sheet->setCellValue('H'.($row+$k), $njtj[$val->subject_name->lieming]['youxiu']); + $sheet->setCellValue('I'.($row+$k), $njtj[$val->subject_name->lieming]['jige']); + $sheet->setCellValue('J'.($row+$k), $njtj[$val->subject_name->lieming]['sifenwei'][0]); + $sheet->setCellValue('K'.($row+$k), $njtj[$val->subject_name->lieming]['sifenwei'][1]); + $sheet->setCellValue('L'.($row+$k), $njtj[$val->subject_name->lieming]['sifenwei'][2]); + } + + // 设置格式 + $sheet->getStyle('A'.($row-1).':L'.($row+$rows-1))->applyFromArray($styleArray); + + + $row = $row + $rows +1 ; + + + + } + + + // 保存文件 + $filename = $tabletitle.date('ymdHis').'.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer->save('php://output'); + ob_flush(); + flush(); + } + + + + + // 学生成绩录入信息 public function readAdd($kaohao) { diff --git a/app/chengji/model/Tongji.php b/app/chengji/model/Tongji.php index eb981437..21cae20b 100644 --- a/app/chengji/model/Tongji.php +++ b/app/chengji/model/Tongji.php @@ -128,6 +128,8 @@ class Tongji extends Base $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); $data[$value->lieming] = $temp; } diff --git a/app/chengji/route/chengji.php b/app/chengji/route/chengji.php index 698b1e7c..765448ad 100644 --- a/app/chengji/route/chengji.php +++ b/app/chengji/route/chengji.php @@ -29,6 +29,8 @@ Route::group('index', function () { Route::rule('deletecjmore','Index/deletecjmore','post'); # 成绩删除 Route::rule('dwchengji/','Index/dwChengji','get'); # 成绩删除 Route::rule('dwxlsx','Index/dwchengjixlsx','post'); # 成绩删除 + Route::rule('dwchengjitiao/','Index/dwChengjitiao','get'); # 成绩删除 + Route::rule('dwcjtiaoxlsx','Index/dwchengjitiaoxlsx','post'); # 成绩删除 }); diff --git a/app/chengji/view/index/dw_chengjitiao.html b/app/chengji/view/index/dw_chengjitiao.html new file mode 100644 index 00000000..1c48fb20 --- /dev/null +++ b/app/chengji/view/index/dw_chengjitiao.html @@ -0,0 +1,134 @@ +{extend name=".././view/create.html" /} + +{block name="form"} +
+ +
+ +
+ {php} $schoollist = schlist('校级','校级',['小学','中小学']);{/php} + +
+
+
+ +
+ {php} + $nianji = new \app\kaoshi\model\KaoshiNianji; + $njlist = $nianji + ->where('kaoshiid',$list['set']['kaoshi']) + ->field('nianji,nianjiname') + ->select(); + {/php} + +
+
+
+ +
+
+
+ +
+ +
+
+{/block} + +{block name="myjs"} + +{/block} + diff --git a/app/common.php b/app/common.php index 6fcd5467..58b4b365 100644 --- a/app/common.php +++ b/app/common.php @@ -35,7 +35,6 @@ function getCategory($str = 0) ->where('pid',$str) ->where('status',1) ->field('id,title') - // ->fetchSql(true) ->select(); @@ -151,7 +150,7 @@ function getAgeByBirth($date = 0,$type = 1){ // EXCEL表格列名 function excelLieming() { - $liemingarr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF']; + $liemingarr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW']; return $liemingarr; } diff --git a/app/kaoshi/controller/Kaohao.php b/app/kaoshi/controller/Kaohao.php index ebffe8ad..5cc908a3 100644 --- a/app/kaoshi/controller/Kaohao.php +++ b/app/kaoshi/controller/Kaohao.php @@ -31,16 +31,17 @@ class Kaohao extends BaseController ]) ->find(); - if(count($kaoshilist->ks_nianji)>0) + + if(count($kaoshilist->ksNianji)>0) { - foreach ($kaoshilist->ks_nianji as $key => $value) { + foreach ($kaoshilist->ksNianji as $key => $value) { $list['data']['nianji'][$key]['id']=$value->nianji; $list['data']['nianji'][$key]['title']=$value->nianjiname; } }else{ $list['data']['nianji']= array(); } - + // 设置页面标题 @@ -93,11 +94,12 @@ class Kaohao extends BaseController ->field('id,school,banji') ->with([ 'stuBanji'=>function($query){ - $query->field('id,ruxuenian'); + $query->field('id,ruxuenian,paixu'); } ]) ->select(); + $njlist = nianjiList(); // 重新组合学生信息 $kaohao = array(); @@ -122,9 +124,10 @@ class Kaohao extends BaseController } $kaohao[$key]['student']= $value->id; $kaohao[$key]['school']= $list['school']; - $kaohao[$key]['ruxuenian']= $value->stu_banji->ruxuenian; + $kaohao[$key]['ruxuenian']= $value->stuBanji->ruxuenian; $kaohao[$key]['nianji']= $njlist[$kaohao[$key]['ruxuenian']]; - $kaohao[$key]['banji']= $value->stu_banji->id; + $kaohao[$key]['banji']= $value->stuBanji->id; + $kaohao[$key]['paixu']= $value->stuBanji->id; $kaohao[$key]['kaoshi']= $list['kaoshi']; } @@ -132,7 +135,7 @@ class Kaohao extends BaseController $kh = new \app\kaoshi\model\Kaohao; $data = $kh - ->allowField(['id','kaoshi','student','school','ruxuenian','nianji','banji','create_time','update_time']) + ->allowField(['id','kaoshi','student','school','ruxuenian','nianji','banji','paixu','create_time','update_time']) ->saveAll($kaohao); diff --git a/app/kaoshi/model/Kaohao.php b/app/kaoshi/model/Kaohao.php index bca06751..6821e235 100644 --- a/app/kaoshi/model/Kaohao.php +++ b/app/kaoshi/model/Kaohao.php @@ -24,14 +24,17 @@ class Kaohao extends Base ->order(['banji']) ->group('banji,school') ->with([ - 'cjBanji' + 'cjBanji'=>function($query){ + $query->field('id,school,ruxuenian,paixu') + ->append(['banjiTitle','numTitle']); + } , 'cjSchool'=>function($query){ $query->field('id,jiancheng'); } , 'banjiKaohao'=>function($query) use($kaoshi){ - $query->field('id,banji,student,kaoshi,school') + $query->field('id,student') ->where('kaoshi',$kaoshi) ->order(['banji','id']) ->with([ @@ -59,6 +62,8 @@ class Kaohao extends Base } } + halt($data->toArray()); + return $data; } @@ -330,20 +335,21 @@ class Kaohao extends Base $ks = new \app\kaoshi\model\Kaoshi; $kssj = $ks::where('id',$src['kaoshi'])->value('bfdate'); + $bjids = $this - ->where('ruxuenian',$src['ruxuenian']) + // ->where('ruxuenian',$src['ruxuenian']) ->where('kaoshi',$src['kaoshi']) - ->when(count($school)>0,function($query) use($school){ - $query->where('school','in',$school); - }) - ->when(count($paixu)>0,function($query) use($paixu){ - $query->withTrashed() - ->where('banji','in',function($q)use($paixu){ - $q->name('banji') - ->where('paixu','in',$paixu) - ->field('id'); - }); - }) + // ->when(count($school)>0,function($query) use($school){ + // $query->where('school','in',$school); + // }) + // ->when(count($paixu)>0,function($query) use($paixu){ + // $query->withTrashed() + // ->where('banji','in',function($q)use($paixu){ + // $q->name('banji') + // ->where('paixu','in',$paixu) + // ->field('id'); + // }); + // }) ->with([ 'cjSchool'=>function($query){ $query->field('id,jiancheng'); @@ -354,6 +360,8 @@ class Kaohao extends Base ->select() ->toArray(); + halt($bjids); + foreach ($bjids as $key => $value) { // halt($key); diff --git a/app/kaoshi/view/index/more_action.html b/app/kaoshi/view/index/more_action.html index b255f2e7..c8e152f7 100644 --- a/app/kaoshi/view/index/more_action.html +++ b/app/kaoshi/view/index/more_action.html @@ -98,6 +98,14 @@ +
diff --git a/app/login/view/index/shangma_log.html b/app/login/view/index/shangma_log.html index e27b21e2..5857b4f8 100644 --- a/app/login/view/index/shangma_log.html +++ b/app/login/view/index/shangma_log.html @@ -43,6 +43,8 @@ 增加考试结束后,不能修改考号、成绩等信息。
恢复班级删除,修改班级移动方法和前端效果 +
+ 修改部分数据排序方法

diff --git a/app/teach/model/Banji.php b/app/teach/model/Banji.php index 43abac33..655f398e 100644 --- a/app/teach/model/Banji.php +++ b/app/teach/model/Banji.php @@ -100,6 +100,9 @@ class Banji extends Base in_array($bj,$bjkeys) ? $title = $bjname[$bj] : $title = $bj.'班'; + $del = $this->getAttr('delete_time'); + $del==null ? $title : $title=$title&'(删)' ; + return $title; } @@ -138,7 +141,7 @@ class Banji extends Base $bjtitle = $bjinfo->ruxuenian.'界'.$bjinfo->paixu.'班'; } - // 如果该班级被删除,则瓢删除 + // 如果该班级被删除,则标删除 if($bjinfo->delete_time != null) { $bjtitle = $bjtitle.'(删)'; diff --git a/database/migrations/20181114055804_kaohao.php b/database/migrations/20181114055804_kaohao.php index 2301ed59..7686386a 100644 --- a/database/migrations/20181114055804_kaohao.php +++ b/database/migrations/20181114055804_kaohao.php @@ -38,6 +38,7 @@ class Kaohao extends Migrator ->addColumn('ruxuenian','integer',['limit'=>4,'null'=>false,'comment'=>'入学年']) ->addColumn('nianji','string',['limit'=>4,'null'=>false,'comment'=>'年级']) ->addColumn('banji','integer',['limit'=>11,'null'=>false,'comment'=>'班级']) + ->addColumn('paixu','integer',['limit'=>11,'null'=>false,'comment'=>'班级排序']) ->addColumn('student','integer',['limit'=>11,'null'=>false,'comment'=>'学生']) ->addColumn('create_time','integer',['limit'=>11,'null'=>true,'comment'=>'创建时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])