From da96d601f010c2b1db2ae8b1fa60c4ff63b4958c Mon Sep 17 00:00:00 2001 From: cxdbz Date: Thu, 14 Feb 2019 19:15:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E4=BD=8D=E8=8D=A3?= =?UTF-8?q?=E8=AA=89=E5=92=8C=E6=95=99=E5=B8=88=E8=8D=A3=E8=AA=89=E7=9A=84?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8E=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rongyu/controller/JsRongyuInfo.php | 88 +++-- application/rongyu/model/JsRongyu.php | 3 +- application/rongyu/model/JsRongyuCanyu.php | 23 ++ application/rongyu/model/JsRongyuInfo.php | 22 +- application/rongyu/validate/JsRongyuInfo.php | 3 +- application/rongyu/view/dw_rongyu/create.html | 3 +- application/rongyu/view/dw_rongyu/edit.html | 1 + .../rongyu/view/js_rongyu_info/create.html | 123 ++++++- .../rongyu/view/js_rongyu_info/edit.html | 309 ++++++++++++++++-- .../20181221041523_js_rongyu_info.php | 2 +- .../20181227061353_dw_rongyu_canyu.php | 2 +- .../20190214052203_js_rongyu_canyu.php | 41 +++ 12 files changed, 553 insertions(+), 67 deletions(-) create mode 100644 application/rongyu/model/JsRongyuCanyu.php create mode 100644 database/migrations/20190214052203_js_rongyu_canyu.php diff --git a/application/rongyu/controller/JsRongyuInfo.php b/application/rongyu/controller/JsRongyuInfo.php index c7ea16cc..736338ce 100644 --- a/application/rongyu/controller/JsRongyuInfo.php +++ b/application/rongyu/controller/JsRongyuInfo.php @@ -105,36 +105,36 @@ class JsRongyuInfo extends Base return $this->fetch(); } - /** + /**留备用 * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ - public function save1() - { - // 获取表单数据 - $list = request()->only(['id','title','category','hjschool','subject','fzshijian','jiangxiang'],'post'); + // public function save1() + // { + // // 获取表单数据 + // $list = request()->only(['id','title','category','hjschool','subject','fzshijian','jiangxiang'],'post'); - // 实例化验证模型 - $validate = new \app\rongyu\validate\JsRongyu; - // 验证表单数据 - $result = $validate->check($list); - $msg = $validate->getError(); - // 如果验证不通过则停止保存 - if(!$result){ - return json(['msg'=>$msg,'val'=>0]);; - } + // // 实例化验证模型 + // $validate = new \app\rongyu\validate\JsRongyu; + // // 验证表单数据 + // $result = $validate->check($list); + // $msg = $validate->getError(); + // // 如果验证不通过则停止保存 + // if(!$result){ + // return json(['msg'=>$msg,'val'=>0]);; + // } - // 保存数据 - $data = ryinfo::create($list); + // // 保存数据 + // $data = ryinfo::create($list); - // 根据更新结果设置返回提示信息 - $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + // // 根据更新结果设置返回提示信息 + // $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; - // 返回信息 - return json($data); - } + // // 返回信息 + // return json($data); + // } /** * 批量上传教师荣誉册图片 @@ -222,8 +222,24 @@ class JsRongyuInfo extends Base // 获取学生信息 $list = ryinfo::where('id',$id) ->field('id,title,rongyuce,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') + ->with([ + 'hjJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + 'cyJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + ]) ->find(); + dump($list); + $this->assign('list',$list); @@ -240,9 +256,9 @@ class JsRongyuInfo extends Base public function update($id) { // 获取表单数据 - $list = request()->only(['title','category','hjschool','subject','hjshijian','jiangxiang'],'put'); + $list = request()->only(['title','category','hjschool','subject','hjshijian','jiangxiang','hjteachers','cyteachers','pic'],'put'); $list['id'] = $id; - + // 实例化验证类 $validate = new \app\rongyu\validate\JsRongyuInfo; @@ -262,11 +278,35 @@ class JsRongyuInfo extends Base // 更新数据 $data = ryinfo::update($list); + // 删除原来的获奖人与参与人信息 + $data->allJsry()->delete(true); + // 声明教师数组 + $teacherlist = []; + // 循环组成获奖教师信息 + foreach ($list['hjteachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'rongyuid' => $list['id'], + 'category' => 1, + ]; + } + // 循环组成参与教师信息 + foreach ($list['cyteachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'rongyuid' => $list['id'], + 'category' => 2, + ]; + } + + // 添加新的获奖人与参与人信息 + $data->allJsry()->saveAll($canyulist); + // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 - return json($data); + return json($data&1); } /** diff --git a/application/rongyu/model/JsRongyu.php b/application/rongyu/model/JsRongyu.php index 6b74827c..9d4aff28 100644 --- a/application/rongyu/model/JsRongyu.php +++ b/application/rongyu/model/JsRongyu.php @@ -52,7 +52,7 @@ class JsRongyu extends Base return $this->belongsTo('\app\system\model\School','fzschool','id'); } - // 荣誉类型 + // 荣誉类型关联 public function lxCategory() { return $this->belongsTo('\app\system\model\Category','category','id'); @@ -65,6 +65,7 @@ class JsRongyu extends Base return $this->hasMany('JsRongyuInfo','rongyuce','id'); } + // 荣誉级别 public function getCntAttr() { diff --git a/application/rongyu/model/JsRongyuCanyu.php b/application/rongyu/model/JsRongyuCanyu.php new file mode 100644 index 00000000..c24600df --- /dev/null +++ b/application/rongyu/model/JsRongyuCanyu.php @@ -0,0 +1,23 @@ +belongsTo('\app\rongyu\model\JsRongyu','rongyuid','id'); + } + + // 教师关联 + public function teacher() + { + return $this->belongsTo('\app\renshi\model\Teacher','teacherid','id'); + } +} diff --git a/application/rongyu/model/JsRongyuInfo.php b/application/rongyu/model/JsRongyuInfo.php index 68fcb491..47b6bb2b 100644 --- a/application/rongyu/model/JsRongyuInfo.php +++ b/application/rongyu/model/JsRongyuInfo.php @@ -84,12 +84,32 @@ class JsRongyuInfo extends Base return $this->belongsTo('\app\teach\model\Subject','subject','id'); } - // 奖项 + // 奖项关联 public function jxCategory() { return $this->belongsTo('\app\system\model\Category','jiangxiang','id'); } + // 获奖人关联 + public function hjJsry() + { + return $this->hasMany('\app\rongyu\model\JsRongyuCanyu','rongyuid','id')->where('category',1); + } + + + // 获奖人与参与教师关联 + public function allJsry() + { + return $this->hasMany('\app\rongyu\model\JsRongyuCanyu','rongyuid','id'); + } + + + // 获奖人关联 + public function cyJsry() + { + return $this->hasMany('\app\rongyu\model\JsRongyuCanyu','rongyuid','id')->where('category',2); + } + // 荣誉级别 public function getJibieAttr() diff --git a/application/rongyu/validate/JsRongyuInfo.php b/application/rongyu/validate/JsRongyuInfo.php index 3d0a86cf..00a05ca6 100644 --- a/application/rongyu/validate/JsRongyuInfo.php +++ b/application/rongyu/validate/JsRongyuInfo.php @@ -15,11 +15,12 @@ class JsRongyuInfo extends Validate protected $rule = [ 'id|请先上传图片' => 'require', 'title|荣册标题' => 'require|length:1,30', - 'category|荣誉类型' => 'require|number', + 'hjteachers|获奖人' => 'require|array', 'hjschool|荣誉所在单位' => 'require|number', 'subject|荣誉所属学科' => 'require|number', 'hjshijian|发证时间' => 'require|date', 'jiangxiang|奖项' => 'require|number', + 'cyteachers|参与人' => 'array', ]; /** diff --git a/application/rongyu/view/dw_rongyu/create.html b/application/rongyu/view/dw_rongyu/create.html index f8fdd23c..965a5c13 100644 --- a/application/rongyu/view/dw_rongyu/create.html +++ b/application/rongyu/view/dw_rongyu/create.html @@ -241,6 +241,7 @@ "str":str, }, function(data,status){ + $('#cySelect').empty(); if($.isEmptyObject(data)) { return true; @@ -260,7 +261,7 @@ function addCy(obj,teacherId) { $('#canyu').val(''); - $(obj).attr('class','btn btn-primary radius mr-5 size-MINI'); + $(obj).attr('class','btn btn-warning radius mr-5 size-MINI'); $(obj).attr('onclick','delCy(this)'); var myhtml = ""; myhtml = ""; diff --git a/application/rongyu/view/dw_rongyu/edit.html b/application/rongyu/view/dw_rongyu/edit.html index ef0507db..bd248955 100644 --- a/application/rongyu/view/dw_rongyu/edit.html +++ b/application/rongyu/view/dw_rongyu/edit.html @@ -238,6 +238,7 @@ "str":str, }, function(data,status){ + $('#cySelect').empty(); if($.isEmptyObject(data)) { return true; diff --git a/application/rongyu/view/js_rongyu_info/create.html b/application/rongyu/view/js_rongyu_info/create.html index 66ba081c..77b801fc 100644 --- a/application/rongyu/view/js_rongyu_info/create.html +++ b/application/rongyu/view/js_rongyu_info/create.html @@ -34,27 +34,17 @@
- + +
+
- -
-
-
- -
- - {php}$category = getCategory(112);{/php} - - + +
+
@@ -243,6 +233,107 @@ }); + + // 获取获奖教师列表 + function hjSelect(obj) + { + $('#hjSelect').empty(); + $('#cySelect').empty(); + var str = ""; + str = $('#hjteacher').val(); + if(str.length<=0) + { + return ""; + } + $.post( + "{:Url::build('renshi/index/srcTeacher')}", + { + "str":str, + }, + function(data,status){ + $('#hjSelect').empty(); + $('#cySelect').empty(); + if($.isEmptyObject(data)) + { + return true; + } + for (var i = data.length - 1; i >= 0; i--) { + var myhtml = ""; + myhtml = ""; + $('#hjSelect').append(myhtml); + } + + } + ); + } + + // 添加参与人 + function addHj(obj,teacherId) + { + $('#hjteacher').val(''); + $('#cyteacher').val(''); + $(obj).attr('class','btn btn-warning radius mr-5 size-MINI'); + $(obj).attr('onclick','delCy(this)'); + var myhtml = ""; + myhtml = ""; + $('#addHj').append(myhtml); + $('#addHj').children("span").last().append(obj); + } + + + // 获取参与教师列表 + function cySelect(obj) + { + $('#hjSelect').empty(); + $('#cySelect').empty(); + var str = ""; + str = $('#cyteacher').val(); + if(str.length<=0) + { + return ""; + } + $.post( + "{:Url::build('renshi/index/srcTeacher')}", + { + "str":str, + }, + function(data,status){ + $('#hjSelect').empty(); + $('#cySelect').empty(); + if($.isEmptyObject(data)) + { + return true; + } + for (var i = data.length - 1; i >= 0; i--) { + var myhtml = ""; + myhtml = ""; + $('#cySelect').append(myhtml); + } + + } + ); + } + + + // 添加参与人 + function addCy(obj,teacherId) + { + $('#hjteacher').val(''); + $('#cyteacher').val(''); + $(obj).attr('class','btn btn-warning radius mr-5 size-MINI'); + $(obj).attr('onclick','delCy(this)'); + var myhtml = ""; + myhtml = ""; + $('#addCy').append(myhtml); + $('#addCy').children("span").last().append(obj); + } + + // 删除参与人 + function delCy(obj) + { + $(obj).parent().remove(); + } + // 匹配用户名 $.validator.addMethod("zh",function(value,element){ var tel = /^[\u4e00-\u9fa5]*$/; diff --git a/application/rongyu/view/js_rongyu_info/edit.html b/application/rongyu/view/js_rongyu_info/edit.html index cc4bef71..a838c2ff 100644 --- a/application/rongyu/view/js_rongyu_info/edit.html +++ b/application/rongyu/view/js_rongyu_info/edit.html @@ -1,40 +1,66 @@ {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"} -
- {php} - dump($list); - {/php} +
+ +
+
- +
- + +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
- - {php}$category = getCategory(112);{/php} - + + {volist name="school" id="vo"} + {/volist}
- +
- {php} $school = schlist('区级','其它级');{/php} - + + {volist name="sjlist" id="vo"} + {/volist} @@ -43,7 +69,22 @@
- + +
+
+
+
+ +
+ + {php}$jiangxiang = getCategory(113);{/php} + +
@@ -54,7 +95,233 @@ {/block} {block name="yanzheng"} +{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"}