From 4d66a075afe30d5d40573df074192534d2d3877b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE=E6=A0=91?= Date: Wed, 27 Feb 2019 13:45:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8D=A3=E8=AA=89=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B1=BB=E5=88=AB=E5=90=8D=E7=A7=B0=E9=99=90?= =?UTF-8?q?=E5=88=B6=E3=80=81=E7=BC=96=E5=86=99=E8=AF=BE=E9=A2=98=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=8E=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/keti/controller/KetiInfo.php | 122 +++++++++++-- application/keti/model/KetiCanyu.php | 12 +- application/keti/model/KetiInfo.php | 61 ++++++- application/keti/validate/KetiInfo.php | 19 +- application/keti/view/index/index.html | 4 +- application/keti/view/keti_info/create.html | 158 +++++++++++++++-- application/keti/view/keti_info/create1.html | 164 ++++++++++++++++++ .../keti/view/keti_info/createall.html | 5 +- application/keti/view/keti_info/index.html | 83 +++++++-- .../rongyu/controller/JsRongyuInfo.php | 5 +- .../rongyu/view/js_rongyu_info/create.html | 1 - application/system/validate/Category.php | 2 +- application/system/view/category/create.html | 2 +- application/system/view/category/edit.html | 2 +- .../migrations/20181025041505_category.php | 2 +- .../migrations/20190222041040_keti_canyu.php | 2 +- route/keti.php | 4 +- 17 files changed, 580 insertions(+), 68 deletions(-) create mode 100644 application/keti/view/keti_info/create1.html 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"}
@@ -14,7 +15,7 @@
-
+ @@ -32,11 +33,10 @@
-
- +
@@ -44,7 +44,7 @@
{php} $school = schlist('校级','区级');{/php} - {volist name="school" id="vo"} @@ -58,7 +58,7 @@
{php}$category = getCategory(116);{/php} - {volist name="category" id="vo"} @@ -84,7 +84,7 @@
- +
@@ -95,19 +95,15 @@ {/block} {block name="yanzheng"} +{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"} diff --git a/application/keti/view/keti_info/create1.html b/application/keti/view/keti_info/create1.html new file mode 100644 index 00000000..7e0890b1 --- /dev/null +++ b/application/keti/view/keti_info/create1.html @@ -0,0 +1,164 @@ +{extend name="common@create" /} +{block name="mycss"} +{/block} +{block name="formaa"} +
+
+ +
+
+
+
选择文件
+ +
+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+ +
+ + {php} $school = schlist('校级','区级');{/php} + + +
+
+
+ +
+ + {php}$category = getCategory(116);{/php} + + +
+
+
+ +
+ + {php}$category = getCategory(117);{/php} + + +
+
+
+ +
+ +
+
+
+
+ +
+
+
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/keti/view/keti_info/createall.html b/application/keti/view/keti_info/createall.html index 443a0dc8..865db032 100644 --- a/application/keti/view/keti_info/createall.html +++ b/application/keti/view/keti_info/createall.html @@ -24,7 +24,6 @@
- {/block} {block name="yanzheng"} {js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"} @@ -190,9 +189,9 @@ function article_save(){ chunked: false, chunkSize: 512 * 1024, compress:false, //是否压缩图片 - server: '{:url("JsRongyuInfo/upload")}', + server: '{:url("KetiInfo/upload")}', formData:{ - rongyuce:"{$list.id}" + ketice:"{$list.ketice}" }, // runtimeOrder: 'flash', diff --git a/application/keti/view/keti_info/index.html b/application/keti/view/keti_info/index.html index e36101a1..277cc9c7 100644 --- a/application/keti/view/keti_info/index.html +++ b/application/keti/view/keti_info/index.html @@ -51,12 +51,12 @@
{php}$category = getCategory(115);{/php} - +
{foreach $category as $key=>$vo } {/foreach} @@ -72,13 +72,41 @@
{foreach $school as $key=>$vo } {/foreach}
+
+ {php}$category = getCategory(116);{/php} + +
+
+ {foreach $category as $key=>$vo } + + {/foreach} +
+ +
+
+ {php}$category = getCategory(117);{/php} + +
+
+ {foreach $category as $key=>$vo } + + {/foreach} +
+ +
{/block} @@ -90,6 +118,7 @@ 主持人 课题名称 立项单位 + 负责单位 课题类型 研究方向 学科 @@ -123,6 +152,36 @@ }); return chk; }, + lxcategory:function(){ + var chk = []; + $('input[name="lxcategory"]:checked').each(function(){ + if(typeof($(this).val()) != "undefined") + { + chk.push($(this).val()); + } + }); + return chk; + }, + fzdanweiid:function(){ + var chk = []; + $('input[name="fzdanweiid"]:checked').each(function(){ + if(typeof($(this).val()) != "undefined") + { + chk.push($(this).val()); + } + }); + return chk; + }, + subject:function(){ + var chk = []; + $('input[name="subject"]:checked').each(function(){ + if(typeof($(this).val()) != "undefined") + { + chk.push($(this).val()); + } + }); + return chk; + }, category:function(){ var chk = []; $('input[name="category"]:checked').each(function(){ @@ -133,25 +192,17 @@ }); return chk; }, - fzschool:function(){ - var chk = []; - $('input[name="fzschool"]:checked').each(function(){ - if(typeof($(this).val()) != "undefined") - { - chk.push($(this).val()); - } - }); - return chk; - }, + }, }; // 定义列参数 var mycolumns = [ { "data": "id" }, - { "data": "id" }, + { "data": "zcrName","name":"id","defaultContent": ""}, { "data": "title","defaultContent": "" }, { "data": "kt_lxdanwei.title" ,"name":"lxdanweiid","defaultContent": ""}, + { "data": "kt_lxdanwei.title" ,"name":"lxdanweiid","defaultContent": ""}, { "data": "kt_category.title","name":"category","defaultContent": ""}, { "data": "ktcnt","name":"id","defaultContent": ""}, { "data": "jtcnt","name":"id","defaultContent": ""}, @@ -180,9 +231,9 @@ startbut = ''; // 上图图片按钮 - picbut = ''; + picbut = ''; // 添加荣誉 - addbut = ''; + addbut = ''; // 编辑按钮 editbut = ''; delbut = ''; diff --git a/application/rongyu/controller/JsRongyuInfo.php b/application/rongyu/controller/JsRongyuInfo.php index da919108..96dcedad 100644 --- a/application/rongyu/controller/JsRongyuInfo.php +++ b/application/rongyu/controller/JsRongyuInfo.php @@ -128,9 +128,6 @@ class JsRongyuInfo extends Base // 如果验证不通过则停止保存 if(!$result){ - if($list['id']>0){ - ryinfo::destroy($list['id'],true); - } return json(['msg'=>$msg,'val'=>0]); } @@ -250,7 +247,7 @@ class JsRongyuInfo extends Base */ public function edit($id) { - // 获取学生信息 + // 获取荣誉信息 $list = ryinfo::where('id',$id) ->field('id,title,rongyuce,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') ->with([ diff --git a/application/rongyu/view/js_rongyu_info/create.html b/application/rongyu/view/js_rongyu_info/create.html index 72c16398..7794231f 100644 --- a/application/rongyu/view/js_rongyu_info/create.html +++ b/application/rongyu/view/js_rongyu_info/create.html @@ -84,7 +84,6 @@ -
diff --git a/application/system/validate/Category.php b/application/system/validate/Category.php index 33364a4f..7fc8bc98 100644 --- a/application/system/validate/Category.php +++ b/application/system/validate/Category.php @@ -13,7 +13,7 @@ class Category extends Validate * @var array */ protected $rule = [ - 'title|规则名' => 'require|chs|length:2,8', + 'title|规则名' => 'require|chs|length:2,50', 'paixu|排序' => 'number|max:999', ]; diff --git a/application/system/view/category/create.html b/application/system/view/category/create.html index bdf08b53..26ece488 100644 --- a/application/system/view/category/create.html +++ b/application/system/view/category/create.html @@ -54,7 +54,7 @@ title:{ required:true, zh:true, - rangelength:[2,8] + rangelength:[2,50] }, paixu:{ digits:true, diff --git a/application/system/view/category/edit.html b/application/system/view/category/edit.html index 5adb1531..6a0d0189 100644 --- a/application/system/view/category/edit.html +++ b/application/system/view/category/edit.html @@ -54,7 +54,7 @@ title:{ required:true, zh:true, - rangelength:[2,6] + rangelength:[2,50] }, paixu:{ digits:true, diff --git a/database/migrations/20181025041505_category.php b/database/migrations/20181025041505_category.php index 60e1b0aa..0bf013aa 100644 --- a/database/migrations/20181025041505_category.php +++ b/database/migrations/20181025041505_category.php @@ -33,7 +33,7 @@ class Category extends Migrator // 添加当前表字段 $table - ->addColumn('title','string',['limit'=>15,'null'=>false,'comment'=>'类型标题']) + ->addColumn('title','string',['limit'=>50,'null'=>false,'comment'=>'类型标题']) ->addColumn('pid','integer',['limit'=>4,'default'=>'0','null'=>false,'comment'=>'父级ID']) ->addColumn('status','boolean',['limit'=>1,'default'=>'1','null'=>false,'comment'=>'0=禁用,1=正常']) ->addColumn('paixu','integer',['limit'=>4,'default'=>'999','null'=>false,'comment'=>'排序']) diff --git a/database/migrations/20190222041040_keti_canyu.php b/database/migrations/20190222041040_keti_canyu.php index 78af0361..490f80ef 100644 --- a/database/migrations/20190222041040_keti_canyu.php +++ b/database/migrations/20190222041040_keti_canyu.php @@ -33,7 +33,7 @@ class KetiCanyu extends Migrator // 添加当前表字段 $table - ->addColumn('category','integer',['limit'=>1,'null'=>false,'default'=>0,'comment'=>'主持人或参与人,1=>主持人,2=>参与人']) + ->addColumn('category','integer',['limit'=>1,'null'=>false,'default'=>0,'comment'=>'1=>课题主持人,2=>课题参与人']) ->addColumn('ketiinfoid','integer',['limit'=>11,'null'=>false,'comment'=>'课题信息id']) ->addColumn('teacherid','integer',['limit'=>11,'null'=>false,'comment'=>'教师id']) ->create(); diff --git a/route/keti.php b/route/keti.php index fae34b42..f33bbcdd 100644 --- a/route/keti.php +++ b/route/keti.php @@ -14,9 +14,9 @@ Route::resource('kt','keti/Index'); Route::resource('ktinfo','keti/KetiInfo'); // 添加立项信息 -Route::get('ktinfoadd/:id/create','keti/KetiInfo/create'); +Route::get('ktinfoadd/:id','keti/KetiInfo/create'); // 批量添加立项图片 -Route::get('ktinfoadd/:id/createall','keti/KetiInfo/createall'); +Route::get('ktinfoaddall/:id','keti/KetiInfo/createall');