request->getQuery('realname1')); //$getStatus = safe_replace(Yii::app()->request->getQuery('status')); // $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id')); // $class_id = safe_replace(Yii::app()->request->getQuery('class_id')); /** * 需求变动 * 重新开发 * */ if (empty($printType)) { $printType = '2'; $printTypeData = 0; } else { switch ($printType) { case "2": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; default: $printTypeData = null; break; } } $condition = array(); if($is_print > -1) { $condition[] = "cep.is_print = '{$is_print}'"; }else{ $is_print = -1; } if($printName) $condition[] = "e.name like '%{$printName}%'"; if (!Str::isBlank($labelled)) { $condition[] = " (p.is_labelled = '{$labelled}' or eg.is_tagging='{$labelled}')"; } if ( empty($display)) { $condition[] = "e.is_display = 0"; }else { $condition[] = "e.is_display = ".$display; } // $condition[] = "e.subject_id = '{$this->subjectId}'"; $condition[] = "eg.is_third = 1"; $condition[] = "eg.xb_homework = 0"; if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "e.subject_id = ".Yii::app()->session['session_duoxueke_subject_id']; } if($list_type){ $condition[] = "eg.import_score_type = 2"; //传了参数,只读线下导入考试 }else{ $condition[] = "eg.import_score_type <>2 "; //没传参数,读其它所有阅卷类型 } $gradeCardLength=array(); $gradeData=SGrade::model()->findAll(); foreach ($gradeData as $datum){ if($datum->card_status==1){ $gradeCardLength[$datum->id]=$datum->card_length; }else{ $gradeCardLength[$datum->id]=0; } } $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc')); $printList = array(); if($resultList["rs"]){ $ExamModel=new Exam(); $StudentPaperRelation=new SStudentPaperRelation(); foreach ($resultList['rs'] as $k=>$v) { $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id']; $time = time(); $classinfo=ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$v['class_id'])); $v['grade']=$classinfo['grade']; //解析状态 $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$v['exam_group_id'])); $v['tw_status']=$topicWord['status']; $v['wrong_reason']=$topicWord['wrong_reason']; $v['word_path']=$topicWord['word_path']; $v['allsubject_file_path']=$topicWord['allsubject_file_path']; if($topicWord['allsubject_file_path']){ //解析预计完成时间 $v['estimate']=48*3600+$topicWord['upload_time']; } $v['params_id']=$topicWord['params_id']; $v['parse_upload_time']=$topicWord['upload_time']; $printList[$k] = $v; $tplData = json_decode($v["tpl_data"], true); //FIXME 添加班级参数 $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0; $printList[$k]['show_print'] = 0; //准考证 if(!$v['school_card_status']){ $printList[$k]['school_card_length'] = $gradeCardLength[$v['grade']]; } //考试时间 if(isset($tplData['examDate'])) { $examDate = strtotime($tplData["examDate"]); } if(isset($tplData['new_items']) && !isset($tplData['items'])) { $printList[$k]['show_print'] = 1; } //标注期望完成时间 if(isset($tplData['estimateTime'])) { $printList[$k]['estimate_time'] = date('Y-m-d H:i:s',$tplData["estimateTime"]); } if(!isset($tplData["examDate"])) { $examDate = $v["create_time"]; } $printList[$k]['examDate'] = $examDate; if(isset($tplData['totals'])){ $printList[$k]['totals'] = $tplData['totals']; } if(isset($tplData['total_score'])){ $printList[$k]['total_score'] = $tplData['total_score']; } if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){ $printList[$k]['is_change_to_third'] = 1; }else{ $printList[$k]['is_change_to_third'] = 0; } //统计班级,学生 if($list_type){ $exam=$ExamModel->getExamIds($v['exam_group_id']); if($exam){ $studentCount=0; $uploadedCount=0; $studentList=$StudentPaperRelation->getStudentExamInfo($exam); $studentCount=count($studentList); $printList[$k]['class_count']=count($exam).'('.$studentCount.'人)'; foreach ($studentList as $value){ if($value['is_feedback']==1){ $uploadedCount++; } } $printList[$k]['upload_count']=$uploadedCount.'/'.$studentCount; if($uploadedCount>0){ $printList[$k]['upload_status']='已上传成绩'; }else{ $printList[$k]['upload_status']='未上传成绩'; } } }else{ //判断上传状态 $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($v['exam_group_id']); $uploadStatus=0; if($uploadExamInfo){ if(isset($uploadExamInfo[1])){ $printList[$k]['uploadExamTemplateId']=$uploadExamInfo[1]['template_id']; if($uploadExamInfo[1]['topic_upload']==1){ $uploadStatus+=1; } } if(isset($uploadExamInfo[2])){ $printList[$k]['uploadAnswerTemplateId']=$uploadExamInfo[2]['template_id']; if($uploadExamInfo[2]['answer_upload']==1){ $uploadStatus+=3; } } } //判断是否已上传成绩 $printList[$k]['is_feedback']=0; $exam=$ExamModel->getExamIds($v['exam_group_id']); if($exam){ if($StudentPaperRelation->getStudentFeedBack($exam)){ $printList[$k]['is_feedback']=1; } } $printList[$k]['uploadExamStatus']=$uploadStatus; $printList[$k]['uploadExamInfo'] = $uploadExamInfo; } } } $sheet_ids = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_group_id',$exam_group_ids); $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria); if($exam_sheet_data) { foreach($exam_sheet_data as $v) { $exam_sheets[$v->exam_group_id] = $v->online_card; $sheet_ids[$v->sheet_id] = $v->sheet_id; $sheet_rs[$v->exam_group_id] = $v; if($v->online_card){ $onlineMultiplex=$this->schoolManager->getOnlineCardMultiplex($v->multiplex_id); if($onlineMultiplex){ $marking_papers[$v->exam_group_id] = $onlineMultiplex['marking_papers']; } } } } //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1); $subject_exam_data=Yii::app()->params['subjectId']; $teachers_data = Teacher::model()->findAll(); $class_teacher_data = array(); if($teachers_data) { foreach($teachers_data as $k=>$v) { $class_teacher_data[$v->teacher_id] = $v->teacher_name; } } //获取班级年级 $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); $class_grade_arr=array(); if($class_data) { foreach($class_data as $v) { $class_grade_arr[$v->class_id] = $v->grade; } } unset($class_data); $data = array(); //$data = $this->export($getName,$grade_id,$class_id); //判断全学科试用学校 // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi'); // $rs=json_decode($rs,true); // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ // $data['is_qxk']=1; // }else{ // $data['is_qxk']=0; // } $data['is_qxk']=1; $data['printList'] = $printList; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data["printType"] = $printType; $data["printName"] = $printName; $data["teachers"] = $class_teacher_data; $data["classId"] = $classId; $data["grade"] = $grade; $data["sheets"] = $sheets; $data["exam_sheets"] = $exam_sheets; $data["sheet_rs"] = $sheet_rs; $data["labelled"] = $labelled; $data["display"] = $display; $data["is_print"] = $is_print; $data["subject"] = $subject_exam_data; $data['list_type'] =$list_type; $data["class_grade"] = $class_grade_arr; $data['showAssist'] =0; $data['extendSubject'] =$this->extendSubject; $data["marking_papers"] = $marking_papers; //获取导出数据白名单 $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);; //debug($printList); if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } unset($resultList); //获取产品设置版本 $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow(); if(!$productEdition || $productEdition['switch']==2){ $data['productSwitch']=2; }else{ $data['productSwitch']=3; } $data['schoolId'] =$this->schoolId; $data['version_number']=$this->version_number; if($list_type){ $this->render('index_underline',$data); }else{ if(Yii::app()->params['section']==0){ $this->render('index_section',$data); }else{ $this->render('index2',$data); } } } public function actionIndex1(){ Url::clean(); $printName = Req::get("name"); $classId = Req::get("classId"); $printType = Req::get("type"); $grade = Req::get("grade"); $labelled = Req::get("labelled"); $display = Req::get("display"); $is_print = Req::get("is_print"); $exam_group_ids = array(); $sheets = array(); $exam_sheets = array(); $sheet_rs = array(); /** * 需求变动 * 重新开发 * */ if (empty($printType)) { $printType = '2'; $printTypeData = 0; } else { switch ($printType) { case "2": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; default: $printTypeData = null; break; } } $condition = array(); if($is_print > -1) { $condition[] = "cep.is_print = '{$is_print}'"; }else{ $is_print = -1; } if($printName) $condition[] = "e.name like '%{$printName}%'"; if (!Str::isBlank($labelled)) { $condition[] = "p.is_labelled = '{$labelled}'"; } if ( empty($display)) { $condition[] = "e.is_display = 0"; }else { $condition[] = "e.is_display = ".$display; } // $condition[] = "e.subject_id = '{$this->subjectId}'"; $condition[] = "eg.is_third = 1"; $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc')); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id']; $time = time(); $printList[$k] = $v; $tplData = json_decode($v["tpl_data"], true); //FIXME 添加班级参数 $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0; //考试时间 if(isset($tplData['examDate'])) { $examDate = strtotime($tplData["examDate"]); } if(!isset($tplData["examDate"])) { $examDate = $v["create_time"]; } $printList[$k]['examDate'] = $examDate; $expireTime = $examDate + (3600 * 24 * 2); if($time > $expireTime){ $printList[$k]['is_expired'] = true; } } } $sheet_ids = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_group_id',$exam_group_ids); $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria); if($exam_sheet_data) { foreach($exam_sheet_data as $v) { $exam_sheets[$v->exam_group_id] = $v->sheet_id; $sheet_ids[$v->sheet_id] = $v->sheet_id; $sheet_rs[$v->exam_group_id] = $v; } } $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); //获取班级年级 $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); if($class_data) { foreach($class_data as $v) { $class_grade_arr[$v->class_id] = $v->grade; } } unset($class_data); $data = array(); $data['printList'] = $printList; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data["printType"] = $printType; $data["printName"] = $printName; $data["classId"] = $classId; $data["grade"] = $grade; $data["sheets"] = $sheets; $data["exam_sheets"] = $exam_sheets; $data["sheet_rs"] = $sheet_rs; $data["sheet_ids"] = $sheet_ids; $data["labelled"] = $labelled; $data["display"] = $display; $data["is_print"] = $is_print; $data["subject"] = $subject_exam_data; $data["class_grade"] = $class_grade_arr; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } unset($resultList); $this->render('index1',$data); } protected function export($getName,$grade_id,$class_id) { //$getStatus = safe_replace(Yii::app()->request->getQuery('status')); $grade_class_array = array(); $con = array(); // 打印任务处理 $ExamModel = Exam::model(); $ClassModel = ClassModel::model(); $printList = array(); $grade_class_data = ClassModel::model()->findAll('grade=:grade', array(':grade' => $grade_id)); if ($grade_class_data) { foreach ($grade_class_data as $v) { $grade_class_array[$v->class_id] = $v->attributes; } } // 获取当前学期班级并组装 $criteria = new CDbCriteria(); $criteria->addCondition('semester_id=:semester_id'); if ($grade_id) { $con = array('c.grade = ' . $grade_id); $criteria->addCondition('grade=:grade'); $criteria->params[':grade'] = $grade_id; } if ($class_id) { $con = array_merge($con, array('c.class_id = ' . $class_id)); $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $class_id; } if ($getName) { $con = array_merge($con, array("e.name like '%{$getName}%'")); } if (Yii::app()->session['session_duoxueke_subject_id'] == 6 || Yii::app()->session['session_duoxueke_subject_id'] == 3) { $con = array_merge($con, array('e.subject_id in (3,6)')); } else { $con = array_merge($con, array('e.subject_id = ' . Yii::app()->session['session_duoxueke_subject_id'])); } if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){ $con = array_merge($con, array('e.subject_id in ('.implode(',',$this->mathSubjectId).')')); }else{ $condition[] = "e.subject_id = '{$this->subjectId}'"; } $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id']; $class_array = ClassModel::model()->findAll($criteria); $ccArray = array(); $ccName = array(); foreach ($class_array as $cc => $ca) { array_push($ccArray, $ca->class_id); $ccName[$ca->class_id] = $ca->class_name; } $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "e.status = 1"), $con),array('e.complete_time desc')); if ($resultList["rs"]) { foreach ($resultList['rs'] as $k => $v) { $printList[$k] = $v; $printList[$k]['class_name'] = @$ccName[$v["class_id"]]; $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称 $printList[$k]['print_name'] = $pname; } } $data = array(); $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data['realname'] = $getName; $data['grade_id'] = $grade_id; $data['class_id'] = $class_id; $data['grade_class'] = $grade_class_array; $data['printList1'] = $printList; $data['pages1'] = $resultList['pager']; $data['page_total1'] = $resultList['pager']->rowsCount; $data["subject"] = $subject_exam_data; if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; } else { $data["use_zhixue"] = 0; } $data['past_sem_exist'] = 0;//默认不存在过去的学期 $sql = 'select start_time from semester where status=1 limit 1'; $res = $this->sConn->createCommand($sql)->queryRow(); $start_time = $res['start_time']; if (!$start_time) { Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误'); } $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time; $res = $this->sConn->createCommand($sql)->queryRow(); $row_num = $res['rownum']; $row_num && $data['past_sem_exist']=1; unset($resultList); return $data; } public function actionOprateexam() { $exam_group_id = Req::post("exam_group_id"); $flag = Req::post("flag"); $error['success'] = 0; if (empty($exam_group_id)) { $error['message'] = '操作失败!'; echo json_encode($error);exit(); } $this->setIs_new($exam_group_id); if ($this->schoolManager->ThirdOprateExamDisplay($exam_group_id,$flag)) { $error['success'] = 1; $error['message'] = '操作成功!'; } else { $error['message'] = '操作失败!'; } echo json_encode($error);exit(); } public function actionExam_list() { ini_set("memory_limit","300M"); $exam_group_id = Req::get("exam_group_id"); $branch = Req::get("branch"); $grade = Req::get("grade"); $exam_date = ''; //考试日期 $exam_name = ''; //考试名称 $exam_uploaded=0; if($exam_group_id>0) { if($exam_group_id <= 0) { Yii::app()->jump->error('未找到考试信息!'); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_group_data) { Yii::app()->jump->error('未找到考试信息!'); } if($exam_group_data->upload_status>0){ $exam_uploaded=1; } $classId = Req::get("classId"); $condition = array(); if($classId) $condition[] = "e.class_id = '{$classId}'"; $condition[] = "eg.exam_group_id = '{$exam_group_id}'"; $classes = $this->schoolManager->getSemesterClasses($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->getExamList($condition,array('e.create_time desc','e.exam_id desc')); if($resultList && isset($resultList['rs'][0])){ $tplData=json_decode($resultList['rs'][0]['tpl_data'],true); }else{ Yii::app()->jump->error('未找到考试信息!'); } if(!$exam_date) $exam_date=$tplData['examDate']; if(!$exam_name) $exam_name=$resultList['rs'][0]['exam_name']; $data['exam_id']=$resultList['rs'][0]['exam_id']; if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){ $data['is_change_to_third'] = 1; }else{ $data['is_change_to_third'] = 0; } //获取paper 表数据 $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$resultList['rs'][0]['exam_id'])); if(!$paper_data) { Yii::app()->jump->error('未找到考试信息!'); } //读取试题数据 $isAllSelect=1; //全部客观题判断 $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id)); //选择题类型判断 $allSubjectType=array(); if($exam_group_data['qxk_paper_id']>0){ $allSubjectType=array(1,2,3,4,12); }else{ $allSubjectType=array(1,2,11); } if($paperTopic){ $data['answer_card_saved'] = 1; foreach ($paperTopic as $item){ if(!in_array($item->type,$allSubjectType)){ $isAllSelect=0; break; } } }else{ //未制作答题卡 $data['answer_card_saved'] = 0; } //读取试题推送设置 $topicPushSettingModel=new SExamPushTopicsSetting(); $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id); $topicPushSettingRelation=array(); if($topicPushSetting){ foreach ($topicPushSetting as $item){ if($item['topic_ids']){ $topicSetting=json_decode($item['topic_ids'],true); if($topicSetting){ $topicPushSettingRelation[(string)$item['exam_id']]=1; } } } } // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $this->setIs_new($exam_group_id); //查询还原记录 $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($examRestore){ $data['restore'] = 1; }else{ $data['restore'] = 0; } //是否使用在线答题卡 $studentAnswerOnline=$this->schoolManager->getAnswerSheetOnline($exam_group_id); if($studentAnswerOnline){ $data['online_card']=$studentAnswerOnline['online_card']; $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online']; }else{ $data['online_card']=0; $data['is_qrcode_online']=0; } $has_marked = false; $studentAnswerCardOnline=new SStudentAnswerCardOnline(); foreach ($resultList['rs'] as $key => $item){ if($item['status'] == 1){ $has_marked = true; } //查询生成数量 if($data['online_card']==1 && $data['is_qrcode_online']==1){ $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($item['exam_id']); if($studentCardOnline){ $resultList['rs'][$key]['card_created']=$studentCardOnline['count']; } } } //是否能添加班级 FIXME add_class_0924 //打印中 $enable_add_class = false; if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] == 0){ $enable_add_class = true; }else{ //混合阅卷 if($exam_group_data['mark_type'] == 3){ $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true; } //单独阅卷 if($exam_group_data['mark_type'] == 4){ $enable_add_class = $has_marked ? false : true; } } $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } $data['printList'] = $resultList['rs']; $data["classes"] = $_classes; $data["classId"] = $classId; $data["exam_group_id"] = $exam_group_id; $data["exam_group_data"] = $exam_group_data; // $data["subject"] = $subject_exam_data; $data["branch"] = $branch; $data["grade"] = $grade; $data["enable_add_class"] = $enable_add_class; $data['is_all_select']=$isAllSelect; $data["exam_name"] = $exam_name; $data['version_number']=$this->version_number; $data['exam_date']=$exam_date; $data['exam_uploaded']=$exam_uploaded; $data['topic_push_setting']=$topicPushSettingRelation; $this->render('exam_list',$data); } } public function actionChange(){ ini_set("memory_limit","300M"); Url::clean(); $sname = Req::get("sname"); $cid = Req::get("cid"); $eid = Req::get("eid"); $tid = Req::get("tid"); $isFeedback=0; switch($tid){ case "0": $printType = 'wp'; break; case "1": $printType = 'wb'; break; case "2": $printType = 'isp'; break; default: $printType = 'wp'; } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与试卷对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id); if(trim($paperInfo->answer_card_src)) $answerCardUploaded = true; else $answerCardUploaded = false; $tpl = 1;// 需要上传模板 $tplTwo= 1; if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) { $paperType = 1; if (empty($paperInfo->tpl_doc_src)) { $tpl = 2; } $tplTwo= 2; }else{ $paperType = 2; } if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl'])) { $tpl = 1; $paperType = 1; $tplTwo= 2; } if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){ $isCustomTpl = true; } else{ $isCustomTpl = false; } // 获取阅卷类型 $markType = 0; $groupInfo = $this->schoolManager->getExam($eid); if (!empty($groupInfo)) { $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id'])); if (!empty($findInfo)) { $markType = $findInfo->mark_type; if($findInfo->mark_type==0 && $findInfo->is_third==1){ $isUnderLine = 1; } } } $result = array(); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,':is_del'=>0)); //if (empty($relateStudent)) { // Yii::app()->jump->error('未找该试卷关联的学生!'); //} else { //$studentModel = StudentInfo::model(); // 获取学生姓名 $_student_id = array(); foreach($relateStudent as $v) { $_student_id[$v->student_id] = $v->student_id; } //if(!$_student_id) //{ // Yii::app()->jump->error('未找该试卷关联的学生!'); //} $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId); if(!$b_student_arr ){ $array_student = array(); $b_student_arr = array(); $criteria = new CDbCriteria(); $criteria->select = 'student_id'; $criteria->addCondition('school_id=:school_id'); $criteria->addCondition('status=:status'); $criteria->params[':school_id'] = $this->schoolId; $criteria->params[':status'] = 1; $b_student_data = BusinessStudent::model()->findAll($criteria); if($b_student_data){ foreach ($b_student_data as $k=>$v){ $array_student[$v->student_id] = $v->student_id; } } Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId); if($array_student){ Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student); Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000); } unset($criteria); if($b_student_data) { foreach($b_student_data as $v) { $b_student_arr[$v->student_id] = $v->student_id; } } unset($b_student_data); unset($criteria); } $studentNames = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$_student_id); $studentArray = SStudentInfo::model()->findAll($criteria); if (!empty($studentArray)) { foreach ($studentArray as $student) { $studentNames[$student->student_id] = $student->realname; } } //查询是否上传答题图片 $uploadAnswerImgStudent=array(); $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,0); if($student_answer_img){ foreach ($student_answer_img as $val){ $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id']; } } foreach ($relateStudent as $key=>$val) { //查询学生身份证号 $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id)); if($studentInfo){ $result[$key]['id_number'] = $studentInfo->id_number; }else{ $result[$key]['id_number'] = ''; } $result[$key]['student_card'] = $val['student_card']; $result[$key]['school_student_card'] = $val['school_student_card']; $result[$key]['upload_answer_img'] =0; if($val->is_feedback==1){ $isFeedback=1; if(isset($uploadAnswerImgStudent[(string)$val->student_id])){ $result[$key]['upload_answer_img'] =1; } } //查询在线答题卡是否生成 $rs=$this->sConn->createCommand("select answer_card_online_created from student_answer_card_online where exam_id='{$eid}' and student_id='{$val->student_id}' ")->queryRow(); if($rs && $rs['answer_card_online_created']==1){ $result[$key]['online_created'] = 1; }else{ $result[$key]['online_created'] = 0; } if (empty($sname)) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperName'] = $examInfo->name; $result[$key]['studentCode'] = $val->student_id; $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null; $result[$key]['is_feedback'] = $val->is_feedback; $result[$key]['student_img_paper'] = $val->student_img_paper; $result[$key]['is_complete'] = $val->is_complete; } else { if ($sname == $studentNames[$val->student_id]) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperName'] = $examInfo->name; $result[$key]['studentCode'] = $val->student_id; $result[$key]['studentName'] = $studentNames[$val->student_id]; $result[$key]['is_feedback'] = $val->is_feedback; $result[$key]['student_img_paper'] = $val->student_img_paper; $result[$key]['is_complete'] = $val->is_complete; }else{ unset($result[$key]); } unset($relateStudent[$key]); } $printCheck = true; } //} $no_paper_student = array(); $paper_student_array = array(); $c_paper_student_array = array(); $class_student_info_data = array(); $_student_ids = array(); $_student_id_names = array(); $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation if($class_student_data) { foreach($class_student_data as $v) { $_student_ids[$v['student_id']] = $v['student_id']; } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$_student_ids); $studentArray = SStudentInfo::model()->findAll($criteria); if (!empty($studentArray)) { foreach ($studentArray as $student) { $_student_id_names[$student->student_id] = $student->realname; } } } ///$class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生 $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生 if ($paper_student_data) { foreach ($paper_student_data as $v) { $paper_student_array[$v['student_id']] = $v['student_id']; } $class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info } if ($c_paper_student_data) { foreach ($c_paper_student_data as $v) { $c_paper_student_array[$v['student_id']] = $v['student_id']; } //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info } if ($class_student_info_data) { foreach ($class_student_info_data as $v) { $class_student_info_array[$v['student_id']] = $v['realname']; } } if ($class_student_data) { foreach($class_student_data as $v) { if(!isset($b_student_arr[$v['student_id']])) { if ($paper_student_array) { if(isset($paper_student_array[$v['student_id']])){ $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'', ); } } if($c_paper_student_array ) { if(!isset($c_paper_student_array[$v['student_id']]) ) { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'', ); } }else { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'', ); } } } } //判断在线答题卡使用情况 $useAnswerCardOnlineQrcode=0; $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']); if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){ $useAnswerCardOnlineQrcode=1; } $this->setIs_new($examInfo->exam_group_id); $data = array(); if(isset($isUnderLine)){ $data['under_line']=$isUnderLine; } //判断在线答题卡使用情况 $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']); if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){ $data['use_answer_card_online_qrcode']=1; }else{ $data['use_answer_card_online_qrcode']=0; } $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $data['version_number']=$version_number; $data['no_paper_student'] = $no_paper_student; $data['result'] = $result; $data["printType"] = $printType; $data["sname"] = $sname; $data['paper_id'] = $paperInfo->paper_id; $data['exam_id'] = $eid; $data['class_id'] = $cid; $data['type_id'] = $tid; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); // $data["subject"] = $subject_exam_data; $data['wp_type'] = $examInfo->tpl_index; $data['className'] = $classInfo->class_name; $data['paperName'] = $examInfo->name; $data['tpl'] = $tpl; $data['tplTwo'] = $tplTwo; $data['markType'] = $markType; $data['examInfo'] = $examInfo; $data['paperType'] = $paperType; $data['answerCardUploaded'] = $answerCardUploaded; $data['paperData'] = $paperData; $data['isCustomTpl'] = $isCustomTpl; $data['isFeedback'] = $isFeedback; $data['printCheck'] = $printCheck; $data['useAnswerCardOnlineQrcode'] = $useAnswerCardOnlineQrcode; $this->render('change',$data); } public function actionExam_answer() { $exam_group_id = Req::get("exam_group_id"); $data = array(); if($exam_group_id>0) { $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_data || !$exam_group_data) { Yii::app()->jump->error('非法试卷!'); } $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_data->exam_id)); if($paper_data) { $paper_topic_data = SPaperTopicRelation::model()->findAll(array( 'order' => '`order` asc', 'condition' => 'paper_id=:paper_id and type=:type', 'params'=>array(':paper_id'=>$paper_data->paper_id,':type'=>1) )); if($paper_topic_data) { $data['paper_topic'] = $paper_topic_data; }else { Yii::app()->jump->error('试卷无选择题!'); } }else { Yii::app()->jump->error('非法试卷!'); } $this->setIs_new($exam_group_id); if($exam_group_data->sheet_answer) { $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1); }else { $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1); } $data['exam_data'] = $exam_data; $data['use_zhixue'] = 0; $data['exam_group_id'] = $exam_group_id; $data['paper_data'] = $paper_data; $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data["subject"] = $subject_exam_data; $this->render('exam_answer',$data); }else { Yii::app()->jump->error('非法试卷!'); } } public function actionSave_answer() { $answer = Req::post("answer"); $paper_id = Req::post("paper_id"); $exam_group_id = Req::post("exam_group_id"); $status = 0; $exam_answers = array(); if($answer && $paper_id && $exam_group_id) { $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type=:type',array(':paper_id'=>$paper_id,':type'=>1)); if($paper_topic_data) { if(count($answer)==count($paper_topic_data)) { foreach($answer as $k=>$v) { if(empty($v)) { $status = 1; }else { $exam_answers[$k+1] = $v; } } if($status==1) { Yii::app()->jump->error('答案尚未设置或未设置完!'); } if($status==0) { if(false!==ExamGroup::model()->updateAll(array('sheet_answer'=>json_encode($exam_answers)),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id))){ Yii::app()->jump->success('设置成功!',Yii::app()->createUrl('third/index'));exit; }; } }else { Yii::app()->jump->error('答案尚未设置或未设置完!'); } } } Yii::app()->jump->error('答案尚未设置或未设置完!'); } public function actionSet_new() { $exam_group_id = Req::post("exam_group_id"); if($exam_group_id>0) { $this->setIs_new($exam_group_id); } } public function actionPaper() { $exam_group_id = Req::post("exam_group_id"); if($exam_group_id) { $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$third_answer_data) { echo json_encode(array('status'=>-1));exit; } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data) { echo json_encode(array('status'=>1));exit; } } echo json_encode(array('status'=>0));exit; } public function actionVerify_exam_rs() { $exam_group_id = Req::post("exam_group_id"); $exam_ids = array(); if($exam_group_id>0) { $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_data) { // //验证是否发送任务 // $task=ATask::model()->findByPk($exam_group_id); // if($task && in_array($task->answer_sheet_task,array(1,2))){ // echo json_encode(array('status'=>4));exit; // } //验证是否有在线答题卡 $thirdAnswerSheet=$this->sConn->createCommand("select online_card from third_answer_sheet where exam_group_id='".$exam_group_id."' and online_card=1 ")->queryRow(); if($thirdAnswerSheet){ echo json_encode(array('status'=>5));exit; } foreach($exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } // $criteria = new CDbCriteria(); // $criteria->addInCondition('exam_id',$exam_ids); // // $criteria->addNotInCondition('is_labelled', array(0,4)); // $_paper_data = SPaper::model()->findAll($criteria); // if($_paper_data) // { // echo json_encode(array('status'=>3));exit; // } } echo json_encode(array('status'=>0));exit; }else { echo json_encode(array('status'=>2));exit; } } public function setIs_new($exam_group_id) { if($exam_group_id) { Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); } } public function actionSheet() { $data = array(); $sname = ''; $exam_id = Req::get("exam_id"); $class_id = Req::get("class_id"); $sname = Req::get("sname"); $this->setIs_new($exam_id); $k = 0; $z = 0; $x = 0; $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data) { $data['exam']['exam_id'] = $exam_data->exam_id; $data['exam']['name'] = $exam_data->name; $tpl_data = json_decode($exam_data->tpl_data,1); if(isset($tpl_data['items'])) { foreach($tpl_data['items'] as $key=>$val) { if(in_array($key,Yii::app()->params['topic_type']['ke'])) { $k += $val['total']; } if(in_array($key,Yii::app()->params['topic_type']['zu'])) { $z += $val['total']; } if(in_array($key,Yii::app()->params['topic_type']['xu'])) { $x += $val['total']; } } } $data['exam']['name'] = $exam_data->name; $data['exam']['topic_type'] = $k.' 客观题,'.$z.' 主观题,'.$x.' 选做题'; } $criteria = new CDbCriteria(); $criteria->order = 'sheet_id desc'; if($sname) { $criteria->addSearchCondition('name',$sname); } $count = SThirdAnswerSheet::model()->count($criteria); $pager = new CPagination($count); $pager->pageSize = 10; $pager->applyLimit($criteria); $classInfo = ClassModel::model()->findByPk($class_id); if($classInfo) { $data['className'] = $classInfo->class_name; $data['class_id'] = $classInfo->class_id; }else { $data['className'] = ''; $data['class_id'] = $class_id; } $sheet_data = SThirdAnswerSheet::model()->findAll($criteria); $data['sheet'] = $sheet_data; $data['sname'] = $sname; $data['pages'] = $pager; $data['pageSize'] = $pager->pageSize; $data['rowsCount'] = $count; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data["subject"] = $subject_exam_data; $this->render('sheet',$data); } public function actionBinding() { $exam_id = Req::post("exam_id"); $sheet_id = Req::post("sheet_id"); $exam_ids = array(); if($sheet_id && $exam_id) { //验证 $sheet_data = SThirdAnswerSheet::model()->find('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id)); if(!$sheet_data) { echo json_encode(array('status'=>-1));exit; } $sheet_score = json_decode($sheet_data->sheet_score,1); if(!$sheet_score) { echo json_encode(array('status'=>-7));exit; } //验证试卷题量 $topic_types = array(); $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 $key=> $v) { if(in_array($v->type,Yii::app()->params['topic_type']['ke'])){ $topic_types['ke'][$v->topic_id] = $v->topic_id; if(isset($sheet_score[$key+1]) && !empty($sheet_score[$key+1])) { if($v->score != $sheet_score[$key+1]) { echo json_encode(array('status'=>-6));exit; } } } if(in_array($v->type,Yii::app()->params['topic_type']['zu'])){ $topic_types['zu'][$v->topic_id] = $v->topic_id; } if(in_array($v->type,Yii::app()->params['topic_type']['xu'])){ $topic_types['xu'][$v->topic_id] = $v->topic_id; } } if(isset($topic_types['ke'])&&(count($topic_types['ke'])!=$sheet_data->ke_topic_num)) { echo json_encode(array('status'=>-4));exit; } if(!isset($topic_types['ke']) && $sheet_data->ke_topic_num>0) { echo json_encode(array('status'=>-4));exit; } if(isset($topic_types['zu'])&&(count($topic_types['zu'])!=$sheet_data->zu_topic_num)) { echo json_encode(array('status'=>-4));exit; } if(!isset($topic_types['zu']) && $sheet_data->zu_topic_num>0) { echo json_encode(array('status'=>-4));exit; } if(isset($topic_types['xu'])&&(count($topic_types['xu'])!=$sheet_data->xuan_topic_num)) { echo json_encode(array('status'=>-4));exit; } if(!isset($topic_types['xu']) && $sheet_data->xuan_topic_num>0) { echo json_encode(array('status'=>-4));exit; } }else{ echo json_encode(array('status'=>-8));exit; } } /** * 获取同一次考试 */ $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data) { $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $transaction = $this->sConn->beginTransaction(); try{ $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 1; SExamAnswerSheet::model()->deleteAll($criteria); unset($criteria); $sql='INSERT INTO `exam_third_answer_sheet_relation` (`sheet_id`,`exam_id`,`status`,`create_time`)VALUES'; foreach($exam_ids as $e_id) { $sql.='('.$sheet_id.','.$e_id.',1,'.time().'),'; } $sql = substr($sql,0,-1); $this->sConn->createCommand($sql)->execute(); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); Exam::model()->updateAll(array('sheet_answer'=>$sheet_data->sheet_answer,'sheet_score'=>$sheet_data->sheet_score),$criteria); $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); echo json_encode(array('status'=>0));exit; } echo json_encode(array('status'=>1));exit; } } } } echo json_encode(array('status'=>0));exit; } public function actionDel() { $sheet_id = Req::post("sheet_id"); if($sheet_id) { SThirdAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id)); SExamAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id)); } echo json_encode(array('status'=>1)); } public function actionThirdview() { //判断教材设置 if(!Yii::app()->params['school_textbook_setting'] ){ Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!'); } $schoolTextBookSet=Yii::app()->params['school_textbook_setting']; $data = array(); $printType = Req::get("type"); $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); unset($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; } //判断全学科试用学校 // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi'); // $rs=json_decode($rs,true); // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ // $data['is_qxk']=1; // }else{ // $data['is_qxk']=0; // } $data['is_qxk']=1; $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用',51=>'新高一高二'); $textbookArr=array(); foreach ($schoolTextBookSet as $val){ //表里有2个版本的教材,此处过滤掉不属于当前版本的教材 if($data['is_qxk']!=$val['is_qxk']){ continue; } $textBookName=''; if(isset($this->textBookType[$val['subject_id']][$val['textbook_id']])){ $textBookName=$this->textBookType[$val['subject_id']][$val['textbook_id']]; } $textbookArr[$val['grade']]=array( 'grade_id'=>$val['grade'], 'subject_id'=>$val['subject_id'], 'textbook_id'=>$val['textbook_id'], 'subject_name'=>$teacherSubjectNames[$val['subject_id']], 'text_book_name'=>$textBookName ); } if(!isset($textbookArr[1]) || !isset($textbookArr[2])){ Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!'); } $data['textbookArr'] = $textbookArr; $data['version_number']=$this->version_number; $this->render('thirdview',$data); } public function actionThirdview_duo() { $data = array(); $printType = Req::get("type"); if (empty($printType)) { $printType = '2'; $printTypeData = 0; } else { switch ($printType) { case "2": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; default: $printTypeData = null; break; } } $data['printType'] = $printType; // $coach_id = Yii::app()->session['coachInfo']['coach_id']; // $semester_id = Yii::app()->session['session_semester_id']; $coach_id = $this->coachId; $semester_id = $this->semesterId; // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id)); $criteria = new CDbCriteria(); if(Yii::app()->session['session_duoxueke_subject_id']==3) { $criteria->addInCondition('subjects',$this->mathSubjectId); }else { if(Yii::app()->session['session_duoxueke_subject_id']==18){ $criteria->addInCondition('subjects',array(12,13,14)); } if(Yii::app()->session['session_duoxueke_subject_id']==19){ $criteria->addInCondition('subjects',array(15,16,17)); } if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){ $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']); } } $criteria->addCondition('status = 0'); $teacher_data = Teacher::model()->findAll($criteria); unset($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; } $teacherSubjectIds = array(3, 6); $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用'); $teacherSubjectMaterialIds = array(); $teacherSubjectMaterialNames = array(); foreach ($teacherSubjectIds as $teacherSubjectId) { $teacherSubjectMaterialIds[$teacherSubjectId] = array(); $teacherSubjectMaterialNames[$teacherSubjectId] = array(); $textbookTree = $this->apiPost('/textbook/tree', array( 'subjectId' => $teacherSubjectId, 'depth' => 3 )); if (! $textbookTree) { $error[] = 'Brain textbook/tree error'; } elseif (isset($textbookTree->error)) { $error[] = $textbookTree->error; } else { foreach ($textbookTree as $textbook) { if (isset($textbook->modules)) { foreach ($textbook->modules as $module) { if (isset($module->chapters)) { $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id; $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name; } } } } } } // $criteria = new CDbCriteria(); $criteria->addCondition('subject_id=:subject_id'); $criteria->addCondition('school_card_length=0'); $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id']; $criteria->order = 'third_tpl_id desc'; $criteria->limit = 5; $thisTpls = SThirdTplModel::model()->findAll($criteria); // debug($thisTpls); if($thisTpls) { $data['thisTpls'] = $thisTpls; } $data['teacherSubjectIds'] = $teacherSubjectIds; $data['teacherSubjectNames'] = $teacherSubjectNames; $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds; $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames; $data['version_number']=$this->version_number; //判断全学科试用学校 // $rs = http('/teacher/paper/word-group/can-use-new/','POST',$this->schoolId,array(),'cgi',array('schoolId:'.$this->schoolId)); // // $rs=json_decode($rs,true); // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ // $data['is_qxk']=1; // }else{ // $data['is_qxk']=0; // } $data['is_qxk']=1; // echo Yii::app()->params['zsy_api_url'].'
'; // echo json_encode($rs).'
'; // echo $data['is_qxk']; $this->render('thirdview1',$data); } public function actionThirdview_section() { $data = array(); //读取全学科教材 $postRs = $this->apiPost('/all_textbook/tree', array( 'subjectId' => Yii::app()->session['session_duoxueke_subject_id'], )); $textbookTree=array(); if(isset($postRs->status) && $postRs->status==1 && $postRs->data ){ foreach ($postRs->data as $val){ if($val->level==1){ $textbookTree[]=array( 'textbook_id'=>$val->textbook_id, 'textbook_name'=>$val->textbook_name, ); } } } $criteria = new CDbCriteria(); $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']); $criteria->addCondition('status = 0'); $teacher_data = Teacher::model()->findAll($criteria); unset($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; $data['textbookTree']=$textbookTree; $this->render('thirdview_section',$data); } public function actionThirdview_under_line() { $data = array(); $printType = Req::get("type"); if (empty($printType)) { $printType = '2'; $printTypeData = 0; } else { switch ($printType) { case "2": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; default: $printTypeData = null; break; } } $data['printType'] = $printType; // $coach_id = Yii::app()->session['coachInfo']['coach_id']; // $semester_id = Yii::app()->session['session_semester_id']; $coach_id = $this->coachId; $semester_id = $this->semesterId; // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id)); $criteria = new CDbCriteria(); if(Yii::app()->session['session_duoxueke_subject_id']==3) { $criteria->addInCondition('subjects',$this->mathSubjectId); }else { if(Yii::app()->session['session_duoxueke_subject_id']==18){ $criteria->addInCondition('subjects',array(12,13,14)); } if(Yii::app()->session['session_duoxueke_subject_id']==19){ $criteria->addInCondition('subjects',array(15,16,17)); } if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){ $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']); } } $criteria->addCondition('status = 0'); $teacher_data = Teacher::model()->findAll($criteria); unset($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; } $teacherSubjectIds = array(3, 6); $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用'); $teacherSubjectMaterialIds = array(); $teacherSubjectMaterialNames = array(); foreach ($teacherSubjectIds as $teacherSubjectId) { $teacherSubjectMaterialIds[$teacherSubjectId] = array(); $teacherSubjectMaterialNames[$teacherSubjectId] = array(); $textbookTree = $this->apiPost('/textbook/tree', array( 'subjectId' => $teacherSubjectId, 'depth' => 3 )); if (! $textbookTree) { $error[] = 'Brain textbook/tree error'; } elseif (isset($textbookTree->error)) { $error[] = $textbookTree->error; } else { foreach ($textbookTree as $textbook) { if (isset($textbook->modules)) { foreach ($textbook->modules as $module) { if (isset($module->chapters)) { $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id; $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name; } } } } } } // $criteria = new CDbCriteria(); $criteria->addCondition('subject_id=:subject_id'); $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id']; $criteria->order = 'third_tpl_id desc'; $criteria->limit = 5; $thisTpls = SThirdTplModel::model()->findAll($criteria); if($thisTpls) { $data['thisTpls'] = $thisTpls; } $data['teacherSubjectIds'] = $teacherSubjectIds; $data['teacherSubjectNames'] = $teacherSubjectNames; $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds; $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames; $this->render('thirdview_under_line',$data); } public function actionUpdateThirdTpl(){ $error = array(); $tplData = array(); $tpl_title = Req::post("tpl_title"); $third_tpl_id = Req::post("third_tpl_id"); $classIds = Req::post("classIds"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $topic = $_POST["topic"]; $layout = Req::post("layout"); $select_card_type = Req::post("select_card_type"); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($tpl_title)){ $error[] = '请设置答题卡名称'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($topic)){ $error[] = '请设置题型'; } if(empty($layout)){ $error[] = '答题卡类型'; } if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ $card_status = 0; $school_card_length = 8; if($this->schoolId>999){ $school_card_length = 9; } $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") "; $cardData = $this->sConn->createCommand($sql)->queryRow(); if(!$cardData){ $error[] = '无法找到对应班级'; } if($cardData['card_status']){ $school_card_length = (int)$cardData['card_length']; $card_status = (int)$cardData['card_status']; } // $rs = $this->sConn->createCommand()->insert('third_tpl',array( // 'title' => $tpl_title, // 'subject_id' => $subjectId, // 'school_card_status' => $card_status, // 'school_card_length' => $school_card_length, // 'layout' => $layout, // 'select_card_type' => $select_card_type, // 'tpl_data' => $topic, // 'create_time' => time() // )); $rs = SThirdTplModel::model()->updateAll(array( 'title' => $tpl_title, 'subject_id' => $subjectId, 'school_card_status' => $card_status, 'school_card_length' => $school_card_length, 'layout' => $layout, 'select_card_type' => $select_card_type, 'tpl_data' => $topic ),'third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id)); $_layout = array(10=>'A4竖版',11=>'A4横版','20'=>'A3竖版','21'=>'A3三栏','31'=>'A3两栏','40'=>'8K(260*370)两栏','41'=>'8K(260*370)三栏','50'=>'8K(270*390)两栏','51'=>'8K(270*390)三栏'); $_select_card_type = array(1=>'准考证号',2=>'条形码'); if($rs !==false){ echo json_encode(array('status'=>1,'msg'=>'保存成功','result'=>array('third_tpl_id'=>$third_tpl_id,'title'=>$tpl_title,'layout'=>$_layout[$layout],'select_card_type'=>$_select_card_type[$select_card_type])));exit; } } echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit; } public function actionDelThirdTpl(){ $third_tpl_id = Req::post("third_tpl_id"); if($third_tpl_id>0){ $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id)); if($thirdTpl){ echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit; } } echo json_encode(array('status'=>0,'msg'=>'失败'));exit; } public function actionGetThirdTpl(){ $third_tpl_id = Req::post("third_tpl_id"); if($third_tpl_id>0){ $thirdTpl = SThirdTplModel::model()->find('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id))->attributes; if($thirdTpl){ echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit; } } echo json_encode(array('status'=>0,'msg'=>'失败'));exit; } public function actionAjaxchangeclasses() { $subject_id=$this->subjectId; if(isset(Yii::app()->session['session_duoxueke_subject_id'])){ $subject_id=Yii::app()->session['session_duoxueke_subject_id']; } //读取走班设置 $classified=array(); $setting=$this->schoolManager->getClassShift($this->semesterId,$subject_id); if($setting){ foreach ($setting as $value){ $classified[$value['grade']]=$value['status']; } } $result = array(); $error = array(); if (Yii::app()->request->getIsPostRequest()){ $teacher_id = Req::post("teacher_id"); $selectedClassId=Req::post('selectedClassId'); if(empty($teacher_id)){ $error[] = "请指定教师"; }else{ $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']; } } }else{ $class_arr_select_data = ClassModel ::model()->getSelectclassesByTeacher($semester_id,$teacher_id); $class_arr_select =array(); $class_arr_select_ids = array(); $i = 0; if($class_arr_select_data){ foreach($class_arr_select_data as $cas){ if(isset($classified[$cas->grade]) && $classified[$cas->grade]==1){ if($cas->class_type==2){ //判断学科 if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cas->class_id)){ continue; } $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; } }else{ if($cas->class_type==1){ $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($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()->getNoSelectclassesByTeacher($semester_id,$teacher_id,$class_arr_select_ids_str); $class_arr_noselect =array(); $j = 0; if($class_arr_noselect_data){ foreach($class_arr_noselect_data as $cans){ if(isset($classified[$cans->grade]) && $classified[$cans->grade]==1){ if($cans->class_type==2){ //判断学科 if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cans->class_id)){ continue; } $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++; } }else{ if($cans->class_type==1){ $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 UUID_SHORT($length = 20) { $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read(); $result = $query['UUID_SHORT']; if ($length AND is_int($length)) { $result = substr($result, ($length * -1)); } return $result; } public function actionCreatethird(){ $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $markType = Req::post("markType"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $examDate = Req::post("examDate"); $tpl_index = (int)Req::post("tpl_index"); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if(empty($tpl_index)){ $error[] = '请指定类型'; } if(empty($textbookId)){ $error[] = '请指定教材'; } if($error){ Yii::app()->jump->error(implode(',',$error)); }else{ $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } $time = time(); $transaction = $this->sConn->beginTransaction(); try{ // $newExamGroupId = $this->UUID_SHORT(); $newExamGroupId=getUniqueId($this->schoolId); if($markType ==4) { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)"; }else { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)"; } $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ //$newExamId = $this->UUID_SHORT(); $newExamId = getUniqueId($this->schoolId); $sql = "select g.card_length,g.card_status,c.class_type 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; } } $class_type=$cardData['class_type']; $this->sConn->createCommand()->insert('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($tplData), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); // $newPaperId = $this->UUID_SHORT(); $newPaperId= getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => 0, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); $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) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), 'class_type' =>$class_type )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time' =>$time )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if(!$error){ $this->redirect($this->createUrl('third/index')); } } public function actionQuanCreatethird(){ $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $markType = Req::post("markType"); $paperType = (int)Req::post("paperType"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $examDate = Req::post("examDate"); $qxkPaperId = (int)Req::post("isQxk"); // $tpl_index = (int)Req::post("tpl_index"); $tpl_index = $paperType; if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(!matchStrChar($examName)){ $error[] = '考试名称不能包含特殊字符'; } if(!in_array($paperType,array(0,1,2,1050))){ $error[] = '请选择正确的试卷类型'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } // if(empty($tpl_index)){ // $error[] = '请指定类型'; // } if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } $time = time(); $transaction = $this->sConn->beginTransaction(); try{ //$newExamGroupId = $this->UUID_SHORT(); $newExamGroupId=getUniqueId($this->schoolId); if($markType ==4){ $markStatus=1; $status=1; }else{ $markStatus=0; $status=0; } $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`,`qxk_paper_id`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")"; $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ //$newExamId = $this->UUID_SHORT(); $newExamId=getUniqueId($this->schoolId); $sql = "select g.card_length,g.card_status,c.class_type 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; } } $class_type=$cardData['class_type']; $this->sConn->createCommand()->insert('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($tplData), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); //$newPaperId = $this->UUID_SHORT(); $newPaperId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => 0, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); $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) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), 'class_type' =>$class_type )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time' =>$time )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit; } } if(!$error){ echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit; } } public function actionAjaxCreatethird() { $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $markType = Req::post("markType"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $is_update = Req::post("is_update"); $examDate = Req::post("examDate"); $tpl_index = (int)Req::post("tpl_index"); $topic = $_POST["topic"]; $layout = Req::post("layout"); $select_card_type = Req::post("select_card_type"); $json = array(); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(!matchStrChar($examName)){ $error[] = '考试名称不能包含特殊字符'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if(!inArray($tpl_index,array(0,1,2,1050))){ $error[] = '请指定类型'; } if(empty($topic)){ $error[] = '请设置题型'; } if(empty($layout)){ $error[] = '答题卡类型'; } if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ //组装题型topic_items $_topic = json_decode($topic,1); $_topic_mould = array(); $border = ''; $required = 0; /** * * 格式:array( * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0))) */ foreach ($_topic as $k=>$v) { if(!empty($v)) { if ($k == 0) { foreach ($v as $item) { $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0)); } } if ($k == 1) { foreach ($v as $item) { $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0)); } } if ($k == 2) { foreach ($v as $item) { $border = 'no'; if ($item[2] >= 1) { $border = 'no'; } if ($item[2] == 2) { $border = 'dashed'; } if ($item[2] == 3) { $border = 'solid'; } $smallTopics = array(); if(isset($item[3]) && !empty($item[3])){ $smallArr = explode(',', $item[3]); foreach($smallArr as $k=>$v){ $smallNextArr = explode('///', $v); $smallTopics[$smallNextArr[0]] = $smallNextArr[1]; } } $style = 'line'; $row = isset($item[0]) ? $item[0] : 1; $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics); } } if ($k == 3) { foreach ($v as $item) { $border = 'no'; if ($item[2] >= 1) { $border = 'no'; } if ($item[2] == 2) { $border = 'dashed'; } if ($item[2] == 3) { $border = 'solid'; } $styles = explode('///', $item[0]); $style = 'blank'; $row = 0; if ($styles) { if ($styles[0] == 1) { $style = 'blank'; } if ($styles[0] == 2) { $style = 'line'; $row = isset($styles[1]) ? $styles[1] : 1; } if ($styles[0] == 3) { $style = 'table'; } } $smallTopics = array(); if(isset($item[3]) && !empty($item[3])){ $smallArr = explode(',', $item[3]); foreach($smallArr as $k=>$v){ $smallNextArr = explode('///', $v); $smallTopics[$smallNextArr[0]] = $smallNextArr[1]; } } $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics); } } if ($k == 4) { $style = 'blank'; foreach ($v as $item) { if ($item[2] == 1) { $style = 'blank'; } if ($item[2] == 2) { $style = 'line'; } $topics = explode('///', $item[0]); if ($topics) { $required+= $topics[1]; //多组,会有多道必做题 } $topic_no = $this->topic_no($item[1]); if (count($topic_no) != $topics[0]) { $error[] = '答题卡选做题格式设置有问题'; } $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0)); } } } } $topic_items = $this->topic_items($_topic_mould); // debug($topic_items); $_topic_items = array(); if(!$topic_items){ // $error[] = '答题卡格式设置有问题'; echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有问题'));exit; } //添加alias $alias=0; $Multi_Group_Sign=0; $isDisplay=0; $letterNum=0; foreach ($topic_items as $v) { if($v['topic_type']!=17){ $alias++; }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){ $Multi_Group_Sign=$v['multi_group_sign']; $alias++; $isDisplay=1; $letterNum=0; } if($v['topic_type']==17){ $v['alias']=(string)$alias.$this->numToLetter($letterNum); }else{ $v['alias']=(string)$alias; } $v['showNum']=(string)$alias; unset($v['multi_group_sign']); $_topic_items[] = $v; $letterNum++; } if($_topic_items){ $newTopicItems = array(); $i = 1; $no = 1; foreach($_topic_items as $v){ if(isset($v['smallCounts'])){ $isDisplay=1; for($a=1;$a<=$v['smallCounts'];$a++){ $v['id'] = $i; $v['smallNo'] = $a; $v['bigNo'] = $no; $v['alias'] = $no.'.'.$a; $newTopicItems[] = $v; $i++; } }else{ $v['id'] = $i; // $v['smallNo'] = 1; $v['bigNo'] = $no; $newTopicItems[] = $v; $i++; } $no++; } } //debug($newTopicItems); $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } $json['author'] = $teacherName; $json['examDate'] = $examDate; $json['subjectId'] = (int)$subjectId; $json['textbookId'] = (int)$textbookId; $json['exam_name'] = $examName; $json['totals'] = count($newTopicItems); $json['layout'] = (int)$layout; $json['select_card_type'] = (int)$select_card_type; $json['impersonal_topic_type'] = 0; $json['total_score'] = 0; $json['scores'] = 0; $json['is_display'] = $isDisplay; $json['times'] = 0; if($subjectId==8){ $json['isNewEnglish']=1; } $json['school_card_length'] = 8; if($this->schoolId>999){ $json['school_card_length'] = 9; } $json['required'] = (int)$required; $json['new_items'] = $newTopicItems; $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") "; $cardData = $this->sConn->createCommand($sql)->queryRow(); if(!$cardData){ $error[] = '无法找到对应班级'; } if($cardData['card_status']){ $json['school_card_length'] = (int)$cardData['card_length']; }else{ $cardData['card_length'] = 8; if($this->schoolId>999){ $cardData['card_length'] = 9; } } $class_type=$cardData['class_type']; $time = time(); if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; } $transaction = $this->sConn->beginTransaction(); try{ if($is_update){ $exam_ids = array(); ExamGroup::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update)); $xams = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update)); if($xams){ foreach ($xams as $v){ $exam_ids[] = $v->exam_id; } } $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); Exam::model()->deleteAll($criteria); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); SPaper::model()->deleteAll($criteria); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); ClassExamPrinter::model()->deleteAll($criteria); unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); SStudentPaperRelation::model()->deleteAll($criteria); unset($criteria); } //$newExamGroupId = $this->UUID_SHORT(); $newExamGroupId = getUniqueId($this->schoolId); if($markType ==4) { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)"; }else { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)"; } $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ //$newExamId = $this->UUID_SHORT(); $newExamId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($json), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); //$newPaperId = $this->UUID_SHORT(); $newPaperId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => 0, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); $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) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), 'class_type' =>$class_type )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time' =>$time )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit; } } if(!$error){ // echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>$json,'exam_group_id'=>$newExamGroupId));exit; echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit; } } public function actionCreateThirdTpl(){ $error = array(); $tplData = array(); $tpl_title = Req::post("tpl_title"); $classIds = Req::post("classIds"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $topic = $_POST["topic"]; $layout = Req::post("layout"); $select_card_type = Req::post("select_card_type"); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($tpl_title)){ $error[] = '请设置答题卡名称'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($topic)){ $error[] = '请设置题型'; } if(empty($layout)){ $error[] = '答题卡类型'; } if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ $card_status = 0; $school_card_length = 8; if($this->schoolId>999){ $school_card_length = 9; } $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") "; $cardData = $this->sConn->createCommand($sql)->queryRow(); if(!$cardData){ $error[] = '无法找到对应班级'; } if($cardData['card_status']){ $school_card_length = (int)$cardData['card_length']; $card_status = (int)$cardData['card_status']; } $rs = $this->sConn->createCommand()->insert('third_tpl',array( 'title' => $tpl_title, 'subject_id' => $subjectId, 'school_card_status' => $card_status, 'school_card_length' => $school_card_length, 'layout' => $layout, 'select_card_type' => $select_card_type, 'tpl_data' => $topic, 'create_time' => time() )); $third_tpl_id = $this->sConn->getLastInsertID(); $_layout = array(10=>'A4竖版',11=>'A4横版','20'=>'A3竖版','21'=>'A3三栏','31'=>'A3两栏','40'=>'8K(260*370)两栏','41'=>'8K(260*370)三栏','50'=>'8K(270*390)两栏','51'=>'8K(270*390)三栏'); $_select_card_type = array(1=>'准考证号',2=>'条形码'); if($rs){ echo json_encode(array('status'=>1,'msg'=>'保存成功','result'=>array('third_tpl_id'=>$third_tpl_id,'title'=>$tpl_title,'layout'=>$_layout[$layout],'select_card_type'=>$_select_card_type[$select_card_type])));exit; } } echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit; } public function actionCheckAnswerCard(){ $eid = Req::post('eid'); $error['success'] = 0; if (empty($eid)) { $error['message'] = '考试id不存在!'; echo json_encode($error);exit(); } $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid)); if (empty($examGroup)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid)); if (empty($thirdSheet)) { $error['message'] = '尚未创建答题卡,请创建!'; echo json_encode($error);exit(); } $mathAi=0; //数学ai解析入口 $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid)); if($exam_data) { foreach($exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_labelled>0'); $criteria->addCondition('is_labelled<4'); $_paper_data = SPaper::model()->findAll($criteria); if($_paper_data || ($examGroup['is_tagging']>0 && $examGroup['is_tagging']<4)) { $error['success'] = 0; $error['message'] = '已发送标注,无法上传'; echo json_encode($error);exit(); } if(in_array($exam_data[0]['subject_id'],$this->mathSubjectId)){ if($examGroup['qxk_paper_id']>0){ //查询解析数据 $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid)); if($topicWord && $topicWord->is_history_topic){ $mathAi=0; }else{ $mathAi=1; } } } } $start=strtotime(date('Y-m-d'))+3600*8+1800; //8点半 $end=strtotime(date('Y-m-d'))+3600*18; //18点 if((time()>$start && time()<$end) || in_array($this->schoolId,array(2133,4016,4044,2134))){ $error['data']='ai'; }else{ $error['data']='word'; } $error['math_ai']=$mathAi; $error['success'] = 1; echo json_encode($error);exit(); } // 上传试卷模板 public function actionUploadTpl(){ $exam_group_id = Req::post('eid'); $error['success'] = 0; if (empty($exam_group_id)) { $error['message'] = '考试id不存在!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($examInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($thirdSheet)) { $error['message'] = '尚未上传答题卡!'; echo json_encode($error);exit(); } if (empty($_FILES['word_file'])) { $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); } if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){ $error['message'] = '非法上传!'; echo json_encode($error);exit(); } if ($_FILES['word_file']['error'] > 0) { switch ($_FILES['word_file']['error']) { case 1: $error['message'] = '文件大小超出了服务器的空间大小!'; break; case 2: $error['message'] = '要上传的文件大小超出浏览器限制!'; break; case 3: $error['message'] = '文件只有部分被上传!'; break; case 4: $error['message'] = '没有找到要上传的文件!'; break; case 5: $error['message'] = '服务器临时文件夹丢失!'; break; case 6: $error['message'] = '文件写入到临时文件夹出错!'; break; } echo json_encode($error);exit(); } // 保存上传文件至服务器 $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.')); $fileName = $exam_group_id.$extName; $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName; $ucloud = new HuaweiCloud(); $uploadInfo = $ucloud->putFile($wordRename, $_FILES['word_file']['tmp_name']); if ($uploadInfo['status'] == 0) { echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg'])); exit(); } $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "title" => '第三方试卷上传试卷', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('insert'=>array('exam_group_id'=>$exam_group_id,'status'=>0,'word_path'=>$uploadInfo['url'],'subject_id'=>$examInfo->subject_id))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])), "date"=>date('Y-m-d H:i:s') ))); } $transcation = $this->sConn->beginTransaction(); try { $time = time(); //查询解析数据 $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($topicWord && $topicWord->is_history_topic){ //复用解析,重新上传清空试题 $historyTopic=json_decode($topicWord->is_history_topic,1); if(!$historyTopic){ $error['message'] = '试卷结构恢复不成功!'; echo json_encode($error);exit(); } $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$exam_group_id}")->queryRow(); if ($examGroup['upload_status'] > 0) { $result['message'] = "已上传成绩,不能切换解析模式"; exit(json_encode($result)); } $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(); //取得试卷topic $paperIds=array(); foreach ($exam as $value){ $paperIds[]=$value['paper_id']; } $tplData=json_decode($exam[0]['tpl_data'],true); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $key =>$val){ if(isset($historyTopic[$val['id']])){ $tplData['new_items'][$key]['topicId']=$historyTopic[$val['id']]['topic_id']; $tplData['new_items'][$key]['stemId']=$historyTopic[$val['id']]['stem_id']; } } } $paperTopicRelation=$this->sConn->createCommand("select `order`,`topic_id`,`type`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll(); $updateSql=array(); foreach ($paperTopicRelation as $value){ if(!isset($historyTopic[$value['order']])){ $error['message'] = '试卷结构恢复不成功!'; echo json_encode($error);exit(); } $stemId=0; if(isset($historyTopic[$value['order']]['stem_id'])){ $stemId=$historyTopic[$value['order']]['stem_id']; } $updateSql[]="update paper_topic_relation set topic_id='".$historyTopic[$value['order']]['topic_id']."',stem_id='".$stemId."',method_ids='',method_difficulty=0 where paper_id in(".implode(',',$paperIds).") and topic_id='".$value['topic_id']."'"; if($examGroup['mark_type']==4 && !in_array($historyTopic[$value['order']]['type'],array(1,2,11))){ $updateSql[]="update marking_topic set topic_id='".$historyTopic[$value['order']]['topic_id']."' where exam_group_id='{$exam_group_id}' and topic_id='{$value['topic_id']}'"; } } foreach ($updateSql as $sql){ $this->sConn->createCommand($sql)->execute(); } if($examGroup['mark_type']!=4){ $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute(); } $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$exam_group_id}'")->execute(); } $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute(); STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll(); $wordId = current(current($uuid)); $topic_word_odj = new STopicWord(); $topic_word_odj->word_id = $wordId; $topic_word_odj->exam_group_id = $exam_group_id; $topic_word_odj->word_name = '第三方试卷'.$fileName; $topic_word_odj->word_path = $uploadInfo['url']; $topic_word_odj->word_md5 = ''; $topic_word_odj->word_size = $_FILES['word_file']['size']; $topic_word_odj->subject_id = $examInfo->subject_id; $topic_word_odj->status = 0; $topic_word_odj->uploader_id = $this->coachId; $topic_word_odj->upload_time = $time; $topic_word_odj->save(); $transcation->commit(); } catch (Exception $e) { $transcation->rollback(); $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } $this->schoolManager->saveExamProcess($exam_group_id,3,time()); $error['success'] = 1; $error['message'] = '上传文件成功!'; echo json_encode($error);exit(); } public function actionSetSubjectId() { $subjectId = Req::post("subjectId"); if($subjectId) { Yii::app()->session['session_duoxueke_subject_id'] = $subjectId; echo 1;exit; }else { echo 0;exit; } } /** * * 格式:array( * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0))) * * ) * */ protected function topic_items($topic_data = array()) { $data = array(); $keys = array(); if(!$topic_data) { return false; } foreach ($topic_data as $k=>$v) { $counter = $this->counter($k,$v); if(!$counter){ return array(); }else{ foreach ($counter as $ck =>$cv){ if(!isset($keys[$ck])){ $keys[$ck] = $ck; $data[$ck] = $cv; }else{ return false; } } } } ksort($data); return $data; } /** *计算题量 */ protected function counter($type,$format) { $data = array(); $keys = array(); if($type==1 || $type ==11) { foreach ($format as $_format){ if(isset($_format['option_count']) && !empty($_format['option_count']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])) { $topic_no = $this->topic_no($_format['topic_no_format']); if($topic_no) { foreach ($topic_no as $v) { if(isset($keys[$v])){ return false; }else{ $keys[$v] = $v; } $data[$v]['id'] = (int)$v; $data[$v]['optionsCount'] = (int)$_format['option_count']; $data[$v]['score'] = 0; $data[$v]['topic_type'] = (int)$type; $data[$v]['group_id'] = 0; $data[$v]['border'] = ""; $data[$v]['style'] = ""; $data[$v]['row'] = 0; } }else{ return false; } } } }elseif($type==5){ foreach ($format as $_format){ if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){ if(isset($_format['smallTopics'])){ $smallArr = $_format['smallTopics']; }else{ $smallArr = array(); } $topic_no = $this->topic_no($_format['topic_no_format']); if($topic_no){ foreach ($topic_no as $v){ if(isset($keys[$v])){ return false; }else{ $keys[$v] = $v; } $data[$v]['id'] = (int)$v; $data[$v]['optionsCount'] = 0; $data[$v]['score'] = 0; $data[$v]['group_id'] = 0; $data[$v]['topic_type'] = (int)$type; $data[$v]['border'] = $_format['style']['border']; $data[$v]['style'] = $_format['style']['style']; $data[$v]['row'] = $_format['style']['row']; if(isset($smallArr[$v])){ $data[$v]['smallCounts'] = $smallArr[$v]; } } } } } }elseif($type==7){ foreach ($format as $_format){ if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){ if(isset($_format['smallTopics'])){ $smallArr = $_format['smallTopics']; }else{ $smallArr = array(); } $topic_no = $this->topic_no($_format['topic_no_format']); if($topic_no){ foreach ($topic_no as $v){ if(isset($keys[$v])){ return false; }else{ $keys[$v] = $v; } $data[$v]['id'] = (int)$v; $data[$v]['optionsCount'] = 0; $data[$v]['score'] = 0; $data[$v]['group_id'] = 0; $data[$v]['topic_type'] = (int)$type; $data[$v]['border'] = $_format['style']['border']; $data[$v]['style'] = $_format['style']['style']; $data[$v]['row'] = $_format['style']['row']; if(isset($smallArr[$v])){ $data[$v]['smallCounts'] = $smallArr[$v]; } } } } } }elseif($type==17){ foreach ($format as $_format){ if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){ $topic_no = $this->topic_no($_format['topic_no_format']); //多选题需要添加一个组的标记 $Multi_Group_Sign=0; if($topic_no){ foreach ($topic_no as $v){ if(isset($keys[$v])){ return false; }else{ $keys[$v] = $v; } if(!$Multi_Group_Sign) $Multi_Group_Sign=$v; $data[$v]['id'] = (int)$v; $data[$v]['optionsCount'] = 0; $data[$v]['score'] = 0; $data[$v]['group_id'] = 0; $data[$v]['topic_type'] = (int) $type; $data[$v]['border'] = $_format['style']['border']; $data[$v]['style'] = $_format['style']['style']; $data[$v]['row'] = $_format['style']['row']; $data[$v]['multi_group_sign'] = $Multi_Group_Sign; } } } } } return $data; } /** * @param $str * 格式 */ protected function topic_no($str) { $data = array(); if($str){ $array = explode(',', $str); foreach ($array as $key => $v) { if(!empty($v)){ $section = explode('-', $v); if(count($section)>1) { if($section[1]<$section[0]) { return array(); }else { if($section[0]){ for ($i=$section[0]; $i<= $section[1] ; $i++) { # code... if(isset($data[$i])) { return array(); }else{ $data[$i] = $i; } } } } }else{ if(isset($data[$v])) { return array(); }else{ $data[$v] = $v; } } } } } return $data; } public function actionPrint_paper(){ $exam_group_id = Req::post('exam_group_id'); $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam) { echo json_encode(array('status'=>1,'msg'=>'','result'=>$exam->tpl_data));exit; } echo json_encode(array('status'=>0,'msg'=>$exam->tpl_data,'result'=>''));exit; } public function actionCreate_sheet(){ $examName = Req::post("examName"); $classIds = Req::post("classIds"); $layout = Req::post("layout"); $select_card_type = Req::post("select_card_type"); $topic = $_POST["topic"]; if($topic && $classIds){ $classIds = explode(',',substr($classIds,0,-1)); //组装题型topic_items $_topic = json_decode($topic,1); $_topic_mould = array(); $border = ''; $required = 0; /** * * 格式:array( * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0))) */ // debug($_topic); foreach ($_topic as $k=>$v) { if(!empty($v)) { if ($k == 0) { foreach ($v as $item) { $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0)); } } if ($k == 1) { foreach ($v as $item) { $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0)); } } if ($k == 2) { foreach ($v as $item) { $border = 'no'; if ($item[2] >= 1) { $border = 'no'; } if ($item[2] == 2) { $border = 'dashed'; } if ($item[2] == 3) { $border = 'solid'; } $smallTopics = array(); if(isset($item[3]) && $item[3]){ $smallArr = explode(',', $item[3]); foreach($smallArr as $k=>$v){ $smallNextArr = explode('///', $v); $smallTopics[$smallNextArr[0]] = $smallNextArr[1]; } } $style = 'line'; $row = isset($item[0]) ? $item[0] : 1; $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics); } } if ($k == 3) { foreach ($v as $item) { $border = 'no'; if ($item[2] >= 1) { $border = 'no'; } if ($item[2] == 2) { $border = 'dashed'; } if ($item[2] == 3) { $border = 'solid'; } $smallTopics = array(); if(isset($item[3]) && $item[3]){ $smallArr = explode(',', $item[3]); foreach($smallArr as $k=>$v){ $smallNextArr = explode('///', $v); $smallTopics[$smallNextArr[0]] = $smallNextArr[1]; } } $styles = explode('///', $item[0]); $style = 'blank'; $row = 0; if ($styles) { if ($styles[0] == 1) { $style = 'blank'; } if ($styles[0] == 2) { $style = 'line'; $row = isset($styles[1]) ? $styles[1] : 1; } if ($styles[0] == 3) { $style = 'table'; } } $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics); } } if ($k == 4) { $style = 'blank'; foreach ($v as $item) { if ($item[2] == 1) { $style = 'blank'; } if ($item[2] == 2) { $style = 'line'; } $topics = explode('///', $item[0]); if ($topics && isset($topics[1])) { $required += $topics[1]; } $topic_no = $this->topic_no($item[1]); if (count($topic_no) != $topics[0]) { $error[] = '答题卡选做题格式设置有误,请填写正确的题号'; } $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0)); } } } } // debug($_topic_mould); $topic_items = $this->topic_items($_topic_mould); $_topic_items = array(); if(!$topic_items){ echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写确的题号'));exit; } //添加alias $alias=0; $Multi_Group_Sign=0; $isDisplay=0; $letterNum=0; foreach ($topic_items as $v) { if($v['topic_type']!=17){ $alias++; }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){ $Multi_Group_Sign=$v['multi_group_sign']; $alias++; $isDisplay=1; $letterNum=0; } if($v['topic_type']==17){ $v['alias']=(string)$alias.$this->numToLetter($letterNum); }else{ $v['alias']=(string)$alias; } $v['showNum']=(string)$alias; unset($v['multi_group_sign']); if(isset($v['smallCounts'])){ $smallCounts = (int)$v['smallCounts']; $bigId = (int)$v['alias']; for($a=1;$a<=$smallCounts;$a++){ $v['alias'] = $bigId.'.'.$a; $v['showNum'] = $bigId.'.'.$a; $_topic_items[] = $v; // $alias++; } }else{ $_topic_items[] = $v; } $letterNum++; } //debug($_topic_items); $json['author'] = ''; $json['examDate'] = ''; $json['subjectId'] = (int)Yii::app()->session['session_duoxueke_subject_id']; $json['textbookId'] = 0; $json['exam_name'] = $examName; $json['totals'] = count($_topic_items); $json['layout'] = (int)$layout; $json['select_card_type'] = (int)$select_card_type; $json['impersonal_topic_type'] = 0; $json['total_score'] = 0; $json['is_display'] = 1; $json['times'] = 0; $json['school_card_length'] = 8; if($this->schoolId>999){ $json['school_card_length'] = 9; } $json['required'] = (int)$required; $json['new_items'] = $_topic_items; $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") "; $cardData = $this->sConn->createCommand($sql)->queryRow(); if(!$cardData){ $error[] = '无法找到对应班级'; } if($cardData['card_status']){ $json['school_card_length'] = (int)$cardData['card_length']; } echo json_encode(array('status'=>1,'msg'=>'打印成功','result'=>$json));exit; } echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写考试名称与班级信息'));exit; } /*判断关联答题卡*/ public function actionGetThirdSheet(){ $ExamGroupId=Req::post('exam_group_id'); $getType=Req::post('get_type'); if(!$getType) $getType=0; $result=array('success'=>0); if(!$ExamGroupId || !is_numeric($ExamGroupId)){ exit(json_encode($result)); } //验证是否发送任务 $task=ATask::model()->findByPk($ExamGroupId); if(!$getType){ if($task && in_array($task->paper_task,array(1,2))){ echo json_encode(array('success'=>4));exit; } }else{ if($task && in_array($task->parse_task,array(1,2))){ echo json_encode(array('success'=>4));exit; } } $ThirdSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$ExamGroupId)); if($ThirdSheet){ $result['success']=1; } exit(json_encode($result)); } /********************* 第三方教学宝开始 *********************/ /** * 第三方教学宝 * @throws CException */ public function actionTeaching() { set_time_limit (300); ini_set('memory_limit', '300M'); $classId = Req::get("classId"); $examId = Req::get("examId"); $force = (int)Req::get('force'); $force = 1;//待删 if(!$examId || !is_numeric($examId)){ echo json_encode(array("status" => 1, "error" => "考试ID参数不正确!")); } $examObj = new Exam(); $examInfo = $examObj->getTeachingInfo($examId); if(!$examInfo){ echo json_encode(array("status" => 1, "error" => "没有考试信息!")); exit; } $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path']; $res = array();//生成pdf命令结果 if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath) || $force) { $paperObj = new SPaper(); $ptrObj = new SPaperTopicRelation(); $ptlObj = new SPaperTopicLarge(); $sprObj = new SStudentPaperRelation(); $sptRsObj = new SStudentPaperTopicRs(); $examGroupId = $examInfo['exam_group_id']; $examIds = $examObj->getExamIds($examGroupId); //去除没有上传成绩的学生 $stuIdsArr = $sptRsObj->getHasScoreStu($examIds); $ptrInfo = $sprObj->getStudentExamInfo($examIds); if(!$ptrInfo){ echo json_encode(array("status" => 1, "error" => "考试没有数据!")); exit(); } $paperIds = array(); foreach($ptrInfo as $value){ $paperIds[$value['exam_id']] = $value['paper_id']; } //试卷总分 $paperScore = $paperObj->getPaperScore($paperIds); if(!$paperScore){ echo json_encode(array("status" => 1, "error" => "试卷总分不正确!")); exit(); } /**************************** 一、班级情况分析 ***********************************/ //获取当前考试的上一次考试数据 $cepObj = new SClassExamPrinter(); $preInfo = $cepObj->getPreExamId($examId,$examInfo['subject_id'],$examInfo['class_id']); $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:''; $preExamGroupId = isset($preInfo['exam_group_id'])?$preInfo['exam_group_id']:''; $prePaperScore = 0; $preStuIdsArr = array(); if($preExamId){ $preExamIds = $examObj->getExamIds($preExamGroupId); //去除没有上传成绩的学生 $preStuIdsArr = $sptRsObj->getHasScoreStu($preExamIds); $prePtrInfo = $sprObj->getStudentExamInfo($preExamIds); $prePaperIds = array(); foreach($prePtrInfo as $value){ $prePaperIds[$value['exam_id']] = $value['paper_id']; } if($prePaperIds){ $prePaperScore = $paperObj->getPaperScore($prePaperIds); } }else{ $prePtrInfo = array(); } if(!$prePaperScore && $prePtrInfo){ echo json_encode(array("status" => 1, "error" => "试卷总分不正确!")); exit(); } $paperId = $paperIds[$examId]; //班级排名得分率人数等数据 $classAnalyData = $this->getClassAnalyse($examId,$ptrInfo,$paperScore,$preExamId,$prePtrInfo,$prePaperScore,$stuIdsArr,$preStuIdsArr); //大幅进步,大幅退步,前5名和后5名 $largeOrderData = $this->getLargeOrder($examId,$ptrInfo,$preExamId,$prePtrInfo,$stuIdsArr,$preStuIdsArr); unset($ptrInfo); unset($prePtrInfo); /**************************** 二、考试情况分析 ***********************************/ //试卷题对应的题号,分数 $largeTopicType = $ptlObj->getPaperLargeTopicInfo($paperId); // list($topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType); list($smallTopicScore,$smallTopicNo,$topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType,$examInfo['subject_id']); if(!$topicScore){ echo json_encode(array("status" => 1, "error" => "没有试卷题数据!")); exit(); } // 学生得分 $stuRs = $sptRsObj->getStudentRs($paperIds); if(!$stuRs){ echo json_encode(array("status" => 1, "error" => "没有学生做题数据!")); exit(); } $examAnalyData = $this->getExamAnalyse($stuRs,$topicScore,$topicNo,$paperId,$topicRelLarge); /**************************** 三、题类型掌握情况 ***********************************/ $typeMasterData = $this->getTopicTypeAnaly($stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge); /**************************** 四、试卷讲评 ***********************************/ //试题年级和班级得分率,答对和答错人数 $topicRateStu = $this->getTopicRateWrongPerson($stuRs,$topicScore,$paperId,$stuIdsArr,$topicRelLarge); unset($stuRs); $topicIds = array_keys($topicNo); $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicIds)); if (!$topicDetails) { echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!")); exit(); } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) { echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0])); exit(); } $topicDetails = $this->getTopicDetail($topicDetails); $diff_id_arr = array_diff($topicIds, array_keys($topicDetails)); if ($diff_id_arr) { //todo 发送消息到补提 echo json_encode(array("status" => 1, "error" => "请等待题库老师补题!")); exit; } $data = array(); $data['examInfo'] = $examInfo; $data['classAnalyData'] = $classAnalyData; $data['largeOrderData'] = $largeOrderData; $data['examAnalyData'] = $examAnalyData; $data['typeMasterData'] = $typeMasterData; $data['topicDetails'] = $topicDetails; $data['paperTopicNo'] = $topicNo; $data['smallTopicNo'] = $smallTopicNo; $data['topicRateStu'] = $topicRateStu; $html = $this->renderPartial("teaching", $data, true); // $html = $this->render("teaching", $data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/assets/pdf/academicr/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $htmlpath.=$examId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); $htmlurl = '/assets/' . $examId . ".html"; //访问HTML的路径 if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath $htmlurl = " http://local.zsyas2teaching.com" . '/'.$examId.'.html'; $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm ''"; } else { $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm ''"; } exec($commond, $res, $code); if(isset($res[0])){ $isBool = false; foreach($res as $msg){ if (strpos($msg, 'succeed') !== false){ $isBool = true; } } if ($isBool) {//命令返回成功 if ($this->file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'"); @unlink($htmlpath); } else { $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'"); @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF文件未找到!")); exit; } } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF创建失败!",'exec_rs'=>json_encode($res))); exit; } }else{ Curl::post(Yii::app()->params['handle_log_api'], array( "exam_group_id" => (string)$examGroupId, "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" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$htmlurl))), )); echo json_encode(array("status" => 1, "error" => "PDF创建失败!")); exit; } } if ($this->check_pdf($pdfpath)) { echo json_encode(array("status" => 0, "error" => "","is_create"=>1,'exec_rs'=>json_encode($res))); exit; } else { echo json_encode(array("status" => 1, "error" => "文件尚未生成!",'exec_rs'=>json_encode($res))); exit; } } private function check_pdf($pdf_path) { if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") { if (file_exists($pdf_path)) { return true; } } return false; } /** * 班级排名得分率人数等数据 * @param $examId * @param $ptrInfo * @param $paperScore * @param $preExamId * @param $prePtrInfo * @param $prePaperScore * @return array */ private function getClassAnalyse($examId,&$ptrInfo,$paperScore,$preExamId,&$prePtrInfo,$prePaperScore,&$stuIdsArr,&$preStuIdsArr){ $result = array(); $gradePerson = $classPerson = 0;//参考人数 $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数 $gradeOrder = $classOrder = 0; //排名 $gradeAvgScore = $classAvgScore = 0; //平均分 $gradeScoreRate = $classScoreRate = 0; //得分率 $gradeFineRate = $classFineRate = 0; //优秀率 80% $gradePassRate = $classPassRate = 0; //合格率 60% $gradeLowRate = $classLowRate = 0; //低分率 30% $angData = array( 'class_num' => 0,//班级数量 'order' => 0, 'absent_person' => 0, 'exam_person' => 0, 'avg_score' => 0, 'score_rate' => 0, 'fine_rate' => 0, 'pass_rate' => 0, 'low_rate' => 0, ); $result['grade'] = $result['class'] = $angData; $gradeScoring = $classScoring = array(); $gradeScoringSum = array();//年级中每个考试的得分和 // $classScoringSum = 0;//考试得分和 $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率 foreach($ptrInfo as $value){ $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array(); if(!isset($gradeScoringSum[$value['exam_id']])){ $gradeScoringSum[$value['exam_id']] = 0; } if(inArray($value['student_id'],$stuIds)){ $gradeScoringSum[$value['exam_id']] += $value['scoring']; $gradeScoring[] = $value['scoring']; $gradeStuScoringRate[] = round($value['scoring']/$paperScore,4)*100; $gradePerson++; } if(!inArray($value['student_id'],$stuIds)){ $gradeAbsentPerson++; } if($examId == $value['exam_id']){ if(inArray($value['student_id'],$stuIds)){ // $classScoringSum += $value['scoring']; $classScoring[] = $value['scoring']; $classStuScoringRate[] = round($value['scoring']/$paperScore,4)*100; $classPerson++; } if(!inArray($value['student_id'],$stuIds)){ $classAbsentPerson++; } } } unset($ptrInfo); $result['class']['class_num'] = count($gradeScoringSum); $result['grade']['exam_person'] = $gradePerson; $result['grade']['absent_person'] = $gradeAbsentPerson; $result['class']['exam_person'] = $classPerson; $result['class']['absent_person'] = $classAbsentPerson; //排名 if($gradeScoringSum){ $scoringArr = array(); foreach($gradeScoringSum as $eId => $scoring){ $stuCount = isset($stuIdsArr[$eId])?count($stuIdsArr[$eId]):0; if($stuCount){ $scoringArr[$eId] = round($scoring/$stuCount,2); } } if(isset($scoringArr[$examId])){ $classOrder = $this->getOrder($scoringArr[$examId],$scoringArr); }else{ $classOrder = 0; } } $result['class']['order'] = $classOrder; //平均分,得分率 $count = count($gradeScoring); if($count > 0){ $gradeAvgScore = round(array_sum($gradeScoring)/$count,2);//平均分 $gradeScoreRate = round(array_sum($gradeScoring)/($paperScore*$count),4)*100;//得分率 }else{ $gradeAvgScore = 0; $gradeScoreRate = 0; } $result['grade']['avg_score'] = $gradeAvgScore; $result['grade']['score_rate'] = $gradeScoreRate; $count = count($classScoring); if($count > 0){ $classAvgScore = round(array_sum($classScoring)/$count,2); $classScoreRate = round(array_sum($classScoring)/($paperScore*$count),4)*100;//得分率 }else{ $classAvgScore = 0; $classScoreRate = 0; } $result['class']['avg_score'] = $classAvgScore; $result['class']['score_rate'] = $classScoreRate; //优秀率,合格率,低分率 // $gradeFineRate = $classFineRate = 0; //优秀率 85% // $gradePassRate = $classPassRate = 0; //合格率 60% // $gradeLowRate = $classLowRate = 0; //低分率 30% $tempFineNum = $tempPassNum = $tempLowNum = 0; $rateCount = count($gradeStuScoringRate); foreach($gradeStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } if($scoringRate >= 60){ $tempPassNum++; } if($scoringRate <= 30){ $tempLowNum++; } } $gradeFineRate = round($tempFineNum/$rateCount,4) * 100; $gradePassRate = round($tempPassNum/$rateCount,4) * 100; $gradeLowRate = round($tempLowNum/$rateCount,4) * 100; $result['grade']['fine_rate'] = $gradeFineRate; $result['grade']['pass_rate'] = $gradePassRate; $result['grade']['low_rate'] = $gradeLowRate; $tempFineNum = $tempPassNum = $tempLowNum = 0; $rateCount = count($classStuScoringRate); foreach($classStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } if($scoringRate >= 60){ $tempPassNum++; } if($scoringRate <= 30){ $tempLowNum++; } } $classFineRate = round($tempFineNum/$rateCount,4) * 100; $classPassRate = round($tempPassNum/$rateCount,4) * 100; $classLowRate = round($tempLowNum/$rateCount,4) * 100; $result['class']['fine_rate'] = $classFineRate; $result['class']['pass_rate'] = $classPassRate; $result['class']['low_rate'] = $classLowRate; /**************** 提升数据 ******************/ $result['class']['order_increase'] = 0; $result['class']['rate_increase'] = 0; $result['class']['fine_rate_increase'] = 0; if($prePtrInfo){ $preGradeScoringSum = array(); $preClassScoringSum = 0; $preClassScoring = array(); if($prePtrInfo){ foreach($prePtrInfo as $value){ $stuIds = isset($preStuIdsArr[$value['exam_id']])?$preStuIdsArr[$value['exam_id']]:array(); if(!isset($preGradeScoringSum[$value['exam_id']])){ $preGradeScoringSum[$value['exam_id']] = 0; } if(inArray($value['student_id'],$stuIds)){ $preGradeScoringSum[$value['exam_id']] += $value['scoring']; } if($preExamId == $value['exam_id']){ if(inArray($value['student_id'],$stuIds)){ $preClassScoringSum += $value['scoring']; $preClassScoring[] = $value['scoring']; $preClassStuScoringRate[] = round($value['scoring']/$prePaperScore,4)*100; } } } } //上一次考试排名 if($gradeScoringSum){ $scoringArr = array(); foreach($preGradeScoringSum as $eId => $scoring){ $stuCount = isset($preStuIdsArr[$eId])?count($preStuIdsArr[$eId]):0; if($stuCount){ $scoringArr[$eId] = round($scoring/$stuCount,2); } } if(isset($scoringArr[$preExamId])){ $preClassOrder = $this->getOrder($scoringArr[$preExamId],$scoringArr); }else{ $preClassOrder = 0; } $result['class']['order_increase'] = -($classOrder - $preClassOrder); } $count = count($preClassScoring); if($count > 0){ $preClassScoreRate = round(array_sum($preClassScoring)/($prePaperScore*$count),4)*100;//得分率 $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate; } $tempFineNum = 0; $rateCount = count($preClassStuScoringRate); foreach($preClassStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } } $preClassFineRate = round($tempFineNum/$rateCount,4) * 100; $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate; } return $result; } /** * 大幅进步,大幅退步,前5名和后5名 * @param $examId * @param $ptrInfo * @param $paperScore * @param $preExamId * @param $prePtrInfo * @param $prePaperScore */ private function getLargeOrder($examId,&$ptrInfo,$preExamId,&$prePtrInfo,&$stuIdsArr,&$preStuIdsArr){ $result = array(); $stuOrderArr = $this->getStudentOrder($examId,$ptrInfo,$stuIdsArr); $diffNum = ceil(count($stuOrderArr)*0.2); if($prePtrInfo){ $preStuOrderArr = $this->getStudentOrder($preExamId,$prePtrInfo,$preStuIdsArr); }else{ $preStuOrderArr = array(); } if($preStuOrderArr){ $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr); if(!$interOrderArr){ $interOrderArr = $stuOrderArr; } }else{ $interOrderArr = array(); } //大幅进步,退步 $increaseArr = $reduceArr = array(); $stuDiffOrder = array(); if($interOrderArr){ foreach($stuOrderArr as $stuId => $order){ if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){ $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]); }else{ $stuDiffOrder[$stuId] = 0; } } arsort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num >= $diffNum){ $increaseArr[] = $stuId; } } $increaseArr = array_slice($increaseArr,0,5,true); asort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num <= -$diffNum){ $reduceArr[] = $stuId; } } $reduceArr = array_slice($reduceArr,0,5,true); }else{ $increaseArr = array_slice($stuOrderArr,0,5,true); $reduceArr = array(); } $result['stu_diff_order'] = $stuDiffOrder; $result['stu_order'] = $stuOrderArr; $result['increase_stu'] = $increaseArr; $result['reduce_stu'] = $reduceArr; //前5名和后5名 $font5 = $back5 = array(); $i = 1; $fonrt5_order = array(); foreach($stuOrderArr as $stuId => $order){ if($i <= 5){ $font5[] = $stuId; $fonrt5_order[] = $order; }else{ break; } $i++; } $result['font_five'] = $font5; $i = 1; //删除前5排名 $_stuOrderArr = $stuOrderArr; foreach($_stuOrderArr as $k => $order){ if(in_array($order,$fonrt5_order)){ unset($_stuOrderArr[$k]); } } arsort($_stuOrderArr); foreach($_stuOrderArr as $stuId => $order){ if($i <= 5){ $back5[] = $stuId; }else{ break; } $i++; } $result['back_five'] = $back5; //学生名称 $stuInfoObj = new SStudentInfo(); $stuName = $stuInfoObj->getStudentNames(array_keys($stuOrderArr)); $result['stu_name'] = $stuName; unset($stuOrderArr); return $result; } /** * 考试情况分析 * @param $stuRs * @param $topicScore * @param $topicNo * @return array */ private function getExamAnalyse(&$stuRs,$paperTopicScore,$topicNo,$paperId,$topicRelLarge){ $result = array(); $stuTopicWrong = array();//题答错人数 $topicScoreRate = array();//题得分率 $topicScoring = array();//题得分 $topicScore= array();//题分 foreach($stuRs as $stuId => $rs){ foreach($rs as $v){ if($paperId == $v['paper_id']){ if(isset($topicRelLarge[$v['topic_id']]) && $topicRelLarge[$v['topic_id']] > 0){ $t_id = $topicRelLarge[$v['topic_id']]; }else{ $t_id = $v['topic_id']; } $t_score = isset($paperTopicScore[$t_id])?$paperTopicScore[$t_id]:0; if(!isset($topicScoring[$t_id])){ $topicScoring[$t_id] = 0; } $topicScoring[$t_id] += $v['scoring']; if(!isset($topicScore[$t_id])){ $topicScore[$t_id] = 0; } $topicScore[$t_id] += $t_score; if(!isset($stuTopicWrong[$t_id])){ $stuTopicWrong[$t_id] = array(); } if($t_score != $v['scoring']){ $stuTopicWrong[$t_id][] = $stuId; } } } } //题得分率 foreach($topicScoring as $topicId => $scoring){ if(isset($topicScore[$topicId]) && $topicScore[$topicId] > 0){ $topicScoreRate[$topicId] = round($scoring/$topicScore[$topicId],4) * 100; }else{ $topicScoreRate[$topicId] = 0; } } unset($topicScoring); //答错人数 if($stuTopicWrong){ foreach($stuTopicWrong as $key => $stuIds){ $stuIds = array_unique($stuIds); $stuTopicWrong[$key] = count($stuIds); } } $result['stu_topic_wrong'] = $stuTopicWrong; $result['topic_score_rate'] = $topicScoreRate; $result['topic_no'] = $topicNo; unset($stuTopicWrong); unset($topicScoreRate); unset($topicNo); unset($topicScore); return $result; } //题类型掌握情况 private function getTopicTypeAnaly(&$stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge){ $result = array(); $gradeRate = $classRate = array();//班级和年级得分率 $stuTypeWrong = array();//题型答错人数 $typeTopicNo = array();//题型对应的题号 $typeMasterDegree = array();//题型掌握水平 $typeName = array('1'=>'选择题','11'=>'不定项选择题','5'=>'填空题','7'=>'解答题','17'=>'选做解答题'); $logicTypeName = getSubjectTopicType(Yii::app()->session['session_duoxueke_subject_id']); $gradeScoreArr = $classScoreArr = array(); $gradeScoring = $classScoring = array(); $typeNameArr = array(); foreach($stuRs as $stuId => $rs){ foreach ($rs as $k => $value){ if(isset($topicLogicType[$value['type']]) && $topicLogicType[$value['type']] > 0){ $type = $topicLogicType[$value['type']]; $typeArr = explode('_',$type); if(count($typeArr) > 1){ $type = $typeArr[0]; } $typeNameArr[$type] = isset($logicTypeName[$type])?$logicTypeName[$type]:''; }else{ $type = $value['type']; $typeNameArr[$type] = isset($typeName[$type])?$typeName[$type]:''; } if(!isset($gradeScoring[$type])){ $gradeScoring[$type] = array(); } $gradeScoring[$type][] = $value['scoring']; if(!isset($gradeScoreArr[$type])){ $gradeScoreArr[$type] = 0; } $gradeScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0; if($paperId == $value['paper_id']){ if(!isset($classScoring[$type])){ $classScoring[$type] = 0; } $classScoring[$type] += $value['scoring']; if(!isset($classScoreArr[$type])){ $classScoreArr[$type] = 0; } $classScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0; if(!isset($stuTypeWrong[$type])){ $stuTypeWrong[$type] = 0; } if($value['is_right'] != 1){ $stuTypeWrong[$type]++; } if(!isset($typeTopicNo[$type])){ $typeTopicNo[$type] = array(); } if(isset($topicNo[$value['topic_id']])){ $typeTopicNo[$type][] = $topicNo[$value['topic_id']]; } } } } //年级得分率 foreach($gradeScoring as $type => $scorings){ if(isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]){ $gradeRate[$type] = round(array_sum($scorings)/$gradeScoreArr[$type],4) * 100; }else{ $gradeRate[$type] = 0; } } //班级得分率 foreach ($classScoring as $type => $scoring){ if(isset($classScoreArr[$type]) && $classScoreArr[$type] > 0){ $classRate[$type] = round($scoring/$classScoreArr[$type],4) * 100; }else{ $classRate[$type] = 0; } } //题型对应题号排序 foreach($typeTopicNo as $type => $nos){ asort($nos); $typeTopicNo[$type] = array_unique($nos); } //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。 foreach($classRate as $type => $rate){ if($rate >= 85){ $typeMasterDegree[$type] = 5; }elseif($rate < 85 && $rate >= 75){ $typeMasterDegree[$type] = 4; }elseif($rate < 75 && $rate >= 65){ $typeMasterDegree[$type] = 3; }elseif($rate < 65 && $rate >= 55){ $typeMasterDegree[$type] = 2; }else{ $typeMasterDegree[$type] = 1; } } $result['class_rate'] = $classRate; $result['grade_rate'] = $gradeRate; $result['stu_type_wrong'] = $stuTypeWrong; $result['type_topic_no'] = $typeTopicNo; $result['type_master_degree'] = $typeMasterDegree; $result['type_name_arr'] = $typeNameArr; return $result; } /** * 试题年级和班级得分率,答对和答错人数 * @param $stuRs * @param $topicScore * @param $paperId * @return array */ public function getTopicRateWrongPerson(&$stuRs,$topicScore,$paperId,&$stuIdsArr,$topicRelLarge){ $gradeRate = $classRate = array();//班级和年级得分率 $wrongStu = $rightStu = array();//答对答错人数 $stuNormalIds = array(); foreach($stuIdsArr as $stuIds){ $stuNormalIds = array_merge($stuNormalIds,$stuIds); } $gradeScoring = $classScoring = array(); $gradeScore = $classScore= array(); $doneTopicNum = array();//每题做题总人数 foreach($stuRs as $stuId => $rs){ if(!inArray($stuId,$stuNormalIds)){ continue; } foreach ($rs as $k => $value){ if(isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0){ $t_id = $topicRelLarge[$value['topic_id']]; }else{ $t_id = $value['topic_id']; } $t_score = isset($topicScore[$t_id])?$topicScore[$t_id]:0; if(!isset($gradeScoring[$t_id])){ $gradeScoring[$t_id] = 0; } $gradeScoring[$t_id] += $value['scoring']; if(!isset($gradeScore[$t_id])){ $gradeScore[$t_id] = 0; } $gradeScore[$t_id] += $t_score; if($paperId == $value['paper_id']){ if(!isset($classScoring[$t_id])){ $classScoring[$t_id] = 0; } $classScoring[$t_id] += $value['scoring']; if(!isset($classScore[$t_id])){ $classScore[$t_id] = 0; } $classScore[$t_id] += $t_score; if(!isset($wrongStu[$t_id])){ $wrongStu[$t_id] = array(); } if($t_score != $value['scoring']){ $wrongStu[$t_id][] = $stuId; } if(!isset($doneTopicNum[$t_id])){ $doneTopicNum[$t_id] = array(); } $doneTopicNum[$t_id][] = $stuId; } } } //年级得分率 foreach($gradeScoring as $tId => $scorings){ if(isset($gradeScore[$tId]) && $gradeScore[$tId] > 0){ $gradeRate[$tId] = round($scorings/$gradeScore[$tId],4) * 100; }else{ $gradeRate[$tId] = 0; } } //班级得分率 foreach ($classScoring as $tId => $scoring){ if(isset($classScore[$tId]) && $classScore[$tId] > 0){ $classRate[$tId] = round($scoring/$classScore[$tId],4) * 100; }else{ $classRate[$tId] = 0; } } //答错人数 if($wrongStu){ foreach($wrongStu as $key => $stuIds){ $stuIds = array_unique($stuIds); $wrongStu[$key] = count($stuIds); if(isset($doneTopicNum[$key])){ $_stuIds = array_unique($doneTopicNum[$key]); $rightStu[$key] = count($_stuIds) - $wrongStu[$key]; } } } $result = array(); $result['grade_rate'] = $gradeRate; $result['class_rate'] = $classRate; $result['wrong_stu'] = $wrongStu; $result['right_stu'] = $rightStu; return $result; } /** * 获取学生排名 * @param $examId * @param $ptrInfo * @return array */ private function getStudentOrder($examId,&$ptrInfo,&$stuIdsArr){ $stuOrderArr = array(); $stuScoring = array(); foreach($ptrInfo as $value){ if($examId == $value['exam_id']){ $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array(); if(inArray($value['student_id'],$stuIds)){ $stuScoring[$value['student_id']] = (int)$value['scoring']; } } } $scoringArr = array_values($stuScoring); foreach($stuScoring as $stuId => $scoring){ $stuOrderArr[$stuId] = $this->getOrder((int)$scoring,$scoringArr); } if($stuOrderArr){ asort($stuOrderArr); } return $stuOrderArr; } /** * 获取排名 * @param $ele * @param $arr * @return false|int|string */ private function getOrder($ele,$arr){ $orderRs = 0; if($arr){ arsort($arr); $arr = array_values($arr); $index = array_search($ele,$arr); $orderRs = $index + 1; } return $orderRs; } /** * 整理题详情 * @param $allApiInfo * @return mixed * @throws CException */ public function getTopicDetail($topicBatches){ $optionIndex=array('A','B','C','D','E','F','G','H','I','J','K'); $topicDetails=array(); foreach ($topicBatches AS $topic) { $topic=(object)$topic; $type = $topic->type_id; 6 == $type && $type =5; //6表示多空题,多空题也是5 $topic->id = (string)$topic->id; $topicDetails[$topic->id]=array(); $topicDetails[$topic->id]['is_large_topic']=isset($topic->is_large_topic)?$topic->is_large_topic:0; $topicDetails[$topic->id]['type']=$type; $topicDetails[$topic->id]['subject_id'] = $topic->subject_id; $topicDetails[$topic->id]['methods']='';//考点 $topicDetails[$topic->id]['method_id_arr']='';//考点id数组 $topicDetails[$topic->id]['kps']='';//知识点 $topicDetails[$topic->id]['queBody'] =$this->topicProcess($topic->title);//题目详情 $topicDetails[$topic->id]['options']=''; $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode)?$topic->parse_video_qrcode:''; $topicDetails[$topic->id]['answer']=''; //每题的正确答案 $topicDetails[$topic->id]['analysis']=$this->topicProcess($topic->parse_content);//答题解析 $topicDetails[$topic->id]['teacher_tips']=$this->topicProcess($topic->teacher_tips);//名师点评 $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree)?$topic->difficulty_degree:null; $topicDetails[$topic->id]['difficulty'] = $topic->difficulty; $_methods = array(); $_method_id_arr = array(); $_method_names = array(); if ($topic->specials) { foreach ($topic->specials AS $_method) { $_method = (object)$_method; if ($_method->method_name) { $_methods[] = $_method->method_name; } if (isset($_method->method_id)) { $_method_id_arr[] = $_method->method_id; } if(isset($_method->method_id) && isset($_method->method_name)){ $_method_names[$_method->method_id] = $_method->method_name; } } $topicDetails[$topic->id]['methods']=implode('|', array_unique($_methods));//考点 $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr; $topicDetails[$topic->id]['method_names'] = $_method_names; } $_kps = array(); if (isset($topic->kps) && $topic->kps) { foreach ($topic->kps as $_kp) { $_kp = (object)$_kp; if ($_kp->kp_name) { $_kps[$_kp->kp_id] = $_kp->kp_name; } } $topicDetails[$topic->id]['kps'] = $_kps;//考点 } if($topic->type_id==1 || $topic->type_id==11){ //选择题有选项 if ($topic->items) { if (isset($topic->items[0])) { $topic->items[0] = (object)$topic->items[0]; if (isset($topic->items[0]->options)) { $options = $topic->items[0]->options; if ($options) { $_tmp_options = array(); $correct_answer_arr = array(); foreach ($options AS $_optionIndex => $_option) { $_option = (object)$_option; $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content); if($_option->option_correct){ $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]); // $topicDetails[$topic->id]['answer']=topicProcess($optionIndex[$_optionIndex]); } } $topicDetails[$topic->id]['answer'] = implode(',',$correct_answer_arr); $_list_type= (int)$topic->items[0]->list_type; $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options,$_list_type); } } } } }else{ if ($topic->items) { if (isset($topic->items[0])) { $topic->items[0] = (object)$topic->items[0]; if (isset($topic->items[0]->options)) { $options = $topic->items[0]->options; if ($options) { $_answer = ''; foreach ($options as $v) { $_option = (object)$v; if (trim($_answer) != ''){ $_answer .= ' ; '; } $_answer .= $_option->option_content; } $topicDetails[$topic->id]['answer']=$this->topicProcess($_answer); } } } } } //大题的小题 $topicDetails[$topic->id]['slave']=array(); if(isset($topic->slave) && $topic->slave){ $topicDetails[$topic->id]['answer'] = array(); foreach($topic->slave as $slave){ $slave = (object)$slave; $_slave = array(); $_slave['topic_slave_id']=(string)$slave->topic_slave_id; $_slave['type']=$slave->topic_type; $_slave['methods']='';//考点 $_slave['method_id_arr']='';//考点id数组 $_slave['kps']='';//知识点 $_slave['queBody'] =$this->topicProcess($slave->title);//题目详情 $_slave['options']=''; $_slave['answer']=''; //每题的正确答案 // $_slave['analysis']=topicProcess($slave->parse_content);//答题解析 // $_slave['teacher_tips']=topicProcess($slave->teacher_tips);//名师点评 $_slave['difficulty_degree'] = isset($slave->difficulty_degree)?$slave->difficulty_degree:null; $_slave['difficulty'] = $slave->difficulty; if($slave->topic_type==1 || $slave->topic_type==11){ //选择题有选项 if ($slave->items) { if (isset($slave->items)) { $slave->items = (object)$slave->items; if (isset($slave->items->options)) { $options = (object)$slave->items->options; if ($options) { $_tmp_options = array(); $correct_answer_arr = array(); foreach ($options AS $_optionIndex => $_option) { $_option = (object)$_option; $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content); if($_option->option_correct){ $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]); // $topicDetails[$slave->id]['answer']=topicProcess($optionIndex[$_optionIndex]); } } $_slave['answer'] = implode(',',$correct_answer_arr); $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer']; $_list_type= (int)$slave->items->list_type; $_slave['options'] = $this->option_process($_tmp_options,$_list_type); } } } } }else{ if ($slave->items) { if (isset($slave->items)) { $slave->items = (object)$slave->items; if (isset($slave->items->options)) { $options = (object)$slave->items->options; if ($options) { $_answer = ''; foreach ($options as $v) { $_option = (object)$v; if (trim($_answer) != ''){ $_answer .= ' ; '; } $_answer .= $_option->option_content; } $_slave['answer'] = $this->topicProcess($_answer); $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer']; } } } } } $topicDetails[$topic->id]['slave'][] = $_slave; } } } return $topicDetails; } /** *对选项的处理 * @param $options * @param $list_type * @return string */ public function option_process($options,$list_type){ $option_index=array('A','B','C','D','E','F','G','H','I','J'); if($list_type==0) { //纵向排列,即1行1个 // $option_str=""; }elseif($list_type==1) { //横向排列,即1行4个 // $option_str=""; }elseif($list_type==2){ //1行2个 // $option_str=""; } return $option_str; } public function topicProcess($html) { preg_match_all('/(]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',$html,$arr); foreach($arr[0] as $v){ $process_str=$this->img_process($v); $html = str_replace($v,$process_str,$html); } $html=preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si','',$html); $html=preg_replace('//','',$html); $html=preg_replace('/<\/p>/','',$html); $html=preg_replace('//','',$html); $html=preg_replace('//','',$html); $html=preg_replace('/<\/big>/','',$html); $html=str_replace(" ",'',$html); return $html; } public function img_process($img){ $widthArr = array(); $heightArr = array(); $width = ''; $height = ''; preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr); if ($widthArr) { $width = $this->length_process($widthArr); } else { preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr); if($widthArr) { $width = $this->length_process($widthArr); } } if ($width) { $width = "width=".$width; } preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr); if ($heightArr) { $height = $this->length_process($heightArr); } else { preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr); if($heightArr) { $height = $this->length_process($heightArr); } } if ($height) { $height = "height=".$height; } $return_img = preg_replace('/]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"",$img); return $return_img; } public function length_process($length_arr){ $units = array( 'in' => 96, 'cm' => 28, 'mm' => 2.8, 'pt' => 1.33, 'pc' => 12, ); $length = 0.6*$length_arr[1]; $unit_keys = array_keys($units); if (isset($length_arr[2])) { //将直接连接单位改为 单位换算 if(in_array($length_arr[2],$unit_keys)){ $length = $length*$units[$length_arr[2]]; }else { $length .= $length_arr[2]; } } return $length; } /********************* 第三方教学宝结束 *********************/ //导入线下考试成绩 public function actionImport(){ $examGroupId=Req::get('examgroupid'); if (Yii::app()->request->getIsPostRequest()){ ini_set('memory_limit','300M'); $examGroupId=Req::post('examgroupid'); $card=Req::post('card'); if(!$examGroupId){ Yii::app()->jump->error('请先创建考试'); } if($card==1){ $filed='student_card'; }elseif($card==2){ $filed='school_student_card'; }else{ Yii::app()->jump->error('考号类型不正确'); } $uploader = new Uploader("upload/tmpDir/UploadStudentScore/{$this->schoolId}/"); $uploader->allowTypes = array('xls','xlsx'); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId)); $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; } } $result = true; $inputFileName = $file["src"]; $semesterId = $this->semesterId; Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); // 读取Excel文档 $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); //FIXME 2019-12-02 @unlink($file["src"]); // 去掉导航 unset($sheetData[1]); if(!$sheetData){ Yii::app()->jump->error('成绩数据不能为空'); } $sheetData=array_values($sheetData); //读取考试信息 $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='".$examGroupId."'")->queryAll(); if(!$exam){ Yii::app()->jump->error('考试ID不正确,请从考试列表点击上传成绩'); } $tpl_data=json_decode($exam[0]['tpl_data'],true); if(!$tpl_data || !isset($tpl_data['totals']) || !isset($tpl_data['new_items'])){ Yii::app()->jump->error('考试数据错误,请检查考试数据'); } $checkData=$sheetData[0]; //提取一条数据用与校验 if(empty($checkData['A']) || empty($checkData['B']) || empty($checkData['C'])){ Yii::app()->jump->error('文件格式不正确,请检查后上传'); } if(count($checkData)-$tpl_data['totals']!=3){ Yii::app()->jump->error('成绩对应题目数量与考试设置不一致,请检查后上传'); } //取得试卷topic $paperIds=array(); foreach ($exam as $value){ $paperIds[]=$value['paper_id']; } $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll(); if(!$paper_topic_relation){ Yii::app()->jump->error('试卷创建不成功,请重新检查'); } $paper_topic_rs=array(); foreach ($tpl_data['new_items'] as $key=>$value){ $paper_topic_rs[$paper_topic_relation[$key]['topic_id']]=$value; $tpl_data['new_items'][$key]['topic_id']=$paper_topic_relation[$key]['topic_id']; } $studentCardAll=array(); //更新student_paper_relation ,新增student_paper_topic_rs $sql='INSERT INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE '; $transaction = $this->sConn->beginTransaction(); try{ $error=array(); $valueSql=array(); foreach ($sheetData as $item){ $studentCard=$item['B']; $studentName=$item['A']; $studentClass=$item['C']; if(!$studentCard || !$studentName || !$studentClass){ $error[]='学生信息缺失,姓名:'.$studentName.',准考证号:'.$studentCard.',学生班级:'.$studentClass; continue; } if(in_array($studentCard,$studentCardAll)){ $error[]='准考证号重复:'.$studentCard; continue; } $studentCardAll[]=$studentCard; $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where ".$filed."='".$studentCard."' and paper_id in(".implode(',',$paperIds).")")->queryRow(); if(!$StudentPaperRelation){ $error[]='学生没有参加本次考试 :'.$studentCard; continue; } $studentId=$StudentPaperRelation['student_id']; $paper_id=$StudentPaperRelation['paper_id']; $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$studentId."' ")->queryRow(); if(!$StudentInfo || $StudentInfo['realname']!=$studentName){ $error[]='学生姓名和准考证号不对应 :'.$studentCard; continue; } $this->sConn->createCommand("delete from `student_paper_topic_rs` where student_id='".$studentId."' and paper_id='".$paper_id."' ")->execute(); $topicScoreData=$item; unset($topicScoreData['A']); unset($topicScoreData['B']); unset($topicScoreData['C']); $topicScoreData=array_values($topicScoreData); $score_get=0; $lost_score=0; foreach($topicScoreData as $key=> $ts){ if(!$ts){ $ts=0; } $score=0; $is_right=1; if($ts>=$tpl_data['new_items'][$key]['score']){ $score=$tpl_data['new_items'][$key]['score']; }else{ $score=$ts; $lost_score+=($tpl_data['new_items'][$key]['score']-$ts); $is_right=0; } if(!$score){ $score=0; } $score_get+=$score; $topic_id= $tpl_data['new_items'][$key]['topic_id']; // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll(); // $uuid = current(current($uuid)); $uuid =getUniqueId($this->schoolId); $valueSql[]=' ('.$uuid.','.$studentId.','.$paper_id.','.$topic_id.',1,'.$score.','.$is_right.') '; } $updateSql=" 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"; $updateSql.=" where student_id='".$studentId."' and paper_id='".$paper_id."' "; $this->sConn->createCommand($updateSql)->execute(); } if($valueSql){ $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'=>$examGroupId)); ExamGroup::model()->updateAll(array('mark_status'=>1,'status'=>2,'upload_status'=>1,'import_score_type'=>2),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $transaction->commit(); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); if($error){ // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error)); $this->render('import_underline_error',array('data'=>$error)); }else{ Yii::app()->jump->error('导入成功'); } } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); Yii::app()->jump->error('成绩导入失败,请检查后重新'); } }else{ $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1); $data['subject']=$subject_exam_data; $data['exam_group_id']=$examGroupId; $data['printType']=2; $this->render('score_import',$data); } } //编辑第三方线下考试 public function actionEditThirdUnderLine(){ $examGroupId=Req::get('examgroupid'); //统考Id if(!$examGroupId){ Yii::app()->jump->error('请从考试列表进入编辑'); } $exam=new SExam(); $sql=" select e.exam_id,e.tpl_data,p.paper_id,e.name,eg.teacher_id,e.class_id,e.type from exam_group eg "; $sql .=" join exam e on eg.exam_group_id=e.exam_group_id "; $sql.=" join paper p on p.exam_id=e.exam_id "; $sql.=" where e.exam_group_id=".$examGroupId; $examlist = $this->sConn->createCommand($sql)->queryAll(); if(!$examlist){ Yii::app()->jump->error('考试ID不正确'); } $tpl_data=json_decode($examlist[0]['tpl_data'],true); $paperInfo=array( 'paper_name'=>$examlist[0]['name'], 'type' =>$examlist[0]['type'], 'teacher_id'=>$examlist[0]['teacher_id'], 'exam_date'=>$tpl_data['examDate'], ); foreach ($examlist as $value){ $paperInfo['class_id'][]=$value['class_id']; } //处理题型 $topic_type_data=array(); if(isset($tpl_data['new_items'])){ foreach($tpl_data['new_items'] as $item){ if(isset($topic_type_data[$item['logic_type']]['count'])){ $topic_type_data[$item['logic_type']]['count']++; }else{ $topic_type_data[$item['logic_type']]['count']=1; } $topic_type_data[$item['logic_type']]['score'][]=$item['score']; if(isset($topic_type_data[$item['logic_type']]['total_score'])){ $topic_type_data[$item['logic_type']]['total_score']+=$item['score']; }else{ $topic_type_data[$item['logic_type']]['total_score']=$item['score']; } } } $paperInfo['topic']=$topic_type_data; $printType = Req::get("type"); if (empty($printType)) { $printType = '2'; $printTypeData = 0; } else { switch ($printType) { case "2": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; default: $printTypeData = null; break; } } $data['printType'] = $printType; // $coach_id = Yii::app()->session['coachInfo']['coach_id']; // $semester_id = Yii::app()->session['session_semester_id']; $coach_id = $this->coachId; $semester_id = $this->semesterId; // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id)); $criteria = new CDbCriteria(); if(Yii::app()->session['session_duoxueke_subject_id']==3) { $criteria->addInCondition('subjects',$this->mathSubjectId); }else { if(Yii::app()->session['session_duoxueke_subject_id']==18){ $criteria->addInCondition('subjects',array(12,13,14)); } if(Yii::app()->session['session_duoxueke_subject_id']==19){ $criteria->addInCondition('subjects',array(15,16,17)); } if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){ $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']); } } $criteria->addCondition('status = 0'); $teacher_data = Teacher::model()->findAll($criteria); unset($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; } $teacherSubjectIds = array(3, 6); $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用'); $teacherSubjectMaterialIds = array(); $teacherSubjectMaterialNames = array(); foreach ($teacherSubjectIds as $teacherSubjectId) { $teacherSubjectMaterialIds[$teacherSubjectId] = array(); $teacherSubjectMaterialNames[$teacherSubjectId] = array(); $textbookTree = $this->apiPost('/textbook/tree', array( 'subjectId' => $teacherSubjectId, 'depth' => 3 )); if (! $textbookTree) { $error[] = 'Brain textbook/tree error'; } elseif (isset($textbookTree->error)) { $error[] = $textbookTree->error; } else { foreach ($textbookTree as $textbook) { if (isset($textbook->modules)) { foreach ($textbook->modules as $module) { if (isset($module->chapters)) { $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id; $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name; } } } } } } // $data['teacherSubjectIds'] = $teacherSubjectIds; $data['teacherSubjectNames'] = $teacherSubjectNames; $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds; $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames; $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1); $data['subject']=$subject_exam_data; $data['examgroupid']=$examGroupId; $data['tpl_data']=$tpl_data; $data['printType']=2; $data['paper']=$paperInfo; $this->render('index_edit_underline',$data); } //导入线下考试成绩创建考试 public function actionCreatethirdunderline(){ $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $paperType = (int)Req::post("paperType"); $teacherId = Req::post("teacherId"); $textbookId = Req::post("textbookId"); $subjectId = Req::post("subjectId"); $examDate = Req::post("examDate"); $ExamGroupId=Req::post('exam_group_id'); $topic_data=htmlspecialchars_decode(Req::post('topic_data')); $tpl_index = $paperType; $result=array('status'=>0); if(!$topic_data){ $error[] = '请设置试题数据'; } if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(!in_array($paperType,array(0,1,2,1050))){ $error[] = '请选择正确的试卷类型'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if($error){ //Yii::app()->jump->error(implode(',',$error)); echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } //处理试题信息组装tpl_data $topic_data=json_decode($topic_data,true); $topic_num=1; $new_items=array(); $totals=0; $total_score=0; foreach ($topic_data as $datum){ $i=0; $totals+=$datum['topic_count']; $score=explode(',',$datum['topic_score']); while ($datum['topic_count']>0){ if(!isset($score[$i])){ $error[]='分数设置不正确'; Yii::app()->jump->error(implode(',',$error)); } $new_items[]=array( 'id'=>$topic_num, 'score'=>$score[$i], 'topic_type'=>7, 'logic_type'=>$datum['topic_type'], ); $datum['topic_count']--; $topic_num++; $total_score+=$score[$i]; $i++; } } $tplData['totals']=$totals; $tplData['total_score']=$total_score; $tplData['new_items']=$new_items; $time = time(); $transaction = $this->sConn->beginTransaction(); try{ if(!$ExamGroupId){ // $newExamGroupId = $this->UUID_SHORT(); $newExamGroupId=getUniqueId($this->schoolId); $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`import_score_type`) " . "values (".$newExamGroupId.",".$teacherId.",0,0,1,2)"; $this->sConn->createCommand($sql)->execute(); }else{ //删除原exam,paper,paper_topic_relation,class_exam_printer,student_paper_relation $sql=" select e.exam_id,e.tpl_data,p.paper_id,e.name,eg.teacher_id,e.class_id,e.type from exam_group eg "; $sql .=" join exam e on eg.exam_group_id=e.exam_group_id "; $sql.=" join paper p on p.exam_id=e.exam_id "; $sql.=" where e.exam_group_id=".$ExamGroupId; $examlist = $this->sConn->createCommand($sql)->queryAll(); if(!$examlist){ exit(json_encode(array('status'=>0,'msg'=>'考试ID不正确'))); } $oldExamIds=array(); $oldPaperIds=array(); foreach($examlist as $item){ $oldExamIds[]=$item['exam_id']; $oldPaperIds[]=$item['paper_id']; } if(!$oldExamIds || !$oldPaperIds){ exit(json_encode(array('status'=>0,'msg'=>'考试数据错误'))); } $this->sConn->createCommand("delete from exam where exam_id in(".implode(',',$oldExamIds).")")->execute(); $this->sConn->createCommand("delete from paper where paper_id in(".implode(',',$oldPaperIds).")")->execute(); $this->sConn->createCommand("delete from paper_topic_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute(); $this->sConn->createCommand("delete from class_exam_printer where exam_id in(".implode(',',$oldExamIds).")")->execute(); $this->sConn->createCommand("delete from student_paper_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute(); $this->sConn->createCommand("update exam_group set teacher_id='".$teacherId."' where exam_group_id='".$ExamGroupId."'")->execute(); $newExamGroupId=$ExamGroupId; } $paperIds=array(); foreach($classIds as $classId){ //$newExamId = $this->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('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($tplData), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); //$newPaperId = $this->UUID_SHORT(); $newPaperId=getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => $total_score, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $paperIds[]=$newPaperId; $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 1, 'print_time' => 0, 'add_time' => $time, )); $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('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time' =>$time )); } } } //写入试题,关联信息 foreach ($new_items as $key=>$item){ $this->sConn->createCommand()->insert('topic', array( 'topic_type' =>7, 'topic_title' => '', 'folder_id' => '0', 'subject_id' => $subjectId, 'is_delete' =>1, 'creator_id' => $teacherId, 'updater_id' => $teacherId, 'is_word_topic'=>1, 'create_time' => time(), 'update_time' => time(), )); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $topic_id=$last_insert_id['last_insert_id()']; $this->sConn->createCommand()->insert('topic_item', array( 'topic_id' => $topic_id, 'topic_type' => 7, 'topic_title' => '' )); $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $topic_id, 'mode' => 1, 'teacher_id' => $teacherId, 'paper_id' =>$paperIds[0] )); foreach($paperIds as $kp=>$p) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $p, 'topic_id' => $topic_id, 'no' => $item['id'], 'order' => $item['id'], 'mode' => 1, 'type' => 7, 'score' =>$item['score'] )); } } $transaction->commit(); }catch (Exception $e){ $transaction->rollBack(); exit(json_encode(array('status'=>0,'msg'=>'保存失败'))); } } exit(json_encode(array('status'=>1,'msg'=>'保存成功'))); //$this->redirect($this->createUrl('third/index?list_type=1')); } private function numToLetter($num){ $index = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; return substr($index,$num,1); } // 英语上传试卷答案解析 public function actionUploadEnglishPaper(){ // $error['success'] = 123; // $error['message'] = '上传文件成功!'; // var_dump($_FILES);exit; // echo json_encode($_FILES);exit(); $exam_group_id = Req::post('examGroupId'); $uploadOne = Req::post('uploadOne'); $paper_exam = array(); $paper_answer = array(); $paper_exam_url = array(); $paper_answer_url = array(); $paper_exam_url_str = ''; $paper_answer_url_str = ''; $error['success'] = 0; if (empty($exam_group_id)) { $error['message'] = '考试id不存在!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($examInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); }else{ $exam_name = $examInfo['name']; $tplData = json_decode($examInfo["tpl_data"], true); //考试时间 if(isset($tplData['examDate'])) { $exam_time = strtotime($tplData["examDate"]); }else{ $exam_time = 0; } } $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($thirdSheet)) { $error['message'] = '尚未上传答题卡!'; echo json_encode($error);exit(); } if (empty($_FILES)) { $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); }else{ foreach($_FILES as $k=>$v){ if(isset($v) && !empty($v)){ if(!isset($v['size']) || $v['size'] >= 8388608){ $error['message'] = '文件超过8M!'; echo json_encode($error);exit(); } if(!isset($v['name']) || !in_array(substr($v['name'],strrpos($v['name'],'.')+1),array('doc','docx','pdf','bmp','jpg','jpeg','png'))){ $error['message'] = '文件格式不正确!'; echo json_encode($error);exit(); } if(strpos($k,'paper_answer') !== false){ $paper_answer[] = $v; } if(strpos($k,'paper_exam') !== false){ $paper_exam[] = $v; } } } if(empty($paper_answer) && empty($paper_exam)){ $error['message'] = '尚未上传试卷答案!'; echo json_encode($error);exit(); }else{ // echo json_encode($paper_exam);exit(); krsort($paper_answer); krsort($paper_exam); // echo json_encode($paper_exam);exit(); // 保存上传文件至服务器 $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/'; $pathName1 = 'upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/'; if (!file_exists($pathName)) { mkdir($pathName, 0777, true); } $ucloud = new HuaweiCloud(); // echo json_encode($paper_exam);exit(); foreach($paper_exam as $k=>$v){ // $v['name']=iconv("UTF-8", "gb2312", $v['name']); $fileName = $exam_group_id.$v['name']; $extName = substr($v['name'],strrpos($v['name'],'.')); if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) { $error['message'] = '上传试卷失败!'; echo json_encode($error);exit(); }else{ $meg = $ucloud->putFile('zsyas2/englishPaper/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName); if($meg['status'] == 0){ $error['message'] = $meg['msg']; echo json_encode($error);exit(); }else{ $url = $meg['url']; $url = str_replace("%2F","/",$url); $paper_exam_url[] = $url; $paper_exam_url_str = $url; } } @unlink($pathName1.$fileName); } foreach($paper_answer as $k=>$v){ // $v['name']=iconv("UTF-8", "gb2312", $v['name']); $fileName = $exam_group_id.$v['name']; $extName = substr($v['name'],strrpos($v['name'],'.')); if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) { $error['message'] = '上传试卷失败!'; echo json_encode($error);exit(); }else{ $meg = $ucloud->putFile('zsyas2/englishPaperAnswer/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName); if($meg['status'] == 0){ $error['message'] = $meg['msg']; echo json_encode($error);exit(); }else{ $url = $meg['url']; $url = str_replace("%2F","/",$url); $paper_answer_url[] = $url; $paper_answer_url_str = $url; } } @unlink($pathName1.$fileName); } } } $error['success'] = 1; $error['message'] = '发送成功!'; $error['uploadOne'] = $uploadOne; $error['answer_url'] = $paper_answer_url_str; $error['paper_url'] = $paper_exam_url_str; echo json_encode($error);exit(); } public function actionUploadEnglishPaperInsert(){ $exam_group_id = Req::post('examGroupId'); $paper_answer_url = Req::post('answerUrl'); $paper_exam_url = Req::post('paperUrl'); $printTime = (int)Req::post('printTime'); if($paper_answer_url && $paper_exam_url){ foreach($paper_answer_url as $k=>$v){ if(!$v || empty($v)){ unset($paper_answer_url[$k]); } } foreach($paper_exam_url as $k=>$v){ if(!$v || empty($v)){ unset($paper_answer_url[$k]); } } ksort($paper_answer_url); ksort($paper_exam_url); //关联third_multi_template $sql = "select count(*) count from third_multi_template where exam_group_id = {$exam_group_id}"; $count = $this->sConn->createCommand($sql)->queryAll(); if($count[0]['count']){ $this->sConn->createCommand("delete from `third_multi_template` where exam_group_id = '{$exam_group_id}'")->execute(); } $this->sConn->createCommand()->insert('third_multi_template',array( 'exam_group_id' => $exam_group_id, 'semester_id' => $this->semesterId, 'template_src' => implode(',',$paper_exam_url), 'topic_upload' => 1, 'answer_upload' => 0, 'template_type' => 1, 'update_time' => 0, 'create_time' => time() )); $this->sConn->createCommand()->insert('third_multi_template',array( 'exam_group_id' => $exam_group_id, 'semester_id' => $this->semesterId, 'template_src' => implode(',',$paper_answer_url), 'topic_upload' => 0, 'answer_upload' => 1, 'template_type' => 2, 'update_time' => 0, 'create_time' => time() )); $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($examInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); }else{ $exam_name = $examInfo['name']; $tplData = json_decode($examInfo["tpl_data"], true); //考试时间 if(isset($tplData['examDate'])) { $exam_time = strtotime($tplData["examDate"]); }else{ $exam_time = 0; } } $jsonArr = array(); $jsonArr['exam_name'] = $exam_name; $jsonArr['school_id'] = $this->schoolId; $jsonArr['exam_group_id'] = $exam_group_id; $jsonArr['exam_time'] = $exam_time; $jsonArr['topic_original'] = $paper_exam_url; $jsonArr['answer_parse_original'] = $paper_answer_url; $jsonArr['coach_name'] = isset(Yii::app()->session['coachInfo']['real_name'])?Yii::app()->session['coachInfo']['real_name']:''; $jsonArr['print_time'] = $printTime; $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr)); $resultArr = json_decode($result,true); if($resultArr['status'] == 1){ $sql = "select exam_id from exam where exam_group_id = '{$exam_group_id}'"; $examAll = $this->sConn->createCommand($sql)->queryAll(); $examArr = array(); if($examAll){ foreach($examAll as $k=>$v){ $examArr[] = $v['exam_id']; } $transcation = $this->sConn->beginTransaction(); try { $this->sConn->createCommand("update paper set is_labelled = 3 where exam_id in (".implode(',',$examArr).")")->execute(); $transcation->commit(); } catch (Exception $e) { $transcation->rollback(); $error['message'] = '更新失败!'; echo json_encode($error);exit(); } }else{ $error['message'] = '考试信息错误!'; echo json_encode($error);exit(); } }else{ $error['message'] = $resultArr['message']; echo json_encode($error);exit(); } }else{ $error['message'] = '上传失败!'; echo json_encode($error);exit(); } $this->schoolManager->saveExamProcess($exam_group_id,1,time()); $error['success'] = 1; $error['message'] = '上传成功!'; echo json_encode($error);exit(); } //第三方发送协助 public function actionAssist(){ Url::clean(); $exam_group_id = Req::get("exam_group_id"); //读取考试数据 $examModel=new SExam(); $examInfo=$examModel->getExamByGroupId($exam_group_id); if(!$examInfo) Yii::app()->jump->error('考试参数异常'); $tpl_data=$examInfo[0]['tpl_data']; $tplData=json_decode($tpl_data,true); //读取答题卡设置 $thirdAnswerSheet = $this->sConn->createCommand("select * from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow(); //判断上传状态 $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($exam_group_id); $uploadStatus=0; if($uploadExamInfo){ if(isset($uploadExamInfo[1])){ if($uploadExamInfo[1]['topic_upload']==1){ $uploadStatus+=1; } } if(isset($uploadExamInfo[2])){ if($uploadExamInfo[2]['answer_upload']==1){ $uploadStatus+=3; } } } // debug($tplData); //判断任务发送情况 $task= ATask::model()->findByPk($exam_group_id); $task = json_decode(CJSON::encode($task),TRUE); if($task){ if($task['operator']){ $task['user']=AssistUser::model()->findByPk($task['operator']); } //答题卡任务耗时 if($task['ast_apply_time']){ if($task['answer_sheet_task']>2){ if($task['ast_update_time'] && ($task['ast_update_time']-$task['ast_apply_time'])>0){ $task['AstConsuming']=$this->consuming($task['ast_update_time'],$task['ast_apply_time']); }else{ $task['AstConsuming']='--'; } }elseif($task['answer_sheet_task']==2){ if($task['ast_apply_time'] && (time()-$task['ast_apply_time'])>0){ $task['AstConsuming']=$this->consuming(time(),$task['ast_apply_time']); }else{ $task['AstConsuming']='--'; } } }else{ $task['AstConsuming']='--'; } //试卷任务耗时 if($task['ppt_apply_time']){ if($task['paper_task']>2){ if($task['ppt_update_time'] && ($task['ppt_update_time']-$task['ppt_apply_time'])>0){ $task['PptConsuming']=$this->consuming($task['ppt_update_time'],$task['ppt_apply_time']); }else{ $task['PptConsuming']='--'; } }elseif($task['paper_task']==2){ if($task['ppt_apply_time'] && (time()-$task['ppt_apply_time'])>0){ $task['PptConsuming']=$this->consuming(time(),$task['ppt_apply_time']); }else{ $task['PptConsuming']='--'; } } }else{ $task['PptConsuming']='--'; } //答案解析任务耗时 if($task['pat_apply_time']){ if($task['parse_task']>2){ if($task['pat_update_time'] && ($task['pat_update_time']-$task['pat_apply_time'])>0){ $task['PatConsuming']=$this->consuming($task['pat_update_time'],$task['pat_apply_time']); }else{ $task['PatConsuming']='--'; } }elseif($task['parse_task']==2){ if($task['pat_apply_time'] && (time()-$task['pat_apply_time'])>0){ $task['PatConsuming']=$this->consuming(time(),$task['pat_apply_time']); }else{ $task['PatConsuming']='--'; } } }else{ $task['PatConsuming']='--'; } } //读取试题结构 if(isset($tplData['new_items'])){ $items=array(); foreach ($tplData['new_items'] as $item){ if(isset($item['alias'])){ $items[$item['topic_type']]['no'][]=$item['alias']; }else{ $items[$item['topic_type']]['no'][]=$item['id']; } } $tplData['items']=$items; } $data['exam_name']=$examInfo[0]['name']; $data['subject']=Yii::app()->params['subjectId'][$examInfo[0]['subject_id']]; $data['tpl_data']=$tplData; $data['task']=$task; //debug($tplData); $data['exam_group_id']=$exam_group_id; if($thirdAnswerSheet){ $data['isAnswerCard']=1; }else{ $data['isAnswerCard']=0; } $this->render('assist',$data); } //发送答题卡任务 public function actionSendTask(){ Url::clean(); $exam_group_id = Req::post("examGroupId"); $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析 $msg['success'] = 0; $taskModel=new ATask(); //判断学管任务数量 $allTask=$this->conn->createCommand("select count(*) as count from assist_task where coach_id='".$this->coachId."' and (answer_sheet_task in(1,2) or paper_task in(1,2) or parse_task in(1,2))")->queryRow(); if($allTask && $allTask['count']>5){ $msg['message'] = '您已超过5场考试任务为处理完成,操作过于频繁哦!'; exit(json_encode($msg)); } //验证设置 $setting=AssistSetting::model()->getAssistSetting(); if($setting){ if($setting['cutting_task']==0){ $msg['message'] = '系统后台暂不接受协助任务,请稍后再试,谢谢!'; exit(json_encode($msg)); }elseif($setting['open_cutting_upper_limit'] && $allTask['count']>$setting['cutting_task_upper_limit_num']){ $msg['message'] = '系统后台排队任务过多,请稍后再试,谢谢!'; exit(json_encode($msg)); } } //拼接mysigninfo $mySignInfo='userid='.$this->coachId.'&session='.Yii::app()->request->cookies['appLoginSessionId'].'&sig='.Yii::app()->request->cookies['loginSig'].'&time='.Yii::app()->request->cookies['loginTime']; if($sendType==1){ $imgArr = Req::post("imgArr"); $paperDoc = Req::post("paperDoc"); $card_type = Req::post("cardType"); $paperDocTitle = Req::post("paperDocTitle"); $answer_card_remark = Req::post("answerCardRemark"); if(!$imgArr || !is_array($imgArr)){ $msg['message'] = '请上传答题卡!'; exit(json_encode($msg)); } if(!$paperDoc){ $msg['message'] = '请上传试卷文件!'; exit(json_encode($msg)); } $examModel=new SExam(); $examInfo=$examModel->getExamByGroupId($exam_group_id); if(!$examInfo){ $msg['message'] = '未找到考试信息!'; exit(json_encode($msg)); } $sheetId=0; //读取答题卡设置 $thirdAnswerSheet = $this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow(); if($thirdAnswerSheet){ $sheetId=$thirdAnswerSheet['sheet_id']; } $time=time(); //读取任务记录 //$task=$taskModel->getTaskByExamGroupId($exam_group_id); $task=$taskModel->findByPk($exam_group_id); if(!$task){ $tpl_data=$examInfo[0]['tpl_data']; $tplData=json_decode($tpl_data,true); $tplIndex=$examInfo[0]['tpl_index']; //学校信息 $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId); $taskModel->exam_group_id=$exam_group_id; $taskModel->exam_name=$examInfo[0]['name']; $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id']; $taskModel->school_id=$this->schoolId; $taskModel->school_name=$schoolInfo['school_name']; $taskModel->school_address=$schoolInfo['address']; $taskModel->exam_date=$tplData['examDate']; $taskModel->coach_id=$this->coachId; if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){ $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name']; }else{ $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name']; } $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone']; $taskModel->my_sign_info=$mySignInfo; $taskModel->create_time=$time; $taskModel->update_time=$time; $taskModel->answer_sheet_task=1; $taskModel->ast_create_time=$time; $taskModel->ast_update_time=$time; $taskModel->answer_card_img=implode(',',$imgArr); $taskModel->paper_file_img=$paperDoc; $taskModel->paper_file_title=$paperDocTitle; $taskModel->answer_card_mark=$answer_card_remark; $taskModel->number_type=$card_type; $taskModel->sheet_id=$sheetId; $taskModel->tpl_index=$tplIndex; $taskModel->dsn=$this->sConn->connectionString; $taskModel->database_user=$this->sConn->username; $taskModel->database_password=$this->sConn->password; if($taskModel->save()){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } }else{ if($task['answer_sheet_task']==1 || $task['answer_sheet_task']==2){ $msg['message'] = '不能重复发送协助任务!'; exit(json_encode($msg)); } $taskStatus=1; if($task['operator']!=0){ $taskStatus=2; } $taskStatus=1; $applyTime=0; if($task['operator']!=0){ $taskStatus=2; $applyTime=$time; } $updateArr=array( 'update_time'=>$time, 'answer_sheet_task'=>$taskStatus, 'ast_create_time'=>$time, 'ast_update_time'=>$time, 'ast_apply_time'=>$applyTime, 'paper_file_img'=>$paperDoc, 'paper_file_title'=>$paperDocTitle, 'answer_card_img'=>implode(',',$imgArr), 'number_type'=>$card_type, 'sheet_id'=>$sheetId, 'answer_card_mark'=>$answer_card_remark ); if($taskModel->updateTask($exam_group_id,$updateArr)){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } } }elseif($sendType==2){ //试卷任务 $imgArr = Req::post("imgArr"); $paperRemark = Req::post("paperRemark"); if(!$imgArr || !is_array($imgArr)){ $msg['message'] = '请上传答题卡!'; exit(json_encode($msg)); } $examModel=new SExam(); $examInfo=$examModel->getExamByGroupId($exam_group_id); if(!$examInfo){ $msg['message'] = '未找到考试信息!'; exit(json_encode($msg)); } $time=time(); $taskModel=new ATask(); //读取任务记录 $task=$taskModel->findByPk($exam_group_id); if(!$task){ $tpl_data=$examInfo[0]['tpl_data']; $tplData=json_decode($tpl_data,true); $tplIndex=$examInfo[0]['tpl_index']; //学校信息 $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId); $taskModel->exam_group_id=$exam_group_id; $taskModel->exam_name=$examInfo[0]['name']; $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id']; $taskModel->school_id=$this->schoolId; $taskModel->school_name=$schoolInfo['school_name']; $taskModel->school_address=$schoolInfo['address']; $taskModel->exam_date=$tplData['examDate']; $taskModel->coach_id=$this->coachId; if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){ $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name']; }else{ $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name']; } $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone']; $taskModel->create_time=$time; $taskModel->update_time=$time; $taskModel->my_sign_info=$mySignInfo; $taskModel->paper_task=1; $taskModel->ppt_create_time=$time; $taskModel->ppt_update_time=$time; $taskModel->paper_img=implode(',',$imgArr); $taskModel->paper_mark=$paperRemark; $taskModel->dsn=$this->sConn->connectionString; $taskModel->database_user=$this->sConn->username; $taskModel->database_password=$this->sConn->password; $taskModel->tpl_index=$tplIndex; if($taskModel->save()){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } }else{ if($task['paper_task']==1 || $task['paper_task']==2){ $msg['message'] = '不能重复发送协助任务!'; exit(json_encode($msg)); } $taskStatus=1; $applyTime=0; if($task['operator']!=0){ $taskStatus=2; $applyTime=$time; } $updateArr=array( 'update_time'=>$time, 'paper_task'=>$taskStatus, 'ppt_create_time'=>$time, 'ppt_apply_time'=>$applyTime, 'ppt_update_time'=>$time, 'paper_img'=>implode(',',$imgArr), 'paper_mark'=>$paperRemark, ); if($taskModel->updateTask($exam_group_id,$updateArr)){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } } }elseif($sendType==3){ //答案解析任务 $imgArr = Req::post("imgArr"); $parseRemark = Req::post("parseRemark"); if(!$imgArr || !is_array($imgArr)){ $msg['message'] = '请上传答题卡!'; exit(json_encode($msg)); } $examModel=new SExam(); $examInfo=$examModel->getExamByGroupId($exam_group_id); if(!$examInfo){ $msg['message'] = '未找到考试信息!'; exit(json_encode($msg)); } $tplIndex=$examInfo[0]['tpl_index']; $time=time(); $taskModel=new ATask(); //读取任务记录 $task=$taskModel->findByPk($exam_group_id); if(!$task){ $tpl_data=$examInfo[0]['tpl_data']; $tplData=json_decode($tpl_data,true); //学校信息 $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId); $taskModel->exam_group_id=$exam_group_id; $taskModel->exam_name=$examInfo[0]['name']; $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id']; $taskModel->school_id=$this->schoolId; $taskModel->school_name=$schoolInfo['school_name']; $taskModel->school_address=$schoolInfo['address']; $taskModel->exam_date=$tplData['examDate']; $taskModel->coach_id=$this->coachId; if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){ $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name']; }else{ $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name']; } $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone']; $taskModel->create_time=$time; $taskModel->update_time=$time; $taskModel->my_sign_info=$mySignInfo; $taskModel->parse_task=1; $taskModel->pat_create_time=$time; $taskModel->pat_update_time=$time; $taskModel->parse_img=implode(',',$imgArr); $taskModel->parse_mark=$parseRemark; $taskModel->tpl_index=$tplIndex; $taskModel->dsn=$this->sConn->connectionString; $taskModel->database_user=$this->sConn->username; $taskModel->database_password=$this->sConn->password; if($taskModel->save()){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } }else{ if($task['parse_task']==1 || $task['parse_task']==2){ $msg['message'] = '不能重复发送协助任务!'; exit(json_encode($msg)); } $taskStatus=1; $applyTime=0; if($task['operator']!=0){ $taskStatus=2; $applyTime=$time; } $updateArr=array( 'update_time'=>$time, 'parse_task'=>$taskStatus, 'pat_create_time'=>$time, 'pat_apply_time'=>$applyTime, 'pat_update_time'=>$time, 'parse_img'=>implode(',',$imgArr), 'parse_mark'=>$parseRemark ); if($taskModel->updateTask($exam_group_id,$updateArr)){ $msg['success'] = 1; $msg['message'] = '发送成功!'; exit(json_encode($msg)); } } } } //撤消任务 public function actionUndo(){ Url::clean(); $exam_group_id = Req::post("examGroupId"); $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析 $msg['success']=0; $examModel=new SExam(); $examInfo=$examModel->getExamByGroupId($exam_group_id); if(!$examInfo){ $msg['message'] = '未找到考试信息!'; exit(json_encode($msg)); } $time=time(); $taskModel=new ATask(); //读取任务记录 $task=$taskModel->findByPk($exam_group_id); $filed=''; $timeFiled=''; switch ($sendType){ case 1: $filed='answer_sheet_task'; $timeFiled='ast_update_time'; break; case 2: $filed='paper_task'; $timeFiled='ppt_update_time'; break; case 3: $filed='parse_task'; $pat_update_time='ast_update_time'; break; } if(!$filed){ $msg['message'] = '参数异常!'; exit(json_encode($msg)); } if($task->$filed==2){ $msg['message'] = '该任务已受理,不可撤回,谢谢!'; exit(json_encode($msg)); }elseif($task->$filed==3){ $msg['message'] = '该任务已完成,谢谢!'; exit(json_encode($msg)); }else{ if($taskModel->updateAll(array($filed=>4,'update_time'=>$time,$timeFiled=>$time),'exam_group_id=:eid',array(':eid'=>$exam_group_id))){ $msg['success']=1; $msg['message'] = '撤消成功!'; exit(json_encode($msg)); } } } //上传图片 public function actionUpload(){ ini_set ('memory_limit', '300M'); if(!$_FILES){ Yii::app()->jump->error('文件大小超过范围'); }else { if (!isset($_FILES['paperFile']) || !isset($_FILES['paperFile']['size']) || $_FILES['paperFile']['size'] > 52428800) { Yii::app()->jump->error('文件大小超过范围'); } } if (Yii::app()->request->getIsPostRequest()) { //FIXME 20191202 ucloud // 保存上传文件至服务器 $pathName = dirname(dirname(dirname(__FILE__)))."/upload/tmpDir/UploadAssistFile/{$this->schoolId}/". date('Y/m/d/'); if (!file_exists($pathName)) { mkdir($pathName, 0777, true); } $error['success'] = 0; $ucloud = new HuaweiCloud(); $fileName = $_FILES['paperFile']['name']; $fileName = iconv("UTF-8", "gb2312", $fileName); $extName = substr($fileName,strrpos($fileName,'.')); if (!move_uploaded_file($_FILES['paperFile']['tmp_name'], $pathName.$fileName)) { $error['message'] = '上传失败!'; echo json_encode($error);exit(); }else{ $meg = $ucloud->putFile('zsyas2/third/'.$this->schoolId.'/'.time().mt_rand().$extName,$pathName.$fileName); if($meg['status'] == 0){ $error['message'] = $meg['msg']; echo json_encode($error);exit(); }else{ $url = $meg['url']; $url = str_replace("%2F","/",$url); } } @unlink($pathName.$fileName); $error['success'] = 1; $error['message'] = '上传成功!'; $error['src']=$url; $error['name']=$_FILES['paperFile']["name"]; echo json_encode($error);exit(); } } //计算耗时 public function consuming($now,$time){ $return=''; $date=floor(($now-$time)/86400); if($date){ $return.=$date.'天'; } $hour=floor(($now-$time)%86400/3600); if($hour){ $return.=$hour.'小时'; } $minute=floor((($now-$time)%86400)%3600/60); if($minute){ $return.=$minute.'分种'; } $second=floor(($now-$time)%86400%3600%60); if($second){ $return.=$second.'秒'; } return $return; } //客户端加载未上传学生列表 public function actionNotUploadedStudent(){ $eid = Req::get("examgroupid"); $page =Req::get("page"); $PageLimit=10; if(!$page) $page=1; $examInfo=$this->schoolManager->getExamsByExamGroupId($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到考试信息!'); } $examIds=array(); foreach($examInfo as $val){ $examIds[]=$val['exam_id']; } $result=array(); $rs=$this->schoolManager->getStudentByExamIds($examIds,$page,$PageLimit); if($rs){ foreach($rs['list'] as $key =>$val){ $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow(); if($StudentInfo){ $rs['list'][$key]['realname']=$StudentInfo['realname']; } } } $rs['examgroupid']=$eid; $this->render('not_upload',$rs); } public function actionDownloadStudent() { $eid = Req::get("examgroupid"); $examInfo=$this->schoolManager->getExamsByExamGroupId($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到考试信息!'); } $examIds=array(); foreach($examInfo as $val){ $examIds[]=$val['exam_id']; } $data=$this->schoolManager->getAllStudentByExamIds($examIds); $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("未上传学生") ->setSubject("未上传学生") ->setDescription("未上传学生") ->setKeywords("excel") ->setCategory("result file"); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '序号') ->setCellValue('B1', '姓名') ->setCellValue('C1', '系统准考证号'); $i = 2; foreach($data as $v) { $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, ($i-1)); $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['realname']); $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('C' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING); $i = $i + 1; } $objPHPExcel->getActiveSheet()->setTitle('未上传学生列表'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean(); // Added by me header("Accept-Ranges:bytes"); header('Content-Type:application/vnd.ms-excel'); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header('Content-Disposition:attachment;filename="未上传学生列表.xls"'); header('Cache-Control:max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); } //修改第三方考试信息 public function actionModifyThirdExam(){ if (Yii::app()->request->getIsPostRequest()){ $exam_group_id = Req::post("examGroupId"); $type=Req::post('type'); $name=Req::post('examName'); $examDate=Req::post('examDate'); $paperType=Req::post('paperType'); $relationAnswerCard=false; $transaction = $this->sConn->beginTransaction(); $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_data) { Yii::app()->jump->error('非法试卷!'); } @$tplData=json_decode($exam_data['tpl_data'],true); if(!$tplData){ Yii::app()->jump->error('非法试卷!'); } if(!matchStrChar($name)){ Yii::app()->jump->error('考试名称不能包含特殊字符!'); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data['status']==2){ $examSql="update `exam` set `name`='".$name."' "; $examSql.=" where exam_group_id='".$exam_group_id."'"; $this->sConn->createCommand($examSql)->execute(); $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow(); if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){ updateExamNameToTiku($exam_group_id,$name,$this->schoolId); } $this->redirect($this->createUrl('print/index')); } //是否修改在线答题卡 $text=Req::post("timu"); if($text){ //处理答题卡数据 $relationAnswerCard=true; $name = Req::post("title"); $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:''; $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:''; $post = json_decode($text,true); $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0; $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0; $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0; $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0; $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : ''; $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分 $subject_id=$this->subjectId; if(!$text || !$name || !$sheet_answer || !$sheet_score){ $error['message'] = '题目参数错误'; echo json_encode($error);exit(); } if(!$positionJson){ $error['message'] = '定位信息异常'; echo json_encode($error);exit(); } //上传答题卡相关文件 $files=$this->uploadAnswerCardPdf($exam_group_id,$positionJson,$pdfUrl); $sheet_score_array = json_decode($sheet_score, 1); if (!$sheet_score_array) { $error['success']=0; $error['message'] = '上传失败,未设置分数!'; echo json_encode($error);exit(); } $score_num = count($sheet_score_array); if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) { $error['success']=0; $error['message'] = '上传失败,设置分数或设置题号有误!'; echo json_encode($error);exit(); } $tplData=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData); } try{ $tplData['examDate']=$examDate; if($relationAnswerCard){ $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'); $topic_data = $this->get_topic_folder(); $topic_ids=array(); $examIds=array(); $paperIds=array(); $examData=$this->schoolManager->getExamsByExamGroupId($exam_group_id); foreach ($examData as $val){ $examIds[]=$val['exam_id']; } $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id in(".implode(',',$examIds).")")->queryAll(); foreach ($paperData as $val){ $paperIds[]=$val['paper_id']; } $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id ='{$paperData[0]['paper_id']}'")->qeuryAll(); foreach ($paperTopic as $item){ $topic_ids[]=$item['topic_id']; } //判断原答题卡 $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow(); if($thirdAnswerSheet){ //删除数据 $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute(); $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id ); } foreach($select_info['content'] as $k=>$v) { $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0; $zsytkTopicType=$_topic_type; if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7; $this->sConn->createCommand()->insert('topic', array( 'topic_type' =>$zsytkTopicType , 'topic_title' => '', 'folder_id' => $topic_data['folder_id'], 'subject_id' => $subject_id, 'is_delete' =>0, 'creator_id' => $exam_data['teacher_id'], 'updater_id' => $exam_data['teacher_id'], 'is_word_topic'=>1, 'create_time' => time(), 'update_time' => time(), )); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $topic_id=$last_insert_id['last_insert_id()']; $this->sConn->createCommand()->insert('topic_item', array( 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_title' => '' )); //增加topic_option if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0)) { $answers = explode(',',$v['answer']); if($answers && isset($answers[0]) && !empty($answers[0])){ $options = array_chunk($option,$v['optionCount']); if(isset($options[0]) && !empty($options[0])){ foreach($options[0] as $item=>$val) { $this->sConn->createCommand()->insert('topic_item_option', array( 'topic_id' => $topic_id, 'option_id' => 0, 'option_content' => '', 'option_correct' => in_array($val,$answers)?1:0, 'option_score' => 0, 'sort_order' => $item, )); } } } } $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $topic_id, 'mode' => 1, 'teacher_id' => $exam_data['teacher_id'], 'paper_id' =>$paperData[0]['paper_id'] )); $questionCount = 0; $questionScoreStr = ''; if(isset($v['scores']) && !empty($v['scores'])){ $scoresArr = explode(',',$v['scores']); if($scoresArr){ $questionCount = count($scoresArr); $questionScoreStr = $v['scores']; } } foreach($paperIds as $p) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $p, 'topic_id' => $topic_id, 'no' => $v['questionNum'], 'order' => $v['questionNum'], 'mode' => 1, 'type' => $_topic_type, 'score' =>$v['fullScore'], 'question_count' => $questionCount, 'question_score_str' => $questionScoreStr )); } if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2))) { $topicNo=$v['questionNum']; if(isset($tplData['new_items'][$k]['alias'])){ $topicNo=$tplData['new_items'][$k]['alias']; }elseif(isset($v['alias'])){ $topicNo=$v['alias']; } if(!$topicNo) $topicNo=$v['questionNum']; $this->sConn->createCommand()->insert('marking_topic', array( 'exam_group_id' => $exam_group_id, 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_index' =>$v['questionNum'], 'topic_no' =>$topicNo, 'topic_score' =>$v['fullScore'] )); } } $total = $tplData['total_score']; $topics_count = count($select_info['content']); $tpl_data=json_encode($tplData); $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute(); $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute(); $insert="insert into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`) "; $insert.=" values('".$name."','".$exam_group_id."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') "; $this->sConn->createCommand($insert)->execute(); } $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'"; $this->sConn->createCommand($examSql)->execute(); $transaction->commit(); if($paperData[0]['is_labelled']>0 || $exam_group_data['is_tagging']>0){ updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库 } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $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_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } // echo json_encode(array('status'=>1,'msg'=>'编辑成功'));exit; $this->redirect($this->createUrl('third/index')); }catch(Exception $e){ $transaction->rollBack(); //echo json_encode(array('status'=>0,'msg'=>'编辑失败'));exit; Yii::app()->jump->error('编辑失败!'); } }else{ $exam_group_id = Req::get("exam_group_id"); $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id)); $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_data) { Yii::app()->jump->error('非法试卷!'); } @$tplData=json_decode($exam_data['tpl_data'],true); if(!$tplData){ Yii::app()->jump->error('非法试卷!'); } $classInfo=$this->sConn->createCommand("select grade from class where class_id='".$exam_data['class_id']."'")->queryRow(); $data['grade']=$classInfo['grade']; } $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score,`position`,select_info from third_answer_sheet where exam_group_id='".$exam_group_id."' ")->queryRow(); $data['answerSheet']=0; $data['onlineCard']=0; if($thirdAnswerSheet){ $data['onlineCard']=$thirdAnswerSheet['online_card']; $data['answerSheet']=1; } $data['examGroupId']=$exam_group_id; $data['name']=$exam_data['name']; $data['markType']=$findInfo->mark_type; $data['paperType']=$exam_data['tpl_index']; $data['type']=$exam_data['type']; $data['examDate']=$tplData['examDate']; $data['examStatus']=$findInfo->status; $this->render('modify_exam',$data); } //创建考试并在线答题卡 public function actionCreateThirdOnline(){ $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $markType = Req::post("markType"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $examDate = Req::post("examDate"); $tpl_index = (int)Req::post("tpl_index"); $relationAnswerCard=false; //是否关联答题卡 $json = array(); if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',substr($classIds,0,-1)); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(empty($markType)){ $error[] = '请选择阅卷方式'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if(!inArray($tpl_index,array(0,1,2,1050))){ $error[] = '请指定类型'; } if($error){ echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit; }else{ $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } $json['author'] = $teacherName; $json['examDate'] = $examDate; $json['subjectId'] = (int)$subjectId; $json['textbookId'] = (int)$textbookId; $json['exam_name'] = $examName; $json['impersonal_topic_type'] = 0; $json['total_score'] = 0; $json['scores'] = 0; $json['times'] = 0; if($subjectId==8){ $json['isNewEnglish']=1; } $json['school_card_length'] = 8; if($this->schoolId>999){ $json['school_card_length'] = 9; } $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") "; $cardData = $this->sConn->createCommand($sql)->queryRow(); if(!$cardData){ $error[] = '无法找到对应班级'; } if($cardData['card_status']){ $json['school_card_length'] = (int)$cardData['card_length']; }else{ $cardData['card_length'] = 8; if($this->schoolId>999){ $cardData['card_length'] = 9; } } $class_type=$cardData['class_type']; $time = time(); $newExamGroupId = getUniqueId($this->schoolId); //判断是否关联答题卡 if(isset($_POST["timu"])){ $text=$_POST["timu"]; //处理答题卡数据 $relationAnswerCard=true; $name = Req::post("title"); $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:''; $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:''; $post = json_decode($text,true); $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0; $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0; $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0; $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0; $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : ''; $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分 $subject_id=$this->subjectId; if(!$text || !$name || !$sheet_answer || !$sheet_score){ $error['message'] = '题目参数错误'; echo json_encode($error);exit(); } if(!$positionJson){ $error['message'] = '定位信息异常'; echo json_encode($error);exit(); } //上传答题卡相关文件 $files=$this->uploadAnswerCardPdf($newExamGroupId,$positionJson,$pdfUrl); $sheet_score_array = json_decode($sheet_score, 1); if (!$sheet_score_array) { $error['success']=0; $error['message'] = '上传失败,未设置分数!'; echo json_encode($error);exit(); } $score_num = count($sheet_score_array); if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) { $error['success']=0; $error['message'] = '上传失败,设置分数或设置题号有误!'; echo json_encode($error);exit(); } $select_info = json_decode($select_info, 1); $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$json); } if($error){ echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit; } $transaction = $this->sConn->beginTransaction(); try{ $paperIds=array(); if($markType ==4) { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)"; }else { $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)"; } $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ $newExamId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($json), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); //$newPaperId = $this->UUID_SHORT(); $newPaperId = getUniqueId($this->schoolId); $paperIds[]=$newPaperId; $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => 0, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); $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('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), 'class_type' =>$class_type )); } } } if($relationAnswerCard){ $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'); $topic_data = $this->get_topic_folder(); foreach($select_info['content'] as $k=>$v) { $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0; $zsytkTopicType=$_topic_type; if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7; $this->sConn->createCommand()->insert('topic', array( 'topic_type' =>$zsytkTopicType , 'topic_title' => '', 'folder_id' => $topic_data['folder_id'], 'subject_id' => $subject_id, 'is_delete' =>0, 'creator_id' => $teacherId, 'updater_id' => $teacherId, 'is_word_topic'=>1, 'create_time' => time(), 'update_time' => time(), )); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $topic_id=$last_insert_id['last_insert_id()']; $this->sConn->createCommand()->insert('topic_item', array( 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_title' => '' )); //增加topic_option if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0)) { $answers = explode(',',$v['answer']); if($answers && isset($answers[0]) && !empty($answers[0])){ $options = array_chunk($option,$v['optionCount']); if(isset($options[0]) && !empty($options[0])){ foreach($options[0] as $item=>$val) { $this->sConn->createCommand()->insert('topic_item_option', array( 'topic_id' => $topic_id, 'option_id' => 0, 'option_content' => '', 'option_correct' => in_array($val,$answers)?1:0, 'option_score' => 0, 'sort_order' => $item, )); } } } } $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $topic_id, 'mode' => 1, 'teacher_id' => $teacherId, 'paper_id' =>$newPaperId )); $questionCount = 0; $questionScoreStr = ''; if(isset($v['scores']) && !empty($v['scores'])){ $scoresArr = explode(',',$v['scores']); if($scoresArr){ $questionCount = count($scoresArr); $questionScoreStr = $v['scores']; } } foreach($paperIds as $p) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $p, 'topic_id' => $topic_id, 'no' => $v['questionNum'], 'order' => $v['questionNum'], 'mode' => 1, 'type' => $_topic_type, 'score' =>$v['fullScore'], 'question_count' => $questionCount, 'question_score_str' => $questionScoreStr )); } if($markType==4 && !in_array($v['questionTypeId'],array(1,11,2))) { if(isset($json['new_items'][$k]['alias'])){ $topicNo=$json['new_items'][$k]['alias']; }elseif(isset($v['alias'])){ $topicNo=$v['alias']; } if(!$topicNo) $topicNo=$v['questionNum']; $this->sConn->createCommand()->insert('marking_topic', array( 'exam_group_id' => $newExamGroupId, 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_index' =>$v['questionNum'], 'topic_no' =>$topicNo, 'topic_score' =>$v['fullScore'] )); } } $total = $json['total_score']; $topics_count = count($select_info['content']); $tpl_data=json_encode($json); $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$newExamGroupId )->execute(); $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$newExamGroupId )->execute(); $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute(); $insert="insert into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`) "; $insert.=" values('".$name."','".$newExamGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') "; $this->sConn->createCommand($insert)->execute(); } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); echo json_encode(array('success'=>0,'message'=>'创建失败'));exit; } } if(!$error){ echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit; } } // 上传答题卡相关文件 private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){ $card_file=array(); $card_pdf=''; $ucloudZipUrl=''; $ucloudPdfUrl=''; if (empty($_FILES)) { $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); }else { // debug($_FILES); foreach ($_FILES as $k => $v) { if (isset($v) && !empty($v)) { if (!isset($v['size']) || $v['size'] >= 8388608) { $error['message'] = '文件超过8M!'; echo json_encode($error); exit(); } $ext = substr($v['name'], strrpos($v['name'], '.') + 1); if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) { $error['message'] = '文件格式不正确!'; echo json_encode($error); exit(); } if ($ext == 'pdf') { $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf'; if (!move_uploaded_file($v["tmp_name"], $card_pdf)) { $error['message'] = '保存Pdf文件失败!'; echo json_encode($error); exit(); } } else { $card_file[] = $v; } } } $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/'; $ucloudPdfUrl = ''; if (!file_exists($fixName)) { mkdir($fixName, 0777, true); } $zipFileName = $examGroupId .'_'.time().'.zip'; $pathName = $fixName . $zipFileName; $zip = new ZipArchive; $zip->open($pathName, ZipArchive::CREATE); foreach ($card_file as $k => $v) { $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name'])); } $zip->addFromString('json.txt', $positionJson); $zip->close(); //FIXME 20191204 $ucloud = new HuaweiCloud(); //上传压缩包 $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName; $uploadInfo = $ucloud->putFile($rename, $pathName); @unlink($pathName); if ($uploadInfo['status'] == 0) { $error['success'] = 0; $error['message'] = '答题卡文件上传失败! '; echo json_encode($error); exit(); } else { $ucloudZipUrl = $uploadInfo['url']; } //上传Pdf if ($pdfUrl) { $ucloudPdfUrl=$pdfUrl; // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf'; // $content = file_get_contents($pdfUrl); // // file_put_contents($card_pdf, $content); // // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf'; // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf); // // if ($uploadInfo['status'] == 0) { // @unlink($card_pdf); // $error['success'] = 0; // $error['message'] = '答题卡PDF文件上传失败!'; // echo json_encode($error); // exit(); // } else { // @unlink($card_pdf); // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']); // $ucloudPdfUrl = $uploadInfo['url']; // } } //单独上传position.txt if($positionJson){ $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ; file_put_contents($positionTxt, $positionJson); $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ; $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt); if ($uploadInfo['status'] == 0) { @unlink($positionTxt); $error['success']=0; $error['message'] = 'Position文件上传失败!'; echo json_encode($error);exit(); }else{ @unlink($positionTxt); $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); $ucloudTxtUrl=$uploadInfo['url']; } } } return array( 'ucloudZipUrl'=>$ucloudZipUrl, 'ucloudPdfUrl'=>$ucloudPdfUrl, 'positionUrl'=>$ucloudTxtUrl ); } //处理在线答题卡tpl_data private function updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,$totals,$json){ $subject_id=$this->subjectId; $exam_ids = array(); $_new_items = array(); $required_count = 0; //分组统计,即选做题中,必做题数量 $isDisplay = 1; //是否使用别名, $selectTopicGroupScore = 0; //计算可能多分组情况总分 if ($select_info) { if ($select_info && isset($select_info['content']) && !empty($select_info['content'])) { // $selectTopicGroupNum = 0; //分组试题显示序号 $nowGroupId = 0; //分组标志 $letterNum = 0; $nowSameAliasNo=0; //选做题小题组序号 $sameAliasLetter=0; foreach ($select_info['content'] as $k => $sc) { //校验别名 if (isset($sc['alias']) && !empty($sc['alias'])) { if (!preg_match('/^[0-9.\~]+$/u', $sc['alias']) || !is_numeric(substr($sc['alias'], -1)) || strlen($sc['alias']) > 6) { $this->output(0, "别名格式不正确,别名允许字符【0-9.】且总长度不大于6位,请重新输入,题号:" . $sc['questionNum']); exit; } } if (isset($sc['questionTypeId'])) { if ($sc['questionTypeId'] == 11 && in_array($subject_id,$this->mathSubjectId)) { $this->output(0, "第三方暂不支持不定项选择题"); exit; } //分组判断 if (!isset($sc['groupid'])) { $selectTopicGroupNum++; $selectTopicGroupScore += $sc['fullScore']; } elseif ($nowGroupId != $sc['groupid']) { $isDisplay = 1; $selectTopicGroupNum++; $selectTopicGroupNum = isset($sc['alias']) ? $sc['alias'] : $selectTopicGroupNum; $nowGroupId = $sc['groupid']; if(isset($sc['smTopicLen']) && $sc['smTopicLen']){ $required_count+=$sc['smTopicLen']; $selectTopicGroupScore += ($sc['fullScore']*$sc['smTopicLen']); }else{ $required_count++; $selectTopicGroupScore += $sc['fullScore']; } $letterNum = 0; $sameAliasLetter=0; } if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && $sc['sameAliasNo']!=$nowSameAliasNo){ $sameAliasLetter++; $nowSameAliasNo=$sc['sameAliasNo']; } $_new_items[$k]['sameAliasNo']=isset($sc['sameAliasNo'])?$sc['sameAliasNo']:0; $_new_items[$k]['smTopicLen']=isset($sc['smTopicLen'])?$sc['smTopicLen']:0; $_new_items[$k]['id'] = (int)$sc['questionNum']; $_new_items[$k]['showNum'] = (string)$selectTopicGroupNum; if ($sc['questionTypeId'] == 17) { //判断选做题小题组 if($sameAliasLetter){ $_new_items[$k]['alias'] = (string)$sc['alias'] .$this->numToLetter($sameAliasLetter-1); }else{ $_new_items[$k]['alias'] = (string)$selectTopicGroupNum . $this->numToLetter($letterNum); } } else { if (isset($sc['alias'])) { $_new_items[$k]['alias'] = (string)$sc['alias']; } else { $_new_items[$k]['alias'] = (string)$selectTopicGroupNum; } } if(!$_new_items[$k]['alias']){ $_new_items[$k]['alias']=(int)$sc['questionNum']; } $_new_items[$k]['score'] = $sc['fullScore']; $_new_items[$k]['topic_type'] = (string)$sc['questionTypeId']; $_new_items[$k]['group_id'] = $sc['groupid']; //新增逻辑题型 if (isset($sc['marktype'])) { $_new_items[$k]['logic_type'] = $sc['marktype']; } //每道题科目 if (isset($sc['subject'])) { $_new_items[$k]['subject'] = $sc['subject']; } $letterNum++; //自动批阅 if(isset($sc['reviewSwitch']) && $sc['reviewSwitch']==1){ $_new_items[$k]['reviewSwitch'] = $sc['reviewSwitch']; //自动批阅开关 $_new_items[$k]['reviewWordNumber'] = $sc['reviewWordNumber']; //字数 $_new_items[$k]['reviewTopicImg'] = $sc['reviewTopicImg']; //试题截图链接 } } } } } //处理半对分 $tplRules=array(); if($half_score){ $halfScoreArr=json_decode($half_score,true); $sheetAnswerArr=json_decode($sheet_answer,true); $sheet_score_array = json_decode($sheet_score, 1); foreach ($halfScoreArr as $key => $val){ $ruleScore=0; $ruleAnswer=''; if(isset($sheet_score_array[$key])){ $ruleScore=$sheet_score_array[$key]; } if(isset($sheetAnswerArr[$key])){ $ruleAnswer=$sheetAnswerArr[$key]; } $tplRules[$key]=array( 'topicNo'=>$key, 'topic_id'=>'', 'rule_type'=>2, 'rule_answer'=>$ruleAnswer, 'rule_score'=>$ruleScore, 'rule_score_half'=>$val ); } } $json['disabled']=0; $json['paper']=0; $json['line']=0; $json['anyway']=0; $json['is_display']=$isDisplay; $json['totals']=$totals; $json['total_score']=$selectTopicGroupScore; $json['scores']=$selectTopicGroupScore; if(!isset($json['subjectId'])){ $json['subjectId']=$subject_id; } $json['new_items']=$_new_items; $json['new_rules']=$tplRules; $json['reviewer']=''; $json['is_new_marking']=1; $json['required']=$required_count; $json['times']=0; $json['branch']=0; if ($subject_id == 8) { $json['isNewEnglish']=1; } return $json; } private function get_topic_folder() { $data = $this->sConn->createCommand("select * from topic_folder where is_system = 1")->queryRow(); if($data) { return $data; } return false; } //保存为第三方在线答题卡模板 public function actionSaveTemplateByOnline(){ $name = Req::post("title"); $layout = isset($_POST['layout'])?$_POST['layout']:''; $select_card_type = isset($_POST['select_card_type'])?$_POST['select_card_type']:'1'; $total_score = isset($_POST['total_score'])?$_POST['total_score']:'0'; $total_topics = isset($_POST['total_topics'])?$_POST['total_topics']:'0'; $tpl_data = isset($_POST['tpl_data'])?$_POST['tpl_data']:''; $error['success']=0; // $count=$this->sConn->createCommand("select count(*) as count from third_tpl where subject_id='{$this->subjectId}'")->queryRow(); // if($count && $count['count']>9){ // $error['message'] = '同一学科最多保存10个模板'; // echo json_encode($error);exit(); // } // if($tpl_data){ // // $positionTxt="upload/ThirdSheet/" .$name.time().'.txt' ; // file_put_contents($positionTxt, $tpl_data); // $ucloud = new HuaweiCloud(); // $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ; // $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt); // // if ($uploadInfo['status'] == 0) { // @unlink($positionTxt); // $error['success']=0; // $error['message'] = 'Position文件上传失败!'; // echo json_encode($error);exit(); // }else{ // @unlink($positionTxt); // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); // $ucloudTxtUrl=$uploadInfo['url']; // } // // } $rs = $this->sConn->createCommand()->insert('third_tpl',array( 'title' => $name, 'subject_id' => $this->subjectId, 'school_card_status' => 0, 'school_card_length' => 0, 'layout' => $layout, 'select_card_type' => $select_card_type, 'tpl_data' => $tpl_data, 'total_score' => $total_score, 'total_topics' => $total_topics, 'create_time' => time() )); if($rs){ $error['success']=1; $error['message'] = '保存成功'; echo json_encode($error);exit(); } echo json_encode($error);exit(); } //读取模板列表 public function actionTplList(){ $criteria = new CDbCriteria(); $criteria->addCondition('subject_id=:subject_id'); $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id']; $criteria->addCondition('school_card_length=0'); $criteria->order = 'third_tpl_id desc'; $thisTpls = SThirdTplModel::model()->findAll($criteria); $list=array(); if($thisTpls) { foreach ($thisTpls as $val){ $jsonData=''; $tplData=$val->tpl_data; if(strpos($tplData,'http://')!==false || strpos($tplData,'https://')!==false){ if(strpos($tplData,'zxhx.cn-bj.ufileos.com')!==false){ $tplData=str_replace('zxhx.cn-bj.ufileos.com','zxhx-u-1302712961.cos.ap-beijing.myqcloud.com',$tplData); } $jsonData=fileGetContents($tplData); }else{ $jsonData=$val->tpl_data; } $jsonDataArr=json_decode($jsonData,true); if(isset($jsonDataArr['position'])){ $list[]=array( 'third_tpl_id'=>$val->third_tpl_id, 'title'=>$val->title, 'total_score'=>$val->total_score, 'total_topics'=>$val->total_topics, 'tpl_data'=>jsonEncode($jsonDataArr['position']) ); }else{ $list[]=array( 'third_tpl_id'=>$val->third_tpl_id, 'title'=>$val->title, 'total_score'=>$val->total_score, 'total_topics'=>$val->total_topics, 'tpl_data'=>$jsonData ); } } $data['thisTpls'] = $list; } $data['success']=1; exit(json_encode($data)); } //删除模板 public function actionDelTpl(){ $third_tpl_id = Req::post("third_tpl_id"); if($third_tpl_id>0){ $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id)); if($thirdTpl){ echo json_encode(array('success'=>1,'msg'=>'1'));exit; } } echo json_encode(array('success'=>0,'msg'=>'失败'));exit; } //读取考试答题卡 public function actionGetTemplateByExamGroupId(){ $exam_group_id = Req::post("examGroupId"); $isHide = Req::post("isHide"); if(!$exam_group_id){ $data['success']=0; $data['msg']='考试id不正确'; exit(json_encode($data)); } //验证是否有在线答题卡 $thirdAnswerSheet=$this->sConn->createCommand("select `name`,`file_path`,`position`,`online_card_pdf`,`online_card`,`is_qrcode_online`,`sheet_answer`,`sheet_score`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`multiplex_id`,`create_time`,`update_time` from third_answer_sheet where exam_group_id='".$exam_group_id."' and online_card=1")->queryRow(); $data['success']=1; $data['data']=array(); //判断全学科 $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$exam_group_id."'")->queryRow(); $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryAll(); //判断全学科白名單 $data['new_answer_sheet_subject']=0; if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){ $rs = http('/cms/api/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi'); $rs=json_decode($rs,true); if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ $data['new_answer_sheet_subject']=1; } } if($thirdAnswerSheet){ $nowMultiplexId=$thirdAnswerSheet['multiplex_id']; //判断是否有复用答题卡记录 if(!$nowMultiplexId){ $mult=$this->sConn->createCommand("select multiplex_id from online_card_multiplex where exam_group_id='{$exam_group_id}' and is_copy=0")->queryRow(); if(!$mult){ //旧数据没有复用记录,需要补一条记录 $onlineCardMultiModel=new SOnlineCardMultiplex(); $onlineCardMultiModel->exam_group_id=$exam_group_id; $onlineCardMultiModel->name=$thirdAnswerSheet['name']; $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path']; $onlineCardMultiModel->position=$thirdAnswerSheet['position']; $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf']; $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online']; $onlineCardMultiModel->is_download=0; $onlineCardMultiModel->is_copy=0; $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time']; $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time']; if($onlineCardMultiModel->save()){ $nowMultiplexId=$onlineCardMultiModel->multiplex_id; $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$exam_group_id}'")->execute(); } }else{ $nowMultiplexId=$mult['multiplex_id']; $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$mult['multiplex_id']}' where exam_group_id='{$exam_group_id}'")->execute(); } } // if($thirdAnswerSheet['position']){ // if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){ // $thirdAnswerSheet['position']=fileGetContents($thirdAnswerSheet['position']); // } // } if(!$examData){ $data['msg']='考试id不正确'; exit(json_encode($data)); } $examIds=array(); foreach ($examData as $datum){ $examIds[]=$datum['exam_id']; } //判断是否有修改的判分规则 $tplData=json_decode($examData[0]['tpl_data'],true); $questions=array(); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $val){ $alias=isset($val['alias'])?$val['alias']:$val['id']; $temp=array( 'questionNum'=>(int)$val['id'], 'questionTypeId'=>(int)$val['topic_type'], 'fullScore'=>(string)$val['score'], 'alias'=>$alias, ); if(isset($tplData['new_rules']) && isset($tplData['new_rules'][$val['id']])){ $temp['ruleScoreHalf']=$tplData['new_rules'][$val['id']]['rule_score_half']; } $questions[]=$temp; } } $thirdAnswerSheet['questions']=$questions; $thirdAnswerSheet['is_third']=$examGroup['is_third']; if($examGroup['qxk_paper_id']){ if(isset($tplData['item_collect'])){ $itemCollect=array(); //读取大题型 $allSubjectTopicType=$this->schoolManager->getAllSubjectTopicType($examData[0]['subject_id']); $allTopicTypeArr=array(); if($allSubjectTopicType){ foreach ($allSubjectTopicType as $item){ $allTopicTypeArr[$item['topic_type_id']]=$item['topic_type_name']; } } //读取基础题型 $allBasicTopicTypeArr=array(); $allSubjectBasicTopicType=$this->schoolManager->getAllSubjectBasicType(); if($allSubjectBasicTopicType){ foreach ($allSubjectBasicTopicType as $item){ $allBasicTopicTypeArr[$item['btt_id']]=$item['btt_name']; } } foreach ($tplData['item_collect'] as $key => $datum){ $topicTypeName=''; $topicBasicName=''; $topicCount=0; if($datum['topicBasicType']==17){ $topicTypeName='选做题'; $topicBasicName='选做'; $topicCount='2选1'; //奇葩的需求 }else{ if(isset($allTopicTypeArr[$datum['topicType']])){ $topicTypeName=$allTopicTypeArr[$datum['topicType']]; } if(isset($allBasicTopicTypeArr[$datum['topicBasicType']])){ $topicBasicName=$allBasicTopicTypeArr[$datum['topicBasicType']]; } $topicCount=$datum['topicCount']; } $itemCollect[]=array( "topic_type_name"=>$topicTypeName, 'topic_basic_name'=>$topicBasicName, 'topic_count'=>$topicCount, 'total_score'=>$datum['totalScore'] ); } $data['item_collect']=$itemCollect; } } $where[]="exam_group_id={$exam_group_id}"; if($isHide){ $where[]="is_hide=1"; }else{ $where[]="is_hide=0"; } $isDownload=0; $multi=$this->sConn->createCommand("select multiplex_id,exam_group_id,`name`,file_path,`position`,online_card_pdf,is_qrcode_online,is_download,is_copy,update_time from online_card_multiplex where ".implode(' and ',$where))->queryAll(); if($multi){ foreach ($multi as $key =>$value){ if($nowMultiplexId==$value['multiplex_id']){ $multi[$key]['active']=1; }else{ $multi[$key]['active']=0; } if($value['is_download']==1){ $isDownload=1; } } } $data['multiplex']=$multi; //查询是否有下载记录 if(!$isDownload){ $checkDownload=$this->sConn->createCommand("select is_download from online_card_multiplex where exam_group_id='".$exam_group_id."' and is_download=1")->queryRow(); if($checkDownload){ $isDownload=1; } } //判断是否上传试卷 if(in_array($this->subjectId,$this->mathSubjectId) || $this->subjectId==12){ $checkPaperUpload=$this->sConn->createCommand("select * from topic_word where exam_group_id='".$exam_group_id."' and status>0")->queryRow(); }else{ $checkPaperUpload=$this->sConn->createCommand("select * from third_multi_template where exam_group_id='".$exam_group_id."' and (topic_upload=1 or answer_upload=1)")->queryRow(); } if($checkPaperUpload){ $thirdAnswerSheet['paper_uploaded']=1; }else{ $thirdAnswerSheet['paper_uploaded']=0; } //查询协助状态 $thirdAnswerSheet['assist_status']=0; $assist=$this->conn->createCommand("select status from abnormal_template where exam_group_id={$exam_group_id}")->queryRow(); if($assist){ $thirdAnswerSheet['assist_status']=$assist['status']; } $data['success']=1; $thirdAnswerSheet['is_download']=$isDownload; $data['data']=$thirdAnswerSheet; }else{ $data['data']=null; } exit(json_encode($data)); } //切换模板,清空原模板数据 public function actionClearExamTpl(){ $exam_group_id = Req::post("examGroupId"); $data['success']=0; if(!$exam_group_id){ $data['msg']='参数错误'; exit(json_encode($data)); } $exam=$this->sConn->createCommand("select exam_id,status,tpl_data from exam where exam_group_id='{$exam_group_id}'")->queryAll(); if(!$exam){ $data['msg']='考试id不正确'; exit(json_encode($data)); } if($exam['status']==1 || $exam['status']==4){ $data['msg']='已上传成绩,不能切换答题卡'; exit(json_encode($data)); } $examIds=array(); $paperIds=array(); $topicIds=array(); $tplData=array(); foreach ($exam as $val){ $examIds[]=$val['exam_id']; if(!$tplData){ $tplData=json_decode($val['tpl_data'],true); } } $paperData=$this->sConn->createCommand("select paper_id from paper where exam_id in(".implode(',',$examIds).")")->queryAll(); if(!$paperData){ $data['msg']='试卷不存在'; exit(json_encode($data)); } foreach ($paperData as $val){ $paperIds[]=$val['paper_id']; } $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id='".$paperIds[0]."'")->queryAll(); foreach ($paperTopic as $val){ $topicIds[]=$val['topic_id']; } $transaction = $this->sConn->beginTransaction(); try{ if(isset($tplData['items'])){ unset($tplData['items']); } if(isset($tplData['new_items'])){ unset($tplData['new_items']); } if(isset($tplData['new_rules'])){ unset($tplData['new_rules']); } $tplData['scores']=0; $tplData['times']=0; $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topicIds).")" )->execute(); $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topicIds).")" )->execute(); $this->sConn->createCommand("delete from topic_use where topic_id in (".implode(',',$topicIds).")" )->execute(); $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topicIds).")" )->execute(); $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute(); $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id )->execute(); $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$exam_group_id )->execute(); $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =".$exam_group_id )->execute(); $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute(); $this->sConn->createCommand("update exam set tpl_data ='".jsonEncode($tplData)."' where exam_group_id = ".$exam_group_id )->execute(); $this->sConn->createCommand("update paper set score = 0,topics_count = 0,is_labelled = 0 where exam_id in (".implode(',',$examIds).")")->execute(); $transaction->commit(); echo json_encode(array('success'=>1));exit; }catch(Exception $e) { $transaction->rollBack(); echo json_encode(array('success'=>0));exit; } } //修改第三方考试信息 public function actionAjaxModifyThirdExam(){ $exam_group_id = Req::post("examGroupId"); $type=Req::post('type'); $name=Req::post('examName'); $examDate=Req::post('examDate'); $paperType=Req::post('paperType'); $relationAnswerCard=false; $data['success']=0; if(!matchStrChar($name)){ $data['msg']='考试名称不能包含特殊字符!'; exit(json_encode($data)); } if(Yii::app()->params['section']==0){ $paperType='1050'; } $exam_group_data=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $transaction = $this->sConn->beginTransaction(); $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_data) { $data['msg']='非法试卷!'; exit(json_encode($data)); } @$tplData=json_decode($exam_data['tpl_data'],true); if(!$tplData){ $data['msg']='非法试卷!'; exit(json_encode($data)); } $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow(); if(!$paperData){ $data['msg']='试卷不存在'; exit(json_encode($data)); } try{ $tplData['examDate']=$examDate; $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'"; $this->sConn->createCommand($examSql)->execute(); if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){ updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库 } $transaction->commit(); $data['success']=1; $data['msg']='编辑成功'; exit(json_encode($data)); }catch(Exception $e){ $transaction->rollBack(); $data['msg']='编辑失败'; exit(json_encode($data)); } $data['msg']='编辑失败'; exit(json_encode($data)); } //第三方创建在线答题卡需要准考证位数,所以需要确定年级 public function actionGetCardStatusByGrade(){ $grade=(int)Req::post("grade"); if(!in_array($grade,array(1,2,3))){ $data=array( 'success'=>0, 'msg'=>'年级不正确', ); exit(json_encode($data)); } $sql = "select card_length,card_status FROM grade where id='{$grade}'"; $cardData = $this->sConn->createCommand($sql)->queryRow(); if($cardData['card_status']==0){ $cardData['card_length'] = 8; if($this->schoolId >999){ $cardData['card_length'] = 9; } } $data=array( 'success'=>1, 'data'=>$cardData, ); exit(json_encode($data)); } //考试扫描异常处理状态查看 public function actionGetTaskDetail(){ $examGroupId = Req::get('exam_group_id'); $grade = Req::get('grade'); $branch = Req::get('branch'); $taskModel=new AScanTask(); $task=$taskModel->getTaskByExamGroupId($examGroupId); if($task){ $task=$task->attributes; if($task['operator']){ $user=AssistUser::model()->findByPk($task['operator']); $task['user']=$user->real_name; }else{ $task['user']='--'; } //答题卡任务耗时 if($task['scan_task_apply_time']){ if($task['scan_task']>2){ if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){ $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']); }else{ $task['AstConsuming']='--'; } }elseif($task['scan_task']==2){ if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){ $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']); }else{ $task['AstConsuming']='--'; } } }else{ $task['AstConsuming']='--'; } } //读取扫描数量 $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1); $task['count']=$count; $data['task']=$task; $data['exam_group_id']=$examGroupId; $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $data['version_number']=$version_number; $data['grade']=$grade; $data['branch']=$branch; $this->render('scan_detail',$data); } //关联第三方在线答题卡 public function actionInsertThirdSheet(){ $error = array(); $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:''; $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id $text=$_POST["timu"]; //处理答题卡数据 $relationAnswerCard=true; $name = Req::post("title"); $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:''; $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:''; $post = json_decode($text,true); $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0; $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0; $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0; $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0; $DuoXuanTi = isset($post["DuoXuanTi"]) ? $post["DuoXuanTi"] : 0; $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : ''; $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分 $zhunkaozhen_length = isset($_POST['zhunkaozhen_length']) ? $_POST['zhunkaozhen_length'] : 0; $isUploadScore=false; //是否已上传成绩 $isLabelled=false; $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(!$exam_data) { echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit; } $teacherId = $exam_data[0]['teacher_id']; $subject_id = $exam_data[0]['subject_id']; @$tplData=json_decode($exam_data[0]['tpl_data'],true); if(!$tplData){ echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit; } if ($zhunkaozhen_length) { if ($exam_data[0]['school_card_status'] == 1) { if ($zhunkaozhen_length < $exam_data[0]['school_card_length']) { echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用学校准考证号,长度为'.$exam_data[0]['school_card_length']));exit; } } else { if ($zhunkaozhen_length < 8 && $this->schoolId < 999) { echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为8'));exit; } if ($zhunkaozhen_length < 9 && ($this->schoolId > 999 && $this->schoolId < 9999)) { echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为9'));exit; } } } if(!$text || !$name || !$sheet_answer || !$sheet_score){ $error['message'] = '题目参数错误'; echo json_encode($error);exit(); } if(!$positionJson){ $error['message'] = '定位信息异常'; echo json_encode($error);exit(); } if($error){ echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit; }else{ $time = time(); $paper_data = $this->schoolManager->getPaperByExamId($exam_data[0]['exam_id']); if ($paper_data) { /** * 验证已上传成绩,无法再次编辑 */ if ($exam_data) { foreach ($exam_data as $v) { $exam_ids[$v['exam_id']] = $v['exam_id']; } if ($exam_ids) { $student_paper_feed=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$exam_ids).") and is_feedback=1 and is_del=0 ")->queryRow(); if ($student_paper_feed) { $isUploadScore = true; } } } //判断是否发送标注 if ($paper_data['is_labelled'] != 0 ) { $isLabelled = true; } } //验证是否已下载,是否是复用的答题卡 if($multiplexId){ $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow(); if($checkMulti['is_download']){ $error['success']=0; $error['message'] = '上传失败,答题卡已经下载!'; echo json_encode($error);exit(); } if($checkMulti['is_copy']){ //只保存文件信息 $this->saveMultiplex(); } } $sheet_score_array = json_decode($sheet_score, 1); if (!$sheet_score_array) { $error['success']=0; $error['message'] = '上传失败,未设置分数!'; echo json_encode($error);exit(); } $score_num = count($sheet_score_array); if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi+$DuoXuanTi )) { $error['success']=0; $error['message'] = '上传失败,设置分数或设置题号有误!'; echo json_encode($error);exit(); } $items = array(); $xu = 0; $t = 0; $z = 0; $x = 0; $duo = 0; foreach ($sheet_score_array as $k => $v) { if ($KeGuanTi >= $k) { $items[1]['total'] = $KeGuanTi; $items[1]['perScores'][$xu] = $v; for ($i = 0; $i < $KeGuanTi; $i++) { $items[1]['no'][$i + 1] = $i + 1; } $xu++; } elseif ($DuoXuanTi > 0 && $KeGuanTi < $k && $k <= ($KeGuanTi + $DuoXuanTi)) { $items[2]['total'] = $DuoXuanTi; $items[2]['perScores'][$duo] = $v; for ($i = $KeGuanTi; $i < ($DuoXuanTi + $KeGuanTi); $i++) { $items[2]['no'][$i + 1] = $i + 1; } $duo++; } elseif ($TianKongTi > 0 && ($KeGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $DuoXuanTi)) { $items[5]['total'] = $TianKongTi; $items[5]['perScores'][$t] = $v; for ($i = ($KeGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i++) { $items[5]['no'][$i + 1] = $i + 1; } $t++; } elseif ($ZhuGuanTi > 0 && ($KeGuanTi + $TianKongTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi)) { $items[7]['total'] = $ZhuGuanTi; $items[7]['perScores'][$z] = $v; for ($i = ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i++) { $items[7]['no'][$i + 1] = $i + 1; } $z++; } elseif ($XuanZuoTi > 0 && ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi)) { $items[17]['total'] = $XuanZuoTi; $items[17]['required'] = 1; $items[17]['score'] = $v; $items[17]['perScores'][$x] = $v; $_select_topic_scroe = $v; for ($i = ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi); $i++) { $items[17]['no'][$i + 1] = $i + 1; } $x++; } } if (!$items) { echo json_encode(array('success'=>0,'message'=>'上传失败,无题'));exit; } $select_info = json_decode($select_info, 1); if(!isset($select_info['content']) || !$select_info['content']){ echo json_encode(array('success'=>0,'message'=>'上传失败,题目数据不能为空'));exit; } //检测id是否重复 $checkRepeatId=array(); foreach ($select_info['content'] as $value){ if(!isset($checkRepeatId[$value['questionNum']])){ $checkRepeatId[$value['questionNum']]=$value['questionNum']; }else{ echo json_encode(array('success'=>0,'message'=>'上传失败,题目序号重复'.$value['questionNum']));exit; } } //上传答题卡相关文件 $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl); $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData); $json['items']=$items; $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if($error){ echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit; } $transaction = $this->sConn->beginTransaction(); try{ $topic_ids=array(); $paperIds=$this->schoolManager->getPaperIdsByExamIds($exam_ids); //判断是否已关联答题卡 //判断原答题卡 $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow(); if($thirdAnswerSheet){ $oldSheetAnswer = $thirdAnswerSheet['sheet_answer']; $oldSheetScore = $thirdAnswerSheet['sheet_score']; if($isUploadScore || $isLabelled){ //判断答案是否改变 if (strcmp($oldSheetAnswer, $sheet_answer) != false) { echo json_encode(array('success'=>0,'message'=>'上传失败,已上传成绩,不能修改试题答案'));exit; } if (strcmp($oldSheetScore, $sheet_score) != false) { echo json_encode(array('success'=>0,'message'=>'传失败,已上传成绩,不能修改试题分数'));exit; } if($multiplexId){ $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); } $insert="replace into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`,`select_info`) "; $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$files['positionUrl']."',1,'".$files['ucloudPdfUrl']."','0','".json_encode($select_info)."') "; $this->sConn->createCommand($insert)->execute(); $transaction->commit(); echo json_encode(array('success'=>1,'message'=>'创建成功'));exit; } $paperTopic=$this->sConn->createCommand("select topic_id,type from paper_topic_relation where paper_id ='{$paperIds[0]}'")->queryAll(); foreach ($paperTopic as $item){ $topic_ids[]=$item['topic_id']; } //删除数据 $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute(); $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute(); $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$examGroupId )->execute();; $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$examGroupId )->execute();; $this->sConn->createCommand("delete from topic_word where exam_group_id =".$examGroupId )->execute(); } $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'); $topic_data = $this->get_topic_folder(); foreach($select_info['content'] as $k=>$v) { if(isset($v['scoreColumnHtml'])){ unset($select_info['content'][$k]['scoreColumnHtml']); } $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0; $zsytkTopicType=$_topic_type; if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7; $this->sConn->createCommand()->insert('topic', array( 'topic_type' =>$zsytkTopicType , 'topic_title' => '', 'folder_id' => $topic_data['folder_id'], 'subject_id' => $subject_id, 'is_delete' =>0, 'creator_id' => $teacherId, 'updater_id' => $teacherId, 'is_word_topic'=>1, 'create_time' => time(), 'update_time' => time(), )); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $topic_id=$last_insert_id['last_insert_id()']; $this->sConn->createCommand()->insert('topic_item', array( 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_title' => '' )); //增加topic_option if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0)) { $answers = explode(',',$v['answer']); if($answers && isset($answers[0]) && !empty($answers[0])){ $options = array_chunk($option,$v['optionCount']); if(isset($options[0]) && !empty($options[0])){ foreach($options[0] as $item=>$val) { $this->sConn->createCommand()->insert('topic_item_option', array( 'topic_id' => $topic_id, 'option_id' => 0, 'option_content' => '', 'option_correct' => in_array($val,$answers)?1:0, 'option_score' => 0, 'sort_order' => $item, )); } } } } $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $topic_id, 'mode' => 1, 'teacher_id' => $teacherId, 'paper_id' =>$paperIds[0] )); $questionCount = 0; $questionScoreStr = ''; if(isset($v['scores']) && !empty($v['scores'])){ $scoresArr = explode(',',$v['scores']); if($scoresArr){ $questionCount = count($scoresArr); $questionScoreStr = $v['scores']; } } foreach($paperIds as $p) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $p, 'topic_id' => $topic_id, 'no' => $v['questionNum'], 'order' => $v['questionNum'], 'mode' => 1, 'type' => $_topic_type, 'score' =>$v['fullScore'], 'question_count' => $questionCount, 'question_score_str' => $questionScoreStr )); } if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2))) { if(isset($json['new_items'][$k]['alias'])){ $topicNo=$json['new_items'][$k]['alias']; }elseif(isset($v['alias'])){ $topicNo=$v['alias']; } if(!$topicNo) $topicNo=$v['questionNum']; //判断自动批阅字段 $autoType=0; if($subject_id==8){ if(in_array($v['marktype'],array(13,16,17)) && !$questionCount){ $autoType=1; }elseif($_topic_type==5){ $autoType=2; } } $this->sConn->createCommand()->insert('marking_topic', array( 'exam_group_id' => $examGroupId, 'topic_id' => $topic_id, 'topic_type' => $_topic_type, 'topic_index' =>$v['questionNum'], 'topic_no' =>$topicNo, 'topic_score' =>$v['fullScore'], 'auto_type'=>$autoType )); } } if(!$multiplexId){ //没有复用记录,初始化一条记录 $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`) values"; $insertSql.="('".$examGroupId."','".$name."','".$files['ucloudZipUrl']."','".$files['positionUrl']."','".$files['ucloudPdfUrl']."','".time()."','".time()."')"; $this->sConn->createCommand($insertSql)->execute(); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $multiplexId=$last_insert_id['last_insert_id()']; }else { //更新复用记录 $updateSql = "update online_card_multiplex set `file_path`='{$files['ucloudZipUrl']}',`position`='{$files['positionUrl']}',`online_card_pdf`='{$files['ucloudPdfUrl']}',update_time='" . time() . "' where multiplex_id='{$multiplexId}'"; $this->sConn->createCommand($updateSql)->execute(); } $total = $json['total_score']; $topics_count = count($select_info['content']); $tpl_data=jsonEncode($json); $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$examGroupId )->execute(); $this->sConn->createCommand("update topic_word set status =0,word_path='' where exam_group_id = ".$examGroupId )->execute(); $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$examGroupId )->execute(); $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute(); $insert="replace into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`,`select_info`,`multiplex_id`) "; $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$files['positionUrl']."',1,'".$files['ucloudPdfUrl']."','0','".jsonEncode($select_info)."','".$multiplexId."') "; $this->sConn->createCommand($insert)->execute(); $OnlineCardSaveLogModel=new SOnlineCardSaveLog(); $OnlineCardSaveLogModel->exam_group_id=$examGroupId; $OnlineCardSaveLogModel->file_path=$files['ucloudZipUrl']; $OnlineCardSaveLogModel->online_card_pdf=$files['ucloudPdfUrl']; $OnlineCardSaveLogModel->position=$files['positionUrl']; $OnlineCardSaveLogModel->create_time=time(); $OnlineCardSaveLogModel->save(); $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); echo json_encode(array('success'=>0,'message'=>'创建失败'));exit; } } if(!$error){ echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId,'multiplex_id'=>$multiplexId));exit; }else{ echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit; } } //创建考试并下一步ajax public function actionCreatethirdForNext(){ $error = array(); $tplData = array(); $semesterId = $this->semesterId; $examName = Req::post("examName"); $type = (int)Req::post("type"); $classIds = Req::post("classIds"); $markType = Req::post("markType"); $teacherId = Req::post("teacherId"); $subjectId = Req::post("subjectId"); $textbookId = Req::post("textbookId"); $examDate = Req::post("examDate"); $tpl_index = (int)Req::post("tpl_index"); $qxkPaperId = (int)Req::post("isQxk"); if(Yii::app()->params['section']==0){ $tpl_index='1050'; } if(empty($classIds)){ $error[] = '请指定考试班级'; }else{ $classIds = explode(',',$classIds); } if(empty($examName)){ $error[] = '请设置考试名称'; } if ($type <= 0 || $type > 9) { $error[] = '考试类型错误'; } if(empty($subjectId)){ $error[] = '请选择题源'; } if(!matchStrChar($examName)){ $error[] = '考试名称不能包含特殊字符!'; } if(empty($teacherId)){ $error[] = '请指定阅卷老师'; } if(empty($examDate)){ $error[] = '请指定考试时间'; } if(empty($tpl_index)){ $error[] = '请指定类型'; } if($qxkPaperId && in_array($subjectId,$this->mathSubjectId)){ $subjectId=3; } if($error){ echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit; }else{ $teacherName = Teacher ::model()->getTeacherName($teacherId); if($teacherName){ $tplData['author'] = $teacherName; $tplData['subjectId'] = $subjectId; $tplData['textbookId'] = $textbookId; $tplData['examDate'] = $examDate; } $time = time(); $transaction = $this->sConn->beginTransaction(); try{ $newExamGroupId=getUniqueId($this->schoolId); if($markType ==4){ $markStatus=1; $status=1; }else{ $markStatus=0; $status=0; } $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`,`qxk_paper_id`) " . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")"; $this->sConn->createCommand($sql)->execute(); foreach($classIds as $classId){ if(!$classId) continue; $newExamId = getUniqueId($this->schoolId); $sql = "select g.card_length,g.card_status,c.class_type 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; } } $class_type=$cardData['class_type']; $this->sConn->createCommand()->insert('exam',array( 'exam_id' => $newExamId, 'exam_group_id' => $newExamGroupId, 'name' => $examName, 'semester_id' => $this->semesterId, 'teacher_id' => $teacherId, 'subject_id' => $subjectId, 'module_id' => 0, 'type' => $type, 'school_card_status' => $cardData['card_status'], 'school_card_length' => $cardData['card_length'], 'status' => 2, 'week_num' => 0, 'create_type' => 0, 'create_time' => $time, 'update_time' => $time, 'tpl_data' => jsonEncode($tplData), 'tpl_index' => $tpl_index, 'class_id' => $classId, 'method_ids' => '', )); // $newPaperId = $this->UUID_SHORT(); $newPaperId= getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => 1, 'exam_id' => $newExamId, 'paper_name' => '', 'paper_layer' => '', 'difficulty' => 0, 'topics_count' => 0, 'score' => 0, 'add_time' => $time, 'update_time' => $time, 'method_ids' => '', 'is_labelled' => 0, )); $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); $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) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), 'class_type' =>$class_type )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time' =>$time )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit; } } if(!$error){ echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'examGroupId'=>$newExamGroupId));exit; } } public function actionGetOnlinePdf(){ $semesterId = $this->semesterId; $width = Req::post("width"); $height = Req::post("height"); $pdfHtml = Req::post("pdfHtml"); $examGroupId = Req::post("examGroupId"); if(!$width || !$height){ $error['success']=0; $error['message'] = '缺少纸张大小参数'; $error['data'] = ''; echo json_encode($error);exit(); } if(!$pdfHtml){ $error['success']=0; $error['message'] = '缺少模板数据'; $error['data'] = ''; echo json_encode($error);exit(); } if(!$examGroupId){ $error['success']=0; $error['message'] = '缺少考试数据'; $error['data'] = ''; echo json_encode($error);exit(); } $sendData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'savedInfoUrl'=>$pdfHtml, 'semesterId'=>$semesterId, 'width'=>$width, 'height'=>$height ); $return=sendDataToKafka('zsyas2-online-card-alone-notify',$sendData); $ucloudPdfUrl=''; if($return){ $maxTimes=25; $server = Yii::app()->params["phpServiceRedis"]["servers"]; $redis = new Redis(); $redis->connect($server["host"], $server["port"]); if(isset($server['password'])){ $redis->auth($server['password']); } $redis->select($server['database']); for($i=0;$i<$maxTimes;$i++){ $redis_get_pdf_status =$redis->get('php_service:exam_group_online_card:'.$examGroupId); if($redis_get_pdf_status ){ $ucloudPdfUrl=$redis_get_pdf_status; $redis->set('php_service:exam_group_online_card:'.$examGroupId,''); break; } sleep(1); } } if($ucloudPdfUrl){ $error['success']=1; $error['message'] = '保存成功!'; $error['data'] = $ucloudPdfUrl; }else{ $error['success']=0; $error['message'] = '生成失败'; $error['data'] = ''; } echo json_encode($error);exit(); } public function actionDownload() { $url = Req::get('url'); $title = Req::get('title'); if (empty($url) ) { return false; } if(!$title) $title=time().'temp'; $ext=substr($url,strrpos($url,'.')+1); $path='upload/tmpDir/downloadTempFiled/'; if (!file_exists($path)) { mkdir($path, 0777, true); } $pathName=$path.$title.'.'.$ext; // 获取远程文件资源 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); $tempFile = curl_exec($ch); curl_close($ch); // 保存文件 $fp = @fopen($pathName, "w"); fwrite($fp, $tempFile); fclose($fp); header('content-type:application/octet-stream'); header('content-disposition:attachment; filename='.get_basename($pathName)); header('content-length:'.filesize($pathName)); readfile($pathName); } //在线答题卡旧版第二步页面 public function actionThirdCardSecond(){ $examGroupId = Req::get('examGroupId'); $this->render('third_card_second',array('examGroupId'=>$examGroupId)); } //复用在线答题卡 public function actionMultiplex(){ $multiplexId=Req::post("multiplexId"); //被复用的记录ID $name=Req::post("name"); //新答题卡名称 $result=array(); $result['status']=0; if(!$multiplexId){ $result['msg']='答题卡ID不能为空'; exit(json_encode($result)); } if(!$name){ $result['msg']='答题卡名称不能为空'; exit(json_encode($result)); } $check=$this->sConn->createCommand("select `multiplex_id`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_download`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow(); if(!$check){ $result['msg']='答题卡模板不存在'; exit(json_encode($result)); } if(!$check['is_download']){ $result['msg']='答题卡尚未下载,如需修改请直接编辑答题卡'; exit(json_encode($result)); } $onlineCardMultiModel = new SOnlineCardMultiplex(); $onlineCardMultiModel->exam_group_id = $check['exam_group_id']; $onlineCardMultiModel->name = $name; $onlineCardMultiModel->file_path = $check['file_path']; $onlineCardMultiModel->position = $check['position']; $onlineCardMultiModel->online_card_pdf = $check['online_card_pdf']; $onlineCardMultiModel->is_qrcode_online = $check['is_qrcode_online']; $onlineCardMultiModel->is_download = 0; $onlineCardMultiModel->is_copy = 1; $onlineCardMultiModel->create_time = time(); $onlineCardMultiModel->update_time = time(); if ($onlineCardMultiModel->save()) { $result['status'] = 1; $result['msg'] = '复用成功'; $result['data'] = $onlineCardMultiModel->multiplex_id; } exit(json_encode($result)); } //版本列表切换在线答题卡 public function actionChangeCard(){ $multiplexId=Req::post("multiplexId"); //记录ID $result=array(); $result['status']=0; $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow(); if(!$check){ $result['msg']='答题卡模板不存在'; exit(json_encode($result)); } if($this->sConn->createCommand("update third_answer_sheet set `multiplex_id`='{$multiplexId}',`name`='{$check['name']}',`file_path`='{$check['file_path']}',`position`='{$check['position']}',`online_card_pdf`='{$check['online_card_pdf']}',`is_qrcode_online`='{$check['is_qrcode_online']}' where exam_group_id='{$check['exam_group_id']}'")->execute()){ $result['status']=1; $result['msg']='切换成功'; $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='".$check['exam_group_id']."'")->queryAll(); $examIds=array(); foreach ($exam as $item){ $examIds[]=$item['exam_id']; } $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).")")->execute(); $this->sConn->createCommand("delete from exam_process where exam_group_id='".$check['exam_group_id']."' and action_type in(9,13,14)")->execute(); } exit(json_encode($result)); } //下载标记 public function actionDownloadStatus(){ $multiplexId=Req::post("multiplexId"); //记录ID $result=array(); $result['status']=0; if(!$multiplexId) { $result['msg']='答题卡Id不能为空'; exit(json_encode($result)); } $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow(); if(!$check){ $result['msg']='答题卡模板不存在'; exit(json_encode($result)); } $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); $this->schoolManager->saveExamProcess($check['exam_group_id'],9,time()); $result['status']=1; $result['msg']='更新成功'; exit(json_encode($result)); } //隐藏答题卡 public function actionHideAnswerCard(){ $multiplexId=Req::post("multiplexId"); //记录ID $isHide=Req::post("isHide"); //记录ID if(!$isHide) $isHide=0; $result=array(); $result['status']=0; if(!$multiplexId) { $result['msg']='答题卡Id不能为空'; exit(json_encode($result)); } $this->sConn->createCommand("update online_card_multiplex set is_hide={$isHide} where multiplex_id='{$multiplexId}'")->execute(); $result['status']=1; $result['msg']='更新成功'; exit(json_encode($result)); } //复用的答题卡编辑后保存 private function saveMultiplex(){ $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:''; $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; //上传答题卡相关文件 $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl); $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow(); if($thirdAnswer['multiplex_id']==$multiplexId){ $this->sConn->createCommand("update third_answer_sheet set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); } echo json_encode(array('status'=>1,'msg'=>'创建成功','data'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId));exit; } //读取在线答题卡复用内容 public function actionGetMultiplex(){ $multiplexId=Req::post("multiplexId"); //记录ID $result=array(); $result['status']=0; $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_hide`,`is_copy`,`is_download`,`create_time`,`update_time`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow(); if(!$check){ $result['msg']='答题卡模板不存在'; exit(json_encode($result)); } //判断全学科 $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$check['exam_group_id']."'")->queryRow(); $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$check['exam_group_id']}'")->queryAll(); //判断全学科白名單 $check['new_answer_sheet_subject']=0; if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){ $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi'); $rs=json_decode($rs,true); if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ $check['new_answer_sheet_subject']=1; } } if($check['position']){ if(strpos($check['position'],'http://')!==false || strpos($check['position'],'https://')!==false){ $check['position']=fileGetContents($check['position']); } } $result['data']=$check; exit(json_encode($result)); } //加载考试完成考试复用试卷 最近30场完成解析的考试 public function actionLoadCopyPaper(){ $grade=Req::post('grade'); $examGroupId=Req::post('examGroupId'); $condition=array(); $subject=$this->subjectId; $condition[]='eg.is_third=1'; // $condition[]='e.status=1'; $condition[]='tw.status=2'; $condition[]="eg.exam_group_id<>'".$examGroupId."'"; if($subject==3){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[]="e.subject_id ='".$subject."'"; } if($grade){ $condition[]="c.grade='".$grade."'"; } $sql="SELECT eg.exam_group_id,e.name,e.tpl_data,e.create_time 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 topic_word tw on tw.exam_group_id=e.exam_group_id "; if($condition){ $sql.=" where ".implode(' and ',$condition); } $sql.=" group by eg.exam_group_id order by e.create_time desc limit 30"; $list=array(); $exam = $this->sConn->createCommand($sql)->queryAll(); if($exam){ foreach ($exam as $value){ $tplData=json_decode($value['tpl_data'],true); $list[]=array( 'name'=>$value['name'], 'create_time'=>date('Y-m-d',$value['create_time']), 'exam_date'=>$tplData['examDate'], 'exam_group_id'=>$value['exam_group_id'] ); } } $result['status']=1; $result['data']=$list; exit(json_encode($result)); } //复用考试,试题结构 public function actionCopyPaperTopic(){ $nowExamId = Req::post('examGroupId'); //当前考试 $copyExamId = Req::post('copyExamGroupId'); //复制结构的考试 $result['status']=0; //读取当前考试试题结构 $nowPaperTopicRelation = array(); $examIds = array(); $paperIds = array(); $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$nowExamId}")->queryRow(); if (!$examGroup) { $result['msg'] = "考试id不正确"; exit(json_encode($result)); } if($examGroup['upload_status']>0){ $result['msg']="已上传成绩,不能复用"; exit(json_encode($result)); } $exam = $this->sConn->createCommand("select exam_id,upload_status,tpl_data from exam where exam_group_id={$nowExamId}")->queryAll(); foreach ($exam as $value) { $examIds[] = $value['exam_id']; $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$value['exam_id']}")->queryRow(); $paperIds[] = $paper['paper_id']; } $tplData=json_decode($exam[0]['tpl_data'],true); $nowPaperTopicRelation = $this->sConn->createCommand("select `order`,`type`,`topic_id`,`stem_id` from paper_topic_relation where paper_id={$paperIds[0]}")->queryAll(); if (!$nowPaperTopicRelation) { $result['msg'] = "未创建答题卡"; exit(json_encode($result)); } $checkArr = array(); $historyTopic = array(); foreach ($nowPaperTopicRelation as $val) { $checkArr[$val['order']] = $val['type']; $checkOrderTopic[$val['order']] = $val['topic_id']; $historyTopic[$val['order']] = array( 'topic_id' => $val['topic_id'], 'type' => $val['type'], 'stem_id'=> $val['stem_id'] ); } //读取复制的考试结构 $copyPaperTopicRelation = array(); $exam = $this->sConn->createCommand("select exam_id,tpl_data from exam where exam_group_id={$copyExamId}")->queryRow(); $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$exam['exam_id']}")->queryRow(); $topicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$copyExamId}")->queryRow(); $copyPaperTopicRelation = $this->sConn->createCommand("select `order`,`type`,`topic_id`,`method_ids`,`method_difficulty`,`stem_id` from paper_topic_relation where paper_id={$paper['paper_id']}")->queryAll(); $checkArrCopy = array(); $copyTopicOrder = array(); foreach ($copyPaperTopicRelation as $val) { $checkArrCopy[$val['order']] = $val['type']; $copyTopicOrder[$val['order']] = array( 'topic_id' => $val['topic_id'], 'method_ids' => $val['method_ids'], 'method_difficulty' => $val['method_difficulty'], 'type'=>$val['type'], 'stem_id'=>$val['stem_id'] ); } if(strcmp(json_encode($checkArr),json_encode($checkArrCopy))!==0){ $result['msg']="两场考试试题结构不相同,不能复用"; exit(json_encode($result)); } if(isset($tplData['new_items'])){ foreach($tplData['new_items'] as $key => $item){ if(isset($copyTopicOrder[$item['id']])){ $tplData['new_items'][$key]['topicId']=$copyTopicOrder[$item['id']]['topic_id']; $tplData['new_items'][$key]['stemId']=$copyTopicOrder[$item['id']]['stem_id']; } } } //开始复用 $updateArr = array(); $updateMarkingTopicArr=array(); foreach ($checkOrderTopic as $key => $val) { $sql = "update paper_topic_relation set topic_id='" . $copyTopicOrder[$key]['topic_id'] . "',stem_id='".$copyTopicOrder[$key]['stem_id']."',method_ids='" . $copyTopicOrder[$key]['method_ids'] . "',method_difficulty='" . $copyTopicOrder[$key]['method_difficulty'] . "' "; $sql .= " where paper_id in(" . implode(',', $paperIds) . ") and topic_id={$val}"; $updateArr[] = $sql; if($examGroup['mark_type']==4 && !in_array($copyTopicOrder[$key]['type'],array(1,2,11))){ $markingTopicSql="update marking_topic set topic_id='".$copyTopicOrder[$key]['topic_id']."' where exam_group_id='{$nowExamId}' and topic_id='{$val}'"; $updateMarkingTopicArr[]=$markingTopicSql; } } $transaction = $this->sConn->beginTransaction(); try{ foreach ($updateArr as $sql){ $this->sConn->createCommand($sql)->execute(); } if($updateMarkingTopicArr){ foreach ($updateMarkingTopicArr as $sql){ $this->sConn->createCommand($sql)->execute(); } } if($examGroup['mark_type']!=4){ $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$nowExamId}'")->execute(); } $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$nowExamId}'")->execute(); $nowTopicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$nowExamId}")->queryRow(); $this->sConn->createCommand("update exam_group set is_answersheet=1 where exam_group_id='" . $nowExamId . "'")->execute(); if ($nowTopicWord) { $this->sConn->createCommand("update topic_word set status=2,is_history_topic='" . jsonEncode($historyTopic) . "',word_name='" . $topicWord['word_name'] . "',word_path='" . $topicWord['word_path'] . "',word_size='" . $topicWord['word_size'] . "' where exam_group_id='" . $nowExamId . "'")->execute(); } else { $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll(); $wordId = current(current($uuid)); $topic_word_odj = new STopicWord(); $topic_word_odj->word_id = $wordId; $topic_word_odj->exam_group_id = $nowExamId; $topic_word_odj->word_name = $topicWord['word_name']; $topic_word_odj->word_path = $topicWord['word_path']; $topic_word_odj->word_md5 = ''; $topic_word_odj->word_size = $topicWord['word_size']; $topic_word_odj->subject_id = $topicWord['subject_id']; $topic_word_odj->status = 2; $topic_word_odj->uploader_id = $this->coachId; $topic_word_odj->upload_time = time(); $topic_word_odj->is_history_topic = jsonEncode($historyTopic); $topic_word_odj->save(); } $transaction->commit(); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $nowExamId, "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') ))); } $result['status'] = 1; } catch (Exception $e) { $transaction->rollBack(); $result['msg']="复用失败"; } exit(json_encode($result)); } //生成二维码 public function actionCreateQrcode(){ $examGroupId = Req::post("examGroupId"); //记录ID $result['status']=0; if(!$examGroupId){ $result['msg']='考试Id不能为空'; exit(json_encode($result)); } $QRcode = new \QRcode(); $level = 'L';// 纠错级别:L、M、Q、H $size = 100;//元素尺寸 $margin = 1;//边距 $path='upload/tmpDir/qrCode/'; if (!file_exists($path)) { mkdir($path, 0777, true); } $outfile=$path.$examGroupId.'.png'; $saveandprint = false;// true直接输出屏幕 false 保存到文件中 $back_color = 0xFFFFFF;//白色底色 $fore_color = 0x000000;//黑色二维码色 若传参数要hexdec处理,如 $fore_color = str_replace('#','0x',$fore_color); $fore_color = hexdec('0xCCCCCC'); $QRcode->png($examGroupId, $outfile, $level, $size, $margin, false, $back_color, $fore_color); if(file_exists($outfile)){ $ucloud = new HuaweiCloud(); $uploadUrl='zsyas2/third/qrcode/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $examGroupId. '.png'; $uploadInfo = $ucloud->putFile($uploadUrl, $outfile); if ($uploadInfo['status'] == 0) { @unlink($outfile); $result['status']=0; $result['msg'] = '文件上传失败!'; }else{ @unlink($outfile); $result['data'] = $uploadInfo['url']; $result['status']=1; } }else{ $result['status']=0; $result['msg'] = '文件生成失败!'; } exit(json_encode($result)); } //切换答题卡,清空模板数据 public function actionClearAnswerCard() { $examGroupId = Req::post("examGroupId"); //考试ID $type = Req::post("type"); //答题卡类型 /* * 是否制作模板及类型 * 判断是否上传答题卡 * 是否解析 * 是否标注 * * 清空 paper_topic_relation * tpl_data new_items items * topic topic_item_option * marking_topic * //删除数据 * */ $examGroup = SExamGroup::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId)); if (!$examGroup) { $result['status'] = 0; $result['msg'] = '考试ID不存在'; exit(json_encode($result)); } if ($examGroup['is_answersheet'] == 1) { $result['status'] = 0; $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板'; exit(json_encode($result)); } if ($examGroup['is_tagging'] == 1) { $result['status'] = 0; $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板'; exit(json_encode($result)); } $thirdMultiTemplate = $this->sConn->createCommand("select template_id from third_multi_template where exam_group_id='{$examGroupId}' and (topic_upload=1 or answer_upload=1)")->queryRow(); if ($thirdMultiTemplate) { $result['status'] = 0; $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板'; exit(json_encode($result)); } $exam = Exam::model()->findAll('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId)); $tplData = json_decode($exam[0]['tpl_data'], true); $thirdAnswerSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId)); if (!$thirdAnswerSheet) { $result['status'] = 0; $result['msg'] = '未制作答题卡'; exit(json_encode($result)); } $examIds = array(); $paperIds = array(); $topicIds = array(); foreach ($exam as $item) { $examIds[] = $item['exam_id']; } $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id', $examIds); $paper = SPaper::model()->findAll($criteria); foreach ($paper as $item) { if ($item['is_labelled'] > 0) { $result['status'] = 0; $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板'; exit(json_encode($result)); } $paperIds[] = $item['paper_id']; } $paperTopic = SPaperTopicRelation::model()->findAll('paper_id=:pid', array(':pid' => $paperIds[0])); foreach ($paperTopic as $item) { $topicIds[] = $item['topic_id']; } //查询是否有上传数据 $rs = $this->sConn->createCommand("select id from student_paper_topic_rs where paper_id in(" . implode(',', $paperIds) . ") limit 1")->queryRow(); if ($rs) { $result['status'] = 0; $result['msg'] = '本场考试已上传学生答题卡,不支持再切换答题卡模板'; exit(json_encode($result)); } $transaction = $this->sConn->beginTransaction(); try { if($topicIds){ $this->sConn->createCommand("delete from topic where topic_id in (" . implode(',', $topicIds) . ")")->execute(); $this->sConn->createCommand("delete from topic_item where topic_id in (" . implode(',', $topicIds) . ")")->execute(); $this->sConn->createCommand("delete from topic_item_option where topic_id in (" . implode(',', $topicIds) . ")")->execute(); } $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")")->execute(); $this->sConn->createCommand("delete from marking_topic where exam_group_id =" . $examGroupId)->execute();; $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =" . $examGroupId)->execute();; $this->sConn->createCommand("delete from topic_word where exam_group_id =" . $examGroupId)->execute(); $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =" . $examGroupId)->execute(); $this->sConn->createCommand("delete from exam_push_topics_setting where exam_group_id =" . $examGroupId)->execute(); unset($tplData['items']); unset($tplData['new_items']); unset($tplData['new_rules']); unset($tplData['update_answer']); if (isset($tplData['totals'])) $tplData['totals'] = 0; if (isset($tplData['scores'])) $tplData['scores'] = 0; if (isset($tplData['total_score'])) $tplData['total_score'] = 0; $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id='" . $examGroupId . "'")->execute(); $transaction->commit(); if (Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $examGroupId, "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') ))); } $result['status'] = 1; } catch (\Exception $e) { $transaction->rollBack(); $result['status'] = 0; $result['msg'] = '清空答题卡数据失败'; } exit(json_encode($result)); } // 上传试卷模板 public function actionNewUploadTpl(){ $exam_group_id = Req::post('eid'); $upload_type = Req::post('uploadType'); //上传类型 $allowFileNameArr=array('word_file','paper_file','parse_file'); $error['success'] = 0; if (empty($exam_group_id)) { $error['message'] = '考试id不存在!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($examInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } $examIds=array(); foreach ($examInfo as $value){ $examIds[]=$value->exam_id; } $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if (empty($thirdSheet)) { $error['message'] = '尚未上传答题卡!'; echo json_encode($error);exit(); } $topicWord=STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($topicWord){ if($topicWord->allsubject_file_path && $topicWord->status!=3 && $topicWord->status!=7){ $error['message'] = '试卷已经上传,请勿重复上传!'; echo json_encode($error);exit(); } if(($upload_type==1 && $topicWord->word_path) || ($upload_type==2 && $topicWord->allsubject_file_path)){ $error['message'] = '已经上传试卷,不能切换解析模式!'; echo json_encode($error);exit(); } } $fileUrlArr=array(); $file_max_size = 11 * 1024 * 1024; foreach ($_FILES as $key =>$val){ if(in_array($key,$allowFileNameArr)){ if(!is_uploaded_file($_FILES[$key]['tmp_name'])){ if($key=='paper_file' && $upload_type==1){ $error['message'] = '非法上传!'; echo json_encode($error);exit(); }else{ continue; } } if ($_FILES[$key]["size"] > $file_max_size) { $error['message'] = '文件超过最大限制,最大为10M'; echo json_encode($error);exit(); } if ($_FILES[$key]['error'] > 0) { switch ($_FILES[$key]['error']) { case 1: $error['message'] = '文件大小超出了服务器的空间大小!'; break; case 2: $error['message'] = '要上传的文件大小超出浏览器限制!'; break; case 3: $error['message'] = '文件只有部分被上传!'; break; case 4: $error['message'] = '没有找到要上传的文件!'; break; case 5: $error['message'] = '服务器临时文件夹丢失!'; break; case 6: $error['message'] = '文件写入到临时文件夹出错!'; break; } echo json_encode($error);exit(); } // 保存上传文件至服务器 $extName = substr($_FILES[$key]['name'],strrpos($_FILES[$key]['name'],'.')); $fileName = $exam_group_id.$extName; $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName; $ucloud = new HuaweiCloud(); $uploadInfo = $ucloud->putFile($wordRename, $_FILES[$key]['tmp_name']); if ($uploadInfo['status'] == 0) { echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg'])); exit(); } if(strpos($key,'paper_file')!==false){ $fileUrlArr[]=array( 'file_type'=>1, 'file_url'=>str_replace("%2F","/",$uploadInfo['url']), 'file_name'=>$_FILES[$key]['name'] ); }elseif(strpos($key,'parse_file')!==false){ $fileUrlArr[]=array( 'file_type'=>2, 'file_url'=>str_replace("%2F","/",$uploadInfo['url']), 'file_name'=>$_FILES[$key]['name'] ); }else{ $fileUrlArr[] = str_replace("%2F","/",$uploadInfo['url']); } } } if(!$fileUrlArr){ $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); } //操作日志 if(Yii::app()->params['handle_log_on_off']) { Curl::post(Yii::app()->params['handle_log_api'], array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "title" => '第三方试卷上传试卷', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('insert'=>array('exam_group_id'=>$exam_group_id,'status'=>0,'word_path'=>$uploadInfo['url'],'subject_id'=>$examInfo[0]->subject_id))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])), )); } $transcation = $this->sConn->beginTransaction(); try { $time = time(); $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute(); STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //$this->sConn->createCommand("update paper set is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute(); $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll(); $wordId = current(current($uuid)); $topic_word_odj = new STopicWord(); $topic_word_odj->word_id = $wordId; $topic_word_odj->exam_group_id = $exam_group_id; $topic_word_odj->word_name = '第三方试卷'.$fileName; if($upload_type==1){ $topic_word_odj->allsubject_file_path = json_encode($fileUrlArr); }elseif($upload_type==2){ $topic_word_odj->word_path = implode(',',$fileUrlArr); } $topic_word_odj->word_md5 = ''; $topic_word_odj->word_size = 0; $topic_word_odj->subject_id = $examInfo[0]->subject_id; $topic_word_odj->status = 0; $topic_word_odj->type_id = 3; $topic_word_odj->uploader_id = $this->coachId; $topic_word_odj->upload_time = $time; $topic_word_odj->save(); $transcation->commit(); } catch (Exception $e) { $transcation->rollback(); $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } $this->schoolManager->saveExamProcess($exam_group_id,3,time()); $error['success'] = 1; $error['message'] = '上传文件成功!'; echo json_encode($error);exit(); } public function actionViewPaper(){ $pid = Req::get('pid'); if(!$pid) Yii::app()->jump->error('解析尚未完成,或未生成预览'); $data=array('pid'=>$pid); $this->renderPartial('view_paper',$data); } //创建考试加载班级 public function actionAjaxGetClassByTeacherGrade(){ $grade = Req::post('grade'); $teacherId = Req::post('teacherId'); $selectClassData = Req::post('selectClassData'); if(!$selectClassData) $selectClassData=array(); $result['status']=0; if (Yii::app()->request->getIsPostRequest()){ $selectedClass=array(); if($selectClassData){ foreach ($selectClassData as $datum){ $selectedClass[(string)$datum]=$datum; } } //读取走班设置 $setting=$this->schoolManager->getClassifiedBySubject($grade,$this->subjectId,$this->semesterId); //读取执教班级 $teacherClassSelectData=array(); $getTeacherClass = ClassModel ::model()->getSelectclassesByTeacherGrade($this->semesterId,$teacherId,$grade); foreach ($getTeacherClass as $val){ $teacherClassSelectData[(string)$val['class_id']]=$val; } //查询年级所有班级 $allClassList=array(); if($setting['status']==1){ $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=2",array(':gid'=>$grade,':sid'=>$this->semesterId)); }else{ $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=1",array(':gid'=>$grade,':sid'=>$this->semesterId)); } if($classes){ foreach ($classes as $class){ if($class['is_hide']==1){ continue; } $temp=array( 'class_id'=>$class['class_id'], 'class_name'=>$class['class_name'], 'arts_science'=>$class['arts_science'], 'selected'=>0 ); if($selectedClass){ if(isset($selectedClass[(string)$class['class_id']])){ $temp['selected']=1; } }else{ if(isset($teacherClassSelectData[(string)$class['class_id']])){ $temp['selected']=1; } } $allClassList[]=$temp; } } $result['status']=1; $result['msg']='success'; $result['data']=$allClassList; } exit(json_encode($result)); } //验证第三方选做题分组 public function actionCheckSelectTopicGroup() { $examGroupId = Req::post("exam_group_id"); if($examGroupId>0) { $examData = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $tplData=json_decode($examData['tpl_data'],true); if(isset($tplData['new_items'])){ foreach($tplData['new_items'] as $item){ if(isset($item['sameAliasNo']) && $item['sameAliasNo']){ echo json_encode(array('status'=>1));exit; } } } } echo json_encode(array('status'=>0));exit; } //生成签名 public function actionCreateSign(){ $eid = Req::post('eid'); if(YII_ENV=='production'){ $appId='946004280126791680'; //线上 }else{ $appId='939792767984566272'; //测试 } $time=time(); $params=array( 'appId'=>$appId, 'timestamp'=>$time ); $params['certificate']=$eid.'_'.$this->schoolId; $vSign=$this->getSignature($appId,$time,'654321',$params); $result['status'] = 1; $result['sign'] = $vSign; $result['time'] = $time; $result['certificate'] = $params['certificate']; echo json_encode($result);exit(); } private function getSignature($appId,$timestamp,$secret,$params) { $subfix=''; if ($params) { ksort($params, SORT_STRING); $subfix = http_build_query($params); } $signature = base64_encode(hash_hmac("sha1", $appId . $timestamp . $secret . $subfix, $secret)); return strtoupper(md5($signature)); } public function actionUploadHw(){ $ucloud = new HuaweiCloud(); $uploadInfo = $ucloud->putFile('images/avatar.png', 'images/avatar.png'); debug($uploadInfo); } }