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("zsyte-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.='班级 | '; if($check_field=='student_name'){ $scoreArr=array_slice($topic_score,1); $excel_html.='科目总分 | '; }else{ $excel_html.=''.$fileName[$check_field].' | '; $excel_html.='科目总分 | '; $scoreArr=array_slice($topic_score,2); } for($i=1;$i<=count($scoreArr);$i++){ $excel_html.='第'.$i.'题 | '; } $excel_html.='|
---|---|---|---|---|---|---|---|
'.$i.' | '; if(isset($card_value)){ $excel_html.=''.$val['student_name'].' | '; $excel_html.=''.$val['class_name'].' | '; $excel_html.=''; }else{ $excel_html.=' | '.$val['check_field_value'].'(原'.$val['student_name'].') | '; $excel_html.=''.$val['class_name'].' | '; } $excel_html.=''.$totalScore.' | '; foreach($scoreArr as $v){ $excel_html.=''.$v.' | '; } $excel_html.='