joinWith('userInfo') ->joinWith('companyInfo'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if(!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andWhere([ 'is_customer' => 1, ]); if($this->type == 2) { $query->andWhere([ 'not', [ 'company_info.company_info_id' => NULL ], ]); $query->andWhere([ 'type' => 2, ]); } else { $query->andWhere([ 'type' => 1, ]); } if($this->online == 1) { $query->andWhere([ '>=', 'user_info.date_visit', date('Y-m-d H:i:s.u', time() - 1800), ]); } $query->andFilterWhere([ 'like', 'user_info.city', $this->city, ]); return $dataProvider; } }