PaperController.php 210 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802
  1. <?php
  2. class PaperController extends Controller{
  3. // 打印列表
  4. public function actionIndex()
  5. {
  6. $exam_id = Req::get('eid');
  7. $is_third = Req::get('is_third');
  8. $tag = Req::get('tag');
  9. $data = array();
  10. $_paper_topic_data = array();
  11. $topic_score_data = array();
  12. $topic_type_data = array();
  13. $topic_subject_data = array();
  14. $alias = array();
  15. $topicIds = array();
  16. $questionCount = array(); //小问个数
  17. $questionScore = array(); //小问分数
  18. $scoresType = array(); //小问小空类型
  19. if(!$tag) $tag=0;
  20. if(!$exam_id)
  21. {
  22. Yii::app()->jump->error('非法访问!');
  23. }
  24. $exam_data= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  25. $data['new_rules']=array();
  26. if($exam_data)
  27. {
  28. $examGroup=SExamGroup::model()->find('exam_group_id=:exam_id',array(':exam_id'=>$exam_data['exam_group_id']));
  29. $tpl_data=json_decode($exam_data->tpl_data,true);
  30. $isNewEnglish=isset($tpl_data['isNewEnglish'])?$tpl_data['isNewEnglish']:0;
  31. $subject=$exam_data->subject_id;
  32. $params=array(
  33. 'isFormat'=>0,
  34. 'isThird'=>$is_third,
  35. 'isNewEnglish'=>$isNewEnglish
  36. );
  37. if($subject==8){
  38. $params['isFormat']=1;
  39. }
  40. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  41. $paper_topic_data = $this->schoolManager->getPaperTopics($paper_data->paper_id,$subject,$params,1);
  42. $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
  43. if($topic_data)
  44. {
  45. foreach($topic_data as $k=>$v)
  46. {
  47. $topicType=$v->type;
  48. if($examGroup['qxk_paper_id']>0 && $is_third){
  49. $topicType=$this->getTopicTypeForAllSubjectThird($topicType);
  50. }
  51. $topic_score_data[$v->topic_id] = $v->score;
  52. $topic_type_data[$topicType][$k] = array('order'=>$v->order,'topic_id'=>$v->topic_id,'score'=>$v->score);
  53. if($v->question_count>0){
  54. $questionCount[$v->order]=$v->question_count;
  55. $questionScore[$v->order]=$v->question_score_str;
  56. $scoresType[$v->order]=1;
  57. }
  58. }
  59. }
  60. if($is_third){
  61. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_answer from third_answer_sheet where exam_group_id='{$exam_data->exam_group_id}'")->queryRow();
  62. if($thirdAnswerSheet) {
  63. $sheet_answer = json_decode($thirdAnswerSheet['sheet_answer'], true);
  64. $data['sheet_answer'] = $sheet_answer;
  65. }
  66. }
  67. if($subject==8){
  68. if(!$is_third && $paper_topic_data)
  69. {
  70. foreach($paper_topic_data as $val)
  71. {
  72. if(isset($val['slave']) && $val['slave']){
  73. foreach ($val['slave'] as $v){
  74. $_paper_topic_data[(string)$v['topic_slave_id']]=array(
  75. 'topic_id'=>$v['topic_slave_id'],
  76. 'title'=>$val['queBody'],
  77. 'answer'=>$v['answer'],
  78. );
  79. if(isset($val['type'])){
  80. $_paper_topic_data[(string)$v['topic_slave_id']]['type']=$val['type'];
  81. }
  82. }
  83. }
  84. }
  85. }else{
  86. $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K',11=>'L',12=>'M');
  87. //读模板里面的数据
  88. if(isset($thirdAnswerSheet)){
  89. if($topic_data)
  90. {
  91. foreach($topic_data as $k=>$v)
  92. {
  93. if(isset($sheet_answer[$v->order])){
  94. $itemOptions=array();
  95. //读取校本题库选项
  96. $schoolTopicOption=$this->sConn->createCommand("select topic_id,option_correct,option_content from topic_item_option where topic_id='{$v->topic_id}'")->queryAll();
  97. $right=array();
  98. if($schoolTopicOption){
  99. foreach ($schoolTopicOption as $ok => $opt){
  100. if($opt['option_correct']==1){
  101. // $right[]=$arr[$ok];
  102. $right[]=numToLetter($ok+1);
  103. }
  104. }
  105. }
  106. $itemOptions[]['options']=$schoolTopicOption;
  107. $answer=$right?implode(',',$right):$sheet_answer[$v->order];
  108. $_paper_topic_data[(string)$v->topic_id]=array(
  109. 'topic_id'=>$v->topic_id,
  110. 'title'=>'',
  111. 'answer'=>$answer,
  112. 'items'=>$itemOptions
  113. );
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }else{
  120. //
  121. if(in_array($subject,array(18,19)) && isset($tpl_data['new_items'])){
  122. foreach ($tpl_data['new_items'] as $val){
  123. if(isset($val['subject'])){
  124. $topic_subject_data[$val['id']]=$val['subject'];
  125. }
  126. }
  127. }
  128. if($paper_topic_data)
  129. {
  130. foreach($paper_topic_data as $v)
  131. {
  132. $_paper_topic_data[(string)$v['id']] = $v;
  133. }
  134. }
  135. }
  136. //读取新规则
  137. if(isset($tpl_data['new_rules'])){
  138. $data['new_rules'] = $tpl_data['new_rules'];
  139. foreach ($data['new_rules'] as $key => $datum){
  140. if(isset($topic_score_data[$datum['topic_id']]) && $datum['rule_score'] ){
  141. $topic_score_data[$datum['topic_id']]=$datum['rule_score']; //分数以修改后规则分数为主
  142. }
  143. }
  144. }
  145. //读取单选题更新答案记录
  146. if(isset($tpl_data['update_answer'])){
  147. $data['update_answer'] = $tpl_data['update_answer'];
  148. }
  149. //读取别名
  150. if(isset($tpl_data['new_items'])){
  151. foreach ($tpl_data['new_items'] as $val){
  152. if(isset($val['alias'])){
  153. $alias[$val['id']] = $val['alias'];
  154. }
  155. }
  156. }
  157. //读取送分题/0分题
  158. if(isset($tpl_data['send_points'])){
  159. $data['send_points'] = $tpl_data['send_points'];
  160. }
  161. //读取小问小空类型
  162. if(isset($tpl_data['new_items'])){
  163. foreach ($tpl_data['new_items'] as $val){
  164. if(isset($val['scoresType']) && isset($scoresType[$val['id']])){
  165. $scoresType[$val['id']]=$val['scoresType'];
  166. }
  167. }
  168. }
  169. }
  170. $data['paper_id'] = $paper_data->paper_id;
  171. $data['topic'] = $_paper_topic_data;
  172. $data['score'] = $topic_score_data;
  173. $data['type'] = $topic_type_data;
  174. $data['exam_id'] = $exam_id;
  175. $data['is_third'] = $is_third;
  176. $data['subject'] = $subject;
  177. $data['exam_name'] = $exam_data->name;
  178. $data['topic_subject_data']=$topic_subject_data;
  179. $data['alias'] = $alias;
  180. $data['question_count'] = $questionCount;
  181. $data['question_scores'] = $questionScore;
  182. $data['score_type'] = $scoresType;
  183. //批量修改单选题分数,数据处理
  184. $choiceQuestionScoreSum=0;
  185. if(isset($topic_type_data[1])){
  186. foreach ($topic_type_data[1] as $item){
  187. $choiceQuestionScoreSum+=$item['score'];
  188. }
  189. }
  190. $data['choice_question_score_sum']=$choiceQuestionScoreSum;
  191. // debug($data);
  192. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  193. $data['subjects']=Yii::app()->params['subjectId'];
  194. unset($data['subjects'][3]);
  195. unset($data['subjects'][6]);
  196. unset($data['subjects'][51]);
  197. unset($data['subjects'][9]);
  198. unset($data['subjects'][8]);
  199. unset($data['subjects'][18]);
  200. unset($data['subjects'][19]);
  201. if(isset($data['subjects'][20])) unset($data['subjects'][20]);
  202. }
  203. $this->renderPartial("index",$data);
  204. }
  205. public function actionRecover()
  206. {
  207. $exam_id = Req::get('exam_id');
  208. $_exam_id = Req::post('exam_id');
  209. if(!$exam_id)
  210. {
  211. $exam_id = $_exam_id;
  212. }
  213. $_select = 0;
  214. $exam_ids = array();
  215. if($exam_id>0)
  216. {
  217. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  218. // $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  219. // if($paper_data)
  220. // {
  221. // $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
  222. // if($paper_topic_data)
  223. // {
  224. // foreach($paper_topic_data as $v)
  225. // {
  226. // if($v->type>1)
  227. // {
  228. // $_select = 1;
  229. // }
  230. // }
  231. // }
  232. // }
  233. // if($_select==0)
  234. // {
  235. // if($_exam_id){
  236. // echo json_encode(array('status'=>0,'msg'=>'只有选择题的试卷无法恢复'));exit;
  237. // }
  238. //
  239. // echo "<div style='margin-top:200px;'>只有选择题的试卷无法恢复!</div>";exit;
  240. //
  241. // }
  242. $exam_datas = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  243. if($exam_datas)
  244. {
  245. foreach($exam_datas as $v)
  246. {
  247. $exam_ids[$v->exam_id] = $v->exam_id;
  248. }
  249. }
  250. $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  251. if(!$exam_group)
  252. {
  253. if($_exam_id){
  254. echo json_encode(array('status'=>0,'msg'=>'考试数据有误!'));exit;
  255. }
  256. }
  257. if($exam_group->mark_type==0)
  258. {
  259. if($_exam_id){
  260. echo json_encode(array('status'=>0,'msg'=>'线下阅卷,无法恢复考试!'));exit;
  261. }
  262. echo "<div style='margin-top:200px;'>线下阅卷,无法恢复考试!</div>";exit;
  263. }
  264. if($exam_data)
  265. {
  266. //操作日志
  267. if(Yii::app()->params['handle_log_on_off'])
  268. {
  269. writeFileLog(jsonEncode(array(
  270. "exam_group_id" => (string)$exam_data->exam_group_id,
  271. "operate_project" => 'zsyas2',
  272. "school_id" => $this->schoolId,
  273. "title" => '恢复考试状态',
  274. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  275. "operate_method" => $this->action,
  276. "operate_url" => $this->getRoute(),
  277. "operate_sql" => json_encode(array('update'=>array(
  278. 'StudentPaperRelation'=>array(
  279. 'report_created'=>0,
  280. 'is_scoring'=>0,
  281. 'scoring_img'=>'',
  282. 'is_isp_html'=>0,
  283. 'isp_html_path'=>'',
  284. 'isp_html_time'=>0,
  285. 'is_wrongbook_html'=>0,
  286. 'wrongbook_html_path'=>'',
  287. 'wrongbook_html_time'=>0,
  288. 'is_isp_pdf'=>0,
  289. 'isp_pdf_path'=>'',
  290. 'isp_pdf_time'=>0,
  291. 'is_wrongbook_pdf'=>0,
  292. 'wrongbook_pdf_path'=>'',
  293. 'wrongbook_pdf_time'=>0,
  294. 'is_wbisp_html'=>0,
  295. 'is_wbisp_pdf'=>0,
  296. 'wbisp_html_path'=>'',
  297. 'wbisp_pdf_path'=>'',
  298. 'wbisp_html_time'=>0,
  299. 'wbisp_pdf_time'=>0,
  300. 'is_studytrend_img'=>0,
  301. 'studytrend_img_path'=>'',
  302. 'is_plan_created'=>0,
  303. 'plan_topic_time'=>0,
  304. 'plan_id'=>null,
  305. 'wb_page_num'=>0,
  306. 'isp_page_num'=>0,
  307. 'wbisp_page_num'=>0,
  308. 'is_three_isp_download'=>0,
  309. 'is_two_isp_download'=>0,
  310. 'is_wrongbook_download'=>0,
  311. 'is_wrong_plan_created'=>0,
  312. 'studytrend_img_time'=>0,
  313. 'download_three_isp_time'=>0,
  314. 'download_two_isp_time'=>0,
  315. 'download_wrongbook_time'=>0,
  316. 'wrong_plan_id'=>null,
  317. 'wrong_plan_topic_time'=>0,
  318. ),
  319. 'exam'=>array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0,
  320. 'is_topwb_pdf'=>0,
  321. 'is_academicr_html'=>0),
  322. 'ExamGroup'=>array('mark_status'=>1,'upload_status'=>1),
  323. ))),
  324. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  325. "date"=>date('Y-m-d H:i:s')
  326. )));
  327. }
  328. $trans = $this->sConn->beginTransaction();
  329. try{
  330. if($exam_ids)
  331. {
  332. $criteria = new CDbCriteria();
  333. $criteria->addInCondition('exam_id',$exam_ids);
  334. SStudentPaperRelation::model()->updateAll(
  335. array(
  336. 'report_created'=>0,
  337. 'is_scoring'=>0,
  338. 'scoring_img'=>'',
  339. 'is_isp_html'=>0,
  340. 'isp_html_path'=>'',
  341. 'isp_html_time'=>0,
  342. 'is_wrongbook_html'=>0,
  343. 'wrongbook_html_path'=>'',
  344. 'wrongbook_html_time'=>0,
  345. 'is_isp_pdf'=>0,
  346. 'isp_pdf_path'=>'',
  347. 'isp_pdf_time'=>0,
  348. 'is_wrongbook_pdf'=>0,
  349. 'wrongbook_pdf_path'=>'',
  350. 'wrongbook_pdf_time'=>0,
  351. 'is_wbisp_html'=>0,
  352. 'is_wbisp_pdf'=>0,
  353. 'wbisp_html_path'=>'',
  354. 'wbisp_pdf_path'=>'',
  355. 'wbisp_html_time'=>0,
  356. 'wbisp_pdf_time'=>0,
  357. 'is_studytrend_img'=>0,
  358. 'studytrend_img_path'=>'',
  359. 'is_plan_created'=>0,
  360. 'plan_topic_time'=>0,
  361. 'plan_id'=>null,
  362. 'wb_page_num'=>0,
  363. 'isp_page_num'=>0,
  364. 'wbisp_page_num'=>0,
  365. 'is_three_isp_download'=>0,
  366. 'is_two_isp_download'=>0,
  367. 'is_wrongbook_download'=>0,
  368. 'is_wrong_plan_created'=>0,
  369. 'studytrend_img_time'=>0,
  370. 'download_three_isp_time'=>0,
  371. 'download_two_isp_time'=>0,
  372. 'download_wrongbook_time'=>0,
  373. 'wrong_plan_id'=>null,
  374. 'wrong_plan_topic_time'=>0,
  375. ),
  376. $criteria);
  377. SStudentPaperRelationProperty::model()->updateAll(
  378. array(
  379. 'is_studytrend_img'=>'',
  380. 'studytrend_img_path'=>'',
  381. 'studytrend_img_time'=>0,
  382. 'is_wb'=>0,
  383. 'wb_complete_time'=>'',
  384. 'is_isp'=>0,
  385. 'isp_complete_time'=>0,
  386. 'is_wbisp'=>0,
  387. 'wbisp_complete_time'=>0,
  388. 'is_enc_lang'=>'',
  389. 'is_studytrend'=>0,
  390. 'is_kps_analy'=>0,
  391. 'is_scoring_detail'=>'',
  392. 'is_tips'=>0,
  393. 'student_order_rate'=>'',
  394. 'wb_level'=>'',
  395. 'isp_level'=>'',
  396. 'wb_isp_level'=>'',
  397. ),
  398. $criteria);
  399. }
  400. $this->sConn->createCommand("update exam_product_status set is_create_html=0,html_path='',html_create_time=0,is_create_pdf=0,pdf_path='',pdf_create_time=0,is_download=0,download_time=0,pdf_page_num=0,pdf_sheet_num=0 where exam_id in(".implode(',',$exam_ids).")")->execute();
  401. $this->sConn->createCommand("delete from can_generate_product where exam_id in(".implode(',',$exam_ids).")")->execute();
  402. Exam::model()->updateAll(array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0,
  403. 'is_topwb_pdf'=>0,
  404. 'is_academicr_html'=>0),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  405. if($exam_group->mark_status==0){
  406. ExamGroup::model()->updateAll(array('is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  407. }else{
  408. ExamGroup::model()->updateAll(array('mark_status'=>1,'is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  409. }
  410. //
  411. $rs=json_decode(http('/qxk/marking/exam/recover/'.$exam_data['exam_group_id'],'PUT',$this->schoolId,array(),'cgi'),true);
  412. if(isset($rs['errCode']) && $rs['errCode']=='00'){
  413. $trans->commit();
  414. }else{
  415. throw new Exception($rs['errMsg']);
  416. }
  417. if($exam_group->homework==1) {
  418. //发送学生端消息
  419. $sendJsonArr = array(
  420. 'school_id' => $this->schoolId,
  421. 'send_type' => 'zsyas',
  422. 'update_type' => 5,
  423. 'exam_group_id' => $exam_data['exam_group_id'],
  424. );
  425. sendStudentCacheQueue($sendJsonArr);
  426. }
  427. }catch(Exception $e)
  428. {
  429. $trans->rollBack();
  430. if($_exam_id){
  431. echo json_encode(array('status'=>0,'msg'=>'异常数据,无法写入!'));exit;
  432. }
  433. if($e->getMessage()){
  434. echo "<div style='margin-top:200px;'>".$e->getMessage()."</div>";exit;
  435. }else{
  436. echo "<div style='margin-top:200px;'>失败</div>";exit;
  437. }
  438. }
  439. }
  440. }
  441. if($_exam_id){
  442. echo json_encode(array('status'=>1,'msg'=>'成功'));exit;
  443. }
  444. echo "<div style='margin-top:200px;'>成功</div>";exit;
  445. }
  446. public function actionUp()
  447. {
  448. $paper_id = Req::post('paper_id');
  449. $topic_id = Req::post('topic_id');
  450. $order = Req::post('order');
  451. $type = Req::post('type');
  452. if(!$paper_id || !$topic_id || !$order || !$type)
  453. {
  454. echo json_encode(array('status'=>-1));exit;
  455. }
  456. /*$topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and `type`='.$type.' and `order` =:order','params'=>array(':paper_id'=>$paper_id,':order'=>$order-1)));*/
  457. $topic_data = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paper_id}' and `type` = ".$type." and `order` < ".$order." order by `order` desc limit 1")->queryRow();
  458. if(empty($topic_data))
  459. {
  460. echo json_encode(array('status'=>0));exit;
  461. }
  462. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  463. $exam_ids = array();
  464. $paper_ids = array();
  465. if($paper_data)
  466. {
  467. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  468. if($exam_data)
  469. {
  470. $tpl_data = json_decode($exam_data->tpl_data,1);
  471. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  472. if($exam_group_data)
  473. {
  474. foreach($exam_group_data as $v)
  475. {
  476. $exam_ids[$v->exam_id] = $v->exam_id;
  477. }
  478. if($exam_ids)
  479. {
  480. $criteria = new CDbCriteria();
  481. $criteria->addInCondition('exam_id',$exam_ids);
  482. $paper_data = SPaper::model()->findAll($criteria);
  483. if($paper_data)
  484. {
  485. foreach($paper_data as $v)
  486. {
  487. $paper_ids[$v->paper_id] = $v->paper_id;
  488. }
  489. $trans = $this->sConn->beginTransaction();
  490. try{
  491. $sql='update `paper_topic_relation` set `order` = '.($topic_data['order']).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id;
  492. $this->sConn->createCommand($sql)->execute();
  493. $sql='update `paper_topic_relation` set `order` = '.($order).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_data['topic_id'];
  494. $this->sConn->createCommand($sql)->execute();
  495. $trans->commit();
  496. }
  497. catch(Exception $e){
  498. $trans->rollBack();
  499. echo json_encode(array('status'=>0));exit;
  500. }
  501. unset($trans);
  502. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id','params'=>array(':paper_id'=>$paper_id)));
  503. if($paper_topic_data)
  504. {
  505. foreach($paper_topic_data as $k=>$v)
  506. {
  507. if($v->type != 1 ||$v->type != 11)
  508. {
  509. $type_score[$v->type][] = $v->score;
  510. }
  511. }
  512. if($type_score)
  513. {
  514. foreach($type_score as $k=>$v)
  515. {
  516. if(isset($tpl_data['items'][$k]) && !empty($tpl_data['items'][$k]))
  517. {
  518. $tpl_data['items'][$k]['perScores'] = $v;
  519. }
  520. }
  521. }
  522. $json_tpl_data = jsonEncode($tpl_data);
  523. $tran = $this->sConn->beginTransaction();
  524. try{
  525. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  526. $this->sConn->createCommand($sql)->execute();
  527. $tran->commit();
  528. }
  529. catch(Exception $e){
  530. $tran->rollBack();
  531. echo json_encode(array('status'=>0));exit;
  532. }
  533. }
  534. echo json_encode(array('status'=>0));exit;
  535. }
  536. }
  537. }
  538. }
  539. }
  540. }
  541. public function actionDown()
  542. {
  543. $paper_id = Req::post('paper_id');
  544. $topic_id = Req::post('topic_id');
  545. $order = Req::post('order');
  546. $type = Req::post('type');
  547. if(!$paper_id || !$topic_id || !$order)
  548. {
  549. echo json_encode(array('status'=>-1));exit;
  550. }
  551. //$topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and `type`='.$type.' and `order` =:order','params'=>array(':paper_id'=>$paper_id,':order'=>$order+1)));
  552. $topic_data = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paper_id}' and `type` = ".$type." and `order` > ".$order." order by `order` asc limit 1")->queryRow();
  553. if(empty($topic_data))
  554. {
  555. echo json_encode(array('status'=>0));exit;
  556. }
  557. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  558. $exam_ids = array();
  559. $paper_ids = array();
  560. $type_score = array();
  561. if($paper_data)
  562. {
  563. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  564. if($exam_data)
  565. {
  566. $tpl_data = json_decode($exam_data->tpl_data,1);
  567. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  568. if($exam_group_data)
  569. {
  570. foreach($exam_group_data as $v)
  571. {
  572. $exam_ids[$v->exam_id] = $v->exam_id;
  573. }
  574. if($exam_ids)
  575. {
  576. $criteria = new CDbCriteria();
  577. $criteria->addInCondition('exam_id',$exam_ids);
  578. $paper_data = SPaper::model()->findAll($criteria);
  579. if($paper_data)
  580. {
  581. foreach($paper_data as $v)
  582. {
  583. $paper_ids[$v->paper_id] = $v->paper_id;
  584. }
  585. $trans = $this->sConn->beginTransaction();
  586. try{
  587. $sql='update `paper_topic_relation` set `order` = '.($topic_data['order']).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id;
  588. $this->sConn->createCommand($sql)->execute();
  589. $sql='update `paper_topic_relation` set `order` = '.($order).' ,`no` = 0 where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_data['topic_id'];
  590. $this->sConn->createCommand($sql)->execute();
  591. $trans->commit();
  592. }
  593. catch(Exception $e){
  594. $trans->rollBack();
  595. echo json_encode(array('status'=>0));exit;
  596. }
  597. unset($trans);
  598. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id','params'=>array(':paper_id'=>$paper_id)));
  599. if($paper_topic_data)
  600. {
  601. foreach($paper_topic_data as $k=>$v)
  602. {
  603. if($v->type != 1 ||$v->type != 11 )
  604. {
  605. $type_score[$v->type][] = $v->score;
  606. }
  607. }
  608. if($type_score)
  609. {
  610. foreach($type_score as $k=>$v)
  611. {
  612. if(isset($tpl_data['items'][$k]) && !empty($tpl_data['items'][$k]))
  613. {
  614. $tpl_data['items'][$k]['perScores'] = $v;
  615. }
  616. }
  617. }
  618. $json_tpl_data = jsonEncode($tpl_data);
  619. $tran = $this->sConn->beginTransaction();
  620. try{
  621. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  622. $this->sConn->createCommand($sql)->execute();
  623. $tran->commit();
  624. }
  625. catch(Exception $e){
  626. $tran->rollBack();
  627. echo json_encode(array('status'=>0));exit;
  628. }
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }
  635. }
  636. public function actionScore()
  637. {
  638. $paper_id = Req::post('paper_id');
  639. $topic_id = Req::post('topic_id');
  640. $score = Req::post('score');
  641. $type = Req::post('type');
  642. $question_count = Req::post('question_count'); //小问
  643. $question_score = Req::post('question_score'); //小问
  644. if(!$paper_id || !$topic_id || !$type || !$score)
  645. {
  646. echo json_encode(array('status'=>-1));exit;
  647. }
  648. $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id)));
  649. $type_score = array();
  650. $paper_score = 0;
  651. $score_diff=0; //分差
  652. if(empty($topic_data))
  653. {
  654. echo json_encode(array('status'=>0));exit;
  655. }
  656. $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)));
  657. if($paper_topic_data)
  658. {
  659. foreach($paper_topic_data as $v)
  660. {
  661. $type_score[$v->type][$v['order']] = $v['score'];
  662. }
  663. }
  664. $score_diff=$score-$topic_data->score;
  665. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  666. $exam_ids = array();
  667. $paper_ids = array();
  668. if($paper_data)
  669. {
  670. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  671. if($exam_data)
  672. {
  673. $tpl_data = json_decode($exam_data->tpl_data,1);
  674. if($score_diff==0){
  675. if($question_count>0){
  676. //只改小问
  677. if(isset($tpl_data['new_items'])){
  678. $tpl_data['new_items'][($topic_data->order-1)]['scores']=$question_score;
  679. }
  680. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  681. foreach($exam_group_data as $v)
  682. {
  683. $exam_ids[$v->exam_id] = $v->exam_id;
  684. }
  685. if($exam_ids) {
  686. $criteria = new CDbCriteria();
  687. $criteria->addInCondition('exam_id', $exam_ids);
  688. $paper_data = SPaper::model()->findAll($criteria);
  689. if ($paper_data) {
  690. foreach ($paper_data as $v) {
  691. $paper_ids[$v->paper_id] = $v->paper_id;
  692. }
  693. }
  694. }
  695. $trans = $this->sConn->beginTransaction();
  696. try{
  697. $sql='update `paper_topic_relation` set `question_count`='.$question_count.',`question_score_str`="'.$question_score.'" where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id;
  698. $this->sConn->createCommand($sql)->execute();
  699. $sql="update `exam` set `tpl_data` = '".(jsonEncode($tpl_data))."' where exam_id in (".implode(',',$exam_ids).")";
  700. $this->sConn->createCommand($sql)->execute();
  701. $trans->commit();
  702. echo json_encode(array('status'=>1,'score'=>$score));exit;
  703. }catch (\Exception $e){
  704. $trans->rollback();
  705. echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit;
  706. }
  707. }else{
  708. echo json_encode(array('status'=>0,'msg'=>'分数与原分数相同'));exit;
  709. }
  710. }
  711. $perScores=array();
  712. $old_paper_score = $paper_data->score;
  713. if($topic_data->type==17||$topic_data->type==27){
  714. $_score = 0;
  715. if(isset($tpl_data['items'][$topic_data->type]['perScores']) && !empty($tpl_data['items'][$topic_data->type]['perScores'])){
  716. $_score = $tpl_data['items'][$topic_data->type]['perScores'][0];
  717. }
  718. if(isset($tpl_data['items'][$topic_data->type]['score']) && !empty($tpl_data['items'][$topic_data->type]['score'])){
  719. $_score = $tpl_data['items'][$topic_data->type]['score'];
  720. }
  721. if(isset($tpl_data['items'][$topic_data->type]['perScore']) && !empty($tpl_data['items'][$topic_data->type]['perScore'])){
  722. $_score = $tpl_data['items'][$topic_data->type]['perScore'];
  723. }
  724. if(isset($tpl_data['items'][$topic_data->type]['required']) && !empty($tpl_data['items'][$topic_data->type]['required'])){
  725. $paper_score = $old_paper_score-($tpl_data['items'][$topic_data->type]['required']*$_score)+($tpl_data['items'][$topic_data->type]['required']*$score);
  726. }
  727. if(isset($tpl_data['items'][$topic_data->type]['score']) && !empty($tpl_data['items'][$topic_data->type]['score']))
  728. {
  729. $tpl_data['items'][$topic_data->type]['score'] = $score;
  730. }
  731. if(isset($tpl_data['items'][$topic_data->type]['perScore']) && !empty($tpl_data['items'][$topic_data->type]['perScore'])){
  732. $tpl_data['items'][$topic_data->type]['perScore'] = $score;
  733. }
  734. if(isset($tpl_data['items'][$topic_data->type]['perScores']) && !empty($tpl_data['items'][$topic_data->type]['perScores'])){
  735. foreach ($tpl_data['items'][$topic_data->type]['perScores'] as $key => $datum){
  736. $tpl_data['items'][$topic_data->type]['perScores'][$key]=$score;
  737. }
  738. }
  739. }else{
  740. foreach ($type_score[$topic_data->type] as $k => $val){
  741. if($k==$topic_data->order){
  742. $perScores[]=$score;
  743. }else{
  744. $perScores[]=$val;
  745. }
  746. }
  747. $paper_score = $old_paper_score-$topic_data->score+$score;
  748. $tpl_data['items'][$topic_data->type]['perScores']=$perScores;
  749. if(isset($tpl_data['items'][$topic_data->type]['perScore']))
  750. {
  751. unset($tpl_data['items'][$topic_data->type]['perScore']);
  752. }elseif(isset($tpl_data['items'][$topic_data->type]['score'])){
  753. unset($tpl_data['items'][$topic_data->type]['score']);
  754. }
  755. if(isset($tpl_data['items'][$topic_data->type]['totalScore']) && !empty($tpl_data['items'][$topic_data->type]['totalScore'])){
  756. $tpl_data['items'][$topic_data->type]['totalScore'] = array_sum($perScores);
  757. }
  758. }
  759. //修改new_items
  760. if(isset($tpl_data['new_items'])){
  761. if($topic_data->type==17||$topic_data->type==27){
  762. //选做题
  763. if(isset($tpl_data['new_items'][($topic_data->order-1)]['showNum'])){
  764. $showNum=$tpl_data['new_items'][($topic_data->order-1)]['showNum'];
  765. foreach ($tpl_data['new_items'] as $key =>$datum){
  766. if($datum['showNum']==$showNum){
  767. $tpl_data['new_items'][$key]['score']=$score;
  768. }
  769. }
  770. }else{
  771. $showNum=intval($tpl_data['new_items'][($topic_data->order-1)]['alias']);
  772. foreach ($tpl_data['new_items'] as $key =>$datum){
  773. if(intval($datum['alias'])==$showNum){
  774. $tpl_data['new_items'][$key]['score']=$score;
  775. }
  776. }
  777. }
  778. }else{
  779. $tpl_data['new_items'][($topic_data->order-1)]['score']=$score;
  780. if($question_score){
  781. $tpl_data['new_items'][($topic_data->order-1)]['scores']=$question_score;
  782. }
  783. }
  784. }else{
  785. $tpl_data= $this->createNewItems($tpl_data);
  786. }
  787. $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  788. $paper_score=$this->sumTplDataScores($tpl_data,$examGroup->is_third);
  789. $tpl_data['total_score']=$tpl_data['scores']=$paper_score;
  790. $json_tpl_data = jsonEncode($tpl_data);
  791. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  792. $needSendMsgForQXK=false;
  793. if($exam_group_data)
  794. {
  795. foreach($exam_group_data as $v)
  796. {
  797. $exam_ids[$v->exam_id] = $v->exam_id;
  798. }
  799. if($exam_ids)
  800. {
  801. $criteria = new CDbCriteria();
  802. $criteria->addInCondition('exam_id',$exam_ids);
  803. $paper_data = SPaper::model()->findAll($criteria);
  804. if($paper_data)
  805. {
  806. foreach($paper_data as $v)
  807. {
  808. $paper_ids[$v->paper_id] = $v->paper_id;
  809. }
  810. $trans = $this->sConn->beginTransaction();
  811. try{
  812. if(in_array($topic_data->type,array(1,2,11)))
  813. {
  814. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  815. $this->sConn->createCommand($sql)->execute();
  816. //修改学生得分
  817. $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 ";
  818. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  819. if($students){
  820. $studentIds=array();
  821. foreach ($students as $v){
  822. $studentIds[]=$v['student_id'];
  823. }
  824. $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 ";
  825. $this->sConn->createCommand($sql)->execute();
  826. $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  827. $this->sConn->createCommand($sql)->execute();
  828. $sendParam=array(
  829. 'school_id'=>$this->schoolId,
  830. 'exam_group_id'=>$exam_data->exam_group_id
  831. );
  832. sendZsystNotic($sendParam);
  833. $kafkaData=array(
  834. 'schoolId'=>$this->schoolId,
  835. 'examGroupId'=>$exam_data->exam_group_id,
  836. 'generateTime'=>time()*1000
  837. );
  838. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  839. $this->sendNoticeToReport($exam_data->exam_group_id);
  840. }
  841. }elseif($topic_data->type==17 ||$topic_data->type==27){
  842. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `type` = '.$topic_data->type;
  843. $this->sConn->createCommand($sql)->execute();
  844. $sql='update `marking_topic` set `topic_score` = '.$score.' where exam_group_id = '.$exam_data->exam_group_id.' and topic_type = '.$topic_data->type;
  845. $this->sConn->createCommand($sql)->execute();
  846. $needSendMsgForQXK=true;
  847. }else
  848. {
  849. if($question_score){
  850. $sql='update `paper_topic_relation` set `score` = '.$score.',`question_count`='.$question_count.',`question_score_str`="'.$question_score.'" where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id;
  851. }else{
  852. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$topic_id;
  853. }
  854. $this->sConn->createCommand($sql)->execute();
  855. $sql='update `marking_topic` set `topic_score` = '.$score.' where exam_group_id = '.$exam_data->exam_group_id.' and topic_id = '.$topic_id;
  856. $this->sConn->createCommand($sql)->execute();
  857. $needSendMsgForQXK=true;
  858. }
  859. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
  860. $this->sConn->createCommand($sql)->execute();
  861. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  862. $this->sConn->createCommand($sql)->execute();
  863. //发送学生端消息
  864. $sendJsonArr=array(
  865. 'school_id'=>$this->schoolId,
  866. 'send_type'=>'zsyas',
  867. 'update_type'=>0,
  868. 'exam_group_id'=>$exam_data->exam_group_id,
  869. );
  870. sendStudentCacheQueue($sendJsonArr);
  871. $trans->commit();
  872. $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  873. if($examGroup['qxk_paper_id'] && $needSendMsgForQXK){
  874. sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
  875. }
  876. }
  877. catch(Exception $e){
  878. $trans->rollBack();
  879. echo json_encode(array('status'=>0));exit;
  880. }
  881. if(Yii::app()->params['handle_log_on_off'])
  882. {
  883. writeFileLog(jsonEncode(array(
  884. "exam_group_id" => 0,
  885. "operate_project" => 'zsyas2',
  886. "school_id" => $this->schoolId,
  887. "title" => '修改分数',
  888. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  889. "operate_method" => $this->action,
  890. "operate_url" => $this->getRoute(),
  891. "operate_sql" =>'',
  892. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  893. "date"=>date('Y-m-d H:i:s')
  894. )));
  895. }
  896. echo json_encode(array('status'=>1,'score'=>$score));exit;
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. private function paper_score($topic_type,$tpl_array)
  904. {
  905. if(!$topic_type || !$tpl_array)
  906. {
  907. return 0;
  908. }
  909. $scores = array();
  910. // print_r($tpl_data);exit;
  911. foreach($topic_type as $v)
  912. {
  913. if( $tpl_array && isset($tpl_array['items'][$v]['required']) && !empty($tpl_array['items'][$v]['required']))
  914. {
  915. $scores[$v] = $tpl_array['items'][$v]['score']*$tpl_array['items'][$v]['required'];
  916. }elseif(isset($tpl_array['items'][$v]) && !empty($tpl_array['items'][$v])){
  917. if(isset($tpl_array['items'][$v]['perScores']) && !empty($tpl_array['items'][$v]['perScores']))
  918. {
  919. if(is_array($tpl_array['items'][$v]['perScores']))
  920. {
  921. $scores[$v] = array_sum($tpl_array['items'][$v]['perScores']);
  922. }else
  923. {
  924. if(isset($tpl_array['items'][$v]['score']))
  925. {
  926. $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['score'];
  927. }else
  928. {
  929. $scores[$v] = 0;
  930. }
  931. }
  932. }elseif(isset($tpl_array['items'][$v]['perScore']) && !empty($tpl_array['items'][$v]['perScore']))
  933. {
  934. $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['perScore'];
  935. }else{
  936. if(isset($tpl_array['items'][$v]['score']))
  937. {
  938. $scores[$v] = $tpl_array['items'][$v]['total']*$tpl_array['items'][$v]['score'];
  939. }else
  940. {
  941. $scores[$v] = 0;
  942. }
  943. }
  944. }else{
  945. $scores[$v] = 0;
  946. }
  947. }
  948. return array_sum($scores);
  949. }
  950. private function jsonEncode($arr)
  951. {
  952. $jsonSupport = version_compare(PHP_VERSION, '5.4', '>=');
  953. if ($jsonSupport)
  954. {
  955. $result = json_encode($arr, JSON_UNESCAPED_UNICODE);
  956. }
  957. else
  958. {
  959. $result = json_encode($arr);
  960. $result = preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $result);
  961. }
  962. return $result;
  963. }
  964. public function actionAnswer()
  965. {
  966. $paper_id = Req::post('paper_id');
  967. $topic_id = Req::post('topic_id');
  968. $answer = Req::post('answer');
  969. $type = Req::post('type');
  970. if(!$paper_id || !$topic_id || !$answer || !$type)
  971. {
  972. echo -2;exit;
  973. }
  974. if($type==1)
  975. {
  976. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  977. if($paper_data)
  978. {
  979. $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type',array(':paper_id'=>$paper_id,':topic_id'=>$topic_id,':type'=>$type));
  980. if(!$paper_student_data)
  981. {
  982. echo -3;exit;
  983. }
  984. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  985. if($exam_data)
  986. {
  987. $rs = apiPost(Yii::app()->params['get_api_url'].'/rest/reset/topic_answer', array(
  988. "schoolId" => $this->schoolId,
  989. "examGroupId" => $exam_data->exam_group_id,
  990. "topicId" => $topic_id,
  991. "answer" => $answer
  992. ));
  993. $result = json_decode($rs,1);
  994. if(!$result)
  995. {
  996. echo -4;exit;
  997. }
  998. if(isset($result['success']) && $result['success']<1)
  999. {
  1000. echo -5;exit;
  1001. }else
  1002. {
  1003. echo 1;exit;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. echo 0;exit;
  1009. }
  1010. public function actionUpdate_answer()
  1011. {
  1012. $paper_id = Req::post('paper_id');
  1013. $topic_id = Req::post('topic_id');
  1014. $answer = Req::post('answer');
  1015. $type = Req::post('type');
  1016. if(!$paper_id || !$topic_id || !$answer || !$type)
  1017. {
  1018. echo -2;exit;
  1019. }
  1020. if($type != 1)
  1021. {
  1022. echo -3;exit;
  1023. }
  1024. $answer_type = array(
  1025. 'A','B','C','D'
  1026. );
  1027. if(!in_array($answer,$answer_type))
  1028. {
  1029. echo -4;exit;
  1030. }
  1031. $sort_order = array_search($answer,$answer_type);
  1032. $topic_data = STopic::model()->find('topic_id=:topic_id and topic_type=:topic_type',array(':topic_id'=>$topic_id,':topic_type'=>$type));
  1033. if(!$topic_data)
  1034. {
  1035. echo -1;exit;
  1036. }
  1037. $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$topic_id)));
  1038. if($topic_option_data)
  1039. {
  1040. $flags = 0;
  1041. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$topic_id));
  1042. if($flags)
  1043. {
  1044. $flags = 0;
  1045. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order=:sort_order',array(':topic_id'=>$topic_id,':sort_order'=>$sort_order));
  1046. $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$topic_id));
  1047. if($topic_item_option)
  1048. {
  1049. $topicInfo = Yii::app()->school_topic_cache->hmget('content:school_topic:'.$topic_id,array(
  1050. 'id','type_id','title','school_id','type_name','difficulty',
  1051. 'subject_id','create_time','update_time','subject_name','teacher_tips',
  1052. 'source','relation_topic','teaching_quality','source_title','parse_video','parse_content','difficulty_degree','kps','specials','items'));
  1053. $topic_array = array();
  1054. if($topicInfo)
  1055. {
  1056. $options = array();
  1057. foreach($topic_item_option as $k=>$v)
  1058. {
  1059. $options[$k]['topic_id'] = $v->topic_id;
  1060. $options[$k]['option_id'] = $v->option_id;
  1061. $options[$k]['option_content'] = $v->option_content;
  1062. $options[$k]['option_correct'] = $v->option_correct;
  1063. $options[$k]['option_score'] = $v->option_score;
  1064. $options[$k]['sort_order'] = $v->sort_order;
  1065. }
  1066. $topic_array['id'] = $topicInfo[0];
  1067. $topic_array['type_id'] = $topicInfo[1];
  1068. $topic_array['title'] = $topicInfo[2];
  1069. $topic_array['school_id'] = $topicInfo[3];
  1070. $topic_array['type_name'] = $topicInfo[4];
  1071. $topic_array['difficulty'] = $topicInfo[5];
  1072. $topic_array['subject_id'] = $topicInfo[6];
  1073. $topic_array['create_time'] = $topicInfo[7];
  1074. $topic_array['update_time'] = $topicInfo[8];
  1075. $topic_array['subject_name'] = $topicInfo[9];
  1076. $topic_array['teacher_tips'] = $topicInfo[10];
  1077. $topic_array['source'] = $topicInfo[11];
  1078. $topic_array['relation_topic'] = $topicInfo[12];
  1079. $topic_array['teaching_quality'] = $topicInfo[13];
  1080. $topic_array['source_title'] = $topicInfo[14];
  1081. $topic_array['parse_video'] = $topicInfo[15];
  1082. $topic_array['parse_content'] = $topicInfo[16];
  1083. $topic_array['difficulty_degree'] = $topicInfo[17];
  1084. $topic_array['kps'] = $topicInfo[18];
  1085. $topic_array['specials'] = $topicInfo[19];
  1086. $topic_array['items'] = json_decode($topicInfo[20],1);
  1087. $topic_array['items'][0]['options'] = $options;
  1088. $topic_array['items'] = json_encode($topic_array['items']);
  1089. Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_id,$topic_array);
  1090. }
  1091. }
  1092. if($flags){
  1093. echo 1;exit;
  1094. }
  1095. }
  1096. }else
  1097. {
  1098. echo -5;exit;
  1099. }
  1100. echo 0;exit;
  1101. }
  1102. /*修改多选题答案OR规则*/
  1103. public function actionChangeMulti(){
  1104. ini_set('memory_limit', '500M');
  1105. $exam_id = Req::post('exam_id');
  1106. $topic_id = Req::post('topic_id');
  1107. $answer = Req::post('answer');
  1108. $type = Req::post('type');
  1109. $rule = Req::post('rule');
  1110. $score_m = Req::post('score_m');
  1111. $score_half_m = Req::post('score_half_m');
  1112. $step = Req::post('step'); //第几步操作
  1113. $needUpdatePaperScore=false; // 是否需要修改试卷的分数
  1114. $result=array(
  1115. 'status'=>0
  1116. );
  1117. if(!$exam_id || !$topic_id || !$answer || !$type || !$rule) {
  1118. exit(json_encode($result));
  1119. }
  1120. if(!is_numeric($score_m)){
  1121. $result['msg']='分数必须为数值类型';
  1122. exit(json_encode($result));
  1123. }
  1124. if(!$score_m){
  1125. $result['msg']='分数不能为空';
  1126. exit(json_encode($result));
  1127. };
  1128. // if(!$score_half_m && $rule!=1){
  1129. // $result['msg']='半对分数不能为空';
  1130. // exit(json_encode($result));
  1131. // };
  1132. if($score_half_m>$score_m){
  1133. $result['msg']='半对分数不能大于满分';
  1134. exit(json_encode($result));
  1135. };
  1136. if(!in_array($rule,array(1,2,3,4,5))){
  1137. $result['msg']='评分规则错误';
  1138. exit(json_encode($result));
  1139. }
  1140. $ExamModel=new SExam();
  1141. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  1142. if(!$ExamInfo){
  1143. $result['msg']='考试ID错误1';
  1144. exit(json_encode($result));
  1145. }
  1146. $Exam_GroupId=$ExamInfo['exam_group_id'];
  1147. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  1148. $AllExamIds=array();
  1149. $tplData=array();
  1150. if($AllExam){
  1151. foreach($AllExam as $val){
  1152. if($val){
  1153. $AllExamIds[]=$val['exam_id'];
  1154. if(!$tplData){
  1155. $tplData=json_decode($val['tpl_data'],true);
  1156. }
  1157. }
  1158. }
  1159. }
  1160. if(!$AllExamIds){
  1161. $result['msg']='考试ID错误2';
  1162. exit(json_encode($result));
  1163. }
  1164. $AllPaperIds=array();
  1165. $paperScore=array();
  1166. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  1167. if($AllPaper){
  1168. foreach ($AllPaper as $val){
  1169. $AllPaperIds[]=$val['paper_id'];
  1170. $paperScore[$val['paper_id']]=$val['score'];
  1171. }
  1172. }
  1173. if(!$AllPaperIds){
  1174. $result['msg']='考试ID错误3';
  1175. exit(json_encode($result));
  1176. }
  1177. $Rs=array();
  1178. foreach ($AllPaperIds as $pid){
  1179. if($step==1){
  1180. //只更改了规则,修改数据只针对有错误的学生
  1181. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id." and is_right=0");
  1182. }elseif($step==2){
  1183. //修改答案,影响范围是所有的学生
  1184. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id);
  1185. }elseif($step==3){
  1186. //改了分数,对所有学生有影响
  1187. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id);
  1188. }else{
  1189. $result['msg']='参数错误,超出允许修改范围';
  1190. exit(json_encode($result));
  1191. }
  1192. if($tempData){
  1193. foreach ($tempData as $v){
  1194. $Rs[]=array(
  1195. 'topic_id' =>$v['topic_id'],
  1196. 'answer' =>$v['answer'],
  1197. 'paper_id' =>$v['paper_id'],
  1198. 'student_id' =>$v['student_id'],
  1199. );
  1200. }
  1201. }
  1202. }
  1203. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and `type`='{$type}' ")->queryAll();
  1204. if(!$paperTopicRelation){
  1205. $result['msg']='试卷试题有误';
  1206. exit(json_encode($result));
  1207. }
  1208. //更新规则
  1209. $order=0;
  1210. $tplRules=array();
  1211. if(isset($tplData['new_rules'])){
  1212. $tplRules=$tplData['new_rules'];
  1213. }
  1214. foreach ($paperTopicRelation as $value){
  1215. if($value['topic_id']==$topic_id){
  1216. $order=$value['order'];
  1217. if(isset($tplRules[$value['order']]) && $tplRules[$order]['rule_score_half']!=$score_half_m && $step==3){
  1218. $needUpdatePaperScore=true;
  1219. }
  1220. if($value['score']!=$score_m && $step==3){
  1221. //需要修改试卷分数
  1222. $needUpdatePaperScore=true;
  1223. $tplData['total_score']=$tplData['scores'] = $tplData['scores']-$value['score']+$score_m;
  1224. }
  1225. $tplRules[$value['order']]=array(
  1226. 'topicNo'=>$value['order'],
  1227. 'topic_id'=>$topic_id,
  1228. 'rule_type'=>(int)$rule,
  1229. 'rule_answer'=>$answer,
  1230. 'rule_score'=>$score_m,
  1231. 'rule_score_half'=>$score_half_m
  1232. );
  1233. $perScores[]=$score_m;
  1234. }else{
  1235. $perScores[]=$value['score'];
  1236. }
  1237. }
  1238. $tplData['new_rules']=$tplRules;
  1239. if($needUpdatePaperScore ){
  1240. if(isset($tplData['items'])){
  1241. $tplData['items'][$type]['perScores']=$perScores;
  1242. if(isset($tplData['items'][$type]['perScore']))
  1243. {
  1244. unset($tplData['items'][$type]['perScore']);
  1245. }elseif(isset($tplData['items'][$type]['score'])){
  1246. unset($tplData['items'][$type]['score']);
  1247. }
  1248. if(isset($tplData['items'][$type]['totalScore']) && !empty($tplData['items'][$type]['totalScore'])){
  1249. $tplData['items'][$type]['totalScore'] = array_sum($perScores);
  1250. }
  1251. }
  1252. if(isset($tplData['new_items'])){
  1253. foreach ($tplData['new_items'] as $key => $val){
  1254. if($val['id']==$order){
  1255. $tplData['new_items'][$key]['score']=$score_m;
  1256. }
  1257. }
  1258. }
  1259. }
  1260. //先更新校本题库试题答案
  1261. $rs=$this->UpdateTopicAnswer($topic_id,$answer,11);
  1262. $msgTopicUpdate='';
  1263. if(!$rs){
  1264. $result['status']=0;
  1265. $result['msg']='更新校本题库答案失败';
  1266. exit(json_encode($result));
  1267. }elseif($rs==-1){
  1268. $msgTopicUpdate='无题或不是校本题库的题';
  1269. }
  1270. if($Rs){
  1271. foreach ($Rs as $k=> $v){
  1272. if($v['topic_id'] == $topic_id){
  1273. $update_data=array();
  1274. if(!$v['answer']){
  1275. $update_data['scoring']=0;
  1276. $update_data['is_right']=0;
  1277. }else{
  1278. if($v['answer'] == $answer){
  1279. $update_data['scoring']=$score_m;
  1280. $update_data['is_right']=1;
  1281. }else{
  1282. switch ($rule){
  1283. case 1: //规则A 最严格规则
  1284. $update_data['scoring']=0;
  1285. $update_data['is_right']=0;
  1286. break;
  1287. case 2://规则B 半对规则
  1288. //查找错误选择
  1289. $answerArr=explode(',',$answer);
  1290. $tempAnswer = explode(',', $v['answer']);
  1291. $FindWrong=false;
  1292. foreach ($tempAnswer as $av) {
  1293. if(!in_array($av,$answerArr)){
  1294. $FindWrong=true;
  1295. break;
  1296. }
  1297. }
  1298. if($FindWrong){
  1299. $update_data['scoring']=0;
  1300. $update_data['is_right']=0;
  1301. }else{
  1302. $update_data['scoring']=$score_half_m;
  1303. $update_data['is_right']=0; //半对算错
  1304. }
  1305. break;
  1306. case 3://规则C 宽松半对规则
  1307. //查找正确选择
  1308. $answerArr=explode(',',$answer);
  1309. $tempAnswer = explode(',', $v['answer']);
  1310. $IsWrong=true;
  1311. if(count($tempAnswer)<=count($answerArr)){
  1312. foreach ($tempAnswer as $av) {
  1313. if (false !== strpos($answer, $av)) {
  1314. $IsWrong=false;
  1315. break;
  1316. }
  1317. }
  1318. }
  1319. //错误答案情况
  1320. if($IsWrong){
  1321. $update_data['scoring']=0;
  1322. $update_data['is_right']=0;
  1323. }else{
  1324. $update_data['scoring']=$score_half_m;
  1325. $update_data['is_right']=0; //半对算错
  1326. }
  1327. break;
  1328. case 4:
  1329. $answerArr=explode(',',$answer);
  1330. $tempAnswer = explode(',', $v['answer']);
  1331. $IsWrong=false;
  1332. if(count($tempAnswer)<=count($answerArr)){
  1333. foreach ($tempAnswer as $av) {
  1334. if(!in_array($av,$answerArr)){
  1335. $IsWrong=true;
  1336. break;
  1337. }
  1338. }
  1339. }else{
  1340. $IsWrong=true;
  1341. }
  1342. //错误答案情况
  1343. if($IsWrong){
  1344. $update_data['scoring']=0;
  1345. $update_data['is_right']=0;
  1346. }else{
  1347. //没有错误答案,且不全对,几个答案几分
  1348. $score_half_m=count($tempAnswer);
  1349. $update_data['scoring']=$score_half_m;
  1350. $update_data['is_right']=0; //半对算错
  1351. }
  1352. break;
  1353. case 5:
  1354. $answerArr=explode(',',$answer);
  1355. $tempAnswer = explode(',', $v['answer']);
  1356. $rightAnswerCount=0;
  1357. if(count($tempAnswer)<=count($answerArr)){
  1358. foreach ($tempAnswer as $av) {
  1359. if (false !== strpos($answer, $av)) {
  1360. $rightAnswerCount++;
  1361. }
  1362. }
  1363. }
  1364. $update_data['scoring']=$rightAnswerCount;
  1365. $update_data['is_right']=0; //半对算错
  1366. break;
  1367. }
  1368. }
  1369. }
  1370. if($update_data && $v['paper_id'] && $v['student_id']){
  1371. $transaction = $this->sConn->beginTransaction();
  1372. try {
  1373. $sql=" update `student_paper_topic_rs` set ";
  1374. $updatesql=array();
  1375. foreach ($update_data as $filed=>$value){
  1376. $updatesql[]="`".$filed."` = '".$value."'";
  1377. }
  1378. $sql.=implode(',',$updatesql);
  1379. $sql.=" where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' and `topic_id`='".$topic_id."'";
  1380. $this->sConn->createCommand($sql)->execute();
  1381. //更新总分queryAll
  1382. $TotalScore = $paperScore[$v['paper_id']];
  1383. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' ";
  1384. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  1385. $right_count = 0;
  1386. $partial_right_count = 0;
  1387. $wrong_count = 0;
  1388. $scoring = 0;
  1389. $lost_score = 0;
  1390. foreach ($StudentAllTopic as $value) {
  1391. if ($value['is_right'] == 1) {
  1392. $right_count++;
  1393. } elseif ($value['is_right'] == 2) {
  1394. $partial_right_count++;
  1395. } else {
  1396. $wrong_count++;
  1397. }
  1398. $scoring = bcadd($scoring, $value['scoring'], 1);
  1399. }
  1400. unset($StudentAllTopic);
  1401. $lost_score = bcsub($TotalScore, $scoring, 1);
  1402. $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."'";
  1403. $paperRelattionSql.=" where `paper_id`='".$v['paper_id']."' and `student_id`='".$v['student_id']."'";
  1404. $this->sConn->createCommand($paperRelattionSql)->execute();
  1405. $transaction->commit();
  1406. } catch (Exception $e) {
  1407. //如果操作失败, 数据回滚
  1408. $transaction->rollback();
  1409. $result['status']=0;
  1410. if(!$msgTopicUpdate){
  1411. $result['msg']='校本题库答案修改成功,报告更新失败';
  1412. }else{
  1413. $result['msg']=$msgTopicUpdate.' 报告更新失败';
  1414. }
  1415. exit(json_encode($result));
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. //修改分数,修改原试卷
  1422. $transaction = $this->sConn->beginTransaction();
  1423. try {
  1424. if($needUpdatePaperScore){
  1425. $sql = 'update `paper_topic_relation` set `score` = ' . $score_m . ' where paper_id in (' . implode(',', $AllPaperIds) . ') and `topic_id` =' . $topic_id;
  1426. $this->sConn->createCommand($sql)->execute();
  1427. $sql = 'update `paper` set `score` = ' . $tplData['scores'] . ' where paper_id in (' . implode(',', $AllPaperIds) . ')';
  1428. $this->sConn->createCommand($sql)->execute();
  1429. }
  1430. $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id = '{$Exam_GroupId}'")->execute();
  1431. $transaction->commit();
  1432. } catch (Exception $e) {
  1433. $transaction->rollback();
  1434. $result['status']=0;
  1435. $result['msg']=' 更新失败';
  1436. exit(json_encode($result));
  1437. }
  1438. $sendParam=array(
  1439. 'school_id'=>$this->schoolId,
  1440. 'exam_group_id'=>$Exam_GroupId
  1441. );
  1442. sendZsystNotic($sendParam);
  1443. $kafkaData=array(
  1444. 'schoolId'=>$this->schoolId,
  1445. 'examGroupId'=>$Exam_GroupId,
  1446. 'generateTime'=>time()*1000
  1447. );
  1448. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1449. $this->sendNoticeToReport($Exam_GroupId);
  1450. if(Yii::app()->params['handle_log_on_off'])
  1451. {
  1452. writeFileLog(jsonEncode(array(
  1453. "exam_group_id" => 0,
  1454. "operate_project" => 'zsyas2',
  1455. "school_id" => $this->schoolId,
  1456. "title" => '更新多选题报告',
  1457. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1458. "operate_method" => $this->action,
  1459. "operate_url" => $this->getRoute(),
  1460. "operate_sql" =>'',
  1461. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1462. "date"=>date('Y-m-d H:i:s')
  1463. )));
  1464. }
  1465. //发送学生端消息
  1466. $sendJsonArr=array(
  1467. 'school_id'=>$this->schoolId,
  1468. 'send_type'=>'zsyas',
  1469. 'update_type'=>0,
  1470. 'exam_group_id'=>$Exam_GroupId,
  1471. );
  1472. sendStudentCacheQueue($sendJsonArr);
  1473. $result['status']=1;
  1474. if($msgTopicUpdate){
  1475. $result['msg']=$msgTopicUpdate.' 报告更新完成';
  1476. }else{
  1477. $result['msg']='报告更新完成';
  1478. }
  1479. exit(json_encode($result));
  1480. }
  1481. //更新单选题答案new,同时更新试题
  1482. public function actionAnswerNew(){
  1483. $paper_id = Req::post('paper_id');
  1484. $topic_id = Req::post('topic_id');
  1485. $answer = Req::post('answer');
  1486. $type = Req::post('type');
  1487. if(!$paper_id || !$topic_id || !$answer || !$type)
  1488. {
  1489. echo -2;exit;
  1490. }
  1491. if ($topic_id <= 0) {
  1492. echo -2;exit;
  1493. }
  1494. $answer = strtoupper($answer);
  1495. if (! preg_match('/[A-Z]{1}/', $answer, $temp)) {
  1496. echo -2;exit;
  1497. }
  1498. if($type==1){
  1499. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  1500. if($paper_data) {
  1501. $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type', array(':paper_id' => $paper_id, ':topic_id' => $topic_id, ':type' => $type));
  1502. if (!$paper_student_data) {
  1503. echo -3;
  1504. exit;
  1505. }
  1506. $queries = array();
  1507. $paperIds = array();
  1508. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  1509. if($exam_data){
  1510. $tplData=json_decode($exam_data->tpl_data,true);
  1511. $tplData['update_answer'][$paper_student_data['order']]=array(
  1512. 'order'=>$paper_student_data['order'],
  1513. 'topic_id'=>$topic_id,
  1514. 'update_answer'=>$answer
  1515. );
  1516. $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'";
  1517. $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' ";
  1518. $papers=$this->sConn->createCommand($PaperSql)->queryAll();
  1519. if ($papers) {
  1520. foreach ($papers as $k => $v) {
  1521. $paperIds[] = $v['paper_id'];
  1522. }
  1523. $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'";
  1524. $ptr=$this->sConn->createCommand($ptrSql)->queryRow();
  1525. if ($ptr) {
  1526. $score = $ptr['score'];
  1527. $studentIds_Right = array();
  1528. $studentIds_Wrong = array();
  1529. //更新选错了,但标为正确答案的
  1530. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'";
  1531. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  1532. if ($sptr) {
  1533. foreach ($sptr as $k => $v) {
  1534. $studentIds_Wrong[] = $v['student_id'];
  1535. }
  1536. $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");";
  1537. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';";
  1538. }
  1539. //更新原本选对了,但标为错误答案的
  1540. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'";
  1541. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  1542. if ($sptr) {
  1543. foreach ($sptr as $k => $v) {
  1544. $studentIds_Right[] = $v['student_id'];
  1545. }
  1546. $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");";
  1547. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';";
  1548. }
  1549. }
  1550. }
  1551. }
  1552. if(Yii::app()->params['handle_log_on_off'])
  1553. {
  1554. writeFileLog(jsonEncode(array(
  1555. "exam_group_id" => 0,
  1556. "operate_project" => 'zsyas2',
  1557. "school_id" => $this->schoolId,
  1558. "title" => '更新报告',
  1559. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1560. "operate_method" => $this->action,
  1561. "operate_url" => $this->getRoute(),
  1562. "operate_sql" =>'',
  1563. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1564. "date"=>date('Y-m-d H:i:s')
  1565. )));
  1566. }
  1567. $flag=$this->UpdateTopicAnswer($topic_id,$answer,1);
  1568. $this->sendNoticeToReport($exam_data->exam_group_id);
  1569. if(!$flag){
  1570. // echo -6;exit;
  1571. }
  1572. if($queries){
  1573. $transaction = $this->sConn->beginTransaction();
  1574. try {
  1575. foreach ($queries as $query) {
  1576. $this->sConn->createCommand($query)->execute();
  1577. }
  1578. //更新试题答案
  1579. $transaction->commit();
  1580. $sendParam=array(
  1581. 'school_id'=>$this->schoolId,
  1582. 'exam_group_id'=>$exam_data->exam_group_id
  1583. );
  1584. sendZsystNotic($sendParam);
  1585. $kafkaData=array(
  1586. 'schoolId'=>$this->schoolId,
  1587. 'examGroupId'=>$exam_data->exam_group_id,
  1588. 'generateTime'=>time()*1000
  1589. );
  1590. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1591. //发送学生端消息
  1592. $sendJsonArr=array(
  1593. 'school_id'=>$this->schoolId,
  1594. 'send_type'=>'zsyas',
  1595. 'update_type'=>0,
  1596. 'exam_group_id'=>$exam_data->exam_group_id,
  1597. );
  1598. sendStudentCacheQueue($sendJsonArr);
  1599. echo 1;exit;
  1600. } catch (Exception $e) {
  1601. $transaction->rollback();
  1602. echo -5;exit;
  1603. }
  1604. }else{
  1605. echo -7;exit;
  1606. }
  1607. }
  1608. }
  1609. echo 0;exit;
  1610. }
  1611. //更新单选题答案,不更新试题
  1612. public function actionAnswerNewNoUpdateTopic(){
  1613. $paper_id = Req::post('paper_id');
  1614. $topic_id = Req::post('topic_id');
  1615. $answer = Req::post('answer');
  1616. $type = Req::post('type');
  1617. if(!$paper_id || !$topic_id || !$answer || !$type)
  1618. {
  1619. echo -2;exit;
  1620. }
  1621. if ($topic_id <= 0) {
  1622. echo -2;exit;
  1623. }
  1624. $answer = strtoupper($answer);
  1625. if (! preg_match('/[A-Z]{1}/', $answer, $temp)) {
  1626. echo -2;exit;
  1627. }
  1628. if($type==1){
  1629. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  1630. if($paper_data) {
  1631. $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id and type=:type', array(':paper_id' => $paper_id, ':topic_id' => $topic_id, ':type' => $type));
  1632. if (!$paper_student_data) {
  1633. echo -3;
  1634. exit;
  1635. }
  1636. $queries = array();
  1637. $paperIds = array();
  1638. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  1639. if($exam_data){
  1640. $tplData=json_decode($exam_data->tpl_data,true);
  1641. $tplData['update_answer'][$paper_student_data['order']]=array(
  1642. 'order'=>$paper_student_data['order'],
  1643. 'topic_id'=>$topic_id,
  1644. 'update_answer'=>$answer
  1645. );
  1646. $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'";
  1647. $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' ";
  1648. $papers=$this->sConn->createCommand($PaperSql)->queryAll();
  1649. if ($papers) {
  1650. foreach ($papers as $k => $v) {
  1651. $paperIds[] = $v['paper_id'];
  1652. }
  1653. $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'";
  1654. $ptr=$this->sConn->createCommand($ptrSql)->queryRow();
  1655. if ($ptr) {
  1656. $score = $ptr['score'];
  1657. $studentIds_Right = array();
  1658. $studentIds_Wrong = array();
  1659. //更新选错了,但标为正确答案的
  1660. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'";
  1661. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  1662. if ($sptr) {
  1663. foreach ($sptr as $k => $v) {
  1664. $studentIds_Wrong[] = $v['student_id'];
  1665. }
  1666. $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");";
  1667. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';";
  1668. }
  1669. //更新原本选对了,但标为错误答案的
  1670. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'";
  1671. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  1672. if ($sptr) {
  1673. foreach ($sptr as $k => $v) {
  1674. $studentIds_Right[] = $v['student_id'];
  1675. }
  1676. $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");";
  1677. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';";
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if(Yii::app()->params['handle_log_on_off'])
  1683. {
  1684. writeFileLog(jsonEncode(array(
  1685. "exam_group_id" => $exam_data->exam_group_id,
  1686. "operate_project" => 'zsyas2',
  1687. "school_id" => $this->schoolId,
  1688. "title" => '更新报告',
  1689. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1690. "operate_method" => $this->action,
  1691. "operate_url" => $this->getRoute(),
  1692. "operate_sql" =>'',
  1693. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1694. "date"=>date('Y-m-d H:i:s')
  1695. )));
  1696. }
  1697. $this->sendNoticeToReport($exam_data->exam_group_id);
  1698. if($queries){
  1699. $transaction = $this->sConn->beginTransaction();
  1700. try {
  1701. foreach ($queries as $query) {
  1702. $this->sConn->createCommand($query)->execute();
  1703. }
  1704. //更新试题答案
  1705. $transaction->commit();
  1706. $sendParam=array(
  1707. 'school_id'=>$this->schoolId,
  1708. 'exam_group_id'=>$exam_data->exam_group_id
  1709. );
  1710. sendZsystNotic($sendParam);
  1711. $kafkaData=array(
  1712. 'schoolId'=>$this->schoolId,
  1713. 'examGroupId'=>$exam_data->exam_group_id,
  1714. 'generateTime'=>time()*1000
  1715. );
  1716. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1717. echo 1;exit;
  1718. } catch (Exception $e) {
  1719. $transaction->rollback();
  1720. echo -5;exit;
  1721. }
  1722. }else{
  1723. echo -7;exit;
  1724. }
  1725. }
  1726. }
  1727. echo 0;exit;
  1728. }
  1729. //修改试题答案
  1730. private function UpdateTopicAnswer($TopicId,$Answer,$type){
  1731. $answer_type = array(
  1732. 'A','B','C','D','E','F','G','H','I','J'
  1733. );
  1734. if(!in_array($type,array(1,2,11))) return false;
  1735. if($type==1 && !in_array($Answer,$answer_type))
  1736. {
  1737. return false;
  1738. }
  1739. if(($type==11 || $type==2) && !preg_match('/^[A-Z,]+$/u',$Answer)){
  1740. return false;
  1741. }
  1742. if($type==1){
  1743. $sort_order[] = array_search($Answer,$answer_type);
  1744. }else{
  1745. $answers=explode(',',$Answer);
  1746. if(!$answers){
  1747. return false;
  1748. }
  1749. $answer_type=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  1750. foreach ($answers as $a){
  1751. $a=strtoupper($a);
  1752. $sort_order[] = array_search($a,$answer_type);
  1753. }
  1754. }
  1755. $topic_data = STopic::model()->find('topic_id=:topic_id ',array(':topic_id'=>$TopicId));
  1756. if(!$topic_data)
  1757. {
  1758. return -1; //不是校本题库的题
  1759. }
  1760. $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$TopicId)));
  1761. if($topic_option_data)
  1762. {
  1763. //判断答案范围
  1764. $sortOrderArr=array();
  1765. foreach ($sort_order as $st){
  1766. if(($st+1)>count($topic_option_data)){
  1767. return false;
  1768. }
  1769. if($st!==false){
  1770. $sortOrderArr[]=$st;
  1771. }
  1772. }
  1773. if(!$sortOrderArr){
  1774. return false;
  1775. }
  1776. //异常情况,试题没有答案情况判断
  1777. $NoAnswer=true;
  1778. foreach ($topic_option_data as $datum){
  1779. if($datum->option_correct==1){
  1780. $NoAnswer=false;
  1781. break;
  1782. }
  1783. }
  1784. $flags = 1;
  1785. if(!$NoAnswer){
  1786. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$TopicId));
  1787. }
  1788. if($flags && $sortOrderArr){
  1789. $flags = 0;
  1790. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order in ('.implode(',',$sortOrderArr).')',array(':topic_id'=>$TopicId));
  1791. $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$TopicId));
  1792. if($topic_item_option)
  1793. {
  1794. //清缓存
  1795. Yii::app()->school_topic_cache->hmset('content:school_topic:'.$TopicId,array('id' => 0));
  1796. if($topic_data->stem_id){
  1797. Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_data->stem_id,array('id' => 0));
  1798. }
  1799. }
  1800. if($flags){
  1801. return true;
  1802. }
  1803. }
  1804. }
  1805. return false;
  1806. }
  1807. //修改学生答案
  1808. public function actionEditStudentAnswer(){
  1809. $exam_id = Req::post('exam_id');
  1810. $topic_id = Req::post('topic_id');
  1811. $answer = Req::post('answer');
  1812. $old_answer = Req::post('old_answer');
  1813. $topic_answer = Req::post('topic_answer');
  1814. if(!$exam_id || !$topic_id || !$answer )
  1815. {
  1816. echo -2;exit;
  1817. }
  1818. if ($topic_id <= 0) {
  1819. echo -2;exit;
  1820. }
  1821. $answer = strtoupper($answer);
  1822. if (! preg_match('/[A-H]{1}/', $answer, $temp)) {
  1823. echo -1;exit;
  1824. }
  1825. if($old_answer && !preg_match('/[A-H]{1}/', $answer, $temp)){
  1826. echo -1;exit;
  1827. }
  1828. if($answer==$old_answer){
  1829. echo -6;exit;
  1830. }
  1831. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1832. if($exam_data){
  1833. $exam_group_id=$exam_data->exam_group_id;
  1834. $ExamAll_sql="select exam_id from exam where exam_group_id='".$exam_group_id."'";
  1835. $ExamAll=$this->sConn->createCommand($ExamAll_sql)->queryAll();
  1836. $ExamIds=array();
  1837. if($ExamAll){
  1838. foreach ($ExamAll as $val){
  1839. $ExamIds[]=$val['exam_id'];
  1840. }
  1841. $P_sql="select paper_id from paper where exam_id in(".implode(',',$ExamIds).")";
  1842. $PaperAll=$this->sConn->createCommand($P_sql)->queryAll();
  1843. $paperIds=array();
  1844. if($PaperAll){
  1845. foreach($PaperAll as $item){
  1846. $paperIds[]=$item['paper_id'];
  1847. }
  1848. $ptrSql="SELECT `score`,`order` FROM paper_topic_relation WHERE paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'";
  1849. $ptr=$this->sConn->createCommand($ptrSql)->queryRow();
  1850. if ($ptr) {
  1851. $score = $ptr['score'];
  1852. $order = $ptr['order'];
  1853. $queries=array();
  1854. if(!$topic_answer){
  1855. //没有答案,读取模板设置的答案
  1856. $third_answer_sheet=$this->sConn->createCommand("select sheet_answer from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow();
  1857. $sheetAnswer=json_decode($third_answer_sheet['sheet_answer'],true);
  1858. if(isset($sheetAnswer[$order])){
  1859. $topic_answer=$sheetAnswer[$order];
  1860. }
  1861. }
  1862. if(!$topic_answer){
  1863. echo -5;exit;
  1864. }
  1865. $is_right=0;
  1866. if($topic_answer==$answer){
  1867. $is_right=1;
  1868. }
  1869. //查询所有不是新答案的学生
  1870. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' ";
  1871. if($old_answer){
  1872. $old_answer=strtoupper($old_answer);
  1873. $sptrSql.=" AND `answer`='".$old_answer."'";
  1874. }else{
  1875. $sptrSql.=" AND `answer`!='".$answer."'";
  1876. }
  1877. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  1878. if($sptr){
  1879. $studentIds=array();
  1880. $onlyUpdateAnswerStudentIds=array();
  1881. foreach ($sptr as $k => $v) {
  1882. if(!$is_right){
  1883. //不小心更新的是错误的答案,原来答对的学生,需被要扣分,答错的,只需要更新答案不再扣分
  1884. if($v['is_right']==1){
  1885. $studentIds[] = $v['student_id'];
  1886. }else{
  1887. $onlyUpdateAnswerStudentIds[]=$v['student_id'];
  1888. }
  1889. }else{
  1890. $studentIds[] = $v['student_id'];
  1891. }
  1892. }
  1893. if($is_right && $studentIds){
  1894. $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .");";
  1895. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score .",answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .") AND topic_id = '". $topic_id ."';";
  1896. }else{
  1897. if($studentIds){
  1898. $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .");";
  1899. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0,answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds) .") AND topic_id = '". $topic_id ."';";
  1900. }
  1901. if($onlyUpdateAnswerStudentIds){
  1902. $queries[] = "UPDATE student_paper_topic_rs SET answer='".$answer."' WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $onlyUpdateAnswerStudentIds) .") AND topic_id = '". $topic_id ."';";
  1903. }
  1904. }
  1905. }
  1906. if($queries){
  1907. $transaction = $this->sConn->beginTransaction();
  1908. try {
  1909. foreach ($queries as $query) {
  1910. $this->sConn->createCommand($query)->execute();
  1911. }
  1912. //更新学生试题答案
  1913. $transaction->commit();
  1914. $sendParam=array(
  1915. 'school_id'=>$this->schoolId,
  1916. 'exam_group_id'=>$exam_group_id
  1917. );
  1918. sendZsystNotic($sendParam);
  1919. $kafkaData=array(
  1920. 'schoolId'=>$this->schoolId,
  1921. 'examGroupId'=>$exam_group_id,
  1922. 'generateTime'=>time()*1000
  1923. );
  1924. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1925. echo 1;exit;
  1926. } catch (Exception $e) {
  1927. $transaction->rollback();
  1928. echo -4;exit;
  1929. }
  1930. }else{
  1931. echo -7;exit;
  1932. }
  1933. }
  1934. if(Yii::app()->params['handle_log_on_off'])
  1935. {
  1936. writeFileLog(jsonEncode(array(
  1937. "exam_group_id" => $exam_group_id,
  1938. "operate_project" => 'zsyas2',
  1939. "school_id" => $this->schoolId,
  1940. "title" => '修改学生答案',
  1941. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1942. "operate_method" => $this->action,
  1943. "operate_url" => $this->getRoute(),
  1944. "operate_sql" =>'',
  1945. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1946. "date"=>date('Y-m-d H:i:s')
  1947. )));
  1948. }
  1949. echo 1;exit; //修改成功
  1950. }
  1951. }
  1952. }
  1953. echo -4;exit;
  1954. }
  1955. //单个班级恢复考试
  1956. public function actionRecover_one_class()
  1957. {
  1958. $exam_id = Req::post('exam_id');
  1959. $_select = 0;
  1960. if($exam_id>0)
  1961. {
  1962. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1963. // $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1964. // if($paper_data)
  1965. // {
  1966. // $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
  1967. // if($paper_topic_data)
  1968. // {
  1969. // foreach($paper_topic_data as $v)
  1970. // {
  1971. // if($v->type>1)
  1972. // {
  1973. // $_select = 1;
  1974. // }
  1975. // }
  1976. // }
  1977. // }
  1978. // if($_select==0)
  1979. // {
  1980. // if($exam_id){
  1981. // echo json_encode(array('status'=>0,'msg'=>'只有选择题的试卷无法恢复'));exit;
  1982. // }
  1983. // echo "<div style='margin-top:200px;'>只有选择题的试卷无法恢复</div>";exit;
  1984. //
  1985. // }
  1986. $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  1987. if(!$exam_group)
  1988. {
  1989. if($exam_id){
  1990. echo json_encode(array('status'=>0,'msg'=>'考试数据有误!'));exit;
  1991. }
  1992. }
  1993. if($exam_group->mark_type!=4)
  1994. {
  1995. if($exam_id){
  1996. echo json_encode(array('status'=>0,'msg'=>'非班级单独阅卷考试不能恢复!'));exit;
  1997. }
  1998. }
  1999. if($exam_data)
  2000. {
  2001. //操作日志
  2002. if(Yii::app()->params['handle_log_on_off'])
  2003. {
  2004. writeFileLog(jsonEncode(array(
  2005. "exam_group_id" => (string)$exam_data->exam_group_id,
  2006. "operate_project" => 'zsyas2',
  2007. "school_id" => $this->schoolId,
  2008. "title" => '恢复单个班级考试状态',
  2009. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2010. "operate_method" => $this->action,
  2011. "operate_url" => $this->getRoute(),
  2012. "operate_sql" => json_encode(array('update'=>array(
  2013. 'StudentPaperRelation'=>array(
  2014. 'report_created'=>0,
  2015. 'is_scoring'=>0,
  2016. 'scoring_img'=>'',
  2017. 'is_isp_html'=>0,
  2018. 'isp_html_path'=>'',
  2019. 'isp_html_time'=>0,
  2020. 'is_wrongbook_html'=>0,
  2021. 'wrongbook_html_path'=>'',
  2022. 'wrongbook_html_time'=>0,
  2023. 'is_isp_pdf'=>0,
  2024. 'isp_pdf_path'=>'',
  2025. 'isp_pdf_time'=>0,
  2026. 'is_wrongbook_pdf'=>0,
  2027. 'wrongbook_pdf_path'=>'',
  2028. 'wrongbook_pdf_time'=>0,
  2029. 'is_wbisp_html'=>0,
  2030. 'is_wbisp_pdf'=>0,
  2031. 'wbisp_html_path'=>'',
  2032. 'wbisp_pdf_path'=>'',
  2033. 'wbisp_html_time'=>0,
  2034. 'wbisp_pdf_time'=>0,
  2035. 'is_studytrend_img'=>0,
  2036. 'studytrend_img_path'=>'',
  2037. 'is_plan_created'=>0,
  2038. 'plan_topic_time'=>0,
  2039. 'plan_id'=>null,
  2040. 'wb_page_num'=>0,
  2041. 'isp_page_num'=>0,
  2042. 'wbisp_page_num'=>0,
  2043. 'is_three_isp_download'=>0,
  2044. 'is_two_isp_download'=>0,
  2045. 'is_wrongbook_download'=>0,
  2046. 'is_wrong_plan_created'=>0,
  2047. 'studytrend_img_time'=>0,
  2048. 'download_three_isp_time'=>0,
  2049. 'download_two_isp_time'=>0,
  2050. 'download_wrongbook_time'=>0,
  2051. 'wrong_plan_id'=>null,
  2052. 'wrong_plan_topic_time'=>0,
  2053. ),
  2054. 'exam'=>array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0,
  2055. 'is_topwb_pdf'=>0,
  2056. 'is_academicr_html'=>0),
  2057. 'ExamGroup'=>array('mark_status'=>1,'upload_status'=>1),
  2058. ))),
  2059. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  2060. "date"=>date('Y-m-d H:i:s')
  2061. )));
  2062. }
  2063. $trans = $this->sConn->beginTransaction();
  2064. try{
  2065. $criteria = new CDbCriteria();
  2066. $criteria->addCondition("exam_id='".$exam_id."'");
  2067. SStudentPaperRelation::model()->updateAll(
  2068. array(
  2069. 'report_created'=>0,
  2070. 'is_scoring'=>0,
  2071. 'scoring_img'=>'',
  2072. 'is_isp_html'=>0,
  2073. 'isp_html_path'=>'',
  2074. 'isp_html_time'=>0,
  2075. 'is_wrongbook_html'=>0,
  2076. 'wrongbook_html_path'=>'',
  2077. 'wrongbook_html_time'=>0,
  2078. 'is_isp_pdf'=>0,
  2079. 'isp_pdf_path'=>'',
  2080. 'isp_pdf_time'=>0,
  2081. 'is_wrongbook_pdf'=>0,
  2082. 'wrongbook_pdf_path'=>'',
  2083. 'wrongbook_pdf_time'=>0,
  2084. 'is_wbisp_html'=>0,
  2085. 'is_wbisp_pdf'=>0,
  2086. 'wbisp_html_path'=>'',
  2087. 'wbisp_pdf_path'=>'',
  2088. 'wbisp_html_time'=>0,
  2089. 'wbisp_pdf_time'=>0,
  2090. 'is_studytrend_img'=>0,
  2091. 'studytrend_img_path'=>'',
  2092. 'is_plan_created'=>0,
  2093. 'plan_topic_time'=>0,
  2094. 'plan_id'=>null,
  2095. 'wb_page_num'=>0,
  2096. 'isp_page_num'=>0,
  2097. 'wbisp_page_num'=>0,
  2098. 'is_three_isp_download'=>0,
  2099. 'is_two_isp_download'=>0,
  2100. 'is_wrongbook_download'=>0,
  2101. 'is_wrong_plan_created'=>0,
  2102. 'studytrend_img_time'=>0,
  2103. 'download_three_isp_time'=>0,
  2104. 'download_two_isp_time'=>0,
  2105. 'download_wrongbook_time'=>0,
  2106. 'wrong_plan_id'=>null,
  2107. 'wrong_plan_topic_time'=>0,
  2108. ),
  2109. $criteria);
  2110. SStudentPaperRelationProperty::model()->updateAll(
  2111. array(
  2112. 'is_studytrend_img'=>'',
  2113. 'studytrend_img_path'=>'',
  2114. 'studytrend_img_time'=>0,
  2115. 'is_wb'=>0,
  2116. 'wb_complete_time'=>'',
  2117. 'is_isp'=>0,
  2118. 'isp_complete_time'=>0,
  2119. 'is_wbisp'=>0,
  2120. 'wbisp_complete_time'=>0,
  2121. 'is_enc_lang'=>'',
  2122. 'is_studytrend'=>0,
  2123. 'is_kps_analy'=>0,
  2124. 'is_scoring_detail'=>'',
  2125. 'is_tips'=>0,
  2126. 'student_order_rate'=>'',
  2127. 'wb_level'=>'',
  2128. 'isp_level'=>'',
  2129. 'wb_isp_level'=>'',
  2130. ),
  2131. $criteria);
  2132. $this->sConn->createCommand("update exam_product_status set is_create_html=0,html_path='',html_create_time=0,is_create_pdf=0,pdf_path='',pdf_create_time=0,is_download=0,download_time=0,pdf_page_num=0,pdf_sheet_num=0 where exam_id ='".$exam_id."'")->execute();
  2133. $this->sConn->createCommand("delete from can_generate_product where exam_id ='".$exam_id."'")->execute();
  2134. Exam::model()->updateAll(array('status'=>4,'upload_status'=>1,'is_topwb_html'=>0,
  2135. 'is_topwb_pdf'=>0,
  2136. 'is_academicr_html'=>0),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  2137. ExamGroup::model()->updateAll(array('mark_status'=>1,'is_marking_stop'=>0,'upload_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data['exam_group_id']));
  2138. //
  2139. $rs=json_decode(http('/qxk/marking/exam/recover/'.$exam_data['exam_group_id'].'/clazz/'.$exam_data['class_id'],'PUT',$this->schoolId,array(),'cgi'),true);
  2140. if(isset($rs['errCode']) && $rs['errCode']=='00'){
  2141. $trans->commit();
  2142. }else{
  2143. throw new Exception($rs['errMsg']);
  2144. }
  2145. //发送学生端消息
  2146. $sendJsonArr=array(
  2147. 'school_id'=>$this->schoolId,
  2148. 'send_type'=>'zsyas',
  2149. 'update_type'=>5,
  2150. 'exam_group_id'=>$exam_data['exam_group_id'],
  2151. 'exam_id_arr'=>array($exam_id),
  2152. );
  2153. sendStudentCacheQueue($sendJsonArr);
  2154. }catch(Exception $e)
  2155. {
  2156. $trans->rollBack();
  2157. if($exam_id){
  2158. echo json_encode(array('status'=>0,'msg'=>'异常数据,无法写入!'));exit;
  2159. }
  2160. echo "<div style='margin-top:200px;'>失败</div>";exit;
  2161. }
  2162. }
  2163. }
  2164. if($exam_id){
  2165. echo json_encode(array('status'=>1,'msg'=>'成功'));exit;
  2166. }
  2167. echo "<div style='margin-top:200px;'>成功</div>";exit;
  2168. }
  2169. /*修改多选题规则*/
  2170. public function actionChangeMultiRule(){
  2171. ini_set('memory_limit', '500M');
  2172. $exam_id = Req::post('exam_id');
  2173. $topic_id = Req::post('topic_id');
  2174. $type = Req::post('type');
  2175. $rule = Req::post('rule');
  2176. $score_m = Req::post('score_m');
  2177. $score_half_m = Req::post('score_half_m');
  2178. $answer = Req::post('answer');
  2179. $result=array(
  2180. 'status'=>0
  2181. );
  2182. if(!$exam_id || !$topic_id || !$type || !$rule ) {
  2183. exit(json_encode($result));
  2184. }
  2185. if(!$score_m){
  2186. $result['msg']='分数不能为空';
  2187. exit(json_encode($result));
  2188. };
  2189. if(!$score_half_m && $rule!=1){
  2190. $result['msg']='半对分数不能为空';
  2191. exit(json_encode($result));
  2192. };
  2193. if($score_half_m>$score_m){
  2194. $result['msg']='半对分数不能大于满分';
  2195. exit(json_encode($result));
  2196. };
  2197. if(!in_array($rule,array(1,2,3,4,5))){
  2198. $result['msg']='评分规则错误';
  2199. exit(json_encode($result));
  2200. }
  2201. $ExamModel=new SExam();
  2202. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  2203. if(!$ExamInfo){
  2204. $result['msg']='考试ID错误1';
  2205. exit(json_encode($result));
  2206. }
  2207. $Exam_GroupId=$ExamInfo['exam_group_id'];
  2208. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  2209. $AllExamIds=array();
  2210. $tplData=array();
  2211. if($AllExam){
  2212. foreach($AllExam as $val){
  2213. if($val){
  2214. $AllExamIds[]=$val['exam_id'];
  2215. if(!$tplData){
  2216. $tplData=json_decode($val['tpl_data'],true);
  2217. }
  2218. }
  2219. }
  2220. }
  2221. if(!$AllExamIds){
  2222. $result['msg']='考试ID错误2';
  2223. exit(json_encode($result));
  2224. }
  2225. $AllPaperIds=array();
  2226. $paperScore=array();
  2227. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  2228. if($AllPaper){
  2229. foreach ($AllPaper as $val){
  2230. $AllPaperIds[]=$val['paper_id'];
  2231. $paperScore[$val['paper_id']]=$val['score'];
  2232. }
  2233. }
  2234. if(!$AllPaperIds){
  2235. $result['msg']='考试ID错误3';
  2236. exit(json_encode($result));
  2237. }
  2238. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and type in(2,11)")->queryAll();
  2239. if(!$paperTopicRelation){
  2240. $result['msg']='试卷试题有误';
  2241. exit(json_encode($result));
  2242. }
  2243. $Rs=array();
  2244. foreach ($AllPaperIds as $pid){
  2245. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id=".$topic_id);
  2246. if($tempData){
  2247. foreach ($tempData as $v){
  2248. $Rs[]=array(
  2249. 'topic_id' =>$v['topic_id'],
  2250. 'answer' =>$v['answer'],
  2251. 'paper_id' =>$v['paper_id'],
  2252. 'student_id' =>$v['student_id'],
  2253. );
  2254. }
  2255. }
  2256. }
  2257. //先更新校本题库试题答案
  2258. $rs=$this->UpdateTopicAnswer($topic_id,$answer,11);
  2259. $msgTopicUpdate='';
  2260. if(!$rs){
  2261. $result['status']=0;
  2262. $result['msg']='更新校本题库答案失败';
  2263. exit(json_encode($result));
  2264. }elseif($rs==-1){
  2265. $msgTopicUpdate='无题或不是校本题库的题';
  2266. }
  2267. if($Rs){
  2268. if(!$answer){
  2269. $result['msg']='答案不能为空';
  2270. exit(json_encode($result));
  2271. }
  2272. foreach ($Rs as $k=> $v){
  2273. if($v['topic_id'] == $topic_id){
  2274. $update_data=array();
  2275. if(!$v['answer']){
  2276. $update_data['scoring']=0;
  2277. $update_data['is_right']=0;
  2278. }else{
  2279. if($v['answer'] == $answer){
  2280. $update_data['scoring']=$score_m;
  2281. $update_data['is_right']=1;
  2282. }else{
  2283. switch ($rule){
  2284. case 1: //规则A 最严格规则
  2285. $update_data['scoring']=0;
  2286. $update_data['is_right']=0;
  2287. break;
  2288. case 2://规则B 半对规则
  2289. //查找错误选择
  2290. $answerArr=explode(',',$answer);
  2291. $tempAnswer = explode(',', $v['answer']);
  2292. $FindWrong=false;
  2293. foreach ($tempAnswer as $av) {
  2294. if(!in_array($av,$answerArr)){
  2295. $FindWrong=true;
  2296. break;
  2297. }
  2298. }
  2299. if($FindWrong){
  2300. $update_data['scoring']=0;
  2301. $update_data['is_right']=0;
  2302. }else{
  2303. $update_data['scoring']=$score_half_m;
  2304. $update_data['is_right']=0; //半对算错
  2305. }
  2306. break;
  2307. case 3://规则C 宽松半对规则
  2308. //查找正确选择
  2309. $answerArr=explode(',',$answer);
  2310. $tempAnswer = explode(',', $v['answer']);
  2311. $IsWrong=true;
  2312. if(count($tempAnswer)<=count($answerArr)){
  2313. foreach ($tempAnswer as $av) {
  2314. if (false !== strpos($answer, $av)) {
  2315. $IsWrong=false;
  2316. break;
  2317. }
  2318. }
  2319. }
  2320. //错误答案情况
  2321. if($IsWrong){
  2322. $update_data['scoring']=0;
  2323. $update_data['is_right']=0;
  2324. }else{
  2325. $update_data['scoring']=$score_half_m;
  2326. $update_data['is_right']=0; //半对算错
  2327. }
  2328. break;
  2329. case 4:
  2330. $answerArr=explode(',',$answer);
  2331. $tempAnswer = explode(',', $v['answer']);
  2332. $IsWrong=false;
  2333. if(count($tempAnswer)<=count($answerArr)){
  2334. foreach ($tempAnswer as $av) {
  2335. if(!in_array($av,$answerArr)){
  2336. $IsWrong=true;
  2337. break;
  2338. }
  2339. }
  2340. }else{
  2341. $IsWrong=true;
  2342. }
  2343. //错误答案情况
  2344. if($IsWrong){
  2345. $update_data['scoring']=0;
  2346. $update_data['is_right']=0;
  2347. }else{
  2348. //没有错误答案,且不全对,几个答案几分
  2349. $score_half_m=count($tempAnswer);
  2350. $update_data['scoring']=$score_half_m;
  2351. $update_data['is_right']=0; //半对算错
  2352. }
  2353. break;
  2354. case 5:
  2355. $answerArr=explode(',',$answer);
  2356. $tempAnswer = explode(',', $v['answer']);
  2357. $rightAnswerCount=0;
  2358. if(count($tempAnswer)<=count($answerArr)){
  2359. foreach ($tempAnswer as $av) {
  2360. if (false !== strpos($answer, $av)) {
  2361. $rightAnswerCount++;
  2362. }
  2363. }
  2364. }
  2365. $update_data['scoring']=$rightAnswerCount;
  2366. $update_data['is_right']=0; //半对算错
  2367. break;
  2368. }
  2369. }
  2370. }
  2371. if($update_data && $v['paper_id'] && $v['student_id']){
  2372. $transaction = $this->sConn->beginTransaction();
  2373. try {
  2374. $sql=" update `student_paper_topic_rs` set ";
  2375. $updatesql=array();
  2376. foreach ($update_data as $filed=>$value){
  2377. $updatesql[]="`".$filed."` = '".$value."'";
  2378. }
  2379. $sql.=implode(',',$updatesql);
  2380. $sql.=" where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' and `topic_id`='".$topic_id."'";
  2381. $this->sConn->createCommand($sql)->execute();
  2382. //更新总分queryAll
  2383. $TotalScore = $paperScore[$v['paper_id']];
  2384. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$v['paper_id']."' and student_id='".$v['student_id']."' ";
  2385. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  2386. $right_count = 0;
  2387. $partial_right_count = 0;
  2388. $wrong_count = 0;
  2389. $scoring = 0;
  2390. $lost_score = 0;
  2391. foreach ($StudentAllTopic as $value) {
  2392. if ($value['is_right'] == 1) {
  2393. $right_count++;
  2394. } elseif ($value['is_right'] == 2) {
  2395. $partial_right_count++;
  2396. } else {
  2397. $wrong_count++;
  2398. }
  2399. $scoring = bcadd($scoring, $value['scoring'], 1);
  2400. }
  2401. unset($StudentAllTopic);
  2402. $lost_score = bcsub($TotalScore, $scoring, 1);
  2403. $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."'";
  2404. $paperRelattionSql.=" where `paper_id`='".$v['paper_id']."' and `student_id`='".$v['student_id']."'";
  2405. $this->sConn->createCommand($paperRelattionSql)->execute();
  2406. $transaction->commit();
  2407. } catch (Exception $e) {
  2408. //如果操作失败, 数据回滚
  2409. $transaction->rollback();
  2410. $result['status']=0;
  2411. $result['msg']=' 报告更新失败';
  2412. exit(json_encode($result));
  2413. }
  2414. }
  2415. }
  2416. }
  2417. }
  2418. //更新规则
  2419. $tplRules=array();
  2420. if(isset($tplData['new_rules'])){
  2421. $tplRules=$tplData['new_rules'];
  2422. }
  2423. foreach ($paperTopicRelation as $value){
  2424. if($value['topic_id']==$topic_id){
  2425. $tplRules[$value['order']]=array(
  2426. 'topicNo'=>$value['order'],
  2427. 'topic_id'=>$topic_id,
  2428. 'rule_type'=>(int)$rule,
  2429. 'rule_answer'=>Req::post('answer'),
  2430. 'rule_score'=>'', //分数不修改传空,使用默认值
  2431. 'rule_score_half'=>$score_half_m
  2432. );
  2433. }
  2434. }
  2435. if($tplRules){
  2436. $tplData['new_rules']=$tplRules;
  2437. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute();
  2438. }
  2439. $sendParam=array(
  2440. 'school_id'=>$this->schoolId,
  2441. 'exam_group_id'=>$Exam_GroupId
  2442. );
  2443. sendZsystNotic($sendParam);
  2444. $this->sendNoticeToReport($Exam_GroupId);
  2445. $kafkaData=array(
  2446. 'schoolId'=>$this->schoolId,
  2447. 'examGroupId'=>$Exam_GroupId,
  2448. 'generateTime'=>time()*1000
  2449. );
  2450. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  2451. if(Yii::app()->params['handle_log_on_off'])
  2452. {
  2453. writeFileLog(jsonEncode(array(
  2454. "exam_group_id" => $Exam_GroupId,
  2455. "operate_project" => 'zsyas2',
  2456. "school_id" => $this->schoolId,
  2457. "title" => '更新多选题报告',
  2458. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2459. "operate_method" => $this->action,
  2460. "operate_url" => $this->getRoute(),
  2461. "operate_sql" =>'',
  2462. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  2463. "date"=>date('Y-m-d H:i:s')
  2464. )));
  2465. }
  2466. $result['status']=1;
  2467. $result['msg']='报告更新完成';
  2468. exit(json_encode($result));
  2469. }
  2470. /*批量修改多选题规则*/
  2471. public function actionChangeMultiRuleBatch(){
  2472. ini_set('memory_limit', '500M');
  2473. $exam_id = Req::post('exam_id');
  2474. $topic_id = Req::post('topic_id');
  2475. $type = Req::post('type');
  2476. $rule = Req::post('rule');
  2477. $score_m = Req::post('score_m');
  2478. $score_half_m = Req::post('score_half_m');
  2479. $answer = Req::post('answer');
  2480. $result=array(
  2481. 'status'=>0
  2482. );
  2483. if(!$exam_id || !$topic_id || !$type || !$rule) {
  2484. exit(json_encode($result));
  2485. }
  2486. // if(!$score_m){
  2487. // $result['msg']='分数不能为空';
  2488. // exit(json_encode($result));
  2489. // };
  2490. // if(!$score_half_m && $rule!=1){
  2491. // $result['msg']='半对分数不能为空';
  2492. // exit(json_encode($result));
  2493. // };
  2494. // if($score_half_m>$score_m){
  2495. // $result['msg']='半对分数不能大于满分';
  2496. // exit(json_encode($result));
  2497. // };
  2498. if(!in_array($rule,array(1,2,3,4,5))){
  2499. $result['msg']='评分规则错误';
  2500. exit(json_encode($result));
  2501. }
  2502. $topicIdArr=explode('///',$topic_id);
  2503. $topicAnswerArr=explode('///',$answer);
  2504. $topicHalfScoreArr=explode('///',$score_half_m);
  2505. if(!$topicIdArr || !$topicAnswerArr){
  2506. $result['msg']='批量读取试题异常';
  2507. exit(json_encode($result));
  2508. }
  2509. $topicIdAnswer=array();
  2510. $topicIdHalfScore=array();
  2511. foreach ($topicIdArr as $key => $val){
  2512. if(!isset($topicAnswerArr[$key])){
  2513. $result['msg']='批量读取试题答案异常';
  2514. exit(json_encode($result));
  2515. }else{
  2516. $this->UpdateTopicAnswer($val,$topicAnswerArr[$key],11);
  2517. $topicIdAnswer[$val]=$topicAnswerArr[$key];
  2518. $topicIdHalfScore[$val]=$topicHalfScoreArr[$key];
  2519. }
  2520. }
  2521. $ExamModel=new SExam();
  2522. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  2523. if(!$ExamInfo){
  2524. $result['msg']='考试ID错误1';
  2525. exit(json_encode($result));
  2526. }
  2527. $Exam_GroupId=$ExamInfo['exam_group_id'];
  2528. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  2529. $AllExamIds=array();
  2530. $tplData=array();
  2531. if($AllExam){
  2532. foreach($AllExam as $val){
  2533. if($val){
  2534. $AllExamIds[]=$val['exam_id'];
  2535. if(!$tplData){
  2536. $tplData=json_decode($val['tpl_data'],true);
  2537. }
  2538. }
  2539. }
  2540. }
  2541. if(!$AllExamIds){
  2542. $result['msg']='考试ID错误2';
  2543. exit(json_encode($result));
  2544. }
  2545. $AllPaperIds=array();
  2546. $paperScore=array();
  2547. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  2548. if($AllPaper){
  2549. foreach ($AllPaper as $val){
  2550. $AllPaperIds[]=$val['paper_id'];
  2551. $paperScore[$val['paper_id']]=$val['score'];
  2552. }
  2553. }
  2554. if(!$AllPaperIds){
  2555. $result['msg']='考试ID错误3';
  2556. exit(json_encode($result));
  2557. }
  2558. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and type in(2,11)")->queryAll();
  2559. if(!$paperTopicRelation){
  2560. $result['msg']='试卷试题有误';
  2561. exit(json_encode($result));
  2562. }
  2563. $Rs=array();
  2564. $topicScoreArr=array();
  2565. $topicHalfScoreArr=array();
  2566. foreach ($paperTopicRelation as $value){
  2567. if($score_half_m>$value['score']){
  2568. $result['msg']='半对分数不能大于满分';
  2569. exit(json_encode($result));
  2570. }
  2571. $topicScoreArr[$value['topic_id']]=$value['score'];
  2572. }
  2573. foreach ($AllPaperIds as $pid){
  2574. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")");
  2575. if($tempData){
  2576. foreach ($tempData as $v){
  2577. $Rs[]=array(
  2578. 'topic_id' =>$v['topic_id'],
  2579. 'answer' =>$v['answer'],
  2580. 'paper_id' =>$v['paper_id'],
  2581. 'student_id' =>$v['student_id'],
  2582. );
  2583. }
  2584. }
  2585. }
  2586. $updateRightData=array();
  2587. $updateScoreData=array();
  2588. $updateStudentPaperRelation=array();
  2589. if($Rs){
  2590. if(!$answer){
  2591. $result['msg']='答案不能为空';
  2592. exit(json_encode($result));
  2593. }
  2594. foreach ($Rs as $k=> $v){
  2595. if(!isset($topicIdAnswer[$v['topic_id']])){
  2596. continue;
  2597. }
  2598. $answer=$topicIdAnswer[$v['topic_id']];
  2599. if(!$v['answer']){
  2600. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2601. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2602. }else{
  2603. if($v['answer'] == $answer){
  2604. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
  2605. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']];
  2606. }else{
  2607. switch ($rule){
  2608. case 1: //规则A 最严格规则
  2609. $update_data['scoring']=0;
  2610. $update_data['is_right']=0;
  2611. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2612. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2613. break;
  2614. case 2://规则B 半对规则
  2615. //查找错误选择
  2616. $answerArr=explode(',',$answer);
  2617. $tempAnswer = explode(',', $v['answer']);
  2618. $FindWrong=false;
  2619. foreach ($tempAnswer as $av) {
  2620. if(!in_array($av,$answerArr)){
  2621. $FindWrong=true;
  2622. break;
  2623. }
  2624. }
  2625. if($FindWrong){
  2626. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2627. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2628. }else{
  2629. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  2630. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  2631. }
  2632. break;
  2633. case 3://规则C 宽松半对规则
  2634. //查找正确选择
  2635. $answerArr=explode(',',$answer);
  2636. $tempAnswer = explode(',', $v['answer']);
  2637. $IsWrong=true;
  2638. if(count($tempAnswer)<=count($answerArr)){
  2639. foreach ($tempAnswer as $av) {
  2640. if (false !== strpos($answer, $av)) {
  2641. $IsWrong=false;
  2642. break;
  2643. }
  2644. }
  2645. }
  2646. //错误答案情况
  2647. if($IsWrong){
  2648. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2649. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2650. }else{
  2651. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  2652. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  2653. }
  2654. break;
  2655. case 4:
  2656. $answerArr=explode(',',$answer);
  2657. $tempAnswer = explode(',', $v['answer']);
  2658. $IsWrong=false;
  2659. if(count($tempAnswer)<=count($answerArr)){
  2660. foreach ($tempAnswer as $av) {
  2661. if(!in_array($av,$answerArr)){
  2662. $IsWrong=true;
  2663. break;
  2664. }
  2665. }
  2666. }else{
  2667. $IsWrong=true;
  2668. }
  2669. //错误答案情况
  2670. if($IsWrong){
  2671. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2672. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2673. }else{
  2674. //没有错误答案,且不全对,几个答案几分
  2675. $score_half_m=count($tempAnswer);
  2676. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2677. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m;
  2678. }
  2679. break;
  2680. case 5:
  2681. $answerArr=explode(',',$answer);
  2682. $tempAnswer = explode(',', $v['answer']);
  2683. $rightAnswerCount=0;
  2684. if(count($tempAnswer)<=count($answerArr)){
  2685. foreach ($tempAnswer as $av) {
  2686. if (false !== strpos($answer, $av)) {
  2687. $rightAnswerCount++;
  2688. }
  2689. }
  2690. }
  2691. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  2692. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount;
  2693. break;
  2694. }
  2695. }
  2696. }
  2697. //更新总分queryAll
  2698. $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
  2699. }
  2700. }
  2701. $updateStudentPaperRelationSql=array();
  2702. if($updateRightData){
  2703. $sqlIsRight=array();
  2704. $sqlScore=array();
  2705. foreach ($updateRightData as $paperId=>$val){
  2706. foreach ($val as $topicId=>$v){
  2707. $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
  2708. foreach ($v as $studentId=>$isRight){
  2709. $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
  2710. }
  2711. $sql.=" Else `is_right`";
  2712. $sql.=" End ";
  2713. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  2714. $sqlIsRight[]=$sql;
  2715. }
  2716. }
  2717. foreach ($updateScoreData as $paperId=>$val){
  2718. foreach ($val as $topicId=>$v){
  2719. $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
  2720. foreach ($v as $studentId=>$score){
  2721. $sql.=" WHEN ".$studentId." THEN '".$score."' ";
  2722. }
  2723. $sql.=" Else `scoring`";
  2724. $sql.=" End ";
  2725. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  2726. $sqlScore[]=$sql;
  2727. }
  2728. }
  2729. $transaction = $this->sConn->beginTransaction();
  2730. try {
  2731. if($sqlIsRight){
  2732. foreach ($sqlIsRight as $sql){
  2733. $this->sConn->createCommand($sql)->execute();
  2734. }
  2735. }
  2736. if($sqlScore){
  2737. foreach ($sqlScore as $sql){
  2738. $this->sConn->createCommand($sql)->execute();
  2739. }
  2740. }
  2741. $transaction->commit();
  2742. } catch (Exception $e) {
  2743. //如果操作失败, 数据回滚
  2744. $transaction->rollback();
  2745. $result['status']=0;
  2746. $result['msg']=' 报告更新失败';
  2747. exit(json_encode($result));
  2748. }
  2749. if($updateStudentPaperRelation){
  2750. foreach ($updateStudentPaperRelation as $studentId =>$paperId){
  2751. $TotalScore = $paperScore[$paperId];
  2752. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
  2753. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  2754. $right_count = 0;
  2755. $partial_right_count = 0;
  2756. $wrong_count = 0;
  2757. $scoring = 0;
  2758. $lost_score = 0;
  2759. foreach ($StudentAllTopic as $value) {
  2760. if ($value['is_right'] == 1) {
  2761. $right_count++;
  2762. } elseif ($value['is_right'] == 2) {
  2763. $partial_right_count++;
  2764. } else {
  2765. $wrong_count++;
  2766. }
  2767. $scoring = bcadd($scoring, $value['scoring'], 1);
  2768. }
  2769. unset($StudentAllTopic);
  2770. $lost_score = bcsub($TotalScore, $scoring, 1);
  2771. $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."'";
  2772. $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
  2773. $updateStudentPaperRelationSql[]=$paperRelattionSql;
  2774. }
  2775. }
  2776. $transaction = $this->sConn->beginTransaction();
  2777. try {
  2778. if($updateStudentPaperRelationSql){
  2779. foreach ($updateStudentPaperRelationSql as $sql){
  2780. $this->sConn->createCommand($sql)->execute();
  2781. }
  2782. }
  2783. $sendParam=array(
  2784. 'school_id'=>$this->schoolId,
  2785. 'exam_group_id'=>$Exam_GroupId
  2786. );
  2787. $transaction->commit();
  2788. sendZsystNotic($sendParam);
  2789. $kafkaData=array(
  2790. 'schoolId'=>$this->schoolId,
  2791. 'examGroupId'=>$Exam_GroupId,
  2792. 'generateTime'=>time()*1000
  2793. );
  2794. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  2795. } catch (Exception $e) {
  2796. //如果操作失败, 数据回滚
  2797. $transaction->rollback();
  2798. $result['status']=0;
  2799. $result['msg']=' 报告更新失败';
  2800. exit(json_encode($result));
  2801. }
  2802. }
  2803. //记录新判分规则
  2804. $tplRules=array();
  2805. if(isset($tplData['new_rules'])){
  2806. $tplRules=$tplData['new_rules'];
  2807. }
  2808. foreach ($paperTopicRelation as $value){
  2809. if(in_array($value['topic_id'],$topicIdArr)){
  2810. if(isset($tplRules[$value['order']])){
  2811. $tplRules[$value['order']]['rule_type']=(int)$rule;
  2812. }else{
  2813. $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:'';
  2814. $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0';
  2815. $tplRules[$value['order']]=array(
  2816. 'topicNo'=>$value['order'],
  2817. 'topic_id'=>$value['topic_id'],
  2818. 'rule_type'=>(int)$rule,
  2819. 'rule_answer'=>$rule_answer,
  2820. 'rule_score'=>'',
  2821. 'rule_score_half'=>$rule_half_score
  2822. );
  2823. }
  2824. }
  2825. }
  2826. if($tplRules){
  2827. $tplData['new_rules']=$tplRules;
  2828. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute();
  2829. }
  2830. $this->sendNoticeToReport($Exam_GroupId);
  2831. if(Yii::app()->params['handle_log_on_off'])
  2832. {
  2833. writeFileLog(jsonEncode(array(
  2834. "exam_group_id" => $Exam_GroupId,
  2835. "operate_project" => 'zsyas2',
  2836. "school_id" => $this->schoolId,
  2837. "title" => '批量更新多选题报告',
  2838. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2839. "operate_method" => $this->action,
  2840. "operate_url" => $this->getRoute(),
  2841. "operate_sql" =>'',
  2842. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  2843. "date"=>date('Y-m-d H:i:s')
  2844. )));
  2845. }
  2846. //发送学生端消息
  2847. $sendJsonArr=array(
  2848. 'school_id'=>$this->schoolId,
  2849. 'send_type'=>'zsyas',
  2850. 'update_type'=>0,
  2851. 'exam_group_id'=>$Exam_GroupId,
  2852. );
  2853. sendStudentCacheQueue($sendJsonArr);
  2854. $result['status']=1;
  2855. $result['msg']='报告更新完成';
  2856. exit(json_encode($result));
  2857. }
  2858. //更新文理综考试试题科目
  2859. public function actionEditTopicSubject(){
  2860. $exam_id = Req::post('exam_id');
  2861. $topic_id = Req::post('topic_id');
  2862. $subject = Req::post('subject');
  2863. $old_subject = Req::post('old_subject');
  2864. $paper_id = Req::post('paper_id');
  2865. $result['status']=0;
  2866. if($subject==$old_subject){
  2867. $result['msg']='新科目与原科目相同';
  2868. exit(json_encode($result));
  2869. }
  2870. if(!isset(Yii::app()->params['subjectId'][$subject])){
  2871. $result['msg']='科目参数不正确';
  2872. exit(json_encode($result));
  2873. }
  2874. $ExamModel=new SExam();
  2875. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  2876. if(!$ExamInfo){
  2877. $result['msg']='考试ID错误1';
  2878. exit(json_encode($result));
  2879. }
  2880. $Exam_GroupId=$ExamInfo['exam_group_id'];
  2881. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  2882. //查询试题序号
  2883. $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id', array(':paper_id' => $paper_id, ':topic_id' => $topic_id));
  2884. $tpl_data=json_decode($ExamInfo['tpl_data'],true);
  2885. if($tpl_data && isset($tpl_data['new_items'])){
  2886. foreach ($tpl_data['new_items'] as $key => $val){
  2887. if($paper_student_data->order==$val['id']){
  2888. $tpl_data['new_items'][$key]['subject']=$subject;
  2889. }
  2890. }
  2891. }
  2892. Exam::model()->updateAll(array('tpl_data'=>json_encode($tpl_data)),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  2893. if(Yii::app()->params['handle_log_on_off'])
  2894. {
  2895. writeFileLog(jsonEncode(array(
  2896. "exam_group_id" => $Exam_GroupId,
  2897. "operate_project" => 'zsyas2',
  2898. "school_id" => $this->schoolId,
  2899. "title" => '更新科目',
  2900. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2901. "operate_method" => $this->action,
  2902. "operate_url" => $this->getRoute(),
  2903. "operate_sql" =>'',
  2904. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  2905. "date"=>date('Y-m-d H:i:s')
  2906. )));
  2907. }
  2908. $result['status']=1;
  2909. $result['msg']='更新科目完成';
  2910. exit(json_encode($result));
  2911. }
  2912. //更新报告后发送通知
  2913. private function sendNoticeToReport($examGroupId){
  2914. $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/external/exam/group/clear-cache/'.$examGroupId;
  2915. $username = $this->schoolInfo->school_id;
  2916. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  2917. $curl = @curl_init();
  2918. $response=null;
  2919. if ($curl) {
  2920. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  2921. curl_setopt($curl, CURLOPT_USERPWD, $username .':'. $password);
  2922. curl_setopt($curl, CURLOPT_HEADER, 0);
  2923. curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
  2924. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  2925. curl_setopt($curl, CURLOPT_URL, $url);
  2926. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
  2927. curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  2928. 'Content-Type: application/json',
  2929. ));
  2930. $response = curl_exec($curl);
  2931. curl_close($curl);
  2932. }
  2933. return $response;
  2934. }
  2935. //批量更新选择题分数
  2936. public function actionUpdateScoreBatch(){
  2937. $scores = Req::post('scores');
  2938. $paper_id = Req::post('paper_id');
  2939. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id and type=1','params'=>array(':paper_id'=>$paper_id)));
  2940. $oldTopicScores=0; //选择题原总分
  2941. $newTopicScores=0; //选题题修改后总分
  2942. $update_score=array(); //需要修改分数的topic
  2943. $update_score_order=array(); //修改分数的序号
  2944. if($paper_topic_data)
  2945. {
  2946. if(count($paper_topic_data)!=count($scores)){
  2947. echo json_encode(array('status'=>0,'msg'=>'提交的选择题数量不正确'));exit;
  2948. }
  2949. foreach($paper_topic_data as $v)
  2950. {
  2951. $oldTopicScores+=$v['score'];
  2952. if($v['score']!=$scores[$v->order]){
  2953. $update_score[$v->topic_id] = $scores[$v->order];
  2954. $update_score_order[$v->order] = $scores[$v->order];
  2955. $score_diff[$v->topic_id]=$scores[$v->order]-$v['score'];
  2956. }
  2957. }
  2958. }
  2959. if(!$update_score){
  2960. echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit;
  2961. }
  2962. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  2963. $exam_ids = array();
  2964. $paper_ids = array();
  2965. if($paper_data)
  2966. {
  2967. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  2968. if($exam_data)
  2969. {
  2970. $tpl_data = json_decode($exam_data->tpl_data,1);
  2971. $newTopicScores=array_sum($scores);
  2972. if(isset($tpl_data['items'])){
  2973. $objectiveTplData=array(
  2974. 'total'=>count($scores),
  2975. 'totalScore'=>$newTopicScores,
  2976. 'perScores'=>array_values($scores)
  2977. );
  2978. $tpl_data['items'][1]=$objectiveTplData;
  2979. }
  2980. //修改new_items
  2981. if(isset($tpl_data['new_items'])){
  2982. foreach ($tpl_data['new_items'] as $key =>$val){
  2983. if($val['topic_type']==1 && isset($update_score_order[$val['id']])){
  2984. $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']];
  2985. }
  2986. }
  2987. }else{
  2988. //没有new_items,补齐
  2989. $tpl_data= $this->createNewItems($tpl_data);
  2990. }
  2991. $exam_group = ExamGroup::model()->find('exam_group_id=:exam_id',array(':exam_id'=>$exam_data->exam_group_id));
  2992. $paper_score=$this->sumTplDataScores($tpl_data,$exam_group->is_third);
  2993. $tpl_data['scores']=$paper_score;
  2994. $tpl_data['total_score']=$paper_score;
  2995. $json_tpl_data = jsonEncode($tpl_data);
  2996. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  2997. if($exam_group_data)
  2998. {
  2999. foreach($exam_group_data as $v)
  3000. {
  3001. $exam_ids[$v->exam_id] = $v->exam_id;
  3002. }
  3003. if($exam_ids)
  3004. {
  3005. $criteria = new CDbCriteria();
  3006. $criteria->addInCondition('exam_id',$exam_ids);
  3007. $paper_data = SPaper::model()->findAll($criteria);
  3008. if($paper_data)
  3009. {
  3010. foreach($paper_data as $v)
  3011. {
  3012. $paper_ids[$v->paper_id] = $v->paper_id;
  3013. }
  3014. $trans = $this->sConn->beginTransaction();
  3015. try{
  3016. foreach ($update_score as $topic_id => $score){
  3017. if(!$score){
  3018. continue;
  3019. }
  3020. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  3021. $this->sConn->createCommand($sql)->execute();
  3022. //修改学生得分
  3023. $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 ";
  3024. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  3025. if($students){
  3026. $studentIds=array();
  3027. foreach ($students as $v){
  3028. $studentIds[]=$v['student_id'];
  3029. }
  3030. $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 ";
  3031. $this->sConn->createCommand($sql)->execute();
  3032. $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).") ";
  3033. $this->sConn->createCommand($sql)->execute();
  3034. }
  3035. }
  3036. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
  3037. $this->sConn->createCommand($sql)->execute();
  3038. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  3039. $this->sConn->createCommand($sql)->execute();
  3040. $trans->commit();
  3041. }
  3042. catch(Exception $e){
  3043. $trans->rollBack();
  3044. echo json_encode(array('status'=>0));exit;
  3045. }
  3046. $sendParam=array(
  3047. 'school_id'=>$this->schoolId,
  3048. 'exam_group_id'=>$exam_data->exam_group_id
  3049. );
  3050. sendZsystNotic($sendParam);
  3051. $kafkaData=array(
  3052. 'schoolId'=>$this->schoolId,
  3053. 'examGroupId'=>$exam_data->exam_group_id,
  3054. 'generateTime'=>time()*1000
  3055. );
  3056. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  3057. $this->sendNoticeToReport($exam_data->exam_group_id);
  3058. //发送学生端消息
  3059. $sendJsonArr=array(
  3060. 'school_id'=>$this->schoolId,
  3061. 'send_type'=>'zsyas',
  3062. 'update_type'=>0,
  3063. 'exam_group_id'=>$exam_data->exam_group_id,
  3064. );
  3065. sendStudentCacheQueue($sendJsonArr);
  3066. if(Yii::app()->params['handle_log_on_off'])
  3067. {
  3068. writeFileLog(jsonEncode(array(
  3069. "exam_group_id" => $exam_data->exam_group_id,
  3070. "operate_project" => 'zsyas2',
  3071. "school_id" => $this->schoolId,
  3072. "title" => '修改分数',
  3073. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3074. "operate_method" => $this->action,
  3075. "operate_url" => $this->getRoute(),
  3076. "operate_sql" =>'',
  3077. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3078. "date"=>date('Y-m-d H:i:s')
  3079. )));
  3080. }
  3081. echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
  3082. }
  3083. }
  3084. }
  3085. }
  3086. }
  3087. }
  3088. //批量更新单选试题答案
  3089. public function actionUpdateAnswerBatch(){
  3090. $paper_id = Req::post('paper_id');
  3091. $updateAnswers = Req::post('update_answers');
  3092. $result=array();
  3093. $result['status']=0;
  3094. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  3095. if(!$paper_data){
  3096. $result['msg']="未找到试卷";
  3097. exit(json_encode($result));
  3098. }
  3099. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  3100. $examGroupData=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  3101. $tplData=json_decode($exam_data->tpl_data,true);
  3102. $queries = array();
  3103. foreach($updateAnswers as $val){
  3104. $topic_id=$val['topicId'];
  3105. $type=1;
  3106. $answer=$val['newAnswer'];
  3107. if($paper_data) {
  3108. $paper_student_data = SPaperTopicRelation::model()->find('paper_id=:paper_id and topic_id=:topic_id ', array(':paper_id' => $paper_id, ':topic_id' => $topic_id ));
  3109. if (!$paper_student_data) {
  3110. $result['msg']="未找到试题";
  3111. exit(json_encode($result));
  3112. }
  3113. $paperIds = array();
  3114. if($exam_data){
  3115. $tplData['update_answer'][$paper_student_data['order']]=array(
  3116. 'order'=>$paper_student_data['order'],
  3117. 'topic_id'=>$topic_id,
  3118. 'update_answer'=>$answer
  3119. );
  3120. $PaperSql="SELECT p.paper_id FROM paper p JOIN exam e ON e.exam_id = p.exam_id WHERE e.exam_group_id = '". $exam_data->exam_group_id ."' ";
  3121. $papers=$this->sConn->createCommand($PaperSql)->queryAll();
  3122. if ($papers) {
  3123. foreach ($papers as $k => $v) {
  3124. $paperIds[] = $v['paper_id'];
  3125. }
  3126. $ptrSql="SELECT ptr.score FROM paper_topic_relation ptr WHERE ptr.paper_id = '". $paperIds[0] ."' AND topic_id = '". $topic_id ."'";
  3127. $ptr=$this->sConn->createCommand($ptrSql)->queryRow();
  3128. if ($ptr) {
  3129. $score = $ptr['score'];
  3130. $studentIds_Right = array();
  3131. $studentIds_Wrong = array();
  3132. //更新选错了,但标为正确答案的
  3133. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND `type` = '1' AND answer != '{$answer}' AND is_right = '1'";
  3134. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  3135. if ($sptr) {
  3136. foreach ($sptr as $k => $v) {
  3137. $studentIds_Wrong[] = $v['student_id'];
  3138. }
  3139. $queries[] = "UPDATE student_paper_relation SET right_count = if(right_count>0,right_count - 1,0), wrong_count = wrong_count + 1, scoring = scoring - ". $score .", lost_score = lost_score + ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .");";
  3140. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 0, scoring = 0 WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Wrong) .") AND topic_id = '". $topic_id ."';";
  3141. }
  3142. //更新原本选对了,但标为错误答案的
  3143. $sptrSql="SELECT sptr.* FROM student_paper_topic_rs sptr WHERE paper_id IN (". implode(',', $paperIds) .") AND topic_id = '". $topic_id ."' AND answer = '{$answer}' AND is_right = '0'";
  3144. $sptr=$this->sConn->createCommand($sptrSql)->queryAll();
  3145. if ($sptr) {
  3146. foreach ($sptr as $k => $v) {
  3147. $studentIds_Right[] = $v['student_id'];
  3148. }
  3149. $queries[] = "UPDATE student_paper_relation SET right_count = right_count + 1, wrong_count = if(wrong_count>0,wrong_count - 1,0), scoring = scoring + ". $score .", lost_score = lost_score - ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .");";
  3150. $queries[] = "UPDATE student_paper_topic_rs SET is_right = 1, scoring = ". $score ." WHERE paper_id IN (". implode(',', $paperIds) .") AND student_id IN (". implode(',', $studentIds_Right) .") AND topic_id = '". $topic_id ."';";
  3151. }
  3152. }
  3153. }
  3154. }
  3155. $this->UpdateTopicAnswer($topic_id,$answer,1);
  3156. $this->sendNoticeToReport($exam_data->exam_group_id);
  3157. }
  3158. }
  3159. if($tplData['update_answer']){
  3160. $queries[]="update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_data->exam_group_id."'";
  3161. }
  3162. if($queries){
  3163. $transaction = $this->sConn->beginTransaction();
  3164. try {
  3165. foreach ($queries as $query) {
  3166. $this->sConn->createCommand($query)->execute();
  3167. }
  3168. //更新试题答案
  3169. $transaction->commit();
  3170. $sendParam=array(
  3171. 'school_id'=>$this->schoolId,
  3172. 'exam_group_id'=>$exam_data->exam_group_id
  3173. );
  3174. sendZsystNotic($sendParam);
  3175. $kafkaData=array(
  3176. 'schoolId'=>$this->schoolId,
  3177. 'examGroupId'=>$exam_data->exam_group_id,
  3178. 'generateTime'=>time()*1000
  3179. );
  3180. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  3181. if(isset($examGroupData) && $examGroupData->homework==1){
  3182. //发送学生端消息
  3183. $sendJsonArr=array(
  3184. 'school_id'=>$this->schoolId,
  3185. 'send_type'=>'zsyas',
  3186. 'update_type'=>0,
  3187. 'exam_group_id'=>$exam_data->exam_group_id,
  3188. );
  3189. sendStudentCacheQueue($sendJsonArr);
  3190. }
  3191. if(Yii::app()->params['handle_log_on_off'])
  3192. {
  3193. writeFileLog(jsonEncode(array(
  3194. "exam_group_id" => $exam_data->exam_group_id,
  3195. "operate_project" => 'zsyas2',
  3196. "school_id" => $this->schoolId,
  3197. "title" => '批量更新单选试题答案',
  3198. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3199. "operate_method" => $this->action,
  3200. "operate_url" => $this->getRoute(),
  3201. "operate_sql" =>'',
  3202. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3203. "date"=>date('Y-m-d H:i:s')
  3204. )));
  3205. }
  3206. $result['status']=1;
  3207. exit(json_encode($result));
  3208. } catch (Exception $e) {
  3209. $transaction->rollback();
  3210. $result['msg']="更新失败";
  3211. exit(json_encode($result));
  3212. }
  3213. }else{
  3214. $result['msg']="没有更新试题";
  3215. exit(json_encode($result));
  3216. }
  3217. }
  3218. /*批量修改多选题答案(各题答案不同,分数,半对分不同)*/
  3219. public function actionUpdateMultiAnswerBatch(){
  3220. ini_set('memory_limit', '500M');
  3221. $exam_id = Req::post('exam_id');
  3222. $topic_id = Req::post('topic_id');
  3223. $rule = Req::post('rule');
  3224. $score_half_m = Req::post('score_half_m');
  3225. $update_answers = Req::post('update_answers');
  3226. $change_obj = Req::post('change_obj');
  3227. $result=array(
  3228. 'status'=>0
  3229. );
  3230. if(!$exam_id) {
  3231. exit(json_encode($result));
  3232. }
  3233. $topicIdHalfScore=array();
  3234. $topicIdRule=array();
  3235. $topicScoreArr=array();
  3236. foreach ($update_answers as $val){
  3237. $topicIdArr[]=$val['topicId'];
  3238. $topicIdAnswer[$val['topicId']]=isset($val['newAnswer'])?$val['newAnswer']:$val['topicAnswer'];
  3239. if(isset($val['topicHalfScore'])){
  3240. $topicIdHalfScore[$val['topicId']]=$val['topicHalfScore'];
  3241. }
  3242. if(isset($val['topicScore'])){
  3243. $topicScoreArr[$val['topicId']]=$val['topicScore'];
  3244. }
  3245. if(isset($val['topicRule'])){
  3246. $topicIdRule[$val['topicId']]=$val['topicRule'];
  3247. }
  3248. }
  3249. if(!$topicIdHalfScore){
  3250. // if(!$score_half_m){
  3251. // $result['msg']='批量读取试题半对分异常';
  3252. // exit(json_encode($result));
  3253. // }
  3254. $topicHalfScoreArr=explode('///',$score_half_m);
  3255. foreach ($topicIdArr as $key => $val){
  3256. if(!isset($topicIdAnswer[$val])){
  3257. $result['msg']='批量读取试题答案异常';
  3258. exit(json_encode($result));
  3259. }else{
  3260. //$this->UpdateTopicAnswer($val,$topicIdAnswer[$val],11);
  3261. $topicIdHalfScore[$val]=$topicHalfScoreArr[$key];
  3262. }
  3263. }
  3264. }
  3265. if($topicIdAnswer){
  3266. foreach ($topicIdAnswer as $key =>$val){
  3267. $this->UpdateTopicAnswer($key,$val,11);
  3268. }
  3269. }
  3270. $ExamModel=new SExam();
  3271. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  3272. if(!$ExamInfo){
  3273. $result['msg']='考试ID错误1';
  3274. exit(json_encode($result));
  3275. }
  3276. $examGroupId=$ExamInfo['exam_group_id'];
  3277. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  3278. $AllExamIds=array();
  3279. $tplData=array();
  3280. if($AllExam){
  3281. foreach($AllExam as $val){
  3282. if($val){
  3283. $AllExamIds[]=$val['exam_id'];
  3284. if(!$tplData){
  3285. $tplData=json_decode($val['tpl_data'],true);
  3286. }
  3287. }
  3288. }
  3289. }
  3290. if(!$AllExamIds){
  3291. $result['msg']='考试ID错误2';
  3292. exit(json_encode($result));
  3293. }
  3294. $AllPaperIds=array();
  3295. $paperScore=array();
  3296. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  3297. if($AllPaper){
  3298. foreach ($AllPaper as $val){
  3299. $AllPaperIds[]=$val['paper_id'];
  3300. $paperScore[$val['paper_id']]=$val['score'];
  3301. }
  3302. }
  3303. if(!$AllPaperIds){
  3304. $result['msg']='考试ID错误3';
  3305. exit(json_encode($result));
  3306. }
  3307. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' ")->queryAll();
  3308. if(!$paperTopicRelation){
  3309. $result['msg']='试卷试题有误';
  3310. exit(json_encode($result));
  3311. }
  3312. if(!$topicScoreArr){
  3313. foreach ($paperTopicRelation as $value){
  3314. if(isset($topicIdHalfScore[$value['topic_id']]) && $topicIdHalfScore[$value['topic_id']]>$value['score']){
  3315. $result['msg']='半对分数不能大于满分';
  3316. exit(json_encode($result));
  3317. }
  3318. $topicScoreArr[$value['topic_id']]=$value['score'];
  3319. }
  3320. }
  3321. $Rs=array();
  3322. foreach ($AllPaperIds as $pid){
  3323. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")");
  3324. if($tempData){
  3325. foreach ($tempData as $v){
  3326. $Rs[]=array(
  3327. 'topic_id' =>$v['topic_id'],
  3328. 'answer' =>$v['answer'],
  3329. 'paper_id' =>$v['paper_id'],
  3330. 'student_id' =>$v['student_id'],
  3331. );
  3332. }
  3333. }
  3334. }
  3335. $updateRightData=array();
  3336. $updateScoreData=array();
  3337. $updateStudentPaperRelation=array();
  3338. if($Rs){
  3339. if(!$topicIdAnswer){
  3340. $result['msg']='答案不能为空';
  3341. exit(json_encode($result));
  3342. }
  3343. foreach ($Rs as $k=> $v){
  3344. if(!isset($topicIdAnswer[$v['topic_id']])){
  3345. continue;
  3346. }
  3347. $answer=$topicIdAnswer[$v['topic_id']];
  3348. if(!$v['answer']){
  3349. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3350. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3351. }else{
  3352. if($v['answer'] == $answer){
  3353. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
  3354. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']];
  3355. }else{
  3356. $nowRule=$rule;
  3357. if($topicIdRule){
  3358. $nowRule=$topicIdRule[$v['topic_id']];
  3359. }
  3360. switch ($nowRule){
  3361. case 1: //规则A 最严格规则
  3362. $update_data['scoring']=0;
  3363. $update_data['is_right']=0;
  3364. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3365. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3366. break;
  3367. case 2://规则B 半对规则
  3368. //查找错误选择
  3369. $answerArr=explode(',',$answer);
  3370. $tempAnswer = explode(',', $v['answer']);
  3371. $FindWrong=false;
  3372. foreach ($tempAnswer as $av) {
  3373. if(!in_array($av,$answerArr)){
  3374. $FindWrong=true;
  3375. break;
  3376. }
  3377. }
  3378. if($FindWrong){
  3379. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3380. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3381. }else{
  3382. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  3383. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  3384. }
  3385. break;
  3386. case 3://规则C 宽松半对规则
  3387. //查找正确选择
  3388. $answerArr=explode(',',$answer);
  3389. $tempAnswer = explode(',', $v['answer']);
  3390. $IsWrong=true;
  3391. if(count($tempAnswer)<=count($answerArr)){
  3392. foreach ($tempAnswer as $av) {
  3393. if (false !== strpos($answer, $av)) {
  3394. $IsWrong=false;
  3395. break;
  3396. }
  3397. }
  3398. }
  3399. //错误答案情况
  3400. if($IsWrong){
  3401. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3402. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3403. }else{
  3404. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  3405. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  3406. }
  3407. break;
  3408. case 4:
  3409. $answerArr=explode(',',$answer);
  3410. $tempAnswer = explode(',', $v['answer']);
  3411. $IsWrong=false;
  3412. if(count($tempAnswer)<=count($answerArr)){
  3413. foreach ($tempAnswer as $av) {
  3414. if(!in_array($av,$answerArr)){
  3415. $IsWrong=true;
  3416. break;
  3417. }
  3418. }
  3419. }else{
  3420. $IsWrong=true;
  3421. }
  3422. //错误答案情况
  3423. if($IsWrong){
  3424. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3425. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3426. }else{
  3427. //没有错误答案,且不全对,几个答案几分
  3428. $score_half_m=count($tempAnswer);
  3429. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m;
  3430. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3431. }
  3432. break;
  3433. case 5:
  3434. $answerArr=explode(',',$answer);
  3435. $tempAnswer = explode(',', $v['answer']);
  3436. $rightAnswerCount=0;
  3437. if(count($tempAnswer)<=count($answerArr)){
  3438. foreach ($tempAnswer as $av) {
  3439. if (false !== strpos($answer, $av)) {
  3440. $rightAnswerCount++;
  3441. }
  3442. }
  3443. }
  3444. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  3445. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount;
  3446. break;
  3447. }
  3448. }
  3449. }
  3450. //更新总分queryAll
  3451. $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
  3452. }
  3453. }
  3454. $updateStudentPaperRelationSql=array();
  3455. if($updateRightData){
  3456. $sqlIsRight=array();
  3457. $sqlScore=array();
  3458. foreach ($updateRightData as $paperId=>$val){
  3459. foreach ($val as $topicId=>$v){
  3460. $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
  3461. foreach ($v as $studentId=>$isRight){
  3462. $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
  3463. }
  3464. $sql.=" Else `is_right`";
  3465. $sql.=" End ";
  3466. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  3467. $sqlIsRight[]=$sql;
  3468. }
  3469. }
  3470. foreach ($updateScoreData as $paperId=>$val){
  3471. foreach ($val as $topicId=>$v){
  3472. $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
  3473. foreach ($v as $studentId=>$score){
  3474. $sql.=" WHEN ".$studentId." THEN '".$score."' ";
  3475. }
  3476. $sql.=" Else `scoring`";
  3477. $sql.=" End ";
  3478. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  3479. $sqlScore[]=$sql;
  3480. }
  3481. }
  3482. $transaction = $this->sConn->beginTransaction();
  3483. try {
  3484. if($sqlIsRight){
  3485. foreach ($sqlIsRight as $sql){
  3486. $this->sConn->createCommand($sql)->execute();
  3487. }
  3488. }
  3489. if($sqlScore){
  3490. foreach ($sqlScore as $sql){
  3491. $this->sConn->createCommand($sql)->execute();
  3492. }
  3493. }
  3494. $transaction->commit();
  3495. } catch (Exception $e) {
  3496. //如果操作失败, 数据回滚
  3497. $transaction->rollback();
  3498. $result['status']=0;
  3499. $result['msg']=' 报告更新失败';
  3500. exit(json_encode($result));
  3501. }
  3502. if($updateStudentPaperRelation){
  3503. foreach ($updateStudentPaperRelation as $studentId =>$paperId){
  3504. $TotalScore = $paperScore[$paperId];
  3505. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
  3506. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  3507. $right_count = 0;
  3508. $partial_right_count = 0;
  3509. $wrong_count = 0;
  3510. $scoring = 0;
  3511. $lost_score = 0;
  3512. foreach ($StudentAllTopic as $value) {
  3513. if ($value['is_right'] == 1) {
  3514. $right_count++;
  3515. } elseif ($value['is_right'] == 2) {
  3516. $partial_right_count++;
  3517. } else {
  3518. $wrong_count++;
  3519. }
  3520. $scoring = bcadd($scoring, $value['scoring'], 1);
  3521. }
  3522. unset($StudentAllTopic);
  3523. $lost_score = bcsub($TotalScore, $scoring, 1);
  3524. $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."'";
  3525. $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
  3526. $updateStudentPaperRelationSql[]=$paperRelattionSql;
  3527. }
  3528. }
  3529. $transaction = $this->sConn->beginTransaction();
  3530. try {
  3531. if($updateStudentPaperRelationSql){
  3532. foreach ($updateStudentPaperRelationSql as $sql){
  3533. $this->sConn->createCommand($sql)->execute();
  3534. }
  3535. }
  3536. $sendParam=array(
  3537. 'school_id'=>$this->schoolId,
  3538. 'exam_group_id'=>$examGroupId
  3539. );
  3540. $transaction->commit();
  3541. sendZsystNotic($sendParam);
  3542. $kafkaData=array(
  3543. 'schoolId'=>$this->schoolId,
  3544. 'examGroupId'=>$examGroupId,
  3545. 'generateTime'=>time()*1000
  3546. );
  3547. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  3548. } catch (Exception $e) {
  3549. //如果操作失败, 数据回滚
  3550. $transaction->rollback();
  3551. $result['status']=0;
  3552. $result['msg']=' 报告更新失败';
  3553. exit(json_encode($result));
  3554. }
  3555. }
  3556. $scores=array_values($topicScoreArr);
  3557. $newTopicScores=array_sum($scores);
  3558. //记录新判分规则
  3559. $tplRules=array();
  3560. if(isset($tplData['new_rules'])){
  3561. $tplRules=$tplData['new_rules'];
  3562. }
  3563. $oldTopicScores=0;
  3564. $type=0;
  3565. $updatePaperScoreSql=array();
  3566. foreach ($paperTopicRelation as $value){
  3567. if(in_array($value['topic_id'],$topicIdArr)){
  3568. $oldTopicScores+=$value['score'];
  3569. if(!$type){
  3570. $type=$value['type'];
  3571. }
  3572. $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:'';
  3573. $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0';
  3574. $rule_score=isset($topicScoreArr[$value['topic_id']])?$topicScoreArr[$value['topic_id']]:'0';
  3575. //修改new_items
  3576. if($topicScoreArr){
  3577. if(isset($tplData['new_items'])){
  3578. foreach ($tplData['new_items'] as $key =>$val){
  3579. if($value['order']==$val['id']){
  3580. $tplData['new_items'][$key]['score']=(float)$rule_score;
  3581. }
  3582. }
  3583. }
  3584. $updatePaperScoreSql[]='update `paper_topic_relation` set `score` = '.$rule_score.' where paper_id in ('.implode(',',$AllPaperIds).') and `topic_id` ='.$value['topic_id'];
  3585. }
  3586. if(isset($rule)){
  3587. $newRule= $rule;
  3588. }elseif(isset($topicIdRule[$value['topic_id']])){
  3589. $newRule= $topicIdRule[$value['topic_id']];
  3590. }
  3591. if(!isset($tplRules[$value['order']])){
  3592. $tplRules[$value['order']]=array(
  3593. 'topicNo'=>$value['order'],
  3594. 'topic_id'=>$value['topic_id'],
  3595. 'rule_type'=>(int)$newRule,
  3596. 'rule_answer'=>$rule_answer,
  3597. 'rule_score'=>$rule_score,
  3598. 'rule_score_half'=>$rule_half_score
  3599. );
  3600. }else{
  3601. $tplRules[$value['order']]['topic_id']=$value['topic_id'];
  3602. if($newRule){
  3603. $tplRules[$value['order']]['rule_type']=(int)$newRule;
  3604. }
  3605. if($rule_answer){
  3606. $tplRules[$value['order']]['rule_answer']=$rule_answer;
  3607. }
  3608. if($rule_score){
  3609. $tplRules[$value['order']]['rule_score']=$rule_score;
  3610. }
  3611. if($rule_half_score){
  3612. $tplRules[$value['order']]['rule_score_half']=$rule_half_score;
  3613. }else{
  3614. $tplRules[$value['order']]['rule_score_half']=0;
  3615. }
  3616. }
  3617. }
  3618. }
  3619. if($topicScoreArr && $change_obj=='score' ){
  3620. if(isset($tplData['items'])){
  3621. $objectiveTplData=array(
  3622. 'total'=>count($scores),
  3623. 'totalScore'=>$newTopicScores,
  3624. 'perScores'=>array_values($scores)
  3625. );
  3626. $tplData['items'][$type]=$objectiveTplData;
  3627. }
  3628. $paper_score=$tplData['scores']=$tplData['total_score']=$tplData['scores']-$oldTopicScores+$newTopicScores;
  3629. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$AllPaperIds).')';
  3630. $this->sConn->createCommand($sql)->execute();
  3631. }
  3632. $tplData['new_rules']=$tplRules;
  3633. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$examGroupId}'")->execute();
  3634. if($updatePaperScoreSql){
  3635. foreach ($updatePaperScoreSql as $sql){
  3636. $this->sConn->createCommand($sql)->execute();
  3637. }
  3638. }
  3639. $this->sendNoticeToReport($examGroupId);
  3640. if(Yii::app()->params['handle_log_on_off'])
  3641. {
  3642. writeFileLog(jsonEncode(array(
  3643. "exam_group_id" => $examGroupId,
  3644. "operate_project" => 'zsyas2',
  3645. "school_id" => $this->schoolId,
  3646. "title" => '批量更新多选题报告',
  3647. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3648. "operate_method" => $this->action,
  3649. "operate_url" => $this->getRoute(),
  3650. "operate_sql" =>'',
  3651. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3652. "date"=>date('Y-m-d H:i:s')
  3653. )));
  3654. }
  3655. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  3656. if(isset($exam_group_data) && $exam_group_data->homework==1){
  3657. //发送学生端消息
  3658. $sendJsonArr=array(
  3659. 'school_id'=>$this->schoolId,
  3660. 'send_type'=>'zsyas',
  3661. 'update_type'=>0,
  3662. 'exam_group_id'=>$examGroupId,
  3663. );
  3664. sendStudentCacheQueue($sendJsonArr);
  3665. }
  3666. $result['status']=1;
  3667. $result['msg']='报告更新完成';
  3668. exit(json_encode($result));
  3669. }
  3670. //送分题/0分题
  3671. public function actionSendPoints(){
  3672. $actionType = Req::post('actype'); //操作 1 送分,2:0分
  3673. $paper_id = Req::post('paper_id');
  3674. $topic_id = Req::post('topic_id');
  3675. if(!$paper_id || !$topic_id)
  3676. {
  3677. echo json_encode(array('status'=>-1));exit;
  3678. }
  3679. $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id)));
  3680. $score_diff=0; //分差
  3681. if(empty($topic_data))
  3682. {
  3683. echo json_encode(array('status'=>0,'msg'=>'试卷不存在'));exit;
  3684. }
  3685. $score=$topic_data->score;
  3686. if($actionType==1){
  3687. $score_diff=$topic_data->score;
  3688. }else{
  3689. $score_diff=0-$topic_data->score;
  3690. }
  3691. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  3692. $exam_ids = array();
  3693. $paper_ids = array();
  3694. if($paper_data)
  3695. {
  3696. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  3697. if($exam_data)
  3698. {
  3699. $tplData = json_decode($exam_data->tpl_data,1);
  3700. $tplData['send_points'][$topic_data->order]=array(
  3701. 'topicNo'=>$topic_data->order,
  3702. 'topic_id'=>$topic_id,
  3703. 'actionType'=>$actionType,
  3704. );
  3705. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  3706. if($exam_group_data)
  3707. {
  3708. foreach($exam_group_data as $v)
  3709. {
  3710. $exam_ids[$v->exam_id] = $v->exam_id;
  3711. }
  3712. if($exam_ids)
  3713. {
  3714. $criteria = new CDbCriteria();
  3715. $criteria->addInCondition('exam_id',$exam_ids);
  3716. $paper_data = SPaper::model()->findAll($criteria);
  3717. if($paper_data)
  3718. {
  3719. foreach($paper_data as $v)
  3720. {
  3721. $paper_ids[$v->paper_id] = $v->paper_id;
  3722. }
  3723. $trans = $this->sConn->beginTransaction();
  3724. try{
  3725. $needSendLog=false;
  3726. //修改学生得分
  3727. if($actionType==1){ //送分
  3728. $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 ";
  3729. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  3730. if($students){
  3731. $studentIds=array();
  3732. foreach ($students as $v){
  3733. $studentIds[]=$v['student_id'];
  3734. }
  3735. $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 ";
  3736. $this->sConn->createCommand($sql)->execute();
  3737. $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  3738. $this->sConn->createCommand($sql)->execute();
  3739. $needSendLog=true;
  3740. }
  3741. }elseif($actionType==2){//0分
  3742. $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 ";
  3743. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  3744. if($students){
  3745. $studentIds=array();
  3746. foreach ($students as $v){
  3747. $studentIds[]=$v['student_id'];
  3748. }
  3749. $sql="update student_paper_topic_rs set scoring=0 where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  3750. $this->sConn->createCommand($sql)->execute();
  3751. $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  3752. $this->sConn->createCommand($sql)->execute();
  3753. $needSendLog=true;
  3754. }
  3755. }
  3756. $sql="update `exam` set `tpl_data` = '".(jsonEncode($tplData))."' where exam_id in (".implode(',',$exam_ids).")";
  3757. $this->sConn->createCommand($sql)->execute();
  3758. if($needSendLog){
  3759. $sendParam=array(
  3760. 'school_id'=>$this->schoolId,
  3761. 'exam_group_id'=>$exam_data->exam_group_id
  3762. );
  3763. sendZsystNotic($sendParam);
  3764. $kafkaData=array(
  3765. 'schoolId'=>$this->schoolId,
  3766. 'examGroupId'=>$exam_data->exam_group_id,
  3767. 'generateTime'=>time()*1000
  3768. );
  3769. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  3770. $this->sendNoticeToReport($exam_data->exam_group_id);
  3771. //发送学生端消息
  3772. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  3773. if($exam_group_data->homework==1){
  3774. $sendJsonArr=array(
  3775. 'school_id'=>$this->schoolId,
  3776. 'send_type'=>'zsyas',
  3777. 'update_type'=>0,
  3778. 'exam_group_id'=>$exam_data->exam_group_id,
  3779. );
  3780. sendStudentCacheQueue($sendJsonArr);
  3781. }
  3782. }
  3783. $trans->commit();
  3784. }
  3785. catch(Exception $e){
  3786. $trans->rollBack();
  3787. echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit;
  3788. }
  3789. if(Yii::app()->params['handle_log_on_off'])
  3790. {
  3791. writeFileLog(jsonEncode(array(
  3792. "exam_group_id" => $exam_data->exam_group_id,
  3793. "operate_project" => 'zsyas2',
  3794. "school_id" => $this->schoolId,
  3795. "title" => '送分0分',
  3796. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3797. "operate_method" => $this->action,
  3798. "operate_url" => $this->getRoute(),
  3799. "operate_sql" =>'',
  3800. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3801. "date"=>date('Y-m-d H:i:s')
  3802. )));
  3803. }
  3804. echo json_encode(array('status'=>1,'score'=>$score));exit;
  3805. }
  3806. }
  3807. }
  3808. }
  3809. }
  3810. }
  3811. //单选题多答案送分题
  3812. public function actionSendScore(){
  3813. $paper_id = Req::post('paper_id');
  3814. $topic_id = Req::post('topic_id');
  3815. $answer = Req::post('answer');
  3816. if(!$paper_id || !$topic_id || !$answer)
  3817. {
  3818. echo json_encode(array('status'=>0));exit;
  3819. }
  3820. $answerArr=explode(',',$answer);
  3821. if(!$answerArr){
  3822. echo json_encode(array('status'=>0,'msg'=>'答案不能为空'));exit;
  3823. }
  3824. foreach ($answerArr as $key => $val){
  3825. $answerArr[$key]="'".$val."'";
  3826. }
  3827. $topic_data = SPaperTopicRelation::model()->find(array('order'=>'`order` asc','condition'=>'`paper_id`=:paper_id and topic_id=:topic_id ','params'=>array(':paper_id'=>$paper_id,':topic_id'=>$topic_id)));
  3828. $score_diff=0; //分差
  3829. if(empty($topic_data))
  3830. {
  3831. echo json_encode(array('status'=>0,'msg'=>'试卷不存在'));exit;
  3832. }
  3833. $score=$topic_data->score;
  3834. $score_diff=$topic_data->score;
  3835. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  3836. $exam_ids = array();
  3837. $paper_ids = array();
  3838. if($paper_data)
  3839. {
  3840. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  3841. if($exam_data)
  3842. {
  3843. $tplData = json_decode($exam_data->tpl_data,1);
  3844. $tplData['send_points'][$topic_data->order]=array(
  3845. 'topicNo'=>$topic_data->order,
  3846. 'topic_id'=>$topic_id,
  3847. 'actionType'=>1,
  3848. 'answer'=>$answer
  3849. );
  3850. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  3851. if($exam_group_data)
  3852. {
  3853. foreach($exam_group_data as $v)
  3854. {
  3855. $exam_ids[$v->exam_id] = $v->exam_id;
  3856. }
  3857. if($exam_ids)
  3858. {
  3859. $criteria = new CDbCriteria();
  3860. $criteria->addInCondition('exam_id',$exam_ids);
  3861. $paper_data = SPaper::model()->findAll($criteria);
  3862. if($paper_data)
  3863. {
  3864. foreach($paper_data as $v)
  3865. {
  3866. $paper_ids[$v->paper_id] = $v->paper_id;
  3867. }
  3868. $trans = $this->sConn->beginTransaction();
  3869. try{
  3870. $needSendLog=false;
  3871. //修改学生得分
  3872. $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=0 and `type`=1 and answer in(".implode(',',$answerArr).")";
  3873. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  3874. if($students){
  3875. $studentIds=array();
  3876. foreach ($students as $v){
  3877. $studentIds[]=$v['student_id'];
  3878. }
  3879. $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and student_id in(".implode(',',$studentIds).")";
  3880. $this->sConn->createCommand($sql)->execute();
  3881. $sql="update student_paper_relation set scoring=scoring+".$score_diff." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  3882. $this->sConn->createCommand($sql)->execute();
  3883. $needSendLog=true;
  3884. }
  3885. $sql="update `exam` set `tpl_data` = '".(json_encode($tplData))."' where exam_id in (".implode(',',$exam_ids).")";
  3886. $this->sConn->createCommand($sql)->execute();
  3887. if($needSendLog){
  3888. $sendParam=array(
  3889. 'school_id'=>$this->schoolId,
  3890. 'exam_group_id'=>$exam_data->exam_group_id
  3891. );
  3892. sendZsystNotic($sendParam);
  3893. $kafkaData=array(
  3894. 'schoolId'=>$this->schoolId,
  3895. 'examGroupId'=>$exam_data->exam_group_id,
  3896. 'generateTime'=>time()*1000
  3897. );
  3898. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  3899. $this->sendNoticeToReport($exam_data->exam_group_id);
  3900. //发送学生端消息
  3901. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  3902. if($exam_group_data->homework==1){
  3903. $sendJsonArr=array(
  3904. 'school_id'=>$this->schoolId,
  3905. 'send_type'=>'zsyas',
  3906. 'update_type'=>0,
  3907. 'exam_group_id'=>$exam_data->exam_group_id,
  3908. );
  3909. sendStudentCacheQueue($sendJsonArr);
  3910. }
  3911. }
  3912. $trans->commit();
  3913. }
  3914. catch(Exception $e){
  3915. $trans->rollBack();
  3916. echo json_encode(array('status'=>0,'msg'=>'更新失败'));exit;
  3917. }
  3918. if(Yii::app()->params['handle_log_on_off'])
  3919. {
  3920. writeFileLog(jsonEncode(array(
  3921. "exam_group_id" => $exam_data->exam_group_id,
  3922. "operate_project" => 'zsyas2',
  3923. "school_id" => $this->schoolId,
  3924. "title" => '单选题多答案送分题',
  3925. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3926. "operate_method" => $this->action,
  3927. "operate_url" => $this->getRoute(),
  3928. "operate_sql" =>'',
  3929. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3930. "date"=>date('Y-m-d H:i:s')
  3931. )));
  3932. }
  3933. echo json_encode(array('status'=>1,'score'=>$score));exit;
  3934. }
  3935. }
  3936. }
  3937. }
  3938. }
  3939. }
  3940. //大题上移下移
  3941. public function actionMoveBatch()
  3942. {
  3943. $paper_id = Req::post('paper_id');
  3944. $topic_id = Req::post('topic_id');
  3945. $action = Req::post('action');
  3946. if(!$paper_id || !$topic_id)
  3947. {
  3948. echo json_encode(array('status'=>0,'msg'=>'参数错误'));exit;
  3949. }
  3950. $nowTopics=array();
  3951. $nowFirstOrder=0;
  3952. $anotherTopics=array();
  3953. $nowTopicType=0;
  3954. if($action=='up'){
  3955. //查找本题所有小题
  3956. $topic_data = $this->sConn->createCommand("select `order`,`topic_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$topic_id." order by `order` asc ")->queryAll();
  3957. foreach ($topic_data as $val){
  3958. $nowTopics[(string)$val['topic_id']]=$val['order'];
  3959. if(!$nowFirstOrder) $nowFirstOrder=$val['order'];
  3960. if(!$nowTopicType) $nowTopicType=$val['type'];
  3961. }
  3962. //查找上一道大题
  3963. $anotherTopic = $this->sConn->createCommand("select `order`,`stem_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `order`<{$nowFirstOrder} order by `order` desc limit 1 ")->queryRow();
  3964. }elseif($action=='down'){
  3965. //查找本题所有小题
  3966. $topic_data = $this->sConn->createCommand("select `order`,`topic_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$topic_id." order by `order` desc ")->queryAll();
  3967. foreach ($topic_data as $val){
  3968. $nowTopics[(string)$val['topic_id']]=$val['order'];
  3969. if(!$nowFirstOrder) $nowFirstOrder=$val['order'];
  3970. if(!$nowTopicType) $nowTopicType=$val['type'];
  3971. }
  3972. //查找下一道大题
  3973. $anotherTopic = $this->sConn->createCommand("select `order`,`stem_id`,`type` from paper_topic_relation where paper_id = '{$paper_id}' and `order`>{$nowFirstOrder} order by `order` asc limit 1 ")->queryRow();
  3974. }else{
  3975. echo json_encode(array('status'=>0,'msg'=>'操作错误'));exit;
  3976. }
  3977. if(!$anotherTopic){
  3978. echo json_encode(array('status'=>0,'msg'=>'不能再移动啦'));exit;
  3979. }
  3980. //查找上一道所有小题
  3981. $topic_data = $this->sConn->createCommand("select `order`,`topic_id` from paper_topic_relation where paper_id = '{$paper_id}' and `stem_id` = ".$anotherTopic['stem_id']." order by `order` asc ")->queryAll();
  3982. foreach ($topic_data as $val){
  3983. $anotherTopics[(string)$val['topic_id']]=$val['order'];
  3984. }
  3985. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  3986. $exam_ids = array();
  3987. $paper_ids = array();
  3988. if($paper_data)
  3989. {
  3990. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  3991. if($exam_data)
  3992. {
  3993. $tpl_data = json_decode($exam_data->tpl_data,1);
  3994. $orderAlias=array();
  3995. if(isset($tpl_data['new_items'])){
  3996. foreach ($tpl_data['new_items'] as $key =>$val){
  3997. if(isset($val['alias'])){
  3998. $orderAlias[$val['id']]=$val['alias'];
  3999. }
  4000. }
  4001. }
  4002. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  4003. if($exam_group_data)
  4004. {
  4005. foreach($exam_group_data as $v)
  4006. {
  4007. $exam_ids[$v->exam_id] = $v->exam_id;
  4008. }
  4009. if($exam_ids)
  4010. {
  4011. $criteria = new CDbCriteria();
  4012. $criteria->addInCondition('exam_id',$exam_ids);
  4013. $paper_data = SPaper::model()->findAll($criteria);
  4014. if($paper_data)
  4015. {
  4016. foreach($paper_data as $v)
  4017. {
  4018. $paper_ids[$v->paper_id] = $v->paper_id;
  4019. }
  4020. $trans = $this->sConn->beginTransaction();
  4021. try{
  4022. $sqlArr=array();
  4023. $updateNewItemsOrder=array();
  4024. foreach ($anotherTopics as $id =>$number){
  4025. if($action=='up'){
  4026. $newOrder=$number+count($nowTopics);
  4027. }else{
  4028. $newOrder=$number-count($nowTopics);
  4029. }
  4030. $updateNewItemsOrder[$number]=$newOrder;
  4031. $sqlArr[]='update `paper_topic_relation` set `order` = '.$newOrder.' ,`no` = '.$newOrder.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$id;
  4032. }
  4033. foreach ($nowTopics as $id =>$number){
  4034. if($action=='up'){
  4035. $newOrder=$number-count($anotherTopics);
  4036. }else{
  4037. $newOrder=$number+count($anotherTopics);
  4038. }
  4039. $updateNewItemsOrder[$number]=$newOrder;
  4040. $sqlArr[]='update `paper_topic_relation` set `order` = '.$newOrder.' ,`no` = '.$newOrder.' where paper_id in ('.implode(',',$paper_ids).') and topic_id = '.$id;
  4041. }
  4042. if(isset($tpl_data['new_items'])){
  4043. foreach ($tpl_data['new_items'] as $key =>$val){
  4044. if(isset($updateNewItemsOrder[$val['id']])){
  4045. $tpl_data['new_items'][$key]['id']=$updateNewItemsOrder[$val['id']];
  4046. $tpl_data['new_items'][$key]['alias']=$orderAlias[$updateNewItemsOrder[$val['id']]];
  4047. }
  4048. }
  4049. $sqlArr[]="update `exam` set `tpl_data` = '".(jsonEncode($tpl_data))."' where exam_id in (".implode(',',$exam_ids).")";
  4050. }
  4051. foreach ($sqlArr as $sql){
  4052. $this->sConn->createCommand($sql)->execute();
  4053. }
  4054. $trans->commit();
  4055. echo json_encode(array('status'=>1));exit;
  4056. }
  4057. catch(Exception $e){
  4058. $trans->rollBack();
  4059. echo json_encode(array('status'=>0));exit;
  4060. }
  4061. }
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. //处理tpl_data,计算部分
  4068. private function sumTplDataScores($select_info,$is_third){
  4069. $TotalScore = 0; //计算可能多分组情况总分
  4070. $sameGroupTopic=array();
  4071. $groupScoreArr=array();
  4072. $required=1;
  4073. if(isset($select_info['required'])){
  4074. $required=$select_info['required'];
  4075. }elseif(isset($select_info['items'][17])){
  4076. $required=$select_info['items'][17]['required'];
  4077. }
  4078. if ($select_info) {
  4079. if ($select_info && isset($select_info['new_items']) && !empty($select_info['new_items'])) {
  4080. $nowGroupId = 0; //分组标志
  4081. foreach ($select_info['new_items'] as $k => $sc) {
  4082. //分组判断
  4083. if($sc['topic_type']==17 && !$sc['group_id']){
  4084. $sc['group_id']=1000;
  4085. }
  4086. if (!isset($sc['group_id']) || !$sc['group_id']) {
  4087. $TotalScore += $sc['score'];
  4088. } else{
  4089. if(isset($sc['smTopicLen']) && $sc['smTopicLen']){
  4090. //在线多组,另计
  4091. }else{
  4092. $groupScoreArr[$sc['group_id']][]=$sc['score'];
  4093. }
  4094. }
  4095. if(isset($sc['sameAliasNo']) && $sc['sameAliasNo']){
  4096. $sameGroupTopic[$sc['group_id']][$sc['sameAliasNo']][]=$sc['score'];
  4097. }
  4098. }
  4099. if($sameGroupTopic){
  4100. foreach ($sameGroupTopic as $gid =>$value){
  4101. $value=array_values($value);
  4102. $TotalScore+=array_sum($value[0]);
  4103. }
  4104. }
  4105. if($groupScoreArr){
  4106. if($is_third){
  4107. //多组,多选一
  4108. foreach ($groupScoreArr as $gid =>$item){
  4109. $TotalScore+=$item[0];
  4110. }
  4111. }else{
  4112. //一组,多选多
  4113. $groupScoreArr=array_values($groupScoreArr);
  4114. $TotalScore+=array_sum(array_slice($groupScoreArr[0],0,$required));
  4115. }
  4116. }
  4117. }
  4118. }
  4119. return $TotalScore;
  4120. }
  4121. /*系统组卷,补齐new_items*/
  4122. private function createNewItems($tplData){
  4123. $newItems=array();
  4124. $id=1;
  4125. $groupId=0;
  4126. $required=0;
  4127. foreach ($tplData['items'] as $type =>$item){
  4128. if($type==17){
  4129. $required=$item['required'];
  4130. if(!$groupId){
  4131. $groupId=$id;
  4132. }
  4133. }
  4134. if(isset($item['perScores'])){
  4135. foreach ($item['perScores'] as $score){
  4136. $newItems[]=array(
  4137. 'id'=>$id,
  4138. 'showNum'=>$id,
  4139. 'alias'=>$id,
  4140. 'score'=>$score,
  4141. 'topic_type'=>$type,
  4142. 'group_id'=>$groupId
  4143. );
  4144. $id++;
  4145. }
  4146. }elseif(isset($item['perScore'])){
  4147. for($i=0;$i<$item['total'];$i++){
  4148. $newItems[]=array(
  4149. 'id'=>$id,
  4150. 'showNum'=>$id,
  4151. 'alias'=>$id,
  4152. 'score'=>$item['perScore'],
  4153. 'topic_type'=>$type,
  4154. 'group_id'=>$groupId
  4155. );
  4156. $id++;
  4157. }
  4158. }elseif(isset($item['score'])){
  4159. for($i=0;$i<$item['total'];$i++){
  4160. $newItems[]=array(
  4161. 'id'=>$id,
  4162. 'showNum'=>$id,
  4163. 'alias'=>$id,
  4164. 'score'=>$item['score'],
  4165. 'topic_type'=>$type,
  4166. 'group_id'=>$groupId
  4167. );
  4168. $id++;
  4169. }
  4170. }
  4171. }
  4172. $tplData['required']=$required;
  4173. $tplData['new_items']=$newItems;
  4174. return $tplData;
  4175. }
  4176. //全学科第三方题型转换
  4177. public function getTopicTypeForAllSubjectThird($clientType){
  4178. $topicTypeRelation=array(
  4179. 1=>1, //单选
  4180. 3=>2, //不定项
  4181. 5=>5, //填空
  4182. 8=>7, //解答
  4183. );
  4184. if(isset($topicTypeRelation[$clientType])){
  4185. return $topicTypeRelation[$clientType];
  4186. }else{
  4187. return 0;
  4188. }
  4189. }
  4190. }