allowTypes = array("xls"); $rs = $uploader->act(); $xls = current($rs); $xls = $xls ? $xls[0] : array(); if(!$xls){ Yii::app()->jump->error('请选择上传的Excel文件'); } if(!in_array($xls["ext"], array("xls", "xlsx"))) Yii::app()->jump->error('上传的文件必须是Excel文件'); $rs = $this->schoolManager->insertExamRecord($recordData, $xls); $url = "record/index"; if(isset($recordData["class_id"]) && $recordData["class_id"]) $url .= "?classId={$recordData["class_id"]}"; $url = $this->createUrl($url); $result = array(); $result["url"] = $url; $result["title"] = "导入结果"; if(is_array($rs)){ $result["result"] = $rs["global"]["result"]; $errorsCount = count($rs["errors"]); $result["content"] = " {$rs["global"]["msg"]}
"; $errorsCount = 0; $result["content"] = ""; foreach($rs["errors"] as $key => $val){ if($val["count"]){ $errorsCount++; $result["content"] .= " 错误{$errorsCount}:
错误原因:{$val["type"]}
错误信息:{$val["msg"]}
"; } } $result["content"] = " {$rs["global"]["msg"]}
共遇到{$errorsCount}个错误
{$result["content"]} "; } else{ $result["result"] = "失败"; $result["content"] = " 共遇到1个错误
错误原因:数据库操作出错
错误信息:数据写入失败
"; } Yii::app()->cache->set("coach_".Yii::app()->session->sessionID."_tips", $result, 120); $this->redirect($this->createUrl("index/showtips")); } public function actionDelAct(){ $examId = Req::post("examId"); $rs = $this->schoolManager->delExam($examId, 2); $code = $rs ? "0" : "1"; $msg = array( "0" => "删除成功", "1" => "删除失败", ); $rs = array( "code" => $code, "msg" => isset($msg[$code]) ? $msg[$code] : "", ); echo json_encode($rs);exit; } public function actionEdit(){ $examId = Req::get("examId"); $classes = $this->schoolManager->getClasses(); $exam = $this->schoolManager->getExam($examId); $examClassesIds = $this->schoolManager->getExamClassesIds($examId); $this->render("edit", array( "classes" => $classes, "examClassesIds" => $examClassesIds, "exam" => $exam, )); } public function actionIndex(){ $classId = Req::get("classId"); $grade = Req::get("grade"); if(!$grade && !$classId){ $grade = "1"; } else if($classId){ $class = $this->schoolManager->getClass($classId); if(!$class) $grade = "1"; else $grade = $class["grade"]; } $classes = $this->schoolManager->getClasses($grade); if(!$classId){ $class = current($classes); if($class) $classId = $class["class_id"]; } $rs = $this->schoolManager->getClassExamsList($classId); $this->render("index", array( "exams" => $rs["rs"], "pager" => $rs["pager"], "class" => $class, "classes" => $classes, "grade" => $grade, )); } public function actionGetGradeClassesJson(){ $grade = Req::get("grade"); echo json_encode($this->schoolManager->getClasses($grade));exit; } public function actionView(){ $examId = Req::get("examId"); $records = $this->schoolManager->getExamRecordsList($examId); $this->render("view", array( "records" => $records, )); } public function actionTo_zhixue_grade() { $data = array(); $exam_group_ids = array(); $exam_data = array(); $exam_groups = array(); // $condition[] = "eg.create_type in (0,1,2,3) "; $criteria = new CDbCriteria(); $criteria->addCondition('semester_id = '.$this->semesterId); $criteria->addInCondition('subject_id',$this->mathSubjectId); $criteria->addCondition('status = 3'); $criteria->addCondition('upload_status = 0'); $criteria->order = 'create_time desc'; $exam_all_data = Exam::model()->findAll($criteria); unset($criteria); if($exam_all_data) { foreach ($exam_all_data as $v) { $exam_group_ids[$v->exam_group_id] = $v->exam_group_id; $exam_data[$v->exam_group_id] = $v; } if($exam_group_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_group_id',$exam_group_ids); $criteria->addInCondition('create_type ',array(0,1,2,3)); $exam_group_data = ExamGroup::model()->findAll($criteria); } if($exam_group_data) { foreach ($exam_group_data as $v) { if(isset($exam_data[$v->exam_group_id])) { $exam_groups[] = $exam_data[$v->exam_group_id]; } } } $data['exam_info'] = $exam_groups; } unset($exam_all_data); $data["use_zhixue"] = $this->schoolInfo->use_zhixue; $this->render("to_zhixue_grade",$data); } public function actionZhixue_import() { 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()) { $bstudents = new BusinessStudent(); $exam_group_id = Req::post("exam_group_id"); if(!$exam_group_id) { Yii::app()->jump->error('请选择考试信息'); } $uploader = new Uploader("upload/tmpDir/zhixue_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'); // 读取Excel文档 $exam_id = ''; $exam_ids = array(); $topic_count = 0; $zhixue_student_card = array(); $class_name_data = array(); $student_ids = array(); $student_topic = array(); $student_name_data = array(); $_student_name_data = array(); $tops = array(); $scores = array(); $_err = array(); $_paper_ids = array(); $_student_paper_ids = array(); $_exam_ids = array(); $total_score = 0; $student_score = array(); $student_paper_all = array(); $student_paper = array(); $sql_arr = array(); $student_paper_info = array(); $paper_ids = array(); $paper_student_ids = array(); $zhixue_student_cards =array(); $id_sum = 0; try{ $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); // FIXME 20191202 @unlink($file["src"]); }catch (Exception $e){ // FIXME 20191202 @unlink($file["src"]); Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage()); } if(!$sheetData) { Yii::app()->jump->error('请正确的Excel!'); } unset($objPHPExcel); unset($sheetData[1]); krsort($sheetData); $sheetData = array_reverse($sheetData); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; $exam_id = $v->exam_id; $tpl_data = json_decode($v->tpl_data,1); if(isset($tpl_data['scores'])) { $total_score = $tpl_data['scores']; } } unset($exam_group_data); $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($paper_data) { $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id))); if($paper_topic_data) { foreach($paper_topic_data as $k=>$v) { $tops[$k] = $v->topic_id; $types[$v->topic_id] = $v->type; $scores[$v->topic_id] = $v->score; } unset($paper_data); $criteria = new CDbCriteria(); //$criteria->select = 'student_id,paper_id,class_id,exam_id,semester_id,student_card,school_student_card,partial_right_count,compare,right_count,wrong_count,lost_score'; $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_del=0'); $student_paper_all_data = SStudentPaperRelation::model()->findAll($criteria); if($student_paper_all_data) { foreach($student_paper_all_data as $v) { $student_paper_all[$v->student_id] = $v->exam_id; $student_paper[$v->student_id] = $v->paper_id; $paper_ids[$v->paper_id] = $v->paper_id; $_paper_ids[$v->exam_id] = $v->paper_id; $student_paper_info[$v->student_id] = $v; } } unset($criteria); unset($student_paper_all_data); foreach($sheetData as $xv) { if(isset($xv['A']) && !empty($xv['A']) && isset($xv['B']) && !empty($xv['B']) && isset($xv['C'])&& !empty($xv['C']) && isset($xv['D'])) { if(!is_numeric($xv['B'])){ continue; } $id_sum++; if(isset($xv['E'])) { $z_card = (string)$xv['B']; if(in_array($z_card, $zhixue_student_cards)){ continue; } $zhixue_student_cards[$z_card] = $z_card; $student_name_data[(string)$z_card] = $xv['A']; $_student_name_data[(string)$z_card] = $xv['A']; $class_name_data[(string)$z_card] = $xv['C']; $student_topic[(string)$z_card] = array_merge(array(),array_slice($xv,4)); $zhixue_student_card[(string)$z_card] = $z_card; $student_score[(string)$z_card] = (float)$xv['D']; //验证导入的成绩 if($student_score[(string)$z_card] && $student_topic[(string)$z_card]){ if($student_score[(string)$z_card] != array_sum($student_topic[(string)$z_card])){ $_err['total_score']['student'][] = $xv['A']; } } if($student_topic[(string)$z_card] && $scores){ if(count($scores) != count($student_topic[(string)$z_card])){ $_err['score_count']['student'][] = $xv['A']; }else{ $n = 0; $m = 0; foreach($scores as $v){ $scoreArr = array_slice($student_topic[(string)$z_card],$n,1); if((int)$v < (int)current($scoreArr)){ $_err['wrong_score']['student'][$z_card] = $xv['A']; } $n++; } } } }else { $_err['no_score']['student'][] = $xv['A']; } }else { //$_err['no_topic']['student'][] = $xv['A']; continue; } } if(!$zhixue_student_card){ Yii::app()->jump->error('没有需要导入的正常数据'); } $_uuid_arr = $this->createId(count($types)*$id_sum); $_uuid_arr_num = count($_uuid_arr); if(!$_uuid_arr) { Yii::app()->jump->error('预定义UUID不足,请联系技术人员'); } // $criteria = new CDbCriteria(); // $criteria->select = 'student_id,zhixue_student_card'; // $criteria->addCondition('school_id=:school_id'); // $criteria->addInCondition('zhixue_student_card',$zhixue_student_card); // $criteria->params[':school_id'] = $this->schoolId; // $b_student_data = BusinessStudent::model()->findAll($criteria); // unset($criteria); //处理准考证号量太大的问题 $ArrCount=count($zhixue_student_card); $Student_data_temp=array(); $b_student_data=array(); if($ArrCount<500){ $Student_data_temp = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card); }elseif($ArrCount<1000){ $TempArr=array_chunk($zhixue_student_card, 2); }else{ $TempArr=array_chunk($zhixue_student_card, 5); } if($Student_data_temp){ $b_student_data=$Student_data_temp; }elseif($TempArr){ foreach ($TempArr as $item){ $Student_data_temp=$bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$item); if($Student_data_temp){ $b_student_data=array_merge($b_student_data,$Student_data_temp); } } } // $b_student_data = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card); if($b_student_data) { // foreach($b_student_data as $v) // { // if(isset($student_paper_all[$v->student_id]) && !empty($student_paper_all[$v->student_id])) // { // $student_ids[(string)$v->zhixue_student_card] = $v->student_id; // $paper_student_ids[$v->student_id] = $v->student_id; // unset($_student_name_data[(string)$v->zhixue_student_card]); // // }else // { // continue; // } // // // // } foreach($b_student_data as $v) { if(isset($student_paper_all[$v['student_id']]) && !empty($student_paper_all[$v['student_id']])) { $student_ids[(string)$v['zhixue_student_card']] = $v['student_id']; $paper_student_ids[$v['student_id']] = $v['student_id']; unset($_student_name_data[(string)$v['zhixue_student_card']]); }else { continue; } } unset($b_student_data); //写入 $sql = ''; $sql_sum = 0; $_sql_sum = 0; $_sql = ''; $_sql_arr = array(); /* */ foreach($zhixue_student_card as $v) { $v = (string)$v; $complete_count = 0; $r_count = 0; $f_count = 0; $_student_id = 0; $_scoring = isset($student_score[$v])?$student_score[$v]:0; if(isset($student_topic[$v])) { if( count($student_topic[$v]) != count($paper_topic_data)) { Yii::app()->jump->error('导入的题数不正确!');exit; } } if(isset($student_ids[$v]) && !empty($student_ids[$v]) && isset($student_paper[$student_ids[$v]]) && !empty($student_paper[$student_ids[$v]]) && isset($student_paper_info[$student_ids[$v]])) { $_paper_id = $student_paper[$student_ids[$v]]; $_student_id = $student_ids[$v]; if(isset($student_topic[$v]) && !empty($student_topic[$v])) { $i = 0; foreach($student_topic[$v] as $key => $val) { $val = (int)$val; $complete_count += 1; $topic_id = ''; $_score = 0; $type = ''; $is_right = 0; if(isset($tops[$i]) && !empty($tops[$i])) { $topic_id = $tops[$i]; if(isset($scores[$tops[$i]]) && !empty($scores[$tops[$i]])) { $_score = $scores[$tops[$i]]; } if(isset($types[$tops[$i]]) && !empty($types[$tops[$i]])) { $type = $types[$tops[$i]]; } } if($type==1) { if($val==$_score) { $is_right = 1; $r_count += 1; }elseif($val>0 && $val<$_score) { $val = 0; $f_count +=1; }else { $f_count +=1; } } if($type==5) { if($val==$_score) { $is_right = 1; $r_count += 1; }else { $f_count +=1; } } if($type>5) { if($val==$_score) { $is_right = 1; $r_count += 1; }elseif($val>0 && $val<$_score) { if($_score*0.8<$val) { $is_right = 1; $r_count += 1; }else{ $is_right = 2; $f_count +=1; } } } if(empty($val)) { $val=0; } $_uuid = current($_uuid_arr); unset($_uuid_arr[$_uuid]); $sql.="(".$_uuid.",".$_student_id.",".$_paper_id.",".$topic_id.",".$type.','.$is_right.','.$val.",''),"; if($sql_sum==300 ) { $sql = substr($sql,0,-1).';'; $sql_arr[] = $sql; $sql_sum = 0; $sql = ''; } $i++; $sql_sum++; } } unset($student_topic[$v]); $paper_obj = $student_paper_info[$_student_id]; $_sql.= "(".$paper_obj->student_id.",".$paper_obj->paper_id.",".$paper_obj->class_id.",".$paper_obj->exam_id.",".$paper_obj->semester_id.",".$paper_obj->student_card.",'".$paper_obj->school_student_card."',".$complete_count.",".$r_count.",".$paper_obj->partial_right_count.",".$f_count.",".$_scoring.",".($total_score-$_scoring).",".$paper_obj->compare.",0,1,1,".time().",".time().",''),"; if($_sql_sum ==300) { $_sql = substr($_sql,0,-1).';'; $_sql_arr[] = $_sql; $_sql_sum = 0; $_sql = ''; } $_sql_sum++; }else { $_err['no_student']['student'][] = isset($student_name_data[(string)$v])?$student_name_data[(string)$v]:''; continue; } } unset($zhixue_student_card); $result = ''; if($_student_name_data) { $_err['no_student']['no_exam_student'] = $_student_name_data; } if($_err) { $y = 0; foreach($_err as $k=>$v) { if($k=='no_score') { $result['msg'][$y]['title'] = '错误无分数'; $result['msg'][$y]['result'] = implode(',',$v['student']); } if($k=='no_topic') { $result['msg'][$y]['title'] = '无做题'; $result['msg'][$y]['result'] = implode(',',$v['student']); } if($k=='no_exam_student') { $result['msg'][$y]['title'] = '无考试'; $result['msg'][$y]['result'] = implode(',',$v['student']); } if($k=='no_student') { $result['msg'][$y]['title'] = '不存在学生'; $result['msg'][$y]['result'] = implode(',',$v['student']); } if($k=='wrong_score') { $result['msg'][$y]['title'] = '上传成绩超出试卷小题成绩'; $result['msg'][$y]['result'] = implode(',',$v['student']); } if($k=='total_score') { $result['msg'][$y]['title'] = '上传成绩总分与各小题不符'; $result['msg'][$y]['result'] = implode(',',$v['student']); } $y++; } $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade'); $this->render('show',$result);exit; } if($sql){ $sql = substr($sql,0,-1).';'; $sql_arr[] = $sql; } if(!$sql_arr ) { Yii::app()->jump->error('数据有误,无法导入!');exit; } if($_sql){ $_sql = substr($_sql,0,-1).';'; $_sql_arr[] = $_sql; } if(!$_sql_arr ) { Yii::app()->jump->error('数据有误,无法导入!');exit; } $transaction = $this->sConn->beginTransaction(); try{ $criteria = new CDbCriteria(); $criteria->addInCondition('paper_id',$paper_ids); $criteria->addInCondition('student_id',$paper_student_ids); SStudentPaperTopicRs::model()->deleteAll($criteria); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('paper_id',$paper_ids); $criteria->addInCondition('student_id',$paper_student_ids); SStudentPaperRelation::model()->deleteAll($criteria); unset($criteria); $sql2 = 'INSERT INTO `student_paper_relation` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`student_card`,`school_student_card`,`complete_count`,`right_count`,`partial_right_count`,`wrong_count`,`scoring`,`lost_score`,`compare`,`report_created`,`is_feedback`,`is_complete`,`feedback_time`,`complete_time`,`studytrend_exam_name`)VALUES'; $sql1='INSERT INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`is_right`,`scoring`,`simplify_answer_url`)VALUES'; if($sql_arr) { foreach($sql_arr as $k=>$v) { if($v==';') { throw new Exception('数据有误,无法导入!'); } $this->sConn->createCommand($sql1.$v)->execute(); ob_flush(); } } unset($sql_arr); if($_sql_arr) { foreach($_sql_arr as $v) { if($v==';') { throw new Exception('数据有误,无法导入!'); } $this->sConn->createCommand($sql2.$v)->execute(); } } unset($_sql_arr); Exam::model()->updateAll(array('upload_status'=>2,'status'=>1,'is_topwb_html'=>0,'is_topwb_pdf'=>0,'is_academicr_html'=>0,'is_academicr_pdf'=>0,'update_time'=>time(),'complete_time'=>time()),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); ExamGroup::model()->updateAll(array('mark_status'=>2,'upload_status'=>2,'status'=>2,'import_score_type'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); Yii::app()->jump->error('Excel导入失败!'); } //$this->UUID_log($exam_group_id,$_uuid_arr_num); Yii::app()->jump->error('Excel导入成功!'); }else { $result['msg'][0]['title'] = '学生不存在'; $result['msg'][0]['result'] = '此文档中所有学生不存在'; $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade'); $this->render('show',$result);exit; } } } } Yii::app()->jump->error('Excel导入失败!'); } } //预生成ID 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($exam_group_id,$sum) { Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入智学网成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time()).',导入考试的ID:'.$exam_group_id); Yii::app()->redis_business_student->expire('redis_business_uuid_log:'.$this->schoolId,86400); } //新版导入成绩 public function actionImportScore(){ $examGroupId=Req::get('exam_group_id'); $checkField=Req::get('check_field'); $renew=Req::get('renew'); $data = array(); $sql="select * from import_score_temp where exam_type=0 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); if($data){ $this->redirect(Yii::app()->createUrl('record/check_excel')); }else{ $sql="select * from import_score_temp where exam_type=2 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); if($data) { $this->redirect(Yii::app()->createUrl('record/checkImgExcel')); } } $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $data['exam_name']=$exam['name']; $data['exam_group_id']=$examGroupId; $data['check_field']=$checkField; $data['renew']=$renew; //扩展字段设置 $studentExtend=$this->schoolManager->getStudentExtend(); $data['studentExtend']=$studentExtend; $this->render('import', $data); } //加载考试 public function actionAjaxSearchExam(){ $exam_type=Req::post('exam_type'); $subject=Req::post('subject'); $grade=Req::post('grade'); $class=Req::post('class'); $keyword=Req::post('keyword'); $condition=array(); //$condition[]=" (eg.qxk_paper_id=0 or eg.qxk_paper_id is null)"; $condition[]="e.semester_id='{$this->semesterId}'"; $condition[] = "e.is_display = 0"; if($exam_type==1){ $condition[]='eg.is_third=0'; }elseif($exam_type==2){ $condition[]='eg.is_third=1'; } $condition[] = "eg.homework = 0"; $condition[] = "eg.import_score_type <> 2"; 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."%'"; } $sql="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type,e.is_backlog FROM `exam` e "; $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id "; $sql.="join class c on c.class_id=e.class_id "; $sql.="join paper p on p.exam_id=e.exam_id "; if($condition){ $sql.=" where ".implode(' and ',$condition); } $sql.=" order by e.create_time desc "; $Exam = $this->sConn->createCommand($sql)->queryAll(); $list=array(); if($Exam){ $paperIds=array(); $examGroupIds=array(); foreach($Exam as $key=>$val){ $paperIds[$val['exam_group_id']][]=$val['paper_id']; $examGroupIds[]=$val['exam_group_id']; $list[$val['exam_group_id']]=$val; } if($class && $examGroupIds){ $paperIds=array(); $sqlClassCount="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type FROM `exam_group` eg "; $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id "; $sqlClassCount.="join class c on c.class_id=e.class_id "; $sqlClassCount.="join paper p on p.exam_id=e.exam_id "; $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).")"; $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll(); foreach ($ExamCount as $val){ $paperIds[$val['exam_group_id']][]=$val['paper_id']; $list[$val['exam_group_id']]=$val; } } //debug($examGroupIds); if($list){ foreach ($list as $key=>$val){ $list[$key]['student_score_count']=0; $list[$key]['class_count']=0; $list[$key]['exam_date']=''; if(isset($paperIds[$val['exam_group_id']])){ $list[$key]['class_count']=count($paperIds[$val['exam_group_id']]); $sql_student_paper="select count(*) as count from student_paper_relation where paper_id in(".implode(',',$paperIds[$val['exam_group_id']]).") and is_feedback=1"; $studentCount = $this->sConn->createCommand($sql_student_paper)->queryRow(); if($studentCount){ if($val['import_score_type']==0 && $studentCount['count']>0){ //扫描成绩,跳过 unset($list[$key]); continue; }else{ $list[$key]['student_score_count']=$studentCount['count']; } } } 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(isset(Yii::app()->params['grade_list'][$val['grade']])){ $list[$key]['grade']=Yii::app()->params['grade_list'][$val['grade']]['grade_name']; }else{ $list[$key]['grade']=''; } } } } $result['status']=1; $result['list']=$list; exit(json_encode($result)); } //新版全学科导入成绩,导入表格 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'); $check_field=Req::post('check_field'); $exam_renew=Req::post('exam_renew'); if(!$exam_group_id) { Yii::app()->jump->error('请选择考试信息'); } $uploader = new Uploader("upload/tmpDir/zhixue_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 20191202 @unlink($file["src"]); }catch (Exception $e){ // FIXME 20191202 @unlink($file["src"]); Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage()); } if(!$sheetData) { Yii::app()->jump->error('请正确的Excel!'); } unset($objPHPExcel); if(($check_field=='student_name' && $sheetData[1]['C']!='科目总分') || ($check_field!='student_name' && $sheetData[1]['C']=='科目总分')){ Yii::app()->jump->error('Excel格式不正确!'); } unset($sheetData[1]); if(!$sheetData) { Yii::app()->jump->error('请输入学生成绩数据'); } $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`) values"; $valuesArray=array(); foreach ($sheetData as $val){ if(!isset($val['A']) || !isset($val['B']) || !isset($val['C']) || !isset($val['D'])){ continue; } $student_topic= array_merge(array(),array_slice($val,2)); $regex = '/^[a-zA-Z0-9]+$/u'; if($check_field=='student_name'){ $topic_score=array_slice($student_topic,1); $check_field_value=$val['A']; }else{ $topic_score=array_slice($student_topic,2); $check_field_value=$val['C']; if(!preg_match($regex, $check_field_value)){ Yii::app()->jump->error('识别考号内容只能是数字和字母'); } } foreach ($topic_score as $k=>$v){ if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){ Yii::app()->jump->error('分数必须是数值类型且》=0'); } } if($check_field=='student_name'){ $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')"; }else{ $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')"; } } if($valuesArray){ // $delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp;"; $this->sConn->createCommand($delSql)->execute(); $insertSql.=implode(',',$valuesArray); $this->sConn->createCommand($insertSql)->execute(); $this->redirect(Yii::app()->createUrl('record/check_excel')); }else{ Yii::app()->jump->error('没有发现学生成绩数据'); } Yii::app()->jump->error('导入失败'); } } //导入数据检测页 public function actionCheck_Excel(){ $sql="select * from import_score_temp where exam_type=0 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); $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']; } } if(isset($fileName[$data['check_field']])){ $data['check_field_name']=$fileName[$data['check_field']]; }else{ $data['check_field_name']='学生姓名'; } $data['need_check_name']=0; if($data['check_field_name']=='学生姓名'){ $data['need_check_name']=1; } $this->render('check',$data); } //处理导入数据页面 public function actionHandle_Excel(){ $this->render('handle'); } //检测格式 public function actionCheck_field_first(){ $result['status']=0; $sql="select * from import_score_temp where exam_type=0"; $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)); } $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //检测题量 $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $total_score=0; if($exam_group_data) { foreach ($exam_group_data as $v) { $exam_id = $v->exam_id; $tpl_data = json_decode($v->tpl_data, 1); if (isset($tpl_data['scores'])) { $total_score = $tpl_data['scores']; } break; } unset($exam_group_data); $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id)); $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id))); if(!$paper_topic_data){ $result['msg']='请先关联答题卡再上传成绩'; exit(json_encode($result)); } $alias=array(); $sortPaperTopic=array(); //检测试题别名 if(isset($tpl_data['new_items']) && !$examGroup['qxk_paper_id']){ foreach ($tpl_data['new_items'] as $item){ $alias[$item['id']]=$item['alias']; } //重新排序 foreach ($paper_topic_data as $key =>$datum){ $sortPaperTopic[$alias[$datum['order']]]=$datum; } ksort($sortPaperTopic); $sortPaperTopic=array_values($sortPaperTopic); }else{ $sortPaperTopic=$paper_topic_data; } //检测试题数据 foreach($All_Data as $key=> $val){ $score_data=json_decode($val['score_data'],true); if($check_field!='student_name'){ $topic_score=array_slice($score_data,2); $total_score_import=$score_data['D']; }else{ $topic_score=array_slice($score_data,1); $total_score_import=$score_data['C']; } if($total_score_import!=array_sum($topic_score)){ $result['msg']='科目总分和试题总分不一致:'.$val['student_name']; exit(json_encode($result)); } if(count($topic_score)!=count($sortPaperTopic)){ $result['msg']='上传题量和试卷题量不一致:'.$val['student_name']; exit(json_encode($result)); } $topic_score=array_values($topic_score); 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($sortPaperTopic[$order])){ if($v>$sortPaperTopic[$order]['score']){ $result['msg']=$val['student_name'].':第'.($order+1).'题试题分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$sortPaperTopic[$order]['score']; exit(json_encode($result)); } }else{ $result['msg']='上传题量和试卷题量不一致'; exit(json_encode($result)); } } } $result['msg']='检测完成'; $result['status']=1; }else{ $result['msg']='未发现对应考试'; exit(json_encode($result)); } 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=0")->queryAll(); if($student_all_data){ //去除非中文字符 $updateArr=array(); $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/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=0"; $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=0 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(); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); $paperIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ if(!$tpl_data && isset($v['tpl_data'])){ $tpl_data=json_decode($v['tpl_data'],true); } $classIds[]=$v['class_id']; $paperIds[]=$v['paper_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=0 ")->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=0 ")->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=0"; }else{ $search_value_arr[]=$val[0]; } } if($search_value_arr){ $student_info=array(); $b_student=array(); switch ($check_field){ case 'student_name': $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,spr.student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.="join student_paper_relation spr on si.student_id = spr.student_id "; $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") and is_del=0 "; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if($b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; $student_card[$item['student_id']]=$item[$check_field]; } $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") and is_del=0 "; $student_info=$this->sConn->createCommand($sql)->queryAll(); if($student_info){ foreach($student_info as $key=>$val){ $student_info[$key][$check_field]=$student_card[$val['student_id']]; } } } 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]); } } if($check_field=='student_name'){ $nameArr=array(); foreach ($student_info as $item){ $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/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=0"; }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{ $studentGroup=array(); foreach ($student_info as $item){ $studentGroup[$item[$check_field]][]=$item; } foreach ($studentGroup as $key=>$val){ if(count($val)>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=0"; }else{ $success++; if(isset($check_data_group[$key])){ $update_temp_data[$check_data_group[$key]]=$val[0]['student_id']; } } } $noExistent=count($search_value_arr)-count($studentGroup); if($noExistent<0) $noExistent=0; $result['noExistent']=$noExistent; $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=0"; $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 actionGiveup(){ // $delSql="truncate table import_score_temp;"; $result['data']=$this->sConn->createCommand("select exam_group_id,check_field,renew from import_score_temp limit 1")->queryRow(); $delSql="delete from import_score_temp where exam_type=0 or exam_type=2;"; $this->sConn->createCommand($delSql)->execute(); $result['status']=1; exit(json_encode($result)); } //处理完毕,执行成绩导入 public function actionUpdate_score(){ ini_set('memory_limit','512M'); $result['status']=0; $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=0"; $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']; $examGroup=$this->sConn->createCommand("SELECT qxk_paper_id FROM `exam_group` where exam_group_id='".$exam_group_id."'")->queryRow(); $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam){ $result['msg']='考试ID不正确,请从考试列表点击上传成绩'; exit(json_encode($result)); } $paperIds=array(); $examIds=array(); foreach ($exam as $value){ $paperIds[]=$value['paper_id']; $examIds[]=$value['exam_id']; } $tpl_data=json_decode($exam[0]['tpl_data'],true); $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`order`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll(); if(!$paper_topic_relation){ $result['msg']='请关联答题卡'; exit(json_encode($result)); } $sortPaperTopic=array(); //检测试题别名 if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $item){ if($examGroup['qxk_paper_id']>0){ $alias[$item['id']]=$item['id']; }else{ $alias[$item['id']]=$item['alias']; } } //重新排序 foreach ($paper_topic_relation as $key =>$datum){ $sortPaperTopic[$alias[$datum['order']]]=$datum; } ksort($sortPaperTopic); $sortPaperTopic=array_values($sortPaperTopic); }else{ $sortPaperTopic=$paper_topic_relation; } $paper_topic_rs=array(); $scores=array(); $paperType=array(); foreach ($sortPaperTopic as $key=>$value){ $paper_topic_rs[$key]=$value['topic_id']; $scores[$key]=$value['score']; $paperType[$key]=$value['type']; } $sql='Replace INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE '; $deleteSql=array(); $updateSql=array(); $error=array(); $studentIds=array(); //用于检测重复 $time=time(); $uuidArr=array(); //批量uuid $needUuidCount=count($all_data)*count($paper_topic_relation); while ($needUuidCount>0){ $getIds=array(); if($needUuidCount>100000){ $getIds=getBatchUuid($this->schoolId,100000); $needUuidCount-=100000; }else{ $getIds=getBatchUuid($this->schoolId,$needUuidCount); $needUuidCount=0; } $uuidArr=array_merge($uuidArr,$getIds); } //debug($uuidArr); // $uuidArr=getBatchUuid($this->schoolId,$needUuidCount); foreach($all_data as $val){ $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).") and is_del=0")->queryRow(); if(!$StudentPaperRelation){ $error[]='学生没有参加本次考试 :'.$val['student_name']; continue; } $paper_id=$StudentPaperRelation['paper_id']; if($val['renew']==0){ $isFound=$this->sConn->createCommand("select * from student_paper_topic_rs where student_id='".$val['student_id']."' and paper_id='".$paper_id."'")->queryRow(); if($isFound){ continue; //已有成绩,跳过 } } $deleteSql[]="delete from `student_paper_topic_rs` where student_id='".$val['student_id']."' and paper_id='".$paper_id."' "; $topicScoreData=json_decode($val['score_data'],true); if($val['check_field']=='student_name'){ $topicScoreData=array_slice($topicScoreData,1); }else{ $topicScoreData=array_slice($topicScoreData,2); } $score_get=0; $lost_score=0; $topicScoreData=array_values($topicScoreData); $isHandle=0; foreach($topicScoreData as $key=> $ts){ $ts=(float)$ts; if(!$ts){ $ts=0; } $is_right=1; $bcR=bccomp($ts,$scores[$key],1); if($bcR==1 || $bcR==0){ if(!$isHandle || $paperType[$key]!=17){ $score=$scores[$key]; } if($paperType[$key]==17){ $isHandle=1; } }else{ $score=$ts; $l=bcsub($scores[$key],$ts,1); if(!$isHandle || $paperType[$key]!=17){ $lost_score=bcadd($lost_score,$l,1); } if($paperType[$key]==17 && $score){ $isHandle=1; } $is_right=0; } $score_get=bcadd($score_get,$score,1); $topic_id= $paper_topic_rs[$key]; $uuid=array_pop($uuidArr); $valueSql[]=' ('.$uuid.','.$val['student_id'].','.$paper_id.','.$topic_id.','.$paperType[$key].','.$score.','.$is_right.') '; } $updateSql_t=" update `student_paper_relation` set complete_count='".$tpl_data['totals']."',`scoring`='".$score_get."',`lost_score`='".$lost_score."',is_feedback=1,feedback_time='".$time."',is_complete=1,complete_time='".$time."'"; $updateSql_t.=" where student_id='".$val['student_id']."' and paper_id='".$paper_id."' "; $updateSql[]=$updateSql_t; } if($deleteSql && $updateSql && $valueSql){ $transaction = $this->sConn->beginTransaction(); try{ if($deleteSql){ foreach ($deleteSql as $dquery){ $this->sConn->createCommand($dquery)->execute(); } if($updateSql){ foreach ($updateSql as $uquery){ $this->sConn->createCommand($uquery)->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(); } } Exam::model()->updateAll(array('status'=>1,'upload_status'=>2,'complete_time'=>$time),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); ExamGroup::model()->updateAll(array('mark_status'=>2,'status'=>2,'upload_status'=>2,'import_score_type'=>3),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //清理导入临时数据 // $delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=0;"; $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']='导入成功'; } 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" =>'', "date"=>date('Y-m-d H:i:s') ))); } $conf = new RdKafka\Conf(); $conf->set('metadata.broker.list', Yii::app()->params['kafka']); $producer = new RdKafka\Producer($conf); $topic = $producer->newTopic("xbkc-academic-offline-generate-report"); $kafkaData=array( 'examGroupId'=>$exam_group_id, 'schoolId'=>$this->schoolId, 'generateTime'=>time()*1000 ); $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($kafkaData)); $producer->poll(0); $producer->flush(10000); //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_group_id, ); sendStudentCacheQueue($sendJsonArr); exit(json_encode($result)); } }catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); // Yii::app()->jump->error('成绩导入失败,请检查后重新'); $result['msg']='成绩导入失败,请检查后重新导入'; exit(json_encode($result)); } }else{ //没有需要重新导入的数据,清理导入临时数据 //$delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=0;"; $this->sConn->createCommand($delSql)->execute(); $result['status']=1; 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=0 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=0 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('record/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{ if($check_field=='student_name'){ $this->render('handle', $data); }else{ $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']; } } $data['fieldName']=$fileName[$check_field]; $data['check_field']=$check_field; $this->render('handle_card', $data); } } } //处理重复考号 public function actionHandle_card(){ $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=1 and exam_type=0 "; $all_data=$this->sConn->createCommand($sql)->queryAll(); $data['list']=$all_data; $data['fieldName']=$fileName; $this->render('handle_card',$data); } //处理不存在学生 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=0 "; $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 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']; } } $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=0"; $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.=''; if($check_field=='student_name'){ $scoreArr=array_slice($topic_score,1); $excel_html.=''; }else{ $excel_html.=''; $excel_html.=''; $scoreArr=array_slice($topic_score,2); } for($i=1;$i<=count($scoreArr);$i++){ $excel_html.=''; } $excel_html.=''; $i=1; foreach($excel_data as $val){ $topic_score=json_decode($val['score_data'],true); if($check_field=='student_name'){ $scoreArr=array_slice($topic_score,1); $totalScore=$topic_score['C']; }else{ $card_value=$val['check_field_value']; $totalScore=$topic_score['D']; $scoreArr=array_slice($topic_score,2); } $numberToId[$i]=$val['id']; $excel_html.=''; $excel_html.=''; if(isset($card_value)){ $excel_html.=''; $excel_html.=''; $excel_html.=''; }else{ $excel_html.=''; $excel_html.=''; } $excel_html.=''; foreach($scoreArr as $v){ $excel_html.=''; } $excel_html.=''; $i++; } $excel_html.=''; $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$excel_data[0]['exam_group_id']."'")->queryAll(); $paperIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ $paperIds[]=$v['paper_id']; } } $_allStudent=array(); if($check_field=='student_name'){ $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 student_paper_relation spr on sc.student_id = spr.student_id "; $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' "; $sys_sql.="order by end_time desc ;"; $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll(); }elseif($check_field=='student_card'){ $sql="select student_id,student_card from student where student_card ='".$name."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryRow(); if($b_student){ $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 student_paper_relation spr on sc.student_id = spr.student_id "; $sys_sql.=" where sc.student_id = '".$b_student['student_id']."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' "; $sys_sql.="order by end_time desc ;"; $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll(); } }elseif($check_field=='school_student_card') { $sql = "select student_id,school_student_card from student where school_student_card ='" . $name . "'and status=0"; $b_student = $this->conn->createCommand($sql)->queryRow(); if ($b_student) { $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 student_paper_relation spr on sc.student_id = spr.student_id "; $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' "; $sys_sql .= "order by end_time desc ;"; $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll(); } }elseif($check_field=='zhixue_student_card'){ $sql = "select student_id,zhixue_student_card from student where zhixue_student_card ='" . $name . "'and status=0"; $b_student = $this->conn->createCommand($sql)->queryRow(); if ($b_student) { $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 student_paper_relation spr on sc.student_id = spr.student_id "; $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' "; $sys_sql .= "order by end_time desc ;"; $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll(); } }else{ $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 student_paper_relation spr on sc.student_id = spr.student_id "; $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") 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=0 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=0"; } } if($updateSql){ foreach($updateSql as $query){ $this->sConn->createCommand($query)->execute(); } $result['status']=1; } exit(json_encode($result)); } //修改不存在的学生数据 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=0 "; $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=0"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名'; } exit(json_encode($result)); } //系统中是否有数据 $exam_group_id=$data['exam_group_id']; $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam_group_data){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); } $paperIds=array(); $examIds=array(); $classIds=array(); foreach ($exam_group_data as $val){ $paperIds[]=$val['paper_id']; $examIds[]=$val['exam_id']; $classIds[]=$val['class_id']; } if($exam_group_data){ $student_info=array(); switch ($check_field){ case 'student_name': $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,spr.student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.="join student_paper_relation spr on si.student_id = spr.student_id "; $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card ='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") "; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(isset($b_student) && $b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; } $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")"; $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 student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->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=0 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 actionChange_check(){ $check_value=Req::post('check_value'); $result['status']=0; if(!$check_value){ exit(json_encode($result)); } $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=0"; $student_info=$this->sConn->createCommand($sql)->queryAll(); if(!$student_info){ $result['status']=1; //没有数据,处理完毕 exit(json_encode($result)); }elseif(count($student_info)>1){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); }else{ //只剩一条,查询 $data=$student_info[0]; $check_field=$data['check_field']; $id=$data['id']; //系统中是否有数据 $exam_group_id=$data['exam_group_id']; $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam_group_data){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); } $paperIds=array(); $examIds=array(); $classIds=array(); foreach ($exam_group_data as $value){ $paperIds[]=$value['paper_id']; $examIds[]=$value['exam_id']; $classIds[]=$value['class_id']; } if($exam_group_data){ $student_info=array(); switch ($check_field){ case 'student_name': $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(isset($b_student) && $b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; } $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(!$student_info){ $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理'; $result['status']=0; exit(json_encode($result)); }elseif(count($student_info)>1){ $result['msg']='系统中存在多个该学生数据,请检查后重新填写'; $result['status']=0; exit(json_encode($result)); }else{ $result['status']=1; $studentId=$student_info[0]['student_id']; //查询是否参加考试 $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->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."' limit 1")->queryRow(); if($related){ $result['status']=0; $result['msg']='需要继续处理'; exit(json_encode($result)); }else{ $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); exit(json_encode($result)); } } }else{ $result['msg']='考试数据有误'; exit(json_encode($result)); } } } /*导入学生答题图片*/ //导入图片,导入表格 public function actionImportStudentExcel(){ 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'); $check_field=Req::post('check_field'); $exam_renew=Req::post('exam_renew'); if(!$exam_group_id) { Yii::app()->jump->error('请选择考试信息'); } $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/"); $uploader->allowTypes = array("xls","xlsx"); $uploader->fieldsMappings = array("exnameYwy" => 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 20191202 @unlink($file["src"]); }catch (Exception $e){ // FIXME 20191202 @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('请输入学生图片数据'); } $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']) || !isset($val['C']) ){ continue; } $student_topic=array_slice($val,2); $regex = '/^[a-zA-Z0-9]+$/u'; if($check_field=='student_name'){ //$student_topic=array_slice($val,2); }else{ $check_field_value=$val['C']; if(!preg_match($regex, $check_field_value)){ Yii::app()->jump->error('识别考号内容只能是数字和字母'); } } if($check_field=='student_name'){ $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)"; }else{ $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)"; } } if($valuesArray){ // $delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp;"; $this->sConn->createCommand($delSql)->execute(); $insertSql.=implode(',',$valuesArray); $this->sConn->createCommand($insertSql)->execute(); $this->redirect(Yii::app()->createUrl('record/checkImgExcel')); }else{ Yii::app()->jump->error('没有发现学生图片数据'); } Yii::app()->jump->error('导入失败'); } } //导入图片检测页 public function actionCheckImgExcel(){ $sql="select * from import_score_temp where exam_type=2 limit 1"; $data=$this->sConn->createCommand($sql)->queryRow(); $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']; } } if(isset($fileName[$data['check_field']])){ $data['check_field_name']=$fileName[$data['check_field']]; }else{ $data['check_field_name']='学生姓名'; } $data['need_check_name']=0; if($data['check_field_name']=='学生姓名'){ $data['need_check_name']=1; } $this->render('check_img',$data); } //检测导入图片数据格式 public function actionCheck_img_field_first(){ $result['status']=0; $sql="select * from import_score_temp where exam_type=2"; $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)); } //检测题量 $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data) { foreach ($exam_group_data as $v) { $exam_id = $v->exam_id; $tpl_data = json_decode($v->tpl_data, 1); } unset($exam_group_data); $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id)); $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id))); if(!$paper_topic_data){ $result['msg']='请先关联答题卡再上传成绩'; exit(json_encode($result)); } //判断是否上传成绩 //检测试题数据 foreach($All_Data as $key=> $val){ $score_data=json_decode($val['score_data'],true); $score_data=array_slice($score_data,1); if(count($score_data)!=count($paper_topic_data)){ $result['msg']='上传题量和试卷题量不一致:'.$val['student_name']; exit(json_encode($result)); } $topic_score=array_values($score_data); foreach($topic_score as $order => $v){ if(!isset($paper_topic_data[$order])){ $result['msg']='上传题量和试卷题量不一致'; exit(json_encode($result)); } } } $result['msg']='检测完成'; $result['status']=1; }else{ $result['msg']='未发现对应考试'; exit(json_encode($result)); } exit(json_encode($result)); } //检测导入图片姓名 public function actionCheck_img_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=2")->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=0"; $this->sConn->createCommand($sql)->execute(); } $transcation->commit(); $result['status']=1; }catch (Exception $e){ $transcation->rollback(); } } $result['count']=$count; } exit(json_encode($result)); } //匹配信息 public function actionMatchingImg(){ $noExistent=0; //不存在 $repeat=0; //重复(组) $success=0; //匹配成功 $scoreWrong=0; //成绩不正确 $result['status']=0; $sql="select * from import_score_temp where exam_type=2 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(); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); $paperIds=array(); if($exam_group_data){ foreach ($exam_group_data as $v){ if(!$tpl_data && isset($v['tpl_data'])){ $tpl_data=json_decode($v['tpl_data'],true); } $classIds[]=$v['class_id']; $paperIds[]=$v['paper_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=0 ")->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=0 ")->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=2"; }else{ $search_value_arr[]=$val[0]; } } if($search_value_arr){ $student_info=array(); $b_student=array(); switch ($check_field){ case 'student_name': $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,spr.student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.="join student_paper_relation spr on si.student_id = spr.student_id "; $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") "; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if($b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; $student_card[$item['student_id']]=$item[$check_field]; } $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") "; $student_info=$this->sConn->createCommand($sql)->queryAll(); if($student_info){ foreach($student_info as $key=>$val){ $student_info[$key][$check_field]=$student_card[$val['student_id']]; } } } 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]); } } if($check_field=='student_name'){ $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=2"; }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{ $studentGroup=array(); foreach ($student_info as $item){ $studentGroup[$item[$check_field]][]=$item; } foreach ($studentGroup as $key=>$val){ if(count($val)>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=2"; }else{ $success++; if(isset($check_data_group[$key])){ $update_temp_data[$check_data_group[$key]]=$val[0]['student_id']; } } } $noExistent=count($search_value_arr)-count($studentGroup); if($noExistent<0) $noExistent=0; $result['noExistent']=$noExistent; $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=2"; $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_img(){ $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=2 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=2 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('record/checkImgExcel')); } $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{ if($check_field=='student_name'){ $this->render('handle', $data); }else{ $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']; } } $data['fieldName']=$fileName[$check_field]; $data['check_field']=$check_field; $this->render('handle_card_img', $data); } } } //修改后确认 public function actionChange_check_img(){ $check_value=Req::post('check_value'); $result['status']=0; if(!$check_value){ exit(json_encode($result)); } $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=2"; $student_info=$this->sConn->createCommand($sql)->queryAll(); if(!$student_info){ $result['status']=1; //没有数据,处理完毕 exit(json_encode($result)); }elseif(count($student_info)>1){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); }else{ //只剩一条,查询 $data=$student_info[0]; $check_field=$data['check_field']; $id=$data['id']; //系统中是否有数据 $exam_group_id=$data['exam_group_id']; $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam_group_data){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); } $paperIds=array(); $examIds=array(); $classIds=array(); foreach ($exam_group_data as $value){ $paperIds[]=$value['paper_id']; $examIds[]=$value['exam_id']; $classIds[]=$value['class_id']; } if($exam_group_data){ $student_info=array(); switch ($check_field){ case 'student_name': $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(isset($b_student) && $b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; } $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(!$student_info){ $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理'; $result['status']=0; exit(json_encode($result)); }elseif(count($student_info)>1){ $result['msg']='系统中存在多个该学生数据,请检查后重新填写'; $result['status']=0; exit(json_encode($result)); }else{ $result['status']=1; $studentId=$student_info[0]['student_id']; //查询是否参加考试 $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->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."' limit 1")->queryRow(); if($related){ $result['status']=0; $result['msg']='需要继续处理'; exit(json_encode($result)); }else{ $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}"; $this->sConn->createCommand($updateSql)->execute(); exit(json_encode($result)); } } }else{ $result['msg']='考试数据有误'; exit(json_encode($result)); } } } //绑定学生id public function actionBindingImg(){ $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=2 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=2"; } } if($updateSql){ foreach($updateSql as $query){ $this->sConn->createCommand($query)->execute(); } $result['status']=1; } exit(json_encode($result)); } //修改不存在的学生数据 public function actionChange_value_img(){ $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=2 "; $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=2"; $this->sConn->createCommand($updateSql)->execute(); $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名'; } exit(json_encode($result)); } //系统中是否有数据 $exam_group_id=$data['exam_group_id']; $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam_group_data){ $result['status']=0; //还有重复数据,需要继续处理 exit(json_encode($result)); } $paperIds=array(); $examIds=array(); $classIds=array(); foreach ($exam_group_data as $val){ $paperIds[]=$val['paper_id']; $examIds[]=$val['exam_id']; $classIds[]=$val['class_id']; } if($exam_group_data){ $student_info=array(); switch ($check_field){ case 'student_name': $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'userno': $sql="select userno,spr.student_id from student_info si "; $sql.="join student_class_relation scr on scr.student_id=si.student_id "; $sql.="join student_paper_relation spr on si.student_id = spr.student_id "; $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")"; $student_info=$this->sConn->createCommand($sql)->queryAll(); break; case 'student_card': $sql="select student_id,student_card from student where student_card ='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'school_student_card': $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; case 'zhixue_student_card': $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0"; $b_student=$this->conn->createCommand($sql)->queryAll(); break; default: $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") "; $student_info=$this->sConn->createCommand($sql)->queryAll(); } if(isset($b_student) && $b_student){ $studentIds=array(); foreach ($b_student as $item){ $studentIds[]=$item['student_id']; } $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")"; $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 student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->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=2 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 actionHandle_existent_img(){ $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=2 "; $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 actionUpdate_images(){ ini_set('memory_limit','512M'); $result['status']=0; $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=2"; $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']; $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll(); if(!$exam){ $result['msg']='考试ID不正确,请从考试列表点击上传成绩'; exit(json_encode($result)); } $paperIds=array(); $examIds=array(); foreach ($exam as $value){ $paperIds[]=$value['paper_id']; $examIds[]=$value['exam_id']; } $tpl_data=json_decode($exam[0]['tpl_data'],true); $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll(); if(!$paper_topic_relation){ $result['msg']='请关联答题卡'; exit(json_encode($result)); } $paper_topic_rs=array(); $paperType=array(); foreach ($paper_topic_relation as $key=>$value){ $paper_topic_rs[$key]=$value['topic_id']; $paperType[$key]=$value['type']; } $error=array(); $updateArr=array(); $studentInPaper=array(); foreach($all_data as $val){ $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).")")->queryRow(); if(!$StudentPaperRelation){ $error[]='学生没有参加本次考试 :'.$val['student_name']; continue; } $studentInPaper[(string)$val['student_id']]=$StudentPaperRelation['paper_id']; $topicScoreData=json_decode($val['score_data'],true); if($val['check_field']!='student_name'){ $topicScoreData=array_slice($topicScoreData,1); } $topicScoreData=array_values($topicScoreData); foreach($topicScoreData as $key=> $ts){ if(!$ts) continue; $topic_id= $paper_topic_rs[$key]; $image_array = @getimagesize($ts); if ($image_array && isset($image_array[0]) && isset($image_array[1])) { $updateArr[(string)$val['student_id']]['answer_url'][$topic_id]=$ts; $updateArr[(string)$val['student_id']]['answer_url_width'][$topic_id]=$image_array[0]; $updateArr[(string)$val['student_id']]['answer_url_height'][$topic_id]=$image_array[1]; $updateArr[(string)$val['student_id']]['simplify_answer_url'][$topic_id]=$ts; $updateArr[(string)$val['student_id']]['simplify_answer_url_width'][$topic_id]=$image_array[0]; $updateArr[(string)$val['student_id']]['simplify_answer_url_height'][$topic_id]=$image_array[1]; } } } if($updateArr){ $transaction = $this->sConn->beginTransaction(); try{ $sqlArr=array(); foreach ($updateArr as $student_id =>$value){ $updateSqlTemp=array(); $sql='update `student_paper_topic_rs` set '; foreach ($value as $filed =>$val){ $updateSqlStr=" `{$filed}` = case topic_id "; foreach ($val as $topic_id =>$v){ $updateSqlStr.=" WHEN '".$topic_id."' THEN '".$v."' "; } $updateSqlStr.=" ELSE `{$filed}` "; $updateSqlStr.=" END "; $updateSqlTemp[]=$updateSqlStr; } $sqlArr[]= $sql.implode(',',$updateSqlTemp)." where student_id='".$student_id."' and paper_id ='".$studentInPaper[$student_id]."'"; } foreach ($sqlArr as $v){ $this->sConn->createCommand($v)->execute(); } //清理导入临时数据 $delSql="delete from import_score_temp where exam_type=2;"; $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']='导入成功'; } 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" =>'', "date"=>date('Y-m-d H:i:s') ))); } exit(json_encode($result)); }catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); // Yii::app()->jump->error('成绩导入失败,请检查后重新'); $result['msg']='图片导入失败,请检查后重新导入'; exit(json_encode($result)); } }else{ //没有需要重新导入的数据,清理导入临时数据 //$delSql="truncate table import_score_temp;"; $delSql="delete from import_score_temp where exam_type=2;"; $this->sConn->createCommand($delSql)->execute(); $result['status']=1; exit(json_encode($result)); } } public function actionT(){ //$image_array = getimagesize('http://zxhx-n-1302712961.cos.ap-beijing.myqcloud.com/PT/CScut/4016/990807494965600256/945581044318568448/6.jpg'); //$image_array = getimagesize('https://pics7.baidu.com/feed/2cf5e0fe9925bc31e23d52434fdae8bdca13709e.jpeg'); $image_array = getimagesize('http://ftp.hujiao.com/iu-1.png'); debug($image_array); } }