//控制器
public function actionYulist(){
$start = yii::$app->request->get('start');//接收要搜索的数据
$end = yii::$app->request->get('end');//接收要搜索的数据
$where = "1=1";//拼接条件
if(!empty($start)&&!empty($end)){//拼接条件
$where .= " and `begintime`>='$start' and `begintime`<='$end'";
}
if(!empty($start)){//拼接条件
$where .= " and `begintime`>='$start'";
}
if(!empty($end)){//拼接条件
$where .= " and `endtime`<='$end'";
}
$yuList = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where")->queryAll();
$count = count($yuList);//取整
$pagesize = 2;//每页显示条数
$pagesum=ceil($count/$pagesize);//向上取整
$page=isset($_GET['page'])?$_GET['page']:1;//页数的取值
$start=($page-1)*$pagesize;//数据的偏移量
$data['data'] = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where limit $start,$pagesize")->queryAll();//查询数据
$data['start'] = $start;
$data['end'] = $end;
$pre=$page-1 < 1 ? 1 : $page-1;//上一页
$next = $page+1>$pagesum ? $pagesum:$page+1;//下一页
$data['str']="<a href='javascript:;' class='p' val='1'>首页</a> <a href='javascript:;' val=".$pre." class='p'>上一页</a> <a href='javascript:;' val=".$next." class='p'>下一页</a>";//页数
if(yii::$app->request->isAjax){
echo json_encode($data);
}else{
return $this->render('listPage',['str'=>$data['str'],'data'=>$data['data']]);
}
}
//前台ajax
//下一页
$(document).on('click','.p', function () {
var start = $(".start").val();
if(start==''){
start='';
}
var end = $(".end").val();
if(end==''){
end='';
}
p = $(this).attr('val');
var str="";
$.ajax({
type: "GET",
url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
data: {page:p,start:start,end:end},
dataType : "json",//数据类型为jsonp
success: function(msg){
str+="<table border='1' id='box'>"+
"<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
for(var i in msg['data']){
str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
}
$("#box").html(str);
$(".page_").html(msg['str']);
$(".start").html(msg['start']);
$(".end").html(msg['end']);
}
});
});
//搜索
$(".but").click(function () {
var p=1;
var start = $(".start").val();
if(start==''){
start='';
}
var end = $(".end").val();
if(end==''){
end='';
}
var str="";
$.ajax({
type: "GET",
url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
data: {start:start,end:end,page:p},
dataType : "json",//数据类型为jsonp
success: function(msg){
str+="<table border='1' id='box'>"+
"<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
for(var i in msg['data']){
str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
}
$("#box").html(str);
$(".page_").html(msg['str']);
$(".start").html(msg['start']);
$(".end").html(msg['end']);
}
});
});