coachId;
$semester_id = $this->semesterId;
$PageLimit=9;
if(!$Page) $Page=1;
$ZlExamGroup=new ZlExamGroup();
$result=$ZlExamGroup->getList($Grade,$Class,$semester_id,$Page,$PageLimit,$Display);
$ZlStudentExamRelation=new ZlStudentExamRelation();
$ZlStudentExamRs=new ZlStudentExamRs();
if($result['data']){
foreach($result['data'] as $key=>$val){
$tpl_data=json_decode($val['zl_tpl_data'],true);
$result['data'][$key]['classCount']=$tpl_data['classCount'];
$result['data'][$key]['subjectCount']=count($tpl_data['items']);
$subjectArr=array();
foreach ($tpl_data['items'] as $sid=>$c){
$subjectArr[]= Yii::app()->params['subjectId'][$sid];
}
$result['data'][$key]['subjects']=$subjectArr;
//上传进度
$allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id']);
$allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id']);
$result['data'][$key]['progress']=$allStudentRs.'/'.$allStudent;
if($allStudentRs){
$result['data'][$key]['status']=1;
}else{
$result['data'][$key]['status']=0;
}
}
}
// debug($result);
$printType = '2';
$printTypeData = 0;
$viewData=array(
'pageTotal' =>$result['pageTotal'],
'dataList' =>$result['data'],
'page' =>$Page,
'grade' =>$Grade,
'class' =>$Class,
'display' =>$Display,
'totalCount' =>$result['totalCount'],
'printType' =>$printType
);
//$HeadInfo=$this->getHeadInfo();
// $viewData=array_merge($viewData,$HeadInfo);
$this->render('index',$viewData);
}
public function actionEdit(){
$viewData=array();
$viewData=array(
'printType'=>'zl'
);
if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
$viewData['subject']=Yii::app()->params['subjectId'];
unset($viewData['subject'][3]);
unset($viewData['subject'][51]);
unset($viewData['subject'][20]);
}
$exam_group_id = Req::get("exam_group_id");
if($exam_group_id){
//读取考试信息
$ZlExamGroup=new ZlExamGroup();
$ZlStudentExamRs=new ZlStudentExamRs();
$studentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($exam_group_id);
if($studentRs){
Yii::app()->jump->error('已上传成绩,不能编辑考试!');
}
$examData=$ZlExamGroup->getExamByExamGroupId($exam_group_id);
$examView=array();
$tplData=array();
foreach ($examData as $val){
if(!$tplData){
$tplData=json_decode($val['zl_tpl_data'],true);
$examView['items']=$tplData['items'];
//$examView['examDate']=$tplData['examDate'];
}
$examView['zl_exam_name']=$val['zl_exam_name'];
$examView['zl_exam_type']=$val['zl_exam_type'];
$examView['examDate']=date('Y-m-d',$val['zl_exam_date']);
$examView['classes'][$val['zl_class_id']]=ClassModel::model()->getClassName($val['zl_class_id']);
$examView['grade']=$val['zl_grade'];
}
$viewData['exam']=$examView;
$viewData['exam_group_id']=$exam_group_id;
}
$this->render('thirdview',$viewData);
}
public function actionAjaxchangeclasses()
{
$result = array();
$error = array();
$class_arr_select=array();
if (Yii::app()->request->getIsPostRequest()){
$selectedClassId=Req::post('selectedClassId');
$semester_id = $this->semesterId;
if($selectedClassId){
$anotherSelectClass=ClassModel ::model()->getClassArrayByIds($selectedClassId);
$i = 0;
if($anotherSelectClass){
foreach ($anotherSelectClass as $cas){
$class_arr_select[$i]['class_id'] = $cas['class_id'];
$class_arr_select[$i]['class_name'] = $cas['class_name'];
$class_arr_select[$i]['grade'] = $cas['grade'];
$i++;
$class_arr_select_ids[] = $cas['class_id'];
}
}
}
$class_arr_select_ids_str = "";
if(isset($class_arr_select_ids) && $class_arr_select_ids){
foreach($class_arr_select_ids as $v){
$class_arr_select_ids_str.=$v.",";
}
$class_arr_select_ids_str=substr($class_arr_select_ids_str,0,-1);
}
$class_arr_noselect_data = ClassModel ::model()->getNoSelectclasses($semester_id,$class_arr_select_ids_str);
$class_arr_noselect =array();
$j = 0;
if($class_arr_noselect_data){
foreach($class_arr_noselect_data as $cans){
$class_arr_noselect[$j]['class_id'] = $cans->class_id;
$class_arr_noselect[$j]['class_name'] = $cans->class_name;
$class_arr_noselect[$j]['grade'] = $cans->grade;
$j++;
}
}
$result['class_arr_select'] = $class_arr_select;
$result['class_arr_noselect'] = $class_arr_noselect;
}else{
$error[] = "错误的来源";
}
header('Content-Type: application/json');
if($error){
echo json_encode(array('status' => 0, 'error'=> implode('
', $error)));exit;
}else{
echo json_encode($result);exit;
}
}
public function actionCreateexam(){
$error = array();
$examName = Req::post("examName");
$type = (int)Req::post("type");
$classIds = Req::post("classIds");
$subjects = Req::post("subjects");
$examDate = Req::post("examDate");
$grade = Req::post("grade");
$ExamGroupId = Req::post("exam_group_id");
if(empty($classIds)){
$error[] = '请指定考试班级';
}else{
$classIds = explode(',',substr($classIds,0,-1));
}
if(empty($examName)){
$error[] = '请设置考试名称';
}
if ($type <= 0 || $type > 8) {
$error[] = '考试类型错误';
}
if(empty($subjects)){
$error[] = '请选择科目';
}
if(empty($examDate)){
$error[] = '请指定考试时间';
}
if((time()-strtotime($examDate))>86400*90){
$error[] = '考试时间不正确';
}
if($error){
Yii::app()->jump->error(implode(',',$error));
}else{
//解析科目分数
$tplData=array();
$tplData['name']=$examName;
// $tplData['examDate']=$examDate;
$tplData['classCount']=count($classIds);
$subject_ids=array();
$subjectArr=explode(',',$subjects);
if($subjectArr){
$total_score=0;
foreach ($subjectArr as $value){
$subject_score=explode('///',$value);
$tplData['items'][$subject_score[0]]=$subject_score[1];
$total_score+=$subject_score[1];
$subject_ids[]=$subject_score[0];
}
$tplData['scores']=$total_score;
}
$time = time();
$transaction = $this->sConn->beginTransaction();
try{
if($ExamGroupId){
$this->sConn->createCommand("delete from `zl_exam_group` where zl_exam_group_id='".$ExamGroupId."'")->execute();
$this->sConn->createCommand("delete from `zl_exam` where zl_exam_group_id='".$ExamGroupId."'")->execute();
$this->sConn->createCommand("delete from `zl_student_exam_relation` where zl_exam_group_id='".$ExamGroupId."'")->execute();
$newExamGroupId = $ExamGroupId;
}else{
// $newExamGroupId = $this->schoolManager->UUID_SHORT();
$newExamGroupId=getUniqueId($this->schoolId);
}
$sql = "insert into `zl_exam_group` (`zl_exam_group_id`,`zl_exam_name`,`zl_exam_type`,`zl_grade`,`zl_exam_date`,`zl_create_time`,`zl_is_display`,`zl_semester_id`) "
. "values (".$newExamGroupId.",'".$examName."',".$type.",'".$grade."','".strtotime($examDate)."',".time().",0,'".$this->semesterId."')";
$this->sConn->createCommand($sql)->execute();
foreach($classIds as $classId){
//$newExamId = $this->schoolManager->UUID_SHORT();
$newExamId=getUniqueId($this->schoolId);
$sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
$cardData = $this->sConn->createCommand($sql)->queryRow();
if($cardData['card_status']==0){
$cardData['card_length'] = 8;
if($this->schoolId >999){
$cardData['card_length'] = 9;
}
}
$this->sConn->createCommand()->insert('zl_exam',array(
'zl_exam_id' => $newExamId,
'zl_exam_group_id' => $newExamGroupId,
'zl_semester_id' => $this->semesterId,
'zl_subject_ids' => implode(',',$subject_ids),
'create_time' => $time,
'zl_tpl_data' => jsonEncode($tplData),
'zl_class_id' => $classId,
));
$studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
$studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
$BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
if($studentIds_0){
foreach ($studentIds_0 as $studentId) {
$this->sConn->createCommand()->insert('zl_student_exam_relation', array(
'zl_student_id' => $studentId,
'zl_exam_group_id' => $newExamGroupId,
'zl_exam_id' => $newExamId,
'zl_semester_id' => $this->semesterId,
'zl_class_id' => $classId,
'zl_student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
'zl_school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
));
}
}
}
$transaction->commit();
}catch(Exception $e){
$transaction->rollBack();
if (YII_ENV == 'production') {
$error[] = '系统错误[SQL]';
} else {
$error[] = $e->getMessage();
}
}
}
if(!$error){
$this->redirect($this->createUrl('zhiliao/index'));
}else{
Yii::app()->jump->error(implode(',',$error));
}
}
public function actionExam_list()
{
$exam_group_id = Req::get("exam_group_id");
if($exam_group_id>0)
{
$classId = Req::get("classId");
$condition = array();
if($classId)
$condition[] = "e.zl_class_id = '{$classId}'";
$condition[] = "eg.zl_exam_group_id = '{$exam_group_id}'";
// $classes = $this->schoolManager->getSemesterClasses($this->semesterId);
$classes=ClassModel::model()->getClassBySemester($this->semesterId);
if(!$classes)
{
Yii::app()->jump->error('本学期尚未建班级!');
}
$_classes = array();
foreach($classes as $v)
{
$_classes[$v['class_id']][$v['class_id']] = $v;
}
$resultList = $this->schoolManager->getZlExamList($condition);
$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
$data['printList'] = $resultList['rs'];
$data["classes"] = $_classes;
$data['pages'] = $resultList['pager'];
$data['page_total'] = $resultList['pager']->rowsCount;
$data["classId"] = $classId;
$data["exam_group_id"] = $exam_group_id;
$data["subject"] = $subject_exam_data;
$this->render('exam_list',$data);
}
}
//删除全部未考试学生
public function actionDelExamStudentAll()
{
$exam_group_id = Req::post('exam_group_id');
if(!$exam_group_id)
{
echo json_encode(array('status'=>0));exit;
}
$ZlStudentExamRelation=new ZlStudentExamRelation();
$student_data =$ZlStudentExamRelation->getCountStudentByExamGroupId($exam_group_id);
if(!$student_data){
echo json_encode(array('status'=>2));exit;
}
if($ZlStudentExamRelation->delStudentPaperByExamIds($exam_group_id))
{
//操作日志
if(Yii::app()->params['handle_log_on_off'])
{
writeFileLog(jsonEncode(array(
"exam_group_id" =>$exam_group_id,
"operate_project" => 'zsyas2',
"school_id" => $this->schoolId,
"title" => '清空本次考试的学生(家校考试)',
"operate_account" => Yii::app()->session['coachInfo']['coach_name'],
"operate_method" => $this->action,
"operate_url" => $this->getRoute(),
"operate_sql" => json_encode(array('delete'=>array(
'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))),
"operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
"date"=>date('Y-m-d H:i:s')
)));
}
echo json_encode(array('status'=>1));exit;
}
echo json_encode(array('status'=>0));exit;
}
//上传成绩
public function actionUpload(){
$exam_group_id = Req::get("exam_group_id");
$sql="select * from import_score_temp where exam_group_id<>'".$exam_group_id."' and exam_type=1 limit 1";
$anotherData=$this->sConn->createCommand($sql)->queryRow();
if($anotherData){
Yii::app()->jump->error('请先处理完成其它考试上传成绩数据,再上传新的考试');
}
$sql="select * from import_score_temp where exam_group_id='".$exam_group_id."' and exam_type=1 limit 1";
$Data=$this->sConn->createCommand($sql)->queryRow();
if($Data){
//跳转检测页
$this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
}
$printType = '2';
$viewData=array(
'printType' =>$printType,
'examGroupId' =>$exam_group_id
);
$this->render('upload',$viewData);
}
//新版导入成绩,导入表格
public function actionImportStore(){
ini_set ('memory_limit', '300M');
if(!$_FILES){
Yii::app()->jump->error('文件大小超过范围');
}else{
if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
Yii::app()->jump->error('文件大小超过范围');
}
}
if (Yii::app()->request->getIsPostRequest()) {
$exam_group_id=Req::post('exam_group_id');
if(!$exam_group_id)
{
Yii::app()->jump->error('请选择考试信息');
}
$uploader = new Uploader("upload/tmpDir/zhiliao_chengji/{$this->schoolId}/");
$uploader->allowTypes = array("xls","xlsx");
$uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
$file = $uploader->act();
$file = Arr::current(Arr::current($file));
if (!$file || !isset($file["error"]))
Yii::app()->jump->error('请上传的Excel!');
if ($file["error"] != 0) {
switch ($file["error"]) {
case 2001:
Yii::app()->jump->error('文件类型不符');
break;
case 2002:
Yii::app()->jump->error('文件大小超出允许范围');
break;
default:
Yii::app()->jump->error('上传失败');
break;
}
}
$inputFileName = $file["src"];
// 导入PHPExcel类
Yii::import('application.extensions.*');
require_once('phpexcel/PHPExcel/IOFactory.php');
try{
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
//FIXME 2019-12-02
@unlink($file["src"]);
}catch (Exception $e){
//FIXME 2019-12-02
@unlink($file["src"]);
Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
}
if(!$sheetData)
{
Yii::app()->jump->error('请正确的Excel!');
}
unset($objPHPExcel);
unset($sheetData[1]);
if(!$sheetData)
{
Yii::app()->jump->error('请输入学生成绩数据');
}
$ZlExam=new ZlExam();
$exam_group_data = $ZlExam->getExamByExamGroupId($exam_group_id);
//debug($exam_group_data);
$total_score=0;
//表格科目对应
$letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM');
$allSubject=Yii::app()->params['subjectId'];
unset($allSubject[3]);
unset($allSubject[20]);
unset($allSubject[51]);
$subjectExcel=array();
$subjectOrder=0;
foreach ($allSubject as $key =>$val){
$subjectExcel[$letters[$subjectOrder]]=$key;
$subjectOrder++;
}
$zlSubjectIds=array(); //考试科目
if($exam_group_data) {
$zl_subject_ids=$exam_group_data[0]['zl_subject_ids'];
$zlSubjectIds=explode(',',$zl_subject_ids);
}
$insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`,`exam_type`) values";
$valuesArray=array();
foreach ($sheetData as $val){
if(!isset($val['A']) || !isset($val['B']) ){
continue;
}
$topic_score= array_merge(array(),array_slice($val,2));
foreach ($topic_score as $k=>$v){
if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
Yii::app()->jump->error('分数必须是数值类型且》=0');
}
//验证科目
if(isset($v) && !empty($zlSubjectIds) && in_array($subjectExcel[$k],$zlSubjectIds)){
unset($zlSubjectIds[array_search($subjectExcel[$k],$zlSubjectIds)]);
}
}
$valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($topic_score)."','".$exam_group_id."','student_name','0',1)";
}
if(!empty($zlSubjectIds)){
$errSubjects=array();
foreach ($zlSubjectIds as $subjectId){
$errSubjects[]=Yii::app()->params['subjectId'][$subjectId];
}
Yii::app()->jump->error('分数设置不正确,科目:【'.implode(',',$errSubjects).'】没有提交分数');
}
if($valuesArray){
//$delSql="truncate table import_score_temp;";
$delSql="delete from import_score_temp where exam_type=1;";
$this->sConn->createCommand($delSql)->execute();
$insertSql.=implode(',',$valuesArray);
$this->sConn->createCommand($insertSql)->execute();
$this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
}else{
Yii::app()->jump->error('没有发现学生成绩数据');
}
Yii::app()->jump->error('导入失败');
}
}
//导入数据检测页
public function actionCheck_Excel(){
$sql="select * from import_score_temp where exam_type=1 limit 1";
$data=$this->sConn->createCommand($sql)->queryRow();
$data['check_field_name']='学生姓名';
$data['need_check_name']=1;
$this->render('check',$data);
}
//检测格式
public function actionCheck_field_first(){
$result['status']=0;
$sql="select * from import_score_temp where exam_type=1";
$All_Data=$this->sConn->createCommand($sql)->queryAll();
if(!$All_Data){
exit(json_encode($result));
}
$data=$All_Data[0];
$check_field=$data['check_field'];
$score_data=json_decode($data['score_data'],true);
$exam_group_id=$data['exam_group_id'];
if(!$score_data){
$result['msg']='数据不完整';
exit(json_encode($result));
}
//检测题量
$ZlExam=new ZlExam();
$exam_group_data = $ZlExam->getExamByExamGroupId($data['exam_group_id']);
//debug($exam_group_data);
$total_score=0;
//表格科目对应
$letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM');
$allSubject=Yii::app()->params['subjectId'];
unset($allSubject[3]);
unset($allSubject[51]);
unset($allSubject[20]);
$subjectExcel=array();
$subjectOrder=0;
foreach ($allSubject as $key =>$val){
$subjectExcel[$letters[$subjectOrder]]=$key;
$subjectOrder++;
}
if($exam_group_data) {
$tpl_data=json_decode($exam_group_data[0]['zl_tpl_data'],true);
if(!$tpl_data) {
$result['msg']='考试数据错误';
exit(json_encode($result));
}
$subjectScores=$tpl_data['items'];
//检测试题数据
foreach($All_Data as $key=> $val){
$topic_score=json_decode($val['score_data'],true);
$uploadSubjectCount=0;
foreach($topic_score as $order => $v){
if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
$result['msg']='试题分数必须是数值类型:'.$val['student_name'];
exit(json_encode($result));
}
if(isset($v)==true){
$uploadSubjectCount++;
if(isset($subjectExcel[$order])){
if(isset($subjectScores[$subjectExcel[$order]])){
if($v>$subjectScores[$subjectExcel[$order]]){
$result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$subjectScores[$subjectExcel[$order]];
exit(json_encode($result));
}
}else{
$result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'考试设置中未设置';
exit(json_encode($result));
}
}else{
$result['msg']='Excel格式不正确';
exit(json_encode($result));
}
}
}
/*
if($uploadSubjectCount!=count($subjectScores)){
$result['msg']='上传科目数量和考试设置不一致';
exit(json_encode($result));
}
*/
}
$result['msg']='检测完成';
$result['status']=1;
}else{
$result['msg']='未发现对应考试';
exit(json_encode($result));
}
exit(json_encode($result));
}
//重新上传
public function actionGiveup(){
// $delSql="truncate table import_score_temp;";
$delSql="delete from import_score_temp where exam_type=1;";
$this->sConn->createCommand($delSql)->execute();
$result['status']=1;
exit(json_encode($result));
}
//检测姓名
public function actionCheck_student_name(){
ini_set('memory_limit','512M');
set_time_limit(0);
$result['status']=0;
$result['data']=0;
$student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=1")->queryAll();
if($student_all_data){
//去除非中文字符
$updateArr=array();
$preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
$count=0;
foreach($student_all_data as $val){
if(preg_match($preg,$val['student_name'])){
$ModifyName = preg_replace($preg, "", $val['student_name']);
if($ModifyName){
$updateArr[$val['id']]=$ModifyName;
$count++;
}
}else{
$updateArr[$val['id']]=$val['student_name'];
}
}
//组织更新语句
if($updateArr){
$arrNumber=ceil(count($updateArr)/500);
$Arr=array_chunk($updateArr,$arrNumber,true);
$transcation = $this->sConn->beginTransaction();
try {
foreach ($Arr as $item){
$sql='update import_score_temp set `check_field_value`= case id ';
foreach ($item as $key=> $val){
$sql.=" WHEN ".$key." THEN '".$val."' ";
}
$sql.=" End ";
$sql.=" where check_field_value='' or check_field_value is null and exam_type=1";
$this->sConn->createCommand($sql)->execute();
}
$transcation->commit();
$result['status']=1;
}catch (Exception $e){
$transcation->rollback();
}
}
$result['count']=$count;
}
exit(json_encode($result));
}
//匹配信息
public function actionMatching(){
$noExistent=0; //不存在
$repeat=0; //重复(组)
$success=0; //匹配成功
$scoreWrong=0; //成绩不正确
$result['status']=0;
$sql="select * from import_score_temp where exam_type=1 limit 1";
$data=$this->sConn->createCommand($sql)->queryRow();
if(!$data){
exit(json_encode($result));
}
$check_field=$data['check_field'];
$exam_group_id=$data['exam_group_id'];
$classArr=array();
$classIds=array();
$check_data_group=array(); //检查字段对应临时表id
$update_temp_data=array(); //更新临时表数据
$student_card=array(); //学生id,准考证号对应数据
$tpl_data=array();
$updateSql=array();
$ZlExam=new ZlExam();
$exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id);
$paperIds=array();
if($exam_group_data){
foreach ($exam_group_data as $v){
if(!$tpl_data && isset($v['zl_tpl_data'])){
$tpl_data=json_decode($v['zl_tpl_data'],true);
}
$classIds[]=$v['zl_class_id'];
$examIds[]=$v['zl_exam_id'];
}
}
//统计已经匹配成功的数据
$success_student_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is not null and student_id<>0 and exam_type=1")->queryAll();
if($success_student_data){
$success=count($success_student_data);
}
$check_field_val_arr=array();
$student_all_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is null or student_id=0 and exam_type=1 ")->queryAll();
if(!$student_all_data){
$result['repeat']=0;
$result['success']=$success;
$result['noExistent']=0;
$result['status']=1;
exit(json_encode($result));
}
foreach ($student_all_data as $val){
//验证学生分数
$check_field_val_arr[]="'".$val['check_field_value']."'";
$check_data_group[$val['check_field_value']]=$val['id'];
}
//处理重复数据
$repeat_group_data=array();
$search_value_arr=array();
foreach ($check_field_val_arr as $value){
$repeat_group_data[$value][]=$value;
}
foreach ($repeat_group_data as $key=>$val){
if(count($val)>1){
$repeat++;
$modify_name=str_replace("'",'',$key);
$updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$modify_name."' and (student_id is null or student_id=0) and exam_type=1";
}else{
$search_value_arr[]=$val[0];
}
}
if($search_value_arr){
$student_info=array();
$sql="select si.student_id,si.realname from student_info si join zl_student_exam_relation spr on si.student_id = spr.zl_student_id where realname in(".implode(',',$search_value_arr).") and zl_exam_id in(".implode(',',$examIds).")";
$student_info=$this->sConn->createCommand($sql)->queryAll();
if(!$student_info){
$noExistent=count($search_value_arr);
$result['repeat']=$repeat;
$result['success']=$success;
$result['noExistent']=$noExistent;
$result['status']=1;
}else{
$result['status']=1;
//过滤掉已被删除的学生
foreach ($student_info as $key=>$value){
$sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
$student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
if(!$student_class_realtion){
unset($student_info[$key]);
}
}
$nameArr=array();
foreach ($student_info as $item){
$preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
$ModifyName = preg_replace($preg, "", $item['realname']);
$nameArr[$ModifyName][]=$item;
}
$noExistent=count($search_value_arr)-count($nameArr);
if($noExistent<0) $noExistent=0;
$result['noExistent']=$noExistent;
foreach ($nameArr as $key=>$value){
if(count($value)>1){
$repeat++;
$updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."' and (student_id is null or student_id=0) and exam_type=1";
}else{
$success++;
if(isset($check_data_group[$key])){
$update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
}
}
}
$result['repeat']=$repeat;
$result['success']=$success;
}
}else{
$result['repeat']=$repeat;
$result['success']=$success;
$result['noExistent']=0;
$result['status']=1;
}
//更新检测成功的数据
if($update_temp_data || $updateSql){
$transcation = $this->sConn->beginTransaction();
try {
if($update_temp_data) {
if ($check_field == 'student_name') {
$sql = 'update import_score_temp set `student_id`= case id ';
} else {
$sql = 'update import_score_temp set `student_id`= case id ';
}
foreach ($update_temp_data as $key => $val) {
$sql .= " WHEN " . $key . " THEN '" . $val . "' ";
}
$sql .= " End ";
$sql .= " where (student_id='' or student_id is null) and exam_type=1";
$this->sConn->createCommand($sql)->execute();
}
if($updateSql){
foreach ($updateSql as $query){
$this->sConn->createCommand($query)->execute();
}
}
$transcation->commit();
$result['status']=1;
}catch (Exception $e){
$result['status']=0;
$transcation->rollback();
}
}
exit(json_encode($result));
}
//处理重复学生
public function actionHandle_repeat(){
$page=Req::post('page');
$name_like=Req::post('name');
if(!$page) $page=1;
$pageSize=10;
$offset=($page-1)*$pageSize;
$sql="select * from import_score_temp where exam_type=1 limit 1";
$checkData=$this->sConn->createCommand($sql)->queryRow();
$check_field=$checkData['check_field'];
$sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=1 group by check_field_value ";
if($name_like){
$sql.=" having check_field_value='".$name_like."'";
}
$sql.="order by count desc";
$all_data=$this->sConn->createCommand($sql)->queryAll();
if(!$all_data){
$this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
}
$repeat=array();
$total=count($all_data);
$data['total_page']=ceil($total/$pageSize);
$data['name_group']=array_slice($all_data,$offset,$pageSize);
$data['page']=$page;
if(Yii::app()->request->isAjaxRequest){
$result['status']=1;
$result['data']=$data['name_group'];
$result['total_page']=$data['total_page'];
exit(json_encode($result));
}else{
$this->render('handle', $data);
}
}
//根据名称加载重名学生
public function actionShowrepeatstudent(){
$name=Req::post('name');
$fileName=array(
'student_name'=>'学生姓名',
'userno'=>'学号',
'student_card'=>'准考证号',
'school_student_card'=>'学校准考证号',
'zhixue_student_card'=>'智学网考证号',
'id_number'=>'身份证号',
'student_phone'=>'手机号'
);
//扩展字段
$studentExtend=$this->schoolManager->getStudentExtend();
if($studentExtend){
foreach ($studentExtend as $key=> $value){
$fileName[$key]=$value['field_mean'];
}
}
//表格科目对应
$letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM');
$allSubject=Yii::app()->params['subjectId'];
unset($allSubject[3]);
unset($allSubject[51]);
unset($allSubject[20]);
$ExcelToSubject=array();
$subjectOrder=0;
foreach ($allSubject as $key =>$val){
$ExcelToSubject[$letters[$subjectOrder]]=$key;
$subjectOrder++;
}
$classIds=array();
$sql="select * from import_score_temp where check_field_value='".$name."' and ( student_id is null or student_id =0) and exam_type=1";
$nameArr=array();
$systemStudent=array();
$numberToId=array();
$excel_data = $this->sConn->createCommand($sql)->queryAll();
if($excel_data){
$topic_score=json_decode($excel_data[0]['score_data'],true);
$check_field=$excel_data[0]['check_field'];
$excel_html='
序号 | '; $excel_html.='姓名 | '; $excel_html.='班级 | '; // $scoreArr=array_slice($topic_score,2); foreach($topic_score as $f=>$v){ $excel_html.=''.Yii::app()->params['subjectId'][$ExcelToSubject[$f]].' | '; } $excel_html.='
---|---|---|---|
'.$i.' | '; $excel_html.=''.$val['check_field_value'].'(原'.$val['student_name'].') | '; $excel_html.=''.$val['class_name'].' | '; foreach($topic_score as $v){ $excel_html.=''.$v.' | '; } $excel_html.='