array(1,2,3,4,12), 'zhu'=>array(5,6,7,8,9,10,11), 'jie'=>array(8,9,10,11), 'tian'=>array(5,6,7), 'single'=>array(1,2), 'multiple'=>array(3,4), 'pan'=>array(12) ); public $oldTopicType=array( 1=>'单选题', 2=>"多选题", 3=>'判断题', 5=>'填空题', 7=>'解答题', 17=>'选做题' ); // 打印列表 public function actionIndex() { $examId = Req::get('eid'); $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId)); if(!$examData) Yii::app()->jump->error('考试id不正确!'); $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id)); if(!$examGroup->qxk_paper_id){ $this->redirect('paper/index?eid='.$examId); } $tplData=json_decode($examData->tpl_data,true); $alias=array(); $stemAlias=array(); $newRules=array(); $selectTopicGroup=array(); if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $item){ if(isset($item['fullAlias'])){ $alias[$item['id']]=$item['fullAlias']; }else{ $alias[$item['id']]=$item['alias']; if($item['stemId']==$item['topicId']){ $stemAlias[$item['id']]=$item['alias']; }else{ $stemAlias[$item['id']]=$item['stemAlias'].$item['alias']; } } if(isset($item['sameAliasNo']) && $item['sameAliasNo']){ $selectTopicGroup[$item['id']]=$item['sameAliasNo']; } if(isset($item['basicTopicType']) && isset($item['topicId'])){ $thirdBasicId[(string)$item['topicId']]=$item['basicTopicType']; if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){ $thirdBasicId[(string)$item['stemId']]=$item['basicTopicType']; } } } } //读取新规则 if(isset($tplData['new_rules'])){ $data['new_rules'] = $tplData['new_rules']; } //读取单选题更新答案记录 if(isset($tplData['update_answer'])){ $data['update_answer'] = $tplData['update_answer']; } //读取送分题/0分题 if(isset($tplData['send_points'])){ $data['send_points'] = $tplData['send_points']; } $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId)); $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id))); if(!$topic_data){ Yii::app()->jump->error('请先创建答题卡!'); } $topicIds=array(); foreach ($topic_data as $item){ if($item['stem_id']){ $topicIds[$item['stem_id']]=$item['stem_id']; $topicTypeCount[$item['type']][]=$item['stem_id']; }else{ $topicIds[$item['topic_id']]=$item['topic_id']; $topicTypeCount[$item['type']][]=$item['topic_id']; } $topicTypeScoreCount[$item['type']][]=$item['score']; $topicNumber[(string)$item['topic_id']]=array( 'topic_id'=>$item['topic_id'], 'type'=>$item['type'], 'score'=>$item['score'], 'order'=>$item['order'], ); } //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id); $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds); //组装试题结构 $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K'); $topicType=array(); $topicGroup=array(); foreach ($topicDetail as $item){ if(!isset($topicType[$item['typeId']])){ $topicType[$item['typeId']]=array( 'type_name'=>$item['typeName'], 'basic_type_id'=>$item['basicType'], 'tips'=>'', 'topic'=>array() ); } $topic=array(); $topic['id']=(string)number_format($item['topicId'],0,'',''); $topic['type_id']=$item['typeId']; $topic['basic_type_id']=$item['basicType']; $topic['type_name']=$item['typeName']; $topic['subject_id']=$item['subjectId']; $topic['subject_name']=$item['subjectName']; $topic['title']=$item['title']; $topic['parse_content']=$item['parseContent']; $topic['slave_stem_editor']=$item['noShowSlaveTitle']?false:true; //小题题干独立编辑 $topic['slave_option_editor']=$item['noShowSlaveOptions']?false:true; //小题选项独立编辑 if(isset($topicNumber[(string)$topic['id']])){ $topic['score']=$topicNumber[(string)$topic['id']]['score']; $topic['order']=$topicNumber[(string)$topic['id']]['order']; if(isset($alias[$topic['order']])){ $topic['alias']=$alias[$topic['order']]; } if(!isset($topicType[$item['typeId']]['order'])){ if(isset($alias[$topic['order']]) && is_numeric($alias[$topic['order']])){ $topicType[$item['typeId']]['order']=$alias[$topic['order']]; }else{ $topicType[$item['typeId']]['order']=$topicNumber[(string)$topic['id']]['order']; } } //判断选做题 if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']])){ $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]; } } $topicGroup[$topic['id']]=array(); if(!$item['slaveList']){ $topic['answer']=$item['answer']; $topic['items']=$item['optionList']; if(!$topic['title'] && !$item['optionList']){ $topic['is_show']=0; }else{ $topic['is_show']=1; } $topic['answer_type_id']=$item['answerType']; if(count($item['answerDtl'])>1){ $topic['is_checkbox']=1; }else{ $topic['is_checkbox']=0; } $topicGroup[$topic['id']][]=$topic; }else{ foreach ($item['slaveList'] as $val){ $slave=array(); $basicTopicArr[(string)$val['topicSlaveId']][]=$val; if(isset($topicNumber[(string)$val['topicSlaveId']])){ $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score']; $slave['order']=$topicNumber[(string)$val['topicSlaveId']]['order']; if(!isset($topic['order'])){ $topic['order']=$slave['order']; } if(isset($alias[$slave['order']])){ $slave['alias']=$alias[$slave['order']]; } if(!isset($topicType[$item['typeId']]['order'])){ if(isset($alias[$slave['order']]) && is_numeric($alias[$slave['order']])){ $topicType[$item['typeId']]['order']=$alias[$slave['order']]; }else{ $topicType[$item['typeId']]['order']=$topicNumber[(string)$val['topicSlaveId']]['order']; } } //判断选做题 if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){ $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']]; } } $slave['title']=$val['title']; $slave['parse_content']=$val['parseContent']; $slave['topic_slave_id']=$val['topicSlaveId']; if(isset($val['slaveList']) && $val['slaveList']){ //三级子题 foreach ($val['slaveList'] as $thirdSlave){ $childSlave=array(); $childSlave['title']=$thirdSlave['title']; $childSlave['topic_slave_id']=$thirdSlave['topicSlaveId']; $childSlave['parse_content']=$thirdSlave['parseContent']; if(isset($topicNumber[(string)$thirdSlave['topicSlaveId']])){ $childSlave['score']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['score']; $childSlave['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']; //判断小题别名 $topicType[$item['typeId']]['last_order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']; if(isset($alias[$childSlave['order']])){ $childSlave['alias']=$alias[$childSlave['order']]; } if(!isset($topicType[$item['typeId']]['order'])){ if(isset($alias[$childSlave['order']]) && is_numeric($alias[$childSlave['order']])){ $topicType[$item['typeId']]['order']=$alias[$childSlave['order']]; }else{ $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']; } } //判断选做题 if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']])){ $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']]; } }else{ continue; } $childSlave['answer']=$thirdSlave['answer']; if(!$childSlave['title'] && !$thirdSlave['options']){ $childSlave['is_show']=0; }else{ $childSlave['is_show']=1; } if(isset($thirdSlave['listType'])){ $childSlave['list_type']=$thirdSlave['listType']; } $childSlave['items']=$thirdSlave['options']; if(isset($thirdSlave['answerType'])){ $childSlave['answer_type_id']=$thirdSlave['answerType']; }else{ $childSlave['answer_type_id']=0; } if(count($thirdSlave['answerDtl'])>1){ $childSlave['is_checkbox']=1; }else{ $childSlave['is_checkbox']=0; } if(isset($thirdSlave['words'])){ $childSlave['words']=$thirdSlave['words']; } $slave['slave'][]=$childSlave; $topicGroup[$topic['id']][]=$childSlave; } }else{ $slave['answer']=$val['answer']; if(!$slave['title'] && !$val['options']){ $slave['is_show']=0; }else{ $slave['is_show']=1; } if(isset($val['listType'])){ $slave['list_type']=$val['listType']; } $slave['items']=$val['options']; if(isset($val['answerType'])){ $slave['answer_type_id']=$val['answerType']; }else{ $slave['answer_type_id']=0; } if(count($val['answerDtl'])>1){ $slave['is_checkbox']=1; }else{ $slave['is_checkbox']=0; } if(isset($val['words'])){ $slave['words']=$val['words']; } $topicGroup[$topic['id']][]=$slave; } $topic['slave'][]=$slave; } } $topicType[$item['typeId']]['topic'][]=$topic; } //拆分选做题 if($selectTopicGroup){ $selectTopicType=array(); $selectTopicType['type_name']='选做题'; $selectTopicType['topic']=array(); foreach ($topicType as $key => $item){ foreach ($item['topic'] as $vk => $val){ if(isset($val['group_id'])){ $selectTopicType['topic'][]=$val; $selectTopicType['basic_type_id']=$val['basic_type_id']; if(!isset($selectTopicType['order'])){ $selectTopicType['order']=$val['order']; } unset($topicType[$key]['topic'][$vk]); } } if(count($topicType[$key]['topic'])==0){ unset($topicType[$key]); }else{ $topicType[$key]['topic']=array_values($topicType[$key]['topic']); $topicType[$key]['order']= $topicType[$key]['topic'][0]['order']; } } $topicType[17]=$selectTopicType; } //计算小题数量 foreach ($topicType as $key => $item){ $topicNumber=0; $scores=0; foreach ($item['topic'] as $val){ if(isset($val['slave'])){ foreach ($val['slave'] as $v){ if(isset($v['slave'])){ foreach ($v['slave'] as $value){ if(isset($value['score'])){ $scores+=$value['score']; } $topicNumber++; } }else{ if(isset($v['score'])){ $scores+=$v['score']; } $topicNumber++; } } }else{ if($key==17){ $scores=$val['score']; }else{ $scores+=$val['score']; } $topicNumber++; } } $topicType[$key]['tips']='本大题共'.$topicNumber.'小题,共'.$scores.'分'; $topicType[$key]['total_score']=$scores; $lastOrder = $this->_array_column($item['topic'],'order'); array_multisort($lastOrder,SORT_ASC,$topicType[$key]['topic']); } //按组卷排序 $lastOrder = $this->_array_column($topicType,'order'); array_multisort($lastOrder,SORT_ASC,$topicType); //计算大题号 foreach ($topicType as $key =>$value){ $topicType[$key]['questionNumber']=numToUpper($key+1); } //题型对应 $singleChoice=array(1,2,12); //单选,小题单选 $multipleChoices=array(3,4); //多选,小题多选 $slaveAnswer=array(7,9); //多选,小题多选 $data['singleChoice']=$singleChoice; $data['multipleChoices']=$multipleChoices; $data['slaveAnswer']=$slaveAnswer; $data['topic']=$topicType; $data['subject']=$examData->subject_id; $data['paper_id']=$paper->paper_id; $data['is_third']=$examGroup->is_third; $data['topic_group']=$topicGroup; $data['exam_id']=$examId; $data['alias']=$alias; $this->renderPartial("all_subject",$data); } //试题操作页面 public function actionOperate(){ $examId = Req::get('eid'); $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId)); if(!$examData) Yii::app()->jump->error('考试id不正确!'); $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id)); if(!$examGroup->qxk_paper_id){ $this->redirect('paper/index?eid='.$examId); } $tplData=json_decode($examData->tpl_data,true); $alias=array(); $stemAlias=array(); $newRules=array(); $thirdBasicId=array(); $scoresType=array(); //小问小空类型 if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $item){ if(isset($item['fullAlias'])){ $alias[$item['id']]=$item['fullAlias']; }else{ $alias[$item['id']]=$item['alias']; if($item['stemId']==$item['topicId']){ $stemAlias[$item['id']]=$item['alias']; }else{ $stemAlias[$item['id']]=$item['stemAlias'].$item['alias']; } } if(isset($item['sameAliasNo']) && $item['sameAliasNo']){ $selectTopicGroup[$item['id']]=$item['sameAliasNo']; } if(isset($item['basicTopicType']) && isset($item['topicId'])){ $thirdBasicId[$item['topicId']]=$item['basicTopicType']; if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){ $thirdBasicId[$item['stemId']]=$item['basicTopicType']; } } if(isset($item['scoresType'])){ $scoresType[$item['topicId']]=$item['scoresType']; } } } //读取新规则 if(isset($tplData['new_rules'])){ $paperData['new_rules'] = $tplData['new_rules']; } //读取单选题更新答案记录 if(isset($tplData['update_answer'])){ $paperData['update_answer'] = $tplData['update_answer']; } //读取送分题/0分题 if(isset($tplData['send_points'])){ $paperData['send_points'] = $tplData['send_points']; } $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId)); $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id))); if(!$topic_data){ Yii::app()->jump->error('请先创建答题卡!'); } $multipleBlank=array(); //多空题 foreach ($topic_data as $item){ $topicIds[$item['stem_id']]=$item['stem_id']; $topicTypeCount[$item['type']][]=$item['stem_id']; $topicTypeScoreCount[$item['type']][]=$item['score']; if($item['question_count']>1){ $questionScore=explode(',',$item['question_score_str']); $multipleBlank[(string)$item['topic_id']]=$questionScore; } $topicNumber[(string)$item['topic_id']]=array( 'topic_id'=>$item['topic_id'], 'type'=>$item['type'], 'score'=>$item['score'], 'order'=>$item['order'], ); } //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id); $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds); // debug($topicDetail); //组装试题结构 $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K'); $topicType=array(); foreach ($topicDetail as $item){ if(isset($item['slaveList']) && $item['slaveList']){ foreach ($item['slaveList'] as $val){ if(isset($val['slaveList']) && $val['slaveList']){ foreach ($val['slaveList'] as $third){ $topic=array(); $topic['id']=(string)number_format($third['topicSlaveId'],0,'',''); if(isset($topicNumber[(string)$topic['id']])){ $topic['score']=$topicNumber[(string)$topic['id']]['score']; $topic['order']=$topicNumber[(string)$topic['id']]['order']; if(isset($alias[$topic['order']])){ $topic['alias']=$alias[$topic['order']]; } } $topic['answer']=$third['answer']; if(isset($paperData['new_rules'][$topic['order']])){ $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type']; $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer']; $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score']; $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half']; } if(isset($tplData['update_answer'][$topic['order']])){ $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer']; } if(isset($tplData['send_points'][$topic['order']])){ $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType']; } if(isset($third['answerType'])){ $answerTypeId=$third['answerType']; }else{ $answerTypeId=0; } if(count($third['answerDtl'])>1){ $isCheckBox=1; }else{ $isCheckBox=0; } $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox); if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){ $topicTypeId=17; } $topic['option_count']=count($third['options']); $topicType[$topicTypeId][]=$topic; } }else{ //无三级小题 $topic=array(); $topic['id']=(string)number_format($val['topicSlaveId'],0,'',''); if(isset($topicNumber[(string)$topic['id']])){ $topic['score']=$topicNumber[(string)$topic['id']]['score']; $topic['order']=$topicNumber[(string)$topic['id']]['order']; if(isset($alias[$topic['order']])){ $topic['alias']=$alias[$topic['order']]; } } $topic['answer']=$val['answer']; if(isset($paperData['new_rules'][$topic['order']])){ $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type']; $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer']; $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score']; $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half']; } if(isset($tplData['update_answer'][$topic['order']])){ $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer']; } if(isset($tplData['send_points'][$topic['order']])){ $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType']; } if(isset($val['answerType'])){ $answerTypeId=$val['answerType']; }else{ $answerTypeId=0; } if(count($val['answerDtl'])>1){ $isCheckBox=1; }else{ $isCheckBox=0; } $topic['option_count']=count($val['options']); $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox); if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){ $topicTypeId=17; } $topicType[$topicTypeId][]=$topic; } } }else{ $topic=array(); $topic['id']=(string)number_format($item['topicId'],0,'',''); //无小题 if(isset($topicNumber[(string)$topic['id']])){ $topic['score']=$topicNumber[(string)$topic['id']]['score']; $topic['order']=$topicNumber[(string)$topic['id']]['order']; if(isset($alias[$topic['order']])){ $topic['alias']=$alias[$topic['order']]; } } $topic['answer']=$item['answer']; if(isset($paperData['new_rules'][$topic['order']])){ $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type']; $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer']; $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score']; $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half']; } if(isset($tplData['update_answer'][$topic['order']])){ $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer']; } if(isset($tplData['send_points'][$topic['order']])){ $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType']; } if(isset($item['answerType'])){ $answerTypeId=$item['answerType']; }else{ $answerTypeId=0; } if(count($item['answerDtl'])>1){ $isCheckBox=1; }else{ $isCheckBox=0; } $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox); if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){ $topicTypeId=17; } $topic['option_count']=count($item['optionList']); $topicType[$topicTypeId][]=$topic; } } foreach ($topicType as $key =>$val){ $lastOrder = $this->_array_column($val,'order'); array_multisort($lastOrder,SORT_ASC,$topicType[$key]); } $menu=array(); foreach ($topicType as $k =>$v){ $menu[$k]=$this->oldTopicType[$k]; } $data['exam_id']=$examId; $data['paper_id']=$paper['paper_id']; $data['topic']=$topicType; $data['menu']=$menu; $data['exam_name']=$examData->name; $data['subject_id']=$examData->subject_id; $data['multiple_blank']=$multipleBlank; $data['scores_type']=$scoresType; $this->renderPartial("operate",$data); } //批量更新分数 public function actionUpdateScoreBatch(){ $scores = Req::post('scores'); $paper_id = Req::post('paper_id'); $multiple_score = Req::post('multiple_score'); $topicType=0; $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))); $oldTopicScores=0; //原总分 $newTopicScores=array(); //修改后总分 $update_score=array(); //需要修改分数的topic $update_score_order=array(); //修改分数的序号 $choiseTYpeArr=array(1,2,3,4,12); $isChoice=true; //修改的题型是选择? if($paper_topic_data) { foreach($paper_topic_data as $v) { $oldTopicScores+=$v['score']; if(isset($scores[$v['order']])){ if($v['score']!=$scores[$v['order']] || isset($multiple_score[$v['topic_id']])){ $update_score[$v->topic_id] = $scores[$v->order]; $update_score_order[$v->order] = $scores[$v->order]; $score_diff[$v->topic_id]=intval($scores[$v->order]-$v['score']); $topicType=$v['type']; if(!in_array($topicType,$choiseTYpeArr)){ $isChoice=false; } } $newTopicScores[]=$scores[$v['order']]; }else{ $newTopicScores[]=$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,true); if(isset($tpl_data['items'])){ $objectiveTplData=array( 'total'=>count($scores), 'totalScore'=>array_sum($newTopicScores), 'perScores'=>array_values($newTopicScores) ); $tpl_data['items'][$topicType]=$objectiveTplData; } $paper_score=$tpl_data['scores']=$tpl_data['total_score']=$tpl_data['scores']-$oldTopicScores+array_sum($newTopicScores); //修改new_items if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if(isset($update_score_order[$val['id']])){ $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']]; } } } $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(isset($multiple_score[$topic_id])){ $sql='update `paper_topic_relation` set `score` = '.$score.',question_count='.count($multiple_score[$topic_id]).',question_score_str="'.implode(',',$multiple_score[$topic_id]).'" 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(); if($isChoice){ //修改学生得分 $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-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false); $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_group_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } if(Yii::app()->params['handle_log_on_off']) { Curl::post(Yii::app()->params['handle_log_api'], 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)), )); } echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit; } } } } } } /*批量修改多选题规则*/ 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(); $topicHalfScoreRelation=array(); foreach ($topicIdArr as $key => $val){ if(!isset($topicAnswerArr[$key])){ $result['msg']='批量读取试题答案异常'; exit(json_encode($result)); }else{ $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 topic_id in(".implode(',',$topicIdArr).") ")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } $Rs=array(); $topicScoreArr=array(); $topicHalfScoreArr=array(); foreach ($paperTopicRelation as $value){ if($topicIdHalfScore[(string)$value['topic_id']]>$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=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{ //没有错误答案,且不全对,几个答案几分 $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']) { Curl::post(Yii::app()->params['handle_log_api'], 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)), )); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); 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'=>$Exam_GroupId, ); sendStudentCacheQueue($sendJsonArr); } $result['status']=1; $result['msg']='报告更新完成'; exit(json_encode($result)); } function _array_column(array $array, $column_key, $index_key=null){ $result = array(); foreach($array as $arr) { if(!is_array($arr)) continue; if(is_null($column_key)){ $value = $arr; }else{ $value = $arr[$column_key]; } if(!is_numeric($value)){ $value=intval($value); } if(!is_null($index_key)){ $key = $arr[$index_key]; $result[$key] = $value; }else{ $result[] = $value; } } return $result; } //更新报告后发送通知 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 TransformTopicType($basicId,$answerTypeId,$checkBox){ $topicTypeId=0; if(in_array($basicId,$this->topicTypeRelation['single'])){ $topicTypeId=1; }elseif(in_array($basicId,$this->topicTypeRelation['multiple'])){ $topicTypeId=2; }elseif(in_array($basicId,$this->topicTypeRelation['tian'])){ $topicTypeId=5; }elseif(in_array($basicId,$this->topicTypeRelation['jie'])){ $topicTypeId=7; }elseif(in_array($basicId,$this->topicTypeRelation['pan'])){ $topicTypeId=3; }elseif ($basicId==13){ if($answerTypeId==1){ if($checkBox==1){ $topicTypeId=2; }else{ $topicTypeId=1; } }elseif($answerTypeId==2){ $topicTypeId=5; }elseif($answerTypeId==3){ $topicTypeId=7; }elseif($answerTypeId==4){ $topicTypeId=3; }else{ $topicTypeId=7; } } return $topicTypeId; } //批量更新分数答案 public function actionUpdateScoreAnswerBatch(){ $changes = Req::post('change_data'); $paper_id = Req::post('paper_id'); // $changes=array( // [ // 'answer'=>'A', // 'score'=>'', // 'topic_id'=>'201511100026379' // ] // ); if(!$changes){ echo json_encode(array('status'=>0,'msg'=>'参数异常'));exit; } $changeTopicData=array(); $topicIds=array(); foreach ($changes as $change){ $topicIds[]=$change['topic_id']; $changeTopicData[(string)$change['topic_id']]=array(); if($change['answer']){ if($change['answer']=='√'){ $change['answer']='T'; }elseif($change['answer']=='×'){ $change['answer']='F'; } $changeTopicData[(string)$change['topic_id']]['answer']=$change['answer']; }else{ $changeTopicData[(string)$change['topic_id']]['answer']=''; } if($change['score']){ $changeTopicData[(string)$change['topic_id']]['score']=$change['score']; }else{ $changeTopicData[(string)$change['topic_id']]['score']=''; } } $topicType=0; $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))); $oldTopicScores=0; //原总分 $newTopicScores=array(); //修改后总分 $update_score=array(); //需要修改分数的topic $update_score_order=array(); //修改分数的序号 $oldTopicScore=array(); $changeTopicOrder=array(); $choiseTYpeArr=array(1,2,3,4,12); $isChoice=true; //修改的题型是选择? $updateAnswer=array(); if($paper_topic_data) { foreach($paper_topic_data as $v) { if(isset($changeTopicData[(string)$v['topic_id']])){ $changeTopicOrder[$v['order']]=$changeTopicData[(string)$v['topic_id']]; if($changeTopicData[$v['topic_id']]['score']){ $update_score[$v->topic_id] = $changeTopicData[(string)$v['topic_id']]['score']; $update_score_order[$v->order] = $changeTopicData[(string)$v['topic_id']]['score']; }else{ $oldTopicScore[(string)$v['topic_id']]=$v['score']; } if($changeTopicData[(string)$v['topic_id']]['answer']){ $updateAnswer[$v['order']]=array( 'order'=>$v['order'], 'topic_id'=>$v['topic_id'], 'update_answer'=>$changeTopicData[(string)$v['topic_id']]['answer'] ); } }else{ $newTopicScores[]=$v['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) { $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); $tpl_data = json_decode($exam_data->tpl_data,true); $exam_all_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id)); //修改new_items if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if(isset($changeTopicOrder[$val['id']]) && $changeTopicOrder[$val['id']]['score']){ $tpl_data['new_items'][$key]['score']=$changeTopicOrder[$val['id']]['score']; } } } //修改答案记录 if($updateAnswer){ foreach ($updateAnswer as $order=>$item){ if(!isset($tpl_data['update_answer'])){ $tpl_data['update_answer']=array(); } $tpl_data['update_answer'][$order]=$item; if($exam_group_data['is_third']==1){ $this->UpdateTopicAnswer($item['topic_id'],$item['update_answer'],1); } } } $paper_score=$this->sumTplDataScores($tpl_data,0); $tpl_data['scores']=$paper_score; $tpl_data['total_score']=$paper_score; $json_tpl_data = jsonEncode($tpl_data); if($exam_all_data) { foreach($exam_all_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 ($changeTopicData as $topic_id => $item){ if(isset($item['score']) && $item['score']){ $sql='update `paper_topic_relation` set `score` = '.$item['score'].' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id; $this->sConn->createCommand($sql)->execute(); } if(isset($item['answer']) && $item['answer']){ //查询选旧答案,得分的学生 $updateStudentSql="select student_id,scoring 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(); $oldScore=0; foreach ($students as $v){ $studentIds[]=$v['student_id']; if(!$oldScore){ $oldScore=$v['scoring']; } } $sql="update student_paper_topic_rs set scoring='0',is_right=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-".$oldScore." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $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 answer='".$item['answer']."' "; $students=$this->sConn->createCommand($updateStudentSql)->queryAll(); if($students){ $studentIds=array(); foreach ($students as $v){ $studentIds[]=$v['student_id']; } $score=0; if(isset($item['score']) && $item['score']){ $score=$item['score']; }else{ $score=$oldTopicScore[$topic_id]; } $sql="update student_paper_topic_rs set scoring='".$score."',is_right=1 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." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") "; $this->sConn->createCommand($sql)->execute(); } }elseif(isset($item['score']) && $item['score']){ //查询选旧答案,得分的学生 $updateStudentSql="select student_id,scoring 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(); $oldScore=0; foreach ($students as $v){ $studentIds[]=$v['student_id']; if(!$oldScore){ $oldScore=$v['scoring']; } } $sql="update student_paper_topic_rs set scoring='".$item['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+".($item['score']-$oldScore)." 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-generate-report",$kafkaData); $this->sendNoticeToReport($exam_data->exam_group_id); sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false); if($exam_group_data->homework==1){ //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_group_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } if(Yii::app()->params['handle_log_on_off']) { Curl::post(Yii::app()->params['handle_log_api'], 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)), )); } echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit; } } } } } } //处理tpl_data,计算部分 private function sumTplDataScores($select_info,$is_third){ $TotalScore = 0; //计算可能多分组情况总分 $sameGroupTopic=array(); $groupScoreArr=array(); $required=1; $qxk=0; 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(isset($sc['basicTopicType']) && $sc['basicTopicType'] && !$qxk){ $qxk=1; } //分组判断 if(($sc['topic_type']==17 || (isset($sc['sameAliasNo']) && $sc['sameAliasNo'])) && !$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'] && !$qxk){ //在线多组,另计 }else{ $groupScoreArr[$sc['group_id']][]=$sc['score']; } } if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && !$qxk){ $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; } /*批量修改多选题规则*/ public function actionChangeMultiRuleBatchNew(){ ini_set('memory_limit', '500M'); $exam_id = Req::post('exam_id'); $topicData = Req::post('topic_data'); $result=array( 'status'=>0 ); if(!$exam_id || !$topicData ) { exit(json_encode($result)); } $topicIds=array(); $topicIdArr=array(); foreach ($topicData as $item){ $topicIds[]=$item['topic_id']; // if($item['rule']!=1 && !$item['half_score']){ // $result['msg']='半对分数不能为空'; // exit(json_encode($result)); // } if(!in_array($item['rule'],array(1,2,3,4,5))){ $result['msg']='评分规则错误'; exit(json_encode($result)); } if($item['half_score']>$item['score']){ $result['msg']='半对分数不能大于满分'; exit(json_encode($result)); } $topicIdArr[(string)$item['topic_id']]=$item; if($item['answer']){ $this->UpdateTopicAnswer($item['topic_id'],$item['answer'],1); } } if(!$topicIdArr){ $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`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and topic_id in(".implode(',',$topicIds).") ")->queryAll(); if(!$paperTopicRelation){ $result['msg']='试卷试题有误'; exit(json_encode($result)); } //更新规则 $tplRules=array(); if(isset($tplData['new_rules'])){ $tplRules=$tplData['new_rules']; } $updatePaperScoreSql=array(); foreach ($paperTopicRelation as $value){ if(isset($topicIdArr[(string)$value['topic_id']])){ $order=$value['order']; $newScore=$topicIdArr[(string)$value['topic_id']]['score']; $tplRules[$value['order']]=array( 'topicNo'=>$value['order'], 'topic_id'=>$value['topic_id'], 'rule_type'=>(int)$topicIdArr[(string)$value['topic_id']]['rule'], 'rule_answer'=>$topicIdArr[(string)$value['topic_id']]['answer'], 'rule_score'=>$newScore, 'rule_score_half'=>$topicIdArr[(string)$value['topic_id']]['half_score'], ); if($value['score']!==$newScore){ if(isset($tplData['new_items'])){ foreach ($tplData['new_items'] as $key => $val){ if($val['id']==$order){ $tplData['new_items'][$key]['score']=$newScore; } } } $updatePaperScoreSql[] = 'update `paper_topic_relation` set `score` = ' . $newScore . ' where paper_id in (' . implode(',', $AllPaperIds) . ') and `topic_id` =' . $value['topic_id']; } } } $tplData['new_rules']=$tplRules; $paperScore=$this->sumTplDataScores($tplData,0); $Rs=array(); $tplData['scores']=$paperScore; $tplData['total_score']=$paperScore; foreach ($AllPaperIds as $pid){ $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIds).")"); 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){ foreach ($Rs as $k=> $v){ $answer=$topicIdArr[(string)$v['topic_id']]['answer']; $rule=$topicIdArr[(string)$v['topic_id']]['rule']; 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']]=$topicIdArr[$v['topic_id']]['score']; }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']]=$topicIdArr[$v['topic_id']]['half_score']; } 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']]=$topicIdArr[$v['topic_id']]['half_score']; } 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(); //学生端接口 $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-generate-report",$kafkaData); $this->sendNoticeToReport($Exam_GroupId); sendDataToKafka("zsy-marking-update-topic",$Exam_GroupId,false); $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); if($exam_group_data->homework==1){ //发送学生端消息 $sendJsonArr=array( 'school_id'=>$this->schoolId, 'send_type'=>'zsyas', 'update_type'=>0, 'exam_group_id'=>$exam_group_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } } catch (Exception $e) { //如果操作失败, 数据回滚 $transaction->rollback(); $result['status']=0; $result['msg']=' 报告更新失败'; exit(json_encode($result)); } } if($updatePaperScoreSql){ foreach ($updatePaperScoreSql as $sql){ $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(); $this->sendNoticeToReport($Exam_GroupId); if(Yii::app()->params['handle_log_on_off']) { Curl::post(Yii::app()->params['handle_log_api'], 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)), )); } $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId)); 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'=>$Exam_GroupId, ); sendStudentCacheQueue($sendJsonArr); } $result['status']=1; $result['msg']='报告更新完成'; exit(json_encode($result)); } //更新选做题分数 public function actionUpdateScoreXuan(){ $scores = Req::post('scores'); $paper_id = Req::post('paper_id'); if(!$scores) { echo json_encode(array('status'=>0,'msg'=>'试题参数错误 ')); exit; } $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id)); if(!$paper_data){ echo json_encode(array('status'=>0,'msg'=>'试卷Id参数错误 '));exit; } $exam_data=Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id)); $xuan_topic=array(); $tpl_data = json_decode($exam_data->tpl_data,true); foreach ($tpl_data['new_items'] as $val){ if(isset($val['sameAliasNo']) && $val['sameAliasNo']) { $xuan_topic[$val['id']] = $val['id']; } } $topicType=17; $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))); $oldTopicScores=0; //原总分 $newTopicScores=array(); //修改后总分 $update_score=array(); //需要修改分数的topic $update_score_order=array(); //修改分数的序号 if($paper_topic_data) { foreach($paper_topic_data as $v) { $oldTopicScores+=$v['score']; if(isset($xuan_topic[$v['order']])){ if(isset($scores[$v['order']])){ if($v['score']!=$scores[$v['order']]){ $update_score[$v->topic_id] = $scores[$v->order]; $update_score_order[$v->order] = $scores[$v->order]; } $newTopicScores[]=$scores[$v['order']]; }else{ $newTopicScores[]=$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) { if(isset($tpl_data['items'])){ $objectiveTplData=array( 'total'=>count($scores), 'totalScore'=>array_sum($newTopicScores), 'perScores'=>array_values($newTopicScores) ); $tpl_data['items'][$topicType]=$objectiveTplData; } //修改new_items if(isset($tpl_data['new_items'])){ foreach ($tpl_data['new_items'] as $key =>$val){ if(isset($update_score_order[$val['id']])){ $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']]; } } } $paper_score=$this->sumTplDataScores($tpl_data,0); $tpl_data['scores']= $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){ $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 `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); sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false); $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_group_data->exam_group_id, ); sendStudentCacheQueue($sendJsonArr); } if(Yii::app()->params['handle_log_on_off']) { Curl::post(Yii::app()->params['handle_log_api'], 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)), )); } echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit; } } } } } //修改试题答案 private function UpdateTopicAnswer($topicId,$answer,$type){ if(!in_array($type,array(1,2,3,4,12))) return false; if(!preg_match('/^[A-Z,]+$/u',$answer)){ return false; } $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'); 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; } }