TP3.2 搜索分页带参数

时间:2022-10-27 11:41:59
   //商品列表页面
    public function  index(){
        $name= I('get.name') ? I('get.name') : "";//商品名称
        $advertiser_id= I('get.advertiser_id') ? I('get.advertiser_id') : "";//广告主id
        $start_time = I('get.start_time') ? I('get.start_time') : "";
        $end_times = I('get.end_time') ? I('get.end_time') : "";
        $end_time = $end_times." 23:59:59";
        $s1 = strtotime($start_time);//开始的时间戳
        $e1 = strtotime($end_time);//结束的时间戳
        $where = [];
        if($name)
        {
            $where['ap.name'] = array('like',"%$name%");
        }
        if($advertiser_id)
        {
            $where['ap.advertiser_id'] = $advertiser_id;
        }
        if($s1 && $e1 !==''){
            $where['ap.add_time'] = array('between',array($s1,$e1));
        }
        $p_num= 2;
        $count  =  D('ApiProduct')->counts($where);// 查询满足要求的总记录数
        $Page   = new \Think\Page($count,$p_num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $page_begin= $Page->firstRow;
        //搜索条件
        $map['name'] = $name;
        $map['start_time'] =  $start_time;
        $map['end_time'] =  $end_times;
        $map['advertiser_id'] =  $advertiser_id;
        $Page->parameter = array_map('urldecode',$map);
        $show = $Page->show();// 分页显示输出
        $list = D('ApiProduct')->allDatas($where,$page_begin,$p_num);
        $wheres=[];
        $lists = D('ApiAdvertiser')->allData($wheres);//查询广告主

        $this->assign("page", $show);
        $this->assign('list',$list);
        $this->assign('name',$name);
        $this->assign('options', $lists);
        $this->assign('start', $start_time);
        $this->assign('end', $end_times);
        $this->display();

    }