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