ExportController.php 248 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168
  1. <?php
  2. /**
  3. * 导出报告控制器类
  4. * @author jiangfei
  5. * @date 2015-07-22 17:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class ExportController extends Controller {
  9. public $newline;
  10. private $units = array(
  11. 'in' => 96,
  12. 'cm' => 28,
  13. 'mm' => 2.8,
  14. 'pt' => 1.33,
  15. 'pc' => 12,
  16. );
  17. // 打印列表
  18. public function actionIndex() {
  19. $this->newline='<br>';
  20. $getName = safe_replace(Yii::app()->request->getQuery('realname'));
  21. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  22. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  23. $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
  24. $display = safe_replace(Yii::app()->request->getQuery('display'));
  25. $type_id = safe_replace(Yii::app()->request->getQuery('type_id'));
  26. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  27. $grade_class_array = array();
  28. $con = array();
  29. // 打印任务处理
  30. // $ExamModel = Exam::model();
  31. //$ClassModel = ClassModel::model();
  32. $printList = array();
  33. $grade_class_data=$this->sConn->createCommand("select class_id,class_name from class where grade='{$grade_id}' and semester_id='{$this->semesterId}'")->queryAll();
  34. //$grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id', array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  35. if ($grade_class_data) {
  36. foreach ($grade_class_data as $v) {
  37. $grade_class_array[$v['class_id']] = $v;
  38. }
  39. }
  40. // 获取当前学期班级并组装
  41. $criteria = new CDbCriteria();
  42. $criteria->addCondition('semester_id=:semester_id');
  43. if ($grade_id) {
  44. $con = array('c.grade = ' . $grade_id);
  45. $criteria->addCondition('grade=:grade');
  46. $criteria->params[':grade'] = $grade_id;
  47. }
  48. if ($class_id) {
  49. $con = array_merge($con, array('c.class_id = ' . $class_id));
  50. $criteria->addCondition('class_id=:class_id');
  51. $criteria->params[':class_id'] = $class_id;
  52. }
  53. if ($getName) {
  54. $con = array_merge($con, array("e.name like '%{$getName}%'"));
  55. }
  56. if(in_array($this->subjectId,$this->mathSubjectId)){
  57. $con = array_merge($con, array("e.subject_id in (".implode(',',$this->mathSubjectId).")"));
  58. }else{
  59. $con = array_merge($con, array('e.subject_id = ' . $this->subjectId));
  60. }
  61. if($display)
  62. {
  63. $con = array_merge($con, array("e.export_dispaly = 1"));
  64. }else
  65. {
  66. $con = array_merge($con, array("e.export_dispaly = 0"));
  67. }
  68. $con = array_merge($con, array('eg.create_type in (0,1,2,3,5,6)'));
  69. if($type_id){
  70. if($type_id==1){
  71. $con =array_merge($con, array('eg.is_third = 0'));
  72. }elseif($type_id==2){
  73. $con = array_merge($con, array('eg.is_third = 1'));
  74. $con = array_merge($con, array('eg.mark_type > 0'));
  75. }else{
  76. $con = array_merge($con, array('eg.is_third = 1'));
  77. $con = array_merge($con, array('eg.mark_type =0'));
  78. }
  79. }
  80. $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
  81. $class_array = ClassModel::model()->findAll($criteria);
  82. $ccArray = array();
  83. $ccName = array();
  84. foreach ($class_array as $cc => $ca) {
  85. array_push($ccArray, $ca->class_id);
  86. $ccName[$ca->class_id] = $ca->class_name;
  87. }
  88. $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "(e.status = 1 or e.status=4)"), $con),array('e.complete_time desc'));
  89. // $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "(e.status = 1 )"), $con),array('e.complete_time desc'));
  90. if ($resultList["rs"]) {
  91. foreach ($resultList['rs'] as $k => $v) {
  92. $printList[$k] = $v;
  93. $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
  94. $printList[$k]['is_method_pdf'] = SExamTeachingProduct::isGenerate($v['exam_id'], 31); //FIXME 方法宝教师端
  95. $pname = $this->schoolManager->getExamName($v["exam_id"]); // 周周练名称
  96. $printList[$k]['print_name'] = $pname;
  97. //试卷类别
  98. if($v['is_third']==0){
  99. $printList[$k]['type_name'] = '校本课程平台试卷';
  100. }elseif($v['is_third']==1){
  101. if($v['mark_type']==0){
  102. $printList[$k]['type_name'] = '第三方导入成绩试卷';
  103. }else{
  104. $printList[$k]['type_name'] = '第三方线上阅卷试卷';
  105. }
  106. }
  107. if(isset(Yii::app()->params['grade_list'][$v['grade']])){
  108. $printList[$k]['grade_name']=Yii::app()->params['grade_list'][$v['grade']]['grade_name'];
  109. }else{
  110. $printList[$k]['grade_name']='';
  111. }
  112. }
  113. }
  114. $data = array();
  115. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  116. $data['realname'] = $getName;
  117. $data['grade_id'] = $grade_id;
  118. $data['class_id'] = $class_id;
  119. $data['display'] = $display;
  120. $data['grade_class'] = $grade_class_array;
  121. $data['printList'] = $printList;
  122. $data['pages'] = $resultList['pager'];
  123. $data['page_total'] = $resultList['pager']->rowsCount;
  124. // $data["subject"] = $subject_exam_data;
  125. $data["subjectId"] = $this->subjectId;
  126. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  127. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  128. } else {
  129. $data["use_zhixue"] = 0;
  130. }
  131. $data['past_sem_exist'] = 0;//默认不存在过去的学期
  132. $data['type_id']=$type_id;
  133. $sql = 'select start_time from semester where status=1 limit 1';
  134. $res = $this->sConn->createCommand($sql)->queryRow();
  135. $start_time = $res['start_time'];
  136. if (!$start_time) {
  137. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  138. }
  139. $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
  140. $res = $this->sConn->createCommand($sql)->queryRow();
  141. $row_num = $res['rownum'];
  142. $row_num && $data['past_sem_exist']=1;
  143. unset($resultList);
  144. $this->render('index', $data);
  145. }
  146. /**
  147. * 是否开通过方法宝
  148. */
  149. public function isOpenProductMethod($classId=0,$examId=0,$type=ProductDownload::PRODUCT_TYPE_METHOD){
  150. $allStudent = SStudentClassRelation::model()->getStudentInfoByClassId($classId);
  151. $studentIds=_array_column($allStudent,'student_id');
  152. $sql = "select e.name,c.class_name,c.grade,e.class_id,p.add_time,e.semester_id from exam e join class_exam_printer p on p.exam_id=e.exam_id
  153. join class c on e.class_id = c.class_id where e.class_id = '{$classId}' and e.exam_id = '{$examId}'";
  154. $names = $this->sConn->createCommand($sql)->queryRow();
  155. $Sem=new SSemester();
  156. $code= $Sem->conn->createQuery()
  157. ->from('semester')
  158. ->where("semester_id = '".$names['semester_id']."'")
  159. ->limit(1)
  160. ->query()
  161. ->read();
  162. $intarr=array(
  163. "schoolId"=>$this->schoolId,
  164. "clazzId"=>$names['class_id'],
  165. "semester"=>$code['refer_code'],
  166. "grade"=>$names['grade'],
  167. "students"=>$studentIds,
  168. "examTime"=>$names['add_time'],
  169. "classify"=>$type,
  170. "subject"=>$this->subjectId
  171. );
  172. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  173. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  174. //该班级是否有学生开通过方法宝
  175. $isClassOpen=false;
  176. if(isset($rs->data)){
  177. $limitstu=$rs->data;
  178. if(($limitstu==0) || (is_array($limitstu) && array_intersect($studentIds,$limitstu))){
  179. $isClassOpen=true;
  180. }
  181. }
  182. return $isClassOpen;
  183. }
  184. //获取错题前十和教师讲堂考试班级
  185. public function actionClassExamAc(){
  186. $examGroupId = safe_replace(Yii::app()->request->getQuery('examGroupId'));
  187. $resultList = array();
  188. if(is_numeric($examGroupId) && $examGroupId > 0){
  189. $con = array();
  190. $con = array_merge($con, array(" e.exam_group_id = ".$examGroupId));
  191. if(in_array($this->subjectId,$this->mathSubjectId)){
  192. $con = array_merge($con, array("e.subject_id in (".implode(',',$this->mathSubjectId).")"));
  193. }else{
  194. $con = array_merge($con, array('e.subject_id = ' . $this->subjectId));
  195. }
  196. $resultList = $this->schoolManager->getClassExamAc(array_merge(array("cep.type = '0'", "e.status = 1"), $con),array('e.complete_time desc'));
  197. }
  198. // var_dump($resultList);die;
  199. $this->render('reset_ac',array("resultList" => $resultList,'printType'=>''));
  200. }
  201. //重置错题前十和教师讲堂
  202. public function actionResetAc(){
  203. $param = Yii::app()->request->getParam('examIds');
  204. foreach($param as $value){
  205. $examId = $value[0];
  206. $this->setIs_new($examId);
  207. //教师讲案
  208. if($value[1] == 1 && $value[2] != ''){
  209. $status_1 = $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => '', "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  210. }
  211. //错题前十
  212. if($value[3] == 1 && $value[4] != ''){
  213. $status_2 = $this->sConn->createCommand()->update("exam", array("is_topwb_pdf" => 0, "is_topwb_html" => 90), "exam_id = '{$examId}'");
  214. }
  215. }
  216. echo 1;
  217. }
  218. public function actionIndex_duo() {
  219. $getName = safe_replace(Yii::app()->request->getQuery('realname'));
  220. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  221. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  222. $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
  223. $type_id = safe_replace(Yii::app()->request->getQuery('type_id'));
  224. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  225. $grade_class_array = array();
  226. $con = array();
  227. // 打印任务处理
  228. // $ExamModel = Exam::model();
  229. // $ClassModel = ClassModel::model();
  230. $printList = array();
  231. $grade_class_data=$this->sConn->createCommand("select class_id,class_name from class where grade='{$grade_id}' and semester_id='{$this->semesterId}'")->queryAll();
  232. //$grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id', array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  233. if ($grade_class_data) {
  234. foreach ($grade_class_data as $v) {
  235. $grade_class_array[$v['class_id']] = $v;
  236. }
  237. }
  238. // 获取当前学期班级并组装
  239. $criteria = new CDbCriteria();
  240. $criteria->addCondition('semester_id=:semester_id');
  241. if ($grade_id) {
  242. $con = array('c.grade = ' . $grade_id);
  243. $criteria->addCondition('grade=:grade');
  244. $criteria->params[':grade'] = $grade_id;
  245. }
  246. if ($class_id) {
  247. $con = array_merge($con, array('c.class_id = ' . $class_id));
  248. $criteria->addCondition('class_id=:class_id');
  249. $criteria->params[':class_id'] = $class_id;
  250. }
  251. if ($getName) {
  252. $con = array_merge($con, array("e.name like '%{$getName}%'"));
  253. }
  254. if($type_id){
  255. if($type_id==1){
  256. $con =array_merge($con, array('eg.is_third = 0'));
  257. }elseif($type_id==2){
  258. $con = array_merge($con, array('eg.is_third = 1'));
  259. $con = array_merge($con, array('eg.mark_type > 0'));
  260. }else{
  261. $con = array_merge($con, array('eg.is_third = 1'));
  262. $con = array_merge($con, array('eg.mark_type =0'));
  263. }
  264. }
  265. if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
  266. $con = array_merge($con, array("e.subject_id in (".implode(',',$this->mathSubjectId).")"));
  267. }else{
  268. $con = array_merge($con, array('e.subject_id = ' . Yii::app()->session['session_duoxueke_subject_id']));
  269. }
  270. $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
  271. $class_array = ClassModel::model()->findAll($criteria);
  272. $ccArray = array();
  273. $ccName = array();
  274. foreach ($class_array as $cc => $ca) {
  275. array_push($ccArray, $ca->class_id);
  276. $ccName[$ca->class_id] = $ca->class_name;
  277. }
  278. $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "(e.status = 1 or e.status=4)"), $con),array('e.complete_time desc'));
  279. //$resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "(e.status = 1)"), $con),array('e.complete_time desc'));
  280. if ($resultList["rs"]) {
  281. foreach ($resultList['rs'] as $k => $v) {
  282. $printList[$k] = $v;
  283. $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
  284. // $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称
  285. $pname = $this->schoolManager->getExamName($v["exam_id"]); // 周周练名称
  286. $printList[$k]['print_name'] = $pname;
  287. //试卷类别
  288. if($v['is_third']==0){
  289. $printList[$k]['type_name'] = '校本课程平台试卷';
  290. }elseif($v['is_third']==1){
  291. if($v['mark_type']==0){
  292. $printList[$k]['type_name'] = '第三方导入成绩试卷';
  293. }else{
  294. $printList[$k]['type_name'] = '第三方线上阅卷试卷';
  295. }
  296. }
  297. if(isset(Yii::app()->params['grade_list'][$v['grade']])){
  298. $printList[$k]['grade_name']=Yii::app()->params['grade_list'][$v['grade']]['grade_name'];
  299. }else{
  300. $printList[$k]['grade_name']='';
  301. }
  302. //判断是否上传答案、试题
  303. $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($v['exam_group_id']);
  304. $uploadStatus=0;
  305. if($uploadExamInfo){
  306. if(isset($uploadExamInfo[1])){
  307. if($uploadExamInfo[1]['topic_upload']==1){
  308. $uploadStatus+=1;
  309. }
  310. }
  311. if(isset($uploadExamInfo[2])){
  312. if($uploadExamInfo[2]['answer_upload']==1){
  313. $uploadStatus+=3;
  314. }
  315. }
  316. }
  317. if($uploadStatus<4){
  318. $printList[$k]['topic_answer_upload']=0;
  319. }else{
  320. $printList[$k]['topic_answer_upload']=1;
  321. }
  322. }
  323. }
  324. $data = array();
  325. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  326. $data['realname'] = $getName;
  327. $data['grade_id'] = $grade_id;
  328. $data['class_id'] = $class_id;
  329. $data['grade_class'] = $grade_class_array;
  330. $data['printList'] = $printList;
  331. $data['pages'] = $resultList['pager'];
  332. $data['page_total'] = $resultList['pager']->rowsCount;
  333. // $data["subject"] = $subject_exam_data;
  334. $data["subjectId"] = $this->subjectId;
  335. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  336. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  337. } else {
  338. $data["use_zhixue"] = 0;
  339. }
  340. $data['past_sem_exist'] = 0;//默认不存在过去的学期
  341. $data['type_id']=$type_id;
  342. $sql = 'select start_time from semester where status=1 limit 1';
  343. $res = $this->sConn->createCommand($sql)->queryRow();
  344. $start_time = $res['start_time'];
  345. if (!$start_time) {
  346. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  347. }
  348. $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
  349. $res = $this->sConn->createCommand($sql)->queryRow();
  350. $row_num = $res['rownum'];
  351. $row_num && $data['past_sem_exist']=1;
  352. unset($resultList);
  353. $this->render('index1', $data);
  354. }
  355. // 更新试卷为打印状态
  356. public function actionExcel() {
  357. $classId = safe_replace(Yii::app()->request->getQuery('classId'));
  358. $examId = safe_replace(Yii::app()->request->getQuery('examId'));
  359. $is_outer = safe_replace(Yii::app()->request->getQuery('is_outer'));
  360. $type = safe_replace(Yii::app()->request->getQuery('type'));
  361. $type = !in_array($type, array('excel', 'word')) ? 'excel' : $type;
  362. $url = Yii::app()->params['te_url'] . "wp/reportExcel?wpId={$examId}&classId={$classId}&schoolId={$this->schoolId}&type={$type}&is_outer={$is_outer}";
  363. $this->redirect($url);
  364. }
  365. /**
  366. * 重置教师讲案
  367. */
  368. public function actionreload_academicr(){
  369. $examId = safe_replace(Yii::app()->request->getQuery('examId'));
  370. $type = safe_replace(Yii::app()->request->getQuery('type'));
  371. $this->setIs_new($examId);
  372. if($type==1){//教师讲案
  373. if($this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => '', "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'")){
  374. echo json_encode(array("status"=>0));exit;
  375. }
  376. }elseif($type==2){//错题前十
  377. $status = $this->sConn->createCommand()->update("exam", array("is_topwb_pdf" => 0, "is_topwb_html" => 90), "exam_id = '{$examId}'");
  378. if($status !== false){
  379. $sql = 'select exam_group_id from exam where exam_id = '.$examId;
  380. $res = $this->sConn->createCommand($sql)->queryRow();
  381. if (isset($res['exam_group_id'])) {
  382. //发送消息
  383. $sendMsg = array(
  384. 'school_id' => $this->schoolId,
  385. 'msg_type' => 90,
  386. 'subject_id' => 3,
  387. 'send_type' => 'exam',
  388. 'product_type' => array(14),
  389. 'exam_group_id' => $res['exam_group_id'],
  390. 'exam_ids' => array($examId),
  391. 'complete_rate' => 0.9,
  392. );
  393. sendDataToKafka('php-product-html',$sendMsg);
  394. echo json_encode(array("status"=>0));exit;
  395. }
  396. }
  397. }elseif ($type==3){
  398. if($this->sConn->createCommand()->update("exam_teaching_product", array("is_create_pdf" => 0,"pdf_path"=>""), "exam_id = '{$examId}' and product_type=31")){
  399. echo json_encode(array("status"=>0));exit;
  400. }
  401. }
  402. echo json_encode(array("status"=>1));exit;
  403. }
  404. /**
  405. * 下载教师讲案
  406. */
  407. public function actionAcademicr() {
  408. @ini_set('default_socket_timeout', 5);
  409. @ini_set('memory_limit', '512M');
  410. set_time_limit(0);
  411. $examId = safe_replace(Yii::app()->request->getQuery('examId'));
  412. $classId = safe_replace(Yii::app()->request->getQuery('classId'));
  413. $force = safe_replace(Yii::app()->request->getQuery('force'));
  414. $isFromPast = safe_replace(Yii::app()->request->getQuery('isFromPast')); //过去学期的教师讲案如果需要生成的话,只生成个性化版的,不生成分层版的
  415. $sem = new SSemester();
  416. $codeNow = $sem->getCodeByExamId($examId);
  417. $this->setIs_new($examId);
  418. $sql = "select e.teacher_id,eg.mark_type,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,c.class_name,eg.import_score_type,c.grade,p.method_ids,e.semester_id from exam as e left join class as c on c.class_id=e.class_id left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id where e.exam_id={$examId}";
  419. $exam_info = $this->sConn->createCommand($sql)->queryRow();
  420. $grade = $exam_info['grade'];
  421. $paper_method_ids = $exam_info['method_ids'];
  422. $score_type = $exam_info['import_score_type'];//成绩导入流程 0-正常扫描
  423. $semesterId = $exam_info['semester_id'];
  424. // $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['academicr_pdf_path'];
  425. $pdfurl = $pdfpath = $exam_info['academicr_pdf_path'];
  426. $is_create=1;
  427. $force=0;
  428. if(strpos($pdfurl,'http') !== false){
  429. // if(!file_get_contents($pdfurl)){
  430. if(!$this->curlDownloadImage($pdfurl)){
  431. $force = 1;
  432. }
  433. }else{
  434. $force = 1;
  435. }
  436. if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || $force) {
  437. $is_create=0;
  438. $sql = "SELECT e.exam_group_id, e.exam_id, e.name AS exam_name, e.create_time AS exam_time, p.paper_id, p.score as paper_score, e.class_id,e.is_preparation_created,e.tpl_index, eg.mark_type,p.is_labelled,p.labelled_type,eg.qxk_paper_id ";
  439. $sql.= "FROM exam e ";
  440. $sql.= "JOIN paper p ON p.exam_id = e.exam_id ";
  441. $sql.= "JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id ";
  442. $sql.= "WHERE e.status = '1' AND e.exam_id = '{$examId}' ";
  443. $data = array();
  444. $exam = $this->sConn->createCommand($sql)->queryRow();
  445. $labelled_type = $exam['labelled_type'];
  446. $class_id = $exam['class_id'];
  447. $is_qxk = $exam['qxk_paper_id']?1:0;//是否是全学科
  448. if($class_id){
  449. $exam['show_level'] = $this->get_version($class_id);
  450. $exam['level_rule'] = $this->get_level_rule($class_id);
  451. }
  452. //获取显示设置
  453. $setting_arr = array("common"=>1,"common_wrong"=>1,"paper"=>1,"paper_wrong"=>1,"real_topic"=>1,"classmateOptimization"=>1);
  454. $sql = "select tt.template_id,tt.config_text from teaching_template tt join teaching_class_set tcs on tt.template_id=tcs.template_id where tt.subject_id = 3 and tcs.class_id='{$class_id}'";
  455. $setting_data = $this->sConn->createCommand($sql)->queryRow();
  456. if($setting_data){
  457. $setting_data_arr = json_decode($setting_data['config_text'],true);
  458. if(isset($setting_data_arr['common'])){
  459. $setting_arr['common'] = $setting_data_arr['common'];
  460. }
  461. if(isset($setting_data_arr['common_wrong'])){
  462. $setting_arr['common_wrong'] = $setting_data_arr['common_wrong'];
  463. }
  464. if(isset($setting_data_arr['paper'])){
  465. $setting_arr['paper'] = $setting_data_arr['paper'];
  466. }
  467. if(isset($setting_data_arr['paper_wrong'])){
  468. $setting_arr['paper_wrong'] = $setting_data_arr['paper_wrong'];
  469. }
  470. if(isset($setting_data_arr['real_topic'])){
  471. $setting_arr['real_topic'] = $setting_data_arr['real_topic'];
  472. }
  473. if(isset($setting_data_arr['classmateOptimization'])){
  474. $setting_arr['classmateOptimization'] = $setting_data_arr['classmateOptimization'];
  475. }
  476. }
  477. $is_same_bs = 1;//是否开启相同变式题(需要读提分宝班级定制的配置)
  478. $same_bs_data = array();//开启相同变式题 原题跟变式题的对应关系
  479. $is_same_bs = $this->getClassSet($classId, $semesterId);
  480. if($is_same_bs && $labelled_type == 1){
  481. //判断有没有订单(提分方案2,提分宝3) 如果没有订单生成教学宝 有订单没数据不能生成
  482. $has_order = 0;
  483. $table_spr = empty($codeNow)?'student_paper_relation':'student_paper_relation_'.$codeNow;
  484. $sql = "select student_id from {$table_spr} where exam_id = '{$examId}'";
  485. $spr_data = $this->sConn->createCommand($sql)->queryAll();
  486. $relateStudentRes = array();
  487. if($spr_data){
  488. foreach($spr_data as $spr_v){
  489. $relateStudentRes[]['student_id'] = $spr_v['student_id'];
  490. }
  491. }
  492. foreach(array(2,3) as $product_type){
  493. $temp_order = $this->getOrderStu($examId, $classId, $product_type, $relateStudentRes, $semesterId, $grade);
  494. if($temp_order && isset($temp_order['limitstu']) && $temp_order['limitstu']){
  495. $has_order = 1;
  496. break;
  497. }
  498. }
  499. $sql = "select preparation_plan_id,template_id,topic_id from preparation_plan_topic where preparation_plan_id='{$examId}'";
  500. $same_bs = $this->sConn->createCommand($sql)->queryAll();
  501. if($same_bs){
  502. foreach($same_bs as $same_k=>$same_v){
  503. $same_bs_data[$same_v['template_id']][] = $same_v['topic_id'];
  504. }
  505. }else{
  506. if($has_order){
  507. echo json_encode(array("status"=>1,"error"=>"变式题未生成,请等待"));
  508. exit;
  509. }
  510. }
  511. $setting_arr['common'] = 0;
  512. }
  513. if($labelled_type == 2){
  514. $exam['show_level'] = 0;
  515. }else{
  516. $sql = "select switch from producut_set_edition";
  517. $switch_data = $this->sConn->createCommand($sql)->queryRow();
  518. if($switch_data && in_array($switch_data['switch'],array(3,4))){
  519. $exam['show_level'] = 0;
  520. $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc";
  521. $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  522. if(!$gongxing_data && !$is_same_bs){
  523. echo json_encode(array("status"=>1,"error"=>"共性问题未生成,请稍等"));
  524. exit;
  525. }
  526. }else{
  527. if ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] != 1) { //如果选择的是分层班,教师讲案的生成条件是教师讲评题已经抽出
  528. echo json_encode(array("status"=>1,"error"=>"文件内容尚未生成,请等待"));
  529. exit;
  530. }elseif ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] == 2) {
  531. echo json_encode(array("status"=>1,"error"=>"由于题库题目导致无法生成,请联系后台题库老师去处理题目!"));
  532. exit;
  533. }
  534. }
  535. }
  536. if (!isset($exam['is_labelled']) || $exam['is_labelled']!=1) {
  537. echo json_encode(array("status"=>1,"error"=>"试卷还未标注,请先标注试卷"));
  538. exit;
  539. }
  540. // if($switch_data && in_array($switch_data['switch'],array(3,4))){
  541. // $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' order by topic_type asc";
  542. // $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  543. // if(!$gongxing_data){
  544. // echo json_encode(array("status"=>1,"error"=>"共性问题未生成,请稍等"));
  545. // exit;
  546. // }
  547. // }
  548. if ($exam) {
  549. //同学优解
  550. $staticUrl = Yii::app()->params['static_url'][$this->schoolGroupId];
  551. $excellent_solution = SStudentPaperTopicRs::model()->bestAnswer($exam,$codeNow,$staticUrl,$this->sConn,$is_qxk);
  552. //获取共性问题
  553. $has_topic_gaokao = array();//本教学宝其他题,用于抽取高考真题
  554. $gen_topics = array();
  555. $gen_topics_ids = array();//共性所有题ID集合
  556. $gen_topics_detail = array();//试题详情
  557. $gen_topics_msg = array();//题目难度、考点、挑战信息
  558. $schoolId = $this->schoolId;//当前学校
  559. $school_province_name = "";//学校省份
  560. $school_province_id = 0;//学校省份Id
  561. $gen_origin_ids = array();//共性原题Id
  562. $gen_origin_methods = array();//共性原题考点集合
  563. $school_msg = Yii::app()->businessDb->createCommand()->from('school')
  564. ->select("province_id")
  565. ->where("school_id = ".$schoolId)
  566. ->queryRow();
  567. if($school_msg){
  568. $school_province_id = $school_msg['province_id'];
  569. }
  570. if($school_province_id){
  571. $region_msg = Yii::app()->businessDb->createCommand()->from('region')
  572. ->select("region_name")
  573. ->where("region_id = ".$school_province_id)
  574. ->queryRow();
  575. if($region_msg){
  576. $school_province_name = $region_msg["region_name"];
  577. }
  578. }
  579. $sql = "select template_id,topic_id,topic_type,template_no from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc";
  580. $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  581. if($gongxing_data && $labelled_type != 2){
  582. foreach($gongxing_data as $k=>$v){
  583. $i = 0;
  584. $gen_topics_ids[] = $gen_origin_ids[] = $v['template_id'];
  585. $gen_topics_ids[] = $v['topic_id'];
  586. $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['template_id'];
  587. $gen_topics[$v['topic_type']][$i]['is_template'] = 1;
  588. $i++;
  589. $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['topic_id'];
  590. $gen_topics[$v['topic_type']][$i]['is_template'] = 0;
  591. //变式训练获取地区挑战数
  592. if($v['topic_id']){
  593. $gen_topics_msg[$v['topic_id']]['school_province_name'] = $school_province_name;
  594. $topic_count = Yii::app()->topic_province_count->hmget('province_stat:topic:'.$school_province_id,array($v['topic_id']));
  595. if($topic_count && isset($topic_count[0])){
  596. $gen_topics_msg[$v['topic_id']]['province_count'] = empty($topic_count[0])?1000:$topic_count[0]+1000;
  597. }else{
  598. $gen_topics_msg[$v['topic_id']]['province_count'] = 1000;
  599. }
  600. $gen_topics_msg[$v['template_id']]['template_no'] = $v['template_no'];
  601. }
  602. }
  603. }
  604. $gen_topics_ids = array_values(array_unique($gen_topics_ids));
  605. if($gen_topics_ids){
  606. $topicItems_1 = $this->aipost('/topic/batchAll', array('topicIds' => $gen_topics_ids));
  607. //debug($topicItems_1);
  608. if ($topicItems_1 && !isset($topicItems_1['status'])) {
  609. foreach ($topicItems_1 as $topicItem) {
  610. $gen_topics_detail_temp[$topicItem['id']] = $topicItem;
  611. }
  612. if ($gen_topics_detail_temp) {
  613. foreach ($gen_topics_detail_temp as $k => $v) {
  614. $v=(array)$v;
  615. $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
  616. if(!$teacher_tips){
  617. $teacher_tips = $this->dealTeacherTips($v);
  618. }
  619. $v['teacher_tips'] = $this->topicProcess($teacher_tips);
  620. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  621. if($v['type_id'] == 5 || $v['type_id'] == 6){
  622. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  623. }
  624. $v['title'] = $this->topicProcess($v['title']);
  625. if(isset($v['items'][0])){
  626. $v['items'][0]=(array)$v['items'][0];
  627. $v['items'][0]['options']=(array)$v['items'][0]['options'];
  628. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  629. foreach ($v['items'][0]['options'] as $key => $val) {
  630. $val=(array)$val;
  631. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  632. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  633. }
  634. }
  635. }
  636. //难度
  637. $gen_topics_msg[(string)$v['id']]['difficulty'] = isset($v['difficulty_degree'])?$v['difficulty_degree']:0;
  638. //考点
  639. $gen_topics_msg[(string)$v['id']]['methods'] = "";
  640. $methods_arr = array();
  641. if(isset($v['specials']) && $v['specials']){
  642. foreach($v['specials'] as $specials){
  643. if(isset($specials['method_name'])){
  644. $methods_arr[] = $specials['method_name'];
  645. }
  646. if(in_array($v['id'],$gen_origin_ids)){
  647. $gen_origin_methods[$specials['method_id']] = $specials['method_name'];
  648. }
  649. }
  650. }elseif (isset($v['kps']) && $v['kps']){
  651. foreach($v['kps'] as $kps){
  652. if(isset($kps['kp_name'])){
  653. $methods_arr[] = $kps['kp_name'];
  654. }
  655. if(in_array($v['id'],$gen_origin_ids)){
  656. $gen_origin_methods[$kps['kp_id']] = $kps['kp_name'];
  657. }
  658. }
  659. }
  660. if($methods_arr){
  661. $gen_topics_msg[$v['id']]['methods'] = implode(",",$methods_arr);
  662. }
  663. $gen_topics_detail[$v['id']] = $v;
  664. }
  665. }
  666. unset($gen_topics_detail_temp);
  667. }
  668. unset($topicItems_1);
  669. }
  670. //年级共性问题
  671. $grade_topics_ids = array();
  672. $grade_topic_data = array();
  673. $sql = "select topic_id from product_grade_common_topic where exam_group_id = '{$exam['exam_group_id']}'";
  674. $grade_data = $this->sConn->createCommand($sql)->queryAll();
  675. if($grade_data){
  676. foreach($grade_data as $k=>$v){
  677. $grade_topics_ids[] = $v['topic_id'];
  678. }
  679. }
  680. if($grade_topics_ids){
  681. $grade_topic_item = $this->aipost('/topic/batchAll', array('topicIds' => $grade_topics_ids));
  682. if ($grade_topic_item && !isset($grade_topic_item['status'])) {
  683. foreach ($grade_topic_item as $k => $v) {
  684. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  685. if($v['type_id'] == 5 || $v['type_id'] == 6){
  686. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  687. }
  688. $v['title'] = $this->topicProcess($v['title']);
  689. if(isset($v['items'][0])){
  690. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  691. foreach ($v['items'][0]['options'] as $key => $val) {
  692. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  693. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  694. }
  695. }
  696. }
  697. $grade_topic_item[$k] =$v;
  698. }
  699. $grade_topic_data = $grade_topic_item;
  700. }
  701. }
  702. $data['grade_topic_data'] = $grade_topic_data;
  703. $data['gen_origin_methods'] = $gen_origin_methods?implode(",",$gen_origin_methods):"";
  704. $data['gen_topics_msg'] = $gen_topics_msg;
  705. $data['gen_topics'] = $gen_topics;
  706. $data['gen_topics_detail'] = $gen_topics_detail;
  707. $data['excellent_solution'] = $excellent_solution;
  708. $data['wb_isp_version'] = $exam['show_level'];
  709. $data['level_rule'] = $exam['level_rule'];
  710. $data['examGroups'] = array();
  711. $data['examGroupIds'] = array();
  712. $data['exams'] = array();
  713. $data['examIds'] = array();
  714. $data['prevExams'] = array();
  715. $data['prevExamIds'] = array();
  716. $data['papers'] = array();
  717. $data['paperIds'] = array();
  718. $data['prevPapers'] = array();
  719. $data['prevPaperIds'] = array();
  720. $data['fcTopicIds'] = array();
  721. $data['methodIds'] = array();
  722. $data['methodNames'] = array();
  723. $data['topicIds'] = array();
  724. $data['noTopicIds'] = array();
  725. $data['topicDetails'] = array();
  726. $data['answer_score_details'] = array();//客观题答案明细
  727. if (!isset($data['examGroups'][$exam['exam_group_id']])) {
  728. $data['examGroups'][$exam['exam_group_id']] = array(
  729. 'examIds' => array(),
  730. 'paperIds' => array(),
  731. 'examName' => $exam['exam_name'],
  732. 'examTime' => $exam['exam_time'],
  733. 'fullScore' => $exam['paper_score'],
  734. );
  735. }
  736. $data['examGroups'][$exam['exam_group_id']]['examIds'][] = $exam['exam_id'];
  737. $data['examGroups'][$exam['exam_group_id']]['paperIds'][] = $exam['paper_id'];
  738. if (!isset($data['exams'][$exam['exam_id']])) {
  739. $data['exams'][$exam['exam_id']] = array(
  740. 'paperIds' => array(),
  741. 'examName' => $exam['exam_name'],
  742. 'examTime' => $exam['exam_time'],
  743. 'examGroupId' => $exam['exam_group_id'],
  744. 'fullScore' => $exam['paper_score'],
  745. );
  746. }
  747. $data['exams'][$exam['exam_id']]['paperIds'][] = $exam['paper_id'];
  748. if (!isset($data['papers'][$exam['paper_id']])) {
  749. $data['papers'][$exam['paper_id']] = array();
  750. }
  751. $data['papers'][$exam['paper_id']]['examId'] = $exam['exam_id'];
  752. $data['papers'][$exam['paper_id']]['examName'] = $exam['exam_name'];
  753. $data['papers'][$exam['paper_id']]['examTime'] = $exam['exam_time'];
  754. $data['papers'][$exam['paper_id']]['examGroupId'] = $exam['exam_group_id'];
  755. $data['papers'][$exam['paper_id']]['fullScore'] = $exam['paper_score'];
  756. $data['examGroupIds'][] = $exam['exam_group_id'];
  757. $data['examIds'][] = $exam['exam_id'];
  758. $data['paperIds'][] = $exam['paper_id'];
  759. // 上一次考试
  760. $sql = "SELECT e.exam_id, p.paper_id
  761. FROM exam e
  762. JOIN paper p ON p.exam_id = e.exam_id
  763. WHERE e.subject_id in(".implode(',',$this->mathSubjectId).") and e.class_id = '" . $exam['class_id'] . "' AND e.create_time < '" . $exam['exam_time'] . "' AND e.status = '1'
  764. ORDER BY e.create_time DESC
  765. LIMIT 1";
  766. $query = $this->sConn->createCommand($sql)->queryRow();
  767. if ($query) {
  768. $codePrev = $sem->getCodeByExamId($query['exam_id']);
  769. $data['prevExamIds'][] = $query['exam_id'];
  770. $data['prevPaperIds'][] = $query['paper_id'];
  771. $data['exams'][$exam['exam_id']]['prevExamId'] = $query['exam_id'];
  772. $data['papers'][$exam['paper_id']]['prevPaperId'] = $query['paper_id'];
  773. $data['prevExams'][$query['exam_id']] = $exam['exam_id'];
  774. $data['prevPapers'][$query['paper_id']] = $exam['paper_id'];
  775. // 上次考试总分
  776. $prevQuery = $this->sConn->createCommand("
  777. SELECT score
  778. FROM paper
  779. WHERE paper_id = '" . $query['paper_id'] . "'
  780. ")->queryRow();
  781. if ($prevQuery) {
  782. $data['papers'][$exam['paper_id']]['prevFullScore'] = $prevQuery['score'];
  783. }
  784. unset($prevQuery);
  785. // 上次考试的平均得分率
  786. if(empty($codePrev)){
  787. $prevQuery = $this->sConn->createCommand("
  788. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  789. FROM student_paper_relation
  790. WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
  791. ")->queryRow();
  792. }else{
  793. $prevQuery = $this->sConn->createCommand("
  794. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  795. FROM student_paper_relation_".$codePrev."
  796. WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
  797. ")->queryRow();
  798. }
  799. if ($prevQuery) {
  800. $data['papers'][$exam['paper_id']]['prevTotalNum'] = $prevQuery['total_num'];
  801. $data['papers'][$exam['paper_id']]['prevTotalScore'] = $prevQuery['total_score'];
  802. $data['papers'][$exam['paper_id']]['prevMaxScore'] = $prevQuery['max_score'];
  803. $data['papers'][$exam['paper_id']]['prevMinScore'] = $prevQuery['min_score'];
  804. $data['papers'][$exam['paper_id']]['prevAvgScore'] = 0;
  805. $data['papers'][$exam['paper_id']]['prevAvgRate'] = 0;
  806. if ($prevQuery['total_num'] > 0) {
  807. $data['papers'][$exam['paper_id']]['prevAvgScore'] = number_format($prevQuery['total_score'] / $prevQuery['total_num'], 2);
  808. if (isset($data['papers'][$exam['paper_id']]['prevFullScore']) && $data['papers'][$exam['paper_id']]['prevFullScore'] > 0) {
  809. $data['papers'][$exam['paper_id']]['prevAvgRate'] = number_format($prevQuery['total_score'] / ($prevQuery['total_num'] * $data['papers'][$exam['paper_id']]['prevFullScore']), 4) * 100;
  810. }
  811. }
  812. }
  813. }
  814. unset($query);
  815. // 参加考试人数、平均得分率、平均分、及格率、最高分、最低分
  816. if(empty($codeNow)){
  817. $query = $this->sConn->createCommand("
  818. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  819. FROM student_paper_relation
  820. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  821. GROUP BY paper_id
  822. ")->queryAll();
  823. }else{
  824. $query = $this->sConn->createCommand("
  825. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  826. FROM student_paper_relation_".$codeNow."
  827. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  828. GROUP BY paper_id
  829. ")->queryAll();
  830. }
  831. if ($query) {
  832. foreach ($query as $k => $v) {
  833. $data['papers'][$v['paper_id']]['totalNum'] = $v['total_num'];
  834. $data['papers'][$v['paper_id']]['totalScore'] = $v['total_score'];
  835. $data['papers'][$v['paper_id']]['maxScore'] = $v['max_score'];
  836. $data['papers'][$v['paper_id']]['minScore'] = $v['min_score'];
  837. $data['papers'][$v['paper_id']]['avgScore'] = 0;
  838. $data['papers'][$v['paper_id']]['avgRate'] = 0;
  839. $data['papers'][$v['paper_id']]['avgFluctuate'] = 0;
  840. if ($v['total_num'] > 0) {
  841. $data['papers'][$v['paper_id']]['avgScore'] = number_format($v['total_score'] / $v['total_num'], 2);
  842. if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
  843. $data['papers'][$v['paper_id']]['avgRate'] = number_format($v['total_score'] / ($v['total_num'] * $data['papers'][$exam['paper_id']]['fullScore']), 4) * 100;
  844. if (isset($data['papers'][$v['paper_id']]['prevAvgRate'])) {
  845. $data['papers'][$v['paper_id']]['avgFluctuate'] = number_format($data['papers'][$v['paper_id']]['avgRate'] - $data['papers'][$v['paper_id']]['prevAvgRate'], 2);
  846. }
  847. }
  848. }
  849. }
  850. }
  851. unset($query);
  852. // 单题班级情况
  853. if(empty($codeNow)){
  854. $sql = "
  855. SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score, sptr.handlerIndex
  856. FROM student_paper_topic_rs sptr
  857. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
  858. //WHERE sptr.handlerIndex = '1'";
  859. }else{
  860. $sql = "
  861. SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score, sptr.handlerIndex
  862. FROM student_paper_topic_rs_".$codeNow." sptr
  863. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
  864. //WHERE sptr.handlerIndex = '1'";
  865. }
  866. $sql.="AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")";
  867. $query = $this->sConn->createCommand($sql)->queryAll();
  868. $class_topic_score = array();
  869. $topic_score_arr = array();
  870. if ($query) {
  871. $data['papers'][$v['paper_id']]['topics'] = array();
  872. foreach ($query as $k => $v) {
  873. if (!isset($data['papers'][$v['paper_id']]['topics'][$v['topic_id']])) {
  874. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']] = array();
  875. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
  876. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
  877. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
  878. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
  879. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] = 0;
  880. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
  881. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'] = array();
  882. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'] = array();//得分率低于70%的,选择题错的
  883. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['classRate'] = 0;
  884. }
  885. $topic_score_arr[$v['topic_id']] = $v['score'];
  886. //班级得分
  887. if (!isset($class_topic_score[$v['paper_id']])) {
  888. $class_topic_score[$v['paper_id']] = array();
  889. }
  890. if (!isset($class_topic_score[$v['paper_id']][$v['topic_id']])) {
  891. $class_topic_score[$v['paper_id']][$v['topic_id']] = array();
  892. }
  893. $class_topic_score[$v['paper_id']][$v['topic_id']][] = $v['scoring'];
  894. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
  895. if ($v['is_right'] == 1) {
  896. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] ++;
  897. } else {
  898. if($v["handlerIndex"]==1){
  899. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong'] ++;
  900. }
  901. }
  902. if($v["handlerIndex"]==1){
  903. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
  904. }
  905. if ($v['score'] && ($v['scoring']/$v['score'] < 0.7 && $v["handlerIndex"]==1)) {
  906. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'][] = $v['student_id'];
  907. }
  908. }
  909. }
  910. unset($query);
  911. // 缺考人数
  912. if(empty($codeNow)){
  913. $query = $this->sConn->createCommand("
  914. SELECT paper_id, COUNT(student_id) AS absent_num
  915. FROM student_paper_relation
  916. WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  917. GROUP BY paper_id
  918. ")->queryAll();
  919. }else{
  920. $query = $this->sConn->createCommand("
  921. SELECT paper_id, COUNT(student_id) AS absent_num
  922. FROM student_paper_relation_".$codeNow."
  923. WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  924. GROUP BY paper_id
  925. ")->queryAll();
  926. }
  927. if ($query) {
  928. foreach ($query as $k => $v) {
  929. $data['papers'][$v['paper_id']]['absentNum'] = $v['absent_num'];
  930. }
  931. }
  932. unset($query);
  933. // 及格率
  934. if(empty($codeNow)){
  935. $query = $this->sConn->createCommand("
  936. SELECT paper_id, student_id, scoring
  937. FROM student_paper_relation
  938. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  939. ")->queryAll();
  940. }else{
  941. $query = $this->sConn->createCommand("
  942. SELECT paper_id, student_id, scoring
  943. FROM student_paper_relation_".$codeNow."
  944. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  945. ")->queryAll();
  946. }
  947. if ($query) {
  948. foreach ($query as $k => $v) {
  949. if (!isset($data['papers'][$exam['paper_id']]['passNum'])) {
  950. $data['papers'][$exam['paper_id']]['passNum'] = 0;
  951. $data['papers'][$exam['paper_id']]['passNum_90'] = 0;
  952. }
  953. if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
  954. if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.6) {
  955. $data['papers'][$exam['paper_id']]['passNum'] ++;
  956. }
  957. if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.9) {
  958. $data['papers'][$exam['paper_id']]['passNum_90'] ++;
  959. }
  960. }
  961. }
  962. unset($query);
  963. }
  964. foreach ($data['paperIds'] as $paperId) {
  965. if (!isset($data['papers'][$exam['paper_id']]['passRate'])) {
  966. $data['papers'][$exam['paper_id']]['passRate'] = 0;
  967. }
  968. if (isset($data['papers'][$v['paper_id']]['totalNum']) && $data['papers'][$v['paper_id']]['totalNum'] > 0 && isset($data['papers'][$exam['paper_id']]['passNum'])) {
  969. $data['papers'][$exam['paper_id']]['passRate'] = number_format($data['papers'][$exam['paper_id']]['passNum'] / $data['papers'][$v['paper_id']]['totalNum'], 4) * 100;
  970. }
  971. }
  972. $prevQuery = array();
  973. if ($data['prevPaperIds']) {
  974. // 上次考试排名
  975. if(empty($codePrev)){
  976. $prevQuery = $this->sConn->createCommand("
  977. SELECT paper_id, student_id, scoring
  978. FROM student_paper_relation
  979. WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
  980. ORDER BY paper_id ASC, scoring DESC
  981. ")->queryAll();
  982. }else{
  983. $prevQuery = $this->sConn->createCommand("
  984. SELECT paper_id, student_id, scoring
  985. FROM student_paper_relation_".$codePrev."
  986. WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
  987. ORDER BY paper_id ASC, scoring DESC
  988. ")->queryAll();
  989. }
  990. }
  991. if ($prevQuery) {
  992. foreach ($prevQuery as $k => $v) {
  993. if (isset($data['prevPapers'][$v['paper_id']])) {
  994. if (!isset($data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'])) {
  995. $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'] = array();
  996. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'] = array();
  997. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] = 0;
  998. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  999. }
  1000. if (!isset($prevRank[$data['prevPapers'][$v['paper_id']]])) {
  1001. $prevRank[$data['prevPapers'][$v['paper_id']]] = 0;
  1002. }
  1003. if ($data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] > 0) {
  1004. if ($v['scoring'] == $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][$data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] - 1][1]) {
  1005. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] ++;
  1006. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  1007. $v['student_id'],
  1008. $v['scoring'],
  1009. $prevRank[$data['prevPapers'][$v['paper_id']]]
  1010. );
  1011. } else {
  1012. $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
  1013. $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
  1014. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  1015. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  1016. $v['student_id'],
  1017. $v['scoring'],
  1018. $prevRank[$data['prevPapers'][$v['paper_id']]]
  1019. );
  1020. }
  1021. } else {
  1022. $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
  1023. $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
  1024. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  1025. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  1026. $v['student_id'],
  1027. $v['scoring'],
  1028. $prevRank[$data['prevPapers'][$v['paper_id']]]
  1029. );
  1030. }
  1031. $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'][$v['student_id']] = $prevRank[$data['prevPapers'][$v['paper_id']]];
  1032. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] ++;
  1033. }
  1034. }
  1035. unset($prevRank);
  1036. }
  1037. // 本次考试排名
  1038. if(empty($codeNow)){
  1039. $query = $this->sConn->createCommand("
  1040. SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
  1041. FROM student_paper_relation spr
  1042. JOIN student_info si ON si.student_id = spr.student_id
  1043. WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
  1044. ORDER BY spr.paper_id ASC, spr.scoring DESC
  1045. ")->queryAll();
  1046. }else{
  1047. $query = $this->sConn->createCommand("
  1048. SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
  1049. FROM student_paper_relation_".$codeNow." spr
  1050. JOIN student_info si ON si.student_id = spr.student_id
  1051. WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
  1052. ORDER BY spr.paper_id ASC, spr.scoring DESC
  1053. ")->queryAll();
  1054. }
  1055. $studentNames = array();
  1056. if ($query) {
  1057. foreach ($query as $k => $v) {
  1058. if (!isset($data['papers'][$v['paper_id']]['ranks'])) {
  1059. $data['papers'][$v['paper_id']]['ranks'] = array();
  1060. $data['papers'][$v['paper_id']]['_ranks'] = array();
  1061. $data['papers'][$v['paper_id']]['_i'] = 0;
  1062. $data['papers'][$v['paper_id']]['_j'] = 0;
  1063. }
  1064. if (!isset($rank[$v['paper_id']])) {
  1065. $rank[$v['paper_id']] = 0;
  1066. }
  1067. if ($data['papers'][$v['paper_id']]['_i'] > 0) {
  1068. if ($v['scoring'] == $data['papers'][$v['paper_id']]['_ranks'][$data['papers'][$v['paper_id']]['_i'] - 1][1]) {
  1069. $data['papers'][$v['paper_id']]['_j'] ++;
  1070. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  1071. $v['student_id'],
  1072. $v['scoring'],
  1073. $rank[$v['paper_id']]
  1074. );
  1075. } else {
  1076. $rank[$v['paper_id']] ++;
  1077. $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
  1078. $data['papers'][$v['paper_id']]['_j'] = 0;
  1079. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  1080. $v['student_id'],
  1081. $v['scoring'],
  1082. $rank[$v['paper_id']]
  1083. );
  1084. }
  1085. } else {
  1086. $rank[$v['paper_id']] ++;
  1087. $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
  1088. $data['papers'][$v['paper_id']]['_j'] = 0;
  1089. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  1090. $v['student_id'],
  1091. $v['scoring'],
  1092. $rank[$v['paper_id']]
  1093. );
  1094. }
  1095. $data['papers'][$v['paper_id']]['ranks'][] = array(
  1096. 'studentId' => $v['student_id'],
  1097. 'realname' => $v['realname'],
  1098. 'rank' => $rank[$v['paper_id']],
  1099. );
  1100. $data['papers'][$v['paper_id']]['_i'] ++;
  1101. $studentNames[$v['student_id']] = $v['realname'];
  1102. }
  1103. unset($rank);
  1104. }
  1105. //班级得分率
  1106. $class_topic_rate = array();
  1107. if ($class_topic_score) {
  1108. foreach ($class_topic_score as $_p_id => $t_id_scoring) {
  1109. if (!isset($class_topic_rate[$_p_id])) {
  1110. $class_topic_rate[$_p_id] = array();
  1111. }
  1112. foreach ($t_id_scoring as $_t_id => $_t_scoring) {
  1113. if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
  1114. $class_topic_rate[$_p_id][$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
  1115. }else{
  1116. $class_topic_rate[$_p_id][$_t_id] = 0;
  1117. }
  1118. }
  1119. }
  1120. }
  1121. unset($class_topic_score);
  1122. //得分率低于70%的,选择题错的对应的学生名称
  1123. if($studentNames && isset($data['papers']) && isset($data['papers'][$v['paper_id']]['topics'])){
  1124. foreach ($data['papers'] as $pId => $_topics){
  1125. foreach ($_topics['topics'] as $tId => $less70) {
  1126. foreach ($less70['rateLess70'] as $lessk => $stuId) {
  1127. if (isset($studentNames[$stuId])) {
  1128. $data['papers'][$pId]['topics'][$tId]['rateLess70'][$lessk] = $studentNames[$stuId];
  1129. }
  1130. }
  1131. $data['papers'][$pId]['topics'][$tId]['classRate'] = isset($class_topic_rate[$pId]) && isset($class_topic_rate[$pId][$tId])?$class_topic_rate[$pId][$tId]:0;
  1132. }
  1133. }
  1134. }
  1135. $data['studentNames'] = $studentNames;
  1136. unset($studentNames);
  1137. // 大幅进步、大幅度退步
  1138. foreach ($data['papers'] as $key => $val) {
  1139. if (isset($val['prevRanks']) && isset($val['ranks'])) {
  1140. foreach ($val['ranks'] as $k => $v) {
  1141. if (isset($val['prevRanks'][$v['studentId']])) {
  1142. // 进步
  1143. if (!isset($data['papers'][$key]['forwards'])) {
  1144. $data['papers'][$key]['forwards'] = array();
  1145. }
  1146. if ($val['prevRanks'][$v['studentId']] - $v['rank'] > 0) {
  1147. if (!isset($data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']])) {
  1148. $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']] = array();
  1149. }
  1150. $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']][] = array(
  1151. 'studentId' => $v['studentId'],
  1152. 'realname' => $v['realname'],
  1153. 'rank' => $v['rank'],
  1154. 'prevRank' => $val['prevRanks'][$v['studentId']]
  1155. );
  1156. }
  1157. // 退步
  1158. if (!isset($data['papers'][$key]['rewinds'])) {
  1159. $data['papers'][$key]['rewinds'] = array();
  1160. }
  1161. if ($v['rank'] - $val['prevRanks'][$v['studentId']] > 0) {
  1162. if (!isset($data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]])) {
  1163. $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]] = array();
  1164. }
  1165. $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]][] = array(
  1166. 'studentId' => $v['studentId'],
  1167. 'realname' => $v['realname'],
  1168. 'rank' => $v['rank'],
  1169. 'prevRank' => $val['prevRanks'][$v['studentId']]
  1170. );
  1171. }
  1172. }
  1173. }
  1174. if (isset($data['papers'][$key]['forwards'])) {
  1175. krsort($data['papers'][$key]['forwards'], SORT_NUMERIC);
  1176. }
  1177. if (isset($data['papers'][$key]['rewinds'])) {
  1178. krsort($data['papers'][$key]['rewinds'], SORT_NUMERIC);
  1179. }
  1180. }
  1181. if (isset($val['topics'])) {
  1182. foreach ($val['topics'] as $k => $v) {
  1183. if (count($v['studentIds']) > 0) {
  1184. $data['papers'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
  1185. if (isset($data['papers'][$key]['topics'][$k]['fullScore']) && $data['papers'][$key]['topics'][$k]['fullScore'] > 0) {
  1186. $data['papers'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['papers'][$key]['topics'][$k]['fullScore']), 4) * 100;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. unset($query);
  1193. // 考试情况分析
  1194. if(empty($codeNow)){
  1195. $query = $this->sConn->createCommand("
  1196. SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id, ptr.stem_id,ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer
  1197. ,sptr.handlerIndex
  1198. FROM student_paper_topic_rs sptr
  1199. JOIN student_paper_relation spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
  1200. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
  1201. JOIN paper p ON p.paper_id = ptr.paper_id
  1202. JOIN exam e ON e.exam_id = p.exam_id
  1203. WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
  1204. ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
  1205. ")->queryAll();
  1206. }else{
  1207. $query = $this->sConn->createCommand("
  1208. SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id, ptr.stem_id,ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer
  1209. ,sptr.handlerIndex
  1210. FROM student_paper_topic_rs_".$codeNow." sptr
  1211. JOIN student_paper_relation_".$codeNow." spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
  1212. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
  1213. JOIN paper p ON p.paper_id = ptr.paper_id
  1214. JOIN exam e ON e.exam_id = p.exam_id
  1215. WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
  1216. ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
  1217. ")->queryAll();
  1218. }
  1219. if($is_qxk){
  1220. $qxkKnowledge = SPaperTopicRelation::newKnowledgeRelate();//获取全学科知识点对应老知识点的关系
  1221. }
  1222. if ($query) {
  1223. //转换试卷中每道题目的序号
  1224. $paperNos = $this->transferOrders($data['paperIds'],$is_qxk);
  1225. //计算出每道必做题 做了的人数
  1226. foreach($query as $k => $v){
  1227. if (!isset($data['papers'][$v['paper_id']]['doTopicNums'])) {//每道必做题 做了的人数
  1228. $data['papers'][$v['paper_id']]['doTopicNums'] = array();
  1229. }
  1230. if (!isset($data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']])) {
  1231. $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] = 0;
  1232. }
  1233. if ($v["handlerIndex"] == 1) {
  1234. $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] ++;
  1235. }
  1236. }
  1237. foreach ($query as $k => $v) {
  1238. if($v['stem_id']){
  1239. $new_topic_id = (string)$v['stem_id'];
  1240. }else{
  1241. $new_topic_id = (string)$v['topic_id'];
  1242. }
  1243. //客观题答案明细
  1244. if($v['type'] == 1 && !$score_type){//单选题
  1245. if(!isset($data['answer_score_details'][$v['topic_id']])){
  1246. $data['answer_score_details'][$v['topic_id']] = array();
  1247. $data['answer_score_details'][$v['topic_id']]['answer'] = '';
  1248. $data['answer_score_details'][$v['topic_id']]['option']['A'] = 0;
  1249. $data['answer_score_details'][$v['topic_id']]['option']['B'] = 0;
  1250. $data['answer_score_details'][$v['topic_id']]['option']['C'] = 0;
  1251. $data['answer_score_details'][$v['topic_id']]['option']['D'] = 0;
  1252. $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
  1253. }
  1254. if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v['answer']])){
  1255. $data['answer_score_details'][$v['topic_id']]['option'][$v['answer']]++;
  1256. }
  1257. }
  1258. if((in_array($v['type'],array(2,11)) && !$score_type ) ||($is_qxk && $v['type']==3)){//多选不定项
  1259. $v_answer = str_replace(',','',$v['answer']);
  1260. if(!isset($data['answer_score_details'][$v['topic_id']])){
  1261. $data['answer_score_details'][$v['topic_id']] = array();
  1262. $data['answer_score_details'][$v['topic_id']]['answer'] = '';
  1263. $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
  1264. }
  1265. if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v_answer])){
  1266. $data['answer_score_details'][$v['topic_id']]['option'][$v_answer]++;
  1267. }else{
  1268. $data['answer_score_details'][$v['topic_id']]['option'][$v_answer] = 1;
  1269. }
  1270. }
  1271. if (!isset($data['papers'][$v['paper_id']]['errorNums'])) {
  1272. $data['papers'][$v['paper_id']]['errorNums'] = array();
  1273. }
  1274. if (!isset($data['papers'][$v['paper_id']]['errorNums'][$v['no']])) {
  1275. $data['papers'][$v['paper_id']]['errorNums'][$v['no']] = 0;
  1276. }
  1277. if ($v['is_right'] != 1 && $v["handlerIndex"] ==1) {
  1278. $data['papers'][$v['paper_id']]['errorNums'][$v['no']] ++;
  1279. }
  1280. if (!in_array((string)$new_topic_id, $data['topicIds'],true)) {
  1281. $data['topicIds'][] = $new_topic_id;
  1282. }
  1283. if (!in_array((string)$v['topic_id'], $data['noTopicIds'],true)) {
  1284. $data['noTopicIds'][] = (string)$v['topic_id'];
  1285. }
  1286. if (!isset($data['papers'][$v['paper_id']]['topicIds'])) {
  1287. $data['papers'][$v['paper_id']]['topicIds'] = array();
  1288. }
  1289. if (!isset($data['papers'][$v['paper_id']]['noTopicIds'])) {
  1290. $data['papers'][$v['paper_id']]['noTopicIds'] = array();
  1291. }
  1292. if (!in_array($new_topic_id, $data['papers'][$v['paper_id']]['topicIds'],true)) {
  1293. $data['papers'][$v['paper_id']]['topicIds'][] = $new_topic_id;
  1294. }
  1295. if (!in_array((string)$v['topic_id'], $data['papers'][$v['paper_id']]['noTopicIds'],true)) {
  1296. $data['papers'][$v['paper_id']]['noTopicIds'][] = (string)$v['topic_id'];
  1297. }
  1298. if (!isset($data['papers'][$v['paper_id']]['topicNos'])) {
  1299. $data['papers'][$v['paper_id']]['topicNos'] = array();
  1300. }
  1301. $data['papers'][$v['paper_id']]['topicNos'][$v['topic_id']] = $v['no'];
  1302. //带选做题的新序号
  1303. if (!isset($data['papers'][$v['paper_id']]['newTopicNos'])) {
  1304. $data['papers'][$v['paper_id']]['newTopicNos'] = array();
  1305. }
  1306. $data['papers'][$v['paper_id']]['newTopicNos'][$v['topic_id']] = isset($paperNos[$v['paper_id']][$v['topic_id']])?$paperNos[$v['paper_id']][$v['topic_id']]:$v['no'];
  1307. if (!isset($data['examGroups'][$v['exam_group_id']]['topicIds'])) {
  1308. $data['examGroups'][$v['exam_group_id']]['topicIds'] = array();
  1309. }
  1310. if (!in_array($v['topic_id'], $data['examGroups'][$v['exam_group_id']]['topicIds'])) {
  1311. $data['examGroups'][$v['exam_group_id']]['topicIds'][] = $v['topic_id'];
  1312. }
  1313. if (!isset($data['examGroups'][$v['exam_group_id']]['rules'])) {
  1314. $data['examGroups'][$v['exam_group_id']]['rules'] = array();
  1315. }
  1316. $ruleMethodIds = $v['method_ids'];
  1317. $ruleType =(in_array($v['type'], array(17, 27)) ? 7 : $v['type']);
  1318. if($is_qxk && $v["method_ids"]){//如果是全学科的考试转变成老知识点
  1319. $methodIds = explode(',', $v['method_ids']);
  1320. $ruleMethodIds = array();
  1321. foreach($methodIds as $methodId){
  1322. if(isset($qxkKnowledge[$methodId])){
  1323. $ruleMethodIds = array_merge($ruleMethodIds,$qxkKnowledge[$methodId]);
  1324. }
  1325. }
  1326. $ruleMethodIds = empty($ruleMethodIds)?"":join(",",$ruleMethodIds);
  1327. $ruleType = 8;
  1328. }
  1329. $data['examGroups'][$v['exam_group_id']]['rules'][$v['topic_id']] = array(
  1330. 'num' => 1,
  1331. 'difficulty' => $v['method_difficulty'],
  1332. 'type' => $ruleType,
  1333. 'inMethodIds' => $ruleMethodIds,
  1334. 'eqMethodIds' => $ruleMethodIds,
  1335. 'callback' => $v['topic_id'],
  1336. );
  1337. $no = $paperNos[$v['paper_id']][$v['topic_id']];
  1338. if ($v['method_ids'] && $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']]) {
  1339. $methodIds = explode(',', $v['method_ids']);
  1340. foreach ($methodIds as $methodId) {
  1341. if (!in_array($methodId, $data['methodIds'])) {
  1342. $data['methodIds'][] = $methodId;
  1343. }
  1344. if (!isset($data['papers'][$v['paper_id']]['methodNos'])) {
  1345. $data['papers'][$v['paper_id']]['methodNos'] = array();
  1346. }
  1347. if (!isset($data['papers'][$v['paper_id']]['methodNos'][$methodId])) {
  1348. $data['papers'][$v['paper_id']]['methodNos'][$methodId] = array();
  1349. }
  1350. if (!in_array($no, $data['papers'][$v['paper_id']]['methodNos'][$methodId]) ) {
  1351. $data['papers'][$v['paper_id']]['methodNos'][$methodId][] = $no;
  1352. }
  1353. if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'])) {
  1354. $data['papers'][$v['paper_id']]['methodErrorNums'] = array();
  1355. }
  1356. if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'][$methodId])) {
  1357. $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] = 0;
  1358. }
  1359. if ($v['is_right'] != 1 && $v['handlerIndex']==1) {
  1360. $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] ++;
  1361. }
  1362. if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'])) {
  1363. $data['papers'][$v['paper_id']]['methodErrorStudents'] = array();
  1364. }
  1365. if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId])) {
  1366. $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId] = array();
  1367. }
  1368. if ($v['is_right'] != 1) {
  1369. if (!in_array($v['student_id'], $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId],true) && $v['handlerIndex']==1) {
  1370. $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId][] = $v['student_id'];
  1371. }
  1372. }
  1373. if (!isset($data['papers'][$v['paper_id']]['methodFullScores'])) {
  1374. $data['papers'][$v['paper_id']]['methodFullScores'] = array();
  1375. }
  1376. if (!isset($data['papers'][$v['paper_id']]['methodFullScores'][$methodId])) {
  1377. $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] = 0;
  1378. }
  1379. $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] += $v['score'];
  1380. if (!isset($data['papers'][$v['paper_id']]['methodScores'])) {
  1381. $data['papers'][$v['paper_id']]['methodScores'] = array();
  1382. }
  1383. if (!isset($data['papers'][$v['paper_id']]['methodScores'][$methodId])) {
  1384. $data['papers'][$v['paper_id']]['methodScores'][$methodId] = 0;
  1385. }
  1386. $data['papers'][$v['paper_id']]['methodScores'][$methodId] += $v['scoring'];
  1387. }
  1388. }
  1389. }
  1390. foreach ($data['papers'] as $key => $val) {
  1391. if (isset($val['errorNums'])) {
  1392. //重置题号
  1393. $i = 1;
  1394. $newErrorNums = array();
  1395. foreach($val['errorNums'] as $k => $v){
  1396. $newErrorNums[$i] = $v;
  1397. $i++;
  1398. }
  1399. if($newErrorNums){
  1400. $val['errorNums'] = $newErrorNums;
  1401. $data['papers'][$key]['errorNums'] = $newErrorNums;
  1402. }
  1403. foreach ($val['errorNums'] as $k => $v) {
  1404. if (!isset($data['papers'][$key]['errorRates'])) {
  1405. $data['papers'][$key]['errorRates'] = array();
  1406. }
  1407. if ($data['papers'][$key]['totalNum'] > 0) {
  1408. $data['papers'][$key]['errorRates'][$k] = number_format($data['papers'][$key]['errorNums'][$k] / $data['papers'][$key]['totalNum'], 4) * 100;
  1409. } else {
  1410. $data['papers'][$key]['errorRates'][$k] = 0;
  1411. }
  1412. }
  1413. }
  1414. }
  1415. }
  1416. } else {
  1417. echo json_encode(array("status" => 1, "error" => "文件尚未生成"));
  1418. exit;
  1419. }
  1420. if ($data['wb_isp_version'] != 1 || $isFromPast) { //个性化版
  1421. if (isset($data['examGroups']) && $data['examGroups'] && is_array($data['examGroups'])) {
  1422. // 抽题
  1423. foreach ($data['examGroups'] as $key => $val) {
  1424. if($same_bs_data){
  1425. $data['examGroups'][$key]['fcTopicIds'] = array();
  1426. $data['examGroups'][$key]['fcCallbacks'] = array();
  1427. foreach($same_bs_data as $sa_k=>$sa_v){
  1428. $has_topic_gaokao[] = $sa_k;
  1429. foreach($sa_v as $sa_v_topic){
  1430. $has_topic_gaokao[] = $sa_v_topic;
  1431. $data['examGroups'][$key]['fcTopicIds'][] = $sa_v_topic;
  1432. $data['examGroups'][$key]['fcCallbacks'][$sa_k][] = $sa_v_topic;
  1433. if (!in_array((string)$sa_v_topic, $data['fcTopicIds'])) {
  1434. $data['fcTopicIds'][] = (string)$sa_v_topic;
  1435. }
  1436. }
  1437. }
  1438. }else{
  1439. if($labelled_type == 2){//教师端标注抽题
  1440. $data['examGroups'][$key]['fcTopicIds'] = array();
  1441. $data['examGroups'][$key]['fcCallbacks'] = array();
  1442. $sql = "select topic_id,relation_id from exam_topic_label where exam_group_id = '{$key}'";
  1443. $etl_data = $this->sConn->createCommand($sql)->queryAll();
  1444. if($etl_data){
  1445. foreach($etl_data as $etl_data_v){
  1446. if($etl_data_v['topic_id'] && $etl_data_v['relation_id']){
  1447. $relation_topic_arr = explode(",",$etl_data_v['relation_id']);
  1448. foreach($relation_topic_arr as $relation_topic_v){
  1449. if (!in_array((string)$relation_topic_v, $data['fcTopicIds'])) {
  1450. $data['fcTopicIds'][] = (string)$relation_topic_v;
  1451. }
  1452. $data['examGroups'][$key]['fcTopicIds'][] = $relation_topic_v;
  1453. $data['examGroups'][$key]['fcCallbacks'][$etl_data_v['topic_id']][] = $relation_topic_v;
  1454. $has_topic_gaokao[] = $relation_topic_v;
  1455. }
  1456. $has_topic_gaokao[] = $etl_data_v['topic_id'];
  1457. }
  1458. }
  1459. }
  1460. }else{
  1461. if (isset($val['rules'])) {
  1462. $fc = $this->apiPost('/isp/ai', array(
  1463. 'schoolId' => $this->schoolId,
  1464. 'rules' => $val['rules'],
  1465. 'notInTopicIds' => $data['examGroups'][$key]['topicIds'],
  1466. ));
  1467. if ($fc && !isset($fc->error)) {
  1468. $data['examGroups'][$key]['fcTopicIds'] = array();
  1469. $data['examGroups'][$key]['fcCallbacks'] = array();
  1470. foreach ($fc as $k => $v) {
  1471. if (!in_array($v->id, $data['fcTopicIds'])) {
  1472. $data['fcTopicIds'][] = $v->id;
  1473. }
  1474. $data['examGroups'][$key]['fcTopicIds'][] = $v->id;
  1475. $data['examGroups'][$key]['fcCallbacks'][$v->callback][] = $v->id;
  1476. $has_topic_gaokao[] = $v->id;
  1477. $has_topic_gaokao[] = $v->callback;
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. $topicDetails=array();
  1485. $topicItems_1 = $this->apiPost('/topic/batchAll', array('topicIds' => array_merge(
  1486. $data['topicIds'],
  1487. (isset($data['fcTopicIds']) ? $data['fcTopicIds'] : array())
  1488. )));
  1489. if (isset($topicItems_1->error)) {
  1490. $error[] = $topicItems_1->error;
  1491. } elseif (! $topicItems_1) {
  1492. $error[] = 'Error in pumping system[2]';
  1493. } else {
  1494. foreach ($topicItems_1 as $topicItem) {
  1495. $topicDetails[(string)$topicItem->id] = (object)$topicItem;
  1496. }
  1497. }
  1498. // $topicItems = $this->apiPost('/topic/batch',
  1499. // array('topicIds' => array_merge(
  1500. // $data['topicIds'],
  1501. // (isset($data['fcTopicIds']) ? $data['fcTopicIds'] : array())
  1502. // )));
  1503. //
  1504. // if (isset($topicItems->error)) {
  1505. // $error[] = $topicItems->error;
  1506. // } elseif (! $topicItems) {
  1507. // $error[] = 'Error in pumping system[2]';
  1508. // } else {
  1509. // foreach ($topicItems as $topicItem) {
  1510. // $topicDetails[$topicItem->id] = (object)$topicItem;
  1511. // }
  1512. // }
  1513. // if($data['topicIds']){
  1514. // $condition = "topic_id IN (". implode(',', $data['topicIds']) .")";
  1515. // $topicItems_1 = STopic::model()->getRecords($condition, 0, 100, $exam_info['teacher_id'], true);
  1516. // }
  1517. // if ($topicItems_1) {
  1518. // foreach ($topicItems_1 as $topicItem_1) {
  1519. // $topicDetails[$topicItem_1['id']] = (object)$topicItem_1;
  1520. // }
  1521. // }
  1522. if ($topicDetails) {
  1523. foreach ($topicDetails as $k => $v) {
  1524. $v=(array)$v;
  1525. $v['id'] = (string)$v['id'];
  1526. $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
  1527. if(!$teacher_tips){
  1528. $teacher_tips = $this->dealTeacherTips($v);
  1529. }
  1530. $v['teacher_tips'] = $this->topicProcess($teacher_tips);
  1531. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  1532. if($v['type_id'] == 5){
  1533. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  1534. }
  1535. $v['title'] = $this->topicProcess($v['title']);
  1536. if(isset($v['items'][0])){
  1537. $v['items'][0]=(array)$v['items'][0];
  1538. $v['items'][0]['options']=(array)$v['items'][0]['options'];
  1539. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  1540. foreach ($v['items'][0]['options'] as $key => $val) {
  1541. $val=(array)$val;
  1542. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  1543. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  1544. if(isset($data['answer_score_details'][$v['id']]) && $val['option_correct'] == 1){
  1545. $data['answer_score_details'][$v['id']]['answer'] .= $this->numToLetter($key + 1);
  1546. }
  1547. }
  1548. }
  1549. }
  1550. $data['topicDetails'][$v['id']] = $v;
  1551. }
  1552. unset($topicDetails);
  1553. }
  1554. }
  1555. } else { //分层版
  1556. //获取原题以及对应四个层次的提分题
  1557. //$preparation_plan_id = $exam['preparation_plan_id'];
  1558. if($data['level_rule'] == 1){
  1559. $isDiffMin = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId." and is_diff_min = 1")->queryAll();
  1560. if($isDiffMin){
  1561. $plan_topic_res = $isDiffMin;
  1562. }else{
  1563. $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
  1564. if($plan_topic_res){
  1565. $topicsOrigin = array();
  1566. $topicRelation = array();
  1567. foreach($plan_topic_res as $k=>$v){
  1568. $topicsOrigin[] = $v['template_id'];
  1569. $topicRelation[$v['template_id']][] = $v;
  1570. $has_topic_gaokao[] =$v['template_id'];
  1571. $has_topic_gaokao[] =$v['topic_id'];
  1572. }
  1573. if($topicsOrigin){
  1574. $topicsOrigin = array_unique($topicsOrigin);
  1575. $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicsOrigin));
  1576. if (!$topicDetails) {
  1577. echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
  1578. exit();
  1579. } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
  1580. echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
  1581. exit();
  1582. }
  1583. $topicDiff = array();
  1584. foreach($topicDetails as $k=>$v){
  1585. if(isset($v['difficulty_degree'])){
  1586. $diff = $v['difficulty_degree'];
  1587. }elseif(isset($v['experience_degree'])){
  1588. $diff = $v['experience_degree'];
  1589. }else{
  1590. $diff = 0;
  1591. }
  1592. $topicDiff[$v['id']] = $diff;
  1593. }
  1594. $new_plan_topic_res = array();
  1595. foreach($topicDiff as $k=>$v){
  1596. if(isset($topicRelation[$k])){
  1597. $arr1 = array();
  1598. $arr2 = array();
  1599. foreach($topicRelation[$k] as $relation){
  1600. $arr1[] = $relation['difficulty_degree'];
  1601. }
  1602. $x=$v;
  1603. $count=count($arr1);
  1604. for ($i=0; $i <$count ; $i++) {
  1605. $arr2[]=abs($x-$arr1[$i]);
  1606. }
  1607. $min= min($arr2);
  1608. for ($i=0; $i <$count ; $i++) {
  1609. if ($min==$arr2[$i]) {
  1610. $new_plan_topic_res[] = $topicRelation[$k][$i];
  1611. break 1;
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. $plan_topic_res = $new_plan_topic_res;
  1618. }
  1619. }
  1620. }else{
  1621. $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
  1622. }
  1623. if (!$plan_topic_res) {
  1624. echo json_encode(array("status" => 1, "error" => "文件尚未生成"));
  1625. exit;
  1626. }
  1627. $template_topic_arr = array();
  1628. $isp_id_arr = array();
  1629. foreach ($plan_topic_res as $v) {
  1630. $template_id = $v['template_id'];
  1631. $level = $v['level'];
  1632. $topic_id = $v['topic_id'];
  1633. if (!isset($template_topic_arr[$template_id])) {
  1634. $template_topic_arr[$template_id] = array();
  1635. }
  1636. $template_topic_arr[$template_id][$level] = $topic_id;
  1637. $isp_id_arr[] = $topic_id;
  1638. }
  1639. //试卷中校本题库题是哪些,云题库题是哪些
  1640. $sch_id_arr = array(); //试卷中校本题库题是哪些
  1641. $yun_id_arr = array();
  1642. $sql = 'select topic_id,mode,type,no from paper_topic_relation ptr join paper p on p.paper_id = ptr.paper_id where p.exam_id=' . $examId;
  1643. $paper_topic_res = $this->sConn->createCommand($sql)->queryAll();
  1644. if (!$paper_topic_res) {
  1645. echo json_encode(array("status" => 1, "error" => "文件尚未生成"));
  1646. exit;
  1647. }
  1648. $topic_no_arr = $this->getTopicNoByPaper($paper_topic_res, $exam['tpl_index']); //获取每道题在试卷中的序号,如 21A,21B
  1649. foreach ($paper_topic_res as $v) {
  1650. $v['mode'] == 1 && $sch_id_arr[] = $v['topic_id'];
  1651. $v['mode'] == 0 && $yun_id_arr [] = $v['topic_id'];
  1652. }
  1653. $isp_id_arr = array_merge($isp_id_arr, $yun_id_arr);
  1654. //获取所有以上题目的详情,以供显示到教师讲案中
  1655. $topic_detail_arr = $this->paperTopicDetail($isp_id_arr, $sch_id_arr, $examId,'分层提分题');
  1656. if (!$topic_detail_arr) {
  1657. echo json_encode(array("status" => 1, "error" => "获取不到试卷题目内容"));
  1658. exit;
  1659. }
  1660. foreach($topic_detail_arr as $k_topic=>$v_topic){
  1661. if(isset($data['answer_score_details'][(string)$k_topic])){
  1662. $data['answer_score_details'][(string)$k_topic]['answer'] = isset($v_topic['answer_format'])?$v_topic['answer_format']:'';
  1663. }
  1664. }
  1665. $diff_id_arr = array_diff($isp_id_arr + $sch_id_arr, array_keys($topic_detail_arr));
  1666. if ($diff_id_arr) {
  1667. //todo 发送消息到补提
  1668. echo json_encode(array("status" => 1, "error" => "请等待题库老师补题!"));
  1669. exit;
  1670. } else {
  1671. $data['template_topic_arr'] = $template_topic_arr;
  1672. $data['topic_details'] = $topic_detail_arr;
  1673. $data['topic_no_arr'] = $topic_no_arr;
  1674. unset($template_topic_arr);
  1675. unset($topic_detail_arr);
  1676. }
  1677. }
  1678. // 获取考点名称
  1679. if (isset($data['methodIds']) && $data['methodIds']) {
  1680. if($is_qxk){
  1681. $methods = $this->apiPost('/all_knowledge/knowledge_name', array('knowledgeIds' => $data['methodIds']));
  1682. if ($methods && isset($methods->data) && $methods->data) {
  1683. foreach ($methods->data as $k => $v) {
  1684. $data['methodNames'][$k] = $v;
  1685. }
  1686. unset($methods);
  1687. }
  1688. }else{
  1689. $methods = $this->apiPost('/special/methods', array('methodIds' => $data['methodIds']));
  1690. if ($methods) {
  1691. foreach ($methods as $k => $v) {
  1692. $data['methodNames'][$v->method_id] = $v->method_name;
  1693. }
  1694. unset($methods);
  1695. }
  1696. }
  1697. }
  1698. if (isset($data['examGroupIds']) && $data['examGroupIds'] && is_array($data['examGroupIds'])) {
  1699. // 年级单题情况
  1700. // $query = $this->sConn->createCommand("
  1701. // SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id, ptr.score
  1702. // FROM student_paper_topic_rs sptr
  1703. // JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id)
  1704. // JOIN paper p ON p.paper_id = sptr.paper_id
  1705. // JOIN exam e ON e.exam_id = p.exam_id
  1706. // WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") AND sptr.handlerIndex = '1'
  1707. // ")->queryAll();
  1708. ////年级单题情况优化后begining////////////////
  1709. // $sql = "SELECT count(0) as count
  1710. // FROM student_paper_topic_rs sptr
  1711. // JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id)
  1712. // JOIN paper p ON p.paper_id = sptr.paper_id
  1713. // JOIN exam e ON e.exam_id = p.exam_id
  1714. // WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") AND sptr.handlerIndex = '1'";
  1715. // $countNum = $this->sConn->createCommand($sql)->queryRow();
  1716. // $query = array();
  1717. // if($countNum){
  1718. // $num = $countNum['count'];
  1719. // $limit = 10000;
  1720. // $page = ceil($num/$limit);
  1721. // $sql_s = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id, ptr.score
  1722. // FROM student_paper_topic_rs sptr
  1723. // JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id)
  1724. // JOIN paper p ON p.paper_id = sptr.paper_id
  1725. // JOIN exam e ON e.exam_id = p.exam_id
  1726. // WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") AND sptr.handlerIndex = '1'";
  1727. // for($i = 1;$i <= $page ; $i++){
  1728. // $offset = ($i - 1)*$limit;
  1729. // $sql = $sql_s." limit {$offset},{$limit}";
  1730. // if($query){
  1731. // $query_next = $this->sConn->createCommand($sql)->queryAll();
  1732. // if($query_next){
  1733. // foreach($query_next as $k=>$v){
  1734. // array_push($query,$v);
  1735. // }
  1736. // }
  1737. // unset($query_next);
  1738. // }else{
  1739. // $query = $this->sConn->createCommand($sql)->queryAll();
  1740. // }
  1741. // }
  1742. // }
  1743. //////////////ending///////////////
  1744. //////////newbegining
  1745. $this->sConn->active = false;
  1746. $this->sConn = $this->getDbConnection();
  1747. $query = array();
  1748. if(empty($codeNow)){
  1749. $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
  1750. FROM student_paper_topic_rs sptr
  1751. JOIN paper p ON p.paper_id = sptr.paper_id
  1752. JOIN exam e ON e.exam_id = p.exam_id
  1753. WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") ";
  1754. }else{
  1755. $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
  1756. FROM student_paper_topic_rs_".$codeNow." sptr
  1757. JOIN paper p ON p.paper_id = sptr.paper_id
  1758. JOIN exam e ON e.exam_id = p.exam_id
  1759. WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") ";
  1760. }
  1761. $sptrData = $this->sConn->createCommand($sql)->queryAll();
  1762. if($sptrData){
  1763. $paperTopic = array();
  1764. $paperIds = array();
  1765. foreach($sptrData as $k=>$v){
  1766. if(!in_array($v['paper_id'], $paperIds,true)){
  1767. $paperIds[] = $v['paper_id'];
  1768. }
  1769. }
  1770. if($paperIds){
  1771. $sql = "select score,paper_id,topic_id from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")";
  1772. $ptrData = $this->sConn->createCommand($sql)->queryAll();
  1773. if($ptrData){
  1774. foreach($ptrData as $k=>$v){
  1775. $paperTopic[$v['paper_id']][$v['topic_id']] = $v['score'];
  1776. }
  1777. unset($ptrData);
  1778. }
  1779. if($paperTopic){
  1780. foreach($sptrData as $k=>$v){
  1781. if(isset($paperTopic[$v['paper_id']]) && isset($paperTopic[$v['paper_id']][$v['topic_id']])){
  1782. $sptrData[$k]['score'] = $paperTopic[$v['paper_id']][$v['topic_id']];
  1783. }
  1784. }
  1785. $query = $sptrData;
  1786. }
  1787. }
  1788. unset($sptrData);
  1789. }
  1790. /////////newending
  1791. ///
  1792. $grade_topic_score = array();
  1793. if ($query) {
  1794. foreach ($query as $k => $v) {
  1795. if (!isset($data['examGroups'][$v['exam_group_id']]['topics'])) {
  1796. $data['examGroups'][$v['exam_group_id']]['topics'] = array();
  1797. }
  1798. if (!isset($data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']])) {
  1799. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']] = array();
  1800. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
  1801. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
  1802. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
  1803. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
  1804. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] = 0;
  1805. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
  1806. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'] = array();
  1807. }
  1808. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
  1809. if ($v['is_right'] == 1) {
  1810. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] ++;
  1811. } else {
  1812. if($v["handlerIndex"]==1){//必做题
  1813. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong'] ++;
  1814. }
  1815. }
  1816. if($v["handlerIndex"]==1) {//必做题
  1817. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
  1818. }
  1819. //年级得分
  1820. if (!isset($grade_topic_score[$v['topic_id']])) {
  1821. $grade_topic_score[$v['topic_id']] = array();
  1822. }
  1823. $grade_topic_score[$v['topic_id']][] = $v['scoring'];
  1824. }
  1825. foreach ($data['examGroups'] as $key => $val) {
  1826. if (isset($val['topics'])) {
  1827. foreach ($val['topics'] as $k => $v) {
  1828. if (count($v['studentIds']) > 0) {
  1829. $data['examGroups'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
  1830. if (isset($data['examGroups'][$key]['topics'][$k]['fullScore']) && $data['examGroups'][$key]['topics'][$k]['fullScore'] > 0) {
  1831. $data['examGroups'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['examGroups'][$key]['topics'][$k]['fullScore']), 4) * 100;
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. }
  1839. //debug($data);
  1840. $grade_topic_rate = array();
  1841. if ($grade_topic_score) {
  1842. foreach ($grade_topic_score as $_t_id => $_t_scoring) {
  1843. if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
  1844. $grade_topic_rate[$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
  1845. }else{
  1846. $grade_topic_rate[$_t_id] = 0;
  1847. }
  1848. }
  1849. }
  1850. unset($grade_topic_score);
  1851. unset($topic_score_arr);
  1852. //高考真题
  1853. $data['gaokao_topic'] = array();
  1854. if($grade == 3){
  1855. $gaokao_topic = array();
  1856. $sql = "select topic_id from gaokao_academicr_topic where class_id ='{$classId}'";
  1857. $gaokao_data = $this->sConn->createCommand($sql)->queryAll();
  1858. if($gaokao_data){
  1859. foreach($gaokao_data as $gao){
  1860. $gaokao_topic[] = $gao['topic_id'];
  1861. }
  1862. }
  1863. if($gen_origin_methods){
  1864. $weak_methodids = array_keys($gen_origin_methods);
  1865. }else{
  1866. $weak_methodids = array();
  1867. }
  1868. if($paper_method_ids){
  1869. $paper_methodids = explode(",",$paper_method_ids);
  1870. }else{
  1871. $paper_methodids = array();
  1872. }
  1873. if($has_topic_gaokao){
  1874. $has_topic = $has_topic_gaokao;
  1875. }else{
  1876. $has_topic = array();
  1877. }
  1878. $gaokao_topic = $this->acadGaokao($examId,$classId,$has_topic,$weak_methodids,$paper_methodids);
  1879. if($gaokao_topic){
  1880. $topicBatchs = $this->aipost('topic/batchall', array('topicIds' => $gaokao_topic));
  1881. if ($topicBatchs && !isset($topicBatchs->error)) {
  1882. $data['gaokao_topic'] = $this->formatDetails($topicBatchs);
  1883. }
  1884. }
  1885. }
  1886. //整理客观题明细数据
  1887. if($data['answer_score_details']){
  1888. $new_answer_score_details = array();
  1889. $a = 0;
  1890. foreach($data['answer_score_details'] as $k=>$v){
  1891. if(isset($v['option']) && $v['option']){
  1892. foreach($v['option'] as $option_type=>$option_count){
  1893. $new_answer_score_details[$a]['id'] = $k;
  1894. $new_answer_score_details[$a]['order'] = $v['order'];
  1895. $new_answer_score_details[$a]['answer'] = $v['answer']?$v['answer']:'';
  1896. $new_answer_score_details[$a]['option'] = $option_type;
  1897. $new_answer_score_details[$a]['option_count'] = $option_count;
  1898. $a++;
  1899. }
  1900. }
  1901. }
  1902. $data['answer_score_details'] = $new_answer_score_details;
  1903. }
  1904. $this->sConn->active = false; // 关闭连接 close();
  1905. // debug($data);
  1906. if (isset($data['papers']) && $data['papers'] && is_array($data['papers'])) {
  1907. // 渲染
  1908. foreach ($data['papers'] as $key => $val) {
  1909. if (!isset($val['examId']) || !$val['examId'])
  1910. continue;
  1911. if (!isset($val['examGroupId']) || !$val['examGroupId'])
  1912. continue;
  1913. $classname = ClassModel::model()->getClassName($classId);
  1914. $data = array_merge($val, array(
  1915. 'methodNames' => (isset($data['methodNames']) ? $data['methodNames'] : array()),
  1916. 'topicDetails' => (isset($data['topicDetails']) ? $data['topicDetails'] : array()),
  1917. 'groupTopics' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['topics']) ? $data['examGroups'][$val['examGroupId']]['topics'] : array()),
  1918. 'fcCallbacks' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['fcCallbacks']) ? $data['examGroups'][$val['examGroupId']]['fcCallbacks'] : array()),
  1919. 'wb_isp_version' => isset($data['wb_isp_version']) ? $data['wb_isp_version'] : 0,
  1920. 'template_topic_arr' => isset($data['template_topic_arr']) ? $data['template_topic_arr'] : array(),
  1921. 'topic_details' => isset($data['topic_details']) ? $data['topic_details'] : array(),
  1922. 'topic_no_arr' => isset($data['topic_no_arr']) ? $data['topic_no_arr']: array(),
  1923. 'level_rule' => isset($data['level_rule']) ? $data['level_rule'] : 0,
  1924. 'gradeTopicRate' => $grade_topic_rate,
  1925. 'studentNames'=>isset($data['studentNames']) ? $data['studentNames'] : array(),
  1926. 'excellent_solution'=>isset($data['excellent_solution']) ? $data['excellent_solution'] : array(),
  1927. 'gen_topics'=>isset($data['gen_topics']) ? $data['gen_topics'] : array(),
  1928. 'gen_topics_detail'=>isset($data['gen_topics_detail']) ? $data['gen_topics_detail'] : array(),
  1929. 'gen_topics_msg'=>isset($data['gen_topics_msg']) ? $data['gen_topics_msg'] : array(),
  1930. 'answer_score_details'=>isset($data['answer_score_details']) ? $data['answer_score_details'] : array(),
  1931. 'gen_origin_methods'=>isset($data['gen_origin_methods'])?$data['gen_origin_methods']:'',
  1932. 'gaokao_topic'=>isset($data['gaokao_topic'])?$data['gaokao_topic']:array(),
  1933. 'setting_arr'=>isset($setting_arr)?$setting_arr:array(),
  1934. 'grade_topic_data'=>isset($data['grade_topic_data']) ? $data['grade_topic_data'] : array(),
  1935. 'is_qxk'=>$is_qxk,
  1936. )
  1937. );
  1938. $data['className'] = $classname;
  1939. //是否是精准学习宝学校
  1940. $http = http('customer/precision-learning-school/check/'.$this->schoolId, 'GET', $this->authUsername);
  1941. $response = formatResponse($http);
  1942. $data['isPrecise'] = isset($response['data']) ? $response['data'] : 0;
  1943. //教师姓名
  1944. $sql = "select t.teacher_id,t.teacher_name from teacher t join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id where tcr.class_id = '{$class_id}' and tcr.semester_id = '{$semesterId}' and t.subjects=3";
  1945. $teacher_msg = $this->sConn->createCommand($sql)->queryRow();
  1946. if($teacher_msg){
  1947. $data['teacherName'] = $teacher_msg['teacher_name'];
  1948. }
  1949. $html = $this->renderPartial("academicr_1", $data, true);
  1950. //echo 11;exit;
  1951. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径
  1952. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径
  1953. $pdfurl = '/upload/tmpDir/academicr/' . $this->schoolId . "/";
  1954. if (!is_dir($htmlpath)) {
  1955. if (!mkdir($htmlpath, 0777, true)) {
  1956. exit('Create directory fail: ' . $htmlpath);
  1957. }
  1958. }if (!is_dir($pdfpath)) {
  1959. if (!mkdir($pdfpath, 0777, true)) {
  1960. exit('Create directory fail1: ' . $pdfpath);
  1961. }
  1962. }
  1963. $htmlpath.=$examId . ".html";
  1964. $f = fopen($htmlpath, "w");
  1965. fwrite($f, $html);
  1966. fclose($f);
  1967. // echo 11;exit;
  1968. $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
  1969. if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
  1970. $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
  1971. setlocale(LC_ALL,$locale);
  1972. putenv('LC_ALL='.$locale);
  1973. $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
  1974. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  1975. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  1976. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  1977. $pdffname=$classId."-".$examId.".pdf";
  1978. $pdfpath = $pdfpath . $pdffname;
  1979. $pdfurl = $pdfurl . $pdffname;
  1980. $header_str = $this->schoolInfo->school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
  1981. $commond = Yii::app()->params['phantomjs_server'] . " "
  1982. . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
  1983. . " {$htmlurl}"
  1984. . " {$pdfpath}"
  1985. . " 176mm*250mm '{$header_str}'";
  1986. } else {
  1987. $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
  1988. setlocale(LC_ALL,$locale);
  1989. putenv('LC_ALL='.$locale);
  1990. // echo Yii::app()->params['phantomjs'];exit;
  1991. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  1992. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  1993. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  1994. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  1995. $pdffname=$classId."-".$examId.".pdf";
  1996. $pdfpath = $pdfpath . $pdffname;
  1997. $pdfurl = $pdfurl . $pdffname;
  1998. $header_str = $this->schoolInfo->school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
  1999. // $header_str = '';
  2000. $commond = Yii::app()->params['phantomjs_server'] . " "
  2001. . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
  2002. . " {$htmlurl}"
  2003. . " {$pdfpath}"
  2004. . " 176mm*250mm '{$header_str}'";
  2005. }
  2006. exec($commond, $res, $code);
  2007. $ucloud = new Qcloud();
  2008. //上传html
  2009. $rehtml = $examId.".html";
  2010. $rehtmlname = 'zsyas2/math_academicr/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $rehtml;
  2011. $uploadHtmlInfo = $ucloud->putFile($rehtmlname, $htmlpath);
  2012. if($uploadHtmlInfo['status'] == 0){
  2013. $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl;
  2014. }else{
  2015. $html_url = $uploadHtmlInfo['url'];
  2016. @unlink($htmlpath);
  2017. }
  2018. $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url), "exam_id = '{$examId}'");
  2019. if(isset($res[0])){
  2020. if (strpos($res[0], 'succeed') !== false) {//命令返回成功
  2021. if ($this->file_exists($pdfpath)) {
  2022. $repdf = $examId.".pdf";
  2023. $rename = 'zsyas2/math_academicr/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
  2024. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  2025. if ($uploadInfo['status'] == 0) {
  2026. $pdfurl="http://" . $_SERVER['SERVER_NAME'].$pdfurl;
  2027. $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url,"academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  2028. //throw new CException("PDF文件上传失败");
  2029. }else{
  2030. @unlink($pdfpath);
  2031. $pdfurl = $uploadInfo['url'];
  2032. $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url,"academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  2033. }
  2034. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  2035. // $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  2036. // @unlink($htmlpath);
  2037. } else {
  2038. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  2039. // @unlink($htmlpath);
  2040. throw new CException("PDF文件未找到");
  2041. }
  2042. } else {
  2043. // @unlink($htmlpath);
  2044. throw new CException("PDF创建失败");
  2045. }
  2046. }else{
  2047. Curl::post(Yii::app()->params['handle_log_api'], array(
  2048. "exam_group_id" => (string)$val['examGroupId'],
  2049. "operate_project" => 'zsyas2',
  2050. "school_id" => $this->schoolId,
  2051. "title" => '下载教师讲案',
  2052. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2053. "operate_method" => $this->action,
  2054. "operate_url" => $this->getRoute(),
  2055. "operate_sql" => '',
  2056. "operate_param" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$html_url))),
  2057. ));
  2058. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  2059. exit;
  2060. }
  2061. }
  2062. } else {
  2063. throw new CException("系统错误");
  2064. }
  2065. }
  2066. if($this->curlDownloadImage($pdfurl)){
  2067. // if (file_get_contents($pdfurl)) {
  2068. echo json_encode(array("status" => 0, "error" => "","is_create"=>$is_create));
  2069. exit;
  2070. } else {
  2071. echo json_encode(array("status" => 1, "error" => "文件尚未生成!"));
  2072. exit;
  2073. }
  2074. }
  2075. private function getTopicNoByPaper($paper_topcic_relation_arr, $tpl_index)
  2076. {
  2077. $topic_no_arr = array(); //每道题的序号
  2078. if ($tpl_index == 10 || $tpl_index == 1010) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
  2079. $prefix_no = 0;
  2080. $num = 0;
  2081. $index_arr = array('A','B','C','D','E');
  2082. foreach($paper_topcic_relation_arr as $v) {
  2083. if (!$prefix_no && $v['type'] == 17) {
  2084. $prefix_no = $v['no'];
  2085. $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
  2086. } elseif ($prefix_no && $v['type'] == 17) {
  2087. $num += 1;
  2088. $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
  2089. }
  2090. if ($v['type'] == 27) {
  2091. $prefix_no += 1;
  2092. $topic_no_arr[$v['topic_id']] = $prefix_no;
  2093. }
  2094. if ($v['type'] != 17 && $v['type'] != 27){
  2095. $topic_no_arr[$v['topic_id']] = $v['no'];
  2096. }
  2097. }
  2098. } else {
  2099. foreach ($paper_topcic_relation_arr as $v) {
  2100. $topic_no_arr[$v['topic_id']] = $v['no'];
  2101. }
  2102. }
  2103. return $topic_no_arr;
  2104. }
  2105. function get_level_rule($class_id)
  2106. {
  2107. if($class_id){
  2108. $sql = 'select level_rule,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
  2109. $product_res = $this->sConn->createCommand($sql)->queryRow();
  2110. if (!$product_res) { //没有找到班级与设置的关系表
  2111. return 0;
  2112. } else {
  2113. // if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置
  2114. // return 0;
  2115. // } else{
  2116. return $product_res['level_rule'];
  2117. // }
  2118. }
  2119. }
  2120. return 0;
  2121. }
  2122. function get_version($class_id)
  2123. {
  2124. if($class_id){
  2125. $sql = 'select show_level,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
  2126. $product_res = $this->sConn->createCommand($sql)->queryRow();
  2127. if (!$product_res) { //没有找到班级与设置的关系表
  2128. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  2129. $res = $this->sConn->createCommand($sql)->queryRow();
  2130. return $res['wb_isp_version'];
  2131. } else {
  2132. if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置
  2133. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  2134. $res = $this->sConn->createCommand($sql)->queryRow();
  2135. return $res['wb_isp_version'];
  2136. } else{
  2137. return $product_res['show_level'];
  2138. }
  2139. }
  2140. }
  2141. return 0;
  2142. }
  2143. private function check_pdf($pdf_path) {
  2144. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  2145. if (file_exists($pdf_path)) {
  2146. return true;
  2147. }
  2148. }
  2149. return false;
  2150. }
  2151. public function actiondown_load() {
  2152. //旧下载 暂时注释
  2153. /*set_time_limit(0);
  2154. $data = array();
  2155. $time = time();
  2156. $examId = safe_replace(Yii::app()->request->getQuery('examId'));
  2157. $sql = "select c.class_name,e.teacher_id,eg.mark_type,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,e.exam_group_id from exam as e left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id left join `class` as c on c.class_id=e.class_id where e.exam_id={$examId}";
  2158. $exam_info = $this->sConn->createCommand($sql)->queryRow();
  2159. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['academicr_pdf_path'];
  2160. if ($this->check_pdf($pdfpath)) {
  2161. $data['coachId'] = $this->coachId;
  2162. $data['schoolId'] = $this->schoolId;
  2163. $data['examGroupId'] = (string)$exam_info['exam_group_id'];
  2164. $data['examId'] = (string)$examId;
  2165. $data['createTime'] = $time;
  2166. $pushData=json_encode($data);
  2167. @$stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  2168. @$stompconn->send("zsy-task.download-teacher-lecture-data-point", $pushData);
  2169. unset($stompconn);
  2170. Header("Content-type:application/pdf");
  2171. Header("Accept-Ranges: bytes");
  2172. Header("Accept-Length: " . filesize($pdfpath));
  2173. Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['exam_name']."-".$exam_info['class_name']) . ".pdf"); // 输出文件内容
  2174. ob_clean();
  2175. flush();// 刷新内容
  2176. $file=fopen($pdfpath,"r");
  2177. $download_rate=1024;
  2178. while (!feof($file)){
  2179. print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者
  2180. flush();// flush 内容输出到浏览器端
  2181. sleep(1);// 终端1秒后继续
  2182. }
  2183. fclose($file);
  2184. } else {
  2185. Yii::app()->jump->error('考试不存在或尚未生成PDF');
  2186. }*/
  2187. //新下载
  2188. set_time_limit(0);
  2189. $data = array();
  2190. $time = time();
  2191. $examId = safe_replace(Yii::app()->request->getQuery('examId'));
  2192. $sql = "select c.class_name,e.teacher_id,eg.mark_type,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,e.exam_group_id,e.class_id,e.subject_id from exam as e left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id left join `class` as c on c.class_id=e.class_id where e.exam_id={$examId}";
  2193. $exam_info = $this->sConn->createCommand($sql)->queryRow();
  2194. if($this->curlDownloadImage($exam_info['academicr_pdf_path'])){
  2195. // if(file_get_contents($exam_info['academicr_pdf_path'])){
  2196. $url = $exam_info['academicr_pdf_path'];
  2197. // // 获取远程文件大小
  2198. // // 注意filesize()无法获取远程文件大小
  2199. // $headers = get_headers($url, 1);
  2200. // $fileSize = $headers['Content-Length'];
  2201. // //echo $fileSize;exit;
  2202. // // 设置header头
  2203. // // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流
  2204. // header('Content-Type: application/pdf');
  2205. // // 告诉浏览器返回的文件大小类型是字节
  2206. // header('Accept-Ranges:bytes');
  2207. // // 告诉浏览器返回的文件大小
  2208. // header('Content-Length: ' . $fileSize);
  2209. // // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称
  2210. // Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['exam_name']."-".$exam_info['class_name']) . ".pdf"); // 输出文件内容
  2211. // //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  2212. // ob_clean();
  2213. // $read_buffer = 1024*1024;
  2214. // $handle = fopen($url, 'rb');
  2215. // //总的缓冲的字节数
  2216. // $sum_buffer = 0;
  2217. // //只要没到文件尾,就一直读取
  2218. // while (!feof($handle)) {
  2219. // echo fread($handle, $read_buffer);
  2220. // ob_flush();
  2221. // }
  2222. // fclose($handle);
  2223. $this->curlDownload($url,$this->filter_file_name($exam_info['exam_name']."-".$exam_info['class_name']));
  2224. if(in_array($exam_info['subject_id'],array(18,19))){
  2225. if($exam_info['subject_id'] == 18){//理综 12物理,13化学,14生物
  2226. $subject_arr = array(12,13,14);
  2227. }else{//文综
  2228. $subject_arr = array(15,16,17);
  2229. }
  2230. $sql = "select t.teacher_id,t.subjects from teacher_class_relation tcr left join teacher t on tcr.teacher_id = t.teacher_id where tcr.class_id = '{$exam_info['class_id']}' and t.subjects in (".implode(',',$subject_arr).") and t.status = 0 group by t.subjects";
  2231. $teacher_info = $this->sConn->createCommand($sql)->queryAll();
  2232. if($teacher_info){
  2233. $data['coachId'] = $this->coachId;
  2234. $data['schoolId'] = $this->schoolId;
  2235. $data['examGroupId'] = (string)$exam_info['exam_group_id'];
  2236. $data['examId'] = (string)$examId;
  2237. $data['createTime'] = $time;
  2238. $data['clazzId'] = (string)$exam_info['class_id'];
  2239. $data['toDataPoint'] = true;
  2240. $data['dataPointType'] = 3;
  2241. foreach($teacher_info as $k=>$v){
  2242. if($v['teacher_id']){
  2243. $data['teacherId'] = $v['teacher_id'];
  2244. }else{
  2245. $data['teacherId'] = '0';
  2246. }
  2247. @$this->sendKafka('datapoint-logs',$data);
  2248. }
  2249. // $pushData=json_encode($data);
  2250. // @$stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  2251. // if(isset($stompconn) && $stompconn){
  2252. // foreach($teacher_info as $k=>$v){
  2253. // if($v['teacher_id']){
  2254. // $data['teacherId'] = $v['teacher_id'];
  2255. // }else{
  2256. // $data['teacherId'] = '0';
  2257. // }
  2258. // $pushData=json_encode($data);
  2259. // @$stompconn->send("zsy-task.download-teacher-lecture-data-point", $pushData);
  2260. // }
  2261. // }
  2262. // unset($stompconn);
  2263. }
  2264. }else{
  2265. if(in_array($exam_info['subject_id'],array(3,6,51))){
  2266. $exam_info['subject_id'] = 3;
  2267. }
  2268. $sql = "select t.teacher_id from teacher_class_relation tcr left join teacher t on tcr.teacher_id = t.teacher_id where tcr.class_id = '{$exam_info['class_id']}' and t.subjects = '{$exam_info['subject_id']}' and t.status = 0";
  2269. $teacher_info = $this->sConn->createCommand($sql)->queryRow();
  2270. if($teacher_info){
  2271. $data['teacherId'] = $teacher_info['teacher_id'];
  2272. }else{
  2273. $data['teacherId'] = '0';
  2274. }
  2275. $url = $exam_info['academicr_pdf_path'];
  2276. $data['coachId'] = $this->coachId;
  2277. $data['schoolId'] = $this->schoolId;
  2278. $data['examGroupId'] = (string)$exam_info['exam_group_id'];
  2279. $data['examId'] = (string)$examId;
  2280. $data['createTime'] = $time;
  2281. $data['clazzId'] = (string)$exam_info['class_id'];
  2282. $data['toDataPoint'] = true;
  2283. $data['dataPointType'] = 3;
  2284. @$this->sendKafka('datapoint-logs',$data);
  2285. // $pushData=json_encode($data);
  2286. // @$stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  2287. // @$stompconn->send("zsy-task.download-teacher-lecture-data-point", $pushData);
  2288. // unset($stompconn);
  2289. }
  2290. }else{
  2291. Yii::app()->jump->error('考试不存在或尚未生成PDF');
  2292. }
  2293. }
  2294. function filter_file_name($filename){
  2295. return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
  2296. array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
  2297. , $filename);
  2298. }
  2299. function readfile_chunked($filename,$retbytes=true) {
  2300. $chunksize = 1*(1024*1024); // how many bytes per chunk
  2301. $buffer = '';
  2302. $cnt =0;
  2303. // $handle = fopen($filename, 'rb');
  2304. $handle = fopen($filename, 'rb');
  2305. if ($handle === false) {
  2306. return false;
  2307. }
  2308. while (!feof($handle)) {
  2309. $buffer = fread($handle, $chunksize);
  2310. echo $buffer;
  2311. ob_flush();
  2312. flush();
  2313. if ($retbytes) {
  2314. $cnt += strlen($buffer);
  2315. }
  2316. }
  2317. $status = fclose($handle);
  2318. if ($retbytes && $status) {
  2319. return $cnt; // return num. bytes delivered like readfile() does.
  2320. }
  2321. return $status;
  2322. }
  2323. private function paperTopicDetail($yun_id_arr, $sch_id_arr, $exam_id, $typestr) {
  2324. try {
  2325. $all_id_arr = array_merge($yun_id_arr,$sch_id_arr);
  2326. if (!$all_id_arr ) {
  2327. return false;
  2328. }
  2329. $data = array();
  2330. $total_count = count($all_id_arr);
  2331. $page_size = 100;
  2332. $page = ceil($total_count/$page_size);
  2333. for ($i = 0; $i<$page; $i++) {
  2334. $offset = $i * $page_size;
  2335. $id_arr = array_slice($all_id_arr,$offset, $page_size);
  2336. $topicBatchs = $this->aipost('topic/batchall', array('topicIds' => $id_arr));
  2337. if (!$topicBatchs) {
  2338. throw new Exception('获取接口topic/batchALL数据时无任何返回,type is '.$typestr.' ,exam_id is ('.$exam_id.')');
  2339. }if(isset($topicBatchs->status) && $topicBatchs->status == 0 ){
  2340. throw new Exception($topicBatchs->error[0]);
  2341. } else{
  2342. $data += $this->formatDetails($topicBatchs);
  2343. }
  2344. }
  2345. return $data;
  2346. } catch (Exception $e) {
  2347. return false;
  2348. }
  2349. }
  2350. public function formatDetails($topicBatches) {
  2351. $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
  2352. $topicDetails = array();
  2353. foreach ($topicBatches AS $ke=>$topic) {
  2354. if(!isset($topic["teacher_tips"]) || !$topic["teacher_tips"]){
  2355. $topicBatches[$ke]["teacher_tips"] = $this->dealTeacherTips($topic);
  2356. }
  2357. $topic = (object) $topic;
  2358. $topic->id = (string)$topic->id;
  2359. $type = $topic->type_id;
  2360. 6 == $type && $type = 5; //6表示多空题,多空题也是5
  2361. $topicDetails[$topic->id] = array();
  2362. $topicDetails[$topic->id]['type'] = $type;
  2363. $topicDetails[$topic->id]['methods'] = ''; //考点
  2364. $topicDetails[$topic->id]['method_id_arr'] = ''; //考点id数组
  2365. $topicDetails[$topic->id]['kps'] = ''; //知识点
  2366. $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title); //题目详情
  2367. $topicDetails[$topic->id]['options'] = '';
  2368. $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : '';
  2369. $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案
  2370. $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content); //答题解析
  2371. $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips); //名师点评
  2372. $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null;
  2373. $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
  2374. $topicDetails[$topic->id]['type_name'] = $topic->type_name;
  2375. $topicDetails[$topic->id]['source'] = $topic->source;
  2376. $_methods = array();
  2377. $_method_id_arr = array();
  2378. if ($topic->specials) {
  2379. foreach ($topic->specials AS $_method) {
  2380. $_method = (object) $_method;
  2381. if ($_method->method_name) {
  2382. $_methods[] = $_method->method_name;
  2383. }
  2384. if (isset($_method->method_id)) {
  2385. $_method_id_arr[] = $_method->method_id;
  2386. }
  2387. }
  2388. $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点
  2389. $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
  2390. }
  2391. $_kps = array();
  2392. if (isset($topic->kps) && $topic->kps) {
  2393. foreach ($topic->kps as $_kp) {
  2394. $_kp = (object) $_kp;
  2395. if ($_kp->kp_name) {
  2396. $_kps[$_kp->kp_id] = $_kp->kp_name;
  2397. }
  2398. }
  2399. $topicDetails[$topic->id]['kps'] = $_kps; //考点
  2400. }
  2401. if ($topic->type_id == 1 || $topic->type_id == 2) { //选择题有选项
  2402. if ($topic->items) {
  2403. if (isset($topic->items[0])) {
  2404. $topic->items[0] = (object) $topic->items[0];
  2405. if (isset($topic->items[0]->options)) {
  2406. $options = $topic->items[0]->options;
  2407. if ($options) {
  2408. $_tmp_options = array();
  2409. $anwer_str = "";
  2410. foreach ($options AS $_optionIndex => $_option) {
  2411. $_option = (object) $_option;
  2412. $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
  2413. if ($_option->option_correct) {
  2414. if($anwer_str == ""){
  2415. $anwer_str = $this->topicProcess($optionIndex[$_optionIndex]);
  2416. // $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]);
  2417. }else{
  2418. $anwer_str .= "、".$this->topicProcess($optionIndex[$_optionIndex]);
  2419. }
  2420. }
  2421. }
  2422. $topicDetails[$topic->id]['answer'] = $anwer_str;
  2423. $topicDetails[$topic->id]['answer_format'] = str_replace('、', '', $anwer_str);
  2424. $_list_type = (int) $topic->items[0]->list_type;
  2425. $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type);
  2426. }
  2427. }
  2428. }
  2429. }
  2430. } else {
  2431. if ($topic->items) {
  2432. if (isset($topic->items[0])) {
  2433. $topic->items[0] = (object) $topic->items[0];
  2434. if (isset($topic->items[0]->options)) {
  2435. $options = $topic->items[0]->options;
  2436. if ($options) {
  2437. $_answer = '';
  2438. foreach ($options as $v) {
  2439. $_option = (object) $v;
  2440. if (trim($_answer) != '') {
  2441. $_answer .= ' ; ';
  2442. }
  2443. $_answer .= $_option->option_content;
  2444. }
  2445. $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer);
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. return $topicDetails;
  2453. }
  2454. private function option_process($options, $list_type) {
  2455. $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
  2456. if ($list_type == 0) { //纵向排列,即1行1个
  2457. $option_str = "";
  2458. foreach ($options as $key => $option) {
  2459. $option_str.="<li class='fl lis-one'>$option_index[$key].$option</li>";
  2460. }
  2461. } elseif ($list_type == 1) { //横向排列,即1行4个
  2462. $option_str = "";
  2463. foreach ($options as $key => $option) {
  2464. $option_str.="<li class='fl lis-four'>$option_index[$key].$option</li>";
  2465. }
  2466. } elseif ($list_type == 2) { //1行2个
  2467. $option_str = "";
  2468. foreach ($options as $key => $option) {
  2469. if ($key % 2 == 0) {
  2470. $option1 = $options[$key];
  2471. $option_str2 = "<li class='fl lis-two'>$option_index[$key].$option1</li>";
  2472. $key1 = $key + 1;
  2473. if (isset($options[$key1])) {
  2474. $option2 = $options[$key1];
  2475. $option_str2.="<li class='fl lis-two'>$option_index[$key1].$option2</li>";
  2476. }
  2477. $option_str.=$option_str2;
  2478. } else {
  2479. continue;
  2480. }
  2481. }
  2482. }
  2483. return $option_str;
  2484. }
  2485. private function topicProcess($html) {
  2486. if (preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr)) {
  2487. foreach ($arr[0] as $v) {
  2488. $process_str = $this->img_process($v);
  2489. ;
  2490. $html = str_replace($v, $process_str, $html);
  2491. }
  2492. }
  2493. $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html);
  2494. $html = preg_replace('/<p\s*>/', '', $html);
  2495. $html = preg_replace('/<\/p>/', '', $html);
  2496. $html = preg_replace('/<br\/*>/', '', $html);
  2497. $html = preg_replace('/<big\s*>/', '', $html);
  2498. $html = preg_replace('/<\/big>/', '', $html);
  2499. $html = str_replace("&nbsp;", '', $html);
  2500. return $html;
  2501. }
  2502. private function img_process($img) {
  2503. $widthArr = array();
  2504. $heightArr = array();
  2505. $width = '';
  2506. $height = '';
  2507. if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si', $img, $widthArr)) {
  2508. $width = $this->length_process($widthArr);
  2509. } else {
  2510. if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si', $img, $widthArr)) {
  2511. $width = $this->length_process($widthArr);
  2512. }
  2513. }
  2514. if ($width) {
  2515. $width = "width=" . $width;
  2516. }
  2517. if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si', $img, $heightArr)) {
  2518. $height = $this->length_process($heightArr);
  2519. } else {
  2520. if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si', $img, $heightArr)) {
  2521. $height = $this->length_process($heightArr);
  2522. }
  2523. }
  2524. if ($height) {
  2525. $height = "height=" . $height;
  2526. }
  2527. $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', "<img " . $width . " " . $height . " $1 />", $img);
  2528. return $return_img;
  2529. }
  2530. private function length_process($length_arr) {
  2531. $length = 0.6 * $length_arr[1];
  2532. $unit_keys = array_keys($this->units);
  2533. if (isset($length_arr[2])) {
  2534. //将直接连接单位改为 单位换算
  2535. if (in_array($length_arr[2], $unit_keys)) {
  2536. $length = $length * $this->units[$length_arr[2]];
  2537. } else {
  2538. $length .= $length_arr[2];
  2539. }
  2540. }
  2541. return $length;
  2542. }
  2543. public function numToUpper($number) {
  2544. $number = substr($number, 0, 2);
  2545. $arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
  2546. if (strlen($number) == 1) {
  2547. $result = $arr[$number];
  2548. } else {
  2549. if ($number == 10) {
  2550. $result = '十';
  2551. } else {
  2552. if ($number < 20) {
  2553. $result = '十';
  2554. } else {
  2555. $result = $arr[substr($number, 0, 1)] . '十';
  2556. }
  2557. if (substr($number, 1, 1) != '0') {
  2558. $result .= $arr[substr($number, 1, 1)];
  2559. }
  2560. }
  2561. }
  2562. return $result;
  2563. }
  2564. public function numToLetter($number) {
  2565. $letters = 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');
  2566. $number = (int) $number;
  2567. $result = '';
  2568. if ($number >= 1 AND $number <= 26) {
  2569. $result = $letters[$number - 1];
  2570. }
  2571. return $result;
  2572. }
  2573. public function actionDownload() {
  2574. $exam_id = safe_replace(Yii::app()->request->getQuery('exam_id'));
  2575. $host = '';
  2576. $databases_data = BusinessDatabase::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  2577. if ($databases_data) {
  2578. $host = isset(Yii::app()->params['static_url'][$databases_data->group_id]) ? Yii::app()->params['static_url'][$databases_data->group_id] : Yii::app()->params['api_host'].'/uploads/';
  2579. }
  2580. $exam_data = Exam::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
  2581. if ($exam_data) {
  2582. $filename = $exam_data->topwb_pdf_path;
  2583. $filenames = explode('/', $filename);
  2584. $filenames = array_reverse($filenames);
  2585. if (!filter_var(trim($filename), FILTER_VALIDATE_URL)) { //没有http
  2586. $filename = $host . '/' . $filename;
  2587. }
  2588. header('Content-Description: File Transfer');
  2589. header('Content-Type: application/vnd.android.package-archive');
  2590. header('Content-Disposition: attachment; filename=' . $filenames[0]);
  2591. header('Content-Transfer-Encoding: binary');
  2592. header('Expires: 0');
  2593. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  2594. header('Pragma: public');
  2595. $ch = curl_init();
  2596. curl_setopt($ch, CURLOPT_URL, $filename);
  2597. curl_setopt($ch, CURLOPT_HEADER, 0);
  2598. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2599. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  2600. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  2601. echo $buffer;
  2602. return strlen($buffer);
  2603. });
  2604. curl_exec($ch);
  2605. curl_close($ch);
  2606. /*$content = curlDownloadImage($filename);
  2607. $length=strlen($content);//取得字符串长度,即文件大小,单位是字节
  2608. $encoded_filename = rawurlencode($filename);//采用rawurlencode避免空格被替换为+
  2609. $ua = $_SERVER["HTTP_USER_AGENT"];//获取用户浏览器UA信息
  2610. header('Content-Type: application/octet-stream');//告诉浏览器输出内容类型,必须
  2611. header('Content-Encoding: none');//内容不加密,gzip等,可选
  2612. header("Content-Transfer-Encoding: binary" );//文件传输方式是二进制,可选
  2613. header("Content-Length: ".$length);//告诉浏览器文件大小,可选
  2614. if (preg_match("/MSIE/", $ua)) {//从UA中找到MSIE判断是IE
  2615. header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
  2616. } else if (preg_match("/Firefox/", $ua)) {//同理判断火狐
  2617. header('Content-Disposition: attachment; filename*="utf8\'\'' . $filenames[0] . '"');
  2618. } else {//其他情况,谷歌等
  2619. header('Content-Disposition: attachment; filename="' . $filenames[0] . '"');
  2620. }
  2621. echo $content;
  2622. exit();*/
  2623. }
  2624. }
  2625. public function actionStatistics() {
  2626. $data = array();
  2627. $semester_data = Semester::model()->findAll();
  2628. if ($semester_data) {
  2629. $data['semester'] = $semester_data;
  2630. } else {
  2631. $data['semester'] = array();
  2632. }
  2633. $data['school_info'] = $this->schoolInfo;
  2634. $this->render('statistics', $data);
  2635. }
  2636. public function actionPastacdemicrs()
  2637. {
  2638. $param_semester_id = safe_replace(Yii::app()->request->getQuery('semester'));
  2639. $param_grad_id = safe_replace(Yii::app()->request->getQuery('grade'));
  2640. $param_class_id = safe_replace(Yii::app()->request->getQuery('class'));
  2641. $param_exam_name = safe_replace(Yii::app()->request->getQuery('exam_name'));
  2642. $data = array(
  2643. 'current_sem_id' =>0,
  2644. 'current_grade_id'=>0,
  2645. 'current_class_id'=>0,
  2646. 'current_exam_name'=>'',
  2647. 'sem_arr' => array(),
  2648. 'class_arr' => array()
  2649. );
  2650. if ($param_semester_id) {
  2651. $data['current_sem_id'] = $param_semester_id;
  2652. }
  2653. if ($param_grad_id) {
  2654. $data['current_grade_id'] = $param_grad_id;
  2655. }
  2656. if ($param_class_id) {
  2657. $data['current_class_id'] = $param_class_id;
  2658. }
  2659. if ($param_exam_name) {
  2660. $data['current_exam_name'] = $param_exam_name;
  2661. }
  2662. //获取所有过去的学期,默认当前学期的第一学期被选中
  2663. $_current_sem_start_time = 0;
  2664. $sql = 'select start_time from semester where status=1 limit 1';
  2665. $res = $this->sConn->createCommand($sql)->queryRow();
  2666. $start_time = $res['start_time'];
  2667. if (!$start_time) {
  2668. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  2669. }
  2670. $sql = 'select semester_id,semester_name from semester where status=0 and start_time < '.$start_time.' order by start_time desc ';
  2671. $res = $this->sConn->createCommand($sql)->queryAll();
  2672. if (!$res) {
  2673. Yii::app()->jump->error('以前的学期不存在');
  2674. }
  2675. $sem_arr = array();
  2676. foreach ($res as $v) {
  2677. $sem_arr[$v['semester_id']] = $v['semester_name'];
  2678. }
  2679. $data['sem_arr'] = $sem_arr;
  2680. if (!$data['current_sem_id']) {
  2681. $data['current_sem_id'] = $res[0]['semester_id'];
  2682. }
  2683. //如果选择了年级,显示出对应的班级
  2684. if ($param_grad_id) {
  2685. $class_arr = array();
  2686. $sql = 'select class_id,class_name from class where semester_id='.$data['current_sem_id'].' and grade='.$param_grad_id;
  2687. $res = $this->sConn->createCommand($sql)->queryAll();
  2688. foreach ($res as $v) {
  2689. $class_arr[$v['class_id']] = $v['class_name'];
  2690. }
  2691. $data['class_arr'] = $class_arr;
  2692. }
  2693. //符合查询条件的考试
  2694. $sql = 'select e.exam_id,e.name,e.is_academicr_pdf,c.class_id,c.class_name from exam e join class c on c.class_id=e.class_id join class_exam_printer cep on cep.class_id=e.class_id and cep.exam_id=e.exam_id where e.semester_id='.$data['current_sem_id'].' and e.status=1 and cep.type=0 and e.subject_id in ('.implode(',',$this->mathSubjectId).') ';
  2695. if ($param_grad_id) {
  2696. $sql.= ' and c.grade='.$param_grad_id;
  2697. }
  2698. if ($param_class_id) {
  2699. $sql.= ' and c.class_id='.$param_class_id;
  2700. }
  2701. if ($param_exam_name) {
  2702. $sql .= ' and e.name like "%'.$param_exam_name.'%"';
  2703. }
  2704. $sql .= ' order by cep.add_time desc';
  2705. $res = $this->sConn->createCommand($sql)->query();
  2706. $data['page_total'] = $res->rowCount;
  2707. $sql = $res->queryString." limit :offset, :limit";
  2708. $command = $this->sConn->createCommand($sql);
  2709. $pager = new CPagination($res->rowCount, 10);
  2710. $offset = $pager->getOffset();
  2711. $command->bindValue(":offset", $offset);
  2712. $limit = $pager->getLimit();
  2713. $command->bindValue(":limit", $limit);
  2714. $res = $command->queryAll();
  2715. if (!$res) {
  2716. $exam_data = array();
  2717. } else{
  2718. foreach ($res as $v) {
  2719. $exam_id = $v['exam_id'];
  2720. $exam_data[$exam_id]['exam_name'] = $v['name'];
  2721. $exam_data[$exam_id]['class_name'] = $v['class_name'];
  2722. $exam_data[$exam_id]['class_id']=$v['class_id'];
  2723. $exam_data[$exam_id]['status'] = $v['is_academicr_pdf']?'已生成':'未生成';
  2724. }
  2725. }
  2726. $data['exam_data'] = $exam_data;
  2727. $data['pager'] = $pager;
  2728. $this->render('pastacdemicrs',$data);
  2729. }
  2730. public function actionGetGradeClass()
  2731. {
  2732. $grade = Req::post("grade");
  2733. $semester_id = Req::post("semester_id");
  2734. $sql = 'select class_id,class_name from class where semester_id='.$semester_id.' and grade='.$grade;
  2735. $classes = $this->sConn->createCommand($sql)->queryAll();
  2736. if ($classes) {
  2737. $error['success'] = 1;
  2738. $error['message'] = $classes;
  2739. } else {
  2740. $error['success'] = 0;
  2741. $error['message'] = '未找到班级!';
  2742. }
  2743. echo json_encode($error);
  2744. exit();
  2745. }
  2746. public function actionS_download() {
  2747. $semester_id = Req::post("semester_id");
  2748. $data = array();
  2749. $host = '';
  2750. if (!$semester_id) {
  2751. echo '{"status":-1}';
  2752. exit;
  2753. }
  2754. $semester_data = Semester::model()->find('semester_id=:semester_id', array(':semester_id' => $semester_id));
  2755. if ($semester_data) {
  2756. $databases_data = BusinessDatabase::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  2757. if ($databases_data) {
  2758. $host = isset(Yii::app()->params['static_url'][$databases_data->group_id]) ? Yii::app()->params['static_url'][$databases_data->group_id] : Yii::app()->params['static_url'][0];
  2759. }
  2760. $str = $host . '/teaching_quality/' . $this->schoolId . '/' . $semester_data->semester_id . '/' . trim($this->schoolInfo->school_name) . '学校' . trim($semester_data->semester_name) . '教学质量统计表.xls';
  2761. $file_data = Curl::http_get($str);
  2762. if ($file_data) {
  2763. /*校长报告埋点*/
  2764. $stomp_data = array();
  2765. $stomp_data['coachId'] = $this->coachId;
  2766. $stomp_data['schoolId'] = $this->schoolId;
  2767. $stomp_data['semesterId'] = (string)$semester_id;
  2768. $stomp_data['createTime'] = time();
  2769. $stomp_data['toDataPoint'] = true;
  2770. $stomp_data['dataPointType'] = 4;
  2771. @$this->sendKafka('datapoint-logs',$stomp_data);
  2772. // $pushData=json_encode($stomp_data);
  2773. // @$stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  2774. // @$stompconn->send("zsy-task.download-coach-schoolmaster-report-data-point", $pushData);
  2775. // unset($stompconn);
  2776. echo '{"status":1,"file_path":"' . $str . '"}';
  2777. exit;
  2778. }
  2779. echo '{"status":0}';
  2780. exit;
  2781. } else {
  2782. echo '{"status":-2}';
  2783. exit;
  2784. }
  2785. }
  2786. /**
  2787. * 判断远程文件是否存在
  2788. * @param string $url 文件地址
  2789. * @return boolean
  2790. */
  2791. function url_exists($url) {
  2792. $ch = curl_init();
  2793. curl_setopt($ch, CURLOPT_URL, $url);
  2794. //涓嶄笅杞?
  2795. curl_setopt($ch, CURLOPT_NOBODY, 1);
  2796. //璁剧疆瓒呮椂
  2797. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
  2798. curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  2799. curl_exec($ch);
  2800. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  2801. if ($http_code == 200) {
  2802. return true;
  2803. }
  2804. return false;
  2805. }
  2806. function transferOrders($paperIds,$is_qxk=0)
  2807. {
  2808. $sql = 'select paper_id,topic_id,type,`order`,stem_id from paper_topic_relation where paper_id in ('.implode(',',$paperIds).') order by paper_id, type asc,`order` asc';
  2809. $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll();
  2810. $sql = 'select tpl_index,tpl_data,paper_id from exam e join paper p on e.exam_id = p.exam_id where p.paper_id in ('.implode(',',$paperIds).')' ;
  2811. $tpl_index_res = $this->sConn->createCommand($sql)->queryAll();
  2812. $tpl_index_arr = array();
  2813. $topic_no_data_arr = $tpl_data_arr = array();
  2814. $changeDoToicNo = array();
  2815. foreach ($tpl_index_res as $v) {
  2816. $tpl_index_arr[$v['paper_id']] = $v['tpl_index'];
  2817. if($v['tpl_data']){
  2818. $v['tpl_data'] = preg_replace('/:\s*(-?\d{15,})/', ': "$1"', $v['tpl_data']);//把15位的int转成string
  2819. $tplData = json_decode($v['tpl_data'],true);
  2820. if($tplData){
  2821. $tplstatus = 0;
  2822. if(isset($tplData['tplstatus'])){
  2823. $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus'];
  2824. }else{
  2825. $tpl_data_arr[$v['paper_id']] = 0;
  2826. }
  2827. }
  2828. //选做题题号
  2829. if (isset($tplData['new_items']) && $tplData['new_items']) {
  2830. $new_items = array_values($tplData['new_items']);
  2831. foreach ($new_items as $key => &$item) {
  2832. if (isset($item['sameAliasNo']) && $item['sameAliasNo']>0) {
  2833. $no =$item['alias'];
  2834. $item['topicId'] = (string)$item['topicId'];
  2835. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["sameAliasNo"] = $item['sameAliasNo'];//选做题组id
  2836. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["smTopicLen"] = $item['smTopicLen'];//选做题组必做数量
  2837. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["no"] = $no;//题号
  2838. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["topicId"] = $item['topicId'];//题目id
  2839. $changeDoToicNo[$v['paper_id']]["gather"][$item['sameAliasNo']][]=$item['topicId'];
  2840. }
  2841. }
  2842. }
  2843. }
  2844. }
  2845. $paper_topcic_relation_arr = array();
  2846. foreach ( $paper_topcic_relation_res as $v) {
  2847. $paper_id = $v['paper_id'];
  2848. $type = $v['type'];
  2849. $order = $v['order'];
  2850. $topic_id = (string)$v['topic_id'];
  2851. $stem_id = (string)$v['stem_id'];
  2852. if (!isset($paper_topcic_relation_arr[$paper_id])) {
  2853. $paper_topcic_relation_arr[$paper_id] = array();
  2854. }
  2855. $paper_topcic_relation_arr[$paper_id][] = array(
  2856. 'type' => $type,
  2857. 'order' => $order,
  2858. 'topic_id'=>$topic_id,
  2859. 'stem_id'=>$stem_id
  2860. );
  2861. }
  2862. $paper_topic_no_arr = array();
  2863. foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) {
  2864. $tpl_index = $tpl_index_arr[$paper_id];
  2865. $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0;
  2866. $change_do_toicno = isset($changeDoToicNo[$paper_id])?$changeDoToicNo[$paper_id]:array();
  2867. $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus,$is_qxk,$change_do_toicno);
  2868. }
  2869. return $paper_topic_no_arr;
  2870. }
  2871. function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus,$is_qxk=0,$change_do_toicno=array())
  2872. {
  2873. $topic_no_arr = array(); //每道题的序号
  2874. if($is_qxk){
  2875. $_order = 1;
  2876. $small_no = 1;
  2877. //$change_no =65;
  2878. $change_no_arr = $temp_stem_arr = array();
  2879. foreach($paper_topcic_relation_arr as $v){
  2880. if($v['stem_id']){
  2881. $temp_stem_arr[$v['stem_id']][] = $v['topic_id'];
  2882. }
  2883. }
  2884. foreach ($paper_topcic_relation_arr as $v) {
  2885. if(!isset($temp_stem_arr[$v['stem_id']]) || count($temp_stem_arr[$v['stem_id']]) == 1){
  2886. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2887. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1){//判断是否选做题
  2888. if(isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])){
  2889. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2890. }else{
  2891. $change_no = 65;//从A开始
  2892. }
  2893. $topic_no_arr[$v['topic_id']] = $_order . chr($change_no) ;
  2894. $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no +1;
  2895. }else{
  2896. $topic_no_arr[$v['topic_id']] = $_order;
  2897. $_order++;
  2898. }
  2899. $small_no = 1;
  2900. }else{//大小提
  2901. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2902. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
  2903. if(isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])){
  2904. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2905. }else{
  2906. $change_no = 65;//从A开始
  2907. }
  2908. $_order = $_order . chr($change_no);
  2909. }
  2910. $topic_no_arr[$v['topic_id']] = $_order.'('.$small_no.')';
  2911. if($small_no == count($temp_stem_arr[$v['stem_id']])){
  2912. $small_no = 1;
  2913. $_order++;
  2914. }
  2915. $small_no++;
  2916. }
  2917. }
  2918. }else if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
  2919. $prefix_no = 0;
  2920. $num = 0;
  2921. $index_arr = array('A','B','C','D','E');
  2922. $_order = 0;
  2923. foreach($paper_topcic_relation_arr as $v) {
  2924. if (!$prefix_no && $v['type'] == 17) {
  2925. $_order += 1; //序号加1
  2926. $prefix_no = $_order;
  2927. $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
  2928. } elseif ($prefix_no && $v['type'] == 17) {
  2929. $num += 1;
  2930. $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
  2931. }
  2932. if ($v['type'] == 27) {
  2933. $prefix_no += 1;
  2934. $topic_no_arr[$v['topic_id']] = $prefix_no;
  2935. }
  2936. if ($v['type'] != 17 && $v['type'] != 27){
  2937. $_order += 1;
  2938. $topic_no_arr[$v['topic_id']] = $_order;
  2939. }
  2940. }
  2941. } else { //其他模板都是根据order就行
  2942. $_order = 0;
  2943. foreach ($paper_topcic_relation_arr as $v) {
  2944. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2945. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
  2946. if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) {
  2947. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2948. } else {
  2949. $change_no = 65;//从A开始
  2950. $_order += 1;
  2951. }
  2952. $topic_no_arr[$v['topic_id']] = $_order . chr($change_no);
  2953. $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no + 1;
  2954. }else{
  2955. $_order += 1;
  2956. $topic_no_arr[$v['topic_id']] = $_order;
  2957. }
  2958. }
  2959. }
  2960. return $topic_no_arr;
  2961. }
  2962. public function actionAjax_down()
  2963. {
  2964. $examId = Req::post("exam_id");
  2965. $file_type = Req::post("download_type");
  2966. $param['hasStudentNo'] = (int)Req::post("hasStudentNo"); //是否有学号
  2967. $param['hasStudentSystemCard'] = (int)Req::post("hasStudentSystemCard"); //是否有学生系统准考证号
  2968. $param['hasStudentSchoolCard'] = (int)Req::post("hasStudentSchoolCard"); //是否有学生学校准考证号
  2969. $param['hasIdNumber'] = (int)Req::post("hasIdNumber"); //是否有身份证
  2970. $param['removeOuterStudent'] = (int)Req::post("removeOuterStudent"); //是否移除借读生
  2971. $param['removeZeroStudent'] = (int)Req::post("removeZeroStudent"); //过滤0分考生
  2972. $param['hasClazzAchievement'] = (int)Req::post("hasClazzAchievement"); //班级成绩分析表
  2973. $param['hasStudentAchievementRank'] = (int)Req::post("hasStudentAchievementRank"); //学生成绩排名分析表
  2974. $param['hasGradeAchievement'] = (int)Req::post("hasGradeAchievement"); //年级成绩分析表
  2975. $param['hasClazzAvgScore'] = (int)Req::post("hasClazzAvgScore"); //班级平均分表
  2976. $param['hasScoreSection'] = (int)Req::post("hasScoreSection"); //班级分数段表
  2977. $param['hasSubjectAchievement'] = (int)Req::post("hasSubjectAchievement"); //各科成绩分析表
  2978. $param['hasWenLiZongDetail'] = (int)Req::post("hasWenLiZongDetail"); //是否有文综理综单科成绩明细报表
  2979. $scoreSectionList = Req::post('scoreSection'); //总分段
  2980. $param['isSimpleClazzAchievement'] = (int)Req::post("isSimpleClazzAchievement"); //班级学生成绩分析表(完整版:0;简易版:1,简易版不提供题目统计、答错人数、选项统计、分数段人数、缺考人数)
  2981. $param['isSimpleClazzAvgScore'] = (int)Req::post("isSimpleClazzAvgScore"); //班级平均分表(完整版:0;简易版:1,简易版不提供题目统计)
  2982. $param['isSimpleGradeAchievement'] = (int)Req::post("isSimpleGradeAchievement"); //年级学生成绩分析表(完整版:0;简易版:1,简易版不提供题目统计、答错人数、选项统计、分数段人数)
  2983. $param['totalScoreCoefficient'] = Req::post("totalScoreCoefficient"); //总分系数
  2984. $param['excellentRatio'] = Req::post('excellentRatio'); //优秀率
  2985. $param['goodRatio'] = Req::post('goodRatio'); //良好率
  2986. $param['mediumRatio'] = Req::post('mediumRatio'); //中等率
  2987. $param['hasStudentAnswerDetail'] = Req::post("hasClazzChoiceTopicStatistics"); //选择题作答明细表
  2988. $param['showSetting'] = Req::post("scoreOfEachQuestion"); //每题得分(学生答案,学生得分 0学生答案,1学生得分)
  2989. $param['examId'] = $examId;
  2990. $param['paperSizeType'] = Req::post("paperSizeType"); //A4横向:1;A3纵向:2;默认1;
  2991. $param['showRankingChanges'] = (int)Req::post("showRankingChanges"); //是否显示排名升降 显示:1;隐藏:0
  2992. $param['totalScoreCoefficientIsRounding'] = (int)Req::post("totalScoreCoefficientIsRounding"); //启用总分系数后,是否保留小数,0整数,1保留小数
  2993. if(!$param['paperSizeType']) $param['paperSizeType'] =1;
  2994. if($scoreSectionList){
  2995. // $param['scoreSectionList']=explode(',',$scoreSectionList);
  2996. $param['scoreSectionList']=$scoreSectionList;
  2997. }
  2998. if($param['totalScoreCoefficient']=='-1'){
  2999. $param['totalScoreCoefficient']=0;
  3000. }
  3001. if(!$examId || !$file_type)
  3002. {
  3003. echo json_encode(array('status'=>0,'result'=>''));exit;
  3004. }
  3005. if($file_type==1 || $file_type==2){
  3006. if($file_type==2){
  3007. $urlType='excel';
  3008. }else{
  3009. //word没有
  3010. // unset($param['hasScoreSection']);
  3011. unset($param['hasWenLiZongDetail']);
  3012. unset($param['hasGradeAchievement']);
  3013. unset($param['hasSubjectAchievement']);
  3014. unset($param['isSimpleGradeAchievement']);
  3015. unset($param['hasStudentAnswerDetail']);
  3016. // unset($param['showSetting']);
  3017. $urlType='word';
  3018. }
  3019. //获取是否是全学科组卷
  3020. $sql = "select eg.qxk_paper_id,e.class_id,e.name,e.subject_id,e.exam_group_id from exam_group eg join exam e on eg.exam_group_id = e.exam_group_id where e.exam_id= '{$examId}'";
  3021. $quan_data = $this->sConn->createCommand($sql)->queryRow();
  3022. if($quan_data && $quan_data['qxk_paper_id']){
  3023. $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/exam-report/download/'.$urlType;
  3024. }else{
  3025. $url = Yii::app()->params['zsy_api_url'].'/teacher/academic/download/'.$urlType.'/'.$this->schoolId;
  3026. }
  3027. $this->setIs_new($examId);
  3028. $username = $this->schoolId;
  3029. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  3030. $rs = $this->CrmApiPost($url,$param,$username,$password);
  3031. if(isset($rs->errCode) && $rs->errCode =='00')
  3032. {
  3033. //组装打印参数
  3034. $printData=array();
  3035. $printData['typeId']=18;
  3036. $printData['productType']=60003;
  3037. $printData['params']=array(
  3038. 'classIds'=>array($quan_data['class_id']),
  3039. 'url'=>$rs->data,
  3040. 'name'=>$quan_data['name'],
  3041. 'subjectId'=>$quan_data['subject_id'],
  3042. 'examGroupId'=>$quan_data['exam_group_id'],
  3043. );
  3044. echo json_encode(array('status'=>1,'result'=>$rs->data,'print'=>$printData));exit;
  3045. }
  3046. $errMsg = '下载失败';
  3047. if(isset($rs->errMsg))
  3048. {
  3049. $errMsg = $rs->errMsg;
  3050. }
  3051. echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
  3052. }
  3053. }
  3054. public function CrmApiPost($url, $arr, $username,$password,$method='POST')
  3055. {
  3056. $ch = @curl_init();
  3057. $result = FALSE;
  3058. if ($ch)
  3059. {
  3060. $data = json_encode($arr);
  3061. if($method=='POST'){
  3062. // Digest认证
  3063. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  3064. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  3065. // 不输出头部
  3066. curl_setopt($ch, CURLOPT_HEADER, 0);
  3067. // curl_exec 获取到的内容不直接输出, 而是返回
  3068. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  3069. // 请求重启路由器的地址 传参 进行重启
  3070. curl_setopt($ch, CURLOPT_URL, $url);
  3071. curl_setopt($ch, CURLOPT_TIMEOUT,120);
  3072. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  3073. curl_setopt($ch, CURLOPT_POST, 1);
  3074. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  3075. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  3076. 'Content-Type: application/json',
  3077. 'Content-Length: '. strlen($data),
  3078. ));
  3079. }else{
  3080. // Digest认证
  3081. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  3082. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  3083. // 不输出头部
  3084. curl_setopt($ch, CURLOPT_HEADER, 0);
  3085. // curl_exec 获取到的内容不直接输出, 而是返回
  3086. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  3087. // 请求重启路由器的地址 传参 进行重启
  3088. curl_setopt($ch, CURLOPT_URL, $url);
  3089. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  3090. }
  3091. if( !curl_errno($ch))
  3092. {
  3093. $result = json_decode(curl_exec($ch));
  3094. }
  3095. // 释放资源
  3096. curl_close($ch);
  3097. }
  3098. return $result;
  3099. }
  3100. public function setIs_new($exam_id)
  3101. {
  3102. if($exam_id)
  3103. {
  3104. Exam::model()->updateAll(array('is_new'=>2),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  3105. }
  3106. }
  3107. // 操作周周练显示状态
  3108. public function actionOprateexam(){
  3109. $exam_id = Req::post("exam_id");
  3110. $flag = Req::post("flag");
  3111. $error['success'] = 0;
  3112. if (empty($exam_id)) {
  3113. $error['message'] = '操作失败!';
  3114. echo json_encode($error);exit();
  3115. }
  3116. $this->setIs_new($exam_id);
  3117. if ($this->schoolManager->oprateExamExportDisplay($exam_id,$flag)) {
  3118. $error['success'] = 1;
  3119. $error['message'] = '操作成功!';
  3120. } else {
  3121. $error['message'] = '操作失败!';
  3122. }
  3123. echo json_encode($error);exit();
  3124. }
  3125. public function actionGetSection(){
  3126. $param=array();
  3127. $exam_id = Req::post("exam_id");
  3128. $result['success']=0;
  3129. if(!$exam_id){
  3130. exit(json_encode($result));
  3131. }
  3132. //判断考试类型
  3133. $is_lecture_download=1; //教师讲案
  3134. $is_topwb_download=1; //错题前十
  3135. $is_lecture_download_msg='';
  3136. $is_topwb_download_msg='';
  3137. $exam_data = Exam::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
  3138. $xamGroupData=ExamGroup::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $exam_data->exam_group_id));
  3139. if($xamGroupData->is_third==1 && $xamGroupData->mark_type==0){
  3140. $is_lecture_download=0;
  3141. $is_topwb_download=0;
  3142. $is_lecture_download_msg='线下导入成绩不能下载教师讲案';
  3143. $is_topwb_download_msg='线下导入成绩不能下载错题前十';
  3144. }else{
  3145. if($exam_data->is_topwb_pdf!=1){
  3146. $is_topwb_download=0;
  3147. $is_topwb_download_msg='错题前十未生成';
  3148. }
  3149. }
  3150. $result['download_rule']=array(
  3151. 'is_lecture_download'=>$is_lecture_download,
  3152. 'is_topwb_download'=>$is_topwb_download,
  3153. 'is_lecture_download_msg'=>$is_lecture_download_msg,
  3154. 'is_topwb_download_msg'=>$is_topwb_download_msg,
  3155. );
  3156. if(isset(Yii::app()->session['session_duoxueke_subject_id'])){
  3157. $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
  3158. }else{
  3159. $subjectId= $this->subjectId;
  3160. }
  3161. if(!in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  3162. $result['download_rule']['is_topwb_download']=0;
  3163. $result['download_rule']['is_topwb_download_msg']='当前科目暂未上线错题前十';
  3164. }
  3165. $username = $this->schoolInfo->school_id;
  3166. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  3167. $url = Yii::app()->params['zsy_api_url'].'/teacher/academic/exam/score/section/'.$this->schoolId.'/'.$exam_id;
  3168. $rs = $this->CrmApiPost($url,$param,$username,$password,'GET');
  3169. //debug($rs);
  3170. if(isset($rs->errCode) && $rs->errCode =='00')
  3171. {
  3172. $result['success']=1;
  3173. $result['data']=$rs->data;
  3174. }
  3175. exit(json_encode($result));
  3176. }
  3177. //读取考试班级
  3178. public function actionGetExamClass(){
  3179. $exam_group_id = Req::post("examGroupId");
  3180. $is_third = Req::post("isThird");
  3181. $result['success']=0;
  3182. //读取考试
  3183. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  3184. if(!$exam_group_data)
  3185. {
  3186. $result['msg']='未找到考试信息';
  3187. exit(json_encode($result));
  3188. }
  3189. $topic_answer_upload=0;
  3190. if($is_third){
  3191. //判断是否上传答案、试题
  3192. $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($exam_group_id);
  3193. $uploadStatus=0;
  3194. if($uploadExamInfo){
  3195. if(isset($uploadExamInfo[1])){
  3196. if($uploadExamInfo[1]['topic_upload']==1){
  3197. $uploadStatus+=1;
  3198. }
  3199. }
  3200. if(isset($uploadExamInfo[2])){
  3201. if($uploadExamInfo[2]['answer_upload']==1){
  3202. $uploadStatus+=3;
  3203. }
  3204. }
  3205. }
  3206. if($uploadStatus<4){
  3207. $topic_answer_upload=0;
  3208. }else{
  3209. $topic_answer_upload=1;
  3210. }
  3211. }
  3212. $classes=$this->schoolManager->getExportClassByExamGroupId($exam_group_id);
  3213. $initData=array();
  3214. $exam_id=0;
  3215. if($classes){
  3216. foreach ($classes as $key => $val){
  3217. $initData['examTitle']=$val['name'];
  3218. $temp=array('className'=>$val['class_name'],'id'=>$val['class_id']);
  3219. $check=$this->schoolManager->classExamHasPaperRs($val['exam_id'], $val['class_id']);
  3220. if($check && $val['status']==1) {
  3221. $temp['excel'] = 1;
  3222. $temp['word'] = 1;
  3223. if ($val['is_topwb_pdf'] == 1) {
  3224. $temp['error'] = 1;
  3225. } else {
  3226. $temp['error'] = 0;
  3227. }
  3228. if (!$is_third || $topic_answer_upload == 1) {
  3229. $temp['teacher'] = 1;
  3230. } else {
  3231. $temp['teacher'] = 0;
  3232. }
  3233. $exam_id = $val['exam_id'];
  3234. }elseif($check){
  3235. $temp['excel']=1;
  3236. $temp['word']=0;
  3237. $temp['error']=0;
  3238. $temp['teacher']=0;
  3239. }else{
  3240. $temp['excel']=0;
  3241. $temp['word']=0;
  3242. $temp['error']=0;
  3243. $temp['teacher']=0;
  3244. }
  3245. $initData['class'][]=$temp;
  3246. }
  3247. }
  3248. // if(!$exam_id) {
  3249. // $result['msg']='无可下载报告班级';
  3250. // exit(json_encode($result));
  3251. // }
  3252. $result['class']=$classes;
  3253. $username = $this->schoolInfo->school_id;
  3254. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  3255. $url = Yii::app()->params['zsy_api_url'].'/teacher/academic/exam/score/section/'.$this->schoolId.'/'.$exam_id;
  3256. $rs = $this->CrmApiPost($url,array(),$username,$password,'GET');
  3257. if(isset($rs->errCode) && $rs->errCode =='00')
  3258. {
  3259. $result['success']=1;
  3260. $initData['scorePart']=$rs->data;
  3261. }
  3262. $result['success']=1;
  3263. $result['data']=$initData;
  3264. exit(json_encode($result));
  3265. }
  3266. //发送任务
  3267. public function actionPushTask(){
  3268. $exam_group_id = Req::post("examGroupId");
  3269. $download_type = Req::post("download_type");
  3270. $classes = Req::post("class_ids");
  3271. //新字段
  3272. $param['hasStudentNo'] = (int)Req::post("hasStudentNo"); //是否有学号
  3273. $param['hasStudentSystemCard'] = (int)Req::post("hasStudentSystemCard"); //是否有学生系统准考证号
  3274. $param['hasStudentSchoolCard'] = (int)Req::post("hasStudentSchoolCard"); //是否有学生学校准考证号
  3275. $param['hasIdNumber'] = (int)Req::post("hasIdNumber"); //是否有身份证
  3276. $param['removeOuterStudent'] = (int)Req::post("removeOuterStudent"); //是否移除借读生
  3277. $param['removeZeroStudent'] = (int)Req::post("removeZeroStudent"); //过滤0分考生
  3278. $param['hasClazzAchievement'] = (int)Req::post("hasClazzAchievement"); //班级成绩分析表
  3279. $param['hasStudentAchievementRank'] = (int)Req::post("hasStudentAchievementRank"); //学生成绩排名分析表
  3280. $param['hasGradeAchievement'] = (int)Req::post("hasGradeAchievement"); //年级成绩分析表
  3281. $param['hasClazzAvgScore'] = (int)Req::post("hasClazzAvgScore"); //班级平均分表
  3282. $param['hasScoreSection'] = (int)Req::post("hasScoreSection"); //班级分数段表
  3283. $param['hasSubjectAchievement'] = (int)Req::post("hasSubjectAchievement"); //各科成绩分析表
  3284. $param['hasWenLiZongDetail'] = (int)Req::post("hasWenLiZongDetail"); //是否有文综理综单科成绩明细报表
  3285. $param['scoreSection'] = Req::post('scoreSection'); //总分段
  3286. $param['isSimpleClazzAchievement'] = (int)Req::post("isSimpleClazzAchievement"); //班级学生成绩分析表(完整版:0;简易版:1,简易版不提供题目统计、答错人数、选项统计、分数段人数、缺考人数)
  3287. $param['isSimpleClazzAvgScore'] = (int)Req::post("isSimpleClazzAvgScore"); //班级平均分表(完整版:0;简易版:1,简易版不提供题目统计)
  3288. $param['isSimpleGradeAchievement'] = (int)Req::post("isSimpleGradeAchievement"); //年级学生成绩分析表(完整版:0;简易版:1,简易版不提供题目统计、答错人数、选项统计、分数段人数)
  3289. $param['totalScoreCoefficient'] = Req::post("totalScoreCoefficient"); //总分系数
  3290. $param['excellentRatio'] = Req::post('excellentRatio'); //优秀率
  3291. $param['goodRatio'] = Req::post('goodRatio'); //良好率
  3292. $param['mediumRatio'] = Req::post('mediumRatio'); //中等率
  3293. $param['reportType'] = Req::post('reportType'); //中等率
  3294. $param['showSetting'] = Req::post("scoreOfEachQuestion"); //每题得分(学生答案,学生得分)
  3295. $param['paperSizeType'] = Req::post("paperSizeType"); //纸张设置:A4横向:1;A3纵向:2;默认1;
  3296. $param['showRankingChanges'] = (int)Req::post("showRankingChanges"); //是否显示排名升降 显示:1;隐藏:0
  3297. $param['totalScoreCoefficientIsRounding'] = (int)Req::post("totalScoreCoefficientIsRounding"); //启用总分系数后,是否保留小数,0整数,1保留小数
  3298. if(!$param['paperSizeType']) $param['paperSizeType']=1;
  3299. if($param['totalScoreCoefficient']==-1){
  3300. unset($param['totalScoreCoefficient']);
  3301. }
  3302. if(!$exam_group_id){
  3303. $result['msg']='参数错误,缺少考试ID';
  3304. exit(json_encode($result));
  3305. }
  3306. $school_id =$this->schoolId;
  3307. if(isset(Yii::app()->session['session_duoxueke_subject_id'])){
  3308. $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
  3309. }else{
  3310. $subjectId= $this->subjectId;
  3311. }
  3312. $result['status']=0;
  3313. if(!$download_type){
  3314. $result['msg']='请选择下载类型';
  3315. exit(json_encode($result));
  3316. }
  3317. if(!$classes){
  3318. $result['msg']='请选择下载班级';
  3319. exit(json_encode($result));
  3320. }
  3321. $classIds=array();
  3322. $classNames=array();
  3323. if($classes){
  3324. foreach ($classes as $val){
  3325. $classIds[]=$val['id'];
  3326. $classNames[]=$val['className'];
  3327. }
  3328. }
  3329. $examData=$this->sConn->createCommand("select exam_id,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryRow();
  3330. $paperLabelled=$this->sConn->createCommand("select is_labelled from paper where exam_id='{$examData['exam_id']}'")->queryRow();
  3331. if($examData['subject_id']<>12){
  3332. $paperLabelled['is_labelled']=0; //批量下载除物理其它学科不判断标注
  3333. }
  3334. $insertSql="insert into download_table_setting(`school_id`,`exam_group_id`,`download_type`,`status`,`create_time`,`class_ids`,`class_names`,`update_time`,`subject_id`,`config`,`is_labelled`) values";
  3335. $insertSql.="('".$school_id."','".$exam_group_id."','".$download_type."',1,'".time()."','".implode(',',$classIds)."','".implode(',',$classNames)."',".time().",'".$subjectId."','".json_encode($param)."','".$paperLabelled['is_labelled']."')";
  3336. $this->conn->createCommand($insertSql)->execute();
  3337. $last_insert_id = $this->conn->createCommand("select last_insert_id()")->queryRow();
  3338. $taskId=$last_insert_id['last_insert_id()'];
  3339. if($download_type==1){
  3340. $pushData=array('id'=>$taskId);
  3341. // $stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  3342. // $stompconn->send("academic.batchDownloadAchievementReportWord", $pushData);
  3343. sendDataToKafka('zsyte-academic-batch-download-achievement-report-word',$pushData);
  3344. unset($stompconn);
  3345. }elseif ($download_type==2){
  3346. $pushData=array('id'=>$taskId);
  3347. // $stompconn = new Stomp(Yii::app()->params["stomp_address"]);
  3348. // $stompconn->send("academic.batchDownloadAchievementReportExcel", $pushData);
  3349. sendDataToKafka('zsyte-academic-batch-download-achievement-report-excel',$pushData);
  3350. unset($stompconn);
  3351. }
  3352. $result['status']=1;
  3353. exit(json_encode($result));
  3354. }
  3355. //下载进度
  3356. public function actionDownloadProgress(){
  3357. $subject_id=(int)Req::post("subjectId");
  3358. $status=(int)Req::post("status");
  3359. $page=(int)Req::post("page");
  3360. if(!$page) $page=1;
  3361. $pageLimit=10;
  3362. $limit=($page-1)*$pageLimit;
  3363. $result['success']=0;
  3364. $where[]="school_id ='{$this->schoolId}'";
  3365. if($subject_id){
  3366. $where[]="subject_id ='{$subject_id}'";
  3367. }
  3368. if($status){
  3369. $where[]="status ='{$status}'";
  3370. }
  3371. $count=$this->conn->createCommand("select count(*) as count from `download_table_setting` where ".implode(' and ',$where))->queryRow();
  3372. $total=intval($count['count']);
  3373. $pageTotal=ceil($total/$pageLimit);
  3374. $data=$this->conn->createCommand("select id,download_type,status,class_names,zip_url,exam_group_id,class_ids,school_id,subject_id,error_msg from `download_table_setting` where ".implode(' and ',$where)." order by create_time desc limit {$limit},{$pageLimit} ")->queryAll();
  3375. $downTask=array();
  3376. if($data){
  3377. foreach ($data as $val){
  3378. //判断错题本
  3379. if($val['download_type']==4 && !$val['zip_url']){
  3380. $classIds=explode(',',$val['class_ids']);
  3381. $examPdf=$this->sConn->createCommand("select is_topwb_pdf,topwb_pdf_path,name,subject_id from `exam`where exam_group_id='{$val['exam_group_id']}' and class_id in(".implode(',',$classIds).")")->queryAll();
  3382. $files=array();
  3383. $isAllCreate=true;
  3384. $examName='';
  3385. $subjectId=0;
  3386. if($examPdf){
  3387. foreach ($examPdf as $v){
  3388. $examName=$v['name'];
  3389. $subjectId=$v['subject_id'];
  3390. if($v['is_topwb_pdf']==0){
  3391. $isAllCreate=false;
  3392. break;
  3393. }
  3394. if (filter_var(trim($v['topwb_pdf_path']), FILTER_VALIDATE_URL)) { //有http
  3395. $top_url = $v['topwb_pdf_path'];
  3396. }else{
  3397. $top_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/'.$v['topwb_pdf_path'];
  3398. }
  3399. $files[] = $top_url;
  3400. }
  3401. }
  3402. if($isAllCreate){
  3403. //生成压缩包
  3404. $fileName='【'.Yii::app()->params['subjectId'][$subjectId].'】'.'·'.$this->schoolInfo->school_name.'·'.$examName.'·错题前十';
  3405. $zip_url=$this->createZip($files,$fileName);
  3406. //$zip_url=Yii::app()->request->hostInfo.'/'.$zip_url; FIXME 2019-12-23
  3407. if($zip_url){
  3408. $this->conn->createCommand("update `download_table_setting` set status=2,zip_url='".$zip_url."' where id='".$val['id']."'")->execute();
  3409. $val['status']=2;
  3410. $val['zip_url']=$zip_url;
  3411. }
  3412. }
  3413. }
  3414. if($val['download_type']==1){
  3415. $printProductType=60003;
  3416. }elseif($val['download_type']==3) {
  3417. $printProductType = 20003;
  3418. }elseif($val['download_type']==4){
  3419. $printProductType = 10005;
  3420. }else{
  3421. $printProductType=60003;
  3422. }
  3423. if(isset($downTask[$val['exam_group_id']])){
  3424. //组装打印参数
  3425. $printData=array();
  3426. $printData['typeId']=18;
  3427. $printData['productType']=$printProductType;
  3428. $printData['params']=array(
  3429. 'classIds'=>explode(',',$val['class_ids']),
  3430. 'url'=>$val['zip_url'],
  3431. 'name'=>$downTask[$val['exam_group_id']]['examName'],
  3432. 'subjectId'=>$val['subject_id'],
  3433. 'examGroupId'=>$val['exam_group_id'],
  3434. );
  3435. $downTask[$val['exam_group_id']]['task'][]=array(
  3436. 'downloadType'=>$val['download_type'],
  3437. 'id'=>$val['id'],
  3438. 'status'=>$val['status'],
  3439. 'zipUrl'=>$val['zip_url'],
  3440. 'class'=>explode(',',$val['class_names']),
  3441. 'subject'=>Yii::app()->params['subjectId'][$val['subject_id']],
  3442. 'errorMsg'=>$val['error_msg'],
  3443. 'print'=>$printData
  3444. );
  3445. }else{
  3446. //读取考试信息
  3447. $examInfo=$this->sConn->createCommand("select `name` from `exam` where exam_group_id='{$val['exam_group_id']}'")->queryRow();
  3448. // $downTask[$val['exam_group_id']]=array(
  3449. // 'examName'=>$examInfo['name'],
  3450. // 'task'=>array($val),
  3451. // );
  3452. //组装打印参数
  3453. $printData=array();
  3454. $printData['typeId']=18;
  3455. $printData['productType']=$printProductType;
  3456. $printData['params']=array(
  3457. 'classIds'=>explode(',',$val['class_ids']),
  3458. 'url'=>$val['zip_url'],
  3459. 'name'=>$examInfo['name'],
  3460. 'subjectId'=>$val['subject_id'],
  3461. 'examGroupId'=>$val['exam_group_id'],
  3462. );
  3463. $downTask[$val['exam_group_id']]['examName']=$examInfo['name'];
  3464. $downTask[$val['exam_group_id']]['task'][]=array(
  3465. 'downloadType'=>$val['download_type'],
  3466. 'id'=>$val['id'],
  3467. 'status'=>$val['status'],
  3468. 'zipUrl'=>$val['zip_url'],
  3469. 'class'=>explode(',',$val['class_names']),
  3470. 'subject'=>Yii::app()->params['subjectId'][$val['subject_id']],
  3471. 'errorMsg'=>$val['error_msg'],
  3472. 'print'=>$printData
  3473. );
  3474. }
  3475. }
  3476. }
  3477. $result['success']=1;
  3478. $result['pages']=array(
  3479. 'totalPage'=>$pageTotal,
  3480. 'pageLimit'=>$pageLimit,
  3481. 'nowPage'=>$page,
  3482. 'total'=>$total
  3483. );
  3484. $result['data']['listData']=array_values($downTask);
  3485. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  3486. $viewData['subject']=Yii::app()->params['subjectId'];
  3487. unset($viewData['subject'][6]);
  3488. unset($viewData['subject'][51]);
  3489. if(isset($viewData['subject'][20])) unset($viewData['subject'][20]);
  3490. }
  3491. $result['subjects']=$viewData['subject'];
  3492. $result['sessionSubjectId']= Yii::app()->session['session_duoxueke_subject_id'];
  3493. exit(json_encode($result));
  3494. }
  3495. //生成压缩包
  3496. private function createZip($files,$fileName)
  3497. {
  3498. $zipFileName=$fileName.'.zip';
  3499. $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j');
  3500. if(!is_dir($dirFile)){
  3501. $this->mkdir($dirFile);
  3502. }
  3503. $dirFile.='/'.$zipFileName;
  3504. $zip = new ZipArchive;
  3505. $zip->open($dirFile, ZipArchive::CREATE);
  3506. foreach ($files as $file) {
  3507. $ch = curl_init();
  3508. curl_setopt($ch, CURLOPT_POST, 0);
  3509. curl_setopt($ch,CURLOPT_URL,$file);
  3510. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3511. $fileContent = curl_exec($ch);
  3512. curl_close($ch);
  3513. //$zip->addFromString(basename($file), $fileContent);
  3514. $zip->addFromString( iconv('utf-8', 'gbk//ignore', basename($file)), $fileContent);//中文使用这个
  3515. }
  3516. $zip->close();
  3517. if(file_exists($dirFile)){
  3518. //FIXME 20191223
  3519. $rename = 'zsyas2/batchDownLoadFile/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $zipFileName;
  3520. $ucloud = new Qcloud();
  3521. $uploadInfo = $ucloud->putFile($rename, $dirFile);
  3522. @unlink($dirFile);
  3523. if ($uploadInfo['status'] == 0) {
  3524. return false;
  3525. }else{
  3526. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  3527. return $uploadInfo['url'];
  3528. }
  3529. }
  3530. return false;
  3531. }
  3532. public function actionBatch(){
  3533. ini_set('memory_limit', '500M');
  3534. $getName = safe_replace(Yii::app()->request->getQuery('realname'));
  3535. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  3536. $type_id = safe_replace(Yii::app()->request->getQuery('type_id'));
  3537. $grade_class_array = array();
  3538. $searchProcessSubjectId=$this->subjectId;
  3539. $con = array();
  3540. // 打印任务处理
  3541. $ExamModel = Exam::model();
  3542. $ClassModel = ClassModel::model();
  3543. $printList = array();
  3544. $grade_class_data = ClassModel::model()->findAll('grade=:grade', array(':grade' => $grade_id));
  3545. if ($grade_class_data) {
  3546. foreach ($grade_class_data as $v) {
  3547. $grade_class_array[$v->class_id] = $v->attributes;
  3548. }
  3549. }
  3550. // 获取当前学期班级并组装
  3551. $criteria = new CDbCriteria();
  3552. $criteria->addCondition('semester_id=:semester_id');
  3553. if ($grade_id) {
  3554. $con = array('c.grade = ' . $grade_id);
  3555. $criteria->addCondition('grade=:grade');
  3556. $criteria->params[':grade'] = $grade_id;
  3557. }
  3558. if ($getName) {
  3559. $con = array_merge($con, array("e.name like '%{$getName}%'"));
  3560. }
  3561. if(in_array($this->subjectId,$this->mathSubjectId)){
  3562. $con = array_merge($con, array("e.subject_id in (".implode(',',$this->mathSubjectId).")"));
  3563. $searchProcessSubjectId=3;
  3564. }else{
  3565. $con = array_merge($con, array('e.subject_id = ' . $this->subjectId));
  3566. }
  3567. $con = array_merge($con, array('eg.create_type in (0,1,2,3,5,6)'));
  3568. if($type_id){
  3569. if($type_id==1){
  3570. $con =array_merge($con, array('eg.is_third = 0'));
  3571. }elseif($type_id==2){
  3572. $con = array_merge($con, array('eg.is_third = 1'));
  3573. $con = array_merge($con, array('eg.mark_type > 0'));
  3574. }else{
  3575. $con = array_merge($con, array('eg.is_third = 1'));
  3576. $con = array_merge($con, array('eg.mark_type =0'));
  3577. }
  3578. }
  3579. $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
  3580. $resultList = $this->schoolManager->getExportList(array_merge(array("(e.status = 1 or e.status=4)"), $con),array('e.complete_time desc'));
  3581. //$resultList = $this->schoolManager->getExportList(array_merge(array("(e.status = 1 )"), $con),array('e.complete_time desc'));
  3582. if ($resultList["rs"]) {
  3583. foreach ($resultList['rs'] as $k => $v) {
  3584. $printList[$k] = $v;
  3585. //班级数量
  3586. $examIds=$ExamModel->getExamIds($v['exam_group_id']);
  3587. $printList[$k]['class_count']=count($examIds);
  3588. if(isset(Yii::app()->params['grade_list'][$v['grade']])){
  3589. $printList[$k]['grade_name']=Yii::app()->params['grade_list'][$v['grade']]['grade_name'];
  3590. }else{
  3591. $printList[$k]['grade_name']='';
  3592. }
  3593. //试卷类别
  3594. if($v['is_third']==0){
  3595. $printList[$k]['type_name'] = '校本课程平台试卷';
  3596. }elseif($v['is_third']==1){
  3597. if($v['mark_type']==0){
  3598. $printList[$k]['type_name'] = '第三方导入成绩试卷';
  3599. }else{
  3600. $printList[$k]['type_name'] = '第三方线上阅卷试卷';
  3601. }
  3602. }
  3603. //考试日期
  3604. $tplData=json_decode($v['tpl_data'],true);
  3605. if(isset($tplData['examDate'])){
  3606. $printList[$k]['exam_date'] =$tplData['examDate'];
  3607. }else{
  3608. $printList[$k]['exam_date'] ='';
  3609. }
  3610. //试题数量
  3611. if(isset($tplData['totals'])){
  3612. $printList[$k]['topic_count'] =$tplData['totals'];
  3613. }else{
  3614. $printList[$k]['topic_count'] =0;
  3615. }
  3616. }
  3617. }
  3618. $data = array();
  3619. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  3620. $data['realname'] = $getName;
  3621. $data['grade_id'] = $grade_id;
  3622. $data['grade_class'] = $grade_class_array;
  3623. $data['printList'] = $printList;
  3624. $data['pages'] = $resultList['pager'];
  3625. $data['page_total'] = $resultList['pager']->rowsCount;
  3626. //$data["subject"] = $subject_exam_data;
  3627. $data['searchProcessSubjectId']=$searchProcessSubjectId;
  3628. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  3629. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  3630. } else {
  3631. $data["use_zhixue"] = 0;
  3632. }
  3633. $data['past_sem_exist'] = 0;//默认不存在过去的学期
  3634. $data['type_id']=$type_id;
  3635. $sql = 'select start_time from semester where status=1 limit 1';
  3636. $res = $this->sConn->createCommand($sql)->queryRow();
  3637. $start_time = $res['start_time'];
  3638. if (!$start_time) {
  3639. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  3640. }
  3641. $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
  3642. $res = $this->sConn->createCommand($sql)->queryRow();
  3643. $row_num = $res['rownum'];
  3644. $row_num && $data['past_sem_exist']=1;
  3645. unset($resultList);
  3646. $this->render('index2', $data);
  3647. }
  3648. public function actionBatch_duo(){
  3649. ini_set('memory_limit', '300M');
  3650. $getName = safe_replace(Yii::app()->request->getQuery('realname'));
  3651. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  3652. $type_id = safe_replace(Yii::app()->request->getQuery('type_id'));
  3653. $grade_class_array = array();
  3654. $searchProcessSubjectId=Yii::app()->session['session_duoxueke_subject_id'];
  3655. $con = array();
  3656. // 打印任务处理
  3657. $ExamModel = Exam::model();
  3658. $ClassModel = ClassModel::model();
  3659. $printList = array();
  3660. $grade_class_data = ClassModel::model()->findAll('grade=:grade', array(':grade' => $grade_id));
  3661. if ($grade_class_data) {
  3662. foreach ($grade_class_data as $v) {
  3663. $grade_class_array[$v->class_id] = $v->attributes;
  3664. }
  3665. }
  3666. // 获取当前学期班级并组装
  3667. $criteria = new CDbCriteria();
  3668. $criteria->addCondition('semester_id=:semester_id');
  3669. if ($grade_id) {
  3670. $con = array('c.grade = ' . $grade_id);
  3671. $criteria->addCondition('grade=:grade');
  3672. $criteria->params[':grade'] = $grade_id;
  3673. }
  3674. if ($getName) {
  3675. $con = array_merge($con, array("e.name like '%{$getName}%'"));
  3676. }
  3677. if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
  3678. $con = array_merge($con, array("e.subject_id in (".implode(',',$this->mathSubjectId).")"));
  3679. $searchProcessSubjectId=3;
  3680. }else{
  3681. $con = array_merge($con, array('e.subject_id = ' . Yii::app()->session['session_duoxueke_subject_id']));
  3682. }
  3683. $con = array_merge($con, array('eg.create_type in (0,1,2,3,5,6)'));
  3684. if($type_id){
  3685. if($type_id==1){
  3686. $con =array_merge($con, array('eg.is_third = 0'));
  3687. }elseif($type_id==2){
  3688. $con = array_merge($con, array('eg.is_third = 1'));
  3689. $con = array_merge($con, array('eg.mark_type > 0'));
  3690. }else{
  3691. $con = array_merge($con, array('eg.is_third = 1'));
  3692. $con = array_merge($con, array('eg.mark_type =0'));
  3693. }
  3694. }
  3695. //如果是物理去掉全学科的组卷
  3696. if($searchProcessSubjectId == 12){
  3697. $con = array_merge($con, array('(eg.qxk_paper_id is null or eg.qxk_paper_id=0)'));
  3698. }
  3699. $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
  3700. $resultList = $this->schoolManager->getExportList(array_merge(array("(e.status = 1 or e.status=4)"), $con),array('e.complete_time desc'));
  3701. //$resultList = $this->schoolManager->getExportList(array_merge(array("(e.status = 1)"), $con),array('e.complete_time desc'));
  3702. if ($resultList["rs"]) {
  3703. foreach ($resultList['rs'] as $k => $v) {
  3704. $printList[$k] = $v;
  3705. //班级数量
  3706. $examIds=$ExamModel->getExamIds($v['exam_group_id']);
  3707. $printList[$k]['class_count']=count($examIds);
  3708. if(isset(Yii::app()->params['grade_list'][$v['grade']])){
  3709. $printList[$k]['grade_name']=Yii::app()->params['grade_list'][$v['grade']]['grade_name'];
  3710. }else{
  3711. $printList[$k]['grade_name']='';
  3712. }
  3713. //试卷类别
  3714. if($v['is_third']==0){
  3715. $printList[$k]['type_name'] = '校本课程平台试卷';
  3716. }elseif($v['is_third']==1){
  3717. if($v['mark_type']==0){
  3718. $printList[$k]['type_name'] = '第三方导入成绩试卷';
  3719. }else{
  3720. $printList[$k]['type_name'] = '第三方线上阅卷试卷';
  3721. }
  3722. }
  3723. //考试日期
  3724. $tplData=json_decode($v['tpl_data'],true);
  3725. if(isset($tplData['examDate'])){
  3726. $printList[$k]['exam_date'] =$tplData['examDate'];
  3727. }else{
  3728. $printList[$k]['exam_date'] ='';
  3729. }
  3730. //试题数量
  3731. if(isset($tplData['totals'])){
  3732. $printList[$k]['topic_count'] =$tplData['totals'];
  3733. }else{
  3734. $printList[$k]['topic_count'] =0;
  3735. }
  3736. }
  3737. }
  3738. // debug($printList);
  3739. $data = array();
  3740. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  3741. $data['realname'] = $getName;
  3742. $data['grade_id'] = $grade_id;
  3743. $data['grade_class'] = $grade_class_array;
  3744. $data['printList'] = $printList;
  3745. $data['pages'] = $resultList['pager'];
  3746. $data['page_total'] = $resultList['pager']->rowsCount;
  3747. // $data["subject"] = $subject_exam_data;
  3748. $data['searchProcessSubjectId']=$searchProcessSubjectId;
  3749. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  3750. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  3751. } else {
  3752. $data["use_zhixue"] = 0;
  3753. }
  3754. $data['past_sem_exist'] = 0;//默认不存在过去的学期
  3755. $data['type_id']=$type_id;
  3756. $sql = 'select start_time from semester where status=1 limit 1';
  3757. $res = $this->sConn->createCommand($sql)->queryRow();
  3758. $start_time = $res['start_time'];
  3759. if (!$start_time) {
  3760. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  3761. }
  3762. $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
  3763. $res = $this->sConn->createCommand($sql)->queryRow();
  3764. $row_num = $res['rownum'];
  3765. $row_num && $data['past_sem_exist']=1;
  3766. unset($resultList);
  3767. // debug($data);
  3768. $this->render('index2_duo', $data);
  3769. }
  3770. //删除任务
  3771. public function actionDeleteTask(){
  3772. $ids = Req::post("ids");
  3773. $result['success']=0;
  3774. if(!$ids){
  3775. $result['msg']='请选择删除的任务';
  3776. exit(json_encode($result));
  3777. }
  3778. $rs=$this->conn->createCommand("delete from download_table_setting where id in(".implode(',',$ids).") ")->execute();
  3779. if($rs){
  3780. $result['success']=1;
  3781. exit(json_encode($result));
  3782. }
  3783. }
  3784. private function mkdir($path, $chmod = 0755){
  3785. return is_dir($path) || (self::mkdir(dirname($path), $chmod) && mkdir($path, $chmod));
  3786. }
  3787. /**
  3788. * 发送消息队列
  3789. * @return mixed
  3790. */
  3791. private function sendKafka($topic='',$data = array())
  3792. {
  3793. if ($data) {
  3794. $conf = new RdKafka\Conf();
  3795. $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
  3796. $producer = new RdKafka\Producer($conf);
  3797. $topic = $producer->newTopic($topic);
  3798. $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data));
  3799. $producer->poll(0);
  3800. $result = $producer->flush(10000);
  3801. if($result===0){
  3802. return true;
  3803. }
  3804. // $destination = 'zsyte.markingFinishedNotify';
  3805. //
  3806. // $stomp_address = Yii::app()->params['markingFinishedNotifyAddress'];
  3807. //
  3808. // $stomp = new Stomp($stomp_address);
  3809. // $stomp->subscribe($destination);
  3810. //
  3811. //// $data = array('schoolId'=>123,'examGroupId'=>45679794,'examIds'=>array('54646465'));
  3812. //
  3813. // $bool = $stomp->send($destination, json_encode($data));
  3814. }
  3815. return true;
  3816. }
  3817. /*
  3818. * 假期报告
  3819. */
  3820. public function actionHoliday_index(){
  3821. Url::clean();
  3822. $data = array();
  3823. $classId = Req::get("classId");
  3824. $grade = (int)Req::get("grade");
  3825. $semsterId = (string)Req::get("semesterId");
  3826. $limit = (int)Req::get("limit") ? (int)Req::get("limit") :10;
  3827. $newCondition = array();
  3828. $schoolId = $this->schoolId;
  3829. if($grade){
  3830. $newCondition[] = 'hrs.grade='.$grade;
  3831. }
  3832. if($classId){
  3833. $newCondition[] = 'hrs.class_id='.$classId;
  3834. }
  3835. if(!$semsterId){
  3836. $semsterId = $this->semesterId;
  3837. }
  3838. if($semsterId){
  3839. $newCondition[] = 'hrs.semester_id='.$semsterId;
  3840. }
  3841. $resultList = $this->schoolManager->getHolidayReport($newCondition,array('hrs.create_time desc','hrs.report_id desc'),$limit);
  3842. $printList = array();
  3843. if($resultList["rs"]){
  3844. foreach ($resultList['rs'] as $k=>$v) {
  3845. $printList[$k]=$v;
  3846. }
  3847. }
  3848. if (empty($grade)) {
  3849. $grade = 'ALL';
  3850. }
  3851. // $classes = $this->schoolManager->getClasses($grade);
  3852. //获取全学科试用学校
  3853. $url = Yii::app()->params['zsy_api_url'].'/cms/api/qxk-math-trial-school/'.$this->schoolId;
  3854. $username = $this->schoolInfo->school_id;
  3855. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  3856. $rs = $this->CrmApiPost($url,array(),$username,$password,'GET');
  3857. $is_qxk_school = (isset($rs->errCode) && $rs->errCode =='00')?$rs->data:false;//是否全学科试用学校---true是全学科--全学科走新的redis的key
  3858. $mkey = $is_qxk_school?"qxk_holiday_school_semester":"holiday_school_semester";
  3859. $semsters = $this->schoolManager->getSemesters();
  3860. $sql = "select report_id from holiday_report_setting where semester_id= '{$semsterId}'";
  3861. $res = $this->sConn->createCommand($sql)->queryRow();
  3862. if(!$res){
  3863. if((string)$semsterId === (string)$this->semesterId){
  3864. $is_current_semester = 1;
  3865. }else{
  3866. $is_current_semester = 0;
  3867. }
  3868. $status = $this->schoolManager->batchInsetHolidayReport($schoolId,$semsterId,$is_current_semester,$is_qxk_school);
  3869. if(isset($status["status"]) && $status["status"] == 1){
  3870. /**
  3871. * 发送redis开始跑数据
  3872. */
  3873. // $holiday_status = Yii::app()->holiday_report->hmget('holiday_school_semester',array($schoolId.':'.$semsterId));
  3874. // if($holiday_status && isset($holiday_status[0]) && $holiday_status[0]){
  3875. Yii::app()->holiday_report->hmset($mkey,array($schoolId.':'.$semsterId=>0));
  3876. // }
  3877. $resultList = $this->schoolManager->getHolidayReport($newCondition,array('hrs.create_time desc','hrs.report_id desc'),$limit);
  3878. $printList = array();
  3879. if($resultList["rs"]){
  3880. foreach ($resultList['rs'] as $k=>$v) {
  3881. $printList[$k]=$v;
  3882. }
  3883. }
  3884. }
  3885. }
  3886. // debug($resultList);
  3887. if(isset($resultList) && $resultList){
  3888. $data['is_all_pdf'] = isset($resultList['is_all_pdf'])?$resultList['is_all_pdf']:0;
  3889. $data['create_time'] = isset($resultList['create_time'])?$resultList['create_time']:0;
  3890. }
  3891. $class_select_arr = array();
  3892. if($semsterId){
  3893. $class_select_arr[] = "hrs.semester_id=".$semsterId;
  3894. }
  3895. if(in_array($grade,array(1,2,3))){
  3896. $class_select_arr[] = "c.grade=".$grade;
  3897. }
  3898. // $class_select_arr[] = "c.class_type=1";
  3899. $classes = $this->schoolManager->getClassesByHolidayReport($class_select_arr,array());
  3900. $data['limit'] = $limit;
  3901. $data['pages'] = $resultList['pager'];
  3902. $data['page_total'] = $resultList['pager']->rowsCount;
  3903. $data['printList'] = $printList;
  3904. $data["classes"] = $classes;
  3905. $data["classId"] = $classId;
  3906. $data["grade"] = $grade;
  3907. $data["semsterId"] = $semsterId;
  3908. $data["semsters"] = $semsters;
  3909. //数据生成状态
  3910. $data['data_status'] = 0;
  3911. $data_status_arr = Yii::app()->holiday_report->hmget($mkey,array($schoolId.':'.$semsterId));
  3912. if($data_status_arr && isset($data_status_arr[0]) && $data_status_arr[0]){
  3913. $data['data_status'] = $data_status_arr[0];
  3914. }
  3915. //批量重置数量
  3916. $holiday_school_semester = Yii::app()->add_exam_class->hmget('zsyas2:holiday_school_reset',array($this->schoolId.'_'.$semsterId));
  3917. if($holiday_school_semester && $holiday_school_semester[0]){
  3918. $data['reset_time'] = $holiday_school_semester[0];
  3919. }else{
  3920. $data['reset_time'] = 0;
  3921. }
  3922. $this->render('holiday_index',$data);
  3923. }
  3924. /**
  3925. * 假期报告设置
  3926. */
  3927. public function actionAjaxSettingHolidayReport(){
  3928. $semesterId = $this->semesterId;
  3929. $schoolId = $this->schoolId;
  3930. $report_ids = getBatchUuid($schoolId,100);
  3931. debug(array_values($report_ids));
  3932. $status = $this->schoolManager->batchInsetHolidayReport($schoolId,$semesterId);
  3933. }
  3934. /**
  3935. * 假期报告选择学生
  3936. */
  3937. public function actionSelectStuByHolidayReport(){
  3938. $data = array();
  3939. $sname = (string)Req::get("sname"); //学生名字
  3940. $reportId = (string)Req::get("reportId");
  3941. if(!$reportId){
  3942. Yii::app()->jump->error('参数错误!');
  3943. }
  3944. //获取班级名称以及周后推送名称
  3945. $sql = "select c.class_name,hrs.grade,hrs.class_id,hrs.create_time,hrs.semester_id,s.semester_name from holiday_report_setting hrs join class c on hrs.class_id = c.class_id join semester s on s.semester_id = hrs.semester_id where hrs.report_id = '{$reportId}'";
  3946. $names = $this->sConn->createCommand($sql)->queryRow();
  3947. // debug($names);
  3948. if(!$names){
  3949. $names = array();
  3950. $names['name'] = '';
  3951. $names['class_name'] = '';
  3952. $names['grade'] = 0;
  3953. }else{
  3954. $data['name'] = $names['semester_name'].'假期总结报告'.'---'.$names['class_name'];
  3955. }
  3956. $sql = "select student_id,is_report_pdf from holiday_report_student where report_id = '{$reportId}'";
  3957. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  3958. $studentIds = array();
  3959. $stuIsPdf = array();
  3960. if($relateStudent){
  3961. foreach ($relateStudent as $studentInfo) {
  3962. $studentIds[] = (string)$studentInfo['student_id'];
  3963. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_report_pdf'];
  3964. }
  3965. }
  3966. if($studentIds){
  3967. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  3968. if($studentNames){
  3969. if($sname){
  3970. $i = 1;
  3971. foreach($studentNames as $k=>$v){
  3972. if(strpos($v,$sname) !== false){
  3973. $data['list'][$i]['stu_id'] = (string)$k;
  3974. $data['list'][$i]['stu_name'] = $v;
  3975. $data['list'][$i]['name'] = $names['class_name'].$v.'假期报告';
  3976. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  3977. $i++;
  3978. }
  3979. }
  3980. }else{
  3981. $i = 1;
  3982. foreach($studentNames as $k=>$v){
  3983. $data['list'][$i]['stu_id'] = (string)$k;
  3984. $data['list'][$i]['stu_name'] = $v;
  3985. $data['list'][$i]['name'] = $names['class_name'].$v.'假期报告';
  3986. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  3987. $i++;
  3988. }
  3989. }
  3990. }
  3991. $intarr=array(
  3992. "subject"=>3,
  3993. "grade"=>$names['grade'],
  3994. "examTime"=>$names['create_time'],
  3995. "students"=>$studentIds,
  3996. );
  3997. //暂时去掉验证订单权限
  3998. $data['limitstu']=$studentIds;
  3999. /*
  4000. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  4001. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url_gather"], json_encode($intarr),$basic),true);
  4002. if(!$rs){
  4003. Yii::app()->jump->error("接口错误");
  4004. }
  4005. if($rs['errCode']!="00"){
  4006. Yii::app()->jump->error($rs['errMsg']);
  4007. }
  4008. if(!empty($rs['data'])){
  4009. $data['limitstu']=$rs['data'];
  4010. }*/
  4011. }
  4012. $data['reportId'] = $reportId;
  4013. $data['sname'] = $sname;
  4014. // debug($data);
  4015. $this->render('holiday_report_stu',$data);
  4016. }
  4017. /**
  4018. * 下载假期报告
  4019. */
  4020. public function actionGetHolidayReportFile(){
  4021. $reportId = (string)Req::get("reportId");
  4022. $studentsIds = (string)Req::get("studentsIds");
  4023. $params = array();
  4024. if(!$reportId){
  4025. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  4026. exit();
  4027. }
  4028. //获取组ID
  4029. $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  4030. $report_settint_data = $this->sConn->createCommand($sql)->queryRow();
  4031. if(!$report_settint_data){
  4032. echo json_encode(array("success" => 0, "message" => "设置信息错误"));
  4033. exit();
  4034. }else{
  4035. $school_group_id = $report_settint_data['school_group_id'];
  4036. }
  4037. if(isset($school_group_id) && $school_group_id){
  4038. $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
  4039. }else{
  4040. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  4041. }
  4042. if(!$studentsIds){
  4043. $studentsIds = array();
  4044. $sql = "select student_id from holiday_report_student where report_id = '{$reportId}' and is_report_pdf = 1";
  4045. $stuArr = $this->sConn->createCommand($sql)->queryAll();
  4046. if($stuArr){
  4047. foreach($stuArr as $k=>$v){
  4048. $studentsIds[] = $v['student_id'];
  4049. }
  4050. }
  4051. }else{
  4052. $studentsIds = explode(',',$studentsIds);
  4053. }
  4054. if(!$studentsIds || empty($studentsIds)){
  4055. echo json_encode(array("success" => 0, "message" => "无生成的学生"));
  4056. exit();
  4057. }
  4058. $params['reportId'] = $reportId;
  4059. // $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  4060. if(!$apiUrl){
  4061. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  4062. exit();
  4063. }
  4064. $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  4065. $msg = $this->sConn->createCommand($sql)->queryRow();
  4066. $Sem=new SSemester();
  4067. $code= $Sem->conn->createQuery()
  4068. ->from('semester')
  4069. ->where("semester_id = '".$msg['semester_id']."'")
  4070. ->limit(1)
  4071. ->query()
  4072. ->read();
  4073. $intarr=array(
  4074. "schoolId"=>$this->schoolId,
  4075. "clazzId"=>$msg['class_id'],
  4076. "semester"=>$code['refer_code'],
  4077. "grade"=>$msg['grade'],
  4078. "students"=>$studentsIds,
  4079. "examTime"=>$msg['create_time'],
  4080. "classify"=>6,
  4081. "subject"=>8
  4082. );
  4083. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  4084. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  4085. if($studentsIds){
  4086. $params["studentIds"] = $studentsIds;
  4087. }
  4088. }else{
  4089. if(Yii::app()->params["limit_open"]){
  4090. // $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  4091. // $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  4092. $intarr=array(
  4093. "subject"=>3,
  4094. "grade"=>$msg['grade'],
  4095. "examTime"=>$msg['create_time'],
  4096. "students"=>$studentsIds,
  4097. );
  4098. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  4099. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url_gather"], json_encode($intarr),$basic),true);
  4100. if(!$rs){
  4101. Yii::app()->jump->error("接口错误");
  4102. }
  4103. if($rs['errCode']!="00"){
  4104. echo json_encode(array("success" => 0, "message" => $rs['errMsg']));
  4105. exit();
  4106. }
  4107. if(!empty($rs['data'])){
  4108. $params["studentIds"]=$rs['data'];
  4109. if(count($rs['data'])<count($intarr['students'])){
  4110. $limitinfo="购买过的".count($intarr['students'])-count($rs['data'])."位学生可下载";
  4111. }
  4112. } else{
  4113. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  4114. exit();
  4115. }
  4116. }else{
  4117. if($studentsIds){
  4118. $params["studentIds"] = $studentsIds;
  4119. }
  4120. }
  4121. }
  4122. $params['schoolId'] = $this->schoolId;
  4123. $params['type'] = 4;
  4124. // $apiUrl = "http://zsyapi.testing.xueping.com";
  4125. $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
  4126. if(!($rs = json_decode($rs))){
  4127. $rs = array(
  4128. "success" => 0,
  4129. "message" => "请求接口失败",
  4130. );
  4131. }else{
  4132. //更新下载时间
  4133. $time = time();
  4134. if($studentsIds){
  4135. $sql = "update holiday_report_student set is_report_download = 1,report_download_time={$time} where report_id = '{$reportId}' and student_id in (".implode(',',$studentsIds).") and report_download_time = 0";
  4136. $this->sConn->createCommand($sql)->execute();
  4137. }
  4138. }
  4139. // if(isset($rs->downloadPath)){
  4140. // if (YII_ENV == 'pro' || YII_ENV == 'production') {
  4141. // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
  4142. // }
  4143. // }
  4144. echo json_encode($rs);exit;
  4145. }
  4146. /**
  4147. * 重置假期报告
  4148. */
  4149. public function actionAjaxResetHolidayReport(){
  4150. $reportId = Req::post('report_id');
  4151. $classId = Req::post('class_id');
  4152. $semsterId = Req::post('semster_id');
  4153. $schoolId = $this->schoolId;
  4154. if(!$reportId){
  4155. echo json_encode(array("status"=>0,"result"=>"假期报告ID不能为空"));exit;
  4156. }
  4157. if(!$classId){
  4158. echo json_encode(array("status"=>0,"result"=>"班级ID不能为空"));exit;
  4159. }
  4160. if(!$semsterId){
  4161. echo json_encode(array("status"=>0,"result"=>"学期ID不能为空"));exit;
  4162. }
  4163. if((string)$semsterId === (string)$this->semesterId){
  4164. $is_current_semester = 1;
  4165. }else{
  4166. $is_current_semester = 0;
  4167. }
  4168. //获取全学科试用学校
  4169. $url = Yii::app()->params['zsy_api_url'].'/cms/api/qxk-math-trial-school/'.$this->schoolId;
  4170. $username = $this->schoolInfo->school_id;
  4171. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  4172. $rs = $this->CrmApiPost($url,array(),$username,$password,'GET');
  4173. $is_qxk_school = (isset($rs->errCode) && $rs->errCode =='00')?$rs->data:false;//是否全学科试用学校---true是全学科--全学科走新的redis的key
  4174. $mkey = $is_qxk_school?"qxk_holiday_school_semester":"holiday_school_semester";
  4175. $status = $this->schoolManager->resetReport($reportId,$classId,$is_current_semester,$is_qxk_school);
  4176. Yii::app()->holiday_report->hmset($mkey,array($schoolId.':'.$semsterId=>0));
  4177. if($status){
  4178. echo json_encode(array("status"=>1,"result"=>"重置成功"));exit;
  4179. }else{
  4180. echo json_encode(array("status"=>0,"result"=>"重置失败"));exit;
  4181. }
  4182. }
  4183. /**
  4184. * 批量下载假期报告
  4185. */
  4186. public function actionAjaxBatchPrintHoliday(){
  4187. }
  4188. /**
  4189. * 批量重置假期报告
  4190. */
  4191. public function actionAjaxBatchResetHoliday(){
  4192. $semesterId = Req::post("semster_id");
  4193. if(!$semesterId){
  4194. echo json_encode(array("status"=>0,"result"=>"请指定学期Id"));exit;
  4195. }
  4196. // echo $semesterId;exit;
  4197. $school_id = $this->schoolId;
  4198. $holiday_school_semester = Yii::app()->add_exam_class->hmget('zsyas2:holiday_school_reset',array($school_id.'_'.$semesterId));
  4199. if($holiday_school_semester && $holiday_school_semester[0]){
  4200. $reset_time = $holiday_school_semester[0];
  4201. }else{
  4202. $reset_time = 0;
  4203. }
  4204. if($reset_time > 4){
  4205. echo json_encode(array("status"=>0,"result"=>"重置次数不能超过5次"));exit;
  4206. }
  4207. //获取全学科试用学校
  4208. $url = Yii::app()->params['zsy_api_url'].'/cms/api/qxk-math-trial-school/'.$this->schoolId;
  4209. $username = $this->schoolInfo->school_id;
  4210. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  4211. $rs = $this->CrmApiPost($url,array(),$username,$password,'GET');
  4212. $is_qxk_school = (isset($rs->errCode) && $rs->errCode =='00')?$rs->data:false;//是否全学科试用学校---true是全学科--全学科走新的redis的key
  4213. $status = $this->schoolManager->batchResetReport($semesterId);
  4214. $mkey = $is_qxk_school?"qxk_holiday_school_semester":"holiday_school_semester";
  4215. Yii::app()->holiday_report->hmset($mkey,array($school_id.':'.$semesterId=>0));
  4216. if($status){
  4217. $holiday_school_semester = Yii::app()->add_exam_class->hmset('zsyas2:holiday_school_reset',array($school_id.'_'.$semesterId=>$reset_time+1));
  4218. echo json_encode(array("status"=>1,"result"=>"批量重置成功"));exit;
  4219. }else{
  4220. echo json_encode(array("status"=>0,"result"=>"批量重置失败"));exit;
  4221. }
  4222. }
  4223. function curlDownloadImage($url)
  4224. {
  4225. if (empty($url)) {
  4226. return false;
  4227. }
  4228. $curl = curl_init($url);
  4229. // 不取回数据
  4230. curl_setopt($curl, CURLOPT_NOBODY, true);
  4231. // 发送请求
  4232. $result = curl_exec($curl);
  4233. $found = false;
  4234. // 如果请求没有发送失败
  4235. if ($result !== false) {
  4236. // 再检查http响应码是否为200
  4237. $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  4238. if ($statusCode == 200) {
  4239. $found = true;
  4240. }
  4241. }
  4242. curl_close($curl);
  4243. return $found;
  4244. }
  4245. function curlDownload($url,$title)
  4246. {
  4247. if (empty($url) || empty($title)) {
  4248. return false;
  4249. }
  4250. $ext=substr($url,strrpos($url,'.')+1);
  4251. $path='upload/tmpDir/downloadTempFiled/';
  4252. if (!file_exists($path)) {
  4253. mkdir($path, 0777, true);
  4254. }
  4255. $pathName=$path.$title.'.'.$ext;
  4256. $pathName = iconv('UTF-8', 'GBK', $pathName);
  4257. // 获取远程文件资源
  4258. $ch = curl_init();
  4259. curl_setopt($ch, CURLOPT_URL, $url);
  4260. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4261. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
  4262. $tempFile = curl_exec($ch);
  4263. curl_close($ch);
  4264. // 保存文件
  4265. $fp = @fopen($pathName, "w");
  4266. fwrite($fp, $tempFile);
  4267. fclose($fp);
  4268. header('content-type:application/octet-stream');
  4269. header('content-disposition:attachment; filename='.$title.'.'.$ext);
  4270. header('content-length:'.filesize($pathName));
  4271. readfile($pathName);
  4272. }
  4273. /**
  4274. * 教师讲案高考真题
  4275. * @exam_id 考试ID
  4276. * @class_id 班级ID
  4277. * @has_topic 教师讲案其他题集合
  4278. * @weak_methodids 共性题考点
  4279. * @paper_methodids 试卷考点
  4280. */
  4281. function acadGaokao($exam_id,$class_id,$has_topic,$weak_methodids,$paper_methodids){
  4282. //最终抽出来的题
  4283. $final_topic = array();
  4284. if(!$weak_methodids){
  4285. return $final_topic;
  4286. }else{
  4287. $topic_data = $this->aipost('/relation_math/true_topic', array('methodIds' => $weak_methodids));
  4288. if($topic_data && isset($topic_data['data']) && $topic_data['data']){
  4289. $topic_pool = $topic_data['data'];
  4290. }else{
  4291. return $final_topic;
  4292. }
  4293. }
  4294. //step1 过滤已经存在的题
  4295. if($has_topic){
  4296. foreach($topic_pool as $k=>$v){
  4297. if(in_array($k,$has_topic)){
  4298. unset($topic_pool[$k]);
  4299. }
  4300. }
  4301. }
  4302. //step2 过滤超纲的题
  4303. if($paper_methodids){
  4304. foreach($topic_pool as $k=>$v){
  4305. foreach($v as $method){
  4306. if(!in_array($method,$paper_methodids)){
  4307. unset($topic_pool[$k]);
  4308. continue;
  4309. }
  4310. }
  4311. }
  4312. }
  4313. //step3 优先抽全部薄弱考点的题,如果题不够,逐一减少薄弱考点,直到抽到2题为止 $weak_methodids(薄弱考点)
  4314. if($topic_pool){
  4315. //整理数据
  4316. $topic_methods_count = array();//题目对应薄弱考点数量
  4317. $count_to_topic = array();//薄弱考点数量对应题目
  4318. foreach($topic_pool as $k=>$v){
  4319. foreach($v as $method){
  4320. if(in_array($method,$weak_methodids)){
  4321. if(!isset($topic_methods_count[$k])){
  4322. $topic_methods_count[$k] = 1;
  4323. }else{
  4324. $topic_methods_count[$k] ++;
  4325. }
  4326. }
  4327. }
  4328. }
  4329. if($topic_methods_count){
  4330. foreach($topic_methods_count as $k=>$v){
  4331. for($a=1;$a<=$v;$a++){
  4332. if(!isset($count_to_topic[$a])){
  4333. $count_to_topic[$a] = array();
  4334. }
  4335. $count_to_topic[$a][] = $k;
  4336. }
  4337. }
  4338. }
  4339. if($count_to_topic){
  4340. krsort($count_to_topic);//根据薄弱考点数量倒序
  4341. foreach($count_to_topic as $k=>$v){
  4342. foreach($v as $topic_id){
  4343. if(count($final_topic) > 1){
  4344. break;
  4345. }
  4346. if(!in_array($topic_id,$final_topic)){
  4347. $final_topic[] = $topic_id;
  4348. }
  4349. }
  4350. }
  4351. }
  4352. }
  4353. //过滤完没题就随机抽两题
  4354. if(!$final_topic || count($final_topic) < 2){
  4355. $topic_keys = array_keys($topic_pool);
  4356. shuffle($topic_keys);
  4357. foreach($topic_keys as $k=>$v){
  4358. if(count($final_topic) > 1){
  4359. break;
  4360. }
  4361. if(!in_array($v,$final_topic)){
  4362. $final_topic[] = $v;
  4363. }
  4364. }
  4365. }
  4366. //插入数据
  4367. if($final_topic){
  4368. $delSql = "delete from gaokao_academicr_topic where exam_id = '".$exam_id."'";
  4369. $insertSql="insert into gaokao_academicr_topic (`exam_id`,`class_id`,`topic_id`,`create_time`) values";
  4370. $insertSqlStr = "";
  4371. foreach($final_topic as $k=>$v){
  4372. $insertSqlStr.="('".$exam_id."','".$class_id."','".$v."','".time()."'),";
  4373. }
  4374. $insertSql .= substr($insertSqlStr, 0, -1);
  4375. $this->sConn->createCommand($delSql)->execute();
  4376. $this->sConn->createCommand($insertSql)->execute();
  4377. }
  4378. return $final_topic;
  4379. }
  4380. /**
  4381. * 教师假期报告设置
  4382. */
  4383. public function actionHoliday_teacher_index(){
  4384. Url::clean();
  4385. $data = array();
  4386. $semsterId = (string)Req::get("semesterId");
  4387. $teacher_name = (string)Req::get("teacher_name");
  4388. $limit = (int)Req::get("limit") ? (int)Req::get("limit") :10;
  4389. $newCondition = array();
  4390. $schoolId = $this->schoolId;
  4391. if(!$semsterId){
  4392. $semsterId = $this->semesterId;
  4393. }
  4394. if($semsterId){
  4395. $newCondition[] = "htrs.semester_id='$semsterId'";
  4396. }
  4397. if($teacher_name){
  4398. $newCondition[] = "t.teacher_name='$teacher_name'";
  4399. }
  4400. $resultList = $this->schoolManager->getTeacherHolidayReport($newCondition,array('htrs.create_time desc','htrs.report_id desc'),$limit);
  4401. $printList = array();
  4402. if($resultList["rs"]){
  4403. foreach ($resultList['rs'] as $k=>$v) {
  4404. $printList[$k]=$v;
  4405. }
  4406. }
  4407. $sql = "select report_id from holiday_teacher_report_setting where semester_id= '{$semsterId}'";
  4408. $res = $this->sConn->createCommand($sql)->queryRow();
  4409. if(!$res){
  4410. $status = $this->schoolManager->batchInsetHolidayTeacherReport($schoolId,$semsterId,1);
  4411. if(isset($status["status"]) && $status["status"] == 1){
  4412. $resultList = $this->schoolManager->getTeacherHolidayReport($newCondition,array('htrs.create_time desc','htrs.report_id desc'),$limit);
  4413. $printList = array();
  4414. if($resultList["rs"]){
  4415. foreach ($resultList['rs'] as $k=>$v) {
  4416. $printList[$k]=$v;
  4417. }
  4418. }
  4419. }
  4420. }else{
  4421. //验证有无新老师
  4422. $this->schoolManager->batchInsetHolidayTeacherReport($schoolId,$semsterId,2);
  4423. }
  4424. $semsters = $this->schoolManager->getSemesters();
  4425. $data['limit'] = $limit;
  4426. $data['pages'] = $resultList['pager'];
  4427. $data['page_total'] = $resultList['pager']->rowsCount;
  4428. $data['printList'] = $printList;
  4429. $data["semsterId"] = $semsterId;
  4430. $data["semsters"] = $semsters;
  4431. $data["teacher_name"] = $teacher_name;
  4432. // debug($data);
  4433. $this->render('holiday_teacher_index',$data);
  4434. }
  4435. /**
  4436. * 重置教师假期报告
  4437. */
  4438. public function actionAjaxResetHolidayTeacherReport(){
  4439. $reportId = Req::post('report_id');
  4440. $teacherId = Req::post('teacher_id');
  4441. $semsterId = Req::post('semster_id');
  4442. $schoolId = $this->schoolId;
  4443. if(!$reportId){
  4444. echo json_encode(array("status"=>0,"result"=>"假期报告ID不能为空"));exit;
  4445. }
  4446. if(!$teacherId){
  4447. echo json_encode(array("status"=>0,"result"=>"教师ID不能为空"));exit;
  4448. }
  4449. if(!$semsterId){
  4450. echo json_encode(array("status"=>0,"result"=>"学期ID不能为空"));exit;
  4451. }
  4452. $status = $this->schoolManager->resetTeacherReport($reportId,$teacherId,$semsterId);
  4453. if($status){
  4454. echo json_encode(array("status"=>1,"result"=>"重置成功"));exit;
  4455. }else{
  4456. echo json_encode(array("status"=>0,"result"=>"重置失败"));exit;
  4457. }
  4458. }
  4459. /**
  4460. * 批量重置教师假期报告
  4461. */
  4462. public function actionAjaxBatchResetHolidayTeacher(){
  4463. $semesterId = Req::post("semster_id");
  4464. if(!$semesterId){
  4465. echo json_encode(array("status"=>0,"result"=>"请指定学期Id"));exit;
  4466. }
  4467. $school_id = $this->schoolId;
  4468. $status = $this->schoolManager->batchResetTeacherReport($semesterId);
  4469. if($status){
  4470. echo json_encode(array("status"=>1,"result"=>"批量重置成功"));exit;
  4471. }else{
  4472. echo json_encode(array("status"=>0,"result"=>"批量重置失败"));exit;
  4473. }
  4474. }
  4475. /**
  4476. * 获取订单
  4477. */
  4478. function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade)
  4479. {
  4480. $data = array();
  4481. $Sem=new SSemester();
  4482. $code= $Sem->conn->createQuery()
  4483. ->from('semester')
  4484. ->where("semester_id = '".$this->semesterId."'")
  4485. ->limit(1)
  4486. ->query()
  4487. ->read();
  4488. $examInfo = Exam::model()->findByPk($eid);
  4489. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$eid,':classid'=>$cid));
  4490. if($print_time && $print_time[0]->add_time){
  4491. $exam_time = $print_time[0]->add_time;
  4492. }else{
  4493. $exam_time = $examInfo['create_time'];
  4494. }
  4495. $intarr=array(
  4496. "schoolId"=>$this->schoolId,
  4497. "clazzId"=>$cid,
  4498. "semester"=>$code['refer_code'],
  4499. "grade"=>$grade,
  4500. "examTime"=>$exam_time,
  4501. "students"=>array(),
  4502. "classify"=>$typeVal,
  4503. );
  4504. $intarr['subject']=$examInfo['subject_id'];
  4505. if(in_array($intarr['subject'],$this->mathSubjectId)){
  4506. $intarr['subject']=3;
  4507. }
  4508. foreach($relateStudentRes as $key => $val){
  4509. $intarr['students'][] = $val['student_id'];
  4510. }
  4511. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  4512. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  4513. if(!$rs){
  4514. //Yii::app()->jump->error("接口错误");
  4515. return false;
  4516. }
  4517. if($rs->errCode!="00"){
  4518. //Yii::app()->jump->error($rs->errMsg);
  4519. //exit();
  4520. return false;
  4521. }
  4522. if(!empty($rs->data)){
  4523. foreach($rs->data as $v){
  4524. $data['limitstu'][$v]=$v;
  4525. }
  4526. }else{
  4527. $data['limitstu']=-1;
  4528. }
  4529. return $data;
  4530. }
  4531. /**
  4532. * 获取班级设置
  4533. */
  4534. function getClassSet($classId,$semesterId){
  4535. $is_set = 0;
  4536. $temp_swich = 3;
  4537. $temp_bate = 0;
  4538. $switch_arr = array(3=>0,4=>1);
  4539. $sql = "select switch from producut_set_edition";
  4540. $switch_data = $this->sConn->createCommand($sql)->queryRow();
  4541. if($switch_data && $switch_data['switch'] && in_array($switch_data['switch'],array(3,4))){
  4542. $temp_swich = $switch_data['switch'];
  4543. $temp_bate = $switch_arr[$temp_swich];
  4544. }
  4545. if($classId && $semesterId){
  4546. $sql = "select wrong_book,isp,wb_isp from product_class_set where class_id = '{$classId}' and semester_id='{$semesterId}' and subject_id =3 and is_beta={$temp_bate}";
  4547. $res = $this->sConn->createCommand($sql)->queryAll();
  4548. if($res){
  4549. foreach($res as $res_k=>$res_v){
  4550. $setting_arr = array();
  4551. $setting_arr[1] = $res_v['wrong_book'];
  4552. $setting_arr[2] = $res_v['isp'];
  4553. $setting_arr[3] = $res_v['wb_isp'];
  4554. foreach($setting_arr as $k=>$v){
  4555. $sql = "select config_text from product_template where template_id = '{$v}'";
  4556. $data = $this->sConn->createCommand($sql)->queryRow();
  4557. if($data){
  4558. $json_data = $data['config_text'];
  4559. $json_data_arr = json_decode($json_data,true);
  4560. if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
  4561. $is_set = 1;
  4562. break 2;
  4563. }
  4564. }
  4565. }
  4566. }
  4567. }else{
  4568. $sql = "select template_id,config_text from product_template where subject_id=3 and is_default=1 and target_type=1 and is_beta={$temp_bate}";
  4569. $data = $this->sConn->createCommand($sql)->queryAll();
  4570. if($data){
  4571. foreach($data as $k=>$v){
  4572. $json_data = $v['config_text'];
  4573. $json_data_arr = json_decode($json_data,true);
  4574. if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
  4575. $is_set = 1;
  4576. break;
  4577. }
  4578. }
  4579. }
  4580. }
  4581. }
  4582. return $is_set;
  4583. }
  4584. /**获取名师指点信息
  4585. * @param $topicInfo
  4586. * @return mixed|string
  4587. */
  4588. public function dealTeacherTips($topicInfo){
  4589. if(isset($topicInfo["teacher_tips"]) && $topicInfo["teacher_tips"]){//如果有的话直接返回
  4590. return $topicInfo["teacher_tips"];
  4591. }
  4592. //兼容全学科题目
  4593. if(!isset($topicInfo["topic_type_config"]) || empty($topicInfo["topic_type_config"]) || !isset($topicInfo["affiliate"])|| empty($topicInfo["affiliate"])){
  4594. return "";
  4595. }
  4596. $topicTypeConfig = $topicInfo["topic_type_config"];
  4597. if(is_object($topicTypeConfig)){
  4598. $topicTypeConfig = json_decode(json_encode($topicTypeConfig),true);
  4599. }
  4600. //$topicTypeConfig = json_decode($topicInfo["topic_type_config"],true);
  4601. if(!isset($topicTypeConfig["subject_custom"]) || !isset($topicTypeConfig["subject_custom"]["custom_column"])){
  4602. return "";
  4603. }
  4604. if(!isset($topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]])){
  4605. return "";
  4606. }
  4607. $customColumnArr = $topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]];
  4608. $field_name = "";
  4609. foreach($customColumnArr as $value){//获取题型对应的 名师指点定制标签
  4610. if(isset($value["field_describe"]) && strpos($value["field_describe"],"名师指点") !==false){
  4611. $field_name =$value["field_name"];
  4612. break;
  4613. }
  4614. }
  4615. if(!$field_name){
  4616. return "";
  4617. }
  4618. $returnTeacherTips ="";
  4619. $affiliate = $topicInfo["affiliate"];
  4620. if(is_object($affiliate)){
  4621. $affiliate = json_decode(json_encode($affiliate),true);
  4622. }
  4623. foreach($affiliate as $affValue){//获取定制标签的值
  4624. if(is_object($affValue)){
  4625. $affValue = json_decode(json_encode($affValue),true);
  4626. }
  4627. if(isset($affValue["field_key"]) && $affValue["field_key"] == $field_name){
  4628. $returnTeacherTips = isset($affValue["field_value"])?$affValue["field_value"]:"";
  4629. break;
  4630. }
  4631. }
  4632. return $returnTeacherTips;
  4633. }
  4634. }