96, 'cm' => 28, 'mm' => 2.8, 'pt' => 1.33, 'pc' => 12, ); public function actionIndex($YII_ENV='development',$taskId=""){ //echo YII_ENV;exit; if(YII_ENV == "production"){ $file_html_url = "http://zsyas2.zhixinhuixue.com"; }else{ if(YII_ENV == 'development'){ $file_html_url = "http://xbas2.dev.xiaoben.com"; }else{ $file_html_url = "http://xbas2.testing.xiaoben.com"; } } //连接业务库 $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); if($conn){ $this->conn = $conn; $time = time(); //获取要生成教师讲案的数据 if(isset($taskId) && $taskId){ $sql = "select id,school_id,exam_group_id,class_ids from download_table_setting where id='{$taskId}'"; }else{ $sql = "select id,school_id,exam_group_id,class_ids from download_table_setting where download_type = 3 and status = 1 and error_msg = '' and subject_id in (3,6,51) order by create_time asc"; } $result_all = $this->conn->createCommand($sql)->queryAll(); //超过五分钟默认生成失败 $sql = "update download_table_setting set status = 3,error_msg ='系统错误,建议单个生成' where status = 4 and error_msg = '' and update_time <".($time-600); $this->conn->createCommand($sql)->execute(); if($result_all){ // $time = time(); // $sql = "update download_table_setting set update_time = {$time},status=4 where download_type = 3 and status = 1 and error_msg = '' and subject_id in (3,6,51)"; // $this->conn->createCommand($sql)->execute(); // foreach($result_all as $v_data){ foreach($result_all as $v_data_k=>$v_data){ if($v_data_k > 0){ break; } // var_dump($v_data);exit; $coach_name = ""; $sql = "select coach_name from coach where school_id='{$v_data['school_id']}' and `status`=0"; $coach_one = $this->conn->createCommand($sql)->queryRow(); if($coach_one){ $coach_name = $coach_one["coach_name"]; } $sql = "select school_name from school where school_id = '{$v_data['school_id']}'"; $school_one = $this->conn->createCommand($sql)->queryRow(); if($school_one){ $school_name = $school_one["school_name"]; }else{ $school_name = ""; } $sql = "update download_table_setting set update_time = {$time},status=4 where id ={$v_data['id']}"; $this->conn->createCommand($sql)->execute(); $error = array(); $pdfArr = array(); $is_success = 0; //学管账号 $coach = $this->conn->createCommand("select coach_name from coach where `status` = 0 and school_id={$v_data['school_id']};")->queryRow(); if($coach){ $authUsername = $v_data['school_id'].'_'.$coach['coach_name']; }else{ echo $v_data['school_id']."学校获取学管信息失败\n"; $error[] = $v_data['school_id']."学校获取学管信息失败"; continue; } try{ if($v_data['class_ids'] && $v_data['school_id'] && $v_data['exam_group_id']){ //连接学校库 $sql = "select database_host,database_user,database_password,database_name,group_id from `database` where school_id = '{$v_data['school_id']}'"; $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); if($conn){ $this->conn = $conn; }else{ echo "连接业务库失败\n"; $error[] = "连接业务库失败"; continue; } $result_one = $this->conn->createCommand($sql)->queryRow(); if($result_one){ $school_group_id = $result_one["group_id"]; if (!is_numeric($school_group_id)){ $school_group_id = 0; } $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]); if($sConn){ $sql = "select * from group_server where group_id = '{$school_group_id}'"; $group_server_data = $this->conn->createCommand($sql)->queryRow(); $static_url_data = $group_server_data['static_url']; $this->sConn = $sConn; echo '连接学校ID'.$v_data['school_id']."成功\n"; $null_data = 1; $pdfNames = array(); echo '开始获取任务ID'.$v_data['id']."的数据\n"; $classIds = explode(",", $v_data["class_ids"]); if($classIds){ foreach($classIds as $classId){ $this->sConn->active = false; $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]); $this->sConn = $sConn; echo "开始获取classId=".$classId."的数据\n"; $data = array(); $sql = "select class_name from class where class_id = '{$classId}'"; $data_one = $this->sConn->createCommand($sql)->queryRow(); if($data_one){ $className = $data_one['class_name']; }else{ $className = ""; } $sql = "select exam_id,name from exam where exam_group_id = '{$v_data["exam_group_id"]}' and class_id = '{$classId}'"; $data_one = $this->sConn->createCommand($sql)->queryRow(); if($data_one){ $examId = $data_one["exam_id"]; $examName = $data_one["name"]; $codeNow = $this->getCodeByExamId($examId);//当前学期code if($codeNow){ $isFromPast = 1; }else{ $isFromPast = 0; } $sql = "select e.teacher_id,eg.mark_type,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,c.class_name,eg.import_score_type,c.grade,p.method_ids,e.semester_id from exam as e left join class as c on c.class_id=e.class_id left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id where e.exam_id={$examId}"; $exam_info = $this->sConn->createCommand($sql)->queryRow(); $grade = $exam_info['grade']; $paper_method_ids = $exam_info['method_ids']; $score_type = $exam_info['import_score_type'];//成绩导入流程 0-正常扫描 $semesterId = $exam_info['semester_id']; if ($exam_info['mark_type'] == 0) { if(empty($codeNow)){ $sql = "SELECT feedback_time FROM student_paper_relation WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1"; }else{ $sql = "SELECT feedback_time FROM student_paper_relation_".$codeNow." WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1"; } $query = $this->sConn->createCommand($sql)->queryRow(); if ($query && $query['feedback_time'] >= $exam_info['academicr_pdf_time']) { if (file_exists($exam_info['academicr_pdf_path'])) { unlink($exam_info['academicr_pdf_path']); } $force = 1; } unset($query); } $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['academicr_pdf_path']; $pdfurl = $pdfpath =$exam_info['academicr_pdf_path']; $is_create=1; $force = 0; if(strpos($pdfurl,'http') !== false){ if(!file_get_contents($pdfurl)){ $force = 1; } }else{ $force = 1; } if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || $force) { // if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath)) { $is_create=0; $sql = "SELECT e.exam_group_id, e.exam_id, e.name AS exam_name, e.create_time AS exam_time, p.paper_id, p.score as paper_score, e.class_id,e.is_preparation_created,e.tpl_index, eg.mark_type,p.is_labelled,p.labelled_type,eg.qxk_paper_id "; $sql.= "FROM exam e "; $sql.= "JOIN paper p ON p.exam_id = e.exam_id "; $sql.= "JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id "; $sql.= "WHERE e.status = '1' AND e.exam_id = '{$examId}' "; $data = array(); $exam = $this->sConn->createCommand($sql)->queryRow(); $labelled_type = $exam['labelled_type']; $class_id = $exam['class_id']; $is_qxk = $exam['qxk_paper_id']?1:0;//是否是全学科 if($is_qxk){ $qxkKnowledge = SPaperTopicRelation::newKnowledgeRelate();//获取全学科知识点对应老知识点的关系 } if($class_id){ $exam['show_level'] = $this->get_version($class_id); $exam['level_rule'] = $this->get_level_rule($class_id); } //获取显示设置 $setting_arr = array("common"=>1,"common_wrong"=>1,"paper"=>1,"paper_wrong"=>1,"real_topic"=>1,"classmateOptimization"=>1); $sql = "select tt.template_id,tt.config_text from teaching_template tt join teaching_class_set tcs on tt.template_id=tcs.template_id where tt.subject_id = 3 and tcs.class_id='{$class_id}'"; $setting_data = $this->sConn->createCommand($sql)->queryRow(); if($setting_data){ $setting_data_arr = json_decode($setting_data['config_text'],true); if(isset($setting_data_arr['common'])){ $setting_arr['common'] = $setting_data_arr['common']; } if(isset($setting_data_arr['common_wrong'])){ $setting_arr['common_wrong'] = $setting_data_arr['common_wrong']; } if(isset($setting_data_arr['paper'])){ $setting_arr['paper'] = $setting_data_arr['paper']; } if(isset($setting_data_arr['paper_wrong'])){ $setting_arr['paper_wrong'] = $setting_data_arr['paper_wrong']; } if(isset($setting_data_arr['real_topic'])){ $setting_arr['real_topic'] = $setting_data_arr['real_topic']; } if(isset($setting_data_arr['classmateOptimization'])){ $setting_arr['classmateOptimization'] = $setting_data_arr['classmateOptimization']; } } $is_same_bs = 1;//是否开启相同变式题(需要读提分宝班级定制的配置) $same_bs_data = array();//开启相同变式题 原题跟变式题的对应关系 $is_same_bs = $this->getClassSet($classId, $semesterId); if($is_same_bs && $labelled_type == 1){ //判断有没有订单(提分方案2,提分宝3) 如果没有订单生成教学宝 有订单没数据不能生成 $has_order = 0; $table_spr = empty($codeNow)?'student_paper_relation':'student_paper_relation_'.$codeNow; $sql = "select student_id from {$table_spr} where exam_id = '{$examId}'"; $spr_data = $this->sConn->createCommand($sql)->queryAll(); $relateStudentRes = array(); if($spr_data){ foreach($spr_data as $spr_v){ $relateStudentRes[]['student_id'] = $spr_v['student_id']; } } foreach(array(2,3) as $product_type){ $temp_order = $this->getOrderStu($examId, $classId, $product_type, $relateStudentRes, $semesterId, $grade,$v_data['school_id'],$coach_name); if($temp_order && isset($temp_order['limitstu']) && $temp_order['limitstu']){ $has_order = 1; break; } } $sql = "select preparation_plan_id,template_id,topic_id from preparation_plan_topic where preparation_plan_id='{$examId}'"; $same_bs = $this->sConn->createCommand($sql)->queryAll(); if($same_bs){ foreach($same_bs as $same_k=>$same_v){ $same_bs_data[$same_v['template_id']][] = $same_v['topic_id']; } }else{ if($has_order){ echo json_encode(array("status"=>1,"error"=>"变式题未生成,请等待")); $error[] = $className."变式题未生成"; continue; // exit; } } $setting_arr['common'] = 0; } if($labelled_type == 2){ $exam['show_level'] = 0; }else{ $sql = "select switch from producut_set_edition"; $switch_data = $this->sConn->createCommand($sql)->queryRow(); if($switch_data && in_array($switch_data['switch'],array(3,4))){ $exam['show_level'] = 0; $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc"; $gongxing_data = $this->sConn->createCommand($sql)->queryAll(); if(!$gongxing_data){ echo json_encode(array("status"=>1,"error"=>"共性问题未生成,请稍等")); $error[] = $className."共性问题未生成"; continue; // exit; } }else{ if ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] != 1) { //如果选择的是分层班,教师讲案的生成条件是教师讲评题已经抽出 echo json_encode(array("status"=>1,"error"=>"文件内容尚未生成,请等待")); exit; }elseif ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] == 2) { echo json_encode(array("status"=>1,"error"=>"由于题库题目导致无法生成,请联系后台题库老师去处理题目!")); exit; } } } if ($exam['is_labelled']!=1) { echo "试卷还未标注,请先标注试卷\n"; $error[] = $className."试卷还未标注,请先标注试卷"; continue; } // if($switch_data && in_array($switch_data['switch'],array(3,4))){ // $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' order by topic_type asc"; // $gongxing_data = $this->sConn->createCommand($sql)->queryAll(); // if(!$gongxing_data){ // echo "共性问题未生成,请等待\n"; // $error[] = $className."共性问题未生成,请等待"; // continue; // } // } if ($exam) { //同学优解 $excellent_solution = SStudentPaperTopicRs::model()->bestAnswer($exam,$codeNow,$static_url_data,$this->sConn,$is_qxk); //获取共性问题 $has_topic_gaokao = array();//本教学宝其他题,用于抽取高考真题 $gen_topics = array(); $gen_topics_ids = array();//共性所有题ID集合 $gen_topics_detail = array();//试题详情 $gen_topics_msg = array();//题目难度、考点、挑战信息 // $schoolId = $this->schoolId;//当前学校 $school_province_name = "";//学校省份 $school_province_id = 0;//学校省份Id $gen_origin_ids = array();//共性原题Id $gen_origin_methods = array();//共性原题考点集合 // $school_msg = Yii::app()->businessDb->createCommand()->from('school') // ->select("province_id") // ->where("school_id = ".$v_data['school_id']) // ->queryRow(); $this->conn->active = false; $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); $this->conn = $conn; $sql = "select province_id from school where school_id = '{$v_data['school_id']}'"; $school_msg = $this->conn->createCommand($sql)->queryRow(); if($school_msg){ $school_province_id = $school_msg['province_id']; } if($school_province_id){ // $region_msg = Yii::app()->businessDb->createCommand()->from('region') // ->select("region_name") // ->where("region_id = ".$school_province_id) // ->queryRow(); $sql = "select region_name from region where region_id = '{$school_province_id}'"; $region_msg = $this->conn->createCommand($sql)->queryRow(); if($region_msg){ $school_province_name = $region_msg["region_name"]; } } $sql = "select template_id,topic_id,topic_type,template_no from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc"; $gongxing_data = $this->sConn->createCommand($sql)->queryAll(); if($gongxing_data){ foreach($gongxing_data as $k=>$v){ $i = 0; $gen_topics_ids[] = $gen_origin_ids[] = $v['template_id']; $gen_topics_ids[] = $v['topic_id']; $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['template_id']; $gen_topics[$v['topic_type']][$i]['is_template'] = 1; $i++; $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['topic_id']; $gen_topics[$v['topic_type']][$i]['is_template'] = 0; //变式训练获取地区挑战数 if($v['topic_id']){ $gen_topics_msg[$v['topic_id']]['school_province_name'] = $school_province_name; $topic_count = Yii::app()->topic_province_count->hmget('province_stat:topic:'.$school_province_id,array($v['topic_id'])); if($topic_count && isset($topic_count[0])){ $gen_topics_msg[$v['topic_id']]['province_count'] = empty($topic_count[0])?1000:$topic_count[0]+1000; }else{ $gen_topics_msg[$v['topic_id']]['province_count'] = 1000; } $gen_topics_msg[$v['template_id']]['template_no'] = $v['template_no']; } } } $gen_topics_ids = array_values(array_unique($gen_topics_ids)); if($gen_topics_ids){ $topicItems_1 = $this->aipost('/topic/batchAll', array('topicIds' => $gen_topics_ids)); //debug($topicItems_1); if ($topicItems_1 && !isset($topicItems_1['status'])) { foreach ($topicItems_1 as $topicItem) { $gen_topics_detail_temp[$topicItem['id']] = $topicItem; } if ($gen_topics_detail_temp) { foreach ($gen_topics_detail_temp as $k => $v) { $v=(array)$v; $v['id'] = (string)$v['id']; $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:""; if(!$teacher_tips){ $teacher_tips = $this->dealTeacherTips($v); } $v['teacher_tips'] = $this->topicProcess($teacher_tips); $v['parse_content'] = $this->topicProcess($v['parse_content']); if($v['type_id'] == 5 || $v['type_id'] == 6){ $v['title'] = preg_replace("/]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']); } $v['title'] = $this->topicProcess($v['title']); if(isset($v['items'][0])){ $v['items'][0]=(array)$v['items'][0]; $v['items'][0]['options']=(array)$v['items'][0]['options']; if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) { foreach ($v['items'][0]['options'] as $key => $val) { $val=(array)$val; $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key]; $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']); } } } //难度 $gen_topics_msg[$v['id']]['difficulty'] = isset($v['difficulty_degree'])?$v['difficulty_degree']:0; //考点 $gen_topics_msg[$v['id']]['methods'] = ""; $methods_arr = array(); if(isset($v['specials']) && $v['specials']){ foreach($v['specials'] as $specials){ if(isset($specials['method_name'])){ $methods_arr[] = $specials['method_name']; } if(in_array($v['id'],$gen_origin_ids)){ $gen_origin_methods[$specials['method_id']] = $specials['method_name']; } } }elseif (isset($v['kps']) && $v['kps']){ foreach($v['kps'] as $kps){ if(isset($kps['kp_name'])){ $methods_arr[] = $kps['kp_name']; } if(in_array($v['id'],$gen_origin_ids)){ $gen_origin_methods[$kps['kp_id']] = $kps['kp_name']; } } } if($methods_arr){ $gen_topics_msg[$v['id']]['methods'] = implode(",",$methods_arr); } $gen_topics_detail[$v['id']] = $v; } } unset($gen_topics_detail_temp); } unset($topicItems_1); } //年级共性问题 $grade_topics_ids = array(); $grade_topic_data = array(); $sql = "select topic_id from product_grade_common_topic where exam_group_id = '{$exam['exam_group_id']}'"; $grade_data = $this->sConn->createCommand($sql)->queryAll(); if($grade_data){ foreach($grade_data as $k=>$v){ $grade_topics_ids[] = $v['topic_id']; } } if($grade_topics_ids){ $grade_topic_item = $this->aipost('/topic/batchAll', array('topicIds' => $grade_topics_ids)); if ($grade_topic_item && !isset($grade_topic_item['status'])) { foreach ($grade_topic_item as $k => $v) { $v['parse_content'] = $this->topicProcess($v['parse_content']); if($v['type_id'] == 5 || $v['type_id'] == 6){ $v['title'] = preg_replace("/]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']); } $v['title'] = $this->topicProcess($v['title']); if(isset($v['items'][0])){ if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) { foreach ($v['items'][0]['options'] as $key => $val) { $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key]; $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']); } } } $grade_topic_item[$k] =$v; } $grade_topic_data = $grade_topic_item; } } $data['grade_topic_data'] = $grade_topic_data; $data['gen_origin_methods'] = $gen_origin_methods?implode(",",$gen_origin_methods):""; $data['gen_topics_msg'] = $gen_topics_msg; $data['gen_topics'] = $gen_topics; $data['gen_topics_detail'] = $gen_topics_detail; $data['excellent_solution'] = $excellent_solution; $data['wb_isp_version'] = $exam['show_level']; $data['level_rule'] = $exam['level_rule']; $data['examGroups'] = array(); $data['examGroupIds'] = array(); $data['exams'] = array(); $data['examIds'] = array(); $data['prevExams'] = array(); $data['prevExamIds'] = array(); $data['papers'] = array(); $data['paperIds'] = array(); $data['prevPapers'] = array(); $data['prevPaperIds'] = array(); $data['fcTopicIds'] = array(); $data['methodIds'] = array(); $data['methodNames'] = array(); $data['topicIds'] = array(); $data['noTopicIds'] = array(); $data['topicDetails'] = array(); $data['answer_score_details'] = array();//客观题答案明细 if (!isset($data['examGroups'][$exam['exam_group_id']])) { $data['examGroups'][$exam['exam_group_id']] = array( 'examIds' => array(), 'paperIds' => array(), 'examName' => $exam['exam_name'], 'examTime' => $exam['exam_time'], 'fullScore' => $exam['paper_score'], ); } $data['examGroups'][$exam['exam_group_id']]['examIds'][] = $exam['exam_id']; $data['examGroups'][$exam['exam_group_id']]['paperIds'][] = $exam['paper_id']; if (!isset($data['exams'][$exam['exam_id']])) { $data['exams'][$exam['exam_id']] = array( 'paperIds' => array(), 'examName' => $exam['exam_name'], 'examTime' => $exam['exam_time'], 'examGroupId' => $exam['exam_group_id'], 'fullScore' => $exam['paper_score'], ); } $data['exams'][$exam['exam_id']]['paperIds'][] = $exam['paper_id']; if (!isset($data['papers'][$exam['paper_id']])) { $data['papers'][$exam['paper_id']] = array(); } $data['papers'][$exam['paper_id']]['examId'] = $exam['exam_id']; $data['papers'][$exam['paper_id']]['examName'] = $exam['exam_name']; $data['papers'][$exam['paper_id']]['examTime'] = $exam['exam_time']; $data['papers'][$exam['paper_id']]['examGroupId'] = $exam['exam_group_id']; $data['papers'][$exam['paper_id']]['fullScore'] = $exam['paper_score']; $data['examGroupIds'][] = $exam['exam_group_id']; $data['examIds'][] = $exam['exam_id']; $data['paperIds'][] = $exam['paper_id']; // 上一次考试 $sql = "SELECT e.exam_id, p.paper_id FROM exam e JOIN paper p ON p.exam_id = e.exam_id WHERE e.subject_id in(3,6,51) and e.class_id = '" . $exam['class_id'] . "' AND e.create_time < '" . $exam['exam_time'] . "' AND e.status = '1' ORDER BY e.create_time DESC LIMIT 1"; $query = $this->sConn->createCommand($sql)->queryRow(); if ($query) { $codePrev = $this->getCodeByExamId($query['exam_id']); $data['prevExamIds'][] = $query['exam_id']; $data['prevPaperIds'][] = $query['paper_id']; $data['exams'][$exam['exam_id']]['prevExamId'] = $query['exam_id']; $data['papers'][$exam['paper_id']]['prevPaperId'] = $query['paper_id']; $data['prevExams'][$query['exam_id']] = $exam['exam_id']; $data['prevPapers'][$query['paper_id']] = $exam['paper_id']; // 上次考试总分 $prevQuery = $this->sConn->createCommand(" SELECT score FROM paper WHERE paper_id = '" . $query['paper_id'] . "' ")->queryRow(); if ($prevQuery) { $data['papers'][$exam['paper_id']]['prevFullScore'] = $prevQuery['score']; } unset($prevQuery); // 上次考试的平均得分率 if(empty($codePrev)){ $prevQuery = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score FROM student_paper_relation WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "' ")->queryRow(); }else{ $prevQuery = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score FROM student_paper_relation_".$codePrev." WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "' ")->queryRow(); } if ($prevQuery) { $data['papers'][$exam['paper_id']]['prevTotalNum'] = $prevQuery['total_num']; $data['papers'][$exam['paper_id']]['prevTotalScore'] = $prevQuery['total_score']; $data['papers'][$exam['paper_id']]['prevMaxScore'] = $prevQuery['max_score']; $data['papers'][$exam['paper_id']]['prevMinScore'] = $prevQuery['min_score']; $data['papers'][$exam['paper_id']]['prevAvgScore'] = 0; $data['papers'][$exam['paper_id']]['prevAvgRate'] = 0; if ($prevQuery['total_num'] > 0) { $data['papers'][$exam['paper_id']]['prevAvgScore'] = number_format($prevQuery['total_score'] / $prevQuery['total_num'], 2); if (isset($data['papers'][$exam['paper_id']]['prevFullScore']) && $data['papers'][$exam['paper_id']]['prevFullScore'] > 0) { $data['papers'][$exam['paper_id']]['prevAvgRate'] = number_format($prevQuery['total_score'] / ($prevQuery['total_num'] * $data['papers'][$exam['paper_id']]['prevFullScore']), 4) * 100; } } } } unset($query); // 参加考试人数、平均得分率、平均分、及格率、最高分、最低分 if(empty($codeNow)){ $query = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score FROM student_paper_relation WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ") GROUP BY paper_id ")->queryAll(); }else{ $query = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score FROM student_paper_relation_".$codeNow." WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ") GROUP BY paper_id ")->queryAll(); } if ($query) { foreach ($query as $k => $v) { $data['papers'][$v['paper_id']]['totalNum'] = $v['total_num']; $data['papers'][$v['paper_id']]['totalScore'] = $v['total_score']; $data['papers'][$v['paper_id']]['maxScore'] = $v['max_score']; $data['papers'][$v['paper_id']]['minScore'] = $v['min_score']; $data['papers'][$v['paper_id']]['avgScore'] = 0; $data['papers'][$v['paper_id']]['avgRate'] = 0; $data['papers'][$v['paper_id']]['avgFluctuate'] = 0; if ($v['total_num'] > 0) { $data['papers'][$v['paper_id']]['avgScore'] = number_format($v['total_score'] / $v['total_num'], 2); if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) { $data['papers'][$v['paper_id']]['avgRate'] = number_format($v['total_score'] / ($v['total_num'] * $data['papers'][$exam['paper_id']]['fullScore']), 4) * 100; if (isset($data['papers'][$v['paper_id']]['prevAvgRate'])) { $data['papers'][$v['paper_id']]['avgFluctuate'] = number_format($data['papers'][$v['paper_id']]['avgRate'] - $data['papers'][$v['paper_id']]['prevAvgRate'], 2); } } } } } unset($query); // 单题班级情况 if(empty($codeNow)){ $sql = " SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex FROM student_paper_topic_rs sptr JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 "; //WHERE sptr.handlerIndex = '1'"; }else{ $sql = " SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex FROM student_paper_topic_rs_".$codeNow." sptr JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 "; //WHERE sptr.handlerIndex = '1'"; } $sql.="AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")"; $query = $this->sConn->createCommand($sql)->queryAll(); $class_topic_score = array(); $topic_score_arr = array(); if ($query) { $data['papers'][$v['paper_id']]['topics'] = array(); foreach ($query as $k => $v) { if (!isset($data['papers'][$v['paper_id']]['topics'][$v['topic_id']])) { $data['papers'][$v['paper_id']]['topics'][$v['topic_id']] = array(); $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score']; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] = 0; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgScore'] = 0; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgRate'] = 0; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] = 0; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong'] = 0; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'] = array(); $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'] = array();//得分率低于70%的,选择题错的 $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['classRate'] = 0; } $topic_score_arr[$v['topic_id']] = $v['score']; //班级得分 if (!isset($class_topic_score[$v['paper_id']])) { $class_topic_score[$v['paper_id']] = array(); } if (!isset($class_topic_score[$v['paper_id']][$v['topic_id']])) { $class_topic_score[$v['paper_id']][$v['topic_id']] = array(); } $class_topic_score[$v['paper_id']][$v['topic_id']][] = $v['scoring']; $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring']; if ($v['is_right'] == 1) { $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] ++; } else { if($v["handlerIndex"]==1) { $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong']++; } } if($v["handlerIndex"]==1) { $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id']; } if ($v['score'] && $v['scoring']/$v['score'] < 0.7 && $v["handlerIndex"]==1) { $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'][] = $v['student_id']; } } } unset($query); // 缺考人数 if(empty($codeNow)){ $query = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS absent_num FROM student_paper_relation WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ") GROUP BY paper_id ")->queryAll(); }else{ $query = $this->sConn->createCommand(" SELECT paper_id, COUNT(student_id) AS absent_num FROM student_paper_relation_".$codeNow." WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ") GROUP BY paper_id ")->queryAll(); } if ($query) { foreach ($query as $k => $v) { $data['papers'][$v['paper_id']]['absentNum'] = $v['absent_num']; } } unset($query); // 及格率 if(empty($codeNow)){ $query = $this->sConn->createCommand(" SELECT paper_id, student_id, scoring FROM student_paper_relation WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ") ")->queryAll(); }else{ $query = $this->sConn->createCommand(" SELECT paper_id, student_id, scoring FROM student_paper_relation_".$codeNow." WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ") ")->queryAll(); } if ($query) { foreach ($query as $k => $v) { if (!isset($data['papers'][$exam['paper_id']]['passNum'])) { $data['papers'][$exam['paper_id']]['passNum'] = 0; $data['papers'][$exam['paper_id']]['passNum_90'] = 0; } if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) { if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.6) { $data['papers'][$exam['paper_id']]['passNum'] ++; } if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.9) { $data['papers'][$exam['paper_id']]['passNum_90'] ++; } } } unset($query); } foreach ($data['paperIds'] as $paperId) { if (!isset($data['papers'][$exam['paper_id']]['passRate'])) { $data['papers'][$exam['paper_id']]['passRate'] = 0; } if (isset($data['papers'][$v['paper_id']]['totalNum']) && $data['papers'][$v['paper_id']]['totalNum'] > 0 && isset($data['papers'][$exam['paper_id']]['passNum'])) { $data['papers'][$exam['paper_id']]['passRate'] = number_format($data['papers'][$exam['paper_id']]['passNum'] / $data['papers'][$v['paper_id']]['totalNum'], 4) * 100; } } $prevQuery = array(); if ($data['prevPaperIds']) { // 上次考试排名 if(empty($codePrev)){ $prevQuery = $this->sConn->createCommand(" SELECT paper_id, student_id, scoring FROM student_paper_relation WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1' ORDER BY paper_id ASC, scoring DESC ")->queryAll(); }else{ $prevQuery = $this->sConn->createCommand(" SELECT paper_id, student_id, scoring FROM student_paper_relation_".$codePrev." WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1' ORDER BY paper_id ASC, scoring DESC ")->queryAll(); } } if ($prevQuery) { foreach ($prevQuery as $k => $v) { if (isset($data['prevPapers'][$v['paper_id']])) { if (!isset($data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'])) { $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'] = array(); $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'] = array(); $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] = 0; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0; } if (!isset($prevRank[$data['prevPapers'][$v['paper_id']]])) { $prevRank[$data['prevPapers'][$v['paper_id']]] = 0; } if ($data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] > 0) { if ($v['scoring'] == $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][$data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] - 1][1]) { $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] ++; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array( $v['student_id'], $v['scoring'], $prevRank[$data['prevPapers'][$v['paper_id']]] ); } else { $prevRank[$data['prevPapers'][$v['paper_id']]] ++; $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j']; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array( $v['student_id'], $v['scoring'], $prevRank[$data['prevPapers'][$v['paper_id']]] ); } } else { $prevRank[$data['prevPapers'][$v['paper_id']]] ++; $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j']; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array( $v['student_id'], $v['scoring'], $prevRank[$data['prevPapers'][$v['paper_id']]] ); } $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'][$v['student_id']] = $prevRank[$data['prevPapers'][$v['paper_id']]]; $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] ++; } } unset($prevRank); } // 本次考试排名 if(empty($codeNow)){ $query = $this->sConn->createCommand(" SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring FROM student_paper_relation spr JOIN student_info si ON si.student_id = spr.student_id WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1' ORDER BY spr.paper_id ASC, spr.scoring DESC ")->queryAll(); }else{ $query = $this->sConn->createCommand(" SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring FROM student_paper_relation_".$codeNow." spr JOIN student_info si ON si.student_id = spr.student_id WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1' ORDER BY spr.paper_id ASC, spr.scoring DESC ")->queryAll(); } $studentNames = array(); if ($query) { foreach ($query as $k => $v) { if (!isset($data['papers'][$v['paper_id']]['ranks'])) { $data['papers'][$v['paper_id']]['ranks'] = array(); $data['papers'][$v['paper_id']]['_ranks'] = array(); $data['papers'][$v['paper_id']]['_i'] = 0; $data['papers'][$v['paper_id']]['_j'] = 0; } if (!isset($rank[$v['paper_id']])) { $rank[$v['paper_id']] = 0; } if ($data['papers'][$v['paper_id']]['_i'] > 0) { if ($v['scoring'] == $data['papers'][$v['paper_id']]['_ranks'][$data['papers'][$v['paper_id']]['_i'] - 1][1]) { $data['papers'][$v['paper_id']]['_j'] ++; $data['papers'][$v['paper_id']]['_ranks'][] = array( $v['student_id'], $v['scoring'], $rank[$v['paper_id']] ); } else { $rank[$v['paper_id']] ++; $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j']; $data['papers'][$v['paper_id']]['_j'] = 0; $data['papers'][$v['paper_id']]['_ranks'][] = array( $v['student_id'], $v['scoring'], $rank[$v['paper_id']] ); } } else { $rank[$v['paper_id']] ++; $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j']; $data['papers'][$v['paper_id']]['_j'] = 0; $data['papers'][$v['paper_id']]['_ranks'][] = array( $v['student_id'], $v['scoring'], $rank[$v['paper_id']] ); } $data['papers'][$v['paper_id']]['ranks'][] = array( 'studentId' => $v['student_id'], 'realname' => $v['realname'], 'rank' => $rank[$v['paper_id']], ); $data['papers'][$v['paper_id']]['_i'] ++; $studentNames[$v['student_id']] = $v['realname']; } unset($rank); } //班级得分率 $class_topic_rate = array(); if ($class_topic_score) { foreach ($class_topic_score as $_p_id => $t_id_scoring) { if (!isset($class_topic_rate[$_p_id])) { $class_topic_rate[$_p_id] = array(); } foreach ($t_id_scoring as $_t_id => $_t_scoring) { if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) { $class_topic_rate[$_p_id][$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100; }else{ $class_topic_rate[$_p_id][$_t_id] = 0; } } } } unset($class_topic_score); //得分率低于70%的,选择题错的对应的学生名称 if($studentNames && isset($data['papers']) && isset($data['papers'][$v['paper_id']]['topics'])){ foreach ($data['papers'] as $pId => $_topics){ foreach ($_topics['topics'] as $tId => $less70) { foreach ($less70['rateLess70'] as $lessk => $stuId) { if (isset($studentNames[$stuId])) { $data['papers'][$pId]['topics'][$tId]['rateLess70'][$lessk] = $studentNames[$stuId]; } } $data['papers'][$pId]['topics'][$tId]['classRate'] = isset($class_topic_rate[$pId]) && isset($class_topic_rate[$pId][$tId])?$class_topic_rate[$pId][$tId]:0; } } } $data['studentNames'] = $studentNames; unset($studentNames); // 大幅进步、大幅度退步 foreach ($data['papers'] as $key => $val) { if (isset($val['prevRanks']) && isset($val['ranks'])) { foreach ($val['ranks'] as $k => $v) { if (isset($val['prevRanks'][$v['studentId']])) { // 进步 if (!isset($data['papers'][$key]['forwards'])) { $data['papers'][$key]['forwards'] = array(); } if ($val['prevRanks'][$v['studentId']] - $v['rank'] > 0) { if (!isset($data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']])) { $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']] = array(); } $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']][] = array( 'studentId' => $v['studentId'], 'realname' => $v['realname'], 'rank' => $v['rank'], 'prevRank' => $val['prevRanks'][$v['studentId']] ); } // 退步 if (!isset($data['papers'][$key]['rewinds'])) { $data['papers'][$key]['rewinds'] = array(); } if ($v['rank'] - $val['prevRanks'][$v['studentId']] > 0) { if (!isset($data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]])) { $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]] = array(); } $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]][] = array( 'studentId' => $v['studentId'], 'realname' => $v['realname'], 'rank' => $v['rank'], 'prevRank' => $val['prevRanks'][$v['studentId']] ); } } } if (isset($data['papers'][$key]['forwards'])) { krsort($data['papers'][$key]['forwards'], SORT_NUMERIC); } if (isset($data['papers'][$key]['rewinds'])) { krsort($data['papers'][$key]['rewinds'], SORT_NUMERIC); } } if (isset($val['topics'])) { foreach ($val['topics'] as $k => $v) { if (count($v['studentIds']) > 0) { $data['papers'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2); if (isset($data['papers'][$key]['topics'][$k]['fullScore']) && $data['papers'][$key]['topics'][$k]['fullScore'] > 0) { $data['papers'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['papers'][$key]['topics'][$k]['fullScore']), 4) * 100; } } } } } unset($query); // 考试情况分析 if(empty($codeNow)){ $query = $this->sConn->createCommand(" SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id,ptr.stem_id, ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer ,sptr.handlerIndex FROM student_paper_topic_rs sptr JOIN student_paper_relation spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id) JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type) JOIN paper p ON p.paper_id = ptr.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ") ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC ")->queryAll(); }else{ $query = $this->sConn->createCommand(" SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id, ptr.stem_id,ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer ,sptr.handlerIndex FROM student_paper_topic_rs_".$codeNow." sptr JOIN student_paper_relation_".$codeNow." spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id) JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type) JOIN paper p ON p.paper_id = ptr.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ") ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC ")->queryAll(); } if ($query) { //转换试卷中每道题目的序号 $paperNos = $this->transferOrders($data['paperIds'],$is_qxk); //计算出每道必做题 做了的人数 foreach($query as $k => $v){ if (!isset($data['papers'][$v['paper_id']]['doTopicNums'])) {//每道必做题 做了的人数 $data['papers'][$v['paper_id']]['doTopicNums'] = array(); } if (!isset($data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']])) { $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] = 0; } if ($v["handlerIndex"] ==1) { $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] ++; } } foreach ($query as $k => $v) { if($v['stem_id']){ $new_topic_id = (string)$v['stem_id']; }else{ $new_topic_id = (string)$v['topic_id']; } //客观题答案明细 if($v['type'] == 1 && !$score_type){//单选题 if(!isset($data['answer_score_details'][$v['topic_id']])){ $data['answer_score_details'][$v['topic_id']] = array(); $data['answer_score_details'][$v['topic_id']]['answer'] = ''; $data['answer_score_details'][$v['topic_id']]['option']['A'] = 0; $data['answer_score_details'][$v['topic_id']]['option']['B'] = 0; $data['answer_score_details'][$v['topic_id']]['option']['C'] = 0; $data['answer_score_details'][$v['topic_id']]['option']['D'] = 0; $data['answer_score_details'][$v['topic_id']]['order'] = $v['order']; } if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v['answer']])){ $data['answer_score_details'][$v['topic_id']]['option'][$v['answer']]++; } } //type=>3 全学科试卷 多选题 if((in_array($v['type'],array(2,11)) || $is_qxk && $v['type']==3) && !$score_type ){//多选不定项 $v_answer = str_replace(',','',$v['answer']); if(!isset($data['answer_score_details'][$v['topic_id']])){ $data['answer_score_details'][$v['topic_id']] = array(); $data['answer_score_details'][$v['topic_id']]['answer'] = ''; $data['answer_score_details'][$v['topic_id']]['order'] = $v['order']; } if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v_answer])){ $data['answer_score_details'][$v['topic_id']]['option'][$v_answer]++; }else{ $data['answer_score_details'][$v['topic_id']]['option'][$v_answer] = 1; } } if (!isset($data['papers'][$v['paper_id']]['errorNums'])) { $data['papers'][$v['paper_id']]['errorNums'] = array(); } if (!isset($data['papers'][$v['paper_id']]['errorNums'][$v['no']])) { $data['papers'][$v['paper_id']]['errorNums'][$v['no']] = 0; } if ($v['is_right'] != 1 && $v["handlerIndex"] ==1) { $data['papers'][$v['paper_id']]['errorNums'][$v['no']] ++; } if (!in_array((string)$new_topic_id, $data['topicIds'],true)) { $data['topicIds'][] = $new_topic_id; } if (!in_array((string)$v['topic_id'], $data['noTopicIds'],true)) { $data['noTopicIds'][] = (string)$v['topic_id']; } if (!isset($data['papers'][$v['paper_id']]['topicIds'])) { $data['papers'][$v['paper_id']]['topicIds'] = array(); } if (!isset($data['papers'][$v['paper_id']]['noTopicIds'])) { $data['papers'][$v['paper_id']]['noTopicIds'] = array(); } if (!in_array($new_topic_id, $data['papers'][$v['paper_id']]['topicIds'],true)) { $data['papers'][$v['paper_id']]['topicIds'][] = $new_topic_id; } if (!in_array((string)$v['topic_id'], $data['papers'][$v['paper_id']]['noTopicIds'],true)) { $data['papers'][$v['paper_id']]['noTopicIds'][] = (string)$v['topic_id']; } if (!isset($data['papers'][$v['paper_id']]['topicNos'])) { $data['papers'][$v['paper_id']]['topicNos'] = array(); } $data['papers'][$v['paper_id']]['topicNos'][$v['topic_id']] = $v['no']; //带选做题的新序号 if (!isset($data['papers'][$v['paper_id']]['newTopicNos'])) { $data['papers'][$v['paper_id']]['newTopicNos'] = array(); } $data['papers'][$v['paper_id']]['newTopicNos'][$v['topic_id']] = isset($paperNos[$v['paper_id']][$v['topic_id']])?$paperNos[$v['paper_id']][$v['topic_id']]:$v['no']; if (!isset($data['examGroups'][$v['exam_group_id']]['topicIds'])) { $data['examGroups'][$v['exam_group_id']]['topicIds'] = array(); } if (!in_array($v['topic_id'], $data['examGroups'][$v['exam_group_id']]['topicIds'])) { $data['examGroups'][$v['exam_group_id']]['topicIds'][] = $v['topic_id']; } if (!isset($data['examGroups'][$v['exam_group_id']]['rules'])) { $data['examGroups'][$v['exam_group_id']]['rules'] = array(); } $ruleMethodIds = $v['method_ids']; $ruleType =(in_array($v['type'], array(17, 27)) ? 7 : $v['type']); if($is_qxk && $v["method_ids"]){//如果是全学科的考试转变成老知识点 $methodIds = explode(',', $v['method_ids']); $ruleMethodIds = array(); foreach($methodIds as $methodId){ if(isset($qxkKnowledge[$methodId])){ $ruleMethodIds = array_merge($ruleMethodIds,$qxkKnowledge[$methodId]); } } $ruleMethodIds = empty($ruleMethodIds)?"":join(",",$ruleMethodIds); $ruleType = 8; } $data['examGroups'][$v['exam_group_id']]['rules'][$v['topic_id']] = array( 'num' => 1, 'difficulty' => $v['method_difficulty'], 'type' => $ruleType, 'inMethodIds' => $ruleMethodIds, 'eqMethodIds' => $ruleMethodIds, 'callback' => $v['topic_id'], ); $no = $paperNos[$v['paper_id']][$v['topic_id']]; if ($v['method_ids'] && $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']]) { $methodIds = explode(',', $v['method_ids']); foreach ($methodIds as $methodId) { if (!in_array($methodId, $data['methodIds'])) { $data['methodIds'][] = $methodId; } if (!isset($data['papers'][$v['paper_id']]['methodNos'])) { $data['papers'][$v['paper_id']]['methodNos'] = array(); } if (!isset($data['papers'][$v['paper_id']]['methodNos'][$methodId])) { $data['papers'][$v['paper_id']]['methodNos'][$methodId] = array(); } if (!in_array($no, $data['papers'][$v['paper_id']]['methodNos'][$methodId])) { $data['papers'][$v['paper_id']]['methodNos'][$methodId][] = $no; } if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'])) { $data['papers'][$v['paper_id']]['methodErrorNums'] = array(); } if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'][$methodId])) { $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] = 0; } if ($v['is_right'] != 1 && $v['handlerIndex']==1) { $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] ++; } if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'])) { $data['papers'][$v['paper_id']]['methodErrorStudents'] = array(); } if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId])) { $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId] = array(); } if ($v['is_right'] != 1) { if (!in_array($v['student_id'], $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId],true) && $v['handlerIndex']==1) { $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId][] = $v['student_id']; } } if (!isset($data['papers'][$v['paper_id']]['methodFullScores'])) { $data['papers'][$v['paper_id']]['methodFullScores'] = array(); } if (!isset($data['papers'][$v['paper_id']]['methodFullScores'][$methodId])) { $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] = 0; } $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] += $v['score']; if (!isset($data['papers'][$v['paper_id']]['methodScores'])) { $data['papers'][$v['paper_id']]['methodScores'] = array(); } if (!isset($data['papers'][$v['paper_id']]['methodScores'][$methodId])) { $data['papers'][$v['paper_id']]['methodScores'][$methodId] = 0; } $data['papers'][$v['paper_id']]['methodScores'][$methodId] += $v['scoring']; } } } foreach ($data['papers'] as $key => $val) { if (isset($val['errorNums'])) { //重置题号 $i = 1; $newErrorNums = array(); foreach($val['errorNums'] as $k => $v){ $newErrorNums[$i] = $v; $i++; } if($newErrorNums){ $val['errorNums'] = $newErrorNums; $data['papers'][$key]['errorNums'] = $newErrorNums; } foreach ($val['errorNums'] as $k => $v) { if (!isset($data['papers'][$key]['errorRates'])) { $data['papers'][$key]['errorRates'] = array(); } if ($data['papers'][$key]['totalNum'] > 0) { $data['papers'][$key]['errorRates'][$k] = number_format($data['papers'][$key]['errorNums'][$k] / $data['papers'][$key]['totalNum'], 4) * 100; } else { $data['papers'][$key]['errorRates'][$k] = 0; } } } } } } else { echo "文件尚未生成\n"; $error[] = $className."文件尚未生成"; continue; } if ($data['wb_isp_version'] != 1 || $isFromPast) { //个性化版 if (isset($data['examGroups']) && $data['examGroups'] && is_array($data['examGroups'])) { // 抽题 foreach ($data['examGroups'] as $key => $val) { if($same_bs_data){ $data['examGroups'][$key]['fcTopicIds'] = array(); $data['examGroups'][$key]['fcCallbacks'] = array(); foreach($same_bs_data as $sa_k=>$sa_v){ $has_topic_gaokao[] = $sa_k; foreach($sa_v as $sa_v_topic){ $has_topic_gaokao[] = $sa_v_topic; $data['examGroups'][$key]['fcTopicIds'][] = $sa_v_topic; $data['examGroups'][$key]['fcCallbacks'][$sa_k][] = $sa_v_topic; if (!in_array((string)$sa_v_topic, $data['fcTopicIds'])) { $data['fcTopicIds'][] = (string)$sa_v_topic; } } } }else{ if($labelled_type == 2){//教师端标注抽题 $data['examGroups'][$key]['fcTopicIds'] = array(); $data['examGroups'][$key]['fcCallbacks'] = array(); $sql = "select topic_id,relation_id from exam_topic_label where exam_group_id = '{$key}'"; $etl_data = $this->sConn->createCommand($sql)->queryAll(); if($etl_data){ foreach($etl_data as $etl_data_v){ if($etl_data_v['topic_id'] && $etl_data_v['relation_id']){ $relation_topic_arr = explode(",",$etl_data_v['relation_id']); foreach($relation_topic_arr as $relation_topic_v){ if (!in_array((string)$relation_topic_v, $data['fcTopicIds'])) { $data['fcTopicIds'][] = (string)$relation_topic_v; } $data['examGroups'][$key]['fcTopicIds'][] = $relation_topic_v; $data['examGroups'][$key]['fcCallbacks'][$etl_data_v['topic_id']][] = $relation_topic_v; $has_topic_gaokao[] = $relation_topic_v; } $has_topic_gaokao[] = $etl_data_v['topic_id']; } } } }else{ if (isset($val['rules'])) { $fc = $this->apiPost('/isp/ai', array( 'schoolId' => $v_data['school_id'], 'rules' => $val['rules'], 'notInTopicIds' => $data['examGroups'][$key]['topicIds'], )); if ($fc && !isset($fc->error)) { $data['examGroups'][$key]['fcTopicIds'] = array(); $data['examGroups'][$key]['fcCallbacks'] = array(); foreach ($fc as $k => $v) { if (!in_array($v->id, $data['fcTopicIds'])) { $data['fcTopicIds'][] = $v->id; } $data['examGroups'][$key]['fcTopicIds'][] = $v->id; $data['examGroups'][$key]['fcCallbacks'][$v->callback][] = $v->id; $has_topic_gaokao[] = $v->id; $has_topic_gaokao[] = $v->callback; } } } } } } $topicDetails=array(); $topicItems_1 = $this->apiPost('/topic/batchAll', array('topicIds' => array_merge( $data['topicIds'], (isset($data['fcTopicIds']) ? $data['fcTopicIds'] : array()) ))); if (isset($topicItems_1->error)) { $error[] = $className.$topicItems_1->error; } elseif (! $topicItems_1) { $error[] = $className.'Error in pumping system[2]'; } else { foreach ($topicItems_1 as $topicItem) { $topicDetails[$topicItem->id] = (object)$topicItem; } } if ($topicDetails) { foreach ($topicDetails as $k => $v) { $v=(array)$v; $v['id'] = (string)$v['id']; $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:""; if(!$teacher_tips){ $teacher_tips = $this->dealTeacherTips($v); } $v['teacher_tips'] = $this->topicProcess($teacher_tips); $v['parse_content'] = $this->topicProcess($v['parse_content']); if($v['type_id'] == 5){ $v['title'] = preg_replace("/]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']); } $v['title'] = $this->topicProcess($v['title']); if(isset($v['items'][0])){ $v['items'][0]=(array)$v['items'][0]; $v['items'][0]['options']=(array)$v['items'][0]['options']; if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) { foreach ($v['items'][0]['options'] as $key => $val) { $val=(array)$val; $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key]; $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']); if(isset($data['answer_score_details'][$v['id']]) && $val['option_correct'] == 1){ $data['answer_score_details'][$v['id']]['answer'] .= $this->numToLetter($key + 1); } } } } $data['topicDetails'][$v['id']] = $v; } unset($topicDetails); } } } else { //分层版 //获取原题以及对应四个层次的提分题 //$preparation_plan_id = $exam['preparation_plan_id']; if($data['level_rule'] == 1){ $isDiffMin = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId." and is_diff_min = 1")->queryAll(); if($isDiffMin){ $plan_topic_res = $isDiffMin; }else{ $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll(); if($plan_topic_res){ $topicsOrigin = array(); $topicRelation = array(); foreach($plan_topic_res as $k=>$v){ $topicsOrigin[] = $v['template_id']; $topicRelation[$v['template_id']][] = $v; $has_topic_gaokao[] =$v['template_id']; $has_topic_gaokao[] =$v['topic_id']; } if($topicsOrigin){ $topicsOrigin = array_unique($topicsOrigin); $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicsOrigin)); if (!$topicDetails) { echo "获取接口batchALL无数据!\n"; $error[] = $className."无数据"; continue; } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) { echo $topicDetails['error'][0]."\n"; $error[] =$className.$topicDetails['error'][0]; continue; } $topicDiff = array(); foreach($topicDetails as $k=>$v){ if(isset($v['difficulty_degree'])){ $diff = $v['difficulty_degree']; }elseif(isset($v['experience_degree'])){ $diff = $v['experience_degree']; }else{ $diff = 0; } $topicDiff[$v['id']] = $diff; } $new_plan_topic_res = array(); foreach($topicDiff as $k=>$v){ if(isset($topicRelation[$k])){ $arr1 = array(); $arr2 = array(); foreach($topicRelation[$k] as $relation){ $arr1[] = $relation['difficulty_degree']; } $x=$v; $count=count($arr1); for ($i=0; $i <$count ; $i++) { $arr2[]=abs($x-$arr1[$i]); } $min= min($arr2); for ($i=0; $i <$count ; $i++) { if ($min==$arr2[$i]) { $new_plan_topic_res[] = $topicRelation[$k][$i]; break 1; } } } } } $plan_topic_res = $new_plan_topic_res; } } }else{ $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll(); } if (!$plan_topic_res) { echo "文件尚未生成\n"; $error[] = $className."文件尚未生成"; continue; } $template_topic_arr = array(); $isp_id_arr = array(); foreach ($plan_topic_res as $v) { $template_id = $v['template_id']; $level = $v['level']; $topic_id = $v['topic_id']; if (!isset($template_topic_arr[$template_id])) { $template_topic_arr[$template_id] = array(); } $template_topic_arr[$template_id][$level] = $topic_id; $isp_id_arr[] = $topic_id; } //试卷中校本题库题是哪些,云题库题是哪些 $sch_id_arr = array(); //试卷中校本题库题是哪些 $yun_id_arr = array(); $sql = 'select topic_id,mode,type,no from paper_topic_relation ptr join paper p on p.paper_id = ptr.paper_id where p.exam_id=' . $examId; $paper_topic_res = $this->sConn->createCommand($sql)->queryAll(); if (!$paper_topic_res) { echo "文件尚未生成\n"; $error[] = $className."文件尚未生成"; continue; } $topic_no_arr = $this->getTopicNoByPaper($paper_topic_res, $exam['tpl_index']); //获取每道题在试卷中的序号,如 21A,21B foreach ($paper_topic_res as $v) { $v['mode'] == 1 && $sch_id_arr[] = $v['topic_id']; $v['mode'] == 0 && $yun_id_arr [] = $v['topic_id']; } $isp_id_arr = array_merge($isp_id_arr, $yun_id_arr); //获取所有以上题目的详情,以供显示到教师讲案中 $topic_detail_arr = $this->paperTopicDetail($isp_id_arr, $sch_id_arr, $examId,'分层提分题'); if (!$topic_detail_arr) { echo "获取不到试卷题目内容\n"; $error[] = $className."获取不到试卷题目内容"; continue; } foreach($topic_detail_arr as $k_topic=>$v_topic){ if(isset($data['answer_score_details'][(string)$k_topic])){ $data['answer_score_details'][(string)$k_topic]['answer'] = isset($v_topic['answer_format'])?$v_topic['answer_format']:''; } } $diff_id_arr = array_diff($isp_id_arr + $sch_id_arr, array_keys($topic_detail_arr)); if ($diff_id_arr) { //todo 发送消息到补提 echo "请等待题库老师补题!\n"; $error[] = $className."请等待题库老师补题!"; continue; } else { $data['template_topic_arr'] = $template_topic_arr; $data['topic_details'] = $topic_detail_arr; $data['topic_no_arr'] = $topic_no_arr; unset($template_topic_arr); unset($topic_detail_arr); } } // 获取考点名称 if (isset($data['methodIds']) && $data['methodIds']) { if($is_qxk){ $methods = $this->apiPost('/all_knowledge/knowledge_name', array('knowledgeIds' => $data['methodIds'])); if ($methods && isset($methods->data) && $methods->data) { foreach ($methods->data as $k => $v) { $data['methodNames'][$k] = $v; } unset($methods); } }else{ $methods = $this->apiPost('/special/methods', array('methodIds' => $data['methodIds'])); if ($methods) { foreach ($methods as $k => $v) { $data['methodNames'][$v->method_id] = $v->method_name; } unset($methods); } } } if (isset($data['examGroupIds']) && $data['examGroupIds'] && is_array($data['examGroupIds'])) { // $this->sConn->active = false; // $this->sConn = $this->getDbConnection(); $this->sConn->active = false; $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]); $this->sConn = $sConn; $query = array(); if(empty($codeNow)){ $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex FROM student_paper_topic_rs sptr JOIN paper p ON p.paper_id = sptr.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ")"; }else{ $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex FROM student_paper_topic_rs_".$codeNow." sptr JOIN paper p ON p.paper_id = sptr.paper_id JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") "; } $sptrData = $this->sConn->createCommand($sql)->queryAll(); if($sptrData){ $paperTopic = array(); $paperIds = array(); foreach($sptrData as $k=>$v){ if(!in_array($v['paper_id'], $paperIds)){ $paperIds[] = $v['paper_id']; } } if($paperIds){ $sql = "select score,paper_id,topic_id from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")"; $ptrData = $this->sConn->createCommand($sql)->queryAll(); if($ptrData){ foreach($ptrData as $k=>$v){ $paperTopic[$v['paper_id']][$v['topic_id']] = $v['score']; } unset($ptrData); } if($paperTopic){ foreach($sptrData as $k=>$v){ if(isset($paperTopic[$v['paper_id']]) && isset($paperTopic[$v['paper_id']][$v['topic_id']])){ $sptrData[$k]['score'] = $paperTopic[$v['paper_id']][$v['topic_id']]; } } $query = $sptrData; } } unset($sptrData); } /////////newending /// $grade_topic_score = array(); if ($query) { foreach ($query as $k => $v) { if (!isset($data['examGroups'][$v['exam_group_id']]['topics'])) { $data['examGroups'][$v['exam_group_id']]['topics'] = array(); } if (!isset($data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']])) { $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']] = array(); $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score']; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] = 0; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgScore'] = 0; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgRate'] = 0; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] = 0; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong'] = 0; $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'] = array(); } $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring']; if ($v['is_right'] == 1) { $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] ++; } else { if($v["handlerIndex"]==1) {//必做题 $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong']++; } } if($v["handlerIndex"]==1) {//必做题 $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id']; } //年级得分 if (!isset($grade_topic_score[$v['topic_id']])) { $grade_topic_score[$v['topic_id']] = array(); } $grade_topic_score[$v['topic_id']][] = $v['scoring']; } foreach ($data['examGroups'] as $key => $val) { if (isset($val['topics'])) { foreach ($val['topics'] as $k => $v) { if (count($v['studentIds']) > 0) { $data['examGroups'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2); if (isset($data['examGroups'][$key]['topics'][$k]['fullScore']) && $data['examGroups'][$key]['topics'][$k]['fullScore'] > 0) { $data['examGroups'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['examGroups'][$key]['topics'][$k]['fullScore']), 4) * 100; } } } } } } } $grade_topic_rate = array(); if ($grade_topic_score) { foreach ($grade_topic_score as $_t_id => $_t_scoring) { if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) { $grade_topic_rate[$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100; }else{ $grade_topic_rate[$_t_id] = 0; } } } unset($grade_topic_score); unset($topic_score_arr); //高考真题 $data['gaokao_topic'] = array(); if($grade == 3){ $gaokao_topic = array(); $sql = "select topic_id from gaokao_academicr_topic where class_id ='{$classId}'"; $gaokao_data = $this->sConn->createCommand($sql)->queryAll(); if($gaokao_data){ foreach($gaokao_data as $gao){ $gaokao_topic[] = $gao['topic_id']; } } if($gen_origin_methods){ $weak_methodids = array_keys($gen_origin_methods); }else{ $weak_methodids = array(); } if($paper_method_ids){ $paper_methodids = explode(",",$paper_method_ids); }else{ $paper_methodids = array(); } if($has_topic_gaokao){ $has_topic = $has_topic_gaokao; }else{ $has_topic = array(); } $gaokao_topic = $this->acadGaokao($examId,$classId,$has_topic,$weak_methodids,$paper_methodids); if($gaokao_topic){ $topicBatchs = $this->aipost('topic/batchall', array('topicIds' => $gaokao_topic)); if ($topicBatchs && !isset($topicBatchs->error)) { $data['gaokao_topic'] = $this->formatDetails($topicBatchs); } } } //整理客观题明细数据 if($data['answer_score_details']){ $new_answer_score_details = array(); $a = 0; foreach($data['answer_score_details'] as $k=>$v){ if(isset($v['option']) && $v['option']){ foreach($v['option'] as $option_type=>$option_count){ $new_answer_score_details[$a]['id'] = $k; $new_answer_score_details[$a]['order'] = $v['order']; $new_answer_score_details[$a]['answer'] = $v['answer']?$v['answer']:''; $new_answer_score_details[$a]['option'] = $option_type; $new_answer_score_details[$a]['option_count'] = $option_count; $a++; } } } $data['answer_score_details'] = $new_answer_score_details; } // $this->sConn->active = false; // 关闭连接 close(); if (isset($data['papers']) && $data['papers'] && is_array($data['papers'])) { // 渲染 foreach ($data['papers'] as $key => $val) { if (!isset($val['examId']) || !$val['examId']) continue; if (!isset($val['examGroupId']) || !$val['examGroupId']) continue; // $classname = ClassModel::model()->getClassName($classId); $data = array_merge($val, array( 'methodNames' => (isset($data['methodNames']) ? $data['methodNames'] : array()), 'topicDetails' => (isset($data['topicDetails']) ? $data['topicDetails'] : array()), 'groupTopics' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['topics']) ? $data['examGroups'][$val['examGroupId']]['topics'] : array()), 'fcCallbacks' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['fcCallbacks']) ? $data['examGroups'][$val['examGroupId']]['fcCallbacks'] : array()), 'wb_isp_version' => isset($data['wb_isp_version']) ? $data['wb_isp_version'] : 0, 'template_topic_arr' => isset($data['template_topic_arr']) ? $data['template_topic_arr'] : array(), 'topic_details' => isset($data['topic_details']) ? $data['topic_details'] : array(), 'topic_no_arr' => isset($data['topic_no_arr']) ? $data['topic_no_arr']: array(), 'level_rule' => isset($data['level_rule']) ? $data['level_rule'] : 0, 'gradeTopicRate' => $grade_topic_rate, 'studentNames'=>isset($data['studentNames']) ? $data['studentNames'] : array(), 'excellent_solution'=>isset($data['excellent_solution']) ? $data['excellent_solution'] : array(), 'gen_topics'=>isset($data['gen_topics']) ? $data['gen_topics'] : array(), 'gen_topics_detail'=>isset($data['gen_topics_detail']) ? $data['gen_topics_detail'] : array(), 'gen_topics_msg'=>isset($data['gen_topics_msg']) ? $data['gen_topics_msg'] : array(), 'answer_score_details'=>isset($data['answer_score_details']) ? $data['answer_score_details'] : array(), 'gen_origin_methods'=>isset($data['gen_origin_methods'])?$data['gen_origin_methods']:'', 'gaokao_topic'=>isset($data['gaokao_topic'])?$data['gaokao_topic']:array(), 'setting_arr'=>isset($setting_arr)?$setting_arr:array(), 'grade_topic_data'=>isset($data['grade_topic_data']) ? $data['grade_topic_data'] : array(), 'is_qxk'=>$is_qxk, ) ); $data['className'] = $className; // $html = $this->renderPartial("academicr", $data, true); $data['imgUrl'] = $file_html_url; //是否是精准学习宝学校 $http = http('customer/precision-learning-school/check/'.$v_data['school_id'], 'GET', $authUsername); $response = formatResponse($http); $data['isPrecise'] = isset($response['data']) ? $response['data'] : 0; //教师姓名 $sql = "select t.teacher_id,t.teacher_name from teacher t join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id where tcr.class_id = '{$classId}' and tcr.semester_id = '{$semesterId}' and t.subjects=3"; $teacher_msg = $this->sConn->createCommand($sql)->queryRow(); if($teacher_msg){ $data['teacherName'] = $teacher_msg['teacher_name']; } $html = $this->viewRender("academicr_1", $data, true); //unset($data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); }else{ exec('chown -R www:www '.$htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); }else{ exec('chown -R www:www '.$pdfpath); } } $htmlpath.=$examId . ".html"; echo "开始写入html\n"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); echo "写入html结束\n"; $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径 if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html"; // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']); // $pdffname = str_replace(" ", "", $pdffname) . ".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time()); $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf_math.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm '{$header_str}'"; } else { $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); // echo Yii::app()->params['phantomjs'];exit; $htmlurl = $file_html_url . $htmlurl; // $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']); // $pdffname = str_replace(" ", "", $pdffname) . ".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time()); $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf_math.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm '{$header_str}'"; } echo "开始转pdf\n"; exec($commond, $res, $code); echo "转pdf结束\n"; $ucloud = new HuaweiCloud(); //上传html $rehtml = $examId.".html"; $rehtmlname = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $rehtml; $uploadHtmlInfo = $ucloud->putFile($rehtmlname, $htmlpath); if($uploadHtmlInfo['status'] == 0){ // $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl; $html_url = $file_html_url.$htmlurl; }else{ $html_url = $uploadHtmlInfo['url']; @unlink($htmlpath); } $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url), "exam_id = '{$examId}'"); if(isset($res[0])){ if (strpos($res[0], 'succeed') !== false) {//命令返回成功 if ($this->file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $repdf = $examId.".pdf"; $rename = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf; echo "开始上传ucloud\n"; $uploadInfo = $ucloud->putFile($rename, $pdfpath); echo "上传ucloud结束\n"; //@unlink($pdfpath); if ($uploadInfo['status'] == 0) { echo "PDF文件上传失败\n"; echo $uploadInfo['msg']."\n"; $error[] = $className."PDF文件上传失败"; }else{ $this->sConn->active = false; $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]); $this->sConn = $sConn; $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url,"academicr_pdf_path" => $uploadInfo['url'], "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'"); $pdfArr[] = $pdfpath; $pdfNames[] = $className; // @unlink($htmlpath); } //echo $htmlpath;exit; // @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 "PDF文件未找到\n"; $error[] = $className."PDF文件未找到"; } } else { // @unlink($htmlpath); echo "PDF创建失败1\n"; $error[] = $className."PDF创建失败1"; } }else{ // Curl::post(Yii::app()->params['handle_log_api'], array( // "exam_group_id" => (string)$val['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 "PDF创建失败2!\n"; $error[] = $className."PDF创建失败2!"; } } } else { echo "渲染失败!\n"; $error[] = $className."渲染失败!"; // throw new CException("系统错误"); } }else{ $pdfArr[] = $pdfpath; $pdfNames[] = $className; } } } // var_dump($pdfArr); foreach($pdfArr as $k=>$v){ if(strpos($v,'http') !== false){ $new_dir_url = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; if (!is_dir($new_dir_url)) { if (!mkdir($new_dir_url, 0777, true)) { echo 'Create directory fail1: ' . $new_dir_url. "\n"; }else{ exec('chown -R www:www '.$new_dir_url); } } $new_file_url = $this->downImgRar($v,$new_dir_url,$k); $pdfArr[$k] = $new_file_url; // echo $new_file_url;exit; } } //var_dump($pdfArr);exit; $this->conn->active = false; $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); $this->conn = $conn; if($pdfArr){ echo "开始压缩文件\n"; if($pdfArr){ echo $examName.'pdf生成成功!'. "\n"; // $report_name = $class_name.$year."年度报告.zip"; $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; //存放生成的PDF路径 if (!is_dir($filepath)) { if (!mkdir($filepath, 0777, true)) { echo 'Create directory fail1: ' . $filepath. "\n"; }else{ exec('chown -R www:www '.$filepath); } } $examName = iconv("UTF-8","GBK//IGNORE",$examName); $filename = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/".$v_data['exam_group_id'].".zip"; //最终生成的文件名(含路径) $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) { echo $examName.'zip生成失败!'. "\n"; }else{ foreach ($pdfArr as $k=>$val) { // $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]); $pdfname = '-'.$pdfNames[$k].'-教师讲案'; $pdfname = iconv("UTF-8","GBK//IGNORE",$pdfname); $res=$zip->addFile($val,$examName.$pdfname.'.pdf'); //@unlink($pdfArr[$k]); } $zip->close();//关闭 foreach($pdfArr as $k=>$val){ @unlink($val); } //生成完成 // $filename = addslashes($filename); $time = time(); $filename = $this->characet($filename); $ucloud = new HuaweiCloud(); $filename = iconv("UTF-8","GBK//IGNORE",$filename); $examName = $this->characet($examName); $meg = $ucloud->putFile('zsyas2/academicr_batch/'.$v_data['exam_group_id'].'/'.$v_data['id'].'/'.$examName.'.zip',$filename); if($meg['status'] == 0){ $error[] = $className.$meg['msg']; }else{ $url = $meg['url']; $url = str_replace("%2F","/",$url); $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); $is_success = 1; echo $examName.'zip生成成功!'. "\n"; } @unlink($filename); // if($pdfArr){ // $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}"; // $this->conn->createCommand($sql)->execute(); // echo $examName.'zip生成成功!'. "\n"; // } } }else{ echo 'pdf生成失败!'. "\n"; } } }else{ echo '连接学校ID'.$v_data['school_id']."失败\n"; continue; } }else{ echo '暂无学校ID'.$v_data['school_id']."的信息\n"; continue; } $this->sConn->active = false; } if(!$is_success){ if($error){ $time = time(); $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time},status=3 where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); echo $examName.'zip生成失败!'. "\n"; }else{ $time = time(); $sql = "update download_table_setting set update_time = {$time},status=3 where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); echo $examName.'zip生成失败!'. "\n"; } }else{ if($error){ $time = time(); $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time} where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); } } // $this->conn->active = false; } }catch(Exception $e){ $sql = "update download_table_setting set status=3,error_msg='系统异常' where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); echo $e->getMessage(); } } }else{ echo "暂无要生成的数据\n"; } $this->conn->active = false; }else{ echo "连接业务库失败\n"; } } function characet($data){ if( !empty($data) ){ $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ; if( $fileType != 'UTF-8'){ $data = mb_convert_encoding($data ,'utf-8' , $fileType); } } return $data; } public function apiPost($path, $arr, $type = 0) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $url = Yii::app()->params['api'][$type]['prefix'] . $path; $username = Yii::app()->params['api'][$type]['username']; $password = Yii::app()->params['api'][$type]['password']; // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data), )); if (!curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); } return $result; } public function aipost($url, $array = array(), $timeout = 5, $type = 0) { $url = Yii::app()->params['api'][$type]['prefix'] . $url; $username = Yii::app()->params['api'][$type]['username']; $password = Yii::app()->params['api'][$type]['password']; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); if ($array) { $array = http_build_query($array); curl_setopt($ch, CURLOPT_POSTFIELDS, $array); } //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); if (!curl_errno($ch)) { $result = json_decode($data, 1); return $result; } curl_close($ch); return false; } private function check_zip($file_path) { if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") { if (file_exists($file_path)) { return true; } } return false; } /** * 获取接口数据 * @param $url * @param $method * @param array $params * @return array */ private function getHttp($url,$method,$params = array()){ $res = http($url, $method, $this->authUsername, $params); $res = $this->handleRes($res); return $res; } /** * 处理接口返回的数据 * @param $res * @return array */ public function handleRes($res){ $result = array( 'status' => 0, 'data' => array(), 'msg' => '暂无数据', ); if($res){ $res = json_decode($res,true); if(isset($res['errCode']) && $res['errCode'] == '00'){ $result['status'] = 1; $result['data'] = isset($res['data'])?$res['data']:array(); $result['msg'] = $res['errMsg']; }else{ if(isset($res['errMsg'])){ $result['msg'] = $res['errMsg']; } } } unset($res); return $result; } function file_exists($url) { $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $contents = curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) { return false; } return true; // $ch = curl_init(); // curl_setopt ($ch, CURLOPT_URL, $url); // //不下载 // curl_setopt($ch, CURLOPT_NOBODY, 1); // //设置超时 // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // curl_setopt($ch, CURLOPT_TIMEOUT, 3); // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // curl_exec($ch); // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // if($http_code == 200) { // return true; // } // return false; } public function viewRender($viewName, $data) { extract($data, EXTR_PREFIX_SAME,'data'); ob_start(); ob_implicit_flush(0); require(dirname(dirname(dirname(__FILE__))).'/protected/views/export/'.$viewName . '.php'); return ob_get_clean(); } public function getDbConnection($database_host,$database_name,$database_user,$database_password) { if($database_host && $database_name && $database_user && $database_password){ $myDbDsn = 'mysql:host=' . $database_host . ';dbname=' . $database_name; $my_connection = new CDbConnection($myDbDsn, $database_user, $database_password); $my_connection->emulatePrepare = true; $my_connection->enableProfiling = true; $my_connection->enableParamLogging = true; $myDbDsn = null; return $my_connection; }else{ return null; } } private function img_process($img) { $widthArr = array(); $heightArr = array(); $width = ''; $height = ''; if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr)) { $width = $this->length_process($widthArr); } else { if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr)) { $width = $this->length_process($widthArr); } } if ($width) { $width = "width=".$width; } if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr)) { $height = $this->length_process($heightArr); } else { if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$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; } private function length_process($length_arr){ $length = 0.6*$length_arr[1]; $unit_keys = array_keys($this->units); if (isset($length_arr[2])) { //将直接连接单位改为 单位换算 if(in_array($length_arr[2],$unit_keys)){ $length = $length*$this->units[$length_arr[2]]; }else { $length .= $length_arr[2]; } } return $length; } public function getCodeByExamId($examId){ $code = 0; $sql = "select s.status,s.refer_code from exam e join semester s on e.semester_id = s.semester_id where e.exam_id = '{$examId}'"; $data_sem = $this->sConn->createCommand($sql)->queryRow(); if($data_sem && $data_sem['status'] != 1){ $code = $data_sem['refer_code']?$data_sem['refer_code']:0; } return $code; } 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; } function get_version($class_id) { if($class_id){ $sql = 'select show_level,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id; $product_res = $this->sConn->createCommand($sql)->queryRow(); if (!$product_res) { //没有找到班级与设置的关系表 $sql = 'select wb_isp_version from class where class_id='.$class_id; $res = $this->sConn->createCommand($sql)->queryRow(); return $res['wb_isp_version']; } else { if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置 $sql = 'select wb_isp_version from class where class_id='.$class_id; $res = $this->sConn->createCommand($sql)->queryRow(); return $res['wb_isp_version']; } else{ return $product_res['show_level']; } } } return 0; } function get_level_rule($class_id) { if($class_id){ $sql = 'select level_rule,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id; $product_res = $this->sConn->createCommand($sql)->queryRow(); if (!$product_res) { //没有找到班级与设置的关系表 return 0; } else { return $product_res['level_rule']; } } return 0; } function transferOrders($paperIds,$is_qxk=0) { $sql = 'select paper_id,topic_id,type,`order`,`stem_id` from paper_topic_relation where paper_id in ('.implode(',',$paperIds).') order by paper_id, type asc,`order` asc'; $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll(); $sql = 'select tpl_index,tpl_data,paper_id from exam e join paper p on e.exam_id = p.exam_id where p.paper_id in ('.implode(',',$paperIds).')' ; $tpl_index_res = $this->sConn->createCommand($sql)->queryAll(); $tpl_index_arr = array(); $changeDoToicNo = $tpl_data_arr = array(); foreach ($tpl_index_res as $v) { $tpl_index_arr[$v['paper_id']] = $v['tpl_index']; if($v['tpl_data']){ $v['tpl_data'] = preg_replace('/:\s*(-?\d{15,})/', ': "$1"', $v['tpl_data']);//把15位的int转成string $tplData = json_decode($v['tpl_data'],true); if($tplData){ $tplstatus = 0; if(isset($tplData['tplstatus'])){ $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus']; }else{ $tpl_data_arr[$v['paper_id']] = 0; } } } //选做题题号 if (isset($tplData['new_items']) && $tplData['new_items']) { $new_items = array_values($tplData['new_items']); foreach ($new_items as $key => &$item) { if (isset($item['sameAliasNo']) && $item['sameAliasNo']>0) { $no =$item['alias']; $item['topicId'] = (string)$item['topicId']; $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["sameAliasNo"] = $item['sameAliasNo'];//选做题组id $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["smTopicLen"] = $item['smTopicLen'];//选做题组必做数量 $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["no"] = $no;//题号 $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["topicId"] = $item['topicId'];//题目id $changeDoToicNo[$v['paper_id']]["gather"][$item['sameAliasNo']][]=$item['topicId']; } } } } $paper_topcic_relation_arr = array(); foreach ( $paper_topcic_relation_res as $v) { $paper_id = $v['paper_id']; $type = $v['type']; $order = $v['order']; $topic_id = $v['topic_id']; $stem_id = (string)$v['stem_id']; if (!isset($paper_topcic_relation_arr[$paper_id])) { $paper_topcic_relation_arr[$paper_id] = array(); } $paper_topcic_relation_arr[$paper_id][] = array( 'type' => $type, 'order' => $order, 'topic_id'=>$topic_id, 'stem_id'=>$stem_id ); } $paper_topic_no_arr = array(); foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) { $tpl_index = $tpl_index_arr[$paper_id]; $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0; $change_do_toicno = isset($changeDoToicNo[$paper_id])?$changeDoToicNo[$paper_id]:array(); $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus,$is_qxk,$change_do_toicno); } return $paper_topic_no_arr; } function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus,$is_qxk=0,$change_do_toicno=array()) { $topic_no_arr = array(); //每道题的序号 if($is_qxk){ $_order = 1; $small_no = 1; $temp_stem_arr = array(); foreach($paper_topcic_relation_arr as $v){ if(isset($v['stem_id']) && $v['stem_id']){ $temp_stem_arr[$v['stem_id']][] = $v['topic_id']; } } foreach ($paper_topcic_relation_arr as $v) { if(!isset($temp_stem_arr[$v['stem_id']]) || count($temp_stem_arr[$v['stem_id']]) == 1){ if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) && count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题 if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) { $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]]; } else { $change_no = 65;//从A开始 } $topic_no_arr[$v['topic_id']] = $_order . chr($change_no); $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no +1; }else{ $topic_no_arr[$v['topic_id']] = $_order; $_order++; } $small_no = 1; }else{ if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) && count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题 if(isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])){ $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]]; }else{ $change_no = 65;//从A开始 } $_order = $_order . chr($change_no); } $topic_no_arr[$v['topic_id']] = $_order.'('.$small_no.')'; if($small_no == count($temp_stem_arr[$v['stem_id']])){ $small_no = 1; $_order++; } $small_no++; } } }else if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来 $prefix_no = 0; $num = 0; $index_arr = array('A','B','C','D','E'); $_order = 0; foreach($paper_topcic_relation_arr as $v) { if (!$prefix_no && $v['type'] == 17) { $_order += 1; //序号加1 $prefix_no = $_order; $topic_no_arr[$v['topic_id']] = $prefix_no.'A'; } elseif ($prefix_no && $v['type'] == 17) { $num += 1; $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num]; } if ($v['type'] == 27) { $prefix_no += 1; $topic_no_arr[$v['topic_id']] = $prefix_no; } if ($v['type'] != 17 && $v['type'] != 27){ $_order += 1; $topic_no_arr[$v['topic_id']] = $_order; } } } else { //其他模板都是根据order就行 $_order = 0; foreach ($paper_topcic_relation_arr as $v) { if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) && count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题 if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) { $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]]; } else { $change_no = 65;//从A开始 $_order += 1; } $topic_no_arr[$v['topic_id']] = $_order . chr($change_no); $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no + 1; }else{ $_order += 1; $topic_no_arr[$v['topic_id']] = $_order; } } } return $topic_no_arr; } private function topicProcess($html) { if (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;
if(preg_match_all("/http:\/\/zxhx[\s\S]*?png/i",$html,$matches)){
$need_replace = array();
foreach($matches[0] as $v){
//$image_info = getimagesize($v);
$er = 'data:image/png;base64,' . chunk_split(base64_encode(file_get_contents($v)));
$need_replace[] = array(
"origin_url" => $v,
"after_url" => $er
);
}
unset($matches);
if($need_replace){
foreach($need_replace as $v){
$html = str_replace($v["origin_url"],$v["after_url"],$html);
}
unset($need_replace);
}
}
return $html;
}
private function getTopicNoByPaper($paper_topcic_relation_arr, $tpl_index)
{
$topic_no_arr = array(); //每道题的序号
if ($tpl_index == 10 || $tpl_index == 1010) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
$prefix_no = 0;
$num = 0;
$index_arr = array('A','B','C','D','E');
foreach($paper_topcic_relation_arr as $v) {
if (!$prefix_no && $v['type'] == 17) {
$prefix_no = $v['no'];
$topic_no_arr[$v['topic_id']] = $prefix_no.'A';
} elseif ($prefix_no && $v['type'] == 17) {
$num += 1;
$topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
}
if ($v['type'] == 27) {
$prefix_no += 1;
$topic_no_arr[$v['topic_id']] = $prefix_no;
}
if ($v['type'] != 17 && $v['type'] != 27){
$topic_no_arr[$v['topic_id']] = $v['no'];
}
}
} else {
foreach ($paper_topcic_relation_arr as $v) {
$topic_no_arr[$v['topic_id']] = $v['no'];
}
}
return $topic_no_arr;
}
private function paperTopicDetail($yun_id_arr, $sch_id_arr, $exam_id, $typestr) {
try {
$all_id_arr = array_merge($yun_id_arr,$sch_id_arr);
if (!$all_id_arr ) {
return false;
}
$data = array();
$total_count = count($all_id_arr);
$page_size = 100;
$page = ceil($total_count/$page_size);
for ($i = 0; $i<$page; $i++) {
$offset = $i * $page_size;
$id_arr = array_slice($all_id_arr,$offset, $page_size);
$topicBatchs = $this->apiPost('topic/batchall', array('topicIds' => $id_arr));
if (!$topicBatchs) {
throw new Exception('获取接口topic/batchALL数据时无任何返回,type is '.$typestr.' ,exam_id is ('.$exam_id.')');
}if(isset($topicBatchs->status) && $topicBatchs->status == 0 ){
throw new Exception($topicBatchs->error[0]);
} else{
$data += $this->formatDetails($topicBatchs);
}
}
return $data;
} catch (Exception $e) {
return false;
}
}
public function formatDetails($topicBatches) {
$optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
$topicDetails = array();
foreach ($topicBatches AS $ke=>$topic) {
if(!isset($topic["teacher_tips"]) || !$topic["teacher_tips"]){
$topicBatches[$ke]["teacher_tips"] = $this->dealTeacherTips($topic);
}
$topic = (object) $topic;
$topic->id = (string)$topic->id;
$type = $topic->type_id;
6 == $type && $type = 5; //6表示多空题,多空题也是5
$topicDetails[$topic->id] = array();
$topicDetails[$topic->id]['type'] = $type;
$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;
$topicDetails[$topic->id]['type_name'] = $topic->type_name;
$topicDetails[$topic->id]['source'] = $topic->source;
$_methods = array();
$_method_id_arr = 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;
}
}
$topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点
$topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
}
$_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 == 2) { //选择题有选项
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();
$anwer_str = "";
foreach ($options AS $_optionIndex => $_option) {
$_option = (object) $_option;
$_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
if ($_option->option_correct) {
if($anwer_str == ""){
$anwer_str = $this->topicProcess($optionIndex[$_optionIndex]);
// $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]);
}else{
$anwer_str .= "、".$this->topicProcess($optionIndex[$_optionIndex]);
}
}
}
$topicDetails[$topic->id]['answer'] = $anwer_str;
$topicDetails[$topic->id]['answer_format'] = str_replace('、', '', $anwer_str);
$_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);
}
}
}
}
}
}
return $topicDetails;
}
private 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 = "";
foreach ($options as $key => $option) {
$option_str.="