From 4ee02a9c4259634f371d741e59eb03208abea9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE=E6=A0=91?= Date: Tue, 11 Jun 2019 14:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E7=9C=8B=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E4=BA=BA=E4=BF=A1=E6=81=AF=E5=92=8C=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=88=90=E7=BB=A9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chengji/common.php | 43 +++- application/chengji/controller/Index.php | 194 +++++++++++++------ application/chengji/controller/Tongji.php | 6 +- application/chengji/model/Chengji.php | 6 + application/chengji/view/index/index.html | 9 +- application/chengji/view/index/read_add.html | 130 +++++++++++++ application/common/view/list.html | 4 +- route/chengji.php | 4 +- 8 files changed, 319 insertions(+), 77 deletions(-) create mode 100644 application/chengji/view/index/read_add.html diff --git a/application/chengji/common.php b/application/chengji/common.php index 38eda1d8..9719a412 100644 --- a/application/chengji/common.php +++ b/application/chengji/common.php @@ -1,26 +1,53 @@ where('id',$cjid)->value('kaoshi'); + $kh = new app\kaoshi\model\Kaohao; + $kaoshiid = $kh->where('id',$kaohaoid)->value('kaoshi'); // 根据考试号和学科名获取满分 $KSXK = new app\kaoshi\model\KaoshiSubject; - $manfen = $KSXK->where('kaoshiid',$kaoshiid)->where('subjectid','in',$subjectid)->column('subjectid,manfen'); + $manfen = $KSXK->where('kaoshiid',$kaoshiid)->where('subjectid','in',$subjectid)->value('manfen'); + $manfen = floatval($manfen); return $manfen; - } // 分数验证 function manfenvalidate($defen,$manfen) { - if(is_numeric($defen) && $defen>=0 && $defen<=$manfen && ($defen*10)%5==0) + $data['val'] = 1; + $data['msg'] = '验证通过'; + + if(is_numeric($defen) == false) { - return true; + $data['val'] = 0; + $data['msg'] = '得分必须是数字'; + return $data; } - return false; + + if( $defen < 0 ) + { + $data['val'] = 0; + $data['msg'] = '得分必须大于等于0'; + return $data; + } + + if($defen > $manfen) + { + $data['val'] = 0; + $data['msg'] = '得分必须必须小于等于'.$manfen; + return $data; + } + + if( ($defen*10)%5 != 0 ) + { + $data['val'] = 0; + $data['msg'] = '得分必须只能是x.5'; + return $data; + } + + return $data; } diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index c136eb64..76e5dcd2 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -37,19 +37,31 @@ class Index extends Base // 获取表单数据 $list = $this->request->only(['kaohao_id','subject_id','defen'],'post'); - // 更新成绩 - $data = Kaohao::where('id',$list['kaohao_id'])->find(); - $cj = $data->ksChengji()->isEmpty(); - if($cj == false) + // 成绩验证 + $manfen = getmanfen($list['kaohao_id'],$list['subject_id']); + $mfyz = manfenvalidate($list['defen'],$manfen); + if($mfyz['val'] == 0) { - $data->ksChengji()->delete(true); + return json($mfyz); } - $data = $data->ksChengji()->save([ - 'subject_id'=>$list['subject_id'], - 'defen'=>$list['defen'], - 'user_id'=>session('userid') - ]); + $cj = new Chengji(); + // 更新成绩 + $data = Chengji::withTrashed() + ->where('subject_id',$list['subject_id']) + ->where('kaohao_id',$list['kaohao_id']) + ->find(); + + if($data) + { + $data->delete(true); + } + + $cj->kaohao_id = $list['kaohao_id']; + $cj->subject_id = $list['subject_id']; + $cj->defen = $list['defen']; + $cj->user_id = session('userid'); + $data = $cj->save(); $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -69,44 +81,24 @@ class Index extends Base // 获取学科信息 $subject = new \app\teach\model\Subject; $subject_id = $subject->where('lieming',$list['colname'])->value('id'); - // 获取考试信息 - $kaohao = new \app\kaoshi\model\Kaohao; - $kaohaoinfo = $kaohao->where('id',$list['kaohao_id']) - ->with([ - 'cjKaoshi'=>function($query) use($subject_id){ - $query->field('id') - ->with([ - 'ksSubject'=>function($q) use($subject_id){ - $q->field('id,kaoshiid,subjectid,manfen') - ->where('subjectid',$subject_id); - } - ]); - } - ]) - ->field('id,kaoshi') - ->find(); - // 验证成绩 - if($list['newdefen'] === null){ # 如果不存在值,跳过这次循环 - $data=['msg'=>'没有找到值','val'=>0]; - return $data; - } - if(is_numeric($list['newdefen'])==false){ # 如果不为数字、则跳过 - $data=['msg'=>'请输入数字','val'=>0]; - return $data; - } - if( $list['newdefen']<0 || $list['newdefen'] > $kaohaoinfo->cj_kaoshi->ks_subject[0]->manfen) # 如果大于满分、小于0分的时候也跳过 + + // 成绩验证 + $manfen = getmanfen($list['kaohao_id'],$subject_id); + $mfyz = manfenvalidate($list['newdefen'],$manfen); + if($mfyz['val'] == 0) { - $data=['msg'=>'得分范围在要大于等于0分,小于等于'.$kaohaoinfo->cj_kaoshi->ks_subject[0]->manfen.'分','val'=>0]; - return $data; + return json($mfyz); } // 更新成绩 $cj = new Chengji; - $cjinfo = $cj->where('kaohao_id',$list['kaohao_id']) + $cjinfo = Chengji::withTrashed() + ->where('kaohao_id',$list['kaohao_id']) ->where('subject_id',$subject_id) ->find(); // 如果存在成绩则更新,不存在则添加 if($cjinfo){ + $cjinfo->restore(); $cjinfo->defen = $list['newdefen']; $cjinfo->user_id = session('userid'); $data = $cjinfo->save(); @@ -138,8 +130,7 @@ class Index extends Base $list = explode('|',$val); $sbj = $list[1]; - $kh = new Kaohao; - $cjlist = $kh->where('id',$list[0]) + $cjlist = Kaohao::where('id',$list[0]) ->field('id,banji,school,student') ->with([ 'ksChengji'=>function($q) use($sbj){ @@ -220,30 +211,46 @@ class Index extends Base if($defen === null){ continue; } - // 如果不为数字、则跳过 - if(is_numeric($defen)==false){ - continue; - } - - $kaoshiid = $kh->where('id',$value[1])->value('kaoshi'); - $manfen = $ks->where('id',$kaoshiid) - ->field('id') - ->with([ - 'ksSubject'=>function($query) use($thissbj){ - $query->field('kaoshiid,subjectid,manfen') - ->where('subjectid',$thissbj); - } - ]) - ->find(); - - // 如果大于满分、小于0分的时候也跳过 - if( $defen<0 || $defen>$manfen->ks_subject[0]->manfen ) + // 成绩验证 + $manfen = getmanfen($value[1],$val); + $mfyz = manfenvalidate($defen,$manfen); + if($mfyz['val'] == 0) { continue; } + + // dump($value); + // halt($val); + + // // 如果不为数字、则跳过 + // if(is_numeric($defen)==false){ + // continue; + // } + + + // $kaoshiid = $kh->where('id',$value[1])->value('kaoshi'); + // $manfen = $ks->where('id',$kaoshiid) + // ->field('id') + // ->with([ + // 'ksSubject'=>function($query) use($thissbj){ + // $query->field('kaoshiid,subjectid,manfen') + // ->where('subjectid',$thissbj); + // } + // ]) + // ->find(); + + // // 如果大于满分、小于0分的时候也跳过 + // if( $defen<0 || $defen>$manfen->ks_subject[0]->manfen ) + // { + // continue; + // } + + + // 查询是否存在这个成绩 - $cj = Chengji::where('kaohao_id',$value[1]) + $cj = Chengji::withTrashed() + ->where('kaohao_id',$value[1]) ->where('subject_id',$val) ->find(); // 如果存在则删除 @@ -612,5 +619,72 @@ class Index extends Base } + // 学生成绩录入信息 + public function readAdd($kaohao) + { + // 设置要给模板赋值的信息 + $list['webtitle'] = '查看成绩录入信息'; + $list['kaohao'] = $kaohao; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染模板 + return $this->fetch(); + } + + // ajax获取学生成绩录入信息 + public function ajaxaddinfo() + { + // 获取参数 + $src = $this->request + ->only([ + 'page'=>'1', + 'limit'=>'10', + 'field'=>'banji', + 'type'=>'desc', + 'kaohao'=>'' + ],'POST'); + + $chengji = new Chengji; + + $data = $chengji + ->where('kaohao_id',$src['kaohao']) + ->field('id,kaohao_id,subject_id,user_id,defen,update_time') + ->order('subject_id') + ->with([ + 'subjectName'=>function($query){ + $query->field('id,title'); + }, + 'userName'=>function($query){ + $query->field('id,school,xingming') + ->with([ + 'adSchool'=>function($query){ + $query->field('id,jiancheng'); + } + ]); + } + ]) + ->select(); + + $cnt = count($data); + + // 获取当前页数据 + $limit_start = $src['page'] * $src['limit'] - $src['limit']; + $limit_length = $src['limit']; + $data = $data->slice($limit_start,$limit_length); + + // 重组返回内容 + $data = [ + 'code'=> 0 , // ajax请求次数,作为标识符 + 'msg'=>"", // 获取到的结果数(每页显示数量) + 'count'=>$cnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + + return json($data); + } + } diff --git a/application/chengji/controller/Tongji.php b/application/chengji/controller/Tongji.php index c8c12afd..138bbf17 100644 --- a/application/chengji/controller/Tongji.php +++ b/application/chengji/controller/Tongji.php @@ -120,6 +120,10 @@ class Tongji extends Base ]; } + $cnt = count($data); + + $data = array_slice($data,($src['page']-1)*$src['limit'],$src['limit']); + // 获取年级成绩 $temp = $tj->tongji($allcj,$src['kaoshi']); $data[] = [ @@ -128,8 +132,6 @@ class Tongji extends Base 'chengji'=>$temp ]; - $cnt = count($data); - // 重组返回内容 $data = [ 'code'=> 0 , // ajax请求次数,作为标识符 diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index 59d39d42..0ea69ee9 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -94,6 +94,12 @@ class Chengji extends Base return $this->belongsTo('\app\teach\model\Subject','subject_id','id'); } + // 学科关联 + public function userName() + { + return $this->belongsTo('\app\admin\model\Admin','user_id','id'); + } + diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html index 0888ea3e..f5c204da 100644 --- a/application/chengji/view/index/index.html +++ b/application/chengji/view/index/index.html @@ -77,7 +77,7 @@ @@ -137,10 +137,11 @@ var data = obj.data; //获得当前行数据 var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值) var tr = obj.tr; //获得当前行 tr 的DOM对象 + console.log(data); switch(layEvent){ case 'detail':// 查看 - layer.msg('查看' + data.id); - break; + cjgl.add(obj.data.student+' 成绩录入信息','/readcjadd/'+obj.data.id,'','',true); + break; case 'del':// 删除 cjgl.del(obj,"/kaohao"); break; @@ -160,8 +161,6 @@ ,colname = obj.field ,rowdata = obj.data; - console.log(obj.data); - // 修改服务器数据 $.ajax({ url:"/chengji/"+rowdata.id, diff --git a/application/chengji/view/index/read_add.html b/application/chengji/view/index/read_add.html new file mode 100644 index 00000000..6887c658 --- /dev/null +++ b/application/chengji/view/index/read_add.html @@ -0,0 +1,130 @@ + +{extend name="common@list" /} +{block name="jsset"} + +{/block} +{block name="nav"} + + 成绩管理 + 成绩列表 + 录入信息 + +{/block} +{block name="search"} +{/block} +{block name="table"} +
+{/block} +{block name="myjs"} + + + + + + +{/block} \ No newline at end of file diff --git a/application/common/view/list.html b/application/common/view/list.html index ccebfdbb..5cf8cc4e 100644 --- a/application/common/view/list.html +++ b/application/common/view/list.html @@ -67,7 +67,9 @@ autoSort:false, id:'mytable', defaultToolbar:'', - where:{} + where:{}, + limits:[10,25,50,75,100], + limit:10 }; {block name="myjs"}{/block} diff --git a/route/chengji.php b/route/chengji.php index 0979d920..6a4d7c52 100644 --- a/route/chengji.php +++ b/route/chengji.php @@ -22,7 +22,9 @@ Route::get('chengji/biaolu','chengji/Index/biaolu'); Route::post('chengji/biaolu','chengji/Index/saveAll'); // 获取学生成绩列表 Route::get('chengji/:kaoshi/stuChengjilist','chengji/Index/index'); -Route::delete('chengji/:kaoshi/cj','chengji/Index/deletecj'); #只清空成绩 +Route::delete('chengji/:kaoshi/cj','chengji/Index/deletecj'); # 删除考号 +Route::get('readcjadd/:kaohao','chengji/Index/readAdd'); # 删除考号 + // 成绩统计表 Route::get('cjtongji/:kaoshi/banji','chengji/Tongji/tjBanji'); # 班级成绩统计列表 Route::get('cjtongji/:kaoshi/nianji','chengji/Tongji/tjNianji'); # 年级成绩统计列表