ThirdController.php 415 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: 刘红伟
  5. * QQ : 454303753
  6. * Date: 2017/6/16 0016
  7. * Time: 下午 15:29
  8. */
  9. class ThirdController extends Controller
  10. {
  11. public function actionIndex(){
  12. Url::clean();
  13. $printName = Req::get("name");
  14. $classId = Req::get("classId");
  15. $printType = Req::get("type");
  16. $grade = Req::get("grade");
  17. $labelled = Req::get("labelled");
  18. $display = Req::get("display");
  19. $is_print = Req::get("is_print");
  20. $exam_group_ids = array();
  21. $sheets = array();
  22. $exam_sheets = array();
  23. $sheet_rs = array();
  24. $marking_papers = array();
  25. $list_type =Req::get('list_type');
  26. //$getName = safe_replace(Yii::app()->request->getQuery('realname1'));
  27. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  28. // $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  29. // $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
  30. /**
  31. * 需求变动
  32. * 重新开发
  33. *
  34. */
  35. if (empty($printType)) {
  36. $printType = '2';
  37. $printTypeData = 0;
  38. } else {
  39. switch ($printType) {
  40. case "2":
  41. $printTypeData = 0;
  42. break;
  43. case "wtb":
  44. $printTypeData = 1;
  45. break;
  46. case "isp":
  47. $printTypeData = 2;
  48. break;
  49. case "studytrend":
  50. $printTypeData = 3;
  51. break;
  52. default:
  53. $printTypeData = null;
  54. break;
  55. }
  56. }
  57. $condition = array();
  58. if($is_print > -1)
  59. {
  60. $condition[] = "cep.is_print = '{$is_print}'";
  61. }else{
  62. $is_print = -1;
  63. }
  64. if($printName)
  65. $condition[] = "e.name like '%{$printName}%'";
  66. if (!Str::isBlank($labelled)) {
  67. $condition[] = " (p.is_labelled = '{$labelled}' or eg.is_tagging='{$labelled}')";
  68. }
  69. if ( empty($display)) {
  70. $condition[] = "e.is_display = 0";
  71. }else
  72. {
  73. $condition[] = "e.is_display = ".$display;
  74. }
  75. // $condition[] = "e.subject_id = '{$this->subjectId}'";
  76. $condition[] = "eg.is_third = 1";
  77. $condition[] = "eg.xb_homework = 0";
  78. if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
  79. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  80. }else{
  81. $condition[] = "e.subject_id = ".Yii::app()->session['session_duoxueke_subject_id'];
  82. }
  83. if($list_type){
  84. $condition[] = "eg.import_score_type = 2"; //传了参数,只读线下导入考试
  85. }else{
  86. $condition[] = "eg.import_score_type <>2 "; //没传参数,读其它所有阅卷类型
  87. }
  88. $gradeCardLength=array();
  89. $gradeData=SGrade::model()->findAll();
  90. foreach ($gradeData as $datum){
  91. if($datum->card_status==1){
  92. $gradeCardLength[$datum->id]=$datum->card_length;
  93. }else{
  94. $gradeCardLength[$datum->id]=0;
  95. }
  96. }
  97. $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc'));
  98. $printList = array();
  99. if($resultList["rs"]){
  100. $ExamModel=new Exam();
  101. $StudentPaperRelation=new SStudentPaperRelation();
  102. foreach ($resultList['rs'] as $k=>$v) {
  103. $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
  104. $time = time();
  105. $classinfo=ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$v['class_id']));
  106. $v['grade']=$classinfo['grade'];
  107. //解析状态
  108. $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$v['exam_group_id']));
  109. $v['tw_status']=$topicWord['status'];
  110. $v['wrong_reason']=$topicWord['wrong_reason'];
  111. $v['word_path']=$topicWord['word_path'];
  112. $v['allsubject_file_path']=$topicWord['allsubject_file_path'];
  113. if($topicWord['allsubject_file_path']){
  114. //解析预计完成时间
  115. $v['estimate']=48*3600+$topicWord['upload_time'];
  116. }
  117. $v['params_id']=$topicWord['params_id'];
  118. $v['parse_upload_time']=$topicWord['upload_time'];
  119. $printList[$k] = $v;
  120. $tplData = json_decode($v["tpl_data"], true);
  121. //FIXME 添加班级参数
  122. $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0;
  123. $printList[$k]['show_print'] = 0;
  124. //准考证
  125. if(!$v['school_card_status']){
  126. $printList[$k]['school_card_length'] = $gradeCardLength[$v['grade']];
  127. }
  128. //考试时间
  129. if(isset($tplData['examDate']))
  130. {
  131. $examDate = strtotime($tplData["examDate"]);
  132. }
  133. if(isset($tplData['new_items']) && !isset($tplData['items']))
  134. {
  135. $printList[$k]['show_print'] = 1;
  136. }
  137. //标注期望完成时间
  138. if(isset($tplData['estimateTime']))
  139. {
  140. $printList[$k]['estimate_time'] = date('Y-m-d H:i:s',$tplData["estimateTime"]);
  141. }
  142. if(!isset($tplData["examDate"]))
  143. {
  144. $examDate = $v["create_time"];
  145. }
  146. $printList[$k]['examDate'] = $examDate;
  147. if(isset($tplData['totals'])){
  148. $printList[$k]['totals'] = $tplData['totals'];
  149. }
  150. if(isset($tplData['total_score'])){
  151. $printList[$k]['total_score'] = $tplData['total_score'];
  152. }
  153. if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){
  154. $printList[$k]['is_change_to_third'] = 1;
  155. }else{
  156. $printList[$k]['is_change_to_third'] = 0;
  157. } //统计班级,学生
  158. if($list_type){
  159. $exam=$ExamModel->getExamIds($v['exam_group_id']);
  160. if($exam){
  161. $studentCount=0;
  162. $uploadedCount=0;
  163. $studentList=$StudentPaperRelation->getStudentExamInfo($exam);
  164. $studentCount=count($studentList);
  165. $printList[$k]['class_count']=count($exam).'('.$studentCount.'人)';
  166. foreach ($studentList as $value){
  167. if($value['is_feedback']==1){
  168. $uploadedCount++;
  169. }
  170. }
  171. $printList[$k]['upload_count']=$uploadedCount.'/'.$studentCount;
  172. if($uploadedCount>0){
  173. $printList[$k]['upload_status']='已上传成绩';
  174. }else{
  175. $printList[$k]['upload_status']='未上传成绩';
  176. }
  177. }
  178. }else{
  179. //判断上传状态
  180. $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($v['exam_group_id']);
  181. $uploadStatus=0;
  182. if($uploadExamInfo){
  183. if(isset($uploadExamInfo[1])){
  184. $printList[$k]['uploadExamTemplateId']=$uploadExamInfo[1]['template_id'];
  185. if($uploadExamInfo[1]['topic_upload']==1){
  186. $uploadStatus+=1;
  187. }
  188. }
  189. if(isset($uploadExamInfo[2])){
  190. $printList[$k]['uploadAnswerTemplateId']=$uploadExamInfo[2]['template_id'];
  191. if($uploadExamInfo[2]['answer_upload']==1){
  192. $uploadStatus+=3;
  193. }
  194. }
  195. }
  196. //判断是否已上传成绩
  197. $printList[$k]['is_feedback']=0;
  198. $exam=$ExamModel->getExamIds($v['exam_group_id']);
  199. if($exam){
  200. if($StudentPaperRelation->getStudentFeedBack($exam)){
  201. $printList[$k]['is_feedback']=1;
  202. }
  203. }
  204. $printList[$k]['uploadExamStatus']=$uploadStatus;
  205. $printList[$k]['uploadExamInfo'] = $uploadExamInfo;
  206. }
  207. }
  208. }
  209. $sheet_ids = array();
  210. $criteria = new CDbCriteria();
  211. $criteria->addInCondition('exam_group_id',$exam_group_ids);
  212. $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
  213. if($exam_sheet_data)
  214. {
  215. foreach($exam_sheet_data as $v)
  216. {
  217. $exam_sheets[$v->exam_group_id] = $v->online_card;
  218. $sheet_ids[$v->sheet_id] = $v->sheet_id;
  219. $sheet_rs[$v->exam_group_id] = $v;
  220. if($v->online_card){
  221. $onlineMultiplex=$this->schoolManager->getOnlineCardMultiplex($v->multiplex_id);
  222. if($onlineMultiplex){
  223. $marking_papers[$v->exam_group_id] = $onlineMultiplex['marking_papers'];
  224. }
  225. }
  226. }
  227. }
  228. //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
  229. $subject_exam_data=Yii::app()->params['subjectId'];
  230. $teachers_data = Teacher::model()->findAll();
  231. $class_teacher_data = array();
  232. if($teachers_data)
  233. {
  234. foreach($teachers_data as $k=>$v)
  235. {
  236. $class_teacher_data[$v->teacher_id] = $v->teacher_name;
  237. }
  238. }
  239. //获取班级年级
  240. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  241. $class_grade_arr=array();
  242. if($class_data)
  243. {
  244. foreach($class_data as $v)
  245. {
  246. $class_grade_arr[$v->class_id] = $v->grade;
  247. }
  248. }
  249. unset($class_data);
  250. $data = array();
  251. //$data = $this->export($getName,$grade_id,$class_id);
  252. //判断全学科试用学校
  253. // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi');
  254. // $rs=json_decode($rs,true);
  255. // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  256. // $data['is_qxk']=1;
  257. // }else{
  258. // $data['is_qxk']=0;
  259. // }
  260. $data['is_qxk']=1;
  261. $data['printList'] = $printList;
  262. $data['pages'] = $resultList['pager'];
  263. $data['page_total'] = $resultList['pager']->rowsCount;
  264. $data["printType"] = $printType;
  265. $data["printName"] = $printName;
  266. $data["teachers"] = $class_teacher_data;
  267. $data["classId"] = $classId;
  268. $data["grade"] = $grade;
  269. $data["sheets"] = $sheets;
  270. $data["exam_sheets"] = $exam_sheets;
  271. $data["sheet_rs"] = $sheet_rs;
  272. $data["labelled"] = $labelled;
  273. $data["display"] = $display;
  274. $data["is_print"] = $is_print;
  275. $data["subject"] = $subject_exam_data;
  276. $data['list_type'] =$list_type;
  277. $data["class_grade"] = $class_grade_arr;
  278. $data['showAssist'] =0;
  279. $data['extendSubject'] =$this->extendSubject;
  280. $data["marking_papers"] = $marking_papers;
  281. //获取导出数据白名单
  282. $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);;
  283. //debug($printList);
  284. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  285. {
  286. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  287. }else
  288. {
  289. $data["use_zhixue"] = 0;
  290. }
  291. unset($resultList);
  292. //获取产品设置版本
  293. $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
  294. if(!$productEdition || $productEdition['switch']==2){
  295. $data['productSwitch']=2;
  296. }else{
  297. $data['productSwitch']=3;
  298. }
  299. $data['schoolId'] =$this->schoolId;
  300. $data['version_number']=$this->version_number;
  301. if($list_type){
  302. $this->render('index_underline',$data);
  303. }else{
  304. if(Yii::app()->params['section']==0){
  305. $this->render('index_section',$data);
  306. }else{
  307. $this->render('index2',$data);
  308. }
  309. }
  310. }
  311. public function actionIndex1(){
  312. Url::clean();
  313. $printName = Req::get("name");
  314. $classId = Req::get("classId");
  315. $printType = Req::get("type");
  316. $grade = Req::get("grade");
  317. $labelled = Req::get("labelled");
  318. $display = Req::get("display");
  319. $is_print = Req::get("is_print");
  320. $exam_group_ids = array();
  321. $sheets = array();
  322. $exam_sheets = array();
  323. $sheet_rs = array();
  324. /**
  325. * 需求变动
  326. * 重新开发
  327. *
  328. */
  329. if (empty($printType)) {
  330. $printType = '2';
  331. $printTypeData = 0;
  332. } else {
  333. switch ($printType) {
  334. case "2":
  335. $printTypeData = 0;
  336. break;
  337. case "wtb":
  338. $printTypeData = 1;
  339. break;
  340. case "isp":
  341. $printTypeData = 2;
  342. break;
  343. case "studytrend":
  344. $printTypeData = 3;
  345. break;
  346. default:
  347. $printTypeData = null;
  348. break;
  349. }
  350. }
  351. $condition = array();
  352. if($is_print > -1)
  353. {
  354. $condition[] = "cep.is_print = '{$is_print}'";
  355. }else{
  356. $is_print = -1;
  357. }
  358. if($printName)
  359. $condition[] = "e.name like '%{$printName}%'";
  360. if (!Str::isBlank($labelled)) {
  361. $condition[] = "p.is_labelled = '{$labelled}'";
  362. }
  363. if ( empty($display)) {
  364. $condition[] = "e.is_display = 0";
  365. }else
  366. {
  367. $condition[] = "e.is_display = ".$display;
  368. }
  369. // $condition[] = "e.subject_id = '{$this->subjectId}'";
  370. $condition[] = "eg.is_third = 1";
  371. $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc'));
  372. $printList = array();
  373. if($resultList["rs"]){
  374. foreach ($resultList['rs'] as $k=>$v) {
  375. $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
  376. $time = time();
  377. $printList[$k] = $v;
  378. $tplData = json_decode($v["tpl_data"], true);
  379. //FIXME 添加班级参数
  380. $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0;
  381. //考试时间
  382. if(isset($tplData['examDate']))
  383. {
  384. $examDate = strtotime($tplData["examDate"]);
  385. }
  386. if(!isset($tplData["examDate"]))
  387. {
  388. $examDate = $v["create_time"];
  389. }
  390. $printList[$k]['examDate'] = $examDate;
  391. $expireTime = $examDate + (3600 * 24 * 2);
  392. if($time > $expireTime){
  393. $printList[$k]['is_expired'] = true;
  394. }
  395. }
  396. }
  397. $sheet_ids = array();
  398. $criteria = new CDbCriteria();
  399. $criteria->addInCondition('exam_group_id',$exam_group_ids);
  400. $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
  401. if($exam_sheet_data)
  402. {
  403. foreach($exam_sheet_data as $v)
  404. {
  405. $exam_sheets[$v->exam_group_id] = $v->sheet_id;
  406. $sheet_ids[$v->sheet_id] = $v->sheet_id;
  407. $sheet_rs[$v->exam_group_id] = $v;
  408. }
  409. }
  410. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  411. //获取班级年级
  412. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  413. if($class_data)
  414. {
  415. foreach($class_data as $v)
  416. {
  417. $class_grade_arr[$v->class_id] = $v->grade;
  418. }
  419. }
  420. unset($class_data);
  421. $data = array();
  422. $data['printList'] = $printList;
  423. $data['pages'] = $resultList['pager'];
  424. $data['page_total'] = $resultList['pager']->rowsCount;
  425. $data["printType"] = $printType;
  426. $data["printName"] = $printName;
  427. $data["classId"] = $classId;
  428. $data["grade"] = $grade;
  429. $data["sheets"] = $sheets;
  430. $data["exam_sheets"] = $exam_sheets;
  431. $data["sheet_rs"] = $sheet_rs;
  432. $data["sheet_ids"] = $sheet_ids;
  433. $data["labelled"] = $labelled;
  434. $data["display"] = $display;
  435. $data["is_print"] = $is_print;
  436. $data["subject"] = $subject_exam_data;
  437. $data["class_grade"] = $class_grade_arr;
  438. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  439. {
  440. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  441. }else
  442. {
  443. $data["use_zhixue"] = 0;
  444. }
  445. unset($resultList);
  446. $this->render('index1',$data);
  447. }
  448. protected function export($getName,$grade_id,$class_id)
  449. {
  450. //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
  451. $grade_class_array = array();
  452. $con = array();
  453. // 打印任务处理
  454. $ExamModel = Exam::model();
  455. $ClassModel = ClassModel::model();
  456. $printList = array();
  457. $grade_class_data = ClassModel::model()->findAll('grade=:grade', array(':grade' => $grade_id));
  458. if ($grade_class_data) {
  459. foreach ($grade_class_data as $v) {
  460. $grade_class_array[$v->class_id] = $v->attributes;
  461. }
  462. }
  463. // 获取当前学期班级并组装
  464. $criteria = new CDbCriteria();
  465. $criteria->addCondition('semester_id=:semester_id');
  466. if ($grade_id) {
  467. $con = array('c.grade = ' . $grade_id);
  468. $criteria->addCondition('grade=:grade');
  469. $criteria->params[':grade'] = $grade_id;
  470. }
  471. if ($class_id) {
  472. $con = array_merge($con, array('c.class_id = ' . $class_id));
  473. $criteria->addCondition('class_id=:class_id');
  474. $criteria->params[':class_id'] = $class_id;
  475. }
  476. if ($getName) {
  477. $con = array_merge($con, array("e.name like '%{$getName}%'"));
  478. }
  479. if (Yii::app()->session['session_duoxueke_subject_id'] == 6 || Yii::app()->session['session_duoxueke_subject_id'] == 3) {
  480. $con = array_merge($con, array('e.subject_id in (3,6)'));
  481. } else {
  482. $con = array_merge($con, array('e.subject_id = ' . Yii::app()->session['session_duoxueke_subject_id']));
  483. }
  484. if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
  485. $con = array_merge($con, array('e.subject_id in ('.implode(',',$this->mathSubjectId).')'));
  486. }else{
  487. $condition[] = "e.subject_id = '{$this->subjectId}'";
  488. }
  489. $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
  490. $class_array = ClassModel::model()->findAll($criteria);
  491. $ccArray = array();
  492. $ccName = array();
  493. foreach ($class_array as $cc => $ca) {
  494. array_push($ccArray, $ca->class_id);
  495. $ccName[$ca->class_id] = $ca->class_name;
  496. }
  497. $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "e.status = 1"), $con),array('e.complete_time desc'));
  498. if ($resultList["rs"]) {
  499. foreach ($resultList['rs'] as $k => $v) {
  500. $printList[$k] = $v;
  501. $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
  502. $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称
  503. $printList[$k]['print_name'] = $pname;
  504. }
  505. }
  506. $data = array();
  507. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  508. $data['realname'] = $getName;
  509. $data['grade_id'] = $grade_id;
  510. $data['class_id'] = $class_id;
  511. $data['grade_class'] = $grade_class_array;
  512. $data['printList1'] = $printList;
  513. $data['pages1'] = $resultList['pager'];
  514. $data['page_total1'] = $resultList['pager']->rowsCount;
  515. $data["subject"] = $subject_exam_data;
  516. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  517. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  518. } else {
  519. $data["use_zhixue"] = 0;
  520. }
  521. $data['past_sem_exist'] = 0;//默认不存在过去的学期
  522. $sql = 'select start_time from semester where status=1 limit 1';
  523. $res = $this->sConn->createCommand($sql)->queryRow();
  524. $start_time = $res['start_time'];
  525. if (!$start_time) {
  526. Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
  527. }
  528. $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
  529. $res = $this->sConn->createCommand($sql)->queryRow();
  530. $row_num = $res['rownum'];
  531. $row_num && $data['past_sem_exist']=1;
  532. unset($resultList);
  533. return $data;
  534. }
  535. public function actionOprateexam()
  536. {
  537. $exam_group_id = Req::post("exam_group_id");
  538. $flag = Req::post("flag");
  539. $error['success'] = 0;
  540. if (empty($exam_group_id)) {
  541. $error['message'] = '操作失败!';
  542. echo json_encode($error);exit();
  543. }
  544. $this->setIs_new($exam_group_id);
  545. if ($this->schoolManager->ThirdOprateExamDisplay($exam_group_id,$flag)) {
  546. $error['success'] = 1;
  547. $error['message'] = '操作成功!';
  548. } else {
  549. $error['message'] = '操作失败!';
  550. }
  551. echo json_encode($error);exit();
  552. }
  553. public function actionExam_list()
  554. {
  555. ini_set("memory_limit","300M");
  556. $exam_group_id = Req::get("exam_group_id");
  557. $branch = Req::get("branch");
  558. $grade = Req::get("grade");
  559. $exam_date = ''; //考试日期
  560. $exam_name = ''; //考试名称
  561. $exam_uploaded=0;
  562. if($exam_group_id>0)
  563. {
  564. if($exam_group_id <= 0)
  565. {
  566. Yii::app()->jump->error('未找到考试信息!');
  567. }
  568. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  569. if(!$exam_group_data)
  570. {
  571. Yii::app()->jump->error('未找到考试信息!');
  572. }
  573. if($exam_group_data->upload_status>0){
  574. $exam_uploaded=1;
  575. }
  576. $classId = Req::get("classId");
  577. $condition = array();
  578. if($classId)
  579. $condition[] = "e.class_id = '{$classId}'";
  580. $condition[] = "eg.exam_group_id = '{$exam_group_id}'";
  581. $classes = $this->schoolManager->getSemesterClasses($this->semesterId);
  582. if(!$classes)
  583. {
  584. Yii::app()->jump->error('本学期尚未建班级!');
  585. }
  586. $_classes = array();
  587. foreach($classes as $v)
  588. {
  589. $_classes[$v['class_id']][$v['class_id']] = $v;
  590. }
  591. $resultList = $this->schoolManager->getExamList($condition,array('e.create_time desc','e.exam_id desc'));
  592. if($resultList && isset($resultList['rs'][0])){
  593. $tplData=json_decode($resultList['rs'][0]['tpl_data'],true);
  594. }else{
  595. Yii::app()->jump->error('未找到考试信息!');
  596. }
  597. if(!$exam_date) $exam_date=$tplData['examDate'];
  598. if(!$exam_name) $exam_name=$resultList['rs'][0]['exam_name'];
  599. $data['exam_id']=$resultList['rs'][0]['exam_id'];
  600. if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){
  601. $data['is_change_to_third'] = 1;
  602. }else{
  603. $data['is_change_to_third'] = 0;
  604. }
  605. //获取paper 表数据
  606. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$resultList['rs'][0]['exam_id']));
  607. if(!$paper_data)
  608. {
  609. Yii::app()->jump->error('未找到考试信息!');
  610. }
  611. //读取试题数据
  612. $isAllSelect=1; //全部客观题判断
  613. $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
  614. //选择题类型判断
  615. $allSubjectType=array();
  616. if($exam_group_data['qxk_paper_id']>0){
  617. $allSubjectType=array(1,2,3,4,12);
  618. }else{
  619. $allSubjectType=array(1,2,11);
  620. }
  621. if($paperTopic){
  622. $data['answer_card_saved'] = 1;
  623. foreach ($paperTopic as $item){
  624. if(!in_array($item->type,$allSubjectType)){
  625. $isAllSelect=0;
  626. break;
  627. }
  628. }
  629. }else{
  630. //未制作答题卡
  631. $data['answer_card_saved'] = 0;
  632. }
  633. //读取试题推送设置
  634. $topicPushSettingModel=new SExamPushTopicsSetting();
  635. $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id);
  636. $topicPushSettingRelation=array();
  637. if($topicPushSetting){
  638. foreach ($topicPushSetting as $item){
  639. if($item['topic_ids']){
  640. $topicSetting=json_decode($item['topic_ids'],true);
  641. if($topicSetting){
  642. $topicPushSettingRelation[(string)$item['exam_id']]=1;
  643. }
  644. }
  645. }
  646. }
  647. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  648. $this->setIs_new($exam_group_id);
  649. //查询还原记录
  650. $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  651. if($examRestore){
  652. $data['restore'] = 1;
  653. }else{
  654. $data['restore'] = 0;
  655. }
  656. //是否使用在线答题卡
  657. $studentAnswerOnline=$this->schoolManager->getAnswerSheetOnline($exam_group_id);
  658. if($studentAnswerOnline){
  659. $data['online_card']=$studentAnswerOnline['online_card'];
  660. $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
  661. }else{
  662. $data['online_card']=0;
  663. $data['is_qrcode_online']=0;
  664. }
  665. $has_marked = false;
  666. $studentAnswerCardOnline=new SStudentAnswerCardOnline();
  667. foreach ($resultList['rs'] as $key => $item){
  668. if($item['status'] == 1){
  669. $has_marked = true;
  670. }
  671. //查询生成数量
  672. if($data['online_card']==1 && $data['is_qrcode_online']==1){
  673. $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($item['exam_id']);
  674. if($studentCardOnline){
  675. $resultList['rs'][$key]['card_created']=$studentCardOnline['count'];
  676. }
  677. }
  678. }
  679. //是否能添加班级 FIXME add_class_0924
  680. //打印中
  681. $enable_add_class = false;
  682. if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] == 0){
  683. $enable_add_class = true;
  684. }else{
  685. //混合阅卷
  686. if($exam_group_data['mark_type'] == 3){
  687. $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true;
  688. }
  689. //单独阅卷
  690. if($exam_group_data['mark_type'] == 4){
  691. $enable_add_class = $has_marked ? false : true;
  692. }
  693. }
  694. $data['pages'] = $resultList['pager'];
  695. $data['page_total'] = $resultList['pager']->rowsCount;
  696. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  697. {
  698. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  699. }else
  700. {
  701. $data["use_zhixue"] = 0;
  702. }
  703. $data['printList'] = $resultList['rs'];
  704. $data["classes"] = $_classes;
  705. $data["classId"] = $classId;
  706. $data["exam_group_id"] = $exam_group_id;
  707. $data["exam_group_data"] = $exam_group_data;
  708. // $data["subject"] = $subject_exam_data;
  709. $data["branch"] = $branch;
  710. $data["grade"] = $grade;
  711. $data["enable_add_class"] = $enable_add_class;
  712. $data['is_all_select']=$isAllSelect;
  713. $data["exam_name"] = $exam_name;
  714. $data['version_number']=$this->version_number;
  715. $data['exam_date']=$exam_date;
  716. $data['exam_uploaded']=$exam_uploaded;
  717. $data['topic_push_setting']=$topicPushSettingRelation;
  718. $this->render('exam_list',$data);
  719. }
  720. }
  721. public function actionChange(){
  722. ini_set("memory_limit","300M");
  723. Url::clean();
  724. $sname = Req::get("sname");
  725. $cid = Req::get("cid");
  726. $eid = Req::get("eid");
  727. $tid = Req::get("tid");
  728. $isFeedback=0;
  729. switch($tid){
  730. case "0":
  731. $printType = 'wp';
  732. break;
  733. case "1":
  734. $printType = 'wb';
  735. break;
  736. case "2":
  737. $printType = 'isp';
  738. break;
  739. default:
  740. $printType = 'wp';
  741. }
  742. $classInfo = ClassModel::model()->findByPk($cid);
  743. if (empty($classInfo)) {
  744. Yii::app()->jump->error('未找到班级!');
  745. }
  746. $examInfo = Exam::model()->findByPk($eid);
  747. if (empty($examInfo)) {
  748. Yii::app()->jump->error('未找到周周练!');
  749. }
  750. $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
  751. if (empty($getResult)) {
  752. Yii::app()->jump->error('未找到班级与试卷对应关系!');
  753. }
  754. $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
  755. if (empty($paperInfo)) {
  756. Yii::app()->jump->error('未找到试卷信息!');
  757. }
  758. $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id);
  759. if(trim($paperInfo->answer_card_src))
  760. $answerCardUploaded = true;
  761. else
  762. $answerCardUploaded = false;
  763. $tpl = 1;// 需要上传模板
  764. $tplTwo= 1;
  765. if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) {
  766. $paperType = 1;
  767. if (empty($paperInfo->tpl_doc_src)) {
  768. $tpl = 2;
  769. }
  770. $tplTwo= 2;
  771. }else{
  772. $paperType = 2;
  773. }
  774. if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl']))
  775. {
  776. $tpl = 1;
  777. $paperType = 1;
  778. $tplTwo= 2;
  779. }
  780. if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){
  781. $isCustomTpl = true;
  782. }
  783. else{
  784. $isCustomTpl = false;
  785. }
  786. // 获取阅卷类型
  787. $markType = 0;
  788. $groupInfo = $this->schoolManager->getExam($eid);
  789. if (!empty($groupInfo)) {
  790. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
  791. if (!empty($findInfo)) {
  792. $markType = $findInfo->mark_type;
  793. if($findInfo->mark_type==0 && $findInfo->is_third==1){
  794. $isUnderLine = 1;
  795. }
  796. }
  797. }
  798. $result = array();
  799. $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));
  800. //if (empty($relateStudent)) {
  801. // Yii::app()->jump->error('未找该试卷关联的学生!');
  802. //} else {
  803. //$studentModel = StudentInfo::model();
  804. // 获取学生姓名
  805. $_student_id = array();
  806. foreach($relateStudent as $v)
  807. {
  808. $_student_id[$v->student_id] = $v->student_id;
  809. }
  810. //if(!$_student_id)
  811. //{
  812. // Yii::app()->jump->error('未找该试卷关联的学生!');
  813. //}
  814. $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId);
  815. if(!$b_student_arr ){
  816. $array_student = array();
  817. $b_student_arr = array();
  818. $criteria = new CDbCriteria();
  819. $criteria->select = 'student_id';
  820. $criteria->addCondition('school_id=:school_id');
  821. $criteria->addCondition('status=:status');
  822. $criteria->params[':school_id'] = $this->schoolId;
  823. $criteria->params[':status'] = 1;
  824. $b_student_data = BusinessStudent::model()->findAll($criteria);
  825. if($b_student_data){
  826. foreach ($b_student_data as $k=>$v){
  827. $array_student[$v->student_id] = $v->student_id;
  828. }
  829. }
  830. Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
  831. if($array_student){
  832. Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student);
  833. Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000);
  834. }
  835. unset($criteria);
  836. if($b_student_data)
  837. {
  838. foreach($b_student_data as $v)
  839. {
  840. $b_student_arr[$v->student_id] = $v->student_id;
  841. }
  842. }
  843. unset($b_student_data);
  844. unset($criteria);
  845. }
  846. $studentNames = array();
  847. $criteria = new CDbCriteria();
  848. $criteria->addInCondition('student_id',$_student_id);
  849. $studentArray = SStudentInfo::model()->findAll($criteria);
  850. if (!empty($studentArray)) {
  851. foreach ($studentArray as $student) {
  852. $studentNames[$student->student_id] = $student->realname;
  853. }
  854. }
  855. //查询是否上传答题图片
  856. $uploadAnswerImgStudent=array();
  857. $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,0);
  858. if($student_answer_img){
  859. foreach ($student_answer_img as $val){
  860. $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id'];
  861. }
  862. }
  863. foreach ($relateStudent as $key=>$val) {
  864. //查询学生身份证号
  865. $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id));
  866. if($studentInfo){
  867. $result[$key]['id_number'] = $studentInfo->id_number;
  868. }else{
  869. $result[$key]['id_number'] = '';
  870. }
  871. $result[$key]['student_card'] = $val['student_card'];
  872. $result[$key]['school_student_card'] = $val['school_student_card'];
  873. $result[$key]['upload_answer_img'] =0;
  874. if($val->is_feedback==1){
  875. $isFeedback=1;
  876. if(isset($uploadAnswerImgStudent[(string)$val->student_id])){
  877. $result[$key]['upload_answer_img'] =1;
  878. }
  879. }
  880. //查询在线答题卡是否生成
  881. $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();
  882. if($rs && $rs['answer_card_online_created']==1){
  883. $result[$key]['online_created'] = 1;
  884. }else{
  885. $result[$key]['online_created'] = 0;
  886. }
  887. if (empty($sname)) {
  888. $result[$key]['clazzName'] = $classInfo->class_name;
  889. $result[$key]['paperName'] = $examInfo->name;
  890. $result[$key]['studentCode'] = $val->student_id;
  891. $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null;
  892. $result[$key]['is_feedback'] = $val->is_feedback;
  893. $result[$key]['student_img_paper'] = $val->student_img_paper;
  894. $result[$key]['is_complete'] = $val->is_complete;
  895. } else {
  896. if ($sname == $studentNames[$val->student_id]) {
  897. $result[$key]['clazzName'] = $classInfo->class_name;
  898. $result[$key]['paperName'] = $examInfo->name;
  899. $result[$key]['studentCode'] = $val->student_id;
  900. $result[$key]['studentName'] = $studentNames[$val->student_id];
  901. $result[$key]['is_feedback'] = $val->is_feedback;
  902. $result[$key]['student_img_paper'] = $val->student_img_paper;
  903. $result[$key]['is_complete'] = $val->is_complete;
  904. }else{
  905. unset($result[$key]);
  906. }
  907. unset($relateStudent[$key]);
  908. }
  909. $printCheck = true;
  910. }
  911. //}
  912. $no_paper_student = array();
  913. $paper_student_array = array();
  914. $c_paper_student_array = array();
  915. $class_student_info_data = array();
  916. $_student_ids = array();
  917. $_student_id_names = array();
  918. $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation
  919. if($class_student_data)
  920. {
  921. foreach($class_student_data as $v)
  922. {
  923. $_student_ids[$v['student_id']] = $v['student_id'];
  924. }
  925. $criteria = new CDbCriteria();
  926. $criteria->addInCondition('student_id',$_student_ids);
  927. $studentArray = SStudentInfo::model()->findAll($criteria);
  928. if (!empty($studentArray)) {
  929. foreach ($studentArray as $student) {
  930. $_student_id_names[$student->student_id] = $student->realname;
  931. }
  932. }
  933. }
  934. ///$class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info
  935. $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生
  936. $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生
  937. if ($paper_student_data) {
  938. foreach ($paper_student_data as $v) {
  939. $paper_student_array[$v['student_id']] = $v['student_id'];
  940. }
  941. $class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
  942. }
  943. if ($c_paper_student_data) {
  944. foreach ($c_paper_student_data as $v) {
  945. $c_paper_student_array[$v['student_id']] = $v['student_id'];
  946. }
  947. //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
  948. }
  949. if ($class_student_info_data) {
  950. foreach ($class_student_info_data as $v) {
  951. $class_student_info_array[$v['student_id']] = $v['realname'];
  952. }
  953. }
  954. if ($class_student_data) {
  955. foreach($class_student_data as $v)
  956. {
  957. if(!isset($b_student_arr[$v['student_id']]))
  958. {
  959. if ($paper_student_array)
  960. {
  961. if(isset($paper_student_array[$v['student_id']])){
  962. $no_paper_student[$v['student_id']] = array(
  963. 'student_id' => $v['student_id'],
  964. 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
  965. );
  966. }
  967. }
  968. if($c_paper_student_array )
  969. {
  970. if(!isset($c_paper_student_array[$v['student_id']]) )
  971. {
  972. $no_paper_student[$v['student_id']] = array(
  973. 'student_id' => $v['student_id'],
  974. 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
  975. );
  976. }
  977. }else
  978. {
  979. $no_paper_student[$v['student_id']] = array(
  980. 'student_id' => $v['student_id'],
  981. 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
  982. );
  983. }
  984. }
  985. }
  986. }
  987. //判断在线答题卡使用情况
  988. $useAnswerCardOnlineQrcode=0;
  989. $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']);
  990. if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
  991. $useAnswerCardOnlineQrcode=1;
  992. }
  993. $this->setIs_new($examInfo->exam_group_id);
  994. $data = array();
  995. if(isset($isUnderLine)){
  996. $data['under_line']=$isUnderLine;
  997. }
  998. //判断在线答题卡使用情况
  999. $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']);
  1000. if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
  1001. $data['use_answer_card_online_qrcode']=1;
  1002. }else{
  1003. $data['use_answer_card_online_qrcode']=0;
  1004. }
  1005. $_num= '';
  1006. $use_version = '';
  1007. if(isset(Yii::app()->session['coachInfo']->use_version))
  1008. {
  1009. $use_version = Yii::app()->session['coachInfo']->use_version;
  1010. }else
  1011. {
  1012. $use_version = Yii::app()->session['coachInfo']['use_version'];
  1013. }
  1014. if(!$use_version)
  1015. {
  1016. $use_version = 100;
  1017. }
  1018. $version_number = implode('',explode('.',$use_version));
  1019. if(strlen($version_number)<7)
  1020. {
  1021. for($i=0;$i<7-strlen($version_number);$i++)
  1022. {
  1023. $_num.='0';
  1024. }
  1025. }
  1026. $version_number=(int)$version_number.$_num;
  1027. $data['version_number']=$version_number;
  1028. $data['no_paper_student'] = $no_paper_student;
  1029. $data['result'] = $result;
  1030. $data["printType"] = $printType;
  1031. $data["sname"] = $sname;
  1032. $data['paper_id'] = $paperInfo->paper_id;
  1033. $data['exam_id'] = $eid;
  1034. $data['class_id'] = $cid;
  1035. $data['type_id'] = $tid;
  1036. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1037. {
  1038. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1039. }else
  1040. {
  1041. $data["use_zhixue"] = 0;
  1042. }
  1043. // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  1044. // $data["subject"] = $subject_exam_data;
  1045. $data['wp_type'] = $examInfo->tpl_index;
  1046. $data['className'] = $classInfo->class_name;
  1047. $data['paperName'] = $examInfo->name;
  1048. $data['tpl'] = $tpl;
  1049. $data['tplTwo'] = $tplTwo;
  1050. $data['markType'] = $markType;
  1051. $data['examInfo'] = $examInfo;
  1052. $data['paperType'] = $paperType;
  1053. $data['answerCardUploaded'] = $answerCardUploaded;
  1054. $data['paperData'] = $paperData;
  1055. $data['isCustomTpl'] = $isCustomTpl;
  1056. $data['isFeedback'] = $isFeedback;
  1057. $data['printCheck'] = $printCheck;
  1058. $data['useAnswerCardOnlineQrcode'] = $useAnswerCardOnlineQrcode;
  1059. $this->render('change',$data);
  1060. }
  1061. public function actionExam_answer()
  1062. {
  1063. $exam_group_id = Req::get("exam_group_id");
  1064. $data = array();
  1065. if($exam_group_id>0)
  1066. {
  1067. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1068. $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1069. if(!$exam_data || !$exam_group_data)
  1070. {
  1071. Yii::app()->jump->error('非法试卷!');
  1072. }
  1073. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_data->exam_id));
  1074. if($paper_data)
  1075. {
  1076. $paper_topic_data = SPaperTopicRelation::model()->findAll(array(
  1077. 'order' => '`order` asc',
  1078. 'condition' => 'paper_id=:paper_id and type=:type',
  1079. 'params'=>array(':paper_id'=>$paper_data->paper_id,':type'=>1)
  1080. ));
  1081. if($paper_topic_data)
  1082. {
  1083. $data['paper_topic'] = $paper_topic_data;
  1084. }else
  1085. {
  1086. Yii::app()->jump->error('试卷无选择题!');
  1087. }
  1088. }else
  1089. {
  1090. Yii::app()->jump->error('非法试卷!');
  1091. }
  1092. $this->setIs_new($exam_group_id);
  1093. if($exam_group_data->sheet_answer)
  1094. {
  1095. $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1);
  1096. }else
  1097. {
  1098. $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1);
  1099. }
  1100. $data['exam_data'] = $exam_data;
  1101. $data['use_zhixue'] = 0;
  1102. $data['exam_group_id'] = $exam_group_id;
  1103. $data['paper_data'] = $paper_data;
  1104. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  1105. $data["subject"] = $subject_exam_data;
  1106. $this->render('exam_answer',$data);
  1107. }else
  1108. {
  1109. Yii::app()->jump->error('非法试卷!');
  1110. }
  1111. }
  1112. public function actionSave_answer()
  1113. {
  1114. $answer = Req::post("answer");
  1115. $paper_id = Req::post("paper_id");
  1116. $exam_group_id = Req::post("exam_group_id");
  1117. $status = 0;
  1118. $exam_answers = array();
  1119. if($answer && $paper_id && $exam_group_id)
  1120. {
  1121. $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type=:type',array(':paper_id'=>$paper_id,':type'=>1));
  1122. if($paper_topic_data)
  1123. {
  1124. if(count($answer)==count($paper_topic_data))
  1125. {
  1126. foreach($answer as $k=>$v)
  1127. {
  1128. if(empty($v))
  1129. {
  1130. $status = 1;
  1131. }else
  1132. {
  1133. $exam_answers[$k+1] = $v;
  1134. }
  1135. }
  1136. if($status==1)
  1137. {
  1138. Yii::app()->jump->error('答案尚未设置或未设置完!');
  1139. }
  1140. if($status==0)
  1141. {
  1142. if(false!==ExamGroup::model()->updateAll(array('sheet_answer'=>json_encode($exam_answers)),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id))){
  1143. Yii::app()->jump->success('设置成功!',Yii::app()->createUrl('third/index'));exit;
  1144. };
  1145. }
  1146. }else
  1147. {
  1148. Yii::app()->jump->error('答案尚未设置或未设置完!');
  1149. }
  1150. }
  1151. }
  1152. Yii::app()->jump->error('答案尚未设置或未设置完!');
  1153. }
  1154. public function actionSet_new()
  1155. {
  1156. $exam_group_id = Req::post("exam_group_id");
  1157. if($exam_group_id>0)
  1158. {
  1159. $this->setIs_new($exam_group_id);
  1160. }
  1161. }
  1162. public function actionPaper()
  1163. {
  1164. $exam_group_id = Req::post("exam_group_id");
  1165. if($exam_group_id)
  1166. {
  1167. $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1168. if(!$third_answer_data)
  1169. {
  1170. echo json_encode(array('status'=>-1));exit;
  1171. }
  1172. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1173. if($exam_group_data)
  1174. {
  1175. echo json_encode(array('status'=>1));exit;
  1176. }
  1177. }
  1178. echo json_encode(array('status'=>0));exit;
  1179. }
  1180. public function actionVerify_exam_rs()
  1181. {
  1182. $exam_group_id = Req::post("exam_group_id");
  1183. $exam_ids = array();
  1184. if($exam_group_id>0)
  1185. {
  1186. $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1187. if($exam_data)
  1188. {
  1189. // //验证是否发送任务
  1190. // $task=ATask::model()->findByPk($exam_group_id);
  1191. // if($task && in_array($task->answer_sheet_task,array(1,2))){
  1192. // echo json_encode(array('status'=>4));exit;
  1193. // }
  1194. //验证是否有在线答题卡
  1195. $thirdAnswerSheet=$this->sConn->createCommand("select online_card from third_answer_sheet where exam_group_id='".$exam_group_id."' and online_card=1 ")->queryRow();
  1196. if($thirdAnswerSheet){
  1197. echo json_encode(array('status'=>5));exit;
  1198. }
  1199. foreach($exam_data as $v)
  1200. {
  1201. $exam_ids[$v->exam_id] = $v->exam_id;
  1202. }
  1203. // $criteria = new CDbCriteria();
  1204. // $criteria->addInCondition('exam_id',$exam_ids);
  1205. //
  1206. // $criteria->addNotInCondition('is_labelled', array(0,4));
  1207. // $_paper_data = SPaper::model()->findAll($criteria);
  1208. // if($_paper_data)
  1209. // {
  1210. // echo json_encode(array('status'=>3));exit;
  1211. // }
  1212. }
  1213. echo json_encode(array('status'=>0));exit;
  1214. }else
  1215. {
  1216. echo json_encode(array('status'=>2));exit;
  1217. }
  1218. }
  1219. public function setIs_new($exam_group_id)
  1220. {
  1221. if($exam_group_id)
  1222. {
  1223. Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1224. }
  1225. }
  1226. public function actionSheet()
  1227. {
  1228. $data = array();
  1229. $sname = '';
  1230. $exam_id = Req::get("exam_id");
  1231. $class_id = Req::get("class_id");
  1232. $sname = Req::get("sname");
  1233. $this->setIs_new($exam_id);
  1234. $k = 0;
  1235. $z = 0;
  1236. $x = 0;
  1237. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1238. if($exam_data)
  1239. {
  1240. $data['exam']['exam_id'] = $exam_data->exam_id;
  1241. $data['exam']['name'] = $exam_data->name;
  1242. $tpl_data = json_decode($exam_data->tpl_data,1);
  1243. if(isset($tpl_data['items']))
  1244. {
  1245. foreach($tpl_data['items'] as $key=>$val)
  1246. {
  1247. if(in_array($key,Yii::app()->params['topic_type']['ke']))
  1248. {
  1249. $k += $val['total'];
  1250. }
  1251. if(in_array($key,Yii::app()->params['topic_type']['zu']))
  1252. {
  1253. $z += $val['total'];
  1254. }
  1255. if(in_array($key,Yii::app()->params['topic_type']['xu']))
  1256. {
  1257. $x += $val['total'];
  1258. }
  1259. }
  1260. }
  1261. $data['exam']['name'] = $exam_data->name;
  1262. $data['exam']['topic_type'] = $k.' 客观题,'.$z.' 主观题,'.$x.' 选做题';
  1263. }
  1264. $criteria = new CDbCriteria();
  1265. $criteria->order = 'sheet_id desc';
  1266. if($sname)
  1267. {
  1268. $criteria->addSearchCondition('name',$sname);
  1269. }
  1270. $count = SThirdAnswerSheet::model()->count($criteria);
  1271. $pager = new CPagination($count);
  1272. $pager->pageSize = 10;
  1273. $pager->applyLimit($criteria);
  1274. $classInfo = ClassModel::model()->findByPk($class_id);
  1275. if($classInfo)
  1276. {
  1277. $data['className'] = $classInfo->class_name;
  1278. $data['class_id'] = $classInfo->class_id;
  1279. }else
  1280. {
  1281. $data['className'] = '';
  1282. $data['class_id'] = $class_id;
  1283. }
  1284. $sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
  1285. $data['sheet'] = $sheet_data;
  1286. $data['sname'] = $sname;
  1287. $data['pages'] = $pager;
  1288. $data['pageSize'] = $pager->pageSize;
  1289. $data['rowsCount'] = $count;
  1290. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1291. {
  1292. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1293. }else
  1294. {
  1295. $data["use_zhixue"] = 0;
  1296. }
  1297. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  1298. $data["subject"] = $subject_exam_data;
  1299. $this->render('sheet',$data);
  1300. }
  1301. public function actionBinding()
  1302. {
  1303. $exam_id = Req::post("exam_id");
  1304. $sheet_id = Req::post("sheet_id");
  1305. $exam_ids = array();
  1306. if($sheet_id && $exam_id)
  1307. {
  1308. //验证
  1309. $sheet_data = SThirdAnswerSheet::model()->find('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
  1310. if(!$sheet_data)
  1311. {
  1312. echo json_encode(array('status'=>-1));exit;
  1313. }
  1314. $sheet_score = json_decode($sheet_data->sheet_score,1);
  1315. if(!$sheet_score)
  1316. {
  1317. echo json_encode(array('status'=>-7));exit;
  1318. }
  1319. //验证试卷题量
  1320. $topic_types = array();
  1321. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1322. if($paper_data)
  1323. {
  1324. $paper_topic_data = SPaperTopicRelation::model()->findAll(
  1325. array('order'=>'type asc,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
  1326. if($paper_topic_data)
  1327. {
  1328. foreach($paper_topic_data as $key=> $v)
  1329. {
  1330. if(in_array($v->type,Yii::app()->params['topic_type']['ke'])){
  1331. $topic_types['ke'][$v->topic_id] = $v->topic_id;
  1332. if(isset($sheet_score[$key+1]) && !empty($sheet_score[$key+1]))
  1333. {
  1334. if($v->score != $sheet_score[$key+1])
  1335. {
  1336. echo json_encode(array('status'=>-6));exit;
  1337. }
  1338. }
  1339. }
  1340. if(in_array($v->type,Yii::app()->params['topic_type']['zu'])){
  1341. $topic_types['zu'][$v->topic_id] = $v->topic_id;
  1342. }
  1343. if(in_array($v->type,Yii::app()->params['topic_type']['xu'])){
  1344. $topic_types['xu'][$v->topic_id] = $v->topic_id;
  1345. }
  1346. }
  1347. if(isset($topic_types['ke'])&&(count($topic_types['ke'])!=$sheet_data->ke_topic_num))
  1348. {
  1349. echo json_encode(array('status'=>-4));exit;
  1350. }
  1351. if(!isset($topic_types['ke']) && $sheet_data->ke_topic_num>0)
  1352. {
  1353. echo json_encode(array('status'=>-4));exit;
  1354. }
  1355. if(isset($topic_types['zu'])&&(count($topic_types['zu'])!=$sheet_data->zu_topic_num))
  1356. {
  1357. echo json_encode(array('status'=>-4));exit;
  1358. }
  1359. if(!isset($topic_types['zu']) && $sheet_data->zu_topic_num>0)
  1360. {
  1361. echo json_encode(array('status'=>-4));exit;
  1362. }
  1363. if(isset($topic_types['xu'])&&(count($topic_types['xu'])!=$sheet_data->xuan_topic_num))
  1364. {
  1365. echo json_encode(array('status'=>-4));exit;
  1366. }
  1367. if(!isset($topic_types['xu']) && $sheet_data->xuan_topic_num>0)
  1368. {
  1369. echo json_encode(array('status'=>-4));exit;
  1370. }
  1371. }else{
  1372. echo json_encode(array('status'=>-8));exit;
  1373. }
  1374. }
  1375. /**
  1376. * 获取同一次考试
  1377. */
  1378. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  1379. if($exam_data)
  1380. {
  1381. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  1382. if($exam_group_data)
  1383. {
  1384. foreach($exam_group_data as $v)
  1385. {
  1386. $exam_ids[$v->exam_id] = $v->exam_id;
  1387. }
  1388. if($exam_ids)
  1389. {
  1390. $transaction = $this->sConn->beginTransaction();
  1391. try{
  1392. $criteria = new CDbCriteria();
  1393. $criteria->addInCondition('exam_id',$exam_ids);
  1394. $criteria->addCondition('status=:status');
  1395. $criteria->params[':status'] = 1;
  1396. SExamAnswerSheet::model()->deleteAll($criteria);
  1397. unset($criteria);
  1398. $sql='INSERT INTO `exam_third_answer_sheet_relation`
  1399. (`sheet_id`,`exam_id`,`status`,`create_time`)VALUES';
  1400. foreach($exam_ids as $e_id)
  1401. {
  1402. $sql.='('.$sheet_id.','.$e_id.',1,'.time().'),';
  1403. }
  1404. $sql = substr($sql,0,-1);
  1405. $this->sConn->createCommand($sql)->execute();
  1406. $criteria = new CDbCriteria();
  1407. $criteria->addInCondition('exam_id',$exam_ids);
  1408. Exam::model()->updateAll(array('sheet_answer'=>$sheet_data->sheet_answer,'sheet_score'=>$sheet_data->sheet_score),$criteria);
  1409. $transaction->commit();
  1410. }catch(Exception $e)
  1411. {
  1412. $transaction->rollBack();
  1413. echo json_encode(array('status'=>0));exit;
  1414. }
  1415. echo json_encode(array('status'=>1));exit;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. echo json_encode(array('status'=>0));exit;
  1421. }
  1422. public function actionDel()
  1423. {
  1424. $sheet_id = Req::post("sheet_id");
  1425. if($sheet_id)
  1426. {
  1427. SThirdAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
  1428. SExamAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
  1429. }
  1430. echo json_encode(array('status'=>1));
  1431. }
  1432. public function actionThirdview()
  1433. {
  1434. //判断教材设置
  1435. if(!Yii::app()->params['school_textbook_setting'] ){
  1436. Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!');
  1437. }
  1438. $schoolTextBookSet=Yii::app()->params['school_textbook_setting'];
  1439. $data = array();
  1440. $printType = Req::get("type");
  1441. $criteria = new CDbCriteria();
  1442. if(Yii::app()->session['session_duoxueke_subject_id']==3)
  1443. {
  1444. $criteria->addInCondition('subjects',$this->mathSubjectId);
  1445. }else
  1446. {
  1447. $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
  1448. }
  1449. $criteria->addCondition('status = 0');
  1450. $teacher_data = Teacher::model()->findAll($criteria);
  1451. unset($criteria);
  1452. $teacher_arr = array();
  1453. if($teacher_data){
  1454. $i = 0;
  1455. foreach($teacher_data as $v){
  1456. $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
  1457. $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
  1458. $i++;
  1459. }
  1460. }
  1461. $data['teacher_arr'] = $teacher_arr;
  1462. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1463. {
  1464. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1465. }else
  1466. {
  1467. $data["use_zhixue"] = 0;
  1468. }
  1469. //判断全学科试用学校
  1470. // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi');
  1471. // $rs=json_decode($rs,true);
  1472. // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  1473. // $data['is_qxk']=1;
  1474. // }else{
  1475. // $data['is_qxk']=0;
  1476. // }
  1477. $data['is_qxk']=1;
  1478. $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用',51=>'新高一高二');
  1479. $textbookArr=array();
  1480. foreach ($schoolTextBookSet as $val){
  1481. //表里有2个版本的教材,此处过滤掉不属于当前版本的教材
  1482. if($data['is_qxk']!=$val['is_qxk']){
  1483. continue;
  1484. }
  1485. $textBookName='';
  1486. if(isset($this->textBookType[$val['subject_id']][$val['textbook_id']])){
  1487. $textBookName=$this->textBookType[$val['subject_id']][$val['textbook_id']];
  1488. }
  1489. $textbookArr[$val['grade']]=array(
  1490. 'grade_id'=>$val['grade'],
  1491. 'subject_id'=>$val['subject_id'],
  1492. 'textbook_id'=>$val['textbook_id'],
  1493. 'subject_name'=>$teacherSubjectNames[$val['subject_id']],
  1494. 'text_book_name'=>$textBookName
  1495. );
  1496. }
  1497. if(!isset($textbookArr[1]) || !isset($textbookArr[2])){
  1498. Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!');
  1499. }
  1500. $data['textbookArr'] = $textbookArr;
  1501. $data['version_number']=$this->version_number;
  1502. $this->render('thirdview',$data);
  1503. }
  1504. public function actionThirdview_duo()
  1505. {
  1506. $data = array();
  1507. $printType = Req::get("type");
  1508. if (empty($printType)) {
  1509. $printType = '2';
  1510. $printTypeData = 0;
  1511. } else {
  1512. switch ($printType) {
  1513. case "2":
  1514. $printTypeData = 0;
  1515. break;
  1516. case "wtb":
  1517. $printTypeData = 1;
  1518. break;
  1519. case "isp":
  1520. $printTypeData = 2;
  1521. break;
  1522. case "studytrend":
  1523. $printTypeData = 3;
  1524. break;
  1525. default:
  1526. $printTypeData = null;
  1527. break;
  1528. }
  1529. }
  1530. $data['printType'] = $printType;
  1531. // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
  1532. // $semester_id = Yii::app()->session['session_semester_id'];
  1533. $coach_id = $this->coachId;
  1534. $semester_id = $this->semesterId;
  1535. // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
  1536. $criteria = new CDbCriteria();
  1537. if(Yii::app()->session['session_duoxueke_subject_id']==3)
  1538. {
  1539. $criteria->addInCondition('subjects',$this->mathSubjectId);
  1540. }else
  1541. {
  1542. if(Yii::app()->session['session_duoxueke_subject_id']==18){
  1543. $criteria->addInCondition('subjects',array(12,13,14));
  1544. }
  1545. if(Yii::app()->session['session_duoxueke_subject_id']==19){
  1546. $criteria->addInCondition('subjects',array(15,16,17));
  1547. }
  1548. if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
  1549. $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
  1550. }
  1551. }
  1552. $criteria->addCondition('status = 0');
  1553. $teacher_data = Teacher::model()->findAll($criteria);
  1554. unset($criteria);
  1555. $teacher_arr = array();
  1556. if($teacher_data){
  1557. $i = 0;
  1558. foreach($teacher_data as $v){
  1559. $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
  1560. $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
  1561. $i++;
  1562. }
  1563. }
  1564. $data['teacher_arr'] = $teacher_arr;
  1565. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1566. {
  1567. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1568. }else
  1569. {
  1570. $data["use_zhixue"] = 0;
  1571. }
  1572. $teacherSubjectIds = array(3, 6);
  1573. $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
  1574. $teacherSubjectMaterialIds = array();
  1575. $teacherSubjectMaterialNames = array();
  1576. foreach ($teacherSubjectIds as $teacherSubjectId) {
  1577. $teacherSubjectMaterialIds[$teacherSubjectId] = array();
  1578. $teacherSubjectMaterialNames[$teacherSubjectId] = array();
  1579. $textbookTree = $this->apiPost('/textbook/tree', array(
  1580. 'subjectId' => $teacherSubjectId,
  1581. 'depth' => 3
  1582. ));
  1583. if (! $textbookTree) {
  1584. $error[] = 'Brain textbook/tree error';
  1585. } elseif (isset($textbookTree->error)) {
  1586. $error[] = $textbookTree->error;
  1587. } else {
  1588. foreach ($textbookTree as $textbook) {
  1589. if (isset($textbook->modules)) {
  1590. foreach ($textbook->modules as $module) {
  1591. if (isset($module->chapters)) {
  1592. $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
  1593. $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. //
  1601. $criteria = new CDbCriteria();
  1602. $criteria->addCondition('subject_id=:subject_id');
  1603. $criteria->addCondition('school_card_length=0');
  1604. $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
  1605. $criteria->order = 'third_tpl_id desc';
  1606. $criteria->limit = 5;
  1607. $thisTpls = SThirdTplModel::model()->findAll($criteria);
  1608. // debug($thisTpls);
  1609. if($thisTpls)
  1610. {
  1611. $data['thisTpls'] = $thisTpls;
  1612. }
  1613. $data['teacherSubjectIds'] = $teacherSubjectIds;
  1614. $data['teacherSubjectNames'] = $teacherSubjectNames;
  1615. $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
  1616. $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
  1617. $data['version_number']=$this->version_number;
  1618. //判断全学科试用学校
  1619. // $rs = http('/teacher/paper/word-group/can-use-new/','POST',$this->schoolId,array(),'cgi',array('schoolId:'.$this->schoolId));
  1620. //
  1621. // $rs=json_decode($rs,true);
  1622. // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  1623. // $data['is_qxk']=1;
  1624. // }else{
  1625. // $data['is_qxk']=0;
  1626. // }
  1627. $data['is_qxk']=1;
  1628. // echo Yii::app()->params['zsy_api_url'].'<br>';
  1629. // echo json_encode($rs).'<br>';
  1630. // echo $data['is_qxk'];
  1631. $this->render('thirdview1',$data);
  1632. }
  1633. public function actionThirdview_section()
  1634. {
  1635. $data = array();
  1636. //读取全学科教材
  1637. $postRs = $this->apiPost('/all_textbook/tree', array(
  1638. 'subjectId' => Yii::app()->session['session_duoxueke_subject_id'],
  1639. ));
  1640. $textbookTree=array();
  1641. if(isset($postRs->status) && $postRs->status==1 && $postRs->data ){
  1642. foreach ($postRs->data as $val){
  1643. if($val->level==1){
  1644. $textbookTree[]=array(
  1645. 'textbook_id'=>$val->textbook_id,
  1646. 'textbook_name'=>$val->textbook_name,
  1647. );
  1648. }
  1649. }
  1650. }
  1651. $criteria = new CDbCriteria();
  1652. $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
  1653. $criteria->addCondition('status = 0');
  1654. $teacher_data = Teacher::model()->findAll($criteria);
  1655. unset($criteria);
  1656. $teacher_arr = array();
  1657. if($teacher_data){
  1658. $i = 0;
  1659. foreach($teacher_data as $v){
  1660. $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
  1661. $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
  1662. $i++;
  1663. }
  1664. }
  1665. $data['teacher_arr'] = $teacher_arr;
  1666. $data['textbookTree']=$textbookTree;
  1667. $this->render('thirdview_section',$data);
  1668. }
  1669. public function actionThirdview_under_line()
  1670. {
  1671. $data = array();
  1672. $printType = Req::get("type");
  1673. if (empty($printType)) {
  1674. $printType = '2';
  1675. $printTypeData = 0;
  1676. } else {
  1677. switch ($printType) {
  1678. case "2":
  1679. $printTypeData = 0;
  1680. break;
  1681. case "wtb":
  1682. $printTypeData = 1;
  1683. break;
  1684. case "isp":
  1685. $printTypeData = 2;
  1686. break;
  1687. case "studytrend":
  1688. $printTypeData = 3;
  1689. break;
  1690. default:
  1691. $printTypeData = null;
  1692. break;
  1693. }
  1694. }
  1695. $data['printType'] = $printType;
  1696. // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
  1697. // $semester_id = Yii::app()->session['session_semester_id'];
  1698. $coach_id = $this->coachId;
  1699. $semester_id = $this->semesterId;
  1700. // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
  1701. $criteria = new CDbCriteria();
  1702. if(Yii::app()->session['session_duoxueke_subject_id']==3)
  1703. {
  1704. $criteria->addInCondition('subjects',$this->mathSubjectId);
  1705. }else
  1706. {
  1707. if(Yii::app()->session['session_duoxueke_subject_id']==18){
  1708. $criteria->addInCondition('subjects',array(12,13,14));
  1709. }
  1710. if(Yii::app()->session['session_duoxueke_subject_id']==19){
  1711. $criteria->addInCondition('subjects',array(15,16,17));
  1712. }
  1713. if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
  1714. $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
  1715. }
  1716. }
  1717. $criteria->addCondition('status = 0');
  1718. $teacher_data = Teacher::model()->findAll($criteria);
  1719. unset($criteria);
  1720. $teacher_arr = array();
  1721. if($teacher_data){
  1722. $i = 0;
  1723. foreach($teacher_data as $v){
  1724. $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
  1725. $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
  1726. $i++;
  1727. }
  1728. }
  1729. $data['teacher_arr'] = $teacher_arr;
  1730. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1731. {
  1732. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1733. }else
  1734. {
  1735. $data["use_zhixue"] = 0;
  1736. }
  1737. $teacherSubjectIds = array(3, 6);
  1738. $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
  1739. $teacherSubjectMaterialIds = array();
  1740. $teacherSubjectMaterialNames = array();
  1741. foreach ($teacherSubjectIds as $teacherSubjectId) {
  1742. $teacherSubjectMaterialIds[$teacherSubjectId] = array();
  1743. $teacherSubjectMaterialNames[$teacherSubjectId] = array();
  1744. $textbookTree = $this->apiPost('/textbook/tree', array(
  1745. 'subjectId' => $teacherSubjectId,
  1746. 'depth' => 3
  1747. ));
  1748. if (! $textbookTree) {
  1749. $error[] = 'Brain textbook/tree error';
  1750. } elseif (isset($textbookTree->error)) {
  1751. $error[] = $textbookTree->error;
  1752. } else {
  1753. foreach ($textbookTree as $textbook) {
  1754. if (isset($textbook->modules)) {
  1755. foreach ($textbook->modules as $module) {
  1756. if (isset($module->chapters)) {
  1757. $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
  1758. $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. //
  1766. $criteria = new CDbCriteria();
  1767. $criteria->addCondition('subject_id=:subject_id');
  1768. $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
  1769. $criteria->order = 'third_tpl_id desc';
  1770. $criteria->limit = 5;
  1771. $thisTpls = SThirdTplModel::model()->findAll($criteria);
  1772. if($thisTpls)
  1773. {
  1774. $data['thisTpls'] = $thisTpls;
  1775. }
  1776. $data['teacherSubjectIds'] = $teacherSubjectIds;
  1777. $data['teacherSubjectNames'] = $teacherSubjectNames;
  1778. $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
  1779. $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
  1780. $this->render('thirdview_under_line',$data);
  1781. }
  1782. public function actionUpdateThirdTpl(){
  1783. $error = array();
  1784. $tplData = array();
  1785. $tpl_title = Req::post("tpl_title");
  1786. $third_tpl_id = Req::post("third_tpl_id");
  1787. $classIds = Req::post("classIds");
  1788. $teacherId = Req::post("teacherId");
  1789. $subjectId = Req::post("subjectId");
  1790. $textbookId = Req::post("textbookId");
  1791. $topic = $_POST["topic"];
  1792. $layout = Req::post("layout");
  1793. $select_card_type = Req::post("select_card_type");
  1794. if(empty($classIds)){
  1795. $error[] = '请指定考试班级';
  1796. }else{
  1797. $classIds = explode(',',substr($classIds,0,-1));
  1798. }
  1799. if(empty($tpl_title)){
  1800. $error[] = '请设置答题卡名称';
  1801. }
  1802. if(empty($subjectId)){
  1803. $error[] = '请选择题源';
  1804. }
  1805. if(empty($teacherId)){
  1806. $error[] = '请指定阅卷老师';
  1807. }
  1808. if(empty($topic)){
  1809. $error[] = '请设置题型';
  1810. }
  1811. if(empty($layout)){
  1812. $error[] = '答题卡类型';
  1813. }
  1814. if($error){
  1815. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  1816. }else{
  1817. $card_status = 0;
  1818. $school_card_length = 8;
  1819. if($this->schoolId>999){
  1820. $school_card_length = 9;
  1821. }
  1822. $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") ";
  1823. $cardData = $this->sConn->createCommand($sql)->queryRow();
  1824. if(!$cardData){
  1825. $error[] = '无法找到对应班级';
  1826. }
  1827. if($cardData['card_status']){
  1828. $school_card_length = (int)$cardData['card_length'];
  1829. $card_status = (int)$cardData['card_status'];
  1830. }
  1831. // $rs = $this->sConn->createCommand()->insert('third_tpl',array(
  1832. // 'title' => $tpl_title,
  1833. // 'subject_id' => $subjectId,
  1834. // 'school_card_status' => $card_status,
  1835. // 'school_card_length' => $school_card_length,
  1836. // 'layout' => $layout,
  1837. // 'select_card_type' => $select_card_type,
  1838. // 'tpl_data' => $topic,
  1839. // 'create_time' => time()
  1840. // ));
  1841. $rs = SThirdTplModel::model()->updateAll(array(
  1842. 'title' => $tpl_title,
  1843. 'subject_id' => $subjectId,
  1844. 'school_card_status' => $card_status,
  1845. 'school_card_length' => $school_card_length,
  1846. 'layout' => $layout,
  1847. 'select_card_type' => $select_card_type,
  1848. 'tpl_data' => $topic
  1849. ),'third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
  1850. $_layout = array(10=>'A4竖版',11=>'A4横版','20'=>'A3竖版','21'=>'A3三栏','31'=>'A3两栏','40'=>'8K(260*370)两栏','41'=>'8K(260*370)三栏','50'=>'8K(270*390)两栏','51'=>'8K(270*390)三栏');
  1851. $_select_card_type = array(1=>'准考证号',2=>'条形码');
  1852. if($rs !==false){
  1853. echo json_encode(array('status'=>1,'msg'=>'保存成功','result'=>array('third_tpl_id'=>$third_tpl_id,'title'=>$tpl_title,'layout'=>$_layout[$layout],'select_card_type'=>$_select_card_type[$select_card_type])));exit;
  1854. }
  1855. }
  1856. echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit;
  1857. }
  1858. public function actionDelThirdTpl(){
  1859. $third_tpl_id = Req::post("third_tpl_id");
  1860. if($third_tpl_id>0){
  1861. $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
  1862. if($thirdTpl){
  1863. echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit;
  1864. }
  1865. }
  1866. echo json_encode(array('status'=>0,'msg'=>'失败'));exit;
  1867. }
  1868. public function actionGetThirdTpl(){
  1869. $third_tpl_id = Req::post("third_tpl_id");
  1870. if($third_tpl_id>0){
  1871. $thirdTpl = SThirdTplModel::model()->find('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id))->attributes;
  1872. if($thirdTpl){
  1873. echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit;
  1874. }
  1875. }
  1876. echo json_encode(array('status'=>0,'msg'=>'失败'));exit;
  1877. }
  1878. public function actionAjaxchangeclasses()
  1879. {
  1880. $subject_id=$this->subjectId;
  1881. if(isset(Yii::app()->session['session_duoxueke_subject_id'])){
  1882. $subject_id=Yii::app()->session['session_duoxueke_subject_id'];
  1883. }
  1884. //读取走班设置
  1885. $classified=array();
  1886. $setting=$this->schoolManager->getClassShift($this->semesterId,$subject_id);
  1887. if($setting){
  1888. foreach ($setting as $value){
  1889. $classified[$value['grade']]=$value['status'];
  1890. }
  1891. }
  1892. $result = array();
  1893. $error = array();
  1894. if (Yii::app()->request->getIsPostRequest()){
  1895. $teacher_id = Req::post("teacher_id");
  1896. $selectedClassId=Req::post('selectedClassId');
  1897. if(empty($teacher_id)){
  1898. $error[] = "请指定教师";
  1899. }else{
  1900. $semester_id = $this->semesterId;
  1901. if($selectedClassId){
  1902. $anotherSelectClass=ClassModel ::model()->getClassArrayByIds($selectedClassId);
  1903. $i = 0;
  1904. if($anotherSelectClass){
  1905. foreach ($anotherSelectClass as $cas){
  1906. $class_arr_select[$i]['class_id'] = $cas['class_id'];
  1907. $class_arr_select[$i]['class_name'] = $cas['class_name'];
  1908. $class_arr_select[$i]['grade'] = $cas['grade'];
  1909. $i++;
  1910. $class_arr_select_ids[] = $cas['class_id'];
  1911. }
  1912. }
  1913. }else{
  1914. $class_arr_select_data = ClassModel ::model()->getSelectclassesByTeacher($semester_id,$teacher_id);
  1915. $class_arr_select =array();
  1916. $class_arr_select_ids = array();
  1917. $i = 0;
  1918. if($class_arr_select_data){
  1919. foreach($class_arr_select_data as $cas){
  1920. if(isset($classified[$cas->grade]) && $classified[$cas->grade]==1){
  1921. if($cas->class_type==2){
  1922. //判断学科
  1923. if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cas->class_id)){
  1924. continue;
  1925. }
  1926. $class_arr_select[$i]['class_id'] = $cas->class_id;
  1927. $class_arr_select[$i]['class_name'] = $cas->class_name;
  1928. $class_arr_select[$i]['grade'] = $cas->grade;
  1929. $i++;
  1930. $class_arr_select_ids[] = $cas->class_id;
  1931. }
  1932. }else{
  1933. if($cas->class_type==1){
  1934. $class_arr_select[$i]['class_id'] = $cas->class_id;
  1935. $class_arr_select[$i]['class_name'] = $cas->class_name;
  1936. $class_arr_select[$i]['grade'] = $cas->grade;
  1937. $i++;
  1938. $class_arr_select_ids[] = $cas->class_id;
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. $class_arr_select_ids_str = "";
  1945. if($class_arr_select_ids){
  1946. foreach($class_arr_select_ids as $v){
  1947. $class_arr_select_ids_str.=$v.",";
  1948. }
  1949. $class_arr_select_ids_str=substr($class_arr_select_ids_str,0,-1);
  1950. }
  1951. $class_arr_noselect_data = ClassModel ::model()->getNoSelectclassesByTeacher($semester_id,$teacher_id,$class_arr_select_ids_str);
  1952. $class_arr_noselect =array();
  1953. $j = 0;
  1954. if($class_arr_noselect_data){
  1955. foreach($class_arr_noselect_data as $cans){
  1956. if(isset($classified[$cans->grade]) && $classified[$cans->grade]==1){
  1957. if($cans->class_type==2){
  1958. //判断学科
  1959. if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cans->class_id)){
  1960. continue;
  1961. }
  1962. $class_arr_noselect[$j]['class_id'] = $cans->class_id;
  1963. $class_arr_noselect[$j]['class_name'] = $cans->class_name;
  1964. $class_arr_noselect[$j]['grade'] = $cans->grade;
  1965. $j++;
  1966. }
  1967. }else{
  1968. if($cans->class_type==1){
  1969. $class_arr_noselect[$j]['class_id'] = $cans->class_id;
  1970. $class_arr_noselect[$j]['class_name'] = $cans->class_name;
  1971. $class_arr_noselect[$j]['grade'] = $cans->grade;
  1972. $j++;
  1973. }
  1974. }
  1975. }
  1976. }
  1977. $result['class_arr_select'] = $class_arr_select;
  1978. $result['class_arr_noselect'] = $class_arr_noselect;
  1979. }
  1980. }else{
  1981. $error[] = "错误的来源";
  1982. }
  1983. header('Content-Type: application/json');
  1984. if($error){
  1985. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));exit;
  1986. }else{
  1987. echo json_encode($result);exit;
  1988. }
  1989. }
  1990. public function UUID_SHORT($length = 20)
  1991. {
  1992. $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
  1993. $result = $query['UUID_SHORT'];
  1994. if ($length AND is_int($length))
  1995. {
  1996. $result = substr($result, ($length * -1));
  1997. }
  1998. return $result;
  1999. }
  2000. public function actionCreatethird(){
  2001. $error = array();
  2002. $tplData = array();
  2003. $semesterId = $this->semesterId;
  2004. $examName = Req::post("examName");
  2005. $type = (int)Req::post("type");
  2006. $classIds = Req::post("classIds");
  2007. $markType = Req::post("markType");
  2008. $teacherId = Req::post("teacherId");
  2009. $subjectId = Req::post("subjectId");
  2010. $textbookId = Req::post("textbookId");
  2011. $examDate = Req::post("examDate");
  2012. $tpl_index = (int)Req::post("tpl_index");
  2013. if(empty($classIds)){
  2014. $error[] = '请指定考试班级';
  2015. }else{
  2016. $classIds = explode(',',substr($classIds,0,-1));
  2017. }
  2018. if(empty($examName)){
  2019. $error[] = '请设置考试名称';
  2020. }
  2021. if ($type <= 0 || $type > 9) {
  2022. $error[] = '考试类型错误';
  2023. }
  2024. if(empty($subjectId)){
  2025. $error[] = '请选择题源';
  2026. }
  2027. if(empty($teacherId)){
  2028. $error[] = '请指定阅卷老师';
  2029. }
  2030. if(empty($examDate)){
  2031. $error[] = '请指定考试时间';
  2032. }
  2033. if(empty($tpl_index)){
  2034. $error[] = '请指定类型';
  2035. }
  2036. if(empty($textbookId)){
  2037. $error[] = '请指定教材';
  2038. }
  2039. if($error){
  2040. Yii::app()->jump->error(implode(',',$error));
  2041. }else{
  2042. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  2043. if($teacherName){
  2044. $tplData['author'] = $teacherName;
  2045. $tplData['subjectId'] = $subjectId;
  2046. $tplData['textbookId'] = $textbookId;
  2047. $tplData['examDate'] = $examDate;
  2048. }
  2049. $time = time();
  2050. $transaction = $this->sConn->beginTransaction();
  2051. try{
  2052. // $newExamGroupId = $this->UUID_SHORT();
  2053. $newExamGroupId=getUniqueId($this->schoolId);
  2054. if($markType ==4)
  2055. {
  2056. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
  2057. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
  2058. }else
  2059. {
  2060. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
  2061. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
  2062. }
  2063. $this->sConn->createCommand($sql)->execute();
  2064. foreach($classIds as $classId){
  2065. //$newExamId = $this->UUID_SHORT();
  2066. $newExamId = getUniqueId($this->schoolId);
  2067. $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
  2068. $cardData = $this->sConn->createCommand($sql)->queryRow();
  2069. if($cardData['card_status']==0){
  2070. $cardData['card_length'] = 8;
  2071. if($this->schoolId >999){
  2072. $cardData['card_length'] = 9;
  2073. }
  2074. }
  2075. $class_type=$cardData['class_type'];
  2076. $this->sConn->createCommand()->insert('exam',array(
  2077. 'exam_id' => $newExamId,
  2078. 'exam_group_id' => $newExamGroupId,
  2079. 'name' => $examName,
  2080. 'semester_id' => $this->semesterId,
  2081. 'teacher_id' => $teacherId,
  2082. 'subject_id' => $subjectId,
  2083. 'module_id' => 0,
  2084. 'type' => $type,
  2085. 'school_card_status' => $cardData['card_status'],
  2086. 'school_card_length' => $cardData['card_length'],
  2087. 'status' => 2,
  2088. 'week_num' => 0,
  2089. 'create_type' => 0,
  2090. 'create_time' => $time,
  2091. 'update_time' => $time,
  2092. 'tpl_data' => jsonEncode($tplData),
  2093. 'tpl_index' => $tpl_index,
  2094. 'class_id' => $classId,
  2095. 'method_ids' => '',
  2096. ));
  2097. // $newPaperId = $this->UUID_SHORT();
  2098. $newPaperId= getUniqueId($this->schoolId);
  2099. $this->sConn->createCommand()->insert('paper', array(
  2100. 'paper_id' => $newPaperId,
  2101. 'paper_type' => 1,
  2102. 'exam_id' => $newExamId,
  2103. 'paper_name' => '',
  2104. 'paper_layer' => '',
  2105. 'difficulty' => 0,
  2106. 'topics_count' => 0,
  2107. 'score' => 0,
  2108. 'add_time' => $time,
  2109. 'update_time' => $time,
  2110. 'method_ids' => '',
  2111. 'is_labelled' => 0,
  2112. ));
  2113. $this->sConn->createCommand()->insert('class_exam_printer', array(
  2114. 'class_id' => $classId,
  2115. 'exam_id' => $newExamId,
  2116. 'type' => 0,
  2117. 'is_print' => 0,
  2118. 'print_time' => 0,
  2119. 'add_time' => $time,
  2120. ));
  2121. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  2122. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  2123. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  2124. if($studentIds_0){
  2125. foreach ($studentIds_0 as $studentId) {
  2126. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  2127. // if($studentIds){
  2128. // foreach ($studentIds as $studentId) {
  2129. $this->sConn->createCommand()->insert('student_paper_relation', array(
  2130. 'student_id' => $studentId,
  2131. 'paper_id' => $newPaperId,
  2132. 'exam_id' => $newExamId,
  2133. 'semester_id' => $this->semesterId,
  2134. 'class_id' => $classId,
  2135. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  2136. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  2137. 'class_type' =>$class_type
  2138. ));
  2139. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  2140. 'student_id' => $studentId,
  2141. 'paper_id' => $newPaperId,
  2142. 'exam_id' => $newExamId,
  2143. 'semester_id' => $this->semesterId,
  2144. 'class_id' => $classId,
  2145. 'create_time' =>$time
  2146. ));
  2147. }
  2148. }
  2149. }
  2150. $transaction->commit();
  2151. }catch(Exception $e){
  2152. $transaction->rollBack();
  2153. if (YII_ENV == 'production') {
  2154. $error[] = '系统错误[SQL]';
  2155. } else {
  2156. $error[] = $e->getMessage();
  2157. }
  2158. }
  2159. }
  2160. if(!$error){
  2161. $this->redirect($this->createUrl('third/index'));
  2162. }
  2163. }
  2164. public function actionQuanCreatethird(){
  2165. $error = array();
  2166. $tplData = array();
  2167. $semesterId = $this->semesterId;
  2168. $examName = Req::post("examName");
  2169. $type = (int)Req::post("type");
  2170. $classIds = Req::post("classIds");
  2171. $markType = Req::post("markType");
  2172. $paperType = (int)Req::post("paperType");
  2173. $teacherId = Req::post("teacherId");
  2174. $subjectId = Req::post("subjectId");
  2175. $textbookId = Req::post("textbookId");
  2176. $examDate = Req::post("examDate");
  2177. $qxkPaperId = (int)Req::post("isQxk");
  2178. // $tpl_index = (int)Req::post("tpl_index");
  2179. $tpl_index = $paperType;
  2180. if(empty($classIds)){
  2181. $error[] = '请指定考试班级';
  2182. }else{
  2183. $classIds = explode(',',substr($classIds,0,-1));
  2184. }
  2185. if(empty($examName)){
  2186. $error[] = '请设置考试名称';
  2187. }
  2188. if ($type <= 0 || $type > 9) {
  2189. $error[] = '考试类型错误';
  2190. }
  2191. if(empty($subjectId)){
  2192. $error[] = '请选择题源';
  2193. }
  2194. if(!matchStrChar($examName)){
  2195. $error[] = '考试名称不能包含特殊字符';
  2196. }
  2197. if(!in_array($paperType,array(0,1,2,1050))){
  2198. $error[] = '请选择正确的试卷类型';
  2199. }
  2200. if(empty($teacherId)){
  2201. $error[] = '请指定阅卷老师';
  2202. }
  2203. if(empty($examDate)){
  2204. $error[] = '请指定考试时间';
  2205. }
  2206. // if(empty($tpl_index)){
  2207. // $error[] = '请指定类型';
  2208. // }
  2209. if($error){
  2210. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  2211. }else{
  2212. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  2213. if($teacherName){
  2214. $tplData['author'] = $teacherName;
  2215. $tplData['subjectId'] = $subjectId;
  2216. $tplData['textbookId'] = $textbookId;
  2217. $tplData['examDate'] = $examDate;
  2218. }
  2219. $time = time();
  2220. $transaction = $this->sConn->beginTransaction();
  2221. try{
  2222. //$newExamGroupId = $this->UUID_SHORT();
  2223. $newExamGroupId=getUniqueId($this->schoolId);
  2224. if($markType ==4){
  2225. $markStatus=1;
  2226. $status=1;
  2227. }else{
  2228. $markStatus=0;
  2229. $status=0;
  2230. }
  2231. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`,`qxk_paper_id`) "
  2232. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")";
  2233. $this->sConn->createCommand($sql)->execute();
  2234. foreach($classIds as $classId){
  2235. //$newExamId = $this->UUID_SHORT();
  2236. $newExamId=getUniqueId($this->schoolId);
  2237. $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
  2238. $cardData = $this->sConn->createCommand($sql)->queryRow();
  2239. if($cardData['card_status']==0){
  2240. $cardData['card_length'] = 8;
  2241. if($this->schoolId >999){
  2242. $cardData['card_length'] = 9;
  2243. }
  2244. }
  2245. $class_type=$cardData['class_type'];
  2246. $this->sConn->createCommand()->insert('exam',array(
  2247. 'exam_id' => $newExamId,
  2248. 'exam_group_id' => $newExamGroupId,
  2249. 'name' => $examName,
  2250. 'semester_id' => $this->semesterId,
  2251. 'teacher_id' => $teacherId,
  2252. 'subject_id' => $subjectId,
  2253. 'module_id' => 0,
  2254. 'type' => $type,
  2255. 'school_card_status' => $cardData['card_status'],
  2256. 'school_card_length' => $cardData['card_length'],
  2257. 'status' => 2,
  2258. 'week_num' => 0,
  2259. 'create_type' => 0,
  2260. 'create_time' => $time,
  2261. 'update_time' => $time,
  2262. 'tpl_data' => jsonEncode($tplData),
  2263. 'tpl_index' => $tpl_index,
  2264. 'class_id' => $classId,
  2265. 'method_ids' => '',
  2266. ));
  2267. //$newPaperId = $this->UUID_SHORT();
  2268. $newPaperId = getUniqueId($this->schoolId);
  2269. $this->sConn->createCommand()->insert('paper', array(
  2270. 'paper_id' => $newPaperId,
  2271. 'paper_type' => 1,
  2272. 'exam_id' => $newExamId,
  2273. 'paper_name' => '',
  2274. 'paper_layer' => '',
  2275. 'difficulty' => 0,
  2276. 'topics_count' => 0,
  2277. 'score' => 0,
  2278. 'add_time' => $time,
  2279. 'update_time' => $time,
  2280. 'method_ids' => '',
  2281. 'is_labelled' => 0,
  2282. ));
  2283. $this->sConn->createCommand()->insert('class_exam_printer', array(
  2284. 'class_id' => $classId,
  2285. 'exam_id' => $newExamId,
  2286. 'type' => 0,
  2287. 'is_print' => 0,
  2288. 'print_time' => 0,
  2289. 'add_time' => $time,
  2290. ));
  2291. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  2292. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  2293. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  2294. if($studentIds_0){
  2295. foreach ($studentIds_0 as $studentId) {
  2296. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  2297. // if($studentIds){
  2298. // foreach ($studentIds as $studentId) {
  2299. $this->sConn->createCommand()->insert('student_paper_relation', array(
  2300. 'student_id' => $studentId,
  2301. 'paper_id' => $newPaperId,
  2302. 'exam_id' => $newExamId,
  2303. 'semester_id' => $this->semesterId,
  2304. 'class_id' => $classId,
  2305. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  2306. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  2307. 'class_type' =>$class_type
  2308. ));
  2309. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  2310. 'student_id' => $studentId,
  2311. 'paper_id' => $newPaperId,
  2312. 'exam_id' => $newExamId,
  2313. 'semester_id' => $this->semesterId,
  2314. 'class_id' => $classId,
  2315. 'create_time' =>$time
  2316. ));
  2317. }
  2318. }
  2319. }
  2320. $transaction->commit();
  2321. }catch(Exception $e){
  2322. $transaction->rollBack();
  2323. echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
  2324. }
  2325. }
  2326. if(!$error){
  2327. echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
  2328. }
  2329. }
  2330. public function actionAjaxCreatethird()
  2331. {
  2332. $error = array();
  2333. $tplData = array();
  2334. $semesterId = $this->semesterId;
  2335. $examName = Req::post("examName");
  2336. $type = (int)Req::post("type");
  2337. $classIds = Req::post("classIds");
  2338. $markType = Req::post("markType");
  2339. $teacherId = Req::post("teacherId");
  2340. $subjectId = Req::post("subjectId");
  2341. $textbookId = Req::post("textbookId");
  2342. $is_update = Req::post("is_update");
  2343. $examDate = Req::post("examDate");
  2344. $tpl_index = (int)Req::post("tpl_index");
  2345. $topic = $_POST["topic"];
  2346. $layout = Req::post("layout");
  2347. $select_card_type = Req::post("select_card_type");
  2348. $json = array();
  2349. if(empty($classIds)){
  2350. $error[] = '请指定考试班级';
  2351. }else{
  2352. $classIds = explode(',',substr($classIds,0,-1));
  2353. }
  2354. if(empty($examName)){
  2355. $error[] = '请设置考试名称';
  2356. }
  2357. if ($type <= 0 || $type > 9) {
  2358. $error[] = '考试类型错误';
  2359. }
  2360. if(empty($subjectId)){
  2361. $error[] = '请选择题源';
  2362. }
  2363. if(!matchStrChar($examName)){
  2364. $error[] = '考试名称不能包含特殊字符';
  2365. }
  2366. if(empty($teacherId)){
  2367. $error[] = '请指定阅卷老师';
  2368. }
  2369. if(empty($examDate)){
  2370. $error[] = '请指定考试时间';
  2371. }
  2372. if(!inArray($tpl_index,array(0,1,2,1050))){
  2373. $error[] = '请指定类型';
  2374. }
  2375. if(empty($topic)){
  2376. $error[] = '请设置题型';
  2377. }
  2378. if(empty($layout)){
  2379. $error[] = '答题卡类型';
  2380. }
  2381. if($error){
  2382. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  2383. }else{
  2384. //组装题型topic_items
  2385. $_topic = json_decode($topic,1);
  2386. $_topic_mould = array();
  2387. $border = '';
  2388. $required = 0;
  2389. /**
  2390. * * 格式:array(
  2391. * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0)))
  2392. */
  2393. foreach ($_topic as $k=>$v)
  2394. {
  2395. if(!empty($v)) {
  2396. if ($k == 0) {
  2397. foreach ($v as $item) {
  2398. $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
  2399. }
  2400. }
  2401. if ($k == 1) {
  2402. foreach ($v as $item) {
  2403. $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
  2404. }
  2405. }
  2406. if ($k == 2) {
  2407. foreach ($v as $item) {
  2408. $border = 'no';
  2409. if ($item[2] >= 1) {
  2410. $border = 'no';
  2411. }
  2412. if ($item[2] == 2) {
  2413. $border = 'dashed';
  2414. }
  2415. if ($item[2] == 3) {
  2416. $border = 'solid';
  2417. }
  2418. $smallTopics = array();
  2419. if(isset($item[3]) && !empty($item[3])){
  2420. $smallArr = explode(',', $item[3]);
  2421. foreach($smallArr as $k=>$v){
  2422. $smallNextArr = explode('///', $v);
  2423. $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
  2424. }
  2425. }
  2426. $style = 'line';
  2427. $row = isset($item[0]) ? $item[0] : 1;
  2428. $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
  2429. }
  2430. }
  2431. if ($k == 3) {
  2432. foreach ($v as $item) {
  2433. $border = 'no';
  2434. if ($item[2] >= 1) {
  2435. $border = 'no';
  2436. }
  2437. if ($item[2] == 2) {
  2438. $border = 'dashed';
  2439. }
  2440. if ($item[2] == 3) {
  2441. $border = 'solid';
  2442. }
  2443. $styles = explode('///', $item[0]);
  2444. $style = 'blank';
  2445. $row = 0;
  2446. if ($styles) {
  2447. if ($styles[0] == 1) {
  2448. $style = 'blank';
  2449. }
  2450. if ($styles[0] == 2) {
  2451. $style = 'line';
  2452. $row = isset($styles[1]) ? $styles[1] : 1;
  2453. }
  2454. if ($styles[0] == 3) {
  2455. $style = 'table';
  2456. }
  2457. }
  2458. $smallTopics = array();
  2459. if(isset($item[3]) && !empty($item[3])){
  2460. $smallArr = explode(',', $item[3]);
  2461. foreach($smallArr as $k=>$v){
  2462. $smallNextArr = explode('///', $v);
  2463. $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
  2464. }
  2465. }
  2466. $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
  2467. }
  2468. }
  2469. if ($k == 4) {
  2470. $style = 'blank';
  2471. foreach ($v as $item) {
  2472. if ($item[2] == 1) {
  2473. $style = 'blank';
  2474. }
  2475. if ($item[2] == 2) {
  2476. $style = 'line';
  2477. }
  2478. $topics = explode('///', $item[0]);
  2479. if ($topics) {
  2480. $required+= $topics[1]; //多组,会有多道必做题
  2481. }
  2482. $topic_no = $this->topic_no($item[1]);
  2483. if (count($topic_no) != $topics[0]) {
  2484. $error[] = '答题卡选做题格式设置有问题';
  2485. }
  2486. $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0));
  2487. }
  2488. }
  2489. }
  2490. }
  2491. $topic_items = $this->topic_items($_topic_mould);
  2492. // debug($topic_items);
  2493. $_topic_items = array();
  2494. if(!$topic_items){
  2495. // $error[] = '答题卡格式设置有问题';
  2496. echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有问题'));exit;
  2497. }
  2498. //添加alias
  2499. $alias=0;
  2500. $Multi_Group_Sign=0;
  2501. $isDisplay=0;
  2502. $letterNum=0;
  2503. foreach ($topic_items as $v)
  2504. {
  2505. if($v['topic_type']!=17){
  2506. $alias++;
  2507. }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){
  2508. $Multi_Group_Sign=$v['multi_group_sign'];
  2509. $alias++;
  2510. $isDisplay=1;
  2511. $letterNum=0;
  2512. }
  2513. if($v['topic_type']==17){
  2514. $v['alias']=(string)$alias.$this->numToLetter($letterNum);
  2515. }else{
  2516. $v['alias']=(string)$alias;
  2517. }
  2518. $v['showNum']=(string)$alias;
  2519. unset($v['multi_group_sign']);
  2520. $_topic_items[] = $v;
  2521. $letterNum++;
  2522. }
  2523. if($_topic_items){
  2524. $newTopicItems = array();
  2525. $i = 1;
  2526. $no = 1;
  2527. foreach($_topic_items as $v){
  2528. if(isset($v['smallCounts'])){
  2529. $isDisplay=1;
  2530. for($a=1;$a<=$v['smallCounts'];$a++){
  2531. $v['id'] = $i;
  2532. $v['smallNo'] = $a;
  2533. $v['bigNo'] = $no;
  2534. $v['alias'] = $no.'.'.$a;
  2535. $newTopicItems[] = $v;
  2536. $i++;
  2537. }
  2538. }else{
  2539. $v['id'] = $i;
  2540. // $v['smallNo'] = 1;
  2541. $v['bigNo'] = $no;
  2542. $newTopicItems[] = $v;
  2543. $i++;
  2544. }
  2545. $no++;
  2546. }
  2547. }
  2548. //debug($newTopicItems);
  2549. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  2550. if($teacherName){
  2551. $tplData['author'] = $teacherName;
  2552. $tplData['subjectId'] = $subjectId;
  2553. $tplData['textbookId'] = $textbookId;
  2554. $tplData['examDate'] = $examDate;
  2555. }
  2556. $json['author'] = $teacherName;
  2557. $json['examDate'] = $examDate;
  2558. $json['subjectId'] = (int)$subjectId;
  2559. $json['textbookId'] = (int)$textbookId;
  2560. $json['exam_name'] = $examName;
  2561. $json['totals'] = count($newTopicItems);
  2562. $json['layout'] = (int)$layout;
  2563. $json['select_card_type'] = (int)$select_card_type;
  2564. $json['impersonal_topic_type'] = 0;
  2565. $json['total_score'] = 0;
  2566. $json['scores'] = 0;
  2567. $json['is_display'] = $isDisplay;
  2568. $json['times'] = 0;
  2569. if($subjectId==8){
  2570. $json['isNewEnglish']=1;
  2571. }
  2572. $json['school_card_length'] = 8;
  2573. if($this->schoolId>999){
  2574. $json['school_card_length'] = 9;
  2575. }
  2576. $json['required'] = (int)$required;
  2577. $json['new_items'] = $newTopicItems;
  2578. $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") ";
  2579. $cardData = $this->sConn->createCommand($sql)->queryRow();
  2580. if(!$cardData){
  2581. $error[] = '无法找到对应班级';
  2582. }
  2583. if($cardData['card_status']){
  2584. $json['school_card_length'] = (int)$cardData['card_length'];
  2585. }else{
  2586. $cardData['card_length'] = 8;
  2587. if($this->schoolId>999){
  2588. $cardData['card_length'] = 9;
  2589. }
  2590. }
  2591. $class_type=$cardData['class_type'];
  2592. $time = time();
  2593. if($error){
  2594. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  2595. }
  2596. $transaction = $this->sConn->beginTransaction();
  2597. try{
  2598. if($is_update){
  2599. $exam_ids = array();
  2600. ExamGroup::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update));
  2601. $xams = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update));
  2602. if($xams){
  2603. foreach ($xams as $v){
  2604. $exam_ids[] = $v->exam_id;
  2605. }
  2606. }
  2607. $criteria = new CDbCriteria();
  2608. $criteria->addInCondition('exam_id',$exam_ids);
  2609. Exam::model()->deleteAll($criteria);
  2610. unset($criteria);
  2611. $criteria = new CDbCriteria();
  2612. $criteria->addInCondition('exam_id',$exam_ids);
  2613. SPaper::model()->deleteAll($criteria);
  2614. unset($criteria);
  2615. $criteria = new CDbCriteria();
  2616. $criteria->addInCondition('exam_id',$exam_ids);
  2617. ClassExamPrinter::model()->deleteAll($criteria);
  2618. unset($criteria);
  2619. $criteria = new CDbCriteria();
  2620. $criteria->addInCondition('exam_id',$exam_ids);
  2621. SStudentPaperRelation::model()->deleteAll($criteria);
  2622. unset($criteria);
  2623. }
  2624. //$newExamGroupId = $this->UUID_SHORT();
  2625. $newExamGroupId = getUniqueId($this->schoolId);
  2626. if($markType ==4)
  2627. {
  2628. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
  2629. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
  2630. }else
  2631. {
  2632. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
  2633. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
  2634. }
  2635. $this->sConn->createCommand($sql)->execute();
  2636. foreach($classIds as $classId){
  2637. //$newExamId = $this->UUID_SHORT();
  2638. $newExamId = getUniqueId($this->schoolId);
  2639. $this->sConn->createCommand()->insert('exam',array(
  2640. 'exam_id' => $newExamId,
  2641. 'exam_group_id' => $newExamGroupId,
  2642. 'name' => $examName,
  2643. 'semester_id' => $this->semesterId,
  2644. 'teacher_id' => $teacherId,
  2645. 'subject_id' => $subjectId,
  2646. 'module_id' => 0,
  2647. 'type' => $type,
  2648. 'school_card_status' => $cardData['card_status'],
  2649. 'school_card_length' => $cardData['card_length'],
  2650. 'status' => 2,
  2651. 'week_num' => 0,
  2652. 'create_type' => 0,
  2653. 'create_time' => $time,
  2654. 'update_time' => $time,
  2655. 'tpl_data' => jsonEncode($json),
  2656. 'tpl_index' => $tpl_index,
  2657. 'class_id' => $classId,
  2658. 'method_ids' => '',
  2659. ));
  2660. //$newPaperId = $this->UUID_SHORT();
  2661. $newPaperId = getUniqueId($this->schoolId);
  2662. $this->sConn->createCommand()->insert('paper', array(
  2663. 'paper_id' => $newPaperId,
  2664. 'paper_type' => 1,
  2665. 'exam_id' => $newExamId,
  2666. 'paper_name' => '',
  2667. 'paper_layer' => '',
  2668. 'difficulty' => 0,
  2669. 'topics_count' => 0,
  2670. 'score' => 0,
  2671. 'add_time' => $time,
  2672. 'update_time' => $time,
  2673. 'method_ids' => '',
  2674. 'is_labelled' => 0,
  2675. ));
  2676. $this->sConn->createCommand()->insert('class_exam_printer', array(
  2677. 'class_id' => $classId,
  2678. 'exam_id' => $newExamId,
  2679. 'type' => 0,
  2680. 'is_print' => 0,
  2681. 'print_time' => 0,
  2682. 'add_time' => $time,
  2683. ));
  2684. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  2685. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  2686. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  2687. if($studentIds_0){
  2688. foreach ($studentIds_0 as $studentId) {
  2689. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  2690. // if($studentIds){
  2691. // foreach ($studentIds as $studentId) {
  2692. $this->sConn->createCommand()->insert('student_paper_relation', array(
  2693. 'student_id' => $studentId,
  2694. 'paper_id' => $newPaperId,
  2695. 'exam_id' => $newExamId,
  2696. 'semester_id' => $this->semesterId,
  2697. 'class_id' => $classId,
  2698. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  2699. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  2700. 'class_type' =>$class_type
  2701. ));
  2702. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  2703. 'student_id' => $studentId,
  2704. 'paper_id' => $newPaperId,
  2705. 'exam_id' => $newExamId,
  2706. 'semester_id' => $this->semesterId,
  2707. 'class_id' => $classId,
  2708. 'create_time' =>$time
  2709. ));
  2710. }
  2711. }
  2712. }
  2713. $transaction->commit();
  2714. }catch(Exception $e){
  2715. $transaction->rollBack();
  2716. echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
  2717. }
  2718. }
  2719. if(!$error){
  2720. // echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>$json,'exam_group_id'=>$newExamGroupId));exit;
  2721. echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
  2722. }
  2723. }
  2724. public function actionCreateThirdTpl(){
  2725. $error = array();
  2726. $tplData = array();
  2727. $tpl_title = Req::post("tpl_title");
  2728. $classIds = Req::post("classIds");
  2729. $teacherId = Req::post("teacherId");
  2730. $subjectId = Req::post("subjectId");
  2731. $textbookId = Req::post("textbookId");
  2732. $topic = $_POST["topic"];
  2733. $layout = Req::post("layout");
  2734. $select_card_type = Req::post("select_card_type");
  2735. if(empty($classIds)){
  2736. $error[] = '请指定考试班级';
  2737. }else{
  2738. $classIds = explode(',',substr($classIds,0,-1));
  2739. }
  2740. if(empty($tpl_title)){
  2741. $error[] = '请设置答题卡名称';
  2742. }
  2743. if(empty($subjectId)){
  2744. $error[] = '请选择题源';
  2745. }
  2746. if(empty($teacherId)){
  2747. $error[] = '请指定阅卷老师';
  2748. }
  2749. if(empty($topic)){
  2750. $error[] = '请设置题型';
  2751. }
  2752. if(empty($layout)){
  2753. $error[] = '答题卡类型';
  2754. }
  2755. if($error){
  2756. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  2757. }else{
  2758. $card_status = 0;
  2759. $school_card_length = 8;
  2760. if($this->schoolId>999){
  2761. $school_card_length = 9;
  2762. }
  2763. $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") ";
  2764. $cardData = $this->sConn->createCommand($sql)->queryRow();
  2765. if(!$cardData){
  2766. $error[] = '无法找到对应班级';
  2767. }
  2768. if($cardData['card_status']){
  2769. $school_card_length = (int)$cardData['card_length'];
  2770. $card_status = (int)$cardData['card_status'];
  2771. }
  2772. $rs = $this->sConn->createCommand()->insert('third_tpl',array(
  2773. 'title' => $tpl_title,
  2774. 'subject_id' => $subjectId,
  2775. 'school_card_status' => $card_status,
  2776. 'school_card_length' => $school_card_length,
  2777. 'layout' => $layout,
  2778. 'select_card_type' => $select_card_type,
  2779. 'tpl_data' => $topic,
  2780. 'create_time' => time()
  2781. ));
  2782. $third_tpl_id = $this->sConn->getLastInsertID();
  2783. $_layout = array(10=>'A4竖版',11=>'A4横版','20'=>'A3竖版','21'=>'A3三栏','31'=>'A3两栏','40'=>'8K(260*370)两栏','41'=>'8K(260*370)三栏','50'=>'8K(270*390)两栏','51'=>'8K(270*390)三栏');
  2784. $_select_card_type = array(1=>'准考证号',2=>'条形码');
  2785. if($rs){
  2786. echo json_encode(array('status'=>1,'msg'=>'保存成功','result'=>array('third_tpl_id'=>$third_tpl_id,'title'=>$tpl_title,'layout'=>$_layout[$layout],'select_card_type'=>$_select_card_type[$select_card_type])));exit;
  2787. }
  2788. }
  2789. echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit;
  2790. }
  2791. public function actionCheckAnswerCard(){
  2792. $eid = Req::post('eid');
  2793. $error['success'] = 0;
  2794. if (empty($eid)) {
  2795. $error['message'] = '考试id不存在!';
  2796. echo json_encode($error);exit();
  2797. }
  2798. $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
  2799. if (empty($examGroup)) {
  2800. $error['message'] = '未找到试卷信息!';
  2801. echo json_encode($error);exit();
  2802. }
  2803. $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
  2804. if (empty($thirdSheet)) {
  2805. $error['message'] = '尚未创建答题卡,请创建!';
  2806. echo json_encode($error);exit();
  2807. }
  2808. $mathAi=0; //数学ai解析入口
  2809. $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
  2810. if($exam_data)
  2811. {
  2812. foreach($exam_data as $v)
  2813. {
  2814. $exam_ids[$v->exam_id] = $v->exam_id;
  2815. }
  2816. $criteria = new CDbCriteria();
  2817. $criteria->addInCondition('exam_id',$exam_ids);
  2818. $criteria->addCondition('is_labelled>0');
  2819. $criteria->addCondition('is_labelled<4');
  2820. $_paper_data = SPaper::model()->findAll($criteria);
  2821. if($_paper_data || ($examGroup['is_tagging']>0 && $examGroup['is_tagging']<4))
  2822. {
  2823. $error['success'] = 0;
  2824. $error['message'] = '已发送标注,无法上传';
  2825. echo json_encode($error);exit();
  2826. }
  2827. if(in_array($exam_data[0]['subject_id'],$this->mathSubjectId)){
  2828. if($examGroup['qxk_paper_id']>0){
  2829. //查询解析数据
  2830. $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
  2831. if($topicWord && $topicWord->is_history_topic){
  2832. $mathAi=0;
  2833. }else{
  2834. $mathAi=1;
  2835. }
  2836. }
  2837. }
  2838. }
  2839. $start=strtotime(date('Y-m-d'))+3600*8+1800; //8点半
  2840. $end=strtotime(date('Y-m-d'))+3600*18; //18点
  2841. if((time()>$start && time()<$end) || in_array($this->schoolId,array(2133,4016,4044,2134))){
  2842. $error['data']='ai';
  2843. }else{
  2844. $error['data']='word';
  2845. }
  2846. $error['math_ai']=$mathAi;
  2847. $error['success'] = 1;
  2848. echo json_encode($error);exit();
  2849. }
  2850. // 上传试卷模板
  2851. public function actionUploadTpl(){
  2852. $exam_group_id = Req::post('eid');
  2853. $error['success'] = 0;
  2854. if (empty($exam_group_id)) {
  2855. $error['message'] = '考试id不存在!';
  2856. echo json_encode($error);exit();
  2857. }
  2858. $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2859. if (empty($examInfo)) {
  2860. $error['message'] = '未找到试卷信息!';
  2861. echo json_encode($error);exit();
  2862. }
  2863. $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2864. if (empty($thirdSheet)) {
  2865. $error['message'] = '尚未上传答题卡!';
  2866. echo json_encode($error);exit();
  2867. }
  2868. if (empty($_FILES['word_file'])) {
  2869. $error['message'] = '未找到上传文件!';
  2870. echo json_encode($error);exit();
  2871. }
  2872. if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){
  2873. $error['message'] = '非法上传!';
  2874. echo json_encode($error);exit();
  2875. }
  2876. if ($_FILES['word_file']['error'] > 0) {
  2877. switch ($_FILES['word_file']['error']) {
  2878. case 1:
  2879. $error['message'] = '文件大小超出了服务器的空间大小!';
  2880. break;
  2881. case 2:
  2882. $error['message'] = '要上传的文件大小超出浏览器限制!';
  2883. break;
  2884. case 3:
  2885. $error['message'] = '文件只有部分被上传!';
  2886. break;
  2887. case 4:
  2888. $error['message'] = '没有找到要上传的文件!';
  2889. break;
  2890. case 5:
  2891. $error['message'] = '服务器临时文件夹丢失!';
  2892. break;
  2893. case 6:
  2894. $error['message'] = '文件写入到临时文件夹出错!';
  2895. break;
  2896. }
  2897. echo json_encode($error);exit();
  2898. }
  2899. // 保存上传文件至服务器
  2900. $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.'));
  2901. $fileName = $exam_group_id.$extName;
  2902. $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName;
  2903. $ucloud = new Qcloud();
  2904. $uploadInfo = $ucloud->putFile($wordRename, $_FILES['word_file']['tmp_name']);
  2905. if ($uploadInfo['status'] == 0) {
  2906. echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg']));
  2907. exit();
  2908. }
  2909. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  2910. //操作日志
  2911. if(Yii::app()->params['handle_log_on_off'])
  2912. {
  2913. writeFileLog(jsonEncode(array(
  2914. "exam_group_id" => (string)$exam_group_id,
  2915. "operate_project" => 'zsyas2',
  2916. "title" => '第三方试卷上传试卷',
  2917. "school_id" => $this->schoolId,
  2918. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2919. "operate_method" => $this->action,
  2920. "operate_url" => $this->getRoute(),
  2921. "operate_sql" => json_encode(array('insert'=>array('exam_group_id'=>$exam_group_id,'status'=>0,'word_path'=>$uploadInfo['url'],'subject_id'=>$examInfo->subject_id))),
  2922. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])),
  2923. "date"=>date('Y-m-d H:i:s')
  2924. )));
  2925. }
  2926. $transcation = $this->sConn->beginTransaction();
  2927. try {
  2928. $time = time();
  2929. //查询解析数据
  2930. $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2931. if($topicWord && $topicWord->is_history_topic){
  2932. //复用解析,重新上传清空试题
  2933. $historyTopic=json_decode($topicWord->is_history_topic,1);
  2934. if(!$historyTopic){
  2935. $error['message'] = '试卷结构恢复不成功!';
  2936. echo json_encode($error);exit();
  2937. }
  2938. $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$exam_group_id}")->queryRow();
  2939. if ($examGroup['upload_status'] > 0) {
  2940. $result['message'] = "已上传成绩,不能切换解析模式";
  2941. exit(json_encode($result));
  2942. }
  2943. $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2944. //取得试卷topic
  2945. $paperIds=array();
  2946. foreach ($exam as $value){
  2947. $paperIds[]=$value['paper_id'];
  2948. }
  2949. $tplData=json_decode($exam[0]['tpl_data'],true);
  2950. if(isset($tplData['new_items'])){
  2951. foreach ($tplData['new_items'] as $key =>$val){
  2952. if(isset($historyTopic[$val['id']])){
  2953. $tplData['new_items'][$key]['topicId']=$historyTopic[$val['id']]['topic_id'];
  2954. $tplData['new_items'][$key]['stemId']=$historyTopic[$val['id']]['stem_id'];
  2955. }
  2956. }
  2957. }
  2958. $paperTopicRelation=$this->sConn->createCommand("select `order`,`topic_id`,`type`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
  2959. $updateSql=array();
  2960. foreach ($paperTopicRelation as $value){
  2961. if(!isset($historyTopic[$value['order']])){
  2962. $error['message'] = '试卷结构恢复不成功!';
  2963. echo json_encode($error);exit();
  2964. }
  2965. $stemId=0;
  2966. if(isset($historyTopic[$value['order']]['stem_id'])){
  2967. $stemId=$historyTopic[$value['order']]['stem_id'];
  2968. }
  2969. $updateSql[]="update paper_topic_relation set topic_id='".$historyTopic[$value['order']]['topic_id']."',stem_id='".$stemId."',method_ids='',method_difficulty=0 where paper_id in(".implode(',',$paperIds).") and topic_id='".$value['topic_id']."'";
  2970. if($examGroup['mark_type']==4 && !in_array($historyTopic[$value['order']]['type'],array(1,2,11))){
  2971. $updateSql[]="update marking_topic set topic_id='".$historyTopic[$value['order']]['topic_id']."' where exam_group_id='{$exam_group_id}' and topic_id='{$value['topic_id']}'";
  2972. }
  2973. }
  2974. foreach ($updateSql as $sql){
  2975. $this->sConn->createCommand($sql)->execute();
  2976. }
  2977. if($examGroup['mark_type']!=4){
  2978. $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute();
  2979. }
  2980. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$exam_group_id}'")->execute();
  2981. }
  2982. $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute();
  2983. STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2984. $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
  2985. $wordId = current(current($uuid));
  2986. $topic_word_odj = new STopicWord();
  2987. $topic_word_odj->word_id = $wordId;
  2988. $topic_word_odj->exam_group_id = $exam_group_id;
  2989. $topic_word_odj->word_name = '第三方试卷'.$fileName;
  2990. $topic_word_odj->word_path = $uploadInfo['url'];
  2991. $topic_word_odj->word_md5 = '';
  2992. $topic_word_odj->word_size = $_FILES['word_file']['size'];
  2993. $topic_word_odj->subject_id = $examInfo->subject_id;
  2994. $topic_word_odj->status = 0;
  2995. $topic_word_odj->uploader_id = $this->coachId;
  2996. $topic_word_odj->upload_time = $time;
  2997. $topic_word_odj->save();
  2998. $transcation->commit();
  2999. }
  3000. catch (Exception $e)
  3001. {
  3002. $transcation->rollback();
  3003. $error['message'] = '上传文件失败!';
  3004. echo json_encode($error);exit();
  3005. }
  3006. $this->schoolManager->saveExamProcess($exam_group_id,3,time());
  3007. $error['success'] = 1;
  3008. $error['message'] = '上传文件成功!';
  3009. echo json_encode($error);exit();
  3010. }
  3011. public function actionSetSubjectId()
  3012. {
  3013. $subjectId = Req::post("subjectId");
  3014. if($subjectId)
  3015. {
  3016. Yii::app()->session['session_duoxueke_subject_id'] = $subjectId;
  3017. echo 1;exit;
  3018. }else
  3019. {
  3020. echo 0;exit;
  3021. }
  3022. }
  3023. /**
  3024. *
  3025. * 格式:array(
  3026. * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0)))
  3027. *
  3028. * )
  3029. *
  3030. */
  3031. protected function topic_items($topic_data = array())
  3032. {
  3033. $data = array();
  3034. $keys = array();
  3035. if(!$topic_data)
  3036. {
  3037. return false;
  3038. }
  3039. foreach ($topic_data as $k=>$v)
  3040. {
  3041. $counter = $this->counter($k,$v);
  3042. if(!$counter){
  3043. return array();
  3044. }else{
  3045. foreach ($counter as $ck =>$cv){
  3046. if(!isset($keys[$ck])){
  3047. $keys[$ck] = $ck;
  3048. $data[$ck] = $cv;
  3049. }else{
  3050. return false;
  3051. }
  3052. }
  3053. }
  3054. }
  3055. ksort($data);
  3056. return $data;
  3057. }
  3058. /**
  3059. *计算题量
  3060. */
  3061. protected function counter($type,$format)
  3062. {
  3063. $data = array();
  3064. $keys = array();
  3065. if($type==1 || $type ==11)
  3066. {
  3067. foreach ($format as $_format){
  3068. if(isset($_format['option_count']) && !empty($_format['option_count']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format']))
  3069. {
  3070. $topic_no = $this->topic_no($_format['topic_no_format']);
  3071. if($topic_no)
  3072. {
  3073. foreach ($topic_no as $v)
  3074. {
  3075. if(isset($keys[$v])){
  3076. return false;
  3077. }else{
  3078. $keys[$v] = $v;
  3079. }
  3080. $data[$v]['id'] = (int)$v;
  3081. $data[$v]['optionsCount'] = (int)$_format['option_count'];
  3082. $data[$v]['score'] = 0;
  3083. $data[$v]['topic_type'] = (int)$type;
  3084. $data[$v]['group_id'] = 0;
  3085. $data[$v]['border'] = "";
  3086. $data[$v]['style'] = "";
  3087. $data[$v]['row'] = 0;
  3088. }
  3089. }else{
  3090. return false;
  3091. }
  3092. }
  3093. }
  3094. }elseif($type==5){
  3095. foreach ($format as $_format){
  3096. if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
  3097. if(isset($_format['smallTopics'])){
  3098. $smallArr = $_format['smallTopics'];
  3099. }else{
  3100. $smallArr = array();
  3101. }
  3102. $topic_no = $this->topic_no($_format['topic_no_format']);
  3103. if($topic_no){
  3104. foreach ($topic_no as $v){
  3105. if(isset($keys[$v])){
  3106. return false;
  3107. }else{
  3108. $keys[$v] = $v;
  3109. }
  3110. $data[$v]['id'] = (int)$v;
  3111. $data[$v]['optionsCount'] = 0;
  3112. $data[$v]['score'] = 0;
  3113. $data[$v]['group_id'] = 0;
  3114. $data[$v]['topic_type'] = (int)$type;
  3115. $data[$v]['border'] = $_format['style']['border'];
  3116. $data[$v]['style'] = $_format['style']['style'];
  3117. $data[$v]['row'] = $_format['style']['row'];
  3118. if(isset($smallArr[$v])){
  3119. $data[$v]['smallCounts'] = $smallArr[$v];
  3120. }
  3121. }
  3122. }
  3123. }
  3124. }
  3125. }elseif($type==7){
  3126. foreach ($format as $_format){
  3127. if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
  3128. if(isset($_format['smallTopics'])){
  3129. $smallArr = $_format['smallTopics'];
  3130. }else{
  3131. $smallArr = array();
  3132. }
  3133. $topic_no = $this->topic_no($_format['topic_no_format']);
  3134. if($topic_no){
  3135. foreach ($topic_no as $v){
  3136. if(isset($keys[$v])){
  3137. return false;
  3138. }else{
  3139. $keys[$v] = $v;
  3140. }
  3141. $data[$v]['id'] = (int)$v;
  3142. $data[$v]['optionsCount'] = 0;
  3143. $data[$v]['score'] = 0;
  3144. $data[$v]['group_id'] = 0;
  3145. $data[$v]['topic_type'] = (int)$type;
  3146. $data[$v]['border'] = $_format['style']['border'];
  3147. $data[$v]['style'] = $_format['style']['style'];
  3148. $data[$v]['row'] = $_format['style']['row'];
  3149. if(isset($smallArr[$v])){
  3150. $data[$v]['smallCounts'] = $smallArr[$v];
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. }elseif($type==17){
  3157. foreach ($format as $_format){
  3158. if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
  3159. $topic_no = $this->topic_no($_format['topic_no_format']);
  3160. //多选题需要添加一个组的标记
  3161. $Multi_Group_Sign=0;
  3162. if($topic_no){
  3163. foreach ($topic_no as $v){
  3164. if(isset($keys[$v])){
  3165. return false;
  3166. }else{
  3167. $keys[$v] = $v;
  3168. }
  3169. if(!$Multi_Group_Sign) $Multi_Group_Sign=$v;
  3170. $data[$v]['id'] = (int)$v;
  3171. $data[$v]['optionsCount'] = 0;
  3172. $data[$v]['score'] = 0;
  3173. $data[$v]['group_id'] = 0;
  3174. $data[$v]['topic_type'] = (int) $type;
  3175. $data[$v]['border'] = $_format['style']['border'];
  3176. $data[$v]['style'] = $_format['style']['style'];
  3177. $data[$v]['row'] = $_format['style']['row'];
  3178. $data[$v]['multi_group_sign'] = $Multi_Group_Sign;
  3179. }
  3180. }
  3181. }
  3182. }
  3183. }
  3184. return $data;
  3185. }
  3186. /**
  3187. * @param $str
  3188. * 格式
  3189. */
  3190. protected function topic_no($str)
  3191. {
  3192. $data = array();
  3193. if($str){
  3194. $array = explode(',', $str);
  3195. foreach ($array as $key => $v) {
  3196. if(!empty($v)){
  3197. $section = explode('-', $v);
  3198. if(count($section)>1)
  3199. {
  3200. if($section[1]<$section[0])
  3201. {
  3202. return array();
  3203. }else
  3204. {
  3205. if($section[0]){
  3206. for ($i=$section[0]; $i<= $section[1] ; $i++) {
  3207. # code...
  3208. if(isset($data[$i]))
  3209. {
  3210. return array();
  3211. }else{
  3212. $data[$i] = $i;
  3213. }
  3214. }
  3215. }
  3216. }
  3217. }else{
  3218. if(isset($data[$v]))
  3219. {
  3220. return array();
  3221. }else{
  3222. $data[$v] = $v;
  3223. }
  3224. }
  3225. }
  3226. }
  3227. }
  3228. return $data;
  3229. }
  3230. public function actionPrint_paper(){
  3231. $exam_group_id = Req::post('exam_group_id');
  3232. $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  3233. if($exam)
  3234. {
  3235. echo json_encode(array('status'=>1,'msg'=>'','result'=>$exam->tpl_data));exit;
  3236. }
  3237. echo json_encode(array('status'=>0,'msg'=>$exam->tpl_data,'result'=>''));exit;
  3238. }
  3239. public function actionCreate_sheet(){
  3240. $examName = Req::post("examName");
  3241. $classIds = Req::post("classIds");
  3242. $layout = Req::post("layout");
  3243. $select_card_type = Req::post("select_card_type");
  3244. $topic = $_POST["topic"];
  3245. if($topic && $classIds){
  3246. $classIds = explode(',',substr($classIds,0,-1));
  3247. //组装题型topic_items
  3248. $_topic = json_decode($topic,1);
  3249. $_topic_mould = array();
  3250. $border = '';
  3251. $required = 0;
  3252. /**
  3253. * * 格式:array(
  3254. * 题型=>array(array("option_count"=>选项',topic_no_format'=>'1-5,8,10,11-15','style'=>array('border'=>'','style'=>'','row'=>0)),array("option_count"=>5',topic_no_format'=>'7,9','style'=>array('border'=>'','style'=>'','row'=>0)))
  3255. */
  3256. // debug($_topic);
  3257. foreach ($_topic as $k=>$v)
  3258. {
  3259. if(!empty($v)) {
  3260. if ($k == 0) {
  3261. foreach ($v as $item) {
  3262. $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
  3263. }
  3264. }
  3265. if ($k == 1) {
  3266. foreach ($v as $item) {
  3267. $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
  3268. }
  3269. }
  3270. if ($k == 2) {
  3271. foreach ($v as $item) {
  3272. $border = 'no';
  3273. if ($item[2] >= 1) {
  3274. $border = 'no';
  3275. }
  3276. if ($item[2] == 2) {
  3277. $border = 'dashed';
  3278. }
  3279. if ($item[2] == 3) {
  3280. $border = 'solid';
  3281. }
  3282. $smallTopics = array();
  3283. if(isset($item[3]) && $item[3]){
  3284. $smallArr = explode(',', $item[3]);
  3285. foreach($smallArr as $k=>$v){
  3286. $smallNextArr = explode('///', $v);
  3287. $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
  3288. }
  3289. }
  3290. $style = 'line';
  3291. $row = isset($item[0]) ? $item[0] : 1;
  3292. $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
  3293. }
  3294. }
  3295. if ($k == 3) {
  3296. foreach ($v as $item) {
  3297. $border = 'no';
  3298. if ($item[2] >= 1) {
  3299. $border = 'no';
  3300. }
  3301. if ($item[2] == 2) {
  3302. $border = 'dashed';
  3303. }
  3304. if ($item[2] == 3) {
  3305. $border = 'solid';
  3306. }
  3307. $smallTopics = array();
  3308. if(isset($item[3]) && $item[3]){
  3309. $smallArr = explode(',', $item[3]);
  3310. foreach($smallArr as $k=>$v){
  3311. $smallNextArr = explode('///', $v);
  3312. $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
  3313. }
  3314. }
  3315. $styles = explode('///', $item[0]);
  3316. $style = 'blank';
  3317. $row = 0;
  3318. if ($styles) {
  3319. if ($styles[0] == 1) {
  3320. $style = 'blank';
  3321. }
  3322. if ($styles[0] == 2) {
  3323. $style = 'line';
  3324. $row = isset($styles[1]) ? $styles[1] : 1;
  3325. }
  3326. if ($styles[0] == 3) {
  3327. $style = 'table';
  3328. }
  3329. }
  3330. $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
  3331. }
  3332. }
  3333. if ($k == 4) {
  3334. $style = 'blank';
  3335. foreach ($v as $item) {
  3336. if ($item[2] == 1) {
  3337. $style = 'blank';
  3338. }
  3339. if ($item[2] == 2) {
  3340. $style = 'line';
  3341. }
  3342. $topics = explode('///', $item[0]);
  3343. if ($topics && isset($topics[1])) {
  3344. $required += $topics[1];
  3345. }
  3346. $topic_no = $this->topic_no($item[1]);
  3347. if (count($topic_no) != $topics[0]) {
  3348. $error[] = '答题卡选做题格式设置有误,请填写正确的题号';
  3349. }
  3350. $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0));
  3351. }
  3352. }
  3353. }
  3354. }
  3355. // debug($_topic_mould);
  3356. $topic_items = $this->topic_items($_topic_mould);
  3357. $_topic_items = array();
  3358. if(!$topic_items){
  3359. echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写确的题号'));exit;
  3360. }
  3361. //添加alias
  3362. $alias=0;
  3363. $Multi_Group_Sign=0;
  3364. $isDisplay=0;
  3365. $letterNum=0;
  3366. foreach ($topic_items as $v)
  3367. {
  3368. if($v['topic_type']!=17){
  3369. $alias++;
  3370. }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){
  3371. $Multi_Group_Sign=$v['multi_group_sign'];
  3372. $alias++;
  3373. $isDisplay=1;
  3374. $letterNum=0;
  3375. }
  3376. if($v['topic_type']==17){
  3377. $v['alias']=(string)$alias.$this->numToLetter($letterNum);
  3378. }else{
  3379. $v['alias']=(string)$alias;
  3380. }
  3381. $v['showNum']=(string)$alias;
  3382. unset($v['multi_group_sign']);
  3383. if(isset($v['smallCounts'])){
  3384. $smallCounts = (int)$v['smallCounts'];
  3385. $bigId = (int)$v['alias'];
  3386. for($a=1;$a<=$smallCounts;$a++){
  3387. $v['alias'] = $bigId.'.'.$a;
  3388. $v['showNum'] = $bigId.'.'.$a;
  3389. $_topic_items[] = $v;
  3390. // $alias++;
  3391. }
  3392. }else{
  3393. $_topic_items[] = $v;
  3394. }
  3395. $letterNum++;
  3396. }
  3397. //debug($_topic_items);
  3398. $json['author'] = '';
  3399. $json['examDate'] = '';
  3400. $json['subjectId'] = (int)Yii::app()->session['session_duoxueke_subject_id'];
  3401. $json['textbookId'] = 0;
  3402. $json['exam_name'] = $examName;
  3403. $json['totals'] = count($_topic_items);
  3404. $json['layout'] = (int)$layout;
  3405. $json['select_card_type'] = (int)$select_card_type;
  3406. $json['impersonal_topic_type'] = 0;
  3407. $json['total_score'] = 0;
  3408. $json['is_display'] = 1;
  3409. $json['times'] = 0;
  3410. $json['school_card_length'] = 8;
  3411. if($this->schoolId>999){
  3412. $json['school_card_length'] = 9;
  3413. }
  3414. $json['required'] = (int)$required;
  3415. $json['new_items'] = $_topic_items;
  3416. $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") ";
  3417. $cardData = $this->sConn->createCommand($sql)->queryRow();
  3418. if(!$cardData){
  3419. $error[] = '无法找到对应班级';
  3420. }
  3421. if($cardData['card_status']){
  3422. $json['school_card_length'] = (int)$cardData['card_length'];
  3423. }
  3424. echo json_encode(array('status'=>1,'msg'=>'打印成功','result'=>$json));exit;
  3425. }
  3426. echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写考试名称与班级信息'));exit;
  3427. }
  3428. /*判断关联答题卡*/
  3429. public function actionGetThirdSheet(){
  3430. $ExamGroupId=Req::post('exam_group_id');
  3431. $getType=Req::post('get_type');
  3432. if(!$getType) $getType=0;
  3433. $result=array('success'=>0);
  3434. if(!$ExamGroupId || !is_numeric($ExamGroupId)){
  3435. exit(json_encode($result));
  3436. }
  3437. //验证是否发送任务
  3438. $task=ATask::model()->findByPk($ExamGroupId);
  3439. if(!$getType){
  3440. if($task && in_array($task->paper_task,array(1,2))){
  3441. echo json_encode(array('success'=>4));exit;
  3442. }
  3443. }else{
  3444. if($task && in_array($task->parse_task,array(1,2))){
  3445. echo json_encode(array('success'=>4));exit;
  3446. }
  3447. }
  3448. $ThirdSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$ExamGroupId));
  3449. if($ThirdSheet){
  3450. $result['success']=1;
  3451. }
  3452. exit(json_encode($result));
  3453. }
  3454. /********************* 第三方教学宝开始 *********************/
  3455. /**
  3456. * 第三方教学宝
  3457. * @throws CException
  3458. */
  3459. public function actionTeaching()
  3460. {
  3461. set_time_limit (300);
  3462. ini_set('memory_limit', '300M');
  3463. $classId = Req::get("classId");
  3464. $examId = Req::get("examId");
  3465. $force = (int)Req::get('force');
  3466. $force = 1;//待删
  3467. if(!$examId || !is_numeric($examId)){
  3468. echo json_encode(array("status" => 1, "error" => "考试ID参数不正确!"));
  3469. }
  3470. $examObj = new Exam();
  3471. $examInfo = $examObj->getTeachingInfo($examId);
  3472. if(!$examInfo){
  3473. echo json_encode(array("status" => 1, "error" => "没有考试信息!"));
  3474. exit;
  3475. }
  3476. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path'];
  3477. $res = array();//生成pdf命令结果
  3478. if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath) || $force) {
  3479. $paperObj = new SPaper();
  3480. $ptrObj = new SPaperTopicRelation();
  3481. $ptlObj = new SPaperTopicLarge();
  3482. $sprObj = new SStudentPaperRelation();
  3483. $sptRsObj = new SStudentPaperTopicRs();
  3484. $examGroupId = $examInfo['exam_group_id'];
  3485. $examIds = $examObj->getExamIds($examGroupId);
  3486. //去除没有上传成绩的学生
  3487. $stuIdsArr = $sptRsObj->getHasScoreStu($examIds);
  3488. $ptrInfo = $sprObj->getStudentExamInfo($examIds);
  3489. if(!$ptrInfo){
  3490. echo json_encode(array("status" => 1, "error" => "考试没有数据!"));
  3491. exit();
  3492. }
  3493. $paperIds = array();
  3494. foreach($ptrInfo as $value){
  3495. $paperIds[$value['exam_id']] = $value['paper_id'];
  3496. }
  3497. //试卷总分
  3498. $paperScore = $paperObj->getPaperScore($paperIds);
  3499. if(!$paperScore){
  3500. echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
  3501. exit();
  3502. }
  3503. /**************************** 一、班级情况分析 ***********************************/
  3504. //获取当前考试的上一次考试数据
  3505. $cepObj = new SClassExamPrinter();
  3506. $preInfo = $cepObj->getPreExamId($examId,$examInfo['subject_id'],$examInfo['class_id']);
  3507. $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:'';
  3508. $preExamGroupId = isset($preInfo['exam_group_id'])?$preInfo['exam_group_id']:'';
  3509. $prePaperScore = 0;
  3510. $preStuIdsArr = array();
  3511. if($preExamId){
  3512. $preExamIds = $examObj->getExamIds($preExamGroupId);
  3513. //去除没有上传成绩的学生
  3514. $preStuIdsArr = $sptRsObj->getHasScoreStu($preExamIds);
  3515. $prePtrInfo = $sprObj->getStudentExamInfo($preExamIds);
  3516. $prePaperIds = array();
  3517. foreach($prePtrInfo as $value){
  3518. $prePaperIds[$value['exam_id']] = $value['paper_id'];
  3519. }
  3520. if($prePaperIds){
  3521. $prePaperScore = $paperObj->getPaperScore($prePaperIds);
  3522. }
  3523. }else{
  3524. $prePtrInfo = array();
  3525. }
  3526. if(!$prePaperScore && $prePtrInfo){
  3527. echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
  3528. exit();
  3529. }
  3530. $paperId = $paperIds[$examId];
  3531. //班级排名得分率人数等数据
  3532. $classAnalyData = $this->getClassAnalyse($examId,$ptrInfo,$paperScore,$preExamId,$prePtrInfo,$prePaperScore,$stuIdsArr,$preStuIdsArr);
  3533. //大幅进步,大幅退步,前5名和后5名
  3534. $largeOrderData = $this->getLargeOrder($examId,$ptrInfo,$preExamId,$prePtrInfo,$stuIdsArr,$preStuIdsArr);
  3535. unset($ptrInfo);
  3536. unset($prePtrInfo);
  3537. /**************************** 二、考试情况分析 ***********************************/
  3538. //试卷题对应的题号,分数
  3539. $largeTopicType = $ptlObj->getPaperLargeTopicInfo($paperId);
  3540. // list($topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType);
  3541. list($smallTopicScore,$smallTopicNo,$topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType,$examInfo['subject_id']);
  3542. if(!$topicScore){
  3543. echo json_encode(array("status" => 1, "error" => "没有试卷题数据!"));
  3544. exit();
  3545. }
  3546. // 学生得分
  3547. $stuRs = $sptRsObj->getStudentRs($paperIds);
  3548. if(!$stuRs){
  3549. echo json_encode(array("status" => 1, "error" => "没有学生做题数据!"));
  3550. exit();
  3551. }
  3552. $examAnalyData = $this->getExamAnalyse($stuRs,$topicScore,$topicNo,$paperId,$topicRelLarge);
  3553. /**************************** 三、题类型掌握情况 ***********************************/
  3554. $typeMasterData = $this->getTopicTypeAnaly($stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge);
  3555. /**************************** 四、试卷讲评 ***********************************/
  3556. //试题年级和班级得分率,答对和答错人数
  3557. $topicRateStu = $this->getTopicRateWrongPerson($stuRs,$topicScore,$paperId,$stuIdsArr,$topicRelLarge);
  3558. unset($stuRs);
  3559. $topicIds = array_keys($topicNo);
  3560. $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicIds));
  3561. if (!$topicDetails) {
  3562. echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
  3563. exit();
  3564. } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
  3565. echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
  3566. exit();
  3567. }
  3568. $topicDetails = $this->getTopicDetail($topicDetails);
  3569. $diff_id_arr = array_diff($topicIds, array_keys($topicDetails));
  3570. if ($diff_id_arr) {
  3571. //todo 发送消息到补提
  3572. echo json_encode(array("status" => 1, "error" => "请等待题库老师补题!"));
  3573. exit;
  3574. }
  3575. $data = array();
  3576. $data['examInfo'] = $examInfo;
  3577. $data['classAnalyData'] = $classAnalyData;
  3578. $data['largeOrderData'] = $largeOrderData;
  3579. $data['examAnalyData'] = $examAnalyData;
  3580. $data['typeMasterData'] = $typeMasterData;
  3581. $data['topicDetails'] = $topicDetails;
  3582. $data['paperTopicNo'] = $topicNo;
  3583. $data['smallTopicNo'] = $smallTopicNo;
  3584. $data['topicRateStu'] = $topicRateStu;
  3585. $html = $this->renderPartial("teaching", $data, true);
  3586. // $html = $this->render("teaching", $data);
  3587. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径
  3588. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径
  3589. $pdfurl = '/assets/pdf/academicr/' . $this->schoolId . "/";
  3590. if (!is_dir($htmlpath)) {
  3591. if (!mkdir($htmlpath, 0777, true)) {
  3592. exit('Create directory fail: ' . $htmlpath);
  3593. }
  3594. }if (!is_dir($pdfpath)) {
  3595. if (!mkdir($pdfpath, 0777, true)) {
  3596. exit('Create directory fail1: ' . $pdfpath);
  3597. }
  3598. }
  3599. $htmlpath.=$examId . ".html";
  3600. $f = fopen($htmlpath, "w");
  3601. fwrite($f, $html);
  3602. $htmlurl = '/assets/' . $examId . ".html"; //访问HTML的路径
  3603. if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
  3604. $htmlurl = " http://local.zsyas2teaching.com" . '/'.$examId.'.html';
  3605. $pdffname=$classId."-".$examId.".pdf";
  3606. $pdfpath = $pdfpath . $pdffname;
  3607. $pdfurl = $pdfurl . $pdffname;
  3608. $commond = Yii::app()->params['phantomjs'] . " "
  3609. . Yii::app()->params['html2pdf'] . " "
  3610. . " {$htmlurl}"
  3611. . " {$pdfpath}"
  3612. . " 176mm*250mm ''";
  3613. } else {
  3614. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  3615. $pdffname=$classId."-".$examId.".pdf";
  3616. $pdfpath = $pdfpath . $pdffname;
  3617. $pdfurl = $pdfurl . $pdffname;
  3618. $commond = Yii::app()->params['phantomjs_server'] . " "
  3619. . Yii::app()->basePath . '/../js/html2pdf.js' . " "
  3620. . " {$htmlurl}"
  3621. . " {$pdfpath}"
  3622. . " 176mm*250mm ''";
  3623. }
  3624. exec($commond, $res, $code);
  3625. if(isset($res[0])){
  3626. $isBool = false;
  3627. foreach($res as $msg){
  3628. if (strpos($msg, 'succeed') !== false){
  3629. $isBool = true;
  3630. }
  3631. }
  3632. if ($isBool) {//命令返回成功
  3633. if ($this->file_exists($pdfpath)) {
  3634. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  3635. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  3636. @unlink($htmlpath);
  3637. } else {
  3638. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  3639. @unlink($htmlpath);
  3640. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  3641. exit;
  3642. }
  3643. } else {
  3644. @unlink($htmlpath);
  3645. echo json_encode(array("status" => 1, "error" => "PDF创建失败!",'exec_rs'=>json_encode($res)));
  3646. exit;
  3647. }
  3648. }else{
  3649. Curl::post(Yii::app()->params['handle_log_api'], array(
  3650. "exam_group_id" => (string)$examGroupId,
  3651. "operate_project" => 'zsyas2',
  3652. "school_id" => $this->schoolId,
  3653. "title" => '下载教师讲案',
  3654. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3655. "operate_method" => $this->action,
  3656. "operate_url" => $this->getRoute(),
  3657. "operate_sql" => '',
  3658. "operate_param" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$htmlurl))),
  3659. ));
  3660. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  3661. exit;
  3662. }
  3663. }
  3664. if ($this->check_pdf($pdfpath)) {
  3665. echo json_encode(array("status" => 0, "error" => "","is_create"=>1,'exec_rs'=>json_encode($res)));
  3666. exit;
  3667. } else {
  3668. echo json_encode(array("status" => 1, "error" => "文件尚未生成!",'exec_rs'=>json_encode($res)));
  3669. exit;
  3670. }
  3671. }
  3672. private function check_pdf($pdf_path) {
  3673. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  3674. if (file_exists($pdf_path)) {
  3675. return true;
  3676. }
  3677. }
  3678. return false;
  3679. }
  3680. /**
  3681. * 班级排名得分率人数等数据
  3682. * @param $examId
  3683. * @param $ptrInfo
  3684. * @param $paperScore
  3685. * @param $preExamId
  3686. * @param $prePtrInfo
  3687. * @param $prePaperScore
  3688. * @return array
  3689. */
  3690. private function getClassAnalyse($examId,&$ptrInfo,$paperScore,$preExamId,&$prePtrInfo,$prePaperScore,&$stuIdsArr,&$preStuIdsArr){
  3691. $result = array();
  3692. $gradePerson = $classPerson = 0;//参考人数
  3693. $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数
  3694. $gradeOrder = $classOrder = 0; //排名
  3695. $gradeAvgScore = $classAvgScore = 0; //平均分
  3696. $gradeScoreRate = $classScoreRate = 0; //得分率
  3697. $gradeFineRate = $classFineRate = 0; //优秀率 80%
  3698. $gradePassRate = $classPassRate = 0; //合格率 60%
  3699. $gradeLowRate = $classLowRate = 0; //低分率 30%
  3700. $angData = array(
  3701. 'class_num' => 0,//班级数量
  3702. 'order' => 0,
  3703. 'absent_person' => 0,
  3704. 'exam_person' => 0,
  3705. 'avg_score' => 0,
  3706. 'score_rate' => 0,
  3707. 'fine_rate' => 0,
  3708. 'pass_rate' => 0,
  3709. 'low_rate' => 0,
  3710. );
  3711. $result['grade'] = $result['class'] = $angData;
  3712. $gradeScoring = $classScoring = array();
  3713. $gradeScoringSum = array();//年级中每个考试的得分和
  3714. // $classScoringSum = 0;//考试得分和
  3715. $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率
  3716. foreach($ptrInfo as $value){
  3717. $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
  3718. if(!isset($gradeScoringSum[$value['exam_id']])){
  3719. $gradeScoringSum[$value['exam_id']] = 0;
  3720. }
  3721. if(inArray($value['student_id'],$stuIds)){
  3722. $gradeScoringSum[$value['exam_id']] += $value['scoring'];
  3723. $gradeScoring[] = $value['scoring'];
  3724. $gradeStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
  3725. $gradePerson++;
  3726. }
  3727. if(!inArray($value['student_id'],$stuIds)){
  3728. $gradeAbsentPerson++;
  3729. }
  3730. if($examId == $value['exam_id']){
  3731. if(inArray($value['student_id'],$stuIds)){
  3732. // $classScoringSum += $value['scoring'];
  3733. $classScoring[] = $value['scoring'];
  3734. $classStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
  3735. $classPerson++;
  3736. }
  3737. if(!inArray($value['student_id'],$stuIds)){
  3738. $classAbsentPerson++;
  3739. }
  3740. }
  3741. }
  3742. unset($ptrInfo);
  3743. $result['class']['class_num'] = count($gradeScoringSum);
  3744. $result['grade']['exam_person'] = $gradePerson;
  3745. $result['grade']['absent_person'] = $gradeAbsentPerson;
  3746. $result['class']['exam_person'] = $classPerson;
  3747. $result['class']['absent_person'] = $classAbsentPerson;
  3748. //排名
  3749. if($gradeScoringSum){
  3750. $scoringArr = array();
  3751. foreach($gradeScoringSum as $eId => $scoring){
  3752. $stuCount = isset($stuIdsArr[$eId])?count($stuIdsArr[$eId]):0;
  3753. if($stuCount){
  3754. $scoringArr[$eId] = round($scoring/$stuCount,2);
  3755. }
  3756. }
  3757. if(isset($scoringArr[$examId])){
  3758. $classOrder = $this->getOrder($scoringArr[$examId],$scoringArr);
  3759. }else{
  3760. $classOrder = 0;
  3761. }
  3762. }
  3763. $result['class']['order'] = $classOrder;
  3764. //平均分,得分率
  3765. $count = count($gradeScoring);
  3766. if($count > 0){
  3767. $gradeAvgScore = round(array_sum($gradeScoring)/$count,2);//平均分
  3768. $gradeScoreRate = round(array_sum($gradeScoring)/($paperScore*$count),4)*100;//得分率
  3769. }else{
  3770. $gradeAvgScore = 0;
  3771. $gradeScoreRate = 0;
  3772. }
  3773. $result['grade']['avg_score'] = $gradeAvgScore;
  3774. $result['grade']['score_rate'] = $gradeScoreRate;
  3775. $count = count($classScoring);
  3776. if($count > 0){
  3777. $classAvgScore = round(array_sum($classScoring)/$count,2);
  3778. $classScoreRate = round(array_sum($classScoring)/($paperScore*$count),4)*100;//得分率
  3779. }else{
  3780. $classAvgScore = 0;
  3781. $classScoreRate = 0;
  3782. }
  3783. $result['class']['avg_score'] = $classAvgScore;
  3784. $result['class']['score_rate'] = $classScoreRate;
  3785. //优秀率,合格率,低分率
  3786. // $gradeFineRate = $classFineRate = 0; //优秀率 85%
  3787. // $gradePassRate = $classPassRate = 0; //合格率 60%
  3788. // $gradeLowRate = $classLowRate = 0; //低分率 30%
  3789. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  3790. $rateCount = count($gradeStuScoringRate);
  3791. foreach($gradeStuScoringRate as $scoringRate){
  3792. if($scoringRate >= 85){
  3793. $tempFineNum++;
  3794. }
  3795. if($scoringRate >= 60){
  3796. $tempPassNum++;
  3797. }
  3798. if($scoringRate <= 30){
  3799. $tempLowNum++;
  3800. }
  3801. }
  3802. $gradeFineRate = round($tempFineNum/$rateCount,4) * 100;
  3803. $gradePassRate = round($tempPassNum/$rateCount,4) * 100;
  3804. $gradeLowRate = round($tempLowNum/$rateCount,4) * 100;
  3805. $result['grade']['fine_rate'] = $gradeFineRate;
  3806. $result['grade']['pass_rate'] = $gradePassRate;
  3807. $result['grade']['low_rate'] = $gradeLowRate;
  3808. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  3809. $rateCount = count($classStuScoringRate);
  3810. foreach($classStuScoringRate as $scoringRate){
  3811. if($scoringRate >= 85){
  3812. $tempFineNum++;
  3813. }
  3814. if($scoringRate >= 60){
  3815. $tempPassNum++;
  3816. }
  3817. if($scoringRate <= 30){
  3818. $tempLowNum++;
  3819. }
  3820. }
  3821. $classFineRate = round($tempFineNum/$rateCount,4) * 100;
  3822. $classPassRate = round($tempPassNum/$rateCount,4) * 100;
  3823. $classLowRate = round($tempLowNum/$rateCount,4) * 100;
  3824. $result['class']['fine_rate'] = $classFineRate;
  3825. $result['class']['pass_rate'] = $classPassRate;
  3826. $result['class']['low_rate'] = $classLowRate;
  3827. /**************** 提升数据 ******************/
  3828. $result['class']['order_increase'] = 0;
  3829. $result['class']['rate_increase'] = 0;
  3830. $result['class']['fine_rate_increase'] = 0;
  3831. if($prePtrInfo){
  3832. $preGradeScoringSum = array();
  3833. $preClassScoringSum = 0;
  3834. $preClassScoring = array();
  3835. if($prePtrInfo){
  3836. foreach($prePtrInfo as $value){
  3837. $stuIds = isset($preStuIdsArr[$value['exam_id']])?$preStuIdsArr[$value['exam_id']]:array();
  3838. if(!isset($preGradeScoringSum[$value['exam_id']])){
  3839. $preGradeScoringSum[$value['exam_id']] = 0;
  3840. }
  3841. if(inArray($value['student_id'],$stuIds)){
  3842. $preGradeScoringSum[$value['exam_id']] += $value['scoring'];
  3843. }
  3844. if($preExamId == $value['exam_id']){
  3845. if(inArray($value['student_id'],$stuIds)){
  3846. $preClassScoringSum += $value['scoring'];
  3847. $preClassScoring[] = $value['scoring'];
  3848. $preClassStuScoringRate[] = round($value['scoring']/$prePaperScore,4)*100;
  3849. }
  3850. }
  3851. }
  3852. }
  3853. //上一次考试排名
  3854. if($gradeScoringSum){
  3855. $scoringArr = array();
  3856. foreach($preGradeScoringSum as $eId => $scoring){
  3857. $stuCount = isset($preStuIdsArr[$eId])?count($preStuIdsArr[$eId]):0;
  3858. if($stuCount){
  3859. $scoringArr[$eId] = round($scoring/$stuCount,2);
  3860. }
  3861. }
  3862. if(isset($scoringArr[$preExamId])){
  3863. $preClassOrder = $this->getOrder($scoringArr[$preExamId],$scoringArr);
  3864. }else{
  3865. $preClassOrder = 0;
  3866. }
  3867. $result['class']['order_increase'] = -($classOrder - $preClassOrder);
  3868. }
  3869. $count = count($preClassScoring);
  3870. if($count > 0){
  3871. $preClassScoreRate = round(array_sum($preClassScoring)/($prePaperScore*$count),4)*100;//得分率
  3872. $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate;
  3873. }
  3874. $tempFineNum = 0;
  3875. $rateCount = count($preClassStuScoringRate);
  3876. foreach($preClassStuScoringRate as $scoringRate){
  3877. if($scoringRate >= 85){
  3878. $tempFineNum++;
  3879. }
  3880. }
  3881. $preClassFineRate = round($tempFineNum/$rateCount,4) * 100;
  3882. $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate;
  3883. }
  3884. return $result;
  3885. }
  3886. /**
  3887. * 大幅进步,大幅退步,前5名和后5名
  3888. * @param $examId
  3889. * @param $ptrInfo
  3890. * @param $paperScore
  3891. * @param $preExamId
  3892. * @param $prePtrInfo
  3893. * @param $prePaperScore
  3894. */
  3895. private function getLargeOrder($examId,&$ptrInfo,$preExamId,&$prePtrInfo,&$stuIdsArr,&$preStuIdsArr){
  3896. $result = array();
  3897. $stuOrderArr = $this->getStudentOrder($examId,$ptrInfo,$stuIdsArr);
  3898. $diffNum = ceil(count($stuOrderArr)*0.2);
  3899. if($prePtrInfo){
  3900. $preStuOrderArr = $this->getStudentOrder($preExamId,$prePtrInfo,$preStuIdsArr);
  3901. }else{
  3902. $preStuOrderArr = array();
  3903. }
  3904. if($preStuOrderArr){
  3905. $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr);
  3906. if(!$interOrderArr){
  3907. $interOrderArr = $stuOrderArr;
  3908. }
  3909. }else{
  3910. $interOrderArr = array();
  3911. }
  3912. //大幅进步,退步
  3913. $increaseArr = $reduceArr = array();
  3914. $stuDiffOrder = array();
  3915. if($interOrderArr){
  3916. foreach($stuOrderArr as $stuId => $order){
  3917. if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){
  3918. $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]);
  3919. }else{
  3920. $stuDiffOrder[$stuId] = 0;
  3921. }
  3922. }
  3923. arsort($stuDiffOrder);
  3924. foreach($stuDiffOrder as $stuId => $num){
  3925. if($num >= $diffNum){
  3926. $increaseArr[] = $stuId;
  3927. }
  3928. }
  3929. $increaseArr = array_slice($increaseArr,0,5,true);
  3930. asort($stuDiffOrder);
  3931. foreach($stuDiffOrder as $stuId => $num){
  3932. if($num <= -$diffNum){
  3933. $reduceArr[] = $stuId;
  3934. }
  3935. }
  3936. $reduceArr = array_slice($reduceArr,0,5,true);
  3937. }else{
  3938. $increaseArr = array_slice($stuOrderArr,0,5,true);
  3939. $reduceArr = array();
  3940. }
  3941. $result['stu_diff_order'] = $stuDiffOrder;
  3942. $result['stu_order'] = $stuOrderArr;
  3943. $result['increase_stu'] = $increaseArr;
  3944. $result['reduce_stu'] = $reduceArr;
  3945. //前5名和后5名
  3946. $font5 = $back5 = array();
  3947. $i = 1;
  3948. $fonrt5_order = array();
  3949. foreach($stuOrderArr as $stuId => $order){
  3950. if($i <= 5){
  3951. $font5[] = $stuId;
  3952. $fonrt5_order[] = $order;
  3953. }else{
  3954. break;
  3955. }
  3956. $i++;
  3957. }
  3958. $result['font_five'] = $font5;
  3959. $i = 1;
  3960. //删除前5排名
  3961. $_stuOrderArr = $stuOrderArr;
  3962. foreach($_stuOrderArr as $k => $order){
  3963. if(in_array($order,$fonrt5_order)){
  3964. unset($_stuOrderArr[$k]);
  3965. }
  3966. }
  3967. arsort($_stuOrderArr);
  3968. foreach($_stuOrderArr as $stuId => $order){
  3969. if($i <= 5){
  3970. $back5[] = $stuId;
  3971. }else{
  3972. break;
  3973. }
  3974. $i++;
  3975. }
  3976. $result['back_five'] = $back5;
  3977. //学生名称
  3978. $stuInfoObj = new SStudentInfo();
  3979. $stuName = $stuInfoObj->getStudentNames(array_keys($stuOrderArr));
  3980. $result['stu_name'] = $stuName;
  3981. unset($stuOrderArr);
  3982. return $result;
  3983. }
  3984. /**
  3985. * 考试情况分析
  3986. * @param $stuRs
  3987. * @param $topicScore
  3988. * @param $topicNo
  3989. * @return array
  3990. */
  3991. private function getExamAnalyse(&$stuRs,$paperTopicScore,$topicNo,$paperId,$topicRelLarge){
  3992. $result = array();
  3993. $stuTopicWrong = array();//题答错人数
  3994. $topicScoreRate = array();//题得分率
  3995. $topicScoring = array();//题得分
  3996. $topicScore= array();//题分
  3997. foreach($stuRs as $stuId => $rs){
  3998. foreach($rs as $v){
  3999. if($paperId == $v['paper_id']){
  4000. if(isset($topicRelLarge[$v['topic_id']]) && $topicRelLarge[$v['topic_id']] > 0){
  4001. $t_id = $topicRelLarge[$v['topic_id']];
  4002. }else{
  4003. $t_id = $v['topic_id'];
  4004. }
  4005. $t_score = isset($paperTopicScore[$t_id])?$paperTopicScore[$t_id]:0;
  4006. if(!isset($topicScoring[$t_id])){
  4007. $topicScoring[$t_id] = 0;
  4008. }
  4009. $topicScoring[$t_id] += $v['scoring'];
  4010. if(!isset($topicScore[$t_id])){
  4011. $topicScore[$t_id] = 0;
  4012. }
  4013. $topicScore[$t_id] += $t_score;
  4014. if(!isset($stuTopicWrong[$t_id])){
  4015. $stuTopicWrong[$t_id] = array();
  4016. }
  4017. if($t_score != $v['scoring']){
  4018. $stuTopicWrong[$t_id][] = $stuId;
  4019. }
  4020. }
  4021. }
  4022. }
  4023. //题得分率
  4024. foreach($topicScoring as $topicId => $scoring){
  4025. if(isset($topicScore[$topicId]) && $topicScore[$topicId] > 0){
  4026. $topicScoreRate[$topicId] = round($scoring/$topicScore[$topicId],4) * 100;
  4027. }else{
  4028. $topicScoreRate[$topicId] = 0;
  4029. }
  4030. }
  4031. unset($topicScoring);
  4032. //答错人数
  4033. if($stuTopicWrong){
  4034. foreach($stuTopicWrong as $key => $stuIds){
  4035. $stuIds = array_unique($stuIds);
  4036. $stuTopicWrong[$key] = count($stuIds);
  4037. }
  4038. }
  4039. $result['stu_topic_wrong'] = $stuTopicWrong;
  4040. $result['topic_score_rate'] = $topicScoreRate;
  4041. $result['topic_no'] = $topicNo;
  4042. unset($stuTopicWrong);
  4043. unset($topicScoreRate);
  4044. unset($topicNo);
  4045. unset($topicScore);
  4046. return $result;
  4047. }
  4048. //题类型掌握情况
  4049. private function getTopicTypeAnaly(&$stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge){
  4050. $result = array();
  4051. $gradeRate = $classRate = array();//班级和年级得分率
  4052. $stuTypeWrong = array();//题型答错人数
  4053. $typeTopicNo = array();//题型对应的题号
  4054. $typeMasterDegree = array();//题型掌握水平
  4055. $typeName = array('1'=>'选择题','11'=>'不定项选择题','5'=>'填空题','7'=>'解答题','17'=>'选做解答题');
  4056. $logicTypeName = getSubjectTopicType(Yii::app()->session['session_duoxueke_subject_id']);
  4057. $gradeScoreArr = $classScoreArr = array();
  4058. $gradeScoring = $classScoring = array();
  4059. $typeNameArr = array();
  4060. foreach($stuRs as $stuId => $rs){
  4061. foreach ($rs as $k => $value){
  4062. if(isset($topicLogicType[$value['type']]) && $topicLogicType[$value['type']] > 0){
  4063. $type = $topicLogicType[$value['type']];
  4064. $typeArr = explode('_',$type);
  4065. if(count($typeArr) > 1){
  4066. $type = $typeArr[0];
  4067. }
  4068. $typeNameArr[$type] = isset($logicTypeName[$type])?$logicTypeName[$type]:'';
  4069. }else{
  4070. $type = $value['type'];
  4071. $typeNameArr[$type] = isset($typeName[$type])?$typeName[$type]:'';
  4072. }
  4073. if(!isset($gradeScoring[$type])){
  4074. $gradeScoring[$type] = array();
  4075. }
  4076. $gradeScoring[$type][] = $value['scoring'];
  4077. if(!isset($gradeScoreArr[$type])){
  4078. $gradeScoreArr[$type] = 0;
  4079. }
  4080. $gradeScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
  4081. if($paperId == $value['paper_id']){
  4082. if(!isset($classScoring[$type])){
  4083. $classScoring[$type] = 0;
  4084. }
  4085. $classScoring[$type] += $value['scoring'];
  4086. if(!isset($classScoreArr[$type])){
  4087. $classScoreArr[$type] = 0;
  4088. }
  4089. $classScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
  4090. if(!isset($stuTypeWrong[$type])){
  4091. $stuTypeWrong[$type] = 0;
  4092. }
  4093. if($value['is_right'] != 1){
  4094. $stuTypeWrong[$type]++;
  4095. }
  4096. if(!isset($typeTopicNo[$type])){
  4097. $typeTopicNo[$type] = array();
  4098. }
  4099. if(isset($topicNo[$value['topic_id']])){
  4100. $typeTopicNo[$type][] = $topicNo[$value['topic_id']];
  4101. }
  4102. }
  4103. }
  4104. }
  4105. //年级得分率
  4106. foreach($gradeScoring as $type => $scorings){
  4107. if(isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]){
  4108. $gradeRate[$type] = round(array_sum($scorings)/$gradeScoreArr[$type],4) * 100;
  4109. }else{
  4110. $gradeRate[$type] = 0;
  4111. }
  4112. }
  4113. //班级得分率
  4114. foreach ($classScoring as $type => $scoring){
  4115. if(isset($classScoreArr[$type]) && $classScoreArr[$type] > 0){
  4116. $classRate[$type] = round($scoring/$classScoreArr[$type],4) * 100;
  4117. }else{
  4118. $classRate[$type] = 0;
  4119. }
  4120. }
  4121. //题型对应题号排序
  4122. foreach($typeTopicNo as $type => $nos){
  4123. asort($nos);
  4124. $typeTopicNo[$type] = array_unique($nos);
  4125. }
  4126. //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。
  4127. foreach($classRate as $type => $rate){
  4128. if($rate >= 85){
  4129. $typeMasterDegree[$type] = 5;
  4130. }elseif($rate < 85 && $rate >= 75){
  4131. $typeMasterDegree[$type] = 4;
  4132. }elseif($rate < 75 && $rate >= 65){
  4133. $typeMasterDegree[$type] = 3;
  4134. }elseif($rate < 65 && $rate >= 55){
  4135. $typeMasterDegree[$type] = 2;
  4136. }else{
  4137. $typeMasterDegree[$type] = 1;
  4138. }
  4139. }
  4140. $result['class_rate'] = $classRate;
  4141. $result['grade_rate'] = $gradeRate;
  4142. $result['stu_type_wrong'] = $stuTypeWrong;
  4143. $result['type_topic_no'] = $typeTopicNo;
  4144. $result['type_master_degree'] = $typeMasterDegree;
  4145. $result['type_name_arr'] = $typeNameArr;
  4146. return $result;
  4147. }
  4148. /**
  4149. * 试题年级和班级得分率,答对和答错人数
  4150. * @param $stuRs
  4151. * @param $topicScore
  4152. * @param $paperId
  4153. * @return array
  4154. */
  4155. public function getTopicRateWrongPerson(&$stuRs,$topicScore,$paperId,&$stuIdsArr,$topicRelLarge){
  4156. $gradeRate = $classRate = array();//班级和年级得分率
  4157. $wrongStu = $rightStu = array();//答对答错人数
  4158. $stuNormalIds = array();
  4159. foreach($stuIdsArr as $stuIds){
  4160. $stuNormalIds = array_merge($stuNormalIds,$stuIds);
  4161. }
  4162. $gradeScoring = $classScoring = array();
  4163. $gradeScore = $classScore= array();
  4164. $doneTopicNum = array();//每题做题总人数
  4165. foreach($stuRs as $stuId => $rs){
  4166. if(!inArray($stuId,$stuNormalIds)){
  4167. continue;
  4168. }
  4169. foreach ($rs as $k => $value){
  4170. if(isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0){
  4171. $t_id = $topicRelLarge[$value['topic_id']];
  4172. }else{
  4173. $t_id = $value['topic_id'];
  4174. }
  4175. $t_score = isset($topicScore[$t_id])?$topicScore[$t_id]:0;
  4176. if(!isset($gradeScoring[$t_id])){
  4177. $gradeScoring[$t_id] = 0;
  4178. }
  4179. $gradeScoring[$t_id] += $value['scoring'];
  4180. if(!isset($gradeScore[$t_id])){
  4181. $gradeScore[$t_id] = 0;
  4182. }
  4183. $gradeScore[$t_id] += $t_score;
  4184. if($paperId == $value['paper_id']){
  4185. if(!isset($classScoring[$t_id])){
  4186. $classScoring[$t_id] = 0;
  4187. }
  4188. $classScoring[$t_id] += $value['scoring'];
  4189. if(!isset($classScore[$t_id])){
  4190. $classScore[$t_id] = 0;
  4191. }
  4192. $classScore[$t_id] += $t_score;
  4193. if(!isset($wrongStu[$t_id])){
  4194. $wrongStu[$t_id] = array();
  4195. }
  4196. if($t_score != $value['scoring']){
  4197. $wrongStu[$t_id][] = $stuId;
  4198. }
  4199. if(!isset($doneTopicNum[$t_id])){
  4200. $doneTopicNum[$t_id] = array();
  4201. }
  4202. $doneTopicNum[$t_id][] = $stuId;
  4203. }
  4204. }
  4205. }
  4206. //年级得分率
  4207. foreach($gradeScoring as $tId => $scorings){
  4208. if(isset($gradeScore[$tId]) && $gradeScore[$tId] > 0){
  4209. $gradeRate[$tId] = round($scorings/$gradeScore[$tId],4) * 100;
  4210. }else{
  4211. $gradeRate[$tId] = 0;
  4212. }
  4213. }
  4214. //班级得分率
  4215. foreach ($classScoring as $tId => $scoring){
  4216. if(isset($classScore[$tId]) && $classScore[$tId] > 0){
  4217. $classRate[$tId] = round($scoring/$classScore[$tId],4) * 100;
  4218. }else{
  4219. $classRate[$tId] = 0;
  4220. }
  4221. }
  4222. //答错人数
  4223. if($wrongStu){
  4224. foreach($wrongStu as $key => $stuIds){
  4225. $stuIds = array_unique($stuIds);
  4226. $wrongStu[$key] = count($stuIds);
  4227. if(isset($doneTopicNum[$key])){
  4228. $_stuIds = array_unique($doneTopicNum[$key]);
  4229. $rightStu[$key] = count($_stuIds) - $wrongStu[$key];
  4230. }
  4231. }
  4232. }
  4233. $result = array();
  4234. $result['grade_rate'] = $gradeRate;
  4235. $result['class_rate'] = $classRate;
  4236. $result['wrong_stu'] = $wrongStu;
  4237. $result['right_stu'] = $rightStu;
  4238. return $result;
  4239. }
  4240. /**
  4241. * 获取学生排名
  4242. * @param $examId
  4243. * @param $ptrInfo
  4244. * @return array
  4245. */
  4246. private function getStudentOrder($examId,&$ptrInfo,&$stuIdsArr){
  4247. $stuOrderArr = array();
  4248. $stuScoring = array();
  4249. foreach($ptrInfo as $value){
  4250. if($examId == $value['exam_id']){
  4251. $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
  4252. if(inArray($value['student_id'],$stuIds)){
  4253. $stuScoring[$value['student_id']] = (int)$value['scoring'];
  4254. }
  4255. }
  4256. }
  4257. $scoringArr = array_values($stuScoring);
  4258. foreach($stuScoring as $stuId => $scoring){
  4259. $stuOrderArr[$stuId] = $this->getOrder((int)$scoring,$scoringArr);
  4260. }
  4261. if($stuOrderArr){
  4262. asort($stuOrderArr);
  4263. }
  4264. return $stuOrderArr;
  4265. }
  4266. /**
  4267. * 获取排名
  4268. * @param $ele
  4269. * @param $arr
  4270. * @return false|int|string
  4271. */
  4272. private function getOrder($ele,$arr){
  4273. $orderRs = 0;
  4274. if($arr){
  4275. arsort($arr);
  4276. $arr = array_values($arr);
  4277. $index = array_search($ele,$arr);
  4278. $orderRs = $index + 1;
  4279. }
  4280. return $orderRs;
  4281. }
  4282. /**
  4283. * 整理题详情
  4284. * @param $allApiInfo
  4285. * @return mixed
  4286. * @throws CException
  4287. */
  4288. public function getTopicDetail($topicBatches){
  4289. $optionIndex=array('A','B','C','D','E','F','G','H','I','J','K');
  4290. $topicDetails=array();
  4291. foreach ($topicBatches AS $topic) {
  4292. $topic=(object)$topic;
  4293. $type = $topic->type_id;
  4294. 6 == $type && $type =5; //6表示多空题,多空题也是5
  4295. $topic->id = (string)$topic->id;
  4296. $topicDetails[$topic->id]=array();
  4297. $topicDetails[$topic->id]['is_large_topic']=isset($topic->is_large_topic)?$topic->is_large_topic:0;
  4298. $topicDetails[$topic->id]['type']=$type;
  4299. $topicDetails[$topic->id]['subject_id'] = $topic->subject_id;
  4300. $topicDetails[$topic->id]['methods']='';//考点
  4301. $topicDetails[$topic->id]['method_id_arr']='';//考点id数组
  4302. $topicDetails[$topic->id]['kps']='';//知识点
  4303. $topicDetails[$topic->id]['queBody'] =$this->topicProcess($topic->title);//题目详情
  4304. $topicDetails[$topic->id]['options']='';
  4305. $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode)?$topic->parse_video_qrcode:'';
  4306. $topicDetails[$topic->id]['answer']=''; //每题的正确答案
  4307. $topicDetails[$topic->id]['analysis']=$this->topicProcess($topic->parse_content);//答题解析
  4308. $topicDetails[$topic->id]['teacher_tips']=$this->topicProcess($topic->teacher_tips);//名师点评
  4309. $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree)?$topic->difficulty_degree:null;
  4310. $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
  4311. $_methods = array();
  4312. $_method_id_arr = array();
  4313. $_method_names = array();
  4314. if ($topic->specials) {
  4315. foreach ($topic->specials AS $_method) {
  4316. $_method = (object)$_method;
  4317. if ($_method->method_name) {
  4318. $_methods[] = $_method->method_name;
  4319. }
  4320. if (isset($_method->method_id)) {
  4321. $_method_id_arr[] = $_method->method_id;
  4322. }
  4323. if(isset($_method->method_id) && isset($_method->method_name)){
  4324. $_method_names[$_method->method_id] = $_method->method_name;
  4325. }
  4326. }
  4327. $topicDetails[$topic->id]['methods']=implode('|', array_unique($_methods));//考点
  4328. $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
  4329. $topicDetails[$topic->id]['method_names'] = $_method_names;
  4330. }
  4331. $_kps = array();
  4332. if (isset($topic->kps) && $topic->kps) {
  4333. foreach ($topic->kps as $_kp) {
  4334. $_kp = (object)$_kp;
  4335. if ($_kp->kp_name) {
  4336. $_kps[$_kp->kp_id] = $_kp->kp_name;
  4337. }
  4338. }
  4339. $topicDetails[$topic->id]['kps'] = $_kps;//考点
  4340. }
  4341. if($topic->type_id==1 || $topic->type_id==11){ //选择题有选项
  4342. if ($topic->items) {
  4343. if (isset($topic->items[0])) {
  4344. $topic->items[0] = (object)$topic->items[0];
  4345. if (isset($topic->items[0]->options)) {
  4346. $options = $topic->items[0]->options;
  4347. if ($options) {
  4348. $_tmp_options = array();
  4349. $correct_answer_arr = array();
  4350. foreach ($options AS $_optionIndex => $_option) {
  4351. $_option = (object)$_option;
  4352. $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content);
  4353. if($_option->option_correct){
  4354. $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]);
  4355. // $topicDetails[$topic->id]['answer']=topicProcess($optionIndex[$_optionIndex]);
  4356. }
  4357. }
  4358. $topicDetails[$topic->id]['answer'] = implode(',',$correct_answer_arr);
  4359. $_list_type= (int)$topic->items[0]->list_type;
  4360. $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options,$_list_type);
  4361. }
  4362. }
  4363. }
  4364. }
  4365. }else{
  4366. if ($topic->items) {
  4367. if (isset($topic->items[0])) {
  4368. $topic->items[0] = (object)$topic->items[0];
  4369. if (isset($topic->items[0]->options)) {
  4370. $options = $topic->items[0]->options;
  4371. if ($options) {
  4372. $_answer = '';
  4373. foreach ($options as $v) {
  4374. $_option = (object)$v;
  4375. if (trim($_answer) != ''){
  4376. $_answer .= ' ; ';
  4377. }
  4378. $_answer .= $_option->option_content;
  4379. }
  4380. $topicDetails[$topic->id]['answer']=$this->topicProcess($_answer);
  4381. }
  4382. }
  4383. }
  4384. }
  4385. }
  4386. //大题的小题
  4387. $topicDetails[$topic->id]['slave']=array();
  4388. if(isset($topic->slave) && $topic->slave){
  4389. $topicDetails[$topic->id]['answer'] = array();
  4390. foreach($topic->slave as $slave){
  4391. $slave = (object)$slave;
  4392. $_slave = array();
  4393. $_slave['topic_slave_id']=(string)$slave->topic_slave_id;
  4394. $_slave['type']=$slave->topic_type;
  4395. $_slave['methods']='';//考点
  4396. $_slave['method_id_arr']='';//考点id数组
  4397. $_slave['kps']='';//知识点
  4398. $_slave['queBody'] =$this->topicProcess($slave->title);//题目详情
  4399. $_slave['options']='';
  4400. $_slave['answer']=''; //每题的正确答案
  4401. // $_slave['analysis']=topicProcess($slave->parse_content);//答题解析
  4402. // $_slave['teacher_tips']=topicProcess($slave->teacher_tips);//名师点评
  4403. $_slave['difficulty_degree'] = isset($slave->difficulty_degree)?$slave->difficulty_degree:null;
  4404. $_slave['difficulty'] = $slave->difficulty;
  4405. if($slave->topic_type==1 || $slave->topic_type==11){ //选择题有选项
  4406. if ($slave->items) {
  4407. if (isset($slave->items)) {
  4408. $slave->items = (object)$slave->items;
  4409. if (isset($slave->items->options)) {
  4410. $options = (object)$slave->items->options;
  4411. if ($options) {
  4412. $_tmp_options = array();
  4413. $correct_answer_arr = array();
  4414. foreach ($options AS $_optionIndex => $_option) {
  4415. $_option = (object)$_option;
  4416. $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content);
  4417. if($_option->option_correct){
  4418. $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]);
  4419. // $topicDetails[$slave->id]['answer']=topicProcess($optionIndex[$_optionIndex]);
  4420. }
  4421. }
  4422. $_slave['answer'] = implode(',',$correct_answer_arr);
  4423. $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
  4424. $_list_type= (int)$slave->items->list_type;
  4425. $_slave['options'] = $this->option_process($_tmp_options,$_list_type);
  4426. }
  4427. }
  4428. }
  4429. }
  4430. }else{
  4431. if ($slave->items) {
  4432. if (isset($slave->items)) {
  4433. $slave->items = (object)$slave->items;
  4434. if (isset($slave->items->options)) {
  4435. $options = (object)$slave->items->options;
  4436. if ($options) {
  4437. $_answer = '';
  4438. foreach ($options as $v) {
  4439. $_option = (object)$v;
  4440. if (trim($_answer) != ''){
  4441. $_answer .= ' ; ';
  4442. }
  4443. $_answer .= $_option->option_content;
  4444. }
  4445. $_slave['answer'] = $this->topicProcess($_answer);
  4446. $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
  4447. }
  4448. }
  4449. }
  4450. }
  4451. }
  4452. $topicDetails[$topic->id]['slave'][] = $_slave;
  4453. }
  4454. }
  4455. }
  4456. return $topicDetails;
  4457. }
  4458. /**
  4459. *对选项的处理
  4460. * @param $options
  4461. * @param $list_type
  4462. * @return string
  4463. */
  4464. public function option_process($options,$list_type){
  4465. $option_index=array('A','B','C','D','E','F','G','H','I','J');
  4466. if($list_type==0) { //纵向排列,即1行1个
  4467. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  4468. $option_str="";
  4469. foreach($options as $key=>$option){
  4470. $option_str.="<li style='width:100%;'>$option_index[$key].$option</li>";
  4471. }
  4472. // $option_str.="</ul>";
  4473. }elseif($list_type==1) { //横向排列,即1行4个
  4474. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  4475. $option_str="";
  4476. foreach($options as $key=>$option){
  4477. $option_str.="<li class='fl'>$option_index[$key].$option</li>";
  4478. }
  4479. // $option_str.="</ul>";
  4480. }elseif($list_type==2){ //1行2个
  4481. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  4482. $option_str="";
  4483. foreach($options as $key=>$option){
  4484. if($key%2==0) {
  4485. $option1=$options[$key];
  4486. $option_str2="<li class='fl' style='width:50%;'>$option_index[$key].$option1</li>";
  4487. $key1=$key+1;
  4488. if(isset($options[$key1])){
  4489. $option2=$options[$key1];
  4490. $option_str2.="<li class='fl' style='width:50%;'>$option_index[$key1].$option2</li>";
  4491. }
  4492. $option_str.=$option_str2;
  4493. }else{
  4494. continue;
  4495. }
  4496. }
  4497. // $option_str.="</ul>";
  4498. }
  4499. return $option_str;
  4500. }
  4501. public function topicProcess($html) {
  4502. preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',$html,$arr);
  4503. foreach($arr[0] as $v){
  4504. $process_str=$this->img_process($v);
  4505. $html = str_replace($v,$process_str,$html);
  4506. }
  4507. $html=preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si','',$html);
  4508. $html=preg_replace('/<p\s*>/','',$html);
  4509. $html=preg_replace('/<\/p>/','',$html);
  4510. $html=preg_replace('/<br\/*>/','',$html);
  4511. $html=preg_replace('/<big\s*>/','',$html);
  4512. $html=preg_replace('/<\/big>/','',$html);
  4513. $html=str_replace("&nbsp;",'',$html);
  4514. return $html;
  4515. }
  4516. public function img_process($img){
  4517. $widthArr = array();
  4518. $heightArr = array();
  4519. $width = '';
  4520. $height = '';
  4521. preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr);
  4522. if ($widthArr) {
  4523. $width = $this->length_process($widthArr);
  4524. } else {
  4525. preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr);
  4526. if($widthArr) {
  4527. $width = $this->length_process($widthArr);
  4528. }
  4529. }
  4530. if ($width) {
  4531. $width = "width=".$width;
  4532. }
  4533. preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr);
  4534. if ($heightArr) {
  4535. $height = $this->length_process($heightArr);
  4536. } else {
  4537. preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr);
  4538. if($heightArr) {
  4539. $height = $this->length_process($heightArr);
  4540. }
  4541. }
  4542. if ($height) {
  4543. $height = "height=".$height;
  4544. }
  4545. $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"<img ".$width." ".$height." $1 />",$img);
  4546. return $return_img;
  4547. }
  4548. public function length_process($length_arr){
  4549. $units = array(
  4550. 'in' => 96,
  4551. 'cm' => 28,
  4552. 'mm' => 2.8,
  4553. 'pt' => 1.33,
  4554. 'pc' => 12,
  4555. );
  4556. $length = 0.6*$length_arr[1];
  4557. $unit_keys = array_keys($units);
  4558. if (isset($length_arr[2])) {
  4559. //将直接连接单位改为 单位换算
  4560. if(in_array($length_arr[2],$unit_keys)){
  4561. $length = $length*$units[$length_arr[2]];
  4562. }else {
  4563. $length .= $length_arr[2];
  4564. }
  4565. }
  4566. return $length;
  4567. }
  4568. /********************* 第三方教学宝结束 *********************/
  4569. //导入线下考试成绩
  4570. public function actionImport(){
  4571. $examGroupId=Req::get('examgroupid');
  4572. if (Yii::app()->request->getIsPostRequest()){
  4573. ini_set('memory_limit','300M');
  4574. $examGroupId=Req::post('examgroupid');
  4575. $card=Req::post('card');
  4576. if(!$examGroupId){
  4577. Yii::app()->jump->error('请先创建考试');
  4578. }
  4579. if($card==1){
  4580. $filed='student_card';
  4581. }elseif($card==2){
  4582. $filed='school_student_card';
  4583. }else{
  4584. Yii::app()->jump->error('考号类型不正确');
  4585. }
  4586. $uploader = new Uploader("upload/tmpDir/UploadStudentScore/{$this->schoolId}/");
  4587. $uploader->allowTypes = array('xls','xlsx');
  4588. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  4589. $file = $uploader->act();
  4590. $file = Arr::current(Arr::current($file));
  4591. if(!$file || !isset($file["error"]))
  4592. Yii::app()->jump->error('请选择上传的Excel!');
  4593. if($file["error"] != 0){
  4594. switch($file["error"]){
  4595. case 2001:
  4596. Yii::app()->jump->error('文件类型不符');
  4597. break;
  4598. case 2002:
  4599. Yii::app()->jump->error('文件大小超出允许范围');
  4600. break;
  4601. default:
  4602. Yii::app()->jump->error('上传失败');
  4603. break;
  4604. }
  4605. }
  4606. $result = true;
  4607. $inputFileName = $file["src"];
  4608. $semesterId = $this->semesterId;
  4609. Yii::import('application.extensions.*');
  4610. require_once('phpexcel/PHPExcel/IOFactory.php');
  4611. // 读取Excel文档
  4612. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  4613. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  4614. //FIXME 2019-12-02
  4615. @unlink($file["src"]);
  4616. // 去掉导航
  4617. unset($sheetData[1]);
  4618. if(!$sheetData){
  4619. Yii::app()->jump->error('成绩数据不能为空');
  4620. }
  4621. $sheetData=array_values($sheetData);
  4622. //读取考试信息
  4623. $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$examGroupId."'")->queryAll();
  4624. if(!$exam){
  4625. Yii::app()->jump->error('考试ID不正确,请从考试列表点击上传成绩');
  4626. }
  4627. $tpl_data=json_decode($exam[0]['tpl_data'],true);
  4628. if(!$tpl_data || !isset($tpl_data['totals']) || !isset($tpl_data['new_items'])){
  4629. Yii::app()->jump->error('考试数据错误,请检查考试数据');
  4630. }
  4631. $checkData=$sheetData[0]; //提取一条数据用与校验
  4632. if(empty($checkData['A']) || empty($checkData['B']) || empty($checkData['C'])){
  4633. Yii::app()->jump->error('文件格式不正确,请检查后上传');
  4634. }
  4635. if(count($checkData)-$tpl_data['totals']!=3){
  4636. Yii::app()->jump->error('成绩对应题目数量与考试设置不一致,请检查后上传');
  4637. }
  4638. //取得试卷topic
  4639. $paperIds=array();
  4640. foreach ($exam as $value){
  4641. $paperIds[]=$value['paper_id'];
  4642. }
  4643. $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
  4644. if(!$paper_topic_relation){
  4645. Yii::app()->jump->error('试卷创建不成功,请重新检查');
  4646. }
  4647. $paper_topic_rs=array();
  4648. foreach ($tpl_data['new_items'] as $key=>$value){
  4649. $paper_topic_rs[$paper_topic_relation[$key]['topic_id']]=$value;
  4650. $tpl_data['new_items'][$key]['topic_id']=$paper_topic_relation[$key]['topic_id'];
  4651. }
  4652. $studentCardAll=array();
  4653. //更新student_paper_relation ,新增student_paper_topic_rs
  4654. $sql='INSERT INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE ';
  4655. $transaction = $this->sConn->beginTransaction();
  4656. try{
  4657. $error=array();
  4658. $valueSql=array();
  4659. foreach ($sheetData as $item){
  4660. $studentCard=$item['B'];
  4661. $studentName=$item['A'];
  4662. $studentClass=$item['C'];
  4663. if(!$studentCard || !$studentName || !$studentClass){
  4664. $error[]='学生信息缺失,姓名:'.$studentName.',准考证号:'.$studentCard.',学生班级:'.$studentClass;
  4665. continue;
  4666. }
  4667. if(in_array($studentCard,$studentCardAll)){
  4668. $error[]='准考证号重复:'.$studentCard;
  4669. continue;
  4670. }
  4671. $studentCardAll[]=$studentCard;
  4672. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where ".$filed."='".$studentCard."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  4673. if(!$StudentPaperRelation){
  4674. $error[]='学生没有参加本次考试 :'.$studentCard;
  4675. continue;
  4676. }
  4677. $studentId=$StudentPaperRelation['student_id'];
  4678. $paper_id=$StudentPaperRelation['paper_id'];
  4679. $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$studentId."' ")->queryRow();
  4680. if(!$StudentInfo || $StudentInfo['realname']!=$studentName){
  4681. $error[]='学生姓名和准考证号不对应 :'.$studentCard;
  4682. continue;
  4683. }
  4684. $this->sConn->createCommand("delete from `student_paper_topic_rs` where student_id='".$studentId."' and paper_id='".$paper_id."' ")->execute();
  4685. $topicScoreData=$item;
  4686. unset($topicScoreData['A']);
  4687. unset($topicScoreData['B']);
  4688. unset($topicScoreData['C']);
  4689. $topicScoreData=array_values($topicScoreData);
  4690. $score_get=0;
  4691. $lost_score=0;
  4692. foreach($topicScoreData as $key=> $ts){
  4693. if(!$ts){
  4694. $ts=0;
  4695. }
  4696. $score=0;
  4697. $is_right=1;
  4698. if($ts>=$tpl_data['new_items'][$key]['score']){
  4699. $score=$tpl_data['new_items'][$key]['score'];
  4700. }else{
  4701. $score=$ts;
  4702. $lost_score+=($tpl_data['new_items'][$key]['score']-$ts);
  4703. $is_right=0;
  4704. }
  4705. if(!$score){
  4706. $score=0;
  4707. }
  4708. $score_get+=$score;
  4709. $topic_id= $tpl_data['new_items'][$key]['topic_id'];
  4710. // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
  4711. // $uuid = current(current($uuid));
  4712. $uuid =getUniqueId($this->schoolId);
  4713. $valueSql[]=' ('.$uuid.','.$studentId.','.$paper_id.','.$topic_id.',1,'.$score.','.$is_right.') ';
  4714. }
  4715. $updateSql=" update `student_paper_relation` set complete_count='".$tpl_data['totals']."',`scoring`='".$score_get."',`lost_score`='".$lost_score."',is_feedback=1,feedback_time='".time()."',is_complete=1";
  4716. $updateSql.=" where student_id='".$studentId."' and paper_id='".$paper_id."' ";
  4717. $this->sConn->createCommand($updateSql)->execute();
  4718. }
  4719. if($valueSql){
  4720. $sql.=implode(',',$valueSql);
  4721. $this->sConn->createCommand($sql)->execute();
  4722. }
  4723. Exam::model()->updateAll(array('status'=>1,'upload_status'=>2,'complete_time'=>time()),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  4724. ExamGroup::model()->updateAll(array('mark_status'=>1,'status'=>2,'upload_status'=>1,'import_score_type'=>2),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  4725. $transaction->commit();
  4726. $kafkaData=array(
  4727. 'schoolId'=>$this->schoolId,
  4728. 'examGroupId'=>$examGroupId,
  4729. 'generateTime'=>time()*1000
  4730. );
  4731. sendDataToKafka("zsyte-academic-offline-generate-report",$kafkaData);
  4732. if($error){
  4733. // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
  4734. $this->render('import_underline_error',array('data'=>$error));
  4735. }else{
  4736. Yii::app()->jump->error('导入成功');
  4737. }
  4738. } catch (Exception $e) {
  4739. //如果操作失败, 数据回滚
  4740. $transaction->rollback();
  4741. Yii::app()->jump->error('成绩导入失败,请检查后重新');
  4742. }
  4743. }else{
  4744. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
  4745. $data['subject']=$subject_exam_data;
  4746. $data['exam_group_id']=$examGroupId;
  4747. $data['printType']=2;
  4748. $this->render('score_import',$data);
  4749. }
  4750. }
  4751. //编辑第三方线下考试
  4752. public function actionEditThirdUnderLine(){
  4753. $examGroupId=Req::get('examgroupid'); //统考Id
  4754. if(!$examGroupId){
  4755. Yii::app()->jump->error('请从考试列表进入编辑');
  4756. }
  4757. $exam=new SExam();
  4758. $sql=" select e.exam_id,e.tpl_data,p.paper_id,e.name,eg.teacher_id,e.class_id,e.type from exam_group eg ";
  4759. $sql .=" join exam e on eg.exam_group_id=e.exam_group_id ";
  4760. $sql.=" join paper p on p.exam_id=e.exam_id ";
  4761. $sql.=" where e.exam_group_id=".$examGroupId;
  4762. $examlist = $this->sConn->createCommand($sql)->queryAll();
  4763. if(!$examlist){
  4764. Yii::app()->jump->error('考试ID不正确');
  4765. }
  4766. $tpl_data=json_decode($examlist[0]['tpl_data'],true);
  4767. $paperInfo=array(
  4768. 'paper_name'=>$examlist[0]['name'],
  4769. 'type' =>$examlist[0]['type'],
  4770. 'teacher_id'=>$examlist[0]['teacher_id'],
  4771. 'exam_date'=>$tpl_data['examDate'],
  4772. );
  4773. foreach ($examlist as $value){
  4774. $paperInfo['class_id'][]=$value['class_id'];
  4775. }
  4776. //处理题型
  4777. $topic_type_data=array();
  4778. if(isset($tpl_data['new_items'])){
  4779. foreach($tpl_data['new_items'] as $item){
  4780. if(isset($topic_type_data[$item['logic_type']]['count'])){
  4781. $topic_type_data[$item['logic_type']]['count']++;
  4782. }else{
  4783. $topic_type_data[$item['logic_type']]['count']=1;
  4784. }
  4785. $topic_type_data[$item['logic_type']]['score'][]=$item['score'];
  4786. if(isset($topic_type_data[$item['logic_type']]['total_score'])){
  4787. $topic_type_data[$item['logic_type']]['total_score']+=$item['score'];
  4788. }else{
  4789. $topic_type_data[$item['logic_type']]['total_score']=$item['score'];
  4790. }
  4791. }
  4792. }
  4793. $paperInfo['topic']=$topic_type_data;
  4794. $printType = Req::get("type");
  4795. if (empty($printType)) {
  4796. $printType = '2';
  4797. $printTypeData = 0;
  4798. } else {
  4799. switch ($printType) {
  4800. case "2":
  4801. $printTypeData = 0;
  4802. break;
  4803. case "wtb":
  4804. $printTypeData = 1;
  4805. break;
  4806. case "isp":
  4807. $printTypeData = 2;
  4808. break;
  4809. case "studytrend":
  4810. $printTypeData = 3;
  4811. break;
  4812. default:
  4813. $printTypeData = null;
  4814. break;
  4815. }
  4816. }
  4817. $data['printType'] = $printType;
  4818. // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
  4819. // $semester_id = Yii::app()->session['session_semester_id'];
  4820. $coach_id = $this->coachId;
  4821. $semester_id = $this->semesterId;
  4822. // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
  4823. $criteria = new CDbCriteria();
  4824. if(Yii::app()->session['session_duoxueke_subject_id']==3)
  4825. {
  4826. $criteria->addInCondition('subjects',$this->mathSubjectId);
  4827. }else
  4828. {
  4829. if(Yii::app()->session['session_duoxueke_subject_id']==18){
  4830. $criteria->addInCondition('subjects',array(12,13,14));
  4831. }
  4832. if(Yii::app()->session['session_duoxueke_subject_id']==19){
  4833. $criteria->addInCondition('subjects',array(15,16,17));
  4834. }
  4835. if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
  4836. $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
  4837. }
  4838. }
  4839. $criteria->addCondition('status = 0');
  4840. $teacher_data = Teacher::model()->findAll($criteria);
  4841. unset($criteria);
  4842. $teacher_arr = array();
  4843. if($teacher_data){
  4844. $i = 0;
  4845. foreach($teacher_data as $v){
  4846. $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
  4847. $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
  4848. $i++;
  4849. }
  4850. }
  4851. $data['teacher_arr'] = $teacher_arr;
  4852. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  4853. {
  4854. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  4855. }else
  4856. {
  4857. $data["use_zhixue"] = 0;
  4858. }
  4859. $teacherSubjectIds = array(3, 6);
  4860. $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
  4861. $teacherSubjectMaterialIds = array();
  4862. $teacherSubjectMaterialNames = array();
  4863. foreach ($teacherSubjectIds as $teacherSubjectId) {
  4864. $teacherSubjectMaterialIds[$teacherSubjectId] = array();
  4865. $teacherSubjectMaterialNames[$teacherSubjectId] = array();
  4866. $textbookTree = $this->apiPost('/textbook/tree', array(
  4867. 'subjectId' => $teacherSubjectId,
  4868. 'depth' => 3
  4869. ));
  4870. if (! $textbookTree) {
  4871. $error[] = 'Brain textbook/tree error';
  4872. } elseif (isset($textbookTree->error)) {
  4873. $error[] = $textbookTree->error;
  4874. } else {
  4875. foreach ($textbookTree as $textbook) {
  4876. if (isset($textbook->modules)) {
  4877. foreach ($textbook->modules as $module) {
  4878. if (isset($module->chapters)) {
  4879. $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
  4880. $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
  4881. }
  4882. }
  4883. }
  4884. }
  4885. }
  4886. }
  4887. //
  4888. $data['teacherSubjectIds'] = $teacherSubjectIds;
  4889. $data['teacherSubjectNames'] = $teacherSubjectNames;
  4890. $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
  4891. $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
  4892. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
  4893. $data['subject']=$subject_exam_data;
  4894. $data['examgroupid']=$examGroupId;
  4895. $data['tpl_data']=$tpl_data;
  4896. $data['printType']=2;
  4897. $data['paper']=$paperInfo;
  4898. $this->render('index_edit_underline',$data);
  4899. }
  4900. //导入线下考试成绩创建考试
  4901. public function actionCreatethirdunderline(){
  4902. $error = array();
  4903. $tplData = array();
  4904. $semesterId = $this->semesterId;
  4905. $examName = Req::post("examName");
  4906. $type = (int)Req::post("type");
  4907. $classIds = Req::post("classIds");
  4908. $paperType = (int)Req::post("paperType");
  4909. $teacherId = Req::post("teacherId");
  4910. $textbookId = Req::post("textbookId");
  4911. $subjectId = Req::post("subjectId");
  4912. $examDate = Req::post("examDate");
  4913. $ExamGroupId=Req::post('exam_group_id');
  4914. $topic_data=htmlspecialchars_decode(Req::post('topic_data'));
  4915. $tpl_index = $paperType;
  4916. $result=array('status'=>0);
  4917. if(!$topic_data){
  4918. $error[] = '请设置试题数据';
  4919. }
  4920. if(empty($classIds)){
  4921. $error[] = '请指定考试班级';
  4922. }else{
  4923. $classIds = explode(',',substr($classIds,0,-1));
  4924. }
  4925. if(empty($examName)){
  4926. $error[] = '请设置考试名称';
  4927. }
  4928. if ($type <= 0 || $type > 9) {
  4929. $error[] = '考试类型错误';
  4930. }
  4931. if(!in_array($paperType,array(0,1,2,1050))){
  4932. $error[] = '请选择正确的试卷类型';
  4933. }
  4934. if(empty($teacherId)){
  4935. $error[] = '请指定阅卷老师';
  4936. }
  4937. if(empty($examDate)){
  4938. $error[] = '请指定考试时间';
  4939. }
  4940. if($error){
  4941. //Yii::app()->jump->error(implode(',',$error));
  4942. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  4943. }else{
  4944. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  4945. if($teacherName){
  4946. $tplData['author'] = $teacherName;
  4947. $tplData['subjectId'] = $subjectId;
  4948. $tplData['textbookId'] = $textbookId;
  4949. $tplData['examDate'] = $examDate;
  4950. }
  4951. //处理试题信息组装tpl_data
  4952. $topic_data=json_decode($topic_data,true);
  4953. $topic_num=1;
  4954. $new_items=array();
  4955. $totals=0;
  4956. $total_score=0;
  4957. foreach ($topic_data as $datum){
  4958. $i=0;
  4959. $totals+=$datum['topic_count'];
  4960. $score=explode(',',$datum['topic_score']);
  4961. while ($datum['topic_count']>0){
  4962. if(!isset($score[$i])){
  4963. $error[]='分数设置不正确';
  4964. Yii::app()->jump->error(implode(',',$error));
  4965. }
  4966. $new_items[]=array(
  4967. 'id'=>$topic_num,
  4968. 'score'=>$score[$i],
  4969. 'topic_type'=>7,
  4970. 'logic_type'=>$datum['topic_type'],
  4971. );
  4972. $datum['topic_count']--;
  4973. $topic_num++;
  4974. $total_score+=$score[$i];
  4975. $i++;
  4976. }
  4977. }
  4978. $tplData['totals']=$totals;
  4979. $tplData['total_score']=$total_score;
  4980. $tplData['new_items']=$new_items;
  4981. $time = time();
  4982. $transaction = $this->sConn->beginTransaction();
  4983. try{
  4984. if(!$ExamGroupId){
  4985. // $newExamGroupId = $this->UUID_SHORT();
  4986. $newExamGroupId=getUniqueId($this->schoolId);
  4987. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`import_score_type`) "
  4988. . "values (".$newExamGroupId.",".$teacherId.",0,0,1,2)";
  4989. $this->sConn->createCommand($sql)->execute();
  4990. }else{
  4991. //删除原exam,paper,paper_topic_relation,class_exam_printer,student_paper_relation
  4992. $sql=" select e.exam_id,e.tpl_data,p.paper_id,e.name,eg.teacher_id,e.class_id,e.type from exam_group eg ";
  4993. $sql .=" join exam e on eg.exam_group_id=e.exam_group_id ";
  4994. $sql.=" join paper p on p.exam_id=e.exam_id ";
  4995. $sql.=" where e.exam_group_id=".$ExamGroupId;
  4996. $examlist = $this->sConn->createCommand($sql)->queryAll();
  4997. if(!$examlist){
  4998. exit(json_encode(array('status'=>0,'msg'=>'考试ID不正确')));
  4999. }
  5000. $oldExamIds=array();
  5001. $oldPaperIds=array();
  5002. foreach($examlist as $item){
  5003. $oldExamIds[]=$item['exam_id'];
  5004. $oldPaperIds[]=$item['paper_id'];
  5005. }
  5006. if(!$oldExamIds || !$oldPaperIds){
  5007. exit(json_encode(array('status'=>0,'msg'=>'考试数据错误')));
  5008. }
  5009. $this->sConn->createCommand("delete from exam where exam_id in(".implode(',',$oldExamIds).")")->execute();
  5010. $this->sConn->createCommand("delete from paper where paper_id in(".implode(',',$oldPaperIds).")")->execute();
  5011. $this->sConn->createCommand("delete from paper_topic_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute();
  5012. $this->sConn->createCommand("delete from class_exam_printer where exam_id in(".implode(',',$oldExamIds).")")->execute();
  5013. $this->sConn->createCommand("delete from student_paper_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute();
  5014. $this->sConn->createCommand("update exam_group set teacher_id='".$teacherId."' where exam_group_id='".$ExamGroupId."'")->execute();
  5015. $newExamGroupId=$ExamGroupId;
  5016. }
  5017. $paperIds=array();
  5018. foreach($classIds as $classId){
  5019. //$newExamId = $this->UUID_SHORT();
  5020. $newExamId=getUniqueId($this->schoolId);
  5021. $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
  5022. $cardData = $this->sConn->createCommand($sql)->queryRow();
  5023. if($cardData['card_status']==0){
  5024. $cardData['card_length'] = 8;
  5025. if($this->schoolId >999){
  5026. $cardData['card_length'] = 9;
  5027. }
  5028. }
  5029. $this->sConn->createCommand()->insert('exam',array(
  5030. 'exam_id' => $newExamId,
  5031. 'exam_group_id' => $newExamGroupId,
  5032. 'name' => $examName,
  5033. 'semester_id' => $this->semesterId,
  5034. 'teacher_id' => $teacherId,
  5035. 'subject_id' => $subjectId,
  5036. 'module_id' => 0,
  5037. 'type' => $type,
  5038. 'school_card_status' => $cardData['card_status'],
  5039. 'school_card_length' => $cardData['card_length'],
  5040. 'status' => 2,
  5041. 'week_num' => 0,
  5042. 'create_type' => 0,
  5043. 'create_time' => $time,
  5044. 'update_time' => $time,
  5045. 'tpl_data' => jsonEncode($tplData),
  5046. 'tpl_index' => $tpl_index,
  5047. 'class_id' => $classId,
  5048. 'method_ids' => '',
  5049. ));
  5050. //$newPaperId = $this->UUID_SHORT();
  5051. $newPaperId=getUniqueId($this->schoolId);
  5052. $this->sConn->createCommand()->insert('paper', array(
  5053. 'paper_id' => $newPaperId,
  5054. 'paper_type' => 1,
  5055. 'exam_id' => $newExamId,
  5056. 'paper_name' => '',
  5057. 'paper_layer' => '',
  5058. 'difficulty' => 0,
  5059. 'topics_count' => 0,
  5060. 'score' => $total_score,
  5061. 'add_time' => $time,
  5062. 'update_time' => $time,
  5063. 'method_ids' => '',
  5064. 'is_labelled' => 0,
  5065. ));
  5066. $paperIds[]=$newPaperId;
  5067. $this->sConn->createCommand()->insert('class_exam_printer', array(
  5068. 'class_id' => $classId,
  5069. 'exam_id' => $newExamId,
  5070. 'type' => 0,
  5071. 'is_print' => 1,
  5072. 'print_time' => 0,
  5073. 'add_time' => $time,
  5074. ));
  5075. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  5076. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  5077. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  5078. if($studentIds_0){
  5079. foreach ($studentIds_0 as $studentId) {
  5080. $this->sConn->createCommand()->insert('student_paper_relation', array(
  5081. 'student_id' => $studentId,
  5082. 'paper_id' => $newPaperId,
  5083. 'exam_id' => $newExamId,
  5084. 'semester_id' => $this->semesterId,
  5085. 'class_id' => $classId,
  5086. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  5087. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  5088. ));
  5089. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  5090. 'student_id' => $studentId,
  5091. 'paper_id' => $newPaperId,
  5092. 'exam_id' => $newExamId,
  5093. 'semester_id' => $this->semesterId,
  5094. 'class_id' => $classId,
  5095. 'create_time' =>$time
  5096. ));
  5097. }
  5098. }
  5099. }
  5100. //写入试题,关联信息
  5101. foreach ($new_items as $key=>$item){
  5102. $this->sConn->createCommand()->insert('topic', array(
  5103. 'topic_type' =>7,
  5104. 'topic_title' => '',
  5105. 'folder_id' => '0',
  5106. 'subject_id' => $subjectId,
  5107. 'is_delete' =>1,
  5108. 'creator_id' => $teacherId,
  5109. 'updater_id' => $teacherId,
  5110. 'is_word_topic'=>1,
  5111. 'create_time' => time(),
  5112. 'update_time' => time(),
  5113. ));
  5114. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  5115. $topic_id=$last_insert_id['last_insert_id()'];
  5116. $this->sConn->createCommand()->insert('topic_item', array(
  5117. 'topic_id' => $topic_id,
  5118. 'topic_type' => 7,
  5119. 'topic_title' => ''
  5120. ));
  5121. $this->sConn->createCommand()->insert('topic_use', array(
  5122. 'topic_id' => $topic_id,
  5123. 'mode' => 1,
  5124. 'teacher_id' => $teacherId,
  5125. 'paper_id' =>$paperIds[0]
  5126. ));
  5127. foreach($paperIds as $kp=>$p)
  5128. {
  5129. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  5130. 'paper_id' => $p,
  5131. 'topic_id' => $topic_id,
  5132. 'no' => $item['id'],
  5133. 'order' => $item['id'],
  5134. 'mode' => 1,
  5135. 'type' => 7,
  5136. 'score' =>$item['score']
  5137. ));
  5138. }
  5139. }
  5140. $transaction->commit();
  5141. }catch (Exception $e){
  5142. $transaction->rollBack();
  5143. exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
  5144. }
  5145. }
  5146. exit(json_encode(array('status'=>1,'msg'=>'保存成功')));
  5147. //$this->redirect($this->createUrl('third/index?list_type=1'));
  5148. }
  5149. private function numToLetter($num){
  5150. $index = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  5151. return substr($index,$num,1);
  5152. }
  5153. // 英语上传试卷答案解析
  5154. public function actionUploadEnglishPaper(){
  5155. // $error['success'] = 123;
  5156. // $error['message'] = '上传文件成功!';
  5157. // var_dump($_FILES);exit;
  5158. // echo json_encode($_FILES);exit();
  5159. $exam_group_id = Req::post('examGroupId');
  5160. $uploadOne = Req::post('uploadOne');
  5161. $paper_exam = array();
  5162. $paper_answer = array();
  5163. $paper_exam_url = array();
  5164. $paper_answer_url = array();
  5165. $paper_exam_url_str = '';
  5166. $paper_answer_url_str = '';
  5167. $error['success'] = 0;
  5168. if (empty($exam_group_id)) {
  5169. $error['message'] = '考试id不存在!';
  5170. echo json_encode($error);exit();
  5171. }
  5172. $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  5173. if (empty($examInfo)) {
  5174. $error['message'] = '未找到试卷信息!';
  5175. echo json_encode($error);exit();
  5176. }else{
  5177. $exam_name = $examInfo['name'];
  5178. $tplData = json_decode($examInfo["tpl_data"], true);
  5179. //考试时间
  5180. if(isset($tplData['examDate']))
  5181. {
  5182. $exam_time = strtotime($tplData["examDate"]);
  5183. }else{
  5184. $exam_time = 0;
  5185. }
  5186. }
  5187. $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  5188. if (empty($thirdSheet)) {
  5189. $error['message'] = '尚未上传答题卡!';
  5190. echo json_encode($error);exit();
  5191. }
  5192. if (empty($_FILES)) {
  5193. $error['message'] = '未找到上传文件!';
  5194. echo json_encode($error);exit();
  5195. }else{
  5196. foreach($_FILES as $k=>$v){
  5197. if(isset($v) && !empty($v)){
  5198. if(!isset($v['size']) || $v['size'] >= 8388608){
  5199. $error['message'] = '文件超过8M!';
  5200. echo json_encode($error);exit();
  5201. }
  5202. if(!isset($v['name']) || !in_array(substr($v['name'],strrpos($v['name'],'.')+1),array('doc','docx','pdf','bmp','jpg','jpeg','png'))){
  5203. $error['message'] = '文件格式不正确!';
  5204. echo json_encode($error);exit();
  5205. }
  5206. if(strpos($k,'paper_answer') !== false){
  5207. $paper_answer[] = $v;
  5208. }
  5209. if(strpos($k,'paper_exam') !== false){
  5210. $paper_exam[] = $v;
  5211. }
  5212. }
  5213. }
  5214. if(empty($paper_answer) && empty($paper_exam)){
  5215. $error['message'] = '尚未上传试卷答案!';
  5216. echo json_encode($error);exit();
  5217. }else{
  5218. // echo json_encode($paper_exam);exit();
  5219. krsort($paper_answer);
  5220. krsort($paper_exam);
  5221. // echo json_encode($paper_exam);exit();
  5222. // 保存上传文件至服务器
  5223. $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/';
  5224. $pathName1 = 'upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/';
  5225. if (!file_exists($pathName)) {
  5226. mkdir($pathName, 0777, true);
  5227. }
  5228. $ucloud = new Qcloud();
  5229. // echo json_encode($paper_exam);exit();
  5230. foreach($paper_exam as $k=>$v){
  5231. // $v['name']=iconv("UTF-8", "gb2312", $v['name']);
  5232. $fileName = $exam_group_id.$v['name'];
  5233. $extName = substr($v['name'],strrpos($v['name'],'.'));
  5234. if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) {
  5235. $error['message'] = '上传试卷失败!';
  5236. echo json_encode($error);exit();
  5237. }else{
  5238. $meg = $ucloud->putFile('zsyas2/englishPaper/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName);
  5239. if($meg['status'] == 0){
  5240. $error['message'] = $meg['msg'];
  5241. echo json_encode($error);exit();
  5242. }else{
  5243. $url = $meg['url'];
  5244. $url = str_replace("%2F","/",$url);
  5245. $paper_exam_url[] = $url;
  5246. $paper_exam_url_str = $url;
  5247. }
  5248. }
  5249. @unlink($pathName1.$fileName);
  5250. }
  5251. foreach($paper_answer as $k=>$v){
  5252. // $v['name']=iconv("UTF-8", "gb2312", $v['name']);
  5253. $fileName = $exam_group_id.$v['name'];
  5254. $extName = substr($v['name'],strrpos($v['name'],'.'));
  5255. if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) {
  5256. $error['message'] = '上传试卷失败!';
  5257. echo json_encode($error);exit();
  5258. }else{
  5259. $meg = $ucloud->putFile('zsyas2/englishPaperAnswer/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName);
  5260. if($meg['status'] == 0){
  5261. $error['message'] = $meg['msg'];
  5262. echo json_encode($error);exit();
  5263. }else{
  5264. $url = $meg['url'];
  5265. $url = str_replace("%2F","/",$url);
  5266. $paper_answer_url[] = $url;
  5267. $paper_answer_url_str = $url;
  5268. }
  5269. }
  5270. @unlink($pathName1.$fileName);
  5271. }
  5272. }
  5273. }
  5274. $error['success'] = 1;
  5275. $error['message'] = '发送成功!';
  5276. $error['uploadOne'] = $uploadOne;
  5277. $error['answer_url'] = $paper_answer_url_str;
  5278. $error['paper_url'] = $paper_exam_url_str;
  5279. echo json_encode($error);exit();
  5280. }
  5281. public function actionUploadEnglishPaperInsert(){
  5282. $exam_group_id = Req::post('examGroupId');
  5283. $paper_answer_url = Req::post('answerUrl');
  5284. $paper_exam_url = Req::post('paperUrl');
  5285. $printTime = (int)Req::post('printTime');
  5286. if($paper_answer_url && $paper_exam_url){
  5287. foreach($paper_answer_url as $k=>$v){
  5288. if(!$v || empty($v)){
  5289. unset($paper_answer_url[$k]);
  5290. }
  5291. }
  5292. foreach($paper_exam_url as $k=>$v){
  5293. if(!$v || empty($v)){
  5294. unset($paper_answer_url[$k]);
  5295. }
  5296. }
  5297. ksort($paper_answer_url);
  5298. ksort($paper_exam_url);
  5299. //关联third_multi_template
  5300. $sql = "select count(*) count from third_multi_template where exam_group_id = {$exam_group_id}";
  5301. $count = $this->sConn->createCommand($sql)->queryAll();
  5302. if($count[0]['count']){
  5303. $this->sConn->createCommand("delete from `third_multi_template` where exam_group_id = '{$exam_group_id}'")->execute();
  5304. }
  5305. $this->sConn->createCommand()->insert('third_multi_template',array(
  5306. 'exam_group_id' => $exam_group_id,
  5307. 'semester_id' => $this->semesterId,
  5308. 'template_src' => implode(',',$paper_exam_url),
  5309. 'topic_upload' => 1,
  5310. 'answer_upload' => 0,
  5311. 'template_type' => 1,
  5312. 'update_time' => 0,
  5313. 'create_time' => time()
  5314. ));
  5315. $this->sConn->createCommand()->insert('third_multi_template',array(
  5316. 'exam_group_id' => $exam_group_id,
  5317. 'semester_id' => $this->semesterId,
  5318. 'template_src' => implode(',',$paper_answer_url),
  5319. 'topic_upload' => 0,
  5320. 'answer_upload' => 1,
  5321. 'template_type' => 2,
  5322. 'update_time' => 0,
  5323. 'create_time' => time()
  5324. ));
  5325. $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  5326. if (empty($examInfo)) {
  5327. $error['message'] = '未找到试卷信息!';
  5328. echo json_encode($error);exit();
  5329. }else{
  5330. $exam_name = $examInfo['name'];
  5331. $tplData = json_decode($examInfo["tpl_data"], true);
  5332. //考试时间
  5333. if(isset($tplData['examDate']))
  5334. {
  5335. $exam_time = strtotime($tplData["examDate"]);
  5336. }else{
  5337. $exam_time = 0;
  5338. }
  5339. }
  5340. $jsonArr = array();
  5341. $jsonArr['exam_name'] = $exam_name;
  5342. $jsonArr['school_id'] = $this->schoolId;
  5343. $jsonArr['exam_group_id'] = $exam_group_id;
  5344. $jsonArr['exam_time'] = $exam_time;
  5345. $jsonArr['topic_original'] = $paper_exam_url;
  5346. $jsonArr['answer_parse_original'] = $paper_answer_url;
  5347. $jsonArr['coach_name'] = isset(Yii::app()->session['coachInfo']['real_name'])?Yii::app()->session['coachInfo']['real_name']:'';
  5348. $jsonArr['print_time'] = $printTime;
  5349. $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr));
  5350. $resultArr = json_decode($result,true);
  5351. if($resultArr['status'] == 1){
  5352. $sql = "select exam_id from exam where exam_group_id = '{$exam_group_id}'";
  5353. $examAll = $this->sConn->createCommand($sql)->queryAll();
  5354. $examArr = array();
  5355. if($examAll){
  5356. foreach($examAll as $k=>$v){
  5357. $examArr[] = $v['exam_id'];
  5358. }
  5359. $transcation = $this->sConn->beginTransaction();
  5360. try {
  5361. $this->sConn->createCommand("update paper set is_labelled = 3 where exam_id in (".implode(',',$examArr).")")->execute();
  5362. $transcation->commit();
  5363. }
  5364. catch (Exception $e)
  5365. {
  5366. $transcation->rollback();
  5367. $error['message'] = '更新失败!';
  5368. echo json_encode($error);exit();
  5369. }
  5370. }else{
  5371. $error['message'] = '考试信息错误!';
  5372. echo json_encode($error);exit();
  5373. }
  5374. }else{
  5375. $error['message'] = $resultArr['message'];
  5376. echo json_encode($error);exit();
  5377. }
  5378. }else{
  5379. $error['message'] = '上传失败!';
  5380. echo json_encode($error);exit();
  5381. }
  5382. $this->schoolManager->saveExamProcess($exam_group_id,1,time());
  5383. $error['success'] = 1;
  5384. $error['message'] = '上传成功!';
  5385. echo json_encode($error);exit();
  5386. }
  5387. //第三方发送协助
  5388. public function actionAssist(){
  5389. Url::clean();
  5390. $exam_group_id = Req::get("exam_group_id");
  5391. //读取考试数据
  5392. $examModel=new SExam();
  5393. $examInfo=$examModel->getExamByGroupId($exam_group_id);
  5394. if(!$examInfo) Yii::app()->jump->error('考试参数异常');
  5395. $tpl_data=$examInfo[0]['tpl_data'];
  5396. $tplData=json_decode($tpl_data,true);
  5397. //读取答题卡设置
  5398. $thirdAnswerSheet = $this->sConn->createCommand("select * from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow();
  5399. //判断上传状态
  5400. $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($exam_group_id);
  5401. $uploadStatus=0;
  5402. if($uploadExamInfo){
  5403. if(isset($uploadExamInfo[1])){
  5404. if($uploadExamInfo[1]['topic_upload']==1){
  5405. $uploadStatus+=1;
  5406. }
  5407. }
  5408. if(isset($uploadExamInfo[2])){
  5409. if($uploadExamInfo[2]['answer_upload']==1){
  5410. $uploadStatus+=3;
  5411. }
  5412. }
  5413. }
  5414. // debug($tplData);
  5415. //判断任务发送情况
  5416. $task= ATask::model()->findByPk($exam_group_id);
  5417. $task = json_decode(CJSON::encode($task),TRUE);
  5418. if($task){
  5419. if($task['operator']){
  5420. $task['user']=AssistUser::model()->findByPk($task['operator']);
  5421. }
  5422. //答题卡任务耗时
  5423. if($task['ast_apply_time']){
  5424. if($task['answer_sheet_task']>2){
  5425. if($task['ast_update_time'] && ($task['ast_update_time']-$task['ast_apply_time'])>0){
  5426. $task['AstConsuming']=$this->consuming($task['ast_update_time'],$task['ast_apply_time']);
  5427. }else{
  5428. $task['AstConsuming']='--';
  5429. }
  5430. }elseif($task['answer_sheet_task']==2){
  5431. if($task['ast_apply_time'] && (time()-$task['ast_apply_time'])>0){
  5432. $task['AstConsuming']=$this->consuming(time(),$task['ast_apply_time']);
  5433. }else{
  5434. $task['AstConsuming']='--';
  5435. }
  5436. }
  5437. }else{
  5438. $task['AstConsuming']='--';
  5439. }
  5440. //试卷任务耗时
  5441. if($task['ppt_apply_time']){
  5442. if($task['paper_task']>2){
  5443. if($task['ppt_update_time'] && ($task['ppt_update_time']-$task['ppt_apply_time'])>0){
  5444. $task['PptConsuming']=$this->consuming($task['ppt_update_time'],$task['ppt_apply_time']);
  5445. }else{
  5446. $task['PptConsuming']='--';
  5447. }
  5448. }elseif($task['paper_task']==2){
  5449. if($task['ppt_apply_time'] && (time()-$task['ppt_apply_time'])>0){
  5450. $task['PptConsuming']=$this->consuming(time(),$task['ppt_apply_time']);
  5451. }else{
  5452. $task['PptConsuming']='--';
  5453. }
  5454. }
  5455. }else{
  5456. $task['PptConsuming']='--';
  5457. }
  5458. //答案解析任务耗时
  5459. if($task['pat_apply_time']){
  5460. if($task['parse_task']>2){
  5461. if($task['pat_update_time'] && ($task['pat_update_time']-$task['pat_apply_time'])>0){
  5462. $task['PatConsuming']=$this->consuming($task['pat_update_time'],$task['pat_apply_time']);
  5463. }else{
  5464. $task['PatConsuming']='--';
  5465. }
  5466. }elseif($task['parse_task']==2){
  5467. if($task['pat_apply_time'] && (time()-$task['pat_apply_time'])>0){
  5468. $task['PatConsuming']=$this->consuming(time(),$task['pat_apply_time']);
  5469. }else{
  5470. $task['PatConsuming']='--';
  5471. }
  5472. }
  5473. }else{
  5474. $task['PatConsuming']='--';
  5475. }
  5476. }
  5477. //读取试题结构
  5478. if(isset($tplData['new_items'])){
  5479. $items=array();
  5480. foreach ($tplData['new_items'] as $item){
  5481. if(isset($item['alias'])){
  5482. $items[$item['topic_type']]['no'][]=$item['alias'];
  5483. }else{
  5484. $items[$item['topic_type']]['no'][]=$item['id'];
  5485. }
  5486. }
  5487. $tplData['items']=$items;
  5488. }
  5489. $data['exam_name']=$examInfo[0]['name'];
  5490. $data['subject']=Yii::app()->params['subjectId'][$examInfo[0]['subject_id']];
  5491. $data['tpl_data']=$tplData;
  5492. $data['task']=$task;
  5493. //debug($tplData);
  5494. $data['exam_group_id']=$exam_group_id;
  5495. if($thirdAnswerSheet){
  5496. $data['isAnswerCard']=1;
  5497. }else{
  5498. $data['isAnswerCard']=0;
  5499. }
  5500. $this->render('assist',$data);
  5501. }
  5502. //发送答题卡任务
  5503. public function actionSendTask(){
  5504. Url::clean();
  5505. $exam_group_id = Req::post("examGroupId");
  5506. $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析
  5507. $msg['success'] = 0;
  5508. $taskModel=new ATask();
  5509. //判断学管任务数量
  5510. $allTask=$this->conn->createCommand("select count(*) as count from assist_task where coach_id='".$this->coachId."' and (answer_sheet_task in(1,2) or paper_task in(1,2) or parse_task in(1,2))")->queryRow();
  5511. if($allTask && $allTask['count']>5){
  5512. $msg['message'] = '您已超过5场考试任务为处理完成,操作过于频繁哦!';
  5513. exit(json_encode($msg));
  5514. }
  5515. //验证设置
  5516. $setting=AssistSetting::model()->getAssistSetting();
  5517. if($setting){
  5518. if($setting['cutting_task']==0){
  5519. $msg['message'] = '系统后台暂不接受协助任务,请稍后再试,谢谢!';
  5520. exit(json_encode($msg));
  5521. }elseif($setting['open_cutting_upper_limit'] && $allTask['count']>$setting['cutting_task_upper_limit_num']){
  5522. $msg['message'] = '系统后台排队任务过多,请稍后再试,谢谢!';
  5523. exit(json_encode($msg));
  5524. }
  5525. }
  5526. //拼接mysigninfo
  5527. $mySignInfo='userid='.$this->coachId.'&session='.Yii::app()->request->cookies['appLoginSessionId'].'&sig='.Yii::app()->request->cookies['loginSig'].'&time='.Yii::app()->request->cookies['loginTime'];
  5528. if($sendType==1){
  5529. $imgArr = Req::post("imgArr");
  5530. $paperDoc = Req::post("paperDoc");
  5531. $card_type = Req::post("cardType");
  5532. $paperDocTitle = Req::post("paperDocTitle");
  5533. $answer_card_remark = Req::post("answerCardRemark");
  5534. if(!$imgArr || !is_array($imgArr)){
  5535. $msg['message'] = '请上传答题卡!';
  5536. exit(json_encode($msg));
  5537. }
  5538. if(!$paperDoc){
  5539. $msg['message'] = '请上传试卷文件!';
  5540. exit(json_encode($msg));
  5541. }
  5542. $examModel=new SExam();
  5543. $examInfo=$examModel->getExamByGroupId($exam_group_id);
  5544. if(!$examInfo){
  5545. $msg['message'] = '未找到考试信息!';
  5546. exit(json_encode($msg));
  5547. }
  5548. $sheetId=0;
  5549. //读取答题卡设置
  5550. $thirdAnswerSheet = $this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow();
  5551. if($thirdAnswerSheet){
  5552. $sheetId=$thirdAnswerSheet['sheet_id'];
  5553. }
  5554. $time=time();
  5555. //读取任务记录
  5556. //$task=$taskModel->getTaskByExamGroupId($exam_group_id);
  5557. $task=$taskModel->findByPk($exam_group_id);
  5558. if(!$task){
  5559. $tpl_data=$examInfo[0]['tpl_data'];
  5560. $tplData=json_decode($tpl_data,true);
  5561. $tplIndex=$examInfo[0]['tpl_index'];
  5562. //学校信息
  5563. $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
  5564. $taskModel->exam_group_id=$exam_group_id;
  5565. $taskModel->exam_name=$examInfo[0]['name'];
  5566. $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
  5567. $taskModel->school_id=$this->schoolId;
  5568. $taskModel->school_name=$schoolInfo['school_name'];
  5569. $taskModel->school_address=$schoolInfo['address'];
  5570. $taskModel->exam_date=$tplData['examDate'];
  5571. $taskModel->coach_id=$this->coachId;
  5572. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  5573. $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
  5574. }else{
  5575. $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
  5576. }
  5577. $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
  5578. $taskModel->my_sign_info=$mySignInfo;
  5579. $taskModel->create_time=$time;
  5580. $taskModel->update_time=$time;
  5581. $taskModel->answer_sheet_task=1;
  5582. $taskModel->ast_create_time=$time;
  5583. $taskModel->ast_update_time=$time;
  5584. $taskModel->answer_card_img=implode(',',$imgArr);
  5585. $taskModel->paper_file_img=$paperDoc;
  5586. $taskModel->paper_file_title=$paperDocTitle;
  5587. $taskModel->answer_card_mark=$answer_card_remark;
  5588. $taskModel->number_type=$card_type;
  5589. $taskModel->sheet_id=$sheetId;
  5590. $taskModel->tpl_index=$tplIndex;
  5591. $taskModel->dsn=$this->sConn->connectionString;
  5592. $taskModel->database_user=$this->sConn->username;
  5593. $taskModel->database_password=$this->sConn->password;
  5594. if($taskModel->save()){
  5595. $msg['success'] = 1;
  5596. $msg['message'] = '发送成功!';
  5597. exit(json_encode($msg));
  5598. }
  5599. }else{
  5600. if($task['answer_sheet_task']==1 || $task['answer_sheet_task']==2){
  5601. $msg['message'] = '不能重复发送协助任务!';
  5602. exit(json_encode($msg));
  5603. }
  5604. $taskStatus=1;
  5605. if($task['operator']!=0){
  5606. $taskStatus=2;
  5607. }
  5608. $taskStatus=1;
  5609. $applyTime=0;
  5610. if($task['operator']!=0){
  5611. $taskStatus=2;
  5612. $applyTime=$time;
  5613. }
  5614. $updateArr=array(
  5615. 'update_time'=>$time,
  5616. 'answer_sheet_task'=>$taskStatus,
  5617. 'ast_create_time'=>$time,
  5618. 'ast_update_time'=>$time,
  5619. 'ast_apply_time'=>$applyTime,
  5620. 'paper_file_img'=>$paperDoc,
  5621. 'paper_file_title'=>$paperDocTitle,
  5622. 'answer_card_img'=>implode(',',$imgArr),
  5623. 'number_type'=>$card_type,
  5624. 'sheet_id'=>$sheetId,
  5625. 'answer_card_mark'=>$answer_card_remark
  5626. );
  5627. if($taskModel->updateTask($exam_group_id,$updateArr)){
  5628. $msg['success'] = 1;
  5629. $msg['message'] = '发送成功!';
  5630. exit(json_encode($msg));
  5631. }
  5632. }
  5633. }elseif($sendType==2){
  5634. //试卷任务
  5635. $imgArr = Req::post("imgArr");
  5636. $paperRemark = Req::post("paperRemark");
  5637. if(!$imgArr || !is_array($imgArr)){
  5638. $msg['message'] = '请上传答题卡!';
  5639. exit(json_encode($msg));
  5640. }
  5641. $examModel=new SExam();
  5642. $examInfo=$examModel->getExamByGroupId($exam_group_id);
  5643. if(!$examInfo){
  5644. $msg['message'] = '未找到考试信息!';
  5645. exit(json_encode($msg));
  5646. }
  5647. $time=time();
  5648. $taskModel=new ATask();
  5649. //读取任务记录
  5650. $task=$taskModel->findByPk($exam_group_id);
  5651. if(!$task){
  5652. $tpl_data=$examInfo[0]['tpl_data'];
  5653. $tplData=json_decode($tpl_data,true);
  5654. $tplIndex=$examInfo[0]['tpl_index'];
  5655. //学校信息
  5656. $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
  5657. $taskModel->exam_group_id=$exam_group_id;
  5658. $taskModel->exam_name=$examInfo[0]['name'];
  5659. $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
  5660. $taskModel->school_id=$this->schoolId;
  5661. $taskModel->school_name=$schoolInfo['school_name'];
  5662. $taskModel->school_address=$schoolInfo['address'];
  5663. $taskModel->exam_date=$tplData['examDate'];
  5664. $taskModel->coach_id=$this->coachId;
  5665. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  5666. $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
  5667. }else{
  5668. $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
  5669. }
  5670. $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
  5671. $taskModel->create_time=$time;
  5672. $taskModel->update_time=$time;
  5673. $taskModel->my_sign_info=$mySignInfo;
  5674. $taskModel->paper_task=1;
  5675. $taskModel->ppt_create_time=$time;
  5676. $taskModel->ppt_update_time=$time;
  5677. $taskModel->paper_img=implode(',',$imgArr);
  5678. $taskModel->paper_mark=$paperRemark;
  5679. $taskModel->dsn=$this->sConn->connectionString;
  5680. $taskModel->database_user=$this->sConn->username;
  5681. $taskModel->database_password=$this->sConn->password;
  5682. $taskModel->tpl_index=$tplIndex;
  5683. if($taskModel->save()){
  5684. $msg['success'] = 1;
  5685. $msg['message'] = '发送成功!';
  5686. exit(json_encode($msg));
  5687. }
  5688. }else{
  5689. if($task['paper_task']==1 || $task['paper_task']==2){
  5690. $msg['message'] = '不能重复发送协助任务!';
  5691. exit(json_encode($msg));
  5692. }
  5693. $taskStatus=1;
  5694. $applyTime=0;
  5695. if($task['operator']!=0){
  5696. $taskStatus=2;
  5697. $applyTime=$time;
  5698. }
  5699. $updateArr=array(
  5700. 'update_time'=>$time,
  5701. 'paper_task'=>$taskStatus,
  5702. 'ppt_create_time'=>$time,
  5703. 'ppt_apply_time'=>$applyTime,
  5704. 'ppt_update_time'=>$time,
  5705. 'paper_img'=>implode(',',$imgArr),
  5706. 'paper_mark'=>$paperRemark,
  5707. );
  5708. if($taskModel->updateTask($exam_group_id,$updateArr)){
  5709. $msg['success'] = 1;
  5710. $msg['message'] = '发送成功!';
  5711. exit(json_encode($msg));
  5712. }
  5713. }
  5714. }elseif($sendType==3){
  5715. //答案解析任务
  5716. $imgArr = Req::post("imgArr");
  5717. $parseRemark = Req::post("parseRemark");
  5718. if(!$imgArr || !is_array($imgArr)){
  5719. $msg['message'] = '请上传答题卡!';
  5720. exit(json_encode($msg));
  5721. }
  5722. $examModel=new SExam();
  5723. $examInfo=$examModel->getExamByGroupId($exam_group_id);
  5724. if(!$examInfo){
  5725. $msg['message'] = '未找到考试信息!';
  5726. exit(json_encode($msg));
  5727. }
  5728. $tplIndex=$examInfo[0]['tpl_index'];
  5729. $time=time();
  5730. $taskModel=new ATask();
  5731. //读取任务记录
  5732. $task=$taskModel->findByPk($exam_group_id);
  5733. if(!$task){
  5734. $tpl_data=$examInfo[0]['tpl_data'];
  5735. $tplData=json_decode($tpl_data,true);
  5736. //学校信息
  5737. $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
  5738. $taskModel->exam_group_id=$exam_group_id;
  5739. $taskModel->exam_name=$examInfo[0]['name'];
  5740. $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
  5741. $taskModel->school_id=$this->schoolId;
  5742. $taskModel->school_name=$schoolInfo['school_name'];
  5743. $taskModel->school_address=$schoolInfo['address'];
  5744. $taskModel->exam_date=$tplData['examDate'];
  5745. $taskModel->coach_id=$this->coachId;
  5746. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  5747. $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
  5748. }else{
  5749. $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
  5750. }
  5751. $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
  5752. $taskModel->create_time=$time;
  5753. $taskModel->update_time=$time;
  5754. $taskModel->my_sign_info=$mySignInfo;
  5755. $taskModel->parse_task=1;
  5756. $taskModel->pat_create_time=$time;
  5757. $taskModel->pat_update_time=$time;
  5758. $taskModel->parse_img=implode(',',$imgArr);
  5759. $taskModel->parse_mark=$parseRemark;
  5760. $taskModel->tpl_index=$tplIndex;
  5761. $taskModel->dsn=$this->sConn->connectionString;
  5762. $taskModel->database_user=$this->sConn->username;
  5763. $taskModel->database_password=$this->sConn->password;
  5764. if($taskModel->save()){
  5765. $msg['success'] = 1;
  5766. $msg['message'] = '发送成功!';
  5767. exit(json_encode($msg));
  5768. }
  5769. }else{
  5770. if($task['parse_task']==1 || $task['parse_task']==2){
  5771. $msg['message'] = '不能重复发送协助任务!';
  5772. exit(json_encode($msg));
  5773. }
  5774. $taskStatus=1;
  5775. $applyTime=0;
  5776. if($task['operator']!=0){
  5777. $taskStatus=2;
  5778. $applyTime=$time;
  5779. }
  5780. $updateArr=array(
  5781. 'update_time'=>$time,
  5782. 'parse_task'=>$taskStatus,
  5783. 'pat_create_time'=>$time,
  5784. 'pat_apply_time'=>$applyTime,
  5785. 'pat_update_time'=>$time,
  5786. 'parse_img'=>implode(',',$imgArr),
  5787. 'parse_mark'=>$parseRemark
  5788. );
  5789. if($taskModel->updateTask($exam_group_id,$updateArr)){
  5790. $msg['success'] = 1;
  5791. $msg['message'] = '发送成功!';
  5792. exit(json_encode($msg));
  5793. }
  5794. }
  5795. }
  5796. }
  5797. //撤消任务
  5798. public function actionUndo(){
  5799. Url::clean();
  5800. $exam_group_id = Req::post("examGroupId");
  5801. $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析
  5802. $msg['success']=0;
  5803. $examModel=new SExam();
  5804. $examInfo=$examModel->getExamByGroupId($exam_group_id);
  5805. if(!$examInfo){
  5806. $msg['message'] = '未找到考试信息!';
  5807. exit(json_encode($msg));
  5808. }
  5809. $time=time();
  5810. $taskModel=new ATask();
  5811. //读取任务记录
  5812. $task=$taskModel->findByPk($exam_group_id);
  5813. $filed='';
  5814. $timeFiled='';
  5815. switch ($sendType){
  5816. case 1:
  5817. $filed='answer_sheet_task';
  5818. $timeFiled='ast_update_time';
  5819. break;
  5820. case 2:
  5821. $filed='paper_task';
  5822. $timeFiled='ppt_update_time';
  5823. break;
  5824. case 3:
  5825. $filed='parse_task';
  5826. $pat_update_time='ast_update_time';
  5827. break;
  5828. }
  5829. if(!$filed){
  5830. $msg['message'] = '参数异常!';
  5831. exit(json_encode($msg));
  5832. }
  5833. if($task->$filed==2){
  5834. $msg['message'] = '该任务已受理,不可撤回,谢谢!';
  5835. exit(json_encode($msg));
  5836. }elseif($task->$filed==3){
  5837. $msg['message'] = '该任务已完成,谢谢!';
  5838. exit(json_encode($msg));
  5839. }else{
  5840. if($taskModel->updateAll(array($filed=>4,'update_time'=>$time,$timeFiled=>$time),'exam_group_id=:eid',array(':eid'=>$exam_group_id))){
  5841. $msg['success']=1;
  5842. $msg['message'] = '撤消成功!';
  5843. exit(json_encode($msg));
  5844. }
  5845. }
  5846. }
  5847. //上传图片
  5848. public function actionUpload(){
  5849. ini_set ('memory_limit', '300M');
  5850. if(!$_FILES){
  5851. Yii::app()->jump->error('文件大小超过范围');
  5852. }else {
  5853. if (!isset($_FILES['paperFile']) || !isset($_FILES['paperFile']['size']) || $_FILES['paperFile']['size'] > 52428800) {
  5854. Yii::app()->jump->error('文件大小超过范围');
  5855. }
  5856. }
  5857. if (Yii::app()->request->getIsPostRequest()) {
  5858. //FIXME 20191202 ucloud
  5859. // 保存上传文件至服务器
  5860. $pathName = dirname(dirname(dirname(__FILE__)))."/upload/tmpDir/UploadAssistFile/{$this->schoolId}/". date('Y/m/d/');
  5861. if (!file_exists($pathName)) {
  5862. mkdir($pathName, 0777, true);
  5863. }
  5864. $error['success'] = 0;
  5865. $ucloud = new Qcloud();
  5866. $fileName = $_FILES['paperFile']['name'];
  5867. $fileName = iconv("UTF-8", "gb2312", $fileName);
  5868. $extName = substr($fileName,strrpos($fileName,'.'));
  5869. if (!move_uploaded_file($_FILES['paperFile']['tmp_name'], $pathName.$fileName)) {
  5870. $error['message'] = '上传失败!';
  5871. echo json_encode($error);exit();
  5872. }else{
  5873. $meg = $ucloud->putFile('zsyas2/third/'.$this->schoolId.'/'.time().mt_rand().$extName,$pathName.$fileName);
  5874. if($meg['status'] == 0){
  5875. $error['message'] = $meg['msg'];
  5876. echo json_encode($error);exit();
  5877. }else{
  5878. $url = $meg['url'];
  5879. $url = str_replace("%2F","/",$url);
  5880. }
  5881. }
  5882. @unlink($pathName.$fileName);
  5883. $error['success'] = 1;
  5884. $error['message'] = '上传成功!';
  5885. $error['src']=$url;
  5886. $error['name']=$_FILES['paperFile']["name"];
  5887. echo json_encode($error);exit();
  5888. }
  5889. }
  5890. //计算耗时
  5891. public function consuming($now,$time){
  5892. $return='';
  5893. $date=floor(($now-$time)/86400);
  5894. if($date){
  5895. $return.=$date.'天';
  5896. }
  5897. $hour=floor(($now-$time)%86400/3600);
  5898. if($hour){
  5899. $return.=$hour.'小时';
  5900. }
  5901. $minute=floor((($now-$time)%86400)%3600/60);
  5902. if($minute){
  5903. $return.=$minute.'分种';
  5904. }
  5905. $second=floor(($now-$time)%86400%3600%60);
  5906. if($second){
  5907. $return.=$second.'秒';
  5908. }
  5909. return $return;
  5910. }
  5911. //客户端加载未上传学生列表
  5912. public function actionNotUploadedStudent(){
  5913. $eid = Req::get("examgroupid");
  5914. $page =Req::get("page");
  5915. $PageLimit=10;
  5916. if(!$page) $page=1;
  5917. $examInfo=$this->schoolManager->getExamsByExamGroupId($eid);
  5918. if (empty($examInfo)) {
  5919. Yii::app()->jump->error('未找到考试信息!');
  5920. }
  5921. $examIds=array();
  5922. foreach($examInfo as $val){
  5923. $examIds[]=$val['exam_id'];
  5924. }
  5925. $result=array();
  5926. $rs=$this->schoolManager->getStudentByExamIds($examIds,$page,$PageLimit);
  5927. if($rs){
  5928. foreach($rs['list'] as $key =>$val){
  5929. $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow();
  5930. if($StudentInfo){
  5931. $rs['list'][$key]['realname']=$StudentInfo['realname'];
  5932. }
  5933. }
  5934. }
  5935. $rs['examgroupid']=$eid;
  5936. $this->render('not_upload',$rs);
  5937. }
  5938. public function actionDownloadStudent()
  5939. {
  5940. $eid = Req::get("examgroupid");
  5941. $examInfo=$this->schoolManager->getExamsByExamGroupId($eid);
  5942. if (empty($examInfo)) {
  5943. Yii::app()->jump->error('未找到考试信息!');
  5944. }
  5945. $examIds=array();
  5946. foreach($examInfo as $val){
  5947. $examIds[]=$val['exam_id'];
  5948. }
  5949. $data=$this->schoolManager->getAllStudentByExamIds($examIds);
  5950. $objPHPExcel = new PHPExcel();
  5951. $objPHPExcel->getProperties()->setCreator("ctos")
  5952. ->setLastModifiedBy("ctos")
  5953. ->setTitle("未上传学生")
  5954. ->setSubject("未上传学生")
  5955. ->setDescription("未上传学生")
  5956. ->setKeywords("excel")
  5957. ->setCategory("result file");
  5958. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  5959. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45);
  5960. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  5961. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  5962. $objPHPExcel->setActiveSheetIndex(0)
  5963. ->setCellValue('A1', '序号')
  5964. ->setCellValue('B1', '姓名')
  5965. ->setCellValue('C1', '系统准考证号');
  5966. $i = 2;
  5967. foreach($data as $v)
  5968. {
  5969. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, ($i-1));
  5970. $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['realname']);
  5971. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('C' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  5972. $i = $i + 1;
  5973. }
  5974. $objPHPExcel->getActiveSheet()->setTitle('未上传学生列表');
  5975. $objPHPExcel->setActiveSheetIndex(0);
  5976. ob_end_clean(); // Added by me
  5977. header("Accept-Ranges:bytes");
  5978. header('Content-Type:application/vnd.ms-excel');
  5979. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  5980. header('Content-Disposition:attachment;filename="未上传学生列表.xls"');
  5981. header('Cache-Control:max-age=0');
  5982. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  5983. $objWriter->save('php://output');
  5984. }
  5985. //修改第三方考试信息
  5986. public function actionModifyThirdExam(){
  5987. if (Yii::app()->request->getIsPostRequest()){
  5988. $exam_group_id = Req::post("examGroupId");
  5989. $type=Req::post('type');
  5990. $name=Req::post('examName');
  5991. $examDate=Req::post('examDate');
  5992. $paperType=Req::post('paperType');
  5993. $relationAnswerCard=false;
  5994. $transaction = $this->sConn->beginTransaction();
  5995. $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  5996. if(!$exam_data)
  5997. {
  5998. Yii::app()->jump->error('非法试卷!');
  5999. }
  6000. @$tplData=json_decode($exam_data['tpl_data'],true);
  6001. if(!$tplData){
  6002. Yii::app()->jump->error('非法试卷!');
  6003. }
  6004. if(!matchStrChar($name)){
  6005. Yii::app()->jump->error('考试名称不能包含特殊字符!');
  6006. }
  6007. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  6008. if($exam_group_data['status']==2){
  6009. $examSql="update `exam` set `name`='".$name."' ";
  6010. $examSql.=" where exam_group_id='".$exam_group_id."'";
  6011. $this->sConn->createCommand($examSql)->execute();
  6012. $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
  6013. if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){
  6014. updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
  6015. }
  6016. $this->redirect($this->createUrl('print/index'));
  6017. }
  6018. //是否修改在线答题卡
  6019. $text=Req::post("timu");
  6020. if($text){
  6021. //处理答题卡数据
  6022. $relationAnswerCard=true;
  6023. $name = Req::post("title");
  6024. $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
  6025. $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
  6026. $post = json_decode($text,true);
  6027. $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
  6028. $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
  6029. $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
  6030. $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
  6031. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  6032. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  6033. $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
  6034. $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
  6035. $subject_id=$this->subjectId;
  6036. if(!$text || !$name || !$sheet_answer || !$sheet_score){
  6037. $error['message'] = '题目参数错误';
  6038. echo json_encode($error);exit();
  6039. }
  6040. if(!$positionJson){
  6041. $error['message'] = '定位信息异常';
  6042. echo json_encode($error);exit();
  6043. }
  6044. //上传答题卡相关文件
  6045. $files=$this->uploadAnswerCardPdf($exam_group_id,$positionJson,$pdfUrl);
  6046. $sheet_score_array = json_decode($sheet_score, 1);
  6047. if (!$sheet_score_array) {
  6048. $error['success']=0;
  6049. $error['message'] = '上传失败,未设置分数!';
  6050. echo json_encode($error);exit();
  6051. }
  6052. $score_num = count($sheet_score_array);
  6053. if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) {
  6054. $error['success']=0;
  6055. $error['message'] = '上传失败,设置分数或设置题号有误!';
  6056. echo json_encode($error);exit();
  6057. }
  6058. $tplData=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData);
  6059. }
  6060. try{
  6061. $tplData['examDate']=$examDate;
  6062. if($relationAnswerCard){
  6063. $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
  6064. $topic_data = $this->get_topic_folder();
  6065. $topic_ids=array();
  6066. $examIds=array();
  6067. $paperIds=array();
  6068. $examData=$this->schoolManager->getExamsByExamGroupId($exam_group_id);
  6069. foreach ($examData as $val){
  6070. $examIds[]=$val['exam_id'];
  6071. }
  6072. $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id in(".implode(',',$examIds).")")->queryAll();
  6073. foreach ($paperData as $val){
  6074. $paperIds[]=$val['paper_id'];
  6075. }
  6076. $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id ='{$paperData[0]['paper_id']}'")->qeuryAll();
  6077. foreach ($paperTopic as $item){
  6078. $topic_ids[]=$item['topic_id'];
  6079. }
  6080. //判断原答题卡
  6081. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow();
  6082. if($thirdAnswerSheet){
  6083. //删除数据
  6084. $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute();
  6085. $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute();
  6086. $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute();
  6087. $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
  6088. $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id );
  6089. }
  6090. foreach($select_info['content'] as $k=>$v)
  6091. {
  6092. $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
  6093. $zsytkTopicType=$_topic_type;
  6094. if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
  6095. $this->sConn->createCommand()->insert('topic', array(
  6096. 'topic_type' =>$zsytkTopicType ,
  6097. 'topic_title' => '',
  6098. 'folder_id' => $topic_data['folder_id'],
  6099. 'subject_id' => $subject_id,
  6100. 'is_delete' =>0,
  6101. 'creator_id' => $exam_data['teacher_id'],
  6102. 'updater_id' => $exam_data['teacher_id'],
  6103. 'is_word_topic'=>1,
  6104. 'create_time' => time(),
  6105. 'update_time' => time(),
  6106. ));
  6107. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  6108. $topic_id=$last_insert_id['last_insert_id()'];
  6109. $this->sConn->createCommand()->insert('topic_item', array(
  6110. 'topic_id' => $topic_id,
  6111. 'topic_type' => $_topic_type,
  6112. 'topic_title' => ''
  6113. ));
  6114. //增加topic_option
  6115. if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
  6116. {
  6117. $answers = explode(',',$v['answer']);
  6118. if($answers && isset($answers[0]) && !empty($answers[0])){
  6119. $options = array_chunk($option,$v['optionCount']);
  6120. if(isset($options[0]) && !empty($options[0])){
  6121. foreach($options[0] as $item=>$val)
  6122. {
  6123. $this->sConn->createCommand()->insert('topic_item_option', array(
  6124. 'topic_id' => $topic_id,
  6125. 'option_id' => 0,
  6126. 'option_content' => '',
  6127. 'option_correct' => in_array($val,$answers)?1:0,
  6128. 'option_score' => 0,
  6129. 'sort_order' => $item,
  6130. ));
  6131. }
  6132. }
  6133. }
  6134. }
  6135. $this->sConn->createCommand()->insert('topic_use', array(
  6136. 'topic_id' => $topic_id,
  6137. 'mode' => 1,
  6138. 'teacher_id' => $exam_data['teacher_id'],
  6139. 'paper_id' =>$paperData[0]['paper_id']
  6140. ));
  6141. $questionCount = 0;
  6142. $questionScoreStr = '';
  6143. if(isset($v['scores']) && !empty($v['scores'])){
  6144. $scoresArr = explode(',',$v['scores']);
  6145. if($scoresArr){
  6146. $questionCount = count($scoresArr);
  6147. $questionScoreStr = $v['scores'];
  6148. }
  6149. }
  6150. foreach($paperIds as $p)
  6151. {
  6152. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  6153. 'paper_id' => $p,
  6154. 'topic_id' => $topic_id,
  6155. 'no' => $v['questionNum'],
  6156. 'order' => $v['questionNum'],
  6157. 'mode' => 1,
  6158. 'type' => $_topic_type,
  6159. 'score' =>$v['fullScore'],
  6160. 'question_count' => $questionCount,
  6161. 'question_score_str' => $questionScoreStr
  6162. ));
  6163. }
  6164. if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2)))
  6165. {
  6166. $topicNo=$v['questionNum'];
  6167. if(isset($tplData['new_items'][$k]['alias'])){
  6168. $topicNo=$tplData['new_items'][$k]['alias'];
  6169. }elseif(isset($v['alias'])){
  6170. $topicNo=$v['alias'];
  6171. }
  6172. if(!$topicNo) $topicNo=$v['questionNum'];
  6173. $this->sConn->createCommand()->insert('marking_topic', array(
  6174. 'exam_group_id' => $exam_group_id,
  6175. 'topic_id' => $topic_id,
  6176. 'topic_type' => $_topic_type,
  6177. 'topic_index' =>$v['questionNum'],
  6178. 'topic_no' =>$topicNo,
  6179. 'topic_score' =>$v['fullScore']
  6180. ));
  6181. }
  6182. }
  6183. $total = $tplData['total_score'];
  6184. $topics_count = count($select_info['content']);
  6185. $tpl_data=json_encode($tplData);
  6186. $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute();
  6187. $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
  6188. $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`) ";
  6189. $insert.=" values('".$name."','".$exam_group_id."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') ";
  6190. $this->sConn->createCommand($insert)->execute();
  6191. }
  6192. $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
  6193. $this->sConn->createCommand($examSql)->execute();
  6194. $transaction->commit();
  6195. if($paperData[0]['is_labelled']>0 || $exam_group_data['is_tagging']>0){
  6196. updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库
  6197. }
  6198. if(Yii::app()->params['handle_log_on_off'])
  6199. {
  6200. writeFileLog(jsonEncode(array(
  6201. "examGroupId" => $exam_group_id,
  6202. "operate_project" => 'zsyas2',
  6203. "school_id" => $this->schoolId,
  6204. "title" => '编辑考试',
  6205. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  6206. "operate_method" => $this->action,
  6207. "operate_url" => $this->getRoute(),
  6208. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  6209. "date"=>date('Y-m-d H:i:s')
  6210. )));
  6211. }
  6212. // echo json_encode(array('status'=>1,'msg'=>'编辑成功'));exit;
  6213. $this->redirect($this->createUrl('third/index'));
  6214. }catch(Exception $e){
  6215. $transaction->rollBack();
  6216. //echo json_encode(array('status'=>0,'msg'=>'编辑失败'));exit;
  6217. Yii::app()->jump->error('编辑失败!');
  6218. }
  6219. }else{
  6220. $exam_group_id = Req::get("exam_group_id");
  6221. $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id));
  6222. $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  6223. if(!$exam_data)
  6224. {
  6225. Yii::app()->jump->error('非法试卷!');
  6226. }
  6227. @$tplData=json_decode($exam_data['tpl_data'],true);
  6228. if(!$tplData){
  6229. Yii::app()->jump->error('非法试卷!');
  6230. }
  6231. $classInfo=$this->sConn->createCommand("select grade from class where class_id='".$exam_data['class_id']."'")->queryRow();
  6232. $data['grade']=$classInfo['grade'];
  6233. }
  6234. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score,`position`,select_info from third_answer_sheet where exam_group_id='".$exam_group_id."' ")->queryRow();
  6235. $data['answerSheet']=0;
  6236. $data['onlineCard']=0;
  6237. if($thirdAnswerSheet){
  6238. $data['onlineCard']=$thirdAnswerSheet['online_card'];
  6239. $data['answerSheet']=1;
  6240. }
  6241. $data['examGroupId']=$exam_group_id;
  6242. $data['name']=$exam_data['name'];
  6243. $data['markType']=$findInfo->mark_type;
  6244. $data['paperType']=$exam_data['tpl_index'];
  6245. $data['type']=$exam_data['type'];
  6246. $data['examDate']=$tplData['examDate'];
  6247. $data['examStatus']=$findInfo->status;
  6248. $this->render('modify_exam',$data);
  6249. }
  6250. //创建考试并在线答题卡
  6251. public function actionCreateThirdOnline(){
  6252. $error = array();
  6253. $tplData = array();
  6254. $semesterId = $this->semesterId;
  6255. $examName = Req::post("examName");
  6256. $type = (int)Req::post("type");
  6257. $classIds = Req::post("classIds");
  6258. $markType = Req::post("markType");
  6259. $teacherId = Req::post("teacherId");
  6260. $subjectId = Req::post("subjectId");
  6261. $textbookId = Req::post("textbookId");
  6262. $examDate = Req::post("examDate");
  6263. $tpl_index = (int)Req::post("tpl_index");
  6264. $relationAnswerCard=false; //是否关联答题卡
  6265. $json = array();
  6266. if(empty($classIds)){
  6267. $error[] = '请指定考试班级';
  6268. }else{
  6269. $classIds = explode(',',substr($classIds,0,-1));
  6270. }
  6271. if(empty($examName)){
  6272. $error[] = '请设置考试名称';
  6273. }
  6274. if ($type <= 0 || $type > 9) {
  6275. $error[] = '考试类型错误';
  6276. }
  6277. if(empty($subjectId)){
  6278. $error[] = '请选择题源';
  6279. }
  6280. if(empty($markType)){
  6281. $error[] = '请选择阅卷方式';
  6282. }
  6283. if(empty($teacherId)){
  6284. $error[] = '请指定阅卷老师';
  6285. }
  6286. if(empty($examDate)){
  6287. $error[] = '请指定考试时间';
  6288. }
  6289. if(!inArray($tpl_index,array(0,1,2,1050))){
  6290. $error[] = '请指定类型';
  6291. }
  6292. if($error){
  6293. echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
  6294. }else{
  6295. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  6296. if($teacherName){
  6297. $tplData['author'] = $teacherName;
  6298. $tplData['subjectId'] = $subjectId;
  6299. $tplData['textbookId'] = $textbookId;
  6300. $tplData['examDate'] = $examDate;
  6301. }
  6302. $json['author'] = $teacherName;
  6303. $json['examDate'] = $examDate;
  6304. $json['subjectId'] = (int)$subjectId;
  6305. $json['textbookId'] = (int)$textbookId;
  6306. $json['exam_name'] = $examName;
  6307. $json['impersonal_topic_type'] = 0;
  6308. $json['total_score'] = 0;
  6309. $json['scores'] = 0;
  6310. $json['times'] = 0;
  6311. if($subjectId==8){
  6312. $json['isNewEnglish']=1;
  6313. }
  6314. $json['school_card_length'] = 8;
  6315. if($this->schoolId>999){
  6316. $json['school_card_length'] = 9;
  6317. }
  6318. $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id in(".join(',',$classIds).") ";
  6319. $cardData = $this->sConn->createCommand($sql)->queryRow();
  6320. if(!$cardData){
  6321. $error[] = '无法找到对应班级';
  6322. }
  6323. if($cardData['card_status']){
  6324. $json['school_card_length'] = (int)$cardData['card_length'];
  6325. }else{
  6326. $cardData['card_length'] = 8;
  6327. if($this->schoolId>999){
  6328. $cardData['card_length'] = 9;
  6329. }
  6330. }
  6331. $class_type=$cardData['class_type'];
  6332. $time = time();
  6333. $newExamGroupId = getUniqueId($this->schoolId);
  6334. //判断是否关联答题卡
  6335. if(isset($_POST["timu"])){
  6336. $text=$_POST["timu"];
  6337. //处理答题卡数据
  6338. $relationAnswerCard=true;
  6339. $name = Req::post("title");
  6340. $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
  6341. $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
  6342. $post = json_decode($text,true);
  6343. $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
  6344. $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
  6345. $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
  6346. $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
  6347. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  6348. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  6349. $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
  6350. $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
  6351. $subject_id=$this->subjectId;
  6352. if(!$text || !$name || !$sheet_answer || !$sheet_score){
  6353. $error['message'] = '题目参数错误';
  6354. echo json_encode($error);exit();
  6355. }
  6356. if(!$positionJson){
  6357. $error['message'] = '定位信息异常';
  6358. echo json_encode($error);exit();
  6359. }
  6360. //上传答题卡相关文件
  6361. $files=$this->uploadAnswerCardPdf($newExamGroupId,$positionJson,$pdfUrl);
  6362. $sheet_score_array = json_decode($sheet_score, 1);
  6363. if (!$sheet_score_array) {
  6364. $error['success']=0;
  6365. $error['message'] = '上传失败,未设置分数!';
  6366. echo json_encode($error);exit();
  6367. }
  6368. $score_num = count($sheet_score_array);
  6369. if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) {
  6370. $error['success']=0;
  6371. $error['message'] = '上传失败,设置分数或设置题号有误!';
  6372. echo json_encode($error);exit();
  6373. }
  6374. $select_info = json_decode($select_info, 1);
  6375. $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$json);
  6376. }
  6377. if($error){
  6378. echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
  6379. }
  6380. $transaction = $this->sConn->beginTransaction();
  6381. try{
  6382. $paperIds=array();
  6383. if($markType ==4)
  6384. {
  6385. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
  6386. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
  6387. }else
  6388. {
  6389. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
  6390. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
  6391. }
  6392. $this->sConn->createCommand($sql)->execute();
  6393. foreach($classIds as $classId){
  6394. $newExamId = getUniqueId($this->schoolId);
  6395. $this->sConn->createCommand()->insert('exam',array(
  6396. 'exam_id' => $newExamId,
  6397. 'exam_group_id' => $newExamGroupId,
  6398. 'name' => $examName,
  6399. 'semester_id' => $this->semesterId,
  6400. 'teacher_id' => $teacherId,
  6401. 'subject_id' => $subjectId,
  6402. 'module_id' => 0,
  6403. 'type' => $type,
  6404. 'school_card_status' => $cardData['card_status'],
  6405. 'school_card_length' => $cardData['card_length'],
  6406. 'status' => 2,
  6407. 'week_num' => 0,
  6408. 'create_type' => 0,
  6409. 'create_time' => $time,
  6410. 'update_time' => $time,
  6411. 'tpl_data' => jsonEncode($json),
  6412. 'tpl_index' => $tpl_index,
  6413. 'class_id' => $classId,
  6414. 'method_ids' => '',
  6415. ));
  6416. //$newPaperId = $this->UUID_SHORT();
  6417. $newPaperId = getUniqueId($this->schoolId);
  6418. $paperIds[]=$newPaperId;
  6419. $this->sConn->createCommand()->insert('paper', array(
  6420. 'paper_id' => $newPaperId,
  6421. 'paper_type' => 1,
  6422. 'exam_id' => $newExamId,
  6423. 'paper_name' => '',
  6424. 'paper_layer' => '',
  6425. 'difficulty' => 0,
  6426. 'topics_count' => 0,
  6427. 'score' => 0,
  6428. 'add_time' => $time,
  6429. 'update_time' => $time,
  6430. 'method_ids' => '',
  6431. 'is_labelled' => 0,
  6432. ));
  6433. $this->sConn->createCommand()->insert('class_exam_printer', array(
  6434. 'class_id' => $classId,
  6435. 'exam_id' => $newExamId,
  6436. 'type' => 0,
  6437. 'is_print' => 0,
  6438. 'print_time' => 0,
  6439. 'add_time' => $time,
  6440. ));
  6441. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  6442. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  6443. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  6444. if($studentIds_0){
  6445. foreach ($studentIds_0 as $studentId) {
  6446. $this->sConn->createCommand()->insert('student_paper_relation', array(
  6447. 'student_id' => $studentId,
  6448. 'paper_id' => $newPaperId,
  6449. 'exam_id' => $newExamId,
  6450. 'semester_id' => $this->semesterId,
  6451. 'class_id' => $classId,
  6452. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  6453. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  6454. 'class_type' =>$class_type
  6455. ));
  6456. }
  6457. }
  6458. }
  6459. if($relationAnswerCard){
  6460. $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
  6461. $topic_data = $this->get_topic_folder();
  6462. foreach($select_info['content'] as $k=>$v)
  6463. {
  6464. $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
  6465. $zsytkTopicType=$_topic_type;
  6466. if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
  6467. $this->sConn->createCommand()->insert('topic', array(
  6468. 'topic_type' =>$zsytkTopicType ,
  6469. 'topic_title' => '',
  6470. 'folder_id' => $topic_data['folder_id'],
  6471. 'subject_id' => $subject_id,
  6472. 'is_delete' =>0,
  6473. 'creator_id' => $teacherId,
  6474. 'updater_id' => $teacherId,
  6475. 'is_word_topic'=>1,
  6476. 'create_time' => time(),
  6477. 'update_time' => time(),
  6478. ));
  6479. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  6480. $topic_id=$last_insert_id['last_insert_id()'];
  6481. $this->sConn->createCommand()->insert('topic_item', array(
  6482. 'topic_id' => $topic_id,
  6483. 'topic_type' => $_topic_type,
  6484. 'topic_title' => ''
  6485. ));
  6486. //增加topic_option
  6487. if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
  6488. {
  6489. $answers = explode(',',$v['answer']);
  6490. if($answers && isset($answers[0]) && !empty($answers[0])){
  6491. $options = array_chunk($option,$v['optionCount']);
  6492. if(isset($options[0]) && !empty($options[0])){
  6493. foreach($options[0] as $item=>$val)
  6494. {
  6495. $this->sConn->createCommand()->insert('topic_item_option', array(
  6496. 'topic_id' => $topic_id,
  6497. 'option_id' => 0,
  6498. 'option_content' => '',
  6499. 'option_correct' => in_array($val,$answers)?1:0,
  6500. 'option_score' => 0,
  6501. 'sort_order' => $item,
  6502. ));
  6503. }
  6504. }
  6505. }
  6506. }
  6507. $this->sConn->createCommand()->insert('topic_use', array(
  6508. 'topic_id' => $topic_id,
  6509. 'mode' => 1,
  6510. 'teacher_id' => $teacherId,
  6511. 'paper_id' =>$newPaperId
  6512. ));
  6513. $questionCount = 0;
  6514. $questionScoreStr = '';
  6515. if(isset($v['scores']) && !empty($v['scores'])){
  6516. $scoresArr = explode(',',$v['scores']);
  6517. if($scoresArr){
  6518. $questionCount = count($scoresArr);
  6519. $questionScoreStr = $v['scores'];
  6520. }
  6521. }
  6522. foreach($paperIds as $p)
  6523. {
  6524. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  6525. 'paper_id' => $p,
  6526. 'topic_id' => $topic_id,
  6527. 'no' => $v['questionNum'],
  6528. 'order' => $v['questionNum'],
  6529. 'mode' => 1,
  6530. 'type' => $_topic_type,
  6531. 'score' =>$v['fullScore'],
  6532. 'question_count' => $questionCount,
  6533. 'question_score_str' => $questionScoreStr
  6534. ));
  6535. }
  6536. if($markType==4 && !in_array($v['questionTypeId'],array(1,11,2)))
  6537. {
  6538. if(isset($json['new_items'][$k]['alias'])){
  6539. $topicNo=$json['new_items'][$k]['alias'];
  6540. }elseif(isset($v['alias'])){
  6541. $topicNo=$v['alias'];
  6542. }
  6543. if(!$topicNo) $topicNo=$v['questionNum'];
  6544. $this->sConn->createCommand()->insert('marking_topic', array(
  6545. 'exam_group_id' => $newExamGroupId,
  6546. 'topic_id' => $topic_id,
  6547. 'topic_type' => $_topic_type,
  6548. 'topic_index' =>$v['questionNum'],
  6549. 'topic_no' =>$topicNo,
  6550. 'topic_score' =>$v['fullScore']
  6551. ));
  6552. }
  6553. }
  6554. $total = $json['total_score'];
  6555. $topics_count = count($select_info['content']);
  6556. $tpl_data=json_encode($json);
  6557. $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$newExamGroupId )->execute();
  6558. $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$newExamGroupId )->execute();
  6559. $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
  6560. $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`) ";
  6561. $insert.=" values('".$name."','".$newExamGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') ";
  6562. $this->sConn->createCommand($insert)->execute();
  6563. }
  6564. $transaction->commit();
  6565. }catch(Exception $e){
  6566. $transaction->rollBack();
  6567. echo json_encode(array('success'=>0,'message'=>'创建失败'));exit;
  6568. }
  6569. }
  6570. if(!$error){
  6571. echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
  6572. }
  6573. }
  6574. // 上传答题卡相关文件
  6575. private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){
  6576. $card_file=array();
  6577. $card_pdf='';
  6578. $ucloudZipUrl='';
  6579. $ucloudPdfUrl='';
  6580. if (empty($_FILES)) {
  6581. $error['message'] = '未找到上传文件!';
  6582. echo json_encode($error);exit();
  6583. }else {
  6584. // debug($_FILES);
  6585. foreach ($_FILES as $k => $v) {
  6586. if (isset($v) && !empty($v)) {
  6587. if (!isset($v['size']) || $v['size'] >= 8388608) {
  6588. $error['message'] = '文件超过8M!';
  6589. echo json_encode($error);
  6590. exit();
  6591. }
  6592. $ext = substr($v['name'], strrpos($v['name'], '.') + 1);
  6593. if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) {
  6594. $error['message'] = '文件格式不正确!';
  6595. echo json_encode($error);
  6596. exit();
  6597. }
  6598. if ($ext == 'pdf') {
  6599. $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf';
  6600. if (!move_uploaded_file($v["tmp_name"], $card_pdf)) {
  6601. $error['message'] = '保存Pdf文件失败!';
  6602. echo json_encode($error);
  6603. exit();
  6604. }
  6605. } else {
  6606. $card_file[] = $v;
  6607. }
  6608. }
  6609. }
  6610. $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/';
  6611. $ucloudPdfUrl = '';
  6612. if (!file_exists($fixName)) {
  6613. mkdir($fixName, 0777, true);
  6614. }
  6615. $zipFileName = $examGroupId .'_'.time().'.zip';
  6616. $pathName = $fixName . $zipFileName;
  6617. $zip = new ZipArchive;
  6618. $zip->open($pathName, ZipArchive::CREATE);
  6619. foreach ($card_file as $k => $v) {
  6620. $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
  6621. }
  6622. $zip->addFromString('json.txt', $positionJson);
  6623. $zip->close();
  6624. //FIXME 20191204
  6625. $ucloud = new Qcloud();
  6626. //上传压缩包
  6627. $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName;
  6628. $uploadInfo = $ucloud->putFile($rename, $pathName);
  6629. @unlink($pathName);
  6630. if ($uploadInfo['status'] == 0) {
  6631. $error['success'] = 0;
  6632. $error['message'] = '答题卡文件上传失败! ';
  6633. echo json_encode($error);
  6634. exit();
  6635. } else {
  6636. $ucloudZipUrl = $uploadInfo['url'];
  6637. }
  6638. //上传Pdf
  6639. if ($pdfUrl) {
  6640. $ucloudPdfUrl=$pdfUrl;
  6641. // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf';
  6642. // $content = file_get_contents($pdfUrl);
  6643. //
  6644. // file_put_contents($card_pdf, $content);
  6645. //
  6646. // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf';
  6647. // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf);
  6648. //
  6649. // if ($uploadInfo['status'] == 0) {
  6650. // @unlink($card_pdf);
  6651. // $error['success'] = 0;
  6652. // $error['message'] = '答题卡PDF文件上传失败!';
  6653. // echo json_encode($error);
  6654. // exit();
  6655. // } else {
  6656. // @unlink($card_pdf);
  6657. // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']);
  6658. // $ucloudPdfUrl = $uploadInfo['url'];
  6659. // }
  6660. }
  6661. //单独上传position.txt
  6662. if($positionJson){
  6663. $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ;
  6664. file_put_contents($positionTxt, $positionJson);
  6665. $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
  6666. $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
  6667. if ($uploadInfo['status'] == 0) {
  6668. @unlink($positionTxt);
  6669. $error['success']=0;
  6670. $error['message'] = 'Position文件上传失败!';
  6671. echo json_encode($error);exit();
  6672. }else{
  6673. @unlink($positionTxt);
  6674. $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  6675. $ucloudTxtUrl=$uploadInfo['url'];
  6676. }
  6677. }
  6678. }
  6679. return array(
  6680. 'ucloudZipUrl'=>$ucloudZipUrl,
  6681. 'ucloudPdfUrl'=>$ucloudPdfUrl,
  6682. 'positionUrl'=>$ucloudTxtUrl
  6683. );
  6684. }
  6685. //处理在线答题卡tpl_data
  6686. private function updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,$totals,$json){
  6687. $subject_id=$this->subjectId;
  6688. $exam_ids = array();
  6689. $_new_items = array();
  6690. $required_count = 0; //分组统计,即选做题中,必做题数量
  6691. $isDisplay = 1; //是否使用别名,
  6692. $selectTopicGroupScore = 0; //计算可能多分组情况总分
  6693. if ($select_info) {
  6694. if ($select_info && isset($select_info['content']) && !empty($select_info['content'])) {
  6695. //
  6696. $selectTopicGroupNum = 0; //分组试题显示序号
  6697. $nowGroupId = 0; //分组标志
  6698. $letterNum = 0;
  6699. $nowSameAliasNo=0; //选做题小题组序号
  6700. $sameAliasLetter=0;
  6701. foreach ($select_info['content'] as $k => $sc) {
  6702. //校验别名
  6703. if (isset($sc['alias']) && !empty($sc['alias'])) {
  6704. if (!preg_match('/^[0-9.\~]+$/u', $sc['alias']) || !is_numeric(substr($sc['alias'], -1)) || strlen($sc['alias']) > 6) {
  6705. $this->output(0, "别名格式不正确,别名允许字符【0-9.】且总长度不大于6位,请重新输入,题号:" . $sc['questionNum']);
  6706. exit;
  6707. }
  6708. }
  6709. if (isset($sc['questionTypeId'])) {
  6710. if ($sc['questionTypeId'] == 11 && in_array($subject_id,$this->mathSubjectId)) {
  6711. $this->output(0, "第三方暂不支持不定项选择题");
  6712. exit;
  6713. }
  6714. //分组判断
  6715. if (!isset($sc['groupid'])) {
  6716. $selectTopicGroupNum++;
  6717. $selectTopicGroupScore += $sc['fullScore'];
  6718. } elseif ($nowGroupId != $sc['groupid']) {
  6719. $isDisplay = 1;
  6720. $selectTopicGroupNum++;
  6721. $selectTopicGroupNum = isset($sc['alias']) ? $sc['alias'] : $selectTopicGroupNum;
  6722. $nowGroupId = $sc['groupid'];
  6723. if(isset($sc['smTopicLen']) && $sc['smTopicLen']){
  6724. $required_count+=$sc['smTopicLen'];
  6725. $selectTopicGroupScore += ($sc['fullScore']*$sc['smTopicLen']);
  6726. }else{
  6727. $required_count++;
  6728. $selectTopicGroupScore += $sc['fullScore'];
  6729. }
  6730. $letterNum = 0;
  6731. $sameAliasLetter=0;
  6732. }
  6733. if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && $sc['sameAliasNo']!=$nowSameAliasNo){
  6734. $sameAliasLetter++;
  6735. $nowSameAliasNo=$sc['sameAliasNo'];
  6736. }
  6737. $_new_items[$k]['sameAliasNo']=isset($sc['sameAliasNo'])?$sc['sameAliasNo']:0;
  6738. $_new_items[$k]['smTopicLen']=isset($sc['smTopicLen'])?$sc['smTopicLen']:0;
  6739. $_new_items[$k]['id'] = (int)$sc['questionNum'];
  6740. $_new_items[$k]['showNum'] = (string)$selectTopicGroupNum;
  6741. if ($sc['questionTypeId'] == 17) {
  6742. //判断选做题小题组
  6743. if($sameAliasLetter){
  6744. $_new_items[$k]['alias'] = (string)$sc['alias'] .$this->numToLetter($sameAliasLetter-1);
  6745. }else{
  6746. $_new_items[$k]['alias'] = (string)$selectTopicGroupNum . $this->numToLetter($letterNum);
  6747. }
  6748. } else {
  6749. if (isset($sc['alias'])) {
  6750. $_new_items[$k]['alias'] = (string)$sc['alias'];
  6751. } else {
  6752. $_new_items[$k]['alias'] = (string)$selectTopicGroupNum;
  6753. }
  6754. }
  6755. if(!$_new_items[$k]['alias']){
  6756. $_new_items[$k]['alias']=(int)$sc['questionNum'];
  6757. }
  6758. $_new_items[$k]['score'] = $sc['fullScore'];
  6759. $_new_items[$k]['topic_type'] = (string)$sc['questionTypeId'];
  6760. $_new_items[$k]['group_id'] = $sc['groupid'];
  6761. //新增逻辑题型
  6762. if (isset($sc['marktype'])) {
  6763. $_new_items[$k]['logic_type'] = $sc['marktype'];
  6764. }
  6765. //每道题科目
  6766. if (isset($sc['subject'])) {
  6767. $_new_items[$k]['subject'] = $sc['subject'];
  6768. }
  6769. $letterNum++;
  6770. //自动批阅
  6771. if(isset($sc['reviewSwitch']) && $sc['reviewSwitch']==1){
  6772. $_new_items[$k]['reviewSwitch'] = $sc['reviewSwitch']; //自动批阅开关
  6773. $_new_items[$k]['reviewWordNumber'] = $sc['reviewWordNumber']; //字数
  6774. $_new_items[$k]['reviewTopicImg'] = $sc['reviewTopicImg']; //试题截图链接
  6775. }
  6776. }
  6777. }
  6778. }
  6779. }
  6780. //处理半对分
  6781. $tplRules=array();
  6782. if($half_score){
  6783. $halfScoreArr=json_decode($half_score,true);
  6784. $sheetAnswerArr=json_decode($sheet_answer,true);
  6785. $sheet_score_array = json_decode($sheet_score, 1);
  6786. foreach ($halfScoreArr as $key => $val){
  6787. $ruleScore=0;
  6788. $ruleAnswer='';
  6789. if(isset($sheet_score_array[$key])){
  6790. $ruleScore=$sheet_score_array[$key];
  6791. }
  6792. if(isset($sheetAnswerArr[$key])){
  6793. $ruleAnswer=$sheetAnswerArr[$key];
  6794. }
  6795. $tplRules[$key]=array(
  6796. 'topicNo'=>$key,
  6797. 'topic_id'=>'',
  6798. 'rule_type'=>2,
  6799. 'rule_answer'=>$ruleAnswer,
  6800. 'rule_score'=>$ruleScore,
  6801. 'rule_score_half'=>$val
  6802. );
  6803. }
  6804. }
  6805. $json['disabled']=0;
  6806. $json['paper']=0;
  6807. $json['line']=0;
  6808. $json['anyway']=0;
  6809. $json['is_display']=$isDisplay;
  6810. $json['totals']=$totals;
  6811. $json['total_score']=$selectTopicGroupScore;
  6812. $json['scores']=$selectTopicGroupScore;
  6813. if(!isset($json['subjectId'])){
  6814. $json['subjectId']=$subject_id;
  6815. }
  6816. $json['new_items']=$_new_items;
  6817. $json['new_rules']=$tplRules;
  6818. $json['reviewer']='';
  6819. $json['is_new_marking']=1;
  6820. $json['required']=$required_count;
  6821. $json['times']=0;
  6822. $json['branch']=0;
  6823. if ($subject_id == 8) {
  6824. $json['isNewEnglish']=1;
  6825. }
  6826. return $json;
  6827. }
  6828. private function get_topic_folder()
  6829. {
  6830. $data = $this->sConn->createCommand("select * from topic_folder where is_system = 1")->queryRow();
  6831. if($data)
  6832. {
  6833. return $data;
  6834. }
  6835. return false;
  6836. }
  6837. //保存为第三方在线答题卡模板
  6838. public function actionSaveTemplateByOnline(){
  6839. $name = Req::post("title");
  6840. $layout = isset($_POST['layout'])?$_POST['layout']:'';
  6841. $select_card_type = isset($_POST['select_card_type'])?$_POST['select_card_type']:'1';
  6842. $total_score = isset($_POST['total_score'])?$_POST['total_score']:'0';
  6843. $total_topics = isset($_POST['total_topics'])?$_POST['total_topics']:'0';
  6844. $tpl_data = isset($_POST['tpl_data'])?$_POST['tpl_data']:'';
  6845. $error['success']=0;
  6846. // $count=$this->sConn->createCommand("select count(*) as count from third_tpl where subject_id='{$this->subjectId}'")->queryRow();
  6847. // if($count && $count['count']>9){
  6848. // $error['message'] = '同一学科最多保存10个模板';
  6849. // echo json_encode($error);exit();
  6850. // }
  6851. // if($tpl_data){
  6852. //
  6853. // $positionTxt="upload/ThirdSheet/" .$name.time().'.txt' ;
  6854. // file_put_contents($positionTxt, $tpl_data);
  6855. // $ucloud = new Qcloud();
  6856. // $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
  6857. // $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
  6858. //
  6859. // if ($uploadInfo['status'] == 0) {
  6860. // @unlink($positionTxt);
  6861. // $error['success']=0;
  6862. // $error['message'] = 'Position文件上传失败!';
  6863. // echo json_encode($error);exit();
  6864. // }else{
  6865. // @unlink($positionTxt);
  6866. // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
  6867. // $ucloudTxtUrl=$uploadInfo['url'];
  6868. // }
  6869. //
  6870. // }
  6871. $rs = $this->sConn->createCommand()->insert('third_tpl',array(
  6872. 'title' => $name,
  6873. 'subject_id' => $this->subjectId,
  6874. 'school_card_status' => 0,
  6875. 'school_card_length' => 0,
  6876. 'layout' => $layout,
  6877. 'select_card_type' => $select_card_type,
  6878. 'tpl_data' => $tpl_data,
  6879. 'total_score' => $total_score,
  6880. 'total_topics' => $total_topics,
  6881. 'create_time' => time()
  6882. ));
  6883. if($rs){
  6884. $error['success']=1;
  6885. $error['message'] = '保存成功';
  6886. echo json_encode($error);exit();
  6887. }
  6888. echo json_encode($error);exit();
  6889. }
  6890. //读取模板列表
  6891. public function actionTplList(){
  6892. $criteria = new CDbCriteria();
  6893. $criteria->addCondition('subject_id=:subject_id');
  6894. $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
  6895. $criteria->addCondition('school_card_length=0');
  6896. $criteria->order = 'third_tpl_id desc';
  6897. $thisTpls = SThirdTplModel::model()->findAll($criteria);
  6898. $list=array();
  6899. if($thisTpls)
  6900. {
  6901. foreach ($thisTpls as $val){
  6902. $jsonData='';
  6903. $tplData=$val->tpl_data;
  6904. if(strpos($tplData,'http://')!==false || strpos($tplData,'https://')!==false){
  6905. if(strpos($tplData,'zxhx.cn-bj.ufileos.com')!==false){
  6906. $tplData=str_replace('zxhx.cn-bj.ufileos.com','zxhx-u-1302712961.cos.ap-beijing.myqcloud.com',$tplData);
  6907. }
  6908. $jsonData=fileGetContents($tplData);
  6909. }else{
  6910. $jsonData=$val->tpl_data;
  6911. }
  6912. $jsonDataArr=json_decode($jsonData,true);
  6913. if(isset($jsonDataArr['position'])){
  6914. $list[]=array(
  6915. 'third_tpl_id'=>$val->third_tpl_id,
  6916. 'title'=>$val->title,
  6917. 'total_score'=>$val->total_score,
  6918. 'total_topics'=>$val->total_topics,
  6919. 'tpl_data'=>jsonEncode($jsonDataArr['position'])
  6920. );
  6921. }else{
  6922. $list[]=array(
  6923. 'third_tpl_id'=>$val->third_tpl_id,
  6924. 'title'=>$val->title,
  6925. 'total_score'=>$val->total_score,
  6926. 'total_topics'=>$val->total_topics,
  6927. 'tpl_data'=>$jsonData
  6928. );
  6929. }
  6930. }
  6931. $data['thisTpls'] = $list;
  6932. }
  6933. $data['success']=1;
  6934. exit(json_encode($data));
  6935. }
  6936. //删除模板
  6937. public function actionDelTpl(){
  6938. $third_tpl_id = Req::post("third_tpl_id");
  6939. if($third_tpl_id>0){
  6940. $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
  6941. if($thirdTpl){
  6942. echo json_encode(array('success'=>1,'msg'=>'1'));exit;
  6943. }
  6944. }
  6945. echo json_encode(array('success'=>0,'msg'=>'失败'));exit;
  6946. }
  6947. //读取考试答题卡
  6948. public function actionGetTemplateByExamGroupId(){
  6949. $exam_group_id = Req::post("examGroupId");
  6950. $isHide = Req::post("isHide");
  6951. if(!$exam_group_id){
  6952. $data['success']=0;
  6953. $data['msg']='考试id不正确';
  6954. exit(json_encode($data));
  6955. }
  6956. //验证是否有在线答题卡
  6957. $thirdAnswerSheet=$this->sConn->createCommand("select `name`,`file_path`,`position`,`online_card_pdf`,`online_card`,`is_qrcode_online`,`sheet_answer`,`sheet_score`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`multiplex_id`,`create_time`,`update_time` from third_answer_sheet where exam_group_id='".$exam_group_id."' and online_card=1")->queryRow();
  6958. $data['success']=1;
  6959. $data['data']=array();
  6960. //判断全学科
  6961. $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
  6962. $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryAll();
  6963. //判断全学科白名單
  6964. $data['new_answer_sheet_subject']=0;
  6965. if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){
  6966. $rs = http('/cms/api/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi');
  6967. $rs=json_decode($rs,true);
  6968. if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  6969. $data['new_answer_sheet_subject']=1;
  6970. }
  6971. }
  6972. if($thirdAnswerSheet){
  6973. $nowMultiplexId=$thirdAnswerSheet['multiplex_id'];
  6974. //判断是否有复用答题卡记录
  6975. if(!$nowMultiplexId){
  6976. $mult=$this->sConn->createCommand("select multiplex_id from online_card_multiplex where exam_group_id='{$exam_group_id}' and is_copy=0")->queryRow();
  6977. if(!$mult){
  6978. //旧数据没有复用记录,需要补一条记录
  6979. $onlineCardMultiModel=new SOnlineCardMultiplex();
  6980. $onlineCardMultiModel->exam_group_id=$exam_group_id;
  6981. $onlineCardMultiModel->name=$thirdAnswerSheet['name'];
  6982. $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path'];
  6983. $onlineCardMultiModel->position=$thirdAnswerSheet['position'];
  6984. $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf'];
  6985. $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online'];
  6986. $onlineCardMultiModel->is_download=0;
  6987. $onlineCardMultiModel->is_copy=0;
  6988. $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time'];
  6989. $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time'];
  6990. if($onlineCardMultiModel->save()){
  6991. $nowMultiplexId=$onlineCardMultiModel->multiplex_id;
  6992. $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$exam_group_id}'")->execute();
  6993. }
  6994. }else{
  6995. $nowMultiplexId=$mult['multiplex_id'];
  6996. $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$mult['multiplex_id']}' where exam_group_id='{$exam_group_id}'")->execute();
  6997. }
  6998. }
  6999. // if($thirdAnswerSheet['position']){
  7000. // if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){
  7001. // $thirdAnswerSheet['position']=fileGetContents($thirdAnswerSheet['position']);
  7002. // }
  7003. // }
  7004. if(!$examData){
  7005. $data['msg']='考试id不正确';
  7006. exit(json_encode($data));
  7007. }
  7008. $examIds=array();
  7009. foreach ($examData as $datum){
  7010. $examIds[]=$datum['exam_id'];
  7011. }
  7012. //判断是否有修改的判分规则
  7013. $tplData=json_decode($examData[0]['tpl_data'],true);
  7014. $questions=array();
  7015. if(isset($tplData['new_items'])){
  7016. foreach ($tplData['new_items'] as $val){
  7017. $alias=isset($val['alias'])?$val['alias']:$val['id'];
  7018. $temp=array(
  7019. 'questionNum'=>(int)$val['id'],
  7020. 'questionTypeId'=>(int)$val['topic_type'],
  7021. 'fullScore'=>(string)$val['score'],
  7022. 'alias'=>$alias,
  7023. );
  7024. if(isset($tplData['new_rules']) && isset($tplData['new_rules'][$val['id']])){
  7025. $temp['ruleScoreHalf']=$tplData['new_rules'][$val['id']]['rule_score_half'];
  7026. }
  7027. $questions[]=$temp;
  7028. }
  7029. }
  7030. $thirdAnswerSheet['questions']=$questions;
  7031. $thirdAnswerSheet['is_third']=$examGroup['is_third'];
  7032. if($examGroup['qxk_paper_id']){
  7033. if(isset($tplData['item_collect'])){
  7034. $itemCollect=array();
  7035. //读取大题型
  7036. $allSubjectTopicType=$this->schoolManager->getAllSubjectTopicType($examData[0]['subject_id']);
  7037. $allTopicTypeArr=array();
  7038. if($allSubjectTopicType){
  7039. foreach ($allSubjectTopicType as $item){
  7040. $allTopicTypeArr[$item['topic_type_id']]=$item['topic_type_name'];
  7041. }
  7042. }
  7043. //读取基础题型
  7044. $allBasicTopicTypeArr=array();
  7045. $allSubjectBasicTopicType=$this->schoolManager->getAllSubjectBasicType();
  7046. if($allSubjectBasicTopicType){
  7047. foreach ($allSubjectBasicTopicType as $item){
  7048. $allBasicTopicTypeArr[$item['btt_id']]=$item['btt_name'];
  7049. }
  7050. }
  7051. foreach ($tplData['item_collect'] as $key => $datum){
  7052. $topicTypeName='';
  7053. $topicBasicName='';
  7054. $topicCount=0;
  7055. if($datum['topicBasicType']==17){
  7056. $topicTypeName='选做题';
  7057. $topicBasicName='选做';
  7058. $topicCount='2选1'; //奇葩的需求
  7059. }else{
  7060. if(isset($allTopicTypeArr[$datum['topicType']])){
  7061. $topicTypeName=$allTopicTypeArr[$datum['topicType']];
  7062. }
  7063. if(isset($allBasicTopicTypeArr[$datum['topicBasicType']])){
  7064. $topicBasicName=$allBasicTopicTypeArr[$datum['topicBasicType']];
  7065. }
  7066. $topicCount=$datum['topicCount'];
  7067. }
  7068. $itemCollect[]=array(
  7069. "topic_type_name"=>$topicTypeName,
  7070. 'topic_basic_name'=>$topicBasicName,
  7071. 'topic_count'=>$topicCount,
  7072. 'total_score'=>$datum['totalScore']
  7073. );
  7074. }
  7075. $data['item_collect']=$itemCollect;
  7076. }
  7077. }
  7078. $where[]="exam_group_id={$exam_group_id}";
  7079. if($isHide){
  7080. $where[]="is_hide=1";
  7081. }else{
  7082. $where[]="is_hide=0";
  7083. }
  7084. $isDownload=0;
  7085. $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 ".implode(' and ',$where))->queryAll();
  7086. if($multi){
  7087. foreach ($multi as $key =>$value){
  7088. if($nowMultiplexId==$value['multiplex_id']){
  7089. $multi[$key]['active']=1;
  7090. }else{
  7091. $multi[$key]['active']=0;
  7092. }
  7093. if($value['is_download']==1){
  7094. $isDownload=1;
  7095. }
  7096. }
  7097. }
  7098. $data['multiplex']=$multi;
  7099. //查询是否有下载记录
  7100. if(!$isDownload){
  7101. $checkDownload=$this->sConn->createCommand("select is_download from online_card_multiplex where exam_group_id='".$exam_group_id."' and is_download=1")->queryRow();
  7102. if($checkDownload){
  7103. $isDownload=1;
  7104. }
  7105. }
  7106. //判断是否上传试卷
  7107. if(in_array($this->subjectId,$this->mathSubjectId) || $this->subjectId==12){
  7108. $checkPaperUpload=$this->sConn->createCommand("select * from topic_word where exam_group_id='".$exam_group_id."' and status>0")->queryRow();
  7109. }else{
  7110. $checkPaperUpload=$this->sConn->createCommand("select * from third_multi_template where exam_group_id='".$exam_group_id."' and (topic_upload=1 or answer_upload=1)")->queryRow();
  7111. }
  7112. if($checkPaperUpload){
  7113. $thirdAnswerSheet['paper_uploaded']=1;
  7114. }else{
  7115. $thirdAnswerSheet['paper_uploaded']=0;
  7116. }
  7117. //查询协助状态
  7118. $thirdAnswerSheet['assist_status']=0;
  7119. $assist=$this->conn->createCommand("select status from abnormal_template where exam_group_id={$exam_group_id}")->queryRow();
  7120. if($assist){
  7121. $thirdAnswerSheet['assist_status']=$assist['status'];
  7122. }
  7123. $data['success']=1;
  7124. $thirdAnswerSheet['is_download']=$isDownload;
  7125. $data['data']=$thirdAnswerSheet;
  7126. }else{
  7127. $data['data']=null;
  7128. }
  7129. exit(json_encode($data));
  7130. }
  7131. //切换模板,清空原模板数据
  7132. public function actionClearExamTpl(){
  7133. $exam_group_id = Req::post("examGroupId");
  7134. $data['success']=0;
  7135. if(!$exam_group_id){
  7136. $data['msg']='参数错误';
  7137. exit(json_encode($data));
  7138. }
  7139. $exam=$this->sConn->createCommand("select exam_id,status,tpl_data from exam where exam_group_id='{$exam_group_id}'")->queryAll();
  7140. if(!$exam){
  7141. $data['msg']='考试id不正确';
  7142. exit(json_encode($data));
  7143. }
  7144. if($exam['status']==1 || $exam['status']==4){
  7145. $data['msg']='已上传成绩,不能切换答题卡';
  7146. exit(json_encode($data));
  7147. }
  7148. $examIds=array();
  7149. $paperIds=array();
  7150. $topicIds=array();
  7151. $tplData=array();
  7152. foreach ($exam as $val){
  7153. $examIds[]=$val['exam_id'];
  7154. if(!$tplData){
  7155. $tplData=json_decode($val['tpl_data'],true);
  7156. }
  7157. }
  7158. $paperData=$this->sConn->createCommand("select paper_id from paper where exam_id in(".implode(',',$examIds).")")->queryAll();
  7159. if(!$paperData){
  7160. $data['msg']='试卷不存在';
  7161. exit(json_encode($data));
  7162. }
  7163. foreach ($paperData as $val){
  7164. $paperIds[]=$val['paper_id'];
  7165. }
  7166. $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id='".$paperIds[0]."'")->queryAll();
  7167. foreach ($paperTopic as $val){
  7168. $topicIds[]=$val['topic_id'];
  7169. }
  7170. $transaction = $this->sConn->beginTransaction();
  7171. try{
  7172. if(isset($tplData['items'])){
  7173. unset($tplData['items']);
  7174. }
  7175. if(isset($tplData['new_items'])){
  7176. unset($tplData['new_items']);
  7177. }
  7178. if(isset($tplData['new_rules'])){
  7179. unset($tplData['new_rules']);
  7180. }
  7181. $tplData['scores']=0;
  7182. $tplData['times']=0;
  7183. $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topicIds).")" )->execute();
  7184. $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topicIds).")" )->execute();
  7185. $this->sConn->createCommand("delete from topic_use where topic_id in (".implode(',',$topicIds).")" )->execute();
  7186. $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topicIds).")" )->execute();
  7187. $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
  7188. $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id )->execute();
  7189. $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$exam_group_id )->execute();
  7190. $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =".$exam_group_id )->execute();
  7191. $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute();
  7192. $this->sConn->createCommand("update exam set tpl_data ='".jsonEncode($tplData)."' where exam_group_id = ".$exam_group_id )->execute();
  7193. $this->sConn->createCommand("update paper set score = 0,topics_count = 0,is_labelled = 0 where exam_id in (".implode(',',$examIds).")")->execute();
  7194. $transaction->commit();
  7195. echo json_encode(array('success'=>1));exit;
  7196. }catch(Exception $e)
  7197. {
  7198. $transaction->rollBack();
  7199. echo json_encode(array('success'=>0));exit;
  7200. }
  7201. }
  7202. //修改第三方考试信息
  7203. public function actionAjaxModifyThirdExam(){
  7204. $exam_group_id = Req::post("examGroupId");
  7205. $type=Req::post('type');
  7206. $name=Req::post('examName');
  7207. $examDate=Req::post('examDate');
  7208. $paperType=Req::post('paperType');
  7209. $relationAnswerCard=false;
  7210. $data['success']=0;
  7211. if(!matchStrChar($name)){
  7212. $data['msg']='考试名称不能包含特殊字符!';
  7213. exit(json_encode($data));
  7214. }
  7215. if(Yii::app()->params['section']==0){
  7216. $paperType='1050';
  7217. }
  7218. $exam_group_data=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  7219. $transaction = $this->sConn->beginTransaction();
  7220. $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  7221. if(!$exam_data)
  7222. {
  7223. $data['msg']='非法试卷!';
  7224. exit(json_encode($data));
  7225. }
  7226. @$tplData=json_decode($exam_data['tpl_data'],true);
  7227. if(!$tplData){
  7228. $data['msg']='非法试卷!';
  7229. exit(json_encode($data));
  7230. }
  7231. $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
  7232. if(!$paperData){
  7233. $data['msg']='试卷不存在';
  7234. exit(json_encode($data));
  7235. }
  7236. try{
  7237. $tplData['examDate']=$examDate;
  7238. $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
  7239. $this->sConn->createCommand($examSql)->execute();
  7240. if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){
  7241. updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库
  7242. }
  7243. $transaction->commit();
  7244. $data['success']=1;
  7245. $data['msg']='编辑成功';
  7246. exit(json_encode($data));
  7247. }catch(Exception $e){
  7248. $transaction->rollBack();
  7249. $data['msg']='编辑失败';
  7250. exit(json_encode($data));
  7251. }
  7252. $data['msg']='编辑失败';
  7253. exit(json_encode($data));
  7254. }
  7255. //第三方创建在线答题卡需要准考证位数,所以需要确定年级
  7256. public function actionGetCardStatusByGrade(){
  7257. $grade=(int)Req::post("grade");
  7258. if(!in_array($grade,array(1,2,3))){
  7259. $data=array(
  7260. 'success'=>0,
  7261. 'msg'=>'年级不正确',
  7262. );
  7263. exit(json_encode($data));
  7264. }
  7265. $sql = "select card_length,card_status FROM grade where id='{$grade}'";
  7266. $cardData = $this->sConn->createCommand($sql)->queryRow();
  7267. if($cardData['card_status']==0){
  7268. $cardData['card_length'] = 8;
  7269. if($this->schoolId >999){
  7270. $cardData['card_length'] = 9;
  7271. }
  7272. }
  7273. $data=array(
  7274. 'success'=>1,
  7275. 'data'=>$cardData,
  7276. );
  7277. exit(json_encode($data));
  7278. }
  7279. //考试扫描异常处理状态查看
  7280. public function actionGetTaskDetail(){
  7281. $examGroupId = Req::get('exam_group_id');
  7282. $grade = Req::get('grade');
  7283. $branch = Req::get('branch');
  7284. $taskModel=new AScanTask();
  7285. $task=$taskModel->getTaskByExamGroupId($examGroupId);
  7286. if($task){
  7287. $task=$task->attributes;
  7288. if($task['operator']){
  7289. $user=AssistUser::model()->findByPk($task['operator']);
  7290. $task['user']=$user->real_name;
  7291. }else{
  7292. $task['user']='--';
  7293. }
  7294. //答题卡任务耗时
  7295. if($task['scan_task_apply_time']){
  7296. if($task['scan_task']>2){
  7297. if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){
  7298. $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']);
  7299. }else{
  7300. $task['AstConsuming']='--';
  7301. }
  7302. }elseif($task['scan_task']==2){
  7303. if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){
  7304. $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']);
  7305. }else{
  7306. $task['AstConsuming']='--';
  7307. }
  7308. }
  7309. }else{
  7310. $task['AstConsuming']='--';
  7311. }
  7312. }
  7313. //读取扫描数量
  7314. $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1);
  7315. $task['count']=$count;
  7316. $data['task']=$task;
  7317. $data['exam_group_id']=$examGroupId;
  7318. $_num= '';
  7319. $use_version = '';
  7320. if(isset(Yii::app()->session['coachInfo']->use_version))
  7321. {
  7322. $use_version = Yii::app()->session['coachInfo']->use_version;
  7323. }else
  7324. {
  7325. $use_version = Yii::app()->session['coachInfo']['use_version'];
  7326. }
  7327. if(!$use_version)
  7328. {
  7329. $use_version = 100;
  7330. }
  7331. $version_number = implode('',explode('.',$use_version));
  7332. if(strlen($version_number)<7)
  7333. {
  7334. for($i=0;$i<7-strlen($version_number);$i++)
  7335. {
  7336. $_num.='0';
  7337. }
  7338. }
  7339. $version_number=(int)$version_number.$_num;
  7340. $data['version_number']=$version_number;
  7341. $data['grade']=$grade;
  7342. $data['branch']=$branch;
  7343. $this->render('scan_detail',$data);
  7344. }
  7345. //关联第三方在线答题卡
  7346. public function actionInsertThirdSheet(){
  7347. $error = array();
  7348. $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
  7349. $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
  7350. $text=$_POST["timu"];
  7351. //处理答题卡数据
  7352. $relationAnswerCard=true;
  7353. $name = Req::post("title");
  7354. $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
  7355. $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
  7356. $post = json_decode($text,true);
  7357. $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
  7358. $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
  7359. $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
  7360. $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
  7361. $DuoXuanTi = isset($post["DuoXuanTi"]) ? $post["DuoXuanTi"] : 0;
  7362. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  7363. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  7364. $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
  7365. $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
  7366. $zhunkaozhen_length = isset($_POST['zhunkaozhen_length']) ? $_POST['zhunkaozhen_length'] : 0;
  7367. $isUploadScore=false; //是否已上传成绩
  7368. $isLabelled=false;
  7369. $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  7370. if(!$exam_data)
  7371. {
  7372. echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit;
  7373. }
  7374. $teacherId = $exam_data[0]['teacher_id'];
  7375. $subject_id = $exam_data[0]['subject_id'];
  7376. @$tplData=json_decode($exam_data[0]['tpl_data'],true);
  7377. if(!$tplData){
  7378. echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit;
  7379. }
  7380. if ($zhunkaozhen_length) {
  7381. if ($exam_data[0]['school_card_status'] == 1) {
  7382. if ($zhunkaozhen_length < $exam_data[0]['school_card_length']) {
  7383. echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用学校准考证号,长度为'.$exam_data[0]['school_card_length']));exit;
  7384. }
  7385. } else {
  7386. if ($zhunkaozhen_length < 8 && $this->schoolId < 999) {
  7387. echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为8'));exit;
  7388. }
  7389. if ($zhunkaozhen_length < 9 && ($this->schoolId > 999 && $this->schoolId < 9999)) {
  7390. echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为9'));exit;
  7391. }
  7392. }
  7393. }
  7394. if(!$text || !$name || !$sheet_answer || !$sheet_score){
  7395. $error['message'] = '题目参数错误';
  7396. echo json_encode($error);exit();
  7397. }
  7398. if(!$positionJson){
  7399. $error['message'] = '定位信息异常';
  7400. echo json_encode($error);exit();
  7401. }
  7402. if($error){
  7403. echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
  7404. }else{
  7405. $time = time();
  7406. $paper_data = $this->schoolManager->getPaperByExamId($exam_data[0]['exam_id']);
  7407. if ($paper_data) {
  7408. /**
  7409. * 验证已上传成绩,无法再次编辑
  7410. */
  7411. if ($exam_data) {
  7412. foreach ($exam_data as $v) {
  7413. $exam_ids[$v['exam_id']] = $v['exam_id'];
  7414. }
  7415. if ($exam_ids) {
  7416. $student_paper_feed=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$exam_ids).") and is_feedback=1 and is_del=0 ")->queryRow();
  7417. if ($student_paper_feed) {
  7418. $isUploadScore = true;
  7419. }
  7420. }
  7421. }
  7422. //判断是否发送标注
  7423. if ($paper_data['is_labelled'] != 0 ) {
  7424. $isLabelled = true;
  7425. }
  7426. }
  7427. //验证是否已下载,是否是复用的答题卡
  7428. if($multiplexId){
  7429. $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow();
  7430. if($checkMulti['is_download']){
  7431. $error['success']=0;
  7432. $error['message'] = '上传失败,答题卡已经下载!';
  7433. echo json_encode($error);exit();
  7434. }
  7435. if($checkMulti['is_copy']){
  7436. //只保存文件信息
  7437. $this->saveMultiplex();
  7438. }
  7439. }
  7440. $sheet_score_array = json_decode($sheet_score, 1);
  7441. if (!$sheet_score_array) {
  7442. $error['success']=0;
  7443. $error['message'] = '上传失败,未设置分数!';
  7444. echo json_encode($error);exit();
  7445. }
  7446. $score_num = count($sheet_score_array);
  7447. if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi+$DuoXuanTi )) {
  7448. $error['success']=0;
  7449. $error['message'] = '上传失败,设置分数或设置题号有误!';
  7450. echo json_encode($error);exit();
  7451. }
  7452. $items = array();
  7453. $xu = 0;
  7454. $t = 0;
  7455. $z = 0;
  7456. $x = 0;
  7457. $duo = 0;
  7458. foreach ($sheet_score_array as $k => $v) {
  7459. if ($KeGuanTi >= $k) {
  7460. $items[1]['total'] = $KeGuanTi;
  7461. $items[1]['perScores'][$xu] = $v;
  7462. for ($i = 0; $i < $KeGuanTi; $i++) {
  7463. $items[1]['no'][$i + 1] = $i + 1;
  7464. }
  7465. $xu++;
  7466. } elseif ($DuoXuanTi > 0 && $KeGuanTi < $k && $k <= ($KeGuanTi + $DuoXuanTi)) {
  7467. $items[2]['total'] = $DuoXuanTi;
  7468. $items[2]['perScores'][$duo] = $v;
  7469. for ($i = $KeGuanTi; $i < ($DuoXuanTi + $KeGuanTi); $i++) {
  7470. $items[2]['no'][$i + 1] = $i + 1;
  7471. }
  7472. $duo++;
  7473. } elseif ($TianKongTi > 0 && ($KeGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $DuoXuanTi)) {
  7474. $items[5]['total'] = $TianKongTi;
  7475. $items[5]['perScores'][$t] = $v;
  7476. for ($i = ($KeGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i++) {
  7477. $items[5]['no'][$i + 1] = $i + 1;
  7478. }
  7479. $t++;
  7480. } elseif ($ZhuGuanTi > 0 && ($KeGuanTi + $TianKongTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi)) {
  7481. $items[7]['total'] = $ZhuGuanTi;
  7482. $items[7]['perScores'][$z] = $v;
  7483. for ($i = ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i++) {
  7484. $items[7]['no'][$i + 1] = $i + 1;
  7485. }
  7486. $z++;
  7487. } elseif ($XuanZuoTi > 0 && ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi)) {
  7488. $items[17]['total'] = $XuanZuoTi;
  7489. $items[17]['required'] = 1;
  7490. $items[17]['score'] = $v;
  7491. $items[17]['perScores'][$x] = $v;
  7492. $_select_topic_scroe = $v;
  7493. for ($i = ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi); $i++) {
  7494. $items[17]['no'][$i + 1] = $i + 1;
  7495. }
  7496. $x++;
  7497. }
  7498. }
  7499. if (!$items) {
  7500. echo json_encode(array('success'=>0,'message'=>'上传失败,无题'));exit;
  7501. }
  7502. $select_info = json_decode($select_info, 1);
  7503. if(!isset($select_info['content']) || !$select_info['content']){
  7504. echo json_encode(array('success'=>0,'message'=>'上传失败,题目数据不能为空'));exit;
  7505. }
  7506. //检测id是否重复
  7507. $checkRepeatId=array();
  7508. foreach ($select_info['content'] as $value){
  7509. if(!isset($checkRepeatId[$value['questionNum']])){
  7510. $checkRepeatId[$value['questionNum']]=$value['questionNum'];
  7511. }else{
  7512. echo json_encode(array('success'=>0,'message'=>'上传失败,题目序号重复'.$value['questionNum']));exit;
  7513. }
  7514. }
  7515. //上传答题卡相关文件
  7516. $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
  7517. $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData);
  7518. $json['items']=$items;
  7519. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  7520. if($error){
  7521. echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
  7522. }
  7523. $transaction = $this->sConn->beginTransaction();
  7524. try{
  7525. $topic_ids=array();
  7526. $paperIds=$this->schoolManager->getPaperIdsByExamIds($exam_ids);
  7527. //判断是否已关联答题卡
  7528. //判断原答题卡
  7529. $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
  7530. if($thirdAnswerSheet){
  7531. $oldSheetAnswer = $thirdAnswerSheet['sheet_answer'];
  7532. $oldSheetScore = $thirdAnswerSheet['sheet_score'];
  7533. if($isUploadScore || $isLabelled){
  7534. //判断答案是否改变
  7535. if (strcmp($oldSheetAnswer, $sheet_answer) != false) {
  7536. echo json_encode(array('success'=>0,'message'=>'上传失败,已上传成绩,不能修改试题答案'));exit;
  7537. }
  7538. if (strcmp($oldSheetScore, $sheet_score) != false) {
  7539. echo json_encode(array('success'=>0,'message'=>'传失败,已上传成绩,不能修改试题分数'));exit;
  7540. }
  7541. if($multiplexId){
  7542. $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  7543. }
  7544. $insert="replace 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`,`select_info`) ";
  7545. $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$files['positionUrl']."',1,'".$files['ucloudPdfUrl']."','0','".json_encode($select_info)."') ";
  7546. $this->sConn->createCommand($insert)->execute();
  7547. $transaction->commit();
  7548. echo json_encode(array('success'=>1,'message'=>'创建成功'));exit;
  7549. }
  7550. $paperTopic=$this->sConn->createCommand("select topic_id,type from paper_topic_relation where paper_id ='{$paperIds[0]}'")->queryAll();
  7551. foreach ($paperTopic as $item){
  7552. $topic_ids[]=$item['topic_id'];
  7553. }
  7554. //删除数据
  7555. $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute();
  7556. $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute();
  7557. $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute();
  7558. $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
  7559. $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$examGroupId )->execute();;
  7560. $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$examGroupId )->execute();;
  7561. $this->sConn->createCommand("delete from topic_word where exam_group_id =".$examGroupId )->execute();
  7562. }
  7563. $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
  7564. $topic_data = $this->get_topic_folder();
  7565. foreach($select_info['content'] as $k=>$v)
  7566. {
  7567. if(isset($v['scoreColumnHtml'])){
  7568. unset($select_info['content'][$k]['scoreColumnHtml']);
  7569. }
  7570. $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
  7571. $zsytkTopicType=$_topic_type;
  7572. if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
  7573. $this->sConn->createCommand()->insert('topic', array(
  7574. 'topic_type' =>$zsytkTopicType ,
  7575. 'topic_title' => '',
  7576. 'folder_id' => $topic_data['folder_id'],
  7577. 'subject_id' => $subject_id,
  7578. 'is_delete' =>0,
  7579. 'creator_id' => $teacherId,
  7580. 'updater_id' => $teacherId,
  7581. 'is_word_topic'=>1,
  7582. 'create_time' => time(),
  7583. 'update_time' => time(),
  7584. ));
  7585. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  7586. $topic_id=$last_insert_id['last_insert_id()'];
  7587. $this->sConn->createCommand()->insert('topic_item', array(
  7588. 'topic_id' => $topic_id,
  7589. 'topic_type' => $_topic_type,
  7590. 'topic_title' => ''
  7591. ));
  7592. //增加topic_option
  7593. if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
  7594. {
  7595. $answers = explode(',',$v['answer']);
  7596. if($answers && isset($answers[0]) && !empty($answers[0])){
  7597. $options = array_chunk($option,$v['optionCount']);
  7598. if(isset($options[0]) && !empty($options[0])){
  7599. foreach($options[0] as $item=>$val)
  7600. {
  7601. $this->sConn->createCommand()->insert('topic_item_option', array(
  7602. 'topic_id' => $topic_id,
  7603. 'option_id' => 0,
  7604. 'option_content' => '',
  7605. 'option_correct' => in_array($val,$answers)?1:0,
  7606. 'option_score' => 0,
  7607. 'sort_order' => $item,
  7608. ));
  7609. }
  7610. }
  7611. }
  7612. }
  7613. $this->sConn->createCommand()->insert('topic_use', array(
  7614. 'topic_id' => $topic_id,
  7615. 'mode' => 1,
  7616. 'teacher_id' => $teacherId,
  7617. 'paper_id' =>$paperIds[0]
  7618. ));
  7619. $questionCount = 0;
  7620. $questionScoreStr = '';
  7621. if(isset($v['scores']) && !empty($v['scores'])){
  7622. $scoresArr = explode(',',$v['scores']);
  7623. if($scoresArr){
  7624. $questionCount = count($scoresArr);
  7625. $questionScoreStr = $v['scores'];
  7626. }
  7627. }
  7628. foreach($paperIds as $p)
  7629. {
  7630. $this->sConn->createCommand()->insert('paper_topic_relation', array(
  7631. 'paper_id' => $p,
  7632. 'topic_id' => $topic_id,
  7633. 'no' => $v['questionNum'],
  7634. 'order' => $v['questionNum'],
  7635. 'mode' => 1,
  7636. 'type' => $_topic_type,
  7637. 'score' =>$v['fullScore'],
  7638. 'question_count' => $questionCount,
  7639. 'question_score_str' => $questionScoreStr
  7640. ));
  7641. }
  7642. if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2)))
  7643. {
  7644. if(isset($json['new_items'][$k]['alias'])){
  7645. $topicNo=$json['new_items'][$k]['alias'];
  7646. }elseif(isset($v['alias'])){
  7647. $topicNo=$v['alias'];
  7648. }
  7649. if(!$topicNo) $topicNo=$v['questionNum'];
  7650. //判断自动批阅字段
  7651. $autoType=0;
  7652. if($subject_id==8){
  7653. if(in_array($v['marktype'],array(13,16,17)) && !$questionCount){
  7654. $autoType=1;
  7655. }elseif($_topic_type==5){
  7656. $autoType=2;
  7657. }
  7658. }
  7659. $this->sConn->createCommand()->insert('marking_topic', array(
  7660. 'exam_group_id' => $examGroupId,
  7661. 'topic_id' => $topic_id,
  7662. 'topic_type' => $_topic_type,
  7663. 'topic_index' =>$v['questionNum'],
  7664. 'topic_no' =>$topicNo,
  7665. 'topic_score' =>$v['fullScore'],
  7666. 'auto_type'=>$autoType
  7667. ));
  7668. }
  7669. }
  7670. if(!$multiplexId){
  7671. //没有复用记录,初始化一条记录
  7672. $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`) values";
  7673. $insertSql.="('".$examGroupId."','".$name."','".$files['ucloudZipUrl']."','".$files['positionUrl']."','".$files['ucloudPdfUrl']."','".time()."','".time()."')";
  7674. $this->sConn->createCommand($insertSql)->execute();
  7675. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  7676. $multiplexId=$last_insert_id['last_insert_id()'];
  7677. }else {
  7678. //更新复用记录
  7679. $updateSql = "update online_card_multiplex set `file_path`='{$files['ucloudZipUrl']}',`position`='{$files['positionUrl']}',`online_card_pdf`='{$files['ucloudPdfUrl']}',update_time='" . time() . "' where multiplex_id='{$multiplexId}'";
  7680. $this->sConn->createCommand($updateSql)->execute();
  7681. }
  7682. $total = $json['total_score'];
  7683. $topics_count = count($select_info['content']);
  7684. $tpl_data=jsonEncode($json);
  7685. $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$examGroupId )->execute();
  7686. $this->sConn->createCommand("update topic_word set status =0,word_path='' where exam_group_id = ".$examGroupId )->execute();
  7687. $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$examGroupId )->execute();
  7688. $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
  7689. $insert="replace 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`,`select_info`,`multiplex_id`) ";
  7690. $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$files['positionUrl']."',1,'".$files['ucloudPdfUrl']."','0','".jsonEncode($select_info)."','".$multiplexId."') ";
  7691. $this->sConn->createCommand($insert)->execute();
  7692. $OnlineCardSaveLogModel=new SOnlineCardSaveLog();
  7693. $OnlineCardSaveLogModel->exam_group_id=$examGroupId;
  7694. $OnlineCardSaveLogModel->file_path=$files['ucloudZipUrl'];
  7695. $OnlineCardSaveLogModel->online_card_pdf=$files['ucloudPdfUrl'];
  7696. $OnlineCardSaveLogModel->position=$files['positionUrl'];
  7697. $OnlineCardSaveLogModel->create_time=time();
  7698. $OnlineCardSaveLogModel->save();
  7699. $transaction->commit();
  7700. }catch(Exception $e){
  7701. $transaction->rollBack();
  7702. echo json_encode(array('success'=>0,'message'=>'创建失败'));exit;
  7703. }
  7704. }
  7705. if(!$error){
  7706. echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId,'multiplex_id'=>$multiplexId));exit;
  7707. }else{
  7708. echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
  7709. }
  7710. }
  7711. //创建考试并下一步ajax
  7712. public function actionCreatethirdForNext(){
  7713. $error = array();
  7714. $tplData = array();
  7715. $semesterId = $this->semesterId;
  7716. $examName = Req::post("examName");
  7717. $type = (int)Req::post("type");
  7718. $classIds = Req::post("classIds");
  7719. $markType = Req::post("markType");
  7720. $teacherId = Req::post("teacherId");
  7721. $subjectId = Req::post("subjectId");
  7722. $textbookId = Req::post("textbookId");
  7723. $examDate = Req::post("examDate");
  7724. $tpl_index = (int)Req::post("tpl_index");
  7725. $qxkPaperId = (int)Req::post("isQxk");
  7726. if(Yii::app()->params['section']==0){
  7727. $tpl_index='1050';
  7728. }
  7729. if(empty($classIds)){
  7730. $error[] = '请指定考试班级';
  7731. }else{
  7732. $classIds = explode(',',$classIds);
  7733. }
  7734. if(empty($examName)){
  7735. $error[] = '请设置考试名称';
  7736. }
  7737. if ($type <= 0 || $type > 9) {
  7738. $error[] = '考试类型错误';
  7739. }
  7740. if(empty($subjectId)){
  7741. $error[] = '请选择题源';
  7742. }
  7743. if(!matchStrChar($examName)){
  7744. $error[] = '考试名称不能包含特殊字符!';
  7745. }
  7746. if(empty($teacherId)){
  7747. $error[] = '请指定阅卷老师';
  7748. }
  7749. if(empty($examDate)){
  7750. $error[] = '请指定考试时间';
  7751. }
  7752. if(empty($tpl_index)){
  7753. $error[] = '请指定类型';
  7754. }
  7755. if($qxkPaperId && in_array($subjectId,$this->mathSubjectId)){
  7756. $subjectId=3;
  7757. }
  7758. if($error){
  7759. echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
  7760. }else{
  7761. $teacherName = Teacher ::model()->getTeacherName($teacherId);
  7762. if($teacherName){
  7763. $tplData['author'] = $teacherName;
  7764. $tplData['subjectId'] = $subjectId;
  7765. $tplData['textbookId'] = $textbookId;
  7766. $tplData['examDate'] = $examDate;
  7767. }
  7768. $time = time();
  7769. $transaction = $this->sConn->beginTransaction();
  7770. try{
  7771. $newExamGroupId=getUniqueId($this->schoolId);
  7772. if($markType ==4){
  7773. $markStatus=1;
  7774. $status=1;
  7775. }else{
  7776. $markStatus=0;
  7777. $status=0;
  7778. }
  7779. $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`,`qxk_paper_id`) "
  7780. . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")";
  7781. $this->sConn->createCommand($sql)->execute();
  7782. foreach($classIds as $classId){
  7783. if(!$classId) continue;
  7784. $newExamId = getUniqueId($this->schoolId);
  7785. $sql = "select g.card_length,g.card_status,c.class_type FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
  7786. $cardData = $this->sConn->createCommand($sql)->queryRow();
  7787. if($cardData['card_status']==0){
  7788. $cardData['card_length'] = 8;
  7789. if($this->schoolId >999){
  7790. $cardData['card_length'] = 9;
  7791. }
  7792. }
  7793. $class_type=$cardData['class_type'];
  7794. $this->sConn->createCommand()->insert('exam',array(
  7795. 'exam_id' => $newExamId,
  7796. 'exam_group_id' => $newExamGroupId,
  7797. 'name' => $examName,
  7798. 'semester_id' => $this->semesterId,
  7799. 'teacher_id' => $teacherId,
  7800. 'subject_id' => $subjectId,
  7801. 'module_id' => 0,
  7802. 'type' => $type,
  7803. 'school_card_status' => $cardData['card_status'],
  7804. 'school_card_length' => $cardData['card_length'],
  7805. 'status' => 2,
  7806. 'week_num' => 0,
  7807. 'create_type' => 0,
  7808. 'create_time' => $time,
  7809. 'update_time' => $time,
  7810. 'tpl_data' => jsonEncode($tplData),
  7811. 'tpl_index' => $tpl_index,
  7812. 'class_id' => $classId,
  7813. 'method_ids' => '',
  7814. ));
  7815. // $newPaperId = $this->UUID_SHORT();
  7816. $newPaperId= getUniqueId($this->schoolId);
  7817. $this->sConn->createCommand()->insert('paper', array(
  7818. 'paper_id' => $newPaperId,
  7819. 'paper_type' => 1,
  7820. 'exam_id' => $newExamId,
  7821. 'paper_name' => '',
  7822. 'paper_layer' => '',
  7823. 'difficulty' => 0,
  7824. 'topics_count' => 0,
  7825. 'score' => 0,
  7826. 'add_time' => $time,
  7827. 'update_time' => $time,
  7828. 'method_ids' => '',
  7829. 'is_labelled' => 0,
  7830. ));
  7831. $this->sConn->createCommand()->insert('class_exam_printer', array(
  7832. 'class_id' => $classId,
  7833. 'exam_id' => $newExamId,
  7834. 'type' => 0,
  7835. 'is_print' => 0,
  7836. 'print_time' => 0,
  7837. 'add_time' => $time,
  7838. ));
  7839. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  7840. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  7841. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  7842. if($studentIds_0){
  7843. foreach ($studentIds_0 as $studentId) {
  7844. // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
  7845. // if($studentIds){
  7846. // foreach ($studentIds as $studentId) {
  7847. $this->sConn->createCommand()->insert('student_paper_relation', array(
  7848. 'student_id' => $studentId,
  7849. 'paper_id' => $newPaperId,
  7850. 'exam_id' => $newExamId,
  7851. 'semester_id' => $this->semesterId,
  7852. 'class_id' => $classId,
  7853. 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  7854. 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  7855. 'class_type' =>$class_type
  7856. ));
  7857. $this->sConn->createCommand()->insert('student_paper_relation_property', array(
  7858. 'student_id' => $studentId,
  7859. 'paper_id' => $newPaperId,
  7860. 'exam_id' => $newExamId,
  7861. 'semester_id' => $this->semesterId,
  7862. 'class_id' => $classId,
  7863. 'create_time' =>$time
  7864. ));
  7865. }
  7866. }
  7867. }
  7868. $transaction->commit();
  7869. }catch(Exception $e){
  7870. $transaction->rollBack();
  7871. if (YII_ENV == 'production') {
  7872. $error[] = '系统错误[SQL]';
  7873. } else {
  7874. $error[] = $e->getMessage();
  7875. }
  7876. echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
  7877. }
  7878. }
  7879. if(!$error){
  7880. echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'examGroupId'=>$newExamGroupId));exit;
  7881. }
  7882. }
  7883. public function actionGetOnlinePdf(){
  7884. $semesterId = $this->semesterId;
  7885. $width = Req::post("width");
  7886. $height = Req::post("height");
  7887. $pdfHtml = Req::post("pdfHtml");
  7888. $examGroupId = Req::post("examGroupId");
  7889. if(!$width || !$height){
  7890. $error['success']=0;
  7891. $error['message'] = '缺少纸张大小参数';
  7892. $error['data'] = '';
  7893. echo json_encode($error);exit();
  7894. }
  7895. if(!$pdfHtml){
  7896. $error['success']=0;
  7897. $error['message'] = '缺少模板数据';
  7898. $error['data'] = '';
  7899. echo json_encode($error);exit();
  7900. }
  7901. if(!$examGroupId){
  7902. $error['success']=0;
  7903. $error['message'] = '缺少考试数据';
  7904. $error['data'] = '';
  7905. echo json_encode($error);exit();
  7906. }
  7907. $sendData=array(
  7908. 'schoolId'=>$this->schoolId,
  7909. 'examGroupId'=>$examGroupId,
  7910. 'savedInfoUrl'=>$pdfHtml,
  7911. 'semesterId'=>$semesterId,
  7912. 'width'=>$width,
  7913. 'height'=>$height
  7914. );
  7915. $return=sendDataToKafka('zsyas2-online-card-alone-notify',$sendData);
  7916. $ucloudPdfUrl='';
  7917. if($return){
  7918. $maxTimes=25;
  7919. $server = Yii::app()->params["phpServiceRedis"]["servers"];
  7920. $redis = new Redis();
  7921. $redis->connect($server["host"], $server["port"]);
  7922. if(isset($server['password'])){
  7923. $redis->auth($server['password']);
  7924. }
  7925. $redis->select($server['database']);
  7926. for($i=0;$i<$maxTimes;$i++){
  7927. $redis_get_pdf_status =$redis->get('php_service:exam_group_online_card:'.$examGroupId);
  7928. if($redis_get_pdf_status ){
  7929. $ucloudPdfUrl=$redis_get_pdf_status;
  7930. $redis->set('php_service:exam_group_online_card:'.$examGroupId,'');
  7931. break;
  7932. }
  7933. sleep(1);
  7934. }
  7935. }
  7936. if($ucloudPdfUrl){
  7937. $error['success']=1;
  7938. $error['message'] = '保存成功!';
  7939. $error['data'] = $ucloudPdfUrl;
  7940. }else{
  7941. $error['success']=0;
  7942. $error['message'] = '生成失败';
  7943. $error['data'] = '';
  7944. }
  7945. echo json_encode($error);exit();
  7946. }
  7947. public function actionDownload()
  7948. {
  7949. $url = Req::get('url');
  7950. $title = Req::get('title');
  7951. if (empty($url) ) {
  7952. return false;
  7953. }
  7954. if(!$title) $title=time().'temp';
  7955. $ext=substr($url,strrpos($url,'.')+1);
  7956. $path='upload/tmpDir/downloadTempFiled/';
  7957. if (!file_exists($path)) {
  7958. mkdir($path, 0777, true);
  7959. }
  7960. $pathName=$path.$title.'.'.$ext;
  7961. // 获取远程文件资源
  7962. $ch = curl_init();
  7963. curl_setopt($ch, CURLOPT_URL, $url);
  7964. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7965. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
  7966. $tempFile = curl_exec($ch);
  7967. curl_close($ch);
  7968. // 保存文件
  7969. $fp = @fopen($pathName, "w");
  7970. fwrite($fp, $tempFile);
  7971. fclose($fp);
  7972. header('content-type:application/octet-stream');
  7973. header('content-disposition:attachment; filename='.get_basename($pathName));
  7974. header('content-length:'.filesize($pathName));
  7975. readfile($pathName);
  7976. }
  7977. //在线答题卡旧版第二步页面
  7978. public function actionThirdCardSecond(){
  7979. $examGroupId = Req::get('examGroupId');
  7980. $this->render('third_card_second',array('examGroupId'=>$examGroupId));
  7981. }
  7982. //复用在线答题卡
  7983. public function actionMultiplex(){
  7984. $multiplexId=Req::post("multiplexId"); //被复用的记录ID
  7985. $name=Req::post("name"); //新答题卡名称
  7986. $result=array();
  7987. $result['status']=0;
  7988. if(!$multiplexId){
  7989. $result['msg']='答题卡ID不能为空';
  7990. exit(json_encode($result));
  7991. }
  7992. if(!$name){
  7993. $result['msg']='答题卡名称不能为空';
  7994. exit(json_encode($result));
  7995. }
  7996. $check=$this->sConn->createCommand("select `multiplex_id`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_download`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
  7997. if(!$check){
  7998. $result['msg']='答题卡模板不存在';
  7999. exit(json_encode($result));
  8000. }
  8001. if(!$check['is_download']){
  8002. $result['msg']='答题卡尚未下载,如需修改请直接编辑答题卡';
  8003. exit(json_encode($result));
  8004. }
  8005. $onlineCardMultiModel = new SOnlineCardMultiplex();
  8006. $onlineCardMultiModel->exam_group_id = $check['exam_group_id'];
  8007. $onlineCardMultiModel->name = $name;
  8008. $onlineCardMultiModel->file_path = $check['file_path'];
  8009. $onlineCardMultiModel->position = $check['position'];
  8010. $onlineCardMultiModel->online_card_pdf = $check['online_card_pdf'];
  8011. $onlineCardMultiModel->is_qrcode_online = $check['is_qrcode_online'];
  8012. $onlineCardMultiModel->is_download = 0;
  8013. $onlineCardMultiModel->is_copy = 1;
  8014. $onlineCardMultiModel->create_time = time();
  8015. $onlineCardMultiModel->update_time = time();
  8016. if ($onlineCardMultiModel->save()) {
  8017. $result['status'] = 1;
  8018. $result['msg'] = '复用成功';
  8019. $result['data'] = $onlineCardMultiModel->multiplex_id;
  8020. }
  8021. exit(json_encode($result));
  8022. }
  8023. //版本列表切换在线答题卡
  8024. public function actionChangeCard(){
  8025. $multiplexId=Req::post("multiplexId"); //记录ID
  8026. $result=array();
  8027. $result['status']=0;
  8028. $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
  8029. if(!$check){
  8030. $result['msg']='答题卡模板不存在';
  8031. exit(json_encode($result));
  8032. }
  8033. if($this->sConn->createCommand("update third_answer_sheet set `multiplex_id`='{$multiplexId}',`name`='{$check['name']}',`file_path`='{$check['file_path']}',`position`='{$check['position']}',`online_card_pdf`='{$check['online_card_pdf']}',`is_qrcode_online`='{$check['is_qrcode_online']}' where exam_group_id='{$check['exam_group_id']}'")->execute()){
  8034. $result['status']=1;
  8035. $result['msg']='切换成功';
  8036. $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='".$check['exam_group_id']."'")->queryAll();
  8037. $examIds=array();
  8038. foreach ($exam as $item){
  8039. $examIds[]=$item['exam_id'];
  8040. }
  8041. $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).")")->execute();
  8042. $this->sConn->createCommand("delete from exam_process where exam_group_id='".$check['exam_group_id']."' and action_type in(9,13,14)")->execute();
  8043. }
  8044. exit(json_encode($result));
  8045. }
  8046. //下载标记
  8047. public function actionDownloadStatus(){
  8048. $multiplexId=Req::post("multiplexId"); //记录ID
  8049. $result=array();
  8050. $result['status']=0;
  8051. if(!$multiplexId) {
  8052. $result['msg']='答题卡Id不能为空';
  8053. exit(json_encode($result));
  8054. }
  8055. $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
  8056. if(!$check){
  8057. $result['msg']='答题卡模板不存在';
  8058. exit(json_encode($result));
  8059. }
  8060. $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  8061. $this->schoolManager->saveExamProcess($check['exam_group_id'],9,time());
  8062. $result['status']=1;
  8063. $result['msg']='更新成功';
  8064. exit(json_encode($result));
  8065. }
  8066. //隐藏答题卡
  8067. public function actionHideAnswerCard(){
  8068. $multiplexId=Req::post("multiplexId"); //记录ID
  8069. $isHide=Req::post("isHide"); //记录ID
  8070. if(!$isHide) $isHide=0;
  8071. $result=array();
  8072. $result['status']=0;
  8073. if(!$multiplexId) {
  8074. $result['msg']='答题卡Id不能为空';
  8075. exit(json_encode($result));
  8076. }
  8077. $this->sConn->createCommand("update online_card_multiplex set is_hide={$isHide} where multiplex_id='{$multiplexId}'")->execute();
  8078. $result['status']=1;
  8079. $result['msg']='更新成功';
  8080. exit(json_encode($result));
  8081. }
  8082. //复用的答题卡编辑后保存
  8083. private function saveMultiplex(){
  8084. $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
  8085. $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
  8086. $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
  8087. $positionJson=isset($_POST['position'])?$_POST['position']:'';
  8088. //上传答题卡相关文件
  8089. $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
  8090. $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  8091. $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow();
  8092. if($thirdAnswer['multiplex_id']==$multiplexId){
  8093. $this->sConn->createCommand("update third_answer_sheet set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
  8094. }
  8095. echo json_encode(array('status'=>1,'msg'=>'创建成功','data'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId));exit;
  8096. }
  8097. //读取在线答题卡复用内容
  8098. public function actionGetMultiplex(){
  8099. $multiplexId=Req::post("multiplexId"); //记录ID
  8100. $result=array();
  8101. $result['status']=0;
  8102. $check=$this->sConn->createCommand("select `multiplex_id`,`name`,`file_path`,`position`,`online_card_pdf`,`exam_group_id`,`is_hide`,`is_copy`,`is_download`,`create_time`,`update_time`,`is_qrcode_online` from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
  8103. if(!$check){
  8104. $result['msg']='答题卡模板不存在';
  8105. exit(json_encode($result));
  8106. }
  8107. //判断全学科
  8108. $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$check['exam_group_id']."'")->queryRow();
  8109. $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$check['exam_group_id']}'")->queryAll();
  8110. //判断全学科白名單
  8111. $check['new_answer_sheet_subject']=0;
  8112. if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){
  8113. $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi');
  8114. $rs=json_decode($rs,true);
  8115. if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
  8116. $check['new_answer_sheet_subject']=1;
  8117. }
  8118. }
  8119. if($check['position']){
  8120. if(strpos($check['position'],'http://')!==false || strpos($check['position'],'https://')!==false){
  8121. $check['position']=fileGetContents($check['position']);
  8122. }
  8123. }
  8124. $result['data']=$check;
  8125. exit(json_encode($result));
  8126. }
  8127. //加载考试完成考试复用试卷 最近30场完成解析的考试
  8128. public function actionLoadCopyPaper(){
  8129. $grade=Req::post('grade');
  8130. $examGroupId=Req::post('examGroupId');
  8131. $condition=array();
  8132. $subject=$this->subjectId;
  8133. $condition[]='eg.is_third=1';
  8134. // $condition[]='e.status=1';
  8135. $condition[]='tw.status=2';
  8136. $condition[]="eg.exam_group_id<>'".$examGroupId."'";
  8137. if($subject==3){
  8138. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  8139. }else{
  8140. $condition[]="e.subject_id ='".$subject."'";
  8141. }
  8142. if($grade){
  8143. $condition[]="c.grade='".$grade."'";
  8144. }
  8145. $sql="SELECT eg.exam_group_id,e.name,e.tpl_data,e.create_time FROM `exam` e ";
  8146. $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
  8147. $sql.="join class c on c.class_id=e.class_id ";
  8148. $sql.=" join topic_word tw on tw.exam_group_id=e.exam_group_id ";
  8149. if($condition){
  8150. $sql.=" where ".implode(' and ',$condition);
  8151. }
  8152. $sql.=" group by eg.exam_group_id order by e.create_time desc limit 30";
  8153. $list=array();
  8154. $exam = $this->sConn->createCommand($sql)->queryAll();
  8155. if($exam){
  8156. foreach ($exam as $value){
  8157. $tplData=json_decode($value['tpl_data'],true);
  8158. $list[]=array(
  8159. 'name'=>$value['name'],
  8160. 'create_time'=>date('Y-m-d',$value['create_time']),
  8161. 'exam_date'=>$tplData['examDate'],
  8162. 'exam_group_id'=>$value['exam_group_id']
  8163. );
  8164. }
  8165. }
  8166. $result['status']=1;
  8167. $result['data']=$list;
  8168. exit(json_encode($result));
  8169. }
  8170. //复用考试,试题结构
  8171. public function actionCopyPaperTopic(){
  8172. $nowExamId = Req::post('examGroupId'); //当前考试
  8173. $copyExamId = Req::post('copyExamGroupId'); //复制结构的考试
  8174. $result['status']=0;
  8175. //读取当前考试试题结构
  8176. $nowPaperTopicRelation = array();
  8177. $examIds = array();
  8178. $paperIds = array();
  8179. $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$nowExamId}")->queryRow();
  8180. if (!$examGroup) {
  8181. $result['msg'] = "考试id不正确";
  8182. exit(json_encode($result));
  8183. }
  8184. if($examGroup['upload_status']>0){
  8185. $result['msg']="已上传成绩,不能复用";
  8186. exit(json_encode($result));
  8187. }
  8188. $exam = $this->sConn->createCommand("select exam_id,upload_status,tpl_data from exam where exam_group_id={$nowExamId}")->queryAll();
  8189. foreach ($exam as $value) {
  8190. $examIds[] = $value['exam_id'];
  8191. $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$value['exam_id']}")->queryRow();
  8192. $paperIds[] = $paper['paper_id'];
  8193. }
  8194. $tplData=json_decode($exam[0]['tpl_data'],true);
  8195. $nowPaperTopicRelation = $this->sConn->createCommand("select `order`,`type`,`topic_id`,`stem_id` from paper_topic_relation where paper_id={$paperIds[0]}")->queryAll();
  8196. if (!$nowPaperTopicRelation) {
  8197. $result['msg'] = "未创建答题卡";
  8198. exit(json_encode($result));
  8199. }
  8200. $checkArr = array();
  8201. $historyTopic = array();
  8202. foreach ($nowPaperTopicRelation as $val) {
  8203. $checkArr[$val['order']] = $val['type'];
  8204. $checkOrderTopic[$val['order']] = $val['topic_id'];
  8205. $historyTopic[$val['order']] = array(
  8206. 'topic_id' => $val['topic_id'],
  8207. 'type' => $val['type'],
  8208. 'stem_id'=> $val['stem_id']
  8209. );
  8210. }
  8211. //读取复制的考试结构
  8212. $copyPaperTopicRelation = array();
  8213. $exam = $this->sConn->createCommand("select exam_id,tpl_data from exam where exam_group_id={$copyExamId}")->queryRow();
  8214. $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$exam['exam_id']}")->queryRow();
  8215. $topicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$copyExamId}")->queryRow();
  8216. $copyPaperTopicRelation = $this->sConn->createCommand("select `order`,`type`,`topic_id`,`method_ids`,`method_difficulty`,`stem_id` from paper_topic_relation where paper_id={$paper['paper_id']}")->queryAll();
  8217. $checkArrCopy = array();
  8218. $copyTopicOrder = array();
  8219. foreach ($copyPaperTopicRelation as $val) {
  8220. $checkArrCopy[$val['order']] = $val['type'];
  8221. $copyTopicOrder[$val['order']] = array(
  8222. 'topic_id' => $val['topic_id'],
  8223. 'method_ids' => $val['method_ids'],
  8224. 'method_difficulty' => $val['method_difficulty'],
  8225. 'type'=>$val['type'],
  8226. 'stem_id'=>$val['stem_id']
  8227. );
  8228. }
  8229. if(strcmp(json_encode($checkArr),json_encode($checkArrCopy))!==0){
  8230. $result['msg']="两场考试试题结构不相同,不能复用";
  8231. exit(json_encode($result));
  8232. }
  8233. if(isset($tplData['new_items'])){
  8234. foreach($tplData['new_items'] as $key => $item){
  8235. if(isset($copyTopicOrder[$item['id']])){
  8236. $tplData['new_items'][$key]['topicId']=$copyTopicOrder[$item['id']]['topic_id'];
  8237. $tplData['new_items'][$key]['stemId']=$copyTopicOrder[$item['id']]['stem_id'];
  8238. }
  8239. }
  8240. }
  8241. //开始复用
  8242. $updateArr = array();
  8243. $updateMarkingTopicArr=array();
  8244. foreach ($checkOrderTopic as $key => $val) {
  8245. $sql = "update paper_topic_relation set topic_id='" . $copyTopicOrder[$key]['topic_id'] . "',stem_id='".$copyTopicOrder[$key]['stem_id']."',method_ids='" . $copyTopicOrder[$key]['method_ids'] . "',method_difficulty='" . $copyTopicOrder[$key]['method_difficulty'] . "' ";
  8246. $sql .= " where paper_id in(" . implode(',', $paperIds) . ") and topic_id={$val}";
  8247. $updateArr[] = $sql;
  8248. if($examGroup['mark_type']==4 && !in_array($copyTopicOrder[$key]['type'],array(1,2,11))){
  8249. $markingTopicSql="update marking_topic set topic_id='".$copyTopicOrder[$key]['topic_id']."' where exam_group_id='{$nowExamId}' and topic_id='{$val}'";
  8250. $updateMarkingTopicArr[]=$markingTopicSql;
  8251. }
  8252. }
  8253. $transaction = $this->sConn->beginTransaction();
  8254. try{
  8255. foreach ($updateArr as $sql){
  8256. $this->sConn->createCommand($sql)->execute();
  8257. }
  8258. if($updateMarkingTopicArr){
  8259. foreach ($updateMarkingTopicArr as $sql){
  8260. $this->sConn->createCommand($sql)->execute();
  8261. }
  8262. }
  8263. if($examGroup['mark_type']!=4){
  8264. $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$nowExamId}'")->execute();
  8265. }
  8266. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$nowExamId}'")->execute();
  8267. $nowTopicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$nowExamId}")->queryRow();
  8268. $this->sConn->createCommand("update exam_group set is_answersheet=1 where exam_group_id='" . $nowExamId . "'")->execute();
  8269. if ($nowTopicWord) {
  8270. $this->sConn->createCommand("update topic_word set status=2,is_history_topic='" . jsonEncode($historyTopic) . "',word_name='" . $topicWord['word_name'] . "',word_path='" . $topicWord['word_path'] . "',word_size='" . $topicWord['word_size'] . "' where exam_group_id='" . $nowExamId . "'")->execute();
  8271. } else {
  8272. $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
  8273. $wordId = current(current($uuid));
  8274. $topic_word_odj = new STopicWord();
  8275. $topic_word_odj->word_id = $wordId;
  8276. $topic_word_odj->exam_group_id = $nowExamId;
  8277. $topic_word_odj->word_name = $topicWord['word_name'];
  8278. $topic_word_odj->word_path = $topicWord['word_path'];
  8279. $topic_word_odj->word_md5 = '';
  8280. $topic_word_odj->word_size = $topicWord['word_size'];
  8281. $topic_word_odj->subject_id = $topicWord['subject_id'];
  8282. $topic_word_odj->status = 2;
  8283. $topic_word_odj->uploader_id = $this->coachId;
  8284. $topic_word_odj->upload_time = time();
  8285. $topic_word_odj->is_history_topic = jsonEncode($historyTopic);
  8286. $topic_word_odj->save();
  8287. }
  8288. $transaction->commit();
  8289. if(Yii::app()->params['handle_log_on_off'])
  8290. {
  8291. writeFileLog(jsonEncode(array(
  8292. "examGroupId" => $nowExamId,
  8293. "operate_project" => 'zsyas2',
  8294. "school_id" => $this->schoolId,
  8295. "title" => '复用考试',
  8296. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  8297. "operate_method" => $this->action,
  8298. "operate_url" => $this->getRoute(),
  8299. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  8300. "date"=>date('Y-m-d H:i:s')
  8301. )));
  8302. }
  8303. $result['status'] = 1;
  8304. } catch (Exception $e) {
  8305. $transaction->rollBack();
  8306. $result['msg']="复用失败";
  8307. }
  8308. exit(json_encode($result));
  8309. }
  8310. //生成二维码
  8311. public function actionCreateQrcode(){
  8312. $examGroupId = Req::post("examGroupId"); //记录ID
  8313. $result['status']=0;
  8314. if(!$examGroupId){
  8315. $result['msg']='考试Id不能为空';
  8316. exit(json_encode($result));
  8317. }
  8318. $QRcode = new \QRcode();
  8319. $level = 'L';// 纠错级别:L、M、Q、H
  8320. $size = 100;//元素尺寸
  8321. $margin = 1;//边距
  8322. $path='upload/tmpDir/qrCode/';
  8323. if (!file_exists($path)) {
  8324. mkdir($path, 0777, true);
  8325. }
  8326. $outfile=$path.$examGroupId.'.png';
  8327. $saveandprint = false;// true直接输出屏幕 false 保存到文件中
  8328. $back_color = 0xFFFFFF;//白色底色
  8329. $fore_color = 0x000000;//黑色二维码色 若传参数要hexdec处理,如 $fore_color = str_replace('#','0x',$fore_color); $fore_color = hexdec('0xCCCCCC');
  8330. $QRcode->png($examGroupId, $outfile, $level, $size, $margin, false, $back_color, $fore_color);
  8331. if(file_exists($outfile)){
  8332. $ucloud = new Qcloud();
  8333. $uploadUrl='zsyas2/third/qrcode/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $examGroupId. '.png';
  8334. $uploadInfo = $ucloud->putFile($uploadUrl, $outfile);
  8335. if ($uploadInfo['status'] == 0) {
  8336. @unlink($outfile);
  8337. $result['status']=0;
  8338. $result['msg'] = '文件上传失败!';
  8339. }else{
  8340. @unlink($outfile);
  8341. $result['data'] = $uploadInfo['url'];
  8342. $result['status']=1;
  8343. }
  8344. }else{
  8345. $result['status']=0;
  8346. $result['msg'] = '文件生成失败!';
  8347. }
  8348. exit(json_encode($result));
  8349. }
  8350. //切换答题卡,清空模板数据
  8351. public function actionClearAnswerCard()
  8352. {
  8353. $examGroupId = Req::post("examGroupId"); //考试ID
  8354. $type = Req::post("type"); //答题卡类型
  8355. /*
  8356. * 是否制作模板及类型
  8357. * 判断是否上传答题卡
  8358. * 是否解析
  8359. * 是否标注
  8360. *
  8361. * 清空 paper_topic_relation
  8362. * tpl_data new_items items
  8363. * topic topic_item_option
  8364. * marking_topic
  8365. * //删除数据
  8366. *
  8367. */
  8368. $examGroup = SExamGroup::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
  8369. if (!$examGroup) {
  8370. $result['status'] = 0;
  8371. $result['msg'] = '考试ID不存在';
  8372. exit(json_encode($result));
  8373. }
  8374. if ($examGroup['is_answersheet'] == 1) {
  8375. $result['status'] = 0;
  8376. $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板';
  8377. exit(json_encode($result));
  8378. }
  8379. if ($examGroup['is_tagging'] == 1) {
  8380. $result['status'] = 0;
  8381. $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板';
  8382. exit(json_encode($result));
  8383. }
  8384. $thirdMultiTemplate = $this->sConn->createCommand("select template_id from third_multi_template where exam_group_id='{$examGroupId}' and (topic_upload=1 or answer_upload=1)")->queryRow();
  8385. if ($thirdMultiTemplate) {
  8386. $result['status'] = 0;
  8387. $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板';
  8388. exit(json_encode($result));
  8389. }
  8390. $exam = Exam::model()->findAll('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
  8391. $tplData = json_decode($exam[0]['tpl_data'], true);
  8392. $thirdAnswerSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
  8393. if (!$thirdAnswerSheet) {
  8394. $result['status'] = 0;
  8395. $result['msg'] = '未制作答题卡';
  8396. exit(json_encode($result));
  8397. }
  8398. $examIds = array();
  8399. $paperIds = array();
  8400. $topicIds = array();
  8401. foreach ($exam as $item) {
  8402. $examIds[] = $item['exam_id'];
  8403. }
  8404. $criteria = new CDbCriteria();
  8405. $criteria->addInCondition('exam_id', $examIds);
  8406. $paper = SPaper::model()->findAll($criteria);
  8407. foreach ($paper as $item) {
  8408. if ($item['is_labelled'] > 0) {
  8409. $result['status'] = 0;
  8410. $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板';
  8411. exit(json_encode($result));
  8412. }
  8413. $paperIds[] = $item['paper_id'];
  8414. }
  8415. $paperTopic = SPaperTopicRelation::model()->findAll('paper_id=:pid', array(':pid' => $paperIds[0]));
  8416. foreach ($paperTopic as $item) {
  8417. $topicIds[] = $item['topic_id'];
  8418. }
  8419. //查询是否有上传数据
  8420. $rs = $this->sConn->createCommand("select id from student_paper_topic_rs where paper_id in(" . implode(',', $paperIds) . ") limit 1")->queryRow();
  8421. if ($rs) {
  8422. $result['status'] = 0;
  8423. $result['msg'] = '本场考试已上传学生答题卡,不支持再切换答题卡模板';
  8424. exit(json_encode($result));
  8425. }
  8426. $transaction = $this->sConn->beginTransaction();
  8427. try {
  8428. if($topicIds){
  8429. $this->sConn->createCommand("delete from topic where topic_id in (" . implode(',', $topicIds) . ")")->execute();
  8430. $this->sConn->createCommand("delete from topic_item where topic_id in (" . implode(',', $topicIds) . ")")->execute();
  8431. $this->sConn->createCommand("delete from topic_item_option where topic_id in (" . implode(',', $topicIds) . ")")->execute();
  8432. }
  8433. $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")")->execute();
  8434. $this->sConn->createCommand("delete from marking_topic where exam_group_id =" . $examGroupId)->execute();;
  8435. $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =" . $examGroupId)->execute();;
  8436. $this->sConn->createCommand("delete from topic_word where exam_group_id =" . $examGroupId)->execute();
  8437. $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =" . $examGroupId)->execute();
  8438. $this->sConn->createCommand("delete from exam_push_topics_setting where exam_group_id =" . $examGroupId)->execute();
  8439. unset($tplData['items']);
  8440. unset($tplData['new_items']);
  8441. unset($tplData['new_rules']);
  8442. unset($tplData['update_answer']);
  8443. if (isset($tplData['totals'])) $tplData['totals'] = 0;
  8444. if (isset($tplData['scores'])) $tplData['scores'] = 0;
  8445. if (isset($tplData['total_score'])) $tplData['total_score'] = 0;
  8446. $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id='" . $examGroupId . "'")->execute();
  8447. $transaction->commit();
  8448. if (Yii::app()->params['handle_log_on_off']) {
  8449. writeFileLog(jsonEncode(array(
  8450. "examGroupId" => $examGroupId,
  8451. "operate_project" => 'zsyas2',
  8452. "school_id" => $this->schoolId,
  8453. "title" => '清空答题卡',
  8454. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  8455. "operate_method" => $this->action,
  8456. "operate_url" => $this->getRoute(),
  8457. "operate_param" => json_encode(array('post' => $_POST, 'get' => $_GET)),
  8458. "date" => date('Y-m-d H:i:s')
  8459. )));
  8460. }
  8461. $result['status'] = 1;
  8462. } catch (\Exception $e) {
  8463. $transaction->rollBack();
  8464. $result['status'] = 0;
  8465. $result['msg'] = '清空答题卡数据失败';
  8466. }
  8467. exit(json_encode($result));
  8468. }
  8469. // 上传试卷模板
  8470. public function actionNewUploadTpl(){
  8471. $exam_group_id = Req::post('eid');
  8472. $upload_type = Req::post('uploadType'); //上传类型
  8473. $allowFileNameArr=array('word_file','paper_file','parse_file');
  8474. $error['success'] = 0;
  8475. if (empty($exam_group_id)) {
  8476. $error['message'] = '考试id不存在!';
  8477. echo json_encode($error);exit();
  8478. }
  8479. $examInfo = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  8480. if (empty($examInfo)) {
  8481. $error['message'] = '未找到试卷信息!';
  8482. echo json_encode($error);exit();
  8483. }
  8484. $examIds=array();
  8485. foreach ($examInfo as $value){
  8486. $examIds[]=$value->exam_id;
  8487. }
  8488. $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  8489. if (empty($thirdSheet)) {
  8490. $error['message'] = '尚未上传答题卡!';
  8491. echo json_encode($error);exit();
  8492. }
  8493. $topicWord=STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  8494. if($topicWord){
  8495. if($topicWord->allsubject_file_path && $topicWord->status!=3 && $topicWord->status!=7){
  8496. $error['message'] = '试卷已经上传,请勿重复上传!';
  8497. echo json_encode($error);exit();
  8498. }
  8499. if(($upload_type==1 && $topicWord->word_path) || ($upload_type==2 && $topicWord->allsubject_file_path)){
  8500. $error['message'] = '已经上传试卷,不能切换解析模式!';
  8501. echo json_encode($error);exit();
  8502. }
  8503. }
  8504. $fileUrlArr=array();
  8505. $file_max_size = 11 * 1024 * 1024;
  8506. foreach ($_FILES as $key =>$val){
  8507. if(in_array($key,$allowFileNameArr)){
  8508. if(!is_uploaded_file($_FILES[$key]['tmp_name'])){
  8509. if($key=='paper_file' && $upload_type==1){
  8510. $error['message'] = '非法上传!';
  8511. echo json_encode($error);exit();
  8512. }else{
  8513. continue;
  8514. }
  8515. }
  8516. if ($_FILES[$key]["size"] > $file_max_size) {
  8517. $error['message'] = '文件超过最大限制,最大为10M';
  8518. echo json_encode($error);exit();
  8519. }
  8520. if ($_FILES[$key]['error'] > 0) {
  8521. switch ($_FILES[$key]['error']) {
  8522. case 1:
  8523. $error['message'] = '文件大小超出了服务器的空间大小!';
  8524. break;
  8525. case 2:
  8526. $error['message'] = '要上传的文件大小超出浏览器限制!';
  8527. break;
  8528. case 3:
  8529. $error['message'] = '文件只有部分被上传!';
  8530. break;
  8531. case 4:
  8532. $error['message'] = '没有找到要上传的文件!';
  8533. break;
  8534. case 5:
  8535. $error['message'] = '服务器临时文件夹丢失!';
  8536. break;
  8537. case 6:
  8538. $error['message'] = '文件写入到临时文件夹出错!';
  8539. break;
  8540. }
  8541. echo json_encode($error);exit();
  8542. }
  8543. // 保存上传文件至服务器
  8544. $extName = substr($_FILES[$key]['name'],strrpos($_FILES[$key]['name'],'.'));
  8545. $fileName = $exam_group_id.$extName;
  8546. $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName;
  8547. $ucloud = new Qcloud();
  8548. $uploadInfo = $ucloud->putFile($wordRename, $_FILES[$key]['tmp_name']);
  8549. if ($uploadInfo['status'] == 0) {
  8550. echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg']));
  8551. exit();
  8552. }
  8553. if(strpos($key,'paper_file')!==false){
  8554. $fileUrlArr[]=array(
  8555. 'file_type'=>1,
  8556. 'file_url'=>str_replace("%2F","/",$uploadInfo['url']),
  8557. 'file_name'=>$_FILES[$key]['name']
  8558. );
  8559. }elseif(strpos($key,'parse_file')!==false){
  8560. $fileUrlArr[]=array(
  8561. 'file_type'=>2,
  8562. 'file_url'=>str_replace("%2F","/",$uploadInfo['url']),
  8563. 'file_name'=>$_FILES[$key]['name']
  8564. );
  8565. }else{
  8566. $fileUrlArr[] = str_replace("%2F","/",$uploadInfo['url']);
  8567. }
  8568. }
  8569. }
  8570. if(!$fileUrlArr){
  8571. $error['message'] = '未找到上传文件!';
  8572. echo json_encode($error);exit();
  8573. }
  8574. //操作日志
  8575. if(Yii::app()->params['handle_log_on_off'])
  8576. {
  8577. Curl::post(Yii::app()->params['handle_log_api'], array(
  8578. "exam_group_id" => (string)$exam_group_id,
  8579. "operate_project" => 'zsyas2',
  8580. "title" => '第三方试卷上传试卷',
  8581. "school_id" => $this->schoolId,
  8582. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  8583. "operate_method" => $this->action,
  8584. "operate_url" => $this->getRoute(),
  8585. "operate_sql" => json_encode(array('insert'=>array('exam_group_id'=>$exam_group_id,'status'=>0,'word_path'=>$uploadInfo['url'],'subject_id'=>$examInfo[0]->subject_id))),
  8586. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])),
  8587. ));
  8588. }
  8589. $transcation = $this->sConn->beginTransaction();
  8590. try {
  8591. $time = time();
  8592. $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute();
  8593. STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  8594. //$this->sConn->createCommand("update paper set is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute();
  8595. $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
  8596. $wordId = current(current($uuid));
  8597. $topic_word_odj = new STopicWord();
  8598. $topic_word_odj->word_id = $wordId;
  8599. $topic_word_odj->exam_group_id = $exam_group_id;
  8600. $topic_word_odj->word_name = '第三方试卷'.$fileName;
  8601. if($upload_type==1){
  8602. $topic_word_odj->allsubject_file_path = json_encode($fileUrlArr);
  8603. }elseif($upload_type==2){
  8604. $topic_word_odj->word_path = implode(',',$fileUrlArr);
  8605. }
  8606. $topic_word_odj->word_md5 = '';
  8607. $topic_word_odj->word_size = 0;
  8608. $topic_word_odj->subject_id = $examInfo[0]->subject_id;
  8609. $topic_word_odj->status = 0;
  8610. $topic_word_odj->type_id = 3;
  8611. $topic_word_odj->uploader_id = $this->coachId;
  8612. $topic_word_odj->upload_time = $time;
  8613. $topic_word_odj->save();
  8614. $transcation->commit();
  8615. }
  8616. catch (Exception $e)
  8617. {
  8618. $transcation->rollback();
  8619. $error['message'] = '上传文件失败!';
  8620. echo json_encode($error);exit();
  8621. }
  8622. $this->schoolManager->saveExamProcess($exam_group_id,3,time());
  8623. $error['success'] = 1;
  8624. $error['message'] = '上传文件成功!';
  8625. echo json_encode($error);exit();
  8626. }
  8627. public function actionViewPaper(){
  8628. $pid = Req::get('pid');
  8629. if(!$pid) Yii::app()->jump->error('解析尚未完成,或未生成预览');
  8630. $data=array('pid'=>$pid);
  8631. $this->renderPartial('view_paper',$data);
  8632. }
  8633. //创建考试加载班级
  8634. public function actionAjaxGetClassByTeacherGrade(){
  8635. $grade = Req::post('grade');
  8636. $teacherId = Req::post('teacherId');
  8637. $selectClassData = Req::post('selectClassData');
  8638. if(!$selectClassData) $selectClassData=array();
  8639. $result['status']=0;
  8640. if (Yii::app()->request->getIsPostRequest()){
  8641. $selectedClass=array();
  8642. if($selectClassData){
  8643. foreach ($selectClassData as $datum){
  8644. $selectedClass[(string)$datum]=$datum;
  8645. }
  8646. }
  8647. //读取走班设置
  8648. $setting=$this->schoolManager->getClassifiedBySubject($grade,$this->subjectId,$this->semesterId);
  8649. //读取执教班级
  8650. $teacherClassSelectData=array();
  8651. $getTeacherClass = ClassModel ::model()->getSelectclassesByTeacherGrade($this->semesterId,$teacherId,$grade);
  8652. foreach ($getTeacherClass as $val){
  8653. $teacherClassSelectData[(string)$val['class_id']]=$val;
  8654. }
  8655. //查询年级所有班级
  8656. $allClassList=array();
  8657. if($setting['status']==1){
  8658. $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=2",array(':gid'=>$grade,':sid'=>$this->semesterId));
  8659. }else{
  8660. $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=1",array(':gid'=>$grade,':sid'=>$this->semesterId));
  8661. }
  8662. if($classes){
  8663. foreach ($classes as $class){
  8664. if($class['is_hide']==1){
  8665. continue;
  8666. }
  8667. $temp=array(
  8668. 'class_id'=>$class['class_id'],
  8669. 'class_name'=>$class['class_name'],
  8670. 'arts_science'=>$class['arts_science'],
  8671. 'selected'=>0
  8672. );
  8673. if($selectedClass){
  8674. if(isset($selectedClass[(string)$class['class_id']])){
  8675. $temp['selected']=1;
  8676. }
  8677. }else{
  8678. if(isset($teacherClassSelectData[(string)$class['class_id']])){
  8679. $temp['selected']=1;
  8680. }
  8681. }
  8682. $allClassList[]=$temp;
  8683. }
  8684. }
  8685. $result['status']=1;
  8686. $result['msg']='success';
  8687. $result['data']=$allClassList;
  8688. }
  8689. exit(json_encode($result));
  8690. }
  8691. //验证第三方选做题分组
  8692. public function actionCheckSelectTopicGroup()
  8693. {
  8694. $examGroupId = Req::post("exam_group_id");
  8695. if($examGroupId>0)
  8696. {
  8697. $examData = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  8698. $tplData=json_decode($examData['tpl_data'],true);
  8699. if(isset($tplData['new_items'])){
  8700. foreach($tplData['new_items'] as $item){
  8701. if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
  8702. echo json_encode(array('status'=>1));exit;
  8703. }
  8704. }
  8705. }
  8706. }
  8707. echo json_encode(array('status'=>0));exit;
  8708. }
  8709. //生成签名
  8710. public function actionCreateSign(){
  8711. $eid = Req::post('eid');
  8712. if(YII_ENV=='production'){
  8713. $appId='946004280126791680'; //线上
  8714. }else{
  8715. $appId='939792767984566272'; //测试
  8716. }
  8717. $time=time();
  8718. $params=array(
  8719. 'appId'=>$appId,
  8720. 'timestamp'=>$time
  8721. );
  8722. $params['certificate']=$eid.'_'.$this->schoolId;
  8723. $vSign=$this->getSignature($appId,$time,'654321',$params);
  8724. $result['status'] = 1;
  8725. $result['sign'] = $vSign;
  8726. $result['time'] = $time;
  8727. $result['certificate'] = $params['certificate'];
  8728. echo json_encode($result);exit();
  8729. }
  8730. private function getSignature($appId,$timestamp,$secret,$params)
  8731. {
  8732. $subfix='';
  8733. if ($params) {
  8734. ksort($params, SORT_STRING);
  8735. $subfix = http_build_query($params);
  8736. }
  8737. $signature = base64_encode(hash_hmac("sha1", $appId . $timestamp . $secret . $subfix, $secret));
  8738. return strtoupper(md5($signature));
  8739. }
  8740. }