コード例 #1
0
 /**
  * Finds the Invite model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Invite the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Invite::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invite::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(['invite_id' => $this->invite_id, 'invite_service_id' => $this->invite_service_id, 'invite_active' => $this->invite_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'invite_code', $this->invite_code])->andFilterWhere(['like', 'invite_desc', $this->invite_desc])->andFilterWhere(['like', 'invite_username', $this->invite_username])->andFilterWhere(['like', 'invite_mobile', $this->invite_mobile])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }
コード例 #3
0
 /**
  * undocumented function
  *
  * @return void
  * @author
  **/
 public function actionSignup()
 {
     if (Yii::$app->user->getIsGuest()) {
         $model = new Service();
         $mConfig = new Config();
         $signup_status = 'invite';
         switch ($mConfig->getConfigValue(Config::SIGNUP_STATUS)) {
             //注册状态
             case Config::SIGNUP_OPEN:
                 $signup_status = 'signup';
                 break;
             case Config::SIGNUP_INVITE:
                 $signup_status = 'invite';
                 break;
             default:
                 Yii::$app->session->setFlash('error', '已关闭注册!');
                 return $this->redirect('signin');
                 break;
         }
         $model->setScenario($signup_status);
         if ($model->load($params = Yii::$app->request->post()) && $model->save()) {
             //邀请码处理
             $serviceInfo = $params['Service'];
             if (isset($serviceInfo['invite']) && $serviceInfo['invite']) {
                 $mInvite = Invite::findOne(['invite_code' => $serviceInfo['invite'] ?: NUll]);
                 $invite['Invite'] = ['invite_service_id' => $model->service_id, 'invite_username' => $model->service_username, 'invite_mobile' => $model->service_mobile, 'invite_active' => 1, 'updated_at' => time()];
                 $mInvite->load($invite);
                 $mInvite->save();
             }
             //注册成功默认角色
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('service');
             $auth->assign($authorRole, $model->service_id);
             Yii::$app->session->setFlash('success', '您已成功注册,请登录!');
             return $this->redirect('signin');
         } else {
             return $this->render('signup', ['model' => $model, 'signup_status' => $signup_status]);
         }
     } else {
         return $this->redirect(['admin/index']);
     }
 }