优化单位列表
This commit is contained in:
1 parent
d89d6bc8a9
commit
f375328cb6
3 files changed
+136
-81
No files matched your search
@@ -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, //获取到的数据结果
|
||||
];
|
||||
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -30,6 +30,25 @@
|
||||
共有数据:<strong>{$list.count}</strong> 条
|
||||
</span>
|
||||
</div>
|
||||
<div class="panel panel-default mt-10 mb-10">
|
||||
<div class="panel-header" id="shaixuan">筛选荣誉册</div>
|
||||
<div class="panel-body" style="min-height: 40px">
|
||||
<div>
|
||||
{php}$category = getCategory(101);{/php}
|
||||
<label class="f-l">荣誉类别:</label>
|
||||
<dt>
|
||||
<dd class=" mt-10">
|
||||
{foreach $category as $key=>$vo }
|
||||
<label class="ml-10">
|
||||
<input type="checkbox" value="{$vo.id}" name="xingzhi" onclick="dtreload()">
|
||||
{$vo.title}
|
||||
</label>
|
||||
{/foreach}
|
||||
</dd>
|
||||
</dt>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="tables"}
|
||||
<table id="table1" class="display" cellspacing="0" width="100%">
|
||||
@@ -39,10 +58,10 @@
|
||||
<th>单位名称</th>
|
||||
<th>简称</th>
|
||||
<th>性质</th>
|
||||
<th>标识码</th>
|
||||
<th>级别</th>
|
||||
<th>学段</th>
|
||||
<th>排序</th>
|
||||
<th>教师数</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
@@ -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();
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
Reference in new issue
Block a user