From baae7c95a94b020362a26f87edf314099b3e90fa Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sun, 2 Dec 2018 15:04:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E4=B8=8B=E8=BD=BD=E6=A0=87?= =?UTF-8?q?=E7=AD=BEdoc=E6=A0=BC=E5=BC=8F=E6=8D=A2=E6=88=90xls=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chengji/controller/Tongji.php | 26 +++- application/chengji/model/Chengji.php | 20 +++ application/chengji/model/Tongji.php | 34 +++++ application/kaoshi/controller/MoreAction.php | 126 +++++++++++++++---- application/renshi/model/Student.php | 21 +++- application/teach/controller/Banji.php | 5 +- route/kaoshi.php | 2 +- 7 files changed, 195 insertions(+), 39 deletions(-) create mode 100644 application/chengji/model/Tongji.php diff --git a/application/chengji/controller/Tongji.php b/application/chengji/controller/Tongji.php index 703ca2d0..0bc0e41e 100644 --- a/application/chengji/controller/Tongji.php +++ b/application/chengji/controller/Tongji.php @@ -2,14 +2,28 @@ namespace app\chengji\controller; -use think\Controller; -use think\Request; +// 引用控制器基类 +use app\common\controller\Base; -class Tongji extends Controller +class Tongji extends Base { - // 成绩统计汇总表 - public function list() + // 年级成绩汇总 + public function nianji() { - // 根据考试号获取成绩统计结果 + // 实例化成绩数据模型 + $cj = new \app\chengji\model\Chengji; + + // 根据考试号和年级获取考试成绩 + $cjlist = $cj->searchNianji(1,'一年级'); + + + + + + $tj = new \app\chengji\model\Tongji(); + $yuwen = $cjlist->column('yuwen'); + dump($yuwen); + $a = $tj->tongji($yuwen); + dump($a); } } diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index c9e19193..9573035b 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -66,6 +66,12 @@ class Chengji extends Base return $this->belongsTo('\app\renshi\model\Student','student','id'); } + // 满分 + public function cjManfen() + { + return $this->belongsTo('\app\kaoshi\model\KaoshiSubject','kaoshi','kaoshiid'); + } + @@ -183,10 +189,24 @@ class Chengji extends Base ->select(); } + + // 查询年级成绩 + public function searchNianji($kaoshiid,$nianji) + { + return $this->where('kaoshi',$kaoshiid) + ->where('nianji',$nianji) + ->field('id,yuwen,shuxue,waiyu') + ->cache('key',180) + ->select(); + } + + // 考试项目查询范围 public function scopeKaoshi($query,$kaoshiid) { $query->where('kaoshi',$kaoshiid); } + + } diff --git a/application/chengji/model/Tongji.php b/application/chengji/model/Tongji.php new file mode 100644 index 00000000..f2b9a1f9 --- /dev/null +++ b/application/chengji/model/Tongji.php @@ -0,0 +1,34 @@ +sum($cjs); + $avg = $sum/$cnt; + $data = ['cnt'=>$cnt,'avg'=>$avg,'sum'=>$sum]; + return $data; + } + + + // 总分 + public function sum($cjs) + { + $sum = array_sum($cjs); + return $sum; + } + + +} diff --git a/application/kaoshi/controller/MoreAction.php b/application/kaoshi/controller/MoreAction.php index f1fffec3..72a08f03 100644 --- a/application/kaoshi/controller/MoreAction.php +++ b/application/kaoshi/controller/MoreAction.php @@ -69,37 +69,18 @@ class MoreAction extends Base // 将班级转换成数组 $list['banjiids'] = implode(',',$list['banjiids']); + $ksid = $list['kaoshi']; // 获取参加考试学生名单 $stulist = Student::where('status',1) ->where('banji','in',$list['banjiids']) ->field('id,school,banji') - ->append(['nianji']) + ->with('stuNanji') ->select(); - $njlist = nianjilist(); - - // 组合参加考试学生信息 - $stus = array(); - foreach ($stulist as $key => $value) { - $src = Chengji::where('kaoshi',$list['kaoshi']) - ->where('student',$value->id) - ->select(); - if($src->isEmpty()){ - $stus[] = [ - 'kaoshi' => $list['kaoshi'], - 'school' => $value->getData('school'), - 'ruxuenian' => $value->nianji, - 'nianji' => $njlist[$value->nianji], - 'banji' => $value->banji, - 'student' => $value->id - ]; - } - } - - // 声明成绩数据模型类 - $cj = new Chengji(); - $data = $cj->saveAll($stus); + // 保存考号 + $data = $this->khsave($stulist,$ksid); + // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -109,10 +90,44 @@ class MoreAction extends Base } + // 分批保存数据 + private function khsave($stulist,$kaoshiid) + { + $njlist = nianjilist(); + + // 组合参加考试学生信息 + $stus = array(); + foreach ($stulist as $stuinfo) { + $src = Chengji::where('kaoshi',$kaoshiid) + ->where('student',$stuinfo->id) + ->select(); + // dump($stuinfo); + if($src->isEmpty()){ + $stus[] = [ + 'kaoshi' => $kaoshiid, + 'school' => $stuinfo->getData('school'), + 'ruxuenian' => $stuinfo->myruxuenian, + 'nianji' => $njlist[$stuinfo->myruxuenian], + 'banji' => $stuinfo->getData('banji'), + 'student' => $stuinfo->id + ]; + } + } + + $cj = new Chengji(); + // 保存学生信息并生成考号 + $data = $cj->saveAll($stus); + + $data ? $str = true : $str = false; + + return $data; + } + + /** * 生成指定网址的二维码 * @param string $url 二维码中所代表的网址 - */ + */ public function create_qrcode($url='127.0.0.1') { $qrCode = new QrCode($url); @@ -129,6 +144,8 @@ class MoreAction extends Base // 获取数据库信息 $chengjiinfo = Chengji::where('kaoshi',$id) + ->where('ruxuenian',2017) + ->limit(15) ->append(['cj_school.jiancheng','cj_Student.xingming','banjiNumname']) ->select(); @@ -171,6 +188,7 @@ class MoreAction extends Base 'bold' => true, ] ); + // 循环写出信息 foreach ($chengjiinfo as $key => $value) { @@ -179,8 +197,10 @@ class MoreAction extends Base $table = $section->addTable($key); $table->addRow(1500); + $img = $this->create_qrcode($value['id'].','.$xkkey); $table->addCell(850)->addImage($img,$imageStyle); + // $table->addCell(700)->addImage('aaaa.jpg',$imageStyle); $info = $table->addCell(650); @@ -188,6 +208,7 @@ class MoreAction extends Base $info->addText($value['banjiNumname'],$myStyle); $info->addText($value['cj_student']['xingming'],$myStyle); $info->addText($val,$myStyle); + } } @@ -200,6 +221,58 @@ class MoreAction extends Base header('Cache-Control: max-age=0'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('php://output'); + + } + + + + //生成标签信息 + public function biaoqianXls($id) + { + set_time_limit(0); + // 获取数据库信息 + $chengjiinfo = Chengji::where('kaoshi',$id) + // ->where('ruxuenian',2017) + ->append(['cj_school.jiancheng','cj_student.xingming','banjiNumname']) + ->select(); + + // 获取学科id + $xks = KS::get($id); + $xks = $xks->Subjectids; + // 获取学科名称 + $subject = new \app\teach\model\Subject(); + $xks = $subject->where('id','in',$xks)->order('id')->column('id,title'); + + // 创建表格 + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + // 循环写出信息 + $i = 1; + foreach ($chengjiinfo as $key => $value) { + foreach ($xks as $xkkey => $val) { + // 表格赋值 + $sheet->setCellValue('A'.$i, $i); + $sheet->setCellValue('B'.$i, $value->id.','.$xkkey); + $sheet->setCellValue('C'.$i, $value['cj_school']['jiancheng']); + $sheet->setCellValue('D'.$i, $value->banjiNumname); + $sheet->setCellValue('E'.$i, $xks[$xkkey]); + $sheet->setCellValue('F'.$i, $value['cj_student']['xingming']); + $i++; + + } + } + + + // 保存文件 + $filename = '试卷标签信息'.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(); } @@ -297,4 +370,7 @@ class MoreAction extends Base $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); } + + + } diff --git a/application/renshi/model/Student.php b/application/renshi/model/Student.php index 3dddc7b5..93e286ff 100644 --- a/application/renshi/model/Student.php +++ b/application/renshi/model/Student.php @@ -9,6 +9,17 @@ use app\teach\model\Banji; class Student extends Base { + // 班级关联 + public function stuNanji() + { + return $this->belongsTo('\app\teach\model\Banji','banji','id')->bind(['myruxuenian'=>'ruxuenian']); + } + // 班级关联 + public function stuBanji() + { + return $this->belongsTo('\app\teach\model\Banji','banji','id'); + } + // 年龄获取器 public function getAgeAttr() { @@ -48,11 +59,11 @@ class Student extends Base return $sex[$value]; } - // 获取入学年 - public function getNianjiAttr() - { - return db('banji')->where('id',$this->getData('banji'))->value('ruxuenian'); - } + // // 获取入学年 + // public function getNianjiAttr() + // { + // return $this->stuBanji()->ruxuenian; + // } } diff --git a/application/teach/controller/Banji.php b/application/teach/controller/Banji.php index 815cf462..de5c1f39 100644 --- a/application/teach/controller/Banji.php +++ b/application/teach/controller/Banji.php @@ -62,13 +62,14 @@ class Banji extends Base $data = BJ::field('id,school,ruxuenian,paixu,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->whereOr('title','like','%'.$search.'%') + // ->whereOr('title','like','%'.$search.'%') ->whereOr('school','in',function($query) use($search) { - $query->table('school') + $query->name('school') ->where('title','like','%'.$search.'%') ->field('id'); }) + ->whereOr('ruxuenian',$search) ->all(); } diff --git a/route/kaoshi.php b/route/kaoshi.php index b4660142..321aef00 100644 --- a/route/kaoshi.php +++ b/route/kaoshi.php @@ -14,7 +14,7 @@ Route::resource('kaoshi','kaoshi/Index'); Route::get('kaoshi/:id/more','kaoshi/MoreAction/index'); Route::get('kaoshi/:id/kaohao','kaoshi/MoreAction/kaohao'); Route::post('kaoshi/kaohao','kaoshi/MoreAction/kaohaosave'); -Route::get('kaoshi/:id/biaoqian','kaoshi/MoreAction/biaoqian'); +Route::get('kaoshi/:id/biaoqian','kaoshi/MoreAction/biaoqianxls'); Route::get('kaoshi/:id/caiji','kaoshi/MoreAction/caiji'); Route::post('kaoshi/caiji','kaoshi/MoreAction/cankaomingdan');