From 483d4de7fdd8943b2178f69e2205f509acf588a7 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sat, 4 May 2019 20:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chengji/controller/Index.php | 164 +++++------ application/chengji/model/Chengji.php | 64 ++-- application/chengji/view/index/index.html | 216 ++++++++++++++ application/chengji/view/index/malu.html | 4 + .../chengji/view/index/stu_chengjilist.html | 277 ------------------ application/kaoshi/controller/Index.php | 2 +- application/kaoshi/controller/Kaohao.php | 5 +- application/kaoshi/model/Kaohao.php | 45 ++- .../migrations/20190430034853_chengji.php | 1 + route/chengji.php | 2 +- 10 files changed, 363 insertions(+), 417 deletions(-) create mode 100644 application/chengji/view/index/index.html delete mode 100644 application/chengji/view/index/stu_chengjilist.html diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 1ac8ac27..4fb1cbcf 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -7,7 +7,7 @@ use app\common\controller\Base; use app\chengji\model\Chengji; // 引用考号数据模型 use app\kaoshi\model\Kaohao; -// 引用学科数据模型 +// // 引用学科数据模型 use \app\teach\model\Subject; @@ -42,7 +42,7 @@ class Index extends Base $cj = $data->ksChengji()->isEmpty(); if($cj == false) { - $data->ksChengji()->delete(); + $data->ksChengji()->delete(true); } $data = $data->ksChengji()->save([ @@ -164,51 +164,38 @@ class Index extends Base array_splice($cjinfo,0,3); - $cj = new Chengji(); - - - $cjone = $cj->srcOne($cjinfo[0][1]); - - halt($cjone); - - - - // 获取学科满分 - // if($cjinfo[0][1] !=null) - // { - // $manfen = getmanfen($cjinfo[0][1],$xk); - // }else{ - // $data = ['msg'=>'上传失败','val' => 0]; - // return json($data); - // } - $cj = array(); - // $i = 0; + $user_id = session('userid'); // 重新组合成绩信息 foreach ($cjinfo as $key => $value) { - // $x = 3; - foreach ($xklie as $k => $val) { - - if(!empty($value[3+$k]) && manfenvalidate($value[3+$k],$manfen[$k])){ - $cj[$i][$xklie[$k]] = number_format($value[3+$x],1); - $cj[$i]['id'] = $value[1]; + foreach ($xk as $k => $val) { + if($value[$k+4] == null){ + continue; } - $x++; + // 查询是否存在这个成绩 + $cj = Chengji::where('kaohao_id',$value[1]) + ->where('subject_id',$val) + ->find(); + // 如果存在则删除 + if($cj){ + $cj->delete(true); + } + Chengji::create([ + 'kaohao_id'=>$value[1], + 'subject_id'=>$val, + 'user_id'=>$user_id, + 'defen'=>$value[$k+4] + ]); } - $i++; } - // 实例成绩模块 - $cjmod = new Chengji(); - // 保存成绩 - $data = $cjmod->saveAll($cj); - // 判断成绩更新结果 empty($cj) ? $data=['msg'=>'上传失败','val'=>0] : $data=['msg'=>'上传成功','val'=>1]; - // 返回成绩结果 - return json($data); ob_flush(); flush(); + // 返回成绩结果 + return json($data); + } @@ -229,19 +216,31 @@ class Index extends Base // 成绩列表 - public function stuChengjilist($id) + public function index($id) { - // 实例化成绩数据模型 - $cj = new Chengji(); + // 设置要给模板赋值的信息 + $list['webtitle'] = '成绩列表'; + + // 实例化考试数据模型 + $kaoshi = new \app\kaoshi\model\Kaoshi; + $ksinfo = $kaoshi->where('id',$id) + ->field('id') + ->with([ + 'ksSubject'=>function($query){ + $query->field('kaoshiid,subjectid') + ->with(['subjectName'=>function($q){ + $q->field('id,jiancheng,lieming'); + }] + ); + } + ]) + ->find(); + + $list['subject'] = $ksinfo->ks_subject; - // 查询成绩数量 - $list['count'] = $cj->searchAll($id)->count(); - // 设置页面标题 - $list['title'] = '成绩列表'; - $list['kaoshi'] = $id; // 模板赋值 - $this->assign('list', $list); + $this->assign('list',$list); // 渲染模板 return $this->fetch(); @@ -252,66 +251,45 @@ class Index extends Base // 获取考试信息 public function ajaxData() { - // 获取DT的传值 - $getdt = request()->param(); - - //得到排序的方式 - $order = $getdt['order'][0]['dir']; - //得到排序字段的下标 - $order_column = $getdt['order'][0]['column']; - //根据排序字段的下标得到排序字段 - $order_field = $getdt['columns'][$order_column]['name']; - if($order_field=='') - { - $order_field = $getdt['columns'][$order_column]['data']; - } - //得到limit参数 - $limit_start = $getdt['start']; - $limit_length = $getdt['length']; - - // 获取班级id - $njlist = nianjiList(); - $njnum = array_keys($njlist); - $bj = new \app\teach\model\Banji; - $bjlist = $bj->where('ruxuenian','in',$njnum) - ->where('paixu','in',$getdt['banji']) - ->column('id'); + // 获取参数 + $src = $this->request + ->only([ + 'page'=>'1', + 'limit'=>'10', + 'field'=>'update_time', + 'order'=>'desc', + 'kaoshi'=>'1', + // 'danwei'=>array(), + // 'xueli'=>array(), + 'searchval'=>'' + ],'POST'); - //得到搜索的关键词 - $search = [ - 'kaoshiid'=>$getdt['kaoshi'], - 'school'=>$getdt['school'], - 'nianji'=>$getdt['nianji'], - 'banji'=>$bjlist, - 'search'=>$getdt['search']['value'], - 'order'=>$order, - 'order_field'=>$order_field - ]; - + // 实例化 + $chengji = new Kaohao; - // 实例化成绩数据模型 - $cj = new Chengji(); + // 查询要显示的数据 + $data = $chengji->srcChengji($src); - // 查询成绩总数 - $cnt = $cj->searchAll($getdt['kaoshi'])->count(); - // 分页查询成绩 - $data = $cj->searchAjax($search); - // 获取符合条件记录数 - $datacnt = $data->count(); + + + // 获取符合条件记录总数 + $cnt = $data->count(); // 获取当前页数据 + $limit_start = $src['page'] * $src['limit'] - $src['limit']; + $limit_length = $src['limit']; $data = $data->slice($limit_start,$limit_length); - - + // 重组返回内容 $data = [ - 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 - 'recordsTotal'=>$cnt, // 获取到的结果数(每页显示数量) - 'recordsFiltered'=>$datacnt, // 符合条件的总数据量 + 'code'=> 0 , // ajax请求次数,作为标识符 + 'msg'=>"", // 获取到的结果数(每页显示数量) + 'count'=>$cnt, // 符合条件的总数据量 'data'=>$data, //获取到的数据结果 ]; + return json($data); } diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index 3b3c41bb..a7da9074 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -9,46 +9,42 @@ use app\common\model\Base; class Chengji extends Base { - - // 定义更新成绩后计算平均分和总分 - // protected static function init() - // { - // self::afterUpdate(function ($cj) { - // $cj =self::where('id',$cj->id)->find(); - // // 重新组合数组 - // $num[] = $cj->yuwen; - // $num[] = $cj->shuxue; - // $num[] = $cj->waiyu; - - // // 删除空数据 - // foreach ($num as $key => $value) { - // if($value == null) - // { - // unset($num[$key]); - // } - // } - - // // 获取数组长度 - // $cnt = count($num); - - // // 如果存在数据则计算平均分与总分 - // if($cnt>0) - // { - // $cj->stuSum=array_sum($num); - // $cj->stuAvg=$cj->stuSum/$cnt; - // $cj->stuAvg = round($cj->stuAvg,1); - // } - - // $cj->save(); - // }); - // } - // 成绩和学科关联 public function cjSubject() { return $this->belongsTo('\app\teach\model\Subject'); } + // 数据筛选 + public function search($src) + { + // 获取参数 + $kaoshi = $src['kaoshi']; + // $banji = $src['banji']; + $searchval = $src['searchval']; + + + $data = $this + ->order([$src['field'] =>$src['order']]) + // ->when(count($school)>0,function($query) use($school){ + // $query->where('school','in',$school); + // }) + ->when(strlen($searchval)>0,function($query) use($searchval){ + $query->where('xingming','like','%'.$searchval.'%')->field('id'); + }) + // ->append(['age']) + ->select(); + + return $data; + } + + + // 学科关联 + public function subjectName() + { + return $this->belongsTo('\app\teach\model\Subject','subject_id','id'); + } + diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html new file mode 100644 index 00000000..685faab6 --- /dev/null +++ b/application/chengji/view/index/index.html @@ -0,0 +1,216 @@ + +{extend name="common@list" /} +{block name="jsset"} + +{/block} +{block name="nav"} + + 系统管理 + 单位管理 + 单位列表 + +{/block} +{block name="search"} + + + +{/block} +{block name="table"} + + + + + + + {volist name="$list.subject" id="vo"} + + {/volist} + + +
学校年级 班级{$vo.subject_name.jiancheng}
+ + +{/block} +{block name="myjs"} + + + + + + +{/block} \ No newline at end of file diff --git a/application/chengji/view/index/malu.html b/application/chengji/view/index/malu.html index a9feb625..c5849a7e 100644 --- a/application/chengji/view/index/malu.html +++ b/application/chengji/view/index/malu.html @@ -40,6 +40,10 @@ $('#xsbanji').text(''); $('#xsxingming').text(''); $('#xsxueke').text(''); + $('#kaohao_id').val(''); + $('#subject_id').val(''); + $('#defen').val(''); + var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13'){ // 查询并显示学生信息 diff --git a/application/chengji/view/index/stu_chengjilist.html b/application/chengji/view/index/stu_chengjilist.html deleted file mode 100644 index 2161cef9..00000000 --- a/application/chengji/view/index/stu_chengjilist.html +++ /dev/null @@ -1,277 +0,0 @@ -{extend name="common@list" /} -{block name="topnav"} - -{/block} -{block name="bouttons"} -
- - - - - 批量删除 - - - - - 下载成绩 - - - - 共有数据:{$list.count} 条 - -
-
-
筛选成绩
-
-
- {php} - $school = schlist('校级','校级'); - {/php} -
-
- {foreach $school as $key=>$vo } - - {/foreach} -
- -
-
- -
-
- - - - - - -
- -
-
- {php} - $banji = new app\teach\model\Banji; - $njlist = nianjiList(); - $bjnames = banjinamelist(); - $njnum = array_keys($njlist); - $bjlist = $banji->where('ruxuenian','in',$njnum)->max('paixu') + 1; - {/php} - -
- {for start="1" end="$bjlist"} - - {/for} - -
-
-
-
- -{/block} -{block name="tables"} - - - - - - - - - - - - - - - - - - -
学校年级学生语文数学英语平均总分状态操作
- - -{/block} -{block name="myjs"} - -{/block} \ No newline at end of file diff --git a/application/kaoshi/controller/Index.php b/application/kaoshi/controller/Index.php index 08af966b..e071c640 100644 --- a/application/kaoshi/controller/Index.php +++ b/application/kaoshi/controller/Index.php @@ -316,7 +316,7 @@ class Index extends Base // 根据更新结果设置返回提示信息 - $ksdata && $subjectdata && $nianjidata ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + $ksdata && $subjectdata && $nianjidata ? $data=['msg'=>'设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 return json($data); diff --git a/application/kaoshi/controller/Kaohao.php b/application/kaoshi/controller/Kaohao.php index 5e2dcd09..10ff01ab 100644 --- a/application/kaoshi/controller/Kaohao.php +++ b/application/kaoshi/controller/Kaohao.php @@ -361,8 +361,7 @@ class Kaohao extends Base } // 保存文件 - // $filename = $kslist->title.' 标签数据'.date('ymdHis').'.xls'; - $filename = 'aa.xls'; + $filename = $kslist->title.' 标签数据'.date('ymdHis').'.xls'; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); @@ -496,7 +495,7 @@ class Kaohao extends Base // 写入列名 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->lieming); + $sheet->setCellValue($lieming[$key + 4].'2', $value->subject_name->id); } // 隐藏第二行和第二列 $sheet->getRowDimension('2')->setRowHeight('0'); diff --git a/application/kaoshi/model/Kaohao.php b/application/kaoshi/model/Kaohao.php index 2f032e75..36568b68 100644 --- a/application/kaoshi/model/Kaohao.php +++ b/application/kaoshi/model/Kaohao.php @@ -17,19 +17,19 @@ class Kaohao extends Base ->order(['banji']) ->group('banji') ->with([ - 'cjBanji'=>function($q){ - $q->field('id,paixu,ruxuenian') + 'cjBanji'=>function($query){ + $query->field('id,paixu,ruxuenian') ->append(['numTitle','banjiTitle']); } - ,'cjSchool'=>function($q){ - $q->field('id,jiancheng'); + ,'cjSchool'=>function($query){ + $query->field('id,jiancheng'); } - ,'banjiKaohao'=>function($q){ - $q->field('id,banji,student,kaoshi,school') + ,'banjiKaohao'=>function($query){ + $query->field('id,banji,student,kaoshi,school') ->order(['banji','id']) ->with([ - 'cjStudent'=>function($qsm){ - $qsm->field('id,xingming'); + 'cjStudent'=>function($q){ + $q->field('id,xingming'); } ]); } @@ -38,6 +38,35 @@ class Kaohao extends Base return $data; } + + // 查询学生成绩 + public function srcChengji($src) + { + $data = $this->where('kaoshi',$src['kaoshi']) + ->field('id,school,student,nianji,banji') + ->with([ + 'ksChengji'=>function($query){ + $query->field('kaohao_id,subject_id,defen') + ->with([ + 'subjectName'=>function($q){ + $q->field('id,lieming'); + } + ]); + } + ,'cjBanji'=>function($query){ + $query->field('id,paixu,ruxuenian') + ->append(['numTitle','banjiTitle']); + } + ,'cjSchool'=>function($query){ + $query->field('id,jiancheng'); + } + ]) + ->order([$src['field'] =>$src['order']]) + ->select(); + + return $data; + } + // 满分 public function banjiKaohao() { diff --git a/database/migrations/20190430034853_chengji.php b/database/migrations/20190430034853_chengji.php index 81c24a0e..dc25e34f 100644 --- a/database/migrations/20190430034853_chengji.php +++ b/database/migrations/20190430034853_chengji.php @@ -36,6 +36,7 @@ class Chengji extends Migrator ->addColumn('kaohao_id','integer',['limit'=>11,'null'=>false,'comment'=>'考试']) ->addColumn('subject_id','integer',['limit'=>4,'null'=>false,'comment'=>'入学年']) ->addColumn('user_id','string',['limit'=>4,'null'=>false,'comment'=>'年级']) + ->addColumn('defen','decimal',['precision'=>4,'scale'=>1,'default'=>Null,'null'=>false,'comment'=>'年级']) ->addColumn('create_time','integer',['limit'=>11,'null'=>true,'comment'=>'创建时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->addColumn('update_time','integer',['limit'=>11,'null'=>true,'comment'=>'更新时间']) diff --git a/route/chengji.php b/route/chengji.php index a821aa57..2e702ccd 100644 --- a/route/chengji.php +++ b/route/chengji.php @@ -21,7 +21,7 @@ Route::post('chengji/read','chengji/Index/read'); Route::get('chengji/biaolu','chengji/Index/biaolu'); Route::post('chengji/biaolu','chengji/Index/saveAll'); // 获取学生成绩列表 -Route::get('chengji/:id/stuChengjilist','chengji/Index/stuChengjilist'); +Route::get('chengji/:id/stuChengjilist','chengji/Index/index'); Route::delete('chengji/:id/cj','chengji/Index/deletecj'); #只清空成绩 Route::get('cjtongji/:id/banji','chengji/Tongji/tjBanji'); # 班级成绩统计列表 Route::get('cjtongji/:id/nianji','chengji/Tongji/tjNianji'); # 年级成绩统计列表