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 actionTrainView()
 {
     $trainUsersId = \Yii::$app->request->get('trainUsersId');
     if (empty($trainUsersId)) {
         throw new ServerErrorHttpException('查看课程信息失败,原因:参数错误!');
     }
     $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);
     //培训信息
     $trainModel = TrainUsers::getTrainInfoById($trainUsersId);
     if (empty($trainModel)) {
         throw new ServerErrorHttpException('查看课程信息失败,原因:不存在的培训课程!');
     }
     //考勤信息
     $attendanceModel = Attendance::getAllByTrainIdAndUserId($trainModel['train_id'], $trainModel['user_id']);
     //迟到数量
     $laterCount = Attendance::getCount($trainModel['train_id'], $trainModel['user_id'], Attendance::LATER);
     $arlyCount = Attendance::getCount($trainModel['train_id'], $trainModel['user_id'], Attendance::EARLY);
     $absencesCount = Attendance::getCount($trainModel['train_id'], $trainModel['user_id'], Attendance::ABSENCES);
     $leaveCount = Attendance::getCount($trainModel['train_id'], $trainModel['user_id'], Attendance::LEAVE);
     $trainTeachersModel = TrainTeachers::getAllTeachersByTrainId($trainModel['id']);
     $usersModel = TrainUsers::getAllUsersByTrainId($trainModel['id']);
     if (!empty($usersModel)) {
         foreach ($usersModel as $key => $val) {
             $usersModel[$key]['img'] = '';
             for ($i = 1; $i <= $val['score_appraise'] / 20; $i++) {
                 $usersModel[$key]['img'] .= '<img src="/images/user/xx1.jpg" />';
             }
             if ($val['score_appraise'] % 20 > 0) {
                 $usersModel[$key]['img'] .= '<img src="/images/user/xx2.jpg" />';
             }
         }
     }
     $data = ['levelName' => $levelName, 'currentTrain' => $currentTrain, 'trainModel' => $trainModel, 'attendanceModel' => $attendanceModel, 'laterCount' => $laterCount, 'arlyCount' => $arlyCount, 'absencesCount' => $absencesCount, 'leaveCount' => $leaveCount, 'attendanceAppraise' => $trainModel['attendance_appraise'], 'trainTeachersModel' => $trainTeachersModel, 'usersModel' => $usersModel, 'photo' => $photo, 'messageCount' => $messageCount];
     return $this->render('train-view', ['data' => $data]);
 }