diff --git a/application/http/middleware/YanZheng.php b/application/http/middleware/YanZheng.php index fb9b4b14..57f0db52 100644 --- a/application/http/middleware/YanZheng.php +++ b/application/http/middleware/YanZheng.php @@ -55,6 +55,8 @@ class YanZheng extends Controller 'welcome','update','save','upload', 'index','mybanji','banjilist', 'editpassword','updatepassword', + // 教师信息查询 + 'srcTeacher', // 查询班级成绩、查询年级成绩 'ajaxbanji','ajaxnianji', // 批量保存 diff --git a/application/renshi/controller/Index.php b/application/renshi/controller/Index.php index 50286451..6941533b 100644 --- a/application/renshi/controller/Index.php +++ b/application/renshi/controller/Index.php @@ -294,4 +294,31 @@ class Index extends Base } + + // 根据教师姓名、首拼、全拼搜索教师信息 + public function srcTeacher($str="") + { + // 声明结果数组 + $data = array(); + + + // 判断是否存在数据,如果没有数据则返回。 + if(strlen($str) <= 0) + { + return json($data); + } + + + // 如果有数据则查询教师信息 + $list = Teacher::field('id,xingming,danwei,shengri,sex') + ->whereOr('xingming|quanpin','like',$str.'%') + ->whereOr('quanpin','like',$str.'%') + ->whereOr('shoupin','like',$str.'%') + ->append(['age']) + ->all(); + return json($list); + } + + + } diff --git a/application/rongyu/controller/DwRongyu.php b/application/rongyu/controller/DwRongyu.php index c0283908..bd99724d 100644 --- a/application/rongyu/controller/DwRongyu.php +++ b/application/rongyu/controller/DwRongyu.php @@ -113,7 +113,7 @@ class DwRongyu extends Base public function save() { // 获取表单数据 - $list = request()->only(['id','url','title','hjschool','category','fzshijian','fzschool','jiangxiang'],'post'); + $list = request()->only(['id','url','title','teachers','hjschool','category','fzshijian','fzschool','jiangxiang'],'post'); // 实例化验证模型 $validate = new \app\rongyu\validate\DwRongyu; @@ -122,12 +122,31 @@ class DwRongyu extends Base $msg = $validate->getError(); // 如果验证不通过则停止保存 if(!$result){ - return json(['msg'=>$msg,'val'=>0]);; + dwry::destroy($list['id'],true); + return json(['msg'=>$msg,'val'=>0]); } // 保存数据 $data = dwry::update($list); + if(!empty($list['teachers'])) + { + // 单位荣誉参与数据模型 + // $dwrycy = new \app\rongyu\model\DwRongyuCanyu; + + // 声明参与教师数组 + $canyulist = []; + // 循环组成参与信息 + foreach ($list['teachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'rongyuid' => $list['id'], + ]; + } + + $data->cyDwry()->saveAll($canyulist); + } + // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -211,9 +230,16 @@ class DwRongyu extends Base // 获取学生信息 $list = dwry::where('id',$id) ->field('id,title,category,hjschool,fzshijian,fzschool,jiangxiang,url') + ->with([ + 'cyDwry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + ]) ->find(); - $this->assign('list',$list); return $this->fetch(); @@ -229,7 +255,7 @@ class DwRongyu extends Base public function update($id) { // 获取表单数据 - $list = request()->only(['title','category','hjschool','fzshijian','fzschool','jiangxiang'],'put'); + $list = request()->only(['title','category','hjschool','fzshijian','fzschool','jiangxiang','teachers'],'put'); $list['id'] = $id; @@ -246,11 +272,29 @@ class DwRongyu extends Base // 更新数据 - $dwry = new dwry(); - $data = $dwry->save($list,['id'=>$id]); + // $dwry = new dwry(); + $data = dwry::update($list); + + if(!empty($list['teachers'])) + { + + $data->cyDwry()->delete(true); + + // 声明参与教师数组 + $canyulist = []; + // 循环组成参与信息 + foreach ($list['teachers'] as $key => $value) { + $canyulist[] = [ + 'teacherid' => $value, + 'rongyuid' => $list['id'], + ]; + } + + $data->cyDwry()->saveAll($canyulist); + } // 根据更新结果设置返回提示信息 - $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 return json($data); diff --git a/application/rongyu/model/DwRongyu.php b/application/rongyu/model/DwRongyu.php index 08f7444e..b38aa2da 100644 --- a/application/rongyu/model/DwRongyu.php +++ b/application/rongyu/model/DwRongyu.php @@ -80,6 +80,12 @@ class DwRongyu extends Base return $this->belongsTo('\app\system\model\Category','category','id'); } + // 参与人 + public function cyDwry() + { + return $this->hasMany('\app\rongyu\model\DwRongyuCanyu','rongyuid','id'); + } + // 荣誉级别 public function getJibieAttr() { diff --git a/application/rongyu/model/DwRongyuCanyu.php b/application/rongyu/model/DwRongyuCanyu.php index 7ef51aaf..90cc2906 100644 --- a/application/rongyu/model/DwRongyuCanyu.php +++ b/application/rongyu/model/DwRongyuCanyu.php @@ -8,4 +8,17 @@ class DwRongyuCanyu extends Model { // 关闭全局自动时间戳 protected $autoWriteTimestamp = false; + + // 荣誉册关联 + public function rongyu() + { + return $this->belongsTo('\app\rongyu\model\DwRongyu','rongyuid','id'); + } + + // 教师关联 + public function teacher() + { + return $this->belongsTo('\app\renshi\model\Teacher','teacherid','id'); + } + } diff --git a/application/rongyu/validate/DwRongyu.php b/application/rongyu/validate/DwRongyu.php index 6ffa468b..b86a03b5 100644 --- a/application/rongyu/validate/DwRongyu.php +++ b/application/rongyu/validate/DwRongyu.php @@ -21,6 +21,7 @@ class DwRongyu extends Validate 'fzshijian|发证时间' => 'require|date', 'fzschool|发证单位' => 'require|number', 'jiangxiang|奖项' => 'require|number', + 'teachers|参与人' =>'array', ]; diff --git a/application/rongyu/view/dw_rongyu/create.html b/application/rongyu/view/dw_rongyu/create.html index 99ce7596..f8fdd23c 100644 --- a/application/rongyu/view/dw_rongyu/create.html +++ b/application/rongyu/view/dw_rongyu/create.html @@ -23,6 +23,14 @@ +
+ +
+ +
+
+
+
@@ -217,6 +225,55 @@ }); + // 搜索教师 + function cySelect() + { + $('#cySelect').empty(); + var str = ""; + str = $('#canyu').val(); + if(str.length<=0) + { + return ""; + } + $.post( + "{:Url::build('renshi/index/srcTeacher')}", + { + "str":str, + }, + function(data,status){ + if($.isEmptyObject(data)) + { + return true; + } + for (var i = data.length - 1; i >= 0; i--) { + var myhtml = ""; + myhtml = ""; + $('#cySelect').append(myhtml); + } + + } + ); + } + + + // 添加参与人 + function addCy(obj,teacherId) + { + $('#canyu').val(''); + $(obj).attr('class','btn btn-primary radius mr-5 size-MINI'); + $(obj).attr('onclick','delCy(this)'); + var myhtml = ""; + myhtml = ""; + $('#addTeacher').append(myhtml); + $('#addTeacher').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/dw_rongyu/edit.html b/application/rongyu/view/dw_rongyu/edit.html index 1ef7d548..ef0507db 100644 --- a/application/rongyu/view/dw_rongyu/edit.html +++ b/application/rongyu/view/dw_rongyu/edit.html @@ -10,7 +10,22 @@
- + +
+
+
+ +
+ +
+ {volist name="list.cy_dwry" id="vo"} + + + + + {/volist} +
+
@@ -206,6 +221,56 @@ }); + + // 搜索教师 + function cySelect() + { + $('#cySelect').empty(); + var str = ""; + str = $('#canyu').val(); + if(str.length<=0) + { + return ""; + } + $.post( + "{:Url::build('renshi/index/srcTeacher')}", + { + "str":str, + }, + function(data,status){ + if($.isEmptyObject(data)) + { + return true; + } + for (var i = data.length - 1; i >= 0; i--) { + var myhtml = ""; + myhtml = ""; + $('#cySelect').append(myhtml); + } + + } + ); + } + + + // 添加参与人 + function addCy(obj,teacherId) + { + $('#canyu').val(''); + $(obj).attr('class','btn btn-primary radius mr-5 size-MINI'); + $(obj).attr('onclick','delCy(this)'); + var myhtml = ""; + myhtml = ""; + $('#addTeacher').append(myhtml); + $('#addTeacher').children("span").last().append(obj); + } + + // 删除参与人 + function delCy(obj) + { + $(obj).parent().remove(); + } + // 匹配用户名 $.validator.addMethod("zh",function(value,element){ var tel = /^[\u4e00-\u9fa5]*$/;