Пример #1
0
 /**
  * Displays a single Users model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $modelInfo = UsersInfo::findOne(['user_id' => $id]);
     $modelEducation = UsersEducation::findAll(['user_id' => $id]);
     $modelTrain = UsersTrain::findAll(['user_id' => $id]);
     $modelVocational = UsersVocational::findAll(['user_id' => $id]);
     $modelPlayers = UsersPlayers::findAll(['user_id' => $id]);
     return $this->render('view', ['model' => $this->findModel($id), 'modelInfo' => $modelInfo, 'modelEducation' => $modelEducation, 'modelTrain' => $modelTrain, 'modelVocational' => $modelVocational, 'modelPlayers' => $modelPlayers]);
 }
 /**
  * Updates an existing UsersLevel model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         if ($infoParams['UsersLevel']['status'] == UsersLevel::SEND_CARD) {
             $infoParams['UsersLevel']['end_date'] = date('Y-m-d', time() + 3600 * 24 * 365);
         }
         $userLevelInfo = $infoParams;
         if ($model->load($userLevelInfo) && $model->save()) {
             //如果状态更新为已经注册
             if ($model->status == UsersLevel::SEND_CARD) {
                 if ($model->level_id == 1) {
                     //如果是注册学员升级市级教练
                     UsersLevel::updateAll(['status' => UsersLevel::LEVEL_UP], ['user_id' => $model->user_id, 'level_id' => $model->level_id]);
                     $userInfo = UsersInfo::findOne(['user_id' => $model->user_id]);
                     //新增一条用户和级别对应的信息
                     $userLevelModel = new UsersLevel();
                     $userLevelModel->user_id = $model->user_id;
                     $userLevelModel->level_id = $model->level_id + 1;
                     $userLevelModel->credentials_number = $userInfo['credentials_number'];
                     $userLevelModel->district = $userInfo['account_location'];
                     $userLevelModel->receive_address = $userInfo['contact_address'];
                     $userLevelModel->postcode = $userInfo['contact_postcode'];
                     $userLevelModel->status = UsersLevel::NO_TRAIN;
                     if (!$userLevelModel->save()) {
                         throw new ServerErrorHttpException(json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!');
                     } else {
                         Users::updateAll(['level_id' => $model->level_id + 1, 'level_order' => $model->level_id + 1], ['id' => $model->user_id]);
                     }
                 }
                 $usersTrainInfo = UsersLevel::getUserTrainInfo($model->id);
                 $teacherInfo = Teachers::findOne($usersTrainInfo['teachers_id']);
                 $usersTrainModel = new UsersTrain();
                 $usersTrain['UsersTrain']['user_id'] = $usersTrainInfo['user_id'];
                 $usersTrain['UsersTrain']['credentials_number'] = $usersTrainInfo['certificate_number'];
                 $usersTrain['UsersTrain']['begin_time'] = $usersTrainInfo['begin_time'];
                 $usersTrain['UsersTrain']['end_time'] = $usersTrainInfo['end_time'];
                 $usersTrain['UsersTrain']['level'] = Level::getOneLevelNameById($usersTrainInfo['level_id']);
                 $usersTrain['UsersTrain']['address'] = $usersTrainInfo['address'];
                 $usersTrain['UsersTrain']['witness'] = $teacherInfo['name'];
                 $usersTrain['UsersTrain']['witness_phone'] = $teacherInfo['phone'];
                 $usersTrain['UsersTrain']['description'] = '通过培训课程' . $usersTrainInfo['content'];
                 if ($usersTrainModel->load($usersTrain) && $usersTrainModel->save()) {
                     $content = "很高兴的通知您,您已完成" . Level::getOneLevelNameById($model->level_id) . "级教练员的注册,注册时效为1年,您现在可以正式开展教练员工作。【教练系统】";
                     $userInfo = Users::findOne($model->user_id);
                     $result = $this->sendMessage($content, Messages::REGISTER_SUCCESS, $model->user_id, $userInfo['mobile_phone'], '1');
                     if ($result != '0') {
                         throw new ServerErrorHttpException($result);
                     } else {
                         return $this->redirect(['view', 'id' => $model->id]);
                     }
                 } else {
                     throw new ServerErrorHttpException(json_encode($usersTrainModel->errors, JSON_UNESCAPED_UNICODE));
                 }
             }
         }
     } else {
         $photo = UsersInfo::getPhotoByUserId($model->user_id);
         return $this->render('update', ['model' => $model, 'photo' => $photo]);
     }
 }
Пример #3
0
 public function actionView()
 {
     $id = Yii::$app->request->get('id');
     $model = Users::findOne($id);
     $modelInfo = UsersInfo::findOne(['user_id' => $id]);
     $modelUserLevel = UsersLevel::findOne(['user_id' => $model['id'], 'level_id' => $model['level_id']]);
     $trainWind = News::getImgRecommendNewsByCategory(11, 12);
     return $this->render('view', ['data' => $modelInfo, 'userModel' => $model, 'trainWind' => $trainWind, 'modelUserLevel' => $modelUserLevel]);
 }
 public function actionLevelUp()
 {
     $levelInfo = Level::findOne(['id' => Yii::$app->user->identity->level_id + 1]);
     $usersLevel = UsersLevel::findOne(['user_id' => Yii::$app->user->id, 'level_id' => Yii::$app->user->identity->level_id]);
     $usersLevelStatusCurrent = $usersLevel['status'];
     if ($usersLevelStatusCurrent != UsersLevel::SEND_CARD) {
         throw new ServerErrorHttpException('当前注册状态不符合!');
     }
     $loginDuration = Users::getLoginDuration(Yii::$app->user->id);
     $loginDurationDiff = $levelInfo['login_duration'] - $loginDuration;
     if ($loginDurationDiff > 0) {
         throw new ServerErrorHttpException('当前注册时长不符合!');
     }
     $scoreDiff = $levelInfo['score'] - Yii::$app->user->identity->score;
     if ($scoreDiff > 0) {
         throw new ServerErrorHttpException('当前一般活动积分不符合!');
     }
     $creditDiff = $levelInfo['credit'] - Yii::$app->user->identity->credit;
     if ($creditDiff > 0) {
         throw new ServerErrorHttpException('当前公益活动积分不符合!');
     }
     $transaction = Yii::$app->db->beginTransaction();
     UsersLevel::updateAll(['status' => UsersLevel::LEVEL_UP], ['user_id' => Yii::$app->user->id, 'level_id' => Yii::$app->user->identity->level_id]);
     $userInfo = UsersInfo::findOne(['user_id' => Yii::$app->user->id]);
     //新增一条用户和级别对应的信息
     $userLevelModel = new UsersLevel();
     $userLevelModel->user_id = Yii::$app->user->id;
     $userLevelModel->level_id = Yii::$app->user->identity->level_id + 1;
     $userLevelModel->credentials_number = $userInfo['credentials_number'];
     $userLevelModel->district = $userInfo['account_location'];
     $userLevelModel->receive_address = $userInfo['contact_address'];
     $userLevelModel->postcode = $userInfo['contact_postcode'];
     $userLevelModel->status = UsersLevel::NO_TRAIN;
     if (!$userLevelModel->save()) {
         $transaction->rollBack();
         throw new ServerErrorHttpException('更新状态错误,原因:' . json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!');
     } else {
         Users::updateAll(['level_id' => Yii::$app->user->identity->level_id + 1, 'level_order' => Yii::$app->user->identity->level_order + 1], ['id' => Yii::$app->user->id]);
         $transaction->commit();
     }
     return $this->redirect('/user-center/index');
 }
 /**
  * Finds the UsersInfo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UsersInfo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UsersInfo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }