/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Manager::find(); // add conditions that should always apply here $query = $query->innerJoinWith('user'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['user_id', 'status', 'created_at', 'updated_at', 'username' => ['asc' => ['wy_user.username' => SORT_ASC], 'desc' => ['wy_user.username' => SORT_DESC], 'label' => 'Username'], 'userStatus' => ['asc' => ['wy_user.status' => SORT_ASC], 'desc' => ['wy_user.status' => SORT_DESC], 'label' => 'User Status']]]); $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; } if ($this->status == '合法') { $this->status = 1; } elseif ($this->status == '冻结') { $this->status = 2; } if ($this->userStatus == '合法') { $this->userStatus = 1; } elseif ($this->userStatus == '冻结') { $this->userStatus = 2; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'wy_manager.status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'wy_user.status' => $this->userStatus]); $query->andFilterWhere(['like', 'wy_user.username', $this->username]); return $dataProvider; }
/** * @return bool */ public function isManager() { $model = User::find()->where(['username' => $this->username])->andWhere(['status' => 1])->one(); $manager = Manager::find()->where(['user_id' => $model->id, 'status' => 1])->one(); if ($manager) { return true; } return false; }
/** * 列表 * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Manager::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }