diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 912b516a..22c66974 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -68,7 +68,7 @@ class Index extends Base return $this->fetch(); } - + // 扫码录入成绩 public function update($id) { // 获取表单数据 @@ -84,6 +84,62 @@ class Index extends Base return $data; } + // 学生成绩表中修改成绩 + public function ajaxupdate() + { + // 获取表单数据 + $list = $this->request->only( + ['kaohao_id', + 'colname', + 'newdefen'] + ,'post'); + // 获取学科信息 + $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分的时候也跳过 + { + $data=['msg'=>'得分范围在要大于等于0分,小于等于'.$kaohaoinfo->cj_kaoshi->ks_subject[0]->manfen.'分','val'=>0]; + return $data; + } + + // 更新成绩 + $cj = new Chengji; + $data = $cj->where('kaohao_id',$list['kaohao_id']) + ->where('subject_id',$subject_id) + ->update(['defen'=>$list['newdefen']]); + + // 判断返回内容 + $data ? $data=['msg'=>'录入成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回更新结果 + return $data; + } + // 根据考号获取学生信息 diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html index 915dc97a..25501ddc 100644 --- a/application/chengji/view/index/index.html +++ b/application/chengji/view/index/index.html @@ -96,7 +96,7 @@ xk = eval(decodeURIComponent(xk)); for(x in xk) { - options.cols[0].push({field: xk[x].subject_name.lieming, title: xk[x].subject_name.title , minWidth:100,sort: true}); + options.cols[0].push({field: xk[x].subject_name.lieming, title: xk[x].subject_name.title , minWidth:100,sort: true,edit:'text'}); } options.cols[0].push({field: 'avg', title: '平均分', minWidth:100,sort: true}); options.cols[0].push({field: 'sum', title: '总分', minWidth:100,sort: true}); @@ -152,6 +152,33 @@ break; }; }); + + // 单元格编辑 + table.on('edit(mytable)',function(obj){ + // 声明变量 + var newdefen = obj.value + ,colname = obj.field + ,rowdata = obj.data; + + // 修改服务器数据 + $.post( + "/chengji/Index/ajaxupdate", + { + "kaohao_id":rowdata.id, + "colname":colname, + "newdefen":newdefen + }, + function(data,status){ + if(data.val == 0){ + layer.msg(data.msg,{icon:5}); + } + } + ); + + }) + + + }); {/block} \ No newline at end of file diff --git a/database/migrations/20181030024954_subject.php b/database/migrations/20181030024954_subject.php index 6dca4b11..9948c337 100644 --- a/database/migrations/20181030024954_subject.php +++ b/database/migrations/20181030024954_subject.php @@ -44,6 +44,9 @@ class Subject extends Migrator ->addColumn('update_time','integer',['limit'=>11,'null'=>true,'comment'=>'更新时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->addColumn('beizhu','string',['limit'=>80,'null'=>true,'comment'=>'备注']) + ->addIndex(array('lieming'), array('unique' => true)) + ->addIndex(array('title'), array('unique' => true)) + ->addIndex(array('jiancheng'), array('unique' => true)) ->create(); } }