/**
  * Finds the UsersVocational model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UsersVocational the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UsersVocational::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionUserVocational()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $infoParams['UsersVocational']['user_id'] = Yii::$app->user->id;
         if (empty($infoParams['UsersVocational']['end_time'])) {
             $infoParams['UsersVocational']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         $model = new UsersVocational();
         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')) {
             UsersVocational::findOne(Yii::$app->request->get('id'))->delete();
             return $this->redirect('/user-center/user-info');
         } else {
             $model = UsersVocational::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-vocational', ['data' => $data, 'model' => $model]);
         }
     }
 }