eyoucms筛选加多条件搜索
后端代码如下:
public function product_search(){
//接收参数
//类别
$category = input('ProType');
//NetSelect1
$netselect1 = input('NetSelect1');
//NetSelect2
$netselect2 = input('NetSelect2');
//NetSelect3
$netselect3 = input('NetSelect3');
//Proname
$proname = input('Proname');
//组装条件
//获取所有符合条件产品
$map = [];
if($category){
$map['b.category'] = ['like',"%".$category.'%'];
}
if($netselect1){
$map['b.netselect1'] = ['like',"%".$netselect1.'%'];
}
if($netselect2){
$map['b.netselect2'] = ['like',"%".$netselect2.'%'];
}
if($netselect3){
$map['b.netselect3'] = ['like',"%".$netselect3.'%'];
}
$where = [
'a.status'=>1,
'a.is_del'=>0,
'a.channel'=>2
];
if($proname){
$where['a.title'] = ['like',"%".$proname.'%'];
}
$list = array();
//分页查询
$count = Db::name('archives')->alias('a')->join('__PRODUCT_CONTENT__ b', 'b.aid = a.aid', 'LEFT')->where($where)->where($map)->count();
$Page = new Page($count, config('paginate.list_rows'));
$field = !empty($field) ? $field : 'b.*, a.*, a.aid as aid';
$list = Db::name('archives')->field($field)
->alias('a')
->join('__PRODUCT_CONTENT__ b', 'b.aid = a.aid', 'LEFT')
->where($map)
->where($where)
->limit($Page->firstRow.','.$Page->listRows)
->select();
$show = $Page->show();
$this->assign('page', $show);
$this->assign('list', $list);
$this->assign('pager', $Page);
$viewfile = 'product_search';
return $this->fetch(":{$viewfile}");
}