From f375328cb63351b7f4105a0ef41750f17e58097f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE=E6=A0=91?= Date: Mon, 4 Mar 2019 09:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E4=BD=8D=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/system/controller/School.php | 49 +++++++--- application/system/model/School.php | 113 ++++++++++------------ application/system/view/school/index.html | 55 +++++++++-- 3 files changed, 136 insertions(+), 81 deletions(-) diff --git a/application/system/controller/School.php b/application/system/controller/School.php index f14b8ce2..c7b9fa0c 100644 --- a/application/system/controller/School.php +++ b/application/system/controller/School.php @@ -35,21 +35,48 @@ class School extends Base // 获取DT的传值 $getdt = request()->param(); - - // 实例化单位模型 - $sch = new sch(); - // 获取记录集总数 - $cnt = $sch->searchAll()->count(); - //查询数据 - $data =$sch->searchAjax($getdt); + //得到排序的方式 + $order = $getdt['order'][0]['dir']; + //得到排序字段的下标 + $order_column = $getdt['order'][0]['column']; + //根据排序字段的下标得到排序字段 + $order_field = $getdt['columns'][$order_column]['name']; + if($order_field=='') + { + $order_field = $getdt['columns'][$order_column]['data']; + } + //得到limit参数 + $limit_start = $getdt['start']; + $limit_length = $getdt['length']; + //得到搜索的关键词 + $search = [ + 'xingzhi'=>$getdt['xingzhi'], + 'search'=>$getdt['search']['value'], + 'order'=>$order, + 'order_field'=>$order_field + ]; + + + // 实例化 + $sch = new sch; + + // 获取荣誉总数 + $cnt = $sch->select()->count(); + + // 查询数据 + $data = $sch->search($search); $datacnt = $data->count(); - - // 组合返回数据 + + // 获取当前页数据 + $data = $data->slice($limit_start,$limit_length); + + + // 重组返回内容 $data = [ 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 - 'recordsTotal'=>$datacnt, // 获取到的结果数(每页显示数量) - 'recordsFiltered'=>$cnt, // 符合条件的总数据量 + 'recordsTotal'=>$cnt, // 获取到的结果数(每页显示数量) + 'recordsFiltered'=>$datacnt, // 符合条件的总数据量 'data'=>$data, //获取到的数据结果 ]; diff --git a/application/system/model/School.php b/application/system/model/School.php index e3b910e7..a137f228 100644 --- a/application/system/model/School.php +++ b/application/system/model/School.php @@ -7,66 +7,75 @@ use app\common\model\Base; class School extends Base { - // 单位性质获取器 - public function getXingzhiAttr($value) + // 教师数据模型关联 + public function dwTeacher() { - return $this->getcategory($value); + return $this->hasMany('\app\renshi\model\Teacher','danwei','id'); } - // 单位级别获取器 - public function getJibieAttr($value) + // 单位性质数据模型关联 + public function dwXingzhi() { - return $this->getcategory($value); + return $this->belongsTo('\app\system\model\Category','xingzhi','id'); } - // 单位学段获取器 - public function getXueduanAttr($value) + + // 单位级别数模型关联 + public function dwJibie() { - return $this->getcategory($value); + return $this->belongsTo('\app\system\model\Category','jibie','id'); } - // 获取类别名 - public function getcategory($id) + + // 单位学段数模型关联 + public function dwXueduan() { - $ct = new \app\system\model\Category; - return $ct - ->where('id',$id) - ->value('title'); + return $this->belongsTo('\app\system\model\Category','xueduan','id'); } + // 查询所有单位 - public function searchAjax($getdt) + public function search($search) { - //得到排序的方式 - $order = $getdt['order'][0]['dir']; - //得到排序字段的下标 - $order_column = $getdt['order'][0]['column']; - //根据排序字段的下标得到排序字段 - $order_field = $getdt['columns'][$order_column]['data']; - //得到limit参数 - $limit_start = $getdt['start']; - $limit_length = $getdt['length']; - //得到搜索的关键词 - $search = $getdt['search']['value']; + // 获取参数 + $xingzhi = $search['xingzhi']; + $order_field = $search['order_field']; + $order = $search['order']; + $search = $search['search']; - // 如果需要查询 - if(trim($search)){ - $data =sch::field('id,title,jiancheng,biaoshi,xingzhi,jibie,status,xueduan,paixu') - ->whereOr('title','like','%'.$search.'%') - ->whereOr('pid','in',function($query) use ($search){ - $query->name('category')->where('title','like','%'.$search.'%')->field('id'); + + $data = $this->order([$order_field =>$order]) + ->when(strlen($xingzhi)>0,function($query) use($xingzhi){ + $query->where('xingzhi','in',$xingzhi); }) - ->order([$order_field=>$order]) - ->limit($limit_start,$limit_length) - ->select(); - }else{ - $data =$this->field('id,title,jiancheng,biaoshi,xingzhi,jibie,status,xueduan,paixu') - ->order([$order_field=>$order]) - ->limit($limit_start,$limit_length) + ->when(strlen($search)>0,function($query) use($search){ + $query->where('title|jiancheng','like',$search); + }) + ->with( + [ + 'dwXingzhi'=>function($query){ + $query->field('id,title'); + }, + 'dwJibie'=>function($query){ + $query->field('id,title'); + }, + 'dwXueduan'=>function($query){ + $query->field('id,title'); + }, + ] + ) + ->withCount( + [ + 'dwTeacher'=>function($query){ + $query->where('status',1); + } + ] + ) + // ->append(['cnt']) ->select(); - } + return $data; } @@ -76,26 +85,4 @@ class School extends Base { return $this->cache('key',180)->select(); } - - // 查询范围内数据 - // public function searchMany($jibie1,$jibie2) - // { - // $jb = new \app\system\model\Category; - // $jibie1 = $jb->wherePid(102) - // ->whereTitle($jibie1) - // ->value('id'); - // $jibie2 = $jb->wherePid(102) - // ->whereTitle($jibie2) - // ->value('id'); - - // $schlist = $this->where('jibie','between',[$jibie1,$jibie2])->select(); - // return $schlist; - // } - - - - - - - } diff --git a/application/system/view/school/index.html b/application/system/view/school/index.html index a0d1d7a0..577b9dc7 100644 --- a/application/system/view/school/index.html +++ b/application/system/view/school/index.html @@ -30,6 +30,25 @@ 共有数据:{$list.count} 条 +
+
筛选荣誉册
+
+
+ {php}$category = getCategory(101);{/php} + +
+
+ {foreach $category as $key=>$vo } + + {/foreach} +
+ +
+
+
{/block} {block name="tables"} @@ -39,10 +58,10 @@ - + @@ -59,8 +78,19 @@ // 定义DTajax参数 var myajax = { url: "{:url('ajaxdata')}", - type: "get", - data: {}, + type: "post", + data: { + xingzhi:function(){ + var chk = []; + $('input[name="xingzhi"]:checked').each(function(){ + if(typeof($(this).val()) != "undefined") + { + chk.push($(this).val()); + } + }); + return chk; + }, + }, }; // 定义列参数 @@ -68,11 +98,11 @@ { "data": "id" }, { "data": "title" }, { "data": "jiancheng" }, - { "data": "xingzhi" }, - { "data": "biaoshi" }, - { "data": "jibie" }, - { "data": "xueduan" }, + { "data": "dw_xingzhi.title" ,"name":"xingzhi","defaultContent": "" }, + { "data": "dw_jibie.title" ,"name":"jibie","defaultContent": "" }, + { "data": "dw_xueduan.title" ,"name":"xueduan","defaultContent": "" }, { "data": "paixu" }, + { "data": "dw_teacher_count","name":"id" ,"defaultContent":""}, { "data": "status" }, { "data": "id" }, ]; @@ -126,5 +156,16 @@ "targets": [0,-1] }, ]; + + // 筛选成绩面板折叠 + $('#shaixuan').click(function(){ + $(this).next().toggle(); + }); + + // 重载数据 + function dtreload() + { + $('#table1').DataTable().ajax.reload(); + } {/block} \ No newline at end of file
单位名称 简称 性质标识码 级别 学段 排序教师数 状态 操作