PrintController.php 664 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072
  1. <?php
  2. /**
  3. * 打印管理控制器类
  4. * @author jiangfei
  5. * @date 2015-07-22 17:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class PrintController extends Controller{
  9. public function actionIndex()
  10. {
  11. //初始化
  12. $exam_group_ids = array();
  13. $exam_ids = array();
  14. $_exam_ids = array();
  15. $_exam_group_ids = array();
  16. $exam_printer_num = array();
  17. $exam_use_wp = array();
  18. $data = array();
  19. $condition = array();
  20. $paper_exam = array();
  21. $class_exam = array();
  22. $class_ids = array();
  23. $class_grade_arr = array();
  24. $paper_arr = array();
  25. $paper_labelled_type_arr = array();
  26. //筛选条件
  27. $printName = Req::get("name");
  28. $grade = Req::get("grade");
  29. $labelled = Req::get("labelled");
  30. $display = Req::get("display");
  31. $type = Req::get("type");
  32. $teacherId = Req::get("teacher_id");
  33. // 发送标注条件
  34. if($labelled>-1)
  35. {
  36. $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled);
  37. if($paper_exam)
  38. {
  39. foreach($paper_exam as $v)
  40. {
  41. $s_exam_ids[$v['exam_id']] = $v['exam_id'];
  42. }
  43. }
  44. unset($paper_exam);
  45. }
  46. // 年级条件
  47. if($grade>0)
  48. {
  49. $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId);
  50. if($class_data)
  51. {
  52. foreach($class_data as $v)
  53. {
  54. $class_ids[$v['class_id']] = $v['class_id'];
  55. }
  56. $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids);
  57. if($exam_class_data)
  58. {
  59. foreach($exam_class_data as $v)
  60. {
  61. if(isset($s_exam_ids[$v['exam_id']]))
  62. {
  63. $l_b_exam_ids[$v['exam_id']] = $v['exam_id'];
  64. }else
  65. {
  66. $s_exam_ids[$v['exam_id']] = $v['exam_id'];
  67. }
  68. }
  69. }
  70. unset($exam_class_data);
  71. }
  72. unset($class_data);
  73. }
  74. if(isset($l_b_exam_ids))
  75. {
  76. if($l_b_exam_ids)
  77. {
  78. $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")";
  79. }else
  80. {
  81. $condition[] = "e.exam_id in (0)";
  82. }
  83. }else
  84. {
  85. if($labelled<0||$grade<1)
  86. {
  87. if(isset($s_exam_ids))
  88. {
  89. if($s_exam_ids)
  90. {
  91. $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")";
  92. }else
  93. {
  94. $condition[] = "e.exam_id in (0)";
  95. }
  96. }
  97. }else
  98. {
  99. $condition[] = "e.exam_id in (0)";
  100. }
  101. }
  102. // 多学科切换条件
  103. if(in_array($this->subjectId,$this->mathSubjectId)){
  104. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  105. }else{
  106. $condition[] = "e.subject_id = '{$this->subjectId}'";
  107. }
  108. if ( $display == 1) {
  109. $condition[] = "e.is_display = 1";
  110. }else
  111. {
  112. $condition[] = "e.is_display = 0";
  113. }
  114. $TeacherModel=new Teacher();
  115. // 考试名称条件
  116. if($printName)
  117. {
  118. //查询教师id
  119. $teacherIds=$TeacherModel->getTeacherIdByName($printName);
  120. if($teacherIds){
  121. $condition[] = " (e.name like '%{$printName}%' or eg.teacher_id in(".implode(',',$teacherIds)."))";
  122. }else{
  123. $condition[] = "e.name like '%{$printName}%'";
  124. }
  125. }
  126. $condition[] = "eg.is_third = 0";
  127. $condition[] = "eg.create_type in (0,1,2,3,5,6) ";
  128. $condition[] = "eg.is_united = 0";
  129. // $condition[] = "eg.homework = 0";
  130. $teachers_data = Teacher::model()->findAll();
  131. $class_teacher_data = array();
  132. $teacherNames=array();
  133. if($teachers_data) {
  134. foreach ($teachers_data as $k => $v) {
  135. $teacherNames[$v->teacher_id] = $v->teacher_name;
  136. }
  137. }
  138. $gradeCardLength=array();
  139. $gradeData=SGrade::model()->findAll();
  140. foreach ($gradeData as $datum){
  141. if($datum->card_status==1){
  142. $gradeCardLength[$datum->id]=$datum->card_length;
  143. }else{
  144. $gradeCardLength[$datum->id]=0;
  145. }
  146. }
  147. //获取考试列表
  148. $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12);
  149. //获取打印班级
  150. if($exam_list)
  151. {
  152. //查询教师
  153. $ExamModel=new Exam();
  154. $StudentPaperRelation=new SStudentPaperRelation();
  155. foreach($exam_list['rs'] as $key=>$v)
  156. {
  157. $items = array();
  158. $tpl_data=array();
  159. $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
  160. $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板
  161. $exam_list['rs'][$key]['is_custom_optional_topic'] = 0;
  162. $exam_list['rs'][$key]['is_paper_49'] = 0;
  163. //准考证
  164. if(!$v['school_card_status']){
  165. $exam_list['rs'][$key]['school_card_length'] = $gradeCardLength[$v['grade']];
  166. }
  167. if(isset($teacherNames[$v['teacher_id']])){
  168. $exam_list['rs'][$key]['teacher_name'] = $teacherNames[$v['teacher_id']];
  169. }else{
  170. $exam_list['rs'][$key]['teacher_name'] = '';
  171. }
  172. if(isset($v['tpl_data'])){
  173. $tpl_data = json_decode($v['tpl_data'],1);
  174. //标注期望完成时间
  175. if(isset($tpl_data['estimateTime']))
  176. {
  177. $exam_list['rs'][$key]['estimate_time'] = date('Y-m-d H:i:s',$tpl_data["estimateTime"]);
  178. }
  179. }
  180. if(isset($tpl_data['branch'])){
  181. $exam_list['rs'][$key]['branch'] = $tpl_data['branch'];
  182. }else{
  183. $exam_list['rs'][$key]['branch'] =0;
  184. }
  185. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  186. //自定义模板
  187. $exam_list['rs'][$key]['is_custom_tpl'] = true;
  188. if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){
  189. $exam_list['rs'][$key]['is_custom_optional_topic'] = 1;
  190. }
  191. $v['is_custom_tpl'] = true;
  192. }else{
  193. //非自定义模板
  194. $exam_list['rs'][$key]['is_custom_tpl'] = false;
  195. $v['is_custom_tpl'] = false;
  196. }
  197. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  198. $exam_list['rs'][$key]['is_tpl'] = 1;
  199. //题卡分离
  200. $exam_list['rs'][$key]['paper_tpl_type'] = 2;
  201. }else{
  202. $exam_list['rs'][$key]['paper_tpl_type'] = 1;
  203. }
  204. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  205. {
  206. $exam_list['rs'][$key]['paper_tpl_type'] = 3;
  207. if($v['tpl_index'] == 9 )
  208. {
  209. $exam_list['rs'][$key]['paper_tpl_type'] = 4;
  210. }
  211. }
  212. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  213. {
  214. $exam_list['rs'][$key]['paper_tpl_type'] = 3;
  215. if($v['tpl_index'] == 9 )
  216. {
  217. $exam_list['rs'][$key]['paper_tpl_type'] = 4;
  218. }
  219. }
  220. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7']))
  221. {
  222. $exam_list['rs'][$key]['is_paper_49'] = 1;
  223. }
  224. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8']))
  225. {
  226. $exam_list['rs'][$key]['is_paper_49'] = 1;
  227. }
  228. if(in_array($v['tpl_index'],Yii::app()->params['template_id_qrcode']))
  229. {
  230. $exam_list['rs'][$key]['qrcode'] = 1;
  231. }else{
  232. $exam_list['rs'][$key]['qrcode'] = 0;
  233. }
  234. //判断是否已上传成绩
  235. $exam_list['rs'][$key]['is_feedback']=0;
  236. $exam=$ExamModel->getExamIds($v['exam_group_id']);
  237. if($exam){
  238. if($StudentPaperRelation->getStudentFeedBack($exam)){
  239. $exam_list['rs'][$key]['is_feedback']=1;
  240. }
  241. }
  242. //是否使用在线答题卡
  243. $exam_list['rs'][$key]['third_card']=0;
  244. $exam_list['rs'][$key]['online_card']=0;
  245. $exam_list['rs'][$key]['is_qrcode_online']=0;
  246. $exam_list['rs'][$key]['marking_papers']=0;
  247. $studentAnswerOnline=$this->schoolManager->getAnswerSheet($v['exam_group_id']);
  248. if($studentAnswerOnline){
  249. if($studentAnswerOnline['online_card']==1){
  250. $exam_list['rs'][$key]['online_card']=$studentAnswerOnline['online_card'];
  251. $exam_list['rs'][$key]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
  252. $exam_list['rs'][$key]['marking_papers']=$studentAnswerOnline['marking_papers'];
  253. if($studentAnswerOnline['paper_size']==1){
  254. $exam_list['rs'][$key]['paper_size']='A3';
  255. }elseif($studentAnswerOnline['paper_size']==2){
  256. $exam_list['rs'][$key]['paper_size']='A4';
  257. }elseif($studentAnswerOnline['paper_size']==3){
  258. $exam_list['rs'][$key]['paper_size']='16K';
  259. }elseif($studentAnswerOnline['paper_size']==4){
  260. $exam_list['rs'][$key]['paper_size']='8K';
  261. }elseif($studentAnswerOnline['paper_size']==5){
  262. $exam_list['rs'][$key]['paper_size']='8K';
  263. }
  264. }else{
  265. $exam_list['rs'][$key]['third_card']=1;
  266. }
  267. }
  268. }
  269. //获取考试ID
  270. $criteria = new CDbCriteria();
  271. $criteria->select = 'exam_id,exam_group_id';
  272. $criteria->addInCondition('exam_group_id',$exam_group_ids);
  273. $exam_data = Exam::model()->findAll($criteria);
  274. unset($criteria);
  275. unset($exam_group_ids);
  276. if($exam_data)
  277. {
  278. foreach($exam_data as $v)
  279. {
  280. //$exam_use_wp
  281. $exam_ids[$v->exam_id] = $v->exam_id;
  282. $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id;
  283. $_exam_ids[$v->exam_id] = $v->exam_group_id;
  284. }
  285. unset($exam_data);
  286. //通过考试ID,获取打印班级
  287. $criteria = new CDbCriteria();
  288. $criteria->select = 'exam_id,class_id,is_print,is_print_online';
  289. $criteria->addInCondition('exam_id',$exam_ids);
  290. $criteria->addCondition('is_print = 1 or is_print_online=1');
  291. $class_print_data = ClassExamPrinter::model()->findAll($criteria);
  292. if($class_print_data)
  293. {
  294. foreach($class_print_data as $v)
  295. {
  296. if( isset($_exam_ids[$v->exam_id]))
  297. {
  298. if($v->is_print==1){
  299. $exam_printer_num['word'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
  300. }
  301. if($v->is_print_online==1){
  302. $exam_printer_num['online'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
  303. }
  304. }
  305. }
  306. }
  307. unset($criteria);
  308. unset($class_print_data);
  309. }
  310. }
  311. //获取班级年级
  312. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  313. if($class_data)
  314. {
  315. foreach($class_data as $v)
  316. {
  317. $class_grade_arr[$v->class_id] = $v->grade;
  318. }
  319. }
  320. unset($class_data);
  321. //获取试卷标注状态
  322. $criteria = new CDbCriteria();
  323. $criteria->select = 'exam_id,is_labelled,labelled_type';
  324. $criteria->addInCondition('exam_id',$exam_ids);
  325. $paper_data = SPaper::model()->findAll($criteria);
  326. unset($criteria);
  327. if($paper_data)
  328. {
  329. foreach($paper_data as $v)
  330. {
  331. if( isset($_exam_ids[$v->exam_id]))
  332. {
  333. $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled;
  334. $paper_labelled_type_arr[$_exam_ids[$v->exam_id]] = $v->labelled_type;
  335. }
  336. }
  337. }
  338. //获取产品设置版本
  339. $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
  340. if(!$productEdition || $productEdition['switch']==2){
  341. $data['productSwitch']=2;
  342. }else{
  343. $data['productSwitch']=3;
  344. }
  345. // 获取多学科状态
  346. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  347. $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id']));
  348. $data['pages'] = $exam_list['pager'];
  349. $data['page_total'] = $exam_list['pager']->rowsCount;
  350. $data['printList'] = $exam_list['rs'];
  351. $data['printer'] = $exam_printer_num;
  352. $data['exam_class'] = $_exam_group_ids;
  353. //$data["subject"] = $subject_exam_data;
  354. $data["exam_use_wp"] = $findSchool->use_wp;
  355. $data["display"] = $display;
  356. $data["labelled"] = $labelled;
  357. $data["grade"] = $grade;
  358. $data["printName"] = $printName;
  359. $data["paper"] = $paper_arr;
  360. $data["paper_labelled_type"] = $paper_labelled_type_arr;
  361. $data["class_grade"] = $class_grade_arr;
  362. $data["printType"] = $type;
  363. $data['teacherNames']=$teacherNames;
  364. $data["teacherId"] = $teacherId;
  365. //获取导出数据白名单
  366. $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);;
  367. $this->render('group_list',$data);
  368. }
  369. public function actionClass_exam()
  370. {
  371. $condition = array();
  372. $exam_ids = array();
  373. $exam_id = '';
  374. $exam_name = '';
  375. $class_names = array();
  376. $class_ids = array();
  377. $class_print = array();
  378. $class_online_print = array();
  379. $data = array();
  380. $exam_student_up_num = array();
  381. $exam_student_num = array();
  382. $student_img_up_num = array();//学生答题原图
  383. $class_name = Req::get("class_name");
  384. $exam_group_id = Req::get("exam_group_id");
  385. $masttype = (int)Req::get("masttype");
  386. $is_united = (int)Req::get('is_united');
  387. $grade = Req::get('grade');
  388. $branch = Req::get('branch');
  389. $multiple_choice_required=0; //多选题必选数量
  390. $exam_date=''; //考试日期
  391. $exam_uploaded=0;
  392. if($exam_group_id <= 0)
  393. {
  394. Yii::app()->jump->error('未找到考试信息!');
  395. }
  396. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  397. if(!$exam_group_data)
  398. {
  399. Yii::app()->jump->error('未找到考试信息!');
  400. }
  401. if($exam_group_data->upload_status>0){
  402. $exam_uploaded=1;
  403. }
  404. $condition[] = "exam_group_id = ".$exam_group_id;
  405. //获取班级信息
  406. $class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
  407. $class_types=array();
  408. if($class_data)
  409. {
  410. foreach($class_data as $v)
  411. {
  412. if($class_name && $v['class_name'] == $class_name)
  413. {
  414. $class_ids[$v['class_id']] = $v['class_id'];
  415. }
  416. $class_names[$v['class_id']] = $v['class_name'];
  417. if($v['class_type']==1){
  418. $class_types[$v['class_id']]='行政班';
  419. }elseif($v['class_type']==2){
  420. $class_types[$v['class_id']]='教学班';
  421. }
  422. }
  423. }
  424. //debug($class_data);
  425. if($class_ids)
  426. {
  427. $condition[] = "class_id in (".implode(',',$class_ids).") ";
  428. }
  429. // 多学科切换条件
  430. if(in_array($this->subjectId,$this->mathSubjectId)){
  431. $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")";
  432. }else{
  433. $condition[] = "subject_id = '{$this->subjectId}'";
  434. }
  435. if($class_ids)
  436. {
  437. $condition[] = "class_id in (".implode(',',$class_ids).") ";
  438. }
  439. //获取考试列表
  440. $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12);
  441. if($exam_data['rs'])
  442. {
  443. foreach($exam_data['rs'] as $k=>$v)
  444. {
  445. $exam_ids[$v['exam_id']] = $v['exam_id'];
  446. $exam_id = $v['exam_id'];
  447. $exam_name = $v['print_name'];
  448. }
  449. }else
  450. {
  451. Yii::app()->jump->error('未找到考试信息!');
  452. }
  453. //获取班级考试是否打印
  454. $criteria = new CDbCriteria();
  455. $criteria->addInCondition('exam_id',$exam_ids);
  456. $criteria->addCondition('type = 0');
  457. $class_print_data = ClassExamPrinter::model()->findAll($criteria);
  458. if($class_print_data)
  459. {
  460. foreach($class_print_data as $v)
  461. {
  462. $class_print[$v->exam_id] = $v->is_print;
  463. $class_online_print[$v->exam_id] = $v->is_print_online;
  464. }
  465. }
  466. unset($criteria);
  467. unset($class_print_data);
  468. //获取班级考试的上传成绩
  469. $criteria = new CDbCriteria();
  470. $criteria->select= 'student_id,is_feedback,exam_id,student_img_paper';
  471. $criteria->addInCondition('exam_id',$exam_ids);
  472. $criteria->addCondition('is_del = 0');
  473. $student_paper_data = SStudentPaperRelation::model()->findAll($criteria);
  474. if($student_paper_data)
  475. {
  476. foreach($student_paper_data as $v)
  477. {
  478. if($v->is_feedback)
  479. {
  480. $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id;
  481. }
  482. $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id;
  483. if (!isset($student_img_up_num[$v->exam_id])) {
  484. $student_img_up_num[$v->exam_id] = array();
  485. }
  486. if (trim($v['student_img_paper'])) {
  487. $student_img_up_num[$v->exam_id][$v->student_id] = $v->student_id;
  488. }
  489. }
  490. }
  491. unset($criteria);
  492. unset($student_paper_data);
  493. //获取paper
  494. $paperIds=array();
  495. $criteria = new CDbCriteria();
  496. $criteria->addInCondition('exam_id',$exam_ids);
  497. $paperData = SPaper::model()->findAll($criteria);
  498. if($paperData)
  499. {
  500. foreach($paperData as $v)
  501. {
  502. $paperIds[$v->exam_id] = $v->paper_id;
  503. }
  504. }
  505. unset($criteria);
  506. unset($exam_ids);
  507. $student_answer_img_num=array();
  508. foreach($exam_student_up_num as $eid =>$sids){
  509. $student_answer_img_num[$eid]=$this->schoolManager->getUpAnswerStudent($paperIds[$eid],$sids,true);
  510. }
  511. //获取paper 表数据
  512. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  513. if(!$paper_data)
  514. {
  515. Yii::app()->jump->error('未找到考试信息!');
  516. }
  517. //读取试题数据
  518. $isAllSelect=1; //全部客观题判断
  519. $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
  520. if(!$paperTopic){
  521. Yii::app()->jump->error('未找到考试信息!');
  522. }
  523. //选择题类型判断
  524. $allSubjectType=array();
  525. if($exam_group_data['qxk_paper_id']>0){
  526. $allSubjectType=array(1,2,3,4,12);
  527. }else{
  528. $allSubjectType=array(1,2,11);
  529. }
  530. foreach ($paperTopic as $item){
  531. if(!in_array($item->type,$allSubjectType)){
  532. $isAllSelect=0;
  533. break;
  534. }
  535. }
  536. $printList = array();
  537. $has_marked = false;
  538. $data['online_card'] = 0;
  539. $data['is_qrcode_online'] = 0;
  540. if($exam_data["rs"]){
  541. $studentAnswerOnline=$this->schoolManager->getAnswerSheet($exam_group_id);
  542. $studentAnswerCardOnline=new SStudentAnswerCardOnline();
  543. foreach ($exam_data['rs'] as $k=>$v) {
  544. $printList['is_tpl'] = 0; // 需要上传模板
  545. $printList['answer_card_uploaded'] = false;
  546. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  547. //自定义模板
  548. $printList['is_custom_tpl'] = true;
  549. $v['is_custom_tpl'] = true;
  550. }else{
  551. //非自定义模板
  552. $printList['is_custom_tpl'] = false;
  553. $v['is_custom_tpl'] = false;
  554. }
  555. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  556. $printList['is_tpl'] = 1;
  557. if(trim($paper_data->answer_card_src)){
  558. $printList['answer_card_uploaded'] = true;
  559. }
  560. //题卡分离
  561. $printList['paper_tpl_type'] = 2;
  562. }else{
  563. $printList['paper_tpl_type'] = 1;
  564. }
  565. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  566. {
  567. $printList['paper_tpl_type'] = 3;
  568. if($v['tpl_index'] == 9 )
  569. {
  570. $printList['paper_tpl_type'] = 4;
  571. }
  572. }
  573. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  574. {
  575. $printList['paper_tpl_type'] = 3;
  576. if($v['tpl_index'] == 9 )
  577. {
  578. $printList['paper_tpl_type'] = 4;
  579. }
  580. }
  581. //英语题卡分离一
  582. if($this->subjectId == 8){
  583. $printList['paper_tpl_type'] = 5;
  584. }
  585. if($v['status'] == 1){
  586. $has_marked = true;
  587. }
  588. //判断多选题
  589. if(!$multiple_choice_required){
  590. $tpl_data=json_decode($v['tpl_data'],true);
  591. if(isset($tpl_data['items'][17]) && isset($tpl_data['items'][17]['required']) ){
  592. $multiple_choice_required=$tpl_data['items'][17]['required'];
  593. }
  594. $exam_date=$tpl_data['examDate'];
  595. }
  596. //是否使用在线答题卡
  597. $exam_data['rs'][$k]['online_card']=0;
  598. $exam_data['rs'][$k]['is_qrcode_online']=0;
  599. if($studentAnswerOnline){
  600. $exam_data['rs'][$k]['online_card']=$studentAnswerOnline['online_card'];
  601. $exam_data['rs'][$k]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
  602. $data['online_card'] = $studentAnswerOnline['online_card'];
  603. $data['is_qrcode_online'] = $studentAnswerOnline['is_qrcode_online'];
  604. if($studentAnswerOnline['online_card']==1){
  605. if($studentAnswerOnline['paper_size']==1){
  606. $exam_data['rs'][$k]['paper_size']='A3';
  607. }elseif($studentAnswerOnline['paper_size']==2){
  608. $exam_data['rs'][$k]['paper_size']='A4';
  609. }elseif($studentAnswerOnline['paper_size']==3){
  610. $exam_data['rs'][$k]['paper_size']='16K';
  611. }elseif($studentAnswerOnline['paper_size']==4){
  612. $exam_data['rs'][$k]['paper_size']='8K';
  613. }elseif($studentAnswerOnline['paper_size']==5){
  614. $exam_data['rs'][$k]['paper_size']='8K';
  615. }
  616. }
  617. if($studentAnswerOnline['online_card']==1 && $studentAnswerOnline['is_qrcode_online']==1){
  618. //查询生成数量
  619. $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($v['exam_id']);
  620. if($studentCardOnline){
  621. $exam_data['rs'][$k]['card_created']=$studentCardOnline['count'];
  622. }
  623. }
  624. }
  625. }
  626. }
  627. //是否能添加班级 FIXME add_class_0924
  628. //打印中
  629. $enable_add_class = false;
  630. if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] ==0){
  631. $enable_add_class = true;
  632. }else{
  633. //混合阅卷
  634. if($exam_group_data['mark_type'] == 3){
  635. $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true;
  636. }
  637. //单独阅卷
  638. if($exam_group_data['mark_type'] == 4){
  639. $enable_add_class = $has_marked ? false : true;
  640. }
  641. }
  642. //查询还原记录
  643. $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  644. if($examRestore){
  645. $data['restore'] = 1;
  646. }else{
  647. $data['restore'] = 0;
  648. }
  649. //读取试题推送设置
  650. $topicPushSettingModel=new SExamPushTopicsSetting();
  651. $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id);
  652. $topicPushSettingRelation=array();
  653. if($topicPushSetting){
  654. foreach ($topicPushSetting as $item){
  655. if($item['topic_ids']){
  656. $topicSetting=json_decode($item['topic_ids'],true);
  657. if($topicSetting){
  658. $topicPushSettingRelation[(string)$item['exam_id']]=1;
  659. }
  660. }
  661. }
  662. }
  663. // 获取多学科状态
  664. //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  665. $this->setIs_new($exam_group_id);
  666. $data['printList'] = $exam_data['rs'];
  667. $data['print'] = $printList;
  668. $data['pages'] = $exam_data['pager'];
  669. $data['page_total'] = $exam_data['pager']->rowsCount;
  670. $data["class_name"] = $class_name;
  671. $data["class_data"] = $class_names;
  672. $data["class_types"] = $class_types;
  673. $data["exam_group_data"] = $exam_group_data;
  674. //$data["subject"] = $subject_exam_data;
  675. $data["exam_id"] = $exam_id;
  676. $data["exam_name"] = $exam_name;
  677. $data["exam_print"] = $class_print;
  678. $data["exam_online_print"] = $class_online_print;
  679. $data["exam_student"] = $exam_student_num;
  680. $data["exam_up_student"] = $exam_student_up_num;
  681. $data["student_img_up_num"] = $student_img_up_num;
  682. $data["student_answer_img_num"] = $student_answer_img_num;
  683. $data["exam_group_id"] = $exam_group_id;
  684. $data["grade"] = $grade;
  685. $data["branch"] = $branch;
  686. $data["enable_add_class"] = $enable_add_class;
  687. $data["qxk_paper_id"] = $exam_group_data->qxk_paper_id;
  688. $data['exam_date']=$exam_date;
  689. $data['exam_uploaded']=$exam_uploaded;
  690. $data['topic_push_setting']=$topicPushSettingRelation;
  691. $data['is_all_select']=$isAllSelect;
  692. $data['qxk_paper_id']=$exam_group_data['qxk_paper_id'];
  693. //判断全学科白名單
  694. $data['new_answer_sheet_subject']=0;
  695. if($data['qxk_paper_id']){
  696. $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$this->subjectId,'GET',$this->schoolId,array(),'cgi');
  697. $rs=json_decode($rs,true);
  698. if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  699. $data['new_answer_sheet_subject']=1;
  700. }
  701. }
  702. $data["subject"]=$this->subjectId;
  703. if($studentAnswerOnline){
  704. $data['online_card']=$studentAnswerOnline['online_card'];
  705. $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
  706. }
  707. if($multiple_choice_required>1){
  708. $data['noOnline']=1;
  709. }elseif(isset($exam_data['rs'][0]['paper_size']) && $exam_data['rs'][0]['paper_size']!='A3'){
  710. $data['noOnline']=2;
  711. }elseif($exam_group_data['mark_type']==0) {
  712. $data['noOnline'] = 3;
  713. }elseif($printList['paper_tpl_type'] == 1 || $printList['paper_tpl_type'] == 3){
  714. $data['noOnline'] = 4;
  715. }else{
  716. $data['noOnline']=0;
  717. }
  718. $data['online_token']=getOnlineToolToken($this->schoolId);
  719. $_num= '';
  720. $use_version = '';
  721. if(isset(Yii::app()->session['coachInfo']->use_version))
  722. {
  723. $use_version = Yii::app()->session['coachInfo']->use_version;
  724. }else
  725. {
  726. $use_version = Yii::app()->session['coachInfo']['use_version'];
  727. }
  728. if(!$use_version)
  729. {
  730. $use_version = 100;
  731. }
  732. $version_number = implode('',explode('.',$use_version));
  733. if(strlen($version_number)<7)
  734. {
  735. for($i=0;$i<7-strlen($version_number);$i++)
  736. {
  737. $_num.='0';
  738. }
  739. }
  740. $version_number=(int)$version_number.$_num;
  741. $data['version_number']=$version_number;
  742. if($is_united==1){
  743. $this->render('class_exam_united',$data);
  744. }else{
  745. $this->render('class_exam2',$data);
  746. }
  747. }
  748. // 打印列表
  749. public function actionSub_index(){
  750. Url::clean();
  751. $printName = Req::get("name");
  752. $classId = Req::get("classId");
  753. $printType = Req::get("type");
  754. $grade = Req::get("grade");
  755. $labelled = Req::get("labelled");
  756. $display = Req::get("display");
  757. $is_print = Req::get("is_print");
  758. if (empty($printType)) {
  759. $printType = 'wp';
  760. $printTypeData = 0;
  761. } else {
  762. switch ($printType) {
  763. case "wp":
  764. $printTypeData = 0;
  765. break;
  766. case "wtb":
  767. $printTypeData = 1;
  768. break;
  769. case "isp":
  770. $printTypeData = 2;
  771. break;
  772. case "studytrend":
  773. $printTypeData = 3;
  774. break;
  775. case "section":
  776. $printTypeData = 4;
  777. break;
  778. case "third_wb": //多学科错题本
  779. $printTypeData = 1;
  780. $this->subjectId = Yii::app()->session['session_duoxueke_subject_id'];
  781. break;
  782. case "third_isp": //多学科个性化学习宝
  783. $printTypeData = 3;
  784. $this->subjectId = Yii::app()->session['session_duoxueke_subject_id'];
  785. break;
  786. default:
  787. $printTypeData = null;
  788. break;
  789. }
  790. }
  791. $condition = array();
  792. if($is_print > -1)
  793. {
  794. $condition[] = "cep.is_print = '{$is_print}'";
  795. }else{
  796. $is_print = -1;
  797. }
  798. if($printName)
  799. $condition[] = "e.name like '%{$printName}%'";
  800. if(!Str::isBlank($printTypeData))
  801. $condition[] = "cep.type = '{$printTypeData}'";
  802. if($classId)
  803. $condition[] = "c.class_id = '{$classId}'";
  804. if ($grade) {
  805. $condition[] = "c.grade = '{$grade}'";
  806. }
  807. if (!Str::isBlank($labelled)) {
  808. $condition[] = "p.is_labelled = '{$labelled}'";
  809. }
  810. if ($printType=='wp' && $display != 1) {
  811. $condition[] = "e.is_display = '0'";
  812. }
  813. if(in_array($this->subjectId,$this->mathSubjectId)){
  814. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  815. }else{
  816. $condition[] = "e.subject_id = '{$this->subjectId}'";
  817. }
  818. $condition[] = "eg.create_type in (0,1,2,3,5,6) ";
  819. //$condition[] = "eg.homework = 0";
  820. //debug($condition);die;
  821. if (empty($grade)) {
  822. $grade = 'ALL';
  823. }
  824. $classes = $this->schoolManager->getClasses($grade);
  825. if($printType=='wp')
  826. {
  827. $condition[] = "eg.is_third = 0";
  828. $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc'));
  829. }else{
  830. $resultList = $this->schoolManager->getPrintList_ipf($condition,array('e.complete_time desc'));
  831. }
  832. $printList = array();
  833. if($resultList["rs"]){
  834. foreach ($resultList['rs'] as $k=>$v) {
  835. $printList[$k] = $v;
  836. if ($v["type"] == 1) {
  837. $printList[$k]['print_name']= $v["exam_name"].'"错题本"';
  838. }
  839. elseif ($v["type"] == 2) {
  840. $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"';
  841. }
  842. elseif ($v["type"] == 3) {
  843. if($this->subjectId == 8){
  844. $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
  845. }else{
  846. $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
  847. }
  848. }elseif ($v["type"] == 4) {
  849. $printList[$k]['print_name']= $v["exam_name"].'"阶段复习个性化学习宝"';
  850. }
  851. else {
  852. $printList[$k]['print_name']= $v["exam_name"];
  853. }
  854. $printList[$k]['is_tpl'] = 0; // 需要上传模板
  855. $printList[$k]['answer_card_uploaded'] = false;
  856. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  857. //自定义模板
  858. $printList[$k]['is_custom_tpl'] = true;
  859. $v['is_custom_tpl'] = true;
  860. }else{
  861. //非自定义模板
  862. $printList[$k]['is_custom_tpl'] = false;
  863. $v['is_custom_tpl'] = false;
  864. }
  865. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  866. $printList[$k]['is_tpl'] = 1;
  867. if(trim($printList[$k]['answer_card_src'])){
  868. $printList[$k]['answer_card_uploaded'] = true;
  869. }
  870. //题卡分离
  871. $printList[$k]['paper_tpl_type'] = 2;
  872. }else{
  873. $printList[$k]['paper_tpl_type'] = 1;
  874. }
  875. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  876. {
  877. $printList[$k]['paper_tpl_type'] = 3;
  878. if($v['tpl_index'] == 9 )
  879. {
  880. $printList[$k]['paper_tpl_type'] = 4;
  881. }
  882. }
  883. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  884. {
  885. $printList[$k]['paper_tpl_type'] = 3;
  886. if($v['tpl_index'] == 9 )
  887. {
  888. $printList[$k]['paper_tpl_type'] = 4;
  889. }
  890. }
  891. //题卡合一
  892. }
  893. }
  894. //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  895. $data = array();
  896. $data['printList'] = $printList;
  897. $data['pages'] = $resultList['pager'];
  898. $data['page_total'] = $resultList['pager']->rowsCount;
  899. $data["printType"] = $printType;
  900. $data["printName"] = $printName;
  901. $data["classes"] = $classes;
  902. $data["classId"] = $classId;
  903. $data["grade"] = $grade;
  904. $data["labelled"] = $labelled;
  905. $data["display"] = $display;
  906. $data["is_print"] = $is_print;
  907. //$data["subject"] = $subject_exam_data;
  908. $data['subjectId']=$this->subjectId;
  909. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  910. {
  911. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  912. }else
  913. {
  914. $data["use_zhixue"] = 0;
  915. }
  916. unset($resultList);
  917. $this->render('index',$data);
  918. }
  919. // 打印试卷、纠错本、个性化学习宝
  920. public function actionAjaxupdate(){
  921. $cid = safe_replace($_POST['cid']);
  922. $eid = safe_replace($_POST['eid']);
  923. $tid = safe_replace($_POST['tid']);
  924. $error = array();
  925. $error['success'] = 0;
  926. if (empty($cid) || !is_numeric($cid)) {
  927. $error['message'] = 'classId 错误!';
  928. echo json_encode($error);exit();
  929. }
  930. if (empty($eid) || !is_numeric($eid)) {
  931. $error['message'] = 'examId 错误!';
  932. echo json_encode($error);exit();
  933. }
  934. if ($tid == 0) { // 打印试卷
  935. $_num= '';
  936. $use_version = '';
  937. if(isset(Yii::app()->session['coachInfo']->use_version))
  938. {
  939. $use_version = Yii::app()->session['coachInfo']->use_version;
  940. }else
  941. {
  942. $use_version = Yii::app()->session['coachInfo']['use_version'];
  943. }
  944. if(!$use_version)
  945. {
  946. $use_version = 100;
  947. }
  948. $version_number = implode('',explode('.',$use_version));
  949. if(strlen($version_number)<7)
  950. {
  951. for($i=0;$i<7-strlen($version_number);$i++)
  952. {
  953. $_num.='0';
  954. }
  955. }
  956. $version_number=(int)$version_number.$_num;
  957. self::printPaper_v2($cid,$eid);
  958. } elseif ($tid == 1) { // 纠错本
  959. //self::printWrongTopic($cid,$eid);
  960. self::downloadWrongTopic($cid,$eid);
  961. } elseif ($tid == 2) { // 个性化学习宝
  962. self::printRaiseScheme($cid, $eid);
  963. }
  964. }
  965. // 选择需打印试卷的学生
  966. public function actionChange(){
  967. Url::clean();
  968. $sname = Req::get("sname");
  969. $cid = Req::get("cid");
  970. $eid = Req::get("eid");
  971. $tid = Req::get("tid");
  972. $isFeedback=0;
  973. $useAnswerCardOnlineQrcode=0;
  974. switch($tid){
  975. case "0":
  976. $printType = 'wp';
  977. break;
  978. case "1":
  979. $printType = 'wb';
  980. break;
  981. case "2":
  982. $printType = 'isp';
  983. break;
  984. default:
  985. $printType = 'wp';
  986. }
  987. if($sname)
  988. { $_student_ids = array();
  989. $criteria = new CDbCriteria();
  990. $criteria->select = 'student_id';
  991. $criteria->addSearchCondition('realname',$sname);
  992. $student_info_data = SStudentInfo::model()->findAll($criteria);
  993. if($student_info_data)
  994. {
  995. foreach($student_info_data as $v)
  996. {
  997. $_student_ids[$v->student_id] = $v->student_id;
  998. }
  999. }
  1000. }
  1001. $classInfo = ClassModel::model()->findByPk($cid);
  1002. if (empty($classInfo)) {
  1003. Yii::app()->jump->error('未找到班级!');
  1004. }
  1005. $examInfo = Exam::model()->findByPk($eid);
  1006. if (empty($examInfo)) {
  1007. Yii::app()->jump->error('未找到周周练!');
  1008. }
  1009. $examGroupInfo=ExamGroup::model()->findByPk($examInfo->exam_group_id);
  1010. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
  1011. if (empty($getResult)) {
  1012. Yii::app()->jump->error('未找到班级与试卷对应关系!');
  1013. }
  1014. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1015. if (empty($paperInfo)) {
  1016. Yii::app()->jump->error('未找到试卷信息!');
  1017. }
  1018. $_num= '';
  1019. $use_version = '';
  1020. if(isset(Yii::app()->session['coachInfo']->use_version))
  1021. {
  1022. $use_version = Yii::app()->session['coachInfo']->use_version;
  1023. }else
  1024. {
  1025. $use_version = Yii::app()->session['coachInfo']['use_version'];
  1026. }
  1027. if(!$use_version)
  1028. {
  1029. $use_version = 100;
  1030. }
  1031. $version_number = implode('',explode('.',$use_version));
  1032. if(strlen($version_number)<7)
  1033. {
  1034. for($i=0;$i<7-strlen($version_number);$i++)
  1035. {
  1036. $_num.='0';
  1037. }
  1038. }
  1039. $version_number=(int)$version_number.$_num;
  1040. $paperData='{}';
  1041. if($examGroupInfo->qxk_paper_id==0){
  1042. $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id);
  1043. }
  1044. if(trim($paperInfo->answer_card_src))
  1045. $answerCardUploaded = true;
  1046. else
  1047. $answerCardUploaded = false;
  1048. $tpl = 1;// 需要上传模板
  1049. $tplTwo= 1;
  1050. if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) {
  1051. $paperType = 1;
  1052. if (empty($paperInfo->tpl_doc_src)) {
  1053. $tpl = 2;
  1054. }
  1055. $tplTwo= 2;
  1056. }else{
  1057. $paperType = 2;
  1058. }
  1059. if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl']))
  1060. {
  1061. $tpl = 1;
  1062. $paperType = 1;
  1063. $tplTwo= 2;
  1064. }
  1065. if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){
  1066. $isCustomTpl = true;
  1067. }
  1068. else{
  1069. $isCustomTpl = false;
  1070. }
  1071. //判断在线答题卡使用情况
  1072. $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
  1073. if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
  1074. $useAnswerCardOnlineQrcode=1;
  1075. }
  1076. $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
  1077. if (empty($relateTopic)) {
  1078. Yii::app()->jump->error('未找该试卷试题信息!');
  1079. }
  1080. // 获取阅卷类型
  1081. $markType = 0;
  1082. $groupInfo = $this->schoolManager->getExam($eid);
  1083. if (!empty($groupInfo)) {
  1084. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
  1085. if (!empty($findInfo)) {
  1086. $markType = $findInfo->mark_type;
  1087. }
  1088. }
  1089. $result = array();
  1090. if(isset($_student_ids) && !empty($_student_ids))
  1091. {
  1092. $criteria = new CDbCriteria();
  1093. $criteria->select = 'student_id,paper_id,class_id,exam_id,student_card,school_student_card,is_feedback,is_complete';
  1094. $criteria->addCondition('paper_id=:paid');
  1095. $criteria->addCondition('class_id=:caid');
  1096. $criteria->addInCondition('student_id',$_student_ids);
  1097. $criteria->addCondition('is_del=:is_del');
  1098. $criteria->params[':paid'] = $paperInfo->paper_id;
  1099. $criteria->params[':caid'] = $cid;
  1100. $criteria->params[':is_del'] = 0;
  1101. $relateStudent = SStudentPaperRelation::model()->findAll($criteria);
  1102. }else
  1103. {
  1104. $relateStudent = SStudentPaperRelation::model()->findAll(array(
  1105. 'select' => array('student_id','paper_id','class_id','exam_id','student_card','school_student_card','is_feedback','is_complete','student_img_paper'),
  1106. 'condition' => 'paper_id=:paid and class_id=:caid and is_del=:is_del',
  1107. 'params' => array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,':is_del'=>0)));
  1108. }
  1109. //if (empty($relateStudent)) {
  1110. // Yii::app()->jump->error('未找该试卷关联的学生!');
  1111. //} else {
  1112. //$studentModel = StudentInfo::model();
  1113. // 获取学生姓名
  1114. $_student_id = array();
  1115. foreach($relateStudent as $v)
  1116. {
  1117. $_student_id[$v->student_id] = $v->student_id;
  1118. }
  1119. //if(!$_student_id)
  1120. //{
  1121. // Yii::app()->jump->error('未找该试卷关联的学生!');
  1122. //}
  1123. $studentNames = array();
  1124. $b_student_arr = array();
  1125. $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId);
  1126. if(!$b_student_arr ){
  1127. $array_student = array();
  1128. $b_student_data=$this->schoolManager->getStudentBySchool($this->schoolId);
  1129. if($b_student_data){
  1130. foreach ($b_student_data as $k=>$v){
  1131. $array_student[$v['student_id']] = $v['student_id'];
  1132. $b_student_arr[$v['student_id']]=$v['student_id'];
  1133. }
  1134. }
  1135. Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
  1136. if($array_student){
  1137. Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student);
  1138. Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000);
  1139. }
  1140. unset($b_student_data);
  1141. unset($criteria);
  1142. }
  1143. $studentNames = array();
  1144. $criteria = new CDbCriteria();
  1145. $criteria->addInCondition('student_id',$_student_id);
  1146. $studentArray = SStudentInfo::model()->findAll($criteria);
  1147. unset($criteria);
  1148. if (!empty($studentArray)) {
  1149. foreach ($studentArray as $student) {
  1150. $studentNames[$student->student_id] = $student->realname;
  1151. }
  1152. }
  1153. unset($studentArray);
  1154. //查询是否上传答题图片
  1155. $uploadAnswerImgStudent=array();
  1156. $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,false);
  1157. if($student_answer_img){
  1158. foreach ($student_answer_img as $val){
  1159. $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id'];
  1160. }
  1161. }
  1162. //redis里查询模板是否生成
  1163. $redis_obj = new Redis();
  1164. $server = Yii::app()->params["redis"]["server"];
  1165. $redis_obj->connect($server["host"], $server["port"]);
  1166. if(isset($server["password"])){
  1167. $redis_obj->auth($server["password"]);
  1168. }
  1169. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  1170. $redis_obj->select(0);
  1171. }else{
  1172. $redis_obj->select(10);
  1173. }
  1174. $redisKey = 'zsy:paper_template:'.$this->schoolId.':'.$eid;
  1175. $tempArr = array('0'=>'生成中','1'=>'已生成','2'=>'生成失败','3'=>'未生成');
  1176. $tempCheck = $printCheck = false;
  1177. foreach ($relateStudent as $key=>$val) {
  1178. $result[$key]['clazzName'] = $classInfo->class_name;
  1179. $result[$key]['paperName'] = $examInfo->name;
  1180. $result[$key]['studentCode'] = $val->student_id;
  1181. $result[$key]['student_card'] = $val->student_card;
  1182. $result[$key]['school_student_card'] = $val->school_student_card;
  1183. $result[$key]['studentCode'] = $val->student_id;
  1184. $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null;
  1185. $result[$key]['is_feedback'] = $val->is_feedback;
  1186. $result[$key]['is_complete'] = $val->is_complete;
  1187. $result[$key]['student_img_paper'] = $val->student_img_paper;
  1188. $result[$key]['upload_answer_img'] =0;
  1189. if($val->is_feedback==1){
  1190. $isFeedback=1;
  1191. if(isset($uploadAnswerImgStudent[(string)$val->student_id])){
  1192. $result[$key]['upload_answer_img'] =1;
  1193. }
  1194. }
  1195. $stuId = (string)$val->student_id;
  1196. $template = $redis_obj->hMGet($redisKey,array($stuId));
  1197. $result[$key]['temp_str'] = '未生成';
  1198. $result[$key]['temp_status'] = 3;
  1199. if(isset($template[$stuId]) && $template[$stuId]){
  1200. $redisData = json_decode($template[$stuId],true);
  1201. if(isset($redisData['status']) && isset($tempArr[$redisData['status']])){
  1202. $result[$key]['temp_str'] = $tempArr[$redisData['status']];
  1203. $result[$key]['temp_status'] = $redisData['status'];
  1204. if($redisData['status'] == 1){
  1205. $printCheck = true;
  1206. }
  1207. if($redisData['status'] == 2){
  1208. $tempCheck = true;
  1209. }
  1210. }else{
  1211. $tempCheck = true;
  1212. }
  1213. }else{
  1214. $tempCheck = true;
  1215. }
  1216. //查询在线答题卡是否生成
  1217. $rs=$this->sConn->createCommand("select answer_card_online_created from student_answer_card_online where exam_id='{$eid}' and student_id='{$val->student_id}' ")->queryRow();
  1218. if($rs && $rs['answer_card_online_created']==1){
  1219. $result[$key]['online_created'] = 1;
  1220. }else{
  1221. $result[$key]['online_created'] = 0;
  1222. }
  1223. //查询学生身份证号
  1224. $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id));
  1225. if($studentInfo){
  1226. $result[$key]['id_number'] = $studentInfo->id_number;
  1227. }else{
  1228. $result[$key]['id_number'] = '';
  1229. }
  1230. }
  1231. $redis_obj->close();
  1232. unset($relateStudent);
  1233. //}
  1234. $no_paper_student = array();
  1235. $paper_student_array = array();
  1236. $c_paper_student_array = array();
  1237. $class_student_info_data = array();
  1238. $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation
  1239. $class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info
  1240. $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生
  1241. $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生
  1242. if ($paper_student_data) {
  1243. foreach ($paper_student_data as $v) {
  1244. $paper_student_array[$v['student_id']] = $v['student_id'];
  1245. }
  1246. //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
  1247. }
  1248. if ($c_paper_student_data) {
  1249. foreach ($c_paper_student_data as $v) {
  1250. $c_paper_student_array[$v['student_id']] = $v['student_id'];
  1251. }
  1252. //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
  1253. }
  1254. if ($class_student_info_data) {
  1255. foreach ($class_student_info_data as $v) {
  1256. $class_student_info_array[$v['student_id']] = $v['realname'];
  1257. }
  1258. }
  1259. if ($class_student_data) {
  1260. foreach($class_student_data as $v)
  1261. {
  1262. if(!isset($b_student_arr[$v['student_id']]))
  1263. {
  1264. if ($paper_student_array)
  1265. {
  1266. if(isset($paper_student_array[$v['student_id']])){
  1267. $no_paper_student[$v['student_id']] = array(
  1268. 'student_id' => $v['student_id'],
  1269. 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
  1270. );
  1271. }
  1272. }
  1273. if($c_paper_student_array )
  1274. {
  1275. if(!isset($c_paper_student_array[$v['student_id']]) )
  1276. {
  1277. $no_paper_student[$v['student_id']] = array(
  1278. 'student_id' => $v['student_id'],
  1279. 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
  1280. );
  1281. }
  1282. }else
  1283. {
  1284. $no_paper_student[$v['student_id']] = array(
  1285. 'student_id' => $v['student_id'],
  1286. 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
  1287. );
  1288. }
  1289. }
  1290. }
  1291. }
  1292. unset($b_student_arr);
  1293. $data = array();
  1294. $data['no_paper_student'] = $no_paper_student;
  1295. $data['result'] = $result;
  1296. $data["printType"] = $printType;
  1297. $data["sname"] = $sname;
  1298. $data['examInfo'] = $examInfo;
  1299. $data['paper_id'] = $paperInfo->paper_id;
  1300. $data['exam_id'] = $eid;
  1301. $data['class_id'] = $cid;
  1302. $data['exam_group_id'] = $examInfo->exam_group_id;
  1303. $data['type_id'] = $tid;
  1304. $data['tempCheck'] = $tempCheck;
  1305. $data['printCheck'] = $printCheck;
  1306. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1307. {
  1308. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1309. }else
  1310. {
  1311. $data["use_zhixue"] = 0;
  1312. }
  1313. //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  1314. //$data["subject"] = $subject_exam_data;
  1315. $data['wp_type'] = $examInfo->tpl_index;
  1316. $data['className'] = $classInfo->class_name;
  1317. $data['paperName'] = $examInfo->name;
  1318. $data['tpl'] = $tpl;
  1319. $data['tplTwo'] = $tplTwo;
  1320. $data['markType'] = $markType;
  1321. $data['paperType'] = $paperType;
  1322. $data['answerCardUploaded'] = $answerCardUploaded;
  1323. $data['paperData'] = $paperData;
  1324. $data['isCustomTpl'] = $isCustomTpl;
  1325. $data['isFeedback'] = $isFeedback;
  1326. $data['useAnswerCardOnlineQrcode']=$useAnswerCardOnlineQrcode;
  1327. $data['qxkPaperId'] = $examGroupInfo->qxk_paper_id;
  1328. $_num= '';
  1329. $use_version = '';
  1330. if(isset(Yii::app()->session['coachInfo']->use_version))
  1331. {
  1332. $use_version = Yii::app()->session['coachInfo']->use_version;
  1333. }else
  1334. {
  1335. $use_version = Yii::app()->session['coachInfo']['use_version'];
  1336. }
  1337. if(!$use_version)
  1338. {
  1339. $use_version = 100;
  1340. }
  1341. $version_number = implode('',explode('.',$use_version));
  1342. if(strlen($version_number)<7)
  1343. {
  1344. for($i=0;$i<7-strlen($version_number);$i++)
  1345. {
  1346. $_num.='0';
  1347. }
  1348. }
  1349. $version_number=(int)$version_number.$_num;
  1350. $data['version_number']=$version_number;
  1351. $this->render('change2',$data);
  1352. }
  1353. // 选择需打印纠错本的同学
  1354. public function actionChangewrongtopic(){
  1355. $sname = Req::get("sname");
  1356. $cid = Req::get("cid");
  1357. $eid = Req::get("eid");
  1358. $printType = (string)Req::get("printType");
  1359. $classInfo = ClassModel::model()->findByPk($cid);
  1360. if (empty($classInfo)) {
  1361. Yii::app()->jump->error('未找到班级!');
  1362. }
  1363. $semesterId = $classInfo->semester_id;//当前学期id
  1364. $grade = $classInfo->grade;
  1365. $examInfo = Exam::model()->findByPk($eid);
  1366. if (empty($examInfo)) {
  1367. Yii::app()->jump->error('未找到周周练!');
  1368. }
  1369. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
  1370. if (empty($getResult)) {
  1371. Yii::app()->jump->error('未找到班级与试卷对应关系!');
  1372. }
  1373. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1374. if (empty($paperInfo)) {
  1375. Yii::app()->jump->error('未找到试卷信息!');
  1376. }
  1377. $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false;
  1378. $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"错题本\"";
  1379. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  1380. //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  1381. if (empty($relateStudent)) {
  1382. Yii::app()->jump->error('未找到学生和试卷的对应关系!');
  1383. } else {
  1384. $studentIds = array();
  1385. foreach ($relateStudent as $studentInfo) {
  1386. $studentIds[] = (string)$studentInfo['student_id'];
  1387. }
  1388. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  1389. $result = array();
  1390. $no = 1;
  1391. foreach ($relateStudent as $v) {
  1392. $studentId = (string)$v['student_id'];
  1393. $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:'';
  1394. $is_html = $v['is_wrongbook_html'];
  1395. $is_pdf = $v['is_wrongbook_pdf'];
  1396. $status = $this->getStatusDesc($is_html, $is_pdf); //错题本状态
  1397. $className = $classInfo->class_name;
  1398. $scoring = $v['scoring'];
  1399. if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的
  1400. if (strpos($_studentName, $sname) !== false) { //是搜索的学生
  1401. $result[$studentId] = array();
  1402. $result[$studentId]['no'] = $no; //序号
  1403. $result[$studentId]['studentId'] = $studentId; //学生id
  1404. $result[$studentId]['studentName'] = $_studentName; //学生名称
  1405. $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
  1406. $result[$studentId]['clazzName'] = $className; //班级名称
  1407. $result[$studentId]['wrongStatus'] = $status; //错题本状态
  1408. $result[$studentId]['scoring'] = $scoring; //得分
  1409. $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
  1410. $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
  1411. $no += 1;
  1412. } else{
  1413. continue;
  1414. }
  1415. } else {
  1416. $result[$studentId] = array();
  1417. $result[$studentId]['no'] = $no; //序号
  1418. $result[$studentId]['studentId'] = $studentId; //学生id
  1419. $result[$studentId]['studentName'] = $_studentName; //学生名称
  1420. $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
  1421. $result[$studentId]['clazzName'] = $className; //班级名称
  1422. $result[$studentId]['wrongStatus'] = $status; //错题本状态
  1423. $result[$studentId]['scoring'] = $scoring; //得分
  1424. $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
  1425. $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
  1426. $no += 1;
  1427. }
  1428. }
  1429. }
  1430. $data = array();
  1431. $data['exam_id'] = $eid;
  1432. $data['examName'] = $examInfo["name"];
  1433. $data['class_id'] = $cid;
  1434. $data['className'] = $classInfo->class_name;
  1435. $data['sname'] = $sname;
  1436. $data['paper_id'] = $paperInfo->paper_id;
  1437. $data['printTaskName'] = $printTaskName;
  1438. $data['paperIsLabelled'] = $paperIsLabelled;
  1439. $data['result'] = $result;
  1440. $data['printType'] = $printType;
  1441. $data['stuIspErroMsg'] = $this->stuIspErrorMsg(1,$eid,$studentIds);
  1442. $order_res = $this->getOrderStu($eid, $cid, 1, $relateStudent,$semesterId, $grade);
  1443. if (!$order_res) {
  1444. Yii::app()->jump->error("接口错误");
  1445. }
  1446. $data = array_merge($data, $order_res);
  1447. $this->render('changewrongtopic',$data);
  1448. }
  1449. /**
  1450. * 学生错题本个性化学习宝未生成错题信息
  1451. * @param $productType
  1452. * @param $examId
  1453. * @param array $studentIds
  1454. */
  1455. protected function stuIspErrorMsg($productType,$examId,$studentIds = array())
  1456. {
  1457. $result = array();
  1458. if (!in_array($this->subjectId, $this->mathSubjectId)) {
  1459. return $result;
  1460. }
  1461. if (!$studentIds) {
  1462. return $result;
  1463. }
  1464. //转字符串
  1465. foreach ($studentIds as $k => $_stuId) {
  1466. $studentIds[$k] = '"'.$_stuId.'"';
  1467. }
  1468. //需要显示学生个性化学习宝错误码
  1469. $showErrorCode = Yii::app()->params['show_isp_error_code'];
  1470. //个性化学习宝错误代码信息
  1471. $errorCodeMsg = Yii::app()->params['isp_error_code_msg'];
  1472. $rs = SStudentIspErrorCode::model()->getStudentIspErrorCode($examId, $productType);
  1473. if ($rs) {
  1474. foreach ($rs as $value) {
  1475. if(!in_array($value['error_code'],$showErrorCode)) continue;
  1476. if (!isset($result[$value['student_id']])) {
  1477. $result[$value['student_id']] = array();
  1478. }
  1479. $result[$value['student_id']][$value['error_code']] = isset($errorCodeMsg[$value['error_code']])?$errorCodeMsg[$value['error_code']]:'错误码无信息';
  1480. }
  1481. }
  1482. unset($rs);
  1483. return $result;
  1484. }
  1485. // 处理选择后同学纠错本打印(于20160908使用API接口的方法替换此方案,暂时废弃)
  1486. public function actionChangewrongtopicdo(){
  1487. $cid = Req::get("cid");
  1488. $eid = Req::get("eid");
  1489. $stids = Req::get("stids");
  1490. if (empty($stids) || empty($cid) || empty($eid)) {
  1491. Yii::app()->jump->error('打印纠错本参数有误!');
  1492. }
  1493. $classInfo = ClassModel::model()->findByPk($cid);
  1494. if (empty($classInfo)) {
  1495. Yii::app()->jump->error('未找到班级!');
  1496. }
  1497. $examInfo = Exam::model()->findByPk($eid);
  1498. if (empty($examInfo)) {
  1499. Yii::app()->jump->error('未找到周周练!');
  1500. }
  1501. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1502. if (empty($paperInfo)) {
  1503. Yii::app()->jump->error('未找到试卷信息!');
  1504. }
  1505. $filePath = array();
  1506. $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids));
  1507. if (empty($getPaths)) {
  1508. Yii::app()->jump->error('正在努力生成纠错本!');
  1509. } else {
  1510. // 下载文件名称
  1511. $fileName = $classInfo->class_name.$examInfo->name.'纠错本.zip';
  1512. // 下载文件路径
  1513. $result = array();
  1514. //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
  1515. $pdfPath = Yii::app()->params['student_wrong_isp_path'];
  1516. foreach ($getPaths as $path) {
  1517. /* if(file_exists(iconv("utf-8", "gbk", $pdfPath.$path->wrongbook_pdf_path))){
  1518. $result[] = $path->wrongbook_pdf_path;
  1519. } */
  1520. if(strpos($path->wrongbook_pdf_path, "data")!==false){
  1521. $paths=$pdfPath.$path->wrongbook_pdf_path;
  1522. }else{
  1523. $paths=$pdfPath."uploads/".$path->wrongbook_pdf_path;
  1524. }
  1525. if(file_exists($paths)){//aaaaaaaaa
  1526. $result[] = $paths;
  1527. }
  1528. }
  1529. if (empty($result)) {
  1530. Yii::app()->jump->error('正在生成学生纠错本!');
  1531. }
  1532. // 下载
  1533. self::downloadStudentFile($fileName,$result);
  1534. }
  1535. }
  1536. // 选择需打印个性化学习宝的同学
  1537. public function actionChangeraisescheme(){
  1538. $sname = Req::get("sname"); //学生名字
  1539. $cid = Req::get("cid"); //班级id
  1540. $eid = Req::get("eid"); //考试id
  1541. $type = Req::get("type"); //2步 还是 3步
  1542. $subjectId = Req::get("subid"); //学科ID
  1543. $planName = "";
  1544. if($type == "isp"){
  1545. $postTypeVal=2;
  1546. if($subjectId == 8){
  1547. $postTypeVal=3;
  1548. $planName = "个性化学习宝";
  1549. }else{
  1550. $planName = "个性化学习方案";
  1551. }
  1552. $typeVal = 2;
  1553. }else if($type == "third_isp"){
  1554. $planName = "个性化学习宝";
  1555. $typeVal = 3;
  1556. if($subjectId == 8){
  1557. $postTypeVal = 3;
  1558. }else{
  1559. $postTypeVal = 2;
  1560. }
  1561. }else if($type == "studytrend"){
  1562. $planName = "个性化学习宝";
  1563. $typeVal = 3;
  1564. $postTypeVal=3;
  1565. }else{
  1566. Yii::app()->jump->error('参数错误!');
  1567. }
  1568. $classInfo = ClassModel::model()->findByPk($cid);
  1569. if (empty($classInfo)) {
  1570. Yii::app()->jump->error('未找到班级!');
  1571. }
  1572. $semesterId = $classInfo->semester_id;//当前学期id
  1573. $grade = $classInfo->grade;
  1574. $examInfo = Exam::model()->findByPk($eid);
  1575. if (empty($examInfo)) {
  1576. Yii::app()->jump->error('未找到周周练!');
  1577. }
  1578. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type='.$typeVal,array(':cid'=>$cid,':eid'=>$eid));
  1579. if (empty($getResult)) {
  1580. Yii::app()->jump->error('未找到班级与试卷对应关系!');
  1581. }
  1582. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1583. if (empty($paperInfo)) {
  1584. Yii::app()->jump->error('未找到试卷信息!');
  1585. }
  1586. $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false;
  1587. $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"{$planName}\"";
  1588. /*$studentIds = array();
  1589. $planNames = array();
  1590. $result = array();
  1591. $ispStatus = array();
  1592. $studentIdsTwo = array();*/
  1593. //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_isp_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  1594. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid ',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));//所有记录
  1595. if (!$relateStudent) {
  1596. Yii::app()->jump->error('未找到学生和试卷的对应关系!');
  1597. }
  1598. $studentIds = array();
  1599. foreach ($relateStudent as $studentInfo) {
  1600. $studentIds[] = (string)$studentInfo['student_id'];
  1601. }
  1602. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  1603. $result = array();
  1604. $no = 1;
  1605. foreach ($relateStudent as $v) {
  1606. $studentId = (string)$v['student_id'];
  1607. $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:'';
  1608. if ($type == 'isp') {
  1609. $is_html = $v['is_isp_html'];
  1610. $is_pdf = $v['is_isp_pdf'];
  1611. }elseif ($type == 'studytrend') {
  1612. $is_html = $v['is_wbisp_html'];
  1613. $is_pdf = $v['is_wbisp_pdf'];
  1614. }elseif ($type == 'third_isp') {
  1615. $is_html = $v['is_wbisp_html'];
  1616. $is_pdf = $v['is_wbisp_pdf'];
  1617. }
  1618. $status = $this->getStatusDesc($is_html, $is_pdf); //个性化学习宝状态
  1619. $className = $classInfo->class_name;
  1620. $_planName = $className.$_studentName.$examInfo->name.$planName;
  1621. if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的
  1622. if (strpos($_studentName, $sname) !== false) { //是搜索的学生
  1623. $result[$studentId] = array();
  1624. $result[$studentId]['no'] = $no; //序号
  1625. $result[$studentId]['studentId'] = $studentId; //学生id
  1626. $result[$studentId]['studentName'] = $_studentName; //学生名称
  1627. $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
  1628. $result[$studentId]['clazzName'] = $className; //班级名称
  1629. $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态
  1630. $result[$studentId]['planName'] = $_planName;
  1631. $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
  1632. $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
  1633. $no += 1;
  1634. } else{
  1635. continue;
  1636. }
  1637. } else {
  1638. $result[$studentId] = array();
  1639. $result[$studentId]['no'] = $no; //序号
  1640. $result[$studentId]['studentId'] = $studentId; //学生id
  1641. $result[$studentId]['studentName'] = $_studentName; //学生名称
  1642. $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
  1643. $result[$studentId]['clazzName'] = $className; //班级名称
  1644. $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态
  1645. $result[$studentId]['planName'] = $_planName;
  1646. $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
  1647. $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
  1648. $no += 1;
  1649. }
  1650. }
  1651. $data = array();
  1652. $data['exam_id'] = $eid;
  1653. $data['class_id'] = $cid;
  1654. $data['className'] = $grade;
  1655. $data['sname'] = $sname;
  1656. $data['paper_id'] = $paperInfo->paper_id;
  1657. $data['result'] = $result;
  1658. $data['type'] = $type;
  1659. $data['paperIsLabelled'] = $paperIsLabelled;
  1660. $data['printTaskName'] = $printTaskName;
  1661. $data['printType'] = $type;
  1662. $data['subjectId']=$subjectId;
  1663. $data['stuIspErroMsg'] = $this->stuIspErrorMsg($type == 'isp'?2:3,$eid,$studentIds);
  1664. $order_res = $this->getOrderStu($eid, $cid, $postTypeVal, $relateStudent,$semesterId, $grade);
  1665. // debug($order_res);
  1666. if (!$order_res) {
  1667. Yii::app()->jump->error("接口错误");
  1668. }
  1669. $data = array_merge($data, $order_res);
  1670. // debug($data);
  1671. $this->render('changeraisescheme',$data);
  1672. /*// 获取当前试卷提分计划
  1673. $improveScore = StudentImproveScorePlan::model()->findAll('paper_id=:paid and is_created=1',array(':paid'=>$paperInfo->paper_id));
  1674. if (empty($relateStudent)) {
  1675. Yii::app()->jump->error('学生的个性化学习宝还未生成,请等待!');
  1676. } else {
  1677. if($type == "isp"){
  1678. foreach ($relateStudent as $paperStudent) {
  1679. $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}')")->queryRow();
  1680. $rs = current($rs);
  1681. if($rs == 0)
  1682. continue;
  1683. $studentIds[] = $paperStudent->student_id;
  1684. $ispStatus[$paperStudent->student_id] = $paperStudent->is_isp_pdf;
  1685. }
  1686. // 获取当前班级需打印周周练的同学
  1687. foreach ($improveScore as $improve) {
  1688. if (in_array($improve->student_id, $studentIds)) {
  1689. $studentIdsTwo[] = $improve->student_id;
  1690. }
  1691. }
  1692. }
  1693. else if($type == "studytrend"){
  1694. foreach ($relateStudent as $paperStudent) {
  1695. $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}' )")->queryRow();
  1696. $rs = current($rs);
  1697. if($rs == 0)
  1698. continue;
  1699. $studentIds[] = $paperStudent->student_id;
  1700. $ispStatus[$paperStudent->student_id] = $paperStudent->is_wbisp_pdf;
  1701. }
  1702. // 获取当前班级需打印周周练的同学
  1703. foreach ($improveScore as $improve) {
  1704. if (in_array($improve->student_id, $studentIds)) {
  1705. $studentIdsTwo[] = $improve->student_id;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. if (empty($studentIdsTwo)) {
  1711. Yii::app()->jump->error('当前班级还未生成个性化学习宝');
  1712. } else {
  1713. // 获取有错题的学生姓名
  1714. $studentNames = SStudentInfo::model()->getStudentNames($studentIdsTwo);
  1715. foreach ($studentIdsTwo as $key=>$val) { //val是学生id
  1716. if (empty($sname)) {
  1717. $result[$key]['studentName'] = $studentNames[$val];
  1718. $result[$key]['studentCode'] = $val;
  1719. $result[$key]['clazzName'] = $classInfo->class_name;
  1720. $result[$key]['ispStatus'] = $ispStatus[$val];
  1721. $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName;
  1722. } else {
  1723. if (false !== strpos($studentNames[$val],$sname) ) {
  1724. $result[$key]['studentName'] = $studentNames[$val];
  1725. $result[$key]['studentCode'] = $val;
  1726. $result[$key]['clazzName'] = $classInfo->class_name;
  1727. $result[$key]['ispStatus'] = $ispStatus[$val];
  1728. $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName;
  1729. }
  1730. unset($studentIdsTwo[$key]);
  1731. }
  1732. }
  1733. }*/
  1734. }
  1735. function getStatusDesc($is_html, $is_pdf)
  1736. {
  1737. if ($is_html == 0 || $is_html == 90) {
  1738. $status = 0; // 未生成
  1739. } elseif ($is_html == 1 && $is_pdf == 0) {
  1740. $status = 1; //正在生成中
  1741. } elseif ($is_pdf == 1) {
  1742. $status = 2; //已生成
  1743. } elseif ($is_html == 9 && $is_pdf == 9) {
  1744. $status = 3; //已过期
  1745. } else {
  1746. $status = 4; //未知状态
  1747. }
  1748. return $status;
  1749. }
  1750. function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade)
  1751. {
  1752. $data = array();
  1753. $Sem=new SSemester();
  1754. $code= $Sem->conn->createQuery()
  1755. ->from('semester')
  1756. ->where("semester_id = '".$this->semesterId."'")
  1757. ->limit(1)
  1758. ->query()
  1759. ->read();
  1760. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$eid,':classid'=>$cid));
  1761. $intarr=array(
  1762. "schoolId"=>$this->schoolId,
  1763. "clazzId"=>$cid,
  1764. "semester"=>$code['refer_code'],
  1765. "grade"=>$grade,
  1766. "examTime"=>$print_time[0]->add_time,
  1767. "students"=>array(),
  1768. "classify"=>$typeVal,
  1769. );
  1770. $examInfo = Exam::model()->findByPk($eid);
  1771. $intarr['subject']=$examInfo['subject_id'];
  1772. if(in_array($intarr['subject'],$this->mathSubjectId)){
  1773. $intarr['subject']=3;
  1774. }
  1775. foreach($relateStudentRes as $key => $val){
  1776. $intarr['students'][] = $val['student_id'];
  1777. }
  1778. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  1779. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  1780. if(!$rs){
  1781. //Yii::app()->jump->error("接口错误");
  1782. return false;
  1783. }
  1784. if($rs->errCode!="00"){
  1785. //Yii::app()->jump->error($rs->errMsg);
  1786. //exit();
  1787. return false;
  1788. }
  1789. if(!empty($rs->data)){
  1790. foreach($rs->data as $v){
  1791. $data['limitstu'][$v]=$v;
  1792. }
  1793. }else{
  1794. $data['limitstu']=-1;
  1795. }
  1796. return $data;
  1797. }
  1798. // 选择打印个性化学习宝同学处理(于20160908使用API接口的方法替换此方案,暂时废弃)
  1799. public function actionChangeraiseschemedo(){
  1800. $cid = Req::get("cid");
  1801. $eid = Req::get("eid");
  1802. $stids = Req::get("stids");
  1803. $type = Req::get("type");
  1804. if (empty($stids) || empty($cid) || empty($eid) || empty($type)) {
  1805. Yii::app()->jump->error('打印个性化学习宝参数有误!');
  1806. }
  1807. $classInfo = ClassModel::model()->findByPk($cid);
  1808. if (empty($classInfo)) {
  1809. Yii::app()->jump->error('未找到班级!');
  1810. }
  1811. $examInfo = Exam::model()->findByPk($eid);
  1812. if (empty($examInfo)) {
  1813. Yii::app()->jump->error('未找到周周练!');
  1814. }
  1815. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1816. if (empty($paperInfo)) {
  1817. Yii::app()->jump->error('未找到试卷信息!');
  1818. }
  1819. $filePath = array();
  1820. $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids));
  1821. if (empty($getPaths)) {
  1822. Yii::app()->jump->error('正在努力生成个性化学习宝!');
  1823. } else {
  1824. $fName = "";
  1825. if($type == "isp")
  1826. $fName = "个性化学习方案";
  1827. else if($type == "studytrend")
  1828. $fName = "个性化学习宝";
  1829. // 下载文件名称
  1830. $fileName = $classInfo->class_name.$examInfo->name.$fName.'.zip';
  1831. // 下载文件路径
  1832. $result = array();
  1833. //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
  1834. $pdfPath = Yii::app()->params['student_wrong_isp_path'];
  1835. foreach ($getPaths as $path) {
  1836. /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){
  1837. $result[] = $path->isp_pdf_path;
  1838. } */
  1839. if($type == "isp"){
  1840. if(strpos($path->isp_pdf_path,'data')!==false){
  1841. $paths=$pdfPath.$path->isp_pdf_path;
  1842. }else{
  1843. $paths=$pdfPath."uploads/".$path->isp_pdf_path;
  1844. }
  1845. $result[] = $paths;
  1846. }
  1847. else if($type == "studytrend" ){
  1848. if(strpos($path->isp_pdf_path,'data')!==false){
  1849. $paths=$pdfPath.$path->wbisp_pdf_path;
  1850. }else{
  1851. $paths=$pdfPath."uploads/".$path->wbisp_pdf_path;
  1852. }
  1853. $result[] = $paths;
  1854. }
  1855. }
  1856. if (empty($result)) {
  1857. Yii::app()->jump->error('正在生成学生个性化学习宝!');
  1858. }
  1859. // 下载
  1860. self::downloadStudentFile($fileName,$result);
  1861. }
  1862. }
  1863. // 打印试卷
  1864. private function printPaper($cid,$eid){
  1865. $error = array();
  1866. $error['success'] = 0;
  1867. $classInfo = ClassModel::model()->findByPk($cid);
  1868. if (empty($classInfo)) {
  1869. $error['message'] = '未找到班级!';
  1870. echo json_encode($error);exit();
  1871. }
  1872. $examInfo = Exam::model()->findByPk($eid);
  1873. if (empty($examInfo)) {
  1874. $error['message'] = '未找到周周练!';
  1875. echo json_encode($error);exit();
  1876. }
  1877. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
  1878. if (empty($getResult)) {
  1879. $error['message'] = '未找到班级与试卷对应关系!';
  1880. echo json_encode($error);exit();
  1881. }
  1882. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1883. if (empty($paperInfo)) {
  1884. $error['message'] = '未找到试卷信息!';
  1885. echo json_encode($error);exit();
  1886. }
  1887. if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) {
  1888. if (empty($paperInfo->tpl_doc_src)) {
  1889. $error['message'] = '未上传模板,请先上传模板!';
  1890. echo json_encode($error);exit();
  1891. }
  1892. }
  1893. // 获取阅卷类型
  1894. $markType = 0;
  1895. $groupInfo = $this->schoolManager->getExam($eid);
  1896. if (!empty($groupInfo)) {
  1897. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
  1898. if (!empty($findInfo)) {
  1899. $markType = $findInfo->mark_type;
  1900. }
  1901. }
  1902. $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
  1903. if (empty($relateTopic)) {
  1904. $error['message'] = '未找该试卷试题信息!';
  1905. echo json_encode($error);exit();
  1906. }
  1907. $result = array();
  1908. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0));
  1909. if (empty($relateStudent)) {
  1910. $error['message'] = '未找该试卷关联的学生!';
  1911. echo json_encode($error);exit();
  1912. } else {
  1913. // 组装json数据发到客户端
  1914. $studentModel = StudentInfo::model();
  1915. $paperData = $this->schoolManager->getPaperWithTopicsDetails($paperInfo->paper_id, "ARR");
  1916. foreach ($relateStudent as $key=>$val) {
  1917. $result[$key]['clazzName'] = $classInfo->class_name;
  1918. $result[$key]['paperId'] = $paperInfo->paper_id;
  1919. $result[$key]['paperName'] = $examInfo->name;
  1920. $result[$key]['schoolId'] = Yii::app()->session['school_id'];
  1921. $result[$key]['studentCode'] = $val->student_id;
  1922. $result[$key]['studentName'] = $studentModel->findByPk($val->student_id)->realname;
  1923. $result[$key]['wpCode'] = $eid;
  1924. $result[$key]['wpType'] = $examInfo->tpl_index;
  1925. $result[$key]['markType'] = $markType;
  1926. if(isset($paperData["object"]["topicsCount"])){
  1927. $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"];
  1928. $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"];
  1929. $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"];
  1930. }
  1931. else{
  1932. $result[$key]['selectQTNub'] = 0;
  1933. $result[$key]['completionNub'] = 0;
  1934. $result[$key]['questionSNub'] = 0;
  1935. }
  1936. }
  1937. }
  1938. if (empty($result)) {
  1939. $error['message'] = '没有打印信息!';
  1940. echo json_encode($error);exit();
  1941. } else {
  1942. // 更新试卷打印状态、时间
  1943. $getResult->is_print = 1;
  1944. $getResult->print_time = time();
  1945. $getResult->save();
  1946. $error['success'] = 1;
  1947. $error['message'] = $result;
  1948. echo json_encode($error);exit();
  1949. }
  1950. }
  1951. private function printPaper_v2($cid,$eid){
  1952. $error = array();
  1953. $error['success'] = 0;
  1954. $classInfo = ClassModel::model()->findByPk($cid);
  1955. if (empty($classInfo)) {
  1956. $error['message'] = '未找到班级!';
  1957. echo json_encode($error);exit();
  1958. }
  1959. $examInfo = Exam::model()->findByPk($eid);
  1960. if (empty($examInfo)) {
  1961. $error['message'] = '未找到周周练!';
  1962. echo json_encode($error);exit();
  1963. }
  1964. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
  1965. if (empty($getResult)) {
  1966. $error['message'] = '未找到班级与试卷对应关系!';
  1967. echo json_encode($error);exit();
  1968. }
  1969. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  1970. if (empty($paperInfo)) {
  1971. $error['message'] = '未找到试卷信息!';
  1972. echo json_encode($error);exit();
  1973. }
  1974. if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) {
  1975. if (empty($paperInfo->tpl_doc_src)) {
  1976. $error['message'] = '未上传模板,请先上传模板!';
  1977. echo json_encode($error);exit();
  1978. }
  1979. }
  1980. // 获取阅卷类型
  1981. $markType = 0;
  1982. $groupInfo = $this->schoolManager->getExam($eid);
  1983. if (!empty($groupInfo)) {
  1984. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
  1985. if (!empty($findInfo)) {
  1986. $markType = $findInfo->mark_type;
  1987. }
  1988. }
  1989. $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
  1990. if (empty($relateTopic)) {
  1991. $error['message'] = '未找该试卷试题信息!';
  1992. echo json_encode($error);exit();
  1993. }
  1994. $result = array();
  1995. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0));
  1996. if (empty($relateStudent)) {
  1997. $error['message'] = '未找该试卷关联的学生!';
  1998. echo json_encode($error);exit();
  1999. } else {
  2000. // 组装json数据发到客户端
  2001. $studentModel = StudentInfo::model();
  2002. $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id, "ARR");
  2003. foreach ($relateStudent as $key=>$val) {
  2004. $studentInfo=$studentModel->findByPk($val->student_id);
  2005. $result[$key]['clazzName'] = $classInfo->class_name;
  2006. $result[$key]['paperId'] = $examInfo->exam_group_id;
  2007. $result[$key]['paperName'] = $examInfo->name;
  2008. $result[$key]['schoolId'] = Yii::app()->session['school_id'];
  2009. $result[$key]['studentCode'] = $val->student_id;
  2010. $result[$key]['studentName'] = $studentInfo->realname;
  2011. $result[$key]['wpCode'] = $eid;
  2012. $result[$key]['wpType'] = $examInfo->tpl_index;
  2013. $result[$key]['markType'] = $markType;
  2014. $result[$key]['idNumber'] = $studentInfo->id_number;
  2015. if(isset($paperData["object"]["topicsCount"])){
  2016. $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"];
  2017. $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"];
  2018. $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"];
  2019. }
  2020. else{
  2021. $result[$key]['selectQTNub'] = 0;
  2022. $result[$key]['completionNub'] = 0;
  2023. $result[$key]['questionSNub'] = 0;
  2024. }
  2025. }
  2026. }
  2027. if (empty($result)) {
  2028. $error['message'] = '没有打印信息!';
  2029. echo json_encode($error);exit();
  2030. } else {
  2031. // 更新试卷打印状态、时间
  2032. $getResult->is_print = 1;
  2033. $getResult->print_time = time();
  2034. $getResult->save();
  2035. $error['success'] = 1;
  2036. $error['message'] = $result;
  2037. echo json_encode($error);exit();
  2038. }
  2039. }
  2040. // 下载全班学生纠错本
  2041. public function actionDownloadwrongtopic() {
  2042. $cid = Req::get("cid");
  2043. $eid = Req::get("eid");
  2044. $classInfo = ClassModel::model()->findByPk($cid);
  2045. if (empty($classInfo)) {
  2046. Yii::app()->jump->error('未找到班级!');
  2047. }
  2048. $examInfo = Exam::model()->findByPk($eid);
  2049. if (empty($examInfo)) {
  2050. Yii::app()->jump->error('未找到周周练!');
  2051. }
  2052. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
  2053. if (empty($getResult)) {
  2054. Yii::app()->jump->error('未找到班级与纠错本对应关系!');
  2055. }
  2056. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  2057. if (empty($paperInfo)) {
  2058. Yii::app()->jump->error('未找到试卷信息!');
  2059. }
  2060. $result = array();
  2061. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1 and is_del=:is_del',array(':is_del'=>0,':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  2062. if (empty($relateStudent)) {
  2063. Yii::app()->jump->error('正在努力生成纠错本!');
  2064. } else {
  2065. $studentIdArray = array();
  2066. // 获取当前考试所有学生ID
  2067. foreach ($relateStudent as $key=>$val) {
  2068. $studentIdArray[] = $val->student_id;
  2069. }
  2070. }
  2071. $filePath = array();
  2072. $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray);
  2073. if (empty($getPaths)) {
  2074. Yii::app()->jump->error('正在生成纠错本!');
  2075. } else {
  2076. // 下载文件名称
  2077. $fileName = $classInfo->class_name.$examInfo->name.'错题本.zip';
  2078. // 下载文件路径
  2079. $result = array();
  2080. //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
  2081. $pdfPath = Yii::app()->params['student_wrong_isp_path'];
  2082. foreach ($getPaths as $path) {
  2083. /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->wrongbook_pdf_path))){
  2084. $result[] = $path->wrongbook_pdf_path;
  2085. } */
  2086. if(strpos($path->wrongbook_pdf_path,"data")!==false){
  2087. $pathstr=$pdfPath.$path->wrongbook_pdf_path;
  2088. }else{
  2089. $pathstr=$pdfPath."uploads/".$path->wrongbook_pdf_path;
  2090. }
  2091. if(file_exists($pathstr)){
  2092. $result[] = $pathstr;
  2093. }
  2094. }
  2095. if (empty($result)) {
  2096. Yii::app()->jump->error('正在生成学生纠错本!');
  2097. }
  2098. // 下载
  2099. self::downloadStudentFile($fileName,$result);
  2100. }
  2101. }
  2102. // 下载全班学生个性化学习宝
  2103. public function actionDownloadraisescheme($cid,$eid,$type){
  2104. if(!in_array($type, array(2, 3)))
  2105. Yii::app()->jump->error('缺少参数!');
  2106. $classInfo = ClassModel::model()->findByPk($cid);
  2107. if (empty($classInfo)) {
  2108. Yii::app()->jump->error('未找到班级!');
  2109. }
  2110. $examInfo = Exam::model()->findByPk($eid);
  2111. if (empty($examInfo)) {
  2112. Yii::app()->jump->error('未找到周周练!');
  2113. }
  2114. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
  2115. if (empty($getResult)) {
  2116. Yii::app()->jump->error('未找到班级与纠错本对应关系!');
  2117. }
  2118. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  2119. if (empty($paperInfo)) {
  2120. Yii::app()->jump->error('未找到试卷信息!');
  2121. }
  2122. if($type == 2){
  2123. $field = "is_isp_pdf";
  2124. $check = "ISP";
  2125. }
  2126. else{
  2127. $field = "is_wbisp_pdf";
  2128. $check = "WB_ISP";
  2129. }
  2130. $relateStudent = SStudentPaperRelation::model()->findAll("paper_id=:paid and class_id=:caid and {$field}=1 and is_del=0",array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  2131. if (empty($relateStudent)) {
  2132. Yii::app()->jump->error('正在努力生成个性化学习宝!');
  2133. } else {
  2134. $studentIdArray = array();
  2135. // 获取当前考试所有学生ID
  2136. foreach ($relateStudent as $key=>$val) {
  2137. $studentIdArray[] = $val->student_id;
  2138. }
  2139. }
  2140. $filePath = array();
  2141. $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray, $check);
  2142. if (empty($getPaths)) {
  2143. Yii::app()->jump->error('正在努力生成个性化学习宝!');
  2144. } else {
  2145. $fName = $type == 2 ? "个性化学习方案" : "个性化学习宝";
  2146. // 下载文件名称
  2147. $fileName = $classInfo->class_name.$examInfo->name."{$fName}.zip";
  2148. // 下载文件路径
  2149. $result = array();
  2150. //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
  2151. $pdfPath = Yii::app()->params['student_wrong_isp_path'];
  2152. foreach ($getPaths as $path) {
  2153. /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){
  2154. $result[] = $path->isp_pdf_path;
  2155. } */
  2156. if($type == 2){
  2157. if(strpos($path->wrongbook_pdf_path,"data")!==false){
  2158. $pathstr=$pdfPath.$path->isp_pdf_path;
  2159. }else{
  2160. $pathstr=$pdfPath."uploads/".$path->isp_pdf_path;
  2161. }
  2162. if(is_file($pathstr)){
  2163. $result[] = $pathstr;
  2164. }
  2165. }
  2166. else if($type == 3){
  2167. if(strpos($path->wrongbook_pdf_path,"data")!==false){
  2168. $pathstr=$pdfPath.$path->wbisp_pdf_path;
  2169. }else{
  2170. $pathstr=$pdfPath."uploads/".$path->wbisp_pdf_path;
  2171. }
  2172. if(is_file($pathstr)){
  2173. $result[] = $pathstr;
  2174. }
  2175. }
  2176. }
  2177. if (empty($result)) {
  2178. Yii::app()->jump->error('正在生成学生个性化学习宝!');
  2179. }
  2180. // 下载
  2181. self::downloadStudentFile($fileName,$result);
  2182. }
  2183. }
  2184. // 下载学生纠错本、个性化学习宝PDF
  2185. function downloadStudentFile($fileName,$result) {
  2186. if (empty($fileName) || empty($result)) {
  2187. return false;
  2188. }
  2189. $downName = mb_convert_encoding($fileName, 'gbk', 'utf-8');
  2190. $filename = dirname(dirname(dirname(__FILE__))).'/upload/'. uniqid().".zip"; //最终生成的文件名(含路径)
  2191. $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  2192. if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
  2193. Yii::app()->jump->error('无法打开文件,或者文件创建失败');
  2194. }
  2195. //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
  2196. // $pdfPath = Yii::app()->params['student_wrong_isp_path'];
  2197. foreach ($result as $val) {
  2198. $res=$zip->addFile($val,mb_convert_encoding(preg_replace('/^.+[\\\\\\/]/', '', $val), 'GBK', 'UTF-8'));
  2199. }
  2200. $zip->close();//关闭
  2201. if (is_file($filename)){
  2202. if (FALSE!== ($handler = fopen($filename, 'r')))
  2203. {
  2204. header('Content-Description: File Transfer');
  2205. header('Content-Type: application/octet-stream');
  2206. header('Content-Disposition: attachment; filename='.$downName);
  2207. header('Content-Transfer-Encoding: chunked'); //changed to chunked
  2208. header('Expires: 0');
  2209. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  2210. header('Pragma: public');
  2211. while (!feof($handler)) {
  2212. file_put_contents("php://output", fread($handler, 4096));
  2213. }
  2214. fclose($handler);
  2215. unlink($filename);
  2216. }
  2217. exit;
  2218. }
  2219. }
  2220. // 获取周周练试卷详情(生成模板使用、打印答案解析使用)
  2221. public function actionCreatetempelate(){
  2222. $wpcode = Req::post("eid");
  2223. $flag = Req::post("flag");
  2224. $error['success'] = 0;
  2225. if (empty($wpcode)) {
  2226. $error['message'] = '么有周周练id!';
  2227. echo json_encode($error);exit();
  2228. }
  2229. $_num= '';
  2230. $use_version = '';
  2231. if(isset(Yii::app()->session['coachInfo']->use_version))
  2232. {
  2233. $use_version = Yii::app()->session['coachInfo']->use_version;
  2234. }else
  2235. {
  2236. $use_version = Yii::app()->session['coachInfo']['use_version'];
  2237. }
  2238. if(!$use_version)
  2239. {
  2240. $use_version = 100;
  2241. }
  2242. $version_number = implode('',explode('.',$use_version));
  2243. if(strlen($version_number)<7)
  2244. {
  2245. for($i=0;$i<7-strlen($version_number);$i++)
  2246. {
  2247. $_num.='0';
  2248. }
  2249. }
  2250. $version_number=(int)$version_number.$_num;
  2251. $getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getWpPapers', 'wpCode='.$wpcode);
  2252. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode));
  2253. //获取本次考试的examids
  2254. $exam_ids = array();
  2255. if($exam_data)
  2256. {
  2257. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  2258. $index_tpl = 0;
  2259. if($exam_group_data)
  2260. {
  2261. foreach($exam_group_data as $v)
  2262. {
  2263. $exam_ids[$v->exam_id] = $v->exam_id;
  2264. $index_tpl = $v->tpl_index;
  2265. }
  2266. }
  2267. if(in_array($index_tpl,Yii::app()->params['print_topic_tpl']))
  2268. {
  2269. $flag = 0;
  2270. }
  2271. if($flag==3 || $flag==4 || $flag == 12)
  2272. {
  2273. $criteria = new CDbCriteria();
  2274. $criteria->addInCondition('exam_id',$exam_ids);
  2275. $criteria->addCondition('type=:type');
  2276. $criteria->params[':type'] = 0;
  2277. $getResult = ClassExamPrinter::model()->findAll($criteria);
  2278. if (!empty($getResult)) {
  2279. ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria);
  2280. }
  2281. }
  2282. if($flag==2 || $flag==11){
  2283. $this->schoolManager->saveExamProcess($exam_data->exam_group_id,14,time());
  2284. }else{
  2285. $this->schoolManager->saveExamProcess($exam_data->exam_group_id,9,time());
  2286. }
  2287. }
  2288. echo $getRes;die;
  2289. }
  2290. // 验证试卷是否已上传模板
  2291. public function actionVerifyTpl(){
  2292. $eid = Req::post('eid');
  2293. $error['success'] = 0;
  2294. if (empty($eid)) {
  2295. $error['message'] = '考试信息不存在!';
  2296. echo json_encode($error);exit();
  2297. }
  2298. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  2299. if (empty($paperInfo)) {
  2300. $error['message'] = '未找到试卷信息!';
  2301. echo json_encode($error);exit();
  2302. }
  2303. if (empty($paperInfo->tpl_doc_src)) {
  2304. $error['message'] = '未上传模板!';
  2305. echo json_encode($error);exit();
  2306. } else {
  2307. $error['success'] = 1;
  2308. $error['message'] = '已上传模板!';
  2309. echo json_encode($error);exit();
  2310. }
  2311. //$getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpapertpl', 'paperId='.$paperInfo->paper_id);
  2312. //echo $getRes;
  2313. }
  2314. public function actionCheckAnswerCard(){
  2315. $eid = Req::post('eid');
  2316. $error['success'] = 0;
  2317. if (empty($eid)) {
  2318. $error['message'] = '考试信息不存在!';
  2319. echo json_encode($error);exit();
  2320. }
  2321. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  2322. if (empty($paperInfo)) {
  2323. $error['message'] = '未找到试卷信息!';
  2324. echo json_encode($error);exit();
  2325. }
  2326. if (empty($paperInfo->answer_card_src)) {
  2327. $error['message'] = '未上传模板!';
  2328. echo json_encode($error);exit();
  2329. } else {
  2330. $error['success'] = 1;
  2331. $error['message'] = '已上传模板!';
  2332. echo json_encode($error);exit();
  2333. }
  2334. }
  2335. // 上传试卷模板
  2336. public function actionUploadTpl(){
  2337. $eid = Req::post('eid');
  2338. $type = Req::post("type");
  2339. $error['success'] = 0;
  2340. if (empty($eid)) {
  2341. $error['message'] = '周周练id不存在!';
  2342. echo json_encode($error);exit();
  2343. }
  2344. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  2345. if (empty($paperInfo)) {
  2346. $error['message'] = '未找到试卷信息333!';
  2347. echo json_encode($error);exit();
  2348. }
  2349. $examInfo = Exam::model()->findByPk($eid);
  2350. if(empty($examInfo)){
  2351. $error['message'] = '未找到统考信息!';
  2352. echo json_encode($error);exit();
  2353. }
  2354. if (empty($_FILES['word_file'])) {
  2355. $error['message'] = '未找到上传文件!';
  2356. echo json_encode($error);exit();
  2357. }
  2358. if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){
  2359. $error['message'] = '非法上传!';
  2360. echo json_encode($error);exit();
  2361. }
  2362. if ($_FILES['word_file']['error'] > 0) {
  2363. switch ($_FILES['word_file']['error']) {
  2364. case 1:
  2365. $error['message'] = '文件大小超出了服务器的空间大小!';
  2366. break;
  2367. case 2:
  2368. $error['message'] = '要上传的文件大小超出浏览器限制!';
  2369. break;
  2370. case 3:
  2371. $error['message'] = '文件只有部分被上传!';
  2372. break;
  2373. case 4:
  2374. $error['message'] = '没有找到要上传的文件!';
  2375. break;
  2376. case 5:
  2377. $error['message'] = '服务器临时文件夹丢失!';
  2378. break;
  2379. case 6:
  2380. $error['message'] = '文件写入到临时文件夹出错!';
  2381. break;
  2382. }
  2383. echo json_encode($error);exit();
  2384. }
  2385. // 保存上传文件至服务器
  2386. $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/word/'. date('Y') .'/'. date('m') . '/';
  2387. if (!file_exists($pathName)) {
  2388. mkdir($pathName, 0777, true);
  2389. }
  2390. $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.'));
  2391. $fileName = uniqid() . $extName;
  2392. if (!move_uploaded_file($_FILES['word_file']['tmp_name'], $pathName.$fileName)) {
  2393. $error['message'] = '上传文件失败!';
  2394. echo json_encode($error);exit();
  2395. }
  2396. $param['tpl_name'] = $_FILES['word_file']['name'];
  2397. $param['paperId'] = $paperInfo->paper_id;
  2398. $param['templetA'] = $_FILES['word_file']['type'];
  2399. $param['path_tpl'] = $pathName.$fileName;
  2400. $fileSrc = $pathName.$fileName;
  2401. //FIXME 20191224
  2402. if(file_exists($fileSrc)){
  2403. $rename = 'zsyas2/uploadTpl/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $extName;
  2404. $ucloud = new HuaweiCloud();
  2405. $uploadInfo = $ucloud->putFile($rename, $fileSrc);
  2406. @unlink($fileSrc);
  2407. if ($uploadInfo['status'] == 0) {
  2408. $error['message'] = '上传文件失败!';
  2409. echo json_encode($error);exit();
  2410. }else{
  2411. $examModel = new Exam();
  2412. $examIds = $examModel->getExamIds($examInfo['exam_group_id']);
  2413. if(empty($examIds)){
  2414. $error['message'] = '上传文件失败!';
  2415. echo json_encode($error);exit();
  2416. }
  2417. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  2418. if($type == 1){
  2419. $this->sConn->createCommand("update paper set tpl_doc_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute();
  2420. }
  2421. else if($type == 2){
  2422. $this->sConn->createCommand("update paper set answer_card_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute();
  2423. }
  2424. else{
  2425. $error['message'] = '上传文件失败!';
  2426. echo json_encode($error);exit();
  2427. }
  2428. $error['success'] = 1;
  2429. $error['message'] = '上传成功!';
  2430. echo json_encode($error);exit();
  2431. }
  2432. }else{
  2433. $error['message'] = '上传文件失败!';
  2434. echo json_encode($error);exit();
  2435. }
  2436. }
  2437. public function actionExportExcel(){
  2438. $classId = Req::get("classId");
  2439. $examId = Req::get("examId");
  2440. $class = $this->schoolManager->getClass($classId);
  2441. $exam = $this->schoolManager->getExam($examId);
  2442. $className = $class ? $class["class_name"] : "";
  2443. $wpName = $exam ? $exam["name"] : "";
  2444. $report = $this->schoolManager->getExamRsByClass($examId, $classId, array(), "EXCEL");
  2445. $excel = new Excel();
  2446. $fileName = "{$className}-{$wpName}报告";
  2447. $excel->export($report, $fileName);
  2448. }
  2449. public function actionReplaceIspTopicAct(){
  2450. $planId = Req::post("planId");
  2451. $previousTopicId = Req::post("previousTopicId");
  2452. $newTopicId = Req::post("newTopicId");
  2453. $rs = $this->schoolManager->replaceIspTopic($planId, $previousTopicId, $newTopicId);
  2454. echo json_encode($rs);exit;
  2455. }
  2456. public function actionIspCheck(){
  2457. $planId = Req::get("planId");
  2458. $isp = $this->schoolManager->getIspInfo($planId);
  2459. if(!$isp)
  2460. Yii::app()->jump->error('个性化学习宝不存在');
  2461. $topics = $this->schoolManager->getIspTopics($planId);
  2462. $sections = $this->schoolManager->composeIspTopics($planId, $topics);
  2463. unset($topics);
  2464. $paper = $this->schoolManager->getExamPaper($isp["exam_id"]);
  2465. $ispTopicsIds = $this->schoolManager->getIspTopicsIds($planId);
  2466. $this->render("ispcheck", array(
  2467. "topicSections" => $sections,
  2468. "isp" => $isp,
  2469. "planId" => $planId,
  2470. "examId" => $isp["exam_id"],
  2471. "paperId" => $paper ? $paper["paper_id"] : null,
  2472. "ispTopicsIds" => implode(",", $ispTopicsIds),
  2473. ));
  2474. }
  2475. public function actionAjaxGetPaperTopicReplace()
  2476. {
  2477. $error = array();
  2478. $result = array();
  2479. if ( ! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest)
  2480. {
  2481. $error[] = '错误的来源!';
  2482. }
  2483. else
  2484. {
  2485. $examId = Yii::app()->request->getPost('examId');
  2486. $paperId = Yii::app()->request->getPost('paperId');
  2487. $topicType = (int)Yii::app()->request->getPost('topicType');
  2488. $topicId = (int)Yii::app()->request->getPost('topicId');
  2489. $methodId = (int)Yii::app()->request->getPost('methodId');
  2490. $methodDifficulty = (int)Yii::app()->request->getPost('methodDifficulty');
  2491. $notIncludeTopicId = (int)Yii::app()->request->getPost('notIncludeTopicId');
  2492. $num = (int)Yii::app()->request->getPost('num', 1);
  2493. $isArray = (int)Yii::app()->request->getPost('isArray');
  2494. $isFind = (int)Yii::app()->request->getPost('isFind');
  2495. $notInTopicsIds = Req::post('notInTopicsIds');
  2496. if ( ! $paperId OR ! is_numeric($paperId))
  2497. {
  2498. $error[] = '必须指定paperId';
  2499. }
  2500. else
  2501. {
  2502. $paperCls = new SPaper();
  2503. $paperDetail = $paperCls->getDetailByPaperId($paperId);
  2504. if ( ! $paperDetail)
  2505. {
  2506. $error[] = '未找到指定的 试卷';
  2507. }
  2508. }
  2509. if ($topicType <= 0)
  2510. {
  2511. $error[] = '必须指定 topicType';
  2512. }
  2513. elseif ( ! in_array($topicType, array(1, 5, 7)))
  2514. {
  2515. $error[] = '不允许的 topicType';
  2516. }
  2517. if ($topicId <= 0)
  2518. {
  2519. $error[] = '必须指定 topicId';
  2520. }
  2521. if (empty($methodId))
  2522. {
  2523. $error[] = '必须指定 methodId';
  2524. }
  2525. if ($methodDifficulty <= 0 OR $methodDifficulty > 3)
  2526. {
  2527. $error[] = '不允许的 methodDifficulty';
  2528. }
  2529. if ($num <= 0) $num = 1;
  2530. }
  2531. if ( ! $error)
  2532. {
  2533. $paperTopicRelationCls = new SPaperTopicRelation();
  2534. $paperTopicRelationDetail = $paperTopicRelationCls->getDetailByPaperId_TopicId($paperId, $topicId);
  2535. if ( ! $paperTopicRelationDetail)
  2536. {
  2537. $error[] = '未找到指定的试题';
  2538. }
  2539. else
  2540. {
  2541. $topicScore = $paperTopicRelationDetail['score'];
  2542. }
  2543. }
  2544. if ( ! $error)
  2545. {
  2546. $methodId = explode(",", $methodId);
  2547. $notInTopicsIds = explode(",", $notInTopicsIds);
  2548. $topicRule = array(
  2549. 'num' => $num,
  2550. 'score' => $topicScore,
  2551. 'types' => $topicType,
  2552. 'difficultys' => $methodDifficulty,
  2553. 'methods' => $methodId,
  2554. );
  2555. // if ( ! $isFind)
  2556. // {
  2557. // $topicRule['difficultys'] = $methodDifficulty;
  2558. // }
  2559. $topicItem = $this->apiPost('/smart/pull', array(
  2560. 'subjectId' => Yii::app()->params['subject_id'],
  2561. 'notInTopicsIds' => $notInTopicsIds,
  2562. 'rules' => array($topicRule),
  2563. ));
  2564. if (isset($topicItem->error))
  2565. {
  2566. $error[] = $topicItem->error;
  2567. }
  2568. else
  2569. {
  2570. if ( ! $isArray AND $num == 1)
  2571. {
  2572. $result = $topicItem[0];
  2573. }
  2574. else
  2575. {
  2576. $result = $topicItem;
  2577. }
  2578. }
  2579. }
  2580. if ( ! $error)
  2581. {
  2582. if ( ! $result)
  2583. {
  2584. $error[] = '未找到符合的题';
  2585. }
  2586. }
  2587. //header('Content-Type: application/json');
  2588. if ($error)
  2589. {
  2590. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));exit;
  2591. }
  2592. else
  2593. {
  2594. $result = Obj::toArr($result);
  2595. $topic = $this->schoolManager->getTopic($topicId);
  2596. $topicMethosCount = isset($topic["specials"]) ? count($topic["specials"]) : 0;
  2597. $matchTopics = array();
  2598. foreach($result as $key => $val){
  2599. $sameCount = 0;
  2600. $diffCount = 0;
  2601. if(isset($val["specials"]) && isset($topic["specials"])){
  2602. $diff1 = Arr::diff($val["specials"], $topic["specials"]);
  2603. $diff2 = Arr::diff($topic["specials"], $val["specials"]);
  2604. if(!$diff1 && !$diff2){
  2605. $matchTopics[] = $val;
  2606. unset($result[$key]);
  2607. continue;
  2608. }
  2609. if($diff1)
  2610. $diffCount = count($diff1);
  2611. $same = Arr::intersect($topic["specials"], $val["specials"]);
  2612. if($same)
  2613. $sameCount = count($same);
  2614. }
  2615. $result[$key]["methods_same_count"] = $sameCount;
  2616. $result[$key]["methods_diff_count"] = $diffCount;
  2617. }
  2618. //按照考点不同点升序排序
  2619. Arr::sortByField($result, "methods_diff_count");
  2620. //按照考点相同点降序排序
  2621. Arr::sortByField($result, "methods_same_count", "DESC");
  2622. //合并完全匹配考点和部分匹配考点的题 完全匹配在前
  2623. $result = Arr::merge($matchTopics, $result);
  2624. echo json_encode($result);exit;
  2625. }
  2626. }
  2627. public function actionSetPrintTransChecked(){
  2628. $planId = Req::post("planId");
  2629. $classId = Req::post("classId");
  2630. $examId = Req::post("examId");
  2631. $studentId = $this->schoolManager->getStudentIdByIspId($planId);
  2632. $this->schoolManager->setStudentIspChecked($planId);
  2633. $this->schoolManager->setPrintTransChecked($classId, $examId);
  2634. $arr=array(
  2635. 'cate' => 3,
  2636. 'schoolId' => $this->schoolId,
  2637. 'examId' => $examId,
  2638. 'studentId'=>$studentId
  2639. );
  2640. $send_json=json_encode($arr);
  2641. $stompconn = new Stomp(Yii::app()->params["activeMq"]["server"]);
  2642. $stompconn->send("wb_isp_html", $send_json);
  2643. unset($stompconn);
  2644. $redis_obj = new Redis();
  2645. $server = Yii::app()->params["redis"]["server"];
  2646. $redis_obj->connect($server["host"], $server["port"]);
  2647. $redis_obj->auth($server["password"]);
  2648. $redis_obj->select(2);
  2649. $redis_obj->set('activeMq.wb_isp_consumer.producer_time',time());
  2650. $this->redirect($this->createUrl("print/studentsispslist?classId={$classId}&examId={$examId}"));
  2651. }
  2652. public function actionIspsList(){
  2653. $getName = safe_replace(Yii::app()->request->getQuery('printName'));
  2654. $getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  2655. $statusArray= array();
  2656. if ($getStatus !== '') {
  2657. $statusArray= array($getStatus);
  2658. }
  2659. // 打印任务处理
  2660. $ExamModel = Exam::model();
  2661. $ClassModel = ClassModel::model();
  2662. $printList = array();
  2663. // 获取当前学期班级并组装
  2664. $class_array= ClassModel::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']);
  2665. $ccArray = array();
  2666. $ccName = array();
  2667. foreach ($class_array as $cc=>$ca) {
  2668. array_push($ccArray, $ca->class_id);
  2669. $ccName[$ca->class_id] = $ca->class_name;
  2670. }
  2671. if(Yii::app()->session['coachInfo']['leader'] == 1) {
  2672. $resultList = $this->schoolManager->getPrintList(array("cep.type = 2"));
  2673. }
  2674. else{
  2675. $resultList = $this->schoolManager->getPrintListOfCoach($this->coachId, array("cep.type = 2"));
  2676. }
  2677. if($resultList["rs"]){
  2678. foreach ($resultList['rs'] as $k=>$v) {
  2679. $printList[$k] = $v;
  2680. $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
  2681. $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称
  2682. if ($v["type"] == 1) {
  2683. $printList[$k]['print_name']= $pname.'"纠错本"打印任务!';
  2684. } elseif ($v["type"] == 2) {
  2685. $printList[$k]['print_name']= $pname.'"个性化学习宝"打印任务!';
  2686. } else {
  2687. $printList[$k]['print_name']= $pname.'打印任务!';
  2688. }
  2689. }
  2690. }
  2691. $data = array();
  2692. $data['getName'] = $getName;
  2693. $data['status'] = $getStatus;
  2694. $data['printList'] = $printList;
  2695. $data['pages'] = $resultList['pager'];
  2696. $data['page_total'] = $resultList['pager']->rowsCount;
  2697. unset($resultList);
  2698. $this->render("ispslist", $data);
  2699. }
  2700. public function actionStudentsIspsList(){
  2701. $classId = Req::get("classId");
  2702. $examId = Req::get("examId");
  2703. $isps = $this->schoolManager->getClassStudentsIspsList($classId, $examId);
  2704. $this->render("studentsispslist", array(
  2705. "isps" => $isps,
  2706. ));
  2707. }
  2708. public function actionUploadConfirm()
  2709. {
  2710. $error = array();
  2711. if (Yii::app()->request->getIsPostRequest())
  2712. {
  2713. $classId = safe_replace(Yii::app()->request->getPost('classId'));
  2714. $examId = safe_replace(Yii::app()->request->getPost('examId'));
  2715. if ( ! $classId AND ! is_numeric($classId))
  2716. {
  2717. $error[] = 'Params: classId error.';
  2718. }
  2719. if ( ! $examId AND ! is_numeric($examId))
  2720. {
  2721. $error[] = 'Params: examId error.';
  2722. }
  2723. }
  2724. else
  2725. {
  2726. $error[] = 'Must post request.';
  2727. }
  2728. if ( ! $error)
  2729. {
  2730. /*$relations = $this->schoolManager->getExamClassesRelations($examId);
  2731. $uploadedRelations = $this->schoolManager->getExamClassesRelationsFilteredByUploadStatus($examId, 2);
  2732. if (count($relations) == count($uploadedRelations))
  2733. {*/
  2734. $this->schoolManager->changeExamStatus($examId, 4);
  2735. $this->schoolManager->changeExamUploadStatus($examId, 2);
  2736. //}
  2737. if (!$error && ($examGroupId = $this->schoolManager->getExamGroupIdByExamId($examId)))
  2738. {
  2739. $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
  2740. if ($examIds)
  2741. {
  2742. $exams = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = '2'"));
  2743. if (count($examIds) == count($exams))
  2744. {
  2745. $examGroup = SExamGroup::model()->find('exam_group_id = :examGroupId', array(
  2746. ':examGroupId' => $examGroupId
  2747. ));
  2748. $examGroup->upload_status = 2;
  2749. $examGroup->save();
  2750. }
  2751. }
  2752. }
  2753. }
  2754. if ($error)
  2755. {
  2756. echo json_encode(array('status' => 0, 'error' => implode(PHP_EOL, $error)));exit;
  2757. }
  2758. else
  2759. {
  2760. echo json_encode(array('status' => 1, 'error' => ''));exit;
  2761. }
  2762. }
  2763. // // 更新试卷打印状态、时间
  2764. public function actionUpdatepaperprinttime() {
  2765. $cid = Req::post("cid");
  2766. $eid = Req::post("eid");
  2767. $type = Req::post("type");
  2768. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type));
  2769. if (!empty($getResult)) {
  2770. $getResult->is_print = 1;
  2771. $getResult->print_time = time();
  2772. if ($getResult->save()) {
  2773. exit('1');
  2774. } else {
  2775. exit('2');
  2776. }
  2777. }
  2778. }
  2779. /* public function actionDownstudentexcel() {
  2780. $filename="导入学生示例.xls";
  2781. $path = dirname(dirname(__FILE__)).'/data/';
  2782. $file=fopen($path.$filename,"r");
  2783. Header("Content-type:application/octet-stream");
  2784. Header("Accept-Ranges:bytes");
  2785. header("Content-Type:application/msexcel");
  2786. Header("Accept-Length:".filesize($path.$filename));
  2787. Header("Content-Disposition:attachment;filename=".$filename);
  2788. echo fread($file,filesize($path.$filename));
  2789. fclose($file);
  2790. } */
  2791. /**
  2792. * 发送/取消/重新发送标注
  2793. */
  2794. public function actionSendLabelTask(){
  2795. $examId = Req::post("examId");
  2796. $examName = Req::post("examName");
  2797. $createTime = Req::post("createTime");
  2798. $type = Req::post('type');
  2799. $status = Req::post('status');
  2800. $remark = Req::post('remark');
  2801. $isTagging = Req::post('isTagging'); //新方法宝发送标注
  2802. $estimate= Req::post('estimate'); //期望时间
  2803. if(!$examId || !$examName || !$type){
  2804. echo json_encode(array("success" => 0, "message" => "缺少必要参数"));
  2805. exit();
  2806. }
  2807. if(!($paper = $this->schoolManager->getExamPaper($examId))){
  2808. echo json_encode(array("success" => 0, "message" => "找不到试卷"));
  2809. exit();
  2810. }
  2811. if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){
  2812. echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
  2813. exit();
  2814. }
  2815. $labelledType=$paper['labelled_type']; //标注类型
  2816. $subjectId = 0;
  2817. $examTime = time();
  2818. if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){
  2819. $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData);
  2820. if(isset($tplData["examDate"]))
  2821. $examTime = strtotime($tplData["examDate"]);
  2822. }
  2823. //取消和重新发送的时候判断题库那边是否已经标注完成
  2824. $sql = "select is_third,qxk_paper_id,is_tagging from exam_group where exam_group_id = '{$exam['exam_group_id']}'";
  2825. $examGroup = $this->sConn->createCommand($sql)->queryRow();
  2826. if ($status==='2' || $status==='4' || $status==='3'){
  2827. $is_labelled = $paper['is_labelled'];
  2828. if ($is_labelled==='1'){
  2829. echo json_encode(array(
  2830. 'success' => 2,
  2831. 'message' => '已经标注完成,点击确定后刷新状态。'
  2832. ));
  2833. exit;
  2834. }
  2835. }
  2836. $this->setIs_new($exam['exam_group_id']);
  2837. if ($type=='cancel'){
  2838. $title = '取消标注';
  2839. }elseif ($type=='resend'){
  2840. $title = '重新发送标注';
  2841. }else{
  2842. $title = '发送标注';
  2843. }
  2844. //操作日志
  2845. if(Yii::app()->params['handle_log_on_off'])
  2846. {
  2847. writeFileLog(jsonEncode(array(
  2848. "exam_group_id" => (string)$exam['exam_group_id'],
  2849. "operate_project" => 'zsyas2',
  2850. "title" => $title,
  2851. "school_id" => $this->schoolId,
  2852. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2853. "operate_method" => $this->action,
  2854. "operate_url" => $this->getRoute(),
  2855. "operate_sql" => '',
  2856. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  2857. "date"=>date('Y-m-d H:i:s')
  2858. )));
  2859. }
  2860. //判断学科
  2861. if($subjectId==8 && !$isTagging){
  2862. $topics = array();
  2863. foreach($topicsRecords as $topicRecord){
  2864. $topics[$topicRecord["stem_id"]] = array(
  2865. "topic_id" => $topicRecord["stem_id"],
  2866. "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
  2867. "topic_type" => $topicRecord["type"],
  2868. "no" => $topicRecord["no"],
  2869. );
  2870. }
  2871. $jsonArr = array();
  2872. $jsonArr['exam_name'] = $examName;
  2873. $jsonArr['school_id'] = $this->schoolId;
  2874. $jsonArr['exam_group_id'] = $exam['exam_group_id'];
  2875. $jsonArr['exam_time'] = $examTime;
  2876. $jsonArr['origin'] = 'zxhx'; //校本课程平台试卷
  2877. $jsonArr['exam_topic'] = $topics; //校本课程平台试卷
  2878. if($type=='send' || $type=='resend'){
  2879. $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr));
  2880. $resultArr=json_decode($result,true);
  2881. if($resultArr['status'] == 1) {
  2882. $sql = "select exam_id from exam where exam_group_id = '{$exam['exam_group_id']}'";
  2883. $examAll = $this->sConn->createCommand($sql)->queryAll();
  2884. $examArr = array();
  2885. if ($examAll) {
  2886. foreach ($examAll as $k => $v) {
  2887. $examArr[] = $v['exam_id'];
  2888. }
  2889. $transcation = $this->sConn->beginTransaction();
  2890. try {
  2891. $this->sConn->createCommand("update paper set is_labelled = 3,labelled_type=1,send_labelled_time='".time()."' where exam_id in (" . implode(',', $examArr) . ")")->execute();
  2892. $transcation->commit();
  2893. $rs['success'] = 1;
  2894. $rs = json_encode($rs);
  2895. } catch (Exception $e) {
  2896. $transcation->rollback();
  2897. $error['message'] = '更新失败!';
  2898. $error['success'] = 0;
  2899. echo json_encode($error);
  2900. exit();
  2901. }
  2902. } else {
  2903. $error['message'] = '考试信息错误!';
  2904. $error['success'] = 0;
  2905. echo json_encode($error);
  2906. exit();
  2907. }
  2908. }elseif($resultArr['status'] == 2){ //完成标注
  2909. $rs['success'] = 1;
  2910. $rs = json_encode($rs);
  2911. }else{
  2912. $error['message'] = $resultArr['message'];
  2913. $error['success']=0;
  2914. echo json_encode($error);exit();
  2915. }
  2916. }else{
  2917. if($labelledType==2){
  2918. if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){
  2919. $error['message'] = '取消成功';
  2920. $error['success']=1;
  2921. echo json_encode($error);exit();
  2922. }else{
  2923. $error['message'] = '取消失败';
  2924. $error['success']=0;
  2925. echo json_encode($error);exit();
  2926. }
  2927. }else{
  2928. $result = Curl::http_post_json(Yii::app()->params['english_cancel_mark'], json_encode($jsonArr));
  2929. $resultArr=json_decode($result,true);
  2930. if($resultArr['status'] == 1){
  2931. $error['message'] = '取消成功';
  2932. $error['success']=1;
  2933. echo json_encode($error);exit();
  2934. }else{
  2935. $error['message'] = $resultArr['message'];
  2936. $error['success']=0;
  2937. echo json_encode($error);exit();
  2938. }
  2939. }
  2940. }
  2941. }else if($subjectId==12 || Yii::app()->params['section']==0 || $isTagging){
  2942. $topics = array();
  2943. if($type=='send' && Yii::app()->params['section']==1){
  2944. if(!$estimate){
  2945. echo json_encode(array("success" => 0, "message" => "期望时间不能为空"));
  2946. exit();
  2947. }
  2948. if(strtotime($estimate)<time()){
  2949. echo json_encode(array("success" => 0, "message" => "期望时间不正确"));
  2950. exit();
  2951. }
  2952. }
  2953. if(!$isTagging && $examGroup['is_third']){
  2954. if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecordsByTopic($paper["paper_id"]))){
  2955. echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
  2956. exit();
  2957. }
  2958. foreach($topicsRecords as $topicRecord){
  2959. $topics[] = array(
  2960. "topic_id" => $topicRecord["topic_id"],
  2961. "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
  2962. "topic_type_id" => $topicRecord["bank_type"],
  2963. );
  2964. }
  2965. }else{
  2966. foreach($topicsRecords as $topicRecord){
  2967. if($topicRecord["stem_id"]){
  2968. $topics[(string)$topicRecord["stem_id"]] = array(
  2969. "topic_id" => $topicRecord["stem_id"],
  2970. "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
  2971. "topic_type_id" => $topicRecord["logic_type"],
  2972. );
  2973. }else{
  2974. $topics[] = array(
  2975. "topic_id" => $topicRecord["topic_id"],
  2976. "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
  2977. "topic_type_id" => $topicRecord["logic_type"],
  2978. );
  2979. }
  2980. }
  2981. }
  2982. $topics=array_values($topics);
  2983. $orderType=array(); //学生订单类型
  2984. if($type=='send' || $type=='resend'){
  2985. //判断权限
  2986. if(!in_array($this->schoolId,array(476,353,3922,3865))){
  2987. if($isTagging && $this->subjectId==3) {
  2988. $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(31, 1, 2, 3,66));
  2989. }elseif($isTagging && $this->subjectId==8){
  2990. $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(3,1));
  2991. }elseif($isTagging){
  2992. $checkRs=$this->checkProductOrderDetail($exam['exam_group_id'],$subjectId,array(31));
  2993. }else{
  2994. $checkRs=$this->checkLabelTaskOrderDetail($exam['exam_group_id'],$subjectId);
  2995. }
  2996. if($checkRs==-1){
  2997. $error['message'] = '接口异常';
  2998. $error['success']=0;
  2999. echo json_encode($error);exit();
  3000. }elseif($checkRs==-2){
  3001. $error['message'] = '考试参数异常';
  3002. $error['success']=0;
  3003. echo json_encode($error);exit();
  3004. }elseif(!$checkRs){
  3005. $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
  3006. $error['success']=0;
  3007. echo json_encode($error);exit();
  3008. }
  3009. $orderType=$checkRs;
  3010. }
  3011. }
  3012. if(in_array($subjectId,$this->mathSubjectId) && $examGroup['qxk_paper_id']==0 && Yii::app()->params['section']==1){
  3013. $orderType=array();
  3014. $orderType[]=array(
  3015. 'goodsTypeId'=>31,
  3016. 'goodsTypeName'=>'方法宝'
  3017. );
  3018. }
  3019. //读取班级相同题配置
  3020. $isPushSameTrain=0;
  3021. if($this->findExamClassSameTrain($exam['exam_group_id'],$subjectId)){
  3022. $isPushSameTrain=1;
  3023. }
  3024. //计算预计时间
  3025. $realEstimate=$this->ComputeCompleteTime($exam['exam_group_id']);
  3026. if($estimate){
  3027. $estimate=strtotime($estimate);
  3028. if($estimate>$realEstimate['estimate']){
  3029. $realEstimate['estimate']=$estimate;
  3030. }
  3031. }
  3032. $classExamPinter = new SClassExamPrinter();
  3033. $isNewLabel = $classExamPinter->getNewLabel($createTime);
  3034. $classInfo=SClass::model()->getClassInfo($exam['class_id']);
  3035. $gradeName=Yii::app()->params['grade_list'][$classInfo['grade']]['grade_name'];
  3036. $provinceName=$this->schoolManager->getProvince($this->schoolInfo['province_id']);
  3037. if($examGroup['is_third']){
  3038. $examType='第三方';
  3039. }else{
  3040. $examType='云题库';
  3041. }
  3042. //是否百万校接口
  3043. $is_bw=$this->checkSchoolBW();
  3044. if ($type=='send'){
  3045. $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/index', array(
  3046. "schoolId" => $this->schoolId,
  3047. "subjectId" => $subjectId,
  3048. "examGroupId" => (string)$exam['exam_group_id'],
  3049. "examName" => $examName,
  3050. "coachName" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
  3051. "schoolName" => isset($this->schoolInfo['school_name'])?$this->schoolInfo['school_name']:'',//学校名称
  3052. "examTopics" => $topics,
  3053. "isTagging"=>$isTagging,
  3054. 'isVariant'=>$isPushSameTrain,
  3055. 'remark'=>$remark,
  3056. 'testTime'=>$examTime,
  3057. 'testNumber'=>$realEstimate['studentNumber'],
  3058. 'isNewSchool'=>$isNewLabel,
  3059. 'isMillionSchool'=>$is_bw,
  3060. 'predictCompleteTime'=>$realEstimate['estimate'],
  3061. 'qxkPaperId'=>$examGroup['qxk_paper_id'],
  3062. 'orderType'=>$orderType,
  3063. 'gradeName'=>$gradeName,
  3064. 'provinceName'=>$provinceName,
  3065. 'examType'=>$examType,
  3066. ));
  3067. $tplData['estimateTime']=$realEstimate['estimate'];
  3068. $this->schoolManager->updateEstimateTime($exam['exam_group_id'],jsonEncode($tplData));
  3069. }else{
  3070. $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_paper_status', array(
  3071. "updateType" => $status,
  3072. "schoolId" => $this->schoolId,
  3073. "subjectId" => $subjectId,
  3074. "examGroupId" => (string)$exam['exam_group_id'],
  3075. "isTagging"=>$isTagging
  3076. ));
  3077. $apiReturn=json_decode($rs,1);
  3078. }
  3079. }else{
  3080. $topics = array();
  3081. foreach($topicsRecords as $topicRecord){
  3082. $topics[] = array(
  3083. "topic_id" => $topicRecord["topic_id"],
  3084. "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
  3085. "topic_type" => $topicRecord["type"],
  3086. "is_null_method" => empty($topicRecord["method_ids"]) ? 1 : 0,
  3087. );
  3088. }
  3089. if($type=='send' || $type=='resend'){
  3090. //判断权限
  3091. if(!in_array($this->schoolId,array(476,353))){
  3092. $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId);
  3093. if($checkRs==-1){
  3094. $error['message'] = '接口异常';
  3095. $error['success']=0;
  3096. echo json_encode($error);exit();
  3097. }elseif($checkRs==-2){
  3098. $error['message'] = '考试参数异常';
  3099. $error['success']=0;
  3100. echo json_encode($error);exit();
  3101. }elseif(!$checkRs){
  3102. $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
  3103. $error['success']=0;
  3104. echo json_encode($error);exit();
  3105. }
  3106. }
  3107. }
  3108. //读取班级相同题配置
  3109. $isPushSameTrain=0;
  3110. if($this->findExamClassSameTrain($exam['exam_group_id'])){
  3111. $isPushSameTrain=1;
  3112. }
  3113. $classExamPinter = new SClassExamPrinter();
  3114. $isNewLabel = $classExamPinter->getNewLabel($createTime);
  3115. //统计班级和人数
  3116. $is_bw =0; //是否百万校
  3117. $class_number=0; //班级数量
  3118. $student_number=0; //学生数量
  3119. $countExamStudent=$this->schoolManager->countExamsAndStudents($exam['exam_group_id']);
  3120. if($countExamStudent){
  3121. if(isset($countExamStudent['classes'])){
  3122. $class_number=$countExamStudent['classes'];
  3123. }
  3124. if(isset($countExamStudent['students'])){
  3125. $student_number=$countExamStudent['students'];
  3126. }
  3127. }
  3128. //是否百万校接口
  3129. $is_bw=$this->checkSchoolBW();
  3130. if (($labelledType==2 && $type=='resend') || $type=='send'){
  3131. if($labelledType==2){
  3132. $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1);
  3133. }
  3134. $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/index', array(
  3135. "schoolId" => $this->schoolId,
  3136. "examId" => $examId,
  3137. "examName" => $examName,
  3138. "subjectId" => $subjectId,
  3139. "examTime" => $createTime,
  3140. "testTime" => $examTime,
  3141. "exam_topic" => $topics,
  3142. "exam_group_id" => (string)$exam['exam_group_id'],
  3143. "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
  3144. "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间
  3145. "is_new_label" => $isNewLabel,
  3146. "remark" => $remark,//发送备注
  3147. 'class_number'=>$class_number,
  3148. 'student_number'=>$student_number,
  3149. 'is_bw'=>$is_bw,
  3150. 'isVariant'=>$isPushSameTrain,
  3151. 'qxkPaperId'=>$examGroup['qxk_paper_id']
  3152. ));
  3153. }else{
  3154. if($labelledType==2 && $type=='cancel'){
  3155. if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){
  3156. $error['message'] = '取消成功';
  3157. $error['success']=1;
  3158. echo json_encode($error);exit();
  3159. }else{
  3160. $error['message'] = '取消失败';
  3161. $error['success']=0;
  3162. echo json_encode($error);exit();
  3163. }
  3164. }else{
  3165. if($labelledType==2){
  3166. $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1);
  3167. }
  3168. $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/set_paper_status', array(
  3169. "status" => $status,
  3170. "schoolId" => $this->schoolId,
  3171. "examId" => $examId,
  3172. "exam_group_id" => (string)$exam['exam_group_id'],
  3173. "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
  3174. "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间
  3175. "is_new_label" => $isNewLabel,
  3176. "remark" => $remark,//发送备注
  3177. 'class_number'=>$class_number,
  3178. 'student_number'=>$student_number,
  3179. 'is_bw'=>$is_bw
  3180. ));
  3181. }
  3182. }
  3183. }
  3184. $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time());
  3185. echo $rs;exit;
  3186. }
  3187. //发送标注到教师端
  3188. public function actionSendLabelToTeacher(){
  3189. $examId = Req::post("examId");
  3190. $type = Req::post('type');
  3191. $status = Req::post('status');
  3192. $remark = Req::post('remark');
  3193. if(!$examId || !$type){
  3194. echo json_encode(array("success" => 0, "message" => "缺少必要参数"));
  3195. exit();
  3196. }
  3197. if(!($paper = $this->schoolManager->getExamPaper($examId))){
  3198. echo json_encode(array("success" => 0, "message" => "找不到试卷"));
  3199. exit();
  3200. }
  3201. if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){
  3202. echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
  3203. exit();
  3204. }
  3205. //取消和重新发送的时候判断题库那边是否已经标注完成
  3206. if ($status==='2' || $status==='4' || $status==='3'){
  3207. $is_labelled = $paper['is_labelled'];
  3208. if ($is_labelled==='1'){
  3209. echo json_encode(array(
  3210. 'success' => 2,
  3211. 'message' => '教师端已经标注完成,点击确定后刷新状态。'
  3212. ));
  3213. exit;
  3214. }
  3215. }
  3216. if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){
  3217. $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData);
  3218. }
  3219. $this->setIs_new($exam['exam_group_id']);
  3220. if ($type=='cancel'){
  3221. $title = '取消标注';
  3222. }elseif ($type=='resend'){
  3223. $title = '重新发送标注';
  3224. }else{
  3225. $title = '发送标注';
  3226. }
  3227. //操作日志
  3228. if(Yii::app()->params['handle_log_on_off'])
  3229. {
  3230. writeFileLog(jsonEncode(array(
  3231. "exam_group_id" => (string)$exam['exam_group_id'],
  3232. "operate_project" => 'zsyas2',
  3233. "title" => $title,
  3234. "school_id" => $this->schoolId,
  3235. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3236. "operate_method" => $this->action,
  3237. "operate_url" => $this->getRoute(),
  3238. "operate_sql" => '',
  3239. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3240. "date"=>date('Y-m-d H:i:s')
  3241. )));
  3242. }
  3243. //判断学科
  3244. if($type=='send' || $type=='resend'){
  3245. //判断权限
  3246. if(!in_array($this->schoolId,array(476,353))){
  3247. $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId);
  3248. if($checkRs==-1){
  3249. $error['message'] = '接口异常';
  3250. $error['success']=0;
  3251. echo json_encode($error);exit();
  3252. }elseif($checkRs==-2){
  3253. $error['message'] = '考试参数异常';
  3254. $error['success']=0;
  3255. echo json_encode($error);exit();
  3256. }elseif(!$checkRs){
  3257. $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
  3258. $error['success']=0;
  3259. echo json_encode($error);exit();
  3260. }
  3261. }
  3262. }
  3263. if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],$type)){
  3264. $error['message'] = '操作成功';
  3265. $error['success']=1;
  3266. $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time());
  3267. echo json_encode($error);exit();
  3268. }else{
  3269. $error['message'] = '发送失败';
  3270. $error['success']=0;
  3271. echo json_encode($error);exit();
  3272. }
  3273. }
  3274. //检查学生订单权限
  3275. public function checkLabelTaskOrder($exam_group_id,$subjectId){
  3276. $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
  3277. if(!$examData){
  3278. return -2;
  3279. }
  3280. $examIds=array();
  3281. foreach ($examData as $val){
  3282. $examIds[]=$val;
  3283. }
  3284. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
  3285. $studentIds=array();
  3286. $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
  3287. if(!$rs){
  3288. return -2;
  3289. }
  3290. $class_id=0;
  3291. foreach ($rs as $val){
  3292. if(!$class_id){
  3293. $class_id=$val['class_id'];
  3294. }
  3295. $studentIds[]=$val['student_id'];
  3296. }
  3297. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
  3298. if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
  3299. $subjectId=3;
  3300. }
  3301. $intarr=array(
  3302. "subject"=>$subjectId,
  3303. "grade"=>$classinfo->grade,
  3304. "examTime"=>$print_time[0]->add_time,
  3305. "students"=>$studentIds,
  3306. );
  3307. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  3308. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url"], json_encode($intarr),$basic),true);
  3309. if(!$rs){
  3310. return -1;
  3311. }
  3312. if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']['hasAnyPermit'])){
  3313. if($rs['data']['hasAnyPermit']){
  3314. return 1;
  3315. }else{
  3316. return 0;
  3317. }
  3318. }else{
  3319. return -1;
  3320. }
  3321. }
  3322. //检查指定产品学生订单权限
  3323. public function checkProductOrder($exam_group_id,$subjectId,$classify=array()){
  3324. $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
  3325. if(!$examData){
  3326. return -2;
  3327. }
  3328. $examIds=array();
  3329. foreach ($examData as $val){
  3330. $examIds[]=$val;
  3331. }
  3332. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
  3333. $studentIds=array();
  3334. $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
  3335. if(!$rs){
  3336. return -2;
  3337. }
  3338. $class_id=0;
  3339. foreach ($rs as $val){
  3340. if(!$class_id){
  3341. $class_id=$val['class_id'];
  3342. }
  3343. $studentIds[]=$val['student_id'];
  3344. }
  3345. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
  3346. if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
  3347. $subjectId=3;
  3348. }
  3349. if($classify){
  3350. foreach ($classify as $item){
  3351. $intarr[]=array(
  3352. "subject"=>$subjectId,
  3353. "grade"=>$classinfo->grade,
  3354. "examTime"=>$print_time[0]->add_time,
  3355. "students"=>$studentIds,
  3356. 'clazzId'=>'',
  3357. 'semester'=>$this->semesterId,
  3358. 'classify'=>$item
  3359. );
  3360. }
  3361. }
  3362. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  3363. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr),$basic),true);
  3364. if(!$rs){
  3365. return -1;
  3366. }
  3367. if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']) && $rs['data']){
  3368. foreach ($rs['data'] as $r){
  3369. if(count($r)>0){
  3370. return 1;
  3371. }
  3372. }
  3373. return 0;
  3374. }else{
  3375. return -1;
  3376. }
  3377. }
  3378. //检查指定产品学生订单权限并返回订单详细
  3379. //examIds 用于添加删除班级判断订单,由于事务还没提交,所以直接查exam表数据不对
  3380. public function checkProductOrderDetail($exam_group_id,$subjectId,$classify=array(),$notUpdateExamIds=array()){
  3381. $examIds=array();
  3382. if($notUpdateExamIds){
  3383. $examIds=$notUpdateExamIds;
  3384. }else{
  3385. $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
  3386. if(!$examData){
  3387. return -2;
  3388. }
  3389. foreach ($examData as $val){
  3390. $examIds[]=$val;
  3391. }
  3392. }
  3393. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
  3394. $studentIds=array();
  3395. $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
  3396. if(!$rs){
  3397. return -2;
  3398. }
  3399. $class_id=0;
  3400. foreach ($rs as $val){
  3401. if(!$class_id){
  3402. $class_id=$val['class_id'];
  3403. }
  3404. $studentIds[]=$val['student_id'];
  3405. }
  3406. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
  3407. if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
  3408. $subjectId=3;
  3409. }
  3410. if($classify){
  3411. foreach ($classify as $item){
  3412. $intarr[]=array(
  3413. "subject"=>$subjectId,
  3414. "grade"=>$classinfo->grade,
  3415. "examTime"=>$print_time[0]->add_time,
  3416. "students"=>$studentIds,
  3417. 'clazzId'=>'',
  3418. 'semester'=>$this->semesterId,
  3419. 'classify'=>$item
  3420. );
  3421. }
  3422. }
  3423. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  3424. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_detail_url"], json_encode($intarr),$basic),true);
  3425. if(!$rs){
  3426. return -1;
  3427. }
  3428. if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){
  3429. if( $rs['data']){
  3430. return $rs['data'];
  3431. }else{
  3432. return 0;
  3433. }
  3434. }else{
  3435. return -1;
  3436. }
  3437. }
  3438. //检查学生订单权限,并返回学生订单类型
  3439. public function checkLabelTaskOrderDetail($exam_group_id,$subjectId){
  3440. $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
  3441. if(!$examData){
  3442. return -2;
  3443. }
  3444. $examIds=array();
  3445. foreach ($examData as $val){
  3446. $examIds[]=$val;
  3447. }
  3448. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
  3449. $studentIds=array();
  3450. $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
  3451. if(!$rs){
  3452. return -2;
  3453. }
  3454. $class_id=0;
  3455. foreach ($rs as $val){
  3456. if(!$class_id){
  3457. $class_id=$val['class_id'];
  3458. }
  3459. $studentIds[]=$val['student_id'];
  3460. }
  3461. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
  3462. if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
  3463. $subjectId=3;
  3464. }
  3465. $intarr=array(
  3466. "subject"=>$subjectId,
  3467. "grade"=>$classinfo->grade,
  3468. "examTime"=>$print_time[0]->add_time,
  3469. "students"=>$studentIds,
  3470. );
  3471. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  3472. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_any_limit_detail_url"], json_encode($intarr),$basic),true);
  3473. if(!$rs){
  3474. return -1;
  3475. }
  3476. if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){
  3477. if($rs['data']){
  3478. return $rs['data'];
  3479. }else{
  3480. return 0;
  3481. }
  3482. }else{
  3483. return -1;
  3484. }
  3485. }
  3486. public function actionGetImproveFile(){
  3487. $examId = Req::get("examId");
  3488. $classId = Req::get("classId");
  3489. $type = Req::get("type");
  3490. $studentsIds = Req::get("studentsIds");
  3491. $printType = Req::get("printType");
  3492. $students_ids = array();
  3493. $is_isp_student_ids = array();
  3494. $is_wbisp_student_ids = array();
  3495. $is_wrongbook_student_ids = array();
  3496. if(!$examId || !$classId || !$type){
  3497. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  3498. exit();
  3499. }
  3500. if(!in_array($type, array(1, 2, 3))){
  3501. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  3502. exit();
  3503. }
  3504. $groupInfo = Exam::model()->getGroupInfo($examId);
  3505. if(empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误")));
  3506. $typeRel = array('1'=>'wb_group_id','2'=>'isp_group_id','3'=>'wbisp_group_id');
  3507. $groupId = $groupInfo[$typeRel[$type]];
  3508. if(!empty($groupId)){
  3509. $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
  3510. }else{
  3511. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  3512. }
  3513. //$apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
  3514. // $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  3515. // echo $apiUrl;exit;
  3516. //$apiUrl = isset(Yii::app()->params["improve_url"][0]) ? Yii::app()->params["improve_url"][0] : null;
  3517. if(!$apiUrl){
  3518. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  3519. exit();
  3520. }
  3521. $params = array(
  3522. "schoolId" => $this->schoolId,
  3523. "examId" => $examId,
  3524. "classId" => $classId,
  3525. "type" => $type,
  3526. "studentIds" => array(),
  3527. );
  3528. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId));
  3529. $Sem=new SSemester();
  3530. $code= $Sem->conn->createQuery()
  3531. ->from('semester')
  3532. ->where("semester_id = '".$classinfo['semester_id']."'")
  3533. ->limit(1)
  3534. ->query()
  3535. ->read();
  3536. $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$examId,':classid'=>$classId));
  3537. $intarr=array(
  3538. "schoolId"=>$this->schoolId,
  3539. "clazzId"=>$classId,
  3540. "semester"=>$code['refer_code'],
  3541. "grade"=>$classinfo['grade'],
  3542. "students"=>array(),
  3543. "examTime"=>$print_time[0]->add_time,
  3544. "classify"=>$type,
  3545. );
  3546. //判断学科
  3547. $examInfo = Exam::model()->findByPk($examId);
  3548. $intarr['subject']=$examInfo['subject_id'];
  3549. if($intarr['subject']==6){
  3550. $intarr['subject']=3;
  3551. }
  3552. if(in_array($intarr['subject'],$this->mathSubjectId)){
  3553. $intarr['subject']=3;
  3554. }
  3555. if ($studentsIds) {
  3556. $studentsIds = explode(",", $studentsIds);
  3557. foreach ($studentsIds as $key => $val) {
  3558. $val = trim($val);
  3559. if ($val == null) {
  3560. unset($studentsIds[$key]);
  3561. continue;
  3562. }
  3563. $students_ids[$val] = $val;
  3564. $studentsIds[$key] = $val;
  3565. }
  3566. $intarr['students'] = $studentsIds;
  3567. $stu = SStudentPaperRelation::model()->findAll("exam_id=:eid", array(":eid" => $examId));
  3568. foreach ($stu as $key => $val) {
  3569. if (isset($students_ids[$val->student_id])) {
  3570. if ($val->is_isp_pdf == 1) {
  3571. $is_isp_student_ids[$val->student_id] = $val->student_id;
  3572. }
  3573. if ($val->is_wbisp_pdf == 1) {
  3574. $is_wbisp_student_ids[$val->student_id] = $val->student_id;
  3575. }
  3576. if ($val->is_wrongbook_pdf == 1) {
  3577. $is_wrongbook_student_ids[$val->student_id] = $val->student_id;
  3578. }
  3579. }
  3580. }
  3581. } else {
  3582. $stu = SStudentPaperRelation::model()->findAll("class_id=:class_id and exam_id=:eid", array(":class_id" => $classId, ":eid" => $examId));
  3583. foreach ($stu as $key => $val) {
  3584. $intarr['students'][] = $val->student_id;
  3585. if ($val->is_isp_pdf == 1) {
  3586. $is_isp_student_ids[$val->student_id] = $val->student_id;
  3587. }
  3588. if ($val->is_wbisp_pdf == 1) {
  3589. $is_wbisp_student_ids[$val->student_id] = $val->student_id;
  3590. }
  3591. if ($val->is_wrongbook_pdf == 1) {
  3592. $is_wrongbook_student_ids[$val->student_id] = $val->student_id;
  3593. }
  3594. }
  3595. }
  3596. $limitinfo="";
  3597. //third_wb第三方多学科和英语不需要权限
  3598. // $subject_id = isset(Yii::app()->session['session_subject_id'])?Yii::app()->session['session_subject_id']:0;
  3599. // $params["subjectId"] = $subject_id;
  3600. // if($printType == 'third_wb' || $printType == 'third_isp' || $subject_id == 8){
  3601. // if($printType == 'third_isp'){
  3602. // $params["subjectId"] = 8;
  3603. // $params["type"] = 2;
  3604. // }
  3605. // if($intarr["students"]){
  3606. // $params["studentIds"] = $intarr["students"];
  3607. // }
  3608. // }else{
  3609. $_schoolId = isset(Yii::app()->session['coachInfo']['school_id'])?Yii::app()->session['coachInfo']['school_id']:0;
  3610. if($printType == 'third_isp'){
  3611. $params["subjectId"] = 8;
  3612. $params["type"] = 3;
  3613. }
  3614. if ($_schoolId) {
  3615. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $_schoolId));
  3616. }
  3617. // if(isset(Yii::app()->session['testFlag']) && (Yii::app()->session['testFlag']==1)){
  3618. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  3619. if($studentsIds){
  3620. $params["studentIds"] = $studentsIds;
  3621. }
  3622. }else{
  3623. if(Yii::app()->params["limit_open"]){
  3624. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  3625. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  3626. if(!$rs){
  3627. Yii::app()->jump->error("接口错误");
  3628. }
  3629. if($rs->errCode!="00"){
  3630. echo json_encode(array("success" => 0, "message" => $rs->errMsg));
  3631. exit();
  3632. }
  3633. if(!empty($rs->data)){
  3634. $params["studentIds"]=$rs->data;
  3635. if(count($rs->data)<count($intarr['students'])){
  3636. $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
  3637. }
  3638. } else{
  3639. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  3640. exit();
  3641. }
  3642. }else{
  3643. if($studentsIds){
  3644. $params["studentIds"] = $studentsIds;
  3645. }
  3646. }
  3647. }
  3648. // }
  3649. $rs = Curl::post($apiUrl."/rest/download_pdf/index", $params);
  3650. if(!($rs = json_decode($rs))){
  3651. $rs = array(
  3652. "success" => 0,
  3653. "message" => "请求接口失败",
  3654. );
  3655. }
  3656. if($printType != 'third_wb'){
  3657. if($limitinfo!=""&&$rs->success!=0){
  3658. $rs->success=2;
  3659. $rs->limitinfo=$limitinfo;
  3660. }
  3661. }
  3662. if($type==1)
  3663. {
  3664. $criteria = new CDbCriteria();
  3665. $_students = array();
  3666. if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
  3667. {
  3668. $_students = $is_wrongbook_student_ids;
  3669. }else
  3670. {
  3671. foreach($params["studentIds"] as $v)
  3672. {
  3673. if(isset($is_wrongbook_student_ids[$v]))
  3674. {
  3675. $_students[] = $v;
  3676. }
  3677. }
  3678. }
  3679. if($_students){
  3680. $criteria->addInCondition('student_id',$_students);
  3681. }else{
  3682. $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
  3683. $criteria->params[':is_complete'] = 1;
  3684. $criteria->params[':is_feedback'] = 1;
  3685. $criteria->params[':is_del'] = 1;
  3686. }
  3687. if($studentsIds || count($studentsIds)>0)
  3688. {
  3689. $criteria->addInCondition('student_id',$studentsIds);
  3690. }else
  3691. {
  3692. $criteria->addCondition('class_id=:class_id');
  3693. $criteria->params[':class_id'] = $classId;
  3694. }
  3695. $criteria->addCondition('exam_id=:exam_id');
  3696. $criteria->addCondition('is_wrongbook_download=:is_wrongbook_download');
  3697. $criteria->params[':exam_id'] = $examId;
  3698. $criteria->params[':is_wrongbook_download'] = 0;
  3699. SStudentPaperRelation::model()->updateAll(array('is_wrongbook_download'=>1,'download_wrongbook_time'=>time()),$criteria);
  3700. }
  3701. if($type==2)
  3702. {
  3703. $criteria = new CDbCriteria();
  3704. $_students = array();
  3705. if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
  3706. {
  3707. $_students = $is_isp_student_ids;
  3708. }else
  3709. {
  3710. foreach($params["studentIds"] as $v)
  3711. {
  3712. if(isset($is_isp_student_ids[$v]))
  3713. {
  3714. $_students[] = $v;
  3715. }
  3716. }
  3717. }
  3718. if($_students){
  3719. $criteria->addInCondition('student_id',$_students);
  3720. }else{
  3721. $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
  3722. $criteria->params[':is_complete'] = 1;
  3723. $criteria->params[':is_feedback'] = 1;
  3724. $criteria->params[':is_del'] = 1;
  3725. }
  3726. if($studentsIds || count($studentsIds)>0)
  3727. {
  3728. $criteria->addInCondition('student_id',$studentsIds);
  3729. }else
  3730. {
  3731. $criteria->addCondition('class_id=:class_id');
  3732. $criteria->params[':class_id'] = $classId;
  3733. }
  3734. $criteria->addCondition('exam_id=:exam_id');
  3735. $criteria->addCondition('is_two_isp_download=:is_two_isp_download');
  3736. $criteria->params[':exam_id'] = $examId;
  3737. $criteria->params[':is_two_isp_download'] = 0;
  3738. SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),$criteria);
  3739. }
  3740. if($type==3)
  3741. {
  3742. $criteria = new CDbCriteria();
  3743. $_students = array();
  3744. if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
  3745. {
  3746. $_students = $is_wbisp_student_ids;
  3747. }else
  3748. {
  3749. foreach($params["studentIds"] as $v)
  3750. {
  3751. if(isset($is_wbisp_student_ids[$v]))
  3752. {
  3753. $_students[] = $v;
  3754. }
  3755. }
  3756. }
  3757. if($_students){
  3758. $criteria->addInCondition('student_id',$_students);
  3759. }else{
  3760. $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
  3761. $criteria->params[':is_complete'] = 1;
  3762. $criteria->params[':is_feedback'] = 1;
  3763. $criteria->params[':is_del'] = 1;
  3764. }
  3765. if($studentsIds || count($studentsIds)>0)
  3766. {
  3767. $criteria->addInCondition('student_id',$studentsIds);
  3768. }else
  3769. {
  3770. $criteria->addCondition('class_id=:class_id');
  3771. $criteria->params[':class_id'] = $classId;
  3772. }
  3773. $criteria->addCondition('exam_id=:exam_id');
  3774. $criteria->addCondition('is_three_isp_download=:is_three_isp_download');
  3775. $criteria->params[':exam_id'] = $examId;
  3776. $criteria->params[':is_three_isp_download'] = 0;
  3777. SStudentPaperRelation::model()->updateAll(array('is_three_isp_download'=>1,'download_three_isp_time'=>time()),$criteria);
  3778. }
  3779. if($groupId && isset($rs->downloadPath)){
  3780. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  3781. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
  3782. }
  3783. }
  3784. echo json_encode($rs);exit;
  3785. }
  3786. public function setIs_new($exam_group_id)
  3787. {
  3788. if($exam_group_id)
  3789. {
  3790. Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  3791. }
  3792. }
  3793. public function actionSetPaperSize(){
  3794. $examId = Req::post("examId");
  3795. $paperSize = Req::post("paperSize");
  3796. $mark_type = Req::post("mark_type");
  3797. $tpl_index = Req::post("tpl_index");
  3798. $exam_ids = array();
  3799. if(!$examId)
  3800. $this->output(0, "参数错误[1]");
  3801. if(!$paperSize)
  3802. $this->output(0, "参数错误[2]");
  3803. if(!in_array($paperSize, array("A3", "A4", "8K", "16K")))
  3804. $this->output(0, "参数错误[3]");
  3805. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
  3806. $paper_topic_m_data = array();
  3807. if($paper_data)
  3808. {
  3809. $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
  3810. if($paper_topic_data)
  3811. {
  3812. foreach($paper_topic_data as $v)
  3813. {
  3814. $paper_topic_m_data[$v->type][] = $v->topic_id;
  3815. }
  3816. //30 ,30 15
  3817. if(((isset($paper_topic_m_data[1]) && count($paper_topic_m_data[1])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[5]) && count($paper_topic_m_data[5])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[7]) && count($paper_topic_m_data[7])>15 && in_array($paperSize, array("A4", "8K", "16K")))))
  3818. {
  3819. $this->output(0, "题数太多,无法切换");
  3820. }
  3821. }
  3822. }
  3823. $paperSizesAndTplIndexesRelations = array(
  3824. "A3" => 12,
  3825. "A4" => 13,
  3826. "8K" => 14,
  3827. "16K" => 15,
  3828. );
  3829. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl"]))
  3830. {
  3831. $paperSizesAndTplIndexesRelations = array(
  3832. "A3" => 16,
  3833. "A4" => 17,
  3834. "8K" => 18,
  3835. "16K" => 19,
  3836. );
  3837. }
  3838. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl1"]))
  3839. {
  3840. $paperSizesAndTplIndexesRelations = array(
  3841. "A3" => 2012,
  3842. "A4" => 2013,
  3843. "8K" => 2014,
  3844. "16K" => 2015,
  3845. );
  3846. }
  3847. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl2"]))
  3848. {
  3849. $paperSizesAndTplIndexesRelations = array(
  3850. "A3" => 2016,
  3851. "A4" => 2017,
  3852. "8K" => 2018,
  3853. "16K" => 2019,
  3854. );
  3855. }
  3856. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl3"]))
  3857. {
  3858. $paperSizesAndTplIndexesRelations = array(
  3859. "A3" => 1012,
  3860. "A4" => 1013,
  3861. "8K" => 1014,
  3862. "16K" => 1015,
  3863. );
  3864. }
  3865. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl4"]))
  3866. {
  3867. $paperSizesAndTplIndexesRelations = array(
  3868. "A3" => 1016,
  3869. "A4" => 1017,
  3870. "8K" => 1018,
  3871. "16K" => 1019,
  3872. );
  3873. }
  3874. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl5"]))
  3875. {
  3876. $paperSizesAndTplIndexesRelations = array(
  3877. "A3" => 3016,
  3878. "A4" => 3017,
  3879. "8K" => 3018,
  3880. "16K" => 3019,
  3881. );
  3882. }
  3883. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl6"]))
  3884. {
  3885. $paperSizesAndTplIndexesRelations = array(
  3886. "A3" => 3012,
  3887. "A4" => 3013,
  3888. "8K" => 3014,
  3889. "16K" => 3015,
  3890. );
  3891. }
  3892. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl7"]))
  3893. {
  3894. $paperSizesAndTplIndexesRelations = array(
  3895. "A3" => 4016,
  3896. "A4" => 4017,
  3897. "8K" => 4018,
  3898. "16K" => 4019,
  3899. );
  3900. }
  3901. if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl8"]))
  3902. {
  3903. $paperSizesAndTplIndexesRelations = array(
  3904. "A3" => 4012,
  3905. "A4" => 4013,
  3906. "8K" => 4014,
  3907. "16K" => 4015,
  3908. );
  3909. }
  3910. $exam_row = Exam::model()->find(array(
  3911. 'select'=>array('exam_id,exam_group_id'),
  3912. 'condition' => 'exam_id=:exam_id',
  3913. 'params' => array(':exam_id'=>$examId)
  3914. ));
  3915. if($exam_row)
  3916. {
  3917. $exam_data = Exam::model()->findAll(array(
  3918. 'select'=>array('exam_id,exam_group_id'),
  3919. 'condition' => 'exam_group_id=:exam_group_id',
  3920. 'params' => array(':exam_group_id'=>$exam_row->exam_group_id)
  3921. ));
  3922. if($exam_data)
  3923. {
  3924. foreach($exam_data as $v)
  3925. {
  3926. $exam_ids[$v->exam_id] = $v->exam_id;
  3927. }
  3928. if($exam_ids)
  3929. {
  3930. $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
  3931. if(!$exam_group_array )
  3932. {
  3933. $this->output(0, "非法数据");
  3934. }
  3935. if($exam_group_array->upload_status>0)
  3936. {
  3937. $this->output(0, "无法修改,已上传数据");
  3938. }
  3939. //操作日志
  3940. if(Yii::app()->params['handle_log_on_off'])
  3941. {
  3942. writeFileLog(jsonEncode(array(
  3943. "exam_group_id" => (string)$exam_row->exam_group_id,
  3944. "operate_project" => 'zsyas2',
  3945. "school_id" => $this->schoolId,
  3946. "title" => '更改试卷阅卷与纸张',
  3947. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3948. "operate_method" => $this->action,
  3949. "operate_url" => $this->getRoute(),
  3950. "operate_sql" => json_encode(array('update'=>array(
  3951. 'ExamGroup'=>array('mark_type'=>$mark_type),
  3952. 'exam'=>array('tpl_index'=>$paperSizesAndTplIndexesRelations[$paperSize],'update_time'=>time()),
  3953. ))),
  3954. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3955. "date"=>date('Y-m-d H:i:s')
  3956. )));
  3957. }
  3958. $this->setIs_new($exam_row->exam_group_id);
  3959. if(is_null($mark_type))
  3960. {
  3961. $mark_type = $exam_group_array->mark_type;
  3962. }
  3963. if(is_numeric($mark_type))
  3964. {
  3965. $transaction = $this->sConn->beginTransaction();
  3966. try{
  3967. if($exam_group_array->mark_type==4)
  3968. {
  3969. $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
  3970. }else
  3971. {
  3972. if($mark_type==4)
  3973. {
  3974. $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
  3975. }
  3976. if($mark_type!=4 && $exam_group_array->mark_type!=4)
  3977. {
  3978. if($exam_group_array->mark_status == 0 )
  3979. {
  3980. ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
  3981. $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
  3982. }else
  3983. {
  3984. //ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
  3985. $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}' where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
  3986. }
  3987. }
  3988. }
  3989. $transaction->commit();
  3990. }catch(Exception $e)
  3991. {
  3992. $transaction->rollBack();
  3993. $this->output(0, "更改失败");
  3994. }
  3995. }
  3996. }
  3997. }
  3998. }
  3999. $this->output(1, "更改成功");
  4000. }
  4001. /**
  4002. * 设置阅卷方式
  4003. */
  4004. public function actionSetmasktype(){
  4005. $exam_group_id = Req::post("exam_group_id");
  4006. $mark_type = Req::post("mark_type");
  4007. $tpl_index = Req::post("tpl_index");
  4008. $exam_ids = array();
  4009. if(!$exam_group_id)
  4010. $this->output(0, "参数错误[1]");
  4011. $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4012. if(!$exam_group_array )
  4013. {
  4014. $this->output(0, "非法数据");
  4015. }
  4016. if($exam_group_array['upload_status']>0){
  4017. $this->output(0, "已上传成绩不能修改阅卷方式");
  4018. }
  4019. $thirdAnswerSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4020. if($exam_group_array['is_third']==1 || $exam_group_array['is_scan_changed']==1){
  4021. if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==0 && $mark_type==0){
  4022. $this->output(0, "切割模板考试不能切换线下阅卷");
  4023. }
  4024. }
  4025. if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==1 && $mark_type==0){
  4026. //判断答题卡评阅类型
  4027. $check = $this->sConn->createCommand("select `marking_papers` from online_card_multiplex where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->queryRow();
  4028. if($check['marking_papers']!=1){
  4029. $this->output(0, "当前在线答题卡的评阅方式为网阅,不支持修改为线下阅卷,请进入在线答题卡修改评阅方式为手批后再更改阅卷方式!");
  4030. }
  4031. }
  4032. if(!in_array($mark_type,array(0,3,4))) $this->output(0, "阅卷方式不正确");
  4033. $transaction = $this->sConn->beginTransaction();
  4034. try{
  4035. if($exam_group_array['mark_type']==4 || $mark_type==4){
  4036. $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute();
  4037. }
  4038. if($mark_type==4){
  4039. $exam=$this->sConn->createCommand("select exam_id,tpl_data,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryRow();
  4040. $paper=$this->sConn->createCommand("select paper_id from paper where exam_id='{$exam['exam_id']}'")->queryRow();
  4041. $paperTopic=$this->sConn->createCommand("select `order`,question_count,`type`,topic_id,score from paper_topic_relation where paper_id='{$paper['paper_id']}' and `type` not in(1,2,11)")->queryAll();
  4042. if($paperTopic){
  4043. $topicAutoType=array();
  4044. if($exam['subject_id']==8){
  4045. $tplData=json_decode($exam['tpl_data'],true);
  4046. if(isset($tplData['new_items'])){
  4047. foreach ($tplData['new_items'] as $item){
  4048. $topicAutoType[$item['id']]=$item['logic_type'];
  4049. }
  4050. }
  4051. }
  4052. foreach ($paperTopic as $item){
  4053. $autoType=0;
  4054. if(isset($topicAutoType[$item['order']])){
  4055. if(in_array($topicAutoType[$item['order']],array(13,16,17)) && $item['question_count']==0){
  4056. $autoType=1;
  4057. }elseif($item['type']==5){
  4058. $autoType=2;
  4059. }
  4060. }
  4061. $this->sConn->createCommand()->insert('marking_topic', array(
  4062. 'exam_group_id' => $exam_group_id,
  4063. 'topic_id' => $item['topic_id'],
  4064. 'topic_type' => $item['type'],
  4065. 'topic_index' =>$item['order'],
  4066. 'topic_no' =>$item['order'],
  4067. 'topic_score' =>$item['score'],
  4068. 'auto_type'=>$autoType
  4069. ));
  4070. }
  4071. }
  4072. ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4073. }else{
  4074. ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>0),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4075. }
  4076. $transaction->commit();
  4077. }catch(Exception $e)
  4078. {
  4079. $transaction->rollBack();
  4080. if(Yii::app()->params['handle_log_on_off'])
  4081. {
  4082. writeFileLog(jsonEncode(array(
  4083. "exam_group_id" => (string)$exam_group_id,
  4084. "operate_project" => 'zsyas2',
  4085. "school_id" => $this->schoolId,
  4086. "title" => '更改阅卷方式失败',
  4087. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4088. "operate_method" => $this->action,
  4089. "operate_url" => $this->getRoute(),
  4090. "operate_sql" => json_encode(array('update'=>array(
  4091. 'ExamGroup'=>array('mark_type'=>$mark_type),
  4092. ))),
  4093. "error"=>$e->getMessage(),
  4094. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4095. "date"=>date('Y-m-d H:i:j')
  4096. )));
  4097. }
  4098. $this->output(0, "更改失败");
  4099. }
  4100. if(Yii::app()->params['handle_log_on_off'])
  4101. {
  4102. writeFileLog(jsonEncode(array(
  4103. "exam_group_id" => (string)$exam_group_id,
  4104. "operate_project" => 'zsyas2',
  4105. "school_id" => $this->schoolId,
  4106. "title" => '更改阅卷方式',
  4107. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4108. "operate_method" => $this->action,
  4109. "operate_url" => $this->getRoute(),
  4110. "operate_sql" => json_encode(array('update'=>array(
  4111. 'ExamGroup'=>array('mark_type'=>$mark_type),
  4112. ))),
  4113. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4114. "date"=>date('Y-m-d H:i:j')
  4115. )));
  4116. }
  4117. $this->output(1, "更改成功");
  4118. }
  4119. // 操作周周练显示状态
  4120. public function actionOprateexam(){
  4121. $exam_groupId = Req::post("exam_groupId");
  4122. $flag = Req::post("flag");
  4123. $error['success'] = 0;
  4124. if (empty($exam_groupId)) {
  4125. $error['message'] = '操作失败!';
  4126. echo json_encode($error);exit();
  4127. }
  4128. $this->setIs_new($exam_groupId);
  4129. if ($this->schoolManager->oprateExamDisplay($exam_groupId,$flag)) {
  4130. $error['success'] = 1;
  4131. $error['message'] = '操作成功!';
  4132. } else {
  4133. $error['message'] = '操作失败!';
  4134. }
  4135. echo json_encode($error);exit();
  4136. }
  4137. // 根据年级获取班级
  4138. public function actionGetGradeClass(){
  4139. $grade = Req::post('grade');
  4140. $subjectId = Req::post('subjectId');
  4141. $filterHide=Req::post('filterHide');
  4142. if(!$filterHide){
  4143. $filterHide=0;
  4144. }else{
  4145. $filterHide=1;
  4146. }
  4147. $error['success'] = 0;
  4148. if (empty($grade)) {
  4149. $error['message'] = '未找到年级!';
  4150. echo json_encode($error);exit();
  4151. }
  4152. $classes=array();
  4153. //判断走班设置
  4154. if($subjectId){
  4155. $classified=$this->schoolManager->getSubjectByGrade($grade,$subjectId,Yii::app()->session['session_semester_id']);
  4156. if($classified){
  4157. $classes=$this->schoolManager->getClassifiedBySubjectId($grade,$subjectId,Yii::app()->session['session_semester_id']);
  4158. }else{
  4159. $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
  4160. }
  4161. }else{
  4162. $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
  4163. }
  4164. if ($classes) {
  4165. $error['success'] = 1;
  4166. $error['message'] = $classes;
  4167. } else {
  4168. $error['message'] = '未找到班级!';
  4169. }
  4170. echo json_encode($error);exit();
  4171. }
  4172. // 根据年级获取班级
  4173. public function actionGetGradeClassForExport(){
  4174. $grade = Req::post('grade');
  4175. $subjectId = Req::post('subjectId');
  4176. $error['success'] = 0;
  4177. if (empty($grade)) {
  4178. $error['message'] = '未找到年级!';
  4179. echo json_encode($error);exit();
  4180. }
  4181. $classes=array();
  4182. $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
  4183. if ($classes) {
  4184. $error['success'] = 1;
  4185. $error['message'] = $classes;
  4186. } else {
  4187. $error['message'] = '未找到班级!';
  4188. }
  4189. echo json_encode($error);exit();
  4190. }
  4191. /**
  4192. * 作者:刘红伟
  4193. * 需求:删除本次考试,但已经考完的学生不能删除
  4194. * 时间:2016-10-25
  4195. */
  4196. public function actionDelPaperStudent()
  4197. {
  4198. $studentsIds = Req::post('studentsIds');
  4199. $exam_id = Req::post('exam_id');
  4200. $paper_id = Req::post('paper_id');
  4201. $class_id = Req::post('class_id');
  4202. if(!$studentsIds || !$exam_id || !$paper_id)
  4203. {
  4204. echo json_encode(array('status'=>0));exit;
  4205. }
  4206. $studentsIds = explode(',',$studentsIds);
  4207. if($this->schoolManager->getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id))
  4208. {
  4209. echo json_encode(array('status'=>2));exit;
  4210. };
  4211. if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id))
  4212. {
  4213. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4214. //操作日志
  4215. if(Yii::app()->params['handle_log_on_off'])
  4216. {
  4217. writeFileLog(jsonEncode(array(
  4218. "exam_group_id" => (string)$exam_data->exam_group_id,
  4219. "operate_project" => 'zsyas2',
  4220. "school_id" => $this->schoolId,
  4221. "title" => '删除考试的学生',
  4222. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4223. "operate_method" => $this->action,
  4224. "operate_url" => $this->getRoute(),
  4225. "operate_sql" => json_encode(array('delete'=>array(
  4226. 'student_paper_relation'=>array('student_id'=>$studentsIds)))),
  4227. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4228. "date"=>date('Y-m-d H:i:j')
  4229. )));
  4230. }
  4231. //发送学生端消息
  4232. //
  4233. $sendJsonArr=array(
  4234. 'school_id'=>$this->schoolId,
  4235. 'send_type'=>'zsyas',
  4236. 'update_type'=>2,
  4237. 'exam_group_id'=>$exam_data->exam_group_id,
  4238. 'exam_id_arr'=>array($exam_id),
  4239. 'student_id_arr'=>$studentsIds
  4240. );
  4241. sendStudentCacheQueue($sendJsonArr);
  4242. $kafkaData=array(
  4243. 'schoolId'=>$this->schoolId,
  4244. 'examGroupId'=>$exam_data->exam_group_id,
  4245. 'generateTime'=>time()*1000
  4246. );
  4247. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  4248. echo json_encode(array('status'=>1));exit;
  4249. }
  4250. echo json_encode(array('status'=>0));exit;
  4251. }
  4252. public function actionDelPaperStudentAll()
  4253. {
  4254. $exam_id = Req::post('exam_id');
  4255. $paper_id = Req::post('paper_id');
  4256. $class_id = Req::post('class_id');
  4257. $studentsIds = array();
  4258. if(!$exam_id || !$paper_id)
  4259. {
  4260. echo json_encode(array('status'=>0));exit;
  4261. }
  4262. $student_data = SStudentPaperRelation::model()->findAll('paper_id=:paper_id and exam_id=:exam_id and is_feedback=:is_feedback and is_del=0',array(':paper_id'=>$paper_id,':exam_id'=>$exam_id,':is_feedback'=>0));
  4263. if($student_data)
  4264. {
  4265. foreach($student_data as $v)
  4266. {
  4267. $studentsIds[$v->student_id] = $v->student_id;
  4268. }
  4269. }
  4270. if(!$studentsIds){
  4271. echo json_encode(array('status'=>2));exit;
  4272. }
  4273. if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id))
  4274. {
  4275. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4276. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  4277. //操作日志
  4278. if(Yii::app()->params['handle_log_on_off'])
  4279. {
  4280. writeFileLog(jsonEncode(array(
  4281. "exam_group_id" => (string)$exam_data->exam_group_id,
  4282. "operate_project" => 'zsyas2',
  4283. "school_id" => $this->schoolId,
  4284. "title" => '清空本次考试的学生',
  4285. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4286. "operate_method" => $this->action,
  4287. "operate_url" => $this->getRoute(),
  4288. "operate_sql" => json_encode(array('delete'=>array(
  4289. 'student_paper_relation'=>array('student_id'=>$studentsIds)))),
  4290. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4291. "date"=>date('Y-m-d H:i:s')
  4292. )));
  4293. }
  4294. //发送学生端消息
  4295. $sendJsonArr = array(
  4296. 'school_id' => $this->schoolId,
  4297. 'send_type' => 'zsyas',
  4298. 'update_type' => 2,
  4299. 'exam_group_id' => $exam_data->exam_group_id,
  4300. 'exam_id_arr' => array($exam_id),
  4301. 'student_id_arr' => $studentsIds
  4302. );
  4303. sendStudentCacheQueue($sendJsonArr);
  4304. echo json_encode(array('status'=>1));exit;
  4305. }
  4306. echo json_encode(array('status'=>0));exit;
  4307. }
  4308. public function actionAddPaperStudent()
  4309. {
  4310. $studentsIds = Req::post('studentsIds');
  4311. $exam_id = Req::post('exam_id');
  4312. $paper_id = Req::post('paper_id');
  4313. $class_id = Req::post('class_id');
  4314. $exam_ids = array();
  4315. $student_ids = array();
  4316. $student_names = array();
  4317. $add_student_paper = array();
  4318. $del_student_paper = array();
  4319. $student_cards = array();
  4320. $school_student_cards = array();
  4321. if(!$exam_id || !$paper_id || !$class_id || !$studentsIds || !$this->semesterId)
  4322. {
  4323. echo json_encode(array('status'=>0));exit;
  4324. }
  4325. if($this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id))
  4326. {
  4327. echo json_encode(array('status'=>2));exit;
  4328. }
  4329. $student_array = explode(',',$studentsIds);
  4330. /* $student_paper_del_data = $this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id,1);
  4331. if($student_paper_del_data)
  4332. {
  4333. foreach($student_paper_del_data as $v)
  4334. {
  4335. $del_student_paper[$v['student_id']] = $v['student_id'];
  4336. }
  4337. }
  4338. $add_student_paper = array_diff($student_array,$del_student_paper);*/
  4339. /**
  4340. *加入准考证号
  4341. */
  4342. $criteria = new CDbCriteria();
  4343. $criteria->addInCondition('student_id',$student_array);
  4344. $criteria->addCondition('status = 0');
  4345. $business_student_data = BusinessStudent::model()->findAll($criteria);
  4346. if($business_student_data)
  4347. {
  4348. foreach($business_student_data as $v)
  4349. {
  4350. $student_cards[$v->student_id] = $v->student_card;
  4351. $school_student_cards[$v->student_id] = $v->school_student_card;
  4352. }
  4353. }
  4354. if(!$student_cards)
  4355. {
  4356. echo json_encode(array('status'=>0));exit;
  4357. }
  4358. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4359. if($exam_data)
  4360. {
  4361. $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId));
  4362. if($class_data)
  4363. {
  4364. $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade));
  4365. }
  4366. $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  4367. if($group_exam_data)
  4368. {
  4369. foreach($group_exam_data as $v)
  4370. {
  4371. $exam_ids[$v->exam_id] = $v->exam_id;
  4372. }
  4373. $student_paper_data = $this->schoolManager->getStudentsByStudentIdsAndExam_ids(implode(',',$exam_ids),$studentsIds);
  4374. if($student_paper_data)
  4375. {
  4376. foreach($student_paper_data as $v)
  4377. {
  4378. $student_ids[$v['student_id']] = $v['student_id'];
  4379. }
  4380. $criteria = new CDbCriteria();
  4381. $criteria->addInCondition('student_id',$student_ids);
  4382. $student_data = SStudentInfo::model()->findAll($criteria);
  4383. unset($criteria);
  4384. if($student_data)
  4385. {
  4386. foreach ($student_data as $v)
  4387. {
  4388. $student_names[$v->student_id] = $v->realname;
  4389. }
  4390. }
  4391. echo json_encode(array('status'=>3,'result'=>implode(',',$student_names)));exit;
  4392. }
  4393. }
  4394. }
  4395. if($this->schoolManager->addAndUpdateStudentPaper($class_id,$student_array,$exam_id,$this->semesterId,$paper_id,$student_cards,$school_student_cards))
  4396. {
  4397. //发送学生端消息
  4398. $sendJsonArr=array(
  4399. 'school_id'=>$this->schoolId,
  4400. 'send_type'=>'zsyas',
  4401. 'update_type'=>1,
  4402. 'exam_group_id'=>$exam_data->exam_group_id,
  4403. 'exam_id_arr'=>array($exam_id),
  4404. 'student_id_arr'=>$studentsIds
  4405. );
  4406. sendStudentCacheQueue($sendJsonArr);
  4407. echo json_encode(array('status'=>1));exit;
  4408. };
  4409. echo json_encode(array('status'=>0));exit;
  4410. }
  4411. public function actionSetExamStudentCard()
  4412. {
  4413. $exam_id = Req::post('exam_id');
  4414. $school_card_status = Req::post('school_card_status');
  4415. $school_card_length = 8;
  4416. if($this->schoolId>999){
  4417. $school_card_length = 9;
  4418. }
  4419. $exam_ids = array();
  4420. if(!$exam_id)
  4421. {
  4422. echo json_encode(array('status'=>0));exit;
  4423. }
  4424. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4425. if($exam_data)
  4426. {
  4427. $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId));
  4428. if($class_data)
  4429. {
  4430. $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade));
  4431. }
  4432. $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  4433. if($group_exam_data && $grade_data)
  4434. {
  4435. foreach($group_exam_data as $v)
  4436. {
  4437. $exam_ids[$v->exam_id] = $v->exam_id;
  4438. }
  4439. if($school_card_status==1)
  4440. {
  4441. $school_card_length = $grade_data->card_length;
  4442. }
  4443. $criteria = new CDbCriteria();
  4444. $criteria->addInCondition('exam_id',$exam_ids);
  4445. if(false!==Exam::model()->updateAll(array('school_card_status'=>$school_card_status,'school_card_length'=>$school_card_length),$criteria))
  4446. {
  4447. echo json_encode(array('status'=>1));exit;
  4448. }
  4449. }
  4450. }
  4451. echo json_encode(array('status'=>0));exit;
  4452. }
  4453. public function actionDelexam()
  4454. {
  4455. $exam_id = Req::post('examId');
  4456. $class_id = Req::post('classId');
  4457. $is_third = Req::post('is_third');
  4458. $student_ids = array();
  4459. $exam_id_array = array();
  4460. if(!$exam_id || !$class_id)
  4461. {
  4462. echo json_encode(array('status'=>0));exit;
  4463. }
  4464. if($is_third){
  4465. $exam_data = $this->schoolManager->ExamStatusAndUploadStatusArr($exam_id, array(2,3),0);
  4466. }else {
  4467. $exam_data = $this->schoolManager->ExamStatusAndUploadStatus($exam_id, 3, 0);
  4468. }
  4469. if($exam_data)
  4470. {
  4471. $examGroupId = $exam_data['exam_group_id'];
  4472. $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
  4473. if($examIds)
  4474. {
  4475. $exams_data = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = 2"));
  4476. if($exams_data){
  4477. foreach($exams_data as $v)
  4478. {
  4479. $exam_id_array[$v['exam_id']] = $v['exam_id'];
  4480. }
  4481. }
  4482. $all_num = count($examIds);
  4483. $finish_num = count($exams_data);
  4484. if(($all_num-$finish_num) == 1 && !isset($exam_id_array[$exam_id]))
  4485. {
  4486. SExamGroup::model()->updateAll(array('upload_status'=>2,'mark_status'=>2),'exam_group_id = :examGroupId', array(
  4487. ':examGroupId' => $examGroupId
  4488. ));
  4489. }
  4490. }
  4491. $transaction = $this->sConn->beginTransaction();
  4492. try{
  4493. Exam::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)) ;
  4494. $paper_list = $this->sConn->createCommand("select paper_id from paper where exam_id='" . $exam_id . "'")->queryAll();
  4495. foreach ($paper_list as $paper){
  4496. SPaperTopicRelation::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
  4497. SPaperTopicLarge::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
  4498. STopicUse::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
  4499. }
  4500. SPaper::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4501. $studentIds=array();
  4502. $student_paper_relation_list = SStudentPaperRelation::model()->findAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4503. $studentIds=array();
  4504. foreach ($student_paper_relation_list as $student_paper_relation){
  4505. $studentIds[]=$student_paper_relation->student_id;
  4506. }
  4507. SStudentPaperRelation::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4508. SStudentPaperRelationProperty::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4509. SClassExamPrinter::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4510. SMarkingGroupModel::model()->deleteAll('class_id=:class_id and exam_group_id=:exam_group_id',array(':class_id'=>$class_id,'exam_group_id'=>$examGroupId));
  4511. //发送学生端消息
  4512. $sendJsonArr=array(
  4513. 'school_id'=>$this->schoolId,
  4514. 'send_type'=>'zsyas',
  4515. 'update_type'=>4,
  4516. 'exam_group_id'=>$examGroupId,
  4517. 'exam_id_arr'=>array($exam_id),
  4518. 'student_id_arr'=>$studentIds
  4519. );
  4520. sendStudentCacheQueue($sendJsonArr);
  4521. $transaction->commit();
  4522. }catch(Exception $e){
  4523. $transaction->rollBack();
  4524. echo json_encode(array('status'=>0));exit;
  4525. }
  4526. //操作日志
  4527. if(Yii::app()->params['handle_log_on_off'])
  4528. {
  4529. writeFileLog(jsonEncode(array(
  4530. "exam_group_id" => (string)$exam_data['exam_group_id'],
  4531. "operate_project" => 'zsyas2',
  4532. "school_id" => $this->schoolId,
  4533. "title" => '删除考试班级',
  4534. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4535. "operate_method" => $this->action,
  4536. "operate_url" => $this->getRoute(),
  4537. "operate_sql" => json_encode(array('update'=>array(
  4538. 'ExamGroup'=>array('upload_status'=>1),
  4539. ),
  4540. array('delete'=>array(
  4541. 'Exam'=>array('exam_id'=>$exam_id),
  4542. 'paper'=>array('exam_id'=>$exam_id),
  4543. 'student_paper_relation'=>array('exam_id'=>$exam_id),
  4544. ))
  4545. )),
  4546. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4547. "date"=>date('Y-m-d H:i:s')
  4548. )));
  4549. }
  4550. echo json_encode(array('status'=>1));exit;
  4551. }
  4552. echo json_encode(array('status'=>0));exit;
  4553. }
  4554. public function actionRestore()
  4555. {
  4556. $examName=Req::get('exam_name');
  4557. $page=intval(Req::get('page'));
  4558. $pageLimit=10;
  4559. if(!$page) $page=1;
  4560. $examRestore=new SExamRestore();
  4561. $result=$examRestore->getList($examName,$page,$pageLimit);
  4562. $viewData=array(
  4563. 'pageTotal' =>$result['pageTotal'],
  4564. 'dataList' =>$result['data'],
  4565. 'page' =>$page,
  4566. 'totalCount' =>$result['totalCount'],
  4567. 'examName' =>$examName
  4568. );
  4569. $this->render('restore',$viewData);
  4570. }
  4571. public function actionRestoreExam()
  4572. {
  4573. $exam_group_id = Req::post('examId');
  4574. $exam_ids = array();
  4575. $paper_ids = array();
  4576. $result=array();
  4577. $result['status']=0;
  4578. if($exam_group_id>0)
  4579. {
  4580. $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4581. if($exam_data)
  4582. {
  4583. foreach($exam_data as $v)
  4584. {
  4585. $exam_ids[$v->exam_id] = $v->exam_id;
  4586. }
  4587. if($exam_ids)
  4588. {
  4589. $criteria = new CDbCriteria();
  4590. $criteria->addInCondition('exam_id',$exam_ids);
  4591. $paper_data = SPaper::model()->findAll($criteria);
  4592. unset($criteria);
  4593. if($paper_data)
  4594. {
  4595. foreach($paper_data as $v)
  4596. {
  4597. $paper_ids[$v->paper_id] = $v->paper_id;
  4598. }
  4599. }
  4600. }
  4601. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4602. if($exam_group_data)
  4603. {
  4604. $examStatus=3;
  4605. if($exam_group_data->is_third==1){
  4606. $examStatus=2;
  4607. }
  4608. if($exam_group_data->mark_type>0)
  4609. {
  4610. $transaction = $this->sConn->beginTransaction();
  4611. try{
  4612. $criteria = new CDbCriteria();
  4613. $criteria->addInCondition('exam_id',$exam_ids);
  4614. $flags=SStudentPaperRelation::model()->updateAll(array(
  4615. 'complete_count'=>0,
  4616. 'right_count'=>0,
  4617. 'partial_right_count'=>0,
  4618. 'wrong_count'=>0,
  4619. 'scoring'=>0.0,
  4620. 'lost_score'=>0.0,
  4621. 'compare'=>0.0000,
  4622. 'report_created'=>0,
  4623. 'report_data'=>'',
  4624. 'is_feedback'=>0,
  4625. 'feedback_time'=>0,
  4626. 'is_scoring'=>0,
  4627. 'scoring_img'=>'',
  4628. 'is_isp_html'=>0,
  4629. 'isp_html_path'=>'',
  4630. 'isp_html_time'=>0,
  4631. 'is_wrongbook_html'=>0,
  4632. 'wrongbook_html_path'=>'',
  4633. 'wrongbook_html_time'=>0,
  4634. 'is_isp_pdf'=>0,
  4635. 'isp_pdf_path'=>'',
  4636. 'isp_pdf_time'=>0,
  4637. 'is_wrongbook_pdf'=>0,
  4638. 'wrongbook_pdf_path'=>'',
  4639. 'wrongbook_pdf_time'=>0,
  4640. 'file_src'=>'',
  4641. 'is_wbisp_html'=>0,
  4642. 'is_wbisp_pdf'=>0,
  4643. 'wbisp_html_path'=>'',
  4644. 'wbisp_pdf_path'=>'',
  4645. 'wbisp_html_time'=>0,
  4646. 'wbisp_pdf_time'=>0,
  4647. 'is_studytrend_img'=>0,
  4648. 'studytrend_img_path'=>'',
  4649. 'is_complete'=>0,
  4650. 'complete_time'=>0,
  4651. 'is_plan_created'=>0,
  4652. 'plan_id'=>NULL,
  4653. 'plan_topic_time'=>0,
  4654. 'studytrend_exam_name'=>'',
  4655. 'wb_page_num'=>0,
  4656. 'isp_page_num'=>0,
  4657. 'is_assigned'=>0,
  4658. 'is_three_isp_download'=>0,
  4659. 'is_two_isp_download'=>0,
  4660. 'is_wrongbook_download'=>0,
  4661. 'studytrend_img_time'=>0,
  4662. 'download_three_isp_time'=>0,
  4663. 'download_two_isp_time'=>0,
  4664. 'download_wrongbook_time'=>0,
  4665. 'is_wrong_plan_created'=>0,
  4666. 'wrong_plan_topic_time'=>0,
  4667. 'wrong_plan_id'=>null,
  4668. 'wbisp_page_num'=>0
  4669. ),$criteria);
  4670. unset($criteria);
  4671. //del paper_topic_rs
  4672. $criteria = new CDbCriteria();
  4673. $criteria->addInCondition('paper_id',$paper_ids);
  4674. SStudentPaperTopicRs::model()->deleteAll($criteria);
  4675. unset($criteria);
  4676. //del marking
  4677. if($exam_group_data->mark_type!=4)
  4678. {
  4679. SMarkingGroupModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4680. SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4681. SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4682. SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4683. //SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id));
  4684. SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4685. //update exam
  4686. $criteria = new CDbCriteria();
  4687. $criteria->addInCondition('exam_id',$exam_ids);
  4688. Exam::model()->updateAll(array(
  4689. 'status'=>$examStatus,
  4690. 'upload_status'=>0,
  4691. 'is_topwb_html'=>0,
  4692. 'is_topwb_pdf'=>0,
  4693. 'is_academicr_html'=>0,
  4694. ),$criteria);
  4695. unset($criteria);
  4696. //update exam_group
  4697. ExamGroup::model()->updateAll(array(
  4698. 'mark_status'=>0,
  4699. 'upload_status'=>0,
  4700. 'init_time'=>0,
  4701. 'status'=>1,
  4702. 'score_bar'=>'',
  4703. 'is_marking_stop'=>0,
  4704. ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4705. }else
  4706. {
  4707. SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4708. SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4709. // SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id));
  4710. SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4711. SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4712. //update exam
  4713. $criteria = new CDbCriteria();
  4714. $criteria->addInCondition('exam_id',$exam_ids);
  4715. Exam::model()->updateAll(array(
  4716. 'status'=>$examStatus,
  4717. 'upload_status'=>0,
  4718. 'is_topwb_html'=>0,
  4719. 'is_topwb_pdf'=>0,
  4720. 'is_academicr_html'=>0,
  4721. ),$criteria);
  4722. unset($criteria);
  4723. //update exam_group
  4724. ExamGroup::model()->updateAll(array(
  4725. 'mark_status'=>1,
  4726. 'upload_status'=>0,
  4727. 'score_bar'=>'',
  4728. 'status'=>1,
  4729. 'is_marking_stop'=>0,
  4730. ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4731. }
  4732. $this->sConn->createCommand("delete from exam_product_status where exam_id in(".implode(',',$exam_ids).")")->execute();
  4733. $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute();
  4734. $rs = http('/qxk/marking/exam/reset/'.$exam_group_id,'PUT',$this->schoolId,array(),'cgi');
  4735. $rs=json_decode($rs,true);
  4736. if(isset($rs['errCode']) && $rs['errCode']=='00'){
  4737. //sendDataToKafka('xbkc-marking-reback-exam',array('examGroupId'=>$exam_group_id,'schoolId'=>$this->schoolId));
  4738. $transaction->commit();
  4739. }else{
  4740. throw new Exception($rs['errMsg']);
  4741. }
  4742. }catch(Exception $e){
  4743. $transaction->rollBack();
  4744. //操作日志
  4745. if(Yii::app()->params['handle_log_on_off'])
  4746. {
  4747. writeFileLog(jsonEncode(array(
  4748. "exam_group_id" => (string)$exam_group_id,
  4749. "operate_project" => 'zsyas2',
  4750. "school_id" => $this->schoolId,
  4751. "title" => '还原考试失败',
  4752. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4753. "operate_method" => $this->action,
  4754. "operate_url" => $this->getRoute(),
  4755. "operate_sql" =>'',
  4756. "error"=>$e->getMessage(),
  4757. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4758. "date"=>date('Y-m-d H:i:s')
  4759. )));
  4760. }
  4761. $result['msg']="还原失败";
  4762. exit(json_encode($result));
  4763. }
  4764. //操作日志
  4765. if(Yii::app()->params['handle_log_on_off'])
  4766. {
  4767. writeFileLog(jsonEncode(array(
  4768. "exam_group_id" => (string)$exam_group_id,
  4769. "operate_project" => 'zsyas2',
  4770. "school_id" => $this->schoolId,
  4771. "title" => '还原考试',
  4772. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4773. "operate_method" => $this->action,
  4774. "operate_url" => $this->getRoute(),
  4775. "operate_sql" =>'',
  4776. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4777. "date"=>date('Y-m-d H:i:s')
  4778. )));
  4779. }
  4780. $result['status']=1;
  4781. $result['msg']="还原成功";
  4782. exit(json_encode($result));
  4783. }else
  4784. {
  4785. //线下阅卷
  4786. $transaction = $this->sConn->beginTransaction();
  4787. try{
  4788. $criteria = new CDbCriteria();
  4789. $criteria->addInCondition('exam_id',$exam_ids);
  4790. $flags=SStudentPaperRelation::model()->updateAll(array(
  4791. 'complete_count'=>0,
  4792. 'right_count'=>0,
  4793. 'partial_right_count'=>0,
  4794. 'wrong_count'=>0,
  4795. 'scoring'=>0.0,
  4796. 'lost_score'=>0.0,
  4797. 'compare'=>0.0000,
  4798. 'report_created'=>0,
  4799. 'report_data'=>'',
  4800. 'is_feedback'=>0,
  4801. 'feedback_time'=>0,
  4802. 'is_scoring'=>0,
  4803. 'scoring_img'=>'',
  4804. 'is_isp_html'=>0,
  4805. 'isp_html_path'=>'',
  4806. 'isp_html_time'=>0,
  4807. 'is_wrongbook_html'=>0,
  4808. 'wrongbook_html_path'=>'',
  4809. 'wrongbook_html_time'=>0,
  4810. 'is_isp_pdf'=>0,
  4811. 'isp_pdf_path'=>'',
  4812. 'isp_pdf_time'=>0,
  4813. 'is_wrongbook_pdf'=>0,
  4814. 'wrongbook_pdf_path'=>'',
  4815. 'wrongbook_pdf_time'=>0,
  4816. 'file_src'=>'',
  4817. 'is_wbisp_html'=>0,
  4818. 'is_wbisp_pdf'=>0,
  4819. 'wbisp_html_path'=>'',
  4820. 'wbisp_pdf_path'=>'',
  4821. 'wbisp_html_time'=>0,
  4822. 'wbisp_pdf_time'=>0,
  4823. 'is_studytrend_img'=>0,
  4824. 'studytrend_img_path'=>'',
  4825. 'is_complete'=>0,
  4826. 'complete_time'=>0,
  4827. 'is_plan_created'=>0,
  4828. 'plan_id'=>NULL,
  4829. 'plan_topic_time'=>0,
  4830. 'studytrend_exam_name'=>'',
  4831. 'wb_page_num'=>0,
  4832. 'isp_page_num'=>0,
  4833. 'wbisp_page_num'=>0
  4834. ),$criteria);
  4835. unset($criteria);
  4836. //del paper_topic_rs
  4837. $criteria = new CDbCriteria();
  4838. $criteria->addInCondition('paper_id',$paper_ids);
  4839. SStudentPaperTopicRs::model()->deleteAll($criteria);
  4840. unset($criteria);
  4841. //update exam
  4842. $criteria = new CDbCriteria();
  4843. $criteria->addInCondition('exam_id',$exam_ids);
  4844. Exam::model()->updateAll(array(
  4845. 'status'=>$examStatus,
  4846. 'upload_status'=>0,
  4847. 'is_topwb_html'=>0,
  4848. 'is_topwb_pdf'=>0,
  4849. 'is_academicr_html'=>0,
  4850. ),$criteria);
  4851. unset($criteria);
  4852. //update exam_group
  4853. ExamGroup::model()->updateAll(array(
  4854. 'mark_status'=>0,
  4855. 'upload_status'=>0,
  4856. 'init_time'=>0,
  4857. 'score_bar'=>'',
  4858. 'status'=>1
  4859. ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  4860. $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute();
  4861. $transaction->commit();
  4862. }catch(Exception $e)
  4863. {
  4864. $transaction->rollBack();
  4865. $result['msg']="还原失败";
  4866. //操作日志
  4867. if(Yii::app()->params['handle_log_on_off'])
  4868. {
  4869. writeFileLog(jsonEncode(array(
  4870. "exam_group_id" => (string)$exam_group_id,
  4871. "operate_project" => 'zsyas2',
  4872. "school_id" => $this->schoolId,
  4873. "title" => '还原考试失败',
  4874. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4875. "operate_method" => $this->action,
  4876. "operate_url" => $this->getRoute(),
  4877. "operate_sql" =>'',
  4878. "error"=>$e->getMessage(),
  4879. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4880. "date"=>date('Y-m-d H:i:s')
  4881. )));
  4882. }
  4883. exit(json_encode($result));
  4884. }
  4885. //操作日志
  4886. if(Yii::app()->params['handle_log_on_off'])
  4887. {
  4888. writeFileLog(jsonEncode(array(
  4889. "exam_group_id" => (string)$exam_group_id,
  4890. "operate_project" => 'zsyas2',
  4891. "school_id" => $this->schoolId,
  4892. "title" => '还原考试',
  4893. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  4894. "operate_method" => $this->action,
  4895. "operate_url" => $this->getRoute(),
  4896. "operate_sql" =>'',
  4897. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  4898. "date"=>date('Y-m-d H:i:j')
  4899. )));
  4900. }
  4901. $result['status']=1;
  4902. $result['msg']="还原成功";
  4903. exit(json_encode($result));
  4904. }
  4905. }
  4906. }
  4907. }
  4908. $result['msg']="考试参数异常";
  4909. exit(json_encode($result));
  4910. }
  4911. public function actionSetSubjectId()
  4912. {
  4913. $subjectId = Req::post("subjectId");
  4914. if($subjectId)
  4915. {
  4916. Yii::app()->session['session_subject_id'] = $subjectId;
  4917. Yii::app()->session['session_duoxueke_subject_id'] = $subjectId;
  4918. // $this->subjectId = $subjectId;
  4919. echo 1;exit;
  4920. }else
  4921. {
  4922. echo 0;exit;
  4923. }
  4924. }
  4925. public function actionSend_ruanyun_pdf()
  4926. {
  4927. $exam_id = Req::post('examId');
  4928. $paper_id = '';
  4929. $student_ids = array();
  4930. $class_id = '';
  4931. $data = array();
  4932. $topic_ids = array();
  4933. $topic_score = array();
  4934. $topic_QuestionId = array();
  4935. if($exam_id)
  4936. {
  4937. $student_paper_relations = SStudentPaperRelation::model()->findAll('exam_id=:exam_id and is_del=:is_del',array(':exam_id'=>$exam_id,':is_del'=>0));
  4938. if($student_paper_relations)
  4939. {
  4940. foreach($student_paper_relations as $v)
  4941. {
  4942. $paper_id = $v->paper_id;
  4943. $student_ids[$v->student_id] = $v->student_id;
  4944. $class_id = $v->class_id;
  4945. }
  4946. }
  4947. $school_data = BusinessSchool::model()->find('school_id = :school_id',array(':school_id'=> $this->schoolId));
  4948. if($school_data)
  4949. {
  4950. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  4951. if($class_data)
  4952. {
  4953. $criteria = new CDbCriteria();
  4954. $criteria->addInCondition('student_id',$student_ids);
  4955. $students = SStudentInfo::model()->findAll($criteria);
  4956. if($students)
  4957. {
  4958. foreach($students as $k=>$v)
  4959. {
  4960. $data['Students'][$k]['StudentNo'] = $v->student_id;
  4961. $data['Students'][$k]['StudentName'] = $v->realname;
  4962. $data['Students'][$k]['SchoolName'] = $school_data->school_name;
  4963. $data['Students'][$k]['GradeName'] = "";
  4964. $data['Students'][$k]['ClassName'] = $class_data->class_name;
  4965. if($class_data->grade==1)
  4966. {
  4967. $data['Students'][$k]['GradeName'] = "高一";
  4968. }
  4969. if($class_data->grade==2)
  4970. {
  4971. $data['Students'][$k]['GradeName'] = "高二";
  4972. }
  4973. if($class_data->grade==3)
  4974. {
  4975. $data['Students'][$k]['GradeName'] = "高三";
  4976. }
  4977. $data['Students'][$k]['ExternalInfo'] = json_encode(array('exam_id'=>$exam_id,'school_id'=>$this->schoolId));
  4978. }
  4979. }
  4980. }
  4981. }
  4982. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  4983. if($exam_data)
  4984. {
  4985. $data['StudentExam']['ExamName'] = $exam_data->name;
  4986. $data['StudentExam']['ExamTypeId'] = 4;
  4987. $data['StudentExam']['CourseId'] = $exam_data->subject_id;
  4988. $data['StudentExam']['RegionId'] = 0;
  4989. }
  4990. $paper_topic_relation = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  4991. if($paper_topic_relation)
  4992. {
  4993. foreach($paper_topic_relation as $v)
  4994. {
  4995. $topic_ids[$v->topic_id] = $v->topic_id;
  4996. $topic_score[$v->topic_id] = $v->score;
  4997. }
  4998. unset($criteria);
  4999. $criteria = new CDbCriteria();
  5000. $criteria->addInCondition('topic_id',$topic_ids);
  5001. $question_ids = SRuanyunTopicRelation::model()->findAll($criteria);
  5002. if($question_ids)
  5003. {
  5004. foreach($question_ids as $k=>$v)
  5005. {
  5006. $topic_QuestionId[$v->topic_id] = $v->question_id;
  5007. $data['ExamQuestions'][$k]['QuestionId'] = $v->question_id;
  5008. $data['ExamQuestions'][$k]['FullScore'] = (double)0;
  5009. if(isset($topic_score[$v->topic_id]))
  5010. {
  5011. $data['ExamQuestions'][$k]['FullScore'] = (double)$topic_score[$v->topic_id];
  5012. }
  5013. }
  5014. }
  5015. unset($criteria);
  5016. $criteria = new CDbCriteria();
  5017. $criteria->addCondition('paper_id=:paper_id');
  5018. $criteria->addInCondition('student_id',$student_ids);
  5019. $criteria->params[':paper_id'] = $paper_id;
  5020. $student_paper_rs = SStudentPaperTopicRs::model()->findAll($criteria);
  5021. if($student_paper_rs)
  5022. {
  5023. foreach($student_paper_rs as $k=>$v)
  5024. {
  5025. $data['ExamResults'][$k]['StudentNo'] = $v->student_id;
  5026. $data['ExamResults'][$k]['QuestionId'] = 0;
  5027. if(isset($topic_QuestionId[$v->topic_id]))
  5028. {
  5029. $data['ExamResults'][$k]['QuestionId'] = $topic_QuestionId[$v->topic_id];
  5030. }
  5031. $data['ExamResults'][$k]['Score'] = (double)$v->scoring;
  5032. }
  5033. //调接口
  5034. $upload_log = new BusinessUploadLog();
  5035. $upload_log->school_id = $this->schoolId;
  5036. $upload_log->file_zip_path = Yii::app()->params['ruanyun_exam_interface'];
  5037. $upload_log->message = json_encode($data);
  5038. $upload_log->create_time = time();
  5039. $upload_log->save();
  5040. $RequestResult = Curl::http_post_gzip_json(Yii::app()->params['ruanyun_exam_interface'],json_encode($data));
  5041. $upload_log = new BusinessUploadLog();
  5042. $upload_log->school_id = $this->schoolId;
  5043. $upload_log->file_zip_path ='result';
  5044. $upload_log->message = $RequestResult;
  5045. $upload_log->create_time = time();
  5046. $upload_log->save();
  5047. if($RequestResult)
  5048. {
  5049. $RequestResult_data = json_decode($RequestResult,1);
  5050. if(isset($RequestResult_data['ResultTypeId']) && $RequestResult_data['ResultTypeId']==1)
  5051. {
  5052. echo json_encode(array('status'=>1));exit;
  5053. }else
  5054. {
  5055. echo json_encode(array('status'=>0));exit;
  5056. }
  5057. }else
  5058. {
  5059. echo json_encode(array('status'=>0));exit;
  5060. }
  5061. }else
  5062. {
  5063. echo json_encode(array('status'=>2));exit;
  5064. }
  5065. }
  5066. }
  5067. echo json_encode(array('status'=>0));exit;
  5068. }
  5069. public function actionDo_ruanyun_pdf()
  5070. {
  5071. $condition = array();
  5072. $printList = array();
  5073. $condition[] = "cep.type = 0";
  5074. $condition[] = "e.is_display = '0'";
  5075. $condition[] = "eg.is_third = '0'";
  5076. $condition[] = "e.subject_id = '{$this->subjectId}'";
  5077. $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc','e.exam_id desc'));
  5078. if($resultList["rs"]){
  5079. foreach ($resultList['rs'] as $k=>$v) {
  5080. $printList[$k] = $v;
  5081. if ($v["type"] == 1) {
  5082. $printList[$k]['print_name']= $v["exam_name"].'"错题本"';
  5083. }
  5084. elseif ($v["type"] == 2) {
  5085. $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"';
  5086. }
  5087. elseif ($v["type"] == 3) {
  5088. $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
  5089. }
  5090. else {
  5091. $printList[$k]['print_name']= $v["exam_name"];
  5092. }
  5093. $printList[$k]['is_tpl'] = 0; // 需要上传模板
  5094. $printList[$k]['answer_card_uploaded'] = false;
  5095. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  5096. //自定义模板
  5097. $printList[$k]['is_custom_tpl'] = true;
  5098. $v['is_custom_tpl'] = true;
  5099. }else{
  5100. //非自定义模板
  5101. $printList[$k]['is_custom_tpl'] = false;
  5102. $v['is_custom_tpl'] = false;
  5103. }
  5104. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  5105. $printList[$k]['is_tpl'] = 1;
  5106. if(trim($printList[$k]['answer_card_src'])){
  5107. $printList[$k]['answer_card_uploaded'] = true;
  5108. }
  5109. //题卡分离
  5110. $printList[$k]['paper_tpl_type'] = 2;
  5111. }else{
  5112. $printList[$k]['paper_tpl_type'] = 1;
  5113. }
  5114. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  5115. {
  5116. $printList[$k]['paper_tpl_type'] = 3;
  5117. if($v['tpl_index'] == 9 )
  5118. {
  5119. $printList[$k]['paper_tpl_type'] = 4;
  5120. }
  5121. }
  5122. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  5123. {
  5124. $printList[$k]['paper_tpl_type'] = 3;
  5125. if($v['tpl_index'] == 9 )
  5126. {
  5127. $printList[$k]['paper_tpl_type'] = 4;
  5128. }
  5129. }
  5130. //题卡合一
  5131. }
  5132. }
  5133. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  5134. $data = array();
  5135. $data['printList'] = $printList;
  5136. $data['pages'] = $resultList['pager'];
  5137. $data['page_total'] = $resultList['pager']->rowsCount;
  5138. $data["subject"] = $subject_exam_data;
  5139. unset($resultList);
  5140. $this->render('do_ruanyun_pdf',$data);
  5141. }
  5142. public function actionRuanyun_change()
  5143. {
  5144. $sname = Req::get("sname");
  5145. $cid = Req::get("cid");
  5146. $eid = Req::get("eid");
  5147. $studentNames = array();
  5148. $classInfo = ClassModel::model()->findByPk($cid);
  5149. if (empty($classInfo)) {
  5150. Yii::app()->jump->error('未找到班级!');
  5151. }
  5152. $examInfo = Exam::model()->findByPk($eid);
  5153. if (empty($examInfo)) {
  5154. Yii::app()->jump->error('未找到周周练!');
  5155. }
  5156. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid',array(':cid'=>$cid,':eid'=>$eid));
  5157. if (empty($getResult)) {
  5158. Yii::app()->jump->error('未找到班级与试卷对应关系!');
  5159. }
  5160. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  5161. if (empty($paperInfo)) {
  5162. Yii::app()->jump->error('未找到试卷信息!');
  5163. }
  5164. //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  5165. $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
  5166. if (empty($relateStudent))
  5167. {
  5168. Yii::app()->jump->error('未找到考试学生信息!');
  5169. } else {
  5170. $studentIdArray = array();
  5171. $wrongStatus = array();
  5172. $studentArrayTwo = array();
  5173. $studentScoring = array();
  5174. $_wrongStudentIds = array();
  5175. $student_name = array();
  5176. // 获取当前考试所有学生ID
  5177. foreach ($relateStudent as $key=>$val) {
  5178. $studentIdArray[] = $val->student_id;
  5179. $wrongStatus[$val->student_id] = $val->is_wbisp_pdf;
  5180. $wrongStudentIds[$val->student_id] = $val->student_id;
  5181. $_wrongStudentIds[$val->student_id] = $val->student_id;
  5182. $studentScoring[$val->student_id] = $val->scoring;
  5183. }
  5184. $wrongStudents = $wrongTopicIds = $wrongAnswers =array();
  5185. // 获取学生的错题
  5186. }
  5187. $result = array();
  5188. if (!empty($wrongStudentIds)) {
  5189. // 获取有错题的学生姓名
  5190. $studentNames = SStudentInfo::model()->getStudentNames($wrongStudentIds);
  5191. }
  5192. $data = array();
  5193. $data['exam_id'] = $eid;
  5194. $data['examName'] = $examInfo["name"];
  5195. $data['class_id'] = $cid;
  5196. $data['sname'] = $sname;
  5197. $data['examInfo'] = $examInfo;
  5198. $data['student_names'] = $studentNames;
  5199. $data['result'] = $relateStudent;
  5200. $this->render('ruanyun_change',$data);
  5201. }
  5202. public function actionUpdatepaperdowntime()
  5203. {
  5204. $student_id = Req::post('student_id');
  5205. $exam_id = Req::post('exam_id');
  5206. if($student_id && $exam_id)
  5207. {
  5208. $student_paper_relation = SStudentPaperRelation::model()->find('student_id = :student_id and exam_id=:exam_id and is_isp_pdf=:is_isp_pdf',array(':student_id'=>$student_id,':exam_id'=>$exam_id,':is_isp_pdf'=>1));
  5209. if($student_paper_relation)
  5210. {
  5211. SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),'student_id= :student_id and exam_id=:exam_id',array(':student_id'=>$student_id,':exam_id'=>$exam_id));
  5212. }
  5213. }
  5214. }
  5215. public function actionStudent_product()
  5216. {
  5217. //当前学期所有班级
  5218. $grade = Req::get('grade');
  5219. $class_id = Req::get('class_id');
  5220. $ptype = Req::get('ptype'); //类型,期中,期末,总复习
  5221. $season = Req::get('season'); //季节
  5222. $class_name = '';
  5223. $pageLimit=4;
  5224. if($season){
  5225. $pageLimit=$pageLimit*2;
  5226. }
  5227. if($ptype){
  5228. $pageLimit=$pageLimit*3;
  5229. }
  5230. $criteria = new CDbCriteria();
  5231. if($class_id)
  5232. {
  5233. $criteria->addCondition('class_id=:class_id');
  5234. $criteria->params[':class_id'] = $class_id;
  5235. }
  5236. $criteria->addCondition('semester_id=:semester_id');
  5237. $criteria->params[':semester_id'] = $this->semesterId;
  5238. if($grade)
  5239. {
  5240. $criteria->addCondition('grade=:grade');
  5241. $criteria->params[':grade'] = $grade;
  5242. }
  5243. $criteria->order = 'grade asc,class_id asc';
  5244. $count = ClassModel::model()->count($criteria);
  5245. $pager = new CPagination($count,$pageLimit);
  5246. $criteria->limit=$pager->getLimit();
  5247. $criteria->offset=$pager->getOffset();
  5248. $class_data = ClassModel::model()->findAll($criteria);
  5249. if(!$class_data)
  5250. {
  5251. Yii::app()->jump->error('未找到班级!');
  5252. }
  5253. $data = array();
  5254. $class_names = array();
  5255. $class_ids = array();
  5256. $class_student_ids = array();
  5257. $class_down = array();
  5258. $class_create = array();
  5259. foreach($class_data as $v)
  5260. {
  5261. if($v->class_id == $class_id)
  5262. {
  5263. $class_name = $v->class_name;
  5264. }
  5265. $class_names[$v->class_id] = $v->class_name;
  5266. $class_ids[$v->class_id] = $v->class_id;
  5267. }
  5268. unset($criteria);
  5269. $criteria = new CDbCriteria();
  5270. $criteria->addInCondition('class_id',$class_ids);
  5271. $criteria->addCondition('status=:status');
  5272. $criteria->params[':status'] = 0;
  5273. $student_data = SStudentClassRelation::model()->findAll($criteria);
  5274. if($student_data)
  5275. {
  5276. foreach($student_data as $v)
  5277. {
  5278. $class_student_ids[$v->class_id][$v->student_id] = $v->student_id;
  5279. }
  5280. }
  5281. //debug($class_data);
  5282. /*** 优化后 *****/
  5283. $_class_ids = array();
  5284. if($class_student_ids){
  5285. $_class_ids = array_keys($class_student_ids);
  5286. }
  5287. // 多学科切换条件
  5288. if(in_array($this->subjectId,$this->mathSubjectId)){
  5289. $subjectId=3;
  5290. }else{
  5291. $subjectId=$this->subjectId;
  5292. }
  5293. list($student_product_data,$student_down_product_data,$class_bt) = $this->schoolManager->getStudentProduct($_class_ids,$subjectId);
  5294. /*** 优化后 *****/
  5295. /*** 优化前 *****/
  5296. // $student_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_pdf_created = 1'));
  5297. // $student_down_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_download = 1'));
  5298. /*** 优化前 *****/
  5299. if($student_down_product_data)
  5300. {
  5301. foreach($student_down_product_data as $v)
  5302. {
  5303. $class_down[$v['class_id']][$v['product_type']] = $v;
  5304. }
  5305. }
  5306. if($student_product_data)
  5307. {
  5308. foreach($student_product_data as $v)
  5309. {
  5310. $class_create[$v['class_id']][$v['product_type']] = $v;
  5311. }
  5312. }
  5313. unset($criteria);
  5314. $criteria = new CDbCriteria();
  5315. if($grade)
  5316. {
  5317. $criteria->addCondition('grade=:grade');
  5318. $criteria->params[':grade'] = $grade;
  5319. }
  5320. $criteria->addCondition('semester_id=:semester_id');
  5321. $criteria->params[':semester_id'] = $this->semesterId;
  5322. $class_all = ClassModel::model()->findAll($criteria);
  5323. //阶段个性化学习宝生成状态
  5324. //category 1--春季期中个性化学习宝(2.1~4.30) 2--春季期末个性化学习宝(5.1~7.31) 3--春季总复习个性化学习宝(2.1~7.31) 4--秋季期中个性化学习宝(9.1~11.30) 5--秋季期末个性化学习宝(12.1~1.31) 6--秋季总复习个性化学习宝(9.1~1.31)
  5325. $review_isp = array(
  5326. array(
  5327. 'product_name' => '期中复习学习宝',
  5328. 'season_arr'=>array(
  5329. array(
  5330. 'category_id' => 1,
  5331. 'is_send' => 0,
  5332. 'status' => 0,
  5333. 'category_name' => '春季(根据2-4月的考试数据生成)',
  5334. ),
  5335. array(
  5336. 'category_id' => 4,
  5337. 'is_send' => 0,
  5338. 'status' => 0,
  5339. 'category_name' => '秋季(根据9-11月的考试数据生成)',
  5340. ),
  5341. ),
  5342. ),
  5343. array(
  5344. 'product_name' => '期末复习学习宝',
  5345. 'season_arr'=>array(
  5346. array(
  5347. 'category_id' => 2,
  5348. 'is_send' => 0,
  5349. 'status' => 0,
  5350. 'category_name' => '春季(根据5-7月的考试数据生成)',
  5351. ),
  5352. array(
  5353. 'category_id' => 5,
  5354. 'is_send' => 0,
  5355. 'status' => 0,
  5356. 'category_name' => '秋季(根据12-1月的考试数据生成)',
  5357. ),
  5358. ),
  5359. ),
  5360. array(
  5361. 'product_name' => '总复习学习宝',
  5362. 'season_arr'=>array(
  5363. array(
  5364. 'category_id' => 3,
  5365. 'is_send' => 0,
  5366. 'status' => 0,
  5367. 'category_name' => '春季(根据2-7月的考试数据生成)',
  5368. ),
  5369. array(
  5370. 'category_id' => 6,
  5371. 'is_send' => 0,
  5372. 'status' => 0,
  5373. 'category_name' => '秋季(根据9-1月的考试数据生成)',
  5374. ),
  5375. ),
  5376. ),
  5377. );
  5378. $review_info = SReviewPaperProductSet::model()->findAll(
  5379. array(
  5380. 'select'=>'category,status,reset_time',
  5381. 'condition'=>'semester_id = :semester_id and subject_id=:subject',
  5382. 'params'=>array(':semester_id'=>$this->semesterId,':subject'=>$subjectId),
  5383. )
  5384. );
  5385. $review_status = array();
  5386. $reset_time = array();
  5387. $cate3_rel_cate6 = array();
  5388. foreach ($review_info as $info) {
  5389. $review_status[$info->category] = $info->status;
  5390. $reset_time[$info->category] = $info->reset_time;
  5391. $cate3_rel_cate6[$info->category] = $info->category;
  5392. }
  5393. unset($review_info);
  5394. foreach ($review_isp as $key => $review){
  5395. foreach ($review['season_arr'] as $k => $cate){
  5396. if(isset($review_status[$cate['category_id']])){
  5397. $review_isp[$key]['season_arr'][$k]['status'] = (int)$review_status[$cate['category_id']];
  5398. $review_isp[$key]['season_arr'][$k]['reset_time'] = $reset_time[$cate['category_id']]; //重置时间
  5399. }
  5400. }
  5401. }
  5402. $data['pages'] = $pager;
  5403. $data['pape_count'] = $count;
  5404. $data['class_data'] = $class_data;
  5405. $data['semester_name'] = $this->semesterDetail['semester_name'];
  5406. $data['class_student'] = $class_student_ids;
  5407. $data['class_down'] = $class_down;
  5408. $data['class_create'] = $class_create;
  5409. $data['grade'] = $grade;
  5410. $data['class_name'] = $class_name;
  5411. $data['class_id'] = $class_id;
  5412. $data['class_all'] = $class_all;
  5413. $data['review_isp'] = $review_isp;
  5414. $data['semester_id'] = $this->semesterId;
  5415. $data['subjectId'] = $this->subjectId;
  5416. $data['cate3_rel_cate6'] = $cate3_rel_cate6;
  5417. $data['ptype'] = $ptype;
  5418. $data['season'] = $season;
  5419. $data['class_bt'] = $class_bt;
  5420. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  5421. {
  5422. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  5423. }else
  5424. {
  5425. $data["use_zhixue"] = 0;
  5426. }
  5427. $this->render('sheet',$data);
  5428. }
  5429. public function actionClass_student_product()
  5430. {
  5431. Url::clean();
  5432. $cid = Req::get("cid");
  5433. $type = Req::get("type");
  5434. $student_name = Req::get("student_name");
  5435. $data = array();
  5436. $student_ids = array();
  5437. $student_products = array();
  5438. if(!$cid)
  5439. {
  5440. Yii::app()->jump->error('未找到班级!');
  5441. }
  5442. $classInfo = ClassModel::model()->findByPk($cid);
  5443. if (empty($classInfo)) {
  5444. Yii::app()->jump->error('未找到班级!');
  5445. }
  5446. $class_student_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$cid,':status'=>0));
  5447. if($class_student_data)
  5448. {
  5449. foreach($class_student_data as $v)
  5450. {
  5451. $student_ids[$v->student_id] = $v->student_id;
  5452. }
  5453. }
  5454. $criteria = new CDbCriteria();
  5455. $criteria->addInCondition('student_id',$student_ids);
  5456. if($student_name)
  5457. {
  5458. $criteria->addSearchCondition('realname',$student_name);
  5459. }
  5460. $count = SStudentInfo::model()->count($criteria);
  5461. $pager = new CPagination($count,10);
  5462. $criteria->limit=$pager->getLimit();
  5463. $criteria->offset=$pager->getOffset();
  5464. $student_data = SStudentInfo::model()->findAll($criteria);
  5465. $student_ids1=array();
  5466. foreach($student_data as $v){
  5467. $student_ids1[] = (string)$v->student_id;
  5468. }
  5469. // 多学科切换条件
  5470. if(in_array($this->subjectId,$this->mathSubjectId)){
  5471. $subjectId=3;
  5472. }else{
  5473. $subjectId=$this->subjectId;
  5474. }
  5475. $stuids = array();
  5476. if($student_ids1){
  5477. if (Yii::app()->params["limit_open"]) {
  5478. $semester=new SSemester();
  5479. $nowsem=$semester->getCurrentSemester();
  5480. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$cid));
  5481. $intarr=array(
  5482. "schoolId"=>$this->schoolId,
  5483. "clazzId"=>$cid,
  5484. "semester"=>$nowsem['refer_code'],
  5485. "grade"=>$classinfo['grade'],
  5486. "students"=>array(),
  5487. "examTime"=>time(),
  5488. "classify"=>1,
  5489. "subject"=>$subjectId,
  5490. );
  5491. $stuids=$this->getManyProductOrder($intarr,array(1,2,3),$student_ids1);
  5492. }else {
  5493. $stuids = $student_ids1;
  5494. }
  5495. }
  5496. foreach($student_data as $k=>$v){
  5497. if($this->inArray($v->student_id,$stuids)){
  5498. // if(in_array((string)$v->student_id,$stuids)){
  5499. $v->is_outer=1;
  5500. }else{
  5501. $v->is_outer=0;
  5502. }
  5503. $student_data[$k]=$v;
  5504. }
  5505. unset($criteria);
  5506. $student_product_data=SStudentProductModel::model()->getStudentCreate($student_ids,$subjectId,$type,$this->semesterId);
  5507. if($student_product_data)
  5508. {
  5509. foreach($student_product_data as $v)
  5510. {
  5511. $student_products[$v['student_id']] = $v;
  5512. }
  5513. }
  5514. $data['page_count'] = $count;
  5515. $data['class_id'] = $cid;
  5516. $data['class_name'] = $classInfo->class_name;
  5517. $data['pages'] = $pager;
  5518. $data['student'] = $student_data;
  5519. $data['type'] = $type;
  5520. $data['student_products'] = $student_products;
  5521. $data['semester_name'] = $this->semesterDetail['semester_name'];
  5522. $data['student_name'] = $student_name;
  5523. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  5524. {
  5525. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  5526. }else
  5527. {
  5528. $data["use_zhixue"] = 0;
  5529. }
  5530. $this->render('sheet_chang',$data);
  5531. }
  5532. /**
  5533. * in_array() php 5.3 有问题重新写
  5534. * @param type $value
  5535. * @param type $arr
  5536. * @return boolean
  5537. */
  5538. public function inArray($value,$arr){
  5539. if($arr){
  5540. foreach($arr as $v){
  5541. if((string)$value === (string)$v){
  5542. return true;
  5543. }
  5544. }
  5545. }
  5546. return false;
  5547. }
  5548. public function actionDownload_student_product(){
  5549. $classId = Req::get("classId");
  5550. $type = Req::get("type");
  5551. $studentsIds = Req::get("studentsIds");
  5552. if( !$classId || !$type){
  5553. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  5554. exit();
  5555. }
  5556. if(!in_array($type, array(1, 2, 3))){
  5557. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  5558. exit();
  5559. }
  5560. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  5561. //
  5562. if(!$apiUrl){
  5563. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  5564. exit();
  5565. }
  5566. $params = array(
  5567. "schoolId" => $this->schoolId,
  5568. "classId" => $classId,
  5569. "type" => $type,
  5570. );
  5571. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$classId,':status'=>0));
  5572. if($student_class_data)
  5573. {
  5574. if(!$studentsIds)
  5575. {
  5576. $studentsIds=array();
  5577. foreach($student_class_data as $v)
  5578. {
  5579. // $params['studentIds'][] = $v->student_id;
  5580. $studentsIds[]=$v->student_id;
  5581. }
  5582. }
  5583. }else{
  5584. echo json_encode(array("success" => 0, "message" => "班级暂无学生"));exit;
  5585. }
  5586. if($studentsIds)
  5587. {
  5588. ;
  5589. if(!is_array($studentsIds)){
  5590. $studentsIds=explode(',',$studentsIds);
  5591. }
  5592. // $student_ids1="";
  5593. // foreach($studentsIds as $v){
  5594. // $student_ids1.="'".$v."',";
  5595. // }
  5596. // $student_ids1=substr($student_ids1,0,strlen($student_ids1)-1);
  5597. // $stu_order=array();
  5598. // if($student_ids1){
  5599. // $today=date("Y-m-d H:i:s");
  5600. // $semester=new SSemester();
  5601. // $nowsem=$semester->getCurrentSemester();
  5602. // $sql="SELECT
  5603. // student_id,
  5604. // student_name,
  5605. // group_concat(trial_begin_time) AS trial_begin_time,
  5606. // group_concat(trial_end_time) AS trial_end_time,
  5607. // group_concat(type_id) AS type_id,
  5608. // group_concat(classify) AS classify,
  5609. // group_concat(`code`) AS `code`
  5610. // FROM
  5611. // (
  5612. // SELECT
  5613. // o.id,
  5614. // IFNULL(o.trial_begin_time, '') AS trial_begin_time,
  5615. // IFNULL(o.trial_end_time,'') as trial_end_time,
  5616. // g.type_id,
  5617. // g.classify,
  5618. // IFNULL(gt.`code`,0) as `code`,
  5619. // os.student_name,
  5620. // os.student_id
  5621. // FROM
  5622. // `order` AS o
  5623. // JOIN order_goods AS og ON og.order_id = o.id
  5624. // JOIN goods AS g ON g.id = og.goods_id
  5625. // left JOIN goods_term AS gt ON g.id = gt.goods_id
  5626. // left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id
  5627. // JOIN order_student AS os ON os.order_id = o.id
  5628. // WHERE
  5629. // os.student_id in ($student_ids1)
  5630. // and (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}')
  5631. // and o.status=1
  5632. // AND o.school_id ={$this->schoolId}
  5633. // AND os.chargeback = 0
  5634. // and o.id not in (select business_key from zsy_service where status=1)
  5635. // ORDER BY
  5636. // g.type_id
  5637. //
  5638. // ) t
  5639. // GROUP BY
  5640. // student_name ";
  5641. // $stu_order=Yii::app()->db251->createCommand($sql)->queryAll();
  5642. //
  5643. // }
  5644. // $limit=array();
  5645. // if($stu_order){
  5646. //
  5647. // foreach($stu_order as $v){
  5648. // $limit[$v['student_id']]=$v;
  5649. // }
  5650. //
  5651. // }
  5652. // $stuids=$studentsIds;
  5653. // foreach($stuids as $k=>$v){
  5654. // if(!isset($limit[$v])){
  5655. // unset($stuids[$k]);
  5656. // }
  5657. // }
  5658. $stuids = array();
  5659. if (Yii::app()->params["limit_open"]) {
  5660. $semester=new SSemester();
  5661. $nowsem=$semester->getCurrentSemester();
  5662. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId));
  5663. $intarr=array(
  5664. "schoolId"=>$this->schoolId,
  5665. "clazzId"=>$classId,
  5666. "semester"=>$nowsem['refer_code'],
  5667. "grade"=>$classinfo['grade'],
  5668. "students"=>array(),
  5669. "examTime"=>time(),
  5670. "classify"=>1,
  5671. "subject"=>3,
  5672. );
  5673. $this->getStuOrder($studentsIds,$intarr,$stuids);
  5674. }else {
  5675. $stuids = $studentsIds;
  5676. }
  5677. if(!$stuids){
  5678. echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限"));exit;
  5679. }
  5680. $params['studentIds'] = $stuids;
  5681. $criteria = new CDbCriteria();
  5682. $_students = array();
  5683. if($params["studentIds"])
  5684. {
  5685. $_students = $params["studentIds"];
  5686. }
  5687. $criteria->addInCondition('student_id',$_students);
  5688. $criteria->addCondition('type=:type');
  5689. $criteria->params[':type'] = $type;
  5690. $_student_product_data = SStudentProductModel::model()->findAll($criteria);
  5691. if(!$_student_product_data)
  5692. {
  5693. echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF"));exit;
  5694. }
  5695. }
  5696. $rs = Curl::post($apiUrl."/rest/download_sp/index", $params);
  5697. if(!($rs = json_decode($rs))){
  5698. $rs = array(
  5699. "success" => 0,
  5700. "message" => "请求接口失败",
  5701. );
  5702. echo json_encode($rs);exit;
  5703. }
  5704. if($rs->success!=0){
  5705. $rs->success=2;
  5706. $rs->limitinfo='全班允许下载';
  5707. }
  5708. if($params["studentIds"] && ($rs->success==1 || $rs->success==2) )
  5709. {
  5710. $criteria = new CDbCriteria();
  5711. $_students = array();
  5712. if($params["studentIds"])
  5713. {
  5714. $_students = $params["studentIds"];
  5715. }
  5716. $criteria->addInCondition('student_id',$_students);
  5717. $criteria->addCondition('type=:type');
  5718. $criteria->params[':type'] = $type;
  5719. SStudentProductModel::model()->updateAll(array('is_download'=>1,'download_time'=>time()),$criteria);
  5720. }
  5721. echo json_encode($rs);exit;
  5722. }
  5723. /**
  5724. * 获取学生是否有订单
  5725. * @param $studentsIds
  5726. * @param $intarr
  5727. * @param $stuids
  5728. */
  5729. protected function getStuOrder($studentsIds,$intarr,&$stuids){
  5730. foreach(array(1,2,3) as $type){
  5731. $intarr['classify'] = $type;
  5732. $intarr['students'] = array_diff($studentsIds,$stuids);
  5733. if(!$intarr['students']){
  5734. break;
  5735. }else{
  5736. $intarr['students'] = array_values($intarr['students']);
  5737. }
  5738. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  5739. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  5740. if (!$rs) {
  5741. Yii::app()->jump->error("接口错误");
  5742. }
  5743. if (!empty($rs->data)) {
  5744. $stuids = array_merge($stuids,$rs->data);
  5745. }
  5746. }
  5747. }
  5748. /**
  5749. * 打包下载
  5750. */
  5751. public function actionPrint_pack()
  5752. {
  5753. $exam_id = Req::post("exam_id");
  5754. $student_id = Req::post("student_id");
  5755. if(!$exam_id )
  5756. {
  5757. echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
  5758. }
  5759. $student_ids = array();
  5760. if(!$student_id)
  5761. {
  5762. $student_paper_data = SStudentPaperRelation::model()->findAll("exam_id=:exam_id and is_del=:is_del ",array(":exam_id"=>$exam_id,':is_del'=>0));
  5763. if($student_paper_data)
  5764. {
  5765. foreach ($student_paper_data as $v)
  5766. {
  5767. $student_ids[] = $v->student_id;
  5768. }
  5769. }
  5770. }else
  5771. {
  5772. $studentIds = explode(',',$student_id);
  5773. foreach ($studentIds as $v)
  5774. {
  5775. if($v)
  5776. {
  5777. $student_ids[] = $v;
  5778. }
  5779. }
  5780. }
  5781. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  5782. $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/download/fixedtemplate/qrinfo/'.$this->schoolId;
  5783. $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password);
  5784. //操作日志
  5785. if(Yii::app()->params['handle_log_on_off'])
  5786. {
  5787. writeFileLog(jsonEncode(array(
  5788. "exam_group_id" => '',
  5789. "operate_project" => 'zsyas2',
  5790. "title" => '打包打印',
  5791. "school_id" => $this->schoolId,
  5792. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  5793. "operate_method" => $this->action,
  5794. "operate_url" => $url,
  5795. "operate_sql" => '',
  5796. "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids),'rs'=>$rs)),
  5797. "date"=>date('Y-m-d H:i:j')
  5798. )));
  5799. }
  5800. if(isset($rs->errCode) && $rs->errCode =='00')
  5801. {
  5802. ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  5803. echo json_encode(array('status'=>1,'result'=>$rs->data));exit;
  5804. }
  5805. $errMsg = '下载失败';
  5806. if(isset($rs->errMsg))
  5807. {
  5808. $errMsg = $rs->errMsg;
  5809. }
  5810. echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
  5811. }
  5812. public function CrmApiPost($url, $arr, $username,$password,$type='POST',$header=array())
  5813. {
  5814. $ch = @curl_init();
  5815. $result = FALSE;
  5816. if ($ch)
  5817. {
  5818. $data = json_encode($arr);
  5819. $headerArr=array(
  5820. 'Content-Type: application/json',
  5821. 'Content-Length: '. strlen($data),
  5822. 'Connection: false',
  5823. 'Expect:'
  5824. );
  5825. if($header){
  5826. $headerArr=array_merge($headerArr,$header);
  5827. }
  5828. if($type=='POST'){
  5829. // Digest认证
  5830. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  5831. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  5832. // 不输出头部
  5833. curl_setopt($ch, CURLOPT_HEADER, 0);
  5834. // curl_exec 获取到的内容不直接输出, 而是返回
  5835. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  5836. curl_setopt($ch, CURLOPT_TIMEOUT,120);
  5837. curl_setopt($ch, CURLOPT_NOSIGNAL,1);
  5838. curl_setopt($ch, CURLOPT_TIMEOUT_MS,120000);
  5839. // 请求重启路由器的地址 传参 进行重启
  5840. curl_setopt($ch, CURLOPT_URL, $url);
  5841. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  5842. curl_setopt($ch, CURLOPT_POST, 1);
  5843. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  5844. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  5845. if( !curl_errno($ch))
  5846. {
  5847. $result = json_decode(curl_exec($ch));
  5848. }
  5849. // 释放资源
  5850. curl_close($ch);
  5851. }elseif($type=='PUT'){
  5852. $data = json_encode($arr);
  5853. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  5854. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  5855. curl_setopt($ch, CURLOPT_HEADER, 0);
  5856. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  5857. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5858. curl_setopt($ch, CURLOPT_URL, $url);
  5859. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  5860. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  5861. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  5862. $result = json_decode(curl_exec($ch));
  5863. curl_close($ch);
  5864. }
  5865. }
  5866. return $result;
  5867. }
  5868. //获取考试的班级
  5869. public function actionGetExamClass(){
  5870. $examGroupId = Req::get("examGroupId");
  5871. $printType = (string)Req::get("printType");
  5872. $productType = (string)Req::get("productType");
  5873. $subjectId = (int)Req::get("subjectId");
  5874. $resultList =$resetLogs= array();
  5875. $resetTotal=3;//学管重置总次数
  5876. if(is_numeric($examGroupId) && $examGroupId > 0){
  5877. $condition[] = " e.exam_group_id = ".$examGroupId;
  5878. if ($printType == 'third_isp' || $subjectId == 8) {
  5879. $condition[] = "e.subject_id = 8";
  5880. }elseif ($printType == 'third_wb') {
  5881. $condition[] = "e.subject_id = '{$subjectId}'";
  5882. }elseif (in_array($this->subjectId,$this->mathSubjectId)) {
  5883. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  5884. } else {
  5885. $condition[] = "e.subject_id = '{$this->subjectId}'";
  5886. }
  5887. switch ($printType) {
  5888. case "wp":
  5889. $printTypeData = 0;
  5890. break;
  5891. case "wtb":
  5892. $printTypeData = 1;
  5893. break;
  5894. case "isp":
  5895. $printTypeData = 2;
  5896. break;
  5897. case "studytrend":
  5898. $printTypeData = 3;
  5899. break;
  5900. case "section":
  5901. $printTypeData = 4;
  5902. break;
  5903. case "third_wb":
  5904. $printTypeData = 1;
  5905. break;
  5906. case "third_isp":
  5907. $printTypeData = 3;
  5908. break;
  5909. case "exam_product":
  5910. $printTypeData = $productType;
  5911. break;
  5912. default:
  5913. $printTypeData = null;
  5914. break;
  5915. }
  5916. if(!Str::isBlank($printTypeData)){
  5917. $condition[] = "cep.type = '{$printTypeData}'";
  5918. }
  5919. if ($printType == 'wp') {
  5920. $condition[] = "eg.is_third = 0";
  5921. $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc'));
  5922. }elseif($printType == 'exam_product'){
  5923. //FIXME 新考试类型产品(如初高中方法宝)
  5924. $examProduct = new SExamProductStatus();
  5925. $rs = $examProduct->getProductList($condition,array('e.create_time desc'), $productType,100);
  5926. $resultList = isset($rs['rs']) ? $rs['rs'] : array();
  5927. }
  5928. else {
  5929. $resultList = $this->schoolManager->getDownloadClassIpf($condition,array('e.complete_time desc'));
  5930. }
  5931. $resetLogs=$this->sConn->createCommand("select exam_group_id,exam_id,class_id,learn_tube_reset_count,learn_tube_reset_time,reset_count from product_reset_log where exam_group_id ='{$examGroupId}' and product_type='".$printTypeData."'")->queryAll();
  5932. foreach($resetLogs as $key=>$resetLogInfo){
  5933. unset($resetLogs[$key]);
  5934. $resetLogs[$resetLogInfo['class_id']]=$resetLogInfo;
  5935. }
  5936. foreach($resultList as &$item){
  5937. $learnTubeResetCount=isset($resetLogs[$item['class_id']]['learn_tube_reset_count'])?$resetLogs[$item['class_id']]['learn_tube_reset_count']:0;
  5938. $learnTubeResetTime=isset($resetLogs[$item['class_id']]['learn_tube_reset_time'])?$resetLogs[$item['class_id']]['learn_tube_reset_time']:0;
  5939. $learnTubeResetResidueCount=$resetTotal>$learnTubeResetCount?$resetTotal-$learnTubeResetCount:0;
  5940. $item['learn_tube_reset_count']=$learnTubeResetCount;
  5941. $item['learn_tube_reset_residue_count']=$learnTubeResetResidueCount;
  5942. //学管30分钟内只能重置一次
  5943. $item['is_cool_down']=time()-$learnTubeResetTime<=1800?0:1;
  5944. //冷却文字提示 30分钟内并且剩余次数大于0
  5945. $item['is_cool_down_prompt']=!$item['is_cool_down'] && $learnTubeResetResidueCount?true:false;
  5946. $item['reset_count']=isset($resetLogs[$item['class_id']]['reset_count'])?$resetLogs[$item['class_id']]['reset_count']:0;
  5947. }
  5948. }
  5949. //是不是技术支持
  5950. $isTechnicalSupport=1;
  5951. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
  5952. $isTechnicalSupport=0;
  5953. }
  5954. $data=array(
  5955. "resultList" => $resultList,
  5956. 'printType'=>$printType,
  5957. 'productType'=>$productType,
  5958. 'is_technical_support'=>$isTechnicalSupport,
  5959. );
  5960. $this->render('reset_isp',$data);
  5961. }
  5962. //设置阶段个性化学习宝
  5963. public function actionSetReviewIsp(){
  5964. $res = array();
  5965. $res['status'] = 0;
  5966. $res['msg'] = '';
  5967. $error = array();
  5968. $semester_id = Req::post("semester_id");
  5969. $category = (int)Req::post("category");
  5970. $_class_id = (string)Req::post("class_id");
  5971. $handle_type = (string)Req::post("handle_type");
  5972. if(!($semester_id && is_numeric($semester_id))){
  5973. $error[] = '学期参数不正确';
  5974. }
  5975. if(!in_array($category,array(1,2,3,4,5,6))){
  5976. $error[] = '类型参数不正确';
  5977. }
  5978. if(!$handle_type){
  5979. $error[] = '操作类型参数不正确';
  5980. }
  5981. $status = 0;
  5982. if($handle_type == 'generat'){
  5983. $status = 1;
  5984. }else{
  5985. $status = 90;
  5986. }
  5987. if(in_array($this->subjectId,$this->mathSubjectId)){
  5988. $subjectId=3;
  5989. }else{
  5990. $subjectId=$this->subjectId;
  5991. }
  5992. //验证时间在不在当前学期范围内
  5993. $time = time();
  5994. // if(!$error){
  5995. // $semester = Semester::model()->find(
  5996. // array(
  5997. // 'select'=>'start_time,end_time',
  5998. // 'condition'=>'status = 1',
  5999. // )
  6000. // );
  6001. //
  6002. // if($semester){
  6003. // if (!($time >= $semester->start_time && $time <= $semester->end_time)) {
  6004. // $error[] = '时间不在当前学期范围内';
  6005. // }
  6006. // }else{
  6007. // $error[] = '学期数据不正确';
  6008. // }
  6009. // }
  6010. $gradeArr=array();
  6011. if(!$error){
  6012. $busTran = $this->sConn->beginTransaction();
  6013. try{
  6014. $sql = 'select class_id,grade from `class` where semester_id = '.$semester_id;
  6015. if ($_class_id) {
  6016. $sql .= ' and class_id = ' . $_class_id;
  6017. }
  6018. $class_info = $this->sConn->createCommand($sql)->queryAll();
  6019. if ($class_info) {
  6020. $class_ids = array();
  6021. foreach ($class_info as $info) {
  6022. $class_ids[$info['class_id']] = $info['class_id'];
  6023. $gradeArr[$info['grade']]=$info['grade'];
  6024. }
  6025. }else{
  6026. throw new Exception('本学期没班级');
  6027. }
  6028. $sql = 'select rprs_id from review_paper_product_set where semester_id = '.$semester_id.' and category = '.$category.' and subject_id='.$subjectId;
  6029. $product_set_info = $this->sConn->createCommand($sql)->queryRow();
  6030. if ($product_set_info) {
  6031. $sql = "update review_paper_product_set set `status` = {$status},update_time = {$time},reset_time={$time} where rprs_id = {$product_set_info['rprs_id']}";
  6032. }else{
  6033. $sql = "insert into review_paper_product_set(semester_id,category,status,update_time,create_time,subject_id) value({$semester_id},{$category},{$status},{$time},{$time},{$subjectId})";
  6034. }
  6035. $bool = $this->sConn->createCommand($sql)->execute();
  6036. if ($bool === false) {
  6037. throw new Exception('操作产品设置失败');
  6038. }
  6039. if (isset($product_set_info['rprs_id']) && $product_set_info['rprs_id']) {
  6040. $rprs_id = $product_set_info['rprs_id'];
  6041. }else{
  6042. $rprs_id = $this->sConn->getLastInsertID();
  6043. }
  6044. $sql = 'select rpc_id,class_id,status from `review_product_class` where rprs_id = '.$rprs_id.' and class_id in ('.implode(',',$class_ids).')';
  6045. if ($_class_id) {
  6046. $sql .= ' and class_id = ' . $_class_id;
  6047. }
  6048. $product_class_info = $this->sConn->createCommand($sql)->queryAll();
  6049. $class_rel_rprc = array();
  6050. if ($product_class_info) {
  6051. foreach ($product_class_info as $info) {
  6052. $class_rel_rprc[$info['class_id']] = $info['rpc_id'];
  6053. }
  6054. }
  6055. //创建或更新数据
  6056. $update_class_sql = array();
  6057. $insert_class_sql = array();
  6058. foreach ($class_ids as $class_id) {
  6059. if (isset($class_rel_rprc[$class_id])) {
  6060. $update_class_sql[] = "update review_product_class set `status` = {$status},update_time = {$time} where rpc_id = {$class_rel_rprc[$class_id]}";
  6061. }else{
  6062. $insert_class_sql[] = "({$rprs_id},{$class_id},{$status},{$time},{$time})";
  6063. }
  6064. }
  6065. if ($update_class_sql) {
  6066. foreach ($update_class_sql as $_sql) {
  6067. $bool = $this->sConn->createCommand($_sql)->execute();
  6068. if ($bool === false) {
  6069. throw new Exception('操作产品班级失败');
  6070. }
  6071. }
  6072. }
  6073. if ($insert_class_sql) {
  6074. $_sql = "insert into review_product_class(rprs_id,class_id,status,update_time,create_time) values ".implode(',',$insert_class_sql);
  6075. $_sql = rtrim($_sql, ',');
  6076. $bool = $this->sConn->createCommand($_sql)->execute();
  6077. if ($bool === false) {
  6078. throw new Exception('操作产品班级失败');
  6079. }
  6080. }
  6081. //更新学生生成状态
  6082. if ($status == 90) {
  6083. if ($category > 3) {
  6084. $_category = $category - 3;
  6085. }else{
  6086. $_category = $category;
  6087. }
  6088. //重置后清除已存在的下载任务
  6089. $unique_key = $semester_id . '_' . $_category;
  6090. $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= '{$unique_key}' and product_type=4 and subject_id='{$subjectId}'")->execute();
  6091. $rpcIds=array_values($class_rel_rprc);
  6092. $sql = "update student_product set `is_html_created` = 0,is_pdf_created = 0 where semester_id = {$semester_id} and product_type = {$category} and plan_id in(".implode(',',$rpcIds).") ";
  6093. if ($_class_id) {
  6094. $_sql = 'select student_id from student_class_relation where class_id = '.$_class_id.' and status = 0';
  6095. $class_student = $this->sConn->createCommand($_sql)->queryAll();
  6096. $class_stu_ids = array();
  6097. if ($class_student) {
  6098. foreach ($class_student as $value) {
  6099. $class_stu_ids[] = $value['student_id'];
  6100. }
  6101. }else{
  6102. throw new Exception('班级没有对应的学生');
  6103. }
  6104. $sql .= ' and student_id in ('.implode(',',$class_stu_ids).')';
  6105. }
  6106. $this->sConn->createCommand($sql)->execute();
  6107. }
  6108. $busTran->commit();
  6109. //发送消息{"school_id":"3955","subject_id":"3","send_type":"stage_review","msg_type":1,"grade_ids":[1],"year":2021,
  6110. //"product_type":"1","class_ids":["683589263477706752"],"student_ids":[]}
  6111. if($handle_type=='reset'){
  6112. $msgType=90;
  6113. }else{
  6114. $msgType=1;
  6115. }
  6116. if ($_class_id) {
  6117. $sendMsg=array(
  6118. 'school_id'=>$this->schoolId,
  6119. 'msg_type'=>$msgType,
  6120. 'subject_id'=>$subjectId,
  6121. 'send_type'=>'many_stage_review',
  6122. 'grade_ids'=>array_values($gradeArr),
  6123. 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'),
  6124. 'product_type'=>$category,
  6125. 'class_ids'=>array($_class_id)
  6126. );
  6127. sendDataToKafka('php-product-many-stage-html',$sendMsg);
  6128. }else{
  6129. foreach ($gradeArr as $value){
  6130. $sendMsg=array(
  6131. 'school_id'=>$this->schoolId,
  6132. 'msg_type'=>$msgType,
  6133. 'subject_id'=>$subjectId,
  6134. 'send_type'=>'many_stage_review',
  6135. 'grade_ids'=>array($value),
  6136. 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'),
  6137. 'product_type'=>$category,
  6138. );
  6139. sendDataToKafka('php-product-many-stage-html',$sendMsg);
  6140. }
  6141. }
  6142. }catch(Exception $e){
  6143. $error[] = $e->getMessage();
  6144. $busTran->rollBack();
  6145. }
  6146. }
  6147. if($error){
  6148. $res['msg'] = implode(PHP_EOL,$error);
  6149. echo json_encode($res);
  6150. }else{
  6151. $res['status'] = 1;
  6152. echo json_encode($res);
  6153. }
  6154. exit;
  6155. }
  6156. //读取班级
  6157. public function actionLoadClass(){
  6158. $grade=Req::post('grade');
  6159. $branch=Req::post('branch');
  6160. $exam_group_ids=Req::post('eid');
  6161. $result['status']=0;
  6162. $examClass=array();
  6163. //获取考试ID
  6164. $criteria = new CDbCriteria();
  6165. $criteria->select = 'exam_id,exam_group_id';
  6166. $criteria->addCondition("exam_group_id='".$exam_group_ids."'");
  6167. $exam_data = Exam::model()->findAll($criteria);
  6168. unset($criteria);
  6169. unset($exam_group_ids);
  6170. if($exam_data)
  6171. {
  6172. foreach($exam_data as $v)
  6173. {
  6174. $exam_ids[] = $v->exam_id;
  6175. }
  6176. unset($exam_data);
  6177. //通过考试ID,获取打印班级
  6178. $criteria = new CDbCriteria();
  6179. $criteria->select = 'exam_id,class_id';
  6180. $criteria->addInCondition('exam_id',$exam_ids);
  6181. $class_print_data = ClassExamPrinter::model()->findAll($criteria);
  6182. if($class_print_data)
  6183. {
  6184. foreach($class_print_data as $v)
  6185. {
  6186. $examClass[]=(string)$v->class_id;
  6187. }
  6188. }
  6189. unset($criteria);
  6190. unset($class_print_data);
  6191. }
  6192. //判断考试是否走班考试
  6193. $class_type=1;
  6194. if($examClass){
  6195. $checkClassData=ClassModel::model()->find('class_id=:classid',array(':classid'=>$examClass[0]));
  6196. if($checkClassData && $checkClassData->class_type==2){
  6197. $class_type=2;
  6198. }
  6199. }
  6200. if($branch){
  6201. $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and arts_science=:arts_science and class_type=:class_type and is_hide=0',array(':semester_id'=>$this->semesterId,":grade"=>$grade,':arts_science'=>$branch,":class_type"=>$class_type));
  6202. }else{
  6203. $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and class_type=:class_type and is_hide=0 ',array(':semester_id'=>$this->semesterId,":grade"=>$grade,":class_type"=>$class_type));
  6204. }
  6205. $groupClassData=array();
  6206. foreach ($class_data as $val){
  6207. $temp=array(
  6208. 'class_id'=>$val->class_id,
  6209. 'class_name'=>$val->class_name,
  6210. 'grade' =>$val->grade,
  6211. 'arts_science'=>$val->arts_science
  6212. );
  6213. if(in_array((string)$val->class_id,$examClass,true)){
  6214. $temp['is_used']=1;
  6215. }else{
  6216. $temp['is_used']=0;
  6217. }
  6218. $groupClassData[$val->level][]=$temp;
  6219. }
  6220. $result['status']=1;
  6221. $result['classData']=$groupClassData;
  6222. exit(json_encode($result));
  6223. }
  6224. //提交选择班级结果
  6225. public function actionSaveExamClass(){
  6226. $classId=Req::post('classId');
  6227. $exam_group_id=Req::post('eid');
  6228. $result['status']=0;
  6229. if(!$exam_group_id || !$classId || !is_array($classId)){
  6230. $result['msg']='数据异常';
  6231. exit(json_encode($result));
  6232. }
  6233. $examName='';
  6234. $examClass=array(); //原考试班级
  6235. $needDelClass=array(); //需要删除的班级
  6236. $neeAddClass=array(); //需要增加的班级
  6237. $time=time();
  6238. //获取考试ID
  6239. $criteria = new CDbCriteria();
  6240. $criteria->select = 'exam_id,exam_group_id,class_id';
  6241. $criteria->addCondition("exam_group_id='".$exam_group_id."'");
  6242. $exam_data = Exam::model()->findAll($criteria);
  6243. unset($criteria);
  6244. if($exam_data)
  6245. {
  6246. foreach($exam_data as $v)
  6247. {
  6248. $exam_ids[] = $v->exam_id;
  6249. $examClass[] = (string)$v->class_id;
  6250. }
  6251. foreach ($examClass as $key => $val){
  6252. if(in_array((string)$val,$classId,true)){
  6253. unset($classId[array_search((string)$val,$classId,true)]);
  6254. }else{
  6255. $needDelClass[]=$val; //需要删除
  6256. }
  6257. }
  6258. if($classId){
  6259. $neeAddClass= $classId;
  6260. }
  6261. $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length from exam where exam_id='".$exam_ids[0]."' ")->queryRow();
  6262. $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
  6263. $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow();
  6264. $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']);
  6265. //增加班级
  6266. if($neeAddClass){
  6267. $transaction = $this->sConn->beginTransaction();
  6268. try {
  6269. foreach ($neeAddClass as $classId) {
  6270. $newExamId=getUniqueId($this->schoolId);
  6271. $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll();
  6272. $studentIds=array();
  6273. if($studentIdData){
  6274. foreach ($studentIdData as $datum){
  6275. $studentIds[]=$datum['student_id'];
  6276. }
  6277. }
  6278. if(!$studentIds) continue;
  6279. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  6280. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  6281. //添加考试
  6282. $this->sConn->createCommand()->insert('exam', array(
  6283. 'exam_id' => $newExamId,
  6284. 'exam_group_id' => $exam_group_id,
  6285. 'name' => $examDetail['name'],
  6286. 'subject_id' => $examDetail['subject_id'],
  6287. 'semester_id' => $examDetail['semester_id'],
  6288. 'teacher_id' => $examDetail['teacher_id'],
  6289. 'module_id' => $examDetail['module_id'],
  6290. //'type' => $examDetail['type'],
  6291. 'type' => $examDetail['type'],
  6292. 'status' => 3,
  6293. 'week_num' => $examDetail['week_num'],
  6294. 'create_type' => $examDetail['create_type'],
  6295. 'create_time' => $examDetail['create_time'],
  6296. 'update_time' => $examDetail['update_time'],
  6297. 'tpl_index' => $examDetail['tpl_index'],
  6298. 'tpl_data' => $examDetail['tpl_data'],
  6299. 'class_id' => $classId,
  6300. 'method_ids' => $examDetail['method_ids'],
  6301. 'from_exam_id' => $examDetail['from_exam_id'],
  6302. 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0,
  6303. 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0,
  6304. // 'is_third' =>$examDetail['is_third']
  6305. ));
  6306. //添加试卷
  6307. $newPaperId=getUniqueId($this->schoolId);
  6308. $this->sConn->createCommand()->insert('paper', array(
  6309. 'paper_id' => $newPaperId,
  6310. 'paper_type' => $paperDetail['paper_type'],
  6311. 'exam_id' => $newExamId,
  6312. 'paper_name' => "",
  6313. 'paper_layer' => $paperDetail['paper_layer'],
  6314. 'difficulty' => $paperDetail['difficulty'],
  6315. 'topics_count' => $paperDetail['topics_count'],
  6316. 'score' => $paperDetail['score'],
  6317. 'add_time' => $paperDetail['add_time'],
  6318. 'update_time' => $paperDetail['update_time'],
  6319. 'method_ids' => $paperDetail['method_ids'],
  6320. 'is_labelled' => $paperDetail['is_labelled'],
  6321. 'status' => $paperDetail['status']
  6322. ));
  6323. if ($studentIds_0) {
  6324. foreach ($studentIds_0 as $studentId) {
  6325. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  6326. // if($studentIds){
  6327. // foreach ($studentIds as $studentId) {
  6328. $this->sConn->createCommand()->insert('student_paper_relation', array(
  6329. 'student_id' => $studentId,
  6330. 'paper_id' => $newPaperId,
  6331. 'exam_id' => $newExamId,
  6332. 'semester_id' => $this->semesterId,
  6333. 'class_id' => $classId,
  6334. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  6335. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  6336. ));
  6337. }
  6338. }
  6339. foreach ($paperTopics as $paperTopic) {
  6340. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  6341. 'paper_id' => $newPaperId,
  6342. 'topic_id' => $paperTopic['topic_id'],
  6343. 'order' => $paperTopic['order'],
  6344. 'mode' => (int)$paperTopic['mode'],
  6345. 'type' => $paperTopic['type'],
  6346. 'score' => $paperTopic['score'],
  6347. 'method_ids' => $paperTopic['method_ids'],
  6348. 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2,
  6349. ));
  6350. $this->sConn->createCommand()->insert('topic_use', array(
  6351. 'topic_id' => $paperTopic['topic_id'],
  6352. 'mode' => $paperTopic['mode'],
  6353. 'teacher_id' => $examDetail['teacher_id'],
  6354. ));
  6355. }
  6356. $this->sConn->createCommand()->insert('class_exam_printer', array(
  6357. 'class_id' => $classId,
  6358. 'exam_id' => $newExamId,
  6359. 'type' => 0,
  6360. 'is_print' => 0,
  6361. 'print_time' => 0,
  6362. 'add_time' => $time,
  6363. ));
  6364. }
  6365. $transaction->commit();
  6366. }catch (Exception $e){
  6367. $transaction->rollBack();
  6368. exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
  6369. }
  6370. }
  6371. if($needDelClass){
  6372. $transaction = $this->sConn->beginTransaction();
  6373. try {
  6374. foreach ($needDelClass as $classId){
  6375. $exam=$this->sConn->createCommand("select exam_id from exam where exam_id IN (".implode(',',$exam_ids).") and class_id='".$classId."'")->queryRow();
  6376. $paper = $this->sConn->createCommand("select paper_id from paper where exam_id ='".$exam['exam_id']."'")->queryRow();
  6377. $this->sConn->createCommand("delete from `exam` where exam_id = '{$exam['exam_id']}'")->execute();
  6378. $this->sConn->createCommand("delete from `paper` where paper_id = '{$paper['paper_id']}'")->execute();
  6379. //student_paper_relation,paper_topic_relation,class_exam_printer
  6380. $this->sConn->createCommand("delete from `student_paper_relation` where paper_id = '{$paper['paper_id']}'")->execute();
  6381. $this->sConn->createCommand("delete from `paper_topic_relation` where paper_id = '{$paper['paper_id']}'")->execute();
  6382. $this->sConn->createCommand("delete from `class_exam_printer` where exam_id = '{$exam['exam_id']}'")->execute();
  6383. }
  6384. $transaction->commit();
  6385. }catch (Exception $e){
  6386. $transaction->rollBack();
  6387. exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
  6388. }
  6389. }
  6390. if(Yii::app()->params['handle_log_on_off'])
  6391. {
  6392. writeFileLog(jsonEncode(array(
  6393. "exam_group_id" => $exam_group_id,
  6394. "operate_project" => 'zsyas2',
  6395. "school_id" => $this->schoolId,
  6396. "title" => '添加考试班级',
  6397. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  6398. "operate_method" => $this->action,
  6399. "operate_url" => $this->getRoute(),
  6400. "operate_sql" =>'',
  6401. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  6402. "date"=>date('Y-m-d H:i:j')
  6403. )));
  6404. }
  6405. exit(json_encode(array('status'=>1,'msg'=>'设置成功')));
  6406. }else{
  6407. $result['msg']='考试数据异常';
  6408. exit(json_encode($result));
  6409. }
  6410. }
  6411. public function UUID_SHORT($length = 20)
  6412. {
  6413. $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
  6414. $result = $query['UUID_SHORT'];
  6415. if ($length AND is_int($length))
  6416. {
  6417. $result = substr($result, ($length * -1));
  6418. }
  6419. return $result;
  6420. }
  6421. //删除全部未考试学生
  6422. public function actionDelExamStudentAll()
  6423. {
  6424. $exam_group_id = Req::post('exam_group_id');
  6425. $studentsIds = array();
  6426. if(!$exam_group_id)
  6427. {
  6428. echo json_encode(array('status'=>0));exit;
  6429. }
  6430. //获取考试ID
  6431. $criteria = new CDbCriteria();
  6432. $criteria->select = 'exam_id,exam_group_id,class_id';
  6433. $criteria->addCondition("exam_group_id='".$exam_group_id."'");
  6434. $exam_data = Exam::model()->findAll($criteria);
  6435. unset($criteria);
  6436. if($exam_data) {
  6437. foreach ($exam_data as $v) {
  6438. $exam_ids[] = $v->exam_id;
  6439. }
  6440. }
  6441. foreach ($exam_ids as $exam_id){
  6442. $examStudentsIds=array();
  6443. $student_data =$this->schoolManager->getStudentPaperByExamIds($exam_ids);
  6444. if($student_data)
  6445. {
  6446. foreach($student_data as $v)
  6447. {
  6448. $examStudentsIds[$v['student_id']] = $v['student_id'];
  6449. }
  6450. $sendJsonArr[]=array(
  6451. 'school_id'=>$this->schoolId,
  6452. 'send_type'=>'zsyas',
  6453. 'update_type'=>2,
  6454. 'exam_group_id'=>$exam_group_id,
  6455. 'exam_id_arr'=>array($exam_id),
  6456. 'student_id_arr'=>$examStudentsIds
  6457. );
  6458. $studentsIds=array_merge($studentsIds,$examStudentsIds);
  6459. }
  6460. }
  6461. if(!$studentsIds){
  6462. echo json_encode(array('status'=>2));exit;
  6463. }
  6464. if($this->schoolManager->delStudentPaperPropertyByExamIds($exam_ids,$studentsIds))
  6465. {
  6466. //操作日志
  6467. if(Yii::app()->params['handle_log_on_off'])
  6468. {
  6469. writeFileLog(jsonEncode(array(
  6470. "exam_group_id" =>$exam_group_id,
  6471. "operate_project" => 'zsyas2',
  6472. "school_id" => $this->schoolId,
  6473. "title" => '清空本次考试的学生',
  6474. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  6475. "operate_method" => $this->action,
  6476. "operate_url" => $this->getRoute(),
  6477. "operate_sql" => json_encode(array('delete'=>array(
  6478. 'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))),
  6479. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  6480. "date"=>date('Y-m-d H:i:j')
  6481. )));
  6482. }
  6483. //发送学生端消息
  6484. foreach ($sendJsonArr as $arr){
  6485. sendStudentCacheQueue($arr);
  6486. }
  6487. echo json_encode(array('status'=>1));exit;
  6488. }
  6489. echo json_encode(array('status'=>0));exit;
  6490. }
  6491. //切换扫描方式
  6492. public function actionChangeScan(){
  6493. $data=array();
  6494. $data['version_number'] =$this->version_number;
  6495. $this->render('change_scan',$data);
  6496. }
  6497. //加载考试信息
  6498. public function actionLoadExamInfo(){
  6499. $exam_group_id=Req::post('exam_group_id');
  6500. $result['status']=0;
  6501. if(!$exam_group_id){
  6502. exit(json_encode($result));
  6503. }
  6504. $examGroup=$this->sConn->createCommand("select teacher_id,mark_type,qxk_paper_id from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
  6505. if(!$examGroup){
  6506. $result['msg']='考试信息不正确';
  6507. exit(json_encode($result));
  6508. }
  6509. $sql="SELECT e.exam_id,e.name,e.tpl_data,c.class_name,e.type FROM `exam` e
  6510. join class c on e.class_id= c.class_id
  6511. where e.exam_group_id='".$exam_group_id."'";
  6512. $examClass=$this->sConn->createCommand($sql)->queryAll();
  6513. $data=array();
  6514. $data['class']='';
  6515. $tplData=array();
  6516. $subject=array(
  6517. 3=>'高考数学',
  6518. 6=>'高三专用',
  6519. 51=>'新高一高二',
  6520. 12=>'物理'
  6521. );
  6522. $topicTypeClass=array(
  6523. 'jie'=>array(8,9,10,11),
  6524. 'tian'=>array(5,6,7),
  6525. 'single'=>array(1,2,12),
  6526. 'multiple'=>array(3,4)
  6527. );
  6528. // '0:线下阅卷、1:按题阅卷、2:按人阅卷、3:班级混合阅卷、4:班级单独阅卷',
  6529. $markType=array(
  6530. 0=>'线下阅卷',1=>'按题阅卷',2=>'按人阅卷',3=>'班级混合阅卷',4=>'班级单独阅卷'
  6531. );
  6532. $typeArr=array(
  6533. 1=>'周考',2=>'单元考',3=>'月考',4=>'联考',5=>'期中',6=>'期末',7=>'高考模拟',8=>'冲刺',
  6534. );
  6535. $data['mark_type']=$markType[$examGroup['mark_type']];
  6536. $subjectId=$this->subjectId;
  6537. if($examClass){
  6538. foreach ($examClass as $val){
  6539. if(!$tplData){
  6540. $json=json_decode($val['tpl_data'],true);
  6541. $tplData['examDate']=$json['examDate'];
  6542. $tplData['subjectId']=$subject[$json['subjectId']];
  6543. $subjectId=$json['subjectId'];
  6544. if(isset($json['textbookId'])){
  6545. $tplData['textbookId']=$json['textbookId'];
  6546. }
  6547. $tplData['qxk']=0;
  6548. $tplData['type']=$typeArr[$val['type']];
  6549. $tplData['author']=$json['author'];
  6550. if($examGroup['qxk_paper_id']>0 && isset($json['new_items'])){
  6551. $tplData['qxk']=1;
  6552. foreach ($json['new_items'] as $item){
  6553. if(in_array($item['basicTopicType'],$topicTypeClass['single'])){
  6554. if(!isset($tplData['select_num'])){
  6555. $tplData['select_num']=1;
  6556. }else{
  6557. $tplData['select_num']++;
  6558. }
  6559. }elseif(in_array($item['basicTopicType'],$topicTypeClass['multiple'])){
  6560. if(!isset($tplData['mult_select_num'])){
  6561. $tplData['mult_select_num']=1;
  6562. }else{
  6563. $tplData['mult_select_num']++;
  6564. }
  6565. }elseif(in_array($item['basicTopicType'],$topicTypeClass['tian'])){
  6566. if(!isset($tplData['tiankong_num'])){
  6567. $tplData['tiankong_num']=1;
  6568. }else{
  6569. $tplData['tiankong_num']++;
  6570. }
  6571. }elseif(in_array($item['basicTopicType'],$topicTypeClass['jie'])){
  6572. if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
  6573. if(!isset($tplData['xuanzuo_num'])){
  6574. $tplData['xuanzuo_num']=1;
  6575. }else{
  6576. $tplData['xuanzuo_num']++;
  6577. }
  6578. }else{
  6579. if(!isset($tplData['jieda_num'])){
  6580. $tplData['jieda_num']=1;
  6581. }else{
  6582. $tplData['jieda_num']++;
  6583. }
  6584. }
  6585. }
  6586. }
  6587. }else{
  6588. if(isset($json['items'][1])){
  6589. $tplData['select_num']=$json['items'][1]['total'];
  6590. }
  6591. if(isset($json['items'][2])){
  6592. $tplData['mult_select_num']=$json['items'][2]['total'];
  6593. }
  6594. if(isset($json['items'][5])){
  6595. $tplData['tiankong_num']=$json['items'][5]['total'];
  6596. }
  6597. if(isset($json['items'][7])){
  6598. $tplData['jieda_num']=$json['items'][7]['total'];
  6599. }
  6600. if(isset($json['items'][17])){
  6601. $tplData['xuanzuo_num']=$json['items'][17]['total'];
  6602. }
  6603. }
  6604. }
  6605. $data['class'].='<span>'.$val['class_name'].'</span>';
  6606. }
  6607. }
  6608. //读取教材
  6609. if(isset($tplData['textbookId']) && $tplData['textbookId']){
  6610. $textBook = $this->apiBrainPost('/textbook/tree', array('subjectId' => $subjectId ));
  6611. if($textBook){
  6612. foreach ($textBook as $value){
  6613. if($tplData['textbookId']==$value->textbook_id){
  6614. $tplData['textBook']=$value->textbook_name;
  6615. }
  6616. }
  6617. }
  6618. }
  6619. $result['status']=1;
  6620. $result['data']=array_merge($data,$tplData);
  6621. exit(json_encode($result));
  6622. }
  6623. //切换扫描方式
  6624. public function actionChangeExamScan(){
  6625. $exam_group_id=Req::post('exam_group_id');
  6626. $result['status']=0;
  6627. if(!$exam_group_id){
  6628. exit(json_encode($result));
  6629. }
  6630. $examGroup=$this->sConn->createCommand("select teacher_id,mark_type from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
  6631. if(!$examGroup){
  6632. $result['msg']='考试信息不正确';
  6633. exit(json_encode($result));
  6634. }
  6635. $exam=$this->sConn->createCommand("select tpl_data from exam where exam_group_id='".$exam_group_id."'")->queryRow();
  6636. $tpl_data=json_decode($exam['tpl_data'],true);
  6637. if(isset($tpl_data['required']) && $tpl_data['required']>1){
  6638. $result['msg']='选做题只支持多选一设置';
  6639. exit(json_encode($result));
  6640. }
  6641. if(isset($tpl_data['items'][17]['required']) && $tpl_data['items'][17]['required']>1){
  6642. $result['msg']='选做题只支持多选一设置';
  6643. exit(json_encode($result));
  6644. }
  6645. $updateSql="update exam_group set is_scan_changed=1 where exam_group_id='".$exam_group_id."'";
  6646. if($this->sConn->createCommand($updateSql)->execute()){
  6647. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow();
  6648. if($thirdAnswerSheet){
  6649. $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id='".$exam_group_id."' ")->execute();
  6650. }
  6651. $this->schoolManager->saveExamProcess($exam_group_id,11,time());
  6652. $result['status']=1;
  6653. }
  6654. exit(json_encode($result));
  6655. }
  6656. //加载考试
  6657. public function actionAjaxSearchExam(){
  6658. $grade=Req::post('grade');
  6659. $class=Req::post('class');
  6660. $condition=array();
  6661. $subject=$this->subjectId;
  6662. $condition[]='eg.is_third=0';
  6663. $condition[]='eg.is_scan_changed=0';
  6664. $condition[]='e.status<>1';
  6665. $condition[]='eg.mark_type<>0';
  6666. // $condition[] = "eg.create_type <>6 ";
  6667. if($subject==3){
  6668. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  6669. }else{
  6670. $condition[]="e.subject_id ='".$subject."'";
  6671. }
  6672. if($grade){
  6673. $condition[]="c.grade='".$grade."'";
  6674. }
  6675. if($class){
  6676. $condition[]="c.class_id='".$class."'";
  6677. }
  6678. $sql="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type,e.is_backlog,e.tpl_index,tas.online_card,tas.is_qrcode_online FROM `exam` e ";
  6679. $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
  6680. $sql.="join class c on c.class_id=e.class_id ";
  6681. $sql.="join paper p on p.exam_id=e.exam_id ";
  6682. $sql.="left join third_answer_sheet tas on tas.exam_group_id=eg.exam_group_id ";
  6683. if($condition){
  6684. $sql.=" where ".implode(' and ',$condition);
  6685. }
  6686. $Exam = $this->sConn->createCommand($sql)->queryAll();
  6687. $list=array();
  6688. if($Exam){
  6689. $paperIds=array();
  6690. $examGroupIds=array();
  6691. foreach($Exam as $key=>$val){
  6692. if( $val['online_card'] && $val['is_qrcode_online']){
  6693. continue;
  6694. }
  6695. $is_custom_tpl=false;
  6696. $paper_tpl_type=0;
  6697. if(in_array($val['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  6698. //自定义模板
  6699. $is_custom_tpl = true;
  6700. }else{
  6701. //非自定义模板
  6702. $is_custom_tpl = false;
  6703. }
  6704. if (in_array($val['tpl_index'], Yii::app()->params['no_template_id']) || $is_custom_tpl) {
  6705. //题卡分离
  6706. $paper_tpl_type = 2;
  6707. }else{
  6708. $paper_tpl_type = 1;
  6709. }
  6710. if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  6711. {
  6712. $paper_tpl_type = 3;
  6713. if($val['tpl_index'] == 9 )
  6714. {
  6715. $paper_tpl_type = 4;
  6716. }
  6717. }
  6718. if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  6719. {
  6720. $paper_tpl_type = 3;
  6721. if($val['tpl_index'] == 9 )
  6722. {
  6723. $paper_tpl_type = 4;
  6724. }
  6725. }
  6726. if (!$is_custom_tpl && $paper_tpl_type != 3){
  6727. continue;
  6728. }
  6729. $tpl_data=json_decode($val['tpl_data'],true);
  6730. if(isset($tpl_data['items'][17])){
  6731. // continue; //选做题过滤
  6732. }
  6733. if($val['is_backlog']==0){
  6734. $examGroupIds[]=$val['exam_group_id'];
  6735. }
  6736. }
  6737. if($class && $examGroupIds){
  6738. $sqlClassCount="SELECT eg.exam_group_id,e.exam_id,e.name,e.tpl_data,eg.is_third,e.`status`,e.subject_id,eg.import_score_type FROM `exam_group` eg ";
  6739. $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id ";
  6740. $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).") order by e.update_time desc";
  6741. $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll();
  6742. foreach ($ExamCount as $val){
  6743. $list[$val['exam_group_id']]=$val;
  6744. }
  6745. }
  6746. }
  6747. $result['status']=1;
  6748. $result['list']=$list;
  6749. exit(json_encode($result));
  6750. }
  6751. //联评卷列表
  6752. public function actionUnited()
  6753. {
  6754. //初始化
  6755. $exam_group_ids = array();
  6756. $exam_ids = array();
  6757. $_exam_ids = array();
  6758. $_exam_group_ids = array();
  6759. $exam_printer_num = array();
  6760. $exam_use_wp = array();
  6761. $data = array();
  6762. $condition = array();
  6763. $paper_exam = array();
  6764. $class_exam = array();
  6765. $class_ids = array();
  6766. $class_grade_arr = array();
  6767. $paper_arr = array();
  6768. //筛选条件
  6769. $printName = Req::get("name");
  6770. $grade = Req::get("grade");
  6771. $labelled = Req::get("labelled");
  6772. $display = Req::get("display");
  6773. $type = Req::get("type");
  6774. // 发送标注条件
  6775. if($labelled>-1)
  6776. {
  6777. $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled);
  6778. if($paper_exam)
  6779. {
  6780. foreach($paper_exam as $v)
  6781. {
  6782. $s_exam_ids[$v['exam_id']] = $v['exam_id'];
  6783. }
  6784. }
  6785. unset($paper_exam);
  6786. }
  6787. // 年级条件
  6788. if($grade>0)
  6789. {
  6790. $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId);
  6791. if($class_data)
  6792. {
  6793. foreach($class_data as $v)
  6794. {
  6795. $class_ids[$v['class_id']] = $v['class_id'];
  6796. }
  6797. $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids);
  6798. if($exam_class_data)
  6799. {
  6800. foreach($exam_class_data as $v)
  6801. {
  6802. if(isset($s_exam_ids[$v['exam_id']]))
  6803. {
  6804. $l_b_exam_ids[$v['exam_id']] = $v['exam_id'];
  6805. }else
  6806. {
  6807. $s_exam_ids[$v['exam_id']] = $v['exam_id'];
  6808. }
  6809. }
  6810. }
  6811. unset($exam_class_data);
  6812. }
  6813. unset($class_data);
  6814. }
  6815. if(isset($l_b_exam_ids))
  6816. {
  6817. if($l_b_exam_ids)
  6818. {
  6819. $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")";
  6820. }else
  6821. {
  6822. $condition[] = "e.exam_id in (0)";
  6823. }
  6824. }else
  6825. {
  6826. if($labelled<0||$grade<1)
  6827. {
  6828. if(isset($s_exam_ids))
  6829. {
  6830. if($s_exam_ids)
  6831. {
  6832. $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")";
  6833. }else
  6834. {
  6835. $condition[] = "e.exam_id in (0)";
  6836. }
  6837. }
  6838. }else
  6839. {
  6840. $condition[] = "e.exam_id in (0)";
  6841. }
  6842. }
  6843. // 多学科切换条件
  6844. if(in_array($this->subjectId,$this->mathSubjectId)){
  6845. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  6846. }else{
  6847. $condition[] = "e.subject_id = '{$this->subjectId}'";
  6848. }
  6849. if ( $display == 1) {
  6850. $condition[] = "e.is_display = 1";
  6851. }else
  6852. {
  6853. $condition[] = "e.is_display = 0";
  6854. }
  6855. // 考试名称条件
  6856. if($printName)
  6857. {
  6858. $condition[] = "e.name like '%{$printName}%'";
  6859. }
  6860. $condition[] = "eg.is_united = 1";
  6861. //获取考试列表
  6862. $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12);
  6863. $branch=array(
  6864. 0=>'不分科',
  6865. 1=>'文科',
  6866. 2=>'理科'
  6867. );
  6868. //获取打印班级
  6869. if($exam_list)
  6870. {
  6871. foreach($exam_list['rs'] as $key=>$v)
  6872. {
  6873. $items = array();
  6874. $tpl_data=array();
  6875. $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
  6876. $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板
  6877. $exam_list['rs'][$key]['is_custom_optional_topic'] = 0;
  6878. $exam_list['rs'][$key]['is_paper_49'] = 0;
  6879. if(isset($v['tpl_data'])){
  6880. $tpl_data = json_decode($v['tpl_data'],1);
  6881. }
  6882. if(isset($tpl_data['branch'])){
  6883. $exam_list['rs'][$key]['branch'] = $tpl_data['branch'];
  6884. }
  6885. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  6886. //自定义模板
  6887. $exam_list['rs'][$key]['is_custom_tpl'] = true;
  6888. if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){
  6889. $exam_list['rs'][$key]['is_custom_optional_topic'] = 1;
  6890. }
  6891. $v['is_custom_tpl'] = true;
  6892. }else{
  6893. //非自定义模板
  6894. $exam_list['rs'][$key]['is_custom_tpl'] = false;
  6895. $v['is_custom_tpl'] = false;
  6896. }
  6897. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  6898. $exam_list['rs'][$key]['is_tpl'] = 1;
  6899. //题卡分离
  6900. $exam_list['rs'][$key]['paper_tpl_type'] = 2;
  6901. }else{
  6902. $exam_list['rs'][$key]['paper_tpl_type'] = 1;
  6903. }
  6904. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  6905. {
  6906. $exam_list['rs'][$key]['paper_tpl_type'] = 3;
  6907. if($v['tpl_index'] == 9 )
  6908. {
  6909. $exam_list['rs'][$key]['paper_tpl_type'] = 4;
  6910. }
  6911. }
  6912. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  6913. {
  6914. $exam_list['rs'][$key]['paper_tpl_type'] = 3;
  6915. if($v['tpl_index'] == 9 )
  6916. {
  6917. $exam_list['rs'][$key]['paper_tpl_type'] = 4;
  6918. }
  6919. }
  6920. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7']))
  6921. {
  6922. $exam_list['rs'][$key]['is_paper_49'] = 1;
  6923. }
  6924. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8']))
  6925. {
  6926. $exam_list['rs'][$key]['is_paper_49'] = 1;
  6927. }
  6928. //题卡合一
  6929. //读取联考文理科
  6930. $united=$this->schoolManager->getUnitedByExamGroupId($v['exam_group_id']);
  6931. if($united){
  6932. $exam_list['rs'][$key]['branch_name']=$branch[$united['branch']];
  6933. }else{
  6934. $exam_list['rs'][$key]['branch_name']='';
  6935. }
  6936. }
  6937. //获取考试ID
  6938. $criteria = new CDbCriteria();
  6939. $criteria->select = 'exam_id,exam_group_id';
  6940. $criteria->addInCondition('exam_group_id',$exam_group_ids);
  6941. $exam_data = Exam::model()->findAll($criteria);
  6942. unset($criteria);
  6943. unset($exam_group_ids);
  6944. if($exam_data)
  6945. {
  6946. foreach($exam_data as $v)
  6947. {
  6948. //$exam_use_wp
  6949. $exam_ids[$v->exam_id] = $v->exam_id;
  6950. $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id;
  6951. $_exam_ids[$v->exam_id] = $v->exam_group_id;
  6952. }
  6953. unset($exam_data);
  6954. //通过考试ID,获取打印班级
  6955. $criteria = new CDbCriteria();
  6956. $criteria->select = 'exam_id,class_id';
  6957. $criteria->addInCondition('exam_id',$exam_ids);
  6958. $criteria->addCondition('is_print = 1');
  6959. $class_print_data = ClassExamPrinter::model()->findAll($criteria);
  6960. if($class_print_data)
  6961. {
  6962. foreach($class_print_data as $v)
  6963. {
  6964. if( isset($_exam_ids[$v->exam_id]))
  6965. {
  6966. $exam_printer_num[$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
  6967. }
  6968. }
  6969. }
  6970. unset($criteria);
  6971. unset($class_print_data);
  6972. }
  6973. }
  6974. //获取班级年级
  6975. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  6976. if($class_data)
  6977. {
  6978. foreach($class_data as $v)
  6979. {
  6980. $class_grade_arr[$v->class_id] = $v->grade;
  6981. }
  6982. }
  6983. unset($class_data);
  6984. //获取试卷标注状态
  6985. $criteria = new CDbCriteria();
  6986. $criteria->select = 'exam_id,is_labelled';
  6987. $criteria->addInCondition('exam_id',$exam_ids);
  6988. $paper_data = SPaper::model()->findAll($criteria);
  6989. unset($criteria);
  6990. if($paper_data)
  6991. {
  6992. foreach($paper_data as $v)
  6993. {
  6994. if( isset($_exam_ids[$v->exam_id]))
  6995. {
  6996. $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled;
  6997. }
  6998. }
  6999. }
  7000. //查询联评卷考试
  7001. $apply_setting_type=1;
  7002. $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
  7003. if($schoolInfo['client']==2){
  7004. $apply_setting_type=0;
  7005. }
  7006. $TaskExam=$this->schoolManager->getUnitedList($apply_setting_type);
  7007. $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id']));
  7008. $data['pages'] = $exam_list['pager'];
  7009. $data['page_total'] = $exam_list['pager']->rowsCount;
  7010. $data['printList'] = $exam_list['rs'];
  7011. $data['printer'] = $exam_printer_num;
  7012. $data['exam_class'] = $_exam_group_ids;
  7013. $data["exam_use_wp"] = $findSchool->use_wp;
  7014. $data["display"] = $display;
  7015. $data["labelled"] = $labelled;
  7016. $data["grade"] = $grade;
  7017. $data["printName"] = $printName;
  7018. $data["paper"] = $paper_arr;
  7019. $data["class_grade"] = $class_grade_arr;
  7020. $data["printType"] = $type;
  7021. $data['task_exam']=$TaskExam;
  7022. $this->render('group_list_united',$data);
  7023. }
  7024. public function actionClass_exam_united()
  7025. {
  7026. $condition = array();
  7027. $exam_ids = array();
  7028. $exam_id = '';
  7029. $exam_name = '';
  7030. $class_names = array();
  7031. $class_ids = array();
  7032. $class_print = array();
  7033. $data = array();
  7034. $exam_student_up_num = array();
  7035. $exam_student_num = array();
  7036. $class_name = Req::get("class_name");
  7037. $exam_group_id = Req::get("exam_group_id");
  7038. $masttype = (int)Req::get("masttype");
  7039. $is_united = (int)Req::get('is_united');
  7040. if($exam_group_id <= 0)
  7041. {
  7042. Yii::app()->jump->error('未找到考试信息!');
  7043. }
  7044. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  7045. if(!$exam_group_data)
  7046. {
  7047. Yii::app()->jump->error('未找到考试信息!');
  7048. }
  7049. $condition[] = "exam_group_id = ".$exam_group_id;
  7050. //获取班级信息
  7051. $class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
  7052. if($class_data)
  7053. {
  7054. foreach($class_data as $v)
  7055. {
  7056. if($class_name && $v['class_name'] == $class_name)
  7057. {
  7058. $class_ids[$v['class_id']] = $v['class_id'];
  7059. }
  7060. $class_names[$v['class_id']] = $v['class_name'];
  7061. }
  7062. }
  7063. if($class_ids)
  7064. {
  7065. $condition[] = "class_id in (".implode(',',$class_ids).") ";
  7066. }
  7067. // 多学科切换条件
  7068. if(in_array($this->subjectId,$this->mathSubjectId)){
  7069. $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")";
  7070. }else{
  7071. $condition[] = "subject_id = '{$this->subjectId}'";
  7072. }
  7073. if($class_ids)
  7074. {
  7075. $condition[] = "class_id in (".implode(',',$class_ids).") ";
  7076. }
  7077. //获取考试列表
  7078. $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12);
  7079. if($exam_data['rs'])
  7080. {
  7081. foreach($exam_data['rs'] as $k=>$v)
  7082. {
  7083. $exam_ids[$v['exam_id']] = $v['exam_id'];
  7084. $exam_id = $v['exam_id'];
  7085. $exam_name = $v['print_name'];
  7086. }
  7087. }else
  7088. {
  7089. Yii::app()->jump->error('未找到考试信息!');
  7090. }
  7091. //查询联考模板
  7092. $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_group_id);
  7093. if(!$task_exam){
  7094. Yii::app()->jump->error('联考数据读取失败!');
  7095. }
  7096. //获取班级考试是否打印
  7097. $criteria = new CDbCriteria();
  7098. $criteria->addInCondition('exam_id',$exam_ids);
  7099. $criteria->addCondition('type = 0');
  7100. $class_print_data = ClassExamPrinter::model()->findAll($criteria);
  7101. if($class_print_data)
  7102. {
  7103. foreach($class_print_data as $v)
  7104. {
  7105. $class_print[$v->exam_id] = $v->is_print;
  7106. }
  7107. }
  7108. unset($criteria);
  7109. unset($class_print_data);
  7110. //获取班级考试的上传成绩
  7111. $criteria = new CDbCriteria();
  7112. $criteria->select= 'student_id,is_feedback,exam_id';
  7113. $criteria->addInCondition('exam_id',$exam_ids);
  7114. $criteria->addCondition('is_del = 0');
  7115. $student_paper_data = SStudentPaperRelation::model()->findAll($criteria);
  7116. unset($exam_ids);
  7117. if($student_paper_data)
  7118. {
  7119. foreach($student_paper_data as $v)
  7120. {
  7121. if($v->is_feedback)
  7122. {
  7123. $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id;
  7124. }
  7125. $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id;
  7126. }
  7127. }
  7128. unset($criteria);
  7129. unset($student_paper_data);
  7130. //获取paper 表数据
  7131. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  7132. if(!$paper_data)
  7133. {
  7134. Yii::app()->jump->error('未找到考试信息!');
  7135. }
  7136. $printList = array();
  7137. if($exam_data["rs"]){
  7138. foreach ($exam_data['rs'] as $k=>$v) {
  7139. $printList['is_tpl'] = 0; // 需要上传模板
  7140. $printList['answer_card_uploaded'] = false;
  7141. if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  7142. //自定义模板
  7143. $printList['is_custom_tpl'] = true;
  7144. $v['is_custom_tpl'] = true;
  7145. }else{
  7146. //非自定义模板
  7147. $printList['is_custom_tpl'] = false;
  7148. $v['is_custom_tpl'] = false;
  7149. }
  7150. if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
  7151. $printList['is_tpl'] = 1;
  7152. if(trim($paper_data->answer_card_src)){
  7153. $printList['answer_card_uploaded'] = true;
  7154. }
  7155. //题卡分离
  7156. $printList['paper_tpl_type'] = 2;
  7157. }else{
  7158. $printList['paper_tpl_type'] = 1;
  7159. }
  7160. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
  7161. {
  7162. $printList['paper_tpl_type'] = 3;
  7163. if($v['tpl_index'] == 9 )
  7164. {
  7165. $printList['paper_tpl_type'] = 4;
  7166. }
  7167. }
  7168. if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
  7169. {
  7170. $printList['paper_tpl_type'] = 3;
  7171. if($v['tpl_index'] == 9 )
  7172. {
  7173. $printList['paper_tpl_type'] = 4;
  7174. }
  7175. }
  7176. //英语题卡分离一
  7177. if($this->subjectId == 8){
  7178. $printList['paper_tpl_type'] = 5;
  7179. }
  7180. }
  7181. }
  7182. // 获取多学科状态
  7183. $this->setIs_new($exam_group_id);
  7184. $data['printList'] = $exam_data['rs'];
  7185. $data['print'] = $printList;
  7186. $data['pages'] = $exam_data['pager'];
  7187. $data['page_total'] = $exam_data['pager']->rowsCount;
  7188. $data["class_name"] = $class_name;
  7189. $data["class_data"] = $class_names;
  7190. $data["exam_group_data"] = $exam_group_data;
  7191. $data["exam_id"] = $exam_id;
  7192. $data["exam_name"] = $exam_name;
  7193. $data["exam_print"] = $class_print;
  7194. $data["exam_student"] = $exam_student_num;
  7195. $data["exam_up_student"] = $exam_student_up_num;
  7196. $data["exam_group_id"] = $exam_group_id;
  7197. $data['task_exam']=$task_exam;
  7198. $this->render('class_exam_united',$data);
  7199. }
  7200. //报名统考列表
  7201. public function actionUnitedTask(){
  7202. $data=array();
  7203. $apply_setting_type=1;
  7204. $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
  7205. if($schoolInfo['client']==2){
  7206. $apply_setting_type=0;
  7207. }
  7208. $TaskExam=$this->schoolManager->getAllUnitedList($apply_setting_type);
  7209. $grade=array(
  7210. 0=>'',
  7211. 1=>'高一',
  7212. 2=>'高二',
  7213. 3=>'高三'
  7214. );
  7215. $branch=array(
  7216. 0=>'不分科',
  7217. 1=>'文科',
  7218. 2=>'理科'
  7219. );
  7220. if($TaskExam){
  7221. foreach ($TaskExam as $key=>$val){
  7222. $TaskExam[$key]['sign_up']=0;
  7223. //查询报名
  7224. $singUpData=$this->schoolManager->getSignUpBySchoolIdTaskId($this->schoolId,$val['task_exam_id']);
  7225. if($singUpData){
  7226. $TaskExam[$key]['sign_up']=1;
  7227. $TaskExam[$key]['mobile']=$singUpData['user_name'].'/'.$singUpData['mobile'];
  7228. }
  7229. $TaskExam[$key]['grade_name']=$grade[$val['grade']];
  7230. $TaskExam[$key]['branch_name']=$branch[$val['branch']];
  7231. }
  7232. }
  7233. $data['task_exam']=$TaskExam;
  7234. $this->render('united_task',$data);
  7235. }
  7236. //报名
  7237. public function actionSignUp(){
  7238. $tk_exam_id = Req::post("exam_group_id");
  7239. $contacts = Req::post('contacts');
  7240. $tel = Req::post('tel');
  7241. $school_id = $this->schoolId;
  7242. $coach_id = Yii::app()->session['coachInfo']['coach_id'];
  7243. $result['status']=0;
  7244. $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id);
  7245. if(!$task_exam){
  7246. $result['msg']="联考信息有误";
  7247. exit(json_encode($result));
  7248. }
  7249. if($task_exam['apply_deadline']<time()){
  7250. $result['msg']="报名已截止";
  7251. exit(json_encode($result));
  7252. }
  7253. $unitedExam=$this->schoolManager->getExamByTaskId($tk_exam_id);
  7254. if($unitedExam){
  7255. $result['msg']="考试已开始,不接受报名啦";
  7256. exit(json_encode($result));
  7257. }
  7258. $signData=$this->schoolManager->getSignUpBySchoolIdTaskId($school_id,$tk_exam_id);
  7259. if($signData){
  7260. $result['msg']="已报名当次联考,不能重复报名";
  7261. exit(json_encode($result));
  7262. }else{
  7263. //学校信息
  7264. $schoolInfo=$this->schoolManager->getSchoolInfo($school_id);
  7265. $insertData=array(
  7266. 'teacher_id'=>$coach_id,
  7267. 'school_id'=>$school_id,
  7268. 'tk_exam_id'=>$tk_exam_id,
  7269. 'user_name'=>$contacts,
  7270. 'mobile'=>$tel,
  7271. 'create_time'=>date('Y-m-d H:i:s'),
  7272. 'school_name'=>$schoolInfo['school_name'],
  7273. 'province_id'=>$schoolInfo['province_id'],
  7274. 'city_id'=>$schoolInfo['city_id'],
  7275. 'area_id'=>$schoolInfo['area_id'],
  7276. 'address'=>$schoolInfo['address']
  7277. );
  7278. if($this->schoolManager->SignUp($insertData)){
  7279. $result['status']=1;
  7280. }
  7281. }
  7282. exit(json_encode($result));
  7283. }
  7284. //取消报名
  7285. public function actionSignOut(){
  7286. $tk_exam_id = Req::post("exam_group_id");
  7287. $school_id = $this->schoolId;
  7288. $result['status']=0;
  7289. $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id);
  7290. if(!$task_exam){
  7291. $result['msg']="联考信息有误";
  7292. exit(json_encode($result));
  7293. }
  7294. if($task_exam['apply_deadline']<time()){
  7295. $result['msg']="报名时间已截止,不能撤消报名";
  7296. exit(json_encode($result));
  7297. }
  7298. $unitedExam=$this->schoolManager->getExamByTaskId($tk_exam_id);
  7299. if($unitedExam){
  7300. $result['msg']="考试已开始,不能撤消报名";
  7301. exit(json_encode($result));
  7302. }
  7303. if($this->schoolManager->SignOutBySchoolIdTaskId($school_id,$tk_exam_id)){
  7304. $result['status']=1;
  7305. }
  7306. exit(json_encode($result));
  7307. }
  7308. // 下载联考答题卡
  7309. public function actionCreate_united_tempelate(){
  7310. $wpcode = Req::post("eid");
  7311. $flag = Req::post("flag");
  7312. $error['success'] = 0;
  7313. if (empty($wpcode)) {
  7314. $error['message'] = '么有周周练id!';
  7315. echo json_encode($error);exit();
  7316. }
  7317. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode));
  7318. //获取本次考试的examids
  7319. $exam_ids = array();
  7320. $getRes=array();
  7321. if($exam_data)
  7322. {
  7323. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  7324. $index_tpl = 0;
  7325. if($exam_group_data)
  7326. {
  7327. foreach($exam_group_data as $v)
  7328. {
  7329. $exam_ids[$v->exam_id] = $v->exam_id;
  7330. $index_tpl = $v->tpl_index;
  7331. }
  7332. }
  7333. $getRes['examGroupId']=$exam_data->exam_group_id;
  7334. //读取联考数据
  7335. $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_data->exam_group_id);
  7336. if(!$task_exam){
  7337. $error['message'] = '联考信息有误!';
  7338. echo json_encode($error);exit();
  7339. }
  7340. $getRes['path']=$task_exam['answer_template_url'];
  7341. if($exam_data['school_card_status']==1){
  7342. $getRes['school_card_status']=1;
  7343. $getRes['school_card_length']=(int)$exam_data['school_card_length'];
  7344. }else{
  7345. $school_card_length = 8;
  7346. if($this->schoolId>999){
  7347. $school_card_length = 9;
  7348. }
  7349. $getRes['school_card_status']=0;
  7350. $getRes['school_card_length']=(int)$school_card_length;
  7351. }
  7352. if(in_array($index_tpl,Yii::app()->params['print_topic_tpl']))
  7353. {
  7354. $flag = 0;
  7355. }
  7356. if($flag==3 || $flag==4 || $flag == 12)
  7357. {
  7358. $criteria = new CDbCriteria();
  7359. $criteria->addInCondition('exam_id',$exam_ids);
  7360. $criteria->addCondition('type=:type');
  7361. $criteria->params[':type'] = 0;
  7362. $getResult = ClassExamPrinter::model()->findAll($criteria);
  7363. if (!empty($getResult)) {
  7364. ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria);
  7365. }
  7366. }
  7367. }
  7368. $data['success']=1;
  7369. $data['object']=$getRes;
  7370. echo json_encode($data);die;
  7371. }
  7372. //晨读词汇全学科获取教材
  7373. public function getQuanTextbook(){
  7374. $result = array();
  7375. $topicDetails = $this->apiBrainPost('/all_textbook/getTextbookBySubjectId', array('subjectId' => 8,'type'=>1), 25, true);
  7376. if($topicDetails && isset($topicDetails['status']) && $topicDetails['status']){
  7377. if(isset($topicDetails['data']) && $topicDetails['data']){
  7378. $result = $topicDetails['data'];
  7379. }
  7380. }
  7381. return $result;
  7382. }
  7383. //晨读词汇全学科获取知识点(暂时用于晨读词汇专题专项)
  7384. public function getQuanKnowledge(){
  7385. $result = array();
  7386. $i=0;
  7387. $data = $this->apiBrainPost('/all_knowledge/tree', array('subjectId' => 8,'isTree'=>1), 25, true);
  7388. if($data && isset($data['status']) && $data['status']){
  7389. if(isset($data['data']) && $data['data']){
  7390. // $result = $data['data'];
  7391. foreach($data['data'] as $level_1){
  7392. if(isset($level_1['child']) && $level_1['child']){
  7393. foreach($level_1['child'] as $level_2){
  7394. if(isset($level_2['knowledge_name']) && $level_2['knowledge_name']=='语法'){
  7395. if(isset($level_2['child']) && $level_2['child']){
  7396. foreach($level_2['child'] as $level_3){
  7397. if(isset($level_3['knowledge_id']) && $level_3['knowledge_id'] && isset($level_3['knowledge_name']) && $level_3['knowledge_name']){
  7398. $result[$i] = array('special_id'=>$level_3['knowledge_id'],'special_name'=>$level_3['knowledge_name'],'items'=>array());
  7399. if(isset($level_3['child']) && $level_3['child']){
  7400. foreach($level_3['child'] as $level_4){
  7401. if(!$level_4['child'] && isset($level_4['knowledge_id']) && $level_4['knowledge_id'] && isset($level_4['knowledge_name']) && $level_4['knowledge_name']){
  7402. $result[$i]['items'][] = array('item_id'=>$level_4['knowledge_id'],'item_name'=>$level_4['knowledge_name']);
  7403. }
  7404. }
  7405. }else{//二级知识点下无三级知识点时,二级补到三级(若专题下无子集时,子集呈现自身)
  7406. $result[$i]['items'][] = array('item_id' => $level_3['knowledge_id'], 'item_name' => $level_3['knowledge_name']);
  7407. }
  7408. $i++;
  7409. }
  7410. }
  7411. }
  7412. }
  7413. }
  7414. }
  7415. }
  7416. }
  7417. }
  7418. return $result;
  7419. }
  7420. //晨读词汇(高三)
  7421. public function actionMrv3(){
  7422. $data = array();
  7423. $time = time();
  7424. $data['year'] = $year = date("Y");
  7425. $data['month'] = $month = (int)date("m");
  7426. $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  7427. $quanTextbookData = $this->getQuanTextbook();
  7428. if($quanTextbookData){
  7429. foreach($quanTextbookData as $k=>$v){
  7430. if(isset($v['textbook_id']) && isset($v['textbook_name'])){
  7431. $data['textbookNames'][$v['textbook_id']] = $v['textbook_name'];
  7432. if(!isset($textbookId)){
  7433. $textbookId = $v['textbook_id'];
  7434. }
  7435. if($textbookId == $v['textbook_id']){
  7436. if(isset($v['child']) && $v['child']){
  7437. foreach($v['child'] as $kk=>$vv){
  7438. $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
  7439. if(!isset($moduleId)){
  7440. $moduleId = $vv['textbook_id'];
  7441. }
  7442. if($moduleId == $vv['textbook_id']){
  7443. if(isset($vv['child']) && $vv['child']){
  7444. foreach($vv['child'] as $kkk=>$vvv){
  7445. $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
  7446. }
  7447. }
  7448. }
  7449. }
  7450. }
  7451. }
  7452. }
  7453. }
  7454. }
  7455. $specialArr = $this->getQuanKnowledge();
  7456. /* 老流程暂时注释
  7457. $textboookTree = new MongodbEnglishTree();
  7458. $criteria = new EMongoCriteria();
  7459. $_textbookData = $textboookTree->find($criteria,array());
  7460. if($_textbookData){
  7461. foreach ($_textbookData as $doc) {
  7462. foreach($doc->attributes as $key => $value){
  7463. if($key !== '_id'){
  7464. if(isset($value['textbook_id']) && isset($value['name'])){
  7465. $data['textbookNames'][$value['textbook_id']] = $value['name'];
  7466. if(!isset($textbookId)){
  7467. $textbookId = $value['textbook_id'];
  7468. }
  7469. if($textbookId == $value['textbook_id']){
  7470. if(isset($value['module']) && $value['module']){
  7471. foreach($value['module'] as $kk=>$vv){
  7472. $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  7473. if(!isset($moduleId)){
  7474. $moduleId = $vv['textbook_module_id'];
  7475. }
  7476. if($moduleId == $vv['textbook_module_id']){
  7477. if(isset($vv['unit']) && $vv['unit']){
  7478. foreach($vv['unit'] as $kkk=>$vvv){
  7479. $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  7480. }
  7481. }
  7482. }
  7483. }
  7484. }
  7485. }
  7486. }
  7487. }
  7488. }
  7489. }
  7490. }
  7491. $textboookTree = new MongodbGrammarSpecial();
  7492. $criteria = new EMongoCriteria();
  7493. $textbookData = $textboookTree->find($criteria,array());
  7494. $specialArr = array();
  7495. if($textbookData){
  7496. foreach ($textbookData as $doc) {
  7497. if ($doc['child']) {
  7498. $item = array();
  7499. foreach ($doc['child'] as $child) {
  7500. $item[] = array(
  7501. 'item_id' => $child['grammar_id'],
  7502. 'item_name' => $child['content'],
  7503. );
  7504. }
  7505. $specialArr[] = array(
  7506. 'special_id' => $doc['_id'],
  7507. 'special_name' => $doc['content'],
  7508. 'items' => $item
  7509. );
  7510. }
  7511. }
  7512. }
  7513. */
  7514. $data['special_arr'] = $specialArr;
  7515. // $data['special_arr'] = array(
  7516. // array(
  7517. // 'special_id' => 1,
  7518. // 'special_name' => '专题1',
  7519. // 'is_selected' => true,
  7520. // 'items' => array(
  7521. // array(
  7522. // 'item_id' => 32,
  7523. // 'item_name' => '专项11',
  7524. // 'is_selected' => true,
  7525. // ),
  7526. // array(
  7527. // 'item_id' => 1232,
  7528. // 'item_name' => '专项10',
  7529. // 'is_selected' => true,
  7530. // ),
  7531. // )
  7532. // ),
  7533. // array(
  7534. // 'special_id' => 2,
  7535. // 'special_name' => '专题2',
  7536. // 'is_selected' => true,
  7537. // 'items' => array(
  7538. // array(
  7539. // 'item_id' => 324,
  7540. // 'item_name' => '专项12',
  7541. // 'is_selected' => true,
  7542. // ),
  7543. // array(
  7544. // 'item_id' => 387,
  7545. // 'item_name' => '专项13',
  7546. // 'is_selected' => true,
  7547. // ),
  7548. // )
  7549. // ),
  7550. // );
  7551. $data['printType'] = 'mrv3';
  7552. $this->render('mrv_3',$data);
  7553. }
  7554. //晨读词汇(高一高二)
  7555. public function actionMrvSetting(){
  7556. $data = array();
  7557. $time = time();
  7558. $data['year'] = $year = date("Y");
  7559. $data['month'] = $month = (int)date("m");
  7560. $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  7561. $quanTextbookData = $this->getQuanTextbook();
  7562. if($quanTextbookData){
  7563. foreach($quanTextbookData as $k=>$v){
  7564. if(isset($v['textbook_id']) && isset($v['textbook_name'])){
  7565. $data['textbookNames'][$v['textbook_id']] = $v['textbook_name'];
  7566. if(!isset($textbookId)){
  7567. $textbookId = $v['textbook_id'];
  7568. }
  7569. if($textbookId == $v['textbook_id']){
  7570. if(isset($v['child']) && $v['child']){
  7571. foreach($v['child'] as $kk=>$vv){
  7572. $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
  7573. if(!isset($moduleId)){
  7574. $moduleId = $vv['textbook_id'];
  7575. }
  7576. if($moduleId == $vv['textbook_id']){
  7577. if(isset($vv['child']) && $vv['child']){
  7578. foreach($vv['child'] as $kkk=>$vvv){
  7579. $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
  7580. }
  7581. }
  7582. }
  7583. }
  7584. }
  7585. }
  7586. }
  7587. }
  7588. }
  7589. /*老流程暂时注释
  7590. $textboookTree = new MongodbEnglishTree();
  7591. $criteria = new EMongoCriteria();
  7592. $textbookData = $textboookTree->find($criteria,array());
  7593. if($textbookData){
  7594. foreach ($textbookData as $doc) {
  7595. foreach($doc->attributes as $key => $value){
  7596. if($key !== '_id'){
  7597. if(isset($value['textbook_id']) && isset($value['name'])){
  7598. $data['textbookNames'][$value['textbook_id']] = $value['name'];
  7599. if(!isset($textbookId)){
  7600. $textbookId = $value['textbook_id'];
  7601. }
  7602. if($textbookId == $value['textbook_id']){
  7603. if(isset($value['module']) && $value['module']){
  7604. foreach($value['module'] as $kk=>$vv){
  7605. $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  7606. if(!isset($moduleId)){
  7607. $moduleId = $vv['textbook_module_id'];
  7608. }
  7609. if($moduleId == $vv['textbook_module_id']){
  7610. if(isset($vv['unit']) && $vv['unit']){
  7611. foreach($vv['unit'] as $kkk=>$vvv){
  7612. $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  7613. }
  7614. }
  7615. }
  7616. }
  7617. }
  7618. }
  7619. }
  7620. }
  7621. }
  7622. }
  7623. }
  7624. */
  7625. $data['printType'] = 'mrv_setting';
  7626. $this->render('mrv_setting',$data);
  7627. }
  7628. //动态获取模块和单元(晨读词汇)
  7629. public function actionAjaxWeekGetModuleAndUnit(){
  7630. $result = array();
  7631. $error = array();
  7632. $textbookId=(int)Req::post('textbookId');
  7633. $quanTextbookData = $this->getQuanTextbook();
  7634. if($quanTextbookData){
  7635. foreach($quanTextbookData as $key => $value){
  7636. if(isset($value['textbook_id']) && isset($value['textbook_name'])){
  7637. if($value['textbook_id'] == $textbookId){
  7638. if(isset($value['child']) && $value['child']){
  7639. foreach($value['child'] as $kk=>$vv){
  7640. $result['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
  7641. if(!isset($moduleId)){
  7642. $moduleId = $vv['textbook_id'];
  7643. }
  7644. if($moduleId == $vv['textbook_id']){
  7645. if(isset($vv['child']) && $vv['child']){
  7646. foreach($vv['child'] as $kkk=>$vvv){
  7647. $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
  7648. }
  7649. }
  7650. }
  7651. }
  7652. }
  7653. }
  7654. }
  7655. }
  7656. }
  7657. echo json_encode($result);exit;
  7658. }
  7659. //动态获取模块和单元
  7660. public function actionAjaxGetModuleAndUnit(){
  7661. $result = array();
  7662. $error = array();
  7663. $textbookId=(int)Req::post('textbookId');
  7664. $textboookTree = new MongodbEnglishTree();
  7665. $criteria = new EMongoCriteria();
  7666. $textbookData = $textboookTree->find($criteria,array());
  7667. if($textbookData && $textbookId){
  7668. foreach ($textbookData as $doc) {
  7669. foreach($doc->attributes as $key => $value){
  7670. if($key !== '_id'){
  7671. if(isset($value['textbook_id']) && isset($value['name'])){
  7672. if($value['textbook_id'] == $textbookId){
  7673. if(isset($value['module']) && $value['module']){
  7674. foreach($value['module'] as $kk=>$vv){
  7675. $result['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  7676. if(!isset($moduleId)){
  7677. $moduleId = $vv['textbook_module_id'];
  7678. }
  7679. if($moduleId == $vv['textbook_module_id']){
  7680. if(isset($vv['unit']) && $vv['unit']){
  7681. foreach($vv['unit'] as $kkk=>$vvv){
  7682. $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  7683. }
  7684. }
  7685. }
  7686. }
  7687. }
  7688. }
  7689. }
  7690. }
  7691. }
  7692. }
  7693. }
  7694. echo json_encode($result);exit;
  7695. }
  7696. //动态获取单元(晨读词汇)
  7697. public function actionAjaxWeekGetUnitByModuleId(){
  7698. $result = array();
  7699. $error = array();
  7700. $textbookId=(int)Req::post('textbookId');
  7701. $moduleId=(int)Req::post('moduleId');
  7702. $quanTextbookData = $this->getQuanTextbook();
  7703. if($quanTextbookData){
  7704. foreach($quanTextbookData as $key => $value){
  7705. if(isset($value['textbook_id']) && isset($value['textbook_name'])){
  7706. if($value['textbook_id'] == $textbookId){
  7707. if(isset($value['child']) && $value['child']){
  7708. foreach($value['child'] as $kk=>$vv){
  7709. if($moduleId == $vv['textbook_id']){
  7710. if(isset($vv['child']) && $vv['child']){
  7711. foreach($vv['child'] as $kkk=>$vvv){
  7712. $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
  7713. }
  7714. }
  7715. }
  7716. }
  7717. }
  7718. }
  7719. }
  7720. }
  7721. }
  7722. echo json_encode($result);exit;
  7723. }
  7724. //动态获取单元
  7725. public function actionAjaxGetUnitByModuleId(){
  7726. $result = array();
  7727. $error = array();
  7728. $textbookId=(int)Req::post('textbookId');
  7729. $moduleId=(int)Req::post('moduleId');
  7730. $textboookTree = new MongodbEnglishTree();
  7731. $criteria = new EMongoCriteria();
  7732. $textbookData = $textboookTree->find($criteria,array());
  7733. if($textbookData && $moduleId && $textbookId){
  7734. foreach ($textbookData as $doc) {
  7735. foreach($doc->attributes as $key => $value){
  7736. if($key !== '_id'){
  7737. if(isset($value['textbook_id']) && isset($value['name'])){
  7738. if($value['textbook_id'] == $textbookId){
  7739. if(isset($value['module']) && $value['module']){
  7740. foreach($value['module'] as $kk=>$vv){
  7741. if($moduleId == $vv['textbook_module_id']){
  7742. if(isset($vv['unit']) && $vv['unit']){
  7743. foreach($vv['unit'] as $kkk=>$vvv){
  7744. $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  7745. }
  7746. }
  7747. }
  7748. }
  7749. }
  7750. }
  7751. }
  7752. }
  7753. }
  7754. }
  7755. }
  7756. echo json_encode($result);exit;
  7757. }
  7758. //获取设置英语个性化学习宝的班级
  7759. public function actionAjaxGetClassesBySettingWeek(){
  7760. $result = array();
  7761. $error = array();
  7762. $grade=(int)Req::post('grade');
  7763. $year = date("Y");
  7764. $month = (int)date("m");
  7765. // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  7766. $week = date("W");
  7767. //获取班级
  7768. $hasSettingClassIds = array();
  7769. $sql = "select class_id,count(*) count from english_week where semester_id = '{$this->semesterId}' and year_num = {$year} and week_num = {$week} group by class_id";
  7770. $data = $this->sConn->createCommand($sql)->queryAll();
  7771. if($data){
  7772. foreach($data as $k=>$v){
  7773. if($v['count'] > 2){
  7774. $hasSettingClassIds[] = (string)$v['class_id'];
  7775. }
  7776. }
  7777. }
  7778. if($grade){
  7779. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0";
  7780. $data = $this->sConn->createCommand($sql)->queryAll();
  7781. if($data){
  7782. $i = 0;
  7783. foreach($data as $k => $v){
  7784. $result[$i]['class_id'] = $v['class_id'];
  7785. $result[$i]['class_name'] = $v['class_name'];
  7786. if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
  7787. $result[$i]['status'] = 1;
  7788. }else{
  7789. $result[$i]['status'] = 0;
  7790. }
  7791. $i++;
  7792. }
  7793. }
  7794. }
  7795. echo json_encode($result);exit;
  7796. }
  7797. //设置高一高二英语个性化学习宝
  7798. public function actionAjaxSaveEnglishWeek(){
  7799. $result = array();
  7800. $error = array();
  7801. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  7802. $error[] = '错误的来源!';
  7803. }else{
  7804. $grade=(int)Req::post('grade');
  7805. $unitIds = (array)Req::post('unitIds');
  7806. $unitNames = (array)Req::post('names');
  7807. $classIds = Req::post('selectClassIds');
  7808. $itemIds = (array)Req::post('selectedItemIds');
  7809. $classIds = array_unique($classIds);
  7810. $wordType = Req::post('wordsType');
  7811. $phraseType = Req::post('phraseType');
  7812. $wordCount = Req::post('wordCount');
  7813. $phraseCount = Req::post('phraseCount');
  7814. $isAnswerSeparate = Req::post('isAnswerSeparate');
  7815. $isSameAnswer = Req::post('isSameAnswer');
  7816. $wordRange = Req::post('wordRange');
  7817. $spellCount = Req::post('spellCount');
  7818. $sentenceCount = Req::post('sentenceCount');
  7819. $isWordDerive = Req::post('isWordDerive');
  7820. $blankCount = Req::post('blankCount');
  7821. $translateCount = Req::post('translateCount');
  7822. $grammarSingleCount = Req::post('grammarSingleCount');
  7823. $grammarSheetCount = Req::post('grammarSheetCount');
  7824. $readingCount = Req::post('readingCount');
  7825. $unitNames = (array)Req::post('names');
  7826. $specialNames = (array)Req::post('specialNames');
  7827. if(in_array($grade,array(1,2))){
  7828. if(empty($unitIds)){$error[] = '请选择单元';}
  7829. if(count($unitIds)>1){$error[] = '已选单元超出限制';}
  7830. }
  7831. if($grade == 3){
  7832. if(empty($unitIds)){$error[] = '请选择单元';}
  7833. if(count($unitIds)>3){$error[] = '已选单元超出限制';}
  7834. }
  7835. if(!$grade){
  7836. $error[] = '请选择年级';
  7837. }
  7838. if(!$classIds){
  7839. $error[] = '请选择班级';
  7840. }
  7841. $wordApply = array(
  7842. 'spell_count' => $spellCount?$sentenceCount:0,
  7843. 'sentence_count' => $sentenceCount?$sentenceCount:0,
  7844. 'blank_count' => $blankCount?$blankCount:0,
  7845. 'translate_count' => $translateCount?$translateCount:0
  7846. );
  7847. }
  7848. if(!$error){
  7849. $time = time();
  7850. $weekIds = array();
  7851. $month = (int)date("m");
  7852. // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  7853. $week = date("W");
  7854. $year = date("Y");
  7855. $strModel = new SStudentClassRelation();
  7856. $transaction = $this->sConn->beginTransaction();
  7857. try{
  7858. if ($grade == 3) {
  7859. $weekName = '高三' . date('Y') . '年第' . date('W') . '周晨读词汇';
  7860. }else{
  7861. $weekName = $unitNames[0] . '晨读词汇';
  7862. }
  7863. $weekGroupId = getUniqueId($this->schoolId);
  7864. foreach($classIds as $k=>$v){
  7865. $weekId = getUniqueId($this->schoolId);
  7866. $weekIds[] = $weekId;
  7867. $this->sConn->createCommand()->insert('english_week_setting',array(
  7868. 'grade' => $grade,
  7869. 'class_id' => $v,
  7870. 'semester_id' => $this->semesterId,
  7871. 'node_ids' => implode(',',$unitIds),
  7872. 'special_ids' => implode(',',$itemIds),
  7873. 'create_time' => $time,
  7874. 'words_type' => $wordType ? $wordType : 1,
  7875. 'phrase_type'=> $phraseType ? $phraseType : 1,
  7876. 'words_count'=> $wordCount ? $wordCount : 0,
  7877. 'phrase_count'=> $phraseCount ? $phraseCount : 0,
  7878. 'is_answer_separate'=>isset($isAnswerSeparate) ? $isAnswerSeparate : 1,
  7879. 'words_range'=>isset($wordRange) ? $wordRange : 1,
  7880. 'is_word_derive'=>isset($isWordDerive) ? $isWordDerive : 1,
  7881. 'words_apply'=>json_encode($wordApply),
  7882. 'is_same_answer' => isset($isSameAnswer)?$isSameAnswer:1,
  7883. 'grammar_single_count' => $grammarSingleCount?$grammarSingleCount:0,
  7884. 'grammar_sheet_count' => $grammarSheetCount?$grammarSheetCount:0,
  7885. 'reading_count' => $readingCount?$readingCount:0,
  7886. 'is_new_version'=>1,
  7887. 'node_names'=>$unitNames ? addslashes(implode(",",$unitNames)) : '',
  7888. 'special_names'=>$specialNames ? implode(",",$specialNames) : ''
  7889. ));
  7890. $set_id = $this->sConn->getLastInsertID();
  7891. $this->sConn->createCommand()->insert('english_week',array(
  7892. 'week_id' => $weekId,
  7893. 'name' => $weekName,
  7894. 'class_id' => $v,
  7895. 'grade' => $grade,
  7896. 'semester_id' => $this->semesterId,
  7897. 'year_num' => $year,
  7898. 'week_num' => $week,
  7899. 'set_id'=>$set_id,
  7900. 'create_time' => $time,
  7901. 'week_group_id' => $weekGroupId,
  7902. 'is_all_html'=>1
  7903. ));
  7904. //获取班级学生
  7905. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  7906. if($stuData){
  7907. foreach($stuData as $kk=>$vv){
  7908. $this->sConn->createCommand()->insert('english_week_student',array(
  7909. 'week_id' => $weekId,
  7910. 'student_id' => $vv['student_id'],
  7911. ));
  7912. }
  7913. $this->sConn->createCommand()->insert('english_week_student',array(
  7914. 'week_id' => $weekId,
  7915. 'student_id' => 0,
  7916. ));
  7917. }
  7918. }
  7919. $transaction->commit();
  7920. }catch(Exception $e){
  7921. $transaction->rollBack();
  7922. if (YII_ENV == 'production') {
  7923. $error[] = '系统错误[SQL]';
  7924. } else {
  7925. $error[] = $e->getMessage();
  7926. }
  7927. }
  7928. }
  7929. if($error){
  7930. echo json_encode(array('status'=>0,'error'=>$error));exit;
  7931. }else{
  7932. //发送消息
  7933. $kafkaData = array(
  7934. 'school_id' => $this->schoolId,
  7935. 'msg_type' => 1,//90:重置 1:新设置
  7936. 'grade' => $grade,
  7937. 'subject_id' => 8,
  7938. 'send_type' => 'english_week',
  7939. 'product_type' => 15,
  7940. 'gp_group_id' => $weekGroupId,//reading_id
  7941. 'gp_ids' => $weekIds,//week_id
  7942. );
  7943. sendDataToKafka("php-product-english-week-html", $kafkaData);
  7944. echo json_encode(array('status'=>1));exit;
  7945. }
  7946. }
  7947. /**
  7948. * 重置晨读词汇
  7949. */
  7950. public function actionResetEnglishWeek(){
  7951. $weekGroupId = (string)Req::get("weekGroupId");
  7952. $data = array();
  7953. $resetCount = 0;
  7954. if($weekGroupId){
  7955. $sql = "select ew.week_id,ew.`name`,ew.class_id,ew.is_reset,c.class_name from english_week ew join class c on ew.class_id = c.class_id where ew.week_group_id = '{$weekGroupId}'";
  7956. $msg = $this->sConn->createCommand($sql)->queryAll();
  7957. if($msg){
  7958. $i=0;
  7959. foreach($msg as $k=>$v){
  7960. if($v["is_reset"]){
  7961. $resetCount++;
  7962. }
  7963. $weekId = $v["week_id"];
  7964. $data[$i]['total_count'] = 0;
  7965. $data[$i]['create_count'] = 0;
  7966. $data[$i]['name'] = $v["name"];
  7967. $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_week_student where student_id > 0 and week_id = '{$weekId}'";
  7968. $msg_student = $this->sConn->createCommand($sql)->queryRow();
  7969. if($msg_student){
  7970. $data[$i]['total_count'] = $msg_student["total_count"];
  7971. $data[$i]['create_count'] = $msg_student["create_count"];
  7972. }
  7973. $data[$i]['week_id'] = $weekId;
  7974. $data[$i]['class_name'] = $v["class_name"];
  7975. $data[$i]['is_reset'] = $v["is_reset"];
  7976. $i++;
  7977. }
  7978. }
  7979. }
  7980. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){
  7981. $resetCount = 0;
  7982. }
  7983. // debug($data);
  7984. $this->render('english_week_reset',array("data"=>$data,"resetCount"=>$resetCount,"weekGroupId"=>$weekGroupId));
  7985. }
  7986. /**
  7987. * 重置外刊美文功能
  7988. */
  7989. public function actionAjaxResetEnglishWeek(){
  7990. $result = array();
  7991. $error = array();
  7992. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  7993. $error[] = '错误的来源!';
  7994. }else{
  7995. $classExam=Req::post('classExam');
  7996. if(!$classExam || !is_array($classExam)){
  7997. $error[] = '请选择班级';
  7998. }
  7999. $redingId=Req::post('readingId');
  8000. if(!$redingId){
  8001. $error[] = '请刷新后再尝试';
  8002. }
  8003. }
  8004. if(!$error){
  8005. $time = time();
  8006. $isNewVersion = 0;
  8007. $transaction = $this->sConn->beginTransaction();
  8008. try{
  8009. $sql = "select week_group_id,week_id,grade,set_id from english_week where week_group_id='{$redingId}' and week_id in (".implode(',',$classExam).")";
  8010. $englishReading = $this->sConn->createCommand($sql)->queryAll();
  8011. if(!$englishReading){
  8012. throw new Exception('无重置晨读词汇推送数据');
  8013. }
  8014. $setId = $englishReading[0]['set_id'];
  8015. $sql = "select is_new_version from english_week_setting where id='{$setId}'";
  8016. $englishSetting = $this->sConn->createCommand($sql)->queryRow();
  8017. if($englishSetting){
  8018. $isNewVersion = $englishSetting['is_new_version'];
  8019. }
  8020. $this->sConn->createCommand("update english_week set is_all_html = 1,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute();
  8021. $sql = "update english_week_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") ";
  8022. $this->sConn->createCommand($sql)->execute();
  8023. //重置后清除已存在的下载任务
  8024. $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=9";
  8025. $this->conn->createCommand($task_sql)->execute();
  8026. $weekIds=array();
  8027. $grade=0;
  8028. foreach($englishReading as $item){
  8029. if($isNewVersion){
  8030. $weekIds[]=$item['week_id'];
  8031. $grade=$item['grade'];
  8032. }
  8033. }
  8034. $transaction->commit();
  8035. }catch(Exception $e){
  8036. $transaction->rollBack();
  8037. if (YII_ENV == 'production') {
  8038. $error[] = '系统错误[SQL]';
  8039. } else {
  8040. $error[] = $e->getMessage();
  8041. }
  8042. }
  8043. }
  8044. if($error){
  8045. echo json_encode(array('status'=>0,'error'=>$error));exit;
  8046. }else{
  8047. //新设置重置才发消息
  8048. if($weekIds && $grade) {
  8049. $kafkaData = array(
  8050. 'school_id' => $this->schoolId,
  8051. 'msg_type' => 90,//90:重置 1:新设置
  8052. 'grade' => $grade,
  8053. 'subject_id' => 8,
  8054. 'send_type' => 'english_week',
  8055. 'product_type' => 15,
  8056. 'gp_group_id' => $redingId,//reading_id
  8057. 'gp_ids' => $weekIds,//week_id
  8058. );
  8059. sendDataToKafka("php-product-english-week-html", $kafkaData);
  8060. }
  8061. echo json_encode(array('status'=>1));exit;
  8062. }
  8063. }
  8064. //晨读词汇列表
  8065. public function actionMrv(){
  8066. Url::clean();
  8067. $data = array();
  8068. $printName = Req::get("name");
  8069. $classId = Req::get("classId");
  8070. $grade = (int)Req::get("grade");
  8071. $newCondition = array();
  8072. if($grade){
  8073. $newCondition[] = 'ew.grade='.$grade;
  8074. }
  8075. if($printName){
  8076. $newCondition[] = 'ew.name like "%'.$printName.'%"';
  8077. }
  8078. if($classId){
  8079. $newCondition[] = 'ew.class_id='.$classId;
  8080. }
  8081. $resultList = $this->schoolManager->getEnglishWeek($newCondition,array('ew.create_time desc','ew.week_id desc'));
  8082. $printList = array();
  8083. if($resultList["rs"]){
  8084. foreach ($resultList['rs'] as $k=>$v) {
  8085. $printList[$k]=$v;
  8086. }
  8087. }
  8088. if (empty($grade)) {
  8089. $grade = 'ALL';
  8090. }
  8091. $classes = $this->schoolManager->getClasses($grade);
  8092. $data['pages'] = $resultList['pager'];
  8093. $data['page_total'] = $resultList['pager']->rowsCount;
  8094. $data['printList'] = $printList;
  8095. $data["printName"] = $printName;
  8096. $data["classes"] = $classes;
  8097. $data["classId"] = $classId;
  8098. $data["grade"] = $grade;
  8099. $data['printType'] = 'mrv';
  8100. // debug($printList);
  8101. $this->render('mrv',$data);
  8102. }
  8103. //设置高三个性化学习宝
  8104. public function actionAjaxSaveEnglishWeekByGrade3(){
  8105. $result = array();
  8106. $error = array();
  8107. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  8108. $error[] = '错误的来源!';
  8109. }else{
  8110. $week=(int)Req::post('week');
  8111. if(!$week){
  8112. $error[] = "请选择周几";
  8113. }
  8114. }
  8115. if(!$error){
  8116. $time = time();
  8117. $sql = "select id from english_week_setting where grade = 3";
  8118. $data = $this->sConn->createCommand($sql)->queryRow();
  8119. if($data){
  8120. $insertStatus = $this->sConn->createCommand()->update("english_week_setting", array("setting_week_num" => $week,"create_time"=>$time),"grade=3");
  8121. }else{
  8122. $insertStatus = $this->sConn->createCommand()->insert('english_week_setting',array(
  8123. 'grade' => 3,
  8124. // 'semester_id' => $this->semesterId,
  8125. 'setting_week_num' => $week,
  8126. 'create_time' => $time,
  8127. ));
  8128. }
  8129. if(!$insertStatus){
  8130. $error[] = '系统错误';
  8131. }
  8132. }
  8133. if($error){
  8134. echo json_encode(array('status'=>0,'error'=>$error));exit;
  8135. }else{
  8136. echo json_encode(array('status'=>1));exit;
  8137. }
  8138. }
  8139. //晨读词汇选择学生
  8140. public function actionSelectStuByMrv(){
  8141. $data = array();
  8142. $sname = (string)Req::get("sname"); //学生名字
  8143. $weekId = (string)Req::get("weekId");
  8144. if(!$weekId){
  8145. Yii::app()->jump->error('参数错误!');
  8146. }
  8147. //获取班级名称以及周后推送名称
  8148. $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from english_week ew join class c on ew.class_id = c.class_id where ew.week_id = '{$weekId}'";
  8149. $names = $this->sConn->createCommand($sql)->queryRow();
  8150. if(!$names){
  8151. $names = array();
  8152. $names['name'] = '';
  8153. $names['class_name'] = '';
  8154. $names['grade'] = 0;
  8155. }else{
  8156. $data['name'] = isset($names['name'])?$names['name']:'';
  8157. }
  8158. $sql = "select student_id,is_week_pdf from english_week_student where week_id = '{$weekId}'";
  8159. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  8160. $studentIds = array();
  8161. $stuIsPdf = array();
  8162. if($relateStudent){
  8163. foreach ($relateStudent as $studentInfo) {
  8164. $studentIds[] = (string)$studentInfo['student_id'];
  8165. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
  8166. }
  8167. }
  8168. if($studentIds){
  8169. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  8170. if($studentNames){
  8171. if($sname){
  8172. $i = 1;
  8173. foreach($studentNames as $k=>$v){
  8174. if(strpos($v,$sname) !== false){
  8175. $data['list'][$i]['stu_id'] = (string)$k;
  8176. $data['list'][$i]['stu_name'] = $v;
  8177. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  8178. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  8179. $i++;
  8180. }
  8181. }
  8182. }else{
  8183. $i = 1;
  8184. foreach($studentNames as $k=>$v){
  8185. $data['list'][$i]['stu_id'] = (string)$k;
  8186. $data['list'][$i]['stu_name'] = $v;
  8187. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  8188. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  8189. $i++;
  8190. }
  8191. }
  8192. }
  8193. }
  8194. $Sem=new SSemester();
  8195. $code= $Sem->conn->createQuery()
  8196. ->from('semester')
  8197. ->where("semester_id = '".$names['semester_id']."'")
  8198. ->limit(1)
  8199. ->query()
  8200. ->read();
  8201. $intarr=array(
  8202. "schoolId"=>$this->schoolId,
  8203. "clazzId"=>$names['class_id'],
  8204. "semester"=>$code['refer_code'],
  8205. "grade"=>$names['grade'],
  8206. "students"=>$studentIds,
  8207. "examTime"=>$names['create_time'],
  8208. "classify"=>3,
  8209. "subject"=>8
  8210. );
  8211. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  8212. $order_classify = ProductDownload::$order_classify;
  8213. $classifies = $order_classify[ProductDownload::PRODUCT_TYPE_EN_MRV];
  8214. $canStudentIds = array();
  8215. foreach ($classifies as $classify) {
  8216. $intarr['classify'] = $classify;
  8217. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  8218. if (!$rs || $rs->errCode != "00") {
  8219. continue;
  8220. }
  8221. if (!empty($rs->data)) {
  8222. $canStudentIds = array_merge($canStudentIds,$rs->data);
  8223. }
  8224. }
  8225. $canStudentIds = array_unique($canStudentIds);
  8226. $data['limitstu'] = $canStudentIds ? $canStudentIds : array();
  8227. $data['weekId'] = $weekId;
  8228. $data['sname'] = $sname;
  8229. $data['printType'] = 'mrv_stu';
  8230. $this->render('mrv_stu',$data);
  8231. }
  8232. //下载晨读词汇个性化学习宝
  8233. public function actionGetEnglishFile(){
  8234. $weekId = (string)Req::get("weekId");
  8235. $studentsIds = (string)Req::get("studentsIds");
  8236. $params = array();
  8237. if(!$weekId){
  8238. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  8239. exit();
  8240. }
  8241. if(!$studentsIds){
  8242. $studentsIds = array();
  8243. $sql = "select student_id from english_week_student where week_id = '{$weekId}' and is_week_pdf = 1";
  8244. $stuArr = $this->sConn->createCommand($sql)->queryAll();
  8245. if($stuArr){
  8246. foreach($stuArr as $k=>$v){
  8247. $studentsIds[] = $v['student_id'];
  8248. }
  8249. }
  8250. }else{
  8251. $studentsIds = explode(',',$studentsIds);
  8252. }
  8253. if(!$studentsIds || empty($studentsIds)){
  8254. echo json_encode(array("success" => 0, "message" => "无生成的学生"));
  8255. exit();
  8256. }
  8257. $params['weekId'] = $weekId;
  8258. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  8259. if(!$apiUrl){
  8260. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  8261. exit();
  8262. }
  8263. $sql = "select class_id,grade,create_time,semester_id from english_week where week_id = '{$weekId}'";
  8264. $msg = $this->sConn->createCommand($sql)->queryRow();
  8265. $Sem=new SSemester();
  8266. $code= $Sem->conn->createQuery()
  8267. ->from('semester')
  8268. ->where("semester_id = '".$msg['semester_id']."'")
  8269. ->limit(1)
  8270. ->query()
  8271. ->read();
  8272. $intarr=array(
  8273. "schoolId"=>$this->schoolId,
  8274. "clazzId"=>$msg['class_id'],
  8275. "semester"=>$code['refer_code'],
  8276. "grade"=>$msg['grade'],
  8277. "students"=>$studentsIds,
  8278. "examTime"=>$msg['create_time'],
  8279. "classify"=>3,
  8280. "subject"=>8
  8281. );
  8282. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  8283. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  8284. if($studentsIds){
  8285. $params["studentIds"] = $studentsIds;
  8286. }
  8287. }else{
  8288. if(Yii::app()->params["limit_open"]){
  8289. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  8290. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  8291. if(!$rs){
  8292. Yii::app()->jump->error("接口错误");
  8293. }
  8294. if($rs->errCode!="00"){
  8295. echo json_encode(array("success" => 0, "message" => $rs->errMsg));
  8296. exit();
  8297. }
  8298. if(!empty($rs->data)){
  8299. $params["studentIds"]=$rs->data;
  8300. if(count($rs->data)<count($intarr['students'])){
  8301. $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
  8302. }
  8303. } else{
  8304. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  8305. exit();
  8306. }
  8307. }else{
  8308. if($studentsIds){
  8309. $params["studentIds"] = $studentsIds;
  8310. }
  8311. }
  8312. }
  8313. $params['schoolId'] = $this->schoolId;
  8314. $params['type'] = 1;
  8315. $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
  8316. if(!($rs = json_decode($rs))){
  8317. $rs = array(
  8318. "success" => 0,
  8319. "message" => "请求接口失败",
  8320. );
  8321. }else{
  8322. //更新下载时间
  8323. if($rs->success==1 || $rs->success==2){
  8324. $time = time();
  8325. if($studentsIds){
  8326. $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).")";
  8327. $this->sConn->createCommand($sql)->execute();
  8328. }
  8329. }
  8330. }
  8331. // if(isset($rs->downloadPath)){
  8332. // if (YII_ENV == 'pro' || YII_ENV == 'production') {
  8333. // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
  8334. // }
  8335. // }
  8336. echo json_encode($rs);exit;
  8337. }
  8338. //月阶段复习列表
  8339. public function actionMainly_revision(){
  8340. Url::clean();
  8341. $data = array();
  8342. $printName = Req::get("name");
  8343. $classId = Req::get("classId");
  8344. $grade = (int)Req::get("grade");
  8345. $newCondition = array();
  8346. if($grade){
  8347. $newCondition[] = 'em.grade='.$grade;
  8348. }
  8349. if($printName){
  8350. $newCondition[] = 'em.name like "%'.$printName.'%"';
  8351. }
  8352. if($classId){
  8353. $newCondition[] = 'em.class_id='.$classId;
  8354. }
  8355. $resultList = $this->schoolManager->getEnglishMonth($newCondition,array('em.create_time desc','em.month_id desc'));
  8356. $printList = array();
  8357. if($resultList["rs"]){
  8358. foreach ($resultList['rs'] as $k=>$v) {
  8359. $printList[$k]=$v;
  8360. }
  8361. }
  8362. if (empty($grade)) {
  8363. $grade = 'ALL';
  8364. }
  8365. $classes = $this->schoolManager->getClasses($grade);
  8366. $data['pages'] = $resultList['pager'];
  8367. $data['page_total'] = $resultList['pager']->rowsCount;
  8368. $data['printList'] = $printList;
  8369. $data["printName"] = $printName;
  8370. $data["classes"] = $classes;
  8371. $data["classId"] = $classId;
  8372. $data["grade"] = $grade;
  8373. $data['printType'] = 'mrv';
  8374. // debug($printList);
  8375. $this->render('mainly_revision',$data);
  8376. }
  8377. //月阶段复习设置
  8378. public function actionSetting_mainly(){
  8379. $data = array();
  8380. $sql = "select setting_month_num from english_month_setting where type = 0";
  8381. $result = $this->sConn->createCommand($sql)->queryRow();
  8382. if($result){
  8383. $data['chooseMonth'] = $result['setting_month_num'];
  8384. }else{
  8385. $data['chooseMonth'] = 1;
  8386. }
  8387. $data['printType'] = 'mrv_3';
  8388. $this->render('setting_mainly',$data);
  8389. }
  8390. //月阶段复习设置
  8391. public function actionAjaxSaveEnglishMonthMainly(){
  8392. $result = array();
  8393. $error = array();
  8394. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  8395. $error[] = '错误的来源!';
  8396. }else{
  8397. $week=(int)Req::post('week');
  8398. if(!$week){
  8399. $error[] = "请选择周几";
  8400. }
  8401. }
  8402. if(!$error){
  8403. $time = time();
  8404. $sql = "select id from english_month_setting where type = 0";
  8405. $data = $this->sConn->createCommand($sql)->queryRow();
  8406. if($data){
  8407. $insertStatus = $this->sConn->createCommand()->update("english_month_setting", array("setting_month_num" => $week,"create_time"=>$time),"type=0");
  8408. }else{
  8409. $insertStatus = $this->sConn->createCommand()->insert('english_month_setting',array(
  8410. 'type' => 0,
  8411. 'setting_month_num' => $week,
  8412. 'create_time' => $time,
  8413. ));
  8414. }
  8415. if(!$insertStatus){
  8416. $error[] = '系统错误';
  8417. }
  8418. }
  8419. if($error){
  8420. echo json_encode(array('status'=>0,'error'=>$error));exit;
  8421. }else{
  8422. echo json_encode(array('status'=>1));exit;
  8423. }
  8424. }
  8425. //下载英语月阶段复习
  8426. public function actionGetEnglishFileMonth(){
  8427. $monthId = (string)Req::get("monthId");
  8428. $studentsIds = (string)Req::get("studentsIds");
  8429. $params = array();
  8430. if(!$monthId){
  8431. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  8432. exit();
  8433. }
  8434. if(!$studentsIds){
  8435. $studentsIds = array();
  8436. $sql = "select student_id from english_month_student where month_id = '{$monthId}' and is_month_pdf = 1";
  8437. $stuArr = $this->sConn->createCommand($sql)->queryAll();
  8438. if($stuArr){
  8439. foreach($stuArr as $k=>$v){
  8440. $studentsIds[] = $v['student_id'];
  8441. }
  8442. }
  8443. }else{
  8444. $studentsIds = explode(',',$studentsIds);
  8445. }
  8446. if(!$studentsIds || empty($studentsIds)){
  8447. echo json_encode(array("success" => 0, "message" => "无生成的学生"));
  8448. exit();
  8449. }
  8450. $params['monthId'] = $monthId;
  8451. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  8452. if(!$apiUrl){
  8453. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  8454. exit();
  8455. }
  8456. $sql = "select class_id,grade,create_time,semester_id from english_month where month_id = '{$monthId}'";
  8457. $msg = $this->sConn->createCommand($sql)->queryRow();
  8458. $Sem=new SSemester();
  8459. $code= $Sem->conn->createQuery()
  8460. ->from('semester')
  8461. ->where("semester_id = '".$msg['semester_id']."'")
  8462. ->limit(1)
  8463. ->query()
  8464. ->read();
  8465. $intarr=array(
  8466. "schoolId"=>$this->schoolId,
  8467. "clazzId"=>$msg['class_id'],
  8468. "semester"=>$code['refer_code'],
  8469. "grade"=>$msg['grade'],
  8470. "students"=>$studentsIds,
  8471. "examTime"=>$msg['create_time'],
  8472. "classify"=>3,
  8473. "subject"=>8
  8474. );
  8475. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  8476. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  8477. if($studentsIds){
  8478. $params["studentIds"] = $studentsIds;
  8479. }
  8480. }else{
  8481. if(Yii::app()->params["limit_open"]){
  8482. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  8483. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  8484. if(!$rs){
  8485. Yii::app()->jump->error("接口错误");
  8486. }
  8487. if($rs->errCode!="00"){
  8488. echo json_encode(array("success" => 0, "message" => $rs->errMsg));
  8489. exit();
  8490. }
  8491. if(!empty($rs->data)){
  8492. $params["studentIds"]=$rs->data;
  8493. if(count($rs->data)<count($intarr['students'])){
  8494. $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
  8495. }
  8496. } else{
  8497. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  8498. exit();
  8499. }
  8500. }else{
  8501. if($studentsIds){
  8502. $params["studentIds"] = $studentsIds;
  8503. }
  8504. }
  8505. }
  8506. $params['schoolId'] = $this->schoolId;
  8507. $params['type'] = 2;
  8508. $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
  8509. if(!($rs = json_decode($rs))){
  8510. $rs = array(
  8511. "success" => 0,
  8512. "message" => "请求接口失败",
  8513. );
  8514. }else{
  8515. //更新下载时间
  8516. if($rs->success==1 || $rs->success==2){
  8517. $time = time();
  8518. if($studentsIds){
  8519. $sql = "update english_month_student set is_download = 1,download_time={$time} where month_id = '{$monthId}' and student_id in (".implode(',',$studentsIds).")";
  8520. $this->sConn->createCommand($sql)->execute();
  8521. }
  8522. }
  8523. }
  8524. // if(isset($rs->downloadPath)){
  8525. // if (YII_ENV == 'pro' || YII_ENV == 'production') {
  8526. // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
  8527. // }
  8528. // }
  8529. echo json_encode($rs);exit;
  8530. }
  8531. //月阶段复习选择学生
  8532. public function actionSelectStuByMainly(){
  8533. $data = array();
  8534. $sname = (string)Req::get("sname"); //学生名字
  8535. $monthId = (string)Req::get("monthId");
  8536. if(!$monthId){
  8537. Yii::app()->jump->error('参数错误!');
  8538. }
  8539. //获取班级名称以及周后推送名称
  8540. $sql = "select em.name,c.class_name,em.grade,em.class_id,em.create_time,em.semester_id from english_month em join class c on em.class_id = c.class_id where em.month_id = '{$monthId}'";
  8541. $names = $this->sConn->createCommand($sql)->queryRow();
  8542. if(!$names){
  8543. $names = array();
  8544. $names['name'] = '';
  8545. $names['class_name'] = '';
  8546. $names['grade'] = 0;
  8547. }else{
  8548. $data['name'] = isset($names['name'])?$names['name']:'';
  8549. }
  8550. $sql = "select student_id,is_month_pdf from english_month_student where month_id = '{$monthId}'";
  8551. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  8552. $studentIds = array();
  8553. $stuIsPdf = array();
  8554. if($relateStudent){
  8555. foreach ($relateStudent as $studentInfo) {
  8556. $studentIds[] = (string)$studentInfo['student_id'];
  8557. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_month_pdf'];
  8558. }
  8559. }
  8560. if($studentIds){
  8561. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  8562. if($studentNames){
  8563. if($sname){
  8564. $i = 1;
  8565. foreach($studentNames as $k=>$v){
  8566. if(strpos($v,$sname) !== false){
  8567. $data['list'][$i]['stu_id'] = (string)$k;
  8568. $data['list'][$i]['stu_name'] = $v;
  8569. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  8570. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  8571. $i++;
  8572. }
  8573. }
  8574. }else{
  8575. $i = 1;
  8576. foreach($studentNames as $k=>$v){
  8577. $data['list'][$i]['stu_id'] = (string)$k;
  8578. $data['list'][$i]['stu_name'] = $v;
  8579. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  8580. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  8581. $i++;
  8582. }
  8583. }
  8584. }
  8585. }
  8586. $Sem=new SSemester();
  8587. $code= $Sem->conn->createQuery()
  8588. ->from('semester')
  8589. ->where("semester_id = '".$names['semester_id']."'")
  8590. ->limit(1)
  8591. ->query()
  8592. ->read();
  8593. $intarr=array(
  8594. "schoolId"=>$this->schoolId,
  8595. "clazzId"=>$names['class_id'],
  8596. "semester"=>$code['refer_code'],
  8597. "grade"=>$names['grade'],
  8598. "students"=>$studentIds,
  8599. "examTime"=>$names['create_time'],
  8600. "classify"=>3,
  8601. "subject"=>8
  8602. );
  8603. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  8604. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  8605. if(!$rs){
  8606. Yii::app()->jump->error("接口错误");
  8607. }
  8608. if($rs->errCode!="00"){
  8609. Yii::app()->jump->error($rs->errMsg);
  8610. }
  8611. if(!empty($rs->data)){
  8612. $data['limitstu']=$rs->data;
  8613. }
  8614. $data['monthId'] = $monthId;
  8615. $data['sname'] = $sname;
  8616. $data['printType'] = 'mrv_stu';
  8617. $this->render('mainly_stu',$data);
  8618. }
  8619. //生成模板
  8620. public function actionAjaxCreateTemplate(){
  8621. $eId = Req::post('exam_id');
  8622. if(!$eId){
  8623. exit(json_encode(array("status"=>0,"result"=>"考试ID不能为空")));
  8624. }
  8625. //调用java生成模板接口
  8626. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  8627. $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/generate-fixed-template/'.$eId;
  8628. $rs = $this->CrmApiPost($url,array(),$this->schoolId,$password);
  8629. //操作日志
  8630. if(Yii::app()->params['handle_log_on_off'])
  8631. {
  8632. writeFileLog(jsonEncode(array(
  8633. "exam_group_id" => '',
  8634. "operate_project" => 'zsyas2',
  8635. "title" => '一键生成',
  8636. "school_id" => $this->schoolId,
  8637. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  8638. "operate_method" => $this->action,
  8639. "operate_url" => $url,
  8640. "operate_sql" => '',
  8641. "operate_param" =>json_encode(array('params'=>array('examId'=>$eId),'rs'=>$rs)),
  8642. "date"=>date('Y-m-d H:i:j')
  8643. )));
  8644. }
  8645. if(isset($rs->errCode) && $rs->errCode =='00')
  8646. {
  8647. echo json_encode(array('status'=>1,'result'=>$rs->errMsg));exit;
  8648. }
  8649. $errMsg = '生成失败';
  8650. if(isset($rs->errMsg))
  8651. {
  8652. $errMsg = $rs->errMsg;
  8653. }
  8654. echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
  8655. }
  8656. public function actionAjaxPrintPaper(){
  8657. $exam_id = Req::post("exam_id");
  8658. $student_id = Req::post("student_id");
  8659. if(!$exam_id ) {
  8660. echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
  8661. }
  8662. if(empty($student_id) ) {
  8663. echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生"));
  8664. }
  8665. $studentIds = explode(',',$student_id);
  8666. foreach ($studentIds as $v)
  8667. {
  8668. if($v)
  8669. {
  8670. $student_ids[] = $v;
  8671. }
  8672. }
  8673. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  8674. $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/download-fixed-template';
  8675. $start = time();
  8676. $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password);
  8677. $endTime = time();
  8678. //操作日志
  8679. if(Yii::app()->params['handle_log_on_off'])
  8680. {
  8681. writeFileLog(jsonEncode(array(
  8682. "exam_group_id" => '',
  8683. "operate_project" => 'zsyas2',
  8684. "title" => '批量打印',
  8685. "school_id" => $this->schoolId,
  8686. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  8687. "operate_method" => $this->action,
  8688. "operate_url" => $url,
  8689. "operate_sql" => '',
  8690. "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids,'time'=>($endTime-$start)),'rs'=>$rs)),
  8691. "date"=>date('Y-m-d H:i:j')
  8692. )));
  8693. }
  8694. if(isset($rs->errCode) && $rs->errCode =='00')
  8695. {
  8696. ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  8697. echo json_encode(array('status'=>1,'result'=>$rs->data));exit;
  8698. }
  8699. $errMsg = '下载失败';
  8700. if(isset($rs->errMsg))
  8701. {
  8702. $errMsg = $rs->errMsg;
  8703. }
  8704. echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
  8705. }
  8706. //打印试卷和第三方试卷添加班级
  8707. public function actionAddExamClass()
  8708. {
  8709. $classId=Req::post('classId');
  8710. $exam_group_id=Req::post('eid');
  8711. $is_third = Req::post('is_third');
  8712. $result['status']=0;
  8713. if(!$exam_group_id || !$classId || !is_array($classId)){
  8714. $result['msg']='数据异常';
  8715. exit(json_encode($result));
  8716. }
  8717. //防止重复操作
  8718. $redis_add_class_status = Yii::app()->add_exam_class->hmget('temp:exam_class_mark_'.$exam_group_id,array('status'));
  8719. if($redis_add_class_status && $redis_add_class_status[0]){
  8720. echo json_encode(array('status'=>0,'msg'=>'操作频繁,请稍后再试'));
  8721. exit;
  8722. }else{
  8723. Yii::app()->add_exam_class->hmset('temp:exam_class_mark_'.$exam_group_id,array('status'=>1));
  8724. Yii::app()->add_exam_class->expire('temp:exam_class_mark_'.$exam_group_id,30);
  8725. }
  8726. $examClass=array(); //原考试班级
  8727. $neeAddClass=array(); //需要增加的班级
  8728. $time=time();
  8729. $allExamIds=array(); //所有考试id,用于判断考试订单
  8730. //获取考试ID
  8731. $criteria = new CDbCriteria();
  8732. $criteria->select = 'exam_id,exam_group_id,class_id';
  8733. $criteria->addCondition("exam_group_id='".$exam_group_id."'");
  8734. $exam_data = Exam::model()->findAll($criteria);
  8735. unset($criteria);
  8736. if($exam_data)
  8737. {
  8738. foreach($exam_data as $v)
  8739. {
  8740. $exam_ids[] = $v->exam_id;
  8741. $examClass[] = (string)$v->class_id;
  8742. }
  8743. foreach ($examClass as $key => $val){
  8744. if(in_array((string)$val,$classId,true)){
  8745. unset($classId[array_search((string)$val,$classId,true)]);
  8746. }
  8747. }
  8748. if($classId){
  8749. $neeAddClass= $classId;
  8750. }
  8751. $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length,is_fine_paper,is_fine_edit from exam where exam_id='".$exam_ids[0]."' ")->queryRow();
  8752. $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
  8753. $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status,labelled_type,send_labelled_time,finish_labelled_time from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow();
  8754. $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']);
  8755. $paperLargeTopics = $this->schoolManager->getPaperLargeTopicsRecords($papers[0]['paper_id']);
  8756. //增加班级
  8757. $needAddExamId=array();
  8758. if($neeAddClass){
  8759. $transaction = $this->sConn->beginTransaction();
  8760. try {
  8761. //单独阅卷 添加exam_group表数据
  8762. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  8763. //FIXME 2019-10-23 单独阅卷&旧版阅卷 才添加marking_group记录
  8764. if( $exam_group_data['mark_type'] == 4 && $exam_group_data['is_new_marking']==0) {
  8765. $i = 1;
  8766. foreach ($paperTopics as $paperTopic) {
  8767. if (!in_array($paperTopic['type'], array(1, 2, 11))) {
  8768. $marking_group_id =getUniqueId($this->schoolId);
  8769. foreach ($neeAddClass as $classId) {
  8770. $sql = "select marking_group_id from marking_group where exam_group_id = '{$exam_group_id}' AND class_id = {$classId} AND topic_id = {$paperTopic['topic_id']}";
  8771. $data = $this->sConn->createCommand($sql)->queryRow();
  8772. if (!$data) {
  8773. $this->sConn->createCommand()->insert('marking_group', array(
  8774. 'exam_group_id' => $exam_group_id,
  8775. 'marking_group_id' => $marking_group_id,
  8776. 'class_id' => $classId,
  8777. 'topic_id' => $paperTopic['topic_id'],
  8778. 'topic_type' => $paperTopic['type'],
  8779. 'topic_index' => $i,
  8780. 'topic_score' => $paperTopic['score']
  8781. ));
  8782. }
  8783. }
  8784. }
  8785. $i++;
  8786. }
  8787. }
  8788. $allStudentIds=array();
  8789. $allTeacherIds=array();
  8790. foreach ($neeAddClass as $classId) {
  8791. $newExamId = getUniqueId($this->schoolId);
  8792. $needAddExamId[]=$newExamId;
  8793. $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll();
  8794. $studentIds=array();
  8795. if($studentIdData){
  8796. foreach ($studentIdData as $datum){
  8797. $studentIds[]=$datum['student_id'];
  8798. }
  8799. }
  8800. //校验是否已存在重复学生
  8801. if($studentIds){
  8802. $checkRepeatStudent=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$exam_ids).") and student_id in(".implode(',',$studentIds).") and is_del=0")->queryRow();
  8803. if($checkRepeatStudent){
  8804. $checkStudentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$checkRepeatStudent['student_id']}'")->queryRow();
  8805. echo json_encode(array('status'=>0,'msg'=>$checkStudentInfo['realname'].'('.$checkStudentInfo['realname'].')已参加本场考试,请勿重复添加'));
  8806. exit;
  8807. }
  8808. }
  8809. $allStudentIds=array_merge($allStudentIds,$studentIds);
  8810. //if(!$studentIds) continue;
  8811. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  8812. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  8813. //添加考试
  8814. $status=3;
  8815. if($exam_group_data->homework==0 && $is_third==1){
  8816. $status=2;
  8817. }else{
  8818. $status=3;
  8819. }
  8820. $this->sConn->createCommand()->insert('exam', array(
  8821. 'exam_id' => $newExamId,
  8822. 'exam_group_id' => $exam_group_id,
  8823. 'name' => $examDetail['name'],
  8824. 'subject_id' => $examDetail['subject_id'],
  8825. 'semester_id' => $examDetail['semester_id'],
  8826. 'teacher_id' => $examDetail['teacher_id'],
  8827. 'module_id' => $examDetail['module_id'],
  8828. 'type' => $examDetail['type'],
  8829. 'status' => $status,
  8830. 'week_num' => $examDetail['week_num'],
  8831. 'create_type' => $examDetail['create_type'],
  8832. 'create_time' => $examDetail['create_time'],
  8833. 'update_time' => $examDetail['update_time'],
  8834. 'tpl_index' => $examDetail['tpl_index'],
  8835. 'tpl_data' => $examDetail['tpl_data'],
  8836. 'class_id' => $classId,
  8837. 'method_ids' => $examDetail['method_ids'],
  8838. 'from_exam_id' => $examDetail['from_exam_id'],
  8839. 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0,
  8840. 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0,
  8841. 'is_fine_paper' => $examDetail['is_fine_paper'],
  8842. 'is_fine_edit' => $examDetail['is_fine_edit'],
  8843. // 'is_third' =>$examDetail['is_third']
  8844. ));
  8845. //添加试卷
  8846. $newPaperId = getUniqueId($this->schoolId);
  8847. $this->sConn->createCommand()->insert('paper', array(
  8848. 'paper_id' => $newPaperId,
  8849. 'paper_type' => $paperDetail['paper_type'],
  8850. 'exam_id' => $newExamId,
  8851. 'paper_name' => "",
  8852. 'paper_layer' => $paperDetail['paper_layer'],
  8853. 'difficulty' => $paperDetail['difficulty'],
  8854. 'topics_count' => $paperDetail['topics_count'],
  8855. 'score' => $paperDetail['score'],
  8856. 'add_time' => $paperDetail['add_time'],
  8857. 'update_time' => $paperDetail['update_time'],
  8858. 'method_ids' => $paperDetail['method_ids'],
  8859. 'is_labelled' => $paperDetail['is_labelled'],
  8860. 'labelled_type' => $paperDetail['labelled_type'],
  8861. 'send_labelled_time' => $paperDetail['send_labelled_time'],
  8862. 'finish_labelled_time' => $paperDetail['finish_labelled_time'],
  8863. 'status' => $paperDetail['status']
  8864. ));
  8865. if ($studentIds_0) {
  8866. foreach ($studentIds_0 as $studentId) {
  8867. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  8868. // if($studentIds){
  8869. // foreach ($studentIds as $studentId) {
  8870. $this->sConn->createCommand()->insert('student_paper_relation', array(
  8871. 'student_id' => $studentId,
  8872. 'paper_id' => $newPaperId,
  8873. 'exam_id' => $newExamId,
  8874. 'semester_id' => $this->semesterId,
  8875. 'class_id' => $classId,
  8876. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  8877. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  8878. ));
  8879. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  8880. 'student_id' => $studentId,
  8881. 'paper_id' => $newPaperId,
  8882. 'exam_id' => $newExamId,
  8883. 'semester_id' => $this->semesterId,
  8884. 'class_id' => $classId,
  8885. 'create_time'=>time(),
  8886. ));
  8887. }
  8888. }
  8889. foreach ($paperTopics as $paperTopic) {
  8890. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  8891. 'paper_id' => $newPaperId,
  8892. 'stem_id' => $paperTopic['stem_id'],
  8893. 'topic_id' => $paperTopic['topic_id'],
  8894. 'no' => $paperTopic['order'],
  8895. 'order' => $paperTopic['order'],
  8896. 'mode' => (int)$paperTopic['mode'],
  8897. 'type' => $paperTopic['type'],
  8898. 'score' => $paperTopic['score'],
  8899. 'question_count' => $paperTopic['question_count'],
  8900. 'question_score_str' => $paperTopic['question_score_str'],
  8901. 'method_ids' => $paperTopic['method_ids'],
  8902. 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2,
  8903. 'template_id' => $paperTopic['template_id'],
  8904. 'is_template' => $paperTopic['is_template'],
  8905. 'is_delete' => $paperTopic['is_delete'],
  8906. 'topic_from' => $paperTopic['topic_from'],
  8907. 'logic_type'=>$paperTopic['logic_type'],
  8908. ));
  8909. $this->sConn->createCommand()->insert('topic_use', array(
  8910. 'topic_id' => $paperTopic['topic_id'],
  8911. 'mode' => $paperTopic['mode'],
  8912. 'teacher_id' => $examDetail['teacher_id'],
  8913. ));
  8914. }
  8915. foreach ($paperLargeTopics as $paperLargeTopic){
  8916. $this->sConn->createCommand()->insert('paper_topic_large', array(
  8917. 'paper_id' => $newPaperId,
  8918. 'large_topic_id' => $paperLargeTopic['large_topic_id'],
  8919. 'topic_no' => $paperLargeTopic['topic_no'],
  8920. 'logic_type' => $paperLargeTopic['logic_type'],
  8921. 'logic_type_second' => $paperLargeTopic['logic_type_second'],
  8922. 'method_ids' => $paperLargeTopic['method_ids'],
  8923. ));
  8924. }
  8925. $this->sConn->createCommand()->insert('class_exam_printer', array(
  8926. 'class_id' => $classId,
  8927. 'exam_id' => $newExamId,
  8928. 'type' => 0,
  8929. 'is_print' => 0,
  8930. 'print_time' => 0,
  8931. 'add_time' => $time,
  8932. ));
  8933. }
  8934. if($exam_group_data['homework']==1){
  8935. $tplData=json_decode($examDetail['tpl_data'],1);
  8936. $teachers=$this->schoolManager->getTeachersByClassesIds($neeAddClass);
  8937. $allStudentIds=array_values($allStudentIds);
  8938. $studentReceiverList=array();
  8939. foreach ($allStudentIds as $val){
  8940. $studentReceiverList[(string)$val]=$val;
  8941. }
  8942. $studentReceiverList=array_values($studentReceiverList);
  8943. $studentNotice[]=array(
  8944. 'app'=>0,
  8945. 'templateId'=>2,
  8946. 'templateParams'=>array($examDetail['name']),
  8947. 'userIds'=>$studentReceiverList
  8948. );
  8949. if(isset($tplData['startline'])){
  8950. $studentNotice['dateTime']=date('Y-m-d H:i:s',strtotime($tplData['startline']));
  8951. }
  8952. foreach ($teachers as $val){
  8953. if(!isset($receiverList[(string)$val['teacher_id']])){
  8954. $receiverList[(string)$val['teacher_id']]=$val['teacher_id'];
  8955. }
  8956. }
  8957. $receiverList=array_values($receiverList);
  8958. $teacherNotice=array(
  8959. 'app'=>1,
  8960. 'templateId'=>1,
  8961. 'templateParams'=>array($examDetail['name']),
  8962. 'userIds'=>$receiverList
  8963. );
  8964. sendDataToKafka('send_message_center',$studentNotice);
  8965. sendDataToKafka('send_message_center',$teacherNotice);
  8966. sendAppNotify($studentNotice);
  8967. sendAppNotify($teacherNotice);
  8968. }
  8969. //数学标注
  8970. $updateLabelledRs='';
  8971. $orderType=array();
  8972. if($exam_group_data['qxk_paper_id']>0 && in_array($examDetail['subject_id'],$this->mathSubjectId) && ($exam_group_data['is_tagging']>0 || $paperDetail['labelled_type']>0)){
  8973. //需要重新查询订单
  8974. $allExamIds=array_merge($exam_ids,$needAddExamId);
  8975. $orderType = $this->checkProductOrderDetail($exam_group_id, $examDetail['subject_id'], array(31, 1, 2, 3,66),$allExamIds);
  8976. if($orderType==-1){
  8977. $error['msg'] = '订单接口异常';
  8978. $error['status']=0;
  8979. echo json_encode($error);exit();
  8980. }elseif($orderType==-2){
  8981. $error['msg'] = '考试参数异常,检查班级中是否添加学生';
  8982. $error['status']=0;
  8983. echo json_encode($error);exit();
  8984. }
  8985. if($orderType){
  8986. $updateLabelledRs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_task_data', array(
  8987. "examGroupId" => (string)$exam_group_id,
  8988. 'productOrderType'=>$orderType
  8989. ));
  8990. $updateLabelledData=json_decode($updateLabelledRs,true);
  8991. if($updateLabelledData['success']==1){
  8992. //判断标注完成状态是否需要更新
  8993. if($exam_group_data['is_tagging']==1 || $paperDetail['is_labelled']==1){
  8994. $needUpdateIsTagging=0;
  8995. $needUpdateLabelled=0;
  8996. foreach ($orderType as $item){
  8997. if($item['goodsTypeId']==31){
  8998. $needUpdateIsTagging=1;
  8999. }
  9000. if(in_array($item['goodsTypeId'],array(1,2,3,66))){
  9001. $needUpdateLabelled=1;
  9002. }
  9003. }
  9004. if($needUpdateIsTagging && $exam_group_data['is_tagging']!=1){
  9005. $this->sConn->createCommand("update exam_group set is_tagging=1 where exam_group_id='{$exam_group_id}'")->execute();
  9006. }
  9007. if($needUpdateLabelled && $paperDetail['is_labelled']!=1){
  9008. $this->sConn->createCommand("update paper set is_labelled=1 where exam_id in(".implode(',',$allExamIds).")")->execute();
  9009. }
  9010. }
  9011. }
  9012. }
  9013. }
  9014. //操作日志
  9015. if(Yii::app()->params['handle_log_on_off'])
  9016. {
  9017. writeFileLog(jsonEncode(array(
  9018. "exam_group_id" => (string)$exam_group_id,
  9019. "operate_project" => 'zsyas2',
  9020. "title" => '添加删除班级',
  9021. "school_id" => $this->schoolId,
  9022. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  9023. "operate_method" => $this->action,
  9024. "operate_url" => $this->getRoute(),
  9025. "operate_sql" => '',
  9026. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  9027. "date"=>date('Y-m-d H:i:s'),
  9028. "update_label_rs"=>$updateLabelledRs,
  9029. 'order_type'=>$orderType
  9030. )));
  9031. }
  9032. $transaction->commit();
  9033. }catch (Exception $e){
  9034. $transaction->rollBack();
  9035. exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
  9036. }
  9037. }
  9038. //发送学生端消息
  9039. if($needAddExamId ){
  9040. $sendJsonArr=array(
  9041. 'school_id'=>$this->schoolId,
  9042. 'send_type'=>'zsyas',
  9043. 'update_type'=>3,
  9044. 'exam_group_id'=>$exam_group_id,
  9045. 'exam_id_arr'=>$needAddExamId
  9046. );
  9047. sendStudentCacheQueue($sendJsonArr);
  9048. }
  9049. exit(json_encode(array('status'=>1,'msg'=>'设置成功')));
  9050. }else{
  9051. $result['msg']='考试数据异常';
  9052. exit(json_encode($result));
  9053. }
  9054. }
  9055. public function actionSendExamStomp(){
  9056. $exam_group_id=Req::post('examGroupId');
  9057. $exam_id=Req::post('examId');
  9058. $result['status']=0;
  9059. if(!$exam_group_id || !$exam_id){
  9060. $result['msg']='考试数据异常';
  9061. exit(json_encode($result));
  9062. }
  9063. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  9064. if($exam_data['subject_id']==8){
  9065. $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_group_id,'examIds'=>array($exam_id));
  9066. $rs=$this->sendStomp($stomp_data);
  9067. if($rs){
  9068. $sendMsg=array(
  9069. 'school_id'=>$this->schoolId,
  9070. 'msg_type'=>3,
  9071. 'subject_id'=>$exam_data['subject_id'],
  9072. 'send_type'=>'exam',
  9073. 'exam_group_id'=>$exam_group_id,
  9074. 'exam_ids'=>array($exam_id)
  9075. );
  9076. sendDataToKafka('xbkc-php-product-html',$sendMsg);
  9077. $result['status']=1;
  9078. $result['msg']='发送成功';
  9079. }
  9080. }else{
  9081. $sendMsg=array(
  9082. 'school_id'=>$this->schoolId,
  9083. 'msg_type'=>3,
  9084. 'subject_id'=>$exam_data['subject_id'],
  9085. 'send_type'=>'exam',
  9086. 'exam_group_id'=>$exam_group_id,
  9087. 'exam_ids'=>array($exam_id)
  9088. );
  9089. sendDataToKafka('xbkc-php-product-html',$sendMsg);
  9090. $result['status']=1;
  9091. $result['msg']='发送成功';
  9092. }
  9093. exit(json_encode($result));
  9094. }
  9095. public function actionSendExamStompHomework(){
  9096. $exam_group_id=Req::post('examGroupId');
  9097. $exam_id=Req::post('examId');
  9098. $result['status']=0;
  9099. if(!$exam_group_id || !$exam_id){
  9100. $result['msg']='考试数据异常';
  9101. exit(json_encode($result));
  9102. }
  9103. //发送学生端消息
  9104. $sendJsonArr=array(
  9105. 'school_id'=>$this->schoolId,
  9106. 'send_type'=>'zsyas',
  9107. 'update_type'=>5,
  9108. 'exam_group_id'=>$exam_group_id,
  9109. 'exam_id_arr'=>array($exam_id),
  9110. );
  9111. sendStudentCacheQueue($sendJsonArr);
  9112. $result['status']=1;
  9113. exit(json_encode($result));
  9114. }
  9115. /**
  9116. * 发送消息队列
  9117. * @return mixed
  9118. */
  9119. private function sendStomp($data = array())
  9120. {
  9121. if ($data) {
  9122. $conf = new RdKafka\Conf();
  9123. $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
  9124. $producer = new RdKafka\Producer($conf);
  9125. $topic = $producer->newTopic("zsyte-marking-finished-notify");
  9126. $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data));
  9127. $producer->poll(0);
  9128. $result = $producer->flush(10000);
  9129. if($result===0){
  9130. return true;
  9131. }
  9132. }
  9133. return true;
  9134. }
  9135. //在线答题卡,试卷结构
  9136. public function actionGetPaperWithTopicsDetails(){
  9137. $examGroupId = Req::post("examGroupId");
  9138. $multiplexId = Req::post("multiplexId");
  9139. if(!$examGroupId){
  9140. exit(json_encode(array('success'=>0,'message'=>'参数错误')));
  9141. }
  9142. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId));
  9143. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  9144. $cardStatus=-1;
  9145. $examIds = array();
  9146. $tplIndex=0;
  9147. if($exam_data) {
  9148. foreach ($exam_data as $val) {
  9149. $examIds[] = $val['exam_id'];
  9150. if(!$tplIndex){
  9151. $tplIndex=$val['tpl_index'];
  9152. }
  9153. if($cardStatus==-1){
  9154. $cardStatus=$val['school_card_status'];
  9155. }
  9156. }
  9157. }else{
  9158. exit(json_encode(array('success'=>0,'message'=>'考试读取失败')));
  9159. }
  9160. $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($examGroupId);
  9161. if(!$paperData){
  9162. exit(json_encode(array('success'=>0,'message'=>'试卷结构读取失败')));
  9163. }
  9164. $paperData=json_decode($paperData,true);
  9165. $paperData['success']=1;
  9166. if(in_array($tplIndex, Yii::app()->params['custom_tpls_ids'])){
  9167. //自定义模板
  9168. $isCustomTpl = true;
  9169. }else{
  9170. //非自定义模板
  9171. $isCustomTpl = false;
  9172. }
  9173. if (in_array($tplIndex, Yii::app()->params['no_template_id']) || $isCustomTpl) {
  9174. //题卡分离
  9175. $paperData['paperTplType'] = 2;
  9176. }else{
  9177. $paperData['paperTplType'] = 1;
  9178. }
  9179. if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl']))
  9180. {
  9181. $paperData['paperTplType']= 1;
  9182. if($tplIndex == 9 )
  9183. {
  9184. $paperData['paperTplType'] = 2;
  9185. }
  9186. }
  9187. if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl_all']))
  9188. {
  9189. $paperData['paperTplType'] = 1;
  9190. if($tplIndex == 9 )
  9191. {
  9192. $paperData['paperTplType'] = 2;
  9193. }
  9194. }
  9195. //英语题卡分离一
  9196. if($this->subjectId == 8){
  9197. $paperData['paperTplType'] = 2;
  9198. }
  9199. //读取打印班级状态
  9200. $countPrint=$this->sConn->createCommand("select count(*) as count from class_exam_printer where is_print_online=1 and exam_id in(".implode(',',$examIds).")")->queryRow();
  9201. if($countPrint && $countPrint['count']>0){
  9202. $paperData['printClassStatus']=1;
  9203. }else{
  9204. $paperData['printClassStatus']=0;
  9205. }
  9206. $thirdAnswerSheet=$this->sConn->createCommand("select `name`,`position`,online_card_pdf,file_path,select_info,multiplex_id,`is_qrcode_online`,`create_time`,`update_time` from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
  9207. if($thirdAnswerSheet){
  9208. $paperData['position']='';
  9209. //判断是否有复用答题卡记录
  9210. if(!$thirdAnswerSheet['multiplex_id']){
  9211. //旧数据没有复用记录,需要补一条记录
  9212. $onlineCardMultiModel=new SOnlineCardMultiplex();
  9213. $onlineCardMultiModel->exam_group_id=$examGroupId;
  9214. $onlineCardMultiModel->name=$thirdAnswerSheet['name'];
  9215. $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path'];
  9216. $onlineCardMultiModel->position=$thirdAnswerSheet['position'];
  9217. $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf'];
  9218. $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online'];
  9219. $onlineCardMultiModel->is_download=0;
  9220. $onlineCardMultiModel->is_copy=0;
  9221. $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time'];
  9222. $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time'];
  9223. if($onlineCardMultiModel->save()){
  9224. $nowMultiplexId=$onlineCardMultiModel->multiplex_id;
  9225. $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$examGroupId}'")->execute();
  9226. }
  9227. }
  9228. if($multiplexId){
  9229. $multi=$this->sConn->createCommand("select multiplex_id,exam_group_id,`name`,file_path,`position`,online_card_pdf,is_qrcode_online,is_download,is_copy,update_time from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
  9230. if($multi){
  9231. if($multi['position']){
  9232. if(strpos($multi['position'],'http://')!==false || strpos($multi['position'],'https://')!==false){
  9233. $multi['position']=fileGetContents($multi['position']);
  9234. }
  9235. $paperData['position']=$multi['position'];
  9236. }
  9237. }
  9238. }elseif($thirdAnswerSheet['position']){
  9239. if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){
  9240. $paperData['position']=fileGetContents($thirdAnswerSheet['position']);
  9241. }else{
  9242. $paperData['position']=$thirdAnswerSheet['position'];
  9243. }
  9244. }
  9245. $paperData['online_card_pdf']=$thirdAnswerSheet['online_card_pdf'];
  9246. $paperData['file_path']=$thirdAnswerSheet['file_path'];
  9247. $paperData['stem_info']=$thirdAnswerSheet['select_info'];
  9248. }else{
  9249. $paperData['position']='';
  9250. $paperData['online_card_pdf']='';
  9251. $paperData['file_path']='';
  9252. $paperData['stem_info']='';
  9253. }
  9254. $paperData['card_status']=$cardStatus;
  9255. $paperData['examStatus']=$findInfo->status;
  9256. exit(json_encode($paperData));
  9257. }
  9258. //保存在线答题卡
  9259. public function actionSaveCardOnline(){
  9260. $examGroupId = Req::post("examGroupId");
  9261. $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
  9262. $text = trim(Req::post("timu"));
  9263. $name = Req::post("title");
  9264. $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
  9265. $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
  9266. $post = json_decode($text,true);
  9267. $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
  9268. $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
  9269. $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
  9270. $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
  9271. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  9272. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  9273. $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0;
  9274. $stemInfo=isset($_POST['stemInfo'])?$_POST['stemInfo']:0;
  9275. $error['success']=0;
  9276. if(!$examGroupId){
  9277. $error['message'] = '考试id不能为空';
  9278. echo json_encode($error);exit();
  9279. }
  9280. if(!$text || !$name || !$sheet_answer || !$sheet_score){
  9281. $error['message'] = '题目参数错误';
  9282. echo json_encode($error);exit();
  9283. }
  9284. if(!$positionJson){
  9285. $error['message'] = '定位信息异常';
  9286. echo json_encode($error);exit();
  9287. }
  9288. $time=time();
  9289. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  9290. if($exam_data){
  9291. // $tpl_data = json_decode($exam_data[0]['tpl_data'],1);
  9292. //验证是否已下载,是否是复用的答题卡
  9293. if($multiplexId){
  9294. $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow();
  9295. if($checkMulti['is_download']){
  9296. $error['success']=0;
  9297. $error['message'] = '上传失败,答题卡已经下载!';
  9298. echo json_encode($error);exit();
  9299. }
  9300. if($checkMulti['is_copy']){
  9301. //只保存文件信息
  9302. $this->saveMultiplex();
  9303. }
  9304. }
  9305. $examIds=array();
  9306. foreach ($exam_data as $val){
  9307. $examIds[]=$val['exam_id'];
  9308. }
  9309. $card_file=array();
  9310. $card_pdf='';
  9311. // if (empty($_FILES)) {
  9312. // $error['message'] = '未找到上传文件!';
  9313. // echo json_encode($error);exit();
  9314. // }else{
  9315. // debug($_FILES);
  9316. if($_FILES){
  9317. foreach($_FILES as $k=>$v){
  9318. if(isset($v) && !empty($v)){
  9319. if(!isset($v['size']) || $v['size'] >= 8388608){
  9320. $error['message'] = '文件超过8M!';
  9321. echo json_encode($error);exit();
  9322. }
  9323. $ext=substr($v['name'],strrpos($v['name'],'.')+1);
  9324. if(!isset($v['name']) || !in_array($ext,array('doc','docx','pdf','bmp','jpg','jpeg','png','txt'))){
  9325. $error['message'] = '文件格式不正确!';
  9326. echo json_encode($error);exit();
  9327. }
  9328. if($ext=='pdf'){
  9329. $card_pdf="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.pdf' ;
  9330. if(!move_uploaded_file($v["tmp_name"], $card_pdf)){
  9331. $error['message'] = '保存Pdf文件失败!';
  9332. echo json_encode($error);exit();
  9333. }
  9334. }else{
  9335. $card_file[] = $v;
  9336. }
  9337. }
  9338. }
  9339. }
  9340. $fixName = 'upload/tmpDir/ThirdSheet/'. date('Y') .'/'. date('m') .'/'.date('j').'/';
  9341. $ucloudZipUrl='';
  9342. $ucloudPdfUrl='';
  9343. $ucloudTxtUrl='';
  9344. if (!file_exists($fixName)) {
  9345. mkdir($fixName, 0777, true);
  9346. }
  9347. $zipFileName=$examGroupId.'_'.$time.'.zip';
  9348. $pathName=$fixName.$zipFileName;
  9349. $zip = new ZipArchive;
  9350. $zip->open($pathName, ZipArchive::CREATE);
  9351. foreach($card_file as $k=>$v){
  9352. $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
  9353. }
  9354. $zip->addFromString('json.txt', $positionJson);
  9355. $zip->close();
  9356. //FIXME 20191204
  9357. $ucloud = new HuaweiCloud();
  9358. //上传压缩包
  9359. $rename = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $zipFileName;
  9360. $uploadInfo = $ucloud->putFile($rename, $pathName);
  9361. @unlink($pathName);
  9362. if ($uploadInfo['status'] == 0) {
  9363. $error['success']=0;
  9364. $error['message'] = '答题卡文件上传失败! ';
  9365. echo json_encode($uploadInfo);exit();
  9366. }else{
  9367. $ucloudZipUrl=$uploadInfo['url'];
  9368. }
  9369. //单独上传position.txt
  9370. if($positionJson){
  9371. $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.txt' ;
  9372. file_put_contents($positionTxt, $positionJson);
  9373. $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .$time.'.txt' ;
  9374. $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
  9375. if ($uploadInfo['status'] == 0) {
  9376. @unlink($positionTxt);
  9377. $error['success']=0;
  9378. $error['message'] = 'Position文件上传失败!';
  9379. echo json_encode($error);exit();
  9380. }else{
  9381. @unlink($positionTxt);
  9382. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  9383. $ucloudTxtUrl=$uploadInfo['url'];
  9384. }
  9385. }
  9386. //上传Pdf
  9387. if($pdfUrl){
  9388. $ucloudPdfUrl=$pdfUrl;
  9389. // $card_pdf="upload/ThirdSheet/" .$examGroupId.'.pdf' ;
  9390. // $content = file_get_contents($pdfUrl);
  9391. //
  9392. // file_put_contents($card_pdf, $content);
  9393. //
  9394. // $uploadPdfName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.pdf' ;
  9395. // $uploadInfo = $ucloud->putFile($uploadPdfName,$card_pdf);
  9396. //
  9397. // if ($uploadInfo['status'] == 0) {
  9398. // @unlink($card_pdf);
  9399. // $error['success']=0;
  9400. // $error['message'] = '答题卡PDF文件上传失败!';
  9401. // echo json_encode($error);exit();
  9402. // }else{
  9403. // @unlink($card_pdf);
  9404. // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  9405. // $ucloudPdfUrl=$uploadInfo['url'];
  9406. // }
  9407. }
  9408. if(!$multiplexId){
  9409. //没有复用记录,初始化一条记录
  9410. $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`,`is_qrcode_online`) values";
  9411. $insertSql.="('".$examGroupId."','".$name."','".$ucloudZipUrl."','".$ucloudTxtUrl."','".$ucloudPdfUrl."','".time()."','".time()."','".$useQrCode."')";
  9412. $this->sConn->createCommand($insertSql)->execute();
  9413. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  9414. $multiplexId=$last_insert_id['last_insert_id()'];
  9415. }else{
  9416. //更新复用记录
  9417. $updateSql="update online_card_multiplex set `file_path`='{$ucloudZipUrl}',`position`='{$ucloudTxtUrl}',`online_card_pdf`='{$ucloudPdfUrl}',update_time='".time()."',is_qrcode_online='".$useQrCode."' where multiplex_id='{$multiplexId}'";
  9418. $this->sConn->createCommand($updateSql)->execute();
  9419. }
  9420. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
  9421. if(!$thirdAnswerSheet){
  9422. $ThirdAnswerSheetModel=new SThirdAnswerSheet();
  9423. $ThirdAnswerSheetModel->name=$name;
  9424. $ThirdAnswerSheetModel->exam_group_id=$examGroupId;
  9425. $ThirdAnswerSheetModel->ke_topic_num=$KeGuanTi;
  9426. $ThirdAnswerSheetModel->tian_topic_num=$TianKongTi;
  9427. $ThirdAnswerSheetModel->zu_topic_num=$ZhuGuanTi;
  9428. $ThirdAnswerSheetModel->xuan_topic_num=$XuanZuoTi;
  9429. $ThirdAnswerSheetModel->file_path=$ucloudZipUrl;
  9430. $ThirdAnswerSheetModel->sheet_answer=$sheet_answer;
  9431. $ThirdAnswerSheetModel->sheet_score=$sheet_score;
  9432. $ThirdAnswerSheetModel->create_time=$time;
  9433. $ThirdAnswerSheetModel->update_time=$time;
  9434. $ThirdAnswerSheetModel->position=$ucloudTxtUrl;
  9435. $ThirdAnswerSheetModel->online_card=1;
  9436. $ThirdAnswerSheetModel->online_card_pdf=$ucloudPdfUrl;
  9437. $ThirdAnswerSheetModel->is_qrcode_online=$useQrCode;
  9438. $ThirdAnswerSheetModel->multiplex_id=$multiplexId;
  9439. $rs=$ThirdAnswerSheetModel->save();
  9440. // $insert="insert into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`) ";
  9441. // $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$ucloudZipUrl."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$ucloudPdfUrl."','".$useQrCode."') ";
  9442. // $rs= $this->sConn->createCommand($insert)->execute();
  9443. }else{
  9444. //更新打印状态
  9445. $this->sConn->createCommand("update class_exam_printer set is_print_online=0 where exam_id in(".implode(',',$examIds).")")->execute();
  9446. $updateArr=array(
  9447. 'file_path'=>$ucloudZipUrl,
  9448. 'sheet_answer'=>$sheet_answer,
  9449. 'sheet_score'=>$sheet_score,
  9450. 'ke_topic_num'=>$KeGuanTi,
  9451. 'tian_topic_num'=>$TianKongTi,
  9452. 'zu_topic_num'=>$ZhuGuanTi,
  9453. 'xuan_topic_num'=>$XuanZuoTi,
  9454. 'update_time'=>$time,
  9455. 'position'=>$ucloudTxtUrl,
  9456. 'online_card'=>1,
  9457. 'online_card_pdf'=>$ucloudPdfUrl,
  9458. 'is_qrcode_online'=>$useQrCode,
  9459. 'multiplex_id'=>$multiplexId
  9460. );
  9461. $rs= SThirdAnswerSheet::model()->updateAll($updateArr,"exam_group_id ='{$examGroupId}'");
  9462. // $rs=$this->sConn->createCommand("update third_answer_sheet set `file_path` = '".$ucloudZipUrl."',sheet_answer='".$sheet_answer."',sheet_score='".$sheet_score."',ke_topic_num=".$KeGuanTi.",tian_topic_num=".$TianKongTi.",zu_topic_num=".$ZhuGuanTi.",xuan_topic_num=".$XuanZuoTi.",update_time=".time().",position='".$positionJson."',online_card=1,online_card_pdf='".$ucloudPdfUrl."',is_qrcode_online='".$useQrCode."' where exam_group_id = '{$examGroupId}' ")->execute();
  9463. }
  9464. if($rs){
  9465. $OnlineCardSaveLogModel=new SOnlineCardSaveLog();
  9466. $OnlineCardSaveLogModel->exam_group_id=$examGroupId;
  9467. $OnlineCardSaveLogModel->file_path=$ucloudZipUrl;
  9468. $OnlineCardSaveLogModel->online_card_pdf=$ucloudPdfUrl;
  9469. $OnlineCardSaveLogModel->position=$ucloudTxtUrl;
  9470. $OnlineCardSaveLogModel->create_time=$time;
  9471. $OnlineCardSaveLogModel->save();
  9472. $error['success']=1;
  9473. $error['message'] = '保存成功!';
  9474. $error['data'] = $ucloudPdfUrl;
  9475. $error['multiplex_id']=$multiplexId;
  9476. echo json_encode($error);exit();
  9477. }
  9478. // }
  9479. }else{
  9480. $error['message'] = '考试不存在'.$examGroupId;
  9481. echo json_encode($error);exit();
  9482. }
  9483. echo json_encode($error);exit();
  9484. }
  9485. //判断在线答题卡
  9486. public function actionGetOnlineCard(){
  9487. $exam_group_id = Req::post("exam_group_id");
  9488. if($exam_group_id)
  9489. {
  9490. $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1',array(':exam_group_id'=>$exam_group_id));
  9491. if(!$third_answer_data)
  9492. {
  9493. echo json_encode(array('status'=>-1));exit;
  9494. }
  9495. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  9496. if($exam_group_data)
  9497. {
  9498. $sheetAnswer=json_decode($third_answer_data['sheet_answer'],true);
  9499. //
  9500. $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  9501. $tplData=json_decode($exam['tpl_data'],true);
  9502. //update_answer new_rules
  9503. $updateAnswer=array();
  9504. $newRules=array();
  9505. if(isset($tplData['update_answer'])){
  9506. $updateAnswer=$tplData['update_answer'];
  9507. }
  9508. if(isset($tplData['new_rules'])){
  9509. $newRules=$tplData['new_rules'];
  9510. }
  9511. $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam['exam_id']));
  9512. $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type in(1,2,11)',array(':paper_id'=>$paper['paper_id']));
  9513. foreach ($paperTopic as $item){
  9514. if((!isset($sheetAnswer[$item['order']]) || !$sheetAnswer[$item['order']]) && !isset($updateAnswer[$item['order']]) && (!isset($newRules[$item['order']]) || !$newRules[$item['order']]['rule_answer'] )){
  9515. echo json_encode(array('status'=>-2));exit;
  9516. }
  9517. }
  9518. echo json_encode(array('status'=>1,'qxk_paper_id'=>$exam_group_data['qxk_paper_id']));exit;
  9519. }
  9520. }
  9521. echo json_encode(array('status'=>0));exit;
  9522. }
  9523. private function mkdir($path, $chmod = 0755){
  9524. return is_dir($path) || (self::mkdir(dirname($path), $chmod) && mkdir($path, $chmod));
  9525. }
  9526. /**
  9527. * 下载pdf
  9528. */
  9529. public function actionDownOnlinePdf()
  9530. {
  9531. $examGroupId = safe_replace(Yii::app()->request->getQuery('exam_group_id'));
  9532. if (!$examGroupId) {
  9533. Yii::app()->jump->error('请指定考试');
  9534. }
  9535. $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1', array(':exam_group_id' => $examGroupId));
  9536. if (!$third_answer_data) {
  9537. echo json_encode(array('status' => -1));
  9538. exit;
  9539. }
  9540. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  9541. $examIds = array();
  9542. if($exam_data) {
  9543. foreach ($exam_data as $val) {
  9544. $examIds[] = $val['exam_id'];
  9545. }
  9546. }
  9547. if(!$examIds)
  9548. {
  9549. echo json_encode(array('status'=>-1));exit;
  9550. }
  9551. if ($third_answer_data->online_card_pdf) {
  9552. ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),' exam_id in('.implode(',',$examIds).')');
  9553. $url=$third_answer_data->online_card_pdf;
  9554. // 获取远程文件大小
  9555. // 注意filesize()无法获取远程文件大小
  9556. $headers = get_headers($url, 1);
  9557. $fileSize = $headers['Content-Length'];
  9558. //echo $fileSize;exit;
  9559. // 设置header头
  9560. // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流
  9561. header('Content-Type: application/pdf');
  9562. // 告诉浏览器返回的文件大小类型是字节
  9563. header('Accept-Ranges:bytes');
  9564. // 告诉浏览器返回的文件大小
  9565. header('Content-Length: ' . $fileSize);
  9566. // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称
  9567. Header("Content-Disposition: attachment; filename=" . $third_answer_data->online_card_pdf); // 输出文件内容
  9568. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  9569. ob_clean();
  9570. $read_buffer = 1024 * 1024;
  9571. $handle = fopen($url, 'rb');
  9572. //总的缓冲的字节数
  9573. $sum_buffer = 0;
  9574. //只要没到文件尾,就一直读取
  9575. while (!feof($handle)) {
  9576. echo fread($handle, $read_buffer);
  9577. ob_flush();
  9578. }
  9579. fclose($handle);
  9580. } else {
  9581. Yii::app()->jump->error('考试不存在或尚未生成PDF');
  9582. }
  9583. }
  9584. /**
  9585. * html转pdf
  9586. */
  9587. public function actionHtmlToPdf(){
  9588. $examGroupId = Req::post("examGroupId");
  9589. $pdfHtml = htmlspecialchars_decode(Req::post("pdfHtml"));
  9590. // $pageSize = Req::post("pageSize");
  9591. // $orientation = (int)Req::post("orientation");//1-横向 2-纵向;
  9592. $widthm = Req::post("widthm");
  9593. $heightm = Req::post("heightm");
  9594. $error['success']=0;
  9595. if(!$examGroupId){
  9596. $error['message'] = '考试id不能为空';
  9597. echo json_encode($error);exit();
  9598. }
  9599. if(!$pdfHtml){
  9600. $error['message'] = 'html信息错误';
  9601. echo json_encode($error);exit();
  9602. }
  9603. // if(!$pageSize){
  9604. // $error['message'] = '请指定纸张大小';
  9605. // echo json_encode($error);exit();
  9606. // }
  9607. // if(!$orientation){
  9608. // $error['message'] = '请指定纸张方向';
  9609. // echo json_encode($error);exit();
  9610. // }else{
  9611. // if($orientation == 1){
  9612. // $orientation = 'landscape';
  9613. // }else{
  9614. // $orientation = 'portrait';
  9615. // }
  9616. // }
  9617. if(!$widthm){
  9618. $error['message'] = '请设置宽度';
  9619. echo json_encode($error);exit();
  9620. }
  9621. if(!$heightm){
  9622. $error['message'] = '请设置高度';
  9623. echo json_encode($error);exit();
  9624. }
  9625. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/'; //存放生成的HTML路径
  9626. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/' . $this->schoolId . "/"; //存放生成的PDF路径
  9627. $pdfurl = '/upload/tmpDir/online_answer/' . $this->schoolId . "/";
  9628. if (!is_dir($htmlpath)) {
  9629. if (!mkdir($htmlpath, 0777, true)) {
  9630. exit('Create directory fail: ' . $htmlpath);
  9631. }
  9632. }if (!is_dir($pdfpath)) {
  9633. if (!mkdir($pdfpath, 0777, true)) {
  9634. exit('Create directory fail1: ' . $pdfpath);
  9635. }
  9636. }
  9637. $htmlpath.=$examGroupId . "-online_answer.html";
  9638. $f = fopen($htmlpath, "w");
  9639. fwrite($f, $pdfHtml);
  9640. fclose($f);
  9641. $htmlurl = '/upload/tmpDir/online_answer/' . $examGroupId . "-online_answer.html"; //访问HTML的路径
  9642. if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
  9643. $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
  9644. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  9645. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  9646. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  9647. $pdffname=$classId."-".$examId.".pdf";
  9648. $pdfpath = $pdfpath . $pdffname;
  9649. $pdfurl = $pdfurl . $pdffname;
  9650. $commond = Yii::app()->params['phantomjs'] . " "
  9651. . Yii::app()->params['html2pdf'] . " "
  9652. . " file://" . $htmlpath
  9653. . " {$pdfpath}"
  9654. . " 176mm*250mm ''";
  9655. } else {
  9656. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  9657. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  9658. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  9659. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  9660. $pdffname=$examGroupId."-online_answer.pdf";
  9661. $pdfpath = $pdfpath . $pdffname;
  9662. $pdfurl = $pdfurl . $pdffname;
  9663. $commond = Yii::app()->params['phantomjs_server'] . " "
  9664. . Yii::app()->basePath . '/../js/html2pdf_answer.js' . " "
  9665. . " {$htmlurl}"
  9666. . " {$pdfpath}"
  9667. . " {$widthm}*{$heightm} ''";
  9668. }
  9669. exec($commond, $res, $code);
  9670. // debug($res);
  9671. if(isset($res[0])){
  9672. if (strpos($res[0], 'succeed') !== false) {//命令返回成功
  9673. if ($this->file_exists($pdfpath)) {
  9674. $repdf = $examGroupId.".pdf";
  9675. $rename = 'zsyas2/online_answer/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
  9676. $ucloud = new HuaweiCloud();
  9677. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  9678. @unlink($pdfpath);
  9679. @unlink($htmlpath);
  9680. if ($uploadInfo['status'] == 0) {
  9681. echo json_encode(array("success" => 0, "message" => "PDF文件上传失败"));exit;
  9682. }else{
  9683. $pdfurl = $uploadInfo['url'];
  9684. }
  9685. $this->sConn->createCommand()->update("exam_group", array("answer_path" => $pdfurl), "exam_group_id = '{$examGroupId}'");
  9686. // echo json_encode(array("success" => 1, "message" => "http://" . $_SERVER['SERVER_NAME'].$pdfurl));exit;
  9687. echo json_encode(array("success" => 1, "message" => "创建成功","url"=>$pdfurl));exit;
  9688. } else {
  9689. @unlink($htmlpath);
  9690. echo json_encode(array("success" => 0, "message" => "PDF文件未找到!"));exit;
  9691. }
  9692. } else {
  9693. @unlink($htmlpath);
  9694. echo json_encode(array("success" => 0, "message" => "PDF创建失败1!"));
  9695. exit;
  9696. }
  9697. }else{
  9698. @unlink($htmlpath);
  9699. echo json_encode(array("success" => 0, "message" => "PDF创建失败2!"));
  9700. exit;
  9701. }
  9702. }
  9703. /**
  9704. * 下载pdf
  9705. */
  9706. public function actionDownPdf(){
  9707. $examGroupId = safe_replace(Yii::app()->request->getQuery('examGroupId'));
  9708. if(!$examGroupId){
  9709. Yii::app()->jump->error('请指定考试');
  9710. }
  9711. $sql = "select eg.answer_path,e.name from exam_group eg join exam e on e.exam_group_id = eg.exam_group_id where eg.exam_group_id = '{$examGroupId}'";
  9712. $exam_info = $this->sConn->createCommand($sql)->queryRow();
  9713. // $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['answer_path'];
  9714. // if ($this->check_pdf($pdfpath)) {
  9715. // Header("Content-type:application/pdf");
  9716. // Header("Accept-Ranges: bytes");
  9717. // Header("Accept-Length: " . filesize($pdfpath));
  9718. // Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容
  9719. // flush();// 刷新内容
  9720. // $file=fopen($pdfpath,"r");
  9721. // $download_rate=600;
  9722. // while (!feof($file)){
  9723. // set_time_limit(0);
  9724. // print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者
  9725. // flush();// flush 内容输出到浏览器端
  9726. // sleep(1);// 终端1秒后继续
  9727. // }
  9728. // } else {
  9729. // Yii::app()->jump->error('考试不存在或尚未生成PDF');
  9730. // }
  9731. if(strpos($exam_info['answer_path'],'http') !== false){
  9732. if(!fileGetContents($exam_info['answer_path'])){
  9733. Yii::app()->jump->error('考试不存在或尚未生成PDF');
  9734. }else{
  9735. $url = $exam_info['answer_path'];
  9736. // 获取远程文件大小
  9737. // 注意filesize()无法获取远程文件大小
  9738. $headers = get_headers($url, 1);
  9739. $fileSize = $headers['Content-Length'];
  9740. //echo $fileSize;exit;
  9741. // 设置header头
  9742. // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流
  9743. header('Content-Type: application/pdf');
  9744. // 告诉浏览器返回的文件大小类型是字节
  9745. header('Accept-Ranges:bytes');
  9746. // 告诉浏览器返回的文件大小
  9747. header('Content-Length: ' . $fileSize);
  9748. // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称
  9749. Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容
  9750. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  9751. ob_clean();
  9752. $read_buffer = 1024*1024;
  9753. $handle = fopen($url, 'rb');
  9754. //总的缓冲的字节数
  9755. $sum_buffer = 0;
  9756. //只要没到文件尾,就一直读取
  9757. while (!feof($handle)) {
  9758. echo fread($handle, $read_buffer);
  9759. ob_flush();
  9760. }
  9761. fclose($handle);
  9762. }
  9763. }else{
  9764. Yii::app()->jump->error('考试不存在或尚未生成PDF');
  9765. }
  9766. }
  9767. private function check_pdf($pdf_path) {
  9768. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  9769. if (file_exists($pdf_path)) {
  9770. return true;
  9771. }
  9772. }
  9773. return false;
  9774. }
  9775. function filter_file_name($filename){
  9776. return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
  9777. array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
  9778. , $filename);
  9779. }
  9780. //二轮复习个性化提分手册列表
  9781. public function actionReview(){
  9782. Url::clean();
  9783. $data = array();
  9784. $printName = Req::get("name");
  9785. $classId = Req::get("classId");
  9786. $grade = (int)Req::get("grade");
  9787. $newCondition = array();
  9788. if($grade){
  9789. $newCondition[] = 'mrs.grade='.$grade;
  9790. }
  9791. if($printName){
  9792. $newCondition[] = 'mrs.name like "%'.$printName.'%"';
  9793. }
  9794. if($classId){
  9795. $newCondition[] = 'mrs.class_id='.$classId;
  9796. }
  9797. $resultList = $this->schoolManager->getMathWeek($newCondition,array('mrs.create_time desc','mrs.mr_id desc'));
  9798. $printList = array();
  9799. if($resultList["rs"]){
  9800. foreach ($resultList['rs'] as $k=>$v) {
  9801. $printList[$k]=$v;
  9802. }
  9803. }
  9804. if (empty($grade)) {
  9805. $grade = 'ALL';
  9806. }
  9807. $classes = $this->schoolManager->getClasses($grade);
  9808. $data['pages'] = $resultList['pager'];
  9809. $data['page_total'] = $resultList['pager']->rowsCount;
  9810. $data['printList'] = $printList;
  9811. $data["printName"] = $printName;
  9812. $data["classes"] = $classes;
  9813. $data["classId"] = $classId;
  9814. $data["grade"] = $grade;
  9815. $this->render('review',$data);
  9816. }
  9817. //二轮复习个性化提分手册设置
  9818. public function actionReviewSetting(){
  9819. $data = array();
  9820. $result = $this->apiPost('all_knowledge/point',array());
  9821. $data['special_arr']=$result;
  9822. $this->render('review_setting',$data);
  9823. }
  9824. //保存二轮复习个性化提分手册设置
  9825. public function actionAjaxSaveMathReview(){
  9826. $result = array();
  9827. $error = array();
  9828. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  9829. $error[] = '错误的来源!';
  9830. }else{
  9831. $grade=(int)Req::post('grade');
  9832. $createType = (int)Req::post('createType');
  9833. $classIds = Req::post('selectClassIds');
  9834. $itemIds = (array)Req::post('selectedItemIds');
  9835. $special = (int)Req::post('special');
  9836. $specialName = Req::post('specialName');
  9837. $isNewVersion = (int)Req::post('isNewVersion');//新版本为1,旧版本默认为0
  9838. if($createType==1){
  9839. //自动,读取专题下所有考点
  9840. $result = $this->apiPost('all_knowledge/point',array('specialIds'=>array($special)));
  9841. $itemIds=array();
  9842. if($result){
  9843. foreach ($result as $item){
  9844. if($item['kps']){
  9845. foreach ($item['kps'] as $kp){
  9846. if($kp['methods']){
  9847. foreach ($kp['methods'] as $method){
  9848. $itemIds[]=$method['method_id'];
  9849. }
  9850. }
  9851. }
  9852. }
  9853. }
  9854. }
  9855. }
  9856. if(!$itemIds){
  9857. $error[] = '请选择专项';
  9858. }
  9859. if(!$grade){
  9860. $error[] = '请选择年级';
  9861. }
  9862. if(!$classIds){
  9863. $error[] = '请选择班级';
  9864. }
  9865. }
  9866. if(!$error){
  9867. $time = time();
  9868. $strModel = new SStudentClassRelation();
  9869. $transaction = $this->sConn->beginTransaction();
  9870. try{
  9871. $mrGroupId = getUniqueId($this->schoolId);
  9872. $mrIds=array();
  9873. foreach($classIds as $k=>$v){
  9874. $mathName = $specialName;
  9875. $mrId=getUniqueId($this->schoolId);
  9876. $mrIds[]=$mrId;
  9877. $this->sConn->createCommand()->insert('math_review_setting',array(
  9878. 'mr_group_id' =>$mrGroupId,
  9879. 'mr_id' => $mrId,
  9880. 'special_id' => $special,
  9881. 'name' => $mathName,
  9882. 'semester_id' => $this->semesterId,
  9883. 'grade' => $grade,
  9884. 'class_id' => $v,
  9885. 'is_all_html' => 0,
  9886. 'method_ids' => implode(',',$itemIds),
  9887. 'create_type' => $createType,
  9888. 'create_time' => $time,
  9889. 'is_new_version' => $isNewVersion,
  9890. ));
  9891. //获取班级学生
  9892. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  9893. if($stuData){
  9894. foreach($stuData as $kk=>$vv){
  9895. $this->sConn->createCommand()->insert('math_review_student',array(
  9896. 'mr_id' => $mrId,
  9897. 'student_id' => $vv['student_id'],
  9898. 'create_time'=>$time
  9899. ));
  9900. }
  9901. }
  9902. }
  9903. $transaction->commit();
  9904. }catch(Exception $e){
  9905. $transaction->rollBack();
  9906. if (YII_ENV == 'production') {
  9907. $error[] = '系统错误[SQL]';
  9908. } else {
  9909. $error[] = $e->getMessage();
  9910. }
  9911. }
  9912. }
  9913. if($error){
  9914. echo json_encode(array('status'=>0,'error'=>$error));exit;
  9915. }else{
  9916. //发消息
  9917. if($isNewVersion){
  9918. $kafkaData=array(
  9919. 'school_id'=>$this->schoolId,
  9920. 'msg_type'=>90,//1-完成阅卷,2-发送标注,3-点代办,90-重置 产品生成说写90
  9921. 'grade'=>$grade,
  9922. 'subject_id'=>3,
  9923. 'send_type'=>'math_review',
  9924. 'product_type'=>17,
  9925. 'gp_group_id'=>$mrGroupId,
  9926. 'gp_ids'=>array_unique($mrIds),
  9927. );
  9928. sendDataToKafka("php-product-math-review-html",$kafkaData);
  9929. }
  9930. echo json_encode(array('status'=>1));exit;
  9931. }
  9932. }
  9933. //选择学生二轮复习个性化提分手册
  9934. public function actionSelectStuByMath(){
  9935. $data = array();
  9936. $sname = (string)Req::get("sname"); //学生名字
  9937. $mrId = (string)Req::get("mrId");
  9938. if(!$mrId){
  9939. Yii::app()->jump->error('参数错误!');
  9940. }
  9941. //获取班级名称以及周后推送名称
  9942. $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from math_review_setting ew join class c on ew.class_id = c.class_id where ew.mr_id = '{$mrId}'";
  9943. $names = $this->sConn->createCommand($sql)->queryRow();
  9944. if(!$names){
  9945. $names = array();
  9946. $names['name'] = '';
  9947. $names['class_name'] = '';
  9948. $names['grade'] = 0;
  9949. }else{
  9950. $data['name'] = isset($names['name'])?$names['name']:'';
  9951. }
  9952. $sql = "select student_id,is_review_pdf from math_review_student where mr_id = '{$mrId}'";
  9953. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  9954. $studentIds = array();
  9955. $stuIsPdf = array();
  9956. if($relateStudent){
  9957. foreach ($relateStudent as $studentInfo) {
  9958. $studentIds[] = (string)$studentInfo['student_id'];
  9959. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_review_pdf'];
  9960. }
  9961. }
  9962. if($studentIds){
  9963. $studentNames = SStudentInfo::model()->getStudents($studentIds); //求学生名字
  9964. if($studentNames){
  9965. if($sname){
  9966. $i = 1;
  9967. foreach($studentNames as $k=>$v){
  9968. if(strpos($v['realname'],$sname) !== false){
  9969. $data['list'][$i]['stu_id'] = (string)$v['student_id'];
  9970. $data['list'][$i]['stu_name'] = $v['realname'];
  9971. $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name'];
  9972. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0;
  9973. switch($v['level']){
  9974. case 1:
  9975. $data['list'][$i]['level'] = '尖子生';
  9976. break;
  9977. case 2:
  9978. $data['list'][$i]['level'] = '尖子生';
  9979. break;
  9980. case 3:
  9981. $data['list'][$i]['level'] = '中等生';
  9982. break;
  9983. case 4:
  9984. $data['list'][$i]['level'] = '学困生';
  9985. break;
  9986. default:
  9987. $data['list'][$i]['level'] = '无';
  9988. }
  9989. $i++;
  9990. }
  9991. }
  9992. }else{
  9993. $i = 1;
  9994. foreach($studentNames as $k=>$v){
  9995. $data['list'][$i]['stu_id'] = (string)$v['student_id'];
  9996. $data['list'][$i]['stu_name'] = $v['realname'];
  9997. $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name'];
  9998. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0;
  9999. switch($v['level']){
  10000. case 1:
  10001. $data['list'][$i]['level'] = '尖子生';
  10002. break;
  10003. case 2:
  10004. $data['list'][$i]['level'] = '尖子生';
  10005. break;
  10006. case 3:
  10007. $data['list'][$i]['level'] = '中等生';
  10008. break;
  10009. case 4:
  10010. $data['list'][$i]['level'] = '学困生';
  10011. break;
  10012. default:
  10013. $data['list'][$i]['level'] = '无';
  10014. }
  10015. $i++;
  10016. }
  10017. }
  10018. }
  10019. }
  10020. $Sem=new SSemester();
  10021. $code= $Sem->conn->createQuery()
  10022. ->from('semester')
  10023. ->where("semester_id = '".$names['semester_id']."'")
  10024. ->limit(1)
  10025. ->query()
  10026. ->read();
  10027. if($studentIds){
  10028. $intarr=array(
  10029. "schoolId"=>$this->schoolId,
  10030. "clazzId"=>$names['class_id'],
  10031. "semester"=>$code['refer_code'],
  10032. "grade"=>$names['grade'],
  10033. "students"=>$studentIds,
  10034. "examTime"=>$names['create_time'],
  10035. "classify"=>5,
  10036. "subject"=>3
  10037. );
  10038. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  10039. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  10040. if(!$rs){
  10041. Yii::app()->jump->error("接口错误");
  10042. }
  10043. if($rs->errCode!="00"){
  10044. Yii::app()->jump->error($rs->errMsg);
  10045. }
  10046. if(!empty($rs->data)){
  10047. $data['limitstu']=array();
  10048. foreach ($rs->data as $v){
  10049. $data['limitstu'][(string)$v]=$v;
  10050. }
  10051. }
  10052. }
  10053. $data['mrId'] = $mrId;
  10054. $data['sname'] = $sname;
  10055. $data['printType'] = 'mrv_stu';
  10056. $this->render('review_stu',$data);
  10057. }
  10058. //获取设置二轮复习个性化提分手册的班级
  10059. public function actionAjaxGetClassesBySettingMath(){
  10060. $result = array();
  10061. $grade=(int)Req::post('grade');
  10062. $specialId=(int)Req::post('specialId');
  10063. //获取班级
  10064. $hasSettingClassIds = array();
  10065. $sql = "select class_id,count(*) count from math_review_setting where semester_id = '{$this->semesterId}' and special_id='{$specialId}' group by class_id";
  10066. $data = $this->sConn->createCommand($sql)->queryAll();
  10067. if($data){
  10068. foreach($data as $k=>$v){
  10069. if($v['count'] > 2){
  10070. $hasSettingClassIds[] = (string)$v['class_id'];
  10071. }
  10072. }
  10073. }
  10074. if($grade){
  10075. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0";
  10076. $data = $this->sConn->createCommand($sql)->queryAll();
  10077. if($data){
  10078. $i = 0;
  10079. foreach($data as $k => $v){
  10080. $result[$i]['class_id'] = $v['class_id'];
  10081. $result[$i]['class_name'] = $v['class_name'];
  10082. if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
  10083. $result[$i]['status'] = 1;
  10084. }else{
  10085. $result[$i]['status'] = 0;
  10086. }
  10087. $i++;
  10088. }
  10089. }
  10090. }
  10091. echo json_encode($result);exit;
  10092. }
  10093. //下载二轮复习个性化提分手册
  10094. public function actionGetMathReviewFile(){
  10095. $mrId = (string)Req::get("mrId");
  10096. $studentsIds = (string)Req::get("studentsIds");
  10097. $params = array();
  10098. if(!$mrId){
  10099. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  10100. exit();
  10101. }
  10102. if(!$studentsIds){
  10103. $studentsIds = array();
  10104. $sql = "select student_id from math_review_student where mr_id = '{$mrId}' and is_review_pdf = 1";
  10105. $stuArr = $this->sConn->createCommand($sql)->queryAll();
  10106. if($stuArr){
  10107. foreach($stuArr as $k=>$v){
  10108. $studentsIds[] = $v['student_id'];
  10109. }
  10110. }
  10111. }else{
  10112. $studentsIds = explode(',',$studentsIds);
  10113. }
  10114. if(!$studentsIds || empty($studentsIds)){
  10115. echo json_encode(array("success" => 0, "message" => "无生成的学生"));
  10116. exit();
  10117. }
  10118. $params['mrId'] = $mrId;
  10119. $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_review_setting where mr_id = '{$mrId}'";
  10120. $msg = $this->sConn->createCommand($sql)->queryRow();
  10121. $Sem=new SSemester();
  10122. $code= $Sem->conn->createQuery()
  10123. ->from('semester')
  10124. ->where("semester_id = '".$msg['semester_id']."'")
  10125. ->limit(1)
  10126. ->query()
  10127. ->read();
  10128. $intarr=array(
  10129. "schoolId"=>$this->schoolId,
  10130. "clazzId"=>$msg['class_id'],
  10131. "semester"=>$code['refer_code'],
  10132. "grade"=>$msg['grade'],
  10133. "students"=>$studentsIds,
  10134. "examTime"=>$msg['create_time'],
  10135. "classify"=>5,
  10136. "subject"=>3
  10137. );
  10138. if(isset($msg['school_group_id']) && $msg['school_group_id']){
  10139. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  10140. }else{
  10141. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  10142. }
  10143. if(!$apiUrl){
  10144. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  10145. exit();
  10146. }
  10147. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  10148. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  10149. if($studentsIds){
  10150. $params["studentIds"] = $studentsIds;
  10151. }
  10152. }else{
  10153. if(Yii::app()->params["limit_open"]){
  10154. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  10155. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  10156. if(!$rs){
  10157. Yii::app()->jump->error("接口错误");
  10158. }
  10159. if($rs->errCode!="00"){
  10160. echo json_encode(array("success" => 0, "message" => $rs->errMsg));
  10161. exit();
  10162. }
  10163. if(!empty($rs->data)){
  10164. $params["studentIds"]=$rs->data;
  10165. if(count($rs->data)<count($intarr['students'])){
  10166. $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
  10167. }
  10168. } else{
  10169. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  10170. exit();
  10171. }
  10172. }else{
  10173. if($studentsIds){
  10174. $params["studentIds"] = $studentsIds;
  10175. }
  10176. }
  10177. }
  10178. $params['schoolId'] = $this->schoolId;
  10179. $params['type'] = 1;
  10180. $rs = Curl::post($apiUrl."/rest/download_math_pdf/index", $params);
  10181. if(!($rs = json_decode($rs))){
  10182. $rs = array(
  10183. "success" => 0,
  10184. "message" => "请求接口失败",
  10185. );
  10186. }else{
  10187. //更新下载时间
  10188. if($rs->success==1 || $rs->success==2){
  10189. $time = time();
  10190. if($studentsIds){
  10191. $sql = "update math_review_student set is_review_download = 1,review_download_time={$time} where mr_id = '{$mrId}' and student_id in (".implode(',',$studentsIds).")";
  10192. $this->sConn->createCommand($sql)->execute();
  10193. }
  10194. }
  10195. }
  10196. if(isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)){
  10197. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  10198. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$msg['school_group_id'],$rs->downloadPath);
  10199. }
  10200. }
  10201. echo json_encode($rs);exit;
  10202. }
  10203. public function apiPost($path, $arr, $type = 0)
  10204. {
  10205. $ch = @curl_init();
  10206. $result = FALSE;
  10207. if ($ch) {
  10208. $data = json_encode($arr);
  10209. $url = Yii::app()->params['api'][$type]['prefix'] . $path;
  10210. $username = Yii::app()->params['api'][$type]['username'];
  10211. $password = Yii::app()->params['api'][$type]['password'];
  10212. // Digest认证
  10213. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  10214. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  10215. // 不输出头部
  10216. curl_setopt($ch, CURLOPT_HEADER, 0);
  10217. // curl_exec 获取到的内容不直接输出, 而是返回
  10218. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10219. // 请求重启路由器的地址 传参 进行重启
  10220. curl_setopt($ch, CURLOPT_URL, $url);
  10221. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  10222. curl_setopt($ch, CURLOPT_POST, 1);
  10223. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  10224. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  10225. 'Content-Type: application/json',
  10226. 'Content-Length: ' . strlen($data),
  10227. ));
  10228. if (!curl_errno($ch)) {
  10229. $result = json_decode(curl_exec($ch),1);
  10230. }
  10231. // 释放资源
  10232. curl_close($ch);
  10233. }
  10234. return $result;
  10235. }
  10236. //编辑考试信息
  10237. public function actionModifyThirdExam(){
  10238. $exam_group_id = Req::post("examGroupId");
  10239. if(!$exam_group_id){
  10240. $exam_group_id = Req::get("exam_group_id");
  10241. }
  10242. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id));
  10243. $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  10244. if(!$exam_data)
  10245. {
  10246. Yii::app()->jump->error('非法试卷!');
  10247. }
  10248. @$tplData=json_decode($exam_data['tpl_data'],true);
  10249. if(!$tplData){
  10250. Yii::app()->jump->error('非法试卷!');
  10251. }
  10252. if (Yii::app()->request->getIsPostRequest()){
  10253. $type=Req::post('type');
  10254. $name=Req::post('examName');
  10255. $examDate=Req::post('examDate');
  10256. $isCustomTpl=Req::post('isCustomTpl');
  10257. $tplDataPaper=Req::post('tplDataPaper');
  10258. $printTypeCard=Req::post('printTypeCard');
  10259. $tianType=Req::post('tianType');
  10260. $jieType=Req::post('jieType');
  10261. $dtkType=Req::post('dtkType');
  10262. $tplIndex=0;
  10263. if(!matchStrChar($name)){
  10264. Yii::app()->jump->error('考试名称不能包含特殊字符!');
  10265. }
  10266. $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
  10267. if($findInfo->status==2){
  10268. $examSql="update `exam` set `name`='".$name."' ";
  10269. $examSql.=" where exam_group_id='".$exam_group_id."'";
  10270. $this->sConn->createCommand($examSql)->execute();
  10271. if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){
  10272. updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
  10273. }
  10274. $this->redirect($this->createUrl('print/index'));
  10275. }
  10276. //解答题大分值特殊index值
  10277. $tplIndexArrJieDa=array(
  10278. 1=>array(
  10279. 3=>array( //29分
  10280. 1=>3016,
  10281. 2=>3017,
  10282. 3=>3018,
  10283. 4=>3019
  10284. ),
  10285. 4=>array( //49分
  10286. 1=>4016,
  10287. 2=>4017,
  10288. 3=>4018,
  10289. 4=>4019
  10290. )
  10291. ),
  10292. 2=>array(
  10293. 3=>array( //29分
  10294. 1=>3012,
  10295. 2=>3013,
  10296. 3=>3014,
  10297. 4=>3015
  10298. ),
  10299. 4=>array( //49分
  10300. 1=>4012,
  10301. 2=>4013,
  10302. 3=>4014,
  10303. 4=>4015
  10304. )
  10305. )
  10306. );
  10307. //解答题小分值index值
  10308. $tplIndexArr=array(
  10309. 1=>array(
  10310. 11=>array(
  10311. 1=>1016,
  10312. 2=>1017,
  10313. 3=>1018,
  10314. 4=>1019
  10315. ),
  10316. 12=>array(
  10317. 1=>2016,
  10318. 2=>2017,
  10319. 3=>2018,
  10320. 4=>2019
  10321. ),
  10322. 13=>array(
  10323. 1=>16,
  10324. 2=>17,
  10325. 3=>18,
  10326. 4=>19
  10327. )
  10328. ),
  10329. 2=>array(
  10330. 11=>array(
  10331. 1=>1012,
  10332. 2=>1013,
  10333. 3=>1014,
  10334. 4=>1015
  10335. ),
  10336. 12=>array(
  10337. 1=>2012,
  10338. 2=>2013,
  10339. 3=>2014,
  10340. 4=>2015
  10341. ),
  10342. 13=>array(
  10343. 1=>12,
  10344. 2=>13,
  10345. 3=>14,
  10346. 4=>15
  10347. )
  10348. ),
  10349. );
  10350. if($isCustomTpl){
  10351. if($printTypeCard){
  10352. if($jieType>2){
  10353. if(isset($tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType])){
  10354. $tplIndex=$tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType];
  10355. }else{
  10356. // Yii::app()->jump->error('编辑失败,解答题分值格式有误!');
  10357. }
  10358. }else{
  10359. if(!inArray($this->schoolInfo->province_id,array(11,12))){
  10360. $tplIndex=$tplIndexArr[$printTypeCard][13][$dtkType];
  10361. }else{
  10362. if(isset($tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType])){
  10363. $tplIndex=$tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType];
  10364. }
  10365. }
  10366. }
  10367. }
  10368. //判断题量,
  10369. // if (inArray($tplIndex, array(12,16,1012, 1016, 2012, 2016,3016,3012,3007,4012,4016))) {
  10370. // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>90){
  10371. // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!');
  10372. // }
  10373. // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>45){
  10374. // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!');
  10375. // }
  10376. // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){
  10377. // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!');
  10378. // }
  10379. // }else{
  10380. // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>30){
  10381. // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!');
  10382. // }
  10383. // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>30){
  10384. // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!');
  10385. // }
  10386. // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){
  10387. // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!');
  10388. // }
  10389. // }
  10390. //校验分数
  10391. $tianType=Req::post('tianType');
  10392. $jieType=Req::post('jieType');
  10393. // if($tianType){
  10394. // $maxScore=100;
  10395. // if($tianType==2){
  10396. // $maxScore=5;
  10397. // }elseif($tianType==3) {
  10398. // $maxScore = 6;
  10399. // }elseif($tianType==4){
  10400. // $maxScore = 4;
  10401. // }
  10402. // if(isset($tplData['items'][5]) && $tplData['items'][5]['perScores']){
  10403. // foreach($tplData['items'][5]['perScores'] as $val){
  10404. // if($val>$maxScore){
  10405. // Yii::app()->jump->error('试卷的填空题分数超出了当前选择的答题卡分数上限!');
  10406. // }
  10407. // }
  10408. // }
  10409. // }
  10410. // if($jieType){
  10411. // $maxScore=0;
  10412. // if($jieType==1){
  10413. // $maxScore=15;
  10414. // }elseif($jieType==2) {
  10415. // $maxScore = 16;
  10416. // }elseif($jieType==3){
  10417. // $maxScore = 29;
  10418. // }elseif($jieType==4){
  10419. // $maxScore = 49;
  10420. // }
  10421. // if(isset($tplData['items'][7]) && $tplData['items'][7]['perScores']){
  10422. // foreach($tplData['items'][7]['perScores'] as $val){
  10423. // if($val>$maxScore){
  10424. // Yii::app()->jump->error('试卷的解答题分数超出了当前选择的答题卡分数上限!');
  10425. // }
  10426. // }
  10427. // }
  10428. // }
  10429. }
  10430. $transaction = $this->sConn->beginTransaction();
  10431. try{
  10432. $tplData['examDate']=$examDate;
  10433. if($tplDataPaper){
  10434. if($tplDataPaper==1){
  10435. $tplData['paper']=1;
  10436. }else{
  10437. $tplData['paper']=0;
  10438. }
  10439. }
  10440. if($tianType){
  10441. $tplData['tianType']=$tianType;
  10442. }
  10443. if($jieType){
  10444. $tplData['jieType']=$jieType;
  10445. }
  10446. $examSql="update `exam` set `type`='".$type."',`name`='".$name."' ";
  10447. if($tplIndex){
  10448. $examSql.=" , tpl_index='".$tplIndex."'";
  10449. }
  10450. $examSql.=" , tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
  10451. $this->sConn->createCommand($examSql)->execute();
  10452. $transaction->commit();
  10453. if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){
  10454. updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
  10455. }
  10456. if(Yii::app()->params['handle_log_on_off'])
  10457. {
  10458. writeFileLog(jsonEncode(array(
  10459. "examGroupId" => $exam_group_id,
  10460. "operate_project" => 'zsyas2',
  10461. "school_id" => $this->schoolId,
  10462. "title" => '编辑考试',
  10463. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  10464. "operate_method" => $this->action,
  10465. "operate_url" => $this->getRoute(),
  10466. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  10467. "date"=>date('Y-m-d H:i:j')
  10468. )));
  10469. }
  10470. $this->redirect($this->createUrl('print/index'));
  10471. }catch(Exception $e){
  10472. $transaction->rollBack();
  10473. Yii::app()->jump->error('编辑失败!');
  10474. }
  10475. }
  10476. $a3=array(12,16,1012,1016,2012,2016,3012,3016,4012,4016);
  10477. $a4=array(13,17,1013,1017,2013,2017,3013,3017,4013,4017);
  10478. $k8=array(14,18,1014,1018,2014,2018,3014,3018,4014,4018);
  10479. $k16=array(15,19,1015,1019,2015,2019,3015,3019,4015,4019);
  10480. if(in_array($exam_data['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
  10481. //自定义模板
  10482. $data['is_custom_tpl'] = 1;
  10483. }else{
  10484. //非自定义模板
  10485. $data['is_custom_tpl'] = 0;
  10486. }
  10487. if (in_array($exam_data['tpl_index'], Yii::app()->params['no_template_id']) ) {
  10488. //题卡分离
  10489. $data['paper_tpl_type'] = 2;
  10490. }else{
  10491. $data['paper_tpl_type'] = 1;
  10492. }
  10493. $data['dtkType']=0;
  10494. $data['dtk']='';
  10495. if(in_array($exam_data['tpl_index'], $a3)){
  10496. $data['dtk']='A3';
  10497. $data['dtkType']=1;
  10498. }elseif(in_array($exam_data['tpl_index'], $a4)){
  10499. $data['dtk']='A4';
  10500. $data['dtkType']=2;
  10501. }elseif(in_array($exam_data['tpl_index'], $k8)){
  10502. $data['dtk']='8k';
  10503. $data['dtkType']=3;
  10504. }elseif(in_array($exam_data['tpl_index'], $k16)){
  10505. $data['dtk']='16k';
  10506. $data['dtkType']=4;
  10507. }
  10508. $data['examGroupId']=$exam_group_id;
  10509. $data['createType']=$findInfo->create_type;
  10510. $data['name']=$exam_data['name'];
  10511. $data['markType']=$findInfo->mark_type;
  10512. $data['paperType']=$exam_data['tpl_index'];
  10513. $data['type']=$exam_data['type'];
  10514. $data['paper']=$tplData['paper'];
  10515. $data['examDate']=$tplData['examDate'];
  10516. $data['qxkPaperId']=$findInfo->qxk_paper_id;
  10517. $data['examStatus']=$findInfo->status;
  10518. if(isset($tplData['tianType'])){
  10519. $data['tianType']=$tplData['tianType'];
  10520. }else{
  10521. $data['tianType']='';
  10522. }
  10523. if(isset($tplData['jieType'])){
  10524. $data['jieType']=$tplData['jieType'];
  10525. }else{
  10526. $data['jieType']='';
  10527. }
  10528. $data['subjectId']=$exam_data['subject_id'];
  10529. $this->render('modify_exam',$data);
  10530. }
  10531. //在线答题卡批量下载
  10532. public function actionDownloadOnlineBatch(){
  10533. $exam_id = Req::post("exam_id");
  10534. $student_id = Req::post("student_id");
  10535. $result['status']=0;
  10536. if(!$exam_id ) {
  10537. echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
  10538. }
  10539. if(empty($student_id) ) {
  10540. echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生"));
  10541. }
  10542. $studentIds = explode(',',$student_id);
  10543. foreach ($studentIds as $v)
  10544. {
  10545. if($v)
  10546. {
  10547. $student_ids[] = $v;
  10548. }
  10549. }
  10550. $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' and student_id in(".implode(',',$student_ids).")")->queryAll();
  10551. if($studentPdf){
  10552. ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  10553. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  10554. //读取班级
  10555. $class=SClass::model()->find('class_id=:class_id',array(':class_id'=>$exam_data['class_id']));
  10556. $thirdAnswerSheet=$this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$exam_data['exam_group_id']}' ")->queryRow();
  10557. if($thirdAnswerSheet['multiplex_id']){
  10558. $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time=".time()." where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->execute();
  10559. }
  10560. //$tmpFile = tempnam('/tmp', '');
  10561. // $zipFileNameNew=$exam_data['name'].'-'.$class['class_name'].'.zip';
  10562. $zipFileName=$exam_id.'.zip';
  10563. $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j');
  10564. if(!is_dir($dirFile)){
  10565. $this->mkdir($dirFile);
  10566. }
  10567. $dirFile.='/'.$zipFileName;
  10568. if(file_exists($dirFile)){
  10569. unlink($dirFile);
  10570. }
  10571. $zip = new ZipArchive;
  10572. $zip->open($dirFile, ZipArchive::CREATE);
  10573. foreach ($studentPdf as $val) {
  10574. // download file
  10575. // $fileContent = file_get_contents($file);
  10576. if($val['answer_card_online_url']){
  10577. $file=$val['answer_card_online_url'];
  10578. $fileUrl=$file.'?r='.mt_rand(1,999);
  10579. $fileContent=fileGetContents($fileUrl);
  10580. $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent);
  10581. }
  10582. }
  10583. $zip->close();
  10584. $result['status']=1;
  10585. $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile;
  10586. exit(json_encode($result));
  10587. }else{
  10588. $result['result']='答题卡尚未生成';
  10589. exit(json_encode($result));
  10590. }
  10591. }
  10592. //在线答题卡班级下载
  10593. public function actionDownloadOnlineClass(){
  10594. $exam_id = Req::post("exam_id");
  10595. if(!$exam_id ) {
  10596. Yii::app()->jump->error('参数错误!');
  10597. }
  10598. $result['status']=0;
  10599. if(!$exam_id ) {
  10600. echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
  10601. }
  10602. $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' ")->queryAll();
  10603. if($studentPdf){
  10604. $files=array();
  10605. foreach ($studentPdf as $value){
  10606. $files[]=$value['answer_card_online_url'];
  10607. }
  10608. ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
  10609. //$tmpFile = tempnam('/tmp', '');
  10610. $zipFileName=$exam_id.'.zip';
  10611. $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j');
  10612. if(!is_dir($dirFile)){
  10613. $this->mkdir($dirFile);
  10614. }
  10615. $dirFile.='/'.$zipFileName;
  10616. if(file_exists($dirFile)){
  10617. unlink($dirFile);
  10618. }
  10619. $zip = new ZipArchive;
  10620. $zip->open($dirFile, ZipArchive::CREATE);
  10621. foreach ($studentPdf as $val) {
  10622. if($val['answer_card_online_url']){
  10623. $file=$val['answer_card_online_url'];
  10624. $fileUrl=$file.'?r='.mt_rand(1,999);
  10625. $fileContent=fileGetContents($fileUrl);
  10626. $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent);
  10627. }
  10628. }
  10629. $zip->close();
  10630. $result['status']=1;
  10631. $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile;
  10632. exit(json_encode($result));
  10633. }else{
  10634. $result['result']='班级答题卡尚未生成';
  10635. exit(json_encode($result));
  10636. }
  10637. }
  10638. //发送生成在线答题卡任务(班级)
  10639. public function actionSendCreateOnline(){
  10640. $examId=Req::post('exam_id');
  10641. $result['status']=0;
  10642. if(!$examId || !is_numeric($examId)){
  10643. $result['msg']='参数不正确';
  10644. exit(json_encode($result));
  10645. }
  10646. $examInfo = Exam::model()->findByPk($examId);
  10647. if(!$examInfo){
  10648. $result['msg']='未找到考试信息';
  10649. exit(json_encode($result));
  10650. }
  10651. $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
  10652. if(!$onlineCard){
  10653. $result['msg']='考试还没有使用在线答题卡';
  10654. exit(json_encode($result));
  10655. }
  10656. $arr=array(
  10657. 'schoolId'=>$this->schoolId,
  10658. 'examId'=>$examId,
  10659. 'examGroupId'=>$examInfo->exam_group_id,
  10660. 'savedInfoUrl'=>$onlineCard['file_path'],
  10661. 'isClassTask'=>1
  10662. );
  10663. $url=Yii::app()->params['answerCardOnlineCreateUrl'].'classesTopdf';
  10664. $ch = @curl_init();
  10665. $return=array();
  10666. if ($ch) {
  10667. $data = json_encode($arr);
  10668. // 不输出头部
  10669. curl_setopt($ch, CURLOPT_HEADER, 0);
  10670. // curl_exec 获取到的内容不直接输出, 而是返回
  10671. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10672. // 请求重启路由器的地址 传参 进行重启
  10673. curl_setopt($ch, CURLOPT_URL, $url);
  10674. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  10675. curl_setopt($ch, CURLOPT_POST, 1);
  10676. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  10677. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  10678. 'Content-Type: application/json',
  10679. 'Content-Length: ' . strlen($data),
  10680. ));
  10681. if (!curl_errno($ch)) {
  10682. $return = json_decode(curl_exec($ch),1);
  10683. }
  10684. curl_close($ch);
  10685. }
  10686. if(isset($return['code']) && $return['code']==1){
  10687. $result['status']=1;
  10688. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='".$examId."' ")->execute();
  10689. }elseif($return['code']==2){
  10690. $result['msg']='任务队列已存在该任务';
  10691. }elseif(isset($return['msg'])){
  10692. $result['msg']=$return['msg'];
  10693. }
  10694. exit(json_encode($result));
  10695. }
  10696. //发送生成在线答题卡任务(学生)
  10697. public function actionSendCreateOnlineStudents(){
  10698. $examId=Req::post('exam_id');
  10699. $students=Req::post('students');
  10700. $className=Req::post('class_name');
  10701. $checkOrder=Req::post('check_order'); //是否检查订单
  10702. $result['status']=0;
  10703. if(!$examId || !is_numeric($examId)){
  10704. $result['msg']='参数不正确';
  10705. exit(json_encode($result));
  10706. }
  10707. if($checkOrder){
  10708. //检查订单
  10709. $orderClass=0;
  10710. if(!$students){
  10711. $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
  10712. if($allClassStudents){
  10713. foreach ($allClassStudents as $student){
  10714. $students[]=$student['student_id'];
  10715. if(!$orderClass) $orderClass=$student['class_id'];
  10716. }
  10717. }
  10718. }
  10719. $semester=new SSemester();
  10720. $nowsem=$semester->getCurrentSemester();
  10721. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
  10722. $subjectId=Yii::app()->session['session_subject_id'];
  10723. if(in_array($subjectId,$this->mathSubjectId)){
  10724. $subjectId=3;
  10725. }
  10726. $intarr=array(
  10727. "schoolId"=>$this->schoolId,
  10728. "clazzId"=>$orderClass,
  10729. "semester"=>$nowsem['refer_code'],
  10730. "grade"=>$classinfo['grade'],
  10731. "students"=>array(),
  10732. "examTime"=>time(),
  10733. "classify"=>1,
  10734. "subject"=>$subjectId,
  10735. );
  10736. $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
  10737. if(!$students){
  10738. $result['msg']='当前班级没查询到订单';
  10739. exit(json_encode($result));
  10740. }
  10741. }
  10742. if(!$students || !is_array($students)){
  10743. $result['msg']='请选择要生成的学生';
  10744. exit(json_encode($result));
  10745. }
  10746. $examInfo = Exam::model()->findByPk($examId);
  10747. if(!$examInfo){
  10748. $result['msg']='未找到考试信息';
  10749. exit(json_encode($result));
  10750. }
  10751. $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
  10752. if(!$onlineCard){
  10753. $result['msg']='考试还没有使用在线答题卡';
  10754. exit(json_encode($result));
  10755. }
  10756. $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id='{$examId}' and is_del=0 and student_id in(".implode(',',$students).")")->queryAll();
  10757. if($postStudents){
  10758. foreach ($postStudents as $key =>$val){
  10759. $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
  10760. $postStudents[$key]['student_name']=$studentInfo['realname'];
  10761. $postStudents[$key]['class_name']=$className;
  10762. if($examInfo->school_card_status==1){
  10763. $postStudents[$key]['student_card']=$val['school_student_card'];
  10764. }
  10765. }
  10766. }
  10767. $error=array();
  10768. if(count($postStudents)>100){
  10769. $newPushArr=array();
  10770. $newPushArr=array_chunk($postStudents,100);
  10771. foreach ($newPushArr as $item){
  10772. $arr=array(
  10773. 'schoolId'=>$this->schoolId,
  10774. 'examId'=>$examId,
  10775. 'examGroupId'=>$examInfo->exam_group_id,
  10776. 'savedInfoUrl'=>$onlineCard['file_path'],
  10777. 'students'=>$item,
  10778. 'groupId'=>$this->schoolGroupId,
  10779. 'qrcode'=>$onlineCard['is_qrcode_online'],
  10780. 'semesterId'=>$this->semesterId
  10781. );
  10782. $key='zsyas2-online-card-notify';
  10783. $return=sendDataToKafka($key,$arr);
  10784. $updateStudentId=array();
  10785. $updateStudentName=array();
  10786. foreach ($item as $v){
  10787. $updateStudentId[]=$v['student_id'];
  10788. $updateStudentName[]=$v['student_name'];
  10789. }
  10790. if($return){
  10791. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $updateStudentId) . ") ")->execute();
  10792. }else{
  10793. $error=array_merge($error,$updateStudentName);
  10794. //$result['msg']='发送任务失败';
  10795. }
  10796. }
  10797. if($error){
  10798. $result['status'] = 1;
  10799. $result['msg'] = '部分学生发送失败';
  10800. }else{
  10801. $result['status'] = 1;
  10802. }
  10803. }else{
  10804. $arr=array(
  10805. 'schoolId'=>$this->schoolId,
  10806. 'examId'=>$examId,
  10807. 'examGroupId'=>$examInfo->exam_group_id,
  10808. 'savedInfoUrl'=>$onlineCard['file_path'],
  10809. 'students'=>$postStudents,
  10810. 'groupId'=>$this->schoolGroupId,
  10811. 'qrcode'=>$onlineCard['is_qrcode_online'],
  10812. 'semesterId'=>$this->semesterId
  10813. );
  10814. $key='zsyas2-online-card-notify';
  10815. $return=sendDataToKafka($key,$arr);
  10816. if($return){
  10817. $result['status'] = 1;
  10818. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $students) . ") ")->execute();
  10819. }else{
  10820. $result['msg']='发送任务失败';
  10821. }
  10822. }
  10823. $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
  10824. $this->schoolManager->saveExamProcess($examInfo->exam_group_id,13,time(),$examId,$examInfo->class_id);
  10825. exit(json_encode($result));
  10826. }
  10827. //发送生成在线答题卡任务(全部学生)
  10828. public function actionSendCreateOnlineAllStudents(){
  10829. $examGroupId=Req::post('exam_group_id');
  10830. $result['status']=0;
  10831. if(!$examGroupId || !is_numeric($examGroupId)){
  10832. $result['msg']='参数不正确';
  10833. exit(json_encode($result));
  10834. }
  10835. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  10836. $examIds = array();
  10837. $examClass=array();
  10838. if($exam_data) {
  10839. foreach ($exam_data as $val) {
  10840. $examIds[] = $val['exam_id'];
  10841. $examClass[$val['exam_id']]=$val['class_id'];
  10842. }
  10843. }
  10844. if(!$examIds){
  10845. $result['msg']='未找到考试信息';
  10846. exit(json_encode($result));
  10847. }
  10848. $onlineCard=$this->schoolManager->getAnswerSheetOnline($examGroupId);
  10849. if(!$onlineCard){
  10850. $result['msg']='考试还没有使用在线答题卡';
  10851. exit(json_encode($result));
  10852. }
  10853. $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0 ")->queryAll();
  10854. if($postStudents){
  10855. foreach ($postStudents as $key =>$val){
  10856. $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
  10857. $postStudents[$key]['student_name']=$studentInfo['realname'];
  10858. $classInfo=$this->sConn->createCommand("select `class_name` from class where class_id='{$val['class_id']}'")->queryRow();
  10859. $postStudents[$key]['class_name']=$classInfo['class_name'];
  10860. if($exam_data[0]['school_card_status']==1){
  10861. $postStudents[$key]['student_card']=$val['school_student_card'];
  10862. }
  10863. }
  10864. }
  10865. $error=array();
  10866. if(count($postStudents)>100){
  10867. $newPushArr=array();
  10868. $newPushArr=array_chunk($postStudents,100);
  10869. foreach ($newPushArr as $item){
  10870. $arr=array(
  10871. 'schoolId'=>$this->schoolId,
  10872. 'examGroupId'=>$examGroupId,
  10873. 'savedInfoUrl'=>$onlineCard['file_path'],
  10874. 'students'=>$item,
  10875. 'groupId'=>$this->schoolGroupId,
  10876. 'qrcode'=>$onlineCard['is_qrcode_online'],
  10877. 'semesterId'=>$this->semesterId
  10878. );
  10879. $key='zsyas2-online-card-notify';
  10880. $return=sendDataToKafka($key,$arr);
  10881. $updateStudentId=array();
  10882. $updateStudentName=array();
  10883. foreach ($item as $v){
  10884. $updateStudentId[]=$v['student_id'];
  10885. $updateStudentName[]=$v['student_name'];
  10886. }
  10887. if($return){
  10888. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") and student_id in(" . implode(',', $updateStudentId) . ") ")->execute();
  10889. $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
  10890. }else{
  10891. $error=array_merge($error,$updateStudentName);
  10892. //$result['msg']='发送任务失败';
  10893. }
  10894. }
  10895. if($error){
  10896. $result['status'] = 1;
  10897. $result['msg'] = '部分学生发送失败';
  10898. exit(json_encode($result));
  10899. }else{
  10900. $result['status'] = 1;
  10901. exit(json_encode($result));
  10902. }
  10903. }else{
  10904. $arr=array(
  10905. 'schoolId'=>$this->schoolId,
  10906. 'examGroupId'=>$examGroupId,
  10907. 'savedInfoUrl'=>$onlineCard['file_path'],
  10908. 'students'=>$postStudents,
  10909. 'groupId'=>$this->schoolGroupId,
  10910. 'qrcode'=>$onlineCard['is_qrcode_online'],
  10911. 'semesterId'=>$this->semesterId
  10912. );
  10913. $key='zsyas2-online-card-notify';
  10914. $return=sendDataToKafka($key,$arr);
  10915. if($return){
  10916. $result['status'] = 1;
  10917. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") ")->execute();
  10918. $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
  10919. }else{
  10920. $result['msg']='发送任务失败';
  10921. }
  10922. }
  10923. foreach ($examClass as $examId =>$classId){
  10924. $this->schoolManager->saveExamProcess($examGroupId,13,time(),$examId,$classId);
  10925. }
  10926. exit(json_encode($result));
  10927. }
  10928. // // 更新试卷在线答题卡打印状态、时间
  10929. public function actionUpdateOnlinePaperPrintTime() {
  10930. $cid = Req::post("cid");
  10931. $eid = Req::post("eid");
  10932. $type = Req::post("type");
  10933. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type));
  10934. if (!empty($getResult)) {
  10935. $getResult->is_print_online = 1;
  10936. if ($getResult->save()) {
  10937. exit('1');
  10938. } else {
  10939. exit('2');
  10940. }
  10941. }
  10942. }
  10943. //客户端打印在线答题卡
  10944. public function actionPrintPdfOnline(){
  10945. $examId=Req::post('exam_id');
  10946. $students=Req::post('students');
  10947. $className=Req::post('class_name');
  10948. $checkOrder=Req::post('check_order');
  10949. $result['success']=0;
  10950. if(!$examId || !is_numeric($examId)){
  10951. $result['msg']='参数不正确';
  10952. exit(json_encode($result));
  10953. }
  10954. $examInfo = Exam::model()->findByPk($examId);
  10955. if(!$examInfo){
  10956. $result['msg']='未找到考试信息';
  10957. exit(json_encode($result));
  10958. }
  10959. $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
  10960. if(!$onlineCard){
  10961. $result['msg']='考试还没有使用在线答题卡';
  10962. exit(json_encode($result));
  10963. }
  10964. if($checkOrder){
  10965. //检查订单
  10966. $orderClass=0;
  10967. if(!$students){
  10968. $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
  10969. if($allClassStudents){
  10970. foreach ($allClassStudents as $student){
  10971. $students[]=$student['student_id'];
  10972. if(!$orderClass) $orderClass=$student['class_id'];
  10973. }
  10974. }
  10975. }
  10976. $semester=new SSemester();
  10977. $nowsem=$semester->getCurrentSemester();
  10978. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
  10979. $intarr=array(
  10980. "schoolId"=>$this->schoolId,
  10981. "clazzId"=>$orderClass,
  10982. "semester"=>$nowsem['refer_code'],
  10983. "grade"=>$classinfo['grade'],
  10984. "students"=>array(),
  10985. "examTime"=>time(),
  10986. "classify"=>1,
  10987. "subject"=>3,
  10988. );
  10989. $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
  10990. }
  10991. if(!$students || !is_array($students)){
  10992. $students=array();
  10993. $studentPaperRelation=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id='".$examId."' and is_del=0 ")->queryAll();
  10994. if($studentPaperRelation){
  10995. foreach ($studentPaperRelation as $val){
  10996. $students[]=$val['student_id'];
  10997. }
  10998. }
  10999. }
  11000. if(!$students){
  11001. $result['msg']='考试班级没有学生';
  11002. exit(json_encode($result));
  11003. }
  11004. $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll();
  11005. $studentData=array();
  11006. if($studentPdf){
  11007. foreach ($studentPdf as $val){
  11008. $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
  11009. $studentData[]=array(
  11010. 'studentName'=>$studentInfo['realname'],
  11011. 'studentCode'=>$val['student_id'],
  11012. 'pdfUrl'=>$val['answer_card_online_url']
  11013. );
  11014. }
  11015. }else{
  11016. $result['msg']='答题卡还未生成';
  11017. exit(json_encode($result));
  11018. }
  11019. $result['success']=1;
  11020. $result['className']=$className;
  11021. $result['students']=$studentData;
  11022. $result['studentIds']=$students;
  11023. exit(json_encode($result));
  11024. }
  11025. /**
  11026. * 英语外刊阅读列表
  11027. */
  11028. public function actionEnglish_reading(){
  11029. Url::clean();
  11030. $data = array();
  11031. $printName = Req::get("name");
  11032. $classId = Req::get("classId");
  11033. $grade = (int)Req::get("grade");
  11034. $cg = (int)Req::get('cg');
  11035. $pt = (int)Req::get('pt');
  11036. if(!$cg) $cg=1;
  11037. $newCondition = array();
  11038. if($grade){
  11039. $newCondition[] = 'er.grade='.$grade;
  11040. }
  11041. if($printName){
  11042. $newCondition[] = 'er.name like "%'.$printName.'%"';
  11043. }
  11044. if($classId){
  11045. $newCondition[] = 'er.class_id='.$classId;
  11046. }
  11047. $newCondition[] = 'ers.category='.$cg;
  11048. if($cg==2){
  11049. $newCondition[] = 'ers.product_type='.$pt;
  11050. }
  11051. $resultList = $this->schoolManager->getEnglishReading($newCondition,array('er.create_time desc','er.week_id desc'),9);
  11052. $printList = array();
  11053. if($resultList["rs"]){
  11054. foreach ($resultList['rs'] as $k=>$v) {
  11055. $isTeacher=false;
  11056. //仅经典模式中,基础宝、外刊宝-共性外刊、热点宝-共性外刊有教师讲义
  11057. if($v['recommend_mode']==1 && (($v['product_type']==1) || (in_array($v['product_type'],array(2,3)) && $v['type']==2)) ){
  11058. $isTeacher=true;
  11059. }
  11060. $v['is_teacher']=$isTeacher;
  11061. $printList[$k]=$v;
  11062. }
  11063. }
  11064. if (empty($grade)) {
  11065. $grade = 'ALL';
  11066. }
  11067. $classes = $this->schoolManager->getClasses($grade);
  11068. $data['pages'] = $resultList['pager'];
  11069. $data['page_total'] = $resultList['pager']->rowsCount;
  11070. $data['printList'] = $printList;
  11071. $data["printName"] = $printName;
  11072. $data["classes"] = $classes;
  11073. $data["classId"] = $classId;
  11074. $data["grade"] = $grade;
  11075. $data['printType'] = 'mrv';
  11076. $data['category'] = $cg;
  11077. $data['eProductType'] = $pt;
  11078. //debug($printList);
  11079. $this->render('english_reading',$data);
  11080. }
  11081. /**
  11082. * 英语外刊阅读高一高二设置
  11083. */
  11084. public function actionEnglishReadingSetting(){
  11085. $data = array();
  11086. $time = time();
  11087. // $data['year'] = $year = date("Y");
  11088. // $data['month'] = $month = (int)date("m");
  11089. // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  11090. $data_msg = $this->getWeekOnMonth();
  11091. $data['year'] = $data_msg['year'];
  11092. $data['month'] = $data_msg['month'];
  11093. $data['week'] = numToUpper($data_msg['week']);
  11094. $textboookTree = new MongodbEnglishTree();
  11095. $criteria = new EMongoCriteria();
  11096. $textbookData = $textboookTree->find($criteria,array());
  11097. if($textbookData){
  11098. foreach ($textbookData as $doc) {
  11099. foreach($doc->attributes as $key => $value){
  11100. if($key !== '_id'){
  11101. if(isset($value['textbook_id']) && isset($value['name'])){
  11102. $data['textbookNames'][$value['textbook_id']] = $value['name'];
  11103. if(!isset($textbookId)){
  11104. $textbookId = $value['textbook_id'];
  11105. }
  11106. if($textbookId == $value['textbook_id']){
  11107. if(isset($value['module']) && $value['module']){
  11108. foreach($value['module'] as $kk=>$vv){
  11109. $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  11110. if(!isset($moduleId)){
  11111. $moduleId = $vv['textbook_module_id'];
  11112. }
  11113. if($moduleId == $vv['textbook_module_id']){
  11114. if(isset($vv['unit']) && $vv['unit']){
  11115. foreach($vv['unit'] as $kkk=>$vvv){
  11116. $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  11117. }
  11118. }
  11119. }
  11120. }
  11121. }
  11122. }
  11123. }
  11124. }
  11125. }
  11126. }
  11127. }
  11128. $data['printType'] = 'english_reading_setting';
  11129. $this->render('english_reading_setting',$data);
  11130. }
  11131. /**
  11132. * 设置英语外刊阅读高一高二
  11133. */
  11134. public function actionAjaxSaveEnglishReading(){
  11135. $result = array();
  11136. $error = array();
  11137. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  11138. $error[] = '错误的来源!';
  11139. }else{
  11140. $grade=(int)Req::post('grade');
  11141. $textbookId = (int)Req::post('textbookId');
  11142. $moduleId = (int)Req::post('moduleId');
  11143. $unitId = (int)Req::post('unitId');
  11144. $moduleName = (string)Req::post('moduleName');
  11145. $unitName = (string)Req::post('unitName');
  11146. $classIds = Req::post('selectClassIds');
  11147. $itemIds = (array)Req::post('selectedItemIds');
  11148. $type = (int)Req::post('type');
  11149. $level = (int)Req::post('level');
  11150. $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
  11151. if($itemIds && ($textbookId || $moduleId || $unitId)){
  11152. $error[] = '设置错误1';
  11153. }
  11154. if(!$itemIds && (!$textbookId || !$moduleId || !$unitId)){
  11155. $error[] = '设置错误2';
  11156. }
  11157. if(!$grade){
  11158. $error[] = '请选择年级';
  11159. }
  11160. if(!$classIds){
  11161. $error[] = '请选择班级';
  11162. }
  11163. if(!in_array($type,array(1,2))){
  11164. $error[] = '外刊类别错误';
  11165. }
  11166. if($type == 2){
  11167. if(!in_array($level,array(1,2,3))){
  11168. $error[] = '外刊分级错误';
  11169. }
  11170. }
  11171. }
  11172. if(!$error){
  11173. $time = time();
  11174. // $month = (int)date("m");
  11175. // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  11176. // $week = date("W");
  11177. // $year = date("Y");
  11178. $date_msg = $this->getWeekOnMonth();
  11179. $year = $date_msg["year"];
  11180. $month = $date_msg["month"];
  11181. $week = $date_msg["week"];
  11182. $weekUpper = numToUpper($week);
  11183. $strModel = new SStudentClassRelation();
  11184. $transaction = $this->sConn->beginTransaction();
  11185. try{
  11186. $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"';
  11187. $reading_id = getUniqueId($this->schoolId);
  11188. $this->sConn->createCommand()->insert('english_reading_setting',array(
  11189. 'reading_id'=>$reading_id,
  11190. 'grade' => $grade,
  11191. 'semester_id' => $this->semesterId,
  11192. 'textbook_id' => $textbookId,
  11193. 'module_id' => $moduleId,
  11194. 'unit_id' => $unitId,
  11195. 'special_ids' => implode(',',$itemIds),
  11196. 'create_time' => $time,
  11197. 'type' => $type,
  11198. 'level'=>$level,
  11199. 'is_answer_separate'=>$isAnswerSeparate
  11200. ));
  11201. foreach($classIds as $k=>$v){
  11202. $weekId = getUniqueId($this->schoolId);
  11203. $this->sConn->createCommand()->insert('english_reading',array(
  11204. 'week_id' => $weekId,
  11205. 'name' => $weekName,
  11206. 'class_id' => $v,
  11207. 'grade' => $grade,
  11208. 'semester_id' => $this->semesterId,
  11209. 'year_num' => $year,
  11210. 'week_num' => $week,
  11211. 'month_num' => $month,
  11212. 'reading_id'=>$reading_id,
  11213. 'create_time' => $time,
  11214. ));
  11215. //获取班级学生
  11216. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  11217. if($stuData){
  11218. foreach($stuData as $kk=>$vv){
  11219. $this->sConn->createCommand()->insert('english_reading_student',array(
  11220. 'week_id' => $weekId,
  11221. 'student_id' => $vv['student_id'],
  11222. ));
  11223. }
  11224. }
  11225. }
  11226. $transaction->commit();
  11227. }catch(Exception $e){
  11228. $transaction->rollBack();
  11229. if (YII_ENV == 'production') {
  11230. $error[] = '系统错误[SQL]';
  11231. } else {
  11232. $error[] = $e->getMessage();
  11233. }
  11234. }
  11235. }
  11236. if($error){
  11237. echo json_encode(array('status'=>0,'error'=>$error));exit;
  11238. }else{
  11239. echo json_encode(array('status'=>1));exit;
  11240. }
  11241. }
  11242. /**
  11243. * 外刊主题语境(高三)
  11244. */
  11245. public function actionEnglishReading3(){
  11246. $data = array();
  11247. $time = time();
  11248. $theme_context = array();
  11249. // $data['year'] = $year = date("Y");
  11250. // $data['month'] = $month = (int)date("m");
  11251. // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  11252. $data_msg = $this->getWeekOnMonth();
  11253. $data['year'] = $data_msg['year'];
  11254. $data['month'] = $data_msg['month'];
  11255. $data['week'] = numToUpper($data_msg['week']);
  11256. $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3));
  11257. if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){
  11258. $i = 0;
  11259. foreach($theme_context_data['data'] as $k=>$v){
  11260. if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){
  11261. $theme_context[$i]['label_id'] = $v['label_id'];
  11262. $theme_context[$i]['content'] = $v['content'];
  11263. $i++;
  11264. }
  11265. }
  11266. }
  11267. $data['theme_context'] = $theme_context;
  11268. $data['printType'] = 'englishreading3';
  11269. $this->render('english_reading_3',$data);
  11270. }
  11271. /**
  11272. * 外刊时间有限设置
  11273. */
  11274. public function actionEnglishReadingTime(){
  11275. $data = array();
  11276. $theme_context = array();
  11277. $data_msg = $this->getWeekOnMonth();
  11278. $data['year'] = $data_msg['year'];
  11279. $data['month'] = $data_msg['month'];
  11280. $data['week'] = numToUpper($data_msg['week']);
  11281. // $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3));
  11282. // if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){
  11283. // $i = 0;
  11284. // foreach($theme_context_data['data'] as $k=>$v){
  11285. // if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){
  11286. // $theme_context[$i]['label_id'] = $v['label_id'];
  11287. // $theme_context[$i]['content'] = $v['content'];
  11288. // $i++;
  11289. // }
  11290. // }
  11291. // }
  11292. // $data['theme_context'] = $theme_context;
  11293. $data['printType'] = 'englishreadingtime';
  11294. $this->render('english_reading_time',$data);
  11295. }
  11296. /**
  11297. * 外刊时间优先推送设置
  11298. */
  11299. public function actionAjaxSaveReadingTime(){
  11300. $result = array();
  11301. $error = array();
  11302. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  11303. $error[] = '错误的来源!';
  11304. }else{
  11305. $grade=(int)Req::post('grade');
  11306. $classIds = Req::post('selectClassIds');
  11307. $type = (int)Req::post('type');
  11308. $level = (int)Req::post('level');
  11309. $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
  11310. if(!$grade){
  11311. $error[] = '请选择年级';
  11312. }
  11313. if(!$classIds){
  11314. $error[] = '请选择班级';
  11315. }
  11316. if(!in_array($type,array(1,2))){
  11317. $error[] = '外刊类别错误';
  11318. }
  11319. if($type == 2){
  11320. if(!in_array($level,array(1,2,3))){
  11321. $error[] = '外刊分级错误';
  11322. }
  11323. }
  11324. }
  11325. if(!$error){
  11326. $time = time();
  11327. $date_msg = $this->getWeekOnMonth();
  11328. $year = $date_msg["year"];
  11329. $month = $date_msg["month"];
  11330. $week = $date_msg["week"];
  11331. $weekUpper = numToUpper($week);
  11332. $strModel = new SStudentClassRelation();
  11333. $transaction = $this->sConn->beginTransaction();
  11334. try{
  11335. $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"';
  11336. $reading_id = getUniqueId($this->schoolId);
  11337. $this->sConn->createCommand()->insert('english_reading_setting',array(
  11338. 'reading_id'=>$reading_id,
  11339. 'grade' => $grade,
  11340. 'semester_id' => $this->semesterId,
  11341. 'textbook_id' => 0,
  11342. 'module_id' => 0,
  11343. 'unit_id' => 0,
  11344. 'special_ids' => '',
  11345. 'create_time' => $time,
  11346. 'type' => $type,
  11347. 'level'=>$level,
  11348. 'is_answer_separate'=>$isAnswerSeparate,
  11349. 'is_time_priority' => 1
  11350. ));
  11351. foreach($classIds as $k=>$v){
  11352. $weekId = getUniqueId($this->schoolId);
  11353. $this->sConn->createCommand()->insert('english_reading',array(
  11354. 'week_id' => $weekId,
  11355. 'name' => $weekName,
  11356. 'class_id' => $v,
  11357. 'grade' => $grade,
  11358. 'semester_id' => $this->semesterId,
  11359. 'year_num' => $year,
  11360. 'week_num' => $week,
  11361. 'month_num' => $month,
  11362. 'reading_id'=>$reading_id,
  11363. 'create_time' => $time,
  11364. ));
  11365. //获取班级学生
  11366. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  11367. if($stuData){
  11368. foreach($stuData as $kk=>$vv){
  11369. $this->sConn->createCommand()->insert('english_reading_student',array(
  11370. 'week_id' => $weekId,
  11371. 'student_id' => $vv['student_id'],
  11372. ));
  11373. }
  11374. }
  11375. }
  11376. $transaction->commit();
  11377. }catch(Exception $e){
  11378. $transaction->rollBack();
  11379. if (YII_ENV == 'production') {
  11380. $error[] = '系统错误[SQL]';
  11381. } else {
  11382. $error[] = $e->getMessage();
  11383. }
  11384. }
  11385. }
  11386. if($error){
  11387. echo json_encode(array('status'=>0,'error'=>$error));exit;
  11388. }else{
  11389. echo json_encode(array('status'=>1));exit;
  11390. }
  11391. }
  11392. /*
  11393. * 获取外刊美文产品班级
  11394. */
  11395. public function actionAjaxGetClassesBySettingReading(){
  11396. $grade=(int)Req::post('grade');
  11397. $result=$this->getClassesBySettingReading($grade);
  11398. echo json_encode($result);exit;
  11399. }
  11400. /*
  11401. * 获取外刊美文产品班级
  11402. */
  11403. public function getClassesBySettingReading($grade=1,$gc=1,$pt=1){
  11404. $result = array();
  11405. $error = array();
  11406. //$grade=(int)Req::post('grade');
  11407. // $year = date("Y");
  11408. // $month = (int)date("m");
  11409. // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  11410. // $week = date("W");
  11411. $data_msg = $this->getWeekOnMonth();
  11412. $year = $data_msg['year'];
  11413. $month = $data_msg['month'];
  11414. $week = $data_msg['week'];
  11415. //获取班级
  11416. $hasSettingClassIds = array();
  11417. $sql="select class_id,count(*) as count from english_reading er";
  11418. $sql.=" left join english_reading_setting ers on er.reading_id= ers.reading_id ";
  11419. $sql.=" where year_num = {$year} and week_num = {$week} and month_num = {$month} ";
  11420. if($gc==1){
  11421. $sql.=" and ers.category=1";
  11422. }else{
  11423. $sql.=" and ers.category=2 and product_type='{$pt}'";
  11424. }
  11425. $sql.=" group by class_id";
  11426. //$sql = "select class_id,count(*) count from english_reading where year_num = {$year} and week_num = {$week} and month_num = {$month} group by class_id";
  11427. $data = $this->sConn->createCommand($sql)->queryAll();
  11428. if($data){
  11429. foreach($data as $k=>$v){
  11430. if($v['count'] > 0){
  11431. $hasSettingClassIds[] = (string)$v['class_id'];
  11432. }
  11433. }
  11434. }
  11435. if($grade){
  11436. //先判断是否走班
  11437. $zouban_sql = "select * from classified where subject_id = 8 and semester_id = '{$this->semesterId}' and grade = {$grade} and `status` = 1";
  11438. $classified_data = $this->sConn->createCommand($zouban_sql)->queryRow();
  11439. if($classified_data){
  11440. $is_zouban = 1;
  11441. $class_type = 2;
  11442. $sql = "select c.class_id,c.class_name "
  11443. . "from class c join class_subject_relation csr on c.class_id=csr.class_id "
  11444. . "where c.semester_id='{$this->semesterId}' and csr.subject_id = 8 and c.grade = {$grade} and c.class_type = 2 and c.is_hide=0 group by c.class_id";
  11445. }else{
  11446. $is_zouban = 0;
  11447. $class_type = 1;
  11448. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
  11449. }
  11450. // $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = {$class_type} and is_hide=0";
  11451. $data = $this->sConn->createCommand($sql)->queryAll();
  11452. if($data){
  11453. $i = 0;
  11454. foreach($data as $k => $v){
  11455. $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0";
  11456. $class_student = $this->sConn->createCommand($sql)->queryRow();
  11457. if($class_student && $class_student['count']>0){
  11458. $result[$i]['class_id'] = $v['class_id'];
  11459. $result[$i]['class_name'] = $v['class_name'];
  11460. if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
  11461. $result[$i]['status'] = 1;
  11462. }else{
  11463. $result[$i]['status'] = 0;
  11464. }
  11465. $i++;
  11466. }
  11467. }
  11468. }
  11469. }
  11470. return $result;
  11471. }
  11472. /**
  11473. * 下载外刊美文个性化学习宝
  11474. */
  11475. public function actionGetEnglishReadingFile(){
  11476. $weekId = (string)Req::get("weekId");
  11477. $studentsIds = (string)Req::get("studentsIds");
  11478. $params = array();
  11479. if(!$weekId){
  11480. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  11481. exit();
  11482. }
  11483. if(!$studentsIds){
  11484. $studentsIds = array();
  11485. $sql = "select student_id from english_reading_student where week_id = '{$weekId}' and is_week_pdf = 1";
  11486. $stuArr = $this->sConn->createCommand($sql)->queryAll();
  11487. if($stuArr){
  11488. foreach($stuArr as $k=>$v){
  11489. $studentsIds[] = $v['student_id'];
  11490. }
  11491. }
  11492. }else{
  11493. $studentsIds = explode(',',$studentsIds);
  11494. }
  11495. if(!$studentsIds || empty($studentsIds)){
  11496. echo json_encode(array("success" => 0, "message" => "无生成的学生"));
  11497. exit();
  11498. }
  11499. $params['weekId'] = $weekId;
  11500. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  11501. if(!$apiUrl){
  11502. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  11503. exit();
  11504. }
  11505. $sql = "select class_id,grade,create_time,semester_id from english_reading where week_id = '{$weekId}'";
  11506. $msg = $this->sConn->createCommand($sql)->queryRow();
  11507. $Sem=new SSemester();
  11508. $code= $Sem->conn->createQuery()
  11509. ->from('semester')
  11510. ->where("semester_id = '".$msg['semester_id']."'")
  11511. ->limit(1)
  11512. ->query()
  11513. ->read();
  11514. $intarr=array(
  11515. "schoolId"=>$this->schoolId,
  11516. "clazzId"=>$msg['class_id'],
  11517. "semester"=>$code['refer_code'],
  11518. "grade"=>$msg['grade'],
  11519. "students"=>$studentsIds,
  11520. "examTime"=>$msg['create_time'],
  11521. "classify"=>6,
  11522. "subject"=>8
  11523. );
  11524. $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
  11525. if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
  11526. if($studentsIds){
  11527. $params["studentIds"] = $studentsIds;
  11528. }
  11529. }else{
  11530. if(Yii::app()->params["limit_open"]){
  11531. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  11532. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  11533. if(!$rs){
  11534. Yii::app()->jump->error("接口错误");
  11535. }
  11536. if($rs->errCode!="00"){
  11537. echo json_encode(array("success" => 0, "message" => $rs->errMsg));
  11538. exit();
  11539. }
  11540. if(!empty($rs->data)){
  11541. $params["studentIds"]=$rs->data;
  11542. if(count($rs->data)<count($intarr['students'])){
  11543. $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
  11544. }
  11545. } else{
  11546. echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
  11547. exit();
  11548. }
  11549. }else{
  11550. if($studentsIds){
  11551. $params["studentIds"] = $studentsIds;
  11552. }
  11553. }
  11554. }
  11555. $params['schoolId'] = $this->schoolId;
  11556. $params['type'] = 3;
  11557. $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
  11558. if(!($rs = json_decode($rs))){
  11559. $rs = array(
  11560. "success" => 0,
  11561. "message" => "请求接口失败",
  11562. );
  11563. }else{
  11564. //更新下载时间
  11565. if($rs->success==1 || $rs->success==2){
  11566. $time = time();
  11567. if($studentsIds){
  11568. $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).") and week_download_time = 0";
  11569. $this->sConn->createCommand($sql)->execute();
  11570. }
  11571. }
  11572. }
  11573. // if(isset($rs->downloadPath)){
  11574. // if (YII_ENV == 'pro' || YII_ENV == 'production') {
  11575. // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
  11576. // }
  11577. // }
  11578. echo json_encode($rs);exit;
  11579. }
  11580. /**
  11581. * 获取当天是第几周(按周一计算)
  11582. */
  11583. public function getWeekOnMonth(){
  11584. $a = time();
  11585. $monDay = $a - ((date('w',$a) == 0 ? 7 : date('w',$a)) - 1) * 24 * 3600;//当前时间周一的时间
  11586. $a_month = date('n',$monDay);//当前周一月份
  11587. $a_year = date('Y',$monDay);//当前周一年份
  11588. $date_now=date('j',$monDay); //得到周一是几号
  11589. $cal_result=ceil($date_now/7); //计算是第几周
  11590. return array("year"=>$a_year,"month"=>$a_month,"week"=>$cal_result);
  11591. }
  11592. /**
  11593. * 重置外刊美文
  11594. */
  11595. public function actionResetEnglishReading(){
  11596. $readingId = (string)Req::get("readingId");
  11597. $data = array();
  11598. $resetCount = 0;
  11599. $productName='';
  11600. if($readingId){
  11601. $sql = "select er.week_id,er.`name`,er.class_id,er.is_reset,c.class_name,ers.product_type,ers.category from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.reading_id = '{$readingId}'";
  11602. $msg = $this->sConn->createCommand($sql)->queryAll();
  11603. if($msg){
  11604. $i=0;
  11605. foreach($msg as $k=>$v){
  11606. if($v["is_reset"]){
  11607. $resetCount++;
  11608. }
  11609. if(!$productName){
  11610. if($v['category']==2){
  11611. if($v['product_type']==1){
  11612. $productName='基础宝';
  11613. }elseif($v['product_type']==2){
  11614. $productName='外刊宝';
  11615. }elseif($v['product_type']==3){
  11616. $productName='热点宝';
  11617. }
  11618. }else{
  11619. $productName='外刊宝';
  11620. }
  11621. }
  11622. $weekId = $v["week_id"];
  11623. $data[$i]['total_count'] = 0;
  11624. $data[$i]['create_count'] = 0;
  11625. $data[$i]['name'] = $v["name"];
  11626. $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_reading_student where week_id = '{$weekId}'";
  11627. $msg_student = $this->sConn->createCommand($sql)->queryRow();
  11628. if($msg_student){
  11629. $data[$i]['total_count'] = $msg_student["total_count"];
  11630. $data[$i]['create_count'] = $msg_student["create_count"];
  11631. }
  11632. $data[$i]['week_id'] = $weekId;
  11633. $data[$i]['class_name'] = $v["class_name"];
  11634. $data[$i]['is_reset'] = $v["is_reset"];
  11635. $i++;
  11636. }
  11637. }
  11638. }
  11639. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){
  11640. $resetCount = 0;
  11641. }
  11642. // debug($data);
  11643. $this->render('english_reading_reset',array("data"=>$data,"resetCount"=>$resetCount,"readingId"=>$readingId,'productName'=>$productName));
  11644. }
  11645. /**
  11646. * 重置外刊美文功能
  11647. */
  11648. public function actionAjaxResetEnglishReading(){
  11649. $result = array();
  11650. $error = array();
  11651. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  11652. $error[] = '错误的来源!';
  11653. }else{
  11654. $classExam=Req::post('classExam');
  11655. if(!$classExam || !is_array($classExam)){
  11656. $error[] = '请选择班级';
  11657. }
  11658. $redingId=Req::post('readingId');
  11659. if(!$redingId){
  11660. $error[] = '请刷新后再尝试';
  11661. }
  11662. }
  11663. if(!$error){
  11664. $time = time();
  11665. $transaction = $this->sConn->beginTransaction();
  11666. try{
  11667. $sql = "select reading_id,week_id,is_new_version,grade from english_reading where reading_id='{$redingId}' and week_id in (".implode(',',$classExam).")";
  11668. $englishReading = $this->sConn->createCommand($sql)->queryAll();
  11669. if(!$englishReading){
  11670. throw new Exception('无重置外刊阅读推送数据');
  11671. }
  11672. $this->sConn->createCommand("update english_reading set is_all_html = 0,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute();
  11673. //重置时common_topic:班级间相同的共性数据 更新为空
  11674. $this->sConn->createCommand("update english_reading_setting set common_topic = '' where reading_id='{$redingId}'")->execute();
  11675. $sql = "update english_reading_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") ";
  11676. $this->sConn->createCommand($sql)->execute();
  11677. //重置后清除已存在的下载任务
  11678. $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=10";
  11679. $this->conn->createCommand($task_sql)->execute();
  11680. $weekIds=array();
  11681. $grade=0;
  11682. foreach($englishReading as $item){
  11683. if($item['is_new_version']){
  11684. $weekIds[]=$item['week_id'];
  11685. $grade=$item['grade'];
  11686. }
  11687. }
  11688. $transaction->commit();
  11689. }catch(Exception $e){
  11690. $transaction->rollBack();
  11691. if (YII_ENV == 'production') {
  11692. $error[] = '系统错误[SQL]';
  11693. } else {
  11694. $error[] = $e->getMessage();
  11695. }
  11696. }
  11697. }
  11698. if($error){
  11699. echo json_encode(array('status'=>0,'error'=>$error));exit;
  11700. }else{
  11701. //新设置重置才发消息
  11702. if($weekIds && $grade) {
  11703. $kafkaData = array(
  11704. 'school_id' => $this->schoolId,
  11705. 'msg_type' => 90,//90:重置 1:新设置
  11706. 'grade' => $grade,
  11707. 'subject_id' => 8,
  11708. 'send_type' => 'english_reading',
  11709. 'product_type' => array(19),
  11710. 'gp_group_id' => $redingId,//reading_id
  11711. 'gp_ids' => $weekIds,//week_id
  11712. );
  11713. sendDataToKafka("php-product-english-reading-html", $kafkaData);
  11714. }
  11715. echo json_encode(array('status'=>1));exit;
  11716. }
  11717. }
  11718. /**
  11719. * 外刊美文选择学生
  11720. */
  11721. public function actionSelectStuByEnglishReading(){
  11722. $data = array();
  11723. $sname = (string)Req::get("sname"); //学生名字
  11724. $weekId = (string)Req::get("weekId");
  11725. if(!$weekId){
  11726. Yii::app()->jump->error('参数错误!');
  11727. }
  11728. //获取班级名称以及周后推送名称
  11729. $sql = "select er.name,c.class_name,er.grade,er.class_id,er.create_time,er.semester_id,ers.category,ers.product_type from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.week_id = '{$weekId}'";
  11730. $names = $this->sConn->createCommand($sql)->queryRow();
  11731. if(!$names){
  11732. $names = array();
  11733. $names['name'] = '';
  11734. $names['class_name'] = '';
  11735. $names['grade'] = 0;
  11736. }else{
  11737. $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
  11738. }
  11739. $sql = "select student_id,is_week_pdf,product_type from english_reading_student where week_id = '{$weekId}'";
  11740. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  11741. $studentIds = array();
  11742. $stuIsPdf = array();
  11743. if($relateStudent){
  11744. foreach ($relateStudent as $studentInfo) {
  11745. $studentIds[] = (string)$studentInfo['student_id'];
  11746. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
  11747. $productTypeName='';
  11748. if($studentInfo['product_type']==1){
  11749. $productTypeName='基础宝';
  11750. }elseif($studentInfo['product_type']==2){
  11751. $productTypeName='外刊宝';
  11752. }elseif($studentInfo['product_type']==3){
  11753. $productTypeName='热点宝';
  11754. }
  11755. $productTypeNames[(string)$studentInfo['student_id']] = $productTypeName;
  11756. }
  11757. }
  11758. if($studentIds){
  11759. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  11760. if($studentNames){
  11761. if($sname){
  11762. $i = 1;
  11763. foreach($studentNames as $k=>$v){
  11764. if(strpos($v,$sname) !== false){
  11765. $data['list'][$i]['stu_id'] = (string)$k;
  11766. $data['list'][$i]['stu_name'] = $v;
  11767. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  11768. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  11769. $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:'';
  11770. $i++;
  11771. }
  11772. }
  11773. }else{
  11774. $i = 1;
  11775. foreach($studentNames as $k=>$v){
  11776. $data['list'][$i]['stu_id'] = (string)$k;
  11777. $data['list'][$i]['stu_name'] = $v;
  11778. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  11779. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  11780. $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:'';
  11781. $i++;
  11782. }
  11783. }
  11784. }
  11785. }
  11786. $Sem=new SSemester();
  11787. $code= $Sem->conn->createQuery()
  11788. ->from('semester')
  11789. ->where("semester_id = '".$names['semester_id']."'")
  11790. ->limit(1)
  11791. ->query()
  11792. ->read();
  11793. $classify=6;
  11794. if($names['category']==2){
  11795. if($names['product_type']==1){
  11796. $classify=57;
  11797. }elseif($names['product_type']==2){
  11798. $classify=61;
  11799. }elseif($names['product_type']==3){
  11800. $classify=58;
  11801. }
  11802. }
  11803. $intarr=array(
  11804. "schoolId"=>$this->schoolId,
  11805. "clazzId"=>$names['class_id'],
  11806. "semester"=>$code['refer_code'],
  11807. "grade"=>$names['grade'],
  11808. "students"=>$studentIds,
  11809. "examTime"=>$names['create_time'],
  11810. "classify"=>$classify,
  11811. "subject"=>8
  11812. );
  11813. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  11814. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  11815. if(!$rs){
  11816. Yii::app()->jump->error("接口错误");
  11817. }
  11818. if($rs->errCode!="00"){
  11819. Yii::app()->jump->error($rs->errMsg);
  11820. }
  11821. if(!empty($rs->data)){
  11822. $data['limitstu']=$rs->data;
  11823. }
  11824. $data['weekId'] = $weekId;
  11825. $data['sname'] = $sname;
  11826. $data['printType'] = 'english_reading';
  11827. $this->render('english_reading_stu',$data);
  11828. }
  11829. public function actionPhpInfo(){
  11830. phpinfo();exit;
  11831. }
  11832. public function actionSendKafka(){
  11833. $conf = new RdKafka\Conf();
  11834. $conf->set('metadata.broker.list', '192.168.1.239:9092,192.168.1.247:9092,192.168.1.248:9092');
  11835. $producer = new RdKafka\Producer($conf);
  11836. $topic = $producer->newTopic("zsyte-marking-finished-notify");
  11837. $topic->produce(RD_KAFKA_PARTITION_UA, 0, '{"examGroupId":"582547523696889856","schoolId":3912,"examIds":["582547523780775936","5825475237807759363"]}');
  11838. $producer->poll(0);
  11839. $result = $producer->flush(10000);
  11840. var_dump($result);
  11841. if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
  11842. throw new \RuntimeException('Was unable to flush, messages might be lost!');
  11843. }
  11844. }
  11845. //考试扫描异常处理状态查看
  11846. public function actionGetTaskDetail(){
  11847. $examGroupId = Req::get('exam_group_id');
  11848. $grade = Req::get('grade');
  11849. $branch = Req::get('branch');
  11850. $taskModel=new AScanTask();
  11851. $task=$taskModel->getTaskByExamGroupId($examGroupId);
  11852. if($task){
  11853. $task=$task->attributes;
  11854. if($task['operator']){
  11855. $user=AssistUser::model()->findByPk($task['operator']);
  11856. $task['user']=$user->real_name;
  11857. }else{
  11858. $task['user']='--';
  11859. }
  11860. //答题卡任务耗时
  11861. if($task['scan_task_apply_time']){
  11862. if($task['scan_task']>2){
  11863. if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){
  11864. $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']);
  11865. }else{
  11866. $task['AstConsuming']='--';
  11867. }
  11868. }elseif($task['scan_task']==2){
  11869. if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){
  11870. $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']);
  11871. }else{
  11872. $task['AstConsuming']='--';
  11873. }
  11874. }
  11875. }else{
  11876. $task['AstConsuming']='--';
  11877. }
  11878. }
  11879. //读取扫描数量
  11880. $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1);
  11881. $task['count']=$count;
  11882. $data['task']=$task;
  11883. $data['exam_group_id']=$examGroupId;
  11884. $_num= '';
  11885. $use_version = '';
  11886. if(isset(Yii::app()->session['coachInfo']->use_version))
  11887. {
  11888. $use_version = Yii::app()->session['coachInfo']->use_version;
  11889. }else
  11890. {
  11891. $use_version = Yii::app()->session['coachInfo']['use_version'];
  11892. }
  11893. if(!$use_version)
  11894. {
  11895. $use_version = 100;
  11896. }
  11897. $version_number = implode('',explode('.',$use_version));
  11898. if(strlen($version_number)<7)
  11899. {
  11900. for($i=0;$i<7-strlen($version_number);$i++)
  11901. {
  11902. $_num.='0';
  11903. }
  11904. }
  11905. $version_number=(int)$version_number.$_num;
  11906. $data['version_number']=$version_number;
  11907. $data['grade']=$grade;
  11908. $data['branch']=$branch;
  11909. $this->render('scan_detail',$data);
  11910. }
  11911. /**
  11912. * 下载英语外刊教师外刊
  11913. *
  11914. */
  11915. public function actiondown_load() {
  11916. set_time_limit(0);
  11917. $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
  11918. $weekId = safe_replace(Yii::app()->request->getQuery('weekId'));
  11919. $sql = "select teacher_general_pdf_path,grade,is_new_version,reading_id,class_id from english_reading where week_id = '{$weekId}'";
  11920. $week_info = $this->sConn->createCommand($sql)->queryRow();
  11921. if (empty($week_info['teacher_general_pdf_path'])) {
  11922. if($week_info['is_new_version']){//新版本
  11923. $this->new_en_reading($weekId,$week_info);
  11924. exit;
  11925. }
  11926. $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
  11927. $sql = "select distinct topic_id from student_reading_topic where week_id = '{$weekId}' order by create_time asc";
  11928. $topic_info = $this->sConn->createCommand($sql)->queryAll();
  11929. if (empty($topic_info)) {
  11930. Yii::app()->jump->error('学生外刊宝尚未生成');
  11931. } else {
  11932. $push_topics = _array_column($topic_info, 'topic_id');
  11933. $_params = array('isFormat' => 1, 'isTird' => 1, 'isNewEnglish' => 1, 'isNoReplaceLable' => 1);
  11934. $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $push_topics, 'subjectId' => $this->subjectId, 'params' => $_params), 25, true);
  11935. if (!$topicDetails) {
  11936. echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
  11937. exit();
  11938. } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
  11939. echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
  11940. exit();
  11941. } else {
  11942. foreach($topicDetails as $node=>$td){
  11943. if (isset($td['slave'])) {
  11944. $topicDetails[$node]['diff_str'] = $this->getLargeDifficulty($td['slave']);
  11945. }else {
  11946. $topicDetails[$node]['diff_str'] = '';
  11947. }
  11948. }
  11949. $data = array();
  11950. $data['all_topics'] = $push_topics;
  11951. $data['reading_detail'] = $topicDetails;
  11952. $html_name = 'en_reading';
  11953. $html = $this->renderPartial("{$html_name}", $data,true);
  11954. unset($data);
  11955. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
  11956. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
  11957. $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
  11958. if (!is_dir($htmlpath)) {
  11959. if (!mkdir($htmlpath, 0777, true)) {
  11960. exit('Create directory fail: ' . $htmlpath);
  11961. }
  11962. }
  11963. if (!is_dir($pdfpath)) {
  11964. if (!mkdir($pdfpath, 0777, true)) {
  11965. exit('Create directory fail1: ' . $pdfpath);
  11966. }
  11967. }
  11968. $htmlpath .= $weekId . ".html";
  11969. $f = fopen($htmlpath, "w");
  11970. fwrite($f, $html);
  11971. fclose($f);
  11972. $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
  11973. //防止exec 执行命令行导致中文乱码
  11974. $locale='en_US.UTF-8';
  11975. setlocale(LC_ALL,$locale);
  11976. putenv('LC_ALL='.$locale);
  11977. if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
  11978. $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html';
  11979. $pdffname = $weekId . ".pdf";
  11980. $pdfpath = $pdfpath . $pdffname;
  11981. $pdfurl = $pdfurl . $pdffname;
  11982. $commond = Yii::app()->params['phantomjs'] . " "
  11983. . Yii::app()->params['html2pdf'] . " "
  11984. . " {$htmlurl}"
  11985. . " {$pdfpath}"
  11986. . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'";
  11987. } else {
  11988. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  11989. $pdffname = $weekId . ".pdf";
  11990. $pdfpath = $pdfpath . $pdffname;
  11991. $pdfurl = $pdfurl . $pdffname;
  11992. $commond = Yii::app()->params['phantomjs_server_en'] . " "
  11993. . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
  11994. . " {$htmlurl}"
  11995. . " {$pdfpath}"
  11996. . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
  11997. }
  11998. exec($commond, $res, $code);
  11999. if(isset($res[0])){
  12000. $isBool = false;
  12001. foreach ($res as $msg) {
  12002. if (strpos($msg, 'succeed') !== false) {
  12003. $isBool = true;
  12004. }
  12005. }
  12006. if ($isBool) {//命令返回成功
  12007. if (file_exists($pdfpath)) {
  12008. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  12009. $repdf = $weekId . ".pdf";
  12010. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  12011. $ucloud = new HuaweiCloud();
  12012. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  12013. if ($uploadInfo['status'] == 0) {
  12014. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  12015. $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
  12016. $week_info['teacher_general_pdf_path'] = $pdfurl;
  12017. }else{
  12018. $pdfurl = $uploadInfo['url'];
  12019. $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
  12020. $week_info['teacher_general_pdf_path'] = $pdfurl;
  12021. @unlink($pdfpath);
  12022. }
  12023. @unlink($htmlpath);
  12024. } else {
  12025. @unlink($htmlpath);
  12026. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  12027. exit;
  12028. }
  12029. } else {
  12030. @unlink($htmlpath);
  12031. echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
  12032. exit;
  12033. }
  12034. } else {
  12035. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  12036. exit;
  12037. }
  12038. }
  12039. }
  12040. }
  12041. if($week_info['teacher_general_pdf_path']){
  12042. $url = $week_info['teacher_general_pdf_path'];
  12043. header('Content-Description: File Transfer');
  12044. header('Content-Type: application/vnd.android.package-archive');
  12045. header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf");
  12046. header('Content-Transfer-Encoding: binary');
  12047. header('Expires: 0');
  12048. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  12049. header('Pragma: public');
  12050. $ch = curl_init();
  12051. curl_setopt($ch, CURLOPT_URL, $url);
  12052. curl_setopt($ch, CURLOPT_HEADER, 0);
  12053. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12054. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  12055. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  12056. echo $buffer;
  12057. return strlen($buffer);
  12058. });
  12059. curl_exec($ch);
  12060. curl_close($ch);
  12061. }else{
  12062. Yii::app()->jump->error('尚未生成PDF');
  12063. }
  12064. }
  12065. /**
  12066. * 英语周推新版教师版下载
  12067. */
  12068. public function newEnTeacherWeek($weekId='',$weekMsg=array()){
  12069. $sql = "select week_pdf_path from english_week_student where week_id='{$weekId}' and student_id=0";
  12070. $week_info = $this->sConn->createCommand($sql)->queryRow();
  12071. if($week_info && $week_info['week_pdf_path']){
  12072. $classId = $weekMsg['class_id'];
  12073. $sql = "select class_name from class where class_id = '{$classId}'";
  12074. $classInfo = $this->sConn->createCommand($sql)->queryRow();
  12075. $className = $classInfo ? $classInfo['class_name'] : '';
  12076. $fileName = $className.'_周推教师版';
  12077. $url = $week_info['week_pdf_path'];
  12078. if(isset(Yii::app()->params["static_url"][$this->schoolGroupId]) && Yii::app()->params["static_url"][$this->schoolGroupId]){
  12079. $url = Yii::app()->params["static_url"][$this->schoolGroupId].'/'.$url;
  12080. }else{
  12081. Yii::app()->jump->error('接口配置信息错误');
  12082. }
  12083. $handle = @fopen($url, 'r');
  12084. if(!$handle){
  12085. Yii::app()->jump->error('尚未生成PDF');
  12086. }
  12087. header('Content-Description: File Transfer');
  12088. header('Content-Type: application/vnd.android.package-archive');
  12089. header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf");
  12090. header('Content-Transfer-Encoding: binary');
  12091. header('Expires: 0');
  12092. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  12093. header('Pragma: public');
  12094. $ch = curl_init();
  12095. curl_setopt($ch, CURLOPT_URL, $url);
  12096. curl_setopt($ch, CURLOPT_HEADER, 0);
  12097. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12098. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  12099. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  12100. echo $buffer;
  12101. return strlen($buffer);
  12102. });
  12103. curl_exec($ch);
  12104. curl_close($ch);
  12105. }else{
  12106. Yii::app()->jump->error('周推教师版尚未生成');
  12107. }
  12108. }
  12109. /**
  12110. * 英语周推教师版下载
  12111. * @throws CException
  12112. */
  12113. public function actionTeacherWeek(){
  12114. set_time_limit(0);
  12115. $weekId = safe_replace(Yii::app()->request->getQuery('weekId'));
  12116. $sql = "select * from teacher_week_extend where week_id = '{$weekId}'";
  12117. $week_info = $this->sConn->createCommand($sql)->queryAll();
  12118. $teacher_extend_arr = array();
  12119. foreach($week_info as $info)
  12120. {
  12121. $content = $info['content'];
  12122. $content = json_decode($content,true);
  12123. $teacher_extend_arr[$info['type']] = $content;
  12124. }
  12125. $sql = "select grade,teacher_general_pdf_path,class_id,set_id from english_week where week_id = '{$weekId}'";
  12126. $week_info = $this->sConn->createCommand($sql)->queryRow();
  12127. $sql = "select class_id,semester_id,words_type,is_new_version from english_week_setting where id = '{$week_info['set_id']}'";
  12128. $week_setting_info = $this->sConn->createCommand($sql)->queryRow();
  12129. if($week_setting_info['is_new_version']){
  12130. $this->newEnTeacherWeek($weekId,$week_info);
  12131. exit;
  12132. }
  12133. $words_type = $week_setting_info['words_type'];
  12134. $sql = "select ps_id from product_class_relation where class_id={$week_setting_info['class_id']} and semester_id={$week_setting_info['semester_id']} and set_type=7 order by ps_id desc limit 1";
  12135. $arr = $this->sConn->createCommand($sql)->queryRow();
  12136. $product_setting = '';
  12137. if($arr){
  12138. $sql = "select custom_config from product_setting where ps_id={$arr['ps_id']}";
  12139. $product_setting = $this->sConn->createCommand($sql)->queryRow();
  12140. $product_setting = $product_setting ? $product_setting['custom_config'] : '';
  12141. }
  12142. $setting = array(
  12143. 'moduleName'=>'晨读词汇',
  12144. 'moduleType'=>'english_4',
  12145. 'setting'=>array(
  12146. 'vocabularySelfTest' =>array( //词汇自测
  12147. "coreVocabulary"=>array( //核心词汇开关
  12148. "onOff" =>1,
  12149. "vocabularyUse" =>1 //词汇运用
  12150. ),
  12151. "keyPhrases" =>1 //重点短语
  12152. ),
  12153. "focusOnGrammar" =>array(//语法聚焦
  12154. "singleSentenceGrammar" =>1, //单句语法填空
  12155. "grammaticalFillIn" =>1 //语法填空
  12156. ),
  12157. "writingTraining" =>array(//写作训练
  12158. "commentsOnGoodSentences" =>1, // 佳句点拨
  12159. "actualCombatDrill" =>1 //实战演练
  12160. ),
  12161. "extensiveReadingOfForeignJournals" =>array( //外刊泛读
  12162. "accumulationOfNewWords" =>1, //新词积累
  12163. "appreciationOfGoldenSentences" =>1, //金句赏析
  12164. "fullTextTranslation" =>1, //全文翻译
  12165. ),
  12166. )
  12167. );
  12168. $product_setting = $product_setting ? json_decode($product_setting, true) : $setting;
  12169. //$product_setting = $setting;
  12170. //核心词区分派生非派生
  12171. $single_words_derivative = array();
  12172. if(isset($teacher_extend_arr[1])){
  12173. foreach($teacher_extend_arr[1] as $k=>$v){
  12174. if(isset($v['is_derivative'])){
  12175. $single_words_derivative[$v['is_derivative']][] = $v;
  12176. }
  12177. }
  12178. }
  12179. $html_data = array(
  12180. 'cur_grade' => $week_info['grade'],
  12181. 'single_words' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
  12182. 'phrase' => isset($teacher_extend_arr[2]) ? $teacher_extend_arr[2] : array(),
  12183. 'topic_type_six' => isset($teacher_extend_arr[4]) ? $teacher_extend_arr[4] : array(),
  12184. 'topic_type_nineteen'=> isset($teacher_extend_arr[3]) ? $teacher_extend_arr[3] : array(),
  12185. 'writing_training' => isset($teacher_extend_arr[5]) ? $teacher_extend_arr[5] : array(),
  12186. 'single_translation' => isset($teacher_extend_arr[6]) ? $teacher_extend_arr[6] : array(),
  12187. 'essayDetail' => isset($teacher_extend_arr[7]) ? $teacher_extend_arr[7] : array(),
  12188. 'word_single_translation' => isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array(), //词汇运用(单句翻译)
  12189. 'word_grammar_blank' => isset($teacher_extend_arr[9]) ? $teacher_extend_arr[9] : array(), //词汇运用(单句语法填空)
  12190. 'word_spelling' => isset($teacher_extend_arr[20]) ? $teacher_extend_arr[20] : array(), //词汇运用(单词拼写)
  12191. 'complete_sentence' => isset($teacher_extend_arr[21]) ? $teacher_extend_arr[21] : array(), //词汇运用(完成句子)
  12192. 'product_setting' => $product_setting['setting'],
  12193. 'words_type'=>$words_type,
  12194. 'single_words_derivative'=>$single_words_derivative
  12195. );
  12196. $classId = $week_info['class_id'];
  12197. $sql = "select class_name from class where class_id = '{$classId}'";
  12198. $classInfo = $this->sConn->createCommand($sql)->queryRow();
  12199. $className = $classInfo ? $classInfo['class_name'] : '';
  12200. if (empty($week_info['teacher_general_pdf_path'])) {
  12201. $sql = "select topic_id from teacher_week where week_id = '{$weekId}' order by topic_id desc";
  12202. $topic_info = $this->sConn->createCommand($sql)->queryAll();
  12203. if (empty($topic_info)) {
  12204. Yii::app()->jump->error('周推教师版尚未生成');
  12205. } else {
  12206. $html_name = 'english_week_teacher';
  12207. //$this->render("{$html_name}", $html_data);exit;
  12208. $html = $this->renderPartial("{$html_name}", $html_data,true);
  12209. unset($html_data);
  12210. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
  12211. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
  12212. $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
  12213. if (!is_dir($htmlpath)) {
  12214. if (!mkdir($htmlpath, 0777, true)) {
  12215. exit('Create directory fail: ' . $htmlpath);
  12216. }
  12217. }
  12218. if (!is_dir($pdfpath)) {
  12219. if (!mkdir($pdfpath, 0777, true)) {
  12220. exit('Create directory fail1: ' . $pdfpath);
  12221. }
  12222. }
  12223. $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
  12224. $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
  12225. $htmlpath .= $weekId . ".html";
  12226. $f = fopen($htmlpath, "w");
  12227. fwrite($f, $html);
  12228. fclose($f);
  12229. $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
  12230. $locale='en_US.UTF-8';
  12231. setlocale(LC_ALL,$locale);
  12232. putenv('LC_ALL='.$locale);
  12233. if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath
  12234. $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $weekId . '.html';
  12235. $pdffname = $weekId . ".pdf";
  12236. $pdfpath = $pdfpath . $pdffname;
  12237. $pdfurl = $pdfurl . $pdffname;
  12238. $commond = Yii::app()->params['phantomjs'] . " "
  12239. . Yii::app()->params['html2pdf'] . " "
  12240. . " {$htmlurl}"
  12241. . " {$pdfpath}"
  12242. . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
  12243. } else {
  12244. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  12245. $pdffname = $weekId . ".pdf";
  12246. $pdfpath = $pdfpath . $pdffname;
  12247. $pdfurl = $pdfurl . $pdffname;
  12248. $commond = Yii::app()->params['phantomjs_server_en'] . " "
  12249. . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
  12250. . " {$htmlurl}"
  12251. . " {$pdfpath}"
  12252. . ' 176mm*250mm "'.$grade.' '.$className.'|||'.date('Y-m-d',time()).'"';
  12253. }
  12254. exec($commond, $res, $code);
  12255. if(isset($res[0])){
  12256. $isBool = false;
  12257. foreach ($res as $msg) {
  12258. if (strpos($msg, 'succeed') !== false) {
  12259. $isBool = true;
  12260. }
  12261. }
  12262. if ($isBool) {//命令返回成功
  12263. if (file_exists($pdfpath)) {
  12264. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  12265. $repdf = $weekId . ".pdf";
  12266. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  12267. $ucloud = new HuaweiCloud();
  12268. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  12269. if ($uploadInfo['status'] == 0) {
  12270. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  12271. $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
  12272. $week_info['teacher_general_pdf_path'] = $pdfurl;
  12273. }else{
  12274. $pdfurl = $uploadInfo['url'];
  12275. $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
  12276. $week_info['teacher_general_pdf_path'] = $pdfurl;
  12277. @unlink($pdfpath);
  12278. }
  12279. @unlink($htmlpath);
  12280. } else {
  12281. @unlink($htmlpath);
  12282. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  12283. exit;
  12284. }
  12285. } else {
  12286. @unlink($htmlpath);
  12287. echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
  12288. exit;
  12289. }
  12290. } else {
  12291. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  12292. exit;
  12293. }
  12294. }
  12295. }
  12296. if($week_info['teacher_general_pdf_path']){
  12297. $fileName = $className.'_周推教师版';
  12298. $url = $week_info['teacher_general_pdf_path'];
  12299. header('Content-Description: File Transfer');
  12300. header('Content-Type: application/vnd.android.package-archive');
  12301. header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf");
  12302. header('Content-Transfer-Encoding: binary');
  12303. header('Expires: 0');
  12304. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  12305. header('Pragma: public');
  12306. $ch = curl_init();
  12307. curl_setopt($ch, CURLOPT_URL, $url);
  12308. curl_setopt($ch, CURLOPT_HEADER, 0);
  12309. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12310. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  12311. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  12312. echo $buffer;
  12313. return strlen($buffer);
  12314. });
  12315. curl_exec($ch);
  12316. curl_close($ch);
  12317. }else{
  12318. Yii::app()->jump->error('尚未生成PDF');
  12319. }
  12320. }
  12321. //数学公式
  12322. public function actionAjaxGetMathtex()
  12323. {
  12324. $error = array();
  12325. $result = array();
  12326. $mathtex = Req::post('mathtex');
  12327. if (strlen($mathtex)) {
  12328. $data = $this->apiPost('/mathtex/url', array('mathtex' => $mathtex,"is_fdfs"=>1), 1);
  12329. if (isset($data->status) or isset($data->error)) {
  12330. $error[] = $data->error;
  12331. } elseif (! $data) {
  12332. $error[] = '系统错误!';
  12333. } else {
  12334. $result['url'] = $data['url'].'?'.$mathtex;
  12335. $result['width'] = $data['width'];
  12336. $result['height'] = $data['height'];
  12337. }
  12338. } else {
  12339. $error[] = '参数不能为空';
  12340. }
  12341. header('Content-Type: application/json');
  12342. if ($error) {
  12343. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
  12344. } else {
  12345. echo json_encode($result);
  12346. }
  12347. }
  12348. //重新发送扫描任务
  12349. public function actionResendScanTask(){
  12350. $examGroupId = Req::post('exam_group_id');
  12351. $result['status']=0;
  12352. $taskModel=new AScanTask();
  12353. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  12354. if(!$task){
  12355. $result['msg']='任务数据异常!';
  12356. exit(json_encode($result));
  12357. }
  12358. //判断剩余任务量
  12359. $studentTask=new AStudentScanTask();
  12360. $taskCount=$studentTask->getTaskCount($examGroupId);
  12361. if($taskCount['surplus']==0){
  12362. $result['msg']='当前任务已无异常数据!';
  12363. exit(json_encode($result));
  12364. }
  12365. $taskStatus=1;
  12366. if($task['operator']){
  12367. $taskStatus=2;
  12368. }else{
  12369. $taskStatus=1;
  12370. }
  12371. if($taskModel->updateAll(array('scan_task'=>$taskStatus,'resend_time'=>time(),'update_time'=>time()),'exam_group_id=:eid',array(':eid'=>$examGroupId))){
  12372. $result['status']=1;
  12373. }
  12374. exit(json_encode($result));
  12375. }
  12376. //撤回发送扫描任务
  12377. public function actionCancelScanTask(){
  12378. $examGroupId = Req::post('exam_group_id');
  12379. $result['status']=0;
  12380. $taskModel=new AScanTask();
  12381. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  12382. if(!$task){
  12383. $result['msg']='任务数据异常!';
  12384. exit(json_encode($result));
  12385. }
  12386. if($task['scan_task']==2){
  12387. $result['msg']='任务已受理不可撤回';
  12388. exit(json_encode($result));
  12389. }
  12390. if($task['scan_task']==3){
  12391. $result['msg']='任务已完成不可撤回';
  12392. exit(json_encode($result));
  12393. }
  12394. if($task['scan_task']==4){
  12395. $result['msg']='任务已撤回,请匆重复操作';
  12396. exit(json_encode($result));
  12397. }
  12398. if($taskModel->updateAll(array('scan_task'=>4),'exam_group_id=:eid',array(':eid'=>$examGroupId))){
  12399. $result['status']=1;
  12400. }
  12401. exit(json_encode($result));
  12402. }
  12403. //读取考试剩余任务量
  12404. public function actionGetSurplus(){
  12405. $examGroupId = Req::post('exam_group_id');
  12406. $studentTask=new AStudentScanTask();
  12407. $result['status']=0;
  12408. $taskCount=$studentTask->getTaskCount($examGroupId);
  12409. if($taskCount['surplus']==0){
  12410. $result['msg']='当前任务已无异常数据!';
  12411. exit(json_encode($result));
  12412. }else{
  12413. $result['status']=1;
  12414. $result['msg']='数据正常!';
  12415. exit(json_encode($result));
  12416. }
  12417. }
  12418. //获取学校百万校
  12419. public function checkSchoolBW(){
  12420. $http = http('customer/school/coach/official/detail', 'GET', $this->authUsername);
  12421. $response = formatResponse($http);
  12422. $data = $response['data'];
  12423. if(isset($data['isHuge']) && $data['isHuge']==1){
  12424. return 1;
  12425. }
  12426. return 0;
  12427. }
  12428. private function getLargeDifficulty($slave)
  12429. {
  12430. if (empty($slave) || !is_array($slave)) {
  12431. return false;
  12432. }
  12433. $difficultyLevel = array(
  12434. 1 => array(
  12435. 'range' => 0.90,
  12436. 'name' => '超易',
  12437. ),
  12438. 2 => array(
  12439. 'range' => 0.75,
  12440. 'name' => '易',
  12441. ),
  12442. 3 => array(
  12443. 'range' => 0.65,
  12444. 'name' => '中档偏易',
  12445. ),
  12446. 4 => array(
  12447. 'range' => 0.50,
  12448. 'name' => '中档偏难',
  12449. ),
  12450. 5 => array(
  12451. 'range' => 0.40,
  12452. 'name' => '难',
  12453. ),
  12454. 6 => array(
  12455. 'range' => 0.20,
  12456. 'name' => '超难',
  12457. ),
  12458. );
  12459. $difficulty = 0;
  12460. $SlaveTopicDifficultySum = 0;
  12461. $slaveCount = 0;
  12462. foreach($slave as $slkey=>$slval){
  12463. //计算大题难度
  12464. if(!isset($slval['difficulty'])) $slval['difficulty'] = 0;
  12465. if(isset($difficultyLevel[$slval['difficulty']]) && $slval['difficulty']) {
  12466. $slaveCount++;
  12467. $SlaveTopicDifficultySum += $difficultyLevel[$slval['difficulty']]['range'];
  12468. }
  12469. }
  12470. if($SlaveTopicDifficultySum>0 && $slaveCount>0){
  12471. $averageDiff=$SlaveTopicDifficultySum/$slaveCount;
  12472. $difficulty=$this->diffChangeSix($averageDiff,8);
  12473. }
  12474. return $this->diffNameSix($difficulty);
  12475. }
  12476. private function diffChangeSix($degree,$sub_id = 3)
  12477. {
  12478. if ($sub_id == 3) {
  12479. if($degree>=0 && $degree<=0.2){
  12480. $diff = 6;
  12481. }elseif($degree>0.2 && $degree<=0.4){
  12482. $diff = 5;
  12483. }elseif($degree>0.4 && $degree<=0.6){
  12484. $diff = 4;
  12485. }elseif($degree>0.6 && $degree<=0.7){
  12486. $diff = 3;
  12487. }elseif($degree>0.7 && $degree<=0.85){
  12488. $diff = 2;
  12489. }elseif($degree>0.85 && $degree<=1){
  12490. $diff = 1;
  12491. }else{
  12492. $diff = 6;
  12493. }
  12494. }else{
  12495. if($degree<=0.2){
  12496. return 6;
  12497. }elseif($degree<=0.4){
  12498. return 5;
  12499. }elseif($degree<=0.5){
  12500. return 4;
  12501. }elseif($degree<=0.65){
  12502. return 3;
  12503. }elseif($degree<=0.75){
  12504. return 2;
  12505. }else{
  12506. return 1;
  12507. }
  12508. }
  12509. return $diff;
  12510. }
  12511. private function diffNameSix($degree)
  12512. {
  12513. $diff_name_arr = array('1'=>'超易','2'=>'易','3'=>'中档偏易','4'=>'中档偏难','5'=>'难','6'=>'超难');
  12514. return isset($diff_name_arr[$degree]) ? $diff_name_arr[$degree] : '';
  12515. }
  12516. //复用的答题卡编辑后保存
  12517. private function saveMultiplex(){
  12518. $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
  12519. $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
  12520. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  12521. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  12522. $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0;
  12523. //上传答题卡相关文件
  12524. $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
  12525. $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  12526. $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow();
  12527. if($thirdAnswer['multiplex_id']==$multiplexId){
  12528. $this->sConn->createCommand("update third_answer_sheet set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  12529. }
  12530. echo json_encode(array('success'=>1,'message'=>'保存成功','multiplex_id'=>$multiplexId,'exam_group_id'=>$examGroupId));exit;
  12531. }
  12532. // 上传答题卡相关文件
  12533. private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){
  12534. $card_file=array();
  12535. if (empty($_FILES)) {
  12536. $error['message'] = '未找到上传文件!';
  12537. echo json_encode($error);exit();
  12538. }else {
  12539. // debug($_FILES);
  12540. foreach ($_FILES as $k => $v) {
  12541. if (isset($v) && !empty($v)) {
  12542. if (!isset($v['size']) || $v['size'] >= 8388608) {
  12543. $error['message'] = '文件超过8M!';
  12544. echo json_encode($error);
  12545. exit();
  12546. }
  12547. $ext = substr($v['name'], strrpos($v['name'], '.') + 1);
  12548. if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) {
  12549. $error['message'] = '文件格式不正确!';
  12550. echo json_encode($error);
  12551. exit();
  12552. }
  12553. if ($ext == 'pdf') {
  12554. $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf';
  12555. if (!move_uploaded_file($v["tmp_name"], $card_pdf)) {
  12556. $error['message'] = '保存Pdf文件失败!';
  12557. echo json_encode($error);
  12558. exit();
  12559. }
  12560. } else {
  12561. $card_file[] = $v;
  12562. }
  12563. }
  12564. }
  12565. $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/';
  12566. $ucloudPdfUrl = '';
  12567. if (!file_exists($fixName)) {
  12568. mkdir($fixName, 0777, true);
  12569. }
  12570. $zipFileName = $examGroupId .'_'.time().'.zip';
  12571. $pathName = $fixName . $zipFileName;
  12572. $zip = new ZipArchive;
  12573. $zip->open($pathName, ZipArchive::CREATE);
  12574. foreach ($card_file as $k => $v) {
  12575. $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
  12576. }
  12577. $zip->addFromString('json.txt', $positionJson);
  12578. $zip->close();
  12579. //FIXME 20191204
  12580. $ucloud = new HuaweiCloud();
  12581. //上传压缩包
  12582. $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName;
  12583. $uploadInfo = $ucloud->putFile($rename, $pathName);
  12584. @unlink($pathName);
  12585. if ($uploadInfo['status'] == 0) {
  12586. $error['success'] = 0;
  12587. $error['message'] = '答题卡文件上传失败! ';
  12588. $error['data']=$uploadInfo;
  12589. echo json_encode($error);
  12590. exit();
  12591. } else {
  12592. $ucloudZipUrl = $uploadInfo['url'];
  12593. }
  12594. //上传Pdf
  12595. if ($pdfUrl) {
  12596. $ucloudPdfUrl=$pdfUrl;
  12597. // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf';
  12598. // $content = file_get_contents($pdfUrl);
  12599. //
  12600. // file_put_contents($card_pdf, $content);
  12601. //
  12602. // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf';
  12603. // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf);
  12604. //
  12605. // if ($uploadInfo['status'] == 0) {
  12606. // @unlink($card_pdf);
  12607. // $error['success'] = 0;
  12608. // $error['message'] = '答题卡PDF文件上传失败!';
  12609. // echo json_encode($error);
  12610. // exit();
  12611. // } else {
  12612. // @unlink($card_pdf);
  12613. // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']);
  12614. // $ucloudPdfUrl = $uploadInfo['url'];
  12615. // }
  12616. }
  12617. //单独上传position.txt
  12618. if($positionJson){
  12619. $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ;
  12620. file_put_contents($positionTxt, $positionJson);
  12621. $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
  12622. $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
  12623. if ($uploadInfo['status'] == 0) {
  12624. @unlink($positionTxt);
  12625. $error['success']=0;
  12626. $error['message'] = 'Position文件上传失败!';
  12627. echo json_encode($error);exit();
  12628. }else{
  12629. @unlink($positionTxt);
  12630. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  12631. $ucloudTxtUrl=$uploadInfo['url'];
  12632. }
  12633. }
  12634. }
  12635. return array(
  12636. 'ucloudZipUrl'=>$ucloudZipUrl,
  12637. 'ucloudPdfUrl'=>$ucloudPdfUrl,
  12638. 'positionUrl'=>$ucloudTxtUrl
  12639. );
  12640. }
  12641. //加载考试未上传学生
  12642. public function actionAjaxLoadNoUploadStudent(){
  12643. $examGroupId = Req::post('exam_group_id');
  12644. $page=intval(Req::post('page'));
  12645. $isDel=intval(Req::post('is_del'));
  12646. $classId=Req::post('class_id');
  12647. if(!$page) $page=1;
  12648. $result=array();
  12649. $result['status']=0;
  12650. if(!$examGroupId){
  12651. $result['msg']='考试id不能为空';
  12652. exit(json_encode($result));
  12653. }
  12654. $data=$this->schoolManager->getNoUploadStudentByGroupId($examGroupId,$page,$isDel,$classId);
  12655. if($data){
  12656. $result['status']=1;
  12657. $result['data']=$data;
  12658. }
  12659. exit(json_encode($result));
  12660. }
  12661. //删除考试学生,全部班级
  12662. public function actionDelExamStudent(){
  12663. $examGroupId = Req::post('examGroupId');
  12664. $studentIds=Req::post('studentsIds');
  12665. $examId=Req::post('examId');
  12666. $result['status']=0;
  12667. if(!$examId){
  12668. $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
  12669. if($examIds){
  12670. $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examIds);
  12671. }
  12672. $sendJsonArr = array(
  12673. 'school_id' => $this->schoolId,
  12674. 'send_type' => 'zsyas',
  12675. 'update_type' => 2,
  12676. 'exam_group_id' => $examGroupId,
  12677. 'exam_id_arr' => $examIds,
  12678. 'student_id_arr' => $studentIds
  12679. );
  12680. }else{
  12681. $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examId);
  12682. $sendJsonArr = array(
  12683. 'school_id' => $this->schoolId,
  12684. 'send_type' => 'zsyas',
  12685. 'update_type' => 2,
  12686. 'exam_group_id' => $examGroupId,
  12687. 'exam_id_arr' => array($examId),
  12688. 'student_id_arr' => $studentIds
  12689. );
  12690. }
  12691. if($rs){
  12692. if(Yii::app()->params['handle_log_on_off'])
  12693. {
  12694. writeFileLog(jsonEncode(array(
  12695. "examGroupId" => $examGroupId,
  12696. "operate_project" => 'zsyas2',
  12697. "school_id" => $this->schoolId,
  12698. "title" => '删除考试学生,全部班级',
  12699. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  12700. "operate_method" => $this->action,
  12701. "operate_url" => $this->getRoute(),
  12702. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  12703. "date"=>date('Y-m-d H:i:s')
  12704. )));
  12705. }
  12706. $result['status']=1;
  12707. sendStudentCacheQueue($sendJsonArr);
  12708. }
  12709. exit(json_encode($result));
  12710. }
  12711. //下载学生导出excel
  12712. public function actionDownloadSelectStudent(){
  12713. $examGroupId = Req::get('examGroupId');
  12714. $studentIds=Req::get('studentsIds');
  12715. $studentIds=explode(',',$studentIds);
  12716. if(!$studentIds || !$examGroupId){
  12717. $result['status']=0;
  12718. exit(json_encode($result));
  12719. }
  12720. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  12721. $rs=$this->schoolManager->getExcelStudent($studentIds,$examGroupId);
  12722. $excel = new Excel();
  12723. $fileName = $exam_data[0]['name']."未上传学生";
  12724. $excel->export($rs, $fileName);
  12725. }
  12726. //批量删除所有未上传考生
  12727. public function actionDelAllNotUploadStudent(){
  12728. $examGroupId = Req::post('examGroupId');
  12729. $result['status']=0;
  12730. $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
  12731. $studentIds=array();
  12732. if($examIds){
  12733. $rs=$this->schoolManager->delStudentPaperByExamGroupId($examIds);
  12734. $studentIds=$this->schoolManager->getStudentPaperByExamGroupId($examIds);
  12735. }
  12736. $sendJsonArr = array(
  12737. 'school_id' => $this->schoolId,
  12738. 'send_type' => 'zsyas',
  12739. 'update_type' => 2,
  12740. 'exam_group_id' => $examGroupId,
  12741. 'exam_id_arr' => $examIds,
  12742. 'student_id_arr' => $studentIds
  12743. );
  12744. if($rs){
  12745. if(Yii::app()->params['handle_log_on_off'])
  12746. {
  12747. writeFileLog(jsonEncode(array(
  12748. "examGroupId" => $examGroupId,
  12749. "operate_project" => 'zsyas2',
  12750. "school_id" => $this->schoolId,
  12751. "title" => '删除所有未上传考生',
  12752. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  12753. "operate_method" => $this->action,
  12754. "operate_url" => $this->getRoute(),
  12755. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  12756. "date"=>date('Y-m-d H:i:j')
  12757. )));
  12758. }
  12759. $result['status']=1;
  12760. sendStudentCacheQueue($sendJsonArr);
  12761. }
  12762. exit(json_encode($result));
  12763. }
  12764. //获取在线答题卡接口token
  12765. public function actionGetOnlineToken(){
  12766. $token=getOnlineToolToken($this->schoolId);
  12767. if($token){
  12768. $result['status']=1;
  12769. $result['data']=$token;
  12770. }else{
  12771. $result['status']=0;
  12772. $result['msg']='token读取失败';
  12773. }
  12774. exit(json_encode($result));
  12775. }
  12776. //更新考试准考证类型
  12777. public function actionChangeStudentCardType(){
  12778. $examGroupId = Req::post('examGroupId');
  12779. $schoolCard = Req::post("schoolCard");
  12780. $schoolCardLength = intval(Req::post("schoolCardLength"));
  12781. if(!$examGroupId)
  12782. $this->output(0, "参数错误[1]");
  12783. if($schoolCard==1 && !$schoolCardLength){
  12784. $this->output(0, "准考证位数不能为空");
  12785. }
  12786. $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  12787. if(!$exam_group_array )
  12788. {
  12789. $this->output(0, "非法数据");
  12790. }
  12791. if($exam_group_array['upload_status']>0){
  12792. $this->output(0, "已上传成绩不能修改考号类型");
  12793. }
  12794. if(!in_array($schoolCard,array(0,1))) $this->output(0, "考号类型不正确");
  12795. $examDetail=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  12796. if(Yii::app()->params['handle_log_on_off'])
  12797. {
  12798. writeFileLog(jsonEncode(array(
  12799. "exam_group_id" => (string)$examGroupId,
  12800. "operate_project" => 'zsyas2',
  12801. "school_id" => $this->schoolId,
  12802. "title" => '更改考号类型',
  12803. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  12804. "operate_method" => $this->action,
  12805. "operate_url" => $this->getRoute(),
  12806. "operate_sql" => json_encode(array('update'=>array(
  12807. 'exam'=>array('school_card_status'=>$schoolCard),
  12808. ))),
  12809. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  12810. "date"=>date('Y-m-d H:i:s')
  12811. )));
  12812. }
  12813. $transaction = $this->sConn->beginTransaction();
  12814. try{
  12815. Exam::model()->updateAll(array('school_card_status'=>$schoolCard,'school_card_length'=>$schoolCardLength),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  12816. $transaction->commit();
  12817. }catch(Exception $e)
  12818. {
  12819. $transaction->rollBack();
  12820. $this->output(0, "更改失败");
  12821. }
  12822. $this->output(1, "更改成功");
  12823. }
  12824. //学生成绩转移读取学生列表
  12825. public function actionGetUploadedStudent(){
  12826. $examGroupId = Req::post('examGroupId');
  12827. if(!$examGroupId)
  12828. $this->output(0, "参数错误[1]");
  12829. $examIds=array();
  12830. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  12831. if(!$exam_data) $this->output(0, "考试不存在");
  12832. foreach ($exam_data as $val){
  12833. $examIds[]=$val['exam_id'];
  12834. }
  12835. if($exam_data[0]['school_card_status']==1){
  12836. $fieldName='school_student_card';
  12837. }else{
  12838. $fieldName='student_card';
  12839. }
  12840. $uploaded=array();
  12841. $noUploaded=array();
  12842. $students=$this->schoolManager->getAllStudentPaperByExamIds($examIds);
  12843. if($students){
  12844. foreach ($students as $val){
  12845. if($val['is_feedback']==1){
  12846. $uploaded[]=array(
  12847. 'student_id'=>$val['student_id'],
  12848. 'student_card'=>$val[$fieldName],
  12849. 'student_name'=>$val['realname']
  12850. );
  12851. }else{
  12852. $noUploaded[]=array(
  12853. 'student_id'=>$val['student_id'],
  12854. 'student_card'=>$val[$fieldName],
  12855. 'student_name'=>$val['realname']
  12856. );
  12857. }
  12858. }
  12859. }
  12860. if(!$uploaded){
  12861. $this->output(0, "考试还未上传成绩");
  12862. }
  12863. if(!$noUploaded){
  12864. $this->output(0, "考试没有未上传的学生");
  12865. }
  12866. $this->output(1, "success",array('data'=>array('uploaded'=>$uploaded,'noUploaded'=>$noUploaded)));
  12867. }
  12868. //交换学生成绩之移形换影大法!
  12869. public function actionAjaxTransferStudentRs(){
  12870. $examGroupId = Req::post('examGroupId');
  12871. $uploadStudentId = Req::post('uploadStudentId');
  12872. $noUploadStudentId = Req::post('noUploadStudentId');
  12873. if(!$examGroupId)
  12874. $this->output(0, "参数错误[1]");
  12875. if(!$uploadStudentId || !$noUploadStudentId) $this->output(0, "请先选择参与转移的学生");
  12876. $examGroupArray = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  12877. $examIds=array();
  12878. $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
  12879. if(!$exam_data) $this->output(0, "考试不存在");
  12880. $examStatus=array();
  12881. foreach ($exam_data as $val){
  12882. $examIds[]=$val['exam_id'];
  12883. $examStatus[(string)$val['exam_id']]=$val['status'];
  12884. }
  12885. if($examGroupArray->mark_type==3 && $examGroupArray->mark_status==2){
  12886. $this->output(0, "本场考试已完成阅卷,需要先恢复阅卷状态,再转移学生成绩");
  12887. }
  12888. $isAllSelect=1; //全部客观题判断
  12889. //获取paper 表数据
  12890. $paperData = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0]));
  12891. $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paperData->paper_id));
  12892. if(!$paperTopic){
  12893. Yii::app()->jump->error('未找到考试信息!');
  12894. }
  12895. //选择题类型判断
  12896. $allSubjectType=array();
  12897. if($examGroupArray['qxk_paper_id']>0){
  12898. $allSubjectType=array(1,2,3,4,12);
  12899. }else{
  12900. $allSubjectType=array(1,2,11);
  12901. }
  12902. foreach ($paperTopic as $item){
  12903. if(!in_array($item->type,$allSubjectType)){
  12904. $isAllSelect=0;
  12905. break;
  12906. }
  12907. }
  12908. $studentPaper=$this->schoolManager->getAllStudentPaperByExamIds($examIds,array($uploadStudentId,$noUploadStudentId));
  12909. $uploadStudentData=array();
  12910. $noUploadStudentData=array();
  12911. if($studentPaper){
  12912. foreach ($studentPaper as $item){
  12913. if(strcmp($item['student_id'],$uploadStudentId)==0){
  12914. $uploadStudentData=$item;
  12915. }elseif(strcmp($item['student_id'],$noUploadStudentId)==0){
  12916. $noUploadStudentData=$item;
  12917. }
  12918. }
  12919. }
  12920. if($examGroupArray->mark_type==4 && $examStatus[$uploadStudentData['exam_id']]==1){
  12921. $this->output(0, $uploadStudentData['realname']."所在班级已完成阅卷,需要先恢复阅卷状态,再转移学生成绩");
  12922. }
  12923. //开始转移
  12924. $transcation = $this->sConn->beginTransaction();
  12925. try {
  12926. //读取原学生成绩数据
  12927. $uploadStudentRs=$this->sConn->createCommand("select * from student_paper_relation where student_id='{$uploadStudentId}' and exam_id='{$uploadStudentData['exam_id']}'")->queryRow();
  12928. $setValue=array(
  12929. "complete_count='{$uploadStudentRs['complete_count']}'",
  12930. "right_count='{$uploadStudentRs['right_count']}'",
  12931. "partial_right_count='{$uploadStudentRs['partial_right_count']}'",
  12932. "wrong_count='{$uploadStudentRs['wrong_count']}'",
  12933. "scoring='{$uploadStudentRs['scoring']}'",
  12934. "lost_score='{$uploadStudentRs['lost_score']}'",
  12935. "is_feedback=1",
  12936. "feedback_time='{$uploadStudentRs['feedback_time']}'",
  12937. "student_img_paper='{$uploadStudentRs['student_img_paper']}'",
  12938. "is_complete='{$uploadStudentRs['is_complete']}'",
  12939. "complete_time='{$uploadStudentRs['complete_time']}'",
  12940. );
  12941. $sourceSetValue=array(
  12942. "complete_count='0'",
  12943. "right_count='0'",
  12944. "partial_right_count='0'",
  12945. "wrong_count='0'",
  12946. "scoring='0'",
  12947. "lost_score='0'",
  12948. "is_feedback=0",
  12949. "feedback_time='0'",
  12950. "student_img_paper='0'",
  12951. "is_complete='0'",
  12952. "complete_time='0'",
  12953. );
  12954. $this->sConn->createCommand("update student_paper_topic_rs set student_id='{$noUploadStudentId}',paper_id='{$noUploadStudentData['paper_id']}' where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute();
  12955. $this->sConn->createCommand("update student_paper_relation set ".implode(',',$sourceSetValue)." where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute();
  12956. $updateSql="update student_paper_relation set ".implode(',',$setValue)." where student_id='{$noUploadStudentId}' and paper_id='{$noUploadStudentData['paper_id']}'";
  12957. $this->sConn->createCommand($updateSql)->execute();
  12958. //判断未上传学生班级状态
  12959. $noUploadExam=$this->sConn->createCommand("select upload_status,subject_id from exam where exam_id='".$noUploadStudentData['exam_id']."'")->queryRow();
  12960. if($noUploadExam['upload_status']==0){
  12961. if($examGroupArray->mark_type>0){
  12962. $this->sConn->createCommand("update exam set upload_status=1,status=4 where exam_id='".$noUploadStudentData['exam_id']."'")->execute();
  12963. }else{
  12964. $this->sConn->createCommand("update exam set upload_status=1,status=1,complete_time='".time()."' where exam_id='".$noUploadStudentData['exam_id']."'")->execute();
  12965. }
  12966. }
  12967. //同步阅卷数据
  12968. if($examGroupArray->mark_type>0 && !$isAllSelect){
  12969. $params=array(
  12970. 'examGroupId'=>$examGroupId,
  12971. 'sourceStudentId'=>$uploadStudentId,
  12972. 'targetStudentId'=>$noUploadStudentId,
  12973. 'schoolId'=>$this->schoolId,
  12974. 'targetClazzId'=>$noUploadStudentData['class_id']
  12975. );
  12976. if($examGroupArray->qxk_paper_id>0){
  12977. //查询班级
  12978. $classInfo=$this->sConn->createCommand("select class_name from class where class_id='".$noUploadStudentData['class_id']."'")->queryRow();
  12979. //班级执教教师
  12980. $teacherClassData=$this->sConn->createCommand("select teacher_id from teacher_class_relation where class_id='".$noUploadStudentData['class_id']."'")->queryAll();
  12981. if ($teacherClassData) {
  12982. foreach ($teacherClassData as $v) {
  12983. $teacherIds[$v['teacher_id']] = $v['teacher_id'];
  12984. }
  12985. }
  12986. if ($noUploadExam['subject_id']) {
  12987. if (in_array($noUploadExam['subject_id'], array(3, 6, 51))) {
  12988. $subjectId = 3;
  12989. } else {
  12990. $subjectId = $noUploadExam['subject_id'];
  12991. }
  12992. }
  12993. $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id in(".implode(',',$teacherIds).") and subjects='{$subjectId}'")->queryRow();
  12994. if (!$teacherSubjectData) {
  12995. $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id='{$examGroupArray['teacher_id']}'")->queryRow();
  12996. }
  12997. $params['targetStudentName']=$noUploadStudentData['realname'];
  12998. $params['targetClazzId']=$noUploadStudentData['class_id'];
  12999. $params['targetClazzName']=$classInfo['class_name'];
  13000. $params['targetTeacherId']=$teacherSubjectData['teacher_id'];
  13001. $params['targetTeacherName']=$teacherSubjectData['teacher_name'];
  13002. $rs=http('/qxk/marking/exam/replace-marking','PUT',$this->schoolId,$params,'cgi');
  13003. }else{
  13004. $rs=http('/teacher/marking/v2/replace-marking','PUT',$this->schoolId,$params,'cgi');
  13005. }
  13006. $rs=json_decode($rs);
  13007. if(Yii::app()->params['handle_log_on_off'])
  13008. {
  13009. writeFileLog(jsonEncode(array(
  13010. "exam_group_id" => (string)$examGroupId,
  13011. "operate_project" => 'zsyas2',
  13012. "school_id" => $this->schoolId,
  13013. "title" => '转移成绩',
  13014. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  13015. "operate_method" => $this->action,
  13016. "operate_url" => $this->getRoute(),
  13017. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  13018. "zsyapi_return"=>$rs,
  13019. "date"=>date('Y-m-d H:i:s')
  13020. )));
  13021. }
  13022. if(!isset($rs->errCode) || $rs->errCode !='00')
  13023. {
  13024. throw new Exception($rs->errMsg);
  13025. }else{
  13026. $transcation->commit();
  13027. }
  13028. }else{
  13029. $transcation->commit();
  13030. }
  13031. if($examGroupArray->mark_type==0){
  13032. $kafkaData=array(
  13033. 'schoolId'=>$this->schoolId,
  13034. 'examGroupId'=>$examGroupId,
  13035. 'generateTime'=>time()*1000
  13036. );
  13037. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  13038. }
  13039. $this->output(1, "转移成功");
  13040. } catch (Exception $e) {
  13041. $transcation->rollback();
  13042. $this->output(0, "转移失败");
  13043. }
  13044. }
  13045. /**
  13046. * 生成产品消息
  13047. * @return mixed
  13048. */
  13049. public function actionSendProductHtml()
  13050. {
  13051. $examGroupId = Req::post('examGroupId');
  13052. $examId = Req::post('examId');
  13053. $sendMsg=array(
  13054. 'school_id'=>$this->schoolId,
  13055. 'msg_type'=>3,
  13056. 'subject_id'=>Yii::app()->session['session_subject_id'],
  13057. 'send_type'=>'exam',
  13058. 'exam_group_id'=>$examGroupId,
  13059. 'exam_ids'=>array($examId)
  13060. );
  13061. sendDataToKafka('xbkc-php-product-html',$sendMsg);
  13062. return true;
  13063. }
  13064. //获取多种指定产品权限
  13065. protected function getManyProductOrder($params,$classify=array(),$studentIds=array())
  13066. {
  13067. $intarr = array();
  13068. $orderIds = array();
  13069. if ($classify) {
  13070. foreach ($classify as $item) {
  13071. $params['students'] = $studentIds;
  13072. $params['classify'] = $item;
  13073. $intarr[] = $params;
  13074. }
  13075. }
  13076. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  13077. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr), $basic), true);
  13078. if (isset($rs['errCode']) && $rs['errCode'] == "00" && isset($rs['data']) && $rs['data']) {
  13079. foreach ($rs['data'] as $r) {
  13080. $orderIds = array_merge($orderIds, $r);
  13081. }
  13082. }
  13083. return $orderIds;
  13084. }
  13085. //下载全学科试卷解析
  13086. public function actionDownloadPaper(){
  13087. $examGroupId = Req::post('examGroupId');
  13088. $paperSheet =Req::post('paperSheet');
  13089. $downloadType =Req::post('downloadType');
  13090. $wordType = Req::post('wordType');
  13091. $isPrint = Req::post('isPrint');
  13092. $examGroup=SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId));
  13093. if(!$examGroup) returnMsg(0,'考试id不存在');
  13094. $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  13095. $paper=SPaper::model()->find('exam_id=:e_id',array(':e_id'=>$exam['exam_id']));
  13096. $paperTopic=$this->sConn->createCommand("select topic_id,`type`,`order`,score,stem_id,`no` from paper_topic_relation where paper_id='".$paper['paper_id']."' order by `type` asc,`order` asc")->queryAll();
  13097. $alias=array();
  13098. $tplData=json_decode($exam['tpl_data'],true);
  13099. $selectTopicGroup=array();
  13100. if(isset($tplData['new_items'])){
  13101. foreach ($tplData['new_items'] as $item){
  13102. if(isset($item['fullAlias'])){
  13103. if(is_numeric($item['fullAlias'])){
  13104. $alias[$item['id']]=$item['fullAlias'];
  13105. }else{
  13106. $alias[$item['id']]=$item['stemAlias'];
  13107. }
  13108. }else{
  13109. $alias[$item['id']]=$item['alias'];
  13110. if($item['stemId']==$item['topicId']){
  13111. $stemAlias[$item['id']]=$item['alias'];
  13112. }else{
  13113. $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
  13114. }
  13115. }
  13116. if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
  13117. $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
  13118. }
  13119. }
  13120. }
  13121. $topicIds=array();
  13122. if($paperTopic)
  13123. {
  13124. foreach($paperTopic as $k=>$v)
  13125. {
  13126. if(isset($v['stem_id']) && $v['stem_id']){
  13127. $topicId=$v['stem_id'];
  13128. }else{
  13129. $topicId=$v['topic_id'];
  13130. }
  13131. $topicIds[]=$topicId;
  13132. $topicNumber[(string)$v['topic_id']]=array(
  13133. 'topic_id'=>$v['topic_id'],
  13134. 'type'=>$v['type'],
  13135. 'order'=>$v['order'],
  13136. 'score'=>$v['score'],
  13137. );
  13138. }
  13139. }else{
  13140. returnMsg(0,'请先创建答题卡');
  13141. }
  13142. //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$exam->subject_id);
  13143. $topicDetail=$this->schoolManager->getQxkPaperTopics(array_values($topicIds));
  13144. foreach ($topicDetail as $item){
  13145. if(!isset($topicType[$item['typeId']])){
  13146. $topicType[$item['typeId']]=array(
  13147. 'typeName'=>$item['typeName'],
  13148. 'description'=>'',
  13149. 'topics'=>array()
  13150. );
  13151. }
  13152. $topic=array();
  13153. $id=(string)number_format($item['topicId'],0,'','');
  13154. $topic['topicId']=$id;
  13155. if(isset($topicNumber[$id])){
  13156. $topic['score']=$topicNumber[$id]['score'];
  13157. $order=$topicNumber[$id]['order'];
  13158. $topicType[$item['typeId']]['order']=$order;
  13159. if(isset($alias[$order])){
  13160. $topic['topicNo']=$alias[$order];
  13161. }else{
  13162. $topic['topicNo']=$order;
  13163. }
  13164. //判断选做题
  13165. if(isset($selectTopicGroup[$topicNumber[$id]['order']])){
  13166. $topic['groupId']=$selectTopicGroup[$topicNumber[$id]['order']];
  13167. }
  13168. }
  13169. if(isset($item['slaveList']) && $item['slaveList']){
  13170. foreach ($item['slaveList'] as $val){
  13171. $slave=array();
  13172. if(isset($val['slaveList']) && $val['slaveList']){
  13173. foreach ($val['slaveList'] as $third){
  13174. $thirdSlave=array();
  13175. $thirdSlave['topicId']=(string)number_format($third['topicSlaveId'],0,'','');
  13176. if(isset($topicNumber[(string)$thirdSlave['topicId']])){
  13177. $thirdSlave['score']=$topicNumber[(string)$thirdSlave['topicId']]['score'];
  13178. $thirdOrder=$topicNumber[(string)$thirdSlave['topicId']]['order'];
  13179. if(isset($alias[$thirdOrder])){
  13180. $thirdSlave['topicNo']=$alias[$thirdOrder];
  13181. }else{
  13182. $thirdSlave['topicNo']=$thirdOrder;
  13183. }
  13184. if(!isset($topicType[$item['typeId']]['order'])){
  13185. $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicId']]['order'];
  13186. }
  13187. if(isset($topicNumber[(string)$thirdSlave['topicId']]['scores'])){
  13188. $thirdSlave['scores']=$topicNumber[(string)$thirdSlave['id']]['scores'];
  13189. }
  13190. if(!isset($topic['topicNo'])){
  13191. $topic['topicNo']= $thirdSlave['topicNo'];
  13192. }
  13193. //判断选做题
  13194. if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']])){
  13195. $thirdSlave['groupId']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']];
  13196. }
  13197. }
  13198. $slave['slave'][]=$thirdSlave;
  13199. }
  13200. }else{
  13201. if(isset($topicNumber[(string)$val['topicSlaveId']])){
  13202. $slave['topicId']=$val['topicSlaveId'];
  13203. $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score'];
  13204. $slaveOrder=$topicNumber[(string)$val['topicSlaveId']]['order'];
  13205. if(isset($alias[$slaveOrder])){
  13206. $slave['topicNo']=$alias[$slaveOrder];
  13207. }else{
  13208. $slave['topicNo']=$slaveOrder;
  13209. }
  13210. if(!isset($topicType[$item['typeId']]['order'])){
  13211. $topicType[$item['typeId']]['order']=$slaveOrder;
  13212. }
  13213. if(!isset($topic['topicNo'])){
  13214. $topic['topicNo']= $slave['topicNo'];
  13215. }
  13216. //判断选做题
  13217. if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){
  13218. $slave['groupId']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']];
  13219. }
  13220. }
  13221. }
  13222. $topic['slave'][]=$slave;
  13223. }
  13224. }
  13225. $topicType[$item['typeId']]['topics'][]=$topic;
  13226. }
  13227. $lastOrder = $this->_array_column($topicType,'order');
  13228. array_multisort($lastOrder,SORT_ASC,$topicType);
  13229. //拆分选做题
  13230. if($selectTopicGroup){
  13231. $selectTopicType=array();
  13232. $selectTopicType['typeName']='选做题';
  13233. $selectTopicType['topics']=array();
  13234. foreach ($topicType as $key => $item){
  13235. foreach ($item['topics'] as $vk => $val){
  13236. if(isset($val['groupId'])){
  13237. unset($val['groupId']);
  13238. $selectTopicType['topics'][]=$val;
  13239. unset($topicType[$key]['topics'][$vk]);
  13240. $selectTopicType['order']=$val['topicNo'];
  13241. }
  13242. }
  13243. if(count($topicType[$key]['topics'])==0){
  13244. unset($topicType[$key]);
  13245. }
  13246. }
  13247. $topicType[17]=$selectTopicType;
  13248. }
  13249. //计算小题数量
  13250. foreach ($topicType as $key => $item){
  13251. $topicNumber=0;
  13252. $scores=0;
  13253. foreach ($item['topics'] as $k => $val){
  13254. if(isset($val['slave'])){
  13255. foreach ($val['slave'] as $v){
  13256. if(isset($v['slave'])){
  13257. foreach ($v['slave'] as $value){
  13258. if(isset($value['score'])){
  13259. $scores+=$value['score'];
  13260. }
  13261. $topicNumber++;
  13262. }
  13263. }else{
  13264. if(isset($v['score'])){
  13265. $scores+=$v['score'];
  13266. }
  13267. $topicNumber++;
  13268. }
  13269. }
  13270. unset($topicType[$key]['topics'][$k]['slave']);
  13271. }else{
  13272. if($key==17){
  13273. $scores=$val['score'];
  13274. }else{
  13275. $scores+=$val['score'];
  13276. }
  13277. $topicNumber++;
  13278. }
  13279. }
  13280. //选做题(每小题2分,共2分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤)
  13281. if($key==17){
  13282. $topicType[$key]['description']='每小题'.$scores.'分,共'.$scores.'分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤';
  13283. }else{
  13284. $topicType[$key]['description']='本大题共'.$topicNumber.'小题,共'.$scores.'分';
  13285. }
  13286. }
  13287. $topicType=array_values($topicType);
  13288. if($paperSheet==0){
  13289. $paperOrientation=1;
  13290. }elseif($paperSheet==2){
  13291. //A4横版
  13292. $paperSheet=0;
  13293. $paperOrientation=0;
  13294. }elseif($paperSheet==1){
  13295. $paperOrientation=null;
  13296. }
  13297. $postParam=array(
  13298. 'subjectId'=>$exam['subject_id'],
  13299. 'downloadType'=>$downloadType,
  13300. 'paperSheet'=>$paperSheet,
  13301. 'wordType'=>$wordType,
  13302. 'paperOrientation'=>$paperOrientation,
  13303. 'subPaperName'=>'',
  13304. 'hasBindLine'=>0,
  13305. 'hasSealFlag'=>0,
  13306. 'attentionInfo'=>'',
  13307. 'paperName'=>$exam['name'],
  13308. 'examTime'=>$tplData['times'],
  13309. 'totalScore'=>$tplData['scores'],
  13310. 'createBy'=>$tplData['author'],
  13311. 'applyBy'=>'',
  13312. 'teacherId'=>$examGroup['teacher_id'],
  13313. 'semesterId'=>$this->semesterId,
  13314. 'types'=>$topicType,
  13315. 'isZxhx'=>3
  13316. );
  13317. $header=array('X-Basic-V:2');
  13318. $cgi=Yii::app()->params['cgi'];
  13319. $username=$cgi['username'];
  13320. $password=$cgi['password'];
  13321. if($isPrint){
  13322. $url = $cgi['domain'].'dmw/qxk/download/mathtype-pdf';
  13323. }else{
  13324. $url = $cgi['domain'].'dmw/qxk/download/mathtype-word';
  13325. }
  13326. $rs = $this->CrmApiPost($url,$postParam,$username,$password,'POST',$header);
  13327. if(isset($rs->errCode) && $rs->errCode=='00'){
  13328. $this->schoolManager->saveExamProcess($examGroupId,14,time());
  13329. if($isPrint){
  13330. //组装打印参数
  13331. $printData=array();
  13332. $printData['typeId']=18;
  13333. $printData['productType']=60001;
  13334. $printData['params']=array(
  13335. 'classIds'=>array(),
  13336. 'url'=>$rs->data,
  13337. 'name'=>$exam['name'],
  13338. 'subjectId'=>$exam['subject_id'],
  13339. 'examGroupId'=>$exam['exam_group_id'],
  13340. );
  13341. returnMsg(1,'success',$printData);
  13342. }else{
  13343. returnMsg(1,'success',$rs->data);
  13344. }
  13345. }else{
  13346. returnMsg(0,$rs->errMsg);
  13347. }
  13348. }
  13349. function _array_column(array $array, $column_key, $index_key=null){
  13350. $result = array();
  13351. foreach($array as $arr) {
  13352. if(!is_array($arr)) continue;
  13353. if(is_null($column_key)){
  13354. $value = $arr;
  13355. }else{
  13356. $value = $arr[$column_key];
  13357. }
  13358. if(!is_numeric($value)){
  13359. $value=intval($value);
  13360. }
  13361. if(!is_null($index_key)){
  13362. $key = $arr[$index_key];
  13363. $result[$key] = $value;
  13364. }else{
  13365. $result[] = $value;
  13366. }
  13367. }
  13368. return $result;
  13369. }
  13370. //读取考试班级产品设置相同题
  13371. public function findExamClassSameTrain($examGroupId,$subject=3){
  13372. if(in_array($subject,$this->mathSubjectId)){
  13373. $subject=3;
  13374. }
  13375. $classes=$this->sConn->createCommand("select class_id from exam where exam_group_id='{$examGroupId}'")->queryAll();
  13376. if($classes){
  13377. //读取产品设置版本
  13378. $productSetEdition=$this->sConn->createCommand("select switch from producut_set_edition limit 1")->queryRow();
  13379. $isBeta=0;
  13380. if($productSetEdition && $productSetEdition['switch']==4){
  13381. $isBeta=1;
  13382. }
  13383. //查询默认模板
  13384. $classIds=array();
  13385. foreach ($classes as $key => $value) {
  13386. $classIds[]=$value['class_id'];
  13387. }
  13388. if($subject==3){
  13389. $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' and is_beta='{$isBeta}'")->queryAll();
  13390. }else{
  13391. $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' ")->queryAll();
  13392. }
  13393. $needCheckDefault=false;
  13394. if($classSet){
  13395. //有配置
  13396. $tids=array();
  13397. $tidClass=array();
  13398. foreach ($classSet as $val) {
  13399. if($val['template_id']){
  13400. $tidClass[$val['class_id']][$val['template_id']]=$val['template_id'];
  13401. $tids[$val['template_id']]=$val['template_id'];
  13402. }
  13403. if($val['isp']){
  13404. $tidClass[$val['class_id']][$val['isp']]=$val['isp'];
  13405. $tids[$val['isp']]=$val['isp'];
  13406. }
  13407. if($val['wb_isp']){
  13408. $tidClass[$val['class_id']][$val['wb_isp']]=$val['wb_isp'];
  13409. $tids[$val['wb_isp']]=$val['wb_isp'];
  13410. }
  13411. }
  13412. if(count($classIds)!=count($tidClass)){
  13413. //有班级是取默认设置
  13414. $needCheckDefault=true;
  13415. }
  13416. if($tids){
  13417. $template=$this->sConn->createCommand("select config_text from product_template where template_id in(".implode(',',$tids).")")->queryAll();
  13418. if($template){
  13419. foreach ($template as $key => $v) {
  13420. $jsonData=json_decode($v['config_text'],true);
  13421. if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){
  13422. return true;
  13423. }
  13424. }
  13425. }
  13426. }
  13427. }
  13428. if($needCheckDefault || !$classSet){
  13429. //没有配置,读取默认模板
  13430. if($subject==3){
  13431. $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 and is_beta='{$isBeta}'")->queryAll();
  13432. }else{
  13433. $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 ")->queryAll();
  13434. }
  13435. if($template){
  13436. foreach ($template as $key => $v) {
  13437. $jsonData=json_decode($v['config_text'],true);
  13438. if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){
  13439. return true;
  13440. }
  13441. }
  13442. }
  13443. }
  13444. }
  13445. return false;
  13446. }
  13447. /*学管发送还原考试申请*/
  13448. public function actionRestoreApply(){
  13449. $examGroupId = Req::post('examId');
  13450. $result['status']=0;
  13451. if(!$examGroupId){
  13452. $result['msg']="参数异常";
  13453. exit(jsonEncode($result));
  13454. }
  13455. $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  13456. if(!$exam){
  13457. $result['msg']="未查询到考试信息";
  13458. exit(jsonEncode($result));
  13459. }
  13460. $tplData=json_decode($exam->tpl_data,true);
  13461. //查询申请记录
  13462. $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  13463. if($examRestore){
  13464. $result['msg']="考试已经申请,不要重复操作";
  13465. exit(jsonEncode($result));
  13466. }
  13467. $model=new SExamRestore();
  13468. $model->exam_group_id=$examGroupId;
  13469. $model->exam_name=$exam->name;
  13470. $model->subject_name=Yii::app()->params['subjectId'][$exam->subject_id];
  13471. $model->exam_date=$tplData['examDate'];
  13472. $model->create_time=time();
  13473. if($model->save()){
  13474. if(Yii::app()->params['handle_log_on_off'])
  13475. {
  13476. writeFileLog(jsonEncode(array(
  13477. "exam_group_id" => (string)$examGroupId,
  13478. "operate_project" => 'zsyas2',
  13479. "school_id" => $this->schoolId,
  13480. "title" => '还原申请',
  13481. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  13482. "operate_method" => $this->action,
  13483. "operate_url" => $this->getRoute(),
  13484. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  13485. "date"=>date('Y-m-d H:i:s')
  13486. )));
  13487. }
  13488. $result['status']=1;
  13489. exit(jsonEncode($result));
  13490. }else{
  13491. $result['msg']="申请失败";
  13492. exit(jsonEncode($result));
  13493. }
  13494. }
  13495. /*退回还原考试申请*/
  13496. public function actionRestoreApplyBack(){
  13497. $examGroupId = Req::post('examId');
  13498. $result['status']=0;
  13499. if(!$examGroupId){
  13500. $result['msg']="参数异常";
  13501. exit(jsonEncode($result));
  13502. }
  13503. $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  13504. if(!$exam){
  13505. $result['msg']="未查询到考试信息";
  13506. exit(jsonEncode($result));
  13507. }
  13508. //查询申请记录
  13509. $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  13510. if(!$examRestore){
  13511. $result['msg']="申请已退回,不要重复操作";
  13512. exit(jsonEncode($result));
  13513. }
  13514. $rs = SExamRestore::model()->deleteByPk($examGroupId);
  13515. if($rs){
  13516. $result['status']=1;
  13517. if(Yii::app()->params['handle_log_on_off'])
  13518. {
  13519. writeFileLog(jsonEncode(array(
  13520. "exam_group_id" => (string)$examGroupId,
  13521. "operate_project" => 'zsyas2',
  13522. "school_id" => $this->schoolId,
  13523. "title" => '还原申请退回',
  13524. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  13525. "operate_method" => $this->action,
  13526. "operate_url" => $this->getRoute(),
  13527. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  13528. "date"=>date('Y-m-d H:i:s')
  13529. )));
  13530. }
  13531. exit(jsonEncode($result));
  13532. }else{
  13533. $result['msg']="退回失败";
  13534. exit(jsonEncode($result));
  13535. }
  13536. }
  13537. //标注预计完成时间计算
  13538. public function ComputeCompleteTime($examGroupId){
  13539. if(!$examGroupId) return false;
  13540. $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='{$examGroupId}'")->queryAll();
  13541. if(!$exam) return false;
  13542. $examIds=array();
  13543. foreach ($exam as $val){
  13544. $examIds[]=$val['exam_id'];
  13545. }
  13546. $taskTime=0;
  13547. $studentPaper=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).")")->queryRow();
  13548. $studentCount=$studentPaper['count'];
  13549. if($studentCount<=500){
  13550. $taskTime=36;
  13551. }elseif($studentCount<=1000){
  13552. $taskTime=24;
  13553. }elseif($studentCount<=1500){
  13554. $taskTime=12;
  13555. }else{
  13556. $taskTime=6;
  13557. }
  13558. $data['studentNumber']=$studentCount;
  13559. $data['estimate']=expectTime($taskTime,time());
  13560. return $data;
  13561. }
  13562. /**
  13563. * 英语外刊阅读初始化获取 版本 模块 单元
  13564. */
  13565. public function actionAjaxReadingTextbookModuleUnit(){
  13566. //版本 模块 单元
  13567. $textbooks=$modules=$units=array();
  13568. // $textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8));
  13569. $textbookResult=$this->apiPost('all_textbook/getTextbookByImsProduct',array('subjectId'=>8,'imsProductId'=>6));
  13570. if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){
  13571. $textbookResult=$textbookResult['data'];
  13572. foreach($textbookResult as $textbookKey=>$textbookItem){
  13573. $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']);
  13574. if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){
  13575. foreach($textbookItem['child'] as $moduleKey=>$moduleItem){
  13576. $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
  13577. if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
  13578. foreach($moduleItem['child'] as $unitItem){
  13579. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  13580. }
  13581. }
  13582. }
  13583. }
  13584. }
  13585. }
  13586. $date_msg = $this->getWeekOnMonth();
  13587. $year = $date_msg["year"];
  13588. $month = $date_msg["month"];
  13589. $week = $date_msg["week"];
  13590. $weekUpper = numToUpper($week);
  13591. $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周';
  13592. $data=array(
  13593. 'textbooks'=>$textbooks,//版本
  13594. 'modules'=>$modules,//模块
  13595. 'units'=>$units,//单元
  13596. 'week_name'=>$weekName,
  13597. );
  13598. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13599. }
  13600. /*
  13601. * 英语外刊阅读获取班级数据
  13602. */
  13603. public function actionAjaxReadingClasses(){
  13604. $req=Req::input();
  13605. $grade=isset($req['grade'])?(int)$req['grade']:0;
  13606. $gc=isset($req['category'])?(int)$req['category']:1; //产品种类 1综合(老版) 2 分离(新版)
  13607. $pt=isset($req['pt'])?(int)$req['pt']:1; //产品类型:1-基础宝 2-外刊宝 3-热点宝
  13608. if(!$grade){
  13609. exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
  13610. }
  13611. $class=$this->getClassesBySettingReading($grade,$gc,$pt);
  13612. $data=array(
  13613. 'class'=>$class,
  13614. );
  13615. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13616. }
  13617. /*
  13618. * 英语外刊阅读获取基础选题
  13619. */
  13620. public function actionAjaxReadingBasicTopics(){
  13621. $req=Req::input();
  13622. $grade=isset($req['grade'])?(int)$req['grade']:0;
  13623. if(!$grade){
  13624. exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
  13625. }
  13626. $basicTopics=array();
  13627. $basicTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>1,'grade'=>$grade));
  13628. if(isset($basicTopicsResult['status']) && $basicTopicsResult['status'] && isset($basicTopicsResult['data']) && $basicTopicsResult['data']){
  13629. $basicTopics=$basicTopicsResult['data'];
  13630. }
  13631. $data=array(
  13632. 'basic_topics'=>$basicTopics,
  13633. );
  13634. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13635. }
  13636. /*
  13637. * 英语外刊阅读获取热点选题
  13638. */
  13639. public function actionAjaxReadingHotTopics(){
  13640. $req=Req::input();
  13641. $grade=isset($req['grade'])?(int)$req['grade']:0;
  13642. if(!$grade){
  13643. exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
  13644. }
  13645. $hotTopics=array();
  13646. $hotTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>2,'grade'=>$grade));
  13647. if(isset($hotTopicsResult['status']) && $hotTopicsResult['status'] && isset($hotTopicsResult['data']) && $hotTopicsResult['data']){
  13648. $hotTopics=$hotTopicsResult['data'];
  13649. }
  13650. $data=array(
  13651. 'hot_topics'=>$hotTopics,
  13652. );
  13653. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13654. }
  13655. /*
  13656. * 英语外刊阅读获取主题语境
  13657. */
  13658. public function actionAjaxReadingSubjectContext(){
  13659. $subjectContextResult=$this->apiPost('all_textbook/subjectContext',array());
  13660. if(isset($subjectContextResult['status']) && $subjectContextResult['status'] && isset($subjectContextResult['data']) && $subjectContextResult['data']){
  13661. $subjectContext=$subjectContextResult['data'];
  13662. }
  13663. $data=array(
  13664. 'subject_context'=>$subjectContext,
  13665. );
  13666. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13667. }
  13668. /**
  13669. * 根据版本获取模块和单元数据
  13670. */
  13671. public function actionAjaxNewGetModuleAndUnit(){
  13672. $req=Req::input();
  13673. $versionId=isset($req['version_id'])?(int)$req['version_id']:0;
  13674. $queryType=isset($req['query_type'])?(int)$req['query_type']:1;
  13675. if(!$versionId){
  13676. $versionId=(int)Req::post('version_id');
  13677. $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
  13678. }
  13679. $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
  13680. $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
  13681. $moduleResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId));
  13682. $modules=$units=$chapters=array();
  13683. if(isset($moduleResult['status']) && $moduleResult['status'] && isset($moduleResult['data']) && $moduleResult['data']){
  13684. $moduleResult=array_values($moduleResult['data']);
  13685. foreach($moduleResult as $moduleKey=>$moduleItem){
  13686. $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
  13687. if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
  13688. foreach($moduleItem['child'] as $unitKey=>$unitItem){
  13689. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  13690. if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){
  13691. foreach($unitItem['child'] as $chapterItem){
  13692. $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
  13693. }
  13694. }
  13695. }
  13696. }
  13697. }
  13698. }
  13699. $data=array(
  13700. 'modules'=>$modules,//模块
  13701. 'units'=>$units,//单元
  13702. 'chapters'=>$chapters,//章节
  13703. );
  13704. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13705. }
  13706. /**
  13707. * 根据版本获取单元数据
  13708. */
  13709. public function actionAjaxNewGetUnitByModuleId(){
  13710. $req=Req::input();
  13711. $versionId=isset($req['version_id'])?(int)$req['version_id']:0;
  13712. $moduleId=isset($req['module_id'])?(int)$req['module_id']:0;
  13713. $queryType=isset($req['query_type'])?(int)$req['query_type']:1;
  13714. if(!$moduleId){
  13715. $versionId=(int)Req::post('version_id');
  13716. $moduleId=(int)Req::post('module_id');
  13717. $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
  13718. }
  13719. $unitResult=$this->apiPost('all_textbook/getUnit',array('module_id'=>$moduleId,'query_type'=>$queryType,'version_id'=>$versionId));
  13720. $units=array();
  13721. if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){
  13722. $unitResult=$unitResult['data'];
  13723. foreach($unitResult as $unitKey=>$unitItem){
  13724. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  13725. }
  13726. }
  13727. $data=array(
  13728. 'units'=>$units,//单元
  13729. );
  13730. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13731. }
  13732. /**
  13733. * 根据模块获取单元数据和章节数据
  13734. */
  13735. public function actionAjaxNewGetUnitAndChapters(){
  13736. $versionId=(int)Req::post('version_id');
  13737. $moduleId=(int)Req::post('module_id');
  13738. $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
  13739. $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
  13740. $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
  13741. $unitResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId));
  13742. $units=$chapters=array();
  13743. if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){
  13744. $unitResult=array_values($unitResult['data']);
  13745. foreach($unitResult as $unitKey=>$unitItem){
  13746. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  13747. if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){
  13748. foreach($unitItem['child'] as $chapterItem){
  13749. $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
  13750. }
  13751. }
  13752. }
  13753. }
  13754. $data=array(
  13755. 'units'=>$units,//单元
  13756. 'chapters'=>$chapters,//章节
  13757. );
  13758. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13759. }
  13760. /**
  13761. * 根据单元获取章节数据
  13762. */
  13763. public function actionAjaxNewGetChapters(){
  13764. $versionId=(int)Req::post('version_id');
  13765. $moduleId=(int)Req::post('module_id');
  13766. $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
  13767. $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
  13768. $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
  13769. $chapterResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId));
  13770. $chapters=array();
  13771. if(isset($chapterResult['status']) && $chapterResult['status'] && isset($chapterResult['data']) && $chapterResult['data']){
  13772. $chapterResult=array_values($chapterResult['data']);
  13773. foreach($chapterResult as $chapterItem){
  13774. $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
  13775. }
  13776. }
  13777. $data=array(
  13778. 'chapters'=>$chapters,//章节
  13779. );
  13780. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13781. }
  13782. /**
  13783. * 智能模式下设置的产品类型学生数据
  13784. */
  13785. public function actionAjaxSmartTypeStudents(){
  13786. $req=Req::input();
  13787. $classIds=isset($req['selectClassIds'])?$req['selectClassIds']:array();
  13788. if(!$classIds || !is_array($classIds)){
  13789. exit(json_encode(array('status'=>0,'msg'=>'请检查班级参数')));
  13790. }
  13791. $classIdsStr=implode(',',$classIds);
  13792. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_id in ({$classIdsStr}) and is_hide=0";
  13793. $validClass = $this->sConn->createCommand($sql)->queryAll();
  13794. if(!$validClass){
  13795. exit(json_encode(array('status'=>0,'msg'=>'成功','data'=>array())));
  13796. }
  13797. // $validClass=$this->_array_column($validClass,'class_name','class_id');
  13798. $newValidClass = array();
  13799. foreach($validClass as $k=>$v){
  13800. $newValidClass[(string)$v['class_id']] = $v['class_name'];
  13801. }
  13802. $validClass = $newValidClass;
  13803. $classIdsStr=implode(',',array_keys($validClass));
  13804. $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and si.reading_level>0 and scr.status=0";
  13805. $studentInfo = $this->sConn->createCommand($sql)->queryAll();
  13806. $studentType=array();
  13807. foreach($studentInfo as $item){
  13808. $classId=$item['class_id'];
  13809. $studentId=(string)$item['student_id'];
  13810. $readingLevel=$item['reading_level'];
  13811. if(!isset($studentType[$readingLevel][$classId]) || !array_key_exists($studentId,$studentType[$readingLevel][$classId])) {
  13812. $studentType[$readingLevel][$classId][$studentId] = $item['realname'];
  13813. }
  13814. }
  13815. $readingSmartTypes=array(1,2,3);
  13816. $lists=array();
  13817. foreach($readingSmartTypes as $type){
  13818. $classInfo=array();
  13819. foreach($validClass as $classId=>$className){
  13820. $classId=(string)$classId;
  13821. if(isset($studentType[$type][$classId])){
  13822. $studentsArr=$studentType[$type][$classId];
  13823. $students=array();
  13824. foreach($studentsArr as $studentId=>$studentName){
  13825. $students[]=array('student_id'=>(string)$studentId,'realname'=>$studentName);
  13826. }
  13827. $classInfo[]=array(
  13828. 'class_id'=>$classId,
  13829. 'class_name'=>$className,
  13830. 'students'=>$students,
  13831. );
  13832. }else{
  13833. $classInfo[]=array(
  13834. 'class_id'=>$classId,
  13835. 'class_name'=>$className,
  13836. 'students'=>array(),
  13837. );
  13838. }
  13839. }
  13840. $lists[]=array(
  13841. 'product_type'=>$type,
  13842. 'class_info'=>$classInfo,
  13843. );
  13844. unset($classInfo);
  13845. }
  13846. $data=array('lists'=>$lists);
  13847. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  13848. }
  13849. /**
  13850. * 外刊阅读保存设置
  13851. */
  13852. public function actionAjaxNewSaveEnglishReading(){
  13853. $error = array();
  13854. $req=Req::input();
  13855. if (!Yii::app()->request->isPostRequest){
  13856. $error[] = '错误的来源!';
  13857. }else{
  13858. $grade=isset($req['grade'])?(int)$req['grade']:0;//年级:1-高一 2-高二 3-高三
  13859. $textbookId=isset($req['textbookId'])?(int)$req['textbookId']:0;//教材Id
  13860. $moduleId=isset($req['moduleId'])?(int)$req['moduleId']:0;//模块Id
  13861. $unitId=isset($req['unitId'])?$req['unitId']:array();//单元Id
  13862. $classIds=isset($req['selectClassIds']) && is_array($req['selectClassIds']) ?$req['selectClassIds']:array();//班级
  13863. $itemIds=isset($req['selectedItemIds']) && is_array($req['selectedItemIds'])?$req['selectedItemIds']:array();//主题语境下话题
  13864. $type=isset($req['type'])?(int)$req['type']:0;//外刊类型:1-个性外刊 2-共性外刊
  13865. $level=isset($req['level'])?(int)$req['level']:0;//外刊分级 1-尖子班 2-培优班 3-提高班
  13866. $isAnswerSeparate=isset($req['isAnswerSeparate'])?(int)$req['isAnswerSeparate']:0;;//答案是否分开打印 0否 1是
  13867. $isNewVersion = 1;//是否新版本 1是 0否
  13868. $recommendMode=isset($req['recommend_mode'])?(int)$req['recommend_mode']:0;;//推荐模式:1-经典模式 2-智能推荐模式
  13869. $productType=isset($req['product_type'])?(int)$req['product_type']:0;;//产品类型:1-基础宝 2-外刊宝 3-热点宝
  13870. $basicTopic=isset($req['basic_topic'])?(int)$req['basic_topic']:0;;//基础选题
  13871. $hotTopic=isset($req['hot_topic'])?(int)$req['hot_topic']:0;//热点选题
  13872. $topicNumber=isset($req['topic_number'])?$req['topic_number']:array();//题目数量
  13873. $selectSetType=isset($req['select_set_type'])?$req['select_set_type']:0;//选择的类型 1-按照教材单元设置 2-主题语境设置 3-时文阅读
  13874. $classBetweenContent=isset($req['class_between_content'])?$req['class_between_content']:0;//班级间内容: 0-相同 1-不同
  13875. $category=isset($req['category'])?(int)$req['category']:1;//产品种类 1综合(老版) 2 分离(新版)
  13876. $classify=19;
  13877. $weekNameExt='外刊宝';
  13878. if($category==2){
  13879. if($productType==1){
  13880. $classify=57;
  13881. $weekNameExt='基础宝';
  13882. }elseif($productType==2){
  13883. $classify=61;
  13884. $weekNameExt='外刊宝';
  13885. }elseif($productType==3){
  13886. $classify=58;
  13887. $weekNameExt='热点宝';
  13888. }
  13889. }
  13890. if(!in_array($selectSetType,array(1,2,3))){
  13891. $error[] = '请选择设置类型';
  13892. }
  13893. if($selectSetType==1){
  13894. if(!$textbookId || !$moduleId || !$unitId){
  13895. $error[] = '按照教材单元设置时教材、模块、单元不能为空';
  13896. }
  13897. $itemIds=array();
  13898. }elseif($selectSetType==2){
  13899. if(!$itemIds){
  13900. $error[] = '主题语境设置时主题语境不能为空';
  13901. }
  13902. $unitId=array();$textbookId=$moduleId=0;
  13903. }elseif($selectSetType==3){
  13904. //时文阅读无这几个参数,处理成不传时候的默认值
  13905. $itemIds=$unitId=array();$textbookId=$moduleId=0;
  13906. }
  13907. if($unitId){
  13908. if(!is_array($unitId)){
  13909. $error[] = '单元格式不正确';
  13910. }
  13911. if(is_array($unitId) && count($unitId)>3) {
  13912. $error[] = '单元最多3个';
  13913. }
  13914. }
  13915. if($unitId && is_array($unitId) && $unitId){
  13916. $unitId=empty($unitId)?0:implode(',',$unitId);
  13917. }elseif(!$unitId){
  13918. $unitId=0;
  13919. }
  13920. if(!in_array($grade,array(1,2,3))){
  13921. $error[] = '请选择正确年级';
  13922. }
  13923. if(!$classIds || !is_array($classIds)){
  13924. $error[] = '请选择班级';
  13925. }
  13926. if(!in_array($recommendMode,array(1,2))){
  13927. $error[] = '推荐模式不在范围内';
  13928. }
  13929. if($recommendMode==1 && !in_array($productType,array(1,2,3))){
  13930. $error[] = '产品类型不在范围内';
  13931. }
  13932. if(!in_array($classBetweenContent,array(0,1))){
  13933. $error[] = '请检查班级间内容';
  13934. }
  13935. if(!in_array($category,array(1,2))){
  13936. $error[] = '产品种类不在合理范围内';
  13937. }
  13938. //经典模式
  13939. if($recommendMode==1){
  13940. if($productType==1){//基础宝
  13941. if(!$basicTopic){
  13942. $error[] = '请选择基础选题';
  13943. }
  13944. //不需要的值,设为0或者空
  13945. $type=0;$level=0;$hotTopic=0;$topicNumberJson='';$classBetweenContent=0;
  13946. }elseif($productType==2){//外刊宝
  13947. if(!in_array($type,array(1,2))){
  13948. $error[] = '请选择外刊类型';
  13949. }
  13950. if($type==2 && !in_array($level,array(1,2,3))){
  13951. $error[] = '外刊类型是共性外刊时请选择正确的外刊分级';
  13952. }
  13953. unset($topicNumber['hot']);
  13954. if(!$topicNumber || !isset($topicNumber['periodicals']) || count($topicNumber)!=1){
  13955. $error[] = '检查题目数量';
  13956. }else{
  13957. $error=array_merge($error,$this->validateTopicNumber($topicNumber));
  13958. }
  13959. //不需要的值,设为0或者空
  13960. $basicTopic=0;$hotTopic=0;
  13961. if($type==1){
  13962. $level=0;
  13963. $classBetweenContent=0;//外刊宝中共性外刊时班级间内容才能选值
  13964. }
  13965. $topicNumberJson=json_encode($topicNumber);
  13966. }elseif($productType==3){//热点宝
  13967. if(!in_array($type,array(1,2))){
  13968. $error[] = '请选择外刊类型';
  13969. }
  13970. if($type==2 && !in_array($level,array(1,2,3))){
  13971. $error[] = '外刊类型是共性外刊时请选择正确的外刊分级';
  13972. }
  13973. if(!$hotTopic){
  13974. $error[] = '请选择热点选题';
  13975. }
  13976. unset($topicNumber['periodicals']);
  13977. if(!$topicNumber || !isset($topicNumber['hot']) || count($topicNumber)!=1){
  13978. $error[] = '缺少题目数量';
  13979. }else{
  13980. $error=array_merge($error,$this->validateTopicNumber($topicNumber));
  13981. }
  13982. //不需要的值,设为0或者空
  13983. $basicTopic=0;
  13984. if($type==1){
  13985. $level=0;
  13986. $classBetweenContent=0;//热点宝中共性外刊时班级间内容才能选值
  13987. }
  13988. $topicNumberJson=json_encode($topicNumber);
  13989. }
  13990. }elseif($recommendMode==2){//智能推荐模式
  13991. if(!$basicTopic){
  13992. $error[] = '请选择基础选题';
  13993. }
  13994. if(!$hotTopic){
  13995. $error[] = '请选择热点选题';
  13996. }
  13997. if(!$topicNumber){
  13998. $error[] = '缺少题目数量';
  13999. }else{
  14000. if(!isset($topicNumber['periodicals']) || !isset($topicNumber['hot'])){
  14001. $error[] = '检查题目数量';
  14002. }else{
  14003. $error=array_merge($error,$this->validateTopicNumber($topicNumber));
  14004. }
  14005. }
  14006. $type=1;//默认个性外刊
  14007. $level=0;$productType=0;$classBetweenContent=0;
  14008. $topicNumberJson=json_encode($topicNumber);
  14009. }
  14010. }
  14011. if(!$error){
  14012. $time = time();
  14013. $date_msg = $this->getWeekOnMonth();
  14014. $year = $date_msg["year"];
  14015. $month = $date_msg["month"];
  14016. $week = $date_msg["week"];
  14017. $weekUpper = numToUpper($week);
  14018. $strModel = new SStudentClassRelation();
  14019. $transaction = $this->sConn->beginTransaction();
  14020. try{
  14021. $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"'.$weekNameExt.'"';
  14022. $reading_id = getUniqueId($this->schoolId);
  14023. $this->sConn->createCommand()->insert('english_reading_setting',array(
  14024. 'reading_id'=>$reading_id,
  14025. 'grade' => $grade,
  14026. 'semester_id' => $this->semesterId,
  14027. 'textbook_id' => $textbookId,
  14028. 'module_id' => $moduleId,
  14029. 'unit_id' => $unitId,
  14030. 'special_ids' => implode(',',$itemIds),
  14031. 'create_time' => $time,
  14032. 'type' => $type,
  14033. 'level'=>$level,
  14034. 'is_answer_separate'=>$isAnswerSeparate,
  14035. 'recommend_mode'=>$recommendMode,
  14036. 'product_type'=>$productType,
  14037. 'basic_topic'=>$basicTopic,
  14038. 'hot_topic'=>$hotTopic,
  14039. 'topic_number_json'=>$topicNumberJson,
  14040. 'class_between_content'=>$classBetweenContent,
  14041. 'category'=>$category
  14042. ));
  14043. $weekIdArr=array();
  14044. foreach($classIds as $k=>$v){
  14045. $weekId = getUniqueId($this->schoolId);
  14046. $weekIdArr[]=$weekId;
  14047. $this->sConn->createCommand()->insert('english_reading',array(
  14048. 'week_id' => $weekId,
  14049. 'name' => $weekName,
  14050. 'class_id' => $v,
  14051. 'grade' => $grade,
  14052. 'semester_id' => $this->semesterId,
  14053. 'year_num' => $year,
  14054. 'week_num' => $week,
  14055. 'month_num' => $month,
  14056. 'reading_id'=>$reading_id,
  14057. 'create_time' => $time,
  14058. 'is_new_version'=>$isNewVersion,
  14059. ));
  14060. //获取班级学生
  14061. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  14062. $studentInfo=array();
  14063. if($stuData && (($recommendMode==1 && in_array($productType,array(2,3)) && $type==1) || ($recommendMode==2)) ){
  14064. $sql = "SELECT si.student_id,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id={$v} and si.reading_level>0 and scr.status=0";
  14065. $studentInfo = $this->sConn->createCommand($sql)->queryAll();
  14066. $studentInfo=$this->_array_column($studentInfo,'reading_level','student_id');
  14067. }
  14068. //智能模式
  14069. if($recommendMode==2 && $stuData){
  14070. foreach($stuData as $kk=>$vv){
  14071. $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2;
  14072. $this->sConn->createCommand()->insert('english_reading_student',array(
  14073. 'week_id' => $weekId,
  14074. 'student_id' => $vv['student_id'],
  14075. 'product_type'=>$readingLevel,//智能模式下档次和产品类型数值一样
  14076. 'reading_level'=>$readingLevel,
  14077. ));
  14078. }
  14079. }else if($recommendMode==1 && $stuData){//推荐模式
  14080. foreach($stuData as $kk=>$vv){
  14081. $readingLevel=0;
  14082. //2-外刊宝 3-热点宝 下个性外刊
  14083. if(in_array($productType,array(2,3)) && $type==1){
  14084. $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2;
  14085. }
  14086. $this->sConn->createCommand()->insert('english_reading_student',array(
  14087. 'week_id' => $weekId,
  14088. 'student_id' => $vv['student_id'],
  14089. 'product_type'=>$productType,
  14090. 'reading_level'=>$readingLevel,
  14091. ));
  14092. }
  14093. }
  14094. }
  14095. $transaction->commit();
  14096. }catch(Exception $e){
  14097. $transaction->rollBack();
  14098. if (YII_ENV == 'production') {
  14099. $error[] = '系统错误[SQL]';
  14100. } else {
  14101. $error[] = $e->getMessage();
  14102. }
  14103. }
  14104. }
  14105. if($error){
  14106. exit(json_encode(array('status'=>0,'msg'=>$error)));
  14107. }else{
  14108. $kafkaData=array(
  14109. 'school_id'=>$this->schoolId,
  14110. 'msg_type'=>1,//90:重置 1:新设置
  14111. 'grade'=>$grade,
  14112. 'subject_id'=>8,
  14113. 'send_type'=>'english_reading',
  14114. 'product_type'=>array($classify),
  14115. 'gp_group_id'=>$reading_id,//reading_id
  14116. 'gp_ids'=>array_unique($weekIdArr),//week_Id
  14117. );
  14118. sendDataToKafka("php-product-english-reading-html",$kafkaData);
  14119. exit(json_encode(array('status'=>1)));
  14120. }
  14121. }
  14122. /**
  14123. * 校验题目数量设置
  14124. * 外刊宝:外刊阅读,题数默认4(数量范围为0-7);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为2-7
  14125. * 热点宝:外刊阅读,题数默认3(数量范围为0-6);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为1-6
  14126. * @param $topicNumberConfig
  14127. * @return array
  14128. */
  14129. private function validateTopicNumber($topicNumberConfig){
  14130. $error=array();
  14131. if(isset($topicNumberConfig['periodicals'])){
  14132. $periodicals=$topicNumberConfig['periodicals'];
  14133. if(!isset($periodicals['reading']) || !isset($periodicals['gestalt']) || !isset($periodicals['seven_selected_five'])){
  14134. $error[]='外刊宝题目数量参数有误';
  14135. }else{
  14136. $reading=intval($periodicals['reading']);
  14137. $gestalt=intval($periodicals['gestalt']);
  14138. $sevenSelectedFive=intval($periodicals['seven_selected_five']);
  14139. if(!($reading>=0 && $reading<=7)){
  14140. $error[]='外刊宝外刊阅读数量设置有误:数量范围为0-7';
  14141. }
  14142. if(!($gestalt>=0 && $gestalt<=7)){
  14143. $error[]='外刊宝外刊完形(新高考)数量设置有误:数量范围为0-2';
  14144. }
  14145. if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){
  14146. $error[]='外刊宝外刊七选五数量设置有误:数量范围为0-2';
  14147. }
  14148. $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive;
  14149. if(!($periodicalsTotal>=2 && $periodicalsTotal<=7)){
  14150. $error[]='外刊宝题数总和题数范围为2-7';
  14151. }
  14152. }
  14153. }
  14154. if(isset($topicNumberConfig['hot'])){
  14155. $hot=$topicNumberConfig['hot'];
  14156. if(!isset($hot['reading']) || !isset($hot['gestalt']) || !isset($hot['seven_selected_five'])){
  14157. $error[]='热点宝题目数量参数有误';
  14158. }else{
  14159. $reading=intval($hot['reading']);
  14160. $gestalt=intval($hot['gestalt']);
  14161. $sevenSelectedFive=intval($hot['seven_selected_five']);
  14162. if(!($reading>=0 && $reading<=7)){
  14163. $error[]='热点宝外刊阅读数量设置有误:数量范围为0-6';
  14164. }
  14165. if(!($gestalt>=0 && $gestalt<=7)){
  14166. $error[]='热点宝外刊完形(新高考)数量设置有误:数量范围为0-2';
  14167. }
  14168. if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){
  14169. $error[]='热点宝外刊七选五数量设置有误:数量范围为0-2';
  14170. }
  14171. $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive;
  14172. if(!($periodicalsTotal>=1 && $periodicalsTotal<=6)){
  14173. $error[]='热点宝题数总和题数范围为1-6';
  14174. }
  14175. }
  14176. }
  14177. return $error;
  14178. }
  14179. /**
  14180. * 外刊阅读学生设置数据初始化
  14181. */
  14182. public function actionAjaxEnglishReadingSetInit(){
  14183. $req=Req::input();
  14184. $grade=isset($req['grade'])?(int)$req['grade']:0;
  14185. if(!$grade){
  14186. exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
  14187. }
  14188. $class=$this->getClassesBySettingReading($grade);
  14189. $data=array('class_students'=>array(), 'reading_level_students'=>array());
  14190. if(!$class){
  14191. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  14192. }
  14193. $class=$this->_array_column($class,'class_name','class_id');
  14194. $classIdsStr=implode(',',array_keys($class));
  14195. $students=$classStudentInfo=$studentType=$classLevelStudent=array();
  14196. if($classIdsStr){
  14197. $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and scr.status=0 order by scr.class_id asc";
  14198. $students = $this->sConn->createCommand($sql)->queryAll();
  14199. }
  14200. $readingLevel=array(1,2,3);
  14201. foreach($students as $item){
  14202. $isSet=false;
  14203. $sutdentItem=array('student_id' => $item['student_id'], 'realname' => $item['realname'],'class_id'=>$item['class_id']);
  14204. if($item['reading_level']){
  14205. $isSet=true;
  14206. $studentType[$item['reading_level']][] = $sutdentItem;//层次学生数据比班级学生数据少一个是否已设置分层标记
  14207. $classLevelStudent[$item['class_id']][$item['reading_level']][]=$sutdentItem;
  14208. }
  14209. $sutdentItem['is_set']=$isSet;
  14210. $sutdentItem['reading_level']=$item['reading_level'];
  14211. $classStudentInfo[$item['class_id']][]=$sutdentItem;
  14212. }
  14213. $classLevelStudentResult=array();
  14214. foreach($classLevelStudent as $classId=>&$itemLevelStudent){
  14215. $classLevelStudentItem=array();
  14216. foreach($readingLevel as $level){
  14217. $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array();
  14218. $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent);
  14219. }
  14220. $classLevelStudentResult[$classId]=$classLevelStudentItem;
  14221. }
  14222. $classStudent=$readingLevelStudent=$levelStudentDefault=array();
  14223. foreach($readingLevel as $level){
  14224. $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array());//默认结构
  14225. }
  14226. foreach($class as $classId=>$className){
  14227. $singleClassStudents=isset($classStudentInfo[$classId])?$classStudentInfo[$classId]:array();//单个班级学生数据
  14228. $singleClassLevelStudent=isset($classLevelStudentResult[$classId])?$classLevelStudentResult[$classId]:$levelStudentDefault;//单个班级分档次学生数据
  14229. $classStudent[]=array('class_id'=>$classId,'class_name'=>$className,'students'=>$singleClassStudents,'reading_level_students'=>$singleClassLevelStudent);
  14230. }
  14231. unset($students); unset($classStudentInfo);unset($classLevelStudentResult);unset($singleClassStudents);unset($singleClassLevelStudent);
  14232. foreach($readingLevel as $level){
  14233. $readingLevelStudent[]=array(
  14234. 'reading_level'=>$level,
  14235. 'students'=>isset($studentType[$level])?$studentType[$level]:array(),
  14236. );
  14237. }
  14238. $data=array(
  14239. 'class_students'=>$classStudent,//班级学生
  14240. 'reading_level_students'=>$readingLevelStudent,//分层学生
  14241. );
  14242. unset($classStudent);unset($readingLevelStudent);unset($studentType);
  14243. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  14244. }
  14245. private function getInWhereStr($data=array()){
  14246. $str='';
  14247. foreach($data as $item){
  14248. $str.="'".$item."',";
  14249. }
  14250. $str=trim($str,',');
  14251. return $str;
  14252. }
  14253. /**
  14254. * 英语外刊学生设置保存学生层次
  14255. */
  14256. public function actionAjaxEnglishReadingStudentSettingSave(){
  14257. $req=Req::input();
  14258. $studentsProductType=isset($req['students_product_type'])?$req['students_product_type']:array();
  14259. if(!$studentsProductType || !is_array($studentsProductType)){
  14260. exit(json_encode(array('status'=>0,'msg'=>'请检查参数')));
  14261. }
  14262. $studentsProductTypeData=array();
  14263. foreach($studentsProductType as $kye=>$item){
  14264. if(!isset($item['reading_level']) || !in_array($item['reading_level'],array(0,1,2,3)) || !isset($item['students']) || !is_array($item['students'])){
  14265. exit(json_encode(array('status'=>0,'msg'=>'请检查参数里的数据')));
  14266. }
  14267. if( !$item['students']){
  14268. unset($studentsProductType[$kye]);
  14269. continue;
  14270. }
  14271. $studentsProductTypeData[$item['reading_level']]=$item['students'];
  14272. }
  14273. unset($studentsProductType);
  14274. ksort($studentsProductTypeData);
  14275. $error=array();
  14276. $transaction = $this->sConn->beginTransaction();
  14277. try{
  14278. foreach($studentsProductTypeData as $readingLevel=>$students){
  14279. $readingLevel=(int)$readingLevel;
  14280. if($students) {
  14281. $studentIdsStr = implode(',', $students);
  14282. $sql = "update student_info set reading_level={$readingLevel} where student_id in ({$studentIdsStr})";
  14283. $this->sConn->createCommand($sql)->execute();
  14284. }
  14285. }
  14286. $transaction->commit();
  14287. }catch(Exception $e){
  14288. $transaction->rollBack();
  14289. if (YII_ENV == 'production') {
  14290. $error[] = '系统错误[SQL]';
  14291. } else {
  14292. $error[] = $e->getMessage();
  14293. }
  14294. }
  14295. if($error){
  14296. exit(json_encode(array('status'=>0,'msg'=>$error)));
  14297. }else{
  14298. exit(json_encode(array('status'=>1)));
  14299. }
  14300. }
  14301. /**
  14302. * 英语外刊阅读学生数据导入
  14303. * @throws CException
  14304. */
  14305. public function actionEnglishReadingStudentImport()
  14306. {
  14307. ini_set('memory_limit', '300M');
  14308. if (Yii::app()->request->getIsPostRequest()) {
  14309. $grade=(int)Req::post('grade');
  14310. if(!$grade){
  14311. exit(json_encode(array('status'=>0,'msg'=>'缺少年级参数')));
  14312. }
  14313. $uploader = new Uploader("upload/tmpDir/UploadEnglisthReadingStudentsList/{$this->schoolId}/");
  14314. $uploader->allowTypes = array("xls","xlsx");
  14315. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  14316. $file = $uploader->act();
  14317. $file = Arr::current(Arr::current($file));
  14318. if (!$file || !isset($file["error"]))
  14319. exit(json_encode(array('status'=>0,'msg'=>'请选择上传的Excel!')));
  14320. if ($file["error"] != 0) {
  14321. switch ($file["error"]) {
  14322. case 2001:
  14323. exit(json_encode(array('status'=>0,'msg'=>'文件类型不符')));
  14324. break;
  14325. case 2002:
  14326. exit(json_encode(array('status'=>0,'msg'=>'文件大小超出允许范围')));
  14327. break;
  14328. default:
  14329. exit(json_encode(array('status'=>0,'msg'=>'上传失败')));
  14330. break;
  14331. }
  14332. }
  14333. $inputFileName = $file["src"];
  14334. if (Yii::app()->params['handle_log_on_off']) {
  14335. writeFileLog(jsonEncode(array(
  14336. "exam_group_id" => 0,
  14337. "operate_project" => 'zsyas2',
  14338. "school_id" => $this->schoolId,
  14339. "title" => '导入学生',
  14340. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  14341. "operate_method" => $this->action,
  14342. "operate_url" => $this->getRoute(),
  14343. "operate_sql" => '',
  14344. "operate_param" => json_encode(array('post' => $_POST, 'get' => $_GET, 'file' => $inputFileName)),
  14345. "date" => date('Y-m-d H:i:s')
  14346. )));
  14347. }
  14348. Yii::import('application.extensions.*');
  14349. require_once('phpexcel/PHPExcel/IOFactory.php');
  14350. // 读取Excel文档
  14351. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  14352. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  14353. @unlink($file["src"]);
  14354. // 去掉导航
  14355. //dump($sheetData);die;
  14356. unset($sheetData[1]);
  14357. krsort($sheetData);
  14358. $excelTotal=count($sheetData);
  14359. $studentScoreInfo = array();
  14360. foreach ($sheetData as $key => $val) {
  14361. if (empty($val['A']) || empty($val['B']) || !isset($val['C']) || !is_numeric($val['C']) || empty($val['D']) || !is_numeric($val['D']) || (int)$val['D']<=0) {
  14362. continue;
  14363. }
  14364. if (count($val) != 4) {
  14365. continue;
  14366. }
  14367. $studentScoreInfo[] = array(
  14368. 'realname' => $val['A'],
  14369. 'class_name' => $val['B'],
  14370. 'score' => (int)$val['C'],
  14371. 'total_score' => (int)$val['D'],
  14372. );
  14373. }
  14374. if(!$studentScoreInfo){
  14375. exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误。')));
  14376. }
  14377. $classNames=_array_column($studentScoreInfo,'class_name','class_name');
  14378. $classNamesStr=$this->getInWhereStr($classNames);
  14379. // $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and class_type=1 and is_hide=0 and grade={$grade} group by class_name having count(*)=1";
  14380. $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and is_hide=0 and grade={$grade} group by class_name having count(*)=1";
  14381. $classInfo= $this->sConn->createCommand($sql)->queryAll();
  14382. if(!$classInfo){
  14383. exit(json_encode(array('status'=>3,'data'=>array(),'msg'=>'没有有效年级数据')));
  14384. }
  14385. $classInfo=$this->_array_column($classInfo,'class_id','class_name');;
  14386. $classIds=implode(',',$classInfo);
  14387. $sql="SELECT scr.class_id,si.student_id,si.realname FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIds}) and scr.status=0 group by scr.class_id,si.realname having count(*)>1";
  14388. $repeatStudents= $this->sConn->createCommand($sql)->queryAll();
  14389. //重复学生
  14390. $repeatStudentsData=$classStudentInfo=array();
  14391. foreach($repeatStudents as $item){
  14392. $repeatStudentsData[$item['class_id'].$item['realname']]='';
  14393. }
  14394. //过滤信息 剔除查询不到班级和 姓名重复的学生
  14395. foreach($studentScoreInfo as $key=>&$item){
  14396. if(isset($classInfo[$item['class_name']])){
  14397. $classId=$classInfo[$item['class_name']];
  14398. //表里姓名重复的学生
  14399. if(isset($repeatStudentsData[$classId][$item['realname']])){
  14400. unset($studentScoreInfo[$key]);
  14401. continue;
  14402. }
  14403. //excel里重复的和不符合条件的学生数据
  14404. if(isset($classStudentInfo[$classId][$item['realname']]) || !intval($item['score']) || intval($item['total_score'])<=0 || intval($item['score'])>intval($item['total_score'])){
  14405. unset($classStudentInfo[$classId][$item['realname']]);
  14406. unset($studentScoreInfo[$key]);
  14407. continue;
  14408. }
  14409. $rate=round(intval($item['score'])/intval($item['total_score']),4)*100;
  14410. $level=2;
  14411. if($rate<=60){
  14412. $level=1;
  14413. }elseif($rate>60 && $rate<=80){
  14414. $level=2;
  14415. }elseif($rate>80){
  14416. $level=3;
  14417. }
  14418. $classStudentInfo[$classId][$item['realname']]=$level;
  14419. }else{
  14420. //不存在班级的学生
  14421. unset($studentScoreInfo[$key]);
  14422. }
  14423. }
  14424. unset($repeatStudentsData);unset($repeatStudents);
  14425. if(!$classStudentInfo){
  14426. exit(json_encode(array('status'=>1,'data'=>array())));
  14427. }
  14428. $sqlWhere='';
  14429. foreach($classStudentInfo as $classId=>$itemStudent){
  14430. $realnames=array_keys($itemStudent);
  14431. if(!$realnames){
  14432. continue;
  14433. }
  14434. $realnameStr=$this->getInWhereStr($realnames);
  14435. $sqlWhere.=" (scr.class_id={$classId} and si.realname in ({$realnameStr}) ) or";
  14436. }
  14437. if(!$sqlWhere){
  14438. exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误!')));
  14439. }
  14440. $sqlWhere=trim($sqlWhere,'or');
  14441. $sql="select si.student_id,si.realname,scr.class_id from student_info si inner join student_class_relation scr on si.student_id=scr.student_id where {$sqlWhere} order by scr.class_id ";
  14442. $students= $this->sConn->createCommand($sql)->queryAll();
  14443. //有效的学生数
  14444. $studentTotal=count($students);
  14445. //有效的班级学生数据
  14446. $classStudentData=array();
  14447. foreach($students as $item){
  14448. $classStudentData[$item['class_id']][$item['realname']]=$item['student_id'];
  14449. }
  14450. $productTypeStudents=$classStudents=$classLevelStudent=array();
  14451. foreach($classStudentInfo as $classId=>$itemStudent){
  14452. foreach($itemStudent as $realname=>$level){
  14453. if(!isset($classStudentData[$classId][$realname])){
  14454. continue;
  14455. }
  14456. $studentId=$classStudentData[$classId][$realname];
  14457. $studentInfo=array('student_id'=>$studentId,'realname'=>$realname,'class_id'=>$classId);
  14458. $productTypeStudents[$level][]=$studentInfo;
  14459. $classLevelStudent[$classId][$level][]=$studentInfo;
  14460. $studentInfo['is_set']=true;
  14461. $studentInfo['reading_level']=$level;
  14462. $classStudents[$classId][]=$studentInfo;//班级学生数据多是否设置和档次字段
  14463. }
  14464. }
  14465. $readingLevel=array(1,2,3);
  14466. $productTypeStudentsResult=$classStudentsResult=$classLevelStudentResult=array();
  14467. //班级学生数据中的档次数据
  14468. foreach($classLevelStudent as $classId=>&$itemLevelStudent){
  14469. $classLevelStudentItem=array();
  14470. foreach($readingLevel as $level){
  14471. $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array();
  14472. $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent);
  14473. }
  14474. $classLevelStudentResult[$classId]=$classLevelStudentItem;
  14475. }
  14476. unset($students);unset($classStudentInfo);unset($classStudentData);unset($classLevelStudent);
  14477. //档次学生数据
  14478. foreach($readingLevel as $itemLevel){
  14479. $studentArr=isset($productTypeStudents[$itemLevel])?$productTypeStudents[$itemLevel]:array();
  14480. $productTypeStudentsResult[]=array(
  14481. 'reading_level'=>$itemLevel,
  14482. 'students'=>$studentArr,
  14483. );
  14484. }
  14485. //默认结构
  14486. $levelStudentDefault=array();
  14487. foreach($readingLevel as $level){
  14488. $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array());
  14489. }
  14490. //班级学生信息
  14491. foreach($classInfo as $itemClassName =>$itemClassId){
  14492. $studentArr=isset($classStudents[$itemClassId])?$classStudents[$itemClassId]:array();
  14493. $classLevelStudentArr=isset($classLevelStudentResult[$itemClassId])?$classLevelStudentResult[$itemClassId]:$levelStudentDefault;
  14494. $classStudentsResult[]=array('class_id'=>$itemClassId,'class_name'=>$itemClassName,'students'=>$studentArr,'reading_level_students'=>$classLevelStudentArr);
  14495. }
  14496. $data=array(
  14497. 'class_students'=>$classStudentsResult,
  14498. 'reading_level_students'=>$productTypeStudentsResult,
  14499. 'excel_total'=>$excelTotal,
  14500. 'student_total'=>$studentTotal,
  14501. );
  14502. unset($productTypeStudents);unset($classStudents);unset($classLevelStudentResult);unset($productTypeStudentsResult);unset($classStudentsResult);unset($studentArr);unset($classLevelStudentArr);
  14503. exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
  14504. }
  14505. }
  14506. /**
  14507. * 新版英语外刊教师版
  14508. */
  14509. public function new_en_reading($weekId='',$week_info=array()){
  14510. $sql = "select product_type,basic_topic,hot_topic from english_reading_setting where reading_id='{$week_info['reading_id']}'";
  14511. $week_setting = $this->sConn->createCommand($sql)->queryRow();
  14512. $data = array();
  14513. $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
  14514. $class_name = '';
  14515. $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
  14516. $class_id = $week_info['class_id'];
  14517. $sql = "select class_id,class_name from class where class_id = '$class_id'";
  14518. $class_data = $this->sConn->createCommand($sql)->queryRow();
  14519. if($class_data){
  14520. $class_name = $class_data['class_name'];
  14521. }
  14522. if($week_setting){
  14523. if($week_setting['product_type'] == 1){//基础宝
  14524. $p_name="外刊-基础宝";
  14525. $html_name = 'en_jichu';
  14526. $basic_data = array();
  14527. $basic_topic = $week_setting['basic_topic'];//基础宝ID
  14528. if($basic_topic){
  14529. $basic_topic_arr = explode(",",$basic_topic);
  14530. $brain_data = $this->apiBrainPost('/all_library/englishBaseBaby', array('ids' => $basic_topic_arr), 25, true);
  14531. if($brain_data && isset($brain_data['data']) && $brain_data['data']){
  14532. foreach($brain_data['data'] as $k=>$v){
  14533. if(isset($v['jsb']) && $v['jsb']){
  14534. $basic_data = json_decode($v['jsb'],true);
  14535. }
  14536. }
  14537. }else{
  14538. Yii::app()->jump->error('基础宝教师版接口有误');
  14539. }
  14540. }else{
  14541. Yii::app()->jump->error('基础宝ID设置有误');
  14542. }
  14543. if(!$basic_data){
  14544. Yii::app()->jump->error('基础宝教师版没有数据');
  14545. }else{
  14546. $data['basic_data'] = $basic_data;
  14547. }
  14548. }else if($week_setting['product_type'] == 2){//外刊宝
  14549. $p_name="外刊-外刊宝";
  14550. $html_name = 'en_waikan';
  14551. $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'";
  14552. $topic_data = $this->sConn->createCommand($sql)->queryAll();
  14553. if($topic_data){
  14554. $topic_ids = _array_column($topic_data, 'topic_id');
  14555. $topic_ids = array_unique($topic_ids);
  14556. $data['topic_ids'] = $topic_ids;
  14557. $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true);
  14558. if (!$topicDetails) {
  14559. Yii::app()->jump->error('获取接口batchALL无数据!');
  14560. } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
  14561. Yii::app()->jump->error($topicDetails['error'][0]);
  14562. } else {
  14563. $paper_topic_detail= array();
  14564. foreach($topicDetails as $k=>$v){
  14565. $paper_topic_detail[(string)$v['id']] = $v;
  14566. }
  14567. $new_topic_detail = $this->newTopicDetail($paper_topic_detail);
  14568. $data['topic_detail'] = $new_topic_detail;
  14569. }
  14570. }else{
  14571. Yii::app()->jump->error('学生外刊没生成');
  14572. }
  14573. }else{//热点宝
  14574. $p_name="外刊-热点宝";
  14575. $html_name = 'en_hot';
  14576. $hot_topic = $week_setting['hot_topic'];//热点宝ID
  14577. $redian_topic_ids = array();
  14578. if($hot_topic){
  14579. $hot_topic_arr = explode(",",$hot_topic);
  14580. $brain_data = $this->apiBrainPost('/all_library/englishHotBaby', array('ids' => $hot_topic_arr), 25, true);
  14581. if($brain_data && isset($brain_data['data']) && $brain_data['data']){
  14582. foreach($brain_data['data'] as $k=>$v){
  14583. if(isset($v['xxtlsy']) && $v['xxtlsy']){
  14584. $redian_topic_ids = array_merge($redian_topic_ids,$v['xxtlsy']);
  14585. }
  14586. if(isset($v['ljfxsy']) && $v['ljfxsy']){
  14587. $redian_topic_ids = array_merge($redian_topic_ids,$v['ljfxsy']);
  14588. }
  14589. if(isset($v['sbsy']) && $v['sbsy']){
  14590. $redian_topic_ids = array_merge($redian_topic_ids,$v['sbsy']);
  14591. }
  14592. if(isset($v['yychhy']) && $v['yychhy']){
  14593. $redian_topic_ids = array_merge($redian_topic_ids,$v['yychhy']);
  14594. }
  14595. if(isset($v['yyjjfx']) && $v['yyjjfx']){
  14596. $redian_topic_ids = array_merge($redian_topic_ids,$v['yyjjfx']);
  14597. }
  14598. if(isset($v['zhyysy']) && $v['zhyysy']){
  14599. $redian_topic_ids = array_merge($redian_topic_ids,$v['zhyysy']);
  14600. }
  14601. }
  14602. $data['hot_data'] = $brain_data['data'][0];
  14603. }else{
  14604. Yii::app()->jump->error('热点宝教师版接口有误');
  14605. }
  14606. }else{
  14607. Yii::app()->jump->error('热点宝ID设置有误');
  14608. }
  14609. $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'";
  14610. $topic_data = $this->sConn->createCommand($sql)->queryAll();
  14611. if($topic_data){
  14612. $topic_ids_0 = _array_column($topic_data, 'topic_id');
  14613. $topic_ids_0 = array_unique($topic_ids_0);
  14614. $topic_ids = array_merge($topic_ids_0,$redian_topic_ids);
  14615. $data['topic_ids'] = $topic_ids_0;
  14616. $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true);
  14617. if (!$topicDetails) {
  14618. Yii::app()->jump->error('获取接口batchALL无数据!');
  14619. } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
  14620. Yii::app()->jump->error($topicDetails['error'][0]);
  14621. } else {
  14622. $paper_topic_detail= array();
  14623. foreach($topicDetails as $k=>$v){
  14624. $paper_topic_detail[(string)$v['id']] = $v;
  14625. }
  14626. $new_topic_detail = $this->newTopicDetail($paper_topic_detail);
  14627. $data['topic_detail'] = $new_topic_detail;
  14628. }
  14629. }else{
  14630. Yii::app()->jump->error('学生外刊没生成');
  14631. }
  14632. }
  14633. //开始生成html
  14634. $data['type_config'] =array('gestalt'=>713,'reading'=>714,'seven_selected_five'=>array(715,432));
  14635. $html = $this->renderPartial("{$html_name}", $data,true);
  14636. unset($data);
  14637. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
  14638. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
  14639. $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
  14640. if (!is_dir($htmlpath)) {
  14641. if (!mkdir($htmlpath, 0777, true)) {
  14642. Yii::app()->jump->error('Create directory fail: ' . $htmlpath);
  14643. }
  14644. }
  14645. if (!is_dir($pdfpath)) {
  14646. if (!mkdir($pdfpath, 0777, true)) {
  14647. Yii::app()->jump->error('Create directory fail: ' . $pdfpath);
  14648. }
  14649. }
  14650. $htmlpath .= $weekId . ".html";
  14651. $f = fopen($htmlpath, "w");
  14652. fwrite($f, $html);
  14653. fclose($f);
  14654. $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
  14655. //防止exec 执行命令行导致中文乱码
  14656. $locale='en_US.UTF-8';
  14657. setlocale(LC_ALL,$locale);
  14658. putenv('LC_ALL='.$locale);
  14659. if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
  14660. $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html';
  14661. $pdffname = $weekId . ".pdf";
  14662. $pdfpath = $pdfpath . $pdffname;
  14663. $pdfurl = $pdfurl . $pdffname;
  14664. $commond = Yii::app()->params['phantomjs'] . " "
  14665. . Yii::app()->params['html2pdf'] . " "
  14666. . " {$htmlurl}"
  14667. . " {$pdfpath}"
  14668. . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'";
  14669. } else {
  14670. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  14671. $pdffname = $weekId . ".pdf";
  14672. $pdfpath = $pdfpath . $pdffname;
  14673. $pdfurl = $pdfurl . $pdffname;
  14674. $commond = Yii::app()->params['phantomjs_server_en'] . " "
  14675. . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
  14676. . " {$htmlurl}"
  14677. . " {$pdfpath}"
  14678. . ' 176mm*250mm "'.$class_name.'|||'.'时间:'.date('Y-m-d',time()).' '.$p_name.'"';
  14679. }
  14680. exec($commond, $res, $code);
  14681. if(isset($res[0])){
  14682. $isBool = false;
  14683. foreach ($res as $msg) {
  14684. if (strpos($msg, 'succeed') !== false) {
  14685. $isBool = true;
  14686. }
  14687. }
  14688. if ($isBool) {//命令返回成功
  14689. if (file_exists($pdfpath)) {
  14690. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  14691. $repdf = $weekId . ".pdf";
  14692. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  14693. $ucloud = new HuaweiCloud();
  14694. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  14695. //上传html
  14696. $rehtml = $weekId.".html";
  14697. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
  14698. $uploadHtmlInfo = $ucloud->putFile($rename, $htmlpath);
  14699. if($uploadHtmlInfo['status'] == 0){
  14700. $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl;
  14701. }else{
  14702. $html_url = $uploadHtmlInfo['url'];
  14703. }
  14704. if ($uploadInfo['status'] == 0) {
  14705. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  14706. $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'");
  14707. $week_info['teacher_general_pdf_path'] = $pdfurl;
  14708. }else{
  14709. $pdfurl = $uploadInfo['url'];
  14710. $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'");
  14711. $week_info['teacher_general_pdf_path'] = $pdfurl;
  14712. @unlink($pdfpath);
  14713. }
  14714. @unlink($htmlpath);
  14715. } else {
  14716. @unlink($htmlpath);
  14717. Yii::app()->jump->error('PDF文件未找到!');
  14718. }
  14719. } else {
  14720. @unlink($htmlpath);
  14721. Yii::app()->jump->error('PDF创建失败!');
  14722. }
  14723. } else {
  14724. Yii::app()->jump->error('PDF创建失败11!');
  14725. }
  14726. }else{
  14727. Yii::app()->jump->error('外刊宝设置信息有误');
  14728. }
  14729. if($week_info['teacher_general_pdf_path']){
  14730. $url = $week_info['teacher_general_pdf_path'];
  14731. header('Content-Description: File Transfer');
  14732. header('Content-Type: application/vnd.android.package-archive');
  14733. header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf");
  14734. header('Content-Transfer-Encoding: binary');
  14735. header('Expires: 0');
  14736. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  14737. header('Pragma: public');
  14738. $ch = curl_init();
  14739. curl_setopt($ch, CURLOPT_URL, $url);
  14740. curl_setopt($ch, CURLOPT_HEADER, 0);
  14741. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14742. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  14743. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  14744. echo $buffer;
  14745. return strlen($buffer);
  14746. });
  14747. curl_exec($ch);
  14748. curl_close($ch);
  14749. }else{
  14750. Yii::app()->jump->error('尚未生成PDF');
  14751. }
  14752. }
  14753. /**
  14754. * 整理试题详情数据
  14755. */
  14756. public function newTopicDetail($paper_topic_detail){
  14757. $result = array();
  14758. $answer = array('A','B','C','D','E','F','G','H','I','J','K');
  14759. foreach($paper_topic_detail as $k=>$v){
  14760. $result[$k]['title'] = $v['title'];
  14761. $result[$k]['type_id'] = $v['type_id'];
  14762. $result[$k]['parse_content'] = $v['parse_content'];
  14763. $result[$k]['answer'] = array();
  14764. $slave_answer = array();
  14765. if(isset($v['slave']) && $v['slave']){
  14766. $slave_arr = array();
  14767. foreach($v['slave'] as $sla_k=>$sla_v){
  14768. $slave_arr[$sla_k]['title'] = $sla_v['title'];//小题题干
  14769. if(isset($sla_v['items']) && $sla_v['items']){
  14770. if(isset($sla_v['items']['options']) && $sla_v['items']['options']){
  14771. foreach($sla_v['items']['options'] as $op_k=>$op_v){
  14772. $slave_arr[$sla_k]['options'][$op_k] = $op_v['option_content'];
  14773. if($op_v['option_correct']){
  14774. $slave_answer[] = $answer[$op_k];
  14775. }
  14776. }
  14777. }
  14778. }
  14779. }
  14780. $result[$k]['slave'] = $slave_arr;
  14781. $result[$k]['answer'] = $slave_answer;
  14782. }else{
  14783. if(isset($v['items']) && $v['items'] && isset($v['items'][0]) && $v['items'][0]){
  14784. if(isset($v['items'][0]['options']) && $v['items'][0]['options']){
  14785. foreach($v['items'][0]['options'] as $op_k=>$op_v){
  14786. if($op_v['option_correct'] == 1){
  14787. $slave_answer[] = $op_v['option_content'];
  14788. }
  14789. }
  14790. }
  14791. }
  14792. $result[$k]['answer'] = $slave_answer;
  14793. }
  14794. if(isset($v['affiliate']) && $v['affiliate']){
  14795. foreach($v['affiliate'] as $aff_k=>$aff_v){
  14796. if($aff_v['field_name'] == '体裁类型'){
  14797. $result[$k]['tc'] = $this->getTags($aff_v['field_key'],$aff_v['field_value']);
  14798. }
  14799. if($aff_v['field_name'] == '主题语境'){
  14800. //主题语境只显示一个
  14801. $ztyj_str = $this->getTags($aff_v['field_key'],$aff_v['field_value']);
  14802. $ztyj_arr = explode(",",$ztyj_str);
  14803. if($ztyj_arr){
  14804. $result[$k]['ztyj'] = $ztyj_arr[0];
  14805. }else{
  14806. $result[$k]['ztyj'] ='';
  14807. }
  14808. }
  14809. if($aff_v['field_name'] == '语篇等级'){
  14810. $result[$k]['ypdj'] = $aff_v['field_value'];
  14811. }
  14812. if($aff_v['field_name'] == '句子剖析'){
  14813. $result[$k]['jzpx'] = $aff_v['field_value'];
  14814. }
  14815. if($aff_v['field_name'] == '词汇积累'){
  14816. $result[$k]['chjl'] = $aff_v['field_value'];
  14817. }
  14818. if($aff_v['field_name'] == '关键词拓展'){
  14819. $result[$k]['gjctz'] = $aff_v['field_value'];
  14820. }
  14821. if($aff_v['field_name'] == '长难句解析'){
  14822. $result[$k]['cnjjx'] = $aff_v['field_value'];
  14823. }
  14824. }
  14825. }
  14826. }
  14827. return $result;
  14828. }
  14829. /*
  14830. * 获取试题标签
  14831. *
  14832. */
  14833. public function getTags($field_key='',$field_value=''){
  14834. $result = '';
  14835. $data = array(
  14836. 'subjectId'=>8,
  14837. 'isSearch'=>1,
  14838. 'tagFieldName'=>array($field_key)
  14839. );
  14840. $brain_data = $this->apiBrainPost('/all_subject/topic_tag', $data, 25, true);
  14841. if($brain_data && isset($brain_data['data']) && $brain_data['data']){
  14842. $brain_arr = $brain_data['data'];
  14843. if(isset($brain_arr[0]) && isset($brain_arr[0]['extend']) && $brain_arr[0]['extend']){
  14844. $field_value_arr = explode("|",$field_value);
  14845. $field_arr = array();
  14846. foreach($brain_arr[0]['extend'] as $extend_v){
  14847. if(in_array($extend_v['tag_extend_id'],$field_value_arr)){
  14848. $field_arr[]=$extend_v['tag_extend_name'];
  14849. }
  14850. }
  14851. if($field_arr){
  14852. $result = implode(",",$field_arr);
  14853. }
  14854. }
  14855. }
  14856. return $result;
  14857. }
  14858. /*读取考试试题推送配置*/
  14859. public function actionLoadExamPushTopic(){
  14860. $examGroupId = Req::post('examGroupId');
  14861. $examIds = Req::post('examIds');
  14862. $result=array();
  14863. $result['status']=0;
  14864. if(!$examGroupId || !is_numeric($examGroupId)){
  14865. $result['msg']="参数异常";
  14866. exit(jsonEncode($result));
  14867. }
  14868. if(!is_array($examIds)){
  14869. $examIds=explode(',',$examIds);
  14870. }
  14871. //加载试题结构
  14872. $classes=array();
  14873. $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  14874. if($examIds){
  14875. $criteria = new CDbCriteria();
  14876. $criteria->select = 'exam_id,class_id,tpl_data';
  14877. $criteria->addInCondition('exam_id',$examIds);
  14878. $exam = Exam::model()->findAll($criteria);
  14879. $tplData=array();
  14880. $alias=array();
  14881. foreach ($exam as $item){
  14882. $class=ClassModel::model()->find('class_id=:cid',array(':cid'=>$item['class_id']));
  14883. $classes[]=$class['class_name'];
  14884. if(!$tplData){
  14885. $tplData=json_decode($item['tpl_data'],true);
  14886. if(isset($tplData['new_items'])){
  14887. foreach ($tplData['new_items'] as $value){
  14888. if(isset($value['fullAlias'])){
  14889. $alias[$value['id']]=$value['fullAlias'];
  14890. }else{
  14891. $alias[$value['id']]=$value['alias'];
  14892. }
  14893. }
  14894. }
  14895. }
  14896. }
  14897. $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam[0]['exam_id']));
  14898. }
  14899. if(!$paper){
  14900. $result['msg']="考试数据异常";
  14901. exit(jsonEncode($result));
  14902. }
  14903. $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:pid',array(':pid'=>$paper['paper_id']));
  14904. $paperTopicRelation=array();
  14905. if($examGroup['qxk_paper_id']>0){
  14906. foreach ($paperTopic as $item){
  14907. $paperTopicRelation[$item['order']]=$item['topic_id'];
  14908. }
  14909. }else{
  14910. foreach ($paperTopic as $item){
  14911. if(isset($alias[$item['order']])){
  14912. $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$alias[$item['order']]);
  14913. }else{
  14914. $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$item['order']);
  14915. }
  14916. }
  14917. }
  14918. $data['qxk_paper_id']=$examGroup['qxk_paper_id'];
  14919. $data['paper_topic']=$paperTopicRelation;
  14920. $data['classes']=$classes;
  14921. //加载设置数据
  14922. $topicSetting=array();
  14923. if(count($examIds)==1){ //只有一个班
  14924. $examPushTopic=SExamPushTopicsSetting::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0]));
  14925. if($examPushTopic){
  14926. $topicSetting=json_decode($examPushTopic['topic_ids'],true);
  14927. }
  14928. }
  14929. $data['topic_setting']=$topicSetting;
  14930. $result['status']=1;
  14931. $result['data']=$data;
  14932. exit(jsonEncode($result));
  14933. }
  14934. /*保存考试试题推送配置*/
  14935. public function actionSaveExamPushTopicSetting(){
  14936. $examGroupId = Req::post('examGroupId');
  14937. $examIds = Req::post('examIds');
  14938. $topics=Req::post('topics');
  14939. $result=array();
  14940. $result['status']=0;
  14941. if(!$examIds || !is_numeric($examGroupId) ){
  14942. $result['msg']="参数异常";
  14943. exit(jsonEncode($result));
  14944. }
  14945. if(!$topics) $topics=array();
  14946. if(!is_array($examIds)){
  14947. $examIds=explode(',',$examIds);
  14948. }
  14949. $examPushTopicModel=new SExamPushTopicsSetting();
  14950. $examPushTopicModel->updateSettingBatch($examIds,$examGroupId,$topics);
  14951. $result['status']=1;
  14952. exit(jsonEncode($result));
  14953. }
  14954. /*加载考试班级*/
  14955. public function actionLoadExamClass(){
  14956. $examGroupId = Req::post('examGroupId');
  14957. $result['status']=0;
  14958. if(!$examGroupId){
  14959. $result['msg']="参数异常";
  14960. exit(jsonEncode($result));
  14961. }
  14962. $exam=$this->schoolManager->getExportClassByExamGroupId($examGroupId);
  14963. if(!$exam){
  14964. $result['msg']="未查询到考试信息";
  14965. exit(jsonEncode($result));
  14966. }
  14967. $uploaded=array();
  14968. $noUploaded=array();
  14969. foreach ($exam as $value){
  14970. if($value['upload_status']==0){
  14971. $noUploaded[]=array(
  14972. 'exam_id'=>$value['exam_id'],
  14973. 'class_id'=>$value['class_id'],
  14974. 'class_name'=>$value['class_name']
  14975. );
  14976. }else{
  14977. $uploaded[]=array(
  14978. 'exam_id'=>$value['exam_id'],
  14979. 'class_id'=>$value['class_id'],
  14980. 'class_name'=>$value['class_name']
  14981. );
  14982. }
  14983. }
  14984. $result['status']=1;
  14985. $result['uploaded']=$uploaded;
  14986. $result['no_uploaded']=$noUploaded;
  14987. exit(jsonEncode($result));
  14988. }
  14989. /*删除指定班级未上传考生*/
  14990. public function actionDelStudentPaperRelation(){
  14991. $examIds = Req::post('examIds');
  14992. $result['status']=0;
  14993. if(!$examIds){
  14994. $result['msg']="参数异常";
  14995. exit(jsonEncode($result));
  14996. }
  14997. if($this->schoolManager->delStudentPaperByExamId($examIds)){
  14998. $result['status']=1;
  14999. $result['msg']="删除成功";
  15000. exit(jsonEncode($result));
  15001. }else{
  15002. $result['msg']="删除失败";
  15003. exit(jsonEncode($result));
  15004. }
  15005. }
  15006. //客户端打印订单学生在线答题卡
  15007. public function actionPrintPdfOnlineByOrder(){
  15008. $examId=Req::post('exam_id');
  15009. $result['success']=0;
  15010. if(!$examId || !is_numeric($examId)){
  15011. $result['msg']='参数不正确';
  15012. exit(json_encode($result));
  15013. }
  15014. $examInfo = Exam::model()->findByPk($examId);
  15015. if(!$examInfo){
  15016. $result['msg']='未找到考试信息';
  15017. exit(json_encode($result));
  15018. }
  15019. $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
  15020. if(!$onlineCard){
  15021. $result['msg']='考试还没有使用在线答题卡';
  15022. exit(json_encode($result));
  15023. }
  15024. //检查订单
  15025. $orderClass=0;
  15026. $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
  15027. if($allClassStudents){
  15028. foreach ($allClassStudents as $student){
  15029. $students[]=$student['student_id'];
  15030. if(!$orderClass) $orderClass=$student['class_id'];
  15031. }
  15032. }
  15033. $semester=new SSemester();
  15034. $nowsem=$semester->getCurrentSemester();
  15035. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
  15036. $subjectId=Yii::app()->session['session_subject_id'];
  15037. if(in_array($subjectId,$this->mathSubjectId)){
  15038. $subjectId=3;
  15039. }
  15040. $intarr=array(
  15041. "schoolId"=>$this->schoolId,
  15042. "clazzId"=>$orderClass,
  15043. "semester"=>$nowsem['refer_code'],
  15044. "grade"=>$classinfo['grade'],
  15045. "students"=>array(),
  15046. "examTime"=>time(),
  15047. "classify"=>1,
  15048. "subject"=>$subjectId,
  15049. );
  15050. $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
  15051. if(count($allClassStudents)>count($students)){
  15052. $result['all_order']=0;
  15053. }else{
  15054. $result['all_order']=1;
  15055. }
  15056. if(!$students){
  15057. $result['msg']='当前班级没查询到订单';
  15058. exit(json_encode($result));
  15059. }
  15060. //查询生成状态
  15061. $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll();
  15062. if(!$studentPdf){
  15063. $result['msg']='答题卡还未生成';
  15064. exit(json_encode($result));
  15065. }
  15066. if(count($studentPdf)!=count($students)){
  15067. $result['all_created']=0;
  15068. }else{
  15069. $result['all_created']=1;
  15070. }
  15071. $result['success']=1;
  15072. $result['students']=$students;
  15073. exit(json_encode($result));
  15074. }
  15075. /*导出考试数据*/
  15076. public function actionExportExamData(){
  15077. $examGroupId = Req::post('examGroupId');
  15078. $params=array(
  15079. 'examGroupId'=>$examGroupId,
  15080. 'schoolId'=>$this->schoolId,
  15081. 'reGenerate'=>1
  15082. );
  15083. $result['status']=0;
  15084. $rs = http('/teacher/academic/report/download/exam-info','POST',$this->schoolId,$params,'cgi');
  15085. $rs=json_decode($rs,true);
  15086. if(isset($rs['errCode']) && $rs['errCode']=='00' ){
  15087. if($rs['data']){
  15088. $result['status']=1;
  15089. $result['data']=$rs['data'];
  15090. }else{
  15091. $result['status']=2;
  15092. }
  15093. }else{
  15094. $result['msg']="接口处理异常:".$rs['errMsg'];
  15095. }
  15096. exit(jsonEncode($result));
  15097. }
  15098. }