From 04487f9c98bbc3ea462842aa375650bed6861e4d Mon Sep 17 00:00:00 2001 From: cxdbz Date: Tue, 30 Apr 2019 22:19:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=AB=E7=A0=81=E5=BD=95?= =?UTF-8?q?=E6=88=90=E7=BB=A9=EF=BC=8C=E6=88=90=E7=BB=A9=E8=A1=A8=E6=9C=AA?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chengji/controller/Index.php | 41 ++++-- application/chengji/model/Chengji.php | 118 +----------------- application/chengji/view/index/malu.html | 22 ++-- application/kaoshi/controller/Kaohao.php | 4 +- application/login/view/index/index.html | 3 +- .../migrations/20190430034853_chengji.php | 5 +- 6 files changed, 51 insertions(+), 142 deletions(-) diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 24ea1ac7..1ac8ac27 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -7,6 +7,8 @@ use app\common\controller\Base; use app\chengji\model\Chengji; // 引用考号数据模型 use app\kaoshi\model\Kaohao; +// 引用学科数据模型 +use \app\teach\model\Subject; class Index extends Base @@ -33,10 +35,21 @@ class Index extends Base public function malusave() { // 获取表单数据 - $list = $this->request->only(['id','zd','defen'],'post'); - + $list = $this->request->only(['kaohao_id','subject_id','defen'],'post'); + // 更新成绩 - $data = Chengji::update(['id'=>$list['id'], $list['zd']=>$list['defen']]); + $data = Kaohao::where('id',$list['kaohao_id'])->find(); + $cj = $data->ksChengji()->isEmpty(); + if($cj == false) + { + $data->ksChengji()->delete(); + } + + $data = $data->ksChengji()->save([ + 'subject_id'=>$list['subject_id'], + 'defen'=>$list['defen'], + 'user_id'=>session('userid') + ]); $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -88,20 +101,24 @@ class Index extends Base ->field('id,banji,school,student') ->with([ 'ksChengji'=>function($q) use($sbj){ - $q->where('stubject_id',$sbj) - ->field('id,kaohao_id,stubject_id,student_id,user_id'); + $q->where('subject_id',$sbj) + ->field('kaohao_id,subject_id,defen'); + } + ,'cjBanji'=>function($q){ + $q->field('id,paixu,ruxuenian') + ->append(['numTitle','banjiTitle']); + } + ,'cjSchool'=>function($q){ + $q->field('id,jiancheng'); + } + ,'cjStudent'=>function($q){ + $q->field('id,xingming'); } ]) ->find(); - + $cjlist->sbj = Subject::where('id',$sbj)->field('id,title')->find(); // 获取列名 - $sbj = new \app\teach\model\Subject; - $cjlist->lieming = $sbj::where('lieming',$list[1])->value('title'); - - - halt($cjlist); - return json($cjlist); } diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index b6e70abf..3b3c41bb 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -43,121 +43,13 @@ class Chengji extends Base // }); // } + // 成绩和学科关联 + public function cjSubject() + { + return $this->belongsTo('\app\teach\model\Subject'); + } - - - - - - - - // 班级名称(数字)获取器 - // public function getBanjiNumnameAttr() - // { - // $bj = new \app\teach\model\Banji; - // $bj = $bj->find($this->getdata('banji')); - - // // 返回班级名称 - // return $bj->numTitle; - // } - - - - - // 查询根据考试ID查询考试成绩 - // public function searchAjax($search) - // { - // // 获取参数 - // $kaoshiid = $search['kaoshiid']; - // $schoolid = $search['school']; - // $nianji = $search['nianji']; - // $banji = $search['banji']; - // $order = $search['order']; - // $order_field = $search['order_field']; - // $search = $search['search']; - - - // $data = $this->where('kaoshi',$kaoshiid) - // ->when(count($schoolid)>0,function($query) use($schoolid){ - // $query->where('school','in',$schoolid); - // }) - // ->when(count($nianji)>0,function($query) use($nianji){ - // $query->where('nianji','in',$nianji); - // }) - // ->when(count($banji)>0,function($query) use($banji){ - // $query->where('banji','in',$banji); - // }) - // // ->when(strlen($search)>0 && is_numeric($search), function ($query) use($search){ - // // // 满足条件后执行 - // // $query->where('yuwen|shuxue|waiyu',$search); - // // }) - // ->when(strlen($search)>0 && !is_numeric($search),function($query) use($search){ - // $query->where('student','in',function ($q) use($search){ - // $q->name('student') - // ->where('xingming','like','%'.$search.'%') - // ->field('id'); - // }); - // }) - // ->order([$order_field=>$order]) - // ->select(); - - - // // $data = $data->append(['cj_school.jiancheng','cj_banji.title','cj_student.xingming']); - - // return $data; - // } - - - - // // 根据成绩ID查询单条成绩 - // public function srcOne($id) - // { - // $data = $this->where('id',$id) - // ->with([ - // 'cjManfen' - // ]) - // ->find(); - - // return $data; - // } - - - - - // // 根据考试ID查询所有考试成绩 - // public function searchAll($kaoshiid) - // { - // return $this::scope('kaoshi',$kaoshiid) - // // ->cache('key',180) - // ->select(); - // } - - - // // 查询年级成绩 - // public function searchNianji($kaoshiid,$schoolid='',$nianji) - // { - // return $this->where('kaoshi',$kaoshiid) - // ->where('ruxuenian',$nianji) - // ->when(!empty($schoolid),function($query) use($schoolid){ - // $query->where('school',$schoolid); - // }) - // ->where('status',1) - // ->field('id,kaoshi,banji,school,yuwen,shuxue,waiyu') - // // ->cache('key',180) - // ->select(); - // } - - - - - // // 考试项目查询范围 - // public function scopeKaoshi($query,$kaoshiid) - // { - // $query->where('kaoshi',$kaoshiid); - // } - - } diff --git a/application/chengji/view/index/malu.html b/application/chengji/view/index/malu.html index 875ec251..a9feb625 100644 --- a/application/chengji/view/index/malu.html +++ b/application/chengji/view/index/malu.html @@ -24,8 +24,8 @@ - - + + @@ -54,12 +54,12 @@ $('#xsschool').text(data.cj_school.jiancheng); $('#xsbanji').text(data.cj_banji.banjiTitle); $('#xsxingming').text(data.cj_student.xingming); - $('#xsxueke').text(data.lieming); + $('#xsxueke').text(data.sbj.title); - $('#id').val(data.id); - $('#zd').val(data.zd); - if(data.defen*1>0){ - $('#defen').val(data.defen*1); + $('#kaohao_id').val(data.id); + $('#subject_id').val(data.sbj.id); + if(data.ks_chengji[0].defen){ + $('#defen').val(data.ks_chengji[0].defen); } $('#saoma').val(''); // $('#xianshi').append(school + banji + student + subject); @@ -80,15 +80,15 @@ type: 'PUT', url: "/chengji/malu", data:{ - id:$('#id').val() - ,zd:$('#zd').val() + subject_id:$('#subject_id').val() + ,kaohao_id:$('#kaohao_id').val() ,defen:$('#defen').val() }, dataType: 'json', success: function(data){ if(data.val == 1){ - $('#id').val(''); - $('#zd').val(''); + $('#kaohao_id').val(''); + $('#subject_id').val(''); $('#defen').val(''); $('#xsschool').text(''); $('#xsbanji').text(''); diff --git a/application/kaoshi/controller/Kaohao.php b/application/kaoshi/controller/Kaohao.php index 3c71054c..5e2dcd09 100644 --- a/application/kaoshi/controller/Kaohao.php +++ b/application/kaoshi/controller/Kaohao.php @@ -263,7 +263,7 @@ class Kaohao extends Base $list['data']['subject'][$key]['title']=$value->subject_name->title; } }else{ - $list['data']['nianji']= array(); + $list['data']['subject']= array(); } @@ -409,7 +409,7 @@ class Kaohao extends Base $list['data']['subject'][$key]['title']=$value->subject_name->title; } }else{ - $list['data']['nianji']= array(); + $list['data']['subject']= array(); } // 设置页面标题 diff --git a/application/login/view/index/index.html b/application/login/view/index/index.html index 6c65316c..f6056ab5 100644 --- a/application/login/view/index/index.html +++ b/application/login/view/index/index.html @@ -24,7 +24,7 @@

- +
captcha
@@ -48,6 +48,7 @@ layer.msg('数据传输错误'); $('#captchaimg').onclick(); $('#captcha').val(''); + $('#password').val(''); } if(data.status == 1) { diff --git a/database/migrations/20190430034853_chengji.php b/database/migrations/20190430034853_chengji.php index 4655b5d9..81c24a0e 100644 --- a/database/migrations/20190430034853_chengji.php +++ b/database/migrations/20190430034853_chengji.php @@ -34,14 +34,13 @@ class Chengji extends Migrator // 添加当前表字段 $table ->addColumn('kaohao_id','integer',['limit'=>11,'null'=>false,'comment'=>'考试']) - ->addColumn('student_id','integer',['limit'=>11,'null'=>false,'comment'=>'学校']) - ->addColumn('stubject_id','integer',['limit'=>4,'null'=>false,'comment'=>'入学年']) + ->addColumn('subject_id','integer',['limit'=>4,'null'=>false,'comment'=>'入学年']) ->addColumn('user_id','string',['limit'=>4,'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'=>'更新时间']) ->addColumn('status','boolean',['limit'=>1,'default'=>'1','null'=>false,'comment'=>'0=禁用,1=正常']) - ->addIndex(array('kaohao_id','stubject_id'), array('unique' => true)) + ->addIndex(array('kaohao_id','subject_id'), array('unique' => true)) ->create(); } }