/**
  * Creates a new UsersPlayers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new UsersPlayers();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function actionRegisterPlayers()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $userId = Yii::$app->user->id;
         $trainId = Yii::$app->request->post('train_id');
         $modelInfo = new UsersPlayers();
         $infoParams['UsersPlayers']['user_id'] = $userId;
         if (empty($infoParams['UsersPlayers']['end_time'])) {
             $infoParams['UsersPlayers']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         if ($modelInfo->load($infoInfo) && $modelInfo->save()) {
             return $this->redirect(['/user/register-players', 'train_id' => $trainId]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE));
         }
     } elseif (Yii::$app->request->get('id')) {
         if (UsersPlayers::deleteAll(['id' => Yii::$app->request->get('id')])) {
             return $this->redirect(['/user/register-players', 'train_id' => Yii::$app->request->get('train_id')]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:删除失败!');
         }
     } else {
         $userId = Yii::$app->user->id;
         $model = UsersPlayers::findAll(['user_id' => $userId]);
         $trainId = Yii::$app->request->get('train_id');
         $trainName = Train::getOneTrainNameById($trainId);
         return $this->render('register-players', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]);
     }
 }
 public function actionUserPlayers()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $infoParams['UsersPlayers']['user_id'] = Yii::$app->user->id;
         if (empty($infoParams['UsersPlayers']['end_time'])) {
             $infoParams['UsersPlayers']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         $model = new UsersPlayers();
         if ($model->load($infoInfo) && $model->save()) {
             return $this->redirect('/user-center/user-info');
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
         }
     } else {
         if (Yii::$app->request->get('id')) {
             UsersPlayers::findOne(Yii::$app->request->get('id'))->delete();
             return $this->redirect('/user-center/user-info');
         } else {
             $model = UsersPlayers::findAll(['user_id' => Yii::$app->user->id]);
             $levelName = Level::getOneLevelNameById(Yii::$app->user->identity->level_id);
             $photo = UsersInfo::getPhotoByUserId(\Yii::$app->user->id);
             $messageCount = MessagesUsers::getCountByUserIdAndType(\Yii::$app->user->id);
             $currentTrain = TrainUsers::getTrainByUserId(Yii::$app->user->id);
             $data = ['levelName' => $levelName, 'currentTrain' => $currentTrain, 'photo' => $photo, 'messageCount' => $messageCount];
             return $this->render('user-players', ['data' => $data, 'model' => $model]);
         }
     }
 }