考试列表
This commit is contained in:
1 parent
9d5bb59806
commit
7219fd68d5
3 files changed
+87
-63
No files matched your search
@@ -30,60 +30,36 @@ class Index extends Base
|
||||
public function ajaxData()
|
||||
{
|
||||
|
||||
// 获取DT的传值
|
||||
$getdt = request()->param();
|
||||
|
||||
//得到排序的方式
|
||||
$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 = $getdt['search']['value'];
|
||||
// 获取参数
|
||||
$src = $this->request
|
||||
->only([
|
||||
'page'=>'1',
|
||||
'limit'=>'10',
|
||||
'field'=>'update_time',
|
||||
'order'=>'asc',
|
||||
'xingzhi'=>array(),
|
||||
'searchval'=>''
|
||||
],'POST');
|
||||
|
||||
|
||||
// 获取记录集总数
|
||||
$cnt = KS::count();
|
||||
//查询数据
|
||||
$data =KS::field('id,title,xueqi,category,bfdate,enddate,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->all();
|
||||
|
||||
|
||||
// 如果需要查询
|
||||
if($search){
|
||||
$data = KS::field('id,title,xueqi,category,bfdate,enddate,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->whereOr('title','like','%'.$search.'%')
|
||||
->whereOr('category','in',function($query) use($search)
|
||||
{
|
||||
$query->name('category')
|
||||
->where('title','like','%'.$search.'%')
|
||||
->field('id');
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
$data = $data->append(['nianjinames','subjectnames','jieshu','kaishi']);
|
||||
|
||||
$datacnt = $data->count();
|
||||
|
||||
// 实例化
|
||||
$ks = new KS;
|
||||
|
||||
// 查询要显示的数据
|
||||
$data = $ks->search($src);
|
||||
// 获取符合条件记录总数
|
||||
$cnt = $data->count();
|
||||
// 获取当前页数据
|
||||
$limit_start = $src['page'] * $src['limit'] - $src['limit'];
|
||||
$limit_length = $src['limit']-1;
|
||||
$data = $data->slice($limit_start,$limit_length);
|
||||
|
||||
// 重组返回内容
|
||||
$data = [
|
||||
'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符
|
||||
'recordsTotal'=>$datacnt, // 获取到的结果数(每页显示数量)
|
||||
'recordsFiltered'=>$cnt, // 符合条件的总数据量
|
||||
'data'=>$data, // 获取到的数据结果
|
||||
'code'=> 0 , // ajax请求次数,作为标识符
|
||||
'msg'=>"", // 获取到的结果数(每页显示数量)
|
||||
'count'=>$cnt, // 符合条件的总数据量
|
||||
'data'=>$data, //获取到的数据结果
|
||||
];
|
||||
|
||||
|
||||
@@ -96,13 +72,18 @@ class Index extends Base
|
||||
public function create()
|
||||
{
|
||||
// 设置页面标题
|
||||
$list['title'] = '添加考试';
|
||||
$list['set'] = array(
|
||||
'webtitle'=>'添加考试',
|
||||
'butname'=>'添加',
|
||||
'formpost'=>'POST',
|
||||
'url'=>'/kaoshi/'.$id,
|
||||
);
|
||||
|
||||
|
||||
// 模板赋值
|
||||
$this->assign('list',$list);
|
||||
|
||||
// 渲染
|
||||
return $this->fetch();
|
||||
return $this->fetch('create');
|
||||
}
|
||||
|
||||
|
||||
@@ -183,18 +164,24 @@ class Index extends Base
|
||||
{
|
||||
|
||||
// 获取考试信息
|
||||
$list = KS::where('id',$id)
|
||||
$list['data'] = KS::where('id',$id)
|
||||
->field('id,title,xueqi,category,bfdate,enddate,zuzhi')
|
||||
// ->with('kaoshisubject')
|
||||
->append(['nianjiids','manfenedit'])
|
||||
->find();
|
||||
|
||||
$list = $list->append(['nianjiids','manfenedit']);
|
||||
// 设置页面标题
|
||||
$list['set'] = array(
|
||||
'webtitle'=>'编辑考试',
|
||||
'butname'=>'修改',
|
||||
'formpost'=>'PUT',
|
||||
'url'=>'/kaoshi/'.$id,
|
||||
);
|
||||
|
||||
|
||||
// 模板赋值
|
||||
$this->assign('list',$list);
|
||||
|
||||
//渲染模板
|
||||
return $this->fetch();
|
||||
// 渲染
|
||||
return $this->fetch('create');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,49 @@ use app\common\model\Base;
|
||||
|
||||
class Kaoshi extends Base
|
||||
{
|
||||
// 查询所有单位
|
||||
public function search($src)
|
||||
{
|
||||
// 整理变量
|
||||
// $xingzhi = $src['xingzhi'];
|
||||
// $searchval = $src['searchval'];
|
||||
|
||||
// 查询数据
|
||||
$data = $this
|
||||
->order([$src['field'] =>$src['order']])
|
||||
// ->when(count($xingzhi)>0,function($query) use($xingzhi){
|
||||
// $query->where('xingzhi','in',$xingzhi);
|
||||
// })
|
||||
// ->when(strlen($searchval)>0,function($query) use($searchval){
|
||||
// $query->where('title|jiancheng','like','%'.$searchval.'%');
|
||||
// })
|
||||
// ->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);
|
||||
// }
|
||||
// ]
|
||||
// )
|
||||
->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 开始时间修改器
|
||||
public function setBfdateAttr($value)
|
||||
{
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,6 @@ class Student extends Base
|
||||
->when(count($school)>0,function($query) use($school){
|
||||
$query->where('school','in',$school);
|
||||
})
|
||||
// ->when(count($banji)>0,function($query) use($banji){
|
||||
// $query->where('banji','in',$banji);
|
||||
// })
|
||||
->when(strlen($searchval)>0,function($query) use($searchval){
|
||||
$query->where('xingming','like','%'.$searchval.'%')->field('id');
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user