12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378 |
- <?php
- class AllSubjectController extends Controller{
- public $topicTypeRelation=array(
- 'ke'=>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;
- }
- }
|