array('A',0,59), "B" => array('B',60,85), "C" => array('C',86,100) ); //protected $material_url = 'http://wybrain.xueping365.com/rest/textbook/tree'; //protected $material_param = 'subjectId=3&depth=3'; // 首页 public function actionIndex(){ $data = array(); $realname = Req::get("realname"); $grade_id = Req::get("grade_id"); $arts_science = Req::get("arts_science"); $class_type = (int)Req::get("class_type"); //班级类型 1行政,2教学 $subject_id = (int)Req::get("subject_id"); $show_type = (int)Req::get('show_type'); //是否显示隐藏班级 if(!$show_type){ $show_type=0; }else{ $show_type=1; } $teachers = array(); // 获取所有学期 $criteria = new CDbCriteria; $criteria->limit = 10; $criteria->order = "create_time desc"; $allSemester = Semester::model()->findAll($criteria); if(!$class_type || !in_array($class_type,array(1,2))) $class_type=1; $smid = safe_replace(Yii::app()->request->getParam('semesterId')); if(empty($smid)){ $semeseter_id = $this->semesterId; } else{ $semeseter_id = $smid; } $semesterId = $semeseter_id; //走班学科筛选 $classIds=array(); //学科筛选班级id if($class_type==2 && $subject_id){ $classIds=$this->schoolManager->getClassIdBySubjectId($subject_id,$semesterId); } // 判断是否教员组长 if($semesterId){ if($grade_id) { $con[] = "seme.semester_id = '{$semesterId}'"; $con[] = "c.grade=".$grade_id; }else { $con[] = "seme.semester_id = '{$semesterId}'"; } if($realname) { // $_class_ids = $this->schoolManager->getTeachersByteacherName($realname); // // if($class_type==2 && $subject_id && $classIds){ // $classIds=array_intersect($classIds,$_class_ids); // }elseif($_class_ids){ // $con[] = "c.class_id in (".implode(',',$_class_ids).")"; // }else{ // $con[] = "c.class_id in (0)"; // } $con[] = "c.class_name like '%".$realname."%'"; } if($classIds){ $con[] = "c.class_id in (".implode(',',$classIds).")"; } if($arts_science){ $con[] = "c.arts_science=".$arts_science; } $con[]=" c.class_type=".$class_type; $con[]=" c.is_hide=".$show_type; $rs = $this->schoolManager->getClassesDetailListre($con,9); } // debug($rs["rs"]); if($rs["rs"]){ $classesIds = array(); $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId)); if($class_data) { foreach($class_data as $class){ $classesIds[] = $class->class_id; } } $teachers = $this->schoolManager->getClassesTeachers($classesIds); if(!$teachers && false){ $rs["rs"] = array(); }else{ foreach($rs["rs"] as $key => $class){ if(isset($teachers[(string)$class["class_id"]]) && !empty($teachers[(string)$class["class_id"]])) { $rs["rs"][$key]["teachers"] = implode(',',$teachers[(string)$class["class_id"]]); }else { $rs["rs"][$key]["teachers"] = ''; // unset($rs["rs"][$key]); } /*foreach($teachers as $teacher){ if($teacher["class_id"] == $class["class_id"]){ $rs["rs"][$key]["teachers"] = $teacher["teachers_names"]; } }*/ //判断班主任 if($class['teacher_id']){ $teacherInfo = Teacher::model()->find('teacher_id=:tid', array(':tid' => $class['teacher_id'])); $rs["rs"][$key]["bzr"]=$teacherInfo; } } } } $currSemester = $this->schoolManager->getCurrSemester(); /** * 转班 */ $_semesters = $this->getFinishSemesters(); if($_semesters) { $data['_semester'] = $_semesters; $_currClass = $this->schoolManager->getSemesterClasses($currSemester['semester_id']); if($_currClass) { foreach($_currClass as $v) { $data['_currClass'][$v['grade']][$v['class_id']] = $v; } } if(!empty($_semesters['semesters'])) { $data['_fluClass'] = $this->schoolManager->getSemesterClassesStudent($_semesters['semesters']->semester_id); }else { $data['_fluClass'] = array(); } } $data["class_type"] = $class_type; if($class_type==2 ){ $setting=$this->schoolManager->getClassShift($this->semesterId); if(!$setting){ //进入走班说明页面 return $this->render('explain',$data); } } if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $data['subjects']=Yii::app()->params['subjectId']; unset($data['subjects'][6]); unset($data['subjects'][18]); unset($data['subjects'][19]); unset($data['subjects'][51]); if(isset($data['subjects'][20])) unset($data['subjects'][20]); } $data["grade_id"] = $grade_id; $data["arts_science"] = $arts_science; $data["realname"] = $realname; $data["currSemester"] = $currSemester; $data['yearsList'] = $rs["rs"]; $data['pages'] = $rs["pager"]; $data['page_total'] = $rs["pager"]->rowsCount; //$data['allSemester'] = $allSemester; $data['semeseter_id'] = $semeseter_id; $data["semesters"] = $allSemester; $data["semesterId"] = $semesterId; $data["class_type"] = $class_type; $data["show_type"] = $show_type; $data["subject_id"] = $subject_id; $data["thisSemester"] = $this->schoolManager->getSemester($semesterId); $model = new Model(); $data["model"] = $model; //unset($classList,$classInfo); // var_dump($rs["pager"]);exit; $this->render('index',$data); } protected function getFinishSemesters() { $data = array(); $currSemester = $this->schoolManager->getCurrSemester(); $criteria = new CDbCriteria; $criteria->addCondition('end_time <= :start_time'); $criteria->params[':start_time'] = $currSemester['start_time']; $criteria->limit = 1; $criteria->order = "end_time desc"; $_allSemester = Semester::model()->find($criteria); $data['currSemester'] = $currSemester; $data['semesters'] = $_allSemester; return $data; } //转入单个班 public function actionInto_alone_class() { if (Yii::app()->request->getIsPostRequest()) { $alone_one_f_class = Req::post("alone_one_f_class"); $alone_one_c_class = Req::post("alone_one_c_class"); $alone_two_f_class = Req::post("alone_two_f_class"); $alone_two_c_class = Req::post("alone_two_c_class"); $alone_three_f_class = Req::post("alone_three_f_class"); $alone_three_c_class = Req::post("alone_three_c_class"); $transfer_class = array(); $msg = ''; $old_class_id = ''; $new_class_id = ''; if($alone_one_c_class && $alone_one_f_class) { $transfer_class[$alone_one_f_class] = $alone_one_c_class; $old_class_id = $alone_one_f_class; $new_class_id = $alone_one_c_class; } if($alone_two_f_class && $alone_two_c_class) { $transfer_class[$alone_two_f_class] = $alone_two_c_class; $old_class_id = $alone_two_f_class; $new_class_id = $alone_two_c_class; } if($alone_three_f_class && $alone_three_c_class) { $transfer_class[$alone_three_f_class] = $alone_three_c_class; $old_class_id = $alone_three_f_class; $new_class_id = $alone_three_c_class; } if($transfer_class) { //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '单个级转移', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $msg = $this->gotoClasses($transfer_class,array($old_class_id),array($new_class_id)); if($msg) { $str = ''; $i=0; foreach($msg as $k=>$v) { $str .= (++$i).'、'.$v.PHP_EOL; } Yii::app()->jump->setErrorWait(20); if($i>2) { Yii::app()->jump->setHeight(100); }else { Yii::app()->jump->setHeight((100+($i*40))); } Yii::app()->jump->error($str);exit; }else { Yii::app()->jump->success('转班成功
',Yii::app()->createUrl('classes/index'));exit; } }else { Yii::app()->jump->error('尚未选择班级!'); } } } //转多个班 public function actionInto_multi_class() { if (Yii::app()->request->getIsPostRequest()) { $one_class = Req::post("one_class"); $two_class = Req::post("two_class"); $three_class = Req::post("three_class"); $flags = 0; $transfer_class = array(); $old_class_id = array(); $new_class_id = array(); if($one_class) { foreach($one_class as $k=>$v) { if($v) { if(isset($old_class_id[$v]) && !empty($old_class_id[$v])) { Yii::app()->jump->error('不能重复的班级同一班级!'); }else { $old_class_id[$v] = $v; } $transfer_class[$v] = $k; } if($k) { $new_class_id[$k] = $k; } } } if($two_class) { foreach($two_class as $k=>$v) { if($v) { if(isset($old_class_id[$v]) && !empty($old_class_id[$v])) { Yii::app()->jump->error('不能重复的班级同一班级!'); }else { $old_class_id[$v] = $v; } $transfer_class[$v] = $k; } if($k) { $new_class_id[$k] = $k; } } } if($three_class) { foreach($three_class as $k=>$v) { if($v) { if(isset($old_class_id[$v]) && !empty($old_class_id[$v])) { Yii::app()->jump->error('不能重复的班级同一班级!'); }else { $old_class_id[$v] = $v; } $transfer_class[$v] = $k; } if($k) { $new_class_id[$k] = $k; } } } if(!$transfer_class) { Yii::app()->jump->error('尚未选择班级!'); } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '多班级转移', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $msg = $this->gotoClasses($transfer_class,$old_class_id,$new_class_id); if($msg) { $str = ''; $i=0; foreach($msg as $k=>$v) { $str .= (++$i).'、'.$v.PHP_EOL; } Yii::app()->jump->setErrorWait(20); if($i>2) { Yii::app()->jump->setHeight(100); }else { Yii::app()->jump->setHeight((100+($i*40))); } Yii::app()->jump->error($str);exit; }else { Yii::app()->jump->success('转班成功
',Yii::app()->createUrl('classes/index'));exit; } } } /** * @param $class_ids 当前学期班级信息 * @param $old_class_ids 转入班级信息 */ public function gotoClasses($class_ids,$old_class_ids,$new_class_ids) { $c_class_ids = array(); ini_set('memory_limit','518M'); //获取当前学期所有学生信息 $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId); if(!$c_class_data) { Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index')); } foreach($c_class_data as $v) { $c_class_ids[$v['class_id']] = $v['class_id']; } $new_class_student = $this->getInClassStudents($c_class_ids);//新学生 $old_class_student = $this->getInClassStudents($old_class_ids);//旧学生 $_err = array(); if($old_class_student) { if(!empty($new_class_student['student_names']) && !empty($new_class_student['student_ids'])) { //验证学生姓名是否已存在 if(!empty($old_class_student['student_names'])) { foreach($old_class_student['student_names'] as $old_student_id => $v) { $student_repeat_found_key=array_search($v,$new_class_student['student_names'],true); if($student_repeat_found_key){ if(!$new_class_student['id_number'][$student_repeat_found_key] && !$old_class_student['id_number'][$old_student_id]) { $_err[] = $v . '学生已存在'; }elseif(strcmp($new_class_student['id_number'][$student_repeat_found_key],$old_class_student['id_number'][$old_student_id])==0){ $_err[] = $v.'学生已存在'; }elseif(strcmp($old_student_id,$student_repeat_found_key)==0){ $_err[] = $v.'学生已存在'; } } } } //验证学生学校准考证号 if(!empty($old_class_student['school_student_cards'])) { foreach($old_class_student['school_student_cards'] as $key => $v) { if(array_search($v,$new_class_student['school_student_cards'],true)) { $_err[] = $old_class_student['student_names'][$key].'学生学校准考证号已存在'; } } } if(empty($_err)) { //写入数据 //$transaction = StudentInfo::model()->dbConnection->beginTransaction(); $transaction=$this->sConn->beginTransaction(); try { /* $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$old_class_student['student_ids']); StudentInfo::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$old_class_student['student_ids']); StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$old_class_student['student_ids']); $criteria->addInCondition('class_id',$new_class_ids); StudentInfo::model()->deleteAll($criteria); */ $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")"; $updateSql="update student_class_relation set status=1,operation=3,update_time='".time()."' where student_id in(".implode(',',$old_class_student['student_ids']).") and class_type=1"; //添加学生 $i = 0; $serial_number = 0; //组装sql $insertStudentSql="replace into `student_info`(`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`,`id_number`,`field_1`,`field_2`,`field_3`,`field_4`,`field_5`) VALUES"; $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES"; $tempInsertStudentInfoData=array(); $tempInsertStudentClassData=array(); $SqlArr=array(); foreach($old_class_student['student_info'] as $k => $v) { $tempStudentInfoData=array(); $tempStudentClassData=array(); $tempStudentInfoData['student_id']="'".$k."'"; $tempStudentInfoData['realname']= "'".$v->realname."'"; $tempStudentInfoData['sex']="'".$v->sex."'"; $tempStudentInfoData['school_id']="'".$this->schoolId."'"; if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]])) { $class_id = $class_ids[$old_class_student['student_class_ids'][$k]]; }else { $class_id = -2; } $tempStudentInfoData['class_id']="'".$class_id."'"; $tempStudentInfoData['family_tel']="'".$v->family_tel."'"; $tempStudentInfoData['telephone']="'".$v->telephone."'"; $tempStudentInfoData['student_phone']="'".$v->student_phone."'"; $tempStudentInfoData['picture']="'".$v->picture."'"; $tempStudentInfoData['signature']="'".$v->signature."'"; $tempStudentInfoData['is_outer']="'".$v->is_outer."'"; $tempStudentInfoData['add_time']="'".$v->add_time."'"; $tempStudentInfoData['update_time']="'".$v->update_time."'"; $tempStudentInfoData['level']="'".$v->level."'"; $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'"; $tempStudentInfoData['game_stars']="'".$v->game_stars."'"; $tempStudentInfoData['id_number']="'".$v->id_number."'"; $tempStudentInfoData['field_1']="'".$v->field_1."'"; $tempStudentInfoData['field_2']="'".$v->field_2."'"; $tempStudentInfoData['field_3']="'".$v->field_3."'"; $tempStudentInfoData['field_4']="'".$v->field_4."'"; $tempStudentInfoData['field_5']="'".$v->field_5."'"; $tempInsertStudentInfoData[$k]=$tempStudentInfoData; // 创建学生与班级关联关系 $class_student = $old_class_student['class_student'][$k]; $tempStudentClassData['student_id']="'".$k."'"; if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]])) { $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]]; }else { $studentClassId = -2; } $tempStudentClassData['class_id']="'".$studentClassId."'"; if($new_class_student && isset($new_class_student['serial_number']) && isset($new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]])) { $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]]; }else { $serial_number = 0; } $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'"; $tempStudentClassData['userno']="'".$class_student->userno."'"; $tempStudentClassData['update_time']=time(); $tempStudentClassData['status']=0; $tempInsertStudentClassData[]=$tempStudentClassData; $i++; if($i%200==0){ $TempData1=array(); $TempData2=array(); foreach ($tempInsertStudentInfoData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentSql.implode(',',$TempData1); } foreach ($tempInsertStudentClassData as $item){ $TempData2[]="(".implode(',',$item).")"; } if($TempData2){ $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2); } $tempInsertStudentInfoData=array(); $tempInsertStudentClassData=array(); } } if($tempInsertStudentInfoData){ $TempData1=array(); foreach ($tempInsertStudentInfoData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentSql.implode(',',$TempData1); } } if($tempInsertStudentClassData){ $TempData1=array(); foreach ($tempInsertStudentClassData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1); } } if($SqlArr){ $this->sConn->createCommand($deleteSql)->execute(); $this->sConn->createCommand($updateSql)->execute(); foreach ($SqlArr as $sql){ $this->sConn->createCommand($sql)->execute(); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index')); } }else { //错误处理 return $_err; } }else { //新学期 //写入数据 //$transaction = StudentInfo::model()->dbConnection->beginTransaction(); $transaction=$this->sConn->beginTransaction(); try { /* $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$old_class_student['student_ids']); StudentInfo::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$old_class_student['student_ids']); StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria); */ $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")"; $updateSql="update student_class_relation set status=1,operation=3,update_time='".time()."' where student_id in(".implode(',',$old_class_student['student_ids']).") and class_type=1 "; //添加学生 $serial_number = 0; $i = 0; //组装sql $insertStudentSql="replace into `student_info`(`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`,`id_number`,`field_1`,`field_2`,`field_3`,`field_4`,`field_5`) VALUES"; $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES"; $tempInsertStudentInfoData=array(); $tempInsertStudentClassData=array(); $SqlArr=array(); foreach($old_class_student['student_info'] as $k => $v) { $tempStudentInfoData=array(); $tempStudentClassData=array(); $tempStudentInfoData['student_id']="'".$k."'"; $tempStudentInfoData['realname']= "'".$v->realname."'"; $tempStudentInfoData['sex']="'".$v->sex."'"; $tempStudentInfoData['school_id']="'".$this->schoolId."'"; $userModel = new StudentInfo(); $userModel->student_id = $k; $userModel->realname = $v->realname; $userModel->sex = $v->sex; $userModel->school_id = $this->schoolId; if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]])) { $class_id = $class_ids[$old_class_student['student_class_ids'][$k]]; }else { $class_id= -2; } $tempStudentInfoData['class_id']="'".$class_id."'"; $tempStudentInfoData['family_tel']="'".$v->family_tel."'"; $tempStudentInfoData['telephone']="'".$v->telephone."'"; $tempStudentInfoData['student_phone']="'".$v->student_phone."'"; $tempStudentInfoData['picture']="'".$v->picture."'"; $tempStudentInfoData['signature']="'".$v->signature."'"; $tempStudentInfoData['is_outer']="'".$v->is_outer."'"; $tempStudentInfoData['add_time']="'".$v->add_time."'"; $tempStudentInfoData['update_time']="'".$v->update_time."'"; $tempStudentInfoData['level']="'".$v->level."'"; $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'"; $tempStudentInfoData['game_stars']="'".$v->game_stars."'"; $tempStudentInfoData['id_number']="'".$v->id_number."'"; $tempStudentInfoData['field_1']="'".$v->field_1."'"; $tempStudentInfoData['field_2']="'".$v->field_2."'"; $tempStudentInfoData['field_3']="'".$v->field_3."'"; $tempStudentInfoData['field_4']="'".$v->field_4."'"; $tempStudentInfoData['field_5']="'".$v->field_5."'"; $tempInsertStudentInfoData[$k]=$tempStudentInfoData; // 创建学生与班级关联关系 $class_student = $old_class_student['class_student'][$k]; $tempStudentClassData['student_id']="'".$k."'"; $studentClass = new StudentToClass(); $studentClass->student_id = $k; if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]])) { $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]]; }else { $studentClassId = -2; } $tempStudentClassData['class_id']="'".$studentClassId."'"; if($new_class_student && isset($new_class_student['serial_number']) && isset($new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]])) { $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]]; }else { $serial_number = 0; } $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'"; $tempStudentClassData['userno']="'".$class_student->userno."'"; $tempStudentClassData['update_time']=time(); $tempStudentClassData['status']=0; $tempInsertStudentClassData[]=$tempStudentClassData; $i++; if($i%200==0){ $TempData1=array(); $TempData2=array(); foreach ($tempInsertStudentInfoData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentSql.implode(',',$TempData1); } foreach ($tempInsertStudentClassData as $item){ $TempData2[]="(".implode(',',$item).")"; } if($TempData2){ $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2); } $tempInsertStudentInfoData=array(); $tempInsertStudentClassData=array(); } } if($tempInsertStudentInfoData){ $TempData1=array(); foreach ($tempInsertStudentInfoData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentSql.implode(',',$TempData1); } } if($tempInsertStudentClassData){ $TempData1=array(); foreach ($tempInsertStudentClassData as $item){ $TempData1[]="(".implode(',',$item).")"; } if($TempData1){ $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1); } } if($SqlArr){ $this->sConn->createCommand($deleteSql)->execute(); $this->sConn->createCommand($updateSql)->execute(); foreach ($SqlArr as $sql){ $this->sConn->createCommand($sql)->execute(); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index')); } } } return false; } public function gotoClass($class_ids) { $_msg = array(); if($class_ids) { /** * 获取当前学期所有班级 */ $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId); $c_class_ids = array(); if(!$c_class_data) { Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index')); } foreach($c_class_data as $v) { $c_class_ids[$v['class_id']] = $v['class_id']; } $new_class_student = $this->getInClassStudents($c_class_ids); foreach($class_ids as $k => $v) { /** * 获取转入班的学生 */ /** * 获取转出班的学生 */ $old_class_student = $this->getClassStudents($k); /** * 验证重名 */ $_err = $this->StudentCompare($old_class_student,$new_class_student); if($_err) { $str = ''; $class_data = $this->schoolManager->getClassByClassIds(array($v,$k)); if($class_data){ foreach($class_data as $c) { if($k==$c['class_id']) { $str .= $c['class_name']; } if($v==$c['class_id']) { $str .= '转入'.$c['class_name'].'失败,请查看学生姓名重名,学校准考完证号重复'; } } $_msg[$v] = array( 'msg'=>$str ); }else { $_msg[$v] = array( 'msg'=>'转班失败' ); } continue ; }else { $serial_number = 0; $_student_class_data = SStudentClassRelation::model()->find(array( 'select' => 'serial_number', 'order' => 'serial_number desc', 'condition' => 'class_id=:class_id and status=:status', 'limit' => 1, 'params' => array(':class_id'=>$v,':status'=>0) )); if($_student_class_data) { if($_student_class_data->serial_number) { $serial_number = $_student_class_data->serial_number; } } //插入学生 if($old_class_student) { $get_array = isset($old_class_student['student_ids'])?$old_class_student['student_ids']:array(); if($get_array) { $transaction = StudentInfo::model()->dbConnection->beginTransaction(); try { foreach ($get_array as $student_id) { $serial_number = $serial_number+1; // 修改当前学生所在的班级 $count = StudentInfo::model()->updateAll(array('class_id'=>$v),'student_id=:sid',array(':sid'=>$student_id)); //更新当前学生之前所在班级状态 StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>3),'student_id=:sid and status=0 and class_type=1',array(':sid'=>$student_id)); // 建立当前学生新班级对应记录 $student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$student_id,':class_id'=>$v)); if($student_class){ if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id])) { $userno = $old_class_student['student_userno'][$student_id]; }else { $userno = ''; } SStudentClassRelation::model()->updateAll(array('status'=>'0','update_time'=>time(),'userno'=>$userno,'serial_number'=>$serial_number),'student_id=:sid and class_id=:class_id',array(':sid'=>$student_id,':class_id'=>$v)); }else{ $newModel = new StudentToClass(); $newModel->class_id = $v; $newModel->student_id = $student_id; $newModel->serial_number = $serial_number; if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id])) { $newModel->userno = $old_class_student['student_userno'][$student_id]; }else { $newModel->userno = ''; } $newModel->update_time = time(); $newModel->save(); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $_msg[$v] = array( 'msg'=>'学生写入失败' ); } }else { $_msg[$v] = array( 'msg'=>'学生写入失败' ); } }else { $_msg[$v] = array( 'msg'=>'此班无学生' ); } } } } return $_msg; } // 创建班级 public function actionAdd(){ $toFiltMaterialsIds = array(13, 14, 15, 16); $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85); checkAuthority(2); // 非当前使用学期无法操作 $data = array(); $teachers = $this->schoolManager->getTeachers(); $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20); $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); if (Yii::app()->request->getIsPostRequest()){ $class_name = trim(Req::post("class_name")); $mid_array = array(); $subjectId = 0; $material_id = 0; $coach_id = Req::post("coach_id"); $period = (int)Req::post("period"); $teachersIds = Req::post("teacher_ids"); $subject_ids = Req::post("subject_ids"); $bzr_id=Req::post("bzrId"); //班主任id $levelName = Req::post("level_name"); if(!$levelName) $levelName='A'; $level = array($levelName => null); $grade = Req::post("grade"); $arts_science = Req::post("arts_science"); $_subject_ids = array(); if($subject_ids) { foreach($subject_ids as $v) { if(in_array($v,$_subject_ids)) { Yii::app()->jump->error('班级不能增加相同的学科教师'); } $_subject_ids[] = $v; } } if(is_array($teachersIds)){ foreach($teachersIds as $key => $val){ if(empty($val) ||(is_string($val) && trim($val) == "")) unset($teachersIds[$key]); } } if(!array_intersect_key($level, $this->class_level)) $levelName = ""; if (empty($class_name)){ Yii::app()->jump->error('班级信息未填写完整!'); } else if(empty($coach_id)){ Yii::app()->jump->error('未选择助教!'); } else if(!$teachersIds){ Yii::app()->jump->error('未选择执教老师!'); } else if(!$grade){ Yii::app()->jump->error('未选择年级!'); } $classesModel = new ClassModel(); // 判断当前学期当前班级是否已添加 if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name))) { Yii::app()->jump->error('该学期下已存在同名班级!'); } // 当前班级唯一id //$classId = getUUID(); $classId=getUniqueId($this->schoolId); if (empty($classId)) { Yii::app()->jump->error('创建班级失败!'); } $improve_book_type = 0; $wb_isp_version = 0; if(Req::post("improve_book_type")==0) { $improve_book_type = 0; $wb_isp_version = 0; } if(Req::post("improve_book_type")==1) { $improve_book_type = 1; $wb_isp_version = 0; } if(Req::post("improve_book_type")==3) { $improve_book_type = 0; $wb_isp_version = 1; } if(Req::post("improve_book_type")==4) { $improve_book_type = 1; $wb_isp_version = 1; } // 创建班级相关事务 //$transaction = Yii::app()->db->beginTransaction(); $transaction = $classesModel->dbConnection->beginTransaction(); try{ //创建班级与老师关系 if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array( 'class_id' => $classId, 'class_name' => $class_name, 'level' => Char::letterToNum($levelName, 1), 'grade' => $grade, 'semester_id' => $semesterId, 'period' => $period, 'add_time' => time(), 'coach_id' => $this->coachId, 'wrong_book_type' => Req::post("wrong_book_type"), 'improve_book_type' => $improve_book_type, 'wb_isp_version' => $wb_isp_version, 'arts_science'=>$arts_science, 'teacher_id'=>$bzr_id ))) throw new CException("创建班级和老师关系失败"); $modulesIds = array(); if($mid_array){ //创建教材模块与班级关系表 foreach($mid_array as $lp){ if (empty($lp)) throw new CException('创建班级失败!'); $lp = (int)$lp; $modulesIds[] = $lp; } $modulesIds = implode(",", $modulesIds); } if(!$modulesIds) $modulesIds = ""; if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds))) { throw new CException('创建失败!'); } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error($e->getMessage()); } if($this->schoolManager->isCurrentSemester($semesterId)) $this->redirect(array('classes/index')); else $this->redirect(array("classes/index?semesterId={$semesterId}")); } unset(Yii::app()->session['school_material']); // 获取所有教材及其模块 $get_material = Yii::app()->session['school_material']; if (empty($get_material)) { //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']); $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3"); $json_material = json_decode($json_material, true); $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true)); $session_material = $json_material; //$session_material = json_decode($json_material,true); if (!empty($session_material) && !isset($session_material['error'])) { Yii::app()->session['school_material'] = $session_material; $get_material = $session_material; } unset($json_material,$session_material); } if($get_material){ foreach($get_material as $key => $material){ if(isset($material["modules"])){ foreach($material["modules"] as $moduleKey => $module){ //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){ if(empty($module["chapters"])){ unset($get_material[$key]["modules"][$moduleKey]); } } } if(empty($get_material[$key]["modules"])) unset($get_material[$key]); } } $data['material'] = $get_material; // 获取当前学校所有助教 $coachList = array(); if(!isset(Yii::app()->session['crmUserInfo'])) { $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])); if (empty($coachList)) { Yii::app()->jump->error('系统未找到助教,请联系管理员!'); } }else { $coachList = array(Yii::app()->session['crmUserInfo']); } unset($transaction); if( Yii::app()->params['section']==1){ $firstSubjectId=3; }else{ $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject); } $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId)); $model = new Model(); //$data['semester'] = $semester; $data['coachList'] = $coachList; $data["teachers"] = $teachers; $data["teacher_data"] = $teacher_data; $data["classLevels"] = $this->class_level; $data["semesters"] = $semesters; $data["semesterId"] = $semesterId; $data["model"] = $model; $data["thisSemester"] = $thisSemester; $this->render('add',$data); } //更新班级排序 public function actionSaveClassSort() { $classSort = Req::post('classSort'); if(!$classSort){ returnMsg(0,'排序参数错误'); } $sql = "UPDATE class SET sort = CASE class_id"; $class_ids = array(); foreach ($classSort as $k=>$v){ $temp = explode('_', $v); $sort = intval($temp[1])>0?intval($temp[1]):0; $sql .= " WHEN {$temp[0]} THEN {$sort}"; $class_ids[] = $temp[0]; } if(!$class_ids){ returnMsg(0,'参数错误'); } $class_id = implode(',', $class_ids); $sql .= " END "; $sql .= " WHERE class_id IN ({$class_id})"; $result = ClassModel::model()->saveClassSort($sql); if ($result !==false){ returnMsg(1,'修改成功'); }else{ returnMsg(0,'修改失败'); } } public function actionVerifyclass_name() { $class_name = trim(Req::post("class_name")); if (empty($class_name)){ echo json_encode(array('status'=>0));exit; } $is_edit = trim(Req::post("is_edit")); if($is_edit) { $class_ids = array(); $class_id = trim(Req::post("class_id")); $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); $_class_data = ClassModel::model()->findAll('semester_id=:seid and class_name=:class_name',array(':seid'=>$this->semesterId,':class_name'=>$class_name)); if(!$class_data) { echo json_encode(array('status'=>0));exit; } if(count($_class_data)>1) { echo json_encode(array('status'=>0));exit; } $class_ids[$class_id] = $class_id; if($_class_data && !isset($class_ids[$_class_data[0]->class_id])) { echo json_encode(array('status'=>0));exit; }elseif($_class_data && isset($class_ids[$_class_data[0]->class_id])) { echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>1));exit; } $classesModel = new ClassModel(); if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$this->semesterId,':cname'=>$class_name))) { echo json_encode(array('status'=>0));exit; } echo json_encode(array('status'=>1));exit; } // 修改班级信息 public function actionEdit(){ $toFiltMaterialsIds = array(13, 14, 15, 16); $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85); //checkAuthority(2); // 非当前使用学期无法操作 $classId = safe_replace(Yii::app()->request->getQuery('cid')); if (empty($classId)) { Yii::app()->jump->error('操作失败!'); } // 获取当前学校所有助教 $coachList = array(); if(!isset(Yii::app()->session['crmUserInfo'])) { $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])); if (empty($coachList)) { Yii::app()->jump->error('系统未找到助教,请联系管理员!'); } }else { $coachList = array(Yii::app()->session['crmUserInfo']); } $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId); $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); // 班级信息 //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId)); $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ"); $grade = $classInfo->grade; $teachers = $this->schoolManager->getTeachers(); $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20); if (empty($classInfo)) { Yii::app()->jump->error('未找到该班级信息!'); } // 当前班级教练信息 $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ"); // 当前班级教材模块 $module = $this->sConn->createCommand()->select("*")->from("class_subject_relation")->where("class_id = '{$classId}'")->queryRow(); $module_array = array(); if($module && $module["module_ids"]){ $module_array = explode(",", $module["module_ids"]); } if (Yii::app()->request->getIsPostRequest()){ /*$class_name = safe_replace($_POST['class_name']); $mid_array = $_POST['mid']; $material_id = safe_replace($_POST['material_id']); $coach_id = safe_replace($_POST['coach_id']); $period = intval($_POST['period']);*/ $class_name = trim(Req::post("class_name")); $improve_book_type = 0; $wb_isp_version = 0; $bzr_id=Req::post("bzrId"); //班主任id if(Req::post("improve_book_type")==0) { $improve_book_type = 0; $wb_isp_version = 0; } if(Req::post("improve_book_type")==1) { $improve_book_type = 1; $wb_isp_version = 0; } if(Req::post("improve_book_type")==3) { $improve_book_type = 0; $wb_isp_version = 1; } if(Req::post("improve_book_type")==4) { $improve_book_type = 1; $wb_isp_version = 1; } //$mid_array = Req::post("mid"); //$subjectId = Req::post("subject_id"); //$material_id = Req::post("material_id"); $mid_array = array(); $subjectId = 0; $material_id = 0; $coach_id = Req::post("coach_id"); $period = Req::post("period"); $levelName = Req::post("level_name"); $level = array($levelName => null); $teachersIds = Req::post("teacher_ids"); $subject_ids = Req::post("subject_ids"); $arts_science= Req::post("arts_science"); $_subject_ids = array(); if($subject_ids) { foreach($subject_ids as $v) { if(in_array($v,$_subject_ids)) { Yii::app()->jump->error('班级不能增加相同的学科教师'); } $_subject_ids[] = $v; } } if(is_array($teachersIds)){ foreach($teachersIds as $key => $val){ if(empty($val) ||(is_string($val) && trim($val) == "")) unset($teachersIds[$key]); } } $grade = Req::post("grade"); //$semesterId = Req::post("semesterId"); if(!array_intersect_key($level, $this->class_level)) $levelName = ""; if(!$levelName) Yii::app()->jump->error('层级只能是A,B,C层!'); if (empty($class_name) || empty($coach_id) || !$teachersIds){ Yii::app()->jump->error('班级信息未填写完整!'); } $classesModel = new ClassModel(); // 判断当前学期当前班级是否已添加 if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name))) { if($classInfo->class_name != $class_name && !$classesModel->count('semester_id=:seid and class_name=:cname and class_id=:classId',array(':seid'=>$semesterId,':cname'=>$class_name,':classId'=>$classId))) Yii::app()->jump->error('您选择的学期已存在同名班级!'); } // 创建班级相关事务 //$transaction = Yii::app()->db->beginTransaction(); $classInfo = ClassModel::model()->find("class_id = '{$classId}'"); $transaction = $classInfo->dbConnection->beginTransaction(); try { if($classInfo->class_name != $class_name) $classInfo->class_name = $class_name; //$classInfo->period = $period; //$classInfo->grade = $grade; //$classInfo->semester_id = $semesterId; $classInfo->level = Char::letterToNum($levelName, 1); $classInfo->wrong_book_type = Req::post("wrong_book_type"); $classInfo->improve_book_type = $improve_book_type; $classInfo->wb_isp_version = $wb_isp_version; $classInfo->teacher_id = $bzr_id; $classInfo->arts_science = $arts_science; if(!$classInfo->save()){ throw new CException('更新失败!'); } if($classInfo->coach_id != $coach_id){ if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) { throw new CException('班级更新失败!'); } } if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId)) throw new CException("班级老师更新失败"); // 是否修改教材模块 $get_array = array_diff($mid_array, $module_array); $modulesIds = array_diff($module_array, $mid_array); if ((!empty($get_array) || !empty($modulesIds)) && $mid_array){ $modulesIds = implode(",", $mid_array); if(!$this->schoolManager->classSubjectExists($classId)){ if(!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds))) throw new CException('创建失败!'); } else{ if (!$this->sConn->createCommand()->update("class_subject_relation", array("subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds), "class_id = {$classId}")) { throw new CException('创建失败!'); } } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error($e->getMessage()); } $this->redirect(array('classes/index')); } $data = array(); unset(Yii::app()->session['school_material']); // 获取所有教材及其模块 $get_material = Yii::app()->session['school_material']; if (empty($get_material)) { //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']); $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3"); $json_material = json_decode($json_material, true); $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true)); $session_material = $json_material; //$session_material = json_decode($json_material,true); if (!empty($session_material) && !isset($session_material['error'])) { Yii::app()->session['school_material'] = $session_material; $get_material = $session_material; } unset($json_material,$session_material); } if($get_material){ foreach($get_material as $key => $material){ if(isset($material["modules"])){ foreach($material["modules"] as $moduleKey => $module){ //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){ if(empty($module["chapters"])){ unset($get_material[$key]["modules"][$moduleKey]); } } } if(empty($get_material[$key]["modules"])) unset($get_material[$key]); } } $data['material'] = $get_material; /*$coachList = BusinessCoach::model()->findAll('school_id=:sid and status=0',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])); if (empty($coachList)) { Yii::app()->jump->error('系统未找到助教,请联系管理员!'); }*/ $class_teacher_data = array(); $subject_teacher_data = array(); $subject_teacher_array = array(); $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3)); $teachers_data = Teacher::model()->findAll('status=0'); if($teachers_data) { $gangwei = array( 0=>'任课教师', 1=>'班主任', 2=>'教研组长', 3=>'年级主任', 4=>'任课教师', 5=>'校长', ); $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三'); foreach($teachers_data as $k=>$v) { $class_teacher_data[$v->teacher_id] = $v->teacher_id; $subject_teacher_data[$v->teacher_id] = $v->subjects; $teacherGrade = $v->grade?$v->grade:0; if($v->posts==3){ //过滤本年级的年级主任 if (!$teacherGrade || $teacherGrade==$grade){ $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts]; $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost); } }else{ $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$gangwei[$v->posts]); } if($classInfo->teacher_id && strcmp($v->teacher_id,$classInfo->teacher_id)==0){ $data['bzr']=$v->teacher_name; } } } if(!$classTeachersIds){//如果没有执教老师 默认会一个执教老师 方便编辑操作 $sql = "select teacher_id from teacher where `status`=0 and (posts !=3 or (posts=3 and grade={$grade}))"; $teacher_data = $this->sConn->createCommand($sql)->queryRow(); if($teacher_data){ $classTeachersIds[] = $teacher_data['teacher_id']; } } $data["teachers"] = $teachers; $data["classLevels"] = $this->class_level; $data["classTeachersIds"] = $classTeachersIds; $data['classInfo'] = $classInfo; $data['relatCoach'] = $relatCoach; $data['class_teacher'] = $class_teacher_data; $data['subject_teacher'] = $subject_teacher_data; $data['subject_teacher_array'] = $subject_teacher_array; $data["teacher_data"] = $teacher_data; $data['module_array'] = $module_array; $data['coachList'] = $coachList; $data["semesters"] = $semesters; $data["semester_id"] = $classInfo->semester_id; $data["thisSemester"] =$thisSemester; $this->render('edit',$data); } public function actionGetChaptersAct(){ $materialId = Req::get("materialId"); $chapters = $this->schoolManager->getMaterialChapters($materialId); echo json_encode($chapters);exit; } public function actionAjax_semester_class() { $semester_id = Req::post("semester_id"); $class_id = Req::post("class_id"); $class_array = array(); if( !$semester_id || !$class_id) { echo json_encode(array('status'=>0,'data'=>''));exit; } $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$semester_id)); $class_ids = array(); $_class_ids = array(); $class_info = array(); if($class_data) { foreach($class_data as $v) { if($class_id != $v->class_id) { $class_ids[$v->class_id] = $v->class_id; $class_info[$v->class_id] = $v->attributes; } } $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_class_data = SStudentClassRelation::model()->findAll($criteria); if($student_class_data) { foreach($student_class_data as $v) { $_class_ids[$v->class_id] = $v->class_id; } foreach($_class_ids as $v) { if(isset($class_info[$v]) && !empty($class_info[$v])) { $class_array[$v] = $class_info[$v]; } } }else{ $class_array =array(); } } if($class_array) { echo json_encode(array('status'=>1,'data'=>$class_array));exit; } echo json_encode(array('status'=>0,'data'=>''));exit; } //根据学期id获取班级 public function actionAjaxclass(){ $json = array(); $smid = safe_replace(Yii::app()->request->getPost('smid')); if (empty($smid)) { $json['flag'] = false; echo json_encode($json);die; } $allClass = ClassModel::model()->findAll('semester_id=:yid',array(':yid'=>$smid)); $classList = array(); if (!empty($allClass)) { foreach ($allClass as $val) { $classList[] = $val->attributes; } } unset($allClass); $json['flag'] = true; $json['classList'] = $classList; echo json_encode($json);exit; } public function actionGetclass() { $grade_id = Req::post("grade_id"); $all_class = Req::post("all_class"); $filter_hide = (int)Req::post('filter_hide'); if(!$filter_hide){ $filter_hide=0; }else{ $filter_hide=1; } $class_array = array(); $class_data=array(); if($all_class){ if($filter_hide){ $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and is_hide=0',array(':grade' => $grade_id,':semester_id'=>$this->semesterId)); }else{ $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id ',array(':grade' => $grade_id,':semester_id'=>$this->semesterId)); } }else{ if($filter_hide){ $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1 and is_hide=0',array(':grade' => $grade_id,':semester_id'=>$this->semesterId)); }else{ $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1',array(':grade' => $grade_id,':semester_id'=>$this->semesterId)); } } if($class_data){ foreach($class_data as $v ) { $class_array[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$class_array));exit; } echo json_encode(array('status'=>0,'result'=>array()));exit; } public function actionGetClassWithSort() { $class_data = ClassModel::model()->getClassWithSort($this->semesterId); if($class_data){ foreach($class_data as $k=>$v ) { $class_array[$k]['class_id'] = $v->class_id; $class_array[$k]['class_name'] = $v->class_name; $class_array[$k]['sort'] = $v->sort; } returnMsg(1,'获取成功',$class_array); }else{ returnMsg(0,'暂无班级'); } } // 复制学生 public function actionCopy(){ ini_set('memory_limit','300M'); $data = array(); $_err = array(); $cid = safe_replace(Yii::app()->request->getQuery('cid')); $currSemester = $this->schoolManager->getCurrSemester(); $criteria = new CDbCriteria; $criteria->addCondition('end_time <= :start_time'); $criteria->params[':start_time'] = $currSemester['start_time']; $criteria->limit = 1; $criteria->order = "end_time desc"; $allSemester = Semester::model()->find($criteria); $data['currSemester'] = $currSemester; $data['semesters'] = $allSemester; if (!($class = $this->schoolManager->getClass($cid))) { Yii::app()->jump->error('复制学生有误1!'); } if($this->schoolManager->isFutureSemester($class["semester_id"])) Yii::app()->jump->error('未开始的学期不能转班'); if (Yii::app()->request->getIsPostRequest()){ //$get_array = $_POST['class_array']; $get_array = Filter::act($_POST['class_array']); $class_id = Filter::act($_POST['class_id']); $semester_id = Filter::act($_POST['semester_id']); $is_ajax = isset($_POST['is_ajax'])?Filter::act($_POST['is_ajax']):0; $chooseStudentIds = array(); $chooseStudentStr = ''; if($get_array){ foreach($get_array as $k=>$v){ $chooseStudentIds[] = $v; } } $operation=2; //转班操作类型 if($semester_id==$this->semesterId){ $operation=2; }else{ $operation=3; } if($this->schoolManager->isFutureSemester($semester_id)){ Yii::app()->jump->error('未开始的学期不能转班'); } if (!($class = $this->schoolManager->getClass($class_id))) { Yii::app()->jump->error('复制学生有误2!'); } if($this->schoolManager->isFutureSemester($class['semester_id'])){ Yii::app()->jump->error('未开始的学期不能转班'); } /** * 获取当前学期所有班级 */ $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId); $c_class_ids = array(); if(!$c_class_data) { Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index')); } foreach($c_class_data as $v) { $c_class_ids[$v['class_id']] = $v['class_id']; } /** * 获取转出班的学生 */ //$out_data = $this->getClassStudents($class_id,0,$chooseStudentIds); $out_data = $this->getStudentsClassNo($chooseStudentIds); /** * 获取转入班的学生 */ $in_data = $this->getInClassStudents($c_class_ids); /** * 验证重名 */ if($class['semester_id']!=$this->semesterId) { $_err = $this->StudentCompare($out_data,$in_data); } if($_err) { Yii::app()->jump->error('转班失败,请查看重名或准考证号重复',Yii::app()->createUrl('classes/copy',array('cid'=>$cid))); } $serial_number = 0; $_student_class_data = SStudentClassRelation::model()->find(array( 'select' => 'serial_number', 'order' => 'serial_number desc', 'condition' => 'class_id=:class_id and status=:status', 'limit' => 1, 'params' => array(':class_id'=>$cid,':status'=>0) )); if($_student_class_data) { if($_student_class_data->serial_number) { $serial_number = $_student_class_data->serial_number; } } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '分班', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $transaction = StudentInfo::model()->dbConnection->beginTransaction(); try { foreach ($get_array as $v) { $serial_number = $serial_number+1; // 修改当前学生所在的班级 $count = StudentInfo::model()->updateAll(array('class_id'=>$cid),'student_id=:sid',array(':sid'=>$v)); if (false === $count) { Yii::app()->jump->error('更新学生班级有误!'); } //更新当前学生之前所在班级状态 $classData=$this->sConn->createCommand("select scr.class_id from student_class_relation scr join class c on scr.class_id=c.class_id where student_id ='{$v}' and c.class_type=1 and scr.status=0")->queryAll(); if($classData){ $classIds=array(); foreach ($classData as $datum){ $classIds[]=$datum['class_id']; } $this->sConn->createCommand("update student_class_relation set status=1,update_time='".time()."',operation='{$operation}',class_type=1 where student_id='{$v}' and class_id in(".implode(',',$classIds).")")->execute(); // StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>$operation,'class_type'=>1),'student_id=:sid and class_id in (:cid)',array(':sid'=>$v,':cid'=>implode(',',$classIds))); } //StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>$operation),'student_id=:sid and status=0 and class_type=1',array(':sid'=>$v)); // 建立当前学生新班级对应记录 //$student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid)); // if($student_class){ // SStudentClassRelation::model()->updateAll(array('status'=>'0','update_time'=>time()),'student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid)); // }else{ // $newModel = new StudentToClass(); // $newModel->class_id = $cid; // $newModel->student_id = safe_replace($v); // $newModel->serial_number = $serial_number; // $newModel->userno = $out_data['class_student'][$v]['userno']; // $newModel->update_time = time(); // if (!$newModel->save()) { // Yii::app()->jump->error('更新学生班级有误!'); // } // } $newModel = new StudentToClass(); $newModel->class_id = $cid; $newModel->student_id = safe_replace($v); $newModel->serial_number = $serial_number; if(isset($out_data['class_student'][$v])){ $newModel->userno = $out_data['class_student'][$v]['userno']; } $newModel->update_time = time(); if (!$newModel->save()) { Yii::app()->jump->error('更新学生班级有误!'); } } $transaction->commit(); } catch (Exception $e) { debug($e); //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error('复制学生信息失败!'); } if($is_ajax){ echo json_encode(array('status'=>1));exit; }else{ $this->redirect(array('classes/index')); } } //所有班级 $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$this->semesterId)); $class_ids = array(); $_class_ids = array(); $class_info = array(); if($class_data) { foreach($class_data as $v) { if($cid != $v->class_id) { $class_ids[$v->class_id] = $v->class_id; $class_info[$v->class_id] = $v; } } $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_class_data = SStudentClassRelation::model()->findAll($criteria); if($student_class_data) { foreach($student_class_data as $v) { $_class_ids[$v->class_id] = $v->class_id; } foreach($_class_ids as $v) { if(isset($class_info[$v]) && !empty($class_info[$v])) { $data['all_class'][$v] = $class_info[$v]; } } }else{ $data['all_class'] =array(); } } $data['all_class'] = ClassModel::model()->findAll("class_id != :cid and semester_id = '{$this->semesterId}' and class_type=1 and is_hide=0",array(':cid'=>$cid)); // 班级名称 $data['className'] = ClassModel::model()->getClassName($cid); $data['classId'] = $cid; $this->render('copy',$data); } public function StudentCompare($out,$in) { $_err = array(); if($out && $in) { if(isset($in['student_names']) && !empty($in['student_names']) && isset($out['student_names']) && !empty($out['student_names'])) { foreach ($in['student_names'] as $key=>$val) { if(isset($out[$key])) { $_err[$key] = $out[$key].'学生已存在'; } foreach($out['student_names'] as $k=>$v) { if($v == $val) { $_err[$k] = $v.'学生姓名已存在'; } } } } if(isset($in['school_student_cards']) && !empty($in['school_student_cards']) && isset($out['school_student_cards']) && !empty($out['school_student_cards'])) { foreach ($in['school_student_cards'] as $key=>$val) { if(isset($out[$key])) { $_err[$key] = $out[$key].'学生已存在'; } foreach($out['school_student_cards'] as $k=>$v) { if($v == $val) { $_err[$k] = $v.'学生学校准考证号已存在'; } } } } if(isset($in['student_cards']) && !empty($in['student_cards']) && isset($out['student_cards']) && !empty($out['student_cards'])) { foreach ($in['student_cards'] as $key=>$val) { if(isset($out[$key])) { $_err[$key] = $out[$key].'学生已存在'; } foreach($out['student_cards'] as $k=>$v) { if($v == $val) { $_err[$k] = $v.'学生准考证号已存在'; } } } } } return $_err; } public function getClassStudents($class_id,$status=0,$chooseStudentArr) { $data = array(); $student_ids = array(); $student_names = array(); $student_cards = array(); $school_student_cards = array(); $userno = array(); $student_info = array(); $class_student = array(); $student_class_ids = array(); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status)); if($student_class_data) { foreach($student_class_data as $v) { if($chooseStudentArr && in_array($v->student_id, $chooseStudentArr)){ $student_ids[$v->student_id] = $v->student_id; $userno[$v->student_id] = $v->userno; $class_student[$v->student_id] = $v; } } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_data = SStudentInfo::model()->findAll($criteria); if($student_data) { foreach($student_data as $v) { $student_names[$v->student_id] = $v->realname; $student_info[$v->student_id] = $v; } } unset($student_data); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data) { foreach($b_student_data as $v) { $student_cards[$v->student_id] = $v->student_card; if($v->school_student_card) { $school_student_cards[$v->student_id] = $v->school_student_card; } //$school_student_cards[$v->student_id] = $v->school_student_card; } } unset($b_student_data); $data['student_names'] = $student_names; $data['student_cards'] = $student_cards; $data['student_ids'] = $student_ids; $data['school_student_cards'] = $school_student_cards; $data['student_userno'] = $userno; $data['student_info'] = $student_info; $data['class_student'] = $class_student; $data['student_class_ids'] = $student_class_ids; } unset($student_class_data); return $data; } public function getInClassStudents($class_ids) { $data = array(); $student_ids = array(); $student_names = array(); $student_cards = array(); $school_student_cards = array(); $userno = array(); $serial_number = array(); $student_class_ids = array(); $student_info = array(); $class_student = array(); $id_number = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $criteria->order = 'serial_number desc,class_id desc'; $student_class_data = SStudentClassRelation::model()->findAll($criteria); if($student_class_data) { foreach($student_class_data as $key=>$v) { if(isset($serial_number[$v->class_id])) { if($serial_number[$v->class_id]<$v->serial_number) { $serial_number[$v->class_id] = $v->serial_number; } }else { $serial_number[$v->class_id] = $v->serial_number; } $student_ids[$v->student_id] = $v->student_id; $userno[$v->student_id] = $v->userno; $class_student[$v->student_id] = $v; $student_class_ids[$v->student_id] = $v->class_id; } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_data = SStudentInfo::model()->findAll($criteria); if($student_data) { foreach($student_data as $v) { $student_names[$v->student_id] = $v->realname; $student_info[$v->student_id] = $v; $id_number[$v->student_id] =$v->id_number; } } unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data) { foreach($b_student_data as $v) { $student_cards[$v->student_id] = $v->student_card; if($v->school_student_card) { $school_student_cards[$v->student_id] = $v->school_student_card; } } } $data['student_names'] = $student_names; $data['student_cards'] = $student_cards; $data['student_ids'] = $student_ids; $data['school_student_cards'] = $school_student_cards; $data['student_userno'] = $userno; $data['student_info'] = $student_info; $data['class_student'] = $class_student; $data['student_class_ids'] = $student_class_ids; $data['serial_number'] = $serial_number; $data['id_number'] =$id_number; } return $data; } // 查看班级学生 public function actionView(){ $get_id = safe_replace(Yii::app()->request->getQuery('cid')); if (empty($get_id)) { Yii::app()->jump->error('无法访问!'); } $semesterId = $this->schoolManager->getSemesterIdByClassId($get_id); $data = array(); $data["semesterId"] = $semesterId; $data["model"] = new Model(); $data["isCurrentSemester"] = $this->schoolManager->isCurrentSemester($semesterId); /*$get_list = StudentInfo::model()->getUserList(array($get_id)); $data['studentList'] = $get_list['result']; $data['pages'] = $get_list['page']; $data['page_total'] = $get_list['page_total'];*/ $get_list = $this->schoolManager->getClassStudentsList($get_id); $team_student=$this->schoolManager->getTeamByClass($get_id,'student'); //所有学生列表 $student_ids = array(); $b_student_arr = array(); $school_student_card = array(); $z_student_arr = array(); if($get_list && isset($get_list['rs']) && !empty($get_list['rs'])) { foreach($get_list['rs'] as $k => $v) { $student_ids[$v['student_id']] = $v['student_id']; if(isset($team_student[$v['student_id']])){ $get_list['rs'][$k]['team']=$team_student[$v['student_id']]; } } if($student_ids){ $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data) { foreach($b_student_data as $v) { $b_student_arr[$v->student_id] = $v->student_card; $school_student_card[$v->student_id] = $v->school_student_card; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $z_student_arr[$v->student_id] = $v->zhixue_student_card; } } } } } $data['b_student'] = $b_student_arr; $data['school_card'] = $school_student_card; $data['z_student'] = $z_student_arr; $data['studentList'] = Arr::toObj($get_list['rs']); $data["students"] = $get_list; $data['pages'] = $get_list['pager']; $data['page_total'] = $get_list['pager']->rowsCount; $data["cid"] = $get_id; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } $this->render('view',$data); } //预生成学生ID private function createStudentId($num) { return $this->createId($num); } //预生成系统准考证号 private function createCard($num) { $cards = array(); $student_cart = 0; if(!$num) { return $cards; } /* $b_student_data = BusinessStudent::model()->find(array( 'select' => 'student_card', 'order' => 'student_card desc', 'condition' => 'school_id=:school_id', 'limit' => 1, 'params' => array(':school_id'=>$this->schoolId) )); */ $b_student_data=$this->conn->createCommand("SELECT student_card FROM (SELECT student_card FROM `student` `t` WHERE school_id='".$this->schoolId."') sc ORDER BY student_card DESC LIMIT 1;")->queryRow(); if($b_student_data) { if(!$b_student_data['student_card']) { if($this->schoolId<100) { $student_cart = '9'.$this->schoolId.'00100'; }else { $student_cart = $this->schoolId.'00100'; } }else { $student_cart = $b_student_data['student_card']; } }else { if($this->schoolId<100) { $student_cart = '9'.$this->schoolId.'00100'; }else { $student_cart = $this->schoolId.'00100'; } } unset($b_student_data); for($i=1;$i<=$num;$i++) { $cards[$student_cart+$i] = array( 'student_card'=>$student_cart+$i, 'use'=>0, 'order'=>$i ); } return $cards; } private function addSetUUID($_uuid_arr) { if($_uuid_arr) { Yii::app()->business_uuid_cache->hmset('redis_business_uuid:'.$this->schoolId,$_uuid_arr); } } private function UUID_log($sum) { Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入学生成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time())); } //优化导入学生 public function actionImport() { ini_set('memory_limit','300M'); $error_msg = array(); //sql $student_sql = ''; $student_info_sql = ''; $student_info_arr = array(); $student_sql_arr = array(); $class_student_sql = ''; $class_student_sql_arr = array(); $sql_count = 0; $update_student_id = array(); $bstudents = new BusinessStudent(); $sstudentinfo = new SStudentInfo(); $sstudentclassrelation = new SStudentClassRelation(); if (Yii::app()->request->getIsPostRequest()){ $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/"); $uploader->allowTypes = array("xls"); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId)); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if(!$file || !isset($file["error"])) Yii::app()->jump->error('请选择上传的Excel!'); if($file["error"] != 0){ switch($file["error"]){ case 2001: Yii::app()->jump->error('文件类型不符'); break; case 2002: Yii::app()->jump->error('文件大小超出允许范围'); break; default: Yii::app()->jump->error('上传失败'); break; } } $result = true; $inputFileName = $file["src"]; if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '导入学生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$inputFileName)), "date"=>date('Y-m-d H:i:s') ))); } if ($result) { $semesterId = $this->semesterId; Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); // 读取Excel文档 $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); //FIXME 20191202 @unlink($file["src"]); // 去掉导航 //dump($sheetData);die; unset($sheetData[1]); krsort($sheetData); $serial_number = 0; $get_id = 0; $b_student_cards = array(); $b_id_student_cards = array(); $b_school_student_cards = array(); $b_id_school_student_cards = array(); $b_id_zhixue_student_cards = array(); $b_student_ids = array(); $b_student = array(); $class_ids = array(); $c_class_names = array(); $grade = 0; $uuid = 0; $n_class_id = array(); $n_student_ids = array(); $class_grade = array(); $class_serial_number = array(); $s_student_ids = array(); $d_student_ids = array();// 删除学生ID $d_student_card = array(); $d_student_names = array(); $d_school_student_card = array(); $use_student_card = array(); $use_school_student_card = array(); $use_zhixue_student_card = array(); $students = array(); $cards = array(); $_school_cards = array(); $_zhixue_cards = array(); $student_info_name = array(); $student_names = array(); $school_student_names = array(); $school_student_info = array(); $_class_ids = array(); $del_class_student = array(); //获当前学校的学生准考证号 ////////////////////优化前 // $b_student_all_data = BusinessStudent::model()->findAll(array( // 'order' => 'student_id desc', // 'condition' => 'school_id=:school_id', // 'params' => array(':school_id'=>$this->schoolId) // )); // // if($b_student_all_data) // { // foreach($b_student_all_data as $k=>$v) // { // // $b_student[$v->student_id] = $v; // $b_student_ids[$v->student_id] = $v->student_id; // $b_id_student_cards[$v->student_id] = $v->student_card; // $b_id_school_student_cards[$v->student_id] = (string)$v->school_student_card; // $b_id_zhixue_student_cards[$v->student_id] = (string)$v->school_student_card; // if($v->student_card) // { // $b_student_cards[$v->student_card] = $v->student_id; // } // if($v->school_student_card) // { // $b_school_student_cards[$v->school_student_card] = $v->student_id; // } // // // // } // } // unset($b_student_all_data); /////////////////////////////优化后 $b_student_all_data = $bstudents->getStudentsByPages($this->schoolId); if($b_student_all_data){ if(isset($b_student_all_data['b_student'])){ $b_student = $b_student_all_data['b_student']; } if(isset($b_student_all_data['b_student_ids'])){ $b_student_ids = $b_student_all_data['b_student_ids']; } if(isset($b_student_all_data['b_id_student_cards'])){ $b_id_student_cards = $b_student_all_data['b_id_student_cards']; } if(isset($b_student_all_data['b_id_school_student_cards'])){ $b_id_school_student_cards = $b_student_all_data['b_id_school_student_cards']; } if(isset($b_student_all_data['b_id_zhixue_student_cards'])){ $b_id_zhixue_student_cards = $b_student_all_data['b_id_zhixue_student_cards']; } if(isset($b_student_all_data['b_student_cards'])){ $b_student_cards = $b_student_all_data['b_student_cards']; } if(isset($b_student_all_data['b_school_student_cards'])){ $b_school_student_cards = $b_student_all_data['b_school_student_cards']; } } unset($b_student_all_data); ///////////////////ending //获取当前学校所有学生信息 ////////////////优化前 // $student_info_data = SStudentInfo::model()->findAll(); // if($student_info_data) // { // foreach($student_info_data as $v) // { // $school_student_info[$v->student_id] = $v; // $school_student_names[$v->student_id] = $v->realname; // } // // } // // unset($student_info_data); //////////////////////优化后 $student_info_data = $sstudentinfo->getStudentsByPages(); if($student_info_data){ if(isset($student_info_data['school_student_info'])){ $school_student_info = $student_info_data['school_student_info']; } if(isset($student_info_data['school_student_names'])){ $school_student_names = $student_info_data['school_student_names']; } } unset($student_info_data); ///////////////////////ending // 获取当前学期的所有班级 $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId)); if($class_semester_data) { foreach($class_semester_data as $v) { $class_ids[$v->class_id] = $v->class_id; $c_class_names[$v->class_id] = (string)$v->class_name; //$class_grade[$v->class_id] = $v->grade; } } unset($class_semester_data); if(!$class_ids) { Yii::app()->jump->error('无班级信息,导入失败'); } // 获取年级信息 /*$grade_data = SGradeModel::model()->findAll(); if(!$grade_data) { Yii::app()->jump->error('此班级无年级信息,导入失败'); }*/ $sheetData = array_reverse($sheetData); // 获取在线学生 $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=0'); $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria); unset($criteria); if($semester_student_class_data) { foreach($semester_student_class_data as $v) { //在线学生ID $s_student_ids[$v->student_id] = $v->student_id; //在线学生准考证号 if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id])) { $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id; } //在线学校准考证号 if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id])) { $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id; } //在线智学网准考证号 if(isset($b_id_zhixue_student_cards[$v->student_id]) && !empty($b_id_zhixue_student_cards[$v->student_id])) { $use_zhixue_student_card[$b_id_zhixue_student_cards[$v->student_id]] = $v->student_id; } //获取在线学生信息 if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id])) { $student_names[$v->student_id] = $school_student_names[$v->student_id]; } //获取班级中的最大序号 if(isset($class_serial_number[$v->class_id])) { if($class_serial_number[$v->class_id]<$v->serial_number) { $class_serial_number[$v->class_id] = $v->serial_number; } }else { $class_serial_number[$v->class_id] = $v->serial_number; } } } unset($semester_student_class_data); //获取已删除的学生信息 $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=1'); $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria); unset($criteria); if($semester_student_class_data) { foreach($semester_student_class_data as $v) { //已删除学生ID $d_student_ids[$v->student_id] = $v->student_id; //在线学生准考证号 if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id])) { $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id; } //在线学校准考证号 if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id])) { $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id; } //获取在线学生信息 if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id])) { $d_student_names[$v->student_id] = $school_student_names[$v->student_id]; } } } unset($semester_student_class_data); $sheetData_sun = count($sheetData); //预定学生准考证号 $create_card_data = $this->createCard($sheetData_sun); //预定学生ID $create_student_ids = $this->createStudentId($sheetData_sun); if(!$create_student_ids) { Yii::app()->jump->error('预定学生ID不足,请联系技术人员'); } foreach ($sheetData as $key=>$val) { if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) { continue; } if(count($val) != 7) { Yii::app()->jump->error('导入学生格式有误! '); } if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空'; $error_msg[$key]['so_msg'] = '按照示例格式填写表格'; continue; } $val['A'] = (string)$val['A']; $card = 0; //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B'])); $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B'])); $username = $realname; if (isset($val['E'])) { $card = safe_replace($val['E']); } if (in_array($username, $students)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '表格中存在姓名重复'; $error_msg[$key]['so_msg'] = '在表格中删除重复学生'; continue; } $students[] = $username; //验证系统准考证号 if (!empty($card)) { if (in_array($card, $cards)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '表格中存在系统准考证号'; $error_msg[$key]['so_msg'] = '在表格中删除重复系统准考证号'; continue; } $cards[] = $card; } if (isset($val['F']) && !empty($val['F'])) { $school_card = safe_replace($val['F']); //验证学校准考证号 if (!empty($school_card)) { if (isset($_school_cards[$school_card]) && !empty($_school_cards[$school_card])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '表格中存在学校准考证号'; $error_msg[$key]['so_msg'] = '在表格中删除重复学校准考证号'; continue; } if(!is_numeric($school_card)){ $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学校准考证号格式不正确'; $error_msg[$key]['so_msg'] = '学校准考证号只能由数字组成'; continue; } $_school_cards[$school_card] = $school_card; } } if (isset($val['G']) && !empty($val['G'])) { $zhixue_student_card = safe_replace($val['G']); //验证智学网准考证号 if (!empty($zhixue_student_card)) { if (in_array($zhixue_student_card, $_zhixue_cards)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '表格中存在智学网准考证号'; $error_msg[$key]['so_msg'] = '在表格中删除重复智学网准考证号'; continue; } if(!is_numeric($zhixue_student_card)){ $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '智学网准考证号格式不正确'; $error_msg[$key]['so_msg'] = '智学网准考证号只能由数字组成'; continue; } $_zhixue_cards[] = $zhixue_student_card; } } } foreach ($sheetData as $key=>$val) { if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) { continue; } if(count($val) != 7) { Yii::app()->jump->error('导入学生格式有误! '); } if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空'; $error_msg[$key]['so_msg'] = '按照示例格式填写表格'; continue; } $val['A'] = (string)$val['A']; $class_name = $val['A']; if(!in_array($class_name,$c_class_names)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '此班级不存在'; $error_msg[$key]['so_msg'] = '填写存在班级名称'; continue; } $get_id = array_search($class_name,$c_class_names,TRUE); if(!$get_id){ $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '此班级不存在'; $error_msg[$key]['so_msg'] = '班级名称填写不正确'; continue; } $_class_ids[$get_id] = $get_id; //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B'])); $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B'])); $sex = safe_replace($val['C']); $userno = safe_replace($val['D']); $card = 0; $username = $realname; if (isset($val['E'])) { $card = safe_replace($val['E']); } if(!isset($class_serial_number[$get_id])) { $class_serial_number[$get_id] = 0; } $school_card = ''; if (isset($val['F']) && !empty($val['F'])) { $school_card = safe_replace($val['F']); //验证学校准考证号 /*if (strlen($school_card) != $grade_data->card_length) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学校准考证号长度不正确'; $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。'; continue; }*/ if (!$card && $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学校准考证号已存在'; $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号'; continue; }else { if (isset($use_student_card[$card])) { if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) { $c_student_id = 0; $c_student_id = $use_student_card[$card]; $s_student_id = $use_school_student_card[$school_card]; if($c_student_id != $s_student_id) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学校准考证号已存在'; $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号'; continue; } } }else { if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学校准考证号已存在'; $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号'; continue; } } } } //智学网 $zhixue_student_card = ''; if (isset($val['G']) && !empty($val['G'])) { $zhixue_student_card = safe_replace($val['G']); if (!$card && $use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card])) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '智学网准考证号已存在'; $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号'; continue; }else { if (isset($use_student_card[$card])) { if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card])) { $c_student_id = 0; $c_student_id = $use_student_card[$card]; $z_student_id = $use_zhixue_student_card[$zhixue_student_card]; if($c_student_id != $z_student_id) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '智学网准考证号已存在'; $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号'; continue; } } }else { if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card])) { $c_student_id = $use_student_card[$card]; $z_student_id = $use_zhixue_student_card[$zhixue_student_card]; if($c_student_id != $z_student_id) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '智学网准考证号已存在'; $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号'; continue; } } } } } if ($sex != '1' && $sex != '2') { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '性别填写有误'; $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)'; continue; } //判断学生是否存在 if (!$card && $student_names && $_student_id = array_search($realname, $student_names,true)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学生在该学校有重名'; $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名'; continue; } else { //验证准考证号 $is_current_student = 0; if ($card) { if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) { $is_current_student = 1; if ($school_student_names && isset($school_student_names[$use_student_card[$card]]) && $school_student_names[$use_student_card[$card]] != $realname) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号'; continue; } } //验证新导入的准考证号 if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) { //正在使用中 $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '系统准考证号正在使用中'; $error_msg[$key]['so_msg'] = '填写不存在的系统准考证号。可以使用学生管理的搜索功能检验是否存在系统准考证号'; continue; } //验证已删除的学生的准考证号 if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) { //验证删除的学生姓名是否一致 if ( $d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号'; continue; } //是否存在 if ($d_student_card == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '学生在该学校有重名'; $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名'; continue; } } //验证上学期的学生 if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) { if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号'; continue; } //是否存在 if ($is_current_student == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '该学生在该在当前学期有重名'; $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名'; continue; } }else { $error_msg[$key]['class_name'] = $val['A']; $error_msg[$key]['student_name'] = $val['B']; $error_msg[$key]['student_six'] = $val['C']; $error_msg[$key]['student_no'] = $val['D']; $error_msg[$key]['student_card'] = $val['E']; $error_msg[$key]['school_student_card'] = $val['F']; $error_msg[$key]['zhixue_student_card'] = $val['G']; $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号'; continue; } } } /////////////////////////////////////////////////////////// $sql_count = $sql_count+1; //创建学生 if (!$card ) { $student_cart = 0; foreach ($create_card_data as $v) { if ($v['use'] == 0) { $student_cart = $v['student_card']; $create_card_data[$student_cart]['use'] = 1; break; } } $studentId = current($create_student_ids); unset($create_student_ids[$studentId]); $student_cart = (int)$student_cart; $password = $student_cart; // 将学生登录账号插入主数据 $student_sql .= "(".$studentId.",'".$student_cart."',".$student_cart.",'".$school_card."','".$zhixue_student_card."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".time()."),"; $student_info_sql .= "(".$studentId.",'".$realname."',".$sex.",".$this->schoolId.",".$get_id.",'','','','','',0,".time().",".time().",0,0.00,0),"; $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),"; if($sql_count==400) { $student_sql = substr($student_sql,0,-1).';'; $student_sql_arr[] = $student_sql; $student_info_sql = substr($student_info_sql,0,-1).';'; $student_info_arr[] = $student_info_sql; $class_student_sql = substr($class_student_sql,0,-1).';'; $class_student_sql_arr[] = $class_student_sql; $student_sql = ''; $student_info_sql = ''; $class_student_sql = ''; $sql_count = 0; } } else { //学生转班 if(!$error_msg) { if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) { $studentId = $b_student_cards[$card]; if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) { $update_student_id[$studentId] = $studentId; $del_class_student[] = "delete from student_class_relation where class_id = '{$get_id}' and student_id = '{$studentId}' ;"; //StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId)); //写入数据 $b_student_obj = $b_student[$studentId]; $school_student_obj = $school_student_info[$studentId]; $student_cart = (int)$card; $password = $student_cart; $student_sql .= "(".(string)$studentId.",'".$b_student_obj['username']."',".$student_cart.",'".(!empty($school_card)?$school_card:$b_student_obj['school_student_card'])."','".(!empty($zhixue_student_card)?$zhixue_student_card:$b_student_obj['zhixue_student_card'])."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".$b_student_obj['register_time']."),"; $student_info_sql .= "(".$studentId.",'".$school_student_obj['realname']."',".$school_student_obj['sex'].",".$this->schoolId.",".$get_id.",'".$school_student_obj['family_tel']."','".$school_student_obj['telephone']."','".$school_student_obj['student_phone']."','". $school_student_obj['picture']."','".$school_student_obj['signature']."',". $school_student_obj['is_outer'].",".$school_student_obj['add_time'].",".time().",".$school_student_obj['level'].",".$school_student_obj['ave_score_rate'].",".$school_student_obj['game_stars']."),"; $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),"; if($sql_count==400) { $student_sql = substr($student_sql,0,-1).';'; $student_sql_arr[] = $student_sql; $student_info_sql = substr($student_info_sql,0,-1).';'; $student_info_arr[] = $student_info_sql; $class_student_sql = substr($class_student_sql,0,-1).';'; $class_student_sql_arr[] = $class_student_sql; $student_sql = ''; $student_info_sql = ''; $class_student_sql = ''; $sql_count = 0; } } } } } } } if($error_msg) { $this->create_import_xls($error_msg); }else { if($del_class_student){ foreach ($del_class_student as $v){ $this->sConn->createCommand($v)->execute(); } } if($student_sql) { $student_sql = substr($student_sql,0,-1).';'; $student_sql_arr[] = $student_sql; } if($student_info_sql) { $student_info_sql = substr($student_info_sql,0,-1).';'; $student_info_arr[] = $student_info_sql; } if($class_student_sql) { $class_student_sql = substr($class_student_sql,0,-1).';'; $class_student_sql_arr[] = $class_student_sql; } if(!$student_sql_arr || !$student_info_arr || !$class_student_sql_arr ) { Yii::app()->jump->error('数据有误,无法导入!');exit; } $b_sql = 'INSERT INTO `student` (`student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time`)VALUES'; $s_sql = 'INSERT INTO `student_info` (`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`)VALUES'; $c_sql = 'INSERT INTO `student_class_relation` (`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`status`)VALUES'; $transaction = Yii::app()->businessDb->beginTransaction();//建立事务 try{ if($student_sql_arr) { if($update_student_id) { /* $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$update_student_id); BusinessStudent::model()->deleteAll($criteria); unset($criteria); */ $businessStudentSql="delete from student where student_id in(".implode(',',$update_student_id).")"; $this->conn->createCommand($businessStudentSql)->execute(); } foreach($student_sql_arr as $k=>$v) { if($v==';') { Yii::app()->jump->error('数据有误,无法导入!');exit; } $this->conn->createCommand($b_sql.$v)->execute(); } } $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); Yii::app()->jump->error('上传失败,添加学生失败'); } unset($transaction); $transaction = $this->sConn->beginTransaction(); try{ if($update_student_id) { $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$update_student_id); StudentInfo::model()->deleteAll($criteria); unset($criteria); /* if($del_class_student){ foreach ($del_class_student as $v){ $this->sConn->createCommand($v)->execute(); } } */ unset($del_class_student); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$update_student_id); $criteria->addCondition('status = 0'); $criteria->addCondition('class_type = 1'); StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3),$criteria); unset($criteria); /* $StudentSql="delete from `student_info` where `student_id` in (".implode(',',$update_student_id).")"; $this->sConn->createCommand($StudentSql)->execute(); $StudentToClassSql="update `student_class_relation` set `status`=1 and `update_time`=".time()." where`student_id` in (".implode(',',$update_student_id).") and `status`=0 "; $this->sConn->createCommand($StudentToClassSql)->execute(); */ } if($student_info_arr) { foreach($student_info_arr as $k=>$v) { if($v==';') { Yii::app()->jump->error('数据有误,无法导入!');exit; } $this->sConn->createCommand($s_sql.$v)->execute(); } } if($class_student_sql_arr) { foreach($class_student_sql_arr as $k=>$v) { if($v==';') { Yii::app()->jump->error('数据有误,无法导入!');exit; } $this->sConn->createCommand($c_sql.$v)->execute(); } } $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); Yii::app()->jump->error('上传失败,添加学生失败'); } unset($create_student_ids); $this->redirect(Yii::app()->createUrl('studentinfo/index')); } } } public function actionStudent_import() { $this->render('student_import'); } // 导入学生 public function actionImport_brack() { $get_id = safe_replace(Yii::app()->request->getQuery('cid')); if (empty($get_id) || !($class = $this->schoolManager->getClass($get_id))) { Yii::app()->jump->error('无法访问!'); } if($this->schoolManager->isPreviousSemester($class["semester_id"])) { Yii::app()->jump->error('不能为已完成学期的班级导入学生!'); } if (Yii::app()->request->getIsPostRequest()){ $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/"); $uploader->allowTypes = array("xls"); $uploader->fieldsMappings = array("exname" => array(0 => $get_id)); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if(!$file || !isset($file["error"])) Yii::app()->jump->error('请选择上传的Excel!'); if($file["error"] != 0){ switch($file["error"]){ case 2001: Yii::app()->jump->error('文件类型不符'); break; case 2002: Yii::app()->jump->error('文件大小超出允许范围'); break; default: Yii::app()->jump->error('上传失败'); break; } } $result = true; $inputFileName = $file["src"]; if ($result) { $semesterId = $this->semesterId; Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); // 读取Excel文档 $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); //FIXME 2019-12-02 @unlink($file["src"]); // 去掉导航 //dump($sheetData);die; unset($sheetData[1]); krsort($sheetData); $serial_number = 0; $b_student_cards = array(); $b_id_student_cards = array(); $b_school_student_cards = array(); $b_id_school_student_cards = array(); $b_student_ids = array(); $b_student = array(); $class_ids = array(); $class_names = array(); $c_class_names = array(); $grade = 0; $n_class_id = array(); $n_student_ids = array(); $s_student_ids = array(); $d_student_ids = array();// 删除学生ID $d_student_card = array(); $d_student_names = array(); $d_school_student_card = array(); $use_student_card = array(); $use_school_student_card = array(); $error_msg = array(); $students = array(); $cards = array(); $student_info_name = array(); $student_names = array(); $school_student_names = array(); $school_student_info = array(); //获当前学校的学生准考证号 $b_student_all_data = BusinessStudent::model()->findAll(array( 'order' => 'student_card desc', 'condition' => 'school_id=:school_id', 'params' => array(':school_id'=>$this->schoolId) )); if($b_student_all_data) { foreach($b_student_all_data as $v) { $b_student[$v->student_id] = $v; $b_student_ids[$v->student_id] = $v->student_id; $b_id_student_cards[$v->student_id] = $v->student_card; $b_id_school_student_cards[$v->student_id] = $v->school_student_card; if($v->student_card) { $b_student_cards[$v->student_card] = $v->student_id; } if($v->school_student_card) { $b_school_student_cards[$v->school_student_card] = $v->student_id; } } } //获取当前学校所有学生信息 $student_info_data = SStudentInfo::model()->findAll(); if($student_info_data) { foreach($student_info_data as $v) { $school_student_info[$v->student_id] = $v; $school_student_names[$v->student_id] = $v->realname; } } $student_class_data = SStudentClassRelation::model()->find(array( 'select' => 'serial_number', 'order' => 'serial_number desc', 'condition' => 'class_id=:class_id and status=:status', 'limit' => 1, 'params' => array(':class_id'=>$get_id,':status'=>0) )); if($student_class_data) { if($student_class_data->serial_number) { $serial_number = $student_class_data->serial_number; } } // 获取当前学期的所有班级 $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId)); if($class_semester_data) { foreach($class_semester_data as $v) { $class_ids[$v->class_id] = $v->class_id; $c_class_names[$v->class_id] = $v->class_name; } } if(!$class_ids) { Yii::app()->jump->error('无班级信息,导入失败'); } // 获取年级信息 $grade_data = SGradeModel::model()->find('id=:id',array(':id'=>$class['grade'])); if(!$grade_data) { Yii::app()->jump->error('此班级无年级信息,导入失败'); } $sheetData = array_reverse($sheetData); // 获取在线学生 $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=0'); $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria); if($semester_student_class_data) { foreach($semester_student_class_data as $v) { //在线学生ID $s_student_ids[$v->student_id] = $v->student_id; //在线学生准考证号 if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id])) { $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id; } //在线学校准考证号 if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id])) { $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id; } //获取在线学生信息 if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id])) { $student_names[$v->student_id] = $school_student_names[$v->student_id]; } } } //获取已删除的学生信息 $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=1'); $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria); if($semester_student_class_data) { foreach($semester_student_class_data as $v) { //已删除学生ID $d_student_ids[$v->student_id] = $v->student_id; //在线学生准考证号 if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id])) { $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id; } //在线学校准考证号 if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id])) { $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id; } //获取在线学生信息 if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id])) { $d_student_names[$v->student_id] = $school_student_names[$v->student_id]; } } } //预定学生准考证号 $create_card_data = $this->createCard(count($sheetData)); foreach ($sheetData as $key=>$val) { if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) { continue; } if (empty($val['A']) OR empty($val['B'])) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学生姓名与性别不能为空'; $error_msg[$key]['so_msg'] = '填写正确的学生姓名与性别'; continue; } $realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['A'])); $sex = safe_replace($val['B']); $userno = safe_replace($val['C']); $card = 0; $username = $realname; if (isset($val['D'])) { $card = safe_replace($val['D']); } $school_card = ''; if (isset($val['E']) && !empty($val['E'])) { $school_card = safe_replace($val['E']); if (strlen($school_card) != $grade_data->card_length) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学校准考证号长度不正确'; $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。'; continue; } if ($use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学校准考证号已存在'; $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前期不存在的学校准考证号'; continue; } } if (in_array($username, $students)) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '表格中存在姓名重复'; $error_msg[$key]['so_msg'] = '在表格中删除重复学生'; continue; } $students[] = $username; if (!empty($card)) { if (in_array($card, $cards)) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '表格中存在姓名准考证号'; $error_msg[$key]['so_msg'] = '在表格中删除重复准考证号'; continue; } $cards[] = $card; } if ($sex != 1 && $sex != 2) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '性别填写有误'; $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)'; continue; } //判断学生是否存在 if ($student_names && $_student_id = array_search($realname, $student_names,true)) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学生在该学校有重名'; $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名'; continue; } else { //验证准考证号 if ($card) { if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) { //正在使用中 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学生准考证号正在使用中'; $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号'; continue; } //验证新导入的准考证号 if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) { //正在使用中 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '学生准考证号正在使用中'; $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号'; continue; } //验证已删除的学生的准考证号 if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) { //验证删除的学生姓名是否一致 if ($d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号'; continue; } } //验证上学期的学生 if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) { if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号'; continue; } }else { $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '准考证与姓名不一致'; $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号'; continue; } } } /////////////////////////////////////////////////////////// //创建学生 if (!$card) { $student_cart = 0; foreach ($create_card_data as $v) { if ($v['use'] == 0) { $student_cart = $v['student_card']; break; } } //$studentId = getUUID(); $studentId=getUniqueId($this->schoolId); $student_cart = (int)$student_cart; $password = $student_cart; // 将学生登录账号插入主数据 $studentModel = new BusinessStudent(); $studentModel->username = $student_cart; $studentModel->password = md5(sha1($password . 'wy') . 'fengche'); $studentModel->school_id = Yii::app()->session['coachInfo']['school_id']; $studentModel->student_id = $studentId; $studentModel->student_card = $student_cart; $studentModel->school_student_card = $school_card ? $school_card : ''; $studentModel->register_time = time(); if ($studentModel->save()) { // 学校库插入学生基本信息 $userModel = new StudentInfo(); $userModel->student_id = $studentId; $userModel->realname = $realname; $userModel->school_id = $this->schoolId; $userModel->class_id = $get_id; $userModel->add_time = time(); $userModel->sex = $sex; $userModel->telephone = ''; if ($userModel->save()) { // 创建学生与班级关联关系 $studentClass = new StudentToClass(); $studentClass->class_id = $get_id; $studentClass->student_id = $studentId; $studentClass->serial_number = $serial_number +$key+ 1; $studentClass->userno = $userno; $studentClass->update_time = time(); $studentClass->status = "0"; $studentClass->save(); } else { //数据写入失败 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '数据写入失败'; $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息'; continue; } } else { //数据写入失败 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '数据写入失败'; $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息'; continue; } $create_card_data[$student_cart]['use'] = 1; continue; } else { //学生转班 if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) { $studentId = $b_student_cards[$card]; if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) { BusinessStudent::model()->deleteAll('student_id=:sid', array(':sid' => $studentId)); StudentInfo::model()->deleteAll('student_id=:sid', array(':sid' => $studentId)); StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3), 'student_id=:sid and status = 0', array(':sid' => $studentId)); StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId)); //写入数据 $b_student_obj = $b_student[$studentId]; $school_student_obj = $school_student_info[$studentId]; $student_cart = (int)$card; $password = $student_cart; // 将学生登录账号插入主数据 $studentModel = new BusinessStudent(); $studentModel->username = $b_student_obj->username; $studentModel->password = md5(sha1($password . 'wy') . 'fengche'); $studentModel->school_id = $this->schoolId; $studentModel->student_id = $studentId; $studentModel->student_card = $student_cart; if ($school_card) { $studentModel->school_student_card = $school_card; } else { $studentModel->school_student_card = $b_student_obj->school_student_card; } $studentModel->register_time = $b_student_obj->register_time; if ($studentModel->save()) { // 学校库插入学生基本信息 $userModel = new StudentInfo(); $userModel->student_id = $studentId; $userModel->realname = $school_student_obj->realname; $userModel->sex = $school_student_obj->sex; $userModel->school_id = $this->schoolId; $userModel->class_id = $get_id; $userModel->family_tel = $school_student_obj->family_tel; $userModel->telephone = $school_student_obj->telephone; $userModel->student_phone = $school_student_obj->student_phone; $userModel->picture = $school_student_obj->picture; $userModel->signature = $school_student_obj->signature; $userModel->is_outer = $school_student_obj->is_outer; $userModel->add_time = $school_student_obj->add_time; $userModel->update_time = time(); $userModel->level = $school_student_obj->level; $userModel->ave_score_rate = $school_student_obj->ave_score_rate; $userModel->game_stars = $school_student_obj->game_stars; if ($userModel->save()) { // 创建学生与班级关联关系 $studentClass = new StudentToClass(); $studentClass->class_id = $get_id; $studentClass->student_id = $studentId; $studentClass->serial_number = $serial_number +$key+ 1; $studentClass->userno = $userno; $studentClass->update_time = time(); $studentClass->status = "0"; $studentClass->save(); } else { //数据写入失败 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '数据写入失败'; $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息'; continue; } } else { //数据写入失败 $error_msg[$key]['student_name'] = $val['A']; $error_msg[$key]['student_six'] = $val['B']; $error_msg[$key]['student_no'] = $val['C']; $error_msg[$key]['student_card'] = $val['D']; $error_msg[$key]['school_student_card'] = $val['E']; $error_msg[$key]['err_msg'] = '数据写入失败'; $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息'; continue; } continue; } } } } } if($error_msg) { $this->create_import_xls($error_msg); }else { $this->redirect(Yii::app()->createUrl('classes/view',array('cid'=>$get_id))); } } $data = array(); $data['cid'] = $get_id; $this->render('import',$data); } public function actionDelClassAct(){ $classId = Req::post("classId"); if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1)) { $rs = $this->schoolManager->delClass($classId); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '使用权限删除班级', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } }else{ $rs = $this->schoolManager->CoachdelClass($classId); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '删除班级', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } } //更新REDSI Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId); echo json_encode($rs);exit; } //删除班级前校验 public function actionCheckBeforeDelClass(){ $classId = Req::post("classId"); $result['status']=0; if(!$classId){ $result['msg']='参数错误'; exit(json_encode($result)); } $checkStatusCode=0; if($this->schoolManager->classHasStudent($classId)){ $checkStatusCode+=2; } if($this->schoolManager->classHasExam($classId)){ $checkStatusCode+=1; } $result['status']=1; $result['data']=$checkStatusCode; exit(json_encode($result)); } public function actionClassHasStudent(){ $classId = Req::get("classId"); $rs = $this->schoolManager->classHasStudent($classId); echo $rs ? 1 : 0; } public function actionDownloadStudentsQrcodesAct(){ $classId = Req::get("classId"); $studentsIds = Req::get("studentsIds"); $force = Req::get("force"); $force = $force == 1 ? true : false; $style = Req::get("style"); $amount = Req::get("amount"); $amount = Number::isInt($amount) && $amount > 0 ? $amount : 8; $filePath = Yii::app()->basePath."/../".Yii::app()->params["qrcode_path"]."schools/{$this->schoolId}/".date("Y", time())."/"; File::mkdir($filePath); //for test $force = true; $style = 1; $class = $this->schoolManager->getClass($classId); $className = $class ? $class["class_name"] : null; if($studentsIds) $studentsIds = explode(",", $studentsIds); $students = array(); $linedBy = "STUDENT"; if($studentsIds){ $students = $this->schoolManager->getStudents($studentsIds); } else if($classId){ $linedBy = "CLASSSTUDENTS"; $students = $this->schoolManager->getClassStudents($classId, null, "ARRAY"); } foreach($students as $key => $student){ $file = $filePath.$student["student_id"].".png"; if(is_file($file) && !$force) continue; $string = "{$student["student_id"]}-{$student["serial_number"]}"; QRcode::png($string, $file, "H", 2.7, 4); if(!is_file($file)){ unset($students[$key]); continue; } $src = Image::createFromFile($file); switch($style){ case 1: Image::Crop($src, array("w" => 70, "h" => 70, "x" => 8, "y" => 9), array("w" => 85, "h" => 85, "x" => "center", "y" => 0, "color" => array(255, 255, 255, 100))); Image::sign($src, "{$student["realname"]}-{$student["serial_number"]}", array("size" => 7.5, "color" => array(0, 0, 0), "x" => "center", "y" => "bottom -2")); Image::setBorder($src); break; case 2: Image::Crop($src, array("w" => 70, "h" => 70, "x" => 12, "y" => 12), array("w" => 80, "h" => 80, "x" => 3, "y" => 3, "color" => array(255, 255, 255, 0))); Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center -5", "y" => 68)); Image::sign($src, "No:{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "71", "y" => 6, "angle" => -90)); Image::setBorder($src); break; case 3: Image::Crop($src, array("w" => 70, "h" => 70, "x" => 12, "y" => 12), array("w" => 80, "h" => 80, "x" => 13, "y" => 13, "color" => array(255, 255, 255, 0))); Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center 5", "y" => 1)); Image::sign($src, "{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "2", "y" => 16, "angle" => -90)); Image::setBorder($src); break; case 4: default: $font = Image::create(25, 25, array(255, 255, 255, 0)); Image::sign($font, $student["realname"], array("size" => 7, "color" => array(0, 0, 0), "x" => "center", "y" => "center")); Image::Crop($src, array("w" => 71, "h" => 71, "x" => 8, "y" => 8), array("w" => 80, "h" => 80, "x" => "center", "y" => "center", "color" => array(255, 255, 255, 100))); $images = array( array( "res" => $font, "layer_num" => 1, "x" => "center", "y" => "center", "w" => 25, "h" => 25 ), array( "res" => $src, "layer_num" => 2, "x" => "left", "y" => "top", "w" => 80, "h" => 80 ), ); $src = Image::puzzle(array("w" => 80, "h" => 80), $images); Image::setBorder($src); break; } $students[$key]["pic"] = $file; if(!Image::saveAs($src, $file)) unset($students[$key]); } Yii::$enableIncludePath = FALSE; Yii::import('application.extensions.phpword.PHPWord', 1); $time = time(); $schoolInfo = $this->schoolManager->getSchoolInfo(); $area = $this->schoolManager->getSchoolAreaFromSchoolInfo($schoolInfo); $filename = "{$schoolInfo["school_name"]}{$className}学生的二维码"; $title = "{$schoolInfo["school_name"]}{$className}学生的二维码"; $encodeFilename = urlencode($filename); $encodeFilename = str_replace("+", "%20", $encodeFilename); $userAgent = $_SERVER["HTTP_USER_AGENT"]; // New Word Document $PHPWord = new PHPWord(); $PHPWord->setDefaultFontName('Tahoma'); $PHPWord->setDefaultFontSize(9); $properties = $PHPWord->getProperties(); $properties->setCreator('CeeFee'); $properties->setLastModifiedBy('CeeFee'); $properties->setCreated($time); $properties->setModified($time); $properties->setCompany('上海互教教育科技有限公司'); $properties->setTitle($filename); $sectionStyle = array( 'orientation' => null, 'marginLeft' => 355, 'marginRight' => 355, 'marginTop' => 900, 'marginBottom' => 900 ); // Define table style arrays $styleTable = array('borderSize' => 0, 'borderColor' => 'ffffff', 'tableAlign' => 'center', 'cellMarginTop'=>80, 'cellMarginLeft'=>80, 'cellMarginRight'=>80, 'cellMarginBottom'=>80); // Define cell style arrays $styleCell = array('marginTop' => '5', 'valign' => 'center', 'align' => 'center'); $styleCellBTLR = array('valign' => 'center', 'align' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); // Define font style for first row $fontStyle = array('align' => 'center', 'size' => 9); // Add table style $PHPWord->addTableStyle('myOwnTableStyle', $styleTable); if($linedBy == "STUDENT"){ $rowSize = 8; $pageSize = 10; $count = 0; $rowsCount = 0; $pagesCount = 0; $repeatedTimes = 1; $studentRepeatedTimes = $amount; } else{ $rowSize = 8; $pageSize = 10; $count = 0; $rowsCount = 0; $pagesCount = 0; $repeatedTimes = $amount; $studentRepeatedTimes = 1; } for($j = 0; $j < $repeatedTimes; $j++){ foreach($students as $student){ for($i = 0; $i < $studentRepeatedTimes; $i++){ if($count == $rowSize){ $count = 0; $rowsCount++; } if(($rowsCount == 0 && $pagesCount == 0) || $rowsCount == $pageSize){ $section = $PHPWord->createSection($sectionStyle); $section->addText(PHPWord_Media::UTF8ToGBK($title), array_merge($fontStyle, array('bold' => TRUE)), array('align' => 'center')); $table = $section->addTable('myOwnTableStyle'); $rowsCount = 0; $pagesCount++; } if($count == 0){ $table->addRow(300); } $table->addCell(1420, $styleCell)->addImage($student["pic"]); $count++; } } } header('Content-Type: application/msword'); if (preg_match("/MSIE/i", $userAgent) OR preg_match('/Trident/i', $userAgent)) { header('Content-Disposition: attachment; filename="'. $encodeFilename .'.docx"'); } else if (preg_match("/Firefox/i", $userAgent)) { header('Content-Disposition: attachment; filename*="utf8\'\''. $filename .'.docx"'); } else { header('Content-Disposition: attachment; filename="'. $filename .'.docx"'); } header('Cache-Control: max-age=0'); $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); } public function actionGetSubjectMaterials() { $toFiltMaterialsIds = array(13, 14, 15, 16); $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85); $subjectId = Req::get("subjectId"); $rs = Curl::post(Yii::app()->params["material_url"]."/subjectId/{$subjectId}/depth/3"); $rs = json_decode($rs, true); if(!isset($rs["status"]) && $rs){ foreach($rs as $key => $material){ if(isset($material["modules"])){ foreach($material["modules"] as $moduleKey => $module){ if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){ unset($rs[$key]["modules"][$moduleKey]); } } } if(empty($rs[$key]["modules"])) unset($rs[$key]); } } $rs = json_encode($rs); header("Content-Type: application/json"); echo $rs;exit; } // 导入学生 protected function insertNewStudent($userName_array,$password_array,$realname_array,$userno_array,$_IDX_array,$sex_array,$get_id,$_no_student_id=array()) { /** * 如果全是新学生则 * 添加三张表。分别 spider_business.student,school.student_info,school.student_class_relation */ $student_ids = array(); //添加 spider_business.student $transaction = Yii::app()->businessDb->beginTransaction();//建立事务 try{ $sql1 = ''; $sql = 'INSERT INTO `student` (`student_id`,`username`,`password`,`school_id`,`register_time`,`login_time`,`status`)VALUES'; foreach($userName_array as $username) { if($_no_student_id) { $sql1.='('.$_no_student_id[$username].',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),'; }else { //$uuid = getUUID(); $uuid=getUniqueId($this->schoolId); $sql1.='('.$uuid.',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),'; $student_ids[$username] = $uuid; } } $sql .= substr($sql1,0,-1).';'; Yii::app()->businessDb->createCommand($sql)->execute(); $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); Yii::app()->jump->error('上传失败,添加学生失败'); } unset($username); if($_no_student_id && !$student_ids) { $student_ids = $_no_student_id; } try{ $this->schoolManager->insertStudentInfoAndStudentClass($userName_array,$student_ids,$realname_array,$userno_array,$_IDX_array,$sex_array,$this->schoolId,$get_id); }catch(Exception $e) { $transaction->rollBack(); Yii::app()->jump->error('上传失败,添加学生失败'); } } public function actionSelectdel() { $classId = Req::post("classId"); $studentsIds = Req::post("studentsIds"); if($classId && $studentsIds) { if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1)) { }else { $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',explode(',',$studentsIds)); $student_paper_data = SStudentPaperRelation::model()->find($criteria); if($student_paper_data) { echo json_encode(array('status'=>-2));exit; } $http = http('service/student-delete-perm','post', $this->authUsername, explode(',',$studentsIds)); $response = formatResponse($http); if(isset($response['data']) && $response['data']){ foreach ($response['data'] as $datum){ if($datum['hasOrder']==1){ $rs=false; $code = 2001; $msg = '无法操作,该学生已存在订单数据'; echo json_encode(array('status'=>-1));exit; } } } } if(Yii::app()->params['handle_log_on_off']){ writeFileLog(jsonEncode(array( "exam_group_id" => 0, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '批量删除学生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',explode(',',$studentsIds)); $criteria->addCondition('class_id=:class_id'); $criteria->addCondition('status=:status'); $criteria->params[':class_id'] = $classId; $criteria->params[':status'] = 0; if(SStudentClassRelation::model()->updateAll(array('status'=>1),$criteria)){ echo json_encode(array('status'=>1));exit; }else { echo json_encode(array('status'=>0));exit; } } } public function actionExport() { $data = array(); $currSemester = $this->schoolManager->getCurrSemester(); $criteria = new CDbCriteria; $criteria->addCondition('end_time <= :start_time'); $criteria->params[':start_time'] = $currSemester['start_time']; $criteria->limit = 1; $criteria->order = "end_time desc"; $allSemester = Semester::model()->find($criteria); $grade = Req::post("grade"); $class_id = Req::post("class_id"); $semester_id = Req::post("semester_id"); $data['grade'] = $grade; $data['class_id'] = $class_id; $data['semester_id'] = $semester_id; if (Yii::app()->request->getIsPostRequest()) { ini_set('memory_limit','200M'); $grade = Req::post("grade"); $class_id = Req::post("class_id"); $semester_id = Req::post("semester_id"); $class_type = Req::post("class_type"); $grade_class_array = array(); $class_array = array(); $class_name_array = array(); $class_grade_array = array(); $class_student_array = array(); $c_student_array = array(); $student_class_array = array(); $student_sex_array = array(); $student_userno_array = array(); $student_username_array = array(); $student_card_array = array(); $school_student_card_array = array(); $zhixue_student_card_array = array(); $id_number_array = array(); $excel_title = '全年学生信息'; $is_class = 0; $student_serial_number_array = array(); $criteria = new CDbCriteria(); $criteria->addCondition('semester_id=:semester_id'); $criteria->params[':semester_id'] = $semester_id; foreach (Yii::app()->params['grade_list'] as $id =>$param){ $grade_name[$id]=$param['grade_name']; } $where=array(); $params=array(); if($grade){ $where[]="grade=:grade"; $params[':grade']=$grade; } if($class_id){ $where[]="class_id=:class_id"; $params[':class_id']=$class_id; $is_class=1; } if($class_type){ $where[]="class_type=:class_type"; $params[':class_type']=$class_type; } if($where){ $criteria->addCondition(implode(' and ',$where)); foreach ($params as $key =>$val){ $criteria->params[$key] = $val; } } if(isset(Yii::app()->params['grade_list'][$grade])) { $excel_title = Yii::app()->params['grade_list'][$grade]['grade_name'].'全班学生信息'; } $criteria->order = "grade asc,class_id asc"; $class_data = ClassModel::model()->findAll($criteria); unset($criteria); if($class_data) { foreach($class_data as $v) { $class_array[$v->class_id] = $v->class_id; $class_name_array[$v->class_id] = $v->class_name; $class_grade_array[$v->class_id] = $v->grade; $grade_class_array[$v->grade][$v->class_id] = array('class_id'=>$v->class_id); if($is_class) { $excel_title = $v->class_name.'学生信息'; } } unset($class_data); $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_array); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_class_data = SStudentClassRelation::model()->findAll($criteria); unset($criteria); if($student_class_data) { foreach($student_class_data as $v) { $c_student_array[$v->student_id] = $v->student_id; $student_class_array[$v->student_id] = (string)$v->class_id; $student_userno_array[$v->student_id] = $v->userno; $student_serial_number_array[$v->student_id] = $v->serial_number; $class_student_array[$v->class_id][$v->student_id] = $v->student_id; } unset($student_class_data); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$c_student_array); $criteria->order = "class_id asc"; $student_info_data = SStudentInfo::model()->findAll($criteria); unset($criteria); if($student_info_data) { foreach($student_info_data as $v) { $student_name_array[$v->student_id] = $v->realname; $student_sex_array [$v->student_id] = $v->sex; $id_number_array[$v->student_id] =$v->id_number; } } unset($student_info_data); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$c_student_array); $student_data = BusinessStudent::model()->findAll($criteria); unset($criteria); if($student_data) { foreach($student_data as $v) { $student_card_array[$v->student_id] = $v->student_card; $school_student_card_array[$v->student_id] = $v->school_student_card; $zhixue_student_card_array[$v->student_id] = $v->zhixue_student_card; } } $columnArr=array(); if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){ $columnArr=array( 'A'=>'学生ID', 'B'=>'年级', 'C'=>'班级', 'D'=>'姓名', 'E'=>'性别(1男 2女)', 'F'=>'准考证号', 'G'=>'学校准考证号', 'H'=>'智学网准考证号', 'I'=>'身份证号' ); }else{ $columnArr=array( 'A'=>'年级', 'B'=>'班级', 'C'=>'姓名', 'D'=>'性别(1男 2女)', 'E'=>'准考证号', 'F'=>'学校准考证号', 'G'=>'智学网准考证号', 'H'=>'身份证号' ); } unset($student_data); unset($c_student_array); // $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("学生信息") ->setSubject("学生信息") ->setDescription("导出学生信息") ->setKeywords("excel") ->setCategory("result file"); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); foreach ($columnArr as $key =>$val){ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($key.'1', $val); } $i = 1; foreach($grade_class_array as $ck=>$class_ids){ foreach($class_ids as $class_id) { if (isset($class_student_array[$class_id['class_id']])) { foreach ($class_student_array[$class_id['class_id']] as $v) { $i = $i + 1; $keys=array_reverse(array_keys($columnArr)); if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){ $objPHPExcel->getActiveSheet(0)->setCellValue(array_pop($keys) . $i, $v.' ',PHPExcel_Cell_DataType::TYPE_STRING); } $letter=array_pop($keys); if (isset($student_class_array[$v]) && isset($class_grade_array[$student_class_array[$v]]) && isset($grade_name[$class_grade_array[$student_class_array[$v]]])) { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $grade_name[$class_grade_array[$student_class_array[$v]]]); } else { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, ''); } $letter=array_pop($keys); if (isset($class_name_array[$class_id['class_id']])) { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $class_name_array[$class_id['class_id']]); } else { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, ''); } $letter=array_pop($keys); if (isset($student_name_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_name_array[$v]); } else { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, ''); } $letter=array_pop($keys); if (isset($student_sex_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_sex_array[$v]); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } else { $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, 1); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } $letter=array_pop($keys); if (isset($student_card_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } else { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } $letter=array_pop($keys); if (isset($school_student_card_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$school_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } else { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } $letter=array_pop($keys); if (isset($zhixue_student_card_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$zhixue_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } else { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } $letter=array_pop($keys); if (isset($id_number_array[$v])) { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$id_number_array[$v], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } else { $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@"); } } } } } unset($student_card_array); unset($school_student_card_array); unset($zhixue_student_card_array); unset($student_class_array); unset($student_userno_array); unset($student_serial_number_array); unset($class_student_array); $objPHPExcel->getActiveSheet()->setTitle($excel_title); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; }else{ Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/export')); } } } $data['semester'] = $allSemester; $data['currSemester'] = $currSemester; $this->render('export',$data); } public function actionAjax_class() { $grade = Req::post("grade"); $semester_id = Req::post("semester_id"); $class_type = Req::post("class_type"); $class_array = array(); if($grade==0 || !$semester_id) { echo json_encode(array('status'=>0,'data'=>''));exit; } if($class_type){ $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and class_type=:class_type and is_hide=0',array(':semester_id'=>$semester_id,':grade'=>$grade,':class_type'=>$class_type)); }else{ $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and is_hide=0',array(':semester_id'=>$semester_id,':grade'=>$grade)); } if($class_data) { foreach($class_data as $v) { $class_array[] = $v->attributes; } echo json_encode(array('status'=>1,'data'=>$class_array));exit; } echo json_encode(array('status'=>0,'data'=>''));exit; } //智学网 public function actionZhixue_student() { if (Yii::app()->request->getIsPostRequest()) { $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/"); $uploader->allowTypes = array("xls"); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId.date('Ymdhis',time()))); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if(!$file || !isset($file["error"])) Yii::app()->jump->error('请选择上传的Excel!'); if($file["error"] != 0){ switch($file["error"]){ case 2001: Yii::app()->jump->error('文件类型不符'); break; case 2002: Yii::app()->jump->error('文件大小超出允许范围'); break; default: Yii::app()->jump->error('上传失败'); break; } } $inputFileName = $file["src"]; $student_all_array = array(); $c_class_names = array(); $class_ids = array(); $student_name_info = array(); $student_ids = array(); $class_name = ''; $_err = array(); // 导入PHPExcel类 Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); // 读取Excel文档 $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); //FIXME 2019-12-02 @unlink($file["src"]); $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); if($class_semester_data) { foreach($class_semester_data as $v) { $class_ids[$v->class_id] = $v->class_id; $c_class_names[$v->class_name] = $v->class_id; } } $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_class_data = SStudentClassRelation::model()->findAll($criteria); if($student_class_data) { foreach($student_class_data as $v) { $student_ids[$v->student_id] = $v->student_id; } } unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_info_data = SStudentInfo::model()->findAll($criteria); if($student_info_data) { foreach($student_info_data as $v) { $student_name_info[$v->class_id][trim($v->realname)] = $v->student_id; } } if($sheetData) { unset($sheetData[1]); krsort($sheetData); $sheetData = array_reverse($sheetData); foreach ($sheetData as $key=>$val) { if ( empty($val['A']) || empty($val['B']) || empty($val['C']) ){ continue; } $class_name = trim($val['A']); $user_name = trim($val['C']); if(isset($c_class_names[$class_name]) && !empty($c_class_names[$class_name])) { $class_id = $c_class_names[$class_name]; if(isset($student_name_info[$class_id]) && !empty($student_name_info[$class_id]) ) { if(isset($student_name_info[$class_id][$user_name]) && !empty($student_name_info[$class_id][$user_name])) { $b_student_data = BusinessStudent::model()->find('student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name])); if($b_student_data) { $b_student_z_one_data = BusinessStudent::model()->find('zhixue_student_card=:zhixue_student_card',array(':zhixue_student_card'=>$val['B'])); if($b_student_z_one_data) { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '准考证已存在'; continue; } if($b_student_data->zhixue_student_card && $b_student_data->zhixue_student_card == $val['B']) { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '用户准考证已存在'; continue; }else { //写入 $flags = BusinessStudent::model()->updateAll(array('zhixue_student_card'=>$val['B']),'student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name])); if($flags) { continue; }else { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '写入失败'; continue; } } }else { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '用户不存在'; continue; } }else { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '用户不存在'; continue; } }else { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '此班级不存该用户'; continue; } }else { $_err[$key]['class_name'] = $val['A']; $_err[$key]['zhixue_student_card'] = $val['B']; $_err[$key]['username'] = $val['C']; $_err[$key]['msg'] = '班级不存在'; continue; } } if($_err) { $this->zhixue_xls($_err); }else { Yii::app()->jump->error('导入成功');exit; } } } $this->render('zhixue_student'); } protected function zhixue_xls($_err) { if(!$_err) { return false; } $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("智学网学生信息") ->setSubject("智学网学生信息") ->setDescription("导入智学网学生信息") ->setKeywords("excel") ->setCategory("result file"); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '班级') ->setCellValue('B1', '准考证号') ->setCellValue('C1', '学生姓名') ->setCellValue('D1', '错误原因'); $i = 1; foreach($_err as $v) { $i = $i + 1; $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('B' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['username']); $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['msg']); } $objPHPExcel->getActiveSheet()->setTitle('导入失败'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="导入失败.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } /** * 获取所有老师,排除其他年级的年级主任 */ public function actionGetAllTeachers() { if(Yii::app()->params['grade_list']){ foreach (Yii::app()->params['grade_list'] as $id => $val){ $grade_arr[$id]=$val['grade_name']; } } $postArr = array( 0=>'任课教师', 1=>'班主任', 2=>'教研组长', 3=>'年级主任', 4=>'任课教师', 5=>'校长', ); $result = array(); $grade = Req::post('grade'); if( Yii::app()->params['section']==1){ $firstSubjectId=3; }else{ $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject); } $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId)); if($teacher_data) { foreach($teacher_data as $v) { $teacherGrade = $v->grade?$v->grade:0; if($v->posts && $v->posts ==3){ //过滤非本年级的年级主任 if ($teacherGrade==$grade || !$teacherGrade){ $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')'; } }else{ $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')'; } } echo json_encode(array('status'=>1,'result'=>$result));exit; } echo json_encode(array('status'=>0,'result'=>$result));exit; } /** * 根据年级和学科组获取老师 */ public function actionGet_subject_teachers() { $subject_id = Req::post("subject_id"); $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三'); $postArr = array( 0=>'任课教师', 1=>'班主任', 2=>'教研组长', 3=>'年级主任', 4=>'任课教师', 5=>'校长', ); $grade = Req::post('grade'); $result = array(); if($subject_id) { $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$subject_id)); if($teacher_data) { foreach($teacher_data as $v) { $teacherGrade = $v->grade?$v->grade:0; if($v->posts && $v->posts ==3){ //过滤非本年级的年级主任 if ($teacherGrade==$grade || !$teacherGrade){ $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')'; } }else{ $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')'; } } echo json_encode(array('status'=>1,'result'=>$result));exit; } } echo json_encode(array('status'=>0,'result'=>array()));exit; } public function actionResetpwd() { if (Yii::app()->request->getIsPostRequest()) { $grade = Req::post("grade"); $class_id = Req::post("class_id"); $pwd = Req::post("pwd"); $class_ids = array(); $student_ids = array(); if($pwd) { $pwd = md5(sha1($pwd . 'wy') . 'fengche'); }else { Yii::app()->jump->error('密码能小于6位!'); } if($grade==0 && $class_id==0 ) { if(false !== BusinessStudent::model()->updateAll(array('password'=>$pwd),'school_id=:school_id',array(':school_id'=>$this->schoolId))){ Yii::app()->jump->success('保存成功
',Yii::app()->createUrl('studentinfo/index'));exit; }else { Yii::app()->jump->error('重置失败,密码与新密码一样!'); } } $class_data = ClassModel::model()->findAll('grade=:grade',array(':grade'=>$grade)); foreach($class_data as $v) { $class_ids[$v->class_id] = $v->class_id; } if($class_ids) { $criteria = new CDbCriteria(); if($grade>0 && $class_id==0) { $criteria->addInCondition('class_id',$class_ids); }else { $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $class_id; } $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_class_data = SStudentClassRelation::model()->findAll($criteria); if($student_class_data) { foreach($student_class_data as $v){ $student_ids[$v->student_id] = $v->student_id; } if($student_ids) { unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); if(false!==BusinessStudent::model()->updateAll(array('password'=>$pwd),$criteria)){ Yii::app()->jump->success('保存成功
',Yii::app()->createUrl('studentinfo/index'));exit; }else { Yii::app()->jump->error('重置失败,密码与新密码一样!'); } } } } Yii::app()->jump->error('重置失败!'); } $data = array(); $data['semester_id'] = $this->semesterId; $this->render('reset',$data); } public function create_xls($_err) { if(!$_err) { return false; } $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("导入学校准考证号") ->setSubject("导入学校准考证号") ->setDescription("导入学校准考证号") ->setKeywords("excel") ->setCategory("result file"); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '班级(当前学期唯一)') ->setCellValue('B1', '姓名(当前学期唯一)') ->setCellValue('C1', '性别(1男 2女)') ->setCellValue('D1', '学号(可填)') ->setCellValue('E1', '准考证号') ->setCellValue('F1', '学校准考证号(可填)') ->setCellValue('G1', '错误原因') ->setCellValue('H1', '处理建议'); $i = 1; foreach($_err as $v) { $i = $i + 1; $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['A']); $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['B']); $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['C']); $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['D']); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['E'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['F'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, $v['G']); $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['H']); } $objPHPExcel->getActiveSheet()->setTitle('导入学生失败'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="导入学生失败.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); } public function create_import_xls($_err) { if(!$_err) { return false; } $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("导入学生") ->setSubject("导入学生") ->setDescription("导入学生") ->setKeywords("excel") ->setCategory("result file"); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '班级(必填)') ->setCellValue('B1', '姓名(当前学期唯一)') ->setCellValue('C1', '性别(1男 2女)') ->setCellValue('D1', '学号(可填') ->setCellValue('E1', '准考证号') ->setCellValue('F1', '学校准考证号(可填)') ->setCellValue('G1', '智学网帐号(可填)') ->setCellValue('H1', '错误原因') ->setCellValue('I1', '处理建议'); $i = 1; foreach($_err as $v) { $i = $i + 1; $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']); $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['student_name']); $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['student_six']); $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['student_no']); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['school_student_card'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('G' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getNumberFormat()->setFormatCode("@"); $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['err_msg']); $objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, $v['so_msg']); } $objPHPExcel->getActiveSheet()->setTitle('导入学生失败'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="导入学生失败.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } public function actionYearReport(){ @ini_set('memory_limit', '1024M'); set_time_limit(0); ignore_user_abort(true); $data = array(); $error = ''; $year = 2018; $year_next = $year+1; if ($year%4==0&&($year%100!=0 || $year%400==0)){ $days = 366; }else{ $days = 365; } $weeks = date("W", mktime(0, 0, 0, 12, 28, $year)); $start_time = mktime(0,0,0,1,1,$year); $end_time = mktime(0,0,0,1,1,$year_next); $classIds = Req::post('classId'); // var_dump(dirname(dirname(dirname(__FILE__))));exit; if($classIds){ foreach($classIds as $cclassId){ //正在生成中 $sql = "update class set report_status = 1 where class_id = {$cclassId}"; $res = $this->sConn->createCommand($sql)->execute(); } foreach($classIds as $classId){ $studentIds = array(); $pdfArr = array(); $pdfNames = array(); //获取班级名称 $sql = "select class_name from class where class_id = {$classId}"; $res = $this->sConn->createCommand($sql)->queryRow(); if($res){ $class_name = $res['class_name']; } $sql = "select student_id from student_class_relation where class_id = {$classId} and status = 0"; $query = $this->sConn->createCommand($sql)->queryAll();//获取班级学生 if($query){ foreach($query as $k=>$v){ $studentIds[] = (string)$v['student_id']; } unset($query); } if($studentIds){ foreach($studentIds as $studentId){ //初始化数据 $methodIds = array(); $bestExam = array(); $totalExamIds = array(); $totalExamIds_subjectId = array(); $exam_count = array( 9=>array(//语文 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 3=>array(//数学 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 8=>array(//英语 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 15=>array(//政治 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 16=>array(//历史 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 17=>array(//地理 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 12=>array(//物理 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 13=>array(//化学 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 14=>array(//生物 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 19=>array(//文综 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 18=>array(//理综 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), );//考试状况 $method_mes = array( 'count' => 0, 'name' => array(), );//数学考点状况 $isp_mes = array( 'isp_days' => 0, 'isp_create' => 0, 'isp_down' => 0, 'isp_down_ratio' => 0 );//数学个性化学习宝状况 $best_exam_mes = array( 9=>array(//语文 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 3=>array(//数学 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 8=>array(//英语 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 15=>array(//政治 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 16=>array(//历史 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 17=>array(//地理 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 12=>array(//物理 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 13=>array(//化学 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 14=>array(//生物 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 19=>array(//文综 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 18=>array(//理综 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), );//最佳考试 $score_mes = array( 9=>array(//语文 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 3=>array(//数学 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 8=>array(//英语 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 15=>array(//政治 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 16=>array(//历史 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 17=>array(//地理 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 12=>array(//物理 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 13=>array(//化学 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 14=>array(//生物 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 19=>array(//文综 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 18=>array(//理综 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), );//成绩状况 $contin_weeks = 1;//连续周数 $studentId = (string)$studentId; $a[] = $studentId; //个性化学习宝使用天数 $res = $this->getHttp('order/coach/days/'.$studentId.'/'.$year, 'get'); if($res && $res['data']){ $isp_mes['isp_days'] = $res['data']; } //获取学生姓名 $sql = "select realname from student_info where student_id = {$studentId}"; $res = $this->sConn->createCommand($sql)->queryRow(); if($res){ $stu_name = $res['realname']; } //考试状况 $sql = "select e.create_time,e.name,e.exam_id,e.exam_group_id,e.subject_id,spr.is_del,spr.scoring,spr.is_isp_pdf,spr.is_wbisp_pdf,spr.is_two_isp_download,spr.is_three_isp_download,p.method_ids,p.score from exam e " . "left join exam_group eg on e.exam_group_id = eg.exam_group_id " . "left join paper p on p.exam_id = e.exam_id " . "left join student_paper_relation spr on e.exam_id = spr.exam_id " . "where spr.student_id = {$studentId} and e.status = 1 and e.upload_status = 2 and eg.status = 2 and eg.mark_status = 2 and e.create_time > {$start_time} and e.create_time < {$end_time} " . "order by e.create_time asc"; $query = $this->sConn->createCommand($sql)->queryAll(); if($query){ foreach($query as $k=>$v){ //考试状况 if(in_array($v['subject_id'],$this->mathSubjectId)){ $totalExamIds_subjectId[$v['exam_id']] = 3; $exam_count[3]['total_count'] ++; if($v['is_del'] == 1){ $exam_count[3]['del_count'] ++; }else{ $exam_count[3]['real_count'] ++; } //考点状况 $methodArr = explode(",",$v['method_ids']); if($methodArr){ foreach($methodArr as $method){ if(is_numeric($method)){ $methodIds[] = $method; } } } //个性化学习宝状况 if($v['is_isp_pdf'] == 1){ $isp_mes['isp_create'] ++; if($v['is_two_isp_download'] == 1){ $isp_mes['isp_down'] ++; } } if($v['is_wbisp_pdf'] == 1){ $isp_mes['isp_create'] ++; if($v['is_three_isp_download'] == 1){ $isp_mes['isp_down'] ++; } } //最佳考试 $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id']; $bestExam[$v['exam_group_id']]['name'] = $v['name']; $bestExam[$v['exam_group_id']]['subject_id'] = 3; $bestExam[$v['exam_group_id']]['score'] = $v['score']; $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring']; }else{ $totalExamIds_subjectId[$v['exam_id']] = $v['subject_id']; $exam_count[$v['subject_id']]['total_count'] ++; if($v['is_del'] == 1){ $exam_count[$v['subject_id']]['del_count'] ++; }else{ $exam_count[$v['subject_id']]['real_count'] ++; } //最佳考试 $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id']; $bestExam[$v['exam_group_id']]['name'] = $v['name']; $bestExam[$v['exam_group_id']]['subject_id'] = $v['subject_id']; $bestExam[$v['exam_group_id']]['score'] = $v['score']; $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring']; } //连续周数 $totalExamIds[] = $v['exam_id']; if(!isset($current_week)){ $current_week = date("W",$v['create_time']); }else{ $week_cur = date("W",$v['create_time']); if($week_cur = $current_week + 1){ $contin_weeks ++; } } } $totalExamIds = array_unique($totalExamIds); //考点状况 if($methodIds){ $count_methods = array(); foreach($methodIds as $kmed=>$vmed){ if(!isset($count_methods[$vmed])){ $count_methods[$vmed] = 1; }else{ $count_methods[$vmed]++; } } $method_mes['count'] = count(array_unique($methodIds)); unset($methodIds); if($count_methods){ arsort($count_methods); $i = 1; $methodArrIds = array(); foreach($count_methods as $k=>$v){ if($i < 6){ $methodArrIds[] = $k; } $i++; } $methods = $this->apiPost('/special/methods', array('methodIds' => $methodArrIds)); if($methods && !isset($methods->error)){ foreach($methods as $k=>$v){ $method_mes['name'][] = $v->method_name; } } } } //数学个性化学习宝状况 if($isp_mes['isp_down'] && $isp_mes['isp_create']){ $isp_mes['isp_down_ratio'] = round($isp_mes['isp_down']/$isp_mes['isp_create'],4) * 100 .'%'; } //最佳考试信息 if($bestExam){ $best_exam_msg = array(); foreach($bestExam as $k=>$v){ //获取groupId对应的examId $examIds = array(); $sql = "select exam_id from exam where exam_group_id = {$k}"; $meg = $this->sConn->createCommand($sql)->queryAll(); if($meg){ foreach($meg as $edata){ $examIds[] = $edata['exam_id']; } } if($examIds){ foreach($examIds as $examIdSc){ $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$examIdSc} order by scoring desc"; $msg = $this->sConn->createCommand($sql)->queryAll(); if($msg){ $no = 1; $no_grade = 1;//年级排名 $no_class = 1;//班级排名 $stu_no_grade = 1;//学生年级排名 $stu_no_class = 1;//学生班级排名 $total_grade = 0; $total_real_grade = 0; $total_class = 0; $total_real_class = 0; foreach($msg as $kk=>$vv){ if($no == 1){ $current_scoring = $vv['scoring']; }else{ if($vv['scoring'] < $current_scoring){ $no_grade ++; } } if($vv['is_del'] == 0){ $total_real_grade ++; } if((string)$vv['class_id'] === (string)$classId){ if(!isset($current_class_scoring)){ $current_class_scoring = $vv['scoring']; }else{ if($vv['scoring'] < $current_class_scoring){ $no_class ++; } } if($vv['is_del'] == 0){ $total_real_class ++; } $total_class ++; } if((string)$vv['student_id'] === (string)$studentId){ $stu_no_grade = $no_grade; $stu_no_class = $no_class; } $total_grade ++; $no++; } //最佳考试定义:数值“年级排名/年级有效人数”最小的一次考试 if(!isset($best_exam_msg[$v['subject_id']])){ $best_exam_msg[$v['subject_id']] = round($stu_no_grade/$total_real_grade,4); $best_exam_mes[$v['subject_id']]['name'] = $v['name']; $best_exam_mes[$v['subject_id']]['score'] = $v['score']; $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring']; $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade; $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade; $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class; $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class; }else{ $tep = round($stu_no_grade/$total_real_grade,4); if($tep < $best_exam_msg[$v['subject_id']]){ $best_exam_msg[$v['subject_id']] = $tep; $best_exam_mes[$v['subject_id']]['name'] = $v['name']; $best_exam_mes[$v['subject_id']]['score'] = $v['score']; $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring']; $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade; $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade; $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class; $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class; } } //成绩状况(统计班级上升下降次数,班级前十) if($stu_no_class <= $total_real_class * 0.1){ $score_mes[$v['subject_id']]['class_top_ten']++; } if(!isset($current_class_no)){ $current_class_no = $stu_no_class; }else{ if($stu_no_class > $current_class_no){ $score_mes[$v['subject_id']]['rise_count']++; }else if($stu_no_class < $current_class_no){ $score_mes[$v['subject_id']]['drop_count']++; } } } unset($msg); } } } } //统考排名 $sql = "select examinfo from cylet where cylet_type = 2 and create_time > {$start_time} and create_time < {$end_time}"; $json_data = $this->sConn->createCommand($sql)->queryAll(); $cylet_exam_ids = array(); if($json_data){ foreach($json_data as $cylet){ $cyletArr = json_decode($cylet['examinfo'],true); if(isset($cyletArr['exam'])){ foreach($cyletArr['exam'] as $examCy){ if(in_array($examCy,$totalExamIds)){ $cylet_exam_ids[] = $examCy; } } } } unset($json_data); } if($cylet_exam_ids){ foreach($cylet_exam_ids as $cexamId){ $this->sConn = $this->getDbConnection(); $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$cexamId} order by scoring desc"; $msg2 = $this->sConn->createCommand($sql)->queryAll(); if($msg2){ $no_cylet_grade = 1;//年级排名 $stu_no_cylet_grade = 1;//学生年级排名 $total_cylet_grade = 0; $total_cylet_real_grade = 0; foreach($msg2 as $cyScore){ if($cyScore['is_del'] == 0){ $total_cylet_real_grade ++; } $total_cylet_grade ++; if(!isset($current_cylet_scoring)){ $current_cylet_scoring = $cyScore['scoring']; }else{ if($cyScore['scoring'] < $current_cylet_scoring){ $no_cylet_grade ++; } } if((string)$vv['student_id'] === (string)$studentId){ $stu_no_cylet_grade = $no_cylet_grade; } } if($stu_no_cylet_grade <= $total_cylet_real_grade * 0.1){ $score_mes[$totalExamIds_subjectId[$cexamId]]['unified_top_ten']++; } } } } } unset($query); $data['stu_name'] = isset($stu_name)?$stu_name:'';//学生姓名 $data['class_name'] = isset($class_name)?$class_name:'';//班级名称 $data['year'] = $year; $data['year_next'] = $year_next; $data['days'] = $days; $data['weeks'] = $weeks; $data['contin_weeks'] = $contin_weeks; $data['exam_count'] = $exam_count;//考试状况 $data['score_mes'] = $score_mes;//成绩状况 $data['best_exam_mes'] = $best_exam_mes;//最佳考试 $data['method_mes'] = $method_mes;//考点状况 $data['isp_mes'] = $isp_mes;//个性化学习宝状况 //print_r($data);exit; $html = $this->renderPartial("year_report", $data, true); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/yearReport/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/assets/pdf/yearReport/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $htmlpath.=$studentId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); $htmlurl = '/assets/' . $studentId . ".html"; //访问HTML的路径 if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html"; // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']); // $pdffname = str_replace(" ", "", $pdffname) . ".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdffname=$classId."-".$studentId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " file://" . $htmlpath . " {$pdfpath}" . " 176mm*250mm ''"; } else { // echo Yii::app()->params['phantomjs'];exit; $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']); // $pdffname = str_replace(" ", "", $pdffname) . ".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdffname=$classId.'-'.$studentId.".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $top_meg = $class_name.'-'.$stu_name."-年度使用报告"; // $top_meg=iconv("UTF-8", "GBK",$top_meg); // echo $top_meg;exit; $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm {$top_meg}"; } // echo $commond;exit; $set_charset = 'export LANG=en_US.UTF-8;'; exec($set_charset.$commond, $res, $code); if(isset($res[0])){ if (strpos($res[0], 'succeed') !== false) { if ($this->file_exists($pdfpath)) { $pdfArr[] = $pdfpath; $pdfNames[] = $stu_name; } } else { } @unlink($htmlpath); } } if($pdfArr){ $report_name = $class_name.$year."年度报告.zip"; $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/year_report/'.$this->schoolId."/"; //存放生成的PDF路径 if (!is_dir($filepath)) { if (!mkdir($filepath, 0777, true)) { exit('Create directory fail1: ' . $filepath); } } $filename = dirname(dirname(dirname(__FILE__))).'/upload/year_report/'.$this->schoolId."/".$classId.'_'.$year.".zip"; //最终生成的文件名(含路径) //$filename=iconv("UTF-8", "GBK",$filename); // var_dump($filename);exit; $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) { Yii::app()->jump->error('无法打开文件,或者文件创建失败'); } foreach ($pdfArr as $k=>$val) { $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]); $res=$zip->addFile($val,$classId.$pdfNames[$k].'.pdf'); @unlink($val); } $zip->close();//关闭 //生成完成 // var_dump($filename);exit; $filename = addslashes($filename); $sql = "update class set report_status = 2,report_url='{$filename}' where class_id = {$classId}"; $res = $this->sConn->createCommand($sql)->execute(); }else{ $error = '生成pdf失败'; } }else{ $error = '暂无学生'; } } }else{ $error = '班级错误'; } // header('Content-Type: application/json'); if (!$error) { echo json_encode(array("status" => 0, "error" => "")); exit; } else { echo json_encode(array("status" => 1, "error" => $error)); exit; } } public function actiondown_load_yearreport() { $classId = safe_replace(Yii::app()->request->getQuery('classId')); $sql = "select report_url,class_name from class where class_id = {$classId}"; $data = $this->sConn->createCommand($sql)->queryRow(); $filepath = $data['report_url']; if($filepath){ if ($this->check_zip($filepath)) { Header("Content-type:application/zip"); Header("Accept-Ranges: bytes"); Header("Accept-Length: " . filesize($filepath)); Header("Content-Disposition: attachment; filename=".$data['class_name']."年度总结报告.zip"); // 输出文件内容 flush();// 刷新内容 $file=fopen($filepath,"r"); $download_rate=600; while (!feof($file)){ print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者 flush();// flush 内容输出到浏览器端 sleep(1);// 终端1秒后继续 } } else { Yii::app()->jump->error('尚未生成'); } }else{ Yii::app()->jump->error('尚未生成'); } } private function check_zip($file_path) { if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") { if (file_exists($file_path)) { return true; } } return false; } /** * 获取接口数据 * @param $url * @param $method * @param array $params * @return array */ private function getHttp($url,$method,$params = array()){ $res = http($url, $method, $this->authUsername, $params); $res = $this->handleRes($res); return $res; } /** * 处理接口返回的数据 * @param $res * @return array */ public function handleRes($res){ $result = array( 'status' => 0, 'data' => array(), 'msg' => '暂无数据', ); if($res){ $res = json_decode($res,true); if(isset($res['errCode']) && $res['errCode'] == '00'){ $result['status'] = 1; $result['data'] = isset($res['data'])?$res['data']:array(); $result['msg'] = $res['errMsg']; }else{ if(isset($res['errMsg'])){ $result['msg'] = $res['errMsg']; } } } unset($res); return $result; } public function actionAjaxGetClassesByGrade(){ $grade = Req::get("grade"); $page = Req::get("page"); $result = array(); $error = array(); $con = array(); if(!$grade){ $grade = 1; } if(!$page){ $page = 1; } $semesterId = $this->semesterId; $con[] = "c.grade = {$grade}"; $con[] = "c.semester_id = {$semesterId}"; $rs = $this->schoolManager->getClassesDetailListre($con,6); if($rs){ if($rs['rs']){ foreach($rs['rs'] as $k=>$v){ $classId = $v['class_id']; $sql = "select count(*) count from student_class_relation where class_id = {$classId} and status = 0"; $count = $this->sConn->createCommand($sql)->queryRow(); $rs['rs'][$k]['stu_count'] = $count['count']; } $result['rs'] = $rs['rs']; $result['page'] = $rs['pager']; $pages_index = $this->widget('CLinkPager', array( 'header' => '', 'firstPageLabel'=> '首页', 'lastPageLabel' => '末页', 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页', 'pages' => $result['page'], 'maxButtonCount'=> 5, ),true); $pages_index = preg_replace('//is',"",$pages_index); $result['pages_index'] = $pages_index; echo json_encode(array('status'=>1,'data'=>$result));exit; }else{ echo json_encode(array('status'=>0,'data'=>''));exit; } }else{ echo json_encode(array('status'=>0,'data'=>''));exit; } } //////设置教学进度 public function actionSettingProgress(){ $data = array(); $textbookNames = array(); $subjectId = Req::get("subjectId")?Req::get("subjectId"):3; $grade = Req::get("grade")?Req::get("grade"):1; $proId = (int)Req::get("proId"); $edit = (int)Req::get("edit"); $data['module_id'] = ''; $data['chapter_id'] = ''; $data['section_id'] = ''; //当前日期 $sdefaultDate = date("Y-m-d"); //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 $first=1; //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $w=date('w',strtotime($sdefaultDate)); //获取本周开始日期,如果$w是0,则表示周日,减去 6 天 $data['start_time']=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days')); //本周结束日期 $data['end_time']=date('Y-m-d',strtotime("{$data['start_time']} +6 days")); $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'"; $timeRange = $this->sConn->createCommand($sql)->queryRow(); if($timeRange){ $data['sem_start_time'] = date("Y-m-d",$timeRange['start_time']); $data['sem_end_time'] = date("Y-m-d",$timeRange['end_time']); }else{ $data['sem_start_time'] = ''; $data['sem_end_time'] = ''; } if($proId && $edit){ $sql = "select class_id,subject_id,grade,module_id,chapter_id,section_id,textbook_id,textbook_name,start_time,end_time from teach_progress_class where id = {$proId}"; $dataArr = $this->sConn->createCommand($sql)->queryRow(); $subjectId = $dataArr['subject_id']; $grade = $dataArr['grade']; $data['classId'] = $dataArr['class_id']; $sql = "select class_name from class where class_id = '{$dataArr['class_id']}'"; $classNameArr = $this->sConn->createCommand($sql)->queryRow(); // var_dump($classNameArr);exit; $data['className'] = $classNameArr['class_name']; $data['textbookId'] = $dataArr['textbook_id']; $data['textbook_name'] = $dataArr['textbook_name']; $data['module_id'] = $dataArr['module_id']; $data['chapter_id'] = $dataArr['chapter_id']; $data['section_id'] = $dataArr['section_id']; $data['start_time'] = date("Y-m-d",$dataArr['start_time']); $data['end_time'] = date("Y-m-d",$dataArr['end_time']); } if($subjectId == 8){ $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); foreach ($textbookData as $doc) { //var_dump($doc->attributes);exit; foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ $textbookNames[$value['textbook_id']] = $value['name']; } } } } }else{ if($grade == 3){ $newSubjectId = 6; }else{ $newSubjectId = 3; } $textbookTree = $this->apiPost('/textbook/tree', array( 'subjectId' => $newSubjectId, 'depth' => 1 )); if (! $textbookTree) { $error[] = '接口错误'; } elseif (isset($textbookTree->error)) { $error[] = '接口错误'; } else { foreach ($textbookTree as $textbook) { $textbookNames[$textbook->textbook_id] = $textbook->textbook_name; } } } $data['edit'] = $edit; // echo $edit;exit; $data['subjectId'] = $subjectId; $data['grade'] = $grade; $data['textbookName'] = $textbookNames; //var_dump($data);exit; $this->render('teach_progress',$data); } /////查看历史教学进度 public function actionViewHistoryProgress(){ //echo 11;exit; $data = array(); $classIdsInSem = array(); $subjectId = Req::get("subjectId")?Req::get("subjectId"):3; $grade = Req::get("grade")?Req::get("grade"):1; $classId = Req::get("classId")?Req::get("classId"):''; $startTime = Req::get("start_time")?Req::get("start_time"):''; $endTime = Req::get("end_time")?Req::get("end_time"):''; $page = (int)Req::get("page")?(int)Req::get("page"):1; $pagesize = 10; $status = (int)Req::get("status")?(int)Req::get("status"):0; $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'"; $timeRange = $this->sConn->createCommand($sql)->queryRow(); if($startTime){ $startTimeStr = $startTime; $startTime = strtotime($startTime); }else{ $startTimeStr = date("Y-m-d",$timeRange['start_time']); $startTime = $timeRange['start_time']; } if($endTime){ $endTimeStr = $endTime; $endTime = strtotime($endTime); }else{ $endTimeStr = date("Y-m-d",$timeRange['end_time']); $endTime = $timeRange['end_time']; } //var_dump($timeRange);exit; $classIdToName = array(); $sql = "select class_id,class_name from class where grade = {$grade} and semester_id = {$this->semesterId}"; $classData = $this->sConn->createCommand($sql)->queryAll(); if($classData){ $data['classmeg'] = $classData; foreach($classData as $class){ $classIdToName[$class['class_id']] = $class['class_name']; $classIdsInSem[] = $class['class_id']; } }else{ $data['classmeg'] = array(); } if($classIdsInSem){ $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} and end_time>={$startTime}) and class_id in (".implode(',',$classIdsInSem).")"; }else{ $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} or end_time>={$startTime}) and 1=2"; } $orderby = " order by start_time desc"; if($status == 1){//开始时间倒序 $orderby = " order by start_time desc"; }else if($status == 2){//开始时间升序 $orderby = " order by start_time asc"; }else if($status == 3){//创建时间倒序 $orderby = " order by create_time desc"; }else if($status == 4){//创建时间升序 $orderby = " order by create_time asc"; } if($classId){ $condition .= " and class_id = {$classId}"; } $condition .= $orderby; $sql = "select id,class_id,subject_id,create_time,start_time,end_time,textbook_id,textbook_name,module_id,chapter_id,section_id,textbook_id,textbook_name,is_new from teach_progress_class where ".$condition; $rs = $this->schoolManager->getTeachProgress($sql,$pagesize); if($rs['rs']){ foreach($rs['rs'] as $k=>$v){ if(isset($classIdToName[$v['class_id']])){ $rs['rs'][$k]['class_name'] = $classIdToName[$v['class_id']]; }else{ $rs['rs'][$k]['class_name'] = ''; } $rs['rs'][$k]['progress_name'] = ''; if($subjectId == 3){ if($v['module_id']){ $mArr = explode(',', $v['module_id']); foreach($mArr as $moduleId){ $moduleMessage = $this->apiPost('/textbook/module', array('moduleId' => $moduleId,'depth' => 1)); if ($moduleMessage && !isset($moduleMessage->error)) { //$rs['rs'][$k]['progress_name'] .= str_replace(array('

','

'),array('',''),$moduleMessage->module_name).','; $rs['rs'][$k]['progress_name'] .= strip_tags($moduleMessage->module_name).','; } } } if($v['chapter_id']){ $cArr = explode(',', $v['chapter_id']); foreach($cArr as $chapterId){ $chapterMessage = $this->apiPost('/textbook/chapter', array('chapterId' => $chapterId,'depth' => 1)); if ($chapterMessage && !isset($chapterMessage->error)) { //$rs['rs'][$k]['progress_name'] .= str_replace(array('

','

'),array('',''),$chapterMessage->chapter_name).','; $rs['rs'][$k]['progress_name'] .= strip_tags($chapterMessage->chapter_name).','; } } } if($v['section_id']){ $sArr = explode(',', $v['section_id']); foreach($sArr as $sectionId){ $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId,'depth' => 1)); if ($sectionMessage && !isset($sectionMessage->error)) { //$rs['rs'][$k]['progress_name'] .= str_replace(array('

','

'),array('',''),$sectionMessage->section_name).','; $rs['rs'][$k]['progress_name'] .= strip_tags($sectionMessage->section_name).','; } } } }else if($subjectId == 8){ if($v['chapter_id']){ $cArr = explode(',', $v['chapter_id']); }else{ $cArr = array(); } if($v['module_id']){ $mArr = explode(',', $v['module_id']); }else{ $mArr = array(); } if($v['section_id']){ $sArr = explode(',', $v['section_id']); }else{ $sArr = array(); } $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $km=>$vm){ if(in_array($vm['textbook_module_id'],$mArr,true)){ $rs['rs'][$k]['progress_name'] .= str_replace(array('

','

'),array('',''),$vm['name']).','; } if(isset($vm['unit']) && $vm['unit']){ foreach($vm['unit'] as $kk=>$vv){ if(in_array($vv['textbook_unit_id'],$cArr,true)){ $rs['rs'][$k]['progress_name'] .= str_replace(array('

','

'),array('',''),$vv['name']).','; } } } } } } } } } } } $data['status'] = $status; $data['start_time'] = $startTimeStr; $data['end_time'] = $endTimeStr; $data['subjectId'] = $subjectId; $data['classId'] = $classId; $data['grade'] = $grade; $data['page'] = $page; $data['pagesize'] = $pagesize; $data['rs'] = $rs; //print_r($data);exit; $this->render('view_history_progress',$data); } ////教学进度分层查看班级 public function actionAjaxGetClassesBylevel(){ $data = array(); $error = array(); $classMeg = array(); $grade = (int)Req::post("grade"); $subjectId = (int)Req::post("subjectId"); if($grade > 0){ $textbook_class = array(); $sql = "SELECT class_id,textbook_id,textbook_name FROM (SELECT class_id,textbook_id,textbook_name,create_time FROM teach_progress_class where subject_id = {$subjectId} and is_new = 1 ORDER BY create_time DESC) a GROUP BY class_id ORDER BY create_time DESC"; $textbook_class_arr = $this->sConn->createCommand($sql)->queryAll(); if($textbook_class_arr){ foreach($textbook_class_arr as $k=>$v){ $textbook_class[$v['class_id']]['textbook_id'] = $v['textbook_id']; $textbook_class[$v['class_id']]['textbook_name'] = $v['textbook_name']; } } //var_dump($textbook_class);exit; $sql = "select class_id,class_name,level from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type=1 and is_hide=0 order by level asc"; $classData = $this->sConn->createCommand($sql)->queryAll(); if($classData){ foreach($classData as $k=>$v){ if(isset($textbook_class[$v['class_id']])){ $v['textbook_id'] = $textbook_class[$v['class_id']]['textbook_id']; $v['textbook_name'] = $textbook_class[$v['class_id']]['textbook_name']; }else{ $v['textbook_id'] = 0; $v['textbook_name'] = ''; } $classMeg[$v['level']][] = $v; } } }else{ $error[] = '年级错误'; } if($error){ echo json_encode(array('status'=>0,'data'=>$classMeg,'error'=>$error));exit; }else{ echo json_encode(array('status'=>1,'data'=>$classMeg));exit; } } //知识图谱 public function actionAjaxGetSectionsByTextbookId(){ $error = array(); $result = array(); $textbookId = (int)Req::post("textbookId"); $subjectId = (int)Req::post("subjectId"); if (!$textbookId) { $error[] = '请指定教材ID!'; } if (!$subjectId) { $error[] = '请指定学科!'; } if(!$error){ if($subjectId == 3){ $textbooks = $this->apiPost('/textbook/detail', array('textbookId' => $textbookId, 'depth' => 4)); if (! $textbooks) { $error[] = '接口错误'; } elseif (isset($textbooks->error)) { $error[] = '接口错误'; } else { if(isset($textbooks->modules) && $textbooks->modules){ $a = 0; foreach($textbooks->modules as $k=>$v){ $result[$a]['module_id'] = $v->module_id; $result[$a]['module_name'] = $v->module_name; if(isset($v->chapters) && $v->chapters){ $b = 0; foreach($v->chapters as $cha){ $result[$a]['chapters'][$b]['chapter_id'] = $cha->chapter_id; $result[$a]['chapters'][$b]['chapter_name'] = $cha->chapter_name; if(isset($cha->sections) && $cha->sections){ $c = 0 ; foreach($cha->sections as $sec){ $result[$a]['chapters'][$b]['sections'][$c]['section_id'] = $sec->section_id; $result[$a]['chapters'][$b]['sections'][$c]['section_name'] = $sec->section_name; $c++; } } $b++; } } $a++; } } } }else if($subjectId == 8){ $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if($value['textbook_id'] == $textbookId){ if(isset($value['module']) && $value['module']){ $a = 0; foreach($value['module'] as $k=>$v){ $result[$a]['module_id'] = $v['textbook_module_id']; $result[$a]['module_name'] = $v['name']; if(isset($v['unit']) && $v['unit']){ $b = 0; foreach($v['unit'] as $kk=>$vv){ $result[$a]['chapters'][$b]['chapter_id'] = $vv['textbook_unit_id']; $result[$a]['chapters'][$b]['chapter_name'] = $vv['name']; $b++; } } $a++; } } } } } } } } if ($error) { echo json_encode(array('status' => 0, 'error'=> implode('
', $error))); } else { echo json_encode(array('status'=>1,'data'=>$result)); } } //插入教学进度数据 public function actionAjaxInsertTeachProgress(){ $error = array(); $subjectId = (int)Req::post("subjectId"); $grade = (int)Req::post("grade"); $classIds = Req::post("classIds"); $startTimeUnix = (int)Req::post("startTimeUnix"); $endTimeUnix = (int)Req::post("endTimeUnix"); $moduleArr = Req::post("moduleArr")?Req::post("moduleArr"):array(); $chapterArr = Req::post("chapterArr")?Req::post("chapterArr"):array(); $sectionArr = Req::post("sectionArr")?Req::post("sectionArr"):array(); $textbookId = (int)Req::post("textbookId"); $textbookName = (string)Req::post("textbookName"); $selectSectionIds = Req::post("selectSectionIds")?Req::post("selectSectionIds"):array(); $methodIds = ''; $kpIds = ''; if(!$subjectId){ $error[] = "请选择科目"; } if(!$grade){ $error[] = "请选择年级"; } if(!$classIds){ $error[] = "请选择班级"; } if(!$startTimeUnix){ $error[] = "请选择开始时间"; } if(!$endTimeUnix){ $error[] = "请选择结束时间"; } if(!$textbookId){ $error[] = "请选择教材"; } if(!$textbookName){ $error[] = "请选择教材名称"; } if($selectSectionIds && $subjectId == 3){ $methodArr = array(); $kpArr = array(); foreach($selectSectionIds as $v){ foreach($v as $sectionId){ if((int)$sectionId > 0){ $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId)); if (! $sectionMessage) { $error[] = '接口错误1'; } elseif (isset($sectionMessage->error)) { $error[] = '接口错误'; } else { if(isset($sectionMessage->kps) && $sectionMessage->kps){ foreach($sectionMessage->kps as $kk=>$vv){ $kpArr[] = $vv->kp_id; if(isset($vv->methods) && $vv->methods){ foreach($vv->methods as $med){ if(isset($med->method_id) && $med->method_id){ $methodArr[] = $med->method_id; } } } } } } } } } if($methodArr){ $methodIds = implode(',', $methodArr); } if($kpArr){ $kpIds = implode(',', $kpArr); } } if(!$error){ $time =time(); $transaction = $this->sConn->beginTransaction(); try{ foreach($classIds as $classId){ $this->sConn->createCommand("update teach_progress_class set is_new = 0 where class_id = {$classId} and subject_id={$subjectId}")->execute(); $this->sConn->createCommand()->insert('teach_progress_class',array( 'class_id' => $classId, 'subject_id' => $subjectId, 'grade' => $grade, 'semester_id' => $this->semesterId, 'textbook_id' => $textbookId, 'textbook_name' => $textbookName, 'create_time' => $time, 'start_time' => $startTimeUnix, 'end_time' => $endTimeUnix, 'module_id' => $moduleArr? implode(",", $moduleArr):'', 'chapter_id' => $chapterArr? implode(",", $chapterArr):'', 'section_id' => $sectionArr? implode(",", $sectionArr):'', 'kp_ids_selected' =>$kpIds, 'method_ids_selected' => $methodIds, 'is_new' => 1 )); } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if ($error) { echo json_encode(array('status' => 0, 'error'=> implode('
', $error))); } else { echo json_encode(array('status'=>1)); } } //删除教学进度 public function actionAjaxDelTeachProgress(){ $error = array(); $progressId = (int)Req::post("progressId"); if(!$progressId){ $error[] = "请指定教学进度"; } if(!$error){ $transaction = $this->sConn->beginTransaction(); try{ $this->sConn->createCommand("delete from teach_progress_class where id = {$progressId}")->execute(); $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if ($error) { echo json_encode(array('status' => 0, 'error'=> implode('
', $error))); } else { echo json_encode(array('status'=>1)); } } //加载班主任 public function actionLoadTeacher(){ $keyword = safe_replace(Yii::app()->request->getParam('keyword')); $result['status']=0; $data=$this->schoolManager->loadTeacher($keyword,0); $teachers=array(); if($data){ foreach ($data as $key => $v){ if(!in_array($v['posts'],array(1,2,3,5))){ continue; } $teachers[]=$v; } } $result['data']=$teachers; $result['status']=1; exit(json_encode($result)); } //走班设置 public function actionClassShift(){ $setting=$this->schoolManager->getClassShift($this->semesterId); $data['setting']=$setting; if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $data['subject']=Yii::app()->params['subjectId']; unset($data['subject'][6]); unset($data['subject'][51]); unset($data['subject'][18]); unset($data['subject'][19]); if(isset($data['subject'][20])) unset($data['subject'][20]); } $this->render('classified',$data); } //新增走班学科 public function actionAddClassified(){ $grade = (int)Req::post("grade"); $subject = Req::post("subject"); $result['status']=0; //debug($subject); if(!$grade){ $result['msg']='请选择年级'; exit(json_encode($result)); } if(!$subject){ $result['msg']='请选择学科'; exit(json_encode($result)); } $semesterId=$this->semesterId; $insertArr=array(); foreach ($subject as $val){ $check=$this->schoolManager->getClassifiedBySubject($grade,$val,$semesterId); if($check){ $result['msg']='学科:'.Yii::app()->params['subjectId'][$val]."已添加,请勿重复添加"; exit(json_encode($result)); } $insertArr[]=array( 'grade'=>$grade, 'subject_id'=>$val, 'status'=>0, 'semester_id'=>$semesterId ); } if($insertArr){ if($this->schoolManager->insertClassified($insertArr)){ $result['status']=1; exit(json_encode($result)); } } exit(json_encode($result)); } //学科走班状态设置 public function actionUpdateClassified(){ $grade = (int)Req::post("grade"); $subject = Req::post("subject"); $type=Req::post('type'); $semesterId= $this->semesterId; $result['status']=0; $rs=$this->schoolManager->updateClassifiedBySubject($grade,$subject,$semesterId,$type); if($rs){ $result['status']=1; } exit(json_encode($result)); } //添加教学班 public function actionAddClass(){ checkAuthority(2); // 非当前使用学期无法操作 $data = array(); $teachers = $this->schoolManager->getTeachers(); $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20); $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); if (Yii::app()->request->getIsPostRequest()){ $class_name = trim(Req::post("class_name")); $mid_array = array(); $subjectId = 0; $material_id = 0; $coach_id = $this->coachInfo->coach_id; $period = $thisSemester['school_year']; $teachersIds = Req::post("teacher_ids"); $subject_ids = Req::post("subject_ids"); $levelName = Req::post("level_name"); $level = array($levelName => null); $grade = Req::post("grade"); $_subject_ids = array(); if($subject_ids) { foreach($subject_ids as $v) { if(in_array($v,$_subject_ids)) { Yii::app()->jump->error('班级不能增加相同的学科教师'); } $_subject_ids[] = $v; } } if(is_array($teachersIds)){ foreach($teachersIds as $key => $val){ if(empty($val) ||(is_string($val) && trim($val) == "")) unset($teachersIds[$key]); } } if(!array_intersect_key($level, $this->class_level)) $levelName = ""; if (empty($class_name)){ Yii::app()->jump->error('班级信息未填写完整!'); } else if(empty($coach_id)){ Yii::app()->jump->error('未选择助教!'); } else if(!$teachersIds){ Yii::app()->jump->error('未选择执教老师!'); } else if(!$grade){ Yii::app()->jump->error('未选择年级!'); } $classesModel = new ClassModel(); // 判断当前学期当前班级是否已添加 if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name))) { Yii::app()->jump->error('该学期下已存在同名班级!'); } // 当前班级唯一id //$classId = getUUID(); $classId=getUniqueId($this->schoolId); if (empty($classId)) { Yii::app()->jump->error('创建班级失败!'); } // 创建班级相关事务 $transaction = $classesModel->dbConnection->beginTransaction(); try{ //创建班级与老师关系 $level=Char::letterToNum($levelName, 1); if(!$level) $level=0; if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array( 'class_id' => $classId, 'class_name' => $class_name, 'level' =>$level, 'grade' => $grade, 'semester_id' => $semesterId, 'period' => $period, 'add_time' => time(), 'coach_id' => $this->coachId, 'class_type' => 2, 'wrong_book_type' =>0, 'improve_book_type' =>0, 'wb_isp_version' => 0, ))) throw new CException("创建班级和老师关系失败"); foreach ($_subject_ids as $subject_id){ if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) { throw new CException('创建失败!'); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error($e->getMessage()); } if($this->schoolManager->isCurrentSemester($semesterId)) $this->redirect(array('classes/index?class_type=2')); else $this->redirect(array("classes/index?semesterId={$semesterId}")); } unset(Yii::app()->session['school_material']); // 获取当前学校所有助教 $coachList = array(); if(!isset(Yii::app()->session['crmUserInfo'])) { $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])); if (empty($coachList)) { Yii::app()->jump->error('系统未找到助教,请联系管理员!'); } }else { $coachList = array(Yii::app()->session['crmUserInfo']); } unset($transaction); $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3)); //$data['semester'] = $semester; $data['coachList'] = $coachList; $data["teachers"] = $teachers; $data["teacher_data"] = $teacher_data; $data["classLevels"] = $this->class_level; $data["semesters"] = $semesters; $data["semesterId"] = $semesterId; $data["thisSemester"] = $thisSemester; $this->render('add_classified',$data); } //根据年级读取走班学科 public function actionGetClassSubjectByGrade(){ $grade = Req::post("grade"); $resultType=Req::post("rtype"); $semesterId=$this->semesterId; $subjects=array(); $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId); if($rs){ foreach ($rs as $val){ if($resultType=='arr'){ $subjects[]=$val['subject_id']; }else{ $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']]; } } } $result['status']=1; $result['data']=$subjects; exit(json_encode($result)); } //编辑走班 public function actionEditClassified(){ $classId = safe_replace(Yii::app()->request->getQuery('cid')); if (empty($classId)) { Yii::app()->jump->error('操作失败!'); } // 获取当前学校所有助教 $coachList = array(); if(!isset(Yii::app()->session['crmUserInfo'])) { $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])); if (empty($coachList)) { Yii::app()->jump->error('系统未找到助教,请联系管理员!'); } }else { $coachList = array(Yii::app()->session['crmUserInfo']); } $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId); // 班级信息 //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId)); $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ"); $grade = $classInfo->grade; $teachers = $this->schoolManager->getTeachers(); $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20); if (empty($classInfo)) { Yii::app()->jump->error('未找到该班级信息!'); } $subjects=array(); $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId); if($rs){ foreach ($rs as $val){ $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']]; } } // 当前班级教练信息 $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ"); if (Yii::app()->request->getIsPostRequest()){ $class_name = trim(Req::post("class_name")); $coach_id = $this->coachId; $period = Req::post("period"); $levelName = Req::post("level_name"); $level = array($levelName => null); $teachersIds = Req::post("teacher_ids"); $subject_ids = Req::post("subject_ids"); $_subject_ids = array(); if($subject_ids) { foreach($subject_ids as $v) { if(in_array($v,$_subject_ids)) { Yii::app()->jump->error('班级不能增加相同的学科教师'); } $_subject_ids[] = $v; } } if(is_array($teachersIds)){ foreach($teachersIds as $key => $val){ if(empty($val) ||(is_string($val) && trim($val) == "")) unset($teachersIds[$key]); } } $grade = Req::post("grade"); //$semesterId = Req::post("semesterId"); if(!array_intersect_key($level, $this->class_level)) $levelName = ""; if (empty($class_name) || empty($coach_id) || !$teachersIds){ Yii::app()->jump->error('班级信息未填写完整!'); } $classesModel = new ClassModel(); // 判断当前学期当前班级是否已添加 if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name))) { if($classInfo->class_name != $class_name && !$classesModel->count('semester_id=:seid and class_name=:cname and class_id=:classId',array(':seid'=>$semesterId,':cname'=>$class_name,':classId'=>$classId))) Yii::app()->jump->error('您选择的学期已存在同名班级!'); } // 创建班级相关事务 //$transaction = Yii::app()->db->beginTransaction(); $classInfo = ClassModel::model()->find("class_id = '{$classId}'"); $transaction = $classInfo->dbConnection->beginTransaction(); try { if($classInfo->class_name != $class_name) $classInfo->class_name = $class_name; //$classInfo->period = $period; //$classInfo->grade = $grade; //$classInfo->semester_id = $semesterId; if(!$levelName){ $classInfo->level =0; }else{ $classInfo->level = Char::letterToNum($levelName, 1); } $classInfo->wrong_book_type = 0; $classInfo->improve_book_type = 0; $classInfo->wb_isp_version = 0; if(!$classInfo->save()){ throw new CException('更新失败!'); } if($classInfo->coach_id != $coach_id){ if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) { throw new CException('班级更新失败!'); } } if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId)) throw new CException("班级老师更新失败"); //清除旧关联 $this->schoolManager->DelClassSubject($classId); foreach ($_subject_ids as $subject_id){ if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) { throw new CException('创建失败!'); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error($e->getMessage()); } $this->redirect(array('classes/index?class_type=2')); } $data = array(); $class_teacher_data = array(); $subject_teacher_data = array(); $subject_teacher_array = array(); $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3)); $teachers_data = Teacher::model()->findAll('status=0'); if($teachers_data) { $gangwei = array( 0=>'任课教师', 1=>'班主任', 2=>'教研组长', 3=>'年级主任', 4=>'任课教师', 5=>'校长', ); $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三'); foreach($teachers_data as $k=>$v) { $class_teacher_data[$v->teacher_id] = $v->teacher_id; $subject_teacher_data[$v->teacher_id] = $v->subjects; $teacherGrade = $v->grade?$v->grade:0; if($v->posts==3){ //过滤本年级的年级主任 if (!$teacherGrade || $teacherGrade==$grade){ $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts]; $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost); } }else{ $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$gangwei[$v->posts]); } } } $data["teachers"] = $teachers; $data["classLevels"] = $this->class_level; $data["classTeachersIds"] = $classTeachersIds; $data['classInfo'] = $classInfo; $data['relatCoach'] = $relatCoach; $data['class_teacher'] = $class_teacher_data; $data['subject_teacher'] = $subject_teacher_data; $data['subject_teacher_array'] = $subject_teacher_array; $data["teacher_data"] = $teacher_data; $data['coachList'] = $coachList; $data["semesters"] = $semesters; $data["semester_id"] = $classInfo->semester_id; $data['subjects']=$subjects; $data['thisSemester']=$thisSemester; $this->render('edit_classified',$data); } //教学班转班 public function actionCopyClassified(){ $gradeArr=array( 1=>'高一', 2=>'高二', 3=>'高三', ); $data = array(); $cid = safe_replace(Yii::app()->request->getQuery('cid')); $classInfo = $this->schoolManager->getClassInfo($cid); $subjects=$this->schoolManager->getSubjectByClass($cid); $semestersList = $this->schoolManager->getSemesters(); if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $data['subject']=Yii::app()->params['subjectId']; unset($data['subject'][6]); unset($data['subject'][51]); unset($data['subject'][18]); unset($data['subject'][19]); if(isset($data['subject'][20])) unset($data['subject'][20]); } $data['cid'] = $cid; $data['grade']=$classInfo['grade']; $data['gradeName']=$gradeArr[$classInfo['grade']]; $data['cname'] = $classInfo['class_name']; $data['subjects'] = $subjects; $data['semester']=$semestersList; $this->render('copy_classified', $data); } //根据学期加载教学班学科 public function actionAjaxGetSubjectBySemester(){ $semester = Req::post("semester"); if(!$semester){ echo json_encode(array('status'=>0,'data'=>''));exit; } $rs=$this->sConn->createCommand("select distinct subject_id from classified where semester_id='{$semester}' and status=1")->queryAll(); $subjects=array(); if($rs){ foreach ($rs as $val){ $subjects[]=array( 'subject_id'=>$val['subject_id'], 'subject_name'=>Yii::app()->params['subjectId'][$val['subject_id']] ); } } echo json_encode(array('status'=>1,'data'=>$subjects));exit; } //根据学期学科加载年级 public function actionAjaxGetGradeBySubject(){ $semester = Req::post("semester"); $subject = Req::post("subject"); if(!$semester || !$subject){ echo json_encode(array('status'=>0,'data'=>''));exit; } $rs=$this->sConn->createCommand("select distinct grade from classified where semester_id='{$semester}' and subject_id='{$subject}' and status=1")->queryAll(); $grades=array(); $gradeText=array( 1=>'高一', 2=>'高二', 3=>'高三' ); if($rs){ foreach ($rs as $val){ $grades[]=array( 'id'=>$val['grade'], 'name'=>$gradeText[$val['grade']] ); } } echo json_encode(array('status'=>1,'data'=>$grades));exit; } //加载教学班 public function actionAjaxGetClass(){ $semester = Req::post("semester"); $subject = Req::post("subject"); $grade = Req::post("grade"); $to_class_id = Req::post("to_class_id"); if(!$semester || !$subject){ echo json_encode(array('status'=>0,'data'=>''));exit; } if($to_class_id){ $rs=$this->sConn->createCommand("SELECT c.class_id,c.class_name FROM `class_subject_relation` csr join class c on c.class_id=csr.class_id where c.grade='{$grade}' and csr.subject_id='{$subject}' and c.semester_id='{$semester}' and c.class_type=2 and c.class_id<>'{$to_class_id}' and is_hide=0")->queryAll(); }else{ $rs=$this->sConn->createCommand("SELECT c.class_id,c.class_name FROM `class_subject_relation` csr join class c on c.class_id=csr.class_id where c.grade='{$grade}' and csr.subject_id='{$subject}' and c.semester_id='{$semester}' and c.class_type=2 and is_hide=0")->queryAll(); } echo json_encode(array('status'=>1,'data'=>$rs));exit; } //校验同学期同名班级 public function actionCheckClassNameOnSameSemester(){ $className=Req::post('class_name'); $result=array(); $result['status']=0; $semesterId=$this->semesterId; $classesModel = new ClassModel(); // 判断当前学期当前班级是否已添加 $checkRepeat=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$className)); if ($checkRepeat) { if($checkRepeat->is_hide==1){ $result['status']=1; $result['data']=$checkRepeat->class_id; } } exit(json_encode($result)); } //恢复班级 public function actionRecoverClass(){ $classId = Req::post("classId"); $result=array(); $result['status']=0; if(!$classId){ exit(json_encode($result)); } $sql="update class set is_hide=0,sort=0 where class_id='{$classId}'"; if($this->sConn->createCommand($sql)->execute()){ $result['status']=1; } exit(json_encode($result)); } //隐藏班级 public function actionHideClass(){ $classId = Req::post("classId"); $result['status']=0; if(!$classId){ $result['msg']='参数错误'; exit(json_encode($result)); } if($this->schoolManager->classHasStudent($classId)){ $result['msg']='班级已关联学生不能隐藏'; exit(json_encode($result)); } $sql="update class set is_hide=1 where class_id='{$classId}'"; if($this->sConn->createCommand($sql)->execute()){ $result['status']=1; } exit(json_encode($result)); } public function actionTestQcloud(){ $qcloud=new HuaweiCloud(); $result=$qcloud->putFile('assets/data/import_score_example.xls','testupload/test/1.xls'); if($result && isset($result['Location'])){ debug($result['Location']); }else{ debug('error'); } } public function getStudentsClassNo($chooseStudentArr) { $data = array(); $student_ids = array(); $student_names = array(); $student_cards = array(); $school_student_cards = array(); $userno = array(); $student_info = array(); $class_student = array(); $student_class_ids = array(); $student_class_data=$this->sConn->createCommand("select class_id,student_id,userno from student_class_relation where student_id in(".implode(',',$chooseStudentArr).") and status=0")->queryAll(); // $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status)); if($student_class_data) { foreach($student_class_data as $v) { if($chooseStudentArr && inArray($v['student_id'], $chooseStudentArr)){ $student_ids[$v['student_id']] = $v['student_id']; $userno[$v['student_id']] = $v['userno']; $class_student[$v['student_id']] = $v; } } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_data = SStudentInfo::model()->findAll($criteria); if($student_data) { foreach($student_data as $v) { $student_names[$v->student_id] = $v->realname; $student_info[$v->student_id] = $v; } } unset($student_data); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data) { foreach($b_student_data as $v) { $student_cards[$v->student_id] = $v->student_card; if($v->school_student_card) { $school_student_cards[$v->student_id] = $v->school_student_card; } //$school_student_cards[$v->student_id] = $v->school_student_card; } } unset($b_student_data); $data['student_names'] = $student_names; $data['student_cards'] = $student_cards; $data['student_ids'] = $student_ids; $data['school_student_cards'] = $school_student_cards; $data['student_userno'] = $userno; $data['student_info'] = $student_info; $data['class_student'] = $class_student; $data['student_class_ids'] = $student_class_ids; } unset($student_class_data); return $data; } /** * 批量添加班级页面 */ public function actionBatchAdd(){ $data = array(); $this->render('batch_add',$data); } /** * 批量添加班级逻辑 */ public function actionClassImport(){ ini_set ('memory_limit', '300M'); $updateSql = $updateSqlSub = array(); $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); $period = $thisSemester['school_year']; if(!$_FILES){ Yii::app()->jump->error('文件大小超过范围'); }else { if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) { Yii::app()->jump->error('文件大小超过范围'); } } $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/"); $uploader->allowTypes = array("xls","xlsx"); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId)); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if (!$file || !isset($file["error"])) Yii::app()->jump->error('请上传的Excel!'); if ($file["error"] != 0) { switch ($file["error"]) { case 2001: Yii::app()->jump->error('文件类型不符'); break; case 2002: Yii::app()->jump->error('文件大小超出允许范围'); break; default: Yii::app()->jump->error('上传失败'); break; } } $inputFileName = $file["src"]; // 导入PHPExcel类 Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); try{ $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); //FIXME 2019-12-02 @unlink($file["src"]); }catch (Exception $e){ //FIXME 2019-12-02 @unlink($file["src"]); Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage()); } if(!$sheetData) { Yii::app()->jump->error('请正确的Excel!'); } unset($objPHPExcel); //模板校验 if(Yii::app()->params['section']==1){ $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*文理科','E'=>'*班主任','F'=>'*班主任电话','G'=>'*学科','H'=>'*老师','I'=>'*老师电话'); $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'文理科','E'=>'班主任','F'=>'班主任电话','G'=>'学科','H'=>'老师','I'=>'老师电话'); }else{ $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*班主任','E'=>'*班主任电话','F'=>'*学科','G'=>'*老师','H'=>'*老师电话'); $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'班主任','E'=>'班主任电话','F'=>'学科','G'=>'老师','H'=>'老师电话'); } $classnamsTemp = array(); if(count($excelTemp) != count($sheetData[1])){ Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传'); } foreach($excelTemp as $key=>$temp){ if(!(isset($sheetData[2][$key]) && $sheetData[2][$key] == trim($temp))){ Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传'); } } unset($sheetData[1]); unset($sheetData[2]); if(!$sheetData) { Yii::app()->jump->error('请输入班级数据'); } /** * 1.检测必填字段不为空的情况 * 2.检测字段时候符合标准 * 3.检测excel班级名称时候重复 * 4、合并单元格处理 * 5、教师账号检测 */ $classTdFirst=1; //标记合并单元格第一行 $classAndTeacherData=array(); $tableNo=0; $classTeacherRepeatCheck=array(); foreach($sheetData as $hang_no=>$hang_data){ if(trim($hang_data['A'])){ $classTdFirst=1; $tableNo=$hang_no; }else{ if(!$classAndTeacherData){ Yii::app()->jump->error('班级名称不能为空'); } $classTdFirst=0; } if($classTdFirst){ foreach($hang_data as $key=>$val){ $val = $hang_data[$key] = trim($val); if(!$val){ Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空'); } if($key=='B'){ if(!in_array($val,array_keys(Yii::app()->params['grade_config']))){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); } } if($key=='C'){ if(!in_array($val,array('A','B','C'))){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); } } if(Yii::app()->params['section']==1){ if($key=='D'){ if(!in_array($val,array('不分科','文科','理科'))){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); } } } } $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'"; $class_data = $this->sConn->createCommand($sql)->queryRow(); if($class_data){ Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传 '.$hang_data['A']); } $teacher_id = ''; $class_master_name = Yii::app()->params['section']==1?$hang_data['E']:$hang_data['D']; $class_master_phone = Yii::app()->params['section']==1?$hang_data['F']:$hang_data['E']; $sql = "select teacher_id from teacher where teacher_name = '{$class_master_name}' and posts=1"; $class_data = $this->sConn->createCommand($sql)->queryAll(); if($class_data){ $teacher_ids = _array_column($class_data, 'teacher_id'); $sql = "select teacher_id,phone_number from xb_teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_master_phone}'"; $teacherInfo = $this->conn->createCommand($sql)->queryRow(); if($teacherInfo){ $teacher_id = $teacherInfo['teacher_id']; }else{ Yii::app()->jump->error('第'.$hang_no.'行班主任与班主任电话不匹配,请核对后再上传
'.$class_master_name.":".$class_master_phone); } }else{ Yii::app()->jump->error('第'.$hang_no.'行班主任姓名不存在 '.$class_master_name); } $grade = $hang_data['B']; if($hang_data['C'] == 'A'){ $level = 1; }else if($hang_data['C'] == 'B'){ $level = 2; }else if($hang_data['C'] == 'C'){ $level = 3; } if(Yii::app()->params['section']==1){ if($hang_data['D'] == '不分科'){ $arts_science = 0; }else if($hang_data['D'] == '文科'){ $arts_science = 1; }else if($hang_data['D'] == '理科'){ $arts_science = 2; } }else{ $arts_science = 0; } //整理数据 $classAndTeacherData[$tableNo]=array( 'class_name'=>$hang_data['A'], 'grade'=>$grade, 'level'=>$level, 'arts_science'=>$arts_science, 'teacher_id'=>$teacher_id, 'teachers'=>array() ); } //关联教师数据 if(Yii::app()->params['section']==1) { $subject = trim($hang_data['G']); $teacher_name = trim($hang_data['H']); $teacher_phone = trim($hang_data['I']); }else{ $subject = trim($hang_data['F']); $teacher_name = trim($hang_data['G']); $teacher_phone = trim($hang_data['H']); } //判断教师 if(!$subject && !$teacher_name && !$teacher_phone){ //都不填,跳过 continue; }elseif($subject && $teacher_name && $teacher_phone){ //校验科目 $subjectId=array_search($subject,Yii::app()->params['subjectId']); if($subjectId==false){ Yii::app()->jump->error('第'.$hang_no.'科目不正确 '); } if(isset($classTeacherRepeatCheck[$tableNo]) && inArray($teacher_phone,$classTeacherRepeatCheck[$tableNo])){ Yii::app()->jump->error($classAndTeacherData[$tableNo]['class_name'].',老师电话有重复'.$teacher_phone); } $classTeacherRepeatCheck[$tableNo][]=$teacher_phone; //检验手机号 $getPhone = BusinessTeacher::model()->find('phone_number=:phnum ', array(':phnum' => $teacher_phone)); if (!$getPhone) { Yii::app()->jump->error('手机号'.$teacher_phone.'不存在!'); }elseif($getPhone->school_id!=$this->schoolId){ Yii::app()->jump->error('手机号'.$teacher_phone.'已在其它学校注册!'); } //校验科目 $schoolTeacher=$this->sConn->createCommand("select subjects from teacher where teacher_id='{$getPhone['teacher_id']}'")->queryRow(); if($schoolTeacher['subjects']!=$subjectId){ Yii::app()->jump->error('第'.$hang_no.'行,教师手机号与科目不匹配'.$teacher_phone); } $classAndTeacherData[$tableNo]['teachers'][]=array( 'teacher_id'=>$getPhone['teacher_id'], 'subject_id'=>$subjectId ); }elseif(!$subject ){ Yii::app()->jump->error('第'.$hang_no.'行,科目不能为空 '); }elseif(!$teacher_name){ Yii::app()->jump->error('第'.$hang_no.'行,教师姓名不能为空 '); }elseif(!$teacher_phone){ Yii::app()->jump->error('第'.$hang_no.'行,教师手机号不能为空 '); } } //校验表格内名称重复 $classNameCheck=array(); if($classAndTeacherData){ $classIds=getBatchUuid($this->schoolId,count($classAndTeacherData)); $insertClassSqlValues=array(); $insertTeacherClassRelationSqlValues=array(); $insertClassSubjectRelationSqlValues=array(); foreach ($classAndTeacherData as $key => $item){ if(in_array($item['class_name'],$classNameCheck)){ Yii::app()->jump->error('第'.$key.'行'.'表格内出现重复的班级名称,请核对后再上传 '.$item['class_name']); }else{ $classNameCheck[]=$item['class_name']; } $classId=array_pop($classIds); $insertClassSqlValues[]="('".$classId."','".$item['class_name']."','".$this->coachId."','".$this->semesterId."','".$period."','".$item['grade']."','".$item['level']."','".time()."','".$item['arts_science']."','".$item['teacher_id']."')"; if($item['teachers']){ $teacherSubjectCheck=array(); foreach ($item['teachers'] as $teacher){ if(in_array($teacher['subject_id'],$teacherSubjectCheck)){ Yii::app()->jump->error('第'.$key.'行'.'同一班级出现重复的科目,请核对后再上传 '); }else{ $teacherSubjectCheck[]=$teacher['subject_id']; } $insertTeacherClassRelationSqlValues[]= "('{$classId}', '{$teacher['teacher_id']}', '{$semesterId}')"; $insertClassSubjectRelationSqlValues[]= "('{$classId}', '{$teacher['subject_id']}')"; } } } } if($insertClassSqlValues){ $insertClassSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`arts_science`,`teacher_id`) VALUES '; $insertTeacherClassRelationSql="insert into teacher_class_relation (`class_id`,`teacher_id`,`semester_id`) values"; $insertClassSubjectRelationSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values '; $insertClassSql.=implode(',',$insertClassSqlValues); $transaction = $this->sConn->beginTransaction(); try{ $this->sConn->createCommand($insertClassSql)->execute(); if($insertTeacherClassRelationSqlValues){ $insertTeacherClassRelationSql.=implode(',',$insertTeacherClassRelationSqlValues); $this->sConn->createCommand($insertTeacherClassRelationSql)->execute(); } if($insertClassSubjectRelationSqlValues){ $insertClassSubjectRelationSql.=implode(',',$insertClassSubjectRelationSqlValues); $this->sConn->createCommand($insertClassSubjectRelationSql)->execute(); } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); debug($e); Yii::app()->jump->error('班级批量上传失败!'); } $url=$this->createUrl('/classes/index'); Yii::app()->jump->error('班级批量上传成功!',$url); }else{ Yii::app()->jump->error('没有需要更新的数据!'); } //end } /** * 批量添加教学班班级页面 */ public function actionBatchAddClass(){ $data = array(); $this->render('batch_addclass',$data); } /** * 批量添加教学班班级逻辑 */ public function actionClassImportType2(){ ini_set ('memory_limit', '300M'); $updateSql = $updateSubSql = array(); $tcrSql = array(); $semesterId = $this->semesterId; $thisSemester = $this->schoolManager->getSemester($semesterId); $period = $thisSemester['school_year']; if(!$_FILES){ Yii::app()->jump->error('文件大小超过范围'); }else { if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) { Yii::app()->jump->error('文件大小超过范围'); } } $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/"); $uploader->allowTypes = array("xls","xlsx"); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId)); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if (!$file || !isset($file["error"])) Yii::app()->jump->error('请上传的Excel!'); if ($file["error"] != 0) { switch ($file["error"]) { case 2001: Yii::app()->jump->error('文件类型不符'); break; case 2002: Yii::app()->jump->error('文件大小超出允许范围'); break; default: Yii::app()->jump->error('上传失败'); break; } } $inputFileName = $file["src"]; // 导入PHPExcel类 Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); try{ $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); //FIXME 2019-12-02 @unlink($file["src"]); }catch (Exception $e){ //FIXME 2019-12-02 @unlink($file["src"]); Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage()); } if(!$sheetData) { Yii::app()->jump->error('请正确的Excel!'); } unset($objPHPExcel); //模板校验 $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*学科','E'=>'*老师','F'=>'*老师电话'); $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'学科','E'=>'老师','F'=>'老师电话'); $classnamsTemp = array(); if(count($excelTemp) != count($sheetData[1])){ Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传'); } foreach($excelTemp as $key=>$temp){ if(!(isset($sheetData[1][$key]) && $sheetData[1][$key] == trim($temp))){ Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传'); } } unset($sheetData[1]); if(!$sheetData) { Yii::app()->jump->error('请输入教师数据'); } /** * 1.检测必填字段不为空的情况 * 2.检测字段时候符合标准 * 3.检测excel班级名称时候重复 */ foreach($sheetData as $hang_no=>$hang_data){ $subject_ids_arr = array(); $classId = getUniqueId($this->schoolId); foreach($hang_data as $key=>$val){ $val = $hang_data[$key] = trim($val); if(!$val){ Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空'); } if($key=='B'){ if(!in_array($val,array('1','2','3'))){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); }else{ // if($val == '一'){ // $grade = 1; // }else if($val == '二'){ // $grade = 2; // }else if($val == '三'){ // $grade = 3; // } $grade = $val; } } if($key=='C'){ if(!in_array($val,array('A','B','C'))){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); } } if($key=='D'){ $subject_data = explode(";",$val); foreach($subject_data as $sub_name){ $sql = "select master_subject_id from subject where subject_name = '{$sub_name}'"; $subject_info = $this->conn->createCommand($sql)->queryRow(); if(!$subject_info){ Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在'); }else{ $subject_id = $subject_info['master_subject_id']; $updateSubSql[] = array($classId,$subject_id); $subject_ids_arr[] = $subject_id; $sql = "select * from classified where subject_id='{$subject_id}' and `status`=1 and semester_id='{$semesterId}' and grade={$grade}"; $is_classified = $this->sConn->createCommand($sql)->queryRow(); if(!$is_classified){ Yii::app()->jump->error('第'.$hang_no.'行走班学科未开通,请核对后再上传
'.$sub_name); } } } } } if(in_array($hang_data['A'],$classnamsTemp)){ Yii::app()->jump->error('第'.$hang_no.'行'.'表格内出现重复的班级名称,请核对后再上传
'.$hang_data['A']); }else{ $classnamsTemp[] = $hang_data['A']; $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'"; $class_data = $this->sConn->createCommand($sql)->queryRow(); if($class_data){ Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传
'.$hang_data['A']); } } //判断学科 老师 电话数量时候一致 $teacher_data = explode(";",$hang_data['E']); $phone_data = explode(";",$hang_data['F']); if(count($subject_data) != count($teacher_data) && count($teacher_data) != count($phone_data) && count($phone_data) != count($subject_data)){ Yii::app()->jump->error('第'.$hang_no.'行 学科老师电话数量不一致'); } //判断学科 老师 电话数据是否一致 foreach($teacher_data as $te_no=>$te_data){ $class_teacher_name = $te_data; $class_teacher_phone = $phone_data[$te_no]; $class_teacher_subject = $subject_data[$te_no]; $class_teacher_subjectid = $subject_ids_arr[$te_no]; $sql = "select teacher_id,posts,grade from teacher where teacher_name = '{$class_teacher_name}' and subjects={$class_teacher_subjectid}"; $te_data = $this->sConn->createCommand($sql)->queryAll(); if($te_data){ //如果匹配到年级主任特殊处理 $teacher_ids = array(); foreach($te_data as $te_data_val){ if($te_data_val['posts'] == 3 && $te_data_val['grade'] != $grade){ }else{ $teacher_ids[] = $te_data_val['teacher_id']; } } if(!$teacher_ids){ Yii::app()->jump->error('第'.$hang_no.'行'.'年级主任与学科不对应 '.$class_teacher_subject.' '.$class_teacher_name); }else{ $sql = "select teacher_id,phone_number from xb_teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_teacher_phone}'"; $teacherInfo = $this->conn->createCommand($sql)->queryRow(); if($teacherInfo){ $teacher_id = $teacherInfo['teacher_id']; $tcrSql[] = array($classId,$teacher_id,$this->semesterId); }else{ Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传
'.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone); } } }else{ Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传
'.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone); } } if($hang_data['C'] == 'A'){ $level = 1; }else if($hang_data['C'] == 'B'){ $level = 2; }else if($hang_data['C'] == 'C'){ $level = 3; } $updateSql[] = array($classId,'"'.$hang_data['A'].'"',$this->coachId,$this->semesterId,$period,$grade,$level,time(),2); } if($updateSql && $tcrSql && $updateSubSql){ $schInsertSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`class_type`) VALUES '; $tcrInsertSql = 'INSERT INTO teacher_class_relation (`class_id`, `teacher_id`,`semester_id`) VALUES '; $schSubSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values '; foreach($updateSql as $stVal){ $schInsertSql .= '('.implode(',',$stVal).'),'; } foreach($tcrSql as $stVal){ $tcrInsertSql .= '('.implode(',',$stVal).'),'; } foreach($updateSubSql as $stVal){ $schSubSql .= '('.implode(',',$stVal).'),'; } $schInsertSql = substr($schInsertSql,0,-1); $tcrInsertSql = substr($tcrInsertSql,0,-1); $schSubSql = substr($schSubSql,0,-1); $transaction = $this->sConn->beginTransaction(); try{ $this->sConn->createCommand($schInsertSql)->execute(); $this->sConn->createCommand($tcrInsertSql)->execute(); $this->sConn->createCommand($schSubSql)->execute(); $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); Yii::app()->jump->error('班级批量上传失败!'); } $url=$this->createUrl('/classes/index?class_type=2'); Yii::app()->jump->error('班级批量上传成功!',$url); }else{ Yii::app()->jump->error('没有需要更新的数据!'); } } /** * 导出班级数据 */ public function actionExportClass(){ $excel_title = '班级信息导出'; $excel_show_title = array(1=>'班级',2=>'年级',3=>'层级',4=>'文理科',5=>'班主任',6=>'执教老师',7=>'学生人数'); $excel_show_msg = array(1=>'class_name',2=>'grade',3=>'level',4=>'arts_science',5=>'master_name',6=>'teacher_names',7=>'student_count'); $realname = (string)Req::get("realname"); $grade = (int)Req::get("grade"); $arts_science = (int)Req::get("arts_science"); $class_type = (int)Req::get("class_type"); $smid = safe_replace(Yii::app()->request->getParam('semesterId')); $choose_type = (string)Req::get("choose_type");//需要导出excel哪些数据 if($choose_type){ $choose_type_arr = explode(',',$choose_type); } $condition = array(); if(!$smid){ $smid = $this->semesterId; } $condition[] = "seme.semester_id = '{$smid}'"; $condition[] = "c.class_type={$class_type}"; $condition[] = "c.is_hide=0"; if($grade){ $condition[] = "c.grade={$grade}"; } if($arts_science == 1){ $condition[] = "c.arts_science=1"; }else if($arts_science == 2){ $condition[] = "c.arts_science=2"; } if($realname){ $condition[] = "c.class_name like '%{$realname}%'"; } $condition = " where ".implode(" and ", $condition); $sql = "select c.class_id,c.class_name,c.grade,c.level,c.arts_science,c.teacher_id from class as c join semester as seme on seme.semester_id = c.semester_id {$condition} order by c.sort!=0 desc,c.sort,c.class_id desc"; $class_data = $this->sConn->createCommand($sql)->queryAll(); if($class_data){ foreach($class_data as $k=>$v){ //获取班主任姓名 $class_data[$k]['master_name'] = ''; if($v['teacher_id']){ $sql = "select teacher_name from teacher where teacher_id = '{$v['teacher_id']}'"; $teacher_data = $this->sConn->createCommand($sql)->queryRow(); if($teacher_data){ $class_data[$k]['master_name'] = $teacher_data['teacher_name']; } } //获取执教老师姓名 $class_data[$k]['teacher_names'] = ''; $sql = "select t.teacher_name from teacher_class_relation tcr join teacher t on tcr.teacher_id = t.teacher_id where tcr.class_id='{$v['class_id']}'"; $teacher_msg = $this->sConn->createCommand($sql)->queryAll(); if($teacher_msg){ $teacher_names = _array_column($teacher_msg, 'teacher_name'); $class_data[$k]['teacher_names'] = implode(';',$teacher_names); } //获取学生人数 $class_data[$k]['student_count'] = ''; $sql = "select count(student_id) count from student_class_relation where class_id='{$v['class_id']}' and `status`=0"; $student_data = $this->sConn->createCommand($sql)->queryRow(); if($student_data){ $class_data[$k]['student_count'] = $student_data['count']; } if($v['grade'] == 1){ $class_data[$k]['grade'] = '一'; }else if($v['grade'] == 2){ $class_data[$k]['grade'] = '二'; }else if($v['grade'] == 3){ $class_data[$k]['grade'] = '三'; } if($v['level'] == 1){ $class_data[$k]['level'] = 'A'; }else if($v['level'] == 2){ $class_data[$k]['level'] = 'B'; }else if($v['level'] == 3){ $class_data[$k]['level'] = 'C'; } if($v['arts_science'] == 1){ $class_data[$k]['arts_science'] = '文科'; }else if($v['arts_science'] == 2){ $class_data[$k]['arts_science'] = '理科'; }else{ $class_data[$k]['arts_science'] = '不分科'; } } }else{ Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index')); } if($class_data){ $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("班级信息") ->setSubject("班级信息") ->setDescription("导出班级信息") ->setKeywords("excel") ->setCategory("result file"); foreach($choose_type_arr as $key=>$val){ $objPHPExcel->getActiveSheet()->getColumnDimension(numToLetter($key+1))->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->setCellValue(numToLetter($key+1).'1', $excel_show_title[$val]); } $i = 2; foreach($class_data as $k=>$v){ foreach($choose_type_arr as $key=>$val){ $objPHPExcel->getActiveSheet(0)->setCellValue(numToLetter($key+1) . $i, $v[$excel_show_msg[$val]]); } $i++; } $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; }else{ Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index')); } } }