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 @@