当前位置:首页>>问题

fastadmin框架筛选在buildparams之前自定义筛选条件

error_reporting(E_ERROR);//第一步:屏蔽掉错误提示$mywhere=[];$a1=input('get.filter');//第二步:获取传入参数,拆解参数,查询参数名对应id$a2=json_decode($a1,true);if($a2['entered']){//判断经纪人参数是否存在$memb

admin
error_reporting (E_ERROR);	//第一步:屏蔽掉错误提示
		
		$mywhere = [];
		$a1 = input('get.filter');	//第二步:获取传入参数,拆解参数,查询参数名对应id
		$a2 = json_decode($a1,true);
		
		if($a2['entered']){		//判断经纪人参数是否存在
			$member2 = Db::name("member")->where("name",trim($a2['entered']))->find();
			if($member2){
				$a3 = $member2['id'];	//用经纪人的name获取经纪人的id
				//$mywhere1 = ['entered'=>$a3];
				//array_push($mywhere,$mywhere1);
			}
		}
		if($a2['area']){		
			$area2 = Db::name("areas")->where("name",trim($a2['area']))->find();
			if($area2){
				$a4 = $area2['id'];	
				//$mywhere2 = ['area'=>$a4];
				//array_push($mywhere,$mywhere2);
			}
		}
		if($a2['nationality']){		
			$nationality2 = Db::name("nationality")->where("name",trim($a2['nationality']))->find();
			if($nationality2){
				$a5 = $nationality2['id'];	
				//$mywhere3 = ['nationality'=>$a5];
				//array_push($mywhere,$mywhere3);
			}
		}
		
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage,则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
			
			//第三步:将传入参数里面的的经纪人、地区、国籍等参数消除掉
			$filter2 = json_decode($this->request->get("filter", ''), true);
			if (isset($filter2['entered'])) {
				unset($filter2['entered']);
			}
			if (isset($filter2['area'])) {
				unset($filter2['area']);
			}
			if (isset($filter2['nationality'])) {
				unset($filter2['nationality']);
			}

			//第四步:消除掉后,再重新设置传入参数,放进 $where 里面,连同自定义参数一起组合查询
			$this->request->get(['filter' => json_encode($filter2, true)]);
			//$this->request->get(['op' => json_encode($op, true)]);

			list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->where($where)
				->where($a2['entered']?['entered'=>$a3]:'1=1')//自定义参数
				->where($a2['area']?['area'=>$a4]:'1=1')//自定义参数
				->where($a2['nationality']?['nationality'=>$a5]:'1=1')//自定义参数
                ->order($sort, $order)
                ->paginate($limit);



返回顶部