Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getManager()
 {
     if ($this->_manager === null) {
         $this->_manager = Manager::findByUsername($this->username);
     }
     return $this->_manager;
 }
 /**
  * @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 [type] [description]
  */
 public function actionMember($id)
 {
     $this->layout = false;
     $auth = Yii::$app->authManager;
     $manager_list = Manager::findAll(['status' => Manager::STATUS_ACTIVE]);
     $model = $this->findModel($id);
     if (Yii::$app->request->post()) {
         $save_arr = array();
         $member_ids = Yii::$app->request->post('mg_id');
         if ($member_ids) {
             foreach ($member_ids as $mg_id) {
                 $save_arr[] = $mg_id;
                 if (!$auth->checkAccess($mg_id, $model->name)) {
                     $auth->assign($model, $mg_id);
                 }
             }
         }
         foreach ($manager_list as $key => $row) {
             if (!in_array($row->id, $save_arr)) {
                 $auth->revoke($model, $row->id);
             }
         }
         return json_encode(['status' => 1]);
     }
     $is_have_arr = [];
     foreach ($manager_list as $key => $row) {
         $is_have_arr[$row->id] = $auth->checkAccess($row->id, $model->name);
     }
     return $this->render('member', array('model' => $model, 'manager_list' => $manager_list, 'is_have_arr' => $is_have_arr, 'num' => count($manager_list)));
 }
Beispiel #5
0
 /**
  * @param $id
  * @return $this
  */
 public function getModel($id)
 {
     $manager = Manager::findOne($id);
     $this->id = $id;
     $this->user_id = $manager->user_id;
     $this->username = $manager->getUsername($this->user_id);
     $this->status = $manager->status;
     return $this;
 }
 /**
  * Finds the Manager model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Manager the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Manager::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }