diff --git a/application/keti/controller/Index.php b/application/keti/controller/Index.php index c78c3569..e5408335 100644 --- a/application/keti/controller/Index.php +++ b/application/keti/controller/Index.php @@ -159,7 +159,7 @@ class Index extends Base // 模板赋值 $this->assign('list',$list); - return $this->fetch('keti_info/read'); + return $this->fetch('read'); } /** diff --git a/application/keti/controller/KetiInfo.php b/application/keti/controller/KetiInfo.php index 8d0a1b57..e8a0f66c 100644 --- a/application/keti/controller/KetiInfo.php +++ b/application/keti/controller/KetiInfo.php @@ -62,6 +62,7 @@ class KetiInfo extends Base 'fzdanweiid'=>$getdt['fzdanweiid'], 'subject'=>$getdt['subject'], 'category'=>$getdt['category'], + 'ketice'=>$getdt['ketice'], 'search'=>$getdt['search']['value'], 'order'=>$order, 'order_field'=>$order_field @@ -193,7 +194,7 @@ class KetiInfo extends Base // 获取表单上传文件 例如上传了001.jpg $file = request()->file('file'); // 移动到框架应用根目录/uploads/ 目录下 - $info = $file->validate(['size'=>2*1024*1024,'ext'=>'jpg,png,gif,jpeg'])->move('uploads\ketilixiang'); + $info = $file->validate(['size'=>2*1024*1024,'ext'=>'jpg,png,gif,jpeg'])->move('uploads\keti\lixiang'); @@ -207,7 +208,7 @@ class KetiInfo extends Base $data = ktinfo::create(['lxpic'=>$list['url'],'ketice'=>$ketice]); $id = $data->id; - $id ? $data = array('msg'=>'上传成功','val'=>true,'url'=>$list['url'],'ryid'=>$id) : $data = array('msg'=>'保存文件信息失败','val'=>false,'url'=>null); + $id ? $data = array('msg'=>'上传成功','val'=>true,'url'=>$list['url'],'ktid'=>$id) : $data = array('msg'=>'保存文件信息失败','val'=>false,'url'=>null); }else{ // 上传失败获取错误信息 $data = array('msg'=>$file->getError(),'val'=>false,'url'=>null); @@ -239,7 +240,7 @@ class KetiInfo extends Base { // 获取课题信息 $list = ktinfo::where('id',$id) - ->field('title','bianhao','fzdanweiid','subject','category','jhjtshijian') + ->field('id,title,fzdanweiid,bianhao,subject,category,jhjtshijian,lxpic') ->with([ 'ktZcr'=>function($query){ $query->field('ketiinfoid,teacherid') @@ -249,10 +250,12 @@ class KetiInfo extends Base }, ]) ->find(); + - + // 模板赋值 $this->assign('list',$list); + // 渲染模板 return $this->fetch(); } @@ -263,9 +266,53 @@ class KetiInfo extends Base * @param int $id * @return \think\Response */ - public function update(Request $request, $id) + public function update($id) { - // + // 获取表单数据 + $list = request()->only(['ketice','title','bianhao','fzdanweiid','subject','category','jhjtshijian','hjteachers','lxpic'],'PUT'); + $list['id'] = $id; + + + // 实例化验证类 + $validate = new \app\keti\validate\KetiInfo; + // 验证表单数据 + $result = $validate->scene('edit')->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]); + } + + + // 更新数据 + $data = ktinfo::update($list); + + // 删除原来的获奖人与参与人信息 + $data->ktZcr() + ->where('ketiinfoid',$list['id']) + ->where('category',1) + ->delete(true); + // 声明教师数组 + $teacherlist = []; + // 循环组成获奖教师信息 + foreach ($list['hjteachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'rongyuid' => $list['id'], + 'category' => 1, + ]; + } + + + // 添加新的获奖人与参与人信息 + $data->ktZcr()->saveAll($canyulist); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** diff --git a/application/keti/model/KetiInfo.php b/application/keti/model/KetiInfo.php index 549f697f..ec0a8d48 100644 --- a/application/keti/model/KetiInfo.php +++ b/application/keti/model/KetiInfo.php @@ -16,6 +16,7 @@ class KetiInfo extends Base $fzdanweiid = $search['fzdanweiid']; $subject = $search['subject']; $category = $search['category']; + $ketice = $search['ketice']; $order_field = $search['order_field']; $order = $search['order']; $search = $search['search']; @@ -40,19 +41,36 @@ class KetiInfo extends Base ->when(!empty($category),function($query) use($category){ $query->where('category','in',$category); }) + ->when(!empty($ketice),function($query) use($ketice){ + $query->where('ketice','in',$ketice); + }) ->when(!empty($search),function($query) use($search){ $query->where('title','like',$search); }) - // ->with( - // [ - // 'ktCategory'=>function($query){ - // $query->field('id,title'); - // }, - // 'ktLxdanwei'=>function($query){ - // $query->field('id,title'); - // }, - // ] - // ) + ->with( + [ + 'fzSchool'=>function($query){ + $query->field('id,jiancheng'); + }, + 'KtCe'=>function($query){ + $query->field('id,lxdanweiid,category,lxshijian') + ->with([ + 'ktCategory' => function($q){ + $q->field('id,title'); + }, + 'ktLxdanwei' => function($q){ + $q->field('id,jiancheng'); + } + ]); + }, + 'ktCategory'=>function($query){ + $query->field('id,title'); + }, + 'ktSubject'=>function($query){ + $query->field('id,title'); + }, + ] + ) ->append(['zcrName']) ->select(); @@ -67,6 +85,49 @@ class KetiInfo extends Base return $this->hasMany('\app\keti\model\KetiCanyu','ketiinfoid','id')->where('category',1); } + // 立项单位关联 + public function fzSchool() + { + return $this->belongsTo('\app\system\model\School','fzdanweiid','id'); + } + + + // 研究类型关联 + public function ktCategory() + { + return $this->belongsTo('\app\system\model\Category','category','id'); + } + + + // 所属学科关联 + public function ktSubject() + { + return $this->belongsTo('\app\system\model\Category','subject','id'); + } + + + // 课题册关联 + public function ktCe() + { + return $this->belongsTo('\app\keti\model\Keti','ketice','id'); + } + + + + // 结题等级获取器 + public function getJddengjiAttr($value) + { + // 结题数组 + $jtdj = array('0'=>'研究中','1'=>'合格','2'=>'优秀','3'=>'流失'); + // 获取结题鉴定等级 + $str = $jtdj[$value]; + // 返回结题等级 + return $str; + } + + + // 立项 + // 课题主持人名单整理 public function getZcrNameAttr($value) @@ -90,5 +151,43 @@ class KetiInfo extends Base } + // 计划结题时间修改器 + public function setJhjtshijianAttr($value) + { + return strtotime($value); + } + + // 计划结题时间获取器 + public function getJhjtshijianAttr($value) + { + if ($value>0) + { + $value = date('Y-m-d',$value); + }else{ + $value = ""; + } + return $value; + } + + // 结题时间修改器 + public function setJtshijianAttr($value) + { + return strtotime($value); + } + + // 结题时间获取器 + public function getJtshijianAttr($value) + { + if ($value>0) + { + $value = date('Y-m-d',$value); + }else{ + $value = ""; + } + return $value; + } + + + } diff --git a/application/keti/view/index/index.html b/application/keti/view/index/index.html index bdaed7e2..d4470b2b 100644 --- a/application/keti/view/index/index.html +++ b/application/keti/view/index/index.html @@ -158,7 +158,7 @@ // 上图图片按钮 picbut = ''; // 添加荣誉 - addbut = ''; + addbut = ''; // 编辑按钮 editbut = ''; delbut = ''; diff --git a/application/keti/view/index/read.html b/application/keti/view/index/read.html new file mode 100644 index 00000000..e3c1f54c --- /dev/null +++ b/application/keti/view/index/read.html @@ -0,0 +1,154 @@ +{extend name="common@list" /} +{block name="topnav"} + +{/block} +{block name="bouttons"} +
| + | 主持人 | +课题名称 | +课题编号 | +负责单位 | +研究类型 | +所属学科 | +研究状态 | +计划结题时间 | +结题时间 | +状态 | +操作 | +
|---|