public function actionApply()
 {
     $activityId = Yii::$app->request->get('id');
     $activityInfo = Activity::findOne(['id' => $activityId]);
     if ($activityInfo['status'] != Activity::BEGIN_SIGN_UP) {
         throw new ServerErrorHttpException('该活动的状态不是开始报名,谢谢。');
     }
     if (Yii::$app->user->isGuest) {
         return $this->redirect(['/user/register', 'activity_id' => $activityId]);
     } else {
         $userId = Yii::$app->user->id;
         $CredentialsNumber = UsersInfo::getCredentialsNumberByUserId($userId);
         if (Yii::$app->user->identity->status != '1') {
             throw new ServerErrorHttpException('系统错误,原因:您目前的状态是未审核,不能报名课程,谢谢。');
         }
         $activityLevelInfo = Level::findOne(['id' => $activityInfo['level_id']]);
         if ($activityLevelInfo['order'] != Yii::$app->user->identity->level_order + 1) {
             throw new ServerErrorHttpException('系统错误,原因:您目前没有权限报名该级别下的课程,谢谢。');
         }
         //检查用户参与的课程,状态不是取消的都算是已经参与了报名
         $isExist = ActivityUsers::getUserIsExistActivityStatus($userId, $activityInfo['level_id']);
         if (!empty($isExist)) {
             throw new ServerErrorHttpException('系统错误,原因:您已经参与了该级别下的培训课程,请耐心等待培训结果,谢谢。');
         }
         //报名成功,给出用户的序号
         $activityUsersOrder = ActivityUsers::getActivityUsersOrder($userId, $activityId);
         if (empty($activityUsersOrder)) {
             $activityUsersOrder = 1;
         }
         $transaction = Yii::$app->db->beginTransaction();
         $data = ['activity_id' => $activityId, 'user_id' => $userId, 'status' => ActivityUsers::APPROVED, 'practice_score' => 0, 'theory_score' => 0, 'rule_score' => 0, 'level_id' => $activityInfo['level_id'], 'orders' => $activityUsersOrder];
         $model = new ActivityUsers();
         $model->setAttributes($data);
         if ($model->save()) {
             $activityUserId = $model->id;
             $activityUser = ActivityUsers::findOne(['id' => $activityUserId]);
             $activityName = Activity::getOneActivityNameById($activityUser['activity_id']);
             $data = ['orders' => $activityUser['orders'], 'activityName' => $activityName];
             //新增一条用户和级别对应的信息
             $userLevelModel = new UsersLevel();
             $userLevelModel->user_id = $userId;
             $userLevelModel->activity_id = $activityId;
             $userLevelModel->level_id = $activityInfo['level_id'];
             $userLevelModel->credentials_number = $CredentialsNumber;
             if (!$userLevelModel->save()) {
                 $transaction->rollBack();
                 throw new ServerErrorHttpException('更新状态错误,原因:' . json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!');
             } else {
                 $transaction->commit();
             }
             return $this->render('/activity/apply-success', ['data' => $data]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
         }
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UsersInfo::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(['id' => $this->id, 'user_id' => $this->user_id, 'sex' => $this->sex, 'birthday' => $this->birthday, 'credentials_type' => $this->credentials_type, 'height' => $this->height, 'weight' => $this->weight, 'disease_history' => $this->disease_history, 'clothes_size' => $this->clothes_size, 't_shirt_size' => $this->t_shirt_size, 'shorts_size' => $this->shorts_size, 'language' => $this->language, 'spoken_language' => $this->spoken_language, 'write_language' => $this->write_language]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'credentials_number', $this->credentials_number])->andFilterWhere(['like', 'account_location', $this->account_location])->andFilterWhere(['like', 'telephone', $this->telephone])->andFilterWhere(['like', 'contact_address', $this->contact_address])->andFilterWhere(['like', 'contact_postcode', $this->contact_postcode])->andFilterWhere(['like', 'company_name', $this->company_name])->andFilterWhere(['like', 'company_address', $this->company_address])->andFilterWhere(['like', 'company_postcode', $this->company_postcode])->andFilterWhere(['like', 'company_contact_phone', $this->company_contact_phone])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'credentials_photo', $this->credentials_photo]);
     return $dataProvider;
 }
 /**
  * Creates a new Users model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Users();
     if (Yii::$app->request->isPost) {
         $postInfo = Yii::$app->request->post();
         if (!empty($postInfo)) {
             $postInfo['Users']['password'] = md5('111111');
             if ($model->load($postInfo) && $model->save()) {
                 $userInfo = ['name' => $model->username, 'name' => $model->name, 'name' => $model->name];
                 UsersInfo::addInfo();
                 Yii::$app->getSession()->setFlash('success', '添加成功!');
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 throw new ServerErrorHttpException('添加用户失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
                 return $this->redirect(['create']);
             }
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #4
0
    <div class="zstop_box">
        <span class="fl zsjl_name"><?php 
echo \app\models\Users::getOneUserNameById($data['user_id']);
?>
 北京市 <?php 
echo \app\models\Level::getOneLevelNameById($data['level_id'] + 1);
?>
 教练员证书</span>
        <p class="fr"><a href="javascript:window.print();" class="pre">打印证书</a><a href="javascript:window.close();" class="close">关闭</a></p>
    </div>
</div>
<div class="content_box">
    <div class="zs_img">
        <div class="zsBox">
            <p class="pimg80"><img src="/upload/images/users_info/photo/<?php 
echo \app\models\UsersInfo::getPhotoByUserId($data['user_id']);
?>
" /></p>
            <p class="puName">北京<?php 
echo \app\models\Level::getOneLevelNameById($data['level_id'] + 1);
?>
足球教练证书</p>
            <p class="pName"><?php 
echo \app\models\Users::getOneUserNameById($data['user_id']);
?>
</p>
            <p class="psucessBox">成功完成"北京市<?php 
echo \app\models\Level::getOneLevelNameById($data['level_id'] + 1);
?>
足球教练员"全部培训课程<span>日期:<?php 
echo date('Y年m月d日', strtotime($data['end_date']) - 3600 * 24 * 365);
 public static function getAllUsersByActivityId($activityId)
 {
     $result = Yii::$app->db->createCommand('SELECT au.activity_id,u.name,u.photo,u.sex,au.user_id,au.score_appraise FROM  ' . self::tableName() . ' tu LEFT JOIN ' . UsersInfo::tableName() . ' u ON au.user_id = u.id WHERE au.activity_id=:activity_id', [':activity_id' => $activityId])->queryAll();
     return $result;
 }
Exemple #6
0
 public static function getCountUserByLevelId($levelId, $count)
 {
     $sql = "SELECT u.level_id,ui.photo,ui.name,ui.birthday,u.id FROM " . self::tableName() . " u LEFT JOIN " . UsersInfo::tableName() . " ui ON u.id = ui.user_id WHERE u.level_id='" . $levelId . "' LIMIT 0," . $count;
     $result = Yii::$app->db->createCommand($sql)->queryAll();
     return $result;
 }
 /**
  * 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]);
     }
 }
 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');
 }
 /**
  * @param $trainId.
  */
 public static function getAllUsersByTrainId($trainId)
 {
     $result = Yii::$app->db->createCommand('SELECT tu.train_id,u.name,u.photo,u.sex,tu.user_id,tu.score_appraise FROM  ' . self::tableName() . ' tu LEFT JOIN ' . UsersInfo::tableName() . ' u ON tu.user_id = u.user_id WHERE tu.train_id=:train_id', [':train_id' => $trainId])->queryAll();
     return $result;
 }
Exemple #11
0
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\UsersLevel */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => '用户晋升管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="users-level-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('删除', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'train_id', 'value' => \app\models\Train::getOneTrainNameById($model->train_id)], ['attribute' => 'user_id', 'value' => \app\models\Users::getOneUserNameById($model->user_id)], ['attribute' => 'status', 'value' => \app\models\UsersLevel::getStatusName($model->status)], 'certificate_number', ['attribute' => 'end_date', 'value' => date('Y-m-d', strtotime($model->end_date))], 'district', 'receive_address', 'postcode', ['attribute' => 'photo', 'format' => 'html', 'value' => "<img src='/upload/images/users_info/photo/" . \app\models\UsersInfo::getPhotoByUserId($model->user_id) . "' width=157 height='210'>"], ['attribute' => 'credentials_photo', 'format' => 'html', 'value' => "<img src='/upload/images/users_level/credentials_photo/" . $model->credentials_photo . "' width=500 height='210'>"], ['attribute' => 'level_id', 'value' => \app\models\Level::getOneLevelNameById($model->level_id + 1)], 'create_time', 'update_time', 'update_user']]);
?>

</div>
 public static function getUserLevelAndScoreByUserIdLevelId($userId, $levelId)
 {
     $sql = "SELECT ul.*,tu.practice_score,tu.theory_score,tu.rule_score,tu.score_appraise,ui.photo,ui.account_location,ui.contact_address,ui.contact_postcode,ul.photo as user_level_photo FROM  " . self::tableName() . "  ul LEFT JOIN " . TrainUsers::tableName() . " tu ON ul.train_id = tu.train_id AND ul.user_id = tu.user_id  LEFT JOIN " . UsersInfo::tableName() . " ui ON ui.user_id = ul.user_id WHERE ul.user_id=:user_id AND ul.level_id = :level_id AND ul.status in (" . UsersLevel::REG . "," . UsersLevel::PAY . "," . UsersLevel::SEND_CARD . "," . UsersLevel::LEVEL_UP . ") AND tu.status = " . TrainUsers::PASS;
     $result = Yii::$app->db->createCommand($sql, [':user_id' => $userId, ':level_id' => $levelId])->queryOne();
     return $result;
 }
 public function actionIndex()
 {
     $keyword = Yii::$app->request->get('keyword', '');
     $levelId = Yii::$app->request->get('level_id', '');
     $district = Yii::$app->request->get('district', '');
     $sex = Yii::$app->request->get('sex', '');
     if (empty($keyword) && empty($levelId) && empty($district) && empty($sex)) {
         throw new ServerErrorHttpException('шп╖ш╛УхЕехЕ│щФохнЧя╝Б');
     }
     $levelList = Level::getAll();
     $districtList = Train::$districtList;
     $userName = '';
     $certificateNumber = '';
     $credentialsNumber = '';
     if (preg_match("/^[- ]+\$/", $keyword)) {
         $userName = $keyword;
     } else {
         if (strlen($keyword) > 10) {
             $credentialsNumber = $keyword;
         } else {
             $certificateNumber = $keyword;
         }
     }
     $order = Yii::$app->request->get('order');
     $query = Users::find()->from(Users::tableName() . ' u')->select("u.*,ui.account_location,ui.sex")->leftJoin(UsersLevel::tableName() . ' ul', ' u.id = ul.user_id')->leftJoin(UsersInfo::tableName() . ' ui', ' u.id = ui.user_id');
     if (!empty($order)) {
         $query->orderBy($order);
     }
     $query->andFilterWhere(['!=', 'u.level_id', '1']);
     if (!empty($levelId)) {
         $query->andFilterWhere(['u.level_id' => $levelId]);
     }
     if (!empty($district)) {
         $query->andFilterWhere(['account_location' => $district]);
     }
     if (!empty($sex)) {
         $query->andFilterWhere(['sex' => $sex]);
     }
     if (!empty($userName)) {
         $query->andFilterWhere(['like', 'name', $userName]);
     }
     if (!empty($certificateNumber)) {
         $query->andFilterWhere(['like', 'certificate_number', $certificateNumber]);
     }
     if (!empty($credentialsNumber)) {
         $query->andFilterWhere(['like', 'credentials_number', $credentialsNumber]);
     }
     $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => 15]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     $result = [];
     if (!empty($models)) {
         foreach ($models as $key => $val) {
             $result[$key]['name'] = $val['username'];
             $result[$key]['photo'] = UsersInfo::getPhotoByUserId($val['id']);
             $result[$key]['birthday'] = UsersInfo::getBirthdayByUserId($val['id']);
             $result[$key]['level_id'] = $val['level_id'];
             $result[$key]['user_id'] = $val['id'];
         }
     }
     $data = ['models' => $result, 'pages' => $pages, 'count' => $query->count(), 'levelList' => $levelList, 'districtList' => $districtList, 'keyword' => empty($keyword) ? '' : $keyword, 'levelId' => empty($levelId) ? '' : $levelId, 'district' => empty($district) ? '' : $district, 'sex' => empty($sex) ? '' : $sex];
     return $this->render('index', ['data' => $data]);
 }
 /**
  * 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.');
     }
 }