/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TrainUsers::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, 'train_id' => $this->train_id, 'user_id' => $this->user_id, 'status' => $this->status, 'practice_score' => $this->practice_score, 'theory_score' => $this->theory_score, 'rule_score' => $this->rule_score, 'create_time' => $this->create_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'score_appraise', $this->score_appraise])->andFilterWhere(['like', 'attendance_appraise', $this->attendance_appraise])->andFilterWhere(['like', 'practice_comment', $this->practice_comment])->andFilterWhere(['like', 'theory_comment', $this->theory_comment])->andFilterWhere(['like', 'rule_comment', $this->rule_comment])->andFilterWhere(['like', 'total_comment', $this->total_comment])->andFilterWhere(['like', 'result_comment', $this->result_comment])->andFilterWhere(['like', 'create_user', $this->create_user])->andFilterWhere(['like', 'update_user', $this->update_user])->andFilterWhere(['<>', 'status', TrainUsers::CANCEL]);
     $query->orderBy(' id desc ');
     return $dataProvider;
 }
 public function actionIndex()
 {
     $userCount = Users::getAllCount();
     $oneNewsPic = News::getOnePicIndexNewsByCategory(2);
     $newsA = News::getIndexNewsByCategory(2, 6);
     $newsB = News::getIndexNewsByCategory(5, 12);
     $newsC = News::getIndexNewsByCategory(7, 5);
     $newsF = News::getOnePicIndexNewsByCategory(2);
     $newsRegister = TrainUsers::getAllByCount(5);
     $newContent = Pages::findOne(9);
     if (!empty($newsRegister)) {
         foreach ($newsRegister as $key => $val) {
             $newsD[$key]['title'] = Users::getOneUserNameById($val['user_id']) . "报名" . Train::getOneTrainNameById($val['train_id']) . "已被录取";
             $newsD[$key]['create_time'] = $val['create_time'];
             $newsD[$key]['user_id'] = $val['user_id'];
         }
     }
     $newsE = News::getIndexNewsByCategory(6, 5);
     $data = ['userCount' => $userCount, 'oneNewsPic' => $oneNewsPic, 'newsA' => $newsA, 'newsB' => $newsB, 'newsC' => $newsC, 'newsD' => $newsD, 'newsE' => $newsE, 'newsF' => $newsF, 'newsRegister' => $newContent];
     return $this->render('index', ['data' => $data]);
 }
 public function actionUpdateStatus()
 {
     $status = Yii::$app->request->post('status');
     $idList = Yii::$app->request->post('selection');
     if (!empty($status) && !empty($idList)) {
         foreach ($idList as $key => $val) {
             TrainUsers::updateAll(['status' => $status], ['id' => $val]);
             if ($status == TrainUsers::ENROLL) {
                 $trainUsersInfo = TrainUsers::findOne($val);
                 //录取发送系统通知
                 $content = "您好,很高兴的通知您,您报名的培训班已通过审核,请按指定日期前往培训地点缴费上课。【教练系统】";
                 $userInfo = Users::findOne(['id' => $trainUsersInfo['user_id']]);
                 $result = $this->sendMessage($content, Messages::TRAIN_SIGN_SUCCESS, $trainUsersInfo['user_id'], $userInfo['mobile_phone'], '1');
                 if ($result != '0') {
                     throw new ServerErrorHttpException('' . $result . '!');
                 }
             }
             if ($status == TrainUsers::END) {
                 $trainUsersInfo = TrainUsers::findOne($val);
                 //结束发送系统通知
                 $content = "尊敬的学员,您参与的培训课程已经结束,请等待评分,谢谢!【教练系统】";
                 $userInfo = Users::findOne(['id' => $trainUsersInfo['user_id']]);
                 $result = $this->sendMessage($content, Messages::TRAIN_END, $trainUsersInfo['user_id'], $userInfo['mobile_phone'], '1');
                 if ($result != '0') {
                     throw new ServerErrorHttpException('' . $result . '!');
                 }
             }
         }
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         throw new ServerErrorHttpException('请选择评分信息!');
     }
 }
 /**
  * Updates an existing Train 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);
     $transaction = Yii::$app->db->beginTransaction();
     if (Yii::$app->request->isPost) {
         $postInfo = Yii::$app->request->post();
         if (!empty($postInfo['Train']['begin_time'])) {
             $postInfo['Train']['code'] = date('Ymd', strtotime($postInfo['Train']['begin_time']));
         }
         if ($model->load($postInfo) && $model->save()) {
             //课程开始
             if ($model->status == Train::DOING) {
                 //获取该课程下已录取的学员
                 $trainUsers = TrainUsers::getApprovedTrainUsersByTrainId($model->id);
                 if (!empty($trainUsers)) {
                     //根据课程id,用户id更新用户状态为正在进行
                     //                        TrainUsers::updateTrainUsersStatusByTrainId(TrainUsers::DOING, $model->id);
                     foreach ($trainUsers as $key => $val) {
                         //创建考勤信息
                         for ($i = strtotime($model->begin_time); $i < strtotime($model->end_time); $i += 86400) {
                             $day = date('Y-m-d H:i:s', $i);
                             $isExist = Attendance::findOne(['train_id' => $model->id, 'user_id' => $val['user_id'], 'day' => $day]);
                             if (empty($isExist)) {
                                 $attendance = ['train_id' => $model->id, 'user_id' => $val['user_id'], 'day' => $day];
                                 Attendance::add($attendance);
                             }
                         }
                     }
                 } else {
                     $transaction->rollBack();
                     throw new ServerErrorHttpException('更新状态失败,原因:该培训课程下没有学员!');
                 }
             }
             $transaction->commit();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;" class="hover">东城区(<b>8</b>)课时</a></li>
                                        <li><a href="javascript:;" class="hover">东城区(<b>8</b>)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;">东城区(8)课时</a></li>
                                        <li><a href="javascript:;" class="hover">东城区(<b>8</b>)课时</a></li>
                                    </ul>
                                </div>
                                <div style="clear:both;height:1px"></div>
                                <h3 class="jjfc_set21"><span class="fl">我的晋级概况</span><span class="fr span_set">我的晋级条件[<?php 
echo \app\models\TrainUsers::getAppraiseResultByUserIdAndLevelId(Yii::$app->user->id, Yii::$app->user->identity->level_id + 1);
?>
]</span></h3>
                                <div class="sj_six2" style="height:288px;">
                                    <ul>
                                        <li><div class="div_box"><p class="shen_blue">注册状态</p><span><?php 
echo \app\models\UsersLevel::$statusList[$data['levelUpInfo']['usersLevelStatusCurrent']];
?>
<b></b></span></div><div class="progres"><?php 
if ($data['levelUpInfo']['usersLevelStatusCurrent'] != \app\models\UsersLevel::SEND_CARD) {
    echo "未注册";
} else {
    echo "已注册";
}
?>
<span></span></div></li>
                                    <th>报名情况</th>
                                    <th>报名截止</th>
                                    <th>类别</th>
                                    <th>活动时间</th>
                                    <th>报名状态</th>
                                    <th>活动状态</th>
                                </tr>
                                <tr>
                                    <td>招<b class="blue"><?php 
echo $data['activityModel']['recruit_count'];
?>
</b>人 | 录取<b class="blue"><?php 
echo \app\models\ActivityUsers::getRecruitCount($data['trainModel']['train_id']);
?>
</b>人 | 结业<b class="blue"><?php 
echo \app\models\TrainUsers::getPassCount($data['trainModel']['train_id']);
?>
</b>人</td>
                                    </td>
                                    <td><?php 
echo date('Y-m-d', strtotime($data['activityModel']['sign_up_end_time']));
?>
</td>
                                    <td><?php 
echo \app\models\ActivityCategory::getNameById($data['activityModel']['category']);
?>
</td>
                                    <td><?php 
echo date('Y-m-d', strtotime($data['activityModel']['begin_time']));
?>
至<?php 
Beispiel #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTrainUsers()
 {
     return $this->hasMany(TrainUsers::className(), ['train_id' => 'id']);
 }
 public function actionApply()
 {
     $trainId = Yii::$app->request->get('train_id');
     $trainInfo = Train::findOne(['id' => $trainId]);
     if ($trainInfo['status'] != Train::BEGIN_SIGN_UP) {
         throw new ServerErrorHttpException('该课程的状态不是开始报名,谢谢。');
     }
     if (Yii::$app->user->isGuest) {
         return $this->redirect(['/user/register', 'train_id' => $trainId]);
     } else {
         $userId = Yii::$app->user->id;
         if (Yii::$app->user->identity->status != '1') {
             throw new ServerErrorHttpException('您目前的状态是未审核,不能报名课程,谢谢。');
         }
         $trainLevelInfo = Level::findOne($trainInfo['level_id']);
         if ($trainLevelInfo['order'] != Yii::$app->user->identity->level_order + 1) {
             throw new ServerErrorHttpException('您目前没有权限报名该级别下的课程,谢谢。');
         }
         //检查用户参与的课程,状态不是取消,注册未完成,审核未通过,未通过的都算是已经参与了报名
         $isExist = TrainUsers::getUserIsExistTrainStatus($userId, $trainInfo['level_id']);
         if (!empty($isExist)) {
             throw new ServerErrorHttpException('您已经参与了该级别下的培训课程,请耐心等待培训结果,谢谢。');
         }
         //报名成功,给出用户的序号
         $trainUsersOrder = TrainUsers::getTrainUsersOrder($trainId);
         if (empty($trainUsersOrder)) {
             $trainUsersOrder = 1;
         } else {
             $trainUsersOrder = $trainUsersOrder + 1;
         }
         $transaction = Yii::$app->db->beginTransaction();
         //如果用户未完成报名流程,更新状态为审核中
         $isSignExist = TrainUsers::getUserIsExistTrainStatusSign($userId, $trainInfo['level_id']);
         if (!empty($isSignExist)) {
             TrainUsers::updateAll(['status' => TrainUsers::APPROVED], ['id' => $isSignExist['id']]);
             $trainName = Train::getOneTrainNameById($isSignExist['train_id']);
             $data = ['orders' => $isSignExist['orders'], 'trainName' => $trainName];
             $transaction->commit();
             return $this->render('/user/apply-success', ['data' => $data]);
         } else {
             //如果没有记录,新增一条
             $data = ['train_id' => $trainId, 'user_id' => $userId, 'status' => TrainUsers::APPROVED, 'practice_score' => 0, 'theory_score' => 0, 'rule_score' => 0, 'level_id' => $trainInfo['level_id'], 'orders' => $trainUsersOrder];
             $model = new TrainUsers();
             $model->setAttributes($data);
             if ($model->save()) {
                 $trainName = Train::getOneTrainNameById($model->train_id);
                 $data = ['orders' => $model->orders, 'trainName' => $trainName];
                 $transaction->commit();
                 return $this->render('/user/apply-success', ['data' => $data]);
             } else {
                 throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
             }
         }
     }
 }
 public function actionView()
 {
     $trainId = Yii::$app->request->get('id');
     $trainModel = Train::findOne(['id' => $trainId]);
     $trainTeachersModel = TrainTeachers::getAllTeachersByTrainId($trainModel['id']);
     $trainUsers = [];
     if ($trainModel['recruit_count'] > 0) {
         for ($i = 1; $i <= $trainModel['recruit_count']; $i++) {
             $trainUsersInfo = TrainUsers::findOne(['train_id' => $trainModel['id'], 'orders' => $i]);
             if (empty($trainUsersInfo)) {
                 $trainUsers[$i]['status'] = '未报名';
                 $trainUsers[$i]['class'] = 'red';
                 $trainUsers[$i]['userId'] = '';
             } else {
                 $trainUsers[$i]['status'] = TrainUsers::$statusList[$trainUsersInfo['status']];
                 $trainUsers[$i]['userId'] = $trainUsersInfo['user_id'];
                 if ($trainUsersInfo['status'] == TrainUsers::NO_APPROVED) {
                     $trainUsers[$i]['class'] = 'blue';
                 } else {
                     $trainUsers[$i]['class'] = '';
                 }
             }
         }
     }
     $data = ['trainModel' => $trainModel, 'trainTeachersModel' => $trainTeachersModel, 'trainUsers' => $trainUsers];
     return $this->render('/train/view', ['data' => $data]);
 }
 public function actionResign()
 {
     $trainUserId = Yii::$app->request->get('train_user_id');
     $result = TrainUsers::updateAll(['status' => TrainUsers::APPROVED], ['id' => $trainUserId]);
     if ($result) {
         return $this->redirect('index');
     } else {
         throw new ServerErrorHttpException('更新状态失败!');
     }
 }
 public static function getAllTrainByUserIdAndLevel($userId = '', $LevelId = '')
 {
     $result = Yii::$app->db->createCommand('SELECT tu.id as id,tu.train_id,t.name,t.category,t.create_time,t.address,t.recruit_count,tu.status,t.begin_time,tu.user_id as train_user_id,t.period_num,t.train_land_id FROM  ' . TrainUsers::tableName() . ' tu LEFT JOIN ' . Train::tableName() . ' t ON tu.train_id = t.id WHERE tu.user_id=:user_id AND tu.level_id=:level_id  ORDER BY id desc', [':user_id' => $userId, ':level_id' => $LevelId])->queryAll();
     return $result;
 }
 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;
 }
Beispiel #13
0
        ?>
</td>
                                                <td><?php 
        echo date('Y年m月d日', strtotime($val['begin_time']));
        ?>
</td>
                                                <td><?php 
        echo \app\models\TrainLand::getNameById($val['train_land_id']);
        ?>
</td>
                                                <td>招<?php 
        echo $val['recruit_count'];
        ?>
人 ( <b
                                                        class="red">已录取 <?php 
        echo \app\models\TrainUsers::getRecruitCount($val['train_id']);
        ?>
                                                        人</b> )
                                                </td>
                                                <td>
                                                    <b class="<?php 
        if ($val['status'] == \app\models\TrainUsers::NO_APPROVED || $val['status'] == \app\models\TrainUsers::SIGN) {
            ?>
red<?php 
        } elseif ($val['status'] == '5') {
            ?>
gray<?php 
        } else {
            ?>
green<?php 
        }