1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243 |
- <?php
- /**
- * Created by 上海互教教育科技有限公司.
- * User: li
- * Date: 2018/5/16 0016
- * Time: 下午 15:29
- */
- class CyletController extends Controller
- {
- /*统考列表*/
- public function actionIndex(){
- Url::clean();
- $printType = Req::get("type");
- $Grade=intval(Req::get('grade'));
- $Class=Req::get('classId');
- $Page=intval(Req::get('page'));
- $Display=intval(Req::get('display'));
- $arts_science=intval(Req::get('arts_science'));
- $cylet_type=intval(Req::get('cylet_type'));
- $coach_id = $this->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]='<span class="c-red">'.$val.'</span>';
- }
- }
- if($Select_Class_Name){
- $Select_Class_Name=array_unique($Select_Class_Name);
- foreach ($Select_Class_Name as $key=>$val){
- $Select_Class_Name[$key]='<span class="c-red">'.$val.'</span>';
- }
- }
- $html=' <i class="icon icon-close"></i><div class="class-modal-head">'.$CyletInfo['title'].'</div>';
- $html.='<div class="class-modal-body">';
- foreach ($result as $subject=>$class){
- $html.='<div class="classes">';
- $html.='<label for="" class="subject-name">';
- if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
- $html.=Yii::app()->params['subjectId'][$subject];
- }
- $html.='</label>';
- $html.='<div>';
- foreach ($class as $val){
- if($val['isComplete']==1){
- $html.='<a href="#" >'.$val['className'].'</a>';
- }else{
- $html.='<a href="#" class="active">'.$val['className'].'</a>';
- }
- }
- $html.='</div>';
- $html.='</div>';
- }
- $html.='</div>';
- $html.='</div>';
- $html.='<p class="c-gray" style="font-size: 14px">';
- if($Select_Class_Name){
- $html.='<span class="c-red">*</span>此次参加统考分析的班级有 ';
- $html.=implode(',',$Select_Class_Name).'已生成报告。';
- }
- if($another_Class_Name){
- $html.=implode(',',$another_Class_Name).'部分科目未出成绩无报告';
- }
- $html.='</p>';
- $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('zsyte-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'].'/teacher/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'].'/teacher/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);
- }
- }
|