From 349b8b0a1c5d0e5fe837dc5b155a1daa0b86a124 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sat, 8 Jun 2019 15:34:37 +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 | 47 +++++++++++++++-------- application/chengji/view/index/index.html | 34 +++++++++------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 22c66974..2a55e7ae 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -68,31 +68,31 @@ class Index extends Base return $this->fetch(); } - // 扫码录入成绩 - public function update($id) - { - // 获取表单数据 - $list = request()->param(); + // // 保存扫码录入成绩 + // public function save($id) + // { + // // 获取表单数据 + // $list = request()->param(); - // 更新成绩 - $data = Chengji::update($list); + // // 更新成绩 + // $data = Chengji::update($list); - // 判断返回内容 - $data ? $data=['msg'=>'录入成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + // // 判断返回内容 + // $data ? $data=['msg'=>'录入成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; - // 返回更新结果 - return $data; - } + // // 返回更新结果 + // return $data; + // } // 学生成绩表中修改成绩 - public function ajaxupdate() + public function update($id) #id为考号ID { // 获取表单数据 $list = $this->request->only( - ['kaohao_id', - 'colname', + ['colname', 'newdefen'] ,'post'); + $list['kaohao_id'] = $id; // 获取学科信息 $subject = new \app\teach\model\Subject; $subject_id = $subject->where('lieming',$list['colname'])->value('id'); @@ -129,9 +129,22 @@ class Index extends Base // 更新成绩 $cj = new Chengji; - $data = $cj->where('kaohao_id',$list['kaohao_id']) + $cjinfo = $cj->where('kaohao_id',$list['kaohao_id']) ->where('subject_id',$subject_id) - ->update(['defen'=>$list['newdefen']]); + ->find(); + // 如果存在成绩则更新,不存在则添加 + if($cjinfo){ + $cjinfo->defen = $list['newdefen']; + $cjinfo->user_id = session('userid'); + $data = $cjinfo->save(); + }else{ + $cj->defen = $list['newdefen']; + $cj->kaohao_id = $list['kaohao_id']; + $cj->subject_id = $subject_id; + $cj->user_id = session('userid'); + $data = $cj->save(); + } + // update(['defen'=>$list['newdefen']]); // 判断返回内容 $data ? $data=['msg'=>'录入成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; diff --git a/application/chengji/view/index/index.html b/application/chengji/view/index/index.html index 25501ddc..0888ea3e 100644 --- a/application/chengji/view/index/index.html +++ b/application/chengji/view/index/index.html @@ -160,20 +160,28 @@ ,colname = obj.field ,rowdata = obj.data; + console.log(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}); - } - } - ); + $.ajax({ + url:"/chengji/"+rowdata.id, + type:'PUT', + data:{ + "colname":colname, + "newdefen":newdefen + }, + success:function(result){ + if(result.val == 0) + { + layer.msg(result.msg,{icon:5}); + }else{ + // 这个地方重新赋值平均分和总分 + } + }, + error:function(result){ + layer.msg('数据扔半道啦。',function(){}); + }, + }); })