diff --git a/application/keti/controller/KetiInfo.php b/application/keti/controller/KetiInfo.php index ceff9100..8d0a1b57 100644 --- a/application/keti/controller/KetiInfo.php +++ b/application/keti/controller/KetiInfo.php @@ -58,8 +58,10 @@ class KetiInfo extends Base //得到搜索的关键词 $search = [ 'lxdanweiid'=>$getdt['lxdanweiid'], + 'lxcategory'=>$getdt['lxcategory'], + 'fzdanweiid'=>$getdt['fzdanweiid'], + 'subject'=>$getdt['subject'], 'category'=>$getdt['category'], - 'fzschool'=>$getdt['fzschool'], 'search'=>$getdt['search']['value'], 'order'=>$order, 'order_field'=>$order_field @@ -117,15 +119,102 @@ class KetiInfo extends Base * @param \think\Request $request * @return \think\Response */ - public function save(Request $request) + public function save() { - // + // 获取表单数据 + $list = request()->only(['ketice','title','bianhao','fzdanweiid','subject','category','jhjtshijian','hjteachers'],'POST'); + + + + // 实例化验证类 + $validate = new \app\keti\validate\KetiInfo; + // 验证表单数据 + $result = $validate->scene('add')->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]); + } + + + // 更新数据 + $data = ktinfo::create($list); + + // 声明教师数组 + $teacherlist = []; + // 循环组成获奖教师信息 + foreach ($list['hjteachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'category' => 1, + ]; + } + + + // 添加新的获奖人与参与人信息 + $data->ktZcr()->saveAll($canyulist); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } // 批量上传立项通知书 - public function createall($id){ - dump($id); + public function createall($id) + { + // 设置页面标题 + $list['title'] = '批量添加课题信息'; + $list['ketice'] = $id; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染 + return $this->fetch(); + } + + + /** + * 上传荣誉图片并保存 + * + * @param \think\Request $request + * @return \think\Response + */ + public function upload() + { + // 获取文件信息 + $ketice=input('post.ketice'); + + + // 获取表单上传文件 例如上传了001.jpg + $file = request()->file('file'); + // 移动到框架应用根目录/uploads/ 目录下 + $info = $file->validate(['size'=>2*1024*1024,'ext'=>'jpg,png,gif,jpeg'])->move('uploads\ketilixiang'); + + + + if($info){ + // 成功上传后 获取上传信息 + $list['url'] = $info->getSaveName(); + $list['url'] = str_replace('\\','/',$list['url']); + + + // 如果图片上传成功,则添加荣誉记录 + $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); + }else{ + // 上传失败获取错误信息 + $data = array('msg'=>$file->getError(),'val'=>false,'url'=>null); + } + + // 返回信息 + return json($data); } @@ -148,7 +237,23 @@ class KetiInfo extends Base */ public function edit($id) { - // + // 获取课题信息 + $list = ktinfo::where('id',$id) + ->field('title','bianhao','fzdanweiid','subject','category','jhjtshijian') + ->with([ + 'ktZcr'=>function($query){ + $query->field('ketiinfoid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + ]) + ->find(); + + + $this->assign('list',$list); + + return $this->fetch(); } /** @@ -176,9 +281,4 @@ class KetiInfo extends Base - // 课题册 - public function KetiCe($id) - { - dump($id); - } } diff --git a/application/keti/model/KetiCanyu.php b/application/keti/model/KetiCanyu.php index 816fdb5b..b17285c7 100644 --- a/application/keti/model/KetiCanyu.php +++ b/application/keti/model/KetiCanyu.php @@ -6,5 +6,15 @@ use think\Model; class KetiCanyu extends Model { - // + // 课题册关联 + public function keti() + { + return $this->belongsTo('\app\keti\model\Keti','ketiinfoid','id'); + } + + // 教师关联 + public function teacher() + { + return $this->belongsTo('\app\renshi\model\Teacher','teacherid','id'); + } } diff --git a/application/keti/model/KetiInfo.php b/application/keti/model/KetiInfo.php index df1cf53e..549f697f 100644 --- a/application/keti/model/KetiInfo.php +++ b/application/keti/model/KetiInfo.php @@ -12,22 +12,33 @@ class KetiInfo extends Base { // 获取参数 $lxdanweiid = $search['lxdanweiid']; - $category = $search['category']; - $fzschool = $search['fzschool']; + $lxcategory = $search['lxcategory']; + $fzdanweiid = $search['fzdanweiid']; + $subject = $search['subject']; + $category = $search['category']; $order_field = $search['order_field']; $order = $search['order']; - $category = $search['category']; $search = $search['search']; $data = $this->order([$order_field =>$order]) ->when(!empty($lxdanweiid),function($query) use($lxdanweiid){ - $query->where('lxdanweiid','in',$lxdanweiid); + $query->where('ketice','in',function ($q) use($lxdanweiid){ + $q->name('keti')->where('lxdanweiid','in',$lxdanweiid)->field('id'); + }); }) - ->when(!empty($category),function($query) use($category){ - $query->where('category','in',$category); + ->when(!empty($lxcategory),function($query) use($lxcategory){ + $query->where('ketice','in',function($q) use($lxcategory){ + $q->name('keti')->where('category','in',$lxcategory)->field('id'); + }); }) - ->when(!empty($fzschool),function($query) use($fzschool){ - $query->where('title','in',$fzschool); + ->when(!empty($fzdanweiid),function($query) use($fzdanweiid){ + $query->where('fzdanweiid','in',$fzdanweiid); + }) + ->when(!empty($subject),function($query) use($subject){ + $query->where('subject','in',$subject); + }) + ->when(!empty($category),function($query) use($category){ + $query->where('category','in',$category); }) ->when(!empty($search),function($query) use($search){ $query->where('title','like',$search); @@ -42,10 +53,42 @@ class KetiInfo extends Base // }, // ] // ) - // ->append(['ktcnt','jtcnt']) + ->append(['zcrName']) ->select(); return $data; } + + + // 课题主持人关联 + public function ktZcr() + { + return $this->hasMany('\app\keti\model\KetiCanyu','ketiinfoid','id')->where('category',1); + } + + + // 课题主持人名单整理 + public function getZcrNameAttr($value) + { + $teacherList = $this->getAttr('ktZcr'); + $teachNames = ""; + $i = 0; + foreach ($teacherList as $key => $value) { + # code... + if($i == 0) + { + $teachNames = $value['teacher']['xingming']; + }else{ + $teachNames = $teachNames . '、' .$value['teacher']['xingming']; + } + $i++; + } + + return $teachNames; + + } + + + } diff --git a/application/keti/validate/KetiInfo.php b/application/keti/validate/KetiInfo.php index 9d72bc1c..e08c7f52 100644 --- a/application/keti/validate/KetiInfo.php +++ b/application/keti/validate/KetiInfo.php @@ -12,7 +12,18 @@ class KetiInfo extends Validate * * @var array */ - protected $rule = []; + protected $rule = [ + 'id|请先上传立项通知书图片' => 'require', + 'ketice|课题册ID丢失' => 'require', + 'title|课题名称' => 'require|length:1,60', + 'bianhao|课题编号' => 'require|length:1,11', + 'hjteachers|课题主持人' => 'require|array', + 'fzdanweiid|课题负责单位' => 'require|number', + 'subject|课题所属学科' => 'require|number', + 'category|课题研究类型' => 'require|number', + 'jhjtshijian|计划结题时间' => 'require|date', + 'cyteachers|参与人' => 'array', + ]; /** * 定义错误信息 @@ -21,4 +32,10 @@ class KetiInfo extends Validate * @var array */ protected $message = []; + + // 验证场景 + protected $scene = [ + 'add' => ['ketice','title','bianhao','fzdanweiid','subject','category','jhjtshijian','hjteachers'], + 'edit' => ['id','title','hjteachers','hjschool','subject','hjshijian','jiangxiang','cyteachers'], + ]; } diff --git a/application/keti/view/index/index.html b/application/keti/view/index/index.html index 0f1b06ce..bdaed7e2 100644 --- a/application/keti/view/index/index.html +++ b/application/keti/view/index/index.html @@ -156,9 +156,9 @@ startbut = ''; // 上图图片按钮 - picbut = ''; + picbut = ''; // 添加荣誉 - addbut = ''; + addbut = ''; // 编辑按钮 editbut = ''; delbut = ''; diff --git a/application/keti/view/keti_info/create.html b/application/keti/view/keti_info/create.html index 7e0890b1..35149912 100644 --- a/application/keti/view/keti_info/create.html +++ b/application/keti/view/keti_info/create.html @@ -1,5 +1,6 @@ {extend name="common@create" /} {block name="mycss"} +{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.css" /} {/block} {block name="formaa"}