ClassesController.php 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315
  1. <?php
  2. /**
  3. * 班级管理控制器类
  4. * @author jiangfei
  5. * @date 2015-09-22 10:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class ClassesController extends Controller{
  9. // 班级等级水平
  10. protected $class_level = array(
  11. "A" => array('A',0,59),
  12. "B" => array('B',60,85),
  13. "C" => array('C',86,100)
  14. );
  15. //protected $material_url = 'http://wybrain.xueping365.com/rest/textbook/tree';
  16. //protected $material_param = 'subjectId=3&depth=3';
  17. // 首页
  18. public function actionIndex(){
  19. $data = array();
  20. $realname = Req::get("realname");
  21. $grade_id = Req::get("grade_id");
  22. $arts_science = Req::get("arts_science");
  23. $class_type = (int)Req::get("class_type"); //班级类型 1行政,2教学
  24. $subject_id = (int)Req::get("subject_id");
  25. $show_type = (int)Req::get('show_type'); //是否显示隐藏班级
  26. if(!$show_type){
  27. $show_type=0;
  28. }else{
  29. $show_type=1;
  30. }
  31. $teachers = array();
  32. // 获取所有学期
  33. $criteria = new CDbCriteria;
  34. $criteria->limit = 10;
  35. $criteria->order = "create_time desc";
  36. $allSemester = Semester::model()->findAll($criteria);
  37. if(!$class_type || !in_array($class_type,array(1,2))) $class_type=1;
  38. $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
  39. if(empty($smid)){
  40. $semeseter_id = $this->semesterId;
  41. }
  42. else{
  43. $semeseter_id = $smid;
  44. }
  45. $semesterId = $semeseter_id;
  46. //走班学科筛选
  47. $classIds=array(); //学科筛选班级id
  48. if($class_type==2 && $subject_id){
  49. $classIds=$this->schoolManager->getClassIdBySubjectId($subject_id,$semesterId);
  50. }
  51. // 判断是否教员组长
  52. if($semesterId){
  53. if($grade_id)
  54. {
  55. $con[] = "seme.semester_id = '{$semesterId}'";
  56. $con[] = "c.grade=".$grade_id;
  57. }else
  58. {
  59. $con[] = "seme.semester_id = '{$semesterId}'";
  60. }
  61. if($realname)
  62. {
  63. // $_class_ids = $this->schoolManager->getTeachersByteacherName($realname);
  64. //
  65. // if($class_type==2 && $subject_id && $classIds){
  66. // $classIds=array_intersect($classIds,$_class_ids);
  67. // }elseif($_class_ids){
  68. // $con[] = "c.class_id in (".implode(',',$_class_ids).")";
  69. // }else{
  70. // $con[] = "c.class_id in (0)";
  71. // }
  72. $con[] = "c.class_name like '%".$realname."%'";
  73. }
  74. if($classIds){
  75. $con[] = "c.class_id in (".implode(',',$classIds).")";
  76. }
  77. if($arts_science){
  78. $con[] = "c.arts_science=".$arts_science;
  79. }
  80. $con[]=" c.class_type=".$class_type;
  81. $con[]=" c.is_hide=".$show_type;
  82. $rs = $this->schoolManager->getClassesDetailListre($con,9);
  83. }
  84. // debug($rs["rs"]);
  85. if($rs["rs"]){
  86. $classesIds = array();
  87. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
  88. if($class_data)
  89. {
  90. foreach($class_data as $class){
  91. $classesIds[] = $class->class_id;
  92. }
  93. }
  94. $teachers = $this->schoolManager->getClassesTeachers($classesIds);
  95. if(!$teachers && false){
  96. $rs["rs"] = array();
  97. }else{
  98. foreach($rs["rs"] as $key => $class){
  99. if(isset($teachers[(string)$class["class_id"]]) && !empty($teachers[(string)$class["class_id"]]))
  100. {
  101. $rs["rs"][$key]["teachers"] = implode(',',$teachers[(string)$class["class_id"]]);
  102. }else
  103. {
  104. $rs["rs"][$key]["teachers"] = '';
  105. // unset($rs["rs"][$key]);
  106. }
  107. /*foreach($teachers as $teacher){
  108. if($teacher["class_id"] == $class["class_id"]){
  109. $rs["rs"][$key]["teachers"] = $teacher["teachers_names"];
  110. }
  111. }*/
  112. //判断班主任
  113. if($class['teacher_id']){
  114. $teacherInfo = Teacher::model()->find('teacher_id=:tid', array(':tid' => $class['teacher_id']));
  115. $rs["rs"][$key]["bzr"]=$teacherInfo;
  116. }
  117. }
  118. }
  119. }
  120. $currSemester = $this->schoolManager->getCurrSemester();
  121. /**
  122. * 转班
  123. */
  124. $_semesters = $this->getFinishSemesters();
  125. if($_semesters)
  126. {
  127. $data['_semester'] = $_semesters;
  128. $_currClass = $this->schoolManager->getSemesterClasses($currSemester['semester_id']);
  129. if($_currClass)
  130. {
  131. foreach($_currClass as $v)
  132. {
  133. $data['_currClass'][$v['grade']][$v['class_id']] = $v;
  134. }
  135. }
  136. if(!empty($_semesters['semesters']))
  137. {
  138. $data['_fluClass'] = $this->schoolManager->getSemesterClassesStudent($_semesters['semesters']->semester_id);
  139. }else
  140. {
  141. $data['_fluClass'] = array();
  142. }
  143. }
  144. $data["class_type"] = $class_type;
  145. if($class_type==2 ){
  146. $setting=$this->schoolManager->getClassShift($this->semesterId);
  147. if(!$setting){
  148. //进入走班说明页面
  149. return $this->render('explain',$data);
  150. }
  151. }
  152. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  153. $data['subjects']=Yii::app()->params['subjectId'];
  154. unset($data['subjects'][6]);
  155. unset($data['subjects'][18]);
  156. unset($data['subjects'][19]);
  157. unset($data['subjects'][51]);
  158. if(isset($data['subjects'][20])) unset($data['subjects'][20]);
  159. }
  160. $data["grade_id"] = $grade_id;
  161. $data["arts_science"] = $arts_science;
  162. $data["realname"] = $realname;
  163. $data["currSemester"] = $currSemester;
  164. $data['yearsList'] = $rs["rs"];
  165. $data['pages'] = $rs["pager"];
  166. $data['page_total'] = $rs["pager"]->rowsCount;
  167. //$data['allSemester'] = $allSemester;
  168. $data['semeseter_id'] = $semeseter_id;
  169. $data["semesters"] = $allSemester;
  170. $data["semesterId"] = $semesterId;
  171. $data["class_type"] = $class_type;
  172. $data["show_type"] = $show_type;
  173. $data["subject_id"] = $subject_id;
  174. $data["thisSemester"] = $this->schoolManager->getSemester($semesterId);
  175. $model = new Model();
  176. $data["model"] = $model;
  177. //unset($classList,$classInfo);
  178. // var_dump($rs["pager"]);exit;
  179. $this->render('index',$data);
  180. }
  181. protected function getFinishSemesters()
  182. {
  183. $data = array();
  184. $currSemester = $this->schoolManager->getCurrSemester();
  185. $criteria = new CDbCriteria;
  186. $criteria->addCondition('end_time <= :start_time');
  187. $criteria->params[':start_time'] = $currSemester['start_time'];
  188. $criteria->limit = 1;
  189. $criteria->order = "end_time desc";
  190. $_allSemester = Semester::model()->find($criteria);
  191. $data['currSemester'] = $currSemester;
  192. $data['semesters'] = $_allSemester;
  193. return $data;
  194. }
  195. //转入单个班
  196. public function actionInto_alone_class()
  197. {
  198. if (Yii::app()->request->getIsPostRequest()) {
  199. $alone_one_f_class = Req::post("alone_one_f_class");
  200. $alone_one_c_class = Req::post("alone_one_c_class");
  201. $alone_two_f_class = Req::post("alone_two_f_class");
  202. $alone_two_c_class = Req::post("alone_two_c_class");
  203. $alone_three_f_class = Req::post("alone_three_f_class");
  204. $alone_three_c_class = Req::post("alone_three_c_class");
  205. $transfer_class = array();
  206. $msg = '';
  207. $old_class_id = '';
  208. $new_class_id = '';
  209. if($alone_one_c_class && $alone_one_f_class)
  210. {
  211. $transfer_class[$alone_one_f_class] = $alone_one_c_class;
  212. $old_class_id = $alone_one_f_class;
  213. $new_class_id = $alone_one_c_class;
  214. }
  215. if($alone_two_f_class && $alone_two_c_class)
  216. {
  217. $transfer_class[$alone_two_f_class] = $alone_two_c_class;
  218. $old_class_id = $alone_two_f_class;
  219. $new_class_id = $alone_two_c_class;
  220. }
  221. if($alone_three_f_class && $alone_three_c_class)
  222. {
  223. $transfer_class[$alone_three_f_class] = $alone_three_c_class;
  224. $old_class_id = $alone_three_f_class;
  225. $new_class_id = $alone_three_c_class;
  226. }
  227. if($transfer_class)
  228. {
  229. //操作日志
  230. if(Yii::app()->params['handle_log_on_off'])
  231. {
  232. writeFileLog(jsonEncode(array(
  233. "exam_group_id" => 0,
  234. "operate_project" => 'zsyas2',
  235. "school_id" => $this->schoolId,
  236. "title" => '单个级转移',
  237. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  238. "operate_method" => $this->action,
  239. "operate_url" => $this->getRoute(),
  240. "operate_sql" =>'',
  241. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  242. "date"=>date('Y-m-d H:i:s')
  243. )));
  244. }
  245. $msg = $this->gotoClasses($transfer_class,array($old_class_id),array($new_class_id));
  246. if($msg)
  247. {
  248. $str = '';
  249. $i=0;
  250. foreach($msg as $k=>$v)
  251. {
  252. $str .= (++$i).'、'.$v.PHP_EOL;
  253. }
  254. Yii::app()->jump->setErrorWait(20);
  255. if($i>2)
  256. {
  257. Yii::app()->jump->setHeight(100);
  258. }else
  259. {
  260. Yii::app()->jump->setHeight((100+($i*40)));
  261. }
  262. Yii::app()->jump->error($str);exit;
  263. }else
  264. {
  265. Yii::app()->jump->success('转班成功<br>',Yii::app()->createUrl('classes/index'));exit;
  266. }
  267. }else
  268. {
  269. Yii::app()->jump->error('尚未选择班级!');
  270. }
  271. }
  272. }
  273. //转多个班
  274. public function actionInto_multi_class()
  275. {
  276. if (Yii::app()->request->getIsPostRequest()) {
  277. $one_class = Req::post("one_class");
  278. $two_class = Req::post("two_class");
  279. $three_class = Req::post("three_class");
  280. $flags = 0;
  281. $transfer_class = array();
  282. $old_class_id = array();
  283. $new_class_id = array();
  284. if($one_class)
  285. {
  286. foreach($one_class as $k=>$v)
  287. {
  288. if($v)
  289. {
  290. if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
  291. {
  292. Yii::app()->jump->error('不能重复的班级同一班级!');
  293. }else
  294. {
  295. $old_class_id[$v] = $v;
  296. }
  297. $transfer_class[$v] = $k;
  298. }
  299. if($k)
  300. {
  301. $new_class_id[$k] = $k;
  302. }
  303. }
  304. }
  305. if($two_class)
  306. {
  307. foreach($two_class as $k=>$v)
  308. {
  309. if($v)
  310. {
  311. if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
  312. {
  313. Yii::app()->jump->error('不能重复的班级同一班级!');
  314. }else
  315. {
  316. $old_class_id[$v] = $v;
  317. }
  318. $transfer_class[$v] = $k;
  319. }
  320. if($k)
  321. {
  322. $new_class_id[$k] = $k;
  323. }
  324. }
  325. }
  326. if($three_class)
  327. {
  328. foreach($three_class as $k=>$v)
  329. {
  330. if($v)
  331. {
  332. if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
  333. {
  334. Yii::app()->jump->error('不能重复的班级同一班级!');
  335. }else
  336. {
  337. $old_class_id[$v] = $v;
  338. }
  339. $transfer_class[$v] = $k;
  340. }
  341. if($k)
  342. {
  343. $new_class_id[$k] = $k;
  344. }
  345. }
  346. }
  347. if(!$transfer_class)
  348. {
  349. Yii::app()->jump->error('尚未选择班级!');
  350. }
  351. //操作日志
  352. if(Yii::app()->params['handle_log_on_off'])
  353. {
  354. writeFileLog(jsonEncode(array(
  355. "exam_group_id" => 0,
  356. "operate_project" => 'zsyas2',
  357. "school_id" => $this->schoolId,
  358. "title" => '多班级转移',
  359. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  360. "operate_method" => $this->action,
  361. "operate_url" => $this->getRoute(),
  362. "operate_sql" =>'',
  363. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  364. "date"=>date('Y-m-d H:i:s')
  365. )));
  366. }
  367. $msg = $this->gotoClasses($transfer_class,$old_class_id,$new_class_id);
  368. if($msg)
  369. {
  370. $str = '';
  371. $i=0;
  372. foreach($msg as $k=>$v)
  373. {
  374. $str .= (++$i).'、'.$v.PHP_EOL;
  375. }
  376. Yii::app()->jump->setErrorWait(20);
  377. if($i>2)
  378. {
  379. Yii::app()->jump->setHeight(100);
  380. }else
  381. {
  382. Yii::app()->jump->setHeight((100+($i*40)));
  383. }
  384. Yii::app()->jump->error($str);exit;
  385. }else
  386. {
  387. Yii::app()->jump->success('转班成功<br>',Yii::app()->createUrl('classes/index'));exit;
  388. }
  389. }
  390. }
  391. /**
  392. * @param $class_ids 当前学期班级信息
  393. * @param $old_class_ids 转入班级信息
  394. */
  395. public function gotoClasses($class_ids,$old_class_ids,$new_class_ids)
  396. {
  397. $c_class_ids = array();
  398. ini_set('memory_limit','518M');
  399. //获取当前学期所有学生信息
  400. $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
  401. if(!$c_class_data)
  402. {
  403. Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
  404. }
  405. foreach($c_class_data as $v)
  406. {
  407. $c_class_ids[$v['class_id']] = $v['class_id'];
  408. }
  409. $new_class_student = $this->getInClassStudents($c_class_ids);//新学生
  410. $old_class_student = $this->getInClassStudents($old_class_ids);//旧学生
  411. $_err = array();
  412. if($old_class_student)
  413. {
  414. if(!empty($new_class_student['student_names']) && !empty($new_class_student['student_ids']))
  415. {
  416. //验证学生姓名是否已存在
  417. if(!empty($old_class_student['student_names']))
  418. {
  419. foreach($old_class_student['student_names'] as $old_student_id => $v)
  420. {
  421. $student_repeat_found_key=array_search($v,$new_class_student['student_names'],true);
  422. if($student_repeat_found_key){
  423. if(!$new_class_student['id_number'][$student_repeat_found_key] && !$old_class_student['id_number'][$old_student_id]) {
  424. $_err[] = $v . '学生已存在';
  425. }elseif(strcmp($new_class_student['id_number'][$student_repeat_found_key],$old_class_student['id_number'][$old_student_id])==0){
  426. $_err[] = $v.'学生已存在';
  427. }elseif(strcmp($old_student_id,$student_repeat_found_key)==0){
  428. $_err[] = $v.'学生已存在';
  429. }
  430. }
  431. }
  432. }
  433. //验证学生学校准考证号
  434. if(!empty($old_class_student['school_student_cards']))
  435. {
  436. foreach($old_class_student['school_student_cards'] as $key => $v)
  437. {
  438. if(array_search($v,$new_class_student['school_student_cards'],true))
  439. {
  440. $_err[] = $old_class_student['student_names'][$key].'学生学校准考证号已存在';
  441. }
  442. }
  443. }
  444. if(empty($_err))
  445. {
  446. //写入数据
  447. //$transaction = StudentInfo::model()->dbConnection->beginTransaction();
  448. $transaction=$this->sConn->beginTransaction();
  449. try {
  450. /*
  451. $criteria = new CDbCriteria();
  452. $criteria->addInCondition('student_id',$old_class_student['student_ids']);
  453. StudentInfo::model()->deleteAll($criteria);
  454. $criteria = new CDbCriteria();
  455. $criteria->addInCondition('student_id',$old_class_student['student_ids']);
  456. StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria);
  457. $criteria = new CDbCriteria();
  458. $criteria->addInCondition('student_id',$old_class_student['student_ids']);
  459. $criteria->addInCondition('class_id',$new_class_ids);
  460. StudentInfo::model()->deleteAll($criteria);
  461. */
  462. $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")";
  463. $updateSql="update student_class_relation set status=1,operation=3,update_time='".time()."' where student_id in(".implode(',',$old_class_student['student_ids']).") and class_type=1";
  464. //添加学生
  465. $i = 0;
  466. $serial_number = 0;
  467. //组装sql
  468. $insertStudentSql="replace into `student_info`(`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`,`id_number`,`field_1`,`field_2`,`field_3`,`field_4`,`field_5`) VALUES";
  469. $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES";
  470. $tempInsertStudentInfoData=array();
  471. $tempInsertStudentClassData=array();
  472. $SqlArr=array();
  473. foreach($old_class_student['student_info'] as $k => $v)
  474. {
  475. $tempStudentInfoData=array();
  476. $tempStudentClassData=array();
  477. $tempStudentInfoData['student_id']="'".$k."'";
  478. $tempStudentInfoData['realname']= "'".$v->realname."'";
  479. $tempStudentInfoData['sex']="'".$v->sex."'";
  480. $tempStudentInfoData['school_id']="'".$this->schoolId."'";
  481. if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]]))
  482. {
  483. $class_id = $class_ids[$old_class_student['student_class_ids'][$k]];
  484. }else
  485. {
  486. $class_id = -2;
  487. }
  488. $tempStudentInfoData['class_id']="'".$class_id."'";
  489. $tempStudentInfoData['family_tel']="'".$v->family_tel."'";
  490. $tempStudentInfoData['telephone']="'".$v->telephone."'";
  491. $tempStudentInfoData['student_phone']="'".$v->student_phone."'";
  492. $tempStudentInfoData['picture']="'".$v->picture."'";
  493. $tempStudentInfoData['signature']="'".$v->signature."'";
  494. $tempStudentInfoData['is_outer']="'".$v->is_outer."'";
  495. $tempStudentInfoData['add_time']="'".$v->add_time."'";
  496. $tempStudentInfoData['update_time']="'".$v->update_time."'";
  497. $tempStudentInfoData['level']="'".$v->level."'";
  498. $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'";
  499. $tempStudentInfoData['game_stars']="'".$v->game_stars."'";
  500. $tempStudentInfoData['id_number']="'".$v->id_number."'";
  501. $tempStudentInfoData['field_1']="'".$v->field_1."'";
  502. $tempStudentInfoData['field_2']="'".$v->field_2."'";
  503. $tempStudentInfoData['field_3']="'".$v->field_3."'";
  504. $tempStudentInfoData['field_4']="'".$v->field_4."'";
  505. $tempStudentInfoData['field_5']="'".$v->field_5."'";
  506. $tempInsertStudentInfoData[$k]=$tempStudentInfoData;
  507. // 创建学生与班级关联关系
  508. $class_student = $old_class_student['class_student'][$k];
  509. $tempStudentClassData['student_id']="'".$k."'";
  510. if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]]))
  511. {
  512. $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]];
  513. }else
  514. {
  515. $studentClassId = -2;
  516. }
  517. $tempStudentClassData['class_id']="'".$studentClassId."'";
  518. if($new_class_student && isset($new_class_student['serial_number']) && isset($new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]]))
  519. {
  520. $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]];
  521. }else
  522. {
  523. $serial_number = 0;
  524. }
  525. $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'";
  526. $tempStudentClassData['userno']="'".$class_student->userno."'";
  527. $tempStudentClassData['update_time']=time();
  528. $tempStudentClassData['status']=0;
  529. $tempInsertStudentClassData[]=$tempStudentClassData;
  530. $i++;
  531. if($i%200==0){
  532. $TempData1=array();
  533. $TempData2=array();
  534. foreach ($tempInsertStudentInfoData as $item){
  535. $TempData1[]="(".implode(',',$item).")";
  536. }
  537. if($TempData1){
  538. $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
  539. }
  540. foreach ($tempInsertStudentClassData as $item){
  541. $TempData2[]="(".implode(',',$item).")";
  542. }
  543. if($TempData2){
  544. $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2);
  545. }
  546. $tempInsertStudentInfoData=array();
  547. $tempInsertStudentClassData=array();
  548. }
  549. }
  550. if($tempInsertStudentInfoData){
  551. $TempData1=array();
  552. foreach ($tempInsertStudentInfoData as $item){
  553. $TempData1[]="(".implode(',',$item).")";
  554. }
  555. if($TempData1){
  556. $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
  557. }
  558. }
  559. if($tempInsertStudentClassData){
  560. $TempData1=array();
  561. foreach ($tempInsertStudentClassData as $item){
  562. $TempData1[]="(".implode(',',$item).")";
  563. }
  564. if($TempData1){
  565. $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1);
  566. }
  567. }
  568. if($SqlArr){
  569. $this->sConn->createCommand($deleteSql)->execute();
  570. $this->sConn->createCommand($updateSql)->execute();
  571. foreach ($SqlArr as $sql){
  572. $this->sConn->createCommand($sql)->execute();
  573. }
  574. }
  575. $transaction->commit();
  576. } catch (Exception $e) {
  577. //如果操作失败, 数据回滚
  578. $transaction->rollback();
  579. Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index'));
  580. }
  581. }else
  582. {
  583. //错误处理
  584. return $_err;
  585. }
  586. }else
  587. {
  588. //新学期
  589. //写入数据
  590. //$transaction = StudentInfo::model()->dbConnection->beginTransaction();
  591. $transaction=$this->sConn->beginTransaction();
  592. try {
  593. /*
  594. $criteria = new CDbCriteria();
  595. $criteria->addInCondition('student_id',$old_class_student['student_ids']);
  596. StudentInfo::model()->deleteAll($criteria);
  597. $criteria = new CDbCriteria();
  598. $criteria->addInCondition('student_id',$old_class_student['student_ids']);
  599. StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria);
  600. */
  601. $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")";
  602. $updateSql="update student_class_relation set status=1,operation=3,update_time='".time()."' where student_id in(".implode(',',$old_class_student['student_ids']).") and class_type=1 ";
  603. //添加学生
  604. $serial_number = 0;
  605. $i = 0;
  606. //组装sql
  607. $insertStudentSql="replace into `student_info`(`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`,`id_number`,`field_1`,`field_2`,`field_3`,`field_4`,`field_5`) VALUES";
  608. $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES";
  609. $tempInsertStudentInfoData=array();
  610. $tempInsertStudentClassData=array();
  611. $SqlArr=array();
  612. foreach($old_class_student['student_info'] as $k => $v)
  613. {
  614. $tempStudentInfoData=array();
  615. $tempStudentClassData=array();
  616. $tempStudentInfoData['student_id']="'".$k."'";
  617. $tempStudentInfoData['realname']= "'".$v->realname."'";
  618. $tempStudentInfoData['sex']="'".$v->sex."'";
  619. $tempStudentInfoData['school_id']="'".$this->schoolId."'";
  620. $userModel = new StudentInfo();
  621. $userModel->student_id = $k;
  622. $userModel->realname = $v->realname;
  623. $userModel->sex = $v->sex;
  624. $userModel->school_id = $this->schoolId;
  625. if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]]))
  626. {
  627. $class_id = $class_ids[$old_class_student['student_class_ids'][$k]];
  628. }else
  629. {
  630. $class_id= -2;
  631. }
  632. $tempStudentInfoData['class_id']="'".$class_id."'";
  633. $tempStudentInfoData['family_tel']="'".$v->family_tel."'";
  634. $tempStudentInfoData['telephone']="'".$v->telephone."'";
  635. $tempStudentInfoData['student_phone']="'".$v->student_phone."'";
  636. $tempStudentInfoData['picture']="'".$v->picture."'";
  637. $tempStudentInfoData['signature']="'".$v->signature."'";
  638. $tempStudentInfoData['is_outer']="'".$v->is_outer."'";
  639. $tempStudentInfoData['add_time']="'".$v->add_time."'";
  640. $tempStudentInfoData['update_time']="'".$v->update_time."'";
  641. $tempStudentInfoData['level']="'".$v->level."'";
  642. $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'";
  643. $tempStudentInfoData['game_stars']="'".$v->game_stars."'";
  644. $tempStudentInfoData['id_number']="'".$v->id_number."'";
  645. $tempStudentInfoData['field_1']="'".$v->field_1."'";
  646. $tempStudentInfoData['field_2']="'".$v->field_2."'";
  647. $tempStudentInfoData['field_3']="'".$v->field_3."'";
  648. $tempStudentInfoData['field_4']="'".$v->field_4."'";
  649. $tempStudentInfoData['field_5']="'".$v->field_5."'";
  650. $tempInsertStudentInfoData[$k]=$tempStudentInfoData;
  651. // 创建学生与班级关联关系
  652. $class_student = $old_class_student['class_student'][$k];
  653. $tempStudentClassData['student_id']="'".$k."'";
  654. $studentClass = new StudentToClass();
  655. $studentClass->student_id = $k;
  656. if(isset($old_class_student['student_class_ids'][$k]) && !empty($old_class_student['student_class_ids'][$k]) && isset($class_ids[$old_class_student['student_class_ids'][$k]]))
  657. {
  658. $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]];
  659. }else
  660. {
  661. $studentClassId = -2;
  662. }
  663. $tempStudentClassData['class_id']="'".$studentClassId."'";
  664. if($new_class_student && isset($new_class_student['serial_number']) && isset($new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]]))
  665. {
  666. $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]];
  667. }else
  668. {
  669. $serial_number = 0;
  670. }
  671. $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'";
  672. $tempStudentClassData['userno']="'".$class_student->userno."'";
  673. $tempStudentClassData['update_time']=time();
  674. $tempStudentClassData['status']=0;
  675. $tempInsertStudentClassData[]=$tempStudentClassData;
  676. $i++;
  677. if($i%200==0){
  678. $TempData1=array();
  679. $TempData2=array();
  680. foreach ($tempInsertStudentInfoData as $item){
  681. $TempData1[]="(".implode(',',$item).")";
  682. }
  683. if($TempData1){
  684. $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
  685. }
  686. foreach ($tempInsertStudentClassData as $item){
  687. $TempData2[]="(".implode(',',$item).")";
  688. }
  689. if($TempData2){
  690. $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2);
  691. }
  692. $tempInsertStudentInfoData=array();
  693. $tempInsertStudentClassData=array();
  694. }
  695. }
  696. if($tempInsertStudentInfoData){
  697. $TempData1=array();
  698. foreach ($tempInsertStudentInfoData as $item){
  699. $TempData1[]="(".implode(',',$item).")";
  700. }
  701. if($TempData1){
  702. $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
  703. }
  704. }
  705. if($tempInsertStudentClassData){
  706. $TempData1=array();
  707. foreach ($tempInsertStudentClassData as $item){
  708. $TempData1[]="(".implode(',',$item).")";
  709. }
  710. if($TempData1){
  711. $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1);
  712. }
  713. }
  714. if($SqlArr){
  715. $this->sConn->createCommand($deleteSql)->execute();
  716. $this->sConn->createCommand($updateSql)->execute();
  717. foreach ($SqlArr as $sql){
  718. $this->sConn->createCommand($sql)->execute();
  719. }
  720. }
  721. $transaction->commit();
  722. } catch (Exception $e) {
  723. //如果操作失败, 数据回滚
  724. $transaction->rollback();
  725. Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index'));
  726. }
  727. }
  728. }
  729. return false;
  730. }
  731. public function gotoClass($class_ids)
  732. {
  733. $_msg = array();
  734. if($class_ids)
  735. {
  736. /**
  737. * 获取当前学期所有班级
  738. */
  739. $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
  740. $c_class_ids = array();
  741. if(!$c_class_data)
  742. {
  743. Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
  744. }
  745. foreach($c_class_data as $v)
  746. {
  747. $c_class_ids[$v['class_id']] = $v['class_id'];
  748. }
  749. $new_class_student = $this->getInClassStudents($c_class_ids);
  750. foreach($class_ids as $k => $v)
  751. {
  752. /**
  753. * 获取转入班的学生
  754. */
  755. /**
  756. * 获取转出班的学生
  757. */
  758. $old_class_student = $this->getClassStudents($k);
  759. /**
  760. * 验证重名
  761. */
  762. $_err = $this->StudentCompare($old_class_student,$new_class_student);
  763. if($_err)
  764. {
  765. $str = '';
  766. $class_data = $this->schoolManager->getClassByClassIds(array($v,$k));
  767. if($class_data){
  768. foreach($class_data as $c)
  769. {
  770. if($k==$c['class_id'])
  771. {
  772. $str .= $c['class_name'];
  773. }
  774. if($v==$c['class_id'])
  775. {
  776. $str .= '转入'.$c['class_name'].'失败,请查看学生姓名重名,学校准考完证号重复';
  777. }
  778. }
  779. $_msg[$v] = array(
  780. 'msg'=>$str
  781. );
  782. }else
  783. {
  784. $_msg[$v] = array(
  785. 'msg'=>'转班失败'
  786. );
  787. }
  788. continue ;
  789. }else
  790. {
  791. $serial_number = 0;
  792. $_student_class_data = SStudentClassRelation::model()->find(array(
  793. 'select' => 'serial_number',
  794. 'order' => 'serial_number desc',
  795. 'condition' => 'class_id=:class_id and status=:status',
  796. 'limit' => 1,
  797. 'params' => array(':class_id'=>$v,':status'=>0)
  798. ));
  799. if($_student_class_data)
  800. {
  801. if($_student_class_data->serial_number)
  802. {
  803. $serial_number = $_student_class_data->serial_number;
  804. }
  805. }
  806. //插入学生
  807. if($old_class_student)
  808. {
  809. $get_array = isset($old_class_student['student_ids'])?$old_class_student['student_ids']:array();
  810. if($get_array)
  811. {
  812. $transaction = StudentInfo::model()->dbConnection->beginTransaction();
  813. try {
  814. foreach ($get_array as $student_id) {
  815. $serial_number = $serial_number+1;
  816. // 修改当前学生所在的班级
  817. $count = StudentInfo::model()->updateAll(array('class_id'=>$v),'student_id=:sid',array(':sid'=>$student_id));
  818. //更新当前学生之前所在班级状态
  819. StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>3),'student_id=:sid and status=0 and class_type=1',array(':sid'=>$student_id));
  820. // 建立当前学生新班级对应记录
  821. $student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$student_id,':class_id'=>$v));
  822. if($student_class){
  823. if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id]))
  824. {
  825. $userno = $old_class_student['student_userno'][$student_id];
  826. }else
  827. {
  828. $userno = '';
  829. }
  830. SStudentClassRelation::model()->updateAll(array('status'=>'0','update_time'=>time(),'userno'=>$userno,'serial_number'=>$serial_number),'student_id=:sid and class_id=:class_id',array(':sid'=>$student_id,':class_id'=>$v));
  831. }else{
  832. $newModel = new StudentToClass();
  833. $newModel->class_id = $v;
  834. $newModel->student_id = $student_id;
  835. $newModel->serial_number = $serial_number;
  836. if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id]))
  837. {
  838. $newModel->userno = $old_class_student['student_userno'][$student_id];
  839. }else
  840. {
  841. $newModel->userno = '';
  842. }
  843. $newModel->update_time = time();
  844. $newModel->save();
  845. }
  846. }
  847. $transaction->commit();
  848. } catch (Exception $e) {
  849. //如果操作失败, 数据回滚
  850. $transaction->rollback();
  851. $_msg[$v] = array(
  852. 'msg'=>'学生写入失败'
  853. );
  854. }
  855. }else
  856. {
  857. $_msg[$v] = array(
  858. 'msg'=>'学生写入失败'
  859. );
  860. }
  861. }else
  862. {
  863. $_msg[$v] = array(
  864. 'msg'=>'此班无学生'
  865. );
  866. }
  867. }
  868. }
  869. }
  870. return $_msg;
  871. }
  872. // 创建班级
  873. public function actionAdd(){
  874. $toFiltMaterialsIds = array(13, 14, 15, 16);
  875. $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
  876. checkAuthority(2); // 非当前使用学期无法操作
  877. $data = array();
  878. $teachers = $this->schoolManager->getTeachers();
  879. $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
  880. $semesterId = $this->semesterId;
  881. $thisSemester = $this->schoolManager->getSemester($semesterId);
  882. if (Yii::app()->request->getIsPostRequest()){
  883. $class_name = trim(Req::post("class_name"));
  884. $mid_array = array();
  885. $subjectId = 0;
  886. $material_id = 0;
  887. $coach_id = Req::post("coach_id");
  888. $period = (int)Req::post("period");
  889. $teachersIds = Req::post("teacher_ids");
  890. $subject_ids = Req::post("subject_ids");
  891. $bzr_id=Req::post("bzrId"); //班主任id
  892. $levelName = Req::post("level_name");
  893. if(!$levelName) $levelName='A';
  894. $level = array($levelName => null);
  895. $grade = Req::post("grade");
  896. $arts_science = Req::post("arts_science");
  897. $_subject_ids = array();
  898. if($subject_ids)
  899. {
  900. foreach($subject_ids as $v)
  901. {
  902. if(in_array($v,$_subject_ids))
  903. {
  904. Yii::app()->jump->error('班级不能增加相同的学科教师');
  905. }
  906. $_subject_ids[] = $v;
  907. }
  908. }
  909. if(is_array($teachersIds)){
  910. foreach($teachersIds as $key => $val){
  911. if(empty($val) ||(is_string($val) && trim($val) == ""))
  912. unset($teachersIds[$key]);
  913. }
  914. }
  915. if(!array_intersect_key($level, $this->class_level))
  916. $levelName = "";
  917. if (empty($class_name)){
  918. Yii::app()->jump->error('班级信息未填写完整!');
  919. }
  920. else if(empty($coach_id)){
  921. Yii::app()->jump->error('未选择助教!');
  922. }
  923. else if(!$teachersIds){
  924. Yii::app()->jump->error('未选择执教老师!');
  925. }
  926. else if(!$grade){
  927. Yii::app()->jump->error('未选择年级!');
  928. }
  929. $classesModel = new ClassModel();
  930. // 判断当前学期当前班级是否已添加
  931. if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
  932. {
  933. Yii::app()->jump->error('该学期下已存在同名班级!');
  934. }
  935. // 当前班级唯一id
  936. //$classId = getUUID();
  937. $classId=getUniqueId($this->schoolId);
  938. if (empty($classId)) {
  939. Yii::app()->jump->error('创建班级失败!');
  940. }
  941. $improve_book_type = 0;
  942. $wb_isp_version = 0;
  943. if(Req::post("improve_book_type")==0)
  944. {
  945. $improve_book_type = 0;
  946. $wb_isp_version = 0;
  947. }
  948. if(Req::post("improve_book_type")==1)
  949. {
  950. $improve_book_type = 1;
  951. $wb_isp_version = 0;
  952. }
  953. if(Req::post("improve_book_type")==3)
  954. {
  955. $improve_book_type = 0;
  956. $wb_isp_version = 1;
  957. }
  958. if(Req::post("improve_book_type")==4)
  959. {
  960. $improve_book_type = 1;
  961. $wb_isp_version = 1;
  962. }
  963. // 创建班级相关事务
  964. //$transaction = Yii::app()->db->beginTransaction();
  965. $transaction = $classesModel->dbConnection->beginTransaction();
  966. try{
  967. //创建班级与老师关系
  968. if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array(
  969. 'class_id' => $classId,
  970. 'class_name' => $class_name,
  971. 'level' => Char::letterToNum($levelName, 1),
  972. 'grade' => $grade,
  973. 'semester_id' => $semesterId,
  974. 'period' => $period,
  975. 'add_time' => time(),
  976. 'coach_id' => $this->coachId,
  977. 'wrong_book_type' => Req::post("wrong_book_type"),
  978. 'improve_book_type' => $improve_book_type,
  979. 'wb_isp_version' => $wb_isp_version,
  980. 'arts_science'=>$arts_science,
  981. 'teacher_id'=>$bzr_id
  982. )))
  983. throw new CException("创建班级和老师关系失败");
  984. $modulesIds = array();
  985. if($mid_array){
  986. //创建教材模块与班级关系表
  987. foreach($mid_array as $lp){
  988. if (empty($lp)) throw new CException('创建班级失败!');
  989. $lp = (int)$lp;
  990. $modulesIds[] = $lp;
  991. }
  992. $modulesIds = implode(",", $modulesIds);
  993. }
  994. if(!$modulesIds)
  995. $modulesIds = "";
  996. if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds))) {
  997. throw new CException('创建失败!');
  998. }
  999. $transaction->commit();
  1000. } catch (Exception $e) {
  1001. //如果操作失败, 数据回滚
  1002. $transaction->rollback();
  1003. Yii::app()->jump->error($e->getMessage());
  1004. }
  1005. if($this->schoolManager->isCurrentSemester($semesterId))
  1006. $this->redirect(array('classes/index'));
  1007. else
  1008. $this->redirect(array("classes/index?semesterId={$semesterId}"));
  1009. }
  1010. unset(Yii::app()->session['school_material']);
  1011. // 获取所有教材及其模块
  1012. $get_material = Yii::app()->session['school_material'];
  1013. if (empty($get_material)) {
  1014. //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']);
  1015. $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3");
  1016. $json_material = json_decode($json_material, true);
  1017. $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true));
  1018. $session_material = $json_material;
  1019. //$session_material = json_decode($json_material,true);
  1020. if (!empty($session_material) && !isset($session_material['error'])) {
  1021. Yii::app()->session['school_material'] = $session_material;
  1022. $get_material = $session_material;
  1023. }
  1024. unset($json_material,$session_material);
  1025. }
  1026. if($get_material){
  1027. foreach($get_material as $key => $material){
  1028. if(isset($material["modules"])){
  1029. foreach($material["modules"] as $moduleKey => $module){
  1030. //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
  1031. if(empty($module["chapters"])){
  1032. unset($get_material[$key]["modules"][$moduleKey]);
  1033. }
  1034. }
  1035. }
  1036. if(empty($get_material[$key]["modules"]))
  1037. unset($get_material[$key]);
  1038. }
  1039. }
  1040. $data['material'] = $get_material;
  1041. // 获取当前学校所有助教
  1042. $coachList = array();
  1043. if(!isset(Yii::app()->session['crmUserInfo']))
  1044. {
  1045. $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  1046. if (empty($coachList)) {
  1047. Yii::app()->jump->error('系统未找到助教,请联系管理员!');
  1048. }
  1049. }else
  1050. {
  1051. $coachList = array(Yii::app()->session['crmUserInfo']);
  1052. }
  1053. unset($transaction);
  1054. if( Yii::app()->params['section']==1){
  1055. $firstSubjectId=3;
  1056. }else{
  1057. $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject);
  1058. }
  1059. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId));
  1060. $model = new Model();
  1061. //$data['semester'] = $semester;
  1062. $data['coachList'] = $coachList;
  1063. $data["teachers"] = $teachers;
  1064. $data["teacher_data"] = $teacher_data;
  1065. $data["classLevels"] = $this->class_level;
  1066. $data["semesters"] = $semesters;
  1067. $data["semesterId"] = $semesterId;
  1068. $data["model"] = $model;
  1069. $data["thisSemester"] = $thisSemester;
  1070. $this->render('add',$data);
  1071. }
  1072. //更新班级排序
  1073. public function actionSaveClassSort()
  1074. {
  1075. $classSort = Req::post('classSort');
  1076. if(!$classSort){
  1077. returnMsg(0,'排序参数错误');
  1078. }
  1079. $sql = "UPDATE class SET sort = CASE class_id";
  1080. $class_ids = array();
  1081. foreach ($classSort as $k=>$v){
  1082. $temp = explode('_', $v);
  1083. $sort = intval($temp[1])>0?intval($temp[1]):0;
  1084. $sql .= " WHEN {$temp[0]} THEN {$sort}";
  1085. $class_ids[] = $temp[0];
  1086. }
  1087. if(!$class_ids){
  1088. returnMsg(0,'参数错误');
  1089. }
  1090. $class_id = implode(',', $class_ids);
  1091. $sql .= " END ";
  1092. $sql .= " WHERE class_id IN ({$class_id})";
  1093. $result = ClassModel::model()->saveClassSort($sql);
  1094. if ($result !==false){
  1095. returnMsg(1,'修改成功');
  1096. }else{
  1097. returnMsg(0,'修改失败');
  1098. }
  1099. }
  1100. public function actionVerifyclass_name()
  1101. {
  1102. $class_name = trim(Req::post("class_name"));
  1103. if (empty($class_name)){
  1104. echo json_encode(array('status'=>0));exit;
  1105. }
  1106. $is_edit = trim(Req::post("is_edit"));
  1107. if($is_edit)
  1108. {
  1109. $class_ids = array();
  1110. $class_id = trim(Req::post("class_id"));
  1111. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  1112. $_class_data = ClassModel::model()->findAll('semester_id=:seid and class_name=:class_name',array(':seid'=>$this->semesterId,':class_name'=>$class_name));
  1113. if(!$class_data)
  1114. {
  1115. echo json_encode(array('status'=>0));exit;
  1116. }
  1117. if(count($_class_data)>1)
  1118. {
  1119. echo json_encode(array('status'=>0));exit;
  1120. }
  1121. $class_ids[$class_id] = $class_id;
  1122. if($_class_data && !isset($class_ids[$_class_data[0]->class_id]))
  1123. {
  1124. echo json_encode(array('status'=>0));exit;
  1125. }elseif($_class_data && isset($class_ids[$_class_data[0]->class_id]))
  1126. {
  1127. echo json_encode(array('status'=>1));exit;
  1128. }
  1129. echo json_encode(array('status'=>1));exit;
  1130. }
  1131. $classesModel = new ClassModel();
  1132. if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$this->semesterId,':cname'=>$class_name)))
  1133. {
  1134. echo json_encode(array('status'=>0));exit;
  1135. }
  1136. echo json_encode(array('status'=>1));exit;
  1137. }
  1138. // 修改班级信息
  1139. public function actionEdit(){
  1140. $toFiltMaterialsIds = array(13, 14, 15, 16);
  1141. $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
  1142. //checkAuthority(2); // 非当前使用学期无法操作
  1143. $classId = safe_replace(Yii::app()->request->getQuery('cid'));
  1144. if (empty($classId)) {
  1145. Yii::app()->jump->error('操作失败!');
  1146. }
  1147. // 获取当前学校所有助教
  1148. $coachList = array();
  1149. if(!isset(Yii::app()->session['crmUserInfo']))
  1150. {
  1151. $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  1152. if (empty($coachList)) {
  1153. Yii::app()->jump->error('系统未找到助教,请联系管理员!');
  1154. }
  1155. }else
  1156. {
  1157. $coachList = array(Yii::app()->session['crmUserInfo']);
  1158. }
  1159. $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId);
  1160. $semesterId = $this->semesterId;
  1161. $thisSemester = $this->schoolManager->getSemester($semesterId);
  1162. // 班级信息
  1163. //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId));
  1164. $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ");
  1165. $grade = $classInfo->grade;
  1166. $teachers = $this->schoolManager->getTeachers();
  1167. $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
  1168. if (empty($classInfo)) {
  1169. Yii::app()->jump->error('未找到该班级信息!');
  1170. }
  1171. // 当前班级教练信息
  1172. $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ");
  1173. // 当前班级教材模块
  1174. $module = $this->sConn->createCommand()->select("*")->from("class_subject_relation")->where("class_id = '{$classId}'")->queryRow();
  1175. $module_array = array();
  1176. if($module && $module["module_ids"]){
  1177. $module_array = explode(",", $module["module_ids"]);
  1178. }
  1179. if (Yii::app()->request->getIsPostRequest()){
  1180. /*$class_name = safe_replace($_POST['class_name']);
  1181. $mid_array = $_POST['mid'];
  1182. $material_id = safe_replace($_POST['material_id']);
  1183. $coach_id = safe_replace($_POST['coach_id']);
  1184. $period = intval($_POST['period']);*/
  1185. $class_name = trim(Req::post("class_name"));
  1186. $improve_book_type = 0;
  1187. $wb_isp_version = 0;
  1188. $bzr_id=Req::post("bzrId"); //班主任id
  1189. if(Req::post("improve_book_type")==0)
  1190. {
  1191. $improve_book_type = 0;
  1192. $wb_isp_version = 0;
  1193. }
  1194. if(Req::post("improve_book_type")==1)
  1195. {
  1196. $improve_book_type = 1;
  1197. $wb_isp_version = 0;
  1198. }
  1199. if(Req::post("improve_book_type")==3)
  1200. {
  1201. $improve_book_type = 0;
  1202. $wb_isp_version = 1;
  1203. }
  1204. if(Req::post("improve_book_type")==4)
  1205. {
  1206. $improve_book_type = 1;
  1207. $wb_isp_version = 1;
  1208. }
  1209. //$mid_array = Req::post("mid");
  1210. //$subjectId = Req::post("subject_id");
  1211. //$material_id = Req::post("material_id");
  1212. $mid_array = array();
  1213. $subjectId = 0;
  1214. $material_id = 0;
  1215. $coach_id = Req::post("coach_id");
  1216. $period = Req::post("period");
  1217. $levelName = Req::post("level_name");
  1218. $level = array($levelName => null);
  1219. $teachersIds = Req::post("teacher_ids");
  1220. $subject_ids = Req::post("subject_ids");
  1221. $arts_science= Req::post("arts_science");
  1222. $_subject_ids = array();
  1223. if($subject_ids)
  1224. {
  1225. foreach($subject_ids as $v)
  1226. {
  1227. if(in_array($v,$_subject_ids))
  1228. {
  1229. Yii::app()->jump->error('班级不能增加相同的学科教师');
  1230. }
  1231. $_subject_ids[] = $v;
  1232. }
  1233. }
  1234. if(is_array($teachersIds)){
  1235. foreach($teachersIds as $key => $val){
  1236. if(empty($val) ||(is_string($val) && trim($val) == ""))
  1237. unset($teachersIds[$key]);
  1238. }
  1239. }
  1240. $grade = Req::post("grade");
  1241. //$semesterId = Req::post("semesterId");
  1242. if(!array_intersect_key($level, $this->class_level))
  1243. $levelName = "";
  1244. if(!$levelName)
  1245. Yii::app()->jump->error('层级只能是A,B,C层!');
  1246. if (empty($class_name) || empty($coach_id) || !$teachersIds){
  1247. Yii::app()->jump->error('班级信息未填写完整!');
  1248. }
  1249. $classesModel = new ClassModel();
  1250. // 判断当前学期当前班级是否已添加
  1251. if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
  1252. {
  1253. if($classInfo->class_name != $class_name && !$classesModel->count('semester_id=:seid and class_name=:cname and class_id=:classId',array(':seid'=>$semesterId,':cname'=>$class_name,':classId'=>$classId)))
  1254. Yii::app()->jump->error('您选择的学期已存在同名班级!');
  1255. }
  1256. // 创建班级相关事务
  1257. //$transaction = Yii::app()->db->beginTransaction();
  1258. $classInfo = ClassModel::model()->find("class_id = '{$classId}'");
  1259. $transaction = $classInfo->dbConnection->beginTransaction();
  1260. try {
  1261. if($classInfo->class_name != $class_name)
  1262. $classInfo->class_name = $class_name;
  1263. //$classInfo->period = $period;
  1264. //$classInfo->grade = $grade;
  1265. //$classInfo->semester_id = $semesterId;
  1266. $classInfo->level = Char::letterToNum($levelName, 1);
  1267. $classInfo->wrong_book_type = Req::post("wrong_book_type");
  1268. $classInfo->improve_book_type = $improve_book_type;
  1269. $classInfo->wb_isp_version = $wb_isp_version;
  1270. $classInfo->teacher_id = $bzr_id;
  1271. $classInfo->arts_science = $arts_science;
  1272. if(!$classInfo->save()){
  1273. throw new CException('更新失败!');
  1274. }
  1275. if($classInfo->coach_id != $coach_id){
  1276. if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) {
  1277. throw new CException('班级更新失败!');
  1278. }
  1279. }
  1280. if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId))
  1281. throw new CException("班级老师更新失败");
  1282. // 是否修改教材模块
  1283. $get_array = array_diff($mid_array, $module_array);
  1284. $modulesIds = array_diff($module_array, $mid_array);
  1285. if ((!empty($get_array) || !empty($modulesIds)) && $mid_array){
  1286. $modulesIds = implode(",", $mid_array);
  1287. if(!$this->schoolManager->classSubjectExists($classId)){
  1288. if(!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds)))
  1289. throw new CException('创建失败!');
  1290. }
  1291. else{
  1292. if (!$this->sConn->createCommand()->update("class_subject_relation", array("subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds), "class_id = {$classId}")) {
  1293. throw new CException('创建失败!');
  1294. }
  1295. }
  1296. }
  1297. $transaction->commit();
  1298. } catch (Exception $e) {
  1299. //如果操作失败, 数据回滚
  1300. $transaction->rollback();
  1301. Yii::app()->jump->error($e->getMessage());
  1302. }
  1303. $this->redirect(array('classes/index'));
  1304. }
  1305. $data = array();
  1306. unset(Yii::app()->session['school_material']);
  1307. // 获取所有教材及其模块
  1308. $get_material = Yii::app()->session['school_material'];
  1309. if (empty($get_material)) {
  1310. //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']);
  1311. $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3");
  1312. $json_material = json_decode($json_material, true);
  1313. $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true));
  1314. $session_material = $json_material;
  1315. //$session_material = json_decode($json_material,true);
  1316. if (!empty($session_material) && !isset($session_material['error'])) {
  1317. Yii::app()->session['school_material'] = $session_material;
  1318. $get_material = $session_material;
  1319. }
  1320. unset($json_material,$session_material);
  1321. }
  1322. if($get_material){
  1323. foreach($get_material as $key => $material){
  1324. if(isset($material["modules"])){
  1325. foreach($material["modules"] as $moduleKey => $module){
  1326. //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
  1327. if(empty($module["chapters"])){
  1328. unset($get_material[$key]["modules"][$moduleKey]);
  1329. }
  1330. }
  1331. }
  1332. if(empty($get_material[$key]["modules"]))
  1333. unset($get_material[$key]);
  1334. }
  1335. }
  1336. $data['material'] = $get_material;
  1337. /*$coachList = BusinessCoach::model()->findAll('school_id=:sid and status=0',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  1338. if (empty($coachList)) {
  1339. Yii::app()->jump->error('系统未找到助教,请联系管理员!');
  1340. }*/
  1341. $class_teacher_data = array();
  1342. $subject_teacher_data = array();
  1343. $subject_teacher_array = array();
  1344. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
  1345. $teachers_data = Teacher::model()->findAll('status=0');
  1346. if($teachers_data)
  1347. {
  1348. $gangwei = array(
  1349. 0=>'任课教师',
  1350. 1=>'班主任',
  1351. 2=>'教研组长',
  1352. 3=>'年级主任',
  1353. 4=>'任课教师',
  1354. 5=>'校长',
  1355. );
  1356. $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
  1357. foreach($teachers_data as $k=>$v)
  1358. {
  1359. $class_teacher_data[$v->teacher_id] = $v->teacher_id;
  1360. $subject_teacher_data[$v->teacher_id] = $v->subjects;
  1361. $teacherGrade = $v->grade?$v->grade:0;
  1362. if($v->posts==3){
  1363. //过滤本年级的年级主任
  1364. if (!$teacherGrade || $teacherGrade==$grade){
  1365. $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts];
  1366. $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost);
  1367. }
  1368. }else{
  1369. $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$gangwei[$v->posts]);
  1370. }
  1371. if($classInfo->teacher_id && strcmp($v->teacher_id,$classInfo->teacher_id)==0){
  1372. $data['bzr']=$v->teacher_name;
  1373. }
  1374. }
  1375. }
  1376. if(!$classTeachersIds){//如果没有执教老师 默认会一个执教老师 方便编辑操作
  1377. $sql = "select teacher_id from teacher where `status`=0 and (posts !=3 or (posts=3 and grade={$grade}))";
  1378. $teacher_data = $this->sConn->createCommand($sql)->queryRow();
  1379. if($teacher_data){
  1380. $classTeachersIds[] = $teacher_data['teacher_id'];
  1381. }
  1382. }
  1383. $data["teachers"] = $teachers;
  1384. $data["classLevels"] = $this->class_level;
  1385. $data["classTeachersIds"] = $classTeachersIds;
  1386. $data['classInfo'] = $classInfo;
  1387. $data['relatCoach'] = $relatCoach;
  1388. $data['class_teacher'] = $class_teacher_data;
  1389. $data['subject_teacher'] = $subject_teacher_data;
  1390. $data['subject_teacher_array'] = $subject_teacher_array;
  1391. $data["teacher_data"] = $teacher_data;
  1392. $data['module_array'] = $module_array;
  1393. $data['coachList'] = $coachList;
  1394. $data["semesters"] = $semesters;
  1395. $data["semester_id"] = $classInfo->semester_id;
  1396. $data["thisSemester"] =$thisSemester;
  1397. $this->render('edit',$data);
  1398. }
  1399. public function actionGetChaptersAct(){
  1400. $materialId = Req::get("materialId");
  1401. $chapters = $this->schoolManager->getMaterialChapters($materialId);
  1402. echo json_encode($chapters);exit;
  1403. }
  1404. public function actionAjax_semester_class()
  1405. {
  1406. $semester_id = Req::post("semester_id");
  1407. $class_id = Req::post("class_id");
  1408. $class_array = array();
  1409. if( !$semester_id || !$class_id)
  1410. {
  1411. echo json_encode(array('status'=>0,'data'=>''));exit;
  1412. }
  1413. $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$semester_id));
  1414. $class_ids = array();
  1415. $_class_ids = array();
  1416. $class_info = array();
  1417. if($class_data)
  1418. {
  1419. foreach($class_data as $v)
  1420. {
  1421. if($class_id != $v->class_id)
  1422. {
  1423. $class_ids[$v->class_id] = $v->class_id;
  1424. $class_info[$v->class_id] = $v->attributes;
  1425. }
  1426. }
  1427. $criteria = new CDbCriteria();
  1428. $criteria->addInCondition('class_id',$class_ids);
  1429. $criteria->addCondition('status=:status');
  1430. $criteria->params[':status'] = 0;
  1431. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  1432. if($student_class_data)
  1433. {
  1434. foreach($student_class_data as $v)
  1435. {
  1436. $_class_ids[$v->class_id] = $v->class_id;
  1437. }
  1438. foreach($_class_ids as $v)
  1439. {
  1440. if(isset($class_info[$v]) && !empty($class_info[$v]))
  1441. {
  1442. $class_array[$v] = $class_info[$v];
  1443. }
  1444. }
  1445. }else{
  1446. $class_array =array();
  1447. }
  1448. }
  1449. if($class_array)
  1450. {
  1451. echo json_encode(array('status'=>1,'data'=>$class_array));exit;
  1452. }
  1453. echo json_encode(array('status'=>0,'data'=>''));exit;
  1454. }
  1455. //根据学期id获取班级
  1456. public function actionAjaxclass(){
  1457. $json = array();
  1458. $smid = safe_replace(Yii::app()->request->getPost('smid'));
  1459. if (empty($smid)) {
  1460. $json['flag'] = false;
  1461. echo json_encode($json);die;
  1462. }
  1463. $allClass = ClassModel::model()->findAll('semester_id=:yid',array(':yid'=>$smid));
  1464. $classList = array();
  1465. if (!empty($allClass)) {
  1466. foreach ($allClass as $val) {
  1467. $classList[] = $val->attributes;
  1468. }
  1469. }
  1470. unset($allClass);
  1471. $json['flag'] = true;
  1472. $json['classList'] = $classList;
  1473. echo json_encode($json);exit;
  1474. }
  1475. public function actionGetclass()
  1476. {
  1477. $grade_id = Req::post("grade_id");
  1478. $all_class = Req::post("all_class");
  1479. $filter_hide = (int)Req::post('filter_hide');
  1480. if(!$filter_hide){
  1481. $filter_hide=0;
  1482. }else{
  1483. $filter_hide=1;
  1484. }
  1485. $class_array = array();
  1486. $class_data=array();
  1487. if($all_class){
  1488. if($filter_hide){
  1489. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and is_hide=0',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  1490. }else{
  1491. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id ',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  1492. }
  1493. }else{
  1494. if($filter_hide){
  1495. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1 and is_hide=0',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  1496. }else{
  1497. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
  1498. }
  1499. }
  1500. if($class_data){
  1501. foreach($class_data as $v )
  1502. {
  1503. $class_array[] = $v->attributes;
  1504. }
  1505. echo json_encode(array('status'=>1,'result'=>$class_array));exit;
  1506. }
  1507. echo json_encode(array('status'=>0,'result'=>array()));exit;
  1508. }
  1509. public function actionGetClassWithSort()
  1510. {
  1511. $class_data = ClassModel::model()->getClassWithSort($this->semesterId);
  1512. if($class_data){
  1513. foreach($class_data as $k=>$v )
  1514. {
  1515. $class_array[$k]['class_id'] = $v->class_id;
  1516. $class_array[$k]['class_name'] = $v->class_name;
  1517. $class_array[$k]['sort'] = $v->sort;
  1518. }
  1519. returnMsg(1,'获取成功',$class_array);
  1520. }else{
  1521. returnMsg(0,'暂无班级');
  1522. }
  1523. }
  1524. // 复制学生
  1525. public function actionCopy(){
  1526. ini_set('memory_limit','300M');
  1527. $data = array();
  1528. $_err = array();
  1529. $cid = safe_replace(Yii::app()->request->getQuery('cid'));
  1530. $currSemester = $this->schoolManager->getCurrSemester();
  1531. $criteria = new CDbCriteria;
  1532. $criteria->addCondition('end_time <= :start_time');
  1533. $criteria->params[':start_time'] = $currSemester['start_time'];
  1534. $criteria->limit = 1;
  1535. $criteria->order = "end_time desc";
  1536. $allSemester = Semester::model()->find($criteria);
  1537. $data['currSemester'] = $currSemester;
  1538. $data['semesters'] = $allSemester;
  1539. if (!($class = $this->schoolManager->getClass($cid))) {
  1540. Yii::app()->jump->error('复制学生有误1!');
  1541. }
  1542. if($this->schoolManager->isFutureSemester($class["semester_id"]))
  1543. Yii::app()->jump->error('未开始的学期不能转班');
  1544. if (Yii::app()->request->getIsPostRequest()){
  1545. //$get_array = $_POST['class_array'];
  1546. $get_array = Filter::act($_POST['class_array']);
  1547. $class_id = Filter::act($_POST['class_id']);
  1548. $semester_id = Filter::act($_POST['semester_id']);
  1549. $is_ajax = isset($_POST['is_ajax'])?Filter::act($_POST['is_ajax']):0;
  1550. $chooseStudentIds = array();
  1551. $chooseStudentStr = '';
  1552. if($get_array){
  1553. foreach($get_array as $k=>$v){
  1554. $chooseStudentIds[] = $v;
  1555. }
  1556. }
  1557. $operation=2; //转班操作类型
  1558. if($semester_id==$this->semesterId){
  1559. $operation=2;
  1560. }else{
  1561. $operation=3;
  1562. }
  1563. if($this->schoolManager->isFutureSemester($semester_id)){
  1564. Yii::app()->jump->error('未开始的学期不能转班');
  1565. }
  1566. if (!($class = $this->schoolManager->getClass($class_id))) {
  1567. Yii::app()->jump->error('复制学生有误2!');
  1568. }
  1569. if($this->schoolManager->isFutureSemester($class['semester_id'])){
  1570. Yii::app()->jump->error('未开始的学期不能转班');
  1571. }
  1572. /**
  1573. * 获取当前学期所有班级
  1574. */
  1575. $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
  1576. $c_class_ids = array();
  1577. if(!$c_class_data)
  1578. {
  1579. Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
  1580. }
  1581. foreach($c_class_data as $v)
  1582. {
  1583. $c_class_ids[$v['class_id']] = $v['class_id'];
  1584. }
  1585. /**
  1586. * 获取转出班的学生
  1587. */
  1588. //$out_data = $this->getClassStudents($class_id,0,$chooseStudentIds);
  1589. $out_data = $this->getStudentsClassNo($chooseStudentIds);
  1590. /**
  1591. * 获取转入班的学生
  1592. */
  1593. $in_data = $this->getInClassStudents($c_class_ids);
  1594. /**
  1595. * 验证重名
  1596. */
  1597. if($class['semester_id']!=$this->semesterId)
  1598. {
  1599. $_err = $this->StudentCompare($out_data,$in_data);
  1600. }
  1601. if($_err)
  1602. {
  1603. Yii::app()->jump->error('转班失败,请查看重名或准考证号重复',Yii::app()->createUrl('classes/copy',array('cid'=>$cid)));
  1604. }
  1605. $serial_number = 0;
  1606. $_student_class_data = SStudentClassRelation::model()->find(array(
  1607. 'select' => 'serial_number',
  1608. 'order' => 'serial_number desc',
  1609. 'condition' => 'class_id=:class_id and status=:status',
  1610. 'limit' => 1,
  1611. 'params' => array(':class_id'=>$cid,':status'=>0)
  1612. ));
  1613. if($_student_class_data)
  1614. {
  1615. if($_student_class_data->serial_number)
  1616. {
  1617. $serial_number = $_student_class_data->serial_number;
  1618. }
  1619. }
  1620. //操作日志
  1621. if(Yii::app()->params['handle_log_on_off'])
  1622. {
  1623. writeFileLog(jsonEncode(array(
  1624. "exam_group_id" => 0,
  1625. "operate_project" => 'zsyas2',
  1626. "school_id" => $this->schoolId,
  1627. "title" => '分班',
  1628. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1629. "operate_method" => $this->action,
  1630. "operate_url" => $this->getRoute(),
  1631. "operate_sql" =>'',
  1632. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1633. "date"=>date('Y-m-d H:i:s')
  1634. )));
  1635. }
  1636. $transaction = StudentInfo::model()->dbConnection->beginTransaction();
  1637. try {
  1638. foreach ($get_array as $v) {
  1639. $serial_number = $serial_number+1;
  1640. // 修改当前学生所在的班级
  1641. $count = StudentInfo::model()->updateAll(array('class_id'=>$cid),'student_id=:sid',array(':sid'=>$v));
  1642. if (false === $count) {
  1643. Yii::app()->jump->error('更新学生班级有误!');
  1644. }
  1645. //更新当前学生之前所在班级状态
  1646. $classData=$this->sConn->createCommand("select scr.class_id from student_class_relation scr join class c on scr.class_id=c.class_id where student_id ='{$v}' and c.class_type=1 and scr.status=0")->queryAll();
  1647. if($classData){
  1648. $classIds=array();
  1649. foreach ($classData as $datum){
  1650. $classIds[]=$datum['class_id'];
  1651. }
  1652. $this->sConn->createCommand("update student_class_relation set status=1,update_time='".time()."',operation='{$operation}',class_type=1 where student_id='{$v}' and class_id in(".implode(',',$classIds).")")->execute();
  1653. // StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>$operation,'class_type'=>1),'student_id=:sid and class_id in (:cid)',array(':sid'=>$v,':cid'=>implode(',',$classIds)));
  1654. }
  1655. //StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>$operation),'student_id=:sid and status=0 and class_type=1',array(':sid'=>$v));
  1656. // 建立当前学生新班级对应记录
  1657. //$student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid));
  1658. // if($student_class){
  1659. // SStudentClassRelation::model()->updateAll(array('status'=>'0','update_time'=>time()),'student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid));
  1660. // }else{
  1661. // $newModel = new StudentToClass();
  1662. // $newModel->class_id = $cid;
  1663. // $newModel->student_id = safe_replace($v);
  1664. // $newModel->serial_number = $serial_number;
  1665. // $newModel->userno = $out_data['class_student'][$v]['userno'];
  1666. // $newModel->update_time = time();
  1667. // if (!$newModel->save()) {
  1668. // Yii::app()->jump->error('更新学生班级有误!');
  1669. // }
  1670. // }
  1671. $newModel = new StudentToClass();
  1672. $newModel->class_id = $cid;
  1673. $newModel->student_id = safe_replace($v);
  1674. $newModel->serial_number = $serial_number;
  1675. if(isset($out_data['class_student'][$v])){
  1676. $newModel->userno = $out_data['class_student'][$v]['userno'];
  1677. }
  1678. $newModel->update_time = time();
  1679. if (!$newModel->save()) {
  1680. Yii::app()->jump->error('更新学生班级有误!');
  1681. }
  1682. }
  1683. $transaction->commit();
  1684. } catch (Exception $e) {
  1685. debug($e);
  1686. //如果操作失败, 数据回滚
  1687. $transaction->rollback();
  1688. Yii::app()->jump->error('复制学生信息失败!');
  1689. }
  1690. if($is_ajax){
  1691. echo json_encode(array('status'=>1));exit;
  1692. }else{
  1693. $this->redirect(array('classes/index'));
  1694. }
  1695. }
  1696. //所有班级
  1697. $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$this->semesterId));
  1698. $class_ids = array();
  1699. $_class_ids = array();
  1700. $class_info = array();
  1701. if($class_data)
  1702. {
  1703. foreach($class_data as $v)
  1704. {
  1705. if($cid != $v->class_id)
  1706. {
  1707. $class_ids[$v->class_id] = $v->class_id;
  1708. $class_info[$v->class_id] = $v;
  1709. }
  1710. }
  1711. $criteria = new CDbCriteria();
  1712. $criteria->addInCondition('class_id',$class_ids);
  1713. $criteria->addCondition('status=:status');
  1714. $criteria->params[':status'] = 0;
  1715. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  1716. if($student_class_data)
  1717. {
  1718. foreach($student_class_data as $v)
  1719. {
  1720. $_class_ids[$v->class_id] = $v->class_id;
  1721. }
  1722. foreach($_class_ids as $v)
  1723. {
  1724. if(isset($class_info[$v]) && !empty($class_info[$v]))
  1725. {
  1726. $data['all_class'][$v] = $class_info[$v];
  1727. }
  1728. }
  1729. }else{
  1730. $data['all_class'] =array();
  1731. }
  1732. }
  1733. $data['all_class'] = ClassModel::model()->findAll("class_id != :cid and semester_id = '{$this->semesterId}' and class_type=1 and is_hide=0",array(':cid'=>$cid));
  1734. // 班级名称
  1735. $data['className'] = ClassModel::model()->getClassName($cid);
  1736. $data['classId'] = $cid;
  1737. $this->render('copy',$data);
  1738. }
  1739. public function StudentCompare($out,$in)
  1740. {
  1741. $_err = array();
  1742. if($out && $in)
  1743. {
  1744. if(isset($in['student_names']) && !empty($in['student_names']) && isset($out['student_names']) && !empty($out['student_names']))
  1745. {
  1746. foreach ($in['student_names'] as $key=>$val)
  1747. {
  1748. if(isset($out[$key]))
  1749. {
  1750. $_err[$key] = $out[$key].'学生已存在';
  1751. }
  1752. foreach($out['student_names'] as $k=>$v)
  1753. {
  1754. if($v == $val)
  1755. {
  1756. $_err[$k] = $v.'学生姓名已存在';
  1757. }
  1758. }
  1759. }
  1760. }
  1761. if(isset($in['school_student_cards']) && !empty($in['school_student_cards']) && isset($out['school_student_cards']) && !empty($out['school_student_cards']))
  1762. {
  1763. foreach ($in['school_student_cards'] as $key=>$val)
  1764. {
  1765. if(isset($out[$key]))
  1766. {
  1767. $_err[$key] = $out[$key].'学生已存在';
  1768. }
  1769. foreach($out['school_student_cards'] as $k=>$v)
  1770. {
  1771. if($v == $val)
  1772. {
  1773. $_err[$k] = $v.'学生学校准考证号已存在';
  1774. }
  1775. }
  1776. }
  1777. }
  1778. if(isset($in['student_cards']) && !empty($in['student_cards']) && isset($out['student_cards']) && !empty($out['student_cards']))
  1779. {
  1780. foreach ($in['student_cards'] as $key=>$val)
  1781. {
  1782. if(isset($out[$key]))
  1783. {
  1784. $_err[$key] = $out[$key].'学生已存在';
  1785. }
  1786. foreach($out['student_cards'] as $k=>$v)
  1787. {
  1788. if($v == $val)
  1789. {
  1790. $_err[$k] = $v.'学生准考证号已存在';
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. return $_err;
  1797. }
  1798. public function getClassStudents($class_id,$status=0,$chooseStudentArr)
  1799. {
  1800. $data = array();
  1801. $student_ids = array();
  1802. $student_names = array();
  1803. $student_cards = array();
  1804. $school_student_cards = array();
  1805. $userno = array();
  1806. $student_info = array();
  1807. $class_student = array();
  1808. $student_class_ids = array();
  1809. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status));
  1810. if($student_class_data)
  1811. {
  1812. foreach($student_class_data as $v)
  1813. {
  1814. if($chooseStudentArr && in_array($v->student_id, $chooseStudentArr)){
  1815. $student_ids[$v->student_id] = $v->student_id;
  1816. $userno[$v->student_id] = $v->userno;
  1817. $class_student[$v->student_id] = $v;
  1818. }
  1819. }
  1820. $criteria = new CDbCriteria();
  1821. $criteria->addInCondition('student_id',$student_ids);
  1822. $student_data = SStudentInfo::model()->findAll($criteria);
  1823. if($student_data)
  1824. {
  1825. foreach($student_data as $v)
  1826. {
  1827. $student_names[$v->student_id] = $v->realname;
  1828. $student_info[$v->student_id] = $v;
  1829. }
  1830. }
  1831. unset($student_data);
  1832. unset($criteria);
  1833. $criteria = new CDbCriteria();
  1834. $criteria->addInCondition('student_id',$student_ids);
  1835. $b_student_data = BusinessStudent::model()->findAll($criteria);
  1836. if($b_student_data)
  1837. {
  1838. foreach($b_student_data as $v)
  1839. {
  1840. $student_cards[$v->student_id] = $v->student_card;
  1841. if($v->school_student_card)
  1842. {
  1843. $school_student_cards[$v->student_id] = $v->school_student_card;
  1844. }
  1845. //$school_student_cards[$v->student_id] = $v->school_student_card;
  1846. }
  1847. }
  1848. unset($b_student_data);
  1849. $data['student_names'] = $student_names;
  1850. $data['student_cards'] = $student_cards;
  1851. $data['student_ids'] = $student_ids;
  1852. $data['school_student_cards'] = $school_student_cards;
  1853. $data['student_userno'] = $userno;
  1854. $data['student_info'] = $student_info;
  1855. $data['class_student'] = $class_student;
  1856. $data['student_class_ids'] = $student_class_ids;
  1857. }
  1858. unset($student_class_data);
  1859. return $data;
  1860. }
  1861. public function getInClassStudents($class_ids)
  1862. {
  1863. $data = array();
  1864. $student_ids = array();
  1865. $student_names = array();
  1866. $student_cards = array();
  1867. $school_student_cards = array();
  1868. $userno = array();
  1869. $serial_number = array();
  1870. $student_class_ids = array();
  1871. $student_info = array();
  1872. $class_student = array();
  1873. $id_number = array();
  1874. $criteria = new CDbCriteria();
  1875. $criteria->addInCondition('class_id',$class_ids);
  1876. $criteria->addCondition('status=:status');
  1877. $criteria->params[':status'] = 0;
  1878. $criteria->order = 'serial_number desc,class_id desc';
  1879. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  1880. if($student_class_data)
  1881. {
  1882. foreach($student_class_data as $key=>$v)
  1883. {
  1884. if(isset($serial_number[$v->class_id]))
  1885. {
  1886. if($serial_number[$v->class_id]<$v->serial_number)
  1887. {
  1888. $serial_number[$v->class_id] = $v->serial_number;
  1889. }
  1890. }else
  1891. {
  1892. $serial_number[$v->class_id] = $v->serial_number;
  1893. }
  1894. $student_ids[$v->student_id] = $v->student_id;
  1895. $userno[$v->student_id] = $v->userno;
  1896. $class_student[$v->student_id] = $v;
  1897. $student_class_ids[$v->student_id] = $v->class_id;
  1898. }
  1899. $criteria = new CDbCriteria();
  1900. $criteria->addInCondition('student_id',$student_ids);
  1901. $student_data = SStudentInfo::model()->findAll($criteria);
  1902. if($student_data)
  1903. {
  1904. foreach($student_data as $v)
  1905. {
  1906. $student_names[$v->student_id] = $v->realname;
  1907. $student_info[$v->student_id] = $v;
  1908. $id_number[$v->student_id] =$v->id_number;
  1909. }
  1910. }
  1911. unset($criteria);
  1912. $criteria = new CDbCriteria();
  1913. $criteria->addInCondition('student_id',$student_ids);
  1914. $b_student_data = BusinessStudent::model()->findAll($criteria);
  1915. if($b_student_data)
  1916. {
  1917. foreach($b_student_data as $v)
  1918. {
  1919. $student_cards[$v->student_id] = $v->student_card;
  1920. if($v->school_student_card)
  1921. {
  1922. $school_student_cards[$v->student_id] = $v->school_student_card;
  1923. }
  1924. }
  1925. }
  1926. $data['student_names'] = $student_names;
  1927. $data['student_cards'] = $student_cards;
  1928. $data['student_ids'] = $student_ids;
  1929. $data['school_student_cards'] = $school_student_cards;
  1930. $data['student_userno'] = $userno;
  1931. $data['student_info'] = $student_info;
  1932. $data['class_student'] = $class_student;
  1933. $data['student_class_ids'] = $student_class_ids;
  1934. $data['serial_number'] = $serial_number;
  1935. $data['id_number'] =$id_number;
  1936. }
  1937. return $data;
  1938. }
  1939. // 查看班级学生
  1940. public function actionView(){
  1941. $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
  1942. if (empty($get_id)) {
  1943. Yii::app()->jump->error('无法访问!');
  1944. }
  1945. $semesterId = $this->schoolManager->getSemesterIdByClassId($get_id);
  1946. $data = array();
  1947. $data["semesterId"] = $semesterId;
  1948. $data["model"] = new Model();
  1949. $data["isCurrentSemester"] = $this->schoolManager->isCurrentSemester($semesterId);
  1950. /*$get_list = StudentInfo::model()->getUserList(array($get_id));
  1951. $data['studentList'] = $get_list['result'];
  1952. $data['pages'] = $get_list['page'];
  1953. $data['page_total'] = $get_list['page_total'];*/
  1954. $get_list = $this->schoolManager->getClassStudentsList($get_id);
  1955. $team_student=$this->schoolManager->getTeamByClass($get_id,'student'); //所有学生列表
  1956. $student_ids = array();
  1957. $b_student_arr = array();
  1958. $school_student_card = array();
  1959. $z_student_arr = array();
  1960. if($get_list && isset($get_list['rs']) && !empty($get_list['rs']))
  1961. {
  1962. foreach($get_list['rs'] as $k => $v)
  1963. {
  1964. $student_ids[$v['student_id']] = $v['student_id'];
  1965. if(isset($team_student[$v['student_id']])){
  1966. $get_list['rs'][$k]['team']=$team_student[$v['student_id']];
  1967. }
  1968. }
  1969. if($student_ids){
  1970. $criteria = new CDbCriteria();
  1971. $criteria->addInCondition('student_id',$student_ids);
  1972. $b_student_data = BusinessStudent::model()->findAll($criteria);
  1973. if($b_student_data)
  1974. {
  1975. foreach($b_student_data as $v)
  1976. {
  1977. $b_student_arr[$v->student_id] = $v->student_card;
  1978. $school_student_card[$v->student_id] = $v->school_student_card;
  1979. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1980. {
  1981. $z_student_arr[$v->student_id] = $v->zhixue_student_card;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. $data['b_student'] = $b_student_arr;
  1988. $data['school_card'] = $school_student_card;
  1989. $data['z_student'] = $z_student_arr;
  1990. $data['studentList'] = Arr::toObj($get_list['rs']);
  1991. $data["students"] = $get_list;
  1992. $data['pages'] = $get_list['pager'];
  1993. $data['page_total'] = $get_list['pager']->rowsCount;
  1994. $data["cid"] = $get_id;
  1995. if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
  1996. {
  1997. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1998. }else
  1999. {
  2000. $data["use_zhixue"] = 0;
  2001. }
  2002. $this->render('view',$data);
  2003. }
  2004. //预生成学生ID
  2005. private function createStudentId($num)
  2006. {
  2007. return $this->createId($num);
  2008. }
  2009. //预生成系统准考证号
  2010. private function createCard($num)
  2011. {
  2012. $cards = array();
  2013. $student_cart = 0;
  2014. if(!$num)
  2015. {
  2016. return $cards;
  2017. }
  2018. /*
  2019. $b_student_data = BusinessStudent::model()->find(array(
  2020. 'select' => 'student_card',
  2021. 'order' => 'student_card desc',
  2022. 'condition' => 'school_id=:school_id',
  2023. 'limit' => 1,
  2024. 'params' => array(':school_id'=>$this->schoolId)
  2025. ));
  2026. */
  2027. $b_student_data=$this->conn->createCommand("SELECT student_card FROM (SELECT student_card FROM `student` `t` WHERE school_id='".$this->schoolId."') sc ORDER BY student_card DESC LIMIT 1;")->queryRow();
  2028. if($b_student_data)
  2029. {
  2030. if(!$b_student_data['student_card'])
  2031. {
  2032. if($this->schoolId<100)
  2033. {
  2034. $student_cart = '9'.$this->schoolId.'00100';
  2035. }else
  2036. {
  2037. $student_cart = $this->schoolId.'00100';
  2038. }
  2039. }else
  2040. {
  2041. $student_cart = $b_student_data['student_card'];
  2042. }
  2043. }else
  2044. {
  2045. if($this->schoolId<100)
  2046. {
  2047. $student_cart = '9'.$this->schoolId.'00100';
  2048. }else
  2049. {
  2050. $student_cart = $this->schoolId.'00100';
  2051. }
  2052. }
  2053. unset($b_student_data);
  2054. for($i=1;$i<=$num;$i++)
  2055. {
  2056. $cards[$student_cart+$i] = array(
  2057. 'student_card'=>$student_cart+$i,
  2058. 'use'=>0,
  2059. 'order'=>$i
  2060. );
  2061. }
  2062. return $cards;
  2063. }
  2064. private function addSetUUID($_uuid_arr)
  2065. {
  2066. if($_uuid_arr)
  2067. {
  2068. Yii::app()->business_uuid_cache->hmset('redis_business_uuid:'.$this->schoolId,$_uuid_arr);
  2069. }
  2070. }
  2071. private function UUID_log($sum)
  2072. {
  2073. Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入学生成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time()));
  2074. }
  2075. //优化导入学生
  2076. public function actionImport()
  2077. {
  2078. ini_set('memory_limit','300M');
  2079. $error_msg = array();
  2080. //sql
  2081. $student_sql = '';
  2082. $student_info_sql = '';
  2083. $student_info_arr = array();
  2084. $student_sql_arr = array();
  2085. $class_student_sql = '';
  2086. $class_student_sql_arr = array();
  2087. $sql_count = 0;
  2088. $update_student_id = array();
  2089. $bstudents = new BusinessStudent();
  2090. $sstudentinfo = new SStudentInfo();
  2091. $sstudentclassrelation = new SStudentClassRelation();
  2092. if (Yii::app()->request->getIsPostRequest()){
  2093. $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
  2094. $uploader->allowTypes = array("xls");
  2095. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  2096. $file = $uploader->act();
  2097. $file = Arr::current(Arr::current($file));
  2098. if(!$file || !isset($file["error"]))
  2099. Yii::app()->jump->error('请选择上传的Excel!');
  2100. if($file["error"] != 0){
  2101. switch($file["error"]){
  2102. case 2001:
  2103. Yii::app()->jump->error('文件类型不符');
  2104. break;
  2105. case 2002:
  2106. Yii::app()->jump->error('文件大小超出允许范围');
  2107. break;
  2108. default:
  2109. Yii::app()->jump->error('上传失败');
  2110. break;
  2111. }
  2112. }
  2113. $result = true;
  2114. $inputFileName = $file["src"];
  2115. if(Yii::app()->params['handle_log_on_off'])
  2116. {
  2117. writeFileLog(jsonEncode(array(
  2118. "exam_group_id" => 0,
  2119. "operate_project" => 'zsyas2',
  2120. "school_id" => $this->schoolId,
  2121. "title" => '导入学生',
  2122. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  2123. "operate_method" => $this->action,
  2124. "operate_url" => $this->getRoute(),
  2125. "operate_sql" =>'',
  2126. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$inputFileName)),
  2127. "date"=>date('Y-m-d H:i:s')
  2128. )));
  2129. }
  2130. if ($result) {
  2131. $semesterId = $this->semesterId;
  2132. Yii::import('application.extensions.*');
  2133. require_once('phpexcel/PHPExcel/IOFactory.php');
  2134. // 读取Excel文档
  2135. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  2136. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  2137. //FIXME 20191202
  2138. @unlink($file["src"]);
  2139. // 去掉导航
  2140. //dump($sheetData);die;
  2141. unset($sheetData[1]);
  2142. krsort($sheetData);
  2143. $serial_number = 0;
  2144. $get_id = 0;
  2145. $b_student_cards = array();
  2146. $b_id_student_cards = array();
  2147. $b_school_student_cards = array();
  2148. $b_id_school_student_cards = array();
  2149. $b_id_zhixue_student_cards = array();
  2150. $b_student_ids = array();
  2151. $b_student = array();
  2152. $class_ids = array();
  2153. $c_class_names = array();
  2154. $grade = 0;
  2155. $uuid = 0;
  2156. $n_class_id = array();
  2157. $n_student_ids = array();
  2158. $class_grade = array();
  2159. $class_serial_number = array();
  2160. $s_student_ids = array();
  2161. $d_student_ids = array();// 删除学生ID
  2162. $d_student_card = array();
  2163. $d_student_names = array();
  2164. $d_school_student_card = array();
  2165. $use_student_card = array();
  2166. $use_school_student_card = array();
  2167. $use_zhixue_student_card = array();
  2168. $students = array();
  2169. $cards = array();
  2170. $_school_cards = array();
  2171. $_zhixue_cards = array();
  2172. $student_info_name = array();
  2173. $student_names = array();
  2174. $school_student_names = array();
  2175. $school_student_info = array();
  2176. $_class_ids = array();
  2177. $del_class_student = array();
  2178. //获当前学校的学生准考证号
  2179. ////////////////////优化前
  2180. // $b_student_all_data = BusinessStudent::model()->findAll(array(
  2181. // 'order' => 'student_id desc',
  2182. // 'condition' => 'school_id=:school_id',
  2183. // 'params' => array(':school_id'=>$this->schoolId)
  2184. // ));
  2185. //
  2186. // if($b_student_all_data)
  2187. // {
  2188. // foreach($b_student_all_data as $k=>$v)
  2189. // {
  2190. //
  2191. // $b_student[$v->student_id] = $v;
  2192. // $b_student_ids[$v->student_id] = $v->student_id;
  2193. // $b_id_student_cards[$v->student_id] = $v->student_card;
  2194. // $b_id_school_student_cards[$v->student_id] = (string)$v->school_student_card;
  2195. // $b_id_zhixue_student_cards[$v->student_id] = (string)$v->school_student_card;
  2196. // if($v->student_card)
  2197. // {
  2198. // $b_student_cards[$v->student_card] = $v->student_id;
  2199. // }
  2200. // if($v->school_student_card)
  2201. // {
  2202. // $b_school_student_cards[$v->school_student_card] = $v->student_id;
  2203. // }
  2204. //
  2205. //
  2206. //
  2207. // }
  2208. // }
  2209. // unset($b_student_all_data);
  2210. /////////////////////////////优化后
  2211. $b_student_all_data = $bstudents->getStudentsByPages($this->schoolId);
  2212. if($b_student_all_data){
  2213. if(isset($b_student_all_data['b_student'])){
  2214. $b_student = $b_student_all_data['b_student'];
  2215. }
  2216. if(isset($b_student_all_data['b_student_ids'])){
  2217. $b_student_ids = $b_student_all_data['b_student_ids'];
  2218. }
  2219. if(isset($b_student_all_data['b_id_student_cards'])){
  2220. $b_id_student_cards = $b_student_all_data['b_id_student_cards'];
  2221. }
  2222. if(isset($b_student_all_data['b_id_school_student_cards'])){
  2223. $b_id_school_student_cards = $b_student_all_data['b_id_school_student_cards'];
  2224. }
  2225. if(isset($b_student_all_data['b_id_zhixue_student_cards'])){
  2226. $b_id_zhixue_student_cards = $b_student_all_data['b_id_zhixue_student_cards'];
  2227. }
  2228. if(isset($b_student_all_data['b_student_cards'])){
  2229. $b_student_cards = $b_student_all_data['b_student_cards'];
  2230. }
  2231. if(isset($b_student_all_data['b_school_student_cards'])){
  2232. $b_school_student_cards = $b_student_all_data['b_school_student_cards'];
  2233. }
  2234. }
  2235. unset($b_student_all_data);
  2236. ///////////////////ending
  2237. //获取当前学校所有学生信息
  2238. ////////////////优化前
  2239. // $student_info_data = SStudentInfo::model()->findAll();
  2240. // if($student_info_data)
  2241. // {
  2242. // foreach($student_info_data as $v)
  2243. // {
  2244. // $school_student_info[$v->student_id] = $v;
  2245. // $school_student_names[$v->student_id] = $v->realname;
  2246. // }
  2247. //
  2248. // }
  2249. //
  2250. // unset($student_info_data);
  2251. //////////////////////优化后
  2252. $student_info_data = $sstudentinfo->getStudentsByPages();
  2253. if($student_info_data){
  2254. if(isset($student_info_data['school_student_info'])){
  2255. $school_student_info = $student_info_data['school_student_info'];
  2256. }
  2257. if(isset($student_info_data['school_student_names'])){
  2258. $school_student_names = $student_info_data['school_student_names'];
  2259. }
  2260. }
  2261. unset($student_info_data);
  2262. ///////////////////////ending
  2263. // 获取当前学期的所有班级
  2264. $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
  2265. if($class_semester_data)
  2266. {
  2267. foreach($class_semester_data as $v)
  2268. {
  2269. $class_ids[$v->class_id] = $v->class_id;
  2270. $c_class_names[$v->class_id] = (string)$v->class_name;
  2271. //$class_grade[$v->class_id] = $v->grade;
  2272. }
  2273. }
  2274. unset($class_semester_data);
  2275. if(!$class_ids)
  2276. {
  2277. Yii::app()->jump->error('无班级信息,导入失败');
  2278. }
  2279. // 获取年级信息
  2280. /*$grade_data = SGradeModel::model()->findAll();
  2281. if(!$grade_data)
  2282. {
  2283. Yii::app()->jump->error('此班级无年级信息,导入失败');
  2284. }*/
  2285. $sheetData = array_reverse($sheetData);
  2286. // 获取在线学生
  2287. $criteria = new CDbCriteria();
  2288. $criteria->addInCondition('class_id',$class_ids);
  2289. $criteria->addCondition('status=0');
  2290. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  2291. unset($criteria);
  2292. if($semester_student_class_data)
  2293. {
  2294. foreach($semester_student_class_data as $v)
  2295. {
  2296. //在线学生ID
  2297. $s_student_ids[$v->student_id] = $v->student_id;
  2298. //在线学生准考证号
  2299. if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
  2300. {
  2301. $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
  2302. }
  2303. //在线学校准考证号
  2304. if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
  2305. {
  2306. $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
  2307. }
  2308. //在线智学网准考证号
  2309. if(isset($b_id_zhixue_student_cards[$v->student_id]) && !empty($b_id_zhixue_student_cards[$v->student_id]))
  2310. {
  2311. $use_zhixue_student_card[$b_id_zhixue_student_cards[$v->student_id]] = $v->student_id;
  2312. }
  2313. //获取在线学生信息
  2314. if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
  2315. {
  2316. $student_names[$v->student_id] = $school_student_names[$v->student_id];
  2317. }
  2318. //获取班级中的最大序号
  2319. if(isset($class_serial_number[$v->class_id]))
  2320. {
  2321. if($class_serial_number[$v->class_id]<$v->serial_number)
  2322. {
  2323. $class_serial_number[$v->class_id] = $v->serial_number;
  2324. }
  2325. }else
  2326. {
  2327. $class_serial_number[$v->class_id] = $v->serial_number;
  2328. }
  2329. }
  2330. }
  2331. unset($semester_student_class_data);
  2332. //获取已删除的学生信息
  2333. $criteria = new CDbCriteria();
  2334. $criteria->addInCondition('class_id',$class_ids);
  2335. $criteria->addCondition('status=1');
  2336. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  2337. unset($criteria);
  2338. if($semester_student_class_data)
  2339. {
  2340. foreach($semester_student_class_data as $v)
  2341. {
  2342. //已删除学生ID
  2343. $d_student_ids[$v->student_id] = $v->student_id;
  2344. //在线学生准考证号
  2345. if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
  2346. {
  2347. $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
  2348. }
  2349. //在线学校准考证号
  2350. if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
  2351. {
  2352. $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
  2353. }
  2354. //获取在线学生信息
  2355. if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
  2356. {
  2357. $d_student_names[$v->student_id] = $school_student_names[$v->student_id];
  2358. }
  2359. }
  2360. }
  2361. unset($semester_student_class_data);
  2362. $sheetData_sun = count($sheetData);
  2363. //预定学生准考证号
  2364. $create_card_data = $this->createCard($sheetData_sun);
  2365. //预定学生ID
  2366. $create_student_ids = $this->createStudentId($sheetData_sun);
  2367. if(!$create_student_ids)
  2368. {
  2369. Yii::app()->jump->error('预定学生ID不足,请联系技术人员');
  2370. }
  2371. foreach ($sheetData as $key=>$val)
  2372. {
  2373. if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
  2374. continue;
  2375. }
  2376. if(count($val) != 7)
  2377. {
  2378. Yii::app()->jump->error('导入学生格式有误! ');
  2379. }
  2380. if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) {
  2381. $error_msg[$key]['class_name'] = $val['A'];
  2382. $error_msg[$key]['student_name'] = $val['B'];
  2383. $error_msg[$key]['student_six'] = $val['C'];
  2384. $error_msg[$key]['student_no'] = $val['D'];
  2385. $error_msg[$key]['student_card'] = $val['E'];
  2386. $error_msg[$key]['school_student_card'] = $val['F'];
  2387. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2388. $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空';
  2389. $error_msg[$key]['so_msg'] = '按照示例格式填写表格';
  2390. continue;
  2391. }
  2392. $val['A'] = (string)$val['A'];
  2393. $card = 0;
  2394. //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
  2395. $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
  2396. $username = $realname;
  2397. if (isset($val['E'])) {
  2398. $card = safe_replace($val['E']);
  2399. }
  2400. if (in_array($username, $students)) {
  2401. $error_msg[$key]['class_name'] = $val['A'];
  2402. $error_msg[$key]['student_name'] = $val['B'];
  2403. $error_msg[$key]['student_six'] = $val['C'];
  2404. $error_msg[$key]['student_no'] = $val['D'];
  2405. $error_msg[$key]['student_card'] = $val['E'];
  2406. $error_msg[$key]['school_student_card'] = $val['F'];
  2407. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2408. $error_msg[$key]['err_msg'] = '表格中存在姓名重复';
  2409. $error_msg[$key]['so_msg'] = '在表格中删除重复学生';
  2410. continue;
  2411. }
  2412. $students[] = $username;
  2413. //验证系统准考证号
  2414. if (!empty($card)) {
  2415. if (in_array($card, $cards)) {
  2416. $error_msg[$key]['class_name'] = $val['A'];
  2417. $error_msg[$key]['student_name'] = $val['B'];
  2418. $error_msg[$key]['student_six'] = $val['C'];
  2419. $error_msg[$key]['student_no'] = $val['D'];
  2420. $error_msg[$key]['student_card'] = $val['E'];
  2421. $error_msg[$key]['school_student_card'] = $val['F'];
  2422. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2423. $error_msg[$key]['err_msg'] = '表格中存在系统准考证号';
  2424. $error_msg[$key]['so_msg'] = '在表格中删除重复系统准考证号';
  2425. continue;
  2426. }
  2427. $cards[] = $card;
  2428. }
  2429. if (isset($val['F']) && !empty($val['F'])) {
  2430. $school_card = safe_replace($val['F']);
  2431. //验证学校准考证号
  2432. if (!empty($school_card)) {
  2433. if (isset($_school_cards[$school_card]) && !empty($_school_cards[$school_card])) {
  2434. $error_msg[$key]['class_name'] = $val['A'];
  2435. $error_msg[$key]['student_name'] = $val['B'];
  2436. $error_msg[$key]['student_six'] = $val['C'];
  2437. $error_msg[$key]['student_no'] = $val['D'];
  2438. $error_msg[$key]['student_card'] = $val['E'];
  2439. $error_msg[$key]['school_student_card'] = $val['F'];
  2440. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2441. $error_msg[$key]['err_msg'] = '表格中存在学校准考证号';
  2442. $error_msg[$key]['so_msg'] = '在表格中删除重复学校准考证号';
  2443. continue;
  2444. }
  2445. if(!is_numeric($school_card)){
  2446. $error_msg[$key]['class_name'] = $val['A'];
  2447. $error_msg[$key]['student_name'] = $val['B'];
  2448. $error_msg[$key]['student_six'] = $val['C'];
  2449. $error_msg[$key]['student_no'] = $val['D'];
  2450. $error_msg[$key]['student_card'] = $val['E'];
  2451. $error_msg[$key]['school_student_card'] = $val['F'];
  2452. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2453. $error_msg[$key]['err_msg'] = '学校准考证号格式不正确';
  2454. $error_msg[$key]['so_msg'] = '学校准考证号只能由数字组成';
  2455. continue;
  2456. }
  2457. $_school_cards[$school_card] = $school_card;
  2458. }
  2459. }
  2460. if (isset($val['G']) && !empty($val['G'])) {
  2461. $zhixue_student_card = safe_replace($val['G']);
  2462. //验证智学网准考证号
  2463. if (!empty($zhixue_student_card)) {
  2464. if (in_array($zhixue_student_card, $_zhixue_cards)) {
  2465. $error_msg[$key]['class_name'] = $val['A'];
  2466. $error_msg[$key]['student_name'] = $val['B'];
  2467. $error_msg[$key]['student_six'] = $val['C'];
  2468. $error_msg[$key]['student_no'] = $val['D'];
  2469. $error_msg[$key]['student_card'] = $val['E'];
  2470. $error_msg[$key]['school_student_card'] = $val['F'];
  2471. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2472. $error_msg[$key]['err_msg'] = '表格中存在智学网准考证号';
  2473. $error_msg[$key]['so_msg'] = '在表格中删除重复智学网准考证号';
  2474. continue;
  2475. }
  2476. if(!is_numeric($zhixue_student_card)){
  2477. $error_msg[$key]['class_name'] = $val['A'];
  2478. $error_msg[$key]['student_name'] = $val['B'];
  2479. $error_msg[$key]['student_six'] = $val['C'];
  2480. $error_msg[$key]['student_no'] = $val['D'];
  2481. $error_msg[$key]['student_card'] = $val['E'];
  2482. $error_msg[$key]['school_student_card'] = $val['F'];
  2483. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2484. $error_msg[$key]['err_msg'] = '智学网准考证号格式不正确';
  2485. $error_msg[$key]['so_msg'] = '智学网准考证号只能由数字组成';
  2486. continue;
  2487. }
  2488. $_zhixue_cards[] = $zhixue_student_card;
  2489. }
  2490. }
  2491. }
  2492. foreach ($sheetData as $key=>$val) {
  2493. if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
  2494. continue;
  2495. }
  2496. if(count($val) != 7)
  2497. {
  2498. Yii::app()->jump->error('导入学生格式有误! ');
  2499. }
  2500. if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) {
  2501. $error_msg[$key]['class_name'] = $val['A'];
  2502. $error_msg[$key]['student_name'] = $val['B'];
  2503. $error_msg[$key]['student_six'] = $val['C'];
  2504. $error_msg[$key]['student_no'] = $val['D'];
  2505. $error_msg[$key]['student_card'] = $val['E'];
  2506. $error_msg[$key]['school_student_card'] = $val['F'];
  2507. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2508. $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空';
  2509. $error_msg[$key]['so_msg'] = '按照示例格式填写表格';
  2510. continue;
  2511. }
  2512. $val['A'] = (string)$val['A'];
  2513. $class_name = $val['A'];
  2514. if(!in_array($class_name,$c_class_names))
  2515. {
  2516. $error_msg[$key]['class_name'] = $val['A'];
  2517. $error_msg[$key]['student_name'] = $val['B'];
  2518. $error_msg[$key]['student_six'] = $val['C'];
  2519. $error_msg[$key]['student_no'] = $val['D'];
  2520. $error_msg[$key]['student_card'] = $val['E'];
  2521. $error_msg[$key]['school_student_card'] = $val['F'];
  2522. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2523. $error_msg[$key]['err_msg'] = '此班级不存在';
  2524. $error_msg[$key]['so_msg'] = '填写存在班级名称';
  2525. continue;
  2526. }
  2527. $get_id = array_search($class_name,$c_class_names,TRUE);
  2528. if(!$get_id){
  2529. $error_msg[$key]['class_name'] = $val['A'];
  2530. $error_msg[$key]['student_name'] = $val['B'];
  2531. $error_msg[$key]['student_six'] = $val['C'];
  2532. $error_msg[$key]['student_no'] = $val['D'];
  2533. $error_msg[$key]['student_card'] = $val['E'];
  2534. $error_msg[$key]['school_student_card'] = $val['F'];
  2535. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2536. $error_msg[$key]['err_msg'] = '此班级不存在';
  2537. $error_msg[$key]['so_msg'] = '班级名称填写不正确';
  2538. continue;
  2539. }
  2540. $_class_ids[$get_id] = $get_id;
  2541. //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
  2542. $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
  2543. $sex = safe_replace($val['C']);
  2544. $userno = safe_replace($val['D']);
  2545. $card = 0;
  2546. $username = $realname;
  2547. if (isset($val['E'])) {
  2548. $card = safe_replace($val['E']);
  2549. }
  2550. if(!isset($class_serial_number[$get_id]))
  2551. {
  2552. $class_serial_number[$get_id] = 0;
  2553. }
  2554. $school_card = '';
  2555. if (isset($val['F']) && !empty($val['F'])) {
  2556. $school_card = safe_replace($val['F']);
  2557. //验证学校准考证号
  2558. /*if (strlen($school_card) != $grade_data->card_length) {
  2559. $error_msg[$key]['student_name'] = $val['A'];
  2560. $error_msg[$key]['student_six'] = $val['B'];
  2561. $error_msg[$key]['student_no'] = $val['C'];
  2562. $error_msg[$key]['student_card'] = $val['D'];
  2563. $error_msg[$key]['school_student_card'] = $val['E'];
  2564. $error_msg[$key]['err_msg'] = '学校准考证号长度不正确';
  2565. $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。';
  2566. continue;
  2567. }*/
  2568. if (!$card && $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
  2569. $error_msg[$key]['class_name'] = $val['A'];
  2570. $error_msg[$key]['student_name'] = $val['B'];
  2571. $error_msg[$key]['student_six'] = $val['C'];
  2572. $error_msg[$key]['student_no'] = $val['D'];
  2573. $error_msg[$key]['student_card'] = $val['E'];
  2574. $error_msg[$key]['school_student_card'] = $val['F'];
  2575. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2576. $error_msg[$key]['err_msg'] = '学校准考证号已存在';
  2577. $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
  2578. continue;
  2579. }else
  2580. {
  2581. if (isset($use_student_card[$card]))
  2582. {
  2583. if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
  2584. $c_student_id = 0;
  2585. $c_student_id = $use_student_card[$card];
  2586. $s_student_id = $use_school_student_card[$school_card];
  2587. if($c_student_id != $s_student_id)
  2588. {
  2589. $error_msg[$key]['class_name'] = $val['A'];
  2590. $error_msg[$key]['student_name'] = $val['B'];
  2591. $error_msg[$key]['student_six'] = $val['C'];
  2592. $error_msg[$key]['student_no'] = $val['D'];
  2593. $error_msg[$key]['student_card'] = $val['E'];
  2594. $error_msg[$key]['school_student_card'] = $val['F'];
  2595. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2596. $error_msg[$key]['err_msg'] = '学校准考证号已存在';
  2597. $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
  2598. continue;
  2599. }
  2600. }
  2601. }else
  2602. {
  2603. if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card]))
  2604. {
  2605. $error_msg[$key]['class_name'] = $val['A'];
  2606. $error_msg[$key]['student_name'] = $val['B'];
  2607. $error_msg[$key]['student_six'] = $val['C'];
  2608. $error_msg[$key]['student_no'] = $val['D'];
  2609. $error_msg[$key]['student_card'] = $val['E'];
  2610. $error_msg[$key]['school_student_card'] = $val['F'];
  2611. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2612. $error_msg[$key]['err_msg'] = '学校准考证号已存在';
  2613. $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
  2614. continue;
  2615. }
  2616. }
  2617. }
  2618. }
  2619. //智学网
  2620. $zhixue_student_card = '';
  2621. if (isset($val['G']) && !empty($val['G'])) {
  2622. $zhixue_student_card = safe_replace($val['G']);
  2623. if (!$card && $use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card])) {
  2624. $error_msg[$key]['class_name'] = $val['A'];
  2625. $error_msg[$key]['student_name'] = $val['B'];
  2626. $error_msg[$key]['student_six'] = $val['C'];
  2627. $error_msg[$key]['student_no'] = $val['D'];
  2628. $error_msg[$key]['student_card'] = $val['E'];
  2629. $error_msg[$key]['school_student_card'] = $val['F'];
  2630. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2631. $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
  2632. $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
  2633. continue;
  2634. }else
  2635. {
  2636. if (isset($use_student_card[$card]))
  2637. {
  2638. if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card]))
  2639. {
  2640. $c_student_id = 0;
  2641. $c_student_id = $use_student_card[$card];
  2642. $z_student_id = $use_zhixue_student_card[$zhixue_student_card];
  2643. if($c_student_id != $z_student_id)
  2644. {
  2645. $error_msg[$key]['class_name'] = $val['A'];
  2646. $error_msg[$key]['student_name'] = $val['B'];
  2647. $error_msg[$key]['student_six'] = $val['C'];
  2648. $error_msg[$key]['student_no'] = $val['D'];
  2649. $error_msg[$key]['student_card'] = $val['E'];
  2650. $error_msg[$key]['school_student_card'] = $val['F'];
  2651. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2652. $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
  2653. $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
  2654. continue;
  2655. }
  2656. }
  2657. }else
  2658. {
  2659. if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card]))
  2660. {
  2661. $c_student_id = $use_student_card[$card];
  2662. $z_student_id = $use_zhixue_student_card[$zhixue_student_card];
  2663. if($c_student_id != $z_student_id)
  2664. {
  2665. $error_msg[$key]['class_name'] = $val['A'];
  2666. $error_msg[$key]['student_name'] = $val['B'];
  2667. $error_msg[$key]['student_six'] = $val['C'];
  2668. $error_msg[$key]['student_no'] = $val['D'];
  2669. $error_msg[$key]['student_card'] = $val['E'];
  2670. $error_msg[$key]['school_student_card'] = $val['F'];
  2671. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2672. $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
  2673. $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
  2674. continue;
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. if ($sex != '1' && $sex != '2') {
  2681. $error_msg[$key]['class_name'] = $val['A'];
  2682. $error_msg[$key]['student_name'] = $val['B'];
  2683. $error_msg[$key]['student_six'] = $val['C'];
  2684. $error_msg[$key]['student_no'] = $val['D'];
  2685. $error_msg[$key]['student_card'] = $val['E'];
  2686. $error_msg[$key]['school_student_card'] = $val['F'];
  2687. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2688. $error_msg[$key]['err_msg'] = '性别填写有误';
  2689. $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)';
  2690. continue;
  2691. }
  2692. //判断学生是否存在
  2693. if (!$card && $student_names && $_student_id = array_search($realname, $student_names,true)) {
  2694. $error_msg[$key]['class_name'] = $val['A'];
  2695. $error_msg[$key]['student_name'] = $val['B'];
  2696. $error_msg[$key]['student_six'] = $val['C'];
  2697. $error_msg[$key]['student_no'] = $val['D'];
  2698. $error_msg[$key]['student_card'] = $val['E'];
  2699. $error_msg[$key]['school_student_card'] = $val['F'];
  2700. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2701. $error_msg[$key]['err_msg'] = '学生在该学校有重名';
  2702. $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
  2703. continue;
  2704. } else {
  2705. //验证准考证号
  2706. $is_current_student = 0;
  2707. if ($card) {
  2708. if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) {
  2709. $is_current_student = 1;
  2710. if ($school_student_names && isset($school_student_names[$use_student_card[$card]]) && $school_student_names[$use_student_card[$card]] != $realname) {
  2711. $error_msg[$key]['class_name'] = $val['A'];
  2712. $error_msg[$key]['student_name'] = $val['B'];
  2713. $error_msg[$key]['student_six'] = $val['C'];
  2714. $error_msg[$key]['student_no'] = $val['D'];
  2715. $error_msg[$key]['student_card'] = $val['E'];
  2716. $error_msg[$key]['school_student_card'] = $val['F'];
  2717. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2718. $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
  2719. $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
  2720. continue;
  2721. }
  2722. }
  2723. //验证新导入的准考证号
  2724. if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) {
  2725. //正在使用中
  2726. $error_msg[$key]['class_name'] = $val['A'];
  2727. $error_msg[$key]['student_name'] = $val['B'];
  2728. $error_msg[$key]['student_six'] = $val['C'];
  2729. $error_msg[$key]['student_no'] = $val['D'];
  2730. $error_msg[$key]['student_card'] = $val['E'];
  2731. $error_msg[$key]['school_student_card'] = $val['F'];
  2732. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2733. $error_msg[$key]['err_msg'] = '系统准考证号正在使用中';
  2734. $error_msg[$key]['so_msg'] = '填写不存在的系统准考证号。可以使用学生管理的搜索功能检验是否存在系统准考证号';
  2735. continue;
  2736. }
  2737. //验证已删除的学生的准考证号
  2738. if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) {
  2739. //验证删除的学生姓名是否一致
  2740. if ( $d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) {
  2741. $error_msg[$key]['class_name'] = $val['A'];
  2742. $error_msg[$key]['student_name'] = $val['B'];
  2743. $error_msg[$key]['student_six'] = $val['C'];
  2744. $error_msg[$key]['student_no'] = $val['D'];
  2745. $error_msg[$key]['student_card'] = $val['E'];
  2746. $error_msg[$key]['school_student_card'] = $val['F'];
  2747. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2748. $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
  2749. $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
  2750. continue;
  2751. }
  2752. //是否存在
  2753. if ($d_student_card == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) {
  2754. $error_msg[$key]['class_name'] = $val['A'];
  2755. $error_msg[$key]['student_name'] = $val['B'];
  2756. $error_msg[$key]['student_six'] = $val['C'];
  2757. $error_msg[$key]['student_no'] = $val['D'];
  2758. $error_msg[$key]['student_card'] = $val['E'];
  2759. $error_msg[$key]['school_student_card'] = $val['F'];
  2760. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2761. $error_msg[$key]['err_msg'] = '学生在该学校有重名';
  2762. $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
  2763. continue;
  2764. }
  2765. }
  2766. //验证上学期的学生
  2767. if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
  2768. if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) {
  2769. $error_msg[$key]['class_name'] = $val['A'];
  2770. $error_msg[$key]['student_name'] = $val['B'];
  2771. $error_msg[$key]['student_six'] = $val['C'];
  2772. $error_msg[$key]['student_no'] = $val['D'];
  2773. $error_msg[$key]['student_card'] = $val['E'];
  2774. $error_msg[$key]['school_student_card'] = $val['F'];
  2775. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2776. $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
  2777. $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
  2778. continue;
  2779. }
  2780. //是否存在
  2781. if ($is_current_student == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) {
  2782. $error_msg[$key]['class_name'] = $val['A'];
  2783. $error_msg[$key]['student_name'] = $val['B'];
  2784. $error_msg[$key]['student_six'] = $val['C'];
  2785. $error_msg[$key]['student_no'] = $val['D'];
  2786. $error_msg[$key]['student_card'] = $val['E'];
  2787. $error_msg[$key]['school_student_card'] = $val['F'];
  2788. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2789. $error_msg[$key]['err_msg'] = '该学生在该在当前学期有重名';
  2790. $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
  2791. continue;
  2792. }
  2793. }else
  2794. {
  2795. $error_msg[$key]['class_name'] = $val['A'];
  2796. $error_msg[$key]['student_name'] = $val['B'];
  2797. $error_msg[$key]['student_six'] = $val['C'];
  2798. $error_msg[$key]['student_no'] = $val['D'];
  2799. $error_msg[$key]['student_card'] = $val['E'];
  2800. $error_msg[$key]['school_student_card'] = $val['F'];
  2801. $error_msg[$key]['zhixue_student_card'] = $val['G'];
  2802. $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
  2803. $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
  2804. continue;
  2805. }
  2806. }
  2807. }
  2808. ///////////////////////////////////////////////////////////
  2809. $sql_count = $sql_count+1;
  2810. //创建学生
  2811. if (!$card ) {
  2812. $student_cart = 0;
  2813. foreach ($create_card_data as $v) {
  2814. if ($v['use'] == 0) {
  2815. $student_cart = $v['student_card'];
  2816. $create_card_data[$student_cart]['use'] = 1;
  2817. break;
  2818. }
  2819. }
  2820. $studentId = current($create_student_ids);
  2821. unset($create_student_ids[$studentId]);
  2822. $student_cart = (int)$student_cart;
  2823. $password = $student_cart;
  2824. // 将学生登录账号插入主数据
  2825. $student_sql .= "(".$studentId.",'".$student_cart."',".$student_cart.",'".$school_card."','".$zhixue_student_card."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".time()."),";
  2826. $student_info_sql .= "(".$studentId.",'".$realname."',".$sex.",".$this->schoolId.",".$get_id.",'','','','','',0,".time().",".time().",0,0.00,0),";
  2827. $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),";
  2828. if($sql_count==400)
  2829. {
  2830. $student_sql = substr($student_sql,0,-1).';';
  2831. $student_sql_arr[] = $student_sql;
  2832. $student_info_sql = substr($student_info_sql,0,-1).';';
  2833. $student_info_arr[] = $student_info_sql;
  2834. $class_student_sql = substr($class_student_sql,0,-1).';';
  2835. $class_student_sql_arr[] = $class_student_sql;
  2836. $student_sql = '';
  2837. $student_info_sql = '';
  2838. $class_student_sql = '';
  2839. $sql_count = 0;
  2840. }
  2841. } else {
  2842. //学生转班
  2843. if(!$error_msg)
  2844. {
  2845. if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
  2846. $studentId = $b_student_cards[$card];
  2847. if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) {
  2848. $update_student_id[$studentId] = $studentId;
  2849. $del_class_student[] = "delete from student_class_relation where class_id = '{$get_id}' and student_id = '{$studentId}' ;";
  2850. //StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId));
  2851. //写入数据
  2852. $b_student_obj = $b_student[$studentId];
  2853. $school_student_obj = $school_student_info[$studentId];
  2854. $student_cart = (int)$card;
  2855. $password = $student_cart;
  2856. $student_sql .= "(".(string)$studentId.",'".$b_student_obj['username']."',".$student_cart.",'".(!empty($school_card)?$school_card:$b_student_obj['school_student_card'])."','".(!empty($zhixue_student_card)?$zhixue_student_card:$b_student_obj['zhixue_student_card'])."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".$b_student_obj['register_time']."),";
  2857. $student_info_sql .= "(".$studentId.",'".$school_student_obj['realname']."',".$school_student_obj['sex'].",".$this->schoolId.",".$get_id.",'".$school_student_obj['family_tel']."','".$school_student_obj['telephone']."','".$school_student_obj['student_phone']."','". $school_student_obj['picture']."','".$school_student_obj['signature']."',". $school_student_obj['is_outer'].",".$school_student_obj['add_time'].",".time().",".$school_student_obj['level'].",".$school_student_obj['ave_score_rate'].",".$school_student_obj['game_stars']."),";
  2858. $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),";
  2859. if($sql_count==400)
  2860. {
  2861. $student_sql = substr($student_sql,0,-1).';';
  2862. $student_sql_arr[] = $student_sql;
  2863. $student_info_sql = substr($student_info_sql,0,-1).';';
  2864. $student_info_arr[] = $student_info_sql;
  2865. $class_student_sql = substr($class_student_sql,0,-1).';';
  2866. $class_student_sql_arr[] = $class_student_sql;
  2867. $student_sql = '';
  2868. $student_info_sql = '';
  2869. $class_student_sql = '';
  2870. $sql_count = 0;
  2871. }
  2872. }
  2873. }
  2874. }
  2875. }
  2876. }
  2877. }
  2878. if($error_msg)
  2879. {
  2880. $this->create_import_xls($error_msg);
  2881. }else
  2882. {
  2883. if($del_class_student){
  2884. foreach ($del_class_student as $v){
  2885. $this->sConn->createCommand($v)->execute();
  2886. }
  2887. }
  2888. if($student_sql)
  2889. {
  2890. $student_sql = substr($student_sql,0,-1).';';
  2891. $student_sql_arr[] = $student_sql;
  2892. }
  2893. if($student_info_sql)
  2894. {
  2895. $student_info_sql = substr($student_info_sql,0,-1).';';
  2896. $student_info_arr[] = $student_info_sql;
  2897. }
  2898. if($class_student_sql)
  2899. {
  2900. $class_student_sql = substr($class_student_sql,0,-1).';';
  2901. $class_student_sql_arr[] = $class_student_sql;
  2902. }
  2903. if(!$student_sql_arr || !$student_info_arr || !$class_student_sql_arr )
  2904. {
  2905. Yii::app()->jump->error('数据有误,无法导入!');exit;
  2906. }
  2907. $b_sql = 'INSERT INTO `student`
  2908. (`student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time`)VALUES';
  2909. $s_sql = 'INSERT INTO `student_info`
  2910. (`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`)VALUES';
  2911. $c_sql = 'INSERT INTO `student_class_relation`
  2912. (`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`status`)VALUES';
  2913. $transaction = Yii::app()->businessDb->beginTransaction();//建立事务
  2914. try{
  2915. if($student_sql_arr)
  2916. {
  2917. if($update_student_id)
  2918. {
  2919. /*
  2920. $criteria = new CDbCriteria();
  2921. $criteria->addInCondition('student_id',$update_student_id);
  2922. BusinessStudent::model()->deleteAll($criteria);
  2923. unset($criteria);
  2924. */
  2925. $businessStudentSql="delete from student where student_id in(".implode(',',$update_student_id).")";
  2926. $this->conn->createCommand($businessStudentSql)->execute();
  2927. }
  2928. foreach($student_sql_arr as $k=>$v)
  2929. {
  2930. if($v==';')
  2931. {
  2932. Yii::app()->jump->error('数据有误,无法导入!');exit;
  2933. }
  2934. $this->conn->createCommand($b_sql.$v)->execute();
  2935. }
  2936. }
  2937. $transaction->commit();
  2938. }catch(Exception $e)
  2939. {
  2940. $transaction->rollBack();
  2941. Yii::app()->jump->error('上传失败,添加学生失败');
  2942. }
  2943. unset($transaction);
  2944. $transaction = $this->sConn->beginTransaction();
  2945. try{
  2946. if($update_student_id)
  2947. {
  2948. $criteria = new CDbCriteria();
  2949. $criteria->addInCondition('student_id',$update_student_id);
  2950. StudentInfo::model()->deleteAll($criteria);
  2951. unset($criteria);
  2952. /*
  2953. if($del_class_student){
  2954. foreach ($del_class_student as $v){
  2955. $this->sConn->createCommand($v)->execute();
  2956. }
  2957. }
  2958. */
  2959. unset($del_class_student);
  2960. $criteria = new CDbCriteria();
  2961. $criteria->addInCondition('student_id',$update_student_id);
  2962. $criteria->addCondition('status = 0');
  2963. $criteria->addCondition('class_type = 1');
  2964. StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3),$criteria);
  2965. unset($criteria);
  2966. /*
  2967. $StudentSql="delete from `student_info` where `student_id` in (".implode(',',$update_student_id).")";
  2968. $this->sConn->createCommand($StudentSql)->execute();
  2969. $StudentToClassSql="update `student_class_relation` set `status`=1 and `update_time`=".time()." where`student_id` in (".implode(',',$update_student_id).") and `status`=0 ";
  2970. $this->sConn->createCommand($StudentToClassSql)->execute();
  2971. */
  2972. }
  2973. if($student_info_arr)
  2974. {
  2975. foreach($student_info_arr as $k=>$v)
  2976. {
  2977. if($v==';')
  2978. {
  2979. Yii::app()->jump->error('数据有误,无法导入!');exit;
  2980. }
  2981. $this->sConn->createCommand($s_sql.$v)->execute();
  2982. }
  2983. }
  2984. if($class_student_sql_arr)
  2985. {
  2986. foreach($class_student_sql_arr as $k=>$v)
  2987. {
  2988. if($v==';')
  2989. {
  2990. Yii::app()->jump->error('数据有误,无法导入!');exit;
  2991. }
  2992. $this->sConn->createCommand($c_sql.$v)->execute();
  2993. }
  2994. }
  2995. $transaction->commit();
  2996. }catch(Exception $e)
  2997. {
  2998. $transaction->rollBack();
  2999. Yii::app()->jump->error('上传失败,添加学生失败');
  3000. }
  3001. unset($create_student_ids);
  3002. $this->redirect(Yii::app()->createUrl('studentinfo/index'));
  3003. }
  3004. }
  3005. }
  3006. public function actionStudent_import()
  3007. {
  3008. $this->render('student_import');
  3009. }
  3010. // 导入学生
  3011. public function actionImport_brack()
  3012. {
  3013. $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
  3014. if (empty($get_id) || !($class = $this->schoolManager->getClass($get_id)))
  3015. {
  3016. Yii::app()->jump->error('无法访问!');
  3017. }
  3018. if($this->schoolManager->isPreviousSemester($class["semester_id"]))
  3019. {
  3020. Yii::app()->jump->error('不能为已完成学期的班级导入学生!');
  3021. }
  3022. if (Yii::app()->request->getIsPostRequest()){
  3023. $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
  3024. $uploader->allowTypes = array("xls");
  3025. $uploader->fieldsMappings = array("exname" => array(0 => $get_id));
  3026. $file = $uploader->act();
  3027. $file = Arr::current(Arr::current($file));
  3028. if(!$file || !isset($file["error"]))
  3029. Yii::app()->jump->error('请选择上传的Excel!');
  3030. if($file["error"] != 0){
  3031. switch($file["error"]){
  3032. case 2001:
  3033. Yii::app()->jump->error('文件类型不符');
  3034. break;
  3035. case 2002:
  3036. Yii::app()->jump->error('文件大小超出允许范围');
  3037. break;
  3038. default:
  3039. Yii::app()->jump->error('上传失败');
  3040. break;
  3041. }
  3042. }
  3043. $result = true;
  3044. $inputFileName = $file["src"];
  3045. if ($result) {
  3046. $semesterId = $this->semesterId;
  3047. Yii::import('application.extensions.*');
  3048. require_once('phpexcel/PHPExcel/IOFactory.php');
  3049. // 读取Excel文档
  3050. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  3051. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  3052. //FIXME 2019-12-02
  3053. @unlink($file["src"]);
  3054. // 去掉导航
  3055. //dump($sheetData);die;
  3056. unset($sheetData[1]);
  3057. krsort($sheetData);
  3058. $serial_number = 0;
  3059. $b_student_cards = array();
  3060. $b_id_student_cards = array();
  3061. $b_school_student_cards = array();
  3062. $b_id_school_student_cards = array();
  3063. $b_student_ids = array();
  3064. $b_student = array();
  3065. $class_ids = array();
  3066. $class_names = array();
  3067. $c_class_names = array();
  3068. $grade = 0;
  3069. $n_class_id = array();
  3070. $n_student_ids = array();
  3071. $s_student_ids = array();
  3072. $d_student_ids = array();// 删除学生ID
  3073. $d_student_card = array();
  3074. $d_student_names = array();
  3075. $d_school_student_card = array();
  3076. $use_student_card = array();
  3077. $use_school_student_card = array();
  3078. $error_msg = array();
  3079. $students = array();
  3080. $cards = array();
  3081. $student_info_name = array();
  3082. $student_names = array();
  3083. $school_student_names = array();
  3084. $school_student_info = array();
  3085. //获当前学校的学生准考证号
  3086. $b_student_all_data = BusinessStudent::model()->findAll(array(
  3087. 'order' => 'student_card desc',
  3088. 'condition' => 'school_id=:school_id',
  3089. 'params' => array(':school_id'=>$this->schoolId)
  3090. ));
  3091. if($b_student_all_data)
  3092. {
  3093. foreach($b_student_all_data as $v)
  3094. {
  3095. $b_student[$v->student_id] = $v;
  3096. $b_student_ids[$v->student_id] = $v->student_id;
  3097. $b_id_student_cards[$v->student_id] = $v->student_card;
  3098. $b_id_school_student_cards[$v->student_id] = $v->school_student_card;
  3099. if($v->student_card)
  3100. {
  3101. $b_student_cards[$v->student_card] = $v->student_id;
  3102. }
  3103. if($v->school_student_card)
  3104. {
  3105. $b_school_student_cards[$v->school_student_card] = $v->student_id;
  3106. }
  3107. }
  3108. }
  3109. //获取当前学校所有学生信息
  3110. $student_info_data = SStudentInfo::model()->findAll();
  3111. if($student_info_data)
  3112. {
  3113. foreach($student_info_data as $v)
  3114. {
  3115. $school_student_info[$v->student_id] = $v;
  3116. $school_student_names[$v->student_id] = $v->realname;
  3117. }
  3118. }
  3119. $student_class_data = SStudentClassRelation::model()->find(array(
  3120. 'select' => 'serial_number',
  3121. 'order' => 'serial_number desc',
  3122. 'condition' => 'class_id=:class_id and status=:status',
  3123. 'limit' => 1,
  3124. 'params' => array(':class_id'=>$get_id,':status'=>0)
  3125. ));
  3126. if($student_class_data)
  3127. {
  3128. if($student_class_data->serial_number)
  3129. {
  3130. $serial_number = $student_class_data->serial_number;
  3131. }
  3132. }
  3133. // 获取当前学期的所有班级
  3134. $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
  3135. if($class_semester_data)
  3136. {
  3137. foreach($class_semester_data as $v)
  3138. {
  3139. $class_ids[$v->class_id] = $v->class_id;
  3140. $c_class_names[$v->class_id] = $v->class_name;
  3141. }
  3142. }
  3143. if(!$class_ids)
  3144. {
  3145. Yii::app()->jump->error('无班级信息,导入失败');
  3146. }
  3147. // 获取年级信息
  3148. $grade_data = SGradeModel::model()->find('id=:id',array(':id'=>$class['grade']));
  3149. if(!$grade_data)
  3150. {
  3151. Yii::app()->jump->error('此班级无年级信息,导入失败');
  3152. }
  3153. $sheetData = array_reverse($sheetData);
  3154. // 获取在线学生
  3155. $criteria = new CDbCriteria();
  3156. $criteria->addInCondition('class_id',$class_ids);
  3157. $criteria->addCondition('status=0');
  3158. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  3159. if($semester_student_class_data)
  3160. {
  3161. foreach($semester_student_class_data as $v)
  3162. {
  3163. //在线学生ID
  3164. $s_student_ids[$v->student_id] = $v->student_id;
  3165. //在线学生准考证号
  3166. if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
  3167. {
  3168. $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
  3169. }
  3170. //在线学校准考证号
  3171. if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
  3172. {
  3173. $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
  3174. }
  3175. //获取在线学生信息
  3176. if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
  3177. {
  3178. $student_names[$v->student_id] = $school_student_names[$v->student_id];
  3179. }
  3180. }
  3181. }
  3182. //获取已删除的学生信息
  3183. $criteria = new CDbCriteria();
  3184. $criteria->addInCondition('class_id',$class_ids);
  3185. $criteria->addCondition('status=1');
  3186. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  3187. if($semester_student_class_data)
  3188. {
  3189. foreach($semester_student_class_data as $v)
  3190. {
  3191. //已删除学生ID
  3192. $d_student_ids[$v->student_id] = $v->student_id;
  3193. //在线学生准考证号
  3194. if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
  3195. {
  3196. $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
  3197. }
  3198. //在线学校准考证号
  3199. if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
  3200. {
  3201. $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
  3202. }
  3203. //获取在线学生信息
  3204. if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
  3205. {
  3206. $d_student_names[$v->student_id] = $school_student_names[$v->student_id];
  3207. }
  3208. }
  3209. }
  3210. //预定学生准考证号
  3211. $create_card_data = $this->createCard(count($sheetData));
  3212. foreach ($sheetData as $key=>$val) {
  3213. if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
  3214. continue;
  3215. }
  3216. if (empty($val['A']) OR empty($val['B'])) {
  3217. $error_msg[$key]['student_name'] = $val['A'];
  3218. $error_msg[$key]['student_six'] = $val['B'];
  3219. $error_msg[$key]['student_no'] = $val['C'];
  3220. $error_msg[$key]['student_card'] = $val['D'];
  3221. $error_msg[$key]['school_student_card'] = $val['E'];
  3222. $error_msg[$key]['err_msg'] = '学生姓名与性别不能为空';
  3223. $error_msg[$key]['so_msg'] = '填写正确的学生姓名与性别';
  3224. continue;
  3225. }
  3226. $realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['A']));
  3227. $sex = safe_replace($val['B']);
  3228. $userno = safe_replace($val['C']);
  3229. $card = 0;
  3230. $username = $realname;
  3231. if (isset($val['D'])) {
  3232. $card = safe_replace($val['D']);
  3233. }
  3234. $school_card = '';
  3235. if (isset($val['E']) && !empty($val['E'])) {
  3236. $school_card = safe_replace($val['E']);
  3237. if (strlen($school_card) != $grade_data->card_length) {
  3238. $error_msg[$key]['student_name'] = $val['A'];
  3239. $error_msg[$key]['student_six'] = $val['B'];
  3240. $error_msg[$key]['student_no'] = $val['C'];
  3241. $error_msg[$key]['student_card'] = $val['D'];
  3242. $error_msg[$key]['school_student_card'] = $val['E'];
  3243. $error_msg[$key]['err_msg'] = '学校准考证号长度不正确';
  3244. $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。';
  3245. continue;
  3246. }
  3247. if ($use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
  3248. $error_msg[$key]['student_name'] = $val['A'];
  3249. $error_msg[$key]['student_six'] = $val['B'];
  3250. $error_msg[$key]['student_no'] = $val['C'];
  3251. $error_msg[$key]['student_card'] = $val['D'];
  3252. $error_msg[$key]['school_student_card'] = $val['E'];
  3253. $error_msg[$key]['err_msg'] = '学校准考证号已存在';
  3254. $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前期不存在的学校准考证号';
  3255. continue;
  3256. }
  3257. }
  3258. if (in_array($username, $students)) {
  3259. $error_msg[$key]['student_name'] = $val['A'];
  3260. $error_msg[$key]['student_six'] = $val['B'];
  3261. $error_msg[$key]['student_no'] = $val['C'];
  3262. $error_msg[$key]['student_card'] = $val['D'];
  3263. $error_msg[$key]['school_student_card'] = $val['E'];
  3264. $error_msg[$key]['err_msg'] = '表格中存在姓名重复';
  3265. $error_msg[$key]['so_msg'] = '在表格中删除重复学生';
  3266. continue;
  3267. }
  3268. $students[] = $username;
  3269. if (!empty($card)) {
  3270. if (in_array($card, $cards)) {
  3271. $error_msg[$key]['student_name'] = $val['A'];
  3272. $error_msg[$key]['student_six'] = $val['B'];
  3273. $error_msg[$key]['student_no'] = $val['C'];
  3274. $error_msg[$key]['student_card'] = $val['D'];
  3275. $error_msg[$key]['school_student_card'] = $val['E'];
  3276. $error_msg[$key]['err_msg'] = '表格中存在姓名准考证号';
  3277. $error_msg[$key]['so_msg'] = '在表格中删除重复准考证号';
  3278. continue;
  3279. }
  3280. $cards[] = $card;
  3281. }
  3282. if ($sex != 1 && $sex != 2) {
  3283. $error_msg[$key]['student_name'] = $val['A'];
  3284. $error_msg[$key]['student_six'] = $val['B'];
  3285. $error_msg[$key]['student_no'] = $val['C'];
  3286. $error_msg[$key]['student_card'] = $val['D'];
  3287. $error_msg[$key]['school_student_card'] = $val['E'];
  3288. $error_msg[$key]['err_msg'] = '性别填写有误';
  3289. $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)';
  3290. continue;
  3291. }
  3292. //判断学生是否存在
  3293. if ($student_names && $_student_id = array_search($realname, $student_names,true)) {
  3294. $error_msg[$key]['student_name'] = $val['A'];
  3295. $error_msg[$key]['student_six'] = $val['B'];
  3296. $error_msg[$key]['student_no'] = $val['C'];
  3297. $error_msg[$key]['student_card'] = $val['D'];
  3298. $error_msg[$key]['school_student_card'] = $val['E'];
  3299. $error_msg[$key]['err_msg'] = '学生在该学校有重名';
  3300. $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
  3301. continue;
  3302. } else {
  3303. //验证准考证号
  3304. if ($card) {
  3305. if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) {
  3306. //正在使用中
  3307. $error_msg[$key]['student_name'] = $val['A'];
  3308. $error_msg[$key]['student_six'] = $val['B'];
  3309. $error_msg[$key]['student_no'] = $val['C'];
  3310. $error_msg[$key]['student_card'] = $val['D'];
  3311. $error_msg[$key]['school_student_card'] = $val['E'];
  3312. $error_msg[$key]['err_msg'] = '学生准考证号正在使用中';
  3313. $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
  3314. continue;
  3315. }
  3316. //验证新导入的准考证号
  3317. if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) {
  3318. //正在使用中
  3319. $error_msg[$key]['student_name'] = $val['A'];
  3320. $error_msg[$key]['student_six'] = $val['B'];
  3321. $error_msg[$key]['student_no'] = $val['C'];
  3322. $error_msg[$key]['student_card'] = $val['D'];
  3323. $error_msg[$key]['school_student_card'] = $val['E'];
  3324. $error_msg[$key]['err_msg'] = '学生准考证号正在使用中';
  3325. $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
  3326. continue;
  3327. }
  3328. //验证已删除的学生的准考证号
  3329. if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) {
  3330. //验证删除的学生姓名是否一致
  3331. if ($d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) {
  3332. $error_msg[$key]['student_name'] = $val['A'];
  3333. $error_msg[$key]['student_six'] = $val['B'];
  3334. $error_msg[$key]['student_no'] = $val['C'];
  3335. $error_msg[$key]['student_card'] = $val['D'];
  3336. $error_msg[$key]['school_student_card'] = $val['E'];
  3337. $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
  3338. $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
  3339. continue;
  3340. }
  3341. }
  3342. //验证上学期的学生
  3343. if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
  3344. if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) {
  3345. $error_msg[$key]['student_name'] = $val['A'];
  3346. $error_msg[$key]['student_six'] = $val['B'];
  3347. $error_msg[$key]['student_no'] = $val['C'];
  3348. $error_msg[$key]['student_card'] = $val['D'];
  3349. $error_msg[$key]['school_student_card'] = $val['E'];
  3350. $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
  3351. $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
  3352. continue;
  3353. }
  3354. }else
  3355. {
  3356. $error_msg[$key]['student_name'] = $val['A'];
  3357. $error_msg[$key]['student_six'] = $val['B'];
  3358. $error_msg[$key]['student_no'] = $val['C'];
  3359. $error_msg[$key]['student_card'] = $val['D'];
  3360. $error_msg[$key]['school_student_card'] = $val['E'];
  3361. $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
  3362. $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
  3363. continue;
  3364. }
  3365. }
  3366. }
  3367. ///////////////////////////////////////////////////////////
  3368. //创建学生
  3369. if (!$card) {
  3370. $student_cart = 0;
  3371. foreach ($create_card_data as $v) {
  3372. if ($v['use'] == 0) {
  3373. $student_cart = $v['student_card'];
  3374. break;
  3375. }
  3376. }
  3377. //$studentId = getUUID();
  3378. $studentId=getUniqueId($this->schoolId);
  3379. $student_cart = (int)$student_cart;
  3380. $password = $student_cart;
  3381. // 将学生登录账号插入主数据
  3382. $studentModel = new BusinessStudent();
  3383. $studentModel->username = $student_cart;
  3384. $studentModel->password = md5(sha1($password . 'wy') . 'fengche');
  3385. $studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
  3386. $studentModel->student_id = $studentId;
  3387. $studentModel->student_card = $student_cart;
  3388. $studentModel->school_student_card = $school_card ? $school_card : '';
  3389. $studentModel->register_time = time();
  3390. if ($studentModel->save()) {
  3391. // 学校库插入学生基本信息
  3392. $userModel = new StudentInfo();
  3393. $userModel->student_id = $studentId;
  3394. $userModel->realname = $realname;
  3395. $userModel->school_id = $this->schoolId;
  3396. $userModel->class_id = $get_id;
  3397. $userModel->add_time = time();
  3398. $userModel->sex = $sex;
  3399. $userModel->telephone = '';
  3400. if ($userModel->save()) {
  3401. // 创建学生与班级关联关系
  3402. $studentClass = new StudentToClass();
  3403. $studentClass->class_id = $get_id;
  3404. $studentClass->student_id = $studentId;
  3405. $studentClass->serial_number = $serial_number +$key+ 1;
  3406. $studentClass->userno = $userno;
  3407. $studentClass->update_time = time();
  3408. $studentClass->status = "0";
  3409. $studentClass->save();
  3410. } else {
  3411. //数据写入失败
  3412. $error_msg[$key]['student_name'] = $val['A'];
  3413. $error_msg[$key]['student_six'] = $val['B'];
  3414. $error_msg[$key]['student_no'] = $val['C'];
  3415. $error_msg[$key]['student_card'] = $val['D'];
  3416. $error_msg[$key]['school_student_card'] = $val['E'];
  3417. $error_msg[$key]['err_msg'] = '数据写入失败';
  3418. $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
  3419. continue;
  3420. }
  3421. } else {
  3422. //数据写入失败
  3423. $error_msg[$key]['student_name'] = $val['A'];
  3424. $error_msg[$key]['student_six'] = $val['B'];
  3425. $error_msg[$key]['student_no'] = $val['C'];
  3426. $error_msg[$key]['student_card'] = $val['D'];
  3427. $error_msg[$key]['school_student_card'] = $val['E'];
  3428. $error_msg[$key]['err_msg'] = '数据写入失败';
  3429. $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
  3430. continue;
  3431. }
  3432. $create_card_data[$student_cart]['use'] = 1;
  3433. continue;
  3434. } else {
  3435. //学生转班
  3436. if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
  3437. $studentId = $b_student_cards[$card];
  3438. if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) {
  3439. BusinessStudent::model()->deleteAll('student_id=:sid', array(':sid' => $studentId));
  3440. StudentInfo::model()->deleteAll('student_id=:sid', array(':sid' => $studentId));
  3441. StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3), 'student_id=:sid and status = 0', array(':sid' => $studentId));
  3442. StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId));
  3443. //写入数据
  3444. $b_student_obj = $b_student[$studentId];
  3445. $school_student_obj = $school_student_info[$studentId];
  3446. $student_cart = (int)$card;
  3447. $password = $student_cart;
  3448. // 将学生登录账号插入主数据
  3449. $studentModel = new BusinessStudent();
  3450. $studentModel->username = $b_student_obj->username;
  3451. $studentModel->password = md5(sha1($password . 'wy') . 'fengche');
  3452. $studentModel->school_id = $this->schoolId;
  3453. $studentModel->student_id = $studentId;
  3454. $studentModel->student_card = $student_cart;
  3455. if ($school_card) {
  3456. $studentModel->school_student_card = $school_card;
  3457. } else {
  3458. $studentModel->school_student_card = $b_student_obj->school_student_card;
  3459. }
  3460. $studentModel->register_time = $b_student_obj->register_time;
  3461. if ($studentModel->save()) {
  3462. // 学校库插入学生基本信息
  3463. $userModel = new StudentInfo();
  3464. $userModel->student_id = $studentId;
  3465. $userModel->realname = $school_student_obj->realname;
  3466. $userModel->sex = $school_student_obj->sex;
  3467. $userModel->school_id = $this->schoolId;
  3468. $userModel->class_id = $get_id;
  3469. $userModel->family_tel = $school_student_obj->family_tel;
  3470. $userModel->telephone = $school_student_obj->telephone;
  3471. $userModel->student_phone = $school_student_obj->student_phone;
  3472. $userModel->picture = $school_student_obj->picture;
  3473. $userModel->signature = $school_student_obj->signature;
  3474. $userModel->is_outer = $school_student_obj->is_outer;
  3475. $userModel->add_time = $school_student_obj->add_time;
  3476. $userModel->update_time = time();
  3477. $userModel->level = $school_student_obj->level;
  3478. $userModel->ave_score_rate = $school_student_obj->ave_score_rate;
  3479. $userModel->game_stars = $school_student_obj->game_stars;
  3480. if ($userModel->save()) {
  3481. // 创建学生与班级关联关系
  3482. $studentClass = new StudentToClass();
  3483. $studentClass->class_id = $get_id;
  3484. $studentClass->student_id = $studentId;
  3485. $studentClass->serial_number = $serial_number +$key+ 1;
  3486. $studentClass->userno = $userno;
  3487. $studentClass->update_time = time();
  3488. $studentClass->status = "0";
  3489. $studentClass->save();
  3490. } else {
  3491. //数据写入失败
  3492. $error_msg[$key]['student_name'] = $val['A'];
  3493. $error_msg[$key]['student_six'] = $val['B'];
  3494. $error_msg[$key]['student_no'] = $val['C'];
  3495. $error_msg[$key]['student_card'] = $val['D'];
  3496. $error_msg[$key]['school_student_card'] = $val['E'];
  3497. $error_msg[$key]['err_msg'] = '数据写入失败';
  3498. $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
  3499. continue;
  3500. }
  3501. } else {
  3502. //数据写入失败
  3503. $error_msg[$key]['student_name'] = $val['A'];
  3504. $error_msg[$key]['student_six'] = $val['B'];
  3505. $error_msg[$key]['student_no'] = $val['C'];
  3506. $error_msg[$key]['student_card'] = $val['D'];
  3507. $error_msg[$key]['school_student_card'] = $val['E'];
  3508. $error_msg[$key]['err_msg'] = '数据写入失败';
  3509. $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
  3510. continue;
  3511. }
  3512. continue;
  3513. }
  3514. }
  3515. }
  3516. }
  3517. }
  3518. if($error_msg)
  3519. {
  3520. $this->create_import_xls($error_msg);
  3521. }else
  3522. {
  3523. $this->redirect(Yii::app()->createUrl('classes/view',array('cid'=>$get_id)));
  3524. }
  3525. }
  3526. $data = array();
  3527. $data['cid'] = $get_id;
  3528. $this->render('import',$data);
  3529. }
  3530. public function actionDelClassAct(){
  3531. $classId = Req::post("classId");
  3532. if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1))
  3533. {
  3534. $rs = $this->schoolManager->delClass($classId);
  3535. if(Yii::app()->params['handle_log_on_off'])
  3536. {
  3537. writeFileLog(jsonEncode(array(
  3538. "exam_group_id" => 0,
  3539. "operate_project" => 'zsyas2',
  3540. "school_id" => $this->schoolId,
  3541. "title" => '使用权限删除班级',
  3542. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3543. "operate_method" => $this->action,
  3544. "operate_url" => $this->getRoute(),
  3545. "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
  3546. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3547. "date"=>date('Y-m-d H:i:s')
  3548. )));
  3549. }
  3550. }else{
  3551. $rs = $this->schoolManager->CoachdelClass($classId);
  3552. if(Yii::app()->params['handle_log_on_off'])
  3553. {
  3554. writeFileLog(jsonEncode(array(
  3555. "exam_group_id" => 0,
  3556. "operate_project" => 'zsyas2',
  3557. "school_id" => $this->schoolId,
  3558. "title" => '删除班级',
  3559. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3560. "operate_method" => $this->action,
  3561. "operate_url" => $this->getRoute(),
  3562. "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
  3563. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3564. "date"=>date('Y-m-d H:i:s')
  3565. )));
  3566. }
  3567. }
  3568. //更新REDSI
  3569. Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
  3570. echo json_encode($rs);exit;
  3571. }
  3572. //删除班级前校验
  3573. public function actionCheckBeforeDelClass(){
  3574. $classId = Req::post("classId");
  3575. $result['status']=0;
  3576. if(!$classId){
  3577. $result['msg']='参数错误';
  3578. exit(json_encode($result));
  3579. }
  3580. $checkStatusCode=0;
  3581. if($this->schoolManager->classHasStudent($classId)){
  3582. $checkStatusCode+=2;
  3583. }
  3584. if($this->schoolManager->classHasExam($classId)){
  3585. $checkStatusCode+=1;
  3586. }
  3587. $result['status']=1;
  3588. $result['data']=$checkStatusCode;
  3589. exit(json_encode($result));
  3590. }
  3591. public function actionClassHasStudent(){
  3592. $classId = Req::get("classId");
  3593. $rs = $this->schoolManager->classHasStudent($classId);
  3594. echo $rs ? 1 : 0;
  3595. }
  3596. public function actionDownloadStudentsQrcodesAct(){
  3597. $classId = Req::get("classId");
  3598. $studentsIds = Req::get("studentsIds");
  3599. $force = Req::get("force");
  3600. $force = $force == 1 ? true : false;
  3601. $style = Req::get("style");
  3602. $amount = Req::get("amount");
  3603. $amount = Number::isInt($amount) && $amount > 0 ? $amount : 8;
  3604. $filePath = Yii::app()->basePath."/../".Yii::app()->params["qrcode_path"]."schools/{$this->schoolId}/".date("Y", time())."/";
  3605. File::mkdir($filePath);
  3606. //for test
  3607. $force = true;
  3608. $style = 1;
  3609. $class = $this->schoolManager->getClass($classId);
  3610. $className = $class ? $class["class_name"] : null;
  3611. if($studentsIds)
  3612. $studentsIds = explode(",", $studentsIds);
  3613. $students = array();
  3614. $linedBy = "STUDENT";
  3615. if($studentsIds){
  3616. $students = $this->schoolManager->getStudents($studentsIds);
  3617. }
  3618. else if($classId){
  3619. $linedBy = "CLASSSTUDENTS";
  3620. $students = $this->schoolManager->getClassStudents($classId, null, "ARRAY");
  3621. }
  3622. foreach($students as $key => $student){
  3623. $file = $filePath.$student["student_id"].".png";
  3624. if(is_file($file) && !$force)
  3625. continue;
  3626. $string = "{$student["student_id"]}-{$student["serial_number"]}";
  3627. QRcode::png($string, $file, "H", 2.7, 4);
  3628. if(!is_file($file)){
  3629. unset($students[$key]);
  3630. continue;
  3631. }
  3632. $src = Image::createFromFile($file);
  3633. switch($style){
  3634. case 1:
  3635. Image::Crop($src, array("w" => 70, "h" => 70, "x" => 8, "y" => 9), array("w" => 85, "h" => 85, "x" => "center", "y" => 0, "color" => array(255, 255, 255, 100)));
  3636. Image::sign($src, "{$student["realname"]}-{$student["serial_number"]}", array("size" => 7.5, "color" => array(0, 0, 0), "x" => "center", "y" => "bottom -2"));
  3637. Image::setBorder($src);
  3638. break;
  3639. case 2:
  3640. Image::Crop($src, array("w" => 70, "h" => 70, "x" => 12, "y" => 12), array("w" => 80, "h" => 80, "x" => 3, "y" => 3, "color" => array(255, 255, 255, 0)));
  3641. Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center -5", "y" => 68));
  3642. Image::sign($src, "No:{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "71", "y" => 6, "angle" => -90));
  3643. Image::setBorder($src);
  3644. break;
  3645. case 3:
  3646. Image::Crop($src, array("w" => 70, "h" => 70, "x" => 12, "y" => 12), array("w" => 80, "h" => 80, "x" => 13, "y" => 13, "color" => array(255, 255, 255, 0)));
  3647. Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center 5", "y" => 1));
  3648. Image::sign($src, "{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "2", "y" => 16, "angle" => -90));
  3649. Image::setBorder($src);
  3650. break;
  3651. case 4:
  3652. default:
  3653. $font = Image::create(25, 25, array(255, 255, 255, 0));
  3654. Image::sign($font, $student["realname"], array("size" => 7, "color" => array(0, 0, 0), "x" => "center", "y" => "center"));
  3655. Image::Crop($src, array("w" => 71, "h" => 71, "x" => 8, "y" => 8), array("w" => 80, "h" => 80, "x" => "center", "y" => "center", "color" => array(255, 255, 255, 100)));
  3656. $images = array(
  3657. array(
  3658. "res" => $font,
  3659. "layer_num" => 1,
  3660. "x" => "center",
  3661. "y" => "center",
  3662. "w" => 25,
  3663. "h" => 25
  3664. ),
  3665. array(
  3666. "res" => $src,
  3667. "layer_num" => 2,
  3668. "x" => "left",
  3669. "y" => "top",
  3670. "w" => 80,
  3671. "h" => 80
  3672. ),
  3673. );
  3674. $src = Image::puzzle(array("w" => 80, "h" => 80), $images);
  3675. Image::setBorder($src);
  3676. break;
  3677. }
  3678. $students[$key]["pic"] = $file;
  3679. if(!Image::saveAs($src, $file))
  3680. unset($students[$key]);
  3681. }
  3682. Yii::$enableIncludePath = FALSE;
  3683. Yii::import('application.extensions.phpword.PHPWord', 1);
  3684. $time = time();
  3685. $schoolInfo = $this->schoolManager->getSchoolInfo();
  3686. $area = $this->schoolManager->getSchoolAreaFromSchoolInfo($schoolInfo);
  3687. $filename = "{$schoolInfo["school_name"]}{$className}学生的二维码";
  3688. $title = "{$schoolInfo["school_name"]}{$className}学生的二维码";
  3689. $encodeFilename = urlencode($filename);
  3690. $encodeFilename = str_replace("+", "%20", $encodeFilename);
  3691. $userAgent = $_SERVER["HTTP_USER_AGENT"];
  3692. // New Word Document
  3693. $PHPWord = new PHPWord();
  3694. $PHPWord->setDefaultFontName('Tahoma');
  3695. $PHPWord->setDefaultFontSize(9);
  3696. $properties = $PHPWord->getProperties();
  3697. $properties->setCreator('CeeFee');
  3698. $properties->setLastModifiedBy('CeeFee');
  3699. $properties->setCreated($time);
  3700. $properties->setModified($time);
  3701. $properties->setCompany('上海互教教育科技有限公司');
  3702. $properties->setTitle($filename);
  3703. $sectionStyle = array(
  3704. 'orientation' => null,
  3705. 'marginLeft' => 355,
  3706. 'marginRight' => 355,
  3707. 'marginTop' => 900,
  3708. 'marginBottom' => 900
  3709. );
  3710. // Define table style arrays
  3711. $styleTable = array('borderSize' => 0, 'borderColor' => 'ffffff', 'tableAlign' => 'center', 'cellMarginTop'=>80, 'cellMarginLeft'=>80, 'cellMarginRight'=>80, 'cellMarginBottom'=>80);
  3712. // Define cell style arrays
  3713. $styleCell = array('marginTop' => '5', 'valign' => 'center', 'align' => 'center');
  3714. $styleCellBTLR = array('valign' => 'center', 'align' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR);
  3715. // Define font style for first row
  3716. $fontStyle = array('align' => 'center', 'size' => 9);
  3717. // Add table style
  3718. $PHPWord->addTableStyle('myOwnTableStyle', $styleTable);
  3719. if($linedBy == "STUDENT"){
  3720. $rowSize = 8;
  3721. $pageSize = 10;
  3722. $count = 0;
  3723. $rowsCount = 0;
  3724. $pagesCount = 0;
  3725. $repeatedTimes = 1;
  3726. $studentRepeatedTimes = $amount;
  3727. }
  3728. else{
  3729. $rowSize = 8;
  3730. $pageSize = 10;
  3731. $count = 0;
  3732. $rowsCount = 0;
  3733. $pagesCount = 0;
  3734. $repeatedTimes = $amount;
  3735. $studentRepeatedTimes = 1;
  3736. }
  3737. for($j = 0; $j < $repeatedTimes; $j++){
  3738. foreach($students as $student){
  3739. for($i = 0; $i < $studentRepeatedTimes; $i++){
  3740. if($count == $rowSize){
  3741. $count = 0;
  3742. $rowsCount++;
  3743. }
  3744. if(($rowsCount == 0 && $pagesCount == 0) || $rowsCount == $pageSize){
  3745. $section = $PHPWord->createSection($sectionStyle);
  3746. $section->addText(PHPWord_Media::UTF8ToGBK($title), array_merge($fontStyle, array('bold' => TRUE)), array('align' => 'center'));
  3747. $table = $section->addTable('myOwnTableStyle');
  3748. $rowsCount = 0;
  3749. $pagesCount++;
  3750. }
  3751. if($count == 0){
  3752. $table->addRow(300);
  3753. }
  3754. $table->addCell(1420, $styleCell)->addImage($student["pic"]);
  3755. $count++;
  3756. }
  3757. }
  3758. }
  3759. header('Content-Type: application/msword');
  3760. if (preg_match("/MSIE/i", $userAgent) OR preg_match('/Trident/i', $userAgent))
  3761. {
  3762. header('Content-Disposition: attachment; filename="'. $encodeFilename .'.docx"');
  3763. }
  3764. else if (preg_match("/Firefox/i", $userAgent))
  3765. {
  3766. header('Content-Disposition: attachment; filename*="utf8\'\''. $filename .'.docx"');
  3767. }
  3768. else
  3769. {
  3770. header('Content-Disposition: attachment; filename="'. $filename .'.docx"');
  3771. }
  3772. header('Cache-Control: max-age=0');
  3773. $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
  3774. $objWriter->save('php://output');
  3775. }
  3776. public function actionGetSubjectMaterials()
  3777. {
  3778. $toFiltMaterialsIds = array(13, 14, 15, 16);
  3779. $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
  3780. $subjectId = Req::get("subjectId");
  3781. $rs = Curl::post(Yii::app()->params["material_url"]."/subjectId/{$subjectId}/depth/3");
  3782. $rs = json_decode($rs, true);
  3783. if(!isset($rs["status"]) && $rs){
  3784. foreach($rs as $key => $material){
  3785. if(isset($material["modules"])){
  3786. foreach($material["modules"] as $moduleKey => $module){
  3787. if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
  3788. unset($rs[$key]["modules"][$moduleKey]);
  3789. }
  3790. }
  3791. }
  3792. if(empty($rs[$key]["modules"]))
  3793. unset($rs[$key]);
  3794. }
  3795. }
  3796. $rs = json_encode($rs);
  3797. header("Content-Type: application/json");
  3798. echo $rs;exit;
  3799. }
  3800. // 导入学生
  3801. protected function insertNewStudent($userName_array,$password_array,$realname_array,$userno_array,$_IDX_array,$sex_array,$get_id,$_no_student_id=array())
  3802. {
  3803. /**
  3804. * 如果全是新学生则
  3805. * 添加三张表。分别 spider_business.student,school.student_info,school.student_class_relation
  3806. */
  3807. $student_ids = array();
  3808. //添加 spider_business.student
  3809. $transaction = Yii::app()->businessDb->beginTransaction();//建立事务
  3810. try{
  3811. $sql1 = '';
  3812. $sql = 'INSERT INTO `student` (`student_id`,`username`,`password`,`school_id`,`register_time`,`login_time`,`status`)VALUES';
  3813. foreach($userName_array as $username)
  3814. {
  3815. if($_no_student_id)
  3816. {
  3817. $sql1.='('.$_no_student_id[$username].',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),';
  3818. }else
  3819. {
  3820. //$uuid = getUUID();
  3821. $uuid=getUniqueId($this->schoolId);
  3822. $sql1.='('.$uuid.',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),';
  3823. $student_ids[$username] = $uuid;
  3824. }
  3825. }
  3826. $sql .= substr($sql1,0,-1).';';
  3827. Yii::app()->businessDb->createCommand($sql)->execute();
  3828. $transaction->commit();
  3829. }catch(Exception $e)
  3830. {
  3831. $transaction->rollBack();
  3832. Yii::app()->jump->error('上传失败,添加学生失败');
  3833. }
  3834. unset($username);
  3835. if($_no_student_id && !$student_ids)
  3836. {
  3837. $student_ids = $_no_student_id;
  3838. }
  3839. try{
  3840. $this->schoolManager->insertStudentInfoAndStudentClass($userName_array,$student_ids,$realname_array,$userno_array,$_IDX_array,$sex_array,$this->schoolId,$get_id);
  3841. }catch(Exception $e)
  3842. {
  3843. $transaction->rollBack();
  3844. Yii::app()->jump->error('上传失败,添加学生失败');
  3845. }
  3846. }
  3847. public function actionSelectdel()
  3848. {
  3849. $classId = Req::post("classId");
  3850. $studentsIds = Req::post("studentsIds");
  3851. if($classId && $studentsIds)
  3852. {
  3853. if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1))
  3854. {
  3855. }else
  3856. {
  3857. $criteria = new CDbCriteria();
  3858. $criteria->addInCondition('student_id',explode(',',$studentsIds));
  3859. $student_paper_data = SStudentPaperRelation::model()->find($criteria);
  3860. if($student_paper_data)
  3861. {
  3862. echo json_encode(array('status'=>-2));exit;
  3863. }
  3864. $http = http('service/student-delete-perm','post', $this->authUsername, explode(',',$studentsIds));
  3865. $response = formatResponse($http);
  3866. if(isset($response['data']) && $response['data']){
  3867. foreach ($response['data'] as $datum){
  3868. if($datum['hasOrder']==1){
  3869. $rs=false;
  3870. $code = 2001;
  3871. $msg = '无法操作,该学生已存在订单数据';
  3872. echo json_encode(array('status'=>-1));exit;
  3873. }
  3874. }
  3875. }
  3876. }
  3877. if(Yii::app()->params['handle_log_on_off']){
  3878. writeFileLog(jsonEncode(array(
  3879. "exam_group_id" => 0,
  3880. "operate_project" => 'zsyas2',
  3881. "school_id" => $this->schoolId,
  3882. "title" => '批量删除学生',
  3883. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3884. "operate_method" => $this->action,
  3885. "operate_url" => $this->getRoute(),
  3886. "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
  3887. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  3888. "date"=>date('Y-m-d H:i:s')
  3889. )));
  3890. }
  3891. unset($criteria);
  3892. $criteria = new CDbCriteria();
  3893. $criteria->addInCondition('student_id',explode(',',$studentsIds));
  3894. $criteria->addCondition('class_id=:class_id');
  3895. $criteria->addCondition('status=:status');
  3896. $criteria->params[':class_id'] = $classId;
  3897. $criteria->params[':status'] = 0;
  3898. if(SStudentClassRelation::model()->updateAll(array('status'=>1),$criteria)){
  3899. echo json_encode(array('status'=>1));exit;
  3900. }else
  3901. {
  3902. echo json_encode(array('status'=>0));exit;
  3903. }
  3904. }
  3905. }
  3906. public function actionExport()
  3907. {
  3908. $data = array();
  3909. $currSemester = $this->schoolManager->getCurrSemester();
  3910. $criteria = new CDbCriteria;
  3911. $criteria->addCondition('end_time <= :start_time');
  3912. $criteria->params[':start_time'] = $currSemester['start_time'];
  3913. $criteria->limit = 1;
  3914. $criteria->order = "end_time desc";
  3915. $allSemester = Semester::model()->find($criteria);
  3916. $grade = Req::post("grade");
  3917. $class_id = Req::post("class_id");
  3918. $semester_id = Req::post("semester_id");
  3919. $data['grade'] = $grade;
  3920. $data['class_id'] = $class_id;
  3921. $data['semester_id'] = $semester_id;
  3922. if (Yii::app()->request->getIsPostRequest())
  3923. {
  3924. ini_set('memory_limit','200M');
  3925. $grade = Req::post("grade");
  3926. $class_id = Req::post("class_id");
  3927. $semester_id = Req::post("semester_id");
  3928. $class_type = Req::post("class_type");
  3929. $grade_class_array = array();
  3930. $class_array = array();
  3931. $class_name_array = array();
  3932. $class_grade_array = array();
  3933. $class_student_array = array();
  3934. $c_student_array = array();
  3935. $student_class_array = array();
  3936. $student_sex_array = array();
  3937. $student_userno_array = array();
  3938. $student_username_array = array();
  3939. $student_card_array = array();
  3940. $school_student_card_array = array();
  3941. $zhixue_student_card_array = array();
  3942. $id_number_array = array();
  3943. $excel_title = '全年学生信息';
  3944. $is_class = 0;
  3945. $student_serial_number_array = array();
  3946. $criteria = new CDbCriteria();
  3947. $criteria->addCondition('semester_id=:semester_id');
  3948. $criteria->params[':semester_id'] = $semester_id;
  3949. foreach (Yii::app()->params['grade_list'] as $id =>$param){
  3950. $grade_name[$id]=$param['grade_name'];
  3951. }
  3952. $where=array();
  3953. $params=array();
  3954. if($grade){
  3955. $where[]="grade=:grade";
  3956. $params[':grade']=$grade;
  3957. }
  3958. if($class_id){
  3959. $where[]="class_id=:class_id";
  3960. $params[':class_id']=$class_id;
  3961. $is_class=1;
  3962. }
  3963. if($class_type){
  3964. $where[]="class_type=:class_type";
  3965. $params[':class_type']=$class_type;
  3966. }
  3967. if($where){
  3968. $criteria->addCondition(implode(' and ',$where));
  3969. foreach ($params as $key =>$val){
  3970. $criteria->params[$key] = $val;
  3971. }
  3972. }
  3973. if(isset(Yii::app()->params['grade_list'][$grade]))
  3974. {
  3975. $excel_title = Yii::app()->params['grade_list'][$grade]['grade_name'].'全班学生信息';
  3976. }
  3977. $criteria->order = "grade asc,class_id asc";
  3978. $class_data = ClassModel::model()->findAll($criteria);
  3979. unset($criteria);
  3980. if($class_data)
  3981. {
  3982. foreach($class_data as $v)
  3983. {
  3984. $class_array[$v->class_id] = $v->class_id;
  3985. $class_name_array[$v->class_id] = $v->class_name;
  3986. $class_grade_array[$v->class_id] = $v->grade;
  3987. $grade_class_array[$v->grade][$v->class_id] = array('class_id'=>$v->class_id);
  3988. if($is_class)
  3989. {
  3990. $excel_title = $v->class_name.'学生信息';
  3991. }
  3992. }
  3993. unset($class_data);
  3994. $criteria = new CDbCriteria();
  3995. $criteria->addInCondition('class_id',$class_array);
  3996. $criteria->addCondition('status=:status');
  3997. $criteria->params[':status'] = 0;
  3998. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  3999. unset($criteria);
  4000. if($student_class_data)
  4001. {
  4002. foreach($student_class_data as $v)
  4003. {
  4004. $c_student_array[$v->student_id] = $v->student_id;
  4005. $student_class_array[$v->student_id] = (string)$v->class_id;
  4006. $student_userno_array[$v->student_id] = $v->userno;
  4007. $student_serial_number_array[$v->student_id] = $v->serial_number;
  4008. $class_student_array[$v->class_id][$v->student_id] = $v->student_id;
  4009. }
  4010. unset($student_class_data);
  4011. $criteria = new CDbCriteria();
  4012. $criteria->addInCondition('student_id',$c_student_array);
  4013. $criteria->order = "class_id asc";
  4014. $student_info_data = SStudentInfo::model()->findAll($criteria);
  4015. unset($criteria);
  4016. if($student_info_data)
  4017. {
  4018. foreach($student_info_data as $v)
  4019. {
  4020. $student_name_array[$v->student_id] = $v->realname;
  4021. $student_sex_array [$v->student_id] = $v->sex;
  4022. $id_number_array[$v->student_id] =$v->id_number;
  4023. }
  4024. }
  4025. unset($student_info_data);
  4026. $criteria = new CDbCriteria();
  4027. $criteria->addInCondition('student_id',$c_student_array);
  4028. $student_data = BusinessStudent::model()->findAll($criteria);
  4029. unset($criteria);
  4030. if($student_data)
  4031. {
  4032. foreach($student_data as $v)
  4033. {
  4034. $student_card_array[$v->student_id] = $v->student_card;
  4035. $school_student_card_array[$v->student_id] = $v->school_student_card;
  4036. $zhixue_student_card_array[$v->student_id] = $v->zhixue_student_card;
  4037. }
  4038. }
  4039. $columnArr=array();
  4040. if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){
  4041. $columnArr=array(
  4042. 'A'=>'学生ID',
  4043. 'B'=>'年级',
  4044. 'C'=>'班级',
  4045. 'D'=>'姓名',
  4046. 'E'=>'性别(1男 2女)',
  4047. 'F'=>'准考证号',
  4048. 'G'=>'学校准考证号',
  4049. 'H'=>'智学网准考证号',
  4050. 'I'=>'身份证号'
  4051. );
  4052. }else{
  4053. $columnArr=array(
  4054. 'A'=>'年级',
  4055. 'B'=>'班级',
  4056. 'C'=>'姓名',
  4057. 'D'=>'性别(1男 2女)',
  4058. 'E'=>'准考证号',
  4059. 'F'=>'学校准考证号',
  4060. 'G'=>'智学网准考证号',
  4061. 'H'=>'身份证号'
  4062. );
  4063. }
  4064. unset($student_data);
  4065. unset($c_student_array);
  4066. //
  4067. $objPHPExcel = new PHPExcel();
  4068. $objPHPExcel->getProperties()->setCreator("ctos")
  4069. ->setLastModifiedBy("ctos")
  4070. ->setTitle("学生信息")
  4071. ->setSubject("学生信息")
  4072. ->setDescription("导出学生信息")
  4073. ->setKeywords("excel")
  4074. ->setCategory("result file");
  4075. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
  4076. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
  4077. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
  4078. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
  4079. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  4080. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
  4081. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
  4082. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  4083. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  4084. foreach ($columnArr as $key =>$val){
  4085. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($key.'1', $val);
  4086. }
  4087. $i = 1;
  4088. foreach($grade_class_array as $ck=>$class_ids){
  4089. foreach($class_ids as $class_id) {
  4090. if (isset($class_student_array[$class_id['class_id']])) {
  4091. foreach ($class_student_array[$class_id['class_id']] as $v) {
  4092. $i = $i + 1;
  4093. $keys=array_reverse(array_keys($columnArr));
  4094. if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){
  4095. $objPHPExcel->getActiveSheet(0)->setCellValue(array_pop($keys) . $i, $v.' ',PHPExcel_Cell_DataType::TYPE_STRING);
  4096. }
  4097. $letter=array_pop($keys);
  4098. if (isset($student_class_array[$v]) && isset($class_grade_array[$student_class_array[$v]]) && isset($grade_name[$class_grade_array[$student_class_array[$v]]])) {
  4099. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $grade_name[$class_grade_array[$student_class_array[$v]]]);
  4100. } else {
  4101. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
  4102. }
  4103. $letter=array_pop($keys);
  4104. if (isset($class_name_array[$class_id['class_id']])) {
  4105. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $class_name_array[$class_id['class_id']]);
  4106. } else {
  4107. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
  4108. }
  4109. $letter=array_pop($keys);
  4110. if (isset($student_name_array[$v])) {
  4111. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_name_array[$v]);
  4112. } else {
  4113. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
  4114. }
  4115. $letter=array_pop($keys);
  4116. if (isset($student_sex_array[$v])) {
  4117. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_sex_array[$v]);
  4118. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4119. } else {
  4120. $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, 1);
  4121. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4122. }
  4123. $letter=array_pop($keys);
  4124. if (isset($student_card_array[$v])) {
  4125. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
  4126. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4127. } else {
  4128. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
  4129. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4130. }
  4131. $letter=array_pop($keys);
  4132. if (isset($school_student_card_array[$v])) {
  4133. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$school_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
  4134. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4135. } else {
  4136. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
  4137. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4138. }
  4139. $letter=array_pop($keys);
  4140. if (isset($zhixue_student_card_array[$v])) {
  4141. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$zhixue_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
  4142. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4143. } else {
  4144. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
  4145. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4146. }
  4147. $letter=array_pop($keys);
  4148. if (isset($id_number_array[$v])) {
  4149. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$id_number_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
  4150. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4151. } else {
  4152. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
  4153. $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
  4154. }
  4155. }
  4156. }
  4157. }
  4158. }
  4159. unset($student_card_array);
  4160. unset($school_student_card_array);
  4161. unset($zhixue_student_card_array);
  4162. unset($student_class_array);
  4163. unset($student_userno_array);
  4164. unset($student_serial_number_array);
  4165. unset($class_student_array);
  4166. $objPHPExcel->getActiveSheet()->setTitle($excel_title);
  4167. $objPHPExcel->setActiveSheetIndex(0);
  4168. ob_end_clean(); // Added by me
  4169. header("Accept-Ranges:bytes");
  4170. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  4171. header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"');
  4172. header('Cache-Control:max-age=0');
  4173. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  4174. $objWriter->save('php://output');
  4175. exit;
  4176. }else{
  4177. Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/export'));
  4178. }
  4179. }
  4180. }
  4181. $data['semester'] = $allSemester;
  4182. $data['currSemester'] = $currSemester;
  4183. $this->render('export',$data);
  4184. }
  4185. public function actionAjax_class()
  4186. {
  4187. $grade = Req::post("grade");
  4188. $semester_id = Req::post("semester_id");
  4189. $class_type = Req::post("class_type");
  4190. $class_array = array();
  4191. if($grade==0 || !$semester_id)
  4192. {
  4193. echo json_encode(array('status'=>0,'data'=>''));exit;
  4194. }
  4195. if($class_type){
  4196. $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and class_type=:class_type and is_hide=0',array(':semester_id'=>$semester_id,':grade'=>$grade,':class_type'=>$class_type));
  4197. }else{
  4198. $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and is_hide=0',array(':semester_id'=>$semester_id,':grade'=>$grade));
  4199. }
  4200. if($class_data)
  4201. {
  4202. foreach($class_data as $v)
  4203. {
  4204. $class_array[] = $v->attributes;
  4205. }
  4206. echo json_encode(array('status'=>1,'data'=>$class_array));exit;
  4207. }
  4208. echo json_encode(array('status'=>0,'data'=>''));exit;
  4209. }
  4210. //智学网
  4211. public function actionZhixue_student()
  4212. {
  4213. if (Yii::app()->request->getIsPostRequest())
  4214. {
  4215. $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
  4216. $uploader->allowTypes = array("xls");
  4217. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId.date('Ymdhis',time())));
  4218. $file = $uploader->act();
  4219. $file = Arr::current(Arr::current($file));
  4220. if(!$file || !isset($file["error"]))
  4221. Yii::app()->jump->error('请选择上传的Excel!');
  4222. if($file["error"] != 0){
  4223. switch($file["error"]){
  4224. case 2001:
  4225. Yii::app()->jump->error('文件类型不符');
  4226. break;
  4227. case 2002:
  4228. Yii::app()->jump->error('文件大小超出允许范围');
  4229. break;
  4230. default:
  4231. Yii::app()->jump->error('上传失败');
  4232. break;
  4233. }
  4234. }
  4235. $inputFileName = $file["src"];
  4236. $student_all_array = array();
  4237. $c_class_names = array();
  4238. $class_ids = array();
  4239. $student_name_info = array();
  4240. $student_ids = array();
  4241. $class_name = '';
  4242. $_err = array();
  4243. // 导入PHPExcel类
  4244. Yii::import('application.extensions.*');
  4245. require_once('phpexcel/PHPExcel/IOFactory.php');
  4246. // 读取Excel文档
  4247. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  4248. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  4249. //FIXME 2019-12-02
  4250. @unlink($file["src"]);
  4251. $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  4252. if($class_semester_data)
  4253. {
  4254. foreach($class_semester_data as $v)
  4255. {
  4256. $class_ids[$v->class_id] = $v->class_id;
  4257. $c_class_names[$v->class_name] = $v->class_id;
  4258. }
  4259. }
  4260. $criteria = new CDbCriteria();
  4261. $criteria->addInCondition('class_id',$class_ids);
  4262. $criteria->addCondition('status=:status');
  4263. $criteria->params[':status'] = 0;
  4264. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  4265. if($student_class_data)
  4266. {
  4267. foreach($student_class_data as $v)
  4268. {
  4269. $student_ids[$v->student_id] = $v->student_id;
  4270. }
  4271. }
  4272. unset($criteria);
  4273. $criteria = new CDbCriteria();
  4274. $criteria->addInCondition('student_id',$student_ids);
  4275. $student_info_data = SStudentInfo::model()->findAll($criteria);
  4276. if($student_info_data)
  4277. {
  4278. foreach($student_info_data as $v)
  4279. {
  4280. $student_name_info[$v->class_id][trim($v->realname)] = $v->student_id;
  4281. }
  4282. }
  4283. if($sheetData)
  4284. {
  4285. unset($sheetData[1]);
  4286. krsort($sheetData);
  4287. $sheetData = array_reverse($sheetData);
  4288. foreach ($sheetData as $key=>$val)
  4289. {
  4290. if ( empty($val['A']) || empty($val['B']) || empty($val['C']) ){
  4291. continue;
  4292. }
  4293. $class_name = trim($val['A']);
  4294. $user_name = trim($val['C']);
  4295. if(isset($c_class_names[$class_name]) && !empty($c_class_names[$class_name]))
  4296. {
  4297. $class_id = $c_class_names[$class_name];
  4298. if(isset($student_name_info[$class_id]) && !empty($student_name_info[$class_id]) )
  4299. {
  4300. if(isset($student_name_info[$class_id][$user_name]) && !empty($student_name_info[$class_id][$user_name]))
  4301. {
  4302. $b_student_data = BusinessStudent::model()->find('student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name]));
  4303. if($b_student_data)
  4304. {
  4305. $b_student_z_one_data = BusinessStudent::model()->find('zhixue_student_card=:zhixue_student_card',array(':zhixue_student_card'=>$val['B']));
  4306. if($b_student_z_one_data)
  4307. {
  4308. $_err[$key]['class_name'] = $val['A'];
  4309. $_err[$key]['zhixue_student_card'] = $val['B'];
  4310. $_err[$key]['username'] = $val['C'];
  4311. $_err[$key]['msg'] = '准考证已存在';
  4312. continue;
  4313. }
  4314. if($b_student_data->zhixue_student_card && $b_student_data->zhixue_student_card == $val['B'])
  4315. {
  4316. $_err[$key]['class_name'] = $val['A'];
  4317. $_err[$key]['zhixue_student_card'] = $val['B'];
  4318. $_err[$key]['username'] = $val['C'];
  4319. $_err[$key]['msg'] = '用户准考证已存在';
  4320. continue;
  4321. }else
  4322. {
  4323. //写入
  4324. $flags = BusinessStudent::model()->updateAll(array('zhixue_student_card'=>$val['B']),'student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name]));
  4325. if($flags)
  4326. {
  4327. continue;
  4328. }else
  4329. {
  4330. $_err[$key]['class_name'] = $val['A'];
  4331. $_err[$key]['zhixue_student_card'] = $val['B'];
  4332. $_err[$key]['username'] = $val['C'];
  4333. $_err[$key]['msg'] = '写入失败';
  4334. continue;
  4335. }
  4336. }
  4337. }else
  4338. {
  4339. $_err[$key]['class_name'] = $val['A'];
  4340. $_err[$key]['zhixue_student_card'] = $val['B'];
  4341. $_err[$key]['username'] = $val['C'];
  4342. $_err[$key]['msg'] = '用户不存在';
  4343. continue;
  4344. }
  4345. }else
  4346. {
  4347. $_err[$key]['class_name'] = $val['A'];
  4348. $_err[$key]['zhixue_student_card'] = $val['B'];
  4349. $_err[$key]['username'] = $val['C'];
  4350. $_err[$key]['msg'] = '用户不存在';
  4351. continue;
  4352. }
  4353. }else
  4354. {
  4355. $_err[$key]['class_name'] = $val['A'];
  4356. $_err[$key]['zhixue_student_card'] = $val['B'];
  4357. $_err[$key]['username'] = $val['C'];
  4358. $_err[$key]['msg'] = '此班级不存该用户';
  4359. continue;
  4360. }
  4361. }else
  4362. {
  4363. $_err[$key]['class_name'] = $val['A'];
  4364. $_err[$key]['zhixue_student_card'] = $val['B'];
  4365. $_err[$key]['username'] = $val['C'];
  4366. $_err[$key]['msg'] = '班级不存在';
  4367. continue;
  4368. }
  4369. }
  4370. if($_err)
  4371. {
  4372. $this->zhixue_xls($_err);
  4373. }else
  4374. {
  4375. Yii::app()->jump->error('导入成功');exit;
  4376. }
  4377. }
  4378. }
  4379. $this->render('zhixue_student');
  4380. }
  4381. protected function zhixue_xls($_err)
  4382. {
  4383. if(!$_err)
  4384. {
  4385. return false;
  4386. }
  4387. $objPHPExcel = new PHPExcel();
  4388. $objPHPExcel->getProperties()->setCreator("ctos")
  4389. ->setLastModifiedBy("ctos")
  4390. ->setTitle("智学网学生信息")
  4391. ->setSubject("智学网学生信息")
  4392. ->setDescription("导入智学网学生信息")
  4393. ->setKeywords("excel")
  4394. ->setCategory("result file");
  4395. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  4396. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  4397. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  4398. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  4399. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  4400. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  4401. $objPHPExcel->setActiveSheetIndex(0)
  4402. ->setCellValue('A1', '班级')
  4403. ->setCellValue('B1', '准考证号')
  4404. ->setCellValue('C1', '学生姓名')
  4405. ->setCellValue('D1', '错误原因');
  4406. $i = 1;
  4407. foreach($_err as $v)
  4408. {
  4409. $i = $i + 1;
  4410. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
  4411. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('B' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  4412. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getNumberFormat()->setFormatCode("@");
  4413. $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['username']);
  4414. $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['msg']);
  4415. }
  4416. $objPHPExcel->getActiveSheet()->setTitle('导入失败');
  4417. $objPHPExcel->setActiveSheetIndex(0);
  4418. ob_end_clean(); // Added by me
  4419. header("Accept-Ranges:bytes");
  4420. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  4421. header('Content-Disposition:attachment;filename="导入失败.xls"');
  4422. header('Cache-Control:max-age=0');
  4423. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  4424. $objWriter->save('php://output');
  4425. exit;
  4426. }
  4427. /**
  4428. * 获取所有老师,排除其他年级的年级主任
  4429. */
  4430. public function actionGetAllTeachers()
  4431. {
  4432. if(Yii::app()->params['grade_list']){
  4433. foreach (Yii::app()->params['grade_list'] as $id => $val){
  4434. $grade_arr[$id]=$val['grade_name'];
  4435. }
  4436. }
  4437. $postArr = array(
  4438. 0=>'任课教师',
  4439. 1=>'班主任',
  4440. 2=>'教研组长',
  4441. 3=>'年级主任',
  4442. 4=>'任课教师',
  4443. 5=>'校长',
  4444. );
  4445. $result = array();
  4446. $grade = Req::post('grade');
  4447. if( Yii::app()->params['section']==1){
  4448. $firstSubjectId=3;
  4449. }else{
  4450. $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject);
  4451. }
  4452. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId));
  4453. if($teacher_data)
  4454. {
  4455. foreach($teacher_data as $v)
  4456. {
  4457. $teacherGrade = $v->grade?$v->grade:0;
  4458. if($v->posts && $v->posts ==3){
  4459. //过滤非本年级的年级主任
  4460. if ($teacherGrade==$grade || !$teacherGrade){
  4461. $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')';
  4462. }
  4463. }else{
  4464. $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')';
  4465. }
  4466. }
  4467. echo json_encode(array('status'=>1,'result'=>$result));exit;
  4468. }
  4469. echo json_encode(array('status'=>0,'result'=>$result));exit;
  4470. }
  4471. /**
  4472. * 根据年级和学科组获取老师
  4473. */
  4474. public function actionGet_subject_teachers()
  4475. {
  4476. $subject_id = Req::post("subject_id");
  4477. $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
  4478. $postArr = array(
  4479. 0=>'任课教师',
  4480. 1=>'班主任',
  4481. 2=>'教研组长',
  4482. 3=>'年级主任',
  4483. 4=>'任课教师',
  4484. 5=>'校长',
  4485. );
  4486. $grade = Req::post('grade');
  4487. $result = array();
  4488. if($subject_id)
  4489. {
  4490. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$subject_id));
  4491. if($teacher_data)
  4492. {
  4493. foreach($teacher_data as $v)
  4494. {
  4495. $teacherGrade = $v->grade?$v->grade:0;
  4496. if($v->posts && $v->posts ==3){
  4497. //过滤非本年级的年级主任
  4498. if ($teacherGrade==$grade || !$teacherGrade){
  4499. $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')';
  4500. }
  4501. }else{
  4502. $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')';
  4503. }
  4504. }
  4505. echo json_encode(array('status'=>1,'result'=>$result));exit;
  4506. }
  4507. }
  4508. echo json_encode(array('status'=>0,'result'=>array()));exit;
  4509. }
  4510. public function actionResetpwd()
  4511. {
  4512. if (Yii::app()->request->getIsPostRequest())
  4513. {
  4514. $grade = Req::post("grade");
  4515. $class_id = Req::post("class_id");
  4516. $pwd = Req::post("pwd");
  4517. $class_ids = array();
  4518. $student_ids = array();
  4519. if($pwd)
  4520. {
  4521. $pwd = md5(sha1($pwd . 'wy') . 'fengche');
  4522. }else
  4523. {
  4524. Yii::app()->jump->error('密码能小于6位!');
  4525. }
  4526. if($grade==0 && $class_id==0 )
  4527. {
  4528. if(false !== BusinessStudent::model()->updateAll(array('password'=>$pwd),'school_id=:school_id',array(':school_id'=>$this->schoolId))){
  4529. Yii::app()->jump->success('保存成功<br>',Yii::app()->createUrl('studentinfo/index'));exit;
  4530. }else
  4531. {
  4532. Yii::app()->jump->error('重置失败,密码与新密码一样!');
  4533. }
  4534. }
  4535. $class_data = ClassModel::model()->findAll('grade=:grade',array(':grade'=>$grade));
  4536. foreach($class_data as $v)
  4537. {
  4538. $class_ids[$v->class_id] = $v->class_id;
  4539. }
  4540. if($class_ids)
  4541. {
  4542. $criteria = new CDbCriteria();
  4543. if($grade>0 && $class_id==0)
  4544. {
  4545. $criteria->addInCondition('class_id',$class_ids);
  4546. }else
  4547. {
  4548. $criteria->addCondition('class_id=:class_id');
  4549. $criteria->params[':class_id'] = $class_id;
  4550. }
  4551. $criteria->addCondition('status=:status');
  4552. $criteria->params[':status'] = 0;
  4553. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  4554. if($student_class_data)
  4555. {
  4556. foreach($student_class_data as $v){
  4557. $student_ids[$v->student_id] = $v->student_id;
  4558. }
  4559. if($student_ids)
  4560. {
  4561. unset($criteria);
  4562. $criteria = new CDbCriteria();
  4563. $criteria->addInCondition('student_id',$student_ids);
  4564. if(false!==BusinessStudent::model()->updateAll(array('password'=>$pwd),$criteria)){
  4565. Yii::app()->jump->success('保存成功<br>',Yii::app()->createUrl('studentinfo/index'));exit;
  4566. }else
  4567. {
  4568. Yii::app()->jump->error('重置失败,密码与新密码一样!');
  4569. }
  4570. }
  4571. }
  4572. }
  4573. Yii::app()->jump->error('重置失败!');
  4574. }
  4575. $data = array();
  4576. $data['semester_id'] = $this->semesterId;
  4577. $this->render('reset',$data);
  4578. }
  4579. public function create_xls($_err)
  4580. {
  4581. if(!$_err)
  4582. {
  4583. return false;
  4584. }
  4585. $objPHPExcel = new PHPExcel();
  4586. $objPHPExcel->getProperties()->setCreator("ctos")
  4587. ->setLastModifiedBy("ctos")
  4588. ->setTitle("导入学校准考证号")
  4589. ->setSubject("导入学校准考证号")
  4590. ->setDescription("导入学校准考证号")
  4591. ->setKeywords("excel")
  4592. ->setCategory("result file");
  4593. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
  4594. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
  4595. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5);
  4596. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
  4597. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
  4598. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
  4599. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  4600. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  4601. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  4602. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  4603. $objPHPExcel->setActiveSheetIndex(0)
  4604. ->setCellValue('A1', '班级(当前学期唯一)')
  4605. ->setCellValue('B1', '姓名(当前学期唯一)')
  4606. ->setCellValue('C1', '性别(1男 2女)')
  4607. ->setCellValue('D1', '学号(可填)')
  4608. ->setCellValue('E1', '准考证号')
  4609. ->setCellValue('F1', '学校准考证号(可填)')
  4610. ->setCellValue('G1', '错误原因')
  4611. ->setCellValue('H1', '处理建议');
  4612. $i = 1;
  4613. foreach($_err as $v)
  4614. {
  4615. $i = $i + 1;
  4616. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['A']);
  4617. $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['B']);
  4618. $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['C']);
  4619. $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['D']);
  4620. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['E'], PHPExcel_Cell_DataType::TYPE_STRING);
  4621. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@");
  4622. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['F'], PHPExcel_Cell_DataType::TYPE_STRING);
  4623. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@");
  4624. $objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, $v['G']);
  4625. $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['H']);
  4626. }
  4627. $objPHPExcel->getActiveSheet()->setTitle('导入学生失败');
  4628. $objPHPExcel->setActiveSheetIndex(0);
  4629. ob_end_clean(); // Added by me
  4630. header("Accept-Ranges:bytes");
  4631. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  4632. header('Content-Disposition:attachment;filename="导入学生失败.xls"');
  4633. header('Cache-Control:max-age=0');
  4634. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  4635. $objWriter->save('php://output');
  4636. }
  4637. public function create_import_xls($_err)
  4638. {
  4639. if(!$_err)
  4640. {
  4641. return false;
  4642. }
  4643. $objPHPExcel = new PHPExcel();
  4644. $objPHPExcel->getProperties()->setCreator("ctos")
  4645. ->setLastModifiedBy("ctos")
  4646. ->setTitle("导入学生")
  4647. ->setSubject("导入学生")
  4648. ->setDescription("导入学生")
  4649. ->setKeywords("excel")
  4650. ->setCategory("result file");
  4651. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
  4652. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
  4653. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5);
  4654. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
  4655. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
  4656. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
  4657. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  4658. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  4659. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  4660. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  4661. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  4662. $objPHPExcel->setActiveSheetIndex(0)
  4663. ->setCellValue('A1', '班级(必填)')
  4664. ->setCellValue('B1', '姓名(当前学期唯一)')
  4665. ->setCellValue('C1', '性别(1男 2女)')
  4666. ->setCellValue('D1', '学号(可填')
  4667. ->setCellValue('E1', '准考证号')
  4668. ->setCellValue('F1', '学校准考证号(可填)')
  4669. ->setCellValue('G1', '智学网帐号(可填)')
  4670. ->setCellValue('H1', '错误原因')
  4671. ->setCellValue('I1', '处理建议');
  4672. $i = 1;
  4673. foreach($_err as $v)
  4674. {
  4675. $i = $i + 1;
  4676. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
  4677. $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['student_name']);
  4678. $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['student_six']);
  4679. $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['student_no']);
  4680. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  4681. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@");
  4682. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['school_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  4683. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@");
  4684. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('G' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  4685. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getNumberFormat()->setFormatCode("@");
  4686. $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['err_msg']);
  4687. $objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, $v['so_msg']);
  4688. }
  4689. $objPHPExcel->getActiveSheet()->setTitle('导入学生失败');
  4690. $objPHPExcel->setActiveSheetIndex(0);
  4691. ob_end_clean(); // Added by me
  4692. header("Accept-Ranges:bytes");
  4693. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  4694. header('Content-Disposition:attachment;filename="导入学生失败.xls"');
  4695. header('Cache-Control:max-age=0');
  4696. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  4697. $objWriter->save('php://output');
  4698. exit;
  4699. }
  4700. public function actionYearReport(){
  4701. @ini_set('memory_limit', '1024M');
  4702. set_time_limit(0);
  4703. ignore_user_abort(true);
  4704. $data = array();
  4705. $error = '';
  4706. $year = 2018;
  4707. $year_next = $year+1;
  4708. if ($year%4==0&&($year%100!=0 || $year%400==0)){
  4709. $days = 366;
  4710. }else{
  4711. $days = 365;
  4712. }
  4713. $weeks = date("W", mktime(0, 0, 0, 12, 28, $year));
  4714. $start_time = mktime(0,0,0,1,1,$year);
  4715. $end_time = mktime(0,0,0,1,1,$year_next);
  4716. $classIds = Req::post('classId');
  4717. // var_dump(dirname(dirname(dirname(__FILE__))));exit;
  4718. if($classIds){
  4719. foreach($classIds as $cclassId){
  4720. //正在生成中
  4721. $sql = "update class set report_status = 1 where class_id = {$cclassId}";
  4722. $res = $this->sConn->createCommand($sql)->execute();
  4723. }
  4724. foreach($classIds as $classId){
  4725. $studentIds = array();
  4726. $pdfArr = array();
  4727. $pdfNames = array();
  4728. //获取班级名称
  4729. $sql = "select class_name from class where class_id = {$classId}";
  4730. $res = $this->sConn->createCommand($sql)->queryRow();
  4731. if($res){
  4732. $class_name = $res['class_name'];
  4733. }
  4734. $sql = "select student_id from student_class_relation where class_id = {$classId} and status = 0";
  4735. $query = $this->sConn->createCommand($sql)->queryAll();//获取班级学生
  4736. if($query){
  4737. foreach($query as $k=>$v){
  4738. $studentIds[] = (string)$v['student_id'];
  4739. }
  4740. unset($query);
  4741. }
  4742. if($studentIds){
  4743. foreach($studentIds as $studentId){
  4744. //初始化数据
  4745. $methodIds = array();
  4746. $bestExam = array();
  4747. $totalExamIds = array();
  4748. $totalExamIds_subjectId = array();
  4749. $exam_count = array(
  4750. 9=>array(//语文
  4751. 'total_count' => 0,
  4752. 'real_count' => 0,
  4753. 'del_count' => 0
  4754. ),
  4755. 3=>array(//数学
  4756. 'total_count' => 0,
  4757. 'real_count' => 0,
  4758. 'del_count' => 0
  4759. ),
  4760. 8=>array(//英语
  4761. 'total_count' => 0,
  4762. 'real_count' => 0,
  4763. 'del_count' => 0
  4764. ),
  4765. 15=>array(//政治
  4766. 'total_count' => 0,
  4767. 'real_count' => 0,
  4768. 'del_count' => 0
  4769. ),
  4770. 16=>array(//历史
  4771. 'total_count' => 0,
  4772. 'real_count' => 0,
  4773. 'del_count' => 0
  4774. ),
  4775. 17=>array(//地理
  4776. 'total_count' => 0,
  4777. 'real_count' => 0,
  4778. 'del_count' => 0
  4779. ),
  4780. 12=>array(//物理
  4781. 'total_count' => 0,
  4782. 'real_count' => 0,
  4783. 'del_count' => 0
  4784. ),
  4785. 13=>array(//化学
  4786. 'total_count' => 0,
  4787. 'real_count' => 0,
  4788. 'del_count' => 0
  4789. ),
  4790. 14=>array(//生物
  4791. 'total_count' => 0,
  4792. 'real_count' => 0,
  4793. 'del_count' => 0
  4794. ),
  4795. 19=>array(//文综
  4796. 'total_count' => 0,
  4797. 'real_count' => 0,
  4798. 'del_count' => 0
  4799. ),
  4800. 18=>array(//理综
  4801. 'total_count' => 0,
  4802. 'real_count' => 0,
  4803. 'del_count' => 0
  4804. ),
  4805. );//考试状况
  4806. $method_mes = array(
  4807. 'count' => 0,
  4808. 'name' => array(),
  4809. );//数学考点状况
  4810. $isp_mes = array(
  4811. 'isp_days' => 0,
  4812. 'isp_create' => 0,
  4813. 'isp_down' => 0,
  4814. 'isp_down_ratio' => 0
  4815. );//数学个性化学习宝状况
  4816. $best_exam_mes = array(
  4817. 9=>array(//语文
  4818. 'name' => '',
  4819. 'score' => 0,
  4820. 'scoring' => 0,
  4821. 'grade_no' => 0,
  4822. 'grade_total_no'=>0,
  4823. 'class_no'=>0,
  4824. 'class_total_no'=>0,
  4825. ),
  4826. 3=>array(//数学
  4827. 'name' => '',
  4828. 'score' => 0,
  4829. 'scoring' => 0,
  4830. 'grade_no' => 0,
  4831. 'grade_total_no'=>0,
  4832. 'class_no'=>0,
  4833. 'class_total_no'=>0,
  4834. ),
  4835. 8=>array(//英语
  4836. 'name' => '',
  4837. 'score' => 0,
  4838. 'scoring' => 0,
  4839. 'grade_no' => 0,
  4840. 'grade_total_no'=>0,
  4841. 'class_no'=>0,
  4842. 'class_total_no'=>0,
  4843. ),
  4844. 15=>array(//政治
  4845. 'name' => '',
  4846. 'score' => 0,
  4847. 'scoring' => 0,
  4848. 'grade_no' => 0,
  4849. 'grade_total_no'=>0,
  4850. 'class_no'=>0,
  4851. 'class_total_no'=>0,
  4852. ),
  4853. 16=>array(//历史
  4854. 'name' => '',
  4855. 'score' => 0,
  4856. 'scoring' => 0,
  4857. 'grade_no' => 0,
  4858. 'grade_total_no'=>0,
  4859. 'class_no'=>0,
  4860. 'class_total_no'=>0,
  4861. ),
  4862. 17=>array(//地理
  4863. 'name' => '',
  4864. 'score' => 0,
  4865. 'scoring' => 0,
  4866. 'grade_no' => 0,
  4867. 'grade_total_no'=>0,
  4868. 'class_no'=>0,
  4869. 'class_total_no'=>0,
  4870. ),
  4871. 12=>array(//物理
  4872. 'name' => '',
  4873. 'score' => 0,
  4874. 'scoring' => 0,
  4875. 'grade_no' => 0,
  4876. 'grade_total_no'=>0,
  4877. 'class_no'=>0,
  4878. 'class_total_no'=>0,
  4879. ),
  4880. 13=>array(//化学
  4881. 'name' => '',
  4882. 'score' => 0,
  4883. 'scoring' => 0,
  4884. 'grade_no' => 0,
  4885. 'grade_total_no'=>0,
  4886. 'class_no'=>0,
  4887. 'class_total_no'=>0,
  4888. ),
  4889. 14=>array(//生物
  4890. 'name' => '',
  4891. 'score' => 0,
  4892. 'scoring' => 0,
  4893. 'grade_no' => 0,
  4894. 'grade_total_no'=>0,
  4895. 'class_no'=>0,
  4896. 'class_total_no'=>0,
  4897. ),
  4898. 19=>array(//文综
  4899. 'name' => '',
  4900. 'score' => 0,
  4901. 'scoring' => 0,
  4902. 'grade_no' => 0,
  4903. 'grade_total_no'=>0,
  4904. 'class_no'=>0,
  4905. 'class_total_no'=>0,
  4906. ),
  4907. 18=>array(//理综
  4908. 'name' => '',
  4909. 'score' => 0,
  4910. 'scoring' => 0,
  4911. 'grade_no' => 0,
  4912. 'grade_total_no'=>0,
  4913. 'class_no'=>0,
  4914. 'class_total_no'=>0,
  4915. ),
  4916. );//最佳考试
  4917. $score_mes = array(
  4918. 9=>array(//语文
  4919. 'rise_count' => 0,
  4920. 'drop_count' => 0,
  4921. 'class_top_ten' => 0,
  4922. 'unified_top_ten' => 0,
  4923. ),
  4924. 3=>array(//数学
  4925. 'rise_count' => 0,
  4926. 'drop_count' => 0,
  4927. 'class_top_ten' => 0,
  4928. 'unified_top_ten' => 0,
  4929. ),
  4930. 8=>array(//英语
  4931. 'rise_count' => 0,
  4932. 'drop_count' => 0,
  4933. 'class_top_ten' => 0,
  4934. 'unified_top_ten' => 0,
  4935. ),
  4936. 15=>array(//政治
  4937. 'rise_count' => 0,
  4938. 'drop_count' => 0,
  4939. 'class_top_ten' => 0,
  4940. 'unified_top_ten' => 0,
  4941. ),
  4942. 16=>array(//历史
  4943. 'rise_count' => 0,
  4944. 'drop_count' => 0,
  4945. 'class_top_ten' => 0,
  4946. 'unified_top_ten' => 0,
  4947. ),
  4948. 17=>array(//地理
  4949. 'rise_count' => 0,
  4950. 'drop_count' => 0,
  4951. 'class_top_ten' => 0,
  4952. 'unified_top_ten' => 0,
  4953. ),
  4954. 12=>array(//物理
  4955. 'rise_count' => 0,
  4956. 'drop_count' => 0,
  4957. 'class_top_ten' => 0,
  4958. 'unified_top_ten' => 0,
  4959. ),
  4960. 13=>array(//化学
  4961. 'rise_count' => 0,
  4962. 'drop_count' => 0,
  4963. 'class_top_ten' => 0,
  4964. 'unified_top_ten' => 0,
  4965. ),
  4966. 14=>array(//生物
  4967. 'rise_count' => 0,
  4968. 'drop_count' => 0,
  4969. 'class_top_ten' => 0,
  4970. 'unified_top_ten' => 0,
  4971. ),
  4972. 19=>array(//文综
  4973. 'rise_count' => 0,
  4974. 'drop_count' => 0,
  4975. 'class_top_ten' => 0,
  4976. 'unified_top_ten' => 0,
  4977. ),
  4978. 18=>array(//理综
  4979. 'rise_count' => 0,
  4980. 'drop_count' => 0,
  4981. 'class_top_ten' => 0,
  4982. 'unified_top_ten' => 0,
  4983. ),
  4984. );//成绩状况
  4985. $contin_weeks = 1;//连续周数
  4986. $studentId = (string)$studentId;
  4987. $a[] = $studentId;
  4988. //个性化学习宝使用天数
  4989. $res = $this->getHttp('order/coach/days/'.$studentId.'/'.$year, 'get');
  4990. if($res && $res['data']){
  4991. $isp_mes['isp_days'] = $res['data'];
  4992. }
  4993. //获取学生姓名
  4994. $sql = "select realname from student_info where student_id = {$studentId}";
  4995. $res = $this->sConn->createCommand($sql)->queryRow();
  4996. if($res){
  4997. $stu_name = $res['realname'];
  4998. }
  4999. //考试状况
  5000. $sql = "select e.create_time,e.name,e.exam_id,e.exam_group_id,e.subject_id,spr.is_del,spr.scoring,spr.is_isp_pdf,spr.is_wbisp_pdf,spr.is_two_isp_download,spr.is_three_isp_download,p.method_ids,p.score from exam e "
  5001. . "left join exam_group eg on e.exam_group_id = eg.exam_group_id "
  5002. . "left join paper p on p.exam_id = e.exam_id "
  5003. . "left join student_paper_relation spr on e.exam_id = spr.exam_id "
  5004. . "where spr.student_id = {$studentId} and e.status = 1 and e.upload_status = 2 and eg.status = 2 and eg.mark_status = 2 and e.create_time > {$start_time} and e.create_time < {$end_time} "
  5005. . "order by e.create_time asc";
  5006. $query = $this->sConn->createCommand($sql)->queryAll();
  5007. if($query){
  5008. foreach($query as $k=>$v){
  5009. //考试状况
  5010. if(in_array($v['subject_id'],$this->mathSubjectId)){
  5011. $totalExamIds_subjectId[$v['exam_id']] = 3;
  5012. $exam_count[3]['total_count'] ++;
  5013. if($v['is_del'] == 1){
  5014. $exam_count[3]['del_count'] ++;
  5015. }else{
  5016. $exam_count[3]['real_count'] ++;
  5017. }
  5018. //考点状况
  5019. $methodArr = explode(",",$v['method_ids']);
  5020. if($methodArr){
  5021. foreach($methodArr as $method){
  5022. if(is_numeric($method)){
  5023. $methodIds[] = $method;
  5024. }
  5025. }
  5026. }
  5027. //个性化学习宝状况
  5028. if($v['is_isp_pdf'] == 1){
  5029. $isp_mes['isp_create'] ++;
  5030. if($v['is_two_isp_download'] == 1){
  5031. $isp_mes['isp_down'] ++;
  5032. }
  5033. }
  5034. if($v['is_wbisp_pdf'] == 1){
  5035. $isp_mes['isp_create'] ++;
  5036. if($v['is_three_isp_download'] == 1){
  5037. $isp_mes['isp_down'] ++;
  5038. }
  5039. }
  5040. //最佳考试
  5041. $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
  5042. $bestExam[$v['exam_group_id']]['name'] = $v['name'];
  5043. $bestExam[$v['exam_group_id']]['subject_id'] = 3;
  5044. $bestExam[$v['exam_group_id']]['score'] = $v['score'];
  5045. $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
  5046. }else{
  5047. $totalExamIds_subjectId[$v['exam_id']] = $v['subject_id'];
  5048. $exam_count[$v['subject_id']]['total_count'] ++;
  5049. if($v['is_del'] == 1){
  5050. $exam_count[$v['subject_id']]['del_count'] ++;
  5051. }else{
  5052. $exam_count[$v['subject_id']]['real_count'] ++;
  5053. }
  5054. //最佳考试
  5055. $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
  5056. $bestExam[$v['exam_group_id']]['name'] = $v['name'];
  5057. $bestExam[$v['exam_group_id']]['subject_id'] = $v['subject_id'];
  5058. $bestExam[$v['exam_group_id']]['score'] = $v['score'];
  5059. $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
  5060. }
  5061. //连续周数
  5062. $totalExamIds[] = $v['exam_id'];
  5063. if(!isset($current_week)){
  5064. $current_week = date("W",$v['create_time']);
  5065. }else{
  5066. $week_cur = date("W",$v['create_time']);
  5067. if($week_cur = $current_week + 1){
  5068. $contin_weeks ++;
  5069. }
  5070. }
  5071. }
  5072. $totalExamIds = array_unique($totalExamIds);
  5073. //考点状况
  5074. if($methodIds){
  5075. $count_methods = array();
  5076. foreach($methodIds as $kmed=>$vmed){
  5077. if(!isset($count_methods[$vmed])){
  5078. $count_methods[$vmed] = 1;
  5079. }else{
  5080. $count_methods[$vmed]++;
  5081. }
  5082. }
  5083. $method_mes['count'] = count(array_unique($methodIds));
  5084. unset($methodIds);
  5085. if($count_methods){
  5086. arsort($count_methods);
  5087. $i = 1;
  5088. $methodArrIds = array();
  5089. foreach($count_methods as $k=>$v){
  5090. if($i < 6){
  5091. $methodArrIds[] = $k;
  5092. }
  5093. $i++;
  5094. }
  5095. $methods = $this->apiPost('/special/methods', array('methodIds' => $methodArrIds));
  5096. if($methods && !isset($methods->error)){
  5097. foreach($methods as $k=>$v){
  5098. $method_mes['name'][] = $v->method_name;
  5099. }
  5100. }
  5101. }
  5102. }
  5103. //数学个性化学习宝状况
  5104. if($isp_mes['isp_down'] && $isp_mes['isp_create']){
  5105. $isp_mes['isp_down_ratio'] = round($isp_mes['isp_down']/$isp_mes['isp_create'],4) * 100 .'%';
  5106. }
  5107. //最佳考试信息
  5108. if($bestExam){
  5109. $best_exam_msg = array();
  5110. foreach($bestExam as $k=>$v){
  5111. //获取groupId对应的examId
  5112. $examIds = array();
  5113. $sql = "select exam_id from exam where exam_group_id = {$k}";
  5114. $meg = $this->sConn->createCommand($sql)->queryAll();
  5115. if($meg){
  5116. foreach($meg as $edata){
  5117. $examIds[] = $edata['exam_id'];
  5118. }
  5119. }
  5120. if($examIds){
  5121. foreach($examIds as $examIdSc){
  5122. $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$examIdSc} order by scoring desc";
  5123. $msg = $this->sConn->createCommand($sql)->queryAll();
  5124. if($msg){
  5125. $no = 1;
  5126. $no_grade = 1;//年级排名
  5127. $no_class = 1;//班级排名
  5128. $stu_no_grade = 1;//学生年级排名
  5129. $stu_no_class = 1;//学生班级排名
  5130. $total_grade = 0;
  5131. $total_real_grade = 0;
  5132. $total_class = 0;
  5133. $total_real_class = 0;
  5134. foreach($msg as $kk=>$vv){
  5135. if($no == 1){
  5136. $current_scoring = $vv['scoring'];
  5137. }else{
  5138. if($vv['scoring'] < $current_scoring){
  5139. $no_grade ++;
  5140. }
  5141. }
  5142. if($vv['is_del'] == 0){
  5143. $total_real_grade ++;
  5144. }
  5145. if((string)$vv['class_id'] === (string)$classId){
  5146. if(!isset($current_class_scoring)){
  5147. $current_class_scoring = $vv['scoring'];
  5148. }else{
  5149. if($vv['scoring'] < $current_class_scoring){
  5150. $no_class ++;
  5151. }
  5152. }
  5153. if($vv['is_del'] == 0){
  5154. $total_real_class ++;
  5155. }
  5156. $total_class ++;
  5157. }
  5158. if((string)$vv['student_id'] === (string)$studentId){
  5159. $stu_no_grade = $no_grade;
  5160. $stu_no_class = $no_class;
  5161. }
  5162. $total_grade ++;
  5163. $no++;
  5164. }
  5165. //最佳考试定义:数值“年级排名/年级有效人数”最小的一次考试
  5166. if(!isset($best_exam_msg[$v['subject_id']])){
  5167. $best_exam_msg[$v['subject_id']] = round($stu_no_grade/$total_real_grade,4);
  5168. $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
  5169. $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
  5170. $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
  5171. $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
  5172. $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
  5173. $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
  5174. $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
  5175. }else{
  5176. $tep = round($stu_no_grade/$total_real_grade,4);
  5177. if($tep < $best_exam_msg[$v['subject_id']]){
  5178. $best_exam_msg[$v['subject_id']] = $tep;
  5179. $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
  5180. $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
  5181. $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
  5182. $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
  5183. $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
  5184. $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
  5185. $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
  5186. }
  5187. }
  5188. //成绩状况(统计班级上升下降次数,班级前十)
  5189. if($stu_no_class <= $total_real_class * 0.1){
  5190. $score_mes[$v['subject_id']]['class_top_ten']++;
  5191. }
  5192. if(!isset($current_class_no)){
  5193. $current_class_no = $stu_no_class;
  5194. }else{
  5195. if($stu_no_class > $current_class_no){
  5196. $score_mes[$v['subject_id']]['rise_count']++;
  5197. }else if($stu_no_class < $current_class_no){
  5198. $score_mes[$v['subject_id']]['drop_count']++;
  5199. }
  5200. }
  5201. }
  5202. unset($msg);
  5203. }
  5204. }
  5205. }
  5206. }
  5207. //统考排名
  5208. $sql = "select examinfo from cylet where cylet_type = 2 and create_time > {$start_time} and create_time < {$end_time}";
  5209. $json_data = $this->sConn->createCommand($sql)->queryAll();
  5210. $cylet_exam_ids = array();
  5211. if($json_data){
  5212. foreach($json_data as $cylet){
  5213. $cyletArr = json_decode($cylet['examinfo'],true);
  5214. if(isset($cyletArr['exam'])){
  5215. foreach($cyletArr['exam'] as $examCy){
  5216. if(in_array($examCy,$totalExamIds)){
  5217. $cylet_exam_ids[] = $examCy;
  5218. }
  5219. }
  5220. }
  5221. }
  5222. unset($json_data);
  5223. }
  5224. if($cylet_exam_ids){
  5225. foreach($cylet_exam_ids as $cexamId){
  5226. $this->sConn = $this->getDbConnection();
  5227. $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$cexamId} order by scoring desc";
  5228. $msg2 = $this->sConn->createCommand($sql)->queryAll();
  5229. if($msg2){
  5230. $no_cylet_grade = 1;//年级排名
  5231. $stu_no_cylet_grade = 1;//学生年级排名
  5232. $total_cylet_grade = 0;
  5233. $total_cylet_real_grade = 0;
  5234. foreach($msg2 as $cyScore){
  5235. if($cyScore['is_del'] == 0){
  5236. $total_cylet_real_grade ++;
  5237. }
  5238. $total_cylet_grade ++;
  5239. if(!isset($current_cylet_scoring)){
  5240. $current_cylet_scoring = $cyScore['scoring'];
  5241. }else{
  5242. if($cyScore['scoring'] < $current_cylet_scoring){
  5243. $no_cylet_grade ++;
  5244. }
  5245. }
  5246. if((string)$vv['student_id'] === (string)$studentId){
  5247. $stu_no_cylet_grade = $no_cylet_grade;
  5248. }
  5249. }
  5250. if($stu_no_cylet_grade <= $total_cylet_real_grade * 0.1){
  5251. $score_mes[$totalExamIds_subjectId[$cexamId]]['unified_top_ten']++;
  5252. }
  5253. }
  5254. }
  5255. }
  5256. }
  5257. unset($query);
  5258. $data['stu_name'] = isset($stu_name)?$stu_name:'';//学生姓名
  5259. $data['class_name'] = isset($class_name)?$class_name:'';//班级名称
  5260. $data['year'] = $year;
  5261. $data['year_next'] = $year_next;
  5262. $data['days'] = $days;
  5263. $data['weeks'] = $weeks;
  5264. $data['contin_weeks'] = $contin_weeks;
  5265. $data['exam_count'] = $exam_count;//考试状况
  5266. $data['score_mes'] = $score_mes;//成绩状况
  5267. $data['best_exam_mes'] = $best_exam_mes;//最佳考试
  5268. $data['method_mes'] = $method_mes;//考点状况
  5269. $data['isp_mes'] = $isp_mes;//个性化学习宝状况
  5270. //print_r($data);exit;
  5271. $html = $this->renderPartial("year_report", $data, true);
  5272. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径
  5273. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/yearReport/' . $this->schoolId . "/"; //存放生成的PDF路径
  5274. $pdfurl = '/assets/pdf/yearReport/' . $this->schoolId . "/";
  5275. if (!is_dir($htmlpath)) {
  5276. if (!mkdir($htmlpath, 0777, true)) {
  5277. exit('Create directory fail: ' . $htmlpath);
  5278. }
  5279. }if (!is_dir($pdfpath)) {
  5280. if (!mkdir($pdfpath, 0777, true)) {
  5281. exit('Create directory fail1: ' . $pdfpath);
  5282. }
  5283. }
  5284. $htmlpath.=$studentId . ".html";
  5285. $f = fopen($htmlpath, "w");
  5286. fwrite($f, $html);
  5287. $htmlurl = '/assets/' . $studentId . ".html"; //访问HTML的路径
  5288. if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
  5289. $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
  5290. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  5291. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  5292. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  5293. $pdffname=$classId."-".$studentId.".pdf";
  5294. $pdfpath = $pdfpath . $pdffname;
  5295. $pdfurl = $pdfurl . $pdffname;
  5296. $commond = Yii::app()->params['phantomjs'] . " "
  5297. . Yii::app()->params['html2pdf'] . " "
  5298. . " file://" . $htmlpath
  5299. . " {$pdfpath}"
  5300. . " 176mm*250mm ''";
  5301. } else {
  5302. // echo Yii::app()->params['phantomjs'];exit;
  5303. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  5304. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  5305. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  5306. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  5307. $pdffname=$classId.'-'.$studentId.".pdf";
  5308. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  5309. $pdfpath = $pdfpath . $pdffname;
  5310. $pdfurl = $pdfurl . $pdffname;
  5311. $top_meg = $class_name.'-'.$stu_name."-年度使用报告";
  5312. // $top_meg=iconv("UTF-8", "GBK",$top_meg);
  5313. // echo $top_meg;exit;
  5314. $commond = Yii::app()->params['phantomjs_server'] . " "
  5315. . Yii::app()->basePath . '/../js/html2pdf.js' . " "
  5316. . " {$htmlurl}"
  5317. . " {$pdfpath}"
  5318. . " 176mm*250mm {$top_meg}";
  5319. }
  5320. // echo $commond;exit;
  5321. $set_charset = 'export LANG=en_US.UTF-8;';
  5322. exec($set_charset.$commond, $res, $code);
  5323. if(isset($res[0])){
  5324. if (strpos($res[0], 'succeed') !== false) {
  5325. if ($this->file_exists($pdfpath)) {
  5326. $pdfArr[] = $pdfpath;
  5327. $pdfNames[] = $stu_name;
  5328. }
  5329. } else {
  5330. }
  5331. @unlink($htmlpath);
  5332. }
  5333. }
  5334. if($pdfArr){
  5335. $report_name = $class_name.$year."年度报告.zip";
  5336. $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/year_report/'.$this->schoolId."/"; //存放生成的PDF路径
  5337. if (!is_dir($filepath)) {
  5338. if (!mkdir($filepath, 0777, true)) {
  5339. exit('Create directory fail1: ' . $filepath);
  5340. }
  5341. }
  5342. $filename = dirname(dirname(dirname(__FILE__))).'/upload/year_report/'.$this->schoolId."/".$classId.'_'.$year.".zip"; //最终生成的文件名(含路径)
  5343. //$filename=iconv("UTF-8", "GBK",$filename);
  5344. // var_dump($filename);exit;
  5345. $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  5346. if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
  5347. Yii::app()->jump->error('无法打开文件,或者文件创建失败');
  5348. }
  5349. foreach ($pdfArr as $k=>$val) {
  5350. $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
  5351. $res=$zip->addFile($val,$classId.$pdfNames[$k].'.pdf');
  5352. @unlink($val);
  5353. }
  5354. $zip->close();//关闭
  5355. //生成完成
  5356. // var_dump($filename);exit;
  5357. $filename = addslashes($filename);
  5358. $sql = "update class set report_status = 2,report_url='{$filename}' where class_id = {$classId}";
  5359. $res = $this->sConn->createCommand($sql)->execute();
  5360. }else{
  5361. $error = '生成pdf失败';
  5362. }
  5363. }else{
  5364. $error = '暂无学生';
  5365. }
  5366. }
  5367. }else{
  5368. $error = '班级错误';
  5369. }
  5370. // header('Content-Type: application/json');
  5371. if (!$error) {
  5372. echo json_encode(array("status" => 0, "error" => ""));
  5373. exit;
  5374. } else {
  5375. echo json_encode(array("status" => 1, "error" => $error));
  5376. exit;
  5377. }
  5378. }
  5379. public function actiondown_load_yearreport() {
  5380. $classId = safe_replace(Yii::app()->request->getQuery('classId'));
  5381. $sql = "select report_url,class_name from class where class_id = {$classId}";
  5382. $data = $this->sConn->createCommand($sql)->queryRow();
  5383. $filepath = $data['report_url'];
  5384. if($filepath){
  5385. if ($this->check_zip($filepath)) {
  5386. Header("Content-type:application/zip");
  5387. Header("Accept-Ranges: bytes");
  5388. Header("Accept-Length: " . filesize($filepath));
  5389. Header("Content-Disposition: attachment; filename=".$data['class_name']."年度总结报告.zip"); // 输出文件内容
  5390. flush();// 刷新内容
  5391. $file=fopen($filepath,"r");
  5392. $download_rate=600;
  5393. while (!feof($file)){
  5394. print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者
  5395. flush();// flush 内容输出到浏览器端
  5396. sleep(1);// 终端1秒后继续
  5397. }
  5398. } else {
  5399. Yii::app()->jump->error('尚未生成');
  5400. }
  5401. }else{
  5402. Yii::app()->jump->error('尚未生成');
  5403. }
  5404. }
  5405. private function check_zip($file_path) {
  5406. if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") {
  5407. if (file_exists($file_path)) {
  5408. return true;
  5409. }
  5410. }
  5411. return false;
  5412. }
  5413. /**
  5414. * 获取接口数据
  5415. * @param $url
  5416. * @param $method
  5417. * @param array $params
  5418. * @return array
  5419. */
  5420. private function getHttp($url,$method,$params = array()){
  5421. $res = http($url, $method, $this->authUsername, $params);
  5422. $res = $this->handleRes($res);
  5423. return $res;
  5424. }
  5425. /**
  5426. * 处理接口返回的数据
  5427. * @param $res
  5428. * @return array
  5429. */
  5430. public function handleRes($res){
  5431. $result = array(
  5432. 'status' => 0,
  5433. 'data' => array(),
  5434. 'msg' => '暂无数据',
  5435. );
  5436. if($res){
  5437. $res = json_decode($res,true);
  5438. if(isset($res['errCode']) && $res['errCode'] == '00'){
  5439. $result['status'] = 1;
  5440. $result['data'] = isset($res['data'])?$res['data']:array();
  5441. $result['msg'] = $res['errMsg'];
  5442. }else{
  5443. if(isset($res['errMsg'])){
  5444. $result['msg'] = $res['errMsg'];
  5445. }
  5446. }
  5447. }
  5448. unset($res);
  5449. return $result;
  5450. }
  5451. public function actionAjaxGetClassesByGrade(){
  5452. $grade = Req::get("grade");
  5453. $page = Req::get("page");
  5454. $result = array();
  5455. $error = array();
  5456. $con = array();
  5457. if(!$grade){
  5458. $grade = 1;
  5459. }
  5460. if(!$page){
  5461. $page = 1;
  5462. }
  5463. $semesterId = $this->semesterId;
  5464. $con[] = "c.grade = {$grade}";
  5465. $con[] = "c.semester_id = {$semesterId}";
  5466. $rs = $this->schoolManager->getClassesDetailListre($con,6);
  5467. if($rs){
  5468. if($rs['rs']){
  5469. foreach($rs['rs'] as $k=>$v){
  5470. $classId = $v['class_id'];
  5471. $sql = "select count(*) count from student_class_relation where class_id = {$classId} and status = 0";
  5472. $count = $this->sConn->createCommand($sql)->queryRow();
  5473. $rs['rs'][$k]['stu_count'] = $count['count'];
  5474. }
  5475. $result['rs'] = $rs['rs'];
  5476. $result['page'] = $rs['pager'];
  5477. $pages_index = $this->widget('CLinkPager', array(
  5478. 'header' => '',
  5479. 'firstPageLabel'=> '首页',
  5480. 'lastPageLabel' => '末页',
  5481. 'prevPageLabel' => '上一页',
  5482. 'nextPageLabel' => '下一页',
  5483. 'pages' => $result['page'],
  5484. 'maxButtonCount'=> 5,
  5485. ),true);
  5486. $pages_index = preg_replace('/<a .*?href="(.*?)".*?>/is',"<a href='javascript:void(0)'>",$pages_index);
  5487. $result['pages_index'] = $pages_index;
  5488. echo json_encode(array('status'=>1,'data'=>$result));exit;
  5489. }else{
  5490. echo json_encode(array('status'=>0,'data'=>''));exit;
  5491. }
  5492. }else{
  5493. echo json_encode(array('status'=>0,'data'=>''));exit;
  5494. }
  5495. }
  5496. //////设置教学进度
  5497. public function actionSettingProgress(){
  5498. $data = array();
  5499. $textbookNames = array();
  5500. $subjectId = Req::get("subjectId")?Req::get("subjectId"):3;
  5501. $grade = Req::get("grade")?Req::get("grade"):1;
  5502. $proId = (int)Req::get("proId");
  5503. $edit = (int)Req::get("edit");
  5504. $data['module_id'] = '';
  5505. $data['chapter_id'] = '';
  5506. $data['section_id'] = '';
  5507. //当前日期
  5508. $sdefaultDate = date("Y-m-d");
  5509. //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
  5510. $first=1;
  5511. //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
  5512. $w=date('w',strtotime($sdefaultDate));
  5513. //获取本周开始日期,如果$w是0,则表示周日,减去 6 天
  5514. $data['start_time']=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
  5515. //本周结束日期
  5516. $data['end_time']=date('Y-m-d',strtotime("{$data['start_time']} +6 days"));
  5517. $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'";
  5518. $timeRange = $this->sConn->createCommand($sql)->queryRow();
  5519. if($timeRange){
  5520. $data['sem_start_time'] = date("Y-m-d",$timeRange['start_time']);
  5521. $data['sem_end_time'] = date("Y-m-d",$timeRange['end_time']);
  5522. }else{
  5523. $data['sem_start_time'] = '';
  5524. $data['sem_end_time'] = '';
  5525. }
  5526. if($proId && $edit){
  5527. $sql = "select class_id,subject_id,grade,module_id,chapter_id,section_id,textbook_id,textbook_name,start_time,end_time from teach_progress_class where id = {$proId}";
  5528. $dataArr = $this->sConn->createCommand($sql)->queryRow();
  5529. $subjectId = $dataArr['subject_id'];
  5530. $grade = $dataArr['grade'];
  5531. $data['classId'] = $dataArr['class_id'];
  5532. $sql = "select class_name from class where class_id = '{$dataArr['class_id']}'";
  5533. $classNameArr = $this->sConn->createCommand($sql)->queryRow();
  5534. // var_dump($classNameArr);exit;
  5535. $data['className'] = $classNameArr['class_name'];
  5536. $data['textbookId'] = $dataArr['textbook_id'];
  5537. $data['textbook_name'] = $dataArr['textbook_name'];
  5538. $data['module_id'] = $dataArr['module_id'];
  5539. $data['chapter_id'] = $dataArr['chapter_id'];
  5540. $data['section_id'] = $dataArr['section_id'];
  5541. $data['start_time'] = date("Y-m-d",$dataArr['start_time']);
  5542. $data['end_time'] = date("Y-m-d",$dataArr['end_time']);
  5543. }
  5544. if($subjectId == 8){
  5545. $textboookTree = new MongodbEnglishTree();
  5546. $criteria = new EMongoCriteria();
  5547. $textbookData = $textboookTree->find($criteria,array());
  5548. foreach ($textbookData as $doc) {
  5549. //var_dump($doc->attributes);exit;
  5550. foreach($doc->attributes as $key => $value){
  5551. if($key !== '_id'){
  5552. if(isset($value['textbook_id']) && isset($value['name'])){
  5553. $textbookNames[$value['textbook_id']] = $value['name'];
  5554. }
  5555. }
  5556. }
  5557. }
  5558. }else{
  5559. if($grade == 3){
  5560. $newSubjectId = 6;
  5561. }else{
  5562. $newSubjectId = 3;
  5563. }
  5564. $textbookTree = $this->apiPost('/textbook/tree', array(
  5565. 'subjectId' => $newSubjectId,
  5566. 'depth' => 1
  5567. ));
  5568. if (! $textbookTree) {
  5569. $error[] = '接口错误';
  5570. } elseif (isset($textbookTree->error)) {
  5571. $error[] = '接口错误';
  5572. } else {
  5573. foreach ($textbookTree as $textbook) {
  5574. $textbookNames[$textbook->textbook_id] = $textbook->textbook_name;
  5575. }
  5576. }
  5577. }
  5578. $data['edit'] = $edit;
  5579. // echo $edit;exit;
  5580. $data['subjectId'] = $subjectId;
  5581. $data['grade'] = $grade;
  5582. $data['textbookName'] = $textbookNames;
  5583. //var_dump($data);exit;
  5584. $this->render('teach_progress',$data);
  5585. }
  5586. /////查看历史教学进度
  5587. public function actionViewHistoryProgress(){
  5588. //echo 11;exit;
  5589. $data = array();
  5590. $classIdsInSem = array();
  5591. $subjectId = Req::get("subjectId")?Req::get("subjectId"):3;
  5592. $grade = Req::get("grade")?Req::get("grade"):1;
  5593. $classId = Req::get("classId")?Req::get("classId"):'';
  5594. $startTime = Req::get("start_time")?Req::get("start_time"):'';
  5595. $endTime = Req::get("end_time")?Req::get("end_time"):'';
  5596. $page = (int)Req::get("page")?(int)Req::get("page"):1;
  5597. $pagesize = 10;
  5598. $status = (int)Req::get("status")?(int)Req::get("status"):0;
  5599. $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'";
  5600. $timeRange = $this->sConn->createCommand($sql)->queryRow();
  5601. if($startTime){
  5602. $startTimeStr = $startTime;
  5603. $startTime = strtotime($startTime);
  5604. }else{
  5605. $startTimeStr = date("Y-m-d",$timeRange['start_time']);
  5606. $startTime = $timeRange['start_time'];
  5607. }
  5608. if($endTime){
  5609. $endTimeStr = $endTime;
  5610. $endTime = strtotime($endTime);
  5611. }else{
  5612. $endTimeStr = date("Y-m-d",$timeRange['end_time']);
  5613. $endTime = $timeRange['end_time'];
  5614. }
  5615. //var_dump($timeRange);exit;
  5616. $classIdToName = array();
  5617. $sql = "select class_id,class_name from class where grade = {$grade} and semester_id = {$this->semesterId}";
  5618. $classData = $this->sConn->createCommand($sql)->queryAll();
  5619. if($classData){
  5620. $data['classmeg'] = $classData;
  5621. foreach($classData as $class){
  5622. $classIdToName[$class['class_id']] = $class['class_name'];
  5623. $classIdsInSem[] = $class['class_id'];
  5624. }
  5625. }else{
  5626. $data['classmeg'] = array();
  5627. }
  5628. if($classIdsInSem){
  5629. $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} and end_time>={$startTime}) and class_id in (".implode(',',$classIdsInSem).")";
  5630. }else{
  5631. $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} or end_time>={$startTime}) and 1=2";
  5632. }
  5633. $orderby = " order by start_time desc";
  5634. if($status == 1){//开始时间倒序
  5635. $orderby = " order by start_time desc";
  5636. }else if($status == 2){//开始时间升序
  5637. $orderby = " order by start_time asc";
  5638. }else if($status == 3){//创建时间倒序
  5639. $orderby = " order by create_time desc";
  5640. }else if($status == 4){//创建时间升序
  5641. $orderby = " order by create_time asc";
  5642. }
  5643. if($classId){
  5644. $condition .= " and class_id = {$classId}";
  5645. }
  5646. $condition .= $orderby;
  5647. $sql = "select id,class_id,subject_id,create_time,start_time,end_time,textbook_id,textbook_name,module_id,chapter_id,section_id,textbook_id,textbook_name,is_new from teach_progress_class where ".$condition;
  5648. $rs = $this->schoolManager->getTeachProgress($sql,$pagesize);
  5649. if($rs['rs']){
  5650. foreach($rs['rs'] as $k=>$v){
  5651. if(isset($classIdToName[$v['class_id']])){
  5652. $rs['rs'][$k]['class_name'] = $classIdToName[$v['class_id']];
  5653. }else{
  5654. $rs['rs'][$k]['class_name'] = '';
  5655. }
  5656. $rs['rs'][$k]['progress_name'] = '';
  5657. if($subjectId == 3){
  5658. if($v['module_id']){
  5659. $mArr = explode(',', $v['module_id']);
  5660. foreach($mArr as $moduleId){
  5661. $moduleMessage = $this->apiPost('/textbook/module', array('moduleId' => $moduleId,'depth' => 1));
  5662. if ($moduleMessage && !isset($moduleMessage->error)) {
  5663. //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$moduleMessage->module_name).',';
  5664. $rs['rs'][$k]['progress_name'] .= strip_tags($moduleMessage->module_name).',';
  5665. }
  5666. }
  5667. }
  5668. if($v['chapter_id']){
  5669. $cArr = explode(',', $v['chapter_id']);
  5670. foreach($cArr as $chapterId){
  5671. $chapterMessage = $this->apiPost('/textbook/chapter', array('chapterId' => $chapterId,'depth' => 1));
  5672. if ($chapterMessage && !isset($chapterMessage->error)) {
  5673. //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$chapterMessage->chapter_name).',';
  5674. $rs['rs'][$k]['progress_name'] .= strip_tags($chapterMessage->chapter_name).',';
  5675. }
  5676. }
  5677. }
  5678. if($v['section_id']){
  5679. $sArr = explode(',', $v['section_id']);
  5680. foreach($sArr as $sectionId){
  5681. $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId,'depth' => 1));
  5682. if ($sectionMessage && !isset($sectionMessage->error)) {
  5683. //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$sectionMessage->section_name).',';
  5684. $rs['rs'][$k]['progress_name'] .= strip_tags($sectionMessage->section_name).',';
  5685. }
  5686. }
  5687. }
  5688. }else if($subjectId == 8){
  5689. if($v['chapter_id']){
  5690. $cArr = explode(',', $v['chapter_id']);
  5691. }else{
  5692. $cArr = array();
  5693. }
  5694. if($v['module_id']){
  5695. $mArr = explode(',', $v['module_id']);
  5696. }else{
  5697. $mArr = array();
  5698. }
  5699. if($v['section_id']){
  5700. $sArr = explode(',', $v['section_id']);
  5701. }else{
  5702. $sArr = array();
  5703. }
  5704. $textboookTree = new MongodbEnglishTree();
  5705. $criteria = new EMongoCriteria();
  5706. $textbookData = $textboookTree->find($criteria,array());
  5707. foreach ($textbookData as $doc) {
  5708. foreach($doc->attributes as $key => $value){
  5709. if($key !== '_id'){
  5710. if(isset($value['module']) && $value['module']){
  5711. foreach($value['module'] as $km=>$vm){
  5712. if(in_array($vm['textbook_module_id'],$mArr,true)){
  5713. $rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$vm['name']).',';
  5714. }
  5715. if(isset($vm['unit']) && $vm['unit']){
  5716. foreach($vm['unit'] as $kk=>$vv){
  5717. if(in_array($vv['textbook_unit_id'],$cArr,true)){
  5718. $rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$vv['name']).',';
  5719. }
  5720. }
  5721. }
  5722. }
  5723. }
  5724. }
  5725. }
  5726. }
  5727. }
  5728. }
  5729. }
  5730. $data['status'] = $status;
  5731. $data['start_time'] = $startTimeStr;
  5732. $data['end_time'] = $endTimeStr;
  5733. $data['subjectId'] = $subjectId;
  5734. $data['classId'] = $classId;
  5735. $data['grade'] = $grade;
  5736. $data['page'] = $page;
  5737. $data['pagesize'] = $pagesize;
  5738. $data['rs'] = $rs;
  5739. //print_r($data);exit;
  5740. $this->render('view_history_progress',$data);
  5741. }
  5742. ////教学进度分层查看班级
  5743. public function actionAjaxGetClassesBylevel(){
  5744. $data = array();
  5745. $error = array();
  5746. $classMeg = array();
  5747. $grade = (int)Req::post("grade");
  5748. $subjectId = (int)Req::post("subjectId");
  5749. if($grade > 0){
  5750. $textbook_class = array();
  5751. $sql = "SELECT class_id,textbook_id,textbook_name FROM (SELECT class_id,textbook_id,textbook_name,create_time FROM teach_progress_class where subject_id = {$subjectId} and is_new = 1 ORDER BY create_time DESC) a GROUP BY class_id ORDER BY create_time DESC";
  5752. $textbook_class_arr = $this->sConn->createCommand($sql)->queryAll();
  5753. if($textbook_class_arr){
  5754. foreach($textbook_class_arr as $k=>$v){
  5755. $textbook_class[$v['class_id']]['textbook_id'] = $v['textbook_id'];
  5756. $textbook_class[$v['class_id']]['textbook_name'] = $v['textbook_name'];
  5757. }
  5758. }
  5759. //var_dump($textbook_class);exit;
  5760. $sql = "select class_id,class_name,level from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type=1 and is_hide=0 order by level asc";
  5761. $classData = $this->sConn->createCommand($sql)->queryAll();
  5762. if($classData){
  5763. foreach($classData as $k=>$v){
  5764. if(isset($textbook_class[$v['class_id']])){
  5765. $v['textbook_id'] = $textbook_class[$v['class_id']]['textbook_id'];
  5766. $v['textbook_name'] = $textbook_class[$v['class_id']]['textbook_name'];
  5767. }else{
  5768. $v['textbook_id'] = 0;
  5769. $v['textbook_name'] = '';
  5770. }
  5771. $classMeg[$v['level']][] = $v;
  5772. }
  5773. }
  5774. }else{
  5775. $error[] = '年级错误';
  5776. }
  5777. if($error){
  5778. echo json_encode(array('status'=>0,'data'=>$classMeg,'error'=>$error));exit;
  5779. }else{
  5780. echo json_encode(array('status'=>1,'data'=>$classMeg));exit;
  5781. }
  5782. }
  5783. //知识图谱
  5784. public function actionAjaxGetSectionsByTextbookId(){
  5785. $error = array();
  5786. $result = array();
  5787. $textbookId = (int)Req::post("textbookId");
  5788. $subjectId = (int)Req::post("subjectId");
  5789. if (!$textbookId) {
  5790. $error[] = '请指定教材ID!';
  5791. }
  5792. if (!$subjectId) {
  5793. $error[] = '请指定学科!';
  5794. }
  5795. if(!$error){
  5796. if($subjectId == 3){
  5797. $textbooks = $this->apiPost('/textbook/detail', array('textbookId' => $textbookId, 'depth' => 4));
  5798. if (! $textbooks) {
  5799. $error[] = '接口错误';
  5800. } elseif (isset($textbooks->error)) {
  5801. $error[] = '接口错误';
  5802. } else {
  5803. if(isset($textbooks->modules) && $textbooks->modules){
  5804. $a = 0;
  5805. foreach($textbooks->modules as $k=>$v){
  5806. $result[$a]['module_id'] = $v->module_id;
  5807. $result[$a]['module_name'] = $v->module_name;
  5808. if(isset($v->chapters) && $v->chapters){
  5809. $b = 0;
  5810. foreach($v->chapters as $cha){
  5811. $result[$a]['chapters'][$b]['chapter_id'] = $cha->chapter_id;
  5812. $result[$a]['chapters'][$b]['chapter_name'] = $cha->chapter_name;
  5813. if(isset($cha->sections) && $cha->sections){
  5814. $c = 0 ;
  5815. foreach($cha->sections as $sec){
  5816. $result[$a]['chapters'][$b]['sections'][$c]['section_id'] = $sec->section_id;
  5817. $result[$a]['chapters'][$b]['sections'][$c]['section_name'] = $sec->section_name;
  5818. $c++;
  5819. }
  5820. }
  5821. $b++;
  5822. }
  5823. }
  5824. $a++;
  5825. }
  5826. }
  5827. }
  5828. }else if($subjectId == 8){
  5829. $textboookTree = new MongodbEnglishTree();
  5830. $criteria = new EMongoCriteria();
  5831. $textbookData = $textboookTree->find($criteria,array());
  5832. foreach ($textbookData as $doc) {
  5833. foreach($doc->attributes as $key => $value){
  5834. if($key !== '_id'){
  5835. if($value['textbook_id'] == $textbookId){
  5836. if(isset($value['module']) && $value['module']){
  5837. $a = 0;
  5838. foreach($value['module'] as $k=>$v){
  5839. $result[$a]['module_id'] = $v['textbook_module_id'];
  5840. $result[$a]['module_name'] = $v['name'];
  5841. if(isset($v['unit']) && $v['unit']){
  5842. $b = 0;
  5843. foreach($v['unit'] as $kk=>$vv){
  5844. $result[$a]['chapters'][$b]['chapter_id'] = $vv['textbook_unit_id'];
  5845. $result[$a]['chapters'][$b]['chapter_name'] = $vv['name'];
  5846. $b++;
  5847. }
  5848. }
  5849. $a++;
  5850. }
  5851. }
  5852. }
  5853. }
  5854. }
  5855. }
  5856. }
  5857. }
  5858. if ($error) {
  5859. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
  5860. } else {
  5861. echo json_encode(array('status'=>1,'data'=>$result));
  5862. }
  5863. }
  5864. //插入教学进度数据
  5865. public function actionAjaxInsertTeachProgress(){
  5866. $error = array();
  5867. $subjectId = (int)Req::post("subjectId");
  5868. $grade = (int)Req::post("grade");
  5869. $classIds = Req::post("classIds");
  5870. $startTimeUnix = (int)Req::post("startTimeUnix");
  5871. $endTimeUnix = (int)Req::post("endTimeUnix");
  5872. $moduleArr = Req::post("moduleArr")?Req::post("moduleArr"):array();
  5873. $chapterArr = Req::post("chapterArr")?Req::post("chapterArr"):array();
  5874. $sectionArr = Req::post("sectionArr")?Req::post("sectionArr"):array();
  5875. $textbookId = (int)Req::post("textbookId");
  5876. $textbookName = (string)Req::post("textbookName");
  5877. $selectSectionIds = Req::post("selectSectionIds")?Req::post("selectSectionIds"):array();
  5878. $methodIds = '';
  5879. $kpIds = '';
  5880. if(!$subjectId){
  5881. $error[] = "请选择科目";
  5882. }
  5883. if(!$grade){
  5884. $error[] = "请选择年级";
  5885. }
  5886. if(!$classIds){
  5887. $error[] = "请选择班级";
  5888. }
  5889. if(!$startTimeUnix){
  5890. $error[] = "请选择开始时间";
  5891. }
  5892. if(!$endTimeUnix){
  5893. $error[] = "请选择结束时间";
  5894. }
  5895. if(!$textbookId){
  5896. $error[] = "请选择教材";
  5897. }
  5898. if(!$textbookName){
  5899. $error[] = "请选择教材名称";
  5900. }
  5901. if($selectSectionIds && $subjectId == 3){
  5902. $methodArr = array();
  5903. $kpArr = array();
  5904. foreach($selectSectionIds as $v){
  5905. foreach($v as $sectionId){
  5906. if((int)$sectionId > 0){
  5907. $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId));
  5908. if (! $sectionMessage) {
  5909. $error[] = '接口错误1';
  5910. } elseif (isset($sectionMessage->error)) {
  5911. $error[] = '接口错误';
  5912. } else {
  5913. if(isset($sectionMessage->kps) && $sectionMessage->kps){
  5914. foreach($sectionMessage->kps as $kk=>$vv){
  5915. $kpArr[] = $vv->kp_id;
  5916. if(isset($vv->methods) && $vv->methods){
  5917. foreach($vv->methods as $med){
  5918. if(isset($med->method_id) && $med->method_id){
  5919. $methodArr[] = $med->method_id;
  5920. }
  5921. }
  5922. }
  5923. }
  5924. }
  5925. }
  5926. }
  5927. }
  5928. }
  5929. if($methodArr){
  5930. $methodIds = implode(',', $methodArr);
  5931. }
  5932. if($kpArr){
  5933. $kpIds = implode(',', $kpArr);
  5934. }
  5935. }
  5936. if(!$error){
  5937. $time =time();
  5938. $transaction = $this->sConn->beginTransaction();
  5939. try{
  5940. foreach($classIds as $classId){
  5941. $this->sConn->createCommand("update teach_progress_class set is_new = 0 where class_id = {$classId} and subject_id={$subjectId}")->execute();
  5942. $this->sConn->createCommand()->insert('teach_progress_class',array(
  5943. 'class_id' => $classId,
  5944. 'subject_id' => $subjectId,
  5945. 'grade' => $grade,
  5946. 'semester_id' => $this->semesterId,
  5947. 'textbook_id' => $textbookId,
  5948. 'textbook_name' => $textbookName,
  5949. 'create_time' => $time,
  5950. 'start_time' => $startTimeUnix,
  5951. 'end_time' => $endTimeUnix,
  5952. 'module_id' => $moduleArr? implode(",", $moduleArr):'',
  5953. 'chapter_id' => $chapterArr? implode(",", $chapterArr):'',
  5954. 'section_id' => $sectionArr? implode(",", $sectionArr):'',
  5955. 'kp_ids_selected' =>$kpIds,
  5956. 'method_ids_selected' => $methodIds,
  5957. 'is_new' => 1
  5958. ));
  5959. }
  5960. $transaction->commit();
  5961. }catch(Exception $e){
  5962. $transaction->rollBack();
  5963. if (YII_ENV == 'production') {
  5964. $error[] = '系统错误[SQL]';
  5965. } else {
  5966. $error[] = $e->getMessage();
  5967. }
  5968. }
  5969. }
  5970. if ($error) {
  5971. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
  5972. } else {
  5973. echo json_encode(array('status'=>1));
  5974. }
  5975. }
  5976. //删除教学进度
  5977. public function actionAjaxDelTeachProgress(){
  5978. $error = array();
  5979. $progressId = (int)Req::post("progressId");
  5980. if(!$progressId){
  5981. $error[] = "请指定教学进度";
  5982. }
  5983. if(!$error){
  5984. $transaction = $this->sConn->beginTransaction();
  5985. try{
  5986. $this->sConn->createCommand("delete from teach_progress_class where id = {$progressId}")->execute();
  5987. $transaction->commit();
  5988. }catch(Exception $e){
  5989. $transaction->rollBack();
  5990. if (YII_ENV == 'production') {
  5991. $error[] = '系统错误[SQL]';
  5992. } else {
  5993. $error[] = $e->getMessage();
  5994. }
  5995. }
  5996. }
  5997. if ($error) {
  5998. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
  5999. } else {
  6000. echo json_encode(array('status'=>1));
  6001. }
  6002. }
  6003. //加载班主任
  6004. public function actionLoadTeacher(){
  6005. $keyword = safe_replace(Yii::app()->request->getParam('keyword'));
  6006. $result['status']=0;
  6007. $data=$this->schoolManager->loadTeacher($keyword,0);
  6008. $teachers=array();
  6009. if($data){
  6010. foreach ($data as $key => $v){
  6011. if(!in_array($v['posts'],array(1,2,3,5))){
  6012. continue;
  6013. }
  6014. $teachers[]=$v;
  6015. }
  6016. }
  6017. $result['data']=$teachers;
  6018. $result['status']=1;
  6019. exit(json_encode($result));
  6020. }
  6021. //走班设置
  6022. public function actionClassShift(){
  6023. $setting=$this->schoolManager->getClassShift($this->semesterId);
  6024. $data['setting']=$setting;
  6025. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  6026. $data['subject']=Yii::app()->params['subjectId'];
  6027. unset($data['subject'][6]);
  6028. unset($data['subject'][51]);
  6029. unset($data['subject'][18]);
  6030. unset($data['subject'][19]);
  6031. if(isset($data['subject'][20])) unset($data['subject'][20]);
  6032. }
  6033. $this->render('classified',$data);
  6034. }
  6035. //新增走班学科
  6036. public function actionAddClassified(){
  6037. $grade = (int)Req::post("grade");
  6038. $subject = Req::post("subject");
  6039. $result['status']=0;
  6040. //debug($subject);
  6041. if(!$grade){
  6042. $result['msg']='请选择年级';
  6043. exit(json_encode($result));
  6044. }
  6045. if(!$subject){
  6046. $result['msg']='请选择学科';
  6047. exit(json_encode($result));
  6048. }
  6049. $semesterId=$this->semesterId;
  6050. $insertArr=array();
  6051. foreach ($subject as $val){
  6052. $check=$this->schoolManager->getClassifiedBySubject($grade,$val,$semesterId);
  6053. if($check){
  6054. $result['msg']='学科:'.Yii::app()->params['subjectId'][$val]."已添加,请勿重复添加";
  6055. exit(json_encode($result));
  6056. }
  6057. $insertArr[]=array(
  6058. 'grade'=>$grade,
  6059. 'subject_id'=>$val,
  6060. 'status'=>0,
  6061. 'semester_id'=>$semesterId
  6062. );
  6063. }
  6064. if($insertArr){
  6065. if($this->schoolManager->insertClassified($insertArr)){
  6066. $result['status']=1;
  6067. exit(json_encode($result));
  6068. }
  6069. }
  6070. exit(json_encode($result));
  6071. }
  6072. //学科走班状态设置
  6073. public function actionUpdateClassified(){
  6074. $grade = (int)Req::post("grade");
  6075. $subject = Req::post("subject");
  6076. $type=Req::post('type');
  6077. $semesterId= $this->semesterId;
  6078. $result['status']=0;
  6079. $rs=$this->schoolManager->updateClassifiedBySubject($grade,$subject,$semesterId,$type);
  6080. if($rs){
  6081. $result['status']=1;
  6082. }
  6083. exit(json_encode($result));
  6084. }
  6085. //添加教学班
  6086. public function actionAddClass(){
  6087. checkAuthority(2); // 非当前使用学期无法操作
  6088. $data = array();
  6089. $teachers = $this->schoolManager->getTeachers();
  6090. $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
  6091. $semesterId = $this->semesterId;
  6092. $thisSemester = $this->schoolManager->getSemester($semesterId);
  6093. if (Yii::app()->request->getIsPostRequest()){
  6094. $class_name = trim(Req::post("class_name"));
  6095. $mid_array = array();
  6096. $subjectId = 0;
  6097. $material_id = 0;
  6098. $coach_id = $this->coachInfo->coach_id;
  6099. $period = $thisSemester['school_year'];
  6100. $teachersIds = Req::post("teacher_ids");
  6101. $subject_ids = Req::post("subject_ids");
  6102. $levelName = Req::post("level_name");
  6103. $level = array($levelName => null);
  6104. $grade = Req::post("grade");
  6105. $_subject_ids = array();
  6106. if($subject_ids)
  6107. {
  6108. foreach($subject_ids as $v)
  6109. {
  6110. if(in_array($v,$_subject_ids))
  6111. {
  6112. Yii::app()->jump->error('班级不能增加相同的学科教师');
  6113. }
  6114. $_subject_ids[] = $v;
  6115. }
  6116. }
  6117. if(is_array($teachersIds)){
  6118. foreach($teachersIds as $key => $val){
  6119. if(empty($val) ||(is_string($val) && trim($val) == ""))
  6120. unset($teachersIds[$key]);
  6121. }
  6122. }
  6123. if(!array_intersect_key($level, $this->class_level))
  6124. $levelName = "";
  6125. if (empty($class_name)){
  6126. Yii::app()->jump->error('班级信息未填写完整!');
  6127. }
  6128. else if(empty($coach_id)){
  6129. Yii::app()->jump->error('未选择助教!');
  6130. }
  6131. else if(!$teachersIds){
  6132. Yii::app()->jump->error('未选择执教老师!');
  6133. }
  6134. else if(!$grade){
  6135. Yii::app()->jump->error('未选择年级!');
  6136. }
  6137. $classesModel = new ClassModel();
  6138. // 判断当前学期当前班级是否已添加
  6139. if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
  6140. {
  6141. Yii::app()->jump->error('该学期下已存在同名班级!');
  6142. }
  6143. // 当前班级唯一id
  6144. //$classId = getUUID();
  6145. $classId=getUniqueId($this->schoolId);
  6146. if (empty($classId)) {
  6147. Yii::app()->jump->error('创建班级失败!');
  6148. }
  6149. // 创建班级相关事务
  6150. $transaction = $classesModel->dbConnection->beginTransaction();
  6151. try{
  6152. //创建班级与老师关系
  6153. $level=Char::letterToNum($levelName, 1);
  6154. if(!$level) $level=0;
  6155. if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array(
  6156. 'class_id' => $classId,
  6157. 'class_name' => $class_name,
  6158. 'level' =>$level,
  6159. 'grade' => $grade,
  6160. 'semester_id' => $semesterId,
  6161. 'period' => $period,
  6162. 'add_time' => time(),
  6163. 'coach_id' => $this->coachId,
  6164. 'class_type' => 2,
  6165. 'wrong_book_type' =>0,
  6166. 'improve_book_type' =>0,
  6167. 'wb_isp_version' => 0,
  6168. )))
  6169. throw new CException("创建班级和老师关系失败");
  6170. foreach ($_subject_ids as $subject_id){
  6171. if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) {
  6172. throw new CException('创建失败!');
  6173. }
  6174. }
  6175. $transaction->commit();
  6176. } catch (Exception $e) {
  6177. //如果操作失败, 数据回滚
  6178. $transaction->rollback();
  6179. Yii::app()->jump->error($e->getMessage());
  6180. }
  6181. if($this->schoolManager->isCurrentSemester($semesterId))
  6182. $this->redirect(array('classes/index?class_type=2'));
  6183. else
  6184. $this->redirect(array("classes/index?semesterId={$semesterId}"));
  6185. }
  6186. unset(Yii::app()->session['school_material']);
  6187. // 获取当前学校所有助教
  6188. $coachList = array();
  6189. if(!isset(Yii::app()->session['crmUserInfo']))
  6190. {
  6191. $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  6192. if (empty($coachList)) {
  6193. Yii::app()->jump->error('系统未找到助教,请联系管理员!');
  6194. }
  6195. }else
  6196. {
  6197. $coachList = array(Yii::app()->session['crmUserInfo']);
  6198. }
  6199. unset($transaction);
  6200. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
  6201. //$data['semester'] = $semester;
  6202. $data['coachList'] = $coachList;
  6203. $data["teachers"] = $teachers;
  6204. $data["teacher_data"] = $teacher_data;
  6205. $data["classLevels"] = $this->class_level;
  6206. $data["semesters"] = $semesters;
  6207. $data["semesterId"] = $semesterId;
  6208. $data["thisSemester"] = $thisSemester;
  6209. $this->render('add_classified',$data);
  6210. }
  6211. //根据年级读取走班学科
  6212. public function actionGetClassSubjectByGrade(){
  6213. $grade = Req::post("grade");
  6214. $resultType=Req::post("rtype");
  6215. $semesterId=$this->semesterId;
  6216. $subjects=array();
  6217. $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId);
  6218. if($rs){
  6219. foreach ($rs as $val){
  6220. if($resultType=='arr'){
  6221. $subjects[]=$val['subject_id'];
  6222. }else{
  6223. $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
  6224. }
  6225. }
  6226. }
  6227. $result['status']=1;
  6228. $result['data']=$subjects;
  6229. exit(json_encode($result));
  6230. }
  6231. //编辑走班
  6232. public function actionEditClassified(){
  6233. $classId = safe_replace(Yii::app()->request->getQuery('cid'));
  6234. if (empty($classId)) {
  6235. Yii::app()->jump->error('操作失败!');
  6236. }
  6237. // 获取当前学校所有助教
  6238. $coachList = array();
  6239. if(!isset(Yii::app()->session['crmUserInfo']))
  6240. {
  6241. $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  6242. if (empty($coachList)) {
  6243. Yii::app()->jump->error('系统未找到助教,请联系管理员!');
  6244. }
  6245. }else
  6246. {
  6247. $coachList = array(Yii::app()->session['crmUserInfo']);
  6248. }
  6249. $semesterId = $this->semesterId;
  6250. $thisSemester = $this->schoolManager->getSemester($semesterId);
  6251. $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId);
  6252. // 班级信息
  6253. //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId));
  6254. $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ");
  6255. $grade = $classInfo->grade;
  6256. $teachers = $this->schoolManager->getTeachers();
  6257. $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
  6258. if (empty($classInfo)) {
  6259. Yii::app()->jump->error('未找到该班级信息!');
  6260. }
  6261. $subjects=array();
  6262. $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId);
  6263. if($rs){
  6264. foreach ($rs as $val){
  6265. $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
  6266. }
  6267. }
  6268. // 当前班级教练信息
  6269. $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ");
  6270. if (Yii::app()->request->getIsPostRequest()){
  6271. $class_name = trim(Req::post("class_name"));
  6272. $coach_id = $this->coachId;
  6273. $period = Req::post("period");
  6274. $levelName = Req::post("level_name");
  6275. $level = array($levelName => null);
  6276. $teachersIds = Req::post("teacher_ids");
  6277. $subject_ids = Req::post("subject_ids");
  6278. $_subject_ids = array();
  6279. if($subject_ids)
  6280. {
  6281. foreach($subject_ids as $v)
  6282. {
  6283. if(in_array($v,$_subject_ids))
  6284. {
  6285. Yii::app()->jump->error('班级不能增加相同的学科教师');
  6286. }
  6287. $_subject_ids[] = $v;
  6288. }
  6289. }
  6290. if(is_array($teachersIds)){
  6291. foreach($teachersIds as $key => $val){
  6292. if(empty($val) ||(is_string($val) && trim($val) == ""))
  6293. unset($teachersIds[$key]);
  6294. }
  6295. }
  6296. $grade = Req::post("grade");
  6297. //$semesterId = Req::post("semesterId");
  6298. if(!array_intersect_key($level, $this->class_level))
  6299. $levelName = "";
  6300. if (empty($class_name) || empty($coach_id) || !$teachersIds){
  6301. Yii::app()->jump->error('班级信息未填写完整!');
  6302. }
  6303. $classesModel = new ClassModel();
  6304. // 判断当前学期当前班级是否已添加
  6305. if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
  6306. {
  6307. if($classInfo->class_name != $class_name && !$classesModel->count('semester_id=:seid and class_name=:cname and class_id=:classId',array(':seid'=>$semesterId,':cname'=>$class_name,':classId'=>$classId)))
  6308. Yii::app()->jump->error('您选择的学期已存在同名班级!');
  6309. }
  6310. // 创建班级相关事务
  6311. //$transaction = Yii::app()->db->beginTransaction();
  6312. $classInfo = ClassModel::model()->find("class_id = '{$classId}'");
  6313. $transaction = $classInfo->dbConnection->beginTransaction();
  6314. try {
  6315. if($classInfo->class_name != $class_name)
  6316. $classInfo->class_name = $class_name;
  6317. //$classInfo->period = $period;
  6318. //$classInfo->grade = $grade;
  6319. //$classInfo->semester_id = $semesterId;
  6320. if(!$levelName){
  6321. $classInfo->level =0;
  6322. }else{
  6323. $classInfo->level = Char::letterToNum($levelName, 1);
  6324. }
  6325. $classInfo->wrong_book_type = 0;
  6326. $classInfo->improve_book_type = 0;
  6327. $classInfo->wb_isp_version = 0;
  6328. if(!$classInfo->save()){
  6329. throw new CException('更新失败!');
  6330. }
  6331. if($classInfo->coach_id != $coach_id){
  6332. if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) {
  6333. throw new CException('班级更新失败!');
  6334. }
  6335. }
  6336. if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId))
  6337. throw new CException("班级老师更新失败");
  6338. //清除旧关联
  6339. $this->schoolManager->DelClassSubject($classId);
  6340. foreach ($_subject_ids as $subject_id){
  6341. if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) {
  6342. throw new CException('创建失败!');
  6343. }
  6344. }
  6345. $transaction->commit();
  6346. } catch (Exception $e) {
  6347. //如果操作失败, 数据回滚
  6348. $transaction->rollback();
  6349. Yii::app()->jump->error($e->getMessage());
  6350. }
  6351. $this->redirect(array('classes/index?class_type=2'));
  6352. }
  6353. $data = array();
  6354. $class_teacher_data = array();
  6355. $subject_teacher_data = array();
  6356. $subject_teacher_array = array();
  6357. $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
  6358. $teachers_data = Teacher::model()->findAll('status=0');
  6359. if($teachers_data)
  6360. {
  6361. $gangwei = array(
  6362. 0=>'任课教师',
  6363. 1=>'班主任',
  6364. 2=>'教研组长',
  6365. 3=>'年级主任',
  6366. 4=>'任课教师',
  6367. 5=>'校长',
  6368. );
  6369. $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
  6370. foreach($teachers_data as $k=>$v)
  6371. {
  6372. $class_teacher_data[$v->teacher_id] = $v->teacher_id;
  6373. $subject_teacher_data[$v->teacher_id] = $v->subjects;
  6374. $teacherGrade = $v->grade?$v->grade:0;
  6375. if($v->posts==3){
  6376. //过滤本年级的年级主任
  6377. if (!$teacherGrade || $teacherGrade==$grade){
  6378. $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts];
  6379. $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost);
  6380. }
  6381. }else{
  6382. $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$gangwei[$v->posts]);
  6383. }
  6384. }
  6385. }
  6386. $data["teachers"] = $teachers;
  6387. $data["classLevels"] = $this->class_level;
  6388. $data["classTeachersIds"] = $classTeachersIds;
  6389. $data['classInfo'] = $classInfo;
  6390. $data['relatCoach'] = $relatCoach;
  6391. $data['class_teacher'] = $class_teacher_data;
  6392. $data['subject_teacher'] = $subject_teacher_data;
  6393. $data['subject_teacher_array'] = $subject_teacher_array;
  6394. $data["teacher_data"] = $teacher_data;
  6395. $data['coachList'] = $coachList;
  6396. $data["semesters"] = $semesters;
  6397. $data["semester_id"] = $classInfo->semester_id;
  6398. $data['subjects']=$subjects;
  6399. $data['thisSemester']=$thisSemester;
  6400. $this->render('edit_classified',$data);
  6401. }
  6402. //教学班转班
  6403. public function actionCopyClassified(){
  6404. $gradeArr=array(
  6405. 1=>'高一',
  6406. 2=>'高二',
  6407. 3=>'高三',
  6408. );
  6409. $data = array();
  6410. $cid = safe_replace(Yii::app()->request->getQuery('cid'));
  6411. $classInfo = $this->schoolManager->getClassInfo($cid);
  6412. $subjects=$this->schoolManager->getSubjectByClass($cid);
  6413. $semestersList = $this->schoolManager->getSemesters();
  6414. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  6415. $data['subject']=Yii::app()->params['subjectId'];
  6416. unset($data['subject'][6]);
  6417. unset($data['subject'][51]);
  6418. unset($data['subject'][18]);
  6419. unset($data['subject'][19]);
  6420. if(isset($data['subject'][20])) unset($data['subject'][20]);
  6421. }
  6422. $data['cid'] = $cid;
  6423. $data['grade']=$classInfo['grade'];
  6424. $data['gradeName']=$gradeArr[$classInfo['grade']];
  6425. $data['cname'] = $classInfo['class_name'];
  6426. $data['subjects'] = $subjects;
  6427. $data['semester']=$semestersList;
  6428. $this->render('copy_classified', $data);
  6429. }
  6430. //根据学期加载教学班学科
  6431. public function actionAjaxGetSubjectBySemester(){
  6432. $semester = Req::post("semester");
  6433. if(!$semester){
  6434. echo json_encode(array('status'=>0,'data'=>''));exit;
  6435. }
  6436. $rs=$this->sConn->createCommand("select distinct subject_id from classified where semester_id='{$semester}' and status=1")->queryAll();
  6437. $subjects=array();
  6438. if($rs){
  6439. foreach ($rs as $val){
  6440. $subjects[]=array(
  6441. 'subject_id'=>$val['subject_id'],
  6442. 'subject_name'=>Yii::app()->params['subjectId'][$val['subject_id']]
  6443. );
  6444. }
  6445. }
  6446. echo json_encode(array('status'=>1,'data'=>$subjects));exit;
  6447. }
  6448. //根据学期学科加载年级
  6449. public function actionAjaxGetGradeBySubject(){
  6450. $semester = Req::post("semester");
  6451. $subject = Req::post("subject");
  6452. if(!$semester || !$subject){
  6453. echo json_encode(array('status'=>0,'data'=>''));exit;
  6454. }
  6455. $rs=$this->sConn->createCommand("select distinct grade from classified where semester_id='{$semester}' and subject_id='{$subject}' and status=1")->queryAll();
  6456. $grades=array();
  6457. $gradeText=array(
  6458. 1=>'高一',
  6459. 2=>'高二',
  6460. 3=>'高三'
  6461. );
  6462. if($rs){
  6463. foreach ($rs as $val){
  6464. $grades[]=array(
  6465. 'id'=>$val['grade'],
  6466. 'name'=>$gradeText[$val['grade']]
  6467. );
  6468. }
  6469. }
  6470. echo json_encode(array('status'=>1,'data'=>$grades));exit;
  6471. }
  6472. //加载教学班
  6473. public function actionAjaxGetClass(){
  6474. $semester = Req::post("semester");
  6475. $subject = Req::post("subject");
  6476. $grade = Req::post("grade");
  6477. $to_class_id = Req::post("to_class_id");
  6478. if(!$semester || !$subject){
  6479. echo json_encode(array('status'=>0,'data'=>''));exit;
  6480. }
  6481. if($to_class_id){
  6482. $rs=$this->sConn->createCommand("SELECT c.class_id,c.class_name FROM `class_subject_relation` csr join class c on c.class_id=csr.class_id where c.grade='{$grade}' and csr.subject_id='{$subject}' and c.semester_id='{$semester}' and c.class_type=2 and c.class_id<>'{$to_class_id}' and is_hide=0")->queryAll();
  6483. }else{
  6484. $rs=$this->sConn->createCommand("SELECT c.class_id,c.class_name FROM `class_subject_relation` csr join class c on c.class_id=csr.class_id where c.grade='{$grade}' and csr.subject_id='{$subject}' and c.semester_id='{$semester}' and c.class_type=2 and is_hide=0")->queryAll();
  6485. }
  6486. echo json_encode(array('status'=>1,'data'=>$rs));exit;
  6487. }
  6488. //校验同学期同名班级
  6489. public function actionCheckClassNameOnSameSemester(){
  6490. $className=Req::post('class_name');
  6491. $result=array();
  6492. $result['status']=0;
  6493. $semesterId=$this->semesterId;
  6494. $classesModel = new ClassModel();
  6495. // 判断当前学期当前班级是否已添加
  6496. $checkRepeat=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$className));
  6497. if ($checkRepeat)
  6498. {
  6499. if($checkRepeat->is_hide==1){
  6500. $result['status']=1;
  6501. $result['data']=$checkRepeat->class_id;
  6502. }
  6503. }
  6504. exit(json_encode($result));
  6505. }
  6506. //恢复班级
  6507. public function actionRecoverClass(){
  6508. $classId = Req::post("classId");
  6509. $result=array();
  6510. $result['status']=0;
  6511. if(!$classId){
  6512. exit(json_encode($result));
  6513. }
  6514. $sql="update class set is_hide=0,sort=0 where class_id='{$classId}'";
  6515. if($this->sConn->createCommand($sql)->execute()){
  6516. $result['status']=1;
  6517. }
  6518. exit(json_encode($result));
  6519. }
  6520. //隐藏班级
  6521. public function actionHideClass(){
  6522. $classId = Req::post("classId");
  6523. $result['status']=0;
  6524. if(!$classId){
  6525. $result['msg']='参数错误';
  6526. exit(json_encode($result));
  6527. }
  6528. if($this->schoolManager->classHasStudent($classId)){
  6529. $result['msg']='班级已关联学生不能隐藏';
  6530. exit(json_encode($result));
  6531. }
  6532. $sql="update class set is_hide=1 where class_id='{$classId}'";
  6533. if($this->sConn->createCommand($sql)->execute()){
  6534. $result['status']=1;
  6535. }
  6536. exit(json_encode($result));
  6537. }
  6538. public function actionTestQcloud(){
  6539. $qcloud=new HuaweiCloud();
  6540. $result=$qcloud->putFile('assets/data/import_score_example.xls','testupload/test/1.xls');
  6541. if($result && isset($result['Location'])){
  6542. debug($result['Location']);
  6543. }else{
  6544. debug('error');
  6545. }
  6546. }
  6547. public function getStudentsClassNo($chooseStudentArr)
  6548. {
  6549. $data = array();
  6550. $student_ids = array();
  6551. $student_names = array();
  6552. $student_cards = array();
  6553. $school_student_cards = array();
  6554. $userno = array();
  6555. $student_info = array();
  6556. $class_student = array();
  6557. $student_class_ids = array();
  6558. $student_class_data=$this->sConn->createCommand("select class_id,student_id,userno from student_class_relation where student_id in(".implode(',',$chooseStudentArr).") and status=0")->queryAll();
  6559. // $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status));
  6560. if($student_class_data)
  6561. {
  6562. foreach($student_class_data as $v)
  6563. {
  6564. if($chooseStudentArr && inArray($v['student_id'], $chooseStudentArr)){
  6565. $student_ids[$v['student_id']] = $v['student_id'];
  6566. $userno[$v['student_id']] = $v['userno'];
  6567. $class_student[$v['student_id']] = $v;
  6568. }
  6569. }
  6570. $criteria = new CDbCriteria();
  6571. $criteria->addInCondition('student_id',$student_ids);
  6572. $student_data = SStudentInfo::model()->findAll($criteria);
  6573. if($student_data)
  6574. {
  6575. foreach($student_data as $v)
  6576. {
  6577. $student_names[$v->student_id] = $v->realname;
  6578. $student_info[$v->student_id] = $v;
  6579. }
  6580. }
  6581. unset($student_data);
  6582. unset($criteria);
  6583. $criteria = new CDbCriteria();
  6584. $criteria->addInCondition('student_id',$student_ids);
  6585. $b_student_data = BusinessStudent::model()->findAll($criteria);
  6586. if($b_student_data)
  6587. {
  6588. foreach($b_student_data as $v)
  6589. {
  6590. $student_cards[$v->student_id] = $v->student_card;
  6591. if($v->school_student_card)
  6592. {
  6593. $school_student_cards[$v->student_id] = $v->school_student_card;
  6594. }
  6595. //$school_student_cards[$v->student_id] = $v->school_student_card;
  6596. }
  6597. }
  6598. unset($b_student_data);
  6599. $data['student_names'] = $student_names;
  6600. $data['student_cards'] = $student_cards;
  6601. $data['student_ids'] = $student_ids;
  6602. $data['school_student_cards'] = $school_student_cards;
  6603. $data['student_userno'] = $userno;
  6604. $data['student_info'] = $student_info;
  6605. $data['class_student'] = $class_student;
  6606. $data['student_class_ids'] = $student_class_ids;
  6607. }
  6608. unset($student_class_data);
  6609. return $data;
  6610. }
  6611. /**
  6612. * 批量添加班级页面
  6613. */
  6614. public function actionBatchAdd(){
  6615. $data = array();
  6616. $this->render('batch_add',$data);
  6617. }
  6618. /**
  6619. * 批量添加班级逻辑
  6620. */
  6621. public function actionClassImport(){
  6622. ini_set ('memory_limit', '300M');
  6623. $updateSql = $updateSqlSub = array();
  6624. $semesterId = $this->semesterId;
  6625. $thisSemester = $this->schoolManager->getSemester($semesterId);
  6626. $period = $thisSemester['school_year'];
  6627. if(!$_FILES){
  6628. Yii::app()->jump->error('文件大小超过范围');
  6629. }else {
  6630. if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
  6631. Yii::app()->jump->error('文件大小超过范围');
  6632. }
  6633. }
  6634. $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/");
  6635. $uploader->allowTypes = array("xls","xlsx");
  6636. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  6637. $file = $uploader->act();
  6638. $file = Arr::current(Arr::current($file));
  6639. if (!$file || !isset($file["error"]))
  6640. Yii::app()->jump->error('请上传的Excel!');
  6641. if ($file["error"] != 0) {
  6642. switch ($file["error"]) {
  6643. case 2001:
  6644. Yii::app()->jump->error('文件类型不符');
  6645. break;
  6646. case 2002:
  6647. Yii::app()->jump->error('文件大小超出允许范围');
  6648. break;
  6649. default:
  6650. Yii::app()->jump->error('上传失败');
  6651. break;
  6652. }
  6653. }
  6654. $inputFileName = $file["src"];
  6655. // 导入PHPExcel类
  6656. Yii::import('application.extensions.*');
  6657. require_once('phpexcel/PHPExcel/IOFactory.php');
  6658. try{
  6659. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  6660. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  6661. //FIXME 2019-12-02
  6662. @unlink($file["src"]);
  6663. }catch (Exception $e){
  6664. //FIXME 2019-12-02
  6665. @unlink($file["src"]);
  6666. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  6667. }
  6668. if(!$sheetData)
  6669. {
  6670. Yii::app()->jump->error('请正确的Excel!');
  6671. }
  6672. unset($objPHPExcel);
  6673. //模板校验
  6674. if(Yii::app()->params['section']==1){
  6675. $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*文理科','E'=>'*班主任','F'=>'*班主任电话','G'=>'*学科','H'=>'*老师','I'=>'*老师电话');
  6676. $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'文理科','E'=>'班主任','F'=>'班主任电话','G'=>'学科','H'=>'老师','I'=>'老师电话');
  6677. }else{
  6678. $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*班主任','E'=>'*班主任电话','F'=>'*学科','G'=>'*老师','H'=>'*老师电话');
  6679. $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'班主任','E'=>'班主任电话','F'=>'学科','G'=>'老师','H'=>'老师电话');
  6680. }
  6681. $classnamsTemp = array();
  6682. if(count($excelTemp) != count($sheetData[1])){
  6683. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  6684. }
  6685. foreach($excelTemp as $key=>$temp){
  6686. if(!(isset($sheetData[2][$key]) && $sheetData[2][$key] == trim($temp))){
  6687. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  6688. }
  6689. }
  6690. unset($sheetData[1]);
  6691. unset($sheetData[2]);
  6692. if(!$sheetData)
  6693. {
  6694. Yii::app()->jump->error('请输入班级数据');
  6695. }
  6696. /**
  6697. * 1.检测必填字段不为空的情况
  6698. * 2.检测字段时候符合标准
  6699. * 3.检测excel班级名称时候重复
  6700. * 4、合并单元格处理
  6701. * 5、教师账号检测
  6702. */
  6703. $classTdFirst=1; //标记合并单元格第一行
  6704. $classAndTeacherData=array();
  6705. $tableNo=0;
  6706. $classTeacherRepeatCheck=array();
  6707. foreach($sheetData as $hang_no=>$hang_data){
  6708. if(trim($hang_data['A'])){
  6709. $classTdFirst=1;
  6710. $tableNo=$hang_no;
  6711. }else{
  6712. if(!$classAndTeacherData){
  6713. Yii::app()->jump->error('班级名称不能为空');
  6714. }
  6715. $classTdFirst=0;
  6716. }
  6717. if($classTdFirst){
  6718. foreach($hang_data as $key=>$val){
  6719. $val = $hang_data[$key] = trim($val);
  6720. if(!$val){
  6721. Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空');
  6722. }
  6723. if($key=='B'){
  6724. if(!in_array($val,array_keys(Yii::app()->params['grade_config']))){
  6725. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  6726. }
  6727. }
  6728. if($key=='C'){
  6729. if(!in_array($val,array('A','B','C'))){
  6730. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  6731. }
  6732. }
  6733. if(Yii::app()->params['section']==1){
  6734. if($key=='D'){
  6735. if(!in_array($val,array('不分科','文科','理科'))){
  6736. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  6737. }
  6738. }
  6739. }
  6740. }
  6741. $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'";
  6742. $class_data = $this->sConn->createCommand($sql)->queryRow();
  6743. if($class_data){
  6744. Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传 '.$hang_data['A']);
  6745. }
  6746. $teacher_id = '';
  6747. $class_master_name = Yii::app()->params['section']==1?$hang_data['E']:$hang_data['D'];
  6748. $class_master_phone = Yii::app()->params['section']==1?$hang_data['F']:$hang_data['E'];
  6749. $sql = "select teacher_id from teacher where teacher_name = '{$class_master_name}' and posts=1";
  6750. $class_data = $this->sConn->createCommand($sql)->queryAll();
  6751. if($class_data){
  6752. $teacher_ids = _array_column($class_data, 'teacher_id');
  6753. $sql = "select teacher_id,phone_number from xb_teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_master_phone}'";
  6754. $teacherInfo = $this->conn->createCommand($sql)->queryRow();
  6755. if($teacherInfo){
  6756. $teacher_id = $teacherInfo['teacher_id'];
  6757. }else{
  6758. Yii::app()->jump->error('第'.$hang_no.'行班主任与班主任电话不匹配,请核对后再上传<br> '.$class_master_name.":".$class_master_phone);
  6759. }
  6760. }else{
  6761. Yii::app()->jump->error('第'.$hang_no.'行班主任姓名不存在 '.$class_master_name);
  6762. }
  6763. $grade = $hang_data['B'];
  6764. if($hang_data['C'] == 'A'){
  6765. $level = 1;
  6766. }else if($hang_data['C'] == 'B'){
  6767. $level = 2;
  6768. }else if($hang_data['C'] == 'C'){
  6769. $level = 3;
  6770. }
  6771. if(Yii::app()->params['section']==1){
  6772. if($hang_data['D'] == '不分科'){
  6773. $arts_science = 0;
  6774. }else if($hang_data['D'] == '文科'){
  6775. $arts_science = 1;
  6776. }else if($hang_data['D'] == '理科'){
  6777. $arts_science = 2;
  6778. }
  6779. }else{
  6780. $arts_science = 0;
  6781. }
  6782. //整理数据
  6783. $classAndTeacherData[$tableNo]=array(
  6784. 'class_name'=>$hang_data['A'],
  6785. 'grade'=>$grade,
  6786. 'level'=>$level,
  6787. 'arts_science'=>$arts_science,
  6788. 'teacher_id'=>$teacher_id,
  6789. 'teachers'=>array()
  6790. );
  6791. }
  6792. //关联教师数据
  6793. if(Yii::app()->params['section']==1) {
  6794. $subject = trim($hang_data['G']);
  6795. $teacher_name = trim($hang_data['H']);
  6796. $teacher_phone = trim($hang_data['I']);
  6797. }else{
  6798. $subject = trim($hang_data['F']);
  6799. $teacher_name = trim($hang_data['G']);
  6800. $teacher_phone = trim($hang_data['H']);
  6801. }
  6802. //判断教师
  6803. if(!$subject && !$teacher_name && !$teacher_phone){
  6804. //都不填,跳过
  6805. continue;
  6806. }elseif($subject && $teacher_name && $teacher_phone){
  6807. //校验科目
  6808. $subjectId=array_search($subject,Yii::app()->params['subjectId']);
  6809. if($subjectId==false){
  6810. Yii::app()->jump->error('第'.$hang_no.'科目不正确 ');
  6811. }
  6812. if(isset($classTeacherRepeatCheck[$tableNo]) && inArray($teacher_phone,$classTeacherRepeatCheck[$tableNo])){
  6813. Yii::app()->jump->error($classAndTeacherData[$tableNo]['class_name'].',老师电话有重复'.$teacher_phone);
  6814. }
  6815. $classTeacherRepeatCheck[$tableNo][]=$teacher_phone;
  6816. //检验手机号
  6817. $getPhone = BusinessTeacher::model()->find('phone_number=:phnum ', array(':phnum' => $teacher_phone));
  6818. if (!$getPhone) {
  6819. Yii::app()->jump->error('手机号'.$teacher_phone.'不存在!');
  6820. }elseif($getPhone->school_id!=$this->schoolId){
  6821. Yii::app()->jump->error('手机号'.$teacher_phone.'已在其它学校注册!');
  6822. }
  6823. //校验科目
  6824. $schoolTeacher=$this->sConn->createCommand("select subjects from teacher where teacher_id='{$getPhone['teacher_id']}'")->queryRow();
  6825. if($schoolTeacher['subjects']!=$subjectId){
  6826. Yii::app()->jump->error('第'.$hang_no.'行,教师手机号与科目不匹配'.$teacher_phone);
  6827. }
  6828. $classAndTeacherData[$tableNo]['teachers'][]=array(
  6829. 'teacher_id'=>$getPhone['teacher_id'],
  6830. 'subject_id'=>$subjectId
  6831. );
  6832. }elseif(!$subject ){
  6833. Yii::app()->jump->error('第'.$hang_no.'行,科目不能为空 ');
  6834. }elseif(!$teacher_name){
  6835. Yii::app()->jump->error('第'.$hang_no.'行,教师姓名不能为空 ');
  6836. }elseif(!$teacher_phone){
  6837. Yii::app()->jump->error('第'.$hang_no.'行,教师手机号不能为空 ');
  6838. }
  6839. }
  6840. //校验表格内名称重复
  6841. $classNameCheck=array();
  6842. if($classAndTeacherData){
  6843. $classIds=getBatchUuid($this->schoolId,count($classAndTeacherData));
  6844. $insertClassSqlValues=array();
  6845. $insertTeacherClassRelationSqlValues=array();
  6846. $insertClassSubjectRelationSqlValues=array();
  6847. foreach ($classAndTeacherData as $key => $item){
  6848. if(in_array($item['class_name'],$classNameCheck)){
  6849. Yii::app()->jump->error('第'.$key.'行'.'表格内出现重复的班级名称,请核对后再上传 '.$item['class_name']);
  6850. }else{
  6851. $classNameCheck[]=$item['class_name'];
  6852. }
  6853. $classId=array_pop($classIds);
  6854. $insertClassSqlValues[]="('".$classId."','".$item['class_name']."','".$this->coachId."','".$this->semesterId."','".$period."','".$item['grade']."','".$item['level']."','".time()."','".$item['arts_science']."','".$item['teacher_id']."')";
  6855. if($item['teachers']){
  6856. $teacherSubjectCheck=array();
  6857. foreach ($item['teachers'] as $teacher){
  6858. if(in_array($teacher['subject_id'],$teacherSubjectCheck)){
  6859. Yii::app()->jump->error('第'.$key.'行'.'同一班级出现重复的科目,请核对后再上传 ');
  6860. }else{
  6861. $teacherSubjectCheck[]=$teacher['subject_id'];
  6862. }
  6863. $insertTeacherClassRelationSqlValues[]= "('{$classId}', '{$teacher['teacher_id']}', '{$semesterId}')";
  6864. $insertClassSubjectRelationSqlValues[]= "('{$classId}', '{$teacher['subject_id']}')";
  6865. }
  6866. }
  6867. }
  6868. }
  6869. if($insertClassSqlValues){
  6870. $insertClassSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`arts_science`,`teacher_id`) VALUES ';
  6871. $insertTeacherClassRelationSql="insert into teacher_class_relation (`class_id`,`teacher_id`,`semester_id`) values";
  6872. $insertClassSubjectRelationSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values ';
  6873. $insertClassSql.=implode(',',$insertClassSqlValues);
  6874. $transaction = $this->sConn->beginTransaction();
  6875. try{
  6876. $this->sConn->createCommand($insertClassSql)->execute();
  6877. if($insertTeacherClassRelationSqlValues){
  6878. $insertTeacherClassRelationSql.=implode(',',$insertTeacherClassRelationSqlValues);
  6879. $this->sConn->createCommand($insertTeacherClassRelationSql)->execute();
  6880. }
  6881. if($insertClassSubjectRelationSqlValues){
  6882. $insertClassSubjectRelationSql.=implode(',',$insertClassSubjectRelationSqlValues);
  6883. $this->sConn->createCommand($insertClassSubjectRelationSql)->execute();
  6884. }
  6885. $transaction->commit();
  6886. }catch(Exception $e){
  6887. $transaction->rollBack();
  6888. debug($e);
  6889. Yii::app()->jump->error('班级批量上传失败!');
  6890. }
  6891. $url=$this->createUrl('/classes/index');
  6892. Yii::app()->jump->error('班级批量上传成功!',$url);
  6893. }else{
  6894. Yii::app()->jump->error('没有需要更新的数据!');
  6895. }
  6896. //end
  6897. }
  6898. /**
  6899. * 批量添加教学班班级页面
  6900. */
  6901. public function actionBatchAddClass(){
  6902. $data = array();
  6903. $this->render('batch_addclass',$data);
  6904. }
  6905. /**
  6906. * 批量添加教学班班级逻辑
  6907. */
  6908. public function actionClassImportType2(){
  6909. ini_set ('memory_limit', '300M');
  6910. $updateSql = $updateSubSql = array();
  6911. $tcrSql = array();
  6912. $semesterId = $this->semesterId;
  6913. $thisSemester = $this->schoolManager->getSemester($semesterId);
  6914. $period = $thisSemester['school_year'];
  6915. if(!$_FILES){
  6916. Yii::app()->jump->error('文件大小超过范围');
  6917. }else {
  6918. if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
  6919. Yii::app()->jump->error('文件大小超过范围');
  6920. }
  6921. }
  6922. $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/");
  6923. $uploader->allowTypes = array("xls","xlsx");
  6924. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  6925. $file = $uploader->act();
  6926. $file = Arr::current(Arr::current($file));
  6927. if (!$file || !isset($file["error"]))
  6928. Yii::app()->jump->error('请上传的Excel!');
  6929. if ($file["error"] != 0) {
  6930. switch ($file["error"]) {
  6931. case 2001:
  6932. Yii::app()->jump->error('文件类型不符');
  6933. break;
  6934. case 2002:
  6935. Yii::app()->jump->error('文件大小超出允许范围');
  6936. break;
  6937. default:
  6938. Yii::app()->jump->error('上传失败');
  6939. break;
  6940. }
  6941. }
  6942. $inputFileName = $file["src"];
  6943. // 导入PHPExcel类
  6944. Yii::import('application.extensions.*');
  6945. require_once('phpexcel/PHPExcel/IOFactory.php');
  6946. try{
  6947. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  6948. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  6949. //FIXME 2019-12-02
  6950. @unlink($file["src"]);
  6951. }catch (Exception $e){
  6952. //FIXME 2019-12-02
  6953. @unlink($file["src"]);
  6954. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  6955. }
  6956. if(!$sheetData)
  6957. {
  6958. Yii::app()->jump->error('请正确的Excel!');
  6959. }
  6960. unset($objPHPExcel);
  6961. //模板校验
  6962. $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*学科','E'=>'*老师','F'=>'*老师电话');
  6963. $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'学科','E'=>'老师','F'=>'老师电话');
  6964. $classnamsTemp = array();
  6965. if(count($excelTemp) != count($sheetData[1])){
  6966. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  6967. }
  6968. foreach($excelTemp as $key=>$temp){
  6969. if(!(isset($sheetData[1][$key]) && $sheetData[1][$key] == trim($temp))){
  6970. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  6971. }
  6972. }
  6973. unset($sheetData[1]);
  6974. if(!$sheetData)
  6975. {
  6976. Yii::app()->jump->error('请输入教师数据');
  6977. }
  6978. /**
  6979. * 1.检测必填字段不为空的情况
  6980. * 2.检测字段时候符合标准
  6981. * 3.检测excel班级名称时候重复
  6982. */
  6983. foreach($sheetData as $hang_no=>$hang_data){
  6984. $subject_ids_arr = array();
  6985. $classId = getUniqueId($this->schoolId);
  6986. foreach($hang_data as $key=>$val){
  6987. $val = $hang_data[$key] = trim($val);
  6988. if(!$val){
  6989. Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空');
  6990. }
  6991. if($key=='B'){
  6992. if(!in_array($val,array('1','2','3'))){
  6993. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  6994. }else{
  6995. // if($val == '一'){
  6996. // $grade = 1;
  6997. // }else if($val == '二'){
  6998. // $grade = 2;
  6999. // }else if($val == '三'){
  7000. // $grade = 3;
  7001. // }
  7002. $grade = $val;
  7003. }
  7004. }
  7005. if($key=='C'){
  7006. if(!in_array($val,array('A','B','C'))){
  7007. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  7008. }
  7009. }
  7010. if($key=='D'){
  7011. $subject_data = explode(";",$val);
  7012. foreach($subject_data as $sub_name){
  7013. $sql = "select master_subject_id from subject where subject_name = '{$sub_name}'";
  7014. $subject_info = $this->conn->createCommand($sql)->queryRow();
  7015. if(!$subject_info){
  7016. Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
  7017. }else{
  7018. $subject_id = $subject_info['master_subject_id'];
  7019. $updateSubSql[] = array($classId,$subject_id);
  7020. $subject_ids_arr[] = $subject_id;
  7021. $sql = "select * from classified where subject_id='{$subject_id}' and `status`=1 and semester_id='{$semesterId}' and grade={$grade}";
  7022. $is_classified = $this->sConn->createCommand($sql)->queryRow();
  7023. if(!$is_classified){
  7024. Yii::app()->jump->error('第'.$hang_no.'行走班学科未开通,请核对后再上传<br> '.$sub_name);
  7025. }
  7026. }
  7027. }
  7028. }
  7029. }
  7030. if(in_array($hang_data['A'],$classnamsTemp)){
  7031. Yii::app()->jump->error('第'.$hang_no.'行'.'表格内出现重复的班级名称,请核对后再上传<br>'.$hang_data['A']);
  7032. }else{
  7033. $classnamsTemp[] = $hang_data['A'];
  7034. $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'";
  7035. $class_data = $this->sConn->createCommand($sql)->queryRow();
  7036. if($class_data){
  7037. Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传<br> '.$hang_data['A']);
  7038. }
  7039. }
  7040. //判断学科 老师 电话数量时候一致
  7041. $teacher_data = explode(";",$hang_data['E']);
  7042. $phone_data = explode(";",$hang_data['F']);
  7043. if(count($subject_data) != count($teacher_data) && count($teacher_data) != count($phone_data) && count($phone_data) != count($subject_data)){
  7044. Yii::app()->jump->error('第'.$hang_no.'行 学科老师电话数量不一致');
  7045. }
  7046. //判断学科 老师 电话数据是否一致
  7047. foreach($teacher_data as $te_no=>$te_data){
  7048. $class_teacher_name = $te_data;
  7049. $class_teacher_phone = $phone_data[$te_no];
  7050. $class_teacher_subject = $subject_data[$te_no];
  7051. $class_teacher_subjectid = $subject_ids_arr[$te_no];
  7052. $sql = "select teacher_id,posts,grade from teacher where teacher_name = '{$class_teacher_name}' and subjects={$class_teacher_subjectid}";
  7053. $te_data = $this->sConn->createCommand($sql)->queryAll();
  7054. if($te_data){
  7055. //如果匹配到年级主任特殊处理
  7056. $teacher_ids = array();
  7057. foreach($te_data as $te_data_val){
  7058. if($te_data_val['posts'] == 3 && $te_data_val['grade'] != $grade){
  7059. }else{
  7060. $teacher_ids[] = $te_data_val['teacher_id'];
  7061. }
  7062. }
  7063. if(!$teacher_ids){
  7064. Yii::app()->jump->error('第'.$hang_no.'行'.'年级主任与学科不对应 '.$class_teacher_subject.' '.$class_teacher_name);
  7065. }else{
  7066. $sql = "select teacher_id,phone_number from xb_teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_teacher_phone}'";
  7067. $teacherInfo = $this->conn->createCommand($sql)->queryRow();
  7068. if($teacherInfo){
  7069. $teacher_id = $teacherInfo['teacher_id'];
  7070. $tcrSql[] = array($classId,$teacher_id,$this->semesterId);
  7071. }else{
  7072. Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传<br> '.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone);
  7073. }
  7074. }
  7075. }else{
  7076. Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传<br> '.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone);
  7077. }
  7078. }
  7079. if($hang_data['C'] == 'A'){
  7080. $level = 1;
  7081. }else if($hang_data['C'] == 'B'){
  7082. $level = 2;
  7083. }else if($hang_data['C'] == 'C'){
  7084. $level = 3;
  7085. }
  7086. $updateSql[] = array($classId,'"'.$hang_data['A'].'"',$this->coachId,$this->semesterId,$period,$grade,$level,time(),2);
  7087. }
  7088. if($updateSql && $tcrSql && $updateSubSql){
  7089. $schInsertSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`class_type`) VALUES ';
  7090. $tcrInsertSql = 'INSERT INTO teacher_class_relation (`class_id`, `teacher_id`,`semester_id`) VALUES ';
  7091. $schSubSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values ';
  7092. foreach($updateSql as $stVal){
  7093. $schInsertSql .= '('.implode(',',$stVal).'),';
  7094. }
  7095. foreach($tcrSql as $stVal){
  7096. $tcrInsertSql .= '('.implode(',',$stVal).'),';
  7097. }
  7098. foreach($updateSubSql as $stVal){
  7099. $schSubSql .= '('.implode(',',$stVal).'),';
  7100. }
  7101. $schInsertSql = substr($schInsertSql,0,-1);
  7102. $tcrInsertSql = substr($tcrInsertSql,0,-1);
  7103. $schSubSql = substr($schSubSql,0,-1);
  7104. $transaction = $this->sConn->beginTransaction();
  7105. try{
  7106. $this->sConn->createCommand($schInsertSql)->execute();
  7107. $this->sConn->createCommand($tcrInsertSql)->execute();
  7108. $this->sConn->createCommand($schSubSql)->execute();
  7109. $transaction->commit();
  7110. }catch(Exception $e){
  7111. $transaction->rollBack();
  7112. Yii::app()->jump->error('班级批量上传失败!');
  7113. }
  7114. $url=$this->createUrl('/classes/index?class_type=2');
  7115. Yii::app()->jump->error('班级批量上传成功!',$url);
  7116. }else{
  7117. Yii::app()->jump->error('没有需要更新的数据!');
  7118. }
  7119. }
  7120. /**
  7121. * 导出班级数据
  7122. */
  7123. public function actionExportClass(){
  7124. $excel_title = '班级信息导出';
  7125. $excel_show_title = array(1=>'班级',2=>'年级',3=>'层级',4=>'文理科',5=>'班主任',6=>'执教老师',7=>'学生人数');
  7126. $excel_show_msg = array(1=>'class_name',2=>'grade',3=>'level',4=>'arts_science',5=>'master_name',6=>'teacher_names',7=>'student_count');
  7127. $realname = (string)Req::get("realname");
  7128. $grade = (int)Req::get("grade");
  7129. $arts_science = (int)Req::get("arts_science");
  7130. $class_type = (int)Req::get("class_type");
  7131. $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
  7132. $choose_type = (string)Req::get("choose_type");//需要导出excel哪些数据
  7133. if($choose_type){
  7134. $choose_type_arr = explode(',',$choose_type);
  7135. }
  7136. $condition = array();
  7137. if(!$smid){
  7138. $smid = $this->semesterId;
  7139. }
  7140. $condition[] = "seme.semester_id = '{$smid}'";
  7141. $condition[] = "c.class_type={$class_type}";
  7142. $condition[] = "c.is_hide=0";
  7143. if($grade){
  7144. $condition[] = "c.grade={$grade}";
  7145. }
  7146. if($arts_science == 1){
  7147. $condition[] = "c.arts_science=1";
  7148. }else if($arts_science == 2){
  7149. $condition[] = "c.arts_science=2";
  7150. }
  7151. if($realname){
  7152. $condition[] = "c.class_name like '%{$realname}%'";
  7153. }
  7154. $condition = " where ".implode(" and ", $condition);
  7155. $sql = "select c.class_id,c.class_name,c.grade,c.level,c.arts_science,c.teacher_id
  7156. from class as c
  7157. join semester as seme on seme.semester_id = c.semester_id
  7158. {$condition}
  7159. order by c.sort!=0 desc,c.sort,c.class_id desc";
  7160. $class_data = $this->sConn->createCommand($sql)->queryAll();
  7161. if($class_data){
  7162. foreach($class_data as $k=>$v){
  7163. //获取班主任姓名
  7164. $class_data[$k]['master_name'] = '';
  7165. if($v['teacher_id']){
  7166. $sql = "select teacher_name from teacher where teacher_id = '{$v['teacher_id']}'";
  7167. $teacher_data = $this->sConn->createCommand($sql)->queryRow();
  7168. if($teacher_data){
  7169. $class_data[$k]['master_name'] = $teacher_data['teacher_name'];
  7170. }
  7171. }
  7172. //获取执教老师姓名
  7173. $class_data[$k]['teacher_names'] = '';
  7174. $sql = "select t.teacher_name from teacher_class_relation tcr join teacher t on tcr.teacher_id = t.teacher_id where tcr.class_id='{$v['class_id']}'";
  7175. $teacher_msg = $this->sConn->createCommand($sql)->queryAll();
  7176. if($teacher_msg){
  7177. $teacher_names = _array_column($teacher_msg, 'teacher_name');
  7178. $class_data[$k]['teacher_names'] = implode(';',$teacher_names);
  7179. }
  7180. //获取学生人数
  7181. $class_data[$k]['student_count'] = '';
  7182. $sql = "select count(student_id) count from student_class_relation where class_id='{$v['class_id']}' and `status`=0";
  7183. $student_data = $this->sConn->createCommand($sql)->queryRow();
  7184. if($student_data){
  7185. $class_data[$k]['student_count'] = $student_data['count'];
  7186. }
  7187. if($v['grade'] == 1){
  7188. $class_data[$k]['grade'] = '一';
  7189. }else if($v['grade'] == 2){
  7190. $class_data[$k]['grade'] = '二';
  7191. }else if($v['grade'] == 3){
  7192. $class_data[$k]['grade'] = '三';
  7193. }
  7194. if($v['level'] == 1){
  7195. $class_data[$k]['level'] = 'A';
  7196. }else if($v['level'] == 2){
  7197. $class_data[$k]['level'] = 'B';
  7198. }else if($v['level'] == 3){
  7199. $class_data[$k]['level'] = 'C';
  7200. }
  7201. if($v['arts_science'] == 1){
  7202. $class_data[$k]['arts_science'] = '文科';
  7203. }else if($v['arts_science'] == 2){
  7204. $class_data[$k]['arts_science'] = '理科';
  7205. }else{
  7206. $class_data[$k]['arts_science'] = '不分科';
  7207. }
  7208. }
  7209. }else{
  7210. Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index'));
  7211. }
  7212. if($class_data){
  7213. $objPHPExcel = new PHPExcel();
  7214. $objPHPExcel->getProperties()->setCreator("ctos")
  7215. ->setLastModifiedBy("ctos")
  7216. ->setTitle("班级信息")
  7217. ->setSubject("班级信息")
  7218. ->setDescription("导出班级信息")
  7219. ->setKeywords("excel")
  7220. ->setCategory("result file");
  7221. foreach($choose_type_arr as $key=>$val){
  7222. $objPHPExcel->getActiveSheet()->getColumnDimension(numToLetter($key+1))->setWidth(30);
  7223. $objPHPExcel->setActiveSheetIndex(0)->setCellValue(numToLetter($key+1).'1', $excel_show_title[$val]);
  7224. }
  7225. $i = 2;
  7226. foreach($class_data as $k=>$v){
  7227. foreach($choose_type_arr as $key=>$val){
  7228. $objPHPExcel->getActiveSheet(0)->setCellValue(numToLetter($key+1) . $i, $v[$excel_show_msg[$val]]);
  7229. }
  7230. $i++;
  7231. }
  7232. $objPHPExcel->setActiveSheetIndex(0);
  7233. ob_end_clean(); // Added by me
  7234. header("Accept-Ranges:bytes");
  7235. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  7236. header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"');
  7237. header('Cache-Control:max-age=0');
  7238. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  7239. $objWriter->save('php://output');
  7240. exit;
  7241. }else{
  7242. Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index'));
  7243. }
  7244. }
  7245. }