/** * @return array * handel search conditions */ function handel_search() { $query = PostJob::find(); if ($_REQUEST['st']) { $_REQUEST['service_type'] ? $arr['service_type'] = $_REQUEST['service_type'] : ''; } switch ($_REQUEST['st']) { case 1: $_REQUEST['search_input'] ? $arr['name'] = $_REQUEST['search_input'] : ''; break; case 2: $_REQUEST['search_input'] ? $arr['mobile'] = $_REQUEST['search_input'] : ''; break; default: } $arr['job_status'] = 0; $query->where($arr); $raw_district = Yii::$app->user->identity->district; if (strlen($raw_district) <= 3) { $query->andWhere(['district' => $raw_district]); } else { $dists = explode(',', $raw_district); $temp_arr[] = 'or'; foreach ($dists as $v) { //$query->orWhere(['district'=>$v]); $temp_arr[] = 'district="' . $v . '"'; } $query->andWhere($temp_arr); } return $query; }
/** * @return array * handel search conditions */ function handel_search() { $query = Schedule::find(); switch ($_REQUEST['st']) { case 1: $_REQUEST['search_input'] ? $arr['employee_id'] = Employee::findOne(['name' => $_REQUEST['search_input']])->id : ''; //search employee name break; case 2: //($_REQUEST['search_input'])?$arr['mobile']=$_REQUEST['search_input']:''; $_REQUEST['search_input'] ? $condition['mobile'] = $_REQUEST['search_input'] : ''; break; default: } $arr['agency_id'] = Yii::$app->user->identity->id; $query->where($arr); if ($_REQUEST['st']) { //($_REQUEST['status'])?$arr['job_id']=PostJob::findOne(['job_status'=>$_REQUEST['status']])->id:''; //search job status // ($_REQUEST['service_type'])?$arr['job_id']=$_REQUEST['service_type']:''; //search service_type $_REQUEST['status'] ? $condition['job_status'] = $_REQUEST['status'] : ''; $_REQUEST['service_type'] ? $condition['service_type'] = $_REQUEST['service_type'] : ''; $res = PostJob::find()->where($condition)->all(); if (count($res) > 0) { foreach ($res as $k => $v) { $ids[] = $v->id; } $query->andWhere(['in', 'job_id', $ids]); } else { $query->andWhere(['job_id' => '-1']); } } return $query; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostJob::find(); $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->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'payment_id' => $this->payment_id, 'create_time' => $this->create_time, 'beginning_date' => $this->beginning_date, 'end_date' => $this->end_date, 'worker' => $this->worker, 'price_range' => $this->price_range, 'number_family' => $this->number_family]); $query->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'topic', $this->topic])->andFilterWhere(['like', 'job_status', $this->job_status])->andFilterWhere(['like', 'service_type', $this->service_type])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'view_time', $this->view_time])->andFilterWhere(['like', 'week', $this->week])->andFilterWhere(['like', 'period', $this->period])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province])->andFilterWhere(['like', 'district', $this->district])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'term_period', $this->term_period])->andFilterWhere(['like', 'cleaning_type', $this->cleaning_type])->andFilterWhere(['like', 'cleaning_pet_type', $this->cleaning_pet_type])->andFilterWhere(['like', 'work_times', $this->work_times])->andFilterWhere(['like', 'workingdays_perweek', $this->workingdays_perweek])->andFilterWhere(['like', 'cleaning_time_estimate', $this->cleaning_time_estimate])->andFilterWhere(['like', 'estimated_date', $this->estimated_date])->andFilterWhere(['like', 'cleaning_size', $this->cleaning_size])->andFilterWhere(['like', 'beginning_time', $this->beginning_time])->andFilterWhere(['like', 'end_time', $this->end_time])->andFilterWhere(['like', 'stay_type', $this->stay_type])->andFilterWhere(['like', 'sex_type', $this->sex_type])->andFilterWhere(['like', 'cure_type', $this->cure_type])->andFilterWhere(['like', 'baby_age_type', $this->baby_age_type])->andFilterWhere(['like', 'food_type', $this->food_type])->andFilterWhere(['like', 'baby_type', $this->baby_type])->andFilterWhere(['like', 'longitude', $this->longitude])->andFilterWhere(['like', 'latitude', $this->latitude]); return $dataProvider; }