coachId; $semester_id = $this->semesterId; $PageLimit=9; if(!$Page) $Page=1; $ZlExamGroup=new ZlExamGroup(); $result=$ZlExamGroup->getList($Grade,$Class,$semester_id,$Page,$PageLimit,$Display); $ZlStudentExamRelation=new ZlStudentExamRelation(); $ZlStudentExamRs=new ZlStudentExamRs(); if($result['data']){ foreach($result['data'] as $key=>$val){ $tpl_data=json_decode($val['zl_tpl_data'],true); $result['data'][$key]['classCount']=$tpl_data['classCount']; $result['data'][$key]['subjectCount']=count($tpl_data['items']); $subjectArr=array(); foreach ($tpl_data['items'] as $sid=>$c){ $subjectArr[]= Yii::app()->params['subjectId'][$sid]; } $result['data'][$key]['subjects']=$subjectArr; //上传进度 $allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id']); $allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id']); $result['data'][$key]['progress']=$allStudentRs.'/'.$allStudent; if($allStudentRs){ $result['data'][$key]['status']=1; }else{ $result['data'][$key]['status']=0; } } } // debug($result); $printType = '2'; $printTypeData = 0; $viewData=array( 'pageTotal' =>$result['pageTotal'], 'dataList' =>$result['data'], 'page' =>$Page, 'grade' =>$Grade, 'class' =>$Class, 'display' =>$Display, 'totalCount' =>$result['totalCount'], 'printType' =>$printType ); //$HeadInfo=$this->getHeadInfo(); // $viewData=array_merge($viewData,$HeadInfo); $this->render('index',$viewData); } public function actionEdit(){ $viewData=array(); $viewData=array( 'printType'=>'zl' ); if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $viewData['subject']=Yii::app()->params['subjectId']; unset($viewData['subject'][3]); unset($viewData['subject'][51]); unset($viewData['subject'][20]); } $exam_group_id = Req::get("exam_group_id"); if($exam_group_id){ //读取考试信息 $ZlExamGroup=new ZlExamGroup(); $ZlStudentExamRs=new ZlStudentExamRs(); $studentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($exam_group_id); if($studentRs){ Yii::app()->jump->error('已上传成绩,不能编辑考试!'); } $examData=$ZlExamGroup->getExamByExamGroupId($exam_group_id); $examView=array(); $tplData=array(); foreach ($examData as $val){ if(!$tplData){ $tplData=json_decode($val['zl_tpl_data'],true); $examView['items']=$tplData['items']; //$examView['examDate']=$tplData['examDate']; } $examView['zl_exam_name']=$val['zl_exam_name']; $examView['zl_exam_type']=$val['zl_exam_type']; $examView['examDate']=date('Y-m-d',$val['zl_exam_date']); $examView['classes'][$val['zl_class_id']]=ClassModel::model()->getClassName($val['zl_class_id']); $examView['grade']=$val['zl_grade']; } $viewData['exam']=$examView; $viewData['exam_group_id']=$exam_group_id; } $this->render('thirdview',$viewData); } public function actionAjaxchangeclasses() { $result = array(); $error = array(); $class_arr_select=array(); if (Yii::app()->request->getIsPostRequest()){ $selectedClassId=Req::post('selectedClassId'); $semester_id = $this->semesterId; if($selectedClassId){ $anotherSelectClass=ClassModel ::model()->getClassArrayByIds($selectedClassId); $i = 0; if($anotherSelectClass){ foreach ($anotherSelectClass as $cas){ $class_arr_select[$i]['class_id'] = $cas['class_id']; $class_arr_select[$i]['class_name'] = $cas['class_name']; $class_arr_select[$i]['grade'] = $cas['grade']; $i++; $class_arr_select_ids[] = $cas['class_id']; } } } $class_arr_select_ids_str = ""; if(isset($class_arr_select_ids) && $class_arr_select_ids){ foreach($class_arr_select_ids as $v){ $class_arr_select_ids_str.=$v.","; } $class_arr_select_ids_str=substr($class_arr_select_ids_str,0,-1); } $class_arr_noselect_data = ClassModel ::model()->getNoSelectclasses($semester_id,$class_arr_select_ids_str); $class_arr_noselect =array(); $j = 0; if($class_arr_noselect_data){ foreach($class_arr_noselect_data as $cans){ $class_arr_noselect[$j]['class_id'] = $cans->class_id; $class_arr_noselect[$j]['class_name'] = $cans->class_name; $class_arr_noselect[$j]['grade'] = $cans->grade; $j++; } } $result['class_arr_select'] = $class_arr_select; $result['class_arr_noselect'] = $class_arr_noselect; }else{ $error[] = "错误的来源"; } header('Content-Type: application/json'); if($error){ echo json_encode(array('status' => 0, 'error'=> implode('
', $error)));exit; }else{ echo json_encode($result);exit; } } public function actionCreateexam(){ $error = array(); $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $subjects = Req::post("subjects"); $examDate = Req::post("examDate"); $grade = Req::post("grade"); $ExamGroupId = Req::post("exam_group_id"); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 8) { $error[] = '考试类型错误'; } if(empty($subjects)){ $error[] = '请选择科目'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if((time()-strtotime($examDate))>86400*90){ $error[] = '考试时间不正确'; } if($error){ Yii::app()->jump->error(implode(',',$error)); }else{ //解析科目分数 $tplData=array(); $tplData['name']=$examName; // $tplData['examDate']=$examDate; $tplData['classCount']=count($classIds); $subject_ids=array(); $subjectArr=explode(',',$subjects); if($subjectArr){ $total_score=0; foreach ($subjectArr as $value){ $subject_score=explode('///',$value); $tplData['items'][$subject_score[0]]=$subject_score[1]; $total_score+=$subject_score[1]; $subject_ids[]=$subject_score[0]; } $tplData['scores']=$total_score; } $time = time(); $transaction = $this->sConn->beginTransaction(); try{ if($ExamGroupId){ $this->sConn->createCommand("delete from `zl_exam_group` where zl_exam_group_id='".$ExamGroupId."'")->execute(); $this->sConn->createCommand("delete from `zl_exam` where zl_exam_group_id='".$ExamGroupId."'")->execute(); $this->sConn->createCommand("delete from `zl_student_exam_relation` where zl_exam_group_id='".$ExamGroupId."'")->execute(); $newExamGroupId = $ExamGroupId; }else{ // $newExamGroupId = $this->schoolManager->UUID_SHORT(); $newExamGroupId=getUniqueId($this->schoolId); } $sql = "insert into `zl_exam_group` (`zl_exam_group_id`,`zl_exam_name`,`zl_exam_type`,`zl_grade`,`zl_exam_date`,`zl_create_time`,`zl_is_display`,`zl_semester_id`) " . "values (".$newExamGroupId.",'".$examName."',".$type.",'".$grade."','".strtotime($examDate)."',".time().",0,'".$this->semesterId."')"; $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ //$newExamId = $this->schoolManager->UUID_SHORT(); $newExamId=getUniqueId($this->schoolId); $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId"; $cardData = $this->sConn->createCommand($sql)->queryRow(); if($cardData['card_status']==0){ $cardData['card_length'] = 8; if($this->schoolId >999){ $cardData['card_length'] = 9; } } $this->sConn->createCommand()->insert('zl_exam',array( 'zl_exam_id' => $newExamId, 'zl_exam_group_id' => $newExamGroupId, 'zl_semester_id' => $this->semesterId, 'zl_subject_ids' => implode(',',$subject_ids), 'create_time' => $time, 'zl_tpl_data' => jsonEncode($tplData), 'zl_class_id' => $classId, )); $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId); $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds); $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0); if($studentIds_0){ foreach ($studentIds_0 as $studentId) { $this->sConn->createCommand()->insert('zl_student_exam_relation', array( 'zl_student_id' => $studentId, 'zl_exam_group_id' => $newExamGroupId, 'zl_exam_id' => $newExamId, 'zl_semester_id' => $this->semesterId, 'zl_class_id' => $classId, 'zl_student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'zl_school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if(!$error){ $this->redirect($this->createUrl('zhiliao/index')); }else{ Yii::app()->jump->error(implode(',',$error)); } } public function actionExam_list() { $exam_group_id = Req::get("exam_group_id"); if($exam_group_id>0) { $classId = Req::get("classId"); $condition = array(); if($classId) $condition[] = "e.zl_class_id = '{$classId}'"; $condition[] = "eg.zl_exam_group_id = '{$exam_group_id}'"; // $classes = $this->schoolManager->getSemesterClasses($this->semesterId); $classes=ClassModel::model()->getClassBySemester($this->semesterId); if(!$classes) { Yii::app()->jump->error('本学期尚未建班级!'); } $_classes = array(); foreach($classes as $v) { $_classes[$v['class_id']][$v['class_id']] = $v; } $resultList = $this->schoolManager->getZlExamList($condition); $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data['printList'] = $resultList['rs']; $data["classes"] = $_classes; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data["classId"] = $classId; $data["exam_group_id"] = $exam_group_id; $data["subject"] = $subject_exam_data; $this->render('exam_list',$data); } } //删除全部未考试学生 public function actionDelExamStudentAll() { $exam_group_id = Req::post('exam_group_id'); if(!$exam_group_id) { echo json_encode(array('status'=>0));exit; } $ZlStudentExamRelation=new ZlStudentExamRelation(); $student_data =$ZlStudentExamRelation->getCountStudentByExamGroupId($exam_group_id); if(!$student_data){ echo json_encode(array('status'=>2));exit; } if($ZlStudentExamRelation->delStudentPaperByExamIds($exam_group_id)) { //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" =>$exam_group_id, "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( 'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>0));exit; } //上传成绩 public function actionUpload(){ $exam_group_id = Req::get("exam_group_id"); $sql="select * from import_score_temp where exam_group_id<>'".$exam_group_id."' and exam_type=1 limit 1"; $anotherData=$this->sConn->createCommand($sql)->queryRow(); if($anotherData){ Yii::app()->jump->error('请先处理完成其它考试上传成绩数据,再上传新的考试'); } $sql="select * from import_score_temp where exam_group_id='".$exam_group_id."' and exam_type=1 limit 1"; $Data=$this->sConn->createCommand($sql)->queryRow(); if($Data){ //跳转检测页 $this->redirect(Yii::app()->createUrl('zhiliao/check_excel')); } $printType = '2'; $viewData=array( 'printType' =>$printType, 'examGroupId' =>$exam_group_id ); $this->render('upload',$viewData); } //新版导入成绩,导入表格 public function actionImportStore(){ ini_set ('memory_limit', '300M'); if(!$_FILES){ Yii::app()->jump->error('文件大小超过范围'); }else{ if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){ Yii::app()->jump->error('文件大小超过范围'); } } if (Yii::app()->request->getIsPostRequest()) { $exam_group_id=Req::post('exam_group_id'); if(!$exam_group_id) { Yii::app()->jump->error('请选择考试信息'); } $uploader = new Uploader("upload/tmpDir/zhiliao_chengji/{$this->schoolId}/"); $uploader->allowTypes = array("xls","xlsx"); $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"]; // 导入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); unset($sheetData[1]); if(!$sheetData) { Yii::app()->jump->error('请输入学生成绩数据'); } $ZlExam=new ZlExam(); $exam_group_data = $ZlExam->getExamByExamGroupId($exam_group_id); //debug($exam_group_data); $total_score=0; //表格科目对应 $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM'); $allSubject=Yii::app()->params['subjectId']; unset($allSubject[3]); unset($allSubject[20]); unset($allSubject[51]); $subjectExcel=array(); $subjectOrder=0; foreach ($allSubject as $key =>$val){ $subjectExcel[$letters[$subjectOrder]]=$key; $subjectOrder++; } $zlSubjectIds=array(); //考试科目 if($exam_group_data) { $zl_subject_ids=$exam_group_data[0]['zl_subject_ids']; $zlSubjectIds=explode(',',$zl_subject_ids); } $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`,`exam_type`) values"; $valuesArray=array(); foreach ($sheetData as $val){ if(!isset($val['A']) || !isset($val['B']) ){ continue; } $topic_score= array_merge(array(),array_slice($val,2)); foreach ($topic_score as $k=>$v){ if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){ Yii::app()->jump->error('分数必须是数值类型且》=0'); } //验证科目 if(isset($v) && !empty($zlSubjectIds) && in_array($subjectExcel[$k],$zlSubjectIds)){ unset($zlSubjectIds[array_search($subjectExcel[$k],$zlSubjectIds)]); } } $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($topic_score)."','".$exam_group_id."','student_name','0',1)"; } if(!empty($zlSubjectIds)){ $errSubjects=array(); foreach ($zlSubjectIds as $subjectId){ $errSubjects[]=Yii::app()->params['subjectId'][$subjectId]; } Yii::app()->jump->error('分数设置不正确,科目:【'.implode(',',$errSubjects).'】没有提交分数'); } if($valuesArray){ //$delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=1;"; $this->sConn->createCommand($delSql)->execute(); $insertSql.=implode(',',$valuesArray); $this->sConn->createCommand($insertSql)->execute(); $this->redirect(Yii::app()->createUrl('zhiliao/check_excel')); }else{ Yii::app()->jump->error('没有发现学生成绩数据'); } Yii::app()->jump->error('导入失败'); } } //导入数据检测页 public function actionCheck_Excel(){ $sql="select * from import_score_temp where exam_type=1 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); $data['check_field_name']='学生姓名'; $data['need_check_name']=1; $this->render('check',$data); } //检测格式 public function actionCheck_field_first(){ $result['status']=0; $sql="select * from import_score_temp where exam_type=1"; $All_Data=$this->sConn->createCommand($sql)->queryAll(); if(!$All_Data){ exit(json_encode($result)); } $data=$All_Data[0]; $check_field=$data['check_field']; $score_data=json_decode($data['score_data'],true); $exam_group_id=$data['exam_group_id']; if(!$score_data){ $result['msg']='数据不完整'; exit(json_encode($result)); } //检测题量 $ZlExam=new ZlExam(); $exam_group_data = $ZlExam->getExamByExamGroupId($data['exam_group_id']); //debug($exam_group_data); $total_score=0; //表格科目对应 $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM'); $allSubject=Yii::app()->params['subjectId']; unset($allSubject[3]); unset($allSubject[51]); unset($allSubject[20]); $subjectExcel=array(); $subjectOrder=0; foreach ($allSubject as $key =>$val){ $subjectExcel[$letters[$subjectOrder]]=$key; $subjectOrder++; } if($exam_group_data) { $tpl_data=json_decode($exam_group_data[0]['zl_tpl_data'],true); if(!$tpl_data) { $result['msg']='考试数据错误'; exit(json_encode($result)); } $subjectScores=$tpl_data['items']; //检测试题数据 foreach($All_Data as $key=> $val){ $topic_score=json_decode($val['score_data'],true); $uploadSubjectCount=0; foreach($topic_score as $order => $v){ if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){ $result['msg']='试题分数必须是数值类型:'.$val['student_name']; exit(json_encode($result)); } if(isset($v)==true){ $uploadSubjectCount++; if(isset($subjectExcel[$order])){ if(isset($subjectScores[$subjectExcel[$order]])){ if($v>$subjectScores[$subjectExcel[$order]]){ $result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$subjectScores[$subjectExcel[$order]]; exit(json_encode($result)); } }else{ $result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'考试设置中未设置'; exit(json_encode($result)); } }else{ $result['msg']='Excel格式不正确'; exit(json_encode($result)); } } } /* if($uploadSubjectCount!=count($subjectScores)){ $result['msg']='上传科目数量和考试设置不一致'; exit(json_encode($result)); } */ } $result['msg']='检测完成'; $result['status']=1; }else{ $result['msg']='未发现对应考试'; exit(json_encode($result)); } exit(json_encode($result)); } //重新上传 public function actionGiveup(){ // $delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=1;"; $this->sConn->createCommand($delSql)->execute(); $result['status']=1; exit(json_encode($result)); } //检测姓名 public function actionCheck_student_name(){ ini_set('memory_limit','512M'); set_time_limit(0); $result['status']=0; $result['data']=0; $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=1")->queryAll(); if($student_all_data){ //去除非中文字符 $updateArr=array(); $preg="/[^\x{4E00}-\x{9FFF}^·]+/u"; $count=0; foreach($student_all_data as $val){ if(preg_match($preg,$val['student_name'])){ $ModifyName = preg_replace($preg, "", $val['student_name']); if($ModifyName){ $updateArr[$val['id']]=$ModifyName; $count++; } }else{ $updateArr[$val['id']]=$val['student_name']; } } //组织更新语句 if($updateArr){ $arrNumber=ceil(count($updateArr)/500); $Arr=array_chunk($updateArr,$arrNumber,true); $transcation = $this->sConn->beginTransaction(); try { foreach ($Arr as $item){ $sql='update import_score_temp set `check_field_value`= case id '; foreach ($item as $key=> $val){ $sql.=" WHEN ".$key." THEN '".$val."' "; } $sql.=" End "; $sql.=" where check_field_value='' or check_field_value is null and exam_type=1"; $this->sConn->createCommand($sql)->execute(); } $transcation->commit(); $result['status']=1; }catch (Exception $e){ $transcation->rollback(); } } $result['count']=$count; } exit(json_encode($result)); } //匹配信息 public function actionMatching(){ $noExistent=0; //不存在 $repeat=0; //重复(组) $success=0; //匹配成功 $scoreWrong=0; //成绩不正确 $result['status']=0; $sql="select * from import_score_temp where exam_type=1 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); if(!$data){ exit(json_encode($result)); } $check_field=$data['check_field']; $exam_group_id=$data['exam_group_id']; $classArr=array(); $classIds=array(); $check_data_group=array(); //检查字段对应临时表id $update_temp_data=array(); //更新临时表数据 $student_card=array(); //学生id,准考证号对应数据 $tpl_data=array(); $updateSql=array(); $ZlExam=new ZlExam(); $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id); $paperIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ if(!$tpl_data && isset($v['zl_tpl_data'])){ $tpl_data=json_decode($v['zl_tpl_data'],true); } $classIds[]=$v['zl_class_id']; $examIds[]=$v['zl_exam_id']; } } //统计已经匹配成功的数据 $success_student_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is not null and student_id<>0 and exam_type=1")->queryAll(); if($success_student_data){ $success=count($success_student_data); } $check_field_val_arr=array(); $student_all_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is null or student_id=0 and exam_type=1 ")->queryAll(); if(!$student_all_data){ $result['repeat']=0; $result['success']=$success; $result['noExistent']=0; $result['status']=1; exit(json_encode($result)); } foreach ($student_all_data as $val){ //验证学生分数 $check_field_val_arr[]="'".$val['check_field_value']."'"; $check_data_group[$val['check_field_value']]=$val['id']; } //处理重复数据 $repeat_group_data=array(); $search_value_arr=array(); foreach ($check_field_val_arr as $value){ $repeat_group_data[$value][]=$value; } foreach ($repeat_group_data as $key=>$val){ if(count($val)>1){ $repeat++; $modify_name=str_replace("'",'',$key); $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$modify_name."' and (student_id is null or student_id=0) and exam_type=1"; }else{ $search_value_arr[]=$val[0]; } } if($search_value_arr){ $student_info=array(); $sql="select si.student_id,si.realname from student_info si join zl_student_exam_relation spr on si.student_id = spr.zl_student_id where realname in(".implode(',',$search_value_arr).") and zl_exam_id in(".implode(',',$examIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); if(!$student_info){ $noExistent=count($search_value_arr); $result['repeat']=$repeat; $result['success']=$success; $result['noExistent']=$noExistent; $result['status']=1; }else{ $result['status']=1; //过滤掉已被删除的学生 foreach ($student_info as $key=>$value){ $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 "; $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow(); if(!$student_class_realtion){ unset($student_info[$key]); } } $nameArr=array(); foreach ($student_info as $item){ $preg="/[^\x{4E00}-\x{9FFF}^·]+/u"; $ModifyName = preg_replace($preg, "", $item['realname']); $nameArr[$ModifyName][]=$item; } $noExistent=count($search_value_arr)-count($nameArr); if($noExistent<0) $noExistent=0; $result['noExistent']=$noExistent; foreach ($nameArr as $key=>$value){ if(count($value)>1){ $repeat++; $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."' and (student_id is null or student_id=0) and exam_type=1"; }else{ $success++; if(isset($check_data_group[$key])){ $update_temp_data[$check_data_group[$key]]=$value[0]['student_id']; } } } $result['repeat']=$repeat; $result['success']=$success; } }else{ $result['repeat']=$repeat; $result['success']=$success; $result['noExistent']=0; $result['status']=1; } //更新检测成功的数据 if($update_temp_data || $updateSql){ $transcation = $this->sConn->beginTransaction(); try { if($update_temp_data) { if ($check_field == 'student_name') { $sql = 'update import_score_temp set `student_id`= case id '; } else { $sql = 'update import_score_temp set `student_id`= case id '; } foreach ($update_temp_data as $key => $val) { $sql .= " WHEN " . $key . " THEN '" . $val . "' "; } $sql .= " End "; $sql .= " where (student_id='' or student_id is null) and exam_type=1"; $this->sConn->createCommand($sql)->execute(); } if($updateSql){ foreach ($updateSql as $query){ $this->sConn->createCommand($query)->execute(); } } $transcation->commit(); $result['status']=1; }catch (Exception $e){ $result['status']=0; $transcation->rollback(); } } exit(json_encode($result)); } //处理重复学生 public function actionHandle_repeat(){ $page=Req::post('page'); $name_like=Req::post('name'); if(!$page) $page=1; $pageSize=10; $offset=($page-1)*$pageSize; $sql="select * from import_score_temp where exam_type=1 limit 1"; $checkData=$this->sConn->createCommand($sql)->queryRow(); $check_field=$checkData['check_field']; $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=1 group by check_field_value "; if($name_like){ $sql.=" having check_field_value='".$name_like."'"; } $sql.="order by count desc"; $all_data=$this->sConn->createCommand($sql)->queryAll(); if(!$all_data){ $this->redirect(Yii::app()->createUrl('zhiliao/check_excel')); } $repeat=array(); $total=count($all_data); $data['total_page']=ceil($total/$pageSize); $data['name_group']=array_slice($all_data,$offset,$pageSize); $data['page']=$page; if(Yii::app()->request->isAjaxRequest){ $result['status']=1; $result['data']=$data['name_group']; $result['total_page']=$data['total_page']; exit(json_encode($result)); }else{ $this->render('handle', $data); } } //根据名称加载重名学生 public function actionShowrepeatstudent(){ $name=Req::post('name'); $fileName=array( 'student_name'=>'学生姓名', 'userno'=>'学号', 'student_card'=>'准考证号', 'school_student_card'=>'学校准考证号', 'zhixue_student_card'=>'智学网考证号', 'id_number'=>'身份证号', 'student_phone'=>'手机号' ); //扩展字段 $studentExtend=$this->schoolManager->getStudentExtend(); if($studentExtend){ foreach ($studentExtend as $key=> $value){ $fileName[$key]=$value['field_mean']; } } //表格科目对应 $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM'); $allSubject=Yii::app()->params['subjectId']; unset($allSubject[3]); unset($allSubject[51]); unset($allSubject[20]); $ExcelToSubject=array(); $subjectOrder=0; foreach ($allSubject as $key =>$val){ $ExcelToSubject[$letters[$subjectOrder]]=$key; $subjectOrder++; } $classIds=array(); $sql="select * from import_score_temp where check_field_value='".$name."' and ( student_id is null or student_id =0) and exam_type=1"; $nameArr=array(); $systemStudent=array(); $numberToId=array(); $excel_data = $this->sConn->createCommand($sql)->queryAll(); if($excel_data){ $topic_score=json_decode($excel_data[0]['score_data'],true); $check_field=$excel_data[0]['check_field']; $excel_html=''; $excel_html.=''; $excel_html.=''; $excel_html.=''; $excel_html.=''; // $scoreArr=array_slice($topic_score,2); foreach($topic_score as $f=>$v){ $excel_html.=''; } $excel_html.=''; $i=1; foreach($excel_data as $val){ $topic_score=json_decode($val['score_data'],true); $numberToId[$i]=$val['id']; $excel_html.=''; $excel_html.=''; $excel_html.=''; $excel_html.=''; foreach($topic_score as $v){ $excel_html.=''; } $excel_html.=''; $i++; } $excel_html.=''; $ZlExam=new ZlExam(); $exam_group_data=$ZlExam->getExamByExamGroupId($excel_data[0]['exam_group_id']); $classIds=array(); $examIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ $classIds[]=$v['zl_class_id']; $examIds[]=$v['zl_exam_id']; } } $_allStudent=array(); $check_field='realname'; $sys_sql="SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc "; $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id "; $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id "; $sys_sql.="LEFT JOIN zl_student_exam_relation spr on sc.student_id = spr.zl_student_id "; $sys_sql.=" where `".$check_field."` = '".$name."' and spr.zl_exam_id in(".implode(',',$examIds).") and s.semester_id <>'' "; $sys_sql.="order by end_time desc ;"; $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll(); $nameArr=array(); $studentData=array(); $businessData=array(); $semester=array(); $studentId=array(); $html=''; if($_allStudent){ foreach ($_allStudent as $val){ $val['serial_number']=0; $val['userno']=0; //班级信息 $sql_class_relation="select * from student_class_relation where student_id='".$val['student_id']."' and status=0 "; $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow(); if($student_class_realtion){ $val['serial_number']=$student_class_realtion['serial_number']; $val['userno']=$student_class_realtion['userno']; }else{ continue; } //查询副号 $sql_fuhao="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)"; $student_fuhao=$this->sConn->createCommand($sql_fuhao)->queryRow(); $val['fuhao']=0; if($student_fuhao){ if($val['student_id']!=$student_fuhao['master_student_id']){ continue; }else{ $fuhao_arr=explode(',',$student_fuhao['relation_student_id']); $val['fuhao']=count($fuhao_arr)-1; } } $studentData[$val['semester_id']][]=$val; $semester[$val['semester_id']]=$val['semester_name']; $studentId[]=$val['student_id']; } //查询business $criteria = new CDbCriteria(); $b_student = array(); $criteria->addInCondition('student_id',$studentId); $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data){ foreach($b_student_data as $v) { $businessData[$v->student_id]=array( 'username'=>$v->username, 'student_card'=>$v->student_card, 'school_student_card'=>$v->school_student_card, 'zhixue_student_card'=>$v->zhixue_student_card, ); } } $i=1; $currSemester = $this->schoolManager->getCurrSemester(); $smid=$currSemester['semester_id']; foreach ($semester as $key=> $val){ $semesterStatus='非当前学期'; if($smid==$key){ $semesterStatus='当前学期'; } $html.='
'; $html.='
'; $html.='
'; $html.=''; $html.='
'; $html.='
    '; if(isset($studentData[$key])){ // debug($studentData[$key]); foreach ($studentData[$key] as $item){ $isZj='是'; if($item['is_outer']==1){ $isZj='否'; } $html.='
  • '; $html.='
    '; $html.='
    '; $html.='
    '; $html.=''; $html.='
    '; $html.='
    '; $html.='
    '; $html.='姓名'; $html.=''.$item['realname'].''; $html.='
    '; $html.='
    '; $html.='班级'; $html.=''.$item['class_name'].''; $html.='
    '; $html.='
    '; $html.='
    '; $html.='学期'; $html.=''.$val.''; $html.='
    '; $html.='
    '; $html.='学期状态'; $html.=''.$semesterStatus.''; $html.='
    '; $html.='
    '; $html.='班级序号'; $html.=''.$item['serial_number'].''; $html.='
    '; $html.='
    '; $html.='学号'; $html.=''.$item['userno'].''; $html.='
    '; $html.='
    '; $html.='登录账号'; if(isset($businessData[$item['student_id']])){ $html.=''.$businessData[$item['student_id']]['username'].''; }else{ $html.=''; } $html.='
    '; $html.='
    '; $html.='系统准考证号'; if(isset($businessData[$item['student_id']])){ $html.=''.$businessData[$item['student_id']]['student_card'].''; }else{ $html.=''; } $html.='
    '; $html.='
    '; $html.='学校准考证号'; if(isset($businessData[$item['student_id']])){ $html.=''.$businessData[$item['student_id']]['school_student_card'].''; }else{ $html.=''; } $html.='
    '; $html.='
    '; $html.='智学网考号'; if(isset($businessData[$item['student_id']])){ $html.=''.$businessData[$item['student_id']]['zhixue_student_card'].''; }else{ $html.=''; } $html.='
    '; $html.='
    '; $html.='身份证号'; $html.=''.$item['id_number'].''; $html.='
    '; $html.='
    '; $html.='是否为在籍生'; $html.=''.$isZj.''; $html.='
    '; $html.='
    '; $html.='历史考试成绩'; $html.='查看'; $html.='
    '; $html.='
    '; $html.='副号'; $html.=''.$item['fuhao'].''; $html.='
    '; $html.='
    '; $html.='展开'; $html.='
    '; $html.='
  • '; $i++; } } $html.='
'; $html.='
'; $html.=''; $html.='
'; $html.='
'; } } } $result['html']=$html; $result['excel_html']=$excel_html; $result['status']=1; exit(json_encode($result)); } //绑定学生id public function actionBinding(){ $str=Req::post('str'); $result['status']=0; if(!$str || !is_array($str)){ exit(json_encode($result)); } $studentIds=array(); $tempIds=array(); foreach($str as $val){ @$nToId=explode('///',$val); if(isset($nToId[0])){ if(in_array((string)$nToId[0],$studentIds,true)){ $result['msg']='不能学生重复选择'; exit(json_encode($result)); }else{ $studentIds[]=(string)$nToId[0]; } } if(isset($nToId[1])){ if(in_array((string)$nToId[1],$tempIds,true)){ $result['msg']='不能学生重复选择'; exit(json_encode($result)); }else{ $tempIds[]=(string)$nToId[1]; } } } $updateSql=array(); foreach($str as $val){ @$nToId=explode('///',$val); if(isset($nToId[0]) && isset($nToId[1])){ //判断学生id是否已关联过 $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=1 limit 1")->queryRow(); if($related){ $result['msg']='学生已经被关联,请重新检查'; exit(json_encode($result)); } $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=1"; } } if($updateSql){ foreach($updateSql as $query){ $this->sConn->createCommand($query)->execute(); } $result['status']=1; } exit(json_encode($result)); } //处理不存在学生 public function actionHandle_existent(){ $fileName=array( 'student_name'=>'学生姓名', 'userno'=>'学号', 'student_card'=>'准考证号', 'school_student_card'=>'学校准考证号', 'zhixue_student_card'=>'智学网考证号', 'id_number'=>'身份证号', 'student_phone'=>'手机号' ); //扩展字段 $studentExtend=$this->schoolManager->getStudentExtend(); if($studentExtend){ foreach ($studentExtend as $key=> $value){ $fileName[$key]=$value['field_mean']; } } //查询不存在的数据 $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=1 "; $all_data=$this->sConn->createCommand($sql)->queryAll(); if($all_data){ $data['check_field']=$all_data[0]['check_field']; }else{ $data['check_field']=''; } $data['list']=$all_data; $data['fieldName']=$fileName; $this->render('handle_existent',$data); } //修改不存在的学生数据 public function actionChange_value(){ $id=Req::post('id'); $value=Req::post('value'); $result['status']=0; if(!$id || !$value){ $result['msg']='参数不正确'; exit(json_encode($result)); } $sql="select student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where id='".$id."' limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); if(!$data){ $result['msg']='id不正确'; exit(json_encode($result)); } $check_field=$data['check_field']; //excel中是否有重复数据 $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=1 "; $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow(); if($excelCheckData){ $result['msg']='excel中已存在相同记录'; if($check_field=='student_name'){ $result['status']=1; $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=1"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名'; } exit(json_encode($result)); } //系统中是否有数据 $exam_group_id=$data['exam_group_id']; $ZlExam=new ZlExam(); $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id); $classIds=array(); $examIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ $classIds[]=$v['zl_class_id']; $examIds[]=$v['zl_exam_id']; } } if($exam_group_data){ $student_info=array(); $sql="select si.student_id,si.realname from student_info si join zl_student_exam_relation spr on si.student_id = spr.zl_student_id where realname ='".$value."' and zl_exam_id in(".implode(',',$examIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); if(!$student_info){ $result['msg']='系统中不存在,或学生没有参加该次考试'; exit(json_encode($result)); }elseif(count($student_info)>1){ $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名'; exit(json_encode($result)); }else{ $result['status']=1; $studentId=$student_info[0]['student_id']; //查询是否参加考试 $StudentPaperRelation=$this->sConn->createCommand("select zl_student_id from `zl_student_exam_relation` where zl_student_id='".$studentId."' and zl_exam_id in(".implode(',',$examIds).")")->queryRow(); if(!$StudentPaperRelation){ $result['status']=1; $result['msg']='学生没有参加本次考试'; exit(json_encode($result)); } //判断学生id是否已关联过 $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=1 limit 1")->queryRow(); if($related){ $result['msg']='学生已经被关联,请重新检查'; exit(json_encode($result)); } $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); exit(json_encode($result)); } }else{ $result['msg']='考试数据有误'; exit(json_encode($result)); } } //处理完毕,执行成绩导入 public function actionUpdate_score(){ $result['status']=0; $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=1"; $all_data=$this->sConn->createCommand($sql)->queryAll(); if(!$all_data){ $result['msg']='没有发现可导入学生成绩数据'; exit(json_encode($result)); } $exam_group_id=$all_data[0]['exam_group_id']; $ZlExam=new ZlExam(); $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id); if(!$exam_group_data){ $result['msg']='考试ID不正确,请从考试列表点击上传成绩'; exit(json_encode($result)); } $classIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ $classIds[]=$v['zl_class_id']; $examIds[]=$v['zl_exam_id']; } } $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM'); $allSubject=Yii::app()->params['subjectId']; unset($allSubject[3]); unset($allSubject[51]); unset($allSubject[20]); $ExcelToSubject=array(); $subjectOrder=0; foreach ($allSubject as $key =>$val){ $ExcelToSubject[$letters[$subjectOrder]]=$key; $subjectOrder++; } // $tpl_data=json_decode($exam_group_data[0]['tpl_data'],true); $sql='INSERT INTO `zl_student_exam_rs` (`id`,`zl_student_id`,`zl_exam_group_id`,`zl_exam_id`,`zl_subject_id`,`zl_scoring`)VALUE '; $deleteSql=array(); $error=array(); $studentIds=array(); //用于检测重复 $time=time(); foreach($all_data as $val){ $StudentPaperRelation=$this->sConn->createCommand("select zl_student_id,zl_exam_id from `zl_student_exam_relation` where zl_student_id='".$val['student_id']."' and zl_exam_id in(".implode(',',$examIds).")")->queryRow(); if(!$StudentPaperRelation){ $error[]='学生没有参加本次考试 :'.$val['student_name']; continue; } $ZlExamId=$StudentPaperRelation['zl_exam_id']; $deleteSql[]="delete from `zl_student_exam_rs` where zl_student_id='".$val['student_id']."' and zl_exam_group_id='".$exam_group_id."' "; $topicScoreData=json_decode($val['score_data'],true); $uuidArr=array(); $uuidArr=getBatchUuid($this->schoolId,count($topicScoreData)); foreach($topicScoreData as $key=> $ts){ if(isset($ts)== true){ if(!is_numeric($ts) || floatval($ts)<0){ continue; } $ts=(float)$ts; if(!$ts){ $ts=0; } // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll(); // $uuid = current(current($uuid)); //$uuid=getUniqueId($this->schoolId); $uuid=current($uuidArr); unset($uuidArr[$uuid]); $valueSql[]=' ('.$uuid.','.$val['student_id'].','.$exam_group_id.','.$ZlExamId.','.$ExcelToSubject[$key].','.$ts.') '; } } } if($deleteSql && $valueSql){ $transaction = $this->sConn->beginTransaction(); try{ if($deleteSql){ foreach ($deleteSql as $dquery){ $this->sConn->createCommand($dquery)->execute(); } if($valueSql){ if(count($valueSql)>100){ $valueSql = array_chunk($valueSql, 10); foreach($valueSql as $value){ $chunkSql=$sql; $chunkSql.=implode(',',$value); $this->sConn->createCommand($chunkSql)->execute(); } }else{ $sql.=implode(',',$valueSql); $this->sConn->createCommand($sql)->execute(); } } //清理导入临时数据 // $delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=1;"; $this->sConn->createCommand($delSql)->execute(); $transaction->commit(); $result['status']=1; if($error){ // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error)); $result['msg']=implode('
',$error); }else{ $result['msg']='导入成功'; } exit(json_encode($result)); } }catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); // Yii::app()->jump->error('成绩导入失败,请检查后重新'); $result['msg']='成绩导入失败,请检查后重新导入'; exit(json_encode($result)); } }else{ //没有需要重新导入的数据,清理导入临时数据 $delSql="delete from import_score_temp where exam_type=1;"; $this->sConn->createCommand($delSql)->execute(); $result['status']=1; exit(json_encode($result)); } } /*切换记录状态*/ public function actionChangeStatus(){ $display=intval(Req::post('display')); $examGroupId=Req::post('cid'); $result=array( 'status'=>0 ); if(!$examGroupId || !in_array($display,array(0,1))){ exit(json_encode($result)); } $ZlExamGroup=new ZlExamGroup(); $data=array( 'zl_is_display'=>$display ); $Condition=array( 'zl_exam_group_id'=>$examGroupId ); $res=$ZlExamGroup->updateByCondition($data,$Condition); if($res){ $result['status']=1; } exit(json_encode($result)); } public function actionChange(){ ini_set("memory_limit","200M"); Url::clean(); $sname = Req::get("sname"); $cid = Req::get("cid"); $eid = Req::get("eid"); $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $ZlExam=new ZlExam(); $examInfo = $ZlExam->getExamByExamId($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到考试!'); } $ZlexmGroup=new ZlExamGroup(); $examInfo=$ZlexmGroup->getExamGroupByExamGroupId($examInfo['zl_exam_group_id']); $ZlStudent=new ZlStudentExamRelation(); $result = array(); $relateStudent = $ZlStudent->getStudentByExamId($eid); // 获取学生姓名 $_student_id = array(); foreach($relateStudent as $v) { $_student_id[$v['zl_student_id']] = $v['zl_student_id']; } $studentNames = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$_student_id); $studentArray = SStudentInfo::model()->findAll($criteria); if (!empty($studentArray)) { foreach ($studentArray as $student) { $studentNames[$student->student_id] = $student->realname; } } //debug($examInfo); foreach ($relateStudent as $key=>$val) { //查询学生身份证号 $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val['zl_student_id'])); if($studentInfo){ $result[$key]['id_number'] = $studentInfo->id_number; }else{ $result[$key]['id_number'] = ''; } if (empty($sname)) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperName'] = $examInfo['zl_exam_name']; $result[$key]['studentCode'] = $val['zl_student_id']; $result[$key]['studentName'] = isset($studentNames[$val['zl_student_id']]) ? $studentNames[$val['zl_student_id']] : null; $result[$key]['is_complete'] = !empty($val['zl_subject_id'])?1:0; } else { if ($sname == $studentNames[$val['zl_student_id']]) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperName'] = $examInfo['zl_exam_name']; $result[$key]['studentCode'] = $val['zl_student_id']; $result[$key]['studentName'] = $studentNames[$val['zl_student_id']]; $result[$key]['is_complete'] = !empty($val['zl_subject_id'])?1:0; }else{ unset($result[$key]); } unset($relateStudent[$key]); } } //} $no_paper_student = array(); $paper_student_array = array(); $c_paper_student_array = array(); $class_student_info_data = array(); $_student_ids = array(); $_student_id_names = array(); $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation if($class_student_data) { foreach($class_student_data as $v) { $_student_ids[$v['student_id']] = $v['student_id']; } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$_student_ids); $studentArray = SStudentInfo::model()->findAll($criteria); if (!empty($studentArray)) { foreach ($studentArray as $student) { $_student_id_names[$student->student_id] = $student->realname; } } } ///$class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info if ($class_student_data) { foreach($class_student_data as $v) { if(!isset($b_student_arr[$v['student_id']])) { if ($paper_student_array) { if(isset($paper_student_array[$v['student_id']])){ $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'', ); } } if($c_paper_student_array ) { if(!isset($c_paper_student_array[$v['student_id']]) ) { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'', ); } }else { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'', ); } } } } $printType = '2'; $data = array(); if(isset($isUnderLine)){ $data['under_line']=$isUnderLine; } $data['no_paper_student'] = $no_paper_student; $data['result'] = $result; $data["sname"] = $sname; $data['exam_id'] = $eid; $data['class_id'] = $cid; $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data["subject"] = $subject_exam_data; $data['className'] = $classInfo->class_name; $data['paperName'] = $examInfo['zl_exam_name']; $data['examInfo'] = $examInfo; $data['printType'] = $printType; $this->render('change',$data); } //不推送成绩设置列表 public function actionBlackList(){ $name = Req::get("name"); $classId = Req::get("class_id"); $grade = Req::get("grade"); $page = intval(Req::get("page")); $subjectId=$this->subjectId; $query=array(); if(!$page) $page=1; $query['page']=$page; $where=array(); if(in_array($subjectId,$this->mathSubjectId)){ $where[]=" subject_id in(".implode(',',$this->mathSubjectId).") and semester_id='".$this->semesterId."'"; }else{ $where[]=" subject_id ='".$subjectId."' and semester_id='".$this->semesterId."'"; } if($name){ $where[]=" name like '%".$name."%'"; $query['name']=$name; } if($classId){ $where[]=" class_id = '".$classId."'"; $query['class_id']=$classId; } if($grade){ $where[]=" grade = '".$grade."'"; $query['grade']=$grade; } $pageLimit=10; $data=Blacklist::model()->getExamList($where,$page,$pageLimit); $ExamModel=new SExam(); if($data['dataList']){ foreach ($data['dataList'] as $key =>$val){ $data['dataList'][$key]['subject']=Yii::app()->params['subjectId'][$val['subject_id']]; //判断成绩是否生成 $exam=$ExamModel->getDetailByExamId($val['exam_id']); if($exam['status']==1){ $data['dataList'][$key]['status']='是'; }else{ $data['dataList'][$key]['status']='否'; } } } $data['query']=$query; $data['subject']=$subjectId; $data['name'] = $name?$name:""; $data['grade'] = $grade?$grade:0; $data['classId'] = $classId?$classId:''; // debug($data); $this->render('blacklist',$data); } //加载考试 public function actionAjaxSearchExam(){ $grade=Req::post('grade'); $class=Req::post('class'); $keyword=Req::post('keyword'); $page=Req::post('page'); if(!$page) $page=1; $pageLimit=10; $condition=array(); $subject=$this->subjectId; $condition[]="e.semester_id='".$this->semesterId."'"; if($subject==3){ $condition[]='e.subject_id in ('.implode(',',$this->mathSubjectId).')'; }else{ $condition[]="e.subject_id ='".$subject."'"; } if($grade){ $condition[]="c.grade='".$grade."'"; } if($class){ $condition[]="c.class_id='".$class."'"; } if($keyword){ $condition[]="e.name like '%".$keyword."%'"; } $notInExamIds=array(); if(in_array($subject,$this->mathSubjectId)){ $blacklist=$this->sConn->createCommand("select exam_id from blacklist where subject_id in(".implode(',',$this->mathSubjectId).") and semester_id='".$this->semesterId."'")->queryAll(); }else{ $blacklist=$this->sConn->createCommand("select exam_id from blacklist where subject_id='".$subject."' and semester_id='".$this->semesterId."'")->queryAll(); } if($blacklist){ foreach ($blacklist as $value){ $notInExamIds[]=$value['exam_id']; } } if($notInExamIds){ $condition[]="e.exam_id not in(".implode(',',$notInExamIds).")"; } $sqlCount="SELECT count(*) as count FROM `exam` e "; $sqlCount.="join class c on c.class_id=e.class_id "; if($condition){ $sqlCount.=" where ".implode(' and ',$condition); } $countData=$this->sConn->createCommand($sqlCount)->queryRow(); $pages=array( 'total'=>$countData['count'], 'totalPage'=>ceil($countData['count']/$pageLimit), 'page'=>$page, ); $offset=($page-1)*$pageLimit; $sql="SELECT e.exam_id,e.name,c.grade,e.tpl_data,e.`status`,c.class_id,e.type,c.class_type,c.class_name,e.create_time FROM `exam` e "; $sql.="join class c on c.class_id=e.class_id "; if($condition){ $sql.=" where ".implode(' and ',$condition); } $sql.=" order by e.create_time desc limit {$offset},{$pageLimit}"; $classArr=array( 1=>'行政班', 2=>'教学班' ); //1:周考2:单元考3:月考4:联考5:期中6:期末7:高考模拟8:冲刺 $typeArr=array( 1=>'周考', 2=>'单元考', 3=>'月考', 4=>'联考', 5=>'期中', 6=>'期末', 7=>'高考模拟', 8=>'冲刺', 9=>'测验' ); $list = $this->sConn->createCommand($sql)->queryAll(); if($list){ foreach ($list as $key=>$val){ $list[$key]['class_type']=$classArr[$val['class_type']]; if(isset($typeArr[$val['type']])){ $list[$key]['type']=$typeArr[$val['type']]; } $list[$key]['subject_name']=Yii::app()->params['subjectId'][$this->subjectId]; $list[$key]['create_date']=date('Y-m-d',$val['create_time']); $list[$key]['exam_date']=''; if($val['tpl_data']){ $tpl_data=json_decode($val['tpl_data'],true); if(isset($tpl_data['examDate'])){ $list[$key]['exam_date']=$tpl_data['examDate']; } } if($val['status']==1){ $list[$key]['status_msg']='是'; }else{ $list[$key]['status_msg']='否'; } switch ($val['grade']){ case 1: $list[$key]['grade']='高一'; break; case 2: $list[$key]['grade']='高二'; break; case 3: $list[$key]['grade']='高三'; break; default: $list[$key]['grade']='高一'; } } } $result['status']=1; $result['list']=$list; $result['pages']=$pages; exit(json_encode($result)); } //添加黑名单 public function actionAddBlacklist(){ $examIds=Req::post('examIds'); $result['status']=0; if(!$examIds){ exit(json_encode($result)); } $delSql="delete from blacklist where exam_id in(".implode(',',$examIds).")"; $insertSql="insert into blacklist(`exam_group_id`,`exam_id`,`name`,`type`,`subject_id`,`semester_id`,`class_id`,`class_name`,`class_type`,`grade`,`exam_create_time`,`exam_date`,`dateline`) values "; $insertData=array(); $ExamModel=new SExam(); foreach ($examIds as $val){ $ExamInfo=$ExamModel->getDetailByExamId($val); $classInfo = ClassModel::model()->findByPk($ExamInfo['class_id']); $tpl_data=json_decode($ExamInfo['tpl_data'],true); $insertData[]="('".$ExamInfo['exam_group_id']."','".$val."','".$ExamInfo['name']."','".$ExamInfo['type']."','".$ExamInfo['subject_id']."','".$this->semesterId."','".$ExamInfo['class_id']."','".$classInfo->class_name."','".$classInfo->class_type."','".$classInfo->grade."','".$ExamInfo['create_time']."','".$tpl_data['examDate']."','".time()."')"; } if($insertData){ $transcation = $this->sConn->beginTransaction(); try { $insertSql.=implode(',',$insertData); $this->sConn->createCommand($delSql)->execute(); $this->sConn->createCommand($insertSql)->execute(); $transcation->commit(); $result['status']=1; }catch (Exception $e){ $transcation->rollback(); } } exit(json_encode($result)); } //删除黑名单 public function actionDelBlacklist(){ $examId=Req::get('exam_id'); if(!$examId || !is_numeric($examId)){ Yii::app()->jump->error('参数异常!'); } $url=$_SERVER['HTTP_REFERER']; if($this->sConn->createCommand("delete from blacklist where exam_id = '".$examId."'")->execute()){ $arr=array( 'schoolId' => $this->schoolId, 'examIds' =>array($examId) ); sendDataToKafka('zsyte-marking-finished-notify-parent',$arr); // $send_json=json_encode($arr); // $stompconn = new Stomp(Yii::app()->params["activeMq"]["server"]); // $stompconn->send("zsyte.markingFinishedNotifyParent", $send_json); unset($stompconn); $this->redirect($url); } } //下载excel public function actionDownloadExcel(){ $rs = $this->schoolManager->getClasses('ALL',array('class_id desc')); $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(30); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10); $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $allSubject=Yii::app()->params['subjectId']; unset($allSubject[3]); unset($allSubject[51]); unset($allSubject[20]); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '姓名(必填)') ->setCellValue('B1', '班级(当前学期唯一)'); $i=0; foreach ($allSubject as $key =>$val){ $column=$letters[$i].'1'; $objPHPExcel->getActiveSheet(0)->setCellValue($column,$val); $i++; } // $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $i = 2; $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, '小李1'); $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, '高一一班'); $subjectOrder=0; foreach ($allSubject as $key =>$val){ $column=$letters[$subjectOrder].$i; $subjectOrder++; $objPHPExcel->getActiveSheet(0)->setCellValue($column, ''); } $objPHPExcel->getActiveSheet()->setTitle('知了家校导入成绩'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header('Content-Type:application/vnd.ms-excel'); 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 actionReportsetting(){ $data = array(); $this->render('reportsetting',$data); } //获取成绩报告设置 public function actionAjaxGetReportSetting(){ $data = array(); $error = array(); $zl_model = new BusinessZl_report_setting(); $setting_data = $zl_model->getReportSetting($this->schoolId); if($setting_data){ $data['class_average'] = $setting_data['class_average']; $data['grade_average'] = $setting_data['grade_average']; $data['class_rank'] = $setting_data['class_rank']; $data['grade_rank'] = $setting_data['grade_rank']; $data['level_replace_score'] = $setting_data['level_replace_score']; if($setting_data['score_level_setting']){ $data['score_level_setting'] = json_decode($setting_data['score_level_setting'],true); }else{ $data['score_level_setting']['A']['min_score'] = 90; $data['score_level_setting']['A']['max_score'] = 100; $data['score_level_setting']['B']['min_score'] = 70; $data['score_level_setting']['B']['max_score'] = 89; $data['score_level_setting']['C']['min_score'] = 60; $data['score_level_setting']['C']['max_score'] = 69; $data['score_level_setting']['D']['min_score'] = 40; $data['score_level_setting']['D']['max_score'] = 59; $data['score_level_setting']['E']['min_score'] = 0; $data['score_level_setting']['E']['max_score'] = 39; } }else{ $data['class_average'] = 1; $data['grade_average'] = 1; $data['class_rank'] = 1; $data['grade_rank'] = 1; $data['level_replace_score'] = 0; $data['score_level_setting']['A']['min_score'] = 90; $data['score_level_setting']['A']['max_score'] = 100; $data['score_level_setting']['B']['min_score'] = 70; $data['score_level_setting']['B']['max_score'] = 89; $data['score_level_setting']['C']['min_score'] = 60; $data['score_level_setting']['C']['max_score'] = 69; $data['score_level_setting']['D']['min_score'] = 40; $data['score_level_setting']['D']['max_score'] = 59; $data['score_level_setting']['E']['min_score'] = 0; $data['score_level_setting']['E']['max_score'] = 39; } if($error){ echo json_encode(array("status"=>0,"error"=>implode("
",$error)));exit; }else{ echo json_encode(array("status"=>1,"data"=>$data));exit; } } //保存成绩报告设置 public function actionAjaxSaveReportSetting(){ $error = array(); $insert_data = array(); $class_average = (int)Req::post('class_average'); $grade_average = (int)Req::post('grade_average'); $class_rank = (int)Req::post('class_rank'); $grade_rank = (int)Req::post('grade_rank'); $level_replace_score = (int)Req::post('level_replace_score'); $setting_data = Req::post('setting_data'); if($level_replace_score == 1 && !$setting_data){ $error[] = "分数等级不能为空"; } if(!$error){ $insert_data["class_average"] = $class_average; $insert_data["grade_average"] = $grade_average; $insert_data["class_rank"] = $class_rank; $insert_data["grade_rank"] = $grade_rank; $insert_data["level_replace_score"] = $level_replace_score; $insert_data["score_level_setting"] = $setting_data?htmlspecialchars_decode($setting_data):""; $zl_model = new BusinessZl_report_setting(); $status= $zl_model->saveReportSetting($this->schoolId,$insert_data); if(!$status){ $error[] = "更新失败"; } } if($error){ echo json_encode(array("status"=>0,"error"=>implode(",",$error)));exit; }else{ echo json_encode(array("status"=>1));exit; } } //未付费用户权限设置 public function actionUnpaidUserSetting(){ $unpaidModel=new UnpaidUserSetting(); $formData=getAttribute($unpaidModel->find('school_id=:school_id',array(':school_id'=>$this->schoolId))); if (Yii::app()->request->getIsPostRequest()){ $parent_report=(int)Req::post('parent_report'); $parent_exam_notify=(int)Req::post('parent_exam_notify'); $student_report=(int)Req::post('student_report'); $student_knowledge_bill=(int)Req::post('student_knowledge_bill'); if($parent_report==$formData['parent_report'] && $parent_exam_notify==$formData['parent_exam_notify'] && $student_report==$formData['student_report'] && $student_knowledge_bill==$formData['student_knowledge_bill']){ // Yii::app()->jump->error('保存成功'); } $insertData=array( 'school_id'=>$this->schoolId, 'parent_report'=>$parent_report, 'parent_exam_notify'=>$parent_exam_notify, 'student_report'=>$student_report, 'student_knowledge_bill'=>$student_knowledge_bill ); if($unpaidModel->saveReportSetting($insertData)){ Yii::app()->unpaid_user_setting->hmset('zhiliao:unpaid_user_setting:'.$this->schoolId,$insertData); Yii::app()->jump->error('保存成功'); }else{ Yii::app()->jump->error('保存失败'); } } $this->render('unpaid',$formData); } }