coachId; $semester_id = $this->semesterId; $PageLimit=9; if(!$Page) $Page=1; $CyletModel=new Cylet(); $result=$CyletModel->getList($Grade,$Class,$semester_id,$Page,$PageLimit,$Display,$arts_science,$cylet_type); if($result['data']){ $ExamModel=new SExam(); foreach($result['data'] as $key=>$val){ $SubjectArr=array(); $SubjectName=array(); $val['subject_ids'] && $SubjectArr=explode(',',$val['subject_ids']); $classArr=explode(',',$val['class_ids']); $result['data'][$key]['classCount']=count($classArr); $result['data'][$key]['classComplete']=0; foreach ($SubjectArr as $v){ if(isset(Yii::app()->params['subjectId'][$v])){ $SubjectName[]=Yii::app()->params['subjectId'][$v]; } } $result['data'][$key]['SubjectName']=array_unique($SubjectName); $result['data'][$key]['SubjectCount']=count(array_unique($SubjectName)); //判断成绩生成情况 $Complete=0; $downloadBtn=0; //是否可以下载 if($val['examinfo']){ $ExamInfo=json_decode($val['examinfo'],true); $ClassListInfo=$this->ExamClassList($ExamInfo,$classArr); $ClassTemp=array(); foreach ($ClassListInfo as $subject=>$v){ foreach ($v as $cid=>$value){ if(!isset($ClassTemp[$cid])){ $ClassTemp[$cid]=$value['isComplete']; }else{ $ClassTemp[$cid]+=$value['isComplete']; } if($value['isComplete']) $downloadBtn=1; } } foreach ($ClassTemp as $cid=>$item){ if($item==count($SubjectArr)){ $Complete++; } } } $result['data'][$key]['classComplete']=$Complete; $result['data'][$key]['downloadBtn']=$downloadBtn; } } $viewData=array( 'pageTotal' =>$result['pageTotal'], 'dataList' =>$result['data'], 'page' =>$Page, 'grade' =>$Grade, 'class' =>$Class, 'printType' =>$printType, 'display' =>$Display, 'arts_science' =>$arts_science, 'cylet_type' =>$cylet_type, 'totalCount' =>$result['totalCount'], ); $HeadInfo=$this->getHeadInfo(); $viewData=array_merge($viewData,$HeadInfo); $this->render('index',$viewData); } /*班级完成情况*/ public function actionGetClassInfo(){ $Cylet_id=intval(Req::post('cid')); $return=array( 'status'=>0 ); if(!$Cylet_id){ exit(json_encode($return)); } $CyletModel=new Cylet(); $EaxmModel=new SExam(); $CyletInfo=$CyletModel->findById($Cylet_id); if(!$CyletInfo){ $return['msg']='统考ID不正确'; exit(json_encode($return)); } if(!$CyletInfo['examinfo']){ exit(json_encode($return)); } $ExamInfo=json_decode($CyletInfo['examinfo'],true); $classArr=explode(',',$CyletInfo['class_ids']); $SubjectCount=count(explode(',',$CyletInfo['subject_ids'])); $another_Class_Name=array(); $Select_Class_Name=array(); $result=$this->ExamClassList($ExamInfo,$classArr); $Class=array(); foreach ($result as $subject=>$val){ foreach ($val as $cid=>$value){ if(!isset($Class[$cid])){ $Class[$cid]=$value['isComplete']; }else{ $Class[$cid]+=$value['isComplete']; } } } foreach ($Class as $cid=> $item){ $ClassName=ClassModel::model()->getClassName($cid); if($item<$SubjectCount){ $another_Class_Name[]=$ClassName; }else{ $Select_Class_Name[]=$ClassName; } } if($another_Class_Name){ $another_Class_Name=array_unique($another_Class_Name); foreach ($another_Class_Name as $key=>$val){ $another_Class_Name[$key]=''.$val.''; } } if($Select_Class_Name){ $Select_Class_Name=array_unique($Select_Class_Name); foreach ($Select_Class_Name as $key=>$val){ $Select_Class_Name[$key]=''.$val.''; } } $html='
'.$CyletInfo['title'].'
'; $html.='
'; foreach ($result as $subject=>$class){ $html.='
'; $html.=''; $html.='
'; foreach ($class as $val){ if($val['isComplete']==1){ $html.=''.$val['className'].''; }else{ $html.=''.$val['className'].''; } } $html.='
'; $html.='
'; } $html.='
'; $html.=''; $html.='

'; if($Select_Class_Name){ $html.='*此次参加统考分析的班级有 '; $html.=implode(',',$Select_Class_Name).'已生成报告。'; } if($another_Class_Name){ $html.=implode(',',$another_Class_Name).'部分科目未出成绩无报告'; } $html.='

'; $return['status']=1; $return['html']=$html; exit(json_encode($return)); } /*编辑统考信息*/ public function actionEdit(){ $Cylet_id=Req::get('cid'); $viewData=array(); if($Cylet_id){ $CyletModel=new Cylet(); $CyletInfo=$CyletModel->findById($Cylet_id); if(!$CyletInfo){ exit('统考ID不正确'); } if($CyletInfo['examinfo']){ $CyletInfo['examinfo']=json_decode($CyletInfo['examinfo'],true); } if(isset($CyletInfo['teacher_view_limit']) && $CyletInfo['teacher_view_limit']){ $CyletInfo['teacher_view_limit']=explode(',',$CyletInfo['teacher_view_limit']); }else{ $CyletInfo['teacher_view_limit']=array(1,2,3,4,5); } $viewData['formInfo']=$CyletInfo; } if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $viewData['subject']=Yii::app()->params['subjectId']; unset($viewData['subject'][3]); unset($viewData['subject'][51]); if(isset($viewData['subject'][20])) unset($viewData['subject'][20]); } //读取年级分科 $grade = SGrade::model()->findAll(array('order'=>'id asc')); foreach ($grade as $value){ $viewData['grade'][$value['id']]=$value['arts_science']; } $HeadInfo=$this->getHeadInfo(); $viewData=array_merge($viewData,$HeadInfo); $this->render('edit',$viewData); } /*保存统考信息*/ public function actionSave(){ $Title=Req::post('title'); $Grade=Req::post('grade'); $Subject_ids=Req::post('subject_ids'); $Class_ids=Req::post('class_ids'); $Exam_json=htmlspecialchars_decode(Req::post('exam_ids')); //这个字段存的是考试的eaxm_id生成的json $Cylet_id=Req::post('cylet_id'); $create_time=Req::post('examDate'); $cylet_type=Req::post('cylet_type'); $arts_science=Req::post('arts_science'); $push_status=Req::post('push_status'); $exam_mode=Req::post('exam_mode'); $teacher_view_limit=Req::post('teacher_view_limit'); if(!$arts_science){ $arts_science=0; } if(replaceSpecialChar($Title)){ Yii::app()->jump->error('考试名称不能包含特殊字符!'); } //读取年级分科 $gradeAll = SGrade::model()->findAll(array('order'=>'id asc')); $CyletModel=new Cylet(); $examIds=array(); $examInfoArr=json_decode($Exam_json,true); if(isset($examInfoArr['exam'])){ foreach ($examInfoArr['exam'] as $value){ $examIds[]=$value; } } if(isset($examInfoArr['same_exam'])){ foreach ($examInfoArr['same_exam'] as $value){ if(is_array($value)){ $examIds=array_merge($examIds,$value); } } } $Data=array( 'title'=>$Title, 'semester_id'=>$this->semesterId, 'subject_ids'=>$Subject_ids, 'class_ids'=>$Class_ids, 'examinfo'=>$Exam_json, 'exam_ids'=>implode(",",$examIds), 'grade'=>$Grade, 'create_time'=>strtotime($create_time), 'cylet_type'=>$cylet_type, 'push_status'=>$push_status, 'exam_mode'=>$exam_mode, 'teacher_view_limit'=>implode(',',$teacher_view_limit) ); $Data['arts_science']=0; foreach ($gradeAll as $value){ if($value['id']==$Grade && $value['arts_science']==2){ $Data['arts_science']=$arts_science; } } $Data['save_time'] = time(); if($Cylet_id){ $CyletInfo=$CyletModel->findById($Cylet_id); if(!$CyletInfo['push_status'] && $push_status==1){ $arr=array( 'schoolId' => $this->schoolId, 'cyletId' =>$Cylet_id ); $send_json=$arr; sendDataToKafka('zsyte-academic-cylet-achievement-notify',$send_json); unset($stompconn); } $Condition=array('cylet_id'=>$Cylet_id); $CyletModel->updateByCondition($Data,$Condition); }else{ $cyletId=$CyletModel->InsertByData($Data); //发送app推送通知 //学生消息 $studentReceiverList=array(); $studentIds=$this->schoolManager->getCyletStudentByExamIds($examIds,explode(",",$Class_ids)); foreach ($studentIds as $val){ $studentReceiverList[]=$val; } if(count($studentReceiverList)>100){ $chunk_result = array_chunk($studentReceiverList, 50); foreach ($chunk_result as $value){ $studentNotice[]=array( 'app'=>0, 'extraData'=>array( 'semesterId'=>$this->semesterId, 'cyletId'=>$cyletId ), 'templateId'=>5, 'templateParams'=>array($Title), 'userIds'=>$value ); } }else{ $studentNotice[]=array( 'app'=>0, 'extraData'=>array( 'semesterId'=>$this->semesterId, 'cyletId'=>$cyletId ), 'templateId'=>5, 'templateParams'=>array($Title), 'userIds'=>$studentReceiverList ); } $receiverList=array(); $teachers=$this->schoolManager->getTeachersByClassesIds(explode(",",$Class_ids)); foreach ($teachers as $val){ if(!isset($receiverList[(string)$val['teacher_id']])){ $receiverList[(string)$val['teacher_id']]=$val['teacher_id']; } } $receiverList=array_values($receiverList); $teacherNotice=array( 'app'=>1, 'extraData'=>array( 'semesterId'=>$this->semesterId, 'cyletId'=>$cyletId ), 'templateId'=>6, 'templateParams'=>array($Title), 'userIds'=>$receiverList ); foreach ($studentNotice as $msg){ sendAppNotify($msg); } sendAppNotify($teacherNotice); } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "cylet" => $Cylet_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_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $this->redirect('/index.php/cylet/index'); } /*根据科目读取考试列表*/ public function actionGetExamBySubject(){ $Subject_id = Req::post("subject_id"); $Grade = Req::post("grade"); $Cylet_id = Req::post("cylet_id"); $Arts_s = Req::post("arts_s"); $SemesterId = Yii::app()->session['session_semester_id']; $SExamModel = new SExam(); if($Grade){ $Grade=explode(',',$Grade); } if($Cylet_id){ $CyletModel=new Cylet(); $CyletInfo=$CyletModel->findById($Cylet_id); $ExamInfo=json_decode($CyletInfo['examinfo'],true); } $result=array( 'status'=>1 ); if($Subject_id == 12){ $is_all_quan = 0; }else{ $is_all_quan = 0; } if(isset($ExamInfo['exam'][$Subject_id]) && $ExamInfo['exam'][$Subject_id]){ if($Subject_id==6){ $Data=$SExamModel->getExamBySubject_Semester_nogroup($this->mathSubjectId,$SemesterId,$Grade,$Arts_s,$is_all_quan); }else{ $Data=$SExamModel->getExamBySubject_Semester_nogroup($Subject_id,$SemesterId,$Grade,$Arts_s,$is_all_quan); } $Exam=array(); $SelectExam=array(); if($Data){ foreach ($Data as $val){ if(strcmp($val['exam_id'], $ExamInfo['exam'][$Subject_id])==0){ $SelectExam=$val; } $Exam[$val['exam_group_id']]=$val; } if($SelectExam){ $Exam[$SelectExam['exam_group_id']]=$SelectExam; } } $Exam=array_values($Exam); }else{ if($Subject_id==6){ $Exam=$SExamModel->getExamBySubject_Semester($this->mathSubjectId,$SemesterId,$Grade,$Arts_s,$is_all_quan); }else{ $Exam=$SExamModel->getExamBySubject_Semester($Subject_id,$SemesterId,$Grade,$Arts_s,$is_all_quan); } } $result['data']=$Exam; $result['subject_name']=Yii::app()->params['subjectId'][$Subject_id]; exit(json_encode($result)); } /*根据考试读取班级列表*/ public function actionGetClassByExam(){ $exam_id = Req::post("examId"); $grade = Req::post("grade"); $arts_science = intval(Req::post("arts_science")); $semesterId = Yii::app()->session['session_semester_id']; $result = array('status'=>0); $ExamModel = new SExam(); $ExamGroupModel = new SExamGroup(); $ClassArr=array(); //读取examGroupid $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']="考试id不正确"; exit(json_encode($result)); } $isAll=0; //加载所有班级 if($arts_science){ $classList = SClass::model()->findAll("semester_id=:semester_id and grade=:grade and arts_science=:arts_science ",array(':semester_id'=>$semesterId,':arts_science'=>$arts_science,':grade'=>$grade)); }else{ $classList = SClass::model()->findAll("semester_id=:semester_id and grade=:grade ",array(':semester_id'=>$semesterId,':grade'=>$grade)); } $ExamGroupId=$ExamInfo['exam_group_id']; $TotalClass=$ExamModel->getClassByExamGroupId($ExamGroupId,$arts_science); if($TotalClass){ foreach($TotalClass as $val){ $ClassArr[]=$val['class_id']; } } if($ClassArr){ $ClassArr=ClassModel::model()->getClassArrayByIds($ClassArr); } if(count($ClassArr)==count($classList)){ $isAll=1; } $tplData=json_decode($ExamInfo['tpl_data'],true); $return=array( 'status'=>1, 'class'=>$ClassArr, 'create_time'=>$tplData['examDate'], 'is_all'=>$isAll ); exit(json_encode($return)); } /*非数学学科查找相似考试 *匹配规则 :考试日期匹配最近5天,题型,试题分数 * 班级不能重复 */ private function findSamePaperForMostSubject($Exam){ $ExamModel = new SExam(); $SemesterId = Yii::app()->session['session_semester_id']; $resultExam=array(); if(!$Exam){ return null; } $ExamInfo=$Exam; if(!$ExamInfo){ return null; } $nowExamGroupId=$ExamInfo['exam_group_id']; $ClassInfo=ClassModel::model()->findByPk($ExamInfo['class_id']); $Grade=$ClassInfo['grade']; //被匹配的考试所有参加的班级 $ClassArr=array(); $TotalClass=$ExamModel->getClassByExamGroupId($nowExamGroupId); if($TotalClass){ foreach($TotalClass as $val){ $ClassArr[]=$val['class_id']; } } //读取试卷规则 $rules=$this->getRules($ExamInfo['tpl_data']); //读取对应科目5天内考试完成试卷 $StartTime=$ExamInfo['create_time']-86400*5; $allExam=$ExamModel->getExamBySubjectTime($ExamInfo['subject_id'],$SemesterId,$nowExamGroupId,$StartTime,$Grade); if($allExam){ foreach($allExam as $value){ if(!$value){ continue; } $examRule=$this->getRules($value['tpl_data']); if(!$this->checkRule($examRule,$rules)){ continue; } $TempClassArr=array(); //检测班级是否重复 $TempExamClass=$ExamModel->getClassByExamGroupId($value['exam_group_id']); if($TempExamClass){ foreach($TempExamClass as $val){ $TempClassArr[]=$val['class_id']; } } if(!$TempClassArr || array_intersect($TempClassArr,$ClassArr)){ continue; } $resultExam[]=$value; } } return $resultExam; } private function getRules($jsonStr){ $rules=array(); $tpl_data=json_decode($jsonStr,true); if(isset($tpl_data['new_items'])){ foreach($tpl_data['new_items'] as $key=>$val){ $rules[$val['topic_type']][]=$val['score']; } }elseif(isset($tpl_data['items'])){ foreach($tpl_data['items'] as $key=>$val){ $rules[$key]=$val['perScores']; } } return $rules; } //对比两个试卷规则 private function checkRule($rule1,$rule2){ //题型 if(count($rule1)!=count($rule2)){ return false; } foreach($rule1 as $topic_type=>$val){ if(count($val)!=count($rule2[$topic_type])){ return false; } if(array_sum($val)!=array_sum($rule2[$topic_type])){ return false; } } return true; } //处理统考班级考试完成情况 private function ExamClassList($ExamInfo,$classArr){ $EaxmModel=new SExam(); $result=array(); foreach($ExamInfo['exam'] as $subject =>$exam){ if(!isset($ExamInfo['same_exam'][$subject]) || empty($ExamInfo['same_exam'][$subject])){ $TempExamInfo=$EaxmModel->getDetailByExamId($exam); foreach($classArr as $cid){ $ExamClass=$EaxmModel->getForExamGroupId_ClassId($TempExamInfo['exam_group_id'],$cid); if($ExamClass){ if($ExamClass['status']==1){ $result[$subject][$cid]=array( 'className'=>$ExamClass['class_name'], 'isComplete'=>1, 'exam_id'=>$ExamClass['exam_id'] ); }else{ $result[$subject][$cid]=array( 'className'=>$ExamClass['class_name'], 'isComplete'=>0, 'exam_id'=>$ExamClass['exam_id'] ); } } } }else{ //有匹配试卷 $tempClassArr=$classArr; $TempExamInfo=$EaxmModel->getDetailByExamId($exam); $ThisAllExam=$EaxmModel->getExamByGroupId($TempExamInfo['exam_group_id']); if($ThisAllExam){ foreach ($ThisAllExam as $val){ if(in_array((string)$val['class_id'],$tempClassArr,true) && $val['status']!=1){ $Class_Name_Temp=ClassModel::model()->getClassName($val['class_id']); $result[$subject][$val['class_id']]=array( 'className'=>$Class_Name_Temp, 'isComplete'=>0, 'exam_id'=>$val['exam_id'] ); unset($tempClassArr[array_search((string)$val['class_id'],$tempClassArr,true)]); break; } } } //查询匹配考试班级完成情况 foreach($ExamInfo['same_exam'][$subject] as $value){ if(!$tempClassArr){ break; } $TempExamInfo=$EaxmModel->getDetailByExamId($value); $ThisAllExam=$EaxmModel->getExamByGroupId($TempExamInfo['exam_group_id']); if($ThisAllExam){ foreach ($ThisAllExam as $val){ if(in_array((string)$val['class_id'],$classArr,true) && $val['status']!=1){ $Class_Name_Temp=ClassModel::model()->getClassName($val['class_id']); $result[$subject][$val['class_id']]=array( 'className'=>$Class_Name_Temp, 'isComplete'=>0, 'exam_id'=>$value ); unset($tempClassArr[array_search((string)$val['class_id'],$tempClassArr,true)]); break; } } } } if($tempClassArr){ foreach ($tempClassArr as $cid){ $ClassName=ClassModel::model()->getClassName($cid); $result[$subject][$cid]=array( 'className'=>$ClassName, 'isComplete'=>1 ); } } } } return $result; } /*匹配试卷*/ public function actionFindSamePaper(){ $exam_id = Req::post("examId"); $ExamModel = new SExam(); $SemesterId = Yii::app()->session['session_semester_id']; $result=array( 'status'=>0 ); $SameExam=array(); $SameExamId=array(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ exit(json_encode($result)); } $Exam_Subject=$ExamInfo['subject_id']; if(in_array($Exam_Subject,$this->mathSubjectId)){ $ClassInfo=ClassModel::model()->findByPk($ExamInfo['class_id']); $Grade=$ClassInfo['grade']; //数学 $nowExamGroupId=$ExamInfo['exam_group_id']; $PaperInfo=SPaper::model()->getPapersByExamId($exam_id); if(!$PaperInfo){ exit(json_encode($result)); } //参加的班级 $ClassArr=array(); $TotalClass=$ExamModel->getClassByExamGroupId($nowExamGroupId); if($TotalClass){ foreach($TotalClass as $val){ $ClassArr[]=$val['class_id']; } } //根据试卷信息查找相同试卷的同期考试 $paperId=$PaperInfo[0]['paper_id']; $Topics=array(); $TopicInfo=array(); $paperRelation=SPaperTopicRelation::model()->getRelationsByPaperId2($paperId); if($paperRelation){ foreach ($paperRelation as $val){ $Topics[]= $val['topic_id']; $TopicInfo[$val['topic_id']]['topic_id']=$val['topic_id']; $TopicInfo[$val['topic_id']]['order']=$val['order']; //排序 $TopicInfo[$val['topic_id']]['score']=$val['score']; //分数 } } $samePaper=array(); if($Topics){ $AllPaperTopic=SPaperTopicRelation::model()->getPaperByTopicIds($Topics,$SemesterId,$nowExamGroupId,$Grade); if($AllPaperTopic){ $Paper_Topic=array(); foreach($AllPaperTopic as $val){ $Paper_Topic[$val['paper_id']][]=$val['topic_id']; } if($Paper_Topic){ foreach ($Paper_Topic as $key=>$val){ $tempTopics=array_unique($val); $isTrue=true; if(count($tempTopics)!=count($Topics)){ continue; } $TempPaperRelation=SPaperTopicRelation::model()->getRelationsByPaperId2($key); if($TempPaperRelation){ foreach ($TempPaperRelation as $v){ if(!isset($TopicInfo[$v['topic_id']]) || $TopicInfo[$v['topic_id']]['order']!=$v['order'] || $TopicInfo[$v['topic_id']]['score']!=$v['score']){ $isTrue=false; break; } } } if($isTrue){ $samePaper[]=$key; } } } } //读取考试id if($samePaper){ foreach($samePaper as $pid){ //读取考试id,排除相同班级 $Exam=$ExamModel->getExamByPaperExcludeClass($pid,$ClassArr); if($Exam){ $TempClassArr=array(); //检测班级是否重复 $TempExamClass=$ExamModel->getClassByExamGroupId($Exam['exam_group_id']); if($TempExamClass){ foreach($TempExamClass as $val){ $TempClassArr[]=$val['class_id']; } } if(!$TempClassArr || array_intersect($TempClassArr,$ClassArr)){ continue; } $SameExam[]=$Exam; } } } } }else{ //非数学学科 $SameExam= $this->findSamePaperForMostSubject($ExamInfo); } if($SameExam){ foreach ($SameExam as $key=>$val){ if(empty($val) || !isset($val['name'])){ unset($SameExam[$key]); } } } if($SameExam){ $SameExam=array_values($SameExam); $result['status']=1; } $result['data']=$SameExam; exit(json_encode($result)); } /*根据年级读取班级*/ public function actionGetClassByGrade(){ $grade=Req::post('grade'); $semester=$this->semesterId; $class=ClassModel::model()->getClassBySemesternianji($semester,$grade); $result=array( 'status'=>1 ); $data=array(); if($class){ foreach($class as $val){ $data[]=array( 'class_id'=>$val->class_id, 'class_name'=>$val->class_name, ); } } $result['data']=$data; exit(json_encode($result)); } /*切换统考记录状态*/ public function actionChangeStatus(){ $display=intval(Req::post('display')); $cylet_id=intval(Req::post('cid')); $result=array( 'status'=>0 ); if(!$cylet_id || !in_array($display,array(0,1))){ exit(json_encode($result)); } $CyletModel=new Cylet(); $data=array( 'is_display'=>$display ); $Condition=array( 'cylet_id'=>$cylet_id ); $res=$CyletModel->updateByCondition($data,$Condition); if($res){ $result['status']=1; } exit(json_encode($result)); } public function actionCheckTime(){ $Time=Req::post('create_time'); $cylet_id=Req::post('cylet_id'); $grade=Req::post('grade'); $arts_s=Req::post('arts_s'); $result=array('status'=>0); if(!$Time){ $result['msg']='时间格式不正确'; exit(json_encode($result)); } $CyletModel=new Cylet(); $create_time=strtotime(date('Y-m-d',$Time)); $data=$CyletModel->getByTime($create_time,$grade,$arts_s); if($data){ if($data['cylet_id']==$cylet_id){ $result=array('status'=>1,'msg'=>'统考时间可以使用'); }else{ $result=array('status'=>0,'msg'=>'已有相同时间统考'); } }else{ $result=array('status'=>1,'msg'=>'统考时间可以使用'); } exit(json_encode($result)); } public function actionDownload(){ $cylet_id=Req::post('cylet_id'); $postData=array( 'cyletId'=>$cylet_id, 'hasStudentNo'=>1, 'hasStudentSchoolCard'=>1, 'hasStudentSystemCard'=>1 ); $url = Yii::app()->params['zsy_api_url'].'/teacher/academic/download/all/subject/'.$this->schoolInfo->school_id; $username = $this->schoolInfo->school_id; $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $rs = $this->CrmApiPost($url,$postData,$username,$password); if(isset($rs->errCode) && $rs->errCode =='00') { echo json_encode(array('status'=>1,'result'=>$rs->data));exit; } $errMsg = '下载失败'; if(isset($rs->errMsg)) { $errMsg = $rs->errMsg; } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "cylet" => $cylet_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_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>0,'result'=>$errMsg));exit; } public function CrmApiPost($url, $arr, $username,$password,$method='POST') { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); if($method=='POST'){ // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), )); }else{ // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); } curl_setopt($ch, CURLOPT_TIMEOUT,30); if( !curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); } return $result; } /*头部菜单信息*/ private function getHeadInfo(){ $coach_id = $this->coachId; $semester_id = $this->semesterId; $criteria = new CDbCriteria(); if(Yii::app()->session['session_duoxueke_subject_id']==3) { $criteria->addInCondition('subjects',$this->mathSubjectId); }else { $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']); } $criteria->addCondition('status = 0'); $teacher_data = Teacher::model()->findAll($criteria); $teacher_arr = array(); if($teacher_data){ $i = 0; foreach($teacher_data as $v){ $teacher_arr[$i]['teacher_id'] = $v->teacher_id; $teacher_arr[$i]['teacher_name'] = $v->teacher_name; $i++; } } $data['teacher_arr'] = $teacher_arr; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } return $data; } function jsonEncode($arr) { $jsonSupport = version_compare(PHP_VERSION, '5.4', '>='); if ($jsonSupport) { $result = json_encode($arr, JSON_UNESCAPED_UNICODE); } else { $result = json_encode($arr); $result = preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $result); // $result = preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $result); } return $result; } public function actionLoadCyletInfo(){ $cylet_id=intval(Req::post('cylet_id')); if(!$cylet_id){ echo json_encode(array('status'=>0,'result'=>'统考ID不正确'));exit; } $CyletModel=new Cylet(); $CyletInfo=$CyletModel->findById($cylet_id); if(!$CyletInfo){ echo json_encode(array('status'=>0,'result'=>'统考ID不正确'));exit; } $subjectIds=explode(',',$CyletInfo['subject_ids']); $isHasEnglish=0; if(in_array(8,$subjectIds)){ $isHasEnglish=1; } $waiData = array(); $waiDefaultSubjectIds = array(8,21,22,23,24,25,26,31);//默认外语学科 if(array_intersect($waiDefaultSubjectIds,$subjectIds)){ $waiSubjectIds = array_intersect($waiDefaultSubjectIds,$subjectIds); $sql = "select subject_id,subject_name from subject where subject_id in (".implode(",",$waiSubjectIds).")"; $subject_info = $this->conn->createCommand($sql)->queryAll(); if($subject_info){ foreach($subject_info as $k=>$v){ $waiData[] = array("subject_id"=>$v['subject_id'],"subject_name"=>$v['subject_name']); } } } if(in_array(array(8,21,22,23,24,25,26,31),$subjectIds)){ $sql = "select subject_id,subject_name from subject where subject_id = '{$sub_name}'"; $subject_info = $this->conn->createCommand($sql)->queryRow(); } $classIds=explode(',',$CyletInfo['class_ids']); $class=ClassModel::model()->getClassArrayByIds($classIds); $ScoreSection=array(); $CountSection=array(); $rs=$this->getSection($cylet_id); //debug($rs); $studentNumber=1; if($rs){ $ScoreSection=$rs['ScoreSection']; $CountSection=$rs['CountSection']; if(isset($ScoreSection[0])){ $TotalScore=$ScoreSection[0]; unset($ScoreSection[0]); } if(isset($ScoreSection[10])){ unset($ScoreSection[10]); } if(isset($CountSection[0])){ unset($CountSection[0]); } if(isset($CountSection[10])){ $studentNumber=$CountSection[10]; unset($CountSection[10]); } $ScoreSection=array_values($ScoreSection); $CountSection=array_reverse(array_values($CountSection)); } $resultData=array( 'score'=>$TotalScore, 'student_count'=>$studentNumber, 'class'=>$class, 'score_section'=>$ScoreSection, 'count_section'=>$CountSection, 'score_report'=>$CyletInfo['generate_new_exam_score_report_status'], 'is_has_english'=>$isHasEnglish, 'waiData'=>$waiData ); exit(json_encode($resultData)); } public function actionDownloadTable(){ $reportTypeList=Req::post('table'); $clazzIdList=Req::post('classlist'); $ratio=Req::post('ratio'); //英语系数值 $ratioSwitch=Req::post('ratio_switch'); //英语系数是否开启 $subjectIds=Req::post('subject_id'); //外语学科 $hasStudentNo=(int)Req::post('hasStudentNo'); //学号 $hasStudentSystemCard=(int)Req::post('hasStudentSystemCard'); //系统准考证 $hasStudentSchoolCard=(int)Req::post('hasStudentSchoolCard'); //学校准考证 $hasIdNumber=(int)Req::post('hasIdNumber'); //身份证 $subjectCoefficients = array(); if($ratio && $subjectIds && count($ratio) == count($subjectIds)){ foreach($subjectIds as $k=>$v){ $key='decimal'.$v; $totalScoreCoefficientIsRounding=Req::post($key); $subjectCoefficients[] = array("subjectId"=>$v,"coefficient"=>$ratio[$k],'totalScoreCoefficientIsRounding'=>$totalScoreCoefficientIsRounding); } } $scoreSectionList=array(); for($i=0;$i<10;$i++){ $inputName='score_'.$i; if(Req::post($inputName)){ $scoreSectionList[]=Req::post('score_'.$i); } } $scoreSectionList[]='0'; $rankSectionList=array(); for($i=10;$i>=0;$i--){ $rankSectionList[]=Req::post('count_'.$i); } $cyletId=Req::post('cylet_id'); $isNative=Req::post('isNative'); $param=array(); $param['clazzIdList']=$clazzIdList; $param['cyletId']=$cyletId; $param['rankSectionList']=$rankSectionList; $param['reportTypeList']=$reportTypeList; $param['scoreSectionList']=$scoreSectionList; $param['removeZeroStudent']=Req::post('removeZeroStudent'); $param['clazzAnalysisMode']=Req::post('clazzAnalysisMode'); if($isNative){ $param['isNative']=1; }else{ $param['isNative']=0; } if($ratioSwitch){ // $param['englishCoefficient']=$ratio; } $param['schoolId']=$this->schoolId; if($subjectCoefficients){ $param['subjectCoefficients']=$subjectCoefficients; } $param['hasStudentNo'] = $hasStudentNo; $param['hasStudentSystemCard'] = $hasStudentSystemCard; $param['hasStudentSchoolCard'] = $hasStudentSchoolCard; $param['hasIdNumber'] = $hasIdNumber; //发送消息 sendDataToKafka('xbkc-hm-download-cylet-report',$param); echo json_encode(array('status'=>1));exit; // $url = Yii::app()->params['zsy_api_url'].'/teacher/hm/report/download/exam/group/analysis/report'; // $username = $this->schoolInfo->school_id; // $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); // // $rs = $this->CrmApiPost($url,$param,$username,$password); // if(isset($rs->errCode) && $rs->errCode =='00') // { // echo json_encode(array('status'=>1,'result'=>$rs->data));exit; // } // $errMsg = '下载失败'; // if(isset($rs->errMsg)) // { // $errMsg = $rs->errMsg; // } // echo json_encode(array('status'=>0,'result'=>$errMsg));exit; } private function getSection($cylet_id){ $param=array(); $username = $this->schoolInfo->school_id; $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/exam/group/rank/section/'.$cylet_id; $rs = $this->CrmApiPost($url,$param,$username,$password,'GET'); $CountSection=array(); //排名分段 if(isset($rs->errCode) && $rs->errCode =='00') { $CountSection=$rs->data; } $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/exam/group/score/section/'.$cylet_id; $rs = $this->CrmApiPost($url,$param,$username,$password,'GET'); $ScoreSection=array(); //总分分段 if(isset($rs->errCode) && $rs->errCode =='00') { $ScoreSection=$rs->data; } return array('CountSection'=>$CountSection,'ScoreSection'=>$ScoreSection); } }