-1) { $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled); if($paper_exam) { foreach($paper_exam as $v) { $s_exam_ids[$v['exam_id']] = $v['exam_id']; } } unset($paper_exam); } // 年级条件 if($grade>0) { $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId); if($class_data) { foreach($class_data as $v) { $class_ids[$v['class_id']] = $v['class_id']; } $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids); if($exam_class_data) { foreach($exam_class_data as $v) { if(isset($s_exam_ids[$v['exam_id']])) { $l_b_exam_ids[$v['exam_id']] = $v['exam_id']; }else { $s_exam_ids[$v['exam_id']] = $v['exam_id']; } } } unset($exam_class_data); } unset($class_data); } if(isset($l_b_exam_ids)) { if($l_b_exam_ids) { $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")"; }else { $condition[] = "e.exam_id in (0)"; } }else { if($labelled<0||$grade<1) { if(isset($s_exam_ids)) { if($s_exam_ids) { $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")"; }else { $condition[] = "e.exam_id in (0)"; } } }else { $condition[] = "e.exam_id in (0)"; } } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "e.subject_id = '{$this->subjectId}'"; } if ( $display == 1) { $condition[] = "e.is_display = 1"; }else { $condition[] = "e.is_display = 0"; } $TeacherModel=new Teacher(); // 考试名称条件 if($printName) { //查询教师id $teacherIds=$TeacherModel->getTeacherIdByName($printName); if($teacherIds){ $condition[] = " (e.name like '%{$printName}%' or eg.teacher_id in(".implode(',',$teacherIds)."))"; }else{ $condition[] = "e.name like '%{$printName}%'"; } } $condition[] = "eg.is_third = 0"; $condition[] = "eg.create_type in (0,1,2,3,5,6) "; $condition[] = "eg.is_united = 0"; // $condition[] = "eg.homework = 0"; $teachers_data = Teacher::model()->findAll(); $class_teacher_data = array(); $teacherNames=array(); if($teachers_data) { foreach ($teachers_data as $k => $v) { $teacherNames[$v->teacher_id] = $v->teacher_name; } } $gradeCardLength=array(); $gradeData=SGrade::model()->findAll(); foreach ($gradeData as $datum){ if($datum->card_status==1){ $gradeCardLength[$datum->id]=$datum->card_length; }else{ $gradeCardLength[$datum->id]=0; } } //获取考试列表 $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12); //获取打印班级 if($exam_list) { //查询教师 $ExamModel=new Exam(); $StudentPaperRelation=new SStudentPaperRelation(); foreach($exam_list['rs'] as $key=>$v) { $items = array(); $tpl_data=array(); $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id']; $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板 $exam_list['rs'][$key]['is_custom_optional_topic'] = 0; $exam_list['rs'][$key]['is_paper_49'] = 0; //准考证 if(!$v['school_card_status']){ $exam_list['rs'][$key]['school_card_length'] = $gradeCardLength[$v['grade']]; } if(isset($teacherNames[$v['teacher_id']])){ $exam_list['rs'][$key]['teacher_name'] = $teacherNames[$v['teacher_id']]; }else{ $exam_list['rs'][$key]['teacher_name'] = ''; } if(isset($v['tpl_data'])){ $tpl_data = json_decode($v['tpl_data'],1); //标注期望完成时间 if(isset($tpl_data['estimateTime'])) { $exam_list['rs'][$key]['estimate_time'] = date('Y-m-d H:i:s',$tpl_data["estimateTime"]); } } if(isset($tpl_data['branch'])){ $exam_list['rs'][$key]['branch'] = $tpl_data['branch']; }else{ $exam_list['rs'][$key]['branch'] =0; } if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $exam_list['rs'][$key]['is_custom_tpl'] = true; if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){ $exam_list['rs'][$key]['is_custom_optional_topic'] = 1; } $v['is_custom_tpl'] = true; }else{ //非自定义模板 $exam_list['rs'][$key]['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $exam_list['rs'][$key]['is_tpl'] = 1; //题卡分离 $exam_list['rs'][$key]['paper_tpl_type'] = 2; }else{ $exam_list['rs'][$key]['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $exam_list['rs'][$key]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $exam_list['rs'][$key]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $exam_list['rs'][$key]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $exam_list['rs'][$key]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7'])) { $exam_list['rs'][$key]['is_paper_49'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8'])) { $exam_list['rs'][$key]['is_paper_49'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['template_id_qrcode'])) { $exam_list['rs'][$key]['qrcode'] = 1; }else{ $exam_list['rs'][$key]['qrcode'] = 0; } //判断是否已上传成绩 $exam_list['rs'][$key]['is_feedback']=0; $exam=$ExamModel->getExamIds($v['exam_group_id']); if($exam){ if($StudentPaperRelation->getStudentFeedBack($exam)){ $exam_list['rs'][$key]['is_feedback']=1; } } //是否使用在线答题卡 $exam_list['rs'][$key]['third_card']=0; $exam_list['rs'][$key]['online_card']=0; $exam_list['rs'][$key]['is_qrcode_online']=0; $exam_list['rs'][$key]['marking_papers']=0; $studentAnswerOnline=$this->schoolManager->getAnswerSheet($v['exam_group_id']); if($studentAnswerOnline){ if($studentAnswerOnline['online_card']==1){ $exam_list['rs'][$key]['online_card']=$studentAnswerOnline['online_card']; $exam_list['rs'][$key]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online']; $exam_list['rs'][$key]['marking_papers']=$studentAnswerOnline['marking_papers']; if($studentAnswerOnline['paper_size']==1){ $exam_list['rs'][$key]['paper_size']='A3'; }elseif($studentAnswerOnline['paper_size']==2){ $exam_list['rs'][$key]['paper_size']='A4'; }elseif($studentAnswerOnline['paper_size']==3){ $exam_list['rs'][$key]['paper_size']='16K'; }elseif($studentAnswerOnline['paper_size']==4){ $exam_list['rs'][$key]['paper_size']='8K'; }elseif($studentAnswerOnline['paper_size']==5){ $exam_list['rs'][$key]['paper_size']='8K'; } }else{ $exam_list['rs'][$key]['third_card']=1; } } } //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id'; $criteria->addInCondition('exam_group_id',$exam_group_ids); $exam_data = Exam::model()->findAll($criteria); unset($criteria); unset($exam_group_ids); if($exam_data) { foreach($exam_data as $v) { //$exam_use_wp $exam_ids[$v->exam_id] = $v->exam_id; $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id; $_exam_ids[$v->exam_id] = $v->exam_group_id; } unset($exam_data); //通过考试ID,获取打印班级 $criteria = new CDbCriteria(); $criteria->select = 'exam_id,class_id,is_print,is_print_online'; $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_print = 1 or is_print_online=1'); $class_print_data = ClassExamPrinter::model()->findAll($criteria); if($class_print_data) { foreach($class_print_data as $v) { if( isset($_exam_ids[$v->exam_id])) { if($v->is_print==1){ $exam_printer_num['word'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id; } if($v->is_print_online==1){ $exam_printer_num['online'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id; } } } } unset($criteria); unset($class_print_data); } } //获取班级年级 $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); if($class_data) { foreach($class_data as $v) { $class_grade_arr[$v->class_id] = $v->grade; } } unset($class_data); //获取试卷标注状态 $criteria = new CDbCriteria(); $criteria->select = 'exam_id,is_labelled,labelled_type'; $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); unset($criteria); if($paper_data) { foreach($paper_data as $v) { if( isset($_exam_ids[$v->exam_id])) { $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled; $paper_labelled_type_arr[$_exam_ids[$v->exam_id]] = $v->labelled_type; } } } //获取产品设置版本 $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow(); if(!$productEdition || $productEdition['switch']==2){ $data['productSwitch']=2; }else{ $data['productSwitch']=3; } // 获取多学科状态 // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id'])); $data['pages'] = $exam_list['pager']; $data['page_total'] = $exam_list['pager']->rowsCount; $data['printList'] = $exam_list['rs']; $data['printer'] = $exam_printer_num; $data['exam_class'] = $_exam_group_ids; //$data["subject"] = $subject_exam_data; $data["exam_use_wp"] = $findSchool->use_wp; $data["display"] = $display; $data["labelled"] = $labelled; $data["grade"] = $grade; $data["printName"] = $printName; $data["paper"] = $paper_arr; $data["paper_labelled_type"] = $paper_labelled_type_arr; $data["class_grade"] = $class_grade_arr; $data["printType"] = $type; $data['teacherNames']=$teacherNames; $data["teacherId"] = $teacherId; //获取导出数据白名单 $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);; $this->render('group_list',$data); } public function actionClass_exam() { $condition = array(); $exam_ids = array(); $exam_id = ''; $exam_name = ''; $class_names = array(); $class_ids = array(); $class_print = array(); $class_online_print = array(); $data = array(); $exam_student_up_num = array(); $exam_student_num = array(); $student_img_up_num = array();//学生答题原图 $class_name = Req::get("class_name"); $exam_group_id = Req::get("exam_group_id"); $masttype = (int)Req::get("masttype"); $is_united = (int)Req::get('is_united'); $grade = Req::get('grade'); $branch = Req::get('branch'); $multiple_choice_required=0; //多选题必选数量 $exam_date=''; //考试日期 $exam_uploaded=0; if($exam_group_id <= 0) { Yii::app()->jump->error('未找到考试信息!'); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_group_data) { Yii::app()->jump->error('未找到考试信息!'); } if($exam_group_data->upload_status>0){ $exam_uploaded=1; } $condition[] = "exam_group_id = ".$exam_group_id; //获取班级信息 $class_data = $this->schoolManager->getSemesterClasses($this->semesterId); $class_types=array(); if($class_data) { foreach($class_data as $v) { if($class_name && $v['class_name'] == $class_name) { $class_ids[$v['class_id']] = $v['class_id']; } $class_names[$v['class_id']] = $v['class_name']; if($v['class_type']==1){ $class_types[$v['class_id']]='行政班'; }elseif($v['class_type']==2){ $class_types[$v['class_id']]='教学班'; } } } //debug($class_data); if($class_ids) { $condition[] = "class_id in (".implode(',',$class_ids).") "; } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "subject_id = '{$this->subjectId}'"; } if($class_ids) { $condition[] = "class_id in (".implode(',',$class_ids).") "; } //获取考试列表 $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12); if($exam_data['rs']) { foreach($exam_data['rs'] as $k=>$v) { $exam_ids[$v['exam_id']] = $v['exam_id']; $exam_id = $v['exam_id']; $exam_name = $v['print_name']; } }else { Yii::app()->jump->error('未找到考试信息!'); } //获取班级考试是否打印 $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('type = 0'); $class_print_data = ClassExamPrinter::model()->findAll($criteria); if($class_print_data) { foreach($class_print_data as $v) { $class_print[$v->exam_id] = $v->is_print; $class_online_print[$v->exam_id] = $v->is_print_online; } } unset($criteria); unset($class_print_data); //获取班级考试的上传成绩 $criteria = new CDbCriteria(); $criteria->select= 'student_id,is_feedback,exam_id,student_img_paper'; $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_del = 0'); $student_paper_data = SStudentPaperRelation::model()->findAll($criteria); if($student_paper_data) { foreach($student_paper_data as $v) { if($v->is_feedback) { $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id; } $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id; if (!isset($student_img_up_num[$v->exam_id])) { $student_img_up_num[$v->exam_id] = array(); } if (trim($v['student_img_paper'])) { $student_img_up_num[$v->exam_id][$v->student_id] = $v->student_id; } } } unset($criteria); unset($student_paper_data); //获取paper $paperIds=array(); $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paperData = SPaper::model()->findAll($criteria); if($paperData) { foreach($paperData as $v) { $paperIds[$v->exam_id] = $v->paper_id; } } unset($criteria); unset($exam_ids); $student_answer_img_num=array(); foreach($exam_student_up_num as $eid =>$sids){ $student_answer_img_num[$eid]=$this->schoolManager->getUpAnswerStudent($paperIds[$eid],$sids,true); } //获取paper 表数据 $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if(!$paper_data) { Yii::app()->jump->error('未找到考试信息!'); } //读取试题数据 $isAllSelect=1; //全部客观题判断 $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id)); if(!$paperTopic){ Yii::app()->jump->error('未找到考试信息!'); } //选择题类型判断 $allSubjectType=array(); if($exam_group_data['qxk_paper_id']>0){ $allSubjectType=array(1,2,3,4,12); }else{ $allSubjectType=array(1,2,11); } foreach ($paperTopic as $item){ if(!in_array($item->type,$allSubjectType)){ $isAllSelect=0; break; } } $printList = array(); $has_marked = false; $data['online_card'] = 0; $data['is_qrcode_online'] = 0; if($exam_data["rs"]){ $studentAnswerOnline=$this->schoolManager->getAnswerSheet($exam_group_id); $studentAnswerCardOnline=new SStudentAnswerCardOnline(); foreach ($exam_data['rs'] as $k=>$v) { $printList['is_tpl'] = 0; // 需要上传模板 $printList['answer_card_uploaded'] = false; if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $printList['is_custom_tpl'] = true; $v['is_custom_tpl'] = true; }else{ //非自定义模板 $printList['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $printList['is_tpl'] = 1; if(trim($paper_data->answer_card_src)){ $printList['answer_card_uploaded'] = true; } //题卡分离 $printList['paper_tpl_type'] = 2; }else{ $printList['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $printList['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $printList['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList['paper_tpl_type'] = 4; } } //英语题卡分离一 if($this->subjectId == 8){ $printList['paper_tpl_type'] = 5; } if($v['status'] == 1){ $has_marked = true; } //判断多选题 if(!$multiple_choice_required){ $tpl_data=json_decode($v['tpl_data'],true); if(isset($tpl_data['items'][17]) && isset($tpl_data['items'][17]['required']) ){ $multiple_choice_required=$tpl_data['items'][17]['required']; } $exam_date=$tpl_data['examDate']; } //是否使用在线答题卡 $exam_data['rs'][$k]['online_card']=0; $exam_data['rs'][$k]['is_qrcode_online']=0; if($studentAnswerOnline){ $exam_data['rs'][$k]['online_card']=$studentAnswerOnline['online_card']; $exam_data['rs'][$k]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online']; $data['online_card'] = $studentAnswerOnline['online_card']; $data['is_qrcode_online'] = $studentAnswerOnline['is_qrcode_online']; if($studentAnswerOnline['online_card']==1){ if($studentAnswerOnline['paper_size']==1){ $exam_data['rs'][$k]['paper_size']='A3'; }elseif($studentAnswerOnline['paper_size']==2){ $exam_data['rs'][$k]['paper_size']='A4'; }elseif($studentAnswerOnline['paper_size']==3){ $exam_data['rs'][$k]['paper_size']='16K'; }elseif($studentAnswerOnline['paper_size']==4){ $exam_data['rs'][$k]['paper_size']='8K'; }elseif($studentAnswerOnline['paper_size']==5){ $exam_data['rs'][$k]['paper_size']='8K'; } } if($studentAnswerOnline['online_card']==1 && $studentAnswerOnline['is_qrcode_online']==1){ //查询生成数量 $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($v['exam_id']); if($studentCardOnline){ $exam_data['rs'][$k]['card_created']=$studentCardOnline['count']; } } } } } //是否能添加班级 FIXME add_class_0924 //打印中 $enable_add_class = false; if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] ==0){ $enable_add_class = true; }else{ //混合阅卷 if($exam_group_data['mark_type'] == 3){ $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true; } //单独阅卷 if($exam_group_data['mark_type'] == 4){ $enable_add_class = $has_marked ? false : true; } } //查询还原记录 $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($examRestore){ $data['restore'] = 1; }else{ $data['restore'] = 0; } //读取试题推送设置 $topicPushSettingModel=new SExamPushTopicsSetting(); $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id); $topicPushSettingRelation=array(); if($topicPushSetting){ foreach ($topicPushSetting as $item){ if($item['topic_ids']){ $topicSetting=json_decode($item['topic_ids'],true); if($topicSetting){ $topicPushSettingRelation[(string)$item['exam_id']]=1; } } } } // 获取多学科状态 //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $this->setIs_new($exam_group_id); $data['printList'] = $exam_data['rs']; $data['print'] = $printList; $data['pages'] = $exam_data['pager']; $data['page_total'] = $exam_data['pager']->rowsCount; $data["class_name"] = $class_name; $data["class_data"] = $class_names; $data["class_types"] = $class_types; $data["exam_group_data"] = $exam_group_data; //$data["subject"] = $subject_exam_data; $data["exam_id"] = $exam_id; $data["exam_name"] = $exam_name; $data["exam_print"] = $class_print; $data["exam_online_print"] = $class_online_print; $data["exam_student"] = $exam_student_num; $data["exam_up_student"] = $exam_student_up_num; $data["student_img_up_num"] = $student_img_up_num; $data["student_answer_img_num"] = $student_answer_img_num; $data["exam_group_id"] = $exam_group_id; $data["grade"] = $grade; $data["branch"] = $branch; $data["enable_add_class"] = $enable_add_class; $data["qxk_paper_id"] = $exam_group_data->qxk_paper_id; $data['exam_date']=$exam_date; $data['exam_uploaded']=$exam_uploaded; $data['topic_push_setting']=$topicPushSettingRelation; $data['is_all_select']=$isAllSelect; $data['qxk_paper_id']=$exam_group_data['qxk_paper_id']; //判断全学科白名單 $data['new_answer_sheet_subject']=0; if($data['qxk_paper_id']){ $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$this->subjectId,'GET',$this->schoolId,array(),'cgi'); $rs=json_decode($rs,true); if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){ $data['new_answer_sheet_subject']=1; } } $data["subject"]=$this->subjectId; if($studentAnswerOnline){ $data['online_card']=$studentAnswerOnline['online_card']; $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online']; } if($multiple_choice_required>1){ $data['noOnline']=1; }elseif(isset($exam_data['rs'][0]['paper_size']) && $exam_data['rs'][0]['paper_size']!='A3'){ $data['noOnline']=2; }elseif($exam_group_data['mark_type']==0) { $data['noOnline'] = 3; }elseif($printList['paper_tpl_type'] == 1 || $printList['paper_tpl_type'] == 3){ $data['noOnline'] = 4; }else{ $data['noOnline']=0; } $data['online_token']=getOnlineToolToken($this->schoolId); $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $data['version_number']=$version_number; if($is_united==1){ $this->render('class_exam_united',$data); }else{ $this->render('class_exam2',$data); } } // 打印列表 public function actionSub_index(){ Url::clean(); $printName = Req::get("name"); $classId = Req::get("classId"); $printType = Req::get("type"); $grade = Req::get("grade"); $labelled = Req::get("labelled"); $display = Req::get("display"); $is_print = Req::get("is_print"); if (empty($printType)) { $printType = 'wp'; $printTypeData = 0; } else { switch ($printType) { case "wp": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; case "section": $printTypeData = 4; break; case "third_wb": //多学科错题本 $printTypeData = 1; $this->subjectId = Yii::app()->session['session_duoxueke_subject_id']; break; case "third_isp": //多学科个性化学习宝 $printTypeData = 3; $this->subjectId = Yii::app()->session['session_duoxueke_subject_id']; break; default: $printTypeData = null; break; } } $condition = array(); if($is_print > -1) { $condition[] = "cep.is_print = '{$is_print}'"; }else{ $is_print = -1; } if($printName) $condition[] = "e.name like '%{$printName}%'"; if(!Str::isBlank($printTypeData)) $condition[] = "cep.type = '{$printTypeData}'"; if($classId) $condition[] = "c.class_id = '{$classId}'"; if ($grade) { $condition[] = "c.grade = '{$grade}'"; } if (!Str::isBlank($labelled)) { $condition[] = "p.is_labelled = '{$labelled}'"; } if ($printType=='wp' && $display != 1) { $condition[] = "e.is_display = '0'"; } if(in_array($this->subjectId,$this->mathSubjectId)){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "e.subject_id = '{$this->subjectId}'"; } $condition[] = "eg.create_type in (0,1,2,3,5,6) "; //$condition[] = "eg.homework = 0"; //debug($condition);die; if (empty($grade)) { $grade = 'ALL'; } $classes = $this->schoolManager->getClasses($grade); if($printType=='wp') { $condition[] = "eg.is_third = 0"; $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc')); }else{ $resultList = $this->schoolManager->getPrintList_ipf($condition,array('e.complete_time desc')); } $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k] = $v; if ($v["type"] == 1) { $printList[$k]['print_name']= $v["exam_name"].'"错题本"'; } elseif ($v["type"] == 2) { $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"'; } elseif ($v["type"] == 3) { if($this->subjectId == 8){ $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"'; }else{ $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"'; } }elseif ($v["type"] == 4) { $printList[$k]['print_name']= $v["exam_name"].'"阶段复习个性化学习宝"'; } else { $printList[$k]['print_name']= $v["exam_name"]; } $printList[$k]['is_tpl'] = 0; // 需要上传模板 $printList[$k]['answer_card_uploaded'] = false; if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $printList[$k]['is_custom_tpl'] = true; $v['is_custom_tpl'] = true; }else{ //非自定义模板 $printList[$k]['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $printList[$k]['is_tpl'] = 1; if(trim($printList[$k]['answer_card_src'])){ $printList[$k]['answer_card_uploaded'] = true; } //题卡分离 $printList[$k]['paper_tpl_type'] = 2; }else{ $printList[$k]['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $printList[$k]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList[$k]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $printList[$k]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList[$k]['paper_tpl_type'] = 4; } } //题卡合一 } } //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data = array(); $data['printList'] = $printList; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data["printType"] = $printType; $data["printName"] = $printName; $data["classes"] = $classes; $data["classId"] = $classId; $data["grade"] = $grade; $data["labelled"] = $labelled; $data["display"] = $display; $data["is_print"] = $is_print; //$data["subject"] = $subject_exam_data; $data['subjectId']=$this->subjectId; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } unset($resultList); $this->render('index',$data); } // 打印试卷、纠错本、个性化学习宝 public function actionAjaxupdate(){ $cid = safe_replace($_POST['cid']); $eid = safe_replace($_POST['eid']); $tid = safe_replace($_POST['tid']); $error = array(); $error['success'] = 0; if (empty($cid) || !is_numeric($cid)) { $error['message'] = 'classId 错误!'; echo json_encode($error);exit(); } if (empty($eid) || !is_numeric($eid)) { $error['message'] = 'examId 错误!'; echo json_encode($error);exit(); } if ($tid == 0) { // 打印试卷 $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; self::printPaper_v2($cid,$eid); } elseif ($tid == 1) { // 纠错本 //self::printWrongTopic($cid,$eid); self::downloadWrongTopic($cid,$eid); } elseif ($tid == 2) { // 个性化学习宝 self::printRaiseScheme($cid, $eid); } } // 选择需打印试卷的学生 public function actionChange(){ Url::clean(); $sname = Req::get("sname"); $cid = Req::get("cid"); $eid = Req::get("eid"); $tid = Req::get("tid"); $isFeedback=0; $useAnswerCardOnlineQrcode=0; switch($tid){ case "0": $printType = 'wp'; break; case "1": $printType = 'wb'; break; case "2": $printType = 'isp'; break; default: $printType = 'wp'; } if($sname) { $_student_ids = array(); $criteria = new CDbCriteria(); $criteria->select = 'student_id'; $criteria->addSearchCondition('realname',$sname); $student_info_data = SStudentInfo::model()->findAll($criteria); if($student_info_data) { foreach($student_info_data as $v) { $_student_ids[$v->student_id] = $v->student_id; } } } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $examGroupInfo=ExamGroup::model()->findByPk($examInfo->exam_group_id); $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与试卷对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $paperData='{}'; if($examGroupInfo->qxk_paper_id==0){ $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id); } if(trim($paperInfo->answer_card_src)) $answerCardUploaded = true; else $answerCardUploaded = false; $tpl = 1;// 需要上传模板 $tplTwo= 1; if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) { $paperType = 1; if (empty($paperInfo->tpl_doc_src)) { $tpl = 2; } $tplTwo= 2; }else{ $paperType = 2; } if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl'])) { $tpl = 1; $paperType = 1; $tplTwo= 2; } if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){ $isCustomTpl = true; } else{ $isCustomTpl = false; } //判断在线答题卡使用情况 $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id); if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){ $useAnswerCardOnlineQrcode=1; } $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id)); if (empty($relateTopic)) { Yii::app()->jump->error('未找该试卷试题信息!'); } // 获取阅卷类型 $markType = 0; $groupInfo = $this->schoolManager->getExam($eid); if (!empty($groupInfo)) { $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id'])); if (!empty($findInfo)) { $markType = $findInfo->mark_type; } } $result = array(); if(isset($_student_ids) && !empty($_student_ids)) { $criteria = new CDbCriteria(); $criteria->select = 'student_id,paper_id,class_id,exam_id,student_card,school_student_card,is_feedback,is_complete'; $criteria->addCondition('paper_id=:paid'); $criteria->addCondition('class_id=:caid'); $criteria->addInCondition('student_id',$_student_ids); $criteria->addCondition('is_del=:is_del'); $criteria->params[':paid'] = $paperInfo->paper_id; $criteria->params[':caid'] = $cid; $criteria->params[':is_del'] = 0; $relateStudent = SStudentPaperRelation::model()->findAll($criteria); }else { $relateStudent = SStudentPaperRelation::model()->findAll(array( 'select' => array('student_id','paper_id','class_id','exam_id','student_card','school_student_card','is_feedback','is_complete','student_img_paper'), 'condition' => 'paper_id=:paid and class_id=:caid and is_del=:is_del', 'params' => array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,':is_del'=>0))); } //if (empty($relateStudent)) { // Yii::app()->jump->error('未找该试卷关联的学生!'); //} else { //$studentModel = StudentInfo::model(); // 获取学生姓名 $_student_id = array(); foreach($relateStudent as $v) { $_student_id[$v->student_id] = $v->student_id; } //if(!$_student_id) //{ // Yii::app()->jump->error('未找该试卷关联的学生!'); //} $studentNames = array(); $b_student_arr = array(); $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId); if(!$b_student_arr ){ $array_student = array(); $b_student_data=$this->schoolManager->getStudentBySchool($this->schoolId); if($b_student_data){ foreach ($b_student_data as $k=>$v){ $array_student[$v['student_id']] = $v['student_id']; $b_student_arr[$v['student_id']]=$v['student_id']; } } Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId); if($array_student){ Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student); Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000); } unset($b_student_data); unset($criteria); } $studentNames = array(); $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$_student_id); $studentArray = SStudentInfo::model()->findAll($criteria); unset($criteria); if (!empty($studentArray)) { foreach ($studentArray as $student) { $studentNames[$student->student_id] = $student->realname; } } unset($studentArray); //查询是否上传答题图片 $uploadAnswerImgStudent=array(); $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,false); if($student_answer_img){ foreach ($student_answer_img as $val){ $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id']; } } //redis里查询模板是否生成 $redis_obj = new Redis(); $server = Yii::app()->params["redis"]["server"]; $redis_obj->connect($server["host"], $server["port"]); if(isset($server["password"])){ $redis_obj->auth($server["password"]); } if (YII_ENV == 'pro' || YII_ENV == 'production') { $redis_obj->select(0); }else{ $redis_obj->select(10); } $redisKey = 'zsy:paper_template:'.$this->schoolId.':'.$eid; $tempArr = array('0'=>'生成中','1'=>'已生成','2'=>'生成失败','3'=>'未生成'); $tempCheck = $printCheck = false; foreach ($relateStudent as $key=>$val) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperName'] = $examInfo->name; $result[$key]['studentCode'] = $val->student_id; $result[$key]['student_card'] = $val->student_card; $result[$key]['school_student_card'] = $val->school_student_card; $result[$key]['studentCode'] = $val->student_id; $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null; $result[$key]['is_feedback'] = $val->is_feedback; $result[$key]['is_complete'] = $val->is_complete; $result[$key]['student_img_paper'] = $val->student_img_paper; $result[$key]['upload_answer_img'] =0; if($val->is_feedback==1){ $isFeedback=1; if(isset($uploadAnswerImgStudent[(string)$val->student_id])){ $result[$key]['upload_answer_img'] =1; } } $stuId = (string)$val->student_id; $template = $redis_obj->hMGet($redisKey,array($stuId)); $result[$key]['temp_str'] = '未生成'; $result[$key]['temp_status'] = 3; if(isset($template[$stuId]) && $template[$stuId]){ $redisData = json_decode($template[$stuId],true); if(isset($redisData['status']) && isset($tempArr[$redisData['status']])){ $result[$key]['temp_str'] = $tempArr[$redisData['status']]; $result[$key]['temp_status'] = $redisData['status']; if($redisData['status'] == 1){ $printCheck = true; } if($redisData['status'] == 2){ $tempCheck = true; } }else{ $tempCheck = true; } }else{ $tempCheck = true; } //查询在线答题卡是否生成 $rs=$this->sConn->createCommand("select answer_card_online_created from student_answer_card_online where exam_id='{$eid}' and student_id='{$val->student_id}' ")->queryRow(); if($rs && $rs['answer_card_online_created']==1){ $result[$key]['online_created'] = 1; }else{ $result[$key]['online_created'] = 0; } //查询学生身份证号 $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id)); if($studentInfo){ $result[$key]['id_number'] = $studentInfo->id_number; }else{ $result[$key]['id_number'] = ''; } } $redis_obj->close(); unset($relateStudent); //} $no_paper_student = array(); $paper_student_array = array(); $c_paper_student_array = array(); $class_student_info_data = array(); $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation $class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生 $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生 if ($paper_student_data) { foreach ($paper_student_data as $v) { $paper_student_array[$v['student_id']] = $v['student_id']; } //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info } if ($c_paper_student_data) { foreach ($c_paper_student_data as $v) { $c_paper_student_array[$v['student_id']] = $v['student_id']; } //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info } if ($class_student_info_data) { foreach ($class_student_info_data as $v) { $class_student_info_array[$v['student_id']] = $v['realname']; } } if ($class_student_data) { foreach($class_student_data as $v) { if(!isset($b_student_arr[$v['student_id']])) { if ($paper_student_array) { if(isset($paper_student_array[$v['student_id']])){ $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'', ); } } if($c_paper_student_array ) { if(!isset($c_paper_student_array[$v['student_id']]) ) { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'', ); } }else { $no_paper_student[$v['student_id']] = array( 'student_id' => $v['student_id'], 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'', ); } } } } unset($b_student_arr); $data = array(); $data['no_paper_student'] = $no_paper_student; $data['result'] = $result; $data["printType"] = $printType; $data["sname"] = $sname; $data['examInfo'] = $examInfo; $data['paper_id'] = $paperInfo->paper_id; $data['exam_id'] = $eid; $data['class_id'] = $cid; $data['exam_group_id'] = $examInfo->exam_group_id; $data['type_id'] = $tid; $data['tempCheck'] = $tempCheck; $data['printCheck'] = $printCheck; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); //$data["subject"] = $subject_exam_data; $data['wp_type'] = $examInfo->tpl_index; $data['className'] = $classInfo->class_name; $data['paperName'] = $examInfo->name; $data['tpl'] = $tpl; $data['tplTwo'] = $tplTwo; $data['markType'] = $markType; $data['paperType'] = $paperType; $data['answerCardUploaded'] = $answerCardUploaded; $data['paperData'] = $paperData; $data['isCustomTpl'] = $isCustomTpl; $data['isFeedback'] = $isFeedback; $data['useAnswerCardOnlineQrcode']=$useAnswerCardOnlineQrcode; $data['qxkPaperId'] = $examGroupInfo->qxk_paper_id; $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $data['version_number']=$version_number; $this->render('change2',$data); } // 选择需打印纠错本的同学 public function actionChangewrongtopic(){ $sname = Req::get("sname"); $cid = Req::get("cid"); $eid = Req::get("eid"); $printType = (string)Req::get("printType"); $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $semesterId = $classInfo->semester_id;//当前学期id $grade = $classInfo->grade; $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与试卷对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false; $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"错题本\""; $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); if (empty($relateStudent)) { Yii::app()->jump->error('未找到学生和试卷的对应关系!'); } else { $studentIds = array(); foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; } $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字 $result = array(); $no = 1; foreach ($relateStudent as $v) { $studentId = (string)$v['student_id']; $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:''; $is_html = $v['is_wrongbook_html']; $is_pdf = $v['is_wrongbook_pdf']; $status = $this->getStatusDesc($is_html, $is_pdf); //错题本状态 $className = $classInfo->class_name; $scoring = $v['scoring']; if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的 if (strpos($_studentName, $sname) !== false) { //是搜索的学生 $result[$studentId] = array(); $result[$studentId]['no'] = $no; //序号 $result[$studentId]['studentId'] = $studentId; //学生id $result[$studentId]['studentName'] = $_studentName; //学生名称 $result[$studentId]['studentCode'] = $studentId; //学生id,即编号 $result[$studentId]['clazzName'] = $className; //班级名称 $result[$studentId]['wrongStatus'] = $status; //错题本状态 $result[$studentId]['scoring'] = $scoring; //得分 $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间 $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考 $no += 1; } else{ continue; } } else { $result[$studentId] = array(); $result[$studentId]['no'] = $no; //序号 $result[$studentId]['studentId'] = $studentId; //学生id $result[$studentId]['studentName'] = $_studentName; //学生名称 $result[$studentId]['studentCode'] = $studentId; //学生id,即编号 $result[$studentId]['clazzName'] = $className; //班级名称 $result[$studentId]['wrongStatus'] = $status; //错题本状态 $result[$studentId]['scoring'] = $scoring; //得分 $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间 $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考 $no += 1; } } } $data = array(); $data['exam_id'] = $eid; $data['examName'] = $examInfo["name"]; $data['class_id'] = $cid; $data['className'] = $classInfo->class_name; $data['sname'] = $sname; $data['paper_id'] = $paperInfo->paper_id; $data['printTaskName'] = $printTaskName; $data['paperIsLabelled'] = $paperIsLabelled; $data['result'] = $result; $data['printType'] = $printType; $data['stuIspErroMsg'] = $this->stuIspErrorMsg(1,$eid,$studentIds); $order_res = $this->getOrderStu($eid, $cid, 1, $relateStudent,$semesterId, $grade); if (!$order_res) { Yii::app()->jump->error("接口错误"); } $data = array_merge($data, $order_res); $this->render('changewrongtopic',$data); } /** * 学生错题本个性化学习宝未生成错题信息 * @param $productType * @param $examId * @param array $studentIds */ protected function stuIspErrorMsg($productType,$examId,$studentIds = array()) { $result = array(); if (!in_array($this->subjectId, $this->mathSubjectId)) { return $result; } if (!$studentIds) { return $result; } //转字符串 foreach ($studentIds as $k => $_stuId) { $studentIds[$k] = '"'.$_stuId.'"'; } //需要显示学生个性化学习宝错误码 $showErrorCode = Yii::app()->params['show_isp_error_code']; //个性化学习宝错误代码信息 $errorCodeMsg = Yii::app()->params['isp_error_code_msg']; $rs = SStudentIspErrorCode::model()->getStudentIspErrorCode($examId, $productType); if ($rs) { foreach ($rs as $value) { if(!in_array($value['error_code'],$showErrorCode)) continue; if (!isset($result[$value['student_id']])) { $result[$value['student_id']] = array(); } $result[$value['student_id']][$value['error_code']] = isset($errorCodeMsg[$value['error_code']])?$errorCodeMsg[$value['error_code']]:'错误码无信息'; } } unset($rs); return $result; } // 处理选择后同学纠错本打印(于20160908使用API接口的方法替换此方案,暂时废弃) public function actionChangewrongtopicdo(){ $cid = Req::get("cid"); $eid = Req::get("eid"); $stids = Req::get("stids"); if (empty($stids) || empty($cid) || empty($eid)) { Yii::app()->jump->error('打印纠错本参数有误!'); } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $filePath = array(); $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids)); if (empty($getPaths)) { Yii::app()->jump->error('正在努力生成纠错本!'); } else { // 下载文件名称 $fileName = $classInfo->class_name.$examInfo->name.'纠错本.zip'; // 下载文件路径 $result = array(); //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/'; $pdfPath = Yii::app()->params['student_wrong_isp_path']; foreach ($getPaths as $path) { /* if(file_exists(iconv("utf-8", "gbk", $pdfPath.$path->wrongbook_pdf_path))){ $result[] = $path->wrongbook_pdf_path; } */ if(strpos($path->wrongbook_pdf_path, "data")!==false){ $paths=$pdfPath.$path->wrongbook_pdf_path; }else{ $paths=$pdfPath."uploads/".$path->wrongbook_pdf_path; } if(file_exists($paths)){//aaaaaaaaa $result[] = $paths; } } if (empty($result)) { Yii::app()->jump->error('正在生成学生纠错本!'); } // 下载 self::downloadStudentFile($fileName,$result); } } // 选择需打印个性化学习宝的同学 public function actionChangeraisescheme(){ $sname = Req::get("sname"); //学生名字 $cid = Req::get("cid"); //班级id $eid = Req::get("eid"); //考试id $type = Req::get("type"); //2步 还是 3步 $subjectId = Req::get("subid"); //学科ID $planName = ""; if($type == "isp"){ $postTypeVal=2; if($subjectId == 8){ $postTypeVal=3; $planName = "个性化学习宝"; }else{ $planName = "个性化学习方案"; } $typeVal = 2; }else if($type == "third_isp"){ $planName = "个性化学习宝"; $typeVal = 3; if($subjectId == 8){ $postTypeVal = 3; }else{ $postTypeVal = 2; } }else if($type == "studytrend"){ $planName = "个性化学习宝"; $typeVal = 3; $postTypeVal=3; }else{ Yii::app()->jump->error('参数错误!'); } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $semesterId = $classInfo->semester_id;//当前学期id $grade = $classInfo->grade; $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type='.$typeVal,array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与试卷对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false; $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"{$planName}\""; /*$studentIds = array(); $planNames = array(); $result = array(); $ispStatus = array(); $studentIdsTwo = array();*/ //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_isp_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid ',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));//所有记录 if (!$relateStudent) { Yii::app()->jump->error('未找到学生和试卷的对应关系!'); } $studentIds = array(); foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; } $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字 $result = array(); $no = 1; foreach ($relateStudent as $v) { $studentId = (string)$v['student_id']; $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:''; if ($type == 'isp') { $is_html = $v['is_isp_html']; $is_pdf = $v['is_isp_pdf']; }elseif ($type == 'studytrend') { $is_html = $v['is_wbisp_html']; $is_pdf = $v['is_wbisp_pdf']; }elseif ($type == 'third_isp') { $is_html = $v['is_wbisp_html']; $is_pdf = $v['is_wbisp_pdf']; } $status = $this->getStatusDesc($is_html, $is_pdf); //个性化学习宝状态 $className = $classInfo->class_name; $_planName = $className.$_studentName.$examInfo->name.$planName; if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的 if (strpos($_studentName, $sname) !== false) { //是搜索的学生 $result[$studentId] = array(); $result[$studentId]['no'] = $no; //序号 $result[$studentId]['studentId'] = $studentId; //学生id $result[$studentId]['studentName'] = $_studentName; //学生名称 $result[$studentId]['studentCode'] = $studentId; //学生id,即编号 $result[$studentId]['clazzName'] = $className; //班级名称 $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态 $result[$studentId]['planName'] = $_planName; $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间 $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考 $no += 1; } else{ continue; } } else { $result[$studentId] = array(); $result[$studentId]['no'] = $no; //序号 $result[$studentId]['studentId'] = $studentId; //学生id $result[$studentId]['studentName'] = $_studentName; //学生名称 $result[$studentId]['studentCode'] = $studentId; //学生id,即编号 $result[$studentId]['clazzName'] = $className; //班级名称 $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态 $result[$studentId]['planName'] = $_planName; $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间 $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考 $no += 1; } } $data = array(); $data['exam_id'] = $eid; $data['class_id'] = $cid; $data['className'] = $grade; $data['sname'] = $sname; $data['paper_id'] = $paperInfo->paper_id; $data['result'] = $result; $data['type'] = $type; $data['paperIsLabelled'] = $paperIsLabelled; $data['printTaskName'] = $printTaskName; $data['printType'] = $type; $data['subjectId']=$subjectId; $data['stuIspErroMsg'] = $this->stuIspErrorMsg($type == 'isp'?2:3,$eid,$studentIds); $order_res = $this->getOrderStu($eid, $cid, $postTypeVal, $relateStudent,$semesterId, $grade); // debug($order_res); if (!$order_res) { Yii::app()->jump->error("接口错误"); } $data = array_merge($data, $order_res); // debug($data); $this->render('changeraisescheme',$data); /*// 获取当前试卷提分计划 $improveScore = StudentImproveScorePlan::model()->findAll('paper_id=:paid and is_created=1',array(':paid'=>$paperInfo->paper_id)); if (empty($relateStudent)) { Yii::app()->jump->error('学生的个性化学习宝还未生成,请等待!'); } else { if($type == "isp"){ foreach ($relateStudent as $paperStudent) { $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}')")->queryRow(); $rs = current($rs); if($rs == 0) continue; $studentIds[] = $paperStudent->student_id; $ispStatus[$paperStudent->student_id] = $paperStudent->is_isp_pdf; } // 获取当前班级需打印周周练的同学 foreach ($improveScore as $improve) { if (in_array($improve->student_id, $studentIds)) { $studentIdsTwo[] = $improve->student_id; } } } else if($type == "studytrend"){ foreach ($relateStudent as $paperStudent) { $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}' )")->queryRow(); $rs = current($rs); if($rs == 0) continue; $studentIds[] = $paperStudent->student_id; $ispStatus[$paperStudent->student_id] = $paperStudent->is_wbisp_pdf; } // 获取当前班级需打印周周练的同学 foreach ($improveScore as $improve) { if (in_array($improve->student_id, $studentIds)) { $studentIdsTwo[] = $improve->student_id; } } } } if (empty($studentIdsTwo)) { Yii::app()->jump->error('当前班级还未生成个性化学习宝'); } else { // 获取有错题的学生姓名 $studentNames = SStudentInfo::model()->getStudentNames($studentIdsTwo); foreach ($studentIdsTwo as $key=>$val) { //val是学生id if (empty($sname)) { $result[$key]['studentName'] = $studentNames[$val]; $result[$key]['studentCode'] = $val; $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['ispStatus'] = $ispStatus[$val]; $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName; } else { if (false !== strpos($studentNames[$val],$sname) ) { $result[$key]['studentName'] = $studentNames[$val]; $result[$key]['studentCode'] = $val; $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['ispStatus'] = $ispStatus[$val]; $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName; } unset($studentIdsTwo[$key]); } } }*/ } function getStatusDesc($is_html, $is_pdf) { if ($is_html == 0 || $is_html == 90) { $status = 0; // 未生成 } elseif ($is_html == 1 && $is_pdf == 0) { $status = 1; //正在生成中 } elseif ($is_pdf == 1) { $status = 2; //已生成 } elseif ($is_html == 9 && $is_pdf == 9) { $status = 3; //已过期 } else { $status = 4; //未知状态 } return $status; } function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade) { $data = array(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$this->semesterId."'") ->limit(1) ->query() ->read(); $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$eid,':classid'=>$cid)); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$cid, "semester"=>$code['refer_code'], "grade"=>$grade, "examTime"=>$print_time[0]->add_time, "students"=>array(), "classify"=>$typeVal, ); $examInfo = Exam::model()->findByPk($eid); $intarr['subject']=$examInfo['subject_id']; if(in_array($intarr['subject'],$this->mathSubjectId)){ $intarr['subject']=3; } foreach($relateStudentRes as $key => $val){ $intarr['students'][] = $val['student_id']; } $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ //Yii::app()->jump->error("接口错误"); return false; } if($rs->errCode!="00"){ //Yii::app()->jump->error($rs->errMsg); //exit(); return false; } if(!empty($rs->data)){ foreach($rs->data as $v){ $data['limitstu'][$v]=$v; } }else{ $data['limitstu']=-1; } return $data; } // 选择打印个性化学习宝同学处理(于20160908使用API接口的方法替换此方案,暂时废弃) public function actionChangeraiseschemedo(){ $cid = Req::get("cid"); $eid = Req::get("eid"); $stids = Req::get("stids"); $type = Req::get("type"); if (empty($stids) || empty($cid) || empty($eid) || empty($type)) { Yii::app()->jump->error('打印个性化学习宝参数有误!'); } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $filePath = array(); $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids)); if (empty($getPaths)) { Yii::app()->jump->error('正在努力生成个性化学习宝!'); } else { $fName = ""; if($type == "isp") $fName = "个性化学习方案"; else if($type == "studytrend") $fName = "个性化学习宝"; // 下载文件名称 $fileName = $classInfo->class_name.$examInfo->name.$fName.'.zip'; // 下载文件路径 $result = array(); //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/'; $pdfPath = Yii::app()->params['student_wrong_isp_path']; foreach ($getPaths as $path) { /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){ $result[] = $path->isp_pdf_path; } */ if($type == "isp"){ if(strpos($path->isp_pdf_path,'data')!==false){ $paths=$pdfPath.$path->isp_pdf_path; }else{ $paths=$pdfPath."uploads/".$path->isp_pdf_path; } $result[] = $paths; } else if($type == "studytrend" ){ if(strpos($path->isp_pdf_path,'data')!==false){ $paths=$pdfPath.$path->wbisp_pdf_path; }else{ $paths=$pdfPath."uploads/".$path->wbisp_pdf_path; } $result[] = $paths; } } if (empty($result)) { Yii::app()->jump->error('正在生成学生个性化学习宝!'); } // 下载 self::downloadStudentFile($fileName,$result); } } // 打印试卷 private function printPaper($cid,$eid){ $error = array(); $error['success'] = 0; $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { $error['message'] = '未找到班级!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { $error['message'] = '未找到周周练!'; echo json_encode($error);exit(); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { $error['message'] = '未找到班级与试卷对应关系!'; echo json_encode($error);exit(); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) { if (empty($paperInfo->tpl_doc_src)) { $error['message'] = '未上传模板,请先上传模板!'; echo json_encode($error);exit(); } } // 获取阅卷类型 $markType = 0; $groupInfo = $this->schoolManager->getExam($eid); if (!empty($groupInfo)) { $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id'])); if (!empty($findInfo)) { $markType = $findInfo->mark_type; } } $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id)); if (empty($relateTopic)) { $error['message'] = '未找该试卷试题信息!'; echo json_encode($error);exit(); } $result = array(); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0)); if (empty($relateStudent)) { $error['message'] = '未找该试卷关联的学生!'; echo json_encode($error);exit(); } else { // 组装json数据发到客户端 $studentModel = StudentInfo::model(); $paperData = $this->schoolManager->getPaperWithTopicsDetails($paperInfo->paper_id, "ARR"); foreach ($relateStudent as $key=>$val) { $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperId'] = $paperInfo->paper_id; $result[$key]['paperName'] = $examInfo->name; $result[$key]['schoolId'] = Yii::app()->session['school_id']; $result[$key]['studentCode'] = $val->student_id; $result[$key]['studentName'] = $studentModel->findByPk($val->student_id)->realname; $result[$key]['wpCode'] = $eid; $result[$key]['wpType'] = $examInfo->tpl_index; $result[$key]['markType'] = $markType; if(isset($paperData["object"]["topicsCount"])){ $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"]; $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"]; $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"]; } else{ $result[$key]['selectQTNub'] = 0; $result[$key]['completionNub'] = 0; $result[$key]['questionSNub'] = 0; } } } if (empty($result)) { $error['message'] = '没有打印信息!'; echo json_encode($error);exit(); } else { // 更新试卷打印状态、时间 $getResult->is_print = 1; $getResult->print_time = time(); $getResult->save(); $error['success'] = 1; $error['message'] = $result; echo json_encode($error);exit(); } } private function printPaper_v2($cid,$eid){ $error = array(); $error['success'] = 0; $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { $error['message'] = '未找到班级!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { $error['message'] = '未找到周周练!'; echo json_encode($error);exit(); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { $error['message'] = '未找到班级与试卷对应关系!'; echo json_encode($error);exit(); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) { if (empty($paperInfo->tpl_doc_src)) { $error['message'] = '未上传模板,请先上传模板!'; echo json_encode($error);exit(); } } // 获取阅卷类型 $markType = 0; $groupInfo = $this->schoolManager->getExam($eid); if (!empty($groupInfo)) { $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id'])); if (!empty($findInfo)) { $markType = $findInfo->mark_type; } } $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id)); if (empty($relateTopic)) { $error['message'] = '未找该试卷试题信息!'; echo json_encode($error);exit(); } $result = array(); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0)); if (empty($relateStudent)) { $error['message'] = '未找该试卷关联的学生!'; echo json_encode($error);exit(); } else { // 组装json数据发到客户端 $studentModel = StudentInfo::model(); $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id, "ARR"); foreach ($relateStudent as $key=>$val) { $studentInfo=$studentModel->findByPk($val->student_id); $result[$key]['clazzName'] = $classInfo->class_name; $result[$key]['paperId'] = $examInfo->exam_group_id; $result[$key]['paperName'] = $examInfo->name; $result[$key]['schoolId'] = Yii::app()->session['school_id']; $result[$key]['studentCode'] = $val->student_id; $result[$key]['studentName'] = $studentInfo->realname; $result[$key]['wpCode'] = $eid; $result[$key]['wpType'] = $examInfo->tpl_index; $result[$key]['markType'] = $markType; $result[$key]['idNumber'] = $studentInfo->id_number; if(isset($paperData["object"]["topicsCount"])){ $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"]; $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"]; $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"]; } else{ $result[$key]['selectQTNub'] = 0; $result[$key]['completionNub'] = 0; $result[$key]['questionSNub'] = 0; } } } if (empty($result)) { $error['message'] = '没有打印信息!'; echo json_encode($error);exit(); } else { // 更新试卷打印状态、时间 $getResult->is_print = 1; $getResult->print_time = time(); $getResult->save(); $error['success'] = 1; $error['message'] = $result; echo json_encode($error);exit(); } } // 下载全班学生纠错本 public function actionDownloadwrongtopic() { $cid = Req::get("cid"); $eid = Req::get("eid"); $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与纠错本对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } $result = array(); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1 and is_del=:is_del',array(':is_del'=>0,':paid'=>$paperInfo->paper_id,':caid'=>$cid)); if (empty($relateStudent)) { Yii::app()->jump->error('正在努力生成纠错本!'); } else { $studentIdArray = array(); // 获取当前考试所有学生ID foreach ($relateStudent as $key=>$val) { $studentIdArray[] = $val->student_id; } } $filePath = array(); $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray); if (empty($getPaths)) { Yii::app()->jump->error('正在生成纠错本!'); } else { // 下载文件名称 $fileName = $classInfo->class_name.$examInfo->name.'错题本.zip'; // 下载文件路径 $result = array(); //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/'; $pdfPath = Yii::app()->params['student_wrong_isp_path']; foreach ($getPaths as $path) { /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->wrongbook_pdf_path))){ $result[] = $path->wrongbook_pdf_path; } */ if(strpos($path->wrongbook_pdf_path,"data")!==false){ $pathstr=$pdfPath.$path->wrongbook_pdf_path; }else{ $pathstr=$pdfPath."uploads/".$path->wrongbook_pdf_path; } if(file_exists($pathstr)){ $result[] = $pathstr; } } if (empty($result)) { Yii::app()->jump->error('正在生成学生纠错本!'); } // 下载 self::downloadStudentFile($fileName,$result); } } // 下载全班学生个性化学习宝 public function actionDownloadraisescheme($cid,$eid,$type){ if(!in_array($type, array(2, 3))) Yii::app()->jump->error('缺少参数!'); $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与纠错本对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } if($type == 2){ $field = "is_isp_pdf"; $check = "ISP"; } else{ $field = "is_wbisp_pdf"; $check = "WB_ISP"; } $relateStudent = SStudentPaperRelation::model()->findAll("paper_id=:paid and class_id=:caid and {$field}=1 and is_del=0",array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); if (empty($relateStudent)) { Yii::app()->jump->error('正在努力生成个性化学习宝!'); } else { $studentIdArray = array(); // 获取当前考试所有学生ID foreach ($relateStudent as $key=>$val) { $studentIdArray[] = $val->student_id; } } $filePath = array(); $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray, $check); if (empty($getPaths)) { Yii::app()->jump->error('正在努力生成个性化学习宝!'); } else { $fName = $type == 2 ? "个性化学习方案" : "个性化学习宝"; // 下载文件名称 $fileName = $classInfo->class_name.$examInfo->name."{$fName}.zip"; // 下载文件路径 $result = array(); //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/'; $pdfPath = Yii::app()->params['student_wrong_isp_path']; foreach ($getPaths as $path) { /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){ $result[] = $path->isp_pdf_path; } */ if($type == 2){ if(strpos($path->wrongbook_pdf_path,"data")!==false){ $pathstr=$pdfPath.$path->isp_pdf_path; }else{ $pathstr=$pdfPath."uploads/".$path->isp_pdf_path; } if(is_file($pathstr)){ $result[] = $pathstr; } } else if($type == 3){ if(strpos($path->wrongbook_pdf_path,"data")!==false){ $pathstr=$pdfPath.$path->wbisp_pdf_path; }else{ $pathstr=$pdfPath."uploads/".$path->wbisp_pdf_path; } if(is_file($pathstr)){ $result[] = $pathstr; } } } if (empty($result)) { Yii::app()->jump->error('正在生成学生个性化学习宝!'); } // 下载 self::downloadStudentFile($fileName,$result); } } // 下载学生纠错本、个性化学习宝PDF function downloadStudentFile($fileName,$result) { if (empty($fileName) || empty($result)) { return false; } $downName = mb_convert_encoding($fileName, 'gbk', 'utf-8'); $filename = dirname(dirname(dirname(__FILE__))).'/upload/'. uniqid().".zip"; //最终生成的文件名(含路径) $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) { Yii::app()->jump->error('无法打开文件,或者文件创建失败'); } //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/'; // $pdfPath = Yii::app()->params['student_wrong_isp_path']; foreach ($result as $val) { $res=$zip->addFile($val,mb_convert_encoding(preg_replace('/^.+[\\\\\\/]/', '', $val), 'GBK', 'UTF-8')); } $zip->close();//关闭 if (is_file($filename)){ if (FALSE!== ($handler = fopen($filename, 'r'))) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$downName); header('Content-Transfer-Encoding: chunked'); //changed to chunked header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); while (!feof($handler)) { file_put_contents("php://output", fread($handler, 4096)); } fclose($handler); unlink($filename); } exit; } } // 获取周周练试卷详情(生成模板使用、打印答案解析使用) public function actionCreatetempelate(){ $wpcode = Req::post("eid"); $flag = Req::post("flag"); $error['success'] = 0; if (empty($wpcode)) { $error['message'] = '么有周周练id!'; echo json_encode($error);exit(); } $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getWpPapers', 'wpCode='.$wpcode); $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode)); //获取本次考试的examids $exam_ids = array(); if($exam_data) { $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $index_tpl = 0; if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; $index_tpl = $v->tpl_index; } } if(in_array($index_tpl,Yii::app()->params['print_topic_tpl'])) { $flag = 0; } if($flag==3 || $flag==4 || $flag == 12) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('type=:type'); $criteria->params[':type'] = 0; $getResult = ClassExamPrinter::model()->findAll($criteria); if (!empty($getResult)) { ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria); } } if($flag==2 || $flag==11){ $this->schoolManager->saveExamProcess($exam_data->exam_group_id,14,time()); }else{ $this->schoolManager->saveExamProcess($exam_data->exam_group_id,9,time()); } } echo $getRes;die; } // 验证试卷是否已上传模板 public function actionVerifyTpl(){ $eid = Req::post('eid'); $error['success'] = 0; if (empty($eid)) { $error['message'] = '考试信息不存在!'; echo json_encode($error);exit(); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } if (empty($paperInfo->tpl_doc_src)) { $error['message'] = '未上传模板!'; echo json_encode($error);exit(); } else { $error['success'] = 1; $error['message'] = '已上传模板!'; echo json_encode($error);exit(); } //$getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpapertpl', 'paperId='.$paperInfo->paper_id); //echo $getRes; } public function actionCheckAnswerCard(){ $eid = Req::post('eid'); $error['success'] = 0; if (empty($eid)) { $error['message'] = '考试信息不存在!'; echo json_encode($error);exit(); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { $error['message'] = '未找到试卷信息!'; echo json_encode($error);exit(); } if (empty($paperInfo->answer_card_src)) { $error['message'] = '未上传模板!'; echo json_encode($error);exit(); } else { $error['success'] = 1; $error['message'] = '已上传模板!'; echo json_encode($error);exit(); } } // 上传试卷模板 public function actionUploadTpl(){ $eid = Req::post('eid'); $type = Req::post("type"); $error['success'] = 0; if (empty($eid)) { $error['message'] = '周周练id不存在!'; echo json_encode($error);exit(); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { $error['message'] = '未找到试卷信息333!'; echo json_encode($error);exit(); } $examInfo = Exam::model()->findByPk($eid); if(empty($examInfo)){ $error['message'] = '未找到统考信息!'; echo json_encode($error);exit(); } if (empty($_FILES['word_file'])) { $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); } if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){ $error['message'] = '非法上传!'; echo json_encode($error);exit(); } if ($_FILES['word_file']['error'] > 0) { switch ($_FILES['word_file']['error']) { case 1: $error['message'] = '文件大小超出了服务器的空间大小!'; break; case 2: $error['message'] = '要上传的文件大小超出浏览器限制!'; break; case 3: $error['message'] = '文件只有部分被上传!'; break; case 4: $error['message'] = '没有找到要上传的文件!'; break; case 5: $error['message'] = '服务器临时文件夹丢失!'; break; case 6: $error['message'] = '文件写入到临时文件夹出错!'; break; } echo json_encode($error);exit(); } // 保存上传文件至服务器 $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/word/'. date('Y') .'/'. date('m') . '/'; if (!file_exists($pathName)) { mkdir($pathName, 0777, true); } $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.')); $fileName = uniqid() . $extName; if (!move_uploaded_file($_FILES['word_file']['tmp_name'], $pathName.$fileName)) { $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } $param['tpl_name'] = $_FILES['word_file']['name']; $param['paperId'] = $paperInfo->paper_id; $param['templetA'] = $_FILES['word_file']['type']; $param['path_tpl'] = $pathName.$fileName; $fileSrc = $pathName.$fileName; //FIXME 20191224 if(file_exists($fileSrc)){ $rename = 'zsyas2/uploadTpl/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $extName; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $fileSrc); @unlink($fileSrc); if ($uploadInfo['status'] == 0) { $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); }else{ $examModel = new Exam(); $examIds = $examModel->getExamIds($examInfo['exam_group_id']); if(empty($examIds)){ $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); if($type == 1){ $this->sConn->createCommand("update paper set tpl_doc_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute(); } else if($type == 2){ $this->sConn->createCommand("update paper set answer_card_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute(); } else{ $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } $error['success'] = 1; $error['message'] = '上传成功!'; echo json_encode($error);exit(); } }else{ $error['message'] = '上传文件失败!'; echo json_encode($error);exit(); } } public function actionExportExcel(){ $classId = Req::get("classId"); $examId = Req::get("examId"); $class = $this->schoolManager->getClass($classId); $exam = $this->schoolManager->getExam($examId); $className = $class ? $class["class_name"] : ""; $wpName = $exam ? $exam["name"] : ""; $report = $this->schoolManager->getExamRsByClass($examId, $classId, array(), "EXCEL"); $excel = new Excel(); $fileName = "{$className}-{$wpName}报告"; $excel->export($report, $fileName); } public function actionReplaceIspTopicAct(){ $planId = Req::post("planId"); $previousTopicId = Req::post("previousTopicId"); $newTopicId = Req::post("newTopicId"); $rs = $this->schoolManager->replaceIspTopic($planId, $previousTopicId, $newTopicId); echo json_encode($rs);exit; } public function actionIspCheck(){ $planId = Req::get("planId"); $isp = $this->schoolManager->getIspInfo($planId); if(!$isp) Yii::app()->jump->error('个性化学习宝不存在'); $topics = $this->schoolManager->getIspTopics($planId); $sections = $this->schoolManager->composeIspTopics($planId, $topics); unset($topics); $paper = $this->schoolManager->getExamPaper($isp["exam_id"]); $ispTopicsIds = $this->schoolManager->getIspTopicsIds($planId); $this->render("ispcheck", array( "topicSections" => $sections, "isp" => $isp, "planId" => $planId, "examId" => $isp["exam_id"], "paperId" => $paper ? $paper["paper_id"] : null, "ispTopicsIds" => implode(",", $ispTopicsIds), )); } public function actionAjaxGetPaperTopicReplace() { $error = array(); $result = array(); if ( ! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest) { $error[] = '错误的来源!'; } else { $examId = Yii::app()->request->getPost('examId'); $paperId = Yii::app()->request->getPost('paperId'); $topicType = (int)Yii::app()->request->getPost('topicType'); $topicId = (int)Yii::app()->request->getPost('topicId'); $methodId = (int)Yii::app()->request->getPost('methodId'); $methodDifficulty = (int)Yii::app()->request->getPost('methodDifficulty'); $notIncludeTopicId = (int)Yii::app()->request->getPost('notIncludeTopicId'); $num = (int)Yii::app()->request->getPost('num', 1); $isArray = (int)Yii::app()->request->getPost('isArray'); $isFind = (int)Yii::app()->request->getPost('isFind'); $notInTopicsIds = Req::post('notInTopicsIds'); if ( ! $paperId OR ! is_numeric($paperId)) { $error[] = '必须指定paperId'; } else { $paperCls = new SPaper(); $paperDetail = $paperCls->getDetailByPaperId($paperId); if ( ! $paperDetail) { $error[] = '未找到指定的 试卷'; } } if ($topicType <= 0) { $error[] = '必须指定 topicType'; } elseif ( ! in_array($topicType, array(1, 5, 7))) { $error[] = '不允许的 topicType'; } if ($topicId <= 0) { $error[] = '必须指定 topicId'; } if (empty($methodId)) { $error[] = '必须指定 methodId'; } if ($methodDifficulty <= 0 OR $methodDifficulty > 3) { $error[] = '不允许的 methodDifficulty'; } if ($num <= 0) $num = 1; } if ( ! $error) { $paperTopicRelationCls = new SPaperTopicRelation(); $paperTopicRelationDetail = $paperTopicRelationCls->getDetailByPaperId_TopicId($paperId, $topicId); if ( ! $paperTopicRelationDetail) { $error[] = '未找到指定的试题'; } else { $topicScore = $paperTopicRelationDetail['score']; } } if ( ! $error) { $methodId = explode(",", $methodId); $notInTopicsIds = explode(",", $notInTopicsIds); $topicRule = array( 'num' => $num, 'score' => $topicScore, 'types' => $topicType, 'difficultys' => $methodDifficulty, 'methods' => $methodId, ); // if ( ! $isFind) // { // $topicRule['difficultys'] = $methodDifficulty; // } $topicItem = $this->apiPost('/smart/pull', array( 'subjectId' => Yii::app()->params['subject_id'], 'notInTopicsIds' => $notInTopicsIds, 'rules' => array($topicRule), )); if (isset($topicItem->error)) { $error[] = $topicItem->error; } else { if ( ! $isArray AND $num == 1) { $result = $topicItem[0]; } else { $result = $topicItem; } } } if ( ! $error) { if ( ! $result) { $error[] = '未找到符合的题'; } } //header('Content-Type: application/json'); if ($error) { echo json_encode(array('status' => 0, 'error'=> implode('
', $error)));exit; } else { $result = Obj::toArr($result); $topic = $this->schoolManager->getTopic($topicId); $topicMethosCount = isset($topic["specials"]) ? count($topic["specials"]) : 0; $matchTopics = array(); foreach($result as $key => $val){ $sameCount = 0; $diffCount = 0; if(isset($val["specials"]) && isset($topic["specials"])){ $diff1 = Arr::diff($val["specials"], $topic["specials"]); $diff2 = Arr::diff($topic["specials"], $val["specials"]); if(!$diff1 && !$diff2){ $matchTopics[] = $val; unset($result[$key]); continue; } if($diff1) $diffCount = count($diff1); $same = Arr::intersect($topic["specials"], $val["specials"]); if($same) $sameCount = count($same); } $result[$key]["methods_same_count"] = $sameCount; $result[$key]["methods_diff_count"] = $diffCount; } //按照考点不同点升序排序 Arr::sortByField($result, "methods_diff_count"); //按照考点相同点降序排序 Arr::sortByField($result, "methods_same_count", "DESC"); //合并完全匹配考点和部分匹配考点的题 完全匹配在前 $result = Arr::merge($matchTopics, $result); echo json_encode($result);exit; } } public function actionSetPrintTransChecked(){ $planId = Req::post("planId"); $classId = Req::post("classId"); $examId = Req::post("examId"); $studentId = $this->schoolManager->getStudentIdByIspId($planId); $this->schoolManager->setStudentIspChecked($planId); $this->schoolManager->setPrintTransChecked($classId, $examId); $arr=array( 'cate' => 3, 'schoolId' => $this->schoolId, 'examId' => $examId, 'studentId'=>$studentId ); $send_json=json_encode($arr); $stompconn = new Stomp(Yii::app()->params["activeMq"]["server"]); $stompconn->send("wb_isp_html", $send_json); unset($stompconn); $redis_obj = new Redis(); $server = Yii::app()->params["redis"]["server"]; $redis_obj->connect($server["host"], $server["port"]); $redis_obj->auth($server["password"]); $redis_obj->select(2); $redis_obj->set('activeMq.wb_isp_consumer.producer_time',time()); $this->redirect($this->createUrl("print/studentsispslist?classId={$classId}&examId={$examId}")); } public function actionIspsList(){ $getName = safe_replace(Yii::app()->request->getQuery('printName')); $getStatus = safe_replace(Yii::app()->request->getQuery('status')); $statusArray= array(); if ($getStatus !== '') { $statusArray= array($getStatus); } // 打印任务处理 $ExamModel = Exam::model(); $ClassModel = ClassModel::model(); $printList = array(); // 获取当前学期班级并组装 $class_array= ClassModel::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']); $ccArray = array(); $ccName = array(); foreach ($class_array as $cc=>$ca) { array_push($ccArray, $ca->class_id); $ccName[$ca->class_id] = $ca->class_name; } if(Yii::app()->session['coachInfo']['leader'] == 1) { $resultList = $this->schoolManager->getPrintList(array("cep.type = 2")); } else{ $resultList = $this->schoolManager->getPrintListOfCoach($this->coachId, array("cep.type = 2")); } if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k] = $v; $printList[$k]['class_name'] = @$ccName[$v["class_id"]]; $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称 if ($v["type"] == 1) { $printList[$k]['print_name']= $pname.'"纠错本"打印任务!'; } elseif ($v["type"] == 2) { $printList[$k]['print_name']= $pname.'"个性化学习宝"打印任务!'; } else { $printList[$k]['print_name']= $pname.'打印任务!'; } } } $data = array(); $data['getName'] = $getName; $data['status'] = $getStatus; $data['printList'] = $printList; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; unset($resultList); $this->render("ispslist", $data); } public function actionStudentsIspsList(){ $classId = Req::get("classId"); $examId = Req::get("examId"); $isps = $this->schoolManager->getClassStudentsIspsList($classId, $examId); $this->render("studentsispslist", array( "isps" => $isps, )); } public function actionUploadConfirm() { $error = array(); if (Yii::app()->request->getIsPostRequest()) { $classId = safe_replace(Yii::app()->request->getPost('classId')); $examId = safe_replace(Yii::app()->request->getPost('examId')); if ( ! $classId AND ! is_numeric($classId)) { $error[] = 'Params: classId error.'; } if ( ! $examId AND ! is_numeric($examId)) { $error[] = 'Params: examId error.'; } } else { $error[] = 'Must post request.'; } if ( ! $error) { /*$relations = $this->schoolManager->getExamClassesRelations($examId); $uploadedRelations = $this->schoolManager->getExamClassesRelationsFilteredByUploadStatus($examId, 2); if (count($relations) == count($uploadedRelations)) {*/ $this->schoolManager->changeExamStatus($examId, 4); $this->schoolManager->changeExamUploadStatus($examId, 2); //} if (!$error && ($examGroupId = $this->schoolManager->getExamGroupIdByExamId($examId))) { $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId); if ($examIds) { $exams = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = '2'")); if (count($examIds) == count($exams)) { $examGroup = SExamGroup::model()->find('exam_group_id = :examGroupId', array( ':examGroupId' => $examGroupId )); $examGroup->upload_status = 2; $examGroup->save(); } } } } if ($error) { echo json_encode(array('status' => 0, 'error' => implode(PHP_EOL, $error)));exit; } else { echo json_encode(array('status' => 1, 'error' => ''));exit; } } // // 更新试卷打印状态、时间 public function actionUpdatepaperprinttime() { $cid = Req::post("cid"); $eid = Req::post("eid"); $type = Req::post("type"); $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type)); if (!empty($getResult)) { $getResult->is_print = 1; $getResult->print_time = time(); if ($getResult->save()) { exit('1'); } else { exit('2'); } } } /* public function actionDownstudentexcel() { $filename="导入学生示例.xls"; $path = dirname(dirname(__FILE__)).'/data/'; $file=fopen($path.$filename,"r"); Header("Content-type:application/octet-stream"); Header("Accept-Ranges:bytes"); header("Content-Type:application/msexcel"); Header("Accept-Length:".filesize($path.$filename)); Header("Content-Disposition:attachment;filename=".$filename); echo fread($file,filesize($path.$filename)); fclose($file); } */ /** * 发送/取消/重新发送标注 */ public function actionSendLabelTask(){ $examId = Req::post("examId"); $examName = Req::post("examName"); $createTime = Req::post("createTime"); $type = Req::post('type'); $status = Req::post('status'); $remark = Req::post('remark'); $isTagging = Req::post('isTagging'); //新方法宝发送标注 $estimate= Req::post('estimate'); //期望时间 if(!$examId || !$examName || !$type){ echo json_encode(array("success" => 0, "message" => "缺少必要参数")); exit(); } if(!($paper = $this->schoolManager->getExamPaper($examId))){ echo json_encode(array("success" => 0, "message" => "找不到试卷")); exit(); } if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){ echo json_encode(array("success" => 0, "message" => "找不到试卷题目")); exit(); } $labelledType=$paper['labelled_type']; //标注类型 $subjectId = 0; $examTime = time(); if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){ $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData); if(isset($tplData["examDate"])) $examTime = strtotime($tplData["examDate"]); } //取消和重新发送的时候判断题库那边是否已经标注完成 $sql = "select is_third,qxk_paper_id,is_tagging from exam_group where exam_group_id = '{$exam['exam_group_id']}'"; $examGroup = $this->sConn->createCommand($sql)->queryRow(); if ($status==='2' || $status==='4' || $status==='3'){ $is_labelled = $paper['is_labelled']; if ($is_labelled==='1'){ echo json_encode(array( 'success' => 2, 'message' => '已经标注完成,点击确定后刷新状态。' )); exit; } } $this->setIs_new($exam['exam_group_id']); if ($type=='cancel'){ $title = '取消标注'; }elseif ($type=='resend'){ $title = '重新发送标注'; }else{ $title = '发送标注'; } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam['exam_group_id'], "operate_project" => 'zsyas2', "title" => $title, "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => '', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } //判断学科 if($subjectId==8 && !$isTagging){ $topics = array(); foreach($topicsRecords as $topicRecord){ $topics[$topicRecord["stem_id"]] = array( "topic_id" => $topicRecord["stem_id"], "school_id" => $topicRecord["mode"] ? $this->schoolId : 0, "topic_type" => $topicRecord["type"], "no" => $topicRecord["no"], ); } $jsonArr = array(); $jsonArr['exam_name'] = $examName; $jsonArr['school_id'] = $this->schoolId; $jsonArr['exam_group_id'] = $exam['exam_group_id']; $jsonArr['exam_time'] = $examTime; $jsonArr['origin'] = 'zxhx'; //校本课程平台试卷 $jsonArr['exam_topic'] = $topics; //校本课程平台试卷 if($type=='send' || $type=='resend'){ $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr)); $resultArr=json_decode($result,true); if($resultArr['status'] == 1) { $sql = "select exam_id from exam where exam_group_id = '{$exam['exam_group_id']}'"; $examAll = $this->sConn->createCommand($sql)->queryAll(); $examArr = array(); if ($examAll) { foreach ($examAll as $k => $v) { $examArr[] = $v['exam_id']; } $transcation = $this->sConn->beginTransaction(); try { $this->sConn->createCommand("update paper set is_labelled = 3,labelled_type=1,send_labelled_time='".time()."' where exam_id in (" . implode(',', $examArr) . ")")->execute(); $transcation->commit(); $rs['success'] = 1; $rs = json_encode($rs); } catch (Exception $e) { $transcation->rollback(); $error['message'] = '更新失败!'; $error['success'] = 0; echo json_encode($error); exit(); } } else { $error['message'] = '考试信息错误!'; $error['success'] = 0; echo json_encode($error); exit(); } }elseif($resultArr['status'] == 2){ //完成标注 $rs['success'] = 1; $rs = json_encode($rs); }else{ $error['message'] = $resultArr['message']; $error['success']=0; echo json_encode($error);exit(); } }else{ if($labelledType==2){ if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){ $error['message'] = '取消成功'; $error['success']=1; echo json_encode($error);exit(); }else{ $error['message'] = '取消失败'; $error['success']=0; echo json_encode($error);exit(); } }else{ $result = Curl::http_post_json(Yii::app()->params['english_cancel_mark'], json_encode($jsonArr)); $resultArr=json_decode($result,true); if($resultArr['status'] == 1){ $error['message'] = '取消成功'; $error['success']=1; echo json_encode($error);exit(); }else{ $error['message'] = $resultArr['message']; $error['success']=0; echo json_encode($error);exit(); } } } }else if($subjectId==12 || Yii::app()->params['section']==0 || $isTagging){ $topics = array(); if($type=='send' && Yii::app()->params['section']==1){ if(!$estimate){ echo json_encode(array("success" => 0, "message" => "期望时间不能为空")); exit(); } if(strtotime($estimate) 0, "message" => "期望时间不正确")); exit(); } } if(!$isTagging && $examGroup['is_third']){ if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecordsByTopic($paper["paper_id"]))){ echo json_encode(array("success" => 0, "message" => "找不到试卷题目")); exit(); } foreach($topicsRecords as $topicRecord){ $topics[] = array( "topic_id" => $topicRecord["topic_id"], "school_id" => $topicRecord["mode"] ? $this->schoolId : 0, "topic_type_id" => $topicRecord["bank_type"], ); } }else{ foreach($topicsRecords as $topicRecord){ if($topicRecord["stem_id"]){ $topics[(string)$topicRecord["stem_id"]] = array( "topic_id" => $topicRecord["stem_id"], "school_id" => $topicRecord["mode"] ? $this->schoolId : 0, "topic_type_id" => $topicRecord["logic_type"], ); }else{ $topics[] = array( "topic_id" => $topicRecord["topic_id"], "school_id" => $topicRecord["mode"] ? $this->schoolId : 0, "topic_type_id" => $topicRecord["logic_type"], ); } } } $topics=array_values($topics); $orderType=array(); //学生订单类型 if($type=='send' || $type=='resend'){ //判断权限 if(!in_array($this->schoolId,array(476,353,3922,3865))){ if($isTagging && $this->subjectId==3) { $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(31, 1, 2, 3,66)); }elseif($isTagging && $this->subjectId==8){ $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(3,1)); }elseif($isTagging){ $checkRs=$this->checkProductOrderDetail($exam['exam_group_id'],$subjectId,array(31)); }else{ $checkRs=$this->checkLabelTaskOrderDetail($exam['exam_group_id'],$subjectId); } if($checkRs==-1){ $error['message'] = '接口异常'; $error['success']=0; echo json_encode($error);exit(); }elseif($checkRs==-2){ $error['message'] = '考试参数异常'; $error['success']=0; echo json_encode($error);exit(); }elseif(!$checkRs){ $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注'; $error['success']=0; echo json_encode($error);exit(); } $orderType=$checkRs; } } if(in_array($subjectId,$this->mathSubjectId) && $examGroup['qxk_paper_id']==0 && Yii::app()->params['section']==1){ $orderType=array(); $orderType[]=array( 'goodsTypeId'=>31, 'goodsTypeName'=>'方法宝' ); } //读取班级相同题配置 $isPushSameTrain=0; if($this->findExamClassSameTrain($exam['exam_group_id'],$subjectId)){ $isPushSameTrain=1; } //计算预计时间 $realEstimate=$this->ComputeCompleteTime($exam['exam_group_id']); if($estimate){ $estimate=strtotime($estimate); if($estimate>$realEstimate['estimate']){ $realEstimate['estimate']=$estimate; } } $classExamPinter = new SClassExamPrinter(); $isNewLabel = $classExamPinter->getNewLabel($createTime); $classInfo=SClass::model()->getClassInfo($exam['class_id']); $gradeName=Yii::app()->params['grade_list'][$classInfo['grade']]['grade_name']; $provinceName=$this->schoolManager->getProvince($this->schoolInfo['province_id']); if($examGroup['is_third']){ $examType='第三方'; }else{ $examType='云题库'; } //是否百万校接口 $is_bw=$this->checkSchoolBW(); if ($type=='send'){ $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/index', array( "schoolId" => $this->schoolId, "subjectId" => $subjectId, "examGroupId" => (string)$exam['exam_group_id'], "examName" => $examName, "coachName" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称 "schoolName" => isset($this->schoolInfo['school_name'])?$this->schoolInfo['school_name']:'',//学校名称 "examTopics" => $topics, "isTagging"=>$isTagging, 'isVariant'=>$isPushSameTrain, 'remark'=>$remark, 'testTime'=>$examTime, 'testNumber'=>$realEstimate['studentNumber'], 'isNewSchool'=>$isNewLabel, 'isMillionSchool'=>$is_bw, 'predictCompleteTime'=>$realEstimate['estimate'], 'qxkPaperId'=>$examGroup['qxk_paper_id'], 'orderType'=>$orderType, 'gradeName'=>$gradeName, 'provinceName'=>$provinceName, 'examType'=>$examType, )); $tplData['estimateTime']=$realEstimate['estimate']; $this->schoolManager->updateEstimateTime($exam['exam_group_id'],jsonEncode($tplData)); }else{ $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_paper_status', array( "updateType" => $status, "schoolId" => $this->schoolId, "subjectId" => $subjectId, "examGroupId" => (string)$exam['exam_group_id'], "isTagging"=>$isTagging )); $apiReturn=json_decode($rs,1); } }else{ $topics = array(); foreach($topicsRecords as $topicRecord){ $topics[] = array( "topic_id" => $topicRecord["topic_id"], "school_id" => $topicRecord["mode"] ? $this->schoolId : 0, "topic_type" => $topicRecord["type"], "is_null_method" => empty($topicRecord["method_ids"]) ? 1 : 0, ); } if($type=='send' || $type=='resend'){ //判断权限 if(!in_array($this->schoolId,array(476,353))){ $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId); if($checkRs==-1){ $error['message'] = '接口异常'; $error['success']=0; echo json_encode($error);exit(); }elseif($checkRs==-2){ $error['message'] = '考试参数异常'; $error['success']=0; echo json_encode($error);exit(); }elseif(!$checkRs){ $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注'; $error['success']=0; echo json_encode($error);exit(); } } } //读取班级相同题配置 $isPushSameTrain=0; if($this->findExamClassSameTrain($exam['exam_group_id'])){ $isPushSameTrain=1; } $classExamPinter = new SClassExamPrinter(); $isNewLabel = $classExamPinter->getNewLabel($createTime); //统计班级和人数 $is_bw =0; //是否百万校 $class_number=0; //班级数量 $student_number=0; //学生数量 $countExamStudent=$this->schoolManager->countExamsAndStudents($exam['exam_group_id']); if($countExamStudent){ if(isset($countExamStudent['classes'])){ $class_number=$countExamStudent['classes']; } if(isset($countExamStudent['students'])){ $student_number=$countExamStudent['students']; } } //是否百万校接口 $is_bw=$this->checkSchoolBW(); if (($labelledType==2 && $type=='resend') || $type=='send'){ if($labelledType==2){ $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1); } $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/index', array( "schoolId" => $this->schoolId, "examId" => $examId, "examName" => $examName, "subjectId" => $subjectId, "examTime" => $createTime, "testTime" => $examTime, "exam_topic" => $topics, "exam_group_id" => (string)$exam['exam_group_id'], "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称 "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间 "is_new_label" => $isNewLabel, "remark" => $remark,//发送备注 'class_number'=>$class_number, 'student_number'=>$student_number, 'is_bw'=>$is_bw, 'isVariant'=>$isPushSameTrain, 'qxkPaperId'=>$examGroup['qxk_paper_id'] )); }else{ if($labelledType==2 && $type=='cancel'){ if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){ $error['message'] = '取消成功'; $error['success']=1; echo json_encode($error);exit(); }else{ $error['message'] = '取消失败'; $error['success']=0; echo json_encode($error);exit(); } }else{ if($labelledType==2){ $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1); } $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/set_paper_status', array( "status" => $status, "schoolId" => $this->schoolId, "examId" => $examId, "exam_group_id" => (string)$exam['exam_group_id'], "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称 "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间 "is_new_label" => $isNewLabel, "remark" => $remark,//发送备注 'class_number'=>$class_number, 'student_number'=>$student_number, 'is_bw'=>$is_bw )); } } } $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time()); echo $rs;exit; } //发送标注到教师端 public function actionSendLabelToTeacher(){ $examId = Req::post("examId"); $type = Req::post('type'); $status = Req::post('status'); $remark = Req::post('remark'); if(!$examId || !$type){ echo json_encode(array("success" => 0, "message" => "缺少必要参数")); exit(); } if(!($paper = $this->schoolManager->getExamPaper($examId))){ echo json_encode(array("success" => 0, "message" => "找不到试卷")); exit(); } if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){ echo json_encode(array("success" => 0, "message" => "找不到试卷题目")); exit(); } //取消和重新发送的时候判断题库那边是否已经标注完成 if ($status==='2' || $status==='4' || $status==='3'){ $is_labelled = $paper['is_labelled']; if ($is_labelled==='1'){ echo json_encode(array( 'success' => 2, 'message' => '教师端已经标注完成,点击确定后刷新状态。' )); exit; } } if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){ $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData); } $this->setIs_new($exam['exam_group_id']); if ($type=='cancel'){ $title = '取消标注'; }elseif ($type=='resend'){ $title = '重新发送标注'; }else{ $title = '发送标注'; } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam['exam_group_id'], "operate_project" => 'zsyas2', "title" => $title, "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => '', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } //判断学科 if($type=='send' || $type=='resend'){ //判断权限 if(!in_array($this->schoolId,array(476,353))){ $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId); if($checkRs==-1){ $error['message'] = '接口异常'; $error['success']=0; echo json_encode($error);exit(); }elseif($checkRs==-2){ $error['message'] = '考试参数异常'; $error['success']=0; echo json_encode($error);exit(); }elseif(!$checkRs){ $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注'; $error['success']=0; echo json_encode($error);exit(); } } } if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],$type)){ $error['message'] = '操作成功'; $error['success']=1; $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time()); echo json_encode($error);exit(); }else{ $error['message'] = '发送失败'; $error['success']=0; echo json_encode($error);exit(); } } //检查学生订单权限 public function checkLabelTaskOrder($exam_group_id,$subjectId){ $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id); if(!$examData){ return -2; } $examIds=array(); foreach ($examData as $val){ $examIds[]=$val; } $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0])); $studentIds=array(); $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll(); if(!$rs){ return -2; } $class_id=0; foreach ($rs as $val){ if(!$class_id){ $class_id=$val['class_id']; } $studentIds[]=$val['student_id']; } $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id)); if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){ $subjectId=3; } $intarr=array( "subject"=>$subjectId, "grade"=>$classinfo->grade, "examTime"=>$print_time[0]->add_time, "students"=>$studentIds, ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url"], json_encode($intarr),$basic),true); if(!$rs){ return -1; } if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']['hasAnyPermit'])){ if($rs['data']['hasAnyPermit']){ return 1; }else{ return 0; } }else{ return -1; } } //检查指定产品学生订单权限 public function checkProductOrder($exam_group_id,$subjectId,$classify=array()){ $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id); if(!$examData){ return -2; } $examIds=array(); foreach ($examData as $val){ $examIds[]=$val; } $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0])); $studentIds=array(); $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll(); if(!$rs){ return -2; } $class_id=0; foreach ($rs as $val){ if(!$class_id){ $class_id=$val['class_id']; } $studentIds[]=$val['student_id']; } $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id)); if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){ $subjectId=3; } if($classify){ foreach ($classify as $item){ $intarr[]=array( "subject"=>$subjectId, "grade"=>$classinfo->grade, "examTime"=>$print_time[0]->add_time, "students"=>$studentIds, 'clazzId'=>'', 'semester'=>$this->semesterId, 'classify'=>$item ); } } $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr),$basic),true); if(!$rs){ return -1; } if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']) && $rs['data']){ foreach ($rs['data'] as $r){ if(count($r)>0){ return 1; } } return 0; }else{ return -1; } } //检查指定产品学生订单权限并返回订单详细 //examIds 用于添加删除班级判断订单,由于事务还没提交,所以直接查exam表数据不对 public function checkProductOrderDetail($exam_group_id,$subjectId,$classify=array(),$notUpdateExamIds=array()){ $examIds=array(); if($notUpdateExamIds){ $examIds=$notUpdateExamIds; }else{ $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id); if(!$examData){ return -2; } foreach ($examData as $val){ $examIds[]=$val; } } $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0])); $studentIds=array(); $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll(); if(!$rs){ return -2; } $class_id=0; foreach ($rs as $val){ if(!$class_id){ $class_id=$val['class_id']; } $studentIds[]=$val['student_id']; } $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id)); if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){ $subjectId=3; } if($classify){ foreach ($classify as $item){ $intarr[]=array( "subject"=>$subjectId, "grade"=>$classinfo->grade, "examTime"=>$print_time[0]->add_time, "students"=>$studentIds, 'clazzId'=>'', 'semester'=>$this->semesterId, 'classify'=>$item ); } } $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_detail_url"], json_encode($intarr),$basic),true); if(!$rs){ return -1; } if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){ if( $rs['data']){ return $rs['data']; }else{ return 0; } }else{ return -1; } } //检查学生订单权限,并返回学生订单类型 public function checkLabelTaskOrderDetail($exam_group_id,$subjectId){ $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id); if(!$examData){ return -2; } $examIds=array(); foreach ($examData as $val){ $examIds[]=$val; } $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0])); $studentIds=array(); $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll(); if(!$rs){ return -2; } $class_id=0; foreach ($rs as $val){ if(!$class_id){ $class_id=$val['class_id']; } $studentIds[]=$val['student_id']; } $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id)); if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){ $subjectId=3; } $intarr=array( "subject"=>$subjectId, "grade"=>$classinfo->grade, "examTime"=>$print_time[0]->add_time, "students"=>$studentIds, ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_any_limit_detail_url"], json_encode($intarr),$basic),true); if(!$rs){ return -1; } if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){ if($rs['data']){ return $rs['data']; }else{ return 0; } }else{ return -1; } } public function actionGetImproveFile(){ $examId = Req::get("examId"); $classId = Req::get("classId"); $type = Req::get("type"); $studentsIds = Req::get("studentsIds"); $printType = Req::get("printType"); $students_ids = array(); $is_isp_student_ids = array(); $is_wbisp_student_ids = array(); $is_wrongbook_student_ids = array(); if(!$examId || !$classId || !$type){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!in_array($type, array(1, 2, 3))){ echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $groupInfo = Exam::model()->getGroupInfo($examId); if(empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误"))); $typeRel = array('1'=>'wb_group_id','2'=>'isp_group_id','3'=>'wbisp_group_id'); $groupId = $groupInfo[$typeRel[$type]]; if(!empty($groupId)){ $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null; }else{ $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } //$apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null; // $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; // echo $apiUrl;exit; //$apiUrl = isset(Yii::app()->params["improve_url"][0]) ? Yii::app()->params["improve_url"][0] : null; if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "examId" => $examId, "classId" => $classId, "type" => $type, "studentIds" => array(), ); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId)); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$classinfo['semester_id']."'") ->limit(1) ->query() ->read(); $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$examId,':classid'=>$classId)); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$classId, "semester"=>$code['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>$print_time[0]->add_time, "classify"=>$type, ); //判断学科 $examInfo = Exam::model()->findByPk($examId); $intarr['subject']=$examInfo['subject_id']; if($intarr['subject']==6){ $intarr['subject']=3; } if(in_array($intarr['subject'],$this->mathSubjectId)){ $intarr['subject']=3; } if ($studentsIds) { $studentsIds = explode(",", $studentsIds); foreach ($studentsIds as $key => $val) { $val = trim($val); if ($val == null) { unset($studentsIds[$key]); continue; } $students_ids[$val] = $val; $studentsIds[$key] = $val; } $intarr['students'] = $studentsIds; $stu = SStudentPaperRelation::model()->findAll("exam_id=:eid", array(":eid" => $examId)); foreach ($stu as $key => $val) { if (isset($students_ids[$val->student_id])) { if ($val->is_isp_pdf == 1) { $is_isp_student_ids[$val->student_id] = $val->student_id; } if ($val->is_wbisp_pdf == 1) { $is_wbisp_student_ids[$val->student_id] = $val->student_id; } if ($val->is_wrongbook_pdf == 1) { $is_wrongbook_student_ids[$val->student_id] = $val->student_id; } } } } else { $stu = SStudentPaperRelation::model()->findAll("class_id=:class_id and exam_id=:eid", array(":class_id" => $classId, ":eid" => $examId)); foreach ($stu as $key => $val) { $intarr['students'][] = $val->student_id; if ($val->is_isp_pdf == 1) { $is_isp_student_ids[$val->student_id] = $val->student_id; } if ($val->is_wbisp_pdf == 1) { $is_wbisp_student_ids[$val->student_id] = $val->student_id; } if ($val->is_wrongbook_pdf == 1) { $is_wrongbook_student_ids[$val->student_id] = $val->student_id; } } } $limitinfo=""; //third_wb第三方多学科和英语不需要权限 // $subject_id = isset(Yii::app()->session['session_subject_id'])?Yii::app()->session['session_subject_id']:0; // $params["subjectId"] = $subject_id; // if($printType == 'third_wb' || $printType == 'third_isp' || $subject_id == 8){ // if($printType == 'third_isp'){ // $params["subjectId"] = 8; // $params["type"] = 2; // } // if($intarr["students"]){ // $params["studentIds"] = $intarr["students"]; // } // }else{ $_schoolId = isset(Yii::app()->session['coachInfo']['school_id'])?Yii::app()->session['coachInfo']['school_id']:0; if($printType == 'third_isp'){ $params["subjectId"] = 8; $params["type"] = 3; } if ($_schoolId) { $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $_schoolId)); } // if(isset(Yii::app()->session['testFlag']) && (Yii::app()->session['testFlag']==1)){ if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } // } $rs = Curl::post($apiUrl."/rest/download_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); } if($printType != 'third_wb'){ if($limitinfo!=""&&$rs->success!=0){ $rs->success=2; $rs->limitinfo=$limitinfo; } } if($type==1) { $criteria = new CDbCriteria(); $_students = array(); if(!is_array($params["studentIds"]) && $params["studentIds"]==1) { $_students = $is_wrongbook_student_ids; }else { foreach($params["studentIds"] as $v) { if(isset($is_wrongbook_student_ids[$v])) { $_students[] = $v; } } } if($_students){ $criteria->addInCondition('student_id',$_students); }else{ $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete '); $criteria->params[':is_complete'] = 1; $criteria->params[':is_feedback'] = 1; $criteria->params[':is_del'] = 1; } if($studentsIds || count($studentsIds)>0) { $criteria->addInCondition('student_id',$studentsIds); }else { $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $classId; } $criteria->addCondition('exam_id=:exam_id'); $criteria->addCondition('is_wrongbook_download=:is_wrongbook_download'); $criteria->params[':exam_id'] = $examId; $criteria->params[':is_wrongbook_download'] = 0; SStudentPaperRelation::model()->updateAll(array('is_wrongbook_download'=>1,'download_wrongbook_time'=>time()),$criteria); } if($type==2) { $criteria = new CDbCriteria(); $_students = array(); if(!is_array($params["studentIds"]) && $params["studentIds"]==1) { $_students = $is_isp_student_ids; }else { foreach($params["studentIds"] as $v) { if(isset($is_isp_student_ids[$v])) { $_students[] = $v; } } } if($_students){ $criteria->addInCondition('student_id',$_students); }else{ $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete '); $criteria->params[':is_complete'] = 1; $criteria->params[':is_feedback'] = 1; $criteria->params[':is_del'] = 1; } if($studentsIds || count($studentsIds)>0) { $criteria->addInCondition('student_id',$studentsIds); }else { $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $classId; } $criteria->addCondition('exam_id=:exam_id'); $criteria->addCondition('is_two_isp_download=:is_two_isp_download'); $criteria->params[':exam_id'] = $examId; $criteria->params[':is_two_isp_download'] = 0; SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),$criteria); } if($type==3) { $criteria = new CDbCriteria(); $_students = array(); if(!is_array($params["studentIds"]) && $params["studentIds"]==1) { $_students = $is_wbisp_student_ids; }else { foreach($params["studentIds"] as $v) { if(isset($is_wbisp_student_ids[$v])) { $_students[] = $v; } } } if($_students){ $criteria->addInCondition('student_id',$_students); }else{ $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete '); $criteria->params[':is_complete'] = 1; $criteria->params[':is_feedback'] = 1; $criteria->params[':is_del'] = 1; } if($studentsIds || count($studentsIds)>0) { $criteria->addInCondition('student_id',$studentsIds); }else { $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $classId; } $criteria->addCondition('exam_id=:exam_id'); $criteria->addCondition('is_three_isp_download=:is_three_isp_download'); $criteria->params[':exam_id'] = $examId; $criteria->params[':is_three_isp_download'] = 0; SStudentPaperRelation::model()->updateAll(array('is_three_isp_download'=>1,'download_three_isp_time'=>time()),$criteria); } if($groupId && isset($rs->downloadPath)){ if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath); } } echo json_encode($rs);exit; } public function setIs_new($exam_group_id) { if($exam_group_id) { Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); } } public function actionSetPaperSize(){ $examId = Req::post("examId"); $paperSize = Req::post("paperSize"); $mark_type = Req::post("mark_type"); $tpl_index = Req::post("tpl_index"); $exam_ids = array(); if(!$examId) $this->output(0, "参数错误[1]"); if(!$paperSize) $this->output(0, "参数错误[2]"); if(!in_array($paperSize, array("A3", "A4", "8K", "16K"))) $this->output(0, "参数错误[3]"); $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId)); $paper_topic_m_data = array(); if($paper_data) { $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id)); if($paper_topic_data) { foreach($paper_topic_data as $v) { $paper_topic_m_data[$v->type][] = $v->topic_id; } //30 ,30 15 if(((isset($paper_topic_m_data[1]) && count($paper_topic_m_data[1])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[5]) && count($paper_topic_m_data[5])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[7]) && count($paper_topic_m_data[7])>15 && in_array($paperSize, array("A4", "8K", "16K"))))) { $this->output(0, "题数太多,无法切换"); } } } $paperSizesAndTplIndexesRelations = array( "A3" => 12, "A4" => 13, "8K" => 14, "16K" => 15, ); if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 16, "A4" => 17, "8K" => 18, "16K" => 19, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl1"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 2012, "A4" => 2013, "8K" => 2014, "16K" => 2015, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl2"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 2016, "A4" => 2017, "8K" => 2018, "16K" => 2019, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl3"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 1012, "A4" => 1013, "8K" => 1014, "16K" => 1015, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl4"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 1016, "A4" => 1017, "8K" => 1018, "16K" => 1019, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl5"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 3016, "A4" => 3017, "8K" => 3018, "16K" => 3019, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl6"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 3012, "A4" => 3013, "8K" => 3014, "16K" => 3015, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl7"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 4016, "A4" => 4017, "8K" => 4018, "16K" => 4019, ); } if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl8"])) { $paperSizesAndTplIndexesRelations = array( "A3" => 4012, "A4" => 4013, "8K" => 4014, "16K" => 4015, ); } $exam_row = Exam::model()->find(array( 'select'=>array('exam_id,exam_group_id'), 'condition' => 'exam_id=:exam_id', 'params' => array(':exam_id'=>$examId) )); if($exam_row) { $exam_data = Exam::model()->findAll(array( 'select'=>array('exam_id,exam_group_id'), 'condition' => 'exam_group_id=:exam_group_id', 'params' => array(':exam_group_id'=>$exam_row->exam_group_id) )); if($exam_data) { foreach($exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id)); if(!$exam_group_array ) { $this->output(0, "非法数据"); } if($exam_group_array->upload_status>0) { $this->output(0, "无法修改,已上传数据"); } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_row->exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '更改试卷阅卷与纸张', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('update'=>array( 'ExamGroup'=>array('mark_type'=>$mark_type), 'exam'=>array('tpl_index'=>$paperSizesAndTplIndexesRelations[$paperSize],'update_time'=>time()), ))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $this->setIs_new($exam_row->exam_group_id); if(is_null($mark_type)) { $mark_type = $exam_group_array->mark_type; } if(is_numeric($mark_type)) { $transaction = $this->sConn->beginTransaction(); try{ if($exam_group_array->mark_type==4) { $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute(); }else { if($mark_type==4) { $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute(); } if($mark_type!=4 && $exam_group_array->mark_type!=4) { if($exam_group_array->mark_status == 0 ) { ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id)); $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute(); }else { //ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id)); $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}' where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute(); } } } $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); $this->output(0, "更改失败"); } } } } } $this->output(1, "更改成功"); } /** * 设置阅卷方式 */ public function actionSetmasktype(){ $exam_group_id = Req::post("exam_group_id"); $mark_type = Req::post("mark_type"); $tpl_index = Req::post("tpl_index"); $exam_ids = array(); if(!$exam_group_id) $this->output(0, "参数错误[1]"); $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_group_array ) { $this->output(0, "非法数据"); } if($exam_group_array['upload_status']>0){ $this->output(0, "已上传成绩不能修改阅卷方式"); } $thirdAnswerSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_array['is_third']==1 || $exam_group_array['is_scan_changed']==1){ if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==0 && $mark_type==0){ $this->output(0, "切割模板考试不能切换线下阅卷"); } } if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==1 && $mark_type==0){ //判断答题卡评阅类型 $check = $this->sConn->createCommand("select `marking_papers` from online_card_multiplex where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->queryRow(); if($check['marking_papers']!=1){ $this->output(0, "当前在线答题卡的评阅方式为网阅,不支持修改为线下阅卷,请进入在线答题卡修改评阅方式为手批后再更改阅卷方式!"); } } if(!in_array($mark_type,array(0,3,4))) $this->output(0, "阅卷方式不正确"); $transaction = $this->sConn->beginTransaction(); try{ if($exam_group_array['mark_type']==4 || $mark_type==4){ $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute(); } if($mark_type==4){ $exam=$this->sConn->createCommand("select exam_id,tpl_data,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryRow(); $paper=$this->sConn->createCommand("select paper_id from paper where exam_id='{$exam['exam_id']}'")->queryRow(); $paperTopic=$this->sConn->createCommand("select `order`,question_count,`type`,topic_id,score from paper_topic_relation where paper_id='{$paper['paper_id']}' and `type` not in(1,2,11)")->queryAll(); if($paperTopic){ $topicAutoType=array(); if($exam['subject_id']==8){ $tplData=json_decode($exam['tpl_data'],true); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $item){ $topicAutoType[$item['id']]=$item['logic_type']; } } } foreach ($paperTopic as $item){ $autoType=0; if(isset($topicAutoType[$item['order']])){ if(in_array($topicAutoType[$item['order']],array(13,16,17)) && $item['question_count']==0){ $autoType=1; }elseif($item['type']==5){ $autoType=2; } } $this->sConn->createCommand()->insert('marking_topic', array( 'exam_group_id' => $exam_group_id, 'topic_id' => $item['topic_id'], 'topic_type' => $item['type'], 'topic_index' =>$item['order'], 'topic_no' =>$item['order'], 'topic_score' =>$item['score'], 'auto_type'=>$autoType )); } } ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); }else{ ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>0),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); } $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '更改阅卷方式失败', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('update'=>array( 'ExamGroup'=>array('mark_type'=>$mark_type), ))), "error"=>$e->getMessage(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } $this->output(0, "更改失败"); } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '更改阅卷方式', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('update'=>array( 'ExamGroup'=>array('mark_type'=>$mark_type), ))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } $this->output(1, "更改成功"); } // 操作周周练显示状态 public function actionOprateexam(){ $exam_groupId = Req::post("exam_groupId"); $flag = Req::post("flag"); $error['success'] = 0; if (empty($exam_groupId)) { $error['message'] = '操作失败!'; echo json_encode($error);exit(); } $this->setIs_new($exam_groupId); if ($this->schoolManager->oprateExamDisplay($exam_groupId,$flag)) { $error['success'] = 1; $error['message'] = '操作成功!'; } else { $error['message'] = '操作失败!'; } echo json_encode($error);exit(); } // 根据年级获取班级 public function actionGetGradeClass(){ $grade = Req::post('grade'); $subjectId = Req::post('subjectId'); $filterHide=Req::post('filterHide'); if(!$filterHide){ $filterHide=0; }else{ $filterHide=1; } $error['success'] = 0; if (empty($grade)) { $error['message'] = '未找到年级!'; echo json_encode($error);exit(); } $classes=array(); //判断走班设置 if($subjectId){ $classified=$this->schoolManager->getSubjectByGrade($grade,$subjectId,Yii::app()->session['session_semester_id']); if($classified){ $classes=$this->schoolManager->getClassifiedBySubjectId($grade,$subjectId,Yii::app()->session['session_semester_id']); }else{ $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']); } }else{ $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']); } if ($classes) { $error['success'] = 1; $error['message'] = $classes; } else { $error['message'] = '未找到班级!'; } echo json_encode($error);exit(); } // 根据年级获取班级 public function actionGetGradeClassForExport(){ $grade = Req::post('grade'); $subjectId = Req::post('subjectId'); $error['success'] = 0; if (empty($grade)) { $error['message'] = '未找到年级!'; echo json_encode($error);exit(); } $classes=array(); $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']); if ($classes) { $error['success'] = 1; $error['message'] = $classes; } else { $error['message'] = '未找到班级!'; } echo json_encode($error);exit(); } /** * 作者:刘红伟 * 需求:删除本次考试,但已经考完的学生不能删除 * 时间:2016-10-25 */ public function actionDelPaperStudent() { $studentsIds = Req::post('studentsIds'); $exam_id = Req::post('exam_id'); $paper_id = Req::post('paper_id'); $class_id = Req::post('class_id'); if(!$studentsIds || !$exam_id || !$paper_id) { echo json_encode(array('status'=>0));exit; } $studentsIds = explode(',',$studentsIds); if($this->schoolManager->getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id)) { echo json_encode(array('status'=>2));exit; }; if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id)) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_data->exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '删除考试的学生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('delete'=>array( 'student_paper_relation'=>array('student_id'=>$studentsIds)))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } //发送学生端消息 // $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>2, 'exam_group_id'=>$exam_data->exam_group_id, 'exam_id_arr'=>array($exam_id), 'student_id_arr'=>$studentsIds ); sendStudentCacheQueue($sendJsonArr); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("zsyte-academic-offline-generate-report",$kafkaData); echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>0));exit; } public function actionDelPaperStudentAll() { $exam_id = Req::post('exam_id'); $paper_id = Req::post('paper_id'); $class_id = Req::post('class_id'); $studentsIds = array(); if(!$exam_id || !$paper_id) { echo json_encode(array('status'=>0));exit; } $student_data = SStudentPaperRelation::model()->findAll('paper_id=:paper_id and exam_id=:exam_id and is_feedback=:is_feedback and is_del=0',array(':paper_id'=>$paper_id,':exam_id'=>$exam_id,':is_feedback'=>0)); if($student_data) { foreach($student_data as $v) { $studentsIds[$v->student_id] = $v->student_id; } } if(!$studentsIds){ echo json_encode(array('status'=>2));exit; } if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id)) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_data->exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '清空本次考试的学生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('delete'=>array( 'student_paper_relation'=>array('student_id'=>$studentsIds)))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } //发送学生端消息 $sendJsonArr = array( 'school_id' => $this->schoolId, 'send_type' => 'zsyas', 'update_type' => 2, 'exam_group_id' => $exam_data->exam_group_id, 'exam_id_arr' => array($exam_id), 'student_id_arr' => $studentsIds ); sendStudentCacheQueue($sendJsonArr); echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>0));exit; } public function actionAddPaperStudent() { $studentsIds = Req::post('studentsIds'); $exam_id = Req::post('exam_id'); $paper_id = Req::post('paper_id'); $class_id = Req::post('class_id'); $exam_ids = array(); $student_ids = array(); $student_names = array(); $add_student_paper = array(); $del_student_paper = array(); $student_cards = array(); $school_student_cards = array(); if(!$exam_id || !$paper_id || !$class_id || !$studentsIds || !$this->semesterId) { echo json_encode(array('status'=>0));exit; } if($this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id)) { echo json_encode(array('status'=>2));exit; } $student_array = explode(',',$studentsIds); /* $student_paper_del_data = $this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id,1); if($student_paper_del_data) { foreach($student_paper_del_data as $v) { $del_student_paper[$v['student_id']] = $v['student_id']; } } $add_student_paper = array_diff($student_array,$del_student_paper);*/ /** *加入准考证号 */ $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_array); $criteria->addCondition('status = 0'); $business_student_data = BusinessStudent::model()->findAll($criteria); if($business_student_data) { foreach($business_student_data as $v) { $student_cards[$v->student_id] = $v->student_card; $school_student_cards[$v->student_id] = $v->school_student_card; } } if(!$student_cards) { echo json_encode(array('status'=>0));exit; } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data) { $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId)); if($class_data) { $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade)); } $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($group_exam_data) { foreach($group_exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } $student_paper_data = $this->schoolManager->getStudentsByStudentIdsAndExam_ids(implode(',',$exam_ids),$studentsIds); if($student_paper_data) { foreach($student_paper_data as $v) { $student_ids[$v['student_id']] = $v['student_id']; } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $student_data = SStudentInfo::model()->findAll($criteria); unset($criteria); if($student_data) { foreach ($student_data as $v) { $student_names[$v->student_id] = $v->realname; } } echo json_encode(array('status'=>3,'result'=>implode(',',$student_names)));exit; } } } if($this->schoolManager->addAndUpdateStudentPaper($class_id,$student_array,$exam_id,$this->semesterId,$paper_id,$student_cards,$school_student_cards)) { //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>1, 'exam_group_id'=>$exam_data->exam_group_id, 'exam_id_arr'=>array($exam_id), 'student_id_arr'=>$studentsIds ); sendStudentCacheQueue($sendJsonArr); echo json_encode(array('status'=>1));exit; }; echo json_encode(array('status'=>0));exit; } public function actionSetExamStudentCard() { $exam_id = Req::post('exam_id'); $school_card_status = Req::post('school_card_status'); $school_card_length = 8; if($this->schoolId>999){ $school_card_length = 9; } $exam_ids = array(); if(!$exam_id) { echo json_encode(array('status'=>0));exit; } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data) { $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId)); if($class_data) { $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade)); } $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($group_exam_data && $grade_data) { foreach($group_exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($school_card_status==1) { $school_card_length = $grade_data->card_length; } $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); if(false!==Exam::model()->updateAll(array('school_card_status'=>$school_card_status,'school_card_length'=>$school_card_length),$criteria)) { echo json_encode(array('status'=>1));exit; } } } echo json_encode(array('status'=>0));exit; } public function actionDelexam() { $exam_id = Req::post('examId'); $class_id = Req::post('classId'); $is_third = Req::post('is_third'); $student_ids = array(); $exam_id_array = array(); if(!$exam_id || !$class_id) { echo json_encode(array('status'=>0));exit; } if($is_third){ $exam_data = $this->schoolManager->ExamStatusAndUploadStatusArr($exam_id, array(2,3),0); }else { $exam_data = $this->schoolManager->ExamStatusAndUploadStatus($exam_id, 3, 0); } if($exam_data) { $examGroupId = $exam_data['exam_group_id']; $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId); if($examIds) { $exams_data = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = 2")); if($exams_data){ foreach($exams_data as $v) { $exam_id_array[$v['exam_id']] = $v['exam_id']; } } $all_num = count($examIds); $finish_num = count($exams_data); if(($all_num-$finish_num) == 1 && !isset($exam_id_array[$exam_id])) { SExamGroup::model()->updateAll(array('upload_status'=>2,'mark_status'=>2),'exam_group_id = :examGroupId', array( ':examGroupId' => $examGroupId )); } } $transaction = $this->sConn->beginTransaction(); try{ Exam::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)) ; $paper_list = $this->sConn->createCommand("select paper_id from paper where exam_id='" . $exam_id . "'")->queryAll(); foreach ($paper_list as $paper){ SPaperTopicRelation::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id'])); SPaperTopicLarge::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id'])); STopicUse::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id'])); } SPaper::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)); $studentIds=array(); $student_paper_relation_list = SStudentPaperRelation::model()->findAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)); $studentIds=array(); foreach ($student_paper_relation_list as $student_paper_relation){ $studentIds[]=$student_paper_relation->student_id; } SStudentPaperRelation::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)); SStudentPaperRelationProperty::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)); SClassExamPrinter::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)); SMarkingGroupModel::model()->deleteAll('class_id=:class_id and exam_group_id=:exam_group_id',array(':class_id'=>$class_id,'exam_group_id'=>$examGroupId)); //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>4, 'exam_group_id'=>$examGroupId, 'exam_id_arr'=>array($exam_id), 'student_id_arr'=>$studentIds ); sendStudentCacheQueue($sendJsonArr); $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); echo json_encode(array('status'=>0));exit; } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_data['exam_group_id'], "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '删除考试班级', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('update'=>array( 'ExamGroup'=>array('upload_status'=>1), ), array('delete'=>array( 'Exam'=>array('exam_id'=>$exam_id), 'paper'=>array('exam_id'=>$exam_id), 'student_paper_relation'=>array('exam_id'=>$exam_id), )) )), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>0));exit; } public function actionRestore() { $examName=Req::get('exam_name'); $page=intval(Req::get('page')); $pageLimit=10; if(!$page) $page=1; $examRestore=new SExamRestore(); $result=$examRestore->getList($examName,$page,$pageLimit); $viewData=array( 'pageTotal' =>$result['pageTotal'], 'dataList' =>$result['data'], 'page' =>$page, 'totalCount' =>$result['totalCount'], 'examName' =>$examName ); $this->render('restore',$viewData); } public function actionRestoreExam() { $exam_group_id = Req::post('examId'); $exam_ids = array(); $paper_ids = array(); $result=array(); $result['status']=0; if($exam_group_id>0) { $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_data) { foreach($exam_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); unset($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } } } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data) { $examStatus=3; if($exam_group_data->is_third==1){ $examStatus=2; } if($exam_group_data->mark_type>0) { $transaction = $this->sConn->beginTransaction(); try{ $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $flags=SStudentPaperRelation::model()->updateAll(array( 'complete_count'=>0, 'right_count'=>0, 'partial_right_count'=>0, 'wrong_count'=>0, 'scoring'=>0.0, 'lost_score'=>0.0, 'compare'=>0.0000, 'report_created'=>0, 'report_data'=>'', 'is_feedback'=>0, 'feedback_time'=>0, 'is_scoring'=>0, 'scoring_img'=>'', 'is_isp_html'=>0, 'isp_html_path'=>'', 'isp_html_time'=>0, 'is_wrongbook_html'=>0, 'wrongbook_html_path'=>'', 'wrongbook_html_time'=>0, 'is_isp_pdf'=>0, 'isp_pdf_path'=>'', 'isp_pdf_time'=>0, 'is_wrongbook_pdf'=>0, 'wrongbook_pdf_path'=>'', 'wrongbook_pdf_time'=>0, 'file_src'=>'', 'is_wbisp_html'=>0, 'is_wbisp_pdf'=>0, 'wbisp_html_path'=>'', 'wbisp_pdf_path'=>'', 'wbisp_html_time'=>0, 'wbisp_pdf_time'=>0, 'is_studytrend_img'=>0, 'studytrend_img_path'=>'', 'is_complete'=>0, 'complete_time'=>0, 'is_plan_created'=>0, 'plan_id'=>NULL, 'plan_topic_time'=>0, 'studytrend_exam_name'=>'', 'wb_page_num'=>0, 'isp_page_num'=>0, 'is_assigned'=>0, 'is_three_isp_download'=>0, 'is_two_isp_download'=>0, 'is_wrongbook_download'=>0, 'studytrend_img_time'=>0, 'download_three_isp_time'=>0, 'download_two_isp_time'=>0, 'download_wrongbook_time'=>0, 'is_wrong_plan_created'=>0, 'wrong_plan_topic_time'=>0, 'wrong_plan_id'=>null, 'wbisp_page_num'=>0 ),$criteria); unset($criteria); //del paper_topic_rs $criteria = new CDbCriteria(); $criteria->addInCondition('paper_id',$paper_ids); SStudentPaperTopicRs::model()->deleteAll($criteria); unset($criteria); //del marking if($exam_group_data->mark_type!=4) { SMarkingGroupModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id)); SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //update exam $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); Exam::model()->updateAll(array( 'status'=>$examStatus, 'upload_status'=>0, 'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0, ),$criteria); unset($criteria); //update exam_group ExamGroup::model()->updateAll(array( 'mark_status'=>0, 'upload_status'=>0, 'init_time'=>0, 'status'=>1, 'score_bar'=>'', 'is_marking_stop'=>0, ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); }else { SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); // SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id)); SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //update exam $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); Exam::model()->updateAll(array( 'status'=>$examStatus, 'upload_status'=>0, 'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0, ),$criteria); unset($criteria); //update exam_group ExamGroup::model()->updateAll(array( 'mark_status'=>1, 'upload_status'=>0, 'score_bar'=>'', 'status'=>1, 'is_marking_stop'=>0, ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); } $this->sConn->createCommand("delete from exam_product_status where exam_id in(".implode(',',$exam_ids).")")->execute(); $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute(); $rs = http('/qxk/marking/exam/reset/'.$exam_group_id,'PUT',$this->schoolId,array(),'cgi'); $rs=json_decode($rs,true); if(isset($rs['errCode']) && $rs['errCode']=='00'){ sendDataToKafka('zsyte-marking-reback-exam',array('examGroupId'=>$exam_group_id,'schoolId'=>$this->schoolId)); $transaction->commit(); }else{ throw new Exception($rs['errMsg']); } }catch(Exception $e){ $transaction->rollBack(); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原考试失败', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "error"=>$e->getMessage(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $result['msg']="还原失败"; exit(json_encode($result)); } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原考试', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $result['status']=1; $result['msg']="还原成功"; exit(json_encode($result)); }else { //线下阅卷 $transaction = $this->sConn->beginTransaction(); try{ $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $flags=SStudentPaperRelation::model()->updateAll(array( 'complete_count'=>0, 'right_count'=>0, 'partial_right_count'=>0, 'wrong_count'=>0, 'scoring'=>0.0, 'lost_score'=>0.0, 'compare'=>0.0000, 'report_created'=>0, 'report_data'=>'', 'is_feedback'=>0, 'feedback_time'=>0, 'is_scoring'=>0, 'scoring_img'=>'', 'is_isp_html'=>0, 'isp_html_path'=>'', 'isp_html_time'=>0, 'is_wrongbook_html'=>0, 'wrongbook_html_path'=>'', 'wrongbook_html_time'=>0, 'is_isp_pdf'=>0, 'isp_pdf_path'=>'', 'isp_pdf_time'=>0, 'is_wrongbook_pdf'=>0, 'wrongbook_pdf_path'=>'', 'wrongbook_pdf_time'=>0, 'file_src'=>'', 'is_wbisp_html'=>0, 'is_wbisp_pdf'=>0, 'wbisp_html_path'=>'', 'wbisp_pdf_path'=>'', 'wbisp_html_time'=>0, 'wbisp_pdf_time'=>0, 'is_studytrend_img'=>0, 'studytrend_img_path'=>'', 'is_complete'=>0, 'complete_time'=>0, 'is_plan_created'=>0, 'plan_id'=>NULL, 'plan_topic_time'=>0, 'studytrend_exam_name'=>'', 'wb_page_num'=>0, 'isp_page_num'=>0, 'wbisp_page_num'=>0 ),$criteria); unset($criteria); //del paper_topic_rs $criteria = new CDbCriteria(); $criteria->addInCondition('paper_id',$paper_ids); SStudentPaperTopicRs::model()->deleteAll($criteria); unset($criteria); //update exam $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); Exam::model()->updateAll(array( 'status'=>$examStatus, 'upload_status'=>0, 'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0, ),$criteria); unset($criteria); //update exam_group ExamGroup::model()->updateAll(array( 'mark_status'=>0, 'upload_status'=>0, 'init_time'=>0, 'score_bar'=>'', 'status'=>1 ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute(); $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); $result['msg']="还原失败"; //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原考试失败', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "error"=>$e->getMessage(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } exit(json_encode($result)); } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原考试', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } $result['status']=1; $result['msg']="还原成功"; exit(json_encode($result)); } } } } $result['msg']="考试参数异常"; exit(json_encode($result)); } public function actionSetSubjectId() { $subjectId = Req::post("subjectId"); if($subjectId) { Yii::app()->session['session_subject_id'] = $subjectId; Yii::app()->session['session_duoxueke_subject_id'] = $subjectId; // $this->subjectId = $subjectId; echo 1;exit; }else { echo 0;exit; } } public function actionSend_ruanyun_pdf() { $exam_id = Req::post('examId'); $paper_id = ''; $student_ids = array(); $class_id = ''; $data = array(); $topic_ids = array(); $topic_score = array(); $topic_QuestionId = array(); if($exam_id) { $student_paper_relations = SStudentPaperRelation::model()->findAll('exam_id=:exam_id and is_del=:is_del',array(':exam_id'=>$exam_id,':is_del'=>0)); if($student_paper_relations) { foreach($student_paper_relations as $v) { $paper_id = $v->paper_id; $student_ids[$v->student_id] = $v->student_id; $class_id = $v->class_id; } } $school_data = BusinessSchool::model()->find('school_id = :school_id',array(':school_id'=> $this->schoolId)); if($school_data) { $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id)); if($class_data) { $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); $students = SStudentInfo::model()->findAll($criteria); if($students) { foreach($students as $k=>$v) { $data['Students'][$k]['StudentNo'] = $v->student_id; $data['Students'][$k]['StudentName'] = $v->realname; $data['Students'][$k]['SchoolName'] = $school_data->school_name; $data['Students'][$k]['GradeName'] = ""; $data['Students'][$k]['ClassName'] = $class_data->class_name; if($class_data->grade==1) { $data['Students'][$k]['GradeName'] = "高一"; } if($class_data->grade==2) { $data['Students'][$k]['GradeName'] = "高二"; } if($class_data->grade==3) { $data['Students'][$k]['GradeName'] = "高三"; } $data['Students'][$k]['ExternalInfo'] = json_encode(array('exam_id'=>$exam_id,'school_id'=>$this->schoolId)); } } } } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data) { $data['StudentExam']['ExamName'] = $exam_data->name; $data['StudentExam']['ExamTypeId'] = 4; $data['StudentExam']['CourseId'] = $exam_data->subject_id; $data['StudentExam']['RegionId'] = 0; } $paper_topic_relation = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if($paper_topic_relation) { foreach($paper_topic_relation as $v) { $topic_ids[$v->topic_id] = $v->topic_id; $topic_score[$v->topic_id] = $v->score; } unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('topic_id',$topic_ids); $question_ids = SRuanyunTopicRelation::model()->findAll($criteria); if($question_ids) { foreach($question_ids as $k=>$v) { $topic_QuestionId[$v->topic_id] = $v->question_id; $data['ExamQuestions'][$k]['QuestionId'] = $v->question_id; $data['ExamQuestions'][$k]['FullScore'] = (double)0; if(isset($topic_score[$v->topic_id])) { $data['ExamQuestions'][$k]['FullScore'] = (double)$topic_score[$v->topic_id]; } } } unset($criteria); $criteria = new CDbCriteria(); $criteria->addCondition('paper_id=:paper_id'); $criteria->addInCondition('student_id',$student_ids); $criteria->params[':paper_id'] = $paper_id; $student_paper_rs = SStudentPaperTopicRs::model()->findAll($criteria); if($student_paper_rs) { foreach($student_paper_rs as $k=>$v) { $data['ExamResults'][$k]['StudentNo'] = $v->student_id; $data['ExamResults'][$k]['QuestionId'] = 0; if(isset($topic_QuestionId[$v->topic_id])) { $data['ExamResults'][$k]['QuestionId'] = $topic_QuestionId[$v->topic_id]; } $data['ExamResults'][$k]['Score'] = (double)$v->scoring; } //调接口 $upload_log = new BusinessUploadLog(); $upload_log->school_id = $this->schoolId; $upload_log->file_zip_path = Yii::app()->params['ruanyun_exam_interface']; $upload_log->message = json_encode($data); $upload_log->create_time = time(); $upload_log->save(); $RequestResult = Curl::http_post_gzip_json(Yii::app()->params['ruanyun_exam_interface'],json_encode($data)); $upload_log = new BusinessUploadLog(); $upload_log->school_id = $this->schoolId; $upload_log->file_zip_path ='result'; $upload_log->message = $RequestResult; $upload_log->create_time = time(); $upload_log->save(); if($RequestResult) { $RequestResult_data = json_decode($RequestResult,1); if(isset($RequestResult_data['ResultTypeId']) && $RequestResult_data['ResultTypeId']==1) { echo json_encode(array('status'=>1));exit; }else { echo json_encode(array('status'=>0));exit; } }else { echo json_encode(array('status'=>0));exit; } }else { echo json_encode(array('status'=>2));exit; } } } echo json_encode(array('status'=>0));exit; } public function actionDo_ruanyun_pdf() { $condition = array(); $printList = array(); $condition[] = "cep.type = 0"; $condition[] = "e.is_display = '0'"; $condition[] = "eg.is_third = '0'"; $condition[] = "e.subject_id = '{$this->subjectId}'"; $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc','e.exam_id desc')); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k] = $v; if ($v["type"] == 1) { $printList[$k]['print_name']= $v["exam_name"].'"错题本"'; } elseif ($v["type"] == 2) { $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"'; } elseif ($v["type"] == 3) { $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"'; } else { $printList[$k]['print_name']= $v["exam_name"]; } $printList[$k]['is_tpl'] = 0; // 需要上传模板 $printList[$k]['answer_card_uploaded'] = false; if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $printList[$k]['is_custom_tpl'] = true; $v['is_custom_tpl'] = true; }else{ //非自定义模板 $printList[$k]['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $printList[$k]['is_tpl'] = 1; if(trim($printList[$k]['answer_card_src'])){ $printList[$k]['answer_card_uploaded'] = true; } //题卡分离 $printList[$k]['paper_tpl_type'] = 2; }else{ $printList[$k]['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $printList[$k]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList[$k]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $printList[$k]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList[$k]['paper_tpl_type'] = 4; } } //题卡合一 } } $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId); $data = array(); $data['printList'] = $printList; $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data["subject"] = $subject_exam_data; unset($resultList); $this->render('do_ruanyun_pdf',$data); } public function actionRuanyun_change() { $sname = Req::get("sname"); $cid = Req::get("cid"); $eid = Req::get("eid"); $studentNames = array(); $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $examInfo = Exam::model()->findByPk($eid); if (empty($examInfo)) { Yii::app()->jump->error('未找到周周练!'); } $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid',array(':cid'=>$cid,':eid'=>$eid)); if (empty($getResult)) { Yii::app()->jump->error('未找到班级与试卷对应关系!'); } $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid)); if (empty($paperInfo)) { Yii::app()->jump->error('未找到试卷信息!'); } //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid)); if (empty($relateStudent)) { Yii::app()->jump->error('未找到考试学生信息!'); } else { $studentIdArray = array(); $wrongStatus = array(); $studentArrayTwo = array(); $studentScoring = array(); $_wrongStudentIds = array(); $student_name = array(); // 获取当前考试所有学生ID foreach ($relateStudent as $key=>$val) { $studentIdArray[] = $val->student_id; $wrongStatus[$val->student_id] = $val->is_wbisp_pdf; $wrongStudentIds[$val->student_id] = $val->student_id; $_wrongStudentIds[$val->student_id] = $val->student_id; $studentScoring[$val->student_id] = $val->scoring; } $wrongStudents = $wrongTopicIds = $wrongAnswers =array(); // 获取学生的错题 } $result = array(); if (!empty($wrongStudentIds)) { // 获取有错题的学生姓名 $studentNames = SStudentInfo::model()->getStudentNames($wrongStudentIds); } $data = array(); $data['exam_id'] = $eid; $data['examName'] = $examInfo["name"]; $data['class_id'] = $cid; $data['sname'] = $sname; $data['examInfo'] = $examInfo; $data['student_names'] = $studentNames; $data['result'] = $relateStudent; $this->render('ruanyun_change',$data); } public function actionUpdatepaperdowntime() { $student_id = Req::post('student_id'); $exam_id = Req::post('exam_id'); if($student_id && $exam_id) { $student_paper_relation = SStudentPaperRelation::model()->find('student_id = :student_id and exam_id=:exam_id and is_isp_pdf=:is_isp_pdf',array(':student_id'=>$student_id,':exam_id'=>$exam_id,':is_isp_pdf'=>1)); if($student_paper_relation) { SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),'student_id= :student_id and exam_id=:exam_id',array(':student_id'=>$student_id,':exam_id'=>$exam_id)); } } } public function actionStudent_product() { //当前学期所有班级 $grade = Req::get('grade'); $class_id = Req::get('class_id'); $ptype = Req::get('ptype'); //类型,期中,期末,总复习 $season = Req::get('season'); //季节 $class_name = ''; $pageLimit=4; if($season){ $pageLimit=$pageLimit*2; } if($ptype){ $pageLimit=$pageLimit*3; } $criteria = new CDbCriteria(); if($class_id) { $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $class_id; } $criteria->addCondition('semester_id=:semester_id'); $criteria->params[':semester_id'] = $this->semesterId; if($grade) { $criteria->addCondition('grade=:grade'); $criteria->params[':grade'] = $grade; } $criteria->order = 'grade asc,class_id asc'; $count = ClassModel::model()->count($criteria); $pager = new CPagination($count,$pageLimit); $criteria->limit=$pager->getLimit(); $criteria->offset=$pager->getOffset(); $class_data = ClassModel::model()->findAll($criteria); if(!$class_data) { Yii::app()->jump->error('未找到班级!'); } $data = array(); $class_names = array(); $class_ids = array(); $class_student_ids = array(); $class_down = array(); $class_create = array(); foreach($class_data as $v) { if($v->class_id == $class_id) { $class_name = $v->class_name; } $class_names[$v->class_id] = $v->class_name; $class_ids[$v->class_id] = $v->class_id; } unset($criteria); $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$class_ids); $criteria->addCondition('status=:status'); $criteria->params[':status'] = 0; $student_data = SStudentClassRelation::model()->findAll($criteria); if($student_data) { foreach($student_data as $v) { $class_student_ids[$v->class_id][$v->student_id] = $v->student_id; } } //debug($class_data); /*** 优化后 *****/ $_class_ids = array(); if($class_student_ids){ $_class_ids = array_keys($class_student_ids); } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } list($student_product_data,$student_down_product_data,$class_bt) = $this->schoolManager->getStudentProduct($_class_ids,$subjectId); /*** 优化后 *****/ /*** 优化前 *****/ // $student_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_pdf_created = 1')); // $student_down_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_download = 1')); /*** 优化前 *****/ if($student_down_product_data) { foreach($student_down_product_data as $v) { $class_down[$v['class_id']][$v['product_type']] = $v; } } if($student_product_data) { foreach($student_product_data as $v) { $class_create[$v['class_id']][$v['product_type']] = $v; } } unset($criteria); $criteria = new CDbCriteria(); if($grade) { $criteria->addCondition('grade=:grade'); $criteria->params[':grade'] = $grade; } $criteria->addCondition('semester_id=:semester_id'); $criteria->params[':semester_id'] = $this->semesterId; $class_all = ClassModel::model()->findAll($criteria); //阶段个性化学习宝生成状态 //category 1--春季期中个性化学习宝(2.1~4.30) 2--春季期末个性化学习宝(5.1~7.31) 3--春季总复习个性化学习宝(2.1~7.31) 4--秋季期中个性化学习宝(9.1~11.30) 5--秋季期末个性化学习宝(12.1~1.31) 6--秋季总复习个性化学习宝(9.1~1.31) $review_isp = array( array( 'product_name' => '期中复习学习宝', 'season_arr'=>array( array( 'category_id' => 1, 'is_send' => 0, 'status' => 0, 'category_name' => '春季(根据2-4月的考试数据生成)', ), array( 'category_id' => 4, 'is_send' => 0, 'status' => 0, 'category_name' => '秋季(根据9-11月的考试数据生成)', ), ), ), array( 'product_name' => '期末复习学习宝', 'season_arr'=>array( array( 'category_id' => 2, 'is_send' => 0, 'status' => 0, 'category_name' => '春季(根据5-7月的考试数据生成)', ), array( 'category_id' => 5, 'is_send' => 0, 'status' => 0, 'category_name' => '秋季(根据12-1月的考试数据生成)', ), ), ), array( 'product_name' => '总复习学习宝', 'season_arr'=>array( array( 'category_id' => 3, 'is_send' => 0, 'status' => 0, 'category_name' => '春季(根据2-7月的考试数据生成)', ), array( 'category_id' => 6, 'is_send' => 0, 'status' => 0, 'category_name' => '秋季(根据9-1月的考试数据生成)', ), ), ), ); $review_info = SReviewPaperProductSet::model()->findAll( array( 'select'=>'category,status,reset_time', 'condition'=>'semester_id = :semester_id and subject_id=:subject', 'params'=>array(':semester_id'=>$this->semesterId,':subject'=>$subjectId), ) ); $review_status = array(); $reset_time = array(); $cate3_rel_cate6 = array(); foreach ($review_info as $info) { $review_status[$info->category] = $info->status; $reset_time[$info->category] = $info->reset_time; $cate3_rel_cate6[$info->category] = $info->category; } unset($review_info); foreach ($review_isp as $key => $review){ foreach ($review['season_arr'] as $k => $cate){ if(isset($review_status[$cate['category_id']])){ $review_isp[$key]['season_arr'][$k]['status'] = (int)$review_status[$cate['category_id']]; $review_isp[$key]['season_arr'][$k]['reset_time'] = $reset_time[$cate['category_id']]; //重置时间 } } } $data['pages'] = $pager; $data['pape_count'] = $count; $data['class_data'] = $class_data; $data['semester_name'] = $this->semesterDetail['semester_name']; $data['class_student'] = $class_student_ids; $data['class_down'] = $class_down; $data['class_create'] = $class_create; $data['grade'] = $grade; $data['class_name'] = $class_name; $data['class_id'] = $class_id; $data['class_all'] = $class_all; $data['review_isp'] = $review_isp; $data['semester_id'] = $this->semesterId; $data['subjectId'] = $this->subjectId; $data['cate3_rel_cate6'] = $cate3_rel_cate6; $data['ptype'] = $ptype; $data['season'] = $season; $data['class_bt'] = $class_bt; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } $this->render('sheet',$data); } public function actionClass_student_product() { Url::clean(); $cid = Req::get("cid"); $type = Req::get("type"); $student_name = Req::get("student_name"); $data = array(); $student_ids = array(); $student_products = array(); if(!$cid) { Yii::app()->jump->error('未找到班级!'); } $classInfo = ClassModel::model()->findByPk($cid); if (empty($classInfo)) { Yii::app()->jump->error('未找到班级!'); } $class_student_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$cid,':status'=>0)); if($class_student_data) { foreach($class_student_data as $v) { $student_ids[$v->student_id] = $v->student_id; } } $criteria = new CDbCriteria(); $criteria->addInCondition('student_id',$student_ids); if($student_name) { $criteria->addSearchCondition('realname',$student_name); } $count = SStudentInfo::model()->count($criteria); $pager = new CPagination($count,10); $criteria->limit=$pager->getLimit(); $criteria->offset=$pager->getOffset(); $student_data = SStudentInfo::model()->findAll($criteria); $student_ids1=array(); foreach($student_data as $v){ $student_ids1[] = (string)$v->student_id; } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } $stuids = array(); if($student_ids1){ if (Yii::app()->params["limit_open"]) { $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$cid)); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$cid, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>time(), "classify"=>1, "subject"=>$subjectId, ); $stuids=$this->getManyProductOrder($intarr,array(1,2,3),$student_ids1); }else { $stuids = $student_ids1; } } foreach($student_data as $k=>$v){ if($this->inArray($v->student_id,$stuids)){ // if(in_array((string)$v->student_id,$stuids)){ $v->is_outer=1; }else{ $v->is_outer=0; } $student_data[$k]=$v; } unset($criteria); $student_product_data=SStudentProductModel::model()->getStudentCreate($student_ids,$subjectId,$type,$this->semesterId); if($student_product_data) { foreach($student_product_data as $v) { $student_products[$v['student_id']] = $v; } } $data['page_count'] = $count; $data['class_id'] = $cid; $data['class_name'] = $classInfo->class_name; $data['pages'] = $pager; $data['student'] = $student_data; $data['type'] = $type; $data['student_products'] = $student_products; $data['semester_name'] = $this->semesterDetail['semester_name']; $data['student_name'] = $student_name; if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) { $data["use_zhixue"] = $this->schoolInfo->use_zhixue; }else { $data["use_zhixue"] = 0; } $this->render('sheet_chang',$data); } /** * in_array() php 5.3 有问题重新写 * @param type $value * @param type $arr * @return boolean */ public function inArray($value,$arr){ if($arr){ foreach($arr as $v){ if((string)$value === (string)$v){ return true; } } } return false; } public function actionDownload_student_product(){ $classId = Req::get("classId"); $type = Req::get("type"); $studentsIds = Req::get("studentsIds"); if( !$classId || !$type){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!in_array($type, array(1, 2, 3))){ echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; // if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "classId" => $classId, "type" => $type, ); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$classId,':status'=>0)); if($student_class_data) { if(!$studentsIds) { $studentsIds=array(); foreach($student_class_data as $v) { // $params['studentIds'][] = $v->student_id; $studentsIds[]=$v->student_id; } } }else{ echo json_encode(array("success" => 0, "message" => "班级暂无学生"));exit; } if($studentsIds) { ; if(!is_array($studentsIds)){ $studentsIds=explode(',',$studentsIds); } // $student_ids1=""; // foreach($studentsIds as $v){ // $student_ids1.="'".$v."',"; // } // $student_ids1=substr($student_ids1,0,strlen($student_ids1)-1); // $stu_order=array(); // if($student_ids1){ // $today=date("Y-m-d H:i:s"); // $semester=new SSemester(); // $nowsem=$semester->getCurrentSemester(); // $sql="SELECT // student_id, // student_name, // group_concat(trial_begin_time) AS trial_begin_time, // group_concat(trial_end_time) AS trial_end_time, // group_concat(type_id) AS type_id, // group_concat(classify) AS classify, // group_concat(`code`) AS `code` // FROM // ( // SELECT // o.id, // IFNULL(o.trial_begin_time, '') AS trial_begin_time, // IFNULL(o.trial_end_time,'') as trial_end_time, // g.type_id, // g.classify, // IFNULL(gt.`code`,0) as `code`, // os.student_name, // os.student_id // FROM // `order` AS o // JOIN order_goods AS og ON og.order_id = o.id // JOIN goods AS g ON g.id = og.goods_id // left JOIN goods_term AS gt ON g.id = gt.goods_id // left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id // JOIN order_student AS os ON os.order_id = o.id // WHERE // os.student_id in ($student_ids1) // and (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}') // and o.status=1 // AND o.school_id ={$this->schoolId} // AND os.chargeback = 0 // and o.id not in (select business_key from zsy_service where status=1) // ORDER BY // g.type_id // // ) t // GROUP BY // student_name "; // $stu_order=Yii::app()->db251->createCommand($sql)->queryAll(); // // } // $limit=array(); // if($stu_order){ // // foreach($stu_order as $v){ // $limit[$v['student_id']]=$v; // } // // } // $stuids=$studentsIds; // foreach($stuids as $k=>$v){ // if(!isset($limit[$v])){ // unset($stuids[$k]); // } // } $stuids = array(); if (Yii::app()->params["limit_open"]) { $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId)); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$classId, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>time(), "classify"=>1, "subject"=>3, ); $this->getStuOrder($studentsIds,$intarr,$stuids); }else { $stuids = $studentsIds; } if(!$stuids){ echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限"));exit; } $params['studentIds'] = $stuids; $criteria = new CDbCriteria(); $_students = array(); if($params["studentIds"]) { $_students = $params["studentIds"]; } $criteria->addInCondition('student_id',$_students); $criteria->addCondition('type=:type'); $criteria->params[':type'] = $type; $_student_product_data = SStudentProductModel::model()->findAll($criteria); if(!$_student_product_data) { echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF"));exit; } } $rs = Curl::post($apiUrl."/rest/download_sp/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); echo json_encode($rs);exit; } if($rs->success!=0){ $rs->success=2; $rs->limitinfo='全班允许下载'; } if($params["studentIds"] && ($rs->success==1 || $rs->success==2) ) { $criteria = new CDbCriteria(); $_students = array(); if($params["studentIds"]) { $_students = $params["studentIds"]; } $criteria->addInCondition('student_id',$_students); $criteria->addCondition('type=:type'); $criteria->params[':type'] = $type; SStudentProductModel::model()->updateAll(array('is_download'=>1,'download_time'=>time()),$criteria); } echo json_encode($rs);exit; } /** * 获取学生是否有订单 * @param $studentsIds * @param $intarr * @param $stuids */ protected function getStuOrder($studentsIds,$intarr,&$stuids){ foreach(array(1,2,3) as $type){ $intarr['classify'] = $type; $intarr['students'] = array_diff($studentsIds,$stuids); if(!$intarr['students']){ break; }else{ $intarr['students'] = array_values($intarr['students']); } $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs) { Yii::app()->jump->error("接口错误"); } if (!empty($rs->data)) { $stuids = array_merge($stuids,$rs->data); } } } /** * 打包下载 */ public function actionPrint_pack() { $exam_id = Req::post("exam_id"); $student_id = Req::post("student_id"); if(!$exam_id ) { echo json_encode(array("status"=>0,"result"=>"参数不能为空")); } $student_ids = array(); if(!$student_id) { $student_paper_data = SStudentPaperRelation::model()->findAll("exam_id=:exam_id and is_del=:is_del ",array(":exam_id"=>$exam_id,':is_del'=>0)); if($student_paper_data) { foreach ($student_paper_data as $v) { $student_ids[] = $v->student_id; } } }else { $studentIds = explode(',',$student_id); foreach ($studentIds as $v) { if($v) { $student_ids[] = $v; } } } $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/download/fixedtemplate/qrinfo/'.$this->schoolId; $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => '', "operate_project" => 'zsyas2', "title" => '打包打印', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $url, "operate_sql" => '', "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids),'rs'=>$rs)), "date"=>date('Y-m-d H:i:j') ))); } if(isset($rs->errCode) && $rs->errCode =='00') { ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id)); echo json_encode(array('status'=>1,'result'=>$rs->data));exit; } $errMsg = '下载失败'; if(isset($rs->errMsg)) { $errMsg = $rs->errMsg; } echo json_encode(array('status'=>0,'result'=>$errMsg));exit; } public function CrmApiPost($url, $arr, $username,$password,$type='POST',$header=array()) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $headerArr=array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), 'Connection: false', 'Expect:' ); if($header){ $headerArr=array_merge($headerArr,$header); } if($type=='POST'){ // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT,120); curl_setopt($ch, CURLOPT_NOSIGNAL,1); curl_setopt($ch, CURLOPT_TIMEOUT_MS,120000); // 请求重启路由器的地址 传参 进行重启 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, $headerArr); if( !curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); }elseif($type=='PUT'){ $data = json_encode($arr); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); $result = json_decode(curl_exec($ch)); curl_close($ch); } } return $result; } //获取考试的班级 public function actionGetExamClass(){ $examGroupId = Req::get("examGroupId"); $printType = (string)Req::get("printType"); $productType = (string)Req::get("productType"); $subjectId = (int)Req::get("subjectId"); $resultList =$resetLogs= array(); $resetTotal=3;//学管重置总次数 if(is_numeric($examGroupId) && $examGroupId > 0){ $condition[] = " e.exam_group_id = ".$examGroupId; if ($printType == 'third_isp' || $subjectId == 8) { $condition[] = "e.subject_id = 8"; }elseif ($printType == 'third_wb') { $condition[] = "e.subject_id = '{$subjectId}'"; }elseif (in_array($this->subjectId,$this->mathSubjectId)) { $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; } else { $condition[] = "e.subject_id = '{$this->subjectId}'"; } switch ($printType) { case "wp": $printTypeData = 0; break; case "wtb": $printTypeData = 1; break; case "isp": $printTypeData = 2; break; case "studytrend": $printTypeData = 3; break; case "section": $printTypeData = 4; break; case "third_wb": $printTypeData = 1; break; case "third_isp": $printTypeData = 3; break; case "exam_product": $printTypeData = $productType; break; default: $printTypeData = null; break; } if(!Str::isBlank($printTypeData)){ $condition[] = "cep.type = '{$printTypeData}'"; } if ($printType == 'wp') { $condition[] = "eg.is_third = 0"; $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc')); }elseif($printType == 'exam_product'){ //FIXME 新考试类型产品(如初高中方法宝) $examProduct = new SExamProductStatus(); $rs = $examProduct->getProductList($condition,array('e.create_time desc'), $productType,100); $resultList = isset($rs['rs']) ? $rs['rs'] : array(); } else { $resultList = $this->schoolManager->getDownloadClassIpf($condition,array('e.complete_time desc')); } $resetLogs=$this->sConn->createCommand("select exam_group_id,exam_id,class_id,learn_tube_reset_count,learn_tube_reset_time,reset_count from product_reset_log where exam_group_id ='{$examGroupId}' and product_type='".$printTypeData."'")->queryAll(); foreach($resetLogs as $key=>$resetLogInfo){ unset($resetLogs[$key]); $resetLogs[$resetLogInfo['class_id']]=$resetLogInfo; } foreach($resultList as &$item){ $learnTubeResetCount=isset($resetLogs[$item['class_id']]['learn_tube_reset_count'])?$resetLogs[$item['class_id']]['learn_tube_reset_count']:0; $learnTubeResetTime=isset($resetLogs[$item['class_id']]['learn_tube_reset_time'])?$resetLogs[$item['class_id']]['learn_tube_reset_time']:0; $learnTubeResetResidueCount=$resetTotal>$learnTubeResetCount?$resetTotal-$learnTubeResetCount:0; $item['learn_tube_reset_count']=$learnTubeResetCount; $item['learn_tube_reset_residue_count']=$learnTubeResetResidueCount; //学管30分钟内只能重置一次 $item['is_cool_down']=time()-$learnTubeResetTime<=1800?0:1; //冷却文字提示 30分钟内并且剩余次数大于0 $item['is_cool_down_prompt']=!$item['is_cool_down'] && $learnTubeResetResidueCount?true:false; $item['reset_count']=isset($resetLogs[$item['class_id']]['reset_count'])?$resetLogs[$item['class_id']]['reset_count']:0; } } //是不是技术支持 $isTechnicalSupport=1; if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){ $isTechnicalSupport=0; } $data=array( "resultList" => $resultList, 'printType'=>$printType, 'productType'=>$productType, 'is_technical_support'=>$isTechnicalSupport, ); $this->render('reset_isp',$data); } //设置阶段个性化学习宝 public function actionSetReviewIsp(){ $res = array(); $res['status'] = 0; $res['msg'] = ''; $error = array(); $semester_id = Req::post("semester_id"); $category = (int)Req::post("category"); $_class_id = (string)Req::post("class_id"); $handle_type = (string)Req::post("handle_type"); if(!($semester_id && is_numeric($semester_id))){ $error[] = '学期参数不正确'; } if(!in_array($category,array(1,2,3,4,5,6))){ $error[] = '类型参数不正确'; } if(!$handle_type){ $error[] = '操作类型参数不正确'; } $status = 0; if($handle_type == 'generat'){ $status = 1; }else{ $status = 90; } if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } //验证时间在不在当前学期范围内 $time = time(); // if(!$error){ // $semester = Semester::model()->find( // array( // 'select'=>'start_time,end_time', // 'condition'=>'status = 1', // ) // ); // // if($semester){ // if (!($time >= $semester->start_time && $time <= $semester->end_time)) { // $error[] = '时间不在当前学期范围内'; // } // }else{ // $error[] = '学期数据不正确'; // } // } $gradeArr=array(); if(!$error){ $busTran = $this->sConn->beginTransaction(); try{ $sql = 'select class_id,grade from `class` where semester_id = '.$semester_id; if ($_class_id) { $sql .= ' and class_id = ' . $_class_id; } $class_info = $this->sConn->createCommand($sql)->queryAll(); if ($class_info) { $class_ids = array(); foreach ($class_info as $info) { $class_ids[$info['class_id']] = $info['class_id']; $gradeArr[$info['grade']]=$info['grade']; } }else{ throw new Exception('本学期没班级'); } $sql = 'select rprs_id from review_paper_product_set where semester_id = '.$semester_id.' and category = '.$category.' and subject_id='.$subjectId; $product_set_info = $this->sConn->createCommand($sql)->queryRow(); if ($product_set_info) { $sql = "update review_paper_product_set set `status` = {$status},update_time = {$time},reset_time={$time} where rprs_id = {$product_set_info['rprs_id']}"; }else{ $sql = "insert into review_paper_product_set(semester_id,category,status,update_time,create_time,subject_id) value({$semester_id},{$category},{$status},{$time},{$time},{$subjectId})"; } $bool = $this->sConn->createCommand($sql)->execute(); if ($bool === false) { throw new Exception('操作产品设置失败'); } if (isset($product_set_info['rprs_id']) && $product_set_info['rprs_id']) { $rprs_id = $product_set_info['rprs_id']; }else{ $rprs_id = $this->sConn->getLastInsertID(); } $sql = 'select rpc_id,class_id,status from `review_product_class` where rprs_id = '.$rprs_id.' and class_id in ('.implode(',',$class_ids).')'; if ($_class_id) { $sql .= ' and class_id = ' . $_class_id; } $product_class_info = $this->sConn->createCommand($sql)->queryAll(); $class_rel_rprc = array(); if ($product_class_info) { foreach ($product_class_info as $info) { $class_rel_rprc[$info['class_id']] = $info['rpc_id']; } } //创建或更新数据 $update_class_sql = array(); $insert_class_sql = array(); foreach ($class_ids as $class_id) { if (isset($class_rel_rprc[$class_id])) { $update_class_sql[] = "update review_product_class set `status` = {$status},update_time = {$time} where rpc_id = {$class_rel_rprc[$class_id]}"; }else{ $insert_class_sql[] = "({$rprs_id},{$class_id},{$status},{$time},{$time})"; } } if ($update_class_sql) { foreach ($update_class_sql as $_sql) { $bool = $this->sConn->createCommand($_sql)->execute(); if ($bool === false) { throw new Exception('操作产品班级失败'); } } } if ($insert_class_sql) { $_sql = "insert into review_product_class(rprs_id,class_id,status,update_time,create_time) values ".implode(',',$insert_class_sql); $_sql = rtrim($_sql, ','); $bool = $this->sConn->createCommand($_sql)->execute(); if ($bool === false) { throw new Exception('操作产品班级失败'); } } //更新学生生成状态 if ($status == 90) { if ($category > 3) { $_category = $category - 3; }else{ $_category = $category; } //重置后清除已存在的下载任务 $unique_key = $semester_id . '_' . $_category; $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= '{$unique_key}' and product_type=4 and subject_id='{$subjectId}'")->execute(); $rpcIds=array_values($class_rel_rprc); $sql = "update student_product set `is_html_created` = 0,is_pdf_created = 0 where semester_id = {$semester_id} and product_type = {$category} and plan_id in(".implode(',',$rpcIds).") "; if ($_class_id) { $_sql = 'select student_id from student_class_relation where class_id = '.$_class_id.' and status = 0'; $class_student = $this->sConn->createCommand($_sql)->queryAll(); $class_stu_ids = array(); if ($class_student) { foreach ($class_student as $value) { $class_stu_ids[] = $value['student_id']; } }else{ throw new Exception('班级没有对应的学生'); } $sql .= ' and student_id in ('.implode(',',$class_stu_ids).')'; } $this->sConn->createCommand($sql)->execute(); } $busTran->commit(); //发送消息{"school_id":"3955","subject_id":"3","send_type":"stage_review","msg_type":1,"grade_ids":[1],"year":2021, //"product_type":"1","class_ids":["683589263477706752"],"student_ids":[]} if($handle_type=='reset'){ $msgType=90; }else{ $msgType=1; } if ($_class_id) { $sendMsg=array( 'school_id'=>$this->schoolId, 'msg_type'=>$msgType, 'subject_id'=>$subjectId, 'send_type'=>'many_stage_review', 'grade_ids'=>array_values($gradeArr), 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'), 'product_type'=>$category, 'class_ids'=>array($_class_id) ); sendDataToKafka('php-product-many-stage-html',$sendMsg); }else{ foreach ($gradeArr as $value){ $sendMsg=array( 'school_id'=>$this->schoolId, 'msg_type'=>$msgType, 'subject_id'=>$subjectId, 'send_type'=>'many_stage_review', 'grade_ids'=>array($value), 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'), 'product_type'=>$category, ); sendDataToKafka('php-product-many-stage-html',$sendMsg); } } }catch(Exception $e){ $error[] = $e->getMessage(); $busTran->rollBack(); } } if($error){ $res['msg'] = implode(PHP_EOL,$error); echo json_encode($res); }else{ $res['status'] = 1; echo json_encode($res); } exit; } //读取班级 public function actionLoadClass(){ $grade=Req::post('grade'); $branch=Req::post('branch'); $exam_group_ids=Req::post('eid'); $result['status']=0; $examClass=array(); //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id'; $criteria->addCondition("exam_group_id='".$exam_group_ids."'"); $exam_data = Exam::model()->findAll($criteria); unset($criteria); unset($exam_group_ids); if($exam_data) { foreach($exam_data as $v) { $exam_ids[] = $v->exam_id; } unset($exam_data); //通过考试ID,获取打印班级 $criteria = new CDbCriteria(); $criteria->select = 'exam_id,class_id'; $criteria->addInCondition('exam_id',$exam_ids); $class_print_data = ClassExamPrinter::model()->findAll($criteria); if($class_print_data) { foreach($class_print_data as $v) { $examClass[]=(string)$v->class_id; } } unset($criteria); unset($class_print_data); } //判断考试是否走班考试 $class_type=1; if($examClass){ $checkClassData=ClassModel::model()->find('class_id=:classid',array(':classid'=>$examClass[0])); if($checkClassData && $checkClassData->class_type==2){ $class_type=2; } } if($branch){ $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and arts_science=:arts_science and class_type=:class_type and is_hide=0',array(':semester_id'=>$this->semesterId,":grade"=>$grade,':arts_science'=>$branch,":class_type"=>$class_type)); }else{ $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and class_type=:class_type and is_hide=0 ',array(':semester_id'=>$this->semesterId,":grade"=>$grade,":class_type"=>$class_type)); } $groupClassData=array(); foreach ($class_data as $val){ $temp=array( 'class_id'=>$val->class_id, 'class_name'=>$val->class_name, 'grade' =>$val->grade, 'arts_science'=>$val->arts_science ); if(in_array((string)$val->class_id,$examClass,true)){ $temp['is_used']=1; }else{ $temp['is_used']=0; } $groupClassData[$val->level][]=$temp; } $result['status']=1; $result['classData']=$groupClassData; exit(json_encode($result)); } //提交选择班级结果 public function actionSaveExamClass(){ $classId=Req::post('classId'); $exam_group_id=Req::post('eid'); $result['status']=0; if(!$exam_group_id || !$classId || !is_array($classId)){ $result['msg']='数据异常'; exit(json_encode($result)); } $examName=''; $examClass=array(); //原考试班级 $needDelClass=array(); //需要删除的班级 $neeAddClass=array(); //需要增加的班级 $time=time(); //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id,class_id'; $criteria->addCondition("exam_group_id='".$exam_group_id."'"); $exam_data = Exam::model()->findAll($criteria); unset($criteria); if($exam_data) { foreach($exam_data as $v) { $exam_ids[] = $v->exam_id; $examClass[] = (string)$v->class_id; } foreach ($examClass as $key => $val){ if(in_array((string)$val,$classId,true)){ unset($classId[array_search((string)$val,$classId,true)]); }else{ $needDelClass[]=$val; //需要删除 } } if($classId){ $neeAddClass= $classId; } $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length from exam where exam_id='".$exam_ids[0]."' ")->queryRow(); $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll(); $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow(); $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']); //增加班级 if($neeAddClass){ $transaction = $this->sConn->beginTransaction(); try { foreach ($neeAddClass as $classId) { $newExamId=getUniqueId($this->schoolId); $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll(); $studentIds=array(); if($studentIdData){ foreach ($studentIdData as $datum){ $studentIds[]=$datum['student_id']; } } if(!$studentIds) continue; $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds); $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0); //添加考试 $this->sConn->createCommand()->insert('exam', array( 'exam_id' => $newExamId, 'exam_group_id' => $exam_group_id, 'name' => $examDetail['name'], 'subject_id' => $examDetail['subject_id'], 'semester_id' => $examDetail['semester_id'], 'teacher_id' => $examDetail['teacher_id'], 'module_id' => $examDetail['module_id'], //'type' => $examDetail['type'], 'type' => $examDetail['type'], 'status' => 3, 'week_num' => $examDetail['week_num'], 'create_type' => $examDetail['create_type'], 'create_time' => $examDetail['create_time'], 'update_time' => $examDetail['update_time'], 'tpl_index' => $examDetail['tpl_index'], 'tpl_data' => $examDetail['tpl_data'], 'class_id' => $classId, 'method_ids' => $examDetail['method_ids'], 'from_exam_id' => $examDetail['from_exam_id'], 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0, 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0, // 'is_third' =>$examDetail['is_third'] )); //添加试卷 $newPaperId=getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => $paperDetail['paper_type'], 'exam_id' => $newExamId, 'paper_name' => "", 'paper_layer' => $paperDetail['paper_layer'], 'difficulty' => $paperDetail['difficulty'], 'topics_count' => $paperDetail['topics_count'], 'score' => $paperDetail['score'], 'add_time' => $paperDetail['add_time'], 'update_time' => $paperDetail['update_time'], 'method_ids' => $paperDetail['method_ids'], 'is_labelled' => $paperDetail['is_labelled'], 'status' => $paperDetail['status'] )); if ($studentIds_0) { foreach ($studentIds_0 as $studentId) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), )); } } foreach ($paperTopics as $paperTopic) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $newPaperId, 'topic_id' => $paperTopic['topic_id'], 'order' => $paperTopic['order'], 'mode' => (int)$paperTopic['mode'], 'type' => $paperTopic['type'], 'score' => $paperTopic['score'], 'method_ids' => $paperTopic['method_ids'], 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2, )); $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $paperTopic['topic_id'], 'mode' => $paperTopic['mode'], 'teacher_id' => $examDetail['teacher_id'], )); } $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); } $transaction->commit(); }catch (Exception $e){ $transaction->rollBack(); exit(json_encode(array('status'=>0,'msg'=>'保存失败'))); } } if($needDelClass){ $transaction = $this->sConn->beginTransaction(); try { foreach ($needDelClass as $classId){ $exam=$this->sConn->createCommand("select exam_id from exam where exam_id IN (".implode(',',$exam_ids).") and class_id='".$classId."'")->queryRow(); $paper = $this->sConn->createCommand("select paper_id from paper where exam_id ='".$exam['exam_id']."'")->queryRow(); $this->sConn->createCommand("delete from `exam` where exam_id = '{$exam['exam_id']}'")->execute(); $this->sConn->createCommand("delete from `paper` where paper_id = '{$paper['paper_id']}'")->execute(); //student_paper_relation,paper_topic_relation,class_exam_printer $this->sConn->createCommand("delete from `student_paper_relation` where paper_id = '{$paper['paper_id']}'")->execute(); $this->sConn->createCommand("delete from `paper_topic_relation` where paper_id = '{$paper['paper_id']}'")->execute(); $this->sConn->createCommand("delete from `class_exam_printer` where exam_id = '{$exam['exam_id']}'")->execute(); } $transaction->commit(); }catch (Exception $e){ $transaction->rollBack(); exit(json_encode(array('status'=>0,'msg'=>'保存失败'))); } } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '添加考试班级', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } exit(json_encode(array('status'=>1,'msg'=>'设置成功'))); }else{ $result['msg']='考试数据异常'; exit(json_encode($result)); } } public function UUID_SHORT($length = 20) { $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read(); $result = $query['UUID_SHORT']; if ($length AND is_int($length)) { $result = substr($result, ($length * -1)); } return $result; } //删除全部未考试学生 public function actionDelExamStudentAll() { $exam_group_id = Req::post('exam_group_id'); $studentsIds = array(); if(!$exam_group_id) { echo json_encode(array('status'=>0));exit; } //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id,class_id'; $criteria->addCondition("exam_group_id='".$exam_group_id."'"); $exam_data = Exam::model()->findAll($criteria); unset($criteria); if($exam_data) { foreach ($exam_data as $v) { $exam_ids[] = $v->exam_id; } } foreach ($exam_ids as $exam_id){ $examStudentsIds=array(); $student_data =$this->schoolManager->getStudentPaperByExamIds($exam_ids); if($student_data) { foreach($student_data as $v) { $examStudentsIds[$v['student_id']] = $v['student_id']; } $sendJsonArr[]=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>2, 'exam_group_id'=>$exam_group_id, 'exam_id_arr'=>array($exam_id), 'student_id_arr'=>$examStudentsIds ); $studentsIds=array_merge($studentsIds,$examStudentsIds); } } if(!$studentsIds){ echo json_encode(array('status'=>2));exit; } if($this->schoolManager->delStudentPaperPropertyByExamIds($exam_ids,$studentsIds)) { //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" =>$exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '清空本次考试的学生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('delete'=>array( 'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } //发送学生端消息 foreach ($sendJsonArr as $arr){ sendStudentCacheQueue($arr); } echo json_encode(array('status'=>1));exit; } echo json_encode(array('status'=>0));exit; } //切换扫描方式 public function actionChangeScan(){ $data=array(); $data['version_number'] =$this->version_number; $this->render('change_scan',$data); } //加载考试信息 public function actionLoadExamInfo(){ $exam_group_id=Req::post('exam_group_id'); $result['status']=0; if(!$exam_group_id){ exit(json_encode($result)); } $examGroup=$this->sConn->createCommand("select teacher_id,mark_type,qxk_paper_id from exam_group where exam_group_id='".$exam_group_id."'")->queryRow(); if(!$examGroup){ $result['msg']='考试信息不正确'; exit(json_encode($result)); } $sql="SELECT e.exam_id,e.name,e.tpl_data,c.class_name,e.type FROM `exam` e join class c on e.class_id= c.class_id where e.exam_group_id='".$exam_group_id."'"; $examClass=$this->sConn->createCommand($sql)->queryAll(); $data=array(); $data['class']=''; $tplData=array(); $subject=array( 3=>'高考数学', 6=>'高三专用', 51=>'新高一高二', 12=>'物理' ); $topicTypeClass=array( 'jie'=>array(8,9,10,11), 'tian'=>array(5,6,7), 'single'=>array(1,2,12), 'multiple'=>array(3,4) ); // '0:线下阅卷、1:按题阅卷、2:按人阅卷、3:班级混合阅卷、4:班级单独阅卷', $markType=array( 0=>'线下阅卷',1=>'按题阅卷',2=>'按人阅卷',3=>'班级混合阅卷',4=>'班级单独阅卷' ); $typeArr=array( 1=>'周考',2=>'单元考',3=>'月考',4=>'联考',5=>'期中',6=>'期末',7=>'高考模拟',8=>'冲刺', ); $data['mark_type']=$markType[$examGroup['mark_type']]; $subjectId=$this->subjectId; if($examClass){ foreach ($examClass as $val){ if(!$tplData){ $json=json_decode($val['tpl_data'],true); $tplData['examDate']=$json['examDate']; $tplData['subjectId']=$subject[$json['subjectId']]; $subjectId=$json['subjectId']; if(isset($json['textbookId'])){ $tplData['textbookId']=$json['textbookId']; } $tplData['qxk']=0; $tplData['type']=$typeArr[$val['type']]; $tplData['author']=$json['author']; if($examGroup['qxk_paper_id']>0 && isset($json['new_items'])){ $tplData['qxk']=1; foreach ($json['new_items'] as $item){ if(in_array($item['basicTopicType'],$topicTypeClass['single'])){ if(!isset($tplData['select_num'])){ $tplData['select_num']=1; }else{ $tplData['select_num']++; } }elseif(in_array($item['basicTopicType'],$topicTypeClass['multiple'])){ if(!isset($tplData['mult_select_num'])){ $tplData['mult_select_num']=1; }else{ $tplData['mult_select_num']++; } }elseif(in_array($item['basicTopicType'],$topicTypeClass['tian'])){ if(!isset($tplData['tiankong_num'])){ $tplData['tiankong_num']=1; }else{ $tplData['tiankong_num']++; } }elseif(in_array($item['basicTopicType'],$topicTypeClass['jie'])){ if(isset($item['sameAliasNo']) && $item['sameAliasNo']){ if(!isset($tplData['xuanzuo_num'])){ $tplData['xuanzuo_num']=1; }else{ $tplData['xuanzuo_num']++; } }else{ if(!isset($tplData['jieda_num'])){ $tplData['jieda_num']=1; }else{ $tplData['jieda_num']++; } } } } }else{ if(isset($json['items'][1])){ $tplData['select_num']=$json['items'][1]['total']; } if(isset($json['items'][2])){ $tplData['mult_select_num']=$json['items'][2]['total']; } if(isset($json['items'][5])){ $tplData['tiankong_num']=$json['items'][5]['total']; } if(isset($json['items'][7])){ $tplData['jieda_num']=$json['items'][7]['total']; } if(isset($json['items'][17])){ $tplData['xuanzuo_num']=$json['items'][17]['total']; } } } $data['class'].=''.$val['class_name'].''; } } //读取教材 if(isset($tplData['textbookId']) && $tplData['textbookId']){ $textBook = $this->apiBrainPost('/textbook/tree', array('subjectId' => $subjectId )); if($textBook){ foreach ($textBook as $value){ if($tplData['textbookId']==$value->textbook_id){ $tplData['textBook']=$value->textbook_name; } } } } $result['status']=1; $result['data']=array_merge($data,$tplData); exit(json_encode($result)); } //切换扫描方式 public function actionChangeExamScan(){ $exam_group_id=Req::post('exam_group_id'); $result['status']=0; if(!$exam_group_id){ exit(json_encode($result)); } $examGroup=$this->sConn->createCommand("select teacher_id,mark_type from exam_group where exam_group_id='".$exam_group_id."'")->queryRow(); if(!$examGroup){ $result['msg']='考试信息不正确'; exit(json_encode($result)); } $exam=$this->sConn->createCommand("select tpl_data from exam where exam_group_id='".$exam_group_id."'")->queryRow(); $tpl_data=json_decode($exam['tpl_data'],true); if(isset($tpl_data['required']) && $tpl_data['required']>1){ $result['msg']='选做题只支持多选一设置'; exit(json_encode($result)); } if(isset($tpl_data['items'][17]['required']) && $tpl_data['items'][17]['required']>1){ $result['msg']='选做题只支持多选一设置'; exit(json_encode($result)); } $updateSql="update exam_group set is_scan_changed=1 where exam_group_id='".$exam_group_id."'"; if($this->sConn->createCommand($updateSql)->execute()){ $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow(); if($thirdAnswerSheet){ $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id='".$exam_group_id."' ")->execute(); } $this->schoolManager->saveExamProcess($exam_group_id,11,time()); $result['status']=1; } exit(json_encode($result)); } //加载考试 public function actionAjaxSearchExam(){ $grade=Req::post('grade'); $class=Req::post('class'); $condition=array(); $subject=$this->subjectId; $condition[]='eg.is_third=0'; $condition[]='eg.is_scan_changed=0'; $condition[]='e.status<>1'; $condition[]='eg.mark_type<>0'; // $condition[] = "eg.create_type <>6 "; if($subject==3){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[]="e.subject_id ='".$subject."'"; } if($grade){ $condition[]="c.grade='".$grade."'"; } if($class){ $condition[]="c.class_id='".$class."'"; } $sql="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type,e.is_backlog,e.tpl_index,tas.online_card,tas.is_qrcode_online FROM `exam` e "; $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id "; $sql.="join class c on c.class_id=e.class_id "; $sql.="join paper p on p.exam_id=e.exam_id "; $sql.="left join third_answer_sheet tas on tas.exam_group_id=eg.exam_group_id "; if($condition){ $sql.=" where ".implode(' and ',$condition); } $Exam = $this->sConn->createCommand($sql)->queryAll(); $list=array(); if($Exam){ $paperIds=array(); $examGroupIds=array(); foreach($Exam as $key=>$val){ if( $val['online_card'] && $val['is_qrcode_online']){ continue; } $is_custom_tpl=false; $paper_tpl_type=0; if(in_array($val['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $is_custom_tpl = true; }else{ //非自定义模板 $is_custom_tpl = false; } if (in_array($val['tpl_index'], Yii::app()->params['no_template_id']) || $is_custom_tpl) { //题卡分离 $paper_tpl_type = 2; }else{ $paper_tpl_type = 1; } if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $paper_tpl_type = 3; if($val['tpl_index'] == 9 ) { $paper_tpl_type = 4; } } if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $paper_tpl_type = 3; if($val['tpl_index'] == 9 ) { $paper_tpl_type = 4; } } if (!$is_custom_tpl && $paper_tpl_type != 3){ continue; } $tpl_data=json_decode($val['tpl_data'],true); if(isset($tpl_data['items'][17])){ // continue; //选做题过滤 } if($val['is_backlog']==0){ $examGroupIds[]=$val['exam_group_id']; } } if($class && $examGroupIds){ $sqlClassCount="SELECT eg.exam_group_id,e.exam_id,e.name,e.tpl_data,eg.is_third,e.`status`,e.subject_id,eg.import_score_type FROM `exam_group` eg "; $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id "; $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).") order by e.update_time desc"; $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll(); foreach ($ExamCount as $val){ $list[$val['exam_group_id']]=$val; } } } $result['status']=1; $result['list']=$list; exit(json_encode($result)); } //联评卷列表 public function actionUnited() { //初始化 $exam_group_ids = array(); $exam_ids = array(); $_exam_ids = array(); $_exam_group_ids = array(); $exam_printer_num = array(); $exam_use_wp = array(); $data = array(); $condition = array(); $paper_exam = array(); $class_exam = array(); $class_ids = array(); $class_grade_arr = array(); $paper_arr = array(); //筛选条件 $printName = Req::get("name"); $grade = Req::get("grade"); $labelled = Req::get("labelled"); $display = Req::get("display"); $type = Req::get("type"); // 发送标注条件 if($labelled>-1) { $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled); if($paper_exam) { foreach($paper_exam as $v) { $s_exam_ids[$v['exam_id']] = $v['exam_id']; } } unset($paper_exam); } // 年级条件 if($grade>0) { $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId); if($class_data) { foreach($class_data as $v) { $class_ids[$v['class_id']] = $v['class_id']; } $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids); if($exam_class_data) { foreach($exam_class_data as $v) { if(isset($s_exam_ids[$v['exam_id']])) { $l_b_exam_ids[$v['exam_id']] = $v['exam_id']; }else { $s_exam_ids[$v['exam_id']] = $v['exam_id']; } } } unset($exam_class_data); } unset($class_data); } if(isset($l_b_exam_ids)) { if($l_b_exam_ids) { $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")"; }else { $condition[] = "e.exam_id in (0)"; } }else { if($labelled<0||$grade<1) { if(isset($s_exam_ids)) { if($s_exam_ids) { $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")"; }else { $condition[] = "e.exam_id in (0)"; } } }else { $condition[] = "e.exam_id in (0)"; } } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "e.subject_id = '{$this->subjectId}'"; } if ( $display == 1) { $condition[] = "e.is_display = 1"; }else { $condition[] = "e.is_display = 0"; } // 考试名称条件 if($printName) { $condition[] = "e.name like '%{$printName}%'"; } $condition[] = "eg.is_united = 1"; //获取考试列表 $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12); $branch=array( 0=>'不分科', 1=>'文科', 2=>'理科' ); //获取打印班级 if($exam_list) { foreach($exam_list['rs'] as $key=>$v) { $items = array(); $tpl_data=array(); $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id']; $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板 $exam_list['rs'][$key]['is_custom_optional_topic'] = 0; $exam_list['rs'][$key]['is_paper_49'] = 0; if(isset($v['tpl_data'])){ $tpl_data = json_decode($v['tpl_data'],1); } if(isset($tpl_data['branch'])){ $exam_list['rs'][$key]['branch'] = $tpl_data['branch']; } if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $exam_list['rs'][$key]['is_custom_tpl'] = true; if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){ $exam_list['rs'][$key]['is_custom_optional_topic'] = 1; } $v['is_custom_tpl'] = true; }else{ //非自定义模板 $exam_list['rs'][$key]['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $exam_list['rs'][$key]['is_tpl'] = 1; //题卡分离 $exam_list['rs'][$key]['paper_tpl_type'] = 2; }else{ $exam_list['rs'][$key]['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $exam_list['rs'][$key]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $exam_list['rs'][$key]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $exam_list['rs'][$key]['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $exam_list['rs'][$key]['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7'])) { $exam_list['rs'][$key]['is_paper_49'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8'])) { $exam_list['rs'][$key]['is_paper_49'] = 1; } //题卡合一 //读取联考文理科 $united=$this->schoolManager->getUnitedByExamGroupId($v['exam_group_id']); if($united){ $exam_list['rs'][$key]['branch_name']=$branch[$united['branch']]; }else{ $exam_list['rs'][$key]['branch_name']=''; } } //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id'; $criteria->addInCondition('exam_group_id',$exam_group_ids); $exam_data = Exam::model()->findAll($criteria); unset($criteria); unset($exam_group_ids); if($exam_data) { foreach($exam_data as $v) { //$exam_use_wp $exam_ids[$v->exam_id] = $v->exam_id; $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id; $_exam_ids[$v->exam_id] = $v->exam_group_id; } unset($exam_data); //通过考试ID,获取打印班级 $criteria = new CDbCriteria(); $criteria->select = 'exam_id,class_id'; $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_print = 1'); $class_print_data = ClassExamPrinter::model()->findAll($criteria); if($class_print_data) { foreach($class_print_data as $v) { if( isset($_exam_ids[$v->exam_id])) { $exam_printer_num[$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id; } } } unset($criteria); unset($class_print_data); } } //获取班级年级 $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId)); if($class_data) { foreach($class_data as $v) { $class_grade_arr[$v->class_id] = $v->grade; } } unset($class_data); //获取试卷标注状态 $criteria = new CDbCriteria(); $criteria->select = 'exam_id,is_labelled'; $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); unset($criteria); if($paper_data) { foreach($paper_data as $v) { if( isset($_exam_ids[$v->exam_id])) { $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled; } } } //查询联评卷考试 $apply_setting_type=1; $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId); if($schoolInfo['client']==2){ $apply_setting_type=0; } $TaskExam=$this->schoolManager->getUnitedList($apply_setting_type); $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id'])); $data['pages'] = $exam_list['pager']; $data['page_total'] = $exam_list['pager']->rowsCount; $data['printList'] = $exam_list['rs']; $data['printer'] = $exam_printer_num; $data['exam_class'] = $_exam_group_ids; $data["exam_use_wp"] = $findSchool->use_wp; $data["display"] = $display; $data["labelled"] = $labelled; $data["grade"] = $grade; $data["printName"] = $printName; $data["paper"] = $paper_arr; $data["class_grade"] = $class_grade_arr; $data["printType"] = $type; $data['task_exam']=$TaskExam; $this->render('group_list_united',$data); } public function actionClass_exam_united() { $condition = array(); $exam_ids = array(); $exam_id = ''; $exam_name = ''; $class_names = array(); $class_ids = array(); $class_print = array(); $data = array(); $exam_student_up_num = array(); $exam_student_num = array(); $class_name = Req::get("class_name"); $exam_group_id = Req::get("exam_group_id"); $masttype = (int)Req::get("masttype"); $is_united = (int)Req::get('is_united'); if($exam_group_id <= 0) { Yii::app()->jump->error('未找到考试信息!'); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_group_data) { Yii::app()->jump->error('未找到考试信息!'); } $condition[] = "exam_group_id = ".$exam_group_id; //获取班级信息 $class_data = $this->schoolManager->getSemesterClasses($this->semesterId); if($class_data) { foreach($class_data as $v) { if($class_name && $v['class_name'] == $class_name) { $class_ids[$v['class_id']] = $v['class_id']; } $class_names[$v['class_id']] = $v['class_name']; } } if($class_ids) { $condition[] = "class_id in (".implode(',',$class_ids).") "; } // 多学科切换条件 if(in_array($this->subjectId,$this->mathSubjectId)){ $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")"; }else{ $condition[] = "subject_id = '{$this->subjectId}'"; } if($class_ids) { $condition[] = "class_id in (".implode(',',$class_ids).") "; } //获取考试列表 $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12); if($exam_data['rs']) { foreach($exam_data['rs'] as $k=>$v) { $exam_ids[$v['exam_id']] = $v['exam_id']; $exam_id = $v['exam_id']; $exam_name = $v['print_name']; } }else { Yii::app()->jump->error('未找到考试信息!'); } //查询联考模板 $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_group_id); if(!$task_exam){ Yii::app()->jump->error('联考数据读取失败!'); } //获取班级考试是否打印 $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('type = 0'); $class_print_data = ClassExamPrinter::model()->findAll($criteria); if($class_print_data) { foreach($class_print_data as $v) { $class_print[$v->exam_id] = $v->is_print; } } unset($criteria); unset($class_print_data); //获取班级考试的上传成绩 $criteria = new CDbCriteria(); $criteria->select= 'student_id,is_feedback,exam_id'; $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('is_del = 0'); $student_paper_data = SStudentPaperRelation::model()->findAll($criteria); unset($exam_ids); if($student_paper_data) { foreach($student_paper_data as $v) { if($v->is_feedback) { $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id; } $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id; } } unset($criteria); unset($student_paper_data); //获取paper 表数据 $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if(!$paper_data) { Yii::app()->jump->error('未找到考试信息!'); } $printList = array(); if($exam_data["rs"]){ foreach ($exam_data['rs'] as $k=>$v) { $printList['is_tpl'] = 0; // 需要上传模板 $printList['answer_card_uploaded'] = false; if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $printList['is_custom_tpl'] = true; $v['is_custom_tpl'] = true; }else{ //非自定义模板 $printList['is_custom_tpl'] = false; $v['is_custom_tpl'] = false; } if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) { $printList['is_tpl'] = 1; if(trim($paper_data->answer_card_src)){ $printList['answer_card_uploaded'] = true; } //题卡分离 $printList['paper_tpl_type'] = 2; }else{ $printList['paper_tpl_type'] = 1; } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl'])) { $printList['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList['paper_tpl_type'] = 4; } } if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all'])) { $printList['paper_tpl_type'] = 3; if($v['tpl_index'] == 9 ) { $printList['paper_tpl_type'] = 4; } } //英语题卡分离一 if($this->subjectId == 8){ $printList['paper_tpl_type'] = 5; } } } // 获取多学科状态 $this->setIs_new($exam_group_id); $data['printList'] = $exam_data['rs']; $data['print'] = $printList; $data['pages'] = $exam_data['pager']; $data['page_total'] = $exam_data['pager']->rowsCount; $data["class_name"] = $class_name; $data["class_data"] = $class_names; $data["exam_group_data"] = $exam_group_data; $data["exam_id"] = $exam_id; $data["exam_name"] = $exam_name; $data["exam_print"] = $class_print; $data["exam_student"] = $exam_student_num; $data["exam_up_student"] = $exam_student_up_num; $data["exam_group_id"] = $exam_group_id; $data['task_exam']=$task_exam; $this->render('class_exam_united',$data); } //报名统考列表 public function actionUnitedTask(){ $data=array(); $apply_setting_type=1; $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId); if($schoolInfo['client']==2){ $apply_setting_type=0; } $TaskExam=$this->schoolManager->getAllUnitedList($apply_setting_type); $grade=array( 0=>'', 1=>'高一', 2=>'高二', 3=>'高三' ); $branch=array( 0=>'不分科', 1=>'文科', 2=>'理科' ); if($TaskExam){ foreach ($TaskExam as $key=>$val){ $TaskExam[$key]['sign_up']=0; //查询报名 $singUpData=$this->schoolManager->getSignUpBySchoolIdTaskId($this->schoolId,$val['task_exam_id']); if($singUpData){ $TaskExam[$key]['sign_up']=1; $TaskExam[$key]['mobile']=$singUpData['user_name'].'/'.$singUpData['mobile']; } $TaskExam[$key]['grade_name']=$grade[$val['grade']]; $TaskExam[$key]['branch_name']=$branch[$val['branch']]; } } $data['task_exam']=$TaskExam; $this->render('united_task',$data); } //报名 public function actionSignUp(){ $tk_exam_id = Req::post("exam_group_id"); $contacts = Req::post('contacts'); $tel = Req::post('tel'); $school_id = $this->schoolId; $coach_id = Yii::app()->session['coachInfo']['coach_id']; $result['status']=0; $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id); if(!$task_exam){ $result['msg']="联考信息有误"; exit(json_encode($result)); } if($task_exam['apply_deadline']schoolManager->getExamByTaskId($tk_exam_id); if($unitedExam){ $result['msg']="考试已开始,不接受报名啦"; exit(json_encode($result)); } $signData=$this->schoolManager->getSignUpBySchoolIdTaskId($school_id,$tk_exam_id); if($signData){ $result['msg']="已报名当次联考,不能重复报名"; exit(json_encode($result)); }else{ //学校信息 $schoolInfo=$this->schoolManager->getSchoolInfo($school_id); $insertData=array( 'teacher_id'=>$coach_id, 'school_id'=>$school_id, 'tk_exam_id'=>$tk_exam_id, 'user_name'=>$contacts, 'mobile'=>$tel, 'create_time'=>date('Y-m-d H:i:s'), 'school_name'=>$schoolInfo['school_name'], 'province_id'=>$schoolInfo['province_id'], 'city_id'=>$schoolInfo['city_id'], 'area_id'=>$schoolInfo['area_id'], 'address'=>$schoolInfo['address'] ); if($this->schoolManager->SignUp($insertData)){ $result['status']=1; } } exit(json_encode($result)); } //取消报名 public function actionSignOut(){ $tk_exam_id = Req::post("exam_group_id"); $school_id = $this->schoolId; $result['status']=0; $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id); if(!$task_exam){ $result['msg']="联考信息有误"; exit(json_encode($result)); } if($task_exam['apply_deadline']schoolManager->getExamByTaskId($tk_exam_id); if($unitedExam){ $result['msg']="考试已开始,不能撤消报名"; exit(json_encode($result)); } if($this->schoolManager->SignOutBySchoolIdTaskId($school_id,$tk_exam_id)){ $result['status']=1; } exit(json_encode($result)); } // 下载联考答题卡 public function actionCreate_united_tempelate(){ $wpcode = Req::post("eid"); $flag = Req::post("flag"); $error['success'] = 0; if (empty($wpcode)) { $error['message'] = '么有周周练id!'; echo json_encode($error);exit(); } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode)); //获取本次考试的examids $exam_ids = array(); $getRes=array(); if($exam_data) { $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $index_tpl = 0; if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; $index_tpl = $v->tpl_index; } } $getRes['examGroupId']=$exam_data->exam_group_id; //读取联考数据 $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_data->exam_group_id); if(!$task_exam){ $error['message'] = '联考信息有误!'; echo json_encode($error);exit(); } $getRes['path']=$task_exam['answer_template_url']; if($exam_data['school_card_status']==1){ $getRes['school_card_status']=1; $getRes['school_card_length']=(int)$exam_data['school_card_length']; }else{ $school_card_length = 8; if($this->schoolId>999){ $school_card_length = 9; } $getRes['school_card_status']=0; $getRes['school_card_length']=(int)$school_card_length; } if(in_array($index_tpl,Yii::app()->params['print_topic_tpl'])) { $flag = 0; } if($flag==3 || $flag==4 || $flag == 12) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $criteria->addCondition('type=:type'); $criteria->params[':type'] = 0; $getResult = ClassExamPrinter::model()->findAll($criteria); if (!empty($getResult)) { ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria); } } } $data['success']=1; $data['object']=$getRes; echo json_encode($data);die; } //晨读词汇全学科获取教材 public function getQuanTextbook(){ $result = array(); $topicDetails = $this->apiBrainPost('/all_textbook/getTextbookBySubjectId', array('subjectId' => 8,'type'=>1), 25, true); if($topicDetails && isset($topicDetails['status']) && $topicDetails['status']){ if(isset($topicDetails['data']) && $topicDetails['data']){ $result = $topicDetails['data']; } } return $result; } //晨读词汇全学科获取知识点(暂时用于晨读词汇专题专项) public function getQuanKnowledge(){ $result = array(); $i=0; $data = $this->apiBrainPost('/all_knowledge/tree', array('subjectId' => 8,'isTree'=>1), 25, true); if($data && isset($data['status']) && $data['status']){ if(isset($data['data']) && $data['data']){ // $result = $data['data']; foreach($data['data'] as $level_1){ if(isset($level_1['child']) && $level_1['child']){ foreach($level_1['child'] as $level_2){ if(isset($level_2['knowledge_name']) && $level_2['knowledge_name']=='语法'){ if(isset($level_2['child']) && $level_2['child']){ foreach($level_2['child'] as $level_3){ if(isset($level_3['knowledge_id']) && $level_3['knowledge_id'] && isset($level_3['knowledge_name']) && $level_3['knowledge_name']){ $result[$i] = array('special_id'=>$level_3['knowledge_id'],'special_name'=>$level_3['knowledge_name'],'items'=>array()); if(isset($level_3['child']) && $level_3['child']){ foreach($level_3['child'] as $level_4){ if(!$level_4['child'] && isset($level_4['knowledge_id']) && $level_4['knowledge_id'] && isset($level_4['knowledge_name']) && $level_4['knowledge_name']){ $result[$i]['items'][] = array('item_id'=>$level_4['knowledge_id'],'item_name'=>$level_4['knowledge_name']); } } }else{//二级知识点下无三级知识点时,二级补到三级(若专题下无子集时,子集呈现自身) $result[$i]['items'][] = array('item_id' => $level_3['knowledge_id'], 'item_name' => $level_3['knowledge_name']); } $i++; } } } } } } } } } return $result; } //晨读词汇(高三) public function actionMrv3(){ $data = array(); $time = time(); $data['year'] = $year = date("Y"); $data['month'] = $month = (int)date("m"); $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $quanTextbookData = $this->getQuanTextbook(); if($quanTextbookData){ foreach($quanTextbookData as $k=>$v){ if(isset($v['textbook_id']) && isset($v['textbook_name'])){ $data['textbookNames'][$v['textbook_id']] = $v['textbook_name']; if(!isset($textbookId)){ $textbookId = $v['textbook_id']; } if($textbookId == $v['textbook_id']){ if(isset($v['child']) && $v['child']){ foreach($v['child'] as $kk=>$vv){ $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_id']; } if($moduleId == $vv['textbook_id']){ if(isset($vv['child']) && $vv['child']){ foreach($vv['child'] as $kkk=>$vvv){ $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name']; } } } } } } } } } $specialArr = $this->getQuanKnowledge(); /* 老流程暂时注释 $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $_textbookData = $textboookTree->find($criteria,array()); if($_textbookData){ foreach ($_textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ $data['textbookNames'][$value['textbook_id']] = $value['name']; if(!isset($textbookId)){ $textbookId = $value['textbook_id']; } if($textbookId == $value['textbook_id']){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $kk=>$vv){ $data['moduleNames'][$vv['textbook_module_id']] = $vv['name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_module_id']; } if($moduleId == $vv['textbook_module_id']){ if(isset($vv['unit']) && $vv['unit']){ foreach($vv['unit'] as $kkk=>$vvv){ $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name']; } } } } } } } } } } } $textboookTree = new MongodbGrammarSpecial(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); $specialArr = array(); if($textbookData){ foreach ($textbookData as $doc) { if ($doc['child']) { $item = array(); foreach ($doc['child'] as $child) { $item[] = array( 'item_id' => $child['grammar_id'], 'item_name' => $child['content'], ); } $specialArr[] = array( 'special_id' => $doc['_id'], 'special_name' => $doc['content'], 'items' => $item ); } } } */ $data['special_arr'] = $specialArr; // $data['special_arr'] = array( // array( // 'special_id' => 1, // 'special_name' => '专题1', // 'is_selected' => true, // 'items' => array( // array( // 'item_id' => 32, // 'item_name' => '专项11', // 'is_selected' => true, // ), // array( // 'item_id' => 1232, // 'item_name' => '专项10', // 'is_selected' => true, // ), // ) // ), // array( // 'special_id' => 2, // 'special_name' => '专题2', // 'is_selected' => true, // 'items' => array( // array( // 'item_id' => 324, // 'item_name' => '专项12', // 'is_selected' => true, // ), // array( // 'item_id' => 387, // 'item_name' => '专项13', // 'is_selected' => true, // ), // ) // ), // ); $data['printType'] = 'mrv3'; $this->render('mrv_3',$data); } //晨读词汇(高一高二) public function actionMrvSetting(){ $data = array(); $time = time(); $data['year'] = $year = date("Y"); $data['month'] = $month = (int)date("m"); $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $quanTextbookData = $this->getQuanTextbook(); if($quanTextbookData){ foreach($quanTextbookData as $k=>$v){ if(isset($v['textbook_id']) && isset($v['textbook_name'])){ $data['textbookNames'][$v['textbook_id']] = $v['textbook_name']; if(!isset($textbookId)){ $textbookId = $v['textbook_id']; } if($textbookId == $v['textbook_id']){ if(isset($v['child']) && $v['child']){ foreach($v['child'] as $kk=>$vv){ $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_id']; } if($moduleId == $vv['textbook_id']){ if(isset($vv['child']) && $vv['child']){ foreach($vv['child'] as $kkk=>$vvv){ $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name']; } } } } } } } } } /*老流程暂时注释 $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); if($textbookData){ foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ $data['textbookNames'][$value['textbook_id']] = $value['name']; if(!isset($textbookId)){ $textbookId = $value['textbook_id']; } if($textbookId == $value['textbook_id']){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $kk=>$vv){ $data['moduleNames'][$vv['textbook_module_id']] = $vv['name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_module_id']; } if($moduleId == $vv['textbook_module_id']){ if(isset($vv['unit']) && $vv['unit']){ foreach($vv['unit'] as $kkk=>$vvv){ $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name']; } } } } } } } } } } } */ $data['printType'] = 'mrv_setting'; $this->render('mrv_setting',$data); } //动态获取模块和单元(晨读词汇) public function actionAjaxWeekGetModuleAndUnit(){ $result = array(); $error = array(); $textbookId=(int)Req::post('textbookId'); $quanTextbookData = $this->getQuanTextbook(); if($quanTextbookData){ foreach($quanTextbookData as $key => $value){ if(isset($value['textbook_id']) && isset($value['textbook_name'])){ if($value['textbook_id'] == $textbookId){ if(isset($value['child']) && $value['child']){ foreach($value['child'] as $kk=>$vv){ $result['moduleNames'][$vv['textbook_id']] = $vv['textbook_name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_id']; } if($moduleId == $vv['textbook_id']){ if(isset($vv['child']) && $vv['child']){ foreach($vv['child'] as $kkk=>$vvv){ $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name']; } } } } } } } } } echo json_encode($result);exit; } //动态获取模块和单元 public function actionAjaxGetModuleAndUnit(){ $result = array(); $error = array(); $textbookId=(int)Req::post('textbookId'); $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); if($textbookData && $textbookId){ foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ if($value['textbook_id'] == $textbookId){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $kk=>$vv){ $result['moduleNames'][$vv['textbook_module_id']] = $vv['name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_module_id']; } if($moduleId == $vv['textbook_module_id']){ if(isset($vv['unit']) && $vv['unit']){ foreach($vv['unit'] as $kkk=>$vvv){ $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name']; } } } } } } } } } } } echo json_encode($result);exit; } //动态获取单元(晨读词汇) public function actionAjaxWeekGetUnitByModuleId(){ $result = array(); $error = array(); $textbookId=(int)Req::post('textbookId'); $moduleId=(int)Req::post('moduleId'); $quanTextbookData = $this->getQuanTextbook(); if($quanTextbookData){ foreach($quanTextbookData as $key => $value){ if(isset($value['textbook_id']) && isset($value['textbook_name'])){ if($value['textbook_id'] == $textbookId){ if(isset($value['child']) && $value['child']){ foreach($value['child'] as $kk=>$vv){ if($moduleId == $vv['textbook_id']){ if(isset($vv['child']) && $vv['child']){ foreach($vv['child'] as $kkk=>$vvv){ $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name']; } } } } } } } } } echo json_encode($result);exit; } //动态获取单元 public function actionAjaxGetUnitByModuleId(){ $result = array(); $error = array(); $textbookId=(int)Req::post('textbookId'); $moduleId=(int)Req::post('moduleId'); $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); if($textbookData && $moduleId && $textbookId){ foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ if($value['textbook_id'] == $textbookId){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $kk=>$vv){ if($moduleId == $vv['textbook_module_id']){ if(isset($vv['unit']) && $vv['unit']){ foreach($vv['unit'] as $kkk=>$vvv){ $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name']; } } } } } } } } } } } echo json_encode($result);exit; } //获取设置英语个性化学习宝的班级 public function actionAjaxGetClassesBySettingWeek(){ $result = array(); $error = array(); $grade=(int)Req::post('grade'); $year = date("Y"); $month = (int)date("m"); // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $week = date("W"); //获取班级 $hasSettingClassIds = array(); $sql = "select class_id,count(*) count from english_week where semester_id = '{$this->semesterId}' and year_num = {$year} and week_num = {$week} group by class_id"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ foreach($data as $k=>$v){ if($v['count'] > 2){ $hasSettingClassIds[] = (string)$v['class_id']; } } } if($grade){ $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ $i = 0; foreach($data as $k => $v){ $result[$i]['class_id'] = $v['class_id']; $result[$i]['class_name'] = $v['class_name']; if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){ $result[$i]['status'] = 1; }else{ $result[$i]['status'] = 0; } $i++; } } } echo json_encode($result);exit; } //设置高一高二英语个性化学习宝 public function actionAjaxSaveEnglishWeek(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=(int)Req::post('grade'); $unitIds = (array)Req::post('unitIds'); $unitNames = (array)Req::post('names'); $classIds = Req::post('selectClassIds'); $itemIds = (array)Req::post('selectedItemIds'); $classIds = array_unique($classIds); $wordType = Req::post('wordsType'); $phraseType = Req::post('phraseType'); $wordCount = Req::post('wordCount'); $phraseCount = Req::post('phraseCount'); $isAnswerSeparate = Req::post('isAnswerSeparate'); $isSameAnswer = Req::post('isSameAnswer'); $wordRange = Req::post('wordRange'); $spellCount = Req::post('spellCount'); $sentenceCount = Req::post('sentenceCount'); $isWordDerive = Req::post('isWordDerive'); $blankCount = Req::post('blankCount'); $translateCount = Req::post('translateCount'); $grammarSingleCount = Req::post('grammarSingleCount'); $grammarSheetCount = Req::post('grammarSheetCount'); $readingCount = Req::post('readingCount'); $unitNames = (array)Req::post('names'); $specialNames = (array)Req::post('specialNames'); if(in_array($grade,array(1,2))){ if(empty($unitIds)){$error[] = '请选择单元';} if(count($unitIds)>1){$error[] = '已选单元超出限制';} } if($grade == 3){ if(empty($unitIds)){$error[] = '请选择单元';} if(count($unitIds)>3){$error[] = '已选单元超出限制';} } if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } $wordApply = array( 'spell_count' => $spellCount?$sentenceCount:0, 'sentence_count' => $sentenceCount?$sentenceCount:0, 'blank_count' => $blankCount?$blankCount:0, 'translate_count' => $translateCount?$translateCount:0 ); } if(!$error){ $time = time(); $weekIds = array(); $month = (int)date("m"); // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $week = date("W"); $year = date("Y"); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ if ($grade == 3) { $weekName = '高三' . date('Y') . '年第' . date('W') . '周晨读词汇'; }else{ $weekName = $unitNames[0] . '晨读词汇'; } $weekGroupId = getUniqueId($this->schoolId); foreach($classIds as $k=>$v){ $weekId = getUniqueId($this->schoolId); $weekIds[] = $weekId; $this->sConn->createCommand()->insert('english_week_setting',array( 'grade' => $grade, 'class_id' => $v, 'semester_id' => $this->semesterId, 'node_ids' => implode(',',$unitIds), 'special_ids' => implode(',',$itemIds), 'create_time' => $time, 'words_type' => $wordType ? $wordType : 1, 'phrase_type'=> $phraseType ? $phraseType : 1, 'words_count'=> $wordCount ? $wordCount : 0, 'phrase_count'=> $phraseCount ? $phraseCount : 0, 'is_answer_separate'=>isset($isAnswerSeparate) ? $isAnswerSeparate : 1, 'words_range'=>isset($wordRange) ? $wordRange : 1, 'is_word_derive'=>isset($isWordDerive) ? $isWordDerive : 1, 'words_apply'=>json_encode($wordApply), 'is_same_answer' => isset($isSameAnswer)?$isSameAnswer:1, 'grammar_single_count' => $grammarSingleCount?$grammarSingleCount:0, 'grammar_sheet_count' => $grammarSheetCount?$grammarSheetCount:0, 'reading_count' => $readingCount?$readingCount:0, 'is_new_version'=>1, 'node_names'=>$unitNames ? addslashes(implode(",",$unitNames)) : '', 'special_names'=>$specialNames ? implode(",",$specialNames) : '' )); $set_id = $this->sConn->getLastInsertID(); $this->sConn->createCommand()->insert('english_week',array( 'week_id' => $weekId, 'name' => $weekName, 'class_id' => $v, 'grade' => $grade, 'semester_id' => $this->semesterId, 'year_num' => $year, 'week_num' => $week, 'set_id'=>$set_id, 'create_time' => $time, 'week_group_id' => $weekGroupId, 'is_all_html'=>1 )); //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); if($stuData){ foreach($stuData as $kk=>$vv){ $this->sConn->createCommand()->insert('english_week_student',array( 'week_id' => $weekId, 'student_id' => $vv['student_id'], )); } $this->sConn->createCommand()->insert('english_week_student',array( 'week_id' => $weekId, 'student_id' => 0, )); } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ //发送消息 $kafkaData = array( 'school_id' => $this->schoolId, 'msg_type' => 1,//90:重置 1:新设置 'grade' => $grade, 'subject_id' => 8, 'send_type' => 'english_week', 'product_type' => 15, 'gp_group_id' => $weekGroupId,//reading_id 'gp_ids' => $weekIds,//week_id ); sendDataToKafka("php-product-english-week-html", $kafkaData); echo json_encode(array('status'=>1));exit; } } /** * 重置晨读词汇 */ public function actionResetEnglishWeek(){ $weekGroupId = (string)Req::get("weekGroupId"); $data = array(); $resetCount = 0; if($weekGroupId){ $sql = "select ew.week_id,ew.`name`,ew.class_id,ew.is_reset,c.class_name from english_week ew join class c on ew.class_id = c.class_id where ew.week_group_id = '{$weekGroupId}'"; $msg = $this->sConn->createCommand($sql)->queryAll(); if($msg){ $i=0; foreach($msg as $k=>$v){ if($v["is_reset"]){ $resetCount++; } $weekId = $v["week_id"]; $data[$i]['total_count'] = 0; $data[$i]['create_count'] = 0; $data[$i]['name'] = $v["name"]; $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_week_student where student_id > 0 and week_id = '{$weekId}'"; $msg_student = $this->sConn->createCommand($sql)->queryRow(); if($msg_student){ $data[$i]['total_count'] = $msg_student["total_count"]; $data[$i]['create_count'] = $msg_student["create_count"]; } $data[$i]['week_id'] = $weekId; $data[$i]['class_name'] = $v["class_name"]; $data[$i]['is_reset'] = $v["is_reset"]; $i++; } } } if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){ $resetCount = 0; } // debug($data); $this->render('english_week_reset',array("data"=>$data,"resetCount"=>$resetCount,"weekGroupId"=>$weekGroupId)); } /** * 重置外刊美文功能 */ public function actionAjaxResetEnglishWeek(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $classExam=Req::post('classExam'); if(!$classExam || !is_array($classExam)){ $error[] = '请选择班级'; } $redingId=Req::post('readingId'); if(!$redingId){ $error[] = '请刷新后再尝试'; } } if(!$error){ $time = time(); $isNewVersion = 0; $transaction = $this->sConn->beginTransaction(); try{ $sql = "select week_group_id,week_id,grade,set_id from english_week where week_group_id='{$redingId}' and week_id in (".implode(',',$classExam).")"; $englishReading = $this->sConn->createCommand($sql)->queryAll(); if(!$englishReading){ throw new Exception('无重置晨读词汇推送数据'); } $setId = $englishReading[0]['set_id']; $sql = "select is_new_version from english_week_setting where id='{$setId}'"; $englishSetting = $this->sConn->createCommand($sql)->queryRow(); if($englishSetting){ $isNewVersion = $englishSetting['is_new_version']; } $this->sConn->createCommand("update english_week set is_all_html = 1,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute(); $sql = "update english_week_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") "; $this->sConn->createCommand($sql)->execute(); //重置后清除已存在的下载任务 $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=9"; $this->conn->createCommand($task_sql)->execute(); $weekIds=array(); $grade=0; foreach($englishReading as $item){ if($isNewVersion){ $weekIds[]=$item['week_id']; $grade=$item['grade']; } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ //新设置重置才发消息 if($weekIds && $grade) { $kafkaData = array( 'school_id' => $this->schoolId, 'msg_type' => 90,//90:重置 1:新设置 'grade' => $grade, 'subject_id' => 8, 'send_type' => 'english_week', 'product_type' => 15, 'gp_group_id' => $redingId,//reading_id 'gp_ids' => $weekIds,//week_id ); sendDataToKafka("php-product-english-week-html", $kafkaData); } echo json_encode(array('status'=>1));exit; } } //晨读词汇列表 public function actionMrv(){ Url::clean(); $data = array(); $printName = Req::get("name"); $classId = Req::get("classId"); $grade = (int)Req::get("grade"); $newCondition = array(); if($grade){ $newCondition[] = 'ew.grade='.$grade; } if($printName){ $newCondition[] = 'ew.name like "%'.$printName.'%"'; } if($classId){ $newCondition[] = 'ew.class_id='.$classId; } $resultList = $this->schoolManager->getEnglishWeek($newCondition,array('ew.create_time desc','ew.week_id desc')); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k]=$v; } } if (empty($grade)) { $grade = 'ALL'; } $classes = $this->schoolManager->getClasses($grade); $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data['printList'] = $printList; $data["printName"] = $printName; $data["classes"] = $classes; $data["classId"] = $classId; $data["grade"] = $grade; $data['printType'] = 'mrv'; // debug($printList); $this->render('mrv',$data); } //设置高三个性化学习宝 public function actionAjaxSaveEnglishWeekByGrade3(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $week=(int)Req::post('week'); if(!$week){ $error[] = "请选择周几"; } } if(!$error){ $time = time(); $sql = "select id from english_week_setting where grade = 3"; $data = $this->sConn->createCommand($sql)->queryRow(); if($data){ $insertStatus = $this->sConn->createCommand()->update("english_week_setting", array("setting_week_num" => $week,"create_time"=>$time),"grade=3"); }else{ $insertStatus = $this->sConn->createCommand()->insert('english_week_setting',array( 'grade' => 3, // 'semester_id' => $this->semesterId, 'setting_week_num' => $week, 'create_time' => $time, )); } if(!$insertStatus){ $error[] = '系统错误'; } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ echo json_encode(array('status'=>1));exit; } } //晨读词汇选择学生 public function actionSelectStuByMrv(){ $data = array(); $sname = (string)Req::get("sname"); //学生名字 $weekId = (string)Req::get("weekId"); if(!$weekId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from english_week ew join class c on ew.class_id = c.class_id where ew.week_id = '{$weekId}'"; $names = $this->sConn->createCommand($sql)->queryRow(); if(!$names){ $names = array(); $names['name'] = ''; $names['class_name'] = ''; $names['grade'] = 0; }else{ $data['name'] = isset($names['name'])?$names['name']:''; } $sql = "select student_id,is_week_pdf from english_week_student where week_id = '{$weekId}'"; $relateStudent = $this->sConn->createCommand($sql)->queryAll(); $studentIds = array(); $stuIsPdf = array(); if($relateStudent){ foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf']; } } if($studentIds){ $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字 if($studentNames){ if($sname){ $i = 1; foreach($studentNames as $k=>$v){ if(strpos($v,$sname) !== false){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $i++; } } }else{ $i = 1; foreach($studentNames as $k=>$v){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $i++; } } } } $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$names['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$names['class_id'], "semester"=>$code['refer_code'], "grade"=>$names['grade'], "students"=>$studentIds, "examTime"=>$names['create_time'], "classify"=>3, "subject"=>8 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $order_classify = ProductDownload::$order_classify; $classifies = $order_classify[ProductDownload::PRODUCT_TYPE_EN_MRV]; $canStudentIds = array(); foreach ($classifies as $classify) { $intarr['classify'] = $classify; $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs || $rs->errCode != "00") { continue; } if (!empty($rs->data)) { $canStudentIds = array_merge($canStudentIds,$rs->data); } } $canStudentIds = array_unique($canStudentIds); $data['limitstu'] = $canStudentIds ? $canStudentIds : array(); $data['weekId'] = $weekId; $data['sname'] = $sname; $data['printType'] = 'mrv_stu'; $this->render('mrv_stu',$data); } //下载晨读词汇个性化学习宝 public function actionGetEnglishFile(){ $weekId = (string)Req::get("weekId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$weekId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from english_week_student where week_id = '{$weekId}' and is_week_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if($stuArr){ foreach($stuArr as $k=>$v){ $studentsIds[] = $v['student_id']; } } }else{ $studentsIds = explode(',',$studentsIds); } if(!$studentsIds || empty($studentsIds)){ echo json_encode(array("success" => 0, "message" => "无生成的学生")); exit(); } $params['weekId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from english_week where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$msg['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$msg['class_id'], "semester"=>$code['refer_code'], "grade"=>$msg['grade'], "students"=>$studentsIds, "examTime"=>$msg['create_time'], "classify"=>3, "subject"=>8 ); $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId)); if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 1; $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); }else{ //更新下载时间 if($rs->success==1 || $rs->success==2){ $time = time(); if($studentsIds){ $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).")"; $this->sConn->createCommand($sql)->execute(); } } } // if(isset($rs->downloadPath)){ // if (YII_ENV == 'pro' || YII_ENV == 'production') { // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath); // } // } echo json_encode($rs);exit; } //月阶段复习列表 public function actionMainly_revision(){ Url::clean(); $data = array(); $printName = Req::get("name"); $classId = Req::get("classId"); $grade = (int)Req::get("grade"); $newCondition = array(); if($grade){ $newCondition[] = 'em.grade='.$grade; } if($printName){ $newCondition[] = 'em.name like "%'.$printName.'%"'; } if($classId){ $newCondition[] = 'em.class_id='.$classId; } $resultList = $this->schoolManager->getEnglishMonth($newCondition,array('em.create_time desc','em.month_id desc')); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k]=$v; } } if (empty($grade)) { $grade = 'ALL'; } $classes = $this->schoolManager->getClasses($grade); $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data['printList'] = $printList; $data["printName"] = $printName; $data["classes"] = $classes; $data["classId"] = $classId; $data["grade"] = $grade; $data['printType'] = 'mrv'; // debug($printList); $this->render('mainly_revision',$data); } //月阶段复习设置 public function actionSetting_mainly(){ $data = array(); $sql = "select setting_month_num from english_month_setting where type = 0"; $result = $this->sConn->createCommand($sql)->queryRow(); if($result){ $data['chooseMonth'] = $result['setting_month_num']; }else{ $data['chooseMonth'] = 1; } $data['printType'] = 'mrv_3'; $this->render('setting_mainly',$data); } //月阶段复习设置 public function actionAjaxSaveEnglishMonthMainly(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $week=(int)Req::post('week'); if(!$week){ $error[] = "请选择周几"; } } if(!$error){ $time = time(); $sql = "select id from english_month_setting where type = 0"; $data = $this->sConn->createCommand($sql)->queryRow(); if($data){ $insertStatus = $this->sConn->createCommand()->update("english_month_setting", array("setting_month_num" => $week,"create_time"=>$time),"type=0"); }else{ $insertStatus = $this->sConn->createCommand()->insert('english_month_setting',array( 'type' => 0, 'setting_month_num' => $week, 'create_time' => $time, )); } if(!$insertStatus){ $error[] = '系统错误'; } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ echo json_encode(array('status'=>1));exit; } } //下载英语月阶段复习 public function actionGetEnglishFileMonth(){ $monthId = (string)Req::get("monthId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$monthId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from english_month_student where month_id = '{$monthId}' and is_month_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if($stuArr){ foreach($stuArr as $k=>$v){ $studentsIds[] = $v['student_id']; } } }else{ $studentsIds = explode(',',$studentsIds); } if(!$studentsIds || empty($studentsIds)){ echo json_encode(array("success" => 0, "message" => "无生成的学生")); exit(); } $params['monthId'] = $monthId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from english_month where month_id = '{$monthId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$msg['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$msg['class_id'], "semester"=>$code['refer_code'], "grade"=>$msg['grade'], "students"=>$studentsIds, "examTime"=>$msg['create_time'], "classify"=>3, "subject"=>8 ); $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId)); if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 2; $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); }else{ //更新下载时间 if($rs->success==1 || $rs->success==2){ $time = time(); if($studentsIds){ $sql = "update english_month_student set is_download = 1,download_time={$time} where month_id = '{$monthId}' and student_id in (".implode(',',$studentsIds).")"; $this->sConn->createCommand($sql)->execute(); } } } // if(isset($rs->downloadPath)){ // if (YII_ENV == 'pro' || YII_ENV == 'production') { // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath); // } // } echo json_encode($rs);exit; } //月阶段复习选择学生 public function actionSelectStuByMainly(){ $data = array(); $sname = (string)Req::get("sname"); //学生名字 $monthId = (string)Req::get("monthId"); if(!$monthId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select em.name,c.class_name,em.grade,em.class_id,em.create_time,em.semester_id from english_month em join class c on em.class_id = c.class_id where em.month_id = '{$monthId}'"; $names = $this->sConn->createCommand($sql)->queryRow(); if(!$names){ $names = array(); $names['name'] = ''; $names['class_name'] = ''; $names['grade'] = 0; }else{ $data['name'] = isset($names['name'])?$names['name']:''; } $sql = "select student_id,is_month_pdf from english_month_student where month_id = '{$monthId}'"; $relateStudent = $this->sConn->createCommand($sql)->queryAll(); $studentIds = array(); $stuIsPdf = array(); if($relateStudent){ foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_month_pdf']; } } if($studentIds){ $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字 if($studentNames){ if($sname){ $i = 1; foreach($studentNames as $k=>$v){ if(strpos($v,$sname) !== false){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $i++; } } }else{ $i = 1; foreach($studentNames as $k=>$v){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $i++; } } } } $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$names['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$names['class_id'], "semester"=>$code['refer_code'], "grade"=>$names['grade'], "students"=>$studentIds, "examTime"=>$names['create_time'], "classify"=>3, "subject"=>8 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ Yii::app()->jump->error($rs->errMsg); } if(!empty($rs->data)){ $data['limitstu']=$rs->data; } $data['monthId'] = $monthId; $data['sname'] = $sname; $data['printType'] = 'mrv_stu'; $this->render('mainly_stu',$data); } //生成模板 public function actionAjaxCreateTemplate(){ $eId = Req::post('exam_id'); if(!$eId){ exit(json_encode(array("status"=>0,"result"=>"考试ID不能为空"))); } //调用java生成模板接口 $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/generate-fixed-template/'.$eId; $rs = $this->CrmApiPost($url,array(),$this->schoolId,$password); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => '', "operate_project" => 'zsyas2', "title" => '一键生成', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $url, "operate_sql" => '', "operate_param" =>json_encode(array('params'=>array('examId'=>$eId),'rs'=>$rs)), "date"=>date('Y-m-d H:i:j') ))); } if(isset($rs->errCode) && $rs->errCode =='00') { echo json_encode(array('status'=>1,'result'=>$rs->errMsg));exit; } $errMsg = '生成失败'; if(isset($rs->errMsg)) { $errMsg = $rs->errMsg; } echo json_encode(array('status'=>0,'result'=>$errMsg));exit; } public function actionAjaxPrintPaper(){ $exam_id = Req::post("exam_id"); $student_id = Req::post("student_id"); if(!$exam_id ) { echo json_encode(array("status"=>0,"result"=>"参数不能为空")); } if(empty($student_id) ) { echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生")); } $studentIds = explode(',',$student_id); foreach ($studentIds as $v) { if($v) { $student_ids[] = $v; } } $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/download-fixed-template'; $start = time(); $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password); $endTime = time(); //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => '', "operate_project" => 'zsyas2', "title" => '批量打印', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $url, "operate_sql" => '', "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids,'time'=>($endTime-$start)),'rs'=>$rs)), "date"=>date('Y-m-d H:i:j') ))); } if(isset($rs->errCode) && $rs->errCode =='00') { ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id)); echo json_encode(array('status'=>1,'result'=>$rs->data));exit; } $errMsg = '下载失败'; if(isset($rs->errMsg)) { $errMsg = $rs->errMsg; } echo json_encode(array('status'=>0,'result'=>$errMsg));exit; } //打印试卷和第三方试卷添加班级 public function actionAddExamClass() { $classId=Req::post('classId'); $exam_group_id=Req::post('eid'); $is_third = Req::post('is_third'); $result['status']=0; if(!$exam_group_id || !$classId || !is_array($classId)){ $result['msg']='数据异常'; exit(json_encode($result)); } //防止重复操作 $redis_add_class_status = Yii::app()->add_exam_class->hmget('temp:exam_class_mark_'.$exam_group_id,array('status')); if($redis_add_class_status && $redis_add_class_status[0]){ echo json_encode(array('status'=>0,'msg'=>'操作频繁,请稍后再试')); exit; }else{ Yii::app()->add_exam_class->hmset('temp:exam_class_mark_'.$exam_group_id,array('status'=>1)); Yii::app()->add_exam_class->expire('temp:exam_class_mark_'.$exam_group_id,30); } $examClass=array(); //原考试班级 $neeAddClass=array(); //需要增加的班级 $time=time(); $allExamIds=array(); //所有考试id,用于判断考试订单 //获取考试ID $criteria = new CDbCriteria(); $criteria->select = 'exam_id,exam_group_id,class_id'; $criteria->addCondition("exam_group_id='".$exam_group_id."'"); $exam_data = Exam::model()->findAll($criteria); unset($criteria); if($exam_data) { foreach($exam_data as $v) { $exam_ids[] = $v->exam_id; $examClass[] = (string)$v->class_id; } foreach ($examClass as $key => $val){ if(in_array((string)$val,$classId,true)){ unset($classId[array_search((string)$val,$classId,true)]); } } if($classId){ $neeAddClass= $classId; } $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length,is_fine_paper,is_fine_edit from exam where exam_id='".$exam_ids[0]."' ")->queryRow(); $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll(); $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status,labelled_type,send_labelled_time,finish_labelled_time from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow(); $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']); $paperLargeTopics = $this->schoolManager->getPaperLargeTopicsRecords($papers[0]['paper_id']); //增加班级 $needAddExamId=array(); if($neeAddClass){ $transaction = $this->sConn->beginTransaction(); try { //单独阅卷 添加exam_group表数据 $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); //FIXME 2019-10-23 单独阅卷&旧版阅卷 才添加marking_group记录 if( $exam_group_data['mark_type'] == 4 && $exam_group_data['is_new_marking']==0) { $i = 1; foreach ($paperTopics as $paperTopic) { if (!in_array($paperTopic['type'], array(1, 2, 11))) { $marking_group_id =getUniqueId($this->schoolId); foreach ($neeAddClass as $classId) { $sql = "select marking_group_id from marking_group where exam_group_id = '{$exam_group_id}' AND class_id = {$classId} AND topic_id = {$paperTopic['topic_id']}"; $data = $this->sConn->createCommand($sql)->queryRow(); if (!$data) { $this->sConn->createCommand()->insert('marking_group', array( 'exam_group_id' => $exam_group_id, 'marking_group_id' => $marking_group_id, 'class_id' => $classId, 'topic_id' => $paperTopic['topic_id'], 'topic_type' => $paperTopic['type'], 'topic_index' => $i, 'topic_score' => $paperTopic['score'] )); } } } $i++; } } $allStudentIds=array(); $allTeacherIds=array(); foreach ($neeAddClass as $classId) { $newExamId = getUniqueId($this->schoolId); $needAddExamId[]=$newExamId; $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll(); $studentIds=array(); if($studentIdData){ foreach ($studentIdData as $datum){ $studentIds[]=$datum['student_id']; } } //校验是否已存在重复学生 if($studentIds){ $checkRepeatStudent=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$exam_ids).") and student_id in(".implode(',',$studentIds).") and is_del=0")->queryRow(); if($checkRepeatStudent){ $checkStudentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$checkRepeatStudent['student_id']}'")->queryRow(); echo json_encode(array('status'=>0,'msg'=>$checkStudentInfo['realname'].'('.$checkStudentInfo['realname'].')已参加本场考试,请勿重复添加')); exit; } } $allStudentIds=array_merge($allStudentIds,$studentIds); //if(!$studentIds) continue; $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds); $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0); //添加考试 $status=3; if($exam_group_data->homework==0 && $is_third==1){ $status=2; }else{ $status=3; } $this->sConn->createCommand()->insert('exam', array( 'exam_id' => $newExamId, 'exam_group_id' => $exam_group_id, 'name' => $examDetail['name'], 'subject_id' => $examDetail['subject_id'], 'semester_id' => $examDetail['semester_id'], 'teacher_id' => $examDetail['teacher_id'], 'module_id' => $examDetail['module_id'], 'type' => $examDetail['type'], 'status' => $status, 'week_num' => $examDetail['week_num'], 'create_type' => $examDetail['create_type'], 'create_time' => $examDetail['create_time'], 'update_time' => $examDetail['update_time'], 'tpl_index' => $examDetail['tpl_index'], 'tpl_data' => $examDetail['tpl_data'], 'class_id' => $classId, 'method_ids' => $examDetail['method_ids'], 'from_exam_id' => $examDetail['from_exam_id'], 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0, 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0, 'is_fine_paper' => $examDetail['is_fine_paper'], 'is_fine_edit' => $examDetail['is_fine_edit'], // 'is_third' =>$examDetail['is_third'] )); //添加试卷 $newPaperId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('paper', array( 'paper_id' => $newPaperId, 'paper_type' => $paperDetail['paper_type'], 'exam_id' => $newExamId, 'paper_name' => "", 'paper_layer' => $paperDetail['paper_layer'], 'difficulty' => $paperDetail['difficulty'], 'topics_count' => $paperDetail['topics_count'], 'score' => $paperDetail['score'], 'add_time' => $paperDetail['add_time'], 'update_time' => $paperDetail['update_time'], 'method_ids' => $paperDetail['method_ids'], 'is_labelled' => $paperDetail['is_labelled'], 'labelled_type' => $paperDetail['labelled_type'], 'send_labelled_time' => $paperDetail['send_labelled_time'], 'finish_labelled_time' => $paperDetail['finish_labelled_time'], 'status' => $paperDetail['status'] )); if ($studentIds_0) { foreach ($studentIds_0 as $studentId) { // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds); // if($studentIds){ // foreach ($studentIds as $studentId) { $this->sConn->createCommand()->insert('student_paper_relation', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0), 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''), )); $this->sConn->createCommand()->insert('student_paper_relation_property', array( 'student_id' => $studentId, 'paper_id' => $newPaperId, 'exam_id' => $newExamId, 'semester_id' => $this->semesterId, 'class_id' => $classId, 'create_time'=>time(), )); } } foreach ($paperTopics as $paperTopic) { $this->sConn->createCommand()->insert('paper_topic_relation', array( 'paper_id' => $newPaperId, 'stem_id' => $paperTopic['stem_id'], 'topic_id' => $paperTopic['topic_id'], 'no' => $paperTopic['order'], 'order' => $paperTopic['order'], 'mode' => (int)$paperTopic['mode'], 'type' => $paperTopic['type'], 'score' => $paperTopic['score'], 'question_count' => $paperTopic['question_count'], 'question_score_str' => $paperTopic['question_score_str'], 'method_ids' => $paperTopic['method_ids'], 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2, 'template_id' => $paperTopic['template_id'], 'is_template' => $paperTopic['is_template'], 'is_delete' => $paperTopic['is_delete'], 'topic_from' => $paperTopic['topic_from'], 'logic_type'=>$paperTopic['logic_type'], )); $this->sConn->createCommand()->insert('topic_use', array( 'topic_id' => $paperTopic['topic_id'], 'mode' => $paperTopic['mode'], 'teacher_id' => $examDetail['teacher_id'], )); } foreach ($paperLargeTopics as $paperLargeTopic){ $this->sConn->createCommand()->insert('paper_topic_large', array( 'paper_id' => $newPaperId, 'large_topic_id' => $paperLargeTopic['large_topic_id'], 'topic_no' => $paperLargeTopic['topic_no'], 'logic_type' => $paperLargeTopic['logic_type'], 'logic_type_second' => $paperLargeTopic['logic_type_second'], 'method_ids' => $paperLargeTopic['method_ids'], )); } $this->sConn->createCommand()->insert('class_exam_printer', array( 'class_id' => $classId, 'exam_id' => $newExamId, 'type' => 0, 'is_print' => 0, 'print_time' => 0, 'add_time' => $time, )); } if($exam_group_data['homework']==1){ $tplData=json_decode($examDetail['tpl_data'],1); $teachers=$this->schoolManager->getTeachersByClassesIds($neeAddClass); $allStudentIds=array_values($allStudentIds); $studentReceiverList=array(); foreach ($allStudentIds as $val){ $studentReceiverList[(string)$val]=$val; } $studentReceiverList=array_values($studentReceiverList); $studentNotice[]=array( 'app'=>0, 'templateId'=>2, 'templateParams'=>array($examDetail['name']), 'userIds'=>$studentReceiverList ); if(isset($tplData['startline'])){ $studentNotice['dateTime']=date('Y-m-d H:i:s',strtotime($tplData['startline'])); } foreach ($teachers as $val){ if(!isset($receiverList[(string)$val['teacher_id']])){ $receiverList[(string)$val['teacher_id']]=$val['teacher_id']; } } $receiverList=array_values($receiverList); $teacherNotice=array( 'app'=>1, 'templateId'=>1, 'templateParams'=>array($examDetail['name']), 'userIds'=>$receiverList ); sendDataToKafka('send_message_center',$studentNotice); sendDataToKafka('send_message_center',$teacherNotice); sendAppNotify($studentNotice); sendAppNotify($teacherNotice); } //数学标注 $updateLabelledRs=''; $orderType=array(); if($exam_group_data['qxk_paper_id']>0 && in_array($examDetail['subject_id'],$this->mathSubjectId) && ($exam_group_data['is_tagging']>0 || $paperDetail['labelled_type']>0)){ //需要重新查询订单 $allExamIds=array_merge($exam_ids,$needAddExamId); $orderType = $this->checkProductOrderDetail($exam_group_id, $examDetail['subject_id'], array(31, 1, 2, 3,66),$allExamIds); if($orderType==-1){ $error['msg'] = '订单接口异常'; $error['status']=0; echo json_encode($error);exit(); }elseif($orderType==-2){ $error['msg'] = '考试参数异常,检查班级中是否添加学生'; $error['status']=0; echo json_encode($error);exit(); } if($orderType){ $updateLabelledRs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_task_data', array( "examGroupId" => (string)$exam_group_id, 'productOrderType'=>$orderType )); $updateLabelledData=json_decode($updateLabelledRs,true); if($updateLabelledData['success']==1){ //判断标注完成状态是否需要更新 if($exam_group_data['is_tagging']==1 || $paperDetail['is_labelled']==1){ $needUpdateIsTagging=0; $needUpdateLabelled=0; foreach ($orderType as $item){ if($item['goodsTypeId']==31){ $needUpdateIsTagging=1; } if(in_array($item['goodsTypeId'],array(1,2,3,66))){ $needUpdateLabelled=1; } } if($needUpdateIsTagging && $exam_group_data['is_tagging']!=1){ $this->sConn->createCommand("update exam_group set is_tagging=1 where exam_group_id='{$exam_group_id}'")->execute(); } if($needUpdateLabelled && $paperDetail['is_labelled']!=1){ $this->sConn->createCommand("update paper set is_labelled=1 where exam_id in(".implode(',',$allExamIds).")")->execute(); } } } } } //操作日志 if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$exam_group_id, "operate_project" => 'zsyas2', "title" => '添加删除班级', "school_id" => $this->schoolId, "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => '', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s'), "update_label_rs"=>$updateLabelledRs, 'order_type'=>$orderType ))); } $transaction->commit(); }catch (Exception $e){ $transaction->rollBack(); exit(json_encode(array('status'=>0,'msg'=>'保存失败'))); } } //发送学生端消息 if($needAddExamId ){ $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>3, 'exam_group_id'=>$exam_group_id, 'exam_id_arr'=>$needAddExamId ); sendStudentCacheQueue($sendJsonArr); } exit(json_encode(array('status'=>1,'msg'=>'设置成功'))); }else{ $result['msg']='考试数据异常'; exit(json_encode($result)); } } public function actionSendExamStomp(){ $exam_group_id=Req::post('examGroupId'); $exam_id=Req::post('examId'); $result['status']=0; if(!$exam_group_id || !$exam_id){ $result['msg']='考试数据异常'; exit(json_encode($result)); } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data['subject_id']==8){ $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_group_id,'examIds'=>array($exam_id)); $rs=$this->sendStomp($stomp_data); if($rs){ $sendMsg=array( 'school_id'=>$this->schoolId, 'msg_type'=>3, 'subject_id'=>$exam_data['subject_id'], 'send_type'=>'exam', 'exam_group_id'=>$exam_group_id, 'exam_ids'=>array($exam_id) ); sendDataToKafka('php-product-html',$sendMsg); $result['status']=1; $result['msg']='发送成功'; } }else{ $sendMsg=array( 'school_id'=>$this->schoolId, 'msg_type'=>3, 'subject_id'=>$exam_data['subject_id'], 'send_type'=>'exam', 'exam_group_id'=>$exam_group_id, 'exam_ids'=>array($exam_id) ); sendDataToKafka('php-product-html',$sendMsg); $result['status']=1; $result['msg']='发送成功'; } exit(json_encode($result)); } public function actionSendExamStompHomework(){ $exam_group_id=Req::post('examGroupId'); $exam_id=Req::post('examId'); $result['status']=0; if(!$exam_group_id || !$exam_id){ $result['msg']='考试数据异常'; exit(json_encode($result)); } //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>5, 'exam_group_id'=>$exam_group_id, 'exam_id_arr'=>array($exam_id), ); sendStudentCacheQueue($sendJsonArr); $result['status']=1; exit(json_encode($result)); } /** * 发送消息队列 * @return mixed */ private function sendStomp($data = array()) { if ($data) { $conf = new RdKafka\Conf(); $conf->set('metadata.broker.list', Yii::app()->params['kafka']); $producer = new RdKafka\Producer($conf); $topic = $producer->newTopic("zsyte-marking-finished-notify"); $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data)); $producer->poll(0); $result = $producer->flush(10000); if($result===0){ return true; } } return true; } //在线答题卡,试卷结构 public function actionGetPaperWithTopicsDetails(){ $examGroupId = Req::post("examGroupId"); $multiplexId = Req::post("multiplexId"); if(!$examGroupId){ exit(json_encode(array('success'=>0,'message'=>'参数错误'))); } $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId)); $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); $cardStatus=-1; $examIds = array(); $tplIndex=0; if($exam_data) { foreach ($exam_data as $val) { $examIds[] = $val['exam_id']; if(!$tplIndex){ $tplIndex=$val['tpl_index']; } if($cardStatus==-1){ $cardStatus=$val['school_card_status']; } } }else{ exit(json_encode(array('success'=>0,'message'=>'考试读取失败'))); } $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($examGroupId); if(!$paperData){ exit(json_encode(array('success'=>0,'message'=>'试卷结构读取失败'))); } $paperData=json_decode($paperData,true); $paperData['success']=1; if(in_array($tplIndex, Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $isCustomTpl = true; }else{ //非自定义模板 $isCustomTpl = false; } if (in_array($tplIndex, Yii::app()->params['no_template_id']) || $isCustomTpl) { //题卡分离 $paperData['paperTplType'] = 2; }else{ $paperData['paperTplType'] = 1; } if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl'])) { $paperData['paperTplType']= 1; if($tplIndex == 9 ) { $paperData['paperTplType'] = 2; } } if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl_all'])) { $paperData['paperTplType'] = 1; if($tplIndex == 9 ) { $paperData['paperTplType'] = 2; } } //英语题卡分离一 if($this->subjectId == 8){ $paperData['paperTplType'] = 2; } //读取打印班级状态 $countPrint=$this->sConn->createCommand("select count(*) as count from class_exam_printer where is_print_online=1 and exam_id in(".implode(',',$examIds).")")->queryRow(); if($countPrint && $countPrint['count']>0){ $paperData['printClassStatus']=1; }else{ $paperData['printClassStatus']=0; } $thirdAnswerSheet=$this->sConn->createCommand("select `name`,`position`,online_card_pdf,file_path,select_info,multiplex_id,`is_qrcode_online`,`create_time`,`update_time` from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow(); if($thirdAnswerSheet){ $paperData['position']=''; //判断是否有复用答题卡记录 if(!$thirdAnswerSheet['multiplex_id']){ //旧数据没有复用记录,需要补一条记录 $onlineCardMultiModel=new SOnlineCardMultiplex(); $onlineCardMultiModel->exam_group_id=$examGroupId; $onlineCardMultiModel->name=$thirdAnswerSheet['name']; $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path']; $onlineCardMultiModel->position=$thirdAnswerSheet['position']; $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf']; $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online']; $onlineCardMultiModel->is_download=0; $onlineCardMultiModel->is_copy=0; $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time']; $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time']; if($onlineCardMultiModel->save()){ $nowMultiplexId=$onlineCardMultiModel->multiplex_id; $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$examGroupId}'")->execute(); } } if($multiplexId){ $multi=$this->sConn->createCommand("select multiplex_id,exam_group_id,`name`,file_path,`position`,online_card_pdf,is_qrcode_online,is_download,is_copy,update_time from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow(); if($multi){ if($multi['position']){ if(strpos($multi['position'],'http://')!==false || strpos($multi['position'],'https://')!==false){ $multi['position']=fileGetContents($multi['position']); } $paperData['position']=$multi['position']; } } }elseif($thirdAnswerSheet['position']){ if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){ $paperData['position']=fileGetContents($thirdAnswerSheet['position']); }else{ $paperData['position']=$thirdAnswerSheet['position']; } } $paperData['online_card_pdf']=$thirdAnswerSheet['online_card_pdf']; $paperData['file_path']=$thirdAnswerSheet['file_path']; $paperData['stem_info']=$thirdAnswerSheet['select_info']; }else{ $paperData['position']=''; $paperData['online_card_pdf']=''; $paperData['file_path']=''; $paperData['stem_info']=''; } $paperData['card_status']=$cardStatus; $paperData['examStatus']=$findInfo->status; exit(json_encode($paperData)); } //保存在线答题卡 public function actionSaveCardOnline(){ $examGroupId = Req::post("examGroupId"); $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id $text = trim(Req::post("timu")); $name = Req::post("title"); $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:''; $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:''; $post = json_decode($text,true); $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0; $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0; $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0; $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0; $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0; $stemInfo=isset($_POST['stemInfo'])?$_POST['stemInfo']:0; $error['success']=0; if(!$examGroupId){ $error['message'] = '考试id不能为空'; echo json_encode($error);exit(); } if(!$text || !$name || !$sheet_answer || !$sheet_score){ $error['message'] = '题目参数错误'; echo json_encode($error);exit(); } if(!$positionJson){ $error['message'] = '定位信息异常'; echo json_encode($error);exit(); } $time=time(); $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); if($exam_data){ // $tpl_data = json_decode($exam_data[0]['tpl_data'],1); //验证是否已下载,是否是复用的答题卡 if($multiplexId){ $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow(); if($checkMulti['is_download']){ $error['success']=0; $error['message'] = '上传失败,答题卡已经下载!'; echo json_encode($error);exit(); } if($checkMulti['is_copy']){ //只保存文件信息 $this->saveMultiplex(); } } $examIds=array(); foreach ($exam_data as $val){ $examIds[]=$val['exam_id']; } $card_file=array(); $card_pdf=''; // if (empty($_FILES)) { // $error['message'] = '未找到上传文件!'; // echo json_encode($error);exit(); // }else{ // debug($_FILES); if($_FILES){ foreach($_FILES as $k=>$v){ if(isset($v) && !empty($v)){ if(!isset($v['size']) || $v['size'] >= 8388608){ $error['message'] = '文件超过8M!'; echo json_encode($error);exit(); } $ext=substr($v['name'],strrpos($v['name'],'.')+1); if(!isset($v['name']) || !in_array($ext,array('doc','docx','pdf','bmp','jpg','jpeg','png','txt'))){ $error['message'] = '文件格式不正确!'; echo json_encode($error);exit(); } if($ext=='pdf'){ $card_pdf="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.pdf' ; if(!move_uploaded_file($v["tmp_name"], $card_pdf)){ $error['message'] = '保存Pdf文件失败!'; echo json_encode($error);exit(); } }else{ $card_file[] = $v; } } } } $fixName = 'upload/tmpDir/ThirdSheet/'. date('Y') .'/'. date('m') .'/'.date('j').'/'; $ucloudZipUrl=''; $ucloudPdfUrl=''; $ucloudTxtUrl=''; if (!file_exists($fixName)) { mkdir($fixName, 0777, true); } $zipFileName=$examGroupId.'_'.$time.'.zip'; $pathName=$fixName.$zipFileName; $zip = new ZipArchive; $zip->open($pathName, ZipArchive::CREATE); foreach($card_file as $k=>$v){ $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name'])); } $zip->addFromString('json.txt', $positionJson); $zip->close(); //FIXME 20191204 $ucloud = new Qcloud(); //上传压缩包 $rename = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $zipFileName; $uploadInfo = $ucloud->putFile($rename, $pathName); @unlink($pathName); if ($uploadInfo['status'] == 0) { $error['success']=0; $error['message'] = '答题卡文件上传失败! '; echo json_encode($uploadInfo);exit(); }else{ $ucloudZipUrl=$uploadInfo['url']; } //单独上传position.txt if($positionJson){ $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.txt' ; file_put_contents($positionTxt, $positionJson); $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .$time.'.txt' ; $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt); if ($uploadInfo['status'] == 0) { @unlink($positionTxt); $error['success']=0; $error['message'] = 'Position文件上传失败!'; echo json_encode($error);exit(); }else{ @unlink($positionTxt); $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); $ucloudTxtUrl=$uploadInfo['url']; } } //上传Pdf if($pdfUrl){ $ucloudPdfUrl=$pdfUrl; // $card_pdf="upload/ThirdSheet/" .$examGroupId.'.pdf' ; // $content = file_get_contents($pdfUrl); // // file_put_contents($card_pdf, $content); // // $uploadPdfName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.pdf' ; // $uploadInfo = $ucloud->putFile($uploadPdfName,$card_pdf); // // if ($uploadInfo['status'] == 0) { // @unlink($card_pdf); // $error['success']=0; // $error['message'] = '答题卡PDF文件上传失败!'; // echo json_encode($error);exit(); // }else{ // @unlink($card_pdf); // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); // $ucloudPdfUrl=$uploadInfo['url']; // } } if(!$multiplexId){ //没有复用记录,初始化一条记录 $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`,`is_qrcode_online`) values"; $insertSql.="('".$examGroupId."','".$name."','".$ucloudZipUrl."','".$ucloudTxtUrl."','".$ucloudPdfUrl."','".time()."','".time()."','".$useQrCode."')"; $this->sConn->createCommand($insertSql)->execute(); $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow(); $multiplexId=$last_insert_id['last_insert_id()']; }else{ //更新复用记录 $updateSql="update online_card_multiplex set `file_path`='{$ucloudZipUrl}',`position`='{$ucloudTxtUrl}',`online_card_pdf`='{$ucloudPdfUrl}',update_time='".time()."',is_qrcode_online='".$useQrCode."' where multiplex_id='{$multiplexId}'"; $this->sConn->createCommand($updateSql)->execute(); } $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow(); if(!$thirdAnswerSheet){ $ThirdAnswerSheetModel=new SThirdAnswerSheet(); $ThirdAnswerSheetModel->name=$name; $ThirdAnswerSheetModel->exam_group_id=$examGroupId; $ThirdAnswerSheetModel->ke_topic_num=$KeGuanTi; $ThirdAnswerSheetModel->tian_topic_num=$TianKongTi; $ThirdAnswerSheetModel->zu_topic_num=$ZhuGuanTi; $ThirdAnswerSheetModel->xuan_topic_num=$XuanZuoTi; $ThirdAnswerSheetModel->file_path=$ucloudZipUrl; $ThirdAnswerSheetModel->sheet_answer=$sheet_answer; $ThirdAnswerSheetModel->sheet_score=$sheet_score; $ThirdAnswerSheetModel->create_time=$time; $ThirdAnswerSheetModel->update_time=$time; $ThirdAnswerSheetModel->position=$ucloudTxtUrl; $ThirdAnswerSheetModel->online_card=1; $ThirdAnswerSheetModel->online_card_pdf=$ucloudPdfUrl; $ThirdAnswerSheetModel->is_qrcode_online=$useQrCode; $ThirdAnswerSheetModel->multiplex_id=$multiplexId; $rs=$ThirdAnswerSheetModel->save(); // $insert="insert into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`) "; // $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$ucloudZipUrl."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$ucloudPdfUrl."','".$useQrCode."') "; // $rs= $this->sConn->createCommand($insert)->execute(); }else{ //更新打印状态 $this->sConn->createCommand("update class_exam_printer set is_print_online=0 where exam_id in(".implode(',',$examIds).")")->execute(); $updateArr=array( 'file_path'=>$ucloudZipUrl, 'sheet_answer'=>$sheet_answer, 'sheet_score'=>$sheet_score, 'ke_topic_num'=>$KeGuanTi, 'tian_topic_num'=>$TianKongTi, 'zu_topic_num'=>$ZhuGuanTi, 'xuan_topic_num'=>$XuanZuoTi, 'update_time'=>$time, 'position'=>$ucloudTxtUrl, 'online_card'=>1, 'online_card_pdf'=>$ucloudPdfUrl, 'is_qrcode_online'=>$useQrCode, 'multiplex_id'=>$multiplexId ); $rs= SThirdAnswerSheet::model()->updateAll($updateArr,"exam_group_id ='{$examGroupId}'"); // $rs=$this->sConn->createCommand("update third_answer_sheet set `file_path` = '".$ucloudZipUrl."',sheet_answer='".$sheet_answer."',sheet_score='".$sheet_score."',ke_topic_num=".$KeGuanTi.",tian_topic_num=".$TianKongTi.",zu_topic_num=".$ZhuGuanTi.",xuan_topic_num=".$XuanZuoTi.",update_time=".time().",position='".$positionJson."',online_card=1,online_card_pdf='".$ucloudPdfUrl."',is_qrcode_online='".$useQrCode."' where exam_group_id = '{$examGroupId}' ")->execute(); } if($rs){ $OnlineCardSaveLogModel=new SOnlineCardSaveLog(); $OnlineCardSaveLogModel->exam_group_id=$examGroupId; $OnlineCardSaveLogModel->file_path=$ucloudZipUrl; $OnlineCardSaveLogModel->online_card_pdf=$ucloudPdfUrl; $OnlineCardSaveLogModel->position=$ucloudTxtUrl; $OnlineCardSaveLogModel->create_time=$time; $OnlineCardSaveLogModel->save(); $error['success']=1; $error['message'] = '保存成功!'; $error['data'] = $ucloudPdfUrl; $error['multiplex_id']=$multiplexId; echo json_encode($error);exit(); } // } }else{ $error['message'] = '考试不存在'.$examGroupId; echo json_encode($error);exit(); } echo json_encode($error);exit(); } //判断在线答题卡 public function actionGetOnlineCard(){ $exam_group_id = Req::post("exam_group_id"); if($exam_group_id) { $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1',array(':exam_group_id'=>$exam_group_id)); if(!$third_answer_data) { echo json_encode(array('status'=>-1));exit; } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if($exam_group_data) { $sheetAnswer=json_decode($third_answer_data['sheet_answer'],true); // $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); $tplData=json_decode($exam['tpl_data'],true); //update_answer new_rules $updateAnswer=array(); $newRules=array(); if(isset($tplData['update_answer'])){ $updateAnswer=$tplData['update_answer']; } if(isset($tplData['new_rules'])){ $newRules=$tplData['new_rules']; } $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam['exam_id'])); $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type in(1,2,11)',array(':paper_id'=>$paper['paper_id'])); foreach ($paperTopic as $item){ if((!isset($sheetAnswer[$item['order']]) || !$sheetAnswer[$item['order']]) && !isset($updateAnswer[$item['order']]) && (!isset($newRules[$item['order']]) || !$newRules[$item['order']]['rule_answer'] )){ echo json_encode(array('status'=>-2));exit; } } echo json_encode(array('status'=>1,'qxk_paper_id'=>$exam_group_data['qxk_paper_id']));exit; } } echo json_encode(array('status'=>0));exit; } private function mkdir($path, $chmod = 0755){ return is_dir($path) || (self::mkdir(dirname($path), $chmod) && mkdir($path, $chmod)); } /** * 下载pdf */ public function actionDownOnlinePdf() { $examGroupId = safe_replace(Yii::app()->request->getQuery('exam_group_id')); if (!$examGroupId) { Yii::app()->jump->error('请指定考试'); } $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1', array(':exam_group_id' => $examGroupId)); if (!$third_answer_data) { echo json_encode(array('status' => -1)); exit; } $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); $examIds = array(); if($exam_data) { foreach ($exam_data as $val) { $examIds[] = $val['exam_id']; } } if(!$examIds) { echo json_encode(array('status'=>-1));exit; } if ($third_answer_data->online_card_pdf) { ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),' exam_id in('.implode(',',$examIds).')'); $url=$third_answer_data->online_card_pdf; // 获取远程文件大小 // 注意filesize()无法获取远程文件大小 $headers = get_headers($url, 1); $fileSize = $headers['Content-Length']; //echo $fileSize;exit; // 设置header头 // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流 header('Content-Type: application/pdf'); // 告诉浏览器返回的文件大小类型是字节 header('Accept-Ranges:bytes'); // 告诉浏览器返回的文件大小 header('Content-Length: ' . $fileSize); // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称 Header("Content-Disposition: attachment; filename=" . $third_answer_data->online_card_pdf); // 输出文件内容 //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据 ob_clean(); $read_buffer = 1024 * 1024; $handle = fopen($url, 'rb'); //总的缓冲的字节数 $sum_buffer = 0; //只要没到文件尾,就一直读取 while (!feof($handle)) { echo fread($handle, $read_buffer); ob_flush(); } fclose($handle); } else { Yii::app()->jump->error('考试不存在或尚未生成PDF'); } } /** * html转pdf */ public function actionHtmlToPdf(){ $examGroupId = Req::post("examGroupId"); $pdfHtml = htmlspecialchars_decode(Req::post("pdfHtml")); // $pageSize = Req::post("pageSize"); // $orientation = (int)Req::post("orientation");//1-横向 2-纵向; $widthm = Req::post("widthm"); $heightm = Req::post("heightm"); $error['success']=0; if(!$examGroupId){ $error['message'] = '考试id不能为空'; echo json_encode($error);exit(); } if(!$pdfHtml){ $error['message'] = 'html信息错误'; echo json_encode($error);exit(); } // if(!$pageSize){ // $error['message'] = '请指定纸张大小'; // echo json_encode($error);exit(); // } // if(!$orientation){ // $error['message'] = '请指定纸张方向'; // echo json_encode($error);exit(); // }else{ // if($orientation == 1){ // $orientation = 'landscape'; // }else{ // $orientation = 'portrait'; // } // } if(!$widthm){ $error['message'] = '请设置宽度'; echo json_encode($error);exit(); } if(!$heightm){ $error['message'] = '请设置高度'; echo json_encode($error);exit(); } $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/online_answer/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $htmlpath.=$examGroupId . "-online_answer.html"; $f = fopen($htmlpath, "w"); fwrite($f, $pdfHtml); fclose($f); $htmlurl = '/upload/tmpDir/online_answer/' . $examGroupId . "-online_answer.html"; //访问HTML的路径 if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath $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; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " file://" . $htmlpath . " {$pdfpath}" . " 176mm*250mm ''"; } else { $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=$examGroupId."-online_answer.pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf_answer.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " {$widthm}*{$heightm} ''"; } exec($commond, $res, $code); // debug($res); if(isset($res[0])){ if (strpos($res[0], 'succeed') !== false) {//命令返回成功 if ($this->file_exists($pdfpath)) { $repdf = $examGroupId.".pdf"; $rename = 'zsyas2/online_answer/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); @unlink($pdfpath); @unlink($htmlpath); if ($uploadInfo['status'] == 0) { echo json_encode(array("success" => 0, "message" => "PDF文件上传失败"));exit; }else{ $pdfurl = $uploadInfo['url']; } $this->sConn->createCommand()->update("exam_group", array("answer_path" => $pdfurl), "exam_group_id = '{$examGroupId}'"); // echo json_encode(array("success" => 1, "message" => "http://" . $_SERVER['SERVER_NAME'].$pdfurl));exit; echo json_encode(array("success" => 1, "message" => "创建成功","url"=>$pdfurl));exit; } else { @unlink($htmlpath); echo json_encode(array("success" => 0, "message" => "PDF文件未找到!"));exit; } } else { @unlink($htmlpath); echo json_encode(array("success" => 0, "message" => "PDF创建失败1!")); exit; } }else{ @unlink($htmlpath); echo json_encode(array("success" => 0, "message" => "PDF创建失败2!")); exit; } } /** * 下载pdf */ public function actionDownPdf(){ $examGroupId = safe_replace(Yii::app()->request->getQuery('examGroupId')); if(!$examGroupId){ Yii::app()->jump->error('请指定考试'); } $sql = "select eg.answer_path,e.name from exam_group eg join exam e on e.exam_group_id = eg.exam_group_id where eg.exam_group_id = '{$examGroupId}'"; $exam_info = $this->sConn->createCommand($sql)->queryRow(); // $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['answer_path']; // if ($this->check_pdf($pdfpath)) { // Header("Content-type:application/pdf"); // Header("Accept-Ranges: bytes"); // Header("Accept-Length: " . filesize($pdfpath)); // Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容 // flush();// 刷新内容 // $file=fopen($pdfpath,"r"); // $download_rate=600; // while (!feof($file)){ // set_time_limit(0); // print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者 // flush();// flush 内容输出到浏览器端 // sleep(1);// 终端1秒后继续 // } // } else { // Yii::app()->jump->error('考试不存在或尚未生成PDF'); // } if(strpos($exam_info['answer_path'],'http') !== false){ if(!fileGetContents($exam_info['answer_path'])){ Yii::app()->jump->error('考试不存在或尚未生成PDF'); }else{ $url = $exam_info['answer_path']; // 获取远程文件大小 // 注意filesize()无法获取远程文件大小 $headers = get_headers($url, 1); $fileSize = $headers['Content-Length']; //echo $fileSize;exit; // 设置header头 // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流 header('Content-Type: application/pdf'); // 告诉浏览器返回的文件大小类型是字节 header('Accept-Ranges:bytes'); // 告诉浏览器返回的文件大小 header('Content-Length: ' . $fileSize); // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称 Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容 //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据 ob_clean(); $read_buffer = 1024*1024; $handle = fopen($url, 'rb'); //总的缓冲的字节数 $sum_buffer = 0; //只要没到文件尾,就一直读取 while (!feof($handle)) { echo fread($handle, $read_buffer); ob_flush(); } fclose($handle); } }else{ Yii::app()->jump->error('考试不存在或尚未生成PDF'); } } 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 filter_file_name($filename){ return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'), array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ') , $filename); } //二轮复习个性化提分手册列表 public function actionReview(){ Url::clean(); $data = array(); $printName = Req::get("name"); $classId = Req::get("classId"); $grade = (int)Req::get("grade"); $newCondition = array(); if($grade){ $newCondition[] = 'mrs.grade='.$grade; } if($printName){ $newCondition[] = 'mrs.name like "%'.$printName.'%"'; } if($classId){ $newCondition[] = 'mrs.class_id='.$classId; } $resultList = $this->schoolManager->getMathWeek($newCondition,array('mrs.create_time desc','mrs.mr_id desc')); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k]=$v; } } if (empty($grade)) { $grade = 'ALL'; } $classes = $this->schoolManager->getClasses($grade); $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data['printList'] = $printList; $data["printName"] = $printName; $data["classes"] = $classes; $data["classId"] = $classId; $data["grade"] = $grade; $this->render('review',$data); } //二轮复习个性化提分手册设置 public function actionReviewSetting(){ $data = array(); $result = $this->apiPost('all_knowledge/point',array()); $data['special_arr']=$result; $this->render('review_setting',$data); } //保存二轮复习个性化提分手册设置 public function actionAjaxSaveMathReview(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=(int)Req::post('grade'); $createType = (int)Req::post('createType'); $classIds = Req::post('selectClassIds'); $itemIds = (array)Req::post('selectedItemIds'); $special = (int)Req::post('special'); $specialName = Req::post('specialName'); $isNewVersion = (int)Req::post('isNewVersion');//新版本为1,旧版本默认为0 if($createType==1){ //自动,读取专题下所有考点 $result = $this->apiPost('all_knowledge/point',array('specialIds'=>array($special))); $itemIds=array(); if($result){ foreach ($result as $item){ if($item['kps']){ foreach ($item['kps'] as $kp){ if($kp['methods']){ foreach ($kp['methods'] as $method){ $itemIds[]=$method['method_id']; } } } } } } } if(!$itemIds){ $error[] = '请选择专项'; } if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } } if(!$error){ $time = time(); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ $mrGroupId = getUniqueId($this->schoolId); $mrIds=array(); foreach($classIds as $k=>$v){ $mathName = $specialName; $mrId=getUniqueId($this->schoolId); $mrIds[]=$mrId; $this->sConn->createCommand()->insert('math_review_setting',array( 'mr_group_id' =>$mrGroupId, 'mr_id' => $mrId, 'special_id' => $special, 'name' => $mathName, 'semester_id' => $this->semesterId, 'grade' => $grade, 'class_id' => $v, 'is_all_html' => 0, 'method_ids' => implode(',',$itemIds), 'create_type' => $createType, 'create_time' => $time, 'is_new_version' => $isNewVersion, )); //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); if($stuData){ foreach($stuData as $kk=>$vv){ $this->sConn->createCommand()->insert('math_review_student',array( 'mr_id' => $mrId, 'student_id' => $vv['student_id'], 'create_time'=>$time )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ //发消息 if($isNewVersion){ $kafkaData=array( 'school_id'=>$this->schoolId, 'msg_type'=>90,//1-完成阅卷,2-发送标注,3-点代办,90-重置 产品生成说写90 'grade'=>$grade, 'subject_id'=>3, 'send_type'=>'math_review', 'product_type'=>17, 'gp_group_id'=>$mrGroupId, 'gp_ids'=>array_unique($mrIds), ); sendDataToKafka("php-product-math-review-html",$kafkaData); } echo json_encode(array('status'=>1));exit; } } //选择学生二轮复习个性化提分手册 public function actionSelectStuByMath(){ $data = array(); $sname = (string)Req::get("sname"); //学生名字 $mrId = (string)Req::get("mrId"); if(!$mrId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from math_review_setting ew join class c on ew.class_id = c.class_id where ew.mr_id = '{$mrId}'"; $names = $this->sConn->createCommand($sql)->queryRow(); if(!$names){ $names = array(); $names['name'] = ''; $names['class_name'] = ''; $names['grade'] = 0; }else{ $data['name'] = isset($names['name'])?$names['name']:''; } $sql = "select student_id,is_review_pdf from math_review_student where mr_id = '{$mrId}'"; $relateStudent = $this->sConn->createCommand($sql)->queryAll(); $studentIds = array(); $stuIsPdf = array(); if($relateStudent){ foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_review_pdf']; } } if($studentIds){ $studentNames = SStudentInfo::model()->getStudents($studentIds); //求学生名字 if($studentNames){ if($sname){ $i = 1; foreach($studentNames as $k=>$v){ if(strpos($v['realname'],$sname) !== false){ $data['list'][$i]['stu_id'] = (string)$v['student_id']; $data['list'][$i]['stu_name'] = $v['realname']; $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0; switch($v['level']){ case 1: $data['list'][$i]['level'] = '尖子生'; break; case 2: $data['list'][$i]['level'] = '尖子生'; break; case 3: $data['list'][$i]['level'] = '中等生'; break; case 4: $data['list'][$i]['level'] = '学困生'; break; default: $data['list'][$i]['level'] = '无'; } $i++; } } }else{ $i = 1; foreach($studentNames as $k=>$v){ $data['list'][$i]['stu_id'] = (string)$v['student_id']; $data['list'][$i]['stu_name'] = $v['realname']; $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0; switch($v['level']){ case 1: $data['list'][$i]['level'] = '尖子生'; break; case 2: $data['list'][$i]['level'] = '尖子生'; break; case 3: $data['list'][$i]['level'] = '中等生'; break; case 4: $data['list'][$i]['level'] = '学困生'; break; default: $data['list'][$i]['level'] = '无'; } $i++; } } } } $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$names['semester_id']."'") ->limit(1) ->query() ->read(); if($studentIds){ $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$names['class_id'], "semester"=>$code['refer_code'], "grade"=>$names['grade'], "students"=>$studentIds, "examTime"=>$names['create_time'], "classify"=>5, "subject"=>3 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ Yii::app()->jump->error($rs->errMsg); } if(!empty($rs->data)){ $data['limitstu']=array(); foreach ($rs->data as $v){ $data['limitstu'][(string)$v]=$v; } } } $data['mrId'] = $mrId; $data['sname'] = $sname; $data['printType'] = 'mrv_stu'; $this->render('review_stu',$data); } //获取设置二轮复习个性化提分手册的班级 public function actionAjaxGetClassesBySettingMath(){ $result = array(); $grade=(int)Req::post('grade'); $specialId=(int)Req::post('specialId'); //获取班级 $hasSettingClassIds = array(); $sql = "select class_id,count(*) count from math_review_setting where semester_id = '{$this->semesterId}' and special_id='{$specialId}' group by class_id"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ foreach($data as $k=>$v){ if($v['count'] > 2){ $hasSettingClassIds[] = (string)$v['class_id']; } } } if($grade){ $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ $i = 0; foreach($data as $k => $v){ $result[$i]['class_id'] = $v['class_id']; $result[$i]['class_name'] = $v['class_name']; if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){ $result[$i]['status'] = 1; }else{ $result[$i]['status'] = 0; } $i++; } } } echo json_encode($result);exit; } //下载二轮复习个性化提分手册 public function actionGetMathReviewFile(){ $mrId = (string)Req::get("mrId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$mrId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from math_review_student where mr_id = '{$mrId}' and is_review_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if($stuArr){ foreach($stuArr as $k=>$v){ $studentsIds[] = $v['student_id']; } } }else{ $studentsIds = explode(',',$studentsIds); } if(!$studentsIds || empty($studentsIds)){ echo json_encode(array("success" => 0, "message" => "无生成的学生")); exit(); } $params['mrId'] = $mrId; $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_review_setting where mr_id = '{$mrId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$msg['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$msg['class_id'], "semester"=>$code['refer_code'], "grade"=>$msg['grade'], "students"=>$studentsIds, "examTime"=>$msg['create_time'], "classify"=>5, "subject"=>3 ); if(isset($msg['school_group_id']) && $msg['school_group_id']){ $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; }else{ $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId)); if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 1; $rs = Curl::post($apiUrl."/rest/download_math_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); }else{ //更新下载时间 if($rs->success==1 || $rs->success==2){ $time = time(); if($studentsIds){ $sql = "update math_review_student set is_review_download = 1,review_download_time={$time} where mr_id = '{$mrId}' and student_id in (".implode(',',$studentsIds).")"; $this->sConn->createCommand($sql)->execute(); } } } if(isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)){ if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$msg['school_group_id'],$rs->downloadPath); } } echo json_encode($rs);exit; } 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),1); } // 释放资源 curl_close($ch); } return $result; } //编辑考试信息 public function actionModifyThirdExam(){ $exam_group_id = Req::post("examGroupId"); if(!$exam_group_id){ $exam_group_id = Req::get("exam_group_id"); } $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id)); $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id)); if(!$exam_data) { Yii::app()->jump->error('非法试卷!'); } @$tplData=json_decode($exam_data['tpl_data'],true); if(!$tplData){ Yii::app()->jump->error('非法试卷!'); } if (Yii::app()->request->getIsPostRequest()){ $type=Req::post('type'); $name=Req::post('examName'); $examDate=Req::post('examDate'); $isCustomTpl=Req::post('isCustomTpl'); $tplDataPaper=Req::post('tplDataPaper'); $printTypeCard=Req::post('printTypeCard'); $tianType=Req::post('tianType'); $jieType=Req::post('jieType'); $dtkType=Req::post('dtkType'); $tplIndex=0; if(!matchStrChar($name)){ Yii::app()->jump->error('考试名称不能包含特殊字符!'); } $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow(); if($findInfo->status==2){ $examSql="update `exam` set `name`='".$name."' "; $examSql.=" where exam_group_id='".$exam_group_id."'"; $this->sConn->createCommand($examSql)->execute(); if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){ updateExamNameToTiku($exam_group_id,$name,$this->schoolId); } $this->redirect($this->createUrl('print/index')); } //解答题大分值特殊index值 $tplIndexArrJieDa=array( 1=>array( 3=>array( //29分 1=>3016, 2=>3017, 3=>3018, 4=>3019 ), 4=>array( //49分 1=>4016, 2=>4017, 3=>4018, 4=>4019 ) ), 2=>array( 3=>array( //29分 1=>3012, 2=>3013, 3=>3014, 4=>3015 ), 4=>array( //49分 1=>4012, 2=>4013, 3=>4014, 4=>4015 ) ) ); //解答题小分值index值 $tplIndexArr=array( 1=>array( 11=>array( 1=>1016, 2=>1017, 3=>1018, 4=>1019 ), 12=>array( 1=>2016, 2=>2017, 3=>2018, 4=>2019 ), 13=>array( 1=>16, 2=>17, 3=>18, 4=>19 ) ), 2=>array( 11=>array( 1=>1012, 2=>1013, 3=>1014, 4=>1015 ), 12=>array( 1=>2012, 2=>2013, 3=>2014, 4=>2015 ), 13=>array( 1=>12, 2=>13, 3=>14, 4=>15 ) ), ); if($isCustomTpl){ if($printTypeCard){ if($jieType>2){ if(isset($tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType])){ $tplIndex=$tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType]; }else{ // Yii::app()->jump->error('编辑失败,解答题分值格式有误!'); } }else{ if(!inArray($this->schoolInfo->province_id,array(11,12))){ $tplIndex=$tplIndexArr[$printTypeCard][13][$dtkType]; }else{ if(isset($tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType])){ $tplIndex=$tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType]; } } } } //判断题量, // if (inArray($tplIndex, array(12,16,1012, 1016, 2012, 2016,3016,3012,3007,4012,4016))) { // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>90){ // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!'); // } // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>45){ // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!'); // } // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){ // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!'); // } // }else{ // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>30){ // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!'); // } // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>30){ // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!'); // } // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){ // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!'); // } // } //校验分数 $tianType=Req::post('tianType'); $jieType=Req::post('jieType'); // if($tianType){ // $maxScore=100; // if($tianType==2){ // $maxScore=5; // }elseif($tianType==3) { // $maxScore = 6; // }elseif($tianType==4){ // $maxScore = 4; // } // if(isset($tplData['items'][5]) && $tplData['items'][5]['perScores']){ // foreach($tplData['items'][5]['perScores'] as $val){ // if($val>$maxScore){ // Yii::app()->jump->error('试卷的填空题分数超出了当前选择的答题卡分数上限!'); // } // } // } // } // if($jieType){ // $maxScore=0; // if($jieType==1){ // $maxScore=15; // }elseif($jieType==2) { // $maxScore = 16; // }elseif($jieType==3){ // $maxScore = 29; // }elseif($jieType==4){ // $maxScore = 49; // } // if(isset($tplData['items'][7]) && $tplData['items'][7]['perScores']){ // foreach($tplData['items'][7]['perScores'] as $val){ // if($val>$maxScore){ // Yii::app()->jump->error('试卷的解答题分数超出了当前选择的答题卡分数上限!'); // } // } // } // } } $transaction = $this->sConn->beginTransaction(); try{ $tplData['examDate']=$examDate; if($tplDataPaper){ if($tplDataPaper==1){ $tplData['paper']=1; }else{ $tplData['paper']=0; } } if($tianType){ $tplData['tianType']=$tianType; } if($jieType){ $tplData['jieType']=$jieType; } $examSql="update `exam` set `type`='".$type."',`name`='".$name."' "; if($tplIndex){ $examSql.=" , tpl_index='".$tplIndex."'"; } $examSql.=" , tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'"; $this->sConn->createCommand($examSql)->execute(); $transaction->commit(); if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){ updateExamNameToTiku($exam_group_id,$name,$this->schoolId); } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '编辑考试', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } $this->redirect($this->createUrl('print/index')); }catch(Exception $e){ $transaction->rollBack(); Yii::app()->jump->error('编辑失败!'); } } $a3=array(12,16,1012,1016,2012,2016,3012,3016,4012,4016); $a4=array(13,17,1013,1017,2013,2017,3013,3017,4013,4017); $k8=array(14,18,1014,1018,2014,2018,3014,3018,4014,4018); $k16=array(15,19,1015,1019,2015,2019,3015,3019,4015,4019); if(in_array($exam_data['tpl_index'], Yii::app()->params['custom_tpls_ids'])){ //自定义模板 $data['is_custom_tpl'] = 1; }else{ //非自定义模板 $data['is_custom_tpl'] = 0; } if (in_array($exam_data['tpl_index'], Yii::app()->params['no_template_id']) ) { //题卡分离 $data['paper_tpl_type'] = 2; }else{ $data['paper_tpl_type'] = 1; } $data['dtkType']=0; $data['dtk']=''; if(in_array($exam_data['tpl_index'], $a3)){ $data['dtk']='A3'; $data['dtkType']=1; }elseif(in_array($exam_data['tpl_index'], $a4)){ $data['dtk']='A4'; $data['dtkType']=2; }elseif(in_array($exam_data['tpl_index'], $k8)){ $data['dtk']='8k'; $data['dtkType']=3; }elseif(in_array($exam_data['tpl_index'], $k16)){ $data['dtk']='16k'; $data['dtkType']=4; } $data['examGroupId']=$exam_group_id; $data['createType']=$findInfo->create_type; $data['name']=$exam_data['name']; $data['markType']=$findInfo->mark_type; $data['paperType']=$exam_data['tpl_index']; $data['type']=$exam_data['type']; $data['paper']=$tplData['paper']; $data['examDate']=$tplData['examDate']; $data['qxkPaperId']=$findInfo->qxk_paper_id; $data['examStatus']=$findInfo->status; if(isset($tplData['tianType'])){ $data['tianType']=$tplData['tianType']; }else{ $data['tianType']=''; } if(isset($tplData['jieType'])){ $data['jieType']=$tplData['jieType']; }else{ $data['jieType']=''; } $data['subjectId']=$exam_data['subject_id']; $this->render('modify_exam',$data); } //在线答题卡批量下载 public function actionDownloadOnlineBatch(){ $exam_id = Req::post("exam_id"); $student_id = Req::post("student_id"); $result['status']=0; if(!$exam_id ) { echo json_encode(array("status"=>0,"result"=>"参数不能为空")); } if(empty($student_id) ) { echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生")); } $studentIds = explode(',',$student_id); foreach ($studentIds as $v) { if($v) { $student_ids[] = $v; } } $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' and student_id in(".implode(',',$student_ids).")")->queryAll(); if($studentPdf){ ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id)); $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); //读取班级 $class=SClass::model()->find('class_id=:class_id',array(':class_id'=>$exam_data['class_id'])); $thirdAnswerSheet=$this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$exam_data['exam_group_id']}' ")->queryRow(); if($thirdAnswerSheet['multiplex_id']){ $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time=".time()." where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->execute(); } //$tmpFile = tempnam('/tmp', ''); // $zipFileNameNew=$exam_data['name'].'-'.$class['class_name'].'.zip'; $zipFileName=$exam_id.'.zip'; $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j'); if(!is_dir($dirFile)){ $this->mkdir($dirFile); } $dirFile.='/'.$zipFileName; if(file_exists($dirFile)){ unlink($dirFile); } $zip = new ZipArchive; $zip->open($dirFile, ZipArchive::CREATE); foreach ($studentPdf as $val) { // download file // $fileContent = file_get_contents($file); if($val['answer_card_online_url']){ $file=$val['answer_card_online_url']; $fileUrl=$file.'?r='.mt_rand(1,999); $fileContent=fileGetContents($fileUrl); $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent); } } $zip->close(); $result['status']=1; $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile; exit(json_encode($result)); }else{ $result['result']='答题卡尚未生成'; exit(json_encode($result)); } } //在线答题卡班级下载 public function actionDownloadOnlineClass(){ $exam_id = Req::post("exam_id"); if(!$exam_id ) { Yii::app()->jump->error('参数错误!'); } $result['status']=0; if(!$exam_id ) { echo json_encode(array("status"=>0,"result"=>"参数不能为空")); } $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' ")->queryAll(); if($studentPdf){ $files=array(); foreach ($studentPdf as $value){ $files[]=$value['answer_card_online_url']; } ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id)); //$tmpFile = tempnam('/tmp', ''); $zipFileName=$exam_id.'.zip'; $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j'); if(!is_dir($dirFile)){ $this->mkdir($dirFile); } $dirFile.='/'.$zipFileName; if(file_exists($dirFile)){ unlink($dirFile); } $zip = new ZipArchive; $zip->open($dirFile, ZipArchive::CREATE); foreach ($studentPdf as $val) { if($val['answer_card_online_url']){ $file=$val['answer_card_online_url']; $fileUrl=$file.'?r='.mt_rand(1,999); $fileContent=fileGetContents($fileUrl); $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent); } } $zip->close(); $result['status']=1; $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile; exit(json_encode($result)); }else{ $result['result']='班级答题卡尚未生成'; exit(json_encode($result)); } } //发送生成在线答题卡任务(班级) public function actionSendCreateOnline(){ $examId=Req::post('exam_id'); $result['status']=0; if(!$examId || !is_numeric($examId)){ $result['msg']='参数不正确'; exit(json_encode($result)); } $examInfo = Exam::model()->findByPk($examId); if(!$examInfo){ $result['msg']='未找到考试信息'; exit(json_encode($result)); } $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id); if(!$onlineCard){ $result['msg']='考试还没有使用在线答题卡'; exit(json_encode($result)); } $arr=array( 'schoolId'=>$this->schoolId, 'examId'=>$examId, 'examGroupId'=>$examInfo->exam_group_id, 'savedInfoUrl'=>$onlineCard['file_path'], 'isClassTask'=>1 ); $url=Yii::app()->params['answerCardOnlineCreateUrl'].'classesTopdf'; $ch = @curl_init(); $return=array(); if ($ch) { $data = json_encode($arr); // 不输出头部 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)) { $return = json_decode(curl_exec($ch),1); } curl_close($ch); } if(isset($return['code']) && $return['code']==1){ $result['status']=1; $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='".$examId."' ")->execute(); }elseif($return['code']==2){ $result['msg']='任务队列已存在该任务'; }elseif(isset($return['msg'])){ $result['msg']=$return['msg']; } exit(json_encode($result)); } //发送生成在线答题卡任务(学生) public function actionSendCreateOnlineStudents(){ $examId=Req::post('exam_id'); $students=Req::post('students'); $className=Req::post('class_name'); $checkOrder=Req::post('check_order'); //是否检查订单 $result['status']=0; if(!$examId || !is_numeric($examId)){ $result['msg']='参数不正确'; exit(json_encode($result)); } if($checkOrder){ //检查订单 $orderClass=0; if(!$students){ $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll(); if($allClassStudents){ foreach ($allClassStudents as $student){ $students[]=$student['student_id']; if(!$orderClass) $orderClass=$student['class_id']; } } } $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass)); $subjectId=Yii::app()->session['session_subject_id']; if(in_array($subjectId,$this->mathSubjectId)){ $subjectId=3; } $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$orderClass, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>time(), "classify"=>1, "subject"=>$subjectId, ); $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students); if(!$students){ $result['msg']='当前班级没查询到订单'; exit(json_encode($result)); } } if(!$students || !is_array($students)){ $result['msg']='请选择要生成的学生'; exit(json_encode($result)); } $examInfo = Exam::model()->findByPk($examId); if(!$examInfo){ $result['msg']='未找到考试信息'; exit(json_encode($result)); } $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id); if(!$onlineCard){ $result['msg']='考试还没有使用在线答题卡'; exit(json_encode($result)); } $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id='{$examId}' and is_del=0 and student_id in(".implode(',',$students).")")->queryAll(); if($postStudents){ foreach ($postStudents as $key =>$val){ $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow(); $postStudents[$key]['student_name']=$studentInfo['realname']; $postStudents[$key]['class_name']=$className; if($examInfo->school_card_status==1){ $postStudents[$key]['student_card']=$val['school_student_card']; } } } $error=array(); if(count($postStudents)>100){ $newPushArr=array(); $newPushArr=array_chunk($postStudents,100); foreach ($newPushArr as $item){ $arr=array( 'schoolId'=>$this->schoolId, 'examId'=>$examId, 'examGroupId'=>$examInfo->exam_group_id, 'savedInfoUrl'=>$onlineCard['file_path'], 'students'=>$item, 'groupId'=>$this->schoolGroupId, 'qrcode'=>$onlineCard['is_qrcode_online'], 'semesterId'=>$this->semesterId ); $key='zsyas2-online-card-notify'; $return=sendDataToKafka($key,$arr); $updateStudentId=array(); $updateStudentName=array(); foreach ($item as $v){ $updateStudentId[]=$v['student_id']; $updateStudentName[]=$v['student_name']; } if($return){ $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $updateStudentId) . ") ")->execute(); }else{ $error=array_merge($error,$updateStudentName); //$result['msg']='发送任务失败'; } } if($error){ $result['status'] = 1; $result['msg'] = '部分学生发送失败'; }else{ $result['status'] = 1; } }else{ $arr=array( 'schoolId'=>$this->schoolId, 'examId'=>$examId, 'examGroupId'=>$examInfo->exam_group_id, 'savedInfoUrl'=>$onlineCard['file_path'], 'students'=>$postStudents, 'groupId'=>$this->schoolGroupId, 'qrcode'=>$onlineCard['is_qrcode_online'], 'semesterId'=>$this->semesterId ); $key='zsyas2-online-card-notify'; $return=sendDataToKafka($key,$arr); if($return){ $result['status'] = 1; $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $students) . ") ")->execute(); }else{ $result['msg']='发送任务失败'; } } $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute(); $this->schoolManager->saveExamProcess($examInfo->exam_group_id,13,time(),$examId,$examInfo->class_id); exit(json_encode($result)); } //发送生成在线答题卡任务(全部学生) public function actionSendCreateOnlineAllStudents(){ $examGroupId=Req::post('exam_group_id'); $result['status']=0; if(!$examGroupId || !is_numeric($examGroupId)){ $result['msg']='参数不正确'; exit(json_encode($result)); } $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); $examIds = array(); $examClass=array(); if($exam_data) { foreach ($exam_data as $val) { $examIds[] = $val['exam_id']; $examClass[$val['exam_id']]=$val['class_id']; } } if(!$examIds){ $result['msg']='未找到考试信息'; exit(json_encode($result)); } $onlineCard=$this->schoolManager->getAnswerSheetOnline($examGroupId); if(!$onlineCard){ $result['msg']='考试还没有使用在线答题卡'; exit(json_encode($result)); } $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0 ")->queryAll(); if($postStudents){ foreach ($postStudents as $key =>$val){ $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow(); $postStudents[$key]['student_name']=$studentInfo['realname']; $classInfo=$this->sConn->createCommand("select `class_name` from class where class_id='{$val['class_id']}'")->queryRow(); $postStudents[$key]['class_name']=$classInfo['class_name']; if($exam_data[0]['school_card_status']==1){ $postStudents[$key]['student_card']=$val['school_student_card']; } } } $error=array(); if(count($postStudents)>100){ $newPushArr=array(); $newPushArr=array_chunk($postStudents,100); foreach ($newPushArr as $item){ $arr=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'savedInfoUrl'=>$onlineCard['file_path'], 'students'=>$item, 'groupId'=>$this->schoolGroupId, 'qrcode'=>$onlineCard['is_qrcode_online'], 'semesterId'=>$this->semesterId ); $key='zsyas2-online-card-notify'; $return=sendDataToKafka($key,$arr); $updateStudentId=array(); $updateStudentName=array(); foreach ($item as $v){ $updateStudentId[]=$v['student_id']; $updateStudentName[]=$v['student_name']; } if($return){ $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") and student_id in(" . implode(',', $updateStudentId) . ") ")->execute(); $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute(); }else{ $error=array_merge($error,$updateStudentName); //$result['msg']='发送任务失败'; } } if($error){ $result['status'] = 1; $result['msg'] = '部分学生发送失败'; exit(json_encode($result)); }else{ $result['status'] = 1; exit(json_encode($result)); } }else{ $arr=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'savedInfoUrl'=>$onlineCard['file_path'], 'students'=>$postStudents, 'groupId'=>$this->schoolGroupId, 'qrcode'=>$onlineCard['is_qrcode_online'], 'semesterId'=>$this->semesterId ); $key='zsyas2-online-card-notify'; $return=sendDataToKafka($key,$arr); if($return){ $result['status'] = 1; $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") ")->execute(); $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute(); }else{ $result['msg']='发送任务失败'; } } foreach ($examClass as $examId =>$classId){ $this->schoolManager->saveExamProcess($examGroupId,13,time(),$examId,$classId); } exit(json_encode($result)); } // // 更新试卷在线答题卡打印状态、时间 public function actionUpdateOnlinePaperPrintTime() { $cid = Req::post("cid"); $eid = Req::post("eid"); $type = Req::post("type"); $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type)); if (!empty($getResult)) { $getResult->is_print_online = 1; if ($getResult->save()) { exit('1'); } else { exit('2'); } } } //客户端打印在线答题卡 public function actionPrintPdfOnline(){ $examId=Req::post('exam_id'); $students=Req::post('students'); $className=Req::post('class_name'); $checkOrder=Req::post('check_order'); $result['success']=0; if(!$examId || !is_numeric($examId)){ $result['msg']='参数不正确'; exit(json_encode($result)); } $examInfo = Exam::model()->findByPk($examId); if(!$examInfo){ $result['msg']='未找到考试信息'; exit(json_encode($result)); } $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id); if(!$onlineCard){ $result['msg']='考试还没有使用在线答题卡'; exit(json_encode($result)); } if($checkOrder){ //检查订单 $orderClass=0; if(!$students){ $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll(); if($allClassStudents){ foreach ($allClassStudents as $student){ $students[]=$student['student_id']; if(!$orderClass) $orderClass=$student['class_id']; } } } $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass)); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$orderClass, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>time(), "classify"=>1, "subject"=>3, ); $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students); } if(!$students || !is_array($students)){ $students=array(); $studentPaperRelation=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id='".$examId."' and is_del=0 ")->queryAll(); if($studentPaperRelation){ foreach ($studentPaperRelation as $val){ $students[]=$val['student_id']; } } } if(!$students){ $result['msg']='考试班级没有学生'; exit(json_encode($result)); } $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll(); $studentData=array(); if($studentPdf){ foreach ($studentPdf as $val){ $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow(); $studentData[]=array( 'studentName'=>$studentInfo['realname'], 'studentCode'=>$val['student_id'], 'pdfUrl'=>$val['answer_card_online_url'] ); } }else{ $result['msg']='答题卡还未生成'; exit(json_encode($result)); } $result['success']=1; $result['className']=$className; $result['students']=$studentData; $result['studentIds']=$students; exit(json_encode($result)); } /** * 英语外刊阅读列表 */ public function actionEnglish_reading(){ Url::clean(); $data = array(); $printName = Req::get("name"); $classId = Req::get("classId"); $grade = (int)Req::get("grade"); $cg = (int)Req::get('cg'); $pt = (int)Req::get('pt'); if(!$cg) $cg=1; $newCondition = array(); if($grade){ $newCondition[] = 'er.grade='.$grade; } if($printName){ $newCondition[] = 'er.name like "%'.$printName.'%"'; } if($classId){ $newCondition[] = 'er.class_id='.$classId; } $newCondition[] = 'ers.category='.$cg; if($cg==2){ $newCondition[] = 'ers.product_type='.$pt; } $resultList = $this->schoolManager->getEnglishReading($newCondition,array('er.create_time desc','er.week_id desc'),9); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $isTeacher=false; //仅经典模式中,基础宝、外刊宝-共性外刊、热点宝-共性外刊有教师讲义 if($v['recommend_mode']==1 && (($v['product_type']==1) || (in_array($v['product_type'],array(2,3)) && $v['type']==2)) ){ $isTeacher=true; } $v['is_teacher']=$isTeacher; $printList[$k]=$v; } } if (empty($grade)) { $grade = 'ALL'; } $classes = $this->schoolManager->getClasses($grade); $data['pages'] = $resultList['pager']; $data['page_total'] = $resultList['pager']->rowsCount; $data['printList'] = $printList; $data["printName"] = $printName; $data["classes"] = $classes; $data["classId"] = $classId; $data["grade"] = $grade; $data['printType'] = 'mrv'; $data['category'] = $cg; $data['eProductType'] = $pt; //debug($printList); $this->render('english_reading',$data); } /** * 英语外刊阅读高一高二设置 */ public function actionEnglishReadingSetting(){ $data = array(); $time = time(); // $data['year'] = $year = date("Y"); // $data['month'] = $month = (int)date("m"); // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $data_msg = $this->getWeekOnMonth(); $data['year'] = $data_msg['year']; $data['month'] = $data_msg['month']; $data['week'] = numToUpper($data_msg['week']); $textboookTree = new MongodbEnglishTree(); $criteria = new EMongoCriteria(); $textbookData = $textboookTree->find($criteria,array()); if($textbookData){ foreach ($textbookData as $doc) { foreach($doc->attributes as $key => $value){ if($key !== '_id'){ if(isset($value['textbook_id']) && isset($value['name'])){ $data['textbookNames'][$value['textbook_id']] = $value['name']; if(!isset($textbookId)){ $textbookId = $value['textbook_id']; } if($textbookId == $value['textbook_id']){ if(isset($value['module']) && $value['module']){ foreach($value['module'] as $kk=>$vv){ $data['moduleNames'][$vv['textbook_module_id']] = $vv['name']; if(!isset($moduleId)){ $moduleId = $vv['textbook_module_id']; } if($moduleId == $vv['textbook_module_id']){ if(isset($vv['unit']) && $vv['unit']){ foreach($vv['unit'] as $kkk=>$vvv){ $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name']; } } } } } } } } } } } $data['printType'] = 'english_reading_setting'; $this->render('english_reading_setting',$data); } /** * 设置英语外刊阅读高一高二 */ public function actionAjaxSaveEnglishReading(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=(int)Req::post('grade'); $textbookId = (int)Req::post('textbookId'); $moduleId = (int)Req::post('moduleId'); $unitId = (int)Req::post('unitId'); $moduleName = (string)Req::post('moduleName'); $unitName = (string)Req::post('unitName'); $classIds = Req::post('selectClassIds'); $itemIds = (array)Req::post('selectedItemIds'); $type = (int)Req::post('type'); $level = (int)Req::post('level'); $isAnswerSeparate = (int)Req::post('isAnswerSeparate'); if($itemIds && ($textbookId || $moduleId || $unitId)){ $error[] = '设置错误1'; } if(!$itemIds && (!$textbookId || !$moduleId || !$unitId)){ $error[] = '设置错误2'; } if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } if(!in_array($type,array(1,2))){ $error[] = '外刊类别错误'; } if($type == 2){ if(!in_array($level,array(1,2,3))){ $error[] = '外刊分级错误'; } } } if(!$error){ $time = time(); // $month = (int)date("m"); // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; // $week = date("W"); // $year = date("Y"); $date_msg = $this->getWeekOnMonth(); $year = $date_msg["year"]; $month = $date_msg["month"]; $week = $date_msg["week"]; $weekUpper = numToUpper($week); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"'; $reading_id = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('english_reading_setting',array( 'reading_id'=>$reading_id, 'grade' => $grade, 'semester_id' => $this->semesterId, 'textbook_id' => $textbookId, 'module_id' => $moduleId, 'unit_id' => $unitId, 'special_ids' => implode(',',$itemIds), 'create_time' => $time, 'type' => $type, 'level'=>$level, 'is_answer_separate'=>$isAnswerSeparate )); foreach($classIds as $k=>$v){ $weekId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('english_reading',array( 'week_id' => $weekId, 'name' => $weekName, 'class_id' => $v, 'grade' => $grade, 'semester_id' => $this->semesterId, 'year_num' => $year, 'week_num' => $week, 'month_num' => $month, 'reading_id'=>$reading_id, 'create_time' => $time, )); //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); if($stuData){ foreach($stuData as $kk=>$vv){ $this->sConn->createCommand()->insert('english_reading_student',array( 'week_id' => $weekId, 'student_id' => $vv['student_id'], )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ echo json_encode(array('status'=>1));exit; } } /** * 外刊主题语境(高三) */ public function actionEnglishReading3(){ $data = array(); $time = time(); $theme_context = array(); // $data['year'] = $year = date("Y"); // $data['month'] = $month = (int)date("m"); // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; $data_msg = $this->getWeekOnMonth(); $data['year'] = $data_msg['year']; $data['month'] = $data_msg['month']; $data['week'] = numToUpper($data_msg['week']); $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3)); if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){ $i = 0; foreach($theme_context_data['data'] as $k=>$v){ if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){ $theme_context[$i]['label_id'] = $v['label_id']; $theme_context[$i]['content'] = $v['content']; $i++; } } } $data['theme_context'] = $theme_context; $data['printType'] = 'englishreading3'; $this->render('english_reading_3',$data); } /** * 外刊时间有限设置 */ public function actionEnglishReadingTime(){ $data = array(); $theme_context = array(); $data_msg = $this->getWeekOnMonth(); $data['year'] = $data_msg['year']; $data['month'] = $data_msg['month']; $data['week'] = numToUpper($data_msg['week']); // $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3)); // if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){ // $i = 0; // foreach($theme_context_data['data'] as $k=>$v){ // if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){ // $theme_context[$i]['label_id'] = $v['label_id']; // $theme_context[$i]['content'] = $v['content']; // $i++; // } // } // } // $data['theme_context'] = $theme_context; $data['printType'] = 'englishreadingtime'; $this->render('english_reading_time',$data); } /** * 外刊时间优先推送设置 */ public function actionAjaxSaveReadingTime(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=(int)Req::post('grade'); $classIds = Req::post('selectClassIds'); $type = (int)Req::post('type'); $level = (int)Req::post('level'); $isAnswerSeparate = (int)Req::post('isAnswerSeparate'); if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } if(!in_array($type,array(1,2))){ $error[] = '外刊类别错误'; } if($type == 2){ if(!in_array($level,array(1,2,3))){ $error[] = '外刊分级错误'; } } } if(!$error){ $time = time(); $date_msg = $this->getWeekOnMonth(); $year = $date_msg["year"]; $month = $date_msg["month"]; $week = $date_msg["week"]; $weekUpper = numToUpper($week); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"'; $reading_id = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('english_reading_setting',array( 'reading_id'=>$reading_id, 'grade' => $grade, 'semester_id' => $this->semesterId, 'textbook_id' => 0, 'module_id' => 0, 'unit_id' => 0, 'special_ids' => '', 'create_time' => $time, 'type' => $type, 'level'=>$level, 'is_answer_separate'=>$isAnswerSeparate, 'is_time_priority' => 1 )); foreach($classIds as $k=>$v){ $weekId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('english_reading',array( 'week_id' => $weekId, 'name' => $weekName, 'class_id' => $v, 'grade' => $grade, 'semester_id' => $this->semesterId, 'year_num' => $year, 'week_num' => $week, 'month_num' => $month, 'reading_id'=>$reading_id, 'create_time' => $time, )); //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); if($stuData){ foreach($stuData as $kk=>$vv){ $this->sConn->createCommand()->insert('english_reading_student',array( 'week_id' => $weekId, 'student_id' => $vv['student_id'], )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ echo json_encode(array('status'=>1));exit; } } /* * 获取外刊美文产品班级 */ public function actionAjaxGetClassesBySettingReading(){ $grade=(int)Req::post('grade'); $result=$this->getClassesBySettingReading($grade); echo json_encode($result);exit; } /* * 获取外刊美文产品班级 */ public function getClassesBySettingReading($grade=1,$gc=1,$pt=1){ $result = array(); $error = array(); //$grade=(int)Req::post('grade'); // $year = date("Y"); // $month = (int)date("m"); // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1; // $week = date("W"); $data_msg = $this->getWeekOnMonth(); $year = $data_msg['year']; $month = $data_msg['month']; $week = $data_msg['week']; //获取班级 $hasSettingClassIds = array(); $sql="select class_id,count(*) as count from english_reading er"; $sql.=" left join english_reading_setting ers on er.reading_id= ers.reading_id "; $sql.=" where year_num = {$year} and week_num = {$week} and month_num = {$month} "; if($gc==1){ $sql.=" and ers.category=1"; }else{ $sql.=" and ers.category=2 and product_type='{$pt}'"; } $sql.=" group by class_id"; //$sql = "select class_id,count(*) count from english_reading where year_num = {$year} and week_num = {$week} and month_num = {$month} group by class_id"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ foreach($data as $k=>$v){ if($v['count'] > 0){ $hasSettingClassIds[] = (string)$v['class_id']; } } } if($grade){ //先判断是否走班 $zouban_sql = "select * from classified where subject_id = 8 and semester_id = '{$this->semesterId}' and grade = {$grade} and `status` = 1"; $classified_data = $this->sConn->createCommand($zouban_sql)->queryRow(); if($classified_data){ $is_zouban = 1; $class_type = 2; $sql = "select c.class_id,c.class_name " . "from class c join class_subject_relation csr on c.class_id=csr.class_id " . "where c.semester_id='{$this->semesterId}' and csr.subject_id = 8 and c.grade = {$grade} and c.class_type = 2 and c.is_hide=0 group by c.class_id"; }else{ $is_zouban = 0; $class_type = 1; $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0"; } // $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = {$class_type} and is_hide=0"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ $i = 0; foreach($data as $k => $v){ $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0"; $class_student = $this->sConn->createCommand($sql)->queryRow(); if($class_student && $class_student['count']>0){ $result[$i]['class_id'] = $v['class_id']; $result[$i]['class_name'] = $v['class_name']; if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){ $result[$i]['status'] = 1; }else{ $result[$i]['status'] = 0; } $i++; } } } } return $result; } /** * 下载外刊美文个性化学习宝 */ public function actionGetEnglishReadingFile(){ $weekId = (string)Req::get("weekId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$weekId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from english_reading_student where week_id = '{$weekId}' and is_week_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if($stuArr){ foreach($stuArr as $k=>$v){ $studentsIds[] = $v['student_id']; } } }else{ $studentsIds = explode(',',$studentsIds); } if(!$studentsIds || empty($studentsIds)){ echo json_encode(array("success" => 0, "message" => "无生成的学生")); exit(); } $params['weekId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from english_reading where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$msg['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$msg['class_id'], "semester"=>$code['refer_code'], "grade"=>$msg['grade'], "students"=>$studentsIds, "examTime"=>$msg['create_time'], "classify"=>6, "subject"=>8 ); $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId)); if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 3; $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); }else{ //更新下载时间 if($rs->success==1 || $rs->success==2){ $time = time(); if($studentsIds){ $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).") and week_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } } } // if(isset($rs->downloadPath)){ // if (YII_ENV == 'pro' || YII_ENV == 'production') { // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath); // } // } echo json_encode($rs);exit; } /** * 获取当天是第几周(按周一计算) */ public function getWeekOnMonth(){ $a = time(); $monDay = $a - ((date('w',$a) == 0 ? 7 : date('w',$a)) - 1) * 24 * 3600;//当前时间周一的时间 $a_month = date('n',$monDay);//当前周一月份 $a_year = date('Y',$monDay);//当前周一年份 $date_now=date('j',$monDay); //得到周一是几号 $cal_result=ceil($date_now/7); //计算是第几周 return array("year"=>$a_year,"month"=>$a_month,"week"=>$cal_result); } /** * 重置外刊美文 */ public function actionResetEnglishReading(){ $readingId = (string)Req::get("readingId"); $data = array(); $resetCount = 0; $productName=''; if($readingId){ $sql = "select er.week_id,er.`name`,er.class_id,er.is_reset,c.class_name,ers.product_type,ers.category from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.reading_id = '{$readingId}'"; $msg = $this->sConn->createCommand($sql)->queryAll(); if($msg){ $i=0; foreach($msg as $k=>$v){ if($v["is_reset"]){ $resetCount++; } if(!$productName){ if($v['category']==2){ if($v['product_type']==1){ $productName='基础宝'; }elseif($v['product_type']==2){ $productName='外刊宝'; }elseif($v['product_type']==3){ $productName='热点宝'; } }else{ $productName='外刊宝'; } } $weekId = $v["week_id"]; $data[$i]['total_count'] = 0; $data[$i]['create_count'] = 0; $data[$i]['name'] = $v["name"]; $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_reading_student where week_id = '{$weekId}'"; $msg_student = $this->sConn->createCommand($sql)->queryRow(); if($msg_student){ $data[$i]['total_count'] = $msg_student["total_count"]; $data[$i]['create_count'] = $msg_student["create_count"]; } $data[$i]['week_id'] = $weekId; $data[$i]['class_name'] = $v["class_name"]; $data[$i]['is_reset'] = $v["is_reset"]; $i++; } } } if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){ $resetCount = 0; } // debug($data); $this->render('english_reading_reset',array("data"=>$data,"resetCount"=>$resetCount,"readingId"=>$readingId,'productName'=>$productName)); } /** * 重置外刊美文功能 */ public function actionAjaxResetEnglishReading(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $classExam=Req::post('classExam'); if(!$classExam || !is_array($classExam)){ $error[] = '请选择班级'; } $redingId=Req::post('readingId'); if(!$redingId){ $error[] = '请刷新后再尝试'; } } if(!$error){ $time = time(); $transaction = $this->sConn->beginTransaction(); try{ $sql = "select reading_id,week_id,is_new_version,grade from english_reading where reading_id='{$redingId}' and week_id in (".implode(',',$classExam).")"; $englishReading = $this->sConn->createCommand($sql)->queryAll(); if(!$englishReading){ throw new Exception('无重置外刊阅读推送数据'); } $this->sConn->createCommand("update english_reading set is_all_html = 0,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute(); //重置时common_topic:班级间相同的共性数据 更新为空 $this->sConn->createCommand("update english_reading_setting set common_topic = '' where reading_id='{$redingId}'")->execute(); $sql = "update english_reading_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") "; $this->sConn->createCommand($sql)->execute(); //重置后清除已存在的下载任务 $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=10"; $this->conn->createCommand($task_sql)->execute(); $weekIds=array(); $grade=0; foreach($englishReading as $item){ if($item['is_new_version']){ $weekIds[]=$item['week_id']; $grade=$item['grade']; } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ echo json_encode(array('status'=>0,'error'=>$error));exit; }else{ //新设置重置才发消息 if($weekIds && $grade) { $kafkaData = array( 'school_id' => $this->schoolId, 'msg_type' => 90,//90:重置 1:新设置 'grade' => $grade, 'subject_id' => 8, 'send_type' => 'english_reading', 'product_type' => array(19), 'gp_group_id' => $redingId,//reading_id 'gp_ids' => $weekIds,//week_id ); sendDataToKafka("php-product-english-reading-html", $kafkaData); } echo json_encode(array('status'=>1));exit; } } /** * 外刊美文选择学生 */ public function actionSelectStuByEnglishReading(){ $data = array(); $sname = (string)Req::get("sname"); //学生名字 $weekId = (string)Req::get("weekId"); if(!$weekId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select er.name,c.class_name,er.grade,er.class_id,er.create_time,er.semester_id,ers.category,ers.product_type from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.week_id = '{$weekId}'"; $names = $this->sConn->createCommand($sql)->queryRow(); if(!$names){ $names = array(); $names['name'] = ''; $names['class_name'] = ''; $names['grade'] = 0; }else{ $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:''; } $sql = "select student_id,is_week_pdf,product_type from english_reading_student where week_id = '{$weekId}'"; $relateStudent = $this->sConn->createCommand($sql)->queryAll(); $studentIds = array(); $stuIsPdf = array(); if($relateStudent){ foreach ($relateStudent as $studentInfo) { $studentIds[] = (string)$studentInfo['student_id']; $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf']; $productTypeName=''; if($studentInfo['product_type']==1){ $productTypeName='基础宝'; }elseif($studentInfo['product_type']==2){ $productTypeName='外刊宝'; }elseif($studentInfo['product_type']==3){ $productTypeName='热点宝'; } $productTypeNames[(string)$studentInfo['student_id']] = $productTypeName; } } if($studentIds){ $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字 if($studentNames){ if($sname){ $i = 1; foreach($studentNames as $k=>$v){ if(strpos($v,$sname) !== false){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:''; $i++; } } }else{ $i = 1; foreach($studentNames as $k=>$v){ $data['list'][$i]['stu_id'] = (string)$k; $data['list'][$i]['stu_name'] = $v; $data['list'][$i]['name'] = $names['class_name'].$v.$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0; $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:''; $i++; } } } } $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$names['semester_id']."'") ->limit(1) ->query() ->read(); $classify=6; if($names['category']==2){ if($names['product_type']==1){ $classify=57; }elseif($names['product_type']==2){ $classify=61; }elseif($names['product_type']==3){ $classify=58; } } $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$names['class_id'], "semester"=>$code['refer_code'], "grade"=>$names['grade'], "students"=>$studentIds, "examTime"=>$names['create_time'], "classify"=>$classify, "subject"=>8 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic)); if(!$rs){ Yii::app()->jump->error("接口错误"); } if($rs->errCode!="00"){ Yii::app()->jump->error($rs->errMsg); } if(!empty($rs->data)){ $data['limitstu']=$rs->data; } $data['weekId'] = $weekId; $data['sname'] = $sname; $data['printType'] = 'english_reading'; $this->render('english_reading_stu',$data); } public function actionPhpInfo(){ phpinfo();exit; } public function actionSendKafka(){ $conf = new RdKafka\Conf(); $conf->set('metadata.broker.list', '192.168.1.239:9092,192.168.1.247:9092,192.168.1.248:9092'); $producer = new RdKafka\Producer($conf); $topic = $producer->newTopic("zsyte-marking-finished-notify"); $topic->produce(RD_KAFKA_PARTITION_UA, 0, '{"examGroupId":"582547523696889856","schoolId":3912,"examIds":["582547523780775936","5825475237807759363"]}'); $producer->poll(0); $result = $producer->flush(10000); var_dump($result); if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) { throw new \RuntimeException('Was unable to flush, messages might be lost!'); } } //考试扫描异常处理状态查看 public function actionGetTaskDetail(){ $examGroupId = Req::get('exam_group_id'); $grade = Req::get('grade'); $branch = Req::get('branch'); $taskModel=new AScanTask(); $task=$taskModel->getTaskByExamGroupId($examGroupId); if($task){ $task=$task->attributes; if($task['operator']){ $user=AssistUser::model()->findByPk($task['operator']); $task['user']=$user->real_name; }else{ $task['user']='--'; } //答题卡任务耗时 if($task['scan_task_apply_time']){ if($task['scan_task']>2){ if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){ $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']); }else{ $task['AstConsuming']='--'; } }elseif($task['scan_task']==2){ if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){ $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']); }else{ $task['AstConsuming']='--'; } } }else{ $task['AstConsuming']='--'; } } //读取扫描数量 $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1); $task['count']=$count; $data['task']=$task; $data['exam_group_id']=$examGroupId; $_num= ''; $use_version = ''; if(isset(Yii::app()->session['coachInfo']->use_version)) { $use_version = Yii::app()->session['coachInfo']->use_version; }else { $use_version = Yii::app()->session['coachInfo']['use_version']; } if(!$use_version) { $use_version = 100; } $version_number = implode('',explode('.',$use_version)); if(strlen($version_number)<7) { for($i=0;$i<7-strlen($version_number);$i++) { $_num.='0'; } } $version_number=(int)$version_number.$_num; $data['version_number']=$version_number; $data['grade']=$grade; $data['branch']=$branch; $this->render('scan_detail',$data); } /** * 下载英语外刊教师外刊 * */ public function actiondown_load() { set_time_limit(0); $gradeRel = array(1=>"高一",2=>"高二",3=>"高三"); $weekId = safe_replace(Yii::app()->request->getQuery('weekId')); $sql = "select teacher_general_pdf_path,grade,is_new_version,reading_id,class_id from english_reading where week_id = '{$weekId}'"; $week_info = $this->sConn->createCommand($sql)->queryRow(); if (empty($week_info['teacher_general_pdf_path'])) { if($week_info['is_new_version']){//新版本 $this->new_en_reading($weekId,$week_info); exit; } $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : ''; $sql = "select distinct topic_id from student_reading_topic where week_id = '{$weekId}' order by create_time asc"; $topic_info = $this->sConn->createCommand($sql)->queryAll(); if (empty($topic_info)) { Yii::app()->jump->error('学生外刊宝尚未生成'); } else { $push_topics = _array_column($topic_info, 'topic_id'); $_params = array('isFormat' => 1, 'isTird' => 1, 'isNewEnglish' => 1, 'isNoReplaceLable' => 1); $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $push_topics, 'subjectId' => $this->subjectId, 'params' => $_params), 25, true); if (!$topicDetails) { echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!")); exit(); } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) { echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0])); exit(); } else { foreach($topicDetails as $node=>$td){ if (isset($td['slave'])) { $topicDetails[$node]['diff_str'] = $this->getLargeDifficulty($td['slave']); }else { $topicDetails[$node]['diff_str'] = ''; } } $data = array(); $data['all_topics'] = $push_topics; $data['reading_detail'] = $topicDetails; $html_name = 'en_reading'; $html = $this->renderPartial("{$html_name}", $data,true); unset($data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } } if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $htmlpath .= $weekId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径 //防止exec 执行命令行导致中文乱码 $locale='en_US.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html'; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'"; } else { $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs_server_en'] . " " . Yii::app()->basePath . '/../js/html2pdf_en.js' . " " . " {$htmlurl}" . " {$pdfpath}" . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"'; } exec($commond, $res, $code); if(isset($res[0])){ $isBool = false; foreach ($res as $msg) { if (strpos($msg, 'succeed') !== false) { $isBool = true; } } if ($isBool) {//命令返回成功 if (file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $repdf = $weekId . ".pdf"; $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); if ($uploadInfo['status'] == 0) { $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl; $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; }else{ $pdfurl = $uploadInfo['url']; $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; @unlink($pdfpath); } @unlink($htmlpath); } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF文件未找到!")); exit; } } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res))); exit; } } else { echo json_encode(array("status" => 1, "error" => "PDF创建失败!")); exit; } } } } if($week_info['teacher_general_pdf_path']){ $url = $week_info['teacher_general_pdf_path']; header('Content-Description: File Transfer'); header('Content-Type: application/vnd.android.package-archive'); header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) { echo $buffer; return strlen($buffer); }); curl_exec($ch); curl_close($ch); }else{ Yii::app()->jump->error('尚未生成PDF'); } } /** * 英语周推新版教师版下载 */ public function newEnTeacherWeek($weekId='',$weekMsg=array()){ $sql = "select week_pdf_path from english_week_student where week_id='{$weekId}' and student_id=0"; $week_info = $this->sConn->createCommand($sql)->queryRow(); if($week_info && $week_info['week_pdf_path']){ $classId = $weekMsg['class_id']; $sql = "select class_name from class where class_id = '{$classId}'"; $classInfo = $this->sConn->createCommand($sql)->queryRow(); $className = $classInfo ? $classInfo['class_name'] : ''; $fileName = $className.'_周推教师版'; $url = $week_info['week_pdf_path']; if(isset(Yii::app()->params["static_url"][$this->schoolGroupId]) && Yii::app()->params["static_url"][$this->schoolGroupId]){ $url = Yii::app()->params["static_url"][$this->schoolGroupId].'/'.$url; }else{ Yii::app()->jump->error('接口配置信息错误'); } $handle = @fopen($url, 'r'); if(!$handle){ Yii::app()->jump->error('尚未生成PDF'); } header('Content-Description: File Transfer'); header('Content-Type: application/vnd.android.package-archive'); header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) { echo $buffer; return strlen($buffer); }); curl_exec($ch); curl_close($ch); }else{ Yii::app()->jump->error('周推教师版尚未生成'); } } /** * 英语周推教师版下载 * @throws CException */ public function actionTeacherWeek(){ set_time_limit(0); $weekId = safe_replace(Yii::app()->request->getQuery('weekId')); $sql = "select * from teacher_week_extend where week_id = '{$weekId}'"; $week_info = $this->sConn->createCommand($sql)->queryAll(); $teacher_extend_arr = array(); foreach($week_info as $info) { $content = $info['content']; $content = json_decode($content,true); $teacher_extend_arr[$info['type']] = $content; } $sql = "select grade,teacher_general_pdf_path,class_id,set_id from english_week where week_id = '{$weekId}'"; $week_info = $this->sConn->createCommand($sql)->queryRow(); $sql = "select class_id,semester_id,words_type,is_new_version from english_week_setting where id = '{$week_info['set_id']}'"; $week_setting_info = $this->sConn->createCommand($sql)->queryRow(); if($week_setting_info['is_new_version']){ $this->newEnTeacherWeek($weekId,$week_info); exit; } $words_type = $week_setting_info['words_type']; $sql = "select ps_id from product_class_relation where class_id={$week_setting_info['class_id']} and semester_id={$week_setting_info['semester_id']} and set_type=7 order by ps_id desc limit 1"; $arr = $this->sConn->createCommand($sql)->queryRow(); $product_setting = ''; if($arr){ $sql = "select custom_config from product_setting where ps_id={$arr['ps_id']}"; $product_setting = $this->sConn->createCommand($sql)->queryRow(); $product_setting = $product_setting ? $product_setting['custom_config'] : ''; } $setting = array( 'moduleName'=>'晨读词汇', 'moduleType'=>'english_4', 'setting'=>array( 'vocabularySelfTest' =>array( //词汇自测 "coreVocabulary"=>array( //核心词汇开关 "onOff" =>1, "vocabularyUse" =>1 //词汇运用 ), "keyPhrases" =>1 //重点短语 ), "focusOnGrammar" =>array(//语法聚焦 "singleSentenceGrammar" =>1, //单句语法填空 "grammaticalFillIn" =>1 //语法填空 ), "writingTraining" =>array(//写作训练 "commentsOnGoodSentences" =>1, // 佳句点拨 "actualCombatDrill" =>1 //实战演练 ), "extensiveReadingOfForeignJournals" =>array( //外刊泛读 "accumulationOfNewWords" =>1, //新词积累 "appreciationOfGoldenSentences" =>1, //金句赏析 "fullTextTranslation" =>1, //全文翻译 ), ) ); $product_setting = $product_setting ? json_decode($product_setting, true) : $setting; //$product_setting = $setting; //核心词区分派生非派生 $single_words_derivative = array(); if(isset($teacher_extend_arr[1])){ foreach($teacher_extend_arr[1] as $k=>$v){ if(isset($v['is_derivative'])){ $single_words_derivative[$v['is_derivative']][] = $v; } } } $html_data = array( 'cur_grade' => $week_info['grade'], 'single_words' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(), 'phrase' => isset($teacher_extend_arr[2]) ? $teacher_extend_arr[2] : array(), 'topic_type_six' => isset($teacher_extend_arr[4]) ? $teacher_extend_arr[4] : array(), 'topic_type_nineteen'=> isset($teacher_extend_arr[3]) ? $teacher_extend_arr[3] : array(), 'writing_training' => isset($teacher_extend_arr[5]) ? $teacher_extend_arr[5] : array(), 'single_translation' => isset($teacher_extend_arr[6]) ? $teacher_extend_arr[6] : array(), 'essayDetail' => isset($teacher_extend_arr[7]) ? $teacher_extend_arr[7] : array(), 'word_single_translation' => isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array(), //词汇运用(单句翻译) 'word_grammar_blank' => isset($teacher_extend_arr[9]) ? $teacher_extend_arr[9] : array(), //词汇运用(单句语法填空) 'word_spelling' => isset($teacher_extend_arr[20]) ? $teacher_extend_arr[20] : array(), //词汇运用(单词拼写) 'complete_sentence' => isset($teacher_extend_arr[21]) ? $teacher_extend_arr[21] : array(), //词汇运用(完成句子) 'product_setting' => $product_setting['setting'], 'words_type'=>$words_type, 'single_words_derivative'=>$single_words_derivative ); $classId = $week_info['class_id']; $sql = "select class_name from class where class_id = '{$classId}'"; $classInfo = $this->sConn->createCommand($sql)->queryRow(); $className = $classInfo ? $classInfo['class_name'] : ''; if (empty($week_info['teacher_general_pdf_path'])) { $sql = "select topic_id from teacher_week where week_id = '{$weekId}' order by topic_id desc"; $topic_info = $this->sConn->createCommand($sql)->queryAll(); if (empty($topic_info)) { Yii::app()->jump->error('周推教师版尚未生成'); } else { $html_name = 'english_week_teacher'; //$this->render("{$html_name}", $html_data);exit; $html = $this->renderPartial("{$html_name}", $html_data,true); unset($html_data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } } if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $gradeRel = array(1=>"高一",2=>"高二",3=>"高三"); $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : ''; $htmlpath .= $weekId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径 $locale='en_US.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $weekId . '.html'; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " {$htmlurl}" . " {$pdfpath}" . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"'; } else { $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs_server_en'] . " " . Yii::app()->basePath . '/../js/html2pdf_en.js' . " " . " {$htmlurl}" . " {$pdfpath}" . ' 176mm*250mm "'.$grade.' '.$className.'|||'.date('Y-m-d',time()).'"'; } exec($commond, $res, $code); if(isset($res[0])){ $isBool = false; foreach ($res as $msg) { if (strpos($msg, 'succeed') !== false) { $isBool = true; } } if ($isBool) {//命令返回成功 if (file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $repdf = $weekId . ".pdf"; $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); if ($uploadInfo['status'] == 0) { $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl; $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; }else{ $pdfurl = $uploadInfo['url']; $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; @unlink($pdfpath); } @unlink($htmlpath); } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF文件未找到!")); exit; } } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res))); exit; } } else { echo json_encode(array("status" => 1, "error" => "PDF创建失败!")); exit; } } } if($week_info['teacher_general_pdf_path']){ $fileName = $className.'_周推教师版'; $url = $week_info['teacher_general_pdf_path']; header('Content-Description: File Transfer'); header('Content-Type: application/vnd.android.package-archive'); header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) { echo $buffer; return strlen($buffer); }); curl_exec($ch); curl_close($ch); }else{ Yii::app()->jump->error('尚未生成PDF'); } } //数学公式 public function actionAjaxGetMathtex() { $error = array(); $result = array(); $mathtex = Req::post('mathtex'); if (strlen($mathtex)) { $data = $this->apiPost('/mathtex/url', array('mathtex' => $mathtex,"is_fdfs"=>1), 1); if (isset($data->status) or isset($data->error)) { $error[] = $data->error; } elseif (! $data) { $error[] = '系统错误!'; } else { $result['url'] = $data['url'].'?'.$mathtex; $result['width'] = $data['width']; $result['height'] = $data['height']; } } else { $error[] = '参数不能为空'; } header('Content-Type: application/json'); if ($error) { echo json_encode(array('status' => 0, 'error'=> implode('
', $error))); } else { echo json_encode($result); } } //重新发送扫描任务 public function actionResendScanTask(){ $examGroupId = Req::post('exam_group_id'); $result['status']=0; $taskModel=new AScanTask(); $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes; if(!$task){ $result['msg']='任务数据异常!'; exit(json_encode($result)); } //判断剩余任务量 $studentTask=new AStudentScanTask(); $taskCount=$studentTask->getTaskCount($examGroupId); if($taskCount['surplus']==0){ $result['msg']='当前任务已无异常数据!'; exit(json_encode($result)); } $taskStatus=1; if($task['operator']){ $taskStatus=2; }else{ $taskStatus=1; } if($taskModel->updateAll(array('scan_task'=>$taskStatus,'resend_time'=>time(),'update_time'=>time()),'exam_group_id=:eid',array(':eid'=>$examGroupId))){ $result['status']=1; } exit(json_encode($result)); } //撤回发送扫描任务 public function actionCancelScanTask(){ $examGroupId = Req::post('exam_group_id'); $result['status']=0; $taskModel=new AScanTask(); $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes; if(!$task){ $result['msg']='任务数据异常!'; exit(json_encode($result)); } if($task['scan_task']==2){ $result['msg']='任务已受理不可撤回'; exit(json_encode($result)); } if($task['scan_task']==3){ $result['msg']='任务已完成不可撤回'; exit(json_encode($result)); } if($task['scan_task']==4){ $result['msg']='任务已撤回,请匆重复操作'; exit(json_encode($result)); } if($taskModel->updateAll(array('scan_task'=>4),'exam_group_id=:eid',array(':eid'=>$examGroupId))){ $result['status']=1; } exit(json_encode($result)); } //读取考试剩余任务量 public function actionGetSurplus(){ $examGroupId = Req::post('exam_group_id'); $studentTask=new AStudentScanTask(); $result['status']=0; $taskCount=$studentTask->getTaskCount($examGroupId); if($taskCount['surplus']==0){ $result['msg']='当前任务已无异常数据!'; exit(json_encode($result)); }else{ $result['status']=1; $result['msg']='数据正常!'; exit(json_encode($result)); } } //获取学校百万校 public function checkSchoolBW(){ $http = http('customer/school/coach/official/detail', 'GET', $this->authUsername); $response = formatResponse($http); $data = $response['data']; if(isset($data['isHuge']) && $data['isHuge']==1){ return 1; } return 0; } private function getLargeDifficulty($slave) { if (empty($slave) || !is_array($slave)) { return false; } $difficultyLevel = array( 1 => array( 'range' => 0.90, 'name' => '超易', ), 2 => array( 'range' => 0.75, 'name' => '易', ), 3 => array( 'range' => 0.65, 'name' => '中档偏易', ), 4 => array( 'range' => 0.50, 'name' => '中档偏难', ), 5 => array( 'range' => 0.40, 'name' => '难', ), 6 => array( 'range' => 0.20, 'name' => '超难', ), ); $difficulty = 0; $SlaveTopicDifficultySum = 0; $slaveCount = 0; foreach($slave as $slkey=>$slval){ //计算大题难度 if(!isset($slval['difficulty'])) $slval['difficulty'] = 0; if(isset($difficultyLevel[$slval['difficulty']]) && $slval['difficulty']) { $slaveCount++; $SlaveTopicDifficultySum += $difficultyLevel[$slval['difficulty']]['range']; } } if($SlaveTopicDifficultySum>0 && $slaveCount>0){ $averageDiff=$SlaveTopicDifficultySum/$slaveCount; $difficulty=$this->diffChangeSix($averageDiff,8); } return $this->diffNameSix($difficulty); } private function diffChangeSix($degree,$sub_id = 3) { if ($sub_id == 3) { if($degree>=0 && $degree<=0.2){ $diff = 6; }elseif($degree>0.2 && $degree<=0.4){ $diff = 5; }elseif($degree>0.4 && $degree<=0.6){ $diff = 4; }elseif($degree>0.6 && $degree<=0.7){ $diff = 3; }elseif($degree>0.7 && $degree<=0.85){ $diff = 2; }elseif($degree>0.85 && $degree<=1){ $diff = 1; }else{ $diff = 6; } }else{ if($degree<=0.2){ return 6; }elseif($degree<=0.4){ return 5; }elseif($degree<=0.5){ return 4; }elseif($degree<=0.65){ return 3; }elseif($degree<=0.75){ return 2; }else{ return 1; } } return $diff; } private function diffNameSix($degree) { $diff_name_arr = array('1'=>'超易','2'=>'易','3'=>'中档偏易','4'=>'中档偏难','5'=>'难','6'=>'超难'); return isset($diff_name_arr[$degree]) ? $diff_name_arr[$degree] : ''; } //复用的答题卡编辑后保存 private function saveMultiplex(){ $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:''; $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0; $positionJson=isset($_POST['position'])?$_POST['position']:''; $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0; //上传答题卡相关文件 $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl); $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow(); if($thirdAnswer['multiplex_id']==$multiplexId){ $this->sConn->createCommand("update third_answer_sheet set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute(); } echo json_encode(array('success'=>1,'message'=>'保存成功','multiplex_id'=>$multiplexId,'exam_group_id'=>$examGroupId));exit; } // 上传答题卡相关文件 private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){ $card_file=array(); if (empty($_FILES)) { $error['message'] = '未找到上传文件!'; echo json_encode($error);exit(); }else { // debug($_FILES); foreach ($_FILES as $k => $v) { if (isset($v) && !empty($v)) { if (!isset($v['size']) || $v['size'] >= 8388608) { $error['message'] = '文件超过8M!'; echo json_encode($error); exit(); } $ext = substr($v['name'], strrpos($v['name'], '.') + 1); if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) { $error['message'] = '文件格式不正确!'; echo json_encode($error); exit(); } if ($ext == 'pdf') { $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf'; if (!move_uploaded_file($v["tmp_name"], $card_pdf)) { $error['message'] = '保存Pdf文件失败!'; echo json_encode($error); exit(); } } else { $card_file[] = $v; } } } $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/'; $ucloudPdfUrl = ''; if (!file_exists($fixName)) { mkdir($fixName, 0777, true); } $zipFileName = $examGroupId .'_'.time().'.zip'; $pathName = $fixName . $zipFileName; $zip = new ZipArchive; $zip->open($pathName, ZipArchive::CREATE); foreach ($card_file as $k => $v) { $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name'])); } $zip->addFromString('json.txt', $positionJson); $zip->close(); //FIXME 20191204 $ucloud = new Qcloud(); //上传压缩包 $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName; $uploadInfo = $ucloud->putFile($rename, $pathName); @unlink($pathName); if ($uploadInfo['status'] == 0) { $error['success'] = 0; $error['message'] = '答题卡文件上传失败! '; $error['data']=$uploadInfo; echo json_encode($error); exit(); } else { $ucloudZipUrl = $uploadInfo['url']; } //上传Pdf if ($pdfUrl) { $ucloudPdfUrl=$pdfUrl; // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf'; // $content = file_get_contents($pdfUrl); // // file_put_contents($card_pdf, $content); // // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf'; // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf); // // if ($uploadInfo['status'] == 0) { // @unlink($card_pdf); // $error['success'] = 0; // $error['message'] = '答题卡PDF文件上传失败!'; // echo json_encode($error); // exit(); // } else { // @unlink($card_pdf); // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']); // $ucloudPdfUrl = $uploadInfo['url']; // } } //单独上传position.txt if($positionJson){ $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ; file_put_contents($positionTxt, $positionJson); $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ; $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt); if ($uploadInfo['status'] == 0) { @unlink($positionTxt); $error['success']=0; $error['message'] = 'Position文件上传失败!'; echo json_encode($error);exit(); }else{ @unlink($positionTxt); $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']); $ucloudTxtUrl=$uploadInfo['url']; } } } return array( 'ucloudZipUrl'=>$ucloudZipUrl, 'ucloudPdfUrl'=>$ucloudPdfUrl, 'positionUrl'=>$ucloudTxtUrl ); } //加载考试未上传学生 public function actionAjaxLoadNoUploadStudent(){ $examGroupId = Req::post('exam_group_id'); $page=intval(Req::post('page')); $isDel=intval(Req::post('is_del')); $classId=Req::post('class_id'); if(!$page) $page=1; $result=array(); $result['status']=0; if(!$examGroupId){ $result['msg']='考试id不能为空'; exit(json_encode($result)); } $data=$this->schoolManager->getNoUploadStudentByGroupId($examGroupId,$page,$isDel,$classId); if($data){ $result['status']=1; $result['data']=$data; } exit(json_encode($result)); } //删除考试学生,全部班级 public function actionDelExamStudent(){ $examGroupId = Req::post('examGroupId'); $studentIds=Req::post('studentsIds'); $examId=Req::post('examId'); $result['status']=0; if(!$examId){ $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId); if($examIds){ $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examIds); } $sendJsonArr = array( 'school_id' => $this->schoolId, 'send_type' => 'zsyas', 'update_type' => 2, 'exam_group_id' => $examGroupId, 'exam_id_arr' => $examIds, 'student_id_arr' => $studentIds ); }else{ $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examId); $sendJsonArr = array( 'school_id' => $this->schoolId, 'send_type' => 'zsyas', 'update_type' => 2, 'exam_group_id' => $examGroupId, 'exam_id_arr' => array($examId), 'student_id_arr' => $studentIds ); } if($rs){ if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '删除考试学生,全部班级', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $result['status']=1; sendStudentCacheQueue($sendJsonArr); } exit(json_encode($result)); } //下载学生导出excel public function actionDownloadSelectStudent(){ $examGroupId = Req::get('examGroupId'); $studentIds=Req::get('studentsIds'); $studentIds=explode(',',$studentIds); if(!$studentIds || !$examGroupId){ $result['status']=0; exit(json_encode($result)); } $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); $rs=$this->schoolManager->getExcelStudent($studentIds,$examGroupId); $excel = new Excel(); $fileName = $exam_data[0]['name']."未上传学生"; $excel->export($rs, $fileName); } //批量删除所有未上传考生 public function actionDelAllNotUploadStudent(){ $examGroupId = Req::post('examGroupId'); $result['status']=0; $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId); $studentIds=array(); if($examIds){ $rs=$this->schoolManager->delStudentPaperByExamGroupId($examIds); $studentIds=$this->schoolManager->getStudentPaperByExamGroupId($examIds); } $sendJsonArr = array( 'school_id' => $this->schoolId, 'send_type' => 'zsyas', 'update_type' => 2, 'exam_group_id' => $examGroupId, 'exam_id_arr' => $examIds, 'student_id_arr' => $studentIds ); if($rs){ if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "examGroupId" => $examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '删除所有未上传考生', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:j') ))); } $result['status']=1; sendStudentCacheQueue($sendJsonArr); } exit(json_encode($result)); } //获取在线答题卡接口token public function actionGetOnlineToken(){ $token=getOnlineToolToken($this->schoolId); if($token){ $result['status']=1; $result['data']=$token; }else{ $result['status']=0; $result['msg']='token读取失败'; } exit(json_encode($result)); } //更新考试准考证类型 public function actionChangeStudentCardType(){ $examGroupId = Req::post('examGroupId'); $schoolCard = Req::post("schoolCard"); $schoolCardLength = intval(Req::post("schoolCardLength")); if(!$examGroupId) $this->output(0, "参数错误[1]"); if($schoolCard==1 && !$schoolCardLength){ $this->output(0, "准考证位数不能为空"); } $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(!$exam_group_array ) { $this->output(0, "非法数据"); } if($exam_group_array['upload_status']>0){ $this->output(0, "已上传成绩不能修改考号类型"); } if(!in_array($schoolCard,array(0,1))) $this->output(0, "考号类型不正确"); $examDetail=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '更改考号类型', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" => json_encode(array('update'=>array( 'exam'=>array('school_card_status'=>$schoolCard), ))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $transaction = $this->sConn->beginTransaction(); try{ Exam::model()->updateAll(array('school_card_status'=>$schoolCard,'school_card_length'=>$schoolCardLength),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $transaction->commit(); }catch(Exception $e) { $transaction->rollBack(); $this->output(0, "更改失败"); } $this->output(1, "更改成功"); } //学生成绩转移读取学生列表 public function actionGetUploadedStudent(){ $examGroupId = Req::post('examGroupId'); if(!$examGroupId) $this->output(0, "参数错误[1]"); $examIds=array(); $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); if(!$exam_data) $this->output(0, "考试不存在"); foreach ($exam_data as $val){ $examIds[]=$val['exam_id']; } if($exam_data[0]['school_card_status']==1){ $fieldName='school_student_card'; }else{ $fieldName='student_card'; } $uploaded=array(); $noUploaded=array(); $students=$this->schoolManager->getAllStudentPaperByExamIds($examIds); if($students){ foreach ($students as $val){ if($val['is_feedback']==1){ $uploaded[]=array( 'student_id'=>$val['student_id'], 'student_card'=>$val[$fieldName], 'student_name'=>$val['realname'] ); }else{ $noUploaded[]=array( 'student_id'=>$val['student_id'], 'student_card'=>$val[$fieldName], 'student_name'=>$val['realname'] ); } } } if(!$uploaded){ $this->output(0, "考试还未上传成绩"); } if(!$noUploaded){ $this->output(0, "考试没有未上传的学生"); } $this->output(1, "success",array('data'=>array('uploaded'=>$uploaded,'noUploaded'=>$noUploaded))); } //交换学生成绩之移形换影大法! public function actionAjaxTransferStudentRs(){ $examGroupId = Req::post('examGroupId'); $uploadStudentId = Req::post('uploadStudentId'); $noUploadStudentId = Req::post('noUploadStudentId'); if(!$examGroupId) $this->output(0, "参数错误[1]"); if(!$uploadStudentId || !$noUploadStudentId) $this->output(0, "请先选择参与转移的学生"); $examGroupArray = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $examIds=array(); $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId); if(!$exam_data) $this->output(0, "考试不存在"); $examStatus=array(); foreach ($exam_data as $val){ $examIds[]=$val['exam_id']; $examStatus[(string)$val['exam_id']]=$val['status']; } if($examGroupArray->mark_type==3 && $examGroupArray->mark_status==2){ $this->output(0, "本场考试已完成阅卷,需要先恢复阅卷状态,再转移学生成绩"); } $isAllSelect=1; //全部客观题判断 //获取paper 表数据 $paperData = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0])); $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paperData->paper_id)); if(!$paperTopic){ Yii::app()->jump->error('未找到考试信息!'); } //选择题类型判断 $allSubjectType=array(); if($examGroupArray['qxk_paper_id']>0){ $allSubjectType=array(1,2,3,4,12); }else{ $allSubjectType=array(1,2,11); } foreach ($paperTopic as $item){ if(!in_array($item->type,$allSubjectType)){ $isAllSelect=0; break; } } $studentPaper=$this->schoolManager->getAllStudentPaperByExamIds($examIds,array($uploadStudentId,$noUploadStudentId)); $uploadStudentData=array(); $noUploadStudentData=array(); if($studentPaper){ foreach ($studentPaper as $item){ if(strcmp($item['student_id'],$uploadStudentId)==0){ $uploadStudentData=$item; }elseif(strcmp($item['student_id'],$noUploadStudentId)==0){ $noUploadStudentData=$item; } } } if($examGroupArray->mark_type==4 && $examStatus[$uploadStudentData['exam_id']]==1){ $this->output(0, $uploadStudentData['realname']."所在班级已完成阅卷,需要先恢复阅卷状态,再转移学生成绩"); } //开始转移 $transcation = $this->sConn->beginTransaction(); try { //读取原学生成绩数据 $uploadStudentRs=$this->sConn->createCommand("select * from student_paper_relation where student_id='{$uploadStudentId}' and exam_id='{$uploadStudentData['exam_id']}'")->queryRow(); $setValue=array( "complete_count='{$uploadStudentRs['complete_count']}'", "right_count='{$uploadStudentRs['right_count']}'", "partial_right_count='{$uploadStudentRs['partial_right_count']}'", "wrong_count='{$uploadStudentRs['wrong_count']}'", "scoring='{$uploadStudentRs['scoring']}'", "lost_score='{$uploadStudentRs['lost_score']}'", "is_feedback=1", "feedback_time='{$uploadStudentRs['feedback_time']}'", "student_img_paper='{$uploadStudentRs['student_img_paper']}'", "is_complete='{$uploadStudentRs['is_complete']}'", "complete_time='{$uploadStudentRs['complete_time']}'", ); $sourceSetValue=array( "complete_count='0'", "right_count='0'", "partial_right_count='0'", "wrong_count='0'", "scoring='0'", "lost_score='0'", "is_feedback=0", "feedback_time='0'", "student_img_paper='0'", "is_complete='0'", "complete_time='0'", ); $this->sConn->createCommand("update student_paper_topic_rs set student_id='{$noUploadStudentId}',paper_id='{$noUploadStudentData['paper_id']}' where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute(); $this->sConn->createCommand("update student_paper_relation set ".implode(',',$sourceSetValue)." where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute(); $updateSql="update student_paper_relation set ".implode(',',$setValue)." where student_id='{$noUploadStudentId}' and paper_id='{$noUploadStudentData['paper_id']}'"; $this->sConn->createCommand($updateSql)->execute(); //判断未上传学生班级状态 $noUploadExam=$this->sConn->createCommand("select upload_status,subject_id from exam where exam_id='".$noUploadStudentData['exam_id']."'")->queryRow(); if($noUploadExam['upload_status']==0){ if($examGroupArray->mark_type>0){ $this->sConn->createCommand("update exam set upload_status=1,status=4 where exam_id='".$noUploadStudentData['exam_id']."'")->execute(); }else{ $this->sConn->createCommand("update exam set upload_status=1,status=1,complete_time='".time()."' where exam_id='".$noUploadStudentData['exam_id']."'")->execute(); } } //同步阅卷数据 if($examGroupArray->mark_type>0 && !$isAllSelect){ $params=array( 'examGroupId'=>$examGroupId, 'sourceStudentId'=>$uploadStudentId, 'targetStudentId'=>$noUploadStudentId, 'schoolId'=>$this->schoolId, 'targetClazzId'=>$noUploadStudentData['class_id'] ); if($examGroupArray->qxk_paper_id>0){ //查询班级 $classInfo=$this->sConn->createCommand("select class_name from class where class_id='".$noUploadStudentData['class_id']."'")->queryRow(); //班级执教教师 $teacherClassData=$this->sConn->createCommand("select teacher_id from teacher_class_relation where class_id='".$noUploadStudentData['class_id']."'")->queryAll(); if ($teacherClassData) { foreach ($teacherClassData as $v) { $teacherIds[$v['teacher_id']] = $v['teacher_id']; } } if ($noUploadExam['subject_id']) { if (in_array($noUploadExam['subject_id'], array(3, 6, 51))) { $subjectId = 3; } else { $subjectId = $noUploadExam['subject_id']; } } $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id in(".implode(',',$teacherIds).") and subjects='{$subjectId}'")->queryRow(); if (!$teacherSubjectData) { $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id='{$examGroupArray['teacher_id']}'")->queryRow(); } $params['targetStudentName']=$noUploadStudentData['realname']; $params['targetClazzId']=$noUploadStudentData['class_id']; $params['targetClazzName']=$classInfo['class_name']; $params['targetTeacherId']=$teacherSubjectData['teacher_id']; $params['targetTeacherName']=$teacherSubjectData['teacher_name']; $rs=http('/qxk/marking/exam/replace-marking','PUT',$this->schoolId,$params,'cgi'); }else{ $rs=http('/teacher/marking/v2/replace-marking','PUT',$this->schoolId,$params,'cgi'); } $rs=json_decode($rs); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '转移成绩', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "zsyapi_return"=>$rs, "date"=>date('Y-m-d H:i:s') ))); } if(!isset($rs->errCode) || $rs->errCode !='00') { throw new Exception($rs->errMsg); }else{ $transcation->commit(); } }else{ $transcation->commit(); } if($examGroupArray->mark_type==0){ $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("zsyte-academic-offline-generate-report",$kafkaData); } $this->output(1, "转移成功"); } catch (Exception $e) { $transcation->rollback(); $this->output(0, "转移失败"); } } /** * 生成产品消息 * @return mixed */ public function actionSendProductHtml() { $examGroupId = Req::post('examGroupId'); $examId = Req::post('examId'); $sendMsg=array( 'school_id'=>$this->schoolId, 'msg_type'=>3, 'subject_id'=>Yii::app()->session['session_subject_id'], 'send_type'=>'exam', 'exam_group_id'=>$examGroupId, 'exam_ids'=>array($examId) ); sendDataToKafka('php-product-html',$sendMsg); return true; } //获取多种指定产品权限 protected function getManyProductOrder($params,$classify=array(),$studentIds=array()) { $intarr = array(); $orderIds = array(); if ($classify) { foreach ($classify as $item) { $params['students'] = $studentIds; $params['classify'] = $item; $intarr[] = $params; } } $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr), $basic), true); if (isset($rs['errCode']) && $rs['errCode'] == "00" && isset($rs['data']) && $rs['data']) { foreach ($rs['data'] as $r) { $orderIds = array_merge($orderIds, $r); } } return $orderIds; } //下载全学科试卷解析 public function actionDownloadPaper(){ $examGroupId = Req::post('examGroupId'); $paperSheet =Req::post('paperSheet'); $downloadType =Req::post('downloadType'); $wordType = Req::post('wordType'); $isPrint = Req::post('isPrint'); $examGroup=SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId)); if(!$examGroup) returnMsg(0,'考试id不存在'); $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $paper=SPaper::model()->find('exam_id=:e_id',array(':e_id'=>$exam['exam_id'])); $paperTopic=$this->sConn->createCommand("select topic_id,`type`,`order`,score,stem_id,`no` from paper_topic_relation where paper_id='".$paper['paper_id']."' order by `type` asc,`order` asc")->queryAll(); $alias=array(); $tplData=json_decode($exam['tpl_data'],true); $selectTopicGroup=array(); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $item){ if(isset($item['fullAlias'])){ if(is_numeric($item['fullAlias'])){ $alias[$item['id']]=$item['fullAlias']; }else{ $alias[$item['id']]=$item['stemAlias']; } }else{ $alias[$item['id']]=$item['alias']; if($item['stemId']==$item['topicId']){ $stemAlias[$item['id']]=$item['alias']; }else{ $stemAlias[$item['id']]=$item['stemAlias'].$item['alias']; } } if(isset($item['sameAliasNo']) && $item['sameAliasNo']){ $selectTopicGroup[$item['id']]=$item['sameAliasNo']; } } } $topicIds=array(); if($paperTopic) { foreach($paperTopic as $k=>$v) { if(isset($v['stem_id']) && $v['stem_id']){ $topicId=$v['stem_id']; }else{ $topicId=$v['topic_id']; } $topicIds[]=$topicId; $topicNumber[(string)$v['topic_id']]=array( 'topic_id'=>$v['topic_id'], 'type'=>$v['type'], 'order'=>$v['order'], 'score'=>$v['score'], ); } }else{ returnMsg(0,'请先创建答题卡'); } //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$exam->subject_id); $topicDetail=$this->schoolManager->getQxkPaperTopics(array_values($topicIds)); foreach ($topicDetail as $item){ if(!isset($topicType[$item['typeId']])){ $topicType[$item['typeId']]=array( 'typeName'=>$item['typeName'], 'description'=>'', 'topics'=>array() ); } $topic=array(); $id=(string)number_format($item['topicId'],0,'',''); $topic['topicId']=$id; if(isset($topicNumber[$id])){ $topic['score']=$topicNumber[$id]['score']; $order=$topicNumber[$id]['order']; $topicType[$item['typeId']]['order']=$order; if(isset($alias[$order])){ $topic['topicNo']=$alias[$order]; }else{ $topic['topicNo']=$order; } //判断选做题 if(isset($selectTopicGroup[$topicNumber[$id]['order']])){ $topic['groupId']=$selectTopicGroup[$topicNumber[$id]['order']]; } } if(isset($item['slaveList']) && $item['slaveList']){ foreach ($item['slaveList'] as $val){ $slave=array(); if(isset($val['slaveList']) && $val['slaveList']){ foreach ($val['slaveList'] as $third){ $thirdSlave=array(); $thirdSlave['topicId']=(string)number_format($third['topicSlaveId'],0,'',''); if(isset($topicNumber[(string)$thirdSlave['topicId']])){ $thirdSlave['score']=$topicNumber[(string)$thirdSlave['topicId']]['score']; $thirdOrder=$topicNumber[(string)$thirdSlave['topicId']]['order']; if(isset($alias[$thirdOrder])){ $thirdSlave['topicNo']=$alias[$thirdOrder]; }else{ $thirdSlave['topicNo']=$thirdOrder; } if(!isset($topicType[$item['typeId']]['order'])){ $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicId']]['order']; } if(isset($topicNumber[(string)$thirdSlave['topicId']]['scores'])){ $thirdSlave['scores']=$topicNumber[(string)$thirdSlave['id']]['scores']; } if(!isset($topic['topicNo'])){ $topic['topicNo']= $thirdSlave['topicNo']; } //判断选做题 if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']])){ $thirdSlave['groupId']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']]; } } $slave['slave'][]=$thirdSlave; } }else{ if(isset($topicNumber[(string)$val['topicSlaveId']])){ $slave['topicId']=$val['topicSlaveId']; $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score']; $slaveOrder=$topicNumber[(string)$val['topicSlaveId']]['order']; if(isset($alias[$slaveOrder])){ $slave['topicNo']=$alias[$slaveOrder]; }else{ $slave['topicNo']=$slaveOrder; } if(!isset($topicType[$item['typeId']]['order'])){ $topicType[$item['typeId']]['order']=$slaveOrder; } if(!isset($topic['topicNo'])){ $topic['topicNo']= $slave['topicNo']; } //判断选做题 if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){ $slave['groupId']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']]; } } } $topic['slave'][]=$slave; } } $topicType[$item['typeId']]['topics'][]=$topic; } $lastOrder = $this->_array_column($topicType,'order'); array_multisort($lastOrder,SORT_ASC,$topicType); //拆分选做题 if($selectTopicGroup){ $selectTopicType=array(); $selectTopicType['typeName']='选做题'; $selectTopicType['topics']=array(); foreach ($topicType as $key => $item){ foreach ($item['topics'] as $vk => $val){ if(isset($val['groupId'])){ unset($val['groupId']); $selectTopicType['topics'][]=$val; unset($topicType[$key]['topics'][$vk]); $selectTopicType['order']=$val['topicNo']; } } if(count($topicType[$key]['topics'])==0){ unset($topicType[$key]); } } $topicType[17]=$selectTopicType; } //计算小题数量 foreach ($topicType as $key => $item){ $topicNumber=0; $scores=0; foreach ($item['topics'] as $k => $val){ if(isset($val['slave'])){ foreach ($val['slave'] as $v){ if(isset($v['slave'])){ foreach ($v['slave'] as $value){ if(isset($value['score'])){ $scores+=$value['score']; } $topicNumber++; } }else{ if(isset($v['score'])){ $scores+=$v['score']; } $topicNumber++; } } unset($topicType[$key]['topics'][$k]['slave']); }else{ if($key==17){ $scores=$val['score']; }else{ $scores+=$val['score']; } $topicNumber++; } } //选做题(每小题2分,共2分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤) if($key==17){ $topicType[$key]['description']='每小题'.$scores.'分,共'.$scores.'分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤'; }else{ $topicType[$key]['description']='本大题共'.$topicNumber.'小题,共'.$scores.'分'; } } $topicType=array_values($topicType); if($paperSheet==0){ $paperOrientation=1; }elseif($paperSheet==2){ //A4横版 $paperSheet=0; $paperOrientation=0; }elseif($paperSheet==1){ $paperOrientation=null; } $postParam=array( 'subjectId'=>$exam['subject_id'], 'downloadType'=>$downloadType, 'paperSheet'=>$paperSheet, 'wordType'=>$wordType, 'paperOrientation'=>$paperOrientation, 'subPaperName'=>'', 'hasBindLine'=>0, 'hasSealFlag'=>0, 'attentionInfo'=>'', 'paperName'=>$exam['name'], 'examTime'=>$tplData['times'], 'totalScore'=>$tplData['scores'], 'createBy'=>$tplData['author'], 'applyBy'=>'', 'teacherId'=>$examGroup['teacher_id'], 'semesterId'=>$this->semesterId, 'types'=>$topicType, 'isZxhx'=>3 ); $header=array('X-Basic-V:2'); $cgi=Yii::app()->params['cgi']; $username=$cgi['username']; $password=$cgi['password']; if($isPrint){ $url = $cgi['domain'].'dmw/qxk/download/mathtype-pdf'; }else{ $url = $cgi['domain'].'dmw/qxk/download/mathtype-word'; } $rs = $this->CrmApiPost($url,$postParam,$username,$password,'POST',$header); if(isset($rs->errCode) && $rs->errCode=='00'){ $this->schoolManager->saveExamProcess($examGroupId,14,time()); if($isPrint){ //组装打印参数 $printData=array(); $printData['typeId']=18; $printData['productType']=60001; $printData['params']=array( 'classIds'=>array(), 'url'=>$rs->data, 'name'=>$exam['name'], 'subjectId'=>$exam['subject_id'], 'examGroupId'=>$exam['exam_group_id'], ); returnMsg(1,'success',$printData); }else{ returnMsg(1,'success',$rs->data); } }else{ returnMsg(0,$rs->errMsg); } } function _array_column(array $array, $column_key, $index_key=null){ $result = array(); foreach($array as $arr) { if(!is_array($arr)) continue; if(is_null($column_key)){ $value = $arr; }else{ $value = $arr[$column_key]; } if(!is_numeric($value)){ $value=intval($value); } if(!is_null($index_key)){ $key = $arr[$index_key]; $result[$key] = $value; }else{ $result[] = $value; } } return $result; } //读取考试班级产品设置相同题 public function findExamClassSameTrain($examGroupId,$subject=3){ if(in_array($subject,$this->mathSubjectId)){ $subject=3; } $classes=$this->sConn->createCommand("select class_id from exam where exam_group_id='{$examGroupId}'")->queryAll(); if($classes){ //读取产品设置版本 $productSetEdition=$this->sConn->createCommand("select switch from producut_set_edition limit 1")->queryRow(); $isBeta=0; if($productSetEdition && $productSetEdition['switch']==4){ $isBeta=1; } //查询默认模板 $classIds=array(); foreach ($classes as $key => $value) { $classIds[]=$value['class_id']; } if($subject==3){ $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' and is_beta='{$isBeta}'")->queryAll(); }else{ $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' ")->queryAll(); } $needCheckDefault=false; if($classSet){ //有配置 $tids=array(); $tidClass=array(); foreach ($classSet as $val) { if($val['template_id']){ $tidClass[$val['class_id']][$val['template_id']]=$val['template_id']; $tids[$val['template_id']]=$val['template_id']; } if($val['isp']){ $tidClass[$val['class_id']][$val['isp']]=$val['isp']; $tids[$val['isp']]=$val['isp']; } if($val['wb_isp']){ $tidClass[$val['class_id']][$val['wb_isp']]=$val['wb_isp']; $tids[$val['wb_isp']]=$val['wb_isp']; } } if(count($classIds)!=count($tidClass)){ //有班级是取默认设置 $needCheckDefault=true; } if($tids){ $template=$this->sConn->createCommand("select config_text from product_template where template_id in(".implode(',',$tids).")")->queryAll(); if($template){ foreach ($template as $key => $v) { $jsonData=json_decode($v['config_text'],true); if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){ return true; } } } } } if($needCheckDefault || !$classSet){ //没有配置,读取默认模板 if($subject==3){ $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 and is_beta='{$isBeta}'")->queryAll(); }else{ $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 ")->queryAll(); } if($template){ foreach ($template as $key => $v) { $jsonData=json_decode($v['config_text'],true); if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){ return true; } } } } } return false; } /*学管发送还原考试申请*/ public function actionRestoreApply(){ $examGroupId = Req::post('examId'); $result['status']=0; if(!$examGroupId){ $result['msg']="参数异常"; exit(jsonEncode($result)); } $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(!$exam){ $result['msg']="未查询到考试信息"; exit(jsonEncode($result)); } $tplData=json_decode($exam->tpl_data,true); //查询申请记录 $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if($examRestore){ $result['msg']="考试已经申请,不要重复操作"; exit(jsonEncode($result)); } $model=new SExamRestore(); $model->exam_group_id=$examGroupId; $model->exam_name=$exam->name; $model->subject_name=Yii::app()->params['subjectId'][$exam->subject_id]; $model->exam_date=$tplData['examDate']; $model->create_time=time(); if($model->save()){ if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原申请', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $result['status']=1; exit(jsonEncode($result)); }else{ $result['msg']="申请失败"; exit(jsonEncode($result)); } } /*退回还原考试申请*/ public function actionRestoreApplyBack(){ $examGroupId = Req::post('examId'); $result['status']=0; if(!$examGroupId){ $result['msg']="参数异常"; exit(jsonEncode($result)); } $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(!$exam){ $result['msg']="未查询到考试信息"; exit(jsonEncode($result)); } //查询申请记录 $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(!$examRestore){ $result['msg']="申请已退回,不要重复操作"; exit(jsonEncode($result)); } $rs = SExamRestore::model()->deleteByPk($examGroupId); if($rs){ $result['status']=1; if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => (string)$examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '还原申请退回', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } exit(jsonEncode($result)); }else{ $result['msg']="退回失败"; exit(jsonEncode($result)); } } //标注预计完成时间计算 public function ComputeCompleteTime($examGroupId){ if(!$examGroupId) return false; $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='{$examGroupId}'")->queryAll(); if(!$exam) return false; $examIds=array(); foreach ($exam as $val){ $examIds[]=$val['exam_id']; } $taskTime=0; $studentPaper=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).")")->queryRow(); $studentCount=$studentPaper['count']; if($studentCount<=500){ $taskTime=36; }elseif($studentCount<=1000){ $taskTime=24; }elseif($studentCount<=1500){ $taskTime=12; }else{ $taskTime=6; } $data['studentNumber']=$studentCount; $data['estimate']=expectTime($taskTime,time()); return $data; } /** * 英语外刊阅读初始化获取 版本 模块 单元 */ public function actionAjaxReadingTextbookModuleUnit(){ //版本 模块 单元 $textbooks=$modules=$units=array(); // $textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8)); $textbookResult=$this->apiPost('all_textbook/getTextbookByImsProduct',array('subjectId'=>8,'imsProductId'=>6)); if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){ $textbookResult=$textbookResult['data']; foreach($textbookResult as $textbookKey=>$textbookItem){ $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']); if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){ foreach($textbookItem['child'] as $moduleKey=>$moduleItem){ $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']); if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){ foreach($moduleItem['child'] as $unitItem){ $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']); } } } } } } $date_msg = $this->getWeekOnMonth(); $year = $date_msg["year"]; $month = $date_msg["month"]; $week = $date_msg["week"]; $weekUpper = numToUpper($week); $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周'; $data=array( 'textbooks'=>$textbooks,//版本 'modules'=>$modules,//模块 'units'=>$units,//单元 'week_name'=>$weekName, ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /* * 英语外刊阅读获取班级数据 */ public function actionAjaxReadingClasses(){ $req=Req::input(); $grade=isset($req['grade'])?(int)$req['grade']:0; $gc=isset($req['category'])?(int)$req['category']:1; //产品种类 1综合(老版) 2 分离(新版) $pt=isset($req['pt'])?(int)$req['pt']:1; //产品类型:1-基础宝 2-外刊宝 3-热点宝 if(!$grade){ exit(json_encode(array('status'=>0,'msg'=>'请传年级参数'))); } $class=$this->getClassesBySettingReading($grade,$gc,$pt); $data=array( 'class'=>$class, ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /* * 英语外刊阅读获取基础选题 */ public function actionAjaxReadingBasicTopics(){ $req=Req::input(); $grade=isset($req['grade'])?(int)$req['grade']:0; if(!$grade){ exit(json_encode(array('status'=>0,'msg'=>'请传年级参数'))); } $basicTopics=array(); $basicTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>1,'grade'=>$grade)); if(isset($basicTopicsResult['status']) && $basicTopicsResult['status'] && isset($basicTopicsResult['data']) && $basicTopicsResult['data']){ $basicTopics=$basicTopicsResult['data']; } $data=array( 'basic_topics'=>$basicTopics, ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /* * 英语外刊阅读获取热点选题 */ public function actionAjaxReadingHotTopics(){ $req=Req::input(); $grade=isset($req['grade'])?(int)$req['grade']:0; if(!$grade){ exit(json_encode(array('status'=>0,'msg'=>'请传年级参数'))); } $hotTopics=array(); $hotTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>2,'grade'=>$grade)); if(isset($hotTopicsResult['status']) && $hotTopicsResult['status'] && isset($hotTopicsResult['data']) && $hotTopicsResult['data']){ $hotTopics=$hotTopicsResult['data']; } $data=array( 'hot_topics'=>$hotTopics, ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /* * 英语外刊阅读获取主题语境 */ public function actionAjaxReadingSubjectContext(){ $subjectContextResult=$this->apiPost('all_textbook/subjectContext',array()); if(isset($subjectContextResult['status']) && $subjectContextResult['status'] && isset($subjectContextResult['data']) && $subjectContextResult['data']){ $subjectContext=$subjectContextResult['data']; } $data=array( 'subject_context'=>$subjectContext, ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 根据版本获取模块和单元数据 */ public function actionAjaxNewGetModuleAndUnit(){ $req=Req::input(); $versionId=isset($req['version_id'])?(int)$req['version_id']:0; $queryType=isset($req['query_type'])?(int)$req['query_type']:1; if(!$versionId){ $versionId=(int)Req::post('version_id'); $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2; } $subjectId= Yii::app()->session['session_duoxueke_subject_id']; $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId; $moduleResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId)); $modules=$units=$chapters=array(); if(isset($moduleResult['status']) && $moduleResult['status'] && isset($moduleResult['data']) && $moduleResult['data']){ $moduleResult=array_values($moduleResult['data']); foreach($moduleResult as $moduleKey=>$moduleItem){ $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']); if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){ foreach($moduleItem['child'] as $unitKey=>$unitItem){ $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']); if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){ foreach($unitItem['child'] as $chapterItem){ $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']); } } } } } } $data=array( 'modules'=>$modules,//模块 'units'=>$units,//单元 'chapters'=>$chapters,//章节 ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 根据版本获取单元数据 */ public function actionAjaxNewGetUnitByModuleId(){ $req=Req::input(); $versionId=isset($req['version_id'])?(int)$req['version_id']:0; $moduleId=isset($req['module_id'])?(int)$req['module_id']:0; $queryType=isset($req['query_type'])?(int)$req['query_type']:1; if(!$moduleId){ $versionId=(int)Req::post('version_id'); $moduleId=(int)Req::post('module_id'); $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2; } $unitResult=$this->apiPost('all_textbook/getUnit',array('module_id'=>$moduleId,'query_type'=>$queryType,'version_id'=>$versionId)); $units=array(); if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){ $unitResult=$unitResult['data']; foreach($unitResult as $unitKey=>$unitItem){ $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']); } } $data=array( 'units'=>$units,//单元 ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 根据模块获取单元数据和章节数据 */ public function actionAjaxNewGetUnitAndChapters(){ $versionId=(int)Req::post('version_id'); $moduleId=(int)Req::post('module_id'); $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2; $subjectId= Yii::app()->session['session_duoxueke_subject_id']; $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId; $unitResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId)); $units=$chapters=array(); if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){ $unitResult=array_values($unitResult['data']); foreach($unitResult as $unitKey=>$unitItem){ $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']); if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){ foreach($unitItem['child'] as $chapterItem){ $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']); } } } } $data=array( 'units'=>$units,//单元 'chapters'=>$chapters,//章节 ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 根据单元获取章节数据 */ public function actionAjaxNewGetChapters(){ $versionId=(int)Req::post('version_id'); $moduleId=(int)Req::post('module_id'); $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2; $subjectId= Yii::app()->session['session_duoxueke_subject_id']; $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId; $chapterResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId)); $chapters=array(); if(isset($chapterResult['status']) && $chapterResult['status'] && isset($chapterResult['data']) && $chapterResult['data']){ $chapterResult=array_values($chapterResult['data']); foreach($chapterResult as $chapterItem){ $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']); } } $data=array( 'chapters'=>$chapters,//章节 ); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 智能模式下设置的产品类型学生数据 */ public function actionAjaxSmartTypeStudents(){ $req=Req::input(); $classIds=isset($req['selectClassIds'])?$req['selectClassIds']:array(); if(!$classIds || !is_array($classIds)){ exit(json_encode(array('status'=>0,'msg'=>'请检查班级参数'))); } $classIdsStr=implode(',',$classIds); $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_id in ({$classIdsStr}) and is_hide=0"; $validClass = $this->sConn->createCommand($sql)->queryAll(); if(!$validClass){ exit(json_encode(array('status'=>0,'msg'=>'成功','data'=>array()))); } // $validClass=$this->_array_column($validClass,'class_name','class_id'); $newValidClass = array(); foreach($validClass as $k=>$v){ $newValidClass[(string)$v['class_id']] = $v['class_name']; } $validClass = $newValidClass; $classIdsStr=implode(',',array_keys($validClass)); $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and si.reading_level>0 and scr.status=0"; $studentInfo = $this->sConn->createCommand($sql)->queryAll(); $studentType=array(); foreach($studentInfo as $item){ $classId=$item['class_id']; $studentId=(string)$item['student_id']; $readingLevel=$item['reading_level']; if(!isset($studentType[$readingLevel][$classId]) || !array_key_exists($studentId,$studentType[$readingLevel][$classId])) { $studentType[$readingLevel][$classId][$studentId] = $item['realname']; } } $readingSmartTypes=array(1,2,3); $lists=array(); foreach($readingSmartTypes as $type){ $classInfo=array(); foreach($validClass as $classId=>$className){ $classId=(string)$classId; if(isset($studentType[$type][$classId])){ $studentsArr=$studentType[$type][$classId]; $students=array(); foreach($studentsArr as $studentId=>$studentName){ $students[]=array('student_id'=>(string)$studentId,'realname'=>$studentName); } $classInfo[]=array( 'class_id'=>$classId, 'class_name'=>$className, 'students'=>$students, ); }else{ $classInfo[]=array( 'class_id'=>$classId, 'class_name'=>$className, 'students'=>array(), ); } } $lists[]=array( 'product_type'=>$type, 'class_info'=>$classInfo, ); unset($classInfo); } $data=array('lists'=>$lists); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } /** * 外刊阅读保存设置 */ public function actionAjaxNewSaveEnglishReading(){ $error = array(); $req=Req::input(); if (!Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=isset($req['grade'])?(int)$req['grade']:0;//年级:1-高一 2-高二 3-高三 $textbookId=isset($req['textbookId'])?(int)$req['textbookId']:0;//教材Id $moduleId=isset($req['moduleId'])?(int)$req['moduleId']:0;//模块Id $unitId=isset($req['unitId'])?$req['unitId']:array();//单元Id $classIds=isset($req['selectClassIds']) && is_array($req['selectClassIds']) ?$req['selectClassIds']:array();//班级 $itemIds=isset($req['selectedItemIds']) && is_array($req['selectedItemIds'])?$req['selectedItemIds']:array();//主题语境下话题 $type=isset($req['type'])?(int)$req['type']:0;//外刊类型:1-个性外刊 2-共性外刊 $level=isset($req['level'])?(int)$req['level']:0;//外刊分级 1-尖子班 2-培优班 3-提高班 $isAnswerSeparate=isset($req['isAnswerSeparate'])?(int)$req['isAnswerSeparate']:0;;//答案是否分开打印 0否 1是 $isNewVersion = 1;//是否新版本 1是 0否 $recommendMode=isset($req['recommend_mode'])?(int)$req['recommend_mode']:0;;//推荐模式:1-经典模式 2-智能推荐模式 $productType=isset($req['product_type'])?(int)$req['product_type']:0;;//产品类型:1-基础宝 2-外刊宝 3-热点宝 $basicTopic=isset($req['basic_topic'])?(int)$req['basic_topic']:0;;//基础选题 $hotTopic=isset($req['hot_topic'])?(int)$req['hot_topic']:0;//热点选题 $topicNumber=isset($req['topic_number'])?$req['topic_number']:array();//题目数量 $selectSetType=isset($req['select_set_type'])?$req['select_set_type']:0;//选择的类型 1-按照教材单元设置 2-主题语境设置 3-时文阅读 $classBetweenContent=isset($req['class_between_content'])?$req['class_between_content']:0;//班级间内容: 0-相同 1-不同 $category=isset($req['category'])?(int)$req['category']:1;//产品种类 1综合(老版) 2 分离(新版) $classify=19; $weekNameExt='外刊宝'; if($category==2){ if($productType==1){ $classify=57; $weekNameExt='基础宝'; }elseif($productType==2){ $classify=61; $weekNameExt='外刊宝'; }elseif($productType==3){ $classify=58; $weekNameExt='热点宝'; } } if(!in_array($selectSetType,array(1,2,3))){ $error[] = '请选择设置类型'; } if($selectSetType==1){ if(!$textbookId || !$moduleId || !$unitId){ $error[] = '按照教材单元设置时教材、模块、单元不能为空'; } $itemIds=array(); }elseif($selectSetType==2){ if(!$itemIds){ $error[] = '主题语境设置时主题语境不能为空'; } $unitId=array();$textbookId=$moduleId=0; }elseif($selectSetType==3){ //时文阅读无这几个参数,处理成不传时候的默认值 $itemIds=$unitId=array();$textbookId=$moduleId=0; } if($unitId){ if(!is_array($unitId)){ $error[] = '单元格式不正确'; } if(is_array($unitId) && count($unitId)>3) { $error[] = '单元最多3个'; } } if($unitId && is_array($unitId) && $unitId){ $unitId=empty($unitId)?0:implode(',',$unitId); }elseif(!$unitId){ $unitId=0; } if(!in_array($grade,array(1,2,3))){ $error[] = '请选择正确年级'; } if(!$classIds || !is_array($classIds)){ $error[] = '请选择班级'; } if(!in_array($recommendMode,array(1,2))){ $error[] = '推荐模式不在范围内'; } if($recommendMode==1 && !in_array($productType,array(1,2,3))){ $error[] = '产品类型不在范围内'; } if(!in_array($classBetweenContent,array(0,1))){ $error[] = '请检查班级间内容'; } if(!in_array($category,array(1,2))){ $error[] = '产品种类不在合理范围内'; } //经典模式 if($recommendMode==1){ if($productType==1){//基础宝 if(!$basicTopic){ $error[] = '请选择基础选题'; } //不需要的值,设为0或者空 $type=0;$level=0;$hotTopic=0;$topicNumberJson='';$classBetweenContent=0; }elseif($productType==2){//外刊宝 if(!in_array($type,array(1,2))){ $error[] = '请选择外刊类型'; } if($type==2 && !in_array($level,array(1,2,3))){ $error[] = '外刊类型是共性外刊时请选择正确的外刊分级'; } unset($topicNumber['hot']); if(!$topicNumber || !isset($topicNumber['periodicals']) || count($topicNumber)!=1){ $error[] = '检查题目数量'; }else{ $error=array_merge($error,$this->validateTopicNumber($topicNumber)); } //不需要的值,设为0或者空 $basicTopic=0;$hotTopic=0; if($type==1){ $level=0; $classBetweenContent=0;//外刊宝中共性外刊时班级间内容才能选值 } $topicNumberJson=json_encode($topicNumber); }elseif($productType==3){//热点宝 if(!in_array($type,array(1,2))){ $error[] = '请选择外刊类型'; } if($type==2 && !in_array($level,array(1,2,3))){ $error[] = '外刊类型是共性外刊时请选择正确的外刊分级'; } if(!$hotTopic){ $error[] = '请选择热点选题'; } unset($topicNumber['periodicals']); if(!$topicNumber || !isset($topicNumber['hot']) || count($topicNumber)!=1){ $error[] = '缺少题目数量'; }else{ $error=array_merge($error,$this->validateTopicNumber($topicNumber)); } //不需要的值,设为0或者空 $basicTopic=0; if($type==1){ $level=0; $classBetweenContent=0;//热点宝中共性外刊时班级间内容才能选值 } $topicNumberJson=json_encode($topicNumber); } }elseif($recommendMode==2){//智能推荐模式 if(!$basicTopic){ $error[] = '请选择基础选题'; } if(!$hotTopic){ $error[] = '请选择热点选题'; } if(!$topicNumber){ $error[] = '缺少题目数量'; }else{ if(!isset($topicNumber['periodicals']) || !isset($topicNumber['hot'])){ $error[] = '检查题目数量'; }else{ $error=array_merge($error,$this->validateTopicNumber($topicNumber)); } } $type=1;//默认个性外刊 $level=0;$productType=0;$classBetweenContent=0; $topicNumberJson=json_encode($topicNumber); } } if(!$error){ $time = time(); $date_msg = $this->getWeekOnMonth(); $year = $date_msg["year"]; $month = $date_msg["month"]; $week = $date_msg["week"]; $weekUpper = numToUpper($week); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"'.$weekNameExt.'"'; $reading_id = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('english_reading_setting',array( 'reading_id'=>$reading_id, 'grade' => $grade, 'semester_id' => $this->semesterId, 'textbook_id' => $textbookId, 'module_id' => $moduleId, 'unit_id' => $unitId, 'special_ids' => implode(',',$itemIds), 'create_time' => $time, 'type' => $type, 'level'=>$level, 'is_answer_separate'=>$isAnswerSeparate, 'recommend_mode'=>$recommendMode, 'product_type'=>$productType, 'basic_topic'=>$basicTopic, 'hot_topic'=>$hotTopic, 'topic_number_json'=>$topicNumberJson, 'class_between_content'=>$classBetweenContent, 'category'=>$category )); $weekIdArr=array(); foreach($classIds as $k=>$v){ $weekId = getUniqueId($this->schoolId); $weekIdArr[]=$weekId; $this->sConn->createCommand()->insert('english_reading',array( 'week_id' => $weekId, 'name' => $weekName, 'class_id' => $v, 'grade' => $grade, 'semester_id' => $this->semesterId, 'year_num' => $year, 'week_num' => $week, 'month_num' => $month, 'reading_id'=>$reading_id, 'create_time' => $time, 'is_new_version'=>$isNewVersion, )); //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); $studentInfo=array(); if($stuData && (($recommendMode==1 && in_array($productType,array(2,3)) && $type==1) || ($recommendMode==2)) ){ $sql = "SELECT si.student_id,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id={$v} and si.reading_level>0 and scr.status=0"; $studentInfo = $this->sConn->createCommand($sql)->queryAll(); $studentInfo=$this->_array_column($studentInfo,'reading_level','student_id'); } //智能模式 if($recommendMode==2 && $stuData){ foreach($stuData as $kk=>$vv){ $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2; $this->sConn->createCommand()->insert('english_reading_student',array( 'week_id' => $weekId, 'student_id' => $vv['student_id'], 'product_type'=>$readingLevel,//智能模式下档次和产品类型数值一样 'reading_level'=>$readingLevel, )); } }else if($recommendMode==1 && $stuData){//推荐模式 foreach($stuData as $kk=>$vv){ $readingLevel=0; //2-外刊宝 3-热点宝 下个性外刊 if(in_array($productType,array(2,3)) && $type==1){ $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2; } $this->sConn->createCommand()->insert('english_reading_student',array( 'week_id' => $weekId, 'student_id' => $vv['student_id'], 'product_type'=>$productType, 'reading_level'=>$readingLevel, )); } } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } } if($error){ exit(json_encode(array('status'=>0,'msg'=>$error))); }else{ $kafkaData=array( 'school_id'=>$this->schoolId, 'msg_type'=>1,//90:重置 1:新设置 'grade'=>$grade, 'subject_id'=>8, 'send_type'=>'english_reading', 'product_type'=>array($classify), 'gp_group_id'=>$reading_id,//reading_id 'gp_ids'=>array_unique($weekIdArr),//week_Id ); sendDataToKafka("php-product-english-reading-html",$kafkaData); exit(json_encode(array('status'=>1))); } } /** * 校验题目数量设置 * 外刊宝:外刊阅读,题数默认4(数量范围为0-7);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为2-7 * 热点宝:外刊阅读,题数默认3(数量范围为0-6);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为1-6 * @param $topicNumberConfig * @return array */ private function validateTopicNumber($topicNumberConfig){ $error=array(); if(isset($topicNumberConfig['periodicals'])){ $periodicals=$topicNumberConfig['periodicals']; if(!isset($periodicals['reading']) || !isset($periodicals['gestalt']) || !isset($periodicals['seven_selected_five'])){ $error[]='外刊宝题目数量参数有误'; }else{ $reading=intval($periodicals['reading']); $gestalt=intval($periodicals['gestalt']); $sevenSelectedFive=intval($periodicals['seven_selected_five']); if(!($reading>=0 && $reading<=7)){ $error[]='外刊宝外刊阅读数量设置有误:数量范围为0-7'; } if(!($gestalt>=0 && $gestalt<=7)){ $error[]='外刊宝外刊完形(新高考)数量设置有误:数量范围为0-2'; } if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){ $error[]='外刊宝外刊七选五数量设置有误:数量范围为0-2'; } $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive; if(!($periodicalsTotal>=2 && $periodicalsTotal<=7)){ $error[]='外刊宝题数总和题数范围为2-7'; } } } if(isset($topicNumberConfig['hot'])){ $hot=$topicNumberConfig['hot']; if(!isset($hot['reading']) || !isset($hot['gestalt']) || !isset($hot['seven_selected_five'])){ $error[]='热点宝题目数量参数有误'; }else{ $reading=intval($hot['reading']); $gestalt=intval($hot['gestalt']); $sevenSelectedFive=intval($hot['seven_selected_five']); if(!($reading>=0 && $reading<=7)){ $error[]='热点宝外刊阅读数量设置有误:数量范围为0-6'; } if(!($gestalt>=0 && $gestalt<=7)){ $error[]='热点宝外刊完形(新高考)数量设置有误:数量范围为0-2'; } if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){ $error[]='热点宝外刊七选五数量设置有误:数量范围为0-2'; } $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive; if(!($periodicalsTotal>=1 && $periodicalsTotal<=6)){ $error[]='热点宝题数总和题数范围为1-6'; } } } return $error; } /** * 外刊阅读学生设置数据初始化 */ public function actionAjaxEnglishReadingSetInit(){ $req=Req::input(); $grade=isset($req['grade'])?(int)$req['grade']:0; if(!$grade){ exit(json_encode(array('status'=>0,'msg'=>'请传年级参数'))); } $class=$this->getClassesBySettingReading($grade); $data=array('class_students'=>array(), 'reading_level_students'=>array()); if(!$class){ exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } $class=$this->_array_column($class,'class_name','class_id'); $classIdsStr=implode(',',array_keys($class)); $students=$classStudentInfo=$studentType=$classLevelStudent=array(); if($classIdsStr){ $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and scr.status=0 order by scr.class_id asc"; $students = $this->sConn->createCommand($sql)->queryAll(); } $readingLevel=array(1,2,3); foreach($students as $item){ $isSet=false; $sutdentItem=array('student_id' => $item['student_id'], 'realname' => $item['realname'],'class_id'=>$item['class_id']); if($item['reading_level']){ $isSet=true; $studentType[$item['reading_level']][] = $sutdentItem;//层次学生数据比班级学生数据少一个是否已设置分层标记 $classLevelStudent[$item['class_id']][$item['reading_level']][]=$sutdentItem; } $sutdentItem['is_set']=$isSet; $sutdentItem['reading_level']=$item['reading_level']; $classStudentInfo[$item['class_id']][]=$sutdentItem; } $classLevelStudentResult=array(); foreach($classLevelStudent as $classId=>&$itemLevelStudent){ $classLevelStudentItem=array(); foreach($readingLevel as $level){ $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array(); $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent); } $classLevelStudentResult[$classId]=$classLevelStudentItem; } $classStudent=$readingLevelStudent=$levelStudentDefault=array(); foreach($readingLevel as $level){ $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array());//默认结构 } foreach($class as $classId=>$className){ $singleClassStudents=isset($classStudentInfo[$classId])?$classStudentInfo[$classId]:array();//单个班级学生数据 $singleClassLevelStudent=isset($classLevelStudentResult[$classId])?$classLevelStudentResult[$classId]:$levelStudentDefault;//单个班级分档次学生数据 $classStudent[]=array('class_id'=>$classId,'class_name'=>$className,'students'=>$singleClassStudents,'reading_level_students'=>$singleClassLevelStudent); } unset($students); unset($classStudentInfo);unset($classLevelStudentResult);unset($singleClassStudents);unset($singleClassLevelStudent); foreach($readingLevel as $level){ $readingLevelStudent[]=array( 'reading_level'=>$level, 'students'=>isset($studentType[$level])?$studentType[$level]:array(), ); } $data=array( 'class_students'=>$classStudent,//班级学生 'reading_level_students'=>$readingLevelStudent,//分层学生 ); unset($classStudent);unset($readingLevelStudent);unset($studentType); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } private function getInWhereStr($data=array()){ $str=''; foreach($data as $item){ $str.="'".$item."',"; } $str=trim($str,','); return $str; } /** * 英语外刊学生设置保存学生层次 */ public function actionAjaxEnglishReadingStudentSettingSave(){ $req=Req::input(); $studentsProductType=isset($req['students_product_type'])?$req['students_product_type']:array(); if(!$studentsProductType || !is_array($studentsProductType)){ exit(json_encode(array('status'=>0,'msg'=>'请检查参数'))); } $studentsProductTypeData=array(); foreach($studentsProductType as $kye=>$item){ if(!isset($item['reading_level']) || !in_array($item['reading_level'],array(0,1,2,3)) || !isset($item['students']) || !is_array($item['students'])){ exit(json_encode(array('status'=>0,'msg'=>'请检查参数里的数据'))); } if( !$item['students']){ unset($studentsProductType[$kye]); continue; } $studentsProductTypeData[$item['reading_level']]=$item['students']; } unset($studentsProductType); ksort($studentsProductTypeData); $error=array(); $transaction = $this->sConn->beginTransaction(); try{ foreach($studentsProductTypeData as $readingLevel=>$students){ $readingLevel=(int)$readingLevel; if($students) { $studentIdsStr = implode(',', $students); $sql = "update student_info set reading_level={$readingLevel} where student_id in ({$studentIdsStr})"; $this->sConn->createCommand($sql)->execute(); } } $transaction->commit(); }catch(Exception $e){ $transaction->rollBack(); if (YII_ENV == 'production') { $error[] = '系统错误[SQL]'; } else { $error[] = $e->getMessage(); } } if($error){ exit(json_encode(array('status'=>0,'msg'=>$error))); }else{ exit(json_encode(array('status'=>1))); } } /** * 英语外刊阅读学生数据导入 * @throws CException */ public function actionEnglishReadingStudentImport() { ini_set('memory_limit', '300M'); if (Yii::app()->request->getIsPostRequest()) { $grade=(int)Req::post('grade'); if(!$grade){ exit(json_encode(array('status'=>0,'msg'=>'缺少年级参数'))); } $uploader = new Uploader("upload/tmpDir/UploadEnglisthReadingStudentsList/{$this->schoolId}/"); $uploader->allowTypes = array("xls","xlsx"); $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId)); $file = $uploader->act(); $file = Arr::current(Arr::current($file)); if (!$file || !isset($file["error"])) exit(json_encode(array('status'=>0,'msg'=>'请选择上传的Excel!'))); if ($file["error"] != 0) { switch ($file["error"]) { case 2001: exit(json_encode(array('status'=>0,'msg'=>'文件类型不符'))); break; case 2002: exit(json_encode(array('status'=>0,'msg'=>'文件大小超出允许范围'))); break; default: exit(json_encode(array('status'=>0,'msg'=>'上传失败'))); break; } } $inputFileName = $file["src"]; if (Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => 0, "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' => $_POST, 'get' => $_GET, 'file' => $inputFileName)), "date" => date('Y-m-d H:i:s') ))); } Yii::import('application.extensions.*'); require_once('phpexcel/PHPExcel/IOFactory.php'); // 读取Excel文档 $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); @unlink($file["src"]); // 去掉导航 //dump($sheetData);die; unset($sheetData[1]); krsort($sheetData); $excelTotal=count($sheetData); $studentScoreInfo = array(); foreach ($sheetData as $key => $val) { if (empty($val['A']) || empty($val['B']) || !isset($val['C']) || !is_numeric($val['C']) || empty($val['D']) || !is_numeric($val['D']) || (int)$val['D']<=0) { continue; } if (count($val) != 4) { continue; } $studentScoreInfo[] = array( 'realname' => $val['A'], 'class_name' => $val['B'], 'score' => (int)$val['C'], 'total_score' => (int)$val['D'], ); } if(!$studentScoreInfo){ exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误。'))); } $classNames=_array_column($studentScoreInfo,'class_name','class_name'); $classNamesStr=$this->getInWhereStr($classNames); // $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and class_type=1 and is_hide=0 and grade={$grade} group by class_name having count(*)=1"; $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and is_hide=0 and grade={$grade} group by class_name having count(*)=1"; $classInfo= $this->sConn->createCommand($sql)->queryAll(); if(!$classInfo){ exit(json_encode(array('status'=>3,'data'=>array(),'msg'=>'没有有效年级数据'))); } $classInfo=$this->_array_column($classInfo,'class_id','class_name');; $classIds=implode(',',$classInfo); $sql="SELECT scr.class_id,si.student_id,si.realname FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIds}) and scr.status=0 group by scr.class_id,si.realname having count(*)>1"; $repeatStudents= $this->sConn->createCommand($sql)->queryAll(); //重复学生 $repeatStudentsData=$classStudentInfo=array(); foreach($repeatStudents as $item){ $repeatStudentsData[$item['class_id'].$item['realname']]=''; } //过滤信息 剔除查询不到班级和 姓名重复的学生 foreach($studentScoreInfo as $key=>&$item){ if(isset($classInfo[$item['class_name']])){ $classId=$classInfo[$item['class_name']]; //表里姓名重复的学生 if(isset($repeatStudentsData[$classId][$item['realname']])){ unset($studentScoreInfo[$key]); continue; } //excel里重复的和不符合条件的学生数据 if(isset($classStudentInfo[$classId][$item['realname']]) || !intval($item['score']) || intval($item['total_score'])<=0 || intval($item['score'])>intval($item['total_score'])){ unset($classStudentInfo[$classId][$item['realname']]); unset($studentScoreInfo[$key]); continue; } $rate=round(intval($item['score'])/intval($item['total_score']),4)*100; $level=2; if($rate<=60){ $level=1; }elseif($rate>60 && $rate<=80){ $level=2; }elseif($rate>80){ $level=3; } $classStudentInfo[$classId][$item['realname']]=$level; }else{ //不存在班级的学生 unset($studentScoreInfo[$key]); } } unset($repeatStudentsData);unset($repeatStudents); if(!$classStudentInfo){ exit(json_encode(array('status'=>1,'data'=>array()))); } $sqlWhere=''; foreach($classStudentInfo as $classId=>$itemStudent){ $realnames=array_keys($itemStudent); if(!$realnames){ continue; } $realnameStr=$this->getInWhereStr($realnames); $sqlWhere.=" (scr.class_id={$classId} and si.realname in ({$realnameStr}) ) or"; } if(!$sqlWhere){ exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误!'))); } $sqlWhere=trim($sqlWhere,'or'); $sql="select si.student_id,si.realname,scr.class_id from student_info si inner join student_class_relation scr on si.student_id=scr.student_id where {$sqlWhere} order by scr.class_id "; $students= $this->sConn->createCommand($sql)->queryAll(); //有效的学生数 $studentTotal=count($students); //有效的班级学生数据 $classStudentData=array(); foreach($students as $item){ $classStudentData[$item['class_id']][$item['realname']]=$item['student_id']; } $productTypeStudents=$classStudents=$classLevelStudent=array(); foreach($classStudentInfo as $classId=>$itemStudent){ foreach($itemStudent as $realname=>$level){ if(!isset($classStudentData[$classId][$realname])){ continue; } $studentId=$classStudentData[$classId][$realname]; $studentInfo=array('student_id'=>$studentId,'realname'=>$realname,'class_id'=>$classId); $productTypeStudents[$level][]=$studentInfo; $classLevelStudent[$classId][$level][]=$studentInfo; $studentInfo['is_set']=true; $studentInfo['reading_level']=$level; $classStudents[$classId][]=$studentInfo;//班级学生数据多是否设置和档次字段 } } $readingLevel=array(1,2,3); $productTypeStudentsResult=$classStudentsResult=$classLevelStudentResult=array(); //班级学生数据中的档次数据 foreach($classLevelStudent as $classId=>&$itemLevelStudent){ $classLevelStudentItem=array(); foreach($readingLevel as $level){ $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array(); $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent); } $classLevelStudentResult[$classId]=$classLevelStudentItem; } unset($students);unset($classStudentInfo);unset($classStudentData);unset($classLevelStudent); //档次学生数据 foreach($readingLevel as $itemLevel){ $studentArr=isset($productTypeStudents[$itemLevel])?$productTypeStudents[$itemLevel]:array(); $productTypeStudentsResult[]=array( 'reading_level'=>$itemLevel, 'students'=>$studentArr, ); } //默认结构 $levelStudentDefault=array(); foreach($readingLevel as $level){ $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array()); } //班级学生信息 foreach($classInfo as $itemClassName =>$itemClassId){ $studentArr=isset($classStudents[$itemClassId])?$classStudents[$itemClassId]:array(); $classLevelStudentArr=isset($classLevelStudentResult[$itemClassId])?$classLevelStudentResult[$itemClassId]:$levelStudentDefault; $classStudentsResult[]=array('class_id'=>$itemClassId,'class_name'=>$itemClassName,'students'=>$studentArr,'reading_level_students'=>$classLevelStudentArr); } $data=array( 'class_students'=>$classStudentsResult, 'reading_level_students'=>$productTypeStudentsResult, 'excel_total'=>$excelTotal, 'student_total'=>$studentTotal, ); unset($productTypeStudents);unset($classStudents);unset($classLevelStudentResult);unset($productTypeStudentsResult);unset($classStudentsResult);unset($studentArr);unset($classLevelStudentArr); exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data))); } } /** * 新版英语外刊教师版 */ public function new_en_reading($weekId='',$week_info=array()){ $sql = "select product_type,basic_topic,hot_topic from english_reading_setting where reading_id='{$week_info['reading_id']}'"; $week_setting = $this->sConn->createCommand($sql)->queryRow(); $data = array(); $gradeRel = array(1=>"高一",2=>"高二",3=>"高三"); $class_name = ''; $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : ''; $class_id = $week_info['class_id']; $sql = "select class_id,class_name from class where class_id = '$class_id'"; $class_data = $this->sConn->createCommand($sql)->queryRow(); if($class_data){ $class_name = $class_data['class_name']; } if($week_setting){ if($week_setting['product_type'] == 1){//基础宝 $p_name="外刊-基础宝"; $html_name = 'en_jichu'; $basic_data = array(); $basic_topic = $week_setting['basic_topic'];//基础宝ID if($basic_topic){ $basic_topic_arr = explode(",",$basic_topic); $brain_data = $this->apiBrainPost('/all_library/englishBaseBaby', array('ids' => $basic_topic_arr), 25, true); if($brain_data && isset($brain_data['data']) && $brain_data['data']){ foreach($brain_data['data'] as $k=>$v){ if(isset($v['jsb']) && $v['jsb']){ $basic_data = json_decode($v['jsb'],true); } } }else{ Yii::app()->jump->error('基础宝教师版接口有误'); } }else{ Yii::app()->jump->error('基础宝ID设置有误'); } if(!$basic_data){ Yii::app()->jump->error('基础宝教师版没有数据'); }else{ $data['basic_data'] = $basic_data; } }else if($week_setting['product_type'] == 2){//外刊宝 $p_name="外刊-外刊宝"; $html_name = 'en_waikan'; $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'"; $topic_data = $this->sConn->createCommand($sql)->queryAll(); if($topic_data){ $topic_ids = _array_column($topic_data, 'topic_id'); $topic_ids = array_unique($topic_ids); $data['topic_ids'] = $topic_ids; $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true); if (!$topicDetails) { Yii::app()->jump->error('获取接口batchALL无数据!'); } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) { Yii::app()->jump->error($topicDetails['error'][0]); } else { $paper_topic_detail= array(); foreach($topicDetails as $k=>$v){ $paper_topic_detail[(string)$v['id']] = $v; } $new_topic_detail = $this->newTopicDetail($paper_topic_detail); $data['topic_detail'] = $new_topic_detail; } }else{ Yii::app()->jump->error('学生外刊没生成'); } }else{//热点宝 $p_name="外刊-热点宝"; $html_name = 'en_hot'; $hot_topic = $week_setting['hot_topic'];//热点宝ID $redian_topic_ids = array(); if($hot_topic){ $hot_topic_arr = explode(",",$hot_topic); $brain_data = $this->apiBrainPost('/all_library/englishHotBaby', array('ids' => $hot_topic_arr), 25, true); if($brain_data && isset($brain_data['data']) && $brain_data['data']){ foreach($brain_data['data'] as $k=>$v){ if(isset($v['xxtlsy']) && $v['xxtlsy']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['xxtlsy']); } if(isset($v['ljfxsy']) && $v['ljfxsy']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['ljfxsy']); } if(isset($v['sbsy']) && $v['sbsy']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['sbsy']); } if(isset($v['yychhy']) && $v['yychhy']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['yychhy']); } if(isset($v['yyjjfx']) && $v['yyjjfx']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['yyjjfx']); } if(isset($v['zhyysy']) && $v['zhyysy']){ $redian_topic_ids = array_merge($redian_topic_ids,$v['zhyysy']); } } $data['hot_data'] = $brain_data['data'][0]; }else{ Yii::app()->jump->error('热点宝教师版接口有误'); } }else{ Yii::app()->jump->error('热点宝ID设置有误'); } $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'"; $topic_data = $this->sConn->createCommand($sql)->queryAll(); if($topic_data){ $topic_ids_0 = _array_column($topic_data, 'topic_id'); $topic_ids_0 = array_unique($topic_ids_0); $topic_ids = array_merge($topic_ids_0,$redian_topic_ids); $data['topic_ids'] = $topic_ids_0; $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true); if (!$topicDetails) { Yii::app()->jump->error('获取接口batchALL无数据!'); } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) { Yii::app()->jump->error($topicDetails['error'][0]); } else { $paper_topic_detail= array(); foreach($topicDetails as $k=>$v){ $paper_topic_detail[(string)$v['id']] = $v; } $new_topic_detail = $this->newTopicDetail($paper_topic_detail); $data['topic_detail'] = $new_topic_detail; } }else{ Yii::app()->jump->error('学生外刊没生成'); } } //开始生成html $data['type_config'] =array('gestalt'=>713,'reading'=>714,'seven_selected_five'=>array(715,432)); $html = $this->renderPartial("{$html_name}", $data,true); unset($data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { Yii::app()->jump->error('Create directory fail: ' . $htmlpath); } } if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { Yii::app()->jump->error('Create directory fail: ' . $pdfpath); } } $htmlpath .= $weekId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径 //防止exec 执行命令行导致中文乱码 $locale='en_US.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html'; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'"; } else { $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; $pdffname = $weekId . ".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs_server_en'] . " " . Yii::app()->basePath . '/../js/html2pdf_en.js' . " " . " {$htmlurl}" . " {$pdfpath}" . ' 176mm*250mm "'.$class_name.'|||'.'时间:'.date('Y-m-d',time()).' '.$p_name.'"'; } exec($commond, $res, $code); if(isset($res[0])){ $isBool = false; foreach ($res as $msg) { if (strpos($msg, 'succeed') !== false) { $isBool = true; } } if ($isBool) {//命令返回成功 if (file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $repdf = $weekId . ".pdf"; $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); //上传html $rehtml = $weekId.".html"; $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml; $uploadHtmlInfo = $ucloud->putFile($rename, $htmlpath); if($uploadHtmlInfo['status'] == 0){ $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl; }else{ $html_url = $uploadHtmlInfo['url']; } if ($uploadInfo['status'] == 0) { $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl; $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; }else{ $pdfurl = $uploadInfo['url']; $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'"); $week_info['teacher_general_pdf_path'] = $pdfurl; @unlink($pdfpath); } @unlink($htmlpath); } else { @unlink($htmlpath); Yii::app()->jump->error('PDF文件未找到!'); } } else { @unlink($htmlpath); Yii::app()->jump->error('PDF创建失败!'); } } else { Yii::app()->jump->error('PDF创建失败11!'); } }else{ Yii::app()->jump->error('外刊宝设置信息有误'); } if($week_info['teacher_general_pdf_path']){ $url = $week_info['teacher_general_pdf_path']; header('Content-Description: File Transfer'); header('Content-Type: application/vnd.android.package-archive'); header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) { echo $buffer; return strlen($buffer); }); curl_exec($ch); curl_close($ch); }else{ Yii::app()->jump->error('尚未生成PDF'); } } /** * 整理试题详情数据 */ public function newTopicDetail($paper_topic_detail){ $result = array(); $answer = array('A','B','C','D','E','F','G','H','I','J','K'); foreach($paper_topic_detail as $k=>$v){ $result[$k]['title'] = $v['title']; $result[$k]['type_id'] = $v['type_id']; $result[$k]['parse_content'] = $v['parse_content']; $result[$k]['answer'] = array(); $slave_answer = array(); if(isset($v['slave']) && $v['slave']){ $slave_arr = array(); foreach($v['slave'] as $sla_k=>$sla_v){ $slave_arr[$sla_k]['title'] = $sla_v['title'];//小题题干 if(isset($sla_v['items']) && $sla_v['items']){ if(isset($sla_v['items']['options']) && $sla_v['items']['options']){ foreach($sla_v['items']['options'] as $op_k=>$op_v){ $slave_arr[$sla_k]['options'][$op_k] = $op_v['option_content']; if($op_v['option_correct']){ $slave_answer[] = $answer[$op_k]; } } } } } $result[$k]['slave'] = $slave_arr; $result[$k]['answer'] = $slave_answer; }else{ if(isset($v['items']) && $v['items'] && isset($v['items'][0]) && $v['items'][0]){ if(isset($v['items'][0]['options']) && $v['items'][0]['options']){ foreach($v['items'][0]['options'] as $op_k=>$op_v){ if($op_v['option_correct'] == 1){ $slave_answer[] = $op_v['option_content']; } } } } $result[$k]['answer'] = $slave_answer; } if(isset($v['affiliate']) && $v['affiliate']){ foreach($v['affiliate'] as $aff_k=>$aff_v){ if($aff_v['field_name'] == '体裁类型'){ $result[$k]['tc'] = $this->getTags($aff_v['field_key'],$aff_v['field_value']); } if($aff_v['field_name'] == '主题语境'){ //主题语境只显示一个 $ztyj_str = $this->getTags($aff_v['field_key'],$aff_v['field_value']); $ztyj_arr = explode(",",$ztyj_str); if($ztyj_arr){ $result[$k]['ztyj'] = $ztyj_arr[0]; }else{ $result[$k]['ztyj'] =''; } } if($aff_v['field_name'] == '语篇等级'){ $result[$k]['ypdj'] = $aff_v['field_value']; } if($aff_v['field_name'] == '句子剖析'){ $result[$k]['jzpx'] = $aff_v['field_value']; } if($aff_v['field_name'] == '词汇积累'){ $result[$k]['chjl'] = $aff_v['field_value']; } if($aff_v['field_name'] == '关键词拓展'){ $result[$k]['gjctz'] = $aff_v['field_value']; } if($aff_v['field_name'] == '长难句解析'){ $result[$k]['cnjjx'] = $aff_v['field_value']; } } } } return $result; } /* * 获取试题标签 * */ public function getTags($field_key='',$field_value=''){ $result = ''; $data = array( 'subjectId'=>8, 'isSearch'=>1, 'tagFieldName'=>array($field_key) ); $brain_data = $this->apiBrainPost('/all_subject/topic_tag', $data, 25, true); if($brain_data && isset($brain_data['data']) && $brain_data['data']){ $brain_arr = $brain_data['data']; if(isset($brain_arr[0]) && isset($brain_arr[0]['extend']) && $brain_arr[0]['extend']){ $field_value_arr = explode("|",$field_value); $field_arr = array(); foreach($brain_arr[0]['extend'] as $extend_v){ if(in_array($extend_v['tag_extend_id'],$field_value_arr)){ $field_arr[]=$extend_v['tag_extend_name']; } } if($field_arr){ $result = implode(",",$field_arr); } } } return $result; } /*读取考试试题推送配置*/ public function actionLoadExamPushTopic(){ $examGroupId = Req::post('examGroupId'); $examIds = Req::post('examIds'); $result=array(); $result['status']=0; if(!$examGroupId || !is_numeric($examGroupId)){ $result['msg']="参数异常"; exit(jsonEncode($result)); } if(!is_array($examIds)){ $examIds=explode(',',$examIds); } //加载试题结构 $classes=array(); $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if($examIds){ $criteria = new CDbCriteria(); $criteria->select = 'exam_id,class_id,tpl_data'; $criteria->addInCondition('exam_id',$examIds); $exam = Exam::model()->findAll($criteria); $tplData=array(); $alias=array(); foreach ($exam as $item){ $class=ClassModel::model()->find('class_id=:cid',array(':cid'=>$item['class_id'])); $classes[]=$class['class_name']; if(!$tplData){ $tplData=json_decode($item['tpl_data'],true); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $value){ if(isset($value['fullAlias'])){ $alias[$value['id']]=$value['fullAlias']; }else{ $alias[$value['id']]=$value['alias']; } } } } } $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam[0]['exam_id'])); } if(!$paper){ $result['msg']="考试数据异常"; exit(jsonEncode($result)); } $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:pid',array(':pid'=>$paper['paper_id'])); $paperTopicRelation=array(); if($examGroup['qxk_paper_id']>0){ foreach ($paperTopic as $item){ $paperTopicRelation[$item['order']]=$item['topic_id']; } }else{ foreach ($paperTopic as $item){ if(isset($alias[$item['order']])){ $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$alias[$item['order']]); }else{ $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$item['order']); } } } $data['qxk_paper_id']=$examGroup['qxk_paper_id']; $data['paper_topic']=$paperTopicRelation; $data['classes']=$classes; //加载设置数据 $topicSetting=array(); if(count($examIds)==1){ //只有一个班 $examPushTopic=SExamPushTopicsSetting::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0])); if($examPushTopic){ $topicSetting=json_decode($examPushTopic['topic_ids'],true); } } $data['topic_setting']=$topicSetting; $result['status']=1; $result['data']=$data; exit(jsonEncode($result)); } /*保存考试试题推送配置*/ public function actionSaveExamPushTopicSetting(){ $examGroupId = Req::post('examGroupId'); $examIds = Req::post('examIds'); $topics=Req::post('topics'); $result=array(); $result['status']=0; if(!$examIds || !is_numeric($examGroupId) ){ $result['msg']="参数异常"; exit(jsonEncode($result)); } if(!$topics) $topics=array(); if(!is_array($examIds)){ $examIds=explode(',',$examIds); } $examPushTopicModel=new SExamPushTopicsSetting(); $examPushTopicModel->updateSettingBatch($examIds,$examGroupId,$topics); $result['status']=1; exit(jsonEncode($result)); } /*加载考试班级*/ public function actionLoadExamClass(){ $examGroupId = Req::post('examGroupId'); $result['status']=0; if(!$examGroupId){ $result['msg']="参数异常"; exit(jsonEncode($result)); } $exam=$this->schoolManager->getExportClassByExamGroupId($examGroupId); if(!$exam){ $result['msg']="未查询到考试信息"; exit(jsonEncode($result)); } $uploaded=array(); $noUploaded=array(); foreach ($exam as $value){ if($value['upload_status']==0){ $noUploaded[]=array( 'exam_id'=>$value['exam_id'], 'class_id'=>$value['class_id'], 'class_name'=>$value['class_name'] ); }else{ $uploaded[]=array( 'exam_id'=>$value['exam_id'], 'class_id'=>$value['class_id'], 'class_name'=>$value['class_name'] ); } } $result['status']=1; $result['uploaded']=$uploaded; $result['no_uploaded']=$noUploaded; exit(jsonEncode($result)); } /*删除指定班级未上传考生*/ public function actionDelStudentPaperRelation(){ $examIds = Req::post('examIds'); $result['status']=0; if(!$examIds){ $result['msg']="参数异常"; exit(jsonEncode($result)); } if($this->schoolManager->delStudentPaperByExamId($examIds)){ $result['status']=1; $result['msg']="删除成功"; exit(jsonEncode($result)); }else{ $result['msg']="删除失败"; exit(jsonEncode($result)); } } //客户端打印订单学生在线答题卡 public function actionPrintPdfOnlineByOrder(){ $examId=Req::post('exam_id'); $result['success']=0; if(!$examId || !is_numeric($examId)){ $result['msg']='参数不正确'; exit(json_encode($result)); } $examInfo = Exam::model()->findByPk($examId); if(!$examInfo){ $result['msg']='未找到考试信息'; exit(json_encode($result)); } $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id); if(!$onlineCard){ $result['msg']='考试还没有使用在线答题卡'; exit(json_encode($result)); } //检查订单 $orderClass=0; $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll(); if($allClassStudents){ foreach ($allClassStudents as $student){ $students[]=$student['student_id']; if(!$orderClass) $orderClass=$student['class_id']; } } $semester=new SSemester(); $nowsem=$semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass)); $subjectId=Yii::app()->session['session_subject_id']; if(in_array($subjectId,$this->mathSubjectId)){ $subjectId=3; } $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$orderClass, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>array(), "examTime"=>time(), "classify"=>1, "subject"=>$subjectId, ); $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students); if(count($allClassStudents)>count($students)){ $result['all_order']=0; }else{ $result['all_order']=1; } if(!$students){ $result['msg']='当前班级没查询到订单'; exit(json_encode($result)); } //查询生成状态 $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll(); if(!$studentPdf){ $result['msg']='答题卡还未生成'; exit(json_encode($result)); } if(count($studentPdf)!=count($students)){ $result['all_created']=0; }else{ $result['all_created']=1; } $result['success']=1; $result['students']=$students; exit(json_encode($result)); } /*导出考试数据*/ public function actionExportExamData(){ $examGroupId = Req::post('examGroupId'); $params=array( 'examGroupId'=>$examGroupId, 'schoolId'=>$this->schoolId, 'reGenerate'=>1 ); $result['status']=0; $rs = http('/teacher/academic/report/download/exam-info','POST',$this->schoolId,$params,'cgi'); $rs=json_decode($rs,true); if(isset($rs['errCode']) && $rs['errCode']=='00' ){ if($rs['data']){ $result['status']=1; $result['data']=$rs['data']; }else{ $result['status']=2; } }else{ $result['msg']="接口处理异常:".$rs['errMsg']; } exit(jsonEncode($result)); } }