123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173 |
- <?php
- /**
- * Created by 上海互教教育科技有限公司.
- * User: 刘红伟
- * QQ : 454303753
- * Date: 2017/6/16 0016
- * Time: 下午 15:29
- */
- class ThirdController extends Controller
- {
- public function actionIndex(){
- Url::clean();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $printType = Req::get("type");
- $grade = Req::get("grade");
- $labelled = Req::get("labelled");
- $display = Req::get("display");
- $is_print = Req::get("is_print");
- $exam_group_ids = array();
- $sheets = array();
- $exam_sheets = array();
- $sheet_rs = array();
- $marking_papers = array();
- $list_type =Req::get('list_type');
- //$getName = safe_replace(Yii::app()->request->getQuery('realname1'));
- //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
- // $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
- // $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
- /**
- * 需求变动
- * 重新开发
- *
- */
- if (empty($printType)) {
- $printType = '2';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "2":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $condition = array();
- if($is_print > -1)
- {
- $condition[] = "cep.is_print = '{$is_print}'";
- }else{
- $is_print = -1;
- }
- if($printName)
- $condition[] = "e.name like '%{$printName}%'";
- if (!Str::isBlank($labelled)) {
- $condition[] = " (p.is_labelled = '{$labelled}' or eg.is_tagging='{$labelled}')";
- }
- if ( empty($display)) {
- $condition[] = "e.is_display = 0";
- }else
- {
- $condition[] = "e.is_display = ".$display;
- }
- // $condition[] = "e.subject_id = '{$this->subjectId}'";
- $condition[] = "eg.is_third = 1";
- $condition[] = "eg.xb_homework = 0";
- if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "e.subject_id = ".Yii::app()->session['session_duoxueke_subject_id'];
- }
- if($list_type){
- $condition[] = "eg.import_score_type = 2"; //传了参数,只读线下导入考试
- }else{
- $condition[] = "eg.import_score_type <>2 "; //没传参数,读其它所有阅卷类型
- }
- $gradeCardLength=array();
- $gradeData=SGrade::model()->findAll();
- foreach ($gradeData as $datum){
- if($datum->card_status==1){
- $gradeCardLength[$datum->id]=$datum->card_length;
- }else{
- $gradeCardLength[$datum->id]=0;
- }
- }
- $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc'));
- $printList = array();
- if($resultList["rs"]){
- $ExamModel=new Exam();
- $StudentPaperRelation=new SStudentPaperRelation();
- foreach ($resultList['rs'] as $k=>$v) {
- $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
- $time = time();
- $classinfo=ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$v['class_id']));
- $v['grade']=$classinfo['grade'];
- //解析状态
- $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$v['exam_group_id']));
- $v['tw_status']=$topicWord['status'];
- $v['wrong_reason']=$topicWord['wrong_reason'];
- $v['word_path']=$topicWord['word_path'];
- $v['allsubject_file_path']=$topicWord['allsubject_file_path'];
- if($topicWord['allsubject_file_path']){
- //解析预计完成时间
- $v['estimate']=48*3600+$topicWord['upload_time'];
- }
- $v['params_id']=$topicWord['params_id'];
- $v['parse_upload_time']=$topicWord['upload_time'];
- $printList[$k] = $v;
- $tplData = json_decode($v["tpl_data"], true);
- //FIXME 添加班级参数
- $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0;
- $printList[$k]['show_print'] = 0;
- //准考证
- if(!$v['school_card_status']){
- $printList[$k]['school_card_length'] = $gradeCardLength[$v['grade']];
- }
- //考试时间
- if(isset($tplData['examDate']))
- {
- $examDate = strtotime($tplData["examDate"]);
- }
- if(isset($tplData['new_items']) && !isset($tplData['items']))
- {
- $printList[$k]['show_print'] = 1;
- }
- //标注期望完成时间
- if(isset($tplData['estimateTime']))
- {
- $printList[$k]['estimate_time'] = date('Y-m-d H:i:s',$tplData["estimateTime"]);
- }
- if(!isset($tplData["examDate"]))
- {
- $examDate = $v["create_time"];
- }
- $printList[$k]['examDate'] = $examDate;
- if(isset($tplData['totals'])){
- $printList[$k]['totals'] = $tplData['totals'];
- }
- if(isset($tplData['total_score'])){
- $printList[$k]['total_score'] = $tplData['total_score'];
- }
- if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){
- $printList[$k]['is_change_to_third'] = 1;
- }else{
- $printList[$k]['is_change_to_third'] = 0;
- } //统计班级,学生
- if($list_type){
- $exam=$ExamModel->getExamIds($v['exam_group_id']);
- if($exam){
- $studentCount=0;
- $uploadedCount=0;
- $studentList=$StudentPaperRelation->getStudentExamInfo($exam);
- $studentCount=count($studentList);
- $printList[$k]['class_count']=count($exam).'('.$studentCount.'人)';
- foreach ($studentList as $value){
- if($value['is_feedback']==1){
- $uploadedCount++;
- }
- }
- $printList[$k]['upload_count']=$uploadedCount.'/'.$studentCount;
- if($uploadedCount>0){
- $printList[$k]['upload_status']='已上传成绩';
- }else{
- $printList[$k]['upload_status']='未上传成绩';
- }
- }
- }else{
- //判断上传状态
- $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($v['exam_group_id']);
- $uploadStatus=0;
- if($uploadExamInfo){
- if(isset($uploadExamInfo[1])){
- $printList[$k]['uploadExamTemplateId']=$uploadExamInfo[1]['template_id'];
- if($uploadExamInfo[1]['topic_upload']==1){
- $uploadStatus+=1;
- }
- }
- if(isset($uploadExamInfo[2])){
- $printList[$k]['uploadAnswerTemplateId']=$uploadExamInfo[2]['template_id'];
- if($uploadExamInfo[2]['answer_upload']==1){
- $uploadStatus+=3;
- }
- }
- }
- //判断是否已上传成绩
- $printList[$k]['is_feedback']=0;
- $exam=$ExamModel->getExamIds($v['exam_group_id']);
- if($exam){
- if($StudentPaperRelation->getStudentFeedBack($exam)){
- $printList[$k]['is_feedback']=1;
- }
- }
- $printList[$k]['uploadExamStatus']=$uploadStatus;
- $printList[$k]['uploadExamInfo'] = $uploadExamInfo;
- }
- }
- }
- $sheet_ids = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_group_id',$exam_group_ids);
- $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
- if($exam_sheet_data)
- {
- foreach($exam_sheet_data as $v)
- {
- $exam_sheets[$v->exam_group_id] = $v->online_card;
- $sheet_ids[$v->sheet_id] = $v->sheet_id;
- $sheet_rs[$v->exam_group_id] = $v;
- if($v->online_card){
- $onlineMultiplex=$this->schoolManager->getOnlineCardMultiplex($v->multiplex_id);
- if($onlineMultiplex){
- $marking_papers[$v->exam_group_id] = $onlineMultiplex['marking_papers'];
- }
- }
- }
- }
- //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
- $subject_exam_data=Yii::app()->params['subjectId'];
- $teachers_data = Teacher::model()->findAll();
- $class_teacher_data = array();
- if($teachers_data)
- {
- foreach($teachers_data as $k=>$v)
- {
- $class_teacher_data[$v->teacher_id] = $v->teacher_name;
- }
- }
- //获取班级年级
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- $class_grade_arr=array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_grade_arr[$v->class_id] = $v->grade;
- }
- }
- unset($class_data);
- $data = array();
- //$data = $this->export($getName,$grade_id,$class_id);
- //判断全学科试用学校
- // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi');
- // $rs=json_decode($rs,true);
- // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- // $data['is_qxk']=1;
- // }else{
- // $data['is_qxk']=0;
- // }
- $data['is_qxk']=1;
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data["printType"] = $printType;
- $data["printName"] = $printName;
- $data["teachers"] = $class_teacher_data;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data["sheets"] = $sheets;
- $data["exam_sheets"] = $exam_sheets;
- $data["sheet_rs"] = $sheet_rs;
- $data["labelled"] = $labelled;
- $data["display"] = $display;
- $data["is_print"] = $is_print;
- $data["subject"] = $subject_exam_data;
- $data['list_type'] =$list_type;
- $data["class_grade"] = $class_grade_arr;
- $data['showAssist'] =0;
- $data['extendSubject'] =$this->extendSubject;
- $data["marking_papers"] = $marking_papers;
- //获取导出数据白名单
- $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);;
- //debug($printList);
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- unset($resultList);
- //获取产品设置版本
- $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
- if(!$productEdition || $productEdition['switch']==2){
- $data['productSwitch']=2;
- }else{
- $data['productSwitch']=3;
- }
- $data['schoolId'] =$this->schoolId;
- $data['version_number']=$this->version_number;
- if($list_type){
- $this->render('index_underline',$data);
- }else{
- if(Yii::app()->params['section']==0){
- $this->render('index_section',$data);
- }else{
- $this->render('index2',$data);
- }
- }
- }
- public function actionIndex1(){
- Url::clean();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $printType = Req::get("type");
- $grade = Req::get("grade");
- $labelled = Req::get("labelled");
- $display = Req::get("display");
- $is_print = Req::get("is_print");
- $exam_group_ids = array();
- $sheets = array();
- $exam_sheets = array();
- $sheet_rs = array();
- /**
- * 需求变动
- * 重新开发
- *
- */
- if (empty($printType)) {
- $printType = '2';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "2":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $condition = array();
- if($is_print > -1)
- {
- $condition[] = "cep.is_print = '{$is_print}'";
- }else{
- $is_print = -1;
- }
- if($printName)
- $condition[] = "e.name like '%{$printName}%'";
- if (!Str::isBlank($labelled)) {
- $condition[] = "p.is_labelled = '{$labelled}'";
- }
- if ( empty($display)) {
- $condition[] = "e.is_display = 0";
- }else
- {
- $condition[] = "e.is_display = ".$display;
- }
- // $condition[] = "e.subject_id = '{$this->subjectId}'";
- $condition[] = "eg.is_third = 1";
- $resultList = $this->schoolManager->getThirdPrintList($condition,array('e.create_time desc','e.exam_id desc'));
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
- $time = time();
- $printList[$k] = $v;
- $tplData = json_decode($v["tpl_data"], true);
- //FIXME 添加班级参数
- $printList[$k]['branch'] = isset($tplData['branch']) ? $tplData['branch'] : 0;
- //考试时间
- if(isset($tplData['examDate']))
- {
- $examDate = strtotime($tplData["examDate"]);
- }
- if(!isset($tplData["examDate"]))
- {
- $examDate = $v["create_time"];
- }
- $printList[$k]['examDate'] = $examDate;
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $printList[$k]['is_expired'] = true;
- }
- }
- }
- $sheet_ids = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_group_id',$exam_group_ids);
- $exam_sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
- if($exam_sheet_data)
- {
- foreach($exam_sheet_data as $v)
- {
- $exam_sheets[$v->exam_group_id] = $v->sheet_id;
- $sheet_ids[$v->sheet_id] = $v->sheet_id;
- $sheet_rs[$v->exam_group_id] = $v;
- }
- }
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- //获取班级年级
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_grade_arr[$v->class_id] = $v->grade;
- }
- }
- unset($class_data);
- $data = array();
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data["printType"] = $printType;
- $data["printName"] = $printName;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data["sheets"] = $sheets;
- $data["exam_sheets"] = $exam_sheets;
- $data["sheet_rs"] = $sheet_rs;
- $data["sheet_ids"] = $sheet_ids;
- $data["labelled"] = $labelled;
- $data["display"] = $display;
- $data["is_print"] = $is_print;
- $data["subject"] = $subject_exam_data;
- $data["class_grade"] = $class_grade_arr;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- unset($resultList);
- $this->render('index1',$data);
- }
- protected function export($getName,$grade_id,$class_id)
- {
- //$getStatus = safe_replace(Yii::app()->request->getQuery('status'));
- $grade_class_array = array();
- $con = array();
- // 打印任务处理
- $ExamModel = Exam::model();
- $ClassModel = ClassModel::model();
- $printList = array();
- $grade_class_data = ClassModel::model()->findAll('grade=:grade', array(':grade' => $grade_id));
- if ($grade_class_data) {
- foreach ($grade_class_data as $v) {
- $grade_class_array[$v->class_id] = $v->attributes;
- }
- }
- // 获取当前学期班级并组装
- $criteria = new CDbCriteria();
- $criteria->addCondition('semester_id=:semester_id');
- if ($grade_id) {
- $con = array('c.grade = ' . $grade_id);
- $criteria->addCondition('grade=:grade');
- $criteria->params[':grade'] = $grade_id;
- }
- if ($class_id) {
- $con = array_merge($con, array('c.class_id = ' . $class_id));
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $class_id;
- }
- if ($getName) {
- $con = array_merge($con, array("e.name like '%{$getName}%'"));
- }
- if (Yii::app()->session['session_duoxueke_subject_id'] == 6 || Yii::app()->session['session_duoxueke_subject_id'] == 3) {
- $con = array_merge($con, array('e.subject_id in (3,6)'));
- } else {
- $con = array_merge($con, array('e.subject_id = ' . Yii::app()->session['session_duoxueke_subject_id']));
- }
- if(in_array(Yii::app()->session['session_duoxueke_subject_id'],$this->mathSubjectId)){
- $con = array_merge($con, array('e.subject_id in ('.implode(',',$this->mathSubjectId).')'));
- }else{
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- }
- $criteria->params[':semester_id'] = Yii::app()->session['session_semester_id'];
- $class_array = ClassModel::model()->findAll($criteria);
- $ccArray = array();
- $ccName = array();
- foreach ($class_array as $cc => $ca) {
- array_push($ccArray, $ca->class_id);
- $ccName[$ca->class_id] = $ca->class_name;
- }
- $resultList = $this->schoolManager->getPrintListre(array_merge(array("cep.type = '0'", "e.status = 1"), $con),array('e.complete_time desc'));
- if ($resultList["rs"]) {
- foreach ($resultList['rs'] as $k => $v) {
- $printList[$k] = $v;
- $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
- $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称
- $printList[$k]['print_name'] = $pname;
- }
- }
- $data = array();
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $data['realname'] = $getName;
- $data['grade_id'] = $grade_id;
- $data['class_id'] = $class_id;
- $data['grade_class'] = $grade_class_array;
- $data['printList1'] = $printList;
- $data['pages1'] = $resultList['pager'];
- $data['page_total1'] = $resultList['pager']->rowsCount;
- $data["subject"] = $subject_exam_data;
- if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- } else {
- $data["use_zhixue"] = 0;
- }
- $data['past_sem_exist'] = 0;//默认不存在过去的学期
- $sql = 'select start_time from semester where status=1 limit 1';
- $res = $this->sConn->createCommand($sql)->queryRow();
- $start_time = $res['start_time'];
- if (!$start_time) {
- Yii::app()->jump->error('该学校无当前学期,请检查学期是否设置错误');
- }
- $sql = 'select count(*) as rownum from semester where status=0 and start_time < '.$start_time;
- $res = $this->sConn->createCommand($sql)->queryRow();
- $row_num = $res['rownum'];
- $row_num && $data['past_sem_exist']=1;
- unset($resultList);
- return $data;
- }
- public function actionOprateexam()
- {
- $exam_group_id = Req::post("exam_group_id");
- $flag = Req::post("flag");
- $error['success'] = 0;
- if (empty($exam_group_id)) {
- $error['message'] = '操作失败!';
- echo json_encode($error);exit();
- }
- $this->setIs_new($exam_group_id);
- if ($this->schoolManager->ThirdOprateExamDisplay($exam_group_id,$flag)) {
- $error['success'] = 1;
- $error['message'] = '操作成功!';
- } else {
- $error['message'] = '操作失败!';
- }
- echo json_encode($error);exit();
- }
- public function actionExam_list()
- {
- ini_set("memory_limit","300M");
- $exam_group_id = Req::get("exam_group_id");
- $branch = Req::get("branch");
- $grade = Req::get("grade");
- $exam_date = ''; //考试日期
- $exam_name = ''; //考试名称
- $exam_uploaded=0;
- if($exam_group_id>0)
- {
- if($exam_group_id <= 0)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_group_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- if($exam_group_data->upload_status>0){
- $exam_uploaded=1;
- }
- $classId = Req::get("classId");
- $condition = array();
- if($classId)
- $condition[] = "e.class_id = '{$classId}'";
- $condition[] = "eg.exam_group_id = '{$exam_group_id}'";
- $classes = $this->schoolManager->getSemesterClasses($this->semesterId);
- if(!$classes)
- {
- Yii::app()->jump->error('本学期尚未建班级!');
- }
- $_classes = array();
- foreach($classes as $v)
- {
- $_classes[$v['class_id']][$v['class_id']] = $v;
- }
- $resultList = $this->schoolManager->getExamList($condition,array('e.create_time desc','e.exam_id desc'));
- if($resultList && isset($resultList['rs'][0])){
- $tplData=json_decode($resultList['rs'][0]['tpl_data'],true);
- }else{
- Yii::app()->jump->error('未找到考试信息!');
- }
- if(!$exam_date) $exam_date=$tplData['examDate'];
- if(!$exam_name) $exam_name=$resultList['rs'][0]['exam_name'];
- $data['exam_id']=$resultList['rs'][0]['exam_id'];
- if(isset($tplData['is_change_to_third']) && $tplData['is_change_to_third']==1){
- $data['is_change_to_third'] = 1;
- }else{
- $data['is_change_to_third'] = 0;
- }
- //获取paper 表数据
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$resultList['rs'][0]['exam_id']));
- if(!$paper_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- //读取试题数据
- $isAllSelect=1; //全部客观题判断
- $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
- //选择题类型判断
- $allSubjectType=array();
- if($exam_group_data['qxk_paper_id']>0){
- $allSubjectType=array(1,2,3,4,12);
- }else{
- $allSubjectType=array(1,2,11);
- }
- if($paperTopic){
- $data['answer_card_saved'] = 1;
- foreach ($paperTopic as $item){
- if(!in_array($item->type,$allSubjectType)){
- $isAllSelect=0;
- break;
- }
- }
- }else{
- //未制作答题卡
- $data['answer_card_saved'] = 0;
- }
- //读取试题推送设置
- $topicPushSettingModel=new SExamPushTopicsSetting();
- $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id);
- $topicPushSettingRelation=array();
- if($topicPushSetting){
- foreach ($topicPushSetting as $item){
- if($item['topic_ids']){
- $topicSetting=json_decode($item['topic_ids'],true);
- if($topicSetting){
- $topicPushSettingRelation[(string)$item['exam_id']]=1;
- }
- }
-
- }
- }
- // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $this->setIs_new($exam_group_id);
- //查询还原记录
- $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($examRestore){
- $data['restore'] = 1;
- }else{
- $data['restore'] = 0;
- }
- //是否使用在线答题卡
- $studentAnswerOnline=$this->schoolManager->getAnswerSheetOnline($exam_group_id);
- if($studentAnswerOnline){
- $data['online_card']=$studentAnswerOnline['online_card'];
- $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
- }else{
- $data['online_card']=0;
- $data['is_qrcode_online']=0;
- }
- $has_marked = false;
- $studentAnswerCardOnline=new SStudentAnswerCardOnline();
- foreach ($resultList['rs'] as $key => $item){
- if($item['status'] == 1){
- $has_marked = true;
- }
- //查询生成数量
- if($data['online_card']==1 && $data['is_qrcode_online']==1){
- $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($item['exam_id']);
- if($studentCardOnline){
- $resultList['rs'][$key]['card_created']=$studentCardOnline['count'];
- }
- }
- }
- //是否能添加班级 FIXME add_class_0924
- //打印中
- $enable_add_class = false;
- if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] == 0){
- $enable_add_class = true;
- }else{
- //混合阅卷
- if($exam_group_data['mark_type'] == 3){
- $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true;
- }
- //单独阅卷
- if($exam_group_data['mark_type'] == 4){
- $enable_add_class = $has_marked ? false : true;
- }
- }
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- $data['printList'] = $resultList['rs'];
- $data["classes"] = $_classes;
- $data["classId"] = $classId;
- $data["exam_group_id"] = $exam_group_id;
- $data["exam_group_data"] = $exam_group_data;
- // $data["subject"] = $subject_exam_data;
- $data["branch"] = $branch;
- $data["grade"] = $grade;
- $data["enable_add_class"] = $enable_add_class;
- $data['is_all_select']=$isAllSelect;
- $data["exam_name"] = $exam_name;
- $data['version_number']=$this->version_number;
- $data['exam_date']=$exam_date;
- $data['exam_uploaded']=$exam_uploaded;
- $data['topic_push_setting']=$topicPushSettingRelation;
- $this->render('exam_list',$data);
- }
- }
- public function actionChange(){
- ini_set("memory_limit","300M");
- Url::clean();
- $sname = Req::get("sname");
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $tid = Req::get("tid");
- $isFeedback=0;
- switch($tid){
- case "0":
- $printType = 'wp';
- break;
- case "1":
- $printType = 'wb';
- break;
- case "2":
- $printType = 'isp';
- break;
- default:
- $printType = 'wp';
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与试卷对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id);
- if(trim($paperInfo->answer_card_src))
- $answerCardUploaded = true;
- else
- $answerCardUploaded = false;
- $tpl = 1;// 需要上传模板
- $tplTwo= 1;
- if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) {
- $paperType = 1;
- if (empty($paperInfo->tpl_doc_src)) {
- $tpl = 2;
- }
- $tplTwo= 2;
- }else{
- $paperType = 2;
- }
- if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl']))
- {
- $tpl = 1;
- $paperType = 1;
- $tplTwo= 2;
- }
- if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){
- $isCustomTpl = true;
- }
- else{
- $isCustomTpl = false;
- }
- // 获取阅卷类型
- $markType = 0;
- $groupInfo = $this->schoolManager->getExam($eid);
- if (!empty($groupInfo)) {
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
- if (!empty($findInfo)) {
- $markType = $findInfo->mark_type;
- if($findInfo->mark_type==0 && $findInfo->is_third==1){
- $isUnderLine = 1;
- }
- }
- }
- $result = array();
- $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));
- //if (empty($relateStudent)) {
- // Yii::app()->jump->error('未找该试卷关联的学生!');
- //} else {
- //$studentModel = StudentInfo::model();
- // 获取学生姓名
- $_student_id = array();
- foreach($relateStudent as $v)
- {
- $_student_id[$v->student_id] = $v->student_id;
- }
- //if(!$_student_id)
- //{
- // Yii::app()->jump->error('未找该试卷关联的学生!');
- //}
- $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId);
- if(!$b_student_arr ){
- $array_student = array();
- $b_student_arr = array();
- $criteria = new CDbCriteria();
- $criteria->select = 'student_id';
- $criteria->addCondition('school_id=:school_id');
- $criteria->addCondition('status=:status');
- $criteria->params[':school_id'] = $this->schoolId;
- $criteria->params[':status'] = 1;
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data){
- foreach ($b_student_data as $k=>$v){
- $array_student[$v->student_id] = $v->student_id;
- }
- }
- Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
- if($array_student){
- Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student);
- Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000);
- }
- unset($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $b_student_arr[$v->student_id] = $v->student_id;
- }
- }
- unset($b_student_data);
- unset($criteria);
- }
- $studentNames = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$_student_id);
- $studentArray = SStudentInfo::model()->findAll($criteria);
- if (!empty($studentArray)) {
- foreach ($studentArray as $student) {
- $studentNames[$student->student_id] = $student->realname;
- }
- }
- //查询是否上传答题图片
- $uploadAnswerImgStudent=array();
- $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,0);
- if($student_answer_img){
- foreach ($student_answer_img as $val){
- $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id'];
- }
- }
- foreach ($relateStudent as $key=>$val) {
- //查询学生身份证号
- $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id));
- if($studentInfo){
- $result[$key]['id_number'] = $studentInfo->id_number;
- }else{
- $result[$key]['id_number'] = '';
- }
- $result[$key]['student_card'] = $val['student_card'];
- $result[$key]['school_student_card'] = $val['school_student_card'];
- $result[$key]['upload_answer_img'] =0;
- if($val->is_feedback==1){
- $isFeedback=1;
- if(isset($uploadAnswerImgStudent[(string)$val->student_id])){
- $result[$key]['upload_answer_img'] =1;
- }
- }
- //查询在线答题卡是否生成
- $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();
- if($rs && $rs['answer_card_online_created']==1){
- $result[$key]['online_created'] = 1;
- }else{
- $result[$key]['online_created'] = 0;
- }
- if (empty($sname)) {
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['paperName'] = $examInfo->name;
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null;
- $result[$key]['is_feedback'] = $val->is_feedback;
- $result[$key]['student_img_paper'] = $val->student_img_paper;
- $result[$key]['is_complete'] = $val->is_complete;
- } else {
- if ($sname == $studentNames[$val->student_id]) {
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['paperName'] = $examInfo->name;
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['studentName'] = $studentNames[$val->student_id];
- $result[$key]['is_feedback'] = $val->is_feedback;
- $result[$key]['student_img_paper'] = $val->student_img_paper;
- $result[$key]['is_complete'] = $val->is_complete;
- }else{
- unset($result[$key]);
- }
- unset($relateStudent[$key]);
- }
-
- $printCheck = true;
- }
- //}
- $no_paper_student = array();
- $paper_student_array = array();
- $c_paper_student_array = array();
- $class_student_info_data = array();
- $_student_ids = array();
- $_student_id_names = array();
- $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation
- if($class_student_data)
- {
- foreach($class_student_data as $v)
- {
- $_student_ids[$v['student_id']] = $v['student_id'];
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$_student_ids);
- $studentArray = SStudentInfo::model()->findAll($criteria);
- if (!empty($studentArray)) {
- foreach ($studentArray as $student) {
- $_student_id_names[$student->student_id] = $student->realname;
- }
- }
- }
- ///$class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info
- $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生
- $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生
- if ($paper_student_data) {
- foreach ($paper_student_data as $v) {
- $paper_student_array[$v['student_id']] = $v['student_id'];
- }
- $class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
- }
- if ($c_paper_student_data) {
- foreach ($c_paper_student_data as $v) {
- $c_paper_student_array[$v['student_id']] = $v['student_id'];
- }
- //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
- }
- if ($class_student_info_data) {
- foreach ($class_student_info_data as $v) {
- $class_student_info_array[$v['student_id']] = $v['realname'];
- }
- }
- if ($class_student_data) {
- foreach($class_student_data as $v)
- {
- if(!isset($b_student_arr[$v['student_id']]))
- {
- if ($paper_student_array)
- {
- if(isset($paper_student_array[$v['student_id']])){
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
- );
- }
- }
- if($c_paper_student_array )
- {
- if(!isset($c_paper_student_array[$v['student_id']]) )
- {
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
- );
- }
- }else
- {
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
- );
- }
- }
- }
- }
- //判断在线答题卡使用情况
- $useAnswerCardOnlineQrcode=0;
- $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']);
- if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
- $useAnswerCardOnlineQrcode=1;
- }
- $this->setIs_new($examInfo->exam_group_id);
- $data = array();
- if(isset($isUnderLine)){
- $data['under_line']=$isUnderLine;
- }
- //判断在线答题卡使用情况
- $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($groupInfo['exam_group_id']);
- if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
- $data['use_answer_card_online_qrcode']=1;
- }else{
- $data['use_answer_card_online_qrcode']=0;
- }
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $data['version_number']=$version_number;
- $data['no_paper_student'] = $no_paper_student;
- $data['result'] = $result;
- $data["printType"] = $printType;
- $data["sname"] = $sname;
- $data['paper_id'] = $paperInfo->paper_id;
- $data['exam_id'] = $eid;
- $data['class_id'] = $cid;
- $data['type_id'] = $tid;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- // $data["subject"] = $subject_exam_data;
- $data['wp_type'] = $examInfo->tpl_index;
- $data['className'] = $classInfo->class_name;
- $data['paperName'] = $examInfo->name;
- $data['tpl'] = $tpl;
- $data['tplTwo'] = $tplTwo;
- $data['markType'] = $markType;
- $data['examInfo'] = $examInfo;
- $data['paperType'] = $paperType;
- $data['answerCardUploaded'] = $answerCardUploaded;
- $data['paperData'] = $paperData;
- $data['isCustomTpl'] = $isCustomTpl;
- $data['isFeedback'] = $isFeedback;
- $data['printCheck'] = $printCheck;
- $data['useAnswerCardOnlineQrcode'] = $useAnswerCardOnlineQrcode;
- $this->render('change',$data);
- }
- public function actionExam_answer()
- {
- $exam_group_id = Req::get("exam_group_id");
- $data = array();
- if($exam_group_id>0)
- {
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_data || !$exam_group_data)
- {
- Yii::app()->jump->error('非法试卷!');
- }
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_data->exam_id));
- if($paper_data)
- {
- $paper_topic_data = SPaperTopicRelation::model()->findAll(array(
- 'order' => '`order` asc',
- 'condition' => 'paper_id=:paper_id and type=:type',
- 'params'=>array(':paper_id'=>$paper_data->paper_id,':type'=>1)
- ));
- if($paper_topic_data)
- {
- $data['paper_topic'] = $paper_topic_data;
- }else
- {
- Yii::app()->jump->error('试卷无选择题!');
- }
- }else
- {
- Yii::app()->jump->error('非法试卷!');
- }
- $this->setIs_new($exam_group_id);
- if($exam_group_data->sheet_answer)
- {
- $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1);
- }else
- {
- $data['exam_answer_data'] = json_decode($exam_group_data->sheet_answer,1);
- }
- $data['exam_data'] = $exam_data;
- $data['use_zhixue'] = 0;
- $data['exam_group_id'] = $exam_group_id;
- $data['paper_data'] = $paper_data;
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $data["subject"] = $subject_exam_data;
- $this->render('exam_answer',$data);
- }else
- {
- Yii::app()->jump->error('非法试卷!');
- }
- }
- public function actionSave_answer()
- {
- $answer = Req::post("answer");
- $paper_id = Req::post("paper_id");
- $exam_group_id = Req::post("exam_group_id");
- $status = 0;
- $exam_answers = array();
- if($answer && $paper_id && $exam_group_id)
- {
- $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type=:type',array(':paper_id'=>$paper_id,':type'=>1));
- if($paper_topic_data)
- {
- if(count($answer)==count($paper_topic_data))
- {
- foreach($answer as $k=>$v)
- {
- if(empty($v))
- {
- $status = 1;
- }else
- {
- $exam_answers[$k+1] = $v;
- }
- }
- if($status==1)
- {
- Yii::app()->jump->error('答案尚未设置或未设置完!');
- }
- if($status==0)
- {
- 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))){
- Yii::app()->jump->success('设置成功!',Yii::app()->createUrl('third/index'));exit;
- };
- }
- }else
- {
- Yii::app()->jump->error('答案尚未设置或未设置完!');
- }
- }
- }
- Yii::app()->jump->error('答案尚未设置或未设置完!');
- }
- public function actionSet_new()
- {
- $exam_group_id = Req::post("exam_group_id");
- if($exam_group_id>0)
- {
- $this->setIs_new($exam_group_id);
- }
- }
- public function actionPaper()
- {
- $exam_group_id = Req::post("exam_group_id");
- if($exam_group_id)
- {
- $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$third_answer_data)
- {
- echo json_encode(array('status'=>-1));exit;
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data)
- {
- echo json_encode(array('status'=>1));exit;
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionVerify_exam_rs()
- {
- $exam_group_id = Req::post("exam_group_id");
- $exam_ids = array();
- if($exam_group_id>0)
- {
- $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_data)
- {
- // //验证是否发送任务
- // $task=ATask::model()->findByPk($exam_group_id);
- // if($task && in_array($task->answer_sheet_task,array(1,2))){
- // echo json_encode(array('status'=>4));exit;
- // }
- //验证是否有在线答题卡
- $thirdAnswerSheet=$this->sConn->createCommand("select online_card from third_answer_sheet where exam_group_id='".$exam_group_id."' and online_card=1 ")->queryRow();
- if($thirdAnswerSheet){
- echo json_encode(array('status'=>5));exit;
- }
- foreach($exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- // $criteria = new CDbCriteria();
- // $criteria->addInCondition('exam_id',$exam_ids);
- //
- // $criteria->addNotInCondition('is_labelled', array(0,4));
- // $_paper_data = SPaper::model()->findAll($criteria);
- // if($_paper_data)
- // {
- // echo json_encode(array('status'=>3));exit;
- // }
- }
- echo json_encode(array('status'=>0));exit;
- }else
- {
- echo json_encode(array('status'=>2));exit;
- }
- }
- public function setIs_new($exam_group_id)
- {
- if($exam_group_id)
- {
- Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }
- }
- public function actionSheet()
- {
- $data = array();
- $sname = '';
- $exam_id = Req::get("exam_id");
- $class_id = Req::get("class_id");
- $sname = Req::get("sname");
- $this->setIs_new($exam_id);
- $k = 0;
- $z = 0;
- $x = 0;
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data)
- {
- $data['exam']['exam_id'] = $exam_data->exam_id;
- $data['exam']['name'] = $exam_data->name;
- $tpl_data = json_decode($exam_data->tpl_data,1);
- if(isset($tpl_data['items']))
- {
- foreach($tpl_data['items'] as $key=>$val)
- {
- if(in_array($key,Yii::app()->params['topic_type']['ke']))
- {
- $k += $val['total'];
- }
- if(in_array($key,Yii::app()->params['topic_type']['zu']))
- {
- $z += $val['total'];
- }
- if(in_array($key,Yii::app()->params['topic_type']['xu']))
- {
- $x += $val['total'];
- }
- }
- }
- $data['exam']['name'] = $exam_data->name;
- $data['exam']['topic_type'] = $k.' 客观题,'.$z.' 主观题,'.$x.' 选做题';
- }
- $criteria = new CDbCriteria();
- $criteria->order = 'sheet_id desc';
- if($sname)
- {
- $criteria->addSearchCondition('name',$sname);
- }
- $count = SThirdAnswerSheet::model()->count($criteria);
- $pager = new CPagination($count);
- $pager->pageSize = 10;
- $pager->applyLimit($criteria);
- $classInfo = ClassModel::model()->findByPk($class_id);
- if($classInfo)
- {
- $data['className'] = $classInfo->class_name;
- $data['class_id'] = $classInfo->class_id;
- }else
- {
- $data['className'] = '';
- $data['class_id'] = $class_id;
- }
- $sheet_data = SThirdAnswerSheet::model()->findAll($criteria);
- $data['sheet'] = $sheet_data;
- $data['sname'] = $sname;
- $data['pages'] = $pager;
- $data['pageSize'] = $pager->pageSize;
- $data['rowsCount'] = $count;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $data["subject"] = $subject_exam_data;
- $this->render('sheet',$data);
- }
- public function actionBinding()
- {
- $exam_id = Req::post("exam_id");
- $sheet_id = Req::post("sheet_id");
- $exam_ids = array();
- if($sheet_id && $exam_id)
- {
- //验证
- $sheet_data = SThirdAnswerSheet::model()->find('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
- if(!$sheet_data)
- {
- echo json_encode(array('status'=>-1));exit;
- }
- $sheet_score = json_decode($sheet_data->sheet_score,1);
- if(!$sheet_score)
- {
- echo json_encode(array('status'=>-7));exit;
- }
- //验证试卷题量
- $topic_types = array();
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($paper_data)
- {
- $paper_topic_data = SPaperTopicRelation::model()->findAll(
- array('order'=>'type asc,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $key=> $v)
- {
- if(in_array($v->type,Yii::app()->params['topic_type']['ke'])){
- $topic_types['ke'][$v->topic_id] = $v->topic_id;
- if(isset($sheet_score[$key+1]) && !empty($sheet_score[$key+1]))
- {
- if($v->score != $sheet_score[$key+1])
- {
- echo json_encode(array('status'=>-6));exit;
- }
- }
- }
- if(in_array($v->type,Yii::app()->params['topic_type']['zu'])){
- $topic_types['zu'][$v->topic_id] = $v->topic_id;
- }
- if(in_array($v->type,Yii::app()->params['topic_type']['xu'])){
- $topic_types['xu'][$v->topic_id] = $v->topic_id;
- }
- }
- if(isset($topic_types['ke'])&&(count($topic_types['ke'])!=$sheet_data->ke_topic_num))
- {
- echo json_encode(array('status'=>-4));exit;
- }
- if(!isset($topic_types['ke']) && $sheet_data->ke_topic_num>0)
- {
- echo json_encode(array('status'=>-4));exit;
- }
- if(isset($topic_types['zu'])&&(count($topic_types['zu'])!=$sheet_data->zu_topic_num))
- {
- echo json_encode(array('status'=>-4));exit;
- }
- if(!isset($topic_types['zu']) && $sheet_data->zu_topic_num>0)
- {
- echo json_encode(array('status'=>-4));exit;
- }
- if(isset($topic_types['xu'])&&(count($topic_types['xu'])!=$sheet_data->xuan_topic_num))
- {
- echo json_encode(array('status'=>-4));exit;
- }
- if(!isset($topic_types['xu']) && $sheet_data->xuan_topic_num>0)
- {
- echo json_encode(array('status'=>-4));exit;
- }
- }else{
- echo json_encode(array('status'=>-8));exit;
- }
- }
- /**
- * 获取同一次考试
- */
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data)
- {
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $transaction = $this->sConn->beginTransaction();
- try{
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 1;
- SExamAnswerSheet::model()->deleteAll($criteria);
- unset($criteria);
- $sql='INSERT INTO `exam_third_answer_sheet_relation`
- (`sheet_id`,`exam_id`,`status`,`create_time`)VALUES';
- foreach($exam_ids as $e_id)
- {
- $sql.='('.$sheet_id.','.$e_id.',1,'.time().'),';
- }
- $sql = substr($sql,0,-1);
- $this->sConn->createCommand($sql)->execute();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- Exam::model()->updateAll(array('sheet_answer'=>$sheet_data->sheet_answer,'sheet_score'=>$sheet_data->sheet_score),$criteria);
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- echo json_encode(array('status'=>0));exit;
- }
- echo json_encode(array('status'=>1));exit;
- }
- }
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionDel()
- {
- $sheet_id = Req::post("sheet_id");
- if($sheet_id)
- {
- SThirdAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
- SExamAnswerSheet::model()->deleteAll('sheet_id=:sheet_id',array(':sheet_id'=>$sheet_id));
- }
- echo json_encode(array('status'=>1));
- }
- public function actionThirdview()
- {
- //判断教材设置
- if(!Yii::app()->params['school_textbook_setting'] ){
- Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!');
- }
- $schoolTextBookSet=Yii::app()->params['school_textbook_setting'];
- $data = array();
- $printType = Req::get("type");
- $criteria = new CDbCriteria();
- if(Yii::app()->session['session_duoxueke_subject_id']==3)
- {
- $criteria->addInCondition('subjects',$this->mathSubjectId);
- }else
- {
- $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
- }
- $criteria->addCondition('status = 0');
- $teacher_data = Teacher::model()->findAll($criteria);
- unset($criteria);
- $teacher_arr = array();
- if($teacher_data){
- $i = 0;
- foreach($teacher_data as $v){
- $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
- $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
- $i++;
- }
- }
- $data['teacher_arr'] = $teacher_arr;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- //判断全学科试用学校
- // $rs = http('/cms/api/qxk-math-trial-school/'.$this->schoolId,'GET',$this->schoolId,array(),'cgi');
- // $rs=json_decode($rs,true);
- // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- // $data['is_qxk']=1;
- // }else{
- // $data['is_qxk']=0;
- // }
- $data['is_qxk']=1;
- $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用',51=>'新高一高二');
- $textbookArr=array();
- foreach ($schoolTextBookSet as $val){
- //表里有2个版本的教材,此处过滤掉不属于当前版本的教材
- if($data['is_qxk']!=$val['is_qxk']){
- continue;
- }
- $textBookName='';
- if(isset($this->textBookType[$val['subject_id']][$val['textbook_id']])){
- $textBookName=$this->textBookType[$val['subject_id']][$val['textbook_id']];
- }
- $textbookArr[$val['grade']]=array(
- 'grade_id'=>$val['grade'],
- 'subject_id'=>$val['subject_id'],
- 'textbook_id'=>$val['textbook_id'],
- 'subject_name'=>$teacherSubjectNames[$val['subject_id']],
- 'text_book_name'=>$textBookName
- );
- }
- if(!isset($textbookArr[1]) || !isset($textbookArr[2])){
- Yii::app()->jump->error('请先在教材管理模块设置高一、高二的教材版本!');
- }
- $data['textbookArr'] = $textbookArr;
- $data['version_number']=$this->version_number;
- $this->render('thirdview',$data);
- }
- public function actionThirdview_duo()
- {
- $data = array();
- $printType = Req::get("type");
- if (empty($printType)) {
- $printType = '2';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "2":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $data['printType'] = $printType;
- // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
- // $semester_id = Yii::app()->session['session_semester_id'];
- $coach_id = $this->coachId;
- $semester_id = $this->semesterId;
- // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
- $criteria = new CDbCriteria();
- if(Yii::app()->session['session_duoxueke_subject_id']==3)
- {
- $criteria->addInCondition('subjects',$this->mathSubjectId);
- }else
- {
- if(Yii::app()->session['session_duoxueke_subject_id']==18){
- $criteria->addInCondition('subjects',array(12,13,14));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']==19){
- $criteria->addInCondition('subjects',array(15,16,17));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
- $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
- }
- }
- $criteria->addCondition('status = 0');
- $teacher_data = Teacher::model()->findAll($criteria);
- unset($criteria);
- $teacher_arr = array();
- if($teacher_data){
- $i = 0;
- foreach($teacher_data as $v){
- $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
- $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
- $i++;
- }
- }
- $data['teacher_arr'] = $teacher_arr;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- $teacherSubjectIds = array(3, 6);
- $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
- $teacherSubjectMaterialIds = array();
- $teacherSubjectMaterialNames = array();
- foreach ($teacherSubjectIds as $teacherSubjectId) {
- $teacherSubjectMaterialIds[$teacherSubjectId] = array();
- $teacherSubjectMaterialNames[$teacherSubjectId] = array();
- $textbookTree = $this->apiPost('/textbook/tree', array(
- 'subjectId' => $teacherSubjectId,
- 'depth' => 3
- ));
- if (! $textbookTree) {
- $error[] = 'Brain textbook/tree error';
- } elseif (isset($textbookTree->error)) {
- $error[] = $textbookTree->error;
- } else {
- foreach ($textbookTree as $textbook) {
- if (isset($textbook->modules)) {
- foreach ($textbook->modules as $module) {
- if (isset($module->chapters)) {
- $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
- $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
- }
- }
- }
- }
- }
- }
- //
- $criteria = new CDbCriteria();
- $criteria->addCondition('subject_id=:subject_id');
- $criteria->addCondition('school_card_length=0');
- $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
- $criteria->order = 'third_tpl_id desc';
- $criteria->limit = 5;
- $thisTpls = SThirdTplModel::model()->findAll($criteria);
- // debug($thisTpls);
- if($thisTpls)
- {
- $data['thisTpls'] = $thisTpls;
- }
- $data['teacherSubjectIds'] = $teacherSubjectIds;
- $data['teacherSubjectNames'] = $teacherSubjectNames;
- $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
- $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
- $data['version_number']=$this->version_number;
- //判断全学科试用学校
- // $rs = http('/teacher/paper/word-group/can-use-new/','POST',$this->schoolId,array(),'cgi',array('schoolId:'.$this->schoolId));
- //
- // $rs=json_decode($rs,true);
- // if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- // $data['is_qxk']=1;
- // }else{
- // $data['is_qxk']=0;
- // }
- $data['is_qxk']=1;
- // echo Yii::app()->params['zsy_api_url'].'<br>';
- // echo json_encode($rs).'<br>';
- // echo $data['is_qxk'];
- $this->render('thirdview1',$data);
- }
- public function actionThirdview_section()
- {
- $data = array();
- //读取全学科教材
- $postRs = $this->apiPost('/all_textbook/tree', array(
- 'subjectId' => Yii::app()->session['session_duoxueke_subject_id'],
- ));
- $textbookTree=array();
- if(isset($postRs->status) && $postRs->status==1 && $postRs->data ){
- foreach ($postRs->data as $val){
- if($val->level==1){
- $textbookTree[]=array(
- 'textbook_id'=>$val->textbook_id,
- 'textbook_name'=>$val->textbook_name,
- );
- }
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
- $criteria->addCondition('status = 0');
- $teacher_data = Teacher::model()->findAll($criteria);
- unset($criteria);
- $teacher_arr = array();
- if($teacher_data){
- $i = 0;
- foreach($teacher_data as $v){
- $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
- $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
- $i++;
- }
- }
- $data['teacher_arr'] = $teacher_arr;
- $data['textbookTree']=$textbookTree;
- $this->render('thirdview_section',$data);
- }
- public function actionThirdview_under_line()
- {
- $data = array();
- $printType = Req::get("type");
- if (empty($printType)) {
- $printType = '2';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "2":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $data['printType'] = $printType;
- // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
- // $semester_id = Yii::app()->session['session_semester_id'];
- $coach_id = $this->coachId;
- $semester_id = $this->semesterId;
- // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
- $criteria = new CDbCriteria();
- if(Yii::app()->session['session_duoxueke_subject_id']==3)
- {
- $criteria->addInCondition('subjects',$this->mathSubjectId);
- }else
- {
- if(Yii::app()->session['session_duoxueke_subject_id']==18){
- $criteria->addInCondition('subjects',array(12,13,14));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']==19){
- $criteria->addInCondition('subjects',array(15,16,17));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
- $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
- }
- }
- $criteria->addCondition('status = 0');
- $teacher_data = Teacher::model()->findAll($criteria);
- unset($criteria);
- $teacher_arr = array();
- if($teacher_data){
- $i = 0;
- foreach($teacher_data as $v){
- $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
- $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
- $i++;
- }
- }
- $data['teacher_arr'] = $teacher_arr;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- $teacherSubjectIds = array(3, 6);
- $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
- $teacherSubjectMaterialIds = array();
- $teacherSubjectMaterialNames = array();
- foreach ($teacherSubjectIds as $teacherSubjectId) {
- $teacherSubjectMaterialIds[$teacherSubjectId] = array();
- $teacherSubjectMaterialNames[$teacherSubjectId] = array();
- $textbookTree = $this->apiPost('/textbook/tree', array(
- 'subjectId' => $teacherSubjectId,
- 'depth' => 3
- ));
- if (! $textbookTree) {
- $error[] = 'Brain textbook/tree error';
- } elseif (isset($textbookTree->error)) {
- $error[] = $textbookTree->error;
- } else {
- foreach ($textbookTree as $textbook) {
- if (isset($textbook->modules)) {
- foreach ($textbook->modules as $module) {
- if (isset($module->chapters)) {
- $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
- $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
- }
- }
- }
- }
- }
- }
- //
- $criteria = new CDbCriteria();
- $criteria->addCondition('subject_id=:subject_id');
- $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
- $criteria->order = 'third_tpl_id desc';
- $criteria->limit = 5;
- $thisTpls = SThirdTplModel::model()->findAll($criteria);
- if($thisTpls)
- {
- $data['thisTpls'] = $thisTpls;
- }
- $data['teacherSubjectIds'] = $teacherSubjectIds;
- $data['teacherSubjectNames'] = $teacherSubjectNames;
- $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
- $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
- $this->render('thirdview_under_line',$data);
- }
- public function actionUpdateThirdTpl(){
- $error = array();
- $tplData = array();
- $tpl_title = Req::post("tpl_title");
- $third_tpl_id = Req::post("third_tpl_id");
- $classIds = Req::post("classIds");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $topic = $_POST["topic"];
- $layout = Req::post("layout");
- $select_card_type = Req::post("select_card_type");
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($tpl_title)){
- $error[] = '请设置答题卡名称';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($topic)){
- $error[] = '请设置题型';
- }
- if(empty($layout)){
- $error[] = '答题卡类型';
- }
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- $card_status = 0;
- $school_card_length = 8;
- if($this->schoolId>999){
- $school_card_length = 9;
- }
- $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).") ";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if(!$cardData){
- $error[] = '无法找到对应班级';
- }
- if($cardData['card_status']){
- $school_card_length = (int)$cardData['card_length'];
- $card_status = (int)$cardData['card_status'];
- }
- // $rs = $this->sConn->createCommand()->insert('third_tpl',array(
- // 'title' => $tpl_title,
- // 'subject_id' => $subjectId,
- // 'school_card_status' => $card_status,
- // 'school_card_length' => $school_card_length,
- // 'layout' => $layout,
- // 'select_card_type' => $select_card_type,
- // 'tpl_data' => $topic,
- // 'create_time' => time()
- // ));
- $rs = SThirdTplModel::model()->updateAll(array(
- 'title' => $tpl_title,
- 'subject_id' => $subjectId,
- 'school_card_status' => $card_status,
- 'school_card_length' => $school_card_length,
- 'layout' => $layout,
- 'select_card_type' => $select_card_type,
- 'tpl_data' => $topic
- ),'third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
- $_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)三栏');
- $_select_card_type = array(1=>'准考证号',2=>'条形码');
- if($rs !==false){
- 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;
- }
- }
- echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit;
- }
- public function actionDelThirdTpl(){
- $third_tpl_id = Req::post("third_tpl_id");
- if($third_tpl_id>0){
- $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
- if($thirdTpl){
- echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit;
- }
- }
- echo json_encode(array('status'=>0,'msg'=>'失败'));exit;
- }
- public function actionGetThirdTpl(){
- $third_tpl_id = Req::post("third_tpl_id");
- if($third_tpl_id>0){
- $thirdTpl = SThirdTplModel::model()->find('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id))->attributes;
- if($thirdTpl){
- echo json_encode(array('status'=>1,'msg'=>'1','result'=>$thirdTpl));exit;
- }
- }
- echo json_encode(array('status'=>0,'msg'=>'失败'));exit;
- }
- public function actionAjaxchangeclasses()
- {
- $subject_id=$this->subjectId;
- if(isset(Yii::app()->session['session_duoxueke_subject_id'])){
- $subject_id=Yii::app()->session['session_duoxueke_subject_id'];
- }
- //读取走班设置
- $classified=array();
- $setting=$this->schoolManager->getClassShift($this->semesterId,$subject_id);
- if($setting){
- foreach ($setting as $value){
- $classified[$value['grade']]=$value['status'];
- }
- }
- $result = array();
- $error = array();
- if (Yii::app()->request->getIsPostRequest()){
- $teacher_id = Req::post("teacher_id");
- $selectedClassId=Req::post('selectedClassId');
- if(empty($teacher_id)){
- $error[] = "请指定教师";
- }else{
- $semester_id = $this->semesterId;
- if($selectedClassId){
- $anotherSelectClass=ClassModel ::model()->getClassArrayByIds($selectedClassId);
- $i = 0;
- if($anotherSelectClass){
- foreach ($anotherSelectClass as $cas){
- $class_arr_select[$i]['class_id'] = $cas['class_id'];
- $class_arr_select[$i]['class_name'] = $cas['class_name'];
- $class_arr_select[$i]['grade'] = $cas['grade'];
- $i++;
- $class_arr_select_ids[] = $cas['class_id'];
- }
- }
- }else{
- $class_arr_select_data = ClassModel ::model()->getSelectclassesByTeacher($semester_id,$teacher_id);
- $class_arr_select =array();
- $class_arr_select_ids = array();
- $i = 0;
- if($class_arr_select_data){
- foreach($class_arr_select_data as $cas){
- if(isset($classified[$cas->grade]) && $classified[$cas->grade]==1){
- if($cas->class_type==2){
- //判断学科
- if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cas->class_id)){
- continue;
- }
- $class_arr_select[$i]['class_id'] = $cas->class_id;
- $class_arr_select[$i]['class_name'] = $cas->class_name;
- $class_arr_select[$i]['grade'] = $cas->grade;
- $i++;
- $class_arr_select_ids[] = $cas->class_id;
- }
- }else{
- if($cas->class_type==1){
- $class_arr_select[$i]['class_id'] = $cas->class_id;
- $class_arr_select[$i]['class_name'] = $cas->class_name;
- $class_arr_select[$i]['grade'] = $cas->grade;
- $i++;
- $class_arr_select_ids[] = $cas->class_id;
- }
- }
- }
- }
- }
- $class_arr_select_ids_str = "";
- if($class_arr_select_ids){
- foreach($class_arr_select_ids as $v){
- $class_arr_select_ids_str.=$v.",";
- }
- $class_arr_select_ids_str=substr($class_arr_select_ids_str,0,-1);
- }
- $class_arr_noselect_data = ClassModel ::model()->getNoSelectclassesByTeacher($semester_id,$teacher_id,$class_arr_select_ids_str);
- $class_arr_noselect =array();
- $j = 0;
- if($class_arr_noselect_data){
- foreach($class_arr_noselect_data as $cans){
- if(isset($classified[$cans->grade]) && $classified[$cans->grade]==1){
- if($cans->class_type==2){
- //判断学科
- if(!$this->schoolManager->checkClassifiedSubject($subject_id,$cans->class_id)){
- continue;
- }
- $class_arr_noselect[$j]['class_id'] = $cans->class_id;
- $class_arr_noselect[$j]['class_name'] = $cans->class_name;
- $class_arr_noselect[$j]['grade'] = $cans->grade;
- $j++;
- }
- }else{
- if($cans->class_type==1){
- $class_arr_noselect[$j]['class_id'] = $cans->class_id;
- $class_arr_noselect[$j]['class_name'] = $cans->class_name;
- $class_arr_noselect[$j]['grade'] = $cans->grade;
- $j++;
- }
- }
- }
- }
- $result['class_arr_select'] = $class_arr_select;
- $result['class_arr_noselect'] = $class_arr_noselect;
- }
- }else{
- $error[] = "错误的来源";
- }
- header('Content-Type: application/json');
- if($error){
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));exit;
- }else{
- echo json_encode($result);exit;
- }
- }
- public function UUID_SHORT($length = 20)
- {
- $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
- $result = $query['UUID_SHORT'];
- if ($length AND is_int($length))
- {
- $result = substr($result, ($length * -1));
- }
- return $result;
- }
- public function actionCreatethird(){
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $markType = Req::post("markType");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $examDate = Req::post("examDate");
- $tpl_index = (int)Req::post("tpl_index");
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- if(empty($tpl_index)){
- $error[] = '请指定类型';
- }
- if(empty($textbookId)){
- $error[] = '请指定教材';
- }
- if($error){
- Yii::app()->jump->error(implode(',',$error));
- }else{
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try{
- // $newExamGroupId = $this->UUID_SHORT();
- $newExamGroupId=getUniqueId($this->schoolId);
- if($markType ==4)
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
- }else
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
- }
- $this->sConn->createCommand($sql)->execute();
- foreach($classIds as $classId){
- //$newExamId = $this->UUID_SHORT();
- $newExamId = getUniqueId($this->schoolId);
- $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";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if($cardData['card_status']==0){
- $cardData['card_length'] = 8;
- if($this->schoolId >999){
- $cardData['card_length'] = 9;
- }
- }
- $class_type=$cardData['class_type'];
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($tplData),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- // $newPaperId = $this->UUID_SHORT();
- $newPaperId= getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => 0,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- 'class_type' =>$class_type
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time' =>$time
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if(!$error){
- $this->redirect($this->createUrl('third/index'));
- }
- }
- public function actionQuanCreatethird(){
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $markType = Req::post("markType");
- $paperType = (int)Req::post("paperType");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $examDate = Req::post("examDate");
- $qxkPaperId = (int)Req::post("isQxk");
- // $tpl_index = (int)Req::post("tpl_index");
- $tpl_index = $paperType;
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(!matchStrChar($examName)){
- $error[] = '考试名称不能包含特殊字符';
- }
-
- if(!in_array($paperType,array(0,1,2,1050))){
- $error[] = '请选择正确的试卷类型';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- // if(empty($tpl_index)){
- // $error[] = '请指定类型';
- // }
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try{
- //$newExamGroupId = $this->UUID_SHORT();
- $newExamGroupId=getUniqueId($this->schoolId);
- if($markType ==4){
- $markStatus=1;
- $status=1;
- }else{
- $markStatus=0;
- $status=0;
- }
- $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`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")";
- $this->sConn->createCommand($sql)->execute();
- foreach($classIds as $classId){
- //$newExamId = $this->UUID_SHORT();
- $newExamId=getUniqueId($this->schoolId);
- $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";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if($cardData['card_status']==0){
- $cardData['card_length'] = 8;
- if($this->schoolId >999){
- $cardData['card_length'] = 9;
- }
- }
- $class_type=$cardData['class_type'];
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($tplData),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- //$newPaperId = $this->UUID_SHORT();
- $newPaperId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => 0,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- 'class_type' =>$class_type
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time' =>$time
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
- }
- }
- if(!$error){
- echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
- }
- }
- public function actionAjaxCreatethird()
- {
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $markType = Req::post("markType");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $is_update = Req::post("is_update");
- $examDate = Req::post("examDate");
- $tpl_index = (int)Req::post("tpl_index");
- $topic = $_POST["topic"];
- $layout = Req::post("layout");
- $select_card_type = Req::post("select_card_type");
- $json = array();
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(!matchStrChar($examName)){
- $error[] = '考试名称不能包含特殊字符';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- if(!inArray($tpl_index,array(0,1,2,1050))){
- $error[] = '请指定类型';
- }
- if(empty($topic)){
- $error[] = '请设置题型';
- }
- if(empty($layout)){
- $error[] = '答题卡类型';
- }
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- //组装题型topic_items
- $_topic = json_decode($topic,1);
- $_topic_mould = array();
- $border = '';
- $required = 0;
- /**
- * * 格式:array(
- * 题型=>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)))
- */
- foreach ($_topic as $k=>$v)
- {
- if(!empty($v)) {
- if ($k == 0) {
- foreach ($v as $item) {
- $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
- }
- }
- if ($k == 1) {
- foreach ($v as $item) {
- $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
- }
- }
- if ($k == 2) {
- foreach ($v as $item) {
- $border = 'no';
- if ($item[2] >= 1) {
- $border = 'no';
- }
- if ($item[2] == 2) {
- $border = 'dashed';
- }
- if ($item[2] == 3) {
- $border = 'solid';
- }
- $smallTopics = array();
- if(isset($item[3]) && !empty($item[3])){
- $smallArr = explode(',', $item[3]);
- foreach($smallArr as $k=>$v){
- $smallNextArr = explode('///', $v);
- $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
- }
- }
- $style = 'line';
- $row = isset($item[0]) ? $item[0] : 1;
- $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
- }
- }
- if ($k == 3) {
- foreach ($v as $item) {
- $border = 'no';
- if ($item[2] >= 1) {
- $border = 'no';
- }
- if ($item[2] == 2) {
- $border = 'dashed';
- }
- if ($item[2] == 3) {
- $border = 'solid';
- }
- $styles = explode('///', $item[0]);
- $style = 'blank';
- $row = 0;
- if ($styles) {
- if ($styles[0] == 1) {
- $style = 'blank';
- }
- if ($styles[0] == 2) {
- $style = 'line';
- $row = isset($styles[1]) ? $styles[1] : 1;
- }
- if ($styles[0] == 3) {
- $style = 'table';
- }
- }
- $smallTopics = array();
- if(isset($item[3]) && !empty($item[3])){
- $smallArr = explode(',', $item[3]);
- foreach($smallArr as $k=>$v){
- $smallNextArr = explode('///', $v);
- $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
- }
- }
- $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
- }
- }
- if ($k == 4) {
- $style = 'blank';
- foreach ($v as $item) {
- if ($item[2] == 1) {
- $style = 'blank';
- }
- if ($item[2] == 2) {
- $style = 'line';
- }
- $topics = explode('///', $item[0]);
- if ($topics) {
- $required+= $topics[1]; //多组,会有多道必做题
- }
- $topic_no = $this->topic_no($item[1]);
- if (count($topic_no) != $topics[0]) {
- $error[] = '答题卡选做题格式设置有问题';
- }
- $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0));
- }
- }
- }
- }
- $topic_items = $this->topic_items($_topic_mould);
- // debug($topic_items);
- $_topic_items = array();
- if(!$topic_items){
- // $error[] = '答题卡格式设置有问题';
- echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有问题'));exit;
- }
- //添加alias
- $alias=0;
- $Multi_Group_Sign=0;
- $isDisplay=0;
- $letterNum=0;
- foreach ($topic_items as $v)
- {
- if($v['topic_type']!=17){
- $alias++;
- }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){
- $Multi_Group_Sign=$v['multi_group_sign'];
- $alias++;
- $isDisplay=1;
- $letterNum=0;
- }
- if($v['topic_type']==17){
- $v['alias']=(string)$alias.$this->numToLetter($letterNum);
- }else{
- $v['alias']=(string)$alias;
- }
- $v['showNum']=(string)$alias;
- unset($v['multi_group_sign']);
- $_topic_items[] = $v;
- $letterNum++;
- }
- if($_topic_items){
- $newTopicItems = array();
- $i = 1;
- $no = 1;
- foreach($_topic_items as $v){
- if(isset($v['smallCounts'])){
- $isDisplay=1;
- for($a=1;$a<=$v['smallCounts'];$a++){
- $v['id'] = $i;
- $v['smallNo'] = $a;
- $v['bigNo'] = $no;
- $v['alias'] = $no.'.'.$a;
- $newTopicItems[] = $v;
- $i++;
- }
- }else{
- $v['id'] = $i;
- // $v['smallNo'] = 1;
- $v['bigNo'] = $no;
- $newTopicItems[] = $v;
- $i++;
- }
- $no++;
- }
- }
- //debug($newTopicItems);
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- $json['author'] = $teacherName;
- $json['examDate'] = $examDate;
- $json['subjectId'] = (int)$subjectId;
- $json['textbookId'] = (int)$textbookId;
- $json['exam_name'] = $examName;
- $json['totals'] = count($newTopicItems);
- $json['layout'] = (int)$layout;
- $json['select_card_type'] = (int)$select_card_type;
- $json['impersonal_topic_type'] = 0;
- $json['total_score'] = 0;
- $json['scores'] = 0;
- $json['is_display'] = $isDisplay;
- $json['times'] = 0;
- if($subjectId==8){
- $json['isNewEnglish']=1;
- }
- $json['school_card_length'] = 8;
- if($this->schoolId>999){
- $json['school_card_length'] = 9;
- }
- $json['required'] = (int)$required;
- $json['new_items'] = $newTopicItems;
- $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).") ";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if(!$cardData){
- $error[] = '无法找到对应班级';
- }
- if($cardData['card_status']){
- $json['school_card_length'] = (int)$cardData['card_length'];
- }else{
- $cardData['card_length'] = 8;
- if($this->schoolId>999){
- $cardData['card_length'] = 9;
- }
- }
- $class_type=$cardData['class_type'];
- $time = time();
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- if($is_update){
- $exam_ids = array();
- ExamGroup::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update));
- $xams = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$is_update));
- if($xams){
- foreach ($xams as $v){
- $exam_ids[] = $v->exam_id;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- Exam::model()->deleteAll($criteria);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- SPaper::model()->deleteAll($criteria);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- ClassExamPrinter::model()->deleteAll($criteria);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- SStudentPaperRelation::model()->deleteAll($criteria);
- unset($criteria);
- }
- //$newExamGroupId = $this->UUID_SHORT();
- $newExamGroupId = getUniqueId($this->schoolId);
- if($markType ==4)
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
- }else
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
- }
- $this->sConn->createCommand($sql)->execute();
- foreach($classIds as $classId){
- //$newExamId = $this->UUID_SHORT();
- $newExamId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($json),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- //$newPaperId = $this->UUID_SHORT();
- $newPaperId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => 0,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- 'class_type' =>$class_type
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time' =>$time
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
- }
- }
- if(!$error){
- // echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>$json,'exam_group_id'=>$newExamGroupId));exit;
- echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
- }
- }
- public function actionCreateThirdTpl(){
- $error = array();
- $tplData = array();
- $tpl_title = Req::post("tpl_title");
- $classIds = Req::post("classIds");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $topic = $_POST["topic"];
- $layout = Req::post("layout");
- $select_card_type = Req::post("select_card_type");
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($tpl_title)){
- $error[] = '请设置答题卡名称';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($topic)){
- $error[] = '请设置题型';
- }
- if(empty($layout)){
- $error[] = '答题卡类型';
- }
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- $card_status = 0;
- $school_card_length = 8;
- if($this->schoolId>999){
- $school_card_length = 9;
- }
- $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).") ";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if(!$cardData){
- $error[] = '无法找到对应班级';
- }
- if($cardData['card_status']){
- $school_card_length = (int)$cardData['card_length'];
- $card_status = (int)$cardData['card_status'];
- }
- $rs = $this->sConn->createCommand()->insert('third_tpl',array(
- 'title' => $tpl_title,
- 'subject_id' => $subjectId,
- 'school_card_status' => $card_status,
- 'school_card_length' => $school_card_length,
- 'layout' => $layout,
- 'select_card_type' => $select_card_type,
- 'tpl_data' => $topic,
- 'create_time' => time()
- ));
- $third_tpl_id = $this->sConn->getLastInsertID();
- $_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)三栏');
- $_select_card_type = array(1=>'准考证号',2=>'条形码');
- if($rs){
- 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;
- }
- }
- echo json_encode(array('status'=>0,'msg'=>'保存成功'));exit;
- }
- public function actionCheckAnswerCard(){
- $eid = Req::post('eid');
- $error['success'] = 0;
- if (empty($eid)) {
- $error['message'] = '考试id不存在!';
- echo json_encode($error);exit();
- }
- $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
- if (empty($examGroup)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
- if (empty($thirdSheet)) {
- $error['message'] = '尚未创建答题卡,请创建!';
- echo json_encode($error);exit();
- }
- $mathAi=0; //数学ai解析入口
- $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_labelled>0');
- $criteria->addCondition('is_labelled<4');
- $_paper_data = SPaper::model()->findAll($criteria);
- if($_paper_data || ($examGroup['is_tagging']>0 && $examGroup['is_tagging']<4))
- {
- $error['success'] = 0;
- $error['message'] = '已发送标注,无法上传';
- echo json_encode($error);exit();
- }
- if(in_array($exam_data[0]['subject_id'],$this->mathSubjectId)){
- if($examGroup['qxk_paper_id']>0){
- //查询解析数据
- $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$eid));
- if($topicWord && $topicWord->is_history_topic){
- $mathAi=0;
- }else{
- $mathAi=1;
- }
- }
- }
- }
- $start=strtotime(date('Y-m-d'))+3600*8+1800; //8点半
- $end=strtotime(date('Y-m-d'))+3600*18; //18点
- if((time()>$start && time()<$end) || in_array($this->schoolId,array(2133,4016,4044,2134))){
- $error['data']='ai';
- }else{
- $error['data']='word';
- }
- $error['math_ai']=$mathAi;
- $error['success'] = 1;
- echo json_encode($error);exit();
- }
- // 上传试卷模板
- public function actionUploadTpl(){
- $exam_group_id = Req::post('eid');
- $error['success'] = 0;
- if (empty($exam_group_id)) {
- $error['message'] = '考试id不存在!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($examInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($thirdSheet)) {
- $error['message'] = '尚未上传答题卡!';
- echo json_encode($error);exit();
- }
- if (empty($_FILES['word_file'])) {
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }
- if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){
- $error['message'] = '非法上传!';
- echo json_encode($error);exit();
- }
- if ($_FILES['word_file']['error'] > 0) {
- switch ($_FILES['word_file']['error']) {
- case 1:
- $error['message'] = '文件大小超出了服务器的空间大小!';
- break;
- case 2:
- $error['message'] = '要上传的文件大小超出浏览器限制!';
- break;
- case 3:
- $error['message'] = '文件只有部分被上传!';
- break;
- case 4:
- $error['message'] = '没有找到要上传的文件!';
- break;
- case 5:
- $error['message'] = '服务器临时文件夹丢失!';
- break;
- case 6:
- $error['message'] = '文件写入到临时文件夹出错!';
- break;
- }
- echo json_encode($error);exit();
- }
- // 保存上传文件至服务器
- $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.'));
- $fileName = $exam_group_id.$extName;
- $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($wordRename, $_FILES['word_file']['tmp_name']);
- if ($uploadInfo['status'] == 0) {
- echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg']));
- exit();
- }
- $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "title" => '第三方试卷上传试卷',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('insert'=>array('exam_group_id'=>$exam_group_id,'status'=>0,'word_path'=>$uploadInfo['url'],'subject_id'=>$examInfo->subject_id))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- $time = time();
- //查询解析数据
- $topicWord = STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($topicWord && $topicWord->is_history_topic){
- //复用解析,重新上传清空试题
- $historyTopic=json_decode($topicWord->is_history_topic,1);
- if(!$historyTopic){
- $error['message'] = '试卷结构恢复不成功!';
- echo json_encode($error);exit();
- }
- $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$exam_group_id}")->queryRow();
- if ($examGroup['upload_status'] > 0) {
- $result['message'] = "已上传成绩,不能切换解析模式";
- exit(json_encode($result));
- }
- $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();
- //取得试卷topic
- $paperIds=array();
- foreach ($exam as $value){
- $paperIds[]=$value['paper_id'];
- }
- $tplData=json_decode($exam[0]['tpl_data'],true);
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $key =>$val){
- if(isset($historyTopic[$val['id']])){
- $tplData['new_items'][$key]['topicId']=$historyTopic[$val['id']]['topic_id'];
- $tplData['new_items'][$key]['stemId']=$historyTopic[$val['id']]['stem_id'];
- }
- }
- }
- $paperTopicRelation=$this->sConn->createCommand("select `order`,`topic_id`,`type`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
- $updateSql=array();
- foreach ($paperTopicRelation as $value){
- if(!isset($historyTopic[$value['order']])){
- $error['message'] = '试卷结构恢复不成功!';
- echo json_encode($error);exit();
- }
- $stemId=0;
- if(isset($historyTopic[$value['order']]['stem_id'])){
- $stemId=$historyTopic[$value['order']]['stem_id'];
- }
- $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']."'";
- if($examGroup['mark_type']==4 && !in_array($historyTopic[$value['order']]['type'],array(1,2,11))){
- $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']}'";
- }
- }
- foreach ($updateSql as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- if($examGroup['mark_type']!=4){
- $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute();
- }
- $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$exam_group_id}'")->execute();
- }
- $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute();
- STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
- $wordId = current(current($uuid));
- $topic_word_odj = new STopicWord();
- $topic_word_odj->word_id = $wordId;
- $topic_word_odj->exam_group_id = $exam_group_id;
- $topic_word_odj->word_name = '第三方试卷'.$fileName;
- $topic_word_odj->word_path = $uploadInfo['url'];
- $topic_word_odj->word_md5 = '';
- $topic_word_odj->word_size = $_FILES['word_file']['size'];
- $topic_word_odj->subject_id = $examInfo->subject_id;
- $topic_word_odj->status = 0;
- $topic_word_odj->uploader_id = $this->coachId;
- $topic_word_odj->upload_time = $time;
- $topic_word_odj->save();
- $transcation->commit();
- }
- catch (Exception $e)
- {
- $transcation->rollback();
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- $this->schoolManager->saveExamProcess($exam_group_id,3,time());
- $error['success'] = 1;
- $error['message'] = '上传文件成功!';
- echo json_encode($error);exit();
- }
- public function actionSetSubjectId()
- {
- $subjectId = Req::post("subjectId");
- if($subjectId)
- {
- Yii::app()->session['session_duoxueke_subject_id'] = $subjectId;
- echo 1;exit;
- }else
- {
- echo 0;exit;
- }
- }
- /**
- *
- * 格式:array(
- * 题型=>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)))
- *
- * )
- *
- */
- protected function topic_items($topic_data = array())
- {
- $data = array();
- $keys = array();
- if(!$topic_data)
- {
- return false;
- }
- foreach ($topic_data as $k=>$v)
- {
- $counter = $this->counter($k,$v);
- if(!$counter){
- return array();
- }else{
- foreach ($counter as $ck =>$cv){
- if(!isset($keys[$ck])){
- $keys[$ck] = $ck;
- $data[$ck] = $cv;
- }else{
- return false;
- }
- }
- }
- }
- ksort($data);
- return $data;
- }
- /**
- *计算题量
- */
- protected function counter($type,$format)
- {
- $data = array();
- $keys = array();
- if($type==1 || $type ==11)
- {
- foreach ($format as $_format){
- if(isset($_format['option_count']) && !empty($_format['option_count']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format']))
- {
- $topic_no = $this->topic_no($_format['topic_no_format']);
- if($topic_no)
- {
- foreach ($topic_no as $v)
- {
- if(isset($keys[$v])){
- return false;
- }else{
- $keys[$v] = $v;
- }
- $data[$v]['id'] = (int)$v;
- $data[$v]['optionsCount'] = (int)$_format['option_count'];
- $data[$v]['score'] = 0;
- $data[$v]['topic_type'] = (int)$type;
- $data[$v]['group_id'] = 0;
- $data[$v]['border'] = "";
- $data[$v]['style'] = "";
- $data[$v]['row'] = 0;
- }
- }else{
- return false;
- }
- }
- }
- }elseif($type==5){
- foreach ($format as $_format){
- if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
- if(isset($_format['smallTopics'])){
- $smallArr = $_format['smallTopics'];
- }else{
- $smallArr = array();
- }
- $topic_no = $this->topic_no($_format['topic_no_format']);
- if($topic_no){
- foreach ($topic_no as $v){
- if(isset($keys[$v])){
- return false;
- }else{
- $keys[$v] = $v;
- }
- $data[$v]['id'] = (int)$v;
- $data[$v]['optionsCount'] = 0;
- $data[$v]['score'] = 0;
- $data[$v]['group_id'] = 0;
- $data[$v]['topic_type'] = (int)$type;
- $data[$v]['border'] = $_format['style']['border'];
- $data[$v]['style'] = $_format['style']['style'];
- $data[$v]['row'] = $_format['style']['row'];
- if(isset($smallArr[$v])){
- $data[$v]['smallCounts'] = $smallArr[$v];
- }
- }
- }
- }
- }
- }elseif($type==7){
- foreach ($format as $_format){
- if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
- if(isset($_format['smallTopics'])){
- $smallArr = $_format['smallTopics'];
- }else{
- $smallArr = array();
- }
- $topic_no = $this->topic_no($_format['topic_no_format']);
- if($topic_no){
- foreach ($topic_no as $v){
- if(isset($keys[$v])){
- return false;
- }else{
- $keys[$v] = $v;
- }
- $data[$v]['id'] = (int)$v;
- $data[$v]['optionsCount'] = 0;
- $data[$v]['score'] = 0;
- $data[$v]['group_id'] = 0;
- $data[$v]['topic_type'] = (int)$type;
- $data[$v]['border'] = $_format['style']['border'];
- $data[$v]['style'] = $_format['style']['style'];
- $data[$v]['row'] = $_format['style']['row'];
- if(isset($smallArr[$v])){
- $data[$v]['smallCounts'] = $smallArr[$v];
- }
- }
- }
- }
- }
- }elseif($type==17){
- foreach ($format as $_format){
- if(isset($_format['style']) && !empty($_format['style']) && isset($_format['topic_no_format']) && !empty($_format['topic_no_format'])){
- $topic_no = $this->topic_no($_format['topic_no_format']);
- //多选题需要添加一个组的标记
- $Multi_Group_Sign=0;
- if($topic_no){
- foreach ($topic_no as $v){
- if(isset($keys[$v])){
- return false;
- }else{
- $keys[$v] = $v;
- }
- if(!$Multi_Group_Sign) $Multi_Group_Sign=$v;
- $data[$v]['id'] = (int)$v;
- $data[$v]['optionsCount'] = 0;
- $data[$v]['score'] = 0;
- $data[$v]['group_id'] = 0;
- $data[$v]['topic_type'] = (int) $type;
- $data[$v]['border'] = $_format['style']['border'];
- $data[$v]['style'] = $_format['style']['style'];
- $data[$v]['row'] = $_format['style']['row'];
- $data[$v]['multi_group_sign'] = $Multi_Group_Sign;
- }
- }
- }
- }
- }
- return $data;
- }
- /**
- * @param $str
- * 格式
- */
- protected function topic_no($str)
- {
- $data = array();
- if($str){
- $array = explode(',', $str);
- foreach ($array as $key => $v) {
- if(!empty($v)){
- $section = explode('-', $v);
- if(count($section)>1)
- {
- if($section[1]<$section[0])
- {
- return array();
- }else
- {
- if($section[0]){
- for ($i=$section[0]; $i<= $section[1] ; $i++) {
- # code...
- if(isset($data[$i]))
- {
- return array();
- }else{
- $data[$i] = $i;
- }
- }
- }
- }
- }else{
- if(isset($data[$v]))
- {
- return array();
- }else{
- $data[$v] = $v;
- }
- }
- }
- }
- }
- return $data;
- }
- public function actionPrint_paper(){
- $exam_group_id = Req::post('exam_group_id');
- $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam)
- {
- echo json_encode(array('status'=>1,'msg'=>'','result'=>$exam->tpl_data));exit;
- }
- echo json_encode(array('status'=>0,'msg'=>$exam->tpl_data,'result'=>''));exit;
- }
- public function actionCreate_sheet(){
- $examName = Req::post("examName");
- $classIds = Req::post("classIds");
- $layout = Req::post("layout");
- $select_card_type = Req::post("select_card_type");
- $topic = $_POST["topic"];
- if($topic && $classIds){
- $classIds = explode(',',substr($classIds,0,-1));
- //组装题型topic_items
- $_topic = json_decode($topic,1);
- $_topic_mould = array();
- $border = '';
- $required = 0;
- /**
- * * 格式:array(
- * 题型=>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)))
- */
- // debug($_topic);
- foreach ($_topic as $k=>$v)
- {
- if(!empty($v)) {
- if ($k == 0) {
- foreach ($v as $item) {
- $_topic_mould[1][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
- }
- }
- if ($k == 1) {
- foreach ($v as $item) {
- $_topic_mould[11][] = array('option_count' => $item[0], 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => '', 'row' => 0));
- }
- }
- if ($k == 2) {
- foreach ($v as $item) {
- $border = 'no';
- if ($item[2] >= 1) {
- $border = 'no';
- }
- if ($item[2] == 2) {
- $border = 'dashed';
- }
- if ($item[2] == 3) {
- $border = 'solid';
- }
- $smallTopics = array();
- if(isset($item[3]) && $item[3]){
- $smallArr = explode(',', $item[3]);
- foreach($smallArr as $k=>$v){
- $smallNextArr = explode('///', $v);
- $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
- }
- }
- $style = 'line';
- $row = isset($item[0]) ? $item[0] : 1;
- $_topic_mould[5][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
- }
- }
- if ($k == 3) {
- foreach ($v as $item) {
- $border = 'no';
- if ($item[2] >= 1) {
- $border = 'no';
- }
- if ($item[2] == 2) {
- $border = 'dashed';
- }
- if ($item[2] == 3) {
- $border = 'solid';
- }
- $smallTopics = array();
- if(isset($item[3]) && $item[3]){
- $smallArr = explode(',', $item[3]);
- foreach($smallArr as $k=>$v){
- $smallNextArr = explode('///', $v);
- $smallTopics[$smallNextArr[0]] = $smallNextArr[1];
- }
- }
- $styles = explode('///', $item[0]);
- $style = 'blank';
- $row = 0;
- if ($styles) {
- if ($styles[0] == 1) {
- $style = 'blank';
- }
- if ($styles[0] == 2) {
- $style = 'line';
- $row = isset($styles[1]) ? $styles[1] : 1;
- }
- if ($styles[0] == 3) {
- $style = 'table';
- }
- }
- $_topic_mould[7][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => $border, 'style' => $style, 'row' => (int)$row),'smallTopics'=>$smallTopics);
- }
- }
- if ($k == 4) {
- $style = 'blank';
- foreach ($v as $item) {
- if ($item[2] == 1) {
- $style = 'blank';
- }
- if ($item[2] == 2) {
- $style = 'line';
- }
- $topics = explode('///', $item[0]);
- if ($topics && isset($topics[1])) {
- $required += $topics[1];
- }
- $topic_no = $this->topic_no($item[1]);
- if (count($topic_no) != $topics[0]) {
- $error[] = '答题卡选做题格式设置有误,请填写正确的题号';
- }
- $_topic_mould[17][] = array('option_count' => 0, 'topic_no_format' => $item[1], 'style' => array('border' => '', 'style' => $style, 'row' => 0));
- }
- }
- }
- }
- // debug($_topic_mould);
- $topic_items = $this->topic_items($_topic_mould);
- $_topic_items = array();
- if(!$topic_items){
- echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写确的题号'));exit;
- }
- //添加alias
- $alias=0;
- $Multi_Group_Sign=0;
- $isDisplay=0;
- $letterNum=0;
- foreach ($topic_items as $v)
- {
- if($v['topic_type']!=17){
- $alias++;
- }elseif(isset($v['multi_group_sign']) && $Multi_Group_Sign!=$v['multi_group_sign']){
- $Multi_Group_Sign=$v['multi_group_sign'];
- $alias++;
- $isDisplay=1;
- $letterNum=0;
- }
- if($v['topic_type']==17){
- $v['alias']=(string)$alias.$this->numToLetter($letterNum);
- }else{
- $v['alias']=(string)$alias;
- }
- $v['showNum']=(string)$alias;
- unset($v['multi_group_sign']);
- if(isset($v['smallCounts'])){
- $smallCounts = (int)$v['smallCounts'];
- $bigId = (int)$v['alias'];
- for($a=1;$a<=$smallCounts;$a++){
- $v['alias'] = $bigId.'.'.$a;
- $v['showNum'] = $bigId.'.'.$a;
- $_topic_items[] = $v;
- // $alias++;
- }
- }else{
- $_topic_items[] = $v;
- }
- $letterNum++;
- }
- //debug($_topic_items);
- $json['author'] = '';
- $json['examDate'] = '';
- $json['subjectId'] = (int)Yii::app()->session['session_duoxueke_subject_id'];
- $json['textbookId'] = 0;
- $json['exam_name'] = $examName;
- $json['totals'] = count($_topic_items);
- $json['layout'] = (int)$layout;
- $json['select_card_type'] = (int)$select_card_type;
- $json['impersonal_topic_type'] = 0;
- $json['total_score'] = 0;
- $json['is_display'] = 1;
- $json['times'] = 0;
- $json['school_card_length'] = 8;
- if($this->schoolId>999){
- $json['school_card_length'] = 9;
- }
- $json['required'] = (int)$required;
- $json['new_items'] = $_topic_items;
- $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).") ";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if(!$cardData){
- $error[] = '无法找到对应班级';
- }
- if($cardData['card_status']){
- $json['school_card_length'] = (int)$cardData['card_length'];
- }
- echo json_encode(array('status'=>1,'msg'=>'打印成功','result'=>$json));exit;
- }
- echo json_encode(array('status'=>0,'msg'=>'答题卡格式设置有误,请填写考试名称与班级信息'));exit;
- }
- /*判断关联答题卡*/
- public function actionGetThirdSheet(){
- $ExamGroupId=Req::post('exam_group_id');
- $getType=Req::post('get_type');
- if(!$getType) $getType=0;
- $result=array('success'=>0);
- if(!$ExamGroupId || !is_numeric($ExamGroupId)){
- exit(json_encode($result));
- }
- //验证是否发送任务
- $task=ATask::model()->findByPk($ExamGroupId);
- if(!$getType){
- if($task && in_array($task->paper_task,array(1,2))){
- echo json_encode(array('success'=>4));exit;
- }
- }else{
- if($task && in_array($task->parse_task,array(1,2))){
- echo json_encode(array('success'=>4));exit;
- }
- }
- $ThirdSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$ExamGroupId));
- if($ThirdSheet){
- $result['success']=1;
- }
- exit(json_encode($result));
- }
- /********************* 第三方教学宝开始 *********************/
- /**
- * 第三方教学宝
- * @throws CException
- */
- public function actionTeaching()
- {
- set_time_limit (300);
- ini_set('memory_limit', '300M');
- $classId = Req::get("classId");
- $examId = Req::get("examId");
- $force = (int)Req::get('force');
- $force = 1;//待删
- if(!$examId || !is_numeric($examId)){
- echo json_encode(array("status" => 1, "error" => "考试ID参数不正确!"));
- }
- $examObj = new Exam();
- $examInfo = $examObj->getTeachingInfo($examId);
- if(!$examInfo){
- echo json_encode(array("status" => 1, "error" => "没有考试信息!"));
- exit;
- }
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path'];
- $res = array();//生成pdf命令结果
- if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath) || $force) {
- $paperObj = new SPaper();
- $ptrObj = new SPaperTopicRelation();
- $ptlObj = new SPaperTopicLarge();
- $sprObj = new SStudentPaperRelation();
- $sptRsObj = new SStudentPaperTopicRs();
- $examGroupId = $examInfo['exam_group_id'];
- $examIds = $examObj->getExamIds($examGroupId);
- //去除没有上传成绩的学生
- $stuIdsArr = $sptRsObj->getHasScoreStu($examIds);
- $ptrInfo = $sprObj->getStudentExamInfo($examIds);
- if(!$ptrInfo){
- echo json_encode(array("status" => 1, "error" => "考试没有数据!"));
- exit();
- }
- $paperIds = array();
- foreach($ptrInfo as $value){
- $paperIds[$value['exam_id']] = $value['paper_id'];
- }
- //试卷总分
- $paperScore = $paperObj->getPaperScore($paperIds);
- if(!$paperScore){
- echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
- exit();
- }
- /**************************** 一、班级情况分析 ***********************************/
- //获取当前考试的上一次考试数据
- $cepObj = new SClassExamPrinter();
- $preInfo = $cepObj->getPreExamId($examId,$examInfo['subject_id'],$examInfo['class_id']);
- $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:'';
- $preExamGroupId = isset($preInfo['exam_group_id'])?$preInfo['exam_group_id']:'';
- $prePaperScore = 0;
- $preStuIdsArr = array();
- if($preExamId){
- $preExamIds = $examObj->getExamIds($preExamGroupId);
- //去除没有上传成绩的学生
- $preStuIdsArr = $sptRsObj->getHasScoreStu($preExamIds);
- $prePtrInfo = $sprObj->getStudentExamInfo($preExamIds);
- $prePaperIds = array();
- foreach($prePtrInfo as $value){
- $prePaperIds[$value['exam_id']] = $value['paper_id'];
- }
- if($prePaperIds){
- $prePaperScore = $paperObj->getPaperScore($prePaperIds);
- }
- }else{
- $prePtrInfo = array();
- }
- if(!$prePaperScore && $prePtrInfo){
- echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
- exit();
- }
- $paperId = $paperIds[$examId];
- //班级排名得分率人数等数据
- $classAnalyData = $this->getClassAnalyse($examId,$ptrInfo,$paperScore,$preExamId,$prePtrInfo,$prePaperScore,$stuIdsArr,$preStuIdsArr);
- //大幅进步,大幅退步,前5名和后5名
- $largeOrderData = $this->getLargeOrder($examId,$ptrInfo,$preExamId,$prePtrInfo,$stuIdsArr,$preStuIdsArr);
- unset($ptrInfo);
- unset($prePtrInfo);
- /**************************** 二、考试情况分析 ***********************************/
- //试卷题对应的题号,分数
- $largeTopicType = $ptlObj->getPaperLargeTopicInfo($paperId);
- // list($topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType);
- list($smallTopicScore,$smallTopicNo,$topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod) = $ptrObj->getPaperTopicInfo($paperId,$largeTopicType,$examInfo['subject_id']);
- if(!$topicScore){
- echo json_encode(array("status" => 1, "error" => "没有试卷题数据!"));
- exit();
- }
- // 学生得分
- $stuRs = $sptRsObj->getStudentRs($paperIds);
- if(!$stuRs){
- echo json_encode(array("status" => 1, "error" => "没有学生做题数据!"));
- exit();
- }
- $examAnalyData = $this->getExamAnalyse($stuRs,$topicScore,$topicNo,$paperId,$topicRelLarge);
- /**************************** 三、题类型掌握情况 ***********************************/
- $typeMasterData = $this->getTopicTypeAnaly($stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge);
- /**************************** 四、试卷讲评 ***********************************/
- //试题年级和班级得分率,答对和答错人数
- $topicRateStu = $this->getTopicRateWrongPerson($stuRs,$topicScore,$paperId,$stuIdsArr,$topicRelLarge);
- unset($stuRs);
- $topicIds = array_keys($topicNo);
- $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicIds));
- if (!$topicDetails) {
- echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
- exit();
- } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
- echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
- exit();
- }
- $topicDetails = $this->getTopicDetail($topicDetails);
- $diff_id_arr = array_diff($topicIds, array_keys($topicDetails));
- if ($diff_id_arr) {
- //todo 发送消息到补提
- echo json_encode(array("status" => 1, "error" => "请等待题库老师补题!"));
- exit;
- }
- $data = array();
- $data['examInfo'] = $examInfo;
- $data['classAnalyData'] = $classAnalyData;
- $data['largeOrderData'] = $largeOrderData;
- $data['examAnalyData'] = $examAnalyData;
- $data['typeMasterData'] = $typeMasterData;
- $data['topicDetails'] = $topicDetails;
- $data['paperTopicNo'] = $topicNo;
- $data['smallTopicNo'] = $smallTopicNo;
- $data['topicRateStu'] = $topicRateStu;
- $html = $this->renderPartial("teaching", $data, true);
- // $html = $this->render("teaching", $data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/assets/pdf/academicr/' . $this->schoolId . "/";
- if (!is_dir($htmlpath)) {
- if (!mkdir($htmlpath, 0777, true)) {
- exit('Create directory fail: ' . $htmlpath);
- }
- }if (!is_dir($pdfpath)) {
- if (!mkdir($pdfpath, 0777, true)) {
- exit('Create directory fail1: ' . $pdfpath);
- }
- }
- $htmlpath.=$examId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- $htmlurl = '/assets/' . $examId . ".html"; //访问HTML的路径
- if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
- $htmlurl = " http://local.zsyas2teaching.com" . '/'.$examId.'.html';
- $pdffname=$classId."-".$examId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm ''";
- } else {
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- $pdffname=$classId."-".$examId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm ''";
- }
- exec($commond, $res, $code);
- if(isset($res[0])){
- $isBool = false;
- foreach($res as $msg){
- if (strpos($msg, 'succeed') !== false){
- $isBool = true;
- }
- }
- if ($isBool) {//命令返回成功
- if ($this->file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
- @unlink($htmlpath);
- } else {
- $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
- exit;
- }
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!",'exec_rs'=>json_encode($res)));
- exit;
- }
- }else{
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => (string)$examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '下载教师讲案',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => '',
- "operate_param" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$htmlurl))),
- ));
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
- exit;
- }
- }
- if ($this->check_pdf($pdfpath)) {
- echo json_encode(array("status" => 0, "error" => "","is_create"=>1,'exec_rs'=>json_encode($res)));
- exit;
- } else {
- echo json_encode(array("status" => 1, "error" => "文件尚未生成!",'exec_rs'=>json_encode($res)));
- exit;
- }
- }
- private function check_pdf($pdf_path) {
- if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
- if (file_exists($pdf_path)) {
- return true;
- }
- }
- return false;
- }
- /**
- * 班级排名得分率人数等数据
- * @param $examId
- * @param $ptrInfo
- * @param $paperScore
- * @param $preExamId
- * @param $prePtrInfo
- * @param $prePaperScore
- * @return array
- */
- private function getClassAnalyse($examId,&$ptrInfo,$paperScore,$preExamId,&$prePtrInfo,$prePaperScore,&$stuIdsArr,&$preStuIdsArr){
- $result = array();
- $gradePerson = $classPerson = 0;//参考人数
- $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数
- $gradeOrder = $classOrder = 0; //排名
- $gradeAvgScore = $classAvgScore = 0; //平均分
- $gradeScoreRate = $classScoreRate = 0; //得分率
- $gradeFineRate = $classFineRate = 0; //优秀率 80%
- $gradePassRate = $classPassRate = 0; //合格率 60%
- $gradeLowRate = $classLowRate = 0; //低分率 30%
- $angData = array(
- 'class_num' => 0,//班级数量
- 'order' => 0,
- 'absent_person' => 0,
- 'exam_person' => 0,
- 'avg_score' => 0,
- 'score_rate' => 0,
- 'fine_rate' => 0,
- 'pass_rate' => 0,
- 'low_rate' => 0,
- );
- $result['grade'] = $result['class'] = $angData;
- $gradeScoring = $classScoring = array();
- $gradeScoringSum = array();//年级中每个考试的得分和
- // $classScoringSum = 0;//考试得分和
- $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率
- foreach($ptrInfo as $value){
- $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
- if(!isset($gradeScoringSum[$value['exam_id']])){
- $gradeScoringSum[$value['exam_id']] = 0;
- }
- if(inArray($value['student_id'],$stuIds)){
- $gradeScoringSum[$value['exam_id']] += $value['scoring'];
- $gradeScoring[] = $value['scoring'];
- $gradeStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
- $gradePerson++;
- }
- if(!inArray($value['student_id'],$stuIds)){
- $gradeAbsentPerson++;
- }
- if($examId == $value['exam_id']){
- if(inArray($value['student_id'],$stuIds)){
- // $classScoringSum += $value['scoring'];
- $classScoring[] = $value['scoring'];
- $classStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
- $classPerson++;
- }
- if(!inArray($value['student_id'],$stuIds)){
- $classAbsentPerson++;
- }
- }
- }
- unset($ptrInfo);
- $result['class']['class_num'] = count($gradeScoringSum);
- $result['grade']['exam_person'] = $gradePerson;
- $result['grade']['absent_person'] = $gradeAbsentPerson;
- $result['class']['exam_person'] = $classPerson;
- $result['class']['absent_person'] = $classAbsentPerson;
- //排名
- if($gradeScoringSum){
- $scoringArr = array();
- foreach($gradeScoringSum as $eId => $scoring){
- $stuCount = isset($stuIdsArr[$eId])?count($stuIdsArr[$eId]):0;
- if($stuCount){
- $scoringArr[$eId] = round($scoring/$stuCount,2);
- }
- }
- if(isset($scoringArr[$examId])){
- $classOrder = $this->getOrder($scoringArr[$examId],$scoringArr);
- }else{
- $classOrder = 0;
- }
- }
- $result['class']['order'] = $classOrder;
- //平均分,得分率
- $count = count($gradeScoring);
- if($count > 0){
- $gradeAvgScore = round(array_sum($gradeScoring)/$count,2);//平均分
- $gradeScoreRate = round(array_sum($gradeScoring)/($paperScore*$count),4)*100;//得分率
- }else{
- $gradeAvgScore = 0;
- $gradeScoreRate = 0;
- }
- $result['grade']['avg_score'] = $gradeAvgScore;
- $result['grade']['score_rate'] = $gradeScoreRate;
- $count = count($classScoring);
- if($count > 0){
- $classAvgScore = round(array_sum($classScoring)/$count,2);
- $classScoreRate = round(array_sum($classScoring)/($paperScore*$count),4)*100;//得分率
- }else{
- $classAvgScore = 0;
- $classScoreRate = 0;
- }
- $result['class']['avg_score'] = $classAvgScore;
- $result['class']['score_rate'] = $classScoreRate;
- //优秀率,合格率,低分率
- // $gradeFineRate = $classFineRate = 0; //优秀率 85%
- // $gradePassRate = $classPassRate = 0; //合格率 60%
- // $gradeLowRate = $classLowRate = 0; //低分率 30%
- $tempFineNum = $tempPassNum = $tempLowNum = 0;
- $rateCount = count($gradeStuScoringRate);
- foreach($gradeStuScoringRate as $scoringRate){
- if($scoringRate >= 85){
- $tempFineNum++;
- }
- if($scoringRate >= 60){
- $tempPassNum++;
- }
- if($scoringRate <= 30){
- $tempLowNum++;
- }
- }
- $gradeFineRate = round($tempFineNum/$rateCount,4) * 100;
- $gradePassRate = round($tempPassNum/$rateCount,4) * 100;
- $gradeLowRate = round($tempLowNum/$rateCount,4) * 100;
- $result['grade']['fine_rate'] = $gradeFineRate;
- $result['grade']['pass_rate'] = $gradePassRate;
- $result['grade']['low_rate'] = $gradeLowRate;
- $tempFineNum = $tempPassNum = $tempLowNum = 0;
- $rateCount = count($classStuScoringRate);
- foreach($classStuScoringRate as $scoringRate){
- if($scoringRate >= 85){
- $tempFineNum++;
- }
- if($scoringRate >= 60){
- $tempPassNum++;
- }
- if($scoringRate <= 30){
- $tempLowNum++;
- }
- }
- $classFineRate = round($tempFineNum/$rateCount,4) * 100;
- $classPassRate = round($tempPassNum/$rateCount,4) * 100;
- $classLowRate = round($tempLowNum/$rateCount,4) * 100;
- $result['class']['fine_rate'] = $classFineRate;
- $result['class']['pass_rate'] = $classPassRate;
- $result['class']['low_rate'] = $classLowRate;
- /**************** 提升数据 ******************/
- $result['class']['order_increase'] = 0;
- $result['class']['rate_increase'] = 0;
- $result['class']['fine_rate_increase'] = 0;
- if($prePtrInfo){
- $preGradeScoringSum = array();
- $preClassScoringSum = 0;
- $preClassScoring = array();
- if($prePtrInfo){
- foreach($prePtrInfo as $value){
- $stuIds = isset($preStuIdsArr[$value['exam_id']])?$preStuIdsArr[$value['exam_id']]:array();
- if(!isset($preGradeScoringSum[$value['exam_id']])){
- $preGradeScoringSum[$value['exam_id']] = 0;
- }
- if(inArray($value['student_id'],$stuIds)){
- $preGradeScoringSum[$value['exam_id']] += $value['scoring'];
- }
- if($preExamId == $value['exam_id']){
- if(inArray($value['student_id'],$stuIds)){
- $preClassScoringSum += $value['scoring'];
- $preClassScoring[] = $value['scoring'];
- $preClassStuScoringRate[] = round($value['scoring']/$prePaperScore,4)*100;
- }
- }
- }
- }
- //上一次考试排名
- if($gradeScoringSum){
- $scoringArr = array();
- foreach($preGradeScoringSum as $eId => $scoring){
- $stuCount = isset($preStuIdsArr[$eId])?count($preStuIdsArr[$eId]):0;
- if($stuCount){
- $scoringArr[$eId] = round($scoring/$stuCount,2);
- }
- }
- if(isset($scoringArr[$preExamId])){
- $preClassOrder = $this->getOrder($scoringArr[$preExamId],$scoringArr);
- }else{
- $preClassOrder = 0;
- }
- $result['class']['order_increase'] = -($classOrder - $preClassOrder);
- }
- $count = count($preClassScoring);
- if($count > 0){
- $preClassScoreRate = round(array_sum($preClassScoring)/($prePaperScore*$count),4)*100;//得分率
- $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate;
- }
- $tempFineNum = 0;
- $rateCount = count($preClassStuScoringRate);
- foreach($preClassStuScoringRate as $scoringRate){
- if($scoringRate >= 85){
- $tempFineNum++;
- }
- }
- $preClassFineRate = round($tempFineNum/$rateCount,4) * 100;
- $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate;
- }
- return $result;
- }
- /**
- * 大幅进步,大幅退步,前5名和后5名
- * @param $examId
- * @param $ptrInfo
- * @param $paperScore
- * @param $preExamId
- * @param $prePtrInfo
- * @param $prePaperScore
- */
- private function getLargeOrder($examId,&$ptrInfo,$preExamId,&$prePtrInfo,&$stuIdsArr,&$preStuIdsArr){
- $result = array();
- $stuOrderArr = $this->getStudentOrder($examId,$ptrInfo,$stuIdsArr);
- $diffNum = ceil(count($stuOrderArr)*0.2);
- if($prePtrInfo){
- $preStuOrderArr = $this->getStudentOrder($preExamId,$prePtrInfo,$preStuIdsArr);
- }else{
- $preStuOrderArr = array();
- }
- if($preStuOrderArr){
- $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr);
- if(!$interOrderArr){
- $interOrderArr = $stuOrderArr;
- }
- }else{
- $interOrderArr = array();
- }
- //大幅进步,退步
- $increaseArr = $reduceArr = array();
- $stuDiffOrder = array();
- if($interOrderArr){
- foreach($stuOrderArr as $stuId => $order){
- if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){
- $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]);
- }else{
- $stuDiffOrder[$stuId] = 0;
- }
- }
- arsort($stuDiffOrder);
- foreach($stuDiffOrder as $stuId => $num){
- if($num >= $diffNum){
- $increaseArr[] = $stuId;
- }
- }
- $increaseArr = array_slice($increaseArr,0,5,true);
- asort($stuDiffOrder);
- foreach($stuDiffOrder as $stuId => $num){
- if($num <= -$diffNum){
- $reduceArr[] = $stuId;
- }
- }
- $reduceArr = array_slice($reduceArr,0,5,true);
- }else{
- $increaseArr = array_slice($stuOrderArr,0,5,true);
- $reduceArr = array();
- }
- $result['stu_diff_order'] = $stuDiffOrder;
- $result['stu_order'] = $stuOrderArr;
- $result['increase_stu'] = $increaseArr;
- $result['reduce_stu'] = $reduceArr;
- //前5名和后5名
- $font5 = $back5 = array();
- $i = 1;
- $fonrt5_order = array();
- foreach($stuOrderArr as $stuId => $order){
- if($i <= 5){
- $font5[] = $stuId;
- $fonrt5_order[] = $order;
- }else{
- break;
- }
- $i++;
- }
- $result['font_five'] = $font5;
- $i = 1;
- //删除前5排名
- $_stuOrderArr = $stuOrderArr;
- foreach($_stuOrderArr as $k => $order){
- if(in_array($order,$fonrt5_order)){
- unset($_stuOrderArr[$k]);
- }
- }
- arsort($_stuOrderArr);
- foreach($_stuOrderArr as $stuId => $order){
- if($i <= 5){
- $back5[] = $stuId;
- }else{
- break;
- }
- $i++;
- }
- $result['back_five'] = $back5;
- //学生名称
- $stuInfoObj = new SStudentInfo();
- $stuName = $stuInfoObj->getStudentNames(array_keys($stuOrderArr));
- $result['stu_name'] = $stuName;
- unset($stuOrderArr);
- return $result;
- }
- /**
- * 考试情况分析
- * @param $stuRs
- * @param $topicScore
- * @param $topicNo
- * @return array
- */
- private function getExamAnalyse(&$stuRs,$paperTopicScore,$topicNo,$paperId,$topicRelLarge){
- $result = array();
- $stuTopicWrong = array();//题答错人数
- $topicScoreRate = array();//题得分率
- $topicScoring = array();//题得分
- $topicScore= array();//题分
- foreach($stuRs as $stuId => $rs){
- foreach($rs as $v){
- if($paperId == $v['paper_id']){
- if(isset($topicRelLarge[$v['topic_id']]) && $topicRelLarge[$v['topic_id']] > 0){
- $t_id = $topicRelLarge[$v['topic_id']];
- }else{
- $t_id = $v['topic_id'];
- }
- $t_score = isset($paperTopicScore[$t_id])?$paperTopicScore[$t_id]:0;
- if(!isset($topicScoring[$t_id])){
- $topicScoring[$t_id] = 0;
- }
- $topicScoring[$t_id] += $v['scoring'];
- if(!isset($topicScore[$t_id])){
- $topicScore[$t_id] = 0;
- }
- $topicScore[$t_id] += $t_score;
- if(!isset($stuTopicWrong[$t_id])){
- $stuTopicWrong[$t_id] = array();
- }
- if($t_score != $v['scoring']){
- $stuTopicWrong[$t_id][] = $stuId;
- }
- }
- }
- }
- //题得分率
- foreach($topicScoring as $topicId => $scoring){
- if(isset($topicScore[$topicId]) && $topicScore[$topicId] > 0){
- $topicScoreRate[$topicId] = round($scoring/$topicScore[$topicId],4) * 100;
- }else{
- $topicScoreRate[$topicId] = 0;
- }
- }
- unset($topicScoring);
- //答错人数
- if($stuTopicWrong){
- foreach($stuTopicWrong as $key => $stuIds){
- $stuIds = array_unique($stuIds);
- $stuTopicWrong[$key] = count($stuIds);
- }
- }
- $result['stu_topic_wrong'] = $stuTopicWrong;
- $result['topic_score_rate'] = $topicScoreRate;
- $result['topic_no'] = $topicNo;
- unset($stuTopicWrong);
- unset($topicScoreRate);
- unset($topicNo);
- unset($topicScore);
- return $result;
- }
- //题类型掌握情况
- private function getTopicTypeAnaly(&$stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge){
- $result = array();
- $gradeRate = $classRate = array();//班级和年级得分率
- $stuTypeWrong = array();//题型答错人数
- $typeTopicNo = array();//题型对应的题号
- $typeMasterDegree = array();//题型掌握水平
- $typeName = array('1'=>'选择题','11'=>'不定项选择题','5'=>'填空题','7'=>'解答题','17'=>'选做解答题');
- $logicTypeName = getSubjectTopicType(Yii::app()->session['session_duoxueke_subject_id']);
- $gradeScoreArr = $classScoreArr = array();
- $gradeScoring = $classScoring = array();
- $typeNameArr = array();
- foreach($stuRs as $stuId => $rs){
- foreach ($rs as $k => $value){
- if(isset($topicLogicType[$value['type']]) && $topicLogicType[$value['type']] > 0){
- $type = $topicLogicType[$value['type']];
- $typeArr = explode('_',$type);
- if(count($typeArr) > 1){
- $type = $typeArr[0];
- }
- $typeNameArr[$type] = isset($logicTypeName[$type])?$logicTypeName[$type]:'';
- }else{
- $type = $value['type'];
- $typeNameArr[$type] = isset($typeName[$type])?$typeName[$type]:'';
- }
- if(!isset($gradeScoring[$type])){
- $gradeScoring[$type] = array();
- }
- $gradeScoring[$type][] = $value['scoring'];
- if(!isset($gradeScoreArr[$type])){
- $gradeScoreArr[$type] = 0;
- }
- $gradeScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
- if($paperId == $value['paper_id']){
- if(!isset($classScoring[$type])){
- $classScoring[$type] = 0;
- }
- $classScoring[$type] += $value['scoring'];
- if(!isset($classScoreArr[$type])){
- $classScoreArr[$type] = 0;
- }
- $classScoreArr[$type] += isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
- if(!isset($stuTypeWrong[$type])){
- $stuTypeWrong[$type] = 0;
- }
- if($value['is_right'] != 1){
- $stuTypeWrong[$type]++;
- }
- if(!isset($typeTopicNo[$type])){
- $typeTopicNo[$type] = array();
- }
- if(isset($topicNo[$value['topic_id']])){
- $typeTopicNo[$type][] = $topicNo[$value['topic_id']];
- }
- }
- }
- }
- //年级得分率
- foreach($gradeScoring as $type => $scorings){
- if(isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]){
- $gradeRate[$type] = round(array_sum($scorings)/$gradeScoreArr[$type],4) * 100;
- }else{
- $gradeRate[$type] = 0;
- }
- }
- //班级得分率
- foreach ($classScoring as $type => $scoring){
- if(isset($classScoreArr[$type]) && $classScoreArr[$type] > 0){
- $classRate[$type] = round($scoring/$classScoreArr[$type],4) * 100;
- }else{
- $classRate[$type] = 0;
- }
- }
- //题型对应题号排序
- foreach($typeTopicNo as $type => $nos){
- asort($nos);
- $typeTopicNo[$type] = array_unique($nos);
- }
- //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。
- foreach($classRate as $type => $rate){
- if($rate >= 85){
- $typeMasterDegree[$type] = 5;
- }elseif($rate < 85 && $rate >= 75){
- $typeMasterDegree[$type] = 4;
- }elseif($rate < 75 && $rate >= 65){
- $typeMasterDegree[$type] = 3;
- }elseif($rate < 65 && $rate >= 55){
- $typeMasterDegree[$type] = 2;
- }else{
- $typeMasterDegree[$type] = 1;
- }
- }
- $result['class_rate'] = $classRate;
- $result['grade_rate'] = $gradeRate;
- $result['stu_type_wrong'] = $stuTypeWrong;
- $result['type_topic_no'] = $typeTopicNo;
- $result['type_master_degree'] = $typeMasterDegree;
- $result['type_name_arr'] = $typeNameArr;
- return $result;
- }
- /**
- * 试题年级和班级得分率,答对和答错人数
- * @param $stuRs
- * @param $topicScore
- * @param $paperId
- * @return array
- */
- public function getTopicRateWrongPerson(&$stuRs,$topicScore,$paperId,&$stuIdsArr,$topicRelLarge){
- $gradeRate = $classRate = array();//班级和年级得分率
- $wrongStu = $rightStu = array();//答对答错人数
- $stuNormalIds = array();
- foreach($stuIdsArr as $stuIds){
- $stuNormalIds = array_merge($stuNormalIds,$stuIds);
- }
- $gradeScoring = $classScoring = array();
- $gradeScore = $classScore= array();
- $doneTopicNum = array();//每题做题总人数
- foreach($stuRs as $stuId => $rs){
- if(!inArray($stuId,$stuNormalIds)){
- continue;
- }
- foreach ($rs as $k => $value){
- if(isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0){
- $t_id = $topicRelLarge[$value['topic_id']];
- }else{
- $t_id = $value['topic_id'];
- }
- $t_score = isset($topicScore[$t_id])?$topicScore[$t_id]:0;
- if(!isset($gradeScoring[$t_id])){
- $gradeScoring[$t_id] = 0;
- }
- $gradeScoring[$t_id] += $value['scoring'];
- if(!isset($gradeScore[$t_id])){
- $gradeScore[$t_id] = 0;
- }
- $gradeScore[$t_id] += $t_score;
- if($paperId == $value['paper_id']){
- if(!isset($classScoring[$t_id])){
- $classScoring[$t_id] = 0;
- }
- $classScoring[$t_id] += $value['scoring'];
- if(!isset($classScore[$t_id])){
- $classScore[$t_id] = 0;
- }
- $classScore[$t_id] += $t_score;
- if(!isset($wrongStu[$t_id])){
- $wrongStu[$t_id] = array();
- }
- if($t_score != $value['scoring']){
- $wrongStu[$t_id][] = $stuId;
- }
- if(!isset($doneTopicNum[$t_id])){
- $doneTopicNum[$t_id] = array();
- }
- $doneTopicNum[$t_id][] = $stuId;
- }
- }
- }
- //年级得分率
- foreach($gradeScoring as $tId => $scorings){
- if(isset($gradeScore[$tId]) && $gradeScore[$tId] > 0){
- $gradeRate[$tId] = round($scorings/$gradeScore[$tId],4) * 100;
- }else{
- $gradeRate[$tId] = 0;
- }
- }
- //班级得分率
- foreach ($classScoring as $tId => $scoring){
- if(isset($classScore[$tId]) && $classScore[$tId] > 0){
- $classRate[$tId] = round($scoring/$classScore[$tId],4) * 100;
- }else{
- $classRate[$tId] = 0;
- }
- }
- //答错人数
- if($wrongStu){
- foreach($wrongStu as $key => $stuIds){
- $stuIds = array_unique($stuIds);
- $wrongStu[$key] = count($stuIds);
- if(isset($doneTopicNum[$key])){
- $_stuIds = array_unique($doneTopicNum[$key]);
- $rightStu[$key] = count($_stuIds) - $wrongStu[$key];
- }
- }
- }
- $result = array();
- $result['grade_rate'] = $gradeRate;
- $result['class_rate'] = $classRate;
- $result['wrong_stu'] = $wrongStu;
- $result['right_stu'] = $rightStu;
- return $result;
- }
- /**
- * 获取学生排名
- * @param $examId
- * @param $ptrInfo
- * @return array
- */
- private function getStudentOrder($examId,&$ptrInfo,&$stuIdsArr){
- $stuOrderArr = array();
- $stuScoring = array();
- foreach($ptrInfo as $value){
- if($examId == $value['exam_id']){
- $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
- if(inArray($value['student_id'],$stuIds)){
- $stuScoring[$value['student_id']] = (int)$value['scoring'];
- }
- }
- }
- $scoringArr = array_values($stuScoring);
- foreach($stuScoring as $stuId => $scoring){
- $stuOrderArr[$stuId] = $this->getOrder((int)$scoring,$scoringArr);
- }
- if($stuOrderArr){
- asort($stuOrderArr);
- }
- return $stuOrderArr;
- }
- /**
- * 获取排名
- * @param $ele
- * @param $arr
- * @return false|int|string
- */
- private function getOrder($ele,$arr){
- $orderRs = 0;
- if($arr){
- arsort($arr);
- $arr = array_values($arr);
- $index = array_search($ele,$arr);
- $orderRs = $index + 1;
- }
- return $orderRs;
- }
- /**
- * 整理题详情
- * @param $allApiInfo
- * @return mixed
- * @throws CException
- */
- public function getTopicDetail($topicBatches){
- $optionIndex=array('A','B','C','D','E','F','G','H','I','J','K');
- $topicDetails=array();
- foreach ($topicBatches AS $topic) {
- $topic=(object)$topic;
- $type = $topic->type_id;
- 6 == $type && $type =5; //6表示多空题,多空题也是5
- $topic->id = (string)$topic->id;
- $topicDetails[$topic->id]=array();
- $topicDetails[$topic->id]['is_large_topic']=isset($topic->is_large_topic)?$topic->is_large_topic:0;
- $topicDetails[$topic->id]['type']=$type;
- $topicDetails[$topic->id]['subject_id'] = $topic->subject_id;
- $topicDetails[$topic->id]['methods']='';//考点
- $topicDetails[$topic->id]['method_id_arr']='';//考点id数组
- $topicDetails[$topic->id]['kps']='';//知识点
- $topicDetails[$topic->id]['queBody'] =$this->topicProcess($topic->title);//题目详情
- $topicDetails[$topic->id]['options']='';
- $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode)?$topic->parse_video_qrcode:'';
- $topicDetails[$topic->id]['answer']=''; //每题的正确答案
- $topicDetails[$topic->id]['analysis']=$this->topicProcess($topic->parse_content);//答题解析
- $topicDetails[$topic->id]['teacher_tips']=$this->topicProcess($topic->teacher_tips);//名师点评
- $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree)?$topic->difficulty_degree:null;
- $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
- $_methods = array();
- $_method_id_arr = array();
- $_method_names = array();
- if ($topic->specials) {
- foreach ($topic->specials AS $_method) {
- $_method = (object)$_method;
- if ($_method->method_name) {
- $_methods[] = $_method->method_name;
- }
- if (isset($_method->method_id)) {
- $_method_id_arr[] = $_method->method_id;
- }
- if(isset($_method->method_id) && isset($_method->method_name)){
- $_method_names[$_method->method_id] = $_method->method_name;
- }
- }
- $topicDetails[$topic->id]['methods']=implode('|', array_unique($_methods));//考点
- $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
- $topicDetails[$topic->id]['method_names'] = $_method_names;
- }
- $_kps = array();
- if (isset($topic->kps) && $topic->kps) {
- foreach ($topic->kps as $_kp) {
- $_kp = (object)$_kp;
- if ($_kp->kp_name) {
- $_kps[$_kp->kp_id] = $_kp->kp_name;
- }
- }
- $topicDetails[$topic->id]['kps'] = $_kps;//考点
- }
- if($topic->type_id==1 || $topic->type_id==11){ //选择题有选项
- if ($topic->items) {
- if (isset($topic->items[0])) {
- $topic->items[0] = (object)$topic->items[0];
- if (isset($topic->items[0]->options)) {
- $options = $topic->items[0]->options;
- if ($options) {
- $_tmp_options = array();
- $correct_answer_arr = array();
- foreach ($options AS $_optionIndex => $_option) {
- $_option = (object)$_option;
- $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content);
- if($_option->option_correct){
- $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]);
- // $topicDetails[$topic->id]['answer']=topicProcess($optionIndex[$_optionIndex]);
- }
- }
- $topicDetails[$topic->id]['answer'] = implode(',',$correct_answer_arr);
- $_list_type= (int)$topic->items[0]->list_type;
- $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options,$_list_type);
- }
- }
- }
- }
- }else{
- if ($topic->items) {
- if (isset($topic->items[0])) {
- $topic->items[0] = (object)$topic->items[0];
- if (isset($topic->items[0]->options)) {
- $options = $topic->items[0]->options;
- if ($options) {
- $_answer = '';
- foreach ($options as $v) {
- $_option = (object)$v;
- if (trim($_answer) != ''){
- $_answer .= ' ; ';
- }
- $_answer .= $_option->option_content;
- }
- $topicDetails[$topic->id]['answer']=$this->topicProcess($_answer);
- }
- }
- }
- }
- }
- //大题的小题
- $topicDetails[$topic->id]['slave']=array();
- if(isset($topic->slave) && $topic->slave){
- $topicDetails[$topic->id]['answer'] = array();
- foreach($topic->slave as $slave){
- $slave = (object)$slave;
- $_slave = array();
- $_slave['topic_slave_id']=(string)$slave->topic_slave_id;
- $_slave['type']=$slave->topic_type;
- $_slave['methods']='';//考点
- $_slave['method_id_arr']='';//考点id数组
- $_slave['kps']='';//知识点
- $_slave['queBody'] =$this->topicProcess($slave->title);//题目详情
- $_slave['options']='';
- $_slave['answer']=''; //每题的正确答案
- // $_slave['analysis']=topicProcess($slave->parse_content);//答题解析
- // $_slave['teacher_tips']=topicProcess($slave->teacher_tips);//名师点评
- $_slave['difficulty_degree'] = isset($slave->difficulty_degree)?$slave->difficulty_degree:null;
- $_slave['difficulty'] = $slave->difficulty;
- if($slave->topic_type==1 || $slave->topic_type==11){ //选择题有选项
- if ($slave->items) {
- if (isset($slave->items)) {
- $slave->items = (object)$slave->items;
- if (isset($slave->items->options)) {
- $options = (object)$slave->items->options;
- if ($options) {
- $_tmp_options = array();
- $correct_answer_arr = array();
- foreach ($options AS $_optionIndex => $_option) {
- $_option = (object)$_option;
- $_tmp_options[$_optionIndex]=$this->topicProcess($_option->option_content);
- if($_option->option_correct){
- $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]);
- // $topicDetails[$slave->id]['answer']=topicProcess($optionIndex[$_optionIndex]);
- }
- }
- $_slave['answer'] = implode(',',$correct_answer_arr);
- $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
- $_list_type= (int)$slave->items->list_type;
- $_slave['options'] = $this->option_process($_tmp_options,$_list_type);
- }
- }
- }
- }
- }else{
- if ($slave->items) {
- if (isset($slave->items)) {
- $slave->items = (object)$slave->items;
- if (isset($slave->items->options)) {
- $options = (object)$slave->items->options;
- if ($options) {
- $_answer = '';
- foreach ($options as $v) {
- $_option = (object)$v;
- if (trim($_answer) != ''){
- $_answer .= ' ; ';
- }
- $_answer .= $_option->option_content;
- }
- $_slave['answer'] = $this->topicProcess($_answer);
- $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
- }
- }
- }
- }
- }
- $topicDetails[$topic->id]['slave'][] = $_slave;
- }
- }
- }
- return $topicDetails;
- }
- /**
- *对选项的处理
- * @param $options
- * @param $list_type
- * @return string
- */
- public function option_process($options,$list_type){
- $option_index=array('A','B','C','D','E','F','G','H','I','J');
- if($list_type==0) { //纵向排列,即1行1个
- // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
- $option_str="";
- foreach($options as $key=>$option){
- $option_str.="<li style='width:100%;'>$option_index[$key].$option</li>";
- }
- // $option_str.="</ul>";
- }elseif($list_type==1) { //横向排列,即1行4个
- // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
- $option_str="";
- foreach($options as $key=>$option){
- $option_str.="<li class='fl'>$option_index[$key].$option</li>";
- }
- // $option_str.="</ul>";
- }elseif($list_type==2){ //1行2个
- // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
- $option_str="";
- foreach($options as $key=>$option){
- if($key%2==0) {
- $option1=$options[$key];
- $option_str2="<li class='fl' style='width:50%;'>$option_index[$key].$option1</li>";
- $key1=$key+1;
- if(isset($options[$key1])){
- $option2=$options[$key1];
- $option_str2.="<li class='fl' style='width:50%;'>$option_index[$key1].$option2</li>";
- }
- $option_str.=$option_str2;
- }else{
- continue;
- }
- }
- // $option_str.="</ul>";
- }
- return $option_str;
- }
- public function topicProcess($html) {
- preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',$html,$arr);
- foreach($arr[0] as $v){
- $process_str=$this->img_process($v);
- $html = str_replace($v,$process_str,$html);
- }
- $html=preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si','',$html);
- $html=preg_replace('/<p\s*>/','',$html);
- $html=preg_replace('/<\/p>/','',$html);
- $html=preg_replace('/<br\/*>/','',$html);
- $html=preg_replace('/<big\s*>/','',$html);
- $html=preg_replace('/<\/big>/','',$html);
- $html=str_replace(" ",'',$html);
- return $html;
- }
- public function img_process($img){
- $widthArr = array();
- $heightArr = array();
- $width = '';
- $height = '';
- preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr);
- if ($widthArr) {
- $width = $this->length_process($widthArr);
- } else {
- preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr);
- if($widthArr) {
- $width = $this->length_process($widthArr);
- }
- }
- if ($width) {
- $width = "width=".$width;
- }
- preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr);
- if ($heightArr) {
- $height = $this->length_process($heightArr);
- } else {
- preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr);
- if($heightArr) {
- $height = $this->length_process($heightArr);
- }
- }
- if ($height) {
- $height = "height=".$height;
- }
- $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"<img ".$width." ".$height." $1 />",$img);
- return $return_img;
- }
- public function length_process($length_arr){
- $units = array(
- 'in' => 96,
- 'cm' => 28,
- 'mm' => 2.8,
- 'pt' => 1.33,
- 'pc' => 12,
- );
- $length = 0.6*$length_arr[1];
- $unit_keys = array_keys($units);
- if (isset($length_arr[2])) {
- //将直接连接单位改为 单位换算
- if(in_array($length_arr[2],$unit_keys)){
- $length = $length*$units[$length_arr[2]];
- }else {
- $length .= $length_arr[2];
- }
- }
- return $length;
- }
- /********************* 第三方教学宝结束 *********************/
- //导入线下考试成绩
- public function actionImport(){
- $examGroupId=Req::get('examgroupid');
- if (Yii::app()->request->getIsPostRequest()){
- ini_set('memory_limit','300M');
- $examGroupId=Req::post('examgroupid');
- $card=Req::post('card');
- if(!$examGroupId){
- Yii::app()->jump->error('请先创建考试');
- }
- if($card==1){
- $filed='student_card';
- }elseif($card==2){
- $filed='school_student_card';
- }else{
- Yii::app()->jump->error('考号类型不正确');
- }
- $uploader = new Uploader("upload/tmpDir/UploadStudentScore/{$this->schoolId}/");
- $uploader->allowTypes = array('xls','xlsx');
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if(!$file || !isset($file["error"]))
- Yii::app()->jump->error('请选择上传的Excel!');
- if($file["error"] != 0){
- switch($file["error"]){
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $result = true;
- $inputFileName = $file["src"];
- $semesterId = $this->semesterId;
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- // 去掉导航
- unset($sheetData[1]);
- if(!$sheetData){
- Yii::app()->jump->error('成绩数据不能为空');
- }
- $sheetData=array_values($sheetData);
- //读取考试信息
- $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();
- if(!$exam){
- Yii::app()->jump->error('考试ID不正确,请从考试列表点击上传成绩');
- }
- $tpl_data=json_decode($exam[0]['tpl_data'],true);
- if(!$tpl_data || !isset($tpl_data['totals']) || !isset($tpl_data['new_items'])){
- Yii::app()->jump->error('考试数据错误,请检查考试数据');
- }
- $checkData=$sheetData[0]; //提取一条数据用与校验
- if(empty($checkData['A']) || empty($checkData['B']) || empty($checkData['C'])){
- Yii::app()->jump->error('文件格式不正确,请检查后上传');
- }
- if(count($checkData)-$tpl_data['totals']!=3){
- Yii::app()->jump->error('成绩对应题目数量与考试设置不一致,请检查后上传');
- }
- //取得试卷topic
- $paperIds=array();
- foreach ($exam as $value){
- $paperIds[]=$value['paper_id'];
- }
- $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
- if(!$paper_topic_relation){
- Yii::app()->jump->error('试卷创建不成功,请重新检查');
- }
- $paper_topic_rs=array();
- foreach ($tpl_data['new_items'] as $key=>$value){
- $paper_topic_rs[$paper_topic_relation[$key]['topic_id']]=$value;
- $tpl_data['new_items'][$key]['topic_id']=$paper_topic_relation[$key]['topic_id'];
- }
- $studentCardAll=array();
- //更新student_paper_relation ,新增student_paper_topic_rs
- $sql='INSERT INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE ';
- $transaction = $this->sConn->beginTransaction();
- try{
- $error=array();
- $valueSql=array();
- foreach ($sheetData as $item){
- $studentCard=$item['B'];
- $studentName=$item['A'];
- $studentClass=$item['C'];
- if(!$studentCard || !$studentName || !$studentClass){
- $error[]='学生信息缺失,姓名:'.$studentName.',准考证号:'.$studentCard.',学生班级:'.$studentClass;
- continue;
- }
- if(in_array($studentCard,$studentCardAll)){
- $error[]='准考证号重复:'.$studentCard;
- continue;
- }
- $studentCardAll[]=$studentCard;
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where ".$filed."='".$studentCard."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $error[]='学生没有参加本次考试 :'.$studentCard;
- continue;
- }
- $studentId=$StudentPaperRelation['student_id'];
- $paper_id=$StudentPaperRelation['paper_id'];
- $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$studentId."' ")->queryRow();
- if(!$StudentInfo || $StudentInfo['realname']!=$studentName){
- $error[]='学生姓名和准考证号不对应 :'.$studentCard;
- continue;
- }
- $this->sConn->createCommand("delete from `student_paper_topic_rs` where student_id='".$studentId."' and paper_id='".$paper_id."' ")->execute();
- $topicScoreData=$item;
- unset($topicScoreData['A']);
- unset($topicScoreData['B']);
- unset($topicScoreData['C']);
- $topicScoreData=array_values($topicScoreData);
- $score_get=0;
- $lost_score=0;
- foreach($topicScoreData as $key=> $ts){
- if(!$ts){
- $ts=0;
- }
- $score=0;
- $is_right=1;
- if($ts>=$tpl_data['new_items'][$key]['score']){
- $score=$tpl_data['new_items'][$key]['score'];
- }else{
- $score=$ts;
- $lost_score+=($tpl_data['new_items'][$key]['score']-$ts);
- $is_right=0;
- }
- if(!$score){
- $score=0;
- }
- $score_get+=$score;
- $topic_id= $tpl_data['new_items'][$key]['topic_id'];
- // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
- // $uuid = current(current($uuid));
- $uuid =getUniqueId($this->schoolId);
- $valueSql[]=' ('.$uuid.','.$studentId.','.$paper_id.','.$topic_id.',1,'.$score.','.$is_right.') ';
- }
- $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";
- $updateSql.=" where student_id='".$studentId."' and paper_id='".$paper_id."' ";
- $this->sConn->createCommand($updateSql)->execute();
- }
- if($valueSql){
- $sql.=implode(',',$valueSql);
- $this->sConn->createCommand($sql)->execute();
- }
- Exam::model()->updateAll(array('status'=>1,'upload_status'=>2,'complete_time'=>time()),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- 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));
- $transaction->commit();
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$examGroupId,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
- if($error){
- // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
- $this->render('import_underline_error',array('data'=>$error));
- }else{
- Yii::app()->jump->error('导入成功');
- }
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error('成绩导入失败,请检查后重新');
- }
- }else{
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
- $data['subject']=$subject_exam_data;
- $data['exam_group_id']=$examGroupId;
- $data['printType']=2;
- $this->render('score_import',$data);
- }
- }
- //编辑第三方线下考试
- public function actionEditThirdUnderLine(){
- $examGroupId=Req::get('examgroupid'); //统考Id
- if(!$examGroupId){
- Yii::app()->jump->error('请从考试列表进入编辑');
- }
- $exam=new SExam();
- $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 ";
- $sql .=" join exam e on eg.exam_group_id=e.exam_group_id ";
- $sql.=" join paper p on p.exam_id=e.exam_id ";
- $sql.=" where e.exam_group_id=".$examGroupId;
- $examlist = $this->sConn->createCommand($sql)->queryAll();
- if(!$examlist){
- Yii::app()->jump->error('考试ID不正确');
- }
- $tpl_data=json_decode($examlist[0]['tpl_data'],true);
- $paperInfo=array(
- 'paper_name'=>$examlist[0]['name'],
- 'type' =>$examlist[0]['type'],
- 'teacher_id'=>$examlist[0]['teacher_id'],
- 'exam_date'=>$tpl_data['examDate'],
- );
- foreach ($examlist as $value){
- $paperInfo['class_id'][]=$value['class_id'];
- }
- //处理题型
- $topic_type_data=array();
- if(isset($tpl_data['new_items'])){
- foreach($tpl_data['new_items'] as $item){
- if(isset($topic_type_data[$item['logic_type']]['count'])){
- $topic_type_data[$item['logic_type']]['count']++;
- }else{
- $topic_type_data[$item['logic_type']]['count']=1;
- }
- $topic_type_data[$item['logic_type']]['score'][]=$item['score'];
- if(isset($topic_type_data[$item['logic_type']]['total_score'])){
- $topic_type_data[$item['logic_type']]['total_score']+=$item['score'];
- }else{
- $topic_type_data[$item['logic_type']]['total_score']=$item['score'];
- }
- }
- }
- $paperInfo['topic']=$topic_type_data;
- $printType = Req::get("type");
- if (empty($printType)) {
- $printType = '2';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "2":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $data['printType'] = $printType;
- // $coach_id = Yii::app()->session['coachInfo']['coach_id'];
- // $semester_id = Yii::app()->session['session_semester_id'];
- $coach_id = $this->coachId;
- $semester_id = $this->semesterId;
- // $teacher_data = Teacher::model()->findAll('coach_id=:coach_id',array(':coach_id'=>$coach_id));
- $criteria = new CDbCriteria();
- if(Yii::app()->session['session_duoxueke_subject_id']==3)
- {
- $criteria->addInCondition('subjects',$this->mathSubjectId);
- }else
- {
- if(Yii::app()->session['session_duoxueke_subject_id']==18){
- $criteria->addInCondition('subjects',array(12,13,14));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']==19){
- $criteria->addInCondition('subjects',array(15,16,17));
- }
- if(Yii::app()->session['session_duoxueke_subject_id']!=18 && Yii::app()->session['session_duoxueke_subject_id']!=19){
- $criteria->addCondition('subjects = '.Yii::app()->session['session_duoxueke_subject_id']);
- }
- }
- $criteria->addCondition('status = 0');
- $teacher_data = Teacher::model()->findAll($criteria);
- unset($criteria);
- $teacher_arr = array();
- if($teacher_data){
- $i = 0;
- foreach($teacher_data as $v){
- $teacher_arr[$i]['teacher_id'] = $v->teacher_id;
- $teacher_arr[$i]['teacher_name'] = $v->teacher_name;
- $i++;
- }
- }
- $data['teacher_arr'] = $teacher_arr;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- $teacherSubjectIds = array(3, 6);
- $teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用');
- $teacherSubjectMaterialIds = array();
- $teacherSubjectMaterialNames = array();
- foreach ($teacherSubjectIds as $teacherSubjectId) {
- $teacherSubjectMaterialIds[$teacherSubjectId] = array();
- $teacherSubjectMaterialNames[$teacherSubjectId] = array();
- $textbookTree = $this->apiPost('/textbook/tree', array(
- 'subjectId' => $teacherSubjectId,
- 'depth' => 3
- ));
- if (! $textbookTree) {
- $error[] = 'Brain textbook/tree error';
- } elseif (isset($textbookTree->error)) {
- $error[] = $textbookTree->error;
- } else {
- foreach ($textbookTree as $textbook) {
- if (isset($textbook->modules)) {
- foreach ($textbook->modules as $module) {
- if (isset($module->chapters)) {
- $teacherSubjectMaterialIds[$teacherSubjectId][] = $textbook->textbook_id;
- $teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
- }
- }
- }
- }
- }
- }
- //
- $data['teacherSubjectIds'] = $teacherSubjectIds;
- $data['teacherSubjectNames'] = $teacherSubjectNames;
- $data['teacherSubjectMaterialIds'] = $teacherSubjectMaterialIds;
- $data['teacherSubjectMaterialNames'] = $teacherSubjectMaterialNames;
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId,1);
- $data['subject']=$subject_exam_data;
- $data['examgroupid']=$examGroupId;
- $data['tpl_data']=$tpl_data;
- $data['printType']=2;
- $data['paper']=$paperInfo;
- $this->render('index_edit_underline',$data);
- }
- //导入线下考试成绩创建考试
- public function actionCreatethirdunderline(){
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $paperType = (int)Req::post("paperType");
- $teacherId = Req::post("teacherId");
- $textbookId = Req::post("textbookId");
- $subjectId = Req::post("subjectId");
- $examDate = Req::post("examDate");
- $ExamGroupId=Req::post('exam_group_id');
- $topic_data=htmlspecialchars_decode(Req::post('topic_data'));
- $tpl_index = $paperType;
- $result=array('status'=>0);
- if(!$topic_data){
- $error[] = '请设置试题数据';
- }
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(!in_array($paperType,array(0,1,2,1050))){
- $error[] = '请选择正确的试卷类型';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- if($error){
- //Yii::app()->jump->error(implode(',',$error));
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- //处理试题信息组装tpl_data
- $topic_data=json_decode($topic_data,true);
- $topic_num=1;
- $new_items=array();
- $totals=0;
- $total_score=0;
- foreach ($topic_data as $datum){
- $i=0;
- $totals+=$datum['topic_count'];
- $score=explode(',',$datum['topic_score']);
- while ($datum['topic_count']>0){
- if(!isset($score[$i])){
- $error[]='分数设置不正确';
- Yii::app()->jump->error(implode(',',$error));
- }
- $new_items[]=array(
- 'id'=>$topic_num,
- 'score'=>$score[$i],
- 'topic_type'=>7,
- 'logic_type'=>$datum['topic_type'],
- );
- $datum['topic_count']--;
- $topic_num++;
- $total_score+=$score[$i];
- $i++;
- }
- }
- $tplData['totals']=$totals;
- $tplData['total_score']=$total_score;
- $tplData['new_items']=$new_items;
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try{
- if(!$ExamGroupId){
- // $newExamGroupId = $this->UUID_SHORT();
- $newExamGroupId=getUniqueId($this->schoolId);
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`import_score_type`) "
- . "values (".$newExamGroupId.",".$teacherId.",0,0,1,2)";
- $this->sConn->createCommand($sql)->execute();
- }else{
- //删除原exam,paper,paper_topic_relation,class_exam_printer,student_paper_relation
- $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 ";
- $sql .=" join exam e on eg.exam_group_id=e.exam_group_id ";
- $sql.=" join paper p on p.exam_id=e.exam_id ";
- $sql.=" where e.exam_group_id=".$ExamGroupId;
- $examlist = $this->sConn->createCommand($sql)->queryAll();
- if(!$examlist){
- exit(json_encode(array('status'=>0,'msg'=>'考试ID不正确')));
- }
- $oldExamIds=array();
- $oldPaperIds=array();
- foreach($examlist as $item){
- $oldExamIds[]=$item['exam_id'];
- $oldPaperIds[]=$item['paper_id'];
- }
- if(!$oldExamIds || !$oldPaperIds){
- exit(json_encode(array('status'=>0,'msg'=>'考试数据错误')));
- }
- $this->sConn->createCommand("delete from exam where exam_id in(".implode(',',$oldExamIds).")")->execute();
- $this->sConn->createCommand("delete from paper where paper_id in(".implode(',',$oldPaperIds).")")->execute();
- $this->sConn->createCommand("delete from paper_topic_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute();
- $this->sConn->createCommand("delete from class_exam_printer where exam_id in(".implode(',',$oldExamIds).")")->execute();
- $this->sConn->createCommand("delete from student_paper_relation where paper_id in(".implode(',',$oldPaperIds).")")->execute();
- $this->sConn->createCommand("update exam_group set teacher_id='".$teacherId."' where exam_group_id='".$ExamGroupId."'")->execute();
- $newExamGroupId=$ExamGroupId;
- }
- $paperIds=array();
- foreach($classIds as $classId){
- //$newExamId = $this->UUID_SHORT();
- $newExamId=getUniqueId($this->schoolId);
- $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";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if($cardData['card_status']==0){
- $cardData['card_length'] = 8;
- if($this->schoolId >999){
- $cardData['card_length'] = 9;
- }
- }
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($tplData),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- //$newPaperId = $this->UUID_SHORT();
- $newPaperId=getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => $total_score,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $paperIds[]=$newPaperId;
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 1,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time' =>$time
- ));
- }
- }
- }
- //写入试题,关联信息
- foreach ($new_items as $key=>$item){
- $this->sConn->createCommand()->insert('topic', array(
- 'topic_type' =>7,
- 'topic_title' => '',
- 'folder_id' => '0',
- 'subject_id' => $subjectId,
- 'is_delete' =>1,
- 'creator_id' => $teacherId,
- 'updater_id' => $teacherId,
- 'is_word_topic'=>1,
- 'create_time' => time(),
- 'update_time' => time(),
- ));
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $topic_id=$last_insert_id['last_insert_id()'];
- $this->sConn->createCommand()->insert('topic_item', array(
- 'topic_id' => $topic_id,
- 'topic_type' => 7,
- 'topic_title' => ''
- ));
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $topic_id,
- 'mode' => 1,
- 'teacher_id' => $teacherId,
- 'paper_id' =>$paperIds[0]
- ));
- foreach($paperIds as $kp=>$p)
- {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $p,
- 'topic_id' => $topic_id,
- 'no' => $item['id'],
- 'order' => $item['id'],
- 'mode' => 1,
- 'type' => 7,
- 'score' =>$item['score']
- ));
- }
- }
- $transaction->commit();
- }catch (Exception $e){
- $transaction->rollBack();
- exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
- }
- }
- exit(json_encode(array('status'=>1,'msg'=>'保存成功')));
- //$this->redirect($this->createUrl('third/index?list_type=1'));
- }
- private function numToLetter($num){
- $index = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- return substr($index,$num,1);
- }
- // 英语上传试卷答案解析
- public function actionUploadEnglishPaper(){
- // $error['success'] = 123;
- // $error['message'] = '上传文件成功!';
- // var_dump($_FILES);exit;
- // echo json_encode($_FILES);exit();
- $exam_group_id = Req::post('examGroupId');
- $uploadOne = Req::post('uploadOne');
- $paper_exam = array();
- $paper_answer = array();
- $paper_exam_url = array();
- $paper_answer_url = array();
- $paper_exam_url_str = '';
- $paper_answer_url_str = '';
- $error['success'] = 0;
- if (empty($exam_group_id)) {
- $error['message'] = '考试id不存在!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($examInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }else{
- $exam_name = $examInfo['name'];
- $tplData = json_decode($examInfo["tpl_data"], true);
- //考试时间
- if(isset($tplData['examDate']))
- {
- $exam_time = strtotime($tplData["examDate"]);
- }else{
- $exam_time = 0;
- }
- }
- $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($thirdSheet)) {
- $error['message'] = '尚未上传答题卡!';
- echo json_encode($error);exit();
- }
- if (empty($_FILES)) {
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }else{
- foreach($_FILES as $k=>$v){
- if(isset($v) && !empty($v)){
- if(!isset($v['size']) || $v['size'] >= 8388608){
- $error['message'] = '文件超过8M!';
- echo json_encode($error);exit();
- }
- if(!isset($v['name']) || !in_array(substr($v['name'],strrpos($v['name'],'.')+1),array('doc','docx','pdf','bmp','jpg','jpeg','png'))){
- $error['message'] = '文件格式不正确!';
- echo json_encode($error);exit();
- }
- if(strpos($k,'paper_answer') !== false){
- $paper_answer[] = $v;
- }
- if(strpos($k,'paper_exam') !== false){
- $paper_exam[] = $v;
- }
- }
- }
- if(empty($paper_answer) && empty($paper_exam)){
- $error['message'] = '尚未上传试卷答案!';
- echo json_encode($error);exit();
- }else{
- // echo json_encode($paper_exam);exit();
- krsort($paper_answer);
- krsort($paper_exam);
- // echo json_encode($paper_exam);exit();
- // 保存上传文件至服务器
- $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/';
- $pathName1 = 'upload/tmpDir/english_paper/'. date('Y') .'/'. date('m') . '/';
- if (!file_exists($pathName)) {
- mkdir($pathName, 0777, true);
- }
- $ucloud = new HuaweiCloud();
- // echo json_encode($paper_exam);exit();
- foreach($paper_exam as $k=>$v){
- // $v['name']=iconv("UTF-8", "gb2312", $v['name']);
- $fileName = $exam_group_id.$v['name'];
- $extName = substr($v['name'],strrpos($v['name'],'.'));
- if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) {
- $error['message'] = '上传试卷失败!';
- echo json_encode($error);exit();
- }else{
- $meg = $ucloud->putFile('zsyas2/englishPaper/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName);
- if($meg['status'] == 0){
- $error['message'] = $meg['msg'];
- echo json_encode($error);exit();
- }else{
- $url = $meg['url'];
- $url = str_replace("%2F","/",$url);
- $paper_exam_url[] = $url;
- $paper_exam_url_str = $url;
- }
- }
- @unlink($pathName1.$fileName);
- }
- foreach($paper_answer as $k=>$v){
- // $v['name']=iconv("UTF-8", "gb2312", $v['name']);
- $fileName = $exam_group_id.$v['name'];
- $extName = substr($v['name'],strrpos($v['name'],'.'));
- if (!move_uploaded_file($v['tmp_name'], $pathName.$fileName)) {
- $error['message'] = '上传试卷失败!';
- echo json_encode($error);exit();
- }else{
- $meg = $ucloud->putFile('zsyas2/englishPaperAnswer/'.$this->schoolId.'/'.$exam_group_id.'/'.time().mt_rand().$extName,$pathName1.$fileName);
- if($meg['status'] == 0){
- $error['message'] = $meg['msg'];
- echo json_encode($error);exit();
- }else{
- $url = $meg['url'];
- $url = str_replace("%2F","/",$url);
- $paper_answer_url[] = $url;
- $paper_answer_url_str = $url;
- }
- }
- @unlink($pathName1.$fileName);
- }
- }
- }
- $error['success'] = 1;
- $error['message'] = '发送成功!';
- $error['uploadOne'] = $uploadOne;
- $error['answer_url'] = $paper_answer_url_str;
- $error['paper_url'] = $paper_exam_url_str;
- echo json_encode($error);exit();
- }
- public function actionUploadEnglishPaperInsert(){
- $exam_group_id = Req::post('examGroupId');
- $paper_answer_url = Req::post('answerUrl');
- $paper_exam_url = Req::post('paperUrl');
- $printTime = (int)Req::post('printTime');
- if($paper_answer_url && $paper_exam_url){
- foreach($paper_answer_url as $k=>$v){
- if(!$v || empty($v)){
- unset($paper_answer_url[$k]);
- }
- }
- foreach($paper_exam_url as $k=>$v){
- if(!$v || empty($v)){
- unset($paper_answer_url[$k]);
- }
- }
- ksort($paper_answer_url);
- ksort($paper_exam_url);
- //关联third_multi_template
- $sql = "select count(*) count from third_multi_template where exam_group_id = {$exam_group_id}";
- $count = $this->sConn->createCommand($sql)->queryAll();
- if($count[0]['count']){
- $this->sConn->createCommand("delete from `third_multi_template` where exam_group_id = '{$exam_group_id}'")->execute();
- }
- $this->sConn->createCommand()->insert('third_multi_template',array(
- 'exam_group_id' => $exam_group_id,
- 'semester_id' => $this->semesterId,
- 'template_src' => implode(',',$paper_exam_url),
- 'topic_upload' => 1,
- 'answer_upload' => 0,
- 'template_type' => 1,
- 'update_time' => 0,
- 'create_time' => time()
- ));
- $this->sConn->createCommand()->insert('third_multi_template',array(
- 'exam_group_id' => $exam_group_id,
- 'semester_id' => $this->semesterId,
- 'template_src' => implode(',',$paper_answer_url),
- 'topic_upload' => 0,
- 'answer_upload' => 1,
- 'template_type' => 2,
- 'update_time' => 0,
- 'create_time' => time()
- ));
- $examInfo = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($examInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }else{
- $exam_name = $examInfo['name'];
- $tplData = json_decode($examInfo["tpl_data"], true);
- //考试时间
- if(isset($tplData['examDate']))
- {
- $exam_time = strtotime($tplData["examDate"]);
- }else{
- $exam_time = 0;
- }
- }
- $jsonArr = array();
- $jsonArr['exam_name'] = $exam_name;
- $jsonArr['school_id'] = $this->schoolId;
- $jsonArr['exam_group_id'] = $exam_group_id;
- $jsonArr['exam_time'] = $exam_time;
- $jsonArr['topic_original'] = $paper_exam_url;
- $jsonArr['answer_parse_original'] = $paper_answer_url;
- $jsonArr['coach_name'] = isset(Yii::app()->session['coachInfo']['real_name'])?Yii::app()->session['coachInfo']['real_name']:'';
- $jsonArr['print_time'] = $printTime;
- $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr));
- $resultArr = json_decode($result,true);
- if($resultArr['status'] == 1){
- $sql = "select exam_id from exam where exam_group_id = '{$exam_group_id}'";
- $examAll = $this->sConn->createCommand($sql)->queryAll();
- $examArr = array();
- if($examAll){
- foreach($examAll as $k=>$v){
- $examArr[] = $v['exam_id'];
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- $this->sConn->createCommand("update paper set is_labelled = 3 where exam_id in (".implode(',',$examArr).")")->execute();
- $transcation->commit();
- }
- catch (Exception $e)
- {
- $transcation->rollback();
- $error['message'] = '更新失败!';
- echo json_encode($error);exit();
- }
- }else{
- $error['message'] = '考试信息错误!';
- echo json_encode($error);exit();
- }
- }else{
- $error['message'] = $resultArr['message'];
- echo json_encode($error);exit();
- }
- }else{
- $error['message'] = '上传失败!';
- echo json_encode($error);exit();
- }
- $this->schoolManager->saveExamProcess($exam_group_id,1,time());
- $error['success'] = 1;
- $error['message'] = '上传成功!';
- echo json_encode($error);exit();
- }
- //第三方发送协助
- public function actionAssist(){
- Url::clean();
- $exam_group_id = Req::get("exam_group_id");
- //读取考试数据
- $examModel=new SExam();
- $examInfo=$examModel->getExamByGroupId($exam_group_id);
- if(!$examInfo) Yii::app()->jump->error('考试参数异常');
- $tpl_data=$examInfo[0]['tpl_data'];
- $tplData=json_decode($tpl_data,true);
- //读取答题卡设置
- $thirdAnswerSheet = $this->sConn->createCommand("select * from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow();
- //判断上传状态
- $uploadExamInfo=SThirdMultiTemplate::model()->getStatusByExamGroupId($exam_group_id);
- $uploadStatus=0;
- if($uploadExamInfo){
- if(isset($uploadExamInfo[1])){
- if($uploadExamInfo[1]['topic_upload']==1){
- $uploadStatus+=1;
- }
- }
- if(isset($uploadExamInfo[2])){
- if($uploadExamInfo[2]['answer_upload']==1){
- $uploadStatus+=3;
- }
- }
- }
- // debug($tplData);
- //判断任务发送情况
- $task= ATask::model()->findByPk($exam_group_id);
- $task = json_decode(CJSON::encode($task),TRUE);
- if($task){
- if($task['operator']){
- $task['user']=AssistUser::model()->findByPk($task['operator']);
- }
- //答题卡任务耗时
- if($task['ast_apply_time']){
- if($task['answer_sheet_task']>2){
- if($task['ast_update_time'] && ($task['ast_update_time']-$task['ast_apply_time'])>0){
- $task['AstConsuming']=$this->consuming($task['ast_update_time'],$task['ast_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }elseif($task['answer_sheet_task']==2){
- if($task['ast_apply_time'] && (time()-$task['ast_apply_time'])>0){
- $task['AstConsuming']=$this->consuming(time(),$task['ast_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }
- }else{
- $task['AstConsuming']='--';
- }
- //试卷任务耗时
- if($task['ppt_apply_time']){
- if($task['paper_task']>2){
- if($task['ppt_update_time'] && ($task['ppt_update_time']-$task['ppt_apply_time'])>0){
- $task['PptConsuming']=$this->consuming($task['ppt_update_time'],$task['ppt_apply_time']);
- }else{
- $task['PptConsuming']='--';
- }
- }elseif($task['paper_task']==2){
- if($task['ppt_apply_time'] && (time()-$task['ppt_apply_time'])>0){
- $task['PptConsuming']=$this->consuming(time(),$task['ppt_apply_time']);
- }else{
- $task['PptConsuming']='--';
- }
- }
- }else{
- $task['PptConsuming']='--';
- }
- //答案解析任务耗时
- if($task['pat_apply_time']){
- if($task['parse_task']>2){
- if($task['pat_update_time'] && ($task['pat_update_time']-$task['pat_apply_time'])>0){
- $task['PatConsuming']=$this->consuming($task['pat_update_time'],$task['pat_apply_time']);
- }else{
- $task['PatConsuming']='--';
- }
- }elseif($task['parse_task']==2){
- if($task['pat_apply_time'] && (time()-$task['pat_apply_time'])>0){
- $task['PatConsuming']=$this->consuming(time(),$task['pat_apply_time']);
- }else{
- $task['PatConsuming']='--';
- }
- }
- }else{
- $task['PatConsuming']='--';
- }
- }
- //读取试题结构
- if(isset($tplData['new_items'])){
- $items=array();
- foreach ($tplData['new_items'] as $item){
- if(isset($item['alias'])){
- $items[$item['topic_type']]['no'][]=$item['alias'];
- }else{
- $items[$item['topic_type']]['no'][]=$item['id'];
- }
- }
- $tplData['items']=$items;
- }
- $data['exam_name']=$examInfo[0]['name'];
- $data['subject']=Yii::app()->params['subjectId'][$examInfo[0]['subject_id']];
- $data['tpl_data']=$tplData;
- $data['task']=$task;
- //debug($tplData);
- $data['exam_group_id']=$exam_group_id;
- if($thirdAnswerSheet){
- $data['isAnswerCard']=1;
- }else{
- $data['isAnswerCard']=0;
- }
- $this->render('assist',$data);
- }
- //发送答题卡任务
- public function actionSendTask(){
- Url::clean();
- $exam_group_id = Req::post("examGroupId");
- $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析
- $msg['success'] = 0;
- $taskModel=new ATask();
- //判断学管任务数量
- $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();
- if($allTask && $allTask['count']>5){
- $msg['message'] = '您已超过5场考试任务为处理完成,操作过于频繁哦!';
- exit(json_encode($msg));
- }
- //验证设置
- $setting=AssistSetting::model()->getAssistSetting();
- if($setting){
- if($setting['cutting_task']==0){
- $msg['message'] = '系统后台暂不接受协助任务,请稍后再试,谢谢!';
- exit(json_encode($msg));
- }elseif($setting['open_cutting_upper_limit'] && $allTask['count']>$setting['cutting_task_upper_limit_num']){
- $msg['message'] = '系统后台排队任务过多,请稍后再试,谢谢!';
- exit(json_encode($msg));
- }
- }
- //拼接mysigninfo
- $mySignInfo='userid='.$this->coachId.'&session='.Yii::app()->request->cookies['appLoginSessionId'].'&sig='.Yii::app()->request->cookies['loginSig'].'&time='.Yii::app()->request->cookies['loginTime'];
- if($sendType==1){
- $imgArr = Req::post("imgArr");
- $paperDoc = Req::post("paperDoc");
- $card_type = Req::post("cardType");
- $paperDocTitle = Req::post("paperDocTitle");
- $answer_card_remark = Req::post("answerCardRemark");
- if(!$imgArr || !is_array($imgArr)){
- $msg['message'] = '请上传答题卡!';
- exit(json_encode($msg));
- }
- if(!$paperDoc){
- $msg['message'] = '请上传试卷文件!';
- exit(json_encode($msg));
- }
- $examModel=new SExam();
- $examInfo=$examModel->getExamByGroupId($exam_group_id);
- if(!$examInfo){
- $msg['message'] = '未找到考试信息!';
- exit(json_encode($msg));
- }
- $sheetId=0;
- //读取答题卡设置
- $thirdAnswerSheet = $this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id = ".$exam_group_id)->queryRow();
- if($thirdAnswerSheet){
- $sheetId=$thirdAnswerSheet['sheet_id'];
- }
- $time=time();
- //读取任务记录
- //$task=$taskModel->getTaskByExamGroupId($exam_group_id);
- $task=$taskModel->findByPk($exam_group_id);
- if(!$task){
- $tpl_data=$examInfo[0]['tpl_data'];
- $tplData=json_decode($tpl_data,true);
- $tplIndex=$examInfo[0]['tpl_index'];
- //学校信息
- $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
- $taskModel->exam_group_id=$exam_group_id;
- $taskModel->exam_name=$examInfo[0]['name'];
- $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
- $taskModel->school_id=$this->schoolId;
- $taskModel->school_name=$schoolInfo['school_name'];
- $taskModel->school_address=$schoolInfo['address'];
- $taskModel->exam_date=$tplData['examDate'];
- $taskModel->coach_id=$this->coachId;
- if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
- $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
- }else{
- $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
- }
- $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
- $taskModel->my_sign_info=$mySignInfo;
- $taskModel->create_time=$time;
- $taskModel->update_time=$time;
- $taskModel->answer_sheet_task=1;
- $taskModel->ast_create_time=$time;
- $taskModel->ast_update_time=$time;
- $taskModel->answer_card_img=implode(',',$imgArr);
- $taskModel->paper_file_img=$paperDoc;
- $taskModel->paper_file_title=$paperDocTitle;
- $taskModel->answer_card_mark=$answer_card_remark;
- $taskModel->number_type=$card_type;
- $taskModel->sheet_id=$sheetId;
- $taskModel->tpl_index=$tplIndex;
- $taskModel->dsn=$this->sConn->connectionString;
- $taskModel->database_user=$this->sConn->username;
- $taskModel->database_password=$this->sConn->password;
- if($taskModel->save()){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }else{
- if($task['answer_sheet_task']==1 || $task['answer_sheet_task']==2){
- $msg['message'] = '不能重复发送协助任务!';
- exit(json_encode($msg));
- }
- $taskStatus=1;
- if($task['operator']!=0){
- $taskStatus=2;
- }
- $taskStatus=1;
- $applyTime=0;
- if($task['operator']!=0){
- $taskStatus=2;
- $applyTime=$time;
- }
- $updateArr=array(
- 'update_time'=>$time,
- 'answer_sheet_task'=>$taskStatus,
- 'ast_create_time'=>$time,
- 'ast_update_time'=>$time,
- 'ast_apply_time'=>$applyTime,
- 'paper_file_img'=>$paperDoc,
- 'paper_file_title'=>$paperDocTitle,
- 'answer_card_img'=>implode(',',$imgArr),
- 'number_type'=>$card_type,
- 'sheet_id'=>$sheetId,
- 'answer_card_mark'=>$answer_card_remark
- );
- if($taskModel->updateTask($exam_group_id,$updateArr)){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }
- }elseif($sendType==2){
- //试卷任务
- $imgArr = Req::post("imgArr");
- $paperRemark = Req::post("paperRemark");
- if(!$imgArr || !is_array($imgArr)){
- $msg['message'] = '请上传答题卡!';
- exit(json_encode($msg));
- }
- $examModel=new SExam();
- $examInfo=$examModel->getExamByGroupId($exam_group_id);
- if(!$examInfo){
- $msg['message'] = '未找到考试信息!';
- exit(json_encode($msg));
- }
- $time=time();
- $taskModel=new ATask();
- //读取任务记录
- $task=$taskModel->findByPk($exam_group_id);
- if(!$task){
- $tpl_data=$examInfo[0]['tpl_data'];
- $tplData=json_decode($tpl_data,true);
- $tplIndex=$examInfo[0]['tpl_index'];
- //学校信息
- $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
- $taskModel->exam_group_id=$exam_group_id;
- $taskModel->exam_name=$examInfo[0]['name'];
- $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
- $taskModel->school_id=$this->schoolId;
- $taskModel->school_name=$schoolInfo['school_name'];
- $taskModel->school_address=$schoolInfo['address'];
- $taskModel->exam_date=$tplData['examDate'];
- $taskModel->coach_id=$this->coachId;
- if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
- $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
- }else{
- $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
- }
- $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
- $taskModel->create_time=$time;
- $taskModel->update_time=$time;
- $taskModel->my_sign_info=$mySignInfo;
- $taskModel->paper_task=1;
- $taskModel->ppt_create_time=$time;
- $taskModel->ppt_update_time=$time;
- $taskModel->paper_img=implode(',',$imgArr);
- $taskModel->paper_mark=$paperRemark;
- $taskModel->dsn=$this->sConn->connectionString;
- $taskModel->database_user=$this->sConn->username;
- $taskModel->database_password=$this->sConn->password;
- $taskModel->tpl_index=$tplIndex;
- if($taskModel->save()){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }else{
- if($task['paper_task']==1 || $task['paper_task']==2){
- $msg['message'] = '不能重复发送协助任务!';
- exit(json_encode($msg));
- }
- $taskStatus=1;
- $applyTime=0;
- if($task['operator']!=0){
- $taskStatus=2;
- $applyTime=$time;
- }
- $updateArr=array(
- 'update_time'=>$time,
- 'paper_task'=>$taskStatus,
- 'ppt_create_time'=>$time,
- 'ppt_apply_time'=>$applyTime,
- 'ppt_update_time'=>$time,
- 'paper_img'=>implode(',',$imgArr),
- 'paper_mark'=>$paperRemark,
- );
- if($taskModel->updateTask($exam_group_id,$updateArr)){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }
- }elseif($sendType==3){
- //答案解析任务
- $imgArr = Req::post("imgArr");
- $parseRemark = Req::post("parseRemark");
- if(!$imgArr || !is_array($imgArr)){
- $msg['message'] = '请上传答题卡!';
- exit(json_encode($msg));
- }
- $examModel=new SExam();
- $examInfo=$examModel->getExamByGroupId($exam_group_id);
- if(!$examInfo){
- $msg['message'] = '未找到考试信息!';
- exit(json_encode($msg));
- }
- $tplIndex=$examInfo[0]['tpl_index'];
- $time=time();
- $taskModel=new ATask();
- //读取任务记录
- $task=$taskModel->findByPk($exam_group_id);
- if(!$task){
- $tpl_data=$examInfo[0]['tpl_data'];
- $tplData=json_decode($tpl_data,true);
- //学校信息
- $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
- $taskModel->exam_group_id=$exam_group_id;
- $taskModel->exam_name=$examInfo[0]['name'];
- $taskModel->subject_id=Yii::app()->session['session_duoxueke_subject_id'];
- $taskModel->school_id=$this->schoolId;
- $taskModel->school_name=$schoolInfo['school_name'];
- $taskModel->school_address=$schoolInfo['address'];
- $taskModel->exam_date=$tplData['examDate'];
- $taskModel->coach_id=$this->coachId;
- if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
- $taskModel->coach_name=Yii::app()->session['coachInfo']['real_name'];
- }else{
- $taskModel->coach_name=Yii::app()->session['coachInfo']['coach_name'];
- }
- $taskModel->coach_mobile=Yii::app()->session['coachInfo']['telephone'];
- $taskModel->create_time=$time;
- $taskModel->update_time=$time;
- $taskModel->my_sign_info=$mySignInfo;
- $taskModel->parse_task=1;
- $taskModel->pat_create_time=$time;
- $taskModel->pat_update_time=$time;
- $taskModel->parse_img=implode(',',$imgArr);
- $taskModel->parse_mark=$parseRemark;
- $taskModel->tpl_index=$tplIndex;
- $taskModel->dsn=$this->sConn->connectionString;
- $taskModel->database_user=$this->sConn->username;
- $taskModel->database_password=$this->sConn->password;
- if($taskModel->save()){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }else{
- if($task['parse_task']==1 || $task['parse_task']==2){
- $msg['message'] = '不能重复发送协助任务!';
- exit(json_encode($msg));
- }
- $taskStatus=1;
- $applyTime=0;
- if($task['operator']!=0){
- $taskStatus=2;
- $applyTime=$time;
- }
- $updateArr=array(
- 'update_time'=>$time,
- 'parse_task'=>$taskStatus,
- 'pat_create_time'=>$time,
- 'pat_apply_time'=>$applyTime,
- 'pat_update_time'=>$time,
- 'parse_img'=>implode(',',$imgArr),
- 'parse_mark'=>$parseRemark
- );
- if($taskModel->updateTask($exam_group_id,$updateArr)){
- $msg['success'] = 1;
- $msg['message'] = '发送成功!';
- exit(json_encode($msg));
- }
- }
- }
- }
- //撤消任务
- public function actionUndo(){
- Url::clean();
- $exam_group_id = Req::post("examGroupId");
- $sendType = Req::post("sendType"); //任务类型1答题卡2试卷3答案解析
- $msg['success']=0;
- $examModel=new SExam();
- $examInfo=$examModel->getExamByGroupId($exam_group_id);
- if(!$examInfo){
- $msg['message'] = '未找到考试信息!';
- exit(json_encode($msg));
- }
- $time=time();
- $taskModel=new ATask();
- //读取任务记录
- $task=$taskModel->findByPk($exam_group_id);
- $filed='';
- $timeFiled='';
- switch ($sendType){
- case 1:
- $filed='answer_sheet_task';
- $timeFiled='ast_update_time';
- break;
- case 2:
- $filed='paper_task';
- $timeFiled='ppt_update_time';
- break;
- case 3:
- $filed='parse_task';
- $pat_update_time='ast_update_time';
- break;
- }
- if(!$filed){
- $msg['message'] = '参数异常!';
- exit(json_encode($msg));
- }
- if($task->$filed==2){
- $msg['message'] = '该任务已受理,不可撤回,谢谢!';
- exit(json_encode($msg));
- }elseif($task->$filed==3){
- $msg['message'] = '该任务已完成,谢谢!';
- exit(json_encode($msg));
- }else{
- if($taskModel->updateAll(array($filed=>4,'update_time'=>$time,$timeFiled=>$time),'exam_group_id=:eid',array(':eid'=>$exam_group_id))){
- $msg['success']=1;
- $msg['message'] = '撤消成功!';
- exit(json_encode($msg));
- }
- }
- }
- //上传图片
- public function actionUpload(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['paperFile']) || !isset($_FILES['paperFile']['size']) || $_FILES['paperFile']['size'] > 52428800) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- if (Yii::app()->request->getIsPostRequest()) {
- //FIXME 20191202 ucloud
- // 保存上传文件至服务器
- $pathName = dirname(dirname(dirname(__FILE__)))."/upload/tmpDir/UploadAssistFile/{$this->schoolId}/". date('Y/m/d/');
- if (!file_exists($pathName)) {
- mkdir($pathName, 0777, true);
- }
- $error['success'] = 0;
- $ucloud = new HuaweiCloud();
- $fileName = $_FILES['paperFile']['name'];
- $fileName = iconv("UTF-8", "gb2312", $fileName);
- $extName = substr($fileName,strrpos($fileName,'.'));
- if (!move_uploaded_file($_FILES['paperFile']['tmp_name'], $pathName.$fileName)) {
- $error['message'] = '上传失败!';
- echo json_encode($error);exit();
- }else{
- $meg = $ucloud->putFile('zsyas2/third/'.$this->schoolId.'/'.time().mt_rand().$extName,$pathName.$fileName);
- if($meg['status'] == 0){
- $error['message'] = $meg['msg'];
- echo json_encode($error);exit();
- }else{
- $url = $meg['url'];
- $url = str_replace("%2F","/",$url);
- }
- }
- @unlink($pathName.$fileName);
- $error['success'] = 1;
- $error['message'] = '上传成功!';
- $error['src']=$url;
- $error['name']=$_FILES['paperFile']["name"];
- echo json_encode($error);exit();
- }
- }
- //计算耗时
- public function consuming($now,$time){
- $return='';
- $date=floor(($now-$time)/86400);
- if($date){
- $return.=$date.'天';
- }
- $hour=floor(($now-$time)%86400/3600);
- if($hour){
- $return.=$hour.'小时';
- }
- $minute=floor((($now-$time)%86400)%3600/60);
- if($minute){
- $return.=$minute.'分种';
- }
- $second=floor(($now-$time)%86400%3600%60);
- if($second){
- $return.=$second.'秒';
- }
- return $return;
- }
- //客户端加载未上传学生列表
- public function actionNotUploadedStudent(){
- $eid = Req::get("examgroupid");
- $page =Req::get("page");
- $PageLimit=10;
- if(!$page) $page=1;
- $examInfo=$this->schoolManager->getExamsByExamGroupId($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $examIds=array();
- foreach($examInfo as $val){
- $examIds[]=$val['exam_id'];
- }
- $result=array();
- $rs=$this->schoolManager->getStudentByExamIds($examIds,$page,$PageLimit);
- if($rs){
- foreach($rs['list'] as $key =>$val){
- $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow();
- if($StudentInfo){
- $rs['list'][$key]['realname']=$StudentInfo['realname'];
- }
- }
- }
- $rs['examgroupid']=$eid;
- $this->render('not_upload',$rs);
- }
- public function actionDownloadStudent()
- {
- $eid = Req::get("examgroupid");
- $examInfo=$this->schoolManager->getExamsByExamGroupId($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $examIds=array();
- foreach($examInfo as $val){
- $examIds[]=$val['exam_id'];
- }
- $data=$this->schoolManager->getAllStudentByExamIds($examIds);
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("未上传学生")
- ->setSubject("未上传学生")
- ->setDescription("未上传学生")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45);
- $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '序号')
- ->setCellValue('B1', '姓名')
- ->setCellValue('C1', '系统准考证号');
- $i = 2;
- foreach($data as $v)
- {
- $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, ($i-1));
- $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['realname']);
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('C' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
- $i = $i + 1;
- }
- $objPHPExcel->getActiveSheet()->setTitle('未上传学生列表');
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header('Content-Type:application/vnd.ms-excel');
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="未上传学生列表.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- }
- //修改第三方考试信息
- public function actionModifyThirdExam(){
- if (Yii::app()->request->getIsPostRequest()){
- $exam_group_id = Req::post("examGroupId");
- $type=Req::post('type');
- $name=Req::post('examName');
- $examDate=Req::post('examDate');
- $paperType=Req::post('paperType');
- $relationAnswerCard=false;
- $transaction = $this->sConn->beginTransaction();
- $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_data)
- {
- Yii::app()->jump->error('非法试卷!');
- }
- @$tplData=json_decode($exam_data['tpl_data'],true);
- if(!$tplData){
- Yii::app()->jump->error('非法试卷!');
- }
- if(!matchStrChar($name)){
- Yii::app()->jump->error('考试名称不能包含特殊字符!');
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data['status']==2){
- $examSql="update `exam` set `name`='".$name."' ";
- $examSql.=" where exam_group_id='".$exam_group_id."'";
- $this->sConn->createCommand($examSql)->execute();
- $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
- if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){
- updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
- }
- $this->redirect($this->createUrl('print/index'));
- }
- //是否修改在线答题卡
- $text=Req::post("timu");
- if($text){
- //处理答题卡数据
- $relationAnswerCard=true;
- $name = Req::post("title");
- $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
- $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
- $post = json_decode($text,true);
- $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
- $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
- $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
- $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
- $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
- $subject_id=$this->subjectId;
- if(!$text || !$name || !$sheet_answer || !$sheet_score){
- $error['message'] = '题目参数错误';
- echo json_encode($error);exit();
- }
- if(!$positionJson){
- $error['message'] = '定位信息异常';
- echo json_encode($error);exit();
- }
- //上传答题卡相关文件
- $files=$this->uploadAnswerCardPdf($exam_group_id,$positionJson,$pdfUrl);
- $sheet_score_array = json_decode($sheet_score, 1);
- if (!$sheet_score_array) {
- $error['success']=0;
- $error['message'] = '上传失败,未设置分数!';
- echo json_encode($error);exit();
- }
- $score_num = count($sheet_score_array);
- if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) {
- $error['success']=0;
- $error['message'] = '上传失败,设置分数或设置题号有误!';
- echo json_encode($error);exit();
- }
- $tplData=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData);
- }
- try{
- $tplData['examDate']=$examDate;
- if($relationAnswerCard){
- $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- $topic_data = $this->get_topic_folder();
- $topic_ids=array();
- $examIds=array();
- $paperIds=array();
- $examData=$this->schoolManager->getExamsByExamGroupId($exam_group_id);
- foreach ($examData as $val){
- $examIds[]=$val['exam_id'];
- }
- $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id in(".implode(',',$examIds).")")->queryAll();
- foreach ($paperData as $val){
- $paperIds[]=$val['paper_id'];
- }
- $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id ='{$paperData[0]['paper_id']}'")->qeuryAll();
- foreach ($paperTopic as $item){
- $topic_ids[]=$item['topic_id'];
- }
- //判断原答题卡
- $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();
- if($thirdAnswerSheet){
- //删除数据
- $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
- $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id );
- }
- foreach($select_info['content'] as $k=>$v)
- {
- $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
- $zsytkTopicType=$_topic_type;
- if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
- $this->sConn->createCommand()->insert('topic', array(
- 'topic_type' =>$zsytkTopicType ,
- 'topic_title' => '',
- 'folder_id' => $topic_data['folder_id'],
- 'subject_id' => $subject_id,
- 'is_delete' =>0,
- 'creator_id' => $exam_data['teacher_id'],
- 'updater_id' => $exam_data['teacher_id'],
- 'is_word_topic'=>1,
- 'create_time' => time(),
- 'update_time' => time(),
- ));
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $topic_id=$last_insert_id['last_insert_id()'];
- $this->sConn->createCommand()->insert('topic_item', array(
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_title' => ''
- ));
- //增加topic_option
- if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
- {
- $answers = explode(',',$v['answer']);
- if($answers && isset($answers[0]) && !empty($answers[0])){
- $options = array_chunk($option,$v['optionCount']);
- if(isset($options[0]) && !empty($options[0])){
- foreach($options[0] as $item=>$val)
- {
- $this->sConn->createCommand()->insert('topic_item_option', array(
- 'topic_id' => $topic_id,
- 'option_id' => 0,
- 'option_content' => '',
- 'option_correct' => in_array($val,$answers)?1:0,
- 'option_score' => 0,
- 'sort_order' => $item,
- ));
- }
- }
- }
- }
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $topic_id,
- 'mode' => 1,
- 'teacher_id' => $exam_data['teacher_id'],
- 'paper_id' =>$paperData[0]['paper_id']
- ));
- $questionCount = 0;
- $questionScoreStr = '';
- if(isset($v['scores']) && !empty($v['scores'])){
- $scoresArr = explode(',',$v['scores']);
- if($scoresArr){
- $questionCount = count($scoresArr);
- $questionScoreStr = $v['scores'];
- }
- }
- foreach($paperIds as $p)
- {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $p,
- 'topic_id' => $topic_id,
- 'no' => $v['questionNum'],
- 'order' => $v['questionNum'],
- 'mode' => 1,
- 'type' => $_topic_type,
- 'score' =>$v['fullScore'],
- 'question_count' => $questionCount,
- 'question_score_str' => $questionScoreStr
- ));
- }
- if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2)))
- {
- $topicNo=$v['questionNum'];
- if(isset($tplData['new_items'][$k]['alias'])){
- $topicNo=$tplData['new_items'][$k]['alias'];
- }elseif(isset($v['alias'])){
- $topicNo=$v['alias'];
- }
- if(!$topicNo) $topicNo=$v['questionNum'];
- $this->sConn->createCommand()->insert('marking_topic', array(
- 'exam_group_id' => $exam_group_id,
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_index' =>$v['questionNum'],
- 'topic_no' =>$topicNo,
- 'topic_score' =>$v['fullScore']
- ));
- }
- }
- $total = $tplData['total_score'];
- $topics_count = count($select_info['content']);
- $tpl_data=json_encode($tplData);
- $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute();
- $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
- $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`) ";
- $insert.=" values('".$name."','".$exam_group_id."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') ";
- $this->sConn->createCommand($insert)->execute();
- }
- $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
- $this->sConn->createCommand($examSql)->execute();
- $transaction->commit();
- if($paperData[0]['is_labelled']>0 || $exam_group_data['is_tagging']>0){
- updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '编辑考试',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- // echo json_encode(array('status'=>1,'msg'=>'编辑成功'));exit;
- $this->redirect($this->createUrl('third/index'));
- }catch(Exception $e){
- $transaction->rollBack();
- //echo json_encode(array('status'=>0,'msg'=>'编辑失败'));exit;
- Yii::app()->jump->error('编辑失败!');
- }
- }else{
- $exam_group_id = Req::get("exam_group_id");
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id));
- $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_data)
- {
- Yii::app()->jump->error('非法试卷!');
- }
- @$tplData=json_decode($exam_data['tpl_data'],true);
- if(!$tplData){
- Yii::app()->jump->error('非法试卷!');
- }
- $classInfo=$this->sConn->createCommand("select grade from class where class_id='".$exam_data['class_id']."'")->queryRow();
- $data['grade']=$classInfo['grade'];
- }
- $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();
- $data['answerSheet']=0;
- $data['onlineCard']=0;
- if($thirdAnswerSheet){
- $data['onlineCard']=$thirdAnswerSheet['online_card'];
- $data['answerSheet']=1;
- }
- $data['examGroupId']=$exam_group_id;
- $data['name']=$exam_data['name'];
- $data['markType']=$findInfo->mark_type;
- $data['paperType']=$exam_data['tpl_index'];
- $data['type']=$exam_data['type'];
- $data['examDate']=$tplData['examDate'];
- $data['examStatus']=$findInfo->status;
- $this->render('modify_exam',$data);
- }
- //创建考试并在线答题卡
- public function actionCreateThirdOnline(){
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $markType = Req::post("markType");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $examDate = Req::post("examDate");
- $tpl_index = (int)Req::post("tpl_index");
- $relationAnswerCard=false; //是否关联答题卡
- $json = array();
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',substr($classIds,0,-1));
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(empty($markType)){
- $error[] = '请选择阅卷方式';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- if(!inArray($tpl_index,array(0,1,2,1050))){
- $error[] = '请指定类型';
- }
- if($error){
- echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
- }else{
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- $json['author'] = $teacherName;
- $json['examDate'] = $examDate;
- $json['subjectId'] = (int)$subjectId;
- $json['textbookId'] = (int)$textbookId;
- $json['exam_name'] = $examName;
- $json['impersonal_topic_type'] = 0;
- $json['total_score'] = 0;
- $json['scores'] = 0;
- $json['times'] = 0;
- if($subjectId==8){
- $json['isNewEnglish']=1;
- }
- $json['school_card_length'] = 8;
- if($this->schoolId>999){
- $json['school_card_length'] = 9;
- }
- $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).") ";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if(!$cardData){
- $error[] = '无法找到对应班级';
- }
- if($cardData['card_status']){
- $json['school_card_length'] = (int)$cardData['card_length'];
- }else{
- $cardData['card_length'] = 8;
- if($this->schoolId>999){
- $cardData['card_length'] = 9;
- }
- }
- $class_type=$cardData['class_type'];
- $time = time();
- $newExamGroupId = getUniqueId($this->schoolId);
- //判断是否关联答题卡
- if(isset($_POST["timu"])){
- $text=$_POST["timu"];
- //处理答题卡数据
- $relationAnswerCard=true;
- $name = Req::post("title");
- $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
- $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
- $post = json_decode($text,true);
- $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
- $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
- $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
- $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
- $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
- $subject_id=$this->subjectId;
- if(!$text || !$name || !$sheet_answer || !$sheet_score){
- $error['message'] = '题目参数错误';
- echo json_encode($error);exit();
- }
- if(!$positionJson){
- $error['message'] = '定位信息异常';
- echo json_encode($error);exit();
- }
- //上传答题卡相关文件
- $files=$this->uploadAnswerCardPdf($newExamGroupId,$positionJson,$pdfUrl);
- $sheet_score_array = json_decode($sheet_score, 1);
- if (!$sheet_score_array) {
- $error['success']=0;
- $error['message'] = '上传失败,未设置分数!';
- echo json_encode($error);exit();
- }
- $score_num = count($sheet_score_array);
- if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi )) {
- $error['success']=0;
- $error['message'] = '上传失败,设置分数或设置题号有误!';
- echo json_encode($error);exit();
- }
- $select_info = json_decode($select_info, 1);
- $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$json);
- }
- if($error){
- echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- $paperIds=array();
- if($markType ==4)
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`mark_status`,`status`,`init_time`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",1,1,".time().",0,1,1)";
- }else
- {
- $sql = "insert into `exam_group` (`exam_group_id`,`teacher_id`,`mark_type`,`is_answersheet`,`is_third`,`is_new_marking`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",0,1,1)";
- }
- $this->sConn->createCommand($sql)->execute();
- foreach($classIds as $classId){
- $newExamId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($json),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- //$newPaperId = $this->UUID_SHORT();
- $newPaperId = getUniqueId($this->schoolId);
- $paperIds[]=$newPaperId;
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => 0,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- 'class_type' =>$class_type
- ));
- }
- }
- }
- if($relationAnswerCard){
- $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- $topic_data = $this->get_topic_folder();
- foreach($select_info['content'] as $k=>$v)
- {
- $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
- $zsytkTopicType=$_topic_type;
- if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
- $this->sConn->createCommand()->insert('topic', array(
- 'topic_type' =>$zsytkTopicType ,
- 'topic_title' => '',
- 'folder_id' => $topic_data['folder_id'],
- 'subject_id' => $subject_id,
- 'is_delete' =>0,
- 'creator_id' => $teacherId,
- 'updater_id' => $teacherId,
- 'is_word_topic'=>1,
- 'create_time' => time(),
- 'update_time' => time(),
- ));
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $topic_id=$last_insert_id['last_insert_id()'];
- $this->sConn->createCommand()->insert('topic_item', array(
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_title' => ''
- ));
- //增加topic_option
- if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
- {
- $answers = explode(',',$v['answer']);
- if($answers && isset($answers[0]) && !empty($answers[0])){
- $options = array_chunk($option,$v['optionCount']);
- if(isset($options[0]) && !empty($options[0])){
- foreach($options[0] as $item=>$val)
- {
- $this->sConn->createCommand()->insert('topic_item_option', array(
- 'topic_id' => $topic_id,
- 'option_id' => 0,
- 'option_content' => '',
- 'option_correct' => in_array($val,$answers)?1:0,
- 'option_score' => 0,
- 'sort_order' => $item,
- ));
- }
- }
- }
- }
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $topic_id,
- 'mode' => 1,
- 'teacher_id' => $teacherId,
- 'paper_id' =>$newPaperId
- ));
- $questionCount = 0;
- $questionScoreStr = '';
- if(isset($v['scores']) && !empty($v['scores'])){
- $scoresArr = explode(',',$v['scores']);
- if($scoresArr){
- $questionCount = count($scoresArr);
- $questionScoreStr = $v['scores'];
- }
- }
- foreach($paperIds as $p)
- {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $p,
- 'topic_id' => $topic_id,
- 'no' => $v['questionNum'],
- 'order' => $v['questionNum'],
- 'mode' => 1,
- 'type' => $_topic_type,
- 'score' =>$v['fullScore'],
- 'question_count' => $questionCount,
- 'question_score_str' => $questionScoreStr
- ));
- }
- if($markType==4 && !in_array($v['questionTypeId'],array(1,11,2)))
- {
- if(isset($json['new_items'][$k]['alias'])){
- $topicNo=$json['new_items'][$k]['alias'];
- }elseif(isset($v['alias'])){
- $topicNo=$v['alias'];
- }
- if(!$topicNo) $topicNo=$v['questionNum'];
- $this->sConn->createCommand()->insert('marking_topic', array(
- 'exam_group_id' => $newExamGroupId,
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_index' =>$v['questionNum'],
- 'topic_no' =>$topicNo,
- 'topic_score' =>$v['fullScore']
- ));
- }
- }
- $total = $json['total_score'];
- $topics_count = count($select_info['content']);
- $tpl_data=json_encode($json);
- $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$newExamGroupId )->execute();
- $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$newExamGroupId )->execute();
- $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
- $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`) ";
- $insert.=" values('".$name."','".$newExamGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$files['ucloudZipUrl']."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$files['ucloudPdfUrl']."','0') ";
- $this->sConn->createCommand($insert)->execute();
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- echo json_encode(array('success'=>0,'message'=>'创建失败'));exit;
- }
- }
- if(!$error){
- echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$newExamGroupId));exit;
- }
- }
- // 上传答题卡相关文件
- private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){
- $card_file=array();
- $card_pdf='';
- $ucloudZipUrl='';
- $ucloudPdfUrl='';
- if (empty($_FILES)) {
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }else {
- // debug($_FILES);
- foreach ($_FILES as $k => $v) {
- if (isset($v) && !empty($v)) {
- if (!isset($v['size']) || $v['size'] >= 8388608) {
- $error['message'] = '文件超过8M!';
- echo json_encode($error);
- exit();
- }
- $ext = substr($v['name'], strrpos($v['name'], '.') + 1);
- if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) {
- $error['message'] = '文件格式不正确!';
- echo json_encode($error);
- exit();
- }
- if ($ext == 'pdf') {
- $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf';
- if (!move_uploaded_file($v["tmp_name"], $card_pdf)) {
- $error['message'] = '保存Pdf文件失败!';
- echo json_encode($error);
- exit();
- }
- } else {
- $card_file[] = $v;
- }
- }
- }
- $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/';
- $ucloudPdfUrl = '';
- if (!file_exists($fixName)) {
- mkdir($fixName, 0777, true);
- }
- $zipFileName = $examGroupId .'_'.time().'.zip';
- $pathName = $fixName . $zipFileName;
- $zip = new ZipArchive;
- $zip->open($pathName, ZipArchive::CREATE);
- foreach ($card_file as $k => $v) {
- $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
- }
- $zip->addFromString('json.txt', $positionJson);
- $zip->close();
- //FIXME 20191204
- $ucloud = new HuaweiCloud();
- //上传压缩包
- $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName;
- $uploadInfo = $ucloud->putFile($rename, $pathName);
- @unlink($pathName);
- if ($uploadInfo['status'] == 0) {
- $error['success'] = 0;
- $error['message'] = '答题卡文件上传失败! ';
- echo json_encode($error);
- exit();
- } else {
- $ucloudZipUrl = $uploadInfo['url'];
- }
- //上传Pdf
- if ($pdfUrl) {
- $ucloudPdfUrl=$pdfUrl;
- // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf';
- // $content = file_get_contents($pdfUrl);
- //
- // file_put_contents($card_pdf, $content);
- //
- // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf';
- // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf);
- //
- // if ($uploadInfo['status'] == 0) {
- // @unlink($card_pdf);
- // $error['success'] = 0;
- // $error['message'] = '答题卡PDF文件上传失败!';
- // echo json_encode($error);
- // exit();
- // } else {
- // @unlink($card_pdf);
- // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']);
- // $ucloudPdfUrl = $uploadInfo['url'];
- // }
- }
- //单独上传position.txt
- if($positionJson){
- $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ;
- file_put_contents($positionTxt, $positionJson);
- $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
- $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
- if ($uploadInfo['status'] == 0) {
- @unlink($positionTxt);
- $error['success']=0;
- $error['message'] = 'Position文件上传失败!';
- echo json_encode($error);exit();
- }else{
- @unlink($positionTxt);
- $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- $ucloudTxtUrl=$uploadInfo['url'];
- }
- }
- }
- return array(
- 'ucloudZipUrl'=>$ucloudZipUrl,
- 'ucloudPdfUrl'=>$ucloudPdfUrl,
- 'positionUrl'=>$ucloudTxtUrl
- );
- }
- //处理在线答题卡tpl_data
- private function updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,$totals,$json){
- $subject_id=$this->subjectId;
- $exam_ids = array();
- $_new_items = array();
- $required_count = 0; //分组统计,即选做题中,必做题数量
- $isDisplay = 1; //是否使用别名,
- $selectTopicGroupScore = 0; //计算可能多分组情况总分
- if ($select_info) {
- if ($select_info && isset($select_info['content']) && !empty($select_info['content'])) {
- //
- $selectTopicGroupNum = 0; //分组试题显示序号
- $nowGroupId = 0; //分组标志
- $letterNum = 0;
- $nowSameAliasNo=0; //选做题小题组序号
- $sameAliasLetter=0;
- foreach ($select_info['content'] as $k => $sc) {
- //校验别名
- if (isset($sc['alias']) && !empty($sc['alias'])) {
- if (!preg_match('/^[0-9.\~]+$/u', $sc['alias']) || !is_numeric(substr($sc['alias'], -1)) || strlen($sc['alias']) > 6) {
- $this->output(0, "别名格式不正确,别名允许字符【0-9.】且总长度不大于6位,请重新输入,题号:" . $sc['questionNum']);
- exit;
- }
- }
- if (isset($sc['questionTypeId'])) {
- if ($sc['questionTypeId'] == 11 && in_array($subject_id,$this->mathSubjectId)) {
- $this->output(0, "第三方暂不支持不定项选择题");
- exit;
- }
- //分组判断
- if (!isset($sc['groupid'])) {
- $selectTopicGroupNum++;
- $selectTopicGroupScore += $sc['fullScore'];
- } elseif ($nowGroupId != $sc['groupid']) {
- $isDisplay = 1;
- $selectTopicGroupNum++;
- $selectTopicGroupNum = isset($sc['alias']) ? $sc['alias'] : $selectTopicGroupNum;
- $nowGroupId = $sc['groupid'];
- if(isset($sc['smTopicLen']) && $sc['smTopicLen']){
- $required_count+=$sc['smTopicLen'];
- $selectTopicGroupScore += ($sc['fullScore']*$sc['smTopicLen']);
- }else{
- $required_count++;
- $selectTopicGroupScore += $sc['fullScore'];
- }
-
- $letterNum = 0;
- $sameAliasLetter=0;
- }
- if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && $sc['sameAliasNo']!=$nowSameAliasNo){
- $sameAliasLetter++;
- $nowSameAliasNo=$sc['sameAliasNo'];
- }
- $_new_items[$k]['sameAliasNo']=isset($sc['sameAliasNo'])?$sc['sameAliasNo']:0;
- $_new_items[$k]['smTopicLen']=isset($sc['smTopicLen'])?$sc['smTopicLen']:0;
- $_new_items[$k]['id'] = (int)$sc['questionNum'];
- $_new_items[$k]['showNum'] = (string)$selectTopicGroupNum;
- if ($sc['questionTypeId'] == 17) {
- //判断选做题小题组
- if($sameAliasLetter){
- $_new_items[$k]['alias'] = (string)$sc['alias'] .$this->numToLetter($sameAliasLetter-1);
- }else{
- $_new_items[$k]['alias'] = (string)$selectTopicGroupNum . $this->numToLetter($letterNum);
- }
- } else {
- if (isset($sc['alias'])) {
- $_new_items[$k]['alias'] = (string)$sc['alias'];
- } else {
- $_new_items[$k]['alias'] = (string)$selectTopicGroupNum;
- }
- }
- if(!$_new_items[$k]['alias']){
- $_new_items[$k]['alias']=(int)$sc['questionNum'];
- }
- $_new_items[$k]['score'] = $sc['fullScore'];
- $_new_items[$k]['topic_type'] = (string)$sc['questionTypeId'];
- $_new_items[$k]['group_id'] = $sc['groupid'];
- //新增逻辑题型
- if (isset($sc['marktype'])) {
- $_new_items[$k]['logic_type'] = $sc['marktype'];
- }
- //每道题科目
- if (isset($sc['subject'])) {
- $_new_items[$k]['subject'] = $sc['subject'];
- }
- $letterNum++;
- //自动批阅
- if(isset($sc['reviewSwitch']) && $sc['reviewSwitch']==1){
- $_new_items[$k]['reviewSwitch'] = $sc['reviewSwitch']; //自动批阅开关
- $_new_items[$k]['reviewWordNumber'] = $sc['reviewWordNumber']; //字数
- $_new_items[$k]['reviewTopicImg'] = $sc['reviewTopicImg']; //试题截图链接
- }
- }
- }
- }
- }
- //处理半对分
- $tplRules=array();
- if($half_score){
- $halfScoreArr=json_decode($half_score,true);
- $sheetAnswerArr=json_decode($sheet_answer,true);
- $sheet_score_array = json_decode($sheet_score, 1);
- foreach ($halfScoreArr as $key => $val){
- $ruleScore=0;
- $ruleAnswer='';
- if(isset($sheet_score_array[$key])){
- $ruleScore=$sheet_score_array[$key];
- }
- if(isset($sheetAnswerArr[$key])){
- $ruleAnswer=$sheetAnswerArr[$key];
- }
- $tplRules[$key]=array(
- 'topicNo'=>$key,
- 'topic_id'=>'',
- 'rule_type'=>2,
- 'rule_answer'=>$ruleAnswer,
- 'rule_score'=>$ruleScore,
- 'rule_score_half'=>$val
- );
- }
- }
- $json['disabled']=0;
- $json['paper']=0;
- $json['line']=0;
- $json['anyway']=0;
- $json['is_display']=$isDisplay;
- $json['totals']=$totals;
- $json['total_score']=$selectTopicGroupScore;
- $json['scores']=$selectTopicGroupScore;
- if(!isset($json['subjectId'])){
- $json['subjectId']=$subject_id;
- }
- $json['new_items']=$_new_items;
- $json['new_rules']=$tplRules;
- $json['reviewer']='';
- $json['is_new_marking']=1;
- $json['required']=$required_count;
- $json['times']=0;
- $json['branch']=0;
- if ($subject_id == 8) {
- $json['isNewEnglish']=1;
- }
- return $json;
- }
- private function get_topic_folder()
- {
- $data = $this->sConn->createCommand("select * from topic_folder where is_system = 1")->queryRow();
- if($data)
- {
- return $data;
- }
- return false;
- }
- //保存为第三方在线答题卡模板
- public function actionSaveTemplateByOnline(){
- $name = Req::post("title");
- $layout = isset($_POST['layout'])?$_POST['layout']:'';
- $select_card_type = isset($_POST['select_card_type'])?$_POST['select_card_type']:'1';
- $total_score = isset($_POST['total_score'])?$_POST['total_score']:'0';
- $total_topics = isset($_POST['total_topics'])?$_POST['total_topics']:'0';
- $tpl_data = isset($_POST['tpl_data'])?$_POST['tpl_data']:'';
- $error['success']=0;
- // $count=$this->sConn->createCommand("select count(*) as count from third_tpl where subject_id='{$this->subjectId}'")->queryRow();
- // if($count && $count['count']>9){
- // $error['message'] = '同一学科最多保存10个模板';
- // echo json_encode($error);exit();
- // }
- // if($tpl_data){
- //
- // $positionTxt="upload/ThirdSheet/" .$name.time().'.txt' ;
- // file_put_contents($positionTxt, $tpl_data);
- // $ucloud = new HuaweiCloud();
- // $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
- // $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
- //
- // if ($uploadInfo['status'] == 0) {
- // @unlink($positionTxt);
- // $error['success']=0;
- // $error['message'] = 'Position文件上传失败!';
- // echo json_encode($error);exit();
- // }else{
- // @unlink($positionTxt);
- // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- // $ucloudTxtUrl=$uploadInfo['url'];
- // }
- //
- // }
- $rs = $this->sConn->createCommand()->insert('third_tpl',array(
- 'title' => $name,
- 'subject_id' => $this->subjectId,
- 'school_card_status' => 0,
- 'school_card_length' => 0,
- 'layout' => $layout,
- 'select_card_type' => $select_card_type,
- 'tpl_data' => $tpl_data,
- 'total_score' => $total_score,
- 'total_topics' => $total_topics,
- 'create_time' => time()
- ));
- if($rs){
- $error['success']=1;
- $error['message'] = '保存成功';
- echo json_encode($error);exit();
- }
- echo json_encode($error);exit();
- }
- //读取模板列表
- public function actionTplList(){
- $criteria = new CDbCriteria();
- $criteria->addCondition('subject_id=:subject_id');
- $criteria->params[':subject_id'] = Yii::app()->session['session_duoxueke_subject_id'];
- $criteria->addCondition('school_card_length=0');
- $criteria->order = 'third_tpl_id desc';
- $thisTpls = SThirdTplModel::model()->findAll($criteria);
- $list=array();
- if($thisTpls)
- {
- foreach ($thisTpls as $val){
- $jsonData='';
- $tplData=$val->tpl_data;
- if(strpos($tplData,'http://')!==false || strpos($tplData,'https://')!==false){
- if(strpos($tplData,'zxhx.cn-bj.ufileos.com')!==false){
- $tplData=str_replace('zxhx.cn-bj.ufileos.com','zxhx-u-1302712961.cos.ap-beijing.myqcloud.com',$tplData);
- }
- $jsonData=fileGetContents($tplData);
- }else{
- $jsonData=$val->tpl_data;
- }
- $jsonDataArr=json_decode($jsonData,true);
- if(isset($jsonDataArr['position'])){
- $list[]=array(
- 'third_tpl_id'=>$val->third_tpl_id,
- 'title'=>$val->title,
- 'total_score'=>$val->total_score,
- 'total_topics'=>$val->total_topics,
- 'tpl_data'=>jsonEncode($jsonDataArr['position'])
- );
- }else{
- $list[]=array(
- 'third_tpl_id'=>$val->third_tpl_id,
- 'title'=>$val->title,
- 'total_score'=>$val->total_score,
- 'total_topics'=>$val->total_topics,
- 'tpl_data'=>$jsonData
- );
- }
- }
- $data['thisTpls'] = $list;
- }
- $data['success']=1;
- exit(json_encode($data));
- }
- //删除模板
- public function actionDelTpl(){
- $third_tpl_id = Req::post("third_tpl_id");
- if($third_tpl_id>0){
- $thirdTpl = SThirdTplModel::model()->deleteAll('third_tpl_id=:third_tpl_id',array(':third_tpl_id'=>$third_tpl_id));
- if($thirdTpl){
- echo json_encode(array('success'=>1,'msg'=>'1'));exit;
- }
- }
- echo json_encode(array('success'=>0,'msg'=>'失败'));exit;
- }
- //读取考试答题卡
- public function actionGetTemplateByExamGroupId(){
- $exam_group_id = Req::post("examGroupId");
- $isHide = Req::post("isHide");
-
- if(!$exam_group_id){
- $data['success']=0;
- $data['msg']='考试id不正确';
- exit(json_encode($data));
- }
- //验证是否有在线答题卡
- $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();
- $data['success']=1;
- $data['data']=array();
- //判断全学科
- $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
- $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryAll();
- //判断全学科白名單
- $data['new_answer_sheet_subject']=0;
- if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){
- $rs = http('/cms/api/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- $data['new_answer_sheet_subject']=1;
- }
- }
- if($thirdAnswerSheet){
- $nowMultiplexId=$thirdAnswerSheet['multiplex_id'];
- //判断是否有复用答题卡记录
- if(!$nowMultiplexId){
- $mult=$this->sConn->createCommand("select multiplex_id from online_card_multiplex where exam_group_id='{$exam_group_id}' and is_copy=0")->queryRow();
- if(!$mult){
- //旧数据没有复用记录,需要补一条记录
- $onlineCardMultiModel=new SOnlineCardMultiplex();
- $onlineCardMultiModel->exam_group_id=$exam_group_id;
- $onlineCardMultiModel->name=$thirdAnswerSheet['name'];
- $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path'];
- $onlineCardMultiModel->position=$thirdAnswerSheet['position'];
- $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf'];
- $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online'];
- $onlineCardMultiModel->is_download=0;
- $onlineCardMultiModel->is_copy=0;
- $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time'];
- $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time'];
- if($onlineCardMultiModel->save()){
- $nowMultiplexId=$onlineCardMultiModel->multiplex_id;
- $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$exam_group_id}'")->execute();
- }
- }else{
- $nowMultiplexId=$mult['multiplex_id'];
- $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$mult['multiplex_id']}' where exam_group_id='{$exam_group_id}'")->execute();
- }
- }
- // if($thirdAnswerSheet['position']){
- // if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){
- // $thirdAnswerSheet['position']=fileGetContents($thirdAnswerSheet['position']);
- // }
- // }
- if(!$examData){
- $data['msg']='考试id不正确';
- exit(json_encode($data));
- }
- $examIds=array();
- foreach ($examData as $datum){
- $examIds[]=$datum['exam_id'];
- }
- //判断是否有修改的判分规则
- $tplData=json_decode($examData[0]['tpl_data'],true);
- $questions=array();
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $val){
- $alias=isset($val['alias'])?$val['alias']:$val['id'];
- $temp=array(
- 'questionNum'=>(int)$val['id'],
- 'questionTypeId'=>(int)$val['topic_type'],
- 'fullScore'=>(string)$val['score'],
- 'alias'=>$alias,
- );
- if(isset($tplData['new_rules']) && isset($tplData['new_rules'][$val['id']])){
- $temp['ruleScoreHalf']=$tplData['new_rules'][$val['id']]['rule_score_half'];
- }
- $questions[]=$temp;
- }
- }
- $thirdAnswerSheet['questions']=$questions;
- $thirdAnswerSheet['is_third']=$examGroup['is_third'];
- if($examGroup['qxk_paper_id']){
- if(isset($tplData['item_collect'])){
- $itemCollect=array();
- //读取大题型
- $allSubjectTopicType=$this->schoolManager->getAllSubjectTopicType($examData[0]['subject_id']);
- $allTopicTypeArr=array();
- if($allSubjectTopicType){
- foreach ($allSubjectTopicType as $item){
- $allTopicTypeArr[$item['topic_type_id']]=$item['topic_type_name'];
- }
- }
- //读取基础题型
- $allBasicTopicTypeArr=array();
- $allSubjectBasicTopicType=$this->schoolManager->getAllSubjectBasicType();
- if($allSubjectBasicTopicType){
- foreach ($allSubjectBasicTopicType as $item){
- $allBasicTopicTypeArr[$item['btt_id']]=$item['btt_name'];
- }
- }
- foreach ($tplData['item_collect'] as $key => $datum){
- $topicTypeName='';
- $topicBasicName='';
- $topicCount=0;
- if($datum['topicBasicType']==17){
- $topicTypeName='选做题';
- $topicBasicName='选做';
- $topicCount='2选1'; //奇葩的需求
- }else{
- if(isset($allTopicTypeArr[$datum['topicType']])){
- $topicTypeName=$allTopicTypeArr[$datum['topicType']];
- }
- if(isset($allBasicTopicTypeArr[$datum['topicBasicType']])){
- $topicBasicName=$allBasicTopicTypeArr[$datum['topicBasicType']];
- }
- $topicCount=$datum['topicCount'];
- }
- $itemCollect[]=array(
- "topic_type_name"=>$topicTypeName,
- 'topic_basic_name'=>$topicBasicName,
- 'topic_count'=>$topicCount,
- 'total_score'=>$datum['totalScore']
- );
- }
- $data['item_collect']=$itemCollect;
- }
- }
- $where[]="exam_group_id={$exam_group_id}";
- if($isHide){
- $where[]="is_hide=1";
- }else{
- $where[]="is_hide=0";
- }
- $isDownload=0;
- $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();
- if($multi){
- foreach ($multi as $key =>$value){
- if($nowMultiplexId==$value['multiplex_id']){
- $multi[$key]['active']=1;
- }else{
- $multi[$key]['active']=0;
- }
- if($value['is_download']==1){
- $isDownload=1;
- }
- }
- }
- $data['multiplex']=$multi;
- //查询是否有下载记录
- if(!$isDownload){
- $checkDownload=$this->sConn->createCommand("select is_download from online_card_multiplex where exam_group_id='".$exam_group_id."' and is_download=1")->queryRow();
- if($checkDownload){
- $isDownload=1;
- }
- }
- //判断是否上传试卷
- if(in_array($this->subjectId,$this->mathSubjectId) || $this->subjectId==12){
- $checkPaperUpload=$this->sConn->createCommand("select * from topic_word where exam_group_id='".$exam_group_id."' and status>0")->queryRow();
- }else{
- $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();
- }
- if($checkPaperUpload){
- $thirdAnswerSheet['paper_uploaded']=1;
- }else{
- $thirdAnswerSheet['paper_uploaded']=0;
- }
- //查询协助状态
- $thirdAnswerSheet['assist_status']=0;
- $assist=$this->conn->createCommand("select status from abnormal_template where exam_group_id={$exam_group_id}")->queryRow();
- if($assist){
- $thirdAnswerSheet['assist_status']=$assist['status'];
- }
- $data['success']=1;
- $thirdAnswerSheet['is_download']=$isDownload;
- $data['data']=$thirdAnswerSheet;
- }else{
- $data['data']=null;
- }
- exit(json_encode($data));
- }
- //切换模板,清空原模板数据
- public function actionClearExamTpl(){
- $exam_group_id = Req::post("examGroupId");
- $data['success']=0;
- if(!$exam_group_id){
- $data['msg']='参数错误';
- exit(json_encode($data));
- }
- $exam=$this->sConn->createCommand("select exam_id,status,tpl_data from exam where exam_group_id='{$exam_group_id}'")->queryAll();
- if(!$exam){
- $data['msg']='考试id不正确';
- exit(json_encode($data));
- }
- if($exam['status']==1 || $exam['status']==4){
- $data['msg']='已上传成绩,不能切换答题卡';
- exit(json_encode($data));
- }
- $examIds=array();
- $paperIds=array();
- $topicIds=array();
- $tplData=array();
- foreach ($exam as $val){
- $examIds[]=$val['exam_id'];
- if(!$tplData){
- $tplData=json_decode($val['tpl_data'],true);
- }
- }
- $paperData=$this->sConn->createCommand("select paper_id from paper where exam_id in(".implode(',',$examIds).")")->queryAll();
- if(!$paperData){
- $data['msg']='试卷不存在';
- exit(json_encode($data));
- }
- foreach ($paperData as $val){
- $paperIds[]=$val['paper_id'];
- }
- $paperTopic=$this->sConn->createCommand("select topic_id from paper_topic_relation where paper_id='".$paperIds[0]."'")->queryAll();
- foreach ($paperTopic as $val){
- $topicIds[]=$val['topic_id'];
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- if(isset($tplData['items'])){
- unset($tplData['items']);
- }
- if(isset($tplData['new_items'])){
- unset($tplData['new_items']);
- }
- if(isset($tplData['new_rules'])){
- unset($tplData['new_rules']);
- }
- $tplData['scores']=0;
- $tplData['times']=0;
- $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topicIds).")" )->execute();
- $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topicIds).")" )->execute();
- $this->sConn->createCommand("delete from topic_use where topic_id in (".implode(',',$topicIds).")" )->execute();
- $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topicIds).")" )->execute();
- $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
- $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$exam_group_id )->execute();
- $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$exam_group_id )->execute();
- $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =".$exam_group_id )->execute();
- $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$exam_group_id )->execute();
- $this->sConn->createCommand("update exam set tpl_data ='".jsonEncode($tplData)."' where exam_group_id = ".$exam_group_id )->execute();
- $this->sConn->createCommand("update paper set score = 0,topics_count = 0,is_labelled = 0 where exam_id in (".implode(',',$examIds).")")->execute();
- $transaction->commit();
- echo json_encode(array('success'=>1));exit;
- }catch(Exception $e)
- {
- $transaction->rollBack();
- echo json_encode(array('success'=>0));exit;
- }
- }
- //修改第三方考试信息
- public function actionAjaxModifyThirdExam(){
- $exam_group_id = Req::post("examGroupId");
- $type=Req::post('type');
- $name=Req::post('examName');
- $examDate=Req::post('examDate');
- $paperType=Req::post('paperType');
- $relationAnswerCard=false;
- $data['success']=0;
- if(!matchStrChar($name)){
- $data['msg']='考试名称不能包含特殊字符!';
- exit(json_encode($data));
- }
- if(Yii::app()->params['section']==0){
- $paperType='1050';
- }
- $exam_group_data=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $transaction = $this->sConn->beginTransaction();
- $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_data)
- {
- $data['msg']='非法试卷!';
- exit(json_encode($data));
- }
- @$tplData=json_decode($exam_data['tpl_data'],true);
- if(!$tplData){
- $data['msg']='非法试卷!';
- exit(json_encode($data));
- }
- $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
- if(!$paperData){
- $data['msg']='试卷不存在';
- exit(json_encode($data));
- }
- try{
- $tplData['examDate']=$examDate;
- $examSql="update `exam` set `type`='".$type."',`name`='".$name."',tpl_index='".$paperType."',tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
- $this->sConn->createCommand($examSql)->execute();
- if($paperData['is_labelled']>0 || $exam_group_data['is_tagging']>0){
- updateExamNameToTiku($exam_group_id,$name,$this->schoolId); //同步题库
- }
- $transaction->commit();
- $data['success']=1;
- $data['msg']='编辑成功';
- exit(json_encode($data));
- }catch(Exception $e){
- $transaction->rollBack();
- $data['msg']='编辑失败';
- exit(json_encode($data));
- }
- $data['msg']='编辑失败';
- exit(json_encode($data));
- }
- //第三方创建在线答题卡需要准考证位数,所以需要确定年级
- public function actionGetCardStatusByGrade(){
- $grade=(int)Req::post("grade");
- if(!in_array($grade,array(1,2,3))){
- $data=array(
- 'success'=>0,
- 'msg'=>'年级不正确',
- );
- exit(json_encode($data));
- }
- $sql = "select card_length,card_status FROM grade where id='{$grade}'";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if($cardData['card_status']==0){
- $cardData['card_length'] = 8;
- if($this->schoolId >999){
- $cardData['card_length'] = 9;
- }
- }
- $data=array(
- 'success'=>1,
- 'data'=>$cardData,
- );
- exit(json_encode($data));
- }
- //考试扫描异常处理状态查看
- public function actionGetTaskDetail(){
- $examGroupId = Req::get('exam_group_id');
- $grade = Req::get('grade');
- $branch = Req::get('branch');
- $taskModel=new AScanTask();
- $task=$taskModel->getTaskByExamGroupId($examGroupId);
- if($task){
- $task=$task->attributes;
- if($task['operator']){
- $user=AssistUser::model()->findByPk($task['operator']);
- $task['user']=$user->real_name;
- }else{
- $task['user']='--';
- }
- //答题卡任务耗时
- if($task['scan_task_apply_time']){
- if($task['scan_task']>2){
- if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){
- $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }elseif($task['scan_task']==2){
- if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){
- $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }
- }else{
- $task['AstConsuming']='--';
- }
- }
- //读取扫描数量
- $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1);
- $task['count']=$count;
- $data['task']=$task;
- $data['exam_group_id']=$examGroupId;
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $data['version_number']=$version_number;
- $data['grade']=$grade;
- $data['branch']=$branch;
- $this->render('scan_detail',$data);
- }
- //关联第三方在线答题卡
- public function actionInsertThirdSheet(){
- $error = array();
- $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
- $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
- $text=$_POST["timu"];
- //处理答题卡数据
- $relationAnswerCard=true;
- $name = Req::post("title");
- $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
- $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
- $post = json_decode($text,true);
- $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
- $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
- $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
- $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
- $DuoXuanTi = isset($post["DuoXuanTi"]) ? $post["DuoXuanTi"] : 0;
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- $select_info = isset($_POST["question_info"]) ? $_POST["question_info"] : '';
- $half_score = isset($_POST['sheet_halfscore']) ? $_POST['sheet_halfscore'] : ''; //多选题半对分
- $zhunkaozhen_length = isset($_POST['zhunkaozhen_length']) ? $_POST['zhunkaozhen_length'] : 0;
- $isUploadScore=false; //是否已上传成绩
- $isLabelled=false;
- $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(!$exam_data)
- {
- echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit;
- }
- $teacherId = $exam_data[0]['teacher_id'];
- $subject_id = $exam_data[0]['subject_id'];
- @$tplData=json_decode($exam_data[0]['tpl_data'],true);
- if(!$tplData){
- echo json_encode(array('success'=>0,'message'=>'非法試卷'));exit;
- }
- if ($zhunkaozhen_length) {
- if ($exam_data[0]['school_card_status'] == 1) {
- if ($zhunkaozhen_length < $exam_data[0]['school_card_length']) {
- echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用学校准考证号,长度为'.$exam_data[0]['school_card_length']));exit;
- }
- } else {
- if ($zhunkaozhen_length < 8 && $this->schoolId < 999) {
- echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为8'));exit;
- }
- if ($zhunkaozhen_length < 9 && ($this->schoolId > 999 && $this->schoolId < 9999)) {
- echo json_encode(array('success'=>0,'message'=>'上传失败,准考证的长度不符;本试卷使用系统准考证号,长度为9'));exit;
- }
- }
- }
- if(!$text || !$name || !$sheet_answer || !$sheet_score){
- $error['message'] = '题目参数错误';
- echo json_encode($error);exit();
- }
- if(!$positionJson){
- $error['message'] = '定位信息异常';
- echo json_encode($error);exit();
- }
- if($error){
- echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
- }else{
- $time = time();
- $paper_data = $this->schoolManager->getPaperByExamId($exam_data[0]['exam_id']);
- if ($paper_data) {
- /**
- * 验证已上传成绩,无法再次编辑
- */
- if ($exam_data) {
- foreach ($exam_data as $v) {
- $exam_ids[$v['exam_id']] = $v['exam_id'];
- }
- if ($exam_ids) {
- $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();
- if ($student_paper_feed) {
- $isUploadScore = true;
- }
- }
- }
- //判断是否发送标注
- if ($paper_data['is_labelled'] != 0 ) {
- $isLabelled = true;
- }
- }
- //验证是否已下载,是否是复用的答题卡
- if($multiplexId){
- $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow();
- if($checkMulti['is_download']){
- $error['success']=0;
- $error['message'] = '上传失败,答题卡已经下载!';
- echo json_encode($error);exit();
- }
- if($checkMulti['is_copy']){
- //只保存文件信息
- $this->saveMultiplex();
- }
- }
- $sheet_score_array = json_decode($sheet_score, 1);
- if (!$sheet_score_array) {
- $error['success']=0;
- $error['message'] = '上传失败,未设置分数!';
- echo json_encode($error);exit();
- }
- $score_num = count($sheet_score_array);
- if ($score_num != ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi+$DuoXuanTi )) {
- $error['success']=0;
- $error['message'] = '上传失败,设置分数或设置题号有误!';
- echo json_encode($error);exit();
- }
- $items = array();
- $xu = 0;
- $t = 0;
- $z = 0;
- $x = 0;
- $duo = 0;
- foreach ($sheet_score_array as $k => $v) {
- if ($KeGuanTi >= $k) {
- $items[1]['total'] = $KeGuanTi;
- $items[1]['perScores'][$xu] = $v;
- for ($i = 0; $i < $KeGuanTi; $i++) {
- $items[1]['no'][$i + 1] = $i + 1;
- }
- $xu++;
- } elseif ($DuoXuanTi > 0 && $KeGuanTi < $k && $k <= ($KeGuanTi + $DuoXuanTi)) {
- $items[2]['total'] = $DuoXuanTi;
- $items[2]['perScores'][$duo] = $v;
- for ($i = $KeGuanTi; $i < ($DuoXuanTi + $KeGuanTi); $i++) {
- $items[2]['no'][$i + 1] = $i + 1;
- }
- $duo++;
- } elseif ($TianKongTi > 0 && ($KeGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $DuoXuanTi)) {
- $items[5]['total'] = $TianKongTi;
- $items[5]['perScores'][$t] = $v;
- for ($i = ($KeGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i++) {
- $items[5]['no'][$i + 1] = $i + 1;
- }
- $t++;
- } elseif ($ZhuGuanTi > 0 && ($KeGuanTi + $TianKongTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi)) {
- $items[7]['total'] = $ZhuGuanTi;
- $items[7]['perScores'][$z] = $v;
- for ($i = ($KeGuanTi + $TianKongTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i++) {
- $items[7]['no'][$i + 1] = $i + 1;
- }
- $z++;
- } elseif ($XuanZuoTi > 0 && ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi) < $k && $k <= ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi)) {
- $items[17]['total'] = $XuanZuoTi;
- $items[17]['required'] = 1;
- $items[17]['score'] = $v;
- $items[17]['perScores'][$x] = $v;
- $_select_topic_scroe = $v;
- for ($i = ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $DuoXuanTi); $i < ($KeGuanTi + $TianKongTi + $ZhuGuanTi + $XuanZuoTi + $DuoXuanTi); $i++) {
- $items[17]['no'][$i + 1] = $i + 1;
- }
- $x++;
- }
- }
- if (!$items) {
- echo json_encode(array('success'=>0,'message'=>'上传失败,无题'));exit;
- }
- $select_info = json_decode($select_info, 1);
- if(!isset($select_info['content']) || !$select_info['content']){
- echo json_encode(array('success'=>0,'message'=>'上传失败,题目数据不能为空'));exit;
- }
- //检测id是否重复
- $checkRepeatId=array();
- foreach ($select_info['content'] as $value){
- if(!isset($checkRepeatId[$value['questionNum']])){
- $checkRepeatId[$value['questionNum']]=$value['questionNum'];
- }else{
- echo json_encode(array('success'=>0,'message'=>'上传失败,题目序号重复'.$value['questionNum']));exit;
- }
- }
- //上传答题卡相关文件
- $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
- $json=$this->updateTplData($select_info,$half_score,$sheet_answer,$sheet_score,($TianKongTi+$TianKongTi+$ZhuGuanTi+$XuanZuoTi),$tplData);
- $json['items']=$items;
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if($error){
- echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- $topic_ids=array();
- $paperIds=$this->schoolManager->getPaperIdsByExamIds($exam_ids);
- //判断是否已关联答题卡
- //判断原答题卡
- $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id,online_card,sheet_answer,sheet_score from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
- if($thirdAnswerSheet){
- $oldSheetAnswer = $thirdAnswerSheet['sheet_answer'];
- $oldSheetScore = $thirdAnswerSheet['sheet_score'];
- if($isUploadScore || $isLabelled){
- //判断答案是否改变
- if (strcmp($oldSheetAnswer, $sheet_answer) != false) {
- echo json_encode(array('success'=>0,'message'=>'上传失败,已上传成绩,不能修改试题答案'));exit;
- }
- if (strcmp($oldSheetScore, $sheet_score) != false) {
- echo json_encode(array('success'=>0,'message'=>'传失败,已上传成绩,不能修改试题分数'));exit;
- }
- if($multiplexId){
- $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();
- }
- $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`) ";
- $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)."') ";
- $this->sConn->createCommand($insert)->execute();
- $transaction->commit();
- echo json_encode(array('success'=>1,'message'=>'创建成功'));exit;
- }
- $paperTopic=$this->sConn->createCommand("select topic_id,type from paper_topic_relation where paper_id ='{$paperIds[0]}'")->queryAll();
- foreach ($paperTopic as $item){
- $topic_ids[]=$item['topic_id'];
- }
- //删除数据
- $this->sConn->createCommand("delete from topic where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from topic_item where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from topic_item_option where topic_id in (".implode(',',$topic_ids).")" )->execute();
- $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (".implode(',',$paperIds).")" )->execute();
- $this->sConn->createCommand("delete from marking_topic where exam_group_id =".$examGroupId )->execute();;
- $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =".$examGroupId )->execute();;
- $this->sConn->createCommand("delete from topic_word where exam_group_id =".$examGroupId )->execute();
- }
- $option = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- $topic_data = $this->get_topic_folder();
- foreach($select_info['content'] as $k=>$v)
- {
- if(isset($v['scoreColumnHtml'])){
- unset($select_info['content'][$k]['scoreColumnHtml']);
- }
- $_topic_type = isset($v['questionTypeId'])?$v['questionTypeId']:0;
- $zsytkTopicType=$_topic_type;
- if($zsytkTopicType==17 && in_array($subject_id,$this->mathSubjectId)) $zsytkTopicType=7;
- $this->sConn->createCommand()->insert('topic', array(
- 'topic_type' =>$zsytkTopicType ,
- 'topic_title' => '',
- 'folder_id' => $topic_data['folder_id'],
- 'subject_id' => $subject_id,
- 'is_delete' =>0,
- 'creator_id' => $teacherId,
- 'updater_id' => $teacherId,
- 'is_word_topic'=>1,
- 'create_time' => time(),
- 'update_time' => time(),
- ));
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $topic_id=$last_insert_id['last_insert_id()'];
- $this->sConn->createCommand()->insert('topic_item', array(
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_title' => ''
- ));
- //增加topic_option
- if(($_topic_type==1 && $v['optionCount']>0) || ($_topic_type ==11 && $v['optionCount']>0) || ($_topic_type ==2 && $v['optionCount']>0))
- {
- $answers = explode(',',$v['answer']);
- if($answers && isset($answers[0]) && !empty($answers[0])){
- $options = array_chunk($option,$v['optionCount']);
- if(isset($options[0]) && !empty($options[0])){
- foreach($options[0] as $item=>$val)
- {
- $this->sConn->createCommand()->insert('topic_item_option', array(
- 'topic_id' => $topic_id,
- 'option_id' => 0,
- 'option_content' => '',
- 'option_correct' => in_array($val,$answers)?1:0,
- 'option_score' => 0,
- 'sort_order' => $item,
- ));
- }
- }
- }
- }
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $topic_id,
- 'mode' => 1,
- 'teacher_id' => $teacherId,
- 'paper_id' =>$paperIds[0]
- ));
- $questionCount = 0;
- $questionScoreStr = '';
- if(isset($v['scores']) && !empty($v['scores'])){
- $scoresArr = explode(',',$v['scores']);
- if($scoresArr){
- $questionCount = count($scoresArr);
- $questionScoreStr = $v['scores'];
- }
- }
- foreach($paperIds as $p)
- {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $p,
- 'topic_id' => $topic_id,
- 'no' => $v['questionNum'],
- 'order' => $v['questionNum'],
- 'mode' => 1,
- 'type' => $_topic_type,
- 'score' =>$v['fullScore'],
- 'question_count' => $questionCount,
- 'question_score_str' => $questionScoreStr
- ));
- }
- if($exam_group_data['mark_type']==4 && !in_array($v['questionTypeId'],array(1,11,2)))
- {
- if(isset($json['new_items'][$k]['alias'])){
- $topicNo=$json['new_items'][$k]['alias'];
- }elseif(isset($v['alias'])){
- $topicNo=$v['alias'];
- }
- if(!$topicNo) $topicNo=$v['questionNum'];
- //判断自动批阅字段
- $autoType=0;
- if($subject_id==8){
- if(in_array($v['marktype'],array(13,16,17)) && !$questionCount){
- $autoType=1;
- }elseif($_topic_type==5){
- $autoType=2;
- }
- }
- $this->sConn->createCommand()->insert('marking_topic', array(
- 'exam_group_id' => $examGroupId,
- 'topic_id' => $topic_id,
- 'topic_type' => $_topic_type,
- 'topic_index' =>$v['questionNum'],
- 'topic_no' =>$topicNo,
- 'topic_score' =>$v['fullScore'],
- 'auto_type'=>$autoType
- ));
- }
- }
- if(!$multiplexId){
- //没有复用记录,初始化一条记录
- $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`) values";
- $insertSql.="('".$examGroupId."','".$name."','".$files['ucloudZipUrl']."','".$files['positionUrl']."','".$files['ucloudPdfUrl']."','".time()."','".time()."')";
- $this->sConn->createCommand($insertSql)->execute();
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $multiplexId=$last_insert_id['last_insert_id()'];
- }else {
- //更新复用记录
- $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}'";
- $this->sConn->createCommand($updateSql)->execute();
- }
- $total = $json['total_score'];
- $topics_count = count($select_info['content']);
- $tpl_data=jsonEncode($json);
- $this->sConn->createCommand("update exam_group set is_answersheet =0 where exam_group_id = ".$examGroupId )->execute();
- $this->sConn->createCommand("update topic_word set status =0,word_path='' where exam_group_id = ".$examGroupId )->execute();
- $this->sConn->createCommand("update exam set tpl_data ='".$tpl_data."' where exam_group_id = ".$examGroupId )->execute();
- $this->sConn->createCommand("update paper set score = ".$total.",topics_count = ".$topics_count.",is_labelled = 0 where paper_id in (".implode(',',$paperIds).")")->execute();
- $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`) ";
- $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."') ";
- $this->sConn->createCommand($insert)->execute();
- $OnlineCardSaveLogModel=new SOnlineCardSaveLog();
- $OnlineCardSaveLogModel->exam_group_id=$examGroupId;
- $OnlineCardSaveLogModel->file_path=$files['ucloudZipUrl'];
- $OnlineCardSaveLogModel->online_card_pdf=$files['ucloudPdfUrl'];
- $OnlineCardSaveLogModel->position=$files['positionUrl'];
- $OnlineCardSaveLogModel->create_time=time();
- $OnlineCardSaveLogModel->save();
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- echo json_encode(array('success'=>0,'message'=>'创建失败'));exit;
- }
- }
- if(!$error){
- echo json_encode(array('success'=>1,'message'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId,'multiplex_id'=>$multiplexId));exit;
- }else{
- echo json_encode(array('success'=>0,'message'=>join(',',$error)));exit;
- }
- }
- //创建考试并下一步ajax
- public function actionCreatethirdForNext(){
- $error = array();
- $tplData = array();
- $semesterId = $this->semesterId;
- $examName = Req::post("examName");
- $type = (int)Req::post("type");
- $classIds = Req::post("classIds");
- $markType = Req::post("markType");
- $teacherId = Req::post("teacherId");
- $subjectId = Req::post("subjectId");
- $textbookId = Req::post("textbookId");
- $examDate = Req::post("examDate");
- $tpl_index = (int)Req::post("tpl_index");
- $qxkPaperId = (int)Req::post("isQxk");
- if(Yii::app()->params['section']==0){
- $tpl_index='1050';
- }
- if(empty($classIds)){
- $error[] = '请指定考试班级';
- }else{
- $classIds = explode(',',$classIds);
- }
- if(empty($examName)){
- $error[] = '请设置考试名称';
- }
- if ($type <= 0 || $type > 9) {
- $error[] = '考试类型错误';
- }
- if(empty($subjectId)){
- $error[] = '请选择题源';
- }
- if(!matchStrChar($examName)){
- $error[] = '考试名称不能包含特殊字符!';
- }
- if(empty($teacherId)){
- $error[] = '请指定阅卷老师';
- }
- if(empty($examDate)){
- $error[] = '请指定考试时间';
- }
- if(empty($tpl_index)){
- $error[] = '请指定类型';
- }
- if($qxkPaperId && in_array($subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }
- if($error){
- echo json_encode(array('status'=>0,'msg'=>join(',',$error)));exit;
- }else{
- $teacherName = Teacher ::model()->getTeacherName($teacherId);
- if($teacherName){
- $tplData['author'] = $teacherName;
- $tplData['subjectId'] = $subjectId;
- $tplData['textbookId'] = $textbookId;
- $tplData['examDate'] = $examDate;
- }
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try{
- $newExamGroupId=getUniqueId($this->schoolId);
- if($markType ==4){
- $markStatus=1;
- $status=1;
- }else{
- $markStatus=0;
- $status=0;
- }
- $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`) "
- . "values (".$newExamGroupId.",".$teacherId.",".$markType.",".$markStatus.",".$status.",".time().",0,1,1,".$qxkPaperId.")";
- $this->sConn->createCommand($sql)->execute();
- foreach($classIds as $classId){
- if(!$classId) continue;
- $newExamId = getUniqueId($this->schoolId);
- $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";
- $cardData = $this->sConn->createCommand($sql)->queryRow();
- if($cardData['card_status']==0){
- $cardData['card_length'] = 8;
- if($this->schoolId >999){
- $cardData['card_length'] = 9;
- }
- }
- $class_type=$cardData['class_type'];
- $this->sConn->createCommand()->insert('exam',array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $newExamGroupId,
- 'name' => $examName,
- 'semester_id' => $this->semesterId,
- 'teacher_id' => $teacherId,
- 'subject_id' => $subjectId,
- 'module_id' => 0,
- 'type' => $type,
- 'school_card_status' => $cardData['card_status'],
- 'school_card_length' => $cardData['card_length'],
- 'status' => 2,
- 'week_num' => 0,
- 'create_type' => 0,
- 'create_time' => $time,
- 'update_time' => $time,
- 'tpl_data' => jsonEncode($tplData),
- 'tpl_index' => $tpl_index,
- 'class_id' => $classId,
- 'method_ids' => '',
- ));
- // $newPaperId = $this->UUID_SHORT();
- $newPaperId= getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => 1,
- 'exam_id' => $newExamId,
- 'paper_name' => '',
- 'paper_layer' => '',
- 'difficulty' => 0,
- 'topics_count' => 0,
- 'score' => 0,
- 'add_time' => $time,
- 'update_time' => $time,
- 'method_ids' => '',
- 'is_labelled' => 0,
- ));
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- if($studentIds_0){
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- 'class_type' =>$class_type
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time' =>$time
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- echo json_encode(array('status'=>0,'msg'=>'创建失败'));exit;
- }
- }
- if(!$error){
- echo json_encode(array('status'=>1,'msg'=>'创建成功','result'=>Yii::app()->createUrl('third/index'),'examGroupId'=>$newExamGroupId));exit;
- }
- }
- public function actionGetOnlinePdf(){
- $semesterId = $this->semesterId;
- $width = Req::post("width");
- $height = Req::post("height");
- $pdfHtml = Req::post("pdfHtml");
- $examGroupId = Req::post("examGroupId");
- if(!$width || !$height){
- $error['success']=0;
- $error['message'] = '缺少纸张大小参数';
- $error['data'] = '';
- echo json_encode($error);exit();
- }
- if(!$pdfHtml){
- $error['success']=0;
- $error['message'] = '缺少模板数据';
- $error['data'] = '';
- echo json_encode($error);exit();
- }
- if(!$examGroupId){
- $error['success']=0;
- $error['message'] = '缺少考试数据';
- $error['data'] = '';
- echo json_encode($error);exit();
- }
- $sendData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$examGroupId,
- 'savedInfoUrl'=>$pdfHtml,
- 'semesterId'=>$semesterId,
- 'width'=>$width,
- 'height'=>$height
- );
- $return=sendDataToKafka('zsyas2-online-card-alone-notify',$sendData);
- $ucloudPdfUrl='';
- if($return){
- $maxTimes=25;
- $server = Yii::app()->params["phpServiceRedis"]["servers"];
- $redis = new Redis();
- $redis->connect($server["host"], $server["port"]);
- if(isset($server['password'])){
- $redis->auth($server['password']);
- }
- $redis->select($server['database']);
- for($i=0;$i<$maxTimes;$i++){
- $redis_get_pdf_status =$redis->get('php_service:exam_group_online_card:'.$examGroupId);
- if($redis_get_pdf_status ){
- $ucloudPdfUrl=$redis_get_pdf_status;
- $redis->set('php_service:exam_group_online_card:'.$examGroupId,'');
- break;
- }
- sleep(1);
- }
- }
- if($ucloudPdfUrl){
- $error['success']=1;
- $error['message'] = '保存成功!';
- $error['data'] = $ucloudPdfUrl;
- }else{
- $error['success']=0;
- $error['message'] = '生成失败';
- $error['data'] = '';
- }
- echo json_encode($error);exit();
- }
- public function actionDownload()
- {
- $url = Req::get('url');
- $title = Req::get('title');
- if (empty($url) ) {
- return false;
- }
- if(!$title) $title=time().'temp';
- $ext=substr($url,strrpos($url,'.')+1);
- $path='upload/tmpDir/downloadTempFiled/';
- if (!file_exists($path)) {
- mkdir($path, 0777, true);
- }
- $pathName=$path.$title.'.'.$ext;
- // 获取远程文件资源
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
- $tempFile = curl_exec($ch);
- curl_close($ch);
- // 保存文件
- $fp = @fopen($pathName, "w");
- fwrite($fp, $tempFile);
- fclose($fp);
- header('content-type:application/octet-stream');
- header('content-disposition:attachment; filename='.get_basename($pathName));
- header('content-length:'.filesize($pathName));
- readfile($pathName);
- }
- //在线答题卡旧版第二步页面
- public function actionThirdCardSecond(){
- $examGroupId = Req::get('examGroupId');
- $this->render('third_card_second',array('examGroupId'=>$examGroupId));
- }
- //复用在线答题卡
- public function actionMultiplex(){
- $multiplexId=Req::post("multiplexId"); //被复用的记录ID
- $name=Req::post("name"); //新答题卡名称
- $result=array();
- $result['status']=0;
- if(!$multiplexId){
- $result['msg']='答题卡ID不能为空';
- exit(json_encode($result));
- }
- if(!$name){
- $result['msg']='答题卡名称不能为空';
- exit(json_encode($result));
- }
- $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();
- if(!$check){
- $result['msg']='答题卡模板不存在';
- exit(json_encode($result));
- }
- if(!$check['is_download']){
- $result['msg']='答题卡尚未下载,如需修改请直接编辑答题卡';
- exit(json_encode($result));
- }
- $onlineCardMultiModel = new SOnlineCardMultiplex();
- $onlineCardMultiModel->exam_group_id = $check['exam_group_id'];
- $onlineCardMultiModel->name = $name;
- $onlineCardMultiModel->file_path = $check['file_path'];
- $onlineCardMultiModel->position = $check['position'];
- $onlineCardMultiModel->online_card_pdf = $check['online_card_pdf'];
- $onlineCardMultiModel->is_qrcode_online = $check['is_qrcode_online'];
- $onlineCardMultiModel->is_download = 0;
- $onlineCardMultiModel->is_copy = 1;
- $onlineCardMultiModel->create_time = time();
- $onlineCardMultiModel->update_time = time();
- if ($onlineCardMultiModel->save()) {
- $result['status'] = 1;
- $result['msg'] = '复用成功';
- $result['data'] = $onlineCardMultiModel->multiplex_id;
- }
- exit(json_encode($result));
- }
- //版本列表切换在线答题卡
- public function actionChangeCard(){
- $multiplexId=Req::post("multiplexId"); //记录ID
- $result=array();
- $result['status']=0;
- $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();
- if(!$check){
- $result['msg']='答题卡模板不存在';
- exit(json_encode($result));
- }
- 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()){
- $result['status']=1;
- $result['msg']='切换成功';
- $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='".$check['exam_group_id']."'")->queryAll();
- $examIds=array();
- foreach ($exam as $item){
- $examIds[]=$item['exam_id'];
- }
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).")")->execute();
- $this->sConn->createCommand("delete from exam_process where exam_group_id='".$check['exam_group_id']."' and action_type in(9,13,14)")->execute();
- }
- exit(json_encode($result));
- }
- //下载标记
- public function actionDownloadStatus(){
- $multiplexId=Req::post("multiplexId"); //记录ID
- $result=array();
- $result['status']=0;
- if(!$multiplexId) {
- $result['msg']='答题卡Id不能为空';
- exit(json_encode($result));
- }
- $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();
- if(!$check){
- $result['msg']='答题卡模板不存在';
- exit(json_encode($result));
- }
- $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
- $this->schoolManager->saveExamProcess($check['exam_group_id'],9,time());
- $result['status']=1;
- $result['msg']='更新成功';
- exit(json_encode($result));
- }
- //隐藏答题卡
- public function actionHideAnswerCard(){
- $multiplexId=Req::post("multiplexId"); //记录ID
- $isHide=Req::post("isHide"); //记录ID
- if(!$isHide) $isHide=0;
- $result=array();
- $result['status']=0;
- if(!$multiplexId) {
- $result['msg']='答题卡Id不能为空';
- exit(json_encode($result));
- }
- $this->sConn->createCommand("update online_card_multiplex set is_hide={$isHide} where multiplex_id='{$multiplexId}'")->execute();
- $result['status']=1;
- $result['msg']='更新成功';
- exit(json_encode($result));
- }
- //复用的答题卡编辑后保存
- private function saveMultiplex(){
- $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
- $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- //上传答题卡相关文件
- $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
- $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();
- $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow();
- if($thirdAnswer['multiplex_id']==$multiplexId){
- $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();
- }
- echo json_encode(array('status'=>1,'msg'=>'创建成功','data'=>Yii::app()->createUrl('third/index'),'exam_group_id'=>$examGroupId));exit;
- }
- //读取在线答题卡复用内容
- public function actionGetMultiplex(){
- $multiplexId=Req::post("multiplexId"); //记录ID
- $result=array();
- $result['status']=0;
- $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();
- if(!$check){
- $result['msg']='答题卡模板不存在';
- exit(json_encode($result));
- }
- //判断全学科
- $examGroup=$this->sConn->createCommand("select qxk_paper_id,is_third from exam_group where exam_group_id='".$check['exam_group_id']."'")->queryRow();
- $examData=$this->sConn->createCommand("select tpl_data,exam_id,subject_id from exam where exam_group_id='{$check['exam_group_id']}'")->queryAll();
- //判断全学科白名單
- $check['new_answer_sheet_subject']=0;
- if($examGroup['qxk_paper_id'] && $examGroup['is_third']==0){
- $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$examData[0]['subject_id'],'GET',$this->schoolId,array(),'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- $check['new_answer_sheet_subject']=1;
- }
- }
- if($check['position']){
- if(strpos($check['position'],'http://')!==false || strpos($check['position'],'https://')!==false){
- $check['position']=fileGetContents($check['position']);
- }
- }
- $result['data']=$check;
- exit(json_encode($result));
- }
- //加载考试完成考试复用试卷 最近30场完成解析的考试
- public function actionLoadCopyPaper(){
- $grade=Req::post('grade');
- $examGroupId=Req::post('examGroupId');
- $condition=array();
- $subject=$this->subjectId;
- $condition[]='eg.is_third=1';
- // $condition[]='e.status=1';
- $condition[]='tw.status=2';
- $condition[]="eg.exam_group_id<>'".$examGroupId."'";
- if($subject==3){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[]="e.subject_id ='".$subject."'";
- }
- if($grade){
- $condition[]="c.grade='".$grade."'";
- }
- $sql="SELECT eg.exam_group_id,e.name,e.tpl_data,e.create_time FROM `exam` e ";
- $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
- $sql.="join class c on c.class_id=e.class_id ";
- $sql.=" join topic_word tw on tw.exam_group_id=e.exam_group_id ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $sql.=" group by eg.exam_group_id order by e.create_time desc limit 30";
- $list=array();
- $exam = $this->sConn->createCommand($sql)->queryAll();
- if($exam){
- foreach ($exam as $value){
- $tplData=json_decode($value['tpl_data'],true);
- $list[]=array(
- 'name'=>$value['name'],
- 'create_time'=>date('Y-m-d',$value['create_time']),
- 'exam_date'=>$tplData['examDate'],
- 'exam_group_id'=>$value['exam_group_id']
- );
- }
- }
- $result['status']=1;
- $result['data']=$list;
- exit(json_encode($result));
- }
- //复用考试,试题结构
- public function actionCopyPaperTopic(){
- $nowExamId = Req::post('examGroupId'); //当前考试
- $copyExamId = Req::post('copyExamGroupId'); //复制结构的考试
- $result['status']=0;
- //读取当前考试试题结构
- $nowPaperTopicRelation = array();
- $examIds = array();
- $paperIds = array();
- $examGroup = $this->sConn->createCommand("select upload_status,mark_type from exam_group where exam_group_id={$nowExamId}")->queryRow();
- if (!$examGroup) {
- $result['msg'] = "考试id不正确";
- exit(json_encode($result));
- }
- if($examGroup['upload_status']>0){
- $result['msg']="已上传成绩,不能复用";
- exit(json_encode($result));
- }
- $exam = $this->sConn->createCommand("select exam_id,upload_status,tpl_data from exam where exam_group_id={$nowExamId}")->queryAll();
- foreach ($exam as $value) {
- $examIds[] = $value['exam_id'];
- $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$value['exam_id']}")->queryRow();
- $paperIds[] = $paper['paper_id'];
- }
- $tplData=json_decode($exam[0]['tpl_data'],true);
- $nowPaperTopicRelation = $this->sConn->createCommand("select `order`,`type`,`topic_id`,`stem_id` from paper_topic_relation where paper_id={$paperIds[0]}")->queryAll();
- if (!$nowPaperTopicRelation) {
- $result['msg'] = "未创建答题卡";
- exit(json_encode($result));
- }
- $checkArr = array();
- $historyTopic = array();
- foreach ($nowPaperTopicRelation as $val) {
- $checkArr[$val['order']] = $val['type'];
- $checkOrderTopic[$val['order']] = $val['topic_id'];
- $historyTopic[$val['order']] = array(
- 'topic_id' => $val['topic_id'],
- 'type' => $val['type'],
- 'stem_id'=> $val['stem_id']
- );
- }
- //读取复制的考试结构
- $copyPaperTopicRelation = array();
- $exam = $this->sConn->createCommand("select exam_id,tpl_data from exam where exam_group_id={$copyExamId}")->queryRow();
- $paper = $this->sConn->createCommand("select paper_id from paper where exam_id={$exam['exam_id']}")->queryRow();
- $topicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$copyExamId}")->queryRow();
- $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();
- $checkArrCopy = array();
- $copyTopicOrder = array();
- foreach ($copyPaperTopicRelation as $val) {
- $checkArrCopy[$val['order']] = $val['type'];
- $copyTopicOrder[$val['order']] = array(
- 'topic_id' => $val['topic_id'],
- 'method_ids' => $val['method_ids'],
- 'method_difficulty' => $val['method_difficulty'],
- 'type'=>$val['type'],
- 'stem_id'=>$val['stem_id']
- );
- }
- if(strcmp(json_encode($checkArr),json_encode($checkArrCopy))!==0){
- $result['msg']="两场考试试题结构不相同,不能复用";
- exit(json_encode($result));
- }
- if(isset($tplData['new_items'])){
- foreach($tplData['new_items'] as $key => $item){
- if(isset($copyTopicOrder[$item['id']])){
- $tplData['new_items'][$key]['topicId']=$copyTopicOrder[$item['id']]['topic_id'];
- $tplData['new_items'][$key]['stemId']=$copyTopicOrder[$item['id']]['stem_id'];
- }
- }
- }
- //开始复用
- $updateArr = array();
- $updateMarkingTopicArr=array();
- foreach ($checkOrderTopic as $key => $val) {
- $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'] . "' ";
- $sql .= " where paper_id in(" . implode(',', $paperIds) . ") and topic_id={$val}";
- $updateArr[] = $sql;
- if($examGroup['mark_type']==4 && !in_array($copyTopicOrder[$key]['type'],array(1,2,11))){
- $markingTopicSql="update marking_topic set topic_id='".$copyTopicOrder[$key]['topic_id']."' where exam_group_id='{$nowExamId}' and topic_id='{$val}'";
- $updateMarkingTopicArr[]=$markingTopicSql;
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- foreach ($updateArr as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- if($updateMarkingTopicArr){
- foreach ($updateMarkingTopicArr as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- if($examGroup['mark_type']!=4){
- $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$nowExamId}'")->execute();
- }
- $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id='{$nowExamId}'")->execute();
- $nowTopicWord = $this->sConn->createCommand("select * from topic_word where exam_group_id={$nowExamId}")->queryRow();
- $this->sConn->createCommand("update exam_group set is_answersheet=1 where exam_group_id='" . $nowExamId . "'")->execute();
- if ($nowTopicWord) {
- $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();
- } else {
-
- $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
- $wordId = current(current($uuid));
- $topic_word_odj = new STopicWord();
- $topic_word_odj->word_id = $wordId;
- $topic_word_odj->exam_group_id = $nowExamId;
- $topic_word_odj->word_name = $topicWord['word_name'];
- $topic_word_odj->word_path = $topicWord['word_path'];
- $topic_word_odj->word_md5 = '';
- $topic_word_odj->word_size = $topicWord['word_size'];
- $topic_word_odj->subject_id = $topicWord['subject_id'];
- $topic_word_odj->status = 2;
- $topic_word_odj->uploader_id = $this->coachId;
- $topic_word_odj->upload_time = time();
- $topic_word_odj->is_history_topic = jsonEncode($historyTopic);
- $topic_word_odj->save();
- }
- $transaction->commit();
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $nowExamId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '复用考试',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $result['status'] = 1;
- } catch (Exception $e) {
- $transaction->rollBack();
- $result['msg']="复用失败";
- }
- exit(json_encode($result));
- }
- //生成二维码
- public function actionCreateQrcode(){
- $examGroupId = Req::post("examGroupId"); //记录ID
- $result['status']=0;
- if(!$examGroupId){
- $result['msg']='考试Id不能为空';
- exit(json_encode($result));
- }
- $QRcode = new \QRcode();
- $level = 'L';// 纠错级别:L、M、Q、H
- $size = 100;//元素尺寸
- $margin = 1;//边距
- $path='upload/tmpDir/qrCode/';
- if (!file_exists($path)) {
- mkdir($path, 0777, true);
- }
- $outfile=$path.$examGroupId.'.png';
- $saveandprint = false;// true直接输出屏幕 false 保存到文件中
- $back_color = 0xFFFFFF;//白色底色
- $fore_color = 0x000000;//黑色二维码色 若传参数要hexdec处理,如 $fore_color = str_replace('#','0x',$fore_color); $fore_color = hexdec('0xCCCCCC');
- $QRcode->png($examGroupId, $outfile, $level, $size, $margin, false, $back_color, $fore_color);
- if(file_exists($outfile)){
- $ucloud = new HuaweiCloud();
- $uploadUrl='zsyas2/third/qrcode/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $examGroupId. '.png';
- $uploadInfo = $ucloud->putFile($uploadUrl, $outfile);
- if ($uploadInfo['status'] == 0) {
- @unlink($outfile);
- $result['status']=0;
- $result['msg'] = '文件上传失败!';
- }else{
- @unlink($outfile);
- $result['data'] = $uploadInfo['url'];
- $result['status']=1;
- }
- }else{
- $result['status']=0;
- $result['msg'] = '文件生成失败!';
- }
- exit(json_encode($result));
- }
- //切换答题卡,清空模板数据
- public function actionClearAnswerCard()
- {
- $examGroupId = Req::post("examGroupId"); //考试ID
- $type = Req::post("type"); //答题卡类型
- /*
- * 是否制作模板及类型
- * 判断是否上传答题卡
- * 是否解析
- * 是否标注
- *
- * 清空 paper_topic_relation
- * tpl_data new_items items
- * topic topic_item_option
- * marking_topic
- * //删除数据
- *
- */
- $examGroup = SExamGroup::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
- if (!$examGroup) {
- $result['status'] = 0;
- $result['msg'] = '考试ID不存在';
- exit(json_encode($result));
- }
- if ($examGroup['is_answersheet'] == 1) {
- $result['status'] = 0;
- $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板';
- exit(json_encode($result));
- }
- if ($examGroup['is_tagging'] == 1) {
- $result['status'] = 0;
- $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板';
- exit(json_encode($result));
- }
- $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();
- if ($thirdMultiTemplate) {
- $result['status'] = 0;
- $result['msg'] = '本场考试已上传试卷,不支持再切换答题卡模板';
- exit(json_encode($result));
- }
- $exam = Exam::model()->findAll('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
- $tplData = json_decode($exam[0]['tpl_data'], true);
- $thirdAnswerSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id', array(':exam_group_id' => $examGroupId));
- if (!$thirdAnswerSheet) {
- $result['status'] = 0;
- $result['msg'] = '未制作答题卡';
- exit(json_encode($result));
- }
- $examIds = array();
- $paperIds = array();
- $topicIds = array();
- foreach ($exam as $item) {
- $examIds[] = $item['exam_id'];
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id', $examIds);
- $paper = SPaper::model()->findAll($criteria);
- foreach ($paper as $item) {
- if ($item['is_labelled'] > 0) {
- $result['status'] = 0;
- $result['msg'] = '本场考试已发送标注,不支持再切换答题卡模板';
- exit(json_encode($result));
- }
- $paperIds[] = $item['paper_id'];
- }
- $paperTopic = SPaperTopicRelation::model()->findAll('paper_id=:pid', array(':pid' => $paperIds[0]));
- foreach ($paperTopic as $item) {
- $topicIds[] = $item['topic_id'];
- }
- //查询是否有上传数据
- $rs = $this->sConn->createCommand("select id from student_paper_topic_rs where paper_id in(" . implode(',', $paperIds) . ") limit 1")->queryRow();
- if ($rs) {
- $result['status'] = 0;
- $result['msg'] = '本场考试已上传学生答题卡,不支持再切换答题卡模板';
- exit(json_encode($result));
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- if($topicIds){
- $this->sConn->createCommand("delete from topic where topic_id in (" . implode(',', $topicIds) . ")")->execute();
- $this->sConn->createCommand("delete from topic_item where topic_id in (" . implode(',', $topicIds) . ")")->execute();
- $this->sConn->createCommand("delete from topic_item_option where topic_id in (" . implode(',', $topicIds) . ")")->execute();
- }
- $this->sConn->createCommand("delete from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")")->execute();
- $this->sConn->createCommand("delete from marking_topic where exam_group_id =" . $examGroupId)->execute();;
- $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id =" . $examGroupId)->execute();;
- $this->sConn->createCommand("delete from topic_word where exam_group_id =" . $examGroupId)->execute();
- $this->sConn->createCommand("delete from online_card_multiplex where exam_group_id =" . $examGroupId)->execute();
- $this->sConn->createCommand("delete from exam_push_topics_setting where exam_group_id =" . $examGroupId)->execute();
- unset($tplData['items']);
- unset($tplData['new_items']);
- unset($tplData['new_rules']);
- unset($tplData['update_answer']);
- if (isset($tplData['totals'])) $tplData['totals'] = 0;
- if (isset($tplData['scores'])) $tplData['scores'] = 0;
- if (isset($tplData['total_score'])) $tplData['total_score'] = 0;
- $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id='" . $examGroupId . "'")->execute();
- $transaction->commit();
- if (Yii::app()->params['handle_log_on_off']) {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '清空答题卡',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" => json_encode(array('post' => $_POST, 'get' => $_GET)),
- "date" => date('Y-m-d H:i:s')
- )));
- }
- $result['status'] = 1;
- } catch (\Exception $e) {
- $transaction->rollBack();
- $result['status'] = 0;
- $result['msg'] = '清空答题卡数据失败';
- }
- exit(json_encode($result));
- }
-
- // 上传试卷模板
- public function actionNewUploadTpl(){
- $exam_group_id = Req::post('eid');
- $upload_type = Req::post('uploadType'); //上传类型
- $allowFileNameArr=array('word_file','paper_file','parse_file');
- $error['success'] = 0;
- if (empty($exam_group_id)) {
- $error['message'] = '考试id不存在!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($examInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- $examIds=array();
- foreach ($examInfo as $value){
- $examIds[]=$value->exam_id;
- }
- $thirdSheet = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if (empty($thirdSheet)) {
- $error['message'] = '尚未上传答题卡!';
- echo json_encode($error);exit();
- }
- $topicWord=STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($topicWord){
- if($topicWord->allsubject_file_path && $topicWord->status!=3 && $topicWord->status!=7){
- $error['message'] = '试卷已经上传,请勿重复上传!';
- echo json_encode($error);exit();
- }
- if(($upload_type==1 && $topicWord->word_path) || ($upload_type==2 && $topicWord->allsubject_file_path)){
- $error['message'] = '已经上传试卷,不能切换解析模式!';
- echo json_encode($error);exit();
- }
- }
-
- $fileUrlArr=array();
- $file_max_size = 11 * 1024 * 1024;
- foreach ($_FILES as $key =>$val){
- if(in_array($key,$allowFileNameArr)){
- if(!is_uploaded_file($_FILES[$key]['tmp_name'])){
- if($key=='paper_file' && $upload_type==1){
- $error['message'] = '非法上传!';
- echo json_encode($error);exit();
- }else{
- continue;
- }
- }
- if ($_FILES[$key]["size"] > $file_max_size) {
- $error['message'] = '文件超过最大限制,最大为10M';
- echo json_encode($error);exit();
- }
- if ($_FILES[$key]['error'] > 0) {
- switch ($_FILES[$key]['error']) {
- case 1:
- $error['message'] = '文件大小超出了服务器的空间大小!';
- break;
- case 2:
- $error['message'] = '要上传的文件大小超出浏览器限制!';
- break;
- case 3:
- $error['message'] = '文件只有部分被上传!';
- break;
- case 4:
- $error['message'] = '没有找到要上传的文件!';
- break;
- case 5:
- $error['message'] = '服务器临时文件夹丢失!';
- break;
- case 6:
- $error['message'] = '文件写入到临时文件夹出错!';
- break;
- }
- echo json_encode($error);exit();
- }
- // 保存上传文件至服务器
- $extName = substr($_FILES[$key]['name'],strrpos($_FILES[$key]['name'],'.'));
- $fileName = $exam_group_id.$extName;
- $wordRename = 'zsyas2/third/words/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $fileName;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($wordRename, $_FILES[$key]['tmp_name']);
- if ($uploadInfo['status'] == 0) {
- echo json_encode(array('success' => 0, 'message' => $uploadInfo['msg']));
- exit();
- }
- if(strpos($key,'paper_file')!==false){
- $fileUrlArr[]=array(
- 'file_type'=>1,
- 'file_url'=>str_replace("%2F","/",$uploadInfo['url']),
- 'file_name'=>$_FILES[$key]['name']
- );
- }elseif(strpos($key,'parse_file')!==false){
- $fileUrlArr[]=array(
- 'file_type'=>2,
- 'file_url'=>str_replace("%2F","/",$uploadInfo['url']),
- 'file_name'=>$_FILES[$key]['name']
- );
- }else{
- $fileUrlArr[] = str_replace("%2F","/",$uploadInfo['url']);
- }
- }
- }
- if(!$fileUrlArr){
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }
-
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "title" => '第三方试卷上传试卷',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "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))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$uploadInfo['url'])),
- ));
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- $time = time();
- $this->sConn->createCommand("update exam_group set is_answersheet=0 where exam_group_id='{$exam_group_id}'")->execute();
- STopicWord::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //$this->sConn->createCommand("update paper set is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute();
- $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 6)")->queryAll();
- $wordId = current(current($uuid));
- $topic_word_odj = new STopicWord();
- $topic_word_odj->word_id = $wordId;
- $topic_word_odj->exam_group_id = $exam_group_id;
- $topic_word_odj->word_name = '第三方试卷'.$fileName;
- if($upload_type==1){
- $topic_word_odj->allsubject_file_path = json_encode($fileUrlArr);
- }elseif($upload_type==2){
- $topic_word_odj->word_path = implode(',',$fileUrlArr);
- }
- $topic_word_odj->word_md5 = '';
- $topic_word_odj->word_size = 0;
- $topic_word_odj->subject_id = $examInfo[0]->subject_id;
- $topic_word_odj->status = 0;
- $topic_word_odj->type_id = 3;
- $topic_word_odj->uploader_id = $this->coachId;
- $topic_word_odj->upload_time = $time;
- $topic_word_odj->save();
- $transcation->commit();
- }
- catch (Exception $e)
- {
- $transcation->rollback();
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- $this->schoolManager->saveExamProcess($exam_group_id,3,time());
- $error['success'] = 1;
- $error['message'] = '上传文件成功!';
- echo json_encode($error);exit();
- }
- public function actionViewPaper(){
- $pid = Req::get('pid');
- if(!$pid) Yii::app()->jump->error('解析尚未完成,或未生成预览');
- $data=array('pid'=>$pid);
- $this->renderPartial('view_paper',$data);
- }
- //创建考试加载班级
- public function actionAjaxGetClassByTeacherGrade(){
- $grade = Req::post('grade');
- $teacherId = Req::post('teacherId');
- $selectClassData = Req::post('selectClassData');
- if(!$selectClassData) $selectClassData=array();
- $result['status']=0;
- if (Yii::app()->request->getIsPostRequest()){
- $selectedClass=array();
- if($selectClassData){
- foreach ($selectClassData as $datum){
- $selectedClass[(string)$datum]=$datum;
- }
- }
- //读取走班设置
- $setting=$this->schoolManager->getClassifiedBySubject($grade,$this->subjectId,$this->semesterId);
- //读取执教班级
- $teacherClassSelectData=array();
- $getTeacherClass = ClassModel ::model()->getSelectclassesByTeacherGrade($this->semesterId,$teacherId,$grade);
- foreach ($getTeacherClass as $val){
- $teacherClassSelectData[(string)$val['class_id']]=$val;
- }
- //查询年级所有班级
- $allClassList=array();
- if($setting['status']==1){
- $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=2",array(':gid'=>$grade,':sid'=>$this->semesterId));
- }else{
- $classes=ClassModel::model()->findAll("grade=:gid and semester_id=:sid and class_type=1",array(':gid'=>$grade,':sid'=>$this->semesterId));
- }
- if($classes){
- foreach ($classes as $class){
- if($class['is_hide']==1){
- continue;
- }
- $temp=array(
- 'class_id'=>$class['class_id'],
- 'class_name'=>$class['class_name'],
- 'arts_science'=>$class['arts_science'],
- 'selected'=>0
- );
- if($selectedClass){
- if(isset($selectedClass[(string)$class['class_id']])){
- $temp['selected']=1;
- }
- }else{
- if(isset($teacherClassSelectData[(string)$class['class_id']])){
- $temp['selected']=1;
- }
- }
- $allClassList[]=$temp;
- }
- }
- $result['status']=1;
- $result['msg']='success';
- $result['data']=$allClassList;
- }
- exit(json_encode($result));
- }
- //验证第三方选做题分组
- public function actionCheckSelectTopicGroup()
- {
- $examGroupId = Req::post("exam_group_id");
- if($examGroupId>0)
- {
- $examData = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- $tplData=json_decode($examData['tpl_data'],true);
- if(isset($tplData['new_items'])){
- foreach($tplData['new_items'] as $item){
- if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
- echo json_encode(array('status'=>1));exit;
- }
- }
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- //生成签名
- public function actionCreateSign(){
- $eid = Req::post('eid');
- if(YII_ENV=='production'){
- $appId='946004280126791680'; //线上
- }else{
- $appId='939792767984566272'; //测试
- }
-
- $time=time();
- $params=array(
- 'appId'=>$appId,
- 'timestamp'=>$time
- );
- $params['certificate']=$eid.'_'.$this->schoolId;
- $vSign=$this->getSignature($appId,$time,'654321',$params);
- $result['status'] = 1;
- $result['sign'] = $vSign;
- $result['time'] = $time;
- $result['certificate'] = $params['certificate'];
- echo json_encode($result);exit();
- }
- private function getSignature($appId,$timestamp,$secret,$params)
- {
- $subfix='';
- if ($params) {
- ksort($params, SORT_STRING);
- $subfix = http_build_query($params);
- }
- $signature = base64_encode(hash_hmac("sha1", $appId . $timestamp . $secret . $subfix, $secret));
- return strtoupper(md5($signature));
- }
- public function actionUploadHw(){
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile('images/avatar.png', 'images/avatar.png');
- debug($uploadInfo);
- }
- }
|