12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315 |
- <?php
- /**
- * 班级管理控制器类
- * @author jiangfei
- * @date 2015-09-22 10:50:00
- * @company 上海风车教育有限公司.
- */
- class ClassesController extends Controller{
- // 班级等级水平
- protected $class_level = array(
- "A" => array('A',0,59),
- "B" => array('B',60,85),
- "C" => array('C',86,100)
- );
- //protected $material_url = 'http://wybrain.xueping365.com/rest/textbook/tree';
- //protected $material_param = 'subjectId=3&depth=3';
- // 首页
- public function actionIndex(){
- $data = array();
- $realname = Req::get("realname");
- $grade_id = Req::get("grade_id");
- $arts_science = Req::get("arts_science");
- $class_type = (int)Req::get("class_type"); //班级类型 1行政,2教学
- $subject_id = (int)Req::get("subject_id");
- $show_type = (int)Req::get('show_type'); //是否显示隐藏班级
- if(!$show_type){
- $show_type=0;
- }else{
- $show_type=1;
- }
- $teachers = array();
- // 获取所有学期
- $criteria = new CDbCriteria;
- $criteria->limit = 10;
- $criteria->order = "create_time desc";
- $allSemester = Semester::model()->findAll($criteria);
- if(!$class_type || !in_array($class_type,array(1,2))) $class_type=1;
- $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
- if(empty($smid)){
- $semeseter_id = $this->semesterId;
- }
- else{
- $semeseter_id = $smid;
- }
- $semesterId = $semeseter_id;
- //走班学科筛选
- $classIds=array(); //学科筛选班级id
- if($class_type==2 && $subject_id){
- $classIds=$this->schoolManager->getClassIdBySubjectId($subject_id,$semesterId);
- }
- // 判断是否教员组长
- if($semesterId){
- if($grade_id)
- {
- $con[] = "seme.semester_id = '{$semesterId}'";
- $con[] = "c.grade=".$grade_id;
- }else
- {
- $con[] = "seme.semester_id = '{$semesterId}'";
- }
- if($realname)
- {
- // $_class_ids = $this->schoolManager->getTeachersByteacherName($realname);
- //
- // if($class_type==2 && $subject_id && $classIds){
- // $classIds=array_intersect($classIds,$_class_ids);
- // }elseif($_class_ids){
- // $con[] = "c.class_id in (".implode(',',$_class_ids).")";
- // }else{
- // $con[] = "c.class_id in (0)";
- // }
- $con[] = "c.class_name like '%".$realname."%'";
- }
- if($classIds){
- $con[] = "c.class_id in (".implode(',',$classIds).")";
- }
- if($arts_science){
- $con[] = "c.arts_science=".$arts_science;
- }
- $con[]=" c.class_type=".$class_type;
- $con[]=" c.is_hide=".$show_type;
- $rs = $this->schoolManager->getClassesDetailListre($con,9);
- }
- // debug($rs["rs"]);
- if($rs["rs"]){
- $classesIds = array();
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
- if($class_data)
- {
- foreach($class_data as $class){
- $classesIds[] = $class->class_id;
- }
- }
- $teachers = $this->schoolManager->getClassesTeachers($classesIds);
- if(!$teachers && false){
- $rs["rs"] = array();
- }else{
- foreach($rs["rs"] as $key => $class){
- if(isset($teachers[(string)$class["class_id"]]) && !empty($teachers[(string)$class["class_id"]]))
- {
- $rs["rs"][$key]["teachers"] = implode(',',$teachers[(string)$class["class_id"]]);
- }else
- {
- $rs["rs"][$key]["teachers"] = '';
- // unset($rs["rs"][$key]);
- }
- /*foreach($teachers as $teacher){
- if($teacher["class_id"] == $class["class_id"]){
- $rs["rs"][$key]["teachers"] = $teacher["teachers_names"];
- }
- }*/
- //判断班主任
- if($class['teacher_id']){
- $teacherInfo = Teacher::model()->find('teacher_id=:tid', array(':tid' => $class['teacher_id']));
- $rs["rs"][$key]["bzr"]=$teacherInfo;
- }
- }
- }
- }
- $currSemester = $this->schoolManager->getCurrSemester();
- /**
- * 转班
- */
- $_semesters = $this->getFinishSemesters();
- if($_semesters)
- {
- $data['_semester'] = $_semesters;
- $_currClass = $this->schoolManager->getSemesterClasses($currSemester['semester_id']);
- if($_currClass)
- {
- foreach($_currClass as $v)
- {
- $data['_currClass'][$v['grade']][$v['class_id']] = $v;
- }
- }
- if(!empty($_semesters['semesters']))
- {
- $data['_fluClass'] = $this->schoolManager->getSemesterClassesStudent($_semesters['semesters']->semester_id);
- }else
- {
- $data['_fluClass'] = array();
- }
- }
- $data["class_type"] = $class_type;
- if($class_type==2 ){
- $setting=$this->schoolManager->getClassShift($this->semesterId);
- if(!$setting){
- //进入走班说明页面
- return $this->render('explain',$data);
- }
- }
- if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
- $data['subjects']=Yii::app()->params['subjectId'];
- unset($data['subjects'][6]);
- unset($data['subjects'][18]);
- unset($data['subjects'][19]);
- unset($data['subjects'][51]);
- if(isset($data['subjects'][20])) unset($data['subjects'][20]);
- }
- $data["grade_id"] = $grade_id;
- $data["arts_science"] = $arts_science;
- $data["realname"] = $realname;
- $data["currSemester"] = $currSemester;
- $data['yearsList'] = $rs["rs"];
- $data['pages'] = $rs["pager"];
- $data['page_total'] = $rs["pager"]->rowsCount;
- //$data['allSemester'] = $allSemester;
- $data['semeseter_id'] = $semeseter_id;
- $data["semesters"] = $allSemester;
- $data["semesterId"] = $semesterId;
- $data["class_type"] = $class_type;
- $data["show_type"] = $show_type;
- $data["subject_id"] = $subject_id;
- $data["thisSemester"] = $this->schoolManager->getSemester($semesterId);
- $model = new Model();
- $data["model"] = $model;
- //unset($classList,$classInfo);
- // var_dump($rs["pager"]);exit;
- $this->render('index',$data);
- }
- protected function getFinishSemesters()
- {
- $data = array();
- $currSemester = $this->schoolManager->getCurrSemester();
- $criteria = new CDbCriteria;
- $criteria->addCondition('end_time <= :start_time');
- $criteria->params[':start_time'] = $currSemester['start_time'];
- $criteria->limit = 1;
- $criteria->order = "end_time desc";
- $_allSemester = Semester::model()->find($criteria);
- $data['currSemester'] = $currSemester;
- $data['semesters'] = $_allSemester;
- return $data;
- }
- //转入单个班
- public function actionInto_alone_class()
- {
- if (Yii::app()->request->getIsPostRequest()) {
- $alone_one_f_class = Req::post("alone_one_f_class");
- $alone_one_c_class = Req::post("alone_one_c_class");
- $alone_two_f_class = Req::post("alone_two_f_class");
- $alone_two_c_class = Req::post("alone_two_c_class");
- $alone_three_f_class = Req::post("alone_three_f_class");
- $alone_three_c_class = Req::post("alone_three_c_class");
- $transfer_class = array();
- $msg = '';
- $old_class_id = '';
- $new_class_id = '';
- if($alone_one_c_class && $alone_one_f_class)
- {
- $transfer_class[$alone_one_f_class] = $alone_one_c_class;
- $old_class_id = $alone_one_f_class;
- $new_class_id = $alone_one_c_class;
- }
- if($alone_two_f_class && $alone_two_c_class)
- {
- $transfer_class[$alone_two_f_class] = $alone_two_c_class;
- $old_class_id = $alone_two_f_class;
- $new_class_id = $alone_two_c_class;
- }
- if($alone_three_f_class && $alone_three_c_class)
- {
- $transfer_class[$alone_three_f_class] = $alone_three_c_class;
- $old_class_id = $alone_three_f_class;
- $new_class_id = $alone_three_c_class;
- }
- if($transfer_class)
- {
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '单个级转移',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $msg = $this->gotoClasses($transfer_class,array($old_class_id),array($new_class_id));
- if($msg)
- {
- $str = '';
- $i=0;
- foreach($msg as $k=>$v)
- {
- $str .= (++$i).'、'.$v.PHP_EOL;
- }
- Yii::app()->jump->setErrorWait(20);
- if($i>2)
- {
- Yii::app()->jump->setHeight(100);
- }else
- {
- Yii::app()->jump->setHeight((100+($i*40)));
- }
- Yii::app()->jump->error($str);exit;
- }else
- {
- Yii::app()->jump->success('转班成功<br>',Yii::app()->createUrl('classes/index'));exit;
- }
- }else
- {
- Yii::app()->jump->error('尚未选择班级!');
- }
- }
- }
- //转多个班
- public function actionInto_multi_class()
- {
- if (Yii::app()->request->getIsPostRequest()) {
- $one_class = Req::post("one_class");
- $two_class = Req::post("two_class");
- $three_class = Req::post("three_class");
- $flags = 0;
- $transfer_class = array();
- $old_class_id = array();
- $new_class_id = array();
- if($one_class)
- {
- foreach($one_class as $k=>$v)
- {
- if($v)
- {
- if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
- {
- Yii::app()->jump->error('不能重复的班级同一班级!');
- }else
- {
- $old_class_id[$v] = $v;
- }
- $transfer_class[$v] = $k;
- }
- if($k)
- {
- $new_class_id[$k] = $k;
- }
- }
- }
- if($two_class)
- {
- foreach($two_class as $k=>$v)
- {
- if($v)
- {
- if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
- {
- Yii::app()->jump->error('不能重复的班级同一班级!');
- }else
- {
- $old_class_id[$v] = $v;
- }
- $transfer_class[$v] = $k;
- }
- if($k)
- {
- $new_class_id[$k] = $k;
- }
- }
- }
- if($three_class)
- {
- foreach($three_class as $k=>$v)
- {
- if($v)
- {
- if(isset($old_class_id[$v]) && !empty($old_class_id[$v]))
- {
- Yii::app()->jump->error('不能重复的班级同一班级!');
- }else
- {
- $old_class_id[$v] = $v;
- }
- $transfer_class[$v] = $k;
- }
- if($k)
- {
- $new_class_id[$k] = $k;
- }
- }
- }
- if(!$transfer_class)
- {
- Yii::app()->jump->error('尚未选择班级!');
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '多班级转移',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $msg = $this->gotoClasses($transfer_class,$old_class_id,$new_class_id);
- if($msg)
- {
- $str = '';
- $i=0;
- foreach($msg as $k=>$v)
- {
- $str .= (++$i).'、'.$v.PHP_EOL;
- }
- Yii::app()->jump->setErrorWait(20);
- if($i>2)
- {
- Yii::app()->jump->setHeight(100);
- }else
- {
- Yii::app()->jump->setHeight((100+($i*40)));
- }
- Yii::app()->jump->error($str);exit;
- }else
- {
- Yii::app()->jump->success('转班成功<br>',Yii::app()->createUrl('classes/index'));exit;
- }
- }
- }
- /**
- * @param $class_ids 当前学期班级信息
- * @param $old_class_ids 转入班级信息
- */
- public function gotoClasses($class_ids,$old_class_ids,$new_class_ids)
- {
- $c_class_ids = array();
- ini_set('memory_limit','518M');
- //获取当前学期所有学生信息
- $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
- if(!$c_class_data)
- {
- Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
- }
- foreach($c_class_data as $v)
- {
- $c_class_ids[$v['class_id']] = $v['class_id'];
- }
- $new_class_student = $this->getInClassStudents($c_class_ids);//新学生
- $old_class_student = $this->getInClassStudents($old_class_ids);//旧学生
- $_err = array();
- if($old_class_student)
- {
- if(!empty($new_class_student['student_names']) && !empty($new_class_student['student_ids']))
- {
- //验证学生姓名是否已存在
- if(!empty($old_class_student['student_names']))
- {
- foreach($old_class_student['student_names'] as $old_student_id => $v)
- {
- $student_repeat_found_key=array_search($v,$new_class_student['student_names'],true);
- if($student_repeat_found_key){
- if(!$new_class_student['id_number'][$student_repeat_found_key] && !$old_class_student['id_number'][$old_student_id]) {
- $_err[] = $v . '学生已存在';
- }elseif(strcmp($new_class_student['id_number'][$student_repeat_found_key],$old_class_student['id_number'][$old_student_id])==0){
- $_err[] = $v.'学生已存在';
- }elseif(strcmp($old_student_id,$student_repeat_found_key)==0){
- $_err[] = $v.'学生已存在';
- }
- }
- }
- }
- //验证学生学校准考证号
- if(!empty($old_class_student['school_student_cards']))
- {
- foreach($old_class_student['school_student_cards'] as $key => $v)
- {
- if(array_search($v,$new_class_student['school_student_cards'],true))
- {
- $_err[] = $old_class_student['student_names'][$key].'学生学校准考证号已存在';
- }
- }
- }
- if(empty($_err))
- {
- //写入数据
- //$transaction = StudentInfo::model()->dbConnection->beginTransaction();
- $transaction=$this->sConn->beginTransaction();
- try {
- /*
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$old_class_student['student_ids']);
- StudentInfo::model()->deleteAll($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$old_class_student['student_ids']);
- StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$old_class_student['student_ids']);
- $criteria->addInCondition('class_id',$new_class_ids);
- StudentInfo::model()->deleteAll($criteria);
- */
- $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")";
- $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";
- //添加学生
- $i = 0;
- $serial_number = 0;
- //组装sql
- $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";
- $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES";
- $tempInsertStudentInfoData=array();
- $tempInsertStudentClassData=array();
- $SqlArr=array();
- foreach($old_class_student['student_info'] as $k => $v)
- {
- $tempStudentInfoData=array();
- $tempStudentClassData=array();
- $tempStudentInfoData['student_id']="'".$k."'";
- $tempStudentInfoData['realname']= "'".$v->realname."'";
- $tempStudentInfoData['sex']="'".$v->sex."'";
- $tempStudentInfoData['school_id']="'".$this->schoolId."'";
- 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]]))
- {
- $class_id = $class_ids[$old_class_student['student_class_ids'][$k]];
- }else
- {
- $class_id = -2;
- }
- $tempStudentInfoData['class_id']="'".$class_id."'";
- $tempStudentInfoData['family_tel']="'".$v->family_tel."'";
- $tempStudentInfoData['telephone']="'".$v->telephone."'";
- $tempStudentInfoData['student_phone']="'".$v->student_phone."'";
- $tempStudentInfoData['picture']="'".$v->picture."'";
- $tempStudentInfoData['signature']="'".$v->signature."'";
- $tempStudentInfoData['is_outer']="'".$v->is_outer."'";
- $tempStudentInfoData['add_time']="'".$v->add_time."'";
- $tempStudentInfoData['update_time']="'".$v->update_time."'";
- $tempStudentInfoData['level']="'".$v->level."'";
- $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'";
- $tempStudentInfoData['game_stars']="'".$v->game_stars."'";
- $tempStudentInfoData['id_number']="'".$v->id_number."'";
- $tempStudentInfoData['field_1']="'".$v->field_1."'";
- $tempStudentInfoData['field_2']="'".$v->field_2."'";
- $tempStudentInfoData['field_3']="'".$v->field_3."'";
- $tempStudentInfoData['field_4']="'".$v->field_4."'";
- $tempStudentInfoData['field_5']="'".$v->field_5."'";
- $tempInsertStudentInfoData[$k]=$tempStudentInfoData;
- // 创建学生与班级关联关系
- $class_student = $old_class_student['class_student'][$k];
- $tempStudentClassData['student_id']="'".$k."'";
- 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]]))
- {
- $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]];
- }else
- {
- $studentClassId = -2;
- }
- $tempStudentClassData['class_id']="'".$studentClassId."'";
- 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]]]))
- {
- $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]];
- }else
- {
- $serial_number = 0;
- }
- $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'";
- $tempStudentClassData['userno']="'".$class_student->userno."'";
- $tempStudentClassData['update_time']=time();
- $tempStudentClassData['status']=0;
- $tempInsertStudentClassData[]=$tempStudentClassData;
- $i++;
- if($i%200==0){
- $TempData1=array();
- $TempData2=array();
- foreach ($tempInsertStudentInfoData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
- }
- foreach ($tempInsertStudentClassData as $item){
- $TempData2[]="(".implode(',',$item).")";
- }
- if($TempData2){
- $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2);
- }
- $tempInsertStudentInfoData=array();
- $tempInsertStudentClassData=array();
- }
- }
- if($tempInsertStudentInfoData){
- $TempData1=array();
- foreach ($tempInsertStudentInfoData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
- }
- }
- if($tempInsertStudentClassData){
- $TempData1=array();
- foreach ($tempInsertStudentClassData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1);
- }
- }
- if($SqlArr){
- $this->sConn->createCommand($deleteSql)->execute();
- $this->sConn->createCommand($updateSql)->execute();
- foreach ($SqlArr as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index'));
- }
- }else
- {
- //错误处理
- return $_err;
- }
- }else
- {
- //新学期
- //写入数据
- //$transaction = StudentInfo::model()->dbConnection->beginTransaction();
- $transaction=$this->sConn->beginTransaction();
- try {
- /*
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$old_class_student['student_ids']);
- StudentInfo::model()->deleteAll($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$old_class_student['student_ids']);
- StudentToClass::model()->updateAll(array('status'=>1,'update_time'=>time(),'operation'=>3),$criteria);
- */
- $deleteSql="delete from `student_info` where student_id in(".implode(',',$old_class_student['student_ids']).")";
- $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 ";
- //添加学生
- $serial_number = 0;
- $i = 0;
- //组装sql
- $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";
- $insertStudentClassSql="Insert into `student_class_relation`(`student_id`,`class_id`,`serial_number`,`userno`,`update_time`,`status`) VALUES";
- $tempInsertStudentInfoData=array();
- $tempInsertStudentClassData=array();
- $SqlArr=array();
- foreach($old_class_student['student_info'] as $k => $v)
- {
- $tempStudentInfoData=array();
- $tempStudentClassData=array();
- $tempStudentInfoData['student_id']="'".$k."'";
- $tempStudentInfoData['realname']= "'".$v->realname."'";
- $tempStudentInfoData['sex']="'".$v->sex."'";
- $tempStudentInfoData['school_id']="'".$this->schoolId."'";
- $userModel = new StudentInfo();
- $userModel->student_id = $k;
- $userModel->realname = $v->realname;
- $userModel->sex = $v->sex;
- $userModel->school_id = $this->schoolId;
- 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]]))
- {
- $class_id = $class_ids[$old_class_student['student_class_ids'][$k]];
- }else
- {
- $class_id= -2;
- }
- $tempStudentInfoData['class_id']="'".$class_id."'";
- $tempStudentInfoData['family_tel']="'".$v->family_tel."'";
- $tempStudentInfoData['telephone']="'".$v->telephone."'";
- $tempStudentInfoData['student_phone']="'".$v->student_phone."'";
- $tempStudentInfoData['picture']="'".$v->picture."'";
- $tempStudentInfoData['signature']="'".$v->signature."'";
- $tempStudentInfoData['is_outer']="'".$v->is_outer."'";
- $tempStudentInfoData['add_time']="'".$v->add_time."'";
- $tempStudentInfoData['update_time']="'".$v->update_time."'";
- $tempStudentInfoData['level']="'".$v->level."'";
- $tempStudentInfoData['ave_score_rate']="'".$v->ave_score_rate."'";
- $tempStudentInfoData['game_stars']="'".$v->game_stars."'";
- $tempStudentInfoData['id_number']="'".$v->id_number."'";
- $tempStudentInfoData['field_1']="'".$v->field_1."'";
- $tempStudentInfoData['field_2']="'".$v->field_2."'";
- $tempStudentInfoData['field_3']="'".$v->field_3."'";
- $tempStudentInfoData['field_4']="'".$v->field_4."'";
- $tempStudentInfoData['field_5']="'".$v->field_5."'";
- $tempInsertStudentInfoData[$k]=$tempStudentInfoData;
- // 创建学生与班级关联关系
- $class_student = $old_class_student['class_student'][$k];
- $tempStudentClassData['student_id']="'".$k."'";
- $studentClass = new StudentToClass();
- $studentClass->student_id = $k;
- 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]]))
- {
- $studentClassId = $class_ids[$old_class_student['student_class_ids'][$k]];
- }else
- {
- $studentClassId = -2;
- }
- $tempStudentClassData['class_id']="'".$studentClassId."'";
- 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]]]))
- {
- $serial_number = $new_class_student['serial_number'][$class_ids[$old_class_student['student_class_ids'][$k]]];
- }else
- {
- $serial_number = 0;
- }
- $tempStudentClassData['serial_number']="'".($serial_number +$i+ 1)."'";
- $tempStudentClassData['userno']="'".$class_student->userno."'";
- $tempStudentClassData['update_time']=time();
- $tempStudentClassData['status']=0;
- $tempInsertStudentClassData[]=$tempStudentClassData;
- $i++;
- if($i%200==0){
- $TempData1=array();
- $TempData2=array();
- foreach ($tempInsertStudentInfoData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
- }
- foreach ($tempInsertStudentClassData as $item){
- $TempData2[]="(".implode(',',$item).")";
- }
- if($TempData2){
- $SqlArr[]=$insertStudentClassSql.implode(',',$TempData2);
- }
- $tempInsertStudentInfoData=array();
- $tempInsertStudentClassData=array();
- }
- }
- if($tempInsertStudentInfoData){
- $TempData1=array();
- foreach ($tempInsertStudentInfoData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentSql.implode(',',$TempData1);
- }
- }
- if($tempInsertStudentClassData){
- $TempData1=array();
- foreach ($tempInsertStudentClassData as $item){
- $TempData1[]="(".implode(',',$item).")";
- }
- if($TempData1){
- $SqlArr[]=$insertStudentClassSql.implode(',',$TempData1);
- }
- }
- if($SqlArr){
- $this->sConn->createCommand($deleteSql)->execute();
- $this->sConn->createCommand($updateSql)->execute();
- foreach ($SqlArr as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error('转班失败',Yii::app()->createUrl('classes/index'));
- }
- }
- }
- return false;
- }
- public function gotoClass($class_ids)
- {
- $_msg = array();
- if($class_ids)
- {
- /**
- * 获取当前学期所有班级
- */
- $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
- $c_class_ids = array();
- if(!$c_class_data)
- {
- Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
- }
- foreach($c_class_data as $v)
- {
- $c_class_ids[$v['class_id']] = $v['class_id'];
- }
- $new_class_student = $this->getInClassStudents($c_class_ids);
- foreach($class_ids as $k => $v)
- {
- /**
- * 获取转入班的学生
- */
- /**
- * 获取转出班的学生
- */
- $old_class_student = $this->getClassStudents($k);
- /**
- * 验证重名
- */
- $_err = $this->StudentCompare($old_class_student,$new_class_student);
- if($_err)
- {
- $str = '';
- $class_data = $this->schoolManager->getClassByClassIds(array($v,$k));
- if($class_data){
- foreach($class_data as $c)
- {
- if($k==$c['class_id'])
- {
- $str .= $c['class_name'];
- }
- if($v==$c['class_id'])
- {
- $str .= '转入'.$c['class_name'].'失败,请查看学生姓名重名,学校准考完证号重复';
- }
- }
- $_msg[$v] = array(
- 'msg'=>$str
- );
- }else
- {
- $_msg[$v] = array(
- 'msg'=>'转班失败'
- );
- }
- continue ;
- }else
- {
- $serial_number = 0;
- $_student_class_data = SStudentClassRelation::model()->find(array(
- 'select' => 'serial_number',
- 'order' => 'serial_number desc',
- 'condition' => 'class_id=:class_id and status=:status',
- 'limit' => 1,
- 'params' => array(':class_id'=>$v,':status'=>0)
- ));
- if($_student_class_data)
- {
- if($_student_class_data->serial_number)
- {
- $serial_number = $_student_class_data->serial_number;
- }
- }
- //插入学生
- if($old_class_student)
- {
- $get_array = isset($old_class_student['student_ids'])?$old_class_student['student_ids']:array();
- if($get_array)
- {
- $transaction = StudentInfo::model()->dbConnection->beginTransaction();
- try {
- foreach ($get_array as $student_id) {
- $serial_number = $serial_number+1;
- // 修改当前学生所在的班级
- $count = StudentInfo::model()->updateAll(array('class_id'=>$v),'student_id=:sid',array(':sid'=>$student_id));
- //更新当前学生之前所在班级状态
- 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));
- // 建立当前学生新班级对应记录
- $student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$student_id,':class_id'=>$v));
- if($student_class){
- if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id]))
- {
- $userno = $old_class_student['student_userno'][$student_id];
- }else
- {
- $userno = '';
- }
- 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));
- }else{
- $newModel = new StudentToClass();
- $newModel->class_id = $v;
- $newModel->student_id = $student_id;
- $newModel->serial_number = $serial_number;
- if(isset($old_class_student['student_userno'][$student_id]) && !empty($old_class_student['student_userno'][$student_id]))
- {
- $newModel->userno = $old_class_student['student_userno'][$student_id];
- }else
- {
- $newModel->userno = '';
- }
- $newModel->update_time = time();
- $newModel->save();
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- $_msg[$v] = array(
- 'msg'=>'学生写入失败'
- );
- }
- }else
- {
- $_msg[$v] = array(
- 'msg'=>'学生写入失败'
- );
- }
- }else
- {
- $_msg[$v] = array(
- 'msg'=>'此班无学生'
- );
- }
- }
- }
- }
- return $_msg;
- }
- // 创建班级
- public function actionAdd(){
- $toFiltMaterialsIds = array(13, 14, 15, 16);
- $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
- checkAuthority(2); // 非当前使用学期无法操作
- $data = array();
- $teachers = $this->schoolManager->getTeachers();
- $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- if (Yii::app()->request->getIsPostRequest()){
- $class_name = trim(Req::post("class_name"));
- $mid_array = array();
- $subjectId = 0;
- $material_id = 0;
- $coach_id = Req::post("coach_id");
- $period = (int)Req::post("period");
- $teachersIds = Req::post("teacher_ids");
- $subject_ids = Req::post("subject_ids");
- $bzr_id=Req::post("bzrId"); //班主任id
- $levelName = Req::post("level_name");
- if(!$levelName) $levelName='A';
- $level = array($levelName => null);
- $grade = Req::post("grade");
- $arts_science = Req::post("arts_science");
- $_subject_ids = array();
- if($subject_ids)
- {
- foreach($subject_ids as $v)
- {
- if(in_array($v,$_subject_ids))
- {
- Yii::app()->jump->error('班级不能增加相同的学科教师');
- }
- $_subject_ids[] = $v;
- }
- }
- if(is_array($teachersIds)){
- foreach($teachersIds as $key => $val){
- if(empty($val) ||(is_string($val) && trim($val) == ""))
- unset($teachersIds[$key]);
- }
- }
- if(!array_intersect_key($level, $this->class_level))
- $levelName = "";
- if (empty($class_name)){
- Yii::app()->jump->error('班级信息未填写完整!');
- }
- else if(empty($coach_id)){
- Yii::app()->jump->error('未选择助教!');
- }
- else if(!$teachersIds){
- Yii::app()->jump->error('未选择执教老师!');
- }
- else if(!$grade){
- Yii::app()->jump->error('未选择年级!');
- }
- $classesModel = new ClassModel();
- // 判断当前学期当前班级是否已添加
- if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
- {
- Yii::app()->jump->error('该学期下已存在同名班级!');
- }
- // 当前班级唯一id
- //$classId = getUUID();
- $classId=getUniqueId($this->schoolId);
- if (empty($classId)) {
- Yii::app()->jump->error('创建班级失败!');
- }
- $improve_book_type = 0;
- $wb_isp_version = 0;
- if(Req::post("improve_book_type")==0)
- {
- $improve_book_type = 0;
- $wb_isp_version = 0;
- }
- if(Req::post("improve_book_type")==1)
- {
- $improve_book_type = 1;
- $wb_isp_version = 0;
- }
- if(Req::post("improve_book_type")==3)
- {
- $improve_book_type = 0;
- $wb_isp_version = 1;
- }
- if(Req::post("improve_book_type")==4)
- {
- $improve_book_type = 1;
- $wb_isp_version = 1;
- }
- // 创建班级相关事务
- //$transaction = Yii::app()->db->beginTransaction();
- $transaction = $classesModel->dbConnection->beginTransaction();
- try{
- //创建班级与老师关系
- if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array(
- 'class_id' => $classId,
- 'class_name' => $class_name,
- 'level' => Char::letterToNum($levelName, 1),
- 'grade' => $grade,
- 'semester_id' => $semesterId,
- 'period' => $period,
- 'add_time' => time(),
- 'coach_id' => $this->coachId,
- 'wrong_book_type' => Req::post("wrong_book_type"),
- 'improve_book_type' => $improve_book_type,
- 'wb_isp_version' => $wb_isp_version,
- 'arts_science'=>$arts_science,
- 'teacher_id'=>$bzr_id
- )))
- throw new CException("创建班级和老师关系失败");
- $modulesIds = array();
- if($mid_array){
- //创建教材模块与班级关系表
- foreach($mid_array as $lp){
- if (empty($lp)) throw new CException('创建班级失败!');
- $lp = (int)$lp;
- $modulesIds[] = $lp;
- }
- $modulesIds = implode(",", $modulesIds);
- }
- if(!$modulesIds)
- $modulesIds = "";
- if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds))) {
- throw new CException('创建失败!');
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error($e->getMessage());
- }
- if($this->schoolManager->isCurrentSemester($semesterId))
- $this->redirect(array('classes/index'));
- else
- $this->redirect(array("classes/index?semesterId={$semesterId}"));
- }
- unset(Yii::app()->session['school_material']);
- // 获取所有教材及其模块
- $get_material = Yii::app()->session['school_material'];
- if (empty($get_material)) {
- //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']);
- $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3");
- $json_material = json_decode($json_material, true);
- $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true));
- $session_material = $json_material;
- //$session_material = json_decode($json_material,true);
- if (!empty($session_material) && !isset($session_material['error'])) {
- Yii::app()->session['school_material'] = $session_material;
- $get_material = $session_material;
- }
- unset($json_material,$session_material);
- }
- if($get_material){
- foreach($get_material as $key => $material){
- if(isset($material["modules"])){
- foreach($material["modules"] as $moduleKey => $module){
- //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
- if(empty($module["chapters"])){
- unset($get_material[$key]["modules"][$moduleKey]);
- }
- }
- }
- if(empty($get_material[$key]["modules"]))
- unset($get_material[$key]);
- }
- }
- $data['material'] = $get_material;
- // 获取当前学校所有助教
- $coachList = array();
- if(!isset(Yii::app()->session['crmUserInfo']))
- {
- $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- if (empty($coachList)) {
- Yii::app()->jump->error('系统未找到助教,请联系管理员!');
- }
- }else
- {
- $coachList = array(Yii::app()->session['crmUserInfo']);
- }
- unset($transaction);
- if( Yii::app()->params['section']==1){
- $firstSubjectId=3;
- }else{
- $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject);
- }
-
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId));
- $model = new Model();
- //$data['semester'] = $semester;
- $data['coachList'] = $coachList;
- $data["teachers"] = $teachers;
- $data["teacher_data"] = $teacher_data;
- $data["classLevels"] = $this->class_level;
- $data["semesters"] = $semesters;
- $data["semesterId"] = $semesterId;
- $data["model"] = $model;
- $data["thisSemester"] = $thisSemester;
- $this->render('add',$data);
- }
- //更新班级排序
- public function actionSaveClassSort()
- {
- $classSort = Req::post('classSort');
- if(!$classSort){
- returnMsg(0,'排序参数错误');
- }
- $sql = "UPDATE class SET sort = CASE class_id";
- $class_ids = array();
- foreach ($classSort as $k=>$v){
- $temp = explode('_', $v);
- $sort = intval($temp[1])>0?intval($temp[1]):0;
- $sql .= " WHEN {$temp[0]} THEN {$sort}";
- $class_ids[] = $temp[0];
- }
- if(!$class_ids){
- returnMsg(0,'参数错误');
- }
- $class_id = implode(',', $class_ids);
- $sql .= " END ";
- $sql .= " WHERE class_id IN ({$class_id})";
- $result = ClassModel::model()->saveClassSort($sql);
- if ($result !==false){
- returnMsg(1,'修改成功');
- }else{
- returnMsg(0,'修改失败');
- }
- }
- public function actionVerifyclass_name()
- {
- $class_name = trim(Req::post("class_name"));
- if (empty($class_name)){
- echo json_encode(array('status'=>0));exit;
- }
- $is_edit = trim(Req::post("is_edit"));
- if($is_edit)
- {
- $class_ids = array();
- $class_id = trim(Req::post("class_id"));
- $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
- $_class_data = ClassModel::model()->findAll('semester_id=:seid and class_name=:class_name',array(':seid'=>$this->semesterId,':class_name'=>$class_name));
- if(!$class_data)
- {
- echo json_encode(array('status'=>0));exit;
- }
- if(count($_class_data)>1)
- {
- echo json_encode(array('status'=>0));exit;
- }
- $class_ids[$class_id] = $class_id;
- if($_class_data && !isset($class_ids[$_class_data[0]->class_id]))
- {
- echo json_encode(array('status'=>0));exit;
- }elseif($_class_data && isset($class_ids[$_class_data[0]->class_id]))
- {
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>1));exit;
- }
- $classesModel = new ClassModel();
- if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$this->semesterId,':cname'=>$class_name)))
- {
- echo json_encode(array('status'=>0));exit;
- }
- echo json_encode(array('status'=>1));exit;
- }
- // 修改班级信息
- public function actionEdit(){
- $toFiltMaterialsIds = array(13, 14, 15, 16);
- $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
- //checkAuthority(2); // 非当前使用学期无法操作
- $classId = safe_replace(Yii::app()->request->getQuery('cid'));
- if (empty($classId)) {
- Yii::app()->jump->error('操作失败!');
- }
- // 获取当前学校所有助教
- $coachList = array();
- if(!isset(Yii::app()->session['crmUserInfo']))
- {
- $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- if (empty($coachList)) {
- Yii::app()->jump->error('系统未找到助教,请联系管理员!');
- }
- }else
- {
- $coachList = array(Yii::app()->session['crmUserInfo']);
- }
- $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId);
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- // 班级信息
- //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId));
- $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ");
- $grade = $classInfo->grade;
- $teachers = $this->schoolManager->getTeachers();
- $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到该班级信息!');
- }
- // 当前班级教练信息
- $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ");
- // 当前班级教材模块
- $module = $this->sConn->createCommand()->select("*")->from("class_subject_relation")->where("class_id = '{$classId}'")->queryRow();
- $module_array = array();
- if($module && $module["module_ids"]){
- $module_array = explode(",", $module["module_ids"]);
- }
- if (Yii::app()->request->getIsPostRequest()){
- /*$class_name = safe_replace($_POST['class_name']);
- $mid_array = $_POST['mid'];
- $material_id = safe_replace($_POST['material_id']);
- $coach_id = safe_replace($_POST['coach_id']);
- $period = intval($_POST['period']);*/
- $class_name = trim(Req::post("class_name"));
- $improve_book_type = 0;
- $wb_isp_version = 0;
- $bzr_id=Req::post("bzrId"); //班主任id
- if(Req::post("improve_book_type")==0)
- {
- $improve_book_type = 0;
- $wb_isp_version = 0;
- }
- if(Req::post("improve_book_type")==1)
- {
- $improve_book_type = 1;
- $wb_isp_version = 0;
- }
- if(Req::post("improve_book_type")==3)
- {
- $improve_book_type = 0;
- $wb_isp_version = 1;
- }
- if(Req::post("improve_book_type")==4)
- {
- $improve_book_type = 1;
- $wb_isp_version = 1;
- }
- //$mid_array = Req::post("mid");
- //$subjectId = Req::post("subject_id");
- //$material_id = Req::post("material_id");
- $mid_array = array();
- $subjectId = 0;
- $material_id = 0;
- $coach_id = Req::post("coach_id");
- $period = Req::post("period");
- $levelName = Req::post("level_name");
- $level = array($levelName => null);
- $teachersIds = Req::post("teacher_ids");
- $subject_ids = Req::post("subject_ids");
- $arts_science= Req::post("arts_science");
- $_subject_ids = array();
- if($subject_ids)
- {
- foreach($subject_ids as $v)
- {
- if(in_array($v,$_subject_ids))
- {
- Yii::app()->jump->error('班级不能增加相同的学科教师');
- }
- $_subject_ids[] = $v;
- }
- }
- if(is_array($teachersIds)){
- foreach($teachersIds as $key => $val){
- if(empty($val) ||(is_string($val) && trim($val) == ""))
- unset($teachersIds[$key]);
- }
- }
- $grade = Req::post("grade");
- //$semesterId = Req::post("semesterId");
- if(!array_intersect_key($level, $this->class_level))
- $levelName = "";
- if(!$levelName)
- Yii::app()->jump->error('层级只能是A,B,C层!');
- if (empty($class_name) || empty($coach_id) || !$teachersIds){
- Yii::app()->jump->error('班级信息未填写完整!');
- }
- $classesModel = new ClassModel();
- // 判断当前学期当前班级是否已添加
- if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
- {
- 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)))
- Yii::app()->jump->error('您选择的学期已存在同名班级!');
- }
- // 创建班级相关事务
- //$transaction = Yii::app()->db->beginTransaction();
- $classInfo = ClassModel::model()->find("class_id = '{$classId}'");
- $transaction = $classInfo->dbConnection->beginTransaction();
- try {
- if($classInfo->class_name != $class_name)
- $classInfo->class_name = $class_name;
- //$classInfo->period = $period;
- //$classInfo->grade = $grade;
- //$classInfo->semester_id = $semesterId;
- $classInfo->level = Char::letterToNum($levelName, 1);
- $classInfo->wrong_book_type = Req::post("wrong_book_type");
- $classInfo->improve_book_type = $improve_book_type;
- $classInfo->wb_isp_version = $wb_isp_version;
- $classInfo->teacher_id = $bzr_id;
- $classInfo->arts_science = $arts_science;
- if(!$classInfo->save()){
- throw new CException('更新失败!');
- }
- if($classInfo->coach_id != $coach_id){
- if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) {
- throw new CException('班级更新失败!');
- }
- }
- if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId))
- throw new CException("班级老师更新失败");
- // 是否修改教材模块
- $get_array = array_diff($mid_array, $module_array);
- $modulesIds = array_diff($module_array, $mid_array);
- if ((!empty($get_array) || !empty($modulesIds)) && $mid_array){
- $modulesIds = implode(",", $mid_array);
- if(!$this->schoolManager->classSubjectExists($classId)){
- if(!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds)))
- throw new CException('创建失败!');
- }
- else{
- if (!$this->sConn->createCommand()->update("class_subject_relation", array("subject_id" => $subjectId, "material_id" => $material_id, "module_ids" => $modulesIds), "class_id = {$classId}")) {
- throw new CException('创建失败!');
- }
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error($e->getMessage());
- }
- $this->redirect(array('classes/index'));
- }
- $data = array();
- unset(Yii::app()->session['school_material']);
- // 获取所有教材及其模块
- $get_material = Yii::app()->session['school_material'];
- if (empty($get_material)) {
- //$json_material = getCurlDataFor(Yii::app()->params['material_url'],Yii::app()->params['material_param']);
- $json_material = Curl::post(Yii::app()->params["material_url"]."/subjectId/3/depth/3");
- $json_material = json_decode($json_material, true);
- $json_material = Arr::merge($json_material, json_decode(Curl::post(Yii::app()->params["material_url"]."/subjectId/6/depth/3"), true));
- $session_material = $json_material;
- //$session_material = json_decode($json_material,true);
- if (!empty($session_material) && !isset($session_material['error'])) {
- Yii::app()->session['school_material'] = $session_material;
- $get_material = $session_material;
- }
- unset($json_material,$session_material);
- }
- if($get_material){
- foreach($get_material as $key => $material){
- if(isset($material["modules"])){
- foreach($material["modules"] as $moduleKey => $module){
- //if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
- if(empty($module["chapters"])){
- unset($get_material[$key]["modules"][$moduleKey]);
- }
- }
- }
- if(empty($get_material[$key]["modules"]))
- unset($get_material[$key]);
- }
- }
- $data['material'] = $get_material;
- /*$coachList = BusinessCoach::model()->findAll('school_id=:sid and status=0',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- if (empty($coachList)) {
- Yii::app()->jump->error('系统未找到助教,请联系管理员!');
- }*/
- $class_teacher_data = array();
- $subject_teacher_data = array();
- $subject_teacher_array = array();
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
- $teachers_data = Teacher::model()->findAll('status=0');
- if($teachers_data)
- {
- $gangwei = array(
- 0=>'任课教师',
- 1=>'班主任',
- 2=>'教研组长',
- 3=>'年级主任',
- 4=>'任课教师',
- 5=>'校长',
- );
- $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
- foreach($teachers_data as $k=>$v)
- {
- $class_teacher_data[$v->teacher_id] = $v->teacher_id;
- $subject_teacher_data[$v->teacher_id] = $v->subjects;
- $teacherGrade = $v->grade?$v->grade:0;
- if($v->posts==3){
- //过滤本年级的年级主任
- if (!$teacherGrade || $teacherGrade==$grade){
- $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts];
- $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost);
- }
- }else{
- $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]);
- }
- if($classInfo->teacher_id && strcmp($v->teacher_id,$classInfo->teacher_id)==0){
- $data['bzr']=$v->teacher_name;
- }
- }
- }
- if(!$classTeachersIds){//如果没有执教老师 默认会一个执教老师 方便编辑操作
- $sql = "select teacher_id from teacher where `status`=0 and (posts !=3 or (posts=3 and grade={$grade}))";
- $teacher_data = $this->sConn->createCommand($sql)->queryRow();
- if($teacher_data){
- $classTeachersIds[] = $teacher_data['teacher_id'];
- }
- }
-
- $data["teachers"] = $teachers;
- $data["classLevels"] = $this->class_level;
- $data["classTeachersIds"] = $classTeachersIds;
- $data['classInfo'] = $classInfo;
- $data['relatCoach'] = $relatCoach;
- $data['class_teacher'] = $class_teacher_data;
- $data['subject_teacher'] = $subject_teacher_data;
- $data['subject_teacher_array'] = $subject_teacher_array;
- $data["teacher_data"] = $teacher_data;
- $data['module_array'] = $module_array;
- $data['coachList'] = $coachList;
- $data["semesters"] = $semesters;
- $data["semester_id"] = $classInfo->semester_id;
- $data["thisSemester"] =$thisSemester;
-
- $this->render('edit',$data);
- }
- public function actionGetChaptersAct(){
- $materialId = Req::get("materialId");
- $chapters = $this->schoolManager->getMaterialChapters($materialId);
- echo json_encode($chapters);exit;
- }
- public function actionAjax_semester_class()
- {
- $semester_id = Req::post("semester_id");
- $class_id = Req::post("class_id");
- $class_array = array();
- if( !$semester_id || !$class_id)
- {
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$semester_id));
- $class_ids = array();
- $_class_ids = array();
- $class_info = array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- if($class_id != $v->class_id)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $class_info[$v->class_id] = $v->attributes;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- $_class_ids[$v->class_id] = $v->class_id;
- }
- foreach($_class_ids as $v)
- {
- if(isset($class_info[$v]) && !empty($class_info[$v]))
- {
- $class_array[$v] = $class_info[$v];
- }
- }
- }else{
- $class_array =array();
- }
- }
- if($class_array)
- {
- echo json_encode(array('status'=>1,'data'=>$class_array));exit;
- }
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- //根据学期id获取班级
- public function actionAjaxclass(){
- $json = array();
- $smid = safe_replace(Yii::app()->request->getPost('smid'));
- if (empty($smid)) {
- $json['flag'] = false;
- echo json_encode($json);die;
- }
- $allClass = ClassModel::model()->findAll('semester_id=:yid',array(':yid'=>$smid));
- $classList = array();
- if (!empty($allClass)) {
- foreach ($allClass as $val) {
- $classList[] = $val->attributes;
- }
- }
- unset($allClass);
- $json['flag'] = true;
- $json['classList'] = $classList;
- echo json_encode($json);exit;
- }
- public function actionGetclass()
- {
- $grade_id = Req::post("grade_id");
- $all_class = Req::post("all_class");
- $filter_hide = (int)Req::post('filter_hide');
- if(!$filter_hide){
- $filter_hide=0;
- }else{
- $filter_hide=1;
- }
- $class_array = array();
- $class_data=array();
- if($all_class){
- if($filter_hide){
- $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and is_hide=0',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
- }else{
- $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id ',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
- }
- }else{
- if($filter_hide){
- $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));
- }else{
- $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1',array(':grade' => $grade_id,':semester_id'=>$this->semesterId));
- }
- }
- if($class_data){
- foreach($class_data as $v )
- {
- $class_array[] = $v->attributes;
- }
- echo json_encode(array('status'=>1,'result'=>$class_array));exit;
- }
- echo json_encode(array('status'=>0,'result'=>array()));exit;
- }
- public function actionGetClassWithSort()
- {
- $class_data = ClassModel::model()->getClassWithSort($this->semesterId);
- if($class_data){
- foreach($class_data as $k=>$v )
- {
- $class_array[$k]['class_id'] = $v->class_id;
- $class_array[$k]['class_name'] = $v->class_name;
- $class_array[$k]['sort'] = $v->sort;
- }
- returnMsg(1,'获取成功',$class_array);
- }else{
- returnMsg(0,'暂无班级');
- }
- }
- // 复制学生
- public function actionCopy(){
- ini_set('memory_limit','300M');
- $data = array();
- $_err = array();
- $cid = safe_replace(Yii::app()->request->getQuery('cid'));
- $currSemester = $this->schoolManager->getCurrSemester();
- $criteria = new CDbCriteria;
- $criteria->addCondition('end_time <= :start_time');
- $criteria->params[':start_time'] = $currSemester['start_time'];
- $criteria->limit = 1;
- $criteria->order = "end_time desc";
- $allSemester = Semester::model()->find($criteria);
- $data['currSemester'] = $currSemester;
- $data['semesters'] = $allSemester;
- if (!($class = $this->schoolManager->getClass($cid))) {
- Yii::app()->jump->error('复制学生有误1!');
- }
- if($this->schoolManager->isFutureSemester($class["semester_id"]))
- Yii::app()->jump->error('未开始的学期不能转班');
- if (Yii::app()->request->getIsPostRequest()){
- //$get_array = $_POST['class_array'];
- $get_array = Filter::act($_POST['class_array']);
- $class_id = Filter::act($_POST['class_id']);
- $semester_id = Filter::act($_POST['semester_id']);
- $is_ajax = isset($_POST['is_ajax'])?Filter::act($_POST['is_ajax']):0;
- $chooseStudentIds = array();
- $chooseStudentStr = '';
- if($get_array){
- foreach($get_array as $k=>$v){
- $chooseStudentIds[] = $v;
- }
- }
- $operation=2; //转班操作类型
- if($semester_id==$this->semesterId){
- $operation=2;
- }else{
- $operation=3;
- }
- if($this->schoolManager->isFutureSemester($semester_id)){
- Yii::app()->jump->error('未开始的学期不能转班');
- }
- if (!($class = $this->schoolManager->getClass($class_id))) {
- Yii::app()->jump->error('复制学生有误2!');
- }
- if($this->schoolManager->isFutureSemester($class['semester_id'])){
- Yii::app()->jump->error('未开始的学期不能转班');
- }
- /**
- * 获取当前学期所有班级
- */
- $c_class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
- $c_class_ids = array();
- if(!$c_class_data)
- {
- Yii::app()->jump->error('当前学期无班级,请创建班级',Yii::app()->createUrl('classes/index'));
- }
- foreach($c_class_data as $v)
- {
- $c_class_ids[$v['class_id']] = $v['class_id'];
- }
- /**
- * 获取转出班的学生
- */
- //$out_data = $this->getClassStudents($class_id,0,$chooseStudentIds);
- $out_data = $this->getStudentsClassNo($chooseStudentIds);
- /**
- * 获取转入班的学生
- */
- $in_data = $this->getInClassStudents($c_class_ids);
- /**
- * 验证重名
- */
- if($class['semester_id']!=$this->semesterId)
- {
- $_err = $this->StudentCompare($out_data,$in_data);
- }
- if($_err)
- {
- Yii::app()->jump->error('转班失败,请查看重名或准考证号重复',Yii::app()->createUrl('classes/copy',array('cid'=>$cid)));
- }
- $serial_number = 0;
- $_student_class_data = SStudentClassRelation::model()->find(array(
- 'select' => 'serial_number',
- 'order' => 'serial_number desc',
- 'condition' => 'class_id=:class_id and status=:status',
- 'limit' => 1,
- 'params' => array(':class_id'=>$cid,':status'=>0)
- ));
- if($_student_class_data)
- {
- if($_student_class_data->serial_number)
- {
- $serial_number = $_student_class_data->serial_number;
- }
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '分班',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $transaction = StudentInfo::model()->dbConnection->beginTransaction();
- try {
- foreach ($get_array as $v) {
- $serial_number = $serial_number+1;
- // 修改当前学生所在的班级
- $count = StudentInfo::model()->updateAll(array('class_id'=>$cid),'student_id=:sid',array(':sid'=>$v));
- if (false === $count) {
- Yii::app()->jump->error('更新学生班级有误!');
- }
- //更新当前学生之前所在班级状态
- $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();
- if($classData){
- $classIds=array();
- foreach ($classData as $datum){
- $classIds[]=$datum['class_id'];
- }
- $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();
- // 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)));
- }
- //StudentToClass::model()->updateAll(array('status'=>'1','update_time'=>time(),'operation'=>$operation),'student_id=:sid and status=0 and class_type=1',array(':sid'=>$v));
- // 建立当前学生新班级对应记录
- //$student_class = SStudentClassRelation::model()->find('student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid));
- // if($student_class){
- // SStudentClassRelation::model()->updateAll(array('status'=>'0','update_time'=>time()),'student_id=:sid and class_id=:class_id',array(':sid'=>$v,':class_id'=>$cid));
- // }else{
- // $newModel = new StudentToClass();
- // $newModel->class_id = $cid;
- // $newModel->student_id = safe_replace($v);
- // $newModel->serial_number = $serial_number;
- // $newModel->userno = $out_data['class_student'][$v]['userno'];
- // $newModel->update_time = time();
- // if (!$newModel->save()) {
- // Yii::app()->jump->error('更新学生班级有误!');
- // }
- // }
- $newModel = new StudentToClass();
- $newModel->class_id = $cid;
- $newModel->student_id = safe_replace($v);
- $newModel->serial_number = $serial_number;
- if(isset($out_data['class_student'][$v])){
- $newModel->userno = $out_data['class_student'][$v]['userno'];
- }
- $newModel->update_time = time();
- if (!$newModel->save()) {
- Yii::app()->jump->error('更新学生班级有误!');
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- debug($e);
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error('复制学生信息失败!');
- }
- if($is_ajax){
- echo json_encode(array('status'=>1));exit;
- }else{
- $this->redirect(array('classes/index'));
- }
- }
- //所有班级
- $class_data = ClassModel::model()->findAll("semester_id =:semester_id",array(':semester_id'=>$this->semesterId));
- $class_ids = array();
- $_class_ids = array();
- $class_info = array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- if($cid != $v->class_id)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $class_info[$v->class_id] = $v;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- $_class_ids[$v->class_id] = $v->class_id;
- }
- foreach($_class_ids as $v)
- {
- if(isset($class_info[$v]) && !empty($class_info[$v]))
- {
- $data['all_class'][$v] = $class_info[$v];
- }
- }
- }else{
- $data['all_class'] =array();
- }
- }
- $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));
- // 班级名称
- $data['className'] = ClassModel::model()->getClassName($cid);
- $data['classId'] = $cid;
- $this->render('copy',$data);
- }
- public function StudentCompare($out,$in)
- {
- $_err = array();
- if($out && $in)
- {
- if(isset($in['student_names']) && !empty($in['student_names']) && isset($out['student_names']) && !empty($out['student_names']))
- {
- foreach ($in['student_names'] as $key=>$val)
- {
- if(isset($out[$key]))
- {
- $_err[$key] = $out[$key].'学生已存在';
- }
- foreach($out['student_names'] as $k=>$v)
- {
- if($v == $val)
- {
- $_err[$k] = $v.'学生姓名已存在';
- }
- }
- }
- }
- if(isset($in['school_student_cards']) && !empty($in['school_student_cards']) && isset($out['school_student_cards']) && !empty($out['school_student_cards']))
- {
- foreach ($in['school_student_cards'] as $key=>$val)
- {
- if(isset($out[$key]))
- {
- $_err[$key] = $out[$key].'学生已存在';
- }
- foreach($out['school_student_cards'] as $k=>$v)
- {
- if($v == $val)
- {
- $_err[$k] = $v.'学生学校准考证号已存在';
- }
- }
- }
- }
- if(isset($in['student_cards']) && !empty($in['student_cards']) && isset($out['student_cards']) && !empty($out['student_cards']))
- {
- foreach ($in['student_cards'] as $key=>$val)
- {
- if(isset($out[$key]))
- {
- $_err[$key] = $out[$key].'学生已存在';
- }
- foreach($out['student_cards'] as $k=>$v)
- {
- if($v == $val)
- {
- $_err[$k] = $v.'学生准考证号已存在';
- }
- }
- }
- }
- }
- return $_err;
- }
- public function getClassStudents($class_id,$status=0,$chooseStudentArr)
- {
- $data = array();
- $student_ids = array();
- $student_names = array();
- $student_cards = array();
- $school_student_cards = array();
- $userno = array();
- $student_info = array();
- $class_student = array();
- $student_class_ids = array();
- $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status));
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- if($chooseStudentArr && in_array($v->student_id, $chooseStudentArr)){
- $student_ids[$v->student_id] = $v->student_id;
- $userno[$v->student_id] = $v->userno;
- $class_student[$v->student_id] = $v;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_data = SStudentInfo::model()->findAll($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $student_names[$v->student_id] = $v->realname;
- $student_info[$v->student_id] = $v;
- }
- }
- unset($student_data);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $student_cards[$v->student_id] = $v->student_card;
- if($v->school_student_card)
- {
- $school_student_cards[$v->student_id] = $v->school_student_card;
- }
- //$school_student_cards[$v->student_id] = $v->school_student_card;
- }
- }
- unset($b_student_data);
- $data['student_names'] = $student_names;
- $data['student_cards'] = $student_cards;
- $data['student_ids'] = $student_ids;
- $data['school_student_cards'] = $school_student_cards;
- $data['student_userno'] = $userno;
- $data['student_info'] = $student_info;
- $data['class_student'] = $class_student;
- $data['student_class_ids'] = $student_class_ids;
- }
- unset($student_class_data);
- return $data;
- }
- public function getInClassStudents($class_ids)
- {
- $data = array();
- $student_ids = array();
- $student_names = array();
- $student_cards = array();
- $school_student_cards = array();
- $userno = array();
- $serial_number = array();
- $student_class_ids = array();
- $student_info = array();
- $class_student = array();
- $id_number = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $criteria->order = 'serial_number desc,class_id desc';
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $key=>$v)
- {
- if(isset($serial_number[$v->class_id]))
- {
- if($serial_number[$v->class_id]<$v->serial_number)
- {
- $serial_number[$v->class_id] = $v->serial_number;
- }
- }else
- {
- $serial_number[$v->class_id] = $v->serial_number;
- }
- $student_ids[$v->student_id] = $v->student_id;
- $userno[$v->student_id] = $v->userno;
- $class_student[$v->student_id] = $v;
- $student_class_ids[$v->student_id] = $v->class_id;
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_data = SStudentInfo::model()->findAll($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $student_names[$v->student_id] = $v->realname;
- $student_info[$v->student_id] = $v;
- $id_number[$v->student_id] =$v->id_number;
- }
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $student_cards[$v->student_id] = $v->student_card;
- if($v->school_student_card)
- {
- $school_student_cards[$v->student_id] = $v->school_student_card;
- }
- }
- }
- $data['student_names'] = $student_names;
- $data['student_cards'] = $student_cards;
- $data['student_ids'] = $student_ids;
- $data['school_student_cards'] = $school_student_cards;
- $data['student_userno'] = $userno;
- $data['student_info'] = $student_info;
- $data['class_student'] = $class_student;
- $data['student_class_ids'] = $student_class_ids;
- $data['serial_number'] = $serial_number;
- $data['id_number'] =$id_number;
- }
- return $data;
- }
- // 查看班级学生
- public function actionView(){
- $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
- if (empty($get_id)) {
- Yii::app()->jump->error('无法访问!');
- }
- $semesterId = $this->schoolManager->getSemesterIdByClassId($get_id);
- $data = array();
- $data["semesterId"] = $semesterId;
- $data["model"] = new Model();
- $data["isCurrentSemester"] = $this->schoolManager->isCurrentSemester($semesterId);
- /*$get_list = StudentInfo::model()->getUserList(array($get_id));
- $data['studentList'] = $get_list['result'];
- $data['pages'] = $get_list['page'];
- $data['page_total'] = $get_list['page_total'];*/
- $get_list = $this->schoolManager->getClassStudentsList($get_id);
- $team_student=$this->schoolManager->getTeamByClass($get_id,'student'); //所有学生列表
- $student_ids = array();
- $b_student_arr = array();
- $school_student_card = array();
- $z_student_arr = array();
- if($get_list && isset($get_list['rs']) && !empty($get_list['rs']))
- {
- foreach($get_list['rs'] as $k => $v)
- {
- $student_ids[$v['student_id']] = $v['student_id'];
- if(isset($team_student[$v['student_id']])){
- $get_list['rs'][$k]['team']=$team_student[$v['student_id']];
- }
- }
- if($student_ids){
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $b_student_arr[$v->student_id] = $v->student_card;
- $school_student_card[$v->student_id] = $v->school_student_card;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $z_student_arr[$v->student_id] = $v->zhixue_student_card;
- }
- }
- }
- }
- }
- $data['b_student'] = $b_student_arr;
- $data['school_card'] = $school_student_card;
- $data['z_student'] = $z_student_arr;
- $data['studentList'] = Arr::toObj($get_list['rs']);
- $data["students"] = $get_list;
- $data['pages'] = $get_list['pager'];
- $data['page_total'] = $get_list['pager']->rowsCount;
- $data["cid"] = $get_id;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
-
- $this->render('view',$data);
- }
- //预生成学生ID
- private function createStudentId($num)
- {
- return $this->createId($num);
- }
- //预生成系统准考证号
- private function createCard($num)
- {
- $cards = array();
- $student_cart = 0;
- if(!$num)
- {
- return $cards;
- }
- /*
- $b_student_data = BusinessStudent::model()->find(array(
- 'select' => 'student_card',
- 'order' => 'student_card desc',
- 'condition' => 'school_id=:school_id',
- 'limit' => 1,
- 'params' => array(':school_id'=>$this->schoolId)
- ));
- */
- $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();
- if($b_student_data)
- {
- if(!$b_student_data['student_card'])
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }else
- {
- $student_cart = $b_student_data['student_card'];
- }
- }else
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }
- unset($b_student_data);
- for($i=1;$i<=$num;$i++)
- {
- $cards[$student_cart+$i] = array(
- 'student_card'=>$student_cart+$i,
- 'use'=>0,
- 'order'=>$i
- );
- }
- return $cards;
- }
- private function addSetUUID($_uuid_arr)
- {
- if($_uuid_arr)
- {
- Yii::app()->business_uuid_cache->hmset('redis_business_uuid:'.$this->schoolId,$_uuid_arr);
- }
- }
- private function UUID_log($sum)
- {
- Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入学生成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time()));
- }
- //优化导入学生
- public function actionImport()
- {
- ini_set('memory_limit','300M');
- $error_msg = array();
- //sql
- $student_sql = '';
- $student_info_sql = '';
- $student_info_arr = array();
- $student_sql_arr = array();
- $class_student_sql = '';
- $class_student_sql_arr = array();
- $sql_count = 0;
- $update_student_id = array();
- $bstudents = new BusinessStudent();
- $sstudentinfo = new SStudentInfo();
- $sstudentclassrelation = new SStudentClassRelation();
- if (Yii::app()->request->getIsPostRequest()){
- $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if(!$file || !isset($file["error"]))
- Yii::app()->jump->error('请选择上传的Excel!');
- if($file["error"] != 0){
- switch($file["error"]){
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $result = true;
- $inputFileName = $file["src"];
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '导入学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$inputFileName)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- if ($result) {
- $semesterId = $this->semesterId;
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
- //FIXME 20191202
- @unlink($file["src"]);
- // 去掉导航
- //dump($sheetData);die;
- unset($sheetData[1]);
- krsort($sheetData);
- $serial_number = 0;
- $get_id = 0;
- $b_student_cards = array();
- $b_id_student_cards = array();
- $b_school_student_cards = array();
- $b_id_school_student_cards = array();
- $b_id_zhixue_student_cards = array();
- $b_student_ids = array();
- $b_student = array();
- $class_ids = array();
- $c_class_names = array();
- $grade = 0;
- $uuid = 0;
- $n_class_id = array();
- $n_student_ids = array();
- $class_grade = array();
- $class_serial_number = array();
- $s_student_ids = array();
- $d_student_ids = array();// 删除学生ID
- $d_student_card = array();
- $d_student_names = array();
- $d_school_student_card = array();
- $use_student_card = array();
- $use_school_student_card = array();
- $use_zhixue_student_card = array();
- $students = array();
- $cards = array();
- $_school_cards = array();
- $_zhixue_cards = array();
- $student_info_name = array();
- $student_names = array();
- $school_student_names = array();
- $school_student_info = array();
- $_class_ids = array();
- $del_class_student = array();
- //获当前学校的学生准考证号
- ////////////////////优化前
- // $b_student_all_data = BusinessStudent::model()->findAll(array(
- // 'order' => 'student_id desc',
- // 'condition' => 'school_id=:school_id',
- // 'params' => array(':school_id'=>$this->schoolId)
- // ));
- //
- // if($b_student_all_data)
- // {
- // foreach($b_student_all_data as $k=>$v)
- // {
- //
- // $b_student[$v->student_id] = $v;
- // $b_student_ids[$v->student_id] = $v->student_id;
- // $b_id_student_cards[$v->student_id] = $v->student_card;
- // $b_id_school_student_cards[$v->student_id] = (string)$v->school_student_card;
- // $b_id_zhixue_student_cards[$v->student_id] = (string)$v->school_student_card;
- // if($v->student_card)
- // {
- // $b_student_cards[$v->student_card] = $v->student_id;
- // }
- // if($v->school_student_card)
- // {
- // $b_school_student_cards[$v->school_student_card] = $v->student_id;
- // }
- //
- //
- //
- // }
- // }
- // unset($b_student_all_data);
- /////////////////////////////优化后
- $b_student_all_data = $bstudents->getStudentsByPages($this->schoolId);
- if($b_student_all_data){
- if(isset($b_student_all_data['b_student'])){
- $b_student = $b_student_all_data['b_student'];
- }
- if(isset($b_student_all_data['b_student_ids'])){
- $b_student_ids = $b_student_all_data['b_student_ids'];
- }
- if(isset($b_student_all_data['b_id_student_cards'])){
- $b_id_student_cards = $b_student_all_data['b_id_student_cards'];
- }
- if(isset($b_student_all_data['b_id_school_student_cards'])){
- $b_id_school_student_cards = $b_student_all_data['b_id_school_student_cards'];
- }
- if(isset($b_student_all_data['b_id_zhixue_student_cards'])){
- $b_id_zhixue_student_cards = $b_student_all_data['b_id_zhixue_student_cards'];
- }
- if(isset($b_student_all_data['b_student_cards'])){
- $b_student_cards = $b_student_all_data['b_student_cards'];
- }
- if(isset($b_student_all_data['b_school_student_cards'])){
- $b_school_student_cards = $b_student_all_data['b_school_student_cards'];
- }
- }
- unset($b_student_all_data);
- ///////////////////ending
- //获取当前学校所有学生信息
- ////////////////优化前
- // $student_info_data = SStudentInfo::model()->findAll();
- // if($student_info_data)
- // {
- // foreach($student_info_data as $v)
- // {
- // $school_student_info[$v->student_id] = $v;
- // $school_student_names[$v->student_id] = $v->realname;
- // }
- //
- // }
- //
- // unset($student_info_data);
- //////////////////////优化后
- $student_info_data = $sstudentinfo->getStudentsByPages();
- if($student_info_data){
- if(isset($student_info_data['school_student_info'])){
- $school_student_info = $student_info_data['school_student_info'];
- }
- if(isset($student_info_data['school_student_names'])){
- $school_student_names = $student_info_data['school_student_names'];
- }
- }
- unset($student_info_data);
-
- ///////////////////////ending
- // 获取当前学期的所有班级
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $c_class_names[$v->class_id] = (string)$v->class_name;
- //$class_grade[$v->class_id] = $v->grade;
- }
- }
- unset($class_semester_data);
-
- if(!$class_ids)
- {
- Yii::app()->jump->error('无班级信息,导入失败');
- }
- // 获取年级信息
- /*$grade_data = SGradeModel::model()->findAll();
- if(!$grade_data)
- {
- Yii::app()->jump->error('此班级无年级信息,导入失败');
- }*/
- $sheetData = array_reverse($sheetData);
- // 获取在线学生
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=0');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- unset($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //在线学生ID
- $s_student_ids[$v->student_id] = $v->student_id;
- //在线学生准考证号
- if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
- {
- $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
- }
- //在线学校准考证号
- if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
- {
- $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
- }
- //在线智学网准考证号
- if(isset($b_id_zhixue_student_cards[$v->student_id]) && !empty($b_id_zhixue_student_cards[$v->student_id]))
- {
- $use_zhixue_student_card[$b_id_zhixue_student_cards[$v->student_id]] = $v->student_id;
- }
- //获取在线学生信息
- if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
- {
- $student_names[$v->student_id] = $school_student_names[$v->student_id];
- }
- //获取班级中的最大序号
- if(isset($class_serial_number[$v->class_id]))
- {
- if($class_serial_number[$v->class_id]<$v->serial_number)
- {
- $class_serial_number[$v->class_id] = $v->serial_number;
- }
- }else
- {
- $class_serial_number[$v->class_id] = $v->serial_number;
- }
- }
- }
- unset($semester_student_class_data);
- //获取已删除的学生信息
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=1');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- unset($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //已删除学生ID
- $d_student_ids[$v->student_id] = $v->student_id;
- //在线学生准考证号
- if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
- {
- $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
- }
- //在线学校准考证号
- if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
- {
- $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
- }
- //获取在线学生信息
- if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
- {
- $d_student_names[$v->student_id] = $school_student_names[$v->student_id];
- }
- }
- }
- unset($semester_student_class_data);
- $sheetData_sun = count($sheetData);
- //预定学生准考证号
- $create_card_data = $this->createCard($sheetData_sun);
- //预定学生ID
- $create_student_ids = $this->createStudentId($sheetData_sun);
- if(!$create_student_ids)
- {
- Yii::app()->jump->error('预定学生ID不足,请联系技术人员');
- }
- foreach ($sheetData as $key=>$val)
- {
- if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
- continue;
- }
- if(count($val) != 7)
- {
- Yii::app()->jump->error('导入学生格式有误! ');
- }
- if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空';
- $error_msg[$key]['so_msg'] = '按照示例格式填写表格';
- continue;
- }
- $val['A'] = (string)$val['A'];
- $card = 0;
- //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
- $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
- $username = $realname;
- if (isset($val['E'])) {
- $card = safe_replace($val['E']);
- }
- if (in_array($username, $students)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '表格中存在姓名重复';
- $error_msg[$key]['so_msg'] = '在表格中删除重复学生';
- continue;
- }
- $students[] = $username;
- //验证系统准考证号
- if (!empty($card)) {
- if (in_array($card, $cards)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '表格中存在系统准考证号';
- $error_msg[$key]['so_msg'] = '在表格中删除重复系统准考证号';
- continue;
- }
- $cards[] = $card;
- }
- if (isset($val['F']) && !empty($val['F'])) {
- $school_card = safe_replace($val['F']);
- //验证学校准考证号
- if (!empty($school_card)) {
- if (isset($_school_cards[$school_card]) && !empty($_school_cards[$school_card])) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '表格中存在学校准考证号';
- $error_msg[$key]['so_msg'] = '在表格中删除重复学校准考证号';
- continue;
- }
- if(!is_numeric($school_card)){
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学校准考证号格式不正确';
- $error_msg[$key]['so_msg'] = '学校准考证号只能由数字组成';
- continue;
- }
- $_school_cards[$school_card] = $school_card;
- }
- }
- if (isset($val['G']) && !empty($val['G'])) {
- $zhixue_student_card = safe_replace($val['G']);
- //验证智学网准考证号
- if (!empty($zhixue_student_card)) {
- if (in_array($zhixue_student_card, $_zhixue_cards)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '表格中存在智学网准考证号';
- $error_msg[$key]['so_msg'] = '在表格中删除重复智学网准考证号';
- continue;
- }
- if(!is_numeric($zhixue_student_card)){
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '智学网准考证号格式不正确';
- $error_msg[$key]['so_msg'] = '智学网准考证号只能由数字组成';
- continue;
- }
- $_zhixue_cards[] = $zhixue_student_card;
- }
- }
- }
- foreach ($sheetData as $key=>$val) {
- if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
- continue;
- }
- if(count($val) != 7)
- {
- Yii::app()->jump->error('导入学生格式有误! ');
- }
- if (empty($val['A']) OR empty($val['B']) or empty($val['C'])) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '班级,姓名,性别不能为空';
- $error_msg[$key]['so_msg'] = '按照示例格式填写表格';
- continue;
- }
- $val['A'] = (string)$val['A'];
- $class_name = $val['A'];
- if(!in_array($class_name,$c_class_names))
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '此班级不存在';
- $error_msg[$key]['so_msg'] = '填写存在班级名称';
- continue;
- }
- $get_id = array_search($class_name,$c_class_names,TRUE);
- if(!$get_id){
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '此班级不存在';
- $error_msg[$key]['so_msg'] = '班级名称填写不正确';
- continue;
- }
- $_class_ids[$get_id] = $get_id;
- //$realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
- $realname = preg_replace("/[^\x{4E00}-\x{9FFF}{3400}-\x{4DBF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['B']));
- $sex = safe_replace($val['C']);
- $userno = safe_replace($val['D']);
- $card = 0;
- $username = $realname;
- if (isset($val['E'])) {
- $card = safe_replace($val['E']);
- }
- if(!isset($class_serial_number[$get_id]))
- {
- $class_serial_number[$get_id] = 0;
- }
- $school_card = '';
- if (isset($val['F']) && !empty($val['F'])) {
- $school_card = safe_replace($val['F']);
- //验证学校准考证号
- /*if (strlen($school_card) != $grade_data->card_length) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学校准考证号长度不正确';
- $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。';
- continue;
- }*/
- if (!$card && $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学校准考证号已存在';
- $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
- continue;
- }else
- {
- if (isset($use_student_card[$card]))
- {
- if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
- $c_student_id = 0;
- $c_student_id = $use_student_card[$card];
- $s_student_id = $use_school_student_card[$school_card];
- if($c_student_id != $s_student_id)
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学校准考证号已存在';
- $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
- continue;
- }
- }
- }else
- {
- if ( $use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card]))
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学校准考证号已存在';
- $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前学期不存在的学校准考证号';
- continue;
- }
- }
- }
- }
- //智学网
- $zhixue_student_card = '';
- if (isset($val['G']) && !empty($val['G'])) {
- $zhixue_student_card = safe_replace($val['G']);
- if (!$card && $use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card])) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
- $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
- continue;
- }else
- {
- if (isset($use_student_card[$card]))
- {
- if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card]))
- {
- $c_student_id = 0;
- $c_student_id = $use_student_card[$card];
- $z_student_id = $use_zhixue_student_card[$zhixue_student_card];
- if($c_student_id != $z_student_id)
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
- $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
- continue;
- }
- }
- }else
- {
- if($use_zhixue_student_card && isset($use_zhixue_student_card[$zhixue_student_card]) && !empty($use_zhixue_student_card[$zhixue_student_card]))
- {
- $c_student_id = $use_student_card[$card];
- $z_student_id = $use_zhixue_student_card[$zhixue_student_card];
- if($c_student_id != $z_student_id)
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '智学网准考证号已存在';
- $error_msg[$key]['so_msg'] = '智学网准考证号在本学校唯一,请使用在本学校不存在的智学网准考证号';
- continue;
- }
- }
- }
- }
- }
- if ($sex != '1' && $sex != '2') {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '性别填写有误';
- $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)';
- continue;
- }
- //判断学生是否存在
- if (!$card && $student_names && $_student_id = array_search($realname, $student_names,true)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学生在该学校有重名';
- $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
- continue;
- } else {
- //验证准考证号
- $is_current_student = 0;
- if ($card) {
- if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) {
- $is_current_student = 1;
- if ($school_student_names && isset($school_student_names[$use_student_card[$card]]) && $school_student_names[$use_student_card[$card]] != $realname) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
- continue;
- }
- }
- //验证新导入的准考证号
- if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) {
- //正在使用中
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '系统准考证号正在使用中';
- $error_msg[$key]['so_msg'] = '填写不存在的系统准考证号。可以使用学生管理的搜索功能检验是否存在系统准考证号';
- continue;
- }
- //验证已删除的学生的准考证号
- if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) {
- //验证删除的学生姓名是否一致
- if ( $d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
- continue;
- }
- //是否存在
- if ($d_student_card == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '学生在该学校有重名';
- $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
- continue;
- }
- }
- //验证上学期的学生
- if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
- if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
- continue;
- }
- //是否存在
- if ($is_current_student == 0 && $student_names && $_student_id = array_search($realname, $student_names,true)) {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '该学生在该在当前学期有重名';
- $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
- continue;
- }
- }else
- {
- $error_msg[$key]['class_name'] = $val['A'];
- $error_msg[$key]['student_name'] = $val['B'];
- $error_msg[$key]['student_six'] = $val['C'];
- $error_msg[$key]['student_no'] = $val['D'];
- $error_msg[$key]['student_card'] = $val['E'];
- $error_msg[$key]['school_student_card'] = $val['F'];
- $error_msg[$key]['zhixue_student_card'] = $val['G'];
- $error_msg[$key]['err_msg'] = '系统准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '系统准考证与姓名必须一致。可以使用学生管理的搜索功能检验是否存在系统准考证号';
- continue;
- }
- }
- }
- ///////////////////////////////////////////////////////////
- $sql_count = $sql_count+1;
- //创建学生
- if (!$card ) {
- $student_cart = 0;
- foreach ($create_card_data as $v) {
- if ($v['use'] == 0) {
- $student_cart = $v['student_card'];
- $create_card_data[$student_cart]['use'] = 1;
- break;
- }
- }
- $studentId = current($create_student_ids);
- unset($create_student_ids[$studentId]);
- $student_cart = (int)$student_cart;
- $password = $student_cart;
- // 将学生登录账号插入主数据
- $student_sql .= "(".$studentId.",'".$student_cart."',".$student_cart.",'".$school_card."','".$zhixue_student_card."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".time()."),";
- $student_info_sql .= "(".$studentId.",'".$realname."',".$sex.",".$this->schoolId.",".$get_id.",'','','','','',0,".time().",".time().",0,0.00,0),";
- $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),";
- if($sql_count==400)
- {
- $student_sql = substr($student_sql,0,-1).';';
- $student_sql_arr[] = $student_sql;
- $student_info_sql = substr($student_info_sql,0,-1).';';
- $student_info_arr[] = $student_info_sql;
- $class_student_sql = substr($class_student_sql,0,-1).';';
- $class_student_sql_arr[] = $class_student_sql;
- $student_sql = '';
- $student_info_sql = '';
- $class_student_sql = '';
- $sql_count = 0;
- }
- } else {
- //学生转班
- if(!$error_msg)
- {
- if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
- $studentId = $b_student_cards[$card];
- if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) {
- $update_student_id[$studentId] = $studentId;
- $del_class_student[] = "delete from student_class_relation where class_id = '{$get_id}' and student_id = '{$studentId}' ;";
- //StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId));
- //写入数据
- $b_student_obj = $b_student[$studentId];
- $school_student_obj = $school_student_info[$studentId];
- $student_cart = (int)$card;
- $password = $student_cart;
- $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']."),";
- $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']."),";
- $class_student_sql .= "(".$get_id.",".$studentId.",".($class_serial_number[$get_id] +$key+ 1).",'".$userno."',".time().",0),";
- if($sql_count==400)
- {
- $student_sql = substr($student_sql,0,-1).';';
- $student_sql_arr[] = $student_sql;
- $student_info_sql = substr($student_info_sql,0,-1).';';
- $student_info_arr[] = $student_info_sql;
- $class_student_sql = substr($class_student_sql,0,-1).';';
- $class_student_sql_arr[] = $class_student_sql;
- $student_sql = '';
- $student_info_sql = '';
- $class_student_sql = '';
- $sql_count = 0;
- }
- }
- }
- }
- }
- }
- }
- if($error_msg)
- {
- $this->create_import_xls($error_msg);
- }else
- {
- if($del_class_student){
- foreach ($del_class_student as $v){
- $this->sConn->createCommand($v)->execute();
- }
- }
- if($student_sql)
- {
- $student_sql = substr($student_sql,0,-1).';';
- $student_sql_arr[] = $student_sql;
- }
- if($student_info_sql)
- {
- $student_info_sql = substr($student_info_sql,0,-1).';';
- $student_info_arr[] = $student_info_sql;
- }
- if($class_student_sql)
- {
- $class_student_sql = substr($class_student_sql,0,-1).';';
- $class_student_sql_arr[] = $class_student_sql;
- }
- if(!$student_sql_arr || !$student_info_arr || !$class_student_sql_arr )
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- $b_sql = 'INSERT INTO `student`
- (`student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time`)VALUES';
- $s_sql = 'INSERT 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`)VALUES';
- $c_sql = 'INSERT INTO `student_class_relation`
- (`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`status`)VALUES';
- $transaction = Yii::app()->businessDb->beginTransaction();//建立事务
- try{
- if($student_sql_arr)
- {
- if($update_student_id)
- {
- /*
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$update_student_id);
- BusinessStudent::model()->deleteAll($criteria);
- unset($criteria);
- */
- $businessStudentSql="delete from student where student_id in(".implode(',',$update_student_id).")";
- $this->conn->createCommand($businessStudentSql)->execute();
- }
- foreach($student_sql_arr as $k=>$v)
- {
- if($v==';')
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- $this->conn->createCommand($b_sql.$v)->execute();
- }
- }
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- Yii::app()->jump->error('上传失败,添加学生失败');
- }
- unset($transaction);
- $transaction = $this->sConn->beginTransaction();
- try{
- if($update_student_id)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$update_student_id);
- StudentInfo::model()->deleteAll($criteria);
- unset($criteria);
- /*
- if($del_class_student){
- foreach ($del_class_student as $v){
- $this->sConn->createCommand($v)->execute();
- }
- }
- */
- unset($del_class_student);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$update_student_id);
- $criteria->addCondition('status = 0');
- $criteria->addCondition('class_type = 1');
- StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3),$criteria);
- unset($criteria);
- /*
- $StudentSql="delete from `student_info` where `student_id` in (".implode(',',$update_student_id).")";
- $this->sConn->createCommand($StudentSql)->execute();
- $StudentToClassSql="update `student_class_relation` set `status`=1 and `update_time`=".time()." where`student_id` in (".implode(',',$update_student_id).") and `status`=0 ";
- $this->sConn->createCommand($StudentToClassSql)->execute();
- */
- }
- if($student_info_arr)
- {
- foreach($student_info_arr as $k=>$v)
- {
- if($v==';')
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- $this->sConn->createCommand($s_sql.$v)->execute();
- }
- }
- if($class_student_sql_arr)
- {
- foreach($class_student_sql_arr as $k=>$v)
- {
- if($v==';')
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- $this->sConn->createCommand($c_sql.$v)->execute();
- }
- }
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- Yii::app()->jump->error('上传失败,添加学生失败');
- }
- unset($create_student_ids);
- $this->redirect(Yii::app()->createUrl('studentinfo/index'));
- }
- }
- }
- public function actionStudent_import()
- {
- $this->render('student_import');
- }
- // 导入学生
- public function actionImport_brack()
- {
- $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
- if (empty($get_id) || !($class = $this->schoolManager->getClass($get_id)))
- {
- Yii::app()->jump->error('无法访问!');
- }
- if($this->schoolManager->isPreviousSemester($class["semester_id"]))
- {
- Yii::app()->jump->error('不能为已完成学期的班级导入学生!');
- }
- if (Yii::app()->request->getIsPostRequest()){
- $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls");
- $uploader->fieldsMappings = array("exname" => array(0 => $get_id));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if(!$file || !isset($file["error"]))
- Yii::app()->jump->error('请选择上传的Excel!');
- if($file["error"] != 0){
- switch($file["error"]){
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $result = true;
- $inputFileName = $file["src"];
- if ($result) {
- $semesterId = $this->semesterId;
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- // 去掉导航
- //dump($sheetData);die;
- unset($sheetData[1]);
- krsort($sheetData);
- $serial_number = 0;
- $b_student_cards = array();
- $b_id_student_cards = array();
- $b_school_student_cards = array();
- $b_id_school_student_cards = array();
- $b_student_ids = array();
- $b_student = array();
- $class_ids = array();
- $class_names = array();
- $c_class_names = array();
- $grade = 0;
- $n_class_id = array();
- $n_student_ids = array();
- $s_student_ids = array();
- $d_student_ids = array();// 删除学生ID
- $d_student_card = array();
- $d_student_names = array();
- $d_school_student_card = array();
- $use_student_card = array();
- $use_school_student_card = array();
- $error_msg = array();
- $students = array();
- $cards = array();
- $student_info_name = array();
- $student_names = array();
- $school_student_names = array();
- $school_student_info = array();
- //获当前学校的学生准考证号
- $b_student_all_data = BusinessStudent::model()->findAll(array(
- 'order' => 'student_card desc',
- 'condition' => 'school_id=:school_id',
- 'params' => array(':school_id'=>$this->schoolId)
- ));
- if($b_student_all_data)
- {
- foreach($b_student_all_data as $v)
- {
- $b_student[$v->student_id] = $v;
- $b_student_ids[$v->student_id] = $v->student_id;
- $b_id_student_cards[$v->student_id] = $v->student_card;
- $b_id_school_student_cards[$v->student_id] = $v->school_student_card;
- if($v->student_card)
- {
- $b_student_cards[$v->student_card] = $v->student_id;
- }
- if($v->school_student_card)
- {
- $b_school_student_cards[$v->school_student_card] = $v->student_id;
- }
- }
- }
- //获取当前学校所有学生信息
- $student_info_data = SStudentInfo::model()->findAll();
- if($student_info_data)
- {
- foreach($student_info_data as $v)
- {
- $school_student_info[$v->student_id] = $v;
- $school_student_names[$v->student_id] = $v->realname;
- }
- }
- $student_class_data = SStudentClassRelation::model()->find(array(
- 'select' => 'serial_number',
- 'order' => 'serial_number desc',
- 'condition' => 'class_id=:class_id and status=:status',
- 'limit' => 1,
- 'params' => array(':class_id'=>$get_id,':status'=>0)
- ));
- if($student_class_data)
- {
- if($student_class_data->serial_number)
- {
- $serial_number = $student_class_data->serial_number;
- }
- }
- // 获取当前学期的所有班级
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $c_class_names[$v->class_id] = $v->class_name;
- }
- }
- if(!$class_ids)
- {
- Yii::app()->jump->error('无班级信息,导入失败');
- }
- // 获取年级信息
- $grade_data = SGradeModel::model()->find('id=:id',array(':id'=>$class['grade']));
- if(!$grade_data)
- {
- Yii::app()->jump->error('此班级无年级信息,导入失败');
- }
- $sheetData = array_reverse($sheetData);
- // 获取在线学生
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=0');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //在线学生ID
- $s_student_ids[$v->student_id] = $v->student_id;
- //在线学生准考证号
- if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
- {
- $use_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
- }
- //在线学校准考证号
- if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
- {
- $use_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
- }
- //获取在线学生信息
- if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
- {
- $student_names[$v->student_id] = $school_student_names[$v->student_id];
- }
- }
- }
- //获取已删除的学生信息
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=1');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //已删除学生ID
- $d_student_ids[$v->student_id] = $v->student_id;
- //在线学生准考证号
- if(isset($b_id_student_cards[$v->student_id]) && !empty($b_id_student_cards[$v->student_id]))
- {
- $d_student_card[$b_id_student_cards[$v->student_id]] = $v->student_id;
- }
- //在线学校准考证号
- if(isset($b_id_school_student_cards[$v->student_id]) && !empty($b_id_school_student_cards[$v->student_id]))
- {
- $d_school_student_card[$b_id_school_student_cards[$v->student_id]] = $v->student_id;
- }
- //获取在线学生信息
- if($school_student_names && isset($school_student_names[$v->student_id]) && !empty($school_student_names[$v->student_id]))
- {
- $d_student_names[$v->student_id] = $school_student_names[$v->student_id];
- }
- }
- }
- //预定学生准考证号
- $create_card_data = $this->createCard(count($sheetData));
- foreach ($sheetData as $key=>$val) {
- if (empty($val['A']) AND empty($val['B']) AND empty($val['C'])) {
- continue;
- }
- if (empty($val['A']) OR empty($val['B'])) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学生姓名与性别不能为空';
- $error_msg[$key]['so_msg'] = '填写正确的学生姓名与性别';
- continue;
- }
- $realname = preg_replace("/[^\x{4E00}-\x{9FFF}a-zA-Z0-9_]+/u", "", exsl_safe_replace($val['A']));
- $sex = safe_replace($val['B']);
- $userno = safe_replace($val['C']);
- $card = 0;
- $username = $realname;
- if (isset($val['D'])) {
- $card = safe_replace($val['D']);
- }
- $school_card = '';
- if (isset($val['E']) && !empty($val['E'])) {
- $school_card = safe_replace($val['E']);
- if (strlen($school_card) != $grade_data->card_length) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学校准考证号长度不正确';
- $error_msg[$key]['so_msg'] = '当前系统设置长度为:'.$grade_data->card_length.',填写的学校准考证号长度为:'.strlen($school_card).',学校准考证号长度与设置一致。';
- continue;
- }
- if ($use_school_student_card && isset($use_school_student_card[$school_card]) && !empty($use_school_student_card[$school_card])) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学校准考证号已存在';
- $error_msg[$key]['so_msg'] = '学校准考证号在当前学期唯一,修改当前期不存在的学校准考证号';
- continue;
- }
- }
- if (in_array($username, $students)) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '表格中存在姓名重复';
- $error_msg[$key]['so_msg'] = '在表格中删除重复学生';
- continue;
- }
- $students[] = $username;
- if (!empty($card)) {
- if (in_array($card, $cards)) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '表格中存在姓名准考证号';
- $error_msg[$key]['so_msg'] = '在表格中删除重复准考证号';
- continue;
- }
- $cards[] = $card;
- }
- if ($sex != 1 && $sex != 2) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '性别填写有误';
- $error_msg[$key]['so_msg'] = '性别数据必须是1(男)或2(女)';
- continue;
- }
- //判断学生是否存在
- if ($student_names && $_student_id = array_search($realname, $student_names,true)) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学生在该学校有重名';
- $error_msg[$key]['so_msg'] = '填写不存在的学生姓名。可以使用学生管理的搜索功能检验是否存在学生姓名';
- continue;
- } else {
- //验证准考证号
- if ($card) {
- if ($use_student_card && isset($use_student_card[$card]) && !empty($use_student_card[$card])) {
- //正在使用中
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学生准考证号正在使用中';
- $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
- continue;
- }
- //验证新导入的准考证号
- if ($create_card_data && isset($create_card_data[$card]) && $create_card_data[$card]['use'] == 1) {
- //正在使用中
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '学生准考证号正在使用中';
- $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
- continue;
- }
- //验证已删除的学生的准考证号
- if ($d_student_card && isset($d_student_card[$card]) && !empty($d_student_card[$card])) {
- //验证删除的学生姓名是否一致
- if ($d_student_names && isset($d_student_names[$d_student_card[$card]]) && $d_student_names[$d_student_card[$card]] != $realname) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
- continue;
- }
- }
- //验证上学期的学生
- if ($b_student_cards && isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
- if ($school_student_names && isset($school_student_names[$b_student_cards[$card]]) && $school_student_names[$b_student_cards[$card]] != $realname) {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
- continue;
- }
- }else
- {
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '准考证与姓名不一致';
- $error_msg[$key]['so_msg'] = '填写不存在的考证号。可以使用学生管理的搜索功能检验是否存在考证号';
- continue;
- }
- }
- }
- ///////////////////////////////////////////////////////////
- //创建学生
- if (!$card) {
- $student_cart = 0;
- foreach ($create_card_data as $v) {
- if ($v['use'] == 0) {
- $student_cart = $v['student_card'];
- break;
- }
- }
- //$studentId = getUUID();
- $studentId=getUniqueId($this->schoolId);
- $student_cart = (int)$student_cart;
- $password = $student_cart;
- // 将学生登录账号插入主数据
- $studentModel = new BusinessStudent();
- $studentModel->username = $student_cart;
- $studentModel->password = md5(sha1($password . 'wy') . 'fengche');
- $studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
- $studentModel->student_id = $studentId;
- $studentModel->student_card = $student_cart;
- $studentModel->school_student_card = $school_card ? $school_card : '';
- $studentModel->register_time = time();
- if ($studentModel->save()) {
- // 学校库插入学生基本信息
- $userModel = new StudentInfo();
- $userModel->student_id = $studentId;
- $userModel->realname = $realname;
- $userModel->school_id = $this->schoolId;
- $userModel->class_id = $get_id;
- $userModel->add_time = time();
- $userModel->sex = $sex;
- $userModel->telephone = '';
- if ($userModel->save()) {
- // 创建学生与班级关联关系
- $studentClass = new StudentToClass();
- $studentClass->class_id = $get_id;
- $studentClass->student_id = $studentId;
- $studentClass->serial_number = $serial_number +$key+ 1;
- $studentClass->userno = $userno;
- $studentClass->update_time = time();
- $studentClass->status = "0";
- $studentClass->save();
- } else {
- //数据写入失败
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '数据写入失败';
- $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
- continue;
- }
- } else {
- //数据写入失败
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '数据写入失败';
- $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
- continue;
- }
- $create_card_data[$student_cart]['use'] = 1;
- continue;
- } else {
- //学生转班
- if (isset($b_student_cards[$card]) && !empty($b_student_cards[$card])) {
- $studentId = $b_student_cards[$card];
- if (isset($b_student[$studentId]) && !empty($b_student[$studentId]) && isset($school_student_info[$studentId]) && !empty($school_student_info[$studentId])) {
- BusinessStudent::model()->deleteAll('student_id=:sid', array(':sid' => $studentId));
- StudentInfo::model()->deleteAll('student_id=:sid', array(':sid' => $studentId));
- StudentToClass::model()->updateAll(array('status' => 1, 'update_time' => time(),'operation'=>3), 'student_id=:sid and status = 0', array(':sid' => $studentId));
- StudentToClass::model()->deleteAll('student_id=:sid and class_id = ' . $get_id, array(':sid' => $studentId));
- //写入数据
- $b_student_obj = $b_student[$studentId];
- $school_student_obj = $school_student_info[$studentId];
- $student_cart = (int)$card;
- $password = $student_cart;
- // 将学生登录账号插入主数据
- $studentModel = new BusinessStudent();
- $studentModel->username = $b_student_obj->username;
- $studentModel->password = md5(sha1($password . 'wy') . 'fengche');
- $studentModel->school_id = $this->schoolId;
- $studentModel->student_id = $studentId;
- $studentModel->student_card = $student_cart;
- if ($school_card) {
- $studentModel->school_student_card = $school_card;
- } else {
- $studentModel->school_student_card = $b_student_obj->school_student_card;
- }
- $studentModel->register_time = $b_student_obj->register_time;
- if ($studentModel->save()) {
- // 学校库插入学生基本信息
- $userModel = new StudentInfo();
- $userModel->student_id = $studentId;
- $userModel->realname = $school_student_obj->realname;
- $userModel->sex = $school_student_obj->sex;
- $userModel->school_id = $this->schoolId;
- $userModel->class_id = $get_id;
- $userModel->family_tel = $school_student_obj->family_tel;
- $userModel->telephone = $school_student_obj->telephone;
- $userModel->student_phone = $school_student_obj->student_phone;
- $userModel->picture = $school_student_obj->picture;
- $userModel->signature = $school_student_obj->signature;
- $userModel->is_outer = $school_student_obj->is_outer;
- $userModel->add_time = $school_student_obj->add_time;
- $userModel->update_time = time();
- $userModel->level = $school_student_obj->level;
- $userModel->ave_score_rate = $school_student_obj->ave_score_rate;
- $userModel->game_stars = $school_student_obj->game_stars;
- if ($userModel->save()) {
- // 创建学生与班级关联关系
- $studentClass = new StudentToClass();
- $studentClass->class_id = $get_id;
- $studentClass->student_id = $studentId;
- $studentClass->serial_number = $serial_number +$key+ 1;
- $studentClass->userno = $userno;
- $studentClass->update_time = time();
- $studentClass->status = "0";
- $studentClass->save();
- } else {
- //数据写入失败
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '数据写入失败';
- $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
- continue;
- }
- } else {
- //数据写入失败
- $error_msg[$key]['student_name'] = $val['A'];
- $error_msg[$key]['student_six'] = $val['B'];
- $error_msg[$key]['student_no'] = $val['C'];
- $error_msg[$key]['student_card'] = $val['D'];
- $error_msg[$key]['school_student_card'] = $val['E'];
- $error_msg[$key]['err_msg'] = '数据写入失败';
- $error_msg[$key]['so_msg'] = '查看文件格式是否正确,按照案例文件填写导入学生信息';
- continue;
- }
- continue;
- }
- }
- }
- }
- }
- if($error_msg)
- {
- $this->create_import_xls($error_msg);
- }else
- {
- $this->redirect(Yii::app()->createUrl('classes/view',array('cid'=>$get_id)));
- }
- }
- $data = array();
- $data['cid'] = $get_id;
- $this->render('import',$data);
- }
- public function actionDelClassAct(){
- $classId = Req::post("classId");
- if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1))
- {
- $rs = $this->schoolManager->delClass($classId);
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '使用权限删除班级',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- }else{
- $rs = $this->schoolManager->CoachdelClass($classId);
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '删除班级',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- }
- //更新REDSI
- Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
- echo json_encode($rs);exit;
- }
- //删除班级前校验
- public function actionCheckBeforeDelClass(){
- $classId = Req::post("classId");
- $result['status']=0;
- if(!$classId){
- $result['msg']='参数错误';
- exit(json_encode($result));
- }
- $checkStatusCode=0;
- if($this->schoolManager->classHasStudent($classId)){
- $checkStatusCode+=2;
- }
- if($this->schoolManager->classHasExam($classId)){
- $checkStatusCode+=1;
- }
- $result['status']=1;
- $result['data']=$checkStatusCode;
- exit(json_encode($result));
- }
- public function actionClassHasStudent(){
- $classId = Req::get("classId");
- $rs = $this->schoolManager->classHasStudent($classId);
- echo $rs ? 1 : 0;
- }
- public function actionDownloadStudentsQrcodesAct(){
- $classId = Req::get("classId");
- $studentsIds = Req::get("studentsIds");
- $force = Req::get("force");
- $force = $force == 1 ? true : false;
- $style = Req::get("style");
- $amount = Req::get("amount");
- $amount = Number::isInt($amount) && $amount > 0 ? $amount : 8;
- $filePath = Yii::app()->basePath."/../".Yii::app()->params["qrcode_path"]."schools/{$this->schoolId}/".date("Y", time())."/";
- File::mkdir($filePath);
- //for test
- $force = true;
- $style = 1;
- $class = $this->schoolManager->getClass($classId);
- $className = $class ? $class["class_name"] : null;
- if($studentsIds)
- $studentsIds = explode(",", $studentsIds);
- $students = array();
- $linedBy = "STUDENT";
- if($studentsIds){
- $students = $this->schoolManager->getStudents($studentsIds);
- }
- else if($classId){
- $linedBy = "CLASSSTUDENTS";
- $students = $this->schoolManager->getClassStudents($classId, null, "ARRAY");
- }
- foreach($students as $key => $student){
- $file = $filePath.$student["student_id"].".png";
- if(is_file($file) && !$force)
- continue;
- $string = "{$student["student_id"]}-{$student["serial_number"]}";
- QRcode::png($string, $file, "H", 2.7, 4);
- if(!is_file($file)){
- unset($students[$key]);
- continue;
- }
- $src = Image::createFromFile($file);
- switch($style){
- case 1:
- 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)));
- Image::sign($src, "{$student["realname"]}-{$student["serial_number"]}", array("size" => 7.5, "color" => array(0, 0, 0), "x" => "center", "y" => "bottom -2"));
- Image::setBorder($src);
- break;
- case 2:
- 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)));
- Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center -5", "y" => 68));
- Image::sign($src, "No:{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "71", "y" => 6, "angle" => -90));
- Image::setBorder($src);
- break;
- case 3:
- 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)));
- Image::sign($src, $student["realname"], array("size" => 8, "color" => array(0, 0, 0), "x" => "center 5", "y" => 1));
- Image::sign($src, "{$student["serial_number"]}", array("size" => 8, "color" => array(0, 0, 0), "x" => "2", "y" => 16, "angle" => -90));
- Image::setBorder($src);
- break;
- case 4:
- default:
- $font = Image::create(25, 25, array(255, 255, 255, 0));
- Image::sign($font, $student["realname"], array("size" => 7, "color" => array(0, 0, 0), "x" => "center", "y" => "center"));
- 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)));
- $images = array(
- array(
- "res" => $font,
- "layer_num" => 1,
- "x" => "center",
- "y" => "center",
- "w" => 25,
- "h" => 25
- ),
- array(
- "res" => $src,
- "layer_num" => 2,
- "x" => "left",
- "y" => "top",
- "w" => 80,
- "h" => 80
- ),
- );
- $src = Image::puzzle(array("w" => 80, "h" => 80), $images);
- Image::setBorder($src);
- break;
- }
- $students[$key]["pic"] = $file;
- if(!Image::saveAs($src, $file))
- unset($students[$key]);
- }
- Yii::$enableIncludePath = FALSE;
- Yii::import('application.extensions.phpword.PHPWord', 1);
- $time = time();
- $schoolInfo = $this->schoolManager->getSchoolInfo();
- $area = $this->schoolManager->getSchoolAreaFromSchoolInfo($schoolInfo);
- $filename = "{$schoolInfo["school_name"]}{$className}学生的二维码";
- $title = "{$schoolInfo["school_name"]}{$className}学生的二维码";
- $encodeFilename = urlencode($filename);
- $encodeFilename = str_replace("+", "%20", $encodeFilename);
- $userAgent = $_SERVER["HTTP_USER_AGENT"];
- // New Word Document
- $PHPWord = new PHPWord();
- $PHPWord->setDefaultFontName('Tahoma');
- $PHPWord->setDefaultFontSize(9);
- $properties = $PHPWord->getProperties();
- $properties->setCreator('CeeFee');
- $properties->setLastModifiedBy('CeeFee');
- $properties->setCreated($time);
- $properties->setModified($time);
- $properties->setCompany('上海互教教育科技有限公司');
- $properties->setTitle($filename);
- $sectionStyle = array(
- 'orientation' => null,
- 'marginLeft' => 355,
- 'marginRight' => 355,
- 'marginTop' => 900,
- 'marginBottom' => 900
- );
- // Define table style arrays
- $styleTable = array('borderSize' => 0, 'borderColor' => 'ffffff', 'tableAlign' => 'center', 'cellMarginTop'=>80, 'cellMarginLeft'=>80, 'cellMarginRight'=>80, 'cellMarginBottom'=>80);
- // Define cell style arrays
- $styleCell = array('marginTop' => '5', 'valign' => 'center', 'align' => 'center');
- $styleCellBTLR = array('valign' => 'center', 'align' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR);
- // Define font style for first row
- $fontStyle = array('align' => 'center', 'size' => 9);
- // Add table style
- $PHPWord->addTableStyle('myOwnTableStyle', $styleTable);
- if($linedBy == "STUDENT"){
- $rowSize = 8;
- $pageSize = 10;
- $count = 0;
- $rowsCount = 0;
- $pagesCount = 0;
- $repeatedTimes = 1;
- $studentRepeatedTimes = $amount;
- }
- else{
- $rowSize = 8;
- $pageSize = 10;
- $count = 0;
- $rowsCount = 0;
- $pagesCount = 0;
- $repeatedTimes = $amount;
- $studentRepeatedTimes = 1;
- }
- for($j = 0; $j < $repeatedTimes; $j++){
- foreach($students as $student){
- for($i = 0; $i < $studentRepeatedTimes; $i++){
- if($count == $rowSize){
- $count = 0;
- $rowsCount++;
- }
- if(($rowsCount == 0 && $pagesCount == 0) || $rowsCount == $pageSize){
- $section = $PHPWord->createSection($sectionStyle);
- $section->addText(PHPWord_Media::UTF8ToGBK($title), array_merge($fontStyle, array('bold' => TRUE)), array('align' => 'center'));
- $table = $section->addTable('myOwnTableStyle');
- $rowsCount = 0;
- $pagesCount++;
- }
- if($count == 0){
- $table->addRow(300);
- }
- $table->addCell(1420, $styleCell)->addImage($student["pic"]);
- $count++;
- }
- }
- }
- header('Content-Type: application/msword');
- if (preg_match("/MSIE/i", $userAgent) OR preg_match('/Trident/i', $userAgent))
- {
- header('Content-Disposition: attachment; filename="'. $encodeFilename .'.docx"');
- }
- else if (preg_match("/Firefox/i", $userAgent))
- {
- header('Content-Disposition: attachment; filename*="utf8\'\''. $filename .'.docx"');
- }
- else
- {
- header('Content-Disposition: attachment; filename="'. $filename .'.docx"');
- }
- header('Cache-Control: max-age=0');
- $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
- $objWriter->save('php://output');
- }
- public function actionGetSubjectMaterials()
- {
- $toFiltMaterialsIds = array(13, 14, 15, 16);
- $allowedModulesIds = array(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85);
- $subjectId = Req::get("subjectId");
- $rs = Curl::post(Yii::app()->params["material_url"]."/subjectId/{$subjectId}/depth/3");
- $rs = json_decode($rs, true);
- if(!isset($rs["status"]) && $rs){
- foreach($rs as $key => $material){
- if(isset($material["modules"])){
- foreach($material["modules"] as $moduleKey => $module){
- if(empty($module["chapters"]) || (in_array($material["textbook_id"], $toFiltMaterialsIds) && isset($module["module_id"]) && !in_array($module["module_id"], $allowedModulesIds))){
- unset($rs[$key]["modules"][$moduleKey]);
- }
- }
- }
- if(empty($rs[$key]["modules"]))
- unset($rs[$key]);
- }
- }
- $rs = json_encode($rs);
- header("Content-Type: application/json");
- echo $rs;exit;
- }
- // 导入学生
- protected function insertNewStudent($userName_array,$password_array,$realname_array,$userno_array,$_IDX_array,$sex_array,$get_id,$_no_student_id=array())
- {
- /**
- * 如果全是新学生则
- * 添加三张表。分别 spider_business.student,school.student_info,school.student_class_relation
- */
- $student_ids = array();
- //添加 spider_business.student
- $transaction = Yii::app()->businessDb->beginTransaction();//建立事务
- try{
- $sql1 = '';
- $sql = 'INSERT INTO `student` (`student_id`,`username`,`password`,`school_id`,`register_time`,`login_time`,`status`)VALUES';
- foreach($userName_array as $username)
- {
- if($_no_student_id)
- {
- $sql1.='('.$_no_student_id[$username].',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),';
- }else
- {
- //$uuid = getUUID();
- $uuid=getUniqueId($this->schoolId);
- $sql1.='('.$uuid.',"'.$username.'","'.md5(sha1($password_array[$username].'wy').'fengche').'",'.$this->schoolId.','.time().',0,0),';
- $student_ids[$username] = $uuid;
- }
- }
- $sql .= substr($sql1,0,-1).';';
- Yii::app()->businessDb->createCommand($sql)->execute();
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- Yii::app()->jump->error('上传失败,添加学生失败');
- }
- unset($username);
- if($_no_student_id && !$student_ids)
- {
- $student_ids = $_no_student_id;
- }
- try{
- $this->schoolManager->insertStudentInfoAndStudentClass($userName_array,$student_ids,$realname_array,$userno_array,$_IDX_array,$sex_array,$this->schoolId,$get_id);
- }catch(Exception $e)
- {
- $transaction->rollBack();
- Yii::app()->jump->error('上传失败,添加学生失败');
- }
- }
- public function actionSelectdel()
- {
- $classId = Req::post("classId");
- $studentsIds = Req::post("studentsIds");
- if($classId && $studentsIds)
- {
- if(isset(Yii::app()->session['testFlag'])&&(Yii::app()->session['testFlag']==1))
- {
- }else
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',explode(',',$studentsIds));
- $student_paper_data = SStudentPaperRelation::model()->find($criteria);
- if($student_paper_data)
- {
- echo json_encode(array('status'=>-2));exit;
- }
- $http = http('service/student-delete-perm','post', $this->authUsername, explode(',',$studentsIds));
- $response = formatResponse($http);
- if(isset($response['data']) && $response['data']){
- foreach ($response['data'] as $datum){
- if($datum['hasOrder']==1){
- $rs=false;
- $code = 2001;
- $msg = '无法操作,该学生已存在订单数据';
- echo json_encode(array('status'=>-1));exit;
- }
- }
- }
- }
- if(Yii::app()->params['handle_log_on_off']){
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '批量删除学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>json_encode(array('delete'=>array('class_id'=>$classId))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',explode(',',$studentsIds));
- $criteria->addCondition('class_id=:class_id');
- $criteria->addCondition('status=:status');
- $criteria->params[':class_id'] = $classId;
- $criteria->params[':status'] = 0;
- if(SStudentClassRelation::model()->updateAll(array('status'=>1),$criteria)){
- echo json_encode(array('status'=>1));exit;
- }else
- {
- echo json_encode(array('status'=>0));exit;
- }
- }
- }
- public function actionExport()
- {
- $data = array();
- $currSemester = $this->schoolManager->getCurrSemester();
- $criteria = new CDbCriteria;
- $criteria->addCondition('end_time <= :start_time');
- $criteria->params[':start_time'] = $currSemester['start_time'];
- $criteria->limit = 1;
- $criteria->order = "end_time desc";
- $allSemester = Semester::model()->find($criteria);
- $grade = Req::post("grade");
- $class_id = Req::post("class_id");
- $semester_id = Req::post("semester_id");
- $data['grade'] = $grade;
- $data['class_id'] = $class_id;
- $data['semester_id'] = $semester_id;
- if (Yii::app()->request->getIsPostRequest())
- {
- ini_set('memory_limit','200M');
- $grade = Req::post("grade");
- $class_id = Req::post("class_id");
- $semester_id = Req::post("semester_id");
- $class_type = Req::post("class_type");
- $grade_class_array = array();
- $class_array = array();
- $class_name_array = array();
- $class_grade_array = array();
- $class_student_array = array();
- $c_student_array = array();
- $student_class_array = array();
- $student_sex_array = array();
- $student_userno_array = array();
- $student_username_array = array();
- $student_card_array = array();
- $school_student_card_array = array();
- $zhixue_student_card_array = array();
- $id_number_array = array();
- $excel_title = '全年学生信息';
- $is_class = 0;
- $student_serial_number_array = array();
- $criteria = new CDbCriteria();
- $criteria->addCondition('semester_id=:semester_id');
- $criteria->params[':semester_id'] = $semester_id;
- foreach (Yii::app()->params['grade_list'] as $id =>$param){
- $grade_name[$id]=$param['grade_name'];
- }
- $where=array();
- $params=array();
- if($grade){
- $where[]="grade=:grade";
- $params[':grade']=$grade;
- }
- if($class_id){
- $where[]="class_id=:class_id";
- $params[':class_id']=$class_id;
- $is_class=1;
- }
- if($class_type){
- $where[]="class_type=:class_type";
- $params[':class_type']=$class_type;
- }
- if($where){
- $criteria->addCondition(implode(' and ',$where));
- foreach ($params as $key =>$val){
- $criteria->params[$key] = $val;
- }
- }
- if(isset(Yii::app()->params['grade_list'][$grade]))
- {
- $excel_title = Yii::app()->params['grade_list'][$grade]['grade_name'].'全班学生信息';
- }
- $criteria->order = "grade asc,class_id asc";
- $class_data = ClassModel::model()->findAll($criteria);
- unset($criteria);
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_array[$v->class_id] = $v->class_id;
- $class_name_array[$v->class_id] = $v->class_name;
- $class_grade_array[$v->class_id] = $v->grade;
- $grade_class_array[$v->grade][$v->class_id] = array('class_id'=>$v->class_id);
- if($is_class)
- {
- $excel_title = $v->class_name.'学生信息';
- }
- }
- unset($class_data);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_array);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- unset($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- $c_student_array[$v->student_id] = $v->student_id;
- $student_class_array[$v->student_id] = (string)$v->class_id;
- $student_userno_array[$v->student_id] = $v->userno;
- $student_serial_number_array[$v->student_id] = $v->serial_number;
- $class_student_array[$v->class_id][$v->student_id] = $v->student_id;
- }
- unset($student_class_data);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$c_student_array);
- $criteria->order = "class_id asc";
- $student_info_data = SStudentInfo::model()->findAll($criteria);
- unset($criteria);
- if($student_info_data)
- {
- foreach($student_info_data as $v)
- {
- $student_name_array[$v->student_id] = $v->realname;
- $student_sex_array [$v->student_id] = $v->sex;
- $id_number_array[$v->student_id] =$v->id_number;
- }
- }
- unset($student_info_data);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$c_student_array);
- $student_data = BusinessStudent::model()->findAll($criteria);
- unset($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $student_card_array[$v->student_id] = $v->student_card;
- $school_student_card_array[$v->student_id] = $v->school_student_card;
- $zhixue_student_card_array[$v->student_id] = $v->zhixue_student_card;
- }
- }
- $columnArr=array();
- if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){
- $columnArr=array(
- 'A'=>'学生ID',
- 'B'=>'年级',
- 'C'=>'班级',
- 'D'=>'姓名',
- 'E'=>'性别(1男 2女)',
- 'F'=>'准考证号',
- 'G'=>'学校准考证号',
- 'H'=>'智学网准考证号',
- 'I'=>'身份证号'
- );
- }else{
- $columnArr=array(
- 'A'=>'年级',
- 'B'=>'班级',
- 'C'=>'姓名',
- 'D'=>'性别(1男 2女)',
- 'E'=>'准考证号',
- 'F'=>'学校准考证号',
- 'G'=>'智学网准考证号',
- 'H'=>'身份证号'
- );
- }
- unset($student_data);
- unset($c_student_array);
- //
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("学生信息")
- ->setSubject("学生信息")
- ->setDescription("导出学生信息")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
- foreach ($columnArr as $key =>$val){
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue($key.'1', $val);
- }
- $i = 1;
-
- foreach($grade_class_array as $ck=>$class_ids){
- foreach($class_ids as $class_id) {
- if (isset($class_student_array[$class_id['class_id']])) {
- foreach ($class_student_array[$class_id['class_id']] as $v) {
- $i = $i + 1;
- $keys=array_reverse(array_keys($columnArr));
- if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1){
- $objPHPExcel->getActiveSheet(0)->setCellValue(array_pop($keys) . $i, $v.' ',PHPExcel_Cell_DataType::TYPE_STRING);
- }
- $letter=array_pop($keys);
- if (isset($student_class_array[$v]) && isset($class_grade_array[$student_class_array[$v]]) && isset($grade_name[$class_grade_array[$student_class_array[$v]]])) {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $grade_name[$class_grade_array[$student_class_array[$v]]]);
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
- }
- $letter=array_pop($keys);
- if (isset($class_name_array[$class_id['class_id']])) {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $class_name_array[$class_id['class_id']]);
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
- }
- $letter=array_pop($keys);
- if (isset($student_name_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_name_array[$v]);
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, '');
- }
- $letter=array_pop($keys);
- if (isset($student_sex_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, $student_sex_array[$v]);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValue($letter . $i, 1);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- }
- $letter=array_pop($keys);
- if (isset($student_card_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- }
- $letter=array_pop($keys);
- if (isset($school_student_card_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$school_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- }
- $letter=array_pop($keys);
- if (isset($zhixue_student_card_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$zhixue_student_card_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- }
- $letter=array_pop($keys);
- if (isset($id_number_array[$v])) {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, (string)$id_number_array[$v], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- } else {
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($letter . $i, '', PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle($letter . $i)->getNumberFormat()->setFormatCode("@");
- }
- }
- }
- }
- }
- unset($student_card_array);
- unset($school_student_card_array);
- unset($zhixue_student_card_array);
- unset($student_class_array);
- unset($student_userno_array);
- unset($student_serial_number_array);
- unset($class_student_array);
- $objPHPExcel->getActiveSheet()->setTitle($excel_title);
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }else{
- Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/export'));
- }
- }
- }
- $data['semester'] = $allSemester;
- $data['currSemester'] = $currSemester;
- $this->render('export',$data);
- }
- public function actionAjax_class()
- {
- $grade = Req::post("grade");
- $semester_id = Req::post("semester_id");
- $class_type = Req::post("class_type");
- $class_array = array();
- if($grade==0 || !$semester_id)
- {
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- if($class_type){
- $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));
- }else{
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and is_hide=0',array(':semester_id'=>$semester_id,':grade'=>$grade));
- }
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_array[] = $v->attributes;
- }
- echo json_encode(array('status'=>1,'data'=>$class_array));exit;
- }
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- //智学网
- public function actionZhixue_student()
- {
- if (Yii::app()->request->getIsPostRequest())
- {
- $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId.date('Ymdhis',time())));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if(!$file || !isset($file["error"]))
- Yii::app()->jump->error('请选择上传的Excel!');
- if($file["error"] != 0){
- switch($file["error"]){
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- $student_all_array = array();
- $c_class_names = array();
- $class_ids = array();
- $student_name_info = array();
- $student_ids = array();
- $class_name = '';
- $_err = array();
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $c_class_names[$v->class_name] = $v->class_id;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- $student_ids[$v->student_id] = $v->student_id;
- }
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_info_data = SStudentInfo::model()->findAll($criteria);
- if($student_info_data)
- {
- foreach($student_info_data as $v)
- {
- $student_name_info[$v->class_id][trim($v->realname)] = $v->student_id;
- }
- }
- if($sheetData)
- {
- unset($sheetData[1]);
- krsort($sheetData);
- $sheetData = array_reverse($sheetData);
- foreach ($sheetData as $key=>$val)
- {
- if ( empty($val['A']) || empty($val['B']) || empty($val['C']) ){
- continue;
- }
- $class_name = trim($val['A']);
- $user_name = trim($val['C']);
- if(isset($c_class_names[$class_name]) && !empty($c_class_names[$class_name]))
- {
- $class_id = $c_class_names[$class_name];
- if(isset($student_name_info[$class_id]) && !empty($student_name_info[$class_id]) )
- {
- if(isset($student_name_info[$class_id][$user_name]) && !empty($student_name_info[$class_id][$user_name]))
- {
- $b_student_data = BusinessStudent::model()->find('student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name]));
- if($b_student_data)
- {
- $b_student_z_one_data = BusinessStudent::model()->find('zhixue_student_card=:zhixue_student_card',array(':zhixue_student_card'=>$val['B']));
- if($b_student_z_one_data)
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '准考证已存在';
- continue;
- }
- if($b_student_data->zhixue_student_card && $b_student_data->zhixue_student_card == $val['B'])
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '用户准考证已存在';
- continue;
- }else
- {
- //写入
- $flags = BusinessStudent::model()->updateAll(array('zhixue_student_card'=>$val['B']),'student_id=:student_id',array(':student_id'=>$student_name_info[$class_id][$user_name]));
- if($flags)
- {
- continue;
- }else
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '写入失败';
- continue;
- }
- }
- }else
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '用户不存在';
- continue;
- }
- }else
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '用户不存在';
- continue;
- }
- }else
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '此班级不存该用户';
- continue;
- }
- }else
- {
- $_err[$key]['class_name'] = $val['A'];
- $_err[$key]['zhixue_student_card'] = $val['B'];
- $_err[$key]['username'] = $val['C'];
- $_err[$key]['msg'] = '班级不存在';
- continue;
- }
- }
- if($_err)
- {
- $this->zhixue_xls($_err);
- }else
- {
- Yii::app()->jump->error('导入成功');exit;
- }
- }
- }
- $this->render('zhixue_student');
- }
- protected function zhixue_xls($_err)
- {
- if(!$_err)
- {
- return false;
- }
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("智学网学生信息")
- ->setSubject("智学网学生信息")
- ->setDescription("导入智学网学生信息")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '班级')
- ->setCellValue('B1', '准考证号')
- ->setCellValue('C1', '学生姓名')
- ->setCellValue('D1', '错误原因');
- $i = 1;
- foreach($_err as $v)
- {
- $i = $i + 1;
- $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('B' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['username']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['msg']);
- }
- $objPHPExcel->getActiveSheet()->setTitle('导入失败');
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="导入失败.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }
- /**
- * 获取所有老师,排除其他年级的年级主任
- */
- public function actionGetAllTeachers()
- {
-
- if(Yii::app()->params['grade_list']){
- foreach (Yii::app()->params['grade_list'] as $id => $val){
- $grade_arr[$id]=$val['grade_name'];
- }
- }
- $postArr = array(
- 0=>'任课教师',
- 1=>'班主任',
- 2=>'教研组长',
- 3=>'年级主任',
- 4=>'任课教师',
- 5=>'校长',
- );
- $result = array();
- $grade = Req::post('grade');
- if( Yii::app()->params['section']==1){
- $firstSubjectId=3;
- }else{
- $firstSubjectId=array_search(current($this->basicSubject),$this->basicSubject);
- }
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$firstSubjectId));
- if($teacher_data)
- {
- foreach($teacher_data as $v)
- {
- $teacherGrade = $v->grade?$v->grade:0;
- if($v->posts && $v->posts ==3){
- //过滤非本年级的年级主任
- if ($teacherGrade==$grade || !$teacherGrade){
- $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')';
- }
- }else{
- $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')';
- }
- }
- echo json_encode(array('status'=>1,'result'=>$result));exit;
- }
- echo json_encode(array('status'=>0,'result'=>$result));exit;
- }
- /**
- * 根据年级和学科组获取老师
- */
- public function actionGet_subject_teachers()
- {
- $subject_id = Req::post("subject_id");
- $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
- $postArr = array(
- 0=>'任课教师',
- 1=>'班主任',
- 2=>'教研组长',
- 3=>'年级主任',
- 4=>'任课教师',
- 5=>'校长',
- );
- $grade = Req::post('grade');
- $result = array();
- if($subject_id)
- {
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>$subject_id));
- if($teacher_data)
- {
- foreach($teacher_data as $v)
- {
- $teacherGrade = $v->grade?$v->grade:0;
- if($v->posts && $v->posts ==3){
- //过滤非本年级的年级主任
- if ($teacherGrade==$grade || !$teacherGrade){
- $result[$v->teacher_id] = $v->teacher_name.'('.$grade_arr[$teacherGrade].$postArr[$v->posts].')';
- }
- }else{
- $result[$v->teacher_id] = $v->teacher_name.'('.$postArr[$v->posts].')';
- }
- }
- echo json_encode(array('status'=>1,'result'=>$result));exit;
- }
- }
- echo json_encode(array('status'=>0,'result'=>array()));exit;
- }
- public function actionResetpwd()
- {
- if (Yii::app()->request->getIsPostRequest())
- {
- $grade = Req::post("grade");
- $class_id = Req::post("class_id");
- $pwd = Req::post("pwd");
- $class_ids = array();
- $student_ids = array();
- if($pwd)
- {
- $pwd = md5(sha1($pwd . 'wy') . 'fengche');
- }else
- {
- Yii::app()->jump->error('密码能小于6位!');
- }
- if($grade==0 && $class_id==0 )
- {
- if(false !== BusinessStudent::model()->updateAll(array('password'=>$pwd),'school_id=:school_id',array(':school_id'=>$this->schoolId))){
- Yii::app()->jump->success('保存成功<br>',Yii::app()->createUrl('studentinfo/index'));exit;
- }else
- {
- Yii::app()->jump->error('重置失败,密码与新密码一样!');
- }
- }
- $class_data = ClassModel::model()->findAll('grade=:grade',array(':grade'=>$grade));
- foreach($class_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- }
- if($class_ids)
- {
- $criteria = new CDbCriteria();
- if($grade>0 && $class_id==0)
- {
- $criteria->addInCondition('class_id',$class_ids);
- }else
- {
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $class_id;
- }
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v){
- $student_ids[$v->student_id] = $v->student_id;
- }
- if($student_ids)
- {
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- if(false!==BusinessStudent::model()->updateAll(array('password'=>$pwd),$criteria)){
- Yii::app()->jump->success('保存成功<br>',Yii::app()->createUrl('studentinfo/index'));exit;
- }else
- {
- Yii::app()->jump->error('重置失败,密码与新密码一样!');
- }
- }
- }
- }
- Yii::app()->jump->error('重置失败!');
- }
- $data = array();
- $data['semester_id'] = $this->semesterId;
- $this->render('reset',$data);
- }
- public function create_xls($_err)
- {
- if(!$_err)
- {
- return false;
- }
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("导入学校准考证号")
- ->setSubject("导入学校准考证号")
- ->setDescription("导入学校准考证号")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '班级(当前学期唯一)')
- ->setCellValue('B1', '姓名(当前学期唯一)')
- ->setCellValue('C1', '性别(1男 2女)')
- ->setCellValue('D1', '学号(可填)')
- ->setCellValue('E1', '准考证号')
- ->setCellValue('F1', '学校准考证号(可填)')
- ->setCellValue('G1', '错误原因')
- ->setCellValue('H1', '处理建议');
- $i = 1;
- foreach($_err as $v)
- {
- $i = $i + 1;
- $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['A']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['B']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['C']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['D']);
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['E'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['F'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, $v['G']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['H']);
- }
- $objPHPExcel->getActiveSheet()->setTitle('导入学生失败');
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="导入学生失败.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- }
- public function create_import_xls($_err)
- {
- if(!$_err)
- {
- return false;
- }
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("导入学生")
- ->setSubject("导入学生")
- ->setDescription("导入学生")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(5);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '班级(必填)')
- ->setCellValue('B1', '姓名(当前学期唯一)')
- ->setCellValue('C1', '性别(1男 2女)')
- ->setCellValue('D1', '学号(可填')
- ->setCellValue('E1', '准考证号')
- ->setCellValue('F1', '学校准考证号(可填)')
- ->setCellValue('G1', '智学网帐号(可填)')
- ->setCellValue('H1', '错误原因')
- ->setCellValue('I1', '处理建议');
- $i = 1;
- foreach($_err as $v)
- {
- $i = $i + 1;
- $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $v['student_name']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['student_six']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['student_no']);
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('E' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('F' . $i, (string)$v['school_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('G' . $i, (string)$v['zhixue_student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getNumberFormat()->setFormatCode("@");
- $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $v['err_msg']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, $v['so_msg']);
- }
- $objPHPExcel->getActiveSheet()->setTitle('导入学生失败');
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="导入学生失败.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }
-
- public function actionYearReport(){
- @ini_set('memory_limit', '1024M');
- set_time_limit(0);
- ignore_user_abort(true);
- $data = array();
- $error = '';
-
-
- $year = 2018;
- $year_next = $year+1;
- if ($year%4==0&&($year%100!=0 || $year%400==0)){
- $days = 366;
- }else{
- $days = 365;
- }
-
- $weeks = date("W", mktime(0, 0, 0, 12, 28, $year));
- $start_time = mktime(0,0,0,1,1,$year);
- $end_time = mktime(0,0,0,1,1,$year_next);
- $classIds = Req::post('classId');
- // var_dump(dirname(dirname(dirname(__FILE__))));exit;
- if($classIds){
- foreach($classIds as $cclassId){
- //正在生成中
- $sql = "update class set report_status = 1 where class_id = {$cclassId}";
- $res = $this->sConn->createCommand($sql)->execute();
- }
- foreach($classIds as $classId){
- $studentIds = array();
- $pdfArr = array();
- $pdfNames = array();
- //获取班级名称
- $sql = "select class_name from class where class_id = {$classId}";
- $res = $this->sConn->createCommand($sql)->queryRow();
- if($res){
- $class_name = $res['class_name'];
- }
- $sql = "select student_id from student_class_relation where class_id = {$classId} and status = 0";
- $query = $this->sConn->createCommand($sql)->queryAll();//获取班级学生
- if($query){
- foreach($query as $k=>$v){
- $studentIds[] = (string)$v['student_id'];
- }
- unset($query);
- }
- if($studentIds){
-
- foreach($studentIds as $studentId){
- //初始化数据
- $methodIds = array();
- $bestExam = array();
- $totalExamIds = array();
- $totalExamIds_subjectId = array();
-
- $exam_count = array(
- 9=>array(//语文
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 3=>array(//数学
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 8=>array(//英语
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 15=>array(//政治
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 16=>array(//历史
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 17=>array(//地理
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 12=>array(//物理
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 13=>array(//化学
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 14=>array(//生物
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 19=>array(//文综
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- 18=>array(//理综
- 'total_count' => 0,
- 'real_count' => 0,
- 'del_count' => 0
- ),
- );//考试状况
- $method_mes = array(
- 'count' => 0,
- 'name' => array(),
- );//数学考点状况
- $isp_mes = array(
- 'isp_days' => 0,
- 'isp_create' => 0,
- 'isp_down' => 0,
- 'isp_down_ratio' => 0
- );//数学个性化学习宝状况
- $best_exam_mes = array(
- 9=>array(//语文
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 3=>array(//数学
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 8=>array(//英语
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 15=>array(//政治
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 16=>array(//历史
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 17=>array(//地理
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 12=>array(//物理
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 13=>array(//化学
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 14=>array(//生物
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 19=>array(//文综
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- 18=>array(//理综
- 'name' => '',
- 'score' => 0,
- 'scoring' => 0,
- 'grade_no' => 0,
- 'grade_total_no'=>0,
- 'class_no'=>0,
- 'class_total_no'=>0,
- ),
- );//最佳考试
- $score_mes = array(
- 9=>array(//语文
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 3=>array(//数学
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 8=>array(//英语
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 15=>array(//政治
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 16=>array(//历史
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 17=>array(//地理
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 12=>array(//物理
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 13=>array(//化学
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 14=>array(//生物
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 19=>array(//文综
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- 18=>array(//理综
- 'rise_count' => 0,
- 'drop_count' => 0,
- 'class_top_ten' => 0,
- 'unified_top_ten' => 0,
- ),
- );//成绩状况
- $contin_weeks = 1;//连续周数
- $studentId = (string)$studentId;
- $a[] = $studentId;
- //个性化学习宝使用天数
- $res = $this->getHttp('order/coach/days/'.$studentId.'/'.$year, 'get');
- if($res && $res['data']){
- $isp_mes['isp_days'] = $res['data'];
- }
- //获取学生姓名
- $sql = "select realname from student_info where student_id = {$studentId}";
- $res = $this->sConn->createCommand($sql)->queryRow();
- if($res){
- $stu_name = $res['realname'];
- }
- //考试状况
- $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 "
- . "left join exam_group eg on e.exam_group_id = eg.exam_group_id "
- . "left join paper p on p.exam_id = e.exam_id "
- . "left join student_paper_relation spr on e.exam_id = spr.exam_id "
- . "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} "
- . "order by e.create_time asc";
- $query = $this->sConn->createCommand($sql)->queryAll();
- if($query){
- foreach($query as $k=>$v){
- //考试状况
- if(in_array($v['subject_id'],$this->mathSubjectId)){
- $totalExamIds_subjectId[$v['exam_id']] = 3;
- $exam_count[3]['total_count'] ++;
- if($v['is_del'] == 1){
- $exam_count[3]['del_count'] ++;
- }else{
- $exam_count[3]['real_count'] ++;
- }
- //考点状况
- $methodArr = explode(",",$v['method_ids']);
- if($methodArr){
- foreach($methodArr as $method){
- if(is_numeric($method)){
- $methodIds[] = $method;
- }
- }
- }
- //个性化学习宝状况
- if($v['is_isp_pdf'] == 1){
- $isp_mes['isp_create'] ++;
- if($v['is_two_isp_download'] == 1){
- $isp_mes['isp_down'] ++;
- }
- }
- if($v['is_wbisp_pdf'] == 1){
- $isp_mes['isp_create'] ++;
- if($v['is_three_isp_download'] == 1){
- $isp_mes['isp_down'] ++;
- }
- }
- //最佳考试
- $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
- $bestExam[$v['exam_group_id']]['name'] = $v['name'];
- $bestExam[$v['exam_group_id']]['subject_id'] = 3;
- $bestExam[$v['exam_group_id']]['score'] = $v['score'];
- $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
- }else{
- $totalExamIds_subjectId[$v['exam_id']] = $v['subject_id'];
- $exam_count[$v['subject_id']]['total_count'] ++;
- if($v['is_del'] == 1){
- $exam_count[$v['subject_id']]['del_count'] ++;
- }else{
- $exam_count[$v['subject_id']]['real_count'] ++;
- }
- //最佳考试
- $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
- $bestExam[$v['exam_group_id']]['name'] = $v['name'];
- $bestExam[$v['exam_group_id']]['subject_id'] = $v['subject_id'];
- $bestExam[$v['exam_group_id']]['score'] = $v['score'];
- $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
- }
- //连续周数
- $totalExamIds[] = $v['exam_id'];
- if(!isset($current_week)){
- $current_week = date("W",$v['create_time']);
- }else{
- $week_cur = date("W",$v['create_time']);
- if($week_cur = $current_week + 1){
- $contin_weeks ++;
- }
- }
- }
- $totalExamIds = array_unique($totalExamIds);
- //考点状况
- if($methodIds){
- $count_methods = array();
- foreach($methodIds as $kmed=>$vmed){
- if(!isset($count_methods[$vmed])){
- $count_methods[$vmed] = 1;
- }else{
- $count_methods[$vmed]++;
- }
- }
- $method_mes['count'] = count(array_unique($methodIds));
- unset($methodIds);
- if($count_methods){
- arsort($count_methods);
- $i = 1;
- $methodArrIds = array();
- foreach($count_methods as $k=>$v){
- if($i < 6){
- $methodArrIds[] = $k;
- }
- $i++;
- }
- $methods = $this->apiPost('/special/methods', array('methodIds' => $methodArrIds));
- if($methods && !isset($methods->error)){
- foreach($methods as $k=>$v){
- $method_mes['name'][] = $v->method_name;
- }
- }
- }
- }
- //数学个性化学习宝状况
- if($isp_mes['isp_down'] && $isp_mes['isp_create']){
- $isp_mes['isp_down_ratio'] = round($isp_mes['isp_down']/$isp_mes['isp_create'],4) * 100 .'%';
- }
- //最佳考试信息
- if($bestExam){
- $best_exam_msg = array();
- foreach($bestExam as $k=>$v){
- //获取groupId对应的examId
- $examIds = array();
- $sql = "select exam_id from exam where exam_group_id = {$k}";
- $meg = $this->sConn->createCommand($sql)->queryAll();
- if($meg){
- foreach($meg as $edata){
- $examIds[] = $edata['exam_id'];
- }
- }
- if($examIds){
- foreach($examIds as $examIdSc){
- $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$examIdSc} order by scoring desc";
- $msg = $this->sConn->createCommand($sql)->queryAll();
- if($msg){
- $no = 1;
- $no_grade = 1;//年级排名
- $no_class = 1;//班级排名
- $stu_no_grade = 1;//学生年级排名
- $stu_no_class = 1;//学生班级排名
- $total_grade = 0;
- $total_real_grade = 0;
- $total_class = 0;
- $total_real_class = 0;
- foreach($msg as $kk=>$vv){
- if($no == 1){
- $current_scoring = $vv['scoring'];
- }else{
- if($vv['scoring'] < $current_scoring){
- $no_grade ++;
- }
- }
- if($vv['is_del'] == 0){
- $total_real_grade ++;
- }
- if((string)$vv['class_id'] === (string)$classId){
- if(!isset($current_class_scoring)){
- $current_class_scoring = $vv['scoring'];
- }else{
- if($vv['scoring'] < $current_class_scoring){
- $no_class ++;
- }
- }
- if($vv['is_del'] == 0){
- $total_real_class ++;
- }
- $total_class ++;
- }
- if((string)$vv['student_id'] === (string)$studentId){
- $stu_no_grade = $no_grade;
- $stu_no_class = $no_class;
- }
- $total_grade ++;
- $no++;
- }
- //最佳考试定义:数值“年级排名/年级有效人数”最小的一次考试
- if(!isset($best_exam_msg[$v['subject_id']])){
- $best_exam_msg[$v['subject_id']] = round($stu_no_grade/$total_real_grade,4);
- $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
- $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
- $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
- $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
- $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
- $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
- $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
- }else{
- $tep = round($stu_no_grade/$total_real_grade,4);
- if($tep < $best_exam_msg[$v['subject_id']]){
- $best_exam_msg[$v['subject_id']] = $tep;
- $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
- $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
- $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
- $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
- $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
- $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
- $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
- }
- }
- //成绩状况(统计班级上升下降次数,班级前十)
- if($stu_no_class <= $total_real_class * 0.1){
- $score_mes[$v['subject_id']]['class_top_ten']++;
- }
- if(!isset($current_class_no)){
- $current_class_no = $stu_no_class;
- }else{
- if($stu_no_class > $current_class_no){
- $score_mes[$v['subject_id']]['rise_count']++;
- }else if($stu_no_class < $current_class_no){
- $score_mes[$v['subject_id']]['drop_count']++;
- }
- }
- }
- unset($msg);
- }
- }
- }
- }
- //统考排名
- $sql = "select examinfo from cylet where cylet_type = 2 and create_time > {$start_time} and create_time < {$end_time}";
- $json_data = $this->sConn->createCommand($sql)->queryAll();
- $cylet_exam_ids = array();
- if($json_data){
- foreach($json_data as $cylet){
- $cyletArr = json_decode($cylet['examinfo'],true);
- if(isset($cyletArr['exam'])){
- foreach($cyletArr['exam'] as $examCy){
- if(in_array($examCy,$totalExamIds)){
- $cylet_exam_ids[] = $examCy;
- }
- }
- }
- }
- unset($json_data);
- }
- if($cylet_exam_ids){
- foreach($cylet_exam_ids as $cexamId){
- $this->sConn = $this->getDbConnection();
- $sql = "select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$cexamId} order by scoring desc";
- $msg2 = $this->sConn->createCommand($sql)->queryAll();
- if($msg2){
- $no_cylet_grade = 1;//年级排名
- $stu_no_cylet_grade = 1;//学生年级排名
- $total_cylet_grade = 0;
- $total_cylet_real_grade = 0;
- foreach($msg2 as $cyScore){
- if($cyScore['is_del'] == 0){
- $total_cylet_real_grade ++;
- }
- $total_cylet_grade ++;
- if(!isset($current_cylet_scoring)){
- $current_cylet_scoring = $cyScore['scoring'];
- }else{
- if($cyScore['scoring'] < $current_cylet_scoring){
- $no_cylet_grade ++;
- }
- }
- if((string)$vv['student_id'] === (string)$studentId){
- $stu_no_cylet_grade = $no_cylet_grade;
- }
- }
- if($stu_no_cylet_grade <= $total_cylet_real_grade * 0.1){
- $score_mes[$totalExamIds_subjectId[$cexamId]]['unified_top_ten']++;
- }
- }
- }
- }
- }
- unset($query);
- $data['stu_name'] = isset($stu_name)?$stu_name:'';//学生姓名
- $data['class_name'] = isset($class_name)?$class_name:'';//班级名称
- $data['year'] = $year;
- $data['year_next'] = $year_next;
- $data['days'] = $days;
- $data['weeks'] = $weeks;
- $data['contin_weeks'] = $contin_weeks;
- $data['exam_count'] = $exam_count;//考试状况
- $data['score_mes'] = $score_mes;//成绩状况
- $data['best_exam_mes'] = $best_exam_mes;//最佳考试
- $data['method_mes'] = $method_mes;//考点状况
- $data['isp_mes'] = $isp_mes;//个性化学习宝状况
- //print_r($data);exit;
- $html = $this->renderPartial("year_report", $data, true);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/yearReport/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/assets/pdf/yearReport/' . $this->schoolId . "/";
- if (!is_dir($htmlpath)) {
- if (!mkdir($htmlpath, 0777, true)) {
- exit('Create directory fail: ' . $htmlpath);
- }
- }if (!is_dir($pdfpath)) {
- if (!mkdir($pdfpath, 0777, true)) {
- exit('Create directory fail1: ' . $pdfpath);
- }
- }
- $htmlpath.=$studentId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- $htmlurl = '/assets/' . $studentId . ".html"; //访问HTML的路径
- if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
- $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
- // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
- // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
- // $pdffname=iconv("UTF-8", "GBK",$pdffname);
- $pdffname=$classId."-".$studentId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " file://" . $htmlpath
- . " {$pdfpath}"
- . " 176mm*250mm ''";
- } else {
- // echo Yii::app()->params['phantomjs'];exit;
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
- // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
- // $pdffname=iconv("UTF-8", "GBK",$pdffname);
- $pdffname=$classId.'-'.$studentId.".pdf";
- // $pdffname=iconv("UTF-8", "GBK",$pdffname);
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $top_meg = $class_name.'-'.$stu_name."-年度使用报告";
- // $top_meg=iconv("UTF-8", "GBK",$top_meg);
- // echo $top_meg;exit;
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm {$top_meg}";
- }
- // echo $commond;exit;
- $set_charset = 'export LANG=en_US.UTF-8;';
- exec($set_charset.$commond, $res, $code);
- if(isset($res[0])){
- if (strpos($res[0], 'succeed') !== false) {
- if ($this->file_exists($pdfpath)) {
- $pdfArr[] = $pdfpath;
- $pdfNames[] = $stu_name;
- }
- } else {
- }
- @unlink($htmlpath);
- }
- }
- if($pdfArr){
- $report_name = $class_name.$year."年度报告.zip";
- $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/year_report/'.$this->schoolId."/"; //存放生成的PDF路径
- if (!is_dir($filepath)) {
- if (!mkdir($filepath, 0777, true)) {
- exit('Create directory fail1: ' . $filepath);
- }
- }
- $filename = dirname(dirname(dirname(__FILE__))).'/upload/year_report/'.$this->schoolId."/".$classId.'_'.$year.".zip"; //最终生成的文件名(含路径)
- //$filename=iconv("UTF-8", "GBK",$filename);
- // var_dump($filename);exit;
- $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
- if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
- Yii::app()->jump->error('无法打开文件,或者文件创建失败');
- }
- foreach ($pdfArr as $k=>$val) {
- $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
- $res=$zip->addFile($val,$classId.$pdfNames[$k].'.pdf');
- @unlink($val);
- }
- $zip->close();//关闭
-
- //生成完成
- // var_dump($filename);exit;
- $filename = addslashes($filename);
- $sql = "update class set report_status = 2,report_url='{$filename}' where class_id = {$classId}";
- $res = $this->sConn->createCommand($sql)->execute();
- }else{
- $error = '生成pdf失败';
- }
- }else{
- $error = '暂无学生';
- }
- }
- }else{
- $error = '班级错误';
- }
- // header('Content-Type: application/json');
- if (!$error) {
- echo json_encode(array("status" => 0, "error" => ""));
- exit;
- } else {
- echo json_encode(array("status" => 1, "error" => $error));
- exit;
- }
-
- }
-
-
- public function actiondown_load_yearreport() {
- $classId = safe_replace(Yii::app()->request->getQuery('classId'));
- $sql = "select report_url,class_name from class where class_id = {$classId}";
- $data = $this->sConn->createCommand($sql)->queryRow();
- $filepath = $data['report_url'];
- if($filepath){
- if ($this->check_zip($filepath)) {
- Header("Content-type:application/zip");
- Header("Accept-Ranges: bytes");
- Header("Accept-Length: " . filesize($filepath));
- Header("Content-Disposition: attachment; filename=".$data['class_name']."年度总结报告.zip"); // 输出文件内容
- flush();// 刷新内容
- $file=fopen($filepath,"r");
- $download_rate=600;
- while (!feof($file)){
- print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者
- flush();// flush 内容输出到浏览器端
- sleep(1);// 终端1秒后继续
- }
- } else {
- Yii::app()->jump->error('尚未生成');
- }
- }else{
- Yii::app()->jump->error('尚未生成');
- }
- }
-
- private function check_zip($file_path) {
- if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") {
- if (file_exists($file_path)) {
- return true;
- }
- }
- return false;
- }
- /**
- * 获取接口数据
- * @param $url
- * @param $method
- * @param array $params
- * @return array
- */
- private function getHttp($url,$method,$params = array()){
- $res = http($url, $method, $this->authUsername, $params);
- $res = $this->handleRes($res);
- return $res;
- }
- /**
- * 处理接口返回的数据
- * @param $res
- * @return array
- */
- public function handleRes($res){
- $result = array(
- 'status' => 0,
- 'data' => array(),
- 'msg' => '暂无数据',
- );
- if($res){
- $res = json_decode($res,true);
- if(isset($res['errCode']) && $res['errCode'] == '00'){
- $result['status'] = 1;
- $result['data'] = isset($res['data'])?$res['data']:array();
- $result['msg'] = $res['errMsg'];
- }else{
- if(isset($res['errMsg'])){
- $result['msg'] = $res['errMsg'];
- }
- }
- }
- unset($res);
- return $result;
- }
-
- public function actionAjaxGetClassesByGrade(){
-
- $grade = Req::get("grade");
- $page = Req::get("page");
- $result = array();
- $error = array();
- $con = array();
- if(!$grade){
- $grade = 1;
- }
- if(!$page){
- $page = 1;
- }
- $semesterId = $this->semesterId;
- $con[] = "c.grade = {$grade}";
- $con[] = "c.semester_id = {$semesterId}";
- $rs = $this->schoolManager->getClassesDetailListre($con,6);
- if($rs){
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- $classId = $v['class_id'];
- $sql = "select count(*) count from student_class_relation where class_id = {$classId} and status = 0";
- $count = $this->sConn->createCommand($sql)->queryRow();
- $rs['rs'][$k]['stu_count'] = $count['count'];
- }
- $result['rs'] = $rs['rs'];
- $result['page'] = $rs['pager'];
-
-
- $pages_index = $this->widget('CLinkPager', array(
- 'header' => '',
- 'firstPageLabel'=> '首页',
- 'lastPageLabel' => '末页',
- 'prevPageLabel' => '上一页',
- 'nextPageLabel' => '下一页',
- 'pages' => $result['page'],
- 'maxButtonCount'=> 5,
- ),true);
-
- $pages_index = preg_replace('/<a .*?href="(.*?)".*?>/is',"<a href='javascript:void(0)'>",$pages_index);
- $result['pages_index'] = $pages_index;
- echo json_encode(array('status'=>1,'data'=>$result));exit;
- }else{
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- }else{
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
-
- }
-
- //////设置教学进度
- public function actionSettingProgress(){
- $data = array();
- $textbookNames = array();
- $subjectId = Req::get("subjectId")?Req::get("subjectId"):3;
- $grade = Req::get("grade")?Req::get("grade"):1;
- $proId = (int)Req::get("proId");
- $edit = (int)Req::get("edit");
- $data['module_id'] = '';
- $data['chapter_id'] = '';
- $data['section_id'] = '';
- //当前日期
- $sdefaultDate = date("Y-m-d");
- //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
- $first=1;
- //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
- $w=date('w',strtotime($sdefaultDate));
- //获取本周开始日期,如果$w是0,则表示周日,减去 6 天
- $data['start_time']=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
- //本周结束日期
- $data['end_time']=date('Y-m-d',strtotime("{$data['start_time']} +6 days"));
- $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'";
- $timeRange = $this->sConn->createCommand($sql)->queryRow();
- if($timeRange){
- $data['sem_start_time'] = date("Y-m-d",$timeRange['start_time']);
- $data['sem_end_time'] = date("Y-m-d",$timeRange['end_time']);
- }else{
- $data['sem_start_time'] = '';
- $data['sem_end_time'] = '';
- }
- if($proId && $edit){
- $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}";
- $dataArr = $this->sConn->createCommand($sql)->queryRow();
- $subjectId = $dataArr['subject_id'];
- $grade = $dataArr['grade'];
- $data['classId'] = $dataArr['class_id'];
- $sql = "select class_name from class where class_id = '{$dataArr['class_id']}'";
- $classNameArr = $this->sConn->createCommand($sql)->queryRow();
- // var_dump($classNameArr);exit;
- $data['className'] = $classNameArr['class_name'];
- $data['textbookId'] = $dataArr['textbook_id'];
- $data['textbook_name'] = $dataArr['textbook_name'];
- $data['module_id'] = $dataArr['module_id'];
- $data['chapter_id'] = $dataArr['chapter_id'];
- $data['section_id'] = $dataArr['section_id'];
- $data['start_time'] = date("Y-m-d",$dataArr['start_time']);
- $data['end_time'] = date("Y-m-d",$dataArr['end_time']);
- }
- if($subjectId == 8){
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- foreach ($textbookData as $doc) {
- //var_dump($doc->attributes);exit;
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- $textbookNames[$value['textbook_id']] = $value['name'];
- }
- }
- }
- }
-
- }else{
- if($grade == 3){
- $newSubjectId = 6;
- }else{
- $newSubjectId = 3;
- }
- $textbookTree = $this->apiPost('/textbook/tree', array(
- 'subjectId' => $newSubjectId,
- 'depth' => 1
- ));
- if (! $textbookTree) {
- $error[] = '接口错误';
- } elseif (isset($textbookTree->error)) {
- $error[] = '接口错误';
- } else {
- foreach ($textbookTree as $textbook) {
- $textbookNames[$textbook->textbook_id] = $textbook->textbook_name;
- }
- }
- }
- $data['edit'] = $edit;
- // echo $edit;exit;
- $data['subjectId'] = $subjectId;
- $data['grade'] = $grade;
- $data['textbookName'] = $textbookNames;
- //var_dump($data);exit;
- $this->render('teach_progress',$data);
- }
- /////查看历史教学进度
- public function actionViewHistoryProgress(){
- //echo 11;exit;
- $data = array();
- $classIdsInSem = array();
- $subjectId = Req::get("subjectId")?Req::get("subjectId"):3;
- $grade = Req::get("grade")?Req::get("grade"):1;
- $classId = Req::get("classId")?Req::get("classId"):'';
- $startTime = Req::get("start_time")?Req::get("start_time"):'';
- $endTime = Req::get("end_time")?Req::get("end_time"):'';
- $page = (int)Req::get("page")?(int)Req::get("page"):1;
- $pagesize = 10;
- $status = (int)Req::get("status")?(int)Req::get("status"):0;
- $sql = "select start_time,end_time from semester where semester_id = '{$this->semesterId}'";
- $timeRange = $this->sConn->createCommand($sql)->queryRow();
- if($startTime){
- $startTimeStr = $startTime;
- $startTime = strtotime($startTime);
- }else{
- $startTimeStr = date("Y-m-d",$timeRange['start_time']);
- $startTime = $timeRange['start_time'];
- }
- if($endTime){
- $endTimeStr = $endTime;
- $endTime = strtotime($endTime);
- }else{
- $endTimeStr = date("Y-m-d",$timeRange['end_time']);
- $endTime = $timeRange['end_time'];
- }
- //var_dump($timeRange);exit;
- $classIdToName = array();
- $sql = "select class_id,class_name from class where grade = {$grade} and semester_id = {$this->semesterId}";
- $classData = $this->sConn->createCommand($sql)->queryAll();
- if($classData){
- $data['classmeg'] = $classData;
- foreach($classData as $class){
- $classIdToName[$class['class_id']] = $class['class_name'];
- $classIdsInSem[] = $class['class_id'];
- }
- }else{
- $data['classmeg'] = array();
- }
- if($classIdsInSem){
- $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} and end_time>={$startTime}) and class_id in (".implode(',',$classIdsInSem).")";
- }else{
- $condition = "subject_id = {$subjectId} and grade = {$grade} and (start_time<={$endTime} or end_time>={$startTime}) and 1=2";
- }
-
- $orderby = " order by start_time desc";
- if($status == 1){//开始时间倒序
- $orderby = " order by start_time desc";
- }else if($status == 2){//开始时间升序
- $orderby = " order by start_time asc";
- }else if($status == 3){//创建时间倒序
- $orderby = " order by create_time desc";
- }else if($status == 4){//创建时间升序
- $orderby = " order by create_time asc";
- }
- if($classId){
- $condition .= " and class_id = {$classId}";
- }
- $condition .= $orderby;
- $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;
- $rs = $this->schoolManager->getTeachProgress($sql,$pagesize);
-
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- if(isset($classIdToName[$v['class_id']])){
- $rs['rs'][$k]['class_name'] = $classIdToName[$v['class_id']];
- }else{
- $rs['rs'][$k]['class_name'] = '';
- }
- $rs['rs'][$k]['progress_name'] = '';
- if($subjectId == 3){
- if($v['module_id']){
- $mArr = explode(',', $v['module_id']);
- foreach($mArr as $moduleId){
- $moduleMessage = $this->apiPost('/textbook/module', array('moduleId' => $moduleId,'depth' => 1));
- if ($moduleMessage && !isset($moduleMessage->error)) {
- //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$moduleMessage->module_name).',';
- $rs['rs'][$k]['progress_name'] .= strip_tags($moduleMessage->module_name).',';
- }
- }
- }
- if($v['chapter_id']){
- $cArr = explode(',', $v['chapter_id']);
- foreach($cArr as $chapterId){
- $chapterMessage = $this->apiPost('/textbook/chapter', array('chapterId' => $chapterId,'depth' => 1));
- if ($chapterMessage && !isset($chapterMessage->error)) {
- //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$chapterMessage->chapter_name).',';
- $rs['rs'][$k]['progress_name'] .= strip_tags($chapterMessage->chapter_name).',';
- }
- }
- }
- if($v['section_id']){
- $sArr = explode(',', $v['section_id']);
- foreach($sArr as $sectionId){
- $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId,'depth' => 1));
- if ($sectionMessage && !isset($sectionMessage->error)) {
- //$rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$sectionMessage->section_name).',';
- $rs['rs'][$k]['progress_name'] .= strip_tags($sectionMessage->section_name).',';
- }
- }
- }
- }else if($subjectId == 8){
- if($v['chapter_id']){
- $cArr = explode(',', $v['chapter_id']);
- }else{
- $cArr = array();
- }
- if($v['module_id']){
- $mArr = explode(',', $v['module_id']);
- }else{
- $mArr = array();
- }
- if($v['section_id']){
- $sArr = explode(',', $v['section_id']);
- }else{
- $sArr = array();
- }
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- foreach ($textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $km=>$vm){
- if(in_array($vm['textbook_module_id'],$mArr,true)){
- $rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$vm['name']).',';
- }
- if(isset($vm['unit']) && $vm['unit']){
- foreach($vm['unit'] as $kk=>$vv){
- if(in_array($vv['textbook_unit_id'],$cArr,true)){
- $rs['rs'][$k]['progress_name'] .= str_replace(array('<p>','</p>'),array('',''),$vv['name']).',';
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- $data['status'] = $status;
- $data['start_time'] = $startTimeStr;
- $data['end_time'] = $endTimeStr;
- $data['subjectId'] = $subjectId;
- $data['classId'] = $classId;
- $data['grade'] = $grade;
- $data['page'] = $page;
- $data['pagesize'] = $pagesize;
- $data['rs'] = $rs;
- //print_r($data);exit;
- $this->render('view_history_progress',$data);
- }
-
- ////教学进度分层查看班级
- public function actionAjaxGetClassesBylevel(){
- $data = array();
- $error = array();
- $classMeg = array();
- $grade = (int)Req::post("grade");
- $subjectId = (int)Req::post("subjectId");
- if($grade > 0){
- $textbook_class = array();
- $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";
- $textbook_class_arr = $this->sConn->createCommand($sql)->queryAll();
- if($textbook_class_arr){
- foreach($textbook_class_arr as $k=>$v){
- $textbook_class[$v['class_id']]['textbook_id'] = $v['textbook_id'];
- $textbook_class[$v['class_id']]['textbook_name'] = $v['textbook_name'];
- }
- }
- //var_dump($textbook_class);exit;
- $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";
- $classData = $this->sConn->createCommand($sql)->queryAll();
- if($classData){
- foreach($classData as $k=>$v){
- if(isset($textbook_class[$v['class_id']])){
- $v['textbook_id'] = $textbook_class[$v['class_id']]['textbook_id'];
- $v['textbook_name'] = $textbook_class[$v['class_id']]['textbook_name'];
- }else{
- $v['textbook_id'] = 0;
- $v['textbook_name'] = '';
- }
- $classMeg[$v['level']][] = $v;
- }
- }
- }else{
- $error[] = '年级错误';
- }
-
- if($error){
- echo json_encode(array('status'=>0,'data'=>$classMeg,'error'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1,'data'=>$classMeg));exit;
- }
- }
-
- //知识图谱
- public function actionAjaxGetSectionsByTextbookId(){
- $error = array();
- $result = array();
- $textbookId = (int)Req::post("textbookId");
- $subjectId = (int)Req::post("subjectId");
- if (!$textbookId) {
- $error[] = '请指定教材ID!';
- }
- if (!$subjectId) {
- $error[] = '请指定学科!';
- }
- if(!$error){
- if($subjectId == 3){
- $textbooks = $this->apiPost('/textbook/detail', array('textbookId' => $textbookId, 'depth' => 4));
- if (! $textbooks) {
- $error[] = '接口错误';
- } elseif (isset($textbooks->error)) {
- $error[] = '接口错误';
- } else {
- if(isset($textbooks->modules) && $textbooks->modules){
- $a = 0;
- foreach($textbooks->modules as $k=>$v){
- $result[$a]['module_id'] = $v->module_id;
- $result[$a]['module_name'] = $v->module_name;
- if(isset($v->chapters) && $v->chapters){
- $b = 0;
- foreach($v->chapters as $cha){
- $result[$a]['chapters'][$b]['chapter_id'] = $cha->chapter_id;
- $result[$a]['chapters'][$b]['chapter_name'] = $cha->chapter_name;
- if(isset($cha->sections) && $cha->sections){
- $c = 0 ;
- foreach($cha->sections as $sec){
- $result[$a]['chapters'][$b]['sections'][$c]['section_id'] = $sec->section_id;
- $result[$a]['chapters'][$b]['sections'][$c]['section_name'] = $sec->section_name;
- $c++;
- }
- }
- $b++;
- }
- }
- $a++;
- }
- }
- }
- }else if($subjectId == 8){
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- foreach ($textbookData as $doc) {
-
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if($value['textbook_id'] == $textbookId){
- if(isset($value['module']) && $value['module']){
- $a = 0;
- foreach($value['module'] as $k=>$v){
- $result[$a]['module_id'] = $v['textbook_module_id'];
- $result[$a]['module_name'] = $v['name'];
- if(isset($v['unit']) && $v['unit']){
- $b = 0;
- foreach($v['unit'] as $kk=>$vv){
- $result[$a]['chapters'][$b]['chapter_id'] = $vv['textbook_unit_id'];
- $result[$a]['chapters'][$b]['chapter_name'] = $vv['name'];
- $b++;
- }
- }
- $a++;
- }
- }
- }
- }
- }
- }
- }
- }
-
- if ($error) {
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
- } else {
- echo json_encode(array('status'=>1,'data'=>$result));
- }
- }
-
- //插入教学进度数据
- public function actionAjaxInsertTeachProgress(){
- $error = array();
- $subjectId = (int)Req::post("subjectId");
- $grade = (int)Req::post("grade");
- $classIds = Req::post("classIds");
- $startTimeUnix = (int)Req::post("startTimeUnix");
- $endTimeUnix = (int)Req::post("endTimeUnix");
- $moduleArr = Req::post("moduleArr")?Req::post("moduleArr"):array();
- $chapterArr = Req::post("chapterArr")?Req::post("chapterArr"):array();
- $sectionArr = Req::post("sectionArr")?Req::post("sectionArr"):array();
- $textbookId = (int)Req::post("textbookId");
- $textbookName = (string)Req::post("textbookName");
- $selectSectionIds = Req::post("selectSectionIds")?Req::post("selectSectionIds"):array();
- $methodIds = '';
- $kpIds = '';
- if(!$subjectId){
- $error[] = "请选择科目";
- }
- if(!$grade){
- $error[] = "请选择年级";
- }
- if(!$classIds){
- $error[] = "请选择班级";
- }
- if(!$startTimeUnix){
- $error[] = "请选择开始时间";
- }
- if(!$endTimeUnix){
- $error[] = "请选择结束时间";
- }
- if(!$textbookId){
- $error[] = "请选择教材";
- }
- if(!$textbookName){
- $error[] = "请选择教材名称";
- }
- if($selectSectionIds && $subjectId == 3){
- $methodArr = array();
- $kpArr = array();
- foreach($selectSectionIds as $v){
- foreach($v as $sectionId){
- if((int)$sectionId > 0){
- $sectionMessage = $this->apiPost('/textbook/section', array('sectionId' => $sectionId));
- if (! $sectionMessage) {
- $error[] = '接口错误1';
- } elseif (isset($sectionMessage->error)) {
- $error[] = '接口错误';
- } else {
- if(isset($sectionMessage->kps) && $sectionMessage->kps){
- foreach($sectionMessage->kps as $kk=>$vv){
- $kpArr[] = $vv->kp_id;
- if(isset($vv->methods) && $vv->methods){
- foreach($vv->methods as $med){
- if(isset($med->method_id) && $med->method_id){
- $methodArr[] = $med->method_id;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if($methodArr){
- $methodIds = implode(',', $methodArr);
- }
- if($kpArr){
- $kpIds = implode(',', $kpArr);
- }
- }
- if(!$error){
- $time =time();
- $transaction = $this->sConn->beginTransaction();
- try{
- foreach($classIds as $classId){
- $this->sConn->createCommand("update teach_progress_class set is_new = 0 where class_id = {$classId} and subject_id={$subjectId}")->execute();
- $this->sConn->createCommand()->insert('teach_progress_class',array(
- 'class_id' => $classId,
- 'subject_id' => $subjectId,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'textbook_id' => $textbookId,
- 'textbook_name' => $textbookName,
- 'create_time' => $time,
- 'start_time' => $startTimeUnix,
- 'end_time' => $endTimeUnix,
- 'module_id' => $moduleArr? implode(",", $moduleArr):'',
- 'chapter_id' => $chapterArr? implode(",", $chapterArr):'',
- 'section_id' => $sectionArr? implode(",", $sectionArr):'',
- 'kp_ids_selected' =>$kpIds,
- 'method_ids_selected' => $methodIds,
- 'is_new' => 1
- ));
-
-
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if ($error) {
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
- } else {
- echo json_encode(array('status'=>1));
- }
- }
- //删除教学进度
- public function actionAjaxDelTeachProgress(){
- $error = array();
- $progressId = (int)Req::post("progressId");
- if(!$progressId){
- $error[] = "请指定教学进度";
- }
- if(!$error){
- $transaction = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand("delete from teach_progress_class where id = {$progressId}")->execute();
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if ($error) {
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
- } else {
- echo json_encode(array('status'=>1));
- }
- }
- //加载班主任
- public function actionLoadTeacher(){
- $keyword = safe_replace(Yii::app()->request->getParam('keyword'));
- $result['status']=0;
- $data=$this->schoolManager->loadTeacher($keyword,0);
- $teachers=array();
- if($data){
- foreach ($data as $key => $v){
- if(!in_array($v['posts'],array(1,2,3,5))){
- continue;
- }
- $teachers[]=$v;
- }
- }
- $result['data']=$teachers;
- $result['status']=1;
- exit(json_encode($result));
- }
- //走班设置
- public function actionClassShift(){
- $setting=$this->schoolManager->getClassShift($this->semesterId);
- $data['setting']=$setting;
- if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
- $data['subject']=Yii::app()->params['subjectId'];
- unset($data['subject'][6]);
- unset($data['subject'][51]);
- unset($data['subject'][18]);
- unset($data['subject'][19]);
- if(isset($data['subject'][20])) unset($data['subject'][20]);
- }
- $this->render('classified',$data);
- }
- //新增走班学科
- public function actionAddClassified(){
- $grade = (int)Req::post("grade");
- $subject = Req::post("subject");
- $result['status']=0;
- //debug($subject);
- if(!$grade){
- $result['msg']='请选择年级';
- exit(json_encode($result));
- }
- if(!$subject){
- $result['msg']='请选择学科';
- exit(json_encode($result));
- }
- $semesterId=$this->semesterId;
- $insertArr=array();
- foreach ($subject as $val){
- $check=$this->schoolManager->getClassifiedBySubject($grade,$val,$semesterId);
- if($check){
- $result['msg']='学科:'.Yii::app()->params['subjectId'][$val]."已添加,请勿重复添加";
- exit(json_encode($result));
- }
- $insertArr[]=array(
- 'grade'=>$grade,
- 'subject_id'=>$val,
- 'status'=>0,
- 'semester_id'=>$semesterId
- );
- }
- if($insertArr){
- if($this->schoolManager->insertClassified($insertArr)){
- $result['status']=1;
- exit(json_encode($result));
- }
- }
- exit(json_encode($result));
- }
- //学科走班状态设置
- public function actionUpdateClassified(){
- $grade = (int)Req::post("grade");
- $subject = Req::post("subject");
- $type=Req::post('type');
- $semesterId= $this->semesterId;
- $result['status']=0;
- $rs=$this->schoolManager->updateClassifiedBySubject($grade,$subject,$semesterId,$type);
- if($rs){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //添加教学班
- public function actionAddClass(){
- checkAuthority(2); // 非当前使用学期无法操作
- $data = array();
- $teachers = $this->schoolManager->getTeachers();
- $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- if (Yii::app()->request->getIsPostRequest()){
- $class_name = trim(Req::post("class_name"));
- $mid_array = array();
- $subjectId = 0;
- $material_id = 0;
- $coach_id = $this->coachInfo->coach_id;
- $period = $thisSemester['school_year'];
- $teachersIds = Req::post("teacher_ids");
- $subject_ids = Req::post("subject_ids");
- $levelName = Req::post("level_name");
- $level = array($levelName => null);
- $grade = Req::post("grade");
- $_subject_ids = array();
- if($subject_ids)
- {
- foreach($subject_ids as $v)
- {
- if(in_array($v,$_subject_ids))
- {
- Yii::app()->jump->error('班级不能增加相同的学科教师');
- }
- $_subject_ids[] = $v;
- }
- }
- if(is_array($teachersIds)){
- foreach($teachersIds as $key => $val){
- if(empty($val) ||(is_string($val) && trim($val) == ""))
- unset($teachersIds[$key]);
- }
- }
- if(!array_intersect_key($level, $this->class_level))
- $levelName = "";
- if (empty($class_name)){
- Yii::app()->jump->error('班级信息未填写完整!');
- }
- else if(empty($coach_id)){
- Yii::app()->jump->error('未选择助教!');
- }
- else if(!$teachersIds){
- Yii::app()->jump->error('未选择执教老师!');
- }
- else if(!$grade){
- Yii::app()->jump->error('未选择年级!');
- }
- $classesModel = new ClassModel();
- // 判断当前学期当前班级是否已添加
- if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
- {
- Yii::app()->jump->error('该学期下已存在同名班级!');
- }
- // 当前班级唯一id
- //$classId = getUUID();
- $classId=getUniqueId($this->schoolId);
- if (empty($classId)) {
- Yii::app()->jump->error('创建班级失败!');
- }
- // 创建班级相关事务
- $transaction = $classesModel->dbConnection->beginTransaction();
- try{
- //创建班级与老师关系
- $level=Char::letterToNum($levelName, 1);
- if(!$level) $level=0;
- if(!$this->schoolManager->_changeClassTeachersRelation($classId, $teachersIds,array(
- 'class_id' => $classId,
- 'class_name' => $class_name,
- 'level' =>$level,
- 'grade' => $grade,
- 'semester_id' => $semesterId,
- 'period' => $period,
- 'add_time' => time(),
- 'coach_id' => $this->coachId,
- 'class_type' => 2,
- 'wrong_book_type' =>0,
- 'improve_book_type' =>0,
- 'wb_isp_version' => 0,
- )))
- throw new CException("创建班级和老师关系失败");
- foreach ($_subject_ids as $subject_id){
- if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) {
- throw new CException('创建失败!');
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error($e->getMessage());
- }
- if($this->schoolManager->isCurrentSemester($semesterId))
- $this->redirect(array('classes/index?class_type=2'));
- else
- $this->redirect(array("classes/index?semesterId={$semesterId}"));
- }
- unset(Yii::app()->session['school_material']);
- // 获取当前学校所有助教
- $coachList = array();
- if(!isset(Yii::app()->session['crmUserInfo']))
- {
- $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- if (empty($coachList)) {
- Yii::app()->jump->error('系统未找到助教,请联系管理员!');
- }
- }else
- {
- $coachList = array(Yii::app()->session['crmUserInfo']);
- }
- unset($transaction);
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
- //$data['semester'] = $semester;
- $data['coachList'] = $coachList;
- $data["teachers"] = $teachers;
- $data["teacher_data"] = $teacher_data;
- $data["classLevels"] = $this->class_level;
- $data["semesters"] = $semesters;
- $data["semesterId"] = $semesterId;
- $data["thisSemester"] = $thisSemester;
- $this->render('add_classified',$data);
- }
- //根据年级读取走班学科
- public function actionGetClassSubjectByGrade(){
- $grade = Req::post("grade");
- $resultType=Req::post("rtype");
- $semesterId=$this->semesterId;
- $subjects=array();
- $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId);
- if($rs){
- foreach ($rs as $val){
- if($resultType=='arr'){
- $subjects[]=$val['subject_id'];
- }else{
- $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
- }
- }
- }
- $result['status']=1;
- $result['data']=$subjects;
- exit(json_encode($result));
- }
- //编辑走班
- public function actionEditClassified(){
- $classId = safe_replace(Yii::app()->request->getQuery('cid'));
- if (empty($classId)) {
- Yii::app()->jump->error('操作失败!');
- }
- // 获取当前学校所有助教
- $coachList = array();
- if(!isset(Yii::app()->session['crmUserInfo']))
- {
- $coachList = BusinessCoach::model()->findAll('school_id=:sid and (status=0 or status=8)',array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- if (empty($coachList)) {
- Yii::app()->jump->error('系统未找到助教,请联系管理员!');
- }
- }else
- {
- $coachList = array(Yii::app()->session['crmUserInfo']);
- }
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- $classTeachersIds = $this->schoolManager->getClassTeachersIds($classId);
- // 班级信息
- //$classInfo = ClassModel::model()->find('class_id=:cid',array(':cid'=>$classId));
- $classInfo = $this->schoolManager->getClassInfo($classId, "OBJ");
- $grade = $classInfo->grade;
- $teachers = $this->schoolManager->getTeachers();
- $semesters = $this->schoolManager->getSemesters(array(), array("semester_id desc"), 0, 20);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到该班级信息!');
- }
- $subjects=array();
- $rs=$this->schoolManager->getSubjectByGrade($grade,0,$semesterId);
- if($rs){
- foreach ($rs as $val){
- $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
- }
- }
- // 当前班级教练信息
- $relatCoach = $this->schoolManager->getCoachClassRelationByClassId($classInfo->class_id, "OBJ");
- if (Yii::app()->request->getIsPostRequest()){
- $class_name = trim(Req::post("class_name"));
- $coach_id = $this->coachId;
- $period = Req::post("period");
- $levelName = Req::post("level_name");
- $level = array($levelName => null);
- $teachersIds = Req::post("teacher_ids");
- $subject_ids = Req::post("subject_ids");
- $_subject_ids = array();
- if($subject_ids)
- {
- foreach($subject_ids as $v)
- {
- if(in_array($v,$_subject_ids))
- {
- Yii::app()->jump->error('班级不能增加相同的学科教师');
- }
- $_subject_ids[] = $v;
- }
- }
- if(is_array($teachersIds)){
- foreach($teachersIds as $key => $val){
- if(empty($val) ||(is_string($val) && trim($val) == ""))
- unset($teachersIds[$key]);
- }
- }
- $grade = Req::post("grade");
- //$semesterId = Req::post("semesterId");
- if(!array_intersect_key($level, $this->class_level))
- $levelName = "";
- if (empty($class_name) || empty($coach_id) || !$teachersIds){
- Yii::app()->jump->error('班级信息未填写完整!');
- }
- $classesModel = new ClassModel();
- // 判断当前学期当前班级是否已添加
- if ($classesModel->count('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$class_name)))
- {
- 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)))
- Yii::app()->jump->error('您选择的学期已存在同名班级!');
- }
- // 创建班级相关事务
- //$transaction = Yii::app()->db->beginTransaction();
- $classInfo = ClassModel::model()->find("class_id = '{$classId}'");
- $transaction = $classInfo->dbConnection->beginTransaction();
- try {
- if($classInfo->class_name != $class_name)
- $classInfo->class_name = $class_name;
- //$classInfo->period = $period;
- //$classInfo->grade = $grade;
- //$classInfo->semester_id = $semesterId;
- if(!$levelName){
- $classInfo->level =0;
- }else{
- $classInfo->level = Char::letterToNum($levelName, 1);
- }
- $classInfo->wrong_book_type = 0;
- $classInfo->improve_book_type = 0;
- $classInfo->wb_isp_version = 0;
- if(!$classInfo->save()){
- throw new CException('更新失败!');
- }
- if($classInfo->coach_id != $coach_id){
- if (!$this->sConn->createCommand()->update("class", array("coach_id" => $coach_id), "class_id = '{$classId}'")) {
- throw new CException('班级更新失败!');
- }
- }
- if(!$this->schoolManager->changeClassTeachersRelation($classId, $teachersIds,$semesterId))
- throw new CException("班级老师更新失败");
- //清除旧关联
- $this->schoolManager->DelClassSubject($classId);
- foreach ($_subject_ids as $subject_id){
- if (!$this->sConn->createCommand()->insert("class_subject_relation", array("class_id" => $classId, "subject_id" => $subject_id, "material_id" => 0, "module_ids" => 0))) {
- throw new CException('创建失败!');
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- Yii::app()->jump->error($e->getMessage());
- }
- $this->redirect(array('classes/index?class_type=2'));
- }
- $data = array();
- $class_teacher_data = array();
- $subject_teacher_data = array();
- $subject_teacher_array = array();
- $teacher_data = Teacher::model()->findAll('subjects=:subjects and status=0',array(':subjects'=>3));
- $teachers_data = Teacher::model()->findAll('status=0');
- if($teachers_data)
- {
- $gangwei = array(
- 0=>'任课教师',
- 1=>'班主任',
- 2=>'教研组长',
- 3=>'年级主任',
- 4=>'任课教师',
- 5=>'校长',
- );
- $grade_arr = array(0=>'',1=>'高一',2=>'高二',3=>'高三');
- foreach($teachers_data as $k=>$v)
- {
- $class_teacher_data[$v->teacher_id] = $v->teacher_id;
- $subject_teacher_data[$v->teacher_id] = $v->subjects;
- $teacherGrade = $v->grade?$v->grade:0;
- if($v->posts==3){
- //过滤本年级的年级主任
- if (!$teacherGrade || $teacherGrade==$grade){
- $tempPost=isset($grade_arr[$v->grade])?$grade_arr[$v->grade].$gangwei[$v->posts]:$gangwei[$v->posts];
- $subject_teacher_array[$v->subjects][$v->teacher_id][$v->teacher_id] = array('teacher_id'=>$v->teacher_id,'teacher_name'=>$v->teacher_name,'posts'=>$tempPost);
- }
- }else{
- $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]);
- }
- }
- }
- $data["teachers"] = $teachers;
- $data["classLevels"] = $this->class_level;
- $data["classTeachersIds"] = $classTeachersIds;
- $data['classInfo'] = $classInfo;
- $data['relatCoach'] = $relatCoach;
- $data['class_teacher'] = $class_teacher_data;
- $data['subject_teacher'] = $subject_teacher_data;
- $data['subject_teacher_array'] = $subject_teacher_array;
- $data["teacher_data"] = $teacher_data;
- $data['coachList'] = $coachList;
- $data["semesters"] = $semesters;
- $data["semester_id"] = $classInfo->semester_id;
- $data['subjects']=$subjects;
- $data['thisSemester']=$thisSemester;
- $this->render('edit_classified',$data);
- }
- //教学班转班
- public function actionCopyClassified(){
- $gradeArr=array(
- 1=>'高一',
- 2=>'高二',
- 3=>'高三',
- );
- $data = array();
- $cid = safe_replace(Yii::app()->request->getQuery('cid'));
- $classInfo = $this->schoolManager->getClassInfo($cid);
- $subjects=$this->schoolManager->getSubjectByClass($cid);
- $semestersList = $this->schoolManager->getSemesters();
- if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
- $data['subject']=Yii::app()->params['subjectId'];
- unset($data['subject'][6]);
- unset($data['subject'][51]);
- unset($data['subject'][18]);
- unset($data['subject'][19]);
- if(isset($data['subject'][20])) unset($data['subject'][20]);
- }
- $data['cid'] = $cid;
- $data['grade']=$classInfo['grade'];
- $data['gradeName']=$gradeArr[$classInfo['grade']];
- $data['cname'] = $classInfo['class_name'];
- $data['subjects'] = $subjects;
- $data['semester']=$semestersList;
- $this->render('copy_classified', $data);
- }
- //根据学期加载教学班学科
- public function actionAjaxGetSubjectBySemester(){
- $semester = Req::post("semester");
- if(!$semester){
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- $rs=$this->sConn->createCommand("select distinct subject_id from classified where semester_id='{$semester}' and status=1")->queryAll();
- $subjects=array();
- if($rs){
- foreach ($rs as $val){
- $subjects[]=array(
- 'subject_id'=>$val['subject_id'],
- 'subject_name'=>Yii::app()->params['subjectId'][$val['subject_id']]
- );
- }
- }
- echo json_encode(array('status'=>1,'data'=>$subjects));exit;
- }
- //根据学期学科加载年级
- public function actionAjaxGetGradeBySubject(){
- $semester = Req::post("semester");
- $subject = Req::post("subject");
- if(!$semester || !$subject){
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- $rs=$this->sConn->createCommand("select distinct grade from classified where semester_id='{$semester}' and subject_id='{$subject}' and status=1")->queryAll();
- $grades=array();
- $gradeText=array(
- 1=>'高一',
- 2=>'高二',
- 3=>'高三'
- );
- if($rs){
- foreach ($rs as $val){
- $grades[]=array(
- 'id'=>$val['grade'],
- 'name'=>$gradeText[$val['grade']]
- );
- }
- }
- echo json_encode(array('status'=>1,'data'=>$grades));exit;
- }
- //加载教学班
- public function actionAjaxGetClass(){
- $semester = Req::post("semester");
- $subject = Req::post("subject");
- $grade = Req::post("grade");
- $to_class_id = Req::post("to_class_id");
- if(!$semester || !$subject){
- echo json_encode(array('status'=>0,'data'=>''));exit;
- }
- if($to_class_id){
- $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();
- }else{
- $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();
- }
- echo json_encode(array('status'=>1,'data'=>$rs));exit;
- }
- //校验同学期同名班级
- public function actionCheckClassNameOnSameSemester(){
- $className=Req::post('class_name');
- $result=array();
- $result['status']=0;
- $semesterId=$this->semesterId;
- $classesModel = new ClassModel();
- // 判断当前学期当前班级是否已添加
- $checkRepeat=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$className));
- if ($checkRepeat)
- {
- if($checkRepeat->is_hide==1){
- $result['status']=1;
- $result['data']=$checkRepeat->class_id;
- }
- }
- exit(json_encode($result));
- }
- //恢复班级
- public function actionRecoverClass(){
- $classId = Req::post("classId");
- $result=array();
- $result['status']=0;
- if(!$classId){
- exit(json_encode($result));
- }
- $sql="update class set is_hide=0,sort=0 where class_id='{$classId}'";
- if($this->sConn->createCommand($sql)->execute()){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //隐藏班级
- public function actionHideClass(){
- $classId = Req::post("classId");
- $result['status']=0;
- if(!$classId){
- $result['msg']='参数错误';
- exit(json_encode($result));
- }
- if($this->schoolManager->classHasStudent($classId)){
- $result['msg']='班级已关联学生不能隐藏';
- exit(json_encode($result));
- }
- $sql="update class set is_hide=1 where class_id='{$classId}'";
- if($this->sConn->createCommand($sql)->execute()){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- public function actionTestQcloud(){
- $qcloud=new Qcloud();
- $result=$qcloud->putFile('assets/data/import_score_example.xls','testupload/test/1.xls');
- if($result && isset($result['Location'])){
- debug($result['Location']);
- }else{
- debug('error');
- }
- }
- public function getStudentsClassNo($chooseStudentArr)
- {
- $data = array();
- $student_ids = array();
- $student_names = array();
- $student_cards = array();
- $school_student_cards = array();
- $userno = array();
- $student_info = array();
- $class_student = array();
- $student_class_ids = array();
- $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();
- // $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$class_id,':status'=>$status));
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- if($chooseStudentArr && inArray($v['student_id'], $chooseStudentArr)){
- $student_ids[$v['student_id']] = $v['student_id'];
- $userno[$v['student_id']] = $v['userno'];
- $class_student[$v['student_id']] = $v;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_data = SStudentInfo::model()->findAll($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $student_names[$v->student_id] = $v->realname;
- $student_info[$v->student_id] = $v;
- }
- }
- unset($student_data);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $student_cards[$v->student_id] = $v->student_card;
- if($v->school_student_card)
- {
- $school_student_cards[$v->student_id] = $v->school_student_card;
- }
- //$school_student_cards[$v->student_id] = $v->school_student_card;
- }
- }
- unset($b_student_data);
- $data['student_names'] = $student_names;
- $data['student_cards'] = $student_cards;
- $data['student_ids'] = $student_ids;
- $data['school_student_cards'] = $school_student_cards;
- $data['student_userno'] = $userno;
- $data['student_info'] = $student_info;
- $data['class_student'] = $class_student;
- $data['student_class_ids'] = $student_class_ids;
- }
- unset($student_class_data);
- return $data;
- }
-
- /**
- * 批量添加班级页面
- */
- public function actionBatchAdd(){
- $data = array();
-
- $this->render('batch_add',$data);
- }
- /**
- * 批量添加班级逻辑
- */
- public function actionClassImport(){
- ini_set ('memory_limit', '300M');
- $updateSql = $updateSqlSub = array();
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- $period = $thisSemester['school_year'];
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- }catch (Exception $e){
- //FIXME 2019-12-02
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- //模板校验
- if(Yii::app()->params['section']==1){
- $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*文理科','E'=>'*班主任','F'=>'*班主任电话','G'=>'*学科','H'=>'*老师','I'=>'*老师电话');
- $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'文理科','E'=>'班主任','F'=>'班主任电话','G'=>'学科','H'=>'老师','I'=>'老师电话');
- }else{
- $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*班主任','E'=>'*班主任电话','F'=>'*学科','G'=>'*老师','H'=>'*老师电话');
- $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'班主任','E'=>'班主任电话','F'=>'学科','G'=>'老师','H'=>'老师电话');
- }
- $classnamsTemp = array();
- if(count($excelTemp) != count($sheetData[1])){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- foreach($excelTemp as $key=>$temp){
- if(!(isset($sheetData[2][$key]) && $sheetData[2][$key] == trim($temp))){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- }
- unset($sheetData[1]);
- unset($sheetData[2]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入班级数据');
- }
- /**
- * 1.检测必填字段不为空的情况
- * 2.检测字段时候符合标准
- * 3.检测excel班级名称时候重复
- * 4、合并单元格处理
- * 5、教师账号检测
- */
- $classTdFirst=1; //标记合并单元格第一行
- $classAndTeacherData=array();
- $tableNo=0;
- $classTeacherRepeatCheck=array();
- foreach($sheetData as $hang_no=>$hang_data){
- if(trim($hang_data['A'])){
- $classTdFirst=1;
- $tableNo=$hang_no;
- }else{
- if(!$classAndTeacherData){
- Yii::app()->jump->error('班级名称不能为空');
- }
- $classTdFirst=0;
- }
- if($classTdFirst){
- foreach($hang_data as $key=>$val){
- $val = $hang_data[$key] = trim($val);
- if(!$val){
- Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空');
- }
- if($key=='B'){
- if(!in_array($val,array_keys(Yii::app()->params['grade_config']))){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }
- }
- if($key=='C'){
- if(!in_array($val,array('A','B','C'))){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }
- }
- if(Yii::app()->params['section']==1){
- if($key=='D'){
- if(!in_array($val,array('不分科','文科','理科'))){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }
- }
- }
- }
- $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'";
- $class_data = $this->sConn->createCommand($sql)->queryRow();
- if($class_data){
- Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传 '.$hang_data['A']);
- }
- $teacher_id = '';
- $class_master_name = Yii::app()->params['section']==1?$hang_data['E']:$hang_data['D'];
- $class_master_phone = Yii::app()->params['section']==1?$hang_data['F']:$hang_data['E'];
- $sql = "select teacher_id from teacher where teacher_name = '{$class_master_name}' and posts=1";
- $class_data = $this->sConn->createCommand($sql)->queryAll();
- if($class_data){
- $teacher_ids = _array_column($class_data, 'teacher_id');
- $sql = "select teacher_id,phone_number from teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_master_phone}'";
- $teacherInfo = $this->conn->createCommand($sql)->queryRow();
- if($teacherInfo){
- $teacher_id = $teacherInfo['teacher_id'];
- }else{
- Yii::app()->jump->error('第'.$hang_no.'行班主任与班主任电话不匹配,请核对后再上传<br> '.$class_master_name.":".$class_master_phone);
- }
- }else{
- Yii::app()->jump->error('第'.$hang_no.'行班主任姓名不存在 '.$class_master_name);
- }
- $grade = $hang_data['B'];
- if($hang_data['C'] == 'A'){
- $level = 1;
- }else if($hang_data['C'] == 'B'){
- $level = 2;
- }else if($hang_data['C'] == 'C'){
- $level = 3;
- }
- if(Yii::app()->params['section']==1){
- if($hang_data['D'] == '不分科'){
- $arts_science = 0;
- }else if($hang_data['D'] == '文科'){
- $arts_science = 1;
- }else if($hang_data['D'] == '理科'){
- $arts_science = 2;
- }
- }else{
- $arts_science = 0;
- }
- //整理数据
- $classAndTeacherData[$tableNo]=array(
- 'class_name'=>$hang_data['A'],
- 'grade'=>$grade,
- 'level'=>$level,
- 'arts_science'=>$arts_science,
- 'teacher_id'=>$teacher_id,
- 'teachers'=>array()
- );
- }
- //关联教师数据
- if(Yii::app()->params['section']==1) {
- $subject = trim($hang_data['G']);
- $teacher_name = trim($hang_data['H']);
- $teacher_phone = trim($hang_data['I']);
- }else{
- $subject = trim($hang_data['F']);
- $teacher_name = trim($hang_data['G']);
- $teacher_phone = trim($hang_data['H']);
- }
- //判断教师
- if(!$subject && !$teacher_name && !$teacher_phone){
- //都不填,跳过
- continue;
- }elseif($subject && $teacher_name && $teacher_phone){
- //校验科目
- $subjectId=array_search($subject,Yii::app()->params['subjectId']);
- if($subjectId==false){
- Yii::app()->jump->error('第'.$hang_no.'科目不正确 ');
- }
- if(isset($classTeacherRepeatCheck[$tableNo]) && inArray($teacher_phone,$classTeacherRepeatCheck[$tableNo])){
- Yii::app()->jump->error($classAndTeacherData[$tableNo]['class_name'].',老师电话有重复'.$teacher_phone);
- }
- $classTeacherRepeatCheck[$tableNo][]=$teacher_phone;
- //检验手机号
- $getPhone = BusinessTeacher::model()->find('phone_number=:phnum ', array(':phnum' => $teacher_phone));
- if (!$getPhone) {
- Yii::app()->jump->error('手机号'.$teacher_phone.'不存在!');
- }elseif($getPhone->school_id!=$this->schoolId){
- Yii::app()->jump->error('手机号'.$teacher_phone.'已在其它学校注册!');
- }
- //校验科目
- $schoolTeacher=$this->sConn->createCommand("select subjects from teacher where teacher_id='{$getPhone['teacher_id']}'")->queryRow();
- if($schoolTeacher['subjects']!=$subjectId){
- Yii::app()->jump->error('第'.$hang_no.'行,教师手机号与科目不匹配'.$teacher_phone);
- }
- $classAndTeacherData[$tableNo]['teachers'][]=array(
- 'teacher_id'=>$getPhone['teacher_id'],
- 'subject_id'=>$subjectId
- );
- }elseif(!$subject ){
- Yii::app()->jump->error('第'.$hang_no.'行,科目不能为空 ');
- }elseif(!$teacher_name){
- Yii::app()->jump->error('第'.$hang_no.'行,教师姓名不能为空 ');
- }elseif(!$teacher_phone){
- Yii::app()->jump->error('第'.$hang_no.'行,教师手机号不能为空 ');
- }
- }
- //校验表格内名称重复
- $classNameCheck=array();
- if($classAndTeacherData){
- $classIds=getBatchUuid($this->schoolId,count($classAndTeacherData));
- $insertClassSqlValues=array();
- $insertTeacherClassRelationSqlValues=array();
- $insertClassSubjectRelationSqlValues=array();
- foreach ($classAndTeacherData as $key => $item){
- if(in_array($item['class_name'],$classNameCheck)){
- Yii::app()->jump->error('第'.$key.'行'.'表格内出现重复的班级名称,请核对后再上传 '.$item['class_name']);
- }else{
- $classNameCheck[]=$item['class_name'];
- }
- $classId=array_pop($classIds);
- $insertClassSqlValues[]="('".$classId."','".$item['class_name']."','".$this->coachId."','".$this->semesterId."','".$period."','".$item['grade']."','".$item['level']."','".time()."','".$item['arts_science']."','".$item['teacher_id']."')";
- if($item['teachers']){
- $teacherSubjectCheck=array();
- foreach ($item['teachers'] as $teacher){
- if(in_array($teacher['subject_id'],$teacherSubjectCheck)){
- Yii::app()->jump->error('第'.$key.'行'.'同一班级出现重复的科目,请核对后再上传 ');
- }else{
- $teacherSubjectCheck[]=$teacher['subject_id'];
- }
- $insertTeacherClassRelationSqlValues[]= "('{$classId}', '{$teacher['teacher_id']}', '{$semesterId}')";
- $insertClassSubjectRelationSqlValues[]= "('{$classId}', '{$teacher['subject_id']}')";
- }
- }
- }
- }
-
- if($insertClassSqlValues){
- $insertClassSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`arts_science`,`teacher_id`) VALUES ';
- $insertTeacherClassRelationSql="insert into teacher_class_relation (`class_id`,`teacher_id`,`semester_id`) values";
- $insertClassSubjectRelationSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values ';
- $insertClassSql.=implode(',',$insertClassSqlValues);
- $transaction = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand($insertClassSql)->execute();
- if($insertTeacherClassRelationSqlValues){
- $insertTeacherClassRelationSql.=implode(',',$insertTeacherClassRelationSqlValues);
- $this->sConn->createCommand($insertTeacherClassRelationSql)->execute();
- }
- if($insertClassSubjectRelationSqlValues){
- $insertClassSubjectRelationSql.=implode(',',$insertClassSubjectRelationSqlValues);
- $this->sConn->createCommand($insertClassSubjectRelationSql)->execute();
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- debug($e);
- Yii::app()->jump->error('班级批量上传失败!');
- }
- $url=$this->createUrl('/classes/index');
- Yii::app()->jump->error('班级批量上传成功!',$url);
- }else{
- Yii::app()->jump->error('没有需要更新的数据!');
- }
- //end
- }
-
- /**
- * 批量添加教学班班级页面
- */
- public function actionBatchAddClass(){
- $data = array();
-
- $this->render('batch_addclass',$data);
- }
- /**
- * 批量添加教学班班级逻辑
- */
- public function actionClassImportType2(){
- ini_set ('memory_limit', '300M');
- $updateSql = $updateSubSql = array();
- $tcrSql = array();
- $semesterId = $this->semesterId;
- $thisSemester = $this->schoolManager->getSemester($semesterId);
- $period = $thisSemester['school_year'];
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- $uploader = new Uploader("upload/tmpDir/UploadClassesList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- }catch (Exception $e){
- //FIXME 2019-12-02
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- //模板校验
- $excelTemp = array('A'=>'*班级名称','B'=>'*年级','C'=>'*层级','D'=>'*学科','E'=>'*老师','F'=>'*老师电话');
- $checkTemp = array('A'=>'班级名称','B'=>'年级','C'=>'层级','D'=>'学科','E'=>'老师','F'=>'老师电话');
- $classnamsTemp = array();
- if(count($excelTemp) != count($sheetData[1])){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- foreach($excelTemp as $key=>$temp){
- if(!(isset($sheetData[1][$key]) && $sheetData[1][$key] == trim($temp))){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- }
- unset($sheetData[1]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入教师数据');
- }
- /**
- * 1.检测必填字段不为空的情况
- * 2.检测字段时候符合标准
- * 3.检测excel班级名称时候重复
- */
- foreach($sheetData as $hang_no=>$hang_data){
- $subject_ids_arr = array();
- $classId = getUniqueId($this->schoolId);
- foreach($hang_data as $key=>$val){
- $val = $hang_data[$key] = trim($val);
- if(!$val){
- Yii::app()->jump->error('第'.$hang_no.'行'.$checkTemp[$key].'不能为空');
- }
- if($key=='B'){
- if(!in_array($val,array('1','2','3'))){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }else{
- // if($val == '一'){
- // $grade = 1;
- // }else if($val == '二'){
- // $grade = 2;
- // }else if($val == '三'){
- // $grade = 3;
- // }
- $grade = $val;
- }
- }
- if($key=='C'){
- if(!in_array($val,array('A','B','C'))){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }
- }
- if($key=='D'){
- $subject_data = explode(";",$val);
- foreach($subject_data as $sub_name){
- $sql = "select master_subject_id from subject where subject_name = '{$sub_name}'";
- $subject_info = $this->conn->createCommand($sql)->queryRow();
- if(!$subject_info){
- Yii::app()->jump->error('第'.$hang_no.'行'.$val.$checkTemp[$key].'不存在');
- }else{
- $subject_id = $subject_info['master_subject_id'];
- $updateSubSql[] = array($classId,$subject_id);
- $subject_ids_arr[] = $subject_id;
- $sql = "select * from classified where subject_id='{$subject_id}' and `status`=1 and semester_id='{$semesterId}' and grade={$grade}";
- $is_classified = $this->sConn->createCommand($sql)->queryRow();
- if(!$is_classified){
- Yii::app()->jump->error('第'.$hang_no.'行走班学科未开通,请核对后再上传<br> '.$sub_name);
- }
- }
- }
- }
- }
-
- if(in_array($hang_data['A'],$classnamsTemp)){
- Yii::app()->jump->error('第'.$hang_no.'行'.'表格内出现重复的班级名称,请核对后再上传<br>'.$hang_data['A']);
- }else{
- $classnamsTemp[] = $hang_data['A'];
- $sql = "select class_id from class where class_name = '{$hang_data['A']}' and semester_id = '{$this->semesterId}'";
- $class_data = $this->sConn->createCommand($sql)->queryRow();
- if($class_data){
- Yii::app()->jump->error('第'.$hang_no.'行'.'表格与系统内出现重复的班级名称,请核对后再上传<br> '.$hang_data['A']);
- }
- }
-
- //判断学科 老师 电话数量时候一致
- $teacher_data = explode(";",$hang_data['E']);
- $phone_data = explode(";",$hang_data['F']);
- if(count($subject_data) != count($teacher_data) && count($teacher_data) != count($phone_data) && count($phone_data) != count($subject_data)){
- Yii::app()->jump->error('第'.$hang_no.'行 学科老师电话数量不一致');
- }
- //判断学科 老师 电话数据是否一致
- foreach($teacher_data as $te_no=>$te_data){
- $class_teacher_name = $te_data;
- $class_teacher_phone = $phone_data[$te_no];
- $class_teacher_subject = $subject_data[$te_no];
- $class_teacher_subjectid = $subject_ids_arr[$te_no];
- $sql = "select teacher_id,posts,grade from teacher where teacher_name = '{$class_teacher_name}' and subjects={$class_teacher_subjectid}";
- $te_data = $this->sConn->createCommand($sql)->queryAll();
- if($te_data){
- //如果匹配到年级主任特殊处理
- $teacher_ids = array();
- foreach($te_data as $te_data_val){
- if($te_data_val['posts'] == 3 && $te_data_val['grade'] != $grade){
-
- }else{
- $teacher_ids[] = $te_data_val['teacher_id'];
- }
- }
- if(!$teacher_ids){
- Yii::app()->jump->error('第'.$hang_no.'行'.'年级主任与学科不对应 '.$class_teacher_subject.' '.$class_teacher_name);
- }else{
- $sql = "select teacher_id,phone_number from teacher where teacher_id in (".implode(',',$teacher_ids).") and phone_number = '{$class_teacher_phone}'";
- $teacherInfo = $this->conn->createCommand($sql)->queryRow();
- if($teacherInfo){
- $teacher_id = $teacherInfo['teacher_id'];
- $tcrSql[] = array($classId,$teacher_id,$this->semesterId);
- }else{
- Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传<br> '.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone);
- }
- }
-
- }else{
- Yii::app()->jump->error('第'.$hang_no.'行 学科、老师、老师电话不匹配,请核对后再上传<br> '.$class_teacher_subject.' '.$class_teacher_name.' '.$class_teacher_phone);
- }
- }
-
-
- if($hang_data['C'] == 'A'){
- $level = 1;
- }else if($hang_data['C'] == 'B'){
- $level = 2;
- }else if($hang_data['C'] == 'C'){
- $level = 3;
- }
-
- $updateSql[] = array($classId,'"'.$hang_data['A'].'"',$this->coachId,$this->semesterId,$period,$grade,$level,time(),2);
-
- }
- if($updateSql && $tcrSql && $updateSubSql){
- $schInsertSql = 'INSERT INTO class (`class_id`, `class_name`,`coach_id`,`semester_id`,`period`,`grade`,`level`,`add_time`,`class_type`) VALUES ';
-
- $tcrInsertSql = 'INSERT INTO teacher_class_relation (`class_id`, `teacher_id`,`semester_id`) VALUES ';
-
- $schSubSql = 'insert into class_subject_relation (`class_id`,`subject_id`) values ';
- foreach($updateSql as $stVal){
- $schInsertSql .= '('.implode(',',$stVal).'),';
- }
- foreach($tcrSql as $stVal){
- $tcrInsertSql .= '('.implode(',',$stVal).'),';
- }
- foreach($updateSubSql as $stVal){
- $schSubSql .= '('.implode(',',$stVal).'),';
- }
- $schInsertSql = substr($schInsertSql,0,-1);
- $tcrInsertSql = substr($tcrInsertSql,0,-1);
- $schSubSql = substr($schSubSql,0,-1);
- $transaction = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand($schInsertSql)->execute();
- $this->sConn->createCommand($tcrInsertSql)->execute();
- $this->sConn->createCommand($schSubSql)->execute();
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- Yii::app()->jump->error('班级批量上传失败!');
- }
- $url=$this->createUrl('/classes/index?class_type=2');
- Yii::app()->jump->error('班级批量上传成功!',$url);
- }else{
- Yii::app()->jump->error('没有需要更新的数据!');
- }
-
- }
-
- /**
- * 导出班级数据
- */
- public function actionExportClass(){
- $excel_title = '班级信息导出';
- $excel_show_title = array(1=>'班级',2=>'年级',3=>'层级',4=>'文理科',5=>'班主任',6=>'执教老师',7=>'学生人数');
- $excel_show_msg = array(1=>'class_name',2=>'grade',3=>'level',4=>'arts_science',5=>'master_name',6=>'teacher_names',7=>'student_count');
- $realname = (string)Req::get("realname");
- $grade = (int)Req::get("grade");
- $arts_science = (int)Req::get("arts_science");
- $class_type = (int)Req::get("class_type");
- $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
- $choose_type = (string)Req::get("choose_type");//需要导出excel哪些数据
- if($choose_type){
- $choose_type_arr = explode(',',$choose_type);
- }
-
- $condition = array();
- if(!$smid){
- $smid = $this->semesterId;
- }
- $condition[] = "seme.semester_id = '{$smid}'";
- $condition[] = "c.class_type={$class_type}";
- $condition[] = "c.is_hide=0";
- if($grade){
- $condition[] = "c.grade={$grade}";
- }
- if($arts_science == 1){
- $condition[] = "c.arts_science=1";
- }else if($arts_science == 2){
- $condition[] = "c.arts_science=2";
- }
- if($realname){
- $condition[] = "c.class_name like '%{$realname}%'";
- }
- $condition = " where ".implode(" and ", $condition);
- $sql = "select c.class_id,c.class_name,c.grade,c.level,c.arts_science,c.teacher_id
- from class as c
- join semester as seme on seme.semester_id = c.semester_id
- {$condition}
- order by c.sort!=0 desc,c.sort,c.class_id desc";
- $class_data = $this->sConn->createCommand($sql)->queryAll();
- if($class_data){
- foreach($class_data as $k=>$v){
- //获取班主任姓名
- $class_data[$k]['master_name'] = '';
- if($v['teacher_id']){
- $sql = "select teacher_name from teacher where teacher_id = '{$v['teacher_id']}'";
- $teacher_data = $this->sConn->createCommand($sql)->queryRow();
- if($teacher_data){
- $class_data[$k]['master_name'] = $teacher_data['teacher_name'];
- }
- }
- //获取执教老师姓名
- $class_data[$k]['teacher_names'] = '';
- $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']}'";
- $teacher_msg = $this->sConn->createCommand($sql)->queryAll();
- if($teacher_msg){
- $teacher_names = _array_column($teacher_msg, 'teacher_name');
- $class_data[$k]['teacher_names'] = implode(';',$teacher_names);
- }
- //获取学生人数
- $class_data[$k]['student_count'] = '';
- $sql = "select count(student_id) count from student_class_relation where class_id='{$v['class_id']}' and `status`=0";
- $student_data = $this->sConn->createCommand($sql)->queryRow();
- if($student_data){
- $class_data[$k]['student_count'] = $student_data['count'];
- }
- if($v['grade'] == 1){
- $class_data[$k]['grade'] = '一';
- }else if($v['grade'] == 2){
- $class_data[$k]['grade'] = '二';
- }else if($v['grade'] == 3){
- $class_data[$k]['grade'] = '三';
- }
- if($v['level'] == 1){
- $class_data[$k]['level'] = 'A';
- }else if($v['level'] == 2){
- $class_data[$k]['level'] = 'B';
- }else if($v['level'] == 3){
- $class_data[$k]['level'] = 'C';
- }
- if($v['arts_science'] == 1){
- $class_data[$k]['arts_science'] = '文科';
- }else if($v['arts_science'] == 2){
- $class_data[$k]['arts_science'] = '理科';
- }else{
- $class_data[$k]['arts_science'] = '不分科';
- }
- }
- }else{
- Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index'));
- }
- if($class_data){
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("班级信息")
- ->setSubject("班级信息")
- ->setDescription("导出班级信息")
- ->setKeywords("excel")
- ->setCategory("result file");
-
- foreach($choose_type_arr as $key=>$val){
- $objPHPExcel->getActiveSheet()->getColumnDimension(numToLetter($key+1))->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue(numToLetter($key+1).'1', $excel_show_title[$val]);
- }
- $i = 2;
- foreach($class_data as $k=>$v){
- foreach($choose_type_arr as $key=>$val){
- $objPHPExcel->getActiveSheet(0)->setCellValue(numToLetter($key+1) . $i, $v[$excel_show_msg[$val]]);
- }
- $i++;
- }
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
- }else{
- Yii::app()->jump->error('导出失败,无学生数据',Yii::app()->createUrl('classes/index'));
- }
-
-
- }
- }
|