jump->error('非法访问!'); } $exam_data= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); $data['new_rules']=array(); if($exam_data) { $examGroup=SExamGroup::model()->find('exam_group_id=:exam_id',array(':exam_id'=>$exam_data['exam_group_id'])); $tpl_data=json_decode($exam_data->tpl_data,true); $isNewEnglish=isset($tpl_data['isNewEnglish'])?$tpl_data['isNewEnglish']:0; $subject=$exam_data->subject_id; $params=array( 'isFormat'=>0, 'isThird'=>$is_third, 'isNewEnglish'=>$isNewEnglish ); if($subject==8){ $params['isFormat']=1; } $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); $paper_topic_data = $this->schoolManager->getPaperTopics($paper_data->paper_id,$subject,$params,1); $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id))); if($topic_data) { foreach($topic_data as $k=>$v) { $topicType=$v->type; if($examGroup['qxk_paper_id']>0 && $is_third){ $topicType=$this->getTopicTypeForAllSubjectThird($topicType); } $topic_score_data[$v->topic_id] = $v->score; $topic_type_data[$topicType][$k] = array('order'=>$v->order,'topic_id'=>$v->topic_id,'score'=>$v->score); if($v->question_count>0){ $questionCount[$v->order]=$v->question_count; $questionScore[$v->order]=$v->question_score_str; $scoresType[$v->order]=1; } } } if($is_third){ $thirdAnswerSheet=$this->sConn->createCommand("select sheet_answer from third_answer_sheet where exam_group_id='{$exam_data->exam_group_id}'")->queryRow(); if($thirdAnswerSheet) { $sheet_answer = json_decode($thirdAnswerSheet['sheet_answer'], true); $data['sheet_answer'] = $sheet_answer; } } if($subject==8){ if(!$is_third && $paper_topic_data) { foreach($paper_topic_data as $val) { if(isset($val['slave']) && $val['slave']){ foreach ($val['slave'] as $v){ $_paper_topic_data[(string)$v['topic_slave_id']]=array( 'topic_id'=>$v['topic_slave_id'], 'title'=>$val['queBody'], 'answer'=>$v['answer'], ); if(isset($val['type'])){ $_paper_topic_data[(string)$v['topic_slave_id']]['type']=$val['type']; } } } } }else{ $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K',11=>'L',12=>'M'); //读模板里面的数据 if(isset($thirdAnswerSheet)){ if($topic_data) { foreach($topic_data as $k=>$v) { if(isset($sheet_answer[$v->order])){ $itemOptions=array(); //读取校本题库选项 $schoolTopicOption=$this->sConn->createCommand("select topic_id,option_correct,option_content from topic_item_option where topic_id='{$v->topic_id}'")->queryAll(); $right=array(); if($schoolTopicOption){ foreach ($schoolTopicOption as $ok => $opt){ if($opt['option_correct']==1){ // $right[]=$arr[$ok]; $right[]=numToLetter($ok+1); } } } $itemOptions[]['options']=$schoolTopicOption; $answer=$right?implode(',',$right):$sheet_answer[$v->order]; $_paper_topic_data[(string)$v->topic_id]=array( 'topic_id'=>$v->topic_id, 'title'=>'', 'answer'=>$answer, 'items'=>$itemOptions ); } } } } } }else{ // if(in_array($subject,array(18,19)) && isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $val){ if(isset($val['subject'])){ $topic_subject_data[$val['id']]=$val['subject']; } } } if($paper_topic_data) { foreach($paper_topic_data as $v) { $_paper_topic_data[(string)$v['id']] = $v; } } } //读取新规则 if(isset($tpl_data['new_rules'])){ $data['new_rules'] = $tpl_data['new_rules']; foreach ($data['new_rules'] as $key => $datum){ if(isset($topic_score_data[$datum['topic_id']]) && $datum['rule_score'] ){ $topic_score_data[$datum['topic_id']]=$datum['rule_score']; //分数以修改后规则分数为主 } } } //读取单选题更新答案记录 if(isset($tpl_data['update_answer'])){ $data['update_answer'] = $tpl_data['update_answer']; } //读取别名 if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $val){ if(isset($val['alias'])){ $alias[$val['id']] = $val['alias']; } } } //读取送分题/0分题 if(isset($tpl_data['send_points'])){ $data['send_points'] = $tpl_data['send_points']; } //读取小问小空类型 if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $val){ if(isset($val['scoresType']) && isset($scoresType[$val['id']])){ $scoresType[$val['id']]=$val['scoresType']; } } } } $data['paper_id'] = $paper_data->paper_id; $data['topic'] = $_paper_topic_data; $data['score'] = $topic_score_data; $data['type'] = $topic_type_data; $data['exam_id'] = $exam_id; $data['is_third'] = $is_third; $data['subject'] = $subject; $data['exam_name'] = $exam_data->name; $data['topic_subject_data']=$topic_subject_data; $data['alias'] = $alias; $data['question_count'] = $questionCount; $data['question_scores'] = $questionScore; $data['score_type'] = $scoresType; //批量修改单选题分数,数据处理 $choiceQuestionScoreSum=0; if(isset($topic_type_data[1])){ foreach ($topic_type_data[1] as $item){ $choiceQuestionScoreSum+=$item['score']; } } $data['choice_question_score_sum']=$choiceQuestionScoreSum; // debug($data); if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){ $data['subjects']=Yii::app()->params['subjectId']; unset($data['subjects'][3]); unset($data['subjects'][6]); unset($data['subjects'][51]); unset($data['subjects'][9]); unset($data['subjects'][8]); unset($data['subjects'][18]); unset($data['subjects'][19]); if(isset($data['subjects'][20])) unset($data['subjects'][20]); } $this->renderPartial("index",$data); } public function actionRecover() { $exam_id = Req::get('exam_id'); $_exam_id = Req::post('exam_id'); if(!$exam_id) { $exam_id = $_exam_id; } $_select = 0; $exam_ids = array(); if($exam_id>0) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); // $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); // 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) // { // if($v->type>1) // { // $_select = 1; // } // } // } // } // if($_select==0) // { // if($_exam_id){ // echo json_encode(array('status'=>0,'msg'=>'只有选择题的试卷无法恢复'));exit; // } // // echo "
只有选择题的试卷无法恢复!
";exit; // // } $exam_datas = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); if($exam_datas) { foreach($exam_datas as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } } $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); if(!$exam_group) { if($_exam_id){ echo json_encode(array('status'=>0,'msg'=>'考试数据有误!'));exit; } } if($exam_group->mark_type==0) { if($_exam_id){ echo json_encode(array('status'=>0,'msg'=>'线下阅卷,无法恢复考试!'));exit; } echo "
线下阅卷,无法恢复考试!
";exit; } if($exam_data) { //操作日志 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( 'StudentPaperRelation'=>array( 'report_created'=>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, '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_plan_created'=>0, 'plan_topic_time'=>0, 'plan_id'=>null, 'wb_page_num'=>0, 'isp_page_num'=>0, 'wbisp_page_num'=>0, 'is_three_isp_download'=>0, 'is_two_isp_download'=>0, 'is_wrongbook_download'=>0, 'is_wrong_plan_created'=>0, 'studytrend_img_time'=>0, 'download_three_isp_time'=>0, 'download_two_isp_time'=>0, 'download_wrongbook_time'=>0, 'wrong_plan_id'=>null, 'wrong_plan_topic_time'=>0, ), 'exam'=>array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0), 'ExamGroup'=>array('mark_status'=>1,'upload_status'=>1), ))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $trans = $this->sConn->beginTransaction(); try{ if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); SStudentPaperRelation::model()->updateAll( array( 'report_created'=>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, '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_plan_created'=>0, 'plan_topic_time'=>0, 'plan_id'=>null, 'wb_page_num'=>0, 'isp_page_num'=>0, 'wbisp_page_num'=>0, 'is_three_isp_download'=>0, 'is_two_isp_download'=>0, 'is_wrongbook_download'=>0, 'is_wrong_plan_created'=>0, 'studytrend_img_time'=>0, 'download_three_isp_time'=>0, 'download_two_isp_time'=>0, 'download_wrongbook_time'=>0, 'wrong_plan_id'=>null, 'wrong_plan_topic_time'=>0, ), $criteria); SStudentPaperRelationProperty::model()->updateAll( array( 'is_studytrend_img'=>'', 'studytrend_img_path'=>'', 'studytrend_img_time'=>0, 'is_wb'=>0, 'wb_complete_time'=>'', 'is_isp'=>0, 'isp_complete_time'=>0, 'is_wbisp'=>0, 'wbisp_complete_time'=>0, 'is_enc_lang'=>'', 'is_studytrend'=>0, 'is_kps_analy'=>0, 'is_scoring_detail'=>'', 'is_tips'=>0, 'student_order_rate'=>'', 'wb_level'=>'', 'isp_level'=>'', 'wb_isp_level'=>'', ), $criteria); } $this->sConn->createCommand("update exam_product_status set is_create_html=0,html_path='',html_create_time=0,is_create_pdf=0,pdf_path='',pdf_create_time=0,is_download=0,download_time=0,pdf_page_num=0,pdf_sheet_num=0 where exam_id in(".implode(',',$exam_ids).")")->execute(); $this->sConn->createCommand("delete from can_generate_product where exam_id in(".implode(',',$exam_ids).")")->execute(); Exam::model()->updateAll(array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); if($exam_group->mark_status==0){ ExamGroup::model()->updateAll(array('is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); }else{ ExamGroup::model()->updateAll(array('mark_status'=>1,'is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); } // $rs=json_decode(http('/qxk/marking/exam/recover/'.$exam_data['exam_group_id'],'PUT',$this->schoolId,array(),'cgi'),true); if(isset($rs['errCode']) && $rs['errCode']=='00'){ $trans->commit(); }else{ throw new Exception($rs['errMsg']); } if($exam_group->homework==1) { //发送学生端消息 $sendJsonArr = array( 'school_id' => $this->schoolId, 'send_type' => 'zsyas', 'update_type' => 5, 'exam_group_id' => $exam_data['exam_group_id'], ); sendStudentCacheQueue($sendJsonArr); } }catch(Exception $e) { $trans->rollBack(); if($_exam_id){ echo json_encode(array('status'=>0,'msg'=>'异常数据,无法写入!'));exit; } if($e->getMessage()){ echo "
".$e->getMessage()."
";exit; }else{ echo "
失败
";exit; } } } } if($_exam_id){ echo json_encode(array('status'=>1,'msg'=>'成功'));exit; } echo "
成功
";exit; } public function actionUp() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $order = Req::post('order'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$order || !$type) { echo json_encode(array('status'=>-1));exit; } /*$topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and `type`='.$type.' and `order` =:order','params'=>array(':paper_id'=>$paper_id,':order'=>$order-1)));*/ $topic_data = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paper_id}' and `type` = ".$type." and `order` < ".$order." order by `order` desc limit 1")->queryRow(); if(empty($topic_data)) { echo json_encode(array('status'=>0));exit; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tpl_data = json_decode($exam_data->tpl_data,1); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ $sql='update `paper_topic_relation` set `order` = '.($topic_data['order']).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id; $this->sConn->createCommand($sql)->execute(); $sql='update `paper_topic_relation` set `order` = '.($order).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_data['topic_id']; $this->sConn->createCommand($sql)->execute(); $trans->commit(); } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0));exit; } unset($trans); $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id','params'=>array(':paper_id'=>$paper_id))); if($paper_topic_data) { foreach($paper_topic_data as $k=>$v) { if($v->type != 1 ||$v->type != 11) { $type_score[$v->type][] = $v->score; } } if($type_score) { foreach($type_score as $k=>$v) { if(isset($tpl_data['items'][$k]) && !empty($tpl_data['items'][$k])) { $tpl_data['items'][$k]['perScores'] = $v; } } } $json_tpl_data = jsonEncode($tpl_data); $tran = $this->sConn->beginTransaction(); try{ $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); $tran->commit(); } catch(Exception $e){ $tran->rollBack(); echo json_encode(array('status'=>0));exit; } } echo json_encode(array('status'=>0));exit; } } } } } } public function actionDown() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $order = Req::post('order'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$order) { echo json_encode(array('status'=>-1));exit; } //$topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and `type`='.$type.' and `order` =:order','params'=>array(':paper_id'=>$paper_id,':order'=>$order+1))); $topic_data = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paper_id}' and `type` = ".$type." and `order` > ".$order." order by `order` asc limit 1")->queryRow(); if(empty($topic_data)) { echo json_encode(array('status'=>0));exit; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); $type_score = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tpl_data = json_decode($exam_data->tpl_data,1); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ $sql='update `paper_topic_relation` set `order` = '.($topic_data['order']).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id; $this->sConn->createCommand($sql)->execute(); $sql='update `paper_topic_relation` set `order` = '.($order).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_data['topic_id']; $this->sConn->createCommand($sql)->execute(); $trans->commit(); } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0));exit; } unset($trans); $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id','params'=>array(':paper_id'=>$paper_id))); if($paper_topic_data) { foreach($paper_topic_data as $k=>$v) { if($v->type != 1 ||$v->type != 11 ) { $type_score[$v->type][] = $v->score; } } if($type_score) { foreach($type_score as $k=>$v) { if(isset($tpl_data['items'][$k]) && !empty($tpl_data['items'][$k])) { $tpl_data['items'][$k]['perScores'] = $v; } } } $json_tpl_data = jsonEncode($tpl_data); $tran = $this->sConn->beginTransaction(); try{ $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); $tran->commit(); } catch(Exception $e){ $tran->rollBack(); echo json_encode(array('status'=>0));exit; } } } } } } } } public function actionScore() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $score = Req::post('score'); $type = Req::post('type'); $question_count = Req::post('question_count'); //小问 $question_score = Req::post('question_score'); //小问 if(!$paper_id || !$topic_id || !$type || !$score) { echo json_encode(array('status'=>-1));exit; } $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id))); $type_score = array(); $paper_score = 0; $score_diff=0; //分差 if(empty($topic_data)) { echo json_encode(array('status'=>0));exit; } $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id','params'=>array(':paper_id'=>$paper_id))); if($paper_topic_data) { foreach($paper_topic_data as $v) { $type_score[$v->type][$v['order']] = $v['score']; } } $score_diff=$score-$topic_data->score; $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tpl_data = json_decode($exam_data->tpl_data,1); if($score_diff==0){ if($question_count>0){ //只改小问 if(isset($tpl_data['new_items'])){ $tpl_data['new_items'][($topic_data->order-1)]['scores']=$question_score; } $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); foreach($exam_group_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); if ($paper_data) { foreach ($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } } } $trans = $this->sConn->beginTransaction(); try{ $sql='update `paper_topic_relation` set `question_count`='.$question_count.',`question_score_str`="'.$question_score.'" where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id; $this->sConn->createCommand($sql)->execute(); $sql="update `exam` set `tpl_data` = '".(jsonEncode($tpl_data))."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); $trans->commit(); echo json_encode(array('status'=>1,'score'=>$score));exit; }catch (\Exception $e){ $trans->rollback(); echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit; } }else{ echo json_encode(array('status'=>0,'msg'=>'分数与原分数相同'));exit; } } $perScores=array(); $old_paper_score = $paper_data->score; if($topic_data->type==17||$topic_data->type==27){ $_score = 0; if(isset($tpl_data['items'][$topic_data->type]['perScores']) && !empty($tpl_data['items'][$topic_data->type]['perScores'])){ $_score = $tpl_data['items'][$topic_data->type]['perScores'][0]; } if(isset($tpl_data['items'][$topic_data->type]['score']) && !empty($tpl_data['items'][$topic_data->type]['score'])){ $_score = $tpl_data['items'][$topic_data->type]['score']; } if(isset($tpl_data['items'][$topic_data->type]['perScore']) && !empty($tpl_data['items'][$topic_data->type]['perScore'])){ $_score = $tpl_data['items'][$topic_data->type]['perScore']; } if(isset($tpl_data['items'][$topic_data->type]['required']) && !empty($tpl_data['items'][$topic_data->type]['required'])){ $paper_score = $old_paper_score-($tpl_data['items'][$topic_data->type]['required']*$_score)+($tpl_data['items'][$topic_data->type]['required']*$score); } if(isset($tpl_data['items'][$topic_data->type]['score']) && !empty($tpl_data['items'][$topic_data->type]['score'])) { $tpl_data['items'][$topic_data->type]['score'] = $score; } if(isset($tpl_data['items'][$topic_data->type]['perScore']) && !empty($tpl_data['items'][$topic_data->type]['perScore'])){ $tpl_data['items'][$topic_data->type]['perScore'] = $score; } if(isset($tpl_data['items'][$topic_data->type]['perScores']) && !empty($tpl_data['items'][$topic_data->type]['perScores'])){ foreach ($tpl_data['items'][$topic_data->type]['perScores'] as $key => $datum){ $tpl_data['items'][$topic_data->type]['perScores'][$key]=$score; } } }else{ foreach ($type_score[$topic_data->type] as $k => $val){ if($k==$topic_data->order){ $perScores[]=$score; }else{ $perScores[]=$val; } } $paper_score = $old_paper_score-$topic_data->score+$score; $tpl_data['items'][$topic_data->type]['perScores']=$perScores; if(isset($tpl_data['items'][$topic_data->type]['perScore'])) { unset($tpl_data['items'][$topic_data->type]['perScore']); }elseif(isset($tpl_data['items'][$topic_data->type]['score'])){ unset($tpl_data['items'][$topic_data->type]['score']); } if(isset($tpl_data['items'][$topic_data->type]['totalScore']) && !empty($tpl_data['items'][$topic_data->type]['totalScore'])){ $tpl_data['items'][$topic_data->type]['totalScore'] = array_sum($perScores); } } //修改new_items if(isset($tpl_data['new_items'])){ if($topic_data->type==17||$topic_data->type==27){ //选做题 if(isset($tpl_data['new_items'][($topic_data->order-1)]['showNum'])){ $showNum=$tpl_data['new_items'][($topic_data->order-1)]['showNum']; foreach ($tpl_data['new_items'] as $key =>$datum){ if($datum['showNum']==$showNum){ $tpl_data['new_items'][$key]['score']=$score; } } }else{ $showNum=intval($tpl_data['new_items'][($topic_data->order-1)]['alias']); foreach ($tpl_data['new_items'] as $key =>$datum){ if(intval($datum['alias'])==$showNum){ $tpl_data['new_items'][$key]['score']=$score; } } } }else{ $tpl_data['new_items'][($topic_data->order-1)]['score']=$score; if($question_score){ $tpl_data['new_items'][($topic_data->order-1)]['scores']=$question_score; } } }else{ $tpl_data= $this->createNewItems($tpl_data); } $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $paper_score=$this->sumTplDataScores($tpl_data,$examGroup->is_third); $tpl_data['total_score']=$tpl_data['scores']=$paper_score; $json_tpl_data = jsonEncode($tpl_data); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $needSendMsgForQXK=false; if($exam_group_data) { foreach($exam_group_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); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ if(in_array($topic_data->type,array(1,2,11))) { $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id; $this->sConn->createCommand($sql)->execute(); //修改学生得分 $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $this->sConn->createCommand($sql)->execute(); $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); } }elseif($topic_data->type==17 ||$topic_data->type==27){ $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `type` = '.$topic_data->type; $this->sConn->createCommand($sql)->execute(); $sql='update `marking_topic` set `topic_score` = '.$score.' where exam_group_id = '.$exam_data->exam_group_id.' and topic_type = '.$topic_data->type; $this->sConn->createCommand($sql)->execute(); $needSendMsgForQXK=true; }else { if($question_score){ $sql='update `paper_topic_relation` set `score` = '.$score.',`question_count`='.$question_count.',`question_score_str`="'.$question_score.'" where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id; }else{ $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id; } $this->sConn->createCommand($sql)->execute(); $sql='update `marking_topic` set `topic_score` = '.$score.' where exam_group_id = '.$exam_data->exam_group_id.' and topic_id = '.$topic_id; $this->sConn->createCommand($sql)->execute(); $needSendMsgForQXK=true; } $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')'; $this->sConn->createCommand($sql)->execute(); $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); $trans->commit(); $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($examGroup['qxk_paper_id'] && $needSendMsgForQXK){ sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false); } } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0));exit; } 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)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>1,'score'=>$score));exit; } } } } } } private function paper_score($topic_type,$tpl_array) { if(!$topic_type || !$tpl_array) { return 0; } $scores = array(); // print_r($tpl_data);exit; foreach($topic_type as $v) { if( $tpl_array && isset($tpl_array['items'][$v]['required']) && !empty($tpl_array['items'][$v]['required'])) { $scores[$v] = $tpl_array['items'][$v]['score']*$tpl_array['items'][$v]['required']; }elseif(isset($tpl_array['items'][$v]) && !empty($tpl_array['items'][$v])){ if(isset($tpl_array['items'][$v]['perScores']) && !empty($tpl_array['items'][$v]['perScores'])) { if(is_array($tpl_array['items'][$v]['perScores'])) { $scores[$v] = array_sum($tpl_array['items'][$v]['perScores']); }else { if(isset($tpl_array['items'][$v]['score'])) { $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['score']; }else { $scores[$v] = 0; } } }elseif(isset($tpl_array['items'][$v]['perScore']) && !empty($tpl_array['items'][$v]['perScore'])) { $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['perScore']; }else{ if(isset($tpl_array['items'][$v]['score'])) { $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['score']; }else { $scores[$v] = 0; } } }else{ $scores[$v] = 0; } } return array_sum($scores); } private function jsonEncode($arr) { $jsonSupport = version_compare(PHP_VERSION, '5.4', '>='); if ($jsonSupport) { $result = json_encode($arr, JSON_UNESCAPED_UNICODE); } else { $result = json_encode($arr); $result = preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $result); } return $result; } public function actionAnswer() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$answer || !$type) { echo -2;exit; } if($type==1) { $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if($paper_data) { $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type',array(':paper_id'=>$paper_id,':topic_id'=>$topic_id,':type'=>$type)); if(!$paper_student_data) { echo -3;exit; } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $rs = apiPost(Yii::app()->params['get_api_url'].'/rest/reset/topic_answer', array( "schoolId" => $this->schoolId, "examGroupId" => $exam_data->exam_group_id, "topicId" => $topic_id, "answer" => $answer )); $result = json_decode($rs,1); if(!$result) { echo -4;exit; } if(isset($result['success']) && $result['success']<1) { echo -5;exit; }else { echo 1;exit; } } } } echo 0;exit; } public function actionUpdate_answer() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$answer || !$type) { echo -2;exit; } if($type != 1) { echo -3;exit; } $answer_type = array( 'A','B','C','D' ); if(!in_array($answer,$answer_type)) { echo -4;exit; } $sort_order = array_search($answer,$answer_type); $topic_data = STopic::model()->find('topic_id=:topic_id and topic_type=:topic_type',array(':topic_id'=>$topic_id,':topic_type'=>$type)); if(!$topic_data) { echo -1;exit; } $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$topic_id))); if($topic_option_data) { $flags = 0; $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$topic_id)); if($flags) { $flags = 0; $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order=:sort_order',array(':topic_id'=>$topic_id,':sort_order'=>$sort_order)); $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$topic_id)); if($topic_item_option) { $topicInfo = Yii::app()->school_topic_cache->hmget('content:school_topic:'.$topic_id,array( 'id','type_id','title','school_id','type_name','difficulty', 'subject_id','create_time','update_time','subject_name','teacher_tips', 'source','relation_topic','teaching_quality','source_title','parse_video','parse_content','difficulty_degree','kps','specials','items')); $topic_array = array(); if($topicInfo) { $options = array(); foreach($topic_item_option as $k=>$v) { $options[$k]['topic_id'] = $v->topic_id; $options[$k]['option_id'] = $v->option_id; $options[$k]['option_content'] = $v->option_content; $options[$k]['option_correct'] = $v->option_correct; $options[$k]['option_score'] = $v->option_score; $options[$k]['sort_order'] = $v->sort_order; } $topic_array['id'] = $topicInfo[0]; $topic_array['type_id'] = $topicInfo[1]; $topic_array['title'] = $topicInfo[2]; $topic_array['school_id'] = $topicInfo[3]; $topic_array['type_name'] = $topicInfo[4]; $topic_array['difficulty'] = $topicInfo[5]; $topic_array['subject_id'] = $topicInfo[6]; $topic_array['create_time'] = $topicInfo[7]; $topic_array['update_time'] = $topicInfo[8]; $topic_array['subject_name'] = $topicInfo[9]; $topic_array['teacher_tips'] = $topicInfo[10]; $topic_array['source'] = $topicInfo[11]; $topic_array['relation_topic'] = $topicInfo[12]; $topic_array['teaching_quality'] = $topicInfo[13]; $topic_array['source_title'] = $topicInfo[14]; $topic_array['parse_video'] = $topicInfo[15]; $topic_array['parse_content'] = $topicInfo[16]; $topic_array['difficulty_degree'] = $topicInfo[17]; $topic_array['kps'] = $topicInfo[18]; $topic_array['specials'] = $topicInfo[19]; $topic_array['items'] = json_decode($topicInfo[20],1); $topic_array['items'][0]['options'] = $options; $topic_array['items'] = json_encode($topic_array['items']); Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_id,$topic_array); } } if($flags){ echo 1;exit; } } }else { echo -5;exit; } echo 0;exit; } /*修改多选题答案OR规则*/ public function actionChangeMulti(){ ini_set('memory_limit', '500M'); $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $type = Req::post('type'); $rule = Req::post('rule'); $score_m = Req::post('score_m'); $score_half_m = Req::post('score_half_m'); $step = Req::post('step'); //第几步操作 $needUpdatePaperScore=false; // 是否需要修改试卷的分数 $result=array( 'status'=>0 ); if(!$exam_id || !$topic_id || !$answer || !$type || !$rule) { exit(json_encode($result)); } if(!is_numeric($score_m)){ $result['msg']='分数必须为数值类型'; exit(json_encode($result)); } if(!$score_m){ $result['msg']='分数不能为空'; exit(json_encode($result)); }; // if(!$score_half_m && $rule!=1){ // $result['msg']='半对分数不能为空'; // exit(json_encode($result)); // }; if($score_half_m>$score_m){ $result['msg']='半对分数不能大于满分'; exit(json_encode($result)); }; if(!in_array($rule,array(1,2,3,4,5))){ $result['msg']='评分规则错误'; exit(json_encode($result)); } $ExamModel=new SExam(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']='考试ID错误1'; exit(json_encode($result)); } $Exam_GroupId=$ExamInfo['exam_group_id']; $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); $AllExamIds=array(); $tplData=array(); if($AllExam){ foreach($AllExam as $val){ if($val){ $AllExamIds[]=$val['exam_id']; if(!$tplData){ $tplData=json_decode($val['tpl_data'],true); } } } } if(!$AllExamIds){ $result['msg']='考试ID错误2'; exit(json_encode($result)); } $AllPaperIds=array(); $paperScore=array(); $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')'); if($AllPaper){ foreach ($AllPaper as $val){ $AllPaperIds[]=$val['paper_id']; $paperScore[$val['paper_id']]=$val['score']; } } if(!$AllPaperIds){ $result['msg']='考试ID错误3'; exit(json_encode($result)); } $Rs=array(); foreach ($AllPaperIds as $pid){ if($step==1){ //只更改了规则,修改数据只针对有错误的学生 $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id." and is_right=0"); }elseif($step==2){ //修改答案,影响范围是所有的学生 $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id); }elseif($step==3){ //改了分数,对所有学生有影响 $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id); }else{ $result['msg']='参数错误,超出允许修改范围'; exit(json_encode($result)); } if($tempData){ foreach ($tempData as $v){ $Rs[]=array( 'topic_id' =>$v['topic_id'], 'answer' =>$v['answer'], 'paper_id' =>$v['paper_id'], 'student_id' =>$v['student_id'], ); } } } $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and `type`='{$type}' ")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } //更新规则 $order=0; $tplRules=array(); if(isset($tplData['new_rules'])){ $tplRules=$tplData['new_rules']; } foreach ($paperTopicRelation as $value){ if($value['topic_id']==$topic_id){ $order=$value['order']; if(isset($tplRules[$value['order']]) && $tplRules[$order]['rule_score_half']!=$score_half_m && $step==3){ $needUpdatePaperScore=true; } if($value['score']!=$score_m && $step==3){ //需要修改试卷分数 $needUpdatePaperScore=true; $tplData['total_score']=$tplData['scores'] = $tplData['scores']-$value['score']+$score_m; } $tplRules[$value['order']]=array( 'topicNo'=>$value['order'], 'topic_id'=>$topic_id, 'rule_type'=>(int)$rule, 'rule_answer'=>$answer, 'rule_score'=>$score_m, 'rule_score_half'=>$score_half_m ); $perScores[]=$score_m; }else{ $perScores[]=$value['score']; } } $tplData['new_rules']=$tplRules; if($needUpdatePaperScore ){ if(isset($tplData['items'])){ $tplData['items'][$type]['perScores']=$perScores; if(isset($tplData['items'][$type]['perScore'])) { unset($tplData['items'][$type]['perScore']); }elseif(isset($tplData['items'][$type]['score'])){ unset($tplData['items'][$type]['score']); } if(isset($tplData['items'][$type]['totalScore']) && !empty($tplData['items'][$type]['totalScore'])){ $tplData['items'][$type]['totalScore'] = array_sum($perScores); } } if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $key => $val){ if($val['id']==$order){ $tplData['new_items'][$key]['score']=$score_m; } } } } //先更新校本题库试题答案 $rs=$this->UpdateTopicAnswer($topic_id,$answer,11); $msgTopicUpdate=''; if(!$rs){ $result['status']=0; $result['msg']='更新校本题库答案失败'; exit(json_encode($result)); }elseif($rs==-1){ $msgTopicUpdate='无题或不是校本题库的题'; } if($Rs){ foreach ($Rs as $k=> $v){ if($v['topic_id'] == $topic_id){ $update_data=array(); if(!$v['answer']){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ if($v['answer'] == $answer){ $update_data['scoring']=$score_m; $update_data['is_right']=1; }else{ switch ($rule){ case 1: //规则A 最严格规则 $update_data['scoring']=0; $update_data['is_right']=0; break; case 2://规则B 半对规则 //查找错误选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $FindWrong=false; foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $FindWrong=true; break; } } if($FindWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 3://规则C 宽松半对规则 //查找正确选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=true; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $IsWrong=false; break; } } } //错误答案情况 if($IsWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 4: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=false; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $IsWrong=true; break; } } }else{ $IsWrong=true; } //错误答案情况 if($IsWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ //没有错误答案,且不全对,几个答案几分 $score_half_m=count($tempAnswer); $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 5: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $rightAnswerCount=0; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $rightAnswerCount++; } } } $update_data['scoring']=$rightAnswerCount; $update_data['is_right']=0; //半对算错 break; } } } if($update_data && $v['paper_id'] && $v['student_id']){ $transaction = $this->sConn->beginTransaction(); try { $sql=" update `student_paper_topic_rs` set "; $updatesql=array(); foreach ($update_data as $filed=>$value){ $updatesql[]="`".$filed."` = '".$value."'"; } $sql.=implode(',',$updatesql); $sql.=" where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' and `topic_id`='".$topic_id."'"; $this->sConn->createCommand($sql)->execute(); //更新总分queryAll $TotalScore = $paperScore[$v['paper_id']]; $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' "; $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll(); $right_count = 0; $partial_right_count = 0; $wrong_count = 0; $scoring = 0; $lost_score = 0; foreach ($StudentAllTopic as $value) { if ($value['is_right'] == 1) { $right_count++; } elseif ($value['is_right'] == 2) { $partial_right_count++; } else { $wrong_count++; } $scoring = bcadd($scoring, $value['scoring'], 1); } unset($StudentAllTopic); $lost_score = bcsub($TotalScore, $scoring, 1); $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'"; $paperRelattionSql.=" where `paper_id`='".$v['paper_id']."' and `student_id`='".$v['student_id']."'"; $this->sConn->createCommand($paperRelattionSql)->execute(); $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; if(!$msgTopicUpdate){ $result['msg']='校本题库答案修改成功,报告更新失败'; }else{ $result['msg']=$msgTopicUpdate.' 报告更新失败'; } exit(json_encode($result)); } } } } } //修改分数,修改原试卷 $transaction = $this->sConn->beginTransaction(); try { if($needUpdatePaperScore){ $sql = 'update `paper_topic_relation` set `score` = ' . $score_m . ' where paper_id in (' . implode(',', $AllPaperIds) . ') and `topic_id` =' . $topic_id; $this->sConn->createCommand($sql)->execute(); $sql = 'update `paper` set `score` = ' . $tplData['scores'] . ' where paper_id in (' . implode(',', $AllPaperIds) . ')'; $this->sConn->createCommand($sql)->execute(); } $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id = '{$Exam_GroupId}'")->execute(); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); $result['status']=0; $result['msg']=' 更新失败'; exit(json_encode($result)); } $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$Exam_GroupId ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$Exam_GroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); $this->sendNoticeToReport($Exam_GroupId); 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)), "date"=>date('Y-m-d H:i:s') ))); } //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$Exam_GroupId, ); sendStudentCacheQueue($sendJsonArr); $result['status']=1; if($msgTopicUpdate){ $result['msg']=$msgTopicUpdate.' 报告更新完成'; }else{ $result['msg']='报告更新完成'; } exit(json_encode($result)); } //更新单选题答案new,同时更新试题 public function actionAnswerNew(){ $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$answer || !$type) { echo -2;exit; } if ($topic_id <= 0) { echo -2;exit; } $answer = strtoupper($answer); if (! preg_match('/[A-Z]{1}/', $answer, $temp)) { echo -2;exit; } if($type==1){ $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if($paper_data) { $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type', array(':paper_id' => $paper_id, ':topic_id' => $topic_id, ':type' => $type)); if (!$paper_student_data) { echo -3; exit; } $queries = array(); $paperIds = array(); $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data){ $tplData=json_decode($exam_data->tpl_data,true); $tplData['update_answer'][$paper_student_data['order']]=array( 'order'=>$paper_student_data['order'], 'topic_id'=>$topic_id, 'update_answer'=>$answer ); $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'"; $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' "; $papers=$this->sConn->createCommand($PaperSql)->queryAll(); if ($papers) { foreach ($papers as $k => $v) { $paperIds[] = $v['paper_id']; } $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'"; $ptr=$this->sConn->createCommand($ptrSql)->queryRow(); if ($ptr) { $score = $ptr['score']; $studentIds_Right = array(); $studentIds_Wrong = array(); //更新选错了,但标为正确答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Wrong[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';"; } //更新原本选对了,但标为错误答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Right[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';"; } } } } 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)), "date"=>date('Y-m-d H:i:s') ))); } $flag=$this->UpdateTopicAnswer($topic_id,$answer,1); $this->sendNoticeToReport($exam_data->exam_group_id); if(!$flag){ // echo -6;exit; } if($queries){ $transaction = $this->sConn->beginTransaction(); try { foreach ($queries as $query) { $this->sConn->createCommand($query)->execute(); } //更新试题答案 $transaction->commit(); $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); echo 1;exit; } catch (Exception $e) { $transaction->rollback(); echo -5;exit; } }else{ echo -7;exit; } } } echo 0;exit; } //更新单选题答案,不更新试题 public function actionAnswerNewNoUpdateTopic(){ $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $type = Req::post('type'); if(!$paper_id || !$topic_id || !$answer || !$type) { echo -2;exit; } if ($topic_id <= 0) { echo -2;exit; } $answer = strtoupper($answer); if (! preg_match('/[A-Z]{1}/', $answer, $temp)) { echo -2;exit; } if($type==1){ $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if($paper_data) { $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type', array(':paper_id' => $paper_id, ':topic_id' => $topic_id, ':type' => $type)); if (!$paper_student_data) { echo -3; exit; } $queries = array(); $paperIds = array(); $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data){ $tplData=json_decode($exam_data->tpl_data,true); $tplData['update_answer'][$paper_student_data['order']]=array( 'order'=>$paper_student_data['order'], 'topic_id'=>$topic_id, 'update_answer'=>$answer ); $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'"; $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' "; $papers=$this->sConn->createCommand($PaperSql)->queryAll(); if ($papers) { foreach ($papers as $k => $v) { $paperIds[] = $v['paper_id']; } $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'"; $ptr=$this->sConn->createCommand($ptrSql)->queryRow(); if ($ptr) { $score = $ptr['score']; $studentIds_Right = array(); $studentIds_Wrong = array(); //更新选错了,但标为正确答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Wrong[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';"; } //更新原本选对了,但标为错误答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Right[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';"; } } } } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $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" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $this->sendNoticeToReport($exam_data->exam_group_id); if($queries){ $transaction = $this->sConn->beginTransaction(); try { foreach ($queries as $query) { $this->sConn->createCommand($query)->execute(); } //更新试题答案 $transaction->commit(); $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); echo 1;exit; } catch (Exception $e) { $transaction->rollback(); echo -5;exit; } }else{ echo -7;exit; } } } echo 0;exit; } //修改试题答案 private function UpdateTopicAnswer($TopicId,$Answer,$type){ $answer_type = array( 'A','B','C','D','E','F','G','H','I','J' ); if(!in_array($type,array(1,2,11))) return false; if($type==1 && !in_array($Answer,$answer_type)) { return false; } if(($type==11 || $type==2) && !preg_match('/^[A-Z,]+$/u',$Answer)){ return false; } if($type==1){ $sort_order[] = array_search($Answer,$answer_type); }else{ $answers=explode(',',$Answer); if(!$answers){ return false; } $answer_type=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); foreach ($answers as $a){ $a=strtoupper($a); $sort_order[] = array_search($a,$answer_type); } } $topic_data = STopic::model()->find('topic_id=:topic_id ',array(':topic_id'=>$TopicId)); if(!$topic_data) { return -1; //不是校本题库的题 } $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$TopicId))); if($topic_option_data) { //判断答案范围 $sortOrderArr=array(); foreach ($sort_order as $st){ if(($st+1)>count($topic_option_data)){ return false; } if($st!==false){ $sortOrderArr[]=$st; } } if(!$sortOrderArr){ return false; } //异常情况,试题没有答案情况判断 $NoAnswer=true; foreach ($topic_option_data as $datum){ if($datum->option_correct==1){ $NoAnswer=false; break; } } $flags = 1; if(!$NoAnswer){ $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$TopicId)); } if($flags && $sortOrderArr){ $flags = 0; $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order in ('.implode(',',$sortOrderArr).')',array(':topic_id'=>$TopicId)); $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$TopicId)); if($topic_item_option) { //清缓存 Yii::app()->school_topic_cache->hmset('content:school_topic:'.$TopicId,array('id' => 0)); if($topic_data->stem_id){ Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_data->stem_id,array('id' => 0)); } } if($flags){ return true; } } } return false; } //修改学生答案 public function actionEditStudentAnswer(){ $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); $old_answer = Req::post('old_answer'); $topic_answer = Req::post('topic_answer'); if(!$exam_id || !$topic_id || !$answer ) { echo -2;exit; } if ($topic_id <= 0) { echo -2;exit; } $answer = strtoupper($answer); if (! preg_match('/[A-H]{1}/', $answer, $temp)) { echo -1;exit; } if($old_answer && !preg_match('/[A-H]{1}/', $answer, $temp)){ echo -1;exit; } if($answer==$old_answer){ echo -6;exit; } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); if($exam_data){ $exam_group_id=$exam_data->exam_group_id; $ExamAll_sql="select exam_id from exam where exam_group_id='".$exam_group_id."'"; $ExamAll=$this->sConn->createCommand($ExamAll_sql)->queryAll(); $ExamIds=array(); if($ExamAll){ foreach ($ExamAll as $val){ $ExamIds[]=$val['exam_id']; } $P_sql="select paper_id from paper where exam_id in(".implode(',',$ExamIds).")"; $PaperAll=$this->sConn->createCommand($P_sql)->queryAll(); $paperIds=array(); if($PaperAll){ foreach($PaperAll as $item){ $paperIds[]=$item['paper_id']; } $ptrSql="SELECT `score`,`order` FROM paper_topic_relation WHERE paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'"; $ptr=$this->sConn->createCommand($ptrSql)->queryRow(); if ($ptr) { $score = $ptr['score']; $order = $ptr['order']; $queries=array(); if(!$topic_answer){ //没有答案,读取模板设置的答案 $third_answer_sheet=$this->sConn->createCommand("select sheet_answer from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow(); $sheetAnswer=json_decode($third_answer_sheet['sheet_answer'],true); if(isset($sheetAnswer[$order])){ $topic_answer=$sheetAnswer[$order]; } } if(!$topic_answer){ echo -5;exit; } $is_right=0; if($topic_answer==$answer){ $is_right=1; } //查询所有不是新答案的学生 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' "; if($old_answer){ $old_answer=strtoupper($old_answer); $sptrSql.=" AND `answer`='".$old_answer."'"; }else{ $sptrSql.=" AND `answer`!='".$answer."'"; } $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if($sptr){ $studentIds=array(); $onlyUpdateAnswerStudentIds=array(); foreach ($sptr as $k => $v) { if(!$is_right){ //不小心更新的是错误的答案,原来答对的学生,需被要扣分,答错的,只需要更新答案不再扣分 if($v['is_right']==1){ $studentIds[] = $v['student_id']; }else{ $onlyUpdateAnswerStudentIds[]=$v['student_id']; } }else{ $studentIds[] = $v['student_id']; } } if($is_right && $studentIds){ $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score .",answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .") AND topic_id = '". $topic_id ."';"; }else{ if($studentIds){ $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0,answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .") AND topic_id = '". $topic_id ."';"; } if($onlyUpdateAnswerStudentIds){ $queries[] = "UPDATE student_paper_topic_rs SET answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $onlyUpdateAnswerStudentIds) .") AND topic_id = '". $topic_id ."';"; } } } if($queries){ $transaction = $this->sConn->beginTransaction(); try { foreach ($queries as $query) { $this->sConn->createCommand($query)->execute(); } //更新学生试题答案 $transaction->commit(); $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); echo 1;exit; } catch (Exception $e) { $transaction->rollback(); echo -4;exit; } }else{ echo -7;exit; } } 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:s') ))); } echo 1;exit; //修改成功 } } } echo -4;exit; } //单个班级恢复考试 public function actionRecover_one_class() { $exam_id = Req::post('exam_id'); $_select = 0; if($exam_id>0) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); // $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id)); // 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) // { // if($v->type>1) // { // $_select = 1; // } // } // } // } // if($_select==0) // { // if($exam_id){ // echo json_encode(array('status'=>0,'msg'=>'只有选择题的试卷无法恢复'));exit; // } // echo "
只有选择题的试卷无法恢复
";exit; // // } $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); if(!$exam_group) { if($exam_id){ echo json_encode(array('status'=>0,'msg'=>'考试数据有误!'));exit; } } if($exam_group->mark_type!=4) { if($exam_id){ echo json_encode(array('status'=>0,'msg'=>'非班级单独阅卷考试不能恢复!'));exit; } } if($exam_data) { //操作日志 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( 'StudentPaperRelation'=>array( 'report_created'=>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, '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_plan_created'=>0, 'plan_topic_time'=>0, 'plan_id'=>null, 'wb_page_num'=>0, 'isp_page_num'=>0, 'wbisp_page_num'=>0, 'is_three_isp_download'=>0, 'is_two_isp_download'=>0, 'is_wrongbook_download'=>0, 'is_wrong_plan_created'=>0, 'studytrend_img_time'=>0, 'download_three_isp_time'=>0, 'download_two_isp_time'=>0, 'download_wrongbook_time'=>0, 'wrong_plan_id'=>null, 'wrong_plan_topic_time'=>0, ), 'exam'=>array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0), 'ExamGroup'=>array('mark_status'=>1,'upload_status'=>1), ))), "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $trans = $this->sConn->beginTransaction(); try{ $criteria = new CDbCriteria(); $criteria->addCondition("exam_id='".$exam_id."'"); SStudentPaperRelation::model()->updateAll( array( 'report_created'=>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, '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_plan_created'=>0, 'plan_topic_time'=>0, 'plan_id'=>null, 'wb_page_num'=>0, 'isp_page_num'=>0, 'wbisp_page_num'=>0, 'is_three_isp_download'=>0, 'is_two_isp_download'=>0, 'is_wrongbook_download'=>0, 'is_wrong_plan_created'=>0, 'studytrend_img_time'=>0, 'download_three_isp_time'=>0, 'download_two_isp_time'=>0, 'download_wrongbook_time'=>0, 'wrong_plan_id'=>null, 'wrong_plan_topic_time'=>0, ), $criteria); SStudentPaperRelationProperty::model()->updateAll( array( 'is_studytrend_img'=>'', 'studytrend_img_path'=>'', 'studytrend_img_time'=>0, 'is_wb'=>0, 'wb_complete_time'=>'', 'is_isp'=>0, 'isp_complete_time'=>0, 'is_wbisp'=>0, 'wbisp_complete_time'=>0, 'is_enc_lang'=>'', 'is_studytrend'=>0, 'is_kps_analy'=>0, 'is_scoring_detail'=>'', 'is_tips'=>0, 'student_order_rate'=>'', 'wb_level'=>'', 'isp_level'=>'', 'wb_isp_level'=>'', ), $criteria); $this->sConn->createCommand("update exam_product_status set is_create_html=0,html_path='',html_create_time=0,is_create_pdf=0,pdf_path='',pdf_create_time=0,is_download=0,download_time=0,pdf_page_num=0,pdf_sheet_num=0 where exam_id ='".$exam_id."'")->execute(); $this->sConn->createCommand("delete from can_generate_product where exam_id ='".$exam_id."'")->execute(); Exam::model()->updateAll(array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0, 'is_topwb_pdf'=>0, 'is_academicr_html'=>0),'exam_id=:exam_id',array(':exam_id'=>$exam_id)); ExamGroup::model()->updateAll(array('mark_status'=>1,'is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id'])); // $rs=json_decode(http('/qxk/marking/exam/recover/'.$exam_data['exam_group_id'].'/clazz/'.$exam_data['class_id'],'PUT',$this->schoolId,array(),'cgi'),true); if(isset($rs['errCode']) && $rs['errCode']=='00'){ $trans->commit(); }else{ throw new Exception($rs['errMsg']); } //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>5, 'exam_group_id'=>$exam_data['exam_group_id'], 'exam_id_arr'=>array($exam_id), ); sendStudentCacheQueue($sendJsonArr); }catch(Exception $e) { $trans->rollBack(); if($exam_id){ echo json_encode(array('status'=>0,'msg'=>'异常数据,无法写入!'));exit; } echo "
失败
";exit; } } } if($exam_id){ echo json_encode(array('status'=>1,'msg'=>'成功'));exit; } echo "
成功
";exit; } /*修改多选题规则*/ public function actionChangeMultiRule(){ ini_set('memory_limit', '500M'); $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $type = Req::post('type'); $rule = Req::post('rule'); $score_m = Req::post('score_m'); $score_half_m = Req::post('score_half_m'); $answer = Req::post('answer'); $result=array( 'status'=>0 ); if(!$exam_id || !$topic_id || !$type || !$rule ) { exit(json_encode($result)); } if(!$score_m){ $result['msg']='分数不能为空'; exit(json_encode($result)); }; if(!$score_half_m && $rule!=1){ $result['msg']='半对分数不能为空'; exit(json_encode($result)); }; if($score_half_m>$score_m){ $result['msg']='半对分数不能大于满分'; exit(json_encode($result)); }; if(!in_array($rule,array(1,2,3,4,5))){ $result['msg']='评分规则错误'; exit(json_encode($result)); } $ExamModel=new SExam(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']='考试ID错误1'; exit(json_encode($result)); } $Exam_GroupId=$ExamInfo['exam_group_id']; $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); $AllExamIds=array(); $tplData=array(); if($AllExam){ foreach($AllExam as $val){ if($val){ $AllExamIds[]=$val['exam_id']; if(!$tplData){ $tplData=json_decode($val['tpl_data'],true); } } } } if(!$AllExamIds){ $result['msg']='考试ID错误2'; exit(json_encode($result)); } $AllPaperIds=array(); $paperScore=array(); $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')'); if($AllPaper){ foreach ($AllPaper as $val){ $AllPaperIds[]=$val['paper_id']; $paperScore[$val['paper_id']]=$val['score']; } } if(!$AllPaperIds){ $result['msg']='考试ID错误3'; exit(json_encode($result)); } $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and type in(2,11)")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } $Rs=array(); foreach ($AllPaperIds as $pid){ $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id); if($tempData){ foreach ($tempData as $v){ $Rs[]=array( 'topic_id' =>$v['topic_id'], 'answer' =>$v['answer'], 'paper_id' =>$v['paper_id'], 'student_id' =>$v['student_id'], ); } } } //先更新校本题库试题答案 $rs=$this->UpdateTopicAnswer($topic_id,$answer,11); $msgTopicUpdate=''; if(!$rs){ $result['status']=0; $result['msg']='更新校本题库答案失败'; exit(json_encode($result)); }elseif($rs==-1){ $msgTopicUpdate='无题或不是校本题库的题'; } if($Rs){ if(!$answer){ $result['msg']='答案不能为空'; exit(json_encode($result)); } foreach ($Rs as $k=> $v){ if($v['topic_id'] == $topic_id){ $update_data=array(); if(!$v['answer']){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ if($v['answer'] == $answer){ $update_data['scoring']=$score_m; $update_data['is_right']=1; }else{ switch ($rule){ case 1: //规则A 最严格规则 $update_data['scoring']=0; $update_data['is_right']=0; break; case 2://规则B 半对规则 //查找错误选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $FindWrong=false; foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $FindWrong=true; break; } } if($FindWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 3://规则C 宽松半对规则 //查找正确选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=true; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $IsWrong=false; break; } } } //错误答案情况 if($IsWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 4: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=false; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $IsWrong=true; break; } } }else{ $IsWrong=true; } //错误答案情况 if($IsWrong){ $update_data['scoring']=0; $update_data['is_right']=0; }else{ //没有错误答案,且不全对,几个答案几分 $score_half_m=count($tempAnswer); $update_data['scoring']=$score_half_m; $update_data['is_right']=0; //半对算错 } break; case 5: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $rightAnswerCount=0; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $rightAnswerCount++; } } } $update_data['scoring']=$rightAnswerCount; $update_data['is_right']=0; //半对算错 break; } } } if($update_data && $v['paper_id'] && $v['student_id']){ $transaction = $this->sConn->beginTransaction(); try { $sql=" update `student_paper_topic_rs` set "; $updatesql=array(); foreach ($update_data as $filed=>$value){ $updatesql[]="`".$filed."` = '".$value."'"; } $sql.=implode(',',$updatesql); $sql.=" where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' and `topic_id`='".$topic_id."'"; $this->sConn->createCommand($sql)->execute(); //更新总分queryAll $TotalScore = $paperScore[$v['paper_id']]; $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' "; $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll(); $right_count = 0; $partial_right_count = 0; $wrong_count = 0; $scoring = 0; $lost_score = 0; foreach ($StudentAllTopic as $value) { if ($value['is_right'] == 1) { $right_count++; } elseif ($value['is_right'] == 2) { $partial_right_count++; } else { $wrong_count++; } $scoring = bcadd($scoring, $value['scoring'], 1); } unset($StudentAllTopic); $lost_score = bcsub($TotalScore, $scoring, 1); $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'"; $paperRelattionSql.=" where `paper_id`='".$v['paper_id']."' and `student_id`='".$v['student_id']."'"; $this->sConn->createCommand($paperRelattionSql)->execute(); $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } } } } } //更新规则 $tplRules=array(); if(isset($tplData['new_rules'])){ $tplRules=$tplData['new_rules']; } foreach ($paperTopicRelation as $value){ if($value['topic_id']==$topic_id){ $tplRules[$value['order']]=array( 'topicNo'=>$value['order'], 'topic_id'=>$topic_id, 'rule_type'=>(int)$rule, 'rule_answer'=>Req::post('answer'), 'rule_score'=>'', //分数不修改传空,使用默认值 'rule_score_half'=>$score_half_m ); } } if($tplRules){ $tplData['new_rules']=$tplRules; $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute(); } $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$Exam_GroupId ); sendZsystNotic($sendParam); $this->sendNoticeToReport($Exam_GroupId); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$Exam_GroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $Exam_GroupId, "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)); } /*批量修改多选题规则*/ public function actionChangeMultiRuleBatch(){ ini_set('memory_limit', '500M'); $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $type = Req::post('type'); $rule = Req::post('rule'); $score_m = Req::post('score_m'); $score_half_m = Req::post('score_half_m'); $answer = Req::post('answer'); $result=array( 'status'=>0 ); if(!$exam_id || !$topic_id || !$type || !$rule) { exit(json_encode($result)); } // if(!$score_m){ // $result['msg']='分数不能为空'; // exit(json_encode($result)); // }; // if(!$score_half_m && $rule!=1){ // $result['msg']='半对分数不能为空'; // exit(json_encode($result)); // }; // if($score_half_m>$score_m){ // $result['msg']='半对分数不能大于满分'; // exit(json_encode($result)); // }; if(!in_array($rule,array(1,2,3,4,5))){ $result['msg']='评分规则错误'; exit(json_encode($result)); } $topicIdArr=explode('///',$topic_id); $topicAnswerArr=explode('///',$answer); $topicHalfScoreArr=explode('///',$score_half_m); if(!$topicIdArr || !$topicAnswerArr){ $result['msg']='批量读取试题异常'; exit(json_encode($result)); } $topicIdAnswer=array(); $topicIdHalfScore=array(); foreach ($topicIdArr as $key => $val){ if(!isset($topicAnswerArr[$key])){ $result['msg']='批量读取试题答案异常'; exit(json_encode($result)); }else{ $this->UpdateTopicAnswer($val,$topicAnswerArr[$key],11); $topicIdAnswer[$val]=$topicAnswerArr[$key]; $topicIdHalfScore[$val]=$topicHalfScoreArr[$key]; } } $ExamModel=new SExam(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']='考试ID错误1'; exit(json_encode($result)); } $Exam_GroupId=$ExamInfo['exam_group_id']; $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); $AllExamIds=array(); $tplData=array(); if($AllExam){ foreach($AllExam as $val){ if($val){ $AllExamIds[]=$val['exam_id']; if(!$tplData){ $tplData=json_decode($val['tpl_data'],true); } } } } if(!$AllExamIds){ $result['msg']='考试ID错误2'; exit(json_encode($result)); } $AllPaperIds=array(); $paperScore=array(); $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')'); if($AllPaper){ foreach ($AllPaper as $val){ $AllPaperIds[]=$val['paper_id']; $paperScore[$val['paper_id']]=$val['score']; } } if(!$AllPaperIds){ $result['msg']='考试ID错误3'; exit(json_encode($result)); } $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and type in(2,11)")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } $Rs=array(); $topicScoreArr=array(); $topicHalfScoreArr=array(); foreach ($paperTopicRelation as $value){ if($score_half_m>$value['score']){ $result['msg']='半对分数不能大于满分'; exit(json_encode($result)); } $topicScoreArr[$value['topic_id']]=$value['score']; } foreach ($AllPaperIds as $pid){ $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")"); if($tempData){ foreach ($tempData as $v){ $Rs[]=array( 'topic_id' =>$v['topic_id'], 'answer' =>$v['answer'], 'paper_id' =>$v['paper_id'], 'student_id' =>$v['student_id'], ); } } } $updateRightData=array(); $updateScoreData=array(); $updateStudentPaperRelation=array(); if($Rs){ if(!$answer){ $result['msg']='答案不能为空'; exit(json_encode($result)); } foreach ($Rs as $k=> $v){ if(!isset($topicIdAnswer[$v['topic_id']])){ continue; } $answer=$topicIdAnswer[$v['topic_id']]; if(!$v['answer']){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ if($v['answer'] == $answer){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']]; }else{ switch ($rule){ case 1: //规则A 最严格规则 $update_data['scoring']=0; $update_data['is_right']=0; $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; break; case 2://规则B 半对规则 //查找错误选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $FindWrong=false; foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $FindWrong=true; break; } } if($FindWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错 $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']]; } break; case 3://规则C 宽松半对规则 //查找正确选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=true; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $IsWrong=false; break; } } } //错误答案情况 if($IsWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错 $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']]; } break; case 4: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=false; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $IsWrong=true; break; } } }else{ $IsWrong=true; } //错误答案情况 if($IsWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ //没有错误答案,且不全对,几个答案几分 $score_half_m=count($tempAnswer); $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m; } break; case 5: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $rightAnswerCount=0; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $rightAnswerCount++; } } } $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount; break; } } } //更新总分queryAll $updateStudentPaperRelation[$v['student_id']]=$v['paper_id']; } } $updateStudentPaperRelationSql=array(); if($updateRightData){ $sqlIsRight=array(); $sqlScore=array(); foreach ($updateRightData as $paperId=>$val){ foreach ($val as $topicId=>$v){ $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` "; foreach ($v as $studentId=>$isRight){ $sql.=" WHEN ".$studentId." THEN '".$isRight."' "; } $sql.=" Else `is_right`"; $sql.=" End "; $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'"; $sqlIsRight[]=$sql; } } foreach ($updateScoreData as $paperId=>$val){ foreach ($val as $topicId=>$v){ $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` "; foreach ($v as $studentId=>$score){ $sql.=" WHEN ".$studentId." THEN '".$score."' "; } $sql.=" Else `scoring`"; $sql.=" End "; $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'"; $sqlScore[]=$sql; } } $transaction = $this->sConn->beginTransaction(); try { if($sqlIsRight){ foreach ($sqlIsRight as $sql){ $this->sConn->createCommand($sql)->execute(); } } if($sqlScore){ foreach ($sqlScore as $sql){ $this->sConn->createCommand($sql)->execute(); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } if($updateStudentPaperRelation){ foreach ($updateStudentPaperRelation as $studentId =>$paperId){ $TotalScore = $paperScore[$paperId]; $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' "; $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll(); $right_count = 0; $partial_right_count = 0; $wrong_count = 0; $scoring = 0; $lost_score = 0; foreach ($StudentAllTopic as $value) { if ($value['is_right'] == 1) { $right_count++; } elseif ($value['is_right'] == 2) { $partial_right_count++; } else { $wrong_count++; } $scoring = bcadd($scoring, $value['scoring'], 1); } unset($StudentAllTopic); $lost_score = bcsub($TotalScore, $scoring, 1); $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'"; $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'"; $updateStudentPaperRelationSql[]=$paperRelattionSql; } } $transaction = $this->sConn->beginTransaction(); try { if($updateStudentPaperRelationSql){ foreach ($updateStudentPaperRelationSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$Exam_GroupId ); $transaction->commit(); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$Exam_GroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } } //记录新判分规则 $tplRules=array(); if(isset($tplData['new_rules'])){ $tplRules=$tplData['new_rules']; } foreach ($paperTopicRelation as $value){ if(in_array($value['topic_id'],$topicIdArr)){ if(isset($tplRules[$value['order']])){ $tplRules[$value['order']]['rule_type']=(int)$rule; }else{ $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:''; $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0'; $tplRules[$value['order']]=array( 'topicNo'=>$value['order'], 'topic_id'=>$value['topic_id'], 'rule_type'=>(int)$rule, 'rule_answer'=>$rule_answer, 'rule_score'=>'', 'rule_score_half'=>$rule_half_score ); } } } if($tplRules){ $tplData['new_rules']=$tplRules; $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute(); } $this->sendNoticeToReport($Exam_GroupId); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $Exam_GroupId, "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') ))); } //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$Exam_GroupId, ); sendStudentCacheQueue($sendJsonArr); $result['status']=1; $result['msg']='报告更新完成'; exit(json_encode($result)); } //更新文理综考试试题科目 public function actionEditTopicSubject(){ $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $subject = Req::post('subject'); $old_subject = Req::post('old_subject'); $paper_id = Req::post('paper_id'); $result['status']=0; if($subject==$old_subject){ $result['msg']='新科目与原科目相同'; exit(json_encode($result)); } if(!isset(Yii::app()->params['subjectId'][$subject])){ $result['msg']='科目参数不正确'; exit(json_encode($result)); } $ExamModel=new SExam(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']='考试ID错误1'; exit(json_encode($result)); } $Exam_GroupId=$ExamInfo['exam_group_id']; $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); //查询试题序号 $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id', array(':paper_id' => $paper_id, ':topic_id' => $topic_id)); $tpl_data=json_decode($ExamInfo['tpl_data'],true); if($tpl_data && isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key => $val){ if($paper_student_data->order==$val['id']){ $tpl_data['new_items'][$key]['subject']=$subject; } } } Exam::model()->updateAll(array('tpl_data'=>json_encode($tpl_data)),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $Exam_GroupId, "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)); } //更新报告后发送通知 private function sendNoticeToReport($examGroupId){ $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/external/exam/group/clear-cache/'.$examGroupId; $username = $this->schoolInfo->school_id; $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']); $curl = @curl_init(); $response=null; if ($curl) { curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, $username .':'. $password); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', )); $response = curl_exec($curl); curl_close($curl); } return $response; } //批量更新选择题分数 public function actionUpdateScoreBatch(){ $scores = Req::post('scores'); $paper_id = Req::post('paper_id'); $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id and type=1','params'=>array(':paper_id'=>$paper_id))); $oldTopicScores=0; //选择题原总分 $newTopicScores=0; //选题题修改后总分 $update_score=array(); //需要修改分数的topic $update_score_order=array(); //修改分数的序号 if($paper_topic_data) { if(count($paper_topic_data)!=count($scores)){ echo json_encode(array('status'=>0,'msg'=>'提交的选择题数量不正确'));exit; } foreach($paper_topic_data as $v) { $oldTopicScores+=$v['score']; if($v['score']!=$scores[$v->order]){ $update_score[$v->topic_id] = $scores[$v->order]; $update_score_order[$v->order] = $scores[$v->order]; $score_diff[$v->topic_id]=$scores[$v->order]-$v['score']; } } } if(!$update_score){ echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tpl_data = json_decode($exam_data->tpl_data,1); $newTopicScores=array_sum($scores); if(isset($tpl_data['items'])){ $objectiveTplData=array( 'total'=>count($scores), 'totalScore'=>$newTopicScores, 'perScores'=>array_values($scores) ); $tpl_data['items'][1]=$objectiveTplData; } //修改new_items if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if($val['topic_type']==1 && isset($update_score_order[$val['id']])){ $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']]; } } }else{ //没有new_items,补齐 $tpl_data= $this->createNewItems($tpl_data); } $exam_group = ExamGroup::model()->find('exam_group_id=:exam_id',array(':exam_id'=>$exam_data->exam_group_id)); $paper_score=$this->sumTplDataScores($tpl_data,$exam_group->is_third); $tpl_data['scores']=$paper_score; $tpl_data['total_score']=$paper_score; $json_tpl_data = jsonEncode($tpl_data); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ foreach ($update_score as $topic_id => $score){ if(!$score){ continue; } $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id; $this->sConn->createCommand($sql)->execute(); //修改学生得分 $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $this->sConn->createCommand($sql)->execute(); $sql="update student_paper_relation set scoring=scoring+".$score_diff[$topic_id]." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); } } $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')'; $this->sConn->createCommand($sql)->execute(); $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); $trans->commit(); } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0));exit; } $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $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" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit; } } } } } } //批量更新单选试题答案 public function actionUpdateAnswerBatch(){ $paper_id = Req::post('paper_id'); $updateAnswers = Req::post('update_answers'); $result=array(); $result['status']=0; $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if(!$paper_data){ $result['msg']="未找到试卷"; exit(json_encode($result)); } $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); $examGroupData=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $tplData=json_decode($exam_data->tpl_data,true); $queries = array(); foreach($updateAnswers as $val){ $topic_id=$val['topicId']; $type=1; $answer=$val['newAnswer']; if($paper_data) { $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id ', array(':paper_id' => $paper_id, ':topic_id' => $topic_id )); if (!$paper_student_data) { $result['msg']="未找到试题"; exit(json_encode($result)); } $paperIds = array(); if($exam_data){ $tplData['update_answer'][$paper_student_data['order']]=array( 'order'=>$paper_student_data['order'], 'topic_id'=>$topic_id, 'update_answer'=>$answer ); $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' "; $papers=$this->sConn->createCommand($PaperSql)->queryAll(); if ($papers) { foreach ($papers as $k => $v) { $paperIds[] = $v['paper_id']; } $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'"; $ptr=$this->sConn->createCommand($ptrSql)->queryRow(); if ($ptr) { $score = $ptr['score']; $studentIds_Right = array(); $studentIds_Wrong = array(); //更新选错了,但标为正确答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Wrong[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';"; } //更新原本选对了,但标为错误答案的 $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'"; $sptr=$this->sConn->createCommand($sptrSql)->queryAll(); if ($sptr) { foreach ($sptr as $k => $v) { $studentIds_Right[] = $v['student_id']; } $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");"; $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';"; } } } } $this->UpdateTopicAnswer($topic_id,$answer,1); $this->sendNoticeToReport($exam_data->exam_group_id); } } if($tplData['update_answer']){ $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'"; } if($queries){ $transaction = $this->sConn->beginTransaction(); try { foreach ($queries as $query) { $this->sConn->createCommand($query)->execute(); } //更新试题答案 $transaction->commit(); $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); if(isset($examGroupData) && $examGroupData->homework==1){ //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $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" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $result['status']=1; exit(json_encode($result)); } catch (Exception $e) { $transaction->rollback(); $result['msg']="更新失败"; exit(json_encode($result)); } }else{ $result['msg']="没有更新试题"; exit(json_encode($result)); } } /*批量修改多选题答案(各题答案不同,分数,半对分不同)*/ public function actionUpdateMultiAnswerBatch(){ ini_set('memory_limit', '500M'); $exam_id = Req::post('exam_id'); $topic_id = Req::post('topic_id'); $rule = Req::post('rule'); $score_half_m = Req::post('score_half_m'); $update_answers = Req::post('update_answers'); $change_obj = Req::post('change_obj'); $result=array( 'status'=>0 ); if(!$exam_id) { exit(json_encode($result)); } $topicIdHalfScore=array(); $topicIdRule=array(); $topicScoreArr=array(); foreach ($update_answers as $val){ $topicIdArr[]=$val['topicId']; $topicIdAnswer[$val['topicId']]=isset($val['newAnswer'])?$val['newAnswer']:$val['topicAnswer']; if(isset($val['topicHalfScore'])){ $topicIdHalfScore[$val['topicId']]=$val['topicHalfScore']; } if(isset($val['topicScore'])){ $topicScoreArr[$val['topicId']]=$val['topicScore']; } if(isset($val['topicRule'])){ $topicIdRule[$val['topicId']]=$val['topicRule']; } } if(!$topicIdHalfScore){ // if(!$score_half_m){ // $result['msg']='批量读取试题半对分异常'; // exit(json_encode($result)); // } $topicHalfScoreArr=explode('///',$score_half_m); foreach ($topicIdArr as $key => $val){ if(!isset($topicIdAnswer[$val])){ $result['msg']='批量读取试题答案异常'; exit(json_encode($result)); }else{ //$this->UpdateTopicAnswer($val,$topicIdAnswer[$val],11); $topicIdHalfScore[$val]=$topicHalfScoreArr[$key]; } } } if($topicIdAnswer){ foreach ($topicIdAnswer as $key =>$val){ $this->UpdateTopicAnswer($key,$val,11); } } $ExamModel=new SExam(); $ExamInfo=$ExamModel->getDetailByExamId($exam_id); if(!$ExamInfo){ $result['msg']='考试ID错误1'; exit(json_encode($result)); } $examGroupId=$ExamInfo['exam_group_id']; $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); $AllExamIds=array(); $tplData=array(); if($AllExam){ foreach($AllExam as $val){ if($val){ $AllExamIds[]=$val['exam_id']; if(!$tplData){ $tplData=json_decode($val['tpl_data'],true); } } } } if(!$AllExamIds){ $result['msg']='考试ID错误2'; exit(json_encode($result)); } $AllPaperIds=array(); $paperScore=array(); $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')'); if($AllPaper){ foreach ($AllPaper as $val){ $AllPaperIds[]=$val['paper_id']; $paperScore[$val['paper_id']]=$val['score']; } } if(!$AllPaperIds){ $result['msg']='考试ID错误3'; exit(json_encode($result)); } $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' ")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } if(!$topicScoreArr){ foreach ($paperTopicRelation as $value){ if(isset($topicIdHalfScore[$value['topic_id']]) && $topicIdHalfScore[$value['topic_id']]>$value['score']){ $result['msg']='半对分数不能大于满分'; exit(json_encode($result)); } $topicScoreArr[$value['topic_id']]=$value['score']; } } $Rs=array(); foreach ($AllPaperIds as $pid){ $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")"); if($tempData){ foreach ($tempData as $v){ $Rs[]=array( 'topic_id' =>$v['topic_id'], 'answer' =>$v['answer'], 'paper_id' =>$v['paper_id'], 'student_id' =>$v['student_id'], ); } } } $updateRightData=array(); $updateScoreData=array(); $updateStudentPaperRelation=array(); if($Rs){ if(!$topicIdAnswer){ $result['msg']='答案不能为空'; exit(json_encode($result)); } foreach ($Rs as $k=> $v){ if(!isset($topicIdAnswer[$v['topic_id']])){ continue; } $answer=$topicIdAnswer[$v['topic_id']]; if(!$v['answer']){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ if($v['answer'] == $answer){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']]; }else{ $nowRule=$rule; if($topicIdRule){ $nowRule=$topicIdRule[$v['topic_id']]; } switch ($nowRule){ case 1: //规则A 最严格规则 $update_data['scoring']=0; $update_data['is_right']=0; $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; break; case 2://规则B 半对规则 //查找错误选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $FindWrong=false; foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $FindWrong=true; break; } } if($FindWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错 $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']]; } break; case 3://规则C 宽松半对规则 //查找正确选择 $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=true; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $IsWrong=false; break; } } } //错误答案情况 if($IsWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错 $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']]; } break; case 4: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $IsWrong=false; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if(!in_array($av,$answerArr)){ $IsWrong=true; break; } } }else{ $IsWrong=true; } //错误答案情况 if($IsWrong){ $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; }else{ //没有错误答案,且不全对,几个答案几分 $score_half_m=count($tempAnswer); $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; } break; case 5: $answerArr=explode(',',$answer); $tempAnswer = explode(',', $v['answer']); $rightAnswerCount=0; if(count($tempAnswer)<=count($answerArr)){ foreach ($tempAnswer as $av) { if (false !== strpos($answer, $av)) { $rightAnswerCount++; } } } $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0; $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount; break; } } } //更新总分queryAll $updateStudentPaperRelation[$v['student_id']]=$v['paper_id']; } } $updateStudentPaperRelationSql=array(); if($updateRightData){ $sqlIsRight=array(); $sqlScore=array(); foreach ($updateRightData as $paperId=>$val){ foreach ($val as $topicId=>$v){ $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` "; foreach ($v as $studentId=>$isRight){ $sql.=" WHEN ".$studentId." THEN '".$isRight."' "; } $sql.=" Else `is_right`"; $sql.=" End "; $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'"; $sqlIsRight[]=$sql; } } foreach ($updateScoreData as $paperId=>$val){ foreach ($val as $topicId=>$v){ $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` "; foreach ($v as $studentId=>$score){ $sql.=" WHEN ".$studentId." THEN '".$score."' "; } $sql.=" Else `scoring`"; $sql.=" End "; $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'"; $sqlScore[]=$sql; } } $transaction = $this->sConn->beginTransaction(); try { if($sqlIsRight){ foreach ($sqlIsRight as $sql){ $this->sConn->createCommand($sql)->execute(); } } if($sqlScore){ foreach ($sqlScore as $sql){ $this->sConn->createCommand($sql)->execute(); } } $transaction->commit(); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } if($updateStudentPaperRelation){ foreach ($updateStudentPaperRelation as $studentId =>$paperId){ $TotalScore = $paperScore[$paperId]; $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' "; $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll(); $right_count = 0; $partial_right_count = 0; $wrong_count = 0; $scoring = 0; $lost_score = 0; foreach ($StudentAllTopic as $value) { if ($value['is_right'] == 1) { $right_count++; } elseif ($value['is_right'] == 2) { $partial_right_count++; } else { $wrong_count++; } $scoring = bcadd($scoring, $value['scoring'], 1); } unset($StudentAllTopic); $lost_score = bcsub($TotalScore, $scoring, 1); $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'"; $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'"; $updateStudentPaperRelationSql[]=$paperRelattionSql; } } $transaction = $this->sConn->beginTransaction(); try { if($updateStudentPaperRelationSql){ foreach ($updateStudentPaperRelationSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$examGroupId ); $transaction->commit(); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$examGroupId, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } } $scores=array_values($topicScoreArr); $newTopicScores=array_sum($scores); //记录新判分规则 $tplRules=array(); if(isset($tplData['new_rules'])){ $tplRules=$tplData['new_rules']; } $oldTopicScores=0; $type=0; $updatePaperScoreSql=array(); foreach ($paperTopicRelation as $value){ if(in_array($value['topic_id'],$topicIdArr)){ $oldTopicScores+=$value['score']; if(!$type){ $type=$value['type']; } $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:''; $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0'; $rule_score=isset($topicScoreArr[$value['topic_id']])?$topicScoreArr[$value['topic_id']]:'0'; //修改new_items if($topicScoreArr){ if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $key =>$val){ if($value['order']==$val['id']){ $tplData['new_items'][$key]['score']=(float)$rule_score; } } } $updatePaperScoreSql[]='update `paper_topic_relation` set `score` = '.$rule_score.' where paper_id in ('.implode(',',$AllPaperIds).') and `topic_id` ='.$value['topic_id']; } if(isset($rule)){ $newRule= $rule; }elseif(isset($topicIdRule[$value['topic_id']])){ $newRule= $topicIdRule[$value['topic_id']]; } if(!isset($tplRules[$value['order']])){ $tplRules[$value['order']]=array( 'topicNo'=>$value['order'], 'topic_id'=>$value['topic_id'], 'rule_type'=>(int)$newRule, 'rule_answer'=>$rule_answer, 'rule_score'=>$rule_score, 'rule_score_half'=>$rule_half_score ); }else{ $tplRules[$value['order']]['topic_id']=$value['topic_id']; if($newRule){ $tplRules[$value['order']]['rule_type']=(int)$newRule; } if($rule_answer){ $tplRules[$value['order']]['rule_answer']=$rule_answer; } if($rule_score){ $tplRules[$value['order']]['rule_score']=$rule_score; } if($rule_half_score){ $tplRules[$value['order']]['rule_score_half']=$rule_half_score; }else{ $tplRules[$value['order']]['rule_score_half']=0; } } } } if($topicScoreArr && $change_obj=='score' ){ if(isset($tplData['items'])){ $objectiveTplData=array( 'total'=>count($scores), 'totalScore'=>$newTopicScores, 'perScores'=>array_values($scores) ); $tplData['items'][$type]=$objectiveTplData; } $paper_score=$tplData['scores']=$tplData['total_score']=$tplData['scores']-$oldTopicScores+$newTopicScores; $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$AllPaperIds).')'; $this->sConn->createCommand($sql)->execute(); } $tplData['new_rules']=$tplRules; $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$examGroupId}'")->execute(); if($updatePaperScoreSql){ foreach ($updatePaperScoreSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } $this->sendNoticeToReport($examGroupId); if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '批量更新多选题报告', "operate_account" => Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->action, "operate_url" => $this->getRoute(), "operate_sql" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId)); if(isset($exam_group_data) && $exam_group_data->homework==1){ //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$examGroupId, ); sendStudentCacheQueue($sendJsonArr); } $result['status']=1; $result['msg']='报告更新完成'; exit(json_encode($result)); } //送分题/0分题 public function actionSendPoints(){ $actionType = Req::post('actype'); //操作 1 送分,2:0分 $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); if(!$paper_id || !$topic_id) { echo json_encode(array('status'=>-1));exit; } $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id))); $score_diff=0; //分差 if(empty($topic_data)) { echo json_encode(array('status'=>0,'msg'=>'试卷不存在'));exit; } $score=$topic_data->score; if($actionType==1){ $score_diff=$topic_data->score; }else{ $score_diff=0-$topic_data->score; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tplData = json_decode($exam_data->tpl_data,1); $tplData['send_points'][$topic_data->order]=array( 'topicNo'=>$topic_data->order, 'topic_id'=>$topic_id, 'actionType'=>$actionType, ); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ $needSendLog=false; //修改学生得分 if($actionType==1){ //送分 $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 "; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 "; $this->sConn->createCommand($sql)->execute(); $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); $needSendLog=true; } }elseif($actionType==2){//0分 $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $sql="update student_paper_topic_rs set scoring=0 where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 "; $this->sConn->createCommand($sql)->execute(); $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); $needSendLog=true; } } $sql="update `exam` set `tpl_data` = '".(jsonEncode($tplData))."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); if($needSendLog){ $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); //发送学生端消息 $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data->homework==1){ $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } } $trans->commit(); } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit; } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $exam_data->exam_group_id, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '送分0分', "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') ))); } echo json_encode(array('status'=>1,'score'=>$score));exit; } } } } } } //单选题多答案送分题 public function actionSendScore(){ $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $answer = Req::post('answer'); if(!$paper_id || !$topic_id || !$answer) { echo json_encode(array('status'=>0));exit; } $answerArr=explode(',',$answer); if(!$answerArr){ echo json_encode(array('status'=>0,'msg'=>'答案不能为空'));exit; } foreach ($answerArr as $key => $val){ $answerArr[$key]="'".$val."'"; } $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id))); $score_diff=0; //分差 if(empty($topic_data)) { echo json_encode(array('status'=>0,'msg'=>'试卷不存在'));exit; } $score=$topic_data->score; $score_diff=$topic_data->score; $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tplData = json_decode($exam_data->tpl_data,1); $tplData['send_points'][$topic_data->order]=array( 'topicNo'=>$topic_data->order, 'topic_id'=>$topic_id, 'actionType'=>1, 'answer'=>$answer ); $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ $needSendLog=false; //修改学生得分 $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 and `type`=1 and answer in(".implode(',',$answerArr).")"; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and student_id in(".implode(',',$studentIds).")"; $this->sConn->createCommand($sql)->execute(); $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); $needSendLog=true; } $sql="update `exam` set `tpl_data` = '".(json_encode($tplData))."' where exam_id in (".implode(',',$exam_ids).")"; $this->sConn->createCommand($sql)->execute(); if($needSendLog){ $sendParam=array( 'school_id'=>$this->schoolId, 'exam_group_id'=>$exam_data->exam_group_id ); sendZsystNotic($sendParam); $kafkaData=array( 'schoolId'=>$this->schoolId, 'examGroupId'=>$exam_data->exam_group_id, 'generateTime'=>time()*1000 ); sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); //发送学生端消息 $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data->homework==1){ $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } } $trans->commit(); } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit; } if(Yii::app()->params['handle_log_on_off']) { writeFileLog(jsonEncode(array( "exam_group_id" => $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" =>'', "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)), "date"=>date('Y-m-d H:i:s') ))); } echo json_encode(array('status'=>1,'score'=>$score));exit; } } } } } } //大题上移下移 public function actionMoveBatch() { $paper_id = Req::post('paper_id'); $topic_id = Req::post('topic_id'); $action = Req::post('action'); if(!$paper_id || !$topic_id) { echo json_encode(array('status'=>0,'msg'=>'参数错误'));exit; } $nowTopics=array(); $nowFirstOrder=0; $anotherTopics=array(); $nowTopicType=0; if($action=='up'){ //查找本题所有小题 $topic_data = $this->sConn->createCommand("select `order`,`topic_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$topic_id." order by `order` asc ")->queryAll(); foreach ($topic_data as $val){ $nowTopics[(string)$val['topic_id']]=$val['order']; if(!$nowFirstOrder) $nowFirstOrder=$val['order']; if(!$nowTopicType) $nowTopicType=$val['type']; } //查找上一道大题 $anotherTopic = $this->sConn->createCommand("select `order`,`stem_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `order`<{$nowFirstOrder} order by `order` desc limit 1 ")->queryRow(); }elseif($action=='down'){ //查找本题所有小题 $topic_data = $this->sConn->createCommand("select `order`,`topic_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$topic_id." order by `order` desc ")->queryAll(); foreach ($topic_data as $val){ $nowTopics[(string)$val['topic_id']]=$val['order']; if(!$nowFirstOrder) $nowFirstOrder=$val['order']; if(!$nowTopicType) $nowTopicType=$val['type']; } //查找下一道大题 $anotherTopic = $this->sConn->createCommand("select `order`,`stem_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `order`>{$nowFirstOrder} order by `order` asc limit 1 ")->queryRow(); }else{ echo json_encode(array('status'=>0,'msg'=>'操作错误'));exit; } if(!$anotherTopic){ echo json_encode(array('status'=>0,'msg'=>'不能再移动啦'));exit; } //查找上一道所有小题 $topic_data = $this->sConn->createCommand("select `order`,`topic_id` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$anotherTopic['stem_id']." order by `order` asc ")->queryAll(); foreach ($topic_data as $val){ $anotherTopics[(string)$val['topic_id']]=$val['order']; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); $exam_ids = array(); $paper_ids = array(); if($paper_data) { $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); if($exam_data) { $tpl_data = json_decode($exam_data->tpl_data,1); $orderAlias=array(); if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if(isset($val['alias'])){ $orderAlias[$val['id']]=$val['alias']; } } } $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); if($exam_group_data) { foreach($exam_group_data as $v) { $exam_ids[$v->exam_id] = $v->exam_id; } if($exam_ids) { $criteria = new CDbCriteria(); $criteria->addInCondition('exam_id',$exam_ids); $paper_data = SPaper::model()->findAll($criteria); if($paper_data) { foreach($paper_data as $v) { $paper_ids[$v->paper_id] = $v->paper_id; } $trans = $this->sConn->beginTransaction(); try{ $sqlArr=array(); $updateNewItemsOrder=array(); foreach ($anotherTopics as $id =>$number){ if($action=='up'){ $newOrder=$number+count($nowTopics); }else{ $newOrder=$number-count($nowTopics); } $updateNewItemsOrder[$number]=$newOrder; $sqlArr[]='update `paper_topic_relation` set `order` = '.$newOrder.' ,`no` = '.$newOrder.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$id; } foreach ($nowTopics as $id =>$number){ if($action=='up'){ $newOrder=$number-count($anotherTopics); }else{ $newOrder=$number+count($anotherTopics); } $updateNewItemsOrder[$number]=$newOrder; $sqlArr[]='update `paper_topic_relation` set `order` = '.$newOrder.' ,`no` = '.$newOrder.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$id; } if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if(isset($updateNewItemsOrder[$val['id']])){ $tpl_data['new_items'][$key]['id']=$updateNewItemsOrder[$val['id']]; $tpl_data['new_items'][$key]['alias']=$orderAlias[$updateNewItemsOrder[$val['id']]]; } } $sqlArr[]="update `exam` set `tpl_data` = '".(jsonEncode($tpl_data))."' where exam_id in (".implode(',',$exam_ids).")"; } foreach ($sqlArr as $sql){ $this->sConn->createCommand($sql)->execute(); } $trans->commit(); echo json_encode(array('status'=>1));exit; } catch(Exception $e){ $trans->rollBack(); echo json_encode(array('status'=>0));exit; } } } } } } } //处理tpl_data,计算部分 private function sumTplDataScores($select_info,$is_third){ $TotalScore = 0; //计算可能多分组情况总分 $sameGroupTopic=array(); $groupScoreArr=array(); $required=1; if(isset($select_info['required'])){ $required=$select_info['required']; }elseif(isset($select_info['items'][17])){ $required=$select_info['items'][17]['required']; } if ($select_info) { if ($select_info && isset($select_info['new_items']) && !empty($select_info['new_items'])) { $nowGroupId = 0; //分组标志 foreach ($select_info['new_items'] as $k => $sc) { //分组判断 if($sc['topic_type']==17 && !$sc['group_id']){ $sc['group_id']=1000; } if (!isset($sc['group_id']) || !$sc['group_id']) { $TotalScore += $sc['score']; } else{ if(isset($sc['smTopicLen']) && $sc['smTopicLen']){ //在线多组,另计 }else{ $groupScoreArr[$sc['group_id']][]=$sc['score']; } } if(isset($sc['sameAliasNo']) && $sc['sameAliasNo']){ $sameGroupTopic[$sc['group_id']][$sc['sameAliasNo']][]=$sc['score']; } } if($sameGroupTopic){ foreach ($sameGroupTopic as $gid =>$value){ $value=array_values($value); $TotalScore+=array_sum($value[0]); } } if($groupScoreArr){ if($is_third){ //多组,多选一 foreach ($groupScoreArr as $gid =>$item){ $TotalScore+=$item[0]; } }else{ //一组,多选多 $groupScoreArr=array_values($groupScoreArr); $TotalScore+=array_sum(array_slice($groupScoreArr[0],0,$required)); } } } } return $TotalScore; } /*系统组卷,补齐new_items*/ private function createNewItems($tplData){ $newItems=array(); $id=1; $groupId=0; $required=0; foreach ($tplData['items'] as $type =>$item){ if($type==17){ $required=$item['required']; if(!$groupId){ $groupId=$id; } } if(isset($item['perScores'])){ foreach ($item['perScores'] as $score){ $newItems[]=array( 'id'=>$id, 'showNum'=>$id, 'alias'=>$id, 'score'=>$score, 'topic_type'=>$type, 'group_id'=>$groupId ); $id++; } }elseif(isset($item['perScore'])){ for($i=0;$i<$item['total'];$i++){ $newItems[]=array( 'id'=>$id, 'showNum'=>$id, 'alias'=>$id, 'score'=>$item['perScore'], 'topic_type'=>$type, 'group_id'=>$groupId ); $id++; } }elseif(isset($item['score'])){ for($i=0;$i<$item['total'];$i++){ $newItems[]=array( 'id'=>$id, 'showNum'=>$id, 'alias'=>$id, 'score'=>$item['score'], 'topic_type'=>$type, 'group_id'=>$groupId ); $id++; } } } $tplData['required']=$required; $tplData['new_items']=$newItems; return $tplData; } //全学科第三方题型转换 public function getTopicTypeForAllSubjectThird($clientType){ $topicTypeRelation=array( 1=>1, //单选 3=>2, //不定项 5=>5, //填空 8=>7, //解答 ); if(isset($topicTypeRelation[$clientType])){ return $topicTypeRelation[$clientType]; }else{ return 0; } } }